@blindmarket/sdk 0.1.7 → 0.1.8

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 (133) hide show
  1. package/dist/chain/BlindEscrowClient.d.ts +2 -0
  2. package/dist/chain/BlindEscrowClient.js +14 -6
  3. package/dist/chain/BlindReputationClient.d.ts +3 -0
  4. package/dist/chain/BlindReputationClient.js +3 -1
  5. package/dist/chain/ChainClient.d.ts +5 -2
  6. package/dist/chain/ChainClient.js +5 -0
  7. package/dist/chain/IBlindMarketChain.d.ts +74 -0
  8. package/dist/chain/IBlindMarketChain.js +1 -0
  9. package/dist/chain/TaskRegistryClient.d.ts +2 -1
  10. package/dist/chain/TaskRegistryClient.js +15 -7
  11. package/dist/chain/createChainAdapter.d.ts +25 -0
  12. package/dist/chain/createChainAdapter.js +24 -0
  13. package/dist/chain/domain-types.d.ts +77 -0
  14. package/dist/chain/domain-types.js +1 -0
  15. package/dist/chain/evm/EVMChainAdapter.d.ts +56 -0
  16. package/dist/chain/evm/EVMChainAdapter.js +161 -0
  17. package/dist/chain/evm/index.d.ts +1 -0
  18. package/dist/chain/evm/index.js +1 -0
  19. package/dist/chain/index.d.ts +4 -0
  20. package/dist/chain/index.js +5 -0
  21. package/dist/executor/WorkerRuntime.d.ts +113 -0
  22. package/dist/executor/WorkerRuntime.js +248 -0
  23. package/dist/executor/index.d.ts +1 -0
  24. package/dist/executor/index.js +1 -0
  25. package/dist/index.d.ts +7 -0
  26. package/dist/index.js +8 -3
  27. package/dist/network/presets.d.ts +33 -5
  28. package/dist/network/presets.js +35 -8
  29. package/dist/network/resolve.d.ts +12 -3
  30. package/dist/network/resolve.js +15 -7
  31. package/dist/network/types.d.ts +3 -16
  32. package/dist/types.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/src/chain/BlindEscrowClient.ts +15 -6
  35. package/src/chain/BlindReputationClient.ts +6 -1
  36. package/src/chain/ChainClient.ts +9 -3
  37. package/src/chain/IBlindMarketChain.ts +109 -0
  38. package/src/chain/TaskRegistryClient.ts +17 -8
  39. package/src/chain/createChainAdapter.ts +40 -0
  40. package/src/chain/domain-types.ts +92 -0
  41. package/src/chain/evm/EVMChainAdapter.ts +212 -0
  42. package/src/chain/evm/index.ts +1 -0
  43. package/src/chain/index.ts +6 -0
  44. package/src/executor/WorkerRuntime.ts +338 -0
  45. package/src/executor/index.ts +8 -0
  46. package/src/index.ts +23 -4
  47. package/src/network/presets.ts +47 -8
  48. package/src/network/resolve.ts +20 -8
  49. package/src/network/types.ts +18 -16
  50. package/src/signer/index.ts +1 -1
  51. package/src/types.ts +2 -1
  52. package/dist/BlindEscrowClient-CyPuKMge.d.cts +0 -54
  53. package/dist/BlindEscrowClient-R7iGpE-n.d.ts +0 -54
  54. package/dist/KeyStore-Be_SSpCt.d.cts +0 -21
  55. package/dist/KeyStore-k1JgYPJY.d.ts +0 -21
  56. package/dist/Signer-BnqH_qew.d.cts +0 -38
  57. package/dist/Signer-LColE0Uo.d.ts +0 -38
  58. package/dist/Storage-4QOrh7rm.d.ts +0 -17
  59. package/dist/Storage-Cf4IJRMk.d.cts +0 -17
  60. package/dist/TaskRegistryClient-Ch6lYqM_.d.ts +0 -24
  61. package/dist/TaskRegistryClient-CrQjddDc.d.cts +0 -24
  62. package/dist/aes-J-7HrHze.d.cts +0 -17
  63. package/dist/aes-J-7HrHze.d.ts +0 -17
  64. package/dist/agent/index.cjs +0 -425
  65. package/dist/agent/index.cjs.map +0 -1
  66. package/dist/agent/index.d.cts +0 -63
  67. package/dist/agent/index.js.map +0 -1
  68. package/dist/api/index.cjs +0 -4
  69. package/dist/api/index.cjs.map +0 -1
  70. package/dist/api/index.d.cts +0 -2
  71. package/dist/api/index.js.map +0 -1
  72. package/dist/chain/index.cjs +0 -2484
  73. package/dist/chain/index.cjs.map +0 -1
  74. package/dist/chain/index.d.cts +0 -2305
  75. package/dist/chain/index.js.map +0 -1
  76. package/dist/compute/index.cjs +0 -4
  77. package/dist/compute/index.cjs.map +0 -1
  78. package/dist/compute/index.d.cts +0 -2
  79. package/dist/compute/index.js.map +0 -1
  80. package/dist/crypto/index.cjs +0 -424
  81. package/dist/crypto/index.cjs.map +0 -1
  82. package/dist/crypto/index.d.cts +0 -74
  83. package/dist/crypto/index.js.map +0 -1
  84. package/dist/errors/BlindBountyError.d.ts +0 -14
  85. package/dist/errors/BlindBountyError.js +0 -30
  86. package/dist/errors/index.cjs +0 -136
  87. package/dist/errors/index.cjs.map +0 -1
  88. package/dist/errors/index.d.cts +0 -60
  89. package/dist/errors/index.js.map +0 -1
  90. package/dist/events/index.cjs +0 -41
  91. package/dist/events/index.cjs.map +0 -1
  92. package/dist/events/index.d.cts +0 -61
  93. package/dist/events/index.js.map +0 -1
  94. package/dist/index.cjs +0 -4
  95. package/dist/index.cjs.map +0 -1
  96. package/dist/index.d.cts +0 -2
  97. package/dist/index.js.map +0 -1
  98. package/dist/keystore/index.cjs +0 -335
  99. package/dist/keystore/index.cjs.map +0 -1
  100. package/dist/keystore/index.d.cts +0 -23
  101. package/dist/keystore/index.js.map +0 -1
  102. package/dist/mcp.d.ts +0 -23
  103. package/dist/mcp.js +0 -101
  104. package/dist/network/index.cjs +0 -74
  105. package/dist/network/index.cjs.map +0 -1
  106. package/dist/network/index.d.cts +0 -36
  107. package/dist/network/index.js.map +0 -1
  108. package/dist/signer/index.cjs +0 -121
  109. package/dist/signer/index.cjs.map +0 -1
  110. package/dist/signer/index.d.cts +0 -40
  111. package/dist/signer/index.js.map +0 -1
  112. package/dist/storage/ZgStorage.d.ts +0 -24
  113. package/dist/storage/ZgStorage.js +0 -102
  114. package/dist/storage/index.cjs +0 -221
  115. package/dist/storage/index.cjs.map +0 -1
  116. package/dist/storage/index.d.cts +0 -44
  117. package/dist/storage/index.js.map +0 -1
  118. package/dist/testing/index.cjs +0 -4
  119. package/dist/testing/index.cjs.map +0 -1
  120. package/dist/testing/index.d.cts +0 -2
  121. package/dist/testing/index.js.map +0 -1
  122. package/dist/types-BOG5Ub1z.d.cts +0 -31
  123. package/dist/types-BOG5Ub1z.d.ts +0 -31
  124. package/dist/types-V7_ZmUb-.d.cts +0 -19
  125. package/dist/types-hAsITUQ7.d.ts +0 -19
  126. package/dist/verifier/index.cjs +0 -4
  127. package/dist/verifier/index.cjs.map +0 -1
  128. package/dist/verifier/index.d.cts +0 -2
  129. package/dist/verifier/index.js.map +0 -1
  130. package/dist/worker/index.cjs +0 -382
  131. package/dist/worker/index.cjs.map +0 -1
  132. package/dist/worker/index.d.cts +0 -58
  133. package/dist/worker/index.js.map +0 -1
