@towns-labs/relayer 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/README.md CHANGED
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "relayer-worker" generated at 2026-02-13T08:35:58.863Z.
1
+ This folder contains the built output assets for the worker "relayer-worker" generated at 2026-02-18T05:42:51.313Z.
package/dist/index.js CHANGED
@@ -12238,6 +12238,18 @@ var addresses_default = {
12238
12238
  simulator: "0xDAD7c34d0c41698B227D3C5ee3d6d88A78c63a65",
12239
12239
  townsAccount: "0x2eEBFfcFABEB8cE3AC016effFeC37dBBAccCff2a"
12240
12240
  }
12241
+ },
12242
+ "42161": {
12243
+ addresses: {
12244
+ accountProxy: "0x9172852305F32819469bf38A3772f29361d7b768",
12245
+ escrow: "0x05f9597eed844410b7c0746A1C584188d0644730",
12246
+ multiSigSigner: "0xa3972FEebd6E1f973eD19cC586D79B3F61f892A3",
12247
+ orchestrator: "0x11050FEC41B66730E91c46Bfd25EBFF3B16F5bcC",
12248
+ simpleFunder: "0x41D23D227C6D0F732D41eE5c203C48d96292A48B",
12249
+ simpleSettler: "0x5386d1026e1598177e03eA52cbF1a0994ADF5eaE",
12250
+ simulator: "0xDAD7c34d0c41698B227D3C5ee3d6d88A78c63a65",
12251
+ townsAccount: "0x4f58d66c5d55B4E6f0aA578Df8D9342f63473FF6"
12252
+ }
12241
12253
  }
12242
12254
  },
12243
12255
  stage: {
@@ -12264,6 +12276,18 @@ var addresses_default = {
12264
12276
  simulator: "0xDAD7c34d0c41698B227D3C5ee3d6d88A78c63a65",
12265
12277
  townsAccount: "0x4f58d66c5d55B4E6f0aA578Df8D9342f63473FF6"
12266
12278
  }
12279
+ },
12280
+ "42161": {
12281
+ addresses: {
12282
+ accountProxy: "0xeE06c19146427bDd5abb702579F3B0568b24Bf6F",
12283
+ escrow: "0x05f9597eed844410b7c0746A1C584188d0644730",
12284
+ multiSigSigner: "0xa3972FEebd6E1f973eD19cC586D79B3F61f892A3",
12285
+ orchestrator: "0x11050FEC41B66730E91c46Bfd25EBFF3B16F5bcC",
12286
+ simpleFunder: "0xf297614c45E3AfAAC849B7Cde4A20A8cF336D8bF",
12287
+ simpleSettler: "0x195424235453eC103082A9406AEE0Cc30E908b24",
12288
+ simulator: "0xDAD7c34d0c41698B227D3C5ee3d6d88A78c63a65",
12289
+ townsAccount: "0x4f58d66c5d55B4E6f0aA578Df8D9342f63473FF6"
12290
+ }
12267
12291
  }
12268
12292
  }
12269
12293
  };
@@ -23663,6 +23687,7 @@ var ACCOUNT_NOT_DELEGATED = -32009;
23663
23687
  var QUOTE_EXPIRED = -32010;
23664
23688
  var INVALID_QUOTE_SIGNATURE = -32011;
23665
23689
  var PAYMENT_EXCEEDS_MAX = -32012;
