@veridex/sdk 1.1.1 → 1.1.3

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AvalancheClient
3
- } from "../../chunk-PEGOXMBU.mjs";
4
- import "../../chunk-YBN2VC6E.mjs";
3
+ } from "../../chunk-6JULIESG.mjs";
4
+ import "../../chunk-E5HHE7IW.mjs";
5
5
  import "../../chunk-TPEP6XUA.mjs";
6
6
  import "../../chunk-RD6ZYUVG.mjs";
7
7
  export {
@@ -1,7 +1,7 @@
1
- export { E as EVMClient, a as EVMClientConfig } from '../../EVMClient-DtqvdfUP.mjs';
2
- export { E as EVMHubClientAdapter } from '../../index-CySMITQ9.mjs';
1
+ export { E as EVMClient, a as EVMClientConfig } from '../../EVMClient-Bmy9czkE.mjs';
2
+ export { E as EVMHubClientAdapter } from '../../index-CKKUV4J7.mjs';
3
3
  import '../../types.mjs';
4
4
  import 'ethers';
5
5
  import '../../types-DP2CQT8p.mjs';
6
- import '../../types-DWx-5jmz.mjs';
6
+ import '../../types-C564CfsE.mjs';
7
7
  import '../../passkey.mjs';
@@ -117,7 +117,9 @@ var ERC20_ABI = [
117
117
  var HUB_ABI = [
118
118
  "function dispatch(tuple(bytes authenticatorData, string clientDataJSON, uint256 challengeIndex, uint256 typeIndex, uint256 r, uint256 s) signature, uint256 publicKeyX, uint256 publicKeyY, uint16 targetChain, bytes actionPayload, uint256 nonce) payable returns (uint64 sequence)",
119
119
  "function userNonces(bytes32 userKeyHash) view returns (uint256)",
120
- "function getMessageFee() view returns (uint256)",
120
+ // Hub exposes the Wormhole core bridge address; message fee is read from the
121
+ // bridge directly (getMessageFee() was removed from the Hub).
122
+ "function wormhole() view returns (address)",
121
123
  "function getVaultAddress(bytes32 userKeyHash) view returns (address)",
122
124
  "function vaultExists(bytes32 userKeyHash) view returns (bool)",
123
125
  "function createVault(bytes32 userKeyHash) returns (address)",
@@ -174,6 +176,8 @@ var EVMClient = class {
174
176
  hubContract;
175
177
  factoryContract = null;
176
178
  cachedImplementation = null;
179
+ cachedWormholeAddress = null;
180
+ cachedMessageFee = null;
177
181
  constructor(config) {
178
182
  this.config = {
179
183
  name: config.name ?? `EVM Chain ${config.chainId}`,
@@ -346,8 +350,24 @@ var EVMClient = class {
346
350
  return Number(count);
347
351
  }
348
352
  async getMessageFee() {
349
- const fee = await this.hubContract.getMessageFee();
350
- return BigInt(fee.toString());
353
+ const now = Date.now();
354
+ if (this.cachedMessageFee && this.cachedMessageFee.expiresAt > now) {
355
+ return this.cachedMessageFee.value;
356
+ }
357
+ let wormholeAddress = this.config.contracts.wormholeCoreBridge ?? this.cachedWormholeAddress;
358
+ if (!wormholeAddress) {
359
+ wormholeAddress = await this.hubContract.wormhole();
360
+ this.cachedWormholeAddress = wormholeAddress;
361
+ }
362
+ const wormhole = new import_ethers2.ethers.Contract(
363
+ wormholeAddress,
364
+ ["function messageFee() view returns (uint256)"],
365
+ this.provider
366
+ );
367
+ const fee = await wormhole.messageFee();
368
+ const value = BigInt(fee.toString());
369
+ this.cachedMessageFee = { value, expiresAt: now + 3e4 };
370
+ return value;
351
371
  }
352
372
  async buildTransferPayload(params) {
353
373
  return encodeTransferAction(
@@ -446,13 +466,41 @@ var EVMClient = class {
446
466
  actionPayload,
447
467
  nonce: Number(nonce)
448
468
  };
449
- const response = await fetch(`${relayerUrl}/api/v1/submit`, {
450
- method: "POST",
451
- headers: {
452
- "Content-Type": "application/json"
453
- },
454
- body: JSON.stringify(request)
455
- });
469
+ const MAX_ATTEMPTS = 3;
470
+ const baseDelayMs = 1e3;
471
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
472
+ let response;
473
+ let lastError;
474
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
475
+ try {
476
+ response = await fetch(`${relayerUrl}/api/v1/submit`, {
477
+ method: "POST",
478
+ headers: {
479
+ "Content-Type": "application/json"
480
+ },
481
+ body: JSON.stringify(request)
482
+ });
483
+ const retryable = response.status >= 500 || response.status === 408 || response.status === 429;
484
+ if (!retryable) {
485
+ break;
486
+ }
487
+ if (attempt === MAX_ATTEMPTS) break;
488
+ const retryAfter = response.headers.get("retry-after");
489
+ const explicitDelay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : 0;
490
+ const backoff = explicitDelay > 0 ? explicitDelay : baseDelayMs * 2 ** (attempt - 1) + Math.floor(Math.random() * 200);
491
+ await sleep(backoff);
492
+ } catch (err) {
493
+ lastError = err;
494
+ if (attempt === MAX_ATTEMPTS) break;
495
+ const backoff = baseDelayMs * 2 ** (attempt - 1) + Math.floor(Math.random() * 200);
496
+ await sleep(backoff);
497
+ }
498
+ }
499
+ if (!response) {
500
+ throw new Error(
501
+ `Relayer submission failed after ${MAX_ATTEMPTS} attempts: ${lastError instanceof Error ? lastError.message : String(lastError)}`
502
+ );
503
+ }
456
504
  if (!response.ok) {
457
505
  const error = await response.json().catch(() => ({ error: response.statusText }));
458
506
  throw new Error(`Relayer submission failed: ${error.error || response.statusText}`);
@@ -1201,14 +1249,28 @@ var EVMClient = class {
1201
1249
  return { receipt };
1202
1250
  }
1203
1251
  async getTransactionPolicy(identityKeyHash) {
1204
- const result = await this.hubContract.getTransactionPolicy(identityKeyHash);
1205
- return {
1206
- enabled: result.enabled,
1207
- threshold: Number(result.threshold),
1208
- protectedActionMask: Number(result.protectedActionMask),
1209
- proposalTtl: Number(result.proposalTtl),
1210
- disableSessions: result.disableSessions
1211
- };
1252
+ try {
1253
+ const result = await this.hubContract.getTransactionPolicy(identityKeyHash);
1254
+ return {
1255
+ enabled: result.enabled,
1256
+ threshold: Number(result.threshold),
1257
+ protectedActionMask: Number(result.protectedActionMask),
1258
+ proposalTtl: Number(result.proposalTtl),
1259
+ disableSessions: result.disableSessions
1260
+ };
1261
+ } catch (error) {
1262
+ const code = error?.code;
1263
+ if (code === "CALL_EXCEPTION" || code === "BAD_DATA") {
1264
+ return {
1265
+ enabled: false,
1266
+ threshold: 0,
1267
+ protectedActionMask: 0,
1268
+ proposalTtl: 0,
1269
+ disableSessions: false
1270
+ };
1271
+ }
1272
+ throw error;
1273
+ }
1212
1274
  }
1213
1275
  async createTransactionProposal(signature, publicKeyX, publicKeyY, targetChain, actionPayload, signer) {
1214
1276
  const s = signer;
@@ -1283,7 +1345,7 @@ var EVMClient = class {
1283
1345
  async executeTransactionProposal(proposalId, signer) {
1284
1346
  const s = signer;
1285
1347
  const hub = this.hubContract.connect(s);
1286
- const fee = await this.hubContract.getMessageFee();
1348
+ const fee = await this.getMessageFee();
1287
1349
  const tx = await hub.executeTransactionProposal(proposalId, { value: fee });
1288
1350
  const receipt = await tx.wait();
1289
1351
  const sequence = this._extractSequenceFromReceipt(receipt);