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/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';
|
|
@@ -9,7 +9,7 @@ import { issueSessionKey, serializeSessionEnvelope, restoreSessionAccount, revok
|
|
|
9
9
|
import '../chunk-NY6VLXQB.js';
|
|
10
10
|
import '../chunk-VJUXTVSW.js';
|
|
11
11
|
import '../chunk-WMVJNPX2.js';
|
|
12
|
-
import { createJpycDailyLimitPolicies } from '../chunk-
|
|
12
|
+
import { createJpycDailyLimitPolicies } from '../chunk-UIDDRHLW.js';
|
|
13
13
|
import '../chunk-7YKRKV6D.js';
|
|
14
14
|
import { JPYC_DECIMALS, getJpycAddress, jpycAbi } from '../chunk-KT7XDT2T.js';
|
|
15
15
|
import { zerodevRpcUrl, polygon, polygonAmoy } from '../chunk-SOTYGX67.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 = {
|
|
@@ -376,31 +425,23 @@ function normalizeRecipientAllowlist(allowlist) {
|
|
|
376
425
|
return normalized;
|
|
377
426
|
}
|
|
378
427
|
|
|
379
|
-
// src/policy/
|
|
380
|
-
|
|
381
|
-
function createJpycDailyLimitPolicies(params) {
|
|
428
|
+
// src/policy/jpyc-call-policy.ts
|
|
429
|
+
function buildJpycTransferCallPolicy(params) {
|
|
382
430
|
if (params.maxPerTransfer <= 0n) {
|
|
383
|
-
throw new Error(
|
|
384
|
-
`createJpycDailyLimitPolicies: maxPerTransfer must be positive, got ${params.maxPerTransfer}.`
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
if (!Number.isInteger(params.maxTransfersPerDay) || params.maxTransfersPerDay < 1) {
|
|
388
|
-
throw new Error(
|
|
389
|
-
`createJpycDailyLimitPolicies: maxTransfersPerDay must be a positive integer, got ${params.maxTransfersPerDay}.`
|
|
390
|
-
);
|
|
431
|
+
throw new Error(`maxPerTransfer must be positive, got ${params.maxPerTransfer}.`);
|
|
391
432
|
}
|
|
392
433
|
const recipients = params.recipientAllowlist === void 0 || params.recipientAllowlist === "any" ? null : normalizeRecipientAllowlist(params.recipientAllowlist);
|
|
393
434
|
if (recipients !== null && recipients.length === 0) {
|
|
394
435
|
throw new Error(
|
|
395
|
-
'
|
|
436
|
+
'recipientAllowlist must not be empty \u2014 omit it or pass "any" to allow any recipient.'
|
|
396
437
|
);
|
|
397
438
|
}
|
|
398
439
|
if (recipients !== null && params.callPolicyVersion === policies.CallPolicyVersion.V0_0_1) {
|
|
399
440
|
throw new Error(
|
|
400
|
-
"
|
|
441
|
+
"recipientAllowlist requires callPolicyVersion V0_0_2 or later (the ONE_OF condition is unsupported on V0_0_1)."
|
|
401
442
|
);
|
|
402
443
|
}
|
|
403
|
-
|
|
444
|
+
return policies.toCallPolicy({
|
|
404
445
|
policyVersion: params.callPolicyVersion ?? policies.CallPolicyVersion.V0_0_4,
|
|
405
446
|
permissions: [
|
|
406
447
|
{
|
|
@@ -420,6 +461,65 @@ function createJpycDailyLimitPolicies(params) {
|
|
|
420
461
|
}
|
|
421
462
|
]
|
|
422
463
|
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/policy/buy-list.ts
|
|
467
|
+
function createBuyListPolicies(params) {
|
|
468
|
+
if (params.merchants.length === 0) {
|
|
469
|
+
throw new Error(
|
|
470
|
+
"createBuyListPolicies: merchants must not be empty \u2014 a buy-list must target at least one merchant."
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
if (!Number.isInteger(params.maxTransfers) || params.maxTransfers < 1) {
|
|
474
|
+
throw new Error(
|
|
475
|
+
`createBuyListPolicies: maxTransfers must be a positive integer, got ${params.maxTransfers}.`
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
if (!Number.isInteger(params.validUntil) || params.validUntil <= 0) {
|
|
479
|
+
throw new Error(
|
|
480
|
+
`createBuyListPolicies: validUntil must be a positive unix-seconds integer, got ${params.validUntil}.`
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
const validAfter = params.validAfter ?? 0;
|
|
484
|
+
if (!Number.isInteger(validAfter) || validAfter < 0) {
|
|
485
|
+
throw new Error(
|
|
486
|
+
`createBuyListPolicies: validAfter must be a non-negative unix-seconds integer, got ${params.validAfter}.`
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
if (validAfter >= params.validUntil) {
|
|
490
|
+
throw new Error(
|
|
491
|
+
`createBuyListPolicies: validAfter (${validAfter}) must be before validUntil (${params.validUntil}).`
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
const callPolicy = buildJpycTransferCallPolicy({
|
|
495
|
+
jpycAddress: params.jpycAddress,
|
|
496
|
+
maxPerTransfer: params.maxPerTransfer,
|
|
497
|
+
recipientAllowlist: params.merchants,
|
|
498
|
+
callPolicyVersion: params.callPolicyVersion
|
|
499
|
+
});
|
|
500
|
+
const rateLimitPolicy = policies.toRateLimitPolicy({
|
|
501
|
+
interval: params.validUntil - validAfter,
|
|
502
|
+
count: params.maxTransfers,
|
|
503
|
+
startAt: validAfter
|
|
504
|
+
});
|
|
505
|
+
const timestampPolicy = policies.toTimestampPolicy(
|
|
506
|
+
params.validAfter === void 0 ? { validUntil: params.validUntil } : { validAfter: params.validAfter, validUntil: params.validUntil }
|
|
507
|
+
);
|
|
508
|
+
return [callPolicy, rateLimitPolicy, timestampPolicy];
|
|
509
|
+
}
|
|
510
|
+
var ONE_DAY_SECONDS = 86400;
|
|
511
|
+
function createJpycDailyLimitPolicies(params) {
|
|
512
|
+
if (!Number.isInteger(params.maxTransfersPerDay) || params.maxTransfersPerDay < 1) {
|
|
513
|
+
throw new Error(
|
|
514
|
+
`createJpycDailyLimitPolicies: maxTransfersPerDay must be a positive integer, got ${params.maxTransfersPerDay}.`
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
const callPolicy = buildJpycTransferCallPolicy({
|
|
518
|
+
jpycAddress: params.jpycAddress,
|
|
519
|
+
maxPerTransfer: params.maxPerTransfer,
|
|
520
|
+
recipientAllowlist: params.recipientAllowlist,
|
|
521
|
+
callPolicyVersion: params.callPolicyVersion
|
|
522
|
+
});
|
|
423
523
|
const rateLimitPolicy = policies.toRateLimitPolicy({
|
|
424
524
|
interval: ONE_DAY_SECONDS,
|
|
425
525
|
count: params.maxTransfersPerDay
|
|
@@ -1548,24 +1648,6 @@ function encodePaymentResponseHeader(payload) {
|
|
|
1548
1648
|
function decodePaymentResponseHeader(headerValue) {
|
|
1549
1649
|
return decodeHeader(X402_HEADER_PAYMENT_RESPONSE, headerValue);
|
|
1550
1650
|
}
|
|
1551
|
-
|
|
1552
|
-
// src/observability/hooks.ts
|
|
1553
|
-
function invokeHookSafely(hook, event) {
|
|
1554
|
-
if (hook === void 0) return;
|
|
1555
|
-
try {
|
|
1556
|
-
const result = hook(event);
|
|
1557
|
-
if (result instanceof Promise) {
|
|
1558
|
-
result.catch(() => {
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
} catch {
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
function extractAcceptedNetworks(requirements) {
|
|
1565
|
-
return requirements.map((req) => req.network);
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
// src/x402/facilitator.ts
|
|
1569
1651
|
var X402_FACILITATOR_ERROR_CODES = {
|
|
1570
1652
|
insufficient_funds: "insufficient_funds",
|
|
1571
1653
|
invalid_exact_evm_payload_authorization_valid_after: "invalid_exact_evm_payload_authorization_valid_after",
|
|
@@ -3234,6 +3316,7 @@ exports.cancelAuthorizationTypes = cancelAuthorizationTypes;
|
|
|
3234
3316
|
exports.canonicalRequestBytes = canonicalRequestBytes;
|
|
3235
3317
|
exports.chainIdToX402Network = chainIdToX402Network;
|
|
3236
3318
|
exports.createAgentSmartAccount = createAgentSmartAccount;
|
|
3319
|
+
exports.createBuyListPolicies = createBuyListPolicies;
|
|
3237
3320
|
exports.createCoinbaseFacilitator = createCoinbaseFacilitator;
|
|
3238
3321
|
exports.createHttpFacilitator = createHttpFacilitator;
|
|
3239
3322
|
exports.createIdempotencyKeyBuilder = createIdempotencyKeyBuilder;
|
|
@@ -3243,6 +3326,7 @@ exports.createLocalPolicyGatedSigner = createLocalPolicyGatedSigner;
|
|
|
3243
3326
|
exports.createMpc2pPolicyGatedSigner = createMpc2pPolicyGatedSigner;
|
|
3244
3327
|
exports.createSelfFacilitator = createSelfFacilitator;
|
|
3245
3328
|
exports.createSpendingPolicy = createSpendingPolicy;
|
|
3329
|
+
exports.createSponsoredKernelClient = createSponsoredKernelClient;
|
|
3246
3330
|
exports.createX402Handler = createX402Handler;
|
|
3247
3331
|
exports.createX402PaymentSigner = createX402PaymentSigner;
|
|
3248
3332
|
exports.decodePaymentRequiredHeader = decodePaymentRequiredHeader;
|