@invisi-labs/sdk 1.1.7 → 1.2.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.
Files changed (118) hide show
  1. package/README.md +5 -0
  2. package/dist/broadcaster-3KTB4JO2.cjs +21 -0
  3. package/dist/broadcaster-3KTB4JO2.cjs.map +1 -0
  4. package/dist/broadcaster-7ZKKSTZQ.js +21 -0
  5. package/dist/broadcaster-preparation-PJ263WBL.cjs +15 -0
  6. package/dist/broadcaster-preparation-PJ263WBL.cjs.map +1 -0
  7. package/dist/broadcaster-preparation-ZQAPZAUG.js +15 -0
  8. package/dist/broadcaster-preparation-ZQAPZAUG.js.map +1 -0
  9. package/dist/{chunk-LOU7AP2B.cjs → chunk-2URICDPW.cjs} +72 -33
  10. package/dist/chunk-2URICDPW.cjs.map +1 -0
  11. package/dist/chunk-3D24ABYR.js +86 -0
  12. package/dist/chunk-3D24ABYR.js.map +1 -0
  13. package/dist/chunk-3KTQQZOW.cjs +71 -0
  14. package/dist/chunk-3KTQQZOW.cjs.map +1 -0
  15. package/dist/chunk-4H4FARQK.js +1582 -0
  16. package/dist/chunk-4H4FARQK.js.map +1 -0
  17. package/dist/chunk-4SDP53YQ.cjs +765 -0
  18. package/dist/chunk-4SDP53YQ.cjs.map +1 -0
  19. package/dist/{chunk-XHKQ2BO2.js → chunk-4VI6LYGH.js} +25 -2
  20. package/dist/chunk-4VI6LYGH.js.map +1 -0
  21. package/dist/chunk-BBSRP4MH.cjs +287 -0
  22. package/dist/chunk-BBSRP4MH.cjs.map +1 -0
  23. package/dist/chunk-DGMVGFKM.js +41 -0
  24. package/dist/chunk-DGMVGFKM.js.map +1 -0
  25. package/dist/chunk-GUD3LAUO.js +765 -0
  26. package/dist/chunk-GUD3LAUO.js.map +1 -0
  27. package/dist/chunk-HCB7RQ3S.cjs +79 -0
  28. package/dist/chunk-HCB7RQ3S.cjs.map +1 -0
  29. package/dist/{chunk-GTPUYPQL.js → chunk-HKGJXQVN.js} +69 -30
  30. package/dist/chunk-HKGJXQVN.js.map +1 -0
  31. package/dist/chunk-HLH5JZD4.js +287 -0
  32. package/dist/chunk-HLH5JZD4.js.map +1 -0
  33. package/dist/chunk-J6TZZVAM.cjs +230 -0
  34. package/dist/chunk-J6TZZVAM.cjs.map +1 -0
  35. package/dist/{chunk-7F7ZZW3L.cjs → chunk-LOR6PYH5.cjs} +25 -2
  36. package/dist/chunk-LOR6PYH5.cjs.map +1 -0
  37. package/dist/chunk-MA2QZEF5.cjs +399 -0
  38. package/dist/chunk-MA2QZEF5.cjs.map +1 -0
  39. package/dist/chunk-MI4IP4ZD.cjs +86 -0
  40. package/dist/chunk-MI4IP4ZD.cjs.map +1 -0
  41. package/dist/chunk-NKYHYIRP.cjs +1582 -0
  42. package/dist/chunk-NKYHYIRP.cjs.map +1 -0
  43. package/dist/chunk-OCZLJKIA.cjs +41 -0
  44. package/dist/chunk-OCZLJKIA.cjs.map +1 -0
  45. package/dist/chunk-R5YAOJKB.js +71 -0
  46. package/dist/chunk-R5YAOJKB.js.map +1 -0
  47. package/dist/chunk-RY4M2CIQ.js +399 -0
  48. package/dist/chunk-RY4M2CIQ.js.map +1 -0
  49. package/dist/chunk-THMD5QO2.js +79 -0
  50. package/dist/chunk-THMD5QO2.js.map +1 -0
  51. package/dist/chunk-ZD2652WH.js +230 -0
  52. package/dist/chunk-ZD2652WH.js.map +1 -0
  53. package/dist/credit.cjs +1 -0
  54. package/dist/credit.cjs.map +1 -0
  55. package/dist/credit.d.cts +12 -0
  56. package/dist/credit.d.ts +12 -0
  57. package/dist/credit.js +1 -0
  58. package/dist/credit.js.map +1 -0
  59. package/dist/ethers.cjs +2 -2
  60. package/dist/ethers.cjs.map +1 -1
  61. package/dist/ethers.d.cts +15 -4
  62. package/dist/ethers.d.ts +15 -4
  63. package/dist/ethers.js +1 -1
  64. package/dist/index-CLhGwLxZ.d.cts +42 -0
  65. package/dist/index-Crp-ZFiM.d.ts +42 -0
  66. package/dist/index.cjs +64 -38
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.cts +21 -14
  69. package/dist/index.d.ts +21 -14
  70. package/dist/index.js +59 -33
  71. package/dist/index.js.map +1 -1
  72. package/dist/note.cjs +11 -0
  73. package/dist/note.cjs.map +1 -0
  74. package/dist/note.d.cts +29 -0
  75. package/dist/note.d.ts +29 -0
  76. package/dist/note.js +11 -0
  77. package/dist/note.js.map +1 -0
  78. package/dist/{broadcaster-preparation-DMxxZ_1Q.d.cts → operation-bridge-CoECSxfi.d.cts} +130 -245
  79. package/dist/{broadcaster-preparation-DMxxZ_1Q.d.ts → operation-bridge-CoECSxfi.d.ts} +130 -245
  80. package/dist/preparation-HUBTVCZE.js +404 -0
  81. package/dist/preparation-HUBTVCZE.js.map +1 -0
  82. package/dist/preparation-QD3ZSYV5.cjs +404 -0
  83. package/dist/preparation-QD3ZSYV5.cjs.map +1 -0
  84. package/dist/provenance-preparation-43DN2WK7.cjs +16 -0
  85. package/dist/provenance-preparation-43DN2WK7.cjs.map +1 -0
  86. package/dist/provenance-preparation-HEZE4L5H.js +16 -0
  87. package/dist/provenance-preparation-HEZE4L5H.js.map +1 -0
  88. package/dist/provenance.cjs +59 -0
  89. package/dist/provenance.cjs.map +1 -0
  90. package/dist/provenance.d.cts +34 -0
  91. package/dist/provenance.d.ts +34 -0
  92. package/dist/provenance.js +59 -0
  93. package/dist/provenance.js.map +1 -0
  94. package/dist/{receipt-logs-m0-bhaxW.d.ts → receipt-logs-8Msm_HZS.d.ts} +82 -78
  95. package/dist/{receipt-logs-CvC951p7.d.cts → receipt-logs-DWG4In8N.d.cts} +82 -78
  96. package/dist/session-support.cjs +28 -7
  97. package/dist/session-support.cjs.map +1 -1
  98. package/dist/session-support.d.cts +71 -39
  99. package/dist/session-support.d.ts +71 -39
  100. package/dist/session-support.js +58 -37
  101. package/dist/session-support.js.map +1 -1
  102. package/package.json +22 -6
  103. package/dist/broadcaster-preparation-RMWQFYNL.js +0 -11
  104. package/dist/broadcaster-preparation-UGOTO4SX.cjs +0 -11
  105. package/dist/broadcaster-preparation-UGOTO4SX.cjs.map +0 -1
  106. package/dist/chunk-7F7ZZW3L.cjs.map +0 -1
  107. package/dist/chunk-EHP5TBC6.js +0 -3565
  108. package/dist/chunk-EHP5TBC6.js.map +0 -1
  109. package/dist/chunk-GTPUYPQL.js.map +0 -1
  110. package/dist/chunk-ITTGBIG2.js +0 -1877
  111. package/dist/chunk-ITTGBIG2.js.map +0 -1
  112. package/dist/chunk-J2JH6HIG.cjs +0 -1877
  113. package/dist/chunk-J2JH6HIG.cjs.map +0 -1
  114. package/dist/chunk-LOU7AP2B.cjs.map +0 -1
  115. package/dist/chunk-RHNIHI4P.cjs +0 -3565
  116. package/dist/chunk-RHNIHI4P.cjs.map +0 -1
  117. package/dist/chunk-XHKQ2BO2.js.map +0 -1
  118. /package/dist/{broadcaster-preparation-RMWQFYNL.js.map → broadcaster-7ZKKSTZQ.js.map} +0 -0
