kawasekit 0.5.0 → 0.7.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/cli/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import { transferJpyc } from '../chunk-RJLDKDWL.js';
2
+ import { transferJpyc } from '../chunk-Y2LOACWO.js';
3
3
  import '../chunk-P5563RGP.js';
4
4
  import '../chunk-PVUKX6IF.js';
5
5
  import '../chunk-LEHWRDVS.js';
6
6
  import '../chunk-TTX3RBIZ.js';
7
7
  import '../chunk-QHUCU5YX.js';
8
8
  import { issueSessionKey, serializeSessionEnvelope, restoreSessionAccount, revokeSessionKey, rotateSessionKey, parseSessionEnvelope } from '../chunk-N3CVLISJ.js';
9
- import '../chunk-S2ZSX2VS.js';
9
+ import '../chunk-NY6VLXQB.js';
10
10
  import '../chunk-VJUXTVSW.js';
11
11
  import '../chunk-WMVJNPX2.js';
12
- import { createJpycDailyLimitPolicies } from '../chunk-E47SIVFY.js';
13
- import '../chunk-6CNAYQOL.js';
12
+ import { createJpycDailyLimitPolicies } from '../chunk-UIDDRHLW.js';
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';
16
16
  import { __commonJS, __require, __toESM } from '../chunk-7D4SUZUM.js';
@@ -980,7 +980,7 @@ function registerTransferCommand(program2) {
980
980
  }
981
981
 
982
982
  // cli/index.ts
983
- var CLI_VERSION = "0.5.0" ;
983
+ var CLI_VERSION = "0.7.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
@@ -363,19 +363,36 @@ async function transferJpyc(kernelClient, params) {
363
363
  success: receipt.success
364
364
  };
365
365
  }
366
- var ONE_DAY_SECONDS = 86400;
367
- function createJpycDailyLimitPolicies(params) {
366
+ function normalizeRecipientAllowlist(allowlist) {
367
+ const seen = /* @__PURE__ */ new Set();
368
+ const normalized = [];
369
+ for (const entry of allowlist) {
370
+ const checksummed = viem.getAddress(entry);
371
+ if (!seen.has(checksummed)) {
372
+ seen.add(checksummed);
373
+ normalized.push(checksummed);
374
+ }
375
+ }
376
+ return normalized;
377
+ }
378
+
379
+ // src/policy/jpyc-call-policy.ts
380
+ function buildJpycTransferCallPolicy(params) {
368
381
  if (params.maxPerTransfer <= 0n) {
382
+ throw new Error(`maxPerTransfer must be positive, got ${params.maxPerTransfer}.`);
383
+ }
384
+ const recipients = params.recipientAllowlist === void 0 || params.recipientAllowlist === "any" ? null : normalizeRecipientAllowlist(params.recipientAllowlist);
385
+ if (recipients !== null && recipients.length === 0) {
369
386
  throw new Error(
370
- `createJpycDailyLimitPolicies: maxPerTransfer must be positive, got ${params.maxPerTransfer}.`
387
+ 'recipientAllowlist must not be empty \u2014 omit it or pass "any" to allow any recipient.'
371
388
  );
372
389
  }
373
- if (!Number.isInteger(params.maxTransfersPerDay) || params.maxTransfersPerDay < 1) {
390
+ if (recipients !== null && params.callPolicyVersion === policies.CallPolicyVersion.V0_0_1) {
374
391
  throw new Error(
375
- `createJpycDailyLimitPolicies: maxTransfersPerDay must be a positive integer, got ${params.maxTransfersPerDay}.`
392
+ "recipientAllowlist requires callPolicyVersion V0_0_2 or later (the ONE_OF condition is unsupported on V0_0_1)."
376
393
  );
377
394
  }
378
- const callPolicy = policies.toCallPolicy({
395
+ return policies.toCallPolicy({
379
396
  policyVersion: params.callPolicyVersion ?? policies.CallPolicyVersion.V0_0_4,
380
397
  permissions: [
381
398
  {
@@ -383,8 +400,9 @@ function createJpycDailyLimitPolicies(params) {
383
400
  abi: jpycAbi,
384
401
  functionName: "transfer",
385
402
  args: [
386
- // Recipient: any address allowed (no allowlist in M2).
387
- null,
403
+ // Recipient (`to`): unrestricted (`null`) unless an allowlist resolved
404
+ // above, in which case it is constrained via the ONE_OF condition.
405
+ recipients === null ? null : { condition: policies.ParamCondition.ONE_OF, value: recipients },
388
406
  // value: must be ≤ maxPerTransfer.
389
407
  {
390
408
  condition: policies.ParamCondition.LESS_THAN_OR_EQUAL,
@@ -394,6 +412,65 @@ function createJpycDailyLimitPolicies(params) {
394
412
  }
395
413
  ]
396
414
  });
415
+ }
416
+
417
+ // src/policy/buy-list.ts
418
+ function createBuyListPolicies(params) {
419
+ if (params.merchants.length === 0) {
420
+ throw new Error(
421
+ "createBuyListPolicies: merchants must not be empty \u2014 a buy-list must target at least one merchant."
422
+ );
423
+ }
424
+ if (!Number.isInteger(params.maxTransfers) || params.maxTransfers < 1) {
425
+ throw new Error(
426
+ `createBuyListPolicies: maxTransfers must be a positive integer, got ${params.maxTransfers}.`
427
+ );
428
+ }
429
+ if (!Number.isInteger(params.validUntil) || params.validUntil <= 0) {
430
+ throw new Error(
431
+ `createBuyListPolicies: validUntil must be a positive unix-seconds integer, got ${params.validUntil}.`
432
+ );
433
+ }
434
+ const validAfter = params.validAfter ?? 0;
435
+ if (!Number.isInteger(validAfter) || validAfter < 0) {
436
+ throw new Error(
437
+ `createBuyListPolicies: validAfter must be a non-negative unix-seconds integer, got ${params.validAfter}.`
438
+ );
439
+ }
440
+ if (validAfter >= params.validUntil) {
441
+ throw new Error(
442
+ `createBuyListPolicies: validAfter (${validAfter}) must be before validUntil (${params.validUntil}).`
443
+ );
444
+ }
445
+ const callPolicy = buildJpycTransferCallPolicy({
446
+ jpycAddress: params.jpycAddress,
447
+ maxPerTransfer: params.maxPerTransfer,
448
+ recipientAllowlist: params.merchants,
449
+ callPolicyVersion: params.callPolicyVersion
450
+ });
451
+ const rateLimitPolicy = policies.toRateLimitPolicy({
452
+ interval: params.validUntil - validAfter,
453
+ count: params.maxTransfers,
454
+ startAt: validAfter
455
+ });
456
+ const timestampPolicy = policies.toTimestampPolicy(
457
+ params.validAfter === void 0 ? { validUntil: params.validUntil } : { validAfter: params.validAfter, validUntil: params.validUntil }
458
+ );
459
+ return [callPolicy, rateLimitPolicy, timestampPolicy];
460
+ }
461
+ var ONE_DAY_SECONDS = 86400;
462
+ function createJpycDailyLimitPolicies(params) {
463
+ if (!Number.isInteger(params.maxTransfersPerDay) || params.maxTransfersPerDay < 1) {
464
+ throw new Error(
465
+ `createJpycDailyLimitPolicies: maxTransfersPerDay must be a positive integer, got ${params.maxTransfersPerDay}.`
466
+ );
467
+ }
468
+ const callPolicy = buildJpycTransferCallPolicy({
469
+ jpycAddress: params.jpycAddress,
470
+ maxPerTransfer: params.maxPerTransfer,
471
+ recipientAllowlist: params.recipientAllowlist,
472
+ callPolicyVersion: params.callPolicyVersion
473
+ });
397
474
  const rateLimitPolicy = policies.toRateLimitPolicy({
398
475
  interval: ONE_DAY_SECONDS,
399
476
  count: params.maxTransfersPerDay
@@ -501,7 +578,7 @@ function createSpendingPolicy(params) {
501
578
  }
502
579
  return { token, maxPerSign: l.maxPerSign };
503
580
  });
504
- const recipientAllowlist = params.recipientAllowlist === "any" ? "any" : params.recipientAllowlist.map((a) => viem.getAddress(a));
581
+ const recipientAllowlist = params.recipientAllowlist === "any" ? "any" : normalizeRecipientAllowlist(params.recipientAllowlist);
505
582
  return {
506
583
  version: "1",
507
584
  session: { id: params.session.id, notAfter: params.session.notAfter },
@@ -3208,6 +3285,7 @@ exports.cancelAuthorizationTypes = cancelAuthorizationTypes;
3208
3285
  exports.canonicalRequestBytes = canonicalRequestBytes;
3209
3286
  exports.chainIdToX402Network = chainIdToX402Network;
3210
3287
  exports.createAgentSmartAccount = createAgentSmartAccount;
3288
+ exports.createBuyListPolicies = createBuyListPolicies;
3211
3289
  exports.createCoinbaseFacilitator = createCoinbaseFacilitator;
3212
3290
  exports.createHttpFacilitator = createHttpFacilitator;
3213
3291
  exports.createIdempotencyKeyBuilder = createIdempotencyKeyBuilder;