@dignetwork/dig-sdk 0.0.1-alpha.99 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/LICENSE +21 -7
  2. package/README.md +267 -0
  3. package/dist/adapters.cjs +315 -0
  4. package/dist/adapters.cjs.map +1 -0
  5. package/dist/adapters.d.cts +20 -0
  6. package/dist/adapters.d.ts +20 -0
  7. package/dist/adapters.js +306 -0
  8. package/dist/adapters.js.map +1 -0
  9. package/dist/dev-shim-Bgw8X2E9.d.cts +118 -0
  10. package/dist/dev-shim-Bgw8X2E9.d.ts +118 -0
  11. package/dist/dig-client-entry-BIzuZ7Rs.d.cts +263 -0
  12. package/dist/dig-client-entry-BIzuZ7Rs.d.ts +263 -0
  13. package/dist/dig-client.cjs +330 -0
  14. package/dist/dig-client.cjs.map +1 -0
  15. package/dist/dig-client.d.cts +1 -0
  16. package/dist/dig-client.d.ts +1 -0
  17. package/dist/dig-client.js +319 -0
  18. package/dist/dig-client.js.map +1 -0
  19. package/dist/index.cjs +754 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +192 -0
  22. package/dist/index.d.ts +192 -5
  23. package/dist/index.js +731 -19
  24. package/dist/index.js.map +1 -0
  25. package/dist/next.cjs +326 -0
  26. package/dist/next.cjs.map +1 -0
  27. package/dist/next.d.cts +23 -0
  28. package/dist/next.d.ts +23 -0
  29. package/dist/next.js +319 -0
  30. package/dist/next.js.map +1 -0
  31. package/dist/spend.cjs +14 -0
  32. package/dist/spend.cjs.map +1 -0
  33. package/dist/spend.d.cts +1 -0
  34. package/dist/spend.d.ts +1 -0
  35. package/dist/spend.js +3 -0
  36. package/dist/spend.js.map +1 -0
  37. package/dist/vite.cjs +338 -0
  38. package/dist/vite.cjs.map +1 -0
  39. package/dist/vite.d.cts +35 -0
  40. package/dist/vite.d.ts +35 -0
  41. package/dist/vite.js +332 -0
  42. package/dist/vite.js.map +1 -0
  43. package/package.json +87 -59
  44. package/vendor/PROVENANCE.md +102 -0
  45. package/vendor/dig_client.d.ts +150 -0
  46. package/vendor/dig_client.mjs +805 -0
  47. package/vendor/dig_client_bg.wasm +0 -0
  48. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +0 -163
  49. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +0 -1
  50. package/dist/DataIntegrityTree/DataIntegrityTree.js +0 -707
  51. package/dist/DataIntegrityTree/DataLayerError.d.ts +0 -6
  52. package/dist/DataIntegrityTree/DataLayerError.d.ts.map +0 -1
  53. package/dist/DataIntegrityTree/DataLayerError.js +0 -17
  54. package/dist/DataIntegrityTree/index.d.ts +0 -2
  55. package/dist/DataIntegrityTree/index.d.ts.map +0 -1
  56. package/dist/DataIntegrityTree/index.js +0 -17
  57. package/dist/DigNetwork/ContentServer.d.ts +0 -31
  58. package/dist/DigNetwork/ContentServer.d.ts.map +0 -1
  59. package/dist/DigNetwork/ContentServer.js +0 -176
  60. package/dist/DigNetwork/DigChallenge.d.ts +0 -82
  61. package/dist/DigNetwork/DigChallenge.d.ts.map +0 -1
  62. package/dist/DigNetwork/DigChallenge.js +0 -144
  63. package/dist/DigNetwork/DigNetwork.d.ts +0 -14
  64. package/dist/DigNetwork/DigNetwork.d.ts.map +0 -1
  65. package/dist/DigNetwork/DigNetwork.js +0 -169
  66. package/dist/DigNetwork/DigPeer.d.ts +0 -24
  67. package/dist/DigNetwork/DigPeer.d.ts.map +0 -1
  68. package/dist/DigNetwork/DigPeer.js +0 -118
  69. package/dist/DigNetwork/IncentiveServer.d.ts +0 -13
  70. package/dist/DigNetwork/IncentiveServer.d.ts.map +0 -1
  71. package/dist/DigNetwork/IncentiveServer.js +0 -76
  72. package/dist/DigNetwork/PropagationServer.d.ts +0 -81
  73. package/dist/DigNetwork/PropagationServer.d.ts.map +0 -1
  74. package/dist/DigNetwork/PropagationServer.js +0 -563
  75. package/dist/DigNetwork/index.d.ts +0 -4
  76. package/dist/DigNetwork/index.d.ts.map +0 -1
  77. package/dist/DigNetwork/index.js +0 -19
  78. package/dist/blockchain/DataStore.d.ts +0 -67
  79. package/dist/blockchain/DataStore.d.ts.map +0 -1
  80. package/dist/blockchain/DataStore.js +0 -413
  81. package/dist/blockchain/DataStoreSerializer.d.ts +0 -52
  82. package/dist/blockchain/DataStoreSerializer.d.ts.map +0 -1
  83. package/dist/blockchain/DataStoreSerializer.js +0 -109
  84. package/dist/blockchain/FullNodePeer.d.ts +0 -31
  85. package/dist/blockchain/FullNodePeer.d.ts.map +0 -1
  86. package/dist/blockchain/FullNodePeer.js +0 -295
  87. package/dist/blockchain/ServerCoin.d.ts +0 -29
  88. package/dist/blockchain/ServerCoin.d.ts.map +0 -1
  89. package/dist/blockchain/ServerCoin.js +0 -324
  90. package/dist/blockchain/Wallet.d.ts +0 -28
  91. package/dist/blockchain/Wallet.d.ts.map +0 -1
  92. package/dist/blockchain/Wallet.js +0 -253
  93. package/dist/blockchain/coins.d.ts +0 -6
  94. package/dist/blockchain/coins.d.ts.map +0 -1
  95. package/dist/blockchain/coins.js +0 -102
  96. package/dist/blockchain/index.d.ts +0 -8
  97. package/dist/blockchain/index.d.ts.map +0 -1
  98. package/dist/blockchain/index.js +0 -36
  99. package/dist/index.d.ts.map +0 -1
  100. package/dist/prompts.d.ts +0 -21
  101. package/dist/prompts.d.ts.map +0 -1
  102. package/dist/prompts.js +0 -149
  103. package/dist/types.d.ts +0 -64
  104. package/dist/types.d.ts.map +0 -1
  105. package/dist/types.js +0 -2
  106. package/dist/utils/ContentScanner.d.ts +0 -63
  107. package/dist/utils/ContentScanner.d.ts.map +0 -1
  108. package/dist/utils/ContentScanner.js +0 -175
  109. package/dist/utils/Environment.d.ts +0 -18
  110. package/dist/utils/Environment.d.ts.map +0 -1
  111. package/dist/utils/Environment.js +0 -85
  112. package/dist/utils/FileCache.d.ts +0 -11
  113. package/dist/utils/FileCache.d.ts.map +0 -1
  114. package/dist/utils/FileCache.js +0 -58
  115. package/dist/utils/FileTransfer.d.ts +0 -47
  116. package/dist/utils/FileTransfer.d.ts.map +0 -1
  117. package/dist/utils/FileTransfer.js +0 -209
  118. package/dist/utils/NconfManager.d.ts +0 -11
  119. package/dist/utils/NconfManager.d.ts.map +0 -1
  120. package/dist/utils/NconfManager.js +0 -56
  121. package/dist/utils/StoreArchiveManager.d.ts +0 -45
  122. package/dist/utils/StoreArchiveManager.d.ts.map +0 -1
  123. package/dist/utils/StoreArchiveManager.js +0 -153
  124. package/dist/utils/asyncPool.d.ts +0 -9
  125. package/dist/utils/asyncPool.d.ts.map +0 -1
  126. package/dist/utils/asyncPool.js +0 -23
  127. package/dist/utils/config.d.ts +0 -68
  128. package/dist/utils/config.d.ts.map +0 -1
  129. package/dist/utils/config.js +0 -223
  130. package/dist/utils/connectionUtils.d.ts +0 -10
  131. package/dist/utils/connectionUtils.d.ts.map +0 -1
  132. package/dist/utils/connectionUtils.js +0 -18
  133. package/dist/utils/credentialsUtils.d.ts +0 -8
  134. package/dist/utils/credentialsUtils.d.ts.map +0 -1
  135. package/dist/utils/credentialsUtils.js +0 -122
  136. package/dist/utils/directoryUtils.d.ts +0 -9
  137. package/dist/utils/directoryUtils.d.ts.map +0 -1
  138. package/dist/utils/directoryUtils.js +0 -110
  139. package/dist/utils/encryption.d.ts +0 -8
  140. package/dist/utils/encryption.d.ts.map +0 -1
  141. package/dist/utils/encryption.js +0 -55
  142. package/dist/utils/hashUtils.d.ts +0 -8
  143. package/dist/utils/hashUtils.d.ts.map +0 -1
  144. package/dist/utils/hashUtils.js +0 -44
  145. package/dist/utils/index.d.ts +0 -14
  146. package/dist/utils/index.d.ts.map +0 -1
  147. package/dist/utils/index.js +0 -29
  148. package/dist/utils/merkle.d.ts +0 -2
  149. package/dist/utils/merkle.d.ts.map +0 -1
  150. package/dist/utils/merkle.js +0 -28
  151. package/dist/utils/network.d.ts +0 -2
  152. package/dist/utils/network.d.ts.map +0 -1
  153. package/dist/utils/network.js +0 -54
  154. package/dist/utils/spinnerUtils.d.ts +0 -2
  155. package/dist/utils/spinnerUtils.d.ts.map +0 -1
  156. package/dist/utils/spinnerUtils.js +0 -47
  157. package/dist/utils/ssl.d.ts +0 -5
  158. package/dist/utils/ssl.d.ts.map +0 -1
  159. package/dist/utils/ssl.js +0 -50
  160. package/dist/utils/validationUtils.d.ts +0 -9
  161. package/dist/utils/validationUtils.d.ts.map +0 -1
  162. package/dist/utils/validationUtils.js +0 -55
