sealnet 3.0.0 → 3.1.1
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 +4 -4
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/dist/index.cjs +634 -261
- package/dist/index.d.cts +103 -35
- package/dist/index.d.ts +103 -35
- 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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// <define:__SEAL_WASM__>
|
|
2
|
-
var define_SEAL_WASM_default = { url: "https://seal.net/sdk/v3.
|
|
2
|
+
var define_SEAL_WASM_default = { url: "https://seal.net/sdk/v3.1.1/seal_crypto.wasm", integrity: "sha384-cxLyz7pU4Ov7nYYJ5cqyhupM04QkkuB7UI3Fvl8FkXp8uWcm8PvGYSYu0PFl4J0O" };
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
@@ -19,7 +19,6 @@ __export(glue_module_generated_exports, {
|
|
|
19
19
|
wasm_contract_message: () => wasm_contract_message,
|
|
20
20
|
wasm_contract_message_v2: () => wasm_contract_message_v2,
|
|
21
21
|
wasm_ed25519_verify: () => wasm_ed25519_verify,
|
|
22
|
-
wasm_sealbox_unwrap: () => wasm_sealbox_unwrap,
|
|
23
22
|
wasm_sealbox_wrap: () => wasm_sealbox_wrap,
|
|
24
23
|
wasm_summary_message: () => wasm_summary_message,
|
|
25
24
|
wasm_unwrap_file_key: () => wasm_unwrap_file_key,
|
|
@@ -237,27 +236,6 @@ var WasmIdentity = class _WasmIdentity {
|
|
|
237
236
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
238
237
|
}
|
|
239
238
|
}
|
|
240
|
-
/**
|
|
241
|
-
* The X25519 address before C1 (base64url) — the migration (Р18), until
|
|
242
|
-
* the removal.
|
|
243
|
-
* @returns {string}
|
|
244
|
-
*/
|
|
245
|
-
legacyAddress() {
|
|
246
|
-
let deferred1_0;
|
|
247
|
-
let deferred1_1;
|
|
248
|
-
try {
|
|
249
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
250
|
-
wasm.wasmidentity_legacyAddress(retptr, this.__wbg_ptr);
|
|
251
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
252
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
253
|
-
deferred1_0 = r0;
|
|
254
|
-
deferred1_1 = r1;
|
|
255
|
-
return getStringFromWasm0(r0, r1);
|
|
256
|
-
} finally {
|
|
257
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
258
|
-
wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
239
|
/**
|
|
262
240
|
* The key a packed box carries for this identity.
|
|
263
241
|
* @param {Uint8Array} packed_box
|
|
@@ -608,29 +586,6 @@ function wasm_ed25519_verify(public_key, message, signature) {
|
|
|
608
586
|
const ret = wasm.wasm_ed25519_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
609
587
|
return ret !== 0;
|
|
610
588
|
}
|
|
611
|
-
function wasm_sealbox_unwrap(packed_grant, recipient_secret, scope_type, scope_id) {
|
|
612
|
-
try {
|
|
613
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
614
|
-
const ptr0 = passArray8ToWasm0(packed_grant, wasm.__wbindgen_export3);
|
|
615
|
-
const len0 = WASM_VECTOR_LEN;
|
|
616
|
-
const ptr1 = passArray8ToWasm0(recipient_secret, wasm.__wbindgen_export3);
|
|
617
|
-
const len1 = WASM_VECTOR_LEN;
|
|
618
|
-
const ptr2 = passStringToWasm0(scope_type, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
619
|
-
const len2 = WASM_VECTOR_LEN;
|
|
620
|
-
const ptr3 = passStringToWasm0(scope_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
621
|
-
const len3 = WASM_VECTOR_LEN;
|
|
622
|
-
wasm.wasm_sealbox_unwrap(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
623
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
624
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
625
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
626
|
-
if (r2) {
|
|
627
|
-
throw takeObject(r1);
|
|
628
|
-
}
|
|
629
|
-
return takeObject(r0);
|
|
630
|
-
} finally {
|
|
631
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
589
|
function wasm_sealbox_wrap(key_to_wrap, packed_bundle, scope_type, scope_id) {
|
|
635
590
|
try {
|
|
636
591
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
@@ -1391,6 +1346,8 @@ var limits_default = {
|
|
|
1391
1346
|
MAX_FILE_KEYS: 1e4,
|
|
1392
1347
|
MAX_ACTIVE_UPLOADS_PER_SEAL: 10,
|
|
1393
1348
|
MAX_OPENS_PER_SEAL_FREE: 10,
|
|
1349
|
+
MAX_GEO_COUNTRIES: 50,
|
|
1350
|
+
SEAL_VISIT_SECONDS: 21600,
|
|
1394
1351
|
TIER_BYTES: {
|
|
1395
1352
|
free: 1073741824,
|
|
1396
1353
|
"5gb": 5368709120,
|
|
@@ -1482,7 +1439,6 @@ var crypto_default = {
|
|
|
1482
1439
|
}
|
|
1483
1440
|
},
|
|
1484
1441
|
hkdf: {
|
|
1485
|
-
wrap_key_salt: "seal:wrapkey:v1",
|
|
1486
1442
|
wrap_key_salt_v2: "seal:wrapkey:v2",
|
|
1487
1443
|
identity_key_salt: "seal:key-derivation:v1",
|
|
1488
1444
|
file_envelope_salt: "seal:file-envelope:v1",
|
|
@@ -1515,7 +1471,7 @@ var crypto_default = {
|
|
|
1515
1471
|
},
|
|
1516
1472
|
secret_scope_aad: "secret:{secret_id}",
|
|
1517
1473
|
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
|
|
1474
|
+
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.",
|
|
1519
1475
|
room: "room:{room_id}:{field}",
|
|
1520
1476
|
org_object: {
|
|
1521
1477
|
bound: "{kind}:{org_id}:{object_id}:{field}",
|
|
@@ -1530,12 +1486,17 @@ var crypto_default = {
|
|
|
1530
1486
|
"sign-request-meta",
|
|
1531
1487
|
"sign-field-value"
|
|
1532
1488
|
],
|
|
1489
|
+
before_read: [
|
|
1490
|
+
"sign-request-meta",
|
|
1491
|
+
"sign-field-value"
|
|
1492
|
+
],
|
|
1533
1493
|
field: "name",
|
|
1534
1494
|
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
1495
|
},
|
|
1536
1496
|
folder: {
|
|
1537
1497
|
bound: "seal:{seal_id}:{folder_id}:name",
|
|
1538
|
-
before: "seal:{seal_id}:name"
|
|
1498
|
+
before: "seal:{seal_id}:name",
|
|
1499
|
+
before_read: false
|
|
1539
1500
|
},
|
|
1540
1501
|
versions: {
|
|
1541
1502
|
before: 3,
|
|
@@ -1556,6 +1517,14 @@ var crypto_default = {
|
|
|
1556
1517
|
before_aad: "secret:0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e:name",
|
|
1557
1518
|
before_b64: "OGmxAlSNNBiKlnxW4fkbPMjFoZGJJDY="
|
|
1558
1519
|
},
|
|
1520
|
+
org_object_signed: {
|
|
1521
|
+
kind: "sign-request-meta",
|
|
1522
|
+
org_id: "0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e",
|
|
1523
|
+
object_id: "5c2e8f71-3a94-4d0b-b6e1-0f7a9c2d4e85",
|
|
1524
|
+
text: "NDA Acme 2026",
|
|
1525
|
+
before_aad: "sign-request-meta:0b9f4c1e-6f0a-4c56-9d0e-2f1c3a4b5d6e:name",
|
|
1526
|
+
before_b64: "Bl+fRjiKO/seUG/a7Ln0rJ0phFB+8MGpdfuM+fI="
|
|
1527
|
+
},
|
|
1559
1528
|
folder: {
|
|
1560
1529
|
seal_id: "AbCd1234",
|
|
1561
1530
|
folder_id: "c0ffee00-1234-4abc-8def-0123456789ab",
|
|
@@ -1760,29 +1729,12 @@ var seal_address_default = {
|
|
|
1760
1729
|
owner_copy: "box.ownerCopy {sealId, ownerToken, linkKey} -> {ok: boolean}",
|
|
1761
1730
|
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)"
|
|
1762
1731
|
},
|
|
1763
|
-
migrate: {
|
|
1764
|
-
until: "C1 + 7 days (C1 \xA76)",
|
|
1765
|
-
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.",
|
|
1766
|
-
old_address: "the X25519 public key of the seed, base64url without padding, 43 characters",
|
|
1767
|
-
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",
|
|
1768
|
-
old_proof: "<ts>.<token>: token base64url of the 32 bytes the challenge opens to",
|
|
1769
|
-
scope_address_proof: "seal_address_proof",
|
|
1770
|
-
vector: {
|
|
1771
|
-
comment: "every client that migrates must open it",
|
|
1772
|
-
secret: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc",
|
|
1773
|
-
address: "E75P6uryBMf9M1j8nAByGIHRdCeBKCJ-xnTzf3_pe20",
|
|
1774
|
-
ts: 179e7,
|
|
1775
|
-
challenge: "4Oel-UMfgP_1dBhmf13yZiujhPDouCIQ6sSx1nY1qy-vyzFqDqb9jARbJ0e5A8vv4EDELDS5OPqBQMcsmDA-C_lXO95y_CVUyYtSu-1fltsy5ZihOFDp0T-C9Ro",
|
|
1776
|
-
token: "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8"
|
|
1777
|
-
}
|
|
1778
|
-
},
|
|
1779
1732
|
vectors: [
|
|
1780
1733
|
{
|
|
1781
1734
|
address: "Afdcc-OkgjU572_xdbUHZSNPO6r6Up6ctP2pfF0PHJw",
|
|
1782
1735
|
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",
|
|
1783
1736
|
challenge: "wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t8",
|
|
1784
1737
|
comment: "generated once by shared/core (Identity::from_seed32, Identity::inbox_proof); every client must reproduce it",
|
|
1785
|
-
legacy_address: "BLp9HAkcfltgHfj7AMg_EfS1b_7-ZsbNPJFBBuVbq28",
|
|
1786
1738
|
proof: "1790000000.wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t8.74s5T1rE2xRNbameeTbYUHVMN-ZzFu1JBPZJNtH8eYC1vV7-h2HE_hxgo4vUB0_sHFfdYRUf0bve4_KGe32ICg",
|
|
1787
1739
|
seed: "Aw4ZJC86RVBbZnF8h5KdqLO-ydTf6vUACxYhLDdCTVg",
|
|
1788
1740
|
signature: "74s5T1rE2xRNbameeTbYUHVMN-ZzFu1JBPZJNtH8eYC1vV7-h2HE_hxgo4vUB0_sHFfdYRUf0bve4_KGe32ICg",
|
|
@@ -1826,6 +1778,7 @@ var upload_default = {
|
|
|
1826
1778
|
VERIFY_POLL_BACKOFF_MS: [0, 2e3, 3e3, 5e3, 8e3],
|
|
1827
1779
|
VERIFY_FALLBACK_WAIT_MS: 6e4,
|
|
1828
1780
|
NOT_READY_MAX_RETRIES: 3,
|
|
1781
|
+
VISIT_HEADER: "X-Seal-Visit",
|
|
1829
1782
|
PROGRESS_SPEED_WINDOW_MS: 2e4
|
|
1830
1783
|
}
|
|
1831
1784
|
};
|
|
@@ -2126,8 +2079,9 @@ var clientIdentity;
|
|
|
2126
2079
|
function setClientIdentity(name2, version) {
|
|
2127
2080
|
clientIdentity = `${name2}/${version}`;
|
|
2128
2081
|
}
|
|
2082
|
+
var requestHeaders = () => void 0;
|
|
2129
2083
|
function clientHeaders() {
|
|
2130
|
-
return clientIdentity === void 0 ? {} : { [header]: clientIdentity };
|
|
2084
|
+
return { ...clientIdentity === void 0 ? {} : { [header]: clientIdentity }, ...requestHeaders() };
|
|
2131
2085
|
}
|
|
2132
2086
|
var BackendError = class extends Error {
|
|
2133
2087
|
constructor(message, code, status, extra = {}) {
|
|
@@ -2199,6 +2153,10 @@ function toSealMetadata(wire) {
|
|
|
2199
2153
|
}))
|
|
2200
2154
|
};
|
|
2201
2155
|
}
|
|
2156
|
+
var VISIT_HEADER = upload_default.upload.VISIT_HEADER;
|
|
2157
|
+
function newVisit() {
|
|
2158
|
+
return bytesToBase64url(crypto.getRandomValues(new Uint8Array(16)));
|
|
2159
|
+
}
|
|
2202
2160
|
function encode(segment) {
|
|
2203
2161
|
return encodeURIComponent(segment);
|
|
2204
2162
|
}
|
|
@@ -2375,7 +2333,7 @@ var SealApi = class _SealApi {
|
|
|
2375
2333
|
/**
|
|
2376
2334
|
* `GET /seal/{id}/download` — the ciphertext, as a live `Response`.
|
|
2377
2335
|
*
|
|
2378
|
-
* THIS is the call that
|
|
2336
|
+
* THIS is the call that takes an open (one a `visit`, each file of it once), so every
|
|
2379
2337
|
* policy check a caller wants to make belongs before it: once a counter
|
|
2380
2338
|
* ticks it stays ticked, whatever the caller does with the bytes.
|
|
2381
2339
|
*
|
|
@@ -2404,6 +2362,7 @@ var SealApi = class _SealApi {
|
|
|
2404
2362
|
async openDownload(sealId, target, opts = {}) {
|
|
2405
2363
|
const headers = target.ownerToken ? _SealApi.ownerHeaders(target.ownerToken) : {};
|
|
2406
2364
|
if (target.sessionCookie) headers.Cookie = target.sessionCookie;
|
|
2365
|
+
if (target.visit) headers[VISIT_HEADER] = target.visit;
|
|
2407
2366
|
for (let retries = 0; ; retries++) {
|
|
2408
2367
|
try {
|
|
2409
2368
|
return await this.request(`/seal/${encode(sealId)}/download?${downloadQuery(target)}`, {
|
|
@@ -2656,10 +2615,11 @@ var SealApi = class _SealApi {
|
|
|
2656
2615
|
if (input.ttlSeconds !== void 0) body.ttl_seconds = input.ttlSeconds;
|
|
2657
2616
|
if (input.to) body.to = input.to;
|
|
2658
2617
|
if (input.bind) body.bind = input.bind;
|
|
2618
|
+
if (input.answerToInbox) body.answer_to_inbox = true;
|
|
2659
2619
|
const resp = await this.request("/intake", {
|
|
2660
2620
|
what: "POST /intake",
|
|
2661
2621
|
method: "POST",
|
|
2662
|
-
headers: { "Content-Type": "application/json" },
|
|
2622
|
+
headers: { "Content-Type": "application/json", ...input.answerToInbox ? proofHeaders(input.answerToInbox) : {} },
|
|
2663
2623
|
body: JSON.stringify(body),
|
|
2664
2624
|
signal: opts.signal
|
|
2665
2625
|
});
|
|
@@ -2678,12 +2638,15 @@ var SealApi = class _SealApi {
|
|
|
2678
2638
|
});
|
|
2679
2639
|
return await resp.json();
|
|
2680
2640
|
}
|
|
2681
|
-
/**
|
|
2641
|
+
/**
|
|
2642
|
+
* `POST /intake/{id}/fulfil` — the page reports the seal it made; once. It carries the proof of the link it holds
|
|
2643
|
+
* for that seal (`holdShareProof`): an answer into a person's inbox is a link its maker proves (OWNER.md 9).
|
|
2644
|
+
*/
|
|
2682
2645
|
async fulfilIntake(intakeId, link, opts = {}) {
|
|
2683
2646
|
const resp = await this.request(`/intake/${encode(intakeId)}/fulfil`, {
|
|
2684
2647
|
what: `POST /intake/${intakeId}/fulfil`,
|
|
2685
2648
|
method: "POST",
|
|
2686
|
-
headers: { "Content-Type": "application/json" },
|
|
2649
|
+
headers: { "Content-Type": "application/json", ...shareProofHeader(`/seal/${encode(link.sealId)}`) },
|
|
2687
2650
|
body: JSON.stringify({ seal_id: link.sealId, share_code: link.shareCode, fragment: link.fragment }),
|
|
2688
2651
|
signal: opts.signal
|
|
2689
2652
|
});
|
|
@@ -2940,6 +2903,11 @@ async function encryptBlob(data, linkKey) {
|
|
|
2940
2903
|
result.set(new Uint8Array(ciphertext), 12);
|
|
2941
2904
|
return result;
|
|
2942
2905
|
}
|
|
2906
|
+
function isNdaFileRef(value) {
|
|
2907
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2908
|
+
const obj = value;
|
|
2909
|
+
return typeof obj.sha256_hex === "string" && typeof obj.name === "string";
|
|
2910
|
+
}
|
|
2943
2911
|
function isBinding(value) {
|
|
2944
2912
|
if (typeof value !== "object" || value === null) return false;
|
|
2945
2913
|
const obj = value;
|
|
@@ -3525,6 +3493,10 @@ var encoder2 = new TextEncoder();
|
|
|
3525
3493
|
var zipLogger = createLogger("FolderZip");
|
|
3526
3494
|
var BLOB_LIMIT = 100 * 1024 * 1024;
|
|
3527
3495
|
var HIGH_WATER_BYTES = 4 * 1024 * 1024;
|
|
3496
|
+
var dropped = /* @__PURE__ */ new WeakMap();
|
|
3497
|
+
function folderPathOf(file) {
|
|
3498
|
+
return dropped.get(file) ?? (file.webkitRelativePath || void 0);
|
|
3499
|
+
}
|
|
3528
3500
|
var ENCRYPTED_FILE_FALLBACK = "Encrypted file";
|
|
3529
3501
|
var ENCRYPTED_MIME_FALLBACK = "application/octet-stream";
|
|
3530
3502
|
function metadataFieldAAD(field) {
|
|
@@ -5017,6 +4989,48 @@ async function uploadRegisteredFile(session, entry, callbacks = {}) {
|
|
|
5017
4989
|
entry.prepared = void 0;
|
|
5018
4990
|
report("done", 1, true);
|
|
5019
4991
|
}
|
|
4992
|
+
async function uploadPendingFiles(session, options = {}) {
|
|
4993
|
+
const { signal, onFileProgress } = options;
|
|
4994
|
+
const isMultipart = (entry) => usesMultipart(entry.file.size, session.policy);
|
|
4995
|
+
const pending = session.pending;
|
|
4996
|
+
const small = pending.filter((entry) => !isMultipart(entry));
|
|
4997
|
+
const large = pending.filter(isMultipart);
|
|
4998
|
+
const stop = new AbortController();
|
|
4999
|
+
const onCallerAbort = () => stop.abort();
|
|
5000
|
+
if (signal?.aborted) stop.abort();
|
|
5001
|
+
else signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
5002
|
+
let failure = null;
|
|
5003
|
+
const runOne = async (entry) => {
|
|
5004
|
+
try {
|
|
5005
|
+
await uploadRegisteredFile(session, entry, {
|
|
5006
|
+
signal: stop.signal,
|
|
5007
|
+
onProgress: (progress) => onFileProgress?.(entry, progress)
|
|
5008
|
+
});
|
|
5009
|
+
} catch (err) {
|
|
5010
|
+
if (failure === null) {
|
|
5011
|
+
failure = err;
|
|
5012
|
+
stop.abort();
|
|
5013
|
+
}
|
|
5014
|
+
}
|
|
5015
|
+
};
|
|
5016
|
+
try {
|
|
5017
|
+
let next = 0;
|
|
5018
|
+
const lane = async () => {
|
|
5019
|
+
while (failure === null && !stop.signal.aborted && next < small.length) await runOne(small[next++]);
|
|
5020
|
+
};
|
|
5021
|
+
await Promise.all(
|
|
5022
|
+
Array.from({ length: Math.min(upload_default.upload.SMALL_FILE_POOL, small.length) }, lane)
|
|
5023
|
+
);
|
|
5024
|
+
for (const entry of large) {
|
|
5025
|
+
if (failure !== null || stop.signal.aborted) break;
|
|
5026
|
+
await runOne(entry);
|
|
5027
|
+
}
|
|
5028
|
+
} finally {
|
|
5029
|
+
signal?.removeEventListener("abort", onCallerAbort);
|
|
5030
|
+
}
|
|
5031
|
+
if (failure !== null) throw failure;
|
|
5032
|
+
if (signal?.aborted) throw new UploadError("Upload aborted", "ABORTED");
|
|
5033
|
+
}
|
|
5020
5034
|
function validateSealContext(ctx) {
|
|
5021
5035
|
if (ctx.roomId) return;
|
|
5022
5036
|
if (!ctx.ownerTokenHash) {
|
|
@@ -5149,9 +5163,56 @@ function toSessionFiles(planned, rows) {
|
|
|
5149
5163
|
state: "pending"
|
|
5150
5164
|
}));
|
|
5151
5165
|
}
|
|
5152
|
-
|
|
5166
|
+
function keysByDigest(files) {
|
|
5167
|
+
const keys = /* @__PURE__ */ new Map();
|
|
5168
|
+
for (const entry of files) keys.set(entry.sha256_hex, entry.key);
|
|
5169
|
+
return keys;
|
|
5170
|
+
}
|
|
5171
|
+
function batchProgress(files) {
|
|
5172
|
+
const totalSize = files.reduce((sum, f) => sum + f.file.size, 0);
|
|
5173
|
+
const percents = /* @__PURE__ */ new Map();
|
|
5174
|
+
for (const f of files) percents.set(f.index, f.state === "pending" ? 0 : 100);
|
|
5175
|
+
let floor = 0;
|
|
5176
|
+
return {
|
|
5177
|
+
/** Record one file's percent; returns the batch's, 100 only when every file is done. */
|
|
5178
|
+
note(entry, progress) {
|
|
5179
|
+
percents.set(entry.index, progress.phase === "done" ? 100 : Math.max(percents.get(entry.index) ?? 0, progress.percent));
|
|
5180
|
+
const finished = files.every((f) => percents.get(f.index) === 100);
|
|
5181
|
+
const weighted = files.reduce((sum, f) => sum + f.file.size * (percents.get(f.index) ?? 0), 0);
|
|
5182
|
+
const overall = totalSize > 0 ? Math.floor(weighted / totalSize) : 100;
|
|
5183
|
+
floor = Math.max(floor, finished ? 100 : Math.min(99, overall));
|
|
5184
|
+
return { percent: floor, finished };
|
|
5185
|
+
}
|
|
5186
|
+
};
|
|
5187
|
+
}
|
|
5188
|
+
async function runManyFiles(session, callbacks) {
|
|
5189
|
+
const { onProgress, signal } = callbacks;
|
|
5190
|
+
const files = session.files;
|
|
5191
|
+
const batch = batchProgress(files);
|
|
5192
|
+
await uploadPendingFiles(session, {
|
|
5193
|
+
signal,
|
|
5194
|
+
onFileProgress: (entry, p) => {
|
|
5195
|
+
onProgress?.({
|
|
5196
|
+
fileIndex: entry.index,
|
|
5197
|
+
totalFiles: files.length,
|
|
5198
|
+
fileName: entry.file.name,
|
|
5199
|
+
fileProgress: p,
|
|
5200
|
+
overallPercent: batch.note(entry, p).percent
|
|
5201
|
+
});
|
|
5202
|
+
}
|
|
5203
|
+
});
|
|
5204
|
+
}
|
|
5205
|
+
async function openManyFilesSession(ctx, items, policy, callbacks, shape) {
|
|
5206
|
+
if (items.length === 0) {
|
|
5207
|
+
throw new Error("At least one file is required");
|
|
5208
|
+
}
|
|
5153
5209
|
validateSealContext(ctx);
|
|
5154
|
-
const planned = await planFile(file, generateKey());
|
|
5210
|
+
const planned = await Promise.all(items.map(({ file }) => planFile(file, generateKey())));
|
|
5211
|
+
const filesMeta = await Promise.all(planned.map(
|
|
5212
|
+
(p, i) => buildFileMeta(p.file, p.key, ciphertextSize(p.file.size), p.sha256_hex, {
|
|
5213
|
+
relativePath: items[i].relativePath
|
|
5214
|
+
})
|
|
5215
|
+
));
|
|
5155
5216
|
const sessionOf = (registration, files) => new UploadSession(
|
|
5156
5217
|
{
|
|
5157
5218
|
ctx,
|
|
@@ -5162,35 +5223,52 @@ async function uploadSingleFile(ctx, file, policy = DEFAULT_POLICY, callbacks =
|
|
|
5162
5223
|
files
|
|
5163
5224
|
},
|
|
5164
5225
|
async (s, cb) => {
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
onProgress: (p) => cb.onProgress?.(p),
|
|
5168
|
-
signal: cb.signal
|
|
5169
|
-
});
|
|
5170
|
-
return {
|
|
5171
|
-
sealId: s.sealId,
|
|
5172
|
-
fileId: entry.fileId,
|
|
5173
|
-
encryptionKey: entry.key,
|
|
5174
|
-
sha256_hex: entry.sha256_hex,
|
|
5175
|
-
expiresAt: s.expiresAt,
|
|
5176
|
-
verification: s.verification
|
|
5177
|
-
};
|
|
5226
|
+
await runManyFiles(s, cb);
|
|
5227
|
+
return shape(s);
|
|
5178
5228
|
}
|
|
5179
5229
|
);
|
|
5180
|
-
const seal = await createSeal(
|
|
5181
|
-
|
|
5182
|
-
|
|
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));
|
|
5230
|
+
const seal = await createSeal(ctx, filesMeta, callbacks.signal, (late) => sessionOf(late, []).cancel(), registrationDeadlineMs(policy));
|
|
5231
|
+
const rows = await pairOrGiveBack(seal.files, planned.map((p) => p.sha256_hex), `Create seal ${seal.id}`, () => sessionOf(seal, []).cancel());
|
|
5232
|
+
const session = sessionOf(seal, toSessionFiles(planned, rows));
|
|
5190
5233
|
await stopIfCancelled(session, callbacks.signal);
|
|
5191
|
-
await announceRegistered(callbacks, seal.id,
|
|
5234
|
+
await announceRegistered(callbacks, seal.id, planned, rows);
|
|
5192
5235
|
return session.resume(callbacks);
|
|
5193
5236
|
}
|
|
5237
|
+
async function uploadMultipleFiles(ctx, files, policy = DEFAULT_POLICY, callbacks = {}) {
|
|
5238
|
+
return openManyFilesSession(ctx, files.map((file) => ({ file })), policy, callbacks, (s) => ({
|
|
5239
|
+
sealId: s.sealId,
|
|
5240
|
+
files: s.files.map((entry) => ({
|
|
5241
|
+
fileId: entry.fileId,
|
|
5242
|
+
sha256_hex: entry.sha256_hex,
|
|
5243
|
+
encryptedSize: entry.encryptedSize
|
|
5244
|
+
})),
|
|
5245
|
+
encryptionKeys: keysByDigest(s.files),
|
|
5246
|
+
expiresAt: s.expiresAt,
|
|
5247
|
+
verification: s.verification
|
|
5248
|
+
}));
|
|
5249
|
+
}
|
|
5250
|
+
async function uploadFolderAsFiles(ctx, files, folderName, policy = DEFAULT_POLICY, callbacks = {}, relativePaths) {
|
|
5251
|
+
if (relativePaths && relativePaths.length !== files.length) {
|
|
5252
|
+
throw new Error(`uploadFolderAsFiles: ${files.length} file(s) but ${relativePaths.length} path(s)`);
|
|
5253
|
+
}
|
|
5254
|
+
const items = files.map((file, i) => ({
|
|
5255
|
+
file,
|
|
5256
|
+
relativePath: relativePaths?.[i] || file.webkitRelativePath || `${folderName}/${file.name}`
|
|
5257
|
+
}));
|
|
5258
|
+
return openManyFilesSession(ctx, items, policy, callbacks, (s) => ({
|
|
5259
|
+
sealId: s.sealId,
|
|
5260
|
+
files: s.files.map((entry) => ({
|
|
5261
|
+
fileId: entry.fileId,
|
|
5262
|
+
sha256_hex: entry.sha256_hex,
|
|
5263
|
+
encryptedSize: entry.encryptedSize,
|
|
5264
|
+
relativePath: items[entry.index].relativePath
|
|
5265
|
+
})),
|
|
5266
|
+
encryptionKeys: keysByDigest(s.files),
|
|
5267
|
+
folderName,
|
|
5268
|
+
expiresAt: s.expiresAt,
|
|
5269
|
+
verification: s.verification
|
|
5270
|
+
}));
|
|
5271
|
+
}
|
|
5194
5272
|
var PAYMENT_POLL_MS = [2e3, 4e3, 8e3, 15e3];
|
|
5195
5273
|
var TIER_BYTES = limits_default.limits.TIER_BYTES;
|
|
5196
5274
|
var PAID_TIERS = Object.keys(TIER_BYTES).filter((code) => code !== "free").sort((a, b) => TIER_BYTES[a] - TIER_BYTES[b]);
|
|
@@ -5217,6 +5295,27 @@ async function waitForPayment(api, sealId, ownerToken, opts) {
|
|
|
5217
5295
|
}
|
|
5218
5296
|
}
|
|
5219
5297
|
var TTL_OPTIONS = limits_default.limits.ttl_options;
|
|
5298
|
+
function maxOpensOf(text2) {
|
|
5299
|
+
const typed = text2.trim();
|
|
5300
|
+
if (typed === "") return void 0;
|
|
5301
|
+
const opens = /^\d+$/.test(typed) ? Number(typed) : Number.NaN;
|
|
5302
|
+
return opens >= 1 && opens <= limits_default.limits.MAX_OPENS_PER_SEAL_FREE ? opens : null;
|
|
5303
|
+
}
|
|
5304
|
+
var NO_COUNTRY = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
|
|
5305
|
+
var regions;
|
|
5306
|
+
function countryCodes(text2) {
|
|
5307
|
+
regions ?? (regions = new Intl.DisplayNames(["en"], { type: "region", fallback: "none" }));
|
|
5308
|
+
const codes = [];
|
|
5309
|
+
const bad = [];
|
|
5310
|
+
for (const token of text2.split(/[\s,;]+/)) {
|
|
5311
|
+
if (token === "") continue;
|
|
5312
|
+
const typed = token.toUpperCase();
|
|
5313
|
+
const code = /^[A-Z]{2}$/.test(typed) ? Intl.getCanonicalLocales(`und-${typed}`)[0]?.split("-")[1] : void 0;
|
|
5314
|
+
if (!code || NO_COUNTRY.has(code) || !regions.of(code)) bad.push(token);
|
|
5315
|
+
else if (!codes.includes(code)) codes.push(code);
|
|
5316
|
+
}
|
|
5317
|
+
return { codes, bad };
|
|
5318
|
+
}
|
|
5220
5319
|
var SEAL_ID_LENGTH = 8;
|
|
5221
5320
|
var LINK_KEY_LENGTH = 43;
|
|
5222
5321
|
var SHARE_CODE_LENGTH = 4;
|
|
@@ -6136,9 +6235,9 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6136
6235
|
let shareKey = parsed.fragmentVariant === "key" ? base64urlToBytes(parsed.fragment) : wrapped !== null && seed2 ? await openLinkWrap(wrapped, seed2, sealId) : null;
|
|
6137
6236
|
if (shareKey !== null) await holdShareProof(sealId, shareKey);
|
|
6138
6237
|
const request = opts.signal ? { signal: opts.signal } : {};
|
|
6139
|
-
let
|
|
6238
|
+
let wire;
|
|
6140
6239
|
try {
|
|
6141
|
-
|
|
6240
|
+
wire = await api.getMetadata(parsed.sealId, { ...request, shareCode });
|
|
6142
6241
|
} catch (err) {
|
|
6143
6242
|
if (err instanceof BackendError && (err.code === "not_found" || err.code === "revoked")) {
|
|
6144
6243
|
throw new OpenError(
|
|
@@ -6149,6 +6248,7 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6149
6248
|
}
|
|
6150
6249
|
throw new OpenError("metadata_failed", `reading seal ${parsed.sealId} failed: ${messageOf(err)}`, err);
|
|
6151
6250
|
}
|
|
6251
|
+
const meta = toSealMetadata(wire);
|
|
6152
6252
|
if (meta.revokedAt !== null) throw new OpenError("seal_revoked", `seal ${parsed.sealId} has been revoked`);
|
|
6153
6253
|
if (meta.files.length === 0) {
|
|
6154
6254
|
throw new OpenError(
|
|
@@ -6181,10 +6281,14 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6181
6281
|
}
|
|
6182
6282
|
let fileKeys;
|
|
6183
6283
|
let bindings;
|
|
6284
|
+
let message;
|
|
6285
|
+
let ndaFile;
|
|
6184
6286
|
try {
|
|
6185
6287
|
const blob = await decryptShareBlob(blobBytes, shareKey);
|
|
6186
6288
|
fileKeys = blob.file_keys;
|
|
6187
6289
|
bindings = bindingsOf(blob);
|
|
6290
|
+
message = blob.message?.trim() ? blob.message : null;
|
|
6291
|
+
ndaFile = isNdaFileRef(blob.nda_file) ? blob.nda_file : null;
|
|
6188
6292
|
} catch (err) {
|
|
6189
6293
|
throw new OpenError(
|
|
6190
6294
|
"share_blob_decrypt_failed",
|
|
@@ -6195,11 +6299,19 @@ async function openShareLink(api, url, opts = {}) {
|
|
|
6195
6299
|
const files = await Promise.all(meta.files.map((f) => describeFile(f, fileKeys, bindings)));
|
|
6196
6300
|
return {
|
|
6197
6301
|
sealId,
|
|
6302
|
+
shareCode,
|
|
6198
6303
|
expiresAt: meta.expiresAt,
|
|
6199
6304
|
singleUse: meta.singleUse,
|
|
6200
6305
|
maxOpens: meta.maxOpens,
|
|
6201
6306
|
otpRequired: meta.otpRequired,
|
|
6202
6307
|
ndaRequired: meta.ndaRequired,
|
|
6308
|
+
otpPassed: wire.otp_session_valid === true,
|
|
6309
|
+
ndaPassed: wire.nda_session_valid === true,
|
|
6310
|
+
spent: wire.spent === true,
|
|
6311
|
+
countries: wire.geo_allowlist?.length ? wire.geo_allowlist : null,
|
|
6312
|
+
message,
|
|
6313
|
+
ndaFile,
|
|
6314
|
+
linkKey: shareKey,
|
|
6203
6315
|
files
|
|
6204
6316
|
};
|
|
6205
6317
|
}
|
|
@@ -6255,8 +6367,26 @@ async function readAnswerFile(api, url, mime, opts) {
|
|
|
6255
6367
|
if (!file?.key || !file.sha256Hex || more.length > 0 || bareMime(file.mime) !== mime || file.size > ANSWER_MAX_BYTES) {
|
|
6256
6368
|
throw new OpenError("share_blob_corrupt", `the answer is not one ${mime} file`);
|
|
6257
6369
|
}
|
|
6258
|
-
|
|
6259
|
-
|
|
6370
|
+
return readOpenedFile(api, { sealId: seal.sealId, shareCode: null }, file, {
|
|
6371
|
+
maxBytes: ANSWER_MAX_BYTES,
|
|
6372
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
6373
|
+
});
|
|
6374
|
+
}
|
|
6375
|
+
async function readOpenedFile(api, seal, file, opts) {
|
|
6376
|
+
if (!file.key || !file.sha256Hex || file.size > opts.maxBytes) {
|
|
6377
|
+
throw new OpenError("share_blob_corrupt", `file ${file.id} is not one of at most ${opts.maxBytes} bytes this link opens`);
|
|
6378
|
+
}
|
|
6379
|
+
const resp = await api.downloadCiphertext(
|
|
6380
|
+
seal.sealId,
|
|
6381
|
+
{
|
|
6382
|
+
fileId: file.id,
|
|
6383
|
+
...seal.shareCode ? { shareCode: seal.shareCode } : {},
|
|
6384
|
+
...opts.sessionCookie ? { sessionCookie: opts.sessionCookie } : {},
|
|
6385
|
+
...opts.visit ? { visit: opts.visit } : {}
|
|
6386
|
+
},
|
|
6387
|
+
opts.signal ? { signal: opts.signal } : {}
|
|
6388
|
+
);
|
|
6389
|
+
if (!resp.body) throw new OpenError("share_blob_corrupt", `file ${file.id} came without a body`);
|
|
6260
6390
|
const reader = decryptVerified(resp.body, file.key, file.sha256Hex).stream.getReader();
|
|
6261
6391
|
const chunks = [];
|
|
6262
6392
|
for (let part = await reader.read(); !part.done; part = await reader.read()) chunks.push(part.value);
|
|
@@ -6394,6 +6524,122 @@ var LEASE_MAX_DAYS = limits_default.limits.LEASE_MAX_DAYS;
|
|
|
6394
6524
|
var LEASE_POLL_SECONDS = limits_default.limits.LEASE_POLL_SECONDS;
|
|
6395
6525
|
var LEASE_STATUS_BATCH_MAX = limits_default.limits.LEASE_STATUS_BATCH_MAX;
|
|
6396
6526
|
|
|
6527
|
+
async function newKeys() {
|
|
6528
|
+
const token = generateOwnerToken();
|
|
6529
|
+
const linkKey = generateLinkKey();
|
|
6530
|
+
return {
|
|
6531
|
+
ownerTokenB64: bytesToBase64url(token),
|
|
6532
|
+
ownerTokenHash: await hashOwnerToken(token),
|
|
6533
|
+
linkKey,
|
|
6534
|
+
linkKeyB64: bytesToBase64url(linkKey)
|
|
6535
|
+
};
|
|
6536
|
+
}
|
|
6537
|
+
var DEFAULT_TTL = TTL_OPTIONS[TTL_OPTIONS.length - 1] ?? TTL_OPTIONS[0];
|
|
6538
|
+
var SECRET_ALONE = { ttl: "1h", singleUse: true };
|
|
6539
|
+
function createOptions(rules, keys, tier) {
|
|
6540
|
+
return {
|
|
6541
|
+
ttl: tier && rules.ttl !== "1d" && rules.ttl !== "7d" ? "1d" : rules.ttl,
|
|
6542
|
+
...tier ? { tier } : {},
|
|
6543
|
+
...rules.otp ? { otp: rules.otp } : {},
|
|
6544
|
+
nda: rules.nda ?? false,
|
|
6545
|
+
...rules.ownerEmail ? { ownerEmail: rules.ownerEmail } : {},
|
|
6546
|
+
singleUse: rules.singleUse ?? false,
|
|
6547
|
+
...!rules.singleUse && rules.maxOpens ? { maxOpens: rules.maxOpens } : {},
|
|
6548
|
+
...rules.geo && rules.geo.length > 0 ? { geo: rules.geo } : {},
|
|
6549
|
+
ownerTokenHash: keys.ownerTokenHash,
|
|
6550
|
+
ownerToken: keys.ownerTokenB64
|
|
6551
|
+
};
|
|
6552
|
+
}
|
|
6553
|
+
var PERSON_UPLOAD_POLICY = { ...DEFAULT_POLICY, transport: { maxStallMs: Infinity } };
|
|
6554
|
+
function createContext(baseUrl, options) {
|
|
6555
|
+
const { ttl, tier, otp, nda, ownerEmail, singleUse, maxOpens, geo, ownerTokenHash, ownerToken } = options;
|
|
6556
|
+
return {
|
|
6557
|
+
baseUrl,
|
|
6558
|
+
auth: { kind: "none" },
|
|
6559
|
+
ttl,
|
|
6560
|
+
...tier ? { tier } : {},
|
|
6561
|
+
...otp ? { otp } : {},
|
|
6562
|
+
...nda !== void 0 ? { nda } : {},
|
|
6563
|
+
...ownerEmail ? { ownerEmail } : {},
|
|
6564
|
+
...singleUse !== void 0 ? { singleUse } : {},
|
|
6565
|
+
...maxOpens ? { maxOpens } : {},
|
|
6566
|
+
...geo && geo.length > 0 ? { geo: [...geo] } : {},
|
|
6567
|
+
ownerTokenHash,
|
|
6568
|
+
ownerToken
|
|
6569
|
+
};
|
|
6570
|
+
}
|
|
6571
|
+
var OwnerBlobNotStored = class extends Error {
|
|
6572
|
+
};
|
|
6573
|
+
async function sealFiles(input) {
|
|
6574
|
+
const { keys, ndaFileName, api } = input;
|
|
6575
|
+
const message = input.message?.trim() ? input.message : void 0;
|
|
6576
|
+
const outcome = await input.upload(async (sealId, registered) => {
|
|
6577
|
+
input.registered?.(sealId);
|
|
6578
|
+
const { fileKeys: fileKeys2, ndaFile: ndaFile2 } = blobKeys(registered, ndaFileName);
|
|
6579
|
+
const ownerBlob = bytesToBase64url(await encryptOwnerBlob(keys.ownerTokenB64, fileKeys2, keys.linkKey, message, ndaFile2));
|
|
6580
|
+
await storeOwnerBlob(api, sealId, keys.ownerTokenB64, ownerBlob);
|
|
6581
|
+
await input.ownerBlobStored?.(sealId);
|
|
6582
|
+
});
|
|
6583
|
+
input.uploaded?.(outcome);
|
|
6584
|
+
const files = outcome.fileResults.map((file) => {
|
|
6585
|
+
const key = outcome.encryptionKeys.get(file.sha256_hex);
|
|
6586
|
+
if (!key) throw new Error(`the upload returned no key for the file ${file.fileId}`);
|
|
6587
|
+
return { sha256_hex: file.sha256_hex, key };
|
|
6588
|
+
});
|
|
6589
|
+
const { fileKeys, ndaFile } = blobKeys(files, ndaFileName);
|
|
6590
|
+
const shareKey = generateLinkKey();
|
|
6591
|
+
const share = {
|
|
6592
|
+
blobB64: bytesToBase64url(await encryptShareBlob(fileKeys, shareKey, message, ndaFile)),
|
|
6593
|
+
linkKeyB64: bytesToBase64url(shareKey)
|
|
6594
|
+
};
|
|
6595
|
+
input.minting?.(share);
|
|
6596
|
+
const { to } = input;
|
|
6597
|
+
if (to) {
|
|
6598
|
+
const fragment = await wrapTo(shareKey, to.bundle, SHARE_SCOPE, outcome.sealId);
|
|
6599
|
+
const label = to.label?.slice(0, 80);
|
|
6600
|
+
const mint = (sender2) => api.createShareLink(outcome.sealId, keys.ownerTokenB64, share.blobB64, shareKey, {
|
|
6601
|
+
to: to.address,
|
|
6602
|
+
fragment,
|
|
6603
|
+
...label ? { label } : {},
|
|
6604
|
+
...sender2 ? { sender: sender2 } : {}
|
|
6605
|
+
});
|
|
6606
|
+
const proof = async (fresh) => await to.sender?.(fresh).catch(() => null) ?? null;
|
|
6607
|
+
const proofRefused = (err) => err instanceof BackendError && err.appCode === "intake.proof_required";
|
|
6608
|
+
const sender = await proof(false);
|
|
6609
|
+
const shareCode2 = await mint(sender).catch(async (err) => {
|
|
6610
|
+
if (!sender || !proofRefused(err)) throw err;
|
|
6611
|
+
const fresh = await proof(true);
|
|
6612
|
+
if (!fresh) return mint(null);
|
|
6613
|
+
return mint(fresh).catch((again) => {
|
|
6614
|
+
if (proofRefused(again)) return mint(null);
|
|
6615
|
+
throw again;
|
|
6616
|
+
});
|
|
6617
|
+
});
|
|
6618
|
+
return { sealId: outcome.sealId, verification: outcome.verification, shareCode: shareCode2, share };
|
|
6619
|
+
}
|
|
6620
|
+
const shareCode = await api.createShareLink(outcome.sealId, keys.ownerTokenB64, share.blobB64, shareKey).catch(() => null);
|
|
6621
|
+
return { sealId: outcome.sealId, verification: outcome.verification, shareCode, share };
|
|
6622
|
+
}
|
|
6623
|
+
async function storeOwnerBlob(api, sealId, ownerToken, blob) {
|
|
6624
|
+
let failure = null;
|
|
6625
|
+
for (let tries = 0; tries < 2; tries++) {
|
|
6626
|
+
try {
|
|
6627
|
+
await api.writeOwnerBlob(sealId, ownerToken, blob);
|
|
6628
|
+
return;
|
|
6629
|
+
} catch (err) {
|
|
6630
|
+
failure = err;
|
|
6631
|
+
}
|
|
6632
|
+
}
|
|
6633
|
+
throw new OwnerBlobNotStored(failure instanceof Error ? failure.message : String(failure), { cause: failure });
|
|
6634
|
+
}
|
|
6635
|
+
function blobKeys(files, ndaFileName) {
|
|
6636
|
+
const last = files[files.length - 1];
|
|
6637
|
+
return {
|
|
6638
|
+
fileKeys: new Map(files.map((f) => [f.sha256_hex, bytesToBase64url(f.key)])),
|
|
6639
|
+
ndaFile: ndaFileName && last ? { sha256_hex: last.sha256_hex, name: ndaFileName } : void 0
|
|
6640
|
+
};
|
|
6641
|
+
}
|
|
6642
|
+
|
|
6397
6643
|
var limits_default2 = {
|
|
6398
6644
|
version: 1,
|
|
6399
6645
|
limits: {
|
|
@@ -6408,6 +6654,8 @@ var limits_default2 = {
|
|
|
6408
6654
|
MAX_FILE_KEYS: 1e4,
|
|
6409
6655
|
MAX_ACTIVE_UPLOADS_PER_SEAL: 10,
|
|
6410
6656
|
MAX_OPENS_PER_SEAL_FREE: 10,
|
|
6657
|
+
MAX_GEO_COUNTRIES: 50,
|
|
6658
|
+
SEAL_VISIT_SECONDS: 21600,
|
|
6411
6659
|
TIER_BYTES: {
|
|
6412
6660
|
free: 1073741824,
|
|
6413
6661
|
"5gb": 5368709120,
|
|
@@ -6473,6 +6721,24 @@ var limits_default2 = {
|
|
|
6473
6721
|
}
|
|
6474
6722
|
};
|
|
6475
6723
|
|
|
6724
|
+
var SIZE_UNITS = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"];
|
|
6725
|
+
var SIZE_LABELS = ["B", "KB", "MB", "GB", "TB"];
|
|
6726
|
+
function formatBytes(bytes, locale) {
|
|
6727
|
+
const k = 1024;
|
|
6728
|
+
let i = bytes > 0 ? Math.min(Math.floor(Math.log(bytes) / Math.log(k)), SIZE_UNITS.length - 1) : 0;
|
|
6729
|
+
let value = parseFloat((bytes / Math.pow(k, i)).toFixed(2));
|
|
6730
|
+
if (value >= k && i < SIZE_UNITS.length - 1) {
|
|
6731
|
+
i += 1;
|
|
6732
|
+
value = parseFloat((bytes / Math.pow(k, i)).toFixed(2));
|
|
6733
|
+
}
|
|
6734
|
+
if (!locale) return `${value} ${SIZE_LABELS[i]}`;
|
|
6735
|
+
return new Intl.NumberFormat(locale, { style: "unit", unit: SIZE_UNITS[i], unitDisplay: i === 0 ? "long" : "short", maximumFractionDigits: 2 }).format(value);
|
|
6736
|
+
}
|
|
6737
|
+
var SECOND = 1e3;
|
|
6738
|
+
var MINUTE = 60 * SECOND;
|
|
6739
|
+
var HOUR = 60 * MINUTE;
|
|
6740
|
+
var DAY = 24 * HOUR;
|
|
6741
|
+
|
|
6476
6742
|
// src/errors.ts
|
|
6477
6743
|
var SealError = class _SealError extends Error {
|
|
6478
6744
|
code;
|
|
@@ -6546,8 +6812,16 @@ function sealErrorFrom(err, fallbackMessage, details = null) {
|
|
|
6546
6812
|
);
|
|
6547
6813
|
}
|
|
6548
6814
|
|
|
6815
|
+
// src/folder.ts
|
|
6816
|
+
function pathParts(path) {
|
|
6817
|
+
return path.split("/").filter((part) => part !== "" && part !== "." && part !== "..");
|
|
6818
|
+
}
|
|
6819
|
+
|
|
6549
6820
|
// src/anonymous.ts
|
|
6550
|
-
var
|
|
6821
|
+
var LIMITS = limits_default2.limits;
|
|
6822
|
+
var TTL_OPTIONS2 = LIMITS.ttl_options;
|
|
6823
|
+
var SECRET_NAME = "Secret";
|
|
6824
|
+
var NDA_DEFAULT_TEXT = "Confidentiality Agreement";
|
|
6551
6825
|
var AnonymousSealsSendResource = class {
|
|
6552
6826
|
api;
|
|
6553
6827
|
baseUrl;
|
|
@@ -6580,14 +6854,15 @@ var AnonymousSealsSendResource = class {
|
|
|
6580
6854
|
});
|
|
6581
6855
|
}
|
|
6582
6856
|
/**
|
|
6583
|
-
* Create an anonymous encrypted seal.
|
|
6857
|
+
* Create an anonymous encrypted seal: files, a folder, a secret, as on seal.net.
|
|
6584
6858
|
*
|
|
6585
|
-
* Full E2EE flow:
|
|
6859
|
+
* Full E2EE flow, seal.net's own steps:
|
|
6586
6860
|
* 1. Generate the owner token client-side (the server sees only its hash)
|
|
6587
|
-
* 2. Register
|
|
6588
|
-
*
|
|
6589
|
-
* blob (owner token + file keys +
|
|
6590
|
-
*
|
|
6861
|
+
* 2. Register every file under the SHA-256 of its header (the rules ride
|
|
6862
|
+
* along, as seal.net reads and sends them); before the first byte, store
|
|
6863
|
+
* the encrypted owner blob (owner token + file keys + note) and the
|
|
6864
|
+
* owner's inbox copy
|
|
6865
|
+
* 3. Encrypt + upload the files' content
|
|
6591
6866
|
* 4. Mint a separate recipient share (share blob + share code), its key
|
|
6592
6867
|
* wrapped to the recipient's bundle when addressed
|
|
6593
6868
|
* 5. Return the recipient shareUrl and the owner ownerUrl
|
|
@@ -6597,10 +6872,11 @@ var AnonymousSealsSendResource = class {
|
|
|
6597
6872
|
* const anonymous = new AnonymousSealsSendResource()
|
|
6598
6873
|
*
|
|
6599
6874
|
* const result = await anonymous.create({
|
|
6600
|
-
* file:
|
|
6601
|
-
* filename: '
|
|
6602
|
-
*
|
|
6603
|
-
*
|
|
6875
|
+
* file: dumpBuffer,
|
|
6876
|
+
* filename: 'dump.sql',
|
|
6877
|
+
* secret: process.env.DB_PASSWORD, // from the environment: no key is written into code
|
|
6878
|
+
* ttl: '1d',
|
|
6879
|
+
* otp: process.env.SEAL_PASSWORD,
|
|
6604
6880
|
* singleUse: true,
|
|
6605
6881
|
* })
|
|
6606
6882
|
*
|
|
@@ -6609,12 +6885,17 @@ var AnonymousSealsSendResource = class {
|
|
|
6609
6885
|
* ```
|
|
6610
6886
|
*/
|
|
6611
6887
|
async create(options) {
|
|
6612
|
-
if (options.nda && !options.ownerEmail)
|
|
6613
|
-
|
|
6614
|
-
}
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6888
|
+
if (options.nda && !options.ownerEmail) refuse("ownerEmail is required when nda=true");
|
|
6889
|
+
if (options.tier && !options.onPaymentRequired) refuse("onPaymentRequired is required with tier");
|
|
6890
|
+
const { files, relativePaths, ndaDocument, secretAlone } = sealContents(options);
|
|
6891
|
+
const note = options.message?.trim() ? options.message : void 0;
|
|
6892
|
+
if (note && note.length > LIMITS.MAX_MESSAGE_LENGTH) {
|
|
6893
|
+
refuse(`message: ${note.length} characters, at most ${LIMITS.MAX_MESSAGE_LENGTH}`);
|
|
6894
|
+
}
|
|
6895
|
+
if (note && ndaDocument) refuse("message and ndaFile: the NDA is its text or its document, give one of them");
|
|
6896
|
+
const message = note ?? (ndaDocument ? `NDA document attached: ${ndaDocument.name} (${formatBytes(ndaDocument.size)})` : options.nda ? NDA_DEFAULT_TEXT : void 0);
|
|
6897
|
+
const rules = sealRules(options, secretAlone);
|
|
6898
|
+
if ("to" in options && !options.to) refuse("to: empty: an address holds a value");
|
|
6618
6899
|
const address = (field, value) => {
|
|
6619
6900
|
if (value === void 0) return void 0;
|
|
6620
6901
|
try {
|
|
@@ -6644,167 +6925,170 @@ var AnonymousSealsSendResource = class {
|
|
|
6644
6925
|
const ownerBundle = owner ? await bundleOf(owner).catch(() => null) : null;
|
|
6645
6926
|
const seed = options.keyPair ? base64urlToBytes(options.keyPair.secretKey) : null;
|
|
6646
6927
|
const proven = (call) => seed ? withAddressProof(this.api, seed, options.signal, call) : call();
|
|
6647
|
-
const
|
|
6648
|
-
let file;
|
|
6649
|
-
if (options.file instanceof File && options.file.name === options.filename && options.file.type === desiredType) {
|
|
6650
|
-
file = options.file;
|
|
6651
|
-
} else if (options.file instanceof Blob) {
|
|
6652
|
-
file = new File([options.file], options.filename, { type: desiredType });
|
|
6653
|
-
} else if (options.file instanceof Uint8Array) {
|
|
6654
|
-
const buffer = options.file.buffer.slice(
|
|
6655
|
-
options.file.byteOffset,
|
|
6656
|
-
options.file.byteOffset + options.file.byteLength
|
|
6657
|
-
);
|
|
6658
|
-
file = new File([buffer], options.filename, { type: desiredType });
|
|
6659
|
-
} else {
|
|
6660
|
-
file = new File([options.file], options.filename, { type: desiredType });
|
|
6661
|
-
}
|
|
6662
|
-
const ownerTokenBytes = generateOwnerToken();
|
|
6663
|
-
const ownerTokenB64 = bytesToBase64url(ownerTokenBytes);
|
|
6664
|
-
const ownerTokenHash = await hashOwnerToken(ownerTokenBytes);
|
|
6665
|
-
const linkKey = generateLinkKey();
|
|
6666
|
-
const linkKeyB64 = bytesToBase64url(linkKey);
|
|
6928
|
+
const keys = await newKeys();
|
|
6667
6929
|
const ctx = {
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
ttl: options.ttl,
|
|
6671
|
-
ownerTokenHash,
|
|
6672
|
-
ownerToken: ownerTokenB64,
|
|
6673
|
-
...this.credentials !== void 0 ? { credentials: this.credentials } : {},
|
|
6674
|
-
...options.otp !== void 0 ? { otp: options.otp } : {},
|
|
6675
|
-
...options.nda !== void 0 ? { nda: options.nda } : {},
|
|
6676
|
-
...options.nda && options.ownerEmail !== void 0 ? { ownerEmail: options.ownerEmail } : {},
|
|
6677
|
-
...options.singleUse !== void 0 ? { singleUse: options.singleUse } : {},
|
|
6678
|
-
...options.geoAllowlist !== void 0 ? { geo: options.geoAllowlist } : {},
|
|
6679
|
-
...options.maxOpens !== void 0 ? { maxOpens: options.maxOpens } : {},
|
|
6680
|
-
...options.tier !== void 0 ? { tier: options.tier } : {}
|
|
6930
|
+
...createContext(this.baseUrl, createOptions(rules, keys, options.tier)),
|
|
6931
|
+
...this.credentials !== void 0 ? { credentials: this.credentials } : {}
|
|
6681
6932
|
};
|
|
6682
6933
|
let createdSealId = null;
|
|
6683
6934
|
const recovery = (sealId) => ({
|
|
6684
6935
|
sealId,
|
|
6685
|
-
ownerToken: ownerTokenB64,
|
|
6686
|
-
ownerLinkKey: linkKeyB64
|
|
6936
|
+
ownerToken: keys.ownerTokenB64,
|
|
6937
|
+
ownerLinkKey: keys.linkKeyB64
|
|
6687
6938
|
});
|
|
6688
|
-
const blobMessage = options.message?.trim() ? options.message : void 0;
|
|
6689
6939
|
let ownerCopy = false;
|
|
6940
|
+
let ownerCopyRefused = false;
|
|
6941
|
+
let sent = null;
|
|
6942
|
+
const onProgress = options.onProgress;
|
|
6690
6943
|
try {
|
|
6691
|
-
const
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
//
|
|
6696
|
-
//
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6944
|
+
const sealed = await sealFiles({
|
|
6945
|
+
keys,
|
|
6946
|
+
ndaFileName: ndaDocument?.name ?? null,
|
|
6947
|
+
message,
|
|
6948
|
+
// seal.net's calls with this send's signal. The owner copy rides the first write of the owner blob, one
|
|
6949
|
+
// request; a refused address part is the same write without it.
|
|
6950
|
+
api: {
|
|
6951
|
+
writeOwnerBlob: async (id, token, blob) => {
|
|
6952
|
+
if (owner && ownerBundle && !ownerCopyRefused) {
|
|
6953
|
+
const fragment = await wrapTo(keys.linkKey, ownerBundle, OWNER_SCOPE, id);
|
|
6954
|
+
const copied = await proven(
|
|
6955
|
+
(sender) => this.api.writeOwnerBlob(id, token, blob, {
|
|
6956
|
+
...signalOpt,
|
|
6957
|
+
to: owner,
|
|
6958
|
+
fragment,
|
|
6959
|
+
label: "sealnet",
|
|
6960
|
+
...sender ? { sender } : {}
|
|
6961
|
+
})
|
|
6962
|
+
).catch(() => null);
|
|
6963
|
+
if (copied) {
|
|
6964
|
+
ownerCopy = true;
|
|
6965
|
+
return copied;
|
|
6966
|
+
}
|
|
6967
|
+
ownerCopyRefused = true;
|
|
6968
|
+
}
|
|
6969
|
+
return this.api.writeOwnerBlob(id, token, blob, signalOpt);
|
|
6970
|
+
},
|
|
6971
|
+
createShareLink: (id, token, blob, linkKey, opts = {}) => this.api.createShareLink(id, token, blob, linkKey, { ...opts, ...signalOpt })
|
|
6972
|
+
},
|
|
6973
|
+
registered: (id) => {
|
|
6700
6974
|
createdSealId = id;
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
(
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6975
|
+
},
|
|
6976
|
+
upload: async (onRegistered) => {
|
|
6977
|
+
const callbacks = {
|
|
6978
|
+
onRegistered,
|
|
6979
|
+
...onProgress ? {
|
|
6980
|
+
onProgress: (p) => onProgress({
|
|
6981
|
+
phase: p.fileProgress.phase,
|
|
6982
|
+
percent: p.overallPercent,
|
|
6983
|
+
fileIndex: p.fileIndex,
|
|
6984
|
+
totalFiles: p.totalFiles,
|
|
6985
|
+
fileName: p.fileName
|
|
6712
6986
|
})
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6987
|
+
} : {},
|
|
6988
|
+
...signalOpt
|
|
6989
|
+
};
|
|
6990
|
+
let result2;
|
|
6991
|
+
let expiresAt2;
|
|
6718
6992
|
try {
|
|
6719
|
-
|
|
6993
|
+
result2 = relativePaths ? await uploadFolderAsFiles(ctx, files, "", DEFAULT_POLICY, callbacks, relativePaths) : await uploadMultipleFiles(ctx, files, DEFAULT_POLICY, callbacks);
|
|
6994
|
+
expiresAt2 = result2.expiresAt;
|
|
6720
6995
|
} catch (err) {
|
|
6721
|
-
|
|
6996
|
+
const session = paymentRequiredSession(err);
|
|
6997
|
+
if (!session || !options.tier || !options.onPaymentRequired) throw err;
|
|
6998
|
+
await options.onPaymentRequired(
|
|
6999
|
+
await this.api.createCheckout(session.sealId, keys.ownerTokenB64, options.tier, signalOpt)
|
|
7000
|
+
);
|
|
7001
|
+
const deadline = paymentDeadline(session instanceof UploadSession ? session.expiresAt : void 0);
|
|
7002
|
+
const paid = await waitForPayment(this.api, session.sealId, keys.ownerTokenB64, { deadline, ...signalOpt });
|
|
7003
|
+
if (!paid) {
|
|
7004
|
+
await this.api.revoke(session.sealId, keys.ownerTokenB64).catch(() => void 0);
|
|
7005
|
+
throw new SealError(
|
|
7006
|
+
"The seal was not paid in time and was revoked",
|
|
7007
|
+
"PAYMENT_REQUIRED",
|
|
7008
|
+
402,
|
|
7009
|
+
recovery(session.sealId)
|
|
7010
|
+
);
|
|
7011
|
+
}
|
|
7012
|
+
result2 = await session.resume(callbacks);
|
|
7013
|
+
expiresAt2 = paid.expires_at;
|
|
6722
7014
|
}
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
7015
|
+
if (!expiresAt2) {
|
|
7016
|
+
throw new SealError(`Seal ${result2.sealId}: the server sent no expiry`, "INTERNAL_ERROR", 500, recovery(result2.sealId));
|
|
7017
|
+
}
|
|
7018
|
+
sent = { result: result2, expiresAt: expiresAt2 };
|
|
7019
|
+
return {
|
|
7020
|
+
sealId: result2.sealId,
|
|
7021
|
+
encryptionKeys: result2.encryptionKeys,
|
|
7022
|
+
fileResults: result2.files,
|
|
7023
|
+
verification: result2.verification
|
|
7024
|
+
};
|
|
7025
|
+
},
|
|
7026
|
+
// Addressed: the link's key wrapped to the recipient's bundle rides the mint into their inbox, the sender
|
|
7027
|
+
// proven at the mint when there is a seed, by a fresh proof when the server refused the first.
|
|
7028
|
+
...recipient && recipientBundle ? {
|
|
7029
|
+
to: {
|
|
7030
|
+
address: recipient,
|
|
7031
|
+
bundle: recipientBundle,
|
|
7032
|
+
label: "sealnet",
|
|
7033
|
+
...seed ? { sender: (fresh) => addressProof(this.api, seed, { ...signalOpt, fresh }) } : {}
|
|
7034
|
+
}
|
|
7035
|
+
} : {}
|
|
7036
|
+
});
|
|
7037
|
+
const { result, expiresAt } = sent;
|
|
7038
|
+
let shareCode = sealed.shareCode;
|
|
7039
|
+
if (shareCode === null) {
|
|
7040
|
+
try {
|
|
7041
|
+
shareCode = await this.api.createShareLink(
|
|
7042
|
+
sealed.sealId,
|
|
7043
|
+
keys.ownerTokenB64,
|
|
7044
|
+
sealed.share.blobB64,
|
|
7045
|
+
base64urlToBytes(sealed.share.linkKeyB64),
|
|
7046
|
+
signalOpt
|
|
6746
7047
|
);
|
|
7048
|
+
} catch (err) {
|
|
7049
|
+
throw sealErrorFrom(err, "Seal created but share link mint failed", recovery(sealed.sealId));
|
|
6747
7050
|
}
|
|
6748
|
-
result = await session.resume(callbacks);
|
|
6749
|
-
expiresAt = paid.expires_at;
|
|
6750
7051
|
}
|
|
6751
|
-
|
|
6752
|
-
|
|
7052
|
+
const sharePath = buildShareUrl(sealed.sealId, shareCode, sealed.share.linkKeyB64);
|
|
7053
|
+
const shareUrl = `${this.shareUrlBase}${recipient ? sharePath.split("#")[0] : sharePath}`;
|
|
7054
|
+
const ownerUrl = `${this.shareUrlBase}${buildOwnerUrl(sealed.sealId, keys.linkKeyB64)}`;
|
|
7055
|
+
const [first] = result.files;
|
|
7056
|
+
const firstKey = first && result.encryptionKeys.get(first.sha256_hex);
|
|
7057
|
+
if (!first || !firstKey) {
|
|
7058
|
+
throw new SealError(`Seal ${sealed.sealId}: the upload returned no key for its first file`, "INTERNAL_ERROR", 500, recovery(sealed.sealId));
|
|
6753
7059
|
}
|
|
6754
|
-
const
|
|
6755
|
-
fileKeysB64.set(result.sha256_hex, bytesToBase64url(result.encryptionKey));
|
|
6756
|
-
const shareLinkKey = generateLinkKey();
|
|
6757
|
-
const shareLinkKeyB64 = bytesToBase64url(shareLinkKey);
|
|
6758
|
-
const shareBlob = await encryptShareBlob(fileKeysB64, shareLinkKey, blobMessage);
|
|
6759
|
-
const fragment = recipient && recipientBundle ? await wrapTo(shareLinkKey, recipientBundle, SHARE_SCOPE, result.sealId) : null;
|
|
6760
|
-
let shareCode;
|
|
6761
|
-
try {
|
|
6762
|
-
const shareBlobB64 = bytesToBase64url(shareBlob);
|
|
6763
|
-
shareCode = recipient && fragment ? await proven(
|
|
6764
|
-
(sender) => this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, shareLinkKey, {
|
|
6765
|
-
...signalOpt,
|
|
6766
|
-
to: recipient,
|
|
6767
|
-
fragment,
|
|
6768
|
-
label: "sealnet",
|
|
6769
|
-
...sender ? { sender } : {}
|
|
6770
|
-
})
|
|
6771
|
-
) : await this.api.createShareLink(result.sealId, ownerTokenB64, shareBlobB64, shareLinkKey, signalOpt);
|
|
6772
|
-
} catch (err) {
|
|
6773
|
-
throw sealErrorFrom(
|
|
6774
|
-
err,
|
|
6775
|
-
"Seal created but share link mint failed",
|
|
6776
|
-
recovery(result.sealId)
|
|
6777
|
-
);
|
|
6778
|
-
}
|
|
6779
|
-
const sharePath = buildShareUrl(result.sealId, shareCode, shareLinkKeyB64);
|
|
6780
|
-
const shareUrl = `${this.shareUrlBase}${fragment ? sharePath.split("#")[0] : sharePath}`;
|
|
6781
|
-
const ownerUrl = `${this.shareUrlBase}${buildOwnerUrl(result.sealId, linkKeyB64)}`;
|
|
6782
|
-
const keyBase64 = bytesToBase64(result.encryptionKey);
|
|
7060
|
+
const names = relativePaths ?? files.map((f) => f.name);
|
|
6783
7061
|
return {
|
|
6784
|
-
sealId:
|
|
7062
|
+
sealId: sealed.sealId,
|
|
6785
7063
|
shareUrl,
|
|
6786
7064
|
ownerUrl,
|
|
6787
|
-
ownerToken: ownerTokenB64,
|
|
7065
|
+
ownerToken: keys.ownerTokenB64,
|
|
6788
7066
|
// For revoke
|
|
6789
7067
|
expiresAt,
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
7068
|
+
// Standard base64 (not base64url): this is what the SDK has always
|
|
7069
|
+
// returned, and `importKey` accepts either alphabet. The encoder is
|
|
7070
|
+
// the kernel's — chunked, and the only one left in the repository.
|
|
7071
|
+
encryptionKey: bytesToBase64(firstKey),
|
|
7072
|
+
fileId: first.fileId,
|
|
7073
|
+
files: result.files.map((f, i) => ({ fileId: f.fileId, name: names[i] })),
|
|
7074
|
+
delivered: recipient !== void 0,
|
|
6793
7075
|
ownerCopy
|
|
6794
7076
|
};
|
|
6795
7077
|
} catch (err) {
|
|
6796
7078
|
if (err instanceof SealError) throw err;
|
|
6797
|
-
if (createdSealId)
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
"INTERNAL_ERROR",
|
|
6802
|
-
500,
|
|
6803
|
-
recovery(createdSealId),
|
|
6804
|
-
{ cause: err }
|
|
6805
|
-
);
|
|
7079
|
+
if (!createdSealId) throw err;
|
|
7080
|
+
const cause = err instanceof OwnerBlobNotStored ? err.cause : err;
|
|
7081
|
+
if (cause instanceof BackendError) {
|
|
7082
|
+
throw sealErrorFrom(cause, `Seal ${createdSealId} was created but its send did not finish`, recovery(createdSealId));
|
|
6806
7083
|
}
|
|
6807
|
-
|
|
7084
|
+
const said = cause instanceof Error ? cause.message : String(cause);
|
|
7085
|
+
throw new SealError(
|
|
7086
|
+
`Seal ${createdSealId} was created but the create flow was interrupted: ${said}`,
|
|
7087
|
+
"INTERNAL_ERROR",
|
|
7088
|
+
500,
|
|
7089
|
+
recovery(createdSealId),
|
|
7090
|
+
{ cause: err }
|
|
7091
|
+
);
|
|
6808
7092
|
}
|
|
6809
7093
|
}
|
|
6810
7094
|
/**
|
|
@@ -6821,6 +7105,80 @@ var AnonymousSealsSendResource = class {
|
|
|
6821
7105
|
}
|
|
6822
7106
|
}
|
|
6823
7107
|
};
|
|
7108
|
+
function sealRules(options, secretAlone) {
|
|
7109
|
+
if ("otp" in options && !options.otp) refuse("otp: empty: a password holds a value");
|
|
7110
|
+
const maxOpens = options.maxOpens === void 0 ? void 0 : maxOpensOf(String(options.maxOpens));
|
|
7111
|
+
if (maxOpens === null) {
|
|
7112
|
+
refuse(`maxOpens: ${options.maxOpens}: a whole number from 1 to ${LIMITS.MAX_OPENS_PER_SEAL_FREE}`);
|
|
7113
|
+
}
|
|
7114
|
+
const countries = countryCodes((options.geoAllowlist ?? []).join(" "));
|
|
7115
|
+
if (countries.bad.length > 0) {
|
|
7116
|
+
refuse(`geoAllowlist: ${countries.bad.join(", ")}: two-letter country codes such as DE, CH, US`);
|
|
7117
|
+
}
|
|
7118
|
+
if (countries.codes.length > LIMITS.MAX_GEO_COUNTRIES) {
|
|
7119
|
+
refuse(`geoAllowlist: ${countries.codes.length} countries, at most ${LIMITS.MAX_GEO_COUNTRIES}`);
|
|
7120
|
+
}
|
|
7121
|
+
return {
|
|
7122
|
+
ttl: options.ttl ?? (secretAlone ? SECRET_ALONE.ttl : DEFAULT_TTL),
|
|
7123
|
+
otp: options.otp,
|
|
7124
|
+
nda: options.nda,
|
|
7125
|
+
ownerEmail: options.ownerEmail,
|
|
7126
|
+
singleUse: options.singleUse ?? (secretAlone && maxOpens === void 0 ? SECRET_ALONE.singleUse : void 0),
|
|
7127
|
+
maxOpens,
|
|
7128
|
+
geo: countries.codes
|
|
7129
|
+
};
|
|
7130
|
+
}
|
|
7131
|
+
function sealContents(options) {
|
|
7132
|
+
const named = (where, source2, filename) => filename || (source2 instanceof File ? source2.name : "") || refuse(`${where}: bytes need a filename`);
|
|
7133
|
+
const entries = [];
|
|
7134
|
+
if ("secret" in options) {
|
|
7135
|
+
if (options.secret === void 0 || options.secret.length === 0) refuse("secret: empty: a secret holds a value");
|
|
7136
|
+
const value = typeof options.secret === "string" ? new Blob([options.secret]) : options.secret;
|
|
7137
|
+
entries.push({ file: asFile(value, SECRET_NAME, SECRET_MIME), secret: true });
|
|
7138
|
+
}
|
|
7139
|
+
if (options.file !== void 0) {
|
|
7140
|
+
entries.push({ file: asFile(options.file, named("file", options.file, options.filename), options.mimeType), secret: false });
|
|
7141
|
+
}
|
|
7142
|
+
for (const [i, f] of (options.files ?? []).entries()) {
|
|
7143
|
+
const file = asFile(f.file, named(`files[${i}]`, f.file, f.filename), f.secret ? SECRET_MIME : f.mimeType);
|
|
7144
|
+
if (f.secret && file.size === 0) refuse(`files[${i}]: an empty secret`);
|
|
7145
|
+
entries.push({ file, secret: f.secret === true });
|
|
7146
|
+
}
|
|
7147
|
+
for (const [i, f] of (options.folder ?? []).entries()) {
|
|
7148
|
+
const parts = pathParts(f instanceof File ? folderPathOf(f) ?? f.name : f.path);
|
|
7149
|
+
const name2 = parts.at(-1);
|
|
7150
|
+
if (!name2) refuse(`folder[${i}]: a file with no path`);
|
|
7151
|
+
const path = parts.join("/");
|
|
7152
|
+
entries.push(f instanceof File ? { file: f, path, secret: false } : { file: asFile(f.file, name2, f.mimeType), path, secret: false });
|
|
7153
|
+
}
|
|
7154
|
+
let ndaDocument = null;
|
|
7155
|
+
if (options.ndaFile !== void 0) {
|
|
7156
|
+
if (!options.nda) refuse("ndaFile goes with nda: true");
|
|
7157
|
+
const { file, filename, mimeType } = options.ndaFile;
|
|
7158
|
+
ndaDocument = asFile(file, named("ndaFile", file, filename), mimeType);
|
|
7159
|
+
entries.push({ file: ndaDocument, secret: false });
|
|
7160
|
+
}
|
|
7161
|
+
if (entries.length === 0) refuse("Nothing to seal: give file, files, folder or secret");
|
|
7162
|
+
if (entries.length > LIMITS.MAX_FILES_PER_SEAL) {
|
|
7163
|
+
refuse(`A seal holds at most ${LIMITS.MAX_FILES_PER_SEAL} files: ${entries.length} given`);
|
|
7164
|
+
}
|
|
7165
|
+
return {
|
|
7166
|
+
files: entries.map((e) => e.file),
|
|
7167
|
+
relativePaths: entries.some((e) => e.path !== void 0) ? entries.map((e) => e.path ?? e.file.name) : void 0,
|
|
7168
|
+
ndaDocument,
|
|
7169
|
+
secretAlone: entries.length === 1 && entries[0].secret
|
|
7170
|
+
};
|
|
7171
|
+
}
|
|
7172
|
+
function refuse(said) {
|
|
7173
|
+
throw new SealError(said, "VALIDATION_ERROR", 400);
|
|
7174
|
+
}
|
|
7175
|
+
function asFile(source2, name2, type) {
|
|
7176
|
+
const mime = type || source2 instanceof File && source2.type || "application/octet-stream";
|
|
7177
|
+
if (source2 instanceof File && source2.name === name2 && source2.type === mime) return source2;
|
|
7178
|
+
if (source2 instanceof Blob) return new File([source2], name2, { type: mime });
|
|
7179
|
+
const bytes = source2 instanceof Uint8Array ? source2.buffer.slice(source2.byteOffset, source2.byteOffset + source2.byteLength) : source2;
|
|
7180
|
+
return new File([bytes], name2, { type: mime });
|
|
7181
|
+
}
|
|
6824
7182
|
|
|
6825
7183
|
async function receiveToDisk(opened, dir, name2) {
|
|
6826
7184
|
const fs = await import(
|
|
@@ -6902,12 +7260,22 @@ async function resolve(api, url, opts, wrap) {
|
|
|
6902
7260
|
const covered = seal.files.filter((f) => f.key !== null && f.sha256Hex !== null);
|
|
6903
7261
|
const total = covered.reduce((sum, f) => sum + f.size, 0);
|
|
6904
7262
|
let done = 0;
|
|
7263
|
+
const visit = newVisit();
|
|
7264
|
+
let visitOpen = false;
|
|
7265
|
+
let turns = Promise.resolve();
|
|
7266
|
+
const download = (file) => api.downloadCiphertext(seal.sealId, { fileId: file.id, visit, ...sessionCookie ? { sessionCookie } : {} }, request);
|
|
7267
|
+
const answered = (file) => {
|
|
7268
|
+
if (visitOpen) return download(file);
|
|
7269
|
+
const turn = turns.then(async () => {
|
|
7270
|
+
const resp = await download(file);
|
|
7271
|
+
visitOpen = true;
|
|
7272
|
+
return resp;
|
|
7273
|
+
});
|
|
7274
|
+
turns = turn.catch(() => void 0);
|
|
7275
|
+
return turn;
|
|
7276
|
+
};
|
|
6905
7277
|
const read = async (file) => {
|
|
6906
|
-
const resp = await
|
|
6907
|
-
seal.sealId,
|
|
6908
|
-
{ fileId: file.id, ...sessionCookie ? { sessionCookie } : {} },
|
|
6909
|
-
request
|
|
6910
|
-
);
|
|
7278
|
+
const resp = await answered(file);
|
|
6911
7279
|
if (!resp.body) throw new SealError(`Download of ${file.name} returned no body`, "INTERNAL_ERROR", resp.status);
|
|
6912
7280
|
return decryptVerified(resp.body, file.key, file.sha256Hex, (bytes) => {
|
|
6913
7281
|
done += bytes;
|
|
@@ -6939,7 +7307,10 @@ async function saveLink(api, url, dir, opts = {}, wrap = null) {
|
|
|
6939
7307
|
const { seal, covered, read } = await resolve(api, url, opts, wrap);
|
|
6940
7308
|
const files = [];
|
|
6941
7309
|
for (const file of covered) {
|
|
6942
|
-
const
|
|
7310
|
+
const parts = pathParts(file.name).map((part) => sanitizeFilename(part));
|
|
7311
|
+
const name2 = parts.pop() ?? sanitizeFilename(file.name);
|
|
7312
|
+
const into = parts.length > 0 ? [dir || ".", ...parts].join("/") : dir;
|
|
7313
|
+
const saved = await receiveToDisk(await read(file), into, name2);
|
|
6943
7314
|
files.push({ name: file.name, mime: file.mime, secret: file.secret, ...saved });
|
|
6944
7315
|
}
|
|
6945
7316
|
return { sealId: seal.sealId, expiresAt: seal.expiresAt, files };
|
|
@@ -7065,7 +7436,7 @@ async function dismissItem(api, item, opts) {
|
|
|
7065
7436
|
}
|
|
7066
7437
|
|
|
7067
7438
|
// src/index.ts
|
|
7068
|
-
var [CLIENT_NAME = "", CLIENT_VERSION = ""] = "sealnet-js/3.
|
|
7439
|
+
var [CLIENT_NAME = "", CLIENT_VERSION = ""] = "sealnet-js/3.1.1".split("/");
|
|
7069
7440
|
if (typeof globalThis.process?.versions?.node !== "string") {
|
|
7070
7441
|
configureWasm(define_SEAL_WASM_default);
|
|
7071
7442
|
}
|
|
@@ -7081,8 +7452,10 @@ var SealClient = class {
|
|
|
7081
7452
|
this.api = new SealApi({ baseUrl: apiUrl, credentials: "omit" });
|
|
7082
7453
|
}
|
|
7083
7454
|
/**
|
|
7084
|
-
* Encrypt
|
|
7085
|
-
*
|
|
7455
|
+
* Encrypt files client-side — one or several, a folder file by file under
|
|
7456
|
+
* its paths, a secret the recipient's page shows hidden — into one seal,
|
|
7457
|
+
* upload the ciphertext, and return the recipient share link plus the
|
|
7458
|
+
* owner management material. The rules go as seal.net reads and sends them.
|
|
7086
7459
|
*
|
|
7087
7460
|
* `filename` and `mimeType` are what the RECIPIENT sees — they override
|
|
7088
7461
|
* the name and type of a `File` you pass in.
|