@qntx/wallet-chains 0.13.0 → 0.14.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 +13 -10
- package/dist/{account-ref-D2rW_qlI.mjs → account-ref-BFTeEyHt.mjs} +2 -2
- package/dist/{account-ref-D2rW_qlI.mjs.map → account-ref-BFTeEyHt.mjs.map} +1 -1
- package/dist/assemble-8GvNDony.mjs +405 -0
- package/dist/assemble-8GvNDony.mjs.map +1 -0
- package/dist/assemble-B3sO9Fvc.mjs +629 -0
- package/dist/assemble-B3sO9Fvc.mjs.map +1 -0
- package/dist/assemble-BdiPo0ZX.mjs +32 -0
- package/dist/assemble-BdiPo0ZX.mjs.map +1 -0
- package/dist/assets-sg2_Z3nZ.mjs +200 -0
- package/dist/assets-sg2_Z3nZ.mjs.map +1 -0
- package/dist/bitcoin-sign.d.mts +3 -0
- package/dist/bitcoin-sign.mjs +52 -18
- package/dist/bitcoin-sign.mjs.map +1 -1
- package/dist/bitcoin.d.mts +123 -7
- package/dist/bitcoin.mjs +162 -69
- package/dist/bitcoin.mjs.map +1 -1
- package/dist/evm-sign.d.mts +3 -1
- package/dist/evm-sign.mjs +25 -108
- package/dist/evm-sign.mjs.map +1 -1
- package/dist/evm.d.mts +152 -28
- package/dist/evm.mjs +2216 -753
- package/dist/evm.mjs.map +1 -1
- package/dist/families-BlgplKAJ.mjs +412 -0
- package/dist/families-BlgplKAJ.mjs.map +1 -0
- package/dist/index-CIRaHKpx.d.mts +941 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/networks.d.mts +29 -0
- package/dist/networks.mjs +245 -0
- package/dist/networks.mjs.map +1 -0
- package/dist/plan-wCnxHqRu.mjs +1311 -0
- package/dist/plan-wCnxHqRu.mjs.map +1 -0
- package/dist/solana-sign.d.mts +3 -0
- package/dist/solana-sign.mjs +23 -10
- package/dist/solana-sign.mjs.map +1 -1
- package/dist/solana.d.mts +117 -34
- package/dist/solana.mjs +796 -99
- package/dist/solana.mjs.map +1 -1
- package/dist/src-CHB_z45M.mjs +387 -0
- package/dist/src-CHB_z45M.mjs.map +1 -0
- package/dist/tasks-7AFv3PQn.mjs +86 -0
- package/dist/tasks-7AFv3PQn.mjs.map +1 -0
- package/dist/token-call-DH22g8BL.mjs +914 -0
- package/dist/token-call-DH22g8BL.mjs.map +1 -0
- package/dist/tron-sign.d.mts +10 -0
- package/dist/tron-sign.mjs +36 -0
- package/dist/tron-sign.mjs.map +1 -0
- package/dist/tron.d.mts +328 -0
- package/dist/tron.mjs +1484 -0
- package/dist/tron.mjs.map +1 -0
- package/dist/typed-data-CE9h4U0F.d.mts +51 -0
- package/dist/{typed-data-B4PJ1v8F.mjs → typed-data-DRtKULsH.mjs} +158 -10
- package/dist/typed-data-DRtKULsH.mjs.map +1 -0
- package/package.json +17 -10
- package/dist/index-DpL5hvPl.d.mts +0 -354
- package/dist/message-zf3XHwwc.mjs +0 -188
- package/dist/message-zf3XHwwc.mjs.map +0 -1
- package/dist/src-8NZeEnrW.mjs +0 -67
- package/dist/src-8NZeEnrW.mjs.map +0 -1
- package/dist/typed-data-B4PJ1v8F.mjs.map +0 -1
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { t as ChainError } from "./src-8NZeEnrW.mjs";
|
|
2
|
-
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
3
|
-
import { sha256 } from "@noble/hashes/sha2.js";
|
|
4
|
-
import { NETWORK, TEST_NETWORK } from "@scure/btc-signer/utils.js";
|
|
5
|
-
import { SigHash, Transaction } from "@scure/btc-signer/transaction.js";
|
|
6
|
-
// src/bitcoin/networks.ts
|
|
7
|
-
/**
|
|
8
|
-
* Bip122 CAIP-2 networks = `bip122:` + the first 32 hex chars of the genesis hash, verified against
|
|
9
|
-
* Bitcoin Core `src/kernel/chainparams.cpp` (assert(consensus.hashGenesisBlock == ...) per network
|
|
10
|
-
* class).
|
|
11
|
-
*/
|
|
12
|
-
const MAINNET_BIP32 = {
|
|
13
|
-
public: 76067358,
|
|
14
|
-
private: 76066276
|
|
15
|
-
};
|
|
16
|
-
const TESTNET_BIP32 = {
|
|
17
|
-
public: 70617039,
|
|
18
|
-
private: 70615956
|
|
19
|
-
};
|
|
20
|
-
const REGTEST_NETWORK = {
|
|
21
|
-
...TEST_NETWORK,
|
|
22
|
-
bech32: "bcrt"
|
|
23
|
-
};
|
|
24
|
-
const NETWORKS = Object.freeze([
|
|
25
|
-
{
|
|
26
|
-
caip2: "bip122:000000000019d6689c085ae165831e93",
|
|
27
|
-
genesis: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
|
|
28
|
-
params: NETWORK,
|
|
29
|
-
coinType: 0,
|
|
30
|
-
bip32: MAINNET_BIP32
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
caip2: "bip122:00000000da84f2bafbbc53dee25a72ae",
|
|
34
|
-
genesis: "00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043",
|
|
35
|
-
params: TEST_NETWORK,
|
|
36
|
-
coinType: 1,
|
|
37
|
-
bip32: TESTNET_BIP32
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
caip2: "bip122:00000008819873e925422c1ff0f99f7c",
|
|
41
|
-
genesis: "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
|
|
42
|
-
params: TEST_NETWORK,
|
|
43
|
-
coinType: 1,
|
|
44
|
-
bip32: TESTNET_BIP32
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
caip2: "bip122:0f9188f13cb7b2c71f2a335e3a4fc328",
|
|
48
|
-
genesis: "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",
|
|
49
|
-
params: REGTEST_NETWORK,
|
|
50
|
-
coinType: 1,
|
|
51
|
-
bip32: TESTNET_BIP32
|
|
52
|
-
}
|
|
53
|
-
]);
|
|
54
|
-
const BITCOIN_NETWORKS = Object.freeze(Object.fromEntries(NETWORKS.map((n) => [n.caip2, n])));
|
|
55
|
-
const bitcoinNetwork = (caip2) => {
|
|
56
|
-
const net = BITCOIN_NETWORKS[caip2];
|
|
57
|
-
if (net === void 0) throw new ChainError("unsupported", `unknown bitcoin network: ${caip2}`);
|
|
58
|
-
return net;
|
|
59
|
-
};
|
|
60
|
-
// src/bitcoin/message.ts
|
|
61
|
-
/**
|
|
62
|
-
* BIP-322 message signing ("simple" + legacy) built on btc-signer primitives.
|
|
63
|
-
* https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
|
|
64
|
-
*/
|
|
65
|
-
const utf8 = (s) => new TextEncoder().encode(s);
|
|
66
|
-
const BIP322_TAG = "BIP0322-signed-message";
|
|
67
|
-
const LEGACY_MAGIC = utf8("Bitcoin Signed Message:\n");
|
|
68
|
-
const concat = (...parts) => {
|
|
69
|
-
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
70
|
-
let o = 0;
|
|
71
|
-
for (const p of parts) {
|
|
72
|
-
out.set(p, o);
|
|
73
|
-
o += p.length;
|
|
74
|
-
}
|
|
75
|
-
return out;
|
|
76
|
-
};
|
|
77
|
-
/** CompactSize length prefix for the one-byte form. */
|
|
78
|
-
const varint = (n) => Uint8Array.of(n);
|
|
79
|
-
const COMPACT_SIZE_ONE_BYTE_MAX = 252;
|
|
80
|
-
/** A length-prefixed push; longer data would need a multi-byte CompactSize this code never emits. */
|
|
81
|
-
const pushData = (data) => {
|
|
82
|
-
if (data.length > COMPACT_SIZE_ONE_BYTE_MAX) throw new ChainError("invalid-request", "BIP-322 script data exceeds 252 bytes");
|
|
83
|
-
return concat(varint(data.length), data);
|
|
84
|
-
};
|
|
85
|
-
const u32le = (n) => Uint8Array.of(n % 256, Math.floor(n / 256) % 256, Math.floor(n / 65536) % 256, Math.floor(n / 16777216) % 256);
|
|
86
|
-
const u64le = (n) => {
|
|
87
|
-
const out = /* @__PURE__ */ new Uint8Array(8);
|
|
88
|
-
let v = n;
|
|
89
|
-
for (let i = 0; i < 8; i++) {
|
|
90
|
-
out[i] = Number(v % 256n);
|
|
91
|
-
v /= 256n;
|
|
92
|
-
}
|
|
93
|
-
return out;
|
|
94
|
-
};
|
|
95
|
-
/** BIP340 tagged hash: sha256(sha256(tag) || sha256(tag) || m). */
|
|
96
|
-
const bip322MessageHash = (message) => {
|
|
97
|
-
const tag = sha256(utf8(BIP322_TAG));
|
|
98
|
-
return sha256(concat(tag, tag, utf8(message)));
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Serialized to_spend tx per BIP-322: version 0, one input spending the zero prevout with the
|
|
102
|
-
* message-hash scriptSig, one output paying the message's scriptPubKey. Returns txid (hash256d,
|
|
103
|
-
* big-endian display order).
|
|
104
|
-
*/
|
|
105
|
-
const toSpend = (scriptPubKey, messageHash) => {
|
|
106
|
-
const scriptSig = concat(Uint8Array.of(0), pushData(messageHash));
|
|
107
|
-
const raw = concat(u32le(0), varint(1), /* @__PURE__ */ new Uint8Array(32), u32le(4294967295), pushData(scriptSig), u32le(0), varint(1), u64le(0n), pushData(scriptPubKey), u32le(0));
|
|
108
|
-
return {
|
|
109
|
-
txid: sha256(sha256(raw)),
|
|
110
|
-
raw
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Display-order (big-endian) txid of the BIP-322 to_spend transaction — exported for vector
|
|
115
|
-
* verification.
|
|
116
|
-
*/
|
|
117
|
-
const bip322ToSpendTxid = (scriptPubKey, message) => Uint8Array.from([...toSpend(scriptPubKey, bip322MessageHash(message)).txid].reverse());
|
|
118
|
-
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
119
|
-
const b64 = (i) => BASE64[i] ?? "";
|
|
120
|
-
const base64 = (bytes) => {
|
|
121
|
-
const c = b64;
|
|
122
|
-
let out = "";
|
|
123
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
124
|
-
const b0 = bytes[i] ?? 0;
|
|
125
|
-
const b1 = bytes[i + 1] ?? 0;
|
|
126
|
-
const b2 = bytes[i + 2] ?? 0;
|
|
127
|
-
out += c(Math.floor(b0 / 4)) + c(b0 % 4 * 16 + Math.floor(b1 / 16));
|
|
128
|
-
out += i + 1 < bytes.length ? c(b1 % 16 * 4 + Math.floor(b2 / 64)) : "=";
|
|
129
|
-
out += i + 2 < bytes.length ? c(b2 % 64) : "=";
|
|
130
|
-
}
|
|
131
|
-
return out;
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Signs the BIP-322 to_sign input through a btc-signer Transaction and returns the `smp`-prefixed
|
|
135
|
-
* base64 witness encoding. `scriptPubKey` is the message address's output script (P2WPKH or P2TR).
|
|
136
|
-
*/
|
|
137
|
-
const signBip322Simple = (message, scriptPubKey, privateKey, auxRand) => {
|
|
138
|
-
const hash = bip322MessageHash(message);
|
|
139
|
-
const { txid } = toSpend(scriptPubKey, hash);
|
|
140
|
-
const tx = new Transaction({
|
|
141
|
-
version: 0,
|
|
142
|
-
lockTime: 0,
|
|
143
|
-
allowUnknownOutputs: true
|
|
144
|
-
});
|
|
145
|
-
const pub = secp256k1.getPublicKey(privateKey, true);
|
|
146
|
-
tx.addInput({
|
|
147
|
-
txid,
|
|
148
|
-
index: 0,
|
|
149
|
-
sequence: 0,
|
|
150
|
-
witnessUtxo: {
|
|
151
|
-
script: scriptPubKey,
|
|
152
|
-
amount: 0n
|
|
153
|
-
},
|
|
154
|
-
bip32Derivation: [[pub, {
|
|
155
|
-
fingerprint: 0,
|
|
156
|
-
path: []
|
|
157
|
-
}]],
|
|
158
|
-
...scriptPubKey[0] === 81 ? { tapInternalKey: pub.slice(1) } : {}
|
|
159
|
-
});
|
|
160
|
-
tx.addOutput({
|
|
161
|
-
script: Uint8Array.of(106),
|
|
162
|
-
amount: 0n
|
|
163
|
-
});
|
|
164
|
-
const isTaproot = scriptPubKey[0] === 81;
|
|
165
|
-
if (!tx.signIdx(privateKey, 0, isTaproot ? [SigHash.DEFAULT, SigHash.ALL] : [SigHash.ALL], auxRand(0))) throw new ChainError("invalid-request", "key cannot sign this BIP-322 input");
|
|
166
|
-
tx.finalizeIdx(0);
|
|
167
|
-
const witness = tx.getInput(0).finalScriptWitness;
|
|
168
|
-
if (witness === void 0) throw new ChainError("invalid-request", "BIP-322 input produced no witness");
|
|
169
|
-
const raw = concat(varint(witness.length), ...witness.map(pushData));
|
|
170
|
-
return `smp${base64(raw)}`;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Legacy "Bitcoin Signed Message" compact signature for P2PKH addresses: base64(1-byte header +
|
|
174
|
-
* 64-byte compact ECDSA sig), header = 27 + recovery + 4 (compressed pubkey).
|
|
175
|
-
*/
|
|
176
|
-
const signLegacyMessage = (message, privateKey) => {
|
|
177
|
-
const data = concat(pushData(LEGACY_MAGIC), pushData(utf8(message)));
|
|
178
|
-
const hash = sha256(sha256(data));
|
|
179
|
-
const recovered = secp256k1.sign(hash, privateKey, {
|
|
180
|
-
lowS: true,
|
|
181
|
-
format: "recovered"
|
|
182
|
-
});
|
|
183
|
-
const header = 27 + (recovered[0] ?? 0) + 4;
|
|
184
|
-
return base64(concat(Uint8Array.of(header), recovered.slice(1)));
|
|
185
|
-
};
|
|
186
|
-
export { bitcoinNetwork as a, BITCOIN_NETWORKS as i, signBip322Simple as n, signLegacyMessage as r, bip322ToSpendTxid as t };
|
|
187
|
-
|
|
188
|
-
//# sourceMappingURL=message-zf3XHwwc.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message-zf3XHwwc.mjs","names":[],"sources":["../src/bitcoin/networks.ts","../src/bitcoin/message.ts"],"sourcesContent":["import { NETWORK, TEST_NETWORK } from \"@scure/btc-signer/utils.js\";\n/**\n * Bip122 CAIP-2 networks = `bip122:` + the first 32 hex chars of the genesis hash, verified against\n * Bitcoin Core `src/kernel/chainparams.cpp` (assert(consensus.hashGenesisBlock == ...) per network\n * class).\n */\n\nimport { ChainError } from \"../index.ts\";\n\nexport type BitcoinNetwork = {\n readonly caip2: string;\n readonly genesis: string;\n readonly params: typeof NETWORK;\n readonly coinType: 0 | 1;\n /** BIP-32 extended-key version bytes: `xpub`/`xprv` on mainnet, `tpub`/`tprv` elsewhere. */\n readonly bip32: { readonly public: number; readonly private: number };\n};\n\nconst MAINNET_BIP32 = { public: 0x0488b21e, private: 0x0488ade4 } as const;\nconst TESTNET_BIP32 = { public: 0x043587cf, private: 0x04358394 } as const;\n\n// btc-signer ships mainnet and testnet parameters only; regtest shares testnet's version bytes but\n// uses the `bcrt` bech32 prefix.\nconst REGTEST_NETWORK: typeof NETWORK = { ...TEST_NETWORK, bech32: \"bcrt\" };\n\nconst NETWORKS: ReadonlyArray<BitcoinNetwork> = Object.freeze([\n {\n caip2: \"bip122:000000000019d6689c085ae165831e93\",\n genesis: \"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f\",\n params: NETWORK,\n coinType: 0,\n bip32: MAINNET_BIP32,\n },\n {\n caip2: \"bip122:00000000da84f2bafbbc53dee25a72ae\",\n genesis: \"00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:00000008819873e925422c1ff0f99f7c\",\n genesis: \"00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:0f9188f13cb7b2c71f2a335e3a4fc328\",\n genesis: \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n params: REGTEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n] as const);\n\nexport const BITCOIN_NETWORKS: Readonly<Record<string, BitcoinNetwork>> = Object.freeze(\n Object.fromEntries(NETWORKS.map((n) => [n.caip2, n])),\n);\n\nexport const bitcoinNetwork = (caip2: string): BitcoinNetwork => {\n const net = BITCOIN_NETWORKS[caip2];\n if (net === undefined) {\n throw new ChainError(\"unsupported\", `unknown bitcoin network: ${caip2}`);\n }\n return net;\n};\n","import { secp256k1 } from \"@noble/curves/secp256k1.js\";\n/**\n * BIP-322 message signing (\"simple\" + legacy) built on btc-signer primitives.\n * https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki\n */\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { SigHash, Transaction } from \"@scure/btc-signer/transaction.js\";\n\nimport { ChainError } from \"../index.ts\";\n\nconst utf8 = (s: string): Uint8Array => new TextEncoder().encode(s);\n\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst LEGACY_MAGIC = utf8(\"Bitcoin Signed Message:\\n\");\n\nconst concat = (...parts: ReadonlyArray<Uint8Array>): Uint8Array => {\n const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));\n let o = 0;\n for (const p of parts) {\n out.set(p, o);\n o += p.length;\n }\n return out;\n};\n\n/** CompactSize length prefix for the one-byte form. */\nconst varint = (n: number): Uint8Array => Uint8Array.of(n);\n\nconst COMPACT_SIZE_ONE_BYTE_MAX = 252;\n\n/** A length-prefixed push; longer data would need a multi-byte CompactSize this code never emits. */\nexport const pushData = (data: Uint8Array): Uint8Array => {\n if (data.length > COMPACT_SIZE_ONE_BYTE_MAX) {\n throw new ChainError(\"invalid-request\", \"BIP-322 script data exceeds 252 bytes\");\n }\n return concat(varint(data.length), data);\n};\n\nconst u32le = (n: number): Uint8Array =>\n Uint8Array.of(\n n % 256,\n Math.floor(n / 256) % 256,\n Math.floor(n / 65536) % 256,\n Math.floor(n / 16777216) % 256,\n );\n\nconst u64le = (n: bigint): Uint8Array => {\n const out = new Uint8Array(8);\n let v = n;\n for (let i = 0; i < 8; i++) {\n out[i] = Number(v % 256n);\n v /= 256n;\n }\n return out;\n};\n\n/** BIP340 tagged hash: sha256(sha256(tag) || sha256(tag) || m). */\nconst bip322MessageHash = (message: string): Uint8Array => {\n const tag = sha256(utf8(BIP322_TAG));\n return sha256(concat(tag, tag, utf8(message)));\n};\n\n/**\n * Serialized to_spend tx per BIP-322: version 0, one input spending the zero prevout with the\n * message-hash scriptSig, one output paying the message's scriptPubKey. Returns txid (hash256d,\n * big-endian display order).\n */\nconst toSpend = (\n scriptPubKey: Uint8Array,\n messageHash: Uint8Array,\n): { txid: Uint8Array; raw: Uint8Array } => {\n const scriptSig = concat(Uint8Array.of(0x00), pushData(messageHash));\n const raw = concat(\n u32le(0),\n varint(1),\n new Uint8Array(32),\n u32le(0xffffffff),\n pushData(scriptSig),\n u32le(0),\n varint(1),\n u64le(0n),\n pushData(scriptPubKey),\n u32le(0),\n );\n const txid = sha256(sha256(raw));\n return { txid, raw };\n};\n\n/**\n * Display-order (big-endian) txid of the BIP-322 to_spend transaction — exported for vector\n * verification.\n */\nexport const bip322ToSpendTxid = (scriptPubKey: Uint8Array, message: string): Uint8Array =>\n Uint8Array.from([...toSpend(scriptPubKey, bip322MessageHash(message)).txid].reverse());\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst b64 = (i: number): string => BASE64[i] ?? \"\";\nconst base64 = (bytes: Uint8Array): string => {\n const c = b64;\n let out = \"\";\n for (let i = 0; i < bytes.length; i += 3) {\n const b0 = bytes[i] ?? 0;\n const b1 = bytes[i + 1] ?? 0;\n const b2 = bytes[i + 2] ?? 0;\n out += c(Math.floor(b0 / 4)) + c((b0 % 4) * 16 + Math.floor(b1 / 16));\n out += i + 1 < bytes.length ? c((b1 % 16) * 4 + Math.floor(b2 / 64)) : \"=\";\n out += i + 2 < bytes.length ? c(b2 % 64) : \"=\";\n }\n return out;\n};\n\n/**\n * Signs the BIP-322 to_sign input through a btc-signer Transaction and returns the `smp`-prefixed\n * base64 witness encoding. `scriptPubKey` is the message address's output script (P2WPKH or P2TR).\n */\nexport const signBip322Simple = (\n message: string,\n scriptPubKey: Uint8Array,\n privateKey: Uint8Array,\n auxRand: (n: number) => Uint8Array,\n): string => {\n const hash = bip322MessageHash(message);\n const { txid } = toSpend(scriptPubKey, hash);\n const tx = new Transaction({ version: 0, lockTime: 0, allowUnknownOutputs: true });\n const pub = secp256k1.getPublicKey(privateKey, true);\n tx.addInput({\n txid,\n index: 0,\n sequence: 0,\n witnessUtxo: { script: scriptPubKey, amount: 0n },\n bip32Derivation: [[pub, { fingerprint: 0, path: [] }]],\n ...(scriptPubKey[0] === 0x51 ? { tapInternalKey: pub.slice(1) } : {}),\n });\n tx.addOutput({ script: Uint8Array.of(0x6a), amount: 0n });\n const isTaproot = scriptPubKey[0] === 0x51;\n const ok = tx.signIdx(\n privateKey,\n 0,\n isTaproot ? [SigHash.DEFAULT, SigHash.ALL] : [SigHash.ALL],\n auxRand(0),\n );\n if (!ok) {\n throw new ChainError(\"invalid-request\", \"key cannot sign this BIP-322 input\");\n }\n tx.finalizeIdx(0);\n const witness = tx.getInput(0).finalScriptWitness;\n if (witness === undefined) {\n throw new ChainError(\"invalid-request\", \"BIP-322 input produced no witness\");\n }\n const raw = concat(varint(witness.length), ...witness.map(pushData));\n return `smp${base64(raw)}`;\n};\n\n/**\n * Legacy \"Bitcoin Signed Message\" compact signature for P2PKH addresses: base64(1-byte header +\n * 64-byte compact ECDSA sig), header = 27 + recovery + 4 (compressed pubkey).\n */\nexport const signLegacyMessage = (message: string, privateKey: Uint8Array): string => {\n const data = concat(pushData(LEGACY_MAGIC), pushData(utf8(message)));\n const hash = sha256(sha256(data));\n const recovered = secp256k1.sign(hash, privateKey, { lowS: true, format: \"recovered\" });\n const header = 27 + (recovered[0] ?? 0) + 4;\n return base64(concat(Uint8Array.of(header), recovered.slice(1)));\n};\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,gBAAgB;CAAE,QAAQ;CAAY,SAAS;AAAW;AAChE,MAAM,gBAAgB;CAAE,QAAQ;CAAY,SAAS;AAAW;AAIhE,MAAM,kBAAkC;CAAE,GA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Q,IAAI,QAAQ,CAAC;CACnE,OAAO,MAAM,OAAO,GAAG;AACzB;;;;;AAMA,MAAa,qBAAqB,SAAiB,eAAmC;CACpF,MAAM,OAAO,OAAO,SAAS,YAAY,GAAG,SAAS,KAAK,OAAO,CAAC,CAAC;CACnE,MAAM,OAAO,OAAO,OAAO,IAAI,CAAC;CAChC,MAAM,YAAY,UAAU,KAAK,MAAM,YAAY;EAAE,MAAM;EAAM,QAAQ;CAAY,CAAC;CACtF,MAAM,SAAS,MAAM,UAAU,MAAM,KAAK;CAC1C,OAAO,OAAO,OAAO,WAAW,GAAG,MAAM,GAAG,UAAU,MAAM,CAAC,CAAC,CAAC;AACjE"}
|
package/dist/src-8NZeEnrW.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { evm } from "@qntx/siwx/evm";
|
|
2
|
-
import { siws, validateAddress } from "@qntx/siwx/svm";
|
|
3
|
-
// src/sign-in.ts
|
|
4
|
-
const PREAMBLE = " wants you to sign in with your ";
|
|
5
|
-
const OPTIONAL_KEYS = [
|
|
6
|
-
"scheme",
|
|
7
|
-
"statement",
|
|
8
|
-
"expirationTime",
|
|
9
|
-
"notBefore",
|
|
10
|
-
"requestId"
|
|
11
|
-
];
|
|
12
|
-
const plainFields = (message) => {
|
|
13
|
-
const { domain, address, uri, version, chainId, nonce, issuedAt, resources } = message;
|
|
14
|
-
const fields = {
|
|
15
|
-
domain,
|
|
16
|
-
address,
|
|
17
|
-
uri,
|
|
18
|
-
version,
|
|
19
|
-
chainId,
|
|
20
|
-
nonce,
|
|
21
|
-
issuedAt
|
|
22
|
-
};
|
|
23
|
-
for (const key of OPTIONAL_KEYS) {
|
|
24
|
-
const value = message[key];
|
|
25
|
-
if (value !== void 0) fields[key] = value;
|
|
26
|
-
}
|
|
27
|
-
if (resources !== void 0) fields.resources = [...resources];
|
|
28
|
-
return fields;
|
|
29
|
-
};
|
|
30
|
-
const parseValid = (text, family) => {
|
|
31
|
-
if (family === "evm") {
|
|
32
|
-
const ns = evm();
|
|
33
|
-
const message = ns.parse(new TextEncoder().encode(text));
|
|
34
|
-
ns.account(message);
|
|
35
|
-
return plainFields(message);
|
|
36
|
-
}
|
|
37
|
-
const message = siws.parse(text);
|
|
38
|
-
validateAddress(message.address);
|
|
39
|
-
return plainFields(message);
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Finds a Sign-In with X message in `text` for the chain `family`. `undefined` when the text has no
|
|
43
|
-
* sign-in preamble; `malformed` when it has one but is not a conforming message for the family
|
|
44
|
-
* (ERC-4361: wallets should warn about that shape).
|
|
45
|
-
*/
|
|
46
|
-
function parseSignIn(text, family) {
|
|
47
|
-
try {
|
|
48
|
-
return {
|
|
49
|
-
status: "valid",
|
|
50
|
-
fields: parseValid(text, family)
|
|
51
|
-
};
|
|
52
|
-
} catch {
|
|
53
|
-
return text.includes(PREAMBLE) ? { status: "malformed" } : void 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// src/index.ts
|
|
57
|
-
var ChainError = class extends Error {
|
|
58
|
-
code;
|
|
59
|
-
constructor(code, message) {
|
|
60
|
-
super(message);
|
|
61
|
-
this.name = "ChainError";
|
|
62
|
-
this.code = code;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
export { parseSignIn as n, ChainError as t };
|
|
66
|
-
|
|
67
|
-
//# sourceMappingURL=src-8NZeEnrW.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"src-8NZeEnrW.mjs","names":[],"sources":["../src/sign-in.ts","../src/index.ts"],"sourcesContent":["/** Recognition of Sign-In with Ethereum (ERC-4361) and Sign-In with Solana text in signed messages. */\nimport type { Message, MessageFields } from \"@qntx/siwx\";\nimport { evm } from \"@qntx/siwx/evm\";\nimport { siws, validateAddress as validateSolanaAddress } from \"@qntx/siwx/svm\";\n\n/** A Sign-In with X message found in signed text (ERC-4361 / SIWS). */\nexport type SignInParse =\n | { readonly status: \"valid\"; readonly fields: MessageFields }\n /** The text contains the sign-in preamble but is not a conforming message for this chain family. */\n | { readonly status: \"malformed\" };\n\nconst PREAMBLE = \" wants you to sign in with your \";\n\nconst OPTIONAL_KEYS = [\"scheme\", \"statement\", \"expirationTime\", \"notBefore\", \"requestId\"] as const;\n\nconst plainFields = (message: Message): MessageFields => {\n const { domain, address, uri, version, chainId, nonce, issuedAt, resources } = message;\n const fields: { -readonly [K in keyof MessageFields]: MessageFields[K] } = {\n domain,\n address,\n uri,\n version,\n chainId,\n nonce,\n issuedAt,\n };\n for (const key of OPTIONAL_KEYS) {\n const value = message[key];\n if (value !== undefined) {\n fields[key] = value;\n }\n }\n if (resources !== undefined) {\n fields.resources = [...resources];\n }\n return fields;\n};\n\nconst parseValid = (text: string, family: \"evm\" | \"solana\"): MessageFields => {\n if (family === \"evm\") {\n const ns = evm();\n const message = ns.parse(new TextEncoder().encode(text));\n ns.account(message);\n return plainFields(message);\n }\n const message = siws.parse(text);\n validateSolanaAddress(message.address);\n return plainFields(message);\n};\n\n/**\n * Finds a Sign-In with X message in `text` for the chain `family`. `undefined` when the text has no\n * sign-in preamble; `malformed` when it has one but is not a conforming message for the family\n * (ERC-4361: wallets should warn about that shape).\n */\nexport function parseSignIn(text: string, family: \"evm\" | \"solana\"): SignInParse | undefined {\n try {\n return { status: \"valid\", fields: parseValid(text, family) };\n } catch {\n return text.includes(PREAMBLE) ? { status: \"malformed\" } : undefined;\n }\n}\n","/**\n * @qntx/wallet-chains — shared chain semantics for the wallet.\n * Types here are wire-safe: values crossing the main↔kernel protocol are\n * Uint8Array, safe integers, strings, booleans, arrays and plain objects.\n * Quantities are canonical `0x` hex (lowercase, no leading zeros, `0x0` for\n * zero), token amounts are decimal strings of the smallest unit.\n */\n\nimport type { SignInParse } from \"./sign-in.ts\";\n\nexport { parseSignIn } from \"./sign-in.ts\";\nexport type { SignInParse } from \"./sign-in.ts\";\n\nexport type ChainFamily = \"evm\" | \"solana\" | \"bitcoin\";\n\nexport type AccountRef =\n | {\n readonly kind: \"hd\";\n readonly walletId: string;\n readonly groupIndex: number;\n readonly template: string;\n }\n | { readonly kind: \"imported\"; readonly keyId: string; readonly family: ChainFamily };\n\n/** The BIP-44/49/84/86 account-level templates a bitcoin.psbt input may sign under. */\nexport type BitcoinTemplate = \"btc.bip44\" | \"btc.bip49\" | \"btc.bip84\" | \"btc.bip86\";\n\nexport type SignRequest =\n | {\n readonly kind: \"bitcoin.psbt\";\n readonly network: string;\n /** The wallet group whose keys sign; each signed input names its template. */\n readonly account: {\n readonly kind: \"hd\";\n readonly walletId: string;\n readonly groupIndex: number;\n };\n readonly psbt: Uint8Array;\n /** Inputs to sign — non-empty, unique, ascending by index, in range; each with its template. */\n readonly sign: ReadonlyArray<{ readonly index: number; readonly template: BitcoinTemplate }>;\n }\n | {\n readonly kind: \"bitcoin.message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly address: string;\n readonly message: string;\n readonly format: \"bip322-simple\" | \"legacy\";\n /** Account change chain and index the address is derived at (0 = receive, 1 = change). */\n readonly change: 0 | 1;\n readonly index: number;\n }\n | {\n readonly kind: \"solana.transaction\";\n readonly network: string;\n readonly account: AccountRef;\n /** Compiled wire message (legacy or v0). */\n readonly message: Uint8Array;\n readonly lookupTables?: ReadonlyArray<{\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n }>;\n }\n | {\n readonly kind: \"solana.message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n /** Only \"raw\" exists in this layer; offchain formats land with C7. */\n readonly format: \"raw\";\n }\n | {\n readonly kind: \"evm.transaction\";\n readonly network: string;\n readonly account: AccountRef;\n readonly tx: EvmTransaction;\n }\n | {\n readonly kind: \"evm.personal-message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n }\n | {\n readonly kind: \"evm.typed-data\";\n readonly network: string;\n readonly account: AccountRef;\n readonly typedData: string;\n };\n\nexport type EvmAccessListEntry = {\n readonly address: string;\n readonly storageKeys: ReadonlyArray<string>;\n};\n\ntype EvmTransactionBase = {\n readonly chainId: number;\n readonly nonce: number;\n readonly gas: string;\n readonly value: string;\n readonly data: string;\n readonly to?: string;\n};\n\n/**\n * A complete transaction — every field the signer needs is present; `to` absent means contract\n * creation.\n */\nexport type EvmTransaction =\n | (EvmTransactionBase & { readonly type: \"legacy\"; readonly gasPrice: string })\n | (EvmTransactionBase & {\n readonly type: \"eip2930\";\n readonly gasPrice: string;\n readonly accessList: ReadonlyArray<EvmAccessListEntry>;\n })\n | (EvmTransactionBase & {\n readonly type: \"eip1559\";\n readonly accessList: ReadonlyArray<EvmAccessListEntry>;\n readonly maxFeePerGas: string;\n readonly maxPriorityFeePerGas: string;\n })\n | (Omit<EvmTransactionBase, \"to\"> & {\n readonly type: \"eip7702\";\n readonly to: string;\n readonly accessList: ReadonlyArray<EvmAccessListEntry>;\n readonly maxFeePerGas: string;\n readonly maxPriorityFeePerGas: string;\n /**\n * One self-sponsored authorization: its chain id is the transaction's chain id and its nonce\n * is `tx.nonce + 1`, so multi-tuple or nonce-mismatched authorizations are unrepresentable.\n * The zero address revokes an existing delegation.\n */\n readonly authorization: { readonly address: string };\n });\n\nexport type Verifiability = \"full\" | \"partial\" | \"opaque\";\n\nexport type IntentSummary =\n | \"transfer\"\n | \"approve\"\n | \"contract-call\"\n | \"swap\"\n | \"message\"\n | \"authorization\"\n | \"batch\"\n | \"stake\"\n | \"bridge\";\n\nexport type AssetAmount = {\n readonly asset: string;\n readonly amount: string;\n readonly decimals?: number;\n readonly symbol?: string;\n /** NFT flows only: the decimal token id; `amount` is then the unit count. */\n readonly tokenId?: string;\n};\n\nexport type AssetFlow = {\n readonly to: string;\n readonly amount: AssetAmount;\n readonly verified: boolean;\n /** The ENS name the recipient was resolved from; attached by the engine, never decoded. */\n readonly name?: string;\n};\n\nexport type ApprovalChange =\n | {\n /** A fungible-token allowance: on the token itself, or on Permit2 when `via` is \"permit2\". */\n readonly kind: \"allowance\";\n readonly spender: string;\n /** The token and amount (base units); symbol/decimals when the token is in the built-in table. */\n readonly amount: AssetAmount;\n /**\n * `set`: the allowance becomes `amount`; `increase`/`decrease`: it changes by `amount`;\n * `transfer`: a one-time right to take up to `amount` before `expiration` (Permit2\n * SignatureTransfer).\n */\n readonly change: \"set\" | \"increase\" | \"decrease\" | \"transfer\";\n /** `amount` is the type's maximum (uint256; uint160 for Permit2). */\n readonly unlimited: boolean;\n /** Unix seconds after which the allowance lapses (Permit2), when it has one. */\n readonly expiration?: number;\n readonly via?: \"permit2\" | \"allowance-holder\";\n /** The token is in the built-in table. */\n readonly verified: boolean;\n }\n | {\n /** ERC-721/1155 `setApprovalForAll`: `spender` may move every token of `asset`. */\n readonly kind: \"operator\";\n readonly asset: string;\n readonly spender: string;\n /** `false` revokes. */\n readonly approved: boolean;\n readonly verified: false;\n }\n | {\n /**\n * A Solana stake account's staker or withdrawer role handed to a key other than the signer —\n * by an `Authorize`/`AuthorizeChecked` instruction, or by `Initialize` naming a non-signer.\n */\n readonly kind: \"stake-authority\";\n /** The stake account the role applies to. */\n readonly account: string;\n readonly role: \"staker\" | \"withdrawer\";\n /** The key receiving the role. */\n readonly authority: string;\n readonly verified: false;\n };\n\n/** One staking operation shown on the signing surface. */\nexport type StakeAction =\n | { readonly kind: \"create\"; readonly account: string; readonly lamports: string }\n | { readonly kind: \"delegate\"; readonly account: string; readonly validator: string }\n | { readonly kind: \"deactivate\"; readonly account: string }\n | {\n readonly kind: \"withdraw\";\n readonly account: string;\n readonly to: string;\n readonly lamports: string;\n }\n /** Lido `submit` on Ethereum mainnet: ETH in, approximately `receive` stETH back. */\n | { readonly kind: \"lido-submit\"; readonly amount: AssetAmount; readonly receive: AssetAmount }\n /** Lido withdrawal request on Ethereum mainnet; `owner` gets the claim NFT. */\n | {\n readonly kind: \"lido-request\";\n readonly token: string;\n readonly amount: AssetAmount;\n readonly owner: string;\n }\n /** Lido claim of finalised withdrawal requests on Ethereum mainnet (ETH to the caller). */\n | { readonly kind: \"lido-claim\"; readonly requestIds: ReadonlyArray<string> };\n\nexport type IntentWarning = {\n readonly kind: string;\n readonly message: string;\n};\n\n/** One item a Seaport order offers or requests; recognized from EIP-712 `itemType` 0–5. */\nexport type SeaportItem = {\n readonly kind: \"native\" | \"erc20\" | \"erc721\" | \"erc1155\" | \"erc721-criteria\" | \"erc1155-criteria\";\n /** The item's contract (EIP-55 checksummed; the zero address for `native`). */\n readonly token: string;\n /** `identifierOrCriteria` as a decimal string; a criteria root for the criteria kinds. */\n readonly identifier: string;\n readonly startAmount: AssetAmount;\n readonly endAmount: AssetAmount;\n};\n\n/** A recognized Seaport `OrderComponents` message. */\nexport type SeaportOrder = {\n readonly offerer: string;\n readonly zone: string;\n readonly startTime: number | undefined;\n readonly endTime: number | undefined;\n readonly offer: ReadonlyArray<SeaportItem>;\n readonly consideration: ReadonlyArray<SeaportItem & { readonly recipient: string }>;\n};\n\n/** A recognized Safe `SafeTx` message. */\nexport type SafeTransaction = {\n readonly safe: string;\n /** The Safe nonce as a decimal string. */\n readonly nonce: string;\n readonly operation: \"call\" | \"delegatecall\";\n readonly to: string;\n /** Wei, decimal. */\n readonly value: string;\n readonly data: string;\n /** The inner call(s) decoded with the transaction rules (no fee); one per MultiSend entry. */\n readonly calls: ReadonlyArray<DisplayIntent>;\n /** The gas-refund terms, present when `gasPrice` is not zero. */\n readonly refund?: {\n readonly gasPrice: string;\n readonly gasToken: string;\n readonly refundReceiver: string;\n };\n};\n\n/** The EIP-712 domain fields a wallet shows. */\nexport type TypedDataDomain = {\n readonly name?: string;\n readonly version?: string;\n readonly chainId?: number;\n /** EIP-55 checksummed. */\n readonly verifyingContract?: string;\n readonly salt?: string;\n};\n\n/** What a message request signs. */\nexport type MessageContent =\n | { readonly kind: \"text\"; readonly text: string; readonly signIn?: SignInParse }\n | { readonly kind: \"bytes\"; readonly hex: string }\n | {\n readonly kind: \"typed-data\";\n readonly primaryType: string;\n readonly domain: TypedDataDomain;\n readonly data: Readonly<Record<string, unknown>>;\n /** A recognized Seaport order; only the exact `OrderComponents` shape populates it. */\n readonly seaport?: SeaportOrder;\n /** A recognized Safe transaction; only the exact `SafeTx` shape populates it. */\n readonly safe?: SafeTransaction;\n };\n\nexport type DisplayIntent = {\n readonly family: ChainFamily;\n readonly network: string;\n readonly summary: IntentSummary;\n readonly outflows: ReadonlyArray<AssetFlow>;\n readonly approvals: ReadonlyArray<ApprovalChange>;\n /**\n * The minimums the settlement contracts enforce on-chain for recognised swaps — each\n * `minAmountOut` a Settler requires its own balance to reach before paying the recipient, not an\n * estimate. Present only when non-empty; a batch concatenates its calls' lists like the others.\n */\n readonly minimumReceived?: ReadonlyArray<{\n readonly to: string;\n readonly amount: AssetAmount;\n }>;\n /**\n * `l1Data`: OP Stack L1 data fee plus operator fee, estimated by the engine and charged on top of\n * `max`; not decodable from the transaction, so the kernel's own decode never sets it.\n */\n readonly fee: { readonly max: AssetAmount; readonly l1Data?: AssetAmount } | undefined;\n /**\n * Recognized Solana stake operations — create, delegate, deactivate, withdraw — one per\n * instruction, in order. Present only when non-empty.\n */\n readonly staking?: ReadonlyArray<StakeAction>;\n /**\n * A recognized Across SpokePool deposit: the calldata-stated destination chain, the fill deadline\n * after which an unfilled deposit refunds `refundTo` on this chain.\n */\n readonly bridge?: {\n readonly destinationNetwork: string;\n readonly fillDeadline: number;\n readonly refundTo: string;\n };\n readonly warnings: ReadonlyArray<IntentWarning>;\n /** What a message request signs; absent for transactions. */\n readonly message?: MessageContent;\n readonly verifiability: Verifiability;\n /** Present iff the transaction carries an EIP-7702 authorization. */\n readonly delegation?:\n | {\n readonly kind: \"set\";\n readonly delegator: string;\n readonly name: string;\n readonly version: string;\n }\n | { readonly kind: \"revoke\" };\n /** The decoded inner calls of a recognized ERC-7821 batch execute. */\n readonly calls?: ReadonlyArray<DisplayIntent>;\n};\n\nexport type ChainErrorCode =\n | \"unknown-field\"\n | \"chain-id-mismatch\"\n | \"fee-payer-mismatch\"\n | \"invalid-quantity\"\n | \"invalid-address\"\n | \"invalid-typed-data\"\n | \"invalid-request\"\n | \"unsupported\";\n\nexport class ChainError extends Error {\n readonly code: ChainErrorCode;\n constructor(code: ChainErrorCode, message: string) {\n super(message);\n this.name = \"ChainError\";\n this.code = code;\n }\n}\n"],"mappings":";;;AAWA,MAAM,WAAW;AAEjB,MAAM,gBAAgB;CAAC;CAAU;CAAa;CAAkB;CAAa;AAAW;AAExF,MAAM,eAAe,YAAoC;CACvD,MAAM,EAAE,QAAQ,SAAS,KAAK,SAAS,SAAS,OAAO,UAAU,cAAc;CAC/E,MAAM,SAAqE;EACzE;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,KAAK,MAAM,OAAO,eAAe;EAC/B,MAAM,QAAQ,QAAQ;EACtB,IAAI,UAAU,KAAA,GACZ,OAAO,OAAO;CAElB;CACA,IAAI,cAAc,KAAA,GAChB,OAAO,YAAY,CAAC,GAAG,SAAS;CAElC,OAAO;AACT;AAEA,MAAM,cAAc,MAAc,WAA4C;CAC5E,IAAI,WAAW,OAAO;EACpB,MAAM,KAAK,IAAI;EACf,MAAM,UAAU,GAAG,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,IAAI,CAAC;EACvD,GAAG,QAAQ,OAAO;EAClB,OAAO,YAAY,OAAO;CAC5B;CACA,MAAM,UAAU,KAAK,MAAM,IAAI;CAC/B,gBAAsB,QAAQ,OAAO;CACrC,OAAO,YAAY,OAAO;AAC5B;;;;;;AAOA,SAAgB,YAAY,MAAc,QAAmD;CAC3F,IAAI;EACF,OAAO;GAAE,QAAQ;GAAS,QAAQ,WAAW,MAAM,MAAM;EAAE;CAC7D,QAAQ;EACN,OAAO,KAAK,SAAS,QAAQ,IAAI,EAAE,QAAQ,YAAY,IAAI,KAAA;CAC7D;AACF;;AC+SA,IAAa,aAAb,cAAgC,MAAM;CACpC;CACA,YAAY,MAAsB,SAAiB;EACjD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typed-data-B4PJ1v8F.mjs","names":[],"sources":["../src/evm/address.ts","../src/evm/delegation.ts","../src/evm/transaction.ts","../src/evm/typed-data.ts"],"sourcesContent":["import { secp256k1 } from \"@noble/curves/secp256k1.js\";\nimport { keccak_256 } from \"@noble/hashes/sha3.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\nimport * as Address from \"ox/Address\";\n\nimport { ChainError } from \"../index.ts\";\n\n/** EIP-55 checksummed address, e.g. `0x52908400098527886E0F7030069857D2E4169EE7`. */\nexport const isEvmAddress = (value: string): boolean => /^0x[0-9a-fA-F]{40}$/.test(value);\n\nexport function checksumEvmAddress(address: string): string {\n if (!isEvmAddress(address)) {\n throw new ChainError(\"invalid-address\", \"not an EVM address\");\n }\n const checksummed = Address.checksum(address);\n Address.assert(checksummed, { strict: true });\n return checksummed;\n}\n\n/** `keccak256(pubkey)[12:]` — accepts a 33-byte compressed or 65-byte uncompressed secp256k1 key. */\nexport function evmAddressFromPublicKey(pubkey: Uint8Array): string {\n const uncompressed =\n pubkey.length === 65 && pubkey[0] === 4\n ? pubkey\n : pubkey.length === 33\n ? secp256k1.Point.fromBytes(pubkey).toBytes(false)\n : undefined;\n if (uncompressed === undefined || uncompressed[0] !== 4) {\n throw new ChainError(\"invalid-address\", \"expected a compressed or uncompressed secp256k1 key\");\n }\n return checksumEvmAddress(`0x${bytesToHex(keccak_256(uncompressed.subarray(1))).slice(-40)}`);\n}\n","import * as AbiFunction from \"ox/AbiFunction\";\nimport * as AbiParameters from \"ox/AbiParameters\";\nimport * as Hex from \"ox/Hex\";\n\nimport { checksumEvmAddress, isEvmAddress } from \"./address.ts\";\n\n/**\n * MetaMask Delegation Framework EIP7702StatelessDeleGator v1.3.0 — deterministic CREATE2, the same\n * address on every chain that supports it.\n */\nexport const EVM_DELEGATOR = {\n address: \"0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B\",\n name: \"EIP7702StatelessDeleGator\",\n version: \"1.3.0\",\n} as const;\n\n/** The EIP-7702 designator byte prefix: `0xef0100 ‖ address` marks a delegated account's code. */\nexport const EVM_DELEGATION_PREFIX = \"0xef0100\";\n\n/** ERC-7821 batch-default execution mode: `0x01` followed by 31 zero bytes. */\nexport const EXECUTE_BATCH_MODE =\n \"0x0100000000000000000000000000000000000000000000000000000000000000\";\n\nexport const EXECUTE: AbiFunction.AbiFunction = AbiFunction.from(\n \"function execute(bytes32 mode, bytes executionData)\",\n);\n\nconst EXECUTIONS = [\n {\n type: \"tuple[]\",\n components: [\n { name: \"target\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"callData\", type: \"bytes\" },\n ],\n },\n] as const;\n\nconst hex = (v: string): `0x${string}` => {\n Hex.assert(v);\n return v;\n};\n\n/** ERC-7821 batch-default self-call payload for `execute` on the delegator. */\nexport const encodeBatchExecute = (\n calls: ReadonlyArray<{ readonly to: string; readonly value: bigint; readonly data: string }>,\n): string =>\n AbiFunction.encodeData(EXECUTE, [\n EXECUTE_BATCH_MODE,\n AbiParameters.encode(EXECUTIONS, [\n calls.map((c) => ({\n target: hex(checksumEvmAddress(c.to)),\n value: c.value,\n callData: hex(c.data),\n })),\n ]),\n ]);\n\ntype Execution = { readonly to: string; readonly value: bigint; readonly data: string };\n\nconst list = (v: unknown): ReadonlyArray<unknown> => (Array.isArray(v) ? v : []);\n\nconst isExecution = (\n e: unknown,\n): e is { readonly target: string; readonly value: bigint; readonly callData: string } =>\n typeof e === \"object\" &&\n e !== null &&\n \"target\" in e &&\n \"value\" in e &&\n \"callData\" in e &&\n typeof e.target === \"string\" &&\n isEvmAddress(e.target) &&\n typeof e.value === \"bigint\" &&\n typeof e.callData === \"string\";\n\n/** Decodes an `execute` call; undefined unless the encoding is canonical batch-default mode. */\nexport const decodeBatchExecute = (data: string): ReadonlyArray<Execution> | undefined => {\n try {\n const args = list(AbiFunction.decodeData(EXECUTE, hex(data)));\n const [mode, executionData] = args;\n if (mode !== EXECUTE_BATCH_MODE || typeof executionData !== \"string\") {\n return undefined;\n }\n const decoded: unknown = AbiParameters.decode(EXECUTIONS, hex(executionData));\n const [inner] = list(decoded);\n const executions: Execution[] = [];\n for (const e of list(inner)) {\n if (!isExecution(e)) {\n return undefined;\n }\n executions.push({\n to: checksumEvmAddress(e.target),\n value: e.value,\n data: e.callData,\n });\n }\n /* Display must equal execution: accept only the canonical encoding the delegator's own\n * calldata decoder would read — a non-canonical payload (trailing bytes, aliased offsets)\n * can decode one way here and another on-chain. */\n return encodeBatchExecute(executions).toLowerCase() === data.toLowerCase()\n ? executions\n : undefined;\n } catch {\n return undefined;\n }\n};\n","import { ChainError } from \"../index.ts\";\nimport type { EvmTransaction, EvmAccessListEntry } from \"../index.ts\";\nimport { checksumEvmAddress, isEvmAddress } from \"./address.ts\";\nimport { EVM_DELEGATOR } from \"./delegation.ts\";\n\n/** Validates a string is `0x`-hex and narrows it to the branded hex type. */\nexport function assertHex(value: string, field: string): asserts value is `0x${string}` {\n if (!/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) {\n throw new ChainError(\"invalid-quantity\", `${field} must be 0x-prefixed bytes`);\n }\n}\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst CANONICAL_HEX = /^0x(?:0|[1-9a-f][0-9a-f]*)$/;\n\nexport const isCanonicalHex = (value: string): boolean => CANONICAL_HEX.test(value);\n\nexport const canonicalHex = (value: bigint): string => `0x${value.toString(16)}`;\n\n/** Parses a JSON-RPC quantity: `0x` and at least one hex digit — a bare `\"0x\"` is malformed. */\nexport const quantityBigInt = (value: unknown, field: string): bigint => {\n if (typeof value !== \"string\" || !/^0x[0-9a-fA-F]+$/.test(value)) {\n throw new ChainError(\"invalid-quantity\", `${field} must be a 0x quantity`);\n }\n return BigInt(value);\n};\n\nconst safeInteger = (value: unknown, field: string): number => {\n if (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n throw new ChainError(\"invalid-quantity\", `${field} must be a non-negative safe integer`);\n }\n return value;\n};\n\nconst quantity = (value: unknown, field: string): string => {\n if (typeof value !== \"string\") {\n throw new ChainError(\"invalid-quantity\", `${field} must be a 0x quantity string`);\n }\n if (CANONICAL_HEX.test(value)) {\n return value;\n }\n return canonicalHex(quantityBigInt(value, field));\n};\n\nconst hexBytes = (value: unknown, field: string): string => {\n if (typeof value !== \"string\" || !/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) {\n throw new ChainError(\"invalid-quantity\", `${field} must be 0x-prefixed bytes`);\n }\n return value.toLowerCase();\n};\n\nconst accessList = (value: unknown): ReadonlyArray<EvmAccessListEntry> => {\n if (!Array.isArray(value)) {\n throw new ChainError(\"invalid-request\", \"accessList must be an array\");\n }\n return value.map((entry): EvmAccessListEntry => {\n if (!isRecord(entry)) {\n throw new ChainError(\"invalid-address\", \"accessList entries must be objects\");\n }\n const keys = Object.keys(entry).sort();\n if (keys.length !== 2 || keys[0] !== \"address\" || keys[1] !== \"storageKeys\") {\n throw new ChainError(\n \"unknown-field\",\n `accessList entry fields must be exactly address+storageKeys, got ${keys.join(\",\")}`,\n );\n }\n const { address, storageKeys } = entry;\n if (typeof address !== \"string\" || !isEvmAddress(address)) {\n throw new ChainError(\"invalid-address\", \"accessList entry has an invalid address\");\n }\n if (!Array.isArray(storageKeys)) {\n throw new ChainError(\"invalid-quantity\", \"accessList storageKeys must be an array\");\n }\n return {\n address: checksumEvmAddress(address),\n storageKeys: storageKeys.map((k) => {\n if (typeof k !== \"string\" || !/^0x[0-9a-fA-F]{64}$/.test(k)) {\n throw new ChainError(\n \"invalid-quantity\",\n \"accessList storageKeys must be 32-byte hex strings\",\n );\n }\n return k.toLowerCase();\n }),\n };\n });\n};\n\n/** The EIP-155 part of a CAIP-2 `network` string, e.g. `eip155:1` → 1. */\nexport const networkChainId = (network: string): number => {\n const match = /^eip155:(\\d+)$/.exec(network);\n const idPart = match?.[1];\n if (idPart === undefined) {\n throw new ChainError(\"chain-id-mismatch\", `network is not an eip155 CAIP-2 id: ${network}`);\n }\n const id = Number(idPart);\n if (!Number.isSafeInteger(id)) {\n throw new ChainError(\"chain-id-mismatch\", `chain id is not a safe integer: ${network}`);\n }\n return id;\n};\n\nconst REQUIRED = {\n base: [\"chainId\", \"nonce\", \"gas\", \"value\", \"data\"],\n gasPrice: [\"gasPrice\"],\n accessList: [\"accessList\"],\n eip1559: [\"maxFeePerGas\", \"maxPriorityFeePerGas\"],\n} as const;\n\nconst ALLOWED = {\n base: [\"type\", \"chainId\", \"nonce\", \"gas\", \"value\", \"data\", \"to\"],\n legacy: [\"gasPrice\"],\n eip2930: [\"gasPrice\", \"accessList\"],\n eip1559: [\"accessList\", \"maxFeePerGas\", \"maxPriorityFeePerGas\"],\n eip7702: [\"accessList\", \"maxFeePerGas\", \"maxPriorityFeePerGas\", \"authorization\"],\n} as const;\n\nconst requireFields = (input: Record<string, unknown>, fields: ReadonlyArray<string>): void => {\n for (const field of fields) {\n if (input[field] === undefined) {\n throw new ChainError(\"invalid-request\", `tx.${field} is required`);\n }\n }\n};\n\nconst rejectUnknown = (\n input: Record<string, unknown>,\n type: \"legacy\" | \"eip2930\" | \"eip1559\" | \"eip7702\",\n): void => {\n const allowed = new Set<string>([...ALLOWED.base, ...ALLOWED[type]]);\n const unknown = Object.keys(input).filter((k) => !allowed.has(k));\n if (unknown.length > 0) {\n throw new ChainError(\n \"unknown-field\",\n `tx has unknown fields for ${type}: ${unknown.sort().join(\", \")}`,\n );\n }\n};\n\n/**\n * Canonicalizes an EVM transaction: exact key sets per type, all required fields present, `0x`\n * canonical quantities, EIP-55 addresses. Idempotent.\n */\nexport const normalizeEvmTransaction = (tx: unknown): EvmTransaction => {\n if (!isRecord(tx)) {\n throw new ChainError(\"invalid-request\", \"tx must be an object\");\n }\n const { type } = tx;\n if (type !== \"legacy\" && type !== \"eip2930\" && type !== \"eip1559\" && type !== \"eip7702\") {\n throw new ChainError(\n \"unsupported\",\n `transaction type ${String(type)} is not supported (legacy, eip2930, eip1559 and eip7702 only)`,\n );\n }\n rejectUnknown(tx, type);\n requireFields(tx, REQUIRED.base);\n const chainId = safeInteger(tx[\"chainId\"], \"chainId\");\n const nonce = safeInteger(tx[\"nonce\"], \"nonce\");\n const gas = quantity(tx[\"gas\"], \"gas\");\n const value = quantity(tx[\"value\"], \"value\");\n const data = hexBytes(tx[\"data\"], \"data\");\n const toRaw = tx[\"to\"];\n const to =\n toRaw === undefined\n ? undefined\n : typeof toRaw === \"string\" && isEvmAddress(toRaw)\n ? checksumEvmAddress(toRaw)\n : undefined;\n if (toRaw !== undefined && to === undefined) {\n throw new ChainError(\"invalid-address\", \"to must be a valid EVM address\");\n }\n const base = { chainId, nonce, gas, value, data, ...(to === undefined ? {} : { to }) };\n if (type === \"legacy\") {\n requireFields(tx, REQUIRED.gasPrice);\n return { type, ...base, gasPrice: quantity(tx[\"gasPrice\"], \"gasPrice\") };\n }\n if (type === \"eip2930\") {\n requireFields(tx, [...REQUIRED.gasPrice, ...REQUIRED.accessList]);\n return {\n type,\n ...base,\n gasPrice: quantity(tx[\"gasPrice\"], \"gasPrice\"),\n accessList: accessList(tx[\"accessList\"]),\n };\n }\n requireFields(tx, [...REQUIRED.accessList, ...REQUIRED.eip1559]);\n const fees = {\n maxFeePerGas: quantity(tx[\"maxFeePerGas\"], \"maxFeePerGas\"),\n maxPriorityFeePerGas: quantity(tx[\"maxPriorityFeePerGas\"], \"maxPriorityFeePerGas\"),\n };\n const list = accessList(tx[\"accessList\"]);\n if (type === \"eip1559\") {\n return { type, ...base, accessList: list, ...fees };\n }\n if (to === undefined) {\n throw new ChainError(\"invalid-request\", \"tx.to is required for eip7702\");\n }\n const auth = tx[\"authorization\"];\n if (!isRecord(auth) || Object.keys(auth).length !== 1 || typeof auth[\"address\"] !== \"string\") {\n throw new ChainError(\n \"invalid-request\",\n \"tx.authorization must be an object with exactly address\",\n );\n }\n const authAddress = checksumEvmAddress(auth[\"address\"]);\n if (\n authAddress !== EVM_DELEGATOR.address &&\n authAddress !== \"0x0000000000000000000000000000000000000000\"\n ) {\n throw new ChainError(\"unsupported\", \"authorization address is not supported\");\n }\n return {\n type,\n ...base,\n to,\n accessList: list,\n ...fees,\n authorization: { address: authAddress },\n };\n};\n","import * as TypedData from \"ox/TypedData\";\n\nimport { ChainError } from \"../index.ts\";\nimport { checksumEvmAddress } from \"./address.ts\";\nimport { isRecord } from \"./transaction.ts\";\n\ntype TypedDataField = {\n readonly name: string;\n readonly type: string;\n};\n\n/**\n * The subset of the EIP-712 document the wallet needs to see before handing it to ox's validator —\n * object with `types`, `primaryType`, `domain` and `message` of the right shapes.\n */\nexport type TypedDataInput = {\n readonly types: Record<string, ReadonlyArray<TypedDataField>>;\n readonly primaryType: string;\n readonly domain: Record<string, unknown>;\n readonly message: Record<string, unknown>;\n};\n\nconst isField = (value: unknown): value is TypedDataField =>\n isRecord(value) && typeof value[\"name\"] === \"string\" && typeof value[\"type\"] === \"string\";\n\nconst isTypedDataInput = (value: unknown): value is TypedDataInput => {\n if (!isRecord(value)) {\n return false;\n }\n const { types, primaryType, domain, message } = value;\n if (!isRecord(types)) {\n return false;\n }\n if (typeof primaryType !== \"string\" || primaryType === \"\") {\n return false;\n }\n if (!isRecord(domain)) {\n return false;\n }\n if (!isRecord(message)) {\n return false;\n }\n return Object.values(types).every((fields) => Array.isArray(fields) && fields.every(isField));\n};\n\nexport type ParsedTypedData = { readonly json: TypedDataInput };\n\n/** A message object inside the document's `message`. */\nexport type TypedDataMessage = Readonly<Record<string, unknown>>;\n\nexport const isTypedDataMessage = (value: unknown): value is TypedDataMessage =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/** `value` is an array of message objects (empty allowed). */\nexport const typedDataMessages = (value: unknown): ReadonlyArray<TypedDataMessage> | undefined =>\n Array.isArray(value) && value.every(isTypedDataMessage) ? value : undefined;\n\n/** The `Type field,Type field` signature of struct `name` in `types`. */\nexport const typedDataSignature = (\n types: TypedDataInput[\"types\"],\n name: string,\n): string | undefined => types[name]?.map((field) => `${field.type} ${field.name}`).join(\",\");\n\n/** Struct `name` has exactly `fields`, in order, no more. */\nexport const sameFields = (\n types: TypedDataInput[\"types\"],\n name: string,\n fields: ReadonlyArray<string>,\n): boolean => typedDataSignature(types, name) === fields.join(\",\");\n\n/** A hex `address` field value, checksummed; `undefined` when malformed. */\nexport const typedDataAddress = (value: unknown): string | undefined =>\n typeof value === \"string\" && /^0x[0-9a-fA-F]{40}$/.test(value)\n ? checksumEvmAddress(value)\n : undefined;\n\n/** A uint field value (safe-integer number, decimal or `0x` hex string) ≤ `max`. */\nexport const typedDataUint = (value: unknown, max: bigint): bigint | undefined => {\n let parsed: bigint;\n if (typeof value === \"number\" && Number.isSafeInteger(value)) {\n parsed = BigInt(value);\n } else if (typeof value === \"string\" && /^(?:[0-9]+|0x[0-9a-fA-F]+)$/.test(value)) {\n parsed = BigInt(value);\n } else {\n return undefined;\n }\n return parsed >= 0n && parsed <= max ? parsed : undefined;\n};\n\n/** The largest timestamp a permit/order expiry or a Safe field is allowed to carry. */\nexport const MAX_UINT48: bigint = 2n ** 48n - 1n;\n\nconst isHexBytes = (value: unknown): value is `0x${string}` =>\n typeof value === \"string\" && /^0x[0-9a-fA-F]*$/.test(value);\n\n/** A `bytes` field value: `0x`-prefixed hex of even length. */\nexport const typedDataBytes = (value: unknown): `0x${string}` | undefined =>\n isHexBytes(value) ? value : undefined;\n\n/** Parses the EIP-712 JSON source and validates its shape with ox. */\nexport const parseTypedData = (typedData: string): ParsedTypedData => {\n let json: unknown;\n try {\n json = JSON.parse(typedData);\n } catch {\n throw new ChainError(\"invalid-typed-data\", \"typedData is not valid JSON\");\n }\n if (!isTypedDataInput(json)) {\n throw new ChainError(\n \"invalid-typed-data\",\n \"typedData must be a JSON object with types, primaryType, domain and message\",\n );\n }\n try {\n TypedData.validate(json);\n } catch {\n throw new ChainError(\"invalid-typed-data\", \"typedData failed EIP-712 validation\");\n }\n return { json };\n};\n\n/**\n * `domain.chainId` as a number, when present: a safe non-negative integer given as a JSON number, a\n * decimal string or a `0x` hex string.\n */\nexport const domainChainId = (domain: Record<string, unknown>): number | undefined => {\n const { chainId } = domain;\n if (chainId === undefined) {\n return undefined;\n }\n const numeric =\n typeof chainId === \"number\"\n ? chainId\n : typeof chainId === \"string\" && /^(?:[0-9]+|0x[0-9a-fA-F]+)$/.test(chainId)\n ? Number(chainId)\n : Number.NaN;\n if (!Number.isSafeInteger(numeric) || numeric < 0) {\n throw new ChainError(\"invalid-typed-data\", \"typed-data domain.chainId is malformed\");\n }\n return numeric;\n};\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,gBAAgB,UAA2B,sBAAsB,KAAK,KAAK;AAExF,SAAgB,mBAAmB,SAAyB;CAC1D,IAAI,CAAC,aAAa,OAAO,GACvB,MAAM,IAAI,WAAW,mBAAmB,oBAAoB;CAE9D,MAAM,cAAc,QAAQ,SAAS,OAAO;CAC5C,QAAQ,OAAO,aAAa,EAAE,QAAQ,KAAK,CAAC;CAC5C,OAAO;AACT;;AAGA,SAAgB,wBAAwB,QAA4B;CAClE,MAAM,eACJ,OAAO,WAAW,MAAM,OAAO,OAAO,IAClC,SACA,OAAO,WAAW,KAChB,UAAU,MAAM,UAAU,MAAM,CAAC,CAAC,QAAQ,KAAK,IAC/C,KAAA;CACR,IAAI,iBAAiB,KAAA,KAAa,aAAa,OAAO,GACpD,MAAM,IAAI,WAAW,mBAAmB,qDAAqD;CAE/F,OAAO,mBAAmB,KAAK,WAAW,WAAW,aAAa,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG;AAC9F;;;;;;ACrBA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACN,SAAS;AACX;;AAGA,MAAa,wBAAwB;;AAGrC,MAAa,qBACX;AAEF,MAAa,UAAmC,YAAY,KAC1D,qDACF;AAEA,MAAM,aAAa,CACjB;CACE,MAAM;CACN,YAAY;EACV;GAAE,MAAM;GAAU,MAAM;EAAU;EAClC;GAAE,MAAM;GAAS,MAAM;EAAU;E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