Merge branch 'main' into iouescrow

This commit is contained in:
Denis Angell
2023-02-06 10:56:50 -05:00
committed by GitHub
465 changed files with 21238 additions and 22260 deletions

View File

@@ -14,6 +14,8 @@ module.exports = {
},
},
ignorePatterns: ['jest.config.js', '.eslintrc.js'],
// Specify global variables that are predefined
env: {
browser: true, // Enable browser global variables
@@ -103,19 +105,19 @@ module.exports = {
'max-lines-per-function': 'off',
'require-unicode-regexp': 'off',
'no-undef-init': 'off',
'curly': 'off',
'eqeqeq': 'off',
curly: 'off',
eqeqeq: 'off',
'no-console': 'off',
'max-classes-per-file': 'off',
'operator-assignment': 'off',
'class-methods-use-this': 'off',
'no-else-return': 'off',
'yoda': 'off',
yoda: 'off',
'max-depth': 'off',
'multiline-comment-style': 'off',
'one-var': 'off',
'no-negated-condition': 'off',
'radix': 'off',
radix: 'off',
'no-nested-ternary': 'off',
'no-useless-concat': 'off',
'object-shorthand': 'off',

View File

@@ -1 +0,0 @@
10.22.0

View File

@@ -1,6 +1,8 @@
# ripple-binary-codec Release History
## Unreleased
### Changed
- All tests now use the Jest test runner and have been refactored for consistency across all packages
## 1.4.2 (2022-06-27)
- Fixed standard currency codes with lowercase and allowed symbols not decoding into standard codes.

View File

@@ -0,0 +1,8 @@
// Jest configuration for api
const base = require('../../jest.config.base.js')
module.exports = {
...base,
roots: [...base.roots, '<rootDir>/test'],
displayName: 'ripple-binary-codec',
}

View File

@@ -23,7 +23,7 @@
"build": "tsc -b && copyfiles ./src/enums/definitions.json ./dist/enums/",
"clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
"prepare": "npm run build && npm test",
"test": "jest",
"test": "jest --verbose false --silent=false ./test/*.test.js",
"lint": "eslint . --ext .ts --ext .test.js"
},
"repository": {
@@ -38,6 +38,6 @@
"readmeFilename": "README.md",
"prettier": "@xrplf/prettier-config",
"engines": {
"node": ">=10.22.0"
"node": ">= 10"
}
}

View File

@@ -10,7 +10,7 @@ import { FieldInstance } from './enums'
import { STObject } from './types/st-object'
import { JsonObject } from './types/serialized-type'
import { Buffer } from 'buffer/'
import * as bigInt from 'big-integer'
import bigInt = require('big-integer')
import { Amount } from './types/amount'
/**

View File

@@ -1,5 +1,5 @@
import { HashPrefix } from './hash-prefixes'
import * as createHash from 'create-hash'
import createHash = require('create-hash')
import { Hash256 } from './types/hash-256'
import { BytesList } from './serdes/binary-serializer'
import { Buffer } from 'buffer/'

View File

@@ -102,7 +102,7 @@ function decodeQuality(value: string): string {
return quality.decode(value).toString()
}
export = {
export {
decode,
encode,
encodeForSigning,

View File

@@ -10,7 +10,7 @@ import { UInt32 } from './types/uint-32'
import { UInt8 } from './types/uint-8'
import { BinaryParser } from './serdes/binary-parser'
import { JsonObject } from './types/serialized-type'
import * as bigInt from 'big-integer'
import bigInt = require('big-integer')
/**
* Computes the hash of a list of objects

View File

@@ -1,6 +1,6 @@
import { coreTypes } from './types'
import { Decimal } from 'decimal.js'
import * as bigInt from 'big-integer'
import bigInt = require('big-integer')
import { Buffer } from 'buffer/'
/**

View File

@@ -5,7 +5,7 @@ import { BinaryParser } from '../serdes/binary-parser'
import { AccountID } from './account-id'
import { Currency } from './currency'
import { JsonObject, SerializedType } from './serialized-type'
import * as bigInt from 'big-integer'
import bigInt = require('big-integer')
import { Buffer } from 'buffer/'
/**

View File

@@ -9,8 +9,25 @@ class Hash128 extends Hash {
static readonly ZERO_128: Hash128 = new Hash128(Buffer.alloc(Hash128.width))
constructor(bytes: Buffer) {
if (bytes && bytes.byteLength === 0) {
bytes = Hash128.ZERO_128.bytes
}
super(bytes ?? Hash128.ZERO_128.bytes)
}
/**
* Get the hex representation of a hash-128 bytes, allowing unset
*
* @returns hex String of this.bytes
*/
toHex(): string {
const hex = this.toBytes().toString('hex').toUpperCase()
if (/^0+$/.exec(hex)) {
return ''
}
return hex
}
}
export { Hash128 }

View File

@@ -1,6 +1,6 @@
import { BytesList } from '../serdes/binary-serializer'
import { BinaryParser } from '../serdes/binary-parser'
import * as bigInt from 'big-integer'
import bigInt = require('big-integer')
import { Buffer } from 'buffer/'
type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject

View File

@@ -1,6 +1,6 @@
import { UInt } from './uint'
import { BinaryParser } from '../serdes/binary-parser'
import * as bigInt from 'big-integer'
import bigInt = require('big-integer')
import { isInstance } from 'big-integer'
import { Buffer } from 'buffer/'

View File

@@ -1,4 +1,4 @@
import * as bigInt from 'big-integer'
import bigInt = require('big-integer')
import { Comparable } from './serialized-type'
import { Buffer } from 'buffer/'

View File

