@dignetwork/dig-sdk 0.2.0 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -7
- package/dist/adapters.cjs.map +1 -1
- package/dist/adapters.js.map +1 -1
- package/dist/{dig-client-entry-ChYxUvBn.d.cts → dig-client-entry-Deb8ZwaO.d.cts} +10 -6
- package/dist/{dig-client-entry-ChYxUvBn.d.ts → dig-client-entry-Deb8ZwaO.d.ts} +10 -6
- package/dist/dig-client.cjs +38 -31
- package/dist/dig-client.cjs.map +1 -1
- package/dist/dig-client.d.cts +1 -1
- package/dist/dig-client.d.ts +1 -1
- package/dist/dig-client.js +38 -31
- package/dist/dig-client.js.map +1 -1
- package/dist/index.cjs +72 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -9
- package/dist/index.d.ts +58 -9
- package/dist/index.js +72 -36
- package/dist/index.js.map +1 -1
- package/dist/next.cjs.map +1 -1
- package/dist/next.js.map +1 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js.map +1 -1
- package/package.json +6 -7
- package/vendor/PROVENANCE.md +0 -102
- package/vendor/dig_client.d.ts +0 -150
- package/vendor/dig_client.mjs +0 -805
- package/vendor/dig_client_bg.wasm +0 -0
package/vendor/PROVENANCE.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# Vendored artifacts — provenance
|
|
2
|
-
|
|
3
|
-
These files are vendored copies of the DIG **read-crypto** WASM (`dig_client`) and its
|
|
4
|
-
wasm-bindgen ES-module glue. They are **byte-identical** to the artifacts shipped by the rest of
|
|
5
|
-
the DIG ecosystem — the `dig-chrome-extension`, the `dig-companion`, and `hub.dig.net` all run the
|
|
6
|
-
**same** `dig_client` WASM, which is built from `chip35_dl_coin`'s `dig-client-wasm` crate.
|
|
7
|
-
|
|
8
|
-
Vendoring them lets the SDK run the **same** verify + decrypt read path those clients use, in
|
|
9
|
-
either the browser or Node, with no network round-trip for the crypto.
|
|
10
|
-
|
|
11
|
-
| File | Source (in the dig_ecosystem monorepo) | Notes |
|
|
12
|
-
|---|---|---|
|
|
13
|
-
| `dig_client.mjs` | `modules/dig-companion/node/src/vendor/dig_client.mjs` (← `dig-chrome-extension/dig_client.js`) | wasm-bindgen ES-module glue. Copied verbatim, `.mjs` so Node loads it as an ES module. No code changes. |
|
|
14
|
-
| `dig_client_bg.wasm` | `modules/dig-companion/node/src/vendor/dig_client_bg.wasm` (← `dig-chrome-extension/dig_client_bg.wasm`) | The read-crypto WASM binary. Copied verbatim. |
|
|
15
|
-
| `dig_client.d.ts` | `modules/hub.dig.net/apps/web/public/dig-client/dig_client.d.ts` | The WASM's TypeScript surface. Copied verbatim. |
|
|
16
|
-
|
|
17
|
-
## Subresource Integrity (SRI)
|
|
18
|
-
|
|
19
|
-
`dig_client_bg.wasm` SHA-256 (lowercase hex):
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
ff486be806f908a2a90780e499a04dbd34e10e3b97be0470cb9ee841a1e49e77
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
This is the **same digest** asserted by:
|
|
26
|
-
|
|
27
|
-
- `dig-chrome-extension/background.js` → `DIG_CLIENT_WASM_SHA256`
|
|
28
|
-
- `hub.dig.net` `sw.js` and `apps/web/lib/dig-client.js`
|
|
29
|
-
- `dig-companion` `node/src/dig-client.js`
|
|
30
|
-
|
|
31
|
-
The SDK's loader (`src/loader.ts` → `DIG_CLIENT_WASM_SHA256`) re-verifies this digest at load time
|
|
32
|
-
and **fails closed** if it does not match — a tampered or wrong WASM refuses to run unverified
|
|
33
|
-
crypto, exactly as the extension/companion/hub do.
|
|
34
|
-
|
|
35
|
-
## Why vendor instead of depend on `@dignetwork/chip35-dl-coin-wasm`?
|
|
36
|
-
|
|
37
|
-
The published `@dignetwork/chip35-dl-coin-wasm` package exposes **only the CHIP-0035 spend
|
|
38
|
-
builder** (mintStore, meltStore, updateStoreMetadata, …) — it does **not** export the read-crypto
|
|
39
|
-
(retrievalKey / deriveKey / verifyInclusion / decryptChunk). The read-crypto is a **separate**
|
|
40
|
-
wasm artifact (`dig_client`) built from the same repo. So the SDK:
|
|
41
|
-
|
|
42
|
-
- **depends on** `@dignetwork/chip35-dl-coin-wasm` for spends (re-exported via `@dignetwork/dig-sdk/spend`), and
|
|
43
|
-
- **vendors** the `dig_client` read-crypto WASM here (SRI-pinned) for `DigClient`.
|
|
44
|
-
|
|
45
|
-
## Updating
|
|
46
|
-
|
|
47
|
-
If the canonical `dig_client` WASM changes (a new `chip35_dl_coin` release → extension/companion
|
|
48
|
-
bump), re-copy `dig_client.mjs` + `dig_client_bg.wasm` (+ `dig_client.d.ts`) from the ecosystem,
|
|
49
|
-
recompute the SHA-256 of `dig_client_bg.wasm`, and update the `DIG_CLIENT_WASM_SHA256` constant in
|
|
50
|
-
`src/loader.ts` **and** the digest above. Keep this digest in lock-step with the
|
|
51
|
-
extension/companion/hub.
|
|
52
|
-
|
|
53
|
-
## Publishing the read-crypto wasm — `@dignetwork/dig-client` (roadmap #16)
|
|
54
|
-
|
|
55
|
-
The read-crypto wasm is currently **vendored** in *every* consumer (this SDK under `vendor/`, plus
|
|
56
|
-
`dig-chrome-extension`, `dig-companion`, and `hub.dig.net`). Each hand-copies the same
|
|
57
|
-
`dig_client_bg.wasm` + glue + `.d.ts` and re-asserts the same SHA-256. That is brittle: a wasm bump
|
|
58
|
-
means re-copying into four+ repos and hoping the digests stay aligned.
|
|
59
|
-
|
|
60
|
-
**The fix (#16): publish the wasm once as `@dignetwork/dig-client`, so nobody vendors it again.**
|
|
61
|
-
|
|
62
|
-
### What dig-sdk ships TODAY (the immediate win — no cross-repo dependency)
|
|
63
|
-
|
|
64
|
-
`@dignetwork/dig-sdk/dig-client` (built from `src/dig-client-entry.ts`) is the clean, publishable
|
|
65
|
-
read-crypto subpath: `DigClient`, the SRI-pinned `loadDigClientWasm`/`configureWasm`,
|
|
66
|
-
`DIG_CLIENT_WASM_SHA256`, and the pure URN helpers, all with `.d.ts`. It runs over the wasm vendored
|
|
67
|
-
here. **The hub and `dig-embed.js` can already depend on `@dignetwork/dig-sdk/dig-client` instead of
|
|
68
|
-
hand-copying the wasm** — that removes most of the duplication now, with the digest enforced in one
|
|
69
|
-
place (`src/loader.ts`).
|
|
70
|
-
|
|
71
|
-
### What must be published in the CANONICAL repo (the cross-repo step — `chip35_dl_coin`)
|
|
72
|
-
|
|
73
|
-
The wasm is built from `chip35_dl_coin`'s `dig-client-wasm` crate. To stop vendoring entirely, that
|
|
74
|
-
repo must publish an npm package (proposed name `@dignetwork/dig-client`) containing:
|
|
75
|
-
|
|
76
|
-
1. `dig_client_bg.wasm` — the read-crypto binary (the artifact this `vendor/` copies verbatim).
|
|
77
|
-
2. `dig_client.mjs` — the wasm-bindgen ES-module glue.
|
|
78
|
-
3. `dig_client.d.ts` — the TypeScript surface.
|
|
79
|
-
4. A package `exports` map so web + Node both resolve the wasm + glue, and an integrity note
|
|
80
|
-
(the SHA-256) so consumers can SRI-pin it — the **same** digest pinned here.
|
|
81
|
-
|
|
82
|
-
**Versioning story:** the npm package version tracks the `dig-client-wasm` crate version; each
|
|
83
|
-
release records the wasm SHA-256 in its README/CHANGELOG. The digest — not the npm semver — remains
|
|
84
|
-
the canonical trust anchor: consumers pin and verify the SHA-256 regardless of the package version,
|
|
85
|
-
so a wrong/tampered artifact fails closed even if the version "looks right".
|
|
86
|
-
|
|
87
|
-
### Wiring dig-sdk to the published package (when it exists) — without breaking the fallback
|
|
88
|
-
|
|
89
|
-
Once `@dignetwork/dig-client` is published, the ONLY change in dig-sdk is in **`src/loader.ts`**:
|
|
90
|
-
resolve the glue + wasm bytes from the published package (e.g. `import.meta.resolve`/a dep import)
|
|
91
|
-
*before* falling back to the bytes under `vendor/`. The SRI check (`DIG_CLIENT_WASM_SHA256`) is
|
|
92
|
-
unchanged and still gates both paths, so:
|
|
93
|
-
|
|
94
|
-
- the **public surface of `@dignetwork/dig-sdk/dig-client` does not change** — consumers are
|
|
95
|
-
unaffected;
|
|
96
|
-
- the **vendored fallback stays intact** — if the dependency is absent (or its bytes don't match the
|
|
97
|
-
pinned digest), the loader uses `vendor/` exactly as today.
|
|
98
|
-
|
|
99
|
-
> **TODO (#16, cross-repo):** publish `@dignetwork/dig-client` from `chip35_dl_coin`'s
|
|
100
|
-
> `dig-client-wasm` crate (items 1–4 above), then update `src/loader.ts` to prefer it with the
|
|
101
|
-
> `vendor/` fallback, keeping `DIG_CLIENT_WASM_SHA256` in lock-step. Until then, the vendored path
|
|
102
|
-
> is the source of truth and `@dignetwork/dig-sdk/dig-client` is the consumable entry.
|
package/vendor/dig_client.d.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Decrypt a SINGLE GCM-SIV chunk under an explicit 32-byte `key` (hex). Returns
|
|
6
|
-
* the plaintext bytes. A failed tag check (tamper / wrong key) is an error.
|
|
7
|
-
* Low-level escape hatch; most callers want `decryptResource`.
|
|
8
|
-
*/
|
|
9
|
-
export function decryptChunk(key_hex: string, ciphertext: Uint8Array): Uint8Array;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Full read pipeline for a resource's served ciphertext (Digstore §9.3 + §11),
|
|
13
|
-
* returning the decrypted plaintext bytes. Steps, in order (gate-then-decrypt):
|
|
14
|
-
*
|
|
15
|
-
* 1. **Integrity gate** — verify the served bytes' merkle inclusion against the
|
|
16
|
-
* chain-anchored `trusted_root_hex` (proof base64 from `X-Dig-Inclusion-Proof`).
|
|
17
|
-
* 2. **Confidentiality** — derive the URN key, split the PLAIN-concatenated
|
|
18
|
-
* chunk ciphertexts by `chunk_lens` (the per-chunk CIPHERTEXT byte lengths in
|
|
19
|
-
* order; D5/C9 — NO length framing on the wire), and AES-256-GCM-SIV-open
|
|
20
|
-
* each, concatenating plaintext in order.
|
|
21
|
-
*
|
|
22
|
-
* `chunk_lens` may be empty for the common single-chunk resource (the whole blob
|
|
23
|
-
* is one GCM-SIV ciphertext). They MUST sum to `ciphertext.len()`.
|
|
24
|
-
*/
|
|
25
|
-
export function decryptResource(store_id_hex: string, resource_key: string, ciphertext: Uint8Array, proof_b64: string, trusted_root_hex: string, salt_hex?: string | null, chunk_lens?: Uint32Array | null): Uint8Array;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Convenience wrapper around [`decrypt_resource`] returning the plaintext as a
|
|
29
|
-
* UTF-8 string (for HTML/text resources rendered into the sandbox iframe).
|
|
30
|
-
*/
|
|
31
|
-
export function decryptResourceToText(store_id_hex: string, resource_key: string, ciphertext: Uint8Array, proof_b64: string, trusted_root_hex: string, salt_hex?: string | null, chunk_lens?: Uint32Array | null): string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Derive the 32-byte AES-256 content key for a resource (Digstore §11.1/§11.4),
|
|
35
|
-
* returned as lowercase hex. `salt_hex` is the 32-byte private-store secret salt
|
|
36
|
-
* (omit / pass `null` for public stores). Mixing in a wrong/missing salt yields
|
|
37
|
-
* a wrong key whose GCM-SIV tag will not verify.
|
|
38
|
-
*/
|
|
39
|
-
export function deriveKey(store_id_hex: string, resource_key: string, salt_hex?: string | null): string;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Seal a resource's plaintext as ONE AES-256-GCM-SIV blob under its per-URN key — the inverse of
|
|
43
|
-
* the read path's chunk decrypt. The browser uses this to PRE-ENCRYPT a file before upload so the
|
|
44
|
-
* server compiles the `.dig` from ciphertext alone (it never sees plaintext or any key). The
|
|
45
|
-
* output is the resource's whole-file ciphertext; `digstore compile --pre-encrypted` stores it
|
|
46
|
-
* verbatim as the single chunk, and `decryptResource`/`decryptChunk` under the same URN reverses
|
|
47
|
-
* it. `salt_hex` is the store's secret salt for a private store (omit for a public store).
|
|
48
|
-
*/
|
|
49
|
-
export function encryptResource(store_id_hex: string, resource_key: string, plaintext: Uint8Array, salt_hex?: string | null): Uint8Array;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* On module load, install a `globalThis.digClient` object exposing the read
|
|
53
|
-
* API, so non-bundler consumers (the standalone usercontent loader) can call
|
|
54
|
-
* `globalThis.digClient.verifyInclusion(...)` / `.decryptResourceToText(...)`
|
|
55
|
-
* after the wasm initializes. ES-module consumers can instead import the named
|
|
56
|
-
* functions directly. Idempotent and best-effort (no-op if `globalThis` lacks
|
|
57
|
-
* `Object`, e.g. in a non-browser host).
|
|
58
|
-
*/
|
|
59
|
-
export function install_global(): void;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Reconstruct the canonical ROOT-INDEPENDENT resource URN string for a store +
|
|
63
|
-
* resource key: `urn:dig:chia:<store_id>[/<resource_key>]`. An empty resource
|
|
64
|
-
* key resolves to the §8.5 default view `index.html`. This is the form whose
|
|
65
|
-
* SHA-256 is the retrieval key and whose bytes seed the AES key.
|
|
66
|
-
*/
|
|
67
|
-
export function reconstructUrn(store_id_hex: string, resource_key: string): string;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Reconstruct a ROOT-PINNED display URN: `urn:dig:chia:<store_id>:<root>/<key>`.
|
|
71
|
-
* Useful for sharing a URN bound to a specific generation; the retrieval/AES
|
|
72
|
-
* keys still use the rootless form (`reconstructUrn`).
|
|
73
|
-
*/
|
|
74
|
-
export function reconstructUrnWithRoot(store_id_hex: string, root_hex: string, resource_key: string): string;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* `retrieval_key = SHA-256(canonical_rootless_urn)`, lowercase hex (Digstore
|
|
78
|
-
* §7.3; API §17). The CDN is addressed by this hash; the URN itself is never
|
|
79
|
-
* sent. An empty resource key resolves to `index.html`.
|
|
80
|
-
*/
|
|
81
|
-
export function retrievalKey(store_id_hex: string, resource_key: string): string;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Verify that `ciphertext` is included under `trusted_root_hex` via the base64
|
|
85
|
-
* merkle `proof_b64` (Digstore §9.3; API §18). Returns `true` on success and
|
|
86
|
-
* `false` on ANY verification failure (tampered bytes, non-chaining path, or a
|
|
87
|
-
* root mismatch / decoy) — a decoy or wrong-store response returns `false`
|
|
88
|
-
* rather than throwing, so a caller can treat it as "not found in this store".
|
|
89
|
-
* Throws only on malformed inputs (bad base64 / hex / proof encoding).
|
|
90
|
-
*/
|
|
91
|
-
export function verifyInclusion(ciphertext: Uint8Array, proof_b64: string, trusted_root_hex: string): boolean;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Library version (matches the crate version), for SRI / compatibility checks.
|
|
95
|
-
*/
|
|
96
|
-
export function version(): string;
|
|
97
|
-
|
|
98
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
99
|
-
|
|
100
|
-
export interface InitOutput {
|
|
101
|
-
readonly memory: WebAssembly.Memory;
|
|
102
|
-
readonly decryptChunk: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
103
|
-
readonly decryptResource: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number) => [number, number, number, number];
|
|
104
|
-
readonly decryptResourceToText: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number) => [number, number, number, number];
|
|
105
|
-
readonly deriveKey: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
106
|
-
readonly encryptResource: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
|
|
107
|
-
readonly install_global: () => void;
|
|
108
|
-
readonly reconstructUrn: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
109
|
-
readonly reconstructUrnWithRoot: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
110
|
-
readonly retrievalKey: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
111
|
-
readonly verifyInclusion: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
112
|
-
readonly version: () => [number, number];
|
|
113
|
-
readonly wasm_bindgen__convert__closures_____invoke__hc605e6b36f32dd24: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => [number, number, number, number];
|
|
114
|
-
readonly wasm_bindgen__convert__closures_____invoke__h58cab831a65fd6c8: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => [number, number, number, number];
|
|
115
|
-
readonly wasm_bindgen__convert__closures_____invoke__h68a3f7e1b7047a46: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
|
|
116
|
-
readonly wasm_bindgen__convert__closures_____invoke__h36771739d8dc18ae: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
|
|
117
|
-
readonly wasm_bindgen__convert__closures_____invoke__hd4233470ad4ef59f: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
118
|
-
readonly wasm_bindgen__convert__closures_____invoke__h61ffc6ac64470c43: (a: number, b: number) => [number, number];
|
|
119
|
-
readonly __wbindgen_exn_store: (a: number) => void;
|
|
120
|
-
readonly __externref_table_alloc: () => number;
|
|
121
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
122
|
-
readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
|
|
123
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
124
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
125
|
-
readonly __externref_table_dealloc: (a: number) => void;
|
|
126
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
127
|
-
readonly __wbindgen_start: () => void;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
134
|
-
* a precompiled `WebAssembly.Module`.
|
|
135
|
-
*
|
|
136
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
137
|
-
*
|
|
138
|
-
* @returns {InitOutput}
|
|
139
|
-
*/
|
|
140
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
144
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
145
|
-
*
|
|
146
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
147
|
-
*
|
|
148
|
-
* @returns {Promise<InitOutput>}
|
|
149
|
-
*/
|
|
150
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|