23690
+ var DRAFT_CONFLICT = -32013;
23666
23691
  var ERROR_MESSAGES = {
23667
23692
  [PARSE_ERROR]: "Parse error",
23668
23693
  [INVALID_REQUEST]: "Invalid Request",
@@ -23681,7 +23706,8 @@ var ERROR_MESSAGES = {
23681
23706
  [ACCOUNT_NOT_DELEGATED]: "Account not delegated",
23682
23707
  [QUOTE_EXPIRED]: "Quote expired",
23683
23708
  [INVALID_QUOTE_SIGNATURE]: "Invalid quote signature",
23684
- [PAYMENT_EXCEEDS_MAX]: "Payment amount exceeds maximum"
23709
+ [PAYMENT_EXCEEDS_MAX]: "Payment amount exceeds maximum",
23710
+ [DRAFT_CONFLICT]: "Draft conflict"
23685
23711
  };
23686
23712
  var RpcError2 = class extends Error {
23687
23713
  static {
@@ -23827,58 +23853,35 @@ var INTENT_TYPES = {
23827
23853
  // src/services/relayer.ts
23828
23854
  function createIntentNonceProvider(durableObject, chainId) {
23829
23855
  const durableObjectNameFor = /* @__PURE__ */ __name((eoa) => `${chainId}:${eoa.toLowerCase()}`, "durableObjectNameFor");
23856
+ const getStubForEoa = /* @__PURE__ */ __name((eoa) => {
23857
+ const id = durableObject.idFromName(durableObjectNameFor(eoa));
23858
+ return durableObject.get(id);
23859
+ }, "getStubForEoa");
23860
+ const postToNonceDo = /* @__PURE__ */ __name(async (eoa, path, body) => {
23861
+ const stub = getStubForEoa(eoa);
23862
+ return stub.fetch(
23863
+ new Request(`http://do/${path}`, {
23864
+ method: "POST",
23865
+ headers: { "Content-Type": "application/json" },
23866
+ body: JSON.stringify(body)
23867
+ })
23868
+ );
23869
+ }, "postToNonceDo");
23830
23870
  return {
23831
- async acquireNonce(eoa, seqKey = 0n) {
23832
- const id = durableObject.idFromName(durableObjectNameFor(eoa));
23833
- const stub = durableObject.get(id);
23834
- const response = await stub.fetch(
23835
- new Request("http://do/acquire", {
23836
- method: "POST",
23837
- headers: { "Content-Type": "application/json" },
23838
- body: JSON.stringify({ seqKey: seqKey.toString() })
23839
- })
23840
- );
23841
- if (!response.ok) {
23842
- const error48 = await response.json();
23843
- throw new Error(`Failed to acquire intent nonce: ${error48.error}`);
23844
- }
23845
- const data = await response.json();
23846
- return BigInt(data.nonce);
23847
- },
23848
- async acquireNonceSynced(eoa, seqKey, onChainSeq) {
23849
- const id = durableObject.idFromName(durableObjectNameFor(eoa));
23850
- const stub = durableObject.get(id);
23851
- const response = await stub.fetch(
23852
- new Request("http://do/acquire_synced", {
23853
- method: "POST",
23854
- headers: { "Content-Type": "application/json" },
23855
- body: JSON.stringify({
23856
- seqKey: seqKey.toString(),
23857
- onChainSeq: onChainSeq.toString()
23858
- })
23859
- })
23860
- );
23861
- if (!response.ok) {
23862
- const error48 = await response.json();
23863
- throw new Error(`Failed to acquire synced intent nonce: ${error48.error}`);
23864
- }
23865
- const data = await response.json();
23866
- return { nonce: BigInt(data.nonce), synced: data.synced };
23867
- },
23868
23871
  async acquireOrGetDraft(eoa, seqKey, onChainSeq, prepareKey) {
23869
- const id = durableObject.idFromName(durableObjectNameFor(eoa));
23870
- const stub = durableObject.get(id);
23871
- const response = await stub.fetch(
23872
- new Request("http://do/acquire_or_get_draft", {
23873
- method: "POST",
23874
- headers: { "Content-Type": "application/json" },
23875
- body: JSON.stringify({
23876
- seqKey: seqKey.toString(),
23877
- onChainSeq: onChainSeq.toString(),
23878
- draftKey: prepareKey
23879
- })
23880
- })
23881
- );
23872
+ const response = await postToNonceDo(eoa, "acquire_or_get_draft", {
23873
+ seqKey: seqKey.toString(),
23874
+ onChainSeq: onChainSeq.toString(),
23875
+ draftKey: prepareKey
23876
+ });
23877
+ if (response.status === 409) {
23878
+ const body = await response.json();
23879
+ return {
23880
+ conflict: true,
23881
+ error: body.error,
23882
+ conflictDraftId: body.conflictDraftId
23883
+ };
23884
+ }
23882
23885
  if (!response.ok) {
23883
23886
  const error48 = await response.json();
23884
23887
  throw new Error(`Failed to acquire intent draft: ${error48.error}`);
@@ -23893,55 +23896,16 @@ function createIntentNonceProvider(durableObject, chainId) {
23893
23896
  };
23894
23897
  },
23895
23898
  async markSubmitted(eoa, seqKey, draftId) {
23896
- const id = durableObject.idFromName(durableObjectNameFor(eoa));
23897
- const stub = durableObject.get(id);
23898
- const response = await stub.fetch(
23899
- new Request("http://do/mark_submitted", {
23900
- method: "POST",
23901
- headers: { "Content-Type": "application/json" },
23902
- body: JSON.stringify({ seqKey: seqKey.toString(), draftId })
23903
- })
23904
- );
23899
+ const response = await postToNonceDo(eoa, "mark_submitted", {
23900
+ seqKey: seqKey.toString(),
23901
+ draftId
23902
+ });
23905
23903
  if (!response.ok) {
23906
23904
  const error48 = await response.json();
23907
23905
  throw new Error(`Failed to mark intent draft submitted: ${error48.error}`);
23908
23906
  }
23909
23907
  const data = await response.json();
23910
23908
  return data.status;
23911
- },
23912
- async cancelDraft(eoa, seqKey, draftId) {
23913
- const id = durableObject.idFromName(durableObjectNameFor(eoa));
23914
- const stub = durableObject.get(id);
23915
- const response = await stub.fetch(
23916
- new Request("http://do/cancel_draft", {
23917
- method: "POST",
23918
- headers: { "Content-Type": "application/json" },
23919
- body: JSON.stringify({ seqKey: seqKey.toString(), draftId })
23920
- })
23921
- );
23922
- if (!response.ok) {
23923
- const error48 = await response.json();
23924
- throw new Error(`Failed to cancel intent draft: ${error48.error}`);
23925
- }
23926
- const data = await response.json();
23927
- return data.status;
23928
- },
23929
- async syncNonce(eoa, seqKey, confirmedSeq) {
23930
- const id = durableObject.idFromName(durableObjectNameFor(eoa));
23931
- const stub = durableObject.get(id);
23932
- const response = await stub.fetch(
23933
- new Request("http://do/sync", {
23934
- method: "POST",
23935
- headers: { "Content-Type": "application/json" },
23936
- body: JSON.stringify({
23937
- seqKey: seqKey.toString(),
23938
- confirmedSeq: confirmedSeq.toString()
23939
- })
23940
- })
23941
- );
23942
- if (!response.ok) {
23943
- console.warn("Failed to sync intent nonce for:", eoa);
23944
- }
23945
23909
  }
23946
23910
  };
23947
23911
  }
@@ -23983,6 +23947,14 @@ function calculateCombinedGas(simulationGas, gasConfig, paymentEnabled) {
23983
23947
  return simulationGas + gasConfig.intentGasBuffer + (paymentEnabled ? gasConfig.paymentGasBuffer : 0n);
23984
23948
  }
23985
23949
  __name(calculateCombinedGas, "calculateCombinedGas");
23950
+ function normalizeCalls(calls) {
23951
+ return calls.map((call2) => ({
23952
+ to: call2.to,
23953
+ value: call2.value ? BigInt(call2.value) : 0n,
23954
+ data: call2.data ?? "0x"
23955
+ }));
23956
+ }
23957
+ __name(normalizeCalls, "normalizeCalls");
23986
23958
  function extractRevertData(error48) {
23987
23959
  if (error48 instanceof BaseError2) {
23988
23960
  const rawError = error48.walk((e) => e instanceof RawContractError);
@@ -24069,12 +24041,20 @@ var RelayerService = class {
24069
24041
  async acquireNonceFromProvider(eoa, seqKey, prepareKey) {
24070
24042
  const onChainSeq = await this.fetchOnChainSeq(eoa, seqKey);
24071
24043
  const safeOnChainSeq = onChainSeq ?? 0n;
24072
- const { nonce, draftId, expiresAtMs, fromCache } = await this.intentNonceProvider.acquireOrGetDraft(
24044
+ const result = await this.intentNonceProvider.acquireOrGetDraft(
24073
24045
  eoa,
24074
24046
  seqKey,
24075
24047
  safeOnChainSeq,
24076
24048
  prepareKey
24077
24049
  );
24050
+ if ("conflict" in result) {
24051
+ return {
24052
+ success: false,
24053
+ error: result.error,
24054
+ conflictDraftId: result.conflictDraftId
24055
+ };
24056
+ }
24057
+ const { nonce, draftId, expiresAtMs, fromCache } = result;
24078
24058
  if (onChainSeq === null) {
24079
24059
  this.logger.debug(
24080
24060
  { eoa, nonce: nonce.toString(), draftId },
@@ -24141,11 +24121,7 @@ var RelayerService = class {
24141
24121
  errorCode: "DELEGATION_PENDING"
24142
24122
  };
24143
24123
  }
24144
- const calls = request.calls.map((c2) => ({
24145
- to: c2.to,
24146
- value: c2.value ? BigInt(c2.value) : 0n,
24147
- data: c2.data ?? "0x"
24148
- }));
24124
+ const calls = normalizeCalls(request.calls);
24149
24125
  const executionData = encodeAbiParameters(
24150
24126
  [
24151
24127
  {
@@ -24161,6 +24137,17 @@ var RelayerService = class {
24161
24137
  );
24162
24138
  const nowSeconds = BigInt(Math.floor(Date.now() / 1e3));
24163
24139
  const expiry = resolveIntentExpirySeconds(request.expiry, nowSeconds);
24140
+ let signature = request.signature ?? "0x";
24141
+ if (request.sessionKey && !request.signature) {
24142
+ const keyHash = keccak256(
24143
+ encodeAbiParameters(parseAbiParameters("uint8, bytes32"), [
24144
+ 0,
24145
+ // secp256k1
24146
+ keccak256(request.sessionKey)
24147
+ ])
24148
+ );
24149
+ signature = concat([`0x${"00".repeat(65)}`, keyHash, "0x00"]);
24150
+ }
24164
24151
  const intent = {
24165
24152
  eoa: request.eoa,
24166
24153
  executionData,
@@ -24180,7 +24167,7 @@ var RelayerService = class {
24180
24167
  settlerContext: request.settlerContext ?? "0x",
24181
24168
  paymentAmount: BigInt(request.paymentAmount ?? "0"),
24182
24169
  paymentRecipient: request.paymentRecipient ?? zeroAddress,
24183
- signature: request.signature ?? "0x",
24170
+ signature,
24184
24171
  paymentSignature: request.paymentSignature ?? "0x",
24185
24172
  supportedAccountImplementation: request.supportedAccountImplementation ?? zeroAddress
24186
24173
  };
@@ -24294,7 +24281,11 @@ var RelayerService = class {
24294
24281
  request.prepareKey
24295
24282
  );
24296
24283
  if (!nonceResult.success) {
24297
- return { success: false, error: nonceResult.error };
24284
+ return {
24285
+ success: false,
24286
+ error: nonceResult.error,
24287
+ conflictDraftId: nonceResult.conflictDraftId
24288
+ };
24298
24289
  }
24299
24290
  const nonce = nonceResult.nonce;
24300
24291
  const nowSeconds = BigInt(Math.floor(Date.now() / 1e3));
@@ -24306,11 +24297,7 @@ var RelayerService = class {
24306
24297
  const paymentToken = request.paymentToken ?? zeroAddress;
24307
24298
  const paymentMaxAmount = BigInt(request.paymentMaxAmount ?? "0");
24308
24299
  const paymentEnabled = isPaymentEnabled(payer, paymentToken);
24309
- const calls = request.calls.map((c2) => ({
24310
- to: c2.to,
24311
- value: c2.value ? BigInt(c2.value) : 0n,
24312
- data: c2.data ?? "0x"
24313
- }));
24300
+ const calls = normalizeCalls(request.calls);
24314
24301
  const simulateResult = await this.simulateIntent({
24315
24302
  eoa: request.eoa,
24316
24303
  calls: request.calls,
@@ -24321,7 +24308,8 @@ var RelayerService = class {
24321
24308
  settler: request.settler,
24322
24309
  payer: request.payer,
24323
24310
  paymentToken: request.paymentToken,
24324
- paymentMaxAmount: request.paymentMaxAmount
24311
+ paymentMaxAmount: request.paymentMaxAmount,
24312
+ sessionKey: request.sessionKey
24325
24313
  });
24326
24314
  const simulationGas = simulateResult.gasUsed ? BigInt(simulateResult.gasUsed) : 0n;
24327
24315
  const simulationSucceeded = simulateResult.success && simulationGas > 0n;
@@ -24533,7 +24521,7 @@ function selectSignerForEoa(eoa, signerCount) {
24533
24521
  __name(selectSignerForEoa, "selectSignerForEoa");
24534
24522
 
24535
24523
  // src/rpc/methods/shared/calls-helpers.ts
24536
- function getChainIdFromContext(context, _env) {
24524
+ function getChainIdFromContext(context) {
24537
24525
  if ("quote" in context && context.quote?.quotes?.length) {
24538
24526
  const first = parseHexChainId(context.quote.quotes[0].chainId, "chain_id");
24539
24527
  for (const quote of context.quote.quotes) {
@@ -24613,30 +24601,11 @@ function hashQuotes(signedQuotes, config2) {
24613
24601
  }
24614
24602
  __name(hashQuotes, "hashQuotes");
24615
24603
  function extractIntentFromContext(context) {
24616
- if ("quote" in context && context.quote) {
24617
- const quote = context.quote.quotes[0];
24618
- if (!quote) {
24619
- throw new RpcError2(INVALID_PARAMS, "No quote found in context");
24620
- }
24621
- return quote.intent;
24604
+ const quote = context.quote.quotes[0];
24605
+ if (!quote) {
24606
+ throw new RpcError2(INVALID_PARAMS, "No quote found in context");
24622
24607
  }
24623
- const legacyContext = context;
24624
- return {
24625
- eoa: legacyContext.eoa,
24626
- calls: legacyContext.calls,
24627
- nonce: legacyContext.nonce,
24628
- combinedGas: legacyContext.combinedGas,
24629
- expiry: legacyContext.expiry,
24630
- encodedPreCalls: legacyContext.encodedPreCalls,
24631
- funder: legacyContext.funder,
24632
- encodedFundTransfers: legacyContext.encodedFundTransfers,
24633
- settler: legacyContext.settler,
24634
- settlerContext: legacyContext.settlerContext,
24635
- payer: legacyContext.payer,
24636
- paymentToken: legacyContext.paymentToken,
24637
- paymentMaxAmount: legacyContext.paymentMaxAmount,
24638
- paymentSignature: legacyContext.paymentSignature
24639
- };
24608
+ return quote.intent;
24640
24609
  }
24641
24610
  __name(extractIntentFromContext, "extractIntentFromContext");
24642
24611
  async function validateQuote(signedQuotes, env) {
@@ -24671,12 +24640,7 @@ function buildIntentFromParams(params) {
24671
24640
  const { context, signature, paymentSignature: paramsPaymentSig, capabilities } = params;
24672
24641
  const explicitPaymentSignature = paramsPaymentSig ?? capabilities?.feeSignature;
24673
24642
  const quoteIntent = extractIntentFromContext(context);
24674
- let calculatedPaymentAmount = "0";
24675
- if ("quote" in context && context.quote?.quotes[0]) {
24676
- calculatedPaymentAmount = context.quote.quotes[0].paymentAmount ?? "0";
24677
- } else if ("paymentAmount" in context && context.paymentAmount) {
24678
- calculatedPaymentAmount = context.paymentAmount;
24679
- }
24643
+ const calculatedPaymentAmount = context.quote.quotes[0]?.paymentAmount ?? "0";
24680
24644
  return {
24681
24645
  eoa: quoteIntent.eoa,
24682
24646
  calls: quoteIntent.calls.map((call2) => ({
@@ -24739,7 +24703,7 @@ async function handleSendPreparedCalls(params, ctx) {
24739
24703
  const quoteError = await validateQuote(context.quote, env);
24740
24704
  if (quoteError) throw quoteError;
24741
24705
  }
24742
- const chainId = getChainIdFromContext(context, env);
24706
+ const chainId = getChainIdFromContext(context);
24743
24707
  const supportedChainIds = getChainIds(env);
24744
24708
  if (supportedChainIds.length > 0 && !supportedChainIds.includes(chainId)) {
24745
24709
  throw new RpcError2(INVALID_PARAMS, `Unsupported chain ID: ${chainId}`);
@@ -24912,7 +24876,7 @@ async function handleBatchSendPreparedCalls(requests, ctx) {
24912
24876
  continue;
24913
24877
  }
24914
24878
  }
24915
- const chainId = getChainIdFromContext(typedParams.context, env);
24879
+ const chainId = getChainIdFromContext(typedParams.context);
24916
24880
  const supportedChainIds = getChainIds(env);
24917
24881
  if (supportedChainIds.length > 0 && !supportedChainIds.includes(chainId)) {
24918
24882
  validationErrors.set(
@@ -39874,9 +39838,32 @@ var ChainsConfigSchema = external_exports.object({
39874
39838
  var chains_default = {
39875
39839
  version: "1.0.0",
39876
39840
  chains: {
39877
- "31337": {
39878
- name: "local-anvil",
39879
- isTestnet: true,
39841
+ "137": {
39842
+ name: "polygon",
39843
+ isTestnet: false,
39844
+ nativeCurrency: {
39845
+ name: "POL",
39846
+ symbol: "POL",
39847
+ decimals: 18
39848
+ },
39849
+ assets: {
39850
+ pol: {
39851
+ address: "0x0000000000000000000000000000000000000000",
39852
+ decimals: 18,
39853
+ feeToken: true,
39854
+ interop: false
39855
+ },
39856
+ usdc: {
39857
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
39858
+ decimals: 6,
39859
+ feeToken: true,
39860
+ interop: true
39861
+ }
39862
+ }
39863
+ },
39864
+ "8453": {
39865
+ name: "base",
39866
+ isTestnet: false,
39880
39867
  nativeCurrency: {
39881
39868
  name: "Ether",
39882
39869
  symbol: "ETH",
@@ -39893,12 +39880,12 @@ var chains_default = {
39893
39880
  address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
39894
39881
  decimals: 6,
39895
39882
  feeToken: true,
39896
- interop: false
39883
+ interop: true
39897
39884
  }
39898
39885
  }
39899
39886
  },
39900
- "41337": {
39901
- name: "local-anvil-2",
39887
+ "31337": {
39888
+ name: "local-anvil",
39902
39889
  isTestnet: true,
39903
39890
  nativeCurrency: {
39904
39891
  name: "Ether",
@@ -39920,31 +39907,31 @@ var chains_default = {
39920
39907
  }
39921
39908
  }
39922
39909
  },
39923
- "137": {
39924
- name: "polygon",
39925
- isTestnet: false,
39910
+ "41337": {
39911
+ name: "local-anvil-2",
39912
+ isTestnet: true,
39926
39913
  nativeCurrency: {
39927
- name: "POL",
39928
- symbol: "POL",
39914
+ name: "Ether",
39915
+ symbol: "ETH",
39929
39916
  decimals: 18
39930
39917
  },
39931
39918
  assets: {
39932
- pol: {
39919
+ eth: {
39933
39920
  address: "0x0000000000000000000000000000000000000000",
39934
39921
  decimals: 18,
39935
39922
  feeToken: true,
39936
39923
  interop: false
39937
39924
  },
39938
39925
  usdc: {
39939
- address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
39926
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
39940
39927
  decimals: 6,
39941
39928
  feeToken: true,
39942
- interop: true
39929
+ interop: false
39943
39930
  }
39944
39931
  }
39945
39932
  },
39946
- "8453": {
39947
- name: "base",
39933
+ "42161": {
39934
+ name: "arbitrum",
39948
39935
  isTestnet: false,
39949
39936
  nativeCurrency: {
39950
39937
  name: "Ether",
@@ -39959,10 +39946,10 @@ var chains_default = {
39959
39946
  interop: false
39960
39947
  },
39961
39948
  usdc: {
39962
- address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
39949
+ address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
39963
39950
  decimals: 6,
39964
39951
  feeToken: true,
39965
- interop: true
39952
+ interop: false
39966
39953
  }
39967
39954
  }
39968
39955
  },
@@ -40081,9 +40068,22 @@ async function handlePrepareCalls(params, ctx) {
40081
40068
  payer,
40082
40069
  paymentToken,
40083
40070
  paymentMaxAmount,
40084
- prepareKey
40071
+ prepareKey,
40072
+ sessionKey: typedParams.session_key
40085
40073
  });
40086
40074
  if (!result.success || !result.typedData || !result.digest) {
40075
+ if (result.conflictDraftId) {
40076
+ throw new RpcError2(DRAFT_CONFLICT, result.error ?? "Draft conflict", {
40077
+ conflictDraftId: result.conflictDraftId
40078
+ });
40079
+ }
40080
+ const rawError = result.error ?? "Failed to prepare calls";
40081
+ if (rawError.toLowerCase().startsWith("simulation failed")) {
40082
+ const cause = rawError.replace(/^simulation failed:\s*/i, "").trim();
40083
+ throw new RpcError2(SIMULATION_FAILED, "Simulation failed", {
40084
+ cause: cause.length > 0 ? cause : void 0
40085
+ });
40086
+ }
40087
40087
  throw new RpcError2(INTERNAL_ERROR, result.error ?? "Failed to prepare calls");
40088
40088
  }
40089
40089
  const feeConfig = getFeeConfig(env);
@@ -40218,14 +40218,6 @@ async function handlePrepareCalls(params, ctx) {
40218
40218
  message[key] = value;
40219
40219
  }
40220
40220
  }
40221
- let callKey;
40222
- if (typedParams.key) {
40223
- callKey = {
40224
- type: typedParams.key.type,
40225
- publicKey: typedParams.key.public_key,
40226
- prehash: typedParams.key.prehash ?? false
40227
- };
40228
- }
40229
40221
  return {
40230
40222
  context: preparedContext,
40231
40223
  digest: result.digest,
@@ -40236,12 +40228,9 @@ async function handlePrepareCalls(params, ctx) {
40236
40228
  message
40237
40229
  },
40238
40230
  capabilities: {
40239
- authorizeKeys: [],
40240
- revokeKeys: [],
40241
40231
  feeTotals: {},
40242
40232
  assetDiffs: {}
40243
40233
  },
40244
- key: callKey,
40245
40234
  signature: signedQuotes.signature
40246
40235
  };
40247
40236
  }
@@ -40876,10 +40865,6 @@ async function handleGetAuthorization(_params, _ctx) {
40876
40865
  throw new RpcError2(METHOD_NOT_IMPLEMENTED, "wallet_getAuthorization not implemented");
40877
40866
  }
40878
40867
  __name(handleGetAuthorization, "handleGetAuthorization");
40879
- async function handleAddFaucetFunds(_params, _ctx) {
40880
- throw new RpcError2(METHOD_NOT_IMPLEMENTED, "wallet_addFaucetFunds not implemented");
40881
- }
40882
- __name(handleAddFaucetFunds, "handleAddFaucetFunds");
40883
40868
 
40884
40869
  // src/lib/erc1271.ts
40885
40870
  var ERC1271_SIGN_TYPEHASH = keccak256(
@@ -41019,8 +41004,7 @@ function createMethods(_env) {
41019
41004
  wallet_getAssets: handleGetAssets,
41020
41005
  wallet_getCallsHistory: handleGetCallsHistory,
41021
41006
  wallet_getAuthorization: handleGetAuthorization,
41022
- wallet_verifySignature: handleVerifySignature,
41023
- wallet_addFaucetFunds: handleAddFaucetFunds
41007
+ wallet_verifySignature: handleVerifySignature
41024
41008
  };
41025
41009
  }
41026
41010
  __name(createMethods, "createMethods");
@@ -45445,11 +45429,17 @@ __name(isPendingTransactionIdUniqueConstraintError, "isPendingTransactionIdUniqu
45445
45429
 
45446
45430
  // src/durable-objects/signer.do.ts
45447
45431
  var DEFAULT_MAX_PENDING = 16;
45448
- var BALANCE_CHECK_INTERVAL_MS = 6e4;
45432
+ var BALANCE_CHECK_INTERVAL_MS = 3e5;
45449
45433
  var STALE_TX_THRESHOLD_MS = 5 * 60 * 1e3;
45450
45434
  var DEFAULT_INTENT_EXPIRY_BUFFER_SECONDS = 30;
45451
45435
  var DUPLICATE_TX_WAIT_MS = 2e3;
45452
45436
  var DUPLICATE_TX_WAIT_POLL_MS = 100;
45437
+ function mapStoredTxStatusToPublicStatus(storedStatus) {
45438
+ if (storedStatus === "confirmed") return "confirmed";
45439
+ if (storedStatus === "failed" || storedStatus === "stuck") return "failed";
45440
+ return "pending";
45441
+ }
45442
+ __name(mapStoredTxStatusToPublicStatus, "mapStoredTxStatusToPublicStatus");
45453
45443
  function isIntentExpired(expiryTimestamp, bufferSeconds = DEFAULT_INTENT_EXPIRY_BUFFER_SECONDS) {
45454
45444
  const expiry = typeof expiryTimestamp === "string" ? BigInt(expiryTimestamp) : expiryTimestamp;
45455
45445
  const currentTime = BigInt(Math.floor(Date.now() / 1e3));
@@ -45884,11 +45874,12 @@ var SignerDO = class extends DurableObject {
45884
45874
  }
45885
45875
  } catch {
45886
45876
  }
45877
+ const fallbackStatus = mapStoredTxStatusToPublicStatus(status);
45887
45878
  return {
45888
45879
  txId,
45889
45880
  txHash,
45890
45881
  chainId,
45891
- status: "pending",
45882
+ status: fallbackStatus,
45892
45883
  submittedAt: sentAt
45893
45884
  };
45894
45885
  }
@@ -47760,6 +47751,15 @@ var IntentNonceDO = class extends DurableObject4 {
47760
47751
  draftKey,
47761
47752
  draftTtlMs: coerceDraftTtlMs(draftTtlMs)
47762
47753
  });
47754
+ if ("error" in result) {
47755
+ return Response.json(
47756
+ {
47757
+ error: result.error,
47758
+ conflictDraftId: result.conflictDraftId
47759
+ },
47760
+ { status: 409 }
47761
+ );
47762
+ }
47763
47763
  return Response.json({
47764
47764
  nonce: result.nonce.toString(),
47765
47765
  draftId: result.draftId,
@@ -47941,6 +47941,14 @@ var IntentNonceDO = class extends DurableObject4 {
47941
47941
  this.deleteExpiredDraftForSeqKey(key, nowMs);
47942
47942
  const existingDraft = this.getDraftForSeqKey(key);
47943
47943
  if (existingDraft !== null) {
47944
+ const incomingDraftKey = options.draftKey ?? null;
47945
+ const existingDraftKey = existingDraft.draft_key;
47946
+ if (incomingDraftKey !== existingDraftKey) {
47947
+ return {
47948
+ error: "draft already exists for seqKey with a different draftKey; complete or cancel the active request first",
47949
+ conflictDraftId: existingDraft.draft_id
47950
+ };
47951
+ }
47944
47952
  return {
47945
47953
  nonce: BigInt(existingDraft.nonce),
47946
47954
  draftId: existingDraft.draft_id,