@@ -0,0 +1,404 @@
1
+ import {
2
+ Preparation,
3
+ copyApplicationPayload,
4
+ creditLeaf,
5
+ positiveAmount,
6
+ recipientLookup
7
+ } from "./chunk-RY4M2CIQ.js";
8
+ import {
9
+ NoteOutput,
10
+ resolveRecipient
11
+ } from "./chunk-GUD3LAUO.js";
12
+ import "./chunk-4VI6LYGH.js";
13
+
14
+ // src/credit/preparation.ts
15
+ import { hexlify } from "ethers";
16
+ import {
17
+ computeCreditNullifier,
18
+ createClue,
19
+ encryptCreditState,
20
+ generateCreditSharedKey,
21
+ generateNonce,
22
+ normalizeCreditDeliveryState,
23
+ normalizeCreditPolicy,
24
+ deriveCreditState,
25
+ deriveCreditUpdate
26
+ } from "@invisi-labs/primitives";
27
+ import { WitnessBuilder } from "@invisi-labs/prover";
28
+ import {
29
+ normalizeFee,
30
+ encodeRevokeCreditTypedData,
31
+ createCreditPublicInputs,
32
+ creditDrawPublicInputs,
33
+ selectCreditDrawCircuit,
34
+ updateCreditPublicInputs,
35
+ word
36
+ } from "@invisi-labs/protocol";
37
+ var CreditPreparation = class {
38
+ constructor(runtime) {
39
+ this.runtime = runtime;
40
+ this.#prepare = new Preparation(runtime);
41
+ }
42
+ #prepare;
43
+ fee(options) {
44
+ return normalizeFee(
45
+ options.fee ? { feeRecipient: options.fee.recipient, feeAmount: options.fee.amount } : {}
46
+ );
47
+ }
48
+ expiry(value, frame) {
49
+ if (typeof value !== "bigint" || value <= frame.block.timestamp || value >= 1n << 64n) {
50
+ throw new Error("Credit expiry must be a future uint64 timestamp");
51
+ }
52
+ return value;
53
+ }
54
+ async seal(input, frame) {
55
+ const state = normalizeCreditDeliveryState(input);
56
+ const commitment = await creditLeaf(state);
57
+ const context = {
58
+ chainId: frame.context.chainId,
59
+ protocolAddress: BigInt(frame.context.protocolAddress),
60
+ outputCommitment: commitment
61
+ };
62
+ const deliveries = await Promise.all(
63
+ ["owner", "spender"].map(async (role) => {
64
+ const keys = role === "owner" ? state.ownerReceivingKeys : state.spenderReceivingKeys;
65
+ return {
66
+ ciphertext: hexlify(
67
+ await encryptCreditState(keys.viewingPublicKey, state, { ...context, role })
68
+ ),
69
+ clue: hexlify(createClue(keys.clueKey))
70
+ };
71
+ })
72
+ );
73
+ return { state, commitment, deliveries };
74
+ }
75
+ async input(commitment, role, frame) {
76
+ const stored = (await this.runtime.readInventory()).credits[commitment + ":" + role];
77
+ if (!stored || stored.spent !== "unspent" || stored.role !== role) {
78
+ throw new Error(`confirmed unspent ${role} Credit is unavailable`);
79
+ }
80
+ const state = normalizeCreditDeliveryState(stored.state);
81
+ const n = state.note;
82
+ if ((role === "owner" ? n.ownerWalletIdentity : n.spenderWalletIdentity) !== this.runtime.scope.ownerAddress || n.chainId !== frame.context.chainId || n.protocolAddress !== BigInt(frame.context.protocolAddress) || n.tokenAddress !== BigInt(frame.context.tokenAddress) || await creditLeaf(state) !== commitment) {
83
+ throw new Error("Credit role, commitment or deployment mismatch");
84
+ }
85
+ if (!this.runtime.reader.getCreditRevocationBitmap)
86
+ throw Error("Credit revocation reader required");
87
+ const bitmap = await this.runtime.reader.getCreditRevocationBitmap(
88
+ frame.context,
89
+ n.ownerWalletIdentity,
90
+ frame.context.tokenAddress,
91
+ n.revocationShard,
92
+ Number(n.revocationSlot >> 8n),
93
+ frame.block
94
+ );
95
+ if (bitmap & 1n << (n.revocationSlot & 255n)) throw Error("Credit grant is revoked");
96
+ const proof = await this.#prepare.membership(stored, frame);
97
+ const path = [...proof.path];
98
+ const nullifier = await computeCreditNullifier(n.chainId, n.creditSharedKey, commitment);
99
+ await this.#prepare.assertUnspent([nullifier], frame);
100
+ return {
101
+ input: {
102
+ state,
103
+ commitment,
104
+ role,
105
+ treeId: stored.treeId,
106
+ leafIndex: stored.leafIndex,
107
+ path
108
+ },
109
+ nullifier,
110
+ source: {
111
+ treeId: stored.treeId,
112
+ merkleRoot: proof.root
113
+ }
114
+ };
115
+ }
116
+ base(frame, kind) {
117
+ return {
118
+ version: 1,
119
+ id: crypto.randomUUID(),
120
+ kind,
121
+ context: frame.context,
122
+ scope: this.runtime.scope,
123
+ preparedAt: frame.block,
124
+ deadline: frame.deadline,
125
+ outputs: [],
126
+ inputs: [],
127
+ funding: {},
128
+ fundingMode: "none"
129
+ };
130
+ }
131
+ async create(options) {
132
+ for (const key of Object.keys(options))
133
+ if (![
134
+ "payload",
135
+ "fee",
136
+ "singleLimit",
137
+ "dailyLimit",
138
+ "monthlyLimit",
139
+ "availableCredit",
140
+ "unlimited",
141
+ "tokenAddress",
142
+ "spender",
143
+ "expiry",
144
+ "deadline"
145
+ ].includes(key))
146
+ throw Error("unsupported Credit creation option");
147
+ const frame = await this.#prepare.frame(options.deadline), expiry = this.expiry(options.expiry, frame);
148
+ if (expiry < frame.deadline) throw Error("expiry before request deadline");
149
+ if (!this.runtime.reader.getCreditAllocation)
150
+ throw Error("Credit allocation reader required");
151
+ const allocation = await this.runtime.reader.getCreditAllocation(
152
+ frame.context,
153
+ this.runtime.scope.ownerAddress,
154
+ frame.context.tokenAddress,
155
+ frame.block
156
+ );
157
+ const spender = await resolveRecipient(
158
+ options.spender,
159
+ recipientLookup(this.runtime.options),
160
+ { field: "spender" }
161
+ ), owner = await resolveRecipient(
162
+ this.runtime.options.wallet.getReceivingAddress().toString(),
163
+ recipientLookup(this.runtime.options),
164
+ { field: "wallet" }
165
+ );
166
+ const output = await this.seal(
167
+ {
168
+ note: {
169
+ chainId: frame.context.chainId,
170
+ protocolAddress: BigInt(frame.context.protocolAddress),
171
+ tokenAddress: BigInt(frame.context.tokenAddress),
172
+ ownerWalletIdentity: this.runtime.scope.ownerAddress,
173
+ spenderWalletIdentity: spender.ownerAddress,
174
+ revocationShard: allocation.shard,
175
+ revocationSlot: BigInt(allocation.slot),
176
+ ...normalizeCreditPolicy(options),
177
+ availableCredit: options.availableCredit === void 0 ? 0n : options.availableCredit,
178
+ unlimited: options.unlimited === void 0 ? false : options.unlimited,
179
+ payload: copyApplicationPayload(options.payload),
180
+ expiry,
181
+ nonce: generateNonce(),
182
+ creditSharedKey: generateCreditSharedKey()
183
+ },
184
+ ownerReceivingKeys: owner.getReceivingKeys(),
185
+ spenderReceivingKeys: spender.getReceivingKeys()
186
+ },
187
+ frame
188
+ );
189
+ const plan = this.base(frame, "create-credit"), params = {
190
+ token: frame.context.tokenAddress,
191
+ owner: this.runtime.scope.ownerAddress,
192
+ revocationShard: allocation.shard,
193
+ revocationSlot: BigInt(allocation.slot),
194
+ creditCommitment: output.commitment,
195
+ deadline: frame.deadline,
196
+ ...this.fee(options)
197
+ };
198
+ plan.capacity = 1;
199
+ plan.credit = {
200
+ inputs: [],
201
+ outputs: [output],
202
+ deliveries: output.deliveries,
203
+ creation: params
204
+ };
205
+ plan.statement = WitnessBuilder.statement(
206
+ "create_credit",
207
+ createCreditPublicInputs(frame.context, params, output.deliveries)
208
+ );
209
+ await this.#prepare.assertBlock(frame);
210
+ return this.runtime.complete(plan);
211
+ }
212
+ async update(options) {
213
+ for (const key of Object.keys(options))
214
+ if (![
215
+ "payload",
216
+ "fee",
217
+ "singleLimit",
218
+ "dailyLimit",
219
+ "monthlyLimit",
220
+ "increaseAvailableCredit",
221
+ "decreaseAvailableCredit",
222
+ "unlimited",
223
+ "tokenAddress",
224
+ "credit",
225
+ "expiry",
226
+ "deadline",
227
+ "creditInputs"
228
+ ].includes(key))
229
+ throw Error("unsupported Credit update option");
230
+ const frame = await this.#prepare.frame(options.deadline), previous = await this.input(options.credit, "owner", frame), n = previous.input.state.note;
231
+ const changes = {
232
+ ...Object.fromEntries(
233
+ [
234
+ "singleLimit",
235
+ "dailyLimit",
236
+ "monthlyLimit",
237
+ "unlimited",
238
+ "increaseAvailableCredit",
239
+ "decreaseAvailableCredit",
240
+ "expiry"
241
+ ].filter((k) => options[k] !== void 0).map((k) => [k, options[k]])
242
+ )
243
+ };
244
+ const next = await deriveCreditUpdate(n, changes, frame.deadline), output = await this.seal(
245
+ {
246
+ ...previous.input.state,
247
+ note: {
248
+ ...next.state,
249
+ payload: copyApplicationPayload(
250
+ options.payload === void 0 ? n.payload : options.payload
251
+ )
252
+ }
253
+ },
254
+ frame
255
+ );
256
+ const params = {
257
+ token: frame.context.tokenAddress,
258
+ owner: n.ownerWalletIdentity,
259
+ source: previous.source,
260
+ nullifier: next.nullifier,
261
+ creditCommitment: output.commitment,
262
+ revocationShard: n.revocationShard,
263
+ revocationSlot: n.revocationSlot,
264
+ deadline: frame.deadline,
265
+ ...this.fee(options)
266
+ }, plan = this.base(frame, "update-credit");
267
+ plan.capacity = 1;
268
+ plan.credit = {
269
+ inputs: [previous.input],
270
+ outputs: [output],
271
+ deliveries: output.deliveries,
272
+ update: params,
273
+ updateChanges: structuredClone(changes)
274
+ };
275
+ plan.statement = WitnessBuilder.statement(
276
+ "credit_update",
277
+ updateCreditPublicInputs(frame.context, params, output.deliveries)
278
+ );
279
+ await this.#prepare.assertBlock(frame);
280
+ return this.runtime.complete(plan);
281
+ }
282
+ async draw(options) {
283
+ const frame = await this.#prepare.frame(options.deadline), profile = selectCreditDrawCircuit(options.credits.length);
284
+ if (new Set(options.credits.map((c) => c.credit)).size !== options.credits.length)
285
+ throw Error("duplicate Credit input");
286
+ const members = await Promise.all(
287
+ options.credits.map(async (value) => ({
288
+ ...await this.input(value.credit, "spender", frame),
289
+ value
290
+ }))
291
+ );
292
+ members.sort((a, b) => {
293
+ const x = a.input.state.note, y = b.input.state.note;
294
+ for (const [u, v] of [
295
+ [BigInt(x.ownerWalletIdentity), BigInt(y.ownerWalletIdentity)],
296
+ [x.revocationShard, y.revocationShard],
297
+ [x.revocationSlot, y.revocationSlot]
298
+ ]) {
299
+ if (u < v) return -1;
300
+ if (u > v) return 1;
301
+ }
302
+ return 0;
303
+ });
304
+ const payers = [], sources = /* @__PURE__ */ new Map(), outputs = [], recoveryAmounts = [], grantRefs = [], amounts = [];
305
+ for (const member of members) {
306
+ const n = member.input.state.note, amount = positiveAmount(member.value.amount, 126);
307
+ if (n.expiry < frame.deadline) throw Error("expiry before request deadline");
308
+ let pi = payers.findIndex((p) => p.payer === n.ownerWalletIdentity);
309
+ if (pi < 0) {
310
+ pi = payers.length;
311
+ payers.push({ payer: n.ownerWalletIdentity, amount: 0n });
312
+ }
313
+ payers[pi].amount += amount;
314
+ grantRefs.push({
315
+ payerIndex: BigInt(pi),
316
+ shard: n.revocationShard,
317
+ slot: n.revocationSlot
318
+ });
319
+ if (sources.has(member.source.treeId) && sources.get(member.source.treeId) !== member.source.merkleRoot)
320
+ throw Error("Credit source root mismatch");
321
+ sources.set(member.source.treeId, member.source.merkleRoot);
322
+ const next = await deriveCreditState(n, amount, frame.block.timestamp);
323
+ outputs.push(
324
+ await this.seal(
325
+ {
326
+ ...member.input.state,
327
+ note: {
328
+ ...next.state,
329
+ payload: copyApplicationPayload(
330
+ member.value.payload === void 0 ? n.payload : member.value.payload
331
+ )
332
+ }
333
+ },
334
+ frame
335
+ )
336
+ );
337
+ recoveryAmounts.push(word(next.recoveryAmount));
338
+ amounts.push(amount);
339
+ }
340
+ const totalAmount = amounts.reduce((sum, n) => sum + n, 0n), fee = this.fee(options), payment = await NoteOutput.create({
341
+ chainId: frame.context.chainId,
342
+ protocolAddress: frame.context.protocolAddress,
343
+ tokenAddress: frame.context.tokenAddress,
344
+ amount: totalAmount - fee.feeAmount,
345
+ recipient: options.recipient.startsWith("0i") ? { type: "invisi", address: options.recipient } : { type: "evm", address: options.recipient },
346
+ payload: copyApplicationPayload(options.payload)
347
+ }), ordinary = await this.#prepare.output(payment, frame.context, false);
348
+ if (!ordinary.note)
349
+ throw Error("Credit draw requires an encrypted ordinary Note recipient");
350
+ const deliveries = [...outputs.flatMap((o) => o.deliveries), ordinary.delivery], params = {
351
+ token: frame.context.tokenAddress,
352
+ sources: [...sources].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([treeId, merkleRoot]) => ({ treeId, merkleRoot })),
353
+ payers,
354
+ grantRefs,
355
+ nullifiers: members.map((m) => m.nullifier),
356
+ creditCommitments: outputs.map((o) => o.commitment),
357
+ recoveryAmounts,
358
+ noteCommitment: ordinary.commitment,
359
+ totalAmount,
360
+ deadline: frame.deadline,
361
+ ...fee
362
+ }, plan = this.base(frame, "draw-credit");
363
+ plan.capacity = profile.capacity;
364
+ plan.outputs = [ordinary];
365
+ plan.credit = {
366
+ inputs: members.map((m) => m.input),
367
+ outputs,
368
+ deliveries,
369
+ draw: params,
370
+ amounts
371
+ };
372
+ plan.statement = WitnessBuilder.statement(
373
+ profile.name,
374
+ creditDrawPublicInputs(frame.context, params, deliveries)
375
+ );
376
+ await this.#prepare.assertBlock(frame);
377
+ return this.runtime.complete(plan);
378
+ }
379
+ async revoke(options) {
380
+ const frame = await this.#prepare.frame(options.deadline), params = {
381
+ token: frame.context.tokenAddress,
382
+ owner: options.owner ?? this.runtime.scope.ownerAddress,
383
+ shard: options.shard,
384
+ slot: options.slot,
385
+ deadline: frame.deadline,
386
+ ...this.fee(options)
387
+ };
388
+ encodeRevokeCreditTypedData(frame.context, params);
389
+ const plan = this.base(frame, "revoke-credit");
390
+ plan.credit = {
391
+ inputs: [],
392
+ outputs: [],
393
+ deliveries: [],
394
+ revocation: params,
395
+ ...options.caller ? { revocationCaller: options.caller } : {}
396
+ };
397
+ await this.#prepare.assertBlock(frame);
398
+ return this.runtime.complete(plan);
399
+ }
400
+ };
401
+ export {
402
+ CreditPreparation
403
+ };
404
+ //# sourceMappingURL=preparation-HUBTVCZE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/credit/preparation.ts"],"sourcesContent":["import { NoteOutput } from \"../notes/NoteOutput\";\nimport type {\n CreateCreditParams,\n Delivery,\n Hex,\n InputSource,\n} from \"@invisi-labs/protocol/contracts\";\nimport { getAddress, hexlify, toBeHex } from \"ethers\";\nimport { recipientLookup } from \"../notes/recipient-infrastructure\";\nimport { resolveRecipient } from \"../notes/resolve-recipient\";\n\nimport {\n FIELD_MODULUS,\n applyCreditDrawUsage,\n computeCreditNullifier,\n computeCreditRecoveryPad,\n createClue,\n deriveCreditStateNonce,\n encryptCreditState,\n generateCreditSharedKey,\n generateNonce,\n normalizeCreditDeliveryState,\n normalizeCreditPolicy,\n deriveCreditState,\n deriveCreditUpdate,\n type CreditDeliveryState,\n} from \"@invisi-labs/primitives\";\nimport { WitnessBuilder } from \"@invisi-labs/prover\";\nimport {\n normalizeFee,\n encodeRevokeCreditTypedData,\n createCreditPublicInputs,\n creditDrawPublicInputs,\n selectCreditDrawCircuit,\n updateCreditPublicInputs,\n word,\n} from \"@invisi-labs/protocol\";\nimport type { CircuitName } from \"@invisi-labs/prover\";\nimport { creditLeaf } from \"./state\";\n\nimport type {\n RevokeCreditPreparation,\n CreateCreditPreparation,\n DrawCreditPreparation,\n OperationPlan,\n PreparationRuntime,\n PreparedCreditInput,\n PreparedCreditOutput,\n UpdateCreditPreparation,\n} from \"../transactions/operation-types\";\nimport {\n Preparation,\n copyApplicationPayload,\n positiveAmount,\n type PreparationFrame,\n} from \"../transactions/preparation/prepare-common\";\n\nconst EMPTY: Delivery = { ciphertext: \"0x\", clue: \"0x\" };\n\n/** Credit roles, grant references and receiving snapshots are frozen before authorization. */\nexport class CreditPreparation<Result> {\n readonly #prepare: Preparation<Result>;\n\n constructor(readonly runtime: PreparationRuntime<Result>) {\n this.#prepare = new Preparation(runtime);\n }\n\n private fee(options: { fee?: { recipient: Hex; amount: bigint } }) {\n return normalizeFee(\n options.fee\n ? { feeRecipient: options.fee.recipient, feeAmount: options.fee.amount }\n : {}\n );\n }\n\n private expiry(value: bigint, frame: PreparationFrame): bigint {\n if (typeof value !== \"bigint\" || value <= frame.block.timestamp || value >= 1n << 64n) {\n throw new Error(\"Credit expiry must be a future uint64 timestamp\");\n }\n return value;\n }\n\n private async seal(\n input: CreditDeliveryState,\n frame: PreparationFrame\n ): Promise<PreparedCreditOutput> {\n const state = normalizeCreditDeliveryState(input);\n const commitment = await creditLeaf(state);\n const context = {\n chainId: frame.context.chainId,\n protocolAddress: BigInt(frame.context.protocolAddress),\n outputCommitment: commitment,\n };\n const deliveries = (await Promise.all(\n ([\"owner\", \"spender\"] as const).map(async (role) => {\n const keys =\n role === \"owner\" ? state.ownerReceivingKeys : state.spenderReceivingKeys;\n return {\n ciphertext: hexlify(\n await encryptCreditState(keys.viewingPublicKey, state, { ...context, role })\n ) as Hex,\n clue: hexlify(createClue(keys.clueKey)) as Hex,\n };\n })\n )) as [Delivery, Delivery];\n return { state, commitment, deliveries };\n }\n\n private async input(\n commitment: Hex,\n role: \"owner\" | \"spender\",\n frame: PreparationFrame\n ): Promise<{ input: PreparedCreditInput; nullifier: Hex; source: InputSource }> {\n const stored = (await this.runtime.readInventory()).credits[commitment + \":\" + role];\n if (!stored || stored.spent !== \"unspent\" || stored.role !== role) {\n throw new Error(`confirmed unspent ${role} Credit is unavailable`);\n }\n const state = normalizeCreditDeliveryState(stored.state);\n const n = state.note;\n if (\n (role === \"owner\" ? n.ownerWalletIdentity : n.spenderWalletIdentity) !==\n this.runtime.scope.ownerAddress ||\n n.chainId !== frame.context.chainId ||\n n.protocolAddress !== BigInt(frame.context.protocolAddress) ||\n n.tokenAddress !== BigInt(frame.context.tokenAddress) ||\n (await creditLeaf(state)) !== commitment\n ) {\n throw new Error(\"Credit role, commitment or deployment mismatch\");\n }\n if (!this.runtime.reader.getCreditRevocationBitmap)\n throw Error(\"Credit revocation reader required\");\n const bitmap = await this.runtime.reader.getCreditRevocationBitmap(\n frame.context,\n n.ownerWalletIdentity,\n frame.context.tokenAddress,\n n.revocationShard,\n Number(n.revocationSlot >> 8n),\n frame.block\n );\n if (bitmap & (1n << (n.revocationSlot & 255n))) throw Error(\"Credit grant is revoked\");\n const proof = await this.#prepare.membership(stored, frame);\n const path = [...proof.path];\n const nullifier = await computeCreditNullifier(n.chainId, n.creditSharedKey, commitment);\n await this.#prepare.assertUnspent([nullifier], frame);\n return {\n input: {\n state,\n commitment,\n role,\n treeId: stored.treeId,\n leafIndex: stored.leafIndex,\n path,\n },\n nullifier,\n source: {\n treeId: stored.treeId,\n merkleRoot: proof.root,\n },\n };\n }\n\n private base(frame: PreparationFrame, kind: OperationPlan[\"kind\"]): OperationPlan {\n return {\n version: 1,\n id: crypto.randomUUID(),\n kind,\n context: frame.context,\n scope: this.runtime.scope,\n preparedAt: frame.block,\n deadline: frame.deadline,\n outputs: [],\n inputs: [],\n funding: {},\n fundingMode: \"none\",\n };\n }\n\n async create(options: CreateCreditPreparation): Promise<Result> {\n for (const key of Object.keys(options))\n if (\n ![\n \"payload\",\n \"fee\",\n \"singleLimit\",\n \"dailyLimit\",\n \"monthlyLimit\",\n \"availableCredit\",\n \"unlimited\",\n \"tokenAddress\",\n \"spender\",\n \"expiry\",\n \"deadline\",\n ].includes(key)\n )\n throw Error(\"unsupported Credit creation option\");\n const frame = await this.#prepare.frame(options.deadline),\n expiry = this.expiry(options.expiry, frame);\n if (expiry < frame.deadline) throw Error(\"expiry before request deadline\");\n if (!this.runtime.reader.getCreditAllocation)\n throw Error(\"Credit allocation reader required\");\n const allocation = await this.runtime.reader.getCreditAllocation(\n frame.context,\n this.runtime.scope.ownerAddress,\n frame.context.tokenAddress,\n frame.block\n );\n const spender = await resolveRecipient(\n options.spender,\n recipientLookup(this.runtime.options),\n { field: \"spender\" }\n ),\n owner = await resolveRecipient(\n this.runtime.options.wallet.getReceivingAddress().toString(),\n recipientLookup(this.runtime.options),\n { field: \"wallet\" }\n );\n const output = await this.seal(\n {\n note: {\n chainId: frame.context.chainId,\n protocolAddress: BigInt(frame.context.protocolAddress),\n tokenAddress: BigInt(frame.context.tokenAddress),\n ownerWalletIdentity: this.runtime.scope.ownerAddress,\n spenderWalletIdentity: spender.ownerAddress,\n revocationShard: allocation.shard,\n revocationSlot: BigInt(allocation.slot),\n ...normalizeCreditPolicy(options),\n availableCredit:\n options.availableCredit === undefined ? 0n : options.availableCredit,\n unlimited: options.unlimited === undefined ? false : options.unlimited,\n payload: copyApplicationPayload(options.payload),\n expiry,\n nonce: generateNonce(),\n creditSharedKey: generateCreditSharedKey(),\n },\n ownerReceivingKeys: owner.getReceivingKeys(),\n spenderReceivingKeys: spender.getReceivingKeys(),\n },\n frame\n );\n const plan = this.base(frame, \"create-credit\"),\n params = {\n token: frame.context.tokenAddress,\n owner: this.runtime.scope.ownerAddress,\n revocationShard: allocation.shard,\n revocationSlot: BigInt(allocation.slot),\n creditCommitment: output.commitment,\n deadline: frame.deadline,\n ...this.fee(options),\n };\n plan.capacity = 1;\n plan.credit = {\n inputs: [],\n outputs: [output],\n deliveries: output.deliveries,\n creation: params,\n };\n plan.statement = WitnessBuilder.statement(\n \"create_credit\",\n createCreditPublicInputs(frame.context, params, output.deliveries)\n );\n await this.#prepare.assertBlock(frame);\n return this.runtime.complete(plan);\n }\n async update(options: UpdateCreditPreparation): Promise<Result> {\n for (const key of Object.keys(options))\n if (\n ![\n \"payload\",\n \"fee\",\n \"singleLimit\",\n \"dailyLimit\",\n \"monthlyLimit\",\n \"increaseAvailableCredit\",\n \"decreaseAvailableCredit\",\n \"unlimited\",\n \"tokenAddress\",\n \"credit\",\n \"expiry\",\n \"deadline\",\n \"creditInputs\",\n ].includes(key)\n )\n throw Error(\"unsupported Credit update option\");\n const frame = await this.#prepare.frame(options.deadline),\n previous = await this.input(options.credit, \"owner\", frame),\n n = previous.input.state.note;\n const changes = {\n ...Object.fromEntries(\n (\n [\n \"singleLimit\",\n \"dailyLimit\",\n \"monthlyLimit\",\n \"unlimited\",\n \"increaseAvailableCredit\",\n \"decreaseAvailableCredit\",\n \"expiry\",\n ] as const\n )\n .filter((k) => options[k] !== undefined)\n .map((k) => [k, options[k]])\n ),\n };\n const next = await deriveCreditUpdate(n, changes, frame.deadline),\n output = await this.seal(\n {\n ...previous.input.state,\n note: {\n ...next.state,\n payload: copyApplicationPayload(\n options.payload === undefined ? n.payload : options.payload\n ),\n },\n },\n frame\n );\n const params = {\n token: frame.context.tokenAddress,\n owner: n.ownerWalletIdentity,\n source: previous.source,\n nullifier: next.nullifier,\n creditCommitment: output.commitment,\n revocationShard: n.revocationShard,\n revocationSlot: n.revocationSlot,\n deadline: frame.deadline,\n ...this.fee(options),\n },\n plan = this.base(frame, \"update-credit\");\n plan.capacity = 1;\n plan.credit = {\n inputs: [previous.input],\n outputs: [output],\n deliveries: output.deliveries,\n update: params,\n updateChanges: structuredClone(changes),\n };\n plan.statement = WitnessBuilder.statement(\n \"credit_update\",\n updateCreditPublicInputs(frame.context, params, output.deliveries)\n );\n await this.#prepare.assertBlock(frame);\n return this.runtime.complete(plan);\n }\n async draw(options: DrawCreditPreparation): Promise<Result> {\n const frame = await this.#prepare.frame(options.deadline),\n profile = selectCreditDrawCircuit(options.credits.length);\n if (new Set(options.credits.map((c) => c.credit)).size !== options.credits.length)\n throw Error(\"duplicate Credit input\");\n const members = await Promise.all(\n options.credits.map(async (value) => ({\n ...(await this.input(value.credit, \"spender\", frame)),\n value,\n }))\n );\n members.sort((a, b) => {\n const x = a.input.state.note,\n y = b.input.state.note;\n for (const [u, v] of [\n [BigInt(x.ownerWalletIdentity), BigInt(y.ownerWalletIdentity)],\n [x.revocationShard, y.revocationShard],\n [x.revocationSlot, y.revocationSlot],\n ]) {\n if (u! < v!) return -1;\n if (u! > v!) return 1;\n }\n return 0;\n });\n const payers: { payer: Hex; amount: bigint }[] = [],\n sources = new Map<bigint, Hex>(),\n outputs: PreparedCreditOutput[] = [],\n recoveryAmounts: Hex[] = [],\n grantRefs: { payerIndex: bigint; shard: bigint; slot: bigint }[] = [],\n amounts: bigint[] = [];\n for (const member of members) {\n const n = member.input.state.note,\n amount = positiveAmount(member.value.amount, 126);\n if (n.expiry < frame.deadline) throw Error(\"expiry before request deadline\");\n let pi = payers.findIndex((p) => p.payer === n.ownerWalletIdentity);\n if (pi < 0) {\n pi = payers.length;\n payers.push({ payer: n.ownerWalletIdentity, amount: 0n });\n }\n payers[pi]!.amount += amount;\n grantRefs.push({\n payerIndex: BigInt(pi),\n shard: n.revocationShard,\n slot: n.revocationSlot,\n });\n if (\n sources.has(member.source.treeId) &&\n sources.get(member.source.treeId) !== member.source.merkleRoot\n )\n throw Error(\"Credit source root mismatch\");\n sources.set(member.source.treeId, member.source.merkleRoot);\n const next = await deriveCreditState(n, amount, frame.block.timestamp);\n outputs.push(\n await this.seal(\n {\n ...member.input.state,\n note: {\n ...next.state,\n payload: copyApplicationPayload(\n member.value.payload === undefined\n ? n.payload\n : member.value.payload\n ),\n },\n },\n frame\n )\n );\n recoveryAmounts.push(word(next.recoveryAmount));\n amounts.push(amount);\n }\n const totalAmount = amounts.reduce((sum, n) => sum + n, 0n),\n fee = this.fee(options),\n payment = await NoteOutput.create({\n chainId: frame.context.chainId,\n protocolAddress: frame.context.protocolAddress,\n tokenAddress: frame.context.tokenAddress,\n amount: totalAmount - fee.feeAmount,\n recipient: options.recipient.startsWith(\"0i\")\n ? { type: \"invisi\", address: options.recipient }\n : { type: \"evm\", address: options.recipient },\n payload: copyApplicationPayload(options.payload),\n }),\n ordinary = await this.#prepare.output(payment, frame.context, false);\n if (!ordinary.note)\n throw Error(\"Credit draw requires an encrypted ordinary Note recipient\");\n const deliveries = [...outputs.flatMap((o) => o.deliveries), ordinary.delivery],\n params = {\n token: frame.context.tokenAddress,\n sources: [...sources]\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n .map(([treeId, merkleRoot]) => ({ treeId, merkleRoot })),\n payers,\n grantRefs,\n nullifiers: members.map((m) => m.nullifier),\n creditCommitments: outputs.map((o) => o.commitment),\n recoveryAmounts,\n noteCommitment: ordinary.commitment,\n totalAmount,\n deadline: frame.deadline,\n ...fee,\n },\n plan = this.base(frame, \"draw-credit\");\n plan.capacity = profile.capacity;\n plan.outputs = [ordinary];\n plan.credit = {\n inputs: members.map((m) => m.input),\n outputs,\n deliveries,\n draw: params,\n amounts,\n };\n plan.statement = WitnessBuilder.statement(\n profile.name as CircuitName,\n creditDrawPublicInputs(frame.context, params, deliveries)\n );\n await this.#prepare.assertBlock(frame);\n return this.runtime.complete(plan);\n }\n async revoke(options: RevokeCreditPreparation): Promise<Result> {\n const frame = await this.#prepare.frame(options.deadline),\n params = {\n token: frame.context.tokenAddress,\n owner: options.owner ?? this.runtime.scope.ownerAddress,\n shard: options.shard,\n slot: options.slot,\n deadline: frame.deadline,\n ...this.fee(options),\n };\n encodeRevokeCreditTypedData(frame.context, params);\n const plan = this.base(frame, \"revoke-credit\");\n plan.credit = {\n inputs: [],\n outputs: [],\n deliveries: [],\n revocation: params,\n ...(options.caller ? { revocationCaller: options.caller } : {}),\n };\n await this.#prepare.assertBlock(frame);\n return this.runtime.complete(plan);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAOA,SAAqB,eAAwB;AAI7C;AAAA,EAGI;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEG;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAwBA,IAAM,oBAA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