@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,221 +0,0 @@
1
- 'use strict';
2
-
3
- var _0gTsSdk = require('@0gfoundation/0g-ts-sdk');
4
-
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __esm = (fn, res) => function __init() {
7
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
- };
9
-
10
- // src/errors/codes.ts
11
- var init_codes = __esm({
12
- "src/errors/codes.ts"() {
13
- }
14
- });
15
-
16
- // src/errors/BlindBountyError.ts
17
- var BlindBountyError;
18
- var init_BlindBountyError = __esm({
19
- "src/errors/BlindBountyError.ts"() {
20
- BlindBountyError = class extends Error {
21
- code;
22
- retriable;
23
- context;
24
- cause;
25
- constructor(code, message, opts = {}) {
26
- super(message);
27
- this.code = code;
28
- this.retriable = opts.retriable ?? false;
29
- if (opts.context !== void 0) this.context = opts.context;
30
- if (opts.cause !== void 0) this.cause = opts.cause;
31
- Object.defineProperty(this, "name", {
32
- value: this.constructor.name,
33
- enumerable: false,
34
- configurable: true,
35
- writable: true
36
- });
37
- }
38
- toJSON() {
39
- return {
40
- name: this.name,
41
- code: this.code,
42
- message: this.message,
43
- retriable: this.retriable,
44
- ...this.context ? { context: this.context } : {}
45
- };
46
- }
47
- };
48
- }
49
- });
50
-
51
- // src/errors/subclasses.ts
52
- var CryptoError, StorageError;
53
- var init_subclasses = __esm({
54
- "src/errors/subclasses.ts"() {
55
- init_BlindBountyError();
56
- CryptoError = class extends BlindBountyError {
57
- constructor(code, msg, opts) {
58
- super(code, msg, opts);
59
- }
60
- };
61
- StorageError = class extends BlindBountyError {
62
- constructor(code, msg, opts) {
63
- super(code, msg, opts);
64
- }
65
- };
66
- }
67
- });
68
-
69
- // src/errors/index.ts
70
- var init_errors = __esm({
71
- "src/errors/index.ts"() {
72
- init_codes();
73
- init_BlindBountyError();
74
- init_subclasses();
75
- }
76
- });
77
-
78
- // src/crypto/aes.ts
79
- function getCrypto() {
80
- const c = globalThis.crypto;
81
- if (!c?.subtle) {
82
- throw new CryptoError("CRYPTO/UNSUPPORTED_CIPHER", "Web Crypto (crypto.subtle) is not available");
83
- }
84
- return c;
85
- }
86
- function toArrayBuffer(u) {
87
- const ab = new ArrayBuffer(u.byteLength);
88
- new Uint8Array(ab).set(u);
89
- return ab;
90
- }
91
- async function sha256(data) {
92
- const digest = await getCrypto().subtle.digest("SHA-256", toArrayBuffer(data));
93
- return new Uint8Array(digest);
94
- }
95
-
96
- // src/storage/MemoryStorage.ts
97
- init_errors();
98
- var MemoryStorage = class {
99
- blobs = /* @__PURE__ */ new Map();
100
- async upload(bytes) {
101
- const rootHash = await this.hash(bytes);
102
- this.blobs.set(rootHash, copy(bytes));
103
- return { rootHash, size: bytes.byteLength };
104
- }
105
- async download(rootHash) {
106
- const data = this.blobs.get(rootHash);
107
- if (!data) {
108
- throw new StorageError("STORAGE/NOT_FOUND", `no blob at ${rootHash}`);
109
- }
110
- return copy(data);
111
- }
112
- async hash(bytes) {
113
- const digest = await sha256(bytes);
114
- return "0x" + Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("");
115
- }
116
- /** Test helper: wipe all stored blobs. */
117
- clear() {
118
- this.blobs.clear();
119
- }
120
- /** Test helper: count of stored blobs. */
121
- size() {
122
- return this.blobs.size;
123
- }
124
- };
125
- function copy(u) {
126
- const c = new Uint8Array(u.byteLength);
127
- c.set(u);
128
- return c;
129
- }
130
-
131
- // src/storage/ZgStorage.ts
132
- init_errors();
133
- var ZgStorage = class {
134
- indexer;
135
- opts;
136
- constructor(opts) {
137
- this.opts = opts;
138
- this.indexer = new _0gTsSdk.Indexer(opts.indexerUrl);
139
- }
140
- async upload(bytes) {
141
- if (!this.opts.signer) {
142
- throw new StorageError("STORAGE/UPLOAD_FAILED", "signer required for uploads");
143
- }
144
- const memData = new _0gTsSdk.MemData(copy2(bytes));
145
- const [tree, treeErr] = await memData.merkleTree();
146
- if (treeErr !== null || !tree) {
147
- throw new StorageError("STORAGE/UPLOAD_FAILED", "merkle tree computation failed", { cause: treeErr ?? void 0 });
148
- }
149
- const rootHash = tree.rootHash();
150
- let txHash;
151
- try {
152
- const [tx, uploadErr] = await this.indexer.upload(memData, this.opts.rpcUrl, this.opts.signer);
153
- if (uploadErr !== null) {
154
- throw new StorageError("STORAGE/UPLOAD_FAILED", "indexer upload failed", {
155
- cause: uploadErr,
156
- retriable: true
157
- });
158
- }
159
- const maybe = tx;
160
- txHash = maybe?.txHash;
161
- } catch (err) {
162
- if (err instanceof StorageError) throw err;
163
- throw new StorageError("STORAGE/UPLOAD_FAILED", "unexpected upload error", {
164
- cause: err,
165
- retriable: true
166
- });
167
- }
168
- return {
169
- rootHash,
170
- ...txHash ? { txHash } : {},
171
- size: bytes.byteLength
172
- };
173
- }
174
- async download(rootHash) {
175
- const [nodeFs, nodePath, nodeOs, nodeCrypto] = await loadNodeFs();
176
- const rand = nodeCrypto.randomBytes(8).toString("hex");
177
- const tmp = nodePath.join(nodeOs.tmpdir(), `0g-${rootHash.replace(/^0x/, "")}-${rand}`);
178
- try {
179
- const err = await this.indexer.download(rootHash, tmp, true);
180
- if (err !== null) {
181
- throw new StorageError("STORAGE/NOT_FOUND", `no blob at ${rootHash}`, {
182
- cause: err,
183
- retriable: true
184
- });
185
- }
186
- return new Uint8Array(nodeFs.readFileSync(tmp));
187
- } finally {
188
- try {
189
- nodeFs.unlinkSync(tmp);
190
- } catch {
191
- }
192
- }
193
- }
194
- async hash(bytes) {
195
- const memData = new _0gTsSdk.MemData(copy2(bytes));
196
- const [tree, err] = await memData.merkleTree();
197
- if (err !== null || !tree) {
198
- throw new StorageError("STORAGE/UPLOAD_FAILED", "merkle tree computation failed", { cause: err ?? void 0 });
199
- }
200
- return tree.rootHash();
201
- }
202
- };
203
- function copy2(u) {
204
- const c = new Uint8Array(u.byteLength);
205
- c.set(u);
206
- return c;
207
- }
208
- async function loadNodeFs() {
209
- const [fs, path, os, crypto] = await Promise.all([
210
- import('fs'),
211
- import('path'),
212
- import('os'),
213
- import('crypto')
214
- ]);
215
- return [fs, path, os, crypto];
216
- }
217
-
218
- exports.MemoryStorage = MemoryStorage;
219
- exports.ZgStorage = ZgStorage;
220
- //# sourceMappingURL=index.cjs.map
221
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/errors/codes.ts","../../src/errors/BlindBountyError.ts","../../src/errors/subclasses.ts","../../src/errors/index.ts","../../src/crypto/aes.ts","../../src/storage/MemoryStorage.ts","../../src/storage/ZgStorage.ts"],"names":["Indexer","MemData","copy"],"mappings":";;;;;;;;;;AAAA,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,QAAA,KAAA,CAAM,OAAO,CAAA;AACb,QAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,QAAA,IAAA,CAAK,SAAA,GAAY,KAAK,SAAA,IAAa,KAAA;AACnC,QAAA,IAAI,IAAA,CAAK,OAAA,KAAY,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AA,EAAM;AACzB,MAAA,MAAM,IAAI,aAAa,uBAAA,EAAyB,gCAAA,EAAkC,EAAE,KAAA,EAAO,GAAA,IAAO,QAAW,CAAA;AAAA,IAC/G;AACA,IAAA,OAAO,KAAK,QAAA,EAAS;AAAA,EACvB;AACF;AAEA,SAASA,MAAK,CAAA,EAA2B;AACvC,EAAA,MAAM,CAAA,GAAI,IAAI,UAAA,CAAW,CAAA,CAAE,UAAU,CAAA;AACrC,EAAA,CAAA,CAAE,IAAI,CAAC,CAAA;AACP,EAAA,OAAO,CAAA;AACT;AAOA,eAAe,UAAA,GAA8D;AAC3E,EAAA,MAAM,CAAC,IAAI,IAAA,EAAM,EAAA,EAAI,MAAM,CAAA,GAAI,MAAM,QAAQ,GAAA,CAAI;AAAA,IAC/C,OAAO,IAAS,CAAA;AAAA,IAChB,OAAO,MAAW,CAAA;AAAA,IAClB,OAAO,IAAS,CAAA;AAAA,IAChB,OAAO,QAAa;AAAA,GACrB,CAAA;AACD,EAAA,OAAO,CAAC,EAAA,EAAyB,IAAA,EAA6B,EAAA,EAAyB,MAA+B,CAAA;AACxH","file":"index.cjs","sourcesContent":["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 { sha256 } from '../crypto/index.js';\nimport { StorageError } from '../errors/index.js';\nimport type { RootHash, UploadResult } from '../types.js';\nimport type { Storage } from './Storage.js';\n\n/**\n * In-process Storage for tests and local development. Deterministic: rootHash\n * is the SHA-256 of the content (not a merkle root), so the same bytes always\n * produce the same hash. Not for production — no replication, no integrity\n * proofs beyond SHA-256.\n */\nexport class MemoryStorage implements Storage {\n private readonly blobs = new Map<string, Uint8Array>();\n\n async upload(bytes: Uint8Array): Promise<UploadResult> {\n const rootHash = await this.hash(bytes);\n this.blobs.set(rootHash, copy(bytes));\n return { rootHash, size: bytes.byteLength };\n }\n\n async download(rootHash: RootHash): Promise<Uint8Array> {\n const data = this.blobs.get(rootHash);\n if (!data) {\n throw new StorageError('STORAGE/NOT_FOUND', `no blob at ${rootHash}`);\n }\n return copy(data);\n }\n\n async hash(bytes: Uint8Array): Promise<RootHash> {\n const digest = await sha256(bytes);\n return ('0x' + Array.from(digest, (b) => b.toString(16).padStart(2, '0')).join('')) as RootHash;\n }\n\n /** Test helper: wipe all stored blobs. */\n clear(): void {\n this.blobs.clear();\n }\n\n /** Test helper: count of stored blobs. */\n size(): number {\n return this.blobs.size;\n }\n}\n\nfunction copy(u: Uint8Array): Uint8Array {\n const c = new Uint8Array(u.byteLength);\n c.set(u);\n return c;\n}\n","import { Indexer, MemData } from '@0gfoundation/0g-ts-sdk';\nimport type { ethers } from 'ethers';\nimport { StorageError } from '../errors/index.js';\nimport type { RootHash, UploadResult } from '../types.js';\nimport type { Storage } from './Storage.js';\n\nexport interface ZgStorageOptions {\n /** 0G Storage indexer URL, e.g. 'https://indexer-storage-testnet-turbo.0g.ai'. */\n indexerUrl: string;\n /** 0G chain RPC URL — passed to the indexer for upload fee submission. */\n rpcUrl: string;\n /** Wallet used to pay for uploads. Reads don't require a signer. */\n signer?: ethers.Signer;\n}\n\n/**\n * Node-only adapter over @0gfoundation/0g-ts-sdk. Browser consumers must\n * provide their own Storage adapter (IPFS, custom server-side proxy, etc.)\n * because the 0G TS SDK uses Node-specific filesystem APIs for downloads.\n */\nexport class ZgStorage implements Storage {\n private readonly indexer: Indexer;\n private readonly opts: ZgStorageOptions;\n\n constructor(opts: ZgStorageOptions) {\n this.opts = opts;\n this.indexer = new Indexer(opts.indexerUrl);\n }\n\n async upload(bytes: Uint8Array): Promise<UploadResult> {\n if (!this.opts.signer) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'signer required for uploads');\n }\n const memData = new MemData(copy(bytes));\n const [tree, treeErr] = await memData.merkleTree();\n if (treeErr !== null || !tree) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'merkle tree computation failed', { cause: treeErr ?? undefined });\n }\n const rootHash = tree.rootHash() as RootHash;\n\n let txHash: string | undefined;\n try {\n // The 0G SDK's Signer types are pinned to a specific ethers minor version\n // that may not match the host project's. Runtime is compatible; the cast\n // avoids false-negative type errors across ethers versions.\n // biome-ignore lint/suspicious/noExplicitAny: see comment above\n const [tx, uploadErr] = await this.indexer.upload(memData, this.opts.rpcUrl, this.opts.signer as any);\n if (uploadErr !== null) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'indexer upload failed', {\n cause: uploadErr,\n retriable: true,\n });\n }\n const maybe = tx as { txHash?: string } | null;\n txHash = maybe?.txHash;\n } catch (err) {\n if (err instanceof StorageError) throw err;\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'unexpected upload error', {\n cause: err,\n retriable: true,\n });\n }\n\n return {\n rootHash,\n ...(txHash ? { txHash: txHash as `0x${string}` } : {}),\n size: bytes.byteLength,\n };\n }\n\n async download(rootHash: RootHash): Promise<Uint8Array> {\n // 0G SDK downloads to a filesystem path. We write to a tmp file, read bytes back,\n // and delete the tmp file regardless of success/failure.\n const [nodeFs, nodePath, nodeOs, nodeCrypto] = await loadNodeFs();\n const rand = nodeCrypto.randomBytes(8).toString('hex');\n const tmp = nodePath.join(nodeOs.tmpdir(), `0g-${rootHash.replace(/^0x/, '')}-${rand}`);\n try {\n const err = await this.indexer.download(rootHash, tmp, true);\n if (err !== null) {\n throw new StorageError('STORAGE/NOT_FOUND', `no blob at ${rootHash}`, {\n cause: err,\n retriable: true,\n });\n }\n return new Uint8Array(nodeFs.readFileSync(tmp));\n } finally {\n try {\n nodeFs.unlinkSync(tmp);\n } catch {\n // ignore cleanup errors\n }\n }\n }\n\n async hash(bytes: Uint8Array): Promise<RootHash> {\n const memData = new MemData(copy(bytes));\n const [tree, err] = await memData.merkleTree();\n if (err !== null || !tree) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'merkle tree computation failed', { cause: err ?? undefined });\n }\n return tree.rootHash() as RootHash;\n }\n}\n\nfunction copy(u: Uint8Array): Uint8Array {\n const c = new Uint8Array(u.byteLength);\n c.set(u);\n return c;\n}\n\ntype NodeFs = { readFileSync: (p: string) => Buffer; unlinkSync: (p: string) => void };\ntype NodePath = { join: (...p: string[]) => string };\ntype NodeOs = { tmpdir: () => string };\ntype NodeCrypto = { randomBytes: (n: number) => { toString: (enc: 'hex') => string } };\n\nasync function loadNodeFs(): Promise<[NodeFs, NodePath, NodeOs, NodeCrypto]> {\n const [fs, path, os, crypto] = await Promise.all([\n import('node:fs'),\n import('node:path'),\n import('node:os'),\n import('node:crypto'),\n ]);\n return [fs as unknown as NodeFs, path as unknown as NodePath, os as unknown as NodeOs, crypto as unknown as NodeCrypto];\n}\n"]}
@@ -1,44 +0,0 @@
1
- import { S as Storage } from '../Storage-Cf4IJRMk.cjs';
2
- import { U as UploadResult, d as RootHash } from '../types-BOG5Ub1z.cjs';
3
- import { ethers } from 'ethers';
4
-
5
- /**
6
- * In-process Storage for tests and local development. Deterministic: rootHash
7
- * is the SHA-256 of the content (not a merkle root), so the same bytes always
8
- * produce the same hash. Not for production — no replication, no integrity
9
- * proofs beyond SHA-256.
10
- */
11
- declare class MemoryStorage implements Storage {
12
- private readonly blobs;
13
- upload(bytes: Uint8Array): Promise<UploadResult>;
14
- download(rootHash: RootHash): Promise<Uint8Array>;
15
- hash(bytes: Uint8Array): Promise<RootHash>;
16
- /** Test helper: wipe all stored blobs. */
17
- clear(): void;
18
- /** Test helper: count of stored blobs. */
19
- size(): number;
20
- }
21
-
22
- interface ZgStorageOptions {
23
- /** 0G Storage indexer URL, e.g. 'https://indexer-storage-testnet-turbo.0g.ai'. */
24
- indexerUrl: string;
25
- /** 0G chain RPC URL — passed to the indexer for upload fee submission. */
26
- rpcUrl: string;
27
- /** Wallet used to pay for uploads. Reads don't require a signer. */
28
- signer?: ethers.Signer;
29
- }
30
- /**
31
- * Node-only adapter over @0gfoundation/0g-ts-sdk. Browser consumers must
32
- * provide their own Storage adapter (IPFS, custom server-side proxy, etc.)
33
- * because the 0G TS SDK uses Node-specific filesystem APIs for downloads.
34
- */
35
- declare class ZgStorage implements Storage {
36
- private readonly indexer;
37
- private readonly opts;
38
- constructor(opts: ZgStorageOptions);
39
- upload(bytes: Uint8Array): Promise<UploadResult>;
40
- download(rootHash: RootHash): Promise<Uint8Array>;
41
- hash(bytes: Uint8Array): Promise<RootHash>;
42
- }
43
-
44
- export { MemoryStorage, Storage, ZgStorage, type ZgStorageOptions };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/errors/codes.ts","../../src/errors/BlindBountyError.ts","../../src/errors/subclasses.ts","../../src/errors/index.ts","../../src/crypto/aes.ts","../../src/storage/MemoryStorage.ts","../../src/storage/ZgStorage.ts"],"names":["copy"],"mappings":";;;;;;;;AAAA,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,QAAA,KAAA,CAAM,OAAO,CAAA;AACb,QAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,QAAA,IAAA,CAAK,SAAA,GAAY,KAAK,SAAA,IAAa,KAAA;AACnC,QAAA,IAAI,IAAA,CAA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CAAC,IAAA,EAAM;AACzB,MAAA,MAAM,IAAI,aAAa,uBAAA,EAAyB,gCAAA,EAAkC,EAAE,KAAA,EAAO,GAAA,IAAO,QAAW,CAAA;AAAA,IAC/G;AACA,IAAA,OAAO,KAAK,QAAA,EAAS;AAAA,EACvB;AACF;AAEA,SAASA,MAAK,CAAA,EAA2B;AACvC,EAAA,MAAM,CAAA,GAAI,IAAI,UAAA,CAAW,CAAA,CAAE,UAAU,CAAA;AACrC,EAAA,CAAA,CAAE,IAAI,CAAC,CAAA;AACP,EAAA,OAAO,CAAA;AACT;AAOA,eAAe,UAAA,GAA8D;AAC3E,EAAA,MAAM,CAAC,IAAI,IAAA,EAAM,EAAA,EAAI,MAAM,CAAA,GAAI,MAAM,QAAQ,GAAA,CAAI;AAAA,IAC/C,OAAO,IAAS,CAAA;AAAA,IAChB,OAAO,MAAW,CAAA;AAAA,IAClB,OAAO,IAAS,CAAA;AAAA,IAChB,OAAO,QAAa;AAAA,GACrB,CAAA;AACD,EAAA,OAAO,CAAC,EAAA,EAAyB,IAAA,EAA6B,EAAA,EAAyB,MAA+B,CAAA;AACxH","file":"index.js","sourcesContent":["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 { sha256 } from '../crypto/index.js';\nimport { StorageError } from '../errors/index.js';\nimport type { RootHash, UploadResult } from '../types.js';\nimport type { Storage } from './Storage.js';\n\n/**\n * In-process Storage for tests and local development. Deterministic: rootHash\n * is the SHA-256 of the content (not a merkle root), so the same bytes always\n * produce the same hash. Not for production — no replication, no integrity\n * proofs beyond SHA-256.\n */\nexport class MemoryStorage implements Storage {\n private readonly blobs = new Map<string, Uint8Array>();\n\n async upload(bytes: Uint8Array): Promise<UploadResult> {\n const rootHash = await this.hash(bytes);\n this.blobs.set(rootHash, copy(bytes));\n return { rootHash, size: bytes.byteLength };\n }\n\n async download(rootHash: RootHash): Promise<Uint8Array> {\n const data = this.blobs.get(rootHash);\n if (!data) {\n throw new StorageError('STORAGE/NOT_FOUND', `no blob at ${rootHash}`);\n }\n return copy(data);\n }\n\n async hash(bytes: Uint8Array): Promise<RootHash> {\n const digest = await sha256(bytes);\n return ('0x' + Array.from(digest, (b) => b.toString(16).padStart(2, '0')).join('')) as RootHash;\n }\n\n /** Test helper: wipe all stored blobs. */\n clear(): void {\n this.blobs.clear();\n }\n\n /** Test helper: count of stored blobs. */\n size(): number {\n return this.blobs.size;\n }\n}\n\nfunction copy(u: Uint8Array): Uint8Array {\n const c = new Uint8Array(u.byteLength);\n c.set(u);\n return c;\n}\n","import { Indexer, MemData } from '@0gfoundation/0g-ts-sdk';\nimport type { ethers } from 'ethers';\nimport { StorageError } from '../errors/index.js';\nimport type { RootHash, UploadResult } from '../types.js';\nimport type { Storage } from './Storage.js';\n\nexport interface ZgStorageOptions {\n /** 0G Storage indexer URL, e.g. 'https://indexer-storage-testnet-turbo.0g.ai'. */\n indexerUrl: string;\n /** 0G chain RPC URL — passed to the indexer for upload fee submission. */\n rpcUrl: string;\n /** Wallet used to pay for uploads. Reads don't require a signer. */\n signer?: ethers.Signer;\n}\n\n/**\n * Node-only adapter over @0gfoundation/0g-ts-sdk. Browser consumers must\n * provide their own Storage adapter (IPFS, custom server-side proxy, etc.)\n * because the 0G TS SDK uses Node-specific filesystem APIs for downloads.\n */\nexport class ZgStorage implements Storage {\n private readonly indexer: Indexer;\n private readonly opts: ZgStorageOptions;\n\n constructor(opts: ZgStorageOptions) {\n this.opts = opts;\n this.indexer = new Indexer(opts.indexerUrl);\n }\n\n async upload(bytes: Uint8Array): Promise<UploadResult> {\n if (!this.opts.signer) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'signer required for uploads');\n }\n const memData = new MemData(copy(bytes));\n const [tree, treeErr] = await memData.merkleTree();\n if (treeErr !== null || !tree) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'merkle tree computation failed', { cause: treeErr ?? undefined });\n }\n const rootHash = tree.rootHash() as RootHash;\n\n let txHash: string | undefined;\n try {\n // The 0G SDK's Signer types are pinned to a specific ethers minor version\n // that may not match the host project's. Runtime is compatible; the cast\n // avoids false-negative type errors across ethers versions.\n // biome-ignore lint/suspicious/noExplicitAny: see comment above\n const [tx, uploadErr] = await this.indexer.upload(memData, this.opts.rpcUrl, this.opts.signer as any);\n if (uploadErr !== null) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'indexer upload failed', {\n cause: uploadErr,\n retriable: true,\n });\n }\n const maybe = tx as { txHash?: string } | null;\n txHash = maybe?.txHash;\n } catch (err) {\n if (err instanceof StorageError) throw err;\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'unexpected upload error', {\n cause: err,\n retriable: true,\n });\n }\n\n return {\n rootHash,\n ...(txHash ? { txHash: txHash as `0x${string}` } : {}),\n size: bytes.byteLength,\n };\n }\n\n async download(rootHash: RootHash): Promise<Uint8Array> {\n // 0G SDK downloads to a filesystem path. We write to a tmp file, read bytes back,\n // and delete the tmp file regardless of success/failure.\n const [nodeFs, nodePath, nodeOs, nodeCrypto] = await loadNodeFs();\n const rand = nodeCrypto.randomBytes(8).toString('hex');\n const tmp = nodePath.join(nodeOs.tmpdir(), `0g-${rootHash.replace(/^0x/, '')}-${rand}`);\n try {\n const err = await this.indexer.download(rootHash, tmp, true);\n if (err !== null) {\n throw new StorageError('STORAGE/NOT_FOUND', `no blob at ${rootHash}`, {\n cause: err,\n retriable: true,\n });\n }\n return new Uint8Array(nodeFs.readFileSync(tmp));\n } finally {\n try {\n nodeFs.unlinkSync(tmp);\n } catch {\n // ignore cleanup errors\n }\n }\n }\n\n async hash(bytes: Uint8Array): Promise<RootHash> {\n const memData = new MemData(copy(bytes));\n const [tree, err] = await memData.merkleTree();\n if (err !== null || !tree) {\n throw new StorageError('STORAGE/UPLOAD_FAILED', 'merkle tree computation failed', { cause: err ?? undefined });\n }\n return tree.rootHash() as RootHash;\n }\n}\n\nfunction copy(u: Uint8Array): Uint8Array {\n const c = new Uint8Array(u.byteLength);\n c.set(u);\n return c;\n}\n\ntype NodeFs = { readFileSync: (p: string) => Buffer; unlinkSync: (p: string) => void };\ntype NodePath = { join: (...p: string[]) => string };\ntype NodeOs = { tmpdir: () => string };\ntype NodeCrypto = { randomBytes: (n: number) => { toString: (enc: 'hex') => string } };\n\nasync function loadNodeFs(): Promise<[NodeFs, NodePath, NodeOs, NodeCrypto]> {\n const [fs, path, os, crypto] = await Promise.all([\n import('node:fs'),\n import('node:path'),\n import('node:os'),\n import('node:crypto'),\n ]);\n return [fs as unknown as NodeFs, path as unknown as NodePath, os as unknown as NodeOs, crypto as unknown as NodeCrypto];\n}\n"]}
@@ -1,4 +0,0 @@
1
- 'use strict';
2
-
3
- //# sourceMappingURL=index.cjs.map
4
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -1,31 +0,0 @@
1
- type Address = `0x${string}`;
2
- type Hex = `0x${string}`;
3
- type TaskId = bigint;
4
- type RootHash = Hex;
5
- type TokenSymbol = 'USDC' | 'A0GI' | string;
6
- interface Reward {
7
- token: Address | TokenSymbol;
8
- amount: bigint;
9
- }
10
- type TaskStatus = 'funded' | 'assigned' | 'submitted' | 'verified' | 'completed' | 'cancelled';
11
- interface TaskKey {
12
- /** AES-256 symmetric key (32 bytes) used to encrypt task content. */
13
- aesKey: Uint8Array;
14
- createdAt: Date;
15
- }
16
- interface TaskKeyRef {
17
- taskId: TaskId;
18
- createdAt: Date;
19
- }
20
- interface UploadResult {
21
- rootHash: RootHash;
22
- txHash?: Hex;
23
- size: number;
24
- }
25
- interface TxReceiptLike {
26
- hash: Hex;
27
- blockNumber: number;
28
- gasUsed: bigint;
29
- }
30
-
31
- export type { Address as A, Hex as H, Reward as R, TaskId as T, UploadResult as U, TaskKey as a, TxReceiptLike as b, TaskKeyRef as c, RootHash as d, TaskStatus as e };
@@ -1,31 +0,0 @@
1
- type Address = `0x${string}`;
2
- type Hex = `0x${string}`;
3
- type TaskId = bigint;
4
- type RootHash = Hex;
5
- type TokenSymbol = 'USDC' | 'A0GI' | string;
6
- interface Reward {
7
- token: Address | TokenSymbol;
8
- amount: bigint;
9
- }
10
- type TaskStatus = 'funded' | 'assigned' | 'submitted' | 'verified' | 'completed' | 'cancelled';
11
- interface TaskKey {
12
- /** AES-256 symmetric key (32 bytes) used to encrypt task content. */
13
- aesKey: Uint8Array;
14
- createdAt: Date;
15
- }
16
- interface TaskKeyRef {
17
- taskId: TaskId;
18
- createdAt: Date;
19
- }
20
- interface UploadResult {
21
- rootHash: RootHash;
22
- txHash?: Hex;
23
- size: number;
24
- }
25
- interface TxReceiptLike {
26
- hash: Hex;
27
- blockNumber: number;
28
- gasUsed: bigint;
29
- }
30
-
31
- export type { Address as A, Hex as H, Reward as R, TaskId as T, UploadResult as U, TaskKey as a, TxReceiptLike as b, TaskKeyRef as c, RootHash as d, TaskStatus as e };
@@ -1,19 +0,0 @@
1
- import { A as Address } from './types-BOG5Ub1z.cjs';
2
-
3
- interface NetworkContracts {
4
- escrow: Address;
5
- registry: Address;
6
- reputation: Address;
7
- usdc: Address;
8
- }
9
- interface Network {
10
- name: string;
11
- chainId: bigint;
12
- rpc: string[];
13
- contracts: NetworkContracts;
14
- indexer: string;
15
- broker: string;
16
- explorer?: string;
17
- }
18
-
19
- export type { Network as N, NetworkContracts as a };
@@ -1,19 +0,0 @@
1
- import { A as Address } from './types-BOG5Ub1z.js';
2
-
3
- interface NetworkContracts {
4
- escrow: Address;
5
- registry: Address;
6
- reputation: Address;
7
- usdc: Address;
8
- }
9
- interface Network {
10
- name: string;
11
- chainId: bigint;
12
- rpc: string[];
13
- contracts: NetworkContracts;
14
- indexer: string;
15
- broker: string;
16
- explorer?: string;
17
- }
18
-
19
- export type { Network as N, NetworkContracts as a };
@@ -1,4 +0,0 @@
1
- 'use strict';
2
-
3
- //# sourceMappingURL=index.cjs.map
4
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}