@thruputchain/client 0.0.0-stage → 0.25.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/LICENSE +201 -0
- package/README.md +935 -2
- package/dist/actions-CdFSUTO2.js +298 -0
- package/dist/actions-CdFSUTO2.js.map +1 -0
- package/dist/actions-DxJZ3yIv.cjs +357 -0
- package/dist/actions-DxJZ3yIv.cjs.map +1 -0
- package/dist/actions.cjs +19 -0
- package/dist/actions.d.cts +4 -0
- package/dist/actions.d.ts +4 -0
- package/dist/actions.js +3 -0
- package/dist/client-BxB6ktQd.d.cts +690 -0
- package/dist/client-BxB6ktQd.d.cts.map +1 -0
- package/dist/client-BxB6ktQd.d.ts +690 -0
- package/dist/client-BxB6ktQd.d.ts.map +1 -0
- package/dist/codec-B7HJjMzI.cjs +8190 -0
- package/dist/codec-B7HJjMzI.cjs.map +1 -0
- package/dist/codec-CX-19jac.js +8130 -0
- package/dist/codec-CX-19jac.js.map +1 -0
- package/dist/contract-BpxjDMHw.js +1105 -0
- package/dist/contract-BpxjDMHw.js.map +1 -0
- package/dist/contract-D0wCFcAN.cjs +1219 -0
- package/dist/contract-D0wCFcAN.cjs.map +1 -0
- package/dist/contract.cjs +58 -0
- package/dist/contract.d.cts +3 -0
- package/dist/contract.d.ts +3 -0
- package/dist/contract.js +2 -0
- package/dist/contracts.cjs +1050 -0
- package/dist/contracts.cjs.map +1 -0
- package/dist/contracts.d.cts +397 -0
- package/dist/contracts.d.cts.map +1 -0
- package/dist/contracts.d.ts +397 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +1030 -0
- package/dist/contracts.js.map +1 -0
- package/dist/dev_wallet-BXWK5KR6.cjs +530 -0
- package/dist/dev_wallet-BXWK5KR6.cjs.map +1 -0
- package/dist/dev_wallet-C9eMQROk.js +497 -0
- package/dist/dev_wallet-C9eMQROk.js.map +1 -0
- package/dist/domainSeparator-B_vU_zUD.cjs +102 -0
- package/dist/domainSeparator-B_vU_zUD.cjs.map +1 -0
- package/dist/domainSeparator-CBCvxIj-.js +79 -0
- package/dist/domainSeparator-CBCvxIj-.js.map +1 -0
- package/dist/execution-CRDyKu45.d.ts +227 -0
- package/dist/execution-CRDyKu45.d.ts.map +1 -0
- package/dist/execution-DyxaIG4v.d.cts +227 -0
- package/dist/execution-DyxaIG4v.d.cts.map +1 -0
- package/dist/hex-DIcaALXL.js +112 -0
- package/dist/hex-DIcaALXL.js.map +1 -0
- package/dist/hex-DkGpiZ5e.cjs +189 -0
- package/dist/hex-DkGpiZ5e.cjs.map +1 -0
- package/dist/index--5LsCotr.d.ts +192 -0
- package/dist/index--5LsCotr.d.ts.map +1 -0
- package/dist/index-B5KqSHeL.d.cts +192 -0
- package/dist/index-B5KqSHeL.d.cts.map +1 -0
- package/dist/index-BZ0O5jZG.d.cts +163 -0
- package/dist/index-BZ0O5jZG.d.cts.map +1 -0
- package/dist/index-BuPQcAK2.d.ts +23 -0
- package/dist/index-BuPQcAK2.d.ts.map +1 -0
- package/dist/index-ByNNqY7S.d.cts +83 -0
- package/dist/index-ByNNqY7S.d.cts.map +1 -0
- package/dist/index-C-M-4jMR.d.cts +263 -0
- package/dist/index-C-M-4jMR.d.cts.map +1 -0
- package/dist/index-C97zw2rk.d.ts +137 -0
- package/dist/index-C97zw2rk.d.ts.map +1 -0
- package/dist/index-CIHK7Ew9.d.cts +303 -0
- package/dist/index-CIHK7Ew9.d.cts.map +1 -0
- package/dist/index-CIHK7Ew9.d.ts +303 -0
- package/dist/index-CIHK7Ew9.d.ts.map +1 -0
- package/dist/index-CXuO2Zjx.d.ts +263 -0
- package/dist/index-CXuO2Zjx.d.ts.map +1 -0
- package/dist/index-DOEBWXY2.d.cts +137 -0
- package/dist/index-DOEBWXY2.d.cts.map +1 -0
- package/dist/index-DzrLv3EA.d.cts +82 -0
- package/dist/index-DzrLv3EA.d.cts.map +1 -0
- package/dist/index-DzrLv3EA.d.ts +82 -0
- package/dist/index-DzrLv3EA.d.ts.map +1 -0
- package/dist/index-fdTURpBk.d.ts +83 -0
- package/dist/index-fdTURpBk.d.ts.map +1 -0
- package/dist/index-sAzHHayu.d.ts +163 -0
- package/dist/index-sAzHHayu.d.ts.map +1 -0
- package/dist/index-uQqRk9Ww.d.cts +23 -0
- package/dist/index-uQqRk9Ww.d.cts.map +1 -0
- package/dist/index.cjs +478 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +173 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +231 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.cjs +101 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +2 -0
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +76 -0
- package/dist/provider.js.map +1 -0
- package/dist/readError-BVbfTMLv.cjs +604 -0
- package/dist/readError-BVbfTMLv.cjs.map +1 -0
- package/dist/readError-Dn_XN98x.js +551 -0
- package/dist/readError-Dn_XN98x.js.map +1 -0
- package/dist/readViews-BKJtE5J3.d.cts +594 -0
- package/dist/readViews-BKJtE5J3.d.cts.map +1 -0
- package/dist/readViews-C_FX8wby.d.ts +594 -0
- package/dist/readViews-C_FX8wby.d.ts.map +1 -0
- package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
- package/dist/sendInvocation-2EZanZZr.cjs +661 -0
- package/dist/sendInvocation-2EZanZZr.cjs.map +1 -0
- package/dist/sendInvocation-C4ruTC-9.js +505 -0
- package/dist/sendInvocation-C4ruTC-9.js.map +1 -0
- package/dist/sign-BewmV_EL.cjs +139 -0
- package/dist/sign-BewmV_EL.cjs.map +1 -0
- package/dist/sign-DVIRyW8Y.js +122 -0
- package/dist/sign-DVIRyW8Y.js.map +1 -0
- package/dist/sign-Ve0eetRO.d.ts +48 -0
- package/dist/sign-Ve0eetRO.d.ts.map +1 -0
- package/dist/sign-eUT0iGQG.d.cts +48 -0
- package/dist/sign-eUT0iGQG.d.cts.map +1 -0
- package/dist/signed-op.cjs +9 -0
- package/dist/signed-op.d.cts +3 -0
- package/dist/signed-op.d.ts +3 -0
- package/dist/signed-op.js +3 -0
- package/dist/signedOp-Bluo0OAd.cjs +183 -0
- package/dist/signedOp-Bluo0OAd.cjs.map +1 -0
- package/dist/signedOp-x4fakrr4.js +166 -0
- package/dist/signedOp-x4fakrr4.js.map +1 -0
- package/dist/signed_op-BzVbBgv4.js +154 -0
- package/dist/signed_op-BzVbBgv4.js.map +1 -0
- package/dist/signed_op-DFgQ2yFj.d.ts +58 -0
- package/dist/signed_op-DFgQ2yFj.d.ts.map +1 -0
- package/dist/signed_op-LwxrDud8.d.cts +58 -0
- package/dist/signed_op-LwxrDud8.d.cts.map +1 -0
- package/dist/signed_op-z_8fqAi1.cjs +175 -0
- package/dist/signed_op-z_8fqAi1.cjs.map +1 -0
- package/dist/signers-BFP84wJP.cjs +137 -0
- package/dist/signers-BFP84wJP.cjs.map +1 -0
- package/dist/signers-CzOSedwJ.js +120 -0
- package/dist/signers-CzOSedwJ.js.map +1 -0
- package/dist/signers.cjs +5 -0
- package/dist/signers.d.cts +3 -0
- package/dist/signers.d.ts +3 -0
- package/dist/signers.js +2 -0
- package/dist/size-506oTE28.js +91 -0
- package/dist/size-506oTE28.js.map +1 -0
- package/dist/size-OAFfOthl.cjs +108 -0
- package/dist/size-OAFfOthl.cjs.map +1 -0
- package/dist/transaction-CwkQxQOx.js +24 -0
- package/dist/transaction-CwkQxQOx.js.map +1 -0
- package/dist/transaction-DrSrCJ5y.cjs +47 -0
- package/dist/transaction-DrSrCJ5y.cjs.map +1 -0
- package/dist/transaction.cjs +13 -0
- package/dist/transaction.d.cts +3 -0
- package/dist/transaction.d.ts +3 -0
- package/dist/transaction.js +4 -0
- package/dist/transactionHash-CO9ajbvU.js +24 -0
- package/dist/transactionHash-CO9ajbvU.js.map +1 -0
- package/dist/transactionHash-D5yf4KoL.cjs +29 -0
- package/dist/transactionHash-D5yf4KoL.cjs.map +1 -0
- package/dist/transport-B-P16rs6.cjs +252 -0
- package/dist/transport-B-P16rs6.cjs.map +1 -0
- package/dist/transport-DqyoNtUy.js +234 -0
- package/dist/transport-DqyoNtUy.js.map +1 -0
- package/dist/transport.cjs +19 -0
- package/dist/transport.d.cts +3 -0
- package/dist/transport.d.ts +3 -0
- package/dist/transport.js +4 -0
- package/dist/types-BE40oD_Q.d.cts +18 -0
- package/dist/types-BE40oD_Q.d.cts.map +1 -0
- package/dist/types-BE40oD_Q.d.ts +18 -0
- package/dist/types-BE40oD_Q.d.ts.map +1 -0
- package/dist/validation-4w-vDGAi.cjs +543 -0
- package/dist/validation-4w-vDGAi.cjs.map +1 -0
- package/dist/validation-eXATmgO0.js +411 -0
- package/dist/validation-eXATmgO0.js.map +1 -0
- package/dist/wallet-Bthapk8i.cjs +709 -0
- package/dist/wallet-Bthapk8i.cjs.map +1 -0
- package/dist/wallet-CwWPYoHF.js +667 -0
- package/dist/wallet-CwWPYoHF.js.map +1 -0
- package/dist/wallet.cjs +27 -0
- package/dist/wallet.d.cts +3 -0
- package/dist/wallet.d.ts +3 -0
- package/dist/wallet.js +3 -0
- package/package.json +122 -4
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { t as PUBKEY_ACCOUNT } from "./domainSeparator-CBCvxIj-.js";
|
|
2
|
+
import { n as transactionSignaturePreimage, r as derivePublicKeyHash, t as pubkeySignatureEnvelopeBytes } from "./size-506oTE28.js";
|
|
3
|
+
import { g as toBase58, i as toHex0x, s as fixedFromBase58 } from "./hex-DIcaALXL.js";
|
|
4
|
+
import { t as hashSignedTransaction } from "./transactionHash-CO9ajbvU.js";
|
|
5
|
+
import { AuthClaimType, CryptographicScheme, codec, contractAddress, deserialize, ed25519PublicKey, fromHex, networkHash, serialize, sha256Hash } from "@thruputchain/protocol";
|
|
6
|
+
import { Point, verifyAsync } from "@noble/ed25519";
|
|
7
|
+
//#region src/derivation/pubkeyAccount.ts
|
|
8
|
+
/**
|
|
9
|
+
* Builds the preimage of a pubkey account's address from its key and nonce:
|
|
10
|
+
* `{ pubkey_hash: derivePublicKeyHash(pubkey), nonce }`.
|
|
11
|
+
*
|
|
12
|
+
* The preimage names the key by its scheme-inclusive hash for every scheme,
|
|
13
|
+
* Ed25519 included, so it is the same size whatever the key.
|
|
14
|
+
*/
|
|
15
|
+
function pubkeyAccountPreimage(pubkey, nonce = 0n) {
|
|
16
|
+
return {
|
|
17
|
+
pubkey_hash: derivePublicKeyHash(pubkey),
|
|
18
|
+
nonce
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Derives the on-chain address of a pubkey account from its preimage:
|
|
23
|
+
* `sha256( cxs(DomainSeparator("PubkeyAccount")) || cxs(preimage) )`.
|
|
24
|
+
*
|
|
25
|
+
* Mirrors `pubkey_account_address` in the Rust `thruput-domain-separator`
|
|
26
|
+
* crate; the two are pinned to each other by the golden vectors in
|
|
27
|
+
* `specs/test-vectors/domain-separator.json`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import {
|
|
32
|
+
* derivePubkeyAccountAddress,
|
|
33
|
+
* pubkeyAccountPreimage,
|
|
34
|
+
* } from "@thruputchain/client";
|
|
35
|
+
*
|
|
36
|
+
* const address = derivePubkeyAccountAddress(
|
|
37
|
+
* pubkeyAccountPreimage(signer.publicKey, 0n),
|
|
38
|
+
* );
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function derivePubkeyAccountAddress(preimage) {
|
|
42
|
+
return contractAddress(PUBKEY_ACCOUNT.hashObject(preimage, codec.PubkeyAccountPreimage));
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/provider/types.ts
|
|
46
|
+
/**
|
|
47
|
+
* A provider failure with a {@link WalletProviderErrorCode | stable numeric code}.
|
|
48
|
+
* Preserve `code` and a human-readable `message` across bridges; `instanceof` does
|
|
49
|
+
* not work across all realms. {@link parseWalletProviderError} reconstructs errors
|
|
50
|
+
* with recognized codes and messages of at most 1,024 characters.
|
|
51
|
+
*
|
|
52
|
+
* After submit starts, even failure may mean broadcast. Keep the previously saved
|
|
53
|
+
* hash and query its status on the original network instead of automatically
|
|
54
|
+
* preparing or signing a replacement transaction.
|
|
55
|
+
*/
|
|
56
|
+
var WalletProviderError = class extends Error {
|
|
57
|
+
code;
|
|
58
|
+
constructor(code, message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.code = code;
|
|
61
|
+
this.name = "WalletProviderError";
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/provider/validation.ts
|
|
66
|
+
/** Maximum decoded signed XDR size: 1,048,576 bytes (1 MiB). */
|
|
67
|
+
const MAX_TRANSACTION_BYTES = 1048576;
|
|
68
|
+
/**
|
|
69
|
+
* Maximum unsigned XDR size: 1,048,460 bytes. Providers must enforce this before
|
|
70
|
+
* requesting user approval. Reserves 116 bytes within {@link MAX_TRANSACTION_BYTES}
|
|
71
|
+
* for the Ed25519 pubkey envelope: the signature vector count, key ID, scheme,
|
|
72
|
+
* and 64-byte signature, plus the present `pubkey_claim_key` option holding the
|
|
73
|
+
* scheme-tagged 32-byte key.
|
|
74
|
+
*/
|
|
75
|
+
const MAX_UNSIGNED_TRANSACTION_BYTES = MAX_TRANSACTION_BYTES - pubkeySignatureEnvelopeBytes(CryptographicScheme.Ed25519);
|
|
76
|
+
/** Maximum accounts in one session. */
|
|
77
|
+
const MAX_WALLET_ACCOUNTS = 32;
|
|
78
|
+
/** Current native DefaultWallet execute call limit. */
|
|
79
|
+
const MAX_DEFAULT_WALLET_CALLS = 16;
|
|
80
|
+
/** Validate scoped DefaultWallet capabilities. Does not establish authorization. */
|
|
81
|
+
function parseWalletCapabilities(value) {
|
|
82
|
+
const data = record(value);
|
|
83
|
+
fields(data, [
|
|
84
|
+
"account",
|
|
85
|
+
"networkHash",
|
|
86
|
+
"atomicBatch"
|
|
87
|
+
]);
|
|
88
|
+
const account = parseWalletIdentifier(data.account);
|
|
89
|
+
const networkHash = parseWalletNetworkHash(data.networkHash);
|
|
90
|
+
if (data.atomicBatch === null) return {
|
|
91
|
+
account,
|
|
92
|
+
networkHash,
|
|
93
|
+
atomicBatch: null
|
|
94
|
+
};
|
|
95
|
+
const batch = record(data.atomicBatch);
|
|
96
|
+
fields(batch, ["maxCalls"]);
|
|
97
|
+
const maxCalls = batch.maxCalls;
|
|
98
|
+
if (typeof maxCalls !== "number" || !Number.isSafeInteger(maxCalls) || maxCalls < 1 || maxCalls > 16) invalid("Invalid DefaultWallet batch call limit");
|
|
99
|
+
return {
|
|
100
|
+
account,
|
|
101
|
+
networkHash,
|
|
102
|
+
atomicBatch: { maxCalls }
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function invalid(message) {
|
|
106
|
+
throw new WalletProviderError(-32602, message);
|
|
107
|
+
}
|
|
108
|
+
function record(value) {
|
|
109
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) invalid("Expected an object");
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
function fields(value, names) {
|
|
113
|
+
const keys = Object.keys(value);
|
|
114
|
+
if (keys.length !== names.length || !keys.every((key) => names.includes(key))) invalid("Unexpected or missing fields");
|
|
115
|
+
}
|
|
116
|
+
/** Validate an unprefixed, case-sensitive base58 address, public key, or hash. */
|
|
117
|
+
function parseWalletIdentifier(value) {
|
|
118
|
+
if (typeof value !== "string") invalid("Expected a 32-byte base58 identifier");
|
|
119
|
+
try {
|
|
120
|
+
fixedFromBase58(value, 32);
|
|
121
|
+
} catch {
|
|
122
|
+
invalid("Expected a 32-byte base58 identifier");
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
/** Validate a case-sensitive, unprefixed base58 network hash. */
|
|
127
|
+
function parseWalletNetworkHash(value) {
|
|
128
|
+
return parseWalletIdentifier(value);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validate and freeze an account snapshot, including a non-small-order, prime-order
|
|
132
|
+
* Ed25519 key and its derived address. The nonce is canonical decimal u64 account
|
|
133
|
+
* derivation data, not a transaction nonce. Rejects extra fields and noncanonical
|
|
134
|
+
* values rather than normalizing them; malformed input throws code -32602.
|
|
135
|
+
*/
|
|
136
|
+
function parseWalletAccount(value) {
|
|
137
|
+
const data = record(value);
|
|
138
|
+
fields(data, [
|
|
139
|
+
"address",
|
|
140
|
+
"publicKey",
|
|
141
|
+
"nonce"
|
|
142
|
+
]);
|
|
143
|
+
const address = parseWalletIdentifier(data.address);
|
|
144
|
+
const publicKey = parseWalletIdentifier(data.publicKey);
|
|
145
|
+
const nonce = data.nonce;
|
|
146
|
+
if (typeof nonce !== "string" || nonce.length > 20 || nonce.trim() !== nonce || !/^(0|[1-9][0-9]*)$/.test(nonce) || BigInt(nonce) > 18446744073709551615n) invalid("Expected a canonical decimal u64 account nonce");
|
|
147
|
+
const key = ed25519PublicKey(fixedFromBase58(publicKey, 32));
|
|
148
|
+
try {
|
|
149
|
+
const point = Point.fromBytes(key, false);
|
|
150
|
+
if (point.isSmallOrder() || !point.isTorsionFree()) invalid("Invalid Ed25519 public key");
|
|
151
|
+
} catch {
|
|
152
|
+
invalid("Invalid Ed25519 public key");
|
|
153
|
+
}
|
|
154
|
+
if (toBase58(derivePubkeyAccountAddress(pubkeyAccountPreimage({
|
|
155
|
+
scheme: CryptographicScheme.Ed25519,
|
|
156
|
+
ed25519: key
|
|
157
|
+
}, BigInt(nonce)))) !== address) invalid("Account address derivation mismatch");
|
|
158
|
+
return Object.freeze({
|
|
159
|
+
address,
|
|
160
|
+
publicKey,
|
|
161
|
+
nonce
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Strictly validate a session and return a frozen snapshot with frozen accounts.
|
|
166
|
+
* Requires a canonical network hash and at most {@link MAX_WALLET_ACCOUNTS} unique
|
|
167
|
+
* account addresses. Empty accounts are valid for an unauthorized origin; this
|
|
168
|
+
* parser does not enforce the nonempty result required by a successful `connect`.
|
|
169
|
+
*/
|
|
170
|
+
function parseWalletSession(value) {
|
|
171
|
+
const data = record(value);
|
|
172
|
+
fields(data, ["networkHash", "accounts"]);
|
|
173
|
+
const networkHash = parseWalletNetworkHash(data.networkHash);
|
|
174
|
+
const inputAccounts = data.accounts;
|
|
175
|
+
if (!Array.isArray(inputAccounts) || inputAccounts.length > 32) invalid("Expected at most 32 wallet accounts");
|
|
176
|
+
const accounts = Array.from(inputAccounts, parseWalletAccount);
|
|
177
|
+
if (new Set(accounts.map((account) => account.address)).size !== accounts.length) invalid("Duplicate wallet account");
|
|
178
|
+
return Object.freeze({
|
|
179
|
+
networkHash,
|
|
180
|
+
accounts: Object.freeze(accounts)
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** Validate bounded display metadata; never render provider names as HTML. */
|
|
184
|
+
function parseWalletProviderInfo(value) {
|
|
185
|
+
const data = record(value);
|
|
186
|
+
fields(data, [
|
|
187
|
+
"id",
|
|
188
|
+
"name",
|
|
189
|
+
"version"
|
|
190
|
+
]);
|
|
191
|
+
const { id, name, version } = data;
|
|
192
|
+
if (typeof id !== "string" || id.trim() !== id || !/^[a-zA-Z0-9._-]{1,64}$/.test(id)) invalid("Invalid provider ID");
|
|
193
|
+
if (typeof name !== "string" || name.length < 1 || name.length > 80 || name.trim() !== name || /[\u0000-\u001f\u007f-\u009f]/.test(name)) invalid("Invalid provider name");
|
|
194
|
+
if (version !== "2.0.0") invalid("Unsupported provider version");
|
|
195
|
+
return Object.freeze({
|
|
196
|
+
id,
|
|
197
|
+
name,
|
|
198
|
+
version
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Validate a provider's structural boundary and return the original live object.
|
|
203
|
+
* Preserves identity and method receivers; metadata is validated, not snapshotted.
|
|
204
|
+
* Unlike {@link parseWalletAccount} and {@link parseWalletSession}, this does not
|
|
205
|
+
* freeze the input. Checks versioned metadata and callable `request`/`on` members,
|
|
206
|
+
* not their behavior, permissions, returned values, or the provider's trustworthiness.
|
|
207
|
+
*/
|
|
208
|
+
function parseWalletProvider(value) {
|
|
209
|
+
const data = record(value);
|
|
210
|
+
parseWalletProviderInfo(data.info);
|
|
211
|
+
if (data.supportedMethods !== void 0 && (!Array.isArray(data.supportedMethods) || data.supportedMethods.length > 32 || Array.from(data.supportedMethods).some((method) => typeof method !== "string"))) invalid("Invalid optional provider methods");
|
|
212
|
+
if (typeof data.request !== "function" || typeof data.on !== "function") invalid("Invalid wallet provider methods");
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Reconstruct a serialized provider error, without relying on `instanceof`.
|
|
217
|
+
* Requires a recognized {@link WalletProviderErrorCode} and a message of at most
|
|
218
|
+
* 1,024 characters. Invalid errors throw a new error with code -32602.
|
|
219
|
+
*/
|
|
220
|
+
function parseWalletProviderError(value) {
|
|
221
|
+
const { code, message } = record(value);
|
|
222
|
+
if (![
|
|
223
|
+
4001,
|
|
224
|
+
4100,
|
|
225
|
+
4200,
|
|
226
|
+
4900,
|
|
227
|
+
4901,
|
|
228
|
+
-32602,
|
|
229
|
+
-32603,
|
|
230
|
+
-32002
|
|
231
|
+
].includes(code) || typeof message !== "string" || message.length > 1024) invalid("Invalid provider error");
|
|
232
|
+
return new WalletProviderError(code, message);
|
|
233
|
+
}
|
|
234
|
+
function transactionBytes(value, maxBytes) {
|
|
235
|
+
if (typeof value !== "string" || value.length > 2 + maxBytes * 2 || value.length <= 2 || value.length % 2 !== 0 || value.trim() !== value || !/^0x[0-9a-f]+$/.test(value)) invalid(`Expected canonical transaction hex of at most ${maxBytes} bytes`);
|
|
236
|
+
return fromHex(value.slice(2));
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Decode bounded canonical unsigned XDR, rejecting trailing or altered encodings.
|
|
240
|
+
* Accepts lowercase, even-length, 0x-prefixed hex within
|
|
241
|
+
* {@link MAX_UNSIGNED_TRANSACTION_BYTES}; providers must check this before approval.
|
|
242
|
+
* Does not establish account authorization; use {@link assertWalletTransaction}
|
|
243
|
+
* to check the transaction's account claim and enforce origin permission separately.
|
|
244
|
+
*/
|
|
245
|
+
function parseTransactionHex(value) {
|
|
246
|
+
const bytes = transactionBytes(value, MAX_UNSIGNED_TRANSACTION_BYTES);
|
|
247
|
+
try {
|
|
248
|
+
const tx = deserialize(bytes, codec.Transaction);
|
|
249
|
+
if (toHex0x(serialize(tx, codec.Transaction)) !== value) invalid("Noncanonical XDR");
|
|
250
|
+
return tx;
|
|
251
|
+
} catch {
|
|
252
|
+
invalid("Invalid canonical unsigned transaction XDR");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** Decode bounded canonical signed XDR; signature verification is separate. */
|
|
256
|
+
function parseSignedTransactionHex(value) {
|
|
257
|
+
const bytes = transactionBytes(value, MAX_TRANSACTION_BYTES);
|
|
258
|
+
try {
|
|
259
|
+
const signed = deserialize(bytes, codec.SignedTransaction);
|
|
260
|
+
if (toHex0x(serialize(signed, codec.SignedTransaction)) !== value) invalid("Noncanonical XDR");
|
|
261
|
+
return signed;
|
|
262
|
+
} catch {
|
|
263
|
+
invalid("Invalid canonical signed transaction XDR");
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Parse the exact request union into a new request object, including bounded,
|
|
268
|
+
* canonical XDR. Unknown methods fail with 4200; malformed known requests fail
|
|
269
|
+
* with -32602. This validates input, not origin permission or prior approval.
|
|
270
|
+
* Bridges must bound raw messages before JSON parsing: at most 2,096,922 unsigned
|
|
271
|
+
* or 2,097,154 signed transaction-hex characters, including 0x.
|
|
272
|
+
*/
|
|
273
|
+
function parseProviderRequest(value) {
|
|
274
|
+
const data = record(value);
|
|
275
|
+
const method = data.method;
|
|
276
|
+
if (typeof method !== "string") invalid("Expected a request method");
|
|
277
|
+
switch (method) {
|
|
278
|
+
case "connect":
|
|
279
|
+
case "getSession":
|
|
280
|
+
case "disconnect":
|
|
281
|
+
fields(data, ["method"]);
|
|
282
|
+
return { method };
|
|
283
|
+
case "getCapabilities": {
|
|
284
|
+
fields(data, ["method", "params"]);
|
|
285
|
+
const params = record(data.params);
|
|
286
|
+
fields(params, ["account", "networkHash"]);
|
|
287
|
+
return {
|
|
288
|
+
method,
|
|
289
|
+
params: {
|
|
290
|
+
account: parseWalletIdentifier(params.account),
|
|
291
|
+
networkHash: parseWalletNetworkHash(params.networkHash)
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
case "signTransaction":
|
|
296
|
+
case "submitTransaction": {
|
|
297
|
+
fields(data, ["method", "params"]);
|
|
298
|
+
const params = record(data.params);
|
|
299
|
+
fields(params, [
|
|
300
|
+
"account",
|
|
301
|
+
"networkHash",
|
|
302
|
+
method === "signTransaction" ? "transaction" : "signedTransaction"
|
|
303
|
+
]);
|
|
304
|
+
const account = parseWalletIdentifier(params.account);
|
|
305
|
+
const networkHash = parseWalletNetworkHash(params.networkHash);
|
|
306
|
+
if (method === "signTransaction") {
|
|
307
|
+
const transaction = params.transaction;
|
|
308
|
+
parseTransactionHex(transaction);
|
|
309
|
+
return {
|
|
310
|
+
method,
|
|
311
|
+
params: {
|
|
312
|
+
account,
|
|
313
|
+
networkHash,
|
|
314
|
+
transaction
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
const signedTransaction = params.signedTransaction;
|
|
319
|
+
parseSignedTransactionHex(signedTransaction);
|
|
320
|
+
return {
|
|
321
|
+
method,
|
|
322
|
+
params: {
|
|
323
|
+
account,
|
|
324
|
+
networkHash,
|
|
325
|
+
signedTransaction
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
default: throw new WalletProviderError(4200, "Unsupported wallet provider method");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Validate a signing response's wire structure and return a new result object.
|
|
334
|
+
* Checks canonical signed XDR and hash encoding, not signature, hash correctness,
|
|
335
|
+
* or approval. Use {@link verifySignTransactionResult} for cryptographic validation.
|
|
336
|
+
*/
|
|
337
|
+
function parseSignTransactionResult(value) {
|
|
338
|
+
const data = record(value);
|
|
339
|
+
fields(data, ["signedTransaction", "hash"]);
|
|
340
|
+
const { signedTransaction, hash } = data;
|
|
341
|
+
parseSignedTransactionHex(signedTransaction);
|
|
342
|
+
return {
|
|
343
|
+
signedTransaction,
|
|
344
|
+
hash: parseWalletIdentifier(hash)
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Validate a submission response's hash encoding and return a new result object.
|
|
349
|
+
* Does not compare the hash to approved bytes or confirm broadcast or execution.
|
|
350
|
+
*/
|
|
351
|
+
function parseSubmitTransactionResult(value) {
|
|
352
|
+
const data = record(value);
|
|
353
|
+
fields(data, ["hash"]);
|
|
354
|
+
return { hash: parseWalletIdentifier(data.hash) };
|
|
355
|
+
}
|
|
356
|
+
/** Require the root address and complete pubkey claim to match a wire account. */
|
|
357
|
+
function assertWalletTransaction(tx, account) {
|
|
358
|
+
const expected = parseWalletAccount(account);
|
|
359
|
+
const claim = tx.auth_claim;
|
|
360
|
+
if (toBase58(tx.invocation.invoked_address) !== expected.address || claim.claim_type !== AuthClaimType.kPubkeySignature || toHex0x(claim.pubkey_preimage.pubkey_hash) !== toHex0x(derivePublicKeyHash(walletPublicKey(expected))) || claim.pubkey_preimage.nonce !== BigInt(expected.nonce)) throw new WalletProviderError(4100, "Transaction does not authorize the selected wallet account");
|
|
361
|
+
}
|
|
362
|
+
function walletPublicKey(account) {
|
|
363
|
+
return {
|
|
364
|
+
scheme: CryptographicScheme.Ed25519,
|
|
365
|
+
ed25519: ed25519PublicKey(fixedFromBase58(account.publicKey, 32))
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Verify unchanged XDR, a single strict network-bound signature, and receipt hash.
|
|
370
|
+
* Requires the exact unsigned transaction bytes and matching root address/pubkey
|
|
371
|
+
* claim, and an attached `pubkey_claim_key` equal to the account's Ed25519 key.
|
|
372
|
+
* The signature must be Ed25519 with public-key ID zero, verified over
|
|
373
|
+
* `transactionSignaturePreimage(networkHash, tx)` with ZIP-215 disabled and both
|
|
374
|
+
* key and signature point R non-small-order and prime-order. The hash is SHA-256
|
|
375
|
+
* of unsigned XDR, excluding signatures and network.
|
|
376
|
+
*
|
|
377
|
+
* @param networkHash - A 32-byte base58 identifier from the authorized session.
|
|
378
|
+
* @returns A frozen verified result. This does not establish origin permission
|
|
379
|
+
* or a retained approval to submit; the provider must enforce both separately.
|
|
380
|
+
*
|
|
381
|
+
* @remarks
|
|
382
|
+
* Requires Web Crypto (HTTPS or localhost in browsers). Invalid signing results
|
|
383
|
+
* throw code -32603; invalid expected inputs fail their boundary validation first.
|
|
384
|
+
*
|
|
385
|
+
* @see https://docs.thruput.network/tools/wallet-provider/
|
|
386
|
+
*/
|
|
387
|
+
async function verifySignTransactionResult(value, transaction, account, networkHash$1) {
|
|
388
|
+
const expected = parseWalletAccount(account);
|
|
389
|
+
const network = networkHash(sha256Hash(fixedFromBase58(parseWalletNetworkHash(networkHash$1), 32)));
|
|
390
|
+
const tx = parseTransactionHex(transaction);
|
|
391
|
+
assertWalletTransaction(tx, expected);
|
|
392
|
+
try {
|
|
393
|
+
const result = parseSignTransactionResult(value);
|
|
394
|
+
const signed = parseSignedTransactionHex(result.signedTransaction);
|
|
395
|
+
if (toHex0x(serialize(signed.tx, codec.Transaction)) !== transaction) throw new Error("Provider altered unsigned transaction bytes");
|
|
396
|
+
const signature = signed.signatures[0];
|
|
397
|
+
if (signed.signatures.length !== 1 || !signature || signature.public_key_id !== 0n || signature.signature.scheme !== CryptographicScheme.Ed25519) throw new Error("Expected one Ed25519 signature with public-key ID zero");
|
|
398
|
+
const claimKey = signed.pubkey_claim_key;
|
|
399
|
+
if (!claimKey || claimKey.scheme !== CryptographicScheme.Ed25519 || toBase58(claimKey.ed25519) !== expected.publicKey) throw new Error("Expected the account's Ed25519 key as pubkey_claim_key");
|
|
400
|
+
const r = Point.fromBytes(signature.signature.ed25519.subarray(0, 32), false);
|
|
401
|
+
if (r.isSmallOrder() || !r.isTorsionFree() || !await verifyAsync(signature.signature.ed25519, transactionSignaturePreimage(network, tx), fixedFromBase58(expected.publicKey, 32), { zip215: false })) throw new Error("Invalid provider transaction signature");
|
|
402
|
+
if (result.hash !== toBase58(hashSignedTransaction(signed))) throw new Error("Provider transaction hash mismatch");
|
|
403
|
+
return Object.freeze(result);
|
|
404
|
+
} catch {
|
|
405
|
+
throw new WalletProviderError(-32603, "Invalid provider signing result: bytes, signature, or hash mismatch");
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
//#endregion
|
|
409
|
+
export { pubkeyAccountPreimage as S, parseWalletProviderInfo as _, assertWalletTransaction as a, WalletProviderError as b, parseSignedTransactionHex as c, parseWalletAccount as d, parseWalletCapabilities as f, parseWalletProviderError as g, parseWalletProvider as h, MAX_WALLET_ACCOUNTS as i, parseSubmitTransactionResult as l, parseWalletNetworkHash as m, MAX_TRANSACTION_BYTES as n, parseProviderRequest as o, parseWalletIdentifier as p, MAX_UNSIGNED_TRANSACTION_BYTES as r, parseSignTransactionResult as s, MAX_DEFAULT_WALLET_CALLS as t, parseTransactionHex as u, parseWalletSession as v, derivePubkeyAccountAddress as x, verifySignTransactionResult as y };
|
|
410
|
+
|
|
411
|
+
//# sourceMappingURL=validation-eXATmgO0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-eXATmgO0.js","names":["toNetworkHash","networkHash"],"sources":["../src/derivation/pubkeyAccount.ts","../src/provider/types.ts","../src/provider/validation.ts"],"sourcesContent":["import { codec, contractAddress } from \"@thruputchain/protocol\";\nimport type {\n ContractAddress,\n PubkeyAccountPreimage,\n PublicKey,\n} from \"@thruputchain/protocol\";\nimport { PUBKEY_ACCOUNT } from \"./domainSeparator.js\";\nimport { derivePublicKeyHash } from \"./publicKeyHash.js\";\n\n/**\n * Builds the preimage of a pubkey account's address from its key and nonce:\n * `{ pubkey_hash: derivePublicKeyHash(pubkey), nonce }`.\n *\n * The preimage names the key by its scheme-inclusive hash for every scheme,\n * Ed25519 included, so it is the same size whatever the key.\n */\nexport function pubkeyAccountPreimage(\n pubkey: PublicKey,\n nonce: bigint = 0n,\n): PubkeyAccountPreimage {\n return { pubkey_hash: derivePublicKeyHash(pubkey), nonce };\n}\n\n/**\n * Derives the on-chain address of a pubkey account from its preimage:\n * `sha256( cxs(DomainSeparator(\"PubkeyAccount\")) || cxs(preimage) )`.\n *\n * Mirrors `pubkey_account_address` in the Rust `thruput-domain-separator`\n * crate; the two are pinned to each other by the golden vectors in\n * `specs/test-vectors/domain-separator.json`.\n *\n * @example\n * ```ts\n * import {\n * derivePubkeyAccountAddress,\n * pubkeyAccountPreimage,\n * } from \"@thruputchain/client\";\n *\n * const address = derivePubkeyAccountAddress(\n * pubkeyAccountPreimage(signer.publicKey, 0n),\n * );\n * ```\n */\nexport function derivePubkeyAccountAddress(\n preimage: PubkeyAccountPreimage,\n): ContractAddress {\n return contractAddress(\n PUBKEY_ACCOUNT.hashObject(preimage, codec.PubkeyAccountPreimage),\n );\n}\n","/** Public identity advertised by a version 2 provider. Not an attestation. */\nexport interface WalletProviderInfo {\n /** Stable discovery ID: 1–64 ASCII letters, digits, dots, underscores, or hyphens. */\n id: string;\n /** Display text: 1–80 characters, without controls or surrounding whitespace. */\n name: string;\n /** Supported wire contract version. */\n version: \"2.0.0\";\n}\n\n/** Wire pubkey account: unprefixed base58 and a decimal u64 derivation nonce. */\nexport interface WalletAccount {\n /** Derived pubkey account address: 32 bytes of case-sensitive base58. */\n address: string;\n /** Non-small-order, prime-order Ed25519 key in the same 32-byte base58 format. */\n publicKey: string;\n /** Canonical decimal u64 account-derivation nonce, not a transaction nonce. */\n nonce: string;\n}\n\n/** Origin-authorized accounts on a network identified by a 32-byte base58 hash. */\nexport interface WalletSession {\n /** Current network identity, retained even when the origin has no permission. */\n networkHash: string;\n /** At most 32 unique addresses; empty for a disconnected or unauthorized origin. */\n accounts: readonly WalletAccount[];\n}\n\n/** Non-interactive execution capabilities for one authorized account and network. */\nexport interface WalletCapabilities {\n /** Canonical account address used in the capability request. */\n account: string;\n /** Network identity: unprefixed, case-sensitive 32-byte base58. */\n networkHash: string;\n /** Ordered, all-or-nothing DefaultWallet calls; null means unsupported. */\n atomicBatch: { maxCalls: number } | null;\n}\n\n/**\n * The complete provider request surface. Requests accept exactly the fields shown.\n * See {@link WalletProvider.request} for each method's result and permission rules.\n *\n * Signing parameters select an authorized account address and the current session's\n * network hash (unprefixed, case-sensitive base58). Transaction payloads are\n * lowercase, even-length, 0x-prefixed canonical classic XDR, with no trailing bytes.\n * Providers must enforce {@link MAX_UNSIGNED_TRANSACTION_BYTES} before user approval;\n * signed payloads are bounded by {@link MAX_TRANSACTION_BYTES}.\n *\n * Signing never broadcasts. Submission requires the exact signed bytes previously\n * approved for the trusted caller origin, account, and network. Providers must clear\n * approvals on session changes or disconnect and recheck authorization before signing\n * or broadcasting. Page-supplied parameters cannot establish the caller's origin.\n *\n * @see https://docs.thruput.network/tools/wallet-provider/\n */\nexport type ProviderRequest =\n | { method: \"connect\" }\n | { method: \"getSession\" }\n | { method: \"disconnect\" }\n | {\n method: \"getCapabilities\";\n params: { account: string; networkHash: string };\n }\n | {\n method: \"signTransaction\";\n params: { account: string; networkHash: string; transaction: string };\n }\n | {\n method: \"submitTransaction\";\n params: {\n account: string;\n networkHash: string;\n signedTransaction: string;\n };\n };\n\n/** Approved signed XDR and the canonical RPC transaction/receipt hash. */\nexport interface SignTransactionResult {\n /** Canonical signed XDR preserving the approved unsigned bytes, with one signature. */\n signedTransaction: string;\n /** Base58 SHA-256 of unsigned transaction XDR; excludes signatures and network. */\n hash: string;\n}\n\n/** Broadcast acknowledgement, not an execution receipt. */\nexport interface SubmitTransactionResult {\n /** The previously approved transaction hash; query its receipt on the original network. */\n hash: string;\n}\n\n/**\n * Framework- and transport-neutral, origin-scoped wallet interface.\n * Validate unknown results with the matching parser before using them.\n *\n * @see https://docs.thruput.network/tools/wallet-provider/\n * @see https://docs.thruput.network/tools/wallet-integration/\n */\nexport interface WalletProvider {\n info: WalletProviderInfo;\n /** Optional request extensions. Absence means legacy single-call behavior. */\n supportedMethods?: readonly string[];\n /**\n * Send a request across the wallet boundary. The result is unknown until validated.\n *\n * | Method | Result | Permission and behavior |\n * | --- | --- | --- |\n * | `connect` | {@link WalletSession} | Request origin-scoped permission through wallet UI; reject on refusal. Success has at least one authorized account. |\n * | `getSession` | {@link WalletSession} | Non-interactive snapshot; never prompt or grant access. Unauthorized origins see empty accounts and the current network hash. |\n * | `disconnect` | `null` | Idempotently revoke this origin's permission and pending approvals. |\n * | `getCapabilities` | {@link WalletCapabilities} | Non-interactive; requires an authorized account on the requested network. Older providers return 4200. |\n * | `signTransaction` | {@link SignTransactionResult} | Approve and sign the exact unsigned transaction; never broadcast. |\n * | `submitTransaction` | {@link SubmitTransactionResult} | Broadcast only exact previously approved signed bytes; acknowledgement is not an execution receipt. |\n *\n * Changes caused by connect/disconnect must reach page-facing listeners before the\n * request resolves, including across bridges with separate response/event paths.\n */\n request(request: ProviderRequest): Promise<unknown>;\n /**\n * Subscribe to full session snapshots for changes to accounts, authorization,\n * account metadata, or network, including disconnect. Subscription itself emits\n * no snapshot; use `getSession` to read one. See {@link request} for event ordering.\n *\n * @returns An idempotent unsubscribe function.\n */\n on(event: \"change\", listener: (session: WalletSession) => void): () => void;\n}\n\n/**\n * Stable provider error codes, including JSON-RPC-style request failures.\n *\n * | Code | Meaning |\n * | --- | --- |\n * | 4001 | User rejected the request. |\n * | 4100 | Origin/account unauthorized, stale session, or no matching approval. |\n * | 4200 | Unsupported method. |\n * | 4900 | Provider disconnected or transport unavailable. |\n * | 4901 | Requested network does not match. |\n * | -32602 | Invalid parameters, noncanonical encoding, or exceeded input limits. |\n * | -32603 | Internal error or invalid provider result. |\n * | -32002 | Another operation is pending. |\n */\nexport type WalletProviderErrorCode =\n | 4001\n | 4100\n | 4200\n | 4900\n | 4901\n | -32602\n | -32603\n | -32002;\n\n/**\n * A provider failure with a {@link WalletProviderErrorCode | stable numeric code}.\n * Preserve `code` and a human-readable `message` across bridges; `instanceof` does\n * not work across all realms. {@link parseWalletProviderError} reconstructs errors\n * with recognized codes and messages of at most 1,024 characters.\n *\n * After submit starts, even failure may mean broadcast. Keep the previously saved\n * hash and query its status on the original network instead of automatically\n * preparing or signing a replacement transaction.\n */\nexport class WalletProviderError extends Error {\n constructor(\n readonly code: WalletProviderErrorCode,\n message: string,\n ) {\n super(message);\n this.name = \"WalletProviderError\";\n }\n}\n","import {\n AuthClaimType,\n CryptographicScheme,\n codec,\n deserialize,\n ed25519PublicKey,\n fromHex,\n networkHash as toNetworkHash,\n serialize,\n sha256Hash,\n type PublicKey,\n type Transaction,\n type SignedTransaction,\n} from \"@thruputchain/protocol\";\nimport { Point, verifyAsync } from \"@noble/ed25519\";\nimport { toHex0x } from \"../actions/hex.js\";\nimport { fixedFromBase58, toBase58 } from \"../encoding.js\";\nimport {\n derivePubkeyAccountAddress,\n pubkeyAccountPreimage,\n} from \"../derivation/pubkeyAccount.js\";\nimport { derivePublicKeyHash } from \"../derivation/publicKeyHash.js\";\nimport { hashSignedTransaction } from \"../derivation/transactionHash.js\";\nimport { transactionSignaturePreimage } from \"../transaction/preimage.js\";\nimport { pubkeySignatureEnvelopeBytes } from \"../transaction/size.js\";\nimport {\n WalletProviderError,\n type WalletProviderErrorCode,\n type WalletAccount,\n type WalletSession,\n type WalletCapabilities,\n type WalletProvider,\n type WalletProviderInfo,\n type ProviderRequest,\n type SignTransactionResult,\n type SubmitTransactionResult,\n} from \"./types.js\";\n\n/** Maximum decoded signed XDR size: 1,048,576 bytes (1 MiB). */\nexport const MAX_TRANSACTION_BYTES = 1_048_576;\n/**\n * Maximum unsigned XDR size: 1,048,460 bytes. Providers must enforce this before\n * requesting user approval. Reserves 116 bytes within {@link MAX_TRANSACTION_BYTES}\n * for the Ed25519 pubkey envelope: the signature vector count, key ID, scheme,\n * and 64-byte signature, plus the present `pubkey_claim_key` option holding the\n * scheme-tagged 32-byte key.\n */\nexport const MAX_UNSIGNED_TRANSACTION_BYTES =\n MAX_TRANSACTION_BYTES -\n pubkeySignatureEnvelopeBytes(CryptographicScheme.Ed25519);\n/** Maximum accounts in one session. */\nexport const MAX_WALLET_ACCOUNTS = 32;\n/** Current native DefaultWallet execute call limit. */\nexport const MAX_DEFAULT_WALLET_CALLS = 16;\n\n/** Validate scoped DefaultWallet capabilities. Does not establish authorization. */\nexport function parseWalletCapabilities(value: unknown): WalletCapabilities {\n const data = record(value);\n fields(data, [\"account\", \"networkHash\", \"atomicBatch\"]);\n const account = parseWalletIdentifier(data.account);\n const networkHash = parseWalletNetworkHash(data.networkHash);\n if (data.atomicBatch === null)\n return { account, networkHash, atomicBatch: null };\n const batch = record(data.atomicBatch);\n fields(batch, [\"maxCalls\"]);\n const maxCalls = batch.maxCalls;\n if (\n typeof maxCalls !== \"number\" ||\n !Number.isSafeInteger(maxCalls) ||\n maxCalls < 1 ||\n maxCalls > MAX_DEFAULT_WALLET_CALLS\n )\n invalid(\"Invalid DefaultWallet batch call limit\");\n return { account, networkHash, atomicBatch: { maxCalls } };\n}\n\nfunction invalid(message: string): never {\n throw new WalletProviderError(-32602, message);\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n invalid(\"Expected an object\");\n }\n return value as Record<string, unknown>;\n}\n\nfunction fields(\n value: Record<string, unknown>,\n names: readonly string[],\n): void {\n const keys = Object.keys(value);\n if (\n keys.length !== names.length ||\n !keys.every((key) => names.includes(key))\n ) {\n invalid(\"Unexpected or missing fields\");\n }\n}\n\n/** Validate an unprefixed, case-sensitive base58 address, public key, or hash. */\nexport function parseWalletIdentifier(value: unknown): string {\n if (typeof value !== \"string\")\n invalid(\"Expected a 32-byte base58 identifier\");\n try {\n fixedFromBase58(value, 32);\n } catch {\n invalid(\"Expected a 32-byte base58 identifier\");\n }\n return value;\n}\n\n/** Validate a case-sensitive, unprefixed base58 network hash. */\nexport function parseWalletNetworkHash(value: unknown): string {\n return parseWalletIdentifier(value);\n}\n\n/**\n * Validate and freeze an account snapshot, including a non-small-order, prime-order\n * Ed25519 key and its derived address. The nonce is canonical decimal u64 account\n * derivation data, not a transaction nonce. Rejects extra fields and noncanonical\n * values rather than normalizing them; malformed input throws code -32602.\n */\nexport function parseWalletAccount(value: unknown): WalletAccount {\n const data = record(value);\n fields(data, [\"address\", \"publicKey\", \"nonce\"]);\n const address = parseWalletIdentifier(data.address);\n const publicKey = parseWalletIdentifier(data.publicKey);\n const nonce = data.nonce;\n if (\n typeof nonce !== \"string\" ||\n nonce.length > 20 ||\n nonce.trim() !== nonce ||\n !/^(0|[1-9][0-9]*)$/.test(nonce) ||\n BigInt(nonce) > 0xffff_ffff_ffff_ffffn\n ) {\n invalid(\"Expected a canonical decimal u64 account nonce\");\n }\n const key = ed25519PublicKey(fixedFromBase58(publicKey, 32));\n try {\n const point = Point.fromBytes(key, false);\n if (point.isSmallOrder() || !point.isTorsionFree()) {\n invalid(\"Invalid Ed25519 public key\");\n }\n } catch {\n invalid(\"Invalid Ed25519 public key\");\n }\n const derived = derivePubkeyAccountAddress(\n pubkeyAccountPreimage(\n { scheme: CryptographicScheme.Ed25519, ed25519: key },\n BigInt(nonce),\n ),\n );\n if (toBase58(derived) !== address)\n invalid(\"Account address derivation mismatch\");\n return Object.freeze({ address, publicKey, nonce });\n}\n\n/**\n * Strictly validate a session and return a frozen snapshot with frozen accounts.\n * Requires a canonical network hash and at most {@link MAX_WALLET_ACCOUNTS} unique\n * account addresses. Empty accounts are valid for an unauthorized origin; this\n * parser does not enforce the nonempty result required by a successful `connect`.\n */\nexport function parseWalletSession(value: unknown): WalletSession {\n const data = record(value);\n fields(data, [\"networkHash\", \"accounts\"]);\n const networkHash = parseWalletNetworkHash(data.networkHash);\n const inputAccounts = data.accounts;\n if (\n !Array.isArray(inputAccounts) ||\n inputAccounts.length > MAX_WALLET_ACCOUNTS\n ) {\n invalid(\"Expected at most 32 wallet accounts\");\n }\n const accounts = Array.from(inputAccounts, parseWalletAccount);\n if (\n new Set(accounts.map((account) => account.address)).size !== accounts.length\n ) {\n invalid(\"Duplicate wallet account\");\n }\n return Object.freeze({ networkHash, accounts: Object.freeze(accounts) });\n}\n\n/** Validate bounded display metadata; never render provider names as HTML. */\nexport function parseWalletProviderInfo(value: unknown): WalletProviderInfo {\n const data = record(value);\n fields(data, [\"id\", \"name\", \"version\"]);\n const { id, name, version } = data;\n if (\n typeof id !== \"string\" ||\n id.trim() !== id ||\n !/^[a-zA-Z0-9._-]{1,64}$/.test(id)\n ) {\n invalid(\"Invalid provider ID\");\n }\n if (\n typeof name !== \"string\" ||\n name.length < 1 ||\n name.length > 80 ||\n name.trim() !== name ||\n /[\\u0000-\\u001f\\u007f-\\u009f]/.test(name)\n ) {\n invalid(\"Invalid provider name\");\n }\n if (version !== \"2.0.0\") invalid(\"Unsupported provider version\");\n return Object.freeze({ id, name, version });\n}\n\n/**\n * Validate a provider's structural boundary and return the original live object.\n * Preserves identity and method receivers; metadata is validated, not snapshotted.\n * Unlike {@link parseWalletAccount} and {@link parseWalletSession}, this does not\n * freeze the input. Checks versioned metadata and callable `request`/`on` members,\n * not their behavior, permissions, returned values, or the provider's trustworthiness.\n */\nexport function parseWalletProvider(value: unknown): WalletProvider {\n const data = record(value);\n parseWalletProviderInfo(data.info);\n if (\n data.supportedMethods !== undefined &&\n (!Array.isArray(data.supportedMethods) ||\n data.supportedMethods.length > 32 ||\n Array.from(data.supportedMethods).some(\n (method) => typeof method !== \"string\",\n ))\n )\n invalid(\"Invalid optional provider methods\");\n if (typeof data.request !== \"function\" || typeof data.on !== \"function\") {\n invalid(\"Invalid wallet provider methods\");\n }\n return value as WalletProvider;\n}\n\n/**\n * Reconstruct a serialized provider error, without relying on `instanceof`.\n * Requires a recognized {@link WalletProviderErrorCode} and a message of at most\n * 1,024 characters. Invalid errors throw a new error with code -32602.\n */\nexport function parseWalletProviderError(value: unknown): WalletProviderError {\n const { code, message } = record(value);\n const codes: readonly unknown[] = [\n 4001, 4100, 4200, 4900, 4901, -32602, -32603, -32002,\n ];\n if (\n !codes.includes(code) ||\n typeof message !== \"string\" ||\n message.length > 1024\n ) {\n invalid(\"Invalid provider error\");\n }\n return new WalletProviderError(code as WalletProviderErrorCode, message);\n}\n\nfunction transactionBytes(value: unknown, maxBytes: number): Uint8Array {\n if (\n typeof value !== \"string\" ||\n value.length > 2 + maxBytes * 2 ||\n value.length <= 2 ||\n value.length % 2 !== 0 ||\n value.trim() !== value ||\n !/^0x[0-9a-f]+$/.test(value)\n ) {\n invalid(`Expected canonical transaction hex of at most ${maxBytes} bytes`);\n }\n return fromHex(value.slice(2));\n}\n\n/**\n * Decode bounded canonical unsigned XDR, rejecting trailing or altered encodings.\n * Accepts lowercase, even-length, 0x-prefixed hex within\n * {@link MAX_UNSIGNED_TRANSACTION_BYTES}; providers must check this before approval.\n * Does not establish account authorization; use {@link assertWalletTransaction}\n * to check the transaction's account claim and enforce origin permission separately.\n */\nexport function parseTransactionHex(value: unknown): Transaction {\n const bytes = transactionBytes(value, MAX_UNSIGNED_TRANSACTION_BYTES);\n try {\n const tx = deserialize(bytes, codec.Transaction);\n if (toHex0x(serialize(tx, codec.Transaction)) !== value)\n invalid(\"Noncanonical XDR\");\n return tx;\n } catch {\n invalid(\"Invalid canonical unsigned transaction XDR\");\n }\n}\n\n/** Decode bounded canonical signed XDR; signature verification is separate. */\nexport function parseSignedTransactionHex(value: unknown): SignedTransaction {\n const bytes = transactionBytes(value, MAX_TRANSACTION_BYTES);\n try {\n const signed = deserialize(bytes, codec.SignedTransaction);\n if (toHex0x(serialize(signed, codec.SignedTransaction)) !== value)\n invalid(\"Noncanonical XDR\");\n return signed;\n } catch {\n invalid(\"Invalid canonical signed transaction XDR\");\n }\n}\n\n/**\n * Parse the exact request union into a new request object, including bounded,\n * canonical XDR. Unknown methods fail with 4200; malformed known requests fail\n * with -32602. This validates input, not origin permission or prior approval.\n * Bridges must bound raw messages before JSON parsing: at most 2,096,922 unsigned\n * or 2,097,154 signed transaction-hex characters, including 0x.\n */\nexport function parseProviderRequest(value: unknown): ProviderRequest {\n const data = record(value);\n const method = data.method;\n if (typeof method !== \"string\") invalid(\"Expected a request method\");\n switch (method) {\n case \"connect\":\n case \"getSession\":\n case \"disconnect\":\n fields(data, [\"method\"]);\n return { method };\n case \"getCapabilities\": {\n fields(data, [\"method\", \"params\"]);\n const params = record(data.params);\n fields(params, [\"account\", \"networkHash\"]);\n return {\n method,\n params: {\n account: parseWalletIdentifier(params.account),\n networkHash: parseWalletNetworkHash(params.networkHash),\n },\n };\n }\n case \"signTransaction\":\n case \"submitTransaction\": {\n fields(data, [\"method\", \"params\"]);\n const params = record(data.params);\n const payload =\n method === \"signTransaction\" ? \"transaction\" : \"signedTransaction\";\n fields(params, [\"account\", \"networkHash\", payload]);\n const account = parseWalletIdentifier(params.account);\n const networkHash = parseWalletNetworkHash(params.networkHash);\n if (method === \"signTransaction\") {\n const transaction = params.transaction;\n parseTransactionHex(transaction);\n return {\n method,\n params: {\n account,\n networkHash,\n transaction: transaction as string,\n },\n };\n }\n const signedTransaction = params.signedTransaction;\n parseSignedTransactionHex(signedTransaction);\n return {\n method,\n params: {\n account,\n networkHash,\n signedTransaction: signedTransaction as string,\n },\n };\n }\n default:\n throw new WalletProviderError(4200, \"Unsupported wallet provider method\");\n }\n}\n\n/**\n * Validate a signing response's wire structure and return a new result object.\n * Checks canonical signed XDR and hash encoding, not signature, hash correctness,\n * or approval. Use {@link verifySignTransactionResult} for cryptographic validation.\n */\nexport function parseSignTransactionResult(\n value: unknown,\n): SignTransactionResult {\n const data = record(value);\n fields(data, [\"signedTransaction\", \"hash\"]);\n const { signedTransaction, hash } = data;\n parseSignedTransactionHex(signedTransaction);\n return {\n signedTransaction: signedTransaction as string,\n hash: parseWalletIdentifier(hash),\n };\n}\n\n/**\n * Validate a submission response's hash encoding and return a new result object.\n * Does not compare the hash to approved bytes or confirm broadcast or execution.\n */\nexport function parseSubmitTransactionResult(\n value: unknown,\n): SubmitTransactionResult {\n const data = record(value);\n fields(data, [\"hash\"]);\n return { hash: parseWalletIdentifier(data.hash) };\n}\n\n/** Require the root address and complete pubkey claim to match a wire account. */\nexport function assertWalletTransaction(\n tx: Transaction,\n account: WalletAccount,\n): void {\n const expected = parseWalletAccount(account);\n const claim = tx.auth_claim;\n if (\n toBase58(tx.invocation.invoked_address) !== expected.address ||\n claim.claim_type !== AuthClaimType.kPubkeySignature ||\n toHex0x(claim.pubkey_preimage.pubkey_hash) !==\n toHex0x(derivePublicKeyHash(walletPublicKey(expected))) ||\n claim.pubkey_preimage.nonce !== BigInt(expected.nonce)\n ) {\n throw new WalletProviderError(\n 4100,\n \"Transaction does not authorize the selected wallet account\",\n );\n }\n}\n\nfunction walletPublicKey(account: WalletAccount): PublicKey {\n return {\n scheme: CryptographicScheme.Ed25519,\n ed25519: ed25519PublicKey(fixedFromBase58(account.publicKey, 32)),\n };\n}\n\n/**\n * Verify unchanged XDR, a single strict network-bound signature, and receipt hash.\n * Requires the exact unsigned transaction bytes and matching root address/pubkey\n * claim, and an attached `pubkey_claim_key` equal to the account's Ed25519 key.\n * The signature must be Ed25519 with public-key ID zero, verified over\n * `transactionSignaturePreimage(networkHash, tx)` with ZIP-215 disabled and both\n * key and signature point R non-small-order and prime-order. The hash is SHA-256\n * of unsigned XDR, excluding signatures and network.\n *\n * @param networkHash - A 32-byte base58 identifier from the authorized session.\n * @returns A frozen verified result. This does not establish origin permission\n * or a retained approval to submit; the provider must enforce both separately.\n *\n * @remarks\n * Requires Web Crypto (HTTPS or localhost in browsers). Invalid signing results\n * throw code -32603; invalid expected inputs fail their boundary validation first.\n *\n * @see https://docs.thruput.network/tools/wallet-provider/\n */\nexport async function verifySignTransactionResult(\n value: unknown,\n transaction: string,\n account: WalletAccount,\n networkHash: string,\n): Promise<SignTransactionResult> {\n const expected = parseWalletAccount(account);\n const network = toNetworkHash(\n sha256Hash(fixedFromBase58(parseWalletNetworkHash(networkHash), 32)),\n );\n const tx = parseTransactionHex(transaction);\n assertWalletTransaction(tx, expected);\n try {\n const result = parseSignTransactionResult(value);\n const signed = parseSignedTransactionHex(result.signedTransaction);\n if (toHex0x(serialize(signed.tx, codec.Transaction)) !== transaction) {\n throw new Error(\"Provider altered unsigned transaction bytes\");\n }\n const signature = signed.signatures[0];\n if (\n signed.signatures.length !== 1 ||\n !signature ||\n signature.public_key_id !== 0n ||\n signature.signature.scheme !== CryptographicScheme.Ed25519\n ) {\n throw new Error(\"Expected one Ed25519 signature with public-key ID zero\");\n }\n const claimKey = signed.pubkey_claim_key;\n if (\n !claimKey ||\n claimKey.scheme !== CryptographicScheme.Ed25519 ||\n toBase58(claimKey.ed25519) !== expected.publicKey\n ) {\n throw new Error(\"Expected the account's Ed25519 key as pubkey_claim_key\");\n }\n // Noble's strict mode still uses a cofactored equation; reject torsion in R.\n const r = Point.fromBytes(\n signature.signature.ed25519.subarray(0, 32),\n false,\n );\n if (\n r.isSmallOrder() ||\n !r.isTorsionFree() ||\n !(await verifyAsync(\n signature.signature.ed25519,\n transactionSignaturePreimage(network, tx),\n fixedFromBase58(expected.publicKey, 32),\n { zip215: false },\n ))\n ) {\n throw new Error(\"Invalid provider transaction signature\");\n }\n if (result.hash !== toBase58(hashSignedTransaction(signed))) {\n throw new Error(\"Provider transaction hash mismatch\");\n }\n return Object.freeze(result);\n } catch {\n throw new WalletProviderError(\n -32603,\n \"Invalid provider signing result: bytes, signature, or hash mismatch\",\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAgB,sBACd,QACA,QAAgB,IACO;CACvB,OAAO;EAAE,aAAa,oBAAoB,MAAM;EAAG;CAAM;AAC3D;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,2BACd,UACiB;CACjB,OAAO,gBACL,eAAe,WAAW,UAAU,MAAM,qBAAqB,CACjE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