mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-02-26 08:42:30 +00:00
Compare commits
7 Commits
xahau@4.0.
...
0.17.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f6af4797f | ||
|
|
5985d9022e | ||
|
|
8abc87c27c | ||
|
|
f0feaca785 | ||
|
|
f811bd6c2d | ||
|
|
eeb6e6b39d | ||
|
|
327a8dc451 |
4
.babelrc
Normal file
4
.babelrc
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"presets": ["es2015", "stage-1"],
|
||||
"plugins": ["syntax-flow", "transform-flow-strip-types"]
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
const xahau = require("xahau");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const filePath = path.resolve(__dirname, "./rippled.cfg");
|
||||
const existingConfig = fs.readFileSync(filePath, "utf-8");
|
||||
|
||||
const networkToEmulate = "wss://s.devnet.rippletest.net:51233/";
|
||||
|
||||
const amendmentsToIgnore = [
|
||||
"86E83A7D2ECE3AD5FA87AB2195AE015C950469ABF0B72EAACED318F74886AE90", // CryptoConditionsSuite is obsolete
|
||||
];
|
||||
|
||||
async function main() {
|
||||
const client = new xahau.Client(networkToEmulate);
|
||||
await client.connect();
|
||||
|
||||
// Looks up what amendments have been enabled via their hash
|
||||
const request = {
|
||||
command: "ledger_entry",
|
||||
index: "7DB0788C020F02780A673DC74757F23823FA3014C1866E72CC4CD8B226CD6EF4",
|
||||
ledger_index: "validated",
|
||||
};
|
||||
const response = await client.request(request);
|
||||
|
||||
const amendments = response.result.node.Amendments;
|
||||
|
||||
const newAmendments = [];
|
||||
amendments.forEach((amendment) => {
|
||||
if (
|
||||
!existingConfig.includes(amendment) &&
|
||||
!amendmentsToIgnore.includes(amendment)
|
||||
) {
|
||||
newAmendments.push(amendment);
|
||||
}
|
||||
});
|
||||
|
||||
if (newAmendments.length > 0) {
|
||||
console.log(
|
||||
"New Amendment Hashes - Look up their names on https://xrpl.org/known-amendments.html"
|
||||
);
|
||||
newAmendments.forEach((amendment) => {
|
||||
console.log(amendment);
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
`No new amendments to add!
|
||||
Looking at network: ${networkToEmulate}.
|
||||
Path to config: ${filePath}`
|
||||
);
|
||||
}
|
||||
|
||||
await client.disconnect();
|
||||
}
|
||||
|
||||
main().catch((error) => console.log(error));
|
||||
@@ -1,169 +0,0 @@
|
||||
[server]
|
||||
port_rpc_admin_local
|
||||
port_ws_public
|
||||
port_ws_admin_local
|
||||
|
||||
# port_peer
|
||||
# port_ws_admin_local
|
||||
# ssl_key = /etc/ssl/private/server.key
|
||||
# ssl_cert = /etc/ssl/certs/server.crt
|
||||
|
||||
# IPs must be 0.0.0.0 instead of 127.0.0.1 to be accessed outside the docker container
|
||||
|
||||
[port_rpc_admin_local]
|
||||
port = 5005
|
||||
ip = 0.0.0.0
|
||||
admin = 0.0.0.0
|
||||
protocol = http
|
||||
|
||||
[port_ws_public]
|
||||
port = 80
|
||||
ip = 0.0.0.0
|
||||
protocol = ws
|
||||
|
||||
# [port_peer]
|
||||
# port = 51235
|
||||
# ip = 0.0.0.0
|
||||
# protocol = peer
|
||||
|
||||
[port_ws_admin_local]
|
||||
port = 6006
|
||||
ip = 0.0.0.0
|
||||
admin = 0.0.0.0
|
||||
protocol = ws
|
||||
|
||||
[node_size]
|
||||
small
|
||||
|
||||
# tiny
|
||||
# small
|
||||
# medium
|
||||
# large
|
||||
# huge
|
||||
|
||||
[node_db]
|
||||
type=NuDB
|
||||
path=/var/lib/rippled/db/nudb
|
||||
advisory_delete=0
|
||||
|
||||
# How many ledgers do we want to keep (history)?
|
||||
# Integer value that defines the number of ledgers
|
||||
# between online deletion events
|
||||
online_delete=256
|
||||
|
||||
[ledger_history]
|
||||
# How many ledgers do we want to keep (history)?
|
||||
# Integer value (ledger count)
|
||||
# or (if you have lots of TB SSD storage): 'full'
|
||||
256
|
||||
|
||||
[database_path]
|
||||
/var/lib/rippled/db
|
||||
|
||||
[debug_logfile]
|
||||
/var/log/rippled/debug.log
|
||||
|
||||
|
||||
[ips]
|
||||
r.ripple.com 51235
|
||||
|
||||
# [validators_file]
|
||||
# validators.txt
|
||||
|
||||
[rpc_startup]
|
||||
{ "command": "log_level", "severity": "info" }
|
||||
|
||||
# severity (order: lots of information .. only errors)
|
||||
# debug
|
||||
# info
|
||||
# warn
|
||||
# error
|
||||
# fatal
|
||||
|
||||
[ssl_verify]
|
||||
1
|
||||
|
||||
# The [features] stanza does not currently work for standalone mode: https://github.com/XRPLF/xrpl-dev-portal/issues/1762#issuecomment-1441252450
|
||||
|
||||
|
||||
# In order to enable an amendment which by default would vote "No", you must include its amendment id and name here.
|
||||
# To add amendments specifically from the latest releases of rippled:
|
||||
# 1. Go to https://xrpl.org/known-amendments.html
|
||||
# 2. Find the first amendment in the latest releases of rippled which are not already in the list below
|
||||
# 3. Click on each amendment to get their Amendment ID and name to add to this list manually.
|
||||
# You will likely update the list with all amendments from a new release of rippled all at once.
|
||||
|
||||
# To get the list of amendments on a network (e.g. devnet) follow the steps in xahau.js's CONTRIBUTING.md for "Updating the Docker container".
|
||||
# https://github.com/Xahau/xahau.js/blob/main/CONTRIBUTING.md
|
||||
# (Running the script `getNewAmendments.js` should help you identify any new amendments that should be added.)
|
||||
#
|
||||
# Note: The version of rippled you use this config with must have an implementation for the amendments you attempt to enable or it will crash.
|
||||
# If you need the version of rippled to be more up to date, you may need to make a comment on this repo: https://github.com/WietseWind/docker-rippled
|
||||
|
||||
[features]
|
||||
# Amendments
|
||||
NegativeUNL
|
||||
fixRemoveNFTokenAutoTrustLine
|
||||
NonFungibleTokensV1
|
||||
CheckCashMakesTrustLine
|
||||
fixRmSmallIncreasedQOffers
|
||||
fixSTAmountCanonicalize
|
||||
FlowSortStrands
|
||||
TicketBatch
|
||||
fixQualityUpperBound
|
||||
FlowCross
|
||||
HardenedValidations
|
||||
DepositPreauth
|
||||
MultiSignReserve
|
||||
fix1623
|
||||
fix1513
|
||||
RequireFullyCanonicalSig
|
||||
fix1543
|
||||
fix1781
|
||||
fixCheckThreading
|
||||
fix1515
|
||||
CryptoConditionsSuite
|
||||
fixPayChanRecipientOwnerDir
|
||||
fix1578
|
||||
fix1571
|
||||
fixAmendmentMajorityCalc
|
||||
fixTakerDryOfferRemoval
|
||||
fixMasterKeyAsRegularKey
|
||||
Flow
|
||||
DeletableAccounts
|
||||
DepositAuth
|
||||
Checks
|
||||
NonFungibleTokensV1_1
|
||||
DisallowIncoming
|
||||
fixNonFungibleTokensV1_2
|
||||
fixUniversalNumber
|
||||
ImmediateOfferKilled
|
||||
XRPFees
|
||||
ExpandedSignerList
|
||||
fixNFTokenRemint
|
||||
# Additional Amendments
|
||||
BalanceRewards
|
||||
Hooks
|
||||
HooksUpdate1
|
||||
Import
|
||||
Remit
|
||||
URIToken
|
||||
XahauGenesis
|
||||
ZeroB2M
|
||||
fix240819
|
||||
fix240911
|
||||
fixFloatDivide
|
||||
fixNFTokenDirV1
|
||||
fixNFTokenNegOffer
|
||||
fixNSDelete
|
||||
fixPageCap
|
||||
fixReduceImport
|
||||
fixXahauV1
|
||||
fixXahauV2
|
||||
fixXahauV3
|
||||
PaychanAndEscrowForTokens
|
||||
DeepFreeze
|
||||
Clawback
|
||||
|
||||
[network_id]
|
||||
21337
|
||||
@@ -1,28 +0,0 @@
|
||||
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
|
||||
language: "en-US"
|
||||
reviews:
|
||||
# Set the profile for reviews. Assertive profile yields more feedback, that may be considered nitpicky.
|
||||
profile: "chill"
|
||||
# Approve the review once CodeRabbit's comments are resolved. Note: In GitLab, all discussions must be resolved.
|
||||
request_changes_workflow: false
|
||||
# Generate a high level summary of the changes in the PR/MR description.
|
||||
high_level_summary: false
|
||||
# Generate a poem in the walkthrough comment.
|
||||
poem: true
|
||||
# Post review details on each review. Additionally, post a review status when a review is skipped in certain cases.
|
||||
review_status: true
|
||||
# Generate walkthrough in a markdown collapsible section.
|
||||
collapse_walkthrough: false
|
||||
# Abort the in-progress review if the pull request is closed or merged.
|
||||
abort_on_close: true
|
||||
auto_review:
|
||||
# Automatic Review | Automatic code review
|
||||
enabled: true
|
||||
# Review draft PRs/MRs.
|
||||
drafts: false
|
||||
# Ignore reviewing if the title of the pull request contains any of these keywords (case-insensitive).
|
||||
ignore_title_keywords:
|
||||
- build(
|
||||
chat:
|
||||
# Enable the bot to reply automatically without requiring the user to tag it.
|
||||
auto_reply: true
|
||||
19
.flowconfig
Normal file
19
.flowconfig
Normal file
@@ -0,0 +1,19 @@
|
||||
[ignore]
|
||||
.*/ripple-lib/src/.*
|
||||
.*/ripple-lib/dist/.*
|
||||
.*/ripple-lib/test/fixtures/.*
|
||||
.*/node_modules/flow-bin/.*
|
||||
.*/node_modules/webpack/.*
|
||||
.*/node_modules/babel-core/.*
|
||||
.*/node_modules/babel-eslint/.*
|
||||
.*/node_modules/babel-preset-es2015/.*
|
||||
.*/node_modules/babel-preset-stage-1/.*
|
||||
.*/node_modules/babel-register/.*
|
||||
|
||||
[include]
|
||||
./node_modules/
|
||||
|
||||
[libs]
|
||||
|
||||
[options]
|
||||
module.system=node
|
||||
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@@ -1,8 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: weekly
|
||||
time: "15:00"
|
||||
open-pull-requests-limit: 10
|
||||
48
.github/pull_request_template.md
vendored
48
.github/pull_request_template.md
vendored
@@ -1,48 +0,0 @@
|
||||
## High Level Overview of Change
|
||||
|
||||
<!--
|
||||
Please include a summary/list of the changes.
|
||||
If too broad, please consider splitting into multiple PRs.
|
||||
If a relevant Asana task, please link it here.
|
||||
-->
|
||||
|
||||
### Context of Change
|
||||
|
||||
<!--
|
||||
Please include the context of a change.
|
||||
If a bug fix, when was the bug introduced? What was the behavior?
|
||||
If a new feature, why was this architecture chosen? What were the alternatives?
|
||||
If a refactor, how is this better than the previous implementation?
|
||||
|
||||
If there is a design document for this feature, please link it here.
|
||||
-->
|
||||
|
||||
### Type of Change
|
||||
|
||||
<!--
|
||||
Please check relevant options, delete irrelevant ones.
|
||||
-->
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
- [ ] Refactor (non-breaking change that only restructures code)
|
||||
- [ ] Tests (You added tests for code that already exists, or your new feature included in this PR)
|
||||
- [ ] Documentation Updates
|
||||
- [ ] Release
|
||||
|
||||
### Did you update HISTORY.md?
|
||||
|
||||
- [ ] Yes
|
||||
- [ ] No, this change does not impact library users
|
||||
|
||||
## Test Plan
|
||||
|
||||
<!--
|
||||
Please describe the tests that you ran to verify your changes and provide instructions so that others can reproduce.
|
||||
-->
|
||||
|
||||
<!--
|
||||
## Future Tasks
|
||||
For future tasks related to PR.
|
||||
-->
|
||||
65
.github/workflows/codeql-analysis.yml
vendored
65
.github/workflows/codeql-analysis.yml
vendored
@@ -1,65 +0,0 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: "44 5 * * 6"
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: ["javascript"]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
200
.github/workflows/nodejs.yml
vendored
200
.github/workflows/nodejs.yml
vendored
@@ -1,200 +0,0 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Node.js CI
|
||||
|
||||
env:
|
||||
XAHAUD_DOCKER_IMAGE: xahauci/xahaud:2025.7.9
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main-xahau, 1.x]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-lint:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Setup npm version 9
|
||||
run: |
|
||||
npm i -g npm@9 --registry=https://registry.npmjs.org
|
||||
|
||||
- name: Cache node modules
|
||||
id: cache-nodemodules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# caching node_modules
|
||||
path: |
|
||||
node_modules
|
||||
*/*/node_modules
|
||||
key: ${{ runner.os }}-deps-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-deps-${{ matrix.node-version }}-
|
||||
${{ runner.os }}-deps-
|
||||
|
||||
- name: Install Dependencies
|
||||
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
|
||||
run: npm ci
|
||||
|
||||
- run: npm run build
|
||||
- run: npm run lint
|
||||
|
||||
unit:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x, 20.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Setup npm version 9
|
||||
run: |
|
||||
npm i -g npm@9 --registry=https://registry.npmjs.org
|
||||
|
||||
- name: Cache node modules
|
||||
id: cache-nodemodules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# caching node_modules
|
||||
path: |
|
||||
node_modules
|
||||
*/*/node_modules
|
||||
key: ${{ runner.os }}-deps-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-deps-${{ matrix.node-version }}-
|
||||
${{ runner.os }}-deps-
|
||||
|
||||
- name: Install Dependencies
|
||||
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
|
||||
run: npm ci
|
||||
|
||||
- run: npm run build
|
||||
- run: npm test
|
||||
|
||||
integration:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x, 20.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Run docker in background
|
||||
run: |
|
||||
docker run --detach --rm --name xahaud-service -p 6006:6006 --volume "${{ github.workspace }}/.ci-config/":"/opt/xahau/etc/" --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s --env GITHUB_ACTIONS=true --env CI=true ${{ env.XAHAUD_DOCKER_IMAGE }} /opt/xahau/bin/xahaud -a --conf /opt/xahau/etc/xahaud.cfg
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Setup npm version 9
|
||||
run: |
|
||||
npm i -g npm@9 --registry=https://registry.npmjs.org
|
||||
|
||||
- name: Cache node modules
|
||||
id: cache-nodemodules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# caching node_modules
|
||||
path: |
|
||||
node_modules
|
||||
*/*/node_modules
|
||||
key: ${{ runner.os }}-deps-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-deps-${{ matrix.node-version }}-
|
||||
${{ runner.os }}-deps-
|
||||
|
||||
- name: Install Dependencies
|
||||
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
|
||||
run: npm ci
|
||||
|
||||
- run: npm run build
|
||||
|
||||
- name: Run integration test
|
||||
run: npm run test:integration
|
||||
|
||||
- name: Stop docker container
|
||||
if: always()
|
||||
run: docker stop xahaud-service
|
||||
|
||||
browser:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Run docker in background
|
||||
run: |
|
||||
docker run --detach --rm --name xahaud-service -p 6006:6006 --volume "${{ github.workspace }}/.ci-config/":"/opt/xahau/etc/" --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s --env GITHUB_ACTIONS=true --env CI=true ${{ env.XAHAUD_DOCKER_IMAGE }} /opt/xahau/bin/xahaud -a --conf /opt/xahau/etc/xahaud.cfg
|
||||
|
||||
- name: Setup npm version 9
|
||||
run: |
|
||||
npm i -g npm@9 --registry=https://registry.npmjs.org
|
||||
|
||||
- name: Cache node modules
|
||||
id: cache-nodemodules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# caching node_modules
|
||||
path: |
|
||||
node_modules
|
||||
*/*/node_modules
|
||||
key: ${{ runner.os }}-deps-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-deps-${{ matrix.node-version }}-
|
||||
${{ runner.os }}-deps-
|
||||
|
||||
- name: Install Dependencies
|
||||
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
|
||||
run: npm ci
|
||||
|
||||
- run: npm run build
|
||||
|
||||
- name: Run integration test
|
||||
run: npm run test:browser
|
||||
|
||||
- name: Stop docker container
|
||||
if: always()
|
||||
run: docker stop xahaud-service
|
||||
25
.gitignore
vendored
25
.gitignore
vendored
@@ -1,9 +1,5 @@
|
||||
# .gitignore
|
||||
|
||||
# Ignore package locks other than npm.
|
||||
yarn.lock
|
||||
npm-shrinkwrap.json
|
||||
|
||||
# Ignore vim swap files.
|
||||
*.swp
|
||||
|
||||
@@ -22,7 +18,6 @@ npm-shrinkwrap.json
|
||||
# Ignore object files.
|
||||
*.o
|
||||
build/
|
||||
coverage/
|
||||
tags
|
||||
bin/rippled
|
||||
Debug/*.*
|
||||
@@ -40,6 +35,8 @@ db/*.db
|
||||
db/*.db-*
|
||||
|
||||
# Ignore customized configs
|
||||
rippled.cfg
|
||||
validators.txt
|
||||
test/config.js
|
||||
|
||||
# Ignore coverage files
|
||||
@@ -50,27 +47,17 @@ test/config.js
|
||||
|
||||
# Ignore IntelliJ files
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
# Ignore npm-debug
|
||||
npm-debug.log
|
||||
|
||||
# Ignore dist folder, built from tsc
|
||||
# Ignore dist folder, build for bower
|
||||
dist/
|
||||
|
||||
# TypeScript incremental compilation cache
|
||||
*.tsbuildinfo
|
||||
# Ignore flow output directory
|
||||
out/
|
||||
|
||||
# Ignore perf test cache
|
||||
scripts/cache
|
||||
|
||||
.eslintrc
|
||||
|
||||
# nyc (istanbul)
|
||||
.nyc_output
|
||||
|
||||
# browser tests
|
||||
testCompiledForWeb
|
||||
|
||||
# lerna debug
|
||||
lerna-debug.log
|
||||
eslintrc
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"reject": [
|
||||
]
|
||||
}
|
||||
4
.npmignore
Normal file
4
.npmignore
Normal file
@@ -0,0 +1,4 @@
|
||||
lib-cov
|
||||
coverage.html
|
||||
src
|
||||
dist/bower
|
||||
@@ -1 +0,0 @@
|
||||
*.md
|
||||
6
.vscode/extensions.json
vendored
6
.vscode/extensions.json
vendored
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode"
|
||||
]
|
||||
}
|
||||
60
.vscode/settings.json
vendored
60
.vscode/settings.json
vendored
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"editor.tabSize": 2,
|
||||
"cSpell.words": [
|
||||
"altnet",
|
||||
"Autofills",
|
||||
"Clawback",
|
||||
"hostid",
|
||||
"keypair",
|
||||
"keypairs",
|
||||
"multisign",
|
||||
"multisigned",
|
||||
"multisigning",
|
||||
"preauthorization",
|
||||
"rippletest",
|
||||
"secp256k1",
|
||||
"Setf",
|
||||
"Sidechains",
|
||||
"xchain"
|
||||
],
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"[javascriptreact]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"[typescriptreact]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"eslint.alwaysShowStatus": true,
|
||||
"eslint.lintTask.enable": true,
|
||||
"eslint.codeAction.showDocumentation": {
|
||||
"enable": true
|
||||
},
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
},
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimFinalNewlines": true,
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"files.watcherExclude": {
|
||||
"**/.git/objects/**": true,
|
||||
"**/.git/subtree-cache/**": true,
|
||||
"**/.hg/store/**": true
|
||||
},
|
||||
"search.exclude": {
|
||||
"**/.git": true,
|
||||
"**/node_modules": true,
|
||||
"**/tmp": true,
|
||||
"**/docs/**/*.html": true,
|
||||
"**/fixtures/**/*.json": true,
|
||||
"**/docs/assets": true
|
||||
},
|
||||
}
|
||||
281
CONTRIBUTING.md
281
CONTRIBUTING.md
@@ -1,281 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
### High Level Process to Contribute Code
|
||||
|
||||
- You should open a PR against `main` and ensure that all CI passes.
|
||||
- Your changes should have [unit](#unit-tests) and/or [integration tests](#integration-tests).
|
||||
- Your changes should [pass the linter](#run-the-linter).
|
||||
- You should get a full code review from two of the maintainers.
|
||||
- Then you can merge your changes. (Which will then be included in the next release)
|
||||
|
||||
## Set up your dev environment
|
||||
|
||||
### Requirements
|
||||
|
||||
We use Node v18 for development - that is the version that our linters require.
|
||||
You must also use `npm` v7. You can check your `npm` version with:
|
||||
|
||||
```bash
|
||||
npm -v
|
||||
```
|
||||
|
||||
If your `npm` version is too old, use this command to update it:
|
||||
|
||||
```bash
|
||||
npm -g i npm@7
|
||||
```
|
||||
|
||||
### Set up
|
||||
|
||||
1. Clone the repository
|
||||
2. `cd` into the repository
|
||||
3. Install dependencies with `npm install`
|
||||
|
||||
### Build
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Run the linter
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run build
|
||||
npm run lint
|
||||
```
|
||||
|
||||
## Running Tests
|
||||
|
||||
For integration and browser tests, we use a `xahaud` node in standalone mode to test xahau.js code against. To set this up, you can either configure and run `xahaud` locally, or set up the Docker container `xahauci/xahaud` by [following these instructions](#integration-tests). The latter will require you to [install Docker](https://docs.docker.com/get-docker/).
|
||||
|
||||
### Unit Tests
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run build
|
||||
npm test
|
||||
```
|
||||
|
||||
### Integration Tests
|
||||
|
||||
From the top-level xahau.js folder (one level above `packages`), run the following commands:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
# sets up the xahaud standalone Docker container - you can skip this step if you already have it set up
|
||||
docker run -p 6006:6006 --interactive -t --volume $PWD/.ci-config:/opt/xahau/etc/ --platform linux/amd64 xahauci/xahaud:2025.2.6 /opt/xahau/bin/xahaud -a --conf /opt/xahau/etc/xahaud.cfg
|
||||
npm run build
|
||||
npm run test:integration
|
||||
```
|
||||
|
||||
Breaking down the command:
|
||||
* `docker run -p 6006:6006` starts a Docker container with an open port for admin WebSocket requests.
|
||||
* `--interactive` allows you to interact with the container.
|
||||
* `-t` starts a terminal in the container for you to send commands to.
|
||||
* `--volume $PWD/.ci-config:/config/` identifies the `xahaud.cfg` and `validators.txt` to import. It must be an absolute path, so we use `$PWD` instead of `./`.
|
||||
* `xahauci/xahaud` is an image that is regularly updated with the latest `xahaud` releases
|
||||
* `/opt/xahau/bin/xahaud -a --conf /opt/xahau/etc/xahaud.cfg` starts `xahaud` in standalone mode
|
||||
|
||||
### Browser Tests
|
||||
|
||||
There are two ways to run browser tests.
|
||||
|
||||
One is in the browser - run `npm run build:browserTests` and open `test/localIntegrationRunner.html` in your browser.
|
||||
|
||||
The other is in the command line (this is what we use for CI) -
|
||||
|
||||
This should be run from the `xahau.js` top level folder (one above the `packages` folder).
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
# sets up the xahaud standalone Docker container - you can skip this step if you already have it set up
|
||||
docker run -p 6006:6006 --interactive -t --volume $PWD/.ci-config:/opt/xahau/etc/ --platform linux/amd64 xahauci/xahaud:2025.2.6 /opt/xahau/bin/xahaud -a --conf /opt/xahau/etc/xahaud.cfg
|
||||
npm run test:browser
|
||||
```
|
||||
|
||||
## High Level Architecture
|
||||
|
||||
This is a monorepo, which means that there are multiple packages in a single GitHub repository using [Lerna](https://lerna.js.org/).
|
||||
|
||||
The 4 packages currently here are:
|
||||
|
||||
1. xahau.js - The client library for interacting with the ledger.
|
||||
2. xahau-binary-codec - A library for serializing and deserializing transactions for the ledger.
|
||||
3. xahau-keypairs - A library for generating and using cryptographic keypairs.
|
||||
4. xahau-address-codec - A library for encoding and decoding Xahau Ledger addresses and seeds.
|
||||
5. isomorphic - A collection of isomorphic implementations of crypto and utility functions.
|
||||
6. secret-numbers - Generate XRPL Accounts with a number-based secret: 8 chunks of 6 digits.
|
||||
|
||||
Each package has it's own README which dives deeper into what it's main purpose is, and the core functionality it offers.
|
||||
They also run tests independently as they were originally in separate repositories.
|
||||
|
||||
These are managed in a monorepo because often a change in a lower-level library will also require a change in xahau.js, and so it makes sense to be able to allow for modifications of all packages at once without coordinating versions across multiple repositories.
|
||||
|
||||
Let's dive a bit into how xahau.js is structured!
|
||||
|
||||
### The File Structure
|
||||
|
||||
Within the xrpl package, each folder has a specific purpose:
|
||||
|
||||
**Client** - This contains logic for handling the websocket connection to xahaud servers.
|
||||
**Models** - These types model LedgerObjects, Requests/Methods, and Transactions in order to give type hints and nice errors for users.
|
||||
**Sugar** - This is where handy helper functions end up, like `submit`, `autofill`, and `getXAHBalance` amongst others.
|
||||
**Utils** - These are shared functions which are useful for conversions, or internal implementation details within the library.
|
||||
**Wallet** - This logic handles managing keys, addresses, and signing within xahau.js
|
||||
|
||||
### Writing Tests for xahau.js
|
||||
|
||||
For every file in `src`, we try to have a corresponding file in `test` with unit tests.
|
||||
|
||||
The goal is to maintain above 80% code coverage, and generally any new feature or bug fix should be accompanied by unit tests, and integration tests if applicable.
|
||||
|
||||
For an example of a unit test, check out the [autofill tests here](./packages/xahau/test/client/autofill.ts).
|
||||
|
||||
If your code connects to the ledger (ex. Adding a new transaction type) it's handy to write integration tests to ensure that you can successfully interact with the ledger. Integration tests are generally run against a docker instance of xahaud which contains the latest updates. Since standalone mode allows us to manually close ledgers, this allows us to run integration tests at a much faster rate than if we had to wait 4-5 seconds per transaction for the ledger to validate the transaction. [See above](#running-tests) for how to start up the docker container to run integration tests.
|
||||
|
||||
All integration tests should be written in the `test/integration` folder, with new `Requests` and `Transactions` tests being in their respective folders.
|
||||
|
||||
For an example of how to write an integration test for `xahau.js`, you can look at the [Payment integration test](./packages/xahau/test/integration/transactions/payment.ts).
|
||||
|
||||
## Generate reference docs
|
||||
|
||||
You can see the complete reference documentation at [`xahau.js` docs](https://js.xrpl.org). You can also generate them locally using `typedoc`:
|
||||
|
||||
```bash
|
||||
npm run docgen
|
||||
```
|
||||
|
||||
This updates `docs/` at the top level, where GitHub Pages looks for the docs.
|
||||
|
||||
## Update `definitions.json`
|
||||
|
||||
Use [this repo](https://github.com/RichardAH/xrpl-codec-gen) to generate a new `definitions.json` file from the xahaud source code. Instructions are available in that README.
|
||||
|
||||
## Adding and removing packages
|
||||
|
||||
`xahau.js` uses `lerna` and `npm`'s workspaces features to manage a monorepo.
|
||||
Adding and removing packages requires a slightly different process than normal
|
||||
as a result.
|
||||
|
||||
### Adding or removing development dependencies
|
||||
|
||||
`xahau.js` strives to use the same development dependencies in all packages.
|
||||
You may add and remove dev dependencies like normal:
|
||||
|
||||
```bash
|
||||
### adding a new dependency
|
||||
npm install --save-dev abbrev
|
||||
### removing a dependency
|
||||
npm uninstall --save-dev abbrev
|
||||
```
|
||||
|
||||
### Adding or removing runtime dependencies
|
||||
|
||||
You need to specify which package is changing using the `-w` flag:
|
||||
|
||||
```bash
|
||||
### adding a new dependency to `xahau`
|
||||
npm install abbrev -w xahau
|
||||
### adding a new dependency to `xahau-keypairs`
|
||||
npm install abbrev -w xahau-keypairs
|
||||
### removing a dependency
|
||||
npm uninstall abbrev -w xahau
|
||||
```
|
||||
|
||||
## Updating the Docker container for CI
|
||||
|
||||
In order to test the library, we need to enable the latest amendments in the docker container.
|
||||
This requires updating the `/.ci-config/xahaud.cfg` file with the hashes and names of new amendments.
|
||||
|
||||
In order to update the list, follow these steps from the top level of the library:
|
||||
1. Run `node ./.ci-config/getNewAmendments.js`
|
||||
2. If there are any new amendment hashes, add a comment to the end of `/.ci-config/xahaud.cfg` with the date
|
||||
- `Ex. "# Added August 9th, 2023"`
|
||||
3. For each hash printed out by the script, add the hash and name to the config file.
|
||||
- Ex. `B2A4DB846F0891BF2C76AB2F2ACC8F5B4EC64437135C6E56F3F859DE5FFD5856 ExpandedSignerList`
|
||||
- You can look up the name by searching for the hash on https://xrpl.org/known-amendments.html
|
||||
4. Push your changes
|
||||
|
||||
Note: The same updated config can be used to update xahau-py's CI as well.
|
||||
|
||||
## Updating `definitions.json`
|
||||
|
||||
This should almost always be done using the [`xrpl-codec-gen`](https://github.com/RichardAH/xrpl-codec-gen) script - if the output needs manual intervention afterwards, consider updating the script instead.
|
||||
|
||||
1. Clone / pull the latest changes from [xahaud](https://github.com/XRPLF/xahaud) - Specifically the `develop` branch is usually the right one.
|
||||
2. Clone / pull the latest changes from [`xrpl-codec-gen`](https://github.com/RichardAH/xrpl-codec-gen)
|
||||
3. From the `xrpl-codec-gen` tool, follow the steps in the `README.md` to generate a new `definitions.json` file.
|
||||
4. Replace the `definitions.json` file in the `xahau-binary-codec` with the newly generated file.
|
||||
5. Verify that the changes make sense by inspection before submitting, as there may be updates required for the `xrpl-codec-gen` tool depending on the latest amendments we're updating to match.
|
||||
|
||||
|
||||
## Release process + checklist
|
||||
|
||||
## PR process
|
||||
|
||||
- [ ] Your changes should be on a branch.
|
||||
- [ ] Your changes should have unit tests.
|
||||
- [ ] Lint the code with `npm lint`
|
||||
- [ ] Build your code with `npm build`
|
||||
- [ ] Run the unit tests with `npm test`
|
||||
- [ ] Get a full code review.
|
||||
- [ ] Merge your branch into `main` and push to github.
|
||||
- [ ] Ensure that all tests passed on the last CI that ran on `main`.
|
||||
|
||||
## Release
|
||||
|
||||
1. Checkout `main` (or your beta branch) and `git pull`.
|
||||
2. Create a new branch (`git checkout -b <BRANCH_NAME>`) to capture updates that take place during this process.
|
||||
3. Update `HISTORY.md` to reflect release changes.
|
||||
|
||||
- [ ] Update the version number and release date, and ensure it lists the changes since the previous release.
|
||||
|
||||
4. Run `npm run docgen` if the docs were modified in this release to update them (skip this step for a beta).
|
||||
5. Run `npm run clean` to delete previously generated artifacts.
|
||||
6. Run `npm run build` to triple check the build still works
|
||||
7. Run `npx lerna version --no-git-tag-version` - This bumps the package versions.
|
||||
|
||||
- For each changed package, pick what the new version should be. Lerna will bump the versions, commit version bumps to `main`, and create a new git tag for each published package.
|
||||
- If you do NOT want to update the package number, choose "Custom Version" and set the version to be the same as the existing version. Lerna will not publish any changes in this case.
|
||||
- If publishing a beta, make sure that the versions are all of the form `a.b.c-beta.d`, where `a`, `b`, and `c` are identical to the last normal release except for one, which has been incremented by 1.
|
||||
|
||||
8. Run `npm i` to update the package-lock with the updated versions.
|
||||
9. Create a new PR from this branch into `main` and merge it (you can directly merge into the beta branch for a beta).
|
||||
10. Checkout `main` and `git pull` (you can skip this step for a beta since you already have the latest version of the beta branch).
|
||||
11. Actually publish the packages with one of the following:
|
||||
|
||||
- Stable release: Run `npx lerna publish from-package --yes`
|
||||
- Beta release: Run `npx lerna publish from-package --dist-tag beta --yes`
|
||||
Notice this allows developers to install the package with `npm add xahau@beta`
|
||||
|
||||
12. If requested, enter your [npmjs.com](https://npmjs.com) OTP (one-time password) to complete publication.
|
||||
|
||||
NOW YOU HAVE PUBLISHED! But you're not done; we have to notify people!
|
||||
|
||||
13. Run `git tag <tagname> -m <tagname>`, where `<tagname>` is the new package and version (e.g. `xahau@2.1.1`), for each version released.
|
||||
14. Run `git push --follow-tags`, to push the tags to Github.
|
||||
15. On GitHub, click the "Releases" link on the right-hand side of the page.
|
||||
|
||||
16. Repeat for each release:
|
||||
|
||||
1. Click "Draft a new release"
|
||||
2. Click "Choose a tag", and choose a tag that you just created.
|
||||
3. Edit the name of the release to match the tag (IE \<package\>@\<version\>) and edit the description as you see fit.
|
||||
|
||||
17. Send an email to [xahau-announce](https://groups.google.com/g/xahau-announce).
|
||||
18. Lastly, send a similar message to the Xahau Discord in the [`javascript` channel](https://discord.com/channels/1085202760548499486/1085203623111295068). The message should include:
|
||||
1. The version changes for xahau libraries
|
||||
2. A link to the more detailed changes
|
||||
3. Highlights of important changes
|
||||
|
||||
|
||||
## Mailing Lists
|
||||
|
||||
We have a low-traffic mailing list for announcements of new `xahau.js` releases. (About 1 email every couple of weeks)
|
||||
|
||||
- [Subscribe to xahau-announce](https://groups.google.com/g/xahau-announce)
|
||||
|
||||
If you're using the Xahau Ledger in production, you should run a [xahaud server](https://github.com/xahau/xahaud) and subscribe to the xahau-server mailing list as well.
|
||||
|
||||
- [Subscribe to xahau-server](https://groups.google.com/g/xahau-server)
|
||||
209
Gulpfile.js
Normal file
209
Gulpfile.js
Normal file
@@ -0,0 +1,209 @@
|
||||
/* eslint-disable no-var, no-param-reassign */
|
||||
/* these eslint rules are disabled because gulp does not support babel yet */
|
||||
'use strict';
|
||||
var _ = require('lodash');
|
||||
var gulp = require('gulp');
|
||||
var uglify = require('gulp-uglify');
|
||||
var rename = require('gulp-rename');
|
||||
var webpack = require('webpack');
|
||||
var bump = require('gulp-bump');
|
||||
var argv = require('yargs').argv;
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
|
||||
var pkg = require('./package.json');
|
||||
|
||||
var uglifyOptions = {
|
||||
mangle: {
|
||||
except: ['_', 'RippleError', 'RippledError', 'UnexpectedError',
|
||||
'LedgerVersionError', 'ConnectionError', 'NotConnectedError',
|
||||
'DisconnectedError', 'TimeoutError', 'ResponseFormatError',
|
||||
'ValidationError', 'NotFoundError', 'MissingLedgerHistoryError',
|
||||
'PendingLedgerVersionError'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
function webpackConfig(extension, overrides) {
|
||||
overrides = overrides || {};
|
||||
var defaults = {
|
||||
cache: true,
|
||||
externals: [{
|
||||
'lodash': '_'
|
||||
}],
|
||||
entry: './src/index.js',
|
||||
output: {
|
||||
library: 'ripple',
|
||||
path: './build/',
|
||||
filename: ['ripple-', extension].join(pkg.version)
|
||||
},
|
||||
plugins: [
|
||||
new webpack.NormalModuleReplacementPlugin(/^ws$/, './wswrapper'),
|
||||
new webpack.NormalModuleReplacementPlugin(/^\.\/wallet$/, './wallet-web'),
|
||||
new webpack.NormalModuleReplacementPlugin(/^.*setup-api$/,
|
||||
'./setup-api-web')
|
||||
],
|
||||
module: {
|
||||
loaders: [{
|
||||
test: /jayson/,
|
||||
loader: 'null'
|
||||
}, {
|
||||
test: /\.js$/,
|
||||
exclude: [/node_modules/],
|
||||
loader: 'babel-loader'
|
||||
}, {
|
||||
test: /\.json/,
|
||||
loader: 'json-loader'
|
||||
}]
|
||||
}
|
||||
};
|
||||
return _.assign({}, defaults, overrides);
|
||||
}
|
||||
|
||||
function webpackConfigForWebTest(testFileName, path) {
|
||||
var match = testFileName.match(/\/?([^\/]*)-test.js$/);
|
||||
if (!match) {
|
||||
assert(false, 'wrong filename:' + testFileName);
|
||||
}
|
||||
var configOverrides = {
|
||||
externals: [{
|
||||
'lodash': '_',
|
||||
'ripple-api': 'ripple',
|
||||
'net': 'null'
|
||||
}],
|
||||
entry: testFileName,
|
||||
output: {
|
||||
library: match[1].replace(/-/g, '_'),
|
||||
path: './test-compiled-for-web/' + (path ? path : ''),
|
||||
filename: match[1] + '-test.js'
|
||||
}
|
||||
};
|
||||
return webpackConfig('.js', configOverrides);
|
||||
}
|
||||
|
||||
gulp.task('build-tests', function(callback) {
|
||||
var times = 0;
|
||||
function done() {
|
||||
if (++times >= 5) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
webpack(webpackConfigForWebTest('./test/rangeset-test.js'), done);
|
||||
webpack(webpackConfigForWebTest('./test/connection-test.js'), done);
|
||||
webpack(webpackConfigForWebTest('./test/api-test.js'), done);
|
||||
webpack(webpackConfigForWebTest('./test/broadcast-api-test.js'), done);
|
||||
webpack(webpackConfigForWebTest('./test/integration/integration-test.js',
|
||||
'integration/'), done);
|
||||
});
|
||||
|
||||
function createLink(from, to) {
|
||||
if (fs.existsSync(to)) {
|
||||
fs.unlinkSync(to);
|
||||
}
|
||||
fs.linkSync(from, to);
|
||||
}
|
||||
|
||||
function createBuildLink(callback) {
|
||||
return function(err, res) {
|
||||
createLink('./build/ripple-' + pkg.version + '.js',
|
||||
'./build/ripple-latest.js');
|
||||
callback(err, res);
|
||||
};
|
||||
}
|
||||
|
||||
gulp.task('build', function(callback) {
|
||||
webpack(webpackConfig('.js'), createBuildLink(callback));
|
||||
});
|
||||
|
||||
gulp.task('build-min', ['build'], function() {
|
||||
return gulp.src(['./build/ripple-', '.js'].join(pkg.version))
|
||||
.pipe(uglify(uglifyOptions))
|
||||
.pipe(rename(['ripple-', '-min.js'].join(pkg.version)))
|
||||
.pipe(gulp.dest('./build/'))
|
||||
.on('end', function() {
|
||||
createLink('./build/ripple-' + pkg.version + '-min.js',
|
||||
'./build/ripple-latest-min.js');
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('build-debug', function(callback) {
|
||||
var configOverrides = {debug: true, devtool: 'eval'};
|
||||
webpack(webpackConfig('-debug.js', configOverrides), callback);
|
||||
});
|
||||
|
||||
/**
|
||||
* Generate a WebPack external for a given unavailable module which replaces
|
||||
* that module's constructor with an error-thrower
|
||||
*/
|
||||
|
||||
function buildUseError(cons) {
|
||||
return ('var {<CONS>:function(){throw new Error('
|
||||
+ '"Class is unavailable in this build: <CONS>")}}')
|
||||
.replace(new RegExp('<CONS>', 'g'), cons);
|
||||
}
|
||||
|
||||
gulp.task('build-core', function(callback) {
|
||||
var configOverrides = {
|
||||
cache: false,
|
||||
entry: './src/remote.js',
|
||||
externals: [{
|
||||
'./transaction': buildUseError('Transaction'),
|
||||
'./orderbook': buildUseError('OrderBook'),
|
||||
'./account': buildUseError('Account'),
|
||||
'./serializedobject': buildUseError('SerializedObject')
|
||||
}],
|
||||
plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin()
|
||||
]
|
||||
};
|
||||
webpack(webpackConfig('-core.js', configOverrides), callback);
|
||||
});
|
||||
|
||||
gulp.task('bower-build', ['build'], function() {
|
||||
return gulp.src(['./build/ripple-', '.js'].join(pkg.version))
|
||||
.pipe(rename('ripple.js'))
|
||||
.pipe(gulp.dest('./dist/bower'));
|
||||
});
|
||||
|
||||
gulp.task('bower-build-min', ['build-min'], function() {
|
||||
return gulp.src(['./build/ripple-', '-min.js'].join(pkg.version))
|
||||
.pipe(rename('ripple-min.js'))
|
||||
.pipe(gulp.dest('./dist/bower'));
|
||||
});
|
||||
|
||||
gulp.task('bower-build-debug', ['build-debug'], function() {
|
||||
return gulp.src(['./build/ripple-', '-debug.js'].join(pkg.version))
|
||||
.pipe(rename('ripple-debug.js'))
|
||||
.pipe(gulp.dest('./dist/bower'));
|
||||
});
|
||||
|
||||
gulp.task('bower-version', function() {
|
||||
gulp.src('./dist/bower/bower.json')
|
||||
.pipe(bump({version: pkg.version}))
|
||||
.pipe(gulp.dest('./dist/bower'));
|
||||
});
|
||||
|
||||
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug',
|
||||
'bower-version']);
|
||||
|
||||
gulp.task('watch', function() {
|
||||
gulp.watch('src/*', ['build-debug']);
|
||||
});
|
||||
|
||||
gulp.task('version-bump', function() {
|
||||
if (!argv.type) {
|
||||
throw new Error('No type found, pass it in using the --type argument');
|
||||
}
|
||||
|
||||
gulp.src('./package.json')
|
||||
.pipe(bump({type: argv.type}))
|
||||
.pipe(gulp.dest('./'));
|
||||
});
|
||||
|
||||
gulp.task('version-beta', function() {
|
||||
gulp.src('./package.json')
|
||||
.pipe(bump({version: pkg.version + '-beta'}))
|
||||
.pipe(gulp.dest('./'));
|
||||
});
|
||||
|
||||
gulp.task('default', ['build', 'build-debug', 'build-min']);
|
||||
526
HISTORY.md
526
HISTORY.md
@@ -1,12 +1,518 @@
|
||||
# Release History (Changelog)
|
||||
##0.16.5
|
||||
**Changes**
|
||||
+ [Filter insufficient source funds paths from pathfind results](https://github.com/ripple/ripple-lib/pull/688)
|
||||
|
||||
Please see the individual HISTORY.md and XAHAU_HISTORY.md documents in each package for changes:
|
||||
##0.16.4
|
||||
**Changes**
|
||||
+ [Update ws to 1.0.1](https://github.com/ripple/ripple-lib/pull/682)
|
||||
|
||||
##0.16.2
|
||||
**Changes**
|
||||
+ [Bump ripple-binary-codec dependency version to 0.1.1 to fix issue with computeLedgerHash for transactions with DeliverMin]
|
||||
|
||||
##0.16.1
|
||||
**Changes**
|
||||
+ [FIX: Use assert not assert-diff](https://github.com/ripple/ripple-lib/commit/f6ebe325193e7208c5ee8d8e84a7504714f0009e)
|
||||
|
||||
##0.16.0
|
||||
**Breaking Changes**
|
||||
+ [Fix types of XRP values in getServerInfo response](https://github.com/ripple/ripple-lib/commit/99d08065e4bda3dda6ae1f183adbd11abc70a9b7)
|
||||
+ [Change error event format and fix crash due to error event on webscocket](https://github.com/ripple/ripple-lib/commit/9cd72595f0efc062d77b9d625695d6030c524cc6)
|
||||
|
||||
**Changes**
|
||||
+ [Fix generateAddress docs and add error event listener to boilerplate](https://github.com/ripple/ripple-lib/commit/809d981987a2890fac3a73a40a05c598b9040334)
|
||||
+ [Allow setting maxLedgerVersion to null to specify no maximum](https://github.com/ripple/ripple-lib/commit/82613e7e8b360d1ae1552eab4559ab4763c06d7e)
|
||||
+ [Add support for client certificates](https://github.com/ripple/ripple-lib/commit/5f5e48e4140345d166b8c1a3ee0847b0d9e2d893)
|
||||
+ [getFee returns a string not float](https://github.com/ripple/ripple-lib/commit/7bf2da6014c87e164542e69356efeaabb575a157)
|
||||
+ [Fix parsing of quality for getTrustlines](https://github.com/ripple/ripple-lib/commit/86ff315ef2a39dfdc2ce97e0e1c4aa73f04e363b)
|
||||
+ [Fix DeliverMin value when specifying minAmount](Fix DeliverMin value when specifying minAmount)
|
||||
+ [http server example](https://github.com/ripple/ripple-lib/commit/76866ab901ea46a2dd73181605e0f7f4220043d4)
|
||||
|
||||
|
||||
##0.15.2
|
||||
**Changes**
|
||||
+ [Fix support for proxy credentials in proxy URL and fix error when there are more than 10 outstanding requests](https://github.com/ripple/ripple-lib/commit/0990ad4a6f1d59ca9d2cb859b4e2d71693f3fc4b)
|
||||
|
||||
##0.15.1
|
||||
**Changes**
|
||||
+ [Fix babel-polyfill require](https://github.com/ripple/ripple-lib/commit/062148674c3b1293ab82c28e25615ddd530339fa)
|
||||
+ [Fix samples](https://github.com/ripple/ripple-lib/commit/5d5cf868a2ddb1b1cd40e4a4f0a782d0066c2055)
|
||||
+ [add unit tests for RippleAPIBroadcast](https://github.com/ripple/ripple-lib/commit/ddf8fe5b1a9c750490dca98fb9ffaaf8017f87e0)
|
||||
|
||||
##0.15.0
|
||||
**Breaking Changes**
|
||||
+ ["servers" parameter changed to single "server"](https://github.com/ripple/ripple-lib/commit/7061e9afe46f0682254d098adeff3dd7157521a1)
|
||||
|
||||
**Changes**
|
||||
+ [fix handling memos in prepareSettings](https://github.com/ripple/ripple-lib/commit/c9704137b7b538e8dbf31c483bcdcf2dcfd7cd75)
|
||||
+ [Docs: SusPay warnings, offline mode, and other tweaks](https://github.com/ripple/ripple-lib/commit/4b4fc36ebd93f1360781a65f2869bd2c4f0a5093)
|
||||
+ [Fix prepareOrderCancellation documentation](https://github.com/ripple/ripple-lib/commit/5e720891f579fd73d43c64e5ec519d9121023c10)
|
||||
|
||||
##0.14.0
|
||||
**Breaking Changes**
|
||||
+ [prepareOrderCancellation now takes orderCancellation specification](https://github.com/ripple/ripple-lib/commit/7f33d8a71e56289e5a5e0ead1c74f75ebcde72bc)
|
||||
+ [Rename "ledgerClosed" event to "ledger" and change format](https://github.com/ripple/ripple-lib/commit/8a3d4a64db5fbf560ebf87dc62e0212513c5e18a)
|
||||
|
||||
**Changes**
|
||||
+ [Fix proxy support and add support for proxy authorization](https://github.com/ripple/ripple-lib/commit/14b840f3feca758e0384b746c94e36d8bf59b8c2)
|
||||
+ [Fix trace option](https://github.com/ripple/ripple-lib/commit/af620755c53556c55eed12de4b0013ef5a349ce2)
|
||||
+ [Allow memos on all transaction types](https://github.com/ripple/ripple-lib/commit/b5081344da8e66fbd3a5113cc3313325ef72a494)
|
||||
+ [Add documentation for RippleAPI options](https://github.com/ripple/ripple-lib/commit/a76b554cadb9f9f918b06f8386bc29355682a1a4)
|
||||
+ [Docs: more on basic types, tx types](https://github.com/ripple/ripple-lib/commit/fdbac63f466b4fd3be701d4878800d856692e26e)
|
||||
+ [Docs: revised introductory material](https://github.com/ripple/ripple-lib/commit/ef2515507dbd3c6a426ab5b31332a1bdf72d5b2d)
|
||||
+ [boost coverage to almost 100%](https://github.com/ripple/ripple-lib/commit/995606b1e6f3643af34d9fd442ccd31f320b03eb)
|
||||
|
||||
##0.13.2
|
||||
|
||||
**Changes**
|
||||
+ [Fix: Specify send_max when pathfinding with a source amount](https://github.com/ripple/ripple-lib/commit/75142139184625c8b9fcc480b1825d9985337813)
|
||||
|
||||
##0.13.1
|
||||
+ [Add documentation for API events](https://github.com/ripple/ripple-lib/commit/25d1ac0c5f95cad32ea4ceebb))
|
||||
|
||||
**Changes**
|
||||
+ [Fix: Add babel-polyfill](https://github.com/ripple/ripple-lib/commit/8a53abc32f6ec6c7d50cd182492d6fb511b86704)
|
||||
+ [Fix: Bump version on ripple-hashes](https://github.com/ripple/ripple-lib/commit/12e5765c64aea31b3c2fb65ff989cf01e6368f58)
|
||||
|
||||
##0.13.0
|
||||
|
||||
**Breaking Changes**
|
||||
+ Add new RippleAPI interface and delete old API
|
||||
- [RippleAPI README and samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
|
||||
- [Method documentation](https://rawgit.com/ripple/ripple-lib/develop/docs/api.html)
|
||||
|
||||
**Changes**
|
||||
+ [Removed timeout method of Request and added default timeout](https://github.com/ripple/ripple-lib/commit/634fe5683a9082e57682ff7d5c4fb9483b4af818)
|
||||
+ [Add Remote.closeCurrentPathFind function, so current pathfind can be properly closed](https://github.com/ripple/ripple-lib/commit/e99010f363fc7cbe7fd547d3ca5b32ea083c44e6)
|
||||
+ [Implement Balance Sheet API](https://github.com/ripple/ripple-lib/pull/579)
|
||||
+ [Fix bugs in orderbook subscription](https://github.com/ripple/ripple-lib/commit/7404795dc64a85216148de7bc3ca7da7b33f4490)
|
||||
+ [Fix crash due to rippled slowDown error](https://github.com/ripple/ripple-lib/commit/84838b2e9f6969b593b8462a62a6b8f516ada937)
|
||||
+ [Fix: Emit error events and return error on pathfind](https://github.com/ripple/ripple-lib/commit/1ccbaf677631a1944eb05d90f7afc5f3690a03dd)
|
||||
+ [Deprecate core and remove snake case method copying](https://github.com/ripple/ripple-lib/commit/fb8dc44ec1d49bb05cd0cdbe6dd4ab211195868a)
|
||||
|
||||
+ [Fix RangeSet for validated_ledger as single ledger](https://github.com/ripple/ripple-lib/commit/9f9e76f8b933201651af59307135f67cfa7d60e8)
|
||||
+ [Fix bug where the paths would be set with an empty array](https://github.com/ripple/ripple-lib/commit/83874ec0962da311b76f2385623e51c68bc39035)
|
||||
+ [Fix reserve calculation](https://github.com/ripple/ripple-lib/commit/52879febb92d876f01f2e4d70871baa07af631fb)
|
||||
|
||||
##0.12.9
|
||||
|
||||
+ [OrderBook performance optimizations](https://github.com/ripple/ripple-lib/commit/3e17d91edf36745f6b6c09b0ad88971b7775f6ab)
|
||||
|
||||
##0.12.7 and 0.12.8
|
||||
|
||||
+ [Improve performance of orderbook](https://github.com/ripple/ripple-lib/commit/c745faaaf0956ca98448a754b4fe97fb50574fc7)
|
||||
|
||||
+ [Remove Firefox warning about prototype overwrite](https://github.com/ripple/ripple-lib/commit/0c62fa21123b220b066871e1c41a3b4fe6f51885)
|
||||
|
||||
+ [Fix compare bug in Amount class](https://github.com/ripple/ripple-lib/commit/806547dd154e1b0bf252e8a74ad3ac6aa8a97660)
|
||||
|
||||
##0.12.6
|
||||
|
||||
+ [Fix webpack require failure due to "./" notation](https://github.com/ripple/ripple-lib/commit/8d9746d7b10be203ee613df523c2522012ff1baf)
|
||||
|
||||
##0.12.15
|
||||
|
||||
+ [Add offer autobridging](https://github.com/ripple/ripple-lib/commit/c7bbce83719c1e8c6a4fae5ca850e7515db1a4a5)
|
||||
|
||||
+ [Prevent crash when listening for "model" events on the OrderBook class](https://github.com/ripple/ripple-lib/commit/5824c3cb7cb6bd834d6e037f69943aebf3d83351)
|
||||
|
||||
+ [Fix empty order edgecase](https://github.com/ripple/ripple-lib/commit/64809d9ae23dc24f47accd4b4788b48f49880d3e)
|
||||
|
||||
+ [Fix AutobridgeCalculator (RT-3445)](https://github.com/ripple/ripple-lib/commit/1fff5ea6dcbcee856536df26f3b9cf1aec3c3b55)
|
||||
|
||||
+ [Update sjcl and delete custom ripemd160, montgomery, and jacobi](https://github.com/ripple/ripple-lib/commit/50cda426eb83599c38c0b725e1524a01fc415da2)
|
||||
|
||||
+ [Fix transaction summary for transactions that fail with remoteError](https://github.com/ripple/ripple-lib/commit/5e714f6143464d7912f42537acaa553b88eaf6dc)
|
||||
|
||||
+ [Fix serializedobject append for excessively large bytes length](https://github.com/ripple/ripple-lib/commit/e93f1ab6f4aaad347450aee75a169af0faa2121c)
|
||||
|
||||
+ [Switch to sjcl npm module](https://github.com/ripple/ripple-lib/commit/9a502580fd89ec6a9aa55f4e5847f6a4a2cb5bba)
|
||||
|
||||
+ [Add babel transpiler](https://github.com/ripple/ripple-lib/commit/398f8d001f758bf575b959537a17e79e4042d17b)
|
||||
|
||||
+ [Remove unused float.js and wallet.js](https://github.com/ripple/ripple-lib/commit/d4a4b5f4fbbf09677a59ce81bace35c6426a2fda)
|
||||
|
||||
+ [Remove config singleton to reduce global state](https://github.com/ripple/ripple-lib/commit/c655c2a20ee5d150a4b5a1b6717b9fb81f636025)
|
||||
|
||||
##0.12.4
|
||||
|
||||
+ [Improve entropy security](https://github.com/ripple/ripple-lib/commit/c7ba822320880037796f57876d1abb4e525648ed)
|
||||
|
||||
+ [Remove unused crypt.js file](https://github.com/ripple/ripple-lib/commit/1f68eba1461bca03a4d22872450d15ae5a185334)
|
||||
|
||||
##0.12.3
|
||||
|
||||
+ [Add getLedgerSequence to Remote](https://github.com/ripple/ripple-lib/commit/d09548d04d3238fca653d482ec1d5faa7254559a)
|
||||
|
||||
+ [Improve randomness when generating ECDSA signatures](https://github.com/ripple/ripple-lib/commit/fe7e30b737ead6e71adfa466f5835ba546feab31)
|
||||
|
||||
+ [Improve SerializedObject.append performance](https://github.com/ripple/ripple-lib/commit/f7c35b118ebba549a64bcaa1a0629385ec6dbf6f)
|
||||
|
||||
+ [Add `Amount.scale`. Multiply an amount’s value by a scale factor](https://github.com/ripple/ripple-lib/commit/74dac97b368493056474468520f05671f458a69f)
|
||||
|
||||
|
||||
##0.12.2
|
||||
|
||||
+ [Check that stack trace is available, fixes logging in browser](https://github.com/ripple/ripple-lib/commit/53cae3a66d48e88e8a6bbb96d6489ce7b9e22975)
|
||||
|
||||
|
||||
##0.12.1
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
+ [Removed support for parsing native amounts in floating point format](https://github.com/ripple/ripple-lib/commit/e80cd1ff55deae9cd5b0ae85be957f86856b887e)
|
||||
|
||||
|
||||
**Changes**
|
||||
|
||||
+ [Fix taker pays funded calculation](https://github.com/ripple/ripple-lib/commit/5af824f5cf46c7b9caa58ee0a757bf854d26c8dc)
|
||||
|
||||
+ [Fix order funded amount calculation](https://github.com/ripple/ripple-lib/commit/b2cdb1a6aed968b1f306e8dadbd4b7ca37e5aa03)
|
||||
|
||||
+ [Fix handling of quality in order book](https://github.com/ripple/ripple-lib/commit/2a5a8b498da60df738ba18d5c265f34771e8a1af)
|
||||
|
||||
+ [Fix currency parsing of non-alphanumeric and no-currency currencies](https://github.com/ripple/ripple-lib/commit/2166bb2e88eae8d5f1aba77338f69e8a9edf6a6f)
|
||||
|
||||
+ [Add Amount.strict_mode for toggling range validation](https://github.com/ripple/ripple-lib/commit/b5ed8f59a7dab1a17491618b8d9193646c314fb4)
|
||||
|
||||
+ [Add filename and line number to log, use log.warn() for deprecations](https://github.com/ripple/ripple-lib/commit/90329d3d73f1a76675063655b407513e32dc048b)
|
||||
|
||||
+ [Add GlobalFreeze and NoFreeze flags](https://github.com/ripple/ripple-lib/commit/e2ed2bdbf6f01c7d4d690c2cf0b83fba94558dd7)
|
||||
|
||||
+ [Fix handling of falsy parameters in requestLedger](https://github.com/ripple/ripple-lib/commit/6023efed41b7812b3bab660a1c0dc9f0a21000b9)
|
||||
|
||||
+ [Fix Base:decode](https://github.com/ripple/ripple-lib/commit/719f39c01c6941d9a650aa94f95617793dd53ea0)
|
||||
|
||||
+ [Fix Amount: clone in ratio_human, product_human](https://github.com/ripple/ripple-lib/commit/19e17a8431550cf156b1ad669a19dedfe4e28e4a)
|
||||
|
||||
+ [Fix Amount.to_human for very small numbers](https://github.com/ripple/ripple-lib/commit/6abfa759aa09d68074ac558d96c4b126a7cd1719)
|
||||
|
||||
+ [Refactor base conversion](https://github.com/ripple/ripple-lib/commit/f2b63fa4a80663eb29472bc6bb1aea8159f1f205)
|
||||
|
||||
+ [Update binary transaction format](https://github.com/ripple/ripple-lib/commit/8e134918fb4c22983320a3102f955e4568bb1dfb)
|
||||
|
||||
+ [Add DefaultRipple account flag](https://github.com/ripple/ripple-lib/commit/3e249902c4cf25b4da5e75048c84ae391be83b10)
|
||||
|
||||
+ [Remove `Features` field requirement in `SetFee` transaction format](https://github.com/ripple/ripple-lib/commit/a20a649013646710c078d4ce1e210f87c7fe74fe)
|
||||
|
||||
+ [Remove `RegularKey` field requirement in `SetRegularKey` transaction format](https://github.com/ripple/ripple-lib/commit/c275174f27877ba8f389eb4efe969feb514d6e46)
|
||||
|
||||
|
||||
##0.12.0
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
+ REMOVED Remote storage interface
|
||||
+ REMOVED Remote `ping` configuration
|
||||
+ REMOVED Old/deprecated Remote server configuration (websocket_ip, websocket_port)
|
||||
+ REMOVED browser `online` reconnect listener
|
||||
- [Cleanup, deprecations - 2833a7b6](https://github.com/ripple/ripple-lib/commit/2833a7b66e696dab427464625077f9b93092d0d5)
|
||||
|
||||
+ Remove `jsbn` and use `bignumber.js` instead for big number math
|
||||
+ The `allow_nan` flag has been removed. Results for invalid amounts will always be `NaN`
|
||||
- [Refactor to use bignumber.js - d025b4a0](https://github.com/ripple/ripple-lib/commit/d025b4a0c3a98a6de27a1bee9573c85347bcd66b)
|
||||
- [Handle invalid input in parse_human - c8f18c8c](https://github.com/ripple/ripple-lib/commit/c8f18c8c8590b7b48e370e0325b6677b7720294f)
|
||||
- [Check for null in isNumber - b86790c8](https://github.com/ripple/ripple-lib/commit/b86790c8543c239a532fd7697d4652829019d385)
|
||||
- [Cleanup amount.js - d0fb291c](https://github.com/ripple/ripple-lib/commit/d0fb291c4e330193a244902156f1d74730da357d)
|
||||
|
||||
|
||||
**Changes**
|
||||
|
||||
+ [Add deprecation warnings to request constructors. The first argument to request constructor functions should be an object containing request properties](https://github.com/ripple/ripple-lib/commit/35d76b3520934285f80059c1badd6c522539104c)
|
||||
|
||||
+ [Fix taker_gets_funded exceeding offer.TakerGets](https://github.com/ripple/ripple-lib/commit/b19ecb4482b589d575382b7a5d0480b963383bb1)
|
||||
|
||||
+ [Fix unsymmetric memo serializing](https://github.com/ripple/ripple-lib/commit/1ed36fabdbd54f4d31078c2b0eaa3becc0fe2821)
|
||||
|
||||
+ [Fix IOU value passed to `Amount.from_json()`](https://github.com/ripple/ripple-lib/commit/fd1b64393dffb3d1819cd40b8d43df43a4db042d)
|
||||
|
||||
+ [Update transaction binary parsing to account for XRP delivered amounts](https://github.com/ripple/ripple-lib/commit/35a346a674e6ee1e1e495db93700d55984efc7dd)
|
||||
|
||||
+ [Bumped dependencies](https://github.com/ripple/ripple-lib/commit/f9bc7cc746b44b24b61bbe260ae2e9d9617286da)
|
||||
|
||||
|
||||
|
||||
##0.11.0
|
||||
|
||||
+ [Track the funded status of an order based on cumulative account orders](https://github.com/ripple/ripple-lib/commit/67d39737a4d5e0fcd9d9b47b9083ee00e5a9e652) and [67d3973](https://github.com/ripple/ripple-lib/commit/b6b99dde022e1e14c4797e454b1d7fca50e49482)
|
||||
|
||||
+ Remove blobvault client from ripple-lib, use the [`ripple-vault-client`](https://github.com/ripple/ripple-vault-client) instead [9b3d62b7](https://github.com/ripple/ripple-lib/commit/9b3d62b765c4c25beae6eb0fa57ef3a07f2581b1)
|
||||
|
||||
+ [Add support for `ledger` option in requestBookOffers](https://github.com/ripple/ripple-lib/commit/34c0677c453c409ef0a5b351959abdc176d3bacb)
|
||||
|
||||
+ [Add support for `limit` option in requestBookOffers](https://github.com/ripple/ripple-lib/commit/d1d4452217c878d0b377d24830b4cd8b3162f6e0)
|
||||
|
||||
+ [Add `ledgerSelect` request constructor in `Remote`](https://github.com/ripple/ripple-lib/commit/98f40abfc3aa74dec5067a2d90002756cc8acd01)
|
||||
|
||||
+ [Default to binary data for commands that accept the binary flag](https://github.com/ripple/ripple-lib/commit/7cb113fcbcfc1e3e9830a999148b3e78df3387cc)
|
||||
|
||||
+ [Fix metadata account check](https://github.com/ripple/ripple-lib/commit/3f61598d6c87e3cc877af60e2d515f9eff73dfe1)
|
||||
|
||||
+ [Double check `tes` code before emitting `success`](https://github.com/ripple/ripple-lib/commit/97a8c874903eb7309d8f755955ac80872f670582)
|
||||
|
||||
+ [Decrease redundancy in binary account_tx parsing](https://github.com/ripple/ripple-lib/commit/0aba638e6e7f4f6e22cb6424eed3897ebad90a5a)
|
||||
|
||||
+ [Abort server connection on unrecoverable TLS error](https://github.com/ripple/ripple-lib/commit/000a2ea00c57157044aeca0fb3f24b37669b163c)
|
||||
|
||||
+ [Fix complete ledgers check on subscription that is not initial](https://github.com/ripple/ripple-lib/commit/89de91301e682a46dc60aaacc7ae152e8fe1b7c7)
|
||||
|
||||
|
||||
##0.10.0
|
||||
|
||||
+ [Transaction changes](https://github.com/ripple/ripple-lib/pull/221)
|
||||
|
||||
+ **Important** `tef*` and `tel*` and errors will no longer be presented as
|
||||
final. Rather than considering these errors final, ripple-lib will wait until
|
||||
the `LastLedgerSequence` specified in the transaction is exceeded. This makes
|
||||
failures more definitive, and ensures that no transaction will resubmit
|
||||
indefinitely.
|
||||
|
||||
+ A new, final tej-class error is introduced to account for transactions that
|
||||
are locally determined to have expired: `tejMaxLedger`.
|
||||
|
||||
+ [Allow per transaction fees to be set, `transaction.setFixedFee()`](https://github.com/ripple/ripple-lib/commit/9b22f279bcbe60ee6bcf4b7fa60a48e9c197a828)
|
||||
|
||||
+ [Improve memo support](https://github.com/ripple/ripple-lib/commit/1704ac4ae144c0ce54afad86f644c75a632080b1)
|
||||
- Add `MemoFormat` property for memo
|
||||
- Enforce `MemoFormat` and `MemoType` to be valid ASCII
|
||||
- Support `text` and `json` MemoFormat
|
||||
|
||||
+ [Update jscl library](https://github.com/ripple/ripple-lib/commit/3204998fcb6f31d6c90532a737a4adb8a1e420f6)
|
||||
- Improved entropy by taking advantage of platform crypto
|
||||
- Use jscl's k256 curve instead of altering the c256 curve with k256 configuration
|
||||
- **deprecated:** the c256 curve is linked to the k256 curve to provide backwards compatibility, this link will be removed in the future
|
||||
|
||||
+ [Fix empty queue check on reconnect](https://github.com/ripple/ripple-lib/commit/3c21994adcf72d1fbd87d453ceb917f9ad6df4ec)
|
||||
|
||||
##0.9.4
|
||||
|
||||
+ [Normalize offers from book_offers and transaction stream](https://github.com/ripple/ripple-lib/commit/86ed24b94cf7c8929c87db3a63e9bbea7f767e9c)
|
||||
|
||||
+ [Fix: Amount.to_human() precision rounding](https://github.com/ripple/ripple-lib/commit/e371cc2c3ceccb3c1cfdf18b98d80093147dd8b2)
|
||||
|
||||
+ [Fix: fractional drops in funded taker_pays setter](https://github.com/ripple/ripple-lib/commit/0d7fc0a573a144caac15dd13798b23eeb1f95fb4)
|
||||
|
||||
##0.9.3
|
||||
|
||||
+ [Change `presubmit` to emit immediately before transaction submit](https://github.com/ripple/ripple-lib/commit/7a1feaa89701bf861ab31ebd8ffdc8d8d1474e29)
|
||||
|
||||
+ [Add a "core" browser build of ripple-lib which has a subset of features and smaller file size](https://github.com/ripple/ripple-lib/pull/205)
|
||||
|
||||
+ [Update binformat with missing fields from rippled](https://github.com/ripple/ripple-lib/commit/cae980788efb00191bfd0988ed836d60cdf7a9a2)
|
||||
|
||||
+ [Wait for transaction validation before returning `tec` error](https://github.com/ripple/ripple-lib/commit/6bdd4b2670906588852fc4dda457607b4aac08e4)
|
||||
|
||||
+ [Change default `max_fee` on `Remote` to `1 XRP`](https://github.com/ripple/ripple-lib/commit/d6b1728c23ff85c3cc791bed6982a750641fd95f)
|
||||
|
||||
+ [Fix: Request ledger_accept should return the Remote](https://github.com/ripple/ripple-lib/pull/209)
|
||||
|
||||
##0.9.2
|
||||
|
||||
+ [**Breaking change**: Change accountRequest method signature](https://github.com/ripple/ripple-lib/commit/6f5d1104aa3eb440c518ec4f39e264fdce15fa15)
|
||||
|
||||
+ [Add paging behavior for account requests, `account_lines` and `account_offers`](https://github.com/ripple/ripple-lib/commit/722f4e175dbbf378e51b49142d0285f87acb22d7)
|
||||
|
||||
+ [Add max_fee setter to transactions to set max fee the submitter is willing to pay] (https://github.com/ripple/ripple-lib/commit/24587fab9c8ad3840d7aa345a7037b48839e09d7)
|
||||
|
||||
+ [Fix: cap IOU Amounts to their max and min value] (https://github.com/ripple/ripple-lib/commit/f05941fbc46fdb7c6fe7ad72927af02d527ffeed)
|
||||
|
||||
Example on how to use paging with `account_offers`:
|
||||
```
|
||||
// A valid `ledger_index` or `ledger_hash` is required to provide a reliable result.
|
||||
// Results can change between ledger closes, so the provided ledger will be used as base.
|
||||
var options = {
|
||||
account: < rippleAccount >,
|
||||
limit: < Number between 10 and 400 >,
|
||||
ledger: < valid ledger_index or ledger_hash >
|
||||
}
|
||||
|
||||
// The `marker` comes back in an account request if there are more results than are returned
|
||||
// in the current response. The amount of results per response are determined by the `limit`.
|
||||
if (marker) {
|
||||
options.marker = < marker >;
|
||||
}
|
||||
|
||||
var request = remote.requestAccountOffers(options);
|
||||
```
|
||||
|
||||
[Full working example](https://github.com/geertweening/ripple-lib-scripts/blob/master/account_offers_paging.js)
|
||||
|
||||
|
||||
##0.9.1
|
||||
|
||||
+ Switch account requests to use ledgerSelect rather than ledgerChoose ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
||||
|
||||
+ **Deprecated** setting `ident` and `account_index` on account requests ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
||||
|
||||
+ Change initial account transaction sequence to 1 ([a3c1d06](https://github.com/ripple/ripple-lib/commit/a3c1d06eba883dc84fe2bfe700e4309795c84cac))
|
||||
|
||||
+ Fix: instance transaction withoute remote ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca))
|
||||
|
||||
+ Fix: account root request ledger argument ([bc1f9f8](https://github.com/ripple/ripple-lib/commit/bc1f9f8a286b187d36ebaf552694e31e73742293))
|
||||
|
||||
+ Fix: rsign.js local signing and example ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca) and [f1004c6](https://github.com/ripple/ripple-lib/commit/f1004c6db2a0ce59bbabbb8f2b355a9fd9995fd8))
|
||||
|
||||
|
||||
##0.9.0
|
||||
|
||||
+ Add routes to the vault client for KYC attestations ([ed2da574](https://github.com/ripple/ripple-lib/commit/ed2da57475acf5e9d2cf3373858f4274832bd83f))
|
||||
|
||||
+ Currency: add `show_interest` flag to show or hide interest in `Currency.to_human()` and `Currency.to_json()` [Example use in tests](https://github.com/ripple/ripple-lib/blob/947ec3edc2e7c8f1ef097e496bf552c74366e749/test/currency-test.js#L123)
|
||||
|
||||
+ Configurable maxAttempts for transaction submission ([d107092](https://github.com/ripple/ripple-lib/commit/d10709254061e9e4416d2cb78b5cac1ec0d7ffa5))
|
||||
|
||||
+ Binformat: added missing TransactionResult options ([6abed8d](https://github.com/ripple/ripple-lib/commit/6abed8dd5311765b2eb70505dadbdf5121439ca8))
|
||||
|
||||
+ **Breaking change:** make maxLoops in seed.get_key optional. [Example use in tests](https://github.com/ripple/ripple-lib/blob/23e473b6886c457781949c825b3ff48b3984e51f/test/seed-test.js) ([23e473b](https://github.com/ripple/ripple-lib/commit/23e473b6886c457781949c825b3ff48b3984e51f))
|
||||
|
||||
+ Shrinkwrap packages for dependency locking ([2dcd5f9](2dcd5f94fbc71200eb08a5044c76ef94f7971913))
|
||||
|
||||
+ Fix: Amount.to_human() precision bugs ([4be209e](https://github.com/ripple/ripple-lib/commit/4be209e286b5b209bec7bcd1212098985e15ff2f) and [7708c64](https://github.com/ripple/ripple-lib/commit/7708c64576e70ce3ac190442daceb30e4446aab7))
|
||||
|
||||
+ Fix: change handling of requestLedger options ([57b7030](https://github.com/ripple/ripple-lib/commit/57b70300f5f0c7534ede118ddbb5d8762668a4f8))
|
||||
|
||||
|
||||
##0.8.2
|
||||
|
||||
+ Currency: Allow mixed letters and numbers in currencies
|
||||
|
||||
+ Deprecate account_tx map/reduce/filterg
|
||||
|
||||
+ Fix: correct requestLedger arguments
|
||||
|
||||
+ Fix: missing subscription on error events for some server methods
|
||||
|
||||
+ Fix: orderbook reset on reconnect
|
||||
|
||||
+ Fix: ripple-lib crashing. Add potential missing error handlers
|
||||
|
||||
|
||||
##0.8.1
|
||||
|
||||
+ Wallet: Add Wallet class that generates wallets
|
||||
|
||||
+ Make npm test runnable in Windows.
|
||||
|
||||
+ Fix several stability issues, see merged PR's for details
|
||||
|
||||
+ Fix bug in Amount.to_human_full()
|
||||
|
||||
+ Fix undefined fee states when connecting to a rippled that is syncing
|
||||
|
||||
|
||||
##0.8.0
|
||||
|
||||
+ Orderbook: Added tracking of offer funds for determining when offers are not funded
|
||||
|
||||
+ Orderbook: Added tests
|
||||
|
||||
+ Orderbook: Update owner funds
|
||||
|
||||
+ Transactions: If transaction errs with `tefALREADY`, wait until all possible submissions err with the same before emitting `error`. Fixes a client "Transaction malformed" bug.
|
||||
|
||||
+ Transactions: Track submissions, don't bother submitting to unconnected servers
|
||||
|
||||
+ Request: `request.request()` now accepts an array of servers as first argument. Servers can be represented with URL, or the server object itself.
|
||||
|
||||
+ Request: `request.broadcast()` now returns the number of servers request was sent to
|
||||
|
||||
+ Server: Acquire host information from server without additional request
|
||||
|
||||
+ Amount: Add a constant for the maximum canonical value that can be expressed as a Ripple value
|
||||
|
||||
+ Amount: Make Constants static fields on the class, instead of a seperate export
|
||||
|
||||
|
||||
##0.7.39
|
||||
|
||||
+ Improvements to multi-server support. Fixed an issue where a server's score was not reset and connections would keep dropping after being connected for a significant amount of time.
|
||||
|
||||
+ Improvements in order book support. Added support for currency pairs with interest bearing currencies. You can request an order book with hex, ISO code or full name for the currency.
|
||||
|
||||
+ Fix value parsing for amount/currency order pairs, e.g. `Amount.from_human("XAU 12345.6789")`
|
||||
|
||||
+ Improved Amount parsing from human readable string given a hex currency, e.g. `Amount.from_human("10 015841551A748AD2C1F76FF6ECB0CCCD00000000")`
|
||||
|
||||
+ Improvements to username normalization in the vault client
|
||||
|
||||
+ Add 2-factor authentication support for vault client
|
||||
|
||||
+ Removed vestiges of Grunt, switched to Gulp
|
||||
|
||||
|
||||
##0.7.37
|
||||
|
||||
+ **Deprecations**
|
||||
|
||||
1. Removed humanistic amount detection in `transaction.payment`. Passing `1XRP` as the payment amount no longer works.
|
||||
2. `remote.setServer` uses full server URL rather than hostname. Example: `remote.setServer('wss://s`.ripple.com:443')`
|
||||
3. Removed constructors for deprecated transaction types from `transaction.js`.
|
||||
4. Removed `invoiceID` option from `transaction.payment`. Instead, use the `transaction.invoiceID` method.
|
||||
5. Removed `transaction.transactionManager` getter.
|
||||
|
||||
+ Improved multi-server support. Servers are now ranked dynamically, and transactions are broadcasted to all connected servers.
|
||||
|
||||
+ Automatically ping connected servers. Client configuration now should contain `ping: <seconds>` to specify the ping interval.
|
||||
|
||||
+ Added `transaction.lastLedger` to specify `LastLedgerSequence`. Setting it this way also ensures that the sequence is not bumped on subsequent requests.
|
||||
|
||||
+ Added optional `remote.accountTx` binary parsing.
|
||||
```js
|
||||
{
|
||||
binary: true,
|
||||
parseBinary: false
|
||||
}
|
||||
```
|
||||
+ Added full currency name support, e.g. `Currency.from_json('XRP').to_human({full_name:'Ripples'})` will return `XRP - Ripples`
|
||||
|
||||
+ Improved interest bearing currency support, e.g. `Currency.from_human('USD - US Dollar (2.5%pa)')`
|
||||
|
||||
+ Improve test coverage
|
||||
|
||||
+ Added blob vault client. The vault client facilitates interaction with ripple's namespace and blob vault or 3rd party blob vaults using ripple's blob vault software (https://github.com/ripple/ripple-blobvault). A list of the available functions can be found at [docs/VAULTCLIENT.md](docs/VAULTCLIENT.md)
|
||||
|
||||
|
||||
##0.7.35
|
||||
|
||||
+ `LastLedgerSequence` is set by default on outgoing transactions. This refers to the last valid ledger index (AKA sequence) for a transaction. By default, this index is set to the current index (at submission time) plus 8. In theory, this allows ripple-lib to deterministically fail a transaction whose submission request timed out, but whose associated server continues to emit ledger_closed events.
|
||||
|
||||
+ Transactions that err with `telINSUF_FEE_P` will be automatically resubmitted. This error indicates that the `Fee` supplied in the transaction submission request was inadquate. Ideally, the `Fee` is tracked by ripple-lib in real-time, and the resubmitted transaction will most likely succeed.
|
||||
|
||||
+ Added Transaction.iff(function(callback) { }). Callback expects first argument to be an Error or null, second argument is a boolean which indicates whether or not to proceed with the transaction submission. If an `iff` function is specified, it will be executed prior to every submission of the transaction (including resubmissions).
|
||||
|
||||
+ Transactions will now emit `presubmit` and `postsubmit` events. They will be emitted before and after a transaction is submitted, respectively.
|
||||
|
||||
+ Added Transaction.summary(). Returns a summary of a transaction in semi-human-readable form. JSON-stringifiable.
|
||||
|
||||
+ Remote.requestAccountTx() with `binary: true` will automatically parse transactions.
|
||||
|
||||
+ Added Remote.requestAccountTx filter, map, and reduce.
|
||||
|
||||
```js
|
||||
remote.requestAccountTx({
|
||||
account: 'retc',
|
||||
ledger_index_min: -1,
|
||||
ledger_index_max: -1,
|
||||
limit: 100,
|
||||
binary: true,
|
||||
|
||||
filter: function(transaction) {
|
||||
return transaction.tx.TransactionType === 'Payment';
|
||||
},
|
||||
|
||||
map: function(transaction) {
|
||||
return Number(transaction.tx.Amount);
|
||||
},
|
||||
|
||||
reduce: function(a, b) {
|
||||
return a + b;
|
||||
},
|
||||
|
||||
pluck: 'transactions'
|
||||
}, console.log)
|
||||
```
|
||||
|
||||
+ Added persistence hooks.
|
||||
|
||||
+ General performance improvements, especially for long-running processes.
|
||||
|
||||
* [Release History for **xahau.js**](packages/xrpl/HISTORY.md)
|
||||
* The **xahau** package is a TypeScript/JavaScript library for interacting with the [Xahau Ledger](https://docs.xahau.network/).
|
||||
* [Release History for **xahau-address-codec**](packages/xahau-address-codec/HISTORY.md)
|
||||
* The **xahau-address-codec** package provides functions for encoding and decoding Xahau Ledger addresses and seeds.
|
||||
* [Release History for **xahau-binary-codec**](packages/xahau-binary-codec/HISTORY.md)
|
||||
* The **xahau-binary-codec** package provides functions to encode to, and decode from, the Xahau binary serialization format.
|
||||
* [Release History for **xahau-keypairs**](packages/xahau-keypairs/HISTORY.md)
|
||||
* The **xahau-keypairs** package implements Xahau cryptographic keypair and wallet generation, with support for rfc6979 and EdDSA deterministic signatures.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2012-2015 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
104
README.md
104
README.md
@@ -1,99 +1,37 @@
|
||||
# xahau.js
|
||||
#ripple-lib
|
||||
|
||||
A JavaScript/TypeScript library for interacting with the Xahau Ledger
|
||||
A JavaScript API for interacting with Ripple in Node.js
|
||||
|
||||
[](https://www.npmjs.org/package/xahau)
|
||||

|
||||
[](https://circleci.com/gh/ripple/ripple-lib/tree/develop) [](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
|
||||
|
||||
This is the recommended library for integrating a JavaScript/TypeScript app with the Xahau Ledger, especially if you intend to use advanced functionality such as IOUs, payment paths, the decentralized exchange, account settings, payment channels, escrows, multi-signing, and more.
|
||||
[](https://www.npmjs.org/package/ripple-lib)
|
||||
|
||||
<!-- ## [➡️ Reference Documentation](http://js.xahau.org)
|
||||
###Features
|
||||
|
||||
See the full reference documentation for all classes, methods, and utilities.
|
||||
+ Connect to a rippled server in Node.js
|
||||
+ Issue [rippled API](https://ripple.com/build/rippled-apis/) requests
|
||||
+ Listen to events on the Ripple network (transaction, ledger, etc.)
|
||||
+ Sign and submit transactions to the Ripple network
|
||||
|
||||
## Features
|
||||
|
||||
1. Managing keys & creating test credentials ([`Wallet`](https://js.xahau.org/classes/Wallet.html) && [`Client.fundWallet()`](https://js.xahau.org/classes/Client.html#fundWallet))
|
||||
2. Submitting transactions to the Xahau Ledger ([`Client.submit(...)`](https://js.xahau.org/classes/Client.html#submit) & [transaction types](https://xahau.org/transaction-types.html))
|
||||
3. Sending requests to observe the ledger ([`Client.request(...)`](https://js.xahau.org/classes/Client.html#request) using [public API methods](https://xahau.org/public-api-methods.html))
|
||||
4. Subscribing to changes in the ledger ([Ex. ledger, transactions, & more...](https://xahau.org/subscribe.html))
|
||||
5. Parsing ledger data into more convenient formats ([`xrpToDrops`](https://js.xahau.org/functions/xrpToDrops.html) and [`rippleTimeToISOTime`](https://js.xahau.org/functions/rippleTimeToISOTime.html))
|
||||
|
||||
All of which works in Node.js (tested for v18+) & web browsers (tested for Chrome). -->
|
||||
|
||||
# Quickstart
|
||||
|
||||
### Requirements
|
||||
|
||||
+ **[Node.js v18](https://nodejs.org/)** is recommended. We also support v20. Other versions may work but are not frequently tested.
|
||||
|
||||
### Installing xahau.js
|
||||
|
||||
In an existing project (with package.json), install xahau.js with:
|
||||
##Getting Started
|
||||
|
||||
Install `ripple-lib` using npm:
|
||||
```
|
||||
$ npm install --save xahau
|
||||
$ npm install ripple-lib
|
||||
```
|
||||
|
||||
Or with `yarn`:
|
||||
Then see the [documentation](https://github.com/ripple/ripple-lib/blob/develop/docs/index.md) and [code samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
|
||||
|
||||
```
|
||||
$ yarn add xahau
|
||||
```
|
||||
##Running tests
|
||||
|
||||
Example usage:
|
||||
1. Clone the repository
|
||||
2. `cd` into the repository and install dependencies with `npm install`
|
||||
3. `npm test` or `npm test --coverage` (`istanbul` will create coverage reports in coverage/lcov-report/`)
|
||||
|
||||
```js
|
||||
const xahau = require("xahau");
|
||||
async function main() {
|
||||
const client = new xahau.Client("wss://xahau-test.net");
|
||||
await client.connect();
|
||||
##Generating Documentation
|
||||
|
||||
const response = await client.request({
|
||||
command: "account_info",
|
||||
account: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
ledger_index: "validated",
|
||||
});
|
||||
console.log(response);
|
||||
The continuous integration tests require that the documentation stays up-to-date. If you make changes the the JSON schemas, fixtures, or documentation sources, you must update the documentation by running `npm run docgen`.
|
||||
|
||||
await client.disconnect();
|
||||
}
|
||||
main();
|
||||
```
|
||||
##More Information
|
||||
|
||||
It goes through:
|
||||
|
||||
1. Creating a new test account
|
||||
2. Sending a payment transaction
|
||||
3. And sending requests to see your account balance!
|
||||
|
||||
### Case by Case Setup Steps
|
||||
|
||||
If you're using xahau.js with React or Deno, you'll need to do a couple extra steps to set it up:
|
||||
|
||||
- [Using xahau.js with a CDN](https://github.com/XRPLF/xahau.js/blob/main/UNIQUE_SETUPS.md#using-xahaujs-from-a-cdn)
|
||||
- [Using xahau.js with `create-react-app`](https://github.com/XRPLF/xahau.js/blob/main/UNIQUE_SETUPS.md#using-xahaujs-with-create-react-app)
|
||||
- [Using xahau.js with `React Native`](https://github.com/XRPLF/xahau.js/blob/main/UNIQUE_SETUPS.md#using-xahaujs-with-react-native)
|
||||
- [Using xahau.js with `Vite React`](https://github.com/XRPLF/xahau.js/blob/main/UNIQUE_SETUPS.md#using-xahaujs-with-vite-react)
|
||||
- [Using xahau.js with `Deno`](https://github.com/XRPLF/xahau.js/blob/main/UNIQUE_SETUPS.md#using-xahaujs-with-deno)
|
||||
|
||||
## Documentation
|
||||
|
||||
As you develop with xahau.js, there's two sites you'll use extensively:
|
||||
|
||||
1. [docs.xahau.network](https://docs.xahau.network/technical/protocol-reference) is the primary source for:
|
||||
- How the ledger works ([See Concepts](https://docs.xahau.network/))
|
||||
- What kinds of transactions there are ([Transaction Types](https://docs.xahau.network/technical/protocol-reference/transactions/transaction-types))
|
||||
- Requests you can send ([Public API Methods](https://docs.xahau.network/features/http-websocket-apis))
|
||||
|
||||
### Mailing Lists
|
||||
|
||||
If you want to hear when we release new versions of xahau.js, you can join our low-traffic mailing list (About 1 email per week):
|
||||
|
||||
- [Subscribe to xahau-announce](https://groups.google.com/g/xahau-announce)
|
||||
|
||||
If you're using the Xahau Ledger in production, you should run a [xahaud server](https://github.com/Xahau/xahaud) and subscribe to the xahau-server mailing list as well.
|
||||
|
||||
- [Subscribe to xahau-server](https://groups.google.com/g/xahau-server)
|
||||
|
||||
You are also welcome to create an [issue](https://github.com/Xahau/xahau.js/issues) here and we'll do our best to respond within 3 days.
|
||||
+ [Ripple Dev Portal](https://ripple.com/build/)
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
# Unique Setup Steps for Xahau.js
|
||||
|
||||
Starting in 3.0 xahau and all the packages in this repo no longer require custom configurations (ex. polyfills) to run.
|
||||
|
||||
### Using xahau.js from a CDN
|
||||
|
||||
You can avoid setting up your build system to handle `xahau.js` by using a cdn version that is prebuilt for the browser.
|
||||
|
||||
- unpkg `<script src="https://unpkg.com/xahau@2.3.0/build/xahau-latest-min.js"></script>`
|
||||
- jsdelivr `<script src="https://cdn.jsdelivr.net/npm/xahau@2.3.0/build/xahau-latest-min.js"></script>`
|
||||
|
||||
Ensure that the full path is provided so the browser can find the sourcemaps.
|
||||
|
||||
### Using xahau.js with `create-react-app`
|
||||
|
||||
Starting in 3.0 xahau and its related packages no longer require custom configurations (ex. polyfills) to run.
|
||||
|
||||
This online template uses these steps to run xahau.js with React in the browser:
|
||||
https://codesandbox.io/s/xahau-intro-pxgdjr?file=/src/App.js
|
||||
|
||||
### Using xahau.js with React Native
|
||||
|
||||
If you want to use `xahau.js` with React Native you will need to install polyfills for core NodeJS modules.
|
||||
|
||||
1. Install dependencies (you can use `yarn` as well):
|
||||
|
||||
```shell
|
||||
npm install xahau \
|
||||
fast-text-encoding \
|
||||
react-native-get-random-values
|
||||
```
|
||||
|
||||
2. After that, run the following commands:
|
||||
|
||||
```shell
|
||||
# compile `react-native-get-random-values` pods see https://www.npmjs.com/package/react-native-get-random-values#installation
|
||||
npx pod-install
|
||||
```
|
||||
|
||||
3. Create `polyfills.js` and add
|
||||
|
||||
```javascript
|
||||
// Required for TextEncoder/TextDecoder
|
||||
import 'fast-text-encoding'
|
||||
// Required for `crypto.getRandomValues`
|
||||
import 'react-native-get-random-values'
|
||||
```
|
||||
|
||||
4. Import `polyfills` in index file your project (it must be the first line):
|
||||
|
||||
```javascript
|
||||
import './polyfills'
|
||||
...
|
||||
```
|
||||
|
||||
### Using xahau.js with Vite React
|
||||
|
||||
Starting in 3.0 xahau and all the packages in this repo no longer require custom configurations (ex. polyfills) to run.
|
||||
|
||||
### Using xahau.js with Deno
|
||||
|
||||
Until official support for [Deno](https://deno.land) is added, you can use the following work-around to use `xahau.js` with Deno:
|
||||
|
||||
> [!NOTE]
|
||||
> The following is currently broken due to https://github.com/denoland/deno/issues/20516.
|
||||
> Once that is fixed there could be other issues as well.
|
||||
|
||||
```javascript
|
||||
import xahau from 'https://dev.jspm.io/npm:xahau';
|
||||
|
||||
(async () => {
|
||||
const api = new (xahau as any).Client('wss://xahau-test.net');
|
||||
const address = 'rH8NxV12EuV...khfJ5uw9kT';
|
||||
|
||||
api.connect().then(() => {
|
||||
api.getBalances(address).then((balances: any) => {
|
||||
console.log(JSON.stringify(balances, null, 2));
|
||||
});
|
||||
});
|
||||
})();
|
||||
```
|
||||
20
circle.yml
Normal file
20
circle.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
machine:
|
||||
node:
|
||||
version: 0.12.0
|
||||
hosts:
|
||||
testripple.circleci.com: 127.0.0.1
|
||||
dependencies:
|
||||
pre:
|
||||
- npm -g install npm@latest-2
|
||||
- npm install flow-bin
|
||||
- wget https://s3-us-west-2.amazonaws.com/ripple-debs/rippled_0.30.1-b11-1.deb
|
||||
- sudo dpkg -i rippled_0.30.1-b11-1.deb
|
||||
test:
|
||||
pre:
|
||||
- rippled -a --start --conf "$HOME/$CIRCLE_PROJECT_REPONAME/test/integration/rippled.cfg":
|
||||
background: true
|
||||
override:
|
||||
- scripts/ci.sh "$CIRCLE_NODE_INDEX" "$CIRCLE_NODE_TOTAL":
|
||||
parallel: true
|
||||
post:
|
||||
- killall /usr/bin/rippled
|
||||
@@ -1,8 +0,0 @@
|
||||
for file in $(git log --diff-filter=D --name-only --format="" | grep -E "oracle.*\.ts$"); do
|
||||
commit=$(git rev-list -n 1 HEAD -- "$file")
|
||||
if [ ! -z "$commit" ]; then
|
||||
git checkout "$commit~1" -- "$file"
|
||||
echo "restore: $file"
|
||||
fi
|
||||
done
|
||||
rsync -av packages/xrpl/ packages/xahau/ && rm -rf packages/xrpl/
|
||||
3638
docs/index.md
Normal file
3638
docs/index.md
Normal file
File diff suppressed because it is too large
Load Diff
3
docs/samples/README
Normal file
3
docs/samples/README
Normal file
@@ -0,0 +1,3 @@
|
||||
Usage:
|
||||
babel-node balances.js
|
||||
babel-node payment.js (requires setting address and secret in source file first)
|
||||
12
docs/samples/balances.js
Normal file
12
docs/samples/balances.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
const RippleAPI = require('../../src').RippleAPI; // require('ripple-lib')
|
||||
|
||||
const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
|
||||
const address = 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV';
|
||||
|
||||
api.connect().then(() => {
|
||||
api.getBalances(address).then(balances => {
|
||||
console.log(JSON.stringify(balances, null, 2));
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
38
docs/samples/cancelall.js
Normal file
38
docs/samples/cancelall.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
const RippleAPI = require('../../dist/npm').RippleAPI; // require('ripple-lib')
|
||||
|
||||
const address = 'rLDYrujdKUfVx28T9vRDAbyJ7G2WVXKo4K';
|
||||
const secret = '';
|
||||
|
||||
const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
|
||||
const instructions = {maxLedgerVersionOffset: 5};
|
||||
|
||||
function fail(message) {
|
||||
console.error(message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function cancelOrder(orderSequence) {
|
||||
console.log('Cancelling order: ' + orderSequence.toString());
|
||||
return api.prepareOrderCancellation(address, {orderSequence}, instructions)
|
||||
.then(prepared => {
|
||||
const signing = api.sign(prepared.txJSON, secret);
|
||||
return api.submit(signing.signedTransaction);
|
||||
});
|
||||
}
|
||||
|
||||
function cancelAllOrders(orderSequences) {
|
||||
if (orderSequences.length === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const orderSequence = orderSequences.pop();
|
||||
return cancelOrder(orderSequence).then(() => cancelAllOrders(orderSequences));
|
||||
}
|
||||
|
||||
api.connect().then(() => {
|
||||
console.log('Connected...');
|
||||
return api.getOrders(address).then(orders => {
|
||||
const orderSequences = orders.map(order => order.properties.sequence);
|
||||
return cancelAllOrders(orderSequences);
|
||||
}).then(() => process.exit(0));
|
||||
}).catch(fail);
|
||||
45
docs/samples/payment.js
Normal file
45
docs/samples/payment.js
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
const RippleAPI = require('../../src').RippleAPI; // require('ripple-lib')
|
||||
|
||||
const address = 'INSERT ADDRESS HERE';
|
||||
const secret = 'INSERT SECRET HERE';
|
||||
|
||||
const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
|
||||
const instructions = {maxLedgerVersionOffset: 5};
|
||||
|
||||
const payment = {
|
||||
source: {
|
||||
address: address,
|
||||
maxAmount: {
|
||||
value: '0.01',
|
||||
currency: 'XRP'
|
||||
}
|
||||
},
|
||||
destination: {
|
||||
address: 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc',
|
||||
amount: {
|
||||
value: '0.01',
|
||||
currency: 'XRP'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function quit(message) {
|
||||
console.log(message);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function fail(message) {
|
||||
console.error(message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
api.connect().then(() => {
|
||||
console.log('Connected...');
|
||||
return api.preparePayment(address, payment, instructions).then(prepared => {
|
||||
console.log('Payment transaction prepared...');
|
||||
const {signedTransaction} = api.sign(prepared.txJSON, secret);
|
||||
console.log('Payment transaction signed...');
|
||||
api.submit(signedTransaction).then(quit, fail);
|
||||
});
|
||||
}).catch(fail);
|
||||
55
docs/src/basictypes.md.ejs
Normal file
55
docs/src/basictypes.md.ejs
Normal file
@@ -0,0 +1,55 @@
|
||||
# Basic Types
|
||||
|
||||
## Ripple Address
|
||||
|
||||
```json
|
||||
"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
|
||||
```
|
||||
|
||||
Every Ripple account has an *address*, which is a base58-encoding of a hash of the account's public key. Ripple addresses always start with the lowercase letter `r`.
|
||||
|
||||
## Account Sequence Number
|
||||
|
||||
Every Ripple account has a *sequence number* that is used to keep transactions in order. Every transaction must have a sequence number. A transaction can only be executed if it has the next sequence number in order, of the account sending it. This prevents one transaction from executing twice and transactions executing out of order. The sequence number starts at `1` and increments for each transaction that the account makes.
|
||||
|
||||
## Currency
|
||||
|
||||
Currencies are represented as either 3-character currency codes or 40-character uppercase hexadecimal strings. We recommend using uppercase [ISO 4217 Currency Codes](http://www.xe.com/iso4217.php) only. The string "XRP" is disallowed on trustlines because it is reserved for the Ripple native currency. The following characters are permitted: all uppercase and lowercase letters, digits, as well as the symbols `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `<`, `>`, `(`, `)`, `{`, `}`, `[`, `]`, and `|`.
|
||||
|
||||
## Value
|
||||
A *value* is a quantity of a currency represented as a decimal string. Be careful: JavaScript's native number format does not have sufficient precision to represent all values. XRP has different precision from other currencies.
|
||||
|
||||
**XRP** has 6 significant digits past the decimal point. In other words, XRP cannot be divided into positive values smaller than `0.000001` (1e-6). XRP has a maximum value of `100000000000` (1e11).
|
||||
|
||||
**Non-XRP values** have 16 decimal digits of precision, with a maximum value of `9999999999999999e80`. The smallest positive non-XRP value is `1e-81`.
|
||||
|
||||
|
||||
## Amount
|
||||
|
||||
Example amount:
|
||||
|
||||
```json
|
||||
{
|
||||
"currency": "USD",
|
||||
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
|
||||
"value": "100"
|
||||
}
|
||||
```
|
||||
|
||||
Example XRP amount:
|
||||
```json
|
||||
{
|
||||
"currency": "XRP",
|
||||
"value": "2000"
|
||||
}
|
||||
```
|
||||
|
||||
An *amount* is data structure representing a currency, a quantity of that currency, and the counterparty on the trustline that holds the value. For XRP, there is no counterparty.
|
||||
|
||||
A *lax amount* allows the counterparty to be omitted for all currencies. If the counterparty is not specified in an amount within a transaction specification, then any counterparty may be used for that amount.
|
||||
|
||||
A *lax lax amount* allows either or both the counterparty and value to be omitted.
|
||||
|
||||
A *balance* is an amount than can have a negative value.
|
||||
|
||||
<%- renderSchema('objects/amount-base.json') %>
|
||||
68
docs/src/boilerplate.md.ejs
Normal file
68
docs/src/boilerplate.md.ejs
Normal file
@@ -0,0 +1,68 @@
|
||||
## Boilerplate
|
||||
|
||||
Use the following [boilerplate code](https://en.wikipedia.org/wiki/Boilerplate_code) to wrap your custom code using RippleAPI.
|
||||
|
||||
```javascript
|
||||
const {RippleAPI} = require('ripple-lib');
|
||||
|
||||
const api = new RippleAPI({
|
||||
server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
|
||||
});
|
||||
api.on('error', (errorCode, errorMessage) => {
|
||||
console.log(errorCode + ': ' + errorMessage);
|
||||
});
|
||||
api.on('connected', () => {
|
||||
console.log('connected');
|
||||
});
|
||||
api.on('disconnected', (code) => {
|
||||
// code - [close code](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) sent by the server
|
||||
// will be 1000 if this was normal closure
|
||||
console.log('disconnected, code:', code);
|
||||
});
|
||||
api.connect().then(() => {
|
||||
/* insert code here */
|
||||
}).then(() => {
|
||||
return api.disconnect();
|
||||
}).catch(console.error);
|
||||
```
|
||||
|
||||
RippleAPI is designed to work in [NodeJS](https://nodejs.org) (version `0.12.0` or greater) using [Babel](https://babeljs.io/) for [ECMAScript 6](https://babeljs.io/docs/learn-es2015/) support.
|
||||
|
||||
The code samples in this documentation are written in ES6, but `RippleAPI` will work with ES5 also. Regardless of whether you use ES5 or ES6, the methods that return promises will return [ES6-style promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
|
||||
|
||||
<aside class="notice">
|
||||
All the code snippets in this documentation assume that you have surrounded them with this boilerplate.
|
||||
</aside>
|
||||
|
||||
<aside class="notice">
|
||||
If you omit the "catch" section, errors may not be visible.
|
||||
</aside>
|
||||
|
||||
<aside class="notice">
|
||||
The "error" event is emitted whenever an error occurs that cannot be associated with a specific request. If the listener is not registered, an exception will be thrown whenever the event is emitted.
|
||||
</aside>
|
||||
|
||||
### Parameters
|
||||
|
||||
The RippleAPI constructor optionally takes one argument, an object with the following options:
|
||||
|
||||
<%- renderSchema('input/api-options.json') %>
|
||||
|
||||
If you omit the `server` parameter, RippleAPI operates [offline](#offline-functionality).
|
||||
|
||||
|
||||
### Installation ###
|
||||
|
||||
1. Install [NodeJS](https://nodejs.org) and the Node Package Manager (npm). Most Linux distros have a package for NodeJS, but make sure you have version `0.12.0` or higher.
|
||||
2. Use npm to install [Babel](https://babeljs.io/) globally:
|
||||
`npm install -g babel-cli`
|
||||
3. Use npm to install RippleAPI:
|
||||
`npm install ripple-lib`
|
||||
|
||||
After you have installed ripple-lib, you can create scripts using the [boilerplate](#boilerplate) and run them using babel-node:
|
||||
`babel-node script.js`
|
||||
|
||||
<aside class="notice">
|
||||
Instead of using babel-node in production, we recommend using Babel to transpile to ECMAScript 5 first.
|
||||
</aside>
|
||||
|
||||
24
docs/src/combine.md.ejs
Normal file
24
docs/src/combine.md.ejs
Normal file
@@ -0,0 +1,24 @@
|
||||
## combine
|
||||
|
||||
`combine(signedTransactions: Array<string>): {signedTransaction: string, id: string}`
|
||||
|
||||
Combines signed transactions from multiple accounts for a multisignature transaction. The signed transaction must subsequently be [submitted](#submit).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/combine.json") %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns an object with the following structure:
|
||||
|
||||
<%- renderSchema("output/sign.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const signedTransactions = <%- importFile('test/fixtures/requests/combine.json') %>;
|
||||
return api.combine(signedTransactions);
|
||||
```
|
||||
|
||||
<%- renderFixture("responses/combine.json") %>
|
||||
28
docs/src/computeLedgerHash.md.ejs
Normal file
28
docs/src/computeLedgerHash.md.ejs
Normal file
@@ -0,0 +1,28 @@
|
||||
## computeLedgerHash
|
||||
|
||||
`computeLedgerHash(ledger: Object): string`
|
||||
|
||||
Compute the hash of a ledger.
|
||||
|
||||
### Parameters
|
||||
|
||||
<aside class="notice">
|
||||
The parameter to this method has the same structure as the return value of getLedger.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema('input/compute-ledger-hash.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns an uppercase hexadecimal string representing the hash of the ledger.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const ledger = <%- importFile('test/fixtures/requests/compute-ledger-hash.json') %>;
|
||||
return api.computeLedgerHash(ledger);
|
||||
```
|
||||
|
||||
```json
|
||||
"F4D865D83EB88C1A1911B9E90641919A1314F36E1B099F8E95FE3B7C77BE3349"
|
||||
```
|
||||
17
docs/src/connect.md.ejs
Normal file
17
docs/src/connect.md.ejs
Normal file
@@ -0,0 +1,17 @@
|
||||
## connect
|
||||
|
||||
`connect(): Promise<void>`
|
||||
|
||||
Tells the RippleAPI instance to connect to its rippled server.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method has no parameters.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with a void value when a connection is established.
|
||||
|
||||
### Example
|
||||
|
||||
See [Boilerplate](#boilerplate) for code sample.
|
||||
17
docs/src/disconnect.md.ejs
Normal file
17
docs/src/disconnect.md.ejs
Normal file
@@ -0,0 +1,17 @@
|
||||
## disconnect
|
||||
|
||||
`disconnect(): Promise<void>`
|
||||
|
||||
Tells the RippleAPI instance to disconnect from its rippled server.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method has no parameters.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with a void value when a connection is destroyed.
|
||||
|
||||
### Example
|
||||
|
||||
See [Boilerplate](#boilerplate) for code sample
|
||||
81
docs/src/events.md.ejs
Normal file
81
docs/src/events.md.ejs
Normal file
@@ -0,0 +1,81 @@
|
||||
# API Events
|
||||
|
||||
## ledger
|
||||
|
||||
This event is emitted whenever a new ledger version is validated on the connected server.
|
||||
|
||||
### Return Value
|
||||
|
||||
<%- renderSchema('output/ledger-event.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
api.on('ledger', ledger => {
|
||||
console.log(JSON.stringify(ledger, null, 2));
|
||||
});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/ledger-event.json') %>
|
||||
|
||||
## error
|
||||
|
||||
This event is emitted when there is an error on the connection to the server that cannot be associated to a specific request.
|
||||
|
||||
### Return Value
|
||||
|
||||
The first parameter is a string indicating the error type:
|
||||
* `badMessage` - rippled returned a malformed message
|
||||
* `websocket` - the websocket library emitted an error
|
||||
* one of the error codes found in the [rippled Universal Errors](https://ripple.com/build/rippled-apis/#universal-errors).
|
||||
|
||||
The second parameter is a message explaining the error.
|
||||
|
||||
The third parameter is:
|
||||
* the message that caused the error for `badMessage`
|
||||
* the error object emitted for `websocket`
|
||||
* the parsed response for rippled errors
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
api.on('error', (errorCode, errorMessage, data) => {
|
||||
console.log(errorCode + ': ' + errorMessage);
|
||||
});
|
||||
```
|
||||
|
||||
```
|
||||
tooBusy: The server is too busy to help you now.
|
||||
```
|
||||
|
||||
## connected
|
||||
|
||||
This event is emitted after connection successfully opened.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
api.on('connected', () => {
|
||||
console.log('Connection is open now.');
|
||||
});
|
||||
```
|
||||
|
||||
## disconnected
|
||||
|
||||
This event is emitted when connection is closed.
|
||||
|
||||
### Return Value
|
||||
|
||||
The only parameter is a number containing the [close code](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) send by the server.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
api.on('disconnected', (code) => {
|
||||
if (code !== 1000) {
|
||||
console.log('Connection is closed due to error.');
|
||||
} else {
|
||||
console.log('Connection is closed normally.');
|
||||
}
|
||||
});
|
||||
```
|
||||
23
docs/src/generateAddress.md.ejs
Normal file
23
docs/src/generateAddress.md.ejs
Normal file
@@ -0,0 +1,23 @@
|
||||
## generateAddress
|
||||
|
||||
`generateAddress(): {address: string, secret: string}`
|
||||
|
||||
Generate a new Ripple address and corresponding secret.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/generate-address.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns an object with the following structure:
|
||||
|
||||
<%- renderSchema('output/generate-address.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.generateAddress();
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/generate-address.json') %>
|
||||
25
docs/src/getAccountInfo.md.ejs
Normal file
25
docs/src/getAccountInfo.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## getAccountInfo
|
||||
|
||||
`getAccountInfo(address: string, options: Object): Promise<Object>`
|
||||
|
||||
Returns information for the specified account. Note: For account data that is modifiable by the user, see [getSettings](#getsettings).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-account-info.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<%- renderSchema('output/get-account-info.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.getAccountInfo(address).then(info =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-account-info.json') %>
|
||||
25
docs/src/getBalanceSheet.md.ejs
Normal file
25
docs/src/getBalanceSheet.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## getBalanceSheet
|
||||
|
||||
`getBalanceSheet(address: string, options: Object): Promise<Object>`
|
||||
|
||||
Returns aggregate balances by currency plus a breakdown of assets and obligations for a specified account.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-balance-sheet.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<%- renderSchema('output/get-balance-sheet.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.getBalanceSheet(address).then(balanceSheet =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-balance-sheet.json') %>
|
||||
25
docs/src/getBalances.md.ejs
Normal file
25
docs/src/getBalances.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## getBalances
|
||||
|
||||
`getBalances(address: string, options: Object): Promise<Array<Object>>`
|
||||
|
||||
Returns balances for a specified account.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-balances.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an array of objects with the following structure:
|
||||
|
||||
<%- renderSchema('output/get-balances.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.getBalances(address).then(balances =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-balances.json') %>
|
||||
23
docs/src/getFee.md.ejs
Normal file
23
docs/src/getFee.md.ejs
Normal file
@@ -0,0 +1,23 @@
|
||||
## getFee
|
||||
|
||||
`getFee(): Promise<number>`
|
||||
|
||||
Returns the estimated transaction fee for the rippled server the RippleAPI instance is connected to.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method has no parameters.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with a string encoded floating point value representing the estimated fee to submit a transaction, expressed in XRP.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.getFee().then(fee => {/* ... */});
|
||||
```
|
||||
|
||||
```json
|
||||
"0.012"
|
||||
```
|
||||
24
docs/src/getLedger.md.ejs
Normal file
24
docs/src/getLedger.md.ejs
Normal file
@@ -0,0 +1,24 @@
|
||||
## getLedger
|
||||
|
||||
`getLedger(options: Object): Promise<Object>`
|
||||
|
||||
Returns header information for the specified ledger (or the most recent validated ledger if no ledger is specified). Optionally, all the transactions that were validated in the ledger or the account state information can be returned with the ledger header.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-ledger.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<%- renderSchema('output/get-ledger.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.getLedger()
|
||||
.then(ledger => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-ledger.json') %>
|
||||
26
docs/src/getLedgerVersion.md.ejs
Normal file
26
docs/src/getLedgerVersion.md.ejs
Normal file
@@ -0,0 +1,26 @@
|
||||
## getLedgerVersion
|
||||
|
||||
`getLedgerVersion(): Promise<number>`
|
||||
|
||||
Returns the most recent validated ledger version number known to the connected server.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method has no parameters.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with a positive integer representing the most recent validated ledger version number known to the connected server.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.getLedgerVersion().then(ledgerVersion => {
|
||||
/* ... */
|
||||
});
|
||||
```
|
||||
|
||||
```json
|
||||
16869039
|
||||
```
|
||||
|
||||
26
docs/src/getOrderbook.md.ejs
Normal file
26
docs/src/getOrderbook.md.ejs
Normal file
@@ -0,0 +1,26 @@
|
||||
## getOrderbook
|
||||
|
||||
`getOrderbook(address: string, orderbook: Object, options: Object): Promise<Object>`
|
||||
|
||||
Returns open orders for the specified account. Open orders are orders that have not yet been fully executed and are still in the order book.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-orderbook.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure (Note: the structures of `bids` and `asks` are identical):
|
||||
|
||||
<%- renderSchema('output/get-orderbook.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const orderbook = <%- importFile('test/fixtures/requests/get-orderbook.json') %>;
|
||||
return api.getOrderbook(address, orderbook)
|
||||
.then(orderbook => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-orderbook.json') %>
|
||||
25
docs/src/getOrders.md.ejs
Normal file
25
docs/src/getOrders.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## getOrders
|
||||
|
||||
`getOrders(address: string, options: Object): Promise<Array<Object>>`
|
||||
|
||||
Returns open orders for the specified account. Open orders are orders that have not yet been fully executed and are still in the order book.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-orders.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an array of objects with the following structure:
|
||||
|
||||
<%- renderSchema('output/get-orders.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.getOrders(address).then(orders =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-orders.json') %>
|
||||
25
docs/src/getPaths.md.ejs
Normal file
25
docs/src/getPaths.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## getPaths
|
||||
|
||||
`getPaths(pathfind: Object): Promise<Array<Object>>`
|
||||
|
||||
Finds paths to send a payment. Paths are options for how to route a payment.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/get-paths.json") %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an array of objects with the following structure:
|
||||
|
||||
<%- renderSchema("output/get-paths.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const pathfind = <%- importFile('test/fixtures/requests/getpaths/normal.json') %>;
|
||||
return api.getPaths(pathfind)
|
||||
.then(paths => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture("responses/get-paths.json") %>
|
||||
23
docs/src/getServerInfo.md.ejs
Normal file
23
docs/src/getServerInfo.md.ejs
Normal file
@@ -0,0 +1,23 @@
|
||||
## getServerInfo
|
||||
|
||||
`getServerInfo(): Promise<object>`
|
||||
|
||||
Get status information about the server that the RippleAPI instance is connected to.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method has no parameters.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<%- renderSchema('output/get-server-info.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.getServerInfo().then(info => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-server-info.json') %>
|
||||
25
docs/src/getSettings.md.ejs
Normal file
25
docs/src/getSettings.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## getSettings
|
||||
|
||||
`getSettings(address: string, options: Object): Promise<Object>`
|
||||
|
||||
Returns settings for the specified account. Note: For account data that is not modifiable by the user, see [getAccountInfo](#getaccountinfo).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-settings.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an array of objects with the following structure (Note: all fields are optional as they will not be shown if they are set to their default value):
|
||||
|
||||
<%- renderSchema('output/get-settings.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.getSettings(address).then(settings =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-settings.json') %>
|
||||
26
docs/src/getTransaction.md.ejs
Normal file
26
docs/src/getTransaction.md.ejs
Normal file
@@ -0,0 +1,26 @@
|
||||
## getTransaction
|
||||
|
||||
`getTransaction(id: string, options: Object): Promise<Object>`
|
||||
|
||||
Retrieves a transaction by its [Transaction ID](#transaction-id).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-transaction.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with a transaction object containing the following fields.
|
||||
|
||||
<%- renderSchema('output/get-transaction.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const id = '01CDEAA89BF99D97DFD47F79A0477E1DCC0989D39F70E8AACBFE68CC83BD1E94';
|
||||
return api.getTransaction(id).then(transaction => {
|
||||
/* ... */
|
||||
});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-transaction-payment.json') %>
|
||||
24
docs/src/getTransactions.md.ejs
Normal file
24
docs/src/getTransactions.md.ejs
Normal file
@@ -0,0 +1,24 @@
|
||||
## getTransactions
|
||||
|
||||
`getTransactions(address: string, options: Object): Promise<Array<Object>>`
|
||||
|
||||
Retrieves historical transactions of an account.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/get-transactions.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an array of transaction object in the same format as [getTransaction](#gettransaction).
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.getTransactions(address).then(transaction => {
|
||||
/* ... */
|
||||
});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/get-transactions.json') %>
|
||||
25
docs/src/getTrustlines.md.ejs
Normal file
25
docs/src/getTrustlines.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## getTrustlines
|
||||
|
||||
`getTrustlines(address: string, options: Object): Promise<Array<Object>>`
|
||||
|
||||
Returns trustlines for a specified account.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/get-trustlines.json") %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an array of objects with the following structure.
|
||||
|
||||
<%- renderSchema("output/get-trustlines.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.getTrustlines(address).then(trustlines =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture("responses/get-trustlines.json") %>
|
||||
38
docs/src/index.md.ejs
Normal file
38
docs/src/index.md.ejs
Normal file
@@ -0,0 +1,38 @@
|
||||
<% include introduction.md.ejs %>
|
||||
<% include boilerplate.md.ejs %>
|
||||
<% include offline.md.ejs %>
|
||||
<% include basictypes.md.ejs %>
|
||||
<% include transactions.md.ejs %>
|
||||
<% include specifications.md.ejs %>
|
||||
<% include methods.md.ejs %>
|
||||
<% include connect.md.ejs %>
|
||||
<% include disconnect.md.ejs %>
|
||||
<% include isConnected.md.ejs %>
|
||||
<% include getServerInfo.md.ejs %>
|
||||
<% include getFee.md.ejs %>
|
||||
<% include getLedgerVersion.md.ejs %>
|
||||
<% include getTransaction.md.ejs %>
|
||||
<% include getTransactions.md.ejs %>
|
||||
<% include getTrustlines.md.ejs %>
|
||||
<% include getBalances.md.ejs %>
|
||||
<% include getBalanceSheet.md.ejs %>
|
||||
<% include getPaths.md.ejs %>
|
||||
<% include getOrders.md.ejs %>
|
||||
<% include getOrderbook.md.ejs %>
|
||||
<% include getSettings.md.ejs %>
|
||||
<% include getAccountInfo.md.ejs %>
|
||||
<% include getLedger.md.ejs %>
|
||||
<% include preparePayment.md.ejs %>
|
||||
<% include prepareTrustline.md.ejs %>
|
||||
<% include prepareOrder.md.ejs %>
|
||||
<% include prepareOrderCancellation.md.ejs %>
|
||||
<% include prepareSettings.md.ejs %>
|
||||
<% include prepareSuspendedPaymentCreation.md.ejs %>
|
||||
<% include prepareSuspendedPaymentCancellation.md.ejs %>
|
||||
<% include prepareSuspendedPaymentExecution.md.ejs %>
|
||||
<% include sign.md.ejs %>
|
||||
<% include combine.md.ejs %>
|
||||
<% include submit.md.ejs %>
|
||||
<% include generateAddress.md.ejs %>
|
||||
<% include computeLedgerHash.md.ejs %>
|
||||
<% include events.md.ejs %>
|
||||
12
docs/src/introduction.md.ejs
Normal file
12
docs/src/introduction.md.ejs
Normal file
@@ -0,0 +1,12 @@
|
||||
# Introduction
|
||||
|
||||
RippleAPI is the official client library to the Ripple Consensus Ledger. Currently, RippleAPI is only available in JavaScript.
|
||||
Using RippleAPI, you can:
|
||||
|
||||
* [Query transactions from the network](#gettransaction)
|
||||
* [Sign](#sign) transactions securely without connecting to any server
|
||||
* [Submit](#submit) transactions to the Ripple Consensus Ledger, including [Payments](#payment), [Orders](#order), [Settings changes](#settings), and [other types](#transaction-types)
|
||||
* [Generate a new Ripple Address](#generateaddress)
|
||||
* ... and [much more](#api-methods).
|
||||
|
||||
RippleAPI only provides access to *validated*, *immutable* transaction data.
|
||||
23
docs/src/isConnected.md.ejs
Normal file
23
docs/src/isConnected.md.ejs
Normal file
@@ -0,0 +1,23 @@
|
||||
## isConnected
|
||||
|
||||
`isConnected(): boolean`
|
||||
|
||||
Checks if the RippleAPI instance is connected to its rippled server.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method has no parameters.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns `true` if connected and `false` if not connected.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.isConnected();
|
||||
```
|
||||
|
||||
```json
|
||||
true
|
||||
```
|
||||
1
docs/src/methods.md.ejs
Normal file
1
docs/src/methods.md.ejs
Normal file
@@ -0,0 +1 @@
|
||||
# API Methods
|
||||
27
docs/src/offline.md.ejs
Normal file
27
docs/src/offline.md.ejs
Normal file
@@ -0,0 +1,27 @@
|
||||
## Offline functionality
|
||||
|
||||
RippleAPI can also function without internet connectivity. This can be useful in order to generate secrets and sign transactions from a secure, isolated machine.
|
||||
|
||||
To instantiate RippleAPI in offline mode, use the following boilerplate code:
|
||||
|
||||
```javascript
|
||||
const {RippleAPI} = require('ripple-lib');
|
||||
|
||||
const api = new RippleAPI();
|
||||
/* insert code here */
|
||||
```
|
||||
|
||||
Methods that depend on the state of the Ripple Consensus Ledger are unavailable in offline mode. To prepare transactions offline, you **must** specify the `fee`, `sequence`, and `maxLedgerVersion` parameters in the [transaction instructions](#transaction-instructions). The following methods should work offline:
|
||||
|
||||
* [preparePayment](#preparepayment)
|
||||
* [prepareTrustline](#preparetrustline)
|
||||
* [prepareOrder](#prepareorder)
|
||||
* [prepareOrderCancellation](#prepareordercancellation)
|
||||
* [prepareSettings](#preparesettings)
|
||||
* [prepareSuspendedPaymentCreation](#preparesuspendedpaymentcreation)
|
||||
* [prepareSuspendedPaymentCancellation](#preparesuspendedpaymentcancellation)
|
||||
* [prepareSuspendedPaymentExecution](#preparesuspendedpaymentexecution)
|
||||
* [sign](#sign)
|
||||
* [generateAddress](#generateaddress)
|
||||
* [computeLedgerHash](#computeledgerhash)
|
||||
|
||||
30
docs/src/prepareOrder.md.ejs
Normal file
30
docs/src/prepareOrder.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
||||
## prepareOrder
|
||||
|
||||
`prepareOrder(address: string, order: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare an order transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/prepare-order.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema('output/prepare.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const order = <%- importFile('test/fixtures/requests/prepare-order.json') %>;
|
||||
return api.prepareOrder(address, order)
|
||||
.then(prepared => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/prepare-order.json') %>
|
||||
30
docs/src/prepareOrderCancellation.md.ejs
Normal file
30
docs/src/prepareOrderCancellation.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
||||
## prepareOrderCancellation
|
||||
|
||||
`prepareOrderCancellation(address: string, orderCancellation: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare an order cancellation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/prepare-order-cancellation.json") %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema("output/prepare.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const orderCancellation = {orderSequence: 123};
|
||||
return api.prepareOrderCancellation(address, orderCancellation)
|
||||
.then(prepared => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture("responses/prepare-order-cancellation.json") %>
|
||||
30
docs/src/preparePayment.md.ejs
Normal file
30
docs/src/preparePayment.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
||||
## preparePayment
|
||||
|
||||
`preparePayment(address: string, payment: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare a payment transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/prepare-payment.json") %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema("output/prepare.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const payment = <%- importFile('test/fixtures/requests/prepare-payment.json') %>;
|
||||
return api.preparePayment(address, payment).then(prepared =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture("responses/prepare-payment.json") %>
|
||||
30
docs/src/prepareSettings.md.ejs
Normal file
30
docs/src/prepareSettings.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
||||
## prepareSettings
|
||||
|
||||
`prepareSettings(address: string, settings: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare a settings transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/prepare-settings.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema('output/prepare.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const settings = <%- importFile('test/fixtures/requests/prepare-settings.json') %>;
|
||||
return api.prepareSettings(address, settings)
|
||||
.then(prepared => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('requests/prepare-settings.json') %>
|
||||
32
docs/src/prepareSuspendedPaymentCancellation.md.ejs
Normal file
32
docs/src/prepareSuspendedPaymentCancellation.md.ejs
Normal file
@@ -0,0 +1,32 @@
|
||||
## prepareSuspendedPaymentCancellation
|
||||
|
||||
`prepareSuspendedPaymentCancellation(address: string, suspendedPaymentCancellation: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare a suspended payment cancellation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
**Caution:** Suspended Payments are currently available on the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) only.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/prepare-suspended-payment-cancellation.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema('output/prepare.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const suspendedPaymentCancellation = <%- importFile('test/fixtures/requests/prepare-suspended-payment-cancellation.json') %>;
|
||||
return api.prepareSuspendedPaymentCancellation(address, suspendedPaymentCancellation).then(prepared =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/prepare-suspended-payment-cancellation.json') %>
|
||||
32
docs/src/prepareSuspendedPaymentCreation.md.ejs
Normal file
32
docs/src/prepareSuspendedPaymentCreation.md.ejs
Normal file
@@ -0,0 +1,32 @@
|
||||
## prepareSuspendedPaymentCreation
|
||||
|
||||
`prepareSuspendedPaymentCreation(address: string, suspendedPaymentCreation: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare a suspended payment creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
**Caution:** Suspended Payments are currently available on the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) only.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/prepare-suspended-payment-creation.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema('output/prepare.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const suspendedPaymentCreation = <%- importFile('test/fixtures/requests/prepare-suspended-payment-creation.json') %>;
|
||||
return api.prepareSuspendedPaymentCreation(address, suspendedPaymentCreation).then(prepared =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/prepare-suspended-payment-creation.json') %>
|
||||
32
docs/src/prepareSuspendedPaymentExecution.md.ejs
Normal file
32
docs/src/prepareSuspendedPaymentExecution.md.ejs
Normal file
@@ -0,0 +1,32 @@
|
||||
## prepareSuspendedPaymentExecution
|
||||
|
||||
`prepareSuspendedPaymentExecution(address: string, suspendedPaymentExecution: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare a suspended payment execution transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
**Caution:** Suspended Payments are currently available on the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) only.
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/prepare-suspended-payment-execution.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema('output/prepare.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const suspendedPaymentExecution = <%- importFile('test/fixtures/requests/prepare-suspended-payment-execution.json') %>;
|
||||
return api.prepareSuspendedPaymentExecution(address, suspendedPaymentExecution).then(prepared =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/prepare-suspended-payment-execution.json') %>
|
||||
30
docs/src/prepareTrustline.md.ejs
Normal file
30
docs/src/prepareTrustline.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
||||
## prepareTrustline
|
||||
|
||||
`prepareTrustline(address: string, trustline: Object, instructions: Object): Promise<Object>`
|
||||
|
||||
Prepare a trustline transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/prepare-trustline.json") %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema("output/prepare.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
const trustline = <%- importFile('test/fixtures/requests/prepare-trustline.json') %>;
|
||||
return api.prepareTrustline(address, trustline).then(prepared =>
|
||||
{/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture("responses/prepare-trustline.json") %>
|
||||
25
docs/src/sign.md.ejs
Normal file
25
docs/src/sign.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## sign
|
||||
|
||||
`sign(txJSON: string, secret: string, options: Object): {signedTransaction: string, id: string}`
|
||||
|
||||
Sign a prepared transaction. The signed transaction must subsequently be [submitted](#submit).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/sign.json") %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns an object with the following structure:
|
||||
|
||||
<%- renderSchema("output/sign.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const txJSON = '{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"726970706C652E636F6D","LastLedgerSequence":8820051,"Fee":"12","Sequence":23}';
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV';
|
||||
return api.sign(txJSON, secret);
|
||||
```
|
||||
|
||||
<%- renderFixture("responses/sign.json") %>
|
||||
83
docs/src/specifications.md.ejs
Normal file
83
docs/src/specifications.md.ejs
Normal file
@@ -0,0 +1,83 @@
|
||||
# Transaction Specifications
|
||||
|
||||
A *transaction specification* specifies what a transaction should do. Each [Transaction Type](#transaction-types) has its own type of specification.
|
||||
|
||||
## Payment
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/payment.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-payment.json') %>
|
||||
|
||||
## Trustline
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/trustline.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-trustline.json') %>
|
||||
|
||||
## Order
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/order.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-order.json') %>
|
||||
|
||||
## Order Cancellation
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/order-cancellation.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-order-cancellation.json') %>
|
||||
|
||||
## Settings
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('output/get-settings.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-settings.json') %>
|
||||
|
||||
## Suspended Payment Creation
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/suspended-payment-creation.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-suspended-payment-creation.json') %>
|
||||
|
||||
## Suspended Payment Cancellation
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/suspended-payment-cancellation.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-suspended-payment-cancellation.json') %>
|
||||
|
||||
## Suspended Payment Execution
|
||||
|
||||
See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/suspended-payment-execution.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-suspended-payment-execution.json') %>
|
||||
25
docs/src/submit.md.ejs
Normal file
25
docs/src/submit.md.ejs
Normal file
@@ -0,0 +1,25 @@
|
||||
## submit
|
||||
|
||||
`submit(signedTransaction: string): Promise<Object>`
|
||||
|
||||
Submits a signed transaction. The transaction is not guaranteed to succeed; it must be verified with [getTransaction](#gettransaction).
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema('input/submit.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns an object with the following structure:
|
||||
|
||||
<%- renderSchema('output/submit.json') %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const signedTransaction = '12000322800000002400000017201B0086955368400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100BDE09A1F6670403F341C21A77CF35BA47E45CDE974096E1AA5FC39811D8269E702203D60291B9A27F1DCABA9CF5DED307B4F23223E0B6F156991DB601DFB9C41CE1C770A726970706C652E636F6D81145E7B112523F68D2F5E879DB4EAC51C6698A69304';
|
||||
return api.submit(signedTransaction)
|
||||
.then(result => {/* ... */});
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/submit.json') %>
|
||||
65
docs/src/transactions.md.ejs
Normal file
65
docs/src/transactions.md.ejs
Normal file
@@ -0,0 +1,65 @@
|
||||
# Transaction Overview
|
||||
|
||||
## Transaction Types
|
||||
|
||||
A transaction type is specified by the strings in the first column in the table below.
|
||||
|
||||
Type | Description
|
||||
---- | -----------
|
||||
[payment](#payment) | A `payment` transaction represents a transfer of value from one account to another. Depending on the [path](https://ripple.com/build/paths/) taken, additional exchanges of value may occur atomically to facilitate the payment.
|
||||
[order](#order) | An `order` transaction creates a limit order. It defines an intent to exchange currencies, and creates an order in the Ripple Consensus Ledger's order book if not completely fulfilled when placed. Orders can be partially fulfilled.
|
||||
[orderCancellation](#order-cancellation) | An `orderCancellation` transaction cancels an order in the Ripple Consensus Ledger's order book.
|
||||
[trustline](#trustline) | A `trustline` transactions creates or modifies a trust line between two accounts.
|
||||
[settings](#settings) | A `settings` transaction modifies the settings of an account in the Ripple Consensus Ledger.
|
||||
[suspendedPaymentCreation](#suspended-payment-creation) | A `suspendedPaymentCreation` transaction creates a suspended payment on the ledger, which locks XRP until a cryptographic condition is met or it expires. It is like an escrow service where the Ripple network acts as the escrow agent.
|
||||
[suspendedPaymentCancellation](#suspended-payment-cancellation) | A `suspendedPaymentCancellation` transaction unlocks the funds in a suspended payment and sends them back to the creator of the suspended payment, but it will only work after the suspended payment expires.
|
||||
[suspendedPaymentExecution](#suspended-payment-execution) | A `suspendedPaymentExecution` transaction unlocks the funds in a suspended payment and sends them to the destination of the suspended payment, but it will only work if the cryptographic condition is provided.
|
||||
|
||||
The three "suspended payment" transaction types are not supported by the production Ripple peer-to-peer network at this time. They are available for testing purposes if you [configure RippleAPI](#boilerplate) to connect to the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) instead.
|
||||
|
||||
## Transaction Flow
|
||||
|
||||
Executing a transaction with `RippleAPI` requires the following four steps:
|
||||
|
||||
1. Prepare - Create an unsigned transaction based on a [specification](#transaction-specifications) and [instructions](#transaction-instructions). There is a method to prepare each type of transaction:
|
||||
* [preparePayment](#preparepayment)
|
||||
* [prepareTrustline](#preparetrustline)
|
||||
* [prepareOrder](#prepareorder)
|
||||
* [prepareOrderCancellation](#prepareordercancellation)
|
||||
* [prepareSettings](#preparesettings)
|
||||
* [prepareSuspendedPaymentCreation](#preparesuspendedpaymentcreation)
|
||||
* [prepareSuspendedPaymentCancellation](#preparesuspendedpaymentcancellation)
|
||||
* [prepareSuspendedPaymentExecution](#preparesuspendedpaymentexecution)
|
||||
2. [Sign](#sign) - Cryptographically sign the transaction locally and save the [transaction ID](#transaction-id). Signing is how the owner of an account authorizes a transaction to take place. For multisignature transactions, the `signedTransaction` fields returned by `sign` must be collected and passed to the [combine](#combine) method.
|
||||
3. [Submit](#submit) - Submit the transaction to the connected server.
|
||||
4. Verify - Verify that the transaction got validated by querying with [getTransaction](#gettransaction). This is necessary because transactions may fail even if they were successfully submitted.
|
||||
|
||||
## Transaction Fees
|
||||
|
||||
Every transaction must destroy a small amount of XRP as a cost to send the transaction. This is also called a *transaction fee*. The transaction cost is designed to increase along with the load on the Ripple network, making it very expensive to deliberately or inadvertently overload the network.
|
||||
|
||||
You can choose the size of the fee you want to pay or let a default be used. You can get an estimate of the fee required to be included in the next ledger closing with the [getFee](#getfee) method.
|
||||
|
||||
## Transaction Instructions
|
||||
|
||||
Transaction instructions indicate how to execute a transaction, complementary with the [transaction specification](#transaction-specifications).
|
||||
|
||||
<%- renderSchema("objects/instructions.json") %>
|
||||
|
||||
We recommended that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the network ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare*" method.
|
||||
|
||||
## Transaction ID
|
||||
|
||||
```json
|
||||
"F4AB442A6D4CBB935D66E1DA7309A5FC71C7143ED4049053EC14E3875B0CF9BF"
|
||||
```
|
||||
|
||||
A transaction ID is a 64-bit hexadecimal string that uniquely identifies the transaction. The transaction ID is derived from the transaction instruction and specifications, using a strong hash function.
|
||||
|
||||
You can look up a transaction by ID using the [getTransaction](#gettransaction) method.
|
||||
|
||||
## Transaction Memos
|
||||
|
||||
Every transaction can optionally have an array of memos for user applications. The `memos` field in each [transaction specification](#transaction-specifications) is an array of objects with the following structure:
|
||||
|
||||
<%- renderSchema('objects/memos.json') %>
|
||||
@@ -1,20 +0,0 @@
|
||||
const { TextDecoder, TextEncoder } = require("util");
|
||||
|
||||
module.exports = {
|
||||
roots: ["<rootDir>/src"],
|
||||
transform: {
|
||||
"^.+\\.ts$": "ts-jest",
|
||||
},
|
||||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
|
||||
collectCoverage: true,
|
||||
verbose: true,
|
||||
testEnvironment: "node",
|
||||
globals: {
|
||||
TextDecoder: TextDecoder,
|
||||
TextEncoder: TextEncoder,
|
||||
error: console.error,
|
||||
warn: console.warn,
|
||||
info: console.info,
|
||||
debug: console.debug,
|
||||
},
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
const path = require("path");
|
||||
const base = require("./jest.config.base.js");
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
projects: ["<rootDir>/packages/**/jest.config.js"],
|
||||
coverageDirectory: "<rootDir>/coverage/",
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
plugins: ["karma-webpack", "karma-jasmine", "karma-chrome-launcher"],
|
||||
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ["jasmine"],
|
||||
|
||||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: {
|
||||
// Use webpack to bundle our test files
|
||||
"test/**/*.test.ts": ["webpack"],
|
||||
},
|
||||
|
||||
browsers: ["ChromeHeadless"],
|
||||
// runs only one browser at a time
|
||||
concurrency: 1,
|
||||
// CI mode
|
||||
singleRun: true,
|
||||
client: {
|
||||
jasmine: {
|
||||
// ensures that tests are run in order instead of a random order
|
||||
random: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "independent",
|
||||
"useWorkspaces": true,
|
||||
"npmClient": "npm"
|
||||
}
|
||||
4144
npm-shrinkwrap.json
generated
Normal file
4144
npm-shrinkwrap.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
14836
package-lock.json
generated
14836
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
142
package.json
142
package.json
@@ -1,70 +1,90 @@
|
||||
{
|
||||
"name": "xahau.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"analyze": "lerna run analyze --stream",
|
||||
"test": "lerna run test --stream",
|
||||
"test:browser": "lerna run test:browser --stream",
|
||||
"test:integration": "lerna run test:integration --stream",
|
||||
"lint": "lerna run lint --stream",
|
||||
"clean": "lerna run clean --stream",
|
||||
"build": "lerna run build --stream",
|
||||
"docgen": "lerna run docgen --stream",
|
||||
"update:check": "npx npm-check-updates --configFileName .ncurc.json",
|
||||
"update:confirm": "npx npm-check-updates --configFileName .ncurc.json -u"
|
||||
"name": "ripple-lib",
|
||||
"version": "0.17.3",
|
||||
"license": "ISC",
|
||||
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
||||
"files": [
|
||||
"dist/npm/*",
|
||||
"bin/*",
|
||||
"build/*",
|
||||
"test/*",
|
||||
"Gulpfile.js"
|
||||
],
|
||||
"main": "dist/npm/",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@xrplf/isomorphic": "file:packages/isomorphic",
|
||||
"@xrplf/secret-numbers": "file:packages/secret-numbers",
|
||||
"xahau-address-codec": "file:packages/xahau-address-codec",
|
||||
"xahau-binary-codec": "file:packages/xahau-binary-codec",
|
||||
"xahau-keypairs": "file:packages/xahau-keypairs",
|
||||
"xahau": "file:packages/xahau"
|
||||
"ajv": "^4.0.5",
|
||||
"ajv-i18n": "^1.2.0",
|
||||
"babel-polyfill": "^6.3.14",
|
||||
"babel-runtime": "^6.3.19",
|
||||
"bignumber.js": "^2.0.3",
|
||||
"https-proxy-agent": "^1.0.0",
|
||||
"jayson": "^1.2.2",
|
||||
"lodash": "^3.1.0",
|
||||
"ripple-address-codec": "^2.0.1",
|
||||
"ripple-binary-codec": "^0.1.4",
|
||||
"ripple-hashes": "^0.1.0",
|
||||
"ripple-keypairs": "^0.10.0",
|
||||
"ripple-lib-transactionparser": "^0.6.0",
|
||||
"ws": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.21",
|
||||
"@types/jest": "^29.2.2",
|
||||
"@types/lodash": "^4.14.136",
|
||||
"@types/node": "^18.19.29",
|
||||
"@types/ws": "^8.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
||||
"@typescript-eslint/parser": "^5.28.0",
|
||||
"@xrplf/eslint-config": "^1.9.1",
|
||||
"@xrplf/prettier-config": "^1.9.1",
|
||||
"chai": "^4.3.4",
|
||||
"copyfiles": "^2.4.1",
|
||||
"eslint": "^8.18.0",
|
||||
"eslint-plugin-array-func": "^3.1.7",
|
||||
"eslint-plugin-consistent-default-export-name": "^0.0.15",
|
||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-jsdoc": "^39.3.3",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-tsdoc": "^0.2.16",
|
||||
"expect": "^29.3.1",
|
||||
"jest": "^29.3.1",
|
||||
"jest-mock": "^29.3.1",
|
||||
"lerna": "^4.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.3.2",
|
||||
"process": "^0.11.10",
|
||||
"source-map-loader": "^5.0.0",
|
||||
"source-map-support": "^0.5.16",
|
||||
"ts-jest": "^29.0.3",
|
||||
"ts-loader": "^9.2.5",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^5.1.6",
|
||||
"webpack": "^5.81.0",
|
||||
"webpack-bundle-analyzer": "^4.1.0",
|
||||
"webpack-cli": "^5.0.1"
|
||||
"assert-diff": "^1.0.1",
|
||||
"babel-cli": "^6.4.0",
|
||||
"babel-core": "^6.4.0",
|
||||
"babel-eslint": "^6.0.4",
|
||||
"babel-loader": "^6.2.1",
|
||||
"babel-plugin-syntax-flow": "^6.3.13",
|
||||
"babel-plugin-transform-flow-strip-types": "^6.4.0",
|
||||
"babel-preset-es2015": "^6.3.13",
|
||||
"babel-preset-stage-1": "^6.3.13",
|
||||
"babel-register": "^6.3.13",
|
||||
"coveralls": "^2.11.9",
|
||||
"doctoc": "^0.15.0",
|
||||
"ejs": "^2.3.4",
|
||||
"eslint": "^2.9.0",
|
||||
"eventemitter2": "^0.4.14",
|
||||
"flow-bin": "^0.30.0",
|
||||
"gulp": "^3.8.10",
|
||||
"gulp-bump": "^0.1.13",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-uglify": "^1.1.0",
|
||||
"http-server": "^0.8.5",
|
||||
"istanbul": "^1.1.0-alpha.1",
|
||||
"json-loader": "^0.5.2",
|
||||
"json-schema-to-markdown-table": "^0.4.0",
|
||||
"mocha": "^2.1.0",
|
||||
"mocha-in-sauce": "^0.0.1",
|
||||
"mocha-junit-reporter": "^1.9.1",
|
||||
"null-loader": "^0.1.1",
|
||||
"webpack": "^1.5.3",
|
||||
"yargs": "^1.3.1"
|
||||
},
|
||||
"workspaces": [
|
||||
"./packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "gulp",
|
||||
"doctoc": "doctoc docs/index.md --title '# RippleAPI Reference' --github --maxlevel 2",
|
||||
"docgen": "node --harmony scripts/build_docs.js",
|
||||
"clean": "rm -rf dist/npm && rm -rf build/flow",
|
||||
"typecheck": "babel --optional runtime --blacklist flow -d build/flow/ src/ && flow check",
|
||||
"compile": "babel -D --optional runtime -d dist/npm/ src/",
|
||||
"watch": "babel -w -D --optional runtime -d dist/npm/ src/",
|
||||
"compile-with-source-maps": "babel -D --optional runtime -s -t -d dist/npm/ src/",
|
||||
"prepublish": "npm run clean && npm run compile",
|
||||
"test": "babel-node ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha",
|
||||
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
||||
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; echo 'parser: babel-eslint' >> eslintrc; fi; eslint -c eslintrc src/",
|
||||
"perf": "./scripts/perf_test.sh",
|
||||
"start": "babel-node scripts/http.js",
|
||||
"sauce": "babel-node scripts/sauce-runner.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/ripple/ripple-lib.git"
|
||||
},
|
||||
"readmeFilename": "README.md",
|
||||
"engines": {
|
||||
"node": ">=18.0.0",
|
||||
"npm": ">=7.10.0 < 10.0.0"
|
||||
"node": ">=0.12.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
# Don't ever lint node_modules
|
||||
node_modules
|
||||
|
||||
# Don't lint build output
|
||||
dist
|
||||
|
||||
# don't lint nyc coverage output
|
||||
coverage
|
||||
.nyc_output
|
||||
|
||||
# Don't lint NYC configuration
|
||||
nyc.config.js
|
||||
|
||||
.idea
|
||||
@@ -1,75 +0,0 @@
|
||||
module.exports = {
|
||||
root: false,
|
||||
|
||||
parser: '@typescript-eslint/parser', // Make ESLint compatible with TypeScript
|
||||
parserOptions: {
|
||||
// Enable linting rules with type information from our tsconfig
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json', './tsconfig.eslint.json'],
|
||||
|
||||
sourceType: 'module', // Allow the use of imports / ES modules
|
||||
|
||||
ecmaFeatures: {
|
||||
impliedStrict: true, // Enable global strict mode
|
||||
},
|
||||
},
|
||||
|
||||
// Specify global variables that are predefined
|
||||
env: {
|
||||
browser: true, // Enable browser global variables
|
||||
node: true, // Enable node global variables & Node.js scoping
|
||||
es2020: true, // Add all ECMAScript 2020 globals and automatically set the ecmaVersion parser option to ES2020
|
||||
jest: true, // Add Jest testing global variables
|
||||
},
|
||||
|
||||
plugins: [],
|
||||
extends: ['@xrplf/eslint-config/base'],
|
||||
|
||||
rules: {
|
||||
// ** TODO **
|
||||
// all of the below are turned off for now during the migration to a
|
||||
// monorepo. They need to actually be addressed!
|
||||
// **
|
||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'off',
|
||||
'@typescript-eslint/no-unsafe-call': 'off',
|
||||
'@typescript-eslint/no-magic-numbers': 'off',
|
||||
'@typescript-eslint/ban-types': 'off',
|
||||
'@typescript-eslint/restrict-plus-operands': 'off',
|
||||
'@typescript-eslint/no-unsafe-return': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/explicit-member-accessibility': 'off',
|
||||
'@typescript-eslint/promise-function-async': 'off',
|
||||
'@typescript-eslint/restrict-template-expressions': 'off',
|
||||
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
||||
'@typescript-eslint/naming-convention': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/consistent-type-assertions': 'off',
|
||||
'import/no-unused-modules': 'off',
|
||||
'import/prefer-default-export': 'off',
|
||||
'jsdoc/require-jsdoc': 'off',
|
||||
'jsdoc/require-description': 'off',
|
||||
'jsdoc/require-returns': 'off',
|
||||
'jsdoc/require-description-complete-sentence': 'off',
|
||||
'jsdoc/check-tag-names': 'off',
|
||||
'jsdoc/check-examples': 'off', // Not implemented in eslint 8
|
||||
'jsdoc/no-types': 'off',
|
||||
'tsdoc/syntax': 'off',
|
||||
'import/order': 'off',
|
||||
'eslint-comments/require-description': 'off',
|
||||
'no-shadow': 'off',
|
||||
'multiline-comment-style': 'off',
|
||||
'@typescript-eslint/no-require-imports': 'off',
|
||||
},
|
||||
|
||||
overrides: [
|
||||
{
|
||||
files: ['test/*.test.ts'],
|
||||
// tests are importing through full module name to test in an isomorphic way
|
||||
rules: {
|
||||
'node/no-extraneous-import': 'off',
|
||||
'import/no-extraneous-dependencies': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
# @xrplf/isomorphic Release History
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 1.0.1 (2024-06-03)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Throw error if `hexToBytes` or `hexToString` is provided a string that is not in hex
|
||||
|
||||
## 1.0.0 (2024-02-01)
|
||||
|
||||
Initial release providing isomorphic and tree-shakable implementations of:
|
||||
|
||||
* ripemd160
|
||||
* sha256
|
||||
* sha512
|
||||
* bytesToHash
|
||||
* hashToBytes
|
||||
* hexToString
|
||||
* stringToHex
|
||||
* randomBytes
|
||||
* stringToHex
|
||||
* ws
|
||||
@@ -1,15 +0,0 @@
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2023 The XRPL developers
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -1,124 +0,0 @@
|
||||
# @xrplf/isomorphic
|
||||
|
||||
A collection of isomorphic implementations of crypto and utility functions.
|
||||
|
||||
Browser implementations of cryptographic functions use `@noble/hashes` and `crypto` for node .
|
||||
|
||||
### Hashes
|
||||
|
||||
All hash functions operate similarly to `@noble/hashes` and have the following properties:
|
||||
|
||||
- They can be called directly by providing a Uint8Array or string which will be converted into a UInt8Array via UTF-8 encoding (not hex).
|
||||
- They all return a UInt8Array.
|
||||
|
||||
```
|
||||
function hash(message: Uint8Array | string): Uint8Array;
|
||||
hash(new Uint8Array([1, 3]));
|
||||
hash('string') == hash(new TextEncoder().encode('string'));
|
||||
```
|
||||
|
||||
All hash functions can be constructed via `hash.create()` method:
|
||||
|
||||
- The result is `Hash` subclass instance, which has `update()` and `digest()` methods.
|
||||
- `digest()` finalizes the hash and makes it no longer usable
|
||||
|
||||
```typescript
|
||||
hash
|
||||
.create()
|
||||
.update(new Uint8Array([1, 3]))
|
||||
.digest();
|
||||
```
|
||||
|
||||
### `@xrplf/isomorphic/ripemd160`
|
||||
```typescript
|
||||
import { ripemd160 } from '@xrplf/isomorphic/ripemd160';
|
||||
const hashA = ripemd160('abc');
|
||||
const hashB = ripemd160
|
||||
.create()
|
||||
.update(Uint8Array.from([1, 2, 3]))
|
||||
.digest();
|
||||
```
|
||||
|
||||
### `@xrplf/isomorphic/sha256`
|
||||
|
||||
```typescript
|
||||
import { sha256 } from '@xrplf/isomorphic/sha256';
|
||||
const hashA = sha256('abc');
|
||||
const hashB = sha256
|
||||
.create()
|
||||
.update(Uint8Array.from([1, 2, 3]))
|
||||
.digest();
|
||||
```
|
||||
|
||||
### `@xrplf/isomorphic/sha512`
|
||||
|
||||
```typescript
|
||||
import { sha512 } from '@xrplf/isomorphic/sha512';
|
||||
const hashA = sha512('abc');
|
||||
const hashB = sha512
|
||||
.create()
|
||||
.update(Uint8Array.from([1, 2, 3]))
|
||||
.digest();
|
||||
```
|
||||
|
||||
## Utilities
|
||||
|
||||
### `@xrplf/isomorphic/utils`
|
||||
|
||||
#### randomBytes
|
||||
|
||||
Create an UInt8Array of the supplied size
|
||||
|
||||
```typescript
|
||||
import { randomBytes } from @xrplf/isomorphic/utils
|
||||
|
||||
console.log(randomBytes(12)) // Uint8Array(12) [95, 236, 188, 55, 208, 128, 161, 249, 171, 57, 141, 7]
|
||||
```
|
||||
|
||||
#### bytesToHex
|
||||
|
||||
Convert an UInt8Array to hex.
|
||||
|
||||
```typescript
|
||||
import { bytesToHex } from @xrplf/isomorphic/utils
|
||||
|
||||
console.log(bytesToHex([222, 173, 190, 239])) // "DEADBEEF"
|
||||
```
|
||||
|
||||
#### hexToBytes
|
||||
|
||||
Convert hex to an UInt8Array.
|
||||
|
||||
```typescript
|
||||
import { hexToBytes } from @xrplf/isomorphic/utils
|
||||
|
||||
console.log(hexToBytes('DEADBEEF')) // [222, 173, 190, 239]
|
||||
```
|
||||
|
||||
#### hexToString
|
||||
|
||||
Converts hex to its string equivalent. Useful to read the Domain field and some Memos.
|
||||
|
||||
```typescript
|
||||
import { hexToString } from @xrplf/isomorphic/utils
|
||||
|
||||
console.log(hexToString('6465616462656566D68D')) // "deadbeef֍"
|
||||
```
|
||||
|
||||
#### stringToHex
|
||||
|
||||
Converts a utf-8 to its hex equivalent. Useful for Memos.
|
||||
|
||||
```typescript
|
||||
import { stringToHex } from @xrplf/isomorphic/utils
|
||||
|
||||
console.log(stringToHex('deadbeef֍')) // "6465616462656566D68D"
|
||||
```
|
||||
|
||||
### `@xrplf/isomorphic/ws`
|
||||
|
||||
```typescript
|
||||
import WebSocket from '@xrplf/isomorphic/ws'
|
||||
|
||||
const socket = new WebSocket('wss://localhost:8080')
|
||||
```
|
||||
@@ -1,8 +0,0 @@
|
||||
// Jest configuration for api
|
||||
const base = require('../../jest.config.base.js')
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
roots: [...base.roots, '<rootDir>/test'],
|
||||
displayName: '@xrplf/isomorphic',
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
const baseKarmaConfig = require('../../karma.config')
|
||||
const webpackConfig = require('./test/webpack.config')
|
||||
delete webpackConfig.entry
|
||||
|
||||
module.exports = function (config) {
|
||||
baseKarmaConfig(config)
|
||||
|
||||
config.set({
|
||||
base: '',
|
||||
webpack: webpackConfig,
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: ['test/**/*.test.ts'],
|
||||
})
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
{
|
||||
"name": "@xrplf/isomorphic",
|
||||
"version": "1.0.1",
|
||||
"description": "A collection of isomorphic and tree-shakeable crypto hashes and utils for xahau.js",
|
||||
"keywords": [
|
||||
"crypto",
|
||||
"isomorphic",
|
||||
"xahau"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc --build ./tsconfig.build.json",
|
||||
"test": "npm run build && jest --verbose false --silent=false ./test/*.test.ts",
|
||||
"test:browser": "npm run build && karma start ./karma.config.js",
|
||||
"clean": "rm -rf ./dist ./coverage ./test/testCompiledForWeb tsconfig.build.tsbuildinfo",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"prepublish": "npm run lint && npm test"
|
||||
},
|
||||
"files": [
|
||||
"dist/*",
|
||||
"sha256/*",
|
||||
"sha512/*",
|
||||
"ripemd160/*",
|
||||
"src/*",
|
||||
"utils/*",
|
||||
"ws/*"
|
||||
],
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@noble/hashes": "^1.0.0",
|
||||
"eventemitter3": "5.0.1",
|
||||
"ws": "^8.13.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.18.38",
|
||||
"@types/ws": "^8.5.6"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:Xahau/xahau.js.git"
|
||||
},
|
||||
"license": "ISC",
|
||||
"prettier": "@xrplf/prettier-config",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "@xrplf/isomorphic/ripemd160",
|
||||
"private": true,
|
||||
"main": "../dist/ripemd160",
|
||||
"types": "../dist/ripemd160",
|
||||
"browser": "../dist/ripemd160/browser.js"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "@xrplf/isomorphic/sha256",
|
||||
"private": true,
|
||||
"main": "../dist/sha256",
|
||||
"types": "../dist/sha256",
|
||||
"browser": "../dist/sha256/browser.js"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "@xrplf/isomorphic/sha512",
|
||||
"private": true,
|
||||
"main": "../dist/sha512",
|
||||
"types": "../dist/sha512",
|
||||
"browser": "../dist/sha512/browser.js"
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Input } from './types'
|
||||
|
||||
/**
|
||||
* Normalize a string, number array, or Uint8Array to a string or Uint8Array.
|
||||
* Both node and noble lib functions accept these types.
|
||||
*
|
||||
* @param input - value to normalize
|
||||
*/
|
||||
export default function normalizeInput(input: Input): string | Uint8Array {
|
||||
return Array.isArray(input) ? new Uint8Array(input) : input
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
export type ByteEncodedString = string
|
||||
export type Input = Uint8Array | number[] | ByteEncodedString
|
||||
|
||||
/**
|
||||
* A stripped down isomorphic hash inspired by node's `crypto.Hash`
|
||||
*/
|
||||
export interface Hash {
|
||||
/**
|
||||
* Updates the hash content with the given data,
|
||||
*
|
||||
* @param data - a byte encoded string, an array of numbers or a Uint8Array
|
||||
*/
|
||||
update: (data: Input) => this
|
||||
/**
|
||||
* Calculates the digest of all the data passed to be hashed and returns a Uint8Array
|
||||
*/
|
||||
digest: () => Uint8Array
|
||||
}
|
||||
|
||||
export interface HashFn {
|
||||
/**
|
||||
* Produces a Uint8Array for the given hash contents
|
||||
* Shorthand for calling `create`, `update`, and then `digest`
|
||||
*
|
||||
* @param data - a byte encoded string, an array of numbers or a Uint8Array
|
||||
*/
|
||||
(data: Input): Uint8Array
|
||||
|
||||
/**
|
||||
* Creates a new empty `Hash`.
|
||||
*/
|
||||
create: () => Hash
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import { createHash } from 'crypto'
|
||||
import { Hash, HashFn, Input } from './types'
|
||||
import normalizeInput from './normalizeInput'
|
||||
|
||||
/**
|
||||
* Wrap createHash from node to provide an interface that is isomorphic
|
||||
*
|
||||
* @param type - the hash name
|
||||
* @param fn - {createHash} the hash factory
|
||||
*/
|
||||
export default function wrapCryptoCreateHash(
|
||||
type: string,
|
||||
fn: typeof createHash,
|
||||
): HashFn {
|
||||
function hashFn(input: Input): Uint8Array {
|
||||
return fn(type).update(normalizeInput(input)).digest()
|
||||
}
|
||||
|
||||
hashFn.create = (): Hash => {
|
||||
const hash = fn(type)
|
||||
return {
|
||||
update(input: Input): Hash {
|
||||
hash.update(normalizeInput(input))
|
||||
return this
|
||||
},
|
||||
digest(): Uint8Array {
|
||||
return hash.digest()
|
||||
},
|
||||
}
|
||||
}
|
||||
return hashFn
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import { CHash } from '@noble/hashes/utils'
|
||||
import { Hash, HashFn, Input } from './types'
|
||||
import normalizeInput from './normalizeInput'
|
||||
|
||||
/**
|
||||
* Wrap a CHash object from @noble/hashes to provide a interface that is isomorphic
|
||||
*
|
||||
* @param chash - {CHash} hash function to wrap
|
||||
*/
|
||||
export default function wrapNoble(chash: CHash): HashFn {
|
||||
function wrapped(input: Input): Uint8Array {
|
||||
return chash(normalizeInput(input))
|
||||
}
|
||||
|
||||
wrapped.create = (): Hash => {
|
||||
const hash = chash.create()
|
||||
return {
|
||||
update(input: Input): Hash {
|
||||
hash.update(normalizeInput(input))
|
||||
return this
|
||||
},
|
||||
digest(): Uint8Array {
|
||||
return hash.digest()
|
||||
},
|
||||
}
|
||||
}
|
||||
return wrapped
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { ripemd160 as nobleImpl } from '@noble/hashes/ripemd160'
|
||||
|
||||
import wrapNoble from '../internal/wrapNoble'
|
||||
|
||||
/**
|
||||
* Wrap noble-libs's ripemd160 implementation in HashFn
|
||||
*/
|
||||
export const ripemd160 = wrapNoble(nobleImpl)
|
||||
@@ -1,7 +0,0 @@
|
||||
import { createHash } from 'crypto'
|
||||
import wrapCryptoCreateHash from '../internal/wrapCryptoCreateHash'
|
||||
|
||||
/**
|
||||
* Wrap node's native ripemd160 implementation in HashFn
|
||||
*/
|
||||
export const ripemd160 = wrapCryptoCreateHash('ripemd160', createHash)
|
||||
@@ -1,8 +0,0 @@
|
||||
import { sha256 as nobleImpl } from '@noble/hashes/sha256'
|
||||
|
||||
import wrapNoble from '../internal/wrapNoble'
|
||||
|
||||
/**
|
||||
* Wrap noble-libs's sha256 implementation in HashFn
|
||||
*/
|
||||
export const sha256 = wrapNoble(nobleImpl)
|
||||
@@ -1,7 +0,0 @@
|
||||
import { createHash } from 'crypto'
|
||||
import wrapCryptoCreateHash from '../internal/wrapCryptoCreateHash'
|
||||
|
||||
/**
|
||||
* Wrap node's native sha256 implementation in HashFn
|
||||
*/
|
||||
export const sha256 = wrapCryptoCreateHash('sha256', createHash)
|
||||
@@ -1,8 +0,0 @@
|
||||
import { sha512 as nobleImpl } from '@noble/hashes/sha512'
|
||||
|
||||
import wrapNoble from '../internal/wrapNoble'
|
||||
|
||||
/**
|
||||
* Wrap noble-libs's sha512 implementation in HashFn
|
||||
*/
|
||||
export const sha512 = wrapNoble(nobleImpl)
|
||||
@@ -1,7 +0,0 @@
|
||||
import { createHash } from 'crypto'
|
||||
import wrapCryptoCreateHash from '../internal/wrapCryptoCreateHash'
|
||||
|
||||
/**
|
||||
* Wrap node's native sha512 implementation in HashFn
|
||||
*/
|
||||
export const sha512 = wrapCryptoCreateHash('sha512', createHash)
|
||||
@@ -1,54 +0,0 @@
|
||||
import {
|
||||
bytesToHex as nobleBytesToHex,
|
||||
randomBytes as nobleRandomBytes,
|
||||
} from '@noble/hashes/utils'
|
||||
import type {
|
||||
BytesToHexFn,
|
||||
HexToBytesFn,
|
||||
HexToStringFn,
|
||||
RandomBytesFn,
|
||||
StringToHexFn,
|
||||
} from './types'
|
||||
import { HEX_REGEX } from './shared'
|
||||
|
||||
/* eslint-disable func-style -- Typed to ensure uniformity between node and browser implementations and docs */
|
||||
export const bytesToHex: typeof BytesToHexFn = (bytes) => {
|
||||
const hex = nobleBytesToHex(
|
||||
bytes instanceof Uint8Array ? bytes : Uint8Array.from(bytes),
|
||||
)
|
||||
return hex.toUpperCase()
|
||||
}
|
||||
|
||||
// A clone of hexToBytes from @noble/hashes without the length checks. This allows us to do our own checks.
|
||||
export const hexToBytes: typeof HexToBytesFn = (hex): Uint8Array => {
|
||||
const len = hex.length
|
||||
const array = new Uint8Array(len / 2)
|
||||
if (!HEX_REGEX.test(hex)) {
|
||||
throw new Error('Invalid hex string')
|
||||
}
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const j = i * 2
|
||||
const hexByte = hex.slice(j, j + 2)
|
||||
const byte = Number.parseInt(hexByte, 16)
|
||||
if (Number.isNaN(byte) || byte < 0) {
|
||||
throw new Error('Invalid byte sequence')
|
||||
}
|
||||
array[i] = byte
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
export const hexToString: typeof HexToStringFn = (
|
||||
hex: string,
|
||||
encoding = 'utf8',
|
||||
): string => {
|
||||
return new TextDecoder(encoding).decode(hexToBytes(hex))
|
||||
}
|
||||
|
||||
export const stringToHex: typeof StringToHexFn = (string: string): string => {
|
||||
return bytesToHex(new TextEncoder().encode(string))
|
||||
}
|
||||
/* eslint-enable func-style */
|
||||
|
||||
export const randomBytes: typeof RandomBytesFn = nobleRandomBytes
|
||||
export * from './shared'
|
||||
@@ -1,93 +0,0 @@
|
||||
import { randomBytes as cryptoRandomBytes } from 'crypto'
|
||||
import type { BytesToHexFn, HexToBytesFn, RandomBytesFn } from './types'
|
||||
import { HexToStringFn, StringToHexFn } from './types'
|
||||
import { HEX_REGEX } from './shared'
|
||||
|
||||
const OriginalBuffer = Symbol('OriginalBuffer')
|
||||
|
||||
/**
|
||||
* An extended Uint8Array that incorporates a reference to the original Node.js Buffer.
|
||||
*
|
||||
* When converting a Node.js Buffer to a Uint8Array, there's an optimization that shares
|
||||
* the memory of the original Buffer with the resulting Uint8Array instead of copying data.
|
||||
* The Uint8ArrayWithReference interface is used to attach a reference to the original Buffer, ensuring
|
||||
* its persistence in memory (preventing garbage collection) as long as the Uint8Array exists.
|
||||
* This strategy upholds the ownership semantics of the slice of the ArrayBuffer.
|
||||
*/
|
||||
interface Uint8ArrayWithReference extends Uint8Array {
|
||||
[OriginalBuffer]: Buffer
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Node.js Buffer to a Uint8Array for uniform behavior with browser implementations.
|
||||
*
|
||||
* Choices:
|
||||
* 1. Directly returning the Buffer:
|
||||
* - Operation: Return Buffer as is (a Buffer *IS* an instanceof Uint8Array).
|
||||
* - Pros: Most memory and performance efficient.
|
||||
* - Cons: Violates strict Uint8Array typing and may lead to issues where Buffer-specific features are [ab]used.
|
||||
*
|
||||
* 2. Using `new Uint8Array(buffer)` or `Uint8Array.from(buffer)`:
|
||||
* - Operation: Copies the buffer's data into a new Uint8Array.
|
||||
* - Pros: Ensures data isolation; memory-safe.
|
||||
* - Cons: Less performant due to data duplication.
|
||||
*
|
||||
* 3. Using buf.buffer slice:
|
||||
* - Operation: Shares memory between Buffer and Uint8Array.
|
||||
* - Pros: Performant.
|
||||
* - Cons: Risks with shared memory and potential for invalid references.
|
||||
*
|
||||
* 4. Using buf.buffer slice and keeping a Buffer reference for ownership semantics:
|
||||
* - Operation: Shares memory and associates the original Buffer with the resulting Uint8Array.
|
||||
* - Pros: Performant while ensuring the original Buffer isn't garbage collected.
|
||||
* - Cons: Risks with shared memory but mitigates potential for invalid references.
|
||||
*
|
||||
* The chosen method (4) prioritizes performance by sharing memory while ensuring buffer ownership.
|
||||
*
|
||||
* @param {Buffer} buffer - The Node.js Buffer to convert.
|
||||
* @returns {Uint8Array} Resulting Uint8Array sharing the same memory as the Buffer and maintaining a reference to it.
|
||||
*/
|
||||
function toUint8Array(buffer: Buffer): Uint8Array {
|
||||
const u8Array = new Uint8Array(
|
||||
buffer.buffer.slice(
|
||||
buffer.byteOffset,
|
||||
buffer.byteOffset + buffer.byteLength,
|
||||
),
|
||||
) as Uint8ArrayWithReference
|
||||
u8Array[OriginalBuffer] = buffer
|
||||
return u8Array
|
||||
}
|
||||
|
||||
/* eslint-disable func-style -- Typed to ensure uniformity between node and browser implementations and docs */
|
||||
export const bytesToHex: typeof BytesToHexFn = (bytes) => {
|
||||
const buf = Buffer.from(bytes)
|
||||
return buf.toString('hex').toUpperCase()
|
||||
}
|
||||
|
||||
export const hexToBytes: typeof HexToBytesFn = (hex) => {
|
||||
if (!HEX_REGEX.test(hex)) {
|
||||
throw new Error('Invalid hex string')
|
||||
}
|
||||
return toUint8Array(Buffer.from(hex, 'hex'))
|
||||
}
|
||||
|
||||
export const randomBytes: typeof RandomBytesFn = (size) => {
|
||||
return toUint8Array(cryptoRandomBytes(size))
|
||||
}
|
||||
|
||||
export const hexToString: typeof HexToStringFn = (
|
||||
hex: string,
|
||||
encoding = 'utf8',
|
||||
): string => {
|
||||
if (!HEX_REGEX.test(hex)) {
|
||||
throw new Error('Invalid hex string')
|
||||
}
|
||||
return new TextDecoder(encoding).decode(hexToBytes(hex))
|
||||
}
|
||||
|
||||
export const stringToHex: typeof StringToHexFn = (string: string): string => {
|
||||
return bytesToHex(new TextEncoder().encode(string))
|
||||
}
|
||||
/* eslint-enable func-style */
|
||||
|
||||
export * from './shared'
|
||||
@@ -1,21 +0,0 @@
|
||||
import { concatBytes } from '@noble/hashes/utils'
|
||||
|
||||
export const HEX_REGEX = /^[A-F0-9]*$/iu
|
||||
|
||||
export function concat(views: Uint8Array[]): Uint8Array {
|
||||
return concatBytes(...views)
|
||||
}
|
||||
|
||||
export function equal(buf1: Uint8Array, buf2: Uint8Array): boolean {
|
||||
if (buf1.byteLength !== buf2.byteLength) {
|
||||
return false
|
||||
}
|
||||
const dv1 = new Int8Array(buf1)
|
||||
const dv2 = new Int8Array(buf2)
|
||||
for (let i = 0; i !== buf1.byteLength; i++) {
|
||||
if (dv1[i] !== dv2[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* Convert a UInt8Array to hex. The returned hex will be in all caps.
|
||||
*
|
||||
* @param bytes - {Uint8Array} to convert to hex
|
||||
*/
|
||||
export declare function BytesToHexFn(bytes: Uint8Array | number[]): string
|
||||
|
||||
/**
|
||||
* Convert hex to a Uint8Array.
|
||||
*
|
||||
* @param hex - {string} to convert to a Uint8Array
|
||||
*/
|
||||
export declare function HexToBytesFn(hex: string): Uint8Array
|
||||
|
||||
/**
|
||||
* Create a Uint8Array of the supplied size.
|
||||
*
|
||||
* @param size - number of bytes to generate
|
||||
*/
|
||||
export declare function RandomBytesFn(size: number): Uint8Array
|
||||
|
||||
/**
|
||||
* Converts hex to its string equivalent. Useful to read the Domain field and some Memos.
|
||||
*
|
||||
* @param hex - The hex to convert to a string.
|
||||
* @param encoding - The encoding to use. Defaults to 'utf8' (UTF-8). 'ascii' is also allowed.
|
||||
* @returns The converted string.
|
||||
*/
|
||||
export declare function HexToStringFn(hex: string, encoding?: string): string
|
||||
|
||||
/**
|
||||
* Converts a utf-8 to its hex equivalent. Useful for Memos.
|
||||
*
|
||||
* @param string - The string to convert to Hex.
|
||||
* @returns The Hex equivalent of the string.
|
||||
*/
|
||||
export declare function StringToHexFn(string: string): string
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user