@bithomp/xrpl-api 3.1.17 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/lib/client.js +1 -0
  2. package/lib/common/index.js +17 -7
  3. package/lib/index.js +17 -7
  4. package/lib/ledger/account_info.js +17 -7
  5. package/lib/ledger/account_lines.js +17 -7
  6. package/lib/ledger/account_namespace.js +17 -7
  7. package/lib/ledger/account_nfts.js +17 -7
  8. package/lib/ledger/account_objects.js +17 -7
  9. package/lib/ledger/account_offers.js +17 -7
  10. package/lib/ledger/account_tx.js +17 -7
  11. package/lib/ledger/amm_info.js +17 -7
  12. package/lib/ledger/book_offers.js +17 -7
  13. package/lib/ledger/currency.js +17 -7
  14. package/lib/ledger/fee.js +17 -7
  15. package/lib/ledger/gateway_balances.js +17 -7
  16. package/lib/ledger/ledger.js +17 -7
  17. package/lib/ledger/ledger_entry.js +17 -7
  18. package/lib/ledger/manifest.js +17 -7
  19. package/lib/ledger/nft_info.js +17 -7
  20. package/lib/ledger/server_definitions.js +17 -7
  21. package/lib/ledger/server_info.js +17 -7
  22. package/lib/ledger/transaction.js +17 -7
  23. package/lib/ledger/vl-v2.js +17 -7
  24. package/lib/ledger/vl.js +17 -7
  25. package/lib/models/index.d.ts +3 -0
  26. package/lib/models/index.js +6 -1
  27. package/lib/models/manifest.js +17 -7
  28. package/lib/models/mptoken.d.ts +7 -0
  29. package/lib/models/mptoken.js +26 -0
  30. package/lib/models/vl.js +17 -7
  31. package/lib/parse/index.js +17 -7
  32. package/lib/parse/ledger/account-order.js +3 -3
  33. package/lib/parse/ledger/amount.d.ts +2 -2
  34. package/lib/parse/ledger/amount.js +8 -5
  35. package/lib/parse/ledger/mptoken-authorize-flags.d.ts +5 -0
  36. package/lib/parse/ledger/mptoken-authorize-flags.js +8 -0
  37. package/lib/parse/ledger/mptoken-issuance-create-flags.d.ts +5 -0
  38. package/lib/parse/ledger/mptoken-issuance-create-flags.js +8 -0
  39. package/lib/parse/ledger/mptoken-issuance-set-flags.d.ts +5 -0
  40. package/lib/parse/ledger/mptoken-issuance-set-flags.js +8 -0
  41. package/lib/parse/ledger/orderbook-order.js +3 -3
  42. package/lib/parse/outcome/amm_changes.d.ts +2 -1
  43. package/lib/parse/outcome/balance_changes.d.ts +15 -2
  44. package/lib/parse/outcome/balance_changes.js +33 -2
  45. package/lib/parse/outcome/delivered_amount.d.ts +2 -2
  46. package/lib/parse/outcome/did_changes.d.ts +2 -1
  47. package/lib/parse/outcome/escrow_changes.d.ts +1 -1
  48. package/lib/parse/outcome/index.d.ts +2 -0
  49. package/lib/parse/outcome/index.js +5 -1
  50. package/lib/parse/outcome/locked_balance_changes.d.ts +14 -2
  51. package/lib/parse/outcome/locked_balance_changes.js +2 -21
  52. package/lib/parse/outcome/mptoken_changes.d.ts +1 -0
  53. package/lib/parse/outcome/mptoken_changes.js +84 -0
  54. package/lib/parse/outcome/mptoken_issuance_changes.d.ts +1 -0
  55. package/lib/parse/outcome/mptoken_issuance_changes.js +94 -0
  56. package/lib/parse/outcome/oracle_changes.d.ts +2 -1
  57. package/lib/parse/outcome/orderbook_changes.d.ts +14 -2
  58. package/lib/parse/outcome/orderbook_changes.js +2 -2
  59. package/lib/parse/outcome/orderbook_quality.js +17 -7
  60. package/lib/parse/outcome.js +4 -20
  61. package/lib/parse/specification/account-delete.js +17 -7
  62. package/lib/parse/specification/amendment.js +17 -7
  63. package/lib/parse/specification/amm-bid.js +17 -7
  64. package/lib/parse/specification/amm-create.js +17 -7
  65. package/lib/parse/specification/amm-delete.js +17 -7
  66. package/lib/parse/specification/amm-deposit.js +17 -7
  67. package/lib/parse/specification/amm-vote.js +17 -7
  68. package/lib/parse/specification/amm-withdraw.js +17 -7
  69. package/lib/parse/specification/check-cancel.js +17 -7
  70. package/lib/parse/specification/check-cash.js +17 -7
  71. package/lib/parse/specification/check-create.js +17 -7
  72. package/lib/parse/specification/clawback.js +17 -7
  73. package/lib/parse/specification/deposit-preauth.js +17 -7
  74. package/lib/parse/specification/did-delete.js +17 -7
  75. package/lib/parse/specification/did-set.js +17 -7
  76. package/lib/parse/specification/escrow-cancel.js +17 -7
  77. package/lib/parse/specification/escrow-create.js +17 -7
  78. package/lib/parse/specification/escrow-finish.js +17 -7
  79. package/lib/parse/specification/genesis-mint.js +17 -7
  80. package/lib/parse/specification/import.js +17 -7
  81. package/lib/parse/specification/invoke.js +17 -7
  82. package/lib/parse/specification/mptoken-authorize.d.ts +3 -0
  83. package/lib/parse/specification/mptoken-authorize.js +58 -0
  84. package/lib/parse/specification/mptoken-issuance-create.d.ts +3 -0
  85. package/lib/parse/specification/mptoken-issuance-create.js +60 -0
  86. package/lib/parse/specification/mptoken-issuance-destroy.d.ts +3 -0
  87. package/lib/parse/specification/mptoken-issuance-destroy.js +52 -0
  88. package/lib/parse/specification/mptoken-issuance-set.d.ts +3 -0
  89. package/lib/parse/specification/mptoken-issuance-set.js +58 -0
  90. package/lib/parse/specification/nftoken-accept-offer.js +22 -7
  91. package/lib/parse/specification/nftoken-burn.js +22 -7
  92. package/lib/parse/specification/nftoken-cancel-offer.js +22 -7
  93. package/lib/parse/specification/nftoken-create-offer.js +17 -7
  94. package/lib/parse/specification/nftoken-mint.js +34 -7
  95. package/lib/parse/specification/offer-cancel.js +22 -9
  96. package/lib/parse/specification/offer-create.js +22 -9
  97. package/lib/parse/specification/oracle-delete.js +17 -9
  98. package/lib/parse/specification/oracle-set.js +17 -7
  99. package/lib/parse/specification/payment-channel-claim.js +17 -7
  100. package/lib/parse/specification/payment-channel-create.js +17 -7
  101. package/lib/parse/specification/payment-channel-fund.js +17 -7
  102. package/lib/parse/specification/payment.js +17 -7
  103. package/lib/parse/specification/remit.js +17 -7
  104. package/lib/parse/specification/settings.js +17 -7
  105. package/lib/parse/specification/ticket-create.js +17 -7
  106. package/lib/parse/specification/trustline.js +17 -7
  107. package/lib/parse/specification/unl-report.js +17 -7
  108. package/lib/parse/specification/uritoken-burn.js +17 -7
  109. package/lib/parse/specification/uritoken-buy.js +17 -7
  110. package/lib/parse/specification/uritoken-cancel-sell-offer.js +17 -7
  111. package/lib/parse/specification/uritoken-create-sell-offer.js +17 -7
  112. package/lib/parse/specification/uritoken-mint.js +17 -7
  113. package/lib/parse/transaction.d.ts +4 -1
  114. package/lib/parse/transaction.js +24 -8
  115. package/lib/parse/utils.d.ts +2 -2
  116. package/lib/parse/utils.js +4 -1
  117. package/lib/types/account.d.ts +2 -2
  118. package/lib/types/amounts.d.ts +6 -2
  119. package/lib/types/checks.d.ts +2 -2
  120. package/lib/types/mptokens.d.ts +69 -0
  121. package/lib/types/mptokens.js +36 -0
  122. package/lib/types/nftokens.d.ts +3 -0
  123. package/lib/types/outcome.d.ts +6 -19
  124. package/lib/v1/utils.d.ts +1 -1
  125. package/lib/v1/utils.js +18 -10
  126. package/lib/validator.js +18 -16
  127. package/lib/wallet.d.ts +8 -1
  128. package/lib/wallet.js +94 -11
  129. package/package.json +18 -15
