@mysten-incubation/suipay-buyer 0.3.0-dev.1 → 0.3.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.
@@ -1008,6 +1008,17 @@ var INDEXER_CODES = {
1008
1008
  user: null,
1009
1009
  logOnly: true
1010
1010
  },
1011
+ "indexer.native_settlement_deferred": {
1012
+ surfaces: ["indexer"],
1013
+ status: null,
1014
+ title: "Native settlement is deferred; holding the checkpoint",
1015
+ paymentState: "not_charged",
1016
+ retry: "after_delay",
1017
+ retryAfterSeconds: 5,
1018
+ nextAction: "retry_later",
1019
+ user: null,
1020
+ logOnly: true
1021
+ },
1011
1022
  "indexer.config_invalid": {
1012
1023
  surfaces: ["indexer"],
1013
1024
  status: null,
@@ -1622,6 +1633,55 @@ var REQUEST_CODES = {
1622
1633
  nextAction: "fix_request",
1623
1634
  user: { title: "Address not found", message: "That web address doesn't exist. Check the spelling and try again." }
1624
1635
  },
1636
+ "request.recipient_changed": {
1637
+ surfaces: ["gateway"],
1638
+ status: 409,
1639
+ title: "Pay-to address changed while its registry was being checked",
1640
+ paymentState: "not_charged",
1641
+ retry: "never",
1642
+ nextAction: "fix_request",
1643
+ user: {
1644
+ title: "Retry this publish",
1645
+ message: "The payout address changed while its payment registry was being checked. Retry so the current address is checked."
1646
+ }
1647
+ },
1648
+ "request.recipient_registry_invalid": {
1649
+ surfaces: ["gateway"],
1650
+ status: 409,
1651
+ title: "Payment registry does not verify for this deployment",
1652
+ paymentState: "not_charged",
1653
+ retry: "never",
1654
+ nextAction: "fix_request",
1655
+ user: {
1656
+ title: "Registry does not match",
1657
+ message: "The payout address's payment registry does not match this deployment. Fix it, then publish again."
1658
+ }
1659
+ },
1660
+ "request.recipient_registry_missing": {
1661
+ surfaces: ["gateway"],
1662
+ status: 409,
1663
+ title: "Pay-to address has no payment registry",
1664
+ paymentState: "not_charged",
1665
+ retry: "never",
1666
+ nextAction: "fix_request",
1667
+ user: {
1668
+ title: "Create a payment registry",
1669
+ message: "This payout address has no payment registry on this network yet. Create it in the seller console, then publish again."
1670
+ }
1671
+ },
1672
+ "request.recipient_registry_unreadable": {
1673
+ surfaces: ["gateway"],
1674
+ status: 503,
1675
+ title: "Payment registry could not be read",
1676
+ paymentState: "not_charged",
1677
+ retry: "after_delay",
1678
+ retryAfterSeconds: 5,
1679
+ nextAction: "retry_later",
1680
+ user: {
1681
+ title: "Registry unread",
1682
+ message: "The payment registry could not be read just now. Wait a moment and try again."
1683
+ }
1684
+ },
1625
1685
  "request.redirect_refused": {
1626
1686
  surfaces: ["console_server", "sdk"],
1627
1687
  status: 422,
@@ -2086,6 +2146,19 @@ var SERVICE_CODES = {
2086
2146
  user: null,
2087
2147
  logOnly: true
2088
2148
  },
2149
+ // A readiness gauge moved while the process is still serving. Not a degraded
2150
+ // boot: `service.config_degraded` is reserved for that, and for the sample
2151
+ // that actually fails closed.
2152
+ "service.readiness": {
2153
+ surfaces: ["gateway"],
2154
+ status: null,
2155
+ title: "Readiness gauge updated",
2156
+ paymentState: "not_charged",
2157
+ retry: "never",
2158
+ nextAction: "none",
2159
+ user: null,
2160
+ logOnly: true
2161
+ },
2089
2162
  // A best-effort write (a trace event, a receipt, a delivery record) failed.
2090
2163
  // The request it belongs to keeps its answer.
2091
2164
  "service.bookkeeping_failed": {
@@ -2913,6 +2986,11 @@ var CONTEXT_ALLOWLIST = /* @__PURE__ */ new Set([
2913
2986
  "rails",
2914
2987
  "shard",
2915
2988
  "metric",
2989
+ // Gateway readiness gauge. Fixed marks only: 0 or 1, and up, down, skipped, unknown.
2990
+ "ready",
2991
+ "grpc",
2992
+ "enoki",
2993
+ "postgres",
2916
2994
  "alarm",
2917
2995
  "alert",
2918
2996
  "from",
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-By0qZ2Jy.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-By0qZ2Jy.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-_cAFkvY9.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-_cAFkvY9.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';
@@ -250,6 +250,16 @@ interface CreateDelegatedSignerResponse {
250
250
  method: string;
251
251
  idempotentReplay: boolean;
252
252
  grants: PreparedSessionTxKind[];
253
+ /**
254
+ * On a replay, grants whose create already executed. Finalize their digest;
255
+ * sponsoring them again could mint a second grant.
256
+ */
257
+ submitted?: SubmittedGrantCreate[];
258
+ }
259
+ interface SubmittedGrantCreate {
260
+ grantId: string;
261
+ asset: string;
262
+ digest: string;
253
263
  }
254
264
  interface FinalizeSessionResponse {
255
265
  delegatedSignerId: string;
@@ -385,6 +395,48 @@ interface CreatePolicyResponse {
385
395
  interface CreateProfileResponse {
386
396
  profile: AgentProfile;
387
397
  }
398
+ /**
399
+ * Discriminated union for prepared consent grant transactions.
400
+ * Returned by POST /v1/oauth/sessions/:id/grants/prepare.
401
+ */
402
+ type PreparedConsentGrant = {
403
+ kind: 'sponsored';
404
+ connectionGrantId: string;
405
+ connectionGrantIds?: string[];
406
+ asset: string;
407
+ coinType: string;
408
+ target: string;
409
+ sender: string;
410
+ bytes: string;
411
+ digest: string;
412
+ transactionKindBytes?: string;
413
+ completed?: false;
414
+ } | {
415
+ kind: 'unsponsored';
416
+ connectionGrantId: string;
417
+ connectionGrantIds?: string[];
418
+ asset: string;
419
+ coinType: string;
420
+ target: string;
421
+ sender: string;
422
+ transactionKindBytes: string;
423
+ bytes?: undefined;
424
+ digest?: undefined;
425
+ completed?: false;
426
+ } | {
427
+ kind: 'completed';
428
+ connectionGrantId: string;
429
+ connectionGrantIds?: string[];
430
+ asset: string;
431
+ coinType: string;
432
+ target: string;
433
+ sender: string;
434
+ bytes?: string;
435
+ digest?: string;
436
+ grantObjectId?: string;
437
+ completed: true;
438
+ transactionKindBytes?: string;
439
+ };
388
440
  /** @deprecated Renamed to {@link DelegatedSignerSession}. */
389
441
  type DelegatedSignerGrant = DelegatedSignerSession;
390
442
  /** @deprecated Renamed to {@link PreparedSessionTxKind}. */
@@ -1763,4 +1815,4 @@ interface VerifyPreparedSettlementInput {
1763
1815
  */
1764
1816
  declare function verifyPreparedPayment(input: VerifyPreparedSettlementInput): Promise<PreparedSettlement>;
1765
1817
 
1766
- export { type AccountApi, type AccountsApi, type AgentConnectionManifest, type AgentGrantBinding, type AgentProfile, type AgentSessionBinding, type AgentsApi, type AssetScopeInput, type BuyerAccount, type BuyerClient, type BuyerClientError, type BuyerClientOptions, type BuyerConnection, type BuyerPolicy, type BuyerResult, type CatalogApi, type CatalogService, type CreateAndActivateResult, type CreateDelegatedSignerInput, type CreateDelegatedSignerResponse, type CreatePolicyInput, type CreatePolicyResponse, type CreateProfileInput, type CreateProfileResponse, type DashboardBridgeResolvers, type DashboardConnectionManifest, type DelegatedSigner, type DelegatedSignerGrant, type DelegatedSignerGrantStatus, type DelegatedSignerSession, type DelegatedSignerStatus, type DelegatedSignersApi, ErrorCode, type ExecuteIntentKind, type ExecuteIntentResult, type FinalizeGrantResponse, type FinalizeIntentResult, type FinalizeSessionResponse, type FundHistoryItem, type GrantsApi, type ManifestError, type ManifestResult, NextAction, type PatchProfileInput, type PayInput, type PayResult, type Payer, type PayerOptions, type PaymentMethod, type PaymentReceipt, type PaymentRow, PaymentState, type PaymentStatusValue, type PaymentsApi, type PoliciesApi, type PolicyStatus, type PolicyTarget, type PrepareCreateGrantInput, type PrepareCreateSessionInput, type PreparedGrantTxKind, type PreparedIntent, type PreparedRevokeTxKind, type PreparedSessionTxKind, type ProfileStatus, type ProfilesApi, type ReceiptsApi, type RegistryApi, type RegistryService, type RevokeDelegatedSignerResponse, type ServiceRail, type ServicesApi, type SessionsApi, type SettlementRow, type SettlementsApi, type SpendAccount, type SpendAccountStatus, type SpendAccountsApi, type SponsoredTx, type TransactionSigner, type TrustSignal, createBuyer, createBuyerControlPlane, createMemoryLedger, createPayer, createReader, dashboardManifestToAgentManifest, manifestToSession, parseAgentManifest, personalMessageSigner, verifyPreparedPayment };
1818
+ export { type AccountApi, type AccountsApi, type AgentConnectionManifest, type AgentGrantBinding, type AgentProfile, type AgentSessionBinding, type AgentsApi, type AssetScopeInput, type BuyerAccount, type BuyerClient, type BuyerClientError, type BuyerClientOptions, type BuyerConnection, type BuyerPolicy, type BuyerResult, type CatalogApi, type CatalogService, type CreateAndActivateResult, type CreateDelegatedSignerInput, type CreateDelegatedSignerResponse, type CreatePolicyInput, type CreatePolicyResponse, type CreateProfileInput, type CreateProfileResponse, type DashboardBridgeResolvers, type DashboardConnectionManifest, type DelegatedSigner, type DelegatedSignerGrant, type DelegatedSignerGrantStatus, type DelegatedSignerSession, type DelegatedSignerStatus, type DelegatedSignersApi, ErrorCode, type ExecuteIntentKind, type ExecuteIntentResult, type FinalizeGrantResponse, type FinalizeIntentResult, type FinalizeSessionResponse, type FundHistoryItem, type GrantsApi, type ManifestError, type ManifestResult, NextAction, type PatchProfileInput, type PayInput, type PayResult, type Payer, type PayerOptions, type PaymentMethod, type PaymentReceipt, type PaymentRow, PaymentState, type PaymentStatusValue, type PaymentsApi, type PoliciesApi, type PolicyStatus, type PolicyTarget, type PrepareCreateGrantInput, type PrepareCreateSessionInput, type PreparedConsentGrant, type PreparedGrantTxKind, type PreparedIntent, type PreparedRevokeTxKind, type PreparedSessionTxKind, type ProfileStatus, type ProfilesApi, type ReceiptsApi, type RegistryApi, type RegistryService, type RevokeDelegatedSignerResponse, type ServiceRail, type ServicesApi, type SessionsApi, type SettlementRow, type SettlementsApi, type SpendAccount, type SpendAccountStatus, type SpendAccountsApi, type SponsoredTx, type SubmittedGrantCreate, type TransactionSigner, type TrustSignal, createBuyer, createBuyerControlPlane, createMemoryLedger, createPayer, createReader, dashboardManifestToAgentManifest, manifestToSession, parseAgentManifest, personalMessageSigner, verifyPreparedPayment };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  parseErrorPayload,
14
14
  stricterPaymentState,
15
15
  toErrorFields
16
- } from "./chunk-JBDYVEX2.js";
16
+ } from "./chunk-MTAXAJHB.js";
17
17
 
18
18
  // src/mcp.ts
19
19
  async function buildMcpPaymentPayload(paymentRequired, signer) {
@@ -514,7 +514,7 @@ function verifyOwnerTransaction(input) {
514
514
  if (k === "TransferObjects" || k === "Publish" || k === "Upgrade") {
515
515
  throw new TransactionVerificationError("unsupportedOperation");
516
516
  }
517
- if (k === "MakeMoveVec" && input.operation.kind !== "create_policy" && input.operation.kind !== "replace_grant") {
517
+ if (k === "MakeMoveVec" && input.operation.kind !== "create_policy" && input.operation.kind !== "replace_grant" && input.operation.kind !== "create_grant_consent_batch") {
518
518
  throw new TransactionVerificationError("unsupportedOperation");
519
519
  }
520
520
  }
@@ -958,87 +958,253 @@ function verifyOwnerTransaction(input) {
958
958
  allowedAssets.add(assetNorm);
959
959
  const existing = assetGroups.get(assetNorm) ?? {
960
960
  sumTotalCap: 0n,
961
- policyIds: []
961
+ policyIds: [],
962
+ policies: []
962
963
  };
963
964
  existing.sumTotalCap += capAmt;
964
965
  existing.policyIds.push(p.id);
966
+ existing.policies.push(p);
965
967
  assetGroups.set(assetNorm, existing);
966
968
  }
967
- const distinctAssetCount = assetGroups.size;
968
- const batchN = commands.length;
969
- if (batchN > distinctAssetCount) {
970
- throw new TransactionVerificationError("caps");
971
- }
972
- const seenCoins = /* @__PURE__ */ new Set();
973
- const seenPools = /* @__PURE__ */ new Set();
974
- for (let i = 0; i < batchN; i++) {
975
- const cmd = commands[i];
976
- if (cmd.$kind !== "MoveCall") {
977
- throw new TransactionVerificationError("unsupportedOperation");
978
- }
979
- const mc = cmd.MoveCall;
980
- if (mc.module !== "spend_account" || mc.function !== "create_policy_grant") {
981
- throw new TransactionVerificationError("target");
982
- }
983
- const mcTypes = mc.typeArguments;
984
- if (mcTypes.length !== 1) {
985
- throw new TransactionVerificationError("coinType");
986
- }
987
- const cmdCoinType = safeNormalizeStructTag(mcTypes[0]);
988
- if (!cmdCoinType || !allowedAssets.has(cmdCoinType)) {
989
- throw new TransactionVerificationError("coinType");
990
- }
991
- if (seenCoins.has(cmdCoinType)) {
992
- throw new TransactionVerificationError("coinType");
993
- }
994
- seenCoins.add(cmdCoinType);
995
- const groupInfo = assetGroups.get(cmdCoinType);
996
- const args = mc.arguments;
997
- if (args.length !== 6) {
998
- throw new TransactionVerificationError("target");
999
- }
1000
- const poolInputIdx = markInput(args[0]);
1001
- const poolId = getObjectIdFromInput(data.inputs[poolInputIdx]);
1002
- if (!poolId) {
1003
- throw new TransactionVerificationError("pool");
1004
- }
1005
- if (seenPools.has(poolId)) {
1006
- throw new TransactionVerificationError("pool");
1007
- }
1008
- seenPools.add(poolId);
1009
- const delInputIdx = markInput(args[1]);
1010
- const delBytes = getPureBytes(data.inputs[delInputIdx]);
1011
- if (!delBytes || parseAddress(delBytes) !== safeNormalizeAddress(op.delegate.address)) {
1012
- throw new TransactionVerificationError("delegate");
1013
- }
1014
- const capInputIdx = markInput(args[2]);
1015
- const capBytes = getPureBytes(data.inputs[capInputIdx]);
1016
- if (!capBytes) {
1017
- throw new TransactionVerificationError("caps");
969
+ const isCombined = commands.length >= 5 && commands[0]?.$kind === "MoveCall" && commands[0].MoveCall?.module === "spend_account" && commands[0].MoveCall?.function === "new_policy_target";
970
+ if (!isCombined) {
971
+ const hasDraftPolicy = uniquePolicies.some((p) => p.status === "draft" || p.onChainPolicyId == null && p.targets && p.targets.length > 0);
972
+ if (hasDraftPolicy) {
973
+ throw new TransactionVerificationError("policyId");
1018
974
  }
1019
- const txSessionCap = parseOptionU64(capBytes);
1020
- const maxInputIdx = markInput(args[3]);
1021
- const maxBytes = getPureBytes(data.inputs[maxInputIdx]);
1022
- if (!maxBytes) {
975
+ const distinctAssetCount = assetGroups.size;
976
+ const batchN = commands.length;
977
+ if (batchN > distinctAssetCount) {
1023
978
  throw new TransactionVerificationError("caps");
1024
979
  }
1025
- const txMaxPerPayment = parseOptionU64(maxBytes);
1026
- if (txSessionCap === null || txMaxPerPayment !== txSessionCap) {
1027
- throw new TransactionVerificationError("caps");
980
+ const seenCoins = /* @__PURE__ */ new Set();
981
+ const seenPools = /* @__PURE__ */ new Set();
982
+ for (let i = 0; i < batchN; i++) {
983
+ const cmd = commands[i];
984
+ if (cmd.$kind !== "MoveCall") {
985
+ throw new TransactionVerificationError("unsupportedOperation");
986
+ }
987
+ const mc = cmd.MoveCall;
988
+ if (mc.module !== "spend_account" || mc.function !== "create_policy_grant") {
989
+ throw new TransactionVerificationError("target");
990
+ }
991
+ const mcTypes = mc.typeArguments;
992
+ if (mcTypes.length !== 1) {
993
+ throw new TransactionVerificationError("coinType");
994
+ }
995
+ const cmdCoinType2 = safeNormalizeStructTag(mcTypes[0]);
996
+ if (!cmdCoinType2 || !allowedAssets.has(cmdCoinType2)) {
997
+ throw new TransactionVerificationError("coinType");
998
+ }
999
+ if (seenCoins.has(cmdCoinType2)) {
1000
+ throw new TransactionVerificationError("coinType");
1001
+ }
1002
+ seenCoins.add(cmdCoinType2);
1003
+ const groupInfo2 = assetGroups.get(cmdCoinType2);
1004
+ const args = mc.arguments;
1005
+ if (args.length !== 6) {
1006
+ throw new TransactionVerificationError("target");
1007
+ }
1008
+ const poolInputIdx2 = markInput(args[0]);
1009
+ const poolId2 = getObjectIdFromInput(data.inputs[poolInputIdx2]);
1010
+ if (!poolId2) {
1011
+ throw new TransactionVerificationError("pool");
1012
+ }
1013
+ if (seenPools.has(poolId2)) {
1014
+ throw new TransactionVerificationError("pool");
1015
+ }
1016
+ seenPools.add(poolId2);
1017
+ const delInputIdx2 = markInput(args[1]);
1018
+ const delBytes2 = getPureBytes(data.inputs[delInputIdx2]);
1019
+ if (!delBytes2 || parseAddress(delBytes2) !== safeNormalizeAddress(op.delegate.address)) {
1020
+ throw new TransactionVerificationError("delegate");
1021
+ }
1022
+ const capInputIdx2 = markInput(args[2]);
1023
+ const capBytes2 = getPureBytes(data.inputs[capInputIdx2]);
1024
+ if (!capBytes2) {
1025
+ throw new TransactionVerificationError("caps");
1026
+ }
1027
+ const txSessionCap2 = parseOptionU64(capBytes2);
1028
+ const maxInputIdx2 = markInput(args[3]);
1029
+ const maxBytes2 = getPureBytes(data.inputs[maxInputIdx2]);
1030
+ if (!maxBytes2) {
1031
+ throw new TransactionVerificationError("caps");
1032
+ }
1033
+ const txMaxPerPayment2 = parseOptionU64(maxBytes2);
1034
+ if (txSessionCap2 === null || txMaxPerPayment2 !== txSessionCap2) {
1035
+ throw new TransactionVerificationError("caps");
1036
+ }
1037
+ if (txSessionCap2 > groupInfo2.sumTotalCap) {
1038
+ throw new TransactionVerificationError("caps");
1039
+ }
1040
+ assertPureU64(args[4], 0n, "expiry");
1041
+ const pIdsInputIdx = markInput(args[5]);
1042
+ const pIdsBytes = getPureBytes(data.inputs[pIdsInputIdx]);
1043
+ if (!pIdsBytes) {
1044
+ throw new TransactionVerificationError("policyId");
1045
+ }
1046
+ const parsedPids = bcs.vector(bcs.u64()).parse(pIdsBytes);
1047
+ const expectedOnChainIds = groupInfo2.policies.map((p) => p.onChainPolicyId != null ? String(p.onChainPolicyId) : null).filter((id) => id != null);
1048
+ if (expectedOnChainIds.length === 0 || expectedOnChainIds.length !== groupInfo2.policies.length || parsedPids.length !== expectedOnChainIds.length) {
1049
+ throw new TransactionVerificationError("policyId");
1050
+ }
1051
+ for (let idx = 0; idx < parsedPids.length; idx++) {
1052
+ if (String(parsedPids[idx]) !== expectedOnChainIds[idx]) {
1053
+ throw new TransactionVerificationError("policyId");
1054
+ }
1055
+ }
1028
1056
  }
1029
- if (txSessionCap > groupInfo.sumTotalCap) {
1030
- throw new TransactionVerificationError("caps");
1057
+ break;
1058
+ }
1059
+ if (uniquePolicies.length !== 1) {
1060
+ throw new TransactionVerificationError("targets");
1061
+ }
1062
+ const draftPolicy = uniquePolicies[0];
1063
+ let N = 0;
1064
+ while (N < commands.length && commands[N]?.$kind === "MoveCall" && commands[N].MoveCall?.module === "spend_account" && commands[N].MoveCall?.function === "new_policy_target") {
1065
+ N++;
1066
+ }
1067
+ if (!draftPolicy.targets || draftPolicy.targets.length !== N) {
1068
+ throw new TransactionVerificationError("targets");
1069
+ }
1070
+ if (commands.length !== N + 4) {
1071
+ throw new TransactionVerificationError("targets");
1072
+ }
1073
+ for (let i = 0; i < N; i++) {
1074
+ const c = commands[i];
1075
+ const mc = c.MoveCall;
1076
+ if (mc.arguments.length !== 3) {
1077
+ throw new TransactionVerificationError("target");
1031
1078
  }
1032
- assertPureU64(args[4], 0n, "expiry");
1033
- const pIdsInputIdx = markInput(args[5]);
1034
- const pIdsBytes = getPureBytes(data.inputs[pIdsInputIdx]);
1035
- if (!pIdsBytes) {
1036
- throw new TransactionVerificationError("policyId");
1079
+ const expectedTarget = draftPolicy.targets[i];
1080
+ const hashIdx = markInput(mc.arguments[0]);
1081
+ const hashBytes = getPureBytes(data.inputs[hashIdx]);
1082
+ const hash = hashBytes ? bcs.vector(bcs.u8()).parse(hashBytes) : null;
1083
+ const got = hash ? [...hash].map((byte) => byte.toString(16).padStart(2, "0")).join("") : "";
1084
+ const want = expectedTarget.targetHash.trim().toLowerCase().replace(/^0x/, "");
1085
+ if (!hash || got !== want)
1086
+ throw new TransactionVerificationError("target");
1087
+ const recipientIdx = markInput(mc.arguments[1]);
1088
+ const recipientBytes = getPureBytes(data.inputs[recipientIdx]);
1089
+ if (!recipientBytes || parseAddress(recipientBytes) !== safeNormalizeAddress(expectedTarget.recipient)) {
1090
+ throw new TransactionVerificationError("target");
1037
1091
  }
1038
- if (parseVectorU64Len(pIdsBytes) > groupInfo.policyIds.length) {
1039
- throw new TransactionVerificationError("policyId");
1092
+ assertPureU64(mc.arguments[2], BigInt(expectedTarget.maxPerPayment), "target");
1093
+ }
1094
+ const vecCmd = commands[N];
1095
+ if (vecCmd.$kind !== "MakeMoveVec") {
1096
+ throw new TransactionVerificationError("unsupportedOperation");
1097
+ }
1098
+ const targetElements = vecCmd.MakeMoveVec?.elements;
1099
+ if (!Array.isArray(targetElements) || targetElements.length !== N) {
1100
+ throw new TransactionVerificationError("targets");
1101
+ }
1102
+ for (let i = 0; i < N; i++) {
1103
+ const el = markResult(targetElements[i], "targets");
1104
+ if (el.cmdIndex !== i || el.resIndex !== 0) {
1105
+ throw new TransactionVerificationError("targets");
1040
1106
  }
1041
1107
  }
1108
+ const createPolicyCmd = commands[N + 1];
1109
+ if (createPolicyCmd.$kind !== "MoveCall" || createPolicyCmd.MoveCall?.module !== "spend_account" || createPolicyCmd.MoveCall?.function !== "create_spend_policy") {
1110
+ throw new TransactionVerificationError("target");
1111
+ }
1112
+ const policyTypes = createPolicyCmd.MoveCall.typeArguments;
1113
+ if (!policyTypes || policyTypes.length !== 1) {
1114
+ throw new TransactionVerificationError("coinType");
1115
+ }
1116
+ const cmdCoinType = safeNormalizeStructTag(policyTypes[0]);
1117
+ if (!cmdCoinType || !allowedAssets.has(cmdCoinType)) {
1118
+ throw new TransactionVerificationError("coinType");
1119
+ }
1120
+ const groupInfo = assetGroups.get(cmdCoinType);
1121
+ const policyArgs = createPolicyCmd.MoveCall.arguments;
1122
+ if (!policyArgs || policyArgs.length !== 5) {
1123
+ throw new TransactionVerificationError("target");
1124
+ }
1125
+ const poolInputIdx = markInput(policyArgs[0]);
1126
+ const poolId = getObjectIdFromInput(data.inputs[poolInputIdx]);
1127
+ if (!poolId) {
1128
+ throw new TransactionVerificationError("pool");
1129
+ }
1130
+ const targetsRes = markResult(policyArgs[1], "unsupportedOperation");
1131
+ if (targetsRes.cmdIndex !== N || targetsRes.resIndex !== 0) {
1132
+ throw new TransactionVerificationError("unsupportedOperation");
1133
+ }
1134
+ const totalCapInputIdx = markInput(policyArgs[2]);
1135
+ const totalCapBytes = getPureBytes(data.inputs[totalCapInputIdx]);
1136
+ if (!totalCapBytes)
1137
+ throw new TransactionVerificationError("caps");
1138
+ const policyTotalCap = parseU64(totalCapBytes);
1139
+ if (policyTotalCap <= 0n || policyTotalCap > groupInfo.sumTotalCap || policyTotalCap !== BigInt(draftPolicy.totalCap)) {
1140
+ throw new TransactionVerificationError("caps");
1141
+ }
1142
+ const maxPerPaymentInputIdx = markInput(policyArgs[3]);
1143
+ const maxPerPaymentBytes = getPureBytes(data.inputs[maxPerPaymentInputIdx]);
1144
+ if (!maxPerPaymentBytes)
1145
+ throw new TransactionVerificationError("caps");
1146
+ const policyMaxPerPayment = parseU64(maxPerPaymentBytes);
1147
+ if (policyMaxPerPayment <= 0n || policyMaxPerPayment > policyTotalCap || draftPolicy.maxPerPayment == null || policyMaxPerPayment !== BigInt(draftPolicy.maxPerPayment)) {
1148
+ throw new TransactionVerificationError("caps");
1149
+ }
1150
+ assertPureU64(policyArgs[4], callerExpiryU64(draftPolicy.expiresAtMs), "expiry");
1151
+ const idVecCmd = commands[N + 2];
1152
+ if (idVecCmd.$kind !== "MakeMoveVec" || !Array.isArray(idVecCmd.MakeMoveVec?.elements) || idVecCmd.MakeMoveVec.elements.length !== 1) {
1153
+ throw new TransactionVerificationError("policyId");
1154
+ }
1155
+ const policyRes = markResult(idVecCmd.MakeMoveVec.elements[0], "policyId");
1156
+ if (policyRes.cmdIndex !== N + 1 || policyRes.resIndex !== 0) {
1157
+ throw new TransactionVerificationError("policyId");
1158
+ }
1159
+ const grantCmd = commands[N + 3];
1160
+ if (grantCmd.$kind !== "MoveCall" || grantCmd.MoveCall?.module !== "spend_account" || grantCmd.MoveCall?.function !== "create_policy_grant") {
1161
+ throw new TransactionVerificationError("target");
1162
+ }
1163
+ const grantTypes = grantCmd.MoveCall.typeArguments;
1164
+ if (!grantTypes || grantTypes.length !== 1) {
1165
+ throw new TransactionVerificationError("coinType");
1166
+ }
1167
+ const grantCoinType = safeNormalizeStructTag(grantTypes[0]);
1168
+ if (grantCoinType !== cmdCoinType) {
1169
+ throw new TransactionVerificationError("coinType");
1170
+ }
1171
+ const grantArgs = grantCmd.MoveCall.arguments;
1172
+ if (!grantArgs || grantArgs.length !== 6) {
1173
+ throw new TransactionVerificationError("target");
1174
+ }
1175
+ const grantPoolInputIdx = markInput(grantArgs[0]);
1176
+ const grantPoolId = getObjectIdFromInput(data.inputs[grantPoolInputIdx]);
1177
+ if (!grantPoolId || grantPoolId !== poolId) {
1178
+ throw new TransactionVerificationError("pool");
1179
+ }
1180
+ const delInputIdx = markInput(grantArgs[1]);
1181
+ const delBytes = getPureBytes(data.inputs[delInputIdx]);
1182
+ if (!delBytes || parseAddress(delBytes) !== safeNormalizeAddress(op.delegate.address)) {
1183
+ throw new TransactionVerificationError("delegate");
1184
+ }
1185
+ const capInputIdx = markInput(grantArgs[2]);
1186
+ const capBytes = getPureBytes(data.inputs[capInputIdx]);
1187
+ if (!capBytes) {
1188
+ throw new TransactionVerificationError("caps");
1189
+ }
1190
+ const txSessionCap = parseOptionU64(capBytes);
1191
+ const maxInputIdx = markInput(grantArgs[3]);
1192
+ const maxBytes = getPureBytes(data.inputs[maxInputIdx]);
1193
+ if (!maxBytes) {
1194
+ throw new TransactionVerificationError("caps");
1195
+ }
1196
+ const txMaxPerPayment = parseOptionU64(maxBytes);
1197
+ if (txSessionCap === null || txMaxPerPayment !== txSessionCap) {
1198
+ throw new TransactionVerificationError("caps");
1199
+ }
1200
+ if (txSessionCap > groupInfo.sumTotalCap) {
1201
+ throw new TransactionVerificationError("caps");
1202
+ }
1203
+ assertPureU64(grantArgs[4], 0n, "expiry");
1204
+ const grantVecRes = markResult(grantArgs[5], "policyId");
1205
+ if (grantVecRes.cmdIndex !== N + 2 || grantVecRes.resIndex !== 0) {
1206
+ throw new TransactionVerificationError("policyId");
1207
+ }
1042
1208
  break;
1043
1209
  }
1044
1210
  case "create_grant_open": {
@@ -1580,6 +1746,12 @@ function createAgentsApi(transport) {
1580
1746
  if (!created.ok)
1581
1747
  return created;
1582
1748
  const finalized = [];
1749
+ for (const submitted of created.value.submitted ?? []) {
1750
+ const fin = await finalizeGrant(created.value.delegatedSignerId, submitted.grantId, submitted.digest);
1751
+ if (!fin.ok)
1752
+ return fin;
1753
+ finalized.push(fin.value);
1754
+ }
1583
1755
  for (const grant of created.value.grants) {
1584
1756
  const scope = input.assetScopes.find((s) => s.asset.toLowerCase() === grant.asset.toLowerCase() || supportedAssetByCoinType(s.asset)?.id === grant.asset.toLowerCase());
1585
1757
  const coinType = TESTNET_ASSETS.find((a) => a.id === grant.asset.toLowerCase() || a.symbol.toLowerCase() === grant.asset.toLowerCase())?.coinType ?? scope?.asset ?? grant.asset;
@@ -2574,6 +2746,14 @@ var SERVICE_STATE_TRANSITIONS = Object.freeze([
2574
2746
  to: "payout_change",
2575
2747
  actors: ["system"],
2576
2748
  requires: ["reason_code"]
2749
+ },
2750
+ {
2751
+ id: "T25",
2752
+ dimension: "suspension",
2753
+ from: ["binding_changed"],
2754
+ to: "none",
2755
+ actors: ["system"],
2756
+ requires: ["reason_code"]
2577
2757
  }
2578
2758
  ]);
2579
2759
 
@@ -2973,6 +3153,70 @@ function createSpendAccountChain(options) {
2973
3153
  });
2974
3154
  return kindBytes(tx);
2975
3155
  },
3156
+ async buildCreatePolicyAndGrantKind(input) {
3157
+ if (!input.policy.targets?.length) {
3158
+ throw new Error("create_spend_policy requires at least one target");
3159
+ }
3160
+ if (!input.policy.totalCap || BigInt(input.policy.totalCap) <= 0n) {
3161
+ throw new Error("create_spend_policy requires a non-zero total_cap");
3162
+ }
3163
+ if (!input.policy.maxPerPayment || BigInt(input.policy.maxPerPayment) <= 0n) {
3164
+ throw new Error("create_spend_policy requires a non-zero max_per_payment");
3165
+ }
3166
+ if (!input.grant.sessionCap || BigInt(input.grant.sessionCap) <= 0n) {
3167
+ throw new Error("create_grant requires a non-zero session_cap");
3168
+ }
3169
+ if (!input.grant.maxPerPayment || BigInt(input.grant.maxPerPayment) <= 0n) {
3170
+ throw new Error("create_grant requires a non-zero max_per_payment");
3171
+ }
3172
+ const tx = new Transaction2();
3173
+ tx.setSender(input.owner);
3174
+ const targetResults = input.policy.targets.map((t) => {
3175
+ const hash = targetHashBytes(t.targetHash);
3176
+ return tx.moveCall({
3177
+ target: target("new_policy_target"),
3178
+ arguments: [
3179
+ tx.pure.vector("u8", Array.from(hash)),
3180
+ tx.pure.address(t.recipient),
3181
+ tx.pure.u64(BigInt(t.maxPerPayment))
3182
+ ]
3183
+ });
3184
+ });
3185
+ const targetsVec = tx.makeMoveVec({
3186
+ type: `${packageId}::${MODULE}::PolicyTarget`,
3187
+ elements: targetResults
3188
+ });
3189
+ const policyExpires = input.policy.expiresAtMs === void 0 || input.policy.expiresAtMs === null ? 0n : BigInt(input.policy.expiresAtMs);
3190
+ const policyIdResult = tx.moveCall({
3191
+ target: target("create_spend_policy"),
3192
+ typeArguments: [input.coinType],
3193
+ arguments: [
3194
+ tx.object(input.poolObjectId),
3195
+ targetsVec,
3196
+ tx.pure.u64(BigInt(input.policy.totalCap)),
3197
+ tx.pure.u64(BigInt(input.policy.maxPerPayment)),
3198
+ tx.pure.u64(policyExpires)
3199
+ ]
3200
+ });
3201
+ const policyIdsVec = tx.makeMoveVec({
3202
+ type: "u64",
3203
+ elements: [policyIdResult]
3204
+ });
3205
+ const grantExpires = input.grant.expiresAtMs === void 0 || input.grant.expiresAtMs === null ? 0n : BigInt(input.grant.expiresAtMs);
3206
+ tx.moveCall({
3207
+ target: target("create_policy_grant"),
3208
+ typeArguments: [input.coinType],
3209
+ arguments: [
3210
+ tx.object(input.poolObjectId),
3211
+ tx.pure.address(input.delegate),
3212
+ tx.pure.option("u64", BigInt(input.grant.sessionCap)),
3213
+ tx.pure.option("u64", BigInt(input.grant.maxPerPayment)),
3214
+ tx.pure.u64(grantExpires),
3215
+ policyIdsVec
3216
+ ]
3217
+ });
3218
+ return kindBytes(tx);
3219
+ },
2976
3220
  async buildPausePolicyKind(input) {
2977
3221
  const tx = new Transaction2();
2978
3222
  tx.setSender(input.owner);
@@ -57,6 +57,17 @@ declare const ERRORS: {
57
57
  readonly user: null;
58
58
  readonly logOnly: true;
59
59
  };
60
+ readonly 'indexer.native_settlement_deferred': {
61
+ readonly surfaces: readonly ["indexer"];
62
+ readonly status: null;
63
+ readonly title: "Native settlement is deferred; holding the checkpoint";
64
+ readonly paymentState: "not_charged";
65
+ readonly retry: "after_delay";
66
+ readonly retryAfterSeconds: 5;
67
+ readonly nextAction: "retry_later";
68
+ readonly user: null;
69
+ readonly logOnly: true;
70
+ };
60
71
  readonly 'indexer.config_invalid': {
61
72
  readonly surfaces: readonly ["indexer"];
62
73
  readonly status: null;
@@ -459,6 +470,16 @@ declare const ERRORS: {
459
470
  readonly user: null;
460
471
  readonly logOnly: true;
461
472
  };
473
+ readonly 'service.readiness': {
474
+ readonly surfaces: readonly ["gateway"];
475
+ readonly status: null;
476
+ readonly title: "Readiness gauge updated";
477
+ readonly paymentState: "not_charged";
478
+ readonly retry: "never";
479
+ readonly nextAction: "none";
480
+ readonly user: null;
481
+ readonly logOnly: true;
482
+ };
462
483
  readonly 'service.bookkeeping_failed': {
463
484
  readonly surfaces: readonly ["gateway"];
464
485
  readonly status: null;
@@ -2696,6 +2717,55 @@ declare const ERRORS: {
2696
2717
  readonly message: "That web address doesn't exist. Check the spelling and try again.";
2697
2718
  };
2698
2719
  };
2720
+ readonly 'request.recipient_changed': {
2721
+ readonly surfaces: readonly ["gateway"];
2722
+ readonly status: 409;
2723
+ readonly title: "Pay-to address changed while its registry was being checked";
2724
+ readonly paymentState: "not_charged";
2725
+ readonly retry: "never";
2726
+ readonly nextAction: "fix_request";
2727
+ readonly user: {
2728
+ readonly title: "Retry this publish";
2729
+ readonly message: "The payout address changed while its payment registry was being checked. Retry so the current address is checked.";
2730
+ };
2731
+ };
2732
+ readonly 'request.recipient_registry_invalid': {
2733
+ readonly surfaces: readonly ["gateway"];
2734
+ readonly status: 409;
2735
+ readonly title: "Payment registry does not verify for this deployment";
2736
+ readonly paymentState: "not_charged";
2737
+ readonly retry: "never";
2738
+ readonly nextAction: "fix_request";
2739
+ readonly user: {
2740
+ readonly title: "Registry does not match";
2741
+ readonly message: "The payout address's payment registry does not match this deployment. Fix it, then publish again.";
2742
+ };
2743
+ };
2744
+ readonly 'request.recipient_registry_missing': {
2745
+ readonly surfaces: readonly ["gateway"];
2746
+ readonly status: 409;
2747
+ readonly title: "Pay-to address has no payment registry";
2748
+ readonly paymentState: "not_charged";
2749
+ readonly retry: "never";
2750
+ readonly nextAction: "fix_request";
2751
+ readonly user: {
2752
+ readonly title: "Create a payment registry";
2753
+ readonly message: "This payout address has no payment registry on this network yet. Create it in the seller console, then publish again.";
2754
+ };
2755
+ };
2756
+ readonly 'request.recipient_registry_unreadable': {
2757
+ readonly surfaces: readonly ["gateway"];
2758
+ readonly status: 503;
2759
+ readonly title: "Payment registry could not be read";
2760
+ readonly paymentState: "not_charged";
2761
+ readonly retry: "after_delay";
2762
+ readonly retryAfterSeconds: 5;
2763
+ readonly nextAction: "retry_later";
2764
+ readonly user: {
2765
+ readonly title: "Registry unread";
2766
+ readonly message: "The payment registry could not be read just now. Wait a moment and try again.";
2767
+ };
2768
+ };
2699
2769
  readonly 'request.redirect_refused': {
2700
2770
  readonly surfaces: readonly ["console_server", "sdk"];
2701
2771
  readonly status: 422;
@@ -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-By0qZ2Jy.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-_cAFkvY9.js';
@@ -3,7 +3,7 @@ import {
3
3
  buildNativeTransferBytes,
4
4
  createNativeTransferSigner,
5
5
  inspectNativeTransfer
6
- } from "./chunk-JBDYVEX2.js";
6
+ } from "./chunk-MTAXAJHB.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.3.0-dev.1",
3
+ "version": "0.3.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",
@@ -40,8 +40,8 @@
40
40
  "tsup": "^8.0.0",
41
41
  "typescript": "^6.0.3",
42
42
  "vitest": "^4.1.10",
43
- "@cmdoss/suipay-core": "0.1.0",
44
- "@cmdoss/suipay-sdk": "0.1.0"
43
+ "@cmdoss/suipay-sdk": "0.1.0",
44
+ "@cmdoss/suipay-core": "0.1.0"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsup",