@invisi-labs/protocol 1.1.2 → 1.1.4

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.cjs CHANGED
@@ -43,7 +43,6 @@ __export(src_exports, {
43
43
  buildTopUpCreditCalldata: () => buildTopUpCreditCalldata,
44
44
  buildTransactAggregateCalldata: () => buildTransactAggregateCalldata,
45
45
  buildTransactCalldata: () => buildTransactCalldata,
46
- buildWithdrawalCalldata: () => buildWithdrawalCalldata,
47
46
  cancelCreditBaseInputs: () => cancelCreditBaseInputs,
48
47
  cancelCreditPublicInputs: () => cancelCreditPublicInputs,
49
48
  cancelCreditRequestHash: () => cancelCreditRequestHash,
@@ -73,8 +72,8 @@ __export(src_exports, {
73
72
  getEIP712Domain: () => getEIP712Domain,
74
73
  known: () => known,
75
74
  normalizeContext: () => normalizeContext,
76
- normalizeDelivery: () => normalizeDelivery,
77
75
  normalizeFunding: () => normalizeFunding,
76
+ normalizeOpaqueDelivery: () => normalizeOpaqueDelivery,
78
77
  normalizeSources: () => normalizeSources,
79
78
  normalizeTransactRequest: () => normalizeTransactRequest,
80
79
  notes: () => notes,
@@ -3943,27 +3942,20 @@ var RegistrationOperation = class _RegistrationOperation {
3943
3942
  update: this.#plan.update
3944
3943
  };
3945
3944
  }
3946
- /** Sign with ethers, or attach externally obtained ERC-1271 signature bytes. */
3947
- async authorize(options = {}) {
3945
+ /** Export portable EIP-712 data for external signing. */
3946
+ async exportRegistrationAuthorization(options = {}) {
3947
+ check(this.status === "prepared", "registry operation is not awaiting authorization");
3948
+ options.signal?.throwIfAborted();
3949
+ await this.validateFreshness();
3950
+ options.signal?.throwIfAborted();
3951
+ return (0, import_core2.createSigningRequest)(this.typedData());
3952
+ }
3953
+ /** Validate and attach an independently obtained EOA or ERC-1271 signature. */
3954
+ async withSignature(signature, options = {}) {
3948
3955
  check(this.status === "prepared", "registry operation is not awaiting authorization");
3949
3956
  options.signal?.throwIfAborted();
3950
3957
  await this.validateFreshness();
3951
3958
  options.signal?.throwIfAborted();
3952
- let signature = options.signature;
3953
- if (signature === void 0) {
3954
- const signer = this.#runtime.signer;
3955
- check(signer, "registry signer capability is missing");
3956
- check(
3957
- BigInt(await signer.getAddress()) === BigInt(this.#plan.registration.walletIdentity),
3958
- "registry signer does not match wallet owner"
3959
- );
3960
- const typed = this.typedData();
3961
- signature = await signer.signTypedData(
3962
- typed.domain,
3963
- typed.types,
3964
- typed.message
3965
- );
3966
- }
3967
3959
  check(
3968
3960
  /^0x(?:[a-fA-F0-9]{2})+$/.test(signature),
3969
3961
  "registry signature must be nonempty hexadecimal bytes"
@@ -4220,9 +4212,10 @@ var AddressRegistry = class {
4220
4212
 
4221
4213
  // src/credit-create.ts
4222
4214
  var import_ethers5 = require("ethers");
4223
- var import_core4 = require("@invisi-labs/core");
4215
+ var import_core5 = require("@invisi-labs/core");
4224
4216
 
4225
4217
  // src/validation.ts
4218
+ var import_core4 = require("@invisi-labs/core");
4226
4219
  var import_ethers4 = require("ethers");
4227
4220
  var FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
4228
4221
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
@@ -4309,19 +4302,14 @@ var pad = (v, n) => [
4309
4302
  ...v,
4310
4303
  ...Array(n - v.length).fill(0n)
4311
4304
  ];
4312
- function normalizeDelivery(value, options = {}) {
4305
+ function normalizeOpaqueDelivery(value, options = {}) {
4313
4306
  known(value, ["ciphertext", "clue"], "delivery");
4314
4307
  if (options.empty) {
4315
4308
  if (value.ciphertext !== "0x" || value.clue !== "0x")
4316
4309
  throw new Error("absent output requires an empty delivery");
4317
4310
  return { ciphertext: "0x", clue: "0x" };
4318
4311
  }
4319
- const ciphertext = envelope(
4320
- value.ciphertext,
4321
- options.credit ? 402 : 160,
4322
- options.credit ? 4 : 2,
4323
- options.credit ? 658 : 416
4324
- );
4312
+ const ciphertext = envelope(value.ciphertext, 1, void 0, import_core4.MAX_CIPHERTEXT_BYTES);
4325
4313
  const clue = envelope(value.clue, 68);
4326
4314
  if (clue.slice(130, 132).toLowerCase() !== "18") throw new Error("clue precision must be 24");
4327
4315
  return { ciphertext, clue };
@@ -4404,7 +4392,7 @@ function validateCreateCreditRequest(c, p, cs, funding = {}) {
4404
4392
  throw new Error("owner must be nonzero and expiry future");
4405
4393
  if (dense(cs, "deliveries").length !== 3) throw new Error("deliveries count mismatch");
4406
4394
  const deliveries = cs.map(
4407
- (v, i) => normalizeDelivery(v, { credit: i < 2, empty: i === 2 && BigInt(changeCommitment) === 0n })
4395
+ (v, i) => normalizeOpaqueDelivery(v, { empty: i === 2 && BigInt(changeCommitment) === 0n })
4408
4396
  );
4409
4397
  if (ns.length === 0 && f.amount === 0n)
4410
4398
  throw new Error("empty inputs require positive funding");
@@ -4454,7 +4442,7 @@ function createCreditBaseInputs(c, p, cs, f = {}) {
4454
4442
  function createCreditPublicInputs(c, p, deliveries, funding = {}) {
4455
4443
  const base = createCreditBaseInputs(c, p, deliveries, funding);
4456
4444
  const digest = BigInt(
4457
- (0, import_core4.computeWalletAuthorizationDigest)({
4445
+ (0, import_core5.computeWalletAuthorizationDigest)({
4458
4446
  context: { chainId: c.chainId, protocolAddress: BigInt(c.protocolAddress) },
4459
4447
  operation: "create-credit",
4460
4448
  capacity: 10,
@@ -4490,7 +4478,7 @@ function createCreditRequestHash(p, cs, f = {}) {
4490
4478
  );
4491
4479
  }
4492
4480
  function encodeCreateCreditTypedData(c, p, deliveries, funding = {}) {
4493
- return (0, import_core4.walletAuthorizationTypedData)({
4481
+ return (0, import_core5.walletAuthorizationTypedData)({
4494
4482
  context: { chainId: c.chainId, protocolAddress: BigInt(c.protocolAddress) },
4495
4483
  operation: "create-credit",
4496
4484
  capacity: 10,
@@ -4537,7 +4525,7 @@ function encodeCreditProof(proof) {
4537
4525
 
4538
4526
  // src/credit-lifecycle.ts
4539
4527
  var import_ethers6 = require("ethers");
4540
- var import_core5 = require("@invisi-labs/core");
4528
+ var import_core6 = require("@invisi-labs/core");
4541
4529
  var CREDIT_DRAW_CAPACITIES = [1, 12, 50, 120];
4542
4530
  function selectCreditDrawCircuit(count) {
4543
4531
  if (!Number.isInteger(count) || count < 1 || count > 120)
@@ -4546,7 +4534,7 @@ function selectCreditDrawCircuit(count) {
4546
4534
  return {
4547
4535
  name: `credit_draw_slots${maxSize}`,
4548
4536
  maxSize,
4549
- publicInputCount: 6 * maxSize + 12,
4537
+ publicInputCount: 6 * maxSize + 14,
4550
4538
  totalBits: 126 + Math.ceil(Math.log2(maxSize))
4551
4539
  };
4552
4540
  }
@@ -4586,7 +4574,7 @@ function validateCreditDrawRequest(c, p, cs) {
4586
4574
  if (dense(cs, "deliveries").length !== 2 * ns.length)
4587
4575
  throw new Error("deliveries count mismatch");
4588
4576
  const deliveries = cs.map(
4589
- (v, i) => BigInt(remainderCommitments[Math.floor(i / 2)]) === 0n ? normalizeDelivery(v, { empty: true }) : normalizeDelivery(v, { credit: true })
4577
+ (v, i) => BigInt(remainderCommitments[Math.floor(i / 2)]) === 0n ? normalizeOpaqueDelivery(v, { empty: true }) : normalizeOpaqueDelivery(v, {})
4590
4578
  );
4591
4579
  return {
4592
4580
  ...ctx,
@@ -4599,7 +4587,8 @@ function validateCreditDrawRequest(c, p, cs) {
4599
4587
  totalAmount,
4600
4588
  deadline: checkDeadline(c, p.deadline),
4601
4589
  deliveries,
4602
- profile
4590
+ profile,
4591
+ periods: (0, import_core6.creditPeriods)(c.timestamp)
4603
4592
  };
4604
4593
  }
4605
4594
  function creditDrawBaseInputs(c, p, cs) {
@@ -4626,7 +4615,9 @@ function creditDrawBaseInputs(c, p, cs) {
4626
4615
  r.deadline,
4627
4616
  h >> 128n,
4628
4617
  h & (1n << 128n) - 1n,
4629
- ...pad(r.recoveryAmounts.map(BigInt), n)
4618
+ ...pad(r.recoveryAmounts.map(BigInt), n),
4619
+ r.periods.currentDay,
4620
+ r.periods.currentMonth
4630
4621
  ].map(word);
4631
4622
  }
4632
4623
  function validateCancelCreditRequest(c, p) {
@@ -4725,7 +4716,7 @@ function topUpCreditRequestHash(p, cs, f = {}) {
4725
4716
  );
4726
4717
  }
4727
4718
  function authorize(c, operation, capacity, words) {
4728
- return (0, import_core5.walletAuthorizationTypedData)({
4719
+ return (0, import_core6.walletAuthorizationTypedData)({
4729
4720
  context: { chainId: c.chainId, protocolAddress: BigInt(c.protocolAddress) },
4730
4721
  operation,
4731
4722
  capacity,
@@ -4734,7 +4725,7 @@ function authorize(c, operation, capacity, words) {
4734
4725
  }
4735
4726
  function appendDigest(c, operation, capacity, words) {
4736
4727
  const digest = BigInt(
4737
- (0, import_core5.computeWalletAuthorizationDigest)({
4728
+ (0, import_core6.computeWalletAuthorizationDigest)({
4738
4729
  context: { chainId: c.chainId, protocolAddress: BigInt(c.protocolAddress) },
4739
4730
  operation,
4740
4731
  capacity,
@@ -4824,7 +4815,7 @@ function buildTopUpCreditCalldata(p) {
4824
4815
 
4825
4816
  // src/funds.ts
4826
4817
  var import_ethers7 = require("ethers");
4827
- var import_core6 = require("@invisi-labs/core");
4818
+ var import_core7 = require("@invisi-labs/core");
4828
4819
  var TRANSACT_CAPACITIES = [14, 56, 112, 168];
4829
4820
  function selectTransactCapacity(inputs, outputs) {
4830
4821
  if (!Number.isInteger(inputs) || !Number.isInteger(outputs) || inputs < 0 || outputs < 0 || inputs + outputs < 1 || inputs === 0 && outputs < 2 || inputs + outputs > 168)
@@ -4845,7 +4836,7 @@ function normalizeTransactRequest(c, p, cs, funding = {}) {
4845
4836
  "deadline"
4846
4837
  ]);
4847
4838
  const ns = notes(p.nullifiers, "nullifiers"), os = notes(p.outputCommitments, "outputCommitments"), capacity = selectTransactCapacity(ns.length, os.length);
4848
- const sources = normalizeSources(p.sources, ns.length, capacity), deliveries = dense(cs, "deliveries").map((v) => normalizeDelivery(v));
4839
+ const sources = normalizeSources(p.sources, ns.length, capacity), deliveries = dense(cs, "deliveries").map((v) => normalizeOpaqueDelivery(v));
4849
4840
  if (deliveries.length !== os.length) throw new Error("deliveries count mismatch");
4850
4841
  const withdrawalAmount = uint(p.withdrawalAmount, 128, "withdrawalAmount"), withdrawalAddress = (0, import_ethers7.getAddress)(p.withdrawalAddress), f = normalizeFunding(funding);
4851
4842
  if (withdrawalAmount === 0n !== (BigInt(withdrawalAddress) === 0n) || os.length === 0 && withdrawalAmount === 0n)
@@ -4903,7 +4894,7 @@ function transactPublicInputs(c, p, cs, f = {}) {
4903
4894
  }
4904
4895
  function encodeTransactTypedData(c, p, deliveries, f = {}) {
4905
4896
  const r = normalizeTransactRequest(c, p, deliveries, f);
4906
- return (0, import_core6.walletAuthorizationTypedData)({
4897
+ return (0, import_core7.walletAuthorizationTypedData)({
4907
4898
  context: { chainId: r.chainId, protocolAddress: BigInt(r.protocolAddress) },
4908
4899
  operation: "transact",
4909
4900
  capacity: r.capacity,
@@ -5024,8 +5015,8 @@ async function validateShieldRequest(p) {
5024
5015
  uint(o.amount, 128, "amount");
5025
5016
  if (o.amount === 0n) throw new Error("amount must be positive");
5026
5017
  field(o.identity);
5027
- normalizeDelivery(cs[i]);
5028
- if (await (0, import_core6.computeNoteCommitment)(
5018
+ normalizeOpaqueDelivery(cs[i]);
5019
+ if (await (0, import_core7.computeNoteCommitment)(
5029
5020
  p.context.chainId,
5030
5021
  o.identity,
5031
5022
  BigInt(p.context.tokenAddress),
@@ -5153,7 +5144,7 @@ var import_rpc = require("@invisi-labs/rpc");
5153
5144
 
5154
5145
  // src/TokenProtocol.ts
5155
5146
  var import_ethers8 = require("ethers");
5156
- var import_core7 = require("@invisi-labs/core");
5147
+ var import_core8 = require("@invisi-labs/core");
5157
5148
  var TokenProtocol = class {
5158
5149
  context;
5159
5150
  expectedRuntimeCodeHash;
@@ -5171,7 +5162,7 @@ var TokenProtocol = class {
5171
5162
  }
5172
5163
  async validateDeployment(reader, options = {}) {
5173
5164
  if ((options.requireRuntimeProfile ?? true) && !this.expectedRuntimeCodeHash) {
5174
- throw new import_core7.MissingCapabilityError("trusted deployment profile");
5165
+ throw new import_core8.MissingCapabilityError("trusted deployment profile");
5175
5166
  }
5176
5167
  if (await reader.getChainId() !== this.context.chainId) {
5177
5168
  throw new Error("deployment chain mismatch");
@@ -5319,20 +5310,20 @@ var Protocol = class _Protocol {
5319
5310
  };
5320
5311
 
5321
5312
  // src/verify.ts
5322
- var import_core8 = require("@invisi-labs/core");
5313
+ var import_core9 = require("@invisi-labs/core");
5323
5314
  async function verifyNoteCommitment(params) {
5324
- const expected = await (0, import_core8.computeNoteCommitment)(
5315
+ const expected = await (0, import_core9.computeNoteCommitment)(
5325
5316
  params.chainId,
5326
- await (0, import_core8.computeNoteIdentity)(BigInt(params.walletIdentity), BigInt(params.nonce)),
5317
+ await (0, import_core9.computeNoteIdentity)(BigInt(params.walletIdentity), BigInt(params.nonce)),
5327
5318
  BigInt(params.tokenAddress),
5328
5319
  params.amount
5329
5320
  );
5330
5321
  return BigInt(expected) === BigInt(params.noteCommitment);
5331
5322
  }
5332
5323
  async function verifyCreditCommitment(params) {
5333
- if (params.creditSharedKey <= 0n || params.creditSharedKey >= import_core8.FIELD_MODULUS)
5324
+ if (params.creditSharedKey <= 0n || params.creditSharedKey >= import_core9.FIELD_MODULUS)
5334
5325
  throw new RangeError("creditSharedKey must be a nonzero canonical Field");
5335
- const expected = await (0, import_core8.computeCreditCommitment)(
5326
+ const expected = await (0, import_core9.computeCreditCommitment)(
5336
5327
  params.chainId,
5337
5328
  params.spenderWalletIdentity,
5338
5329
  params.ownerWalletIdentity,
@@ -5342,41 +5333,12 @@ async function verifyCreditCommitment(params) {
5342
5333
  params.amount,
5343
5334
  params.nonce,
5344
5335
  params.expiry,
5345
- await (0, import_core8.computeCreditSharedKeyHash)(params.creditSharedKey)
5336
+ await (0, import_core9.computeCreditSharedKeyHash)(params.creditSharedKey),
5337
+ params
5346
5338
  );
5347
5339
  return BigInt(expected) === BigInt(params.creditCommitment);
5348
5340
  }
5349
5341
 
5350
- // src/withdrawal.ts
5351
- var import_core9 = require("@invisi-labs/core");
5352
- async function buildWithdrawalCalldata(p) {
5353
- const r = normalizeTransactRequest(p.context, p.params, [], p.funding);
5354
- if (r.outputCount !== 0 || r.depositAmount !== 0n || p.sourceNotes.length === 0 || p.sourceNotes.length !== r.inputCount) {
5355
- throw new Error("full withdrawal requires inputs, no private outputs and no funding");
5356
- }
5357
- const walletIdentity = BigInt(p.sourceNotes[0].walletIdentity);
5358
- let total = 0n;
5359
- for (const [index, note] of p.sourceNotes.entries()) {
5360
- if (note.chainId !== p.context.chainId || note.protocolAddress !== BigInt(p.context.protocolAddress))
5361
- throw new Error("source note context mismatch");
5362
- if (BigInt(note.walletIdentity) !== walletIdentity || note.tokenAddress !== BigInt(p.context.tokenAddress) || note.amount <= 0n)
5363
- throw new Error("source note wallet/token/amount mismatch");
5364
- const commitment = await (0, import_core9.computeNoteCommitment)(
5365
- note.chainId,
5366
- await (0, import_core9.computeNoteIdentity)(walletIdentity, note.nonce),
5367
- note.tokenAddress,
5368
- note.amount
5369
- );
5370
- const nullifier = await (0, import_core9.computeNoteNullifier)(note.chainId, note.nonce, commitment);
5371
- if (nullifier.toLowerCase() !== r.nullifiers[index].toLowerCase())
5372
- throw new Error("source note nullifier mismatch");
5373
- total += note.amount;
5374
- }
5375
- if (r.withdrawalAmount !== total)
5376
- throw new Error("withdrawal must equal the full input balance");
5377
- return buildTransactCalldata({ ...p, deliveries: [] });
5378
- }
5379
-
5380
5342
  // src/witness.ts
5381
5343
  var import_core10 = require("@invisi-labs/core");
5382
5344
  var import_prover = require("@invisi-labs/prover");
@@ -5901,9 +5863,9 @@ var witness_layouts_default = {
5901
5863
  ]
5902
5864
  },
5903
5865
  create_credit: {
5904
- artifactSha256: "078c6d2da1ed2d6bd27fab28af9970261fe626a0b22ae56ad170e5d15b1b05ba",
5866
+ artifactSha256: "3ed6cfdee4f5fd840f023580f76c208768777fea79737f2511377e5c55be0230",
5905
5867
  keys: {
5906
- evm: "8285456447e92833a4fa9c330b9c667a3a1b9e48649578082041b9738f037c8f"
5868
+ evm: "56f663c6053be0d158a271022d200c732597efd3a2e0be48fe94549d0b1795e0"
5907
5869
  },
5908
5870
  publicInputCount: 46,
5909
5871
  public: [
@@ -6018,16 +5980,19 @@ var witness_layouts_default = {
6018
5980
  "credit_amount",
6019
5981
  "credit_nonce",
6020
5982
  "credit_shared_key",
5983
+ "single_limit",
5984
+ "daily_limit",
5985
+ "monthly_limit",
6021
5986
  "change_amount",
6022
5987
  "change_nonce"
6023
5988
  ]
6024
5989
  },
6025
5990
  credit_draw_slots1: {
6026
- artifactSha256: "2b9da9d3d1dbd411d9be1bbe2b34305ac5dce7c7d18e3857d8e2be7dd9bf7c21",
5991
+ artifactSha256: "4542b227e0552b45c302f1dace21cadeba4962c96244e021472f1f7531cff8d1",
6027
5992
  keys: {
6028
- evm: "613699a440f50a0937e4c57e5152b5fdea42c31b10157d6b93226fef313df553"
5993
+ evm: "43c051a2bedf9454c12e70b10156361e414944823ba23e80662c16c7ced0a2ce"
6029
5994
  },
6030
- publicInputCount: 18,
5995
+ publicInputCount: 20,
6031
5996
  public: [
6032
5997
  {
6033
5998
  name: "chain_id",
@@ -6109,6 +6074,16 @@ var witness_layouts_default = {
6109
6074
  count: 1,
6110
6075
  array: true
6111
6076
  },
6077
+ {
6078
+ name: "current_day",
6079
+ count: 1,
6080
+ array: false
6081
+ },
6082
+ {
6083
+ name: "current_month",
6084
+ count: 1,
6085
+ array: false
6086
+ },
6112
6087
  {
6113
6088
  name: "auth_digest_high",
6114
6089
  count: 1,
@@ -6133,15 +6108,22 @@ var witness_layouts_default = {
6133
6108
  "leaf_indices",
6134
6109
  "merkle_paths",
6135
6110
  "input_source_indices",
6136
- "draw_amounts"
6111
+ "draw_amounts",
6112
+ "single_limits",
6113
+ "daily_limits",
6114
+ "monthly_limits",
6115
+ "last_days",
6116
+ "daily_spents",
6117
+ "last_months",
6118
+ "monthly_spents"
6137
6119
  ]
6138
6120
  },
6139
6121
  credit_draw_slots12: {
6140
- artifactSha256: "92b741e161a99c05b8810bc24cee6bafc1cebc85347ea47fe511ee6c8f7065be",
6122
+ artifactSha256: "dd72b0867fc3be7cd90de263bd2d0892075cb18eb4f6dd671b13111710f10369",
6141
6123
  keys: {
6142
- evm: "a5ae214784fe6e523977ef4e283a6d217fc3f4ec0c5a40effb275693a74ee5ce"
6124
+ evm: "5e31d771e6294993736078596d9c69f21fe7595eda50e3cce6d7406b65cf1443"
6143
6125
  },
6144
- publicInputCount: 84,
6126
+ publicInputCount: 86,
6145
6127
  public: [
6146
6128
  {
6147
6129
  name: "chain_id",
@@ -6223,6 +6205,16 @@ var witness_layouts_default = {
6223
6205
  count: 12,
6224
6206
  array: true
6225
6207
  },
6208
+ {
6209
+ name: "current_day",
6210
+ count: 1,
6211
+ array: false
6212
+ },
6213
+ {
6214
+ name: "current_month",
6215
+ count: 1,
6216
+ array: false
6217
+ },
6226
6218
  {
6227
6219
  name: "auth_digest_high",
6228
6220
  count: 1,
@@ -6247,15 +6239,22 @@ var witness_layouts_default = {
6247
6239
  "leaf_indices",
6248
6240
  "merkle_paths",
6249
6241
  "input_source_indices",
6250
- "draw_amounts"
6242
+ "draw_amounts",
6243
+ "single_limits",
6244
+ "daily_limits",
6245
+ "monthly_limits",
6246
+ "last_days",
6247
+ "daily_spents",
6248
+ "last_months",
6249
+ "monthly_spents"
6251
6250
  ]
6252
6251
  },
6253
6252
  credit_draw_slots50: {
6254
- artifactSha256: "9c6a23d5dbca3a1aeed461c908f228e89642550775cbc519d633bb1c984a3d04",
6253
+ artifactSha256: "09c7469866748b4c0c4bbf2b040844771948a170999f6dc7a38fe5c0ecda4054",
6255
6254
  keys: {
6256
- evm: "f0b192e2cb312148c7a16fae3acaed9efb01b0c6a1b381ce03468f00b4ef0f2a"
6255
+ evm: "7b613225b6f32a077011d4196c356e836d22dcd116efe687fde53144fbd8db9f"
6257
6256
  },
6258
- publicInputCount: 312,
6257
+ publicInputCount: 314,
6259
6258
  public: [
6260
6259
  {
6261
6260
  name: "chain_id",
@@ -6337,6 +6336,16 @@ var witness_layouts_default = {
6337
6336
  count: 50,
6338
6337
  array: true
6339
6338
  },
6339
+ {
6340
+ name: "current_day",
6341
+ count: 1,
6342
+ array: false
6343
+ },
6344
+ {
6345
+ name: "current_month",
6346
+ count: 1,
6347
+ array: false
6348
+ },
6340
6349
  {
6341
6350
  name: "auth_digest_high",
6342
6351
  count: 1,
@@ -6361,15 +6370,22 @@ var witness_layouts_default = {
6361
6370
  "leaf_indices",
6362
6371
  "merkle_paths",
6363
6372
  "input_source_indices",
6364
- "draw_amounts"
6373
+ "draw_amounts",
6374
+ "single_limits",
6375
+ "daily_limits",
6376
+ "monthly_limits",
6377
+ "last_days",
6378
+ "daily_spents",
6379
+ "last_months",
6380
+ "monthly_spents"
6365
6381
  ]
6366
6382
  },
6367
6383
  credit_draw_slots120: {
6368
- artifactSha256: "69686a4f0a8a98d8cef06485b0de1804ca2e8f47ce0244287a03ceef4d67625a",
6384
+ artifactSha256: "6ccd0366a669c50fd5da875c3eae194fe8aa4c36d35a5f9ebfd64636ea599b48",
6369
6385
  keys: {
6370
- evm: "6f32ca89775f332a9193af9b1e25641ef14fda9fbdd2685c33ee775d3c170b92"
6386
+ evm: "d715848afc5c1ecdfcef5ed5026865abef5040a3bc232fd65330a5ffee8475fb"
6371
6387
  },
6372
- publicInputCount: 732,
6388
+ publicInputCount: 734,
6373
6389
  public: [
6374
6390
  {
6375
6391
  name: "chain_id",
@@ -6451,6 +6467,16 @@ var witness_layouts_default = {
6451
6467
  count: 120,
6452
6468
  array: true
6453
6469
  },
6470
+ {
6471
+ name: "current_day",
6472
+ count: 1,
6473
+ array: false
6474
+ },
6475
+ {
6476
+ name: "current_month",
6477
+ count: 1,
6478
+ array: false
6479
+ },
6454
6480
  {
6455
6481
  name: "auth_digest_high",
6456
6482
  count: 1,
@@ -6475,13 +6501,20 @@ var witness_layouts_default = {
6475
6501
  "leaf_indices",
6476
6502
  "merkle_paths",
6477
6503
  "input_source_indices",
6478
- "draw_amounts"
6504
+ "draw_amounts",
6505
+ "single_limits",
6506
+ "daily_limits",
6507
+ "monthly_limits",
6508
+ "last_days",
6509
+ "daily_spents",
6510
+ "last_months",
6511
+ "monthly_spents"
6479
6512
  ]
6480
6513
  },
6481
6514
  credit_cancel: {
6482
- artifactSha256: "ff278a04f22d2886c9f27f7785a0b8fc317dd242fd4aa9d0d9398d18b7513daf",
6515
+ artifactSha256: "b4459c2cf756d096e37291cf4d7cd129866b6d420b6d03c928f383b057112ccb",
6483
6516
  keys: {
6484
- evm: "1f8a3c20cb081d6a90962556da3124919cc4e5675e59ad31562af39299da02fb"
6517
+ evm: "fc8ad196ef15f3328afcc8f01d867a3ebefd15451c2813948442fab1923b73b2"
6485
6518
  },
6486
6519
  publicInputCount: 11,
6487
6520
  public: [
@@ -6551,14 +6584,21 @@ var witness_layouts_default = {
6551
6584
  "input_nonce",
6552
6585
  "expiry",
6553
6586
  "credit_shared_key",
6587
+ "single_limit",
6588
+ "daily_limit",
6589
+ "monthly_limit",
6590
+ "last_day",
6591
+ "daily_spent",
6592
+ "last_month",
6593
+ "monthly_spent",
6554
6594
  "leaf_index",
6555
6595
  "merkle_path"
6556
6596
  ]
6557
6597
  },
6558
6598
  credit_top_up: {
6559
- artifactSha256: "fbe662363d9814983f7940f74369117cd6c84783945fbf527b0ed48d011b58a4",
6599
+ artifactSha256: "2ffebd5753ec1b0c050204d4f97498765fe61ea01a793a9b2466c2f97536345c",
6560
6600
  keys: {
6561
- evm: "44436f31414497a708355426da051ee48ba63fdebcb6cfd72347c37c34c98c50"
6601
+ evm: "40b02a9d2e7eb7b49daaac4b7760328537b7982fd5a225cc065bb74cd5ef44b3"
6562
6602
  },
6563
6603
  publicInputCount: 50,
6564
6604
  public: [
@@ -6693,6 +6733,16 @@ var witness_layouts_default = {
6693
6733
  "credit_amount",
6694
6734
  "credit_nonce",
6695
6735
  "credit_shared_key",
6736
+ "single_limit",
6737
+ "daily_limit",
6738
+ "monthly_limit",
6739
+ "previous_single_limit",
6740
+ "previous_daily_limit",
6741
+ "previous_monthly_limit",
6742
+ "last_day",
6743
+ "daily_spent",
6744
+ "last_month",
6745
+ "monthly_spent",
6696
6746
  "change_amount",
6697
6747
  "change_nonce",
6698
6748
  "previous_credit_amount",
@@ -6708,6 +6758,20 @@ var pad2 = (values, count, zero) => {
6708
6758
  if (values.length > count) throw new Error("witness capacity exceeded");
6709
6759
  return [...values, ...Array.from({ length: count - values.length }, zero)];
6710
6760
  };
6761
+ var policyWitness = (note, usage = true) => {
6762
+ const p = (0, import_core10.normalizeCreditPolicy)(note);
6763
+ return {
6764
+ single_limit: p.singleLimit,
6765
+ daily_limit: p.dailyLimit,
6766
+ monthly_limit: p.monthlyLimit,
6767
+ ...usage ? {
6768
+ last_day: p.lastDay,
6769
+ daily_spent: p.dailySpent,
6770
+ last_month: p.lastMonth,
6771
+ monthly_spent: p.monthlySpent
6772
+ } : {}
6773
+ };
6774
+ };
6711
6775
  var zeros = () => Array(16).fill(0n);
6712
6776
  var zeroAuthority = () => ({
6713
6777
  public_key_x: Array(32).fill(0),
@@ -6836,7 +6900,8 @@ var WitnessBuilder = class {
6836
6900
  note.amount,
6837
6901
  note.nonce,
6838
6902
  note.expiry,
6839
- await (0, import_core10.computeCreditSharedKeyHash)(note.creditSharedKey)
6903
+ await (0, import_core10.computeCreditSharedKeyHash)(note.creditSharedKey),
6904
+ note
6840
6905
  );
6841
6906
  }
6842
6907
  async noteInputs(inputs, sources, nullifiers, identity, authority) {
@@ -6920,6 +6985,8 @@ var WitnessBuilder = class {
6920
6985
  await this.creditLeaf(note) === p.params.creditCommitment && note.ownerPayout === BigInt(p.params.owner) && note.expiry === p.params.expiry,
6921
6986
  "Credit creation mismatch"
6922
6987
  );
6988
+ if (operation === "create-credit" && [note.lastDay, note.dailySpent, note.lastMonth, note.monthlySpent].some((v) => v !== 0n))
6989
+ throw new Error("new Credit usage must be zero");
6923
6990
  const authority = await this.authority(
6924
6991
  operation,
6925
6992
  10,
@@ -6966,6 +7033,7 @@ var WitnessBuilder = class {
6966
7033
  spender_payout: note.spenderPayout,
6967
7034
  spender_wallet_identity: BigInt(note.spenderWalletIdentity),
6968
7035
  owner_wallet_identity: BigInt(note.ownerWalletIdentity),
7036
+ ...policyWitness(note, operation === "top-up-credit"),
6969
7037
  credit_amount: note.amount,
6970
7038
  credit_nonce: note.nonce,
6971
7039
  credit_shared_key: note.creditSharedKey,
@@ -7007,6 +7075,7 @@ var WitnessBuilder = class {
7007
7075
  spender_payout: note.spenderPayout,
7008
7076
  spender_wallet_identity: BigInt(note.spenderWalletIdentity),
7009
7077
  owner_wallet_identity: BigInt(note.ownerWalletIdentity),
7078
+ ...policyWitness(note),
7010
7079
  input_nonce: note.nonce,
7011
7080
  expiry: note.expiry,
7012
7081
  credit_shared_key: note.creditSharedKey,
@@ -7017,7 +7086,7 @@ var WitnessBuilder = class {
7017
7086
  );
7018
7087
  }
7019
7088
  async drawCredit(p) {
7020
- const c = this.#protocol.context, profile = selectCreditDrawCircuit(p.inputs.length), capacity = profile.maxSize;
7089
+ const c = { ...this.#protocol.context, timestamp: p.timestamp }, profile = selectCreditDrawCircuit(p.inputs.length), capacity = profile.maxSize;
7021
7090
  check2(
7022
7091
  p.inputs.length === p.amounts.length && p.inputs.length === p.params.nullifiers.length,
7023
7092
  "draw input count mismatch"
@@ -7032,6 +7101,7 @@ var WitnessBuilder = class {
7032
7101
  );
7033
7102
  const sourceIndices = await Promise.all(
7034
7103
  notes2.map(async (note, i) => {
7104
+ (0, import_core10.applyCreditDrawUsage)(note, p.amounts[i], p.timestamp);
7035
7105
  const leaf = await this.creditLeaf(note);
7036
7106
  check2(
7037
7107
  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 (0, import_core10.computeCreditNullifier)(c.chainId, note.creditSharedKey, leaf) === p.params.nullifiers[i],
@@ -7044,6 +7114,26 @@ var WitnessBuilder = class {
7044
7114
  profile.name,
7045
7115
  {
7046
7116
  ...authority,
7117
+ ...Object.fromEntries(
7118
+ Object.entries({
7119
+ singleLimit: "single_limits",
7120
+ dailyLimit: "daily_limits",
7121
+ monthlyLimit: "monthly_limits",
7122
+ lastDay: "last_days",
7123
+ dailySpent: "daily_spents",
7124
+ lastMonth: "last_months",
7125
+ monthlySpent: "monthly_spents"
7126
+ }).map(([key, name]) => [
7127
+ name,
7128
+ pad2(
7129
+ notes2.map(
7130
+ (note) => (0, import_core10.normalizeCreditPolicy)(note)[key]
7131
+ ),
7132
+ capacity,
7133
+ () => 0n
7134
+ )
7135
+ ])
7136
+ ),
7047
7137
  spender_wallet_identity: BigInt(identity),
7048
7138
  owner_payouts: pad2(
7049
7139
  notes2.map((note) => note.ownerPayout),
@@ -7093,7 +7183,11 @@ var WitnessBuilder = class {
7093
7183
  "ownerWalletIdentity",
7094
7184
  "spenderPayout",
7095
7185
  "ownerPayout",
7096
- "creditSharedKey"
7186
+ "creditSharedKey",
7187
+ "lastDay",
7188
+ "dailySpent",
7189
+ "lastMonth",
7190
+ "monthlySpent"
7097
7191
  ])
7098
7192
  check2(old[field2] === note[field2], "Credit role or payout changed");
7099
7193
  check2(
@@ -7114,6 +7208,9 @@ var WitnessBuilder = class {
7114
7208
  "credit_top_up",
7115
7209
  {
7116
7210
  ...base,
7211
+ previous_single_limit: old.singleLimit,
7212
+ previous_daily_limit: old.dailyLimit,
7213
+ previous_monthly_limit: old.monthlyLimit,
7117
7214
  previous_credit_amount: old.amount,
7118
7215
  previous_credit_nonce: old.nonce,
7119
7216
  previous_credit_leaf_index: BigInt(p.previous.leafIndex),
@@ -7159,7 +7256,6 @@ async function resolveInstanceAddress(client, factoryAddress, salt) {
7159
7256
  buildTopUpCreditCalldata,
7160
7257
  buildTransactAggregateCalldata,
7161
7258
  buildTransactCalldata,
7162
- buildWithdrawalCalldata,
7163
7259
  cancelCreditBaseInputs,
7164
7260
  cancelCreditPublicInputs,
7165
7261
  cancelCreditRequestHash,
@@ -7189,8 +7285,8 @@ async function resolveInstanceAddress(client, factoryAddress, salt) {
7189
7285
  getEIP712Domain,
7190
7286
  known,
7191
7287
  normalizeContext,
7192
- normalizeDelivery,
7193
7288
  normalizeFunding,
7289
+ normalizeOpaqueDelivery,
7194
7290
  normalizeSources,
7195
7291
  normalizeTransactRequest,
7196
7292
  notes,