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/{chunk-Y2LOACWO.js → chunk-DMP7YFGA.js} +37 -4
- package/dist/chunk-DMP7YFGA.js.map +1 -0
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/index.cjs +50 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -2
- package/dist/index.d.ts +72 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-Y2LOACWO.js.map +0 -1
|
@@ -1,9 +1,42 @@
|
|
|
1
|
+
import { invokeHookSafely } from './chunk-LEHWRDVS.js';
|
|
1
2
|
import { buildJpycTransferCallPolicy } from './chunk-UIDDRHLW.js';
|
|
2
3
|
import { getJpycAddress, jpycAbi } from './chunk-KT7XDT2T.js';
|
|
3
4
|
import { isSupportedChainId } from './chunk-SOTYGX67.js';
|
|
4
|
-
import {
|
|
5
|
+
import { createZeroDevPaymasterClient, createKernelAccountClient } from '@zerodev/sdk';
|
|
6
|
+
import { http, isAddress, encodeFunctionData } from 'viem';
|
|
5
7
|
import { toRateLimitPolicy, toTimestampPolicy } from '@zerodev/permissions/policies';
|
|
6
8
|
|
|
9
|
+
async function sponsorWithObservability(sponsor, account, observability) {
|
|
10
|
+
try {
|
|
11
|
+
const data = await sponsor();
|
|
12
|
+
invokeHookSafely(observability?.onSponsor, { account });
|
|
13
|
+
return data;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
invokeHookSafely(observability?.onSponsorError, { account, error });
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function createSponsoredKernelClient(params) {
|
|
20
|
+
const paymasterClient = createZeroDevPaymasterClient({
|
|
21
|
+
chain: params.chain,
|
|
22
|
+
transport: http(params.zerodevRpc)
|
|
23
|
+
});
|
|
24
|
+
const client = createKernelAccountClient({
|
|
25
|
+
account: params.account,
|
|
26
|
+
chain: params.chain,
|
|
27
|
+
// exactOptionalPropertyTypes: only pass `client` when given (never `undefined`).
|
|
28
|
+
...params.publicClient !== void 0 ? { client: params.publicClient } : {},
|
|
29
|
+
bundlerTransport: http(params.zerodevRpc),
|
|
30
|
+
paymaster: {
|
|
31
|
+
getPaymasterData: (userOperation) => sponsorWithObservability(
|
|
32
|
+
() => paymasterClient.sponsorUserOperation({ userOperation }),
|
|
33
|
+
params.account.address,
|
|
34
|
+
params.observability
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return client;
|
|
39
|
+
}
|
|
7
40
|
var TransferJpycInputError = class extends Error {
|
|
8
41
|
constructor(message) {
|
|
9
42
|
super(`transferJpyc: ${message}`);
|
|
@@ -83,6 +116,6 @@ function createBuyListPolicies(params) {
|
|
|
83
116
|
return [callPolicy, rateLimitPolicy, timestampPolicy];
|
|
84
117
|
}
|
|
85
118
|
|
|
86
|
-
export { TransferJpycInputError, createBuyListPolicies, transferJpyc };
|
|
87
|
-
//# sourceMappingURL=chunk-
|
|
88
|
-
//# sourceMappingURL=chunk-
|
|
119
|
+
export { TransferJpycInputError, createBuyListPolicies, createSponsoredKernelClient, transferJpyc };
|
|
120
|
+
//# sourceMappingURL=chunk-DMP7YFGA.js.map
|
|
121
|
+
//# sourceMappingURL=chunk-DMP7YFGA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/sponsored-kernel-client.ts","../src/client/transfer-jpyc.ts","../src/policy/buy-list.ts"],"names":[],"mappings":";;;;;;;;AAoCA,eAAsB,wBAAA,CACrB,OAAA,EACA,OAAA,EACA,aAAA,EACa;AACb,EAAA,IAAI;AACH,IAAA,MAAM,IAAA,GAAO,MAAM,OAAA,EAAQ;AAC3B,IAAA,gBAAA,CAAiB,aAAA,EAAe,SAAA,EAAW,EAAE,OAAA,EAAS,CAAA;AACtD,IAAA,OAAO,IAAA;AAAA,EACR,SAAS,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AO;AAAA,GAC1B,CAAA;AAOD,EAAA,MAAM,kBAAkB,iBAAA,CAAkB;AAAA,IACzC,QAAA,EAAU,OAAO,UAAA,GAAa,UAAA;AAAA,IAC9B,OAAO,MAAA,CAAO,YAAA;AAAA,IACd,OAAA,EAAS;AAAA,GACT,CAAA;AAID,EAAA,MAAM,eAAA,GAAkB,iBAAA;AAAA,IACvB,MAAA,CAAO,UAAA,KAAe,MAAA,GACnB,EAAE,YAAY,MAAA,CAAO,UAAA,EAAW,GAChC,EAAE,UAAA,EAAY,MAAA,CAAO,UAAA,EAAY,UAAA,EAAY,OAAO,UAAA;AAAW,GACnE;AAEA,EAAA,OAAO,CAAC,UAAA,EAAY,eAAA,EAAiB,eAAe,CAAA;AACrD","file":"chunk-DMP7YFGA.js","sourcesContent":["/**\n * Build a gas-sponsored Kernel account client — a {@link ConfiguredKernelClient}\n * whose UserOp gas is paid by the ZeroDev paymaster. Pass the returned client\n * straight to {@link transferJpyc}; callers never construct a paymaster client or\n * cast to {@link ConfiguredKernelClient}.\n *\n * @packageDocumentation\n */\n\nimport {\n\ttype CreateKernelAccountReturnType,\n\tcreateKernelAccountClient,\n\tcreateZeroDevPaymasterClient,\n} from \"@zerodev/sdk\";\nimport { type Address, type Chain, http, type PublicClient, type Transport } from \"viem\";\nimport { invokeHookSafely } from \"../observability/hooks\";\nimport type { ConfiguredKernelClient } from \"./transfer-jpyc\";\n\n/**\n * Optional sponsorship observability. Hooks fire through {@link invokeHookSafely},\n * so a throwing hook never breaks sponsorship. The existing `ObservabilityHooks`\n * is x402-facilitator-shaped (verify/settle); this is the paymaster-seam surface.\n */\nexport interface SponsoredKernelClientObservability {\n\t/** Fired AFTER the paymaster GRANTS sponsorship for a userOp. */\n\treadonly onSponsor?: (event: { readonly account: Address }) => void;\n\t/** Fired when the paymaster DECLINES sponsorship (the raw error then propagates). */\n\treadonly onSponsorError?: (event: { readonly account: Address; readonly error: unknown }) => void;\n}\n\n/**\n * @internal Sponsor a userOp and fire the granted/declined observability hook.\n * The original paymaster error is re-thrown unchanged (no SDK wrapping). Exported\n * for unit testing the seam without a live chain; NOT part of the public API\n * (not re-exported from `src/index.ts`).\n */\nexport async function sponsorWithObservability<T>(\n\tsponsor: () => Promise<T>,\n\taccount: Address,\n\tobservability: SponsoredKernelClientObservability | undefined,\n): Promise<T> {\n\ttry {\n\t\tconst data = await sponsor();\n\t\tinvokeHookSafely(observability?.onSponsor, { account });\n\t\treturn data;\n\t} catch (error) {\n\t\tinvokeHookSafely(observability?.onSponsorError, { account, error });\n\t\tthrow error;\n\t}\n}\n\n/** Parameters for {@link createSponsoredKernelClient}. */\nexport interface CreateSponsoredKernelClientParams {\n\t/** A Kernel v0.7 account from `createAgentSmartAccount` or `restoreSessionAccount`. */\n\treadonly account: CreateKernelAccountReturnType<\"0.7\">;\n\t/** The viem chain the client operates on (e.g. `polygonAmoy`). */\n\treadonly chain: Chain;\n\t/**\n\t * The ZeroDev RPC URL — used for BOTH the bundler and the paymaster (ZeroDev\n\t * serves both from one project RPC). Build it from a project id with\n\t * `zerodevRpcUrl(chain, projectId)`, or paste the dashboard URL.\n\t */\n\treadonly zerodevRpc: string;\n\t/** Optional viem `PublicClient` for on-chain reads during userOp prep (recommended). */\n\treadonly publicClient?: PublicClient<Transport, Chain>;\n\t/** Optional sponsorship observability — granted / declined. */\n\treadonly observability?: SponsoredKernelClientObservability;\n}\n\n/**\n * Build a gas-sponsored Kernel account client. The returned\n * {@link ConfiguredKernelClient} pays UserOp gas via the ZeroDev paymaster and is\n * accepted directly by {@link transferJpyc} — no caller-side cast.\n *\n * @example\n * ```ts\n * import {\n * createSponsoredKernelClient,\n * polygonAmoy,\n * restoreSessionAccount,\n * transferJpyc,\n * zerodevRpcUrl,\n * } from \"kawasekit\";\n *\n * const account = await restoreSessionAccount({ publicClient, envelope, sessionKeySigner });\n * const client = createSponsoredKernelClient({\n * account,\n * chain: polygonAmoy,\n * zerodevRpc: zerodevRpcUrl(polygonAmoy, projectId),\n * publicClient,\n * });\n * const { transactionHash } = await transferJpyc(client, { to, amount });\n * ```\n */\nexport function createSponsoredKernelClient(\n\tparams: CreateSponsoredKernelClientParams,\n): ConfiguredKernelClient {\n\tconst paymasterClient = createZeroDevPaymasterClient({\n\t\tchain: params.chain,\n\t\ttransport: http(params.zerodevRpc),\n\t});\n\tconst client = createKernelAccountClient({\n\t\taccount: params.account,\n\t\tchain: params.chain,\n\t\t// exactOptionalPropertyTypes: only pass `client` when given (never `undefined`).\n\t\t...(params.publicClient !== undefined ? { client: params.publicClient } : {}),\n\t\tbundlerTransport: http(params.zerodevRpc),\n\t\tpaymaster: {\n\t\t\tgetPaymasterData: (userOperation) =>\n\t\t\t\tsponsorWithObservability(\n\t\t\t\t\t() => paymasterClient.sponsorUserOperation({ userOperation }),\n\t\t\t\t\tparams.account.address,\n\t\t\t\t\tparams.observability,\n\t\t\t\t),\n\t\t},\n\t});\n\t// createKernelAccountClient's deep generics don't unify with the exported\n\t// ConfiguredKernelClient alias; the runtime client is identical. One cast here\n\t// means callers never cast (closing gap G4).\n\treturn client as unknown as ConfiguredKernelClient;\n}\n","/**\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"]}
|
package/dist/cli/index.cjs
CHANGED
|
@@ -1675,7 +1675,7 @@ function registerTransferCommand(program2) {
|
|
|
1675
1675
|
}
|
|
1676
1676
|
|
|
1677
1677
|
// cli/index.ts
|
|
1678
|
-
var CLI_VERSION = "0.
|
|
1678
|
+
var CLI_VERSION = "0.8.0" ;
|
|
1679
1679
|
var program = new commander.Command();
|
|
1680
1680
|
program.name("kawasekit").description(
|
|
1681
1681
|
"kawasekit \u2014 CLI for the kawasekit SDK (AI-agent stablecoin payments, Japan-first, JPYC-native)."
|
package/dist/cli/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { transferJpyc } from '../chunk-
|
|
2
|
+
import { transferJpyc } from '../chunk-DMP7YFGA.js';
|
|
3
3
|
import '../chunk-P5563RGP.js';
|
|
4
4
|
import '../chunk-PVUKX6IF.js';
|
|
5
5
|
import '../chunk-LEHWRDVS.js';
|
|
@@ -980,7 +980,7 @@ function registerTransferCommand(program2) {
|
|
|
980
980
|
}
|
|
981
981
|
|
|
982
982
|
// cli/index.ts
|
|
983
|
-
var CLI_VERSION = "0.
|
|
983
|
+
var CLI_VERSION = "0.8.0" ;
|
|
984
984
|
var program = new Command();
|
|
985
985
|
program.name("kawasekit").description(
|
|
986
986
|
"kawasekit \u2014 CLI for the kawasekit SDK (AI-agent stablecoin payments, Japan-first, JPYC-native)."
|
package/dist/index.cjs
CHANGED
|
@@ -123,6 +123,55 @@ function getChain(chainId) {
|
|
|
123
123
|
return chain;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// src/observability/hooks.ts
|
|
127
|
+
function invokeHookSafely(hook, event) {
|
|
128
|
+
if (hook === void 0) return;
|
|
129
|
+
try {
|
|
130
|
+
const result = hook(event);
|
|
131
|
+
if (result instanceof Promise) {
|
|
132
|
+
result.catch(() => {
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function extractAcceptedNetworks(requirements) {
|
|
139
|
+
return requirements.map((req) => req.network);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/client/sponsored-kernel-client.ts
|
|
143
|
+
async function sponsorWithObservability(sponsor, account, observability) {
|
|
144
|
+
try {
|
|
145
|
+
const data = await sponsor();
|
|
146
|
+
invokeHookSafely(observability?.onSponsor, { account });
|
|
147
|
+
return data;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
invokeHookSafely(observability?.onSponsorError, { account, error });
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function createSponsoredKernelClient(params) {
|
|
154
|
+
const paymasterClient = sdk.createZeroDevPaymasterClient({
|
|
155
|
+
chain: params.chain,
|
|
156
|
+
transport: viem.http(params.zerodevRpc)
|
|
157
|
+
});
|
|
158
|
+
const client = sdk.createKernelAccountClient({
|
|
159
|
+
account: params.account,
|
|
160
|
+
chain: params.chain,
|
|
161
|
+
// exactOptionalPropertyTypes: only pass `client` when given (never `undefined`).
|
|
162
|
+
...params.publicClient !== void 0 ? { client: params.publicClient } : {},
|
|
163
|
+
bundlerTransport: viem.http(params.zerodevRpc),
|
|
164
|
+
paymaster: {
|
|
165
|
+
getPaymasterData: (userOperation) => sponsorWithObservability(
|
|
166
|
+
() => paymasterClient.sponsorUserOperation({ userOperation }),
|
|
167
|
+
params.account.address,
|
|
168
|
+
params.observability
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return client;
|
|
173
|
+
}
|
|
174
|
+
|
|
126
175
|
// src/tokens/jpyc.ts
|
|
127
176
|
var JPYC_DECIMALS = 18;
|
|
128
177
|
var JPYC_EIP712_DOMAIN_HINT = {
|
|
@@ -1599,24 +1648,6 @@ function encodePaymentResponseHeader(payload) {
|
|
|
1599
1648
|
function decodePaymentResponseHeader(headerValue) {
|
|
1600
1649
|
return decodeHeader(X402_HEADER_PAYMENT_RESPONSE, headerValue);
|
|
1601
1650
|
}
|
|
1602
|
-
|
|
1603
|
-
// src/observability/hooks.ts
|
|
1604
|
-
function invokeHookSafely(hook, event) {
|
|
1605
|
-
if (hook === void 0) return;
|
|
1606
|
-
try {
|
|
1607
|
-
const result = hook(event);
|
|
1608
|
-
if (result instanceof Promise) {
|
|
1609
|
-
result.catch(() => {
|
|
1610
|
-
});
|
|
1611
|
-
}
|
|
1612
|
-
} catch {
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
function extractAcceptedNetworks(requirements) {
|
|
1616
|
-
return requirements.map((req) => req.network);
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1619
|
-
// src/x402/facilitator.ts
|
|
1620
1651
|
var X402_FACILITATOR_ERROR_CODES = {
|
|
1621
1652
|
insufficient_funds: "insufficient_funds",
|
|
1622
1653
|
invalid_exact_evm_payload_authorization_valid_after: "invalid_exact_evm_payload_authorization_valid_after",
|
|
@@ -3295,6 +3326,7 @@ exports.createLocalPolicyGatedSigner = createLocalPolicyGatedSigner;
|
|
|
3295
3326
|
exports.createMpc2pPolicyGatedSigner = createMpc2pPolicyGatedSigner;
|
|
3296
3327
|
exports.createSelfFacilitator = createSelfFacilitator;
|
|
3297
3328
|
exports.createSpendingPolicy = createSpendingPolicy;
|
|
3329
|
+
exports.createSponsoredKernelClient = createSponsoredKernelClient;
|
|
3298
3330
|
exports.createX402Handler = createX402Handler;
|
|
3299
3331
|
exports.createX402PaymentSigner = createX402PaymentSigner;
|
|
3300
3332
|
exports.decodePaymentRequiredHeader = decodePaymentRequiredHeader;
|