@paybox-sh/sdk 2.1.0 → 2.2.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.
@@ -479,8 +479,8 @@ function buildSwapEnvelopes(txs, binding, creds) {
479
479
  );
480
480
  }
481
481
  return txs.map((t) => {
482
- const payload = t.vm === "solana" ? solanaSigningPayload(t.transaction) : eip1559SigningHash(t.transaction);
483
- const { signed_body, agent_signature } = buildEnvelope(payload, binding, creds);
482
+ const payload2 = t.vm === "solana" ? solanaSigningPayload(t.transaction) : eip1559SigningHash(t.transaction);
483
+ const { signed_body, agent_signature } = buildEnvelope(payload2, binding, creds);
484
484
  return { api_pub: creds.apiPubHex, signed_body, agent_signature };
485
485
  });
486
486
  }
@@ -638,42 +638,43 @@ function credsFromToken(token) {
638
638
  function toBinding(b) {
639
639
  return { walletId: b.wallet_id, keyId: b.key_id ?? "", derivationPath: b.derivation_path ?? "" };
640
640
  }
641
- async function resolveBinding(post, requestId, creds) {
641
+ async function resolveBinding(post, requestId2, creds) {
642
642
  const env = buildIssuedAtEnvelope(creds);
643
- const r = await post(`/agent/requests/${requestId}/binding`, {
643
+ const r = await post(`/agent/requests/${requestId2}/binding`, {
644
644
  api_pub: creds.apiPubHex,
645
645
  signed_body: env.signed_body,
646
646
  agent_signature: env.agent_signature
647
647
  });
648
648
  return toBinding(r);
649
649
  }
650
- async function signWalletRequest(post, requestId, intent, creds, binding) {
651
- const resolved = binding && binding.key_id && binding.derivation_path ? toBinding(binding) : await resolveBinding(post, requestId, creds);
652
- const transport = (envelope) => post(`/agent/requests/${requestId}/moonx-sign`, {
650
+ async function signWalletRequest(post, requestId2, intent, creds, binding) {
651
+ const resolved = binding && binding.key_id && binding.derivation_path ? toBinding(binding) : await resolveBinding(post, requestId2, creds);
652
+ const transport = (envelope) => post(`/agent/requests/${requestId2}/moonx-sign`, {
653
653
  api_pub: creds.apiPubHex,
654
654
  ...envelope
655
655
  });
656
656
  const result = await signIntent(intent, creds, resolved, transport);
657
657
  if (!result.ok) throw new Error(result.error);
658
- await post(`/agent/requests/${requestId}/signature`, { artifact: result.artifact });
658
+ await post(`/agent/requests/${requestId2}/signature`, { artifact: result.artifact });
659
659
  return result.artifact;
660
660
  }
661
- function isSolanaRefreshablePlan(plan) {
661
+ function isRefreshablePlan(plan) {
662
+ if (typeof plan.refresh_before_sign === "boolean") return plan.refresh_before_sign;
662
663
  const txs = plan.txs;
663
664
  const solana = txs.some((t) => t.vm === "solana");
664
665
  return solana && txs.some(
665
- (t) => t.kind === "swap" || t.kind === "prediction_trade" || t.kind === "jupiter_swap"
666
+ (t) => t.kind === "swap" || t.kind === "prediction_trade"
666
667
  );
667
668
  }
668
- async function refreshPlan(post, requestId) {
669
- const r = await post(`/agent/requests/${requestId}/refresh`, {});
669
+ async function refreshPlan(post, requestId2) {
670
+ const r = await post(`/agent/requests/${requestId2}/refresh`, {});
670
671
  if (!r || typeof r.plan !== "object" || r.plan === null) {
671
672
  throw new Error("refresh returned no plan");
672
673
  }
673
674
  return r.plan;
674
675
  }
675
- async function refreshSwapPlan(post, requestId) {
676
- const refreshed = await refreshPlan(post, requestId);
676
+ async function refreshSwapPlan(post, requestId2) {
677
+ const refreshed = await refreshPlan(post, requestId2);
677
678
  if (!Array.isArray(refreshed.txs) || refreshed.txs.length === 0) {
678
679
  throw new Error("swap refresh returned a plan with no txs");
679
680
  }
@@ -682,42 +683,43 @@ async function refreshSwapPlan(post, requestId) {
682
683
  function isSolanaRailX402(plan) {
683
684
  return plan.x402?.rail === "solana";
684
685
  }
685
- async function refreshX402SolanaTx(post, requestId) {
686
- const refreshed = await refreshPlan(post, requestId);
686
+ async function refreshX402SolanaTx(post, requestId2) {
687
+ const refreshed = await refreshPlan(post, requestId2);
687
688
  const tx = refreshed.solana?.transaction;
688
689
  if (typeof tx !== "string" || tx.length === 0) {
689
690
  throw new Error("x402 refresh returned a plan with no Solana transaction");
690
691
  }
691
692
  return tx;
692
693
  }
693
- async function signSwapRequest(post, requestId, plan, creds) {
694
- const signPlan = isSolanaRefreshablePlan(plan) ? await refreshSwapPlan(post, requestId) : plan;
694
+ async function signSwapRequest(post, requestId2, plan, creds, validate) {
695
+ const signPlan = isRefreshablePlan(plan) ? await refreshSwapPlan(post, requestId2) : plan;
696
+ validate?.(signPlan);
695
697
  let binding = {
696
698
  walletId: signPlan.binding.wallet_id,
697
699
  keyId: signPlan.binding.key_id ?? "",
698
700
  derivationPath: signPlan.binding.derivation_path ?? ""
699
701
  };
700
702
  if (binding.walletId && (!binding.keyId || !binding.derivationPath)) {
701
- binding = await resolveBinding(post, requestId, creds);
703
+ binding = await resolveBinding(post, requestId2, creds);
702
704
  }
703
705
  const envelopes = buildSwapEnvelopes(signPlan.txs, binding, creds);
704
- await post(`/agent/requests/${requestId}/envelopes`, { envelopes });
706
+ await post(`/agent/requests/${requestId2}/envelopes`, { envelopes });
705
707
  }
706
- async function signX402Request(post, requestId, plan, creds) {
708
+ async function signX402Request(post, requestId2, plan, creds) {
707
709
  let binding = {
708
710
  walletId: plan.binding.wallet_id,
709
711
  keyId: plan.binding.key_id ?? "",
710
712
  derivationPath: plan.binding.derivation_path ?? ""
711
713
  };
712
714
  if (binding.walletId && (!binding.keyId || !binding.derivationPath)) {
713
- binding = await resolveBinding(post, requestId, creds);
715
+ binding = await resolveBinding(post, requestId2, creds);
714
716
  }
715
- const envelope = isSolanaRailX402(plan) ? buildX402SolanaEnvelope(await refreshX402SolanaTx(post, requestId), binding, creds) : buildX402Envelope(
717
+ const envelope = isSolanaRailX402(plan) ? buildX402SolanaEnvelope(await refreshX402SolanaTx(post, requestId2), binding, creds) : buildX402Envelope(
716
718
  plan.typed_data,
717
719
  binding,
718
720
  creds
719
721
  );
720
- await post(`/agent/requests/${requestId}/envelopes`, { envelopes: [envelope] });
722
+ await post(`/agent/requests/${requestId2}/envelopes`, { envelopes: [envelope] });
721
723
  }
722
724
 
723
725
  // src/mcp.ts
@@ -769,7 +771,7 @@ var McpTransport = class {
769
771
  throw error;
770
772
  }
771
773
  }
772
- async post(payload, method, signingSurface) {
774
+ async post(payload2, method, signingSurface) {
773
775
  const response = await this.fetchImpl(this.endpoint, {
774
776
  method: "POST",
775
777
  headers: {
@@ -779,7 +781,7 @@ var McpTransport = class {
779
781
  "mcp-protocol-version": PROTOCOL_VERSION,
780
782
  ...signingSurface ? { "x-paybox-signing-surface": signingSurface } : {}
781
783
  },
782
- body: JSON.stringify(payload)
784
+ body: JSON.stringify(payload2)
783
785
  });
784
786
  const text = await response.text();
785
787
  if (!response.ok) {
@@ -816,6 +818,220 @@ var McpTransport = class {
816
818
  }
817
819
  };
818
820
 
821
+ // src/execution.ts
822
+ import { setTimeout as delay } from "node:timers/promises";
823
+
824
+ // src/plugins/signing.ts
825
+ function supportedSigningAction(value) {
826
+ if (value.operation != null) {
827
+ const operation = value.operation;
828
+ const intent = operation.intent;
829
+ if (operation.type !== "wallet_sign" || value.next_action?.kind !== "sign" || !intent || !["transaction", "solanaTransaction"].includes(intent.op)) return null;
830
+ try {
831
+ if (intent.op === "transaction") eip1559SigningHash(intent.transaction);
832
+ else if (intent.op === "solanaTransaction" && typeof intent.address === "string" && intent.address) deserializeSolanaTx(intent.transactionBase64);
833
+ else return null;
834
+ } catch {
835
+ return null;
836
+ }
837
+ const binding = operation.wallet_id == null ? null : {
838
+ wallet_id: operation.wallet_id,
839
+ key_id: operation.key_id ?? null,
840
+ derivation_path: operation.derivation_path ?? null
841
+ };
842
+ if (binding && (typeof binding.wallet_id !== "string" || binding.key_id !== null && typeof binding.key_id !== "string" || binding.derivation_path !== null && typeof binding.derivation_path !== "string")) return null;
843
+ return { type: "wallet_sign", intent, binding };
844
+ }
845
+ const plan = supportedSigningPlan(value.plan);
846
+ return plan ? { type: "transactions", plan } : null;
847
+ }
848
+ function supportedSigningPlan(value) {
849
+ if (!value || typeof value !== "object") return null;
850
+ const plan = value;
851
+ if (plan.version !== void 0 || plan.schema_version !== void 0 || plan.gasless != null || typeof plan.refresh_before_sign !== "boolean") return null;
852
+ const binding = plan.binding;
853
+ if (!binding || typeof binding.wallet_id !== "string" || !binding.wallet_id || binding.key_id != null && typeof binding.key_id !== "string" || binding.derivation_path != null && typeof binding.derivation_path !== "string" || typeof plan.sender !== "string" || !plan.sender || !Array.isArray(plan.txs) || plan.txs.length === 0) return null;
854
+ try {
855
+ for (const tx of plan.txs) {
856
+ if (!tx || tx.vm !== plan.txs[0].vm) return null;
857
+ if (tx.vm === "solana" && typeof tx.transaction === "string") deserializeSolanaTx(tx.transaction);
858
+ else if (tx.vm === "evm" && tx.transaction && typeof tx.transaction === "object" && !Array.isArray(tx.transaction)) eip1559SigningHash(tx.transaction);
859
+ else return null;
860
+ }
861
+ } catch {
862
+ return null;
863
+ }
864
+ return value;
865
+ }
866
+
867
+ // src/execution.ts
868
+ var UnsupportedPlanError = class extends Error {
869
+ };
870
+ var invocationIdMeta = "com.moonpay.paybox/invocationId";
871
+ var requestIdMeta = "com.moonpay.paybox/requestId";
872
+ function requestId(value) {
873
+ return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value) ? value.toLowerCase() : null;
874
+ }
875
+ function payload(result) {
876
+ const value = result.structuredContent ?? toolJson("plugin execution", { ...result, isError: false });
877
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("invalid response");
878
+ return value;
879
+ }
880
+ var statuses = /* @__PURE__ */ new Set([
881
+ "pending_approval",
882
+ "pending_funding",
883
+ "pending_signature",
884
+ "pending_settlement",
885
+ "pending_confirmation",
886
+ "success",
887
+ "denied",
888
+ "error"
889
+ ]);
890
+ async function executePlugin(start, options, connect) {
891
+ const timeoutMs = options.timeoutMs ?? 3e5;
892
+ const intervalMs = options.intervalMs ?? 2e3;
893
+ if (!Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2147483647 || !Number.isInteger(intervalMs) || intervalMs <= 0 || intervalMs > 3e4) {
894
+ throw new RangeError("timeoutMs must be 1..2147483647 and intervalMs must be 1..30000");
895
+ }
896
+ let id = typeof start === "string" ? requestId(start) : null;
897
+ if (typeof start === "string" && !id) throw new TypeError("requestId must be a UUID");
898
+ let response = null;
899
+ const result = (outcome, reason) => ({
900
+ outcome,
901
+ requestId: id,
902
+ response,
903
+ ...reason ? { reason } : {}
904
+ });
905
+ const controller = new AbortController();
906
+ let stopped = "cancelled";
907
+ const cancel = () => controller.abort();
908
+ options.signal?.addEventListener("abort", cancel, { once: true });
909
+ if (options.signal?.aborted) cancel();
910
+ const timer = setTimeout(() => {
911
+ if (!controller.signal.aborted) {
912
+ stopped = "deadline_exceeded";
913
+ controller.abort();
914
+ }
915
+ }, timeoutMs);
916
+ let onAbort;
917
+ const aborted = new Promise((resolve) => {
918
+ onAbort = () => resolve(result(stopped));
919
+ if (controller.signal.aborted) onAbort();
920
+ else controller.signal.addEventListener("abort", onAbort, { once: true });
921
+ });
922
+ const ports = connect(controller.signal);
923
+ const read = async () => {
924
+ controller.signal.throwIfAborted();
925
+ const next = await ports.getRequest(id);
926
+ controller.signal.throwIfAborted();
927
+ if (!next || requestId(next.request_id) !== id || !statuses.has(next.status)) {
928
+ throw new Error("invalid request response");
929
+ }
930
+ response = pendingFundingResponse(next) ?? next;
931
+ return response;
932
+ };
933
+ const terminal = (current) => {
934
+ if (current.status === "error" || current.status === "denied") return result("terminal");
935
+ if (current.status !== "success") return null;
936
+ const value = current.output?.value;
937
+ const fields = current.output?.output_type === "tx_hash" ? ["tx_hash"] : current.output?.output_type === "signature" ? ["signature", "serializedTransaction", "signedTransactionBase64"] : [];
938
+ return fields.some((field) => typeof value?.[field] === "string" && value[field].trim()) ? result("terminal") : result("unsupported", "success_output_not_supported");
939
+ };
940
+ const drive = async () => {
941
+ try {
942
+ controller.signal.throwIfAborted();
943
+ let toolError = false;
944
+ if (typeof start !== "string") {
945
+ const raw = await ports.callTool("use_plugin", {
946
+ plugin_id: start.pluginId,
947
+ tool_id: start.toolId,
948
+ input: start.input,
949
+ invocation_id: start.invocationId
950
+ });
951
+ controller.signal.throwIfAborted();
952
+ const funding = pendingFundingToolResponse(raw);
953
+ if (funding) {
954
+ response = funding;
955
+ id = requestId(funding.request_id);
956
+ return result("unsupported", "funding_required");
957
+ }
958
+ let data;
959
+ try {
960
+ data = payload(raw);
961
+ } catch {
962
+ return result("reconcile_required", raw.isError ? "tool_error" : "invalid_plugin_result");
963
+ }
964
+ toolError = raw.isError === true || data.status === "error";
965
+ const nextId = requestId(data.request_id);
966
+ if (!nextId) return result(toolError ? "reconcile_required" : "unsupported", toolError ? "tool_error" : "no_request_id");
967
+ if (requestId(start.pluginId)) {
968
+ const invocationId = requestId(raw._meta?.[invocationIdMeta]);
969
+ const expectedInvocationId = requestId(start.invocationId);
970
+ const boundRequestId = requestId(raw._meta?.[requestIdMeta]);
971
+ if (!invocationId || start.invocationId !== void 0 && invocationId !== expectedInvocationId || boundRequestId !== nextId) {
972
+ return result("reconcile_required", "request_id_mismatch");
973
+ }
974
+ }
975
+ id = nextId;
976
+ }
977
+ let current = await read();
978
+ let attempted = false;
979
+ let pauseMs = intervalMs;
980
+ for (; ; ) {
981
+ controller.signal.throwIfAborted();
982
+ const done = terminal(current);
983
+ if (done) return done;
984
+ if (current.status === "pending_funding") return result("unsupported", "funding_required");
985
+ if (toolError) return result("reconcile_required", "tool_error");
986
+ if (current.status === "pending_approval" && !options.waitForApproval) {
987
+ return result("approval_required");
988
+ }
989
+ if (current.status === "pending_signature") {
990
+ if (attempted) return result("reconcile_required", "submission_not_confirmed");
991
+ if (options.autoSign === false || !ports.sign) return result("signing_required");
992
+ try {
993
+ const raw = await ports.callTool("reopen_signing_window", { request_id: id });
994
+ if (raw.isError) throw new Error("reopen failed");
995
+ const reopened = payload(raw);
996
+ if (requestId(reopened.request_id) !== id) return result("unsupported", "request_id_mismatch");
997
+ current = await read();
998
+ if (current.status !== "pending_signature") continue;
999
+ if (reopened.status !== "pending_signature") return result("reconcile_required", "request_changed");
1000
+ const action = supportedSigningAction(reopened);
1001
+ if (!action) return result("unsupported", "signing_plan_not_supported");
1002
+ attempted = true;
1003
+ await ports.sign(id, action, (refreshed) => {
1004
+ controller.signal.throwIfAborted();
1005
+ if (!supportedSigningPlan(refreshed)) throw new UnsupportedPlanError();
1006
+ });
1007
+ } catch (error) {
1008
+ current = await read();
1009
+ const done2 = terminal(current);
1010
+ if (done2) return done2;
1011
+ if (error instanceof UnsupportedPlanError) return result("unsupported", "refreshed_plan_not_supported");
1012
+ if (current.status === "pending_signature") return result("reconcile_required", "signing_interrupted");
1013
+ }
1014
+ current = await read();
1015
+ continue;
1016
+ }
1017
+ await delay(pauseMs, void 0, { signal: controller.signal });
1018
+ const previous = current.status;
1019
+ current = await read();
1020
+ pauseMs = current.status === previous ? Math.min(pauseMs * 2, 3e4) : intervalMs;
1021
+ }
1022
+ } catch {
1023
+ return result(controller.signal.aborted ? stopped : "reconcile_required", "execution_interrupted");
1024
+ }
1025
+ };
1026
+ try {
1027
+ return await Promise.race([drive(), aborted]);
1028
+ } finally {
1029
+ clearTimeout(timer);
1030
+ options.signal?.removeEventListener("abort", cancel);
1031
+ controller.signal.removeEventListener("abort", onAbort);
1032
+ }
1033
+ }
1034
+
819
1035
  // src/client.ts
820
1036
  var DEFAULT_BASE_URL = "https://api.paybox.sh";
821
1037
  var EXPIRY_SKEW_MS = 6e4;
@@ -907,6 +1123,7 @@ var PayboxClient = class _PayboxClient {
907
1123
  );
908
1124
  }
909
1125
  async request(method, path, init = {}) {
1126
+ init.signal?.throwIfAborted();
910
1127
  const url = new URL(this.baseUrl + path);
911
1128
  for (const [k, v] of Object.entries(init.query ?? {})) {
912
1129
  if (v != null) url.searchParams.set(k, v);
@@ -917,8 +1134,10 @@ var PayboxClient = class _PayboxClient {
917
1134
  headers["content-type"] = "application/json";
918
1135
  body = JSON.stringify(init.body);
919
1136
  }
920
- const res = await this.fetchImpl(url, { method, headers, body });
1137
+ init.signal?.throwIfAborted();
1138
+ const res = await this.fetchImpl(url, { method, headers, body, signal: init.signal });
921
1139
  const text = await res.text();
1140
+ init.signal?.throwIfAborted();
922
1141
  if (!res.ok) throw new PayboxError(res.status, text, `${method} ${path}`);
923
1142
  return nonSigningFundingResult(text ? JSON.parse(text) : void 0);
924
1143
  }
@@ -991,21 +1210,21 @@ var PayboxClient = class _PayboxClient {
991
1210
  (r) => r
992
1211
  );
993
1212
  }
994
- async completeWalletSignRequest(requestId) {
1213
+ async completeWalletSignRequest(requestId2) {
995
1214
  const creds = this.signingCreds();
996
1215
  if (!creds) {
997
1216
  throw new Error("cannot complete wallet-sign request without a valid local signing key");
998
1217
  }
999
1218
  const result = await this.mcp.callTool(
1000
1219
  "reopen_signing_window",
1001
- { request_id: requestId },
1220
+ { request_id: requestId2 },
1002
1221
  "in-process"
1003
1222
  );
1004
1223
  const parked = toolJson("reopen_signing_window", result);
1005
- if (parked.request_id !== requestId) {
1224
+ if (parked.request_id !== requestId2) {
1006
1225
  throw new Error("paybox returned a different request_id for the parked signature");
1007
1226
  }
1008
- if (parked.status === "success") return this.getRequest(requestId);
1227
+ if (parked.status === "success") return this.getRequest(requestId2);
1009
1228
  if (parked.status !== "pending_signature") {
1010
1229
  throw new Error(`cannot complete wallet-sign request while it is ${parked.status ?? "unknown"}`);
1011
1230
  }
@@ -1019,10 +1238,10 @@ var PayboxClient = class _PayboxClient {
1019
1238
  derivation_path: parked.operation.derivation_path ?? null
1020
1239
  };
1021
1240
  await this.signWithReconcile(
1022
- requestId,
1023
- () => signWalletRequest(this.poster, requestId, intent, creds, binding)
1241
+ requestId2,
1242
+ () => signWalletRequest(this.poster, requestId2, intent, creds, binding)
1024
1243
  );
1025
- return this.getRequest(requestId);
1244
+ return this.getRequest(requestId2);
1026
1245
  }
1027
1246
  async requestSwap(args, opts = {}) {
1028
1247
  return this.withExpiryRetry(
@@ -1071,12 +1290,12 @@ var PayboxClient = class _PayboxClient {
1071
1290
  await this.requestAfterSign(response.request_id, opts.waitForApproval)
1072
1291
  );
1073
1292
  }
1074
- async waitWhileApproval(requestId, wait) {
1293
+ async waitWhileApproval(requestId2, wait) {
1075
1294
  const o = typeof wait === "object" ? wait : {};
1076
1295
  const interval = o.intervalMs ?? 2e3;
1077
1296
  const deadline = Date.now() + (o.timeoutMs ?? 3e5);
1078
1297
  for (; ; ) {
1079
- const r = await this.getRequest(requestId);
1298
+ const r = await this.getRequest(requestId2);
1080
1299
  if (r.status !== "pending_approval" || Date.now() > deadline) return r;
1081
1300
  await new Promise((res) => setTimeout(res, interval));
1082
1301
  }
@@ -1089,11 +1308,11 @@ var PayboxClient = class _PayboxClient {
1089
1308
  }
1090
1309
  return first;
1091
1310
  }
1092
- async signWithReconcile(requestId, sign) {
1311
+ async signWithReconcile(requestId2, sign) {
1093
1312
  try {
1094
1313
  await sign();
1095
1314
  } catch {
1096
- const reconciled = await this.getRequest(requestId);
1315
+ const reconciled = await this.getRequest(requestId2);
1097
1316
  if (reconciled.status !== "pending_signature") return;
1098
1317
  await sign();
1099
1318
  }
@@ -1145,6 +1364,34 @@ var PayboxClient = class _PayboxClient {
1145
1364
  invocation_id: args.invocationId
1146
1365
  }));
1147
1366
  }
1367
+ runPlugin(args, options = {}) {
1368
+ return this.executePlugin(args, options);
1369
+ }
1370
+ resumeRequest(requestId2, options = {}) {
1371
+ return this.executePlugin(requestId2, options);
1372
+ }
1373
+ executePlugin(start, options) {
1374
+ return executePlugin(start, options, (signal) => {
1375
+ const mcp = new McpTransport({
1376
+ baseUrl: this.baseUrl,
1377
+ bearer: () => this.bearer(),
1378
+ fetchImpl: (input, init) => {
1379
+ signal.throwIfAborted();
1380
+ return this.fetchImpl(input, { ...init, signal });
1381
+ }
1382
+ });
1383
+ const post = (path, body) => this.request("POST", path, { body, signal });
1384
+ const creds = this.signingCreds();
1385
+ return {
1386
+ callTool: (name, args) => mcp.callTool(name, args, name === "reopen_signing_window" ? "in-process" : void 0),
1387
+ getRequest: (id) => this.request("GET", `/agent/requests/${id}`, { signal }),
1388
+ sign: creds ? async (id, action, validate) => {
1389
+ if (action.type === "transactions") await signSwapRequest(post, id, action.plan, creds, validate);
1390
+ else await signWalletRequest(post, id, action.intent, creds, action.binding);
1391
+ } : void 0
1392
+ };
1393
+ });
1394
+ }
1148
1395
  async payX402(args, opts = {}) {
1149
1396
  return this.withExpiryRetry(
1150
1397
  async () => {
@@ -1199,8 +1446,8 @@ var PayboxClient = class _PayboxClient {
1199
1446
  await this.requestAfterSign(response.request_id, opts.waitForApproval)
1200
1447
  );
1201
1448
  }
1202
- claimPaymentCredentials(requestId) {
1203
- return this.request("POST", `/agent/requests/${requestId}/credentials`);
1449
+ claimPaymentCredentials(requestId2) {
1450
+ return this.request("POST", `/agent/requests/${requestId2}/credentials`);
1204
1451
  }
1205
1452
  requestAccountChange(note) {
1206
1453
  return this.request("POST", "/agent/account-change", { body: { note } });
@@ -1223,18 +1470,18 @@ var PayboxClient = class _PayboxClient {
1223
1470
  }
1224
1471
  });
1225
1472
  }
1226
- getRequest(requestId) {
1227
- return this.request("GET", `/agent/requests/${requestId}`);
1473
+ getRequest(requestId2) {
1474
+ return this.request("GET", `/agent/requests/${requestId2}`);
1228
1475
  }
1229
- requestAfterSign(requestId, wait) {
1230
- if (!wait) return this.getRequest(requestId);
1231
- return this.waitForRequest(requestId, typeof wait === "object" ? wait : {});
1476
+ requestAfterSign(requestId2, wait) {
1477
+ if (!wait) return this.getRequest(requestId2);
1478
+ return this.waitForRequest(requestId2, typeof wait === "object" ? wait : {});
1232
1479
  }
1233
- async waitForRequest(requestId, opts = {}) {
1480
+ async waitForRequest(requestId2, opts = {}) {
1234
1481
  const interval = opts.intervalMs ?? 2e3;
1235
1482
  const deadline = Date.now() + (opts.timeoutMs ?? 3e5);
1236
1483
  for (; ; ) {
1237
- const r = await this.getRequest(requestId);
1484
+ const r = await this.getRequest(requestId2);
1238
1485
  const pending = r.status === "pending_approval" || r.status === "pending_funding" || r.status === "pending_signature" || r.status === "pending_settlement" || r.status === "pending_confirmation";
1239
1486
  if (!pending || Date.now() > deadline) return r;
1240
1487
  await new Promise((res) => setTimeout(res, interval));
@@ -1262,4 +1509,4 @@ export {
1262
1509
  PayboxError,
1263
1510
  PayboxClient
1264
1511
  };
1265
- //# sourceMappingURL=chunk-OZ7KVOBT.js.map
1512
+ //# sourceMappingURL=chunk-DWDC6W5P.js.map