kawasekit 0.7.0 → 0.8.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/dist/index.d.cts CHANGED
@@ -5,7 +5,8 @@ import * as viem from 'viem';
5
5
  import { PublicClient, Transport, Chain, LocalAccount, Address } from 'viem';
6
6
  import { S as SupportedChainId } from './index-2fEOL83n.cjs';
7
7
  export { C as ChainNotSupportedError, g as getChain, i as isSupportedChainId, s as supportedChains } from './index-2fEOL83n.cjs';
8
- export { C as ConfiguredKernelClient, I as IssueSessionKeyParams, K as KAWASEKIT_SESSION_ENVELOPE_VERSION, a as KawasekitSessionEnvelope, b as KawasekitSessionEnvelopeVersion, c as KawasekitSessionPolicySummary, R as RestoreSessionAccountParams, d as RevokeSessionKeyParams, e as RevokeSessionKeyResult, f as RotateSessionKeyParams, g as RotateSessionKeyResult, S as SessionEnvelopeChainMismatchError, h as SessionEnvelopeParseError, i as SessionEnvelopeSignerMismatchError, j as SessionEnvelopeVersionError, T as TransferJpycInputError, k as TransferJpycParams, l as TransferJpycResult, m as issueSessionKey, p as parseSessionEnvelope, r as restoreSessionAccount, n as revokeSessionKey, o as rotateSessionKey, s as serializeSessionEnvelope, t as transferJpyc } from './index-DFChv_fT.cjs';
8
+ import { C as ConfiguredKernelClient } from './index-DFChv_fT.cjs';
9
+ export { I as IssueSessionKeyParams, K as KAWASEKIT_SESSION_ENVELOPE_VERSION, a as KawasekitSessionEnvelope, b as KawasekitSessionEnvelopeVersion, c as KawasekitSessionPolicySummary, R as RestoreSessionAccountParams, d as RevokeSessionKeyParams, e as RevokeSessionKeyResult, f as RotateSessionKeyParams, g as RotateSessionKeyResult, S as SessionEnvelopeChainMismatchError, h as SessionEnvelopeParseError, i as SessionEnvelopeSignerMismatchError, j as SessionEnvelopeVersionError, T as TransferJpycInputError, k as TransferJpycParams, l as TransferJpycResult, m as issueSessionKey, p as parseSessionEnvelope, r as restoreSessionAccount, n as revokeSessionKey, o as rotateSessionKey, s as serializeSessionEnvelope, t as transferJpyc } from './index-DFChv_fT.cjs';
9
10
  import { CallPolicyVersion } from '@zerodev/permissions/policies';
10
11
  export { CreateJpycDailyLimitPoliciesParams, ONE_DAY_SECONDS, createJpycDailyLimitPolicies } from './policy/index.cjs';
11
12
  export { C as CreateSpendingPolicyParams, P as PolicyDecision, S as SpendState, a as SpendingPolicy, b as SpendingPolicyConfigError, T as TokenLimit, c as createSpendingPolicy, e as evaluateSpendingPolicy, m as mergeSpendState } from './spending-policy-CwXcTFD_.cjs';
@@ -553,6 +554,75 @@ declare const polygonAmoy: {
553
554
  verifyHash?: ((client: viem.Client, parameters: viem.VerifyHashActionParameters) => Promise<viem.VerifyHashActionReturnType>) | undefined;
554
555
  };
555
556
 
