@mysten-incubation/suipay-buyer 0.4.0-dev.10 → 0.4.0-dev.11

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.
@@ -43,6 +43,18 @@ var ACCOUNT_CODES = {
43
43
  nextAction: "fix_request",
44
44
  user: { title: "Agent address not valid", message: "Enter a valid agent address and try again." }
45
45
  },
46
+ "account.deposit_cap_exceeded": {
47
+ surfaces: ["gateway", "sdk", "browser"],
48
+ status: 403,
49
+ title: "Deposit would exceed the vault beta cap",
50
+ paymentState: "not_charged",
51
+ retry: "never",
52
+ nextAction: "fix_request",
53
+ user: {
54
+ title: "Over the beta vault limit",
55
+ message: "This deposit would put your vault over the Mainnet Beta cap. Deposit less, or withdraw first."
56
+ }
57
+ },
46
58
  "account.finalize_mismatch": {
47
59
  surfaces: ["gateway"],
48
60
  status: 409,
@@ -2122,6 +2134,16 @@ var SERVICE_CODES = {
2122
2134
  nextAction: "retry_later",
2123
2135
  user: { title: "Temporarily unavailable", message: "This isn't available right now. Try again in a moment." }
2124
2136
  },
2137
+ "service.halted": {
2138
+ surfaces: ["gateway", "seller", "console_server", "mcp_hosted", "browser"],
2139
+ status: 503,
2140
+ title: "Services halted temporarily",
2141
+ paymentState: "not_charged",
2142
+ retry: "after_delay",
2143
+ retryAfterSeconds: 5,
2144
+ nextAction: "retry_later",
2145
+ user: { title: "Services halted temporarily", message: "Try again in a moment." }
2146
+ },
2125
2147
  "service.not_ready": {
2126
2148
  surfaces: ["gateway", "seller", "console_server"],
2127
2149
  status: 503,
@@ -2820,6 +2842,15 @@ function parseErrorPayload(input) {
2820
2842
  }
2821
2843
  return null;
2822
2844
  }
2845
+ var DEFINITE_PRE_BROADCAST_REFUSALS = /* @__PURE__ */ new Set([
2846
+ "auth.spend_not_whitelisted"
2847
+ ]);
2848
+ function isValidatedProblemRefusal(parsed, allowedCodes) {
2849
+ return parsed !== null && parsed.source === "problem" && parsed.paymentState === "not_charged" && isErrorCode(parsed.code) && allowedCodes.has(parsed.code) && definitionOf(parsed.code).status === parsed.status;
2850
+ }
2851
+ function isDefinitePreBroadcastRefusal(parsed) {
2852
+ return isValidatedProblemRefusal(parsed, DEFINITE_PRE_BROADCAST_REFUSALS);
2853
+ }
2823
2854
  function readX402Failure(headers) {
2824
2855
  for (const name of X402_RESPONSE_HEADERS) {
2825
2856
  const raw = readHeader(headers, name);
@@ -3590,6 +3621,9 @@ export {
3590
3621
  deriveNextAction,
3591
3622
  stricterPaymentState,
3592
3623
  parseErrorPayload,
3624
+ DEFINITE_PRE_BROADCAST_REFUSALS,
3625
+ isValidatedProblemRefusal,
3626
+ isDefinitePreBroadcastRefusal,
3593
3627
  logError,
3594
3628
  SuiPayError,
3595
3629
  toErrorFields,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as ErrorCode, P as PaymentState, N as NextAction, R as Receipt, C as CodeFor, D as DelegationScope, O as Offer } from './native-transfer-DWs55Mse.js';
2
- export { B as BuildNativeTransferInput, M as McpPaymentSigner, a as NativeTransferAccept, b as NativeTransferBuild, c as NativeTransferError, d as NativeTransferGas, e as NativeTransferSignerInput, S as SuiPayError, f as SuiPayErrorFields, g as buildMcpPaymentPayload, h as buildNativeTransferBytes, i as createNativeTransferSigner, j as inspectNativeTransfer, t as toErrorFields } from './native-transfer-DWs55Mse.js';
1
+ import { E as ErrorCode, P as PaymentState, N as NextAction, R as Receipt, C as CodeFor, D as DelegationScope, O as Offer } from './native-transfer-B9FlBiJZ.js';
2
+ export { B as BuildNativeTransferInput, M as McpPaymentSigner, a as NativeTransferAccept, b as NativeTransferBuild, c as NativeTransferError, d as NativeTransferGas, e as NativeTransferSignerInput, S as SuiPayError, f as SuiPayErrorFields, g as buildMcpPaymentPayload, h as buildNativeTransferBytes, i as createNativeTransferSigner, j as inspectNativeTransfer, t as toErrorFields } from './native-transfer-B9FlBiJZ.js';
3
3
  import { SuiGrpcClient } from '@mysten/sui/grpc';
4
4
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
5
5
  import { KeyObject } from 'node:crypto';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DEFINITE_PRE_BROADCAST_REFUSALS,
2
3
  ERROR_CODE_HEADER,
3
4
  NativeTransferError,
4
5
  SuiPayError,
@@ -8,12 +9,14 @@ import {
8
9
  deriveNextAction,
9
10
  deriveRetryable,
10
11
  inspectNativeTransfer,
12
+ isDefinitePreBroadcastRefusal,
11
13
  isErrorCode,
14
+ isValidatedProblemRefusal,
12
15
  logError,
13
16
  parseErrorPayload,
14
17
  stricterPaymentState,
15
18
  toErrorFields
16
- } from "./chunk-RWUAPD7K.js";
19
+ } from "./chunk-QY52OWHD.js";
17
20
 
18
21
  // src/mcp.ts
19
22
  async function buildMcpPaymentPayload(paymentRequired, signer) {
@@ -43,6 +46,7 @@ var LEGACY_CONTROL_PLANE_CODES = {
43
46
  CAP_EXCEEDED: "account.limit_exceeded",
44
47
  CONFLICT: "request.conflict",
45
48
  CROSS_ASSET_FORBIDDEN: "account.asset_unsupported",
49
+ DEPOSIT_CAP_EXCEEDED: "account.deposit_cap_exceeded",
46
50
  EXPIRED: "request.expired",
47
51
  FINALIZE_MISMATCH: "account.finalize_mismatch",
48
52
  FINALIZE_UNVERIFIED: "chain.tx_unverified",
@@ -765,23 +769,35 @@ function verifyOwnerTransaction(input) {
765
769
  throw new TransactionVerificationError("target");
766
770
  }
767
771
  const bCall = lastCmd.MoveCall;
768
- const expectedFn = op.kind === "create_pool" ? "create_account" : "fund_account";
769
- if (bCall.module !== "spend_account" || bCall.function !== expectedFn) {
772
+ const limitedFn = op.kind === "create_pool" ? "create_account_limited" : "fund_account_limited";
773
+ const legacyFn = op.kind === "create_pool" ? "create_account" : "fund_account";
774
+ if (bCall.module !== "spend_account" || bCall.function !== limitedFn && bCall.function !== legacyFn) {
770
775
  throw new TransactionVerificationError("target");
771
776
  }
777
+ const useLimited = bCall.function === limitedFn;
772
778
  const bTypeArgs = bCall.typeArguments;
773
779
  if (bTypeArgs.length !== 1 || safeNormalizeStructTag(bTypeArgs[0]) !== normCoinType) {
774
780
  throw new TransactionVerificationError("coinType");
775
781
  }
776
782
  const bArgs = bCall.arguments;
777
- const bExpectedArgCount = op.kind === "create_pool" ? 1 : 2;
783
+ const bExpectedArgCount = useLimited ? op.kind === "create_pool" ? 2 : 3 : op.kind === "create_pool" ? 1 : 2;
778
784
  if (bArgs.length !== bExpectedArgCount) {
779
785
  throw new TransactionVerificationError("target");
780
786
  }
781
- if (op.kind === "top_up") {
787
+ if (useLimited) {
788
+ const dirIdx = markInput(bArgs[0]);
789
+ const dirInput = data.inputs[dirIdx];
790
+ const dirObj = dirInput?.Object;
791
+ if (!dirObj?.SharedObject) {
792
+ throw new TransactionVerificationError("target");
793
+ }
794
+ if (op.kind === "top_up") {
795
+ assertPoolInput(bArgs[1], expectedPool);
796
+ }
797
+ } else if (op.kind === "top_up") {
782
798
  assertPoolInput(bArgs[0], expectedPool);
783
799
  }
784
- const coinArg = op.kind === "create_pool" ? bArgs[0] : bArgs[1];
800
+ const coinArg = useLimited ? op.kind === "create_pool" ? bArgs[1] : bArgs[2] : op.kind === "create_pool" ? bArgs[0] : bArgs[1];
785
801
  const splitCmdIdx = commands.findIndex((c) => c.$kind === "SplitCoins");
786
802
  if (splitCmdIdx === -1) {
787
803
  throw new TransactionVerificationError("funding");
@@ -3358,22 +3374,38 @@ function createSpendAccountChain(options) {
3358
3374
  const tx = new Transaction2();
3359
3375
  tx.setSender(input.owner);
3360
3376
  const funding = await fundingCoin(tx, input.owner, input.coinType, BigInt(input.funding));
3361
- tx.moveCall({
3362
- target: target("create_account"),
3363
- typeArguments: [input.coinType],
3364
- arguments: [funding]
3365
- });
3377
+ if (input.exclusionDirectoryId) {
3378
+ tx.moveCall({
3379
+ target: target("create_account_limited"),
3380
+ typeArguments: [input.coinType],
3381
+ arguments: [tx.object(input.exclusionDirectoryId), funding]
3382
+ });
3383
+ } else {
3384
+ tx.moveCall({
3385
+ target: target("create_account"),
3386
+ typeArguments: [input.coinType],
3387
+ arguments: [funding]
3388
+ });
3389
+ }
3366
3390
  return kindBytes(tx);
3367
3391
  },
3368
3392
  async buildTopUpKind(input) {
3369
3393
  const tx = new Transaction2();
3370
3394
  tx.setSender(input.owner);
3371
3395
  const funding = await fundingCoin(tx, input.owner, input.coinType, BigInt(input.amount));
3372
- tx.moveCall({
3373
- target: target("fund_account"),
3374
- typeArguments: [input.coinType],
3375
- arguments: [tx.object(input.poolObjectId), funding]
3376
- });
3396
+ if (input.exclusionDirectoryId) {
3397
+ tx.moveCall({
3398
+ target: target("fund_account_limited"),
3399
+ typeArguments: [input.coinType],
3400
+ arguments: [tx.object(input.exclusionDirectoryId), tx.object(input.poolObjectId), funding]
3401
+ });
3402
+ } else {
3403
+ tx.moveCall({
3404
+ target: target("fund_account"),
3405
+ typeArguments: [input.coinType],
3406
+ arguments: [tx.object(input.poolObjectId), funding]
3407
+ });
3408
+ }
3377
3409
  return kindBytes(tx);
3378
3410
  },
3379
3411
  async buildWithdrawKind(input) {
@@ -8050,6 +8082,12 @@ async function readPublicSessionState(getObjectJson, grantObjectId) {
8050
8082
  revoked: asBool(g.revoked)
8051
8083
  };
8052
8084
  }
8085
+ function isRevokedBootstrap(data) {
8086
+ if (!data || typeof data !== "object")
8087
+ return false;
8088
+ const dto = data;
8089
+ return Array.isArray(dto.grants) && dto.grants.length === 0 && dto.grantStatus === "revoked";
8090
+ }
8053
8091
  async function bootstrapPayerSessions(options) {
8054
8092
  const fetchImpl = options.fetchImpl ?? fetch;
8055
8093
  const basePath = options.basePath ?? "/v1/delegate";
@@ -8371,14 +8409,13 @@ function gatewayFailure(answer, local, extras) {
8371
8409
  txDigest: error.txDigest ?? extras.txDigest
8372
8410
  });
8373
8411
  }
8374
- var SPEND_NOT_WHITELISTED = "auth.spend_not_whitelisted";
8375
- var REFUSED_BEFORE_BROADCAST = {
8376
- [SPEND_NOT_WHITELISTED]: 403,
8377
- "limit.rate_limited": 429
8378
- };
8379
- async function spendWhitelistRefusal(response, paymentId) {
8412
+ var PRE_SIGN_SPONSOR_CREATE_REFUSALS = /* @__PURE__ */ new Set([
8413
+ ...DEFINITE_PRE_BROADCAST_REFUSALS,
8414
+ "limit.rate_limited"
8415
+ ]);
8416
+ async function sponsorProblemRefusal(response, paymentId, admit) {
8380
8417
  const parsed = parseErrorPayload(await readGatewayAnswer(response));
8381
- if (parsed?.source !== "problem" || parsed.paymentState !== "not_charged" || REFUSED_BEFORE_BROADCAST[parsed.code] !== parsed.status) {
8418
+ if (!admit(parsed)) {
8382
8419
  return null;
8383
8420
  }
8384
8421
  const detail = parsed.detail?.trim();
@@ -9548,7 +9585,7 @@ async function payDelegatedSpendAccount(args) {
9548
9585
  })
9549
9586
  });
9550
9587
  if (!createRes.ok) {
9551
- const refused = await spendWhitelistRefusal(createRes, paymentId);
9588
+ const refused = await sponsorProblemRefusal(createRes, paymentId, (parsed) => isValidatedProblemRefusal(parsed, PRE_SIGN_SPONSOR_CREATE_REFUSALS));
9552
9589
  if (refused) {
9553
9590
  await releaseReservation(ledger, ownedPaymentId, log);
9554
9591
  return refused;
@@ -9645,7 +9682,7 @@ async function payDelegatedSpendAccount(args) {
9645
9682
  })
9646
9683
  });
9647
9684
  if (!execRes.ok) {
9648
- const refused = await spendWhitelistRefusal(execRes, paymentId);
9685
+ const refused = await sponsorProblemRefusal(execRes, paymentId, isDefinitePreBroadcastRefusal);
9649
9686
  if (refused) {
9650
9687
  await releaseReservation(ledger, ownedPaymentId, log);
9651
9688
  return refused;
@@ -10886,6 +10923,15 @@ async function resolvePayerSession(options) {
10886
10923
  });
10887
10924
  if (whole.ok)
10888
10925
  return { ok: true, value: { ...whole.value, deployment } };
10926
+ if (whole.error.reason === MANIFEST_ERROR_CODES.NO_GRANTS) {
10927
+ if (isRevokedBootstrap(bootstrap.data)) {
10928
+ return {
10929
+ ok: false,
10930
+ error: manifestError(MANIFEST_ERROR_CODES.NO_GRANTS, "this delegate key has been revoked", "account.grant_revoked")
10931
+ };
10932
+ }
10933
+ return whole;
10934
+ }
10889
10935
  const data = bootstrap.data;
10890
10936
  const rawGrants = Array.isArray(data.grants) ? data.grants : [];
10891
10937
  const usable = [];
@@ -10918,7 +10964,9 @@ async function resolvePayerSession(options) {
10918
10964
  if (usable.length === 0) {
10919
10965
  const scoped = blocked.find((b) => b.error.reason === MANIFEST_ERROR_CODES.MISSING_POLICY_BINDING);
10920
10966
  const pick2 = scoped ?? blocked[0];
10921
- return pick2 ? { ok: false, error: explainBlockedGrant(pick2.raw, pick2.error) } : whole;
10967
+ if (pick2)
10968
+ return { ok: false, error: explainBlockedGrant(pick2.raw, pick2.error) };
10969
+ return whole;
10922
10970
  }
10923
10971
  const resolved = manifestToSession({
10924
10972
  manifest: { ...data, grants: usable },
@@ -10982,10 +11030,16 @@ async function verifyGrantOnChain(input) {
10982
11030
  return notVerified(`grant ${input.grantObjectId} draws on a different pool than the one resolved`);
10983
11031
  }
10984
11032
  if (state.revoked === true) {
10985
- return notVerified(`grant ${input.grantObjectId} is revoked on chain`);
11033
+ return {
11034
+ ok: false,
11035
+ error: manifestError(MANIFEST_ERROR_CODES.GRANT_NOT_VERIFIED, `grant ${input.grantObjectId} is revoked on chain`, "account.grant_revoked")
11036
+ };
10986
11037
  }
10987
11038
  if (state.paused === true) {
10988
- return notVerified(`grant ${input.grantObjectId} is paused on chain`);
11039
+ return {
11040
+ ok: false,
11041
+ error: manifestError(MANIFEST_ERROR_CODES.GRANT_NOT_VERIFIED, `grant ${input.grantObjectId} is paused on chain`, "account.grant_paused")
11042
+ };
10989
11043
  }
10990
11044
  return { ok: true, value: null };
10991
11045
  }
@@ -449,6 +449,19 @@ declare const ERRORS: {
449
449
  readonly message: "This isn't available right now. Try again in a moment.";
450
450
  };
451
451
  };
452
+ readonly 'service.halted': {
453
+ readonly surfaces: readonly ["gateway", "seller", "console_server", "mcp_hosted", "browser"];
454
+ readonly status: 503;
455
+ readonly title: "Services halted temporarily";
456
+ readonly paymentState: "not_charged";
457
+ readonly retry: "after_delay";
458
+ readonly retryAfterSeconds: 5;
459
+ readonly nextAction: "retry_later";
460
+ readonly user: {
461
+ readonly title: "Services halted temporarily";
462
+ readonly message: "Try again in a moment.";
463
+ };
464
+ };
452
465
  readonly 'service.not_ready': {
453
466
  readonly surfaces: readonly ["gateway", "seller", "console_server"];
454
467
  readonly status: 503;
@@ -1693,6 +1706,18 @@ declare const ERRORS: {
1693
1706
  readonly message: "Enter a valid agent address and try again.";
1694
1707
  };
1695
1708
  };
1709
+ readonly 'account.deposit_cap_exceeded': {
1710
+ readonly surfaces: readonly ["gateway", "sdk", "browser"];
1711
+ readonly status: 403;
1712
+ readonly title: "Deposit would exceed the vault beta cap";
1713
+ readonly paymentState: "not_charged";
1714
+ readonly retry: "never";
1715
+ readonly nextAction: "fix_request";
1716
+ readonly user: {
1717
+ readonly title: "Over the beta vault limit";
1718
+ readonly message: "This deposit would put your vault over the Mainnet Beta cap. Deposit less, or withdraw first.";
1719
+ };
1720
+ };
1696
1721
  readonly 'account.finalize_mismatch': {
1697
1722
  readonly surfaces: readonly ["gateway"];
1698
1723
  readonly status: 409;
@@ -1,2 +1,2 @@
1
1
  import '@mysten/sui/client';
2
- export { B as BuildNativeTransferInput, a as NativeTransferAccept, b as NativeTransferBuild, c as NativeTransferError, k as NativeTransferErrorCode, d as NativeTransferGas, e as NativeTransferSignerInput, h as buildNativeTransferBytes, i as createNativeTransferSigner, j as inspectNativeTransfer } from './native-transfer-DWs55Mse.js';
2
+ export { B as BuildNativeTransferInput, a as NativeTransferAccept, b as NativeTransferBuild, c as NativeTransferError, k as NativeTransferErrorCode, d as NativeTransferGas, e as NativeTransferSignerInput, h as buildNativeTransferBytes, i as createNativeTransferSigner, j as inspectNativeTransfer } from './native-transfer-B9FlBiJZ.js';
@@ -3,7 +3,7 @@ import {
3
3
  buildNativeTransferBytes,
4
4
  createNativeTransferSigner,
5
5
  inspectNativeTransfer
6
- } from "./chunk-RWUAPD7K.js";
6
+ } from "./chunk-QY52OWHD.js";
7
7
  export {
8
8
  NativeTransferError,
9
9
  buildNativeTransferBytes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten-incubation/suipay-buyer",
3
- "version": "0.4.0-dev.10",
3
+ "version": "0.4.0-dev.11",
4
4
  "type": "module",
5
5
  "description": "SuiPay buyer SDK — delegated spend-account pay plus a typed /v1 control-plane client.",
6
6
  "license": "MIT",