@bithomp/xrpl-api 3.1.17 → 3.1.18

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.
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
@@ -34,6 +34,7 @@ exports.isValidClassicAddress = isValidClassicAddress;
34
34
  exports.checksumClassicAddress = checksumClassicAddress;
35
35
  exports.signTransaction = signTransaction;
36
36
  exports.verifyTransaction = verifyTransaction;
37
+ exports.verifySignature = verifySignature;
37
38
  exports.hashSignedTx = hashSignedTx;
38
39
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
39
40
  const omitBy_1 = __importDefault(require("lodash/omitBy"));
@@ -147,11 +148,83 @@ function signTransaction(wallet, transaction, multisign, definitions, validateTx
147
148
  hash: hashSignedTx(serialized, definitions),
148
149
  };
149
150
  }
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);
151
+ function verifyTransaction(signedTransaction, definitions) {
152
+ const tx = typeof signedTransaction === "string" ? (0, ripple_binary_codec_1.decode)(signedTransaction, definitions) : signedTransaction;
153
+ const messageHex = (0, ripple_binary_codec_1.encodeForSigning)(tx, definitions);
153
154
  const signature = tx.TxnSignature;
154
- return (0, ripple_keypairs_1.verify)(messageHex, signature, wallet.publicKey);
155
+ const publicKey = tx.SigningPubKey;
156
+ return (0, ripple_keypairs_1.verify)(messageHex, signature, publicKey);
157
+ }
158
+ function verifySignature(signedTransaction, explicitMultiSigner, definitions) {
159
+ let tx;
160
+ let signedBy = "";
161
+ let signatureValid = false;
162
+ try {
163
+ if (typeof signedTransaction === "string") {
164
+ tx = (0, ripple_binary_codec_1.decode)(signedTransaction, definitions);
165
+ }
166
+ else if (signedTransaction !== null && typeof signedTransaction === "object") {
167
+ tx = signedTransaction;
168
+ }
169
+ }
170
+ catch (err) {
171
+ return { signatureValid: false, error: err.message };
172
+ }
173
+ if (!tx) {
174
+ return { signatureValid: false, error: "The transaction could not be decoded." };
175
+ }
176
+ if (!tx.TxnSignature && !tx.Signers) {
177
+ return { signatureValid: false, error: "The transaction must be signed to verify the signature." };
178
+ }
179
+ const signatureMultiSign = typeof tx.Signers !== "undefined" &&
180
+ Array.isArray(tx.Signers) &&
181
+ tx.Signers.length > 0 &&
182
+ typeof tx.SigningPubKey === "string" &&
183
+ tx.SigningPubKey === "";
184
+ try {
185
+ if (signatureMultiSign && explicitMultiSigner && explicitMultiSigner.match(/^r/)) {
186
+ signedBy = explicitMultiSigner;
187
+ }
188
+ else if (signatureMultiSign && explicitMultiSigner) {
189
+ signedBy = (0, ripple_keypairs_1.deriveAddress)(explicitMultiSigner);
190
+ }
191
+ else {
192
+ let signer = tx.SigningPubKey;
193
+ if (signatureMultiSign && tx.Signers && tx.Signers.length > 0) {
194
+ const firstSigner = Object.values(tx.Signers)[0];
195
+ signer = firstSigner.Signer.SigningPubKey;
196
+ }
197
+ signedBy = (0, ripple_keypairs_1.deriveAddress)(signer);
198
+ }
199
+ }
200
+ catch (err) {
201
+ return { signatureValid: false, error: err.message };
202
+ }
203
+ try {
204
+ if (signatureMultiSign && tx.Signers) {
205
+ const matchingSigners = Object.values(tx.Signers).filter((signer) => {
206
+ return (0, ripple_keypairs_1.deriveAddress)(signer.Signer.SigningPubKey) === signedBy;
207
+ });
208
+ if (matchingSigners.length > 0) {
209
+ const multiSigner = matchingSigners[0];
210
+ signatureValid = (0, ripple_keypairs_1.verify)((0, ripple_binary_codec_1.encodeForMultisigning)(tx, signedBy, definitions), multiSigner.Signer.TxnSignature, multiSigner.Signer.SigningPubKey);
211
+ }
212
+ else {
213
+ return { signatureValid: false, error: "Explicit MultiSigner not in Signers" };
214
+ }
215
+ }
216
+ else {
217
+ signatureValid = (0, ripple_keypairs_1.verify)((0, ripple_binary_codec_1.encodeForSigning)(tx, definitions), tx.TxnSignature, tx.SigningPubKey);
218
+ }
219
+ }
220
+ catch (err) {
221
+ return { signedBy, signatureValid: false, error: err.message };
222
+ }
223
+ return {
224
+ signedBy,
225
+ signatureValid,
226
+ signatureMultiSign,
227
+ };
155
228
  }
156
229
  function computeSignature(tx, privateKey, signAs, definitions) {
157
230
  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.1.18",
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",
@@ -55,28 +55,28 @@
55
55
  "axios": "^1.7.7",
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
+ "@types/chai": "^5.0.1",
66
+ "@types/chai-as-promised": "^8.0.1",
67
67
  "@types/lodash": "^4.17.13",
68
68
  "@types/mocha": "^10.0.9",
69
69
  "@types/nconf": "^0.10.7",
70
70
  "@types/node": "^20.14.15",
71
- "@typescript-eslint/eslint-plugin": "^8.13.0",
72
- "@typescript-eslint/parser": "^8.13.0",
71
+ "@typescript-eslint/eslint-plugin": "^8.14.0",
72
+ "@typescript-eslint/parser": "^8.14.0",
73
73
  "chai": "^4.5.0",
74
74
  "chai-as-promised": "^7.1.2",
75
75
  "eslint": "^8.57.0",
76
76
  "eslint-config-prettier": "^9.1.0",
77
77
  "eslint-plugin-chai-friendly": "^1.0.1",
78
78
  "eslint-plugin-import": "^2.31.0",
79
- "eslint-plugin-n": "^17.12.0",
79
+ "eslint-plugin-n": "^17.13.2",
80
80
  "eslint-plugin-promise": "^7.1.0",
81
81
  "mocha": "^10.8.2",
82
82
  "nconf": "^0.12.1",