@mysten-incubation/suipay-buyer 0.3.0-dev.21 → 0.3.0-dev.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1815,4 +1815,22 @@ interface VerifyPreparedSettlementInput {
1815
1815
  */
1816
1816
  declare function verifyPreparedPayment(input: VerifyPreparedSettlementInput): Promise<PreparedSettlement>;
1817
1817
 
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 };
1818
+ interface OAuthDelegateBinding {
1819
+ clientId: string;
1820
+ redirectUri: string;
1821
+ resource: string;
1822
+ scope: string;
1823
+ codeChallenge: string;
1824
+ delegateAddress: string | null;
1825
+ }
1826
+ interface OAuthDelegateProof {
1827
+ signature: string;
1828
+ expiresAtMs: number;
1829
+ ownerAddress: string;
1830
+ }
1831
+ declare const OAUTH_DELEGATE_PROOF_TTL_MS: number;
1832
+ /** Exact text values are signed; the Sui address alone is normalized. */
1833
+ declare function encodeOAuthDelegateProof(binding: OAuthDelegateBinding, expiresAtMs: number, ownerAddress: string): Uint8Array;
1834
+ declare function verifyOAuthDelegateProof(binding: OAuthDelegateBinding, proof: unknown, nowMs?: number, expectedOwner?: string): Promise<boolean>;
1835
+
1836
+ 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, 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 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 };
package/dist/index.js CHANGED
@@ -3747,13 +3747,18 @@ var GUARDED_DELEGATE_ARG_LAYOUT = {
3747
3747
  recipient: null,
3748
3748
  amount: 6,
3749
3749
  paymentIdHash: 7,
3750
- expiresAtMs: 9
3750
+ expiresAtMs: 9,
3751
+ // After clock (10): chain id, refund config, decide window, refund window.
3752
+ decideWindowMs: 13,
3753
+ refundWindowMs: 14
3751
3754
  },
3752
3755
  settle_any_recipient_to_refund_vault: {
3753
3756
  recipient: 4,
3754
3757
  amount: 5,
3755
3758
  paymentIdHash: 6,
3756
- expiresAtMs: 9
3759
+ expiresAtMs: 9,
3760
+ decideWindowMs: 13,
3761
+ refundWindowMs: 14
3757
3762
  }
3758
3763
  };
3759
3764
  function pureBytesOf(data, arg) {
@@ -3833,11 +3838,48 @@ function recoverGuardedDelegateCalls(finalized) {
3833
3838
  paymentIdHash: readPureVectorU8Hex(data, args[layout.paymentIdHash]),
3834
3839
  amount: readPureU64(data, args[layout.amount]),
3835
3840
  recipient: layout.recipient === null ? null : readPureAddress(data, args[layout.recipient]),
3836
- expiresAtMs: readPureU64(data, args[layout.expiresAtMs])
3841
+ expiresAtMs: readPureU64(data, args[layout.expiresAtMs]),
3842
+ ..."decideWindowMs" in layout ? {
3843
+ decideWindowMs: readPureU64(data, args[layout.decideWindowMs]),
3844
+ refundWindowMs: readPureU64(data, args[layout.refundWindowMs])
3845
+ } : {}
3837
3846
  });
3838
3847
  }
3839
3848
  return calls;
3840
3849
  }
3850
+ var VAULT_SETTLEMENT_TS_TIMEOUT_MS = 1e4;
3851
+ function withTimeout(work, ms, label) {
3852
+ return new Promise((resolve, reject2) => {
3853
+ const timer = setTimeout(() => reject2(new Error(`${label} timed out after ${ms}ms`)), ms);
3854
+ Promise.resolve(work).then((value) => {
3855
+ clearTimeout(timer);
3856
+ resolve(value);
3857
+ }, (err) => {
3858
+ clearTimeout(timer);
3859
+ reject2(err);
3860
+ });
3861
+ });
3862
+ }
3863
+ async function readVaultSettlementMs(client, digest) {
3864
+ const ledger = client.ledgerService;
3865
+ if (!ledger?.getTransaction)
3866
+ return void 0;
3867
+ try {
3868
+ const call = await withTimeout(ledger.getTransaction({
3869
+ digest,
3870
+ readMask: { paths: ["timestamp"] }
3871
+ }), VAULT_SETTLEMENT_TS_TIMEOUT_MS, "vault settlement timestamp read");
3872
+ const ts = call.response.transaction?.timestamp;
3873
+ if (!ts || ts.seconds === void 0)
3874
+ return void 0;
3875
+ const seconds = Number(ts.seconds);
3876
+ if (!Number.isFinite(seconds))
3877
+ return void 0;
3878
+ return seconds * 1e3 + Math.floor((ts.nanos ?? 0) / 1e6);
3879
+ } catch {
3880
+ return void 0;
3881
+ }
3882
+ }
3841
3883
  function createSpendAccountSettledTxReader(options) {
3842
3884
  const network = toGrpcNetwork(options.network);
3843
3885
  const client = options.client ?? createFailoverGrpcClient({
@@ -3892,6 +3934,7 @@ function createSpendAccountSettledTxReader(options) {
3892
3934
  kind: e.eventType.split("::").pop() ?? e.eventType
3893
3935
  }));
3894
3936
  const guardedDelegateCalls = recoverGuardedDelegateCalls(finalized);
3937
+ const timestampMs = events.some((event) => event.kind === "VaultOpened") ? await readVaultSettlementMs(client, digest) : void 0;
3895
3938
  return {
3896
3939
  status: "success",
3897
3940
  txDigest: digest,
@@ -3899,7 +3942,8 @@ function createSpendAccountSettledTxReader(options) {
3899
3942
  moveCalls,
3900
3943
  objectIds,
3901
3944
  events,
3902
- guardedDelegateCalls
3945
+ guardedDelegateCalls,
3946
+ ...timestampMs !== void 0 ? { timestampMs } : {}
3903
3947
  };
3904
3948
  }
3905
3949
  };
