sealnet 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/dist/index.cjs +634 -261
- package/dist/index.d.cts +102 -34
- package/dist/index.d.ts +102 -34
- package/dist/index.js +634 -261
- 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.cjs
CHANGED
|
@@ -37,7 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
|
|
39
39
|
// <define:__SEAL_WASM__>
|
|
40
|
-
var define_SEAL_WASM_default = { url: "https://seal.net/sdk/v3.
|
|
40
|
+
var define_SEAL_WASM_default = { url: "https://seal.net/sdk/v3.1.0/seal_crypto.wasm", integrity: "sha384-cxLyz7pU4Ov7nYYJ5cqyhupM04QkkuB7UI3Fvl8FkXp8uWcm8PvGYSYu0PFl4J0O" };
|
|
41
41
|
|
|
42
42
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
43
43
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
@@ -60,7 +60,6 @@ __export2(glue_module_generated_exports, {
|
|
|
60
60
|
wasm_contract_message: () => wasm_contract_message,
|
|
61
61
|
wasm_contract_message_v2: () => wasm_contract_message_v2,
|
|
62
62
|
wasm_ed25519_verify: () => wasm_ed25519_verify,
|
|
63
|
-
wasm_sealbox_unwrap: () => wasm_sealbox_unwrap,
|
|
64
63
|
wasm_sealbox_wrap: () => wasm_sealbox_wrap,
|
|
65
64
|
wasm_summary_message: () => wasm_summary_message,
|
|
66
65
|
wasm_unwrap_file_key: () => wasm_unwrap_file_key,
|
|
@@ -278,27 +277,6 @@ var WasmIdentity = class _WasmIdentity {
|
|
|
278
277
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
279
278
|
}
|
|
280
279
|
}
|
|
281
|
-
/**
|
|
282
|
-
* The X25519 address before C1 (base64url) — the migration (Р18), until
|
|
283
|
-
* the removal.
|
|
284
|
-
* @returns {string}
|
|
285
|
-
*/
|
|
286
|
-
legacyAddress() {
|
|
287
|
-
let deferred1_0;
|
|
288
|
-
let deferred1_1;
|
|
289
|
-
try {
|
|
290
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
291
|
-
wasm.wasmidentity_legacyAddress(retptr, this.__wbg_ptr);
|
|
292
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
293
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
294
|
-
deferred1_0 = r0;
|
|
295
|
-
deferred1_1 = r1;
|
|
296
|
-
return getStringFromWasm0(r0, r1);
|
|
297
|
-
} finally {
|
|
298
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
299
|
-
wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
280
|
/**
|
|
303
281
|
* The key a packed box carries for this identity.
|
|
304
282
|
* @param {Uint8Array} packed_box
|
|
@@ -649,29 +627,6 @@ function wasm_ed25519_verify(public_key, message, signature) {
|
|
|
649
627
|
const ret = wasm.wasm_ed25519_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
650
628
|
return ret !== 0;
|
|
651
629
|
}
|
|
652
|
-
function wasm_sealbox_unwrap(packed_grant, recipient_secret, scope_type, scope_id) {
|
|
653
|
-
try {
|
|
654
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
655
|
-
const ptr0 = passArray8ToWasm0(packed_grant, wasm.__wbindgen_export3);
|
|
656
|
-
const len0 = WASM_VECTOR_LEN;
|
|
657
|
-
const ptr1 = passArray8ToWasm0(recipient_secret, wasm.__wbindgen_export3);
|
|
658
|
-
const len1 = WASM_VECTOR_LEN;
|
|
659
|
-
const ptr2 = passStringToWasm0(scope_type, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
660
|
-
const len2 = WASM_VECTOR_LEN;
|
|
661
|
-
const ptr3 = passStringToWasm0(scope_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
662
|
-
const len3 = WASM_VECTOR_LEN;
|
|
663
|
-
wasm.wasm_sealbox_unwrap(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
664
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
665
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
666
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
667
|
-
if (r2) {
|
|
668
|
-
throw takeObject(r1);
|
|
669
|
-
}
|
|
670
|
-
return takeObject(r0);
|
|
671
|
-
} finally {
|
|
672
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
630
|
function wasm_sealbox_wrap(key_to_wrap, packed_bundle, scope_type, scope_id) {
|
|
676
631
|
try {
|
|
677
632
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -1432,6 +1387,8 @@ var limits_default = {
|
|
|
1432
1387
|
MAX_FILE_KEYS: 1e4,
|
|
1433
1388
|
MAX_ACTIVE_UPLOADS_PER_SEAL: 10,
|
|
1434
1389
|
MAX_OPENS_PER_SEAL_FREE: 10,
|
|
1390
|
+
MAX_GEO_COUNTRIES: 50,
|
|
1391
|
+
SEAL_VISIT_SECONDS: 21600,
|
|
1435
1392
|
TIER_BYTES: {
|
|
1436
1393
|
free: 1073741824,
|
|
1437
1394
|
"5gb": 5368709120,
|
|
@@ -1523,7 +1480,6 @@ var crypto_default = {
|
|
|
1523
1480
|
}
|
|
1524
1481
|
},
|
|
1525
1482
|
hkdf: {
|
|
1526
|
-
wrap_key_salt: "seal:wrapkey:v1",
|
|
1527
1483
|
wrap_key_salt_v2: "seal:wrapkey:v2",
|
|
1528
1484
|
identity_key_salt: "seal:key-derivation:v1",
|
|
1529
1485
|
file_envelope_salt: "seal:file-envelope:v1",
|
|
@@ -1556,7 +1512,7 @@ var crypto_default = {
|
|
|
1556
1512
|
},
|
|
1557
1513
|
secret_scope_aad: "secret:{secret_id}",
|
|
1558
1514
|
scope_metadata_aad: {
|
|
1559
|
-
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
|
|
1515
|
+
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`. Since the old binding's end (SPEC-NAMES-BOUND \u04213) a text of before is read only of the kinds in `org_object.before_read` \u2014 a contract's data and a member's drawing lie under their signatures and are never sealed again (\u041D5) \u2014; any other, and a seal's folder's name, opens bound alone.",
|
|
1560
1516
|
room: "room:{room_id}:{field}",
|
|
1561
1517
|
org_object: {
|
|
1562
1518
|
bound: "{kind}:{org_id}:{object_id}:{field}",
|
|
@@ -1571,12 +1527,17 @@ var crypto_default = {
|
|
|
1571
1527
|
"sign-request-meta",
|
|
1572
1528
|
"sign-field-value"
|
|
1573
1529
|
],
|
|
1530
|
+
before_read: [
|
|
1531
|
+
"sign-request-meta",
|
|
1532
|
+
"sign-field-value"
|
|
1533
|
+
],
|
|
1574
1534
|
field: "name",
|
|
1575
1535
|
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"
|
|
1576
1536
|
},
|
|
1577
1537
|
folder: {
|
|
1578
1538
|
bound: "seal:{seal_id}:{folder_id}:name",
|
|
1579
|
-
before: "seal:{seal_id}:name"
|
|
1539
|
+
before: "seal:{seal_id}:name",
|
|
1540
|
+
before_read: false
|
|
1580
1541
|
},
|
|
1581
1542
|
versions: {
|
|
1582
1543
|
before: 3,
|
|
@@ -1597,6 +1558,14 @@ var crypto_default = {
|
|
|
1597
1558
|
before_aad: "secret:0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e:name",
|
|
1598
1559
|
before_b64: "OGmxAlSNNBiKlnxW4fkbPMjFoZGJJDY="
|
|
1599
1560
|
},
|
|
1561
|
+
org_object_signed: {
|
|
1562
|
+
kind: "sign-request-meta",
|
|
1563
|
+
org_id: "0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e",
|
|
1564
|
+
object_id: "5c2e8f71-3a94-4d0b-b6e1-0f7a9c2d4e85",
|
|
1565
|
+
text: "NDA Acme 2026",
|
|
1566
|
+
before_aad: "sign-request-meta:0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e:name",
|
|
1567
|
+
before_b64: "Bl+fRjiKO/seUG/a7Ln0rJ0phFB+8MGpdfuM+fI="
|
|
1568
|
+
},
|
|
1600
1569
|
folder: {
|
|
1601
1570
|
seal_id: "AbCd1234",
|
|
1602
1571
|
folder_id: "c0ffee00-1234-4abc-8def-0123456789ab",
|
|
@@ -1801,29 +1770,12 @@ var seal_address_default = {
|
|
|
1801
1770
|
owner_copy: "box.ownerCopy {sealId, ownerToken, linkKey} -> {ok: boolean}",
|
|
1802
1771
|
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)"
|
|
1803
1772
|
},
|
|
1804
|
-
migrate: {
|
|
1805
|
-
until: "C1 + 7 days (C1 \xA76)",
|
|
1806
|
-
is: "Every inbox and agent changes its address once (\xA75.7). The X25519 key does not change \u2014 it is the seed \u2014 so the client moves the live rows of its old address once, under the proof of its new one: POST /intake/migrate {old_address} answers the old challenge, {old_address, old_proof} moves links, owner copies, cards and push subscriptions; the agreement key of the new address's bundle must equal the old address, and the senders of moved rows are cleared. Zero rows is a success.",
|
|
1807
|
-
old_address: "the X25519 public key of the seed, base64url without padding, 43 characters",
|
|
1808
|
-
challenge: "sealed box v1 of a 32-byte token to the old address with scope (address_proof, decimal ts): ephemeral_pub(32) || nonce(12) || ciphertext(48), base64url, 123 characters",
|
|
1809
|
-
old_proof: "<ts>.<token>: token base64url of the 32 bytes the challenge opens to",
|
|
1810
|
-
scope_address_proof: "seal_address_proof",
|
|
1811
|
-
vector: {
|
|
1812
|
-
comment: "every client that migrates must open it",
|
|
1813
|
-
secret: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc",
|
|
1814
|
-
address: "E75P6uryBMf9M1j8nAByGIHRdCeBKCJ-xnTzf3_pe20",
|
|
1815
|
-
ts: 179e7,
|
|
1816
|
-
challenge: "4Oel-UMfgP_1dBhmf13yZiujhPDouCIQ6sSx1nY1qy-vyzFqDqb9jARbJ0e5A8vv4EDELDS5OPqBQMcsmDA-C_lXO95y_CVUyYtSu-1fltsy5ZihOFDp0T-C9Ro",
|
|
1817
|
-
token: "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8"
|
|
1818
|
-
}
|
|
1819
|
-
},
|
|
1820
1773
|
vectors: [
|
|
1821
1774
|
{
|
|
1822
1775
|
address: "Afdcc-OkgjU572_xdbUHZSNPO6r6Up6ctP2pfF0PHJw",
|
|
1823
1776
|
bundle: "4rFhOdoKNSNI9qMxGju3FssbOjE0YN8CnitU4OD4dW4Eun0cCRx-W2Ad-PsAyD8R9LVv_v5mxs08kUEG5VurbwtRz7BXT4NoZoZytUXshnRVuBnjT3nghVcGmLLCpUi4qVzBsZOkO3e7tBbmAHsnDDF1eEPkjS0zQ6s6mkmFbHQnANoFXUnSM6ESOpPMmi11pv4QE9XYRpj2C_5JzmFXWLiYTA3pucRjUgPZkSmgp38RGRWZbcpsexeMmmJCdEolY52MoQaJesxJYRPgzlMSa9YnEICxfr8Xuwkgpxw3ucOxMolUXQKUBToGfUUxtC7BHrq2W3wEcF4LJaFytD44qdW2Ze0LSf8IlsESZWj6YbLabL25FAwmGntZKHQ7LDK7C4ZXsNVioS9yDNh1ADaqdTqGZnPlDaI2HiDCGVMzVTOQRvt6BZWKSUNrudd7t-2JxyUCWFk5szNrcUVJwsBrNdIXm_04iuvbcW-4s-kmXmX6CStgPdZSVgFgcAOQwsOwU57zjoA0pehUqiLwaHbLu0Z5poD1agnppIXItFLhVkRDExOHF7KxUD70CEJjUrHxxf0ln4H1S1t3udfFTA11SjBYXsTxq0VIMDoTnXzYenHLWXpYwDlogzagyb1UXfprRkNgbssmd9xyw_aKz2AWjAdqpeAmIwVbnlfcxA-0MixZpVtkpSyZeXhwAPf8Q0raFNESLbJSBx1GStgiNzNkf553RC0JCLXITOw6YHuyQKF8y05gFwXTjJ0hBwUgTEQVJt71miJ8N7asYFDrAVSWm7t0qA55RobkTdnBliKCCjrnKxGET5M0sPrlyC3yTUu3fHrpEDRqiN8yFZRpD9QBXtaorIM8b6XcVAWJFKjauhn5tC4RAJDEi384o_NQAg0WowA3UuJ0LFg5ELRGQuZCrP_RVIHGAR5lcOeSY9SzW-dmp-MbsfSWf_iBEkYsc_iFTwkTf3M5Thd4TSJxwJ9odRS0LqRZgrgEWcYYl5PalYYrBHqhsMiAshpzibQLTPbQh1CUMTLMIrorvqVbhdZovQmSdShIWLTmkhWJGN_seAfnQNFhufXlg2dsNSGZCdcivn_VfKUHFpm8DOHRCqWcdwcrw7K3gtPgTC2GQvSJxAH6pq5hshTKCqF6mtFiA2-FbjYwDhRskt8Mf15IkQWDCI2LNDnJLg6qPMbaMxUEyWd7N1QWmHNgtU9syAMLhVHsHlohPq8ZdygIRIw6IjbFR0EDb8jYhY1DQUc3WWLQX_AsdMwHNgeRzhlcd2fohE5BzB_Lb3V1NpmsMPe2FhmGD8b3Pb-1ZR-MtJD6tgq1YSs7JOeWjKETlN2YqCaIFCeRWUIygkpbF158x4lVqqgQQZ70kzXsJTWJZbY5mvXHbAUsWLezERn4hWWKau_Mno78GTRKZfO5ymbWl4Hku8ECskl3dL8oy5hAOGhGcGOyhDLXISTTZL3JQ2Qwy0X7AfqDIQCTnuCLa3_AhIsjMXFzB-rCq8WjUsh4YsW1ENBJjV_2G6-HWRVDpo6nIDVnZRGxATTCvnLjXcn0USEXsBI6R6aAcgqGXzabd_QyLpK2EdUnaH3xIWjGYsdRjIuUWQM3odyjH7TFOurwlQV3hU2KMmAO13XqmD5fvhxVi5-kWTnN16EDDV0EXLky4Jug0SNgHchy3ymbXVBx8TfsJcCumYk9iuui2D-cDpa7KJEGwBVN-9lvLEidQddWX_CMfbmG_wdHaC4Hapi-U2OhsH-2AwEAAAA",
|
|
1824
1777
|
challenge: "wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t8",
|
|
1825
1778
|
comment: "generated once by shared/core (Identity::from_seed32, Identity::inbox_proof); every client must reproduce it",
|
|
1826
|
-
legacy_address: "BLp9HAkcfltgHfj7AMg_EfS1b_7-ZsbNPJFBBuVbq28",
|
|
1827
1779
|
proof: "1790000000.wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t8.74s5T1rE2xRNbameeTbYUHVMN-ZzFu1JBPZJNtH8eYC1vV7-h2HE_hxgo4vUB0_sHFfdYRUf0bve4_KGe32ICg",
|
|
1828
1780
|
seed: "Aw4ZJC86RVBbZnF8h5KdqLO-ydTf6vUACxYhLDdCTVg",
|
|
1829
1781
|
signature: "74s5T1rE2xRNbameeTbYUHVMN-ZzFu1JBPZJNtH8eYC1vV7-h2HE_hxgo4vUB0_sHFfdYRUf0bve4_KGe32ICg",
|
|
@@ -1867,6 +1819,7 @@ var upload_default = {
|
|
|
1867
1819
|
VERIFY_POLL_BACKOFF_MS: [0, 2e3, 3e3, 5e3, 8e3],
|
|
1868
1820
|
VERIFY_FALLBACK_WAIT_MS: 6e4,
|
|
1869
1821
|
NOT_READY_MAX_RETRIES: 3,
|
|
1822
|
+
VISIT_HEADER: "X-Seal-Visit",
|
|
1870
1823
|
PROGRESS_SPEED_WINDOW_MS: 2e4
|
|
1871
1824
|
}
|
|
1872
1825
|
};
|
|
@@ -2167,8 +2120,9 @@ var clientIdentity;
|
|
|
2167
2120
|
function setClientIdentity(name2, version) {
|
|
2168
2121
|
clientIdentity = `${name2}/${version}`;
|
|
2169
2122
|
}
|
|
2123
|
+
var requestHeaders = () => void 0;
|
|
2170
2124
|
function clientHeaders() {
|
|
2171
|
-
return clientIdentity === void 0 ? {} : { [header]: clientIdentity };
|
|
2125
|
+
return { ...clientIdentity === void 0 ? {} : { [header]: clientIdentity }, ...requestHeaders() };
|
|
2172
2126
|
}
|
|
2173
2127
|
var BackendError = class extends Error {
|
|
2174
2128
|
constructor(message, code, status, extra = {}) {
|
|
@@ -2240,6 +2194,10 @@ function toSealMetadata(wire) {
|
|
|
2240
2194
|
}))
|
|
2241
2195
|
};
|
|
2242
2196
|
}
|
|
2197
|
+
var VISIT_HEADER = upload_default.upload.VISIT_HEADER;
|
|
2198
|
+
function newVisit() {
|
|
2199
|
+
return bytesToBase64url(crypto.getRandomValues(new Uint8Array(16)));
|
|
2200
|
+
}
|
|
2243
2201
|
function encode(segment) {
|
|
2244
2202
|
return encodeURIComponent(segment);
|
|
2245
2203
|
}
|
|
@@ -2416,7 +2374,7 @@ var SealApi = class _SealApi {
|
|
|
2416
2374
|
/**
|
|
2417
2375
|
* `GET /seal/{id}/download` — the ciphertext, as a live `Response`.
|
|
2418
2376
|
*
|
|
2419
|
-
* THIS is the call that
|
|
2377
|
+
* THIS is the call that takes an open (one a `visit`, each file of it once), so every
|
|
2420
2378
|
* policy check a caller wants to make belongs before it: once a counter
|
|
2421
2379
|
* ticks it stays ticked, whatever the caller does with the bytes.
|
|
2422
2380
|
*
|
|
@@ -2445,6 +2403,7 @@ var SealApi = class _SealApi {
|
|
|
2445
2403
|
async openDownload(sealId, target, opts = {}) {
|
|
2446
2404
|
const headers = target.ownerToken ? _SealApi.ownerHeaders(target.ownerToken) : {};
|
|
2447
2405
|
if (target.sessionCookie) headers.Cookie = target.sessionCookie;
|
|
2406
|
+
if (target.visit) headers[VISIT_HEADER] = target.visit;
|
|
2448
2407
|
for (let retries = 0; ; retries++) {
|
|
2449
2408
|
try {
|
|
2450
2409
|
return await this.request(`/seal/${encode(sealId)}/download?${downloadQuery(target)}`, {
|
|
@@ -2697,10 +2656,11 @@ var SealApi = class _SealApi {
|
|
|
2697
2656
|
if (input.ttlSeconds !== void 0) body.ttl_seconds = input.ttlSeconds;
|
|
2698
2657
|
if (input.to) body.to = input.to;
|
|
2699
2658
|
if (input.bind) body.bind = input.bind;
|
|
2659
|
+
if (input.answerToInbox) body.answer_to_inbox = true;
|
|
2700
2660
|
const resp = await this.request("/intake", {
|
|
2701
2661
|
what: "POST /intake",
|
|
2702
2662
|
method: "POST",
|
|
2703
|
-
headers: { "Content-Type": "application/json" },
|
|
2663
|
+
headers: { "Content-Type": "application/json", ...input.answerToInbox ? proofHeaders(input.answerToInbox) : {} },
|
|
2704
2664
|
body: JSON.stringify(body),
|
|
2705
2665
|
signal: opts.signal
|
|
2706
2666
|
});
|
|
@@ -2719,12 +2679,15 @@ var SealApi = class _SealApi {
|
|
|
2719
2679
|
});
|
|
2720
2680
|
return await resp.json();
|
|
2721
2681
|
}
|
|
2722
|
-
/**
|
|
2682
|
+
/**
|
|
2683
|
+
* `POST /intake/{id}/fulfil` — the page reports the seal it made; once. It carries the proof of the link it holds
|
|
2684
|
+
* for that seal (`holdShareProof`): an answer into a person's inbox is a link its maker proves (OWNER.md 9).
|
|
2685
|
+
*/
|
|
2723
2686
|
async fulfilIntake(intakeId, link, opts = {}) {
|
|
2724
2687
|
const resp = await this.request(`/intake/${encode(intakeId)}/fulfil`, {
|
|
2725
2688
|
what: `POST /intake/${intakeId}/fulfil`,
|
|
2726
2689
|
method: "POST",
|
|
2727
|
-
headers: { "Content-Type": "application/json" },
|
|
2690
|
+
headers: { "Content-Type": "application/json", ...shareProofHeader(`/seal/${encode(link.sealId)}`) },
|
|
2728
2691
|
body: JSON.stringify({ seal_id: link.sealId, share_code: link.shareCode, fragment: link.fragment }),
|
|
2729
2692
|
signal: opts.signal
|
|
2730
2693
|
});
|
|
@@ -2981,6 +2944,11 @@ async function encryptBlob(data, linkKey) {
|
|
|
2981
2944
|
result.set(new Uint8Array(ciphertext), 12);
|
|
2982
2945
|
return result;
|
|
2983
2946
|
}
|
|
2947
|
+
function isNdaFileRef(value) {
|
|
2948
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2949
|
+
const obj = value;
|
|
2950
|
+
return typeof obj.sha256_hex === "string" && typeof obj.name === "string";
|
|
2951
|
+
}
|
|
2984
2952
|
function isBinding(value) {
|
|
2985
2953
|
if (typeof value !== "object" || value === null) return false;
|
|
2986
2954
|
const obj = value;
|
|
@@ -3566,6 +3534,10 @@ var encoder2 = new TextEncoder();
|
|
|
3566
3534
|
var zipLogger = createLogger("FolderZip");
|
|
3567
3535
|
var BLOB_LIMIT = 100 * 1024 * 1024;
|
|
3568
3536
|
var HIGH_WATER_BYTES = 4 * 1024 * 1024;
|
|
3537
|
+
var dropped = /* @__PURE__ */ new WeakMap();
|
|
3538
|
+
function folderPathOf(file) {
|
|
3539
|
+
return dropped.get(file) ?? (file.webkitRelativePath || void 0);
|
|
3540
|
+
}
|
|
3569
3541
|
var ENCRYPTED_FILE_FALLBACK = "Encrypted file";
|
|
3570
3542
|
var ENCRYPTED_MIME_FALLBACK = "application/octet-stream";
|
|
3571
3543
|
function metadataFieldAAD(field) {
|
|
@@ -5058,6 +5030,48 @@ async function uploadRegisteredFile(session, entry, callbacks = {}) {
|
|
|
5058
5030
|
entry.prepared = void 0;
|
|
5059
5031
|
report("done", 1, true);
|
|
5060
5032
|
}
|
|
5033
|
+
async function uploadPendingFiles(session, options = {}) {
|
|
5034
|
+
const { signal, onFileProgress } = options;
|
|
5035
|
+
const isMultipart = (entry) => usesMultipart(entry.file.size, session.policy);
|
|
5036
|
+
const pending = session.pending;
|
|
5037
|
+
const small = pending.filter((entry) => !isMultipart(entry));
|
|
5038
|
+
const large = pending.filter(isMultipart);
|
|
5039
|
+
const stop = new AbortController();
|
|
5040
|
+
const onCallerAbort = () => stop.abort();
|
|
5041
|
+
if (signal?.aborted) stop.abort();
|
|
5042
|
+
else signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
5043
|
+
let failure = null;
|
|
5044
|
+
const runOne = async (entry) => {
|
|
5045
|
+
try {
|
|
5046
|
+
await uploadRegisteredFile(session, entry, {
|
|
5047
|
+
signal: stop.signal,
|
|
5048
|
+
onProgress: (progress) => onFileProgress?.(entry, progress)
|
|
5049
|
+
});
|
|
5050
|
+
} catch (err) {
|
|
5051
|
+
if (failure === null) {
|
|
5052
|
+
failure = err;
|
|
5053
|
+
stop.abort();
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
};
|
|
5057
|
+
try {
|
|
5058
|
+
let next = 0;
|
|
5059
|
+
const lane = async () => {
|
|
5060
|
+
while (failure === null && !stop.signal.aborted && next < small.length) await runOne(small[next++]);
|
|
5061
|
+
};
|
|
5062
|
+
await Promise.all(
|
|
5063
|
+
Array.from({ length: Math.min(upload_default.upload.SMALL_FILE_POOL, small.length) }, lane)
|
|
5064
|
+
);
|
|
5065
|
+
for (const entry of large) {
|
|
5066
|
+
if (failure !== null || stop.signal.aborted) break;
|
|
5067
|
+
await runOne(entry);
|
|
5068
|
+
}
|
|
5069
|
+
} finally {
|
|
5070
|
+
signal?.removeEventListener("abort", onCallerAbort);
|
|
5071
|
+
}
|
|
5072
|
+
if (failure !== null) throw failure;
|
|
5073
|
+
if (signal?.aborted) throw new UploadError("Upload aborted", "ABORTED");
|
|
5074
|
+
}
|
|
5061
5075
|
function validateSealContext(ctx) {
|
|
5062
5076
|
if (ctx.roomId) return;
|
|
5063
5077
|
if (!ctx.ownerTokenHash) {
|
|
@@ -5190,9 +5204,56 @@ function toSessionFiles(planned, rows) {
|
|
|
5190
5204
|
state: "pending"
|
|
5191
5205
|
}));
|
|
5192
5206
|
}
|
|
5193
|
-
|
|
5207
|
+
function keysByDigest(files) {
|
|
5208
|
+
const keys = /* @__PURE__ */ new Map();
|
|
5209
|
+
for (const entry of files) keys.set(entry.sha256_hex, entry.key);
|
|
5210
|
+
return keys;
|
|
5211
|
+
}
|
|
5212
|
+
function batchProgress(files) {
|
|
5213
|
+
const totalSize = files.reduce((sum, f) => sum + f.file.size, 0);
|
|
5214
|
+
const percents = /* @__PURE__ */ new Map();
|
|
5215
|
+
for (const f of files) percents.set(f.index, f.state === "pending" ? 0 : 100);
|
|
5216
|
+
let floor = 0;
|
|
5217
|
+
return {
|
|
5218
|
+
/** Record one file's percent; returns the batch's, 100 only when every file is done. */
|
|
5219
|
+
note(entry, progress) {
|
|
5220
|
+
percents.set(entry.index, progress.phase === "done" ? 100 : Math.max(percents.get(entry.index) ?? 0, progress.percent));
|
|
5221
|
+
const finished = files.every((f) => percents.get(f.index) === 100);
|
|
5222
|
+
const weighted = files.reduce((sum, f) => sum + f.file.size * (percents.get(f.index) ?? 0), 0);
|
|
5223
|
+
const overall = totalSize > 0 ? Math.floor(weighted / totalSize) : 100;
|
|
5224
|
+
floor = Math.max(floor, finished ? 100 : Math.min(99, overall));
|
|
5225
|
+
return { percent: floor, finished };
|
|
5226
|
+
}
|
|
5227
|
+
};
|
|
5228
|
+
}
|
|
5229
|
+
async function runManyFiles(session, callbacks) {
|
|
5230
|
+
const { onProgress, signal } = callbacks;
|
|
5231
|
+
const files = session.files;
|
|
5232
|
+
const batch = batchProgress(files);
|
|
5233
|
+
await uploadPendingFiles(session, {
|
|
5234
|
+
signal,
|
|
5235
|
+
onFileProgress: (entry, p) => {
|
|
5236
|
+
onProgress?.({
|
|
5237
|
+
fileIndex: entry.index,
|
|
5238
|
+
totalFiles: files.length,
|
|
5239
|
+
fileName: entry.file.name,
|
|
5240
|
+
fileProgress: p,
|
|
5241
|
+
overallPercent: batch.note(entry, p).percent
|
|
5242
|
+
});
|
|
5243
|
+
}
|
|
5244
|
+
});
|
|
5245
|
+
}
|
|
5246
|
+
async function openManyFilesSession(ctx, items, policy, callbacks, shape) {
|
|
5247
|
+
if (items.length === 0) {
|
|
5248
|
+
throw new Error("At least one file is required");
|
|
5249
|
+
}
|
|
5194
5250
|
validateSealContext(ctx);
|
|
5195
|
-
const planned = await planFile(file, generateKey());
|
|
5251
|
+
const planned = await Promise.all(items.map(({ file }) => planFile(file, generateKey())));
|
|
5252
|
+
const filesMeta = await Promise.all(planned.map(
|
|
5253
|
+
(p, i) => buildFileMeta(p.file, p.key, ciphertextSize(p.file.size), p.sha256_hex, {
|
|
5254
|
+
relativePath: items[i].relativePath
|
|
5255
|
+
})
|
|
5256
|
+
));
|
|
5196
5257
|
const sessionOf = (registration, files) => new UploadSession(
|
|
5197
5258
|
{
|
|
5198
5259
|
ctx,
|
|
@@ -5203,35 +5264,52 @@ async function uploadSingleFile(ctx, file, policy = DEFAULT_POLICY, callbacks =
|
|
|
5203
5264
|
files
|
|
5204
5265
|
},
|
|
5205
5266
|
async (s, cb) => {
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
onProgress: (p) => cb.onProgress?.(p),
|
|
5209
|
-
signal: cb.signal
|
|
5210
|
-
});
|
|
5211
|
-
return {
|
|
5212
|
-
sealId: s.sealId,
|
|
5213
|
-
fileId: entry.fileId,
|
|
5214
|
-
encryptionKey: entry.key,
|
|
5215
|
-
sha256_hex: entry.sha256_hex,
|
|
5216
|
-
expiresAt: s.expiresAt,
|
|
5217
|
-
verification: s.verification
|
|
5218
|
-
};
|
|
5267
|
+
await runManyFiles(s, cb);
|
|
5268
|
+
return shape(s);
|
|
5219
5269
|
}
|
|
5220
5270
|
);
|
|
5221
|
-
const seal = await createSeal(
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
callbacks.signal,
|
|
5225
|
-
// A seal this upload created is given back whole.
|
|
5226
|
-
(late) => sessionOf(late, []).cancel(),
|
|
5227
|
-
registrationDeadlineMs(policy)
|
|
5228
|
-
);
|
|
5229
|
-
const rows = await pairOrGiveBack(seal.files, [planned.sha256_hex], `Create seal ${seal.id}`, () => sessionOf(seal, []).cancel());
|
|
5230
|
-
const session = sessionOf(seal, toSessionFiles([planned], rows));
|
|
5271
|
+
const seal = await createSeal(ctx, filesMeta, callbacks.signal, (late) => sessionOf(late, []).cancel(), registrationDeadlineMs(policy));
|
|
5272
|
+
const rows = await pairOrGiveBack(seal.files, planned.map((p) => p.sha256_hex), `Create seal ${seal.id}`, () => sessionOf(seal, []).cancel());
|
|
5273
|
+
const session = sessionOf(seal, toSessionFiles(planned, rows));
|
|
5231
5274
|
await stopIfCancelled(session, callbacks.signal);
|
|
5232
|
-
await announceRegistered(callbacks, seal.id,
|
|
5275
|
+
await announceRegistered(callbacks, seal.id, planned, rows);
|
|
5233
5276
|
return session.resume(callbacks);
|
|
5234
5277
|
}
|
|
5278
|
+
async function uploadMultipleFiles(ctx, files, policy = DEFAULT_POLICY, callbacks = {}) {
|
|
5279
|
+
return openManyFilesSession(ctx, files.map((file) => ({ file })), policy, callbacks, (s) => ({
|
|
5280
|
+
sealId: s.sealId,
|
|
5281
|
+
files: s.files.map((entry) => ({
|
|
5282
|
+
fileId: entry.fileId,
|
|
5283
|
+
sha256_hex: entry.sha256_hex,
|
|
5284
|
+
encryptedSize: entry.encryptedSize
|
|
5285
|
+
})),
|
|
5286
|
+
encryptionKeys: keysByDigest(s.files),
|
|
5287
|
+
expiresAt: s.expiresAt,
|
|
5288
|
+
verification: s.verification
|
|
5289
|
+
}));
|
|
5290
|
+
}
|
|
5291
|
+
async function uploadFolderAsFiles(ctx, files, folderName, policy = DEFAULT_POLICY, callbacks = {}, relativePaths) {
|
|
5292
|
+
if (relativePaths && relativePaths.length !== files.length) {
|
|
5293
|
+
throw new Error(`uploadFolderAsFiles: ${files.length} file(s) but ${relativePaths.length} path(s)`);
|
|
5294
|
+
}
|
|
5295
|
+
const items = files.map((file, i) => ({
|
|
5296
|
+
file,
|
|
5297
|
+
relativePath: relativePaths?.[i] || file.webkitRelativePath || `${folderName}/${file.name}`
|
|
5298
|
+
}));
|
|
5299
|
+
return openManyFilesSession(ctx, items, policy, callbacks, (s) => ({
|
|
5300
|
+
sealId: s.sealId,
|
|
5301
|
+
files: s.files.map((entry) => ({
|
|
5302
|
+
fileId: entry.fileId,
|
|
5303
|
+
sha256_hex: entry.sha256_hex,
|
|
5304
|
+
encryptedSize: entry.encryptedSize,
|
|
5305
|
+
relativePath: items[entry.index].relativePath
|
|
5306
|
+
})),
|
|
5307
|
+
encryptionKeys: keysByDigest(s.files),
|
|
5308
|
+
folderName,
|
|
5309
|
+
expiresAt: s.expiresAt,
|
|
5310
|
+
verification: s.verification
|
|
5311
|
+
}));
|
|
5312
|
+
}
|
|
5235
5313
|
var PAYMENT_POLL_MS = [2e3, 4e3, 8e3, 15e3];
|
|
5236
5314
|
var TIER_BYTES = limits_default.limits.TIER_BYTES;
|
|
5237
5315
|
var PAID_TIERS = Object.keys(TIER_BYTES).filter((code) => code !== "free").sort((a, b) => TIER_BYTES[a] - TIER_BYTES[b]);
|
|
@@ -5258,6 +5336,27 @@ async function waitForPayment(api, sealId, ownerToken, opts) {
|
|
|
5258
5336
|
}
|
|
5259
5337
|
}
|
|
5260
5338
|
var TTL_OPTIONS = limits_default.limits.ttl_options;
|
|
5339
|
+
function maxOpensOf(text2) {
|
|
5340
|
+
const typed = text2.trim();
|
|
5341
|
+
if (typed === "") return void 0;
|
|
5342
|
+
const opens = /^\d+$/.test(typed) ? Number(typed) : Number.NaN;
|
|
5343
|
+
return opens >= 1 && opens <= limits_default.limits.MAX_OPENS_PER_SEAL_FREE ? opens : null;
|
|
5344
|
+
}
|
|
5345
|
+
var NO_COUNTRY = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
|
|
5346
|
+
var regions;
|
|
5347
|
+
function countryCodes(text2) {
|
|
5348
|
+
regions ?? (regions = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" }));
|
|
5349
|
+
const codes = [];
|
|
5350
|
+
const bad = [];
|
|
5351
|
+
for (const token of text2.split(/[\s,;]+/)) {
|
|
5352
|
+
if (token === "") continue;
|
|
5353
|
+
const typed = token.toUpperCase();
|
|
5354
|
+
const code = /^[A-Z]{2}$/.test(typed) ? Intl.getCanonicalLocales(`und-${typed}`)[0]?.split("-")[1] : void 0;
|
|
5355
|
+
if (!code || NO_COUNTRY.has(code) || !regions.of(code)) bad.push(token);
|
|
5356
|
+
else if (!codes.includes(code)) codes.push(code);
|
|
5357
|
+
}
|
|
5358
|
+
return { codes, bad };
|
|
5359
|
+
}
|
|
5261
5360
|
var SEAL_ID_LENGTH = 8;
|
|
5262
5361
|
var LINK_KEY_LENGTH = 43;
|
|
5263
5362
|
var SHARE_CODE_LENGTH = 4;
|
|
@@ -6177,9 +6276,9 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6177
6276
|
let shareKey = parsed.fragmentVariant === "key" ? base64urlToBytes(parsed.fragment) : wrapped !== null && seed2 ? await openLinkWrap(wrapped, seed2, sealId) : null;
|
|
6178
6277
|
if (shareKey !== null) await holdShareProof(sealId, shareKey);
|
|
6179
6278
|
const request = opts.signal ? { signal: opts.signal } : {};
|
|
6180
|
-
let
|
|
6279
|
+
let wire;
|
|
6181
6280
|
try {
|
|
6182
|
-
|
|
6281
|
+
wire = await api.getMetadata(parsed.sealId, { ...request, shareCode });
|
|
6183
6282
|
} catch (err) {
|
|
6184
6283
|
if (err instanceof BackendError && (err.code === "not_found" || err.code === "revoked")) {
|
|
6185
6284
|
throw new OpenError(
|
|
@@ -6190,6 +6289,7 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6190
6289
|
}
|
|
6191
6290
|
throw new OpenError("metadata_failed", `reading seal ${parsed.sealId} failed: ${messageOf(err)}`, err);
|
|
6192
6291
|
}
|
|
6292
|
+
const meta = toSealMetadata(wire);
|
|
6193
6293
|
if (meta.revokedAt !== null) throw new OpenError("seal_revoked", `seal ${parsed.sealId} has been revoked`);
|
|
6194
6294
|
if (meta.files.length === 0) {
|
|
6195
6295
|
throw new OpenError(
|
|
@@ -6222,10 +6322,14 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6222
6322
|
}
|
|
6223
6323
|
let fileKeys;
|
|
6224
6324
|
let bindings;
|
|
6325
|
+
let message;
|
|
6326
|
+
let ndaFile;
|
|
6225
6327
|
try {
|
|
6226
6328
|
const blob = await decryptShareBlob(blobBytes, shareKey);
|
|
6227
6329
|
fileKeys = blob.file_keys;
|
|
6228
6330
|
bindings = bindingsOf(blob);
|
|
6331
|
+
message = blob.message?.trim() ? blob.message : null;
|
|
6332
|
+
ndaFile = isNdaFileRef(blob.nda_file) ? blob.nda_file : null;
|
|
6229
6333
|
} catch (err) {
|
|
6230
6334
|
throw new OpenError(
|
|
6231
6335
|
"share_blob_decrypt_failed",
|
|
@@ -6236,11 +6340,19 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6236
6340
|
const files = await Promise.all(meta.files.map((f) => describeFile(f, fileKeys, bindings)));
|
|
6237
6341
|
return {
|
|
6238
6342
|
sealId,
|
|
6343
|
+
shareCode,
|
|
6239
6344
|
expiresAt: meta.expiresAt,
|
|
6240
6345
|
singleUse: meta.singleUse,
|
|
6241
6346
|
maxOpens: meta.maxOpens,
|
|
6242
6347
|
otpRequired: meta.otpRequired,
|
|
6243
6348
|
ndaRequired: meta.ndaRequired,
|
|
6349
|
+
otpPassed: wire.otp_session_valid === true,
|
|
6350
|
+
ndaPassed: wire.nda_session_valid === true,
|
|
6351
|
+
spent: wire.spent === true,
|
|
6352
|
+
countries: wire.geo_allowlist?.length ? wire.geo_allowlist : null,
|
|
6353
|
+
message,
|
|
6354
|
+
ndaFile,
|
|
6355
|
+
linkKey: shareKey,
|
|
6244
6356
|
files
|
|
6245
6357
|
};
|
|
6246
6358
|
}
|
|
@@ -6296,8 +6408,26 @@ async function readAnswerFile(api, url, mime, opts) {
|
|
|
6296
6408
|
if (!file?.key || !file.sha256Hex || more.length > 0 || bareMime(file.mime) !== mime || file.size > ANSWER_MAX_BYTES) {
|
|
6297
6409
|
throw new OpenError("share_blob_corrupt", `the answer is not one ${mime} file`);
|
|
6298
6410
|
}
|
|
6299
|
-
|
|
6300
|
-
|
|
6411
|
+
return readOpenedFile(api, { sealId: seal.sealId, shareCode: null }, file, {
|
|
6412
|
+
maxBytes: ANSWER_MAX_BYTES,
|
|
6413
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
6414
|
+
});
|
|
6415
|
+
}
|
|
6416
|
+
async function readOpenedFile(api, seal, file, opts) {
|
|
6417
|
+
if (!file.key || !file.sha256Hex || file.size > opts.maxBytes) {
|
|
6418
|
+
throw new OpenError("share_blob_corrupt", `file ${file.id} is not one of at most ${opts.maxBytes} bytes this link opens`);
|
|
6419
|
+
}
|
|
6420
|
+
const resp = await api.downloadCiphertext(
|
|
6421
|
+
seal.sealId,
|
|
6422
|
+
{
|
|
6423
|
+
fileId: file.id,
|
|
6424
|
+
...seal.shareCode ? { shareCode: seal.shareCode } : {},
|
|
6425
|
+
...opts.sessionCookie ? { sessionCookie: opts.sessionCookie } : {},
|
|
6426
|
+
...opts.visit ? { visit: opts.visit } : {}
|
|
6427
|
+
},
|
|
6428
|
+
opts.signal ? { signal: opts.signal } : {}
|
|
6429
|
+
);
|
|
6430
|
+
if (!resp.body) throw new OpenError("share_blob_corrupt", `file ${file.id} came without a body`);
|
|
6301
6431
|
const reader = decryptVerified(resp.body, file.key, file.sha256Hex).stream.getReader();
|
|
6302
6432
|
const chunks = [];
|
|
6303
6433
|
for (let part = await reader.read(); !part.done; part = await reader.read()) chunks.push(part.value);
|
|
@@ -6435,6 +6565,122 @@ var LEASE_MAX_DAYS = limits_default.limits.LEASE_MAX_DAYS;
|
|
|
6435
6565
|
var LEASE_POLL_SECONDS = limits_default.limits.LEASE_POLL_SECONDS;
|
|
6436
6566
|
var LEASE_STATUS_BATCH_MAX = limits_default.limits.LEASE_STATUS_BATCH_MAX;
|
|
6437
6567
|
|
|
6568
|
+
async function newKeys() {
|
|
6569
|
+
const token = generateOwnerToken();
|
|
6570
|
+
const linkKey = generateLinkKey();
|
|
6571
|
+
return {
|
|
6572
|
+
ownerTokenB64: bytesToBase64url(token),
|
|
6573
|
+
ownerTokenHash: await hashOwnerToken(token),
|
|
6574
|
+
linkKey,
|
|
6575
|
+
linkKeyB64: bytesToBase64url(linkKey)
|
|
6576
|
+
};
|
|
6577
|
+
}
|
|
6578
|
+
var DEFAULT_TTL = TTL_OPTIONS[TTL_OPTIONS.length - 1] ?? TTL_OPTIONS[0];
|
|
6579
|
+
var SECRET_ALONE = { ttl: "1h", singleUse: true };
|
|
6580
|
+
function createOptions(rules, keys, tier) {
|
|
6581
|
+
return {
|
|
6582
|
+
ttl: tier && rules.ttl !== "1d" && rules.ttl !== "7d" ? "1d" : rules.ttl,
|
|
6583
|
+
...tier ? { tier } : {},
|
|
6584
|
+
...rules.otp ? { otp: rules.otp } : {},
|
|
6585
|
+
nda: rules.nda ?? false,
|
|
6586
|
+
...rules.nda && rules.ownerEmail ? { ownerEmail: rules.ownerEmail } : {},
|
|
6587
|
+
singleUse: rules.singleUse ?? false,
|
|
6588
|
+
...!rules.singleUse && rules.maxOpens ? { maxOpens: rules.maxOpens } : {},
|
|
6589
|
+
...rules.geo && rules.geo.length > 0 ? { geo: rules.geo } : {},
|
|
6590
|
+
ownerTokenHash: keys.ownerTokenHash,
|
|
6591
|
+
ownerToken: keys.ownerTokenB64
|
|
6592
|
+
};
|
|
6593
|
+
}
|
|
6594
|
+
var PERSON_UPLOAD_POLICY = { ...DEFAULT_POLICY, transport: { maxStallMs: Infinity } };
|
|
6595
|
+
function createContext(baseUrl, options) {
|
|
6596
|
+
const { ttl, tier, otp, nda, ownerEmail, singleUse, maxOpens, geo, ownerTokenHash, ownerToken } = options;
|
|
6597
|
+
return {
|
|
6598
|
+
baseUrl,
|
|
6599
|
+
auth: { kind: "none" },
|
|
6600
|
+
ttl,
|
|
6601
|
+
...tier ? { tier } : {},
|
|
6602
|
+
...otp ? { otp } : {},
|
|
6603
|
+
...nda !== void 0 ? { nda } : {},
|
|
6604
|
+
...ownerEmail ? { ownerEmail } : {},
|
|
6605
|
+
...singleUse !== void 0 ? { singleUse } : {},
|
|
6606
|
+
...maxOpens ? { maxOpens } : {},
|
|
6607
|
+
...geo && geo.length > 0 ? { geo: [...geo] } : {},
|
|
6608
|
+
ownerTokenHash,
|
|
6609
|
+
ownerToken
|
|
6610
|
+
};
|
|
6611
|
+
}
|
|
6612
|
+
var OwnerBlobNotStored = class extends Error {
|
|
6613
|
+
};
|
|
6614
|
+
async function sealFiles(input) {
|
|
6615
|
+
const { keys, ndaFileName, api } = input;
|
|
6616
|
+
const message = input.message?.trim() ? input.message : void 0;
|
|
6617
|
+
const outcome = await input.upload(async (sealId, registered) => {
|
|
6618
|
+
input.registered?.(sealId);
|
|
6619
|
+
const { fileKeys: fileKeys2, ndaFile: ndaFile2 } = blobKeys(registered, ndaFileName);
|
|
6620
|
+
const ownerBlob = bytesToBase64url(await encryptOwnerBlob(keys.ownerTokenB64, fileKeys2, keys.linkKey, message, ndaFile2));
|
|
6621
|
+
await storeOwnerBlob(api, sealId, keys.ownerTokenB64, ownerBlob);
|
|
6622
|
+
await input.ownerBlobStored?.(sealId);
|
|
6623
|
+
});
|
|
6624
|
+
input.uploaded?.(outcome);
|
|
6625
|
+
const files = outcome.fileResults.map((file) => {
|
|
6626
|
+
const key = outcome.encryptionKeys.get(file.sha256_hex);
|
|
6627
|
+
if (!key) throw new Error(`the upload returned no key for the file ${file.fileId}`);
|
|
6628
|
+
return { sha256_hex: file.sha256_hex, key };
|
|
6629
|
+
});
|
|
6630
|
+
const { fileKeys, ndaFile } = blobKeys(files, ndaFileName);
|
|
6631
|
+
const shareKey = generateLinkKey();
|
|
6632
|
+
const share = {
|
|
6633
|
+
blobB64: bytesToBase64url(await encryptShareBlob(fileKeys, shareKey, message, ndaFile)),
|
|
6634
|
+
linkKeyB64: bytesToBase64url(shareKey)
|
|
6635
|
+
};
|
|
6636
|
+
input.minting?.(share);
|
|
6637
|
+
const { to } = input;
|
|
6638
|
+
if (to) {
|
|
6639
|
+
const fragment = await wrapTo(shareKey, to.bundle, SHARE_SCOPE, outcome.sealId);
|
|
6640
|
+
const label = to.label?.slice(0, 80);
|
|
6641
|
+
const mint = (sender2) => api.createShareLink(outcome.sealId, keys.ownerTokenB64, share.blobB64, shareKey, {
|
|
6642
|
+
to: to.address,
|
|
6643
|
+
fragment,
|
|
6644
|
+
...label ? { label } : {},
|
|
6645
|
+
...sender2 ? { sender: sender2 } : {}
|
|
6646
|
+
});
|
|
6647
|
+
const proof = async (fresh) => await to.sender?.(fresh).catch(() => null) ?? null;
|
|
6648
|
+
const proofRefused = (err) => err instanceof BackendError && err.appCode === "intake.proof_required";
|
|
6649
|
+
const sender = await proof(false);
|
|
6650
|
+
const shareCode2 = await mint(sender).catch(async (err) => {
|
|
6651
|
+
if (!sender || !proofRefused(err)) throw err;
|
|
6652
|
+
const fresh = await proof(true);
|
|
6653
|
+
if (!fresh) return mint(null);
|
|
6654
|
+
return mint(fresh).catch((again) => {
|
|
6655
|
+
if (proofRefused(again)) return mint(null);
|
|
6656
|
+
throw again;
|
|
6657
|
+
});
|
|
6658
|
+
});
|
|
6659
|
+
return { sealId: outcome.sealId, verification: outcome.verification, shareCode: shareCode2, share };
|
|
6660
|
+
}
|
|
6661
|
+
const shareCode = await api.createShareLink(outcome.sealId, keys.ownerTokenB64, share.blobB64, shareKey).catch(() => null);
|
|
6662
|
+
return { sealId: outcome.sealId, verification: outcome.verification, shareCode, share };
|
|
6663
|
+
}
|
|
6664
|
+
async function storeOwnerBlob(api, sealId, ownerToken, blob) {
|
|
6665
|
+
let failure = null;
|
|
6666
|
+
for (let tries = 0; tries < 2; tries++) {
|
|
6667
|
+
try {
|
|
6668
|
+
await api.writeOwnerBlob(sealId, ownerToken, blob);
|
|
6669
|
+
return;
|
|
6670
|
+
} catch (err) {
|
|
6671
|
+
failure = err;
|
|
6672
|
+
}
|
|
6673
|
+
}
|
|
6674
|
+
throw new OwnerBlobNotStored(failure instanceof Error ? failure.message : String(failure), { cause: failure });
|
|
6675
|
+
}
|
|
6676
|
+
function blobKeys(files, ndaFileName) {
|
|
6677
|
+
const last = files[files.length - 1];
|
|
6678
|
+
return {
|
|
6679
|
+
fileKeys: new Map(files.map((f) => [f.sha256_hex, bytesToBase64url(f.key)])),
|
|
6680
|
+
ndaFile: ndaFileName && last ? { sha256_hex: last.sha256_hex, name: ndaFileName } : void 0
|
|
6681
|
+
};
|
|
6682
|
+
}
|
|
6683
|
+
|
|
6438
6684
|
var limits_default2 = {
|
|
6439
6685
|
version: 1,
|
|
6440
6686
|
limits: {
|
|
@@ -6449,6 +6695,8 @@ var limits_default2 = {
|
|
|
6449
6695
|
MAX_FILE_KEYS: 1e4,
|
|
6450
6696
|
MAX_ACTIVE_UPLOADS_PER_SEAL: 10,
|
|
6451
6697
|
MAX_OPENS_PER_SEAL_FREE: 10,
|
|
6698
|
+
MAX_GEO_COUNTRIES: 50,
|
|
6699
|
+
SEAL_VISIT_SECONDS: 21600,
|
|
6452
6700
|
TIER_BYTES: {
|
|
6453
6701
|
free: 1073741824,
|
|
6454
6702
|
"5gb": 5368709120,
|
|
@@ -6514,6 +6762,24 @@ var limits_default2 = {
|
|
|
6514
6762
|
}
|
|
6515
6763
|
};
|
|
6516
6764
|
|
|
6765
|
+
var SIZE_UNITS = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"];
|
|
6766
|
+
var SIZE_LABELS = ["B", "KB", "MB", "GB", "TB"];
|
|
6767
|
+
function formatBytes(bytes, locale) {
|
|
6768
|
+
const k = 1024;
|
|
6769
|
+
let i = bytes > 0 ? Math.min(Math.floor(Math.log(bytes) / Math.log(k)), SIZE_UNITS.length - 1) : 0;
|
|
6770
|
+
let value = parseFloat((bytes / Math.pow(k, i)).toFixed(2));
|
|
6771
|
+
if (value >= k && i < SIZE_UNITS.length - 1) {
|
|
6772
|
+
i += 1;
|
|
6773
|
+
value = parseFloat((bytes / Math.pow(k, i)).toFixed(2));
|
|
6774
|
+
}
|
|
6775
|
+
if (!locale) return `${value} ${SIZE_LABELS[i]}`;
|
|
6776
|
+
return new Intl.NumberFormat(locale, { style: "unit", unit: SIZE_UNITS[i], unitDisplay: i === 0 ? "long" : "short", maximumFractionDigits: 2 }).format(value);
|
|
6777
|
+
}
|
|
6778
|
+
var SECOND = 1e3;
|
|
6779
|
+
var MINUTE = 60 * SECOND;
|
|
6780
|
+
var HOUR = 60 * MINUTE;
|
|
6781
|
+
var DAY = 24 * HOUR;
|
|
6782
|
+
|
|
6517
6783
|
// src/errors.ts
|
|
6518
6784
|
var SealError = class _SealError extends Error {
|
|
6519
6785
|
code;
|
|
@@ -6587,8 +6853,16 @@ function sealErrorFrom(err, fallbackMessage, details = null) {
|
|
|
6587
6853
|
);
|
|
6588
6854
|
}
|
|
6589
6855
|
|
|
6856
|
+
// src/folder.ts
|
|
6857
|
+
function pathParts(path) {
|
|
6858
|
+
return path.split("/").filter((part) => part !== "" && part !== "." && part !== "..");
|
|
6859
|
+
}
|
|
6860
|
+
|
|
6590
6861
|
// src/anonymous.ts
|
|
6591
|
-
var
|
|
6862
|
+
var LIMITS = limits_default2.limits;
|
|
6863
|
+
var TTL_OPTIONS2 = LIMITS.ttl_options;
|
|
6864
|
+
var SECRET_NAME = "Secret";
|
|
6865
|
+
var NDA_DEFAULT_TEXT = "Confidentiality Agreement";
|
|
6592
6866
|
var AnonymousSealsSendResource = class {
|
|
6593
6867
|
api;
|
|
6594
6868
|
baseUrl;
|
|
@@ -6621,14 +6895,15 @@ var AnonymousSealsSendResource = class {
|
|
|
6621
6895
|
});
|
|
6622
6896
|
}
|
|
6623
6897
|
/**
|
|
6624
|
-
* Create an anonymous encrypted seal.
|
|
6898
|
+
* Create an anonymous encrypted seal: files, a folder, a secret, as on seal.net.
|
|
6625
6899
|
*
|
|
6626
|
-
* Full E2EE flow:
|
|
6900
|
+
* Full E2EE flow, seal.net's own steps:
|
|
6627
6901
|
* 1. Generate the owner token client-side (the server sees only its hash)
|
|
6628
|
-
* 2. Register
|
|
6629
|
-
*
|
|
6630
|
-
* blob (owner token + file keys +
|
|
6631
|
-
*
|
|
6902
|
+
* 2. Register every file under the SHA-256 of its header (the rules ride
|
|
6903
|
+
* along, as seal.net reads and sends them); before the first byte, store
|
|
6904
|
+
* the encrypted owner blob (owner token + file keys + note) and the
|
|
6905
|
+
* owner's inbox copy
|
|
6906
|
+
* 3. Encrypt + upload the files' content
|
|
6632
6907
|
* 4. Mint a separate recipient share (share blob + share code), its key
|
|
6633
6908
|
* wrapped to the recipient's bundle when addressed
|
|
6634
6909
|
* 5. Return the recipient shareUrl and the owner ownerUrl
|
|
@@ -6638,10 +6913,11 @@ var AnonymousSealsSendResource = class {
|
|
|
6638
6913
|
* const anonymous = new AnonymousSealsSendResource()
|
|
6639
6914
|
*
|
|
6640
6915
|
* const result = await anonymous.create({
|
|
6641
|
-
* file:
|
|
6642
|
-
* filename: '
|
|
6643
|
-
*
|
|
6644
|
-
*
|
|
6916
|
+
* file: dumpBuffer,
|
|
6917
|
+
* filename: 'dump.sql',
|
|
6918
|
+
* secret: process.env.DB_PASSWORD, // from the environment: no key is written into code
|
|
6919
|
+
* ttl: '1d',
|
|
6920
|
+
* otp: process.env.SEAL_PASSWORD,
|
|
6645
6921
|
* singleUse: true,
|
|
6646
6922
|
* })
|
|
6647
6923
|
*
|
|
@@ -6650,12 +6926,17 @@ var AnonymousSealsSendResource = class {
|
|
|
6650
6926
|
* ```
|
|
6651
6927
|
*/
|
|
6652
6928
|
async create(options) {
|
|
6653
|
-
if (options.nda && !options.ownerEmail)
|
|
6654
|
-
|
|
6655
|
-
}
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6929
|
+
if (options.nda && !options.ownerEmail) refuse("ownerEmail is required when nda=true");
|
|
6930
|
+
if (options.tier && !options.onPaymentRequired) refuse("onPaymentRequired is required with tier");
|
|
6931
|
+
const { files, relativePaths, ndaDocument, secretAlone } = sealContents(options);
|
|
6932
|
+
const note = options.message?.trim() ? options.message : void 0;
|
|
6933
|
+
if (note && note.length > LIMITS.MAX_MESSAGE_LENGTH) {
|
|
6934
|
+
refuse(`message: ${note.length} characters, at most ${LIMITS.MAX_MESSAGE_LENGTH}`);
|
|
6935
|
+
}
|
|
6936
|
+
if (note && ndaDocument) refuse("message and ndaFile: the NDA is its text or its document, give one of them");
|
|
6937
|
+
const message = note ?? (ndaDocument ? `NDA document attached: ${ndaDocument.name} (${formatBytes(ndaDocument.size)})` : options.nda ? NDA_DEFAULT_TEXT : void 0);
|
|
6938
|
+
const rules = sealRules(options, secretAlone);
|
|
6939
|
+
if ("to" in options && !options.to) refuse("to: empty: an address holds a value");
|
|
6659
6940
|
const address = (field, value) => {
|
|
6660
6941
|
if (value === void 0) return void 0;
|
|
6661
6942
|
try {
|
|
@@ -6685,167 +6966,170 @@ var AnonymousSealsSendResource = class {
|
|
|
6685
6966
|
const ownerBundle = owner ? await bundleOf(owner).catch(() => null) : null;
|
|
6686
6967
|
const seed = options.keyPair ? base64urlToBytes(options.keyPair.secretKey) : null;
|
|
6687
6968
|
const proven = (call) => seed ? withAddressProof(this.api, seed, options.signal, call) : call();
|
|
6688
|
-
const
|
|
6689
|
-
let file;
|
|
6690
|
-
if (options.file instanceof File && options.file.name === options.filename && options.file.type === desiredType) {
|
|
6691
|
-
file = options.file;
|
|
6692
|
-
} else if (options.file instanceof Blob) {
|
|
6693
|
-
file = new File([options.file], options.filename, { type: desiredType });
|
|
6694
|
-
} else if (options.file instanceof Uint8Array) {
|
|
6695
|
-
const buffer = options.file.buffer.slice(
|
|
6696
|
-
options.file.byteOffset,
|
|
6697
|
-
options.file.byteOffset + options.file.byteLength
|
|
6698
|
-
);
|
|
6699
|
-
file = new File([buffer], options.filename, { type: desiredType });
|
|
6700
|
-
} else {
|
|
6701
|
-
file = new File([options.file], options.filename, { type: desiredType });
|
|
6702
|
-
}
|
|
6703
|
-
const ownerTokenBytes = generateOwnerToken();
|
|
6704
|
-
const ownerTokenB64 = bytesToBase64url(ownerTokenBytes);
|
|
6705
|
-
const ownerTokenHash = await hashOwnerToken(ownerTokenBytes);
|
|
6706
|
-
const linkKey = generateLinkKey();
|
|
6707
|
-
const linkKeyB64 = bytesToBase64url(linkKey);
|
|
6969
|
+
const keys = await newKeys();
|
|
6708
6970
|
const ctx = {
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
ttl: options.ttl,
|
|
6712
|
-
ownerTokenHash,
|
|
6713
|
-
ownerToken: ownerTokenB64,
|
|
6714
|
-
...this.credentials !== void 0 ? { credentials: this.credentials } : {},
|
|
6715
|
-
...options.otp !== void 0 ? { otp: options.otp } : {},
|
|
6716
|
-
...options.nda !== void 0 ? { nda: options.nda } : {},
|
|
6717
|
-
...options.nda && options.ownerEmail !== void 0 ? { ownerEmail: options.ownerEmail } : {},
|
|
6718
|
-
...options.singleUse !== void 0 ? { singleUse: options.singleUse } : {},
|
|
6719
|
-
...options.geoAllowlist !== void 0 ? { geo: options.geoAllowlist } : {},
|
|
6720
|
-
...options.maxOpens !== void 0 ? { maxOpens: options.maxOpens } : {},
|
|
6721
|
-
...options.tier !== void 0 ? { tier: options.tier } : {}
|
|
6971
|
+
...createContext(this.baseUrl, createOptions(rules, keys, options.tier)),
|
|
6972
|
+
...this.credentials !== void 0 ? { credentials: this.credentials } : {}
|
|
6722
6973
|
};
|
|
6723
6974
|
let createdSealId = null;
|
|
6724
6975
|
const recovery = (sealId) => ({
|
|
6725
6976
|
sealId,
|
|
6726
|
-
ownerToken: ownerTokenB64,
|
|
6727
|
-
ownerLinkKey: linkKeyB64
|
|
6977
|
+
ownerToken: keys.ownerTokenB64,
|
|
6978
|
+
ownerLinkKey: keys.linkKeyB64
|
|
6728
6979
|
});
|
|
6729
|
-
const blobMessage = options.message?.trim() ? options.message : void 0;
|
|
6730
6980
|
let ownerCopy = false;
|
|
6981
|
+
let ownerCopyRefused = false;
|
|
6982
|
+
let sent = null;
|
|
6983
|
+
const onProgress = options.onProgress;
|
|
6731
6984
|
try {
|
|
6732
|
-
const
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
//
|
|
6737
|
-
//
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6985
|
+
const sealed = await sealFiles({
|
|
6986
|
+
keys,
|
|
6987
|
+
ndaFileName: ndaDocument?.name ?? null,
|
|
6988
|
+
message,
|
|
6989
|
+
// seal.net's calls with this send's signal. The owner copy rides the first write of the owner blob, one
|
|
6990
|
+
// request; a refused address part is the same write without it.
|
|
6991
|
+
api: {
|
|
6992
|
+
writeOwnerBlob: async (id, token, blob) => {
|
|
6993
|
+
if (owner && ownerBundle && !ownerCopyRefused) {
|
|
6994
|
+
const fragment = await wrapTo(keys.linkKey, ownerBundle, OWNER_SCOPE, id);
|
|
6995
|
+
const copied = await proven(
|
|
6996
|
+
(sender) => this.api.writeOwnerBlob(id, token, blob, {
|
|
6997
|
+
...signalOpt,
|
|
6998
|
+
to: owner,
|
|
6999
|
+
fragment,
|
|
7000
|
+
label: "sealnet",
|
|
7001
|
+
...sender ? { sender } : {}
|
|
7002
|
+
})
|
|
7003
|
+
).catch(() => null);
|
|
7004
|
+
if (copied) {
|
|
7005
|
+
ownerCopy = true;
|
|
7006
|
+
return copied;
|
|
7007
|
+
}
|
|
7008
|
+
ownerCopyRefused = true;
|
|
7009
|
+
}
|
|
7010
|
+
return this.api.writeOwnerBlob(id, token, blob, signalOpt);
|
|
7011
|
+
},
|
|
7012
|
+
createShareLink: (id, token, blob, linkKey, opts = {}) => this.api.createShareLink(id, token, blob, linkKey, { ...opts, ...signalOpt })
|
|
7013
|
+
},
|
|
7014
|
+
registered: (id) => {
|
|
6741
7015
|
createdSealId = id;
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
(
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
7016
|
+
},
|
|
7017
|
+
upload: async (onRegistered) => {
|
|
7018
|
+
const callbacks = {
|
|
7019
|
+
onRegistered,
|
|
7020
|
+
...onProgress ? {
|
|
7021
|
+
onProgress: (p) => onProgress({
|
|
7022
|
+
phase: p.fileProgress.phase,
|
|
7023
|
+
percent: p.overallPercent,
|
|
7024
|
+
fileIndex: p.fileIndex,
|
|
7025
|
+
totalFiles: p.totalFiles,
|
|
7026
|
+
fileName: p.fileName
|
|
6753
7027
|
})
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
7028
|
+
} : {},
|
|
7029
|
+
...signalOpt
|
|
7030
|
+
};
|
|
7031
|
+
let result2;
|
|
7032
|
+
let expiresAt2;
|
|
6759
7033
|
try {
|
|
6760
|
-
|
|
7034
|
+
result2 = relativePaths ? await uploadFolderAsFiles(ctx, files, "", DEFAULT_POLICY, callbacks, relativePaths) : await uploadMultipleFiles(ctx, files, DEFAULT_POLICY, callbacks);
|
|
7035
|
+
expiresAt2 = result2.expiresAt;
|
|
6761
7036
|
} catch (err) {
|
|
6762
|
-
|
|
7037
|
+
const session = paymentRequiredSession(err);
|
|
7038
|
+
if (!session || !options.tier || !options.onPaymentRequired) throw err;
|
|
7039
|
+
await options.onPaymentRequired(
|
|
7040
|
+
await this.api.createCheckout(session.sealId, keys.ownerTokenB64, options.tier, signalOpt)
|
|
7041
|
+
);
|
|
7042
|
+
const deadline = paymentDeadline(session instanceof UploadSession ? session.expiresAt : void 0);
|
|
7043
|
+
const paid = await waitForPayment(this.api, session.sealId, keys.ownerTokenB64, { deadline, ...signalOpt });
|
|
7044
|
+
if (!paid) {
|
|
7045
|
+
await this.api.revoke(session.sealId, keys.ownerTokenB64).catch(() => void 0);
|
|
7046
|
+
throw new SealError(
|
|
7047
|
+
"The seal was not paid in time and was revoked",
|
|
7048
|
+
"PAYMENT_REQUIRED",
|
|
7049
|
+
402,
|
|
7050
|
+
recovery(session.sealId)
|
|
7051
|
+
);
|
|
7052
|
+
}
|
|
7053
|
+
result2 = await session.resume(callbacks);
|
|
7054
|
+
expiresAt2 = paid.expires_at;
|
|
6763
7055
|
}
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
7056
|
+
if (!expiresAt2) {
|
|
7057
|
+
throw new SealError(`Seal ${result2.sealId}: the server sent no expiry`, "INTERNAL_ERROR", 500, recovery(result2.sealId));
|
|
7058
|
+
}
|
|
7059
|
+
sent = { result: result2, expiresAt: expiresAt2 };
|
|
7060
|
+
return {
|
|
7061
|
+
sealId: result2.sealId,
|
|
7062
|
+
encryptionKeys: result2.encryptionKeys,
|
|
7063
|
+
fileResults: result2.files,
|
|
7064
|
+
verification: result2.verification
|
|
7065
|
+
};
|
|
7066
|
+
},
|
|
7067
|
+
// Addressed: the link's key wrapped to the recipient's bundle rides the mint into their inbox, the sender
|
|
7068
|
+
// proven at the mint when there is a seed, by a fresh proof when the server refused the first.
|
|
7069
|
+
...recipient && recipientBundle ? {
|
|
7070
|
+
to: {
|
|
7071
|
+
address: recipient,
|
|
7072
|
+
bundle: recipientBundle,
|
|
7073
|
+
label: "sealnet",
|
|
7074
|
+
...seed ? { sender: (fresh) => addressProof(this.api, seed, { ...signalOpt, fresh }) } : {}
|
|
7075
|
+
}
|
|
7076
|
+
} : {}
|
|
7077
|
+
});
|
|
7078
|
+
const { result, expiresAt } = sent;
|
|
7079
|
+
let shareCode = sealed.shareCode;
|
|
7080
|
+
if (shareCode === null) {
|
|
7081
|
+
try {
|
|
7082
|
+
shareCode = await this.api.createShareLink(
|
|
7083
|
+
sealed.sealId,
|
|
7084
|
+
keys.ownerTokenB64,
|
|
7085
|
+
sealed.share.blobB64,
|
|
7086
|
+
base64urlToBytes(sealed.share.linkKeyB64),
|
|
7087
|
+
signalOpt
|
|
6787
7088
|
);
|
|
7089
|
+
} catch (err) {
|
|
7090
|
+
throw sealErrorFrom(err, "Seal created but share link mint failed", recovery(sealed.sealId));
|
|
6788
7091
|
}
|
|
6789
|
-
result = await session.resume(callbacks);
|
|
6790
|
-
expiresAt = paid.expires_at;
|
|
6791
7092
|
}
|
|
6792
|
-
|
|
6793
|
-
|
|
7093
|
+
const sharePath = buildShareUrl(sealed.sealId, shareCode, sealed.share.linkKeyB64);
|
|
7094
|
+
const shareUrl = `${this.shareUrlBase}${recipient ? sharePath.split("#")[0] : sharePath}`;
|
|
7095
|
+
const ownerUrl = `${this.shareUrlBase}${buildOwnerUrl(sealed.sealId, keys.linkKeyB64)}`;
|
|
7096
|
+
const [first] = result.files;
|
|
7097
|
+
const firstKey = first && result.encryptionKeys.get(first.sha256_hex);
|
|
7098
|
+
if (!first || !firstKey) {
|
|
7099
|
+
throw new SealError(`Seal ${sealed.sealId}: the upload returned no key for its first file`, "INTERNAL_ERROR", 500, recovery(sealed.sealId));
|
|
6794
7100
|
}
|
|
6795
|
-
const
|
|
6796
|
-
fileKeysB64.set(result.sha256_hex, bytesToBase64url(result.encryptionKey));
|
|
6797
|
-
const shareLinkKey = generateLinkKey();
|
|
6798
|
-
const shareLinkKeyB64 = bytesToBase64url(shareLinkKey);
|
|
6799
|
-
const shareBlob = await encryptShareBlob(fileKeysB64, shareLinkKey, blobMessage);
|
|
6800
|
-
const fragment = recipient && recipientBundle ? await wrapTo(shareLinkKey, recipientBundle, SHARE_SCOPE, result.sealId) : null;
|
|
6801
|
-
let shareCode;
|
|
6802
|
-
try {
|
|
6803
|
-
const shareBlobB64 = bytesToBase64url(shareBlob);
|
|
6804
|
-
shareCode = recipient && fragment ? await proven(
|
|
6805
|
-
(sender) => this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, shareLinkKey, {
|
|
6806
|
-
...signalOpt,
|
|
6807
|
-
to: recipient,
|
|
6808
|
-
fragment,
|
|
6809
|
-
label: "sealnet",
|
|
6810
|
-
...sender ? { sender } : {}
|
|
6811
|
-
})
|
|
6812
|
-
) : await this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, shareLinkKey, signalOpt);
|
|
6813
|
-
} catch (err) {
|
|
6814
|
-
throw sealErrorFrom(
|
|
6815
|
-
err,
|
|
6816
|
-
"Seal created but share link mint failed",
|
|
6817
|
-
recovery(result.sealId)
|
|
6818
|
-
);
|
|
6819
|
-
}
|
|
6820
|
-
const sharePath = buildShareUrl(result.sealId, shareCode, shareLinkKeyB64);
|
|
6821
|
-
const shareUrl = `${this.shareUrlBase}${fragment ? sharePath.split("#")[0] : sharePath}`;
|
|
6822
|
-
const ownerUrl = `${this.shareUrlBase}${buildOwnerUrl(result.sealId, linkKeyB64)}`;
|
|
6823
|
-
const keyBase64 = bytesToBase64(result.encryptionKey);
|
|
7101
|
+
const names = relativePaths ?? files.map((f) => f.name);
|
|
6824
7102
|
return {
|
|
6825
|
-
sealId:
|
|
7103
|
+
sealId: sealed.sealId,
|
|
6826
7104
|
shareUrl,
|
|
6827
7105
|
ownerUrl,
|
|
6828
|
-
ownerToken: ownerTokenB64,
|
|
7106
|
+
ownerToken: keys.ownerTokenB64,
|
|
6829
7107
|
// For revoke
|
|
6830
7108
|
expiresAt,
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
7109
|
+
// Standard base64 (not base64url): this is what the SDK has always
|
|
7110
|
+
// returned, and `importKey` accepts either alphabet. The encoder is
|
|
7111
|
+
// the kernel's — chunked, and the only one left in the repository.
|
|
7112
|
+
encryptionKey: bytesToBase64(firstKey),
|
|
7113
|
+
fileId: first.fileId,
|
|
7114
|
+
files: result.files.map((f, i) => ({ fileId: f.fileId, name: names[i] })),
|
|
7115
|
+
delivered: recipient !== void 0,
|
|
6834
7116
|
ownerCopy
|
|
6835
7117
|
};
|
|
6836
7118
|
} catch (err) {
|
|
6837
7119
|
if (err instanceof SealError) throw err;
|
|
6838
|
-
if (createdSealId)
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
"INTERNAL_ERROR",
|
|
6843
|
-
500,
|
|
6844
|
-
recovery(createdSealId),
|
|
6845
|
-
{ cause: err }
|
|
6846
|
-
);
|
|
7120
|
+
if (!createdSealId) throw err;
|
|
7121
|
+
const cause = err instanceof OwnerBlobNotStored ? err.cause : err;
|
|
7122
|
+
if (cause instanceof BackendError) {
|
|
7123
|
+
throw sealErrorFrom(cause, `Seal ${createdSealId} was created but its send did not finish`, recovery(createdSealId));
|
|
6847
7124
|
}
|
|
6848
|
-
|
|
7125
|
+
const said = cause instanceof Error ? cause.message : String(cause);
|
|
7126
|
+
throw new SealError(
|
|
7127
|
+
`Seal ${createdSealId} was created but the create flow was interrupted: ${said}`,
|
|
7128
|
+
"INTERNAL_ERROR",
|
|
7129
|
+
500,
|
|
7130
|
+
recovery(createdSealId),
|
|
7131
|
+
{ cause: err }
|
|
7132
|
+
);
|
|
6849
7133
|
}
|
|
6850
7134
|
}
|
|
6851
7135
|
/**
|
|
@@ -6862,6 +7146,80 @@ var AnonymousSealsSendResource = class {
|
|
|
6862
7146
|
}
|
|
6863
7147
|
}
|
|
6864
7148
|
};
|
|
7149
|
+
function sealRules(options, secretAlone) {
|
|
7150
|
+
if ("otp" in options && !options.otp) refuse("otp: empty: a password holds a value");
|
|
7151
|
+
const maxOpens = options.maxOpens === void 0 ? void 0 : maxOpensOf(String(options.maxOpens));
|
|
7152
|
+
if (maxOpens === null) {
|
|
7153
|
+
refuse(`maxOpens: ${options.maxOpens}: a whole number from 1 to ${LIMITS.MAX_OPENS_PER_SEAL_FREE}`);
|
|
7154
|
+
}
|
|
7155
|
+
const countries = countryCodes((options.geoAllowlist ?? []).join(" "));
|
|
7156
|
+
if (countries.bad.length > 0) {
|
|
7157
|
+
refuse(`geoAllowlist: ${countries.bad.join(", ")}: two-letter country codes such as DE, CH, US`);
|
|
7158
|
+
}
|
|
7159
|
+
if (countries.codes.length > LIMITS.MAX_GEO_COUNTRIES) {
|
|
7160
|
+
refuse(`geoAllowlist: ${countries.codes.length} countries, at most ${LIMITS.MAX_GEO_COUNTRIES}`);
|
|
7161
|
+
}
|
|
7162
|
+
return {
|
|
7163
|
+
ttl: options.ttl ?? (secretAlone ? SECRET_ALONE.ttl : DEFAULT_TTL),
|
|
7164
|
+
otp: options.otp,
|
|
7165
|
+
nda: options.nda,
|
|
7166
|
+
ownerEmail: options.ownerEmail,
|
|
7167
|
+
singleUse: options.singleUse ?? (secretAlone && maxOpens === void 0 ? SECRET_ALONE.singleUse : void 0),
|
|
7168
|
+
maxOpens,
|
|
7169
|
+
geo: countries.codes
|
|
7170
|
+
};
|
|
7171
|
+
}
|
|
7172
|
+
function sealContents(options) {
|
|
7173
|
+
const named = (where, source2, filename) => filename || (source2 instanceof File ? source2.name : "") || refuse(`${where}: bytes need a filename`);
|
|
7174
|
+
const entries = [];
|
|
7175
|
+
if ("secret" in options) {
|
|
7176
|
+
if (options.secret === void 0 || options.secret.length === 0) refuse("secret: empty: a secret holds a value");
|
|
7177
|
+
const value = typeof options.secret === "string" ? new Blob([options.secret]) : options.secret;
|
|
7178
|
+
entries.push({ file: asFile(value, SECRET_NAME, SECRET_MIME), secret: true });
|
|
7179
|
+
}
|
|
7180
|
+
if (options.file !== void 0) {
|
|
7181
|
+
entries.push({ file: asFile(options.file, named("file", options.file, options.filename), options.mimeType), secret: false });
|
|
7182
|
+
}
|
|
7183
|
+
for (const [i, f] of (options.files ?? []).entries()) {
|
|
7184
|
+
const file = asFile(f.file, named(`files[${i}]`, f.file, f.filename), f.secret ? SECRET_MIME : f.mimeType);
|
|
7185
|
+
if (f.secret && file.size === 0) refuse(`files[${i}]: an empty secret`);
|
|
7186
|
+
entries.push({ file, secret: f.secret === true });
|
|
7187
|
+
}
|
|
7188
|
+
for (const [i, f] of (options.folder ?? []).entries()) {
|
|
7189
|
+
const parts = pathParts(f instanceof File ? folderPathOf(f) ?? f.name : f.path);
|
|
7190
|
+
const name2 = parts.at(-1);
|
|
7191
|
+
if (!name2) refuse(`folder[${i}]: a file with no path`);
|
|
7192
|
+
const path = parts.join("/");
|
|
7193
|
+
entries.push(f instanceof File ? { file: f, path, secret: false } : { file: asFile(f.file, name2, f.mimeType), path, secret: false });
|
|
7194
|
+
}
|
|
7195
|
+
let ndaDocument = null;
|
|
7196
|
+
if (options.ndaFile !== void 0) {
|
|
7197
|
+
if (!options.nda) refuse("ndaFile goes with nda: true");
|
|
7198
|
+
const { file, filename, mimeType } = options.ndaFile;
|
|
7199
|
+
ndaDocument = asFile(file, named("ndaFile", file, filename), mimeType);
|
|
7200
|
+
entries.push({ file: ndaDocument, secret: false });
|
|
7201
|
+
}
|
|
7202
|
+
if (entries.length === 0) refuse("Nothing to seal: give file, files, folder or secret");
|
|
7203
|
+
if (entries.length > LIMITS.MAX_FILES_PER_SEAL) {
|
|
7204
|
+
refuse(`A seal holds at most ${LIMITS.MAX_FILES_PER_SEAL} files: ${entries.length} given`);
|
|
7205
|
+
}
|
|
7206
|
+
return {
|
|
7207
|
+
files: entries.map((e) => e.file),
|
|
7208
|
+
relativePaths: entries.some((e) => e.path !== void 0) ? entries.map((e) => e.path ?? e.file.name) : void 0,
|
|
7209
|
+
ndaDocument,
|
|
7210
|
+
secretAlone: entries.length === 1 && entries[0].secret
|
|
7211
|
+
};
|
|
7212
|
+
}
|
|
7213
|
+
function refuse(said) {
|
|
7214
|
+
throw new SealError(said, "VALIDATION_ERROR", 400);
|
|
7215
|
+
}
|
|
7216
|
+
function asFile(source2, name2, type) {
|
|
7217
|
+
const mime = type || source2 instanceof File && source2.type || "application/octet-stream";
|
|
7218
|
+
if (source2 instanceof File && source2.name === name2 && source2.type === mime) return source2;
|
|
7219
|
+
if (source2 instanceof Blob) return new File([source2], name2, { type: mime });
|
|
7220
|
+
const bytes = source2 instanceof Uint8Array ? source2.buffer.slice(source2.byteOffset, source2.byteOffset + source2.byteLength) : source2;
|
|
7221
|
+
return new File([bytes], name2, { type: mime });
|
|
7222
|
+
}
|
|
6865
7223
|
|
|
6866
7224
|
async function receiveToDisk(opened, dir, name2) {
|
|
6867
7225
|
const fs = await import(
|
|
@@ -6943,12 +7301,22 @@ async function resolve(api, url, opts, wrap) {
|
|
|
6943
7301
|
const covered = seal.files.filter((f) => f.key !== null && f.sha256Hex !== null);
|
|
6944
7302
|
const total = covered.reduce((sum, f) => sum + f.size, 0);
|
|
6945
7303
|
let done = 0;
|
|
7304
|
+
const visit = newVisit();
|
|
7305
|
+
let visitOpen = false;
|
|
7306
|
+
let turns = Promise.resolve();
|
|
7307
|
+
const download = (file) => api.downloadCiphertext(seal.sealId, { fileId: file.id, visit, ...sessionCookie ? { sessionCookie } : {} }, request);
|
|
7308
|
+
const answered = (file) => {
|
|
7309
|
+
if (visitOpen) return download(file);
|
|
7310
|
+
const turn = turns.then(async () => {
|
|
7311
|
+
const resp = await download(file);
|
|
7312
|
+
visitOpen = true;
|
|
7313
|
+
return resp;
|
|
7314
|
+
});
|
|
7315
|
+
turns = turn.catch(() => void 0);
|
|
7316
|
+
return turn;
|
|
7317
|
+
};
|
|
6946
7318
|
const read = async (file) => {
|
|
6947
|
-
const resp = await
|
|
6948
|
-
seal.sealId,
|
|
6949
|
-
{ fileId: file.id, ...sessionCookie ? { sessionCookie } : {} },
|
|
6950
|
-
request
|
|
6951
|
-
);
|
|
7319
|
+
const resp = await answered(file);
|
|
6952
7320
|
if (!resp.body) throw new SealError(`Download of ${file.name} returned no body`, "INTERNAL_ERROR", resp.status);
|
|
6953
7321
|
return decryptVerified(resp.body, file.key, file.sha256Hex, (bytes) => {
|
|
6954
7322
|
done += bytes;
|
|
@@ -6980,7 +7348,10 @@ async function saveLink(api, url, dir, opts = {}, wrap = null) {
|
|
|
6980
7348
|
const { seal, covered, read } = await resolve(api, url, opts, wrap);
|
|
6981
7349
|
const files = [];
|
|
6982
7350
|
for (const file of covered) {
|
|
6983
|
-
const
|
|
7351
|
+
const parts = pathParts(file.name).map((part) => sanitizeFilename(part));
|
|
7352
|
+
const name2 = parts.pop() ?? sanitizeFilename(file.name);
|
|
7353
|
+
const into = parts.length > 0 ? [dir || ".", ...parts].join("/") : dir;
|
|
7354
|
+
const saved = await receiveToDisk(await read(file), into, name2);
|
|
6984
7355
|
files.push({ name: file.name, mime: file.mime, secret: file.secret, ...saved });
|
|
6985
7356
|
}
|
|
6986
7357
|
return { sealId: seal.sealId, expiresAt: seal.expiresAt, files };
|
|
@@ -7106,7 +7477,7 @@ async function dismissItem(api, item, opts) {
|
|
|
7106
7477
|
}
|
|
7107
7478
|
|
|
7108
7479
|
// src/index.ts
|
|
7109
|
-
var [CLIENT_NAME = "", CLIENT_VERSION = ""] = "sealnet-js/3.
|
|
7480
|
+
var [CLIENT_NAME = "", CLIENT_VERSION = ""] = "sealnet-js/3.1.0".split("/");
|
|
7110
7481
|
if (typeof globalThis.process?.versions?.node !== "string") {
|
|
7111
7482
|
configureWasm(define_SEAL_WASM_default);
|
|
7112
7483
|
}
|
|
@@ -7122,8 +7493,10 @@ var SealClient = class {
|
|
|
7122
7493
|
this.api = new SealApi({ baseUrl: apiUrl, credentials: "omit" });
|
|
7123
7494
|
}
|
|
7124
7495
|
/**
|
|
7125
|
-
* Encrypt
|
|
7126
|
-
*
|
|
7496
|
+
* Encrypt files client-side — one or several, a folder file by file under
|
|
7497
|
+
* its paths, a secret the recipient's page shows hidden — into one seal,
|
|
7498
|
+
* upload the ciphertext, and return the recipient share link plus the
|
|
7499
|
+
* owner management material. The rules go as seal.net reads and sends them.
|
|
7127
7500
|
*
|
|
7128
7501
|
* `filename` and `mimeType` are what the RECIPIENT sees — they override
|
|
7129
7502
|
* the name and type of a `File` you pass in.
|