@@ -1,424 +0,0 @@
1
- 'use strict';
2
-
3
- var ethers = require('ethers');
4
-
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
-
15
- // src/crypto/constants.ts
16
- exports.IV_LENGTH = void 0; exports.TAG_LENGTH = void 0; exports.KEY_LENGTH = void 0; exports.ECIES_PUBKEY_LENGTH = void 0; exports.ECIES_HKDF_INFO = void 0; exports.AES_MIN_BLOB = void 0; exports.ECIES_MIN_BLOB = void 0;
17
- var init_constants = __esm({
18
- "src/crypto/constants.ts"() {
19
- exports.IV_LENGTH = 12;
20
- exports.TAG_LENGTH = 16;
21
- exports.KEY_LENGTH = 32;
22
- exports.ECIES_PUBKEY_LENGTH = 65;
23
- exports.ECIES_HKDF_INFO = new TextEncoder().encode("BlindBounty-ECIES-v1");
24
- exports.AES_MIN_BLOB = exports.IV_LENGTH + exports.TAG_LENGTH;
25
- exports.ECIES_MIN_BLOB = exports.ECIES_PUBKEY_LENGTH + exports.AES_MIN_BLOB;
26
- }
27
- });
28
-
29
- // src/errors/codes.ts
30
- var init_codes = __esm({
31
- "src/errors/codes.ts"() {
32
- }
33
- });
34
-
35
- // src/errors/BlindBountyError.ts
36
- var BlindBountyError;
37
- var init_BlindBountyError = __esm({
38
- "src/errors/BlindBountyError.ts"() {
39
- BlindBountyError = class extends Error {
40
- code;
41
- retriable;
42
- context;
43
- cause;
44
- constructor(code, message, opts = {}) {
45
- super(message);
46
- this.code = code;
47
- this.retriable = opts.retriable ?? false;
48
- if (opts.context !== void 0) this.context = opts.context;
49
- if (opts.cause !== void 0) this.cause = opts.cause;
50
- Object.defineProperty(this, "name", {
51
- value: this.constructor.name,
52
- enumerable: false,
53
- configurable: true,
54
- writable: true
55
- });
56
- }
57
- toJSON() {
58
- return {
59
- name: this.name,
60
- code: this.code,
61
- message: this.message,
62
- retriable: this.retriable,
63
- ...this.context ? { context: this.context } : {}
64
- };
65
- }
66
- };
67
- }
68
- });
69
-
70
- // src/errors/subclasses.ts
71
- var CryptoError;
72
- var init_subclasses = __esm({
73
- "src/errors/subclasses.ts"() {
74
- init_BlindBountyError();
75
- CryptoError = class extends BlindBountyError {
76
- constructor(code, msg, opts) {
77
- super(code, msg, opts);
78
- }
79
- };
80
- }
81
- });
82
-
83
- // src/errors/index.ts
84
- var init_errors = __esm({
85
- "src/errors/index.ts"() {
86
- init_codes();
87
- init_BlindBountyError();
88
- init_subclasses();
89
- }
90
- });
91
-
92
- // src/crypto/aes.ts
93
- function getCrypto() {
94
- const c = globalThis.crypto;
95
- if (!c?.subtle) {
96
- throw new CryptoError("CRYPTO/UNSUPPORTED_CIPHER", "Web Crypto (crypto.subtle) is not available");
97
- }
98
- return c;
99
- }
100
- function toArrayBuffer(u) {
101
- const ab = new ArrayBuffer(u.byteLength);
102
- new Uint8Array(ab).set(u);
103
- return ab;
104
- }
105
- async function generateAesKey() {
106
- const key = new Uint8Array(exports.KEY_LENGTH);
107
- getCrypto().getRandomValues(key);
108
- return key;
109
- }
110
- async function aesEncrypt(plaintext, key) {
111
- if (key.byteLength !== exports.KEY_LENGTH) {
112
- throw new CryptoError(
113
- "CRYPTO/INVALID_KEY",
114
- `AES key must be ${exports.KEY_LENGTH} bytes, got ${key.byteLength}`
115
- );
116
- }
117
- const c = getCrypto();
118
- const iv = new Uint8Array(exports.IV_LENGTH);
119
- c.getRandomValues(iv);
120
- try {
121
- const ck = await c.subtle.importKey("raw", toArrayBuffer(key), "AES-GCM", false, ["encrypt"]);
122
- const wcOut = new Uint8Array(
123
- await c.subtle.encrypt(
124
- { name: "AES-GCM", iv: toArrayBuffer(iv), tagLength: exports.TAG_LENGTH * 8 },
125
- ck,
126
- toArrayBuffer(plaintext)
127
- )
128
- );
129
- const ctLen = wcOut.length - exports.TAG_LENGTH;
130
- const ct = wcOut.subarray(0, ctLen);
131
- const tag = wcOut.subarray(ctLen);
132
- const blob = new Uint8Array(exports.IV_LENGTH + exports.TAG_LENGTH + ctLen);
133
- blob.set(iv, 0);
134
- blob.set(tag, exports.IV_LENGTH);
135
- blob.set(ct, exports.IV_LENGTH + exports.TAG_LENGTH);
136
- return blob;
137
- } catch (cause) {
138
- throw new CryptoError("CRYPTO/DECRYPT_FAILED", "AES-GCM encryption failed", { cause });
139
- }
140
- }
141
- async function aesDecrypt(blob, key) {
142
- if (key.byteLength !== exports.KEY_LENGTH) {
143
- throw new CryptoError(
144
- "CRYPTO/INVALID_KEY",
145
- `AES key must be ${exports.KEY_LENGTH} bytes, got ${key.byteLength}`
146
- );
147
- }
148
- if (blob.byteLength < exports.AES_MIN_BLOB) {
149
- throw new CryptoError(
150
- "CRYPTO/INTEGRITY_CHECK",
151
- `AES blob too short: need \u2265${exports.AES_MIN_BLOB} bytes, got ${blob.byteLength}`
152
- );
153
- }
154
- const iv = blob.subarray(0, exports.IV_LENGTH);
155
- const tag = blob.subarray(exports.IV_LENGTH, exports.IV_LENGTH + exports.TAG_LENGTH);
156
- const ct = blob.subarray(exports.IV_LENGTH + exports.TAG_LENGTH);
157
- const combined = new Uint8Array(ct.length + exports.TAG_LENGTH);
158
- combined.set(ct, 0);
159
- combined.set(tag, ct.length);
160
- try {
161
- const c = getCrypto();
162
- const ck = await c.subtle.importKey("raw", toArrayBuffer(key), "AES-GCM", false, ["decrypt"]);
163
- const pt = await c.subtle.decrypt(
164
- { name: "AES-GCM", iv: toArrayBuffer(iv), tagLength: exports.TAG_LENGTH * 8 },
165
- ck,
166
- toArrayBuffer(combined)
167
- );
168
- return new Uint8Array(pt);
169
- } catch (cause) {
170
- throw new CryptoError("CRYPTO/DECRYPT_FAILED", "AES-GCM decryption failed (wrong key or tampered data)", { cause });
171
- }
172
- }
173
- async function sha256(data) {
174
- const digest = await getCrypto().subtle.digest("SHA-256", toArrayBuffer(data));
175
- return new Uint8Array(digest);
176
- }
177
- var init_aes = __esm({
178
- "src/crypto/aes.ts"() {
179
- init_errors();
180
- init_constants();
181
- }
182
- });
183
-
184
- // src/crypto/hkdf.ts
185
- function getSubtle() {
186
- const c = globalThis.crypto;
187
- if (!c?.subtle) {
188
- throw new CryptoError("CRYPTO/UNSUPPORTED_CIPHER", "Web Crypto (crypto.subtle) is not available");
189
- }
190
- return c.subtle;
191
- }
192
- function toArrayBuffer2(u) {
193
- const ab = new ArrayBuffer(u.byteLength);
194
- new Uint8Array(ab).set(u);
195
- return ab;
196
- }
197
- async function hkdfSha256(ikm, length = 32, info = exports.ECIES_HKDF_INFO, salt = new Uint8Array(0)) {
198
- try {
199
- const subtle = getSubtle();
200
- const baseKey = await subtle.importKey("raw", toArrayBuffer2(ikm), "HKDF", false, ["deriveBits"]);
201
- const derived = await subtle.deriveBits(
202
- {
203
- name: "HKDF",
204
- hash: "SHA-256",
205
- info: toArrayBuffer2(info),
206
- salt: toArrayBuffer2(salt)
207
- },
208
- baseKey,
209
- length * 8
210
- );
211
- return new Uint8Array(derived);
212
- } catch (cause) {
213
- throw new CryptoError("CRYPTO/INVALID_KEY", "HKDF derivation failed", { cause });
214
- }
215
- }
216
- var init_hkdf = __esm({
217
- "src/crypto/hkdf.ts"() {
218
- init_errors();
219
- init_constants();
220
- }
221
- });
222
- function generateKeyPair() {
223
- const w = ethers.ethers.Wallet.createRandom();
224
- return {
225
- privateKey: w.privateKey.slice(2),
226
- publicKey: w.signingKey.publicKey.slice(2)
227
- };
228
- }
229
- function derivePublicKey(privateKey) {
230
- const sk = new ethers.ethers.SigningKey(`0x${strip(privateKey)}`);
231
- return sk.publicKey.slice(2);
232
- }
233
- function strip(hex) {
234
- return hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
235
- }
236
- function assertUncompressedPubKey(pub) {
237
- const s = strip(pub);
238
- if (s.length !== 130 || !/^04/i.test(s)) {
239
- throw new CryptoError(
240
- "CRYPTO/INVALID_KEY",
241
- "expected uncompressed secp256k1 pubkey (65 bytes hex, starts with 04)"
242
- );
243
- }
244
- }
245
- function hexToBytes(hex) {
246
- const s = strip(hex);
247
- if (s.length % 2 !== 0) {
248
- throw new CryptoError("CRYPTO/INVALID_KEY", "hex string has odd length");
249
- }
250
- const out = new Uint8Array(s.length / 2);
251
- for (let i = 0; i < out.length; i++) {
252
- const byte = Number.parseInt(s.substring(i * 2, i * 2 + 2), 16);
253
- if (Number.isNaN(byte)) {
254
- throw new CryptoError("CRYPTO/INVALID_KEY", `invalid hex byte at position ${i * 2}`);
255
- }
256
- out[i] = byte;
257
- }
258
- return out;
259
- }
260
- function bytesToHex(u) {
261
- return Array.from(u, (b) => b.toString(16).padStart(2, "0")).join("");
262
- }
263
- var init_keys = __esm({
264
- "src/crypto/keys.ts"() {
265
- init_errors();
266
- }
267
- });
268
-
269
- // src/crypto/ecies.ts
270
- var ecies_exports = {};
271
- __export(ecies_exports, {
272
- eciesDecrypt: () => eciesDecrypt,
273
- eciesEncrypt: () => eciesEncrypt
274
- });
275
- async function eciesEncrypt(plaintext, recipientPubKey) {
276
- assertUncompressedPubKey(recipientPubKey);
277
- const ephemeral = ethers.ethers.Wallet.createRandom();
278
- const shared = deriveSharedSecretX(ephemeral.privateKey, `0x${strip(recipientPubKey)}`);
279
- const aesKey = await hkdfSha256(shared, exports.KEY_LENGTH);
280
- const aesBlob = await aesEncrypt(plaintext, aesKey);
281
- const ephPub = hexToBytes(strip(ephemeral.signingKey.publicKey));
282
- if (ephPub.byteLength !== exports.ECIES_PUBKEY_LENGTH) {
283
- throw new CryptoError("CRYPTO/INVALID_KEY", `ephemeral pubkey length ${ephPub.byteLength}`);
284
- }
285
- const blob = new Uint8Array(exports.ECIES_PUBKEY_LENGTH + aesBlob.byteLength);
286
- blob.set(ephPub, 0);
287
- blob.set(aesBlob, exports.ECIES_PUBKEY_LENGTH);
288
- return blob;
289
- }
290
- async function eciesDecrypt(blob, recipientPrivKey) {
291
- if (blob.byteLength < exports.ECIES_MIN_BLOB) {
292
- throw new CryptoError(
293
- "CRYPTO/INTEGRITY_CHECK",
294
- `ECIES blob too short: need \u2265${exports.ECIES_MIN_BLOB} bytes, got ${blob.byteLength}`
295
- );
296
- }
297
- const ephPub = blob.subarray(0, exports.ECIES_PUBKEY_LENGTH);
298
- const aesBlob = blob.subarray(exports.ECIES_PUBKEY_LENGTH);
299
- const shared = deriveSharedSecretX(`0x${strip(recipientPrivKey)}`, `0x${bytesToHex(ephPub)}`);
300
- const aesKey = await hkdfSha256(shared, exports.KEY_LENGTH);
301
- return aesDecrypt(aesBlob, aesKey);
302
- }
303
- function deriveSharedSecretX(privHex, pubHex) {
304
- const sk = new ethers.ethers.SigningKey(privHex);
305
- const shared = sk.computeSharedSecret(pubHex);
306
- const bytes = hexToBytes(strip(shared));
307
- if (bytes.byteLength !== 65 || bytes[0] !== 4) {
308
- throw new CryptoError(
309
- "CRYPTO/INVALID_KEY",
310
- `unexpected shared secret shape (len=${bytes.byteLength}, prefix=${bytes[0]?.toString(16) ?? "none"})`
311
- );
312
- }
313
- return bytes.subarray(1, 33);
314
- }
315
- var init_ecies = __esm({
316
- "src/crypto/ecies.ts"() {
317
- init_errors();
318
- init_aes();
319
- init_constants();
320
- init_hkdf();
321
- init_keys();
322
- }
323
- });
324
-
325
- // src/crypto/index.ts
326
- init_constants();
327
- init_aes();
328
- init_ecies();
329
- init_keys();
330
-
331
- // src/crypto/envelope.ts
332
- init_errors();
333
- init_aes();
334
- init_ecies();
335
- var MAGIC_0 = 66;
336
- var MAGIC_1 = 66;
337
- var VERSION = 1;
338
- var HEADER_LEN = 3;
339
- async function sealEvidence(input) {
340
- const aesKey = await generateAesKey();
341
- const aesCiphertext = await aesEncrypt(input.evidence, aesKey);
342
- const wrappedForAgent = await eciesEncrypt(aesKey, input.agentPubKey);
343
- const wrappedForEnclave = await eciesEncrypt(aesKey, input.enclavePubKey);
344
- const envelope = pack({ wrappedForAgent, wrappedForEnclave, aesCiphertext });
345
- return { envelope, aesKey };
346
- }
347
- async function openEvidenceAsAgent(envelope, agentPrivKey) {
348
- const parsed = parse(envelope);
349
- const { eciesDecrypt: eciesDecrypt2 } = await Promise.resolve().then(() => (init_ecies(), ecies_exports));
350
- const aesKey = await eciesDecrypt2(parsed.wrappedForAgent, agentPrivKey);
351
- return aesDecrypt(parsed.aesCiphertext, aesKey);
352
- }
353
- function pack(parts) {
354
- const { wrappedForAgent, wrappedForEnclave, aesCiphertext } = parts;
355
- const total = HEADER_LEN + 4 + wrappedForAgent.byteLength + 4 + wrappedForEnclave.byteLength + aesCiphertext.byteLength;
356
- const out = new Uint8Array(total);
357
- const view = new DataView(out.buffer);
358
- let off = 0;
359
- out[off++] = MAGIC_0;
360
- out[off++] = MAGIC_1;
361
- out[off++] = VERSION;
362
- view.setUint32(off, wrappedForAgent.byteLength, false);
363
- off += 4;
364
- out.set(wrappedForAgent, off);
365
- off += wrappedForAgent.byteLength;
366
- view.setUint32(off, wrappedForEnclave.byteLength, false);
367
- off += 4;
368
- out.set(wrappedForEnclave, off);
369
- off += wrappedForEnclave.byteLength;
370
- out.set(aesCiphertext, off);
371
- return out;
372
- }
373
- function parse(blob) {
374
- if (blob.byteLength < HEADER_LEN + 4 + 4) {
375
- throw new CryptoError("CRYPTO/INTEGRITY_CHECK", `envelope too short: ${blob.byteLength}`);
376
- }
377
- if (blob[0] !== MAGIC_0 || blob[1] !== MAGIC_1) {
378
- throw new CryptoError("CRYPTO/INTEGRITY_CHECK", "bad envelope magic");
379
- }
380
- if (blob[2] !== VERSION) {
381
- throw new CryptoError("CRYPTO/UNSUPPORTED_CIPHER", `unknown envelope version ${blob[2]}`);
382
- }
383
- const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);
384
- let off = HEADER_LEN;
385
- const agentLen = view.getUint32(off, false);
386
- off += 4;
387
- if (off + agentLen + 4 > blob.byteLength) {
388
- throw new CryptoError("CRYPTO/INTEGRITY_CHECK", "envelope truncated (agent)");
389
- }
390
- const wrappedForAgent = blob.slice(off, off + agentLen);
391
- off += agentLen;
392
- const enclaveLen = view.getUint32(off, false);
393
- off += 4;
394
- if (off + enclaveLen > blob.byteLength) {
395
- throw new CryptoError("CRYPTO/INTEGRITY_CHECK", "envelope truncated (enclave)");
396
- }
397
- const wrappedForEnclave = blob.slice(off, off + enclaveLen);
398
- off += enclaveLen;
399
- const aesCiphertext = blob.slice(off);
400
- return { wrappedForAgent, wrappedForEnclave, aesCiphertext };
401
- }
402
- var __internals = { pack, parse };
403
-
404
- // src/crypto/index.ts
405
- init_hkdf();
406
-
407
- exports.__internals = __internals;
408
- exports.aesDecrypt = aesDecrypt;
409
- exports.aesEncrypt = aesEncrypt;
410
- exports.assertUncompressedPubKey = assertUncompressedPubKey;
411
- exports.bytesToHex = bytesToHex;
412
- exports.derivePublicKey = derivePublicKey;
413
- exports.eciesDecrypt = eciesDecrypt;
414
- exports.eciesEncrypt = eciesEncrypt;
415
- exports.generateAesKey = generateAesKey;
416
- exports.generateKeyPair = generateKeyPair;
417
- exports.hexToBytes = hexToBytes;
418
- exports.hkdfSha256 = hkdfSha256;
419
- exports.openEvidenceAsAgent = openEvidenceAsAgent;
420
- exports.sealEvidence = sealEvidence;
421
- exports.sha256 = sha256;
422
- exports.strip = strip;
423
- //# sourceMappingURL=index.cjs.map
424
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/crypto/constants.ts","../../src/errors/codes.ts","../../src/errors/BlindBountyError.ts","../../src/errors/subclasses.ts","../../src/errors/index.ts","../../src/crypto/aes.ts","../../src/crypto/hkdf.ts","../../src/crypto/keys.ts","../../src/crypto/ecies.ts","../../src/crypto/index.ts","../../src/crypto/envelope.ts"],"names":["IV_LENGTH","TAG_LENGTH","KEY_LENGTH","ECIES_PUBKEY_LENGTH","ECIES_HKDF_INFO","AES_MIN_BLOB","ECIES_MIN_BLOB","toArrayBuffer","ethers","eciesDecrypt"],"mappings":";;;;;;;;;;;;;;;AAAaA,0BAAA,CAAA,CACAC,2BAAA,CAAA,CACAC,2BAAA,CAAA,CACAC,oCAAA,CAAA,CACAC,kCACAC,6BAAA,CAAA,CACAC;AANb,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,yBAAA,GAAA;AAAO,IAAMN,iBAAA,GAAY,EAAA;AAClB,IAAMC,kBAAA,GAAa,EAAA;AACnB,IAAMC,kBAAA,GAAa,EAAA;AACnB,IAAMC,2BAAA,GAAsB,EAAA;AAC5B,IAAMC,uBAAA,GAAkB,IAAI,WAAA,EAAY,CAAE,OAAO,sBAAsB,CAAA;AACvE,IAAMC,uBAAeL,iBAAA,GAAYC,kBAAA;AACjC,IAAMK,yBAAiBH,2BAAA,GAAsBE,oBAAA;AAAA,EAAA;AAAA,CAAA,CAAA;;;ACNpD,IAAA,UAAA,GAAA,KAAA,CAAA;AAAA,EAAA,qBAAA,GAAA;AAAA,EAAA;AAAA,CAAA,CAAA;;;ACAA,IAQsB,gBAAA;AARtB,IAAA,qBAAA,GAAA,KAAA,CAAA;AAAA,EAAA,gCAAA,GAAA;AAQO,IAAe,gBAAA,GAAf,cAAwC,KAAA,CAAM;AAAA,MAC1C,IAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAA;AAAA,MACS,KAAA;AAAA,MAElB,WAAA,CAAY,IAAA,EAAiB,OAAA,EAAiB,IAAA,GAAqB,EAAC,EAAG;AACrE,QAA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AAoB,IAAA,CAAK,KAAA,CAAM,GAAA,EAAK,MAAM,UAAU,CAAA;AAC1D,EAAA,GAAA,IAAO,UAAA;AACP,EAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AACpC,EAAA,OAAO,EAAE,eAAA,EAAiB,iBAAA,EAAmB,aAAA,EAAc;AAC7D;AAEO,IAAM,WAAA,GAAc,EAAE,IAAA,EAAM,KAAA;;;AD7HnC,SAAA,EAAA","file":"index.cjs","sourcesContent":["export const IV_LENGTH = 12;\nexport const TAG_LENGTH = 16;\nexport const KEY_LENGTH = 32;\nexport const ECIES_PUBKEY_LENGTH = 65;\nexport const ECIES_HKDF_INFO = new TextEncoder().encode('BlindBounty-ECIES-v1');\nexport const AES_MIN_BLOB = IV_LENGTH + TAG_LENGTH;\nexport const ECIES_MIN_BLOB = ECIES_PUBKEY_LENGTH + AES_MIN_BLOB;\n","export const ErrorCodes = {\n Config: ['CONFIG/INVALID_NETWORK', 'CONFIG/MISSING_SIGNER', 'CONFIG/BAD_CONFIG'] as const,\n Crypto: [\n 'CRYPTO/INVALID_KEY',\n 'CRYPTO/DECRYPT_FAILED',\n 'CRYPTO/INTEGRITY_CHECK',\n 'CRYPTO/UNSUPPORTED_CIPHER',\n ] as const,\n Storage: [\n 'STORAGE/UPLOAD_FAILED',\n 'STORAGE/DOWNLOAD_FAILED',\n 'STORAGE/MERKLE_MISMATCH',\n 'STORAGE/NOT_FOUND',\n 'STORAGE/INDEXER_UNREACHABLE',\n ] as const,\n Chain: [\n 'CHAIN/TX_REVERTED',\n 'CHAIN/TX_TIMED_OUT',\n 'CHAIN/NONCE_CONFLICT',\n 'CHAIN/INSUFFICIENT_BALANCE',\n 'CHAIN/NETWORK_MISMATCH',\n 'CHAIN/CONTRACT_NOT_DEPLOYED',\n ] as const,\n Compute: [\n 'COMPUTE/BROKER_UNREACHABLE',\n 'COMPUTE/NO_PROVIDERS',\n 'COMPUTE/LEDGER_INSUFFICIENT',\n 'COMPUTE/TEE_ATTESTATION_INVALID',\n 'COMPUTE/VERIFICATION_TIMEOUT',\n ] as const,\n Api: [\n 'API/AUTH_REQUIRED',\n 'API/AUTH_EXPIRED',\n 'API/FORBIDDEN',\n 'API/RATE_LIMITED',\n 'API/VALIDATION',\n 'API/SERVER',\n 'API/NOT_FOUND',\n ] as const,\n Lifecycle: [\n 'LIFECYCLE/ILLEGAL_TRANSITION',\n 'LIFECYCLE/TASK_NOT_FOUND',\n 'LIFECYCLE/NOT_ASSIGNED',\n 'LIFECYCLE/ALREADY_SUBMITTED',\n 'LIFECYCLE/CLAIM_NOT_READY',\n ] as const,\n Timeout: ['TIMEOUT'] as const,\n} as const;\n\nexport type ConfigCode = (typeof ErrorCodes.Config)[number];\nexport type CryptoCode = (typeof ErrorCodes.Crypto)[number];\nexport type StorageCode = (typeof ErrorCodes.Storage)[number];\nexport type ChainCode = (typeof ErrorCodes.Chain)[number];\nexport type ComputeCode = (typeof ErrorCodes.Compute)[number];\nexport type ApiCode = (typeof ErrorCodes.Api)[number];\nexport type LifecycleCode = (typeof ErrorCodes.Lifecycle)[number];\nexport type TimeoutCode = (typeof ErrorCodes.Timeout)[number];\n\nexport type ErrorCode =\n | ConfigCode\n | CryptoCode\n | StorageCode\n | ChainCode\n | ComputeCode\n | ApiCode\n | LifecycleCode\n | TimeoutCode;\n","import type { ErrorCode } from './codes.js';\n\nexport interface ErrorOptions {\n retriable?: boolean;\n context?: Record<string, unknown>;\n cause?: unknown;\n}\n\nexport abstract class BlindBountyError extends Error {\n readonly code: ErrorCode;\n readonly retriable: boolean;\n readonly context?: Record<string, unknown>;\n override readonly cause?: unknown;\n\n constructor(code: ErrorCode, message: string, opts: ErrorOptions = {}) {\n super(message);\n this.code = code;\n this.retriable = opts.retriable ?? false;\n if (opts.context !== undefined) this.context = opts.context;\n if (opts.cause !== undefined) this.cause = opts.cause;\n Object.defineProperty(this, 'name', {\n value: this.constructor.name,\n enumerable: false,\n configurable: true,\n writable: true,\n });\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n retriable: this.retriable,\n ...(this.context ? { context: this.context } : {}),\n };\n }\n}\n","import { BlindBountyError, type ErrorOptions } from './BlindBountyError.js';\nimport type {\n ApiCode,\n ChainCode,\n ComputeCode,\n ConfigCode,\n CryptoCode,\n LifecycleCode,\n StorageCode,\n TimeoutCode,\n} from './codes.js';\n\nexport class ConfigError extends BlindBountyError {\n constructor(code: ConfigCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class CryptoError extends BlindBountyError {\n constructor(code: CryptoCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class StorageError extends BlindBountyError {\n constructor(code: StorageCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ChainError extends BlindBountyError {\n constructor(code: ChainCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ComputeError extends BlindBountyError {\n constructor(code: ComputeCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ApiError extends BlindBountyError {\n constructor(code: ApiCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class LifecycleError extends BlindBountyError {\n constructor(code: LifecycleCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class TimeoutError extends BlindBountyError {\n constructor(code: TimeoutCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n","export * from './codes.js';\nexport * from './BlindBountyError.js';\nexport * from './subclasses.js';\n","import { CryptoError } from '../errors/index.js';\nimport { AES_MIN_BLOB, IV_LENGTH, KEY_LENGTH, TAG_LENGTH } from './constants.js';\n\nfunction getCrypto(): Crypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', 'Web Crypto (crypto.subtle) is not available');\n }\n return c;\n}\n\nfunction toArrayBuffer(u: Uint8Array): ArrayBuffer {\n const ab = new ArrayBuffer(u.byteLength);\n new Uint8Array(ab).set(u);\n return ab;\n}\n\n/** Generate a fresh 32-byte AES-256 key. */\nexport async function generateAesKey(): Promise<Uint8Array> {\n const key = new Uint8Array(KEY_LENGTH);\n getCrypto().getRandomValues(key);\n return key;\n}\n\n/**\n * AES-256-GCM encrypt. Output format: [12 IV][16 tag][ciphertext].\n * This ordering matches backend/src/services/crypto.ts and frontend/src/lib/crypto.ts\n * byte-for-byte, so SDK blobs decrypt anywhere in the stack.\n */\nexport async function aesEncrypt(plaintext: Uint8Array, key: Uint8Array): Promise<Uint8Array> {\n if (key.byteLength !== KEY_LENGTH) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `AES key must be ${KEY_LENGTH} bytes, got ${key.byteLength}`,\n );\n }\n const c = getCrypto();\n const iv = new Uint8Array(IV_LENGTH);\n c.getRandomValues(iv);\n try {\n const ck = await c.subtle.importKey('raw', toArrayBuffer(key), 'AES-GCM', false, ['encrypt']);\n const wcOut = new Uint8Array(\n await c.subtle.encrypt(\n { name: 'AES-GCM', iv: toArrayBuffer(iv), tagLength: TAG_LENGTH * 8 },\n ck,\n toArrayBuffer(plaintext),\n ),\n );\n // WebCrypto returns [ciphertext || tag]. Rewrite to [IV || tag || ciphertext].\n const ctLen = wcOut.length - TAG_LENGTH;\n const ct = wcOut.subarray(0, ctLen);\n const tag = wcOut.subarray(ctLen);\n const blob = new Uint8Array(IV_LENGTH + TAG_LENGTH + ctLen);\n blob.set(iv, 0);\n blob.set(tag, IV_LENGTH);\n blob.set(ct, IV_LENGTH + TAG_LENGTH);\n return blob;\n } catch (cause) {\n throw new CryptoError('CRYPTO/DECRYPT_FAILED', 'AES-GCM encryption failed', { cause });\n }\n}\n\n/**\n * AES-256-GCM decrypt. Input format: [12 IV][16 tag][ciphertext].\n * Throws CRYPTO/INTEGRITY_CHECK on truncation or tag mismatch.\n */\nexport async function aesDecrypt(blob: Uint8Array, key: Uint8Array): Promise<Uint8Array> {\n if (key.byteLength !== KEY_LENGTH) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `AES key must be ${KEY_LENGTH} bytes, got ${key.byteLength}`,\n );\n }\n if (blob.byteLength < AES_MIN_BLOB) {\n throw new CryptoError(\n 'CRYPTO/INTEGRITY_CHECK',\n `AES blob too short: need ≥${AES_MIN_BLOB} bytes, got ${blob.byteLength}`,\n );\n }\n const iv = blob.subarray(0, IV_LENGTH);\n const tag = blob.subarray(IV_LENGTH, IV_LENGTH + TAG_LENGTH);\n const ct = blob.subarray(IV_LENGTH + TAG_LENGTH);\n const combined = new Uint8Array(ct.length + TAG_LENGTH);\n combined.set(ct, 0);\n combined.set(tag, ct.length);\n try {\n const c = getCrypto();\n const ck = await c.subtle.importKey('raw', toArrayBuffer(key), 'AES-GCM', false, ['decrypt']);\n const pt = await c.subtle.decrypt(\n { name: 'AES-GCM', iv: toArrayBuffer(iv), tagLength: TAG_LENGTH * 8 },\n ck,\n toArrayBuffer(combined),\n );\n return new Uint8Array(pt);\n } catch (cause) {\n throw new CryptoError('CRYPTO/DECRYPT_FAILED', 'AES-GCM decryption failed (wrong key or tampered data)', { cause });\n }\n}\n\n/** SHA-256 of arbitrary bytes. Returns 32-byte digest. */\nexport async function sha256(data: Uint8Array): Promise<Uint8Array> {\n const digest = await getCrypto().subtle.digest('SHA-256', toArrayBuffer(data));\n return new Uint8Array(digest);\n}\n","import { CryptoError } from '../errors/index.js';\nimport { ECIES_HKDF_INFO } from './constants.js';\n\nfunction getSubtle(): SubtleCrypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', 'Web Crypto (crypto.subtle) is not available');\n }\n return c.subtle;\n}\n\nfunction toArrayBuffer(u: Uint8Array): ArrayBuffer {\n const ab = new ArrayBuffer(u.byteLength);\n new Uint8Array(ab).set(u);\n return ab;\n}\n\n/**\n * HKDF-SHA256. Defaults match backend: empty salt, the ECIES domain separation info,\n * 32-byte output length. Pass custom values for other uses.\n */\nexport async function hkdfSha256(\n ikm: Uint8Array,\n length = 32,\n info: Uint8Array = ECIES_HKDF_INFO,\n salt: Uint8Array = new Uint8Array(0),\n): Promise<Uint8Array> {\n try {\n const subtle = getSubtle();\n const baseKey = await subtle.importKey('raw', toArrayBuffer(ikm), 'HKDF', false, ['deriveBits']);\n const derived = await subtle.deriveBits(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n info: toArrayBuffer(info),\n salt: toArrayBuffer(salt),\n },\n baseKey,\n length * 8,\n );\n return new Uint8Array(derived);\n } catch (cause) {\n throw new CryptoError('CRYPTO/INVALID_KEY', 'HKDF derivation failed', { cause });\n }\n}\n","import { ethers } from 'ethers';\nimport { CryptoError } from '../errors/index.js';\n\nexport interface KeyPair {\n privateKey: string;\n publicKey: string;\n}\n\n/** Fresh secp256k1 keypair. Hex strings returned un-prefixed (no 0x). */\nexport function generateKeyPair(): KeyPair {\n const w = ethers.Wallet.createRandom();\n return {\n privateKey: w.privateKey.slice(2),\n publicKey: w.signingKey.publicKey.slice(2),\n };\n}\n\n/** Recover the uncompressed public key (un-prefixed hex) from a private key. */\nexport function derivePublicKey(privateKey: string): string {\n const sk = new ethers.SigningKey(`0x${strip(privateKey)}`);\n return sk.publicKey.slice(2);\n}\n\nexport function strip(hex: string): string {\n return hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;\n}\n\nexport function assertUncompressedPubKey(pub: string): void {\n const s = strip(pub);\n if (s.length !== 130 || !/^04/i.test(s)) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n 'expected uncompressed secp256k1 pubkey (65 bytes hex, starts with 04)',\n );\n }\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n const s = strip(hex);\n if (s.length % 2 !== 0) {\n throw new CryptoError('CRYPTO/INVALID_KEY', 'hex string has odd length');\n }\n const out = new Uint8Array(s.length / 2);\n for (let i = 0; i < out.length; i++) {\n const byte = Number.parseInt(s.substring(i * 2, i * 2 + 2), 16);\n if (Number.isNaN(byte)) {\n throw new CryptoError('CRYPTO/INVALID_KEY', `invalid hex byte at position ${i * 2}`);\n }\n out[i] = byte;\n }\n return out;\n}\n\nexport function bytesToHex(u: Uint8Array): string {\n return Array.from(u, (b) => b.toString(16).padStart(2, '0')).join('');\n}\n","import { ethers } from 'ethers';\nimport { CryptoError } from '../errors/index.js';\nimport { aesDecrypt, aesEncrypt } from './aes.js';\nimport { ECIES_MIN_BLOB, ECIES_PUBKEY_LENGTH, KEY_LENGTH } from './constants.js';\nimport { hkdfSha256 } from './hkdf.js';\nimport { assertUncompressedPubKey, bytesToHex, hexToBytes, strip } from './keys.js';\n\n/**\n * ECIES-secp256k1 encrypt to a recipient's uncompressed public key.\n * Wire format: [65 ephemeral pubkey][12 IV][16 tag][ciphertext].\n * Byte-compatible with backend/src/services/crypto.ts.\n */\nexport async function eciesEncrypt(plaintext: Uint8Array, recipientPubKey: string): Promise<Uint8Array> {\n assertUncompressedPubKey(recipientPubKey);\n const ephemeral = ethers.Wallet.createRandom();\n const shared = deriveSharedSecretX(ephemeral.privateKey, `0x${strip(recipientPubKey)}`);\n const aesKey = await hkdfSha256(shared, KEY_LENGTH);\n const aesBlob = await aesEncrypt(plaintext, aesKey);\n const ephPub = hexToBytes(strip(ephemeral.signingKey.publicKey));\n if (ephPub.byteLength !== ECIES_PUBKEY_LENGTH) {\n throw new CryptoError('CRYPTO/INVALID_KEY', `ephemeral pubkey length ${ephPub.byteLength}`);\n }\n const blob = new Uint8Array(ECIES_PUBKEY_LENGTH + aesBlob.byteLength);\n blob.set(ephPub, 0);\n blob.set(aesBlob, ECIES_PUBKEY_LENGTH);\n return blob;\n}\n\n/** ECIES-secp256k1 decrypt with the recipient's private key. */\nexport async function eciesDecrypt(blob: Uint8Array, recipientPrivKey: string): Promise<Uint8Array> {\n if (blob.byteLength < ECIES_MIN_BLOB) {\n throw new CryptoError(\n 'CRYPTO/INTEGRITY_CHECK',\n `ECIES blob too short: need ≥${ECIES_MIN_BLOB} bytes, got ${blob.byteLength}`,\n );\n }\n const ephPub = blob.subarray(0, ECIES_PUBKEY_LENGTH);\n const aesBlob = blob.subarray(ECIES_PUBKEY_LENGTH);\n const shared = deriveSharedSecretX(`0x${strip(recipientPrivKey)}`, `0x${bytesToHex(ephPub)}`);\n const aesKey = await hkdfSha256(shared, KEY_LENGTH);\n return aesDecrypt(aesBlob, aesKey);\n}\n\n/**\n * Compute the ECDH shared secret X coordinate (32 bytes) between a private key\n * and a peer's public key. Matches Node createECDH.computeSecret() output used by\n * the backend — ethers v6 returns 0x04||X||Y, so we slice X.\n */\nfunction deriveSharedSecretX(privHex: string, pubHex: string): Uint8Array {\n const sk = new ethers.SigningKey(privHex);\n const shared = sk.computeSharedSecret(pubHex);\n const bytes = hexToBytes(strip(shared));\n if (bytes.byteLength !== 65 || bytes[0] !== 0x04) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `unexpected shared secret shape (len=${bytes.byteLength}, prefix=${bytes[0]?.toString(16) ?? 'none'})`,\n );\n }\n return bytes.subarray(1, 33);\n}\n","export * from './constants.js';\nexport * from './aes.js';\nexport * from './ecies.js';\nexport * from './keys.js';\nexport * from './envelope.js';\nexport { hkdfSha256 } from './hkdf.js';\n","import { CryptoError } from '../errors/index.js';\nimport { aesDecrypt, aesEncrypt, generateAesKey } from './aes.js';\nimport { eciesEncrypt } from './ecies.js';\n\n/**\n * Evidence envelope — the single blob a worker uploads to Storage containing:\n * 1. The AES key wrapped to the agent's pubkey (so agent can decrypt later)\n * 2. The AES key wrapped to the TEE enclave's pubkey (so Sealed Inference can decrypt)\n * 3. The evidence ciphertext under that AES key\n *\n * Wire format (big-endian):\n * bytes 0..1 magic = 0x42 0x42 (\"BB\")\n * byte 2 version = 0x01\n * bytes 3..6 wrappedAgentLen (uint32)\n * bytes 7.. wrappedAgent (ECIES blob)\n * 4-byte uint32 wrappedEnclaveLen\n * bytes wrappedEnclave (ECIES blob)\n * bytes aesCiphertext (rest of the blob — AES blob [IV||tag||ct])\n *\n * The layout is versioned so we can rev it without breaking old blobs.\n */\n\nconst MAGIC_0 = 0x42;\nconst MAGIC_1 = 0x42;\nconst VERSION = 0x01;\nconst HEADER_LEN = 3;\n\nexport interface EvidenceEnvelope {\n wrappedForAgent: Uint8Array;\n wrappedForEnclave: Uint8Array;\n aesCiphertext: Uint8Array;\n}\n\nexport interface SealEvidenceInput {\n evidence: Uint8Array;\n agentPubKey: string;\n enclavePubKey: string;\n}\n\nexport interface SealEvidenceOutput {\n envelope: Uint8Array;\n aesKey: Uint8Array;\n}\n\n/**\n * Seal evidence for the agent + TEE enclave. Generates a fresh AES key,\n * encrypts the evidence, ECIES-wraps the key twice, and concatenates the\n * result as an EvidenceEnvelope. Returns both the on-wire envelope and\n * the raw AES key (for audit / diagnostic use — do NOT persist beyond\n * the submission).\n */\nexport async function sealEvidence(input: SealEvidenceInput): Promise<SealEvidenceOutput> {\n const aesKey = await generateAesKey();\n const aesCiphertext = await aesEncrypt(input.evidence, aesKey);\n const wrappedForAgent = await eciesEncrypt(aesKey, input.agentPubKey);\n const wrappedForEnclave = await eciesEncrypt(aesKey, input.enclavePubKey);\n const envelope = pack({ wrappedForAgent, wrappedForEnclave, aesCiphertext });\n return { envelope, aesKey };\n}\n\n/**\n * Open an evidence envelope as the agent — extracts the AES key wrapped\n * to the agent's pubkey, decrypts the ciphertext, and returns the plaintext\n * evidence. The enclave-wrapped key is ignored by agents (TEE-only).\n */\nexport async function openEvidenceAsAgent(\n envelope: Uint8Array,\n agentPrivKey: string,\n): Promise<Uint8Array> {\n const parsed = parse(envelope);\n const { eciesDecrypt } = await import('./ecies.js');\n const aesKey = await eciesDecrypt(parsed.wrappedForAgent, agentPrivKey);\n return aesDecrypt(parsed.aesCiphertext, aesKey);\n}\n\nfunction pack(parts: EvidenceEnvelope): Uint8Array {\n const { wrappedForAgent, wrappedForEnclave, aesCiphertext } = parts;\n const total =\n HEADER_LEN +\n 4 + wrappedForAgent.byteLength +\n 4 + wrappedForEnclave.byteLength +\n aesCiphertext.byteLength;\n const out = new Uint8Array(total);\n const view = new DataView(out.buffer);\n let off = 0;\n out[off++] = MAGIC_0;\n out[off++] = MAGIC_1;\n out[off++] = VERSION;\n view.setUint32(off, wrappedForAgent.byteLength, false);\n off += 4;\n out.set(wrappedForAgent, off);\n off += wrappedForAgent.byteLength;\n view.setUint32(off, wrappedForEnclave.byteLength, false);\n off += 4;\n out.set(wrappedForEnclave, off);\n off += wrappedForEnclave.byteLength;\n out.set(aesCiphertext, off);\n return out;\n}\n\nfunction parse(blob: Uint8Array): EvidenceEnvelope {\n if (blob.byteLength < HEADER_LEN + 4 + 4) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', `envelope too short: ${blob.byteLength}`);\n }\n if (blob[0] !== MAGIC_0 || blob[1] !== MAGIC_1) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'bad envelope magic');\n }\n if (blob[2] !== VERSION) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', `unknown envelope version ${blob[2]}`);\n }\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);\n let off = HEADER_LEN;\n const agentLen = view.getUint32(off, false);\n off += 4;\n if (off + agentLen + 4 > blob.byteLength) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'envelope truncated (agent)');\n }\n const wrappedForAgent = blob.slice(off, off + agentLen);\n off += agentLen;\n const enclaveLen = view.getUint32(off, false);\n off += 4;\n if (off + enclaveLen > blob.byteLength) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'envelope truncated (enclave)');\n }\n const wrappedForEnclave = blob.slice(off, off + enclaveLen);\n off += enclaveLen;\n const aesCiphertext = blob.slice(off);\n return { wrappedForAgent, wrappedForEnclave, aesCiphertext };\n}\n\nexport const __internals = { pack, parse };\n"]}
@@ -1,74 +0,0 @@
1
- export { a as aesDecrypt, b as aesEncrypt, g as generateAesKey, s as sha256 } from '../aes-J-7HrHze.cjs';
2
-
3
- declare const IV_LENGTH = 12;
4
- declare const TAG_LENGTH = 16;
5
- declare const KEY_LENGTH = 32;
6
- declare const ECIES_PUBKEY_LENGTH = 65;
7
- declare const ECIES_HKDF_INFO: Uint8Array<ArrayBuffer>;
8
- declare const AES_MIN_BLOB: number;
9
- declare const ECIES_MIN_BLOB: number;
10
-
11
- /**
12
- * ECIES-secp256k1 encrypt to a recipient's uncompressed public key.
13
- * Wire format: [65 ephemeral pubkey][12 IV][16 tag][ciphertext].
14
- * Byte-compatible with backend/src/services/crypto.ts.
15
- */
16
- declare function eciesEncrypt(plaintext: Uint8Array, recipientPubKey: string): Promise<Uint8Array>;
17
- /** ECIES-secp256k1 decrypt with the recipient's private key. */
18
- declare function eciesDecrypt(blob: Uint8Array, recipientPrivKey: string): Promise<Uint8Array>;
19
-
20
- interface KeyPair {
21
- privateKey: string;
22
- publicKey: string;
23
- }
24
- /** Fresh secp256k1 keypair. Hex strings returned un-prefixed (no 0x). */
25
- declare function generateKeyPair(): KeyPair;
26
- /** Recover the uncompressed public key (un-prefixed hex) from a private key. */
27
- declare function derivePublicKey(privateKey: string): string;
28
- declare function strip(hex: string): string;
29
- declare function assertUncompressedPubKey(pub: string): void;
30
- declare function hexToBytes(hex: string): Uint8Array;
31
- declare function bytesToHex(u: Uint8Array): string;
32
-
33
- interface EvidenceEnvelope {
34
- wrappedForAgent: Uint8Array;
35
- wrappedForEnclave: Uint8Array;
36
- aesCiphertext: Uint8Array;
37
- }
38
- interface SealEvidenceInput {
39
- evidence: Uint8Array;
40
- agentPubKey: string;
41
- enclavePubKey: string;
42
- }
43
- interface SealEvidenceOutput {
44
- envelope: Uint8Array;
45
- aesKey: Uint8Array;
46
- }
47
- /**
48
- * Seal evidence for the agent + TEE enclave. Generates a fresh AES key,
49
- * encrypts the evidence, ECIES-wraps the key twice, and concatenates the
50
- * result as an EvidenceEnvelope. Returns both the on-wire envelope and
51
- * the raw AES key (for audit / diagnostic use — do NOT persist beyond
52
- * the submission).
53
- */
54
- declare function sealEvidence(input: SealEvidenceInput): Promise<SealEvidenceOutput>;
55
- /**
56
- * Open an evidence envelope as the agent — extracts the AES key wrapped
57
- * to the agent's pubkey, decrypts the ciphertext, and returns the plaintext
58
- * evidence. The enclave-wrapped key is ignored by agents (TEE-only).
59
- */
60
- declare function openEvidenceAsAgent(envelope: Uint8Array, agentPrivKey: string): Promise<Uint8Array>;
61
- declare function pack(parts: EvidenceEnvelope): Uint8Array;
62
- declare function parse(blob: Uint8Array): EvidenceEnvelope;
63
- declare const __internals: {
64
- pack: typeof pack;
65
- parse: typeof parse;
66
- };
67
-
68
- /**
69
- * HKDF-SHA256. Defaults match backend: empty salt, the ECIES domain separation info,
70
- * 32-byte output length. Pass custom values for other uses.
71
- */
72
- declare function hkdfSha256(ikm: Uint8Array, length?: number, info?: Uint8Array, salt?: Uint8Array): Promise<Uint8Array>;
73
-
74
- export { AES_MIN_BLOB, ECIES_HKDF_INFO, ECIES_MIN_BLOB, ECIES_PUBKEY_LENGTH, type EvidenceEnvelope, IV_LENGTH, KEY_LENGTH, type KeyPair, type SealEvidenceInput, type SealEvidenceOutput, TAG_LENGTH, __internals, assertUncompressedPubKey, bytesToHex, derivePublicKey, eciesDecrypt, eciesEncrypt, generateKeyPair, hexToBytes, hkdfSha256, openEvidenceAsAgent, sealEvidence, strip };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/crypto/constants.ts","../../src/errors/codes.ts","../../src/errors/BlindBountyError.ts","../../src/errors/subclasses.ts","../../src/errors/index.ts","../../src/crypto/aes.ts","../../src/crypto/hkdf.ts","../../src/crypto/keys.ts","../../src/crypto/ecies.ts","../../src/crypto/index.ts","../../src/crypto/envelope.ts"],"names":["toArrayBuffer","ethers","eciesDecrypt"],"mappings":";;;;;;;;;;;;;AAAA,IAAa,SAAA,CAAA,CACA,UAAA,CAAA,CACA,UAAA,CAAA,CACA,mBAAA,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,KAAK,UAAU,CAAA;AACvE,EAAA,IAAI,GAAA,GAAM,UAAA;AACV,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,SAAA,CAAU,GAAA,EAAK,KAAK,CAAA;AAC1C,EAAA,GAAA,IAAO,CAAA;AACP,EAAA,IAAI,GAAA,GAAM,QAAA,GAAW,CAAA,GAAI,IAAA,CAAK,UAAA,EAAY;AACxC,IAAA,MAAM,IAAI,WAAA,CAAY,wBAAA,EAA0B,4BAA4B,CAAA;AAAA,EAC9E;AACA,EAAA,MAAM,eAAA,GAAkB,IAAA,CAAK,KAAA,CAAM,GAAA,EAAK,MAAM,QAAQ,CAAA;AACtD,EAAA,GAAA,IAAO,QAAA;AACP,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,SAAA,CAAU,GAAA,EAAK,KAAK,CAAA;AAC5C,EAAA,GAAA,IAAO,CAAA;AACP,EAAA,IAAI,GAAA,GAAM,UAAA,GAAa,IAAA,CAAK,UAAA,EAAY;AACtC,IAAA,MAAM,IAAI,WAAA,CAAY,wBAAA,EAA0B,8BAA8B,CAAA;AAAA,EAChF;AACA,EAAA,MAAM,iBAAA,GAAoB,IAAA,CAAK,KAAA,CAAM,GAAA,EAAK,MAAM,UAAU,CAAA;AAC1D,EAAA,GAAA,IAAO,UAAA;AACP,EAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AACpC,EAAA,OAAO,EAAE,eAAA,EAAiB,iBAAA,EAAmB,aAAA,EAAc;AAC7D;AAEO,IAAM,WAAA,GAAc,EAAE,IAAA,EAAM,KAAA;;;AD7HnC,SAAA,EAAA","file":"index.js","sourcesContent":["export const IV_LENGTH = 12;\nexport const TAG_LENGTH = 16;\nexport const KEY_LENGTH = 32;\nexport const ECIES_PUBKEY_LENGTH = 65;\nexport const ECIES_HKDF_INFO = new TextEncoder().encode('BlindBounty-ECIES-v1');\nexport const AES_MIN_BLOB = IV_LENGTH + TAG_LENGTH;\nexport const ECIES_MIN_BLOB = ECIES_PUBKEY_LENGTH + AES_MIN_BLOB;\n","export const ErrorCodes = {\n Config: ['CONFIG/INVALID_NETWORK', 'CONFIG/MISSING_SIGNER', 'CONFIG/BAD_CONFIG'] as const,\n Crypto: [\n 'CRYPTO/INVALID_KEY',\n 'CRYPTO/DECRYPT_FAILED',\n 'CRYPTO/INTEGRITY_CHECK',\n 'CRYPTO/UNSUPPORTED_CIPHER',\n ] as const,\n Storage: [\n 'STORAGE/UPLOAD_FAILED',\n 'STORAGE/DOWNLOAD_FAILED',\n 'STORAGE/MERKLE_MISMATCH',\n 'STORAGE/NOT_FOUND',\n 'STORAGE/INDEXER_UNREACHABLE',\n ] as const,\n Chain: [\n 'CHAIN/TX_REVERTED',\n 'CHAIN/TX_TIMED_OUT',\n 'CHAIN/NONCE_CONFLICT',\n 'CHAIN/INSUFFICIENT_BALANCE',\n 'CHAIN/NETWORK_MISMATCH',\n 'CHAIN/CONTRACT_NOT_DEPLOYED',\n ] as const,\n Compute: [\n 'COMPUTE/BROKER_UNREACHABLE',\n 'COMPUTE/NO_PROVIDERS',\n 'COMPUTE/LEDGER_INSUFFICIENT',\n 'COMPUTE/TEE_ATTESTATION_INVALID',\n 'COMPUTE/VERIFICATION_TIMEOUT',\n ] as const,\n Api: [\n 'API/AUTH_REQUIRED',\n 'API/AUTH_EXPIRED',\n 'API/FORBIDDEN',\n 'API/RATE_LIMITED',\n 'API/VALIDATION',\n 'API/SERVER',\n 'API/NOT_FOUND',\n ] as const,\n Lifecycle: [\n 'LIFECYCLE/ILLEGAL_TRANSITION',\n 'LIFECYCLE/TASK_NOT_FOUND',\n 'LIFECYCLE/NOT_ASSIGNED',\n 'LIFECYCLE/ALREADY_SUBMITTED',\n 'LIFECYCLE/CLAIM_NOT_READY',\n ] as const,\n Timeout: ['TIMEOUT'] as const,\n} as const;\n\nexport type ConfigCode = (typeof ErrorCodes.Config)[number];\nexport type CryptoCode = (typeof ErrorCodes.Crypto)[number];\nexport type StorageCode = (typeof ErrorCodes.Storage)[number];\nexport type ChainCode = (typeof ErrorCodes.Chain)[number];\nexport type ComputeCode = (typeof ErrorCodes.Compute)[number];\nexport type ApiCode = (typeof ErrorCodes.Api)[number];\nexport type LifecycleCode = (typeof ErrorCodes.Lifecycle)[number];\nexport type TimeoutCode = (typeof ErrorCodes.Timeout)[number];\n\nexport type ErrorCode =\n | ConfigCode\n | CryptoCode\n | StorageCode\n | ChainCode\n | ComputeCode\n | ApiCode\n | LifecycleCode\n | TimeoutCode;\n","import type { ErrorCode } from './codes.js';\n\nexport interface ErrorOptions {\n retriable?: boolean;\n context?: Record<string, unknown>;\n cause?: unknown;\n}\n\nexport abstract class BlindBountyError extends Error {\n readonly code: ErrorCode;\n readonly retriable: boolean;\n readonly context?: Record<string, unknown>;\n override readonly cause?: unknown;\n\n constructor(code: ErrorCode, message: string, opts: ErrorOptions = {}) {\n super(message);\n this.code = code;\n this.retriable = opts.retriable ?? false;\n if (opts.context !== undefined) this.context = opts.context;\n if (opts.cause !== undefined) this.cause = opts.cause;\n Object.defineProperty(this, 'name', {\n value: this.constructor.name,\n enumerable: false,\n configurable: true,\n writable: true,\n });\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n retriable: this.retriable,\n ...(this.context ? { context: this.context } : {}),\n };\n }\n}\n","import { BlindBountyError, type ErrorOptions } from './BlindBountyError.js';\nimport type {\n ApiCode,\n ChainCode,\n ComputeCode,\n ConfigCode,\n CryptoCode,\n LifecycleCode,\n StorageCode,\n TimeoutCode,\n} from './codes.js';\n\nexport class ConfigError extends BlindBountyError {\n constructor(code: ConfigCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class CryptoError extends BlindBountyError {\n constructor(code: CryptoCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class StorageError extends BlindBountyError {\n constructor(code: StorageCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ChainError extends BlindBountyError {\n constructor(code: ChainCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ComputeError extends BlindBountyError {\n constructor(code: ComputeCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ApiError extends BlindBountyError {\n constructor(code: ApiCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class LifecycleError extends BlindBountyError {\n constructor(code: LifecycleCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class TimeoutError extends BlindBountyError {\n constructor(code: TimeoutCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n","export * from './codes.js';\nexport * from './BlindBountyError.js';\nexport * from './subclasses.js';\n","import { CryptoError } from '../errors/index.js';\nimport { AES_MIN_BLOB, IV_LENGTH, KEY_LENGTH, TAG_LENGTH } from './constants.js';\n\nfunction getCrypto(): Crypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', 'Web Crypto (crypto.subtle) is not available');\n }\n return c;\n}\n\nfunction toArrayBuffer(u: Uint8Array): ArrayBuffer {\n const ab = new ArrayBuffer(u.byteLength);\n new Uint8Array(ab).set(u);\n return ab;\n}\n\n/** Generate a fresh 32-byte AES-256 key. */\nexport async function generateAesKey(): Promise<Uint8Array> {\n const key = new Uint8Array(KEY_LENGTH);\n getCrypto().getRandomValues(key);\n return key;\n}\n\n/**\n * AES-256-GCM encrypt. Output format: [12 IV][16 tag][ciphertext].\n * This ordering matches backend/src/services/crypto.ts and frontend/src/lib/crypto.ts\n * byte-for-byte, so SDK blobs decrypt anywhere in the stack.\n */\nexport async function aesEncrypt(plaintext: Uint8Array, key: Uint8Array): Promise<Uint8Array> {\n if (key.byteLength !== KEY_LENGTH) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `AES key must be ${KEY_LENGTH} bytes, got ${key.byteLength}`,\n );\n }\n const c = getCrypto();\n const iv = new Uint8Array(IV_LENGTH);\n c.getRandomValues(iv);\n try {\n const ck = await c.subtle.importKey('raw', toArrayBuffer(key), 'AES-GCM', false, ['encrypt']);\n const wcOut = new Uint8Array(\n await c.subtle.encrypt(\n { name: 'AES-GCM', iv: toArrayBuffer(iv), tagLength: TAG_LENGTH * 8 },\n ck,\n toArrayBuffer(plaintext),\n ),\n );\n // WebCrypto returns [ciphertext || tag]. Rewrite to [IV || tag || ciphertext].\n const ctLen = wcOut.length - TAG_LENGTH;\n const ct = wcOut.subarray(0, ctLen);\n const tag = wcOut.subarray(ctLen);\n const blob = new Uint8Array(IV_LENGTH + TAG_LENGTH + ctLen);\n blob.set(iv, 0);\n blob.set(tag, IV_LENGTH);\n blob.set(ct, IV_LENGTH + TAG_LENGTH);\n return blob;\n } catch (cause) {\n throw new CryptoError('CRYPTO/DECRYPT_FAILED', 'AES-GCM encryption failed', { cause });\n }\n}\n\n/**\n * AES-256-GCM decrypt. Input format: [12 IV][16 tag][ciphertext].\n * Throws CRYPTO/INTEGRITY_CHECK on truncation or tag mismatch.\n */\nexport async function aesDecrypt(blob: Uint8Array, key: Uint8Array): Promise<Uint8Array> {\n if (key.byteLength !== KEY_LENGTH) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `AES key must be ${KEY_LENGTH} bytes, got ${key.byteLength}`,\n );\n }\n if (blob.byteLength < AES_MIN_BLOB) {\n throw new CryptoError(\n 'CRYPTO/INTEGRITY_CHECK',\n `AES blob too short: need ≥${AES_MIN_BLOB} bytes, got ${blob.byteLength}`,\n );\n }\n const iv = blob.subarray(0, IV_LENGTH);\n const tag = blob.subarray(IV_LENGTH, IV_LENGTH + TAG_LENGTH);\n const ct = blob.subarray(IV_LENGTH + TAG_LENGTH);\n const combined = new Uint8Array(ct.length + TAG_LENGTH);\n combined.set(ct, 0);\n combined.set(tag, ct.length);\n try {\n const c = getCrypto();\n const ck = await c.subtle.importKey('raw', toArrayBuffer(key), 'AES-GCM', false, ['decrypt']);\n const pt = await c.subtle.decrypt(\n { name: 'AES-GCM', iv: toArrayBuffer(iv), tagLength: TAG_LENGTH * 8 },\n ck,\n toArrayBuffer(combined),\n );\n return new Uint8Array(pt);\n } catch (cause) {\n throw new CryptoError('CRYPTO/DECRYPT_FAILED', 'AES-GCM decryption failed (wrong key or tampered data)', { cause });\n }\n}\n\n/** SHA-256 of arbitrary bytes. Returns 32-byte digest. */\nexport async function sha256(data: Uint8Array): Promise<Uint8Array> {\n const digest = await getCrypto().subtle.digest('SHA-256', toArrayBuffer(data));\n return new Uint8Array(digest);\n}\n","import { CryptoError } from '../errors/index.js';\nimport { ECIES_HKDF_INFO } from './constants.js';\n\nfunction getSubtle(): SubtleCrypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', 'Web Crypto (crypto.subtle) is not available');\n }\n return c.subtle;\n}\n\nfunction toArrayBuffer(u: Uint8Array): ArrayBuffer {\n const ab = new ArrayBuffer(u.byteLength);\n new Uint8Array(ab).set(u);\n return ab;\n}\n\n/**\n * HKDF-SHA256. Defaults match backend: empty salt, the ECIES domain separation info,\n * 32-byte output length. Pass custom values for other uses.\n */\nexport async function hkdfSha256(\n ikm: Uint8Array,\n length = 32,\n info: Uint8Array = ECIES_HKDF_INFO,\n salt: Uint8Array = new Uint8Array(0),\n): Promise<Uint8Array> {\n try {\n const subtle = getSubtle();\n const baseKey = await subtle.importKey('raw', toArrayBuffer(ikm), 'HKDF', false, ['deriveBits']);\n const derived = await subtle.deriveBits(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n info: toArrayBuffer(info),\n salt: toArrayBuffer(salt),\n },\n baseKey,\n length * 8,\n );\n return new Uint8Array(derived);\n } catch (cause) {\n throw new CryptoError('CRYPTO/INVALID_KEY', 'HKDF derivation failed', { cause });\n }\n}\n","import { ethers } from 'ethers';\nimport { CryptoError } from '../errors/index.js';\n\nexport interface KeyPair {\n privateKey: string;\n publicKey: string;\n}\n\n/** Fresh secp256k1 keypair. Hex strings returned un-prefixed (no 0x). */\nexport function generateKeyPair(): KeyPair {\n const w = ethers.Wallet.createRandom();\n return {\n privateKey: w.privateKey.slice(2),\n publicKey: w.signingKey.publicKey.slice(2),\n };\n}\n\n/** Recover the uncompressed public key (un-prefixed hex) from a private key. */\nexport function derivePublicKey(privateKey: string): string {\n const sk = new ethers.SigningKey(`0x${strip(privateKey)}`);\n return sk.publicKey.slice(2);\n}\n\nexport function strip(hex: string): string {\n return hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;\n}\n\nexport function assertUncompressedPubKey(pub: string): void {\n const s = strip(pub);\n if (s.length !== 130 || !/^04/i.test(s)) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n 'expected uncompressed secp256k1 pubkey (65 bytes hex, starts with 04)',\n );\n }\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n const s = strip(hex);\n if (s.length % 2 !== 0) {\n throw new CryptoError('CRYPTO/INVALID_KEY', 'hex string has odd length');\n }\n const out = new Uint8Array(s.length / 2);\n for (let i = 0; i < out.length; i++) {\n const byte = Number.parseInt(s.substring(i * 2, i * 2 + 2), 16);\n if (Number.isNaN(byte)) {\n throw new CryptoError('CRYPTO/INVALID_KEY', `invalid hex byte at position ${i * 2}`);\n }\n out[i] = byte;\n }\n return out;\n}\n\nexport function bytesToHex(u: Uint8Array): string {\n return Array.from(u, (b) => b.toString(16).padStart(2, '0')).join('');\n}\n","import { ethers } from 'ethers';\nimport { CryptoError } from '../errors/index.js';\nimport { aesDecrypt, aesEncrypt } from './aes.js';\nimport { ECIES_MIN_BLOB, ECIES_PUBKEY_LENGTH, KEY_LENGTH } from './constants.js';\nimport { hkdfSha256 } from './hkdf.js';\nimport { assertUncompressedPubKey, bytesToHex, hexToBytes, strip } from './keys.js';\n\n/**\n * ECIES-secp256k1 encrypt to a recipient's uncompressed public key.\n * Wire format: [65 ephemeral pubkey][12 IV][16 tag][ciphertext].\n * Byte-compatible with backend/src/services/crypto.ts.\n */\nexport async function eciesEncrypt(plaintext: Uint8Array, recipientPubKey: string): Promise<Uint8Array> {\n assertUncompressedPubKey(recipientPubKey);\n const ephemeral = ethers.Wallet.createRandom();\n const shared = deriveSharedSecretX(ephemeral.privateKey, `0x${strip(recipientPubKey)}`);\n const aesKey = await hkdfSha256(shared, KEY_LENGTH);\n const aesBlob = await aesEncrypt(plaintext, aesKey);\n const ephPub = hexToBytes(strip(ephemeral.signingKey.publicKey));\n if (ephPub.byteLength !== ECIES_PUBKEY_LENGTH) {\n throw new CryptoError('CRYPTO/INVALID_KEY', `ephemeral pubkey length ${ephPub.byteLength}`);\n }\n const blob = new Uint8Array(ECIES_PUBKEY_LENGTH + aesBlob.byteLength);\n blob.set(ephPub, 0);\n blob.set(aesBlob, ECIES_PUBKEY_LENGTH);\n return blob;\n}\n\n/** ECIES-secp256k1 decrypt with the recipient's private key. */\nexport async function eciesDecrypt(blob: Uint8Array, recipientPrivKey: string): Promise<Uint8Array> {\n if (blob.byteLength < ECIES_MIN_BLOB) {\n throw new CryptoError(\n 'CRYPTO/INTEGRITY_CHECK',\n `ECIES blob too short: need ≥${ECIES_MIN_BLOB} bytes, got ${blob.byteLength}`,\n );\n }\n const ephPub = blob.subarray(0, ECIES_PUBKEY_LENGTH);\n const aesBlob = blob.subarray(ECIES_PUBKEY_LENGTH);\n const shared = deriveSharedSecretX(`0x${strip(recipientPrivKey)}`, `0x${bytesToHex(ephPub)}`);\n const aesKey = await hkdfSha256(shared, KEY_LENGTH);\n return aesDecrypt(aesBlob, aesKey);\n}\n\n/**\n * Compute the ECDH shared secret X coordinate (32 bytes) between a private key\n * and a peer's public key. Matches Node createECDH.computeSecret() output used by\n * the backend — ethers v6 returns 0x04||X||Y, so we slice X.\n */\nfunction deriveSharedSecretX(privHex: string, pubHex: string): Uint8Array {\n const sk = new ethers.SigningKey(privHex);\n const shared = sk.computeSharedSecret(pubHex);\n const bytes = hexToBytes(strip(shared));\n if (bytes.byteLength !== 65 || bytes[0] !== 0x04) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `unexpected shared secret shape (len=${bytes.byteLength}, prefix=${bytes[0]?.toString(16) ?? 'none'})`,\n );\n }\n return bytes.subarray(1, 33);\n}\n","export * from './constants.js';\nexport * from './aes.js';\nexport * from './ecies.js';\nexport * from './keys.js';\nexport * from './envelope.js';\nexport { hkdfSha256 } from './hkdf.js';\n","import { CryptoError } from '../errors/index.js';\nimport { aesDecrypt, aesEncrypt, generateAesKey } from './aes.js';\nimport { eciesEncrypt } from './ecies.js';\n\n/**\n * Evidence envelope — the single blob a worker uploads to Storage containing:\n * 1. The AES key wrapped to the agent's pubkey (so agent can decrypt later)\n * 2. The AES key wrapped to the TEE enclave's pubkey (so Sealed Inference can decrypt)\n * 3. The evidence ciphertext under that AES key\n *\n * Wire format (big-endian):\n * bytes 0..1 magic = 0x42 0x42 (\"BB\")\n * byte 2 version = 0x01\n * bytes 3..6 wrappedAgentLen (uint32)\n * bytes 7.. wrappedAgent (ECIES blob)\n * 4-byte uint32 wrappedEnclaveLen\n * bytes wrappedEnclave (ECIES blob)\n * bytes aesCiphertext (rest of the blob — AES blob [IV||tag||ct])\n *\n * The layout is versioned so we can rev it without breaking old blobs.\n */\n\nconst MAGIC_0 = 0x42;\nconst MAGIC_1 = 0x42;\nconst VERSION = 0x01;\nconst HEADER_LEN = 3;\n\nexport interface EvidenceEnvelope {\n wrappedForAgent: Uint8Array;\n wrappedForEnclave: Uint8Array;\n aesCiphertext: Uint8Array;\n}\n\nexport interface SealEvidenceInput {\n evidence: Uint8Array;\n agentPubKey: string;\n enclavePubKey: string;\n}\n\nexport interface SealEvidenceOutput {\n envelope: Uint8Array;\n aesKey: Uint8Array;\n}\n\n/**\n * Seal evidence for the agent + TEE enclave. Generates a fresh AES key,\n * encrypts the evidence, ECIES-wraps the key twice, and concatenates the\n * result as an EvidenceEnvelope. Returns both the on-wire envelope and\n * the raw AES key (for audit / diagnostic use — do NOT persist beyond\n * the submission).\n */\nexport async function sealEvidence(input: SealEvidenceInput): Promise<SealEvidenceOutput> {\n const aesKey = await generateAesKey();\n const aesCiphertext = await aesEncrypt(input.evidence, aesKey);\n const wrappedForAgent = await eciesEncrypt(aesKey, input.agentPubKey);\n const wrappedForEnclave = await eciesEncrypt(aesKey, input.enclavePubKey);\n const envelope = pack({ wrappedForAgent, wrappedForEnclave, aesCiphertext });\n return { envelope, aesKey };\n}\n\n/**\n * Open an evidence envelope as the agent — extracts the AES key wrapped\n * to the agent's pubkey, decrypts the ciphertext, and returns the plaintext\n * evidence. The enclave-wrapped key is ignored by agents (TEE-only).\n */\nexport async function openEvidenceAsAgent(\n envelope: Uint8Array,\n agentPrivKey: string,\n): Promise<Uint8Array> {\n const parsed = parse(envelope);\n const { eciesDecrypt } = await import('./ecies.js');\n const aesKey = await eciesDecrypt(parsed.wrappedForAgent, agentPrivKey);\n return aesDecrypt(parsed.aesCiphertext, aesKey);\n}\n\nfunction pack(parts: EvidenceEnvelope): Uint8Array {\n const { wrappedForAgent, wrappedForEnclave, aesCiphertext } = parts;\n const total =\n HEADER_LEN +\n 4 + wrappedForAgent.byteLength +\n 4 + wrappedForEnclave.byteLength +\n aesCiphertext.byteLength;\n const out = new Uint8Array(total);\n const view = new DataView(out.buffer);\n let off = 0;\n out[off++] = MAGIC_0;\n out[off++] = MAGIC_1;\n out[off++] = VERSION;\n view.setUint32(off, wrappedForAgent.byteLength, false);\n off += 4;\n out.set(wrappedForAgent, off);\n off += wrappedForAgent.byteLength;\n view.setUint32(off, wrappedForEnclave.byteLength, false);\n off += 4;\n out.set(wrappedForEnclave, off);\n off += wrappedForEnclave.byteLength;\n out.set(aesCiphertext, off);\n return out;\n}\n\nfunction parse(blob: Uint8Array): EvidenceEnvelope {\n if (blob.byteLength < HEADER_LEN + 4 + 4) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', `envelope too short: ${blob.byteLength}`);\n }\n if (blob[0] !== MAGIC_0 || blob[1] !== MAGIC_1) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'bad envelope magic');\n }\n if (blob[2] !== VERSION) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', `unknown envelope version ${blob[2]}`);\n }\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);\n let off = HEADER_LEN;\n const agentLen = view.getUint32(off, false);\n off += 4;\n if (off + agentLen + 4 > blob.byteLength) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'envelope truncated (agent)');\n }\n const wrappedForAgent = blob.slice(off, off + agentLen);\n off += agentLen;\n const enclaveLen = view.getUint32(off, false);\n off += 4;\n if (off + enclaveLen > blob.byteLength) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'envelope truncated (enclave)');\n }\n const wrappedForEnclave = blob.slice(off, off + enclaveLen);\n off += enclaveLen;\n const aesCiphertext = blob.slice(off);\n return { wrappedForAgent, wrappedForEnclave, aesCiphertext };\n}\n\nexport const __internals = { pack, parse };\n"]}