557
+ /**
558
+ * Build a gas-sponsored Kernel account client — a {@link ConfiguredKernelClient}
559
+ * whose UserOp gas is paid by the ZeroDev paymaster. Pass the returned client
560
+ * straight to {@link transferJpyc}; callers never construct a paymaster client or
561
+ * cast to {@link ConfiguredKernelClient}.
562
+ *
563
+ * @packageDocumentation
564
+ */
565
+
566
+ /**
567
+ * Optional sponsorship observability. Hooks fire through {@link invokeHookSafely},
568
+ * so a throwing hook never breaks sponsorship. The existing `ObservabilityHooks`
569
+ * is x402-facilitator-shaped (verify/settle); this is the paymaster-seam surface.
570
+ */
571
+ interface SponsoredKernelClientObservability {
572
+ /** Fired AFTER the paymaster GRANTS sponsorship for a userOp. */
573
+ readonly onSponsor?: (event: {
574
+ readonly account: Address;
575
+ }) => void;
576
+ /** Fired when the paymaster DECLINES sponsorship (the raw error then propagates). */
577
+ readonly onSponsorError?: (event: {
578
+ readonly account: Address;
579
+ readonly error: unknown;
580
+ }) => void;
581
+ }
582
+ /** Parameters for {@link createSponsoredKernelClient}. */
583
+ interface CreateSponsoredKernelClientParams {
584
+ /** A Kernel v0.7 account from `createAgentSmartAccount` or `restoreSessionAccount`. */
585
+ readonly account: CreateKernelAccountReturnType<"0.7">;
586
+ /** The viem chain the client operates on (e.g. `polygonAmoy`). */
587
+ readonly chain: Chain;
588
+ /**
589
+ * The ZeroDev RPC URL — used for BOTH the bundler and the paymaster (ZeroDev
590
+ * serves both from one project RPC). Build it from a project id with
591
+ * `zerodevRpcUrl(chain, projectId)`, or paste the dashboard URL.
592
+ */
593
+ readonly zerodevRpc: string;
594
+ /** Optional viem `PublicClient` for on-chain reads during userOp prep (recommended). */
595
+ readonly publicClient?: PublicClient<Transport, Chain>;
596
+ /** Optional sponsorship observability — granted / declined. */
597
+ readonly observability?: SponsoredKernelClientObservability;
598
+ }
599
+ /**
600
+ * Build a gas-sponsored Kernel account client. The returned
601
+ * {@link ConfiguredKernelClient} pays UserOp gas via the ZeroDev paymaster and is
602
+ * accepted directly by {@link transferJpyc} — no caller-side cast.
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * import {
607
+ * createSponsoredKernelClient,
608
+ * polygonAmoy,
609
+ * restoreSessionAccount,
610
+ * transferJpyc,
611
+ * zerodevRpcUrl,
612
+ * } from "kawasekit";
613
+ *
614
+ * const account = await restoreSessionAccount({ publicClient, envelope, sessionKeySigner });
615
+ * const client = createSponsoredKernelClient({
616
+ * account,
617
+ * chain: polygonAmoy,
618
+ * zerodevRpc: zerodevRpcUrl(polygonAmoy, projectId),
619
+ * publicClient,
620
+ * });
621
+ * const { transactionHash } = await transferJpyc(client, { to, amount });
622
+ * ```
623
+ */
624
+ declare function createSponsoredKernelClient(params: CreateSponsoredKernelClientParams): ConfiguredKernelClient;
625
+
556
626
  /**
557
627
  * Buy-list → ZeroDev policy bundle for a **disposable, scoped session key**
558
628
  * (the Agent Commerce Hub authorization flow).
@@ -994,4 +1064,4 @@ declare const jpycAbi: readonly [{
994
1064
  }];
995
1065
  }];
996
1066
 
997
- export { type CreateAgentSmartAccountParams, type CreateBuyListPoliciesParams, JPYC_DECIMALS, JPYC_EIP712_DOMAIN_HINT, JPYC_V2_ADDRESS, type JpycDeployment, JpycNotAvailableError, SupportedChainId, avalanche, avalancheFuji, createAgentSmartAccount, createBuyListPolicies, ethereum, getJpycAddress, jpycAbi, jpycDeployments, kaia, kairos, polygon, polygonAmoy, sepolia };
1067
+ export { ConfiguredKernelClient, type CreateAgentSmartAccountParams, type CreateBuyListPoliciesParams, type CreateSponsoredKernelClientParams, JPYC_DECIMALS, JPYC_EIP712_DOMAIN_HINT, JPYC_V2_ADDRESS, type JpycDeployment, JpycNotAvailableError, type SponsoredKernelClientObservability, SupportedChainId, avalanche, avalancheFuji, createAgentSmartAccount, createBuyListPolicies, createSponsoredKernelClient, ethereum, getJpycAddress, jpycAbi, jpycDeployments, kaia, kairos, polygon, polygonAmoy, sepolia };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@ import * as viem from 'viem';
5
5
  import { PublicClient, Transport, Chain, LocalAccount, Address } from 'viem';
6
6
  import { S as SupportedChainId } from './index-2fEOL83n.js';
7
7
  export { C as ChainNotSupportedError, g as getChain, i as isSupportedChainId, s as supportedChains } from './index-2fEOL83n.js';
8
- export { C as ConfiguredKernelClient, I as IssueSessionKeyParams, K as KAWASEKIT_SESSION_ENVELOPE_VERSION, a as KawasekitSessionEnvelope, b as KawasekitSessionEnvelopeVersion, c as KawasekitSessionPolicySummary, R as RestoreSessionAccountParams, d as RevokeSessionKeyParams, e as RevokeSessionKeyResult, f as RotateSessionKeyParams, g as RotateSessionKeyResult, S as SessionEnvelopeChainMismatchError, h as SessionEnvelopeParseError, i as SessionEnvelopeSignerMismatchError, j as SessionEnvelopeVersionError, T as TransferJpycInputError, k as TransferJpycParams, l as TransferJpycResult, m as issueSessionKey, p as parseSessionEnvelope, r as restoreSessionAccount, n as revokeSessionKey, o as rotateSessionKey, s as serializeSessionEnvelope, t as transferJpyc } from './index-CSpNGigO.js';
8
+ import { C as ConfiguredKernelClient } from './index-CSpNGigO.js';
9
+ export { I as IssueSessionKeyParams, K as KAWASEKIT_SESSION_ENVELOPE_VERSION, a as KawasekitSessionEnvelope, b as KawasekitSessionEnvelopeVersion, c as KawasekitSessionPolicySummary, R as RestoreSessionAccountParams, d as RevokeSessionKeyParams, e as RevokeSessionKeyResult, f as RotateSessionKeyParams, g as RotateSessionKeyResult, S as SessionEnvelopeChainMismatchError, h as SessionEnvelopeParseError, i as SessionEnvelopeSignerMismatchError, j as SessionEnvelopeVersionError, T as TransferJpycInputError, k as TransferJpycParams, l as TransferJpycResult, m as issueSessionKey, p as parseSessionEnvelope, r as restoreSessionAccount, n as revokeSessionKey, o as rotateSessionKey, s as serializeSessionEnvelope, t as transferJpyc } from './index-CSpNGigO.js';
9
10
  import { CallPolicyVersion } from '@zerodev/permissions/policies';
10
11
  export { CreateJpycDailyLimitPoliciesParams, ONE_DAY_SECONDS, createJpycDailyLimitPolicies } from './policy/index.js';
11
12
  export { C as CreateSpendingPolicyParams, P as PolicyDecision, S as SpendState, a as SpendingPolicy, b as SpendingPolicyConfigError, T as TokenLimit, c as createSpendingPolicy, e as evaluateSpendingPolicy, m as mergeSpendState } from './spending-policy-BBgXDrVD.js';
@@ -553,6 +554,75 @@ declare const polygonAmoy: {
553
554
  verifyHash?: ((client: viem.Client, parameters: viem.VerifyHashActionParameters) => Promise<viem.VerifyHashActionReturnType>) | undefined;
554
555
  };
555
556
 
557
+ /**
558
+ * Build a gas-sponsored Kernel account client — a {@link ConfiguredKernelClient}
559
+ * whose UserOp gas is paid by the ZeroDev paymaster. Pass the returned client
560
+ * straight to {@link transferJpyc}; callers never construct a paymaster client or
561
+ * cast to {@link ConfiguredKernelClient}.
562
+ *
563
+ * @packageDocumentation
564
+ */
565
+
566
+ /**
567
+ * Optional sponsorship observability. Hooks fire through {@link invokeHookSafely},
568
+ * so a throwing hook never breaks sponsorship. The existing `ObservabilityHooks`
569
+ * is x402-facilitator-shaped (verify/settle); this is the paymaster-seam surface.
570
+ */
571
+ interface SponsoredKernelClientObservability {
572
+ /** Fired AFTER the paymaster GRANTS sponsorship for a userOp. */
573
+ readonly onSponsor?: (event: {
574
+ readonly account: Address;
575
+ }) => void;
576
+ /** Fired when the paymaster DECLINES sponsorship (the raw error then propagates). */
577
+ readonly onSponsorError?: (event: {
578
+ readonly account: Address;
579
+ readonly error: unknown;
580
+ }) => void;
581
+ }
582
+ /** Parameters for {@link createSponsoredKernelClient}. */
583
+ interface CreateSponsoredKernelClientParams {
584
+ /** A Kernel v0.7 account from `createAgentSmartAccount` or `restoreSessionAccount`. */
585
+ readonly account: CreateKernelAccountReturnType<"0.7">;
586
+ /** The viem chain the client operates on (e.g. `polygonAmoy`). */
587
+ readonly chain: Chain;
588
+ /**
589
+ * The ZeroDev RPC URL — used for BOTH the bundler and the paymaster (ZeroDev
590
+ * serves both from one project RPC). Build it from a project id with
591
+ * `zerodevRpcUrl(chain, projectId)`, or paste the dashboard URL.
592
+ */
593
+ readonly zerodevRpc: string;
594
+ /** Optional viem `PublicClient` for on-chain reads during userOp prep (recommended). */
595
+ readonly publicClient?: PublicClient<Transport, Chain>;
596
+ /** Optional sponsorship observability — granted / declined. */
597
+ readonly observability?: SponsoredKernelClientObservability;
598
+ }
599
+ /**
600
+ * Build a gas-sponsored Kernel account client. The returned
601
+ * {@link ConfiguredKernelClient} pays UserOp gas via the ZeroDev paymaster and is
602
+ * accepted directly by {@link transferJpyc} — no caller-side cast.
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * import {
607
+ * createSponsoredKernelClient,
608
+ * polygonAmoy,
609
+ * restoreSessionAccount,
610
+ * transferJpyc,
611
+ * zerodevRpcUrl,
612
+ * } from "kawasekit";
613
+ *
614
+ * const account = await restoreSessionAccount({ publicClient, envelope, sessionKeySigner });
615
+ * const client = createSponsoredKernelClient({
616
+ * account,
617
+ * chain: polygonAmoy,
618
+ * zerodevRpc: zerodevRpcUrl(polygonAmoy, projectId),
619
+ * publicClient,
620
+ * });
621
+ * const { transactionHash } = await transferJpyc(client, { to, amount });
622
+ * ```
623
+ */
624
+ declare function createSponsoredKernelClient(params: CreateSponsoredKernelClientParams): ConfiguredKernelClient;
625
+
556
626
  /**
557
627
  * Buy-list → ZeroDev policy bundle for a **disposable, scoped session key**
558
628
  * (the Agent Commerce Hub authorization flow).
@@ -994,4 +1064,4 @@ declare const jpycAbi: readonly [{
994
1064
  }];
995
1065
  }];
996
1066
 
997
- export { type CreateAgentSmartAccountParams, type CreateBuyListPoliciesParams, JPYC_DECIMALS, JPYC_EIP712_DOMAIN_HINT, JPYC_V2_ADDRESS, type JpycDeployment, JpycNotAvailableError, SupportedChainId, avalanche, avalancheFuji, createAgentSmartAccount, createBuyListPolicies, ethereum, getJpycAddress, jpycAbi, jpycDeployments, kaia, kairos, polygon, polygonAmoy, sepolia };
1067
+ export { ConfiguredKernelClient, type CreateAgentSmartAccountParams, type CreateBuyListPoliciesParams, type CreateSponsoredKernelClientParams, JPYC_DECIMALS, JPYC_EIP712_DOMAIN_HINT, JPYC_V2_ADDRESS, type JpycDeployment, JpycNotAvailableError, type SponsoredKernelClientObservability, SupportedChainId, avalanche, avalancheFuji, createAgentSmartAccount, createBuyListPolicies, createSponsoredKernelClient, ethereum, getJpycAddress, jpycAbi, jpycDeployments, kaia, kairos, polygon, polygonAmoy, sepolia };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { TransferJpycInputError, createBuyListPolicies, transferJpyc } from './chunk-Y2LOACWO.js';
1
+ export { TransferJpycInputError, createBuyListPolicies, createSponsoredKernelClient, transferJpyc } from './chunk-DMP7YFGA.js';
2
2
  export { X402_DEFAULT_AUTHORIZATION_LIFETIME_SECONDS, X402_FACILITATOR_ERROR_CODES, createCoinbaseFacilitator, createHttpFacilitator, createSelfFacilitator, createX402PaymentSigner, deriveReceiptTimeoutMs, wrapFetch } from './chunk-P5563RGP.js';
3
3
  export { X402_DEFAULT_MAX_TIMEOUT_SECONDS, X402_HEADER_IDEMPOTENCY_KEY, X402_HEADER_PAYMENT_REQUIRED, X402_HEADER_PAYMENT_RESPONSE, X402_HEADER_PAYMENT_SIGNATURE, buildPaymentRequiredResponse, buildPaymentRequirements, createX402Handler, decodePaymentRequiredHeader, decodePaymentResponseHeader, decodePaymentSignatureHeader, encodePaymentRequiredHeader, encodePaymentResponseHeader, encodePaymentSignatureHeader } from './chunk-PVUKX6IF.js';
4
4
  export { extractAcceptedNetworks, invokeHookSafely } from './chunk-LEHWRDVS.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kawasekit",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "TypeScript SDK for stablecoin payments by AI agents. Japan-first, JPYC-native.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "k0yote",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/client/transfer-jpyc.ts","../src/policy/buy-list.ts"],"names":[],"mappings":";;;;;;AA6DO,IAAM,sBAAA,GAAN,cAAqC,KAAA,CAAM;AAAA,EACjD,YAAY,OAAA,EAAiB;AAC5B,IAAA,KAAA,CAAM,CAAA,cAAA,EAAiB,OAAO,CAAA,CAAE,CAAA;AAChC,IAAA,IAAA,CAAK,IAAA,GAAO,wBAAA;AAAA,EACb;AACD;AAgBA,eAAsB,YAAA,CACrB,cACA,MAAA,EAC8B;AAC9B,EAAA,IAAI,CAAC,UAAU,MAAA,CAAO,EAAA,EAAI,EAAE,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAG;AAC7C,IAAA,MAAM,IAAI,sBAAA,CAAuB,CAAA,+BAAA,EAAkC,MAAA,CAAO,EAAE,CAAA,CAAE,CAAA;AAAA,EAC/E;AACA,EAAA,IAAI,MAAA,CAAO,UAAU,EAAA,EAAI;AACxB,IAAA,MAAM,IAAI,sBAAA,CAAuB,CAAA,iCAAA,EAAoC,MAAA,CAAO,MAAM,CAAA,CAAA,CAAG,CAAA;AAAA,EACtF;AAEA,EAAA,MAAM,OAAA,GAAU,aAAa,KAAA,CAAM,EAAA;AACnC,EAAA,IAAI,CAAC,kBAAA,CAAmB,OAAO,CAAA,EAAG;AACjC,IAAA,MAAM,IAAI,sBAAA,CAAuB,CAAA,SAAA,EAAY,OAAO,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OAAO,CAAC,UAAA,EAAY,eAAA,EAAiB,eAAe,CAAA;AACrD","file":"chunk-Y2LOACWO.js","sourcesContent":["/**\n * High-level helper: transfer JPYC from a Kernel smart account via a sponsored\n * UserOp.\n *\n * This is the canonical \"agent payment\" path for M2. The flow:\n * 1. Resolve the JPYC contract address for `kernelClient.chain`.\n * 2. Encode `JPYC.transfer(to, amount)` calldata.\n * 3. Wrap it as a Kernel call and submit via `sendUserOperation`.\n * 4. Wait for the bundler receipt and return both hashes.\n *\n * EIP-3009 `transferWithAuthorization` cannot be used here: JPYC's signature\n * verification is pure `ecrecover`, so a smart account cannot be `from`. See\n * `src/tokens/eip3009.ts` for the EOA-payer path.\n *\n * @packageDocumentation\n */\n\nimport type { KernelAccountClient } from \"@zerodev/sdk\";\nimport type { Address, Chain, Hex, Transport } from \"viem\";\nimport { encodeFunctionData, isAddress } from \"viem\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { isSupportedChainId, type SupportedChainId } from \"../chains\";\nimport { getJpycAddress, jpycAbi } from \"../tokens/jpyc\";\n\n/** A {@link KernelAccountClient} that is fully configured (chain + account). */\nexport type ConfiguredKernelClient = KernelAccountClient<Transport, Chain, SmartAccount>;\n\n/** Parameters for {@link transferJpyc}. */\nexport interface TransferJpycParams {\n\t/** Recipient address. */\n\treadonly to: Address;\n\t/**\n\t * Raw token amount in the token's smallest unit (JPYC has 18 decimals).\n\t *\n\t * @example\n\t * ```ts\n\t * import { parseUnits } from \"viem\";\n\t * import { JPYC_DECIMALS } from \"kawasekit\";\n\t *\n\t * parseUnits(\"100\", JPYC_DECIMALS); // 100 JPYC\n\t * ```\n\t */\n\treadonly amount: bigint;\n\t/**\n\t * Optional. Defaults to waiting for the bundler receipt before returning.\n\t * Set to `false` to return after the UserOp is submitted but before it\n\t * lands on chain — useful when the caller wants to do its own polling.\n\t */\n\treadonly waitForReceipt?: boolean;\n}\n\n/** Result of a {@link transferJpyc} call. */\nexport interface TransferJpycResult {\n\treadonly userOpHash: Hex;\n\t/** `null` when `waitForReceipt: false` was requested. */\n\treadonly transactionHash: Hex | null;\n\t/** `true` if the bundler receipt reported success; `null` if not awaited. */\n\treadonly success: boolean | null;\n}\n\n/** Thrown when {@link transferJpyc} is called with invalid arguments. */\nexport class TransferJpycInputError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(`transferJpyc: ${message}`);\n\t\tthis.name = \"TransferJpycInputError\";\n\t}\n}\n\n/**\n * Transfer JPYC from the Kernel smart account to `to` via a sponsored UserOp.\n *\n * @example\n * ```ts\n * import { parseUnits } from \"viem\";\n * import { JPYC_DECIMALS, transferJpyc } from \"kawasekit\";\n *\n * const { userOpHash, transactionHash } = await transferJpyc(kernelClient, {\n * to: \"0xBeef0000000000000000000000000000DEADBEEF\",\n * amount: parseUnits(\"100\", JPYC_DECIMALS),\n * });\n * ```\n */\nexport async function transferJpyc(\n\tkernelClient: ConfiguredKernelClient,\n\tparams: TransferJpycParams,\n): Promise<TransferJpycResult> {\n\tif (!isAddress(params.to, { strict: false })) {\n\t\tthrow new TransferJpycInputError(`\\`to\\` is not a valid address: ${params.to}`);\n\t}\n\tif (params.amount <= 0n) {\n\t\tthrow new TransferJpycInputError(`\\`amount\\` must be positive, got ${params.amount}.`);\n\t}\n\n\tconst chainId = kernelClient.chain.id;\n\tif (!isSupportedChainId(chainId)) {\n\t\tthrow new TransferJpycInputError(`Chain ID ${chainId} is not a kawasekit-supported chain.`);\n\t}\n\tconst jpycAddress = getJpycAddress(chainId satisfies SupportedChainId);\n\n\tconst data = encodeFunctionData({\n\t\tabi: jpycAbi,\n\t\tfunctionName: \"transfer\",\n\t\targs: [params.to, params.amount],\n\t});\n\n\tconst callData = await kernelClient.account.encodeCalls([{ to: jpycAddress, value: 0n, data }]);\n\n\tconst userOpHash = await kernelClient.sendUserOperation({ callData });\n\n\tif (params.waitForReceipt === false) {\n\t\treturn { userOpHash, transactionHash: null, success: null };\n\t}\n\n\tconst receipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });\n\treturn {\n\t\tuserOpHash,\n\t\ttransactionHash: receipt.receipt.transactionHash,\n\t\tsuccess: receipt.success,\n\t};\n}\n","/**\n * Buy-list → ZeroDev policy bundle for a **disposable, scoped session key**\n * (the Agent Commerce Hub authorization flow).\n *\n * A user's resolved buy-list (its merchants + a per-transfer cap + a total\n * transfer count + a schedule window) is baked into a single-use session key by\n * composing three on-chain policies:\n * 1. **callPolicy** — `JPYC.transfer(to, value)` with `value ≤ maxPerTransfer`\n * and `to ∈ merchants` (the allowlist; shared with\n * {@link createJpycDailyLimitPolicies} via {@link buildJpycTransferCallPolicy}).\n * 2. **rateLimitPolicy** — a **total** cap of `maxTransfers` over the whole\n * schedule window (the rate window is set to span `[validAfter, validUntil]`,\n * so `count` does NOT reset within the session — it is a session total, not a\n * per-day limit).\n * 3. **timestampPolicy** — the session key is only valid within\n * `[validAfter, validUntil]`.\n *\n * Cumulative budget (\"spend ≤ ¥X total\") is NOT a policy field — it is the\n * amount the user funds the account with (funding is the user's responsibility,\n * out of the SDK's scope). These policies bound *who* (allowlist), *how much per\n * transfer* (cap), *how many* (count), and *when* (window).\n *\n * @packageDocumentation\n */\n\nimport type { Policy } from \"@zerodev/permissions\";\nimport {\n\ttype CallPolicyVersion,\n\ttoRateLimitPolicy,\n\ttoTimestampPolicy,\n} from \"@zerodev/permissions/policies\";\nimport type { Address } from \"viem\";\nimport { buildJpycTransferCallPolicy } from \"./jpyc-call-policy\";\n\n/** Parameters for {@link createBuyListPolicies}. */\nexport interface CreateBuyListPoliciesParams {\n\t/** JPYC contract address on the target chain. */\n\treadonly jpycAddress: Address;\n\t/**\n\t * The buy-list's resolved merchant recipient addresses — the allowlist the\n\t * session key may pay. **Required and non-empty** (a buy-list always targets\n\t * specific merchants); checksum-normalized + de-duplicated.\n\t */\n\treadonly merchants: readonly Address[];\n\t/** Maximum JPYC (raw units) per single transfer. Must be positive. */\n\treadonly maxPerTransfer: bigint;\n\t/**\n\t * Maximum number of transfers over the WHOLE window — a session total, not a\n\t * per-day limit. Must be a positive integer.\n\t */\n\treadonly maxTransfers: number;\n\t/** Schedule-window end (unix seconds); the key is invalid after this. Must be a positive integer. */\n\treadonly validUntil: number;\n\t/**\n\t * Optional schedule-window start (unix seconds); the key is invalid before\n\t * this. Defaults to 0 (valid immediately). Must be `< validUntil`.\n\t */\n\treadonly validAfter?: number;\n\t/** ZeroDev callPolicy on-chain version. Defaults to V0_0_4. */\n\treadonly callPolicyVersion?: CallPolicyVersion;\n}\n\n/**\n * Build the ZeroDev policy bundle for a buy-list-scoped, single-use session key.\n *\n * Plug the returned policies into `toPermissionValidator({ policies, … })` and\n * issue the session key via {@link issueSessionKey}.\n *\n * @example\n * ```ts\n * import { parseUnits } from \"viem\";\n * import { createBuyListPolicies, getJpycAddress, JPYC_DECIMALS, polygonAmoy } from \"kawasekit\";\n *\n * const policies = createBuyListPolicies({\n * jpycAddress: getJpycAddress(polygonAmoy.id),\n * merchants: [merchantA, merchantB], // pay ONLY these (allowlist)\n * maxPerTransfer: parseUnits(\"500\", JPYC_DECIMALS),\n * maxTransfers: 3, // at most 3 transfers, total\n * validUntil: Math.floor(Date.now() / 1000) + 3 * 86_400, // valid 3 days\n * });\n * // user funds the account with their budget; the policies bound who/how-much/how-many/when.\n * ```\n */\nexport function createBuyListPolicies(\n\tparams: CreateBuyListPoliciesParams,\n): readonly [Policy, Policy, Policy] {\n\tif (params.merchants.length === 0) {\n\t\tthrow new Error(\n\t\t\t\"createBuyListPolicies: merchants must not be empty — a buy-list must target at least one merchant.\",\n\t\t);\n\t}\n\tif (!Number.isInteger(params.maxTransfers) || params.maxTransfers < 1) {\n\t\tthrow new Error(\n\t\t\t`createBuyListPolicies: maxTransfers must be a positive integer, got ${params.maxTransfers}.`,\n\t\t);\n\t}\n\tif (!Number.isInteger(params.validUntil) || params.validUntil <= 0) {\n\t\tthrow new Error(\n\t\t\t`createBuyListPolicies: validUntil must be a positive unix-seconds integer, got ${params.validUntil}.`,\n\t\t);\n\t}\n\tconst validAfter = params.validAfter ?? 0;\n\tif (!Number.isInteger(validAfter) || validAfter < 0) {\n\t\tthrow new Error(\n\t\t\t`createBuyListPolicies: validAfter must be a non-negative unix-seconds integer, got ${params.validAfter}.`,\n\t\t);\n\t}\n\tif (validAfter >= params.validUntil) {\n\t\tthrow new Error(\n\t\t\t`createBuyListPolicies: validAfter (${validAfter}) must be before validUntil (${params.validUntil}).`,\n\t\t);\n\t}\n\n\t// callPolicy: amount cap + merchant allowlist (shared with daily-limit).\n\tconst callPolicy = buildJpycTransferCallPolicy({\n\t\tjpycAddress: params.jpycAddress,\n\t\tmaxPerTransfer: params.maxPerTransfer,\n\t\trecipientAllowlist: params.merchants,\n\t\tcallPolicyVersion: params.callPolicyVersion,\n\t});\n\n\t// rateLimitPolicy: a TOTAL cap of maxTransfers over the window. Setting the\n\t// rate window to span exactly [validAfter, validUntil] (interval = the window\n\t// length, startAt = validAfter) keeps the whole session in one rate bucket, so\n\t// `count` is a session total — NOT a per-day limit that could reset and let\n\t// more than maxTransfers through over a multi-day window.\n\tconst rateLimitPolicy = toRateLimitPolicy({\n\t\tinterval: params.validUntil - validAfter,\n\t\tcount: params.maxTransfers,\n\t\tstartAt: validAfter,\n\t});\n\n\t// timestampPolicy: the key is only valid within the schedule window. Omit\n\t// validAfter when not given (exactOptionalPropertyTypes: don't pass undefined).\n\tconst timestampPolicy = toTimestampPolicy(\n\t\tparams.validAfter === undefined\n\t\t\t? { validUntil: params.validUntil }\n\t\t\t: { validAfter: params.validAfter, validUntil: params.validUntil },\n\t);\n\n\treturn [callPolicy, rateLimitPolicy, timestampPolicy] as const;\n}\n"]}