mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-09 07:15:48 +00:00
Compare commits
6 Commits
xrpl@2.0.3
...
gw/more-li
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0aad4e7d31 | ||
|
|
78d9b11794 | ||
|
|
4e0a093677 | ||
|
|
fe845de884 | ||
|
|
8461ef6804 | ||
|
|
7c6230b18e |
40
package-lock.json
generated
40
package-lock.json
generated
@@ -15575,8 +15575,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/typedoc": {
|
||||
"version": "0.22.8",
|
||||
"integrity": "sha512-92S+YzyhospdXN5rnkYUTgirdTYqNWY7NP9vco+IqQQoiSXzVSUsawVro+tMyEEsWUS7EMaJ2YOjB9uE0CBi6A==",
|
||||
"version": "0.22.10",
|
||||
"resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.22.10.tgz",
|
||||
"integrity": "sha512-hQYZ4WtoMZ61wDC6w10kxA42+jclWngdmztNZsDvIz7BMJg7F2xnT+uYsUa7OluyKossdFj9E9Ye4QOZKTy8SA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"glob": "^7.2.0",
|
||||
@@ -15592,7 +15593,7 @@
|
||||
"node": ">= 12.10.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "4.0.x || 4.1.x || 4.2.x || 4.3.x || 4.4.x"
|
||||
"typescript": "4.0.x || 4.1.x || 4.2.x || 4.3.x || 4.4.x || 4.5.x"
|
||||
}
|
||||
},
|
||||
"node_modules/typedoc/node_modules/glob": {
|
||||
@@ -16607,7 +16608,7 @@
|
||||
}
|
||||
},
|
||||
"packages/ripple-address-codec": {
|
||||
"version": "4.2.1-beta.0",
|
||||
"version": "4.2.2",
|
||||
"integrity": "sha512-9QhBNDiWjwj7l+WQ7H7klXF/VwxVj2Q0HRhd4vLCueTPoxUtaNQyfvUZFiXJrqxg0heM3/iWxupkq4TwrXgSuQ==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
@@ -16619,7 +16620,7 @@
|
||||
}
|
||||
},
|
||||
"packages/ripple-binary-codec": {
|
||||
"version": "1.2.1-beta.0",
|
||||
"version": "1.2.2",
|
||||
"integrity": "sha512-XMRCbFXyG+dGp3x7tMs9IwA+FVWPPaGjdHYW2+g4Q/WQJqFp5MRED+jjOBOUafmrW4TUsOn1PEEdbB4ozWbDBw==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
@@ -16628,7 +16629,7 @@
|
||||
"buffer": "5.6.0",
|
||||
"create-hash": "^1.2.0",
|
||||
"decimal.js": "^10.2.0",
|
||||
"ripple-address-codec": "^4.2.1-beta.0"
|
||||
"ripple-address-codec": "^4.2.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.22.0"
|
||||
@@ -16643,7 +16644,7 @@
|
||||
}
|
||||
},
|
||||
"packages/ripple-keypairs": {
|
||||
"version": "1.1.1-beta.0",
|
||||
"version": "1.1.2",
|
||||
"integrity": "sha512-Zlmbtn2YUpW4uKlLm2/tpkY5RC/EXQlkJwIIKp0AoF9D23pJ43/EuipNW2F6qURdbkUezDwB0bMV7uRXip3x2w==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
@@ -16651,14 +16652,14 @@
|
||||
"brorand": "^1.0.5",
|
||||
"elliptic": "^6.5.4",
|
||||
"hash.js": "^1.0.3",
|
||||
"ripple-address-codec": "^4.2.1-beta.0"
|
||||
"ripple-address-codec": "^4.2.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"packages/xrpl": {
|
||||
"version": "2.0.3-beta.0",
|
||||
"version": "2.0.4",
|
||||
"integrity": "sha512-NmrSYpXym7NzGABeXU1H8g4ZtCxRhr/3wu0lguxzcIYpcKPgWLYimg+s9NLLNbPWTZdxXu9SeSWu5zh4gyqAeA==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
@@ -16667,9 +16668,9 @@
|
||||
"bip39": "^3.0.4",
|
||||
"https-proxy-agent": "^5.0.0",
|
||||
"lodash": "^4.17.4",
|
||||
"ripple-address-codec": "^4.2.1-beta.0",
|
||||
"ripple-binary-codec": "^1.2.1-beta.0",
|
||||
"ripple-keypairs": "^1.1.1-beta.0",
|
||||
"ripple-address-codec": "^4.2.2",
|
||||
"ripple-binary-codec": "^1.2.2",
|
||||
"ripple-keypairs": "^1.1.2",
|
||||
"ws": "^8.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -27095,7 +27096,7 @@
|
||||
"buffer": "5.6.0",
|
||||
"create-hash": "^1.2.0",
|
||||
"decimal.js": "^10.2.0",
|
||||
"ripple-address-codec": "^4.2.1-beta.0"
|
||||
"ripple-address-codec": "^4.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"buffer": {
|
||||
@@ -27115,7 +27116,7 @@
|
||||
"brorand": "^1.0.5",
|
||||
"elliptic": "^6.5.4",
|
||||
"hash.js": "^1.0.3",
|
||||
"ripple-address-codec": "^4.2.1-beta.0"
|
||||
"ripple-address-codec": "^4.2.2"
|
||||
}
|
||||
},
|
||||
"rsvp": {
|
||||
@@ -28569,8 +28570,9 @@
|
||||
}
|
||||
},
|
||||
"typedoc": {
|
||||
"version": "0.22.8",
|
||||
"integrity": "sha512-92S+YzyhospdXN5rnkYUTgirdTYqNWY7NP9vco+IqQQoiSXzVSUsawVro+tMyEEsWUS7EMaJ2YOjB9uE0CBi6A==",
|
||||
"version": "0.22.10",
|
||||
"resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.22.10.tgz",
|
||||
"integrity": "sha512-hQYZ4WtoMZ61wDC6w10kxA42+jclWngdmztNZsDvIz7BMJg7F2xnT+uYsUa7OluyKossdFj9E9Ye4QOZKTy8SA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "^7.2.0",
|
||||
@@ -29252,9 +29254,9 @@
|
||||
"bip39": "^3.0.4",
|
||||
"https-proxy-agent": "^5.0.0",
|
||||
"lodash": "^4.17.4",
|
||||
"ripple-address-codec": "^4.2.1-beta.0",
|
||||
"ripple-binary-codec": "^1.2.1-beta.0",
|
||||
"ripple-keypairs": "^1.1.1-beta.0",
|
||||
"ripple-address-codec": "^4.2.2",
|
||||
"ripple-binary-codec": "^1.2.2",
|
||||
"ripple-keypairs": "^1.1.2",
|
||||
"ws": "^8.2.2",
|
||||
"xrpl-local": "file:src"
|
||||
},
|
||||
|
||||
@@ -34,18 +34,7 @@ module.exports = {
|
||||
// monorepo. They need to actually be addressed!
|
||||
// **
|
||||
'@typescript-eslint/consistent-type-assertions': 'off',
|
||||
'@typescript-eslint/no-unnecessary-condition': 'off',
|
||||
'@typescript-eslint/no-unsafe-call': 'off',
|
||||
'@typescript-eslint/no-magic-numbers': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': '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/prefer-nullish-coalescing': 'off',
|
||||
'@typescript-eslint/naming-convention': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'jsdoc/require-returns': 'off',
|
||||
'jsdoc/check-param-names': 'off',
|
||||
'jsdoc/require-throws': 'off',
|
||||
'jsdoc/require-jsdoc': 'off',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-address-codec",
|
||||
"version": "4.2.1-beta.0",
|
||||
"version": "4.2.2",
|
||||
"description": "encodes/decodes base58 encoded XRP Ledger identifiers",
|
||||
"files": [
|
||||
"dist/*",
|
||||
|
||||
@@ -13,12 +13,15 @@ import {
|
||||
isValidClassicAddress,
|
||||
} from './xrp-codec'
|
||||
|
||||
/* eslint-disable @typescript-eslint/naming-convention --
|
||||
* there are just sub constants */
|
||||
const PREFIX_BYTES = {
|
||||
// 5, 68
|
||||
MAIN: Buffer.from([0x05, 0x44]),
|
||||
// 4, 147
|
||||
TEST: Buffer.from([0x04, 0x93]),
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
const MAX_32_BIT_UNSIGNED_INT = 4294967295
|
||||
|
||||
@@ -72,6 +75,8 @@ function encodeXAddress(
|
||||
return codec.encodeChecked(bytes)
|
||||
}
|
||||
|
||||
/* eslint-disable @typescript-eslint/naming-convention --
|
||||
* not a big deal on these old param names */
|
||||
function xAddressToClassicAddress(xAddress: string): {
|
||||
classicAddress: string
|
||||
tag: number | false
|
||||
@@ -85,7 +90,10 @@ function xAddressToClassicAddress(xAddress: string): {
|
||||
test,
|
||||
}
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
/* eslint-disable @typescript-eslint/naming-convention --
|
||||
* not a big deal on these old param names */
|
||||
function decodeXAddress(xAddress: string): {
|
||||
accountId: Buffer
|
||||
tag: number | false
|
||||
@@ -101,6 +109,7 @@ function decodeXAddress(xAddress: string): {
|
||||
test,
|
||||
}
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
function isBufferForTestAddress(buf: Buffer): boolean {
|
||||
const decodedPrefix = buf.slice(0, 2)
|
||||
|
||||
@@ -5,6 +5,8 @@ type Sequence = number[] | Buffer | Uint8Array
|
||||
*
|
||||
* @param arr1 - One of the arrays to compare.
|
||||
* @param arr2 - The other array to compare.
|
||||
*
|
||||
* @returns true if arguments are equal; false otherwise.
|
||||
*/
|
||||
export function seqEqual(arr1: Sequence, arr2: Sequence): boolean {
|
||||
if (arr1.length !== arr2.length) {
|
||||
@@ -23,9 +25,11 @@ export function seqEqual(arr1: Sequence, arr2: Sequence): boolean {
|
||||
* Check whether a value is a sequence (e.g. Array of numbers).
|
||||
*
|
||||
* @param val - The value to check.
|
||||
*
|
||||
* @returns true if value is a Sequence; false otherwise.
|
||||
*/
|
||||
function isSequence(val: Sequence | number): val is Sequence {
|
||||
return (val as Sequence).length !== undefined
|
||||
return typeof val === 'object' && val.length !== undefined
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,20 +7,24 @@ import * as createHash from 'create-hash'
|
||||
|
||||
import { seqEqual, concatArgs } from './utils'
|
||||
|
||||
class Codec {
|
||||
sha256: (bytes: Uint8Array) => Buffer
|
||||
alphabet: string
|
||||
codec: baseCodec.BaseConverter
|
||||
base: number
|
||||
interface Decoded {
|
||||
version: number[]
|
||||
bytes: Buffer
|
||||
type: string | null
|
||||
}
|
||||
|
||||
constructor(options: {
|
||||
class Codec {
|
||||
private readonly _sha256: (bytes: Uint8Array) => Buffer
|
||||
private readonly _alphabet: string
|
||||
private readonly _codec: baseCodec.BaseConverter
|
||||
|
||||
public constructor(options: {
|
||||
sha256: (bytes: Uint8Array) => Buffer
|
||||
alphabet: string
|
||||
}) {
|
||||
this.sha256 = options.sha256
|
||||
this.alphabet = options.alphabet
|
||||
this.codec = baseCodec(this.alphabet)
|
||||
this.base = this.alphabet.length
|
||||
this._sha256 = options.sha256
|
||||
this._alphabet = options.alphabet
|
||||
this._codec = baseCodec(this._alphabet)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,8 +32,10 @@ class Codec {
|
||||
*
|
||||
* @param bytes - Buffer of data to encode.
|
||||
* @param opts - Options object including the version bytes and the expected length of the data to encode.
|
||||
*
|
||||
* @returns bytes encoded using options
|
||||
*/
|
||||
encode(
|
||||
public encode(
|
||||
bytes: Buffer,
|
||||
opts: {
|
||||
versions: number[]
|
||||
@@ -40,29 +46,11 @@ class Codec {
|
||||
return this.encodeVersioned(bytes, versions, opts.expectedLength)
|
||||
}
|
||||
|
||||
encodeVersioned(
|
||||
bytes: Buffer,
|
||||
versions: number[],
|
||||
expectedLength: number,
|
||||
): string {
|
||||
if (expectedLength && bytes.length !== expectedLength) {
|
||||
throw new Error(
|
||||
'unexpected_payload_length: bytes.length does not match expectedLength.' +
|
||||
' Ensure that the bytes are a Buffer.',
|
||||
)
|
||||
}
|
||||
return this.encodeChecked(Buffer.from(concatArgs(versions, bytes)))
|
||||
}
|
||||
|
||||
encodeChecked(buffer: Buffer): string {
|
||||
const check = this.sha256(this.sha256(buffer)).slice(0, 4)
|
||||
public encodeChecked(buffer: Buffer): string {
|
||||
const check = this._sha256(this._sha256(buffer)).slice(0, 4)
|
||||
return this.encodeRaw(Buffer.from(concatArgs(buffer, check)))
|
||||
}
|
||||
|
||||
encodeRaw(bytes: Buffer): string {
|
||||
return this.codec.encode(bytes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Decoder.
|
||||
*
|
||||
@@ -71,18 +59,14 @@ class Codec {
|
||||
*/
|
||||
/* eslint-disable max-lines-per-function --
|
||||
* TODO refactor */
|
||||
decode(
|
||||
public decode(
|
||||
base58string: string,
|
||||
opts: {
|
||||
versions: Array<number | number[]>
|
||||
expectedLength?: number
|
||||
versionTypes?: ['ed25519', 'secp256k1']
|
||||
},
|
||||
): {
|
||||
version: number[]
|
||||
bytes: Buffer
|
||||
type: string | null
|
||||
} {
|
||||
): Decoded {
|
||||
const versions = opts.versions
|
||||
const types = opts.versionTypes
|
||||
|
||||
@@ -96,7 +80,7 @@ class Codec {
|
||||
const versionLengthGuess =
|
||||
typeof versions[0] === 'number' ? 1 : versions[0].length
|
||||
const payloadLength =
|
||||
opts.expectedLength || withoutSum.length - versionLengthGuess
|
||||
opts.expectedLength ?? withoutSum.length - versionLengthGuess
|
||||
const versionBytes = withoutSum.slice(0, -payloadLength)
|
||||
const payload = withoutSum.slice(-payloadLength)
|
||||
|
||||
@@ -119,7 +103,7 @@ class Codec {
|
||||
}
|
||||
/* eslint-enable max-lines-per-function */
|
||||
|
||||
decodeChecked(base58string: string): Buffer {
|
||||
public decodeChecked(base58string: string): Buffer {
|
||||
const buffer = this.decodeRaw(base58string)
|
||||
if (buffer.length < 5) {
|
||||
throw new Error('invalid_input_size: decoded data must have length >= 5')
|
||||
@@ -130,12 +114,30 @@ class Codec {
|
||||
return buffer.slice(0, -4)
|
||||
}
|
||||
|
||||
decodeRaw(base58string: string): Buffer {
|
||||
return this.codec.decode(base58string)
|
||||
private encodeVersioned(
|
||||
bytes: Buffer,
|
||||
versions: number[],
|
||||
expectedLength: number,
|
||||
): string {
|
||||
if (expectedLength && bytes.length !== expectedLength) {
|
||||
throw new Error(
|
||||
'unexpected_payload_length: bytes.length does not match expectedLength.' +
|
||||
' Ensure that the bytes are a Buffer.',
|
||||
)
|
||||
}
|
||||
return this.encodeChecked(Buffer.from(concatArgs(versions, bytes)))
|
||||
}
|
||||
|
||||
verifyCheckSum(bytes: Buffer): boolean {
|
||||
const computed = this.sha256(this.sha256(bytes.slice(0, -4))).slice(0, 4)
|
||||
private encodeRaw(bytes: Buffer): string {
|
||||
return this._codec.encode(bytes)
|
||||
}
|
||||
|
||||
private decodeRaw(base58string: string): Buffer {
|
||||
return this._codec.decode(base58string)
|
||||
}
|
||||
|
||||
private verifyCheckSum(bytes: Buffer): boolean {
|
||||
const computed = this._sha256(this._sha256(bytes.slice(0, -4))).slice(0, 4)
|
||||
const checksum = bytes.slice(-4)
|
||||
return seqEqual(computed, checksum)
|
||||
}
|
||||
@@ -159,7 +161,7 @@ const NODE_PUBLIC = 0x1c
|
||||
const ED25519_SEED = [0x01, 0xe1, 0x4b]
|
||||
|
||||
const codecOptions = {
|
||||
sha256(bytes: Uint8Array) {
|
||||
sha256(bytes: Uint8Array): Buffer {
|
||||
return createHash('sha256').update(Buffer.from(bytes)).digest()
|
||||
},
|
||||
alphabet: 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz',
|
||||
@@ -200,7 +202,7 @@ export function decodeSeed(
|
||||
versions: [ED25519_SEED, FAMILY_SEED],
|
||||
expectedLength: 16,
|
||||
},
|
||||
) {
|
||||
): Decoded {
|
||||
return codecWithXrpAlphabet.decode(seed, opts)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# ripple-binary-codec Release History
|
||||
|
||||
## 1.2.2 (2021-12-2)
|
||||
- Fix issue where unsupported currency codes weren't being correctly processed
|
||||
|
||||
## 1.2.1 (2021-12-1)
|
||||
- Fix issue where npm < 7 could not install the library
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-binary-codec",
|
||||
"version": "1.2.1-beta.0",
|
||||
"version": "1.2.2",
|
||||
"description": "XRP Ledger binary codec",
|
||||
"files": [
|
||||
"dist/*",
|
||||
@@ -17,7 +17,7 @@
|
||||
"buffer": "5.6.0",
|
||||
"create-hash": "^1.2.0",
|
||||
"decimal.js": "^10.2.0",
|
||||
"ripple-address-codec": "^4.2.1-beta.0"
|
||||
"ripple-address-codec": "^4.2.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "run-script-os",
|
||||
|
||||
@@ -89,7 +89,7 @@ class Currency extends Hash160 {
|
||||
|
||||
if (this.bytes[0] !== 0) {
|
||||
this._iso = null
|
||||
} else if (code.toString('hex') === '000000') {
|
||||
} else if (/^0*$/.test(this.bytes.toString('hex'))) {
|
||||
this._iso = 'XRP'
|
||||
} else {
|
||||
this._iso = isoCodeFromHex(code)
|
||||
|
||||
@@ -69,6 +69,7 @@ describe('Currency', function () {
|
||||
expect(Currency.from('X8P').toJSON()).toBe('X8P')
|
||||
expect(Currency.from('USD').toJSON()).toBe('USD')
|
||||
})
|
||||
|
||||
test('can be constructed from a Buffer', function () {
|
||||
const xrp = new Currency(Buffer.alloc(20))
|
||||
expect(xrp.iso()).toBe('XRP')
|
||||
@@ -77,6 +78,12 @@ describe('Currency', function () {
|
||||
const currency = '015841551A748AD2C1F76FF6ECB0CCCD00000000'
|
||||
expect(Currency.from(currency).toJSON()).toBe(currency)
|
||||
})
|
||||
|
||||
test('Can handle other non-standard currency codes', () => {
|
||||
const currency = '0000000000414C6F676F30330000000000000000'
|
||||
expect(Currency.from(currency).toJSON()).toBe(currency)
|
||||
})
|
||||
|
||||
test('throws on invalid reprs', function () {
|
||||
expect(() => Currency.from(Buffer.alloc(19))).toThrow()
|
||||
expect(() => Currency.from(1)).toThrow()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-keypairs",
|
||||
"version": "1.1.1-beta.0",
|
||||
"version": "1.1.2",
|
||||
"description": "Cryptographic key pairs for the XRP Ledger",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
@@ -21,7 +21,7 @@
|
||||
"brorand": "^1.0.5",
|
||||
"elliptic": "^6.5.4",
|
||||
"hash.js": "^1.0.3",
|
||||
"ripple-address-codec": "^4.2.1-beta.0"
|
||||
"ripple-address-codec": "^4.2.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xrpl",
|
||||
"version": "2.0.3-beta.0",
|
||||
"version": "2.0.4",
|
||||
"license": "ISC",
|
||||
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
|
||||
"files": [
|
||||
@@ -24,9 +24,9 @@
|
||||
"bip39": "^3.0.4",
|
||||
"https-proxy-agent": "^5.0.0",
|
||||
"lodash": "^4.17.4",
|
||||
"ripple-address-codec": "^4.2.1-beta.0",
|
||||
"ripple-binary-codec": "^1.2.1-beta.0",
|
||||
"ripple-keypairs": "^1.1.1-beta.0",
|
||||
"ripple-address-codec": "^4.2.2",
|
||||
"ripple-binary-codec": "^1.2.2",
|
||||
"ripple-keypairs": "^1.1.2",
|
||||
"ws": "^8.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user