kawasekit 0.6.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/chunk-DMP7YFGA.js +121 -0
- package/dist/chunk-DMP7YFGA.js.map +1 -0
- package/dist/{chunk-X54U6GU4.js → chunk-UIDDRHLW.js} +24 -16
- package/dist/chunk-UIDDRHLW.js.map +1 -0
- package/dist/cli/index.cjs +21 -15
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +3 -3
- package/dist/index.cjs +116 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +148 -3
- package/dist/index.d.ts +148 -3
- package/dist/index.js +2 -2
- package/dist/policy/index.cjs +22 -14
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-RJLDKDWL.js +0 -43
- package/dist/chunk-RJLDKDWL.js.map +0 -1
- package/dist/chunk-X54U6GU4.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,9 @@ 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
|
-
|
|
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';
|
|
10
|
+
import { CallPolicyVersion } from '@zerodev/permissions/policies';
|
|
9
11
|
export { CreateJpycDailyLimitPoliciesParams, ONE_DAY_SECONDS, createJpycDailyLimitPolicies } from './policy/index.cjs';
|
|
10
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';
|
|
11
13
|
export { CoSignConnection, CoSignFrame, CoSignRequestAuthenticator, CoSignRequestEnvelope, CoSignTransport, CoSignUnavailableError, CreateLocalPolicyGatedSignerParams, Mpc2pCoSignAgent, Mpc2pSignerParams, Mpc2pStepOutcome, PolicyGatedSignerConfigError, WIRE_VERSION, WireIntent, assertNonBypassable, canonicalRequestBytes, createLocalPolicyGatedSigner, createMpc2pPolicyGatedSigner, requireNonBypassable, toWireIntent } from './signer/index.cjs';
|
|
@@ -18,7 +20,6 @@ export { ClientPaymentEvent, HookCallback, ObservabilityEvent, ObservabilityEven
|
|
|
18
20
|
export { CanonicalRequestIdentity, CreateIdempotencyKeyBuilderParams, IdempotencyConfigError, IdempotencyKeyBuilder, IdempotencyRecordParseError, IdempotencyRecordVersionError, createIdempotencyKeyBuilder, deriveIdempotencyKey, normalizeIntentText } from './idempotency/index.cjs';
|
|
19
21
|
export { C as CreateInMemoryIdempotencyStoreParams, I as IdempotencyLease, a as IdempotencyLookupResult, b as IdempotencyRecord, c as IdempotencyResponseSnapshot, d as IdempotencyStore, K as KAWASEKIT_IDEMPOTENCY_RECORD_VERSION, e as KawasekitIdempotencyRecordVersion, f as createInMemoryIdempotencyStore, p as parseIdempotencyRecord, s as serializeIdempotencyRecord } from './store-DPOLS6yp.cjs';
|
|
20
22
|
import 'viem/account-abstraction';
|
|
21
|
-
import '@zerodev/permissions/policies';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Agent smart account = Kernel v3.1 + ECDSA sudo validator + session-key
|
|
@@ -553,6 +554,150 @@ 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
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Buy-list → ZeroDev policy bundle for a **disposable, scoped session key**
|
|
628
|
+
* (the Agent Commerce Hub authorization flow).
|
|
629
|
+
*
|
|
630
|
+
* A user's resolved buy-list (its merchants + a per-transfer cap + a total
|
|
631
|
+
* transfer count + a schedule window) is baked into a single-use session key by
|
|
632
|
+
* composing three on-chain policies:
|
|
633
|
+
* 1. **callPolicy** — `JPYC.transfer(to, value)` with `value ≤ maxPerTransfer`
|
|
634
|
+
* and `to ∈ merchants` (the allowlist; shared with
|
|
635
|
+
* {@link createJpycDailyLimitPolicies} via {@link buildJpycTransferCallPolicy}).
|
|
636
|
+
* 2. **rateLimitPolicy** — a **total** cap of `maxTransfers` over the whole
|
|
637
|
+
* schedule window (the rate window is set to span `[validAfter, validUntil]`,
|
|
638
|
+
* so `count` does NOT reset within the session — it is a session total, not a
|
|
639
|
+
* per-day limit).
|
|
640
|
+
* 3. **timestampPolicy** — the session key is only valid within
|
|
641
|
+
* `[validAfter, validUntil]`.
|
|
642
|
+
*
|
|
643
|
+
* Cumulative budget ("spend ≤ ¥X total") is NOT a policy field — it is the
|
|
644
|
+
* amount the user funds the account with (funding is the user's responsibility,
|
|
645
|
+
* out of the SDK's scope). These policies bound *who* (allowlist), *how much per
|
|
646
|
+
* transfer* (cap), *how many* (count), and *when* (window).
|
|
647
|
+
*
|
|
648
|
+
* @packageDocumentation
|
|
649
|
+
*/
|
|
650
|
+
|
|
651
|
+
/** Parameters for {@link createBuyListPolicies}. */
|
|
652
|
+
interface CreateBuyListPoliciesParams {
|
|
653
|
+
/** JPYC contract address on the target chain. */
|
|
654
|
+
readonly jpycAddress: Address;
|
|
655
|
+
/**
|
|
656
|
+
* The buy-list's resolved merchant recipient addresses — the allowlist the
|
|
657
|
+
* session key may pay. **Required and non-empty** (a buy-list always targets
|
|
658
|
+
* specific merchants); checksum-normalized + de-duplicated.
|
|
659
|
+
*/
|
|
660
|
+
readonly merchants: readonly Address[];
|
|
661
|
+
/** Maximum JPYC (raw units) per single transfer. Must be positive. */
|
|
662
|
+
readonly maxPerTransfer: bigint;
|
|
663
|
+
/**
|
|
664
|
+
* Maximum number of transfers over the WHOLE window — a session total, not a
|
|
665
|
+
* per-day limit. Must be a positive integer.
|
|
666
|
+
*/
|
|
667
|
+
readonly maxTransfers: number;
|
|
668
|
+
/** Schedule-window end (unix seconds); the key is invalid after this. Must be a positive integer. */
|
|
669
|
+
readonly validUntil: number;
|
|
670
|
+
/**
|
|
671
|
+
* Optional schedule-window start (unix seconds); the key is invalid before
|
|
672
|
+
* this. Defaults to 0 (valid immediately). Must be `< validUntil`.
|
|
673
|
+
*/
|
|
674
|
+
readonly validAfter?: number;
|
|
675
|
+
/** ZeroDev callPolicy on-chain version. Defaults to V0_0_4. */
|
|
676
|
+
readonly callPolicyVersion?: CallPolicyVersion;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Build the ZeroDev policy bundle for a buy-list-scoped, single-use session key.
|
|
680
|
+
*
|
|
681
|
+
* Plug the returned policies into `toPermissionValidator({ policies, … })` and
|
|
682
|
+
* issue the session key via {@link issueSessionKey}.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* import { parseUnits } from "viem";
|
|
687
|
+
* import { createBuyListPolicies, getJpycAddress, JPYC_DECIMALS, polygonAmoy } from "kawasekit";
|
|
688
|
+
*
|
|
689
|
+
* const policies = createBuyListPolicies({
|
|
690
|
+
* jpycAddress: getJpycAddress(polygonAmoy.id),
|
|
691
|
+
* merchants: [merchantA, merchantB], // pay ONLY these (allowlist)
|
|
692
|
+
* maxPerTransfer: parseUnits("500", JPYC_DECIMALS),
|
|
693
|
+
* maxTransfers: 3, // at most 3 transfers, total
|
|
694
|
+
* validUntil: Math.floor(Date.now() / 1000) + 3 * 86_400, // valid 3 days
|
|
695
|
+
* });
|
|
696
|
+
* // user funds the account with their budget; the policies bound who/how-much/how-many/when.
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
declare function createBuyListPolicies(params: CreateBuyListPoliciesParams): readonly [Policy, Policy, Policy];
|
|
700
|
+
|
|
556
701
|
/**
|
|
557
702
|
* JPYC stablecoin metadata, deployments, and ABI.
|
|
558
703
|
*
|
|
@@ -919,4 +1064,4 @@ declare const jpycAbi: readonly [{
|
|
|
919
1064
|
}];
|
|
920
1065
|
}];
|
|
921
1066
|
|
|
922
|
-
export { type CreateAgentSmartAccountParams, JPYC_DECIMALS, JPYC_EIP712_DOMAIN_HINT, JPYC_V2_ADDRESS, type JpycDeployment, JpycNotAvailableError, SupportedChainId, avalanche, avalancheFuji, createAgentSmartAccount, 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,9 @@ 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
|
-
|
|
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';
|
|
10
|
+
import { CallPolicyVersion } from '@zerodev/permissions/policies';
|
|
9
11
|
export { CreateJpycDailyLimitPoliciesParams, ONE_DAY_SECONDS, createJpycDailyLimitPolicies } from './policy/index.js';
|
|
10
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';
|
|
11
13
|
export { CoSignConnection, CoSignFrame, CoSignRequestAuthenticator, CoSignRequestEnvelope, CoSignTransport, CoSignUnavailableError, CreateLocalPolicyGatedSignerParams, Mpc2pCoSignAgent, Mpc2pSignerParams, Mpc2pStepOutcome, PolicyGatedSignerConfigError, WIRE_VERSION, WireIntent, assertNonBypassable, canonicalRequestBytes, createLocalPolicyGatedSigner, createMpc2pPolicyGatedSigner, requireNonBypassable, toWireIntent } from './signer/index.js';
|
|
@@ -18,7 +20,6 @@ export { ClientPaymentEvent, HookCallback, ObservabilityEvent, ObservabilityEven
|
|
|
18
20
|
export { CanonicalRequestIdentity, CreateIdempotencyKeyBuilderParams, IdempotencyConfigError, IdempotencyKeyBuilder, IdempotencyRecordParseError, IdempotencyRecordVersionError, createIdempotencyKeyBuilder, deriveIdempotencyKey, normalizeIntentText } from './idempotency/index.js';
|
|
19
21
|
export { C as CreateInMemoryIdempotencyStoreParams, I as IdempotencyLease, a as IdempotencyLookupResult, b as IdempotencyRecord, c as IdempotencyResponseSnapshot, d as IdempotencyStore, K as KAWASEKIT_IDEMPOTENCY_RECORD_VERSION, e as KawasekitIdempotencyRecordVersion, f as createInMemoryIdempotencyStore, p as parseIdempotencyRecord, s as serializeIdempotencyRecord } from './store-DmdoV3Ii.js';
|
|
20
22
|
import 'viem/account-abstraction';
|
|
21
|
-
import '@zerodev/permissions/policies';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Agent smart account = Kernel v3.1 + ECDSA sudo validator + session-key
|
|
@@ -553,6 +554,150 @@ 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
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Buy-list → ZeroDev policy bundle for a **disposable, scoped session key**
|
|
628
|
+
* (the Agent Commerce Hub authorization flow).
|
|
629
|
+
*
|
|
630
|
+
* A user's resolved buy-list (its merchants + a per-transfer cap + a total
|
|
631
|
+
* transfer count + a schedule window) is baked into a single-use session key by
|
|
632
|
+
* composing three on-chain policies:
|
|
633
|
+
* 1. **callPolicy** — `JPYC.transfer(to, value)` with `value ≤ maxPerTransfer`
|
|
634
|
+
* and `to ∈ merchants` (the allowlist; shared with
|
|
635
|
+
* {@link createJpycDailyLimitPolicies} via {@link buildJpycTransferCallPolicy}).
|
|
636
|
+
* 2. **rateLimitPolicy** — a **total** cap of `maxTransfers` over the whole
|
|
637
|
+
* schedule window (the rate window is set to span `[validAfter, validUntil]`,
|
|
638
|
+
* so `count` does NOT reset within the session — it is a session total, not a
|
|
639
|
+
* per-day limit).
|
|
640
|
+
* 3. **timestampPolicy** — the session key is only valid within
|
|
641
|
+
* `[validAfter, validUntil]`.
|
|
642
|
+
*
|
|
643
|
+
* Cumulative budget ("spend ≤ ¥X total") is NOT a policy field — it is the
|
|
644
|
+
* amount the user funds the account with (funding is the user's responsibility,
|
|
645
|
+
* out of the SDK's scope). These policies bound *who* (allowlist), *how much per
|
|
646
|
+
* transfer* (cap), *how many* (count), and *when* (window).
|
|
647
|
+
*
|
|
648
|
+
* @packageDocumentation
|
|
649
|
+
*/
|
|
650
|
+
|
|
651
|
+
/** Parameters for {@link createBuyListPolicies}. */
|
|
652
|
+
interface CreateBuyListPoliciesParams {
|
|
653
|
+
/** JPYC contract address on the target chain. */
|
|
654
|
+
readonly jpycAddress: Address;
|
|
655
|
+
/**
|
|
656
|
+
* The buy-list's resolved merchant recipient addresses — the allowlist the
|
|
657
|
+
* session key may pay. **Required and non-empty** (a buy-list always targets
|
|
658
|
+
* specific merchants); checksum-normalized + de-duplicated.
|
|
659
|
+
*/
|
|
660
|
+
readonly merchants: readonly Address[];
|
|
661
|
+
/** Maximum JPYC (raw units) per single transfer. Must be positive. */
|
|
662
|
+
readonly maxPerTransfer: bigint;
|
|
663
|
+
/**
|
|
664
|
+
* Maximum number of transfers over the WHOLE window — a session total, not a
|
|
665
|
+
* per-day limit. Must be a positive integer.
|
|
666
|
+
*/
|
|
667
|
+
readonly maxTransfers: number;
|
|
668
|
+
/** Schedule-window end (unix seconds); the key is invalid after this. Must be a positive integer. */
|
|
669
|
+
readonly validUntil: number;
|
|
670
|
+
/**
|
|
671
|
+
* Optional schedule-window start (unix seconds); the key is invalid before
|
|
672
|
+
* this. Defaults to 0 (valid immediately). Must be `< validUntil`.
|
|
673
|
+
*/
|
|
674
|
+
readonly validAfter?: number;
|
|
675
|
+
/** ZeroDev callPolicy on-chain version. Defaults to V0_0_4. */
|
|
676
|
+
readonly callPolicyVersion?: CallPolicyVersion;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Build the ZeroDev policy bundle for a buy-list-scoped, single-use session key.
|
|
680
|
+
*
|
|
681
|
+
* Plug the returned policies into `toPermissionValidator({ policies, … })` and
|
|
682
|
+
* issue the session key via {@link issueSessionKey}.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* import { parseUnits } from "viem";
|
|
687
|
+
* import { createBuyListPolicies, getJpycAddress, JPYC_DECIMALS, polygonAmoy } from "kawasekit";
|
|
688
|
+
*
|
|
689
|
+
* const policies = createBuyListPolicies({
|
|
690
|
+
* jpycAddress: getJpycAddress(polygonAmoy.id),
|
|
691
|
+
* merchants: [merchantA, merchantB], // pay ONLY these (allowlist)
|
|
692
|
+
* maxPerTransfer: parseUnits("500", JPYC_DECIMALS),
|
|
693
|
+
* maxTransfers: 3, // at most 3 transfers, total
|
|
694
|
+
* validUntil: Math.floor(Date.now() / 1000) + 3 * 86_400, // valid 3 days
|
|
695
|
+
* });
|
|
696
|
+
* // user funds the account with their budget; the policies bound who/how-much/how-many/when.
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
declare function createBuyListPolicies(params: CreateBuyListPoliciesParams): readonly [Policy, Policy, Policy];
|
|
700
|
+
|
|
556
701
|
/**
|
|
557
702
|
* JPYC stablecoin metadata, deployments, and ABI.
|
|
558
703
|
*
|
|
@@ -919,4 +1064,4 @@ declare const jpycAbi: readonly [{
|
|
|
919
1064
|
}];
|
|
920
1065
|
}];
|
|
921
1066
|
|
|
922
|
-
export { type CreateAgentSmartAccountParams, JPYC_DECIMALS, JPYC_EIP712_DOMAIN_HINT, JPYC_V2_ADDRESS, type JpycDeployment, JpycNotAvailableError, SupportedChainId, avalanche, avalancheFuji, createAgentSmartAccount, 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, transferJpyc } from './chunk-
|
|
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';
|
|
@@ -8,7 +8,7 @@ export { KAWASEKIT_SESSION_ENVELOPE_VERSION, SessionEnvelopeChainMismatchError,
|
|
|
8
8
|
export { WIRE_VERSION, canonicalRequestBytes, createLocalPolicyGatedSigner, createMpc2pPolicyGatedSigner, toWireIntent } from './chunk-NY6VLXQB.js';
|
|
9
9
|
export { CoSignUnavailableError, PolicyGatedSignerConfigError, assertNonBypassable, authorizationDeadlineFromNow, cancelAuthorizationTypes, deriveAuthorizationNonce, generateAuthorizationNonce, getKnownAssetDomain, listKnownAssetIds, receiveWithAuthorizationTypes, requireNonBypassable, resolvedAssetToEip3009Domain, signCancelAuthorization, signReceiveWithAuthorization, signTransferWithAuthorization, transferWithAuthorizationTypes } from './chunk-VJUXTVSW.js';
|
|
10
10
|
export { X402InvalidConfigError, X402InvalidPayloadError, X402PolicyRejectedError } from './chunk-WMVJNPX2.js';
|
|
11
|
-
export { ONE_DAY_SECONDS, createJpycDailyLimitPolicies } from './chunk-
|
|
11
|
+
export { ONE_DAY_SECONDS, createJpycDailyLimitPolicies } from './chunk-UIDDRHLW.js';
|
|
12
12
|
export { SpendingPolicyConfigError, createSpendingPolicy, evaluateSpendingPolicy, mergeSpendState } from './chunk-7YKRKV6D.js';
|
|
13
13
|
export { JPYC_DECIMALS, JPYC_EIP712_DOMAIN_HINT, JPYC_V2_ADDRESS, JpycNotAvailableError, getJpycAddress, jpycAbi, jpycDeployments } from './chunk-KT7XDT2T.js';
|
|
14
14
|
export { ChainNotSupportedError, avalanche, avalancheFuji, ethereum, getChain, isSupportedChainId, kaia, kairos, polygon, polygonAmoy, sepolia, supportedChains, zerodevRpcUrl } from './chunk-SOTYGX67.js';
|
package/dist/policy/index.cjs
CHANGED
|
@@ -264,31 +264,23 @@ function normalizeRecipientAllowlist(allowlist) {
|
|
|
264
264
|
return normalized;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
// src/policy/
|
|
268
|
-
|
|
269
|
-
function createJpycDailyLimitPolicies(params) {
|
|
267
|
+
// src/policy/jpyc-call-policy.ts
|
|
268
|
+
function buildJpycTransferCallPolicy(params) {
|
|
270
269
|
if (params.maxPerTransfer <= 0n) {
|
|
271
|
-
throw new Error(
|
|
272
|
-
`createJpycDailyLimitPolicies: maxPerTransfer must be positive, got ${params.maxPerTransfer}.`
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
if (!Number.isInteger(params.maxTransfersPerDay) || params.maxTransfersPerDay < 1) {
|
|
276
|
-
throw new Error(
|
|
277
|
-
`createJpycDailyLimitPolicies: maxTransfersPerDay must be a positive integer, got ${params.maxTransfersPerDay}.`
|
|
278
|
-
);
|
|
270
|
+
throw new Error(`maxPerTransfer must be positive, got ${params.maxPerTransfer}.`);
|
|
279
271
|
}
|
|
280
272
|
const recipients = params.recipientAllowlist === void 0 || params.recipientAllowlist === "any" ? null : normalizeRecipientAllowlist(params.recipientAllowlist);
|
|
281
273
|
if (recipients !== null && recipients.length === 0) {
|
|
282
274
|
throw new Error(
|
|
283
|
-
'
|
|
275
|
+
'recipientAllowlist must not be empty \u2014 omit it or pass "any" to allow any recipient.'
|
|
284
276
|
);
|
|
285
277
|
}
|
|
286
278
|
if (recipients !== null && params.callPolicyVersion === policies.CallPolicyVersion.V0_0_1) {
|
|
287
279
|
throw new Error(
|
|
288
|
-
"
|
|
280
|
+
"recipientAllowlist requires callPolicyVersion V0_0_2 or later (the ONE_OF condition is unsupported on V0_0_1)."
|
|
289
281
|
);
|
|
290
282
|
}
|
|
291
|
-
|
|
283
|
+
return policies.toCallPolicy({
|
|
292
284
|
policyVersion: params.callPolicyVersion ?? policies.CallPolicyVersion.V0_0_4,
|
|
293
285
|
permissions: [
|
|
294
286
|
{
|
|
@@ -308,6 +300,22 @@ function createJpycDailyLimitPolicies(params) {
|
|
|
308
300
|
}
|
|
309
301
|
]
|
|
310
302
|
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/policy/daily-limit.ts
|
|
306
|
+
var ONE_DAY_SECONDS = 86400;
|
|
307
|
+
function createJpycDailyLimitPolicies(params) {
|
|
308
|
+
if (!Number.isInteger(params.maxTransfersPerDay) || params.maxTransfersPerDay < 1) {
|
|
309
|
+
throw new Error(
|
|
310
|
+
`createJpycDailyLimitPolicies: maxTransfersPerDay must be a positive integer, got ${params.maxTransfersPerDay}.`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
const callPolicy = buildJpycTransferCallPolicy({
|
|
314
|
+
jpycAddress: params.jpycAddress,
|
|
315
|
+
maxPerTransfer: params.maxPerTransfer,
|
|
316
|
+
recipientAllowlist: params.recipientAllowlist,
|
|
317
|
+
callPolicyVersion: params.callPolicyVersion
|
|
318
|
+
});
|
|
311
319
|
const rateLimitPolicy = policies.toRateLimitPolicy({
|
|
312
320
|
interval: ONE_DAY_SECONDS,
|
|
313
321
|
count: params.maxTransfersPerDay
|