@veridex/sdk 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/LICENSE +21 -0
  3. package/README.md +212 -0
  4. package/dist/chains/aptos/index.d.mts +140 -0
  5. package/dist/chains/aptos/index.d.ts +140 -0
  6. package/dist/chains/aptos/index.js +563 -0
  7. package/dist/chains/aptos/index.js.map +1 -0
  8. package/dist/chains/aptos/index.mjs +536 -0
  9. package/dist/chains/aptos/index.mjs.map +1 -0
  10. package/dist/chains/evm/index.d.mts +5 -0
  11. package/dist/chains/evm/index.d.ts +5 -0
  12. package/dist/chains/evm/index.js +1233 -0
  13. package/dist/chains/evm/index.js.map +1 -0
  14. package/dist/chains/evm/index.mjs +1205 -0
  15. package/dist/chains/evm/index.mjs.map +1 -0
  16. package/dist/chains/solana/index.d.mts +116 -0
  17. package/dist/chains/solana/index.d.ts +116 -0
  18. package/dist/chains/solana/index.js +513 -0
  19. package/dist/chains/solana/index.js.map +1 -0
  20. package/dist/chains/solana/index.mjs +491 -0
  21. package/dist/chains/solana/index.mjs.map +1 -0
  22. package/dist/chains/starknet/index.d.mts +172 -0
  23. package/dist/chains/starknet/index.d.ts +172 -0
  24. package/dist/chains/starknet/index.js +534 -0
  25. package/dist/chains/starknet/index.js.map +1 -0
  26. package/dist/chains/starknet/index.mjs +507 -0
  27. package/dist/chains/starknet/index.mjs.map +1 -0
  28. package/dist/chains/sui/index.d.mts +182 -0
  29. package/dist/chains/sui/index.d.ts +182 -0
  30. package/dist/chains/sui/index.js +560 -0
  31. package/dist/chains/sui/index.js.map +1 -0
  32. package/dist/chains/sui/index.mjs +533 -0
  33. package/dist/chains/sui/index.mjs.map +1 -0
  34. package/dist/constants.d.mts +150 -0
  35. package/dist/constants.d.ts +150 -0
  36. package/dist/constants.js +430 -0
  37. package/dist/constants.js.map +1 -0
  38. package/dist/constants.mjs +392 -0
  39. package/dist/constants.mjs.map +1 -0
  40. package/dist/index-0NXfbk0z.d.ts +637 -0
  41. package/dist/index-D0dLVjTA.d.mts +637 -0
  42. package/dist/index.d.mts +3101 -0
  43. package/dist/index.d.ts +3101 -0
  44. package/dist/index.js +13186 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/index.mjs +13011 -0
  47. package/dist/index.mjs.map +1 -0
  48. package/dist/payload.d.mts +125 -0
  49. package/dist/payload.d.ts +125 -0
  50. package/dist/payload.js +315 -0
  51. package/dist/payload.js.map +1 -0
  52. package/dist/payload.mjs +269 -0
  53. package/dist/payload.mjs.map +1 -0
  54. package/dist/queries/index.d.mts +148 -0
  55. package/dist/queries/index.d.ts +148 -0
  56. package/dist/queries/index.js +1533 -0
  57. package/dist/queries/index.js.map +1 -0
  58. package/dist/queries/index.mjs +1508 -0
  59. package/dist/queries/index.mjs.map +1 -0
  60. package/dist/types-ChIsqCiw.d.mts +565 -0
  61. package/dist/types-ChIsqCiw.d.ts +565 -0
  62. package/dist/types-FJL7j6gQ.d.mts +172 -0
  63. package/dist/types-FJL7j6gQ.d.ts +172 -0
  64. package/dist/types.d.mts +407 -0
  65. package/dist/types.d.ts +407 -0
  66. package/dist/types.js +19 -0
  67. package/dist/types.js.map +1 -0
  68. package/dist/types.mjs +1 -0
  69. package/dist/types.mjs.map +1 -0
  70. package/dist/utils.d.mts +81 -0
  71. package/dist/utils.d.ts +81 -0
  72. package/dist/utils.js +430 -0
  73. package/dist/utils.js.map +1 -0
  74. package/dist/utils.mjs +390 -0
  75. package/dist/utils.mjs.map +1 -0
  76. package/dist/wormhole.d.mts +167 -0
  77. package/dist/wormhole.d.ts +167 -0
  78. package/dist/wormhole.js +468 -0
  79. package/dist/wormhole.js.map +1 -0
  80. package/dist/wormhole.mjs +422 -0
  81. package/dist/wormhole.mjs.map +1 -0
  82. package/package.json +151 -0
@@ -0,0 +1,269 @@
1
+ // src/payload.ts
2
+ import { ethers } from "ethers";
3
+
4
+ // src/constants.ts
5
+ var ACTION_TRANSFER = 1;
6
+ var ACTION_EXECUTE = 2;
7
+ var ACTION_CONFIG = 3;
8
+ var ACTION_BRIDGE = 4;
9
+ var PROTOCOL_VERSION = 1;
10
+
11
+ // src/payload.ts
12
+ function encodeTransferAction(token, recipient, amount) {
13
+ const tokenPadded = padTo32Bytes(token);
14
+ const recipientPadded = padTo32Bytes(recipient);
15
+ const amountBytes = ethers.zeroPadValue(ethers.toBeHex(amount), 32);
16
+ return ethers.concat([
17
+ ethers.toBeHex(ACTION_TRANSFER, 1),
18
+ tokenPadded,
19
+ recipientPadded,
20
+ amountBytes
21
+ ]);
22
+ }
23
+ function encodeBridgeAction(token, amount, targetChain, recipient) {
24
+ const tokenPadded = padTo32Bytes(token);
25
+ const amountBytes = ethers.zeroPadValue(ethers.toBeHex(amount), 32);
26
+ const targetChainBytes = ethers.toBeHex(targetChain, 2);
27
+ const recipientPadded = padTo32Bytes(recipient);
28
+ return ethers.concat([
29
+ ethers.toBeHex(ACTION_BRIDGE, 1),
30
+ tokenPadded,
31
+ amountBytes,
32
+ targetChainBytes,
33
+ recipientPadded
34
+ ]);
35
+ }
36
+ function encodeExecuteAction(target, value, data) {
37
+ const targetPadded = padTo32Bytes(target);
38
+ const valueBytes = ethers.zeroPadValue(ethers.toBeHex(value), 32);
39
+ const dataBytes = ethers.getBytes(data);
40
+ const dataLengthBytes = ethers.toBeHex(dataBytes.length, 2);
41
+ return ethers.concat([
42
+ ethers.toBeHex(ACTION_EXECUTE, 1),
43
+ targetPadded,
44
+ valueBytes,
45
+ dataLengthBytes,
46
+ data
47
+ ]);
48
+ }
49
+ function encodeConfigAction(configType, configData) {
50
+ return ethers.concat([
51
+ ethers.toBeHex(ACTION_CONFIG, 1),
52
+ ethers.toBeHex(configType, 1),
53
+ configData
54
+ ]);
55
+ }
56
+ function encodeVeridexPayload(userKeyHash, targetChain, nonce, publicKeyX, publicKeyY, actionPayload) {
57
+ return ethers.concat([
58
+ ethers.toBeHex(PROTOCOL_VERSION, 1),
59
+ userKeyHash,
60
+ ethers.toBeHex(targetChain, 2),
61
+ ethers.zeroPadValue(ethers.toBeHex(nonce), 32),
62
+ ethers.zeroPadValue(ethers.toBeHex(publicKeyX), 32),
63
+ ethers.zeroPadValue(ethers.toBeHex(publicKeyY), 32),
64
+ actionPayload
65
+ ]);
66
+ }
67
+ function decodeActionPayload(payload) {
68
+ const data = ethers.getBytes(payload);
69
+ const actionType = data[0];
70
+ switch (actionType) {
71
+ case ACTION_TRANSFER:
72
+ return decodeTransferAction(payload);
73
+ case ACTION_BRIDGE:
74
+ return decodeBridgeAction(payload);
75
+ case ACTION_EXECUTE:
76
+ return decodeExecuteAction(payload);
77
+ default:
78
+ return { type: `unknown_${actionType}`, raw: payload };
79
+ }
80
+ }
81
+ function decodeTransferAction(payload) {
82
+ const data = ethers.getBytes(payload);
83
+ const tokenBytes = data.slice(1, 33);
84
+ const recipientBytes = data.slice(33, 65);
85
+ const amountBytes = data.slice(65, 97);
86
+ return {
87
+ type: "transfer",
88
+ token: trimTo20Bytes(ethers.hexlify(tokenBytes)),
89
+ recipient: trimTo20Bytes(ethers.hexlify(recipientBytes)),
90
+ amount: BigInt(ethers.hexlify(amountBytes))
91
+ };
92
+ }
93
+ function decodeBridgeAction(payload) {
94
+ const data = ethers.getBytes(payload);
95
+ const tokenBytes = data.slice(1, 33);
96
+ const amountBytes = data.slice(33, 65);
97
+ const targetChainByte0 = data[65];
98
+ const targetChainByte1 = data[66];
99
+ const recipientBytes = data.slice(67, 99);
100
+ const targetChain = (targetChainByte0 ?? 0) << 8 | (targetChainByte1 ?? 0);
101
+ return {
102
+ type: "bridge",
103
+ token: trimTo20Bytes(ethers.hexlify(tokenBytes)),
104
+ amount: BigInt(ethers.hexlify(amountBytes)),
105
+ targetChain,
106
+ recipient: ethers.hexlify(recipientBytes)
107
+ };
108
+ }
109
+ function decodeExecuteAction(payload) {
110
+ const data = ethers.getBytes(payload);
111
+ const targetBytes = data.slice(1, 33);
112
+ const valueBytes = data.slice(33, 65);
113
+ const dataLengthByte0 = data[65];
114
+ const dataLengthByte1 = data[66];
115
+ const dataLength = (dataLengthByte0 ?? 0) << 8 | (dataLengthByte1 ?? 0);
116
+ const callData = data.slice(67, 67 + dataLength);
117
+ return {
118
+ type: "execute",
119
+ target: trimTo20Bytes(ethers.hexlify(targetBytes)),
120
+ value: BigInt(ethers.hexlify(valueBytes)),
121
+ data: ethers.hexlify(callData)
122
+ };
123
+ }
124
+ function encodeSolanaTransferAction(amount, recipient) {
125
+ const amountBytes = Buffer.alloc(8);
126
+ amountBytes.writeBigUInt64LE(amount);
127
+ const recipientBytes = ethers.getBytes(recipient);
128
+ return ethers.hexlify(
129
+ Buffer.concat([
130
+ Buffer.from([ACTION_TRANSFER]),
131
+ amountBytes,
132
+ Buffer.from(recipientBytes)
133
+ ])
134
+ );
135
+ }
136
+ function encodeAptosTransferAction(amount, recipient) {
137
+ const amountBytes = Buffer.alloc(8);
138
+ amountBytes.writeBigUInt64LE(amount);
139
+ const recipientPadded = padTo32Bytes(recipient);
140
+ return ethers.hexlify(
141
+ Buffer.concat([
142
+ Buffer.from([ACTION_TRANSFER]),
143
+ amountBytes,
144
+ Buffer.from(ethers.getBytes(recipientPadded))
145
+ ])
146
+ );
147
+ }
148
+ function encodeSuiTransferAction(amount, recipient) {
149
+ const amountBytes = Buffer.alloc(8);
150
+ amountBytes.writeBigUInt64LE(amount);
151
+ const recipientPadded = padTo32Bytes(recipient);
152
+ return ethers.hexlify(
153
+ Buffer.concat([
154
+ Buffer.from([ACTION_TRANSFER]),
155
+ amountBytes,
156
+ Buffer.from(ethers.getBytes(recipientPadded))
157
+ ])
158
+ );
159
+ }
160
+ function padTo32Bytes(address) {
161
+ if (address.toLowerCase() === "native") {
162
+ return "0x" + "0".repeat(64);
163
+ }
164
+ if (address.startsWith("0x")) {
165
+ const hex2 = address.replace("0x", "");
166
+ if (!/^[0-9a-fA-F]*$/.test(hex2)) {
167
+ throw new Error(`Invalid address: ${address}. Expected hex string or 'native'.`);
168
+ }
169
+ return "0x" + hex2.padStart(64, "0");
170
+ }
171
+ const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
172
+ for (const char of address) {
173
+ if (!base58Chars.includes(char)) {
174
+ throw new Error(`Invalid address: ${address}. Contains invalid base58 character '${char}'.`);
175
+ }
176
+ }
177
+ let value = BigInt(0);
178
+ for (const char of address) {
179
+ value = value * 58n + BigInt(base58Chars.indexOf(char));
180
+ }
181
+ let hex = value.toString(16);
182
+ if (hex.length > 64) {
183
+ throw new Error(`Invalid address: ${address}. Decoded value too large for 32 bytes.`);
184
+ }
185
+ return "0x" + hex.padStart(64, "0");
186
+ }
187
+ function trimTo20Bytes(hex32) {
188
+ const clean = hex32.replace("0x", "");
189
+ return "0x" + clean.slice(-40);
190
+ }
191
+ function solanaAddressToBytes32(base58Address) {
192
+ return padTo32Bytes(base58Address);
193
+ }
194
+ function formatAmount(amount, decimals = 18) {
195
+ const divisor = 10n ** BigInt(decimals);
196
+ const whole = amount / divisor;
197
+ const fraction = amount % divisor;
198
+ if (fraction === 0n) {
199
+ return whole.toString();
200
+ }
201
+ const fractionStr = fraction.toString().padStart(decimals, "0");
202
+ const trimmedFraction = fractionStr.replace(/0+$/, "");
203
+ return `${whole}.${trimmedFraction}`;
204
+ }
205
+ function parseAmount(amountStr, decimals = 18) {
206
+ const parts = amountStr.split(".");
207
+ const whole = BigInt(parts[0] ?? "0");
208
+ if (parts.length === 1 || !parts[1]) {
209
+ return whole * 10n ** BigInt(decimals);
210
+ }
211
+ const fractionStr = parts[1].slice(0, decimals).padEnd(decimals, "0");
212
+ const fraction = BigInt(fractionStr);
213
+ return whole * 10n ** BigInt(decimals) + fraction;
214
+ }
215
+ function generateNonce() {
216
+ const timestamp = BigInt(Date.now());
217
+ const random = BigInt(Math.floor(Math.random() * 1e6));
218
+ return timestamp << 20n | random;
219
+ }
220
+ function createMessageHash(targetChain, actionPayload, nonce) {
221
+ return ethers.keccak256(
222
+ ethers.solidityPacked(
223
+ ["uint16", "bytes", "uint256"],
224
+ [targetChain, actionPayload, nonce]
225
+ )
226
+ );
227
+ }
228
+ function createGaslessMessageHash(targetChain, actionPayload, nonce, hubChainId) {
229
+ return ethers.solidityPacked(
230
+ ["uint16", "bytes", "uint256", "uint16"],
231
+ [targetChain, actionPayload, nonce, hubChainId]
232
+ );
233
+ }
234
+ function buildGaslessChallenge(targetChain, actionPayload, nonce, hubChainId) {
235
+ const packed = createGaslessMessageHash(targetChain, actionPayload, nonce, hubChainId);
236
+ return ethers.getBytes(packed);
237
+ }
238
+ function buildChallenge(userKeyHash, targetChain, nonce, actionPayload) {
239
+ const encoded = ethers.solidityPacked(
240
+ ["bytes32", "uint16", "uint256", "bytes"],
241
+ [userKeyHash, targetChain, nonce, actionPayload]
242
+ );
243
+ return ethers.getBytes(ethers.keccak256(encoded));
244
+ }
245
+ export {
246
+ buildChallenge,
247
+ buildGaslessChallenge,
248
+ createGaslessMessageHash,
249
+ createMessageHash,
250
+ decodeActionPayload,
251
+ decodeBridgeAction,
252
+ decodeExecuteAction,
253
+ decodeTransferAction,
254
+ encodeAptosTransferAction,
255
+ encodeBridgeAction,
256
+ encodeConfigAction,
257
+ encodeExecuteAction,
258
+ encodeSolanaTransferAction,
259
+ encodeSuiTransferAction,
260
+ encodeTransferAction,
261
+ encodeVeridexPayload,
262
+ formatAmount,
263
+ generateNonce,
264
+ padTo32Bytes,
265
+ parseAmount,
266
+ solanaAddressToBytes32,
267
+ trimTo20Bytes
268
+ };
269
+ //# sourceMappingURL=payload.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/payload.ts","../src/constants.ts"],"sourcesContent":["/**\n * Veridex Protocol SDK - Payload Encoding/Decoding Utilities\n */\n\nimport { ethers } from 'ethers';\nimport {\n ACTION_TRANSFER,\n ACTION_EXECUTE,\n ACTION_CONFIG,\n ACTION_BRIDGE,\n PROTOCOL_VERSION,\n} from './constants.js';\nimport type { TransferAction, BridgeAction, ExecuteAction, ActionPayload } from './types.js';\n\n// ============================================================================\n// Action Encoding\n// ============================================================================\n\n/**\n * Encode a transfer action payload\n * Format: [actionType(1)] [token(32)] [recipient(32)] [amount(32)]\n */\nexport function encodeTransferAction(\n token: string,\n recipient: string,\n amount: bigint\n): string {\n const tokenPadded = padTo32Bytes(token);\n const recipientPadded = padTo32Bytes(recipient);\n const amountBytes = ethers.zeroPadValue(ethers.toBeHex(amount), 32);\n\n return ethers.concat([\n ethers.toBeHex(ACTION_TRANSFER, 1),\n tokenPadded,\n recipientPadded,\n amountBytes,\n ]);\n}\n\n/**\n * Encode a bridge action payload\n * Format: [actionType(1)] [token(32)] [amount(32)] [targetChain(2)] [recipient(32)]\n */\nexport function encodeBridgeAction(\n token: string,\n amount: bigint,\n targetChain: number,\n recipient: string\n): string {\n const tokenPadded = padTo32Bytes(token);\n const amountBytes = ethers.zeroPadValue(ethers.toBeHex(amount), 32);\n const targetChainBytes = ethers.toBeHex(targetChain, 2);\n const recipientPadded = padTo32Bytes(recipient);\n\n return ethers.concat([\n ethers.toBeHex(ACTION_BRIDGE, 1),\n tokenPadded,\n amountBytes,\n targetChainBytes,\n recipientPadded,\n ]);\n}\n\n/**\n * Encode an execute action payload (arbitrary contract call)\n * Format: [actionType(1)] [target(32)] [value(32)] [dataLength(2)] [data(variable)]\n */\nexport function encodeExecuteAction(\n target: string,\n value: bigint,\n data: string\n): string {\n const targetPadded = padTo32Bytes(target);\n const valueBytes = ethers.zeroPadValue(ethers.toBeHex(value), 32);\n const dataBytes = ethers.getBytes(data);\n const dataLengthBytes = ethers.toBeHex(dataBytes.length, 2);\n\n return ethers.concat([\n ethers.toBeHex(ACTION_EXECUTE, 1),\n targetPadded,\n valueBytes,\n dataLengthBytes,\n data,\n ]);\n}\n\n/**\n * Encode a config action payload\n * Format: [actionType(1)] [configType(1)] [configData(variable)]\n */\nexport function encodeConfigAction(configType: number, configData: string): string {\n return ethers.concat([\n ethers.toBeHex(ACTION_CONFIG, 1),\n ethers.toBeHex(configType, 1),\n configData,\n ]);\n}\n\n// ============================================================================\n// Veridex Payload Encoding\n// ============================================================================\n\n/**\n * Encode the full Veridex message payload that gets published via Wormhole\n * Format: [version(1)] [userKeyHash(32)] [targetChain(2)] [nonce(32)] [pubKeyX(32)] [pubKeyY(32)] [actionPayload]\n */\nexport function encodeVeridexPayload(\n userKeyHash: string,\n targetChain: number,\n nonce: bigint,\n publicKeyX: bigint,\n publicKeyY: bigint,\n actionPayload: string\n): string {\n return ethers.concat([\n ethers.toBeHex(PROTOCOL_VERSION, 1),\n userKeyHash,\n ethers.toBeHex(targetChain, 2),\n ethers.zeroPadValue(ethers.toBeHex(nonce), 32),\n ethers.zeroPadValue(ethers.toBeHex(publicKeyX), 32),\n ethers.zeroPadValue(ethers.toBeHex(publicKeyY), 32),\n actionPayload,\n ]);\n}\n\n// ============================================================================\n// Action Decoding\n// ============================================================================\n\n/**\n * Decode an action payload to determine its type and contents\n */\nexport function decodeActionPayload(payload: string): ActionPayload {\n const data = ethers.getBytes(payload);\n const actionType = data[0];\n\n switch (actionType) {\n case ACTION_TRANSFER:\n return decodeTransferAction(payload);\n case ACTION_BRIDGE:\n return decodeBridgeAction(payload);\n case ACTION_EXECUTE:\n return decodeExecuteAction(payload);\n default:\n return { type: `unknown_${actionType}`, raw: payload };\n }\n}\n\n/**\n * Decode a transfer action payload\n */\nexport function decodeTransferAction(payload: string): TransferAction {\n const data = ethers.getBytes(payload);\n\n const tokenBytes = data.slice(1, 33);\n const recipientBytes = data.slice(33, 65);\n const amountBytes = data.slice(65, 97);\n\n return {\n type: 'transfer',\n token: trimTo20Bytes(ethers.hexlify(tokenBytes)),\n recipient: trimTo20Bytes(ethers.hexlify(recipientBytes)),\n amount: BigInt(ethers.hexlify(amountBytes)),\n };\n}\n\n/**\n * Decode a bridge action payload\n */\nexport function decodeBridgeAction(payload: string): BridgeAction {\n const data = ethers.getBytes(payload);\n\n const tokenBytes = data.slice(1, 33);\n const amountBytes = data.slice(33, 65);\n const targetChainByte0 = data[65];\n const targetChainByte1 = data[66];\n const recipientBytes = data.slice(67, 99);\n\n const targetChain = ((targetChainByte0 ?? 0) << 8) | (targetChainByte1 ?? 0);\n\n return {\n type: 'bridge',\n token: trimTo20Bytes(ethers.hexlify(tokenBytes)),\n amount: BigInt(ethers.hexlify(amountBytes)),\n targetChain,\n recipient: ethers.hexlify(recipientBytes),\n };\n}\n\n/**\n * Decode an execute action payload\n */\nexport function decodeExecuteAction(payload: string): ExecuteAction {\n const data = ethers.getBytes(payload);\n\n const targetBytes = data.slice(1, 33);\n const valueBytes = data.slice(33, 65);\n const dataLengthByte0 = data[65];\n const dataLengthByte1 = data[66];\n const dataLength = ((dataLengthByte0 ?? 0) << 8) | (dataLengthByte1 ?? 0);\n const callData = data.slice(67, 67 + dataLength);\n\n return {\n type: 'execute',\n target: trimTo20Bytes(ethers.hexlify(targetBytes)),\n value: BigInt(ethers.hexlify(valueBytes)),\n data: ethers.hexlify(callData),\n };\n}\n\n// ============================================================================\n// Chain-Specific Encodings\n// ============================================================================\n\n/**\n * Encode a Solana-compatible transfer action\n * Solana uses: [actionType(1)] [amount(8 LE)] [recipient(32)]\n */\nexport function encodeSolanaTransferAction(\n amount: bigint,\n recipient: string\n): string {\n const amountBytes = Buffer.alloc(8);\n amountBytes.writeBigUInt64LE(amount);\n\n const recipientBytes = ethers.getBytes(recipient);\n\n return ethers.hexlify(\n Buffer.concat([\n Buffer.from([ACTION_TRANSFER]),\n amountBytes,\n Buffer.from(recipientBytes),\n ])\n );\n}\n\n/**\n * Encode an Aptos-compatible transfer action\n * Aptos uses: [actionType(1)] [amount(8 LE)] [recipient(32)]\n */\nexport function encodeAptosTransferAction(\n amount: bigint,\n recipient: string\n): string {\n const amountBytes = Buffer.alloc(8);\n amountBytes.writeBigUInt64LE(amount);\n\n const recipientPadded = padTo32Bytes(recipient);\n\n return ethers.hexlify(\n Buffer.concat([\n Buffer.from([ACTION_TRANSFER]),\n amountBytes,\n Buffer.from(ethers.getBytes(recipientPadded)),\n ])\n );\n}\n\n/**\n * Encode a Sui-compatible transfer action\n * Sui uses: [actionType(1)] [amount(8 LE)] [recipient(32)]\n */\nexport function encodeSuiTransferAction(\n amount: bigint,\n recipient: string\n): string {\n const amountBytes = Buffer.alloc(8);\n amountBytes.writeBigUInt64LE(amount);\n\n const recipientPadded = padTo32Bytes(recipient);\n\n return ethers.hexlify(\n Buffer.concat([\n Buffer.from([ACTION_TRANSFER]),\n amountBytes,\n Buffer.from(ethers.getBytes(recipientPadded)),\n ])\n );\n}\n\n// ============================================================================\n// Address Utilities\n// ============================================================================\n\n/**\n * Pad an address to 32 bytes (Wormhole standard)\n * Supports both EVM addresses (0x...) and Solana addresses (base58)\n */\nexport function padTo32Bytes(address: string): string {\n // Handle native token - convert to zero address\n if (address.toLowerCase() === 'native') {\n return '0x' + '0'.repeat(64);\n }\n \n // If it starts with 0x, treat as hex\n if (address.startsWith('0x')) {\n const hex = address.replace('0x', '');\n // Validate that hex only contains valid hex characters\n if (!/^[0-9a-fA-F]*$/.test(hex)) {\n throw new Error(`Invalid address: ${address}. Expected hex string or 'native'.`);\n }\n return '0x' + hex.padStart(64, '0');\n }\n \n // Otherwise, assume base58 Solana address and decode it\n // Base58 character set (Bitcoin/Solana style - no 0, O, I, l)\n const base58Chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\n \n // Validate base58 characters\n for (const char of address) {\n if (!base58Chars.includes(char)) {\n throw new Error(`Invalid address: ${address}. Contains invalid base58 character '${char}'.`);\n }\n }\n \n // Decode base58 to bytes\n let value = BigInt(0);\n for (const char of address) {\n value = value * 58n + BigInt(base58Chars.indexOf(char));\n }\n \n // Convert to 32-byte hex\n let hex = value.toString(16);\n // Ensure it's not longer than 64 chars (32 bytes)\n if (hex.length > 64) {\n throw new Error(`Invalid address: ${address}. Decoded value too large for 32 bytes.`);\n }\n \n return '0x' + hex.padStart(64, '0');\n}\n\n/**\n * Trim a 32-byte hex to a 20-byte EVM address\n */\nexport function trimTo20Bytes(hex32: string): string {\n const clean = hex32.replace('0x', '');\n return '0x' + clean.slice(-40);\n}\n\n/**\n * Convert a Solana public key (base58) to bytes32\n * @deprecated Use padTo32Bytes instead, which now handles both EVM and Solana addresses\n */\nexport function solanaAddressToBytes32(base58Address: string): string {\n return padTo32Bytes(base58Address);\n}\n\n// ============================================================================\n// Amount Utilities\n// ============================================================================\n\n/**\n * Format an amount with decimals for display\n */\nexport function formatAmount(amount: bigint, decimals = 18): string {\n const divisor = 10n ** BigInt(decimals);\n const whole = amount / divisor;\n const fraction = amount % divisor;\n\n if (fraction === 0n) {\n return whole.toString();\n }\n\n const fractionStr = fraction.toString().padStart(decimals, '0');\n const trimmedFraction = fractionStr.replace(/0+$/, '');\n\n return `${whole}.${trimmedFraction}`;\n}\n\n/**\n * Parse an amount string with decimals to bigint\n */\nexport function parseAmount(amountStr: string, decimals = 18): bigint {\n const parts = amountStr.split('.');\n const whole = BigInt(parts[0] ?? '0');\n\n if (parts.length === 1 || !parts[1]) {\n return whole * (10n ** BigInt(decimals));\n }\n\n const fractionStr = parts[1].slice(0, decimals).padEnd(decimals, '0');\n const fraction = BigInt(fractionStr);\n\n return whole * (10n ** BigInt(decimals)) + fraction;\n}\n\n// ============================================================================\n// Nonce Utilities\n// ============================================================================\n\n/**\n * Generate a unique nonce for a transaction\n */\nexport function generateNonce(): bigint {\n const timestamp = BigInt(Date.now());\n const random = BigInt(Math.floor(Math.random() * 1000000));\n return (timestamp << 20n) | random;\n}\n\n/**\n * Create a message hash for signing (used in authenticateRawAndDispatch)\n */\nexport function createMessageHash(\n targetChain: number,\n actionPayload: string,\n nonce: bigint\n): string {\n return ethers.keccak256(\n ethers.solidityPacked(\n ['uint16', 'bytes', 'uint256'],\n [targetChain, actionPayload, nonce]\n )\n );\n}\n\n/**\n * Create the challenge bytes for gasless dispatch (matches Hub's authenticateAndDispatch)\n * \n * The Hub contract passes raw packed bytes to WebAuthn.verify():\n * abi.encodePacked(targetChain, actionPayload, userNonce, hubChainId)\n * \n * The WebAuthn library then base64url-encodes these bytes to match against clientDataJSON.\n * We do NOT hash here - the challenge is the raw packed bytes.\n * \n * @param targetChain - Wormhole chain ID of the destination\n * @param actionPayload - The action payload (hex string)\n * @param nonce - User's current nonce\n * @param hubChainId - Wormhole chain ID of the Hub (e.g., 30 for Base)\n * @returns The packed bytes as hex string (NOT hashed)\n */\nexport function createGaslessMessageHash(\n targetChain: number,\n actionPayload: string,\n nonce: bigint,\n hubChainId: number\n): string {\n // Return raw packed bytes - NO sha256 hash\n // The contract passes these bytes directly to WebAuthn.verify()\n return ethers.solidityPacked(\n ['uint16', 'bytes', 'uint256', 'uint16'],\n [targetChain, actionPayload, nonce, hubChainId]\n );\n}\n\n/**\n * Build the challenge bytes for WebAuthn signing (gasless flow)\n * Returns raw packed bytes that match what the Hub contract expects\n * \n * @param targetChain - Wormhole chain ID of the destination\n * @param actionPayload - The action payload (hex string)\n * @param nonce - User's current nonce\n * @param hubChainId - Wormhole chain ID of the Hub\n * @returns Challenge bytes for WebAuthn signing (raw packed, not hashed)\n */\nexport function buildGaslessChallenge(\n targetChain: number,\n actionPayload: string,\n nonce: bigint,\n hubChainId: number\n): Uint8Array {\n const packed = createGaslessMessageHash(targetChain, actionPayload, nonce, hubChainId);\n return ethers.getBytes(packed);\n}\n\n/**\n * Build the challenge bytes for WebAuthn signing\n */\nexport function buildChallenge(\n userKeyHash: string,\n targetChain: number,\n nonce: bigint,\n actionPayload: string\n): Uint8Array {\n const encoded = ethers.solidityPacked(\n ['bytes32', 'uint16', 'uint256', 'bytes'],\n [userKeyHash, targetChain, nonce, actionPayload]\n );\n return ethers.getBytes(ethers.keccak256(encoded));\n}\n","/**\n * Veridex Protocol SDK - Constants and Chain Configurations\n */\n\nimport type { ChainConfig } from './types.js';\n\n// ============================================================================\n// Action Type Constants\n// ============================================================================\n\nexport const ACTION_TYPES = {\n TRANSFER: 1,\n EXECUTE: 2,\n CONFIG: 3,\n BRIDGE: 4,\n} as const;\n\nexport const ACTION_TRANSFER = 1;\nexport const ACTION_EXECUTE = 2;\nexport const ACTION_CONFIG = 3;\nexport const ACTION_BRIDGE = 4;\n\n// Protocol version\nexport const PROTOCOL_VERSION = 1;\n\n// ============================================================================\n// Wormhole Chain IDs\n// ============================================================================\n\n/**\n * Wormhole Chain IDs organized by network\n * @see https://docs.wormhole.com/wormhole/reference/constants\n */\nexport const WORMHOLE_CHAIN_IDS = {\n MAINNET: {\n SOLANA: 1,\n ETHEREUM: 2,\n TERRA: 3,\n BSC: 4,\n POLYGON: 5,\n AVALANCHE: 6,\n OASIS: 7,\n ALGORAND: 8,\n AURORA: 9,\n FANTOM: 10,\n KARURA: 11,\n ACALA: 12,\n KLAYTN: 13,\n CELO: 14,\n NEAR: 15,\n MOONBEAM: 16,\n NEON: 17,\n TERRA2: 18,\n INJECTIVE: 19,\n OSMOSIS: 20,\n SUI: 21,\n APTOS: 22,\n ARBITRUM: 23,\n OPTIMISM: 24,\n GNOSIS: 25,\n PYTHNET: 26,\n XPLA: 28,\n BASE: 30,\n SEI: 32,\n ROOTSTOCK: 33,\n SCROLL: 34,\n MANTLE: 35,\n BLAST: 36,\n XLAYER: 37,\n LINEA: 38,\n BERACHAIN: 39,\n SEIEVM: 40,\n },\n TESTNET: {\n SOLANA_DEVNET: 1,\n GOERLI: 2,\n BSC_TESTNET: 4,\n POLYGON_MUMBAI: 5,\n AVALANCHE_FUJI: 6,\n FANTOM_TESTNET: 10,\n CELO_ALFAJORES: 14,\n MOONBASE_ALPHA: 16,\n SUI_TESTNET: 21,\n APTOS_TESTNET: 22,\n SEPOLIA: 10002,\n ARBITRUM_SEPOLIA: 10003,\n BASE_SEPOLIA: 10004,\n OPTIMISM_SEPOLIA: 10005,\n HOLESKY: 10006,\n POLYGON_SEPOLIA: 10007,\n SEI_ATLANTIC_2: 10066, // Sei Arctic-1 testnet (EVM)\n STARKNET_SEPOLIA: 50001, // Custom bridge (non-Wormhole, relayer-attested)\n },\n} as const;\n\n// Legacy flat exports for backward compatibility\nexport const WORMHOLE_CHAIN_IDS_FLAT = {\n // Mainnets\n SOLANA: 1,\n ETHEREUM: 2,\n TERRA: 3,\n BSC: 4,\n POLYGON: 5,\n AVALANCHE: 6,\n OASIS: 7,\n ALGORAND: 8,\n AURORA: 9,\n FANTOM: 10,\n KARURA: 11,\n ACALA: 12,\n KLAYTN: 13,\n CELO: 14,\n NEAR: 15,\n MOONBEAM: 16,\n NEON: 17,\n TERRA2: 18,\n INJECTIVE: 19,\n OSMOSIS: 20,\n SUI: 21,\n APTOS: 22,\n ARBITRUM: 23,\n OPTIMISM: 24,\n GNOSIS: 25,\n PYTHNET: 26,\n XPLA: 28,\n BASE: 30,\n SEI: 32,\n ROOTSTOCK: 33,\n SCROLL: 34,\n MANTLE: 35,\n BLAST: 36,\n XLAYER: 37,\n LINEA: 38,\n BERACHAIN: 39,\n SEIEVM: 40,\n\n // Testnets\n SOLANA_DEVNET: 1,\n GOERLI: 2,\n BSC_TESTNET: 4,\n POLYGON_MUMBAI: 5,\n AVALANCHE_FUJI: 6,\n FANTOM_TESTNET: 10,\n CELO_ALFAJORES: 14,\n MOONBASE_ALPHA: 16,\n SUI_TESTNET: 21,\n APTOS_TESTNET: 22,\n ARBITRUM_SEPOLIA: 10003,\n BASE_SEPOLIA: 10004,\n OPTIMISM_SEPOLIA: 10005,\n POLYGON_SEPOLIA: 10007,\n HOLESKY: 10006,\n STARKNET_SEPOLIA: 50001, // Custom bridge (non-Wormhole)\n} as const;\n\n// ============================================================================\n// Testnet Chain Configurations\n// ============================================================================\n\nexport const TESTNET_CHAINS: Record<string, ChainConfig> = {\n baseSepolia: {\n name: 'Base Sepolia',\n chainId: 84532,\n wormholeChainId: 10004,\n rpcUrl: 'https://sepolia.base.org', // Public CORS-friendly RPC\n explorerUrl: 'https://sepolia.basescan.org',\n isEvm: true,\n contracts: {\n hub: '0x66D87dE68327f48A099c5B9bE97020Feab9a7c82',\n vaultFactory: '0x40D9B16094808Fa48e73598E31AB964Cf15b475f',\n vaultImplementation: '0xcBEb49b0109E61c1C69C51D5D9483A3aD6D18258',\n wormholeCoreBridge: '0x79A1027a6A159502049F10906D333EC57E95F083',\n tokenBridge: '0x86F55A04690fd7815A3D802bD587e83eA888B239',\n },\n },\n optimismSepolia: {\n name: 'Optimism Sepolia',\n chainId: 11155420,\n wormholeChainId: 10005,\n rpcUrl: 'https://sepolia.optimism.io',\n explorerUrl: 'https://sepolia-optimism.etherscan.io',\n isEvm: true,\n contracts: {\n vaultFactory: '0xAbB421166E648953CDBE93c0078a0A794c56Fb84',\n vaultImplementation: '0xDCD7daEf1AC06f4a8392957cca4834F7a16c058D',\n wormholeCoreBridge: '0x31377888146f3253211EFEf5c676D41ECe7D58Fe',\n tokenBridge: '0x99737Ec4B815d816c49A385943baf0380e75c0Ac',\n },\n },\n arbitrumSepolia: {\n name: 'Arbitrum Sepolia',\n chainId: 421614,\n wormholeChainId: 10003,\n rpcUrl: 'https://sepolia-rollup.arbitrum.io/rpc',\n explorerUrl: 'https://sepolia.arbiscan.io',\n isEvm: true,\n contracts: {\n vaultFactory: '0xd36D3D5DB59d78f1E33813490F72DABC15C9B07c',\n vaultImplementation: '0xB10ACf39eBF17fc33F722cBD955b7aeCB0611bc4',\n wormholeCoreBridge: '0x6b9C8671cdDC8dEab9c719bB87cBd3e782bA6a35',\n tokenBridge: '0xC7A204bDBFe983FCD8d8E61D02b475D4073fF97e',\n },\n },\n seiTestnet: {\n name: 'Sei Atlantic-2',\n chainId: 1328,\n wormholeChainId: 40,\n rpcUrl: 'https://evm-rpc-testnet.sei-apis.com',\n explorerUrl: 'https://seitrace.com/?chain=atlantic-2',\n isEvm: true,\n contracts: {\n vaultFactory: '0x07F608AFf6d63b68029488b726d895c4Bb593038',\n vaultImplementation: '0xD66153fccFB6731fB6c4944FbD607ba86A76a1f6',\n wormholeCoreBridge: '0x0000000000000000000000000000000000000000', // Mock - not yet deployed\n },\n },\n solanaDevnet: {\n name: 'Solana Devnet',\n chainId: 0,\n wormholeChainId: 1,\n rpcUrl: 'https://api.devnet.solana.com',\n explorerUrl: 'https://explorer.solana.com',\n isEvm: false,\n contracts: {\n hub: 'AnyXHsqq9c2BiW4WgBcj6Aye7Ua7a7L7iSuwpfJxECJM',\n wormholeCoreBridge: '3u8hJUVTA4jH1wYAyUur7FFZVQ8H635K3tSHHF4ssjQ5',\n tokenBridge: 'DZnkkTmCiFWfYTfT41X3Rd1kDgozqzxWaHqsw6W4x2oe',\n },\n },\n aptosTestnet: {\n name: 'Aptos Testnet',\n chainId: 0,\n wormholeChainId: 22,\n rpcUrl: 'https://fullnode.testnet.aptoslabs.com/v1',\n explorerUrl: 'https://explorer.aptoslabs.com',\n isEvm: false,\n contracts: {\n hub: '0x1a89da9e9f8f0bc90d8d492890bd55fb261c6277d2a95dfcac70c268d0c23dcc',\n wormholeCoreBridge: '0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625',\n tokenBridge: '0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f',\n },\n },\n suiTestnet: {\n name: 'Sui Testnet',\n chainId: 0,\n wormholeChainId: 21,\n rpcUrl: 'https://fullnode.testnet.sui.io:443',\n explorerUrl: 'https://suiscan.xyz/testnet',\n isEvm: false,\n contracts: {\n hub: '0x35e99fdbbc1cde7e093da6f9e758ba2c4a077904bd64caee2fa6db5e6c4e9e37',\n wormholeCoreBridge: '0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790',\n },\n },\n starknetSepolia: {\n name: 'Starknet Sepolia',\n chainId: 0, // Native Starknet chain ID (SN_SEPOLIA = 0x534e5f5345504f4c4941)\n wormholeChainId: 50001, // Custom chain ID (50000+ reserved for non-Wormhole chains)\n rpcUrl: 'https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/tsOnfTBZDKMXcUA26OED-',\n explorerUrl: 'https://sepolia.starkscan.co',\n isEvm: false,\n contracts: {\n // Starknet spoke contract\n hub: '0x68adcc730ed6c355200d00f763825448497b9cdf7936ca121711e078c88e811',\n // Custom bridge contract (NOT Wormhole)\n wormholeCoreBridge: '0x2c458c1ae64556482b05cc2d3ee5b032ed114d68429dda2062c9849a5a725f8',\n },\n // Hub chain ID that Starknet bridge validates (Base Sepolia = 10004)\n hubChainId: 10004,\n },\n};\n\n// ============================================================================\n// Mainnet Chain Configurations\n// ============================================================================\n\nexport const MAINNET_CHAINS: Record<string, ChainConfig> = {\n ethereum: {\n name: 'Ethereum',\n chainId: 1,\n wormholeChainId: 2,\n rpcUrl: 'https://eth.llamarpc.com',\n explorerUrl: 'https://etherscan.io',\n isEvm: true,\n contracts: {\n wormholeCoreBridge: '0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B',\n tokenBridge: '0x3ee18B2214AFF97000D974cf647E7C347E8fa585',\n },\n },\n base: {\n name: 'Base',\n chainId: 8453,\n wormholeChainId: 30,\n rpcUrl: 'https://mainnet.base.org',\n explorerUrl: 'https://basescan.org',\n isEvm: true,\n contracts: {\n wormholeCoreBridge: '0xbebdb6C8ddC678FfA9f8748f85C815C556Dd8ac6',\n tokenBridge: '0x8d2de8d2f73F1F4cAB472AC9A881C9b123C79627',\n },\n },\n optimism: {\n name: 'Optimism',\n chainId: 10,\n wormholeChainId: 24,\n rpcUrl: 'https://mainnet.optimism.io',\n explorerUrl: 'https://optimistic.etherscan.io',\n isEvm: true,\n contracts: {\n wormholeCoreBridge: '0xEe91C335eab126dF5fDB3797EA9d6aD93aeC9722',\n tokenBridge: '0x1D68124e65faFC907325e3EDbF8c4d84499DAa8b',\n },\n },\n arbitrum: {\n name: 'Arbitrum',\n chainId: 42161,\n wormholeChainId: 23,\n rpcUrl: 'https://arb1.arbitrum.io/rpc',\n explorerUrl: 'https://arbiscan.io',\n isEvm: true,\n contracts: {\n wormholeCoreBridge: '0xa5f208e072434bC67592E4C49C1B991BA79BCA46',\n tokenBridge: '0x0b2402144Bb366A632D14B83F244D2e0e21bD39c',\n },\n },\n polygon: {\n name: 'Polygon',\n chainId: 137,\n wormholeChainId: 5,\n rpcUrl: 'https://polygon-rpc.com',\n explorerUrl: 'https://polygonscan.com',\n isEvm: true,\n contracts: {\n wormholeCoreBridge: '0x7A4B5a56256163F07b2C80A7cA55aBE66c4ec4d7',\n tokenBridge: '0x5a58505a96D1dbf8dF91cB21B54419FC36e93fdE',\n },\n },\n solana: {\n name: 'Solana',\n chainId: 0,\n wormholeChainId: 1,\n rpcUrl: 'https://api.mainnet-beta.solana.com',\n explorerUrl: 'https://explorer.solana.com',\n isEvm: false,\n contracts: {\n wormholeCoreBridge: 'worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth',\n tokenBridge: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',\n },\n },\n aptos: {\n name: 'Aptos',\n chainId: 0,\n wormholeChainId: 22,\n rpcUrl: 'https://fullnode.mainnet.aptoslabs.com/v1',\n explorerUrl: 'https://explorer.aptoslabs.com',\n isEvm: false,\n contracts: {\n wormholeCoreBridge: '0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625',\n tokenBridge: '0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f',\n },\n },\n sui: {\n name: 'Sui',\n chainId: 0,\n wormholeChainId: 21,\n rpcUrl: 'https://fullnode.mainnet.sui.io:443',\n explorerUrl: 'https://suiscan.xyz/mainnet',\n isEvm: false,\n contracts: {\n wormholeCoreBridge: '0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c',\n },\n },\n};\n\n// ============================================================================\n// Wormhole API Endpoints\n// ============================================================================\n\nexport const WORMHOLE_API = {\n MAINNET: 'https://api.wormholescan.io',\n TESTNET: 'https://api.testnet.wormholescan.io',\n GUARDIAN_RPC_MAINNET: 'https://wormhole-v2-mainnet-api.certus.one',\n GUARDIAN_RPC_TESTNET: 'https://wormhole-v2-testnet-api.certus.one',\n} as const;\n\n// ============================================================================\n// Hub Contract ABI (minimal)\n// ============================================================================\n\nexport const HUB_ABI = [\n 'function authenticateAndDispatch((bytes authenticatorData, string clientDataJSON, uint256 challengeIndex, uint256 typeIndex, uint256 r, uint256 s) auth, uint256 publicKeyX, uint256 publicKeyY, uint16 targetChain, bytes actionPayload) external payable returns (uint64 sequence)',\n 'function authenticateRawAndDispatch(uint256 r, uint256 s, bytes32 messageHash, uint256 publicKeyX, uint256 publicKeyY, uint16 targetChain, bytes actionPayload, uint256 nonce) external payable returns (uint64 sequence)',\n 'function getNonce(bytes32 userKeyHash) external view returns (uint256)',\n 'function encodeTransferAction(address token, address recipient, uint256 amount) external pure returns (bytes)',\n 'function encodeExecuteAction(address target, uint256 value, bytes data) external pure returns (bytes)',\n 'function encodeBridgeAction(bytes32 token, uint256 amount, uint16 targetChain, bytes32 recipient) external pure returns (bytes)',\n 'function messageFee() external view returns (uint256)',\n 'event Dispatched(bytes32 indexed userKeyHash, uint16 targetChain, uint256 nonce, uint64 sequence, bytes actionPayload)',\n] as const;\n\n// ============================================================================\n// Vault Factory ABI (minimal)\n// ============================================================================\n\nexport const VAULT_FACTORY_ABI = [\n 'function createVault(bytes32 userKeyHash) external returns (address)',\n 'function getVault(bytes32 userKeyHash) external view returns (address)',\n 'function vaultExists(bytes32 userKeyHash) external view returns (bool)',\n 'event VaultCreated(bytes32 indexed userKeyHash, address vault)',\n] as const;\n\n// ============================================================================\n// Vault ABI (minimal)\n// ============================================================================\n\nexport const VAULT_ABI = [\n 'function execute(address target, uint256 value, bytes data) external returns (bytes)',\n 'function executeFromHub(bytes32 vaaHash, uint16 emitterChain, bytes32 emitterAddress, bytes payload) external',\n 'function owner() external view returns (bytes32)',\n 'function hub() external view returns (address)',\n 'receive() external payable',\n] as const;\n"],"mappings":";AAIA,SAAS,cAAc;;;ACahB,IAAM,kBAAkB;AACxB,IAAM,iBAAiB;AACvB,IAAM,gBAAgB;AACtB,IAAM,gBAAgB;AAGtB,IAAM,mBAAm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;AAiBO,SAAS,yBACd,aACA,eACA,OACA,YACQ;AAGR,SAAO,OAAO;AAAA,IACZ,CAAC,UAAU,SAAS,WAAW,QAAQ;AAAA,IACvC,CAAC,aAAa,eAAe,OAAO,UAAU;AAAA,EAChD;AACF;AAYO,SAAS,sBACd,aACA,eACA,OACA,YACY;AACZ,QAAM,SAAS,yBAAyB,aAAa,eAAe,OAAO,UAAU;AACrF,SAAO,OAAO,SAAS,MAAM;AAC/B;AAKO,SAAS,eACd,aACA,aACA,OACA,eACY;AACZ,QAAM,UAAU,OAAO;AAAA,IACrB,CAAC,WAAW,UAAU,WAAW,OAAO;AAAA,IACxC,CAAC,aAAa,aAAa,OAAO,aAAa;AAAA,EACjD;AACA,SAAO,OAAO,SAAS,OAAO,UAAU,OAAO,CAAC;AAClD;","names":["hex"]}
@@ -0,0 +1,148 @@
1
+ import { QueryRequest as QueryRequest$1, QueryResponse as QueryResponse$1 } from '@wormhole-foundation/wormhole-query-sdk';
2
+
3
+ type QueryNetwork = 'mainnet' | 'testnet';
4
+ /**
5
+ * Configuration for calling the Wormhole Query Proxy.
6
+ *
7
+ * `apiKey` is required for hosted Query Proxy access.
8
+ * `endpoint` may be overridden for custom proxy deployments.
9
+ */
10
+ interface QueryConfig {
11
+ apiKey: string;
12
+ endpoint?: string;
13
+ timeoutMs?: number;
14
+ }
15
+ /**
16
+ * Re-exported Wormhole Query SDK types (type-only).
17
+ * These map directly to the request/response shapes expected by the Query Proxy.
18
+ */
19
+ type QueryRequest = QueryRequest$1;
20
+ type QueryResponse = QueryResponse$1;
21
+ type QueryOperationType = 'hubState' | 'portfolio';
22
+ interface HubStateQuery {
23
+ type: 'hubState';
24
+ wormholeChainId: number;
25
+ hubAddress: string;
26
+ }
27
+ interface PortfolioQuery {
28
+ type: 'portfolio';
29
+ walletAddress: string;
30
+ wormholeChainIds: readonly number[];
31
+ }
32
+ type QueryOperation = HubStateQuery | PortfolioQuery;
33
+
34
+ declare const WORMHOLE_QUERY_PROXY_URLS: {
35
+ readonly mainnet: "https://query.wormhole.com/v1/query";
36
+ readonly testnet: "https://testnet.query.wormhole.com/v1/query";
37
+ };
38
+ /**
39
+ * Wormhole Query Proxy rate limit: 6 queries per second.
40
+ * SDK callers should throttle requests accordingly.
41
+ */
42
+ declare const WORMHOLE_QUERY_RATE_LIMIT_PER_SECOND = 6;
43
+ /**
44
+ * Convenience set of Wormhole chain IDs commonly supported by Queries.
45
+ * This is not an exhaustive list of all Wormhole chains.
46
+ */
47
+ declare const WORMHOLE_QUERY_CHAIN_IDS: {
48
+ readonly ETHEREUM: 2;
49
+ readonly POLYGON: 5;
50
+ readonly ARBITRUM: 23;
51
+ readonly OPTIMISM: 24;
52
+ readonly BASE: 30;
53
+ };
54
+
55
+ type QueryHubStateNetwork = 'testnet' | 'mainnet';
56
+ type QueryHubStateOptions = {
57
+ /** Max response age in seconds (default: 60). */
58
+ maxAge?: number;
59
+ network?: QueryHubStateNetwork;
60
+ /** Maximum attempts including the first try (default: 4). */
61
+ maxAttempts?: number;
62
+ };
63
+ type HubStateResult = {
64
+ nonce: bigint;
65
+ isRegistered: boolean;
66
+ blockTime: number;
67
+ proof: Uint8Array;
68
+ /** Last action hash (Issue #9/#10 - for action-hash binding) */
69
+ lastActionHash?: string;
70
+ };
71
+ type QueryHubStateErrorCode = 'INVALID_ARGUMENT' | 'UNSUPPORTED_NETWORK' | 'MISSING_HUB_ADDRESS' | 'PROXY_HTTP_ERROR' | 'PROXY_RESPONSE_INVALID' | 'ATTESTATION_STALE' | 'QUERY_RESPONSE_INVALID';
72
+ declare class QueryHubStateError extends Error {
73
+ code: QueryHubStateErrorCode;
74
+ cause?: unknown;
75
+ constructor(code: QueryHubStateErrorCode, message: string, cause?: unknown);
76
+ }
77
+ /** * Fetch Guardian-attested Hub state directly from the Wormhole Query Proxy.
78
+ *
79
+ * Client-side only: this avoids relayer API costs and produces a Guardian-signed proof
80
+ * that can be forwarded to the relayer for on-chain verification/submission.
81
+ */
82
+ declare function queryHubState(userKeyHash: string, apiKey: string, options?: QueryHubStateOptions): Promise<HubStateResult>;
83
+
84
+ type QueryPortfolioNetwork = 'testnet' | 'mainnet';
85
+ type QueryPortfolioOptions = {
86
+ /** Max response age in seconds (default: 60). */
87
+ maxAge?: number;
88
+ network?: QueryPortfolioNetwork;
89
+ /** Maximum attempts including the first try (default: 4). */
90
+ maxAttempts?: number;
91
+ /** Cache TTL in ms (default: 30_000). */
92
+ cacheTtlMs?: number;
93
+ /** Request timeout in ms (default: 15_000 for testnet, 10_000 for mainnet). */
94
+ timeout?: number;
95
+ /** Override Query Proxy endpoint. */
96
+ endpoint?: string;
97
+ /** Override per-chain RPC URLs used for block tag lookups. */
98
+ rpcUrls?: Record<number, string>;
99
+ /** Override derived vault addresses for specific Wormhole chain IDs. */
100
+ vaultAddresses?: Record<number, string>;
101
+ /** Override token lists (ERC20 only) for specific Wormhole chain IDs. */
102
+ evmTokenAddresses?: Record<number, string[]>;
103
+ /** Additional Solana accounts to include in the Solana account query (base58). */
104
+ solanaAccounts?: string[];
105
+ /** Optional USD prices by symbol/address for aggregation (e.g. { USDC: 1 }). */
106
+ pricesUsd?: Record<string, number>;
107
+ };
108
+ type PortfolioBalance = {
109
+ assetId: string;
110
+ amount: bigint;
111
+ decimals?: number;
112
+ symbol?: string;
113
+ usdValue?: number;
114
+ };
115
+ type PortfolioChainErrorCode = 'UNSUPPORTED_CHAIN' | 'MISSING_VAULT' | 'MISSING_TOKENS' | 'ATTESTATION_STALE' | 'DECODE_ERROR';
116
+ type PortfolioChainResult = {
117
+ wormholeChainId: number;
118
+ chainName?: string;
119
+ vaultAddress?: string;
120
+ blockTime?: number;
121
+ balances: PortfolioBalance[];
122
+ error?: {
123
+ code: PortfolioChainErrorCode;
124
+ message: string;
125
+ };
126
+ };
127
+ type PortfolioResult = {
128
+ proof: Uint8Array;
129
+ totalUsd?: number;
130
+ chains: PortfolioChainResult[];
131
+ };
132
+ type QueryPortfolioErrorCode = 'INVALID_ARGUMENT' | 'NETWORK_ERROR' | 'PROXY_HTTP_ERROR' | 'PROXY_RESPONSE_INVALID' | 'QUERY_RESPONSE_INVALID';
133
+ declare class QueryPortfolioError extends Error {
134
+ code: QueryPortfolioErrorCode;
135
+ cause?: unknown;
136
+ constructor(code: QueryPortfolioErrorCode, message: string, cause?: unknown);
137
+ }
138
+ /**
139
+ * Fetch Guardian-attested vault balances across multiple chains in one Query Proxy request.
140
+ *
141
+ * Notes:
142
+ * - EVM balances are ERC20-only via `eth_call` (native ETH is not queryable via this query type).
143
+ * - Solana balance uses lamports of the Veridex vault PDA (plus optional extra accounts).
144
+ * - Aptos is included only if/when Wormhole Queries adds Aptos query types (currently returned as unsupported).
145
+ */
146
+ declare function queryPortfolio(userKeyHash: string, apiKey: string, options?: QueryPortfolioOptions): Promise<PortfolioResult>;
147
+
148
+ export { type HubStateQuery, type HubStateResult, type PortfolioBalance, type PortfolioChainErrorCode, type PortfolioChainResult, type PortfolioQuery, type PortfolioResult, type QueryConfig, QueryHubStateError, type QueryHubStateErrorCode, type QueryHubStateNetwork, type QueryHubStateOptions, type QueryNetwork, type QueryOperation, type QueryOperationType, QueryPortfolioError, type QueryPortfolioErrorCode, type QueryPortfolioNetwork, type QueryPortfolioOptions, type QueryRequest, type QueryResponse, WORMHOLE_QUERY_CHAIN_IDS, WORMHOLE_QUERY_PROXY_URLS, WORMHOLE_QUERY_RATE_LIMIT_PER_SECOND, queryHubState, queryPortfolio };
@@ -0,0 +1,148 @@
1
+ import { QueryRequest as QueryRequest$1, QueryResponse as QueryResponse$1 } from '@wormhole-foundation/wormhole-query-sdk';
2
+
3
+ type QueryNetwork = 'mainnet' | 'testnet';
4
+ /**
5
+ * Configuration for calling the Wormhole Query Proxy.
6
+ *
7
+ * `apiKey` is required for hosted Query Proxy access.
8
+ * `endpoint` may be overridden for custom proxy deployments.
9
+ */
10
+ interface QueryConfig {
11
+ apiKey: string;
12
+ endpoint?: string;
13
+ timeoutMs?: number;
14
+ }
15
+ /**
16
+ * Re-exported Wormhole Query SDK types (type-only).
17
+ * These map directly to the request/response shapes expected by the Query Proxy.
18
+ */
19
+ type QueryRequest = QueryRequest$1;
20
+ type QueryResponse = QueryResponse$1;
21
+ type QueryOperationType = 'hubState' | 'portfolio';
22
+ interface HubStateQuery {
23
+ type: 'hubState';
24
+ wormholeChainId: number;
25
+ hubAddress: string;
26
+ }
27
+ interface PortfolioQuery {
28
+ type: 'portfolio';
29
+ walletAddress: string;
30
+ wormholeChainIds: readonly number[];
31
+ }
32
+ type QueryOperation = HubStateQuery | PortfolioQuery;
33
+
34
+ declare const WORMHOLE_QUERY_PROXY_URLS: {
35
+ readonly mainnet: "https://query.wormhole.com/v1/query";
36
+ readonly testnet: "https://testnet.query.wormhole.com/v1/query";
37
+ };
38
+ /**
39
+ * Wormhole Query Proxy rate limit: 6 queries per second.
40
+ * SDK callers should throttle requests accordingly.
41
+ */
42
+ declare const WORMHOLE_QUERY_RATE_LIMIT_PER_SECOND = 6;
43
+ /**
44
+ * Convenience set of Wormhole chain IDs commonly supported by Queries.
45
+ * This is not an exhaustive list of all Wormhole chains.
46
+ */
47
+ declare const WORMHOLE_QUERY_CHAIN_IDS: {
48
+ readonly ETHEREUM: 2;
49
+ readonly POLYGON: 5;
50
+ readonly ARBITRUM: 23;
51
+ readonly OPTIMISM: 24;
52
+ readonly BASE: 30;
53
+ };
54
+
55
+ type QueryHubStateNetwork = 'testnet' | 'mainnet';
56
+ type QueryHubStateOptions = {
57
+ /** Max response age in seconds (default: 60). */
58
+ maxAge?: number;
59
+ network?: QueryHubStateNetwork;
60
+ /** Maximum attempts including the first try (default: 4). */
61
+ maxAttempts?: number;
62
+ };
63
+ type HubStateResult = {
64
+ nonce: bigint;
65
+ isRegistered: boolean;
66
+ blockTime: number;
67
+ proof: Uint8Array;
68
+ /** Last action hash (Issue #9/#10 - for action-hash binding) */
69
+ lastActionHash?: string;
70
+ };
71
+ type QueryHubStateErrorCode = 'INVALID_ARGUMENT' | 'UNSUPPORTED_NETWORK' | 'MISSING_HUB_ADDRESS' | 'PROXY_HTTP_ERROR' | 'PROXY_RESPONSE_INVALID' | 'ATTESTATION_STALE' | 'QUERY_RESPONSE_INVALID';
72
+ declare class QueryHubStateError extends Error {
73
+ code: QueryHubStateErrorCode;
74
+ cause?: unknown;
75
+ constructor(code: QueryHubStateErrorCode, message: string, cause?: unknown);
76
+ }
77
+ /** * Fetch Guardian-attested Hub state directly from the Wormhole Query Proxy.
78
+ *
79
+ * Client-side only: this avoids relayer API costs and produces a Guardian-signed proof
80
+ * that can be forwarded to the relayer for on-chain verification/submission.
81
+ */
82
+ declare function queryHubState(userKeyHash: string, apiKey: string, options?: QueryHubStateOptions): Promise<HubStateResult>;
83
+
84
+ type QueryPortfolioNetwork = 'testnet' | 'mainnet';
85
+ type QueryPortfolioOptions = {
86
+ /** Max response age in seconds (default: 60). */
87
+ maxAge?: number;
88
+ network?: QueryPortfolioNetwork;
89
+ /** Maximum attempts including the first try (default: 4). */
90
+ maxAttempts?: number;
91
+ /** Cache TTL in ms (default: 30_000). */
92
+ cacheTtlMs?: number;
93
+ /** Request timeout in ms (default: 15_000 for testnet, 10_000 for mainnet). */
94
+ timeout?: number;
95
+ /** Override Query Proxy endpoint. */
96
+ endpoint?: string;
97
+ /** Override per-chain RPC URLs used for block tag lookups. */
98
+ rpcUrls?: Record<number, string>;
99
+ /** Override derived vault addresses for specific Wormhole chain IDs. */
100
+ vaultAddresses?: Record<number, string>;
101
+ /** Override token lists (ERC20 only) for specific Wormhole chain IDs. */
102
+ evmTokenAddresses?: Record<number, string[]>;
103
+ /** Additional Solana accounts to include in the Solana account query (base58). */
104
+ solanaAccounts?: string[];
105
+ /** Optional USD prices by symbol/address for aggregation (e.g. { USDC: 1 }). */
106
+ pricesUsd?: Record<string, number>;
107
+ };
108
+ type PortfolioBalance = {
109
+ assetId: string;
110
+ amount: bigint;
111
+ decimals?: number;
112
+ symbol?: string;
113
+ usdValue?: number;
114
+ };
115
+ type PortfolioChainErrorCode = 'UNSUPPORTED_CHAIN' | 'MISSING_VAULT' | 'MISSING_TOKENS' | 'ATTESTATION_STALE' | 'DECODE_ERROR';
116
+ type PortfolioChainResult = {
117
+ wormholeChainId: number;
118
+ chainName?: string;
119
+ vaultAddress?: string;
120
+ blockTime?: number;
121
+ balances: PortfolioBalance[];
122
+ error?: {
123
+ code: PortfolioChainErrorCode;
124
+ message: string;
125
+ };
126
+ };
127
+ type PortfolioResult = {
128
+ proof: Uint8Array;
129
+ totalUsd?: number;
130
+ chains: PortfolioChainResult[];
131
+ };
132
+ type QueryPortfolioErrorCode = 'INVALID_ARGUMENT' | 'NETWORK_ERROR' | 'PROXY_HTTP_ERROR' | 'PROXY_RESPONSE_INVALID' | 'QUERY_RESPONSE_INVALID';
133
+ declare class QueryPortfolioError extends Error {
134
+ code: QueryPortfolioErrorCode;
135
+ cause?: unknown;
136
+ constructor(code: QueryPortfolioErrorCode, message: string, cause?: unknown);
137
+ }
138
+ /**
139
+ * Fetch Guardian-attested vault balances across multiple chains in one Query Proxy request.
140
+ *
141
+ * Notes:
142
+ * - EVM balances are ERC20-only via `eth_call` (native ETH is not queryable via this query type).
143
+ * - Solana balance uses lamports of the Veridex vault PDA (plus optional extra accounts).
144
+ * - Aptos is included only if/when Wormhole Queries adds Aptos query types (currently returned as unsupported).
145
+ */
146
+ declare function queryPortfolio(userKeyHash: string, apiKey: string, options?: QueryPortfolioOptions): Promise<PortfolioResult>;
147
+
148
+ export { type HubStateQuery, type HubStateResult, type PortfolioBalance, type PortfolioChainErrorCode, type PortfolioChainResult, type PortfolioQuery, type PortfolioResult, type QueryConfig, QueryHubStateError, type QueryHubStateErrorCode, type QueryHubStateNetwork, type QueryHubStateOptions, type QueryNetwork, type QueryOperation, type QueryOperationType, QueryPortfolioError, type QueryPortfolioErrorCode, type QueryPortfolioNetwork, type QueryPortfolioOptions, type QueryRequest, type QueryResponse, WORMHOLE_QUERY_CHAIN_IDS, WORMHOLE_QUERY_PROXY_URLS, WORMHOLE_QUERY_RATE_LIMIT_PER_SECOND, queryHubState, queryPortfolio };