@invisi-labs/primitives 0.0.0-stage → 1.2.1

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/note.cjs ADDED
@@ -0,0 +1,887 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3);
19
+
20
+ // src/note/index.ts
21
+ var note_exports = {};
22
+ __export(note_exports, {
23
+ computeNoteCommitment: () => computeNoteCommitment,
24
+ computeNoteIdentity: () => computeNoteIdentity,
25
+ computeNoteNullifier: () => computeNoteNullifier,
26
+ decryptPrivateTransferNote: () => decryptPrivateTransferNote,
27
+ encryptPrivateTransferNote: () => encryptPrivateTransferNote
28
+ });
29
+ module.exports = __toCommonJS(note_exports);
30
+
31
+ // src/crypto/domains.ts
32
+ var D_IDENT = 2n;
33
+ var D_NOTE = 3n;
34
+ var D_NULL = 4n;
35
+
36
+ // src/crypto/random.ts
37
+ var FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
38
+
39
+ // src/crypto/poseidon-constants.ts
40
+ var INTERNAL_DIAGONAL = [
41
+ 0x10dc6e9c006ea38b04b1e03b4bd9490c0d03f98929ca1d7fb56821fd19d3b6e7n,
42
+ 0x0c28145b6a44df3e0149b3d0a30b3bb599df9756d4dd9b84a86b38cfb45a740bn,
43
+ 0x00544b8338791518b2c7645a50392798b21f75bb60e3596170067d00141cac15n,
44
+ 0x222c01175718386f2e2e82eb122789e352e105a3b8fa852613bc534433ee428bn
45
+ ];
46
+ var ROUND_CONSTANTS = [
47
+ [
48
+ 0x19b849f69450b06848da1d39bd5e4a4302bb86744edc26238b0878e269ed23e5n,
49
+ 0x265ddfe127dd51bd7239347b758f0a1320eb2cc7450acc1dad47f80c8dcf34d6n,
50
+ 0x199750ec472f1809e0f66a545e1e51624108ac845015c2aa3dfc36bab497d8aan,
51
+ 0x157ff3fe65ac7208110f06a5f74302b14d743ea25067f0ffd032f787c7f1cdf8n
52
+ ],
53
+ [
54
+ 0x2e49c43c4569dd9c5fd35ac45fca33f10b15c590692f8beefe18f4896ac94902n,
55
+ 0x0e35fb89981890520d4aef2b6d6506c3cb2f0b6973c24fa82731345ffa2d1f1en,
56
+ 0x251ad47cb15c4f1105f109ae5e944f1ba9d9e7806d667ffec6fe723002e0b996n,
57
+ 0x13da07dc64d428369873e97160234641f8beb56fdd05e5f3563fa39d9c22df4en
58
+ ],
59
+ [
60
+ 0x0c009b84e650e6d23dc00c7dccef7483a553939689d350cd46e7b89055fd4738n,
61
+ 0x011f16b1c63a854f01992e3956f42d8b04eb650c6d535eb0203dec74befdca06n,
62
+ 0x0ed69e5e383a688f209d9a561daa79612f3f78d0467ad45485df07093f367549n,
63
+ 0x04dba94a7b0ce9e221acad41472b6bbe3aec507f5eb3d33f463672264c9f789bn
64
+ ],
65
+ [
66
+ 0x0a3f2637d840f3a16eb094271c9d237b6036757d4bb50bf7ce732ff1d4fa28e8n,
67
+ 0x259a666f129eea198f8a1c502fdb38fa39b1f075569564b6e54a485d1182323fn,
68
+ 0x28bf7459c9b2f4c6d8e7d06a4ee3a47f7745d4271038e5157a32fdf7ede0d6a1n,
69
+ 0x0a1ca941f057037526ea200f489be8d4c37c85bbcce6a2aeec91bd6941432447n
70
+ ],
71
+ [0x0c6f8f958be0e93053d7fd4fc54512855535ed1539f051dcb43a26fd926361cfn, 0x0n, 0x0n, 0x0n],
72
+ [0x123106a93cd17578d426e8128ac9d90aa9e8a00708e296e084dd57e69caaf811n, 0x0n, 0x0n, 0x0n],
73
+ [0x26e1ba52ad9285d97dd3ab52f8e840085e8fa83ff1e8f1877b074867cd2dee75n, 0x0n, 0x0n, 0x0n],
74
+ [0x1cb55cad7bd133de18a64c5c47b9c97cbe4d8b7bf9e095864471537e6a4ae2c5n, 0x0n, 0x0n, 0x0n],
75
+ [0x1dcd73e46acd8f8e0e2c7ce04bde7f6d2a53043d5060a41c7143f08e6e9055d0n, 0x0n, 0x0n, 0x0n],
76
+ [0x011003e32f6d9c66f5852f05474a4def0cda294a0eb4e9b9b12b9bb4512e5574n, 0x0n, 0x0n, 0x0n],
77
+ [0x2b1e809ac1d10ab29ad5f20d03a57dfebadfe5903f58bafed7c508dd2287ae8cn, 0x0n, 0x0n, 0x0n],
78
+ [0x2539de1785b735999fb4dac35ee17ed0ef995d05ab2fc5faeaa69ae87bcec0a5n, 0x0n, 0x0n, 0x0n],
79
+ [0x0c246c5a2ef8ee0126497f222b3e0a0ef4e1c3d41c86d46e43982cb11d77951dn, 0x0n, 0x0n, 0x0n],
80
+ [0x192089c4974f68e95408148f7c0632edbb09e6a6ad1a1c2f3f0305f5d03b527bn, 0x0n, 0x0n, 0x0n],
81
+ [0x1eae0ad8ab68b2f06a0ee36eeb0d0c058529097d91096b756d8fdc2fb5a60d85n, 0x0n, 0x0n, 0x0n],
82
+ [0x179190e5d0e22179e46f8282872abc88db6e2fdc0dee99e69768bd98c5d06bfbn, 0x0n, 0x0n, 0x0n],
83
+ [0x29bb9e2c9076732576e9a81c7ac4b83214528f7db00f31bf6cafe794a9b3cd1cn, 0x0n, 0x0n, 0x0n],
84
+ [0x225d394e42207599403efd0c2464a90d52652645882aac35b10e590e6e691e08n, 0x0n, 0x0n, 0x0n],
85
+ [0x064760623c25c8cf753d238055b444532be13557451c087de09efd454b23fd59n, 0x0n, 0x0n, 0x0n],
86
+ [0x10ba3a0e01df92e87f301c4b716d8a394d67f4bf42a75c10922910a78f6b5b87n, 0x0n, 0x0n, 0x0n],
87
+ [0x0e070bf53f8451b24f9c6e96b0c2a801cb511bc0c242eb9d361b77693f21471cn, 0x0n, 0x0n, 0x0n],
88
+ [0x1b94cd61b051b04dd39755ff93821a73ccd6cb11d2491d8aa7f921014de252fbn, 0x0n, 0x0n, 0x0n],
89
+ [0x1d7cb39bafb8c744e148787a2e70230f9d4e917d5713bb050487b5aa7d74070bn, 0x0n, 0x0n, 0x0n],
90
+ [0x2ec93189bd1ab4f69117d0fe980c80ff8785c2961829f701bb74ac1f303b17dbn, 0x0n, 0x0n, 0x0n],
91
+ [0x2db366bfdd36d277a692bb825b86275beac404a19ae07a9082ea46bd83517926n, 0x0n, 0x0n, 0x0n],
92
+ [0x062100eb485db06269655cf186a68532985275428450359adc99cec6960711b8n, 0x0n, 0x0n, 0x0n],
93
+ [0x0761d33c66614aaa570e7f1e8244ca1120243f92fa59e4f900c567bf41f5a59bn, 0x0n, 0x0n, 0x0n],
94
+ [0x20fc411a114d13992c2705aa034e3f315d78608a0f7de4ccf7a72e494855ad0dn, 0x0n, 0x0n, 0x0n],
95
+ [0x25b5c004a4bdfcb5add9ec4e9ab219ba102c67e8b3effb5fc3a30f317250bc5an, 0x0n, 0x0n, 0x0n],
96
+ [0x23b1822d278ed632a494e58f6df6f5ed038b186d8474155ad87e7dff62b37f4bn, 0x0n, 0x0n, 0x0n],
97
+ [0x22734b4c5c3f9493606c4ba9012499bf0f14d13bfcfcccaa16102a29cc2f69e0n, 0x0n, 0x0n, 0x0n],
98
+ [0x26c0c8fe09eb30b7e27a74dc33492347e5bdff409aa3610254413d3fad795ce5n, 0x0n, 0x0n, 0x0n],
99
+ [0x070dd0ccb6bd7bbae88eac03fa1fbb26196be3083a809829bbd626df348ccad9n, 0x0n, 0x0n, 0x0n],
100
+ [0x12b6595bdb329b6fb043ba78bb28c3bec2c0a6de46d8c5ad6067c4ebfd4250dan, 0x0n, 0x0n, 0x0n],
101
+ [0x248d97d7f76283d63bec30e7a5876c11c06fca9b275c671c5e33d95bb7e8d729n, 0x0n, 0x0n, 0x0n],
102
+ [0x1a306d439d463b0816fc6fd64cc939318b45eb759ddde4aa106d15d9bd9baaaan, 0x0n, 0x0n, 0x0n],
103
+ [0x28a8f8372e3c38daced7c00421cb4621f4f1b54ddc27821b0d62d3d6ec7c56cfn, 0x0n, 0x0n, 0x0n],
104
+ [0x0094975717f9a8a8bb35152f24d43294071ce320c829f388bc852183e1e2ce7en, 0x0n, 0x0n, 0x0n],
105
+ [0x04d5ee4c3aa78f7d80fde60d716480d3593f74d4f653ae83f4103246db2e8d65n, 0x0n, 0x0n, 0x0n],
106
+ [0x2a6cf5e9aa03d4336349ad6fb8ed2269c7bef54b8822cc76d08495c12efde187n, 0x0n, 0x0n, 0x0n],
107
+ [0x2304d31eaab960ba9274da43e19ddeb7f792180808fd6e43baae48d7efcba3f3n, 0x0n, 0x0n, 0x0n],
108
+ [0x03fd9ac865a4b2a6d5e7009785817249bff08a7e0726fcb4e1c11d39d199f0b0n, 0x0n, 0x0n, 0x0n],
109
+ [0x00b7258ded52bbda2248404d55ee5044798afc3a209193073f7954d4d63b0b64n, 0x0n, 0x0n, 0x0n],
110
+ [0x159f81ada0771799ec38fca2d4bf65ebb13d3a74f3298db36272c5ca65e92d9an, 0x0n, 0x0n, 0x0n],
111
+ [0x1ef90e67437fbc8550237a75bc28e3bb9000130ea25f0c5471e144cf4264431fn, 0x0n, 0x0n, 0x0n],
112
+ [0x1e65f838515e5ff0196b49aa41a2d2568df739bc176b08ec95a79ed82932e30dn, 0x0n, 0x0n, 0x0n],
113
+ [0x2b1b045def3a166cec6ce768d079ba74b18c844e570e1f826575c1068c94c33fn, 0x0n, 0x0n, 0x0n],
114
+ [0x0832e5753ceb0ff6402543b1109229c165dc2d73bef715e3f1c6e07c168bb173n, 0x0n, 0x0n, 0x0n],
115
+ [0x02f614e9cedfb3dc6b762ae0a37d41bab1b841c2e8b6451bc5a8e3c390b6ad16n, 0x0n, 0x0n, 0x0n],
116
+ [0x0e2427d38bd46a60dd640b8e362cad967370ebb777bedff40f6a0be27e7ed705n, 0x0n, 0x0n, 0x0n],
117
+ [0x0493630b7c670b6deb7c84d414e7ce79049f0ec098c3c7c50768bbe29214a53an, 0x0n, 0x0n, 0x0n],
118
+ [0x22ead100e8e482674decdab17066c5a26bb1515355d5461a3dc06cc85327cea9n, 0x0n, 0x0n, 0x0n],
119
+ [0x25b3e56e655b42cdaae2626ed2554d48583f1ae35626d04de5084e0b6d2a6f16n, 0x0n, 0x0n, 0x0n],
120
+ [0x1e32752ada8836ef5837a6cde8ff13dbb599c336349e4c584b4fdc0a0cf6f9d0n, 0x0n, 0x0n, 0x0n],
121
+ [0x2fa2a871c15a387cc50f68f6f3c3455b23c00995f05078f672a9864074d412e5n, 0x0n, 0x0n, 0x0n],
122
+ [0x2f569b8a9a4424c9278e1db7311e889f54ccbf10661bab7fcd18e7c7a7d83505n, 0x0n, 0x0n, 0x0n],
123
+ [0x044cb455110a8fdd531ade530234c518a7df93f7332ffd2144165374b246b43dn, 0x0n, 0x0n, 0x0n],
124
+ [0x227808de93906d5d420246157f2e42b191fe8c90adfe118178ddc723a5319025n, 0x0n, 0x0n, 0x0n],
125
+ [0x02fcca2934e046bc623adead873579865d03781ae090ad4a8579d2e7a6800355n, 0x0n, 0x0n, 0x0n],
126
+ [0x0ef915f0ac120b876abccceb344a1d36bad3f3c5ab91a8ddcbec2e060d8befacn, 0x0n, 0x0n, 0x0n],
127
+ [
128
+ 0x1797130f4b7a3e1777eb757bc6f287f6ab0fb85f6be63b09f3b16ef2b1405d38n,
129
+ 0x0a76225dc04170ae3306c85abab59e608c7f497c20156d4d36c668555decc6e5n,
130
+ 0x1fffb9ec1992d66ba1e77a7b93209af6f8fa76d48acb664796174b5326a31a5cn,
131
+ 0x25721c4fc15a3f2853b57c338fa538d85f8fbba6c6b9c6090611889b797b9c5fn
132
+ ],
133
+ [
134
+ 0x0c817fd42d5f7a41215e3d07ba197216adb4c3790705da95eb63b982bfcaf75an,
135
+ 0x13abe3f5239915d39f7e13c2c24970b6df8cf86ce00a22002bc15866e52b5a96n,
136
+ 0x2106feea546224ea12ef7f39987a46c85c1bc3dc29bdbd7a92cd60acb4d391cen,
137
+ 0x21ca859468a746b6aaa79474a37dab49f1ca5a28c748bc7157e1b3345bb0f959n
138
+ ],
139
+ [
140
+ 0x05ccd6255c1e6f0c5cf1f0df934194c62911d14d0321662a8f1a48999e34185bn,
141
+ 0x0f0e34a64b70a626e464d846674c4c8816c4fb267fe44fe6ea28678cb09490a4n,
142
+ 0x0558531a4e25470c6157794ca36d0e9647dbfcfe350d64838f5b1a8a2de0d4bfn,
143
+ 0x09d3dca9173ed2faceea125157683d18924cadad3f655a60b72f5864961f1455n
144
+ ],
145
+ [
146
+ 0x0328cbd54e8c0913493f866ed03d218bf23f92d68aaec48617d4c722e5bd4335n,
147
+ 0x2bf07216e2aff0a223a487b1a7094e07e79e7bcc9798c648ee3347dd5329d34bn,
148
+ 0x1daf345a58006b736499c583cb76c316d6f78ed6a6dffc82111e11a63fe412dfn,
149
+ 0x176563472456aaa746b694c60e1823611ef39039b2edc7ff391e6f2293d2c404n
150
+ ]
151
+ ];
152
+
153
+ // src/crypto/poseidon.ts
154
+ var mod = (n) => n % FIELD_MODULUS;
155
+ var fifth = (n) => {
156
+ const x = mod(n), x2 = mod(x * x);
157
+ return mod(x * x2 * x2);
158
+ };
159
+ function external(s) {
160
+ const t0 = s[0] + s[1], t1 = s[2] + s[3], t2 = 2n * s[1] + t1, t3 = 2n * s[3] + t0;
161
+ const t4 = 4n * t1 + t3, t5 = 4n * t0 + t2;
162
+ s[0] = mod(t3 + t5);
163
+ s[1] = mod(t5);
164
+ s[2] = mod(t2 + t4);
165
+ s[3] = mod(t4);
166
+ }
167
+ function permute(s) {
168
+ external(s);
169
+ for (let r = 0; r < 64; r++) {
170
+ const full = r < 4 || r >= 60, rc = ROUND_CONSTANTS[r];
171
+ if (full) {
172
+ for (let i = 0; i < 4; i++) s[i] = fifth(s[i] + rc[i]);
173
+ external(s);
174
+ } else {
175
+ s[0] = fifth(s[0] + rc[0]);
176
+ const sum = s.reduce((a, b) => a + b, 0n);
177
+ for (let i = 0; i < 4; i++) s[i] = mod(s[i] * INTERNAL_DIAGONAL[i] + sum);
178
+ }
179
+ }
180
+ }
181
+ async function poseidonHash(inputs) {
182
+ for (let i = 0; i < inputs.length; i++)
183
+ if (inputs[i] < 0n || inputs[i] >= FIELD_MODULUS)
184
+ throw new RangeError(
185
+ `poseidonHash: input[${i}] out of BN254 field range [0, FIELD_MODULUS): ${inputs[i]}`
186
+ );
187
+ const state = [0n, 0n, 0n, BigInt(inputs.length) << 64n];
188
+ let used = 0;
189
+ for (const input of inputs) {
190
+ if (used === 3) {
191
+ permute(state);
192
+ used = 0;
193
+ }
194
+ state[used] = mod(state[used] + input);
195
+ used++;
196
+ }
197
+ permute(state);
198
+ return `0x${state[0].toString(16).padStart(64, "0")}`;
199
+ }
200
+
201
+ // src/notes/commitment.ts
202
+ async function computeNoteIdentity(ownerAddress, nonce) {
203
+ if (ownerAddress <= 0n || ownerAddress >= 1n << 160n)
204
+ throw new RangeError("invalid owner address");
205
+ return poseidonHash([D_IDENT, ownerAddress, nonce]);
206
+ }
207
+ async function computeNoteCommitment(chainId, protocolAddress, identity, tokenAddress, amount) {
208
+ if (chainId < 0n || chainId >= 1n << 64n) throw new RangeError("invalid chainId");
209
+ if (protocolAddress <= 0n || protocolAddress >= 1n << 160n)
210
+ throw new RangeError("invalid protocol address");
211
+ if (tokenAddress < 0n || tokenAddress >= 1n << 160n)
212
+ throw new RangeError("invalid token address");
213
+ if (amount <= 0n || amount >= 1n << 128n) throw new RangeError("invalid note amount");
214
+ if (!/^0x[0-9a-fA-F]{64}$/.test(identity)) throw new Error("invalid note identity encoding");
215
+ return poseidonHash([D_NOTE, chainId, protocolAddress, BigInt(identity), tokenAddress, amount]);
216
+ }
217
+
218
+ // src/notes/nullifier.ts
219
+ async function computeNoteNullifier(chainId, protocolAddress, nonce, commitment) {
220
+ if (chainId < 0n || chainId >= 1n << 64n) throw new RangeError("invalid chainId");
221
+ if (protocolAddress <= 0n || protocolAddress >= 1n << 160n)
222
+ throw new RangeError("invalid protocol address");
223
+ if (nonce < 0n || nonce >= FIELD_MODULUS) throw new RangeError("invalid note nonce");
224
+ if (!/^0x[0-9a-fA-F]{64}$/.test(commitment))
225
+ throw new Error("invalid note commitment encoding");
226
+ return poseidonHash([D_NULL, chainId, protocolAddress, nonce, BigInt(commitment)]);
227
+ }
228
+
229
+ // src/delivery/delivery-codec.ts
230
+ var import_ethers = require("ethers");
231
+
232
+ // src/delivery/note-payload.ts
233
+ var import_secp256k1 = require("@noble/curves/secp256k1");
234
+
235
+ // src/fmd/fmd.ts
236
+ var import_blake2b2 = require("@noble/hashes/blake2b");
237
+ var import_utils = require("@noble/hashes/utils");
238
+
239
+ // src/fmd/decaf377.ts
240
+ var import_edwards = require("@noble/curves/abstract/edwards");
241
+ var import_modular = require("@noble/curves/abstract/modular");
242
+ var import_blake2b = require("@noble/hashes/blake2b");
243
+ var FQ = 8444461749428370424248824938781546531375899335154063827935233455917409239041n;
244
+ var FR = 2111115437357092606062206234695386632838870926408408195193685246394721360383n;
245
+ var field = (0, import_modular.Field)(FQ, 253, true);
246
+ var f = (n) => (0, import_modular.mod)(n, FQ);
247
+ function secureRandomBytes(length) {
248
+ const webCrypto = globalThis.crypto;
249
+ if (!webCrypto?.getRandomValues) throw new Error("WebCrypto secure randomness is unavailable");
250
+ return webCrypto.getRandomValues(new Uint8Array(length));
251
+ }
252
+ var curve = (0, import_edwards.twistedEdwards)({
253
+ a: FQ - 1n,
254
+ d: 3021n,
255
+ Fp: field,
256
+ n: FR,
257
+ h: 4n,
258
+ Gx: 4959445789346820725352484487855828915252512307947624787834978378872129235627n,
259
+ Gy: 6060471950081851567114691557659790004756535011754163002297540472747064943288n,
260
+ hash: import_blake2b.blake2b,
261
+ randomBytes: (length = 32) => secureRandomBytes(length)
262
+ });
263
+ var generator = curve.ExtendedPoint.BASE;
264
+ function readLE(bytes2) {
265
+ let n = 0n;
266
+ for (let i = bytes2.length - 1; i >= 0; i--) n = n << 8n | BigInt(bytes2[i]);
267
+ return n;
268
+ }
269
+ function decodePoint(bytes2) {
270
+ if (!(bytes2 instanceof Uint8Array) || bytes2.length !== 32)
271
+ throw new Error("Invalid Decaf377 encoding length");
272
+ const s = readLE(bytes2);
273
+ if (s >= FQ || (s & 1n) !== 0n || bytes2[31] >> 5 !== 0)
274
+ throw new Error("Invalid Decaf377 encoding");
275
+ const ss = f(s * s);
276
+ const u1 = f(1n - ss);
277
+ const u2 = f(u1 * u1 - 4n * 3021n * ss);
278
+ const denominator = f(u2 * u1 * u1);
279
+ if (denominator === 0n) throw new Error("Invalid Decaf377 encoding");
280
+ let v;
281
+ try {
282
+ v = field.sqrt(field.inv(denominator));
283
+ } catch {
284
+ throw new Error("Invalid Decaf377 encoding");
285
+ }
286
+ const twoSU1 = f(2n * s * u1);
287
+ if ((f(twoSU1 * v) & 1n) !== 0n) v = f(-v);
288
+ const x = f(twoSU1 * v * v * u2);
289
+ const y = f((1n + ss) * v * u1);
290
+ return curve.ExtendedPoint.fromAffine({ x, y });
291
+ }
292
+ function isIdentity(point) {
293
+ return point.ex === 0n;
294
+ }
295
+
296
+ // src/fmd/fmd.ts
297
+ function requireBytes(value, length, name) {
298
+ if (!(value instanceof Uint8Array) || value.length !== length)
299
+ throw new TypeError(`${name} must be a ${length}-byte Uint8Array`);
300
+ }
301
+ function validateClueKey(clueKey) {
302
+ requireBytes(clueKey, 32, "Clue key");
303
+ if (isIdentity(decodePoint(clueKey))) throw new Error("Clue key must not be the identity");
304
+ }
305
+
306
+ // src/notes/noteContext.ts
307
+ function assertNoteContext(note, context) {
308
+ if (note.chainId !== context.chainId || note.protocolAddress !== context.protocolAddress) {
309
+ throw new Error("note context mismatch");
310
+ }
311
+ }
312
+
313
+ // src/credit/state.ts
314
+ var CREDIT_POLICY_FIELDS = ["singleLimit", "dailyLimit", "monthlyLimit"];
315
+ var CREDIT_USAGE_FIELDS = [
316
+ "lastDay",
317
+ "dailySpent",
318
+ "lastMonth",
319
+ "monthlySpent",
320
+ "totalSpent"
321
+ ];
322
+ function normalizeCreditPolicy(value = {}) {
323
+ return Object.fromEntries(
324
+ CREDIT_POLICY_FIELDS.map((key) => {
325
+ const n = value[key] ?? 0n;
326
+ uint(n, 126, key);
327
+ return [key, n];
328
+ })
329
+ );
330
+ }
331
+ function normalizeCreditUsage(value = {}) {
332
+ const usage = Object.fromEntries(
333
+ CREDIT_USAGE_FIELDS.map((key) => {
334
+ const n = value[key] ?? 0n;
335
+ uint(n, key === "lastDay" || key === "lastMonth" ? 64 : 128, key);
336
+ return [key, n];
337
+ })
338
+ );
339
+ for (const [period, spent] of [
340
+ ["lastDay", "dailySpent"],
341
+ ["lastMonth", "monthlySpent"]
342
+ ])
343
+ if (usage[period] === 0n && usage[spent] !== 0n) throw Error("noncanonical Credit usage");
344
+ return usage;
345
+ }
346
+ function balance(value) {
347
+ uint(value.availableCredit, 128, "availableCredit");
348
+ if (typeof value.unlimited !== "boolean") throw TypeError("unlimited must be boolean");
349
+ if (value.unlimited && value.availableCredit !== 0n)
350
+ throw Error("unlimited Credit must have zero available credit");
351
+ return { availableCredit: value.availableCredit, unlimited: value.unlimited };
352
+ }
353
+ function normalizeCreditState(state) {
354
+ const allowed = [
355
+ "chainId",
356
+ "protocolAddress",
357
+ "tokenAddress",
358
+ "spenderWalletIdentity",
359
+ "ownerWalletIdentity",
360
+ "revocationShard",
361
+ "revocationSlot",
362
+ "nonce",
363
+ "expiry",
364
+ "creditSharedKey",
365
+ ...CREDIT_POLICY_FIELDS,
366
+ ...CREDIT_USAGE_FIELDS,
367
+ "availableCredit",
368
+ "unlimited",
369
+ "payload"
370
+ ];
371
+ if (!state || typeof state !== "object" || Object.keys(state).some((k) => !allowed.includes(k)))
372
+ throw Error("Unsupported Credit fields");
373
+ for (const [name, bits] of [
374
+ ["chainId", 64],
375
+ ["protocolAddress", 160],
376
+ ["tokenAddress", 160],
377
+ ["revocationShard", 64],
378
+ ["revocationSlot", 16],
379
+ ["expiry", 64]
380
+ ])
381
+ uint(state[name], bits, name);
382
+ for (const id of [state.spenderWalletIdentity, state.ownerWalletIdentity])
383
+ if (!/^0x[0-9a-fA-F]{40}$/.test(id) || BigInt(id) === 0n)
384
+ throw Error("invalid Credit identity");
385
+ if (!state.protocolAddress || !state.tokenAddress || !state.revocationShard || !state.expiry)
386
+ throw Error("Credit deployment, token, shard and expiry must be positive");
387
+ field2(state.nonce, "nonce");
388
+ field2(state.creditSharedKey, "creditSharedKey");
389
+ if (!state.creditSharedKey) throw Error("Credit shared key must be positive");
390
+ if (state.payload !== void 0 && !(state.payload instanceof Uint8Array))
391
+ throw TypeError("payload must be Uint8Array");
392
+ return {
393
+ ...state,
394
+ ...normalizeCreditPolicy(state),
395
+ ...normalizeCreditUsage(state),
396
+ ...balance(state),
397
+ ...state.payload !== void 0 ? { payload: Uint8Array.from(state.payload) } : {}
398
+ };
399
+ }
400
+ function uint(value, bits, name) {
401
+ if (typeof value !== "bigint" || value < 0n || value >= 1n << BigInt(bits))
402
+ throw new RangeError(`${name} out of uint${bits} range`);
403
+ }
404
+ function field2(value, name) {
405
+ if (typeof value !== "bigint" || value < 0n || value >= FIELD_MODULUS)
406
+ throw new RangeError(`${name} out of BN254 field range`);
407
+ }
408
+
409
+ // src/delivery/note-payload.ts
410
+ function concat(...parts) {
411
+ const out = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
412
+ let offset = 0;
413
+ for (const part of parts) {
414
+ out.set(part, offset);
415
+ offset += part.length;
416
+ }
417
+ return out;
418
+ }
419
+ function uint2(value, bits, name) {
420
+ if (value < 0n || value >= 1n << BigInt(bits))
421
+ throw new RangeError(`${name} out of uint${bits} range`);
422
+ }
423
+ function encode(value, length = 32) {
424
+ uint2(value, length * 8, "encoded value");
425
+ const out = new Uint8Array(length);
426
+ for (let i = length - 1; i >= 0; i--) {
427
+ out[i] = Number(value & 255n);
428
+ value >>= 8n;
429
+ }
430
+ return out;
431
+ }
432
+ function decode(value) {
433
+ return value.reduce((result, byte) => result << 8n | BigInt(byte), 0n);
434
+ }
435
+ function hexField(value) {
436
+ uint2(value, 160, "owner address");
437
+ return `0x${value.toString(16).padStart(40, "0")}`;
438
+ }
439
+ function receivingKeys(keys) {
440
+ if (!keys || !(keys.viewingPublicKey instanceof Uint8Array) || !(keys.clueKey instanceof Uint8Array))
441
+ throw new Error("receiving keys required");
442
+ const viewingPublicKey2 = Uint8Array.from(keys.viewingPublicKey), clueKey = Uint8Array.from(keys.clueKey);
443
+ if (viewingPublicKey2.length !== 33 || viewingPublicKey2[0] !== 2 && viewingPublicKey2[0] !== 3)
444
+ throw new Error("invalid compressed viewing public key");
445
+ import_secp256k1.secp256k1.ProjectivePoint.fromHex(viewingPublicKey2).assertValidity();
446
+ if (clueKey.length !== 32) throw new Error("invalid clue key length");
447
+ validateClueKey(clueKey);
448
+ return { viewingPublicKey: viewingPublicKey2, clueKey };
449
+ }
450
+ function normalizeCreditDeliveryState(state) {
451
+ if (!state || typeof state !== "object" || !state.note || typeof state.note !== "object")
452
+ throw new TypeError("complete Credit delivery state required");
453
+ const allowed = [
454
+ "chainId",
455
+ "protocolAddress",
456
+ "tokenAddress",
457
+ "spenderWalletIdentity",
458
+ "ownerWalletIdentity",
459
+ "revocationShard",
460
+ "revocationSlot",
461
+ "nonce",
462
+ "expiry",
463
+ "creditSharedKey",
464
+ "singleLimit",
465
+ "dailyLimit",
466
+ "monthlyLimit",
467
+ "availableCredit",
468
+ "unlimited",
469
+ "lastDay",
470
+ "dailySpent",
471
+ "lastMonth",
472
+ "monthlySpent",
473
+ "totalSpent",
474
+ "payload"
475
+ ];
476
+ if (Object.keys(state.note).some((k) => !allowed.includes(k)))
477
+ throw Error("Unsupported Credit fields");
478
+ const note = normalizeCreditState(structuredClone(state.note));
479
+ return {
480
+ note: {
481
+ ...note,
482
+ ...normalizeCreditPolicy(note)
483
+ },
484
+ ownerReceivingKeys: receivingKeys(state.ownerReceivingKeys),
485
+ spenderReceivingKeys: receivingKeys(state.spenderReceivingKeys)
486
+ };
487
+ }
488
+ function encodePayload(value) {
489
+ if (value !== void 0 && !(value instanceof Uint8Array))
490
+ throw new TypeError("payload must be Uint8Array");
491
+ const payload = value ?? new Uint8Array();
492
+ if (payload.length > 65535) throw new RangeError("payload length exceeds uint16");
493
+ return concat(encode(BigInt(payload.length), 2), payload);
494
+ }
495
+ function readPayload(plain, offset) {
496
+ if (plain.length < offset + 2) throw new Error("missing payload length");
497
+ const length = Number(decode(plain.slice(offset, offset + 2)));
498
+ if (plain.length !== offset + 2 + length) throw new Error("invalid payload length");
499
+ return Uint8Array.from(plain.subarray(offset + 2));
500
+ }
501
+ var fundsEnvelopeV1 = {
502
+ kind: "funds",
503
+ version: 1,
504
+ minimum: 160,
505
+ maximum: 4096,
506
+ encode(note) {
507
+ return concat(
508
+ encode(BigInt(note.ownerAddress)),
509
+ encode(note.amount, 16),
510
+ encode(note.nonce),
511
+ encodePayload(note.payload)
512
+ );
513
+ },
514
+ decode(plain, context) {
515
+ return {
516
+ chainId: context.chainId,
517
+ protocolAddress: context.protocolAddress,
518
+ tokenAddress: context.tokenAddress,
519
+ ownerAddress: hexField(decode(plain.slice(0, 32))),
520
+ amount: decode(plain.slice(32, 48)),
521
+ nonce: decode(plain.slice(48, 80)),
522
+ payload: readPayload(plain, 80)
523
+ };
524
+ }
525
+ };
526
+ var creditWireFields = [
527
+ ["spenderWalletIdentity", 32],
528
+ ["ownerWalletIdentity", 32],
529
+ ["revocationShard", 8],
530
+ ["revocationSlot", 2],
531
+ ["nonce", 32],
532
+ ["expiry", 8],
533
+ ["creditSharedKey", 32],
534
+ ["singleLimit", 16],
535
+ ["dailyLimit", 16],
536
+ ["monthlyLimit", 16],
537
+ ["availableCredit", 16],
538
+ ["unlimited", 1],
539
+ ["lastDay", 8],
540
+ ["dailySpent", 16],
541
+ ["lastMonth", 8],
542
+ ["monthlySpent", 16],
543
+ ["totalSpent", 16]
544
+ ];
545
+ var creditEnvelopeV2 = {
546
+ kind: "credit",
547
+ version: 2,
548
+ minimum: 485,
549
+ maximum: 4096,
550
+ encode(input) {
551
+ const state = normalizeCreditDeliveryState(input);
552
+ return concat(
553
+ ...creditWireFields.map(([k, size]) => encode(BigInt(state.note[k]), size)),
554
+ state.ownerReceivingKeys.viewingPublicKey,
555
+ state.ownerReceivingKeys.clueKey,
556
+ state.spenderReceivingKeys.viewingPublicKey,
557
+ state.spenderReceivingKeys.clueKey,
558
+ encodePayload(state.note.payload)
559
+ );
560
+ },
561
+ decode(plain, context) {
562
+ let offset = 0;
563
+ const note = {
564
+ chainId: context.chainId,
565
+ protocolAddress: context.protocolAddress,
566
+ tokenAddress: context.tokenAddress
567
+ };
568
+ for (const [k, size] of creditWireFields) {
569
+ const n = decode(plain.slice(offset, offset + size));
570
+ if (k === "unlimited" && n !== 0n && n !== 1n)
571
+ throw Error("invalid Credit unlimited byte");
572
+ note[k] = k === "unlimited" ? n === 1n : k.endsWith("Identity") ? hexField(n) : n;
573
+ offset += size;
574
+ }
575
+ const keys = () => {
576
+ const k = {
577
+ viewingPublicKey: plain.slice(offset, offset + 33),
578
+ clueKey: plain.slice(offset + 33, offset + 65)
579
+ };
580
+ offset += 65;
581
+ return k;
582
+ };
583
+ const ownerReceivingKeys = keys(), spenderReceivingKeys = keys();
584
+ note.payload = readPayload(plain, offset);
585
+ return normalizeCreditDeliveryState({
586
+ note,
587
+ ownerReceivingKeys,
588
+ spenderReceivingKeys
589
+ });
590
+ }
591
+ };
592
+
593
+ // src/delivery/delivery-codec.ts
594
+ var MAX_CIPHERTEXT_BYTES = 4096;
595
+ function deliveryHeader(kind) {
596
+ if (kind !== "funds" && kind !== "credit") throw new Error("unsupported delivery kind");
597
+ return kind === "credit" ? 130 : 1;
598
+ }
599
+ function decodeDeliveryHeader(header) {
600
+ if (!Number.isInteger(header) || header < 0 || header > 255)
601
+ throw new Error("delivery header must be one byte");
602
+ const kind = header >>> 7 ? "credit" : "funds";
603
+ const version = header & 127;
604
+ if (version === 0) throw new Error("invalid envelope version");
605
+ return { kind, version };
606
+ }
607
+ function deliveryCodec(header) {
608
+ const { kind, version } = decodeDeliveryHeader(header);
609
+ if (version !== (kind === "credit" ? 2 : 1))
610
+ throw new Error(`unsupported envelope version ${version}`);
611
+ const codec = kind === "funds" ? fundsEnvelopeV1 : creditEnvelopeV2;
612
+ return {
613
+ ...codec,
614
+ domain: `Invisi.${kind === "funds" ? "Note" : "Credit"}Delivery.v${kind === "credit" ? 2 : 1}`
615
+ };
616
+ }
617
+ function validateDeliveryCiphertext(value, kind) {
618
+ const data = Uint8Array.from((0, import_ethers.getBytes)(value));
619
+ if (data.length === 0 || data.length > MAX_CIPHERTEXT_BYTES)
620
+ throw new Error("invalid envelope length");
621
+ const codec = deliveryCodec(data[0]);
622
+ if (kind !== void 0 && codec.kind !== kind) throw new Error("unexpected envelope kind");
623
+ if (data.length < codec.minimum || data.length > codec.maximum)
624
+ throw new Error("invalid envelope length");
625
+ return data;
626
+ }
627
+
628
+ // src/delivery/errors.ts
629
+ var DeliveryAuthenticationError = class extends Error {
630
+ constructor(cause) {
631
+ super("delivery authentication failed", { cause });
632
+ this.name = "DeliveryAuthenticationError";
633
+ }
634
+ };
635
+
636
+ // src/delivery/envelope.ts
637
+ var import_secp256k12 = require("@noble/curves/secp256k1");
638
+
639
+ // src/delivery/binary.ts
640
+ var ascii = (value) => Uint8Array.from(value, (character) => character.charCodeAt(0));
641
+ function concat2(...parts) {
642
+ const out = new Uint8Array(parts.reduce((size, p) => size + p.length, 0));
643
+ let offset = 0;
644
+ for (const part of parts) {
645
+ out.set(part, offset);
646
+ offset += part.length;
647
+ }
648
+ return out;
649
+ }
650
+ function bytes(value, length) {
651
+ let out;
652
+ if (typeof value === "string") {
653
+ if (!/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) throw new Error("invalid hexadecimal bytes");
654
+ out = Uint8Array.from(value.slice(2).match(/../g) ?? [], (b) => parseInt(b, 16));
655
+ } else if (value instanceof Uint8Array) out = Uint8Array.from(value);
656
+ else throw new Error("expected hexadecimal bytes or Uint8Array");
657
+ if (out.length !== length) throw new Error(`expected ${length} bytes`);
658
+ return out;
659
+ }
660
+ function uint3(value, bits, name) {
661
+ if (value < 0n || value >= 1n << BigInt(bits))
662
+ throw new RangeError(`${name} out of uint${bits} range`);
663
+ }
664
+ function field3(value, name) {
665
+ if (value < 0n || value >= FIELD_MODULUS)
666
+ throw new RangeError(`${name} out of BN254 field range`);
667
+ }
668
+ function encode2(value, length = 32) {
669
+ uint3(value, length * 8, "encoded value");
670
+ const out = new Uint8Array(length);
671
+ for (let i = length - 1; i >= 0; i--) {
672
+ out[i] = Number(value & 255n);
673
+ value >>= 8n;
674
+ }
675
+ return out;
676
+ }
677
+
678
+ // src/delivery/validation.ts
679
+ function validateContext(context, tokenAddress) {
680
+ uint3(context.chainId, 64, "chainId");
681
+ uint3(context.protocolAddress, 160, "protocolAddress");
682
+ uint3(tokenAddress, 160, "tokenAddress");
683
+ field3(BigInt(context.outputCommitment), "outputCommitment");
684
+ }
685
+ function validateNote(note) {
686
+ uint3(note.amount, 128, "amount");
687
+ if (note.amount === 0n) throw new Error("amount must be positive");
688
+ field3(note.nonce, "nonce");
689
+ uint3(BigInt(note.ownerAddress), 160, "ownerAddress");
690
+ if (BigInt(note.ownerAddress) === 0n) throw new Error("owner address must be positive");
691
+ uint3(note.tokenAddress, 160, "tokenAddress");
692
+ }
693
+ async function noteCommitment(context, note) {
694
+ validateContext(context, note.tokenAddress);
695
+ assertNoteContext(note, context);
696
+ validateNote(note);
697
+ const commitment = await computeNoteCommitment(
698
+ context.chainId,
699
+ BigInt(context.protocolAddress),
700
+ await computeNoteIdentity(BigInt(note.ownerAddress), note.nonce),
701
+ note.tokenAddress,
702
+ note.amount
703
+ );
704
+ if (BigInt(commitment) !== BigInt(context.outputCommitment))
705
+ throw new Error("output commitment mismatch");
706
+ }
707
+
708
+ // src/delivery/envelope.ts
709
+ function aad(domain, context, tokenAddress, header, role) {
710
+ validateContext(context, tokenAddress);
711
+ return concat2(
712
+ domain,
713
+ header,
714
+ new Uint8Array([role]),
715
+ encode2(context.chainId, 8),
716
+ encode2(context.protocolAddress, 20),
717
+ encode2(tokenAddress, 20),
718
+ encode2(BigInt(context.outputCommitment))
719
+ );
720
+ }
721
+ function privateKey(value) {
722
+ const key = bytes(value, 32);
723
+ if (!import_secp256k12.secp256k1.utils.isValidPrivateKey(key)) throw new Error("invalid viewing private key");
724
+ return key;
725
+ }
726
+ function publicKey(value) {
727
+ const key = bytes(value, 33);
728
+ if (key[0] !== 2 && key[0] !== 3) throw new Error("expected compressed secp256k1 public key");
729
+ import_secp256k12.secp256k1.ProjectivePoint.fromHex(key);
730
+ return key;
731
+ }
732
+ function random(length) {
733
+ return crypto.getRandomValues(new Uint8Array(length));
734
+ }
735
+ function ephemeralKey() {
736
+ for (; ; ) {
737
+ const key = random(32);
738
+ if (import_secp256k12.secp256k1.utils.isValidPrivateKey(key)) return key;
739
+ }
740
+ }
741
+ var buffer = (value) => Uint8Array.from(value).buffer;
742
+ async function derivedKey(key, peer, header, recipient, domain, extractable = false) {
743
+ const secret = import_secp256k12.secp256k1.getSharedSecret(key, peer, true).slice(1);
744
+ const material = await crypto.subtle.importKey("raw", buffer(secret), "HKDF", false, [
745
+ "deriveKey"
746
+ ]);
747
+ try {
748
+ return await crypto.subtle.deriveKey(
749
+ {
750
+ name: "HKDF",
751
+ hash: "SHA-256",
752
+ salt: buffer(header.slice(34, 50)),
753
+ info: buffer(concat2(domain, header.slice(1, 34), recipient))
754
+ },
755
+ material,
756
+ { name: "AES-GCM", length: 256 },
757
+ extractable,
758
+ ["encrypt", "decrypt"]
759
+ );
760
+ } finally {
761
+ secret.fill(0);
762
+ }
763
+ }
764
+ async function seal(viewingKey, plaintext, context, tokenAddress, headerByte, role) {
765
+ const peer = publicKey(viewingKey), key = ephemeralKey();
766
+ const salt = random(16), iv = random(12), domain = deliveryDomain(headerByte);
767
+ const header = concat2(
768
+ new Uint8Array([headerByte]),
769
+ import_secp256k12.secp256k1.getPublicKey(key, true),
770
+ salt,
771
+ iv
772
+ );
773
+ const additionalData = aad(domain, context, tokenAddress, header, role);
774
+ try {
775
+ const encrypted = await crypto.subtle.encrypt(
776
+ {
777
+ name: "AES-GCM",
778
+ iv: buffer(iv),
779
+ additionalData: buffer(additionalData),
780
+ tagLength: 128
781
+ },
782
+ await derivedKey(key, peer, header, peer, domain),
783
+ buffer(plaintext)
784
+ );
785
+ return concat2(header, new Uint8Array(encrypted));
786
+ } finally {
787
+ key.fill(0);
788
+ plaintext.fill(0);
789
+ }
790
+ }
791
+ async function open(key, envelope, context, headerByte, role, payloadKey = false) {
792
+ const data = envelopeBytes(envelope, deliveryCodec(headerByte).kind === "credit");
793
+ if (data[0] !== headerByte) throw new Error("unsupported envelope version");
794
+ const domain = deliveryDomain(headerByte);
795
+ const additionalData = aad(domain, context, context.tokenAddress, data.slice(0, 62), role);
796
+ const localKey = payloadKey ? bytes(key, 32) : privateKey(key);
797
+ try {
798
+ const aes = payloadKey ? await crypto.subtle.importKey("raw", buffer(bytes(key, 32)), "AES-GCM", false, [
799
+ "decrypt"
800
+ ]) : await derivedKey(
801
+ localKey,
802
+ publicKey(data.slice(1, 34)),
803
+ data.slice(0, 62),
804
+ import_secp256k12.secp256k1.getPublicKey(localKey, true),
805
+ domain
806
+ );
807
+ const decrypted = await crypto.subtle.decrypt(
808
+ {
809
+ name: "AES-GCM",
810
+ iv: buffer(data.slice(50, 62)),
811
+ additionalData: buffer(additionalData),
812
+ tagLength: 128
813
+ },
814
+ aes,
815
+ buffer(data.slice(62))
816
+ ).catch((error) => {
817
+ if (error instanceof Error && error.name === "OperationError")
818
+ throw new DeliveryAuthenticationError(error);
819
+ throw error;
820
+ });
821
+ return new Uint8Array(decrypted);
822
+ } finally {
823
+ localKey.fill(0);
824
+ }
825
+ }
826
+ function deliveryDomain(headerByte) {
827
+ return ascii(deliveryCodec(headerByte).domain);
828
+ }
829
+ function envelopeBytes(value, credit) {
830
+ return validateDeliveryCiphertext(value, credit ? "credit" : "funds");
831
+ }
832
+
833
+ // src/delivery/encryption.ts
834
+ function copyPayload(value, codec) {
835
+ if (!(value instanceof Uint8Array)) throw new Error("codec encode must return Uint8Array");
836
+ if (value.length + 78 < codec.minimum || value.length + 78 > codec.maximum)
837
+ throw new Error("invalid codec payload length");
838
+ return Uint8Array.from(value);
839
+ }
840
+ async function encryptPrivateTransferNote(viewingKey, note, context) {
841
+ const scopedNote = structuredClone(note), scopedContext = { ...context };
842
+ const codec = deliveryCodec(deliveryHeader("funds"));
843
+ if (codec.kind !== "funds") throw new Error("unexpected envelope kind");
844
+ await noteCommitment(scopedContext, scopedNote);
845
+ const plaintext = copyPayload(codec.encode(structuredClone(scopedNote)), codec);
846
+ return seal(
847
+ viewingKey,
848
+ plaintext,
849
+ scopedContext,
850
+ scopedNote.tokenAddress,
851
+ deliveryHeader("funds"),
852
+ 0
853
+ );
854
+ }
855
+ async function readNote(key, envelope, context, payloadKey = false) {
856
+ const authenticatedContext = { ...context };
857
+ const data = envelopeBytes(envelope, false);
858
+ const headerByte = data[0];
859
+ const plain = await open(key, data, authenticatedContext, headerByte, 0, payloadKey);
860
+ try {
861
+ const codec = deliveryCodec(headerByte);
862
+ if (codec.kind !== "funds") throw new Error("unexpected envelope kind");
863
+ const note = structuredClone(
864
+ codec.decode(plain, Object.freeze({ ...authenticatedContext }))
865
+ );
866
+ if (BigInt(note.ownerAddress) !== BigInt(authenticatedContext.ownerAddress))
867
+ throw new Error("recipient owner address mismatch");
868
+ if (note.tokenAddress !== authenticatedContext.tokenAddress)
869
+ throw new Error("note token context mismatch");
870
+ await noteCommitment(authenticatedContext, note);
871
+ return note;
872
+ } finally {
873
+ plain.fill(0);
874
+ }
875
+ }
876
+ function decryptPrivateTransferNote(key, envelope, context) {
877
+ return readNote(key, envelope, context);
878
+ }
879
+ // Annotate the CommonJS export names for ESM import in node:
880
+ 0 && (module.exports = {
881
+ computeNoteCommitment,
882
+ computeNoteIdentity,
883
+ computeNoteNullifier,
884
+ decryptPrivateTransferNote,
885
+ encryptPrivateTransferNote
886
+ });
887
+ //# sourceMappingURL=note.cjs.map