package/lib/v1/utils.js CHANGED
@@ -8,18 +8,26 @@ const client_1 = require("../client");
8
8
  function toRippledAmount(amount) {
9
9
  if (typeof amount === "string")
10
10
  return amount;
11
- if (amount.currency === (0, client_1.getNativeCurrency)()) {
12
- return (0, common_1.xrpToDrops)(amount.value);
11
+ if ("currency" in amount) {
12
+ if (amount.currency === (0, client_1.getNativeCurrency)()) {
13
+ return (0, common_1.xrpToDrops)(amount.value);
14
+ }
15
+ else if (amount.currency === "drops") {
16
+ return amount.value;
17
+ }
18
+ const issuer = amount.counterparty || amount.issuer;
19
+ return {
20
+ currency: amount.currency,
21
+ issuer,
22
+ value: amount.value,
23
+ };
13
24
  }
14
- if (amount.currency === "drops") {
15
- return amount.value;
25
+ if ("mpt_issuance_id" in amount) {
26
+ return {
27
+ value: amount.value,
28
+ mpt_issuance_id: amount.mpt_issuance_id,
29
+ };
16
30
  }
17
- const issuer = amount.counterparty || amount.issuer;
18
- return {
19
- currency: amount.currency,
20
- issuer,
21
- value: amount.value,
22
- };
23
31
  }
24
32
  function getClassicAccountAndTag(Account, expectedTag) {
25
33
  if ((0, ripple_address_codec_1.isValidXAddress)(Account)) {
package/lib/validator.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -34,7 +44,6 @@ exports.verify2 = verify2;
34
44
  const assert = __importStar(require("assert"));
35
45
  const ripple_address_codec_1 = require("ripple-address-codec");
36
46
  const Crypto = __importStar(require("crypto"));
37
- const Base58 = __importStar(require("./base58"));
38
47
  const elliptic_1 = __importDefault(require("elliptic"));
39
48
  const secp256k1 = new elliptic_1.default.ec("secp256k1");
40
49
  const ed25519 = new elliptic_1.default.eddsa("ed25519");
@@ -56,14 +65,7 @@ function classicAddressFromValidatorPK(pk) {
56
65
  const pubkeyOuterHash = Crypto.createHash("ripemd160");
57
66
  pubkeyOuterHash.update(pubkeyInnerHash.digest());
58
67
  const accountID = pubkeyOuterHash.digest();
59
- const addressTypePrefix = Buffer.from([0x00]);
60
- const payload = Buffer.concat([addressTypePrefix, accountID]);
61
- const chksumHash1 = Crypto.createHash("sha256").update(payload).digest();
62
- const chksumHash2 = Crypto.createHash("sha256").update(chksumHash1).digest();
63
- const checksum = chksumHash2.slice(0, 4);
64
- const dataToEncode = Buffer.concat([payload, checksum]);
65
- const address = Base58.encode(dataToEncode);
66
- return address;
68
+ return (0, ripple_address_codec_1.encodeAccountID)(accountID);
67
69
  }
68
70
  function generateSecrets() {
69
71
  const keypair = Crypto.generateKeyPairSync("ed25519", {
package/lib/wallet.d.ts CHANGED
@@ -6,6 +6,12 @@ interface GenerateAddressInterface {
6
6
  address: string;
7
7
  seed: string;
8
8
  }
9
+ export interface VerifySignatureInterface {
10
+ signedBy?: string;
11
+ signatureValid?: boolean;
12
+ signatureMultiSign?: boolean;
13
+ error?: string;
14
+ }
9
15
  export declare function isValidSecret(secret: string): boolean;
10
16
  export interface WalletFromSeedInterface {
11
17
  masterAddress?: string;
@@ -21,6 +27,7 @@ export declare function signTransaction(wallet: Wallet, transaction: Transaction
21
27
  tx_blob: string;
22
28
  hash: string;
23
29
  };
24
- export declare function verifyTransaction(wallet: Wallet, signedTransaction: Transaction | string): boolean;
30
+ export declare function verifyTransaction(signedTransaction: Transaction | string, definitions?: XrplDefinitionsBase): boolean;
31
+ export declare function verifySignature(signedTransaction: Transaction | string, explicitMultiSigner?: string | null, definitions?: XrplDefinitionsBase): VerifySignatureInterface;
25
32
  declare function hashSignedTx(tx: Transaction | string, definitions?: XrplDefinitionsBase, validateTx?: boolean): string;
26
33
  export { XrplDefinitionsBase, XrplDefinitions, DEFAULT_DEFINITIONS, hashSignedTx };
package/lib/wallet.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -34,6 +44,7 @@ exports.isValidClassicAddress = isValidClassicAddress;
34
44
  exports.checksumClassicAddress = checksumClassicAddress;
35
45
  exports.signTransaction = signTransaction;
36
46
  exports.verifyTransaction = verifyTransaction;
47
+ exports.verifySignature = verifySignature;
37
48
  exports.hashSignedTx = hashSignedTx;
38
49
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
39
50
  const omitBy_1 = __importDefault(require("lodash/omitBy"));
@@ -147,11 +158,83 @@ function signTransaction(wallet, transaction, multisign, definitions, validateTx
147
158
  hash: hashSignedTx(serialized, definitions),
148
159
  };
149
160
  }
150
- function verifyTransaction(wallet, signedTransaction) {
151
- const tx = typeof signedTransaction === "string" ? (0, ripple_binary_codec_1.decode)(signedTransaction) : signedTransaction;
152
- const messageHex = (0, ripple_binary_codec_1.encodeForSigning)(tx);
161
+ function verifyTransaction(signedTransaction, definitions) {
162
+ const tx = typeof signedTransaction === "string" ? (0, ripple_binary_codec_1.decode)(signedTransaction, definitions) : signedTransaction;
163
+ const messageHex = (0, ripple_binary_codec_1.encodeForSigning)(tx, definitions);
153
164
  const signature = tx.TxnSignature;
154
- return (0, ripple_keypairs_1.verify)(messageHex, signature, wallet.publicKey);
165
+ const publicKey = tx.SigningPubKey;
166
+ return (0, ripple_keypairs_1.verify)(messageHex, signature, publicKey);
167
+ }
168
+ function verifySignature(signedTransaction, explicitMultiSigner, definitions) {
169
+ let tx;
170
+ let signedBy = "";
171
+ let signatureValid = false;
172
+ try {
173
+ if (typeof signedTransaction === "string") {
174
+ tx = (0, ripple_binary_codec_1.decode)(signedTransaction, definitions);
175
+ }
176
+ else if (signedTransaction !== null && typeof signedTransaction === "object") {
177
+ tx = signedTransaction;
178
+ }
179
+ }
180
+ catch (err) {
181
+ return { signatureValid: false, error: err.message };
182
+ }
183
+ if (!tx) {
184
+ return { signatureValid: false, error: "The transaction could not be decoded." };
185
+ }
186
+ if (!tx.TxnSignature && !tx.Signers) {
187
+ return { signatureValid: false, error: "The transaction must be signed to verify the signature." };
188
+ }
189
+ const signatureMultiSign = typeof tx.Signers !== "undefined" &&
190
+ Array.isArray(tx.Signers) &&
191
+ tx.Signers.length > 0 &&
192
+ typeof tx.SigningPubKey === "string" &&
193
+ tx.SigningPubKey === "";
194
+ try {
195
+ if (signatureMultiSign && explicitMultiSigner && explicitMultiSigner.match(/^r/)) {
196
+ signedBy = explicitMultiSigner;
197
+ }
198
+ else if (signatureMultiSign && explicitMultiSigner) {
199
+ signedBy = (0, ripple_keypairs_1.deriveAddress)(explicitMultiSigner);
200
+ }
201
+ else {
202
+ let signer = tx.SigningPubKey;
203
+ if (signatureMultiSign && tx.Signers && tx.Signers.length > 0) {
204
+ const firstSigner = Object.values(tx.Signers)[0];
205
+ signer = firstSigner.Signer.SigningPubKey;
206
+ }
207
+ signedBy = (0, ripple_keypairs_1.deriveAddress)(signer);
208
+ }
209
+ }
210
+ catch (err) {
211
+ return { signatureValid: false, error: err.message };
212
+ }
213
+ try {
214
+ if (signatureMultiSign && tx.Signers) {
215
+ const matchingSigners = Object.values(tx.Signers).filter((signer) => {
216
+ return (0, ripple_keypairs_1.deriveAddress)(signer.Signer.SigningPubKey) === signedBy;
217
+ });
218
+ if (matchingSigners.length > 0) {
219
+ const multiSigner = matchingSigners[0];
220
+ signatureValid = (0, ripple_keypairs_1.verify)((0, ripple_binary_codec_1.encodeForMultisigning)(tx, signedBy, definitions), multiSigner.Signer.TxnSignature, multiSigner.Signer.SigningPubKey);
221
+ }
222
+ else {
223
+ return { signatureValid: false, error: "Explicit MultiSigner not in Signers" };
224
+ }
225
+ }
226
+ else {
227
+ signatureValid = (0, ripple_keypairs_1.verify)((0, ripple_binary_codec_1.encodeForSigning)(tx, definitions), tx.TxnSignature, tx.SigningPubKey);
228
+ }
229
+ }
230
+ catch (err) {
231
+ return { signedBy, signatureValid: false, error: err.message };
232
+ }
233
+ return {
234
+ signedBy,
235
+ signatureValid,
236
+ signatureMultiSign,
237
+ };
155
238
  }
156
239
  function computeSignature(tx, privateKey, signAs, definitions) {
157
240
  if (signAs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "3.1.17",
3
+ "version": "3.2.0",
4
4
  "description": "A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "test": "node ./node_modules/mocha/bin/mocha",
42
42
  "build": "tsc",
43
43
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
44
- "lint": "eslint -c .eslintrc.json --ext .ts src/",
44
+ "lint": "eslint",
45
45
  "prepare": "npm run build",
46
46
  "prepublishOnly": "npm test && npm run lint",
47
47
  "preversion": "npm run lint",
@@ -52,36 +52,39 @@
52
52
  "lib/**/*"
53
53
  ],
54
54
  "dependencies": {
55
- "axios": "^1.7.7",
55
+ "axios": "^1.7.9",
56
56
  "base-x": "^5.0.0",
57
57
  "bignumber.js": "^9.1.2",
58
- "elliptic": "^6.6.0",
58
+ "elliptic": "^6.6.1",
59
59
  "lodash": "^4.17.21",
60
60
  "ripple-address-codec": "^5.0.0",
61
61
  "ripple-binary-codec": "^2.1.0",
62
62
  "xrpl": "^4.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@types/chai": "^4.3.19",
66
- "@types/chai-as-promised": "^7.1.8",
65
+ "@eslint/eslintrc": "^3.2.0",
66
+ "@eslint/js": "^9.17.0",
67
+ "@types/chai": "^5.0.1",
68
+ "@types/chai-as-promised": "^8.0.1",
67
69
  "@types/lodash": "^4.17.13",
68
- "@types/mocha": "^10.0.9",
70
+ "@types/mocha": "^10.0.10",
69
71
  "@types/nconf": "^0.10.7",
70
- "@types/node": "^20.14.15",
71
- "@typescript-eslint/eslint-plugin": "^8.13.0",
72
- "@typescript-eslint/parser": "^8.13.0",
72
+ "@types/node": "^22.10.2",
73
+ "@typescript-eslint/eslint-plugin": "^8.18.1",
74
+ "@typescript-eslint/parser": "^8.18.1",
73
75
  "chai": "^4.5.0",
74
76
  "chai-as-promised": "^7.1.2",
75
- "eslint": "^8.57.0",
77
+ "eslint": "^9.17.0",
76
78
  "eslint-config-prettier": "^9.1.0",
77
79
  "eslint-plugin-chai-friendly": "^1.0.1",
78
80
  "eslint-plugin-import": "^2.31.0",
79
- "eslint-plugin-n": "^17.12.0",
80
- "eslint-plugin-promise": "^7.1.0",
81
- "mocha": "^10.8.2",
81
+ "eslint-plugin-n": "^17.15.1",
82
+ "eslint-plugin-promise": "^7.2.1",
83
+ "globals": "^15.14.0",
84
+ "mocha": "^11.0.1",
82
85
  "nconf": "^0.12.1",
83
86
  "ts-jest": "^29.2.5",
84
87
  "ts-node": "^10.9.2",
85
- "typescript": "^5.4.5"
88
+ "typescript": "^5.7.2"
86
89
  }
87
90
  }