From e3ce19c54a6ba52654a2cc159cfaa98f478aa417 Mon Sep 17 00:00:00 2001 From: Caleb Kniffen Date: Mon, 17 Jul 2023 20:11:54 -0500 Subject: [PATCH 1/5] feat(deps): remove `assert-browserify` Use `if` statements and manually error throwing to save 21kb gzipped. --- package.json | 1 + packages/ripple-address-codec/src/index.ts | 13 ++++---- packages/ripple-binary-codec/package.json | 4 ++- packages/ripple-binary-codec/src/index.ts | 33 ++++++++++++++----- .../ripple-binary-codec/src/ledger-hashes.ts | 17 +++++++--- .../src/serdes/binary-parser.ts | 17 +++++++--- .../src/serdes/binary-serializer.ts | 6 ++-- packages/ripple-binary-codec/src/shamap.ts | 5 +-- packages/ripple-keypairs/src/index.ts | 12 +++---- packages/ripple-keypairs/src/utils.ts | 5 +-- packages/xrpl/package.json | 3 +- packages/xrpl/src/client/index.ts | 5 +-- packages/xrpl/test/webpack.config.js | 2 -- packages/xrpl/webpack.config.js | 1 - 14 files changed, 77 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 4ee14e6034..da5c6bef9f 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "xrpl.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", diff --git a/packages/ripple-address-codec/src/index.ts b/packages/ripple-address-codec/src/index.ts index 51053e8866..445214b92e 100644 --- a/packages/ripple-address-codec/src/index.ts +++ b/packages/ripple-address-codec/src/index.ts @@ -1,5 +1,3 @@ -import * as assert from 'assert' - import { codec, encodeSeed, @@ -133,11 +131,12 @@ function tagFromBuffer(buf: Buffer): number | false { // Little-endian to big-endian return buf[23] + buf[24] * 0x100 + buf[25] * 0x10000 + buf[26] * 0x1000000 } - assert.strictEqual(flag, 0, 'flag must be zero to indicate no tag') - assert.ok( - Buffer.from('0000000000000000', 'hex').equals(buf.slice(23, 23 + 8)), - 'remaining bytes must be zero', - ) + if (flag !== 0) { + throw new Error('flag must be zero to indicate no tag') + } + if (!Buffer.from('0000000000000000', 'hex').equals(buf.slice(23, 23 + 8))) { + throw new Error('remaining bytes must be zero') + } return false } diff --git a/packages/ripple-binary-codec/package.json b/packages/ripple-binary-codec/package.json index c4692c8120..54e68348dc 100644 --- a/packages/ripple-binary-codec/package.json +++ b/packages/ripple-binary-codec/package.json @@ -12,13 +12,15 @@ "test": "test" }, "dependencies": { - "assert": "^2.0.0", "big-integer": "^1.6.48", "buffer": "6.0.3", "create-hash": "^1.2.0", "decimal.js": "^10.2.0", "ripple-address-codec": "^4.3.0" }, + "devDependencies": { + "assert": "^2.0.0" + }, "scripts": { "build": "tsc -b && copyfiles ./src/enums/definitions.json ./dist/enums/", "clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo", diff --git a/packages/ripple-binary-codec/src/index.ts b/packages/ripple-binary-codec/src/index.ts index 6d7852d240..9b767e543c 100644 --- a/packages/ripple-binary-codec/src/index.ts +++ b/packages/ripple-binary-codec/src/index.ts @@ -1,4 +1,3 @@ -import * as assert from 'assert' import { quality, binary, HashPrefix } from './coretypes' import { decodeLedgerData } from './ledger-hashes' import { ClaimObject } from './binary' @@ -27,7 +26,9 @@ const { * @returns the JSON representation of the transaction */ function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject { - assert.ok(typeof binary === 'string', 'binary must be a hex string') + if (typeof binary !== 'string') { + throw new Error('binary must be a hex string') + } return binaryToJSON(binary, definitions) } @@ -40,7 +41,9 @@ function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject { * @returns A hex-string of the encoded transaction */ function encode(json: object, definitions?: XrplDefinitionsBase): string { - assert.ok(typeof json === 'object') + if (typeof json !== 'object') { + throw new Error() + } return serializeObject(json as JsonObject, { definitions }) .toString('hex') .toUpperCase() @@ -58,7 +61,9 @@ function encodeForSigning( json: object, definitions?: XrplDefinitionsBase, ): string { - assert.ok(typeof json === 'object') + if (typeof json !== 'object') { + throw new Error() + } return signingData(json as JsonObject, HashPrefix.transactionSig, { definitions, }) @@ -75,7 +80,9 @@ function encodeForSigning( * @returns a hex string of the encoded transaction */ function encodeForSigningClaim(json: object): string { - assert.ok(typeof json === 'object') + if (typeof json !== 'object') { + throw new Error() + } return signingClaimData(json as ClaimObject) .toString('hex') .toUpperCase() @@ -94,8 +101,12 @@ function encodeForMultisigning( signer: string, definitions?: XrplDefinitionsBase, ): string { - assert.ok(typeof json === 'object') - assert.equal(json['SigningPubKey'], '') + if (typeof json !== 'object') { + throw new Error() + } + if (json['SigningPubKey'] === '') { + throw new Error() + } const definitionsOpt = definitions ? { definitions } : undefined return multiSigningData(json as JsonObject, signer, definitionsOpt) .toString('hex') @@ -109,7 +120,9 @@ function encodeForMultisigning( * @returns a hex-string representing the quality */ function encodeQuality(value: string): string { - assert.ok(typeof value === 'string') + if (typeof value !== 'string') { + throw new Error() + } return quality.encode(value).toString('hex').toUpperCase() } @@ -120,7 +133,9 @@ function encodeQuality(value: string): string { * @returns a string representing the quality */ function decodeQuality(value: string): string { - assert.ok(typeof value === 'string') + if (typeof value !== 'string') { + throw new Error() + } return quality.decode(value).toString() } diff --git a/packages/ripple-binary-codec/src/ledger-hashes.ts b/packages/ripple-binary-codec/src/ledger-hashes.ts index 92f5b03f84..4b5d7f8c7a 100644 --- a/packages/ripple-binary-codec/src/ledger-hashes.ts +++ b/packages/ripple-binary-codec/src/ledger-hashes.ts @@ -1,4 +1,3 @@ -import * as assert from 'assert' import { ShaMap, ShaMapNode, ShaMapLeaf } from './shamap' import { HashPrefix } from './hash-prefixes' import { Sha512Half } from './hashes' @@ -46,7 +45,9 @@ interface transactionItemObject extends JsonObject { function transactionItemizer( json: transactionItemObject, ): [Hash256, ShaMapNode, undefined] { - assert.ok(json.hash) + if (!json.hash) { + throw new Error() + } const index = Hash256.from(json.hash) const item = { hashPrefix() { @@ -140,8 +141,12 @@ interface ledgerObject { function ledgerHash(header: ledgerObject): Hash256 { const hash = new Sha512Half() hash.put(HashPrefix.ledgerHeader) - assert.ok(header.parent_close_time !== undefined) - assert.ok(header.close_flags !== undefined) + if ( + header.parent_close_time !== undefined || + header.close_flags !== undefined + ) { + throw new Error() + } UInt32.from(header.ledger_index).toBytesSink(hash) UInt64.from( @@ -169,7 +174,9 @@ function decodeLedgerData( binary: string, definitions?: XrplDefinitionsBase, ): object { - assert.ok(typeof binary === 'string', 'binary must be a hex string') + if (typeof binary !== 'string') { + throw new Error('binary must be a hex string') + } const parser = new BinaryParser(binary, definitions) return { ledger_index: parser.readUInt32(), diff --git a/packages/ripple-binary-codec/src/serdes/binary-parser.ts b/packages/ripple-binary-codec/src/serdes/binary-parser.ts index bd6545805e..69fd14c09e 100644 --- a/packages/ripple-binary-codec/src/serdes/binary-parser.ts +++ b/packages/ripple-binary-codec/src/serdes/binary-parser.ts @@ -1,4 +1,3 @@ -import * as assert from 'assert' import { XrplDefinitionsBase, DEFAULT_DEFINITIONS, @@ -35,7 +34,9 @@ class BinaryParser { * @returns The first byte of the BinaryParser */ peek(): number { - assert.ok(this.bytes.byteLength !== 0) + if (this.bytes.byteLength === 0) { + throw new Error() + } return this.bytes[0] } @@ -45,7 +46,9 @@ class BinaryParser { * @param n the number of bytes to skip */ skip(n: number): void { - assert.ok(n <= this.bytes.byteLength) + if (n > this.bytes.byteLength) { + throw new Error() + } this.bytes = this.bytes.slice(n) } @@ -56,7 +59,9 @@ class BinaryParser { * @return The bytes */ read(n: number): Buffer { - assert.ok(n <= this.bytes.byteLength) + if (n > this.bytes.byteLength) { + throw new Error() + } const slice = this.bytes.slice(0, n) this.skip(n) @@ -70,7 +75,9 @@ class BinaryParser { * @return The number represented by those bytes */ readUIntN(n: number): number { - assert.ok(0 < n && n <= 4, 'invalid n') + if (0 >= n && n > 4) { + throw new Error('invalid n') + } return this.read(n).reduce((a, b) => (a << 8) | b) >>> 0 } diff --git a/packages/ripple-binary-codec/src/serdes/binary-serializer.ts b/packages/ripple-binary-codec/src/serdes/binary-serializer.ts index bf060211d1..5ecab893c5 100644 --- a/packages/ripple-binary-codec/src/serdes/binary-serializer.ts +++ b/packages/ripple-binary-codec/src/serdes/binary-serializer.ts @@ -1,4 +1,3 @@ -import * as assert from 'assert' import { FieldInstance } from '../enums' import { type SerializedType } from '../types/serialized-type' import { Buffer } from 'buffer/' @@ -132,8 +131,9 @@ class BinarySerializer { isUnlModifyWorkaround = false, ): void { const associatedValue = field.associatedType.from(value) - assert.ok(associatedValue.toBytesSink !== undefined) - assert.ok(field.name !== undefined) + if (associatedValue.toBytesSink === undefined || field.name === undefined) { + throw new Error() + } this.sink.put(field.header) diff --git a/packages/ripple-binary-codec/src/shamap.ts b/packages/ripple-binary-codec/src/shamap.ts index a2b26bf1e7..f7573ff585 100644 --- a/packages/ripple-binary-codec/src/shamap.ts +++ b/packages/ripple-binary-codec/src/shamap.ts @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert' import { coreTypes } from './types' import { HashPrefix } from './hash-prefixes' import { Sha512Half } from './hashes' @@ -160,7 +159,9 @@ class ShaMapInner extends ShaMapNode { * @param leaf Leaf node to insert when branch doesn't exist */ addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void { - assert.ok(index !== undefined) + if (index === undefined) { + throw new Error() + } if (index !== undefined) { const nibble = index.nibblet(this.depth) const existing = this.branches[nibble] diff --git a/packages/ripple-keypairs/src/index.ts b/packages/ripple-keypairs/src/index.ts index 631e79134d..6f8a0838db 100644 --- a/packages/ripple-keypairs/src/index.ts +++ b/packages/ripple-keypairs/src/index.ts @@ -1,4 +1,3 @@ -import * as assert from 'assert' import brorand = require('brorand') import * as hashjs from 'hash.js' import * as elliptic from 'elliptic' @@ -19,10 +18,9 @@ function generateSeed( algorithm?: 'ed25519' | 'ecdsa-secp256k1' } = {}, ): string { - assert.ok( - !options.entropy || options.entropy.length >= 16, - 'entropy too short', - ) + if (!options.entropy || options.entropy.length >= 16) { + throw new Error('entropy too short') + } const entropy = options.entropy ? options.entropy.slice(0, 16) : brorand(16) const type = options.algorithm === 'ed25519' ? 'ed25519' : 'secp256k1' return addressCodec.encodeSeed(Buffer.from(entropy), type) @@ -82,7 +80,9 @@ const ed25519 = { sign(message, privateKey): string { // caution: Ed25519.sign interprets all strings as hex, stripping // any non-hex characters without warning - assert.ok(Array.isArray(message), 'message must be array of octets') + if (!Array.isArray(message)) { + throw new Error('message must be array of octets') + } return bytesToHex( Ed25519.sign(message, hexToBytes(privateKey).slice(1)).toBytes(), ) diff --git a/packages/ripple-keypairs/src/utils.ts b/packages/ripple-keypairs/src/utils.ts index 564c4f65ef..5e066f13e9 100644 --- a/packages/ripple-keypairs/src/utils.ts +++ b/packages/ripple-keypairs/src/utils.ts @@ -1,4 +1,3 @@ -import * as assert from 'assert' import * as hashjs from 'hash.js' import BN = require('bn.js') @@ -10,7 +9,9 @@ function bytesToHex(a: Iterable | ArrayLike): string { } function hexToBytes(a): number[] { - assert.ok(a.length % 2 === 0) + if (a.length % 2 !== 0) { + throw new Error() + } // Special-case length zero to return []. // BN.toArray intentionally returns [0] rather than [] for length zero, // which may make sense for BigNum data, but not for byte strings. diff --git a/packages/xrpl/package.json b/packages/xrpl/package.json index b6b28d82d5..010a5a1f71 100644 --- a/packages/xrpl/package.json +++ b/packages/xrpl/package.json @@ -35,7 +35,6 @@ "devDependencies": { "@geut/browser-node-core": "^2.0.13", "@types/node": "^14.18.36", - "assert-browserify": "^2.0.0", "browserify-fs": "^1.0.0", "constants-browserify": "^1.0.0", "https-browserify": "^1.0.0", @@ -56,7 +55,7 @@ "build:lib": "tsc --build tsconfig.build.json", "build:web": "webpack", "build:browserTests": "webpack --config ./test/webpack.config.js", - "analyze": "run-s build:web --analyze", + "analyze": "webpack --analyze", "watch": "run-s build:lib --watch", "clean": "rm -rf dist build coverage", "docgen": "tsc --build tsconfig.docs.json && typedoc && echo js.xrpl.org >> ../../docs/CNAME", diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 27b2402ef0..6652a7e785 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -1,7 +1,6 @@ /* eslint-disable jsdoc/require-jsdoc -- Request has many aliases, but they don't need unique docs */ /* eslint-disable @typescript-eslint/member-ordering -- TODO: remove when instance methods aren't members */ /* eslint-disable max-lines -- Client is a large file w/ lots of imports/exports */ -import * as assert from 'assert' import { EventEmitter } from 'events' import { NotFoundError, ValidationError, XrplError } from '../errors' @@ -155,7 +154,9 @@ function getCollectKeyFromCommand(command: string): string | null { } function clamp(value: number, min: number, max: number): number { - assert.ok(min <= max, 'Illegal clamp bounds') + if (min > max) { + throw new Error('Illegal clamp bounds') + } return Math.min(Math.max(value, min), max) } diff --git a/packages/xrpl/test/webpack.config.js b/packages/xrpl/test/webpack.config.js index ae461ae159..d8a23f8fd2 100644 --- a/packages/xrpl/test/webpack.config.js +++ b/packages/xrpl/test/webpack.config.js @@ -100,11 +100,9 @@ function webpackForTest(testFileName) { extensions: ['.ts', '.js', '.json'], fallback: { module: false, - assert: require.resolve('assert-browserify'), constants: require.resolve('constants-browserify'), fs: require.resolve('browserify-fs'), buffer: require.resolve('buffer/'), - assert: require.resolve('assert/'), url: require.resolve('url/'), stream: require.resolve('stream-browserify'), crypto: require.resolve('crypto-browserify'), diff --git a/packages/xrpl/webpack.config.js b/packages/xrpl/webpack.config.js index aed3785a8e..d33927f930 100644 --- a/packages/xrpl/webpack.config.js +++ b/packages/xrpl/webpack.config.js @@ -65,7 +65,6 @@ function getDefaultConfiguration() { symlinks: false, fallback: { buffer: require.resolve('buffer/'), - assert: require.resolve('assert/'), url: require.resolve('url/'), stream: require.resolve('stream-browserify'), crypto: require.resolve('crypto-browserify'), From 4491aa9b1fabefd05184f8aad704fff789d72dee Mon Sep 17 00:00:00 2001 From: Caleb Kniffen Date: Mon, 17 Jul 2023 20:26:53 -0500 Subject: [PATCH 2/5] Fix some assertions I didn't inverse. --- packages/ripple-binary-codec/src/index.ts | 2 +- packages/ripple-binary-codec/src/ledger-hashes.ts | 4 ++-- packages/ripple-keypairs/src/index.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ripple-binary-codec/src/index.ts b/packages/ripple-binary-codec/src/index.ts index 9b767e543c..c7d4624e3b 100644 --- a/packages/ripple-binary-codec/src/index.ts +++ b/packages/ripple-binary-codec/src/index.ts @@ -104,7 +104,7 @@ function encodeForMultisigning( if (typeof json !== 'object') { throw new Error() } - if (json['SigningPubKey'] === '') { + if (json['SigningPubKey'] !== '') { throw new Error() } const definitionsOpt = definitions ? { definitions } : undefined diff --git a/packages/ripple-binary-codec/src/ledger-hashes.ts b/packages/ripple-binary-codec/src/ledger-hashes.ts index 4b5d7f8c7a..29ae6f73ff 100644 --- a/packages/ripple-binary-codec/src/ledger-hashes.ts +++ b/packages/ripple-binary-codec/src/ledger-hashes.ts @@ -142,8 +142,8 @@ function ledgerHash(header: ledgerObject): Hash256 { const hash = new Sha512Half() hash.put(HashPrefix.ledgerHeader) if ( - header.parent_close_time !== undefined || - header.close_flags !== undefined + header.parent_close_time === undefined || + header.close_flags === undefined ) { throw new Error() } diff --git a/packages/ripple-keypairs/src/index.ts b/packages/ripple-keypairs/src/index.ts index 6f8a0838db..93da6565b6 100644 --- a/packages/ripple-keypairs/src/index.ts +++ b/packages/ripple-keypairs/src/index.ts @@ -18,7 +18,7 @@ function generateSeed( algorithm?: 'ed25519' | 'ecdsa-secp256k1' } = {}, ): string { - if (!options.entropy || options.entropy.length >= 16) { + if (!(!options.entropy || options.entropy.length >= 16)) { throw new Error('entropy too short') } const entropy = options.entropy ? options.entropy.slice(0, 16) : brorand(16) From cf8b48b16fca87bc9850257e1bc55b936965013b Mon Sep 17 00:00:00 2001 From: Caleb Kniffen Date: Tue, 18 Jul 2023 13:38:53 -0500 Subject: [PATCH 3/5] feat: bump typescript to 5.x (#2387) --- package-lock.json | 34 ++++++++++----------- package.json | 2 +- packages/ripple-address-codec/src/index.ts | 2 +- packages/ripple-address-codec/tsconfig.json | 1 - packages/ripple-binary-codec/tsconfig.json | 1 - packages/xrpl/package.json | 2 +- packages/xrpl/test/createMockRippled.ts | 2 +- packages/xrpl/tsconfig.json | 1 - 8 files changed, 21 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index bec534d6c7..ce695c4366 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,7 +59,7 @@ "ts-jest": "^29.0.3", "ts-loader": "^9.2.5", "ts-node": "^10.2.1", - "typescript": "^4.4.2", + "typescript": "^5.1.6", "url": "^0.11.0", "webpack": "^5.81.0", "webpack-bundle-analyzer": "^4.1.0", @@ -15789,9 +15789,9 @@ } }, "node_modules/typedoc": { - "version": "0.24.7", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.24.7.tgz", - "integrity": "sha512-zzfKDFIZADA+XRIp2rMzLe9xZ6pt12yQOhCr7cD7/PBTjhPmMyMvGrkZ2lPNJitg3Hj1SeiYFNzCsSDrlpxpKw==", + "version": "0.24.8", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.24.8.tgz", + "integrity": "sha512-ahJ6Cpcvxwaxfu4KtjA8qZNqS43wYt6JL27wYiIgl1vd38WW/KWX11YuAeZhuz9v+ttrutSsgK+XO1CjL1kA3w==", "dev": true, "dependencies": { "lunr": "^2.3.9", @@ -15806,7 +15806,7 @@ "node": ">= 14.14" }, "peerDependencies": { - "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x" + "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x" } }, "node_modules/typedoc/node_modules/brace-expansion": { @@ -15839,16 +15839,16 @@ "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==" }, "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/ua-parser-js": { @@ -16857,7 +16857,7 @@ "karma-webpack": "^5.0.0", "node-polyfill-webpack-plugin": "^2.0.1", "react": "^18.2.0", - "typedoc": "^0.24.6" + "typedoc": "^0.24.8" }, "engines": { "node": ">=10.13.0" @@ -29273,9 +29273,9 @@ } }, "typedoc": { - "version": "0.24.7", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.24.7.tgz", - "integrity": "sha512-zzfKDFIZADA+XRIp2rMzLe9xZ6pt12yQOhCr7cD7/PBTjhPmMyMvGrkZ2lPNJitg3Hj1SeiYFNzCsSDrlpxpKw==", + "version": "0.24.8", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.24.8.tgz", + "integrity": "sha512-ahJ6Cpcvxwaxfu4KtjA8qZNqS43wYt6JL27wYiIgl1vd38WW/KWX11YuAeZhuz9v+ttrutSsgK+XO1CjL1kA3w==", "dev": true, "requires": { "lunr": "^2.3.9", @@ -29310,9 +29310,9 @@ "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==" }, "typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", "dev": true }, "ua-parser-js": { @@ -29975,7 +29975,7 @@ "ripple-address-codec": "^4.3.0", "ripple-binary-codec": "^1.7.0", "ripple-keypairs": "^1.3.0", - "typedoc": "^0.24.6", + "typedoc": "^0.24.8", "ws": "^8.2.2" } }, diff --git a/package.json b/package.json index 4ee14e6034..9a8ca28936 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "ts-jest": "^29.0.3", "ts-loader": "^9.2.5", "ts-node": "^10.2.1", - "typescript": "^4.4.2", + "typescript": "^5.1.6", "url": "^0.11.0", "webpack": "^5.81.0", "webpack-bundle-analyzer": "^4.1.0", diff --git a/packages/ripple-address-codec/src/index.ts b/packages/ripple-address-codec/src/index.ts index 51053e8866..2dced14132 100644 --- a/packages/ripple-address-codec/src/index.ts +++ b/packages/ripple-address-codec/src/index.ts @@ -40,7 +40,7 @@ function encodeXAddress( // RIPEMD160 is 160 bits = 20 bytes throw new Error('Account ID must be 20 bytes') } - if (tag > MAX_32_BIT_UNSIGNED_INT) { + if (tag !== false && tag > MAX_32_BIT_UNSIGNED_INT) { throw new Error('Invalid tag') } const theTag = tag || 0 diff --git a/packages/ripple-address-codec/tsconfig.json b/packages/ripple-address-codec/tsconfig.json index cc5a324ab2..941f61aa67 100644 --- a/packages/ripple-address-codec/tsconfig.json +++ b/packages/ripple-address-codec/tsconfig.json @@ -11,7 +11,6 @@ "noUnusedParameters": true, "removeComments": false, "preserveConstEnums": false, - "suppressImplicitAnyIndexErrors": false, "skipLibCheck": true, "declaration": true, "strictNullChecks": true diff --git a/packages/ripple-binary-codec/tsconfig.json b/packages/ripple-binary-codec/tsconfig.json index 9c8f38ba5b..645c4aeae3 100644 --- a/packages/ripple-binary-codec/tsconfig.json +++ b/packages/ripple-binary-codec/tsconfig.json @@ -14,7 +14,6 @@ "noImplicitAny": false, "removeComments": false, "preserveConstEnums": false, - "suppressImplicitAnyIndexErrors": true, "skipLibCheck": true, "declaration": true }, diff --git a/packages/xrpl/package.json b/packages/xrpl/package.json index b6b28d82d5..d1d6ad9d35 100644 --- a/packages/xrpl/package.json +++ b/packages/xrpl/package.json @@ -45,7 +45,7 @@ "karma-webpack": "^5.0.0", "node-polyfill-webpack-plugin": "^2.0.1", "react": "^18.2.0", - "typedoc": "^0.24.6" + "typedoc": "^0.24.8" }, "resolutions": { "elliptic": "^6.5.4" diff --git a/packages/xrpl/test/createMockRippled.ts b/packages/xrpl/test/createMockRippled.ts index bae75b6b90..48ef5253ed 100644 --- a/packages/xrpl/test/createMockRippled.ts +++ b/packages/xrpl/test/createMockRippled.ts @@ -55,7 +55,7 @@ export type MockedWebSocketServer = WebSocketServer & addResponse: ( command: string, response: - | Response + | BaseResponse | ErrorResponse | ((r: Request) => Response | ErrorResponse | Record) | Record, diff --git a/packages/xrpl/tsconfig.json b/packages/xrpl/tsconfig.json index 9a2f13b956..a906155d36 100644 --- a/packages/xrpl/tsconfig.json +++ b/packages/xrpl/tsconfig.json @@ -12,7 +12,6 @@ "removeComments": true, "preserveConstEnums": false, "esModuleInterop": true, - "suppressImplicitAnyIndexErrors": false, "resolveJsonModule": true, "preserveSymlinks": true }, From ba9d0a6069d16b4a82acbab115b806b30a38f8cb Mon Sep 17 00:00:00 2001 From: Caleb Kniffen Date: Thu, 20 Jul 2023 14:33:42 -0500 Subject: [PATCH 4/5] feat: remove node 14 support (#2386) --- .github/workflows/nodejs.yml | 6 ++-- .nvmrc | 2 +- README.md | 4 +-- package-lock.json | 30 ++++++++++++++----- package.json | 4 +-- .../ripple-address-codec/package-lock.json | 2 +- packages/ripple-address-codec/package.json | 2 +- packages/ripple-binary-codec/package.json | 2 +- packages/ripple-keypairs/package.json | 2 +- packages/xrpl/package.json | 4 +-- 10 files changed, 36 insertions(+), 22 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index a2e57cdb40..1094f4af31 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -57,7 +57,7 @@ jobs: strategy: matrix: - node-version: [14.x, 16.x, 18.x, 20.x] + node-version: [16.x, 18.x, 20.x] steps: - uses: actions/checkout@v3 @@ -98,7 +98,7 @@ jobs: strategy: matrix: - node-version: [14.x, 16.x, 18.x, 20.x] + node-version: [16.x, 18.x, 20.x] steps: - uses: actions/checkout@v3 @@ -202,7 +202,7 @@ jobs: strategy: matrix: - node-version: [14.x, 16.x, 18.x, 20.x] + node-version: [16.x, 18.x, 20.x] steps: - uses: actions/checkout@v3 diff --git a/.nvmrc b/.nvmrc index 958b5a36e1..6f7f377bf5 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v14 +v16 diff --git a/README.md b/README.md index 34f3f0e278..ecf1f544d7 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ See the full reference documentation for all classes, methods, and utilities. 4. Subscribing to changes in the ledger ([Ex. ledger, transactions, & more...](https://xrpl.org/subscribe.html)) 5. Parsing ledger data into more convenient formats ([`xrpToDrops`](https://js.xrpl.org/functions/xrpToDrops.html) and [`rippleTimeToISOTime`](https://js.xrpl.org/functions/rippleTimeToISOTime.html)) -All of which works in Node.js (tested for v14+) & web browsers (tested for Chrome). +All of which works in Node.js (tested for v16+) & web browsers (tested for Chrome). # Quickstart ### Requirements -+ **[Node.js v16](https://nodejs.org/)** is recommended. We also support v14, v18 and v20. Other versions may work but are not frequently tested. ++ **[Node.js v16](https://nodejs.org/)** is recommended. We also support v18 and v20. Other versions may work but are not frequently tested. ### Installing xrpl.js diff --git a/package-lock.json b/package-lock.json index ce695c4366..2a8b7c1dcd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -66,8 +66,8 @@ "webpack-cli": "^5.0.1" }, "engines": { - "node": ">=12.0.0", - "npm": ">=7.0.0 < 10.0.0" + "node": ">=16.0.0", + "npm": ">=8.0.0 < 10.0.0" } }, "node_modules/@ampproject/remapping": { @@ -16798,7 +16798,7 @@ "create-hash": "^1.1.2" }, "engines": { - "node": ">= 10" + "node": ">= 16" } }, "packages/ripple-binary-codec": { @@ -16813,7 +16813,7 @@ "ripple-address-codec": "^4.3.0" }, "engines": { - "node": ">= 10" + "node": ">= 16" } }, "packages/ripple-keypairs": { @@ -16827,7 +16827,7 @@ "ripple-address-codec": "^4.3.0" }, "engines": { - "node": ">= 10" + "node": ">= 16" } }, "packages/xrpl": { @@ -16846,7 +16846,7 @@ }, "devDependencies": { "@geut/browser-node-core": "^2.0.13", - "@types/node": "^14.18.36", + "@types/node": "^16.18.38", "assert-browserify": "^2.0.0", "browserify-fs": "^1.0.0", "constants-browserify": "^1.0.0", @@ -16860,8 +16860,14 @@ "typedoc": "^0.24.8" }, "engines": { - "node": ">=10.13.0" + "node": ">=16.0.0" } + }, + "packages/xrpl/node_modules/@types/node": { + "version": "16.18.38", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.38.tgz", + "integrity": "sha512-6sfo1qTulpVbkxECP+AVrHV9OoJqhzCsfTNp5NIG+enM4HyM3HvZCO798WShIXBN0+QtDIcutJCjsVYnQP5rIQ==", + "dev": true } }, "dependencies": { @@ -29956,7 +29962,7 @@ "version": "file:packages/xrpl", "requires": { "@geut/browser-node-core": "^2.0.13", - "@types/node": "^14.18.36", + "@types/node": "16", "assert-browserify": "^2.0.0", "bignumber.js": "^9.0.0", "bip32": "^2.0.6", @@ -29977,6 +29983,14 @@ "ripple-keypairs": "^1.3.0", "typedoc": "^0.24.8", "ws": "^8.2.2" + }, + "dependencies": { + "@types/node": { + "version": "16.18.38", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.38.tgz", + "integrity": "sha512-6sfo1qTulpVbkxECP+AVrHV9OoJqhzCsfTNp5NIG+enM4HyM3HvZCO798WShIXBN0+QtDIcutJCjsVYnQP5rIQ==", + "dev": true + } } }, "xtend": { diff --git a/package.json b/package.json index 9a8ca28936..1e538fdb43 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "./packages/*" ], "engines": { - "node": ">=12.0.0", - "npm": ">=7.0.0 < 10.0.0" + "node": ">=16.0.0", + "npm": ">=7.10.0 < 10.0.0" } } diff --git a/packages/ripple-address-codec/package-lock.json b/packages/ripple-address-codec/package-lock.json index 6fe7b3dbc3..85187ee305 100644 --- a/packages/ripple-address-codec/package-lock.json +++ b/packages/ripple-address-codec/package-lock.json @@ -13,7 +13,7 @@ "create-hash": "^1.1.2" }, "engines": { - "node": ">= 10" + "node": ">= 16" } }, "node_modules/base-x": { diff --git a/packages/ripple-address-codec/package.json b/packages/ripple-address-codec/package.json index 4167818151..51015f2d4d 100644 --- a/packages/ripple-address-codec/package.json +++ b/packages/ripple-address-codec/package.json @@ -27,6 +27,6 @@ }, "prettier": "@xrplf/prettier-config", "engines": { - "node": ">= 10" + "node": ">= 16" } } diff --git a/packages/ripple-binary-codec/package.json b/packages/ripple-binary-codec/package.json index c4692c8120..54f1f8df39 100644 --- a/packages/ripple-binary-codec/package.json +++ b/packages/ripple-binary-codec/package.json @@ -38,6 +38,6 @@ "readmeFilename": "README.md", "prettier": "@xrplf/prettier-config", "engines": { - "node": ">= 10" + "node": ">= 16" } } diff --git a/packages/ripple-keypairs/package.json b/packages/ripple-keypairs/package.json index 8864cd74d8..843631a547 100644 --- a/packages/ripple-keypairs/package.json +++ b/packages/ripple-keypairs/package.json @@ -30,6 +30,6 @@ "license": "ISC", "prettier": "@xrplf/prettier-config", "engines": { - "node": ">= 10" + "node": ">= 16" } } diff --git a/packages/xrpl/package.json b/packages/xrpl/package.json index d1d6ad9d35..ff7ba2f862 100644 --- a/packages/xrpl/package.json +++ b/packages/xrpl/package.json @@ -34,7 +34,7 @@ }, "devDependencies": { "@geut/browser-node-core": "^2.0.13", - "@types/node": "^14.18.36", + "@types/node": "^16.18.38", "assert-browserify": "^2.0.0", "browserify-fs": "^1.0.0", "constants-browserify": "^1.0.0", @@ -79,6 +79,6 @@ }, "readmeFilename": "README.md", "engines": { - "node": ">=10.13.0" + "node": ">=16.0.0" } } From 9f44fbfee5819d73f03a5dac867fa617e35b3d64 Mon Sep 17 00:00:00 2001 From: Caleb Kniffen Date: Tue, 25 Jul 2023 20:46:41 -0500 Subject: [PATCH 5/5] Update bundler config setups. --- UNIQUE_SETUPS.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/UNIQUE_SETUPS.md b/UNIQUE_SETUPS.md index bc45269cc5..3bed06f4c7 100644 --- a/UNIQUE_SETUPS.md +++ b/UNIQUE_SETUPS.md @@ -19,7 +19,6 @@ To use `xrpl.js` with React, you need to install shims for core NodeJS modules. ```shell npm install --save-dev \ - assert \ buffer \ crypto-browserify \ https-browserify \ @@ -46,7 +45,6 @@ To use `xrpl.js` with React, you need to install shims for core NodeJS modules. module.exports = function override(config) { const fallback = config.resolve.fallback || {}; Object.assign(fallback, { - assert: require.resolve("assert"), crypto: require.resolve("crypto-browserify"), http: require.resolve("stream-http"), https: require.resolve("https-browserify"), @@ -127,7 +125,7 @@ Similar to above, to get xrpl.js to work with Vite you need to set up a couple a 2. Copy these settings into your `vite.config.ts` file. -``` +```javascript import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill"; @@ -141,7 +139,6 @@ export default defineConfig({ }, optimizeDeps: { esbuildOptions: { - define: { global: 'globalThis', }, @@ -174,7 +171,7 @@ resolve: { 3. Install the config dependencies and xrpl (e.g. using this command) -``` +```shell npm install --save-dev @esbuild-plugins/node-globals-polyfill \ rollup-plugin-polyfill-node \ && npm install