@@ -0,0 +1 @@
1
+ export { D as DEFAULT_RPC, b as DIG_CLIENT_WASM_SHA256, c as DigClient, d as DigClientOptions, e as DigClientWasm, P as ParsedUrn, R as ReadOptions, f as ReadResult, U as UrnKeys, g as WasmConfig, h as configureWasm, i as isUrn, l as loadDigClientWasm, p as parseUrn, r as reconstructUrn, j as reconstructUrnWithRoot } from './dig-client-entry-BIzuZ7Rs.cjs';
@@ -0,0 +1 @@
1
+ export { D as DEFAULT_RPC, b as DIG_CLIENT_WASM_SHA256, c as DigClient, d as DigClientOptions, e as DigClientWasm, P as ParsedUrn, R as ReadOptions, f as ReadResult, U as UrnKeys, g as WasmConfig, h as configureWasm, i as isUrn, l as loadDigClientWasm, p as parseUrn, r as reconstructUrn, j as reconstructUrnWithRoot } from './dig-client-entry-BIzuZ7Rs.js';
@@ -0,0 +1,319 @@
1
+ // src/loader.ts
2
+ var DIG_CLIENT_WASM_SHA256 = "ff486be806f908a2a90780e499a04dbd34e10e3b97be0470cb9ee841a1e49e77";
3
+ var _config = {};
4
+ var _ready = null;
5
+ function configureWasm(config) {
6
+ _config = { ...config };
7
+ _ready = null;
8
+ }
9
+ var isNode = typeof process !== "undefined" && !!process.versions?.node;
10
+ async function sha256Hex(bytes) {
11
+ if (isNode) {
12
+ const { createHash } = await import('crypto');
13
+ const view = bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : new Uint8Array(
14
+ bytes.buffer,
15
+ bytes.byteOffset,
16
+ bytes.byteLength
17
+ );
18
+ return createHash("sha256").update(view).digest("hex");
19
+ }
20
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
21
+ return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
22
+ }
23
+ function assertIntegrity(hex) {
24
+ if (_config.skipIntegrity) return;
25
+ if (hex !== DIG_CLIENT_WASM_SHA256) {
26
+ throw new Error(
27
+ `dig-client wasm integrity check failed \u2014 refusing to run unverified crypto (expected ${DIG_CLIENT_WASM_SHA256}, got ${hex}).`
28
+ );
29
+ }
30
+ }
31
+ async function loadNode() {
32
+ const { readFile } = await import('fs/promises');
33
+ const { fileURLToPath, pathToFileURL } = await import('url');
34
+ const path = await import('path');
35
+ const here = path.dirname(fileURLToPath(import.meta.url));
36
+ const vendorDir = path.resolve(here, "..", "vendor");
37
+ const wasmPath = path.join(vendorDir, "dig_client_bg.wasm");
38
+ const gluePath = path.join(vendorDir, "dig_client.mjs");
39
+ const buf = await readFile(wasmPath);
40
+ const bytes = new Uint8Array(buf.byteLength);
41
+ bytes.set(buf);
42
+ return { glueHref: pathToFileURL(gluePath).href, bytes };
43
+ }
44
+ async function loadBrowser() {
45
+ const glueHref = _config.glueUrl ?? new URL("../vendor/dig_client.mjs", import.meta.url).href;
46
+ let bytes;
47
+ if (_config.wasmBytes) {
48
+ bytes = _config.wasmBytes;
49
+ } else {
50
+ const wasmUrl = _config.wasmUrl ?? new URL("../vendor/dig_client_bg.wasm", import.meta.url).href;
51
+ const res = await fetch(wasmUrl);
52
+ if (!res.ok) throw new Error(`dig-client wasm fetch failed (${res.status})`);
53
+ bytes = await res.arrayBuffer();
54
+ }
55
+ return { glueHref, bytes };
56
+ }
57
+ function loadDigClientWasm() {
58
+ if (_ready) return _ready;
59
+ _ready = (async () => {
60
+ const { glueHref, bytes } = isNode ? await loadNode() : await loadBrowser();
61
+ assertIntegrity(await sha256Hex(bytes));
62
+ const mod = await import(
63
+ /* @vite-ignore */
64
+ glueHref
65
+ );
66
+ await mod.default({ module_or_path: bytes });
67
+ return mod;
68
+ })().catch((e) => {
69
+ _ready = null;
70
+ throw e;
71
+ });
72
+ return _ready;
73
+ }
74
+
75
+ // src/urn.ts
76
+ var URN_RE = /^urn:dig:chia:([0-9a-fA-F]{64})(?::([0-9a-fA-F]{64}))?\/(.+?)(?:\?salt=([0-9a-fA-F]+))?$/;
77
+ function parseUrn(raw) {
78
+ const s = String(raw ?? "").trim();
79
+ const m = URN_RE.exec(s);
80
+ if (!m) {
81
+ throw new Error(
82
+ "Not a valid dig URN (expected urn:dig:chia:<store-id>[:<root>]/<path>[?salt=<hex>])."
83
+ );
84
+ }
85
+ return {
86
+ storeId: m[1].toLowerCase(),
87
+ root: m[2] ? m[2].toLowerCase() : null,
88
+ resourceKey: m[3],
89
+ salt: m[4] ? m[4].toLowerCase() : null
90
+ };
91
+ }
92
+ function isUrn(raw) {
93
+ try {
94
+ parseUrn(raw);
95
+ return true;
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
100
+ function reconstructUrn(storeId, resourceKey) {
101
+ const key = resourceKey && resourceKey.length > 0 ? resourceKey : "index.html";
102
+ return `urn:dig:chia:${storeId.toLowerCase()}/${key}`;
103
+ }
104
+ function reconstructUrnWithRoot(storeId, root, resourceKey) {
105
+ const key = resourceKey && resourceKey.length > 0 ? resourceKey : "index.html";
106
+ return `urn:dig:chia:${storeId.toLowerCase()}:${root.toLowerCase()}/${key}`;
107
+ }
108
+
109
+ // src/dig-client.ts
110
+ var DEFAULT_RPC = "https://rpc.dig.net";
111
+ var RPC_CHUNK_BYTES = 3 * 1024 * 1024;
112
+ function b64ToBytes(b64) {
113
+ if (typeof atob === "function") {
114
+ const bin = atob(b64);
115
+ const out = new Uint8Array(bin.length);
116
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
117
+ return out;
118
+ }
119
+ return new Uint8Array(globalThis.Buffer.from(b64, "base64"));
120
+ }
121
+ var DigClient = class {
122
+ constructor(options = {}) {
123
+ this.rpc = options.rpc ?? DEFAULT_RPC;
124
+ this.fetchImpl = options.fetch ?? (typeof fetch === "function" ? fetch.bind(globalThis) : undefinedFetch());
125
+ }
126
+ /** Load (and SRI-verify) the read-crypto wasm. Exposed for callers that want the raw functions. */
127
+ async wasm() {
128
+ return loadDigClientWasm();
129
+ }
130
+ /** `retrieval_key = SHA-256(canonical rootless URN)`, lowercase hex. */
131
+ async retrievalKey(storeId, resourceKey) {
132
+ return (await this.wasm()).retrievalKey(storeId, resourceKey);
133
+ }
134
+ /** Derive the per-URN AES-256-GCM-SIV key, lowercase hex. `salt` for a private store. */
135
+ async deriveKey(storeId, resourceKey, salt) {
136
+ return (await this.wasm()).deriveKey(storeId, resourceKey, salt ?? void 0);
137
+ }
138
+ /** Verify served `ciphertext` is included under `root` via the base64 merkle `proof`. */
139
+ async verifyInclusion(ciphertext, proof, root) {
140
+ return (await this.wasm()).verifyInclusion(ciphertext, proof, root);
141
+ }
142
+ /** Reconstruct the canonical rootless URN whose SHA-256 is the retrieval key. */
143
+ async reconstructUrn(storeId, resourceKey) {
144
+ return (await this.wasm()).reconstructUrn(storeId, resourceKey);
145
+ }
146
+ /**
147
+ * Derive, client-side, the two root-independent keys a URN maps to (retrieval + decryption).
148
+ * Nothing is sent to the network — pure local derivation via the wasm.
149
+ */
150
+ async deriveUrnKeys(input) {
151
+ const parsed = parseUrn(input.urn);
152
+ const wasm = await this.wasm();
153
+ const effSalt = input.salt ?? parsed.salt ?? void 0;
154
+ return {
155
+ storeId: parsed.storeId,
156
+ root: parsed.root,
157
+ resourceKey: parsed.resourceKey,
158
+ salt: effSalt ?? null,
159
+ retrievalKey: wasm.retrievalKey(parsed.storeId, parsed.resourceKey),
160
+ decryptionKey: wasm.deriveKey(parsed.storeId, parsed.resourceKey, effSalt)
161
+ };
162
+ }
163
+ /**
164
+ * Fetch + verify + decrypt one resource by URN. `root` is the on-chain generation root to verify
165
+ * against (resolved by the caller from the chain); when omitted, the root embedded in the URN is
166
+ * used. Returns the bytes plus advisory `verified`/`decrypted` flags. NEVER throws "not found"
167
+ * (presence is unknowable) — it throws only on a transport failure.
168
+ */
169
+ async read(input, opts = {}) {
170
+ const parsed = parseUrn(input.urn);
171
+ const effSalt = input.salt ?? parsed.salt ?? null;
172
+ const effRoot = input.root ?? parsed.root ?? null;
173
+ if (!effRoot) {
174
+ throw new Error(
175
+ "a confirmed on-chain root is required to read content (pass { root } or use a root-pinned URN)"
176
+ );
177
+ }
178
+ return this.readResource(
179
+ { storeId: parsed.storeId, resourceKey: parsed.resourceKey, root: effRoot, salt: effSalt },
180
+ opts
181
+ );
182
+ }
183
+ /** As `read`, but decoding the plaintext to a UTF-8 string when it decrypts (else throws). */
184
+ async readText(input, opts = {}) {
185
+ const r = await this.read(input, opts);
186
+ if (!r.decrypted) {
187
+ throw new Error(
188
+ "resource did not decrypt under this URN \u2014 wrong store/key/salt, or a decoy response"
189
+ );
190
+ }
191
+ return new TextDecoder().decode(r.bytes);
192
+ }
193
+ /**
194
+ * Read by explicit (storeId, resourceKey, root, salt) rather than a URN string. The oblivious
195
+ * download primitive the URN read is built on.
196
+ */
197
+ async readResource(input, opts = {}) {
198
+ const rpc = opts.rpc ?? this.rpc;
199
+ const wasm = await this.wasm();
200
+ const rk = wasm.retrievalKey(input.storeId, input.resourceKey);
201
+ const { ciphertext, proof, chunkLens } = await this.fetchCiphertext(
202
+ input.storeId,
203
+ rk,
204
+ input.root,
205
+ rpc
206
+ );
207
+ let verified = false;
208
+ try {
209
+ verified = !!wasm.verifyInclusion(ciphertext, proof, input.root);
210
+ } catch {
211
+ verified = false;
212
+ }
213
+ const keyHex = wasm.deriveKey(input.storeId, input.resourceKey, input.salt ?? void 0);
214
+ try {
215
+ const bytes = decryptResourceChunks(wasm, keyHex, ciphertext, chunkLens);
216
+ return {
217
+ storeId: input.storeId,
218
+ root: input.root,
219
+ resourceKey: input.resourceKey,
220
+ salt: input.salt ?? null,
221
+ bytes,
222
+ verified,
223
+ decrypted: true
224
+ };
225
+ } catch {
226
+ return {
227
+ storeId: input.storeId,
228
+ root: input.root,
229
+ resourceKey: input.resourceKey,
230
+ salt: input.salt ?? null,
231
+ bytes: ciphertext,
232
+ verified,
233
+ decrypted: false
234
+ };
235
+ }
236
+ }
237
+ // Stream the FULL ciphertext for a resource from the RPC by retrieval key, reassembling 3-MiB
238
+ // chunks. A null result is a TRANSPORT failure, never a presence judgment.
239
+ async fetchCiphertext(storeId, rk, root, rpc) {
240
+ let offset = 0;
241
+ let total = null;
242
+ let buf = null;
243
+ let proof = "";
244
+ let chunkLens = null;
245
+ for (; ; ) {
246
+ const r = await this.rpcCall(rpc, "dig.getContent", {
247
+ store_id: storeId,
248
+ root,
249
+ retrieval_key: rk,
250
+ offset,
251
+ length: RPC_CHUNK_BYTES
252
+ });
253
+ if (!r) throw new Error("The content network returned no data for this request.");
254
+ if (total === null) {
255
+ total = r.total_length >>> 0;
256
+ buf = new Uint8Array(total);
257
+ }
258
+ if (chunkLens === null && Array.isArray(r.chunk_lens)) {
259
+ chunkLens = r.chunk_lens.map((n) => n >>> 0);
260
+ }
261
+ const chunk = b64ToBytes(r.ciphertext ?? "");
262
+ const at = r.offset >>> 0;
263
+ buf.set(chunk.subarray(0, Math.max(0, Math.min(chunk.length, total - at))), at);
264
+ if (r.inclusion_proof) proof = r.inclusion_proof;
265
+ if (r.complete || r.next_offset == null) break;
266
+ offset = r.next_offset >>> 0;
267
+ }
268
+ return { ciphertext: buf ?? new Uint8Array(0), proof, chunkLens };
269
+ }
270
+ // One JSON-RPC 2.0 call. Throws on transport failure or a JSON-RPC error; returns `result`.
271
+ async rpcCall(rpc, method, params) {
272
+ let res;
273
+ try {
274
+ res = await this.fetchImpl(rpc, {
275
+ method: "POST",
276
+ headers: { "content-type": "application/json" },
277
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params })
278
+ });
279
+ } catch {
280
+ throw new Error("Could not reach the content network. Check your connection and try again.");
281
+ }
282
+ if (!res.ok) throw new Error(`dig RPC ${method} failed (${res.status})`);
283
+ const json = await res.json();
284
+ if (json && json.error) throw new Error(`dig RPC ${method}: ${json.error.message ?? "error"}`);
285
+ return json ? json.result ?? null : null;
286
+ }
287
+ };
288
+ function decryptResourceChunks(wasm, keyHex, ciphertext, chunkLens) {
289
+ const lens = chunkLens && chunkLens.length ? chunkLens : [ciphertext.length];
290
+ const total = lens.reduce((a, n) => a + n, 0);
291
+ if (total !== ciphertext.length) {
292
+ throw new Error("served ciphertext length does not match chunk lengths");
293
+ }
294
+ if (lens.length === 1) return wasm.decryptChunk(keyHex, ciphertext);
295
+ const parts = [];
296
+ let p = 0;
297
+ for (const len of lens) {
298
+ parts.push(wasm.decryptChunk(keyHex, ciphertext.subarray(p, p + len)));
299
+ p += len;
300
+ }
301
+ const out = new Uint8Array(parts.reduce((a, x) => a + x.length, 0));
302
+ let q = 0;
303
+ for (const part of parts) {
304
+ out.set(part, q);
305
+ q += part.length;
306
+ }
307
+ return out;
308
+ }
309
+ function undefinedFetch() {
310
+ return (() => {
311
+ throw new Error(
312
+ "No global fetch available. Pass { fetch } to DigClient (Node < 18 needs a fetch polyfill)."
313
+ );
314
+ });
315
+ }
316
+
317
+ export { DEFAULT_RPC, DIG_CLIENT_WASM_SHA256, DigClient, configureWasm, isUrn, loadDigClientWasm, parseUrn, reconstructUrn, reconstructUrnWithRoot };
318
+ //# sourceMappingURL=dig-client.js.map
319
+ //# sourceMappingURL=dig-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/loader.ts","../src/urn.ts","../src/dig-client.ts"],"names":[],"mappings":";AAmBO,IAAM,sBAAA,GACX;AAuBF,IAAI,UAAsB,EAAC;AAC3B,IAAI,MAAA,GAAwC,IAAA;AAOrC,SAAS,cAAc,MAAA,EAA0B;AACtD,EAAA,OAAA,GAAU,EAAE,GAAG,MAAA,EAAO;AACtB,EAAA,MAAA,GAAS,IAAA;AACX;AAEA,IAAM,SACJ,OAAO,OAAA,KAAY,eACnB,CAAC,CAAE,QAA6C,QAAA,EAAU,IAAA;AAG5D,eAAe,UAAU,KAAA,EAAsC;AAC7D,EAAA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AAA,CAAW,SAAS,CAAA,EAAG,CAAA,GAAI,GAAG,CAAC,CAAC,CAAA;AACrE,IAAA,CAAA,IAAK,GAAA;AAAA,EACP;AACA,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,EAAG,CAAA,KAAM,CAAA,GAAI,CAAA,CAAE,MAAA,EAAQ,CAAC,CAAC,CAAA;AAClE,EAAA,IAAI,CAAA,GAAI,CAAA;AACR,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,GAAA,CAAI,GAAA,CAAI,MAAM,CAAC,CAAA;AACf,IAAA,CAAA,IAAK,IAAA,CAAK,MAAA;AAAA,EACZ;AACA,EAAA,OAAO,GAAA;AACT;AAEA,SAAS,cAAA,GAA+B;AACtC,EAAA,QAAQ,MAAM;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF,CAAA;AACF","file":"dig-client.js","sourcesContent":["// Cross-target loader for the vendored `dig_client` read-crypto WASM.\n//\n// The wasm is the SAME artifact the DIG Browser, extension, companion, and hub all run — vendored\n// under vendor/ with a PROVENANCE note and pinned SRI (see vendor/PROVENANCE.md). We NEVER run it\n// unverified: we obtain the raw bytes, SHA-256 them, compare against the pinned digest, and only\n// then hand the verified bytes to wasm-bindgen's init. A mismatch (tampered / wrong artifact)\n// throws — the reader FAILS CLOSED rather than running unverified crypto.\n//\n// Three runtimes are supported, auto-detected, with an escape hatch (`configureWasm`):\n// • Node / Bun — read vendor/ files from the package directory (fs + node:crypto).\n// • Browser (bundled) — the consumer's bundler can resolve the vendor files; if it can't, the\n// consumer supplies bytes via `configureWasm({ wasmBytes, glueUrl })`.\n// • Browser (no bundler) — `configureWasm` with a URL/bytes you serve yourself.\n//\n// Memoized: the wasm initializes at most once per process/page.\n\nimport type { DigClientWasm } from \"./wasm.js\";\n\n/** SHA-256 (lowercase hex) of vendor/dig_client_bg.wasm — the SRI digest. Fail closed on mismatch. */\nexport const DIG_CLIENT_WASM_SHA256 =\n \"ff486be806f908a2a90780e499a04dbd34e10e3b97be0470cb9ee841a1e49e77\";\n\n/** Optional explicit wasm inputs, for environments where auto-resolution can't find vendor/. */\nexport interface WasmConfig {\n /**\n * The wasm bytes (already loaded). When provided, SRI is still enforced unless `skipIntegrity`.\n * Pass this in CSP-strict browsers where you fetch + verify the bytes yourself.\n */\n wasmBytes?: BufferSource;\n /**\n * URL to the wasm-bindgen glue module (vendor/dig_client.mjs) for browser dynamic import. When\n * omitted in a browser, the loader tries to import the glue relative to this module.\n */\n glueUrl?: string;\n /**\n * URL to fetch the wasm bytes from (browser) when `wasmBytes` is not supplied. The fetched bytes\n * are SRI-verified before init.\n */\n wasmUrl?: string;\n /** Skip the SRI check. Only for tests / trusted custom builds — NOT recommended. */\n skipIntegrity?: boolean;\n}\n\nlet _config: WasmConfig = {};\nlet _ready: Promise<DigClientWasm> | null = null;\n\n/**\n * Override how the read-crypto wasm is located/loaded. Call BEFORE the first `DigClient` read.\n * Mainly for browsers without a bundler that resolves package files, or CSP-strict apps that fetch\n * + verify the wasm bytes themselves and hand them in. Resets any cached instance.\n */\nexport function configureWasm(config: WasmConfig): void {\n _config = { ...config };\n _ready = null;\n}\n\nconst isNode =\n typeof process !== \"undefined\" &&\n !!(process as { versions?: { node?: string } }).versions?.node;\n\n/** SHA-256 a buffer to lowercase hex, using node:crypto or WebCrypto. */\nasync function sha256Hex(bytes: BufferSource): Promise<string> {\n if (isNode) {\n const { createHash } = await import(\"node:crypto\");\n const view =\n bytes instanceof ArrayBuffer\n ? new Uint8Array(bytes)\n : new Uint8Array(\n (bytes as ArrayBufferView).buffer,\n (bytes as ArrayBufferView).byteOffset,\n (bytes as ArrayBufferView).byteLength,\n );\n return createHash(\"sha256\").update(view).digest(\"hex\");\n }\n const digest = await crypto.subtle.digest(\"SHA-256\", bytes as BufferSource);\n return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nfunction assertIntegrity(hex: string): void {\n if (_config.skipIntegrity) return;\n if (hex !== DIG_CLIENT_WASM_SHA256) {\n throw new Error(\n \"dig-client wasm integrity check failed — refusing to run unverified crypto \" +\n `(expected ${DIG_CLIENT_WASM_SHA256}, got ${hex}).`,\n );\n }\n}\n\n// Read the vendored glue URL + wasm bytes for Node from the package's vendor/ directory.\nasync function loadNode(): Promise<{ glueHref: string; bytes: BufferSource }> {\n const { readFile } = await import(\"node:fs/promises\");\n const { fileURLToPath, pathToFileURL } = await import(\"node:url\");\n const path = await import(\"node:path\");\n // This module lives in dist/; vendor/ sits at the package root, one level up.\n const here = path.dirname(fileURLToPath(import.meta.url));\n const vendorDir = path.resolve(here, \"..\", \"vendor\");\n const wasmPath = path.join(vendorDir, \"dig_client_bg.wasm\");\n const gluePath = path.join(vendorDir, \"dig_client.mjs\");\n const buf = await readFile(wasmPath);\n // Copy into a fresh ArrayBuffer-backed view so the type is a plain BufferSource (not the\n // ArrayBufferLike/SharedArrayBuffer union the Node Buffer type widens to).\n const bytes = new Uint8Array(buf.byteLength);\n bytes.set(buf);\n return { glueHref: pathToFileURL(gluePath).href, bytes };\n}\n\n// Resolve the glue URL + wasm bytes for a browser. Prefers explicit config; otherwise resolves\n// the vendored files relative to this module (works when the bundler copies vendor/ alongside).\nasync function loadBrowser(): Promise<{ glueHref: string; bytes: BufferSource }> {\n const glueHref =\n _config.glueUrl ?? new URL(\"../vendor/dig_client.mjs\", import.meta.url).href;\n let bytes: BufferSource;\n if (_config.wasmBytes) {\n bytes = _config.wasmBytes;\n } else {\n const wasmUrl =\n _config.wasmUrl ?? new URL(\"../vendor/dig_client_bg.wasm\", import.meta.url).href;\n const res = await fetch(wasmUrl);\n if (!res.ok) throw new Error(`dig-client wasm fetch failed (${res.status})`);\n bytes = await res.arrayBuffer();\n }\n return { glueHref, bytes };\n}\n\n/**\n * Load, SRI-verify, and instantiate the read-crypto wasm, returning its functions. Memoized — at\n * most one init per process/page. Fails closed on an integrity mismatch.\n */\nexport function loadDigClientWasm(): Promise<DigClientWasm> {\n if (_ready) return _ready;\n _ready = (async () => {\n const { glueHref, bytes } = isNode ? await loadNode() : await loadBrowser();\n assertIntegrity(await sha256Hex(bytes));\n const mod = (await import(/* @vite-ignore */ glueHref)) as {\n default: (input: { module_or_path: BufferSource }) => Promise<unknown>;\n } & Partial<DigClientWasm>;\n // wasm-bindgen default export = async init; accepts raw bytes via { module_or_path }.\n await mod.default({ module_or_path: bytes });\n return mod as unknown as DigClientWasm;\n })().catch((e) => {\n _ready = null; // allow a retry on transient load failure\n throw e;\n });\n return _ready;\n}\n","// DIG URN parsing + canonicalization — PURE, dependency-free, and identical to the parser the\n// hub (apps/web/lib/dig-client.js), the extension, and the companion use. Kept pure (no wasm) so\n// it is trivially unit-testable under `node --test` and usable on any runtime.\n//\n// A DIG URN addresses one resource inside a store:\n//\n// urn:dig:chia:<store_id>[:<root>]/<resource_key>[?salt=<hex>]\n//\n// • <store_id> — 64 hex chars, the singleton launcher id (the store identity).\n// • :<root> — OPTIONAL 64 hex chars, pins a specific on-chain generation. Omit for the\n// canonical, root-INDEPENDENT form. The root is only the trust anchor for\n// inclusion verification; it is NOT a key input (retrieval/decryption keys are\n// root-independent).\n// • <resource_key> — the path within the store (e.g. \"index.html\", \"img/logo.png\"). An empty\n// key resolves to the §8.5 default view \"index.html\".\n// • ?salt=<hex> — OPTIONAL out-of-band secret salt for a PRIVATE store.\n\n/** The parts of a parsed DIG URN. `root`/`salt` are null when absent. */\nexport interface ParsedUrn {\n /** Store identity (64-hex launcher id), lowercased. */\n readonly storeId: string;\n /** Generation root (64-hex), lowercased — or null for the root-independent form. */\n readonly root: string | null;\n /** Resource path within the store (verbatim, not lowercased). */\n readonly resourceKey: string;\n /** Private-store secret salt (hex), lowercased — or null for a public store. */\n readonly salt: string | null;\n}\n\nconst URN_RE =\n /^urn:dig:chia:([0-9a-fA-F]{64})(?::([0-9a-fA-F]{64}))?\\/(.+?)(?:\\?salt=([0-9a-fA-F]+))?$/;\n\n/**\n * Parse a DIG URN into its parts. Throws on a malformed URN.\n *\n * @example\n * parseUrn(\"urn:dig:chia:\" + \"ab\".repeat(32) + \"/index.html\")\n * // → { storeId: \"abab…\", root: null, resourceKey: \"index.html\", salt: null }\n */\nexport function parseUrn(raw: string): ParsedUrn {\n const s = String(raw ?? \"\").trim();\n const m = URN_RE.exec(s);\n if (!m) {\n throw new Error(\n \"Not a valid dig URN (expected urn:dig:chia:<store-id>[:<root>]/<path>[?salt=<hex>]).\",\n );\n }\n return {\n storeId: m[1]!.toLowerCase(),\n root: m[2] ? m[2].toLowerCase() : null,\n resourceKey: m[3]!,\n salt: m[4] ? m[4].toLowerCase() : null,\n };\n}\n\n/** True iff `raw` is a syntactically valid DIG URN. Never throws. */\nexport function isUrn(raw: string): boolean {\n try {\n parseUrn(raw);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Reconstruct the canonical, root-INDEPENDENT URN string for a store + resource key:\n * `urn:dig:chia:<store_id>/<resource_key>`. An empty resource key resolves to the default view\n * `index.html`. This is the form whose SHA-256 is the retrieval key and whose bytes seed the AES\n * key — matching the wasm's `reconstructUrn`.\n */\nexport function reconstructUrn(storeId: string, resourceKey: string): string {\n const key = resourceKey && resourceKey.length > 0 ? resourceKey : \"index.html\";\n return `urn:dig:chia:${storeId.toLowerCase()}/${key}`;\n}\n\n/**\n * Reconstruct a root-PINNED display URN: `urn:dig:chia:<store_id>:<root>/<resource_key>`. Useful\n * for sharing a URN bound to a specific generation; the retrieval/AES keys still use the rootless\n * form (`reconstructUrn`).\n */\nexport function reconstructUrnWithRoot(\n storeId: string,\n root: string,\n resourceKey: string,\n): string {\n const key = resourceKey && resourceKey.length > 0 ? resourceKey : \"index.html\";\n return `urn:dig:chia:${storeId.toLowerCase()}:${root.toLowerCase()}/${key}`;\n}\n","// DigClient — the read side of the SDK. It fetches a resource's served ciphertext from the dig RPC,\n// derives the URN's keys CLIENT-SIDE via the read-crypto wasm, verifies inclusion against an\n// on-chain root, and decrypts — so the serving host stays BLIND (it only ever relays opaque\n// ciphertext + proofs). Genericized from hub.dig.net/apps/web/lib/dig-client.js, with the hub-app\n// coupling removed (no Vite import.meta.env, no window.location origin; the RPC endpoint and the\n// trust root are explicit inputs).\n//\n// HARD BOUNDARY (read sources). Everything read from a .dig — ciphertext, inclusion proofs, the\n// public manifest, metadata — comes ONLY from the dig RPC. The trust ROOT it is verified against\n// comes from the chain (the caller resolves it from coinset.org and passes it in). The host can\n// never become the trust anchor: every content read REQUIRES a caller-supplied root.\n//\n// OBLIVIOUS model. The host returns indistinguishable ciphertext for any retrieval key, so\n// presence is UNKNOWABLE. A read therefore NEVER concludes \"not found\": it returns plaintext when\n// the URN key decrypts the bytes, otherwise the raw ciphertext (a decoy is just opaque bytes). The\n// only thrown error is a transport failure.\n\nimport { loadDigClientWasm } from \"./loader.js\";\nimport type { DigClientWasm } from \"./wasm.js\";\nimport { parseUrn } from \"./urn.js\";\nimport type { ReadOptions, ReadResult, UrnKeys } from \"./types.js\";\n\n/** The default public dig RPC endpoint. */\nexport const DEFAULT_RPC = \"https://rpc.dig.net\";\n\n// The backend caps each dig.getContent chunk at 3 MiB (Lambda/APIGW response ceiling); the client\n// loops chunks until `complete`.\nconst RPC_CHUNK_BYTES = 3 * 1024 * 1024;\n\n/** Options to construct a DigClient. */\nexport interface DigClientOptions {\n /** dig RPC endpoint. Defaults to the public `https://rpc.dig.net`. */\n rpc?: string;\n /** Override `fetch` (e.g. an instrumented one). Defaults to the global `fetch`. */\n fetch?: typeof fetch;\n}\n\ninterface GetContentResult {\n total_length: number;\n offset: number;\n next_offset?: number | null;\n complete?: boolean;\n ciphertext?: string;\n inclusion_proof?: string;\n chunk_lens?: number[];\n}\n\n/** Decode a standard-base64 string (the RPC ciphertext encoding) to bytes — no DOM dependency. */\nfunction b64ToBytes(b64: string): Uint8Array {\n // atob exists in browsers and modern Node; fall back to Buffer in older Node.\n if (typeof atob === \"function\") {\n const bin = atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return new Uint8Array((globalThis as any).Buffer.from(b64, \"base64\"));\n}\n\n/**\n * The read-crypto client. Construct once and reuse — the wasm is loaded + SRI-verified lazily on\n * the first read and memoized process/page-wide.\n *\n * @example\n * const dig = new DigClient();\n * const { bytes, decrypted } = await dig.read({\n * urn: \"urn:dig:chia:<storeId>/index.html\",\n * root: \"<onchain-root-hex>\",\n * });\n * if (decrypted) console.log(new TextDecoder().decode(bytes));\n */\nexport class DigClient {\n private readonly rpc: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: DigClientOptions = {}) {\n this.rpc = options.rpc ?? DEFAULT_RPC;\n this.fetchImpl =\n options.fetch ??\n (typeof fetch === \"function\" ? fetch.bind(globalThis) : undefinedFetch());\n }\n\n /** Load (and SRI-verify) the read-crypto wasm. Exposed for callers that want the raw functions. */\n async wasm(): Promise<DigClientWasm> {\n return loadDigClientWasm();\n }\n\n /** `retrieval_key = SHA-256(canonical rootless URN)`, lowercase hex. */\n async retrievalKey(storeId: string, resourceKey: string): Promise<string> {\n return (await this.wasm()).retrievalKey(storeId, resourceKey);\n }\n\n /** Derive the per-URN AES-256-GCM-SIV key, lowercase hex. `salt` for a private store. */\n async deriveKey(\n storeId: string,\n resourceKey: string,\n salt?: string | null,\n ): Promise<string> {\n return (await this.wasm()).deriveKey(storeId, resourceKey, salt ?? undefined);\n }\n\n /** Verify served `ciphertext` is included under `root` via the base64 merkle `proof`. */\n async verifyInclusion(\n ciphertext: Uint8Array,\n proof: string,\n root: string,\n ): Promise<boolean> {\n return (await this.wasm()).verifyInclusion(ciphertext, proof, root);\n }\n\n /** Reconstruct the canonical rootless URN whose SHA-256 is the retrieval key. */\n async reconstructUrn(storeId: string, resourceKey: string): Promise<string> {\n return (await this.wasm()).reconstructUrn(storeId, resourceKey);\n }\n\n /**\n * Derive, client-side, the two root-independent keys a URN maps to (retrieval + decryption).\n * Nothing is sent to the network — pure local derivation via the wasm.\n */\n async deriveUrnKeys(input: { urn: string; salt?: string | null }): Promise<UrnKeys> {\n const parsed = parseUrn(input.urn);\n const wasm = await this.wasm();\n const effSalt = input.salt ?? parsed.salt ?? undefined;\n return {\n storeId: parsed.storeId,\n root: parsed.root,\n resourceKey: parsed.resourceKey,\n salt: effSalt ?? null,\n retrievalKey: wasm.retrievalKey(parsed.storeId, parsed.resourceKey),\n decryptionKey: wasm.deriveKey(parsed.storeId, parsed.resourceKey, effSalt),\n };\n }\n\n /**\n * Fetch + verify + decrypt one resource by URN. `root` is the on-chain generation root to verify\n * against (resolved by the caller from the chain); when omitted, the root embedded in the URN is\n * used. Returns the bytes plus advisory `verified`/`decrypted` flags. NEVER throws \"not found\"\n * (presence is unknowable) — it throws only on a transport failure.\n */\n async read(\n input: { urn: string; root?: string | null; salt?: string | null },\n opts: ReadOptions = {},\n ): Promise<ReadResult> {\n const parsed = parseUrn(input.urn);\n const effSalt = input.salt ?? parsed.salt ?? null;\n const effRoot = input.root ?? parsed.root ?? null;\n if (!effRoot) {\n throw new Error(\n \"a confirmed on-chain root is required to read content (pass { root } or use a root-pinned URN)\",\n );\n }\n return this.readResource(\n { storeId: parsed.storeId, resourceKey: parsed.resourceKey, root: effRoot, salt: effSalt },\n opts,\n );\n }\n\n /** As `read`, but decoding the plaintext to a UTF-8 string when it decrypts (else throws). */\n async readText(\n input: { urn: string; root?: string | null; salt?: string | null },\n opts: ReadOptions = {},\n ): Promise<string> {\n const r = await this.read(input, opts);\n if (!r.decrypted) {\n throw new Error(\n \"resource did not decrypt under this URN — wrong store/key/salt, or a decoy response\",\n );\n }\n return new TextDecoder().decode(r.bytes);\n }\n\n /**\n * Read by explicit (storeId, resourceKey, root, salt) rather than a URN string. The oblivious\n * download primitive the URN read is built on.\n */\n async readResource(\n input: { storeId: string; resourceKey: string; root: string; salt?: string | null },\n opts: ReadOptions = {},\n ): Promise<ReadResult> {\n const rpc = opts.rpc ?? this.rpc;\n const wasm = await this.wasm();\n const rk = wasm.retrievalKey(input.storeId, input.resourceKey);\n const { ciphertext, proof, chunkLens } = await this.fetchCiphertext(\n input.storeId,\n rk,\n input.root,\n rpc,\n );\n let verified = false;\n try {\n verified = !!wasm.verifyInclusion(ciphertext, proof, input.root);\n } catch {\n verified = false;\n }\n const keyHex = wasm.deriveKey(input.storeId, input.resourceKey, input.salt ?? undefined);\n try {\n const bytes = decryptResourceChunks(wasm, keyHex, ciphertext, chunkLens);\n return {\n storeId: input.storeId,\n root: input.root,\n resourceKey: input.resourceKey,\n salt: input.salt ?? null,\n bytes,\n verified,\n decrypted: true,\n };\n } catch {\n // Not decryptable with this URN/salt — hand back the raw bytes; never a \"not present\" verdict.\n return {\n storeId: input.storeId,\n root: input.root,\n resourceKey: input.resourceKey,\n salt: input.salt ?? null,\n bytes: ciphertext,\n verified,\n decrypted: false,\n };\n }\n }\n\n // Stream the FULL ciphertext for a resource from the RPC by retrieval key, reassembling 3-MiB\n // chunks. A null result is a TRANSPORT failure, never a presence judgment.\n private async fetchCiphertext(\n storeId: string,\n rk: string,\n root: string,\n rpc: string,\n ): Promise<{ ciphertext: Uint8Array; proof: string; chunkLens: number[] | null }> {\n let offset = 0;\n let total: number | null = null;\n let buf: Uint8Array | null = null;\n let proof = \"\";\n let chunkLens: number[] | null = null;\n for (;;) {\n const r = await this.rpcCall<GetContentResult>(rpc, \"dig.getContent\", {\n store_id: storeId,\n root,\n retrieval_key: rk,\n offset,\n length: RPC_CHUNK_BYTES,\n });\n if (!r) throw new Error(\"The content network returned no data for this request.\");\n if (total === null) {\n total = r.total_length >>> 0;\n buf = new Uint8Array(total);\n }\n if (chunkLens === null && Array.isArray(r.chunk_lens)) {\n chunkLens = r.chunk_lens.map((n) => n >>> 0);\n }\n const chunk = b64ToBytes(r.ciphertext ?? \"\");\n const at = r.offset >>> 0;\n buf!.set(chunk.subarray(0, Math.max(0, Math.min(chunk.length, total - at))), at);\n if (r.inclusion_proof) proof = r.inclusion_proof;\n if (r.complete || r.next_offset == null) break;\n offset = r.next_offset >>> 0;\n }\n return { ciphertext: buf ?? new Uint8Array(0), proof, chunkLens };\n }\n\n // One JSON-RPC 2.0 call. Throws on transport failure or a JSON-RPC error; returns `result`.\n private async rpcCall<T>(rpc: string, method: string, params: unknown): Promise<T | null> {\n let res: Response;\n try {\n res = await this.fetchImpl(rpc, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ jsonrpc: \"2.0\", id: 1, method, params }),\n });\n } catch {\n throw new Error(\"Could not reach the content network. Check your connection and try again.\");\n }\n if (!res.ok) throw new Error(`dig RPC ${method} failed (${res.status})`);\n const json = (await res.json()) as { result?: T; error?: { message?: string } };\n if (json && json.error) throw new Error(`dig RPC ${method}: ${json.error.message ?? \"error\"}`);\n return json ? (json.result ?? null) : null;\n }\n}\n\n// AES-256-GCM-SIV-open a resource's served ciphertext under `keyHex`, splitting the PLAIN-\n// concatenated chunk ciphertexts by `chunkLens` (per-chunk CIPHERTEXT byte lengths) and opening\n// each. Empty/absent chunkLens ⇒ single-chunk resource. Throws if any chunk's tag fails.\nfunction decryptResourceChunks(\n wasm: DigClientWasm,\n keyHex: string,\n ciphertext: Uint8Array,\n chunkLens: number[] | null,\n): Uint8Array {\n const lens = chunkLens && chunkLens.length ? chunkLens : [ciphertext.length];\n const total = lens.reduce((a, n) => a + n, 0);\n if (total !== ciphertext.length) {\n throw new Error(\"served ciphertext length does not match chunk lengths\");\n }\n if (lens.length === 1) return wasm.decryptChunk(keyHex, ciphertext);\n const parts: Uint8Array[] = [];\n let p = 0;\n for (const len of lens) {\n parts.push(wasm.decryptChunk(keyHex, ciphertext.subarray(p, p + len)));\n p += len;\n }\n const out = new Uint8Array(parts.reduce((a, x) => a + x.length, 0));\n let q = 0;\n for (const part of parts) {\n out.set(part, q);\n q += part.length;\n }\n return out;\n}\n\nfunction undefinedFetch(): typeof fetch {\n return (() => {\n throw new Error(\n \"No global fetch available. Pass { fetch } to DigClient (Node < 18 needs a fetch polyfill).\",\n );\n }) as unknown as typeof fetch;\n}\n"]}