@@ -10618,8 +10662,44 @@ async function createPayer(options) {
10618
10662
  value: { address, deployment, grant: binding, session, pay, verifySettlement }
10619
10663
  };
10620
10664
  }
10665
+
10666
+ // ../sdk/dist/oauth/delegate-proof.js
10667
+ import { normalizeSuiAddress as normalizeSuiAddress12 } from "@mysten/sui/utils";
10668
+ import { verifyPersonalMessageSignature as verifyPersonalMessageSignature3 } from "@mysten/sui/verify";
10669
+ var OAUTH_DELEGATE_PROOF_TTL_MS = 15 * 6e4;
10670
+ function encodeOAuthDelegateProof(binding, expiresAtMs, ownerAddress) {
10671
+ if (!binding.delegateAddress || !Number.isSafeInteger(expiresAtMs) || expiresAtMs <= 0) {
10672
+ throw new Error("Invalid delegate proof binding.");
10673
+ }
10674
+ return new TextEncoder().encode(JSON.stringify([
10675
+ "suipay:oauth-delegate:v1",
10676
+ binding.clientId,
10677
+ binding.redirectUri,
10678
+ binding.resource,
10679
+ binding.scope,
10680
+ binding.codeChallenge,
10681
+ normalizeSuiAddress12(binding.delegateAddress),
10682
+ normalizeSuiAddress12(ownerAddress),
10683
+ expiresAtMs
10684
+ ]));
10685
+ }
10686
+ async function verifyOAuthDelegateProof(binding, proof, nowMs = Date.now(), expectedOwner) {
10687
+ try {
10688
+ const p = proof;
10689
+ const message = encodeOAuthDelegateProof(binding, p.expiresAtMs, p.ownerAddress);
10690
+ if (typeof p.signature !== "string" || p.signature.length > 8192 || p.expiresAtMs <= nowMs || p.expiresAtMs > nowMs + OAUTH_DELEGATE_PROOF_TTL_MS)
10691
+ return false;
10692
+ if (expectedOwner && normalizeSuiAddress12(p.ownerAddress) !== normalizeSuiAddress12(expectedOwner))
10693
+ return false;
10694
+ const publicKey = await verifyPersonalMessageSignature3(message, p.signature);
10695
+ return publicKey.toSuiAddress() === normalizeSuiAddress12(binding.delegateAddress);
10696
+ } catch {
10697
+ return false;
10698
+ }
10699
+ }
10621
10700
  export {
10622
10701
  NativeTransferError,
10702
+ OAUTH_DELEGATE_PROOF_TTL_MS,
10623
10703
  SuiPayError,
10624
10704
  buildMcpPaymentPayload,
10625
10705
  buildNativeTransferBytes,
@@ -10630,10 +10710,12 @@ export {
10630
10710
  createPayer,
10631
10711
  createReader,
10632
10712
  dashboardManifestToAgentManifest,
10713
+ encodeOAuthDelegateProof,
10633
10714
  inspectNativeTransfer,
10634
10715
  manifestToSession,
10635
10716
  parseAgentManifest,
10636
10717
  personalMessageSigner,
10637
10718
  toErrorFields,
10719
+ verifyOAuthDelegateProof,
10638
10720
  verifyPreparedPayment
10639
10721
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten-incubation/suipay-buyer",
3
- "version": "0.3.0-dev.21",
3
+ "version": "0.3.0-dev.23",
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",