@@ -1,5 +1,5 @@
const { loadFixture } = require('./utils')
const { coreTypes } = require('../dist/types')
const { coreTypes } = require('../src/types')
const { Amount } = coreTypes
const fixtures = loadFixture('data-driven-tests.json')

View File

@@ -1,5 +1,5 @@
const fixtures = require('./fixtures/codec-fixtures.json')
const { decode, encode, decodeLedgerData } = require('../dist')
const { decode, encode, decodeLedgerData } = require('../src')
function json(object) {
return JSON.stringify(object)

View File

@@ -1,14 +1,14 @@
const { coreTypes } = require('../dist/types')
const { coreTypes } = require('../src/types')
const Decimal = require('decimal.js')
const { encodeAccountID } = require('ripple-address-codec')
const { binary } = require('../dist/coretypes')
const { binary } = require('../src/coretypes')
const { Amount, Hash160 } = coreTypes
const { makeParser, readJSON } = binary
const { Field, TransactionType } = require('./../dist/enums')
const { Field, TransactionType } = require('./../src/enums')
const { parseHexOnly, hexOnly, loadFixture } = require('./utils')
const fixtures = loadFixture('data-driven-tests.json')
const { BytesList } = require('../dist/serdes/binary-serializer')
const { BytesList } = require('../src/serdes/binary-serializer')
const { Buffer } = require('buffer/')
const __ = hexOnly

View File

@@ -1,7 +1,7 @@
const { binary } = require('../dist/coretypes')
const { encode, decode } = require('../dist')
const { binary } = require('../src/coretypes')
const { encode, decode } = require('../src')
const { makeParser, BytesList, BinarySerializer } = binary
const { coreTypes } = require('../dist/types')
const { coreTypes } = require('../src/types')
const { UInt8, UInt16, UInt32, UInt64, STObject } = coreTypes
const bigInt = require('big-integer')
const { Buffer } = require('buffer/')

View File

@@ -1,7 +1,33 @@
const { coreTypes } = require('../dist/types')
const { Hash160, Hash256, AccountID, Currency } = coreTypes
const { coreTypes } = require('../src/types')
const { Hash128, Hash160, Hash256, AccountID, Currency } = coreTypes
const { Buffer } = require('buffer/')
describe('Hash128', function () {
test('has a static width member', function () {
expect(Hash128.width).toBe(16)
})
test('can be unset', function () {
const h1 = Hash128.from('')
expect(h1.toJSON()).toBe('')
})
test('can be compared against another', function () {
const h1 = Hash128.from('100000000000000000000000000000000')
const h2 = Hash128.from('200000000000000000000000000000000')
const h3 = Hash128.from('000000000000000000000000000000003')
expect(h1.lt(h2)).toBe(true)
expect(h3.lt(h2)).toBe(true)
expect(h2.gt(h1)).toBe(true)
expect(h1.gt(h3)).toBe(true)
})
test('throws when constructed from invalid hash length', () => {
expect(() => Hash128.from('1000000000000000000000000000000')).toThrow(
'Invalid Hash length 15',
)
expect(() => Hash128.from('10000000000000000000000000000000000')).toThrow(
'Invalid Hash length 17',
)
})
})
describe('Hash160', function () {
test('has a static width member', function () {
expect(Hash160.width).toBe(20)

View File

@@ -3,7 +3,7 @@ const {
transactionTreeHash,
ledgerHash,
accountStateHash,
} = require('../dist/ledger-hashes')
} = require('../src/ledger-hashes')
describe('Ledger Hashes', function () {
function testFactory(ledgerFixture) {

View File

@@ -1,4 +1,4 @@
const { encode, decode } = require('../dist')
const { encode, decode } = require('../src')
let str =
'1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC'

View File

@@ -1,4 +1,4 @@
const { encode, decode } = require('../dist')
const { encode, decode } = require('../src')
let json = {
Account: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',

View File

@@ -1,4 +1,4 @@
const { quality } = require('../dist/coretypes')
const { quality } = require('../src/coretypes')
describe('Quality encode/decode', function () {
const bookDirectory =

View File

@@ -1,6 +1,6 @@
const { ShaMap } = require('../dist/shamap.js')
const { binary, HashPrefix } = require('../dist/coretypes')
const { coreTypes } = require('../dist/types')
const { ShaMap } = require('../src/shamap')
const { binary, HashPrefix } = require('../src/coretypes')
const { coreTypes } = require('../src/types')
const { loadFixture } = require('./utils')
const { Buffer } = require('buffer/')

View File

@@ -3,7 +3,7 @@ const {
encodeForSigning,
encodeForSigningClaim,
encodeForMultisigning,
} = require('../dist')
} = require('../src')
const tx_json = {
Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',

View File

@@ -1,4 +1,4 @@
const { encode, decode } = require('../dist')
const { encode, decode } = require('../src')
// Notice: no Amount or Fee
const tx_json = {

View File

@@ -1,5 +1,5 @@
const { coreTypes } = require('../dist/types')
const { SerializedType } = require('../dist/types/serialized-type')
const { coreTypes } = require('../src/types')
const { SerializedType } = require('../src/types/serialized-type')
describe('SerializedType interfaces', () => {
Object.entries(coreTypes).forEach(([name, Value]) => {

View File

@@ -1,7 +1,7 @@
const { coreTypes } = require('../dist/types')
const { coreTypes } = require('../src/types')
const { UInt8, UInt64 } = coreTypes
const { encode } = require('../dist')
const { encode } = require('../src')
const binary =
'11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F'

View File

@@ -1,4 +1,4 @@
const { encode, decode } = require('./../dist/index')
const { encode, decode } = require('./../src/index')
const fixtures = require('./fixtures/x-codec-fixtures.json')
let json_x1 = {

View File

@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es5",
"target": "es6",
"lib": [
"es2017"
],