@needmoretruth/nmts-cli 0.17.2
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/AGENTS.md +591 -0
- package/LICENSE +202 -0
- package/LICENSING.md +49 -0
- package/README.ko.md +641 -0
- package/README.md +657 -0
- package/dist/account-proof.js +78 -0
- package/dist/account.js +75 -0
- package/dist/api-key.js +310 -0
- package/dist/api.js +271 -0
- package/dist/args.js +137 -0
- package/dist/artifact-about.js +70 -0
- package/dist/autonomy.js +98 -0
- package/dist/code-access.js +76 -0
- package/dist/code-vault.js +233 -0
- package/dist/collision.js +133 -0
- package/dist/commands/balance.js +93 -0
- package/dist/commands/consent.js +77 -0
- package/dist/commands/create.js +356 -0
- package/dist/commands/env.js +136 -0
- package/dist/commands/expiring.js +167 -0
- package/dist/commands/extend.js +236 -0
- package/dist/commands/get.js +130 -0
- package/dist/commands/kit.js +136 -0
- package/dist/commands/listfile.js +105 -0
- package/dist/commands/login.js +335 -0
- package/dist/commands/logout.js +33 -0
- package/dist/commands/ls.js +202 -0
- package/dist/commands/marks.js +176 -0
- package/dist/commands/mcp.js +139 -0
- package/dist/commands/mode.js +54 -0
- package/dist/commands/on-collision.js +45 -0
- package/dist/commands/organise.js +296 -0
- package/dist/commands/public-code.js +89 -0
- package/dist/commands/pull.js +185 -0
- package/dist/commands/push.js +278 -0
- package/dist/commands/put.js +282 -0
- package/dist/commands/rebuild.js +160 -0
- package/dist/commands/receive.js +125 -0
- package/dist/commands/recovery-list.js +104 -0
- package/dist/commands/recovery.js +291 -0
- package/dist/commands/s3.js +241 -0
- package/dist/commands/settings.js +28 -0
- package/dist/commands/share.js +276 -0
- package/dist/commands/sweep.js +240 -0
- package/dist/commands/trash.js +288 -0
- package/dist/commands/trial.js +264 -0
- package/dist/commands/update.js +169 -0
- package/dist/commands/usage.js +84 -0
- package/dist/commands/verify.js +331 -0
- package/dist/commands/wallet.js +122 -0
- package/dist/commands/whoami.js +33 -0
- package/dist/consent.js +200 -0
- package/dist/credentials.js +311 -0
- package/dist/crypto-surface.js +54 -0
- package/dist/crypto.js +137 -0
- package/dist/download-part.js +144 -0
- package/dist/download-sink.js +213 -0
- package/dist/download.js +163 -0
- package/dist/drive-paths.js +170 -0
- package/dist/environment.js +190 -0
- package/dist/errors.js +71 -0
- package/dist/exit.js +107 -0
- package/dist/expiry.js +115 -0
- package/dist/extend-chain.js +137 -0
- package/dist/extend-plan.js +149 -0
- package/dist/extend-sign.js +130 -0
- package/dist/guards.js +15 -0
- package/dist/help.js +192 -0
- package/dist/human-check.js +54 -0
- package/dist/item-trash.js +25 -0
- package/dist/kit-file.js +133 -0
- package/dist/list-file.js +71 -0
- package/dist/list-view-find.js +71 -0
- package/dist/list-view-order.js +96 -0
- package/dist/main.js +394 -0
- package/dist/manifest-create.js +81 -0
- package/dist/manifest-write.js +244 -0
- package/dist/manifest.js +213 -0
- package/dist/mark-render.js +45 -0
- package/dist/mcp-args.js +154 -0
- package/dist/mcp-tools/context.js +50 -0
- package/dist/mcp-tools/files.js +133 -0
- package/dist/mcp-tools/organise.js +128 -0
- package/dist/mcp-tools/reads.js +89 -0
- package/dist/mcp-tools/share.js +61 -0
- package/dist/mcp.js +142 -0
- package/dist/net-retry.js +84 -0
- package/dist/network.js +43 -0
- package/dist/notice.js +45 -0
- package/dist/product.js +38 -0
- package/dist/progress.js +110 -0
- package/dist/prompt.js +145 -0
- package/dist/rebuild.js +255 -0
- package/dist/recovery-assemble.js +148 -0
- package/dist/recovery-build.js +260 -0
- package/dist/recovery-map-file.js +114 -0
- package/dist/recovery-map.js +191 -0
- package/dist/recovery-release.js +229 -0
- package/dist/recovery-seq.js +63 -0
- package/dist/recovery-source.js +143 -0
- package/dist/registration.js +83 -0
- package/dist/s3/listing.js +134 -0
- package/dist/s3/multipart.js +104 -0
- package/dist/s3/response-sink.js +41 -0
- package/dist/s3/same-file.js +117 -0
- package/dist/s3/server.js +252 -0
- package/dist/s3/sigv4.js +168 -0
- package/dist/s3/staging.js +87 -0
- package/dist/s3/xml.js +80 -0
- package/dist/safe-path.js +89 -0
- package/dist/seal.js +206 -0
- package/dist/secret-reader.js +112 -0
- package/dist/server.js +33 -0
- package/dist/session.js +49 -0
- package/dist/setup-questions.js +31 -0
- package/dist/share.js +195 -0
- package/dist/shared/lib/crypto/size-padding.js +126 -0
- package/dist/shared/lib/drive/manifest-codec.js +287 -0
- package/dist/shared/lib/drive/manifest-index.js +235 -0
- package/dist/shared/lib/drive/manifest-ops.js +267 -0
- package/dist/shared/lib/drive/manifest-settings.js +65 -0
- package/dist/shared/lib/drive/name-conflict.js +121 -0
- package/dist/shared/lib/drive/unique-name.js +48 -0
- package/dist/shared/lib/extend/epochs.js +256 -0
- package/dist/shared/lib/net/retry-budget.js +95 -0
- package/dist/shared/lib/share/shared-file-info.js +65 -0
- package/dist/shared/lib/storage-network.js +64 -0
- package/dist/shared/lib/upload/part-plan.js +28 -0
- package/dist/stdout.js +109 -0
- package/dist/trash-sweep.js +123 -0
- package/dist/units.js +19 -0
- package/dist/update-check.js +164 -0
- package/dist/update-source.js +143 -0
- package/dist/upload-api.js +98 -0
- package/dist/upload-file.js +242 -0
- package/dist/upload-price.js +117 -0
- package/dist/upload-steps.js +111 -0
- package/dist/upload-store.js +252 -0
- package/dist/upload-wire.js +25 -0
- package/dist/upload.js +294 -0
- package/dist/usage-report.js +54 -0
- package/dist/wallet-chain.js +76 -0
- package/dist/wallet.js +209 -0
- package/dist/walrus-write.js +188 -0
- package/dist/walrus.js +156 -0
- package/package.json +56 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +469 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +1300 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +55 -0
- package/vendor/nmts-crypto/package.json +17 -0
|
@@ -0,0 +1,1300 @@
|
|
|
1
|
+
/* @ts-self-types="./nmts_crypto_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Incremental SHA-256 over a file's PLAINTEXT, for the content-hash envelope
|
|
5
|
+
* (`docs/CRYPTO-FORMAT-NCF3.md` §3).
|
|
6
|
+
*
|
|
7
|
+
* WHY STREAMING: the one-shot `sha256` needs the whole file in memory at once. Uploads run
|
|
8
|
+
* to many gigabytes and parts may be encrypted concurrently, so the hash is accumulated by
|
|
9
|
+
* a separate sequential pass that never holds more than one slice. `update()` in order,
|
|
10
|
+
* then `finalize()` exactly once. Call `free()` afterwards to release the wasm-side memory.
|
|
11
|
+
*
|
|
12
|
+
* Not key material: the digest is of plaintext the caller already holds. It is the SEALED
|
|
13
|
+
* form (see `wrap::seal_content_hash`) that ever reaches the server.
|
|
14
|
+
*/
|
|
15
|
+
export class Sha256Hasher {
|
|
16
|
+
__destroy_into_raw() {
|
|
17
|
+
const ptr = this.__wbg_ptr;
|
|
18
|
+
this.__wbg_ptr = 0;
|
|
19
|
+
Sha256HasherFinalization.unregister(this);
|
|
20
|
+
return ptr;
|
|
21
|
+
}
|
|
22
|
+
free() {
|
|
23
|
+
const ptr = this.__destroy_into_raw();
|
|
24
|
+
wasm.__wbg_sha256hasher_free(ptr, 0);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The 32-byte digest. Consumes the state — calling twice errors rather than returning
|
|
28
|
+
* the digest of a silently restarted hasher.
|
|
29
|
+
* @returns {Uint8Array}
|
|
30
|
+
*/
|
|
31
|
+
finalize() {
|
|
32
|
+
const ret = wasm.sha256hasher_finalize(this.__wbg_ptr);
|
|
33
|
+
if (ret[3]) {
|
|
34
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
35
|
+
}
|
|
36
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
37
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
38
|
+
return v1;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A fresh hasher with empty state.
|
|
42
|
+
*/
|
|
43
|
+
constructor() {
|
|
44
|
+
const ret = wasm.sha256hasher_new();
|
|
45
|
+
this.__wbg_ptr = ret;
|
|
46
|
+
Sha256HasherFinalization.register(this, this.__wbg_ptr, this);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Absorb the next plaintext slice, in order. Any slice size.
|
|
51
|
+
* @param {Uint8Array} data
|
|
52
|
+
*/
|
|
53
|
+
update(data) {
|
|
54
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
55
|
+
const len0 = WASM_VECTOR_LEN;
|
|
56
|
+
const ret = wasm.sha256hasher_update(this.__wbg_ptr, ptr0, len0);
|
|
57
|
+
if (ret[1]) {
|
|
58
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (Symbol.dispose) Sha256Hasher.prototype[Symbol.dispose] = Sha256Hasher.prototype.free;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Streaming sequential NCF-3 decryptor with full anti-truncation/reorder verification
|
|
66
|
+
* (the download path). Construct with the file DEK and the 72-byte stream header,
|
|
67
|
+
* `push()` ciphertext in arbitrary slice sizes — each call returns decrypted plaintext
|
|
68
|
+
* for any chunks that completed — then call `finish()` after the last byte: it enforces
|
|
69
|
+
* every end-of-stream invariant (all chunks consumed, final chunk flagged, decoded total
|
|
70
|
+
* equals `plaintext_len`, no trailing bytes). Call `free()` afterwards.
|
|
71
|
+
*/
|
|
72
|
+
export class StreamDecryptor {
|
|
73
|
+
__destroy_into_raw() {
|
|
74
|
+
const ptr = this.__wbg_ptr;
|
|
75
|
+
this.__wbg_ptr = 0;
|
|
76
|
+
StreamDecryptorFinalization.unregister(this);
|
|
77
|
+
return ptr;
|
|
78
|
+
}
|
|
79
|
+
free() {
|
|
80
|
+
const ptr = this.__destroy_into_raw();
|
|
81
|
+
wasm.__wbg_streamdecryptor_free(ptr, 0);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Verifies the stream ended cleanly (end-of-stream invariants above). Errors on an
|
|
85
|
+
* incomplete or oversized stream; idempotent after a successful call (mirrors Rust).
|
|
86
|
+
*/
|
|
87
|
+
finish() {
|
|
88
|
+
const ret = wasm.streamdecryptor_finish(this.__wbg_ptr);
|
|
89
|
+
if (ret[1]) {
|
|
90
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* `dek` must be 32 bytes; `header` the 72-byte NCF-3 stream header (parsed and
|
|
95
|
+
* validated here — bad magic/version/chunk size error immediately).
|
|
96
|
+
* @param {Uint8Array} dek
|
|
97
|
+
* @param {Uint8Array} header
|
|
98
|
+
*/
|
|
99
|
+
constructor(dek, header) {
|
|
100
|
+
const ptr0 = passArray8ToWasm0(dek, wasm.__wbindgen_malloc);
|
|
101
|
+
const len0 = WASM_VECTOR_LEN;
|
|
102
|
+
const ptr1 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
103
|
+
const len1 = WASM_VECTOR_LEN;
|
|
104
|
+
const ret = wasm.streamdecryptor_new(ptr0, len0, ptr1, len1);
|
|
105
|
+
if (ret[2]) {
|
|
106
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
107
|
+
}
|
|
108
|
+
this.__wbg_ptr = ret[0];
|
|
109
|
+
StreamDecryptorFinalization.register(this, this.__wbg_ptr, this);
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Feeds ciphertext in. Returns decrypted plaintext for any chunks that completed
|
|
114
|
+
* (possibly empty). Tampering, reordering, and truncation surface as errors here.
|
|
115
|
+
* @param {Uint8Array} data
|
|
116
|
+
* @returns {Uint8Array}
|
|
117
|
+
*/
|
|
118
|
+
push(data) {
|
|
119
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
120
|
+
const len0 = WASM_VECTOR_LEN;
|
|
121
|
+
const ret = wasm.streamdecryptor_push(this.__wbg_ptr, ptr0, len0);
|
|
122
|
+
if (ret[3]) {
|
|
123
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
124
|
+
}
|
|
125
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
126
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
127
|
+
return v2;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (Symbol.dispose) StreamDecryptor.prototype[Symbol.dispose] = StreamDecryptor.prototype.free;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Streaming NCF-3 encryptor (misuse-resistant by construction): the random
|
|
134
|
+
* `nonce_prefix` is generated INSIDE Rust and chunk indexes are managed internally, so a
|
|
135
|
+
* JS-side bug can never cause nonce reuse or out-of-order sealing.
|
|
136
|
+
*
|
|
137
|
+
* Protocol (CRYPTO-FORMAT §3): construct with the file DEK and the total plaintext
|
|
138
|
+
* length, emit `header()` (32 bytes) first, `push()` plaintext in arbitrary slice sizes —
|
|
139
|
+
* each call returns any now-complete sealed NON-final chunks (possibly empty) — then call
|
|
140
|
+
* `finish()` exactly once for the remaining sealed bytes including the final chunk.
|
|
141
|
+
* `header || push outputs || finish output`, concatenated in order, is the complete
|
|
142
|
+
* stream. Call `free()` afterwards to release the wasm-side memory.
|
|
143
|
+
*/
|
|
144
|
+
export class StreamEncryptor {
|
|
145
|
+
static __wrap(ptr) {
|
|
146
|
+
const obj = Object.create(StreamEncryptor.prototype);
|
|
147
|
+
obj.__wbg_ptr = ptr;
|
|
148
|
+
StreamEncryptorFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
149
|
+
return obj;
|
|
150
|
+
}
|
|
151
|
+
__destroy_into_raw() {
|
|
152
|
+
const ptr = this.__wbg_ptr;
|
|
153
|
+
this.__wbg_ptr = 0;
|
|
154
|
+
StreamEncryptorFinalization.unregister(this);
|
|
155
|
+
return ptr;
|
|
156
|
+
}
|
|
157
|
+
free() {
|
|
158
|
+
const ptr = this.__destroy_into_raw();
|
|
159
|
+
wasm.__wbg_streamencryptor_free(ptr, 0);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Total chunk count for this stream: `max(1, ceil(plaintext_len / chunk_size))`.
|
|
163
|
+
* @returns {number}
|
|
164
|
+
*/
|
|
165
|
+
chunk_count() {
|
|
166
|
+
const ret = wasm.streamencryptor_chunk_count(this.__wbg_ptr);
|
|
167
|
+
return ret;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Flushes any buffered chunks plus the final chunk (sealed with `is_final = 0x01`).
|
|
171
|
+
* Errors if fewer than `plaintext_len` bytes were pushed. A second call returns an
|
|
172
|
+
* empty array (idempotent — mirrors the Rust engine's `finish`).
|
|
173
|
+
* @returns {Uint8Array}
|
|
174
|
+
*/
|
|
175
|
+
finish() {
|
|
176
|
+
const ret = wasm.streamencryptor_finish(this.__wbg_ptr);
|
|
177
|
+
if (ret[3]) {
|
|
178
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
179
|
+
}
|
|
180
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
181
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
182
|
+
return v1;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The 32 plaintext header bytes (magic/version/log2/plaintext_len/nonce_prefix).
|
|
186
|
+
* Emit these first, before any chunk output. On a resume handle these are the SAME
|
|
187
|
+
* bytes passed to `resumeFromHeader`.
|
|
188
|
+
* @returns {Uint8Array}
|
|
189
|
+
*/
|
|
190
|
+
header() {
|
|
191
|
+
const ret = wasm.streamencryptor_header(this.__wbg_ptr);
|
|
192
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
193
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
194
|
+
return v1;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* `dek` must be 32 bytes; `plaintext_len` a non-negative integer ≤ 2^53. Uses the
|
|
198
|
+
* production constructor only: fresh random nonce prefix, chunk_size_log2 = 22
|
|
199
|
+
* (4 MiB) — callers can never supply nonces or chunk sizes.
|
|
200
|
+
*
|
|
201
|
+
* `part_index` and `part_total` say WHERE this blob sits in the file (NCF-3 §4.1, defect
|
|
202
|
+
* A4). They go into the header and therefore into every chunk's AAD, so a part that is
|
|
203
|
+
* later served in another part's position fails authentication instead of decrypting into
|
|
204
|
+
* the wrong place. A whole file in one blob is part 0 of 1.
|
|
205
|
+
*
|
|
206
|
+
* The pair is validated HERE rather than left to Rust's debug assertion: an impossible
|
|
207
|
+
* placement panics inside the engine, and a panic across the wasm boundary aborts the
|
|
208
|
+
* worker rather than raising something the caller can handle.
|
|
209
|
+
* @param {Uint8Array} dek
|
|
210
|
+
* @param {number} plaintext_len
|
|
211
|
+
* @param {number} part_index
|
|
212
|
+
* @param {number} part_total
|
|
213
|
+
*/
|
|
214
|
+
constructor(dek, plaintext_len, part_index, part_total) {
|
|
215
|
+
const ptr0 = passArray8ToWasm0(dek, wasm.__wbindgen_malloc);
|
|
216
|
+
const len0 = WASM_VECTOR_LEN;
|
|
217
|
+
const ret = wasm.streamencryptor_new(ptr0, len0, plaintext_len, part_index, part_total);
|
|
218
|
+
if (ret[2]) {
|
|
219
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
220
|
+
}
|
|
221
|
+
this.__wbg_ptr = ret[0];
|
|
222
|
+
StreamEncryptorFinalization.register(this, this.__wbg_ptr, this);
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Feeds plaintext in. Returns the sealed bytes (`ciphertext||tag` each) of any chunks
|
|
227
|
+
* that became complete — possibly empty. Errors if more than `plaintext_len` bytes
|
|
228
|
+
* are pushed in total.
|
|
229
|
+
* @param {Uint8Array} data
|
|
230
|
+
* @returns {Uint8Array}
|
|
231
|
+
*/
|
|
232
|
+
push(data) {
|
|
233
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
234
|
+
const len0 = WASM_VECTOR_LEN;
|
|
235
|
+
const ret = wasm.streamencryptor_push(this.__wbg_ptr, ptr0, len0);
|
|
236
|
+
if (ret[3]) {
|
|
237
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
238
|
+
}
|
|
239
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
240
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
241
|
+
return v2;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* ☠️ RESUME RE-DERIVATION ONLY. Reconstructs an encryptor from a PERSISTED 72-byte NCF-3
|
|
245
|
+
* header so a cross-reload resume can re-derive a registered part's EXACT ciphertext.
|
|
246
|
+
* Validates the header like the parser (magic/version/chunk_size_log2/plaintext_len) and
|
|
247
|
+
* re-emits those same 32 header bytes; seeds the nonce prefix + chunk sizing from it and
|
|
248
|
+
* starts at chunk index 0.
|
|
249
|
+
*
|
|
250
|
+
* The caller MUST NOT transmit any output unless its Walrus blobId bit-matches the
|
|
251
|
+
* originally registered blobId — reusing `(DEK, nonce_prefix)` for DIFFERENT plaintext is
|
|
252
|
+
* catastrophic. This is NEVER a fresh-upload path (use the constructor, random nonce).
|
|
253
|
+
* See `ResumeEncryptor`'s safety note for the full rationale.
|
|
254
|
+
* @param {Uint8Array} dek
|
|
255
|
+
* @param {Uint8Array} header
|
|
256
|
+
* @returns {StreamEncryptor}
|
|
257
|
+
*/
|
|
258
|
+
static resumeFromHeader(dek, header) {
|
|
259
|
+
const ptr0 = passArray8ToWasm0(dek, wasm.__wbindgen_malloc);
|
|
260
|
+
const len0 = WASM_VECTOR_LEN;
|
|
261
|
+
const ptr1 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
262
|
+
const len1 = WASM_VECTOR_LEN;
|
|
263
|
+
const ret = wasm.streamencryptor_resumeFromHeader(ptr0, len0, ptr1, len1);
|
|
264
|
+
if (ret[2]) {
|
|
265
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
266
|
+
}
|
|
267
|
+
return StreamEncryptor.__wrap(ret[0]);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (Symbol.dispose) StreamEncryptor.prototype[Symbol.dispose] = StreamEncryptor.prototype.free;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The display string for a set of 20 raw account-code bytes.
|
|
274
|
+
* @param {Uint8Array} code_bytes
|
|
275
|
+
* @returns {string}
|
|
276
|
+
*/
|
|
277
|
+
export function account_code_display(code_bytes) {
|
|
278
|
+
let deferred3_0;
|
|
279
|
+
let deferred3_1;
|
|
280
|
+
try {
|
|
281
|
+
const ptr0 = passArray8ToWasm0(code_bytes, wasm.__wbindgen_malloc);
|
|
282
|
+
const len0 = WASM_VECTOR_LEN;
|
|
283
|
+
const ret = wasm.account_code_display(ptr0, len0);
|
|
284
|
+
var ptr2 = ret[0];
|
|
285
|
+
var len2 = ret[1];
|
|
286
|
+
if (ret[3]) {
|
|
287
|
+
ptr2 = 0; len2 = 0;
|
|
288
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
289
|
+
}
|
|
290
|
+
deferred3_0 = ptr2;
|
|
291
|
+
deferred3_1 = len2;
|
|
292
|
+
return getStringFromWasm0(ptr2, len2);
|
|
293
|
+
} finally {
|
|
294
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Generates a fresh 160-bit account code and returns its display string
|
|
300
|
+
* (`XXXX-XXXX-…-XXXXC`). The bytes never leave the worker except as this one-time string.
|
|
301
|
+
* @returns {string}
|
|
302
|
+
*/
|
|
303
|
+
export function account_code_generate() {
|
|
304
|
+
let deferred1_0;
|
|
305
|
+
let deferred1_1;
|
|
306
|
+
try {
|
|
307
|
+
const ret = wasm.account_code_generate();
|
|
308
|
+
deferred1_0 = ret[0];
|
|
309
|
+
deferred1_1 = ret[1];
|
|
310
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
311
|
+
} finally {
|
|
312
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Parses+validates a user-entered account code (any spacing/case), returning the 20 raw
|
|
318
|
+
* bytes. Errors if the check symbol fails.
|
|
319
|
+
* @param {string} input
|
|
320
|
+
* @returns {Uint8Array}
|
|
321
|
+
*/
|
|
322
|
+
export function account_code_parse(input) {
|
|
323
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
324
|
+
const len0 = WASM_VECTOR_LEN;
|
|
325
|
+
const ret = wasm.account_code_parse(ptr0, len0);
|
|
326
|
+
if (ret[3]) {
|
|
327
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
328
|
+
}
|
|
329
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
330
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
331
|
+
return v2;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Unpadded base64url of arbitrary bytes. The textual `accountId` is
|
|
336
|
+
* `b64_encode(account_id_16_bytes)`.
|
|
337
|
+
* @param {Uint8Array} data
|
|
338
|
+
* @returns {string}
|
|
339
|
+
*/
|
|
340
|
+
export function b64_encode(data) {
|
|
341
|
+
let deferred2_0;
|
|
342
|
+
let deferred2_1;
|
|
343
|
+
try {
|
|
344
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
345
|
+
const len0 = WASM_VECTOR_LEN;
|
|
346
|
+
const ret = wasm.b64_encode(ptr0, len0);
|
|
347
|
+
deferred2_0 = ret[0];
|
|
348
|
+
deferred2_1 = ret[1];
|
|
349
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
350
|
+
} finally {
|
|
351
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Derives the 32-byte wrapping key for a passphrase-protected "remember this device" record.
|
|
357
|
+
*
|
|
358
|
+
* `salt` is 16 bytes the CALLER generated fresh for that record and stores beside the
|
|
359
|
+
* ciphertext — a human-chosen passphrase must never share a salt with another user's (see
|
|
360
|
+
* `kdf::derive_device_wrap_key`). Errors on a short passphrase or a wrong-length salt rather
|
|
361
|
+
* than deriving something weak.
|
|
362
|
+
*
|
|
363
|
+
* The returned key is ordinary bytes: the browser imports it into WebCrypto to seal the record
|
|
364
|
+
* and drops it. It is NOT an account key and reaches nothing an account key reaches.
|
|
365
|
+
* @param {Uint8Array} passphrase
|
|
366
|
+
* @param {Uint8Array} salt
|
|
367
|
+
* @returns {Uint8Array}
|
|
368
|
+
*/
|
|
369
|
+
export function device_wrap_key(passphrase, salt) {
|
|
370
|
+
const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_malloc);
|
|
371
|
+
const len0 = WASM_VECTOR_LEN;
|
|
372
|
+
const ptr1 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc);
|
|
373
|
+
const len1 = WASM_VECTOR_LEN;
|
|
374
|
+
const ret = wasm.device_wrap_key(ptr0, len0, ptr1, len1);
|
|
375
|
+
if (ret[3]) {
|
|
376
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
377
|
+
}
|
|
378
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
379
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
380
|
+
return v3;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Decrypts and authenticates an envelope (`nonce||ct||tag`) under `key`, checking `aad`.
|
|
385
|
+
* @param {Uint8Array} key
|
|
386
|
+
* @param {Uint8Array} aad
|
|
387
|
+
* @param {Uint8Array} envelope
|
|
388
|
+
* @returns {Uint8Array}
|
|
389
|
+
*/
|
|
390
|
+
export function envelope_open(key, aad, envelope) {
|
|
391
|
+
const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
|
|
392
|
+
const len0 = WASM_VECTOR_LEN;
|
|
393
|
+
const ptr1 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
394
|
+
const len1 = WASM_VECTOR_LEN;
|
|
395
|
+
const ptr2 = passArray8ToWasm0(envelope, wasm.__wbindgen_malloc);
|
|
396
|
+
const len2 = WASM_VECTOR_LEN;
|
|
397
|
+
const ret = wasm.envelope_open(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
398
|
+
if (ret[3]) {
|
|
399
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
400
|
+
}
|
|
401
|
+
var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
402
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
403
|
+
return v4;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Encrypts `plaintext` under `key` with a FRESH random 24-byte nonce (production path).
|
|
408
|
+
* @param {Uint8Array} key
|
|
409
|
+
* @param {Uint8Array} aad
|
|
410
|
+
* @param {Uint8Array} plaintext
|
|
411
|
+
* @returns {Uint8Array}
|
|
412
|
+
*/
|
|
413
|
+
export function envelope_seal(key, aad, plaintext) {
|
|
414
|
+
const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
|
|
415
|
+
const len0 = WASM_VECTOR_LEN;
|
|
416
|
+
const ptr1 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
417
|
+
const len1 = WASM_VECTOR_LEN;
|
|
418
|
+
const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
419
|
+
const len2 = WASM_VECTOR_LEN;
|
|
420
|
+
const ret = wasm.envelope_seal(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
421
|
+
if (ret[3]) {
|
|
422
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
423
|
+
}
|
|
424
|
+
var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
425
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
426
|
+
return v4;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* A fresh random 32-byte file DEK (WebCrypto-backed).
|
|
431
|
+
* @returns {Uint8Array}
|
|
432
|
+
*/
|
|
433
|
+
export function generate_dek() {
|
|
434
|
+
const ret = wasm.generate_dek();
|
|
435
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
436
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
437
|
+
return v1;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Chunk count derived from a validated header: `max(1, ceil(plaintext_len/chunk_size))`.
|
|
442
|
+
* Errors on a malformed header or a count beyond 2^53.
|
|
443
|
+
* @param {Uint8Array} header
|
|
444
|
+
* @returns {number}
|
|
445
|
+
*/
|
|
446
|
+
export function header_chunk_count(header) {
|
|
447
|
+
const ptr0 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
448
|
+
const len0 = WASM_VECTOR_LEN;
|
|
449
|
+
const ret = wasm.header_chunk_count(ptr0, len0);
|
|
450
|
+
if (ret[2]) {
|
|
451
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
452
|
+
}
|
|
453
|
+
return ret[0];
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Chunk size in bytes from a validated header (`1 << chunk_size_log2`; 4 MiB in v1).
|
|
458
|
+
* Errors on a malformed header. Always a power of two, hence exact as a JS number.
|
|
459
|
+
* @param {Uint8Array} header
|
|
460
|
+
* @returns {number}
|
|
461
|
+
*/
|
|
462
|
+
export function header_chunk_size(header) {
|
|
463
|
+
const ptr0 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
464
|
+
const len0 = WASM_VECTOR_LEN;
|
|
465
|
+
const ret = wasm.header_chunk_size(ptr0, len0);
|
|
466
|
+
if (ret[2]) {
|
|
467
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
468
|
+
}
|
|
469
|
+
return ret[0];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Where this part sits in its file, and how many parts the file has (NCF-3 §4.1).
|
|
474
|
+
* Exposed so the download path can show and check placement without decrypting anything.
|
|
475
|
+
* @param {Uint8Array} header
|
|
476
|
+
* @returns {number}
|
|
477
|
+
*/
|
|
478
|
+
export function header_part_index(header) {
|
|
479
|
+
const ptr0 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
480
|
+
const len0 = WASM_VECTOR_LEN;
|
|
481
|
+
const ret = wasm.header_part_index(ptr0, len0);
|
|
482
|
+
if (ret[2]) {
|
|
483
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
484
|
+
}
|
|
485
|
+
return ret[0];
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* @param {Uint8Array} header
|
|
490
|
+
* @returns {number}
|
|
491
|
+
*/
|
|
492
|
+
export function header_part_total(header) {
|
|
493
|
+
const ptr0 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
494
|
+
const len0 = WASM_VECTOR_LEN;
|
|
495
|
+
const ret = wasm.header_part_total(ptr0, len0);
|
|
496
|
+
if (ret[2]) {
|
|
497
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
498
|
+
}
|
|
499
|
+
return ret[0];
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* `plaintext_len` from a validated 32-byte header (u64 LE at offset 8). Errors on a
|
|
504
|
+
* malformed header, or on a declared length beyond 2^53 (not a JS-safe integer).
|
|
505
|
+
* @param {Uint8Array} header
|
|
506
|
+
* @returns {number}
|
|
507
|
+
*/
|
|
508
|
+
export function header_plaintext_len(header) {
|
|
509
|
+
const ptr0 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
510
|
+
const len0 = WASM_VECTOR_LEN;
|
|
511
|
+
const ret = wasm.header_plaintext_len(ptr0, len0);
|
|
512
|
+
if (ret[2]) {
|
|
513
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
514
|
+
}
|
|
515
|
+
return ret[0];
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Derives the account keys from the 20 raw account-code bytes (NCF-3 §1).
|
|
520
|
+
*
|
|
521
|
+
* Returns one concatenated buffer (`KDF_DERIVE_LEN` = 256 bytes) the caller slices:
|
|
522
|
+
* ```text
|
|
523
|
+
* 0.. 16 account_id public — the server's lookup key
|
|
524
|
+
* 16.. 48 auth_secret secret — sent to the server over TLS at login
|
|
525
|
+
* 48.. 80 data_key secret — wraps every file DEK; NEVER leaves the worker
|
|
526
|
+
* 80..112 file_list_key secret — opens the sealed drive index, and nothing else
|
|
527
|
+
* 112..144 share_kem_seed secret — X-Wing seed for private sharing (NCF-3 §5.1)
|
|
528
|
+
* 144..176 share_auth_secret secret — proves this account SENT a share (NCF-3 §5.5)
|
|
529
|
+
* 176..208 wallet_root secret — parent of EVERY wallet, including the first
|
|
530
|
+
* 208..224 share_address public — the address a user hands out to be shared with
|
|
531
|
+
* 224..256 share_sig_seed secret — ML-DSA-44 seed; its key IS the identity root (§5.2a)
|
|
532
|
+
* ```
|
|
533
|
+
* Every secret region above must be retained inside the crypto worker and never cross the
|
|
534
|
+
* postMessage boundary.
|
|
535
|
+
*
|
|
536
|
+
* ⚠ **This layout only ever grows at the TAIL.** `share_sig_seed` was appended in 2026-08-02
|
|
537
|
+
* rather than filed beside the other two share secrets, where it would read better, because
|
|
538
|
+
* inserting it there would shift `wallet_root` and `share_address` and every constant on the
|
|
539
|
+
* JS side would be silently wrong about which 32 bytes it was holding. Readability loses to
|
|
540
|
+
* that, every time.
|
|
541
|
+
*
|
|
542
|
+
* `share_address` is included even though it is not an HKDF output: since NCF-3 it is the
|
|
543
|
+
* FINGERPRINT of the share identity's root (§5.2), and computing it here means the browser never
|
|
544
|
+
* has to decide for itself which key an address belongs to.
|
|
545
|
+
* @param {Uint8Array} code_bytes
|
|
546
|
+
* @returns {Uint8Array}
|
|
547
|
+
*/
|
|
548
|
+
export function kdf_derive(code_bytes) {
|
|
549
|
+
const ptr0 = passArray8ToWasm0(code_bytes, wasm.__wbindgen_malloc);
|
|
550
|
+
const len0 = WASM_VECTOR_LEN;
|
|
551
|
+
const ret = wasm.kdf_derive(ptr0, len0);
|
|
552
|
+
if (ret[3]) {
|
|
553
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
554
|
+
}
|
|
555
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
556
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
557
|
+
return v2;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* The name this account's recovery manifest is stored under inside a quilt (NCF-3 §2.5).
|
|
562
|
+
*
|
|
563
|
+
* Public, and deliberately not secret-looking: it is a v4-shaped UUID exactly like the random
|
|
564
|
+
* per-item identifiers beside it in the same quilt. What it buys is that a recovery holding only
|
|
565
|
+
* an account code can compute the one name to ask a public aggregator for — no NMTS server, no
|
|
566
|
+
* saved file, no prior knowledge of the account's data.
|
|
567
|
+
*
|
|
568
|
+
* Takes `dataKey` rather than the account code because that key already lives in the worker; the
|
|
569
|
+
* code does not, and moving it here to hash it would put it somewhere it has no reason to be.
|
|
570
|
+
* @param {Uint8Array} data_key
|
|
571
|
+
* @returns {string}
|
|
572
|
+
*/
|
|
573
|
+
export function recovery_patch_name(data_key) {
|
|
574
|
+
let deferred3_0;
|
|
575
|
+
let deferred3_1;
|
|
576
|
+
try {
|
|
577
|
+
const ptr0 = passArray8ToWasm0(data_key, wasm.__wbindgen_malloc);
|
|
578
|
+
const len0 = WASM_VECTOR_LEN;
|
|
579
|
+
const ret = wasm.recovery_patch_name(ptr0, len0);
|
|
580
|
+
var ptr2 = ret[0];
|
|
581
|
+
var len2 = ret[1];
|
|
582
|
+
if (ret[3]) {
|
|
583
|
+
ptr2 = 0; len2 = 0;
|
|
584
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
585
|
+
}
|
|
586
|
+
deferred3_0 = ptr2;
|
|
587
|
+
deferred3_1 = len2;
|
|
588
|
+
return getStringFromWasm0(ptr2, len2);
|
|
589
|
+
} finally {
|
|
590
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* SHA-256 using the same `sha2` implementation as the Rust engine.
|
|
596
|
+
* @param {Uint8Array} data
|
|
597
|
+
* @returns {Uint8Array}
|
|
598
|
+
*/
|
|
599
|
+
export function sha256(data) {
|
|
600
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
601
|
+
const len0 = WASM_VECTOR_LEN;
|
|
602
|
+
const ret = wasm.sha256(ptr0, len0);
|
|
603
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
604
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
605
|
+
return v2;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* The display form of a share address (`kdf_derive` bytes 208..224):
|
|
610
|
+
* `XXXXXXXXX-XXXXXXXXX-XXXXXXXXC` — Crockford Base32 with a trailing check symbol.
|
|
611
|
+
* @param {Uint8Array} share_address
|
|
612
|
+
* @returns {string}
|
|
613
|
+
*/
|
|
614
|
+
export function share_address_display(share_address) {
|
|
615
|
+
let deferred3_0;
|
|
616
|
+
let deferred3_1;
|
|
617
|
+
try {
|
|
618
|
+
const ptr0 = passArray8ToWasm0(share_address, wasm.__wbindgen_malloc);
|
|
619
|
+
const len0 = WASM_VECTOR_LEN;
|
|
620
|
+
const ret = wasm.share_address_display(ptr0, len0);
|
|
621
|
+
var ptr2 = ret[0];
|
|
622
|
+
var len2 = ret[1];
|
|
623
|
+
if (ret[3]) {
|
|
624
|
+
ptr2 = 0; len2 = 0;
|
|
625
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
626
|
+
}
|
|
627
|
+
deferred3_0 = ptr2;
|
|
628
|
+
deferred3_1 = len2;
|
|
629
|
+
return getStringFromWasm0(ptr2, len2);
|
|
630
|
+
} finally {
|
|
631
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* The 16-byte share ADDRESS a published identity fingerprints to (NCF-3 §5.2).
|
|
637
|
+
*
|
|
638
|
+
* ⚠ **It parses the whole bundle first**, which means an identity whose self-signature does not
|
|
639
|
+
* verify, whose version is unknown, or whose X25519 halves are degenerate has no address at all
|
|
640
|
+
* as far as this function is concerned — it throws instead of returning one. Returning an address
|
|
641
|
+
* for a bundle nothing vouches for would be handing the caller a value that looks checkable and
|
|
642
|
+
* is not.
|
|
643
|
+
*
|
|
644
|
+
* Exposed so the browser can show a sender WHY a share was refused: the address it looked up and
|
|
645
|
+
* the address the returned identity actually belongs to are different values, and saying so is
|
|
646
|
+
* more useful than "failed".
|
|
647
|
+
* @param {Uint8Array} recipient_public
|
|
648
|
+
* @returns {Uint8Array}
|
|
649
|
+
*/
|
|
650
|
+
export function share_address_of(recipient_public) {
|
|
651
|
+
const ptr0 = passArray8ToWasm0(recipient_public, wasm.__wbindgen_malloc);
|
|
652
|
+
const len0 = WASM_VECTOR_LEN;
|
|
653
|
+
const ret = wasm.share_address_of(ptr0, len0);
|
|
654
|
+
if (ret[3]) {
|
|
655
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
656
|
+
}
|
|
657
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
658
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
659
|
+
return v2;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Parses a user-entered share address (any spacing/case) back to its 16 bytes, verifying the
|
|
664
|
+
* check symbol. A typo fails HERE, in the browser, before any lookup reaches the server.
|
|
665
|
+
* @param {string} input
|
|
666
|
+
* @returns {Uint8Array}
|
|
667
|
+
*/
|
|
668
|
+
export function share_address_parse(input) {
|
|
669
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
670
|
+
const len0 = WASM_VECTOR_LEN;
|
|
671
|
+
const ret = wasm.share_address_parse(ptr0, len0);
|
|
672
|
+
if (ret[3]) {
|
|
673
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
674
|
+
}
|
|
675
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
676
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
677
|
+
return v2;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* The sender address an envelope CLAIMS, so the caller knows whose identity to fetch.
|
|
682
|
+
*
|
|
683
|
+
* ⚠ A claim, not a fact, until `share_unwrap_dek` succeeds — the address is bound into the
|
|
684
|
+
* wrapping key, so an envelope that opens is one whose claim was true.
|
|
685
|
+
* @param {Uint8Array} envelope
|
|
686
|
+
* @returns {Uint8Array}
|
|
687
|
+
*/
|
|
688
|
+
export function share_claimed_sender(envelope) {
|
|
689
|
+
const ptr0 = passArray8ToWasm0(envelope, wasm.__wbindgen_malloc);
|
|
690
|
+
const len0 = WASM_VECTOR_LEN;
|
|
691
|
+
const ret = wasm.share_claimed_sender(ptr0, len0);
|
|
692
|
+
if (ret[3]) {
|
|
693
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
694
|
+
}
|
|
695
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
696
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
697
|
+
return v2;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* The 4989-byte PUBLIC share identity, built from the three secrets at `kdf_derive` bytes
|
|
702
|
+
* 112..176 and 224..256 (KEM seed, auth secret, signing seed).
|
|
703
|
+
*
|
|
704
|
+
* Layout: `version(1) || derivation_index(4) || pk_sig(1312) || key_epoch(4) || pk_kem(1216) ||
|
|
705
|
+
* pk_auth(32) || self_sig(2420)`. This is the only part of the identity the server holds, the
|
|
706
|
+
* address is the fingerprint of its ROOT, and the self-signature is what makes every key after
|
|
707
|
+
* the root attributable to that address (NCF-3 §5.2a).
|
|
708
|
+
*
|
|
709
|
+
* ⚠ The bytes are the same on every device the account code is entered on — deterministic
|
|
710
|
+
* signing, never hedged — which is what lets the server hold one bundle per account
|
|
711
|
+
* first-writer-wins without rejecting the account's own second device.
|
|
712
|
+
* @param {Uint8Array} share_kem_seed
|
|
713
|
+
* @param {Uint8Array} share_auth_secret
|
|
714
|
+
* @param {Uint8Array} share_sig_seed
|
|
715
|
+
* @returns {Uint8Array}
|
|
716
|
+
*/
|
|
717
|
+
export function share_public_key(share_kem_seed, share_auth_secret, share_sig_seed) {
|
|
718
|
+
const ptr0 = passArray8ToWasm0(share_kem_seed, wasm.__wbindgen_malloc);
|
|
719
|
+
const len0 = WASM_VECTOR_LEN;
|
|
720
|
+
const ptr1 = passArray8ToWasm0(share_auth_secret, wasm.__wbindgen_malloc);
|
|
721
|
+
const len1 = WASM_VECTOR_LEN;
|
|
722
|
+
const ptr2 = passArray8ToWasm0(share_sig_seed, wasm.__wbindgen_malloc);
|
|
723
|
+
const len2 = WASM_VECTOR_LEN;
|
|
724
|
+
const ret = wasm.share_public_key(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
725
|
+
if (ret[3]) {
|
|
726
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
727
|
+
}
|
|
728
|
+
var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
729
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
730
|
+
return v4;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Unwraps a share envelope addressed to us, returning the 32-byte file DEK.
|
|
735
|
+
*
|
|
736
|
+
* An envelope meant for somebody else fails exactly like a tampered one — the recipient's key is
|
|
737
|
+
* bound into the wrapping key, so there is nothing to tell the two cases apart. Since NCF-3 §5.3
|
|
738
|
+
* the same is true of an envelope stored beside a substituted name, digest or item id: the row is
|
|
739
|
+
* bound in too, and a rewritten row is indistinguishable from a forged envelope.
|
|
740
|
+
* @param {Uint8Array} share_kem_seed
|
|
741
|
+
* @param {Uint8Array} share_auth_secret
|
|
742
|
+
* @param {Uint8Array} share_sig_seed
|
|
743
|
+
* @param {Uint8Array} sender_public
|
|
744
|
+
* @param {Uint8Array} envelope
|
|
745
|
+
* @param {string} item_id
|
|
746
|
+
* @param {Uint8Array} name_share_ct
|
|
747
|
+
* @param {Uint8Array} content_hash_share_ct
|
|
748
|
+
* @returns {Uint8Array}
|
|
749
|
+
*/
|
|
750
|
+
export function share_unwrap_dek(share_kem_seed, share_auth_secret, share_sig_seed, sender_public, envelope, item_id, name_share_ct, content_hash_share_ct) {
|
|
751
|
+
const ptr0 = passArray8ToWasm0(share_kem_seed, wasm.__wbindgen_malloc);
|
|
752
|
+
const len0 = WASM_VECTOR_LEN;
|
|
753
|
+
const ptr1 = passArray8ToWasm0(share_auth_secret, wasm.__wbindgen_malloc);
|
|
754
|
+
const len1 = WASM_VECTOR_LEN;
|
|
755
|
+
const ptr2 = passArray8ToWasm0(share_sig_seed, wasm.__wbindgen_malloc);
|
|
756
|
+
const len2 = WASM_VECTOR_LEN;
|
|
757
|
+
const ptr3 = passArray8ToWasm0(sender_public, wasm.__wbindgen_malloc);
|
|
758
|
+
const len3 = WASM_VECTOR_LEN;
|
|
759
|
+
const ptr4 = passArray8ToWasm0(envelope, wasm.__wbindgen_malloc);
|
|
760
|
+
const len4 = WASM_VECTOR_LEN;
|
|
761
|
+
const ptr5 = passStringToWasm0(item_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
762
|
+
const len5 = WASM_VECTOR_LEN;
|
|
763
|
+
const ptr6 = passArray8ToWasm0(name_share_ct, wasm.__wbindgen_malloc);
|
|
764
|
+
const len6 = WASM_VECTOR_LEN;
|
|
765
|
+
const ptr7 = passArray8ToWasm0(content_hash_share_ct, wasm.__wbindgen_malloc);
|
|
766
|
+
const len7 = WASM_VECTOR_LEN;
|
|
767
|
+
const ret = wasm.share_unwrap_dek(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
|
|
768
|
+
if (ret[3]) {
|
|
769
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
770
|
+
}
|
|
771
|
+
var v9 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
772
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
773
|
+
return v9;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Wraps a file DEK for ONE recipient, given the public key the server returned AND the address
|
|
778
|
+
* the sender was actually given.
|
|
779
|
+
*
|
|
780
|
+
* ⚠ **Both arguments are required on purpose.** The key is checked against the address before
|
|
781
|
+
* anything is encrypted to it, so a server that substitutes its own key is refused here rather
|
|
782
|
+
* than silently handed a readable DEK (NCF-3 §5.2, defect A1). There is deliberately no
|
|
783
|
+
* two-argument form.
|
|
784
|
+
*
|
|
785
|
+
* ⚠ **The last three arguments are the row this envelope will be stored in** — the item id and
|
|
786
|
+
* the already-sealed name and content digest — and they are required for the same kind of reason
|
|
787
|
+
* (NCF-3 §5.3, defect A6). They are hashed into the wrapping key, so an envelope kept next to
|
|
788
|
+
* different columns stops opening. **This therefore has to be called AFTER `share_seal_name` and
|
|
789
|
+
* the re-sealed digest, not before.**
|
|
790
|
+
*
|
|
791
|
+
* Returns the 1240-byte share envelope (`sender_address(16) || kem_ciphertext(1120) || sealed
|
|
792
|
+
* DEK(104)`). A fresh encapsulation is drawn per call, so wrapping the same DEK for the same
|
|
793
|
+
* recipient twice produces unrelated bytes — the server cannot tell two shares went to the same
|
|
794
|
+
* person.
|
|
795
|
+
* @param {Uint8Array} sender_auth_secret
|
|
796
|
+
* @param {Uint8Array} sender_sig_seed
|
|
797
|
+
* @param {Uint8Array} recipient_public
|
|
798
|
+
* @param {Uint8Array} recipient_address
|
|
799
|
+
* @param {Uint8Array} dek
|
|
800
|
+
* @param {string} item_id
|
|
801
|
+
* @param {Uint8Array} name_share_ct
|
|
802
|
+
* @param {Uint8Array} content_hash_share_ct
|
|
803
|
+
* @returns {Uint8Array}
|
|
804
|
+
*/
|
|
805
|
+
export function share_wrap_dek(sender_auth_secret, sender_sig_seed, recipient_public, recipient_address, dek, item_id, name_share_ct, content_hash_share_ct) {
|
|
806
|
+
const ptr0 = passArray8ToWasm0(sender_auth_secret, wasm.__wbindgen_malloc);
|
|
807
|
+
const len0 = WASM_VECTOR_LEN;
|
|
808
|
+
const ptr1 = passArray8ToWasm0(sender_sig_seed, wasm.__wbindgen_malloc);
|
|
809
|
+
const len1 = WASM_VECTOR_LEN;
|
|
810
|
+
const ptr2 = passArray8ToWasm0(recipient_public, wasm.__wbindgen_malloc);
|
|
811
|
+
const len2 = WASM_VECTOR_LEN;
|
|
812
|
+
const ptr3 = passArray8ToWasm0(recipient_address, wasm.__wbindgen_malloc);
|
|
813
|
+
const len3 = WASM_VECTOR_LEN;
|
|
814
|
+
const ptr4 = passArray8ToWasm0(dek, wasm.__wbindgen_malloc);
|
|
815
|
+
const len4 = WASM_VECTOR_LEN;
|
|
816
|
+
const ptr5 = passStringToWasm0(item_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
817
|
+
const len5 = WASM_VECTOR_LEN;
|
|
818
|
+
const ptr6 = passArray8ToWasm0(name_share_ct, wasm.__wbindgen_malloc);
|
|
819
|
+
const len6 = WASM_VECTOR_LEN;
|
|
820
|
+
const ptr7 = passArray8ToWasm0(content_hash_share_ct, wasm.__wbindgen_malloc);
|
|
821
|
+
const len7 = WASM_VECTOR_LEN;
|
|
822
|
+
const ret = wasm.share_wrap_dek(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
|
|
823
|
+
if (ret[3]) {
|
|
824
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
825
|
+
}
|
|
826
|
+
var v9 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
827
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
828
|
+
return v9;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Decrypts a whole NCF-3 stream under the file DEK, verifying framing/anti-tamper.
|
|
833
|
+
* @param {Uint8Array} dek
|
|
834
|
+
* @param {Uint8Array} stream
|
|
835
|
+
* @returns {Uint8Array}
|
|
836
|
+
*/
|
|
837
|
+
export function stream_decrypt_all(dek, stream) {
|
|
838
|
+
const ptr0 = passArray8ToWasm0(dek, wasm.__wbindgen_malloc);
|
|
839
|
+
const len0 = WASM_VECTOR_LEN;
|
|
840
|
+
const ptr1 = passArray8ToWasm0(stream, wasm.__wbindgen_malloc);
|
|
841
|
+
const len1 = WASM_VECTOR_LEN;
|
|
842
|
+
const ret = wasm.stream_decrypt_all(ptr0, len0, ptr1, len1);
|
|
843
|
+
if (ret[3]) {
|
|
844
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
845
|
+
}
|
|
846
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
847
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
848
|
+
return v3;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Decrypts ONE chunk for random access (ranged reads), independent of any stream state.
|
|
853
|
+
*
|
|
854
|
+
* `header` is the 72-byte stream header; `chunk_index` the zero-based chunk index (non-negative
|
|
855
|
+
* integer); `ciphertext` must be EXACTLY that chunk's bytes — chunk `i` starts at stream
|
|
856
|
+
* offset `72 + i·(chunk_size+16)` and is `chunk_plaintext_len(i) + 16` bytes. `is_final`
|
|
857
|
+
* is derived from the header INSIDE Rust, so callers cannot mis-authenticate finality;
|
|
858
|
+
* a wrongly sized or out-of-range slice is rejected.
|
|
859
|
+
*
|
|
860
|
+
* `expected_part_index` / `expected_part_total` are WHERE THE CALLER BELIEVES IT IS READING
|
|
861
|
+
* (§4.1, defect A4) and are required, not optional. A ranged reader receives the header and the
|
|
862
|
+
* chunk in the SAME response, so the AAD it authenticates against is self-consistent whichever
|
|
863
|
+
* part the server actually served — and every part of a file is sealed under one DEK, so the
|
|
864
|
+
* wrong part opens cleanly with a valid tag. A whole file in one blob is `0, 1`. Take these from
|
|
865
|
+
* the position the byte range was computed FROM; reading them back out of `header` compares a
|
|
866
|
+
* value with itself and restores the hole.
|
|
867
|
+
* @param {Uint8Array} dek
|
|
868
|
+
* @param {Uint8Array} header
|
|
869
|
+
* @param {number} expected_part_index
|
|
870
|
+
* @param {number} expected_part_total
|
|
871
|
+
* @param {number} chunk_index
|
|
872
|
+
* @param {Uint8Array} ciphertext
|
|
873
|
+
* @returns {Uint8Array}
|
|
874
|
+
*/
|
|
875
|
+
export function stream_decrypt_chunk(dek, header, expected_part_index, expected_part_total, chunk_index, ciphertext) {
|
|
876
|
+
const ptr0 = passArray8ToWasm0(dek, wasm.__wbindgen_malloc);
|
|
877
|
+
const len0 = WASM_VECTOR_LEN;
|
|
878
|
+
const ptr1 = passArray8ToWasm0(header, wasm.__wbindgen_malloc);
|
|
879
|
+
const len1 = WASM_VECTOR_LEN;
|
|
880
|
+
const ptr2 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
881
|
+
const len2 = WASM_VECTOR_LEN;
|
|
882
|
+
const ret = wasm.stream_decrypt_chunk(ptr0, len0, ptr1, len1, expected_part_index, expected_part_total, chunk_index, ptr2, len2);
|
|
883
|
+
if (ret[3]) {
|
|
884
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
885
|
+
}
|
|
886
|
+
var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
887
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
888
|
+
return v4;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Encrypts `plaintext` into a whole NCF-3 stream under `dek` (production: random nonce prefix).
|
|
893
|
+
* @param {Uint8Array} dek
|
|
894
|
+
* @param {Uint8Array} plaintext
|
|
895
|
+
* @returns {Uint8Array}
|
|
896
|
+
*/
|
|
897
|
+
export function stream_encrypt_all(dek, plaintext) {
|
|
898
|
+
const ptr0 = passArray8ToWasm0(dek, wasm.__wbindgen_malloc);
|
|
899
|
+
const len0 = WASM_VECTOR_LEN;
|
|
900
|
+
const ptr1 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
901
|
+
const len1 = WASM_VECTOR_LEN;
|
|
902
|
+
const ret = wasm.stream_encrypt_all(ptr0, len0, ptr1, len1);
|
|
903
|
+
if (ret[3]) {
|
|
904
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
905
|
+
}
|
|
906
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
907
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
908
|
+
return v3;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Checks that a multi-part file's headers are the complete set, in order, of one file
|
|
913
|
+
* (NCF-3 §4.1, defect A4). `headers` is the parts' headers CONCATENATED in the order they
|
|
914
|
+
* will be decrypted — `part_total × 72` bytes.
|
|
915
|
+
*
|
|
916
|
+
* ⚠ Order is the whole point: the check is "the i-th header says part i", not "every index
|
|
917
|
+
* appears once". Sorting the parts by their own claimed index before calling this would make
|
|
918
|
+
* it pass on any permutation, which is exactly the attack it exists to catch. Pass them in
|
|
919
|
+
* the order the download will actually consume, straight from the server's list.
|
|
920
|
+
* @param {Uint8Array} headers
|
|
921
|
+
*/
|
|
922
|
+
export function verify_part_set(headers) {
|
|
923
|
+
const ptr0 = passArray8ToWasm0(headers, wasm.__wbindgen_malloc);
|
|
924
|
+
const len0 = WASM_VECTOR_LEN;
|
|
925
|
+
const ret = wasm.verify_part_set(ptr0, len0);
|
|
926
|
+
if (ret[1]) {
|
|
927
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* `SHA-256(normalize(input))` — the voucher redemption hash for arbitrary user input.
|
|
933
|
+
* @param {string} input
|
|
934
|
+
* @returns {Uint8Array}
|
|
935
|
+
*/
|
|
936
|
+
export function voucher_hash_from_input(input) {
|
|
937
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
938
|
+
const len0 = WASM_VECTOR_LEN;
|
|
939
|
+
const ret = wasm.voucher_hash_from_input(ptr0, len0);
|
|
940
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
941
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
942
|
+
return v2;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Derives the Ed25519 seed for wallet number `index` from the 32-byte `wallet_root`.
|
|
947
|
+
*
|
|
948
|
+
* EVERY wallet comes from here, including wallet 0. NCF-2 gave the first wallet its own
|
|
949
|
+
* derivation off the account PRK because it already existed on chain and could not move; NCF-3
|
|
950
|
+
* deletes that exception, so there is one rule and no index this function refuses.
|
|
951
|
+
* @param {Uint8Array} wallet_root
|
|
952
|
+
* @param {number} index
|
|
953
|
+
* @returns {Uint8Array}
|
|
954
|
+
*/
|
|
955
|
+
export function wallet_seed_for(wallet_root, index) {
|
|
956
|
+
const ptr0 = passArray8ToWasm0(wallet_root, wasm.__wbindgen_malloc);
|
|
957
|
+
const len0 = WASM_VECTOR_LEN;
|
|
958
|
+
const ret = wasm.wallet_seed_for(ptr0, len0, index);
|
|
959
|
+
if (ret[3]) {
|
|
960
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
961
|
+
}
|
|
962
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
963
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
964
|
+
return v2;
|
|
965
|
+
}
|
|
966
|
+
function __wbg_get_imports() {
|
|
967
|
+
const import0 = {
|
|
968
|
+
__proto__: null,
|
|
969
|
+
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
970
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
971
|
+
return ret;
|
|
972
|
+
},
|
|
973
|
+
__wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
|
|
974
|
+
const ret = typeof(arg0) === 'function';
|
|
975
|
+
return ret;
|
|
976
|
+
},
|
|
977
|
+
__wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
|
|
978
|
+
const val = arg0;
|
|
979
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
980
|
+
return ret;
|
|
981
|
+
},
|
|
982
|
+
__wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(arg0) {
|
|
983
|
+
const ret = typeof(arg0) === 'string';
|
|
984
|
+
return ret;
|
|
985
|
+
},
|
|
986
|
+
__wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
|
|
987
|
+
const ret = arg0 === undefined;
|
|
988
|
+
return ret;
|
|
989
|
+
},
|
|
990
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
991
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
992
|
+
},
|
|
993
|
+
__wbg_call_a6e5c5dce5018821: function() { return handleError(function (arg0, arg1, arg2) {
|
|
994
|
+
const ret = arg0.call(arg1, arg2);
|
|
995
|
+
return ret;
|
|
996
|
+
}, arguments); },
|
|
997
|
+
__wbg_crypto_38df2bab126b63dc: function(arg0) {
|
|
998
|
+
const ret = arg0.crypto;
|
|
999
|
+
return ret;
|
|
1000
|
+
},
|
|
1001
|
+
__wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
|
|
1002
|
+
arg0.getRandomValues(arg1);
|
|
1003
|
+
}, arguments); },
|
|
1004
|
+
__wbg_length_1f0964f4a5e2c6d8: function(arg0) {
|
|
1005
|
+
const ret = arg0.length;
|
|
1006
|
+
return ret;
|
|
1007
|
+
},
|
|
1008
|
+
__wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
|
|
1009
|
+
const ret = arg0.msCrypto;
|
|
1010
|
+
return ret;
|
|
1011
|
+
},
|
|
1012
|
+
__wbg_new_with_length_e6785c33c8e4cce8: function(arg0) {
|
|
1013
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
1014
|
+
return ret;
|
|
1015
|
+
},
|
|
1016
|
+
__wbg_node_84ea875411254db1: function(arg0) {
|
|
1017
|
+
const ret = arg0.node;
|
|
1018
|
+
return ret;
|
|
1019
|
+
},
|
|
1020
|
+
__wbg_process_44c7a14e11e9f69e: function(arg0) {
|
|
1021
|
+
const ret = arg0.process;
|
|
1022
|
+
return ret;
|
|
1023
|
+
},
|
|
1024
|
+
__wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
|
|
1025
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
1026
|
+
},
|
|
1027
|
+
__wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
|
|
1028
|
+
arg0.randomFillSync(arg1);
|
|
1029
|
+
}, arguments); },
|
|
1030
|
+
__wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
|
|
1031
|
+
const ret = module.require;
|
|
1032
|
+
return ret;
|
|
1033
|
+
}, arguments); },
|
|
1034
|
+
__wbg_static_accessor_GLOBAL_4ef717fb391d88b7: function() {
|
|
1035
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
1036
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
1037
|
+
},
|
|
1038
|
+
__wbg_static_accessor_GLOBAL_THIS_8d1badc68b5a74f4: function() {
|
|
1039
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
1040
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
1041
|
+
},
|
|
1042
|
+
__wbg_static_accessor_SELF_146583524fe1469b: function() {
|
|
1043
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
1044
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
1045
|
+
},
|
|
1046
|
+
__wbg_static_accessor_WINDOW_f2829a2234d7819e: function() {
|
|
1047
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
1048
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
1049
|
+
},
|
|
1050
|
+
__wbg_subarray_3ed232c8a6baee09: function(arg0, arg1, arg2) {
|
|
1051
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
1052
|
+
return ret;
|
|
1053
|
+
},
|
|
1054
|
+
__wbg_versions_276b2795b1c6a219: function(arg0) {
|
|
1055
|
+
const ret = arg0.versions;
|
|
1056
|
+
return ret;
|
|
1057
|
+
},
|
|
1058
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1059
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
1060
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
1061
|
+
return ret;
|
|
1062
|
+
},
|
|
1063
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
1064
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
1065
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
1066
|
+
return ret;
|
|
1067
|
+
},
|
|
1068
|
+
__wbindgen_init_externref_table: function() {
|
|
1069
|
+
const table = wasm.__wbindgen_externrefs;
|
|
1070
|
+
const offset = table.grow(4);
|
|
1071
|
+
table.set(0, undefined);
|
|
1072
|
+
table.set(offset + 0, undefined);
|
|
1073
|
+
table.set(offset + 1, null);
|
|
1074
|
+
table.set(offset + 2, true);
|
|
1075
|
+
table.set(offset + 3, false);
|
|
1076
|
+
},
|
|
1077
|
+
};
|
|
1078
|
+
return {
|
|
1079
|
+
__proto__: null,
|
|
1080
|
+
"./nmts_crypto_wasm_bg.js": import0,
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
const Sha256HasherFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1085
|
+
? { register: () => {}, unregister: () => {} }
|
|
1086
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_sha256hasher_free(ptr, 1));
|
|
1087
|
+
const StreamDecryptorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1088
|
+
? { register: () => {}, unregister: () => {} }
|
|
1089
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_streamdecryptor_free(ptr, 1));
|
|
1090
|
+
const StreamEncryptorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1091
|
+
? { register: () => {}, unregister: () => {} }
|
|
1092
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_streamencryptor_free(ptr, 1));
|
|
1093
|
+
|
|
1094
|
+
function addToExternrefTable0(obj) {
|
|
1095
|
+
const idx = wasm.__externref_table_alloc();
|
|
1096
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
1097
|
+
return idx;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
1101
|
+
ptr = ptr >>> 0;
|
|
1102
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function getStringFromWasm0(ptr, len) {
|
|
1106
|
+
return decodeText(ptr >>> 0, len);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
let cachedUint8ArrayMemory0 = null;
|
|
1110
|
+
function getUint8ArrayMemory0() {
|
|
1111
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
1112
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
1113
|
+
}
|
|
1114
|
+
return cachedUint8ArrayMemory0;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
function handleError(f, args) {
|
|
1118
|
+
try {
|
|
1119
|
+
return f.apply(this, args);
|
|
1120
|
+
} catch (e) {
|
|
1121
|
+
const idx = addToExternrefTable0(e);
|
|
1122
|
+
wasm.__wbindgen_exn_store(idx);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
function isLikeNone(x) {
|
|
1127
|
+
return x === undefined || x === null;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
1131
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
1132
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
1133
|
+
WASM_VECTOR_LEN = arg.length;
|
|
1134
|
+
return ptr;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
1138
|
+
if (realloc === undefined) {
|
|
1139
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
1140
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
1141
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
1142
|
+
WASM_VECTOR_LEN = buf.length;
|
|
1143
|
+
return ptr;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
let len = arg.length;
|
|
1147
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
1148
|
+
|
|
1149
|
+
const mem = getUint8ArrayMemory0();
|
|
1150
|
+
|
|
1151
|
+
let offset = 0;
|
|
1152
|
+
|
|
1153
|
+
for (; offset < len; offset++) {
|
|
1154
|
+
const code = arg.charCodeAt(offset);
|
|
1155
|
+
if (code > 0x7F) break;
|
|
1156
|
+
mem[ptr + offset] = code;
|
|
1157
|
+
}
|
|
1158
|
+
if (offset !== len) {
|
|
1159
|
+
if (offset !== 0) {
|
|
1160
|
+
arg = arg.slice(offset);
|
|
1161
|
+
}
|
|
1162
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
1163
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
1164
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
1165
|
+
|
|
1166
|
+
offset += ret.written;
|
|
1167
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
WASM_VECTOR_LEN = offset;
|
|
1171
|
+
return ptr;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
function takeFromExternrefTable0(idx) {
|
|
1175
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
1176
|
+
wasm.__externref_table_dealloc(idx);
|
|
1177
|
+
return value;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1181
|
+
cachedTextDecoder.decode();
|
|
1182
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
1183
|
+
let numBytesDecoded = 0;
|
|
1184
|
+
function decodeText(ptr, len) {
|
|
1185
|
+
numBytesDecoded += len;
|
|
1186
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
1187
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1188
|
+
cachedTextDecoder.decode();
|
|
1189
|
+
numBytesDecoded = len;
|
|
1190
|
+
}
|
|
1191
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
const cachedTextEncoder = new TextEncoder();
|
|
1195
|
+
|
|
1196
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
1197
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
1198
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
1199
|
+
view.set(buf);
|
|
1200
|
+
return {
|
|
1201
|
+
read: arg.length,
|
|
1202
|
+
written: buf.length
|
|
1203
|
+
};
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
let WASM_VECTOR_LEN = 0;
|
|
1208
|
+
|
|
1209
|
+
let wasmModule, wasmInstance, wasm;
|
|
1210
|
+
function __wbg_finalize_init(instance, module) {
|
|
1211
|
+
wasmInstance = instance;
|
|
1212
|
+
wasm = instance.exports;
|
|
1213
|
+
wasmModule = module;
|
|
1214
|
+
cachedUint8ArrayMemory0 = null;
|
|
1215
|
+
wasm.__wbindgen_start();
|
|
1216
|
+
return wasm;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
async function __wbg_load(module, imports) {
|
|
1220
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
1221
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
1222
|
+
try {
|
|
1223
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
1224
|
+
} catch (e) {
|
|
1225
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
1226
|
+
|
|
1227
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
1228
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
1229
|
+
|
|
1230
|
+
} else { throw e; }
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
const bytes = await module.arrayBuffer();
|
|
1235
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
1236
|
+
} else {
|
|
1237
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
1238
|
+
|
|
1239
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
1240
|
+
return { instance, module };
|
|
1241
|
+
} else {
|
|
1242
|
+
return instance;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function expectedResponseType(type) {
|
|
1247
|
+
switch (type) {
|
|
1248
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
1249
|
+
}
|
|
1250
|
+
return false;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
function initSync(module) {
|
|
1255
|
+
if (wasm !== undefined) return wasm;
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
if (module !== undefined) {
|
|
1259
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
1260
|
+
({module} = module)
|
|
1261
|
+
} else {
|
|
1262
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
const imports = __wbg_get_imports();
|
|
1267
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
1268
|
+
module = new WebAssembly.Module(module);
|
|
1269
|
+
}
|
|
1270
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
1271
|
+
return __wbg_finalize_init(instance, module);
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
async function __wbg_init(module_or_path) {
|
|
1275
|
+
if (wasm !== undefined) return wasm;
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
if (module_or_path !== undefined) {
|
|
1279
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
1280
|
+
({module_or_path} = module_or_path)
|
|
1281
|
+
} else {
|
|
1282
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
if (module_or_path === undefined) {
|
|
1287
|
+
module_or_path = new URL('nmts_crypto_wasm_bg.wasm', import.meta.url);
|
|
1288
|
+
}
|
|
1289
|
+
const imports = __wbg_get_imports();
|
|
1290
|
+
|
|
1291
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
1292
|
+
module_or_path = fetch(module_or_path);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
1296
|
+
|
|
1297
|
+
return __wbg_finalize_init(instance, module);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
export { initSync, __wbg_init as default };
|