sealnet 2.0.4 → 3.0.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.
- package/README.md +11 -8
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/dist/index.cjs +1890 -1053
- package/dist/index.d.cts +11 -8
- package/dist/index.d.ts +11 -8
- package/dist/index.js +1890 -1053
- package/dist/seal.global.js +3 -3
- package/dist/seal.global.js.sha384 +1 -1
- package/dist/seal_crypto.wasm +0 -0
- package/dist/seal_crypto.wasm.sha384 +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// <define:__SEAL_WASM__>
|
|
2
|
-
var define_SEAL_WASM_default = { url: "https://seal.net/sdk/
|
|
2
|
+
var define_SEAL_WASM_default = { url: "https://seal.net/sdk/v3.0.0/seal_crypto.wasm", integrity: "sha384-1YRbwC1HEXYdDK3uZhUll78kTSwBJsxo0u34UsveDvpdd5We2JKnqAWOsru5GK3R" };
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
@@ -8,19 +8,122 @@ var __export = (target, all) => {
|
|
|
8
8
|
};
|
|
9
9
|
var glue_module_generated_exports = {};
|
|
10
10
|
__export(glue_module_generated_exports, {
|
|
11
|
+
ContractTermsBuilder: () => ContractTermsBuilder,
|
|
11
12
|
WasmIdentity: () => WasmIdentity,
|
|
12
13
|
default: () => __wbg_init,
|
|
13
14
|
init: () => init,
|
|
14
15
|
initSync: () => initSync,
|
|
16
|
+
wasm_approval_message: () => wasm_approval_message,
|
|
15
17
|
wasm_bundle_address: () => wasm_bundle_address,
|
|
16
18
|
wasm_bundle_verify_for_address: () => wasm_bundle_verify_for_address,
|
|
17
19
|
wasm_contract_message: () => wasm_contract_message,
|
|
20
|
+
wasm_contract_message_v2: () => wasm_contract_message_v2,
|
|
18
21
|
wasm_ed25519_verify: () => wasm_ed25519_verify,
|
|
19
22
|
wasm_sealbox_unwrap: () => wasm_sealbox_unwrap,
|
|
20
23
|
wasm_sealbox_wrap: () => wasm_sealbox_wrap,
|
|
24
|
+
wasm_summary_message: () => wasm_summary_message,
|
|
21
25
|
wasm_unwrap_file_key: () => wasm_unwrap_file_key,
|
|
22
26
|
wasm_wrap_file_key: () => wasm_wrap_file_key
|
|
23
27
|
});
|
|
28
|
+
var ContractTermsBuilder = class {
|
|
29
|
+
__destroy_into_raw() {
|
|
30
|
+
const ptr = this.__wbg_ptr;
|
|
31
|
+
this.__wbg_ptr = 0;
|
|
32
|
+
ContractTermsBuilderFinalization.unregister(this);
|
|
33
|
+
return ptr;
|
|
34
|
+
}
|
|
35
|
+
free() {
|
|
36
|
+
const ptr = this.__destroy_into_raw();
|
|
37
|
+
wasm.__wbg_contracttermsbuilder_free(ptr, 0);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The digest in hex; the builder is spent.
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
digest() {
|
|
44
|
+
let deferred1_0;
|
|
45
|
+
let deferred1_1;
|
|
46
|
+
try {
|
|
47
|
+
const ptr = this.__destroy_into_raw();
|
|
48
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
49
|
+
wasm.contracttermsbuilder_digest(retptr, ptr);
|
|
50
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
51
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
52
|
+
deferred1_0 = r0;
|
|
53
|
+
deferred1_1 = r1;
|
|
54
|
+
return getStringFromWasm0(r0, r1);
|
|
55
|
+
} finally {
|
|
56
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
57
|
+
wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} id
|
|
62
|
+
* @param {string} field_type
|
|
63
|
+
* @param {number} page
|
|
64
|
+
* @param {number} x
|
|
65
|
+
* @param {number} y
|
|
66
|
+
* @param {number} w
|
|
67
|
+
* @param {number} h
|
|
68
|
+
* @param {string} assignee_type
|
|
69
|
+
* @param {string} assignee
|
|
70
|
+
* @param {boolean} required
|
|
71
|
+
*/
|
|
72
|
+
field(id, field_type, page, x, y, w, h, assignee_type, assignee, required) {
|
|
73
|
+
try {
|
|
74
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
75
|
+
const ptr0 = passStringToWasm0(id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
76
|
+
const len0 = WASM_VECTOR_LEN;
|
|
77
|
+
const ptr1 = passStringToWasm0(field_type, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
78
|
+
const len1 = WASM_VECTOR_LEN;
|
|
79
|
+
const ptr2 = passStringToWasm0(assignee_type, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
80
|
+
const len2 = WASM_VECTOR_LEN;
|
|
81
|
+
const ptr3 = passStringToWasm0(assignee, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
82
|
+
const len3 = WASM_VECTOR_LEN;
|
|
83
|
+
wasm.contracttermsbuilder_field(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, page, x, y, w, h, ptr2, len2, ptr3, len3, required);
|
|
84
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
85
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
86
|
+
if (r1) {
|
|
87
|
+
throw takeObject(r0);
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} field_id
|
|
95
|
+
* @param {string} sha256_hex
|
|
96
|
+
*/
|
|
97
|
+
filled(field_id, sha256_hex) {
|
|
98
|
+
try {
|
|
99
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
100
|
+
const ptr0 = passStringToWasm0(field_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
101
|
+
const len0 = WASM_VECTOR_LEN;
|
|
102
|
+
const ptr1 = passStringToWasm0(sha256_hex, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
103
|
+
const len1 = WASM_VECTOR_LEN;
|
|
104
|
+
wasm.contracttermsbuilder_filled(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
105
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
106
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
107
|
+
if (r1) {
|
|
108
|
+
throw takeObject(r0);
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @param {string | null} [meta_encrypted]
|
|
116
|
+
*/
|
|
117
|
+
constructor(meta_encrypted) {
|
|
118
|
+
var ptr0 = isLikeNone(meta_encrypted) ? 0 : passStringToWasm0(meta_encrypted, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
119
|
+
var len0 = WASM_VECTOR_LEN;
|
|
120
|
+
const ret = wasm.contracttermsbuilder_new(ptr0, len0);
|
|
121
|
+
this.__wbg_ptr = ret;
|
|
122
|
+
ContractTermsBuilderFinalization.register(this, this.__wbg_ptr, this);
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
if (Symbol.dispose) ContractTermsBuilder.prototype[Symbol.dispose] = ContractTermsBuilder.prototype.free;
|
|
24
127
|
var WasmIdentity = class _WasmIdentity {
|
|
25
128
|
static __wrap(ptr) {
|
|
26
129
|
const obj = Object.create(_WasmIdentity.prototype);
|
|
@@ -183,6 +286,34 @@ var WasmIdentity = class _WasmIdentity {
|
|
|
183
286
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
184
287
|
}
|
|
185
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* An owner's answer to a guard's question (SPEC agent egress §7.3): `allow` or `deny` of `ask` at `at`.
|
|
291
|
+
* @param {string} ask
|
|
292
|
+
* @param {string} decision
|
|
293
|
+
* @param {string} at
|
|
294
|
+
* @returns {Uint8Array}
|
|
295
|
+
*/
|
|
296
|
+
signApproval(ask, decision, at) {
|
|
297
|
+
try {
|
|
298
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
299
|
+
const ptr0 = passStringToWasm0(ask, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
300
|
+
const len0 = WASM_VECTOR_LEN;
|
|
301
|
+
const ptr1 = passStringToWasm0(decision, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
302
|
+
const len1 = WASM_VECTOR_LEN;
|
|
303
|
+
const ptr2 = passStringToWasm0(at, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
304
|
+
const len2 = WASM_VECTOR_LEN;
|
|
305
|
+
wasm.wasmidentity_signApproval(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
306
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
307
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
308
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
309
|
+
if (r2) {
|
|
310
|
+
throw takeObject(r1);
|
|
311
|
+
}
|
|
312
|
+
return takeObject(r0);
|
|
313
|
+
} finally {
|
|
314
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
186
317
|
/**
|
|
187
318
|
* The signature of a contract (Р31, Р37).
|
|
188
319
|
* @param {string} org_id
|
|
@@ -212,7 +343,93 @@ var WasmIdentity = class _WasmIdentity {
|
|
|
212
343
|
}
|
|
213
344
|
}
|
|
214
345
|
/**
|
|
215
|
-
* The
|
|
346
|
+
* The signature of a contract and of what its signer saw (AUDIT K204): `terms` is `ContractTermsBuilder`'s digest.
|
|
347
|
+
* @param {string} org_id
|
|
348
|
+
* @param {string} request_id
|
|
349
|
+
* @param {string} doc_hash
|
|
350
|
+
* @param {string} terms
|
|
351
|
+
* @returns {Uint8Array}
|
|
352
|
+
*/
|
|
353
|
+
signContractV2(org_id, request_id, doc_hash, terms) {
|
|
354
|
+
try {
|
|
355
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
356
|
+
const ptr0 = passStringToWasm0(org_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
357
|
+
const len0 = WASM_VECTOR_LEN;
|
|
358
|
+
const ptr1 = passStringToWasm0(request_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
359
|
+
const len1 = WASM_VECTOR_LEN;
|
|
360
|
+
const ptr2 = passStringToWasm0(doc_hash, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
361
|
+
const len2 = WASM_VECTOR_LEN;
|
|
362
|
+
const ptr3 = passStringToWasm0(terms, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
363
|
+
const len3 = WASM_VECTOR_LEN;
|
|
364
|
+
wasm.wasmidentity_signContractV2(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
365
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
366
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
367
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
368
|
+
if (r2) {
|
|
369
|
+
throw takeObject(r1);
|
|
370
|
+
}
|
|
371
|
+
return takeObject(r0);
|
|
372
|
+
} finally {
|
|
373
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* A guard's daily summary of a lent key (SPEC agent egress §7.4): the chain's root and length for `day`.
|
|
378
|
+
* @param {string} secret_id
|
|
379
|
+
* @param {string} day
|
|
380
|
+
* @param {string} root_hex
|
|
381
|
+
* @param {bigint} n
|
|
382
|
+
* @returns {Uint8Array}
|
|
383
|
+
*/
|
|
384
|
+
signSummary(secret_id, day, root_hex, n) {
|
|
385
|
+
try {
|
|
386
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
387
|
+
const ptr0 = passStringToWasm0(secret_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
388
|
+
const len0 = WASM_VECTOR_LEN;
|
|
389
|
+
const ptr1 = passStringToWasm0(day, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
390
|
+
const len1 = WASM_VECTOR_LEN;
|
|
391
|
+
const ptr2 = passStringToWasm0(root_hex, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
392
|
+
const len2 = WASM_VECTOR_LEN;
|
|
393
|
+
wasm.wasmidentity_signSummary(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, n);
|
|
394
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
395
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
396
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
397
|
+
if (r2) {
|
|
398
|
+
throw takeObject(r1);
|
|
399
|
+
}
|
|
400
|
+
return takeObject(r0);
|
|
401
|
+
} finally {
|
|
402
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* A person's sign-in from a device (Д5 §3.2): the user proof for a 16-byte user id and the server's challenge, as
|
|
407
|
+
* sealfs signs it — the SEAL Pro CLI's key session (AUDIT K227).
|
|
408
|
+
* @param {Uint8Array} user_id
|
|
409
|
+
* @param {Uint8Array} nonce
|
|
410
|
+
* @returns {Uint8Array}
|
|
411
|
+
*/
|
|
412
|
+
userProof(user_id, nonce) {
|
|
413
|
+
try {
|
|
414
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
415
|
+
const ptr0 = passArray8ToWasm0(user_id, wasm.__wbindgen_export3);
|
|
416
|
+
const len0 = WASM_VECTOR_LEN;
|
|
417
|
+
const ptr1 = passArray8ToWasm0(nonce, wasm.__wbindgen_export3);
|
|
418
|
+
const len1 = WASM_VECTOR_LEN;
|
|
419
|
+
wasm.wasmidentity_userProof(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
420
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
421
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
422
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
423
|
+
if (r2) {
|
|
424
|
+
throw takeObject(r1);
|
|
425
|
+
}
|
|
426
|
+
return takeObject(r0);
|
|
427
|
+
} finally {
|
|
428
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* The eight words of the address.
|
|
216
433
|
* @returns {string}
|
|
217
434
|
*/
|
|
218
435
|
words() {
|
|
@@ -261,6 +478,37 @@ if (Symbol.dispose) WasmIdentity.prototype[Symbol.dispose] = WasmIdentity.protot
|
|
|
261
478
|
function init() {
|
|
262
479
|
wasm.init();
|
|
263
480
|
}
|
|
481
|
+
function wasm_approval_message(ask, decision, at) {
|
|
482
|
+
let deferred5_0;
|
|
483
|
+
let deferred5_1;
|
|
484
|
+
try {
|
|
485
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
486
|
+
const ptr0 = passStringToWasm0(ask, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
487
|
+
const len0 = WASM_VECTOR_LEN;
|
|
488
|
+
const ptr1 = passStringToWasm0(decision, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
489
|
+
const len1 = WASM_VECTOR_LEN;
|
|
490
|
+
const ptr2 = passStringToWasm0(at, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
491
|
+
const len2 = WASM_VECTOR_LEN;
|
|
492
|
+
wasm.wasm_approval_message(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
493
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
494
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
495
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
496
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
497
|
+
var ptr4 = r0;
|
|
498
|
+
var len4 = r1;
|
|
499
|
+
if (r3) {
|
|
500
|
+
ptr4 = 0;
|
|
501
|
+
len4 = 0;
|
|
502
|
+
throw takeObject(r2);
|
|
503
|
+
}
|
|
504
|
+
deferred5_0 = ptr4;
|
|
505
|
+
deferred5_1 = len4;
|
|
506
|
+
return getStringFromWasm0(ptr4, len4);
|
|
507
|
+
} finally {
|
|
508
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
509
|
+
wasm.__wbindgen_export2(deferred5_0, deferred5_1, 1);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
264
512
|
function wasm_bundle_address(packed) {
|
|
265
513
|
try {
|
|
266
514
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -317,6 +565,39 @@ function wasm_contract_message(org_id, request_id, doc_hash) {
|
|
|
317
565
|
wasm.__wbindgen_export2(deferred5_0, deferred5_1, 1);
|
|
318
566
|
}
|
|
319
567
|
}
|
|
568
|
+
function wasm_contract_message_v2(org_id, request_id, doc_hash, terms) {
|
|
569
|
+
let deferred6_0;
|
|
570
|
+
let deferred6_1;
|
|
571
|
+
try {
|
|
572
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
573
|
+
const ptr0 = passStringToWasm0(org_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
574
|
+
const len0 = WASM_VECTOR_LEN;
|
|
575
|
+
const ptr1 = passStringToWasm0(request_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
576
|
+
const len1 = WASM_VECTOR_LEN;
|
|
577
|
+
const ptr2 = passStringToWasm0(doc_hash, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
578
|
+
const len2 = WASM_VECTOR_LEN;
|
|
579
|
+
const ptr3 = passStringToWasm0(terms, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
580
|
+
const len3 = WASM_VECTOR_LEN;
|
|
581
|
+
wasm.wasm_contract_message_v2(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
582
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
583
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
584
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
585
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
586
|
+
var ptr5 = r0;
|
|
587
|
+
var len5 = r1;
|
|
588
|
+
if (r3) {
|
|
589
|
+
ptr5 = 0;
|
|
590
|
+
len5 = 0;
|
|
591
|
+
throw takeObject(r2);
|
|
592
|
+
}
|
|
593
|
+
deferred6_0 = ptr5;
|
|
594
|
+
deferred6_1 = len5;
|
|
595
|
+
return getStringFromWasm0(ptr5, len5);
|
|
596
|
+
} finally {
|
|
597
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
598
|
+
wasm.__wbindgen_export2(deferred6_0, deferred6_1, 1);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
320
601
|
function wasm_ed25519_verify(public_key, message, signature) {
|
|
321
602
|
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_export3);
|
|
322
603
|
const len0 = WASM_VECTOR_LEN;
|
|
@@ -373,6 +654,37 @@ function wasm_sealbox_wrap(key_to_wrap, packed_bundle, scope_type, scope_id) {
|
|
|
373
654
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
374
655
|
}
|
|
375
656
|
}
|
|
657
|
+
function wasm_summary_message(secret_id, day, root_hex, n) {
|
|
658
|
+
let deferred5_0;
|
|
659
|
+
let deferred5_1;
|
|
660
|
+
try {
|
|
661
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
662
|
+
const ptr0 = passStringToWasm0(secret_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
663
|
+
const len0 = WASM_VECTOR_LEN;
|
|
664
|
+
const ptr1 = passStringToWasm0(day, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
665
|
+
const len1 = WASM_VECTOR_LEN;
|
|
666
|
+
const ptr2 = passStringToWasm0(root_hex, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
667
|
+
const len2 = WASM_VECTOR_LEN;
|
|
668
|
+
wasm.wasm_summary_message(retptr, ptr0, len0, ptr1, len1, ptr2, len2, n);
|
|
669
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
670
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
671
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
672
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
673
|
+
var ptr4 = r0;
|
|
674
|
+
var len4 = r1;
|
|
675
|
+
if (r3) {
|
|
676
|
+
ptr4 = 0;
|
|
677
|
+
len4 = 0;
|
|
678
|
+
throw takeObject(r2);
|
|
679
|
+
}
|
|
680
|
+
deferred5_0 = ptr4;
|
|
681
|
+
deferred5_1 = len4;
|
|
682
|
+
return getStringFromWasm0(ptr4, len4);
|
|
683
|
+
} finally {
|
|
684
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
685
|
+
wasm.__wbindgen_export2(deferred5_0, deferred5_1, 1);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
376
688
|
function wasm_unwrap_file_key(packed_envelope, seal_key, seal_id, file_id) {
|
|
377
689
|
try {
|
|
378
690
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -572,6 +884,9 @@ function __wbg_get_imports() {
|
|
|
572
884
|
"./seal_crypto_bg.js": import0
|
|
573
885
|
};
|
|
574
886
|
}
|
|
887
|
+
var ContractTermsBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
888
|
+
}, unregister: () => {
|
|
889
|
+
} } : new FinalizationRegistry((ptr) => wasm.__wbg_contracttermsbuilder_free(ptr, 1));
|
|
575
890
|
var WasmIdentityFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
576
891
|
}, unregister: () => {
|
|
577
892
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_wasmidentity_free(ptr, 1));
|
|
@@ -780,9 +1095,12 @@ function configureWasm(next) {
|
|
|
780
1095
|
}
|
|
781
1096
|
source = next;
|
|
782
1097
|
}
|
|
1098
|
+
function isWorker() {
|
|
1099
|
+
return globalThis.navigator?.userAgent === "Cloudflare-Workers";
|
|
1100
|
+
}
|
|
783
1101
|
function isNode() {
|
|
784
1102
|
const p = globalThis.process;
|
|
785
|
-
return typeof p?.versions?.node === "string";
|
|
1103
|
+
return typeof p?.versions?.node === "string" && !isWorker();
|
|
786
1104
|
}
|
|
787
1105
|
async function readNodeFile(path) {
|
|
788
1106
|
const fsModule = "node:fs/promises";
|
|
@@ -794,6 +1112,9 @@ async function readNodeFile(path) {
|
|
|
794
1112
|
return readFile(path);
|
|
795
1113
|
}
|
|
796
1114
|
async function wasmInput() {
|
|
1115
|
+
if (source && "module" in source) {
|
|
1116
|
+
return source.module;
|
|
1117
|
+
}
|
|
797
1118
|
if (source && "url" in source) {
|
|
798
1119
|
return fetch(source.url, source.integrity ? { integrity: source.integrity } : {});
|
|
799
1120
|
}
|
|
@@ -804,7 +1125,7 @@ async function wasmInput() {
|
|
|
804
1125
|
return readNodeFile(new URL(WASM_FILE, import.meta.url));
|
|
805
1126
|
}
|
|
806
1127
|
throw new Error(
|
|
807
|
-
"sealnet: no WASM source in this browser (a broken build — reinstall sealnet)"
|
|
1128
|
+
isWorker() ? "seal crypto core: a Worker compiles no WASM from bytes \u2014 call configureWasm({ module }) with the imported .wasm" : "sealnet: no WASM source in this browser (a broken build — reinstall sealnet)"
|
|
808
1129
|
);
|
|
809
1130
|
}
|
|
810
1131
|
async function ensureWasm() {
|
|
@@ -826,18 +1147,6 @@ async function ensureWasm() {
|
|
|
826
1147
|
throw error;
|
|
827
1148
|
}
|
|
828
1149
|
}
|
|
829
|
-
async function sha256(data) {
|
|
830
|
-
const buffer = data.buffer.slice(
|
|
831
|
-
data.byteOffset,
|
|
832
|
-
data.byteOffset + data.byteLength
|
|
833
|
-
);
|
|
834
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", buffer);
|
|
835
|
-
return new Uint8Array(hashBuffer);
|
|
836
|
-
}
|
|
837
|
-
async function sha256Hex(data) {
|
|
838
|
-
const hashBytes = await sha256(data);
|
|
839
|
-
return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
840
|
-
}
|
|
841
1150
|
var BASE64_CHUNK_SIZE = 32768;
|
|
842
1151
|
var Base64DecodeError = class extends Error {
|
|
843
1152
|
constructor(message, input) {
|
|
@@ -862,7 +1171,7 @@ function binaryStringToBytes(binary) {
|
|
|
862
1171
|
return bytes;
|
|
863
1172
|
}
|
|
864
1173
|
function safeAtob(base64) {
|
|
865
|
-
const preview = base64.
|
|
1174
|
+
const preview = `${base64.length} characters`;
|
|
866
1175
|
if (typeof atob !== "undefined") {
|
|
867
1176
|
try {
|
|
868
1177
|
return atob(base64);
|
|
@@ -903,6 +1212,18 @@ function base64ToBytes(base64) {
|
|
|
903
1212
|
function base64urlToBytes(base64url) {
|
|
904
1213
|
return base64ToBytes(base64urlToBase64(base64url));
|
|
905
1214
|
}
|
|
1215
|
+
async function sha256(data) {
|
|
1216
|
+
const buffer = data.buffer.slice(
|
|
1217
|
+
data.byteOffset,
|
|
1218
|
+
data.byteOffset + data.byteLength
|
|
1219
|
+
);
|
|
1220
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", buffer);
|
|
1221
|
+
return new Uint8Array(hashBuffer);
|
|
1222
|
+
}
|
|
1223
|
+
async function sha256Hex(data) {
|
|
1224
|
+
const hashBytes = await sha256(data);
|
|
1225
|
+
return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1226
|
+
}
|
|
906
1227
|
|
|
907
1228
|
import { sha256 as sha2562 } from "@noble/hashes/sha2";
|
|
908
1229
|
import { Zip, ZipPassThrough } from "fflate";
|
|
@@ -950,8 +1271,8 @@ var FILE_ID = aeon_format_default.header_layout.find((field) => field.name === "
|
|
|
950
1271
|
var AAD_LENGTH = aeon_format_default.aad_layout.reduce((sum, field) => sum + field.length, 0);
|
|
951
1272
|
var V3_MAGIC = new Uint8Array(aeon_format_default.v3_reader.magic_bytes);
|
|
952
1273
|
var V3_HEADER_LENGTH = aeon_format_default.v3_reader.header_length;
|
|
953
|
-
function encryptedSegmentSize(
|
|
954
|
-
return NONCE_LENGTH +
|
|
1274
|
+
function encryptedSegmentSize(plaintextSize2) {
|
|
1275
|
+
return NONCE_LENGTH + plaintextSize2 + TAG_LENGTH;
|
|
955
1276
|
}
|
|
956
1277
|
function ciphertextSize(plaintextLen) {
|
|
957
1278
|
const segments = Math.max(1, Math.ceil(plaintextLen / SEGMENT_SIZE));
|
|
@@ -1004,7 +1325,12 @@ function toArrayBuffer(bytes) {
|
|
|
1004
1325
|
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
1005
1326
|
}
|
|
1006
1327
|
function importSegmentKey(key2) {
|
|
1007
|
-
|
|
1328
|
+
const copy = toArrayBuffer(key2);
|
|
1329
|
+
try {
|
|
1330
|
+
return crypto.subtle.importKey("raw", copy, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
1331
|
+
} finally {
|
|
1332
|
+
new Uint8Array(copy).fill(0);
|
|
1333
|
+
}
|
|
1008
1334
|
}
|
|
1009
1335
|
async function encryptSegment(key2, plaintext, aad) {
|
|
1010
1336
|
const nonce = crypto.getRandomValues(new Uint8Array(NONCE_LENGTH));
|
|
@@ -1094,7 +1420,7 @@ var limits_default = {
|
|
|
1094
1420
|
description: "One-time payment for 500 GB storage and 12 months TTL"
|
|
1095
1421
|
}
|
|
1096
1422
|
},
|
|
1097
|
-
PRO_REGIONS: ["eu-west", "us-east", "us-west", "apac-southeast", "apac-northeast"],
|
|
1423
|
+
PRO_REGIONS: ["eu-west", "eu-central", "us-east", "us-west", "apac-southeast", "apac-northeast"],
|
|
1098
1424
|
ttl_options: ["5m", "30m", "1h", "1d", "7d"],
|
|
1099
1425
|
OTP_LENGTH: { min: 6, max: 10 },
|
|
1100
1426
|
USER_PASSWORD_MIN_LENGTH: 8,
|
|
@@ -1104,6 +1430,13 @@ var limits_default = {
|
|
|
1104
1430
|
PAYMENT_WAIT_MAX_SECONDS: 82800,
|
|
1105
1431
|
ADDRESS_PROOF_TTL_SECONDS: 300,
|
|
1106
1432
|
INBOX_MAX_ITEMS: 200,
|
|
1433
|
+
LEASE_DEFAULT_DAYS: 7,
|
|
1434
|
+
LEASE_MAX_DAYS: 90,
|
|
1435
|
+
LEASE_STATUS_BATCH_MAX: 500,
|
|
1436
|
+
LEASE_POLL_SECONDS: 600,
|
|
1437
|
+
LEASE_KEEP_DAYS: 30,
|
|
1438
|
+
APPROVE_WAIT_SECONDS: 120,
|
|
1439
|
+
APPROVE_BODY_SHOWN_BYTES: 2048,
|
|
1107
1440
|
DRIVE_OPEN_TTL_SECONDS: 300,
|
|
1108
1441
|
DRIVE_PRESIGN_WINDOW_DEFAULT_BYTES: 67108864,
|
|
1109
1442
|
DRIVE_PRESIGN_WINDOW_MIN_BYTES: 8388608,
|
|
@@ -1122,26 +1455,217 @@ var limits_default = {
|
|
|
1122
1455
|
SENSOR_GROWTH_BYTES_PER_DAY_DEFAULT: 107374182400
|
|
1123
1456
|
}
|
|
1124
1457
|
};
|
|
1125
|
-
var
|
|
1126
|
-
version:
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1458
|
+
var crypto_default = {
|
|
1459
|
+
version: 1,
|
|
1460
|
+
default_aead: "aes_256_gcm",
|
|
1461
|
+
aes_gcm: {
|
|
1462
|
+
key_length_bytes: 32,
|
|
1463
|
+
nonce_length_bytes: 12,
|
|
1464
|
+
tag_length_bytes: 16
|
|
1465
|
+
},
|
|
1466
|
+
sha256: {
|
|
1467
|
+
output_length_bytes: 32,
|
|
1468
|
+
hex_string_length: 64
|
|
1469
|
+
},
|
|
1470
|
+
owner_token_bytes: 32,
|
|
1471
|
+
link_key_bytes: 32,
|
|
1472
|
+
metadata_aad_prefix: "field:",
|
|
1473
|
+
keybundle: {
|
|
1474
|
+
signature_prefix: "seal:keybundle:",
|
|
1475
|
+
signed_bundle_version: 2,
|
|
1476
|
+
v2_fields: ["identity_ed25519_pub", "agreement_x25519_pub", "kem_mlkem768_pub"],
|
|
1477
|
+
packed_length: 1316,
|
|
1478
|
+
address: {
|
|
1479
|
+
of: "sha256(identity_ed25519_pub), 32 bytes",
|
|
1480
|
+
text: "base64url without padding, 43 characters",
|
|
1481
|
+
words: "fingerprint_words.json over its first eight bytes"
|
|
1482
|
+
}
|
|
1483
|
+
},
|
|
1484
|
+
hkdf: {
|
|
1485
|
+
wrap_key_salt: "seal:wrapkey:v1",
|
|
1486
|
+
wrap_key_salt_v2: "seal:wrapkey:v2",
|
|
1487
|
+
identity_key_salt: "seal:key-derivation:v1",
|
|
1488
|
+
file_envelope_salt: "seal:file-envelope:v1",
|
|
1489
|
+
info_prefixes: {
|
|
1490
|
+
wrap: "WRAP",
|
|
1491
|
+
agreement: "AGRE",
|
|
1492
|
+
identity: "IDEN",
|
|
1493
|
+
workload_identity: "seal:workload-identity:v1",
|
|
1494
|
+
share_proof: "seal:share-proof:v1",
|
|
1495
|
+
kem_mlkem768: "seal:kem-mlkem768:v1"
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
share_link: {
|
|
1499
|
+
proof_of: "the proof of a share link's key (AUDIT K237): HKDF-SHA256(ikm = the link's 32-byte key, salt = hkdf.identity_key_salt, info = hkdf.info_prefixes.share_proof, 32 bytes), base64url; its maker gives the server proof_hash = SHA-256 hex of those bytes, an opener sends the proof in proof_header",
|
|
1500
|
+
proof_header: "X-Share-Proof",
|
|
1501
|
+
proof_vector: { link_key: "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8", proof: "xYwpyfG6o6iW43T5O7W9Av5bVZJc5MpUhcmPa6SxQy8", proof_hash: "75d668b6b3295aad0b8e3f83eb9d03181a9c81f92836105077023bf3bea0aa4a" }
|
|
1502
|
+
},
|
|
1503
|
+
xwing: { label_hex: "5c2e2f2f5e5c" },
|
|
1504
|
+
sealed_box_v2: {
|
|
1505
|
+
version_byte: 2,
|
|
1506
|
+
packed_layout: [
|
|
1507
|
+
{ name: "version", offset: 0, length: 1 },
|
|
1508
|
+
{ name: "eph_pub", offset: 1, length: 32 },
|
|
1509
|
+
{ name: "kem_ct", offset: 33, length: 1088 },
|
|
1510
|
+
{ name: "nonce", offset: 1121, length: 12 },
|
|
1511
|
+
{ name: "ct", offset: 1133, length: 48 }
|
|
1512
|
+
],
|
|
1513
|
+
packed_length: 1181,
|
|
1514
|
+
packed_b64_length: 1575
|
|
1515
|
+
},
|
|
1516
|
+
secret_scope_aad: "secret:{secret_id}",
|
|
1517
|
+
scope_metadata_aad: {
|
|
1518
|
+
is: "What a sealed text of a scope's metadata is bound to: the AAD of its AES-256-GCM (SEAL Pro, AUDIT K140, SPEC-NAMES-BOUND). A room's name and description are bound to the room. A text under the organization's key and the name of a seal's folder are bound to their own object: its id stands in the AAD, so two of them cannot be swapped unnoticed. The binding before that named the kind and the organization (the seal) only; a row says which one its text has by `encryption_version`, a seal's folder has no such mark and is read bound first, then as before.",
|
|
1519
|
+
room: "room:{room_id}:{field}",
|
|
1520
|
+
org_object: {
|
|
1521
|
+
bound: "{kind}:{org_id}:{object_id}:{field}",
|
|
1522
|
+
before: "{kind}:{org_id}:{field}",
|
|
1523
|
+
kinds: [
|
|
1524
|
+
"secret",
|
|
1525
|
+
"sign-policy",
|
|
1526
|
+
"sign-template",
|
|
1527
|
+
"sign-template-body",
|
|
1528
|
+
"sign-template-meta",
|
|
1529
|
+
"sign-folder",
|
|
1530
|
+
"sign-request-meta",
|
|
1531
|
+
"sign-field-value"
|
|
1532
|
+
],
|
|
1533
|
+
field: "name",
|
|
1534
|
+
object: "the row the text belongs to: the secret, the policy, the template (its name, text and terms alike), the contract folder, the sign request, the signature field of a drawing"
|
|
1535
|
+
},
|
|
1536
|
+
folder: {
|
|
1537
|
+
bound: "seal:{seal_id}:{folder_id}:name",
|
|
1538
|
+
before: "seal:{seal_id}:name"
|
|
1539
|
+
},
|
|
1540
|
+
versions: {
|
|
1541
|
+
before: 3,
|
|
1542
|
+
bound: 5,
|
|
1543
|
+
note: "4 is a file's format version (seal_files) and names no metadata"
|
|
1544
|
+
},
|
|
1545
|
+
vectors: {
|
|
1546
|
+
key_hex: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
|
|
1547
|
+
nonce_b64: "ZGVmZ2hpamtsbW5v",
|
|
1548
|
+
org_object: {
|
|
1549
|
+
kind: "secret",
|
|
1550
|
+
org_id: "0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e",
|
|
1551
|
+
object_id: "7a1d2c3b-4e5f-4a6b-8c7d-9e0f1a2b3c4d",
|
|
1552
|
+
other_object_id: "11111111-2222-4333-8444-555555555555",
|
|
1553
|
+
text: "prod-db",
|
|
1554
|
+
bound_aad: "secret:0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e:7a1d2c3b-4e5f-4a6b-8c7d-9e0f1a2b3c4d:name",
|
|
1555
|
+
bound_b64: "OGmxAlSNNC/EcAW6hlU6eU73XrC7Vaw=",
|
|
1556
|
+
before_aad: "secret:0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e:name",
|
|
1557
|
+
before_b64: "OGmxAlSNNBiKlnxW4fkbPMjFoZGJJDY="
|
|
1558
|
+
},
|
|
1559
|
+
folder: {
|
|
1560
|
+
seal_id: "AbCd1234",
|
|
1561
|
+
folder_id: "c0ffee00-1234-4abc-8def-0123456789ab",
|
|
1562
|
+
other_folder_id: "11111111-2222-4333-8444-555555555555",
|
|
1563
|
+
text: "\u0414\u043E\u0433\u043E\u0432\u043E\u0440\u044B 2026",
|
|
1564
|
+
bound_aad: "seal:AbCd1234:c0ffee00-1234-4abc-8def-0123456789ab:name",
|
|
1565
|
+
bound_b64: "mI8O2KlahiDu0I9WC+W7dmLwNji94CvUmMxJnLVFN5EChD6uMg==",
|
|
1566
|
+
before_aad: "seal:AbCd1234:name",
|
|
1567
|
+
before_b64: "mI8O2KlahiDu0I9WC+W7dmLwNji9ni0vIvgReyNDk0uY98XR7Q=="
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
},
|
|
1571
|
+
sign: {
|
|
1572
|
+
message_prefix: "aeon:sign:v1",
|
|
1573
|
+
message_format: "aeon:sign:v1|org:{org_id}|req:{request_id}|doc_hash:{doc_hash_hex}",
|
|
1574
|
+
message_prefix_v2: "aeon:sign:v2",
|
|
1575
|
+
message_format_v2: "aeon:sign:v2|org:{org_id}|req:{request_id}|doc_hash:{doc_hash_hex}|terms:{terms_hex}",
|
|
1576
|
+
terms_label: "aeon:terms:v1",
|
|
1577
|
+
terms_of: "what the signer was shown (AUDIT K204): SHA-256 hex of the lines the core builds (shared/core/src/contract_terms.rs) \u2014 for a member of the organization or its agent from the metadata ciphertext and the whole field layout, for an outside signer from their own fields alone and no metadata \u2014 and the signer's own filled fields",
|
|
1578
|
+
terms_vector: {
|
|
1579
|
+
org_id: "0d0f2a1e-5b7c-4c1d-9e3a-2f6b8c4d1a70",
|
|
1580
|
+
request_id: "7a1c3e5b-9d2f-4b6a-8c0e-1f3a5b7d9c2e",
|
|
1581
|
+
doc_hash: "cb99e3fc33b873e56252762ef641f21153fb14f66fb1d8bbf82d2033dcb31d33",
|
|
1582
|
+
meta: "bWV0YS1jaXBoZXJ0ZXh0",
|
|
1583
|
+
fields: [
|
|
1584
|
+
{
|
|
1585
|
+
id: "b2f1c3d4-0000-4000-8000-000000000002",
|
|
1586
|
+
type: "signature",
|
|
1587
|
+
page: 2,
|
|
1588
|
+
x: 0.615,
|
|
1589
|
+
y: 0.8125,
|
|
1590
|
+
w: 0.3,
|
|
1591
|
+
h: 0.075,
|
|
1592
|
+
assignee_type: "email",
|
|
1593
|
+
assignee: "ann|example@example.com",
|
|
1594
|
+
required: true
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
id: "a1e0b2c3-0000-4000-8000-000000000001",
|
|
1598
|
+
type: "signature",
|
|
1599
|
+
page: 1,
|
|
1600
|
+
x: 0.1,
|
|
1601
|
+
y: 0.7,
|
|
1602
|
+
w: 0.3,
|
|
1603
|
+
h: 0.075,
|
|
1604
|
+
assignee_type: "user",
|
|
1605
|
+
assignee: "5c9e7a3b-1d2f-4a6b-8c0d-2e4f6a8b0c1d",
|
|
1606
|
+
required: true
|
|
1607
|
+
}
|
|
1608
|
+
],
|
|
1609
|
+
filled: [
|
|
1610
|
+
{
|
|
1611
|
+
field_id: "a1e0b2c3-0000-4000-8000-000000000001",
|
|
1612
|
+
sha256: "bde5c9647a96e96c78ea116eaa7a653b2347cd83855d223b30984f235151f813"
|
|
1613
|
+
}
|
|
1614
|
+
],
|
|
1615
|
+
terms: "a38d4d567232eb54cb8c2276988b1a4d0b31dc763b6dadcc6b33909d1b844f30",
|
|
1616
|
+
message: "aeon:sign:v2|org:0d0f2a1e-5b7c-4c1d-9e3a-2f6b8c4d1a70|req:7a1c3e5b-9d2f-4b6a-8c0e-1f3a5b7d9c2e|doc_hash:cb99e3fc33b873e56252762ef641f21153fb14f66fb1d8bbf82d2033dcb31d33|terms:a38d4d567232eb54cb8c2276988b1a4d0b31dc763b6dadcc6b33909d1b844f30"
|
|
1617
|
+
}
|
|
1618
|
+
},
|
|
1619
|
+
sign_doc_hash_of: "sha256(plaintext) of the exact seal_files row in doc_ref",
|
|
1620
|
+
recovery_phrase: {
|
|
1621
|
+
seed: `BIP39: PBKDF2-HMAC-SHA512 of the phrase after trim, lower case and NFKD, salt "mnemonic", 2048 iterations, 64 bytes; the web's recoveryPhrase.ts phraseToMasterSeed and the core's hkdf::master_seed_from_phrase (\u04145 \xA73.2)`,
|
|
1622
|
+
vector: {
|
|
1623
|
+
phrase: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art",
|
|
1624
|
+
typed: " Abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon ART\n",
|
|
1625
|
+
seed_hex: "408b285c123836004f4b8842c89324c1f01382450c0d439af345ba7fc49acf705489c6fc77dbd4e3dc1dd8cc6bc9f043db8ada1e243c4a0eafb290d399480840"
|
|
1626
|
+
}
|
|
1627
|
+
},
|
|
1628
|
+
device_link: {
|
|
1629
|
+
record: "a person's seed64, base64url, sealed by the browser to the one-time bundle of sealfs login: sealReply(seed64, bundle, scope, code) of the protocol's identity module \u2014 box (sealed_box_v2) \u2016 nonce(12) \u2016 AES-256-GCM of the record under the box's key; the daemon opens it with its one-time identity (\u04145 \xA73.2 \u043F. 2, D119)",
|
|
1630
|
+
scope: "device",
|
|
1631
|
+
vector: {
|
|
1632
|
+
daemon_seed64_hex: "01080f161d242b323940474e555c636a71787f868d949ba2a9b0b7bec5ccd3dae1e8eff6fd040b121920272e353c434a51585f666d747b828990979ea5acb3ba",
|
|
1633
|
+
code: "K7M2Q9XA",
|
|
1634
|
+
seed64_hex: "030a11181f262d343b424950575e656c737a81888f969da4abb2b9c0c7ced5dce3eaf1f8ff060d141b222930373e454c535a61686f767d848b9299a0a7aeb5bc",
|
|
1635
|
+
record: "AlbSFUYf2V9yux_9DyViIEw_gXJcdITRt0kFjJC9XAJTOCRSKh3_hDCGxBSS5idHldzc_qQOtd43_GYaZQm9_VH90eY2JDP_A2T4I8W_qPPfS4MlLGtBp0kkShY_PnspF6bELAbft3XNkEuwQpfynXH2OFFvAPwJFKceua18YAywNbq84plsv8n3C5lRmeITyeFwKlxDW3-6q-2NHlAgkSrScie1B63CQu3D0U3SRWcOHMvwnl9Topwe1J2iu4EpOUlJRZQsgfBR4LhyywAWam0R3VHa_pXjCtN4Of-JRyO3Jub-6MgDXpoGsQuD9V1XszngRZkwz0R_4xqSlabtA-GMiCJyhff7HBp3t0XHeaS04cNdtATfwce_FUL3IL-z0YAQh-JSzKz_VeVq8iFSZcbHnx2Eab3ND4YuwvJxfJJ8jGquahnhndiI6qxZtK7OmQsy8ZBQ_p4Gi8v1ziN74OMdQG9UtqR9igeJohiMos5tHpveIXQ9luWiQ9gk22p53yGzP8hH_mv508tb4KsveNjssXS0hVmLl4c7fqQbrBjKvNauuEbzNd1gimV4I_f-N0FN2c7Pe7sTZevR5dnIGrAF_31cxFTOWVjZdKsyEWUiwSHrG2dQBccO2AB6TurTsqr4hBP64c3WkUW1vJVXKEOCKxBIwMa7XyyLw4La5tZue0Ls2cHzfy2Kd5jKCo3UIQrjvNWOvXFDRlkTx10UMFpZNvmnITHVh6rHkr5_tGFVMwqU2arRmwQBWCBYsDhN1NVJ8cEwEb0lNHfuotqf54IZUP25JwqpqSkSadjHdVHZdJ50MQUiNiumm0e-kbLDfWHds9dkGhwVgqha3s-svngKweowybgYAnRIDYeHHkSN-9Bm2jNmidilQhTiY6eLmnxg81sdESUNrjk1nhNJdiTaDAeX-CL5DJxPVirKFWYgrBpvJ7ocpxg9Idqsdm8fIzZi-MAQyq_I1y2RcsUqZEwFFeHqwPZdUce1PxVBjFn27cfKzyifotbTBumodLXMRnrrhfQ2i6cHAt9utI2X_WJuGxDRfYICuKdQHt3NPswIwLxSxgNUvpani5DzhYA5FnC-zfh_LWXyJnyfJx1Yr-07_ICpIP85fwzO7FAVZxpdpsL8wk19HhW63LAOVcQxANLcIue7hp1vU6QU1Co0H4yGJgmehDEBYWFJCpaDk8_srkw42Y9eZn6SNoIekuz-BNgjnnB0WB2mh-k3vux92C-_2o8GsSeENNvOOTRwLOLAB4PCi-Uf__oonrLR0kBdE2gbrVjb6sttEx8Df_S7YuTCytpw13ABaXCcJRsPfR6os2KuM1Rv53CH5SZ2NpKgdFlBmva9gIsMSJxAh08UtLGNhKrli3uUW1KER7Ng92RDDV-HHUqNyOhkPPD4KteeZHX0m9h8POVCjXr0TNHSisQK_CPFMMOhUc2DmEHDOZO9piI5uMAznMdzrR-qFbhPNN9ugUUSIdDnVS9Mc2INiUIKjnLWB37_wYTSpXRCS5bSfohMPyNu0dTuAJuHLNfK1hA9XOGhvZLFW9rgXN8bYdAmUL0TrJJ4DYBWrpzXuzaiXEf2peRi0z6LYiXWyjvmIaQfvttTgWSymbREbJmanBDfTUPR5XPFQHZ-n_876ODCoJAXnqOkSSWEHKf885bOre3IkJIS_2jH9_MJzG0Fsmnvj8VYHECIrZlRFdsqzMQ9MIIIIWg0bfHvAn5R06o"
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
var seal_address_default = {
|
|
1640
|
+
version: 2,
|
|
1641
|
+
$comment: "Address of a bundle: who a seal is for, without a URL (SPEC-AEON-V4 \xA75). Numbers live in limits.json, error codes in error_codes.json, the bundle and the wrap in crypto.json (keybundle, sealed_box_v2).",
|
|
1642
|
+
address: {
|
|
1643
|
+
of: "SHA-256 of the identity key (Ed25519) of the bundle v2, 32 bytes",
|
|
1644
|
+
text: "base64url without padding, 43 characters",
|
|
1645
|
+
words: "fingerprint_words.json over the first eight bytes of the address: the words of SHA-256(identity key), named without hashing again",
|
|
1646
|
+
inbox: "the 32 bytes of the address are the key the server finds an inbox by"
|
|
1647
|
+
},
|
|
1648
|
+
box_origin: "https://box.seal.net",
|
|
1649
|
+
seed: {
|
|
1650
|
+
env: "SEAL_SEED",
|
|
1651
|
+
text: "base64url without padding of the 64-byte seed of an agent, a device or an inbox, 86 characters",
|
|
1652
|
+
derives: "all three keys of the bundle v2 the address names are HKDF-SHA256 of the seed under crypto.json hkdf.identity_key_salt, each under its own info: hkdf.info_prefixes identity (Ed25519), agreement (X25519) and kem_mlkem768 (d \u2016 z of ML-KEM-768), followed by key_version as four bytes, little-endian \u2014 the core's Identity::from_seed. No public key of the bundle is the seed",
|
|
1653
|
+
key_version: 1,
|
|
1654
|
+
same_as: [
|
|
1655
|
+
"sealnet-mcp state.identity.seed_b64",
|
|
1656
|
+
"seal identity.v1.json seed_b64url",
|
|
1657
|
+
"sealnet (npm) KeyPair.secretKey",
|
|
1143
1658
|
"sealnet (PyPI) keygen().secret_key"
|
|
1144
|
-
]
|
|
1659
|
+
],
|
|
1660
|
+
root: "SPEC-SEED-ROOT: the one kind of seed. A seed of 32 bytes (43 characters) is a key of the kind before: a holder that keeps its seed itself reads it as its previous key (below) until that expires, and nothing makes it or takes it as a seed \u2014 SEAL_SEED, an inbox key file, a device transfer and an SDK key of that length are refused in words that say how to make a new one.",
|
|
1661
|
+
vector: {
|
|
1662
|
+
comment: "the seed of the vector `sealed-box-v2-person` of xwing_test_vectors.json (seed64_hex; its bundle, address and words are there) signs the challenge of ts into this proof \u2014 Identity::from_seed, Identity::inbox_proof; Ed25519 is deterministic, every client reproduces it",
|
|
1663
|
+
of: "sealed-box-v2-person",
|
|
1664
|
+
ts: 179e7,
|
|
1665
|
+
challenge: "wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t8",
|
|
1666
|
+
proof: "1790000000.wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t8.1VKxaNHrNu5Is9gYxMur7mAABL8Pn0Lcz6vpw5JDmUI65epcxGCMUOGcJK-lneqALDx0EHlBHbhmUIHWPCCDCQ"
|
|
1667
|
+
},
|
|
1668
|
+
previous: "the seed a holder had before it replaced its key, 32 or 64 bytes, kept beside the current one where the holder keeps its seed itself (an inbox, a device's identity file, the MCP server's state): it opens what the server still holds at the old address and is erased when the last of that has expired \u2014 seven days from the replacement (limits.json ttl_options, the longest free seal), longer while the inbox shows a live row at the old address"
|
|
1145
1669
|
},
|
|
1146
1670
|
bundles: {
|
|
1147
1671
|
put: "PUT /intake/bundles {bundle}: bundle is base64url of the packed bundle (crypto.json keybundle.packed_length). The server verifies it with the core and files it under the address it computes; no authorization \u2014 the bundle proves itself \u2014 and a limit per IP",
|
|
@@ -1176,14 +1700,20 @@ var seal_address_default = {
|
|
|
1176
1700
|
listing: "GET /intake?to= lists deliveries only, as before owner copies and cards existed; `all=1` adds owner and request items (a person's inbox). Agent clients never send it: those rows are a person's."
|
|
1177
1701
|
},
|
|
1178
1702
|
request: {
|
|
1179
|
-
recipient_bundle: "POST /intake carries recipient_bundle, base64url of the requester's packed bundle; the page verifies it and shows the
|
|
1703
|
+
recipient_bundle: "POST /intake carries recipient_bundle, base64url of the requester's packed bundle; the page verifies it and shows the eight words of its address, the answer's key is wrapped to it (scope share_link) and comes back as the request's fragment, with share_path without a fragment"
|
|
1180
1704
|
},
|
|
1181
1705
|
owner_copy: {
|
|
1182
1706
|
web_label: "seal.net",
|
|
1183
1707
|
is: "The seal names the inbox that manages it: its row carries the owner-blob key wrapped to that address's bundle, one per seal, written with the owner blob (PATCH /seal/{id}/blob with to, fragment, label) before the first byte of the files. Best effort: an address without a bundle is the same PATCH without the address part, and the seal is made anyway."
|
|
1184
1708
|
},
|
|
1185
|
-
request_kinds: ["secret", "file", "any", "pair", "device"],
|
|
1709
|
+
request_kinds: ["secret", "file", "any", "pair", "device", "guard"],
|
|
1186
1710
|
pair_what: "inbox",
|
|
1711
|
+
guard: {
|
|
1712
|
+
kind: "guard",
|
|
1713
|
+
is: "a pair request whose requester is this machine's guard (SPEC agent egress \xA73.1): the same answer as `pair` (the pairing file), and the inbox marks the agent as a guard. A request for a secret whose recipient_bundle is a guard's is shown by the inbox as sealed to that guard; one whose bundle is no known guard's is answered only after the person types its eight words (\xA76.1, T2\u0430).",
|
|
1714
|
+
gateway: "SPEC agent egress \xA77.2, level \u0412: `seal guard expose --listen <address:port> [--as <host:port>]` makes a guard the owner's gateway \u2014 `POST https://<host:port>/v1/forward` over mTLS, both certificates made from the guards' Ed25519 identity keys and checked against the published bundles of their addresses (the client names its address in `x-seal-address`, the server is the `gateway.guard` of the binding). `seal guard lend <key> --to <address>` lends a key as use: the borrower's guard receives a handle under a binding with `gateway: {at, guard}` (owner_blob_payload.v1.json bindings) and sends the request with `x-seal-method` and `x-seal-url` (the host's URL) to the gateway, which puts the value in and answers with the host's answer. The gateway not reachable: 502 `{error: seal_guard.gateway, reason: gateway_offline}`.",
|
|
1715
|
+
bind: "POST /intake may carry `bind`: what the agent proposes the key be bound to \u2014 {hosts: [<host>], place?: <place>, class?: outbound|inprocess} (secrets.json guard_note). `bind` is sent only when the recipient_bundle is a guard's, hosts proposed or not: its presence is what lets the page bind the key and lend it under a lease; without it the page says the value goes to the agent as it is. The page shows the proposal as the binding when no entry of secrets.json knows the key's form; the person confirms, narrows or removes it. At most 16 hosts of 253 characters, each a name of two labels or more (`*.` with two labels under it, three under secrets.json wildcard_public_second_level); the server checks the shape and keeps it as given."
|
|
1716
|
+
},
|
|
1187
1717
|
payloads: {
|
|
1188
1718
|
name_max: 80,
|
|
1189
1719
|
pair: {
|
|
@@ -1192,19 +1722,43 @@ var seal_address_default = {
|
|
|
1192
1722
|
},
|
|
1193
1723
|
device: {
|
|
1194
1724
|
mime: "application/vnd.seal.device+json",
|
|
1195
|
-
json: '{"v":2,"seed":"<inbox seed,
|
|
1725
|
+
json: '{"v":2,"seed":"<inbox seed, 86>","name":"<inbox name>","agents":[{"address":"<43>","name":"<name>","paired_at":"<ISO 8601>","kind":"guard"?}]}',
|
|
1726
|
+
kind: "`guard` for an agent that is a machine's guard (request kind `guard`): it stays a guard on every device of the inbox and through a rename; a reader drops a kind it does not know (SPEC-APP r5 \u041425)"
|
|
1727
|
+
},
|
|
1728
|
+
approve: {
|
|
1729
|
+
mime: "application/vnd.seal.approve+json",
|
|
1730
|
+
json: '{"v":2,"ask":"<16 random bytes, base64url>","secret_id":"<k_\u2026>","secret":"<STRIPE_KEY>","guard":"<eight words of the guard>","host":"api.stripe.com","method":"POST","path":"/v1/refunds?expand=charge","at":"<ISO 8601>","until":"<ISO 8601>","body_bytes":24,"body":"charge=ch_1&amount=50000"?,"body_sha256":"<SHA-256 hex of the whole body>"?,"body_more":true?}',
|
|
1731
|
+
body: "What the call carries (AUDIT K152): `path` is the path with its query; `body_bytes` the bytes of the body the guard read; `body` its first `limits.json::APPROVE_BODY_SHOWN_BYTES` bytes when they are text, cut where a character ends, absent for an empty or a binary body; `body_sha256` the digest of the whole body, absent for an empty one and for one that streams on past what the guard reads whole, which `body_more` says. An agent's request holds surrogates, never a value. A reader takes a question without these fields (a guard before them) and shows what it has.",
|
|
1732
|
+
is: "A guard's question to a key's owner (SPEC agent egress \xA77.3, \u04214): a call the binding marks `approve: owner` waits for this answer. Sent as a seal addressed to the owner (30 minutes, one open), its share blob marked `payload: approve`; the inbox shows it as a card with Allow and Deny and pushes. Unanswered within `limits.json::APPROVE_WAIT_SECONDS` the call is refused (403 `approve`)."
|
|
1733
|
+
},
|
|
1734
|
+
approve_answer: {
|
|
1735
|
+
mime: "application/vnd.seal.approve-answer+json",
|
|
1736
|
+
json: `{"v":2,"ask":"<the ask>","decision":"allow"|"deny","at":"<ISO 8601>","signature":"<Ed25519 by the inbox's identity key over the core's approval message, base64url, 86>"}`,
|
|
1737
|
+
is: "The owner's answer (\xA77.3): a seal from the inbox to the guard's address (30 minutes, one open), blob `payload: approve_answer`; the guard checks the signature against the owner's bundle (the `owner` of the binding). `allow` is for the one call the question was about (AUDIT K152): the same call again is another question."
|
|
1738
|
+
},
|
|
1739
|
+
summary: {
|
|
1740
|
+
mime: "application/vnd.seal.summary+json",
|
|
1741
|
+
json: `{"v":2,"secret_id":"<k_\u2026>","secret":"<STRIPE_KEY>","day":"<YYYY-MM-DD, UTC>","counts":[{"method":"GET","path":"/v1/charges/*","status":200,"n":40}],"approved":2,"refused":1,"root":"<SHA-256 hex, the chain's last link>","n":43,"signature":"<Ed25519 by the guard's identity key over the core's summary message, base64url, 86>"}`,
|
|
1742
|
+
is: "A guard's daily summary of one lent key to its owner (\xA77.4, \u04213): once a day by UTC and on a revoke, a seal addressed to the owner (7 days, one open), blob `payload: summary`. The inbox checks the signature against the guard's bundle (the item's sender), keeps the summary in its own storage (the carrier expires) and shows the journal under the lease. Attested by the guard that wrote the receipts: honest of an honest guard."
|
|
1743
|
+
},
|
|
1744
|
+
blob_payload: "A seal a machine makes for another machine or for an inbox carries the kind of its file in the share blob's `payload` (`approve`, `approve_answer`, `summary`, `delivery`), under the link key: the inbox reads the blob of every delivery and downloads only the files of these kinds; the server sees one more addressed seal. Readers tolerate a blob without the field.",
|
|
1745
|
+
delivery: {
|
|
1746
|
+
mime: "application/vnd.seal.delivery+json",
|
|
1747
|
+
json: `{"v":2,"name":"<the binding's name, STRIPE_KEY>","level":"A"|"B"|"0","at":"<ISO 8601>"}`,
|
|
1748
|
+
is: "The receipt of a lent key's arrival (SPEC agent egress \xA76.2, T17): whoever opens a secret whose binding names an `owner` sends this file, as a seal addressed to that owner (7d, one open), the moment the secret is opened. `A` or `B`: the opener's guard holds the key and the agent got a surrogate \u2014 the level is the one that guard names in its `status` (SPEC-APP r4 \u042038: `A` its key in a file of the user, `B` in the protected keychain of the SEAL app); `0`: the opener holds the value itself, the second level. The level travels inside the ciphertext; the server sees one more addressed seal. No receipt when the binding has no owner, or the owner is the opener itself."
|
|
1196
1749
|
}
|
|
1197
1750
|
},
|
|
1198
1751
|
device_link: {
|
|
1199
|
-
code: "
|
|
1752
|
+
code: "16 Crockford base32 characters from 10 random bytes (80 bits): the server sees the what beside the device's address, so the code must not be searchable from them (SPEC-r4 \u041A-4, AUDIT wpkg03.3)",
|
|
1200
1753
|
what: "base64url(HMAC-SHA256(key = the code in ASCII, message = the 32-byte address of the new device)), 43 characters: the what of the device request",
|
|
1201
1754
|
link: "https://box.seal.net/#link=<address>.<code>"
|
|
1202
1755
|
},
|
|
1203
1756
|
bridge: {
|
|
1204
1757
|
path: "/bridge",
|
|
1205
|
-
is: "A hidden iframe of box_origin on seal.net; postMessage only between the two origins. It never gives out the address or the name: it answers any script of seal.net.",
|
|
1758
|
+
is: "A hidden iframe of box_origin on seal.net; postMessage only between the two origins. It never gives out the address or the name for the asking: it answers any script of seal.net. The address goes back only with a lease the inbox kept (box.lease), to be sealed into the key's binding as its owner.",
|
|
1206
1759
|
hello: "box.hello {sealId?} -> {box: boolean, has: boolean}; box: this device has an inbox; has: this seal is already in Yours",
|
|
1207
|
-
owner_copy: "box.ownerCopy {sealId, ownerToken, linkKey} -> {ok: boolean}"
|
|
1760
|
+
owner_copy: "box.ownerCopy {sealId, ownerToken, linkKey} -> {ok: boolean}",
|
|
1761
|
+
lease: "box.lease {lease: {id, token, name, hosts, words, expires_at}} -> {ok: boolean, address?: string}; ok: the lease and its revoke token are in Sent; address: the inbox's address, the owner of the lent key (SPEC agent egress \xA77.3\u20137.5: the guard asks it for its word and sends it the daily summary)"
|
|
1208
1762
|
},
|
|
1209
1763
|
migrate: {
|
|
1210
1764
|
until: "C1 + 7 days (C1 \xA76)",
|
|
@@ -1233,7 +1787,7 @@ var seal_address_default = {
|
|
|
1233
1787
|
seed: "Aw4ZJC86RVBbZnF8h5KdqLO-ydTf6vUACxYhLDdCTVg",
|
|
1234
1788
|
signature: "74s5T1rE2xRNbameeTbYUHVMN-ZzFu1JBPZJNtH8eYC1vV7-h2HE_hxgo4vUB0_sHFfdYRUf0bve4_KGe32ICg",
|
|
1235
1789
|
ts: 179e7,
|
|
1236
|
-
words: "album wren hedge"
|
|
1790
|
+
words: "album wren hedge kite tulip peach llama echo"
|
|
1237
1791
|
}
|
|
1238
1792
|
]
|
|
1239
1793
|
};
|
|
@@ -1275,129 +1829,454 @@ var upload_default = {
|
|
|
1275
1829
|
PROGRESS_SPEED_WINDOW_MS: 2e4
|
|
1276
1830
|
}
|
|
1277
1831
|
};
|
|
1278
|
-
var
|
|
1279
|
-
function
|
|
1280
|
-
|
|
1832
|
+
var hostFetch;
|
|
1833
|
+
function transportFetch(input, init2) {
|
|
1834
|
+
return (hostFetch ?? globalThis.fetch).call(globalThis, input, init2);
|
|
1281
1835
|
}
|
|
1282
|
-
function
|
|
1283
|
-
return
|
|
1836
|
+
function hostNamedTransport() {
|
|
1837
|
+
return hostFetch !== void 0;
|
|
1284
1838
|
}
|
|
1285
|
-
var
|
|
1286
|
-
|
|
1839
|
+
var MAX_BODY_BYTES = 2 * 1024 * 1024;
|
|
1840
|
+
var API_ANSWER_TIMEOUT_MS = (limits_default.limits.INTAKE_WAIT_MAX_SECONDS + 15) * 1e3;
|
|
1841
|
+
var ADDRESS_HEADER = seal_address_default.proof.header_address;
|
|
1842
|
+
var PROOF_HEADER = seal_address_default.proof.header_proof;
|
|
1843
|
+
function isProduction() {
|
|
1844
|
+
try {
|
|
1845
|
+
return typeof process !== "undefined" && process.env?.NODE_ENV === "production";
|
|
1846
|
+
} catch {
|
|
1847
|
+
return false;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
var defaultLogHandler = (level2, module2, message, ...args) => {
|
|
1851
|
+
const formatted = `[${module2}] ${message}`;
|
|
1852
|
+
switch (level2) {
|
|
1853
|
+
case "debug":
|
|
1854
|
+
if (!isProduction()) {
|
|
1855
|
+
console.debug(formatted, ...args);
|
|
1856
|
+
}
|
|
1857
|
+
break;
|
|
1858
|
+
case "info":
|
|
1859
|
+
console.info(formatted, ...args);
|
|
1860
|
+
break;
|
|
1861
|
+
case "warn":
|
|
1862
|
+
console.warn(formatted, ...args);
|
|
1863
|
+
break;
|
|
1864
|
+
case "error":
|
|
1865
|
+
console.error(formatted, ...args);
|
|
1866
|
+
break;
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
var currentHandler = defaultLogHandler;
|
|
1870
|
+
function createLogger(module2) {
|
|
1871
|
+
return {
|
|
1872
|
+
debug: (message, ...args) => currentHandler("debug", module2, message, ...args),
|
|
1873
|
+
info: (message, ...args) => currentHandler("info", module2, message, ...args),
|
|
1874
|
+
warn: (message, ...args) => currentHandler("warn", module2, message, ...args),
|
|
1875
|
+
error: (message, ...args) => currentHandler("error", module2, message, ...args)
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
var UploadError = class extends Error {
|
|
1879
|
+
constructor(message, code, httpStatus, partNumber, retryable = false) {
|
|
1287
1880
|
super(message);
|
|
1288
|
-
this.name = "BackendError";
|
|
1289
1881
|
this.code = code;
|
|
1290
|
-
this.
|
|
1291
|
-
this.
|
|
1292
|
-
this.
|
|
1293
|
-
this.
|
|
1294
|
-
this.retryAfter = extra.retryAfter;
|
|
1295
|
-
this.update = extra.update;
|
|
1296
|
-
this.minVersion = extra.minVersion;
|
|
1882
|
+
this.httpStatus = httpStatus;
|
|
1883
|
+
this.partNumber = partNumber;
|
|
1884
|
+
this.retryable = retryable;
|
|
1885
|
+
this.name = "UploadError";
|
|
1297
1886
|
}
|
|
1298
1887
|
};
|
|
1299
|
-
function
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
if (status === 429) return "rate_limited";
|
|
1303
|
-
if (status === 401 || status === 403) return "auth";
|
|
1304
|
-
if (status >= 500 && status < 600) return "transient";
|
|
1305
|
-
return "unknown";
|
|
1888
|
+
function attachSession(err, session) {
|
|
1889
|
+
Object.defineProperty(err, "session", { value: session, enumerable: false, configurable: true, writable: true });
|
|
1890
|
+
return err;
|
|
1306
1891
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
let retryAfter;
|
|
1312
|
-
let update;
|
|
1313
|
-
let minVersion;
|
|
1314
|
-
if (body) {
|
|
1315
|
-
try {
|
|
1316
|
-
const parsed = JSON.parse(body);
|
|
1317
|
-
if (typeof parsed?.detail === "string") detail = parsed.detail;
|
|
1318
|
-
if (typeof parsed?.code === "string") appCode = parsed.code;
|
|
1319
|
-
if (typeof parsed?.retry_after === "number") retryAfter = parsed.retry_after;
|
|
1320
|
-
if (typeof parsed?.update === "string") update = parsed.update;
|
|
1321
|
-
if (typeof parsed?.min_version === "string") minVersion = parsed.min_version;
|
|
1322
|
-
} catch {
|
|
1323
|
-
}
|
|
1892
|
+
function toUploadError(err, fallbackMessage) {
|
|
1893
|
+
if (err instanceof UploadError) return err;
|
|
1894
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
1895
|
+
return new UploadError("Upload aborted", "ABORTED");
|
|
1324
1896
|
}
|
|
1325
|
-
return new
|
|
1326
|
-
body: body || void 0,
|
|
1327
|
-
detail,
|
|
1328
|
-
appCode,
|
|
1329
|
-
retryAfter,
|
|
1330
|
-
update,
|
|
1331
|
-
minVersion
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
function toSealMetadata(wire) {
|
|
1335
|
-
return {
|
|
1336
|
-
id: wire.id,
|
|
1337
|
-
expiresAt: wire.expires_at,
|
|
1338
|
-
revokedAt: wire.revoked_at,
|
|
1339
|
-
ndaRequired: wire.nda_required,
|
|
1340
|
-
otpRequired: wire.otp_required,
|
|
1341
|
-
singleUse: wire.single_use,
|
|
1342
|
-
maxOpens: wire.max_opens ?? null,
|
|
1343
|
-
files: (wire.files ?? []).map((f) => ({
|
|
1344
|
-
id: f.id,
|
|
1345
|
-
size: f.size,
|
|
1346
|
-
sha256_hex: f.sha256_hex,
|
|
1347
|
-
name_encrypted: f.name_encrypted,
|
|
1348
|
-
name_nonce: f.name_nonce,
|
|
1349
|
-
mime_encrypted: f.mime_encrypted,
|
|
1350
|
-
mime_nonce: f.mime_nonce
|
|
1351
|
-
}))
|
|
1352
|
-
};
|
|
1897
|
+
return new UploadError(err instanceof Error ? err.message : fallbackMessage, "UNKNOWN");
|
|
1353
1898
|
}
|
|
1354
|
-
function
|
|
1355
|
-
|
|
1899
|
+
async function uploadErrorFromResponse(resp, what, code, partNumber) {
|
|
1900
|
+
const refusal = await errorFromResponse(resp, String(resp.status));
|
|
1901
|
+
return new UploadError(
|
|
1902
|
+
`${what}: ${refusal.message}`,
|
|
1903
|
+
resp.status === 426 ? "CLIENT_OUTDATED" : code,
|
|
1904
|
+
resp.status,
|
|
1905
|
+
partNumber
|
|
1906
|
+
);
|
|
1356
1907
|
}
|
|
1357
|
-
var
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1908
|
+
var log = createLogger("upload");
|
|
1909
|
+
var REAL_CLOCK = {
|
|
1910
|
+
now: () => performance.now(),
|
|
1911
|
+
after: (ms, run) => {
|
|
1912
|
+
const timer = setTimeout(run, ms);
|
|
1913
|
+
return () => clearTimeout(timer);
|
|
1914
|
+
},
|
|
1915
|
+
every: (ms, run) => {
|
|
1916
|
+
const timer = setInterval(run, ms);
|
|
1917
|
+
return () => clearInterval(timer);
|
|
1367
1918
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1919
|
+
};
|
|
1920
|
+
var DEFAULT_TRANSPORT_POLICY = {
|
|
1921
|
+
retryBackoffMs: upload_default.upload.RETRY_BACKOFF_MS,
|
|
1922
|
+
retryJitterRatio: upload_default.upload.RETRY_JITTER_RATIO,
|
|
1923
|
+
stallNoticeMs: upload_default.upload.STALL_NOTICE_MS,
|
|
1924
|
+
maxStallMs: upload_default.upload.MAX_STALL_MS,
|
|
1925
|
+
putFloorBytesPerSecond: upload_default.upload.PUT_FLOOR_BYTES_PER_SECOND,
|
|
1926
|
+
putMinDeadlineMs: upload_default.upload.PUT_MIN_DEADLINE_MS,
|
|
1927
|
+
controlTimeoutMs: upload_default.upload.CONTROL_TIMEOUT_MS,
|
|
1928
|
+
completeTimeoutMs: upload_default.upload.COMPLETE_TIMEOUT_MS,
|
|
1929
|
+
poolStart: upload_default.upload.PART_POOL_START,
|
|
1930
|
+
poolMax: upload_default.upload.PART_POOL_MAX,
|
|
1931
|
+
poolMin: upload_default.upload.PART_POOL_MIN,
|
|
1932
|
+
poolGrowRatio: upload_default.upload.PART_POOL_GROW_RATIO,
|
|
1933
|
+
poolShrinkRatio: upload_default.upload.PART_POOL_SHRINK_RATIO,
|
|
1934
|
+
partQueueLimit: upload_default.upload.PART_QUEUE_LIMIT,
|
|
1935
|
+
hedgeMinInflightMs: upload_default.upload.HEDGE_MIN_INFLIGHT_MS,
|
|
1936
|
+
hedgeLagFactor: upload_default.upload.HEDGE_LAG_FACTOR,
|
|
1937
|
+
hedgePollMs: upload_default.upload.HEDGE_POLL_MS,
|
|
1938
|
+
livenessSilenceMs: upload_default.upload.LIVENESS_SILENCE_MS,
|
|
1939
|
+
verifyPollBackoffMs: upload_default.upload.VERIFY_POLL_BACKOFF_MS,
|
|
1940
|
+
verifyFallbackWaitMs: upload_default.upload.VERIFY_FALLBACK_WAIT_MS,
|
|
1941
|
+
speedWindowMs: upload_default.upload.PROGRESS_SPEED_WINDOW_MS,
|
|
1942
|
+
clock: REAL_CLOCK
|
|
1943
|
+
};
|
|
1944
|
+
function resolveTransportPolicy(overrides) {
|
|
1945
|
+
return { ...DEFAULT_TRANSPORT_POLICY, ...overrides };
|
|
1946
|
+
}
|
|
1947
|
+
function putDeadlineMs(bytes, policy) {
|
|
1948
|
+
return Math.max(policy.putMinDeadlineMs, Math.ceil(bytes / policy.putFloorBytesPerSecond * 1e3));
|
|
1949
|
+
}
|
|
1950
|
+
var signalStatics = () => globalThis.AbortSignal;
|
|
1951
|
+
function anySignal(signals) {
|
|
1952
|
+
const native = signalStatics()?.any;
|
|
1953
|
+
if (typeof native === "function") return native.call(AbortSignal, signals);
|
|
1954
|
+
const controller = new AbortController();
|
|
1955
|
+
const done = signals.find((signal) => signal.aborted);
|
|
1956
|
+
if (done) {
|
|
1957
|
+
controller.abort(done.reason);
|
|
1958
|
+
return controller.signal;
|
|
1959
|
+
}
|
|
1960
|
+
for (const signal of signals) {
|
|
1961
|
+
signal.addEventListener("abort", () => controller.abort(signal.reason), { once: true, signal: controller.signal });
|
|
1962
|
+
}
|
|
1963
|
+
return controller.signal;
|
|
1964
|
+
}
|
|
1965
|
+
function timeoutSignal(ms) {
|
|
1966
|
+
const native = signalStatics()?.timeout;
|
|
1967
|
+
if (typeof native === "function") return native.call(AbortSignal, ms);
|
|
1968
|
+
const controller = new AbortController();
|
|
1969
|
+
setTimeout(() => controller.abort(new DOMException("The operation timed out.", "TimeoutError")), ms);
|
|
1970
|
+
return controller.signal;
|
|
1971
|
+
}
|
|
1972
|
+
function withDeadline(base, ms) {
|
|
1973
|
+
const deadline = timeoutSignal(ms);
|
|
1974
|
+
return base ? anySignal([base, deadline]) : deadline;
|
|
1975
|
+
}
|
|
1976
|
+
async function policyFetch(url, init2, timeoutMs, signal) {
|
|
1977
|
+
try {
|
|
1978
|
+
return await transportFetch(url, { ...init2, signal: withDeadline(signal, timeoutMs) });
|
|
1979
|
+
} catch (err) {
|
|
1980
|
+
if (signal?.aborted) throw new UploadError("Upload aborted", "ABORTED");
|
|
1981
|
+
throw new UploadError(
|
|
1982
|
+
`Request failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
1983
|
+
"NETWORK",
|
|
1984
|
+
void 0,
|
|
1985
|
+
void 0,
|
|
1986
|
+
true
|
|
1987
|
+
);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
function classifyStatus(status) {
|
|
1991
|
+
if (status === 408 || status === 429 || status >= 500) return "retryable";
|
|
1992
|
+
return "terminal";
|
|
1993
|
+
}
|
|
1994
|
+
function classifyStorageFailure(failure) {
|
|
1995
|
+
if (failure.code === "ABORTED") return "terminal";
|
|
1996
|
+
if (failure.code === "BAD_DIGEST") return "retryable";
|
|
1997
|
+
if (failure.httpStatus === void 0) return "retryable";
|
|
1998
|
+
if (failure.httpStatus === 403) return "refresh_url";
|
|
1999
|
+
return classifyStatus(failure.httpStatus);
|
|
2000
|
+
}
|
|
2001
|
+
function classifyControlFailure(failure) {
|
|
2002
|
+
if (failure.code === "ABORTED") return "terminal";
|
|
2003
|
+
if (failure.httpStatus === void 0) return "retryable";
|
|
2004
|
+
return classifyStatus(failure.httpStatus);
|
|
2005
|
+
}
|
|
2006
|
+
var StallClock = class {
|
|
2007
|
+
constructor(policy, onState, now = () => performance.now()) {
|
|
2008
|
+
this.policy = policy;
|
|
2009
|
+
this.onState = onState;
|
|
2010
|
+
this.now = now;
|
|
2011
|
+
this.failingSince = null;
|
|
2012
|
+
this.current = "running";
|
|
2013
|
+
this.noticeTimer = null;
|
|
2014
|
+
this.retriesSinceDelivery = 0;
|
|
2015
|
+
}
|
|
2016
|
+
get state() {
|
|
2017
|
+
return this.current;
|
|
2018
|
+
}
|
|
2019
|
+
/**
|
|
2020
|
+
* The connections are known to be dead (the browser went offline, or every
|
|
2021
|
+
* socket of the upload has been silent): say so now. Nothing failed, so the
|
|
2022
|
+
* give-up clock does not start; the next delivery clears it.
|
|
2023
|
+
*/
|
|
2024
|
+
connectionLost() {
|
|
2025
|
+
this.setState("stalled");
|
|
2026
|
+
}
|
|
2027
|
+
/** Storage (or the API) confirmed bytes: the upload is alive. */
|
|
2028
|
+
delivered() {
|
|
2029
|
+
this.failingSince = null;
|
|
2030
|
+
this.retriesSinceDelivery = 0;
|
|
2031
|
+
this.clearNotice();
|
|
2032
|
+
this.setState("running");
|
|
2033
|
+
}
|
|
2034
|
+
/** True when the upload has failed, delivering nothing, for `maxStallMs`. */
|
|
2035
|
+
exhausted() {
|
|
2036
|
+
return this.failingSince !== null && this.now() - this.failingSince >= this.policy.maxStallMs;
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* A retryable failure happened. Flips to `stalled` once the failing has
|
|
2040
|
+
* lasted long enough — now, or later via a timer, so the notice is on
|
|
2041
|
+
* time even when the next attempt sits out a 30 s backoff.
|
|
2042
|
+
*/
|
|
2043
|
+
failed() {
|
|
2044
|
+
this.retriesSinceDelivery += 1;
|
|
2045
|
+
this.failingSince ?? (this.failingSince = this.now());
|
|
2046
|
+
const remaining = this.policy.stallNoticeMs - (this.now() - this.failingSince);
|
|
2047
|
+
if (remaining <= 0) {
|
|
2048
|
+
this.setState("stalled");
|
|
2049
|
+
} else if (this.noticeTimer === null && this.current === "running") {
|
|
2050
|
+
this.noticeTimer = setTimeout(() => {
|
|
2051
|
+
this.noticeTimer = null;
|
|
2052
|
+
this.setState("stalled");
|
|
2053
|
+
}, remaining);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
/** Stop the pending notice; call when the upload ends either way. */
|
|
2057
|
+
dispose() {
|
|
2058
|
+
this.clearNotice();
|
|
2059
|
+
}
|
|
2060
|
+
clearNotice() {
|
|
2061
|
+
if (this.noticeTimer !== null) {
|
|
2062
|
+
clearTimeout(this.noticeTimer);
|
|
2063
|
+
this.noticeTimer = null;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
setState(next) {
|
|
2067
|
+
if (next === this.current) return;
|
|
2068
|
+
this.current = next;
|
|
2069
|
+
this.onState?.(next);
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
function abortableDelay(ms, signal) {
|
|
2073
|
+
return new Promise((resolve2, reject) => {
|
|
2074
|
+
if (signal?.aborted) {
|
|
2075
|
+
reject(new UploadError("Upload aborted", "ABORTED"));
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
const onAbort = () => {
|
|
2079
|
+
clearTimeout(timer);
|
|
2080
|
+
reject(new UploadError("Upload aborted", "ABORTED"));
|
|
2081
|
+
};
|
|
2082
|
+
const timer = setTimeout(() => {
|
|
2083
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2084
|
+
resolve2();
|
|
2085
|
+
}, ms);
|
|
2086
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
async function retrying(step, options) {
|
|
2090
|
+
const { clock, policy, signal, classify, what } = options;
|
|
2091
|
+
let after;
|
|
2092
|
+
let refreshedInARow = 0;
|
|
2093
|
+
for (let attempt = 0; ; attempt++) {
|
|
2094
|
+
if (signal?.aborted) throw new UploadError("Upload aborted", "ABORTED");
|
|
2095
|
+
try {
|
|
2096
|
+
return await step({ attempt, after });
|
|
2097
|
+
} catch (err) {
|
|
2098
|
+
const failure = toUploadError(err, `${what} failed`);
|
|
2099
|
+
if (failure.code === "ABORTED") throw failure;
|
|
2100
|
+
const failureClass = classify(failure);
|
|
2101
|
+
if (failureClass === "terminal") throw failure;
|
|
2102
|
+
if (clock.exhausted()) {
|
|
2103
|
+
throw new UploadError(
|
|
2104
|
+
`${what}: no progress for ${Math.round(policy.maxStallMs / 1e3)} s \u2014 ${failure.message}`,
|
|
2105
|
+
failure.code,
|
|
2106
|
+
failure.httpStatus,
|
|
2107
|
+
failure.partNumber,
|
|
2108
|
+
false
|
|
2109
|
+
);
|
|
2110
|
+
}
|
|
2111
|
+
clock.failed();
|
|
2112
|
+
refreshedInARow = failureClass === "refresh_url" ? refreshedInARow + 1 : 0;
|
|
2113
|
+
const immediate = failureClass === "refresh_url" && refreshedInARow === 1;
|
|
2114
|
+
const base = policy.retryBackoffMs[Math.min(attempt, policy.retryBackoffMs.length - 1)] ?? 0;
|
|
2115
|
+
const jitter = 1 + (Math.random() * 2 - 1) * policy.retryJitterRatio;
|
|
2116
|
+
const delay = immediate ? 0 : Math.round(base * jitter);
|
|
2117
|
+
log.debug(
|
|
2118
|
+
`retry ${what} attempt=${attempt + 2} in ${delay}ms after ${failure.code}${failure.httpStatus ? " " + failure.httpStatus : ""} (${failureClass})`
|
|
2119
|
+
);
|
|
2120
|
+
after = failureClass;
|
|
2121
|
+
await abortableDelay(delay, signal);
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
var clientIdentity;
|
|
2126
|
+
function setClientIdentity(name2, version) {
|
|
2127
|
+
clientIdentity = `${name2}/${version}`;
|
|
2128
|
+
}
|
|
2129
|
+
function clientHeaders() {
|
|
2130
|
+
return clientIdentity === void 0 ? {} : { [header]: clientIdentity };
|
|
2131
|
+
}
|
|
2132
|
+
var BackendError = class extends Error {
|
|
2133
|
+
constructor(message, code, status, extra = {}) {
|
|
2134
|
+
super(message);
|
|
2135
|
+
this.name = "BackendError";
|
|
2136
|
+
this.code = code;
|
|
2137
|
+
this.status = status;
|
|
2138
|
+
this.body = extra.body;
|
|
2139
|
+
this.detail = extra.detail;
|
|
2140
|
+
this.appCode = extra.appCode;
|
|
2141
|
+
this.retryAfter = extra.retryAfter;
|
|
2142
|
+
this.update = extra.update;
|
|
2143
|
+
this.minVersion = extra.minVersion;
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
function classifyStatus2(status) {
|
|
2147
|
+
if (status === 404) return "not_found";
|
|
2148
|
+
if (status === 410) return "revoked";
|
|
2149
|
+
if (status === 451) return "blocked";
|
|
2150
|
+
if (status === 429) return "rate_limited";
|
|
2151
|
+
if (status === 401 || status === 403) return "auth";
|
|
2152
|
+
if (status >= 500 && status < 600) return "transient";
|
|
2153
|
+
return "unknown";
|
|
2154
|
+
}
|
|
2155
|
+
async function errorFromResponse(resp, fallback) {
|
|
2156
|
+
const body = await resp.text().catch(() => "");
|
|
2157
|
+
let detail;
|
|
2158
|
+
let appCode;
|
|
2159
|
+
let retryAfter;
|
|
2160
|
+
let update;
|
|
2161
|
+
let minVersion;
|
|
2162
|
+
if (body) {
|
|
2163
|
+
try {
|
|
2164
|
+
const parsed = JSON.parse(body);
|
|
2165
|
+
if (typeof parsed?.detail === "string") detail = parsed.detail;
|
|
2166
|
+
if (typeof parsed?.code === "string") appCode = parsed.code;
|
|
2167
|
+
if (typeof parsed?.retry_after === "number") retryAfter = parsed.retry_after;
|
|
2168
|
+
if (typeof parsed?.update === "string") update = parsed.update;
|
|
2169
|
+
if (typeof parsed?.min_version === "string") minVersion = parsed.min_version;
|
|
2170
|
+
} catch {
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
return new BackendError(detail ?? fallback, classifyStatus2(resp.status), resp.status, {
|
|
2174
|
+
body: body || void 0,
|
|
2175
|
+
detail,
|
|
2176
|
+
appCode,
|
|
2177
|
+
retryAfter,
|
|
2178
|
+
update,
|
|
2179
|
+
minVersion
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
function toSealMetadata(wire) {
|
|
2183
|
+
return {
|
|
2184
|
+
id: wire.id,
|
|
2185
|
+
expiresAt: wire.expires_at,
|
|
2186
|
+
revokedAt: wire.revoked_at,
|
|
2187
|
+
ndaRequired: wire.nda_required,
|
|
2188
|
+
otpRequired: wire.otp_required,
|
|
2189
|
+
singleUse: wire.single_use,
|
|
2190
|
+
maxOpens: wire.max_opens ?? null,
|
|
2191
|
+
files: (wire.files ?? []).map((f) => ({
|
|
2192
|
+
id: f.id,
|
|
2193
|
+
size: f.size,
|
|
2194
|
+
sha256_hex: f.sha256_hex,
|
|
2195
|
+
name_encrypted: f.name_encrypted,
|
|
2196
|
+
name_nonce: f.name_nonce,
|
|
2197
|
+
mime_encrypted: f.mime_encrypted,
|
|
2198
|
+
mime_nonce: f.mime_nonce
|
|
2199
|
+
}))
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
function encode(segment) {
|
|
2203
|
+
return encodeURIComponent(segment);
|
|
2204
|
+
}
|
|
2205
|
+
var SHARE_PROOF_HEADER = crypto_default.share_link.proof_header;
|
|
2206
|
+
var heldProofs = /* @__PURE__ */ new Map();
|
|
2207
|
+
async function shareProof(linkKey) {
|
|
2208
|
+
const text2 = new TextEncoder();
|
|
2209
|
+
const ikm = await crypto.subtle.importKey("raw", linkKey, "HKDF", false, ["deriveBits"]);
|
|
2210
|
+
const derived = await crypto.subtle.deriveBits(
|
|
2211
|
+
{ name: "HKDF", hash: "SHA-256", salt: text2.encode(crypto_default.hkdf.identity_key_salt), info: text2.encode(crypto_default.hkdf.info_prefixes.share_proof) },
|
|
2212
|
+
ikm,
|
|
2213
|
+
256
|
|
2214
|
+
);
|
|
2215
|
+
const proof = new Uint8Array(derived);
|
|
2216
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", proof));
|
|
2217
|
+
return { proof: bytesToBase64url(proof), hash: Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("") };
|
|
2218
|
+
}
|
|
2219
|
+
async function holdShareProof(sealId, linkKey) {
|
|
2220
|
+
heldProofs.set(sealId, (await shareProof(linkKey)).proof);
|
|
2221
|
+
}
|
|
2222
|
+
function shareProofHeader(path) {
|
|
2223
|
+
const seal = /^\/seal\/([^/?]+)/.exec(path)?.[1];
|
|
2224
|
+
const proof = seal ? heldProofs.get(decodeURIComponent(seal)) : void 0;
|
|
2225
|
+
return proof ? { [SHARE_PROOF_HEADER]: proof } : {};
|
|
2226
|
+
}
|
|
2227
|
+
var SealApi = class _SealApi {
|
|
2228
|
+
constructor(options) {
|
|
2229
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
2230
|
+
if (typeof (options.fetch ?? globalThis.fetch) !== "function") {
|
|
2231
|
+
throw new Error(
|
|
2232
|
+
"SealApi: no global fetch in this runtime \u2014 pass options.fetch or use Node >= 18"
|
|
2233
|
+
);
|
|
2234
|
+
}
|
|
2235
|
+
this.injectedFetch = options.fetch;
|
|
2236
|
+
this.credentials = options.credentials;
|
|
2237
|
+
this.answerTimeoutMs = options.answerTimeoutMs ?? API_ANSWER_TIMEOUT_MS;
|
|
2238
|
+
}
|
|
2239
|
+
/**
|
|
2240
|
+
* The transport for one request.
|
|
2241
|
+
*
|
|
2242
|
+
* Called with `globalThis` as receiver, ALWAYS. Storing `globalThis.fetch`
|
|
2243
|
+
* on an instance and calling it as `this.fetchImpl(...)` hands the browser a
|
|
2244
|
+
* receiver that is not `window`, and it answers "Failed to execute 'fetch'
|
|
2245
|
+
* on 'Window': Illegal invocation". Node does not care, which is exactly why
|
|
2246
|
+
* the previous copies of this client — all of them Node-only — could carry
|
|
2247
|
+
* the same line for a year without anyone noticing.
|
|
2248
|
+
*
|
|
2249
|
+
* Resolved per call rather than captured in the constructor: a browser host
|
|
2250
|
+
* may replace `window.fetch` after this module is evaluated (SEAL Pro does,
|
|
2251
|
+
* to re-anchor root-absolute paths onto its `/pro` base path), and clients
|
|
1381
2252
|
* built as module-level singletons are constructed before that happens.
|
|
2253
|
+
* Without an injected one, the host's network (`setTransport`) carries it.
|
|
1382
2254
|
*/
|
|
1383
2255
|
fetchImpl(input, init2) {
|
|
1384
|
-
|
|
1385
|
-
return impl.call(globalThis, input, init2);
|
|
2256
|
+
return this.injectedFetch ? this.injectedFetch.call(globalThis, input, init2) : transportFetch(input, init2);
|
|
1386
2257
|
}
|
|
1387
2258
|
/** Absolute (or origin-relative) URL for a path that must start with `/`. */
|
|
1388
2259
|
url(path) {
|
|
1389
2260
|
if (!path.startsWith("/")) {
|
|
1390
2261
|
throw new Error(`SealApi: path must start with '/', got: ${path}`);
|
|
1391
2262
|
}
|
|
1392
|
-
return `${this.baseUrl}${path}`;
|
|
1393
|
-
}
|
|
1394
|
-
async request(path, init2) {
|
|
1395
|
-
const { what, ...rest } = init2;
|
|
1396
|
-
const
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
2263
|
+
return `${this.baseUrl}${path}`;
|
|
2264
|
+
}
|
|
2265
|
+
async request(path, init2) {
|
|
2266
|
+
const { what, ...rest } = init2;
|
|
2267
|
+
const deadline = new AbortController();
|
|
2268
|
+
const timer = setTimeout(() => deadline.abort(new DOMException(`${what}: no answer in time`, "TimeoutError")), this.answerTimeoutMs);
|
|
2269
|
+
let resp;
|
|
2270
|
+
try {
|
|
2271
|
+
resp = await this.fetchImpl(this.url(path), {
|
|
2272
|
+
...rest,
|
|
2273
|
+
headers: { ...clientHeaders(), ...shareProofHeader(path), ...rest.headers },
|
|
2274
|
+
credentials: rest.credentials ?? this.credentials,
|
|
2275
|
+
signal: rest.signal ? anySignal([rest.signal, deadline.signal]) : deadline.signal
|
|
2276
|
+
});
|
|
2277
|
+
} finally {
|
|
2278
|
+
clearTimeout(timer);
|
|
2279
|
+
}
|
|
1401
2280
|
if (!resp.ok) {
|
|
1402
2281
|
throw await errorFromResponse(resp, `${what} failed: ${resp.status}`);
|
|
1403
2282
|
}
|
|
@@ -1411,9 +2290,13 @@ var SealApi = class _SealApi {
|
|
|
1411
2290
|
// ---------------------------------------------------------------------------
|
|
1412
2291
|
// Public surface (recipient side)
|
|
1413
2292
|
// ---------------------------------------------------------------------------
|
|
1414
|
-
/**
|
|
2293
|
+
/**
|
|
2294
|
+
* `GET /seal/{id}` — public metadata. Ticks no counters. An organization's seal lists its files only to the
|
|
2295
|
+
* link `shareCode` names, the files of its scope (SPEC-r4 api11.1).
|
|
2296
|
+
*/
|
|
1415
2297
|
async getMetadata(sealId, opts = {}) {
|
|
1416
|
-
const
|
|
2298
|
+
const query = opts.shareCode ? `?share_code=${encode(opts.shareCode)}` : "";
|
|
2299
|
+
const resp = await this.request(`/seal/${encode(sealId)}${query}`, {
|
|
1417
2300
|
what: `GET /seal/${sealId}`,
|
|
1418
2301
|
signal: opts.signal
|
|
1419
2302
|
});
|
|
@@ -1535,6 +2418,28 @@ var SealApi = class _SealApi {
|
|
|
1535
2418
|
}
|
|
1536
2419
|
}
|
|
1537
2420
|
}
|
|
2421
|
+
/**
|
|
2422
|
+
* The ciphertext itself, for a runtime that decrypts: `openDownload`, and
|
|
2423
|
+
* where the answer is a BFF's `{url}` (`X-Download-Mode: presigned` — a
|
|
2424
|
+
* page served from seal.net reaches the API through `/api`, and script
|
|
2425
|
+
* cannot read `Location`), the bytes from storage behind it, opened as the
|
|
2426
|
+
* URL was signed: no client header, cookie or credentials. A page that
|
|
2427
|
+
* streams from the URL itself keeps calling `openDownload`.
|
|
2428
|
+
*
|
|
2429
|
+
* Found 30.10: an SDK on a seal.net page piped the `{url}` answer into the
|
|
2430
|
+
* decryptor; the one open of a single-use seal went on an integrity failure.
|
|
2431
|
+
*/
|
|
2432
|
+
async downloadCiphertext(sealId, target, opts = {}) {
|
|
2433
|
+
const answer = await this.openDownload(sealId, target, opts);
|
|
2434
|
+
if (answer.headers.get("X-Download-Mode") !== "presigned") return answer;
|
|
2435
|
+
const { url } = await answer.json();
|
|
2436
|
+
if (typeof url !== "string" || !url) {
|
|
2437
|
+
throw new BackendError(`GET /seal/${sealId}/download answered no storage URL`, "transient", 502);
|
|
2438
|
+
}
|
|
2439
|
+
const storage = await this.fetchImpl(url, { signal: opts.signal });
|
|
2440
|
+
if (!storage.ok) throw await errorFromResponse(storage, `storage download failed: ${storage.status}`);
|
|
2441
|
+
return storage;
|
|
2442
|
+
}
|
|
1538
2443
|
// ---------------------------------------------------------------------------
|
|
1539
2444
|
// Owner surface (X-Owner-Token)
|
|
1540
2445
|
// ---------------------------------------------------------------------------
|
|
@@ -1593,10 +2498,13 @@ var SealApi = class _SealApi {
|
|
|
1593
2498
|
* `fileIds` scopes the link to those files of the seal (all of them when
|
|
1594
2499
|
* absent). `ownerToken` is null when the host's BFF authorises the call
|
|
1595
2500
|
* itself: an organisation's seal, minted under a member's session.
|
|
2501
|
+
* `linkKey` is the key the blob was encrypted with: the server gets the hash
|
|
2502
|
+
* of its proof, and opens the link to that proof whatever the seal's count
|
|
2503
|
+
* of wrong codes (AUDIT K237).
|
|
1596
2504
|
*/
|
|
1597
|
-
async createShareLink(sealId, ownerToken, encryptedBlobB64, opts = {}) {
|
|
2505
|
+
async createShareLink(sealId, ownerToken, encryptedBlobB64, linkKey, opts = {}) {
|
|
1598
2506
|
const headers = ownerToken === null ? { "Content-Type": "application/json" } : _SealApi.ownerHeaders(ownerToken, true);
|
|
1599
|
-
const body = { encrypted_blob: encryptedBlobB64 };
|
|
2507
|
+
const body = { encrypted_blob: encryptedBlobB64, proof_hash: (await shareProof(linkKey)).hash };
|
|
1600
2508
|
if (opts.fileIds) body.file_ids = opts.fileIds;
|
|
1601
2509
|
addAddress(opts, body, headers);
|
|
1602
2510
|
const resp = await this.request(`/seal/${encode(sealId)}/share`, {
|
|
@@ -1632,9 +2540,11 @@ var SealApi = class _SealApi {
|
|
|
1632
2540
|
/**
|
|
1633
2541
|
* `POST /seal/{id}/revoke` — revoke the whole seal.
|
|
1634
2542
|
*
|
|
1635
|
-
* Idempotent, including at the extremes: a seal that is already gone
|
|
1636
|
-
* or already revoked (410) satisfies the caller's
|
|
1637
|
-
* success.
|
|
2543
|
+
* Idempotent, including at the extremes: a seal that is already gone
|
|
2544
|
+
* (404 `seal.not_found`) or already revoked (410) satisfies the caller's
|
|
2545
|
+
* intent, so both count as success. Any other 404 — a proxy's, a route this
|
|
2546
|
+
* host does not serve — is a failure (AUDIT wpkg03.19): the seal may live on.
|
|
2547
|
+
* `revokedAt` is null when the server had nothing left to report.
|
|
1638
2548
|
*/
|
|
1639
2549
|
async revoke(sealId, ownerToken, opts = {}) {
|
|
1640
2550
|
let resp;
|
|
@@ -1646,7 +2556,7 @@ var SealApi = class _SealApi {
|
|
|
1646
2556
|
signal: opts.signal
|
|
1647
2557
|
});
|
|
1648
2558
|
} catch (err) {
|
|
1649
|
-
if (err instanceof BackendError && (err.status === 404 || err.status === 410)) {
|
|
2559
|
+
if (err instanceof BackendError && (err.status === 404 && err.appCode === "seal.not_found" || err.status === 410)) {
|
|
1650
2560
|
return { status: "revoked", revokedAt: null };
|
|
1651
2561
|
}
|
|
1652
2562
|
throw err;
|
|
@@ -1745,6 +2655,7 @@ var SealApi = class _SealApi {
|
|
|
1745
2655
|
if (input.whereUrl) body.where_url = input.whereUrl;
|
|
1746
2656
|
if (input.ttlSeconds !== void 0) body.ttl_seconds = input.ttlSeconds;
|
|
1747
2657
|
if (input.to) body.to = input.to;
|
|
2658
|
+
if (input.bind) body.bind = input.bind;
|
|
1748
2659
|
const resp = await this.request("/intake", {
|
|
1749
2660
|
what: "POST /intake",
|
|
1750
2661
|
method: "POST",
|
|
@@ -1839,16 +2750,6 @@ var SealApi = class _SealApi {
|
|
|
1839
2750
|
signal: opts.signal
|
|
1840
2751
|
});
|
|
1841
2752
|
}
|
|
1842
|
-
async migrateInbox(proof, body, opts = {}) {
|
|
1843
|
-
const resp = await this.request("/intake/migrate", {
|
|
1844
|
-
what: "POST /intake/migrate",
|
|
1845
|
-
method: "POST",
|
|
1846
|
-
headers: { "Content-Type": "application/json", ...proofHeaders(proof) },
|
|
1847
|
-
body: JSON.stringify(body),
|
|
1848
|
-
signal: opts.signal
|
|
1849
|
-
});
|
|
1850
|
-
return await resp.json();
|
|
1851
|
-
}
|
|
1852
2753
|
/** `GET /intake/push-key` — the VAPID key a browser subscribes an inbox's push with (F3 §8). */
|
|
1853
2754
|
async pushKey(opts = {}) {
|
|
1854
2755
|
const resp = await this.request("/intake/push-key", { what: "GET /intake/push-key", signal: opts.signal });
|
|
@@ -1865,6 +2766,53 @@ var SealApi = class _SealApi {
|
|
|
1865
2766
|
signal: opts.signal
|
|
1866
2767
|
});
|
|
1867
2768
|
}
|
|
2769
|
+
// ---------------------------------------------------------------------------
|
|
2770
|
+
// Leases of lent keys (SPEC agent egress §5.8)
|
|
2771
|
+
// ---------------------------------------------------------------------------
|
|
2772
|
+
/**
|
|
2773
|
+
* `POST /lease` — the one record of a lent key the server keeps: under the SHA-256 hex of a token the
|
|
2774
|
+
* lender made (`newLease` makes both), until `expiresAt` or, with null, until revoked. Which key, host
|
|
2775
|
+
* or address it is about stays inside the sealed binding.
|
|
2776
|
+
*/
|
|
2777
|
+
async createLease(ownerTokenHash, expiresAt, opts = {}) {
|
|
2778
|
+
const resp = await this.request("/lease", {
|
|
2779
|
+
what: "POST /lease",
|
|
2780
|
+
method: "POST",
|
|
2781
|
+
headers: { "Content-Type": "application/json" },
|
|
2782
|
+
body: JSON.stringify({ owner_token_hash: ownerTokenHash, expires_at: expiresAt }),
|
|
2783
|
+
signal: opts.signal
|
|
2784
|
+
});
|
|
2785
|
+
return await resp.json();
|
|
2786
|
+
}
|
|
2787
|
+
/** `POST /lease/{id}/revoke` — the owner takes the key back; a repeat answers the first `revoked_at`. */
|
|
2788
|
+
async revokeLease(leaseId, token, opts = {}) {
|
|
2789
|
+
const resp = await this.request(`/lease/${encode(leaseId)}/revoke`, {
|
|
2790
|
+
what: `POST /lease/${leaseId}/revoke`,
|
|
2791
|
+
method: "POST",
|
|
2792
|
+
headers: _SealApi.ownerHeaders(token),
|
|
2793
|
+
signal: opts.signal
|
|
2794
|
+
});
|
|
2795
|
+
return await resp.json();
|
|
2796
|
+
}
|
|
2797
|
+
/**
|
|
2798
|
+
* `POST /lease/status` — the state of up to `LEASE_STATUS_BATCH_MAX` leases in one ask; an id the server
|
|
2799
|
+
* does not hold is `expired`. With `etag` from the last answer the server says 304 when nothing changed,
|
|
2800
|
+
* and this answers null.
|
|
2801
|
+
*/
|
|
2802
|
+
async leaseStatus(ids, opts = {}) {
|
|
2803
|
+
const headers = { "Content-Type": "application/json" };
|
|
2804
|
+
if (opts.etag) headers["If-None-Match"] = opts.etag;
|
|
2805
|
+
const resp = await this.fetchImpl(this.url("/lease/status"), {
|
|
2806
|
+
method: "POST",
|
|
2807
|
+
headers: { ...clientHeaders(), ...headers },
|
|
2808
|
+
body: JSON.stringify({ ids }),
|
|
2809
|
+
credentials: this.credentials,
|
|
2810
|
+
signal: opts.signal
|
|
2811
|
+
});
|
|
2812
|
+
if (resp.status === 304) return null;
|
|
2813
|
+
if (!resp.ok) throw await errorFromResponse(resp, `POST /lease/status failed: ${resp.status}`);
|
|
2814
|
+
return { statuses: await resp.json(), etag: resp.headers.get("ETag") };
|
|
2815
|
+
}
|
|
1868
2816
|
};
|
|
1869
2817
|
var NOT_READY_DEFAULT_RETRY_AFTER_S = 3;
|
|
1870
2818
|
function proofHeaders(proof) {
|
|
@@ -1924,6 +2872,10 @@ function extractSessionCookie(resp, wantedName) {
|
|
|
1924
2872
|
var OWNER_TOKEN_BYTES = 32;
|
|
1925
2873
|
var LINK_KEY_BYTES = 32;
|
|
1926
2874
|
var MAX_BLOB_SIZE = limits_default.limits.MAX_BLOB_SIZE;
|
|
2875
|
+
var MAX_FILE_KEYS = limits_default.limits.MAX_FILE_KEYS;
|
|
2876
|
+
function assertFileKeyCount(count2) {
|
|
2877
|
+
if (count2 > MAX_FILE_KEYS) throw new Error(`Too many file keys: ${count2} exceeds maximum of ${MAX_FILE_KEYS}`);
|
|
2878
|
+
}
|
|
1927
2879
|
var BlobDecryptionError = class extends Error {
|
|
1928
2880
|
constructor() {
|
|
1929
2881
|
super("Invalid encryption key");
|
|
@@ -1940,30 +2892,36 @@ async function hashOwnerToken(token) {
|
|
|
1940
2892
|
function generateLinkKey() {
|
|
1941
2893
|
return crypto.getRandomValues(new Uint8Array(LINK_KEY_BYTES));
|
|
1942
2894
|
}
|
|
1943
|
-
async function encryptOwnerBlob(ownerToken, fileKeys, linkKey, message, ndaFile) {
|
|
2895
|
+
async function encryptOwnerBlob(ownerToken, fileKeys, linkKey, message, ndaFile, bindings, payload) {
|
|
2896
|
+
assertFileKeyCount(fileKeys.size);
|
|
1944
2897
|
const data = {
|
|
1945
2898
|
owner_token: ownerToken,
|
|
1946
2899
|
file_keys: Object.fromEntries(fileKeys),
|
|
1947
2900
|
...message ? { message } : {},
|
|
1948
|
-
...ndaFile ? { nda_file: ndaFile } : {}
|
|
2901
|
+
...ndaFile ? { nda_file: ndaFile } : {},
|
|
2902
|
+
...bindings && Object.keys(bindings).length > 0 ? { bindings } : {},
|
|
2903
|
+
...payload ? { payload } : {}
|
|
1949
2904
|
};
|
|
1950
2905
|
return encryptBlob(data, linkKey);
|
|
1951
2906
|
}
|
|
1952
|
-
async function encryptShareBlob(fileKeys, linkKey, message, ndaFile, replyTo) {
|
|
2907
|
+
async function encryptShareBlob(fileKeys, linkKey, message, ndaFile, replyTo, bindings, payload) {
|
|
2908
|
+
assertFileKeyCount(fileKeys.size);
|
|
1953
2909
|
const data = {
|
|
1954
2910
|
file_keys: Object.fromEntries(fileKeys),
|
|
1955
2911
|
...message ? { message } : {},
|
|
1956
2912
|
...ndaFile ? { nda_file: ndaFile } : {},
|
|
1957
|
-
...replyTo ? { reply_to: bytesToBase64url(replyTo) } : {}
|
|
2913
|
+
...replyTo ? { reply_to: bytesToBase64url(replyTo) } : {},
|
|
2914
|
+
...bindings && Object.keys(bindings).length > 0 ? { bindings } : {},
|
|
2915
|
+
...payload ? { payload } : {}
|
|
1958
2916
|
};
|
|
1959
2917
|
return encryptBlob(data, linkKey);
|
|
1960
2918
|
}
|
|
1961
2919
|
async function encryptBlob(data, linkKey) {
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1964
|
-
|
|
2920
|
+
const plaintext = new TextEncoder().encode(JSON.stringify(data));
|
|
2921
|
+
const blobSize = 12 + plaintext.length + 16;
|
|
2922
|
+
if (blobSize > MAX_BLOB_SIZE) {
|
|
2923
|
+
throw new Error(`Blob size ${blobSize} exceeds maximum of ${MAX_BLOB_SIZE}`);
|
|
1965
2924
|
}
|
|
1966
|
-
const plaintext = new TextEncoder().encode(json);
|
|
1967
2925
|
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
1968
2926
|
const cryptoKey = await crypto.subtle.importKey(
|
|
1969
2927
|
"raw",
|
|
@@ -1982,6 +2940,15 @@ async function encryptBlob(data, linkKey) {
|
|
|
1982
2940
|
result.set(new Uint8Array(ciphertext), 12);
|
|
1983
2941
|
return result;
|
|
1984
2942
|
}
|
|
2943
|
+
function isBinding(value) {
|
|
2944
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2945
|
+
const obj = value;
|
|
2946
|
+
return obj.v === 1 && typeof obj.name === "string" && (obj.class === "outbound" || obj.class === "inprocess") && Array.isArray(obj.hosts) && obj.hosts.every((h) => typeof h === "string");
|
|
2947
|
+
}
|
|
2948
|
+
function bindingsOf(data) {
|
|
2949
|
+
if (typeof data.bindings !== "object" || data.bindings === null) return {};
|
|
2950
|
+
return Object.fromEntries(Object.entries(data.bindings).filter(([, b]) => isBinding(b)));
|
|
2951
|
+
}
|
|
1985
2952
|
function isShareBlobData(data) {
|
|
1986
2953
|
if (typeof data !== "object" || data === null) return false;
|
|
1987
2954
|
const obj = data;
|
|
@@ -1991,6 +2958,7 @@ function isShareBlobData(data) {
|
|
|
1991
2958
|
}
|
|
1992
2959
|
if (obj.message !== void 0 && typeof obj.message !== "string") return false;
|
|
1993
2960
|
if (obj.reply_to !== void 0 && typeof obj.reply_to !== "string") return false;
|
|
2961
|
+
if (obj.payload !== void 0 && typeof obj.payload !== "string") return false;
|
|
1994
2962
|
return true;
|
|
1995
2963
|
}
|
|
1996
2964
|
async function decryptShareBlob(encrypted, linkKey) {
|
|
@@ -2032,42 +3000,7 @@ async function decryptBlob(encrypted, linkKey) {
|
|
|
2032
3000
|
throw new Error("Invalid JSON in decrypted blob");
|
|
2033
3001
|
}
|
|
2034
3002
|
}
|
|
2035
|
-
|
|
2036
|
-
try {
|
|
2037
|
-
return typeof process !== "undefined" && process.env?.NODE_ENV === "production";
|
|
2038
|
-
} catch {
|
|
2039
|
-
return false;
|
|
2040
|
-
}
|
|
2041
|
-
}
|
|
2042
|
-
var defaultLogHandler = (level, module2, message, ...args) => {
|
|
2043
|
-
const formatted = `[${module2}] ${message}`;
|
|
2044
|
-
switch (level) {
|
|
2045
|
-
case "debug":
|
|
2046
|
-
if (!isProduction()) {
|
|
2047
|
-
console.debug(formatted, ...args);
|
|
2048
|
-
}
|
|
2049
|
-
break;
|
|
2050
|
-
case "info":
|
|
2051
|
-
console.info(formatted, ...args);
|
|
2052
|
-
break;
|
|
2053
|
-
case "warn":
|
|
2054
|
-
console.warn(formatted, ...args);
|
|
2055
|
-
break;
|
|
2056
|
-
case "error":
|
|
2057
|
-
console.error(formatted, ...args);
|
|
2058
|
-
break;
|
|
2059
|
-
}
|
|
2060
|
-
};
|
|
2061
|
-
var currentHandler = defaultLogHandler;
|
|
2062
|
-
function createLogger(module2) {
|
|
2063
|
-
return {
|
|
2064
|
-
debug: (message, ...args) => currentHandler("debug", module2, message, ...args),
|
|
2065
|
-
info: (message, ...args) => currentHandler("info", module2, message, ...args),
|
|
2066
|
-
warn: (message, ...args) => currentHandler("warn", module2, message, ...args),
|
|
2067
|
-
error: (message, ...args) => currentHandler("error", module2, message, ...args)
|
|
2068
|
-
};
|
|
2069
|
-
}
|
|
2070
|
-
var MAX_FILE_KEYS = limits_default.limits.MAX_FILE_KEYS;
|
|
3003
|
+
var MAX_FILE_KEYS2 = limits_default.limits.MAX_FILE_KEYS;
|
|
2071
3004
|
var BLOCK_BYTES = 64;
|
|
2072
3005
|
var SHIFTS = [
|
|
2073
3006
|
7,
|
|
@@ -2424,23 +3357,256 @@ function createDecryptStream(key2, options) {
|
|
|
2424
3357
|
{ highWaterMark: 1 }
|
|
2425
3358
|
);
|
|
2426
3359
|
}
|
|
2427
|
-
var swLogger = createLogger("SwDownload");
|
|
2428
|
-
var
|
|
2429
|
-
var
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
3360
|
+
var swLogger = createLogger("SwDownload");
|
|
3361
|
+
var SW_QUIET_MS = 10 * 6e4;
|
|
3362
|
+
var mime_default = {
|
|
3363
|
+
version: 1,
|
|
3364
|
+
default: "application/octet-stream",
|
|
3365
|
+
extensions: {
|
|
3366
|
+
json: "application/json",
|
|
3367
|
+
txt: "text/plain",
|
|
3368
|
+
log: "text/plain",
|
|
3369
|
+
md: "text/plain",
|
|
3370
|
+
csv: "text/csv",
|
|
3371
|
+
html: "text/html",
|
|
3372
|
+
htm: "text/html",
|
|
3373
|
+
xml: "application/xml",
|
|
3374
|
+
pdf: "application/pdf",
|
|
3375
|
+
zip: "application/zip",
|
|
3376
|
+
png: "image/png",
|
|
3377
|
+
jpg: "image/jpeg",
|
|
3378
|
+
jpeg: "image/jpeg",
|
|
3379
|
+
gif: "image/gif",
|
|
3380
|
+
webp: "image/webp",
|
|
3381
|
+
svg: "image/svg+xml",
|
|
3382
|
+
mp4: "video/mp4",
|
|
3383
|
+
webm: "video/webm",
|
|
3384
|
+
mp3: "audio/mpeg",
|
|
3385
|
+
wav: "audio/wav",
|
|
3386
|
+
ogg: "audio/ogg",
|
|
3387
|
+
doc: "application/msword",
|
|
3388
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
3389
|
+
xls: "application/vnd.ms-excel",
|
|
3390
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
var REPLACEMENT_CHAR = "_";
|
|
3394
|
+
var MAX_FILENAME_BYTES = 200;
|
|
3395
|
+
var encoder = new TextEncoder();
|
|
3396
|
+
function utf8Length(text2) {
|
|
3397
|
+
return encoder.encode(text2).length;
|
|
3398
|
+
}
|
|
3399
|
+
function headWithin(text2, bytes) {
|
|
3400
|
+
let head = "";
|
|
3401
|
+
let used = 0;
|
|
3402
|
+
for (const char of text2) {
|
|
3403
|
+
used += utf8Length(char);
|
|
3404
|
+
if (used > bytes) break;
|
|
3405
|
+
head += char;
|
|
3406
|
+
}
|
|
3407
|
+
return head;
|
|
3408
|
+
}
|
|
3409
|
+
var WINDOWS_RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
3410
|
+
"CON",
|
|
3411
|
+
"PRN",
|
|
3412
|
+
"AUX",
|
|
3413
|
+
"NUL",
|
|
3414
|
+
"COM1",
|
|
3415
|
+
"COM2",
|
|
3416
|
+
"COM3",
|
|
3417
|
+
"COM4",
|
|
3418
|
+
"COM5",
|
|
3419
|
+
"COM6",
|
|
3420
|
+
"COM7",
|
|
3421
|
+
"COM8",
|
|
3422
|
+
"COM9",
|
|
3423
|
+
"LPT1",
|
|
3424
|
+
"LPT2",
|
|
3425
|
+
"LPT3",
|
|
3426
|
+
"LPT4",
|
|
3427
|
+
"LPT5",
|
|
3428
|
+
"LPT6",
|
|
3429
|
+
"LPT7",
|
|
3430
|
+
"LPT8",
|
|
3431
|
+
"LPT9"
|
|
3432
|
+
]);
|
|
3433
|
+
function detectPlatform() {
|
|
3434
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
3435
|
+
switch (process.platform) {
|
|
3436
|
+
case "win32":
|
|
3437
|
+
return "windows";
|
|
3438
|
+
case "darwin":
|
|
3439
|
+
return "macos";
|
|
3440
|
+
case "linux":
|
|
3441
|
+
return "linux";
|
|
3442
|
+
case "android":
|
|
3443
|
+
return "android";
|
|
3444
|
+
default:
|
|
3445
|
+
return "unknown";
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
3449
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
3450
|
+
if (ua.includes("win")) return "windows";
|
|
3451
|
+
if (ua.includes("android")) return "android";
|
|
3452
|
+
if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) return "ios";
|
|
3453
|
+
if (ua.includes("mac")) return "macos";
|
|
3454
|
+
if (ua.includes("linux")) return "linux";
|
|
3455
|
+
}
|
|
3456
|
+
return "unknown";
|
|
3457
|
+
}
|
|
3458
|
+
function isValidChar(char, platform) {
|
|
3459
|
+
const code = char.charCodeAt(0);
|
|
3460
|
+
if (code < 32 || code === 127) return false;
|
|
3461
|
+
if (/[\u202A-\u202E\u2066-\u2069\u200E\u200F\u061C]/.test(char)) return false;
|
|
3462
|
+
switch (platform) {
|
|
3463
|
+
case "windows":
|
|
3464
|
+
return !/[<>:"/\\|?*]/.test(char);
|
|
3465
|
+
case "macos":
|
|
3466
|
+
case "ios":
|
|
3467
|
+
return !/[/:]/.test(char);
|
|
3468
|
+
case "linux":
|
|
3469
|
+
case "android":
|
|
3470
|
+
return char !== "/";
|
|
3471
|
+
default:
|
|
3472
|
+
return !/[<>:"/\\|?*]/.test(char);
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
function isWindowsReservedName(name2) {
|
|
3476
|
+
const baseName = name2.split(".")[0].toUpperCase();
|
|
3477
|
+
return WINDOWS_RESERVED_NAMES.has(baseName);
|
|
3478
|
+
}
|
|
3479
|
+
function sanitizeFilename(filename, options = {}) {
|
|
3480
|
+
const {
|
|
3481
|
+
platform = detectPlatform(),
|
|
3482
|
+
replacement = REPLACEMENT_CHAR,
|
|
3483
|
+
maxLength = MAX_FILENAME_BYTES,
|
|
3484
|
+
fallback = "file"
|
|
3485
|
+
} = options;
|
|
3486
|
+
if (!filename || !filename.trim()) {
|
|
3487
|
+
return fallback;
|
|
3488
|
+
}
|
|
3489
|
+
let result = filename.normalize("NFC");
|
|
3490
|
+
result = result.trim();
|
|
3491
|
+
result = result.replace(/^\.+|\.+$/g, "");
|
|
3492
|
+
const chars = [...result];
|
|
3493
|
+
result = chars.map((char) => isValidChar(char, platform) ? char : replacement).join("");
|
|
3494
|
+
const escapedReplacement = replacement.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3495
|
+
result = result.replace(new RegExp(`${escapedReplacement}+`, "g"), replacement);
|
|
3496
|
+
result = result.replace(new RegExp(`^(?:\\.|${escapedReplacement})+|${escapedReplacement}+$`, "g"), "");
|
|
3497
|
+
if (platform === "windows" || platform === "unknown") {
|
|
3498
|
+
if (isWindowsReservedName(result)) {
|
|
3499
|
+
result = `${replacement}${result}`;
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
if (utf8Length(result) > maxLength) {
|
|
3503
|
+
const lastDot = result.lastIndexOf(".");
|
|
3504
|
+
if (lastDot > 0 && lastDot > result.length - 10) {
|
|
3505
|
+
const ext = result.slice(lastDot);
|
|
3506
|
+
result = headWithin(result.slice(0, lastDot), maxLength - utf8Length(ext)) + ext;
|
|
3507
|
+
} else {
|
|
3508
|
+
result = headWithin(result, maxLength);
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
if (!result || result === replacement) {
|
|
3512
|
+
return fallback;
|
|
3513
|
+
}
|
|
3514
|
+
return result;
|
|
3515
|
+
}
|
|
3516
|
+
var MIME_BY_EXTENSION = new Map(Object.entries(mime_default.extensions));
|
|
3517
|
+
function guessMimeFromName(name2) {
|
|
3518
|
+
const idx = name2.lastIndexOf(".");
|
|
3519
|
+
const ext = idx >= 0 && idx < name2.length - 1 ? name2.slice(idx + 1).toLowerCase() : "";
|
|
3520
|
+
return MIME_BY_EXTENSION.get(ext) ?? mime_default.default;
|
|
3521
|
+
}
|
|
3522
|
+
var DEFAULT_BLOB_LIMIT = upload_default.upload.MULTIPART_THRESHOLD_BYTES;
|
|
3523
|
+
var STREAMING_THRESHOLD = upload_default.upload.MULTIPART_THRESHOLD_BYTES;
|
|
3524
|
+
var encoder2 = new TextEncoder();
|
|
3525
|
+
var zipLogger = createLogger("FolderZip");
|
|
3526
|
+
var BLOB_LIMIT = 100 * 1024 * 1024;
|
|
3527
|
+
var HIGH_WATER_BYTES = 4 * 1024 * 1024;
|
|
3528
|
+
var ENCRYPTED_FILE_FALLBACK = "Encrypted file";
|
|
3529
|
+
var ENCRYPTED_MIME_FALLBACK = "application/octet-stream";
|
|
3530
|
+
function metadataFieldAAD(field) {
|
|
3531
|
+
return new TextEncoder().encode(`field:${field}`);
|
|
3532
|
+
}
|
|
3533
|
+
async function encryptMetadataField(plaintext, key2, field) {
|
|
3534
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
3535
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
3536
|
+
"raw",
|
|
3537
|
+
key2.buffer.slice(key2.byteOffset, key2.byteOffset + key2.byteLength),
|
|
3538
|
+
{ name: "AES-GCM" },
|
|
3539
|
+
false,
|
|
3540
|
+
["encrypt"]
|
|
3541
|
+
);
|
|
3542
|
+
const params = { name: "AES-GCM", iv: nonce, tagLength: 128 };
|
|
3543
|
+
if (field) {
|
|
3544
|
+
const aad = metadataFieldAAD(field);
|
|
3545
|
+
params.additionalData = aad.buffer.slice(aad.byteOffset, aad.byteOffset + aad.byteLength);
|
|
3546
|
+
}
|
|
3547
|
+
const ciphertext = await crypto.subtle.encrypt(params, cryptoKey, new TextEncoder().encode(plaintext));
|
|
3548
|
+
return { ciphertext: bytesToBase64(new Uint8Array(ciphertext)), nonce: bytesToBase64(nonce) };
|
|
3549
|
+
}
|
|
3550
|
+
async function decryptMetadataField(encrypted, nonce, key2, field) {
|
|
3551
|
+
const ciphertext = base64ToBytes(encrypted);
|
|
3552
|
+
const iv = base64ToBytes(nonce);
|
|
3553
|
+
const run = async (aad) => {
|
|
3554
|
+
const params = { name: "AES-GCM", iv };
|
|
3555
|
+
if (aad) params.additionalData = aad;
|
|
3556
|
+
const plaintext = await crypto.subtle.decrypt(params, key2, ciphertext);
|
|
3557
|
+
return new TextDecoder().decode(plaintext);
|
|
3558
|
+
};
|
|
3559
|
+
return run(field ? metadataFieldAAD(field) : void 0);
|
|
3560
|
+
}
|
|
3561
|
+
async function decryptFileMetadata(file, key2) {
|
|
3562
|
+
let name2 = ENCRYPTED_FILE_FALLBACK;
|
|
3563
|
+
let mime = ENCRYPTED_MIME_FALLBACK;
|
|
3564
|
+
if (file.name_encrypted && file.name_nonce && file.name_nonce.length > 0) {
|
|
3565
|
+
try {
|
|
3566
|
+
name2 = await decryptMetadataField(file.name_encrypted, file.name_nonce, key2, "name");
|
|
3567
|
+
} catch {
|
|
3568
|
+
name2 = ENCRYPTED_FILE_FALLBACK;
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
if (file.mime_encrypted && file.mime_nonce && file.mime_nonce.length > 0) {
|
|
3572
|
+
try {
|
|
3573
|
+
mime = await decryptMetadataField(file.mime_encrypted, file.mime_nonce, key2, "mime");
|
|
3574
|
+
} catch {
|
|
3575
|
+
mime = ENCRYPTED_MIME_FALLBACK;
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
return { name: name2, mime };
|
|
3579
|
+
}
|
|
3580
|
+
async function importKeyForMetadata(keyBytes) {
|
|
3581
|
+
return crypto.subtle.importKey(
|
|
3582
|
+
"raw",
|
|
3583
|
+
keyBytes,
|
|
3584
|
+
{ name: "AES-GCM" },
|
|
3585
|
+
false,
|
|
3586
|
+
["decrypt"]
|
|
3587
|
+
);
|
|
3588
|
+
}
|
|
3589
|
+
async function decryptFileMetadataWithBytes(file, keyBytes) {
|
|
3590
|
+
try {
|
|
3591
|
+
const key2 = await importKeyForMetadata(keyBytes);
|
|
3592
|
+
return decryptFileMetadata(file, key2);
|
|
3593
|
+
} catch {
|
|
3594
|
+
return { name: ENCRYPTED_FILE_FALLBACK, mime: ENCRYPTED_MIME_FALLBACK };
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
var log2 = createLogger("upload");
|
|
2434
3598
|
var RENDER_SLICE_BYTES = 4 * 1024 * 1024;
|
|
2435
3599
|
function abortError() {
|
|
2436
3600
|
return new DOMException("Upload aborted", "AbortError");
|
|
2437
3601
|
}
|
|
2438
3602
|
async function runCryptoPipeline(options) {
|
|
2439
3603
|
const { stream, totalBytes, key: key2, header: header2, partSize, signal, yieldToRenderer, onSegment } = options;
|
|
2440
|
-
const segmentSize = SEGMENT_SIZE;
|
|
2441
|
-
const segments = Math.max(1, Math.ceil(totalBytes / segmentSize));
|
|
2442
3604
|
const encryptor = new Encryptor({ key: key2, header: header2 });
|
|
2443
3605
|
await encryptor.init();
|
|
3606
|
+
const segmentSize = encryptor.segmentSize;
|
|
3607
|
+
const segments = Math.max(1, Math.ceil(totalBytes / segmentSize));
|
|
3608
|
+
let readBytes = 0;
|
|
3609
|
+
const changed = (what) => new UploadError(`The file changed while it was being sent: ${what} ${readBytes} of ${totalBytes} bytes`, "FILE_CHANGED");
|
|
2444
3610
|
let headerPending = true;
|
|
2445
3611
|
let segmentNumber = 0;
|
|
2446
3612
|
let partNumber = 0;
|
|
@@ -2529,7 +3695,7 @@ async function runCryptoPipeline(options) {
|
|
|
2529
3695
|
await emitFullParts();
|
|
2530
3696
|
const encrypted = await encrypting;
|
|
2531
3697
|
await wipe(plaintext);
|
|
2532
|
-
|
|
3698
|
+
log2.debug(`encrypt segment=${segmentNumber} bytes=${plaintext.length} time=${Math.round(performance.now() - tEncStart)}ms`);
|
|
2533
3699
|
let partData;
|
|
2534
3700
|
if (headerPending) {
|
|
2535
3701
|
partData = new Uint8Array(header2.length + encrypted.length);
|
|
@@ -2550,333 +3716,127 @@ async function runCryptoPipeline(options) {
|
|
|
2550
3716
|
const { done, value } = await reader.read();
|
|
2551
3717
|
if (done) break;
|
|
2552
3718
|
if (value && value.length > 0) {
|
|
3719
|
+
readBytes += value.length;
|
|
3720
|
+
if (readBytes > totalBytes) throw changed("it gave more than");
|
|
2553
3721
|
pending.push(value);
|
|
2554
3722
|
pendingBytes += value.length;
|
|
2555
3723
|
}
|
|
2556
3724
|
while (pendingBytes >= segmentSize) {
|
|
2557
3725
|
await encryptOneSegment(drainSegment(segmentSize), segmentNumber === segments - 1);
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
if (pendingBytes > 0 || segmentNumber === 0) {
|
|
2561
|
-
await encryptOneSegment(drainSegment(pendingBytes), true);
|
|
2562
|
-
}
|
|
2563
|
-
await emitFullParts();
|
|
2564
|
-
if (ciphertextPendingBytes > 0) {
|
|
2565
|
-
await emitPart(await drainCiphertextPart(ciphertextPendingBytes));
|
|
2566
|
-
}
|
|
2567
|
-
} finally {
|
|
2568
|
-
reader.releaseLock();
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
function blobToSegmentStream(blob, segmentSize) {
|
|
2572
|
-
let offset = 0;
|
|
2573
|
-
return new ReadableStream({
|
|
2574
|
-
async pull(controller) {
|
|
2575
|
-
if (offset >= blob.size) {
|
|
2576
|
-
controller.close();
|
|
2577
|
-
return;
|
|
2578
|
-
}
|
|
2579
|
-
const end = Math.min(offset + segmentSize, blob.size);
|
|
2580
|
-
try {
|
|
2581
|
-
const buf = await blob.slice(offset, end).arrayBuffer();
|
|
2582
|
-
controller.enqueue(new Uint8Array(buf));
|
|
2583
|
-
offset = end;
|
|
2584
|
-
} catch (e) {
|
|
2585
|
-
controller.error(e);
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
});
|
|
2589
|
-
}
|
|
2590
|
-
function runCryptoPipelineInWorker(worker, hasher, options) {
|
|
2591
|
-
const { file, key: key2, header: header2, partSize, totalBytes, signal, initialCredits, onSegment, onPart } = options;
|
|
2592
|
-
return new Promise((resolve2, reject) => {
|
|
2593
|
-
let settled = false;
|
|
2594
|
-
let workerDone = false;
|
|
2595
|
-
let hashing = 0;
|
|
2596
|
-
let partChain = Promise.resolve();
|
|
2597
|
-
const fail = (err) => {
|
|
2598
|
-
if (settled) return;
|
|
2599
|
-
settled = true;
|
|
2600
|
-
reject(err);
|
|
2601
|
-
};
|
|
2602
|
-
const maybeFinish = () => {
|
|
2603
|
-
if (!workerDone || hashing > 0) return;
|
|
2604
|
-
void partChain.then(() => {
|
|
2605
|
-
if (settled) return;
|
|
2606
|
-
settled = true;
|
|
2607
|
-
resolve2();
|
|
2608
|
-
});
|
|
2609
|
-
};
|
|
2610
|
-
if (signal) {
|
|
2611
|
-
if (signal.aborted) {
|
|
2612
|
-
fail(abortError());
|
|
2613
|
-
return;
|
|
2614
|
-
}
|
|
2615
|
-
signal.addEventListener("abort", () => fail(abortError()), { once: true });
|
|
2616
|
-
}
|
|
2617
|
-
worker.onerror = hasher.onerror = (event) => {
|
|
2618
|
-
fail(new Error(`crypto worker crashed: ${String(event?.message ?? event)}`));
|
|
2619
|
-
};
|
|
2620
|
-
worker.onmessage = (event) => {
|
|
2621
|
-
const msg = event.data;
|
|
2622
|
-
if (msg.type === "segment") {
|
|
2623
|
-
onSegment?.(msg.segmentNumber);
|
|
2624
|
-
return;
|
|
2625
|
-
}
|
|
2626
|
-
if (msg.type === "part") {
|
|
2627
|
-
hashing += 1;
|
|
2628
|
-
hasher.postMessage(
|
|
2629
|
-
{ type: "md5", partNumber: msg.partNumber, buffer: msg.buffer },
|
|
2630
|
-
[msg.buffer]
|
|
2631
|
-
);
|
|
2632
|
-
return;
|
|
2633
|
-
}
|
|
2634
|
-
if (msg.type === "done") {
|
|
2635
|
-
workerDone = true;
|
|
2636
|
-
maybeFinish();
|
|
2637
|
-
return;
|
|
2638
|
-
}
|
|
2639
|
-
if (msg.type === "error") fail(new Error(msg.message));
|
|
2640
|
-
};
|
|
2641
|
-
hasher.onmessage = (event) => {
|
|
2642
|
-
const msg = event.data;
|
|
2643
|
-
if (msg.type !== "md5") return;
|
|
2644
|
-
hashing -= 1;
|
|
2645
|
-
const ciphertext = new Uint8Array(msg.buffer);
|
|
2646
|
-
partChain = partChain.then(async () => {
|
|
2647
|
-
if (settled) return;
|
|
2648
|
-
await onPart(msg.partNumber, ciphertext, msg.md5);
|
|
2649
|
-
worker.postMessage({ type: "credit" });
|
|
2650
|
-
}).catch(fail);
|
|
2651
|
-
maybeFinish();
|
|
2652
|
-
};
|
|
2653
|
-
const keyBuf = new ArrayBuffer(key2.length);
|
|
2654
|
-
new Uint8Array(keyBuf).set(key2);
|
|
2655
|
-
const headerBuf = header2.slice().buffer;
|
|
2656
|
-
worker.postMessage(
|
|
2657
|
-
{ type: "start", file, key: keyBuf, header: headerBuf, partSize, totalBytes, credits: initialCredits },
|
|
2658
|
-
[keyBuf, headerBuf]
|
|
2659
|
-
);
|
|
2660
|
-
});
|
|
2661
|
-
}
|
|
2662
|
-
var cryptoWorkerFactory = null;
|
|
2663
|
-
function getCryptoWorkerFactory() {
|
|
2664
|
-
return cryptoWorkerFactory;
|
|
2665
|
-
}
|
|
2666
|
-
var UploadError = class extends Error {
|
|
2667
|
-
constructor(message, code, httpStatus, partNumber, retryable = false) {
|
|
2668
|
-
super(message);
|
|
2669
|
-
this.code = code;
|
|
2670
|
-
this.httpStatus = httpStatus;
|
|
2671
|
-
this.partNumber = partNumber;
|
|
2672
|
-
this.retryable = retryable;
|
|
2673
|
-
this.name = "UploadError";
|
|
2674
|
-
}
|
|
2675
|
-
};
|
|
2676
|
-
function toUploadError(err, fallbackMessage) {
|
|
2677
|
-
if (err instanceof UploadError) return err;
|
|
2678
|
-
if (err instanceof DOMException && err.name === "AbortError") {
|
|
2679
|
-
return new UploadError("Upload aborted", "ABORTED");
|
|
2680
|
-
}
|
|
2681
|
-
return new UploadError(err instanceof Error ? err.message : fallbackMessage, "UNKNOWN");
|
|
2682
|
-
}
|
|
2683
|
-
async function uploadErrorFromResponse(resp, what, code, partNumber) {
|
|
2684
|
-
const refusal = await errorFromResponse(resp, String(resp.status));
|
|
2685
|
-
return new UploadError(
|
|
2686
|
-
`${what}: ${refusal.message}`,
|
|
2687
|
-
resp.status === 426 ? "CLIENT_OUTDATED" : code,
|
|
2688
|
-
resp.status,
|
|
2689
|
-
partNumber
|
|
2690
|
-
);
|
|
2691
|
-
}
|
|
2692
|
-
var log2 = createLogger("upload");
|
|
2693
|
-
var DEFAULT_TRANSPORT_POLICY = {
|
|
2694
|
-
retryBackoffMs: upload_default.upload.RETRY_BACKOFF_MS,
|
|
2695
|
-
retryJitterRatio: upload_default.upload.RETRY_JITTER_RATIO,
|
|
2696
|
-
stallNoticeMs: upload_default.upload.STALL_NOTICE_MS,
|
|
2697
|
-
maxStallMs: upload_default.upload.MAX_STALL_MS,
|
|
2698
|
-
putFloorBytesPerSecond: upload_default.upload.PUT_FLOOR_BYTES_PER_SECOND,
|
|
2699
|
-
putMinDeadlineMs: upload_default.upload.PUT_MIN_DEADLINE_MS,
|
|
2700
|
-
controlTimeoutMs: upload_default.upload.CONTROL_TIMEOUT_MS,
|
|
2701
|
-
completeTimeoutMs: upload_default.upload.COMPLETE_TIMEOUT_MS,
|
|
2702
|
-
poolStart: upload_default.upload.PART_POOL_START,
|
|
2703
|
-
poolMax: upload_default.upload.PART_POOL_MAX,
|
|
2704
|
-
poolMin: upload_default.upload.PART_POOL_MIN,
|
|
2705
|
-
poolGrowRatio: upload_default.upload.PART_POOL_GROW_RATIO,
|
|
2706
|
-
poolShrinkRatio: upload_default.upload.PART_POOL_SHRINK_RATIO,
|
|
2707
|
-
partQueueLimit: upload_default.upload.PART_QUEUE_LIMIT,
|
|
2708
|
-
hedgeMinInflightMs: upload_default.upload.HEDGE_MIN_INFLIGHT_MS,
|
|
2709
|
-
hedgeLagFactor: upload_default.upload.HEDGE_LAG_FACTOR,
|
|
2710
|
-
hedgePollMs: upload_default.upload.HEDGE_POLL_MS,
|
|
2711
|
-
livenessSilenceMs: upload_default.upload.LIVENESS_SILENCE_MS,
|
|
2712
|
-
verifyPollBackoffMs: upload_default.upload.VERIFY_POLL_BACKOFF_MS,
|
|
2713
|
-
verifyFallbackWaitMs: upload_default.upload.VERIFY_FALLBACK_WAIT_MS,
|
|
2714
|
-
speedWindowMs: upload_default.upload.PROGRESS_SPEED_WINDOW_MS
|
|
2715
|
-
};
|
|
2716
|
-
function resolveTransportPolicy(overrides) {
|
|
2717
|
-
return { ...DEFAULT_TRANSPORT_POLICY, ...overrides };
|
|
2718
|
-
}
|
|
2719
|
-
function putDeadlineMs(bytes, policy) {
|
|
2720
|
-
return Math.max(policy.putMinDeadlineMs, Math.ceil(bytes / policy.putFloorBytesPerSecond * 1e3));
|
|
2721
|
-
}
|
|
2722
|
-
function withDeadline(base, ms) {
|
|
2723
|
-
const statics = globalThis.AbortSignal;
|
|
2724
|
-
if (typeof statics?.timeout !== "function") return base;
|
|
2725
|
-
const deadline = statics.timeout(ms);
|
|
2726
|
-
if (!base) return deadline;
|
|
2727
|
-
if (typeof statics.any !== "function") return base;
|
|
2728
|
-
return statics.any([base, deadline]);
|
|
2729
|
-
}
|
|
2730
|
-
async function policyFetch(url, init2, timeoutMs, signal) {
|
|
2731
|
-
try {
|
|
2732
|
-
return await fetch(url, { ...init2, signal: withDeadline(signal, timeoutMs) });
|
|
2733
|
-
} catch (err) {
|
|
2734
|
-
if (signal?.aborted) throw new UploadError("Upload aborted", "ABORTED");
|
|
2735
|
-
throw new UploadError(
|
|
2736
|
-
`Request failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
2737
|
-
"NETWORK",
|
|
2738
|
-
void 0,
|
|
2739
|
-
void 0,
|
|
2740
|
-
true
|
|
2741
|
-
);
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
function classifyStatus2(status) {
|
|
2745
|
-
if (status === 408 || status === 429 || status >= 500) return "retryable";
|
|
2746
|
-
return "terminal";
|
|
2747
|
-
}
|
|
2748
|
-
function classifyStorageFailure(failure) {
|
|
2749
|
-
if (failure.code === "ABORTED") return "terminal";
|
|
2750
|
-
if (failure.code === "BAD_DIGEST") return "retryable";
|
|
2751
|
-
if (failure.httpStatus === void 0) return "retryable";
|
|
2752
|
-
if (failure.httpStatus === 403) return "refresh_url";
|
|
2753
|
-
return classifyStatus2(failure.httpStatus);
|
|
2754
|
-
}
|
|
2755
|
-
function classifyControlFailure(failure) {
|
|
2756
|
-
if (failure.code === "ABORTED") return "terminal";
|
|
2757
|
-
if (failure.httpStatus === void 0) return "retryable";
|
|
2758
|
-
return classifyStatus2(failure.httpStatus);
|
|
2759
|
-
}
|
|
2760
|
-
var StallClock = class {
|
|
2761
|
-
constructor(policy, onState, now = () => performance.now()) {
|
|
2762
|
-
this.policy = policy;
|
|
2763
|
-
this.onState = onState;
|
|
2764
|
-
this.now = now;
|
|
2765
|
-
this.failingSince = null;
|
|
2766
|
-
this.current = "running";
|
|
2767
|
-
this.noticeTimer = null;
|
|
2768
|
-
this.retriesSinceDelivery = 0;
|
|
2769
|
-
}
|
|
2770
|
-
get state() {
|
|
2771
|
-
return this.current;
|
|
2772
|
-
}
|
|
2773
|
-
/**
|
|
2774
|
-
* The connections are known to be dead (the browser went offline, or every
|
|
2775
|
-
* socket of the upload has been silent): say so now. Nothing failed, so the
|
|
2776
|
-
* give-up clock does not start; the next delivery clears it.
|
|
2777
|
-
*/
|
|
2778
|
-
connectionLost() {
|
|
2779
|
-
this.setState("stalled");
|
|
2780
|
-
}
|
|
2781
|
-
/** Storage (or the API) confirmed bytes: the upload is alive. */
|
|
2782
|
-
delivered() {
|
|
2783
|
-
this.failingSince = null;
|
|
2784
|
-
this.retriesSinceDelivery = 0;
|
|
2785
|
-
this.clearNotice();
|
|
2786
|
-
this.setState("running");
|
|
2787
|
-
}
|
|
2788
|
-
/** True when the upload has failed, delivering nothing, for `maxStallMs`. */
|
|
2789
|
-
exhausted() {
|
|
2790
|
-
return this.failingSince !== null && this.now() - this.failingSince >= this.policy.maxStallMs;
|
|
2791
|
-
}
|
|
2792
|
-
/**
|
|
2793
|
-
* A retryable failure happened. Flips to `stalled` once the failing has
|
|
2794
|
-
* lasted long enough — now, or later via a timer, so the notice is on
|
|
2795
|
-
* time even when the next attempt sits out a 30 s backoff.
|
|
2796
|
-
*/
|
|
2797
|
-
failed() {
|
|
2798
|
-
this.retriesSinceDelivery += 1;
|
|
2799
|
-
this.failingSince ?? (this.failingSince = this.now());
|
|
2800
|
-
const remaining = this.policy.stallNoticeMs - (this.now() - this.failingSince);
|
|
2801
|
-
if (remaining <= 0) {
|
|
2802
|
-
this.setState("stalled");
|
|
2803
|
-
} else if (this.noticeTimer === null && this.current === "running") {
|
|
2804
|
-
this.noticeTimer = setTimeout(() => {
|
|
2805
|
-
this.noticeTimer = null;
|
|
2806
|
-
this.setState("stalled");
|
|
2807
|
-
}, remaining);
|
|
3726
|
+
}
|
|
2808
3727
|
}
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
this.clearNotice();
|
|
2813
|
-
}
|
|
2814
|
-
clearNotice() {
|
|
2815
|
-
if (this.noticeTimer !== null) {
|
|
2816
|
-
clearTimeout(this.noticeTimer);
|
|
2817
|
-
this.noticeTimer = null;
|
|
3728
|
+
if (readBytes < totalBytes) throw changed("it ended at");
|
|
3729
|
+
if (pendingBytes > 0 || segmentNumber === 0) {
|
|
3730
|
+
await encryptOneSegment(drainSegment(pendingBytes), true);
|
|
2818
3731
|
}
|
|
3732
|
+
await emitFullParts();
|
|
3733
|
+
if (ciphertextPendingBytes > 0) {
|
|
3734
|
+
await emitPart(await drainCiphertextPart(ciphertextPendingBytes));
|
|
3735
|
+
}
|
|
3736
|
+
} finally {
|
|
3737
|
+
reader.releaseLock();
|
|
2819
3738
|
}
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
3739
|
+
}
|
|
3740
|
+
function blobToSegmentStream(blob, segmentSize) {
|
|
3741
|
+
let offset = 0;
|
|
3742
|
+
return new ReadableStream({
|
|
3743
|
+
async pull(controller) {
|
|
3744
|
+
if (offset >= blob.size) {
|
|
3745
|
+
controller.close();
|
|
3746
|
+
return;
|
|
3747
|
+
}
|
|
3748
|
+
const end = Math.min(offset + segmentSize, blob.size);
|
|
3749
|
+
try {
|
|
3750
|
+
const buf = await blob.slice(offset, end).arrayBuffer();
|
|
3751
|
+
controller.enqueue(new Uint8Array(buf));
|
|
3752
|
+
offset = end;
|
|
3753
|
+
} catch (e) {
|
|
3754
|
+
controller.error(e);
|
|
3755
|
+
}
|
|
2831
3756
|
}
|
|
2832
|
-
const onAbort = () => {
|
|
2833
|
-
clearTimeout(timer);
|
|
2834
|
-
reject(new UploadError("Upload aborted", "ABORTED"));
|
|
2835
|
-
};
|
|
2836
|
-
const timer = setTimeout(() => {
|
|
2837
|
-
signal?.removeEventListener("abort", onAbort);
|
|
2838
|
-
resolve2();
|
|
2839
|
-
}, ms);
|
|
2840
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2841
3757
|
});
|
|
2842
3758
|
}
|
|
2843
|
-
|
|
2844
|
-
const {
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
if (
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
3759
|
+
function runCryptoPipelineInWorker(worker, hasher, options) {
|
|
3760
|
+
const { file, key: key2, header: header2, partSize, totalBytes, signal, initialCredits, onSegment, onPart } = options;
|
|
3761
|
+
return new Promise((resolve2, reject) => {
|
|
3762
|
+
let settled = false;
|
|
3763
|
+
let workerDone = false;
|
|
3764
|
+
let hashing = 0;
|
|
3765
|
+
let partChain = Promise.resolve();
|
|
3766
|
+
const fail = (err) => {
|
|
3767
|
+
if (settled) return;
|
|
3768
|
+
settled = true;
|
|
3769
|
+
reject(err);
|
|
3770
|
+
};
|
|
3771
|
+
const maybeFinish = () => {
|
|
3772
|
+
if (!workerDone || hashing > 0) return;
|
|
3773
|
+
void partChain.then(() => {
|
|
3774
|
+
if (settled) return;
|
|
3775
|
+
settled = true;
|
|
3776
|
+
resolve2();
|
|
3777
|
+
});
|
|
3778
|
+
};
|
|
3779
|
+
if (signal) {
|
|
3780
|
+
if (signal.aborted) {
|
|
3781
|
+
fail(abortError());
|
|
3782
|
+
return;
|
|
2864
3783
|
}
|
|
2865
|
-
|
|
2866
|
-
refreshedInARow = failureClass === "refresh_url" ? refreshedInARow + 1 : 0;
|
|
2867
|
-
const immediate = failureClass === "refresh_url" && refreshedInARow === 1;
|
|
2868
|
-
const base = policy.retryBackoffMs[Math.min(attempt, policy.retryBackoffMs.length - 1)] ?? 0;
|
|
2869
|
-
const jitter = 1 + (Math.random() * 2 - 1) * policy.retryJitterRatio;
|
|
2870
|
-
const delay = immediate ? 0 : Math.round(base * jitter);
|
|
2871
|
-
log2.debug(
|
|
2872
|
-
`retry ${what} attempt=${attempt + 2} in ${delay}ms after ${failure.code}${failure.httpStatus ? " " + failure.httpStatus : ""} (${failureClass})`
|
|
2873
|
-
);
|
|
2874
|
-
after = failureClass;
|
|
2875
|
-
await abortableDelay(delay, signal);
|
|
3784
|
+
signal.addEventListener("abort", () => fail(abortError()), { once: true });
|
|
2876
3785
|
}
|
|
2877
|
-
|
|
3786
|
+
worker.onerror = hasher.onerror = (event) => {
|
|
3787
|
+
fail(new Error(`crypto worker crashed: ${String(event?.message ?? event)}`));
|
|
3788
|
+
};
|
|
3789
|
+
worker.onmessage = (event) => {
|
|
3790
|
+
const msg = event.data;
|
|
3791
|
+
if (msg.type === "segment") {
|
|
3792
|
+
onSegment?.(msg.segmentNumber);
|
|
3793
|
+
return;
|
|
3794
|
+
}
|
|
3795
|
+
if (msg.type === "part") {
|
|
3796
|
+
hashing += 1;
|
|
3797
|
+
hasher.postMessage(
|
|
3798
|
+
{ type: "md5", partNumber: msg.partNumber, buffer: msg.buffer },
|
|
3799
|
+
[msg.buffer]
|
|
3800
|
+
);
|
|
3801
|
+
return;
|
|
3802
|
+
}
|
|
3803
|
+
if (msg.type === "done") {
|
|
3804
|
+
workerDone = true;
|
|
3805
|
+
maybeFinish();
|
|
3806
|
+
return;
|
|
3807
|
+
}
|
|
3808
|
+
if (msg.type === "error") fail(new Error(msg.message));
|
|
3809
|
+
};
|
|
3810
|
+
hasher.onmessage = (event) => {
|
|
3811
|
+
const msg = event.data;
|
|
3812
|
+
if (msg.type !== "md5") return;
|
|
3813
|
+
hashing -= 1;
|
|
3814
|
+
const ciphertext = new Uint8Array(msg.buffer);
|
|
3815
|
+
partChain = partChain.then(async () => {
|
|
3816
|
+
if (settled) return;
|
|
3817
|
+
await onPart(msg.partNumber, ciphertext, msg.md5);
|
|
3818
|
+
worker.postMessage({ type: "credit" });
|
|
3819
|
+
}).catch(fail);
|
|
3820
|
+
maybeFinish();
|
|
3821
|
+
};
|
|
3822
|
+
const keyBuf = new ArrayBuffer(key2.length);
|
|
3823
|
+
new Uint8Array(keyBuf).set(key2);
|
|
3824
|
+
const headerBuf = header2.slice().buffer;
|
|
3825
|
+
worker.postMessage(
|
|
3826
|
+
{ type: "start", file, key: keyBuf, header: headerBuf, partSize, totalBytes, credits: initialCredits },
|
|
3827
|
+
[keyBuf, headerBuf]
|
|
3828
|
+
);
|
|
3829
|
+
});
|
|
3830
|
+
}
|
|
3831
|
+
var cryptoWorkerFactory = null;
|
|
3832
|
+
function getCryptoWorkerFactory() {
|
|
3833
|
+
return cryptoWorkerFactory;
|
|
2878
3834
|
}
|
|
2879
3835
|
var log3 = createLogger("upload");
|
|
3836
|
+
function silenceHeard(look) {
|
|
3837
|
+
if (look.now - look.lastLookAt > 2 * look.every) return false;
|
|
3838
|
+
return look.now - look.lastActivityAt >= look.silenceMs;
|
|
3839
|
+
}
|
|
2880
3840
|
var BAD_DIGEST_MARKER = "<Code>BadDigest</Code>";
|
|
2881
3841
|
var HEDGE_MAX_PER_PART = 2;
|
|
2882
3842
|
function createAuthHeaders(auth) {
|
|
@@ -2910,7 +3870,7 @@ async function multipartUpload(options) {
|
|
|
2910
3870
|
async function multipartUploadFromFile(options) {
|
|
2911
3871
|
const { file, partSize } = options;
|
|
2912
3872
|
return multipartUploadStream({
|
|
2913
|
-
stream: blobToSegmentStream(file,
|
|
3873
|
+
stream: blobToSegmentStream(file, parseHeader(options.header).segmentSize),
|
|
2914
3874
|
totalBytes: file.size,
|
|
2915
3875
|
sealId: options.sealId,
|
|
2916
3876
|
fileId: options.fileId,
|
|
@@ -2946,6 +3906,7 @@ async function multipartUploadStream(options) {
|
|
|
2946
3906
|
onConflict
|
|
2947
3907
|
} = options;
|
|
2948
3908
|
const policy = resolveTransportPolicy(options.transport);
|
|
3909
|
+
const time = policy.clock;
|
|
2949
3910
|
if (key2.length !== 32) {
|
|
2950
3911
|
throw new UploadError("Key must be 32 bytes", "ENCRYPTION_FAILED");
|
|
2951
3912
|
}
|
|
@@ -2968,7 +3929,7 @@ async function multipartUploadStream(options) {
|
|
|
2968
3929
|
let firstPutStartedAt = null;
|
|
2969
3930
|
let speedBps;
|
|
2970
3931
|
const noteDelivered = (bytes) => {
|
|
2971
|
-
const now =
|
|
3932
|
+
const now = time.now();
|
|
2972
3933
|
speedSamples.push({ at: now, bytes });
|
|
2973
3934
|
const windowStart = Math.max(firstPutStartedAt ?? now, now - policy.speedWindowMs);
|
|
2974
3935
|
while (speedSamples.length > 0 && speedSamples[0].at < windowStart) speedSamples.shift();
|
|
@@ -2993,10 +3954,9 @@ async function multipartUploadStream(options) {
|
|
|
2993
3954
|
attempt: clock.retriesSinceDelivery + 1
|
|
2994
3955
|
});
|
|
2995
3956
|
};
|
|
2996
|
-
const clock = new StallClock(policy, () => report(lastPhase));
|
|
3957
|
+
const clock = new StallClock(policy, () => report(lastPhase), time.now);
|
|
2997
3958
|
const teardown = new AbortController();
|
|
2998
|
-
const
|
|
2999
|
-
const runSignal = signal && typeof combine === "function" ? combine([signal, teardown.signal]) : signal ?? teardown.signal;
|
|
3959
|
+
const runSignal = signal ? anySignal([signal, teardown.signal]) : teardown.signal;
|
|
3000
3960
|
const controlStep = (what, step) => retrying(step, { clock, policy, signal: runSignal, classify: classifyControlFailure, what });
|
|
3001
3961
|
const abortUpload = async (_deliberate) => {
|
|
3002
3962
|
keyCopy.fill(0);
|
|
@@ -3005,7 +3965,7 @@ async function multipartUploadStream(options) {
|
|
|
3005
3965
|
const abortSessionBestEffort = (discardFile) => {
|
|
3006
3966
|
if (!uploadId) return;
|
|
3007
3967
|
try {
|
|
3008
|
-
void
|
|
3968
|
+
void transportFetch(`${baseUrl}/upload/multipart/abort`, {
|
|
3009
3969
|
method: "POST",
|
|
3010
3970
|
headers: { "Content-Type": "application/json", ...authHeaders },
|
|
3011
3971
|
// `discard_file`: the caller cancelled, so the row this upload was
|
|
@@ -3018,6 +3978,7 @@ async function multipartUploadStream(options) {
|
|
|
3018
3978
|
} catch {
|
|
3019
3979
|
}
|
|
3020
3980
|
};
|
|
3981
|
+
let streamed = false;
|
|
3021
3982
|
const presignedUrlCache = /* @__PURE__ */ new Map();
|
|
3022
3983
|
let presignPrefetchInFlight = null;
|
|
3023
3984
|
let uploadError = null;
|
|
@@ -3033,10 +3994,10 @@ async function multipartUploadStream(options) {
|
|
|
3033
3994
|
let roomWaiters = [];
|
|
3034
3995
|
const fullPartPace = [];
|
|
3035
3996
|
const partsInFlight = /* @__PURE__ */ new Set();
|
|
3036
|
-
let lastSocketActivityAt =
|
|
3997
|
+
let lastSocketActivityAt = time.now();
|
|
3037
3998
|
let socketActivityObservable = false;
|
|
3038
3999
|
const reconnectAllParts = (why) => {
|
|
3039
|
-
lastSocketActivityAt =
|
|
4000
|
+
lastSocketActivityAt = time.now();
|
|
3040
4001
|
for (const part of [...partsInFlight]) part.reconnect(why);
|
|
3041
4002
|
};
|
|
3042
4003
|
function recordDelivery(item, elapsedMs) {
|
|
@@ -3050,7 +4011,7 @@ async function multipartUploadStream(options) {
|
|
|
3050
4011
|
poolCeiling = poolSize;
|
|
3051
4012
|
lastRoundRate = null;
|
|
3052
4013
|
round += 1;
|
|
3053
|
-
roundStartedAt =
|
|
4014
|
+
roundStartedAt = time.now();
|
|
3054
4015
|
roundBytes = 0;
|
|
3055
4016
|
roundDeliveries = 0;
|
|
3056
4017
|
return;
|
|
@@ -3060,7 +4021,7 @@ async function multipartUploadStream(options) {
|
|
|
3060
4021
|
roundBytes += bytes;
|
|
3061
4022
|
roundDeliveries += 1;
|
|
3062
4023
|
if (roundDeliveries < poolSize || roundStartedAt === null) return;
|
|
3063
|
-
const roundMs =
|
|
4024
|
+
const roundMs = time.now() - roundStartedAt;
|
|
3064
4025
|
if (roundMs <= 0) return;
|
|
3065
4026
|
const roundRate = roundBytes / roundMs;
|
|
3066
4027
|
if (lastRoundRate === null) {
|
|
@@ -3072,12 +4033,12 @@ async function multipartUploadStream(options) {
|
|
|
3072
4033
|
}
|
|
3073
4034
|
lastRoundRate = roundRate;
|
|
3074
4035
|
round += 1;
|
|
3075
|
-
roundStartedAt =
|
|
4036
|
+
roundStartedAt = time.now();
|
|
3076
4037
|
roundBytes = 0;
|
|
3077
4038
|
roundDeliveries = 0;
|
|
3078
4039
|
}
|
|
3079
4040
|
function hedgeDue(item, lastLaunchAt) {
|
|
3080
|
-
const inFlightMs =
|
|
4041
|
+
const inFlightMs = time.now() - lastLaunchAt;
|
|
3081
4042
|
if (inFlightMs < policy.hedgeMinInflightMs) return false;
|
|
3082
4043
|
const flowsNow = runningParts.size;
|
|
3083
4044
|
const peers = fullPartPace.filter((p) => p.flows >= flowsNow).map((p) => p.rate);
|
|
@@ -3087,22 +4048,22 @@ async function multipartUploadStream(options) {
|
|
|
3087
4048
|
return item.ciphertext.length / inFlightMs * policy.hedgeLagFactor < medianRate;
|
|
3088
4049
|
}
|
|
3089
4050
|
async function transportPut(ciphertext, contentMd52, partNumber, presignedUrl, copySignal, liveness) {
|
|
3090
|
-
if (typeof XMLHttpRequest !== "undefined" && typeof document !== "undefined") {
|
|
4051
|
+
if (!hostNamedTransport() && typeof XMLHttpRequest !== "undefined" && typeof document !== "undefined") {
|
|
3091
4052
|
return await new Promise((resolve2, reject) => {
|
|
3092
4053
|
const xhr = new XMLHttpRequest();
|
|
3093
4054
|
let settled = false;
|
|
3094
4055
|
socketActivityObservable = true;
|
|
3095
4056
|
xhr.upload.onprogress = (event) => {
|
|
3096
4057
|
liveness.onSocketActivity(event.loaded, event.lengthComputable ? event.total : ciphertext.length);
|
|
3097
|
-
|
|
3098
|
-
|
|
4058
|
+
cancelDeadline();
|
|
4059
|
+
cancelDeadline = armDeadline();
|
|
3099
4060
|
};
|
|
3100
|
-
const armDeadline = () =>
|
|
4061
|
+
const armDeadline = () => time.after(putDeadlineMs(ciphertext.length, policy), () => {
|
|
3101
4062
|
if (!settled) liveness.onDeadline();
|
|
3102
|
-
}
|
|
3103
|
-
let
|
|
4063
|
+
});
|
|
4064
|
+
let cancelDeadline = armDeadline();
|
|
3104
4065
|
const cleanup = () => {
|
|
3105
|
-
|
|
4066
|
+
cancelDeadline();
|
|
3106
4067
|
copySignal.removeEventListener("abort", abortFromSignal);
|
|
3107
4068
|
};
|
|
3108
4069
|
const abortFromSignal = () => {
|
|
@@ -3148,7 +4109,7 @@ async function multipartUploadStream(options) {
|
|
|
3148
4109
|
}
|
|
3149
4110
|
let putResponse;
|
|
3150
4111
|
try {
|
|
3151
|
-
putResponse = await
|
|
4112
|
+
putResponse = await transportFetch(presignedUrl, {
|
|
3152
4113
|
method: "PUT",
|
|
3153
4114
|
headers: { "Content-MD5": contentMd52 },
|
|
3154
4115
|
body: ciphertext,
|
|
@@ -3200,9 +4161,11 @@ async function multipartUploadStream(options) {
|
|
|
3200
4161
|
return outcome.etag;
|
|
3201
4162
|
}
|
|
3202
4163
|
async function hedgedPut(item, presignedUrl) {
|
|
3203
|
-
const t0 =
|
|
3204
|
-
let
|
|
4164
|
+
const t0 = time.now();
|
|
4165
|
+
let stopHedgeTicker = () => {
|
|
4166
|
+
};
|
|
3205
4167
|
let hedgeCount = 0;
|
|
4168
|
+
let deadlines = 0;
|
|
3206
4169
|
let lastLaunchAt = t0;
|
|
3207
4170
|
let current = null;
|
|
3208
4171
|
let replace = () => {
|
|
@@ -3227,14 +4190,24 @@ async function multipartUploadStream(options) {
|
|
|
3227
4190
|
else runSignal?.addEventListener("abort", onUploadEnd, { once: true });
|
|
3228
4191
|
const copy = { ctl, unsent: true, ended: Promise.resolve() };
|
|
3229
4192
|
current = copy;
|
|
3230
|
-
lastLaunchAt =
|
|
4193
|
+
lastLaunchAt = time.now();
|
|
3231
4194
|
lastSocketActivityAt = lastLaunchAt;
|
|
3232
4195
|
copy.ended = transportPut(item.ciphertext, item.contentMd5, item.partNumber, presignedUrl, ctl.signal, {
|
|
3233
4196
|
onSocketActivity: (loaded, total) => {
|
|
3234
|
-
lastSocketActivityAt =
|
|
4197
|
+
lastSocketActivityAt = time.now();
|
|
3235
4198
|
copy.unsent = loaded < total;
|
|
3236
4199
|
},
|
|
3237
|
-
onDeadline: () =>
|
|
4200
|
+
onDeadline: () => {
|
|
4201
|
+
if (++deadlines < 2) return replace("copy deadline", false, false);
|
|
4202
|
+
if (current !== copy) return;
|
|
4203
|
+
settle(() => reject(new UploadError(
|
|
4204
|
+
`Part ${item.partNumber}: no answer from storage after a reconnect`,
|
|
4205
|
+
"NETWORK",
|
|
4206
|
+
void 0,
|
|
4207
|
+
item.partNumber,
|
|
4208
|
+
true
|
|
4209
|
+
)));
|
|
4210
|
+
}
|
|
3238
4211
|
}).then(
|
|
3239
4212
|
(outcome) => {
|
|
3240
4213
|
if (current !== copy) return;
|
|
@@ -3253,11 +4226,11 @@ async function multipartUploadStream(options) {
|
|
|
3253
4226
|
runSignal?.removeEventListener("abort", onUploadEnd);
|
|
3254
4227
|
});
|
|
3255
4228
|
};
|
|
3256
|
-
replace = (why, spendsTicket) => {
|
|
4229
|
+
replace = (why, spendsTicket, handsBack = true) => {
|
|
3257
4230
|
const old = current;
|
|
3258
4231
|
if (settled || old === null || signal?.aborted) return;
|
|
3259
4232
|
current = null;
|
|
3260
|
-
hedgeCount = spendsTicket ? hedgeCount + 1 : 0;
|
|
4233
|
+
hedgeCount = spendsTicket ? hedgeCount + 1 : handsBack ? 0 : hedgeCount;
|
|
3261
4234
|
log3.debug(`${spendsTicket ? "replace" : "reconnect"} part=${item.partNumber} (${why})`);
|
|
3262
4235
|
old.ctl.abort();
|
|
3263
4236
|
void old.ended.then(() => {
|
|
@@ -3270,14 +4243,14 @@ async function multipartUploadStream(options) {
|
|
|
3270
4243
|
});
|
|
3271
4244
|
};
|
|
3272
4245
|
launch();
|
|
3273
|
-
|
|
4246
|
+
stopHedgeTicker = time.every(policy.hedgePollMs, () => {
|
|
3274
4247
|
if (settled || signal?.aborted || current === null) return;
|
|
3275
4248
|
if (hedgeCount >= HEDGE_MAX_PER_PART) return;
|
|
3276
4249
|
if (!hedgeDue(item, lastLaunchAt)) return;
|
|
3277
|
-
replace(`slower than its peers after ${Math.round(
|
|
3278
|
-
}
|
|
4250
|
+
replace(`slower than its peers after ${Math.round(time.now() - t0)}ms`, true);
|
|
4251
|
+
});
|
|
3279
4252
|
});
|
|
3280
|
-
const tPut =
|
|
4253
|
+
const tPut = time.now();
|
|
3281
4254
|
uploadedParts.push({ part_number: item.partNumber, etag });
|
|
3282
4255
|
processedBytes += item.ciphertext.length;
|
|
3283
4256
|
noteDelivered(item.ciphertext.length);
|
|
@@ -3292,7 +4265,7 @@ async function multipartUploadStream(options) {
|
|
|
3292
4265
|
partsInFlight.delete(inFlight);
|
|
3293
4266
|
replace = () => {
|
|
3294
4267
|
};
|
|
3295
|
-
|
|
4268
|
+
stopHedgeTicker();
|
|
3296
4269
|
current?.ctl.abort();
|
|
3297
4270
|
}
|
|
3298
4271
|
}
|
|
@@ -3358,7 +4331,7 @@ async function multipartUploadStream(options) {
|
|
|
3358
4331
|
}
|
|
3359
4332
|
async function runPart(item) {
|
|
3360
4333
|
await yieldToMain();
|
|
3361
|
-
roundStartedAt ?? (roundStartedAt =
|
|
4334
|
+
roundStartedAt ?? (roundStartedAt = time.now());
|
|
3362
4335
|
firstPutStartedAt ?? (firstPutStartedAt = roundStartedAt);
|
|
3363
4336
|
item.round = round;
|
|
3364
4337
|
item.flowsAtStart = runningParts.size;
|
|
@@ -3427,15 +4400,19 @@ async function multipartUploadStream(options) {
|
|
|
3427
4400
|
scope.addEventListener?.("online", onOnline);
|
|
3428
4401
|
scope.addEventListener?.("offline", onOffline);
|
|
3429
4402
|
connection?.addEventListener?.("change", onConnectionChange);
|
|
3430
|
-
const
|
|
3431
|
-
|
|
3432
|
-
|
|
4403
|
+
const every = Math.max(10, policy.livenessSilenceMs / 4);
|
|
4404
|
+
let lastLookAt = time.now();
|
|
4405
|
+
const stopSilenceCheck = time.every(every, () => {
|
|
4406
|
+
const now = time.now();
|
|
4407
|
+
const silent = silenceHeard({ now, lastLookAt, every, lastActivityAt: lastSocketActivityAt, silenceMs: policy.livenessSilenceMs });
|
|
4408
|
+
lastLookAt = now;
|
|
4409
|
+
if (!socketActivityObservable || partsInFlight.size === 0 || !silent) return;
|
|
3433
4410
|
if (![...partsInFlight].some((part) => part.hasUnsentBytes())) return;
|
|
3434
4411
|
clock.connectionLost();
|
|
3435
4412
|
reconnectAllParts("every socket silent");
|
|
3436
|
-
}
|
|
4413
|
+
});
|
|
3437
4414
|
return () => {
|
|
3438
|
-
|
|
4415
|
+
stopSilenceCheck();
|
|
3439
4416
|
scope.removeEventListener?.("online", onOnline);
|
|
3440
4417
|
scope.removeEventListener?.("offline", onOffline);
|
|
3441
4418
|
connection?.removeEventListener?.("change", onConnectionChange);
|
|
@@ -3556,6 +4533,7 @@ async function multipartUploadStream(options) {
|
|
|
3556
4533
|
if (signal?.aborted) {
|
|
3557
4534
|
await abortUpload(signal?.aborted === true);
|
|
3558
4535
|
}
|
|
4536
|
+
streamed = true;
|
|
3559
4537
|
onStreamed?.();
|
|
3560
4538
|
let completeAttempted = false;
|
|
3561
4539
|
let conflictWith;
|
|
@@ -3596,7 +4574,8 @@ async function multipartUploadStream(options) {
|
|
|
3596
4574
|
} catch (error) {
|
|
3597
4575
|
keyCopy.fill(0);
|
|
3598
4576
|
const failure = toUploadError(error, "Unknown upload error");
|
|
3599
|
-
|
|
4577
|
+
const askLater = streamed && failure.code !== "ABORTED" && (failure.httpStatus === void 0 || failure.httpStatus >= 500);
|
|
4578
|
+
if (!askLater) abortSessionBestEffort(failure.code === "ABORTED");
|
|
3600
4579
|
throw failure;
|
|
3601
4580
|
} finally {
|
|
3602
4581
|
stopWatchingLiveness();
|
|
@@ -3604,88 +4583,6 @@ async function multipartUploadStream(options) {
|
|
|
3604
4583
|
teardown.abort();
|
|
3605
4584
|
}
|
|
3606
4585
|
}
|
|
3607
|
-
var ENCRYPTED_FILE_FALLBACK = "Encrypted file";
|
|
3608
|
-
var ENCRYPTED_MIME_FALLBACK = "application/octet-stream";
|
|
3609
|
-
function metadataFieldAAD(field) {
|
|
3610
|
-
return new TextEncoder().encode(`field:${field}`);
|
|
3611
|
-
}
|
|
3612
|
-
async function encryptMetadataField(plaintext, key2, field) {
|
|
3613
|
-
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
3614
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
3615
|
-
"raw",
|
|
3616
|
-
key2.buffer.slice(key2.byteOffset, key2.byteOffset + key2.byteLength),
|
|
3617
|
-
{ name: "AES-GCM" },
|
|
3618
|
-
false,
|
|
3619
|
-
["encrypt"]
|
|
3620
|
-
);
|
|
3621
|
-
const params = { name: "AES-GCM", iv: nonce, tagLength: 128 };
|
|
3622
|
-
if (field) {
|
|
3623
|
-
const aad = metadataFieldAAD(field);
|
|
3624
|
-
params.additionalData = aad.buffer.slice(aad.byteOffset, aad.byteOffset + aad.byteLength);
|
|
3625
|
-
}
|
|
3626
|
-
const ciphertext = await crypto.subtle.encrypt(params, cryptoKey, new TextEncoder().encode(plaintext));
|
|
3627
|
-
return { ciphertext: bytesToBase64(new Uint8Array(ciphertext)), nonce: bytesToBase64(nonce) };
|
|
3628
|
-
}
|
|
3629
|
-
function isAeadTagFailure(error) {
|
|
3630
|
-
const name2 = error?.name;
|
|
3631
|
-
return name2 === "OperationError";
|
|
3632
|
-
}
|
|
3633
|
-
async function decryptMetadataField(encrypted, nonce, key2, field) {
|
|
3634
|
-
const ciphertext = base64ToBytes(encrypted);
|
|
3635
|
-
const iv = base64ToBytes(nonce);
|
|
3636
|
-
const run = async (aad) => {
|
|
3637
|
-
const params = { name: "AES-GCM", iv };
|
|
3638
|
-
if (aad) params.additionalData = aad;
|
|
3639
|
-
const plaintext = await crypto.subtle.decrypt(params, key2, ciphertext);
|
|
3640
|
-
return new TextDecoder().decode(plaintext);
|
|
3641
|
-
};
|
|
3642
|
-
if (!field) return run(void 0);
|
|
3643
|
-
try {
|
|
3644
|
-
return await run(metadataFieldAAD(field));
|
|
3645
|
-
} catch (boundError) {
|
|
3646
|
-
if (!isAeadTagFailure(boundError)) throw boundError;
|
|
3647
|
-
return run(void 0);
|
|
3648
|
-
}
|
|
3649
|
-
}
|
|
3650
|
-
async function decryptFileMetadata(file, key2) {
|
|
3651
|
-
let name2 = file.name || ENCRYPTED_FILE_FALLBACK;
|
|
3652
|
-
let mime = file.mime || ENCRYPTED_MIME_FALLBACK;
|
|
3653
|
-
if (file.name_encrypted && file.name_nonce && file.name_nonce.length > 0) {
|
|
3654
|
-
try {
|
|
3655
|
-
name2 = await decryptMetadataField(file.name_encrypted, file.name_nonce, key2, "name");
|
|
3656
|
-
} catch {
|
|
3657
|
-
name2 = ENCRYPTED_FILE_FALLBACK;
|
|
3658
|
-
}
|
|
3659
|
-
}
|
|
3660
|
-
if (file.mime_encrypted && file.mime_nonce && file.mime_nonce.length > 0) {
|
|
3661
|
-
try {
|
|
3662
|
-
mime = await decryptMetadataField(file.mime_encrypted, file.mime_nonce, key2, "mime");
|
|
3663
|
-
} catch {
|
|
3664
|
-
mime = ENCRYPTED_MIME_FALLBACK;
|
|
3665
|
-
}
|
|
3666
|
-
}
|
|
3667
|
-
return { name: name2, mime };
|
|
3668
|
-
}
|
|
3669
|
-
async function importKeyForMetadata(keyBytes) {
|
|
3670
|
-
return crypto.subtle.importKey(
|
|
3671
|
-
"raw",
|
|
3672
|
-
keyBytes,
|
|
3673
|
-
{ name: "AES-GCM" },
|
|
3674
|
-
false,
|
|
3675
|
-
["decrypt"]
|
|
3676
|
-
);
|
|
3677
|
-
}
|
|
3678
|
-
async function decryptFileMetadataWithBytes(file, keyBytes) {
|
|
3679
|
-
try {
|
|
3680
|
-
const key2 = await importKeyForMetadata(keyBytes);
|
|
3681
|
-
return decryptFileMetadata(file, key2);
|
|
3682
|
-
} catch {
|
|
3683
|
-
return {
|
|
3684
|
-
name: file.name || ENCRYPTED_FILE_FALLBACK,
|
|
3685
|
-
mime: file.mime || ENCRYPTED_MIME_FALLBACK
|
|
3686
|
-
};
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
4586
|
var DEFAULT_POLICY = {
|
|
3690
4587
|
multipartThresholdBytes: upload_default.upload.MULTIPART_THRESHOLD_BYTES,
|
|
3691
4588
|
partSizeBytes: upload_default.upload.DEFAULT_PART_SIZE_BYTES,
|
|
@@ -3761,6 +4658,7 @@ var UploadSession = class {
|
|
|
3761
4658
|
constructor(init2, run) {
|
|
3762
4659
|
this.run = run;
|
|
3763
4660
|
this.cancelled = false;
|
|
4661
|
+
this.running = null;
|
|
3764
4662
|
this.ctx = init2.ctx;
|
|
3765
4663
|
this.policy = init2.policy;
|
|
3766
4664
|
this.sealId = init2.sealId;
|
|
@@ -3790,13 +4688,12 @@ var UploadSession = class {
|
|
|
3790
4688
|
if (this.cancelled) {
|
|
3791
4689
|
throw new UploadError("Upload session was cancelled", "ABORTED");
|
|
3792
4690
|
}
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
}
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
}
|
|
4691
|
+
this.running ?? (this.running = this.run(this, callbacks).catch((err) => {
|
|
4692
|
+
throw attachSession(toUploadError(err, "Upload failed"), this);
|
|
4693
|
+
}).finally(() => {
|
|
4694
|
+
this.running = null;
|
|
4695
|
+
}));
|
|
4696
|
+
return this.running;
|
|
3800
4697
|
}
|
|
3801
4698
|
/**
|
|
3802
4699
|
* Give the registration back. A seal this upload created is revoked
|
|
@@ -3804,15 +4701,29 @@ var UploadSession = class {
|
|
|
3804
4701
|
* which returns their bytes to the quota (the backend charges at
|
|
3805
4702
|
* registration, not at delivery).
|
|
3806
4703
|
*
|
|
4704
|
+
* A host without an owner token (an organisation's seal under a member's
|
|
4705
|
+
* session) gives its rows back by its own route, `ctx.revokeFilePath`.
|
|
4706
|
+
*
|
|
3807
4707
|
* Best effort: the caller is cancelling, not asking for a second failure
|
|
3808
|
-
* to handle. What this misses — a
|
|
3809
|
-
*
|
|
3810
|
-
* stale `pending` rows collects.
|
|
4708
|
+
* to handle. What this misses — a request that does not get through — the
|
|
4709
|
+
* server's sweep of stale `pending` rows collects.
|
|
3811
4710
|
*/
|
|
3812
4711
|
async cancel() {
|
|
3813
4712
|
this.cancelled = true;
|
|
3814
4713
|
const ownerToken = ownerTokenOf(this.ctx);
|
|
3815
|
-
if (!ownerToken)
|
|
4714
|
+
if (!ownerToken) {
|
|
4715
|
+
const template = this.ctx.revokeFilePath;
|
|
4716
|
+
if (!template || this.createdSeal) return;
|
|
4717
|
+
for (const entry of this.pending) {
|
|
4718
|
+
const path = template.replace("{sealId}", encodeURIComponent(this.sealId)).replace("{fileId}", encodeURIComponent(entry.fileId));
|
|
4719
|
+
await transportFetch(`${this.ctx.baseUrl}${path}`, {
|
|
4720
|
+
method: "DELETE",
|
|
4721
|
+
headers: createAuthHeaders(uploadAuthFor(this.ctx)),
|
|
4722
|
+
credentials: this.ctx.credentials ?? "include"
|
|
4723
|
+
}).catch(() => void 0);
|
|
4724
|
+
}
|
|
4725
|
+
return;
|
|
4726
|
+
}
|
|
3816
4727
|
const api = new SealApi({ baseUrl: this.ctx.baseUrl, credentials: this.ctx.credentials ?? "include" });
|
|
3817
4728
|
try {
|
|
3818
4729
|
if (this.createdSeal) {
|
|
@@ -3839,8 +4750,7 @@ function pairRegisteredRows(rows, sentDigests, what) {
|
|
|
3839
4750
|
throw new Error(`${what}: file record ${i} has no id \u2014 cannot upload ciphertext`);
|
|
3840
4751
|
}
|
|
3841
4752
|
if (row.sha256_hex === void 0) {
|
|
3842
|
-
|
|
3843
|
-
throw new Error(`${what}: file record ${i} carries no sha256_hex \u2014 refusing to pair ${n} files by position alone`);
|
|
4753
|
+
throw new Error(`${what}: file record ${i} carries no sha256_hex \u2014 refusing to pair it by position`);
|
|
3844
4754
|
}
|
|
3845
4755
|
if (row.sha256_hex !== sentDigests[i]) {
|
|
3846
4756
|
throw new Error(
|
|
@@ -3918,6 +4828,7 @@ async function uploadPresignedSmallFile(opts) {
|
|
|
3918
4828
|
...ctx.onConflict ? { on_conflict: ctx.onConflict } : {}
|
|
3919
4829
|
})
|
|
3920
4830
|
}, transport.controlTimeoutMs, signal);
|
|
4831
|
+
if (response.status === 409) return false;
|
|
3921
4832
|
if (!response.ok) throw await uploadErrorFromResponse(response, `Upload confirm failed${suffix}`, "NETWORK");
|
|
3922
4833
|
const body = await response.json().catch(() => null);
|
|
3923
4834
|
if (typeof body?.conflict_with === "string") opts.onConflictWith(body.conflict_with);
|
|
@@ -3943,15 +4854,16 @@ async function readUploadStatus(ctx, sealId, digest, authHeaders, transport, sig
|
|
|
3943
4854
|
}
|
|
3944
4855
|
}
|
|
3945
4856
|
var REJECTED_STATUSES = /* @__PURE__ */ new Set(["failed", "size_mismatch", "verification_error"]);
|
|
4857
|
+
var DELIVERED_STATUSES = /* @__PURE__ */ new Set(["verified", "pending_verification"]);
|
|
3946
4858
|
async function awaitVerification(opts) {
|
|
3947
4859
|
const { ctx, sealId, digest, authHeaders, transport, signal, label } = opts;
|
|
3948
4860
|
const ceilingMs = transport.verifyFallbackWaitMs;
|
|
3949
4861
|
const startedAt = performance.now();
|
|
3950
4862
|
const pauses = transport.verifyPollBackoffMs;
|
|
3951
4863
|
for (let poll = 0; ; poll++) {
|
|
3952
|
-
const
|
|
3953
|
-
if (performance.now() - startedAt +
|
|
3954
|
-
if (
|
|
4864
|
+
const pause2 = pauses[Math.min(poll, pauses.length - 1)] ?? 0;
|
|
4865
|
+
if (performance.now() - startedAt + pause2 > ceilingMs) return "pending";
|
|
4866
|
+
if (pause2 > 0) await abortableDelay(pause2, signal);
|
|
3955
4867
|
const status = await readUploadStatus(ctx, sealId, digest, authHeaders, transport, signal);
|
|
3956
4868
|
if (status === "verified") return "verified";
|
|
3957
4869
|
if (status !== null && REJECTED_STATUSES.has(status)) {
|
|
@@ -3998,7 +4910,7 @@ async function uploadRegisteredFile(session, entry, callbacks = {}) {
|
|
|
3998
4910
|
if (usesMultipart(file.size, policy)) {
|
|
3999
4911
|
if (entry.streamed) {
|
|
4000
4912
|
const held = await readUploadStatus(ctx, sealId, entry.sha256_hex, authHeaders, transport, signal);
|
|
4001
|
-
if (held !== null && held
|
|
4913
|
+
if (held !== null && DELIVERED_STATUSES.has(held)) {
|
|
4002
4914
|
await settle(held === "verified");
|
|
4003
4915
|
return;
|
|
4004
4916
|
}
|
|
@@ -4054,6 +4966,7 @@ async function uploadRegisteredFile(session, entry, callbacks = {}) {
|
|
|
4054
4966
|
const track = createFileProgress("single-put", (p) => onProgress?.(p));
|
|
4055
4967
|
const totalBytes = entry.encryptedSize;
|
|
4056
4968
|
let last = { phase: "encrypting", fraction: 0, delivered: false };
|
|
4969
|
+
let clock = null;
|
|
4057
4970
|
const report = (phase, fraction, delivered = last.delivered) => {
|
|
4058
4971
|
last = { phase, fraction, delivered };
|
|
4059
4972
|
track({
|
|
@@ -4062,11 +4975,10 @@ async function uploadRegisteredFile(session, entry, callbacks = {}) {
|
|
|
4062
4975
|
// A single request is all or nothing: 0 until storage confirms it.
|
|
4063
4976
|
deliveredBytes: delivered ? totalBytes : 0,
|
|
4064
4977
|
totalBytes,
|
|
4065
|
-
state: clock
|
|
4066
|
-
attempt: clock
|
|
4978
|
+
state: clock?.state ?? "running",
|
|
4979
|
+
attempt: (clock?.retriesSinceDelivery ?? 0) + 1
|
|
4067
4980
|
});
|
|
4068
4981
|
};
|
|
4069
|
-
const clock = new StallClock(transport, () => report(last.phase, last.fraction));
|
|
4070
4982
|
if (!entry.prepared) {
|
|
4071
4983
|
report("encrypting", 0);
|
|
4072
4984
|
entry.prepared = await encryptBlob2(
|
|
@@ -4077,6 +4989,8 @@ async function uploadRegisteredFile(session, entry, callbacks = {}) {
|
|
|
4077
4989
|
);
|
|
4078
4990
|
}
|
|
4079
4991
|
const ciphertext = entry.prepared;
|
|
4992
|
+
const transferClock = new StallClock(transport, () => report(last.phase, last.fraction));
|
|
4993
|
+
clock = transferClock;
|
|
4080
4994
|
report("uploading", 0);
|
|
4081
4995
|
let verified;
|
|
4082
4996
|
try {
|
|
@@ -4089,14 +5003,14 @@ async function uploadRegisteredFile(session, entry, callbacks = {}) {
|
|
|
4089
5003
|
onVerifying: () => report("verifying", 0, true),
|
|
4090
5004
|
label: file.name,
|
|
4091
5005
|
signal,
|
|
4092
|
-
clock,
|
|
5006
|
+
clock: transferClock,
|
|
4093
5007
|
transport,
|
|
4094
5008
|
onConflictWith: (head) => {
|
|
4095
5009
|
entry.conflictWith = head;
|
|
4096
5010
|
}
|
|
4097
5011
|
});
|
|
4098
5012
|
} finally {
|
|
4099
|
-
|
|
5013
|
+
transferClock.dispose();
|
|
4100
5014
|
}
|
|
4101
5015
|
report("verifying", 0.5, true);
|
|
4102
5016
|
await settle(verified);
|
|
@@ -4124,8 +5038,8 @@ function applyAccessControl(sealPayload, ctx) {
|
|
|
4124
5038
|
if (ctx.tier) sealPayload.tier = ctx.tier;
|
|
4125
5039
|
}
|
|
4126
5040
|
async function buildFileMeta(file, fileKey, size, sha256_hex, opts = {}) {
|
|
4127
|
-
const nameEncrypted = await encryptMetadataField(file.name, fileKey, "name");
|
|
4128
|
-
const mimeEncrypted = await encryptMetadataField(file.type ||
|
|
5041
|
+
const nameEncrypted = await encryptMetadataField(opts.relativePath ?? file.name, fileKey, "name");
|
|
5042
|
+
const mimeEncrypted = await encryptMetadataField(file.type || guessMimeFromName(file.name), fileKey, "mime");
|
|
4129
5043
|
const meta = {
|
|
4130
5044
|
size,
|
|
4131
5045
|
sha256_hex,
|
|
@@ -4135,11 +5049,6 @@ async function buildFileMeta(file, fileKey, size, sha256_hex, opts = {}) {
|
|
|
4135
5049
|
mime_nonce: mimeEncrypted.nonce,
|
|
4136
5050
|
encryption_version: aeon_format_default.current_format_version
|
|
4137
5051
|
};
|
|
4138
|
-
if (opts.relativePath !== void 0) {
|
|
4139
|
-
const pathEncrypted = await encryptMetadataField(opts.relativePath, fileKey, "path");
|
|
4140
|
-
meta.path_encrypted = pathEncrypted.ciphertext;
|
|
4141
|
-
meta.path_nonce = pathEncrypted.nonce;
|
|
4142
|
-
}
|
|
4143
5052
|
if (opts.parentFolderId) {
|
|
4144
5053
|
meta.parent_folder_id = opts.parentFolderId;
|
|
4145
5054
|
}
|
|
@@ -4149,16 +5058,63 @@ async function buildFileMeta(file, fileKey, size, sha256_hex, opts = {}) {
|
|
|
4149
5058
|
}
|
|
4150
5059
|
return meta;
|
|
4151
5060
|
}
|
|
4152
|
-
async function registrationFetch(url, init2, signal) {
|
|
4153
|
-
if (signal?.aborted) throw new UploadError("Upload aborted", "ABORTED");
|
|
5061
|
+
async function registrationFetch(url, init2, signal, giveBack, deadlineMs) {
|
|
5062
|
+
if (signal?.aborted) throw new UploadError("Upload aborted", "ABORTED");
|
|
5063
|
+
const request = transportFetch(url, init2);
|
|
5064
|
+
return new Promise((resolve2, reject) => {
|
|
5065
|
+
let settled = false;
|
|
5066
|
+
const giveUp = (failure) => {
|
|
5067
|
+
if (settled) return;
|
|
5068
|
+
settled = true;
|
|
5069
|
+
cleanup();
|
|
5070
|
+
reject(failure);
|
|
5071
|
+
void request.then(async (answer) => answer.ok ? giveBack(await answer.json()) : void 0).catch(() => {
|
|
5072
|
+
});
|
|
5073
|
+
};
|
|
5074
|
+
const onAbort = () => giveUp(new UploadError("Upload aborted", "ABORTED"));
|
|
5075
|
+
const timer = setTimeout(
|
|
5076
|
+
() => giveUp(new UploadError(`The registration got no answer in ${Math.round(deadlineMs / 1e3)} s`, "NETWORK", void 0, void 0, true)),
|
|
5077
|
+
deadlineMs
|
|
5078
|
+
);
|
|
5079
|
+
const cleanup = () => {
|
|
5080
|
+
clearTimeout(timer);
|
|
5081
|
+
signal?.removeEventListener("abort", onAbort);
|
|
5082
|
+
};
|
|
5083
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
5084
|
+
request.then(
|
|
5085
|
+
(answer) => {
|
|
5086
|
+
if (settled) return;
|
|
5087
|
+
settled = true;
|
|
5088
|
+
cleanup();
|
|
5089
|
+
resolve2(answer);
|
|
5090
|
+
},
|
|
5091
|
+
(err) => {
|
|
5092
|
+
if (settled) return;
|
|
5093
|
+
settled = true;
|
|
5094
|
+
cleanup();
|
|
5095
|
+
reject(err);
|
|
5096
|
+
}
|
|
5097
|
+
);
|
|
5098
|
+
});
|
|
5099
|
+
}
|
|
5100
|
+
function registrationDeadlineMs(policy) {
|
|
5101
|
+
return resolveTransportPolicy(policy.transport).completeTimeoutMs;
|
|
5102
|
+
}
|
|
5103
|
+
async function pairOrGiveBack(rows, digests, what, giveBack) {
|
|
4154
5104
|
try {
|
|
4155
|
-
return
|
|
5105
|
+
return pairRegisteredRows(rows, digests, what);
|
|
4156
5106
|
} catch (err) {
|
|
4157
|
-
|
|
5107
|
+
await giveBack((rows ?? []).filter((row) => row.sha256_hex !== void 0 && digests.includes(row.sha256_hex))).catch(() => {
|
|
5108
|
+
});
|
|
4158
5109
|
throw err;
|
|
4159
5110
|
}
|
|
4160
5111
|
}
|
|
4161
|
-
async function
|
|
5112
|
+
async function stopIfCancelled(session, signal) {
|
|
5113
|
+
if (!signal?.aborted) return;
|
|
5114
|
+
await session.cancel();
|
|
5115
|
+
throw new UploadError("Upload aborted", "ABORTED");
|
|
5116
|
+
}
|
|
5117
|
+
async function createSeal(ctx, filesMeta, signal, giveBack, deadlineMs) {
|
|
4162
5118
|
const sealPayload = { files_meta: filesMeta };
|
|
4163
5119
|
if (ctx.ownerTokenHash) sealPayload.owner_token_hash = ctx.ownerTokenHash;
|
|
4164
5120
|
applyAccessControl(sealPayload, ctx);
|
|
@@ -4167,7 +5123,7 @@ async function createSeal(ctx, filesMeta, signal) {
|
|
|
4167
5123
|
headers: { "Content-Type": "application/json", ...createAuthHeaders(uploadAuthFor(ctx)) },
|
|
4168
5124
|
credentials: ctx.credentials ?? "include",
|
|
4169
5125
|
body: JSON.stringify(sealPayload)
|
|
4170
|
-
}, signal);
|
|
5126
|
+
}, signal, giveBack, deadlineMs);
|
|
4171
5127
|
if (!sealResponse.ok) throw await uploadErrorFromResponse(sealResponse, "Create seal failed", "UNKNOWN");
|
|
4172
5128
|
return await sealResponse.json();
|
|
4173
5129
|
}
|
|
@@ -4196,21 +5152,14 @@ function toSessionFiles(planned, rows) {
|
|
|
4196
5152
|
async function uploadSingleFile(ctx, file, policy = DEFAULT_POLICY, callbacks = {}) {
|
|
4197
5153
|
validateSealContext(ctx);
|
|
4198
5154
|
const planned = await planFile(file, generateKey());
|
|
4199
|
-
const
|
|
4200
|
-
ctx,
|
|
4201
|
-
[await buildFileMeta(file, planned.key, ciphertextSize(file.size), planned.sha256_hex)],
|
|
4202
|
-
callbacks.signal
|
|
4203
|
-
);
|
|
4204
|
-
const rows = pairRegisteredRows(seal.files, [planned.sha256_hex], `Create seal ${seal.id}`);
|
|
4205
|
-
await announceRegistered(callbacks, seal.id, [planned], rows);
|
|
4206
|
-
const session = new UploadSession(
|
|
5155
|
+
const sessionOf = (registration, files) => new UploadSession(
|
|
4207
5156
|
{
|
|
4208
5157
|
ctx,
|
|
4209
5158
|
policy,
|
|
4210
|
-
sealId:
|
|
5159
|
+
sealId: registration.id,
|
|
4211
5160
|
createdSeal: true,
|
|
4212
|
-
expiresAt:
|
|
4213
|
-
files
|
|
5161
|
+
expiresAt: registration.expires_at,
|
|
5162
|
+
files
|
|
4214
5163
|
},
|
|
4215
5164
|
async (s, cb) => {
|
|
4216
5165
|
const entry = s.files[0];
|
|
@@ -4228,6 +5177,18 @@ async function uploadSingleFile(ctx, file, policy = DEFAULT_POLICY, callbacks =
|
|
|
4228
5177
|
};
|
|
4229
5178
|
}
|
|
4230
5179
|
);
|
|
5180
|
+
const seal = await createSeal(
|
|
5181
|
+
ctx,
|
|
5182
|
+
[await buildFileMeta(file, planned.key, ciphertextSize(file.size), planned.sha256_hex)],
|
|
5183
|
+
callbacks.signal,
|
|
5184
|
+
// A seal this upload created is given back whole.
|
|
5185
|
+
(late) => sessionOf(late, []).cancel(),
|
|
5186
|
+
registrationDeadlineMs(policy)
|
|
5187
|
+
);
|
|
5188
|
+
const rows = await pairOrGiveBack(seal.files, [planned.sha256_hex], `Create seal ${seal.id}`, () => sessionOf(seal, []).cancel());
|
|
5189
|
+
const session = sessionOf(seal, toSessionFiles([planned], rows));
|
|
5190
|
+
await stopIfCancelled(session, callbacks.signal);
|
|
5191
|
+
await announceRegistered(callbacks, seal.id, [planned], rows);
|
|
4231
5192
|
return session.resume(callbacks);
|
|
4232
5193
|
}
|
|
4233
5194
|
var PAYMENT_POLL_MS = [2e3, 4e3, 8e3, 15e3];
|
|
@@ -4250,75 +5211,12 @@ async function waitForPayment(api, sealId, ownerToken, opts) {
|
|
|
4250
5211
|
if (opts.signal?.aborted) throw err;
|
|
4251
5212
|
if (err instanceof BackendError && err.code !== "transient" && err.code !== "rate_limited") throw err;
|
|
4252
5213
|
}
|
|
4253
|
-
const
|
|
4254
|
-
if (Date.now() +
|
|
4255
|
-
await abortableDelay(
|
|
5214
|
+
const pause2 = PAYMENT_POLL_MS[Math.min(poll, PAYMENT_POLL_MS.length - 1)];
|
|
5215
|
+
if (Date.now() + pause2 > opts.deadline) return null;
|
|
5216
|
+
await abortableDelay(pause2, opts.signal);
|
|
4256
5217
|
}
|
|
4257
5218
|
}
|
|
4258
5219
|
var TTL_OPTIONS = limits_default.limits.ttl_options;
|
|
4259
|
-
var seal_share_url_default = {
|
|
4260
|
-
version: 2,
|
|
4261
|
-
name: "SEAL_SHARE_URL",
|
|
4262
|
-
description: "URL fragment scheme for SEAL share links (SPEC-AEON-V4 \xA76, law \u041B2): the fragment of any link carries one symmetric key or nothing. A link addressed to someone carries no fragment: its key, wrapped to the recipient's bundle (sealed box v2, crypto.json sealed_box_v2), lives in the share link's row on the server and comes back as `fragment` of GET /seal/{id}/share/{code}. Backends never see fragments (URL fragments are not sent over HTTP per RFC 3986 \xA73.5). Consumers: the web, the CLI, the MCP server, the SDK, sealnet and the bots. The wrap and its opening live in shared/core (targeted.rs over sealed_box.rs, Identity::open).",
|
|
4263
|
-
url_template: "https://<host>/s/<seal_id>/<share_code>[#<link_key>]",
|
|
4264
|
-
fragment_variants: {
|
|
4265
|
-
key: {
|
|
4266
|
-
format: "<link_key_urlsafe_b64_no_pad>",
|
|
4267
|
-
detection: "exactly 43 urlsafe-b64-no-pad characters, 32 bytes: the AES-256-GCM key of the share blob (seal_blob.v1.json)",
|
|
4268
|
-
field_layout: [
|
|
4269
|
-
{ name: "link_key", offset: 0, length: 32, encoding: "urlsafe-b64-no-pad in URL" }
|
|
4270
|
-
]
|
|
4271
|
-
},
|
|
4272
|
-
none: {
|
|
4273
|
-
format: "",
|
|
4274
|
-
detection: "no fragment: an addressed link. The key, wrapped to the recipient's bundle with scope ('seal_share', seal_id from the path), is the `fragment` field of the share blob response (1575 base64url characters, first byte 0x02); only the recipient's seed opens it."
|
|
4275
|
-
},
|
|
4276
|
-
targeted_x25519_v1: {
|
|
4277
|
-
status: "read only until the removal (C1 \xA76): links made before C1 with the sealed box v1 in the fragment",
|
|
4278
|
-
format: "x25519:<packed_b64>",
|
|
4279
|
-
prefix: "x25519:",
|
|
4280
|
-
packed_binary_length_bytes: 92,
|
|
4281
|
-
packed_layout: [
|
|
4282
|
-
{ name: "ephemeral_public", offset: 0, length: 32, encoding: "raw bytes; X25519 ephemeral pubkey from sender" },
|
|
4283
|
-
{ name: "nonce", offset: 32, length: 12, encoding: "raw bytes; AES-256-GCM nonce" },
|
|
4284
|
-
{ name: "wrapped_link_key", offset: 44, length: 48, encoding: "raw bytes; 32 B ciphertext of the link key || 16 B GCM tag" }
|
|
4285
|
-
],
|
|
4286
|
-
implicit_fields_not_in_packed: {
|
|
4287
|
-
recipient_public: "the X25519 key of the recipient's seed (the seed itself is the X25519 secret)",
|
|
4288
|
-
scope_type: "'seal_share'",
|
|
4289
|
-
scope_id: "seal_id from the URL path /s/<seal_id>/<code>",
|
|
4290
|
-
grant_version: "1"
|
|
4291
|
-
},
|
|
4292
|
-
kdf_info_layout: 'seal_crypto::hkdf::derive_wrap_key: b"WRAP" || 0x01 || len(scope_type) || scope_type || len(scope_id) || scope_id, salt crypto.json hkdf.wrap_key_salt',
|
|
4293
|
-
aad_layout: "recipient_public (32 B) || 0x01"
|
|
4294
|
-
}
|
|
4295
|
-
},
|
|
4296
|
-
version_detection_rule: "(1) no fragment \u2192 none: the wrap comes from the server; (2) starts with 'x25519:' \u2192 targeted_x25519_v1, read only until the removal; (3) exactly 43 urlsafe-b64-no-pad characters \u2192 key; (4) anything else \u2192 'update the client' (SPEC-AEON-V4 \xA77.4), never decoded as a key.",
|
|
4297
|
-
current_format_version: 2,
|
|
4298
|
-
supported_format_versions: [2],
|
|
4299
|
-
implementations: {
|
|
4300
|
-
rust: "shared/core/src/targeted.rs (wrap_link_key / open_wrap; the x25519: opening until the removal); the CLI calls it as seal_crypto::targeted",
|
|
4301
|
-
ts: "shared/packages/protocol/src/identity.ts (wrapTo / openWrap) over the core's WASM; the whole link is parsed by protocol/src/url.ts::parseShareUrl",
|
|
4302
|
-
python: "sealnet calls the Rust core in its wheel (sealnet.seal_crypto); no Python implementation"
|
|
4303
|
-
},
|
|
4304
|
-
test_vectors: {
|
|
4305
|
-
description: "Frozen outputs of the read-only v1 variant, until the removal: every reader MUST recover link_key from fragment with recipient_secret (the seed) and seal_id, and MUST fail with any other seal_id.",
|
|
4306
|
-
targeted_x25519_v1: [
|
|
4307
|
-
{
|
|
4308
|
-
recipient_secret_b64url: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc",
|
|
4309
|
-
recipient_public_b64url: "E75P6uryBMf9M1j8nAByGIHRdCeBKCJ-xnTzf3_pe20",
|
|
4310
|
-
seal_id: "AbCd1234",
|
|
4311
|
-
fragment: "x25519:GkbbXddA43eoSgY1ZAAnPTCDmJIoGM3ZrY2_wctdKX2ivODHag_TCSjQql3PMu22xzsxJsYKHnIhHjXhvuJfe468pvsvvzuEZiaVzoPu2PTqlRin8xiDsopyrGQ",
|
|
4312
|
-
link_key_b64url: "q6urq6urq6urq6urq6urq6urq6urq6urq6urq6urq6s"
|
|
4313
|
-
}
|
|
4314
|
-
]
|
|
4315
|
-
},
|
|
4316
|
-
security_properties: {
|
|
4317
|
-
key: "Anyone with the URL can open. link_key is the entire capability \u2014 treat the URL itself as a bearer credential.",
|
|
4318
|
-
none: "The URL alone opens nothing: the key is sealed to the recipient's bundle (X25519 + ML-KEM-768) and only the seed on the recipient's device opens it. Each wrap has a fresh ephemeral key and encapsulation."
|
|
4319
|
-
}
|
|
4320
|
-
};
|
|
4321
|
-
var LEGACY_PREFIX = seal_share_url_default.fragment_variants.targeted_x25519_v1.prefix;
|
|
4322
5220
|
var SEAL_ID_LENGTH = 8;
|
|
4323
5221
|
var LINK_KEY_LENGTH = 43;
|
|
4324
5222
|
var SHARE_CODE_LENGTH = 4;
|
|
@@ -4375,7 +5273,7 @@ function parseShareUrl(input) {
|
|
|
4375
5273
|
try {
|
|
4376
5274
|
url = new URL(input);
|
|
4377
5275
|
} catch {
|
|
4378
|
-
throw new ShareUrlError("url_invalid", `not a valid URL
|
|
5276
|
+
throw new ShareUrlError("url_invalid", `not a valid URL (${input.length} characters)`);
|
|
4379
5277
|
}
|
|
4380
5278
|
let parsed;
|
|
4381
5279
|
try {
|
|
@@ -4386,9 +5284,6 @@ function parseShareUrl(input) {
|
|
|
4386
5284
|
const fragment = url.hash.replace(/^#/, "").trim();
|
|
4387
5285
|
const shareCode = parsed.shareCode ?? null;
|
|
4388
5286
|
if (!fragment) return { sealId: parsed.sealId, shareCode, fragmentVariant: "none", fragment };
|
|
4389
|
-
if (fragment.startsWith(LEGACY_PREFIX)) {
|
|
4390
|
-
return { sealId: parsed.sealId, shareCode, fragmentVariant: "targeted_x25519_v1", fragment };
|
|
4391
|
-
}
|
|
4392
5287
|
if (!isValidLinkKey(fragment)) {
|
|
4393
5288
|
throw new ShareUrlError(
|
|
4394
5289
|
"url_invalid",
|
|
@@ -4410,108 +5305,30 @@ function parseUrlType(pathname) {
|
|
|
4410
5305
|
}
|
|
4411
5306
|
return { sealId, shareCode };
|
|
4412
5307
|
}
|
|
4413
|
-
var crypto_default = {
|
|
4414
|
-
version: 1,
|
|
4415
|
-
default_aead: "aes_256_gcm",
|
|
4416
|
-
aes_gcm: {
|
|
4417
|
-
key_length_bytes: 32,
|
|
4418
|
-
nonce_length_bytes: 12,
|
|
4419
|
-
tag_length_bytes: 16
|
|
4420
|
-
},
|
|
4421
|
-
sha256: {
|
|
4422
|
-
output_length_bytes: 32,
|
|
4423
|
-
hex_string_length: 64
|
|
4424
|
-
},
|
|
4425
|
-
owner_token_bytes: 32,
|
|
4426
|
-
link_key_bytes: 32,
|
|
4427
|
-
metadata_aad_prefix: "field:",
|
|
4428
|
-
keybundle: {
|
|
4429
|
-
signature_prefix: "seal:keybundle:",
|
|
4430
|
-
signed_bundle_version: 2,
|
|
4431
|
-
v2_fields: ["identity_ed25519_pub", "agreement_x25519_pub", "kem_mlkem768_pub"],
|
|
4432
|
-
packed_length: 1316,
|
|
4433
|
-
address: {
|
|
4434
|
-
of: "sha256(identity_ed25519_pub), 32 bytes",
|
|
4435
|
-
text: "base64url without padding, 43 characters",
|
|
4436
|
-
words: "fingerprint_words.json over its first three bytes"
|
|
4437
|
-
}
|
|
4438
|
-
},
|
|
4439
|
-
hkdf: {
|
|
4440
|
-
wrap_key_salt: "seal:wrapkey:v1",
|
|
4441
|
-
wrap_key_salt_v2: "seal:wrapkey:v2",
|
|
4442
|
-
identity_key_salt: "seal:key-derivation:v1",
|
|
4443
|
-
file_envelope_salt: "seal:file-envelope:v1",
|
|
4444
|
-
info_prefixes: {
|
|
4445
|
-
wrap: "WRAP",
|
|
4446
|
-
agreement: "AGRE",
|
|
4447
|
-
identity: "IDEN",
|
|
4448
|
-
workload_identity: "seal:workload-identity:v1",
|
|
4449
|
-
kem_mlkem768: "seal:kem-mlkem768:v1"
|
|
4450
|
-
}
|
|
4451
|
-
},
|
|
4452
|
-
xwing: { label_hex: "5c2e2f2f5e5c" },
|
|
4453
|
-
sealed_box_v2: {
|
|
4454
|
-
version_byte: 2,
|
|
4455
|
-
packed_layout: [
|
|
4456
|
-
{ name: "version", offset: 0, length: 1 },
|
|
4457
|
-
{ name: "eph_pub", offset: 1, length: 32 },
|
|
4458
|
-
{ name: "kem_ct", offset: 33, length: 1088 },
|
|
4459
|
-
{ name: "nonce", offset: 1121, length: 12 },
|
|
4460
|
-
{ name: "ct", offset: 1133, length: 48 }
|
|
4461
|
-
],
|
|
4462
|
-
packed_length: 1181,
|
|
4463
|
-
packed_b64_length: 1575
|
|
4464
|
-
},
|
|
4465
|
-
secret_scope_aad: "secret:{secret_id}",
|
|
4466
|
-
sign: {
|
|
4467
|
-
message_prefix: "aeon:sign:v1",
|
|
4468
|
-
message_format: "aeon:sign:v1|org:{org_id}|req:{request_id}|doc_hash:{doc_hash_hex}"
|
|
4469
|
-
},
|
|
4470
|
-
recovery_phrase: {
|
|
4471
|
-
seed: `BIP39: PBKDF2-HMAC-SHA512 of the phrase after trim, lower case and NFKD, salt "mnemonic", 2048 iterations, 64 bytes; the web's recoveryPhrase.ts phraseToMasterSeed and the core's hkdf::master_seed_from_phrase (\u04145 \xA73.2)`,
|
|
4472
|
-
vector: {
|
|
4473
|
-
phrase: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art",
|
|
4474
|
-
typed: " Abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon ART\n",
|
|
4475
|
-
seed_hex: "408b285c123836004f4b8842c89324c1f01382450c0d439af345ba7fc49acf705489c6fc77dbd4e3dc1dd8cc6bc9f043db8ada1e243c4a0eafb290d399480840"
|
|
4476
|
-
}
|
|
4477
|
-
},
|
|
4478
|
-
device_link: {
|
|
4479
|
-
record: "a person's seed64, base64url, sealed by the browser to the one-time bundle of sealfs login: sealReply(seed64, bundle, scope, code) of the protocol's identity module \u2014 box (sealed_box_v2) \u2016 nonce(12) \u2016 AES-256-GCM of the record under the box's key; the daemon opens it with its one-time identity (\u04145 \xA73.2 \u043F. 2, D119)",
|
|
4480
|
-
scope: "device",
|
|
4481
|
-
vector: {
|
|
4482
|
-
daemon_seed32_hex: "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20",
|
|
4483
|
-
code: "K7M2Q9XA",
|
|
4484
|
-
seed64_hex: "030a11181f262d343b424950575e656c737a81888f969da4abb2b9c0c7ced5dce3eaf1f8ff060d141b222930373e454c535a61686f767d848b9299a0a7aeb5bc",
|
|
4485
|
-
record: "AiLUcCQ-y_sD9lk4-SfbqB2ye0O1kPNp9WXB17aooqw6e0T2cUNCgVtTT-6G85cWqJYck6oV0yjTt2pk299lJ-mU4sJOwTcYqD_AmSzQEGalLYBfMWQUaDNbiN0izBY-gUwMMBYfhu5Dg8iunGtRq_NqmR_RVD90XKZcLGeDYlIP-Y9PZgpjhLgzYyygYVk_frpnezADgvVJZPX9aJZWBvYnluYJ7cziq0I1gNOd4YsxD9s5_YILQUPv5FZSD4pO6VteIa8frg_emCIbbZqOlfVAH4BJ9kc082OLPthe_c1-kk0r6a7aYCWMrQzDhiQaGtORWSc1zp6g4CS0EZgOH5hwi4-bTEiwA-DHNJAwheel8vOdAf9jj94e_3z-r0-VJqGvdZY1dojaxsH9ncnYtmPJHnK4NSA0HN8WUCTE9GPSGXdy-v5TPGl1lbx_CorhVS0skxnufB7Xbr0BdHH5RgwFogxCWHiltENydvBSLTdI1_R-N7ZI7qng0_4nOekZsQdIoVlgfzepatTtPHOvfVYEmvQ-VIurJWuIQTM2fcvqZNcjBtAMNmwMSfWuJZVL02ydFQTH8a9ZcNQI56lCOHkJvm5zakpx0E2RJr2vgDwNzrb_1AnQ7_3K0IK9Zv0sA-hCxOH8qQx6an-tAX_Nu-ImW-YKu-nZgCeG3eMmnhKHpMu3-quGhWhAI2ECrwCLUxycONPzbKpScXNn5KnBmAfJNvHdxJOzAIzoxPiDcbme1eud10pgxILimVXZ0aRwhvqxxr9qOrmDobsJfcLx8NKFgQ4NZad81j23CtoeadX03lPHJYngvsTJdhjgR4NUMLYzO-Y5D7dagDVI5I80oqhBtelMXqizH10b7LIIWPtFBBNmfeUjuOZau5CJuDGbiof53irMi3vugv1HggNQq0SS5E0_Lu6muVz4YR_O9E_caXosymEU4tcLsxxAolxNJO_nYorWgL-o_KrePQo81L-IAlpSf-wgjNQGm1CScnCZGAEY3ZYOHeB5bSdeNgzX4VWENZ5arfLk02ENk82Gfx8pdFgOFHhSXz574sGdnvIeTHiW0mQglVYSOodSLICAKvpwME3LtSytFl6zb5gpj_52mkFVXrPXV8ja2LK4ssCxtFXYzCYYgKSa7ZEKtx34xtj6U9yUI-TqWnSvukfOo2eTAEmxYf7DTyMq6Uj1EfNC7Zy77wBSXvPeca3M-1_aRuoaH3BKtveqkqAhIcacDbUW4ysg_F09ZFMAJZxJ7sXFAVI_jS-PDNvOn5Q5lkg07zAjZ64a9maZPXReNX-XNqBOde3GZ179HxmWPC0AEgKtyH7zjV9SSRs3tvTopyZuFd8tcZ17r2OaeR8UQWys6NKlK0dFqquQAeNlB4PyNIl3wKHxoIItVEiN4dT9UC_rZuYf-fsjRsZ9yvcOW6iCnZOSWoggV_sBl-7bvKhnkBwSreKFggXTnjEsAK0L-INniS3aYwrRAv9ZjYee0jUOV0DwbPskckVzjyiquja1-7_rt6XGmSqRkFDkBxvvLgEFFJjE22ySdyT2gRVuxLg8ayA0d3Mn-qqpGRMrThqnxaUv7Pp7KzcFQ97Eb0zxWroa3DdSPhPmutepx8P4cxtVhVP5R_aUHY0l26SwS2SwL-1yIicca4_PgSYlQX4gOKa87JPgr1BhO9HuDTXzu16hlDQ99-ioq0n0pXyDaUp4bVx9GL72hosl6U_vDNhMniI"
|
|
4486
|
-
}
|
|
4487
|
-
}
|
|
4488
|
-
};
|
|
4489
5308
|
var SHARE_SCOPE = seal_address_default.scopes.share_link;
|
|
4490
5309
|
var OWNER_SCOPE = seal_address_default.scopes.owner_copy;
|
|
4491
5310
|
var WRAP_VERSION = crypto_default.sealed_box_v2.version_byte;
|
|
4492
5311
|
var WRAP_BYTES = crypto_default.sealed_box_v2.packed_length;
|
|
4493
|
-
var
|
|
4494
|
-
var
|
|
4495
|
-
var SEED_BYTES = 32;
|
|
5312
|
+
var SEED_BYTES = 64;
|
|
5313
|
+
var SEED_BYTES_BEFORE = 32;
|
|
4496
5314
|
var KEY_BYTES = 32;
|
|
4497
5315
|
var B64URL = /^[A-Za-z0-9_-]+$/;
|
|
4498
5316
|
function newSeed() {
|
|
4499
5317
|
return crypto.getRandomValues(new Uint8Array(SEED_BYTES));
|
|
4500
5318
|
}
|
|
4501
|
-
async function openIdentity(
|
|
5319
|
+
async function openIdentity(seed2, keyVersion = 1) {
|
|
4502
5320
|
const wasm2 = await ensureWasm();
|
|
4503
|
-
if (
|
|
4504
|
-
if (
|
|
4505
|
-
throw new Error(`a seed is ${SEED_BYTES} or ${
|
|
5321
|
+
if (seed2.length === SEED_BYTES) return wasm2.WasmIdentity.fromSeed64(seed2, keyVersion);
|
|
5322
|
+
if (seed2.length === SEED_BYTES_BEFORE) return wasm2.WasmIdentity.fromSeed32(seed2);
|
|
5323
|
+
throw new Error(`a seed is ${SEED_BYTES} bytes, or the ${SEED_BYTES_BEFORE} of a key made before, got ${seed2.length}`);
|
|
4506
5324
|
}
|
|
4507
|
-
async function identityOf(
|
|
4508
|
-
const identity = await openIdentity(
|
|
5325
|
+
async function identityOf(seed2, keyVersion = 1) {
|
|
5326
|
+
const identity = await openIdentity(seed2, keyVersion);
|
|
4509
5327
|
try {
|
|
4510
5328
|
return {
|
|
4511
5329
|
bundle: identity.bundle(),
|
|
4512
5330
|
address: identity.address(),
|
|
4513
|
-
words: identity.words()
|
|
4514
|
-
legacyAddress: identity.legacyAddress()
|
|
5331
|
+
words: identity.words()
|
|
4515
5332
|
};
|
|
4516
5333
|
} finally {
|
|
4517
5334
|
identity.free();
|
|
@@ -4548,9 +5365,8 @@ var WrapError = class extends Error {
|
|
|
4548
5365
|
this.cause = cause;
|
|
4549
5366
|
}
|
|
4550
5367
|
};
|
|
4551
|
-
async function openWrap(wrap,
|
|
5368
|
+
async function openWrap(wrap, seed2, scope, id, keyVersion = 1) {
|
|
4552
5369
|
if (id.length === 0) throw new WrapError("parse", "the scope id must not be empty: the wrap binds to it");
|
|
4553
|
-
if (wrap.startsWith(LEGACY.prefix)) return openLegacy(wrap.slice(LEGACY.prefix.length), seed, scope, id);
|
|
4554
5370
|
if (!B64URL.test(wrap)) throw new WrapError("parse", "the wrap is not urlsafe-base64-no-pad");
|
|
4555
5371
|
const packed = base64urlToBytes(wrap);
|
|
4556
5372
|
if (packed[0] !== WRAP_VERSION) {
|
|
@@ -4559,10 +5375,10 @@ async function openWrap(wrap, seed, scope, id, keyVersion = 1) {
|
|
|
4559
5375
|
if (packed.length !== WRAP_BYTES) {
|
|
4560
5376
|
throw new WrapError("parse", `the wrap is ${packed.length} bytes, expected ${WRAP_BYTES}`);
|
|
4561
5377
|
}
|
|
4562
|
-
if (
|
|
4563
|
-
throw new WrapError("parse", `a seed is ${SEED_BYTES} or ${
|
|
5378
|
+
if (seed2.length !== SEED_BYTES && seed2.length !== SEED_BYTES_BEFORE) {
|
|
5379
|
+
throw new WrapError("parse", `a seed is ${SEED_BYTES} bytes, or the ${SEED_BYTES_BEFORE} of a key made before, got ${seed2.length}`);
|
|
4564
5380
|
}
|
|
4565
|
-
const identity = await openIdentity(
|
|
5381
|
+
const identity = await openIdentity(seed2, keyVersion);
|
|
4566
5382
|
try {
|
|
4567
5383
|
return identity.open(packed, scope, id);
|
|
4568
5384
|
} catch (err) {
|
|
@@ -4571,22 +5387,8 @@ async function openWrap(wrap, seed, scope, id, keyVersion = 1) {
|
|
|
4571
5387
|
identity.free();
|
|
4572
5388
|
}
|
|
4573
5389
|
}
|
|
4574
|
-
async function
|
|
4575
|
-
|
|
4576
|
-
const packed = base64urlToBytes(packedB64);
|
|
4577
|
-
if (packed.length !== LEGACY.packed_binary_length_bytes) {
|
|
4578
|
-
throw new WrapError("parse", `the ${LEGACY.prefix} wrap is ${packed.length} bytes, expected ${LEGACY.packed_binary_length_bytes}`);
|
|
4579
|
-
}
|
|
4580
|
-
if (seed.length !== SEED_BYTES) throw new WrapError("parse", `an ${LEGACY.prefix} wrap opens with a ${SEED_BYTES}-byte seed`);
|
|
4581
|
-
const wasm2 = await ensureWasm();
|
|
4582
|
-
try {
|
|
4583
|
-
return wasm2.wasm_sealbox_unwrap(packed, seed, scope, id);
|
|
4584
|
-
} catch (err) {
|
|
4585
|
-
throw new WrapError("aead", "the wrap does not open: it is not for this seed, or its scope, id or bytes were changed", err);
|
|
4586
|
-
}
|
|
4587
|
-
}
|
|
4588
|
-
async function proveInbox(seed, challenge) {
|
|
4589
|
-
const identity = await openIdentity(seed);
|
|
5390
|
+
async function proveInbox(seed2, challenge) {
|
|
5391
|
+
const identity = await openIdentity(seed2);
|
|
4590
5392
|
try {
|
|
4591
5393
|
const signature = identity.inboxProof(BigInt(challenge.ts), base64urlToBytes(challenge.challenge));
|
|
4592
5394
|
return `${challenge.ts}.${challenge.challenge}.${bytesToBase64url(signature)}`;
|
|
@@ -4594,17 +5396,12 @@ async function proveInbox(seed, challenge) {
|
|
|
4594
5396
|
identity.free();
|
|
4595
5397
|
}
|
|
4596
5398
|
}
|
|
4597
|
-
async function proveLegacyAddress(seed, challenge, ts) {
|
|
4598
|
-
const wasm2 = await ensureWasm();
|
|
4599
|
-
const token = wasm2.wasm_sealbox_unwrap(base64urlToBytes(challenge), seed, ADDRESS_PROOF_SCOPE, String(ts));
|
|
4600
|
-
return `${ts}.${bytesToBase64url(token)}`;
|
|
4601
|
-
}
|
|
4602
5399
|
var fingerprint_words_default = {
|
|
4603
|
-
version:
|
|
5400
|
+
version: 2,
|
|
4604
5401
|
name: "FINGERPRINT_WORDS",
|
|
4605
|
-
description: "
|
|
5402
|
+
description: "Eight words that name the identity key of a bundle to a person (SPEC-AEON-V4 \xA75.3; eight since AUDIT K251, owner 11.11: eight words, 24 bits, were ground in 207 s on one Mac): word i (i = 0 \u2026 7) is words[byte i of SHA-256(identity public key)] \u2014 the first eight bytes of the same SHA-256 that is the address, so a client names an address by its own first bytes without hashing again \u2014 64 bits in all, written in lower case with one space between them; the first three are the three of before. The agent shows them in its chat, box.seal.net and seal.net/i/{id} show them on the page, so a person sees at a glance whether both sides hold the same key. One list for every language and client: 256 English nouns of 3 to 7 letters, no two sharing their first three letters, in alphabetical order.",
|
|
4606
5403
|
digest: "sha256",
|
|
4607
|
-
count:
|
|
5404
|
+
count: 8,
|
|
4608
5405
|
separator: " ",
|
|
4609
5406
|
words: [
|
|
4610
5407
|
"acorn",
|
|
@@ -4866,8 +5663,8 @@ var fingerprint_words_default = {
|
|
|
4866
5663
|
],
|
|
4867
5664
|
vector: {
|
|
4868
5665
|
public_key_b64url: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
|
4869
|
-
sha256_prefix_hex: "
|
|
4870
|
-
words: "iron ivory lava"
|
|
5666
|
+
sha256_prefix_hex: "66687aadf862bd77",
|
|
5667
|
+
words: "iron ivory lava plum yacht horse river lagoon"
|
|
4871
5668
|
}
|
|
4872
5669
|
};
|
|
4873
5670
|
var WORDS = fingerprint_words_default.words;
|
|
@@ -4879,8 +5676,13 @@ function addressWords(address) {
|
|
|
4879
5676
|
}
|
|
4880
5677
|
var PAIRING_MIME = seal_address_default.payloads.pair.mime;
|
|
4881
5678
|
var DEVICE_MIME = seal_address_default.payloads.device.mime;
|
|
5679
|
+
var DELIVERY_MIME = seal_address_default.payloads.delivery.mime;
|
|
5680
|
+
var APPROVE_MIME = seal_address_default.payloads.approve.mime;
|
|
5681
|
+
var APPROVE_ANSWER_MIME = seal_address_default.payloads.approve_answer.mime;
|
|
5682
|
+
var SUMMARY_MIME = seal_address_default.payloads.summary.mime;
|
|
4882
5683
|
var PAIR_WHAT = seal_address_default.pair_what;
|
|
4883
5684
|
var NAME_MAX = seal_address_default.payloads.name_max;
|
|
5685
|
+
var BODY_SHOWN_BYTES = limits_default.limits.APPROVE_BODY_SHOWN_BYTES;
|
|
4884
5686
|
var BUNDLE_BYTES = crypto_default.keybundle.packed_length;
|
|
4885
5687
|
var VERSION = 2;
|
|
4886
5688
|
var B64URL2 = /^[A-Za-z0-9_-]+$/;
|
|
@@ -4942,6 +5744,21 @@ var secrets_default = {
|
|
|
4942
5744
|
},
|
|
4943
5745
|
patterns_note: "What a key looks like, for every reader: `seal doctor --transcripts`, the scanner of the Pro web page and the `sealfs` detector (C1 \u042039). `pattern` is an expression in the subset all three run alike \u2014 JS, Python `re`, Rust `regex`: no lookaround, no backreference, no inline flag; a boundary is `\\b` inside the expression. The flags are shared: case-insensitive and multiline. A match that contains a string of the entry's `allowlist` (case-insensitive) is no finding. A match of an entry with `checksum` is a finding only when it passes that sum: `luhn` \u2014 the Luhn sum of its digits is 0 modulo 10; `iban` \u2014 its characters but spaces, upper-cased, the first four moved to the end, each letter read as a number (A = 10 \u2026 Z = 35), are 1 modulo 97. A finding is shown masked: its first four characters, `\u2026`, its last two. `vectors.hit` holds a finding of the entry, `vectors.clean` none; every reader passes them. The scanner page does not take a file larger than `max_file_bytes`; `seal doctor` reads agent transcripts of any size, a line at a time \u2014 skipping a long transcript would hide its leak. Data, not code: a service is added with one entry.",
|
|
4944
5746
|
max_file_bytes: 10485760,
|
|
5747
|
+
wildcard_public_second_level: ["ac", "co", "com", "edu", "gov", "go", "ne", "net", "or", "org", "mil", "int", "gob", "ltd", "plc", "me", "nom"],
|
|
5748
|
+
shared_host_suffixes: ["s3.amazonaws.com", "cloudfront.net", "azurewebsites.net", "appspot.com", "firebaseapp.com", "web.app", "github.io", "githubusercontent.com", "gitlab.io", "herokuapp.com", "pages.dev", "workers.dev", "vercel.app", "netlify.app", "onrender.com", "fly.dev", "blogspot.com", "ngrok.io", "ngrok-free.app", "glitch.me", "surge.sh"],
|
|
5749
|
+
shared_host_note: "Names under which each customer has a name of its own (the private part of the public suffix list): a host there is one service with the label before it, as `x.co.uk` is \u2014 AUDIT K162: by its last two labels every github.io page was one service.",
|
|
5750
|
+
wildcard_note: "A proposed `*.<name>` binds a key unless <name> is a public suffix: one label (`*.com`), or two where the second is a two-letter country top level and the first is one of wildcard_public_second_level (`*.co.uk` would be a root for every .co.uk host; `*.me.com` is a name of its own); a bare name needs two labels (SPEC agent egress \xA74.2, review of phase 1).",
|
|
5751
|
+
guard_note: "What the guard does with a key of an entry (SPEC agent egress \xA74.1, read by `seal-client-core::guard`). `hosts`: where the key is a way in, the default binding a person confirms or narrows; `*.` is one label. `place`: where the guard puts the value \u2014 `bearer` (Authorization: Bearer), `header:<name>`, `query:<param>`, `basic_user`, `basic_pass`, `userinfo`, `url` (the secret is the request address itself, a webhook). `class`: `outbound` \u2014 a key a program enters a service with, the proxy puts it in; `inprocess` \u2014 a key a program works with itself (a webhook signing secret, a database password of a driver that uses no proxy, a private key, an assignment the pattern matches with its name): the program gets the value, by the person's word on the page. `surrogate`: the form of the stand-in the agent sees \u2014 `keep_prefix` (kept as it is), `alphabet` (`base62`, `base64url`, `hex`, `digits`, `base32`, `classes` \u2014 each character keeps its class and punctuation stays), `length` (a number, else the value's), `checksum` (`github_crc32`: the last six characters are the CRC32 of the body, base62), `parts` (`password`: of a connection URI only the password changes). An entry without `surrogate` is treated by classes. `provision_commands`: commands that write a key as data into a service's own store; a surrogate in their arguments or stdin is refused unless the binding's `provision` names the host (\xA75.4, \xA76.4). Data, not code: a service is added with one entry.",
|
|
5752
|
+
provision_commands: [
|
|
5753
|
+
{ command: "wrangler secret put", host: "api.cloudflare.com" },
|
|
5754
|
+
{ command: "gh secret set", host: "api.github.com" },
|
|
5755
|
+
{ command: "vercel env add", host: "api.vercel.com" },
|
|
5756
|
+
{ command: "fly secrets set", host: "api.machines.dev" },
|
|
5757
|
+
{ command: "kubectl create secret", host: null },
|
|
5758
|
+
{ command: "aws secretsmanager put-secret-value", host: "*.amazonaws.com" },
|
|
5759
|
+
{ command: "heroku config:set", host: "api.heroku.com" },
|
|
5760
|
+
{ command: "doppler secrets set", host: "api.doppler.com" }
|
|
5761
|
+
],
|
|
4945
5762
|
patterns: [
|
|
4946
5763
|
{
|
|
4947
5764
|
name: "openai_api_key",
|
|
@@ -4949,6 +5766,10 @@ var secrets_default = {
|
|
|
4949
5766
|
severity: "critical",
|
|
4950
5767
|
description: "OpenAI API Key",
|
|
4951
5768
|
keywords: ["openai", "sk-proj-"],
|
|
5769
|
+
hosts: ["api.openai.com"],
|
|
5770
|
+
place: "bearer",
|
|
5771
|
+
class: "outbound",
|
|
5772
|
+
surrogate: { keep_prefix: "^sk-proj-", alphabet: "base64url" },
|
|
4952
5773
|
vectors: { hit: "OPENAI_API_KEY=sk-proj-AbCdEfGhIjKlMnOpQrStUvWxYz0123456789_-AbCdEf", clean: "OPENAI_API_KEY=sk-proj-AbCdEfGhIj" }
|
|
4953
5774
|
},
|
|
4954
5775
|
{
|
|
@@ -4957,6 +5778,10 @@ var secrets_default = {
|
|
|
4957
5778
|
severity: "critical",
|
|
4958
5779
|
description: "Anthropic API Key",
|
|
4959
5780
|
keywords: ["anthropic", "sk-ant-"],
|
|
5781
|
+
hosts: ["api.anthropic.com"],
|
|
5782
|
+
place: "header:x-api-key",
|
|
5783
|
+
class: "outbound",
|
|
5784
|
+
surrogate: { keep_prefix: "^sk-ant-(?:api[0-9]{2}-)?", alphabet: "base64url" },
|
|
4960
5785
|
vectors: { hit: "sk-ant-api03-AbCdEfGhIjKlMnOpQrStUvWxYz0123456789AbCd", clean: "sk-ant-api03-short" }
|
|
4961
5786
|
},
|
|
4962
5787
|
{
|
|
@@ -4965,6 +5790,10 @@ var secrets_default = {
|
|
|
4965
5790
|
severity: "critical",
|
|
4966
5791
|
description: "GitHub Token",
|
|
4967
5792
|
keywords: ["github", "token", "ghp_", "github_pat_"],
|
|
5793
|
+
hosts: ["api.github.com", "github.com", "uploads.github.com", "codeload.github.com"],
|
|
5794
|
+
place: "bearer",
|
|
5795
|
+
class: "outbound",
|
|
5796
|
+
surrogate: { keep_prefix: "^(?:gh[pousr]|github_pat)_", alphabet: "classes", checksum: "github_crc32" },
|
|
4968
5797
|
vectors: { hit: "token: ghp_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789", clean: "token: xghp_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789" }
|
|
4969
5798
|
},
|
|
4970
5799
|
{
|
|
@@ -4973,6 +5802,10 @@ var secrets_default = {
|
|
|
4973
5802
|
severity: "critical",
|
|
4974
5803
|
description: "GitLab Personal Access Token",
|
|
4975
5804
|
keywords: ["gitlab", "token"],
|
|
5805
|
+
hosts: ["gitlab.com"],
|
|
5806
|
+
place: "header:PRIVATE-TOKEN",
|
|
5807
|
+
class: "outbound",
|
|
5808
|
+
surrogate: { keep_prefix: "^glpat-", alphabet: "classes" },
|
|
4976
5809
|
vectors: { hit: "glpat-AbCdEfGhIjKlMnOpQrSt", clean: "glpat-short" }
|
|
4977
5810
|
},
|
|
4978
5811
|
{
|
|
@@ -4981,6 +5814,8 @@ var secrets_default = {
|
|
|
4981
5814
|
severity: "critical",
|
|
4982
5815
|
description: "AWS Access Key ID",
|
|
4983
5816
|
keywords: ["aws", "amazon", "access_key", "accesskey"],
|
|
5817
|
+
class: "inprocess",
|
|
5818
|
+
surrogate: { keep_prefix: "^(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)", alphabet: "classes" },
|
|
4984
5819
|
vectors: { hit: "AKIAIOSFODNN7EXAMPLE", clean: "AKIAIOSFODNN7EXAMPLEX" }
|
|
4985
5820
|
},
|
|
4986
5821
|
{
|
|
@@ -4989,6 +5824,8 @@ var secrets_default = {
|
|
|
4989
5824
|
severity: "critical",
|
|
4990
5825
|
description: "AWS Secret Access Key",
|
|
4991
5826
|
keywords: ["aws", "secret", "access_key"],
|
|
5827
|
+
class: "inprocess",
|
|
5828
|
+
surrogate: { keep_prefix: `^.*[:=]\\s*['\\"]?`, alphabet: "classes" },
|
|
4992
5829
|
vectors: { hit: 'aws_secret_access_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"', clean: 'aws_secret_access_key = "short"' }
|
|
4993
5830
|
},
|
|
4994
5831
|
{
|
|
@@ -4997,6 +5834,10 @@ var secrets_default = {
|
|
|
4997
5834
|
severity: "critical",
|
|
4998
5835
|
description: "Stripe Live Secret Key",
|
|
4999
5836
|
keywords: ["stripe", "live", "secret"],
|
|
5837
|
+
hosts: ["api.stripe.com", "files.stripe.com"],
|
|
5838
|
+
place: "bearer",
|
|
5839
|
+
class: "outbound",
|
|
5840
|
+
surrogate: { keep_prefix: "^[sr]k_live_", alphabet: "base62" },
|
|
5000
5841
|
vectors: { hit: "sk_live_AbCdEfGhIjKlMnOpQrStUvWx", clean: "sk_live_AbCd" }
|
|
5001
5842
|
},
|
|
5002
5843
|
{
|
|
@@ -5005,6 +5846,10 @@ var secrets_default = {
|
|
|
5005
5846
|
severity: "medium",
|
|
5006
5847
|
description: "Stripe Test Secret Key",
|
|
5007
5848
|
keywords: ["stripe", "test"],
|
|
5849
|
+
hosts: ["api.stripe.com", "files.stripe.com"],
|
|
5850
|
+
place: "bearer",
|
|
5851
|
+
class: "outbound",
|
|
5852
|
+
surrogate: { keep_prefix: "^[sr]k_test_", alphabet: "base62" },
|
|
5008
5853
|
vectors: { hit: "rk_test_AbCdEfGhIjKlMnOpQrStUvWx", clean: "rk_test_AbCd" }
|
|
5009
5854
|
},
|
|
5010
5855
|
{
|
|
@@ -5015,12 +5860,26 @@ var secrets_default = {
|
|
|
5015
5860
|
keywords: ["stripe", "publishable"],
|
|
5016
5861
|
vectors: { hit: "pk_live_AbCdEfGhIjKlMnOpQrStUvWx", clean: "pk_live_AbCd" }
|
|
5017
5862
|
},
|
|
5863
|
+
{
|
|
5864
|
+
name: "stripe_webhook_secret",
|
|
5865
|
+
pattern: "\\bwhsec_[A-Za-z0-9]{32,}",
|
|
5866
|
+
severity: "critical",
|
|
5867
|
+
description: "Stripe Webhook Signing Secret",
|
|
5868
|
+
keywords: ["stripe", "webhook", "whsec_"],
|
|
5869
|
+
class: "inprocess",
|
|
5870
|
+
surrogate: { keep_prefix: "^whsec_", alphabet: "base62" },
|
|
5871
|
+
vectors: { hit: "STRIPE_WEBHOOK_SECRET=whsec_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789", clean: "STRIPE_WEBHOOK_SECRET=whsec_short" }
|
|
5872
|
+
},
|
|
5018
5873
|
{
|
|
5019
5874
|
name: "slack_token",
|
|
5020
5875
|
pattern: "\\bxox[abprs]-[A-Za-z0-9-]{20,}",
|
|
5021
5876
|
severity: "critical",
|
|
5022
5877
|
description: "Slack Token",
|
|
5023
5878
|
keywords: ["slack", "token", "xox"],
|
|
5879
|
+
hosts: ["slack.com"],
|
|
5880
|
+
place: "bearer",
|
|
5881
|
+
class: "outbound",
|
|
5882
|
+
surrogate: { keep_prefix: "^xox[abprs]-", alphabet: "classes" },
|
|
5024
5883
|
vectors: { hit: "xoxb-1234567890-1234567890123-AbCdEfGhIjKl", clean: "xoxb-12345" }
|
|
5025
5884
|
},
|
|
5026
5885
|
{
|
|
@@ -5029,6 +5888,10 @@ var secrets_default = {
|
|
|
5029
5888
|
severity: "high",
|
|
5030
5889
|
description: "Slack Webhook URL",
|
|
5031
5890
|
keywords: ["slack", "webhook", "hooks.slack.com"],
|
|
5891
|
+
hosts: ["hooks.slack.com"],
|
|
5892
|
+
place: "url",
|
|
5893
|
+
class: "outbound",
|
|
5894
|
+
surrogate: { keep_prefix: "^https://hooks\\.slack\\.com/services/T[A-Z0-9]+/B", alphabet: "classes" },
|
|
5032
5895
|
vectors: { hit: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", clean: "https://hooks.slack.com/services/" }
|
|
5033
5896
|
},
|
|
5034
5897
|
{
|
|
@@ -5037,6 +5900,10 @@ var secrets_default = {
|
|
|
5037
5900
|
severity: "high",
|
|
5038
5901
|
description: "Google API Key",
|
|
5039
5902
|
keywords: ["google", "api", "AIza"],
|
|
5903
|
+
hosts: ["*.googleapis.com"],
|
|
5904
|
+
place: "query:key",
|
|
5905
|
+
class: "outbound",
|
|
5906
|
+
surrogate: { keep_prefix: "^AIza", alphabet: "base64url" },
|
|
5040
5907
|
vectors: { hit: "AIzaSyAbCdEfGhIjKlMnOpQrStUvWxYz0123456", clean: "AIzaSyShort" }
|
|
5041
5908
|
},
|
|
5042
5909
|
{
|
|
@@ -5045,6 +5912,8 @@ var secrets_default = {
|
|
|
5045
5912
|
severity: "high",
|
|
5046
5913
|
description: "Google OAuth Client Secret",
|
|
5047
5914
|
keywords: ["google", "oauth", "client_secret"],
|
|
5915
|
+
class: "inprocess",
|
|
5916
|
+
surrogate: { keep_prefix: `^.*[:=]\\s*['\\"]?`, alphabet: "classes" },
|
|
5048
5917
|
vectors: { hit: 'client_secret: "AbCdEfGhIjKlMnOpQrStUvWx"', clean: 'client_secret: "short"' }
|
|
5049
5918
|
},
|
|
5050
5919
|
{
|
|
@@ -5085,6 +5954,8 @@ var secrets_default = {
|
|
|
5085
5954
|
severity: "critical",
|
|
5086
5955
|
description: "PostgreSQL Connection String",
|
|
5087
5956
|
keywords: ["postgres", "postgresql", "database"],
|
|
5957
|
+
class: "inprocess",
|
|
5958
|
+
surrogate: { parts: "password" },
|
|
5088
5959
|
vectors: { hit: "postgresql://app:hunter2secret@db.internal:5432/app", clean: "postgresql://db.internal/app" }
|
|
5089
5960
|
},
|
|
5090
5961
|
{
|
|
@@ -5093,6 +5964,8 @@ var secrets_default = {
|
|
|
5093
5964
|
severity: "critical",
|
|
5094
5965
|
description: "MySQL Connection String",
|
|
5095
5966
|
keywords: ["mysql", "database"],
|
|
5967
|
+
class: "inprocess",
|
|
5968
|
+
surrogate: { parts: "password" },
|
|
5096
5969
|
vectors: { hit: "mysql://app:hunter2secret@db.internal/app", clean: "mysql://db.internal/app" }
|
|
5097
5970
|
},
|
|
5098
5971
|
{
|
|
@@ -5101,6 +5974,8 @@ var secrets_default = {
|
|
|
5101
5974
|
severity: "critical",
|
|
5102
5975
|
description: "MongoDB Connection String",
|
|
5103
5976
|
keywords: ["mongodb", "mongo", "database"],
|
|
5977
|
+
class: "inprocess",
|
|
5978
|
+
surrogate: { parts: "password" },
|
|
5104
5979
|
vectors: { hit: "mongodb+srv://app:hunter2secret@cluster0.example.net", clean: "mongodb://localhost" }
|
|
5105
5980
|
},
|
|
5106
5981
|
{
|
|
@@ -5109,6 +5984,8 @@ var secrets_default = {
|
|
|
5109
5984
|
severity: "high",
|
|
5110
5985
|
description: "Redis Connection String",
|
|
5111
5986
|
keywords: ["redis", "cache"],
|
|
5987
|
+
class: "inprocess",
|
|
5988
|
+
surrogate: { parts: "password" },
|
|
5112
5989
|
vectors: { hit: "redis://:hunter2secret@cache.internal:6379", clean: "redis://cache.internal:6379" }
|
|
5113
5990
|
},
|
|
5114
5991
|
{
|
|
@@ -5133,6 +6010,10 @@ var secrets_default = {
|
|
|
5133
6010
|
severity: "high",
|
|
5134
6011
|
description: "SendGrid API Key",
|
|
5135
6012
|
keywords: ["sendgrid", "email", "SG."],
|
|
6013
|
+
hosts: ["api.sendgrid.com"],
|
|
6014
|
+
place: "bearer",
|
|
6015
|
+
class: "outbound",
|
|
6016
|
+
surrogate: { keep_prefix: "^SG\\.", alphabet: "classes" },
|
|
5136
6017
|
vectors: { hit: "SG.AbCdEfGhIjKlMnOpQrStUv.AbCdEfGhIjKlMnOpQrStUvWxYz0123456789_-AbCdE", clean: "SG.short.key" }
|
|
5137
6018
|
},
|
|
5138
6019
|
{
|
|
@@ -5141,6 +6022,10 @@ var secrets_default = {
|
|
|
5141
6022
|
severity: "high",
|
|
5142
6023
|
description: "Twilio API Key",
|
|
5143
6024
|
keywords: ["twilio", "sms"],
|
|
6025
|
+
hosts: ["api.twilio.com"],
|
|
6026
|
+
place: "basic_user",
|
|
6027
|
+
class: "outbound",
|
|
6028
|
+
surrogate: { keep_prefix: "^SK", alphabet: "hex" },
|
|
5144
6029
|
vectors: { hit: "SK0123456789abcdef0123456789abcdef", clean: "SK0123456789abcdef" }
|
|
5145
6030
|
},
|
|
5146
6031
|
{
|
|
@@ -5149,6 +6034,10 @@ var secrets_default = {
|
|
|
5149
6034
|
severity: "high",
|
|
5150
6035
|
description: "NPM Access Token",
|
|
5151
6036
|
keywords: ["npm", "token"],
|
|
6037
|
+
hosts: ["registry.npmjs.org"],
|
|
6038
|
+
place: "bearer",
|
|
6039
|
+
class: "outbound",
|
|
6040
|
+
surrogate: { keep_prefix: "^npm_", alphabet: "base62" },
|
|
5152
6041
|
vectors: { hit: "npm_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789", clean: "npm_short" }
|
|
5153
6042
|
},
|
|
5154
6043
|
{
|
|
@@ -5157,6 +6046,10 @@ var secrets_default = {
|
|
|
5157
6046
|
severity: "high",
|
|
5158
6047
|
description: "PyPI API Token",
|
|
5159
6048
|
keywords: ["pypi", "token", "python"],
|
|
6049
|
+
hosts: ["upload.pypi.org"],
|
|
6050
|
+
place: "basic_pass",
|
|
6051
|
+
class: "outbound",
|
|
6052
|
+
surrogate: { keep_prefix: "^pypi-", alphabet: "base64url" },
|
|
5160
6053
|
vectors: { hit: "pypi-AbCdEfGhIjKlMnOpQrStUvWxYz0123456789_-AbCdEfGhIjKlMnOpQrStUvWxYz0123456789_-AbCdEfGhIjKlMnOpQrStUvWx", clean: "pypi-short" }
|
|
5161
6054
|
},
|
|
5162
6055
|
{
|
|
@@ -5166,6 +6059,8 @@ var secrets_default = {
|
|
|
5166
6059
|
description: "Generic Password Assignment",
|
|
5167
6060
|
keywords: ["password", "passwd", "secret"],
|
|
5168
6061
|
allowlist: ["password123", "changeme", "example", "placeholder", "xxxxxxxx"],
|
|
6062
|
+
class: "inprocess",
|
|
6063
|
+
surrogate: { keep_prefix: `^.*[:=]\\s*['\\"]`, alphabet: "classes" },
|
|
5169
6064
|
vectors: { hit: 'password = "s3cr3t-Value!"', clean: 'password = "changeme-now"' }
|
|
5170
6065
|
},
|
|
5171
6066
|
{
|
|
@@ -5174,6 +6069,8 @@ var secrets_default = {
|
|
|
5174
6069
|
severity: "medium",
|
|
5175
6070
|
description: "Generic API Key Assignment",
|
|
5176
6071
|
keywords: ["api_key", "apikey"],
|
|
6072
|
+
class: "inprocess",
|
|
6073
|
+
surrogate: { keep_prefix: `^.*[:=]\\s*['\\"]`, alphabet: "classes" },
|
|
5177
6074
|
vectors: { hit: 'api_key = "AbCdEfGhIjKlMnOpQrStUvWx"', clean: 'api_key = "short"' }
|
|
5178
6075
|
},
|
|
5179
6076
|
{
|
|
@@ -5234,16 +6131,14 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
5234
6131
|
throw new OpenError("url_invalid", "share code missing from the URL path (/s/<seal_id>/<share_code>#<key>)");
|
|
5235
6132
|
}
|
|
5236
6133
|
const { sealId, shareCode } = parsed;
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
const wrapped = parsed.fragmentVariant === "targeted_x25519_v1" ? parsed.fragment : opts.wrap ?? null;
|
|
5242
|
-
let shareKey = parsed.fragmentVariant === "key" ? base64urlToBytes(parsed.fragment) : wrapped !== null && seed ? await openLinkWrap(wrapped, seed, sealId) : null;
|
|
6134
|
+
const seed2 = opts.seed;
|
|
6135
|
+
const wrapped = opts.wrap ?? null;
|
|
6136
|
+
let shareKey = parsed.fragmentVariant === "key" ? base64urlToBytes(parsed.fragment) : wrapped !== null && seed2 ? await openLinkWrap(wrapped, seed2, sealId) : null;
|
|
6137
|
+
if (shareKey !== null) await holdShareProof(sealId, shareKey);
|
|
5243
6138
|
const request = opts.signal ? { signal: opts.signal } : {};
|
|
5244
6139
|
let meta;
|
|
5245
6140
|
try {
|
|
5246
|
-
meta = toSealMetadata(await api.getMetadata(parsed.sealId, request));
|
|
6141
|
+
meta = toSealMetadata(await api.getMetadata(parsed.sealId, { ...request, shareCode }));
|
|
5247
6142
|
} catch (err) {
|
|
5248
6143
|
if (err instanceof BackendError && (err.code === "not_found" || err.code === "revoked")) {
|
|
5249
6144
|
throw new OpenError(
|
|
@@ -5266,10 +6161,12 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
5266
6161
|
const share = await api.getShareBlob(sealId, shareCode, request);
|
|
5267
6162
|
blobBytes = share.blob;
|
|
5268
6163
|
if (shareKey === null) {
|
|
5269
|
-
if (share.wrap === null
|
|
5270
|
-
throw new OpenError("url_no_fragment", "the link carries no key
|
|
6164
|
+
if (share.wrap === null) {
|
|
6165
|
+
throw new OpenError("url_no_fragment", "the link carries no key after #: copy it whole");
|
|
5271
6166
|
}
|
|
5272
|
-
|
|
6167
|
+
if (!seed2) throw new OpenError("targeted_fragment_invalid", "this link is addressed to someone: pass their seed to open it");
|
|
6168
|
+
shareKey = await openLinkWrap(share.wrap, seed2, sealId);
|
|
6169
|
+
await holdShareProof(sealId, shareKey);
|
|
5273
6170
|
}
|
|
5274
6171
|
} catch (err) {
|
|
5275
6172
|
if (err instanceof OpenError) throw err;
|
|
@@ -5283,8 +6180,11 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
5283
6180
|
throw new OpenError("share_blob_fetch_failed", `share blob fetch failed: ${messageOf(err)}`, err);
|
|
5284
6181
|
}
|
|
5285
6182
|
let fileKeys;
|
|
6183
|
+
let bindings;
|
|
5286
6184
|
try {
|
|
5287
|
-
|
|
6185
|
+
const blob = await decryptShareBlob(blobBytes, shareKey);
|
|
6186
|
+
fileKeys = blob.file_keys;
|
|
6187
|
+
bindings = bindingsOf(blob);
|
|
5288
6188
|
} catch (err) {
|
|
5289
6189
|
throw new OpenError(
|
|
5290
6190
|
"share_blob_decrypt_failed",
|
|
@@ -5292,7 +6192,7 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
5292
6192
|
err
|
|
5293
6193
|
);
|
|
5294
6194
|
}
|
|
5295
|
-
const files = await Promise.all(meta.files.map((f) => describeFile(f, fileKeys)));
|
|
6195
|
+
const files = await Promise.all(meta.files.map((f) => describeFile(f, fileKeys, bindings)));
|
|
5296
6196
|
return {
|
|
5297
6197
|
sealId,
|
|
5298
6198
|
expiresAt: meta.expiresAt,
|
|
@@ -5303,9 +6203,9 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
5303
6203
|
files
|
|
5304
6204
|
};
|
|
5305
6205
|
}
|
|
5306
|
-
async function openLinkWrap(wrap,
|
|
6206
|
+
async function openLinkWrap(wrap, seed2, sealId) {
|
|
5307
6207
|
try {
|
|
5308
|
-
return await openWrap(wrap,
|
|
6208
|
+
return await openWrap(wrap, seed2, SHARE_SCOPE, sealId);
|
|
5309
6209
|
} catch (err) {
|
|
5310
6210
|
const aead = err instanceof WrapError && err.kind === "aead";
|
|
5311
6211
|
throw new OpenError(aead ? "targeted_decrypt_failed" : "targeted_fragment_invalid", messageOf(err), err);
|
|
@@ -5313,6 +6213,8 @@ async function openLinkWrap(wrap, seed, sealId) {
|
|
|
5313
6213
|
}
|
|
5314
6214
|
async function waitForIntake(api, intakeId, opts = {}) {
|
|
5315
6215
|
for (; ; ) {
|
|
6216
|
+
opts.signal?.throwIfAborted();
|
|
6217
|
+
const askedAt = Date.now();
|
|
5316
6218
|
let view;
|
|
5317
6219
|
try {
|
|
5318
6220
|
view = await api.getIntake(intakeId, { ...opts, waitSeconds: limits_default.limits.INTAKE_WAIT_MAX_SECONDS });
|
|
@@ -5323,11 +6225,29 @@ async function waitForIntake(api, intakeId, opts = {}) {
|
|
|
5323
6225
|
throw err;
|
|
5324
6226
|
}
|
|
5325
6227
|
if (view.status === "expired") throw new OpenError("request_expired", "nobody answered before the request expired");
|
|
5326
|
-
if (view.status === "fulfilled"
|
|
5327
|
-
return { sharePath: view.share_path, wrap: view.fragment };
|
|
6228
|
+
if (view.status === "fulfilled") {
|
|
6229
|
+
if (view.share_path && view.fragment) return { sharePath: view.share_path, wrap: view.fragment };
|
|
6230
|
+
throw new OpenError("share_blob_corrupt", "the request was answered without its link");
|
|
5328
6231
|
}
|
|
6232
|
+
if (view.status !== "pending") throw new OpenError("client_outdated", `the request is ${String(view.status)}, a state this client does not know`);
|
|
6233
|
+
const left = INTAKE_POLL_FLOOR_MS - (Date.now() - askedAt);
|
|
6234
|
+
if (left > 0) await pause(left, opts.signal);
|
|
5329
6235
|
}
|
|
5330
6236
|
}
|
|
6237
|
+
var INTAKE_POLL_FLOOR_MS = 2e3;
|
|
6238
|
+
function pause(ms, signal) {
|
|
6239
|
+
return new Promise((resolve2, reject) => {
|
|
6240
|
+
const onAbort = () => {
|
|
6241
|
+
clearTimeout(timer);
|
|
6242
|
+
reject(signal?.reason);
|
|
6243
|
+
};
|
|
6244
|
+
const timer = setTimeout(() => {
|
|
6245
|
+
signal?.removeEventListener("abort", onAbort);
|
|
6246
|
+
resolve2();
|
|
6247
|
+
}, ms);
|
|
6248
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
6249
|
+
});
|
|
6250
|
+
}
|
|
5331
6251
|
var ANSWER_MAX_BYTES = 64 * 1024;
|
|
5332
6252
|
async function readAnswerFile(api, url, mime, opts) {
|
|
5333
6253
|
const seal = await openShareLink(api, url, opts);
|
|
@@ -5335,7 +6255,7 @@ async function readAnswerFile(api, url, mime, opts) {
|
|
|
5335
6255
|
if (!file?.key || !file.sha256Hex || more.length > 0 || bareMime(file.mime) !== mime || file.size > ANSWER_MAX_BYTES) {
|
|
5336
6256
|
throw new OpenError("share_blob_corrupt", `the answer is not one ${mime} file`);
|
|
5337
6257
|
}
|
|
5338
|
-
const resp = await api.
|
|
6258
|
+
const resp = await api.downloadCiphertext(seal.sealId, { fileId: file.id }, opts.signal ? { signal: opts.signal } : {});
|
|
5339
6259
|
if (!resp.body) throw new OpenError("share_blob_corrupt", "the answer came without a body");
|
|
5340
6260
|
const reader = decryptVerified(resp.body, file.key, file.sha256Hex).stream.getReader();
|
|
5341
6261
|
const chunks = [];
|
|
@@ -5355,46 +6275,38 @@ async function publishOwn(api, identity, opts) {
|
|
|
5355
6275
|
if (held !== null && equalBytes(held, identity.bundle)) return;
|
|
5356
6276
|
await api.putBundle(identity.bundle, opts);
|
|
5357
6277
|
}
|
|
5358
|
-
async function addressProof(api,
|
|
5359
|
-
const identity = await identityOf(
|
|
6278
|
+
async function addressProof(api, seed2, opts = {}) {
|
|
6279
|
+
const identity = await identityOf(seed2);
|
|
5360
6280
|
const key2 = `${api.baseUrl} ${identity.address}`;
|
|
5361
6281
|
const kept = proofs.get(key2);
|
|
5362
6282
|
if (!opts.fresh && kept && kept.until > Date.now()) return kept.proof;
|
|
5363
6283
|
await publishOwn(api, identity, opts);
|
|
5364
6284
|
const challenge = await api.requestAddressProof(identity.address, opts);
|
|
5365
|
-
const proof = { address: identity.address, proof: await proveInbox(
|
|
6285
|
+
const proof = { address: identity.address, proof: await proveInbox(seed2, challenge) };
|
|
5366
6286
|
proofs.set(key2, { proof, until: Date.parse(challenge.expires_at) - PROOF_MARGIN_MS });
|
|
5367
6287
|
return proof;
|
|
5368
6288
|
}
|
|
5369
|
-
async function withAddressProof(api,
|
|
6289
|
+
async function withAddressProof(api, seed2, signal, call) {
|
|
5370
6290
|
const request = signal ? { signal } : {};
|
|
5371
6291
|
try {
|
|
5372
|
-
return await call(await addressProof(api,
|
|
6292
|
+
return await call(await addressProof(api, seed2, request));
|
|
5373
6293
|
} catch (err) {
|
|
5374
6294
|
if (!(err instanceof BackendError && err.appCode === "intake.proof_required")) throw err;
|
|
5375
|
-
return call(await addressProof(api,
|
|
6295
|
+
return call(await addressProof(api, seed2, { ...request, fresh: true }));
|
|
5376
6296
|
}
|
|
5377
6297
|
}
|
|
5378
|
-
async function
|
|
5379
|
-
const { legacyAddress } = await identityOf(seed);
|
|
5380
|
-
return withAddressProof(api, seed, opts.signal, async (proof) => {
|
|
5381
|
-
const challenge = await api.migrateInbox(proof, { old_address: legacyAddress }, opts);
|
|
5382
|
-
const oldProof = await proveLegacyAddress(seed, challenge.challenge, challenge.ts);
|
|
5383
|
-
return (await api.migrateInbox(proof, { old_address: legacyAddress, old_proof: oldProof }, opts)).moved;
|
|
5384
|
-
});
|
|
5385
|
-
}
|
|
5386
|
-
async function readInbox(api, seed, opts = {}) {
|
|
6298
|
+
async function readInbox(api, seed2, opts = {}) {
|
|
5387
6299
|
const list = opts;
|
|
5388
|
-
return withAddressProof(api,
|
|
6300
|
+
return withAddressProof(api, seed2, opts.signal, (proof) => api.listInbox(proof, list));
|
|
5389
6301
|
}
|
|
5390
|
-
async function removeFromInbox(api,
|
|
5391
|
-
return withAddressProof(api,
|
|
6302
|
+
async function removeFromInbox(api, seed2, itemId, opts = {}) {
|
|
6303
|
+
return withAddressProof(api, seed2, opts.signal, (proof) => api.dismissInboxItem(itemId, proof, opts));
|
|
5392
6304
|
}
|
|
5393
|
-
async function describeFile(file, fileKeys) {
|
|
6305
|
+
async function describeFile(file, fileKeys, bindings) {
|
|
5394
6306
|
const keyB64 = file.sha256_hex ? fileKeys[file.sha256_hex] : void 0;
|
|
5395
6307
|
const base = { id: file.id, size: file.size, sha256Hex: file.sha256_hex };
|
|
5396
6308
|
if (keyB64 === void 0) {
|
|
5397
|
-
return { ...base, name: ENCRYPTED_FILE_FALLBACK, mime: ENCRYPTED_MIME_FALLBACK, secret: false, key: null };
|
|
6309
|
+
return { ...base, name: ENCRYPTED_FILE_FALLBACK, mime: ENCRYPTED_MIME_FALLBACK, secret: false, key: null, binding: null };
|
|
5398
6310
|
}
|
|
5399
6311
|
let key2;
|
|
5400
6312
|
try {
|
|
@@ -5406,7 +6318,9 @@ async function describeFile(file, fileKeys) {
|
|
|
5406
6318
|
throw new OpenError("share_blob_corrupt", `share blob key for ${file.sha256_hex} is ${key2.length} bytes`);
|
|
5407
6319
|
}
|
|
5408
6320
|
const { name: name2, mime } = await decryptFileMetadataWithBytes(file, key2);
|
|
5409
|
-
|
|
6321
|
+
const secret = bareMime(mime) === SECRET_MIME;
|
|
6322
|
+
const binding = secret && file.sha256_hex ? bindings[file.sha256_hex] ?? null : null;
|
|
6323
|
+
return { ...base, name: name2, mime, secret, key: key2, binding };
|
|
5410
6324
|
}
|
|
5411
6325
|
function bareMime(mime) {
|
|
5412
6326
|
return (mime.split(";")[0] ?? mime).trim().toLowerCase();
|
|
@@ -5426,7 +6340,7 @@ function decryptVerified(body, key2, expectedSha256, onCiphertext = () => void 0
|
|
|
5426
6340
|
controller.enqueue(chunk);
|
|
5427
6341
|
}
|
|
5428
6342
|
});
|
|
5429
|
-
const
|
|
6343
|
+
const count2 = new TransformStream({
|
|
5430
6344
|
transform(plaintext, controller) {
|
|
5431
6345
|
plainHash.update(plaintext);
|
|
5432
6346
|
sizeBytes += plaintext.length;
|
|
@@ -5437,7 +6351,7 @@ function decryptVerified(body, key2, expectedSha256, onCiphertext = () => void 0
|
|
|
5437
6351
|
settle.resolve({ sizeBytes, sha256: bytesToHex(plainHash.digest()) });
|
|
5438
6352
|
}
|
|
5439
6353
|
});
|
|
5440
|
-
const stream = body.pipeThrough(tap).pipeThrough(createDecryptStream(keyCopy, { expectedSha256Hex: expectedSha256 })).pipeThrough(
|
|
6354
|
+
const stream = body.pipeThrough(tap).pipeThrough(createDecryptStream(keyCopy, { expectedSha256Hex: expectedSha256 })).pipeThrough(count2);
|
|
5441
6355
|
return { stream: rejectDoneOnError(stream, settle.reject, keyCopy), done };
|
|
5442
6356
|
}
|
|
5443
6357
|
function openErrorOf(err) {
|
|
@@ -5475,115 +6389,10 @@ function rejectDoneOnError(stream, reject, keyCopy) {
|
|
|
5475
6389
|
function messageOf(err) {
|
|
5476
6390
|
return err instanceof Error ? err.message : String(err);
|
|
5477
6391
|
}
|
|
5478
|
-
var
|
|
5479
|
-
var
|
|
5480
|
-
var
|
|
5481
|
-
|
|
5482
|
-
"PRN",
|
|
5483
|
-
"AUX",
|
|
5484
|
-
"NUL",
|
|
5485
|
-
"COM1",
|
|
5486
|
-
"COM2",
|
|
5487
|
-
"COM3",
|
|
5488
|
-
"COM4",
|
|
5489
|
-
"COM5",
|
|
5490
|
-
"COM6",
|
|
5491
|
-
"COM7",
|
|
5492
|
-
"COM8",
|
|
5493
|
-
"COM9",
|
|
5494
|
-
"LPT1",
|
|
5495
|
-
"LPT2",
|
|
5496
|
-
"LPT3",
|
|
5497
|
-
"LPT4",
|
|
5498
|
-
"LPT5",
|
|
5499
|
-
"LPT6",
|
|
5500
|
-
"LPT7",
|
|
5501
|
-
"LPT8",
|
|
5502
|
-
"LPT9"
|
|
5503
|
-
]);
|
|
5504
|
-
function detectPlatform() {
|
|
5505
|
-
if (typeof process !== "undefined" && process.platform) {
|
|
5506
|
-
switch (process.platform) {
|
|
5507
|
-
case "win32":
|
|
5508
|
-
return "windows";
|
|
5509
|
-
case "darwin":
|
|
5510
|
-
return "macos";
|
|
5511
|
-
case "linux":
|
|
5512
|
-
return "linux";
|
|
5513
|
-
case "android":
|
|
5514
|
-
return "android";
|
|
5515
|
-
default:
|
|
5516
|
-
return "unknown";
|
|
5517
|
-
}
|
|
5518
|
-
}
|
|
5519
|
-
if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
5520
|
-
const ua = navigator.userAgent.toLowerCase();
|
|
5521
|
-
if (ua.includes("win")) return "windows";
|
|
5522
|
-
if (ua.includes("android")) return "android";
|
|
5523
|
-
if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) return "ios";
|
|
5524
|
-
if (ua.includes("mac")) return "macos";
|
|
5525
|
-
if (ua.includes("linux")) return "linux";
|
|
5526
|
-
}
|
|
5527
|
-
return "unknown";
|
|
5528
|
-
}
|
|
5529
|
-
function isValidChar(char, platform) {
|
|
5530
|
-
const code = char.charCodeAt(0);
|
|
5531
|
-
if (code < 32 || code === 127) return false;
|
|
5532
|
-
switch (platform) {
|
|
5533
|
-
case "windows":
|
|
5534
|
-
return !/[<>:"/\\|?*]/.test(char);
|
|
5535
|
-
case "macos":
|
|
5536
|
-
case "ios":
|
|
5537
|
-
return !/[/:]/.test(char);
|
|
5538
|
-
case "linux":
|
|
5539
|
-
case "android":
|
|
5540
|
-
return char !== "/";
|
|
5541
|
-
default:
|
|
5542
|
-
return !/[<>:"/\\|?*]/.test(char);
|
|
5543
|
-
}
|
|
5544
|
-
}
|
|
5545
|
-
function isWindowsReservedName(name2) {
|
|
5546
|
-
const baseName = name2.split(".")[0].toUpperCase();
|
|
5547
|
-
return WINDOWS_RESERVED_NAMES.has(baseName);
|
|
5548
|
-
}
|
|
5549
|
-
function sanitizeFilename(filename, options = {}) {
|
|
5550
|
-
const {
|
|
5551
|
-
platform = detectPlatform(),
|
|
5552
|
-
replacement = REPLACEMENT_CHAR,
|
|
5553
|
-
maxLength = MAX_FILENAME_LENGTH,
|
|
5554
|
-
fallback = "file"
|
|
5555
|
-
} = options;
|
|
5556
|
-
if (!filename || !filename.trim()) {
|
|
5557
|
-
return fallback;
|
|
5558
|
-
}
|
|
5559
|
-
let result = filename.normalize("NFC");
|
|
5560
|
-
result = result.trim();
|
|
5561
|
-
result = result.replace(/^\.+|\.+$/g, "");
|
|
5562
|
-
const chars = [...result];
|
|
5563
|
-
result = chars.map((char) => isValidChar(char, platform) ? char : replacement).join("");
|
|
5564
|
-
const escapedReplacement = replacement.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5565
|
-
result = result.replace(new RegExp(`${escapedReplacement}+`, "g"), replacement);
|
|
5566
|
-
result = result.replace(new RegExp(`^(?:\\.|${escapedReplacement})+|${escapedReplacement}+$`, "g"), "");
|
|
5567
|
-
if (platform === "windows" || platform === "unknown") {
|
|
5568
|
-
if (isWindowsReservedName(result)) {
|
|
5569
|
-
result = `${replacement}${result}`;
|
|
5570
|
-
}
|
|
5571
|
-
}
|
|
5572
|
-
if (result.length > maxLength) {
|
|
5573
|
-
const lastDot = result.lastIndexOf(".");
|
|
5574
|
-
if (lastDot > 0 && lastDot > result.length - 10) {
|
|
5575
|
-
const ext = result.slice(lastDot);
|
|
5576
|
-
const base = result.slice(0, maxLength - ext.length);
|
|
5577
|
-
result = base + ext;
|
|
5578
|
-
} else {
|
|
5579
|
-
result = result.slice(0, maxLength);
|
|
5580
|
-
}
|
|
5581
|
-
}
|
|
5582
|
-
if (!result || result === replacement) {
|
|
5583
|
-
return fallback;
|
|
5584
|
-
}
|
|
5585
|
-
return result;
|
|
5586
|
-
}
|
|
6392
|
+
var LEASE_DEFAULT_DAYS = limits_default.limits.LEASE_DEFAULT_DAYS;
|
|
6393
|
+
var LEASE_MAX_DAYS = limits_default.limits.LEASE_MAX_DAYS;
|
|
6394
|
+
var LEASE_POLL_SECONDS = limits_default.limits.LEASE_POLL_SECONDS;
|
|
6395
|
+
var LEASE_STATUS_BATCH_MAX = limits_default.limits.LEASE_STATUS_BATCH_MAX;
|
|
5587
6396
|
|
|
5588
6397
|
var limits_default2 = {
|
|
5589
6398
|
version: 1,
|
|
@@ -5628,7 +6437,7 @@ var limits_default2 = {
|
|
|
5628
6437
|
description: "One-time payment for 500 GB storage and 12 months TTL"
|
|
5629
6438
|
}
|
|
5630
6439
|
},
|
|
5631
|
-
PRO_REGIONS: ["eu-west", "us-east", "us-west", "apac-southeast", "apac-northeast"],
|
|
6440
|
+
PRO_REGIONS: ["eu-west", "eu-central", "us-east", "us-west", "apac-southeast", "apac-northeast"],
|
|
5632
6441
|
ttl_options: ["5m", "30m", "1h", "1d", "7d"],
|
|
5633
6442
|
OTP_LENGTH: { min: 6, max: 10 },
|
|
5634
6443
|
USER_PASSWORD_MIN_LENGTH: 8,
|
|
@@ -5638,6 +6447,13 @@ var limits_default2 = {
|
|
|
5638
6447
|
PAYMENT_WAIT_MAX_SECONDS: 82800,
|
|
5639
6448
|
ADDRESS_PROOF_TTL_SECONDS: 300,
|
|
5640
6449
|
INBOX_MAX_ITEMS: 200,
|
|
6450
|
+
LEASE_DEFAULT_DAYS: 7,
|
|
6451
|
+
LEASE_MAX_DAYS: 90,
|
|
6452
|
+
LEASE_STATUS_BATCH_MAX: 500,
|
|
6453
|
+
LEASE_POLL_SECONDS: 600,
|
|
6454
|
+
LEASE_KEEP_DAYS: 30,
|
|
6455
|
+
APPROVE_WAIT_SECONDS: 120,
|
|
6456
|
+
APPROVE_BODY_SHOWN_BYTES: 2048,
|
|
5641
6457
|
DRIVE_OPEN_TTL_SECONDS: 300,
|
|
5642
6458
|
DRIVE_PRESIGN_WINDOW_DEFAULT_BYTES: 67108864,
|
|
5643
6459
|
DRIVE_PRESIGN_WINDOW_MIN_BYTES: 8388608,
|
|
@@ -5668,7 +6484,7 @@ var SealError = class _SealError extends Error {
|
|
|
5668
6484
|
this.name = "SealError";
|
|
5669
6485
|
this.code = code;
|
|
5670
6486
|
this.status = status;
|
|
5671
|
-
this.details = details;
|
|
6487
|
+
this.details = details && withHiddenSecrets(details);
|
|
5672
6488
|
if (Error.captureStackTrace) Error.captureStackTrace(this, _SealError);
|
|
5673
6489
|
}
|
|
5674
6490
|
toJSON() {
|
|
@@ -5681,6 +6497,17 @@ var SealError = class _SealError extends Error {
|
|
|
5681
6497
|
};
|
|
5682
6498
|
}
|
|
5683
6499
|
};
|
|
6500
|
+
var SECRET_DETAILS = ["ownerToken", "ownerLinkKey"];
|
|
6501
|
+
function withHiddenSecrets(details) {
|
|
6502
|
+
const shown = { ...details };
|
|
6503
|
+
for (const name2 of SECRET_DETAILS) {
|
|
6504
|
+
if (!(name2 in shown)) continue;
|
|
6505
|
+
const value = shown[name2];
|
|
6506
|
+
delete shown[name2];
|
|
6507
|
+
Object.defineProperty(shown, name2, { value, enumerable: false, writable: false, configurable: false });
|
|
6508
|
+
}
|
|
6509
|
+
return shown;
|
|
6510
|
+
}
|
|
5684
6511
|
var OPEN_CODES = {
|
|
5685
6512
|
url_invalid: "VALIDATION_ERROR",
|
|
5686
6513
|
url_no_fragment: "VALIDATION_ERROR",
|
|
@@ -5934,14 +6761,14 @@ var AnonymousSealsSendResource = class {
|
|
|
5934
6761
|
try {
|
|
5935
6762
|
const shareBlobB64 = bytesToBase64url(shareBlob);
|
|
5936
6763
|
shareCode = recipient && fragment ? await proven(
|
|
5937
|
-
(sender) => this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, {
|
|
6764
|
+
(sender) => this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, shareLinkKey, {
|
|
5938
6765
|
...signalOpt,
|
|
5939
6766
|
to: recipient,
|
|
5940
6767
|
fragment,
|
|
5941
6768
|
label: "sealnet",
|
|
5942
6769
|
...sender ? { sender } : {}
|
|
5943
6770
|
})
|
|
5944
|
-
) : await this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, signalOpt);
|
|
6771
|
+
) : await this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, shareLinkKey, signalOpt);
|
|
5945
6772
|
} catch (err) {
|
|
5946
6773
|
throw sealErrorFrom(
|
|
5947
6774
|
err,
|
|
@@ -6029,11 +6856,16 @@ async function receiveToDisk(opened, dir, name2) {
|
|
|
6029
6856
|
try {
|
|
6030
6857
|
await fs.link(tmp, candidate);
|
|
6031
6858
|
} catch (err) {
|
|
6032
|
-
|
|
6033
|
-
|
|
6859
|
+
const code = err.code;
|
|
6860
|
+
if (code === "EEXIST") continue;
|
|
6861
|
+
if (code !== "EPERM" && code !== "ENOTSUP" && code !== "EOPNOTSUPP" && code !== "ENOSYS") throw err;
|
|
6862
|
+
if (await fs.access(candidate).then(() => true, () => false)) continue;
|
|
6863
|
+
await fs.rename(tmp, candidate);
|
|
6864
|
+
placed = true;
|
|
6865
|
+
return { path: candidate, sizeBytes, sha256: sha2563 };
|
|
6034
6866
|
}
|
|
6035
|
-
await fs.unlink(tmp);
|
|
6036
6867
|
placed = true;
|
|
6868
|
+
await fs.unlink(tmp).catch(() => void 0);
|
|
6037
6869
|
return { path: candidate, sizeBytes, sha256: sha2563 };
|
|
6038
6870
|
}
|
|
6039
6871
|
throw new Error(`no free name for ${name2} in ${dir}`);
|
|
@@ -6046,10 +6878,16 @@ async function receiveToDisk(opened, dir, name2) {
|
|
|
6046
6878
|
}
|
|
6047
6879
|
|
|
6048
6880
|
// src/receive.ts
|
|
6881
|
+
var SECRET_KEY = /^[A-Za-z0-9_-]{86}$/;
|
|
6882
|
+
function seedOf(keyPair) {
|
|
6883
|
+
if (SECRET_KEY.test(keyPair.secretKey)) return base64urlToBytes(keyPair.secretKey);
|
|
6884
|
+
const said = keyPair.secretKey.length === 43 ? "This key is of the kind before: make a new one with keygen() and give its address to whoever sends to you. What was sent to the old address does not open." : "secretKey is not a SEAL key: expected the 86 base64url characters keygen() gives";
|
|
6885
|
+
throw new SealError(said, "INVALID_KEY", 400);
|
|
6886
|
+
}
|
|
6049
6887
|
async function resolve(api, url, opts, wrap) {
|
|
6050
6888
|
const request = opts.signal ? { signal: opts.signal } : {};
|
|
6051
6889
|
const seal = await openShareLink(api, url, {
|
|
6052
|
-
...opts.keyPair ? { seed:
|
|
6890
|
+
...opts.keyPair ? { seed: seedOf(opts.keyPair) } : {},
|
|
6053
6891
|
...wrap ? { wrap } : {},
|
|
6054
6892
|
...request
|
|
6055
6893
|
});
|
|
@@ -6065,7 +6903,7 @@ async function resolve(api, url, opts, wrap) {
|
|
|
6065
6903
|
const total = covered.reduce((sum, f) => sum + f.size, 0);
|
|
6066
6904
|
let done = 0;
|
|
6067
6905
|
const read = async (file) => {
|
|
6068
|
-
const resp = await api.
|
|
6906
|
+
const resp = await api.downloadCiphertext(
|
|
6069
6907
|
seal.sealId,
|
|
6070
6908
|
{ fileId: file.id, ...sessionCookie ? { sessionCookie } : {} },
|
|
6071
6909
|
request
|
|
@@ -6154,7 +6992,7 @@ async function pairWith(api, siteOrigin, opts) {
|
|
|
6154
6992
|
const { sharePath, wrap } = await waitIntake(api, intake.id, opts.signal);
|
|
6155
6993
|
try {
|
|
6156
6994
|
const file = await readAnswerFile(api, `${siteOrigin}${sharePath}`, PAIRING_MIME, {
|
|
6157
|
-
seed:
|
|
6995
|
+
seed: seedOf(opts.keyPair),
|
|
6158
6996
|
wrap,
|
|
6159
6997
|
...opts.signal ? { signal: opts.signal } : {}
|
|
6160
6998
|
});
|
|
@@ -6177,10 +7015,9 @@ async function keygen() {
|
|
|
6177
7015
|
return { secretKey: bytesToBase64url(seed), address, bundle: bytesToBase64url(bundle2), words };
|
|
6178
7016
|
}
|
|
6179
7017
|
async function inboxOf(api, opts) {
|
|
6180
|
-
const seed =
|
|
7018
|
+
const seed = seedOf(opts.keyPair);
|
|
6181
7019
|
const deadline = Date.now() + (opts.wait ?? 0) * 1e3;
|
|
6182
7020
|
try {
|
|
6183
|
-
await migrateInbox(api, seed, opts.signal ? { signal: opts.signal } : {}).catch(() => 0);
|
|
6184
7021
|
for (; ; ) {
|
|
6185
7022
|
const left = Math.ceil((deadline - Date.now()) / 1e3);
|
|
6186
7023
|
const wire = await readInbox(api, seed, {
|
|
@@ -6209,7 +7046,7 @@ async function inboxOf(api, opts) {
|
|
|
6209
7046
|
async function inboxRow(api, site, item, opts) {
|
|
6210
7047
|
let items;
|
|
6211
7048
|
try {
|
|
6212
|
-
items = (await readInbox(api,
|
|
7049
|
+
items = (await readInbox(api, seedOf(opts.keyPair), opts.signal ? { signal: opts.signal } : {})).items;
|
|
6213
7050
|
} catch (err) {
|
|
6214
7051
|
throw sealErrorFrom(err, "Failed to read the inbox");
|
|
6215
7052
|
}
|
|
@@ -6221,14 +7058,14 @@ async function inboxRow(api, site, item, opts) {
|
|
|
6221
7058
|
}
|
|
6222
7059
|
async function dismissItem(api, item, opts) {
|
|
6223
7060
|
try {
|
|
6224
|
-
await removeFromInbox(api,
|
|
7061
|
+
await removeFromInbox(api, seedOf(opts.keyPair), item.id, opts.signal ? { signal: opts.signal } : {});
|
|
6225
7062
|
} catch (err) {
|
|
6226
7063
|
throw sealErrorFrom(err, "Failed to remove the item");
|
|
6227
7064
|
}
|
|
6228
7065
|
}
|
|
6229
7066
|
|
|
6230
7067
|
// src/index.ts
|
|
6231
|
-
var [CLIENT_NAME = "", CLIENT_VERSION = ""] = "sealnet-js/
|
|
7068
|
+
var [CLIENT_NAME = "", CLIENT_VERSION = ""] = "sealnet-js/3.0.0".split("/");
|
|
6232
7069
|
if (typeof globalThis.process?.versions?.node !== "string") {
|
|
6233
7070
|
configureWasm(define_SEAL_WASM_default);
|
|
6234
7071
|
}
|