@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,560 @@
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/chains/sui/index.ts
21
+ var sui_exports = {};
22
+ __export(sui_exports, {
23
+ SuiClient: () => SuiClient
24
+ });
25
+ module.exports = __toCommonJS(sui_exports);
26
+
27
+ // src/chains/sui/SuiClient.ts
28
+ var import_client = require("@mysten/sui/client");
29
+ var import_crypto = require("crypto");
30
+
31
+ // src/payload.ts
32
+ var import_ethers = require("ethers");
33
+
34
+ // src/constants.ts
35
+ var ACTION_TRANSFER = 1;
36
+ var ACTION_EXECUTE = 2;
37
+ var ACTION_BRIDGE = 4;
38
+
39
+ // src/payload.ts
40
+ function encodeTransferAction(token, recipient, amount) {
41
+ const tokenPadded = padTo32Bytes(token);
42
+ const recipientPadded = padTo32Bytes(recipient);
43
+ const amountBytes = import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(amount), 32);
44
+ return import_ethers.ethers.concat([
45
+ import_ethers.ethers.toBeHex(ACTION_TRANSFER, 1),
46
+ tokenPadded,
47
+ recipientPadded,
48
+ amountBytes
49
+ ]);
50
+ }
51
+ function encodeBridgeAction(token, amount, targetChain, recipient) {
52
+ const tokenPadded = padTo32Bytes(token);
53
+ const amountBytes = import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(amount), 32);
54
+ const targetChainBytes = import_ethers.ethers.toBeHex(targetChain, 2);
55
+ const recipientPadded = padTo32Bytes(recipient);
56
+ return import_ethers.ethers.concat([
57
+ import_ethers.ethers.toBeHex(ACTION_BRIDGE, 1),
58
+ tokenPadded,
59
+ amountBytes,
60
+ targetChainBytes,
61
+ recipientPadded
62
+ ]);
63
+ }
64
+ function encodeExecuteAction(target, value, data) {
65
+ const targetPadded = padTo32Bytes(target);
66
+ const valueBytes = import_ethers.ethers.zeroPadValue(import_ethers.ethers.toBeHex(value), 32);
67
+ const dataBytes = import_ethers.ethers.getBytes(data);
68
+ const dataLengthBytes = import_ethers.ethers.toBeHex(dataBytes.length, 2);
69
+ return import_ethers.ethers.concat([
70
+ import_ethers.ethers.toBeHex(ACTION_EXECUTE, 1),
71
+ targetPadded,
72
+ valueBytes,
73
+ dataLengthBytes,
74
+ data
75
+ ]);
76
+ }
77
+ function padTo32Bytes(address) {
78
+ if (address.toLowerCase() === "native") {
79
+ return "0x" + "0".repeat(64);
80
+ }
81
+ if (address.startsWith("0x")) {
82
+ const hex2 = address.replace("0x", "");
83
+ if (!/^[0-9a-fA-F]*$/.test(hex2)) {
84
+ throw new Error(`Invalid address: ${address}. Expected hex string or 'native'.`);
85
+ }
86
+ return "0x" + hex2.padStart(64, "0");
87
+ }
88
+ const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
89
+ for (const char of address) {
90
+ if (!base58Chars.includes(char)) {
91
+ throw new Error(`Invalid address: ${address}. Contains invalid base58 character '${char}'.`);
92
+ }
93
+ }
94
+ let value = BigInt(0);
95
+ for (const char of address) {
96
+ value = value * 58n + BigInt(base58Chars.indexOf(char));
97
+ }
98
+ let hex = value.toString(16);
99
+ if (hex.length > 64) {
100
+ throw new Error(`Invalid address: ${address}. Decoded value too large for 32 bytes.`);
101
+ }
102
+ return "0x" + hex.padStart(64, "0");
103
+ }
104
+
105
+ // src/chains/sui/SuiClient.ts
106
+ var SuiClient = class {
107
+ config;
108
+ client;
109
+ packageId;
110
+ hubRpcUrl;
111
+ hubContractAddress;
112
+ constructor(config) {
113
+ this.config = {
114
+ name: `Sui ${config.network || "mainnet"}`,
115
+ chainId: 0,
116
+ wormholeChainId: config.wormholeChainId,
117
+ rpcUrl: config.rpcUrl,
118
+ explorerUrl: config.network === "testnet" ? "https://suiscan.xyz/testnet" : config.network === "devnet" ? "https://suiscan.xyz/devnet" : "https://suiscan.xyz/mainnet",
119
+ isEvm: false,
120
+ contracts: {
121
+ hub: config.packageId,
122
+ wormholeCoreBridge: config.wormholeCoreBridge,
123
+ tokenBridge: config.tokenBridge
124
+ }
125
+ };
126
+ this.client = new import_client.SuiClient({ url: config.rpcUrl });
127
+ this.packageId = config.packageId;
128
+ this.hubRpcUrl = config.hubRpcUrl;
129
+ this.hubContractAddress = config.hubContractAddress;
130
+ }
131
+ getConfig() {
132
+ return this.config;
133
+ }
134
+ async getNonce(_userKeyHash) {
135
+ return 0n;
136
+ }
137
+ async getMessageFee() {
138
+ return 0n;
139
+ }
140
+ async buildTransferPayload(params) {
141
+ return encodeTransferAction(params.token, params.recipient, params.amount);
142
+ }
143
+ async buildExecutePayload(params) {
144
+ return encodeExecuteAction(params.target, params.value, params.data);
145
+ }
146
+ async buildBridgePayload(params) {
147
+ return encodeBridgeAction(params.token, params.amount, params.destinationChain, params.recipient);
148
+ }
149
+ async dispatch(signature, publicKeyX, publicKeyY, targetChain, actionPayload, nonce, signer) {
150
+ void signature;
151
+ void publicKeyX;
152
+ void publicKeyY;
153
+ void targetChain;
154
+ void actionPayload;
155
+ void nonce;
156
+ void signer;
157
+ throw new Error(
158
+ "Direct dispatch not supported on Sui spoke chains. Actions must be dispatched from the Hub (EVM) chain. "
159
+ );
160
+ }
161
+ async dispatchGasless(signature, publicKeyX, publicKeyY, targetChain, actionPayload, nonce, relayerUrl) {
162
+ const keyHash = this.computeKeyHash(publicKeyX, publicKeyY);
163
+ const messageHash = this.buildMessageHash(keyHash, targetChain, actionPayload, nonce);
164
+ const request = {
165
+ messageHash,
166
+ r: "0x" + signature.r.toString(16).padStart(64, "0"),
167
+ s: "0x" + signature.s.toString(16).padStart(64, "0"),
168
+ publicKeyX: "0x" + publicKeyX.toString(16).padStart(64, "0"),
169
+ publicKeyY: "0x" + publicKeyY.toString(16).padStart(64, "0"),
170
+ targetChain,
171
+ actionPayload,
172
+ nonce: Number(nonce)
173
+ };
174
+ const response = await fetch(`${relayerUrl}/api/v1/submit`, {
175
+ method: "POST",
176
+ headers: { "Content-Type": "application/json" },
177
+ body: JSON.stringify(request)
178
+ });
179
+ if (!response.ok) {
180
+ throw new Error(`Relayer submission failed: ${response.status} ${response.statusText}`);
181
+ }
182
+ const result = await response.json();
183
+ return {
184
+ transactionHash: result.transactionHash ?? result.txHash,
185
+ sequence: BigInt(result.sequence || 0),
186
+ userKeyHash: keyHash,
187
+ targetChain
188
+ };
189
+ }
190
+ async getVaultAddress(userKeyHash) {
191
+ return this.computeVaultAddress(userKeyHash);
192
+ }
193
+ computeVaultAddress(userKeyHash) {
194
+ const clean = userKeyHash.replace(/^0x/, "").padStart(64, "0");
195
+ return "0x" + clean;
196
+ }
197
+ async vaultExists(_userKeyHash) {
198
+ return true;
199
+ }
200
+ async createVault(userKeyHash, signer) {
201
+ void signer;
202
+ throw new Error(
203
+ `Vault creation on Sui must be done via cross-chain message from Hub. Use the Hub client to dispatch a vault creation action targeting Sui (chain ${this.config.wormholeChainId}). KeyHash=${userKeyHash}`
204
+ );
205
+ }
206
+ async createVaultSponsored(userKeyHash, sponsorPrivateKey, rpcUrl) {
207
+ void userKeyHash;
208
+ void sponsorPrivateKey;
209
+ void rpcUrl;
210
+ throw new Error(
211
+ "Vault creation on Sui must be done via cross-chain message from Hub. Use relayer gasless submission to create vault."
212
+ );
213
+ }
214
+ /**
215
+ * Create a vault via the relayer (sponsored/gasless)
216
+ * This is the recommended way to create Sui vaults
217
+ *
218
+ * The relayer will dispatch a vault creation action from Hub to Sui spoke
219
+ */
220
+ async createVaultViaRelayer(userKeyHash, relayerUrl) {
221
+ const response = await fetch(`${relayerUrl}/api/v1/sui/vault`, {
222
+ method: "POST",
223
+ headers: {
224
+ "Content-Type": "application/json"
225
+ },
226
+ body: JSON.stringify({
227
+ userKeyHash,
228
+ chainId: this.config.wormholeChainId
229
+ })
230
+ });
231
+ const result = await response.json();
232
+ if (!response.ok || !result.success) {
233
+ throw new Error(result.error || "Failed to create vault via relayer");
234
+ }
235
+ return {
236
+ address: result.vaultAddress,
237
+ transactionHash: result.transactionHash || "",
238
+ blockNumber: 0,
239
+ gasUsed: 0n,
240
+ alreadyExisted: result.alreadyExists || false,
241
+ sponsoredBy: "relayer"
242
+ };
243
+ }
244
+ /**
245
+ * Get vault info via relayer (includes existence check)
246
+ */
247
+ async getVaultViaRelayer(userKeyHash, relayerUrl) {
248
+ const response = await fetch(
249
+ `${relayerUrl}/api/v1/sui/vault/${userKeyHash}?chainId=${this.config.wormholeChainId}`
250
+ );
251
+ if (!response.ok) {
252
+ throw new Error("Failed to get vault info from relayer");
253
+ }
254
+ const result = await response.json();
255
+ return {
256
+ vaultAddress: result.vaultAddress,
257
+ exists: result.exists
258
+ };
259
+ }
260
+ async estimateVaultCreationGas(_userKeyHash) {
261
+ return 5000n;
262
+ }
263
+ getFactoryAddress() {
264
+ return void 0;
265
+ }
266
+ getImplementationAddress() {
267
+ return void 0;
268
+ }
269
+ // ========================================================================
270
+ // Balance utilities (used by VeridexSDK multichain)
271
+ // ========================================================================
272
+ async getNativeBalance(address) {
273
+ const balance = await this.client.getBalance({ owner: address });
274
+ return BigInt(balance.totalBalance);
275
+ }
276
+ async getTokenBalance(coinType, ownerAddress) {
277
+ const balance = await this.client.getBalance({ owner: ownerAddress, coinType });
278
+ return BigInt(balance.totalBalance);
279
+ }
280
+ getClient() {
281
+ return this.client;
282
+ }
283
+ getPackageId() {
284
+ return this.packageId;
285
+ }
286
+ // ========================================================================
287
+ // Session Management (Issue #13)
288
+ // ========================================================================
289
+ /**
290
+ * Register a session key on the Hub (must be called via Hub client)
291
+ * Sui spokes validate sessions via CCQ, but registration happens on Hub
292
+ *
293
+ * @throws Error - Session management must be done via Hub chain
294
+ */
295
+ async registerSession(_params) {
296
+ throw new Error(
297
+ "Session registration must be performed on the Hub chain (Base). Use EVMClient connected to the Hub to call registerSession()."
298
+ );
299
+ }
300
+ /**
301
+ * Revoke a session key on the Hub (must be called via Hub client)
302
+ *
303
+ * @throws Error - Session management must be done via Hub chain
304
+ */
305
+ async revokeSession(_params) {
306
+ throw new Error(
307
+ "Session revocation must be performed on the Hub chain (Base). Use EVMClient connected to the Hub to call revokeSession()."
308
+ );
309
+ }
310
+ /**
311
+ * Check if a session is active by querying the Hub
312
+ * This method queries the Hub contract directly for session validation
313
+ *
314
+ * @param userKeyHash - Hash of user's Passkey public key
315
+ * @param sessionKeyHash - Hash of session key to validate
316
+ * @returns Session validation result with expiry and limits
317
+ */
318
+ async isSessionActive(_userKeyHash, _sessionKeyHash) {
319
+ if (!this.hubRpcUrl || !this.hubContractAddress) {
320
+ throw new Error(
321
+ "Hub configuration required for session validation. Provide hubRpcUrl and hubContractAddress in SuiClientConfig."
322
+ );
323
+ }
324
+ throw new Error(
325
+ "isSessionActive requires Hub client integration. Use EVMClient.isSessionActive() on the Hub chain, then pass the result to session execution on Sui."
326
+ );
327
+ }
328
+ /**
329
+ * Get all sessions for a user from the Hub
330
+ *
331
+ * @param userKeyHash - Hash of user's Passkey public key
332
+ * @returns Array of all sessions (active and expired/revoked)
333
+ */
334
+ async getUserSessions(userKeyHash) {
335
+ if (!this.hubRpcUrl || !this.hubContractAddress) {
336
+ throw new Error(
337
+ "Hub configuration required for session queries. Provide hubRpcUrl and hubContractAddress in SuiClientConfig."
338
+ );
339
+ }
340
+ throw new Error(
341
+ `getUserSessions requires Hub client integration. Use EVMClient.getUserSessions() on the Hub chain. User: ${userKeyHash}`
342
+ );
343
+ }
344
+ // ========================================================================
345
+ // Query-Based Execution (Issue #9/#10)
346
+ // ========================================================================
347
+ /**
348
+ * Get user state from Hub (comprehensive state query)
349
+ * Returns key hash, nonce, and last action hash for CCQ validation
350
+ *
351
+ * @param userKeyHash - Hash of user's Passkey public key
352
+ * @returns User state with nonce and last action hash
353
+ */
354
+ async getUserState(userKeyHash) {
355
+ if (!this.hubRpcUrl || !this.hubContractAddress) {
356
+ throw new Error(
357
+ "Hub configuration required for state queries. Provide hubRpcUrl and hubContractAddress in SuiClientConfig."
358
+ );
359
+ }
360
+ throw new Error(
361
+ `getUserState requires Hub client integration. Use EVMClient.getUserState() on the Hub chain. User: ${userKeyHash}`
362
+ );
363
+ }
364
+ /**
365
+ * Get user's last action hash from Hub
366
+ * Used for optimistic execution and nonce validation
367
+ *
368
+ * @param userKeyHash - Hash of user's Passkey public key
369
+ * @returns Last action hash (zero hash if no actions)
370
+ */
371
+ async getUserLastActionHash(userKeyHash) {
372
+ if (!this.hubRpcUrl || !this.hubContractAddress) {
373
+ throw new Error(
374
+ "Hub configuration required for action hash queries. Provide hubRpcUrl and hubContractAddress in SuiClientConfig."
375
+ );
376
+ }
377
+ throw new Error(
378
+ `getUserLastActionHash requires Hub client integration. Use EVMClient.getUserLastActionHash() on the Hub chain. User: ${userKeyHash}`
379
+ );
380
+ }
381
+ /**
382
+ * Execute with query-based validation (faster than VAA, ~23s vs 60-90s)
383
+ * Uses Wormhole CCQ to validate Hub state, then executes on Sui
384
+ *
385
+ * @param params Query execution parameters with CCQ response
386
+ * @returns Dispatch result with transaction hash
387
+ *
388
+ * @remarks
389
+ * Query-based execution flow:
390
+ * 1. Query Hub state via Wormhole CCQ
391
+ * 2. Validate Guardian signatures on query response
392
+ * 3. Execute on Sui with validated state
393
+ * 4. Hub state must be < 60s stale (enforced by QueryVerifier)
394
+ */
395
+ async executeWithQuery(_params) {
396
+ throw new Error(
397
+ "Query-based execution on Sui requires relayer integration. Use relayer API to submit query-validated transactions. Relayer will call veridex_spoke::execute_with_query on Sui."
398
+ );
399
+ }
400
+ // ========================================================================
401
+ // Internal helpers
402
+ // ========================================================================
403
+ computeKeyHash(publicKeyX, publicKeyY) {
404
+ const xHex = publicKeyX.toString(16).padStart(64, "0");
405
+ const yHex = publicKeyY.toString(16).padStart(64, "0");
406
+ const combined = Buffer.from(xHex + yHex, "hex");
407
+ const hash = (0, import_crypto.createHash)("sha256").update(combined).digest("hex");
408
+ return "0x" + hash;
409
+ }
410
+ buildMessageHash(keyHash, targetChain, actionPayload, nonce) {
411
+ const keyHashBuffer = Buffer.from(keyHash.replace(/^0x/, ""), "hex");
412
+ const targetChainBuffer = Buffer.alloc(2);
413
+ targetChainBuffer.writeUInt16BE(targetChain);
414
+ const payloadBuffer = Buffer.from(actionPayload.replace(/^0x/, ""), "hex");
415
+ const nonceHex = nonce.toString(16).padStart(64, "0");
416
+ const nonceBuffer = Buffer.from(nonceHex, "hex");
417
+ const combined = Buffer.concat([keyHashBuffer, targetChainBuffer, payloadBuffer, nonceBuffer]);
418
+ const hash = (0, import_crypto.createHash)("sha256").update(combined).digest("hex");
419
+ return "0x" + hash;
420
+ }
421
+ // ============================================================================
422
+ // Social Recovery Methods (Issue #23)
423
+ // ============================================================================
424
+ //
425
+ // Note: Social recovery is managed on the Hub chain (EVM).
426
+ // Sui spokes receive and execute recovery VAAs broadcast from the Hub.
427
+ // The relayer service handles submitting recovery transactions to Sui.
428
+ //
429
+ // SDK users should use EVMClient methods for guardian management and
430
+ // recovery initiation on the Hub chain.
431
+ // ============================================================================
432
+ /**
433
+ * Get vault object ID by owner key hash
434
+ *
435
+ * @param ownerKeyHash - Owner's passkey hash (32 bytes as hex)
436
+ * @param configObjectId - Shared Config object ID
437
+ * @param registryObjectId - Shared VaultRegistry object ID
438
+ * @returns Vault object ID or null if not found
439
+ */
440
+ async getVaultId(ownerKeyHash, registryObjectId) {
441
+ try {
442
+ const registryObject = await this.client.getObject({
443
+ id: registryObjectId,
444
+ options: { showContent: true }
445
+ });
446
+ if (!registryObject.data?.content) {
447
+ return null;
448
+ }
449
+ console.warn("getVaultId requires dynamic field query - use Move view function");
450
+ return null;
451
+ } catch (error) {
452
+ console.error("Error getting vault ID:", error);
453
+ return null;
454
+ }
455
+ }
456
+ /**
457
+ * Get vault owner key hash from vault object
458
+ *
459
+ * @param vaultObjectId - Vault object ID
460
+ * @returns Owner key hash as hex string
461
+ */
462
+ async getVaultOwner(vaultObjectId) {
463
+ try {
464
+ const vaultObject = await this.client.getObject({
465
+ id: vaultObjectId,
466
+ options: { showContent: true }
467
+ });
468
+ if (!vaultObject.data?.content || vaultObject.data.content.dataType !== "moveObject") {
469
+ return null;
470
+ }
471
+ const fields = vaultObject.data.content.fields;
472
+ const ownerKeyHash = fields["owner_key_hash"];
473
+ if (!ownerKeyHash) {
474
+ return null;
475
+ }
476
+ return "0x" + Buffer.from(ownerKeyHash).toString("hex");
477
+ } catch (error) {
478
+ console.error("Error getting vault owner:", error);
479
+ return null;
480
+ }
481
+ }
482
+ /**
483
+ * Get authorized signers for a vault
484
+ *
485
+ * @param vaultObjectId - Vault object ID
486
+ * @returns Array of authorized signer key hashes
487
+ */
488
+ async getAuthorizedSigners(vaultObjectId) {
489
+ try {
490
+ const vaultObject = await this.client.getObject({
491
+ id: vaultObjectId,
492
+ options: { showContent: true }
493
+ });
494
+ if (!vaultObject.data?.content || vaultObject.data.content.dataType !== "moveObject") {
495
+ return [];
496
+ }
497
+ const fields = vaultObject.data.content.fields;
498
+ const authorizedSigners = fields["authorized_signers"];
499
+ if (!authorizedSigners) {
500
+ return [];
501
+ }
502
+ return authorizedSigners.map(
503
+ (signer) => "0x" + Buffer.from(signer).toString("hex")
504
+ );
505
+ } catch (error) {
506
+ console.error("Error getting authorized signers:", error);
507
+ return [];
508
+ }
509
+ }
510
+ /**
511
+ * Check if a VAA has been processed (for replay protection)
512
+ *
513
+ * @param vaaHash - VAA hash as hex string
514
+ * @param processedVaasObjectId - ProcessedVAAs shared object ID
515
+ * @returns Whether the VAA has been processed
516
+ */
517
+ async isVaaProcessed(vaaHash, processedVaasObjectId) {
518
+ try {
519
+ const processedObject = await this.client.getObject({
520
+ id: processedVaasObjectId,
521
+ options: { showContent: true }
522
+ });
523
+ if (!processedObject.data?.content) {
524
+ return false;
525
+ }
526
+ console.warn("isVaaProcessed requires dynamic field query");
527
+ return false;
528
+ } catch (error) {
529
+ console.error("Error checking VAA status:", error);
530
+ return false;
531
+ }
532
+ }
533
+ /**
534
+ * Check if protocol is paused
535
+ *
536
+ * @param configObjectId - Config shared object ID
537
+ * @returns Whether the protocol is paused
538
+ */
539
+ async isProtocolPaused(configObjectId) {
540
+ try {
541
+ const configObject = await this.client.getObject({
542
+ id: configObjectId,
543
+ options: { showContent: true }
544
+ });
545
+ if (!configObject.data?.content || configObject.data.content.dataType !== "moveObject") {
546
+ return false;
547
+ }
548
+ const fields = configObject.data.content.fields;
549
+ return fields["paused"] === true;
550
+ } catch (error) {
551
+ console.error("Error checking pause status:", error);
552
+ return false;
553
+ }
554
+ }
555
+ };
556
+ // Annotate the CommonJS export names for ESM import in node:
557
+ 0 && (module.exports = {
558
+ SuiClient
559
+ });
560
+ //# sourceMappingURL=index.js.map