@mysten-incubation/suipay-buyer 0.3.0-dev.9 → 0.4.0-dev.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/README.md CHANGED
@@ -169,6 +169,35 @@ bytes to the owner signer (ADR-0065). If transaction bytes do not strictly match
169
169
  the expected operation, signing is refused and a `TransactionVerificationError`
170
170
  is thrown.
171
171
 
172
+ What is checked comes from your own input, never from the gateway's reply
173
+ (ADR-0089). `agents.createAndActivate` signs an open-recipient grant only when
174
+ you pass `accessMode: 'open'`, and only for assets you declared in
175
+ `assetScopes`, with those caps.
176
+
177
+ Activating a policy takes the terms you created it with:
178
+
179
+ ```ts
180
+ // One call: create, then activate with the same input.
181
+ await client.policies.createAndActivate({
182
+ name: 'research',
183
+ asset: 'usdc',
184
+ serviceIds: ['svc-1'],
185
+ totalCap: '10000000',
186
+ maxPerPayment: '1000000',
187
+ });
188
+
189
+ // Or activate a draft created earlier. `expected` is required.
190
+ await client.policies.activate(policyId, {
191
+ expected: { asset: 'usdc', totalCap: '10000000', maxPerPayment: '1000000', expiresAt: null, targetCount: 1 },
192
+ });
193
+ ```
194
+
195
+ Breaking in 0.4.0: `policies.activate(id)` and `policies.activate(id, signer)`
196
+ are refused with `request.invalid` before anything is fetched or signed. Pass
197
+ the policy's terms as `expected` (and the signer as `options.signer`), or use
198
+ `policies.createAndActivate`. `expected.asset` fixes the coin type: a policy
199
+ the gateway reports for another asset is refused before anything is signed.
200
+
172
201
  `createAndActivate` and the pool / policy / grant action helpers run the
173
202
  prepare → sponsor → sign → execute → finalize round-trip. After execute
174
203
  is sent, a lost confirmation is `chain.tx_unconfirmed` (money state
@@ -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,
@@ -1138,7 +1149,7 @@ var LIMIT_CODES = {
1138
1149
  }
1139
1150
  },
1140
1151
  "limit.rate_limited": {
1141
- surfaces: ["gateway", "console_server"],
1152
+ surfaces: ["gateway", "console_server", "sdk"],
1142
1153
  status: 429,
1143
1154
  title: "Rate limit exceeded",
1144
1155
  paymentState: "not_charged",
@@ -2910,6 +2921,8 @@ var CONTEXT_ALLOWLIST = /* @__PURE__ */ new Set([
2910
2921
  "seedId",
2911
2922
  "grantId",
2912
2923
  "grantObjectId",
2924
+ "policyId",
2925
+ "onChainPolicyId",
2913
2926
  "sameGrantObjectId",
2914
2927
  "verifiedGrant",
2915
2928
  "poolObjectId",
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-BSiUmi3i.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-BSiUmi3i.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-DspFvMQc.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-DspFvMQc.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';
@@ -498,6 +498,11 @@ interface AgentsApi {
498
498
  /**
499
499
  * Create then sponsor/sign/execute/finalize every returned grant.
500
500
  * Stops without retrying if any grant may already have been submitted.
501
+ *
502
+ * What is signed follows `input`, not the gateway's reply: an open grant
503
+ * only when `accessMode` is `'open'`, and only for an asset declared in
504
+ * `assetScopes`, with those caps. Anything else throws
505
+ * `TransactionVerificationError` before the signer is asked.
501
506
  */
502
507
  createAndActivate(input: CreateDelegatedSignerInput, signer?: TransactionSigner): Promise<BuyerResult<CreateAndActivateResult>>;
503
508
  }
@@ -523,6 +528,25 @@ interface SpendAccountsApi {
523
528
  /** @deprecated Renamed to {@link SpendAccountsApi}. Kept one minor for compatibility. */
524
529
  type AccountsApi = SpendAccountsApi;
525
530
 
531
+ /**
532
+ * The terms the caller created a policy with. `activate` signs only a
533
+ * `create_spend_policy` carrying exactly these values, so a gateway cannot
534
+ * raise a cap or drop an expiry between create and activate.
535
+ */
536
+ interface PolicyActivationExpectation {
537
+ /** The asset the policy was created for: its table id (`usdc`) or coin type. */
538
+ asset: string;
539
+ totalCap: string;
540
+ maxPerPayment: string;
541
+ /** ISO time or epoch ms; omit or null for no expiry. */
542
+ expiresAt?: string | number | null;
543
+ /** Number of distinct services the policy was created for. */
544
+ targetCount: number;
545
+ }
546
+ interface ActivatePolicyOptions {
547
+ expected: PolicyActivationExpectation;
548
+ signer?: TransactionSigner;
549
+ }
526
550
  interface PoliciesApi {
527
551
  list(): Promise<BuyerResult<BuyerPolicy[]>>;
528
552
  get(id: string): Promise<BuyerResult<BuyerPolicy>>;
@@ -531,7 +555,16 @@ interface PoliciesApi {
531
555
  preparePause(id: string): Promise<BuyerResult<PreparedIntent>>;
532
556
  prepareResume(id: string): Promise<BuyerResult<PreparedIntent>>;
533
557
  prepareRevoke(id: string): Promise<BuyerResult<PreparedIntent>>;
534
- activate(id: string, signer?: TransactionSigner): Promise<BuyerResult<ExecuteIntentResult>>;
558
+ /**
559
+ * Put a draft policy on chain. `options.expected` is required: the owner
560
+ * signs only the caps, expiry and target count given there. Without it
561
+ * nothing is signed and the call fails with `request.invalid`.
562
+ */
563
+ activate(id: string, options: ActivatePolicyOptions): Promise<BuyerResult<ExecuteIntentResult>>;
564
+ /** Create a policy and activate it with the same input as the expectation. */
565
+ createAndActivate(input: CreatePolicyInput, signer?: TransactionSigner): Promise<BuyerResult<ExecuteIntentResult & {
566
+ policy: BuyerPolicy;
567
+ }>>;
535
568
  pause(id: string, signer?: TransactionSigner): Promise<BuyerResult<ExecuteIntentResult>>;
536
569
  resume(id: string, signer?: TransactionSigner): Promise<BuyerResult<ExecuteIntentResult>>;
537
570
  revoke(id: string, signer?: TransactionSigner): Promise<BuyerResult<ExecuteIntentResult>>;
@@ -1815,4 +1848,22 @@ interface VerifyPreparedSettlementInput {
1815
1848
  */
1816
1849
  declare function verifyPreparedPayment(input: VerifyPreparedSettlementInput): Promise<PreparedSettlement>;
1817
1850
 
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 };
1851
+ interface OAuthDelegateBinding {
1852
+ clientId: string;
1853
+ redirectUri: string;
1854
+ resource: string;
1855
+ scope: string;
1856
+ codeChallenge: string;
1857
+ delegateAddress: string | null;
1858
+ }
1859
+ interface OAuthDelegateProof {
1860
+ signature: string;
1861
+ expiresAtMs: number;
1862
+ ownerAddress: string;
1863
+ }
1864
+ declare const OAUTH_DELEGATE_PROOF_TTL_MS: number;
1865
+ /** Exact text values are signed; the Sui address alone is normalized. */
1866
+ declare function encodeOAuthDelegateProof(binding: OAuthDelegateBinding, expiresAtMs: number, ownerAddress: string): Uint8Array;
1867
+ declare function verifyOAuthDelegateProof(binding: OAuthDelegateBinding, proof: unknown, nowMs?: number, expectedOwner?: string): Promise<boolean>;
1868
+
1869
+ export { type AccountApi, type AccountsApi, type ActivatePolicyOptions, 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, OAUTH_DELEGATE_PROOF_TTL_MS, type OAuthDelegateBinding, type OAuthDelegateProof, type PatchProfileInput, type PayInput, type PayResult, type Payer, type PayerOptions, type PaymentMethod, type PaymentReceipt, type PaymentRow, PaymentState, type PaymentStatusValue, type PaymentsApi, type PoliciesApi, type PolicyActivationExpectation, 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, encodeOAuthDelegateProof, manifestToSession, parseAgentManifest, personalMessageSigner, verifyOAuthDelegateProof, verifyPreparedPayment };