@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,125 @@
1
+ import { ActionPayload, TransferAction, BridgeAction, ExecuteAction } from './types.mjs';
2
+
3
+ /**
4
+ * Veridex Protocol SDK - Payload Encoding/Decoding Utilities
5
+ */
6
+
7
+ /**
8
+ * Encode a transfer action payload
9
+ * Format: [actionType(1)] [token(32)] [recipient(32)] [amount(32)]
10
+ */
11
+ declare function encodeTransferAction(token: string, recipient: string, amount: bigint): string;
12
+ /**
13
+ * Encode a bridge action payload
14
+ * Format: [actionType(1)] [token(32)] [amount(32)] [targetChain(2)] [recipient(32)]
15
+ */
16
+ declare function encodeBridgeAction(token: string, amount: bigint, targetChain: number, recipient: string): string;
17
+ /**
18
+ * Encode an execute action payload (arbitrary contract call)
19
+ * Format: [actionType(1)] [target(32)] [value(32)] [dataLength(2)] [data(variable)]
20
+ */
21
+ declare function encodeExecuteAction(target: string, value: bigint, data: string): string;
22
+ /**
23
+ * Encode a config action payload
24
+ * Format: [actionType(1)] [configType(1)] [configData(variable)]
25
+ */
26
+ declare function encodeConfigAction(configType: number, configData: string): string;
27
+ /**
28
+ * Encode the full Veridex message payload that gets published via Wormhole
29
+ * Format: [version(1)] [userKeyHash(32)] [targetChain(2)] [nonce(32)] [pubKeyX(32)] [pubKeyY(32)] [actionPayload]
30
+ */
31
+ declare function encodeVeridexPayload(userKeyHash: string, targetChain: number, nonce: bigint, publicKeyX: bigint, publicKeyY: bigint, actionPayload: string): string;
32
+ /**
33
+ * Decode an action payload to determine its type and contents
34
+ */
35
+ declare function decodeActionPayload(payload: string): ActionPayload;
36
+ /**
37
+ * Decode a transfer action payload
38
+ */
39
+ declare function decodeTransferAction(payload: string): TransferAction;
40
+ /**
41
+ * Decode a bridge action payload
42
+ */
43
+ declare function decodeBridgeAction(payload: string): BridgeAction;
44
+ /**
45
+ * Decode an execute action payload
46
+ */
47
+ declare function decodeExecuteAction(payload: string): ExecuteAction;
48
+ /**
49
+ * Encode a Solana-compatible transfer action
50
+ * Solana uses: [actionType(1)] [amount(8 LE)] [recipient(32)]
51
+ */
52
+ declare function encodeSolanaTransferAction(amount: bigint, recipient: string): string;
53
+ /**
54
+ * Encode an Aptos-compatible transfer action
55
+ * Aptos uses: [actionType(1)] [amount(8 LE)] [recipient(32)]
56
+ */
57
+ declare function encodeAptosTransferAction(amount: bigint, recipient: string): string;
58
+ /**
59
+ * Encode a Sui-compatible transfer action
60
+ * Sui uses: [actionType(1)] [amount(8 LE)] [recipient(32)]
61
+ */
62
+ declare function encodeSuiTransferAction(amount: bigint, recipient: string): string;
63
+ /**
64
+ * Pad an address to 32 bytes (Wormhole standard)
65
+ * Supports both EVM addresses (0x...) and Solana addresses (base58)
66
+ */
67
+ declare function padTo32Bytes(address: string): string;
68
+ /**
69
+ * Trim a 32-byte hex to a 20-byte EVM address
70
+ */
71
+ declare function trimTo20Bytes(hex32: string): string;
72
+ /**
73
+ * Convert a Solana public key (base58) to bytes32
74
+ * @deprecated Use padTo32Bytes instead, which now handles both EVM and Solana addresses
75
+ */
76
+ declare function solanaAddressToBytes32(base58Address: string): string;
77
+ /**
78
+ * Format an amount with decimals for display
79
+ */
80
+ declare function formatAmount(amount: bigint, decimals?: number): string;
81
+ /**
82
+ * Parse an amount string with decimals to bigint
83
+ */
84
+ declare function parseAmount(amountStr: string, decimals?: number): bigint;
85
+ /**
86
+ * Generate a unique nonce for a transaction
87
+ */
88
+ declare function generateNonce(): bigint;
89
+ /**
90
+ * Create a message hash for signing (used in authenticateRawAndDispatch)
91
+ */
92
+ declare function createMessageHash(targetChain: number, actionPayload: string, nonce: bigint): string;
93
+ /**
94
+ * Create the challenge bytes for gasless dispatch (matches Hub's authenticateAndDispatch)
95
+ *
96
+ * The Hub contract passes raw packed bytes to WebAuthn.verify():
97
+ * abi.encodePacked(targetChain, actionPayload, userNonce, hubChainId)
98
+ *
99
+ * The WebAuthn library then base64url-encodes these bytes to match against clientDataJSON.
100
+ * We do NOT hash here - the challenge is the raw packed bytes.
101
+ *
102
+ * @param targetChain - Wormhole chain ID of the destination
103
+ * @param actionPayload - The action payload (hex string)
104
+ * @param nonce - User's current nonce
105
+ * @param hubChainId - Wormhole chain ID of the Hub (e.g., 30 for Base)
106
+ * @returns The packed bytes as hex string (NOT hashed)
107
+ */
108
+ declare function createGaslessMessageHash(targetChain: number, actionPayload: string, nonce: bigint, hubChainId: number): string;
109
+ /**
110
+ * Build the challenge bytes for WebAuthn signing (gasless flow)
111
+ * Returns raw packed bytes that match what the Hub contract expects
112
+ *
113
+ * @param targetChain - Wormhole chain ID of the destination
114
+ * @param actionPayload - The action payload (hex string)
115
+ * @param nonce - User's current nonce
116
+ * @param hubChainId - Wormhole chain ID of the Hub
117
+ * @returns Challenge bytes for WebAuthn signing (raw packed, not hashed)
118
+ */
119
+ declare function buildGaslessChallenge(targetChain: number, actionPayload: string, nonce: bigint, hubChainId: number): Uint8Array;
120
+ /**
121
+ * Build the challenge bytes for WebAuthn signing
122
+ */
123
+ declare function buildChallenge(userKeyHash: string, targetChain: number, nonce: bigint, actionPayload: string): Uint8Array;
124
+
125
+ export { buildChallenge, buildGaslessChallenge, createGaslessMessageHash, createMessageHash, decodeActionPayload, decodeBridgeAction, decodeExecuteAction, decodeTransferAction, encodeAptosTransferAction, encodeBridgeAction, encodeConfigAction, encodeExecuteAction, encodeSolanaTransferAction, encodeSuiTransferAction, encodeTransferAction, encodeVeridexPayload, formatAmount, generateNonce, padTo32Bytes, parseAmount, solanaAddressToBytes32, trimTo20Bytes };
@@ -0,0 +1,125 @@
1
+ import { ActionPayload, TransferAction, BridgeAction, ExecuteAction } from './types.js';
2
+
3
+ /**
4
+ * Veridex Protocol SDK - Payload Encoding/Decoding Utilities
5
+ */
6
+
7
+ /**
8
+ * Encode a transfer action payload
9
+ * Format: [actionType(1)] [token(32)] [recipient(32)] [amount(32)]
10
+ */
11
+ declare function encodeTransferAction(token: string, recipient: string, amount: bigint): string;
12
+ /**
13
+ * Encode a bridge action payload
14
+ * Format: [actionType(1)] [token(32)] [amount(32)] [targetChain(2)] [recipient(32)]
15
+ */
16
+ declare function encodeBridgeAction(token: string, amount: bigint, targetChain: number, recipient: string): string;
17
+ /**
18
+ * Encode an execute action payload (arbitrary contract call)
19
+ * Format: [actionType(1)] [target(32)] [value(32)] [dataLength(2)] [data(variable)]
20
+ */
21
+ declare function encodeExecuteAction(target: string, value: bigint, data: string): string;
22
+ /**
23
+ * Encode a config action payload
24
+ * Format: [actionType(1)] [configType(1)] [configData(variable)]
25
+ */
26
+ declare function encodeConfigAction(configType: number, configData: string): string;
27
+ /**
28
+ * Encode the full Veridex message payload that gets published via Wormhole
29
+ * Format: [version(1)] [userKeyHash(32)] [targetChain(2)] [nonce(32)] [pubKeyX(32)] [pubKeyY(32)] [actionPayload]
30
+ */
31
+ declare function encodeVeridexPayload(userKeyHash: string, targetChain: number, nonce: bigint, publicKeyX: bigint, publicKeyY: bigint, actionPayload: string): string;
32
+ /**
33
+ * Decode an action payload to determine its type and contents
34
+ */
35
+ declare function decodeActionPayload(payload: string): ActionPayload;
36
+ /**
37
+ * Decode a transfer action payload
38
+ */
39
+ declare function decodeTransferAction(payload: string): TransferAction;
40
+ /**
41
+ * Decode a bridge action payload
42
+ */
43
+ declare function decodeBridgeAction(payload: string): BridgeAction;
44
+ /**
45
+ * Decode an execute action payload
46
+ */
47
+ declare function decodeExecuteAction(payload: string): ExecuteAction;
48
+ /**
49
+ * Encode a Solana-compatible transfer action
50
+ * Solana uses: [actionType(1)] [amount(8 LE)] [recipient(32)]
51
+ */
52
+ declare function encodeSolanaTransferAction(amount: bigint, recipient: string): string;
53
+ /**
54
+ * Encode an Aptos-compatible transfer action
55
+ * Aptos uses: [actionType(1)] [amount(8 LE)] [recipient(32)]
56
+ */
57
+ declare function encodeAptosTransferAction(amount: bigint, recipient: string): string;
58
+ /**
59
+ * Encode a Sui-compatible transfer action
60
+ * Sui uses: [actionType(1)] [amount(8 LE)] [recipient(32)]
61
+ */
62
+ declare function encodeSuiTransferAction(amount: bigint, recipient: string): string;
63
+ /**
64
+ * Pad an address to 32 bytes (Wormhole standard)
65
+ * Supports both EVM addresses (0x...) and Solana addresses (base58)
66
+ */
67
+ declare function padTo32Bytes(address: string): string;
68
+ /**
69
+ * Trim a 32-byte hex to a 20-byte EVM address
70
+ */
71
+ declare function trimTo20Bytes(hex32: string): string;
72
+ /**
73
+ * Convert a Solana public key (base58) to bytes32
74
+ * @deprecated Use padTo32Bytes instead, which now handles both EVM and Solana addresses
75
+ */
76
+ declare function solanaAddressToBytes32(base58Address: string): string;
77
+ /**
78
+ * Format an amount with decimals for display
79
+ */
80
+ declare function formatAmount(amount: bigint, decimals?: number): string;
81
+ /**
82
+ * Parse an amount string with decimals to bigint
83
+ */
84
+ declare function parseAmount(amountStr: string, decimals?: number): bigint;
85
+ /**
86
+ * Generate a unique nonce for a transaction
87
+ */
88
+ declare function generateNonce(): bigint;
89
+ /**
90
+ * Create a message hash for signing (used in authenticateRawAndDispatch)
91
+ */
92
+ declare function createMessageHash(targetChain: number, actionPayload: string, nonce: bigint): string;
93
+ /**
94
+ * Create the challenge bytes for gasless dispatch (matches Hub's authenticateAndDispatch)
95
+ *
96
+ * The Hub contract passes raw packed bytes to WebAuthn.verify():
97
+ * abi.encodePacked(targetChain, actionPayload, userNonce, hubChainId)
98
+ *
99
+ * The WebAuthn library then base64url-encodes these bytes to match against clientDataJSON.
100
+ * We do NOT hash here - the challenge is the raw packed bytes.
101
+ *
102
+ * @param targetChain - Wormhole chain ID of the destination
103
+ * @param actionPayload - The action payload (hex string)
104
+ * @param nonce - User's current nonce
105
+ * @param hubChainId - Wormhole chain ID of the Hub (e.g., 30 for Base)
106
+ * @returns The packed bytes as hex string (NOT hashed)
107
+ */
108
+ declare function createGaslessMessageHash(targetChain: number, actionPayload: string, nonce: bigint, hubChainId: number): string;
109
+ /**
110
+ * Build the challenge bytes for WebAuthn signing (gasless flow)
111
+ * Returns raw packed bytes that match what the Hub contract expects
112
+ *
113
+ * @param targetChain - Wormhole chain ID of the destination
114
+ * @param actionPayload - The action payload (hex string)
115
+ * @param nonce - User's current nonce
116
+ * @param hubChainId - Wormhole chain ID of the Hub
117
+ * @returns Challenge bytes for WebAuthn signing (raw packed, not hashed)
118
+ */
119
+ declare function buildGaslessChallenge(targetChain: number, actionPayload: string, nonce: bigint, hubChainId: number): Uint8Array;
120
+ /**
121
+ * Build the challenge bytes for WebAuthn signing
122
+ */
123
+ declare function buildChallenge(userKeyHash: string, targetChain: number, nonce: bigint, actionPayload: string): Uint8Array;
124
+
125
+ export { buildChallenge, buildGaslessChallenge, createGaslessMessageHash, createMessageHash, decodeActionPayload, decodeBridgeAction, decodeExecuteAction, decodeTransferAction, encodeAptosTransferAction, encodeBridgeAction, encodeConfigAction, encodeExecuteAction, encodeSolanaTransferAction, encodeSuiTransferAction, encodeTransferAction, encodeVeridexPayload, formatAmount, generateNonce, padTo32Bytes, parseAmount, solanaAddressToBytes32, trimTo20Bytes };
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/payload.ts
21
+ var payload_exports = {};
22
+ __export(payload_exports, {
23
+ buildChallenge: () => buildChallenge,
24
+ buildGaslessChallenge: () => buildGaslessChallenge,
25
+ createGaslessMessageHash: () => createGaslessMessageHash,
26
+ createMessageHash: () => createMessageHash,
27
+ decodeActionPayload: () => decodeActionPayload,
28
+ decodeBridgeAction: () => decodeBridgeAction,
29
+ decodeExecuteAction: () => decodeExecuteAction,
30
+ decodeTransferAction: () => decodeTransferAction,
31
+ encodeAptosTransferAction: () => encodeAptosTransferAction,
32
+ encodeBridgeAction: () => encodeBridgeAction,
33
+ encodeConfigAction: () => encodeConfigAction,
34
+ encodeExecuteAction: () => encodeExecuteAction,
35
+ encodeSolanaTransferAction: () => encodeSolanaTransferAction,
36
+ encodeSuiTransferAction: () => encodeSuiTransferAction,
37
+ encodeTransferAction: () => encodeTransferAction,
38
+ encodeVeridexPayload: () => encodeVeridexPayload,
39
+ formatAmount: () => formatAmount,
40
+ generateNonce: () => generateNonce,
41
+ padTo32Bytes: () => padTo32Bytes,
42
+ parseAmount: () => parseAmount,
43
+ solanaAddressToBytes32: () => solanaAddressToBytes32,
44
+ trimTo20Bytes: () => trimTo20Bytes
45
+ });
46
+ module.exports = __toCommonJS(payload_exports);
47
+ var import_ethers = require("ethers");
48
+
49
+ // src/constants.ts
50
+ var ACTION_TRANSFER = 1;
51
+ var ACTION_EXECUTE = 2;
52
+ var ACTION_CONFIG = 3;
53
+ var ACTION_BRIDGE = 4;
54
+ var PROTOCOL_VERSION = 1;
55
+
56
+ // src/payload.ts
57
+ function encodeTransferAction(token, recipient, amount) {
58
+ const tokenPadded = padTo32Bytes(token);
59
+ const recipientPadded = padTo32Bytes(recipient);
60
+ const amountBytes = import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(amount), 32);
61
+ return import_ethers.ethers.concat([
62
+ import_ethers.ethers.toBeHex(ACTION_TRANSFER, 1),
63
+ tokenPadded,
64
+ recipientPadded,
65
+ amountBytes
66
+ ]);
67
+ }
68
+ function encodeBridgeAction(token, amount, targetChain, recipient) {
69
+ const tokenPadded = padTo32Bytes(token);
70
+ const amountBytes = import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(amount), 32);
71
+ const targetChainBytes = import_ethers.ethers.toBeHex(targetChain, 2);
72
+ const recipientPadded = padTo32Bytes(recipient);
73
+ return import_ethers.ethers.concat([
74
+ import_ethers.ethers.toBeHex(ACTION_BRIDGE, 1),
75
+ tokenPadded,
76
+ amountBytes,
77
+ targetChainBytes,
78
+ recipientPadded
79
+ ]);
80
+ }
81
+ function encodeExecuteAction(target, value, data) {
82
+ const targetPadded = padTo32Bytes(target);
83
+ const valueBytes = import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(value), 32);
84
+ const dataBytes = import_ethers.ethers.getBytes(data);
85
+ const dataLengthBytes = import_ethers.ethers.toBeHex(dataBytes.length, 2);
86
+ return import_ethers.ethers.concat([
87
+ import_ethers.ethers.toBeHex(ACTION_EXECUTE, 1),
88
+ targetPadded,
89
+ valueBytes,
90
+ dataLengthBytes,
91
+ data
92
+ ]);
93
+ }
94
+ function encodeConfigAction(configType, configData) {
95
+ return import_ethers.ethers.concat([
96
+ import_ethers.ethers.toBeHex(ACTION_CONFIG, 1),
97
+ import_ethers.ethers.toBeHex(configType, 1),
98
+ configData
99
+ ]);
100
+ }
101
+ function encodeVeridexPayload(userKeyHash, targetChain, nonce, publicKeyX, publicKeyY, actionPayload) {
102
+ return import_ethers.ethers.concat([
103
+ import_ethers.ethers.toBeHex(PROTOCOL_VERSION, 1),
104
+ userKeyHash,
105
+ import_ethers.ethers.toBeHex(targetChain, 2),
106
+ import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(nonce), 32),
107
+ import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(publicKeyX), 32),
108
+ import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(publicKeyY), 32),
109
+ actionPayload
110
+ ]);
111
+ }
112
+ function decodeActionPayload(payload) {
113
+ const data = import_ethers.ethers.getBytes(payload);
114
+ const actionType = data[0];
115
+ switch (actionType) {
116
+ case ACTION_TRANSFER:
117
+ return decodeTransferAction(payload);
118
+ case ACTION_BRIDGE:
119
+ return decodeBridgeAction(payload);
120
+ case ACTION_EXECUTE:
121
+ return decodeExecuteAction(payload);
122
+ default:
123
+ return { type: `unknown_${actionType}`, raw: payload };
124
+ }
125
+ }
126
+ function decodeTransferAction(payload) {
127
+ const data = import_ethers.ethers.getBytes(payload);
128
+ const tokenBytes = data.slice(1, 33);
129
+ const recipientBytes = data.slice(33, 65);
130
+ const amountBytes = data.slice(65, 97);
131
+ return {
132
+ type: "transfer",
133
+ token: trimTo20Bytes(import_ethers.ethers.hexlify(tokenBytes)),
134
+ recipient: trimTo20Bytes(import_ethers.ethers.hexlify(recipientBytes)),
135
+ amount: BigInt(import_ethers.ethers.hexlify(amountBytes))
136
+ };
137
+ }
138
+ function decodeBridgeAction(payload) {
139
+ const data = import_ethers.ethers.getBytes(payload);
140
+ const tokenBytes = data.slice(1, 33);
141
+ const amountBytes = data.slice(33, 65);
142
+ const targetChainByte0 = data[65];
143
+ const targetChainByte1 = data[66];
144
+ const recipientBytes = data.slice(67, 99);
145
+ const targetChain = (targetChainByte0 ?? 0) << 8 | (targetChainByte1 ?? 0);
146
+ return {
147
+ type: "bridge",
148
+ token: trimTo20Bytes(import_ethers.ethers.hexlify(tokenBytes)),
149
+ amount: BigInt(import_ethers.ethers.hexlify(amountBytes)),
150
+ targetChain,
151
+ recipient: import_ethers.ethers.hexlify(recipientBytes)
152
+ };
153
+ }
154
+ function decodeExecuteAction(payload) {
155
+ const data = import_ethers.ethers.getBytes(payload);
156
+ const targetBytes = data.slice(1, 33);
157
+ const valueBytes = data.slice(33, 65);
158
+ const dataLengthByte0 = data[65];
159
+ const dataLengthByte1 = data[66];
160
+ const dataLength = (dataLengthByte0 ?? 0) << 8 | (dataLengthByte1 ?? 0);
161
+ const callData = data.slice(67, 67 + dataLength);
162
+ return {
163
+ type: "execute",
164
+ target: trimTo20Bytes(import_ethers.ethers.hexlify(targetBytes)),
165
+ value: BigInt(import_ethers.ethers.hexlify(valueBytes)),
166
+ data: import_ethers.ethers.hexlify(callData)
167
+ };
168
+ }
169
+ function encodeSolanaTransferAction(amount, recipient) {
170
+ const amountBytes = Buffer.alloc(8);
171
+ amountBytes.writeBigUInt64LE(amount);
172
+ const recipientBytes = import_ethers.ethers.getBytes(recipient);
173
+ return import_ethers.ethers.hexlify(
174
+ Buffer.concat([
175
+ Buffer.from([ACTION_TRANSFER]),
176
+ amountBytes,
177
+ Buffer.from(recipientBytes)
178
+ ])
179
+ );
180
+ }
181
+ function encodeAptosTransferAction(amount, recipient) {
182
+ const amountBytes = Buffer.alloc(8);
183
+ amountBytes.writeBigUInt64LE(amount);
184
+ const recipientPadded = padTo32Bytes(recipient);
185
+ return import_ethers.ethers.hexlify(
186
+ Buffer.concat([
187
+ Buffer.from([ACTION_TRANSFER]),
188
+ amountBytes,
189
+ Buffer.from(import_ethers.ethers.getBytes(recipientPadded))
190
+ ])
191
+ );
192
+ }
193
+ function encodeSuiTransferAction(amount, recipient) {
194
+ const amountBytes = Buffer.alloc(8);
195
+ amountBytes.writeBigUInt64LE(amount);
196
+ const recipientPadded = padTo32Bytes(recipient);
197
+ return import_ethers.ethers.hexlify(
198
+ Buffer.concat([
199
+ Buffer.from([ACTION_TRANSFER]),
200
+ amountBytes,
201
+ Buffer.from(import_ethers.ethers.getBytes(recipientPadded))
202
+ ])
203
+ );
204
+ }
205
+ function padTo32Bytes(address) {
206
+ if (address.toLowerCase() === "native") {
207
+ return "0x" + "0".repeat(64);
208
+ }
209
+ if (address.startsWith("0x")) {
210
+ const hex2 = address.replace("0x", "");
211
+ if (!/^[0-9a-fA-F]*$/.test(hex2)) {
212
+ throw new Error(`Invalid address: ${address}. Expected hex string or 'native'.`);
213
+ }
214
+ return "0x" + hex2.padStart(64, "0");
215
+ }
216
+ const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
217
+ for (const char of address) {
218
+ if (!base58Chars.includes(char)) {
219
+ throw new Error(`Invalid address: ${address}. Contains invalid base58 character '${char}'.`);
220
+ }
221
+ }
222
+ let value = BigInt(0);
223
+ for (const char of address) {
224
+ value = value * 58n + BigInt(base58Chars.indexOf(char));
225
+ }
226
+ let hex = value.toString(16);
227
+ if (hex.length > 64) {
228
+ throw new Error(`Invalid address: ${address}. Decoded value too large for 32 bytes.`);
229
+ }
230
+ return "0x" + hex.padStart(64, "0");
231
+ }
232
+ function trimTo20Bytes(hex32) {
233
+ const clean = hex32.replace("0x", "");
234
+ return "0x" + clean.slice(-40);
235
+ }
236
+ function solanaAddressToBytes32(base58Address) {
237
+ return padTo32Bytes(base58Address);
238
+ }
239
+ function formatAmount(amount, decimals = 18) {
240
+ const divisor = 10n ** BigInt(decimals);
241
+ const whole = amount / divisor;
242
+ const fraction = amount % divisor;
243
+ if (fraction === 0n) {
244
+ return whole.toString();
245
+ }
246
+ const fractionStr = fraction.toString().padStart(decimals, "0");
247
+ const trimmedFraction = fractionStr.replace(/0+$/, "");
248
+ return `${whole}.${trimmedFraction}`;
249
+ }
250
+ function parseAmount(amountStr, decimals = 18) {
251
+ const parts = amountStr.split(".");
252
+ const whole = BigInt(parts[0] ?? "0");
253
+ if (parts.length === 1 || !parts[1]) {
254
+ return whole * 10n ** BigInt(decimals);
255
+ }
256
+ const fractionStr = parts[1].slice(0, decimals).padEnd(decimals, "0");
257
+ const fraction = BigInt(fractionStr);
258
+ return whole * 10n ** BigInt(decimals) + fraction;
259
+ }
260
+ function generateNonce() {
261
+ const timestamp = BigInt(Date.now());
262
+ const random = BigInt(Math.floor(Math.random() * 1e6));
263
+ return timestamp << 20n | random;
264
+ }
265
+ function createMessageHash(targetChain, actionPayload, nonce) {
266
+ return import_ethers.ethers.keccak256(
267
+ import_ethers.ethers.solidityPacked(
268
+ ["uint16", "bytes", "uint256"],
269
+ [targetChain, actionPayload, nonce]
270
+ )
271
+ );
272
+ }
273
+ function createGaslessMessageHash(targetChain, actionPayload, nonce, hubChainId) {
274
+ return import_ethers.ethers.solidityPacked(
275
+ ["uint16", "bytes", "uint256", "uint16"],
276
+ [targetChain, actionPayload, nonce, hubChainId]
277
+ );
278
+ }
279
+ function buildGaslessChallenge(targetChain, actionPayload, nonce, hubChainId) {
280
+ const packed = createGaslessMessageHash(targetChain, actionPayload, nonce, hubChainId);
281
+ return import_ethers.ethers.getBytes(packed);
282
+ }
283
+ function buildChallenge(userKeyHash, targetChain, nonce, actionPayload) {
284
+ const encoded = import_ethers.ethers.solidityPacked(
285
+ ["bytes32", "uint16", "uint256", "bytes"],
286
+ [userKeyHash, targetChain, nonce, actionPayload]
287
+ );
288
+ return import_ethers.ethers.getBytes(import_ethers.ethers.keccak256(encoded));
289
+ }
290
+ // Annotate the CommonJS export names for ESM import in node:
291
+ 0 && (module.exports = {
292
+ buildChallenge,
293
+ buildGaslessChallenge,
294
+ createGaslessMessageHash,
295
+ createMessageHash,
296
+ decodeActionPayload,
297
+ decodeBridgeAction,
298
+ decodeExecuteAction,
299
+ decodeTransferAction,
300
+ encodeAptosTransferAction,
301
+ encodeBridgeAction,
302
+ encodeConfigAction,
303
+ encodeExecuteAction,
304
+ encodeSolanaTransferAction,
305
+ encodeSuiTransferAction,
306
+ encodeTransferAction,
307
+ encodeVeridexPayload,
308
+ formatAmount,
309
+ generateNonce,
310
+ padTo32Bytes,
311
+ parseAmount,
312
+ solanaAddressToBytes32,
313
+ trimTo20Bytes
314
+ });
315
+ //# sourceMappingURL=payload.js.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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAAuB;;;ACahB,IAAM,kBAAkB;AACxB,IAAM,iBAAiB;AACvB,IAAM,gBAAgB;AACtB,IAAM,gBAAgB;AAGtB,IAAM,mBAAmB;;;ADDzB,SAAS,qBACd,OACA,WACA,QACQ;AACR,QAAM,cA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