@hwlt/era-connect 0.3.0 → 0.4.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.
- package/README.md +5 -5
- package/cosmos/package.json +6 -0
- package/dist/{btc-DfQ0q79G.d.ts → btc-B8LfSEkv.d.ts} +11 -2
- package/dist/{btc-VyJKXq7d.js → btc-B_Nq2H4T.js} +16 -7
- package/dist/btc-B_Nq2H4T.js.map +1 -0
- package/dist/{btc-Fr6Jz4Fi.cjs → btc-ByzjzUKs.cjs} +19 -10
- package/dist/btc-ByzjzUKs.cjs.map +1 -0
- package/dist/{btc-Dn6_Y12c.d.cts → btc-C4dVkxHb.d.cts} +11 -2
- package/dist/btc.cjs +2 -2
- package/dist/btc.d.cts +1 -1
- package/dist/btc.d.ts +1 -1
- package/dist/btc.js +2 -2
- package/dist/{cardano-yuOygqwp.js → cardano-BCT55gwf.js} +3 -2
- package/dist/{cardano-yuOygqwp.js.map → cardano-BCT55gwf.js.map} +1 -1
- package/dist/{cardano-DP6U_K1J.cjs → cardano-CzYswGzK.cjs} +5 -4
- package/dist/{cardano-DP6U_K1J.cjs.map → cardano-CzYswGzK.cjs.map} +1 -1
- package/dist/cardano.cjs +2 -2
- package/dist/cardano.js +2 -2
- package/dist/cosmos-BYrhIqRk.d.cts +77 -0
- package/dist/cosmos-DDsgtUki.cjs +113 -0
- package/dist/cosmos-DDsgtUki.cjs.map +1 -0
- package/dist/cosmos-DqyjA6lg.d.ts +77 -0
- package/dist/cosmos-jUHNxgWC.js +102 -0
- package/dist/cosmos-jUHNxgWC.js.map +1 -0
- package/dist/cosmos.cjs +10 -0
- package/dist/cosmos.d.cts +3 -0
- package/dist/cosmos.d.ts +3 -0
- package/dist/cosmos.js +3 -0
- package/dist/{derive-CuILJRPT.cjs → derive-BayrpfJk.cjs} +14 -2
- package/dist/derive-BayrpfJk.cjs.map +1 -0
- package/dist/{derive-C4JdycUh.js → derive-CK9Nc9Jc.js} +9 -3
- package/dist/derive-CK9Nc9Jc.js.map +1 -0
- package/dist/{evm-kJb3-oiR.js → evm-CI1cuZsp.js} +3 -2
- package/dist/{evm-kJb3-oiR.js.map → evm-CI1cuZsp.js.map} +1 -1
- package/dist/{evm-BHj_2OTG.cjs → evm-yfKOc2dy.cjs} +6 -5
- package/dist/{evm-BHj_2OTG.cjs.map → evm-yfKOc2dy.cjs.map} +1 -1
- package/dist/evm.cjs +2 -2
- package/dist/evm.js +2 -2
- package/dist/index.cjs +79 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +51 -9
- package/dist/index.js.map +1 -1
- package/dist/keypath-Bvv_cfHt.js +75 -0
- package/dist/keypath-Bvv_cfHt.js.map +1 -0
- package/dist/keypath-pzm_YIfN.cjs +116 -0
- package/dist/keypath-pzm_YIfN.cjs.map +1 -0
- package/dist/{messages-BzcdWlg1.cjs → messages-BZXDY29v.cjs} +2 -2
- package/dist/{messages-BzcdWlg1.cjs.map → messages-BZXDY29v.cjs.map} +1 -1
- package/dist/{messages-17Oup0-Z.js → messages-DbnXy3dC.js} +2 -2
- package/dist/{messages-17Oup0-Z.js.map → messages-DbnXy3dC.js.map} +1 -1
- package/dist/{shared-B8Wc7ViU.js → shared-Bbgejrus.js} +2 -73
- package/dist/shared-Bbgejrus.js.map +1 -0
- package/dist/{shared-nISrEktU.cjs → shared-Cu2yynP9.cjs} +13 -114
- package/dist/shared-Cu2yynP9.cjs.map +1 -0
- package/dist/{solana-DdEn24X4.cjs → solana-BoQBy0hu.cjs} +6 -5
- package/dist/{solana-DdEn24X4.cjs.map → solana-BoQBy0hu.cjs.map} +1 -1
- package/dist/{solana-C7JQEAec.js → solana-BukH3AI3.js} +3 -2
- package/dist/{solana-C7JQEAec.js.map → solana-BukH3AI3.js.map} +1 -1
- package/dist/solana.cjs +2 -2
- package/dist/solana.js +2 -2
- package/dist/sui-6WX6VPlW.d.cts +49 -0
- package/dist/sui-BtbPG6Xt.js +71 -0
- package/dist/sui-BtbPG6Xt.js.map +1 -0
- package/dist/sui-CYRn331O.cjs +82 -0
- package/dist/sui-CYRn331O.cjs.map +1 -0
- package/dist/sui-DI0ruW7E.d.ts +49 -0
- package/dist/sui.cjs +10 -0
- package/dist/sui.d.cts +3 -0
- package/dist/sui.d.ts +3 -0
- package/dist/sui.js +3 -0
- package/dist/{ton-5Uvi5ifg.js → ton-BSPKU5B9.js} +3 -2
- package/dist/{ton-5Uvi5ifg.js.map → ton-BSPKU5B9.js.map} +1 -1
- package/dist/{ton-DUJGXdGa.cjs → ton-CI2s9puH.cjs} +6 -5
- package/dist/{ton-DUJGXdGa.cjs.map → ton-CI2s9puH.cjs.map} +1 -1
- package/dist/ton.cjs +2 -2
- package/dist/ton.js +2 -2
- package/dist/{tron-CQIEqjCA.cjs → tron-B9wXdzlA.cjs} +7 -6
- package/dist/{tron-CQIEqjCA.cjs.map → tron-B9wXdzlA.cjs.map} +1 -1
- package/dist/{tron-Bo9HnvVE.js → tron-fufBDNuQ.js} +4 -3
- package/dist/{tron-Bo9HnvVE.js.map → tron-fufBDNuQ.js.map} +1 -1
- package/dist/tron.cjs +3 -3
- package/dist/tron.js +3 -3
- package/dist/verify.cjs +192 -9
- package/dist/verify.cjs.map +1 -1
- package/dist/verify.d.cts +54 -1
- package/dist/verify.d.ts +54 -1
- package/dist/verify.js +189 -9
- package/dist/verify.js.map +1 -1
- package/dist/xrp-BXAeK4iH.d.cts +32 -0
- package/dist/xrp-BrHXUnX5.cjs +52 -0
- package/dist/xrp-BrHXUnX5.cjs.map +1 -0
- package/dist/xrp-C8LJO5b-.js +47 -0
- package/dist/xrp-C8LJO5b-.js.map +1 -0
- package/dist/xrp-DqCXGYEk.d.ts +32 -0
- package/dist/xrp.cjs +9 -0
- package/dist/xrp.d.cts +3 -0
- package/dist/xrp.d.ts +3 -0
- package/dist/xrp.js +3 -0
- package/package.json +37 -1
- package/sui/package.json +6 -0
- package/xrp/package.json +6 -0
- package/dist/btc-Fr6Jz4Fi.cjs.map +0 -1
- package/dist/btc-VyJKXq7d.js.map +0 -1
- package/dist/derive-C4JdycUh.js.map +0 -1
- package/dist/derive-CuILJRPT.cjs.map +0 -1
- package/dist/shared-B8Wc7ViU.js.map +0 -1
- package/dist/shared-nISrEktU.cjs.map +0 -1
package/dist/verify.d.cts
CHANGED
|
@@ -94,6 +94,24 @@ interface VerifyCardanoSignatureArgs {
|
|
|
94
94
|
*/
|
|
95
95
|
declare function verifyCardanoSignature(args: VerifyCardanoSignatureArgs): VerifyResult;
|
|
96
96
|
//#endregion
|
|
97
|
+
//#region src/verify/cosmos.d.ts
|
|
98
|
+
interface VerifyCosmosSignatureArgs {
|
|
99
|
+
/** The exact SignDoc bytes the request carried. */
|
|
100
|
+
readonly signData: Uint8Array;
|
|
101
|
+
/**
|
|
102
|
+
* Digest family: vanilla Cosmos zones hash with sha256; Ethermint chains
|
|
103
|
+
* (Injective, Evmos, Dymension) with keccak256.
|
|
104
|
+
*/
|
|
105
|
+
readonly digest: 'sha256' | 'keccak256';
|
|
106
|
+
/** 64-byte compact signature from the reply. */
|
|
107
|
+
readonly signature: Uint8Array;
|
|
108
|
+
/** 33-byte compressed public key (from the reply, or derived from your linked xpub). */
|
|
109
|
+
readonly publicKey: Uint8Array;
|
|
110
|
+
/** Optional binding: the key you EXPECT (derived from the linked account). */
|
|
111
|
+
readonly expectedPublicKey?: Uint8Array;
|
|
112
|
+
}
|
|
113
|
+
declare function verifyCosmosSignature(args: VerifyCosmosSignatureArgs): VerifyResult;
|
|
114
|
+
//#endregion
|
|
97
115
|
//#region src/verify/evm.d.ts
|
|
98
116
|
interface VerifyEvmSignatureArgs {
|
|
99
117
|
/** The exact bytes the request carried in `signData`. */
|
|
@@ -168,6 +186,21 @@ interface VerifySolanaSignatureArgs {
|
|
|
168
186
|
}
|
|
169
187
|
declare function verifySolanaSignature(args: VerifySolanaSignatureArgs): VerifyResult;
|
|
170
188
|
//#endregion
|
|
189
|
+
//#region src/verify/sui.d.ts
|
|
190
|
+
interface VerifySuiSignatureArgs {
|
|
191
|
+
/** The intent message the request carried (or pass `messageHash` for the hash variant). */
|
|
192
|
+
readonly intentMessage?: Uint8Array;
|
|
193
|
+
readonly messageHash?: Uint8Array;
|
|
194
|
+
/** 64-byte Ed25519 signature from the reply. */
|
|
195
|
+
readonly signature: Uint8Array;
|
|
196
|
+
/** The signer key the reply carried. */
|
|
197
|
+
readonly publicKey: Uint8Array;
|
|
198
|
+
/** The linked account's key (`accounts.sui()[i].publicKey`) — binds the reply to YOUR wallet. */
|
|
199
|
+
readonly expectedPublicKey?: Uint8Array;
|
|
200
|
+
}
|
|
201
|
+
/** BLAKE2b-256 of the intent message (or the given hash) + Ed25519 verification. */
|
|
202
|
+
declare function verifySuiSignature(args: VerifySuiSignatureArgs): VerifyResult;
|
|
203
|
+
//#endregion
|
|
171
204
|
//#region src/verify/ton.d.ts
|
|
172
205
|
interface VerifyTonSignatureArgs {
|
|
173
206
|
/** The exact bytes the request carried in `signData`. */
|
|
@@ -213,5 +246,25 @@ interface VerifyTronSignatureArgs {
|
|
|
213
246
|
*/
|
|
214
247
|
declare function verifyTronSignature(args: VerifyTronSignatureArgs): VerifyResult;
|
|
215
248
|
//#endregion
|
|
216
|
-
|
|
249
|
+
//#region src/verify/xrp.d.ts
|
|
250
|
+
interface VerifyXrpSignatureArgs {
|
|
251
|
+
/** The signed binary transaction from the reply. */
|
|
252
|
+
readonly signedTx: Uint8Array;
|
|
253
|
+
/** The `SigningPubKey` hex your request JSON carried (33-byte compressed secp256k1). */
|
|
254
|
+
readonly expectedSigningPubKey: string;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* XRP has no request id — this check IS the binding. The signed binary is
|
|
258
|
+
* split into its canonical fields; `TxnSignature` is removed; the remainder
|
|
259
|
+
* (prefixed with the XRPL signing tag `STX\0`) is hashed with SHA-512-half
|
|
260
|
+
* and the DER signature is verified against `SigningPubKey`, which must also
|
|
261
|
+
* equal the key your request carried.
|
|
262
|
+
*
|
|
263
|
+
* The field walker covers the types Payment-class transactions use; a
|
|
264
|
+
* transaction carrying an exotic field type comes back `checked: false`
|
|
265
|
+
* rather than a false verdict.
|
|
266
|
+
*/
|
|
267
|
+
declare function verifyXrpSignature(args: VerifyXrpSignatureArgs): VerifyResult;
|
|
268
|
+
//#endregion
|
|
269
|
+
export { type ParsedPsbt, PsbtInputType, type PsbtKeyValue, type VerifyBtcMessageHeaderArgs, type VerifyCardanoSignatureArgs, type VerifyCosmosSignatureArgs, type VerifyEvmSignatureArgs, type VerifyResult, type VerifySignedPsbtArgs, type VerifySolanaSignatureArgs, type VerifySuiSignatureArgs, type VerifyTonSignatureArgs, type VerifyTronSignatureArgs, type VerifyXrpSignatureArgs, bocRootHash, parsePsbt, verifyBtcMessageHeader, verifyCardanoSignature, verifyCosmosSignature, verifyEvmSignature, verifySignedPsbt, verifySolanaSignature, verifySuiSignature, verifyTonSignature, verifyTronSignature, verifyXrpSignature };
|
|
217
270
|
//# sourceMappingURL=verify.d.cts.map
|
package/dist/verify.d.ts
CHANGED
|
@@ -94,6 +94,24 @@ interface VerifyCardanoSignatureArgs {
|
|
|
94
94
|
*/
|
|
95
95
|
declare function verifyCardanoSignature(args: VerifyCardanoSignatureArgs): VerifyResult;
|
|
96
96
|
//#endregion
|
|
97
|
+
//#region src/verify/cosmos.d.ts
|
|
98
|
+
interface VerifyCosmosSignatureArgs {
|
|
99
|
+
/** The exact SignDoc bytes the request carried. */
|
|
100
|
+
readonly signData: Uint8Array;
|
|
101
|
+
/**
|
|
102
|
+
* Digest family: vanilla Cosmos zones hash with sha256; Ethermint chains
|
|
103
|
+
* (Injective, Evmos, Dymension) with keccak256.
|
|
104
|
+
*/
|
|
105
|
+
readonly digest: 'sha256' | 'keccak256';
|
|
106
|
+
/** 64-byte compact signature from the reply. */
|
|
107
|
+
readonly signature: Uint8Array;
|
|
108
|
+
/** 33-byte compressed public key (from the reply, or derived from your linked xpub). */
|
|
109
|
+
readonly publicKey: Uint8Array;
|
|
110
|
+
/** Optional binding: the key you EXPECT (derived from the linked account). */
|
|
111
|
+
readonly expectedPublicKey?: Uint8Array;
|
|
112
|
+
}
|
|
113
|
+
declare function verifyCosmosSignature(args: VerifyCosmosSignatureArgs): VerifyResult;
|
|
114
|
+
//#endregion
|
|
97
115
|
//#region src/verify/evm.d.ts
|
|
98
116
|
interface VerifyEvmSignatureArgs {
|
|
99
117
|
/** The exact bytes the request carried in `signData`. */
|
|
@@ -168,6 +186,21 @@ interface VerifySolanaSignatureArgs {
|
|
|
168
186
|
}
|
|
169
187
|
declare function verifySolanaSignature(args: VerifySolanaSignatureArgs): VerifyResult;
|
|
170
188
|
//#endregion
|
|
189
|
+
//#region src/verify/sui.d.ts
|
|
190
|
+
interface VerifySuiSignatureArgs {
|
|
191
|
+
/** The intent message the request carried (or pass `messageHash` for the hash variant). */
|
|
192
|
+
readonly intentMessage?: Uint8Array;
|
|
193
|
+
readonly messageHash?: Uint8Array;
|
|
194
|
+
/** 64-byte Ed25519 signature from the reply. */
|
|
195
|
+
readonly signature: Uint8Array;
|
|
196
|
+
/** The signer key the reply carried. */
|
|
197
|
+
readonly publicKey: Uint8Array;
|
|
198
|
+
/** The linked account's key (`accounts.sui()[i].publicKey`) — binds the reply to YOUR wallet. */
|
|
199
|
+
readonly expectedPublicKey?: Uint8Array;
|
|
200
|
+
}
|
|
201
|
+
/** BLAKE2b-256 of the intent message (or the given hash) + Ed25519 verification. */
|
|
202
|
+
declare function verifySuiSignature(args: VerifySuiSignatureArgs): VerifyResult;
|
|
203
|
+
//#endregion
|
|
171
204
|
//#region src/verify/ton.d.ts
|
|
172
205
|
interface VerifyTonSignatureArgs {
|
|
173
206
|
/** The exact bytes the request carried in `signData`. */
|
|
@@ -213,5 +246,25 @@ interface VerifyTronSignatureArgs {
|
|
|
213
246
|
*/
|
|
214
247
|
declare function verifyTronSignature(args: VerifyTronSignatureArgs): VerifyResult;
|
|
215
248
|
//#endregion
|
|
216
|
-
|
|
249
|
+
//#region src/verify/xrp.d.ts
|
|
250
|
+
interface VerifyXrpSignatureArgs {
|
|
251
|
+
/** The signed binary transaction from the reply. */
|
|
252
|
+
readonly signedTx: Uint8Array;
|
|
253
|
+
/** The `SigningPubKey` hex your request JSON carried (33-byte compressed secp256k1). */
|
|
254
|
+
readonly expectedSigningPubKey: string;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* XRP has no request id — this check IS the binding. The signed binary is
|
|
258
|
+
* split into its canonical fields; `TxnSignature` is removed; the remainder
|
|
259
|
+
* (prefixed with the XRPL signing tag `STX\0`) is hashed with SHA-512-half
|
|
260
|
+
* and the DER signature is verified against `SigningPubKey`, which must also
|
|
261
|
+
* equal the key your request carried.
|
|
262
|
+
*
|
|
263
|
+
* The field walker covers the types Payment-class transactions use; a
|
|
264
|
+
* transaction carrying an exotic field type comes back `checked: false`
|
|
265
|
+
* rather than a false verdict.
|
|
266
|
+
*/
|
|
267
|
+
declare function verifyXrpSignature(args: VerifyXrpSignatureArgs): VerifyResult;
|
|
268
|
+
//#endregion
|
|
269
|
+
export { type ParsedPsbt, PsbtInputType, type PsbtKeyValue, type VerifyBtcMessageHeaderArgs, type VerifyCardanoSignatureArgs, type VerifyCosmosSignatureArgs, type VerifyEvmSignatureArgs, type VerifyResult, type VerifySignedPsbtArgs, type VerifySolanaSignatureArgs, type VerifySuiSignatureArgs, type VerifyTonSignatureArgs, type VerifyTronSignatureArgs, type VerifyXrpSignatureArgs, bocRootHash, parsePsbt, verifyBtcMessageHeader, verifyCardanoSignature, verifyCosmosSignature, verifyEvmSignature, verifySignedPsbt, verifySolanaSignature, verifySuiSignature, verifyTonSignature, verifyTronSignature, verifyXrpSignature };
|
|
217
270
|
//# sourceMappingURL=verify.d.ts.map
|
package/dist/verify.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { A as utf8Encode, D as hexToBytes, E as equalBytes,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
1
|
+
import { A as utf8Encode, D as hexToBytes, E as equalBytes, K as EraSdkError, T as concatBytes, k as utf8Decode, w as bytesToHex } from "./shared-Bbgejrus.js";
|
|
2
|
+
import { i as parsePath } from "./keypath-Bvv_cfHt.js";
|
|
3
|
+
import { a as cardanoSoftDerivePath } from "./derive-CK9Nc9Jc.js";
|
|
4
|
+
import { n as parseWitnessSet } from "./cardano-BCT55gwf.js";
|
|
5
|
+
import { n as EvmDataType, r as foldRecoveryId } from "./evm-CI1cuZsp.js";
|
|
6
|
+
import { n as suiIntentDigest } from "./sui-BtbPG6Xt.js";
|
|
7
|
+
import { n as TonDataType } from "./ton-BSPKU5B9.js";
|
|
8
|
+
import { a as firstVarint, i as firstBytes, o as readFields, r as splitSignedTronTx } from "./messages-DbnXy3dC.js";
|
|
7
9
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
8
|
-
import {
|
|
10
|
+
import { blake2b } from "@noble/hashes/blake2b";
|
|
11
|
+
import { sha256, sha512 } from "@noble/hashes/sha2";
|
|
9
12
|
import { keccak_256 } from "@noble/hashes/sha3";
|
|
10
13
|
import { createBase58check } from "@scure/base";
|
|
11
14
|
import { ed25519 } from "@noble/curves/ed25519";
|
|
12
|
-
import { blake2b } from "@noble/hashes/blake2b";
|
|
13
15
|
//#region src/verify/psbt-reader.ts
|
|
14
16
|
const MAGIC = [
|
|
15
17
|
112,
|
|
@@ -393,6 +395,21 @@ function skipItem(bytes, offset, depth) {
|
|
|
393
395
|
}
|
|
394
396
|
}
|
|
395
397
|
//#endregion
|
|
398
|
+
//#region src/verify/cosmos.ts
|
|
399
|
+
function verifyCosmosSignature(args) {
|
|
400
|
+
if (args.signature.length !== 64) return failed("signature must be 64 bytes (compact r||s)");
|
|
401
|
+
if (args.publicKey.length !== 33) return failed("publicKey must be 33 bytes (compressed)");
|
|
402
|
+
if (args.expectedPublicKey !== void 0 && !equalBytes(args.publicKey, args.expectedPublicKey)) return failed("the reply public key is not the linked account key");
|
|
403
|
+
const digest = args.digest === "keccak256" ? keccak_256(args.signData) : sha256(args.signData);
|
|
404
|
+
let ok;
|
|
405
|
+
try {
|
|
406
|
+
ok = secp256k1.verify(args.signature, digest, args.publicKey);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
return failed(`Cosmos signature could not be checked: ${e.message}`);
|
|
409
|
+
}
|
|
410
|
+
return ok ? verified : failed("the signature does not belong to this account");
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
396
413
|
//#region src/verify/evm.ts
|
|
397
414
|
/** EIP-191: 0x19 || "Ethereum Signed Message:\n" || len(message). */
|
|
398
415
|
function personalSignDigest(message) {
|
|
@@ -448,6 +465,25 @@ function verifySolanaSignature(args) {
|
|
|
448
465
|
return ok ? verified : failed("the signature does not belong to this account");
|
|
449
466
|
}
|
|
450
467
|
//#endregion
|
|
468
|
+
//#region src/verify/sui.ts
|
|
469
|
+
/** BLAKE2b-256 of the intent message (or the given hash) + Ed25519 verification. */
|
|
470
|
+
function verifySuiSignature(args) {
|
|
471
|
+
let digest;
|
|
472
|
+
if (args.messageHash !== void 0) {
|
|
473
|
+
if (args.messageHash.length !== 32) return failed("messageHash must be 32 bytes");
|
|
474
|
+
digest = args.messageHash;
|
|
475
|
+
} else if (args.intentMessage !== void 0) digest = suiIntentDigest(args.intentMessage);
|
|
476
|
+
else return failed("provide intentMessage or messageHash");
|
|
477
|
+
if (args.expectedPublicKey !== void 0 && !equalBytes(args.publicKey, args.expectedPublicKey)) return failed("the reply public key is not the linked account key");
|
|
478
|
+
let ok;
|
|
479
|
+
try {
|
|
480
|
+
ok = ed25519.verify(args.signature, digest, args.publicKey);
|
|
481
|
+
} catch (e) {
|
|
482
|
+
return failed(`Sui signature could not be checked: ${e.message}`);
|
|
483
|
+
}
|
|
484
|
+
return ok ? verified : failed("the signature does not belong to this account");
|
|
485
|
+
}
|
|
486
|
+
//#endregion
|
|
451
487
|
//#region src/verify/ton-boc.ts
|
|
452
488
|
/**
|
|
453
489
|
* Minimal TON Bag-of-Cells reader + cell representation hash — exactly the
|
|
@@ -719,6 +755,150 @@ function compareWindow(repliedBytes, latestBlock) {
|
|
|
719
755
|
return verified;
|
|
720
756
|
}
|
|
721
757
|
//#endregion
|
|
722
|
-
|
|
758
|
+
//#region src/verify/xrp.ts
|
|
759
|
+
/**
|
|
760
|
+
* XRP has no request id — this check IS the binding. The signed binary is
|
|
761
|
+
* split into its canonical fields; `TxnSignature` is removed; the remainder
|
|
762
|
+
* (prefixed with the XRPL signing tag `STX\0`) is hashed with SHA-512-half
|
|
763
|
+
* and the DER signature is verified against `SigningPubKey`, which must also
|
|
764
|
+
* equal the key your request carried.
|
|
765
|
+
*
|
|
766
|
+
* The field walker covers the types Payment-class transactions use; a
|
|
767
|
+
* transaction carrying an exotic field type comes back `checked: false`
|
|
768
|
+
* rather than a false verdict.
|
|
769
|
+
*/
|
|
770
|
+
function verifyXrpSignature(args) {
|
|
771
|
+
let fields;
|
|
772
|
+
try {
|
|
773
|
+
fields = splitFields(args.signedTx);
|
|
774
|
+
} catch (e) {
|
|
775
|
+
const message = e.message;
|
|
776
|
+
if (message === "unsupported-field") return unverifiable("the transaction carries a field type this checker does not walk");
|
|
777
|
+
return failed(`the signed transaction is not readable: ${message}`);
|
|
778
|
+
}
|
|
779
|
+
const signingPubKey = fields.find((f) => f.header === 115);
|
|
780
|
+
const txnSignature = fields.find((f) => f.header === 116);
|
|
781
|
+
if (!signingPubKey || !txnSignature) return failed("the signed transaction is missing SigningPubKey or TxnSignature");
|
|
782
|
+
const expected = hexToBytes(args.expectedSigningPubKey);
|
|
783
|
+
if (!equalBytes(signingPubKey.value, expected)) return failed(`the transaction was signed with a different key (${bytesToHex(signingPubKey.value)})`);
|
|
784
|
+
const payload = concatBytes(new Uint8Array([
|
|
785
|
+
83,
|
|
786
|
+
84,
|
|
787
|
+
88,
|
|
788
|
+
0
|
|
789
|
+
]), ...fields.filter((f) => f.header !== 116).map((f) => f.raw));
|
|
790
|
+
const digest = sha512(payload).slice(0, 32);
|
|
791
|
+
let ok;
|
|
792
|
+
try {
|
|
793
|
+
ok = secp256k1.verify(secp256k1.Signature.fromDER(txnSignature.value).toCompactRawBytes(), digest, expected);
|
|
794
|
+
} catch (e) {
|
|
795
|
+
return failed(`XRP signature could not be checked: ${e.message}`);
|
|
796
|
+
}
|
|
797
|
+
return ok ? verified : failed("the signature does not verify against SigningPubKey");
|
|
798
|
+
}
|
|
799
|
+
/** Split a canonical STObject into its top-level fields. */
|
|
800
|
+
function splitFields(bytes) {
|
|
801
|
+
const fields = [];
|
|
802
|
+
let pos = 0;
|
|
803
|
+
while (pos < bytes.length) {
|
|
804
|
+
const field = parseField(bytes, pos);
|
|
805
|
+
fields.push(field.field);
|
|
806
|
+
pos = field.end;
|
|
807
|
+
}
|
|
808
|
+
return fields;
|
|
809
|
+
}
|
|
810
|
+
/** Parse ONE field at `pos`; returns the field and the offset past it. */
|
|
811
|
+
function parseField(bytes, pos) {
|
|
812
|
+
const start = pos;
|
|
813
|
+
const first = bytes[pos++];
|
|
814
|
+
if (first === void 0) throw new Error("truncated");
|
|
815
|
+
let type = first >> 4;
|
|
816
|
+
let fieldCode = first & 15;
|
|
817
|
+
if (type === 0) {
|
|
818
|
+
const t = bytes[pos++];
|
|
819
|
+
if (t === void 0) throw new Error("truncated type");
|
|
820
|
+
type = t;
|
|
821
|
+
}
|
|
822
|
+
if (fieldCode === 0) {
|
|
823
|
+
const f = bytes[pos++];
|
|
824
|
+
if (f === void 0) throw new Error("truncated field code");
|
|
825
|
+
fieldCode = f;
|
|
826
|
+
}
|
|
827
|
+
let valueStart = pos;
|
|
828
|
+
switch (type) {
|
|
829
|
+
case 1:
|
|
830
|
+
pos += 2;
|
|
831
|
+
break;
|
|
832
|
+
case 2:
|
|
833
|
+
pos += 4;
|
|
834
|
+
break;
|
|
835
|
+
case 5:
|
|
836
|
+
pos += 32;
|
|
837
|
+
break;
|
|
838
|
+
case 6: {
|
|
839
|
+
const head = bytes[pos];
|
|
840
|
+
if (head === void 0) throw new Error("truncated amount");
|
|
841
|
+
pos += (head & 128) !== 0 ? 48 : 8;
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
case 7:
|
|
845
|
+
case 8: {
|
|
846
|
+
const vl = readVl(bytes, pos);
|
|
847
|
+
valueStart = vl.next;
|
|
848
|
+
pos = vl.next + vl.length;
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
case 14:
|
|
852
|
+
while (bytes[pos] !== 225) {
|
|
853
|
+
if (pos >= bytes.length) throw new Error("unterminated inner object");
|
|
854
|
+
pos = parseField(bytes, pos).end;
|
|
855
|
+
}
|
|
856
|
+
pos += 1;
|
|
857
|
+
break;
|
|
858
|
+
case 15:
|
|
859
|
+
while (bytes[pos] !== 241) {
|
|
860
|
+
if (pos >= bytes.length) throw new Error("unterminated array");
|
|
861
|
+
pos = parseField(bytes, pos).end;
|
|
862
|
+
}
|
|
863
|
+
pos += 1;
|
|
864
|
+
break;
|
|
865
|
+
default: throw new Error("unsupported-field");
|
|
866
|
+
}
|
|
867
|
+
if (pos > bytes.length) throw new Error("truncated field");
|
|
868
|
+
return {
|
|
869
|
+
field: {
|
|
870
|
+
header: type << 4 | (fieldCode <= 15 ? fieldCode : 0),
|
|
871
|
+
value: bytes.slice(valueStart, pos),
|
|
872
|
+
raw: bytes.slice(start, pos)
|
|
873
|
+
},
|
|
874
|
+
end: pos
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
/** XRPL variable-length prefix. */
|
|
878
|
+
function readVl(bytes, pos) {
|
|
879
|
+
const b1 = bytes[pos];
|
|
880
|
+
if (b1 === void 0) throw new Error("truncated length");
|
|
881
|
+
if (b1 <= 192) return {
|
|
882
|
+
length: b1,
|
|
883
|
+
next: pos + 1
|
|
884
|
+
};
|
|
885
|
+
if (b1 <= 240) {
|
|
886
|
+
const b2 = bytes[pos + 1];
|
|
887
|
+
if (b2 === void 0) throw new Error("truncated length");
|
|
888
|
+
return {
|
|
889
|
+
length: 193 + (b1 - 193) * 256 + b2,
|
|
890
|
+
next: pos + 2
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
const b2 = bytes[pos + 1];
|
|
894
|
+
const b3 = bytes[pos + 2];
|
|
895
|
+
if (b2 === void 0 || b3 === void 0) throw new Error("truncated length");
|
|
896
|
+
return {
|
|
897
|
+
length: 12481 + (b1 - 241) * 65536 + b2 * 256 + b3,
|
|
898
|
+
next: pos + 3
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
//#endregion
|
|
902
|
+
export { PsbtInputType, bocRootHash, parsePsbt, verifyBtcMessageHeader, verifyCardanoSignature, verifyCosmosSignature, verifyEvmSignature, verifySignedPsbt, verifySolanaSignature, verifySuiSignature, verifyTonSignature, verifyTronSignature, verifyXrpSignature };
|
|
723
903
|
|
|
724
904
|
//# sourceMappingURL=verify.js.map
|