@invisi-labs/protocol 1.1.2 → 1.1.3

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
@@ -1,3 +1,4 @@
1
+ import * as _invisi_labs_core from '@invisi-labs/core';
1
2
  import { Hex, Address, ReceivingKeyLookup, Wallet, Note, CreditDeliveryState, AuthorizedStatement } from '@invisi-labs/core';
2
3
  import { ContractRunner, Signer, Provider } from 'ethers';
3
4
  import { DeploymentContext, CanonicalBlock, ProtocolDeployment, ProtocolRpcClient } from '@invisi-labs/rpc';
@@ -67,6 +68,8 @@ declare function createRegistryReceivingKeyLookup(client: RegistryReadClient, re
67
68
  interface TransactionContext extends DeploymentContext {
68
69
  tokenAddress: Address;
69
70
  now?: bigint;
71
+ /** Explicit chain timestamp used to bind Credit draw UTC periods. */
72
+ timestamp?: bigint;
70
73
  }
71
74
  declare const FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
72
75
  declare const ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
@@ -93,6 +96,8 @@ declare function normalizeContext(c: TransactionContext): {
93
96
  protocolAddress: Hex;
94
97
  tokenAddress: Hex;
95
98
  now?: bigint;
99
+ /** Explicit chain timestamp used to bind Credit draw UTC periods. */
100
+ timestamp?: bigint;
96
101
  };
97
102
  declare function checkDeadline(c: TransactionContext, value: bigint): bigint;
98
103
  declare function normalizeSources(sources: readonly InputSource[], inputCount: number, capacity: number): {
@@ -307,6 +312,7 @@ declare function validateCreateCreditRequest(c: TransactionContext, p: CreateCre
307
312
  protocolAddress: Hex;
308
313
  tokenAddress: Hex;
309
314
  now?: bigint;
315
+ timestamp?: bigint;
310
316
  };
311
317
  declare function createCreditBaseInputs(c: TransactionContext, p: CreateCreditParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
312
318
  declare function createCreditPublicInputs(c: TransactionContext, p: CreateCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): `0x${string}`[];
@@ -408,10 +414,15 @@ declare function validateCreditDrawRequest(c: TransactionContext, p: CreditDrawP
408
414
  publicInputCount: number;
409
415
  totalBits: number;
410
416
  };
417
+ periods: {
418
+ currentDay: bigint;
419
+ currentMonth: bigint;
420
+ };
411
421
  chainId: bigint;
412
422
  protocolAddress: Hex;
413
423
  tokenAddress: Hex;
414
424
  now?: bigint;
425
+ timestamp?: bigint;
415
426
  };
416
427
  declare function creditDrawBaseInputs(c: TransactionContext, p: CreditDrawParams, cs: readonly Delivery[]): `0x${string}`[];
417
428
  declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCreditParams): {
@@ -427,6 +438,7 @@ declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCre
427
438
  protocolAddress: Hex;
428
439
  tokenAddress: Hex;
429
440
  now?: bigint;
441
+ timestamp?: bigint;
430
442
  };
431
443
  declare function cancelCreditBaseInputs(c: TransactionContext, p: CancelCreditParams): `0x${string}`[];
432
444
  declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCreditParams, cs: readonly Delivery[], funding?: FundingInput): {
@@ -449,6 +461,7 @@ declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCredi
449
461
  protocolAddress: Hex;
450
462
  tokenAddress: Hex;
451
463
  now?: bigint;
464
+ timestamp?: bigint;
452
465
  };
453
466
  creditSource: {
454
467
  treeId: bigint;
@@ -625,6 +638,7 @@ declare function normalizeTransactRequest(c: TransactionContext, p: TransactRequ
625
638
  protocolAddress: Hex;
626
639
  tokenAddress: Hex;
627
640
  now?: bigint;
641
+ timestamp?: bigint;
628
642
  };
629
643
  declare function transactPublicInputs(c: TransactionContext, p: TransactRequestParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
630
644
  declare function encodeTransactTypedData(c: TransactionContext, p: TransactRequestParams, deliveries: readonly Delivery[], f?: FundingInput): {
@@ -892,7 +906,7 @@ interface VerifyNoteCommitmentParams {
892
906
  chainId: bigint;
893
907
  }
894
908
  declare function verifyNoteCommitment(params: VerifyNoteCommitmentParams): Promise<boolean>;
895
- interface VerifyCreditCommitmentParams {
909
+ interface VerifyCreditCommitmentParams extends Partial<_invisi_labs_core.CreditPolicy> {
896
910
  chainId: bigint;
897
911
  spenderWalletIdentity: `0x${string}`;
898
912
  ownerWalletIdentity: `0x${string}`;
@@ -951,6 +965,8 @@ interface CreateCreditWitnessParams {
951
965
  authorization: AuthorizedStatement;
952
966
  }
953
967
  interface DrawCreditWitnessParams {
968
+ /** Explicit chain timestamp used to prepare this signed statement. */
969
+ timestamp: bigint;
954
970
  params: CreditDrawParams;
955
971
  deliveries: readonly Delivery[];
956
972
  inputs: readonly CreditMembership[];
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as _invisi_labs_core from '@invisi-labs/core';
1
2
  import { Hex, Address, ReceivingKeyLookup, Wallet, Note, CreditDeliveryState, AuthorizedStatement } from '@invisi-labs/core';
2
3
  import { ContractRunner, Signer, Provider } from 'ethers';
3
4
  import { DeploymentContext, CanonicalBlock, ProtocolDeployment, ProtocolRpcClient } from '@invisi-labs/rpc';
@@ -67,6 +68,8 @@ declare function createRegistryReceivingKeyLookup(client: RegistryReadClient, re
67
68
  interface TransactionContext extends DeploymentContext {
68
69
  tokenAddress: Address;
69
70
  now?: bigint;
71
+ /** Explicit chain timestamp used to bind Credit draw UTC periods. */
72
+ timestamp?: bigint;
70
73
  }
71
74
  declare const FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
72
75
  declare const ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
@@ -93,6 +96,8 @@ declare function normalizeContext(c: TransactionContext): {
93
96
  protocolAddress: Hex;
94
97
  tokenAddress: Hex;
95
98
  now?: bigint;
99
+ /** Explicit chain timestamp used to bind Credit draw UTC periods. */
100
+ timestamp?: bigint;
96
101
  };
97
102
  declare function checkDeadline(c: TransactionContext, value: bigint): bigint;
98
103
  declare function normalizeSources(sources: readonly InputSource[], inputCount: number, capacity: number): {
@@ -307,6 +312,7 @@ declare function validateCreateCreditRequest(c: TransactionContext, p: CreateCre
307
312
  protocolAddress: Hex;
308
313
  tokenAddress: Hex;
309
314
  now?: bigint;
315
+ timestamp?: bigint;
310
316
  };
311
317
  declare function createCreditBaseInputs(c: TransactionContext, p: CreateCreditParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
312
318
  declare function createCreditPublicInputs(c: TransactionContext, p: CreateCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): `0x${string}`[];
@@ -408,10 +414,15 @@ declare function validateCreditDrawRequest(c: TransactionContext, p: CreditDrawP
408
414
  publicInputCount: number;
409
415
  totalBits: number;
410
416
  };
417
+ periods: {
418
+ currentDay: bigint;
419
+ currentMonth: bigint;
420
+ };
411
421
  chainId: bigint;
412
422
  protocolAddress: Hex;
413
423
  tokenAddress: Hex;
414
424
  now?: bigint;
425
+ timestamp?: bigint;
415
426
  };
416
427
  declare function creditDrawBaseInputs(c: TransactionContext, p: CreditDrawParams, cs: readonly Delivery[]): `0x${string}`[];
417
428
  declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCreditParams): {
@@ -427,6 +438,7 @@ declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCre
427
438
  protocolAddress: Hex;
428
439
  tokenAddress: Hex;
429
440
  now?: bigint;
441
+ timestamp?: bigint;
430
442
  };
431
443
  declare function cancelCreditBaseInputs(c: TransactionContext, p: CancelCreditParams): `0x${string}`[];
432
444
  declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCreditParams, cs: readonly Delivery[], funding?: FundingInput): {
@@ -449,6 +461,7 @@ declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCredi
449
461
  protocolAddress: Hex;
450
462
  tokenAddress: Hex;
451
463
  now?: bigint;
464
+ timestamp?: bigint;
452
465
  };
453
466
  creditSource: {
454
467
  treeId: bigint;
@@ -625,6 +638,7 @@ declare function normalizeTransactRequest(c: TransactionContext, p: TransactRequ
625
638
  protocolAddress: Hex;
626
639
  tokenAddress: Hex;
627
640
  now?: bigint;
641
+ timestamp?: bigint;
628
642
  };
629
643
  declare function transactPublicInputs(c: TransactionContext, p: TransactRequestParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
630
644
  declare function encodeTransactTypedData(c: TransactionContext, p: TransactRequestParams, deliveries: readonly Delivery[], f?: FundingInput): {
@@ -892,7 +906,7 @@ interface VerifyNoteCommitmentParams {
892
906
  chainId: bigint;
893
907
  }
894
908
  declare function verifyNoteCommitment(params: VerifyNoteCommitmentParams): Promise<boolean>;
895
- interface VerifyCreditCommitmentParams {
909
+ interface VerifyCreditCommitmentParams extends Partial<_invisi_labs_core.CreditPolicy> {
896
910
  chainId: bigint;
897
911
  spenderWalletIdentity: `0x${string}`;
898
912
  ownerWalletIdentity: `0x${string}`;
@@ -951,6 +965,8 @@ interface CreateCreditWitnessParams {
951
965
  authorization: AuthorizedStatement;
952
966
  }
953
967
  interface DrawCreditWitnessParams {
968
+ /** Explicit chain timestamp used to prepare this signed statement. */
969
+ timestamp: bigint;
954
970
  params: CreditDrawParams;
955
971
  deliveries: readonly Delivery[];
956
972
  inputs: readonly CreditMembership[];
package/dist/index.js CHANGED
@@ -619,9 +619,9 @@ function normalizeDelivery(value, options = {}) {
619
619
  }
620
620
  const ciphertext = envelope(
621
621
  value.ciphertext,
622
- options.credit ? 402 : 160,
623
- options.credit ? 4 : 2,
624
- options.credit ? 658 : 416
622
+ options.credit ? 498 : 160,
623
+ options.credit ? 5 : 2,
624
+ options.credit ? 754 : 416
625
625
  );
626
626
  const clue = envelope(value.clue, 68);
627
627
  if (clue.slice(130, 132).toLowerCase() !== "18") throw new Error("clue precision must be 24");
@@ -839,6 +839,7 @@ function encodeCreditProof(proof) {
839
839
  // src/credit-lifecycle.ts
840
840
  import { AbiCoder as AbiCoder3, getAddress as getAddress5, Interface as Interface4, keccak256 as keccak2564, ParamType as ParamType3 } from "ethers";
841
841
  import {
842
+ creditPeriods,
842
843
  computeWalletAuthorizationDigest as computeWalletAuthorizationDigest2,
843
844
  walletAuthorizationTypedData as walletAuthorizationTypedData2
844
845
  } from "@invisi-labs/core";
@@ -850,7 +851,7 @@ function selectCreditDrawCircuit(count) {
850
851
  return {
851
852
  name: `credit_draw_slots${maxSize}`,
852
853
  maxSize,
853
- publicInputCount: 6 * maxSize + 12,
854
+ publicInputCount: 6 * maxSize + 14,
854
855
  totalBits: 126 + Math.ceil(Math.log2(maxSize))
855
856
  };
856
857
  }
@@ -903,7 +904,8 @@ function validateCreditDrawRequest(c, p, cs) {
903
904
  totalAmount,
904
905
  deadline: checkDeadline(c, p.deadline),
905
906
  deliveries,
906
- profile
907
+ profile,
908
+ periods: creditPeriods(c.timestamp)
907
909
  };
908
910
  }
909
911
  function creditDrawBaseInputs(c, p, cs) {
@@ -930,7 +932,9 @@ function creditDrawBaseInputs(c, p, cs) {
930
932
  r.deadline,
931
933
  h >> 128n,
932
934
  h & (1n << 128n) - 1n,
933
- ...pad(r.recoveryAmounts.map(BigInt), n)
935
+ ...pad(r.recoveryAmounts.map(BigInt), n),
936
+ r.periods.currentDay,
937
+ r.periods.currentMonth
934
938
  ].map(word);
935
939
  }
936
940
  function validateCancelCreditRequest(c, p) {
@@ -1654,7 +1658,8 @@ async function verifyCreditCommitment(params) {
1654
1658
  params.amount,
1655
1659
  params.nonce,
1656
1660
  params.expiry,
1657
- await computeCreditSharedKeyHash(params.creditSharedKey)
1661
+ await computeCreditSharedKeyHash(params.creditSharedKey),
1662
+ params
1658
1663
  );
1659
1664
  return BigInt(expected) === BigInt(params.creditCommitment);
1660
1665
  }
@@ -1696,6 +1701,8 @@ async function buildWithdrawalCalldata(p) {
1696
1701
  // src/witness.ts
1697
1702
  import {
1698
1703
  computeCreditCommitment as computeCreditCommitment2,
1704
+ normalizeCreditPolicy,
1705
+ applyCreditDrawUsage,
1699
1706
  computeCreditNullifier,
1700
1707
  computeCreditSharedKeyHash as computeCreditSharedKeyHash2,
1701
1708
  computeNoteCommitment as computeNoteCommitment4,
@@ -2230,9 +2237,9 @@ var witness_layouts_default = {
2230
2237
  ]
2231
2238
  },
2232
2239
  create_credit: {
2233
- artifactSha256: "078c6d2da1ed2d6bd27fab28af9970261fe626a0b22ae56ad170e5d15b1b05ba",
2240
+ artifactSha256: "3ed6cfdee4f5fd840f023580f76c208768777fea79737f2511377e5c55be0230",
2234
2241
  keys: {
2235
- evm: "8285456447e92833a4fa9c330b9c667a3a1b9e48649578082041b9738f037c8f"
2242
+ evm: "56f663c6053be0d158a271022d200c732597efd3a2e0be48fe94549d0b1795e0"
2236
2243
  },
2237
2244
  publicInputCount: 46,
2238
2245
  public: [
@@ -2347,16 +2354,19 @@ var witness_layouts_default = {
2347
2354
  "credit_amount",
2348
2355
  "credit_nonce",
2349
2356
  "credit_shared_key",
2357
+ "single_limit",
2358
+ "daily_limit",
2359
+ "monthly_limit",
2350
2360
  "change_amount",
2351
2361
  "change_nonce"
2352
2362
  ]
2353
2363
  },
2354
2364
  credit_draw_slots1: {
2355
- artifactSha256: "2b9da9d3d1dbd411d9be1bbe2b34305ac5dce7c7d18e3857d8e2be7dd9bf7c21",
2365
+ artifactSha256: "4542b227e0552b45c302f1dace21cadeba4962c96244e021472f1f7531cff8d1",
2356
2366
  keys: {
2357
- evm: "613699a440f50a0937e4c57e5152b5fdea42c31b10157d6b93226fef313df553"
2367
+ evm: "43c051a2bedf9454c12e70b10156361e414944823ba23e80662c16c7ced0a2ce"
2358
2368
  },
2359
- publicInputCount: 18,
2369
+ publicInputCount: 20,
2360
2370
  public: [
2361
2371
  {
2362
2372
  name: "chain_id",
@@ -2438,6 +2448,16 @@ var witness_layouts_default = {
2438
2448
  count: 1,
2439
2449
  array: true
2440
2450
  },
2451
+ {
2452
+ name: "current_day",
2453
+ count: 1,
2454
+ array: false
2455
+ },
2456
+ {
2457
+ name: "current_month",
2458
+ count: 1,
2459
+ array: false
2460
+ },
2441
2461
  {
2442
2462
  name: "auth_digest_high",
2443
2463
  count: 1,
@@ -2462,15 +2482,22 @@ var witness_layouts_default = {
2462
2482
  "leaf_indices",
2463
2483
  "merkle_paths",
2464
2484
  "input_source_indices",
2465
- "draw_amounts"
2485
+ "draw_amounts",
2486
+ "single_limits",
2487
+ "daily_limits",
2488
+ "monthly_limits",
2489
+ "last_days",
2490
+ "daily_spents",
2491
+ "last_months",
2492
+ "monthly_spents"
2466
2493
  ]
2467
2494
  },
2468
2495
  credit_draw_slots12: {
2469
- artifactSha256: "92b741e161a99c05b8810bc24cee6bafc1cebc85347ea47fe511ee6c8f7065be",
2496
+ artifactSha256: "dd72b0867fc3be7cd90de263bd2d0892075cb18eb4f6dd671b13111710f10369",
2470
2497
  keys: {
2471
- evm: "a5ae214784fe6e523977ef4e283a6d217fc3f4ec0c5a40effb275693a74ee5ce"
2498
+ evm: "5e31d771e6294993736078596d9c69f21fe7595eda50e3cce6d7406b65cf1443"
2472
2499
  },
2473
- publicInputCount: 84,
2500
+ publicInputCount: 86,
2474
2501
  public: [
2475
2502
  {
2476
2503
  name: "chain_id",
@@ -2552,6 +2579,16 @@ var witness_layouts_default = {
2552
2579
  count: 12,
2553
2580
  array: true
2554
2581
  },
2582
+ {
2583
+ name: "current_day",
2584
+ count: 1,
2585
+ array: false
2586
+ },
2587
+ {
2588
+ name: "current_month",
2589
+ count: 1,
2590
+ array: false
2591
+ },
2555
2592
  {
2556
2593
  name: "auth_digest_high",
2557
2594
  count: 1,
@@ -2576,15 +2613,22 @@ var witness_layouts_default = {
2576
2613
  "leaf_indices",
2577
2614
  "merkle_paths",
2578
2615
  "input_source_indices",
2579
- "draw_amounts"
2616
+ "draw_amounts",
2617
+ "single_limits",
2618
+ "daily_limits",
2619
+ "monthly_limits",
2620
+ "last_days",
2621
+ "daily_spents",
2622
+ "last_months",
2623
+ "monthly_spents"
2580
2624
  ]
2581
2625
  },
2582
2626
  credit_draw_slots50: {
2583
- artifactSha256: "9c6a23d5dbca3a1aeed461c908f228e89642550775cbc519d633bb1c984a3d04",
2627
+ artifactSha256: "09c7469866748b4c0c4bbf2b040844771948a170999f6dc7a38fe5c0ecda4054",
2584
2628
  keys: {
2585
- evm: "f0b192e2cb312148c7a16fae3acaed9efb01b0c6a1b381ce03468f00b4ef0f2a"
2629
+ evm: "7b613225b6f32a077011d4196c356e836d22dcd116efe687fde53144fbd8db9f"
2586
2630
  },
2587
- publicInputCount: 312,
2631
+ publicInputCount: 314,
2588
2632
  public: [
2589
2633
  {
2590
2634
  name: "chain_id",
@@ -2666,6 +2710,16 @@ var witness_layouts_default = {
2666
2710
  count: 50,
2667
2711
  array: true
2668
2712
  },
2713
+ {
2714
+ name: "current_day",
2715
+ count: 1,
2716
+ array: false
2717
+ },
2718
+ {
2719
+ name: "current_month",
2720
+ count: 1,
2721
+ array: false
2722
+ },
2669
2723
  {
2670
2724
  name: "auth_digest_high",
2671
2725
  count: 1,
@@ -2690,15 +2744,22 @@ var witness_layouts_default = {
2690
2744
  "leaf_indices",
2691
2745
  "merkle_paths",
2692
2746
  "input_source_indices",
2693
- "draw_amounts"
2747
+ "draw_amounts",
2748
+ "single_limits",
2749
+ "daily_limits",
2750
+ "monthly_limits",
2751
+ "last_days",
2752
+ "daily_spents",
2753
+ "last_months",
2754
+ "monthly_spents"
2694
2755
  ]
2695
2756
  },
2696
2757
  credit_draw_slots120: {
2697
- artifactSha256: "69686a4f0a8a98d8cef06485b0de1804ca2e8f47ce0244287a03ceef4d67625a",
2758
+ artifactSha256: "6ccd0366a669c50fd5da875c3eae194fe8aa4c36d35a5f9ebfd64636ea599b48",
2698
2759
  keys: {
2699
- evm: "6f32ca89775f332a9193af9b1e25641ef14fda9fbdd2685c33ee775d3c170b92"
2760
+ evm: "d715848afc5c1ecdfcef5ed5026865abef5040a3bc232fd65330a5ffee8475fb"
2700
2761
  },
2701
- publicInputCount: 732,
2762
+ publicInputCount: 734,
2702
2763
  public: [
2703
2764
  {
2704
2765
  name: "chain_id",
@@ -2780,6 +2841,16 @@ var witness_layouts_default = {
2780
2841
  count: 120,
2781
2842
  array: true
2782
2843
  },
2844
+ {
2845
+ name: "current_day",
2846
+ count: 1,
2847
+ array: false
2848
+ },
2849
+ {
2850
+ name: "current_month",
2851
+ count: 1,
2852
+ array: false
2853
+ },
2783
2854
  {
2784
2855
  name: "auth_digest_high",
2785
2856
  count: 1,
@@ -2804,13 +2875,20 @@ var witness_layouts_default = {
2804
2875
  "leaf_indices",
2805
2876
  "merkle_paths",
2806
2877
  "input_source_indices",
2807
- "draw_amounts"
2878
+ "draw_amounts",
2879
+ "single_limits",
2880
+ "daily_limits",
2881
+ "monthly_limits",
2882
+ "last_days",
2883
+ "daily_spents",
2884
+ "last_months",
2885
+ "monthly_spents"
2808
2886
  ]
2809
2887
  },
2810
2888
  credit_cancel: {
2811
- artifactSha256: "ff278a04f22d2886c9f27f7785a0b8fc317dd242fd4aa9d0d9398d18b7513daf",
2889
+ artifactSha256: "b4459c2cf756d096e37291cf4d7cd129866b6d420b6d03c928f383b057112ccb",
2812
2890
  keys: {
2813
- evm: "1f8a3c20cb081d6a90962556da3124919cc4e5675e59ad31562af39299da02fb"
2891
+ evm: "fc8ad196ef15f3328afcc8f01d867a3ebefd15451c2813948442fab1923b73b2"
2814
2892
  },
2815
2893
  publicInputCount: 11,
2816
2894
  public: [
@@ -2880,14 +2958,21 @@ var witness_layouts_default = {
2880
2958
  "input_nonce",
2881
2959
  "expiry",
2882
2960
  "credit_shared_key",
2961
+ "single_limit",
2962
+ "daily_limit",
2963
+ "monthly_limit",
2964
+ "last_day",
2965
+ "daily_spent",
2966
+ "last_month",
2967
+ "monthly_spent",
2883
2968
  "leaf_index",
2884
2969
  "merkle_path"
2885
2970
  ]
2886
2971
  },
2887
2972
  credit_top_up: {
2888
- artifactSha256: "fbe662363d9814983f7940f74369117cd6c84783945fbf527b0ed48d011b58a4",
2973
+ artifactSha256: "2ffebd5753ec1b0c050204d4f97498765fe61ea01a793a9b2466c2f97536345c",
2889
2974
  keys: {
2890
- evm: "44436f31414497a708355426da051ee48ba63fdebcb6cfd72347c37c34c98c50"
2975
+ evm: "40b02a9d2e7eb7b49daaac4b7760328537b7982fd5a225cc065bb74cd5ef44b3"
2891
2976
  },
2892
2977
  publicInputCount: 50,
2893
2978
  public: [
@@ -3022,6 +3107,16 @@ var witness_layouts_default = {
3022
3107
  "credit_amount",
3023
3108
  "credit_nonce",
3024
3109
  "credit_shared_key",
3110
+ "single_limit",
3111
+ "daily_limit",
3112
+ "monthly_limit",
3113
+ "previous_single_limit",
3114
+ "previous_daily_limit",
3115
+ "previous_monthly_limit",
3116
+ "last_day",
3117
+ "daily_spent",
3118
+ "last_month",
3119
+ "monthly_spent",
3025
3120
  "change_amount",
3026
3121
  "change_nonce",
3027
3122
  "previous_credit_amount",
@@ -3037,6 +3132,20 @@ var pad2 = (values, count, zero) => {
3037
3132
  if (values.length > count) throw new Error("witness capacity exceeded");
3038
3133
  return [...values, ...Array.from({ length: count - values.length }, zero)];
3039
3134
  };
3135
+ var policyWitness = (note, usage = true) => {
3136
+ const p = normalizeCreditPolicy(note);
3137
+ return {
3138
+ single_limit: p.singleLimit,
3139
+ daily_limit: p.dailyLimit,
3140
+ monthly_limit: p.monthlyLimit,
3141
+ ...usage ? {
3142
+ last_day: p.lastDay,
3143
+ daily_spent: p.dailySpent,
3144
+ last_month: p.lastMonth,
3145
+ monthly_spent: p.monthlySpent
3146
+ } : {}
3147
+ };
3148
+ };
3040
3149
  var zeros = () => Array(16).fill(0n);
3041
3150
  var zeroAuthority = () => ({
3042
3151
  public_key_x: Array(32).fill(0),
@@ -3165,7 +3274,8 @@ var WitnessBuilder = class {
3165
3274
  note.amount,
3166
3275
  note.nonce,
3167
3276
  note.expiry,
3168
- await computeCreditSharedKeyHash2(note.creditSharedKey)
3277
+ await computeCreditSharedKeyHash2(note.creditSharedKey),
3278
+ note
3169
3279
  );
3170
3280
  }
3171
3281
  async noteInputs(inputs, sources, nullifiers, identity, authority) {
@@ -3249,6 +3359,8 @@ var WitnessBuilder = class {
3249
3359
  await this.creditLeaf(note) === p.params.creditCommitment && note.ownerPayout === BigInt(p.params.owner) && note.expiry === p.params.expiry,
3250
3360
  "Credit creation mismatch"
3251
3361
  );
3362
+ if (operation === "create-credit" && [note.lastDay, note.dailySpent, note.lastMonth, note.monthlySpent].some((v) => v !== 0n))
3363
+ throw new Error("new Credit usage must be zero");
3252
3364
  const authority = await this.authority(
3253
3365
  operation,
3254
3366
  10,
@@ -3295,6 +3407,7 @@ var WitnessBuilder = class {
3295
3407
  spender_payout: note.spenderPayout,
3296
3408
  spender_wallet_identity: BigInt(note.spenderWalletIdentity),
3297
3409
  owner_wallet_identity: BigInt(note.ownerWalletIdentity),
3410
+ ...policyWitness(note, operation === "top-up-credit"),
3298
3411
  credit_amount: note.amount,
3299
3412
  credit_nonce: note.nonce,
3300
3413
  credit_shared_key: note.creditSharedKey,
@@ -3336,6 +3449,7 @@ var WitnessBuilder = class {
3336
3449
  spender_payout: note.spenderPayout,
3337
3450
  spender_wallet_identity: BigInt(note.spenderWalletIdentity),
3338
3451
  owner_wallet_identity: BigInt(note.ownerWalletIdentity),
3452
+ ...policyWitness(note),
3339
3453
  input_nonce: note.nonce,
3340
3454
  expiry: note.expiry,
3341
3455
  credit_shared_key: note.creditSharedKey,
@@ -3346,7 +3460,7 @@ var WitnessBuilder = class {
3346
3460
  );
3347
3461
  }
3348
3462
  async drawCredit(p) {
3349
- const c = this.#protocol.context, profile = selectCreditDrawCircuit(p.inputs.length), capacity = profile.maxSize;
3463
+ const c = { ...this.#protocol.context, timestamp: p.timestamp }, profile = selectCreditDrawCircuit(p.inputs.length), capacity = profile.maxSize;
3350
3464
  check2(
3351
3465
  p.inputs.length === p.amounts.length && p.inputs.length === p.params.nullifiers.length,
3352
3466
  "draw input count mismatch"
@@ -3361,6 +3475,7 @@ var WitnessBuilder = class {
3361
3475
  );
3362
3476
  const sourceIndices = await Promise.all(
3363
3477
  notes2.map(async (note, i) => {
3478
+ applyCreditDrawUsage(note, p.amounts[i], p.timestamp);
3364
3479
  const leaf = await this.creditLeaf(note);
3365
3480
  check2(
3366
3481
  note.spenderWalletIdentity === identity && note.spenderPayout === BigInt(p.params.spender) && note.expiry === p.params.expiries[i] && p.amounts[i] > 0n && p.amounts[i] <= note.amount && await computeCreditNullifier(c.chainId, note.creditSharedKey, leaf) === p.params.nullifiers[i],
@@ -3373,6 +3488,26 @@ var WitnessBuilder = class {
3373
3488
  profile.name,
3374
3489
  {
3375
3490
  ...authority,
3491
+ ...Object.fromEntries(
3492
+ Object.entries({
3493
+ singleLimit: "single_limits",
3494
+ dailyLimit: "daily_limits",
3495
+ monthlyLimit: "monthly_limits",
3496
+ lastDay: "last_days",
3497
+ dailySpent: "daily_spents",
3498
+ lastMonth: "last_months",
3499
+ monthlySpent: "monthly_spents"
3500
+ }).map(([key, name]) => [
3501
+ name,
3502
+ pad2(
3503
+ notes2.map(
3504
+ (note) => normalizeCreditPolicy(note)[key]
3505
+ ),
3506
+ capacity,
3507
+ () => 0n
3508
+ )
3509
+ ])
3510
+ ),
3376
3511
  spender_wallet_identity: BigInt(identity),
3377
3512
  owner_payouts: pad2(
3378
3513
  notes2.map((note) => note.ownerPayout),
@@ -3422,7 +3557,11 @@ var WitnessBuilder = class {
3422
3557
  "ownerWalletIdentity",
3423
3558
  "spenderPayout",
3424
3559
  "ownerPayout",
3425
- "creditSharedKey"
3560
+ "creditSharedKey",
3561
+ "lastDay",
3562
+ "dailySpent",
3563
+ "lastMonth",
3564
+ "monthlySpent"
3426
3565
  ])
3427
3566
  check2(old[field2] === note[field2], "Credit role or payout changed");
3428
3567
  check2(
@@ -3443,6 +3582,9 @@ var WitnessBuilder = class {
3443
3582
  "credit_top_up",
3444
3583
  {
3445
3584
  ...base,
3585
+ previous_single_limit: old.singleLimit,
3586
+ previous_daily_limit: old.dailyLimit,
3587
+ previous_monthly_limit: old.monthlyLimit,
3446
3588
  previous_credit_amount: old.amount,
3447
3589
  previous_credit_nonce: old.nonce,
3448
3590
  previous_credit_leaf_index: BigInt(p.previous.leafIndex),