sealnet 1.1.2 → 1.2.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 +25 -2
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/dist/index.cjs +274 -15
- package/dist/index.d.cts +48 -10
- package/dist/index.d.ts +48 -10
- package/dist/index.js +274 -15
- package/dist/seal.global.js +2 -2
- package/dist/seal.global.js.sha384 +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2088,9 +2088,60 @@ var limits_default = {
|
|
|
2088
2088
|
INTAKE_TTL_DEFAULT_SECONDS: 900,
|
|
2089
2089
|
INTAKE_TTL_MAX_SECONDS: 86400,
|
|
2090
2090
|
INTAKE_WAIT_MAX_SECONDS: 25,
|
|
2091
|
-
PAYMENT_WAIT_MAX_SECONDS: 82800
|
|
2091
|
+
PAYMENT_WAIT_MAX_SECONDS: 82800,
|
|
2092
|
+
ADDRESS_PROOF_TTL_SECONDS: 300,
|
|
2093
|
+
INBOX_MAX_ITEMS: 200
|
|
2092
2094
|
}
|
|
2093
2095
|
};
|
|
2096
|
+
var seal_address_v1_default = {
|
|
2097
|
+
version: 1,
|
|
2098
|
+
$comment: "Address of a key: who a seal is for, without a URL (audit/SPEC-ADDRESS.md). Numbers live in limits.json, error codes in error_codes.json.",
|
|
2099
|
+
address: {
|
|
2100
|
+
key: "X25519 public key, 32 bytes",
|
|
2101
|
+
text: "base64url without padding, 43 characters",
|
|
2102
|
+
emoji: "fingerprint_emoji.json over sha256(key)[0..3], the same picture as intake",
|
|
2103
|
+
inbox_hash: "sha256(key), 32 bytes: the server finds an inbox by it"
|
|
2104
|
+
},
|
|
2105
|
+
seed: {
|
|
2106
|
+
env: "SEAL_SEED",
|
|
2107
|
+
text: "base64url without padding of the 32-byte X25519 secret, 43 characters",
|
|
2108
|
+
same_as: [
|
|
2109
|
+
"sealnet-mcp state.identity.x25519_secret_b64",
|
|
2110
|
+
"seal identity.v1.json x25519_secret_b64url",
|
|
2111
|
+
"sealnet (npm) KeyPair.secretKey",
|
|
2112
|
+
"sealnet (PyPI) keygen().secret_key"
|
|
2113
|
+
]
|
|
2114
|
+
},
|
|
2115
|
+
scopes: {
|
|
2116
|
+
share_link: "seal_share",
|
|
2117
|
+
owner_copy: "seal_owner",
|
|
2118
|
+
address_proof: "seal_address_proof"
|
|
2119
|
+
},
|
|
2120
|
+
proof: {
|
|
2121
|
+
header_address: "X-Seal-Address",
|
|
2122
|
+
header_proof: "X-Seal-Proof",
|
|
2123
|
+
proof_text: "<ts>.<token>: ts is the decimal Unix second from the challenge, token base64url of 32 bytes",
|
|
2124
|
+
challenge: "sealed box of the 32-byte token to the address with scope (address_proof, decimal ts): ephemeral_pub(32) || nonce(12) || ciphertext(48), base64url, 123 characters",
|
|
2125
|
+
token: "opaque to clients: unwrap it and send it back"
|
|
2126
|
+
},
|
|
2127
|
+
items: {
|
|
2128
|
+
delivery: {
|
|
2129
|
+
id: "s.<seal_id>.<share_code>",
|
|
2130
|
+
is: "a share link addressed to this key; fragment = its key wrapped to the address (x25519:, targeted_x25519_v1, scope share_link)"
|
|
2131
|
+
}
|
|
2132
|
+
},
|
|
2133
|
+
request_kinds: ["secret", "file", "any"],
|
|
2134
|
+
vectors: [
|
|
2135
|
+
{
|
|
2136
|
+
comment: "generated once by backend_crypto.sealed_box.seal_key_for_recipient; every client must unwrap it",
|
|
2137
|
+
secret: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc",
|
|
2138
|
+
address: "E75P6uryBMf9M1j8nAByGIHRdCeBKCJ-xnTzf3_pe20",
|
|
2139
|
+
ts: 179e7,
|
|
2140
|
+
challenge: "4Oel-UMfgP_1dBhmf13yZiujhPDouCIQ6sSx1nY1qy-vyzFqDqb9jARbJ0e5A8vv4EDELDS5OPqBQMcsmDA-C_lXO95y_CVUyYtSu-1fltsy5ZihOFDp0T-C9Ro",
|
|
2141
|
+
token: "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8"
|
|
2142
|
+
}
|
|
2143
|
+
]
|
|
2144
|
+
};
|
|
2094
2145
|
var upload_default = {
|
|
2095
2146
|
version: 1,
|
|
2096
2147
|
upload: {
|
|
@@ -2422,13 +2473,24 @@ var SealApi = class _SealApi {
|
|
|
2422
2473
|
});
|
|
2423
2474
|
return { etag: resp.headers.get("ETag") };
|
|
2424
2475
|
}
|
|
2425
|
-
/**
|
|
2476
|
+
/**
|
|
2477
|
+
* `POST /seal/{id}/share` — mint a share link, returns its code. With an
|
|
2478
|
+
* address the link also lands in that key's inbox, in the same request.
|
|
2479
|
+
*/
|
|
2426
2480
|
async createShareLink(sealId, ownerToken, encryptedBlobB64, opts = {}) {
|
|
2481
|
+
const headers = _SealApi.ownerHeaders(ownerToken, true);
|
|
2482
|
+
const body = { encrypted_blob: encryptedBlobB64 };
|
|
2483
|
+
if ("to" in opts) {
|
|
2484
|
+
body.to = opts.to;
|
|
2485
|
+
body.fragment = opts.fragment;
|
|
2486
|
+
if (opts.label) body.label = opts.label;
|
|
2487
|
+
if (opts.sender) Object.assign(headers, proofHeaders(opts.sender));
|
|
2488
|
+
}
|
|
2427
2489
|
const resp = await this.request(`/seal/${encode(sealId)}/share`, {
|
|
2428
2490
|
what: `POST /seal/${sealId}/share`,
|
|
2429
2491
|
method: "POST",
|
|
2430
|
-
headers
|
|
2431
|
-
body: JSON.stringify(
|
|
2492
|
+
headers,
|
|
2493
|
+
body: JSON.stringify(body),
|
|
2432
2494
|
signal: opts.signal
|
|
2433
2495
|
});
|
|
2434
2496
|
const data = await resp.json();
|
|
@@ -2611,8 +2673,57 @@ var SealApi = class _SealApi {
|
|
|
2611
2673
|
});
|
|
2612
2674
|
return await resp.json();
|
|
2613
2675
|
}
|
|
2676
|
+
// ---------------------------------------------------------------------------
|
|
2677
|
+
// Inbox (SPEC-ADDRESS F2): the share links addressed to a key
|
|
2678
|
+
// ---------------------------------------------------------------------------
|
|
2679
|
+
/** `POST /intake/proof` — a challenge sealed to `address`. */
|
|
2680
|
+
async requestAddressProof(address, opts = {}) {
|
|
2681
|
+
const resp = await this.request("/intake/proof", {
|
|
2682
|
+
what: "POST /intake/proof",
|
|
2683
|
+
method: "POST",
|
|
2684
|
+
headers: { "Content-Type": "application/json" },
|
|
2685
|
+
body: JSON.stringify({ address }),
|
|
2686
|
+
signal: opts.signal
|
|
2687
|
+
});
|
|
2688
|
+
return await resp.json();
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* `GET /intake?to=` — every live item. `waitSeconds` holds the answer
|
|
2692
|
+
* while the inbox is empty, or, with `seen`, while its version is still
|
|
2693
|
+
* `seen`; one call waits at most `INTAKE_WAIT_MAX_SECONDS`, longer waits
|
|
2694
|
+
* are the caller's loop.
|
|
2695
|
+
*/
|
|
2696
|
+
async listInbox(proof, opts = {}) {
|
|
2697
|
+
const params = new URLSearchParams({ to: proof.address });
|
|
2698
|
+
if (opts.waitSeconds) {
|
|
2699
|
+
params.set("wait", String(Math.min(opts.waitSeconds, limits_default.limits.INTAKE_WAIT_MAX_SECONDS)));
|
|
2700
|
+
}
|
|
2701
|
+
if (opts.seen) params.set("seen", opts.seen);
|
|
2702
|
+
const resp = await this.request(`/intake?${params.toString()}`, {
|
|
2703
|
+
what: "GET /intake",
|
|
2704
|
+
headers: proofHeaders(proof),
|
|
2705
|
+
signal: opts.signal
|
|
2706
|
+
});
|
|
2707
|
+
return await resp.json();
|
|
2708
|
+
}
|
|
2709
|
+
/** `DELETE /intake?to=&item=` — take one item out; the link keeps working. */
|
|
2710
|
+
async dismissInboxItem(itemId, proof, opts = {}) {
|
|
2711
|
+
const params = new URLSearchParams({ to: proof.address, item: itemId });
|
|
2712
|
+
await this.request(`/intake?${params.toString()}`, {
|
|
2713
|
+
what: "DELETE /intake",
|
|
2714
|
+
method: "DELETE",
|
|
2715
|
+
headers: proofHeaders(proof),
|
|
2716
|
+
signal: opts.signal
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2614
2719
|
};
|
|
2615
2720
|
var NOT_READY_DEFAULT_RETRY_AFTER_S = 3;
|
|
2721
|
+
function proofHeaders(proof) {
|
|
2722
|
+
return {
|
|
2723
|
+
[seal_address_v1_default.proof.header_address]: proof.address,
|
|
2724
|
+
[seal_address_v1_default.proof.header_proof]: proof.proof
|
|
2725
|
+
};
|
|
2726
|
+
}
|
|
2616
2727
|
function abortableSleep(ms, signal) {
|
|
2617
2728
|
return new Promise((resolve2, reject) => {
|
|
2618
2729
|
if (signal?.aborted) {
|
|
@@ -5171,10 +5282,29 @@ function parseUrlType(pathname) {
|
|
|
5171
5282
|
var TARGETED_PREFIX_V1 = "x25519:";
|
|
5172
5283
|
var TARGETED_PREFIX_V2_RESERVED = "x25519v2:";
|
|
5173
5284
|
var SCOPE_TYPE = "seal_share";
|
|
5285
|
+
var ADDRESS_PROOF_SCOPE = "seal_address_proof";
|
|
5174
5286
|
var X25519_KEY_BYTES = 32;
|
|
5175
5287
|
var LINK_KEY_BYTES2 = 32;
|
|
5176
5288
|
var PACKED_BYTES_V1 = 92;
|
|
5177
5289
|
var B64URL = /^[A-Za-z0-9_-]+$/;
|
|
5290
|
+
function parseRecipientPubkey(raw) {
|
|
5291
|
+
const trimmed = raw.trim().replace(/=+$/, "");
|
|
5292
|
+
if (trimmed.length !== 43) {
|
|
5293
|
+
throw new Error(
|
|
5294
|
+
`expected 43-character urlsafe-base64-no-pad encoding of an X25519 public key (32 bytes), got ${trimmed.length} characters`
|
|
5295
|
+
);
|
|
5296
|
+
}
|
|
5297
|
+
if (!B64URL.test(trimmed)) {
|
|
5298
|
+
throw new Error(
|
|
5299
|
+
"not valid urlsafe-base64-no-pad: contains characters outside [A-Za-z0-9_-] (standard-base64 input is rejected \u2014 copy the exact string from `seal keygen` output)"
|
|
5300
|
+
);
|
|
5301
|
+
}
|
|
5302
|
+
const bytes = base64urlToBytes(trimmed);
|
|
5303
|
+
if (bytes.length !== X25519_KEY_BYTES) {
|
|
5304
|
+
throw new Error(`decoded to ${bytes.length} bytes, expected ${X25519_KEY_BYTES} (X25519 public key length)`);
|
|
5305
|
+
}
|
|
5306
|
+
return bytes;
|
|
5307
|
+
}
|
|
5178
5308
|
async function generateRecipientKeyPair() {
|
|
5179
5309
|
const wasm3 = await ensureWasm();
|
|
5180
5310
|
const secretKey = wasm3.wasm_x25519_static_from_seed(crypto.getRandomValues(new Uint8Array(X25519_KEY_BYTES)));
|
|
@@ -5187,6 +5317,21 @@ async function recipientPublicKey(secretKey) {
|
|
|
5187
5317
|
const wasm3 = await ensureWasm();
|
|
5188
5318
|
return wasm3.wasm_x25519_public_from_secret(secretKey);
|
|
5189
5319
|
}
|
|
5320
|
+
async function buildTargetedFragment(linkKey, recipientPub, sealId) {
|
|
5321
|
+
if (linkKey.length !== LINK_KEY_BYTES2) throw new Error(`linkKey length ${linkKey.length} \u2260 ${LINK_KEY_BYTES2}`);
|
|
5322
|
+
if (recipientPub.length !== X25519_KEY_BYTES) {
|
|
5323
|
+
throw new Error(`recipientPub length ${recipientPub.length} \u2260 ${X25519_KEY_BYTES}`);
|
|
5324
|
+
}
|
|
5325
|
+
if (sealId.length === 0) throw new Error("sealId must not be empty (AEAD binds to it via HKDF info)");
|
|
5326
|
+
const wasm3 = await ensureWasm();
|
|
5327
|
+
const packed = wasm3.wasm_sealbox_wrap(linkKey, recipientPub, SCOPE_TYPE, sealId);
|
|
5328
|
+
if (packed.length !== PACKED_BYTES_V1) {
|
|
5329
|
+
throw new Error(
|
|
5330
|
+
`wasm_sealbox_wrap returned ${packed.length} bytes \u2014 expected ${PACKED_BYTES_V1} for v1. GRANT_VERSION may have been bumped without minting a new "${TARGETED_PREFIX_V1}" prefix.`
|
|
5331
|
+
);
|
|
5332
|
+
}
|
|
5333
|
+
return `${TARGETED_PREFIX_V1}${bytesToBase64url(packed)}`;
|
|
5334
|
+
}
|
|
5190
5335
|
var TargetedUnwrapError = class extends Error {
|
|
5191
5336
|
constructor(kind, message, cause) {
|
|
5192
5337
|
super(message);
|
|
@@ -5244,6 +5389,11 @@ async function unwrapTargetedFragment(fragment, recipientSecret, sealId) {
|
|
|
5244
5389
|
}
|
|
5245
5390
|
return linkKey;
|
|
5246
5391
|
}
|
|
5392
|
+
async function proveAddress(secret, challenge, ts) {
|
|
5393
|
+
const wasm3 = await ensureWasm();
|
|
5394
|
+
const token = wasm3.wasm_sealbox_unwrap(base64urlToBytes(challenge), secret, ADDRESS_PROOF_SCOPE, String(ts));
|
|
5395
|
+
return `${ts}.${bytesToBase64url(token)}`;
|
|
5396
|
+
}
|
|
5247
5397
|
var fingerprint_emoji_default = {
|
|
5248
5398
|
version: 1,
|
|
5249
5399
|
name: "FINGERPRINT_EMOJI",
|
|
@@ -5703,6 +5853,36 @@ async function waitForIntake(api, intakeId, opts = {}) {
|
|
|
5703
5853
|
if (view.status === "fulfilled" && view.share_path) return view.share_path;
|
|
5704
5854
|
}
|
|
5705
5855
|
}
|
|
5856
|
+
var PROOF_MARGIN_MS = 3e4;
|
|
5857
|
+
var proofs = /* @__PURE__ */ new Map();
|
|
5858
|
+
async function addressProof(api, secret, opts = {}) {
|
|
5859
|
+
const address = bytesToBase64url(await recipientPublicKey(secret));
|
|
5860
|
+
const key = `${api.baseUrl} ${address}`;
|
|
5861
|
+
const kept = proofs.get(key);
|
|
5862
|
+
if (!opts.fresh && kept && kept.until > Date.now()) return kept.proof;
|
|
5863
|
+
const challenge = await api.requestAddressProof(address, opts);
|
|
5864
|
+
const proof = { address, proof: await proveAddress(secret, challenge.challenge, challenge.ts) };
|
|
5865
|
+
proofs.set(key, { proof, until: Date.parse(challenge.expires_at) - PROOF_MARGIN_MS });
|
|
5866
|
+
return proof;
|
|
5867
|
+
}
|
|
5868
|
+
async function withAddressProof(api, secret, signal, call) {
|
|
5869
|
+
const request = signal ? { signal } : {};
|
|
5870
|
+
try {
|
|
5871
|
+
return await call(await addressProof(api, secret, request));
|
|
5872
|
+
} catch (err) {
|
|
5873
|
+
if (!(err instanceof BackendError && err.appCode === "intake.proof_required")) throw err;
|
|
5874
|
+
return call(await addressProof(api, secret, { ...request, fresh: true }));
|
|
5875
|
+
}
|
|
5876
|
+
}
|
|
5877
|
+
async function readInbox(api, secret, opts = {}) {
|
|
5878
|
+
return withAddressProof(api, secret, opts.signal, (proof) => api.listInbox(proof, opts));
|
|
5879
|
+
}
|
|
5880
|
+
async function removeFromInbox(api, secret, itemId, opts = {}) {
|
|
5881
|
+
return withAddressProof(api, secret, opts.signal, (proof) => api.dismissInboxItem(itemId, proof, opts));
|
|
5882
|
+
}
|
|
5883
|
+
function inboxItemUrl(site, item) {
|
|
5884
|
+
return `${site.replace(/\/+$/, "")}${item.path}#${item.fragment}`;
|
|
5885
|
+
}
|
|
5706
5886
|
async function describeFile(file, fileKeys) {
|
|
5707
5887
|
const keyB64 = file.sha256_hex ? fileKeys[file.sha256_hex] : void 0;
|
|
5708
5888
|
const base = { id: file.id, size: file.size, sha256Hex: file.sha256_hex };
|
|
@@ -5844,7 +6024,7 @@ function sealErrorFrom(err, fallbackMessage, details = null) {
|
|
|
5844
6024
|
return new SealError(err.message, OPEN_CODES[err.code], status, { ...details, reason: err.code }, { cause: err });
|
|
5845
6025
|
}
|
|
5846
6026
|
if (err instanceof BackendError) {
|
|
5847
|
-
const code = err.code === "not_found" || err.code === "revoked" ? "RESOURCE_NOT_FOUND" : err.code === "auth" ? "AUTH_INSUFFICIENT_SCOPE" : err.code === "rate_limited" ? "RATE_LIMITED" : err.code === "transient" ? "SERVICE_UNAVAILABLE" : "INTERNAL_ERROR";
|
|
6027
|
+
const code = err.appCode === "intake.proof_required" ? "AUTH_INVALID_KEY" : err.code === "not_found" || err.code === "revoked" ? "RESOURCE_NOT_FOUND" : err.code === "auth" ? "AUTH_INSUFFICIENT_SCOPE" : err.code === "rate_limited" ? "RATE_LIMITED" : err.code === "transient" ? "SERVICE_UNAVAILABLE" : "INTERNAL_ERROR";
|
|
5848
6028
|
return new SealError(err.detail ?? fallbackMessage, code, err.status, details, { cause: err });
|
|
5849
6029
|
}
|
|
5850
6030
|
return new SealError(
|
|
@@ -5921,6 +6101,14 @@ var AnonymousSealsSendResource = class {
|
|
|
5921
6101
|
if (options.tier && !options.onPaymentRequired) {
|
|
5922
6102
|
throw new SealError("onPaymentRequired is required with tier", "VALIDATION_ERROR", 400);
|
|
5923
6103
|
}
|
|
6104
|
+
let recipient;
|
|
6105
|
+
if (options.to !== void 0) {
|
|
6106
|
+
try {
|
|
6107
|
+
recipient = parseRecipientPubkey(options.to);
|
|
6108
|
+
} catch (err) {
|
|
6109
|
+
throw new SealError(`to: ${err instanceof Error ? err.message : String(err)}`, "VALIDATION_ERROR", 400);
|
|
6110
|
+
}
|
|
6111
|
+
}
|
|
5924
6112
|
const desiredType = options.mimeType || options.file instanceof File && options.file.type || "application/octet-stream";
|
|
5925
6113
|
let file;
|
|
5926
6114
|
if (options.file instanceof File && options.file.name === options.filename && options.file.type === desiredType) {
|
|
@@ -6015,14 +6203,13 @@ var AnonymousSealsSendResource = class {
|
|
|
6015
6203
|
const shareLinkKey = generateLinkKey();
|
|
6016
6204
|
const shareLinkKeyB64 = bytesToBase64url(shareLinkKey);
|
|
6017
6205
|
const shareBlob = await encryptShareBlob(fileKeysB64, shareLinkKey, blobMessage);
|
|
6206
|
+
const fragment = recipient ? await buildTargetedFragment(shareLinkKey, recipient, result.sealId) : null;
|
|
6018
6207
|
let shareCode;
|
|
6019
6208
|
try {
|
|
6020
|
-
shareCode = await this.api.createShareLink(
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
options.signal ? { signal: options.signal } : {}
|
|
6025
|
-
);
|
|
6209
|
+
shareCode = await this.api.createShareLink(result.sealId, ownerTokenB64, bytesToBase64url(shareBlob), {
|
|
6210
|
+
...options.signal ? { signal: options.signal } : {},
|
|
6211
|
+
...recipient && fragment ? { to: bytesToBase64url(recipient), fragment, label: "sealnet" } : {}
|
|
6212
|
+
});
|
|
6026
6213
|
} catch (err) {
|
|
6027
6214
|
throw sealErrorFrom(
|
|
6028
6215
|
err,
|
|
@@ -6030,7 +6217,8 @@ var AnonymousSealsSendResource = class {
|
|
|
6030
6217
|
recovery(result.sealId)
|
|
6031
6218
|
);
|
|
6032
6219
|
}
|
|
6033
|
-
const
|
|
6220
|
+
const sharePath = buildShareUrl(result.sealId, shareCode, shareLinkKeyB64);
|
|
6221
|
+
const shareUrl = `${this.shareUrlBase}${fragment ? sharePath.replace(/#.*$/, `#${fragment}`) : sharePath}`;
|
|
6034
6222
|
const ownerUrl = `${this.shareUrlBase}${buildOwnerUrl(result.sealId, linkKeyB64)}`;
|
|
6035
6223
|
const keyBase64 = bytesToBase64(result.encryptionKey);
|
|
6036
6224
|
return {
|
|
@@ -6045,7 +6233,8 @@ var AnonymousSealsSendResource = class {
|
|
|
6045
6233
|
// `now + ttl` as the seal's expiry states something we do not know.
|
|
6046
6234
|
expiresAt: expiresAt ?? new Date(Date.now() + this.ttlToMs(options.ttl)).toISOString(),
|
|
6047
6235
|
encryptionKey: keyBase64,
|
|
6048
|
-
fileId: result.fileId
|
|
6236
|
+
fileId: result.fileId,
|
|
6237
|
+
delivered: fragment !== null
|
|
6049
6238
|
};
|
|
6050
6239
|
} catch (err) {
|
|
6051
6240
|
if (err instanceof SealError) throw err;
|
|
@@ -6243,6 +6432,55 @@ async function keygen() {
|
|
|
6243
6432
|
const { publicKey, secretKey } = await generateRecipientKeyPair();
|
|
6244
6433
|
return { publicKey: bytesToBase64url(publicKey), secretKey: bytesToBase64url(secretKey) };
|
|
6245
6434
|
}
|
|
6435
|
+
async function inboxOf(api, opts) {
|
|
6436
|
+
const secret = base64urlToBytes(opts.keyPair.secretKey);
|
|
6437
|
+
const deadline = Date.now() + (opts.wait ?? 0) * 1e3;
|
|
6438
|
+
try {
|
|
6439
|
+
for (; ; ) {
|
|
6440
|
+
const left = Math.ceil((deadline - Date.now()) / 1e3);
|
|
6441
|
+
const wire = await readInbox(api, secret, {
|
|
6442
|
+
...left > 0 ? { waitSeconds: left } : {},
|
|
6443
|
+
...opts.seen !== void 0 ? { seen: opts.seen } : {},
|
|
6444
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
6445
|
+
});
|
|
6446
|
+
const due = opts.seen !== void 0 ? wire.version !== opts.seen : wire.items.length > 0;
|
|
6447
|
+
if (due || Date.now() >= deadline) {
|
|
6448
|
+
return {
|
|
6449
|
+
version: wire.version,
|
|
6450
|
+
items: wire.items.map((i) => ({
|
|
6451
|
+
id: i.id,
|
|
6452
|
+
from: i.sender === null ? null : keyEmoji(base64urlToBytes(i.sender)),
|
|
6453
|
+
label: i.label,
|
|
6454
|
+
receivedAt: i.at,
|
|
6455
|
+
expiresAt: i.expires_at
|
|
6456
|
+
}))
|
|
6457
|
+
};
|
|
6458
|
+
}
|
|
6459
|
+
}
|
|
6460
|
+
} catch (err) {
|
|
6461
|
+
throw sealErrorFrom(err, "Failed to read the inbox");
|
|
6462
|
+
}
|
|
6463
|
+
}
|
|
6464
|
+
async function inboxLink(api, site, item, opts) {
|
|
6465
|
+
let wire;
|
|
6466
|
+
try {
|
|
6467
|
+
wire = await readInbox(api, base64urlToBytes(opts.keyPair.secretKey), opts.signal ? { signal: opts.signal } : {});
|
|
6468
|
+
} catch (err) {
|
|
6469
|
+
throw sealErrorFrom(err, "Failed to read the inbox");
|
|
6470
|
+
}
|
|
6471
|
+
const row = wire.items.find((i) => i.id === item.id);
|
|
6472
|
+
if (!row) {
|
|
6473
|
+
throw new SealError(`${item.id} is not in the inbox: it was revoked, expired or removed`, "RESOURCE_NOT_FOUND", 404);
|
|
6474
|
+
}
|
|
6475
|
+
return inboxItemUrl(site, row);
|
|
6476
|
+
}
|
|
6477
|
+
async function dismissItem(api, item, opts) {
|
|
6478
|
+
try {
|
|
6479
|
+
await removeFromInbox(api, base64urlToBytes(opts.keyPair.secretKey), item.id, opts.signal ? { signal: opts.signal } : {});
|
|
6480
|
+
} catch (err) {
|
|
6481
|
+
throw sealErrorFrom(err, "Failed to remove the item");
|
|
6482
|
+
}
|
|
6483
|
+
}
|
|
6246
6484
|
|
|
6247
6485
|
// src/index.ts
|
|
6248
6486
|
var SealClient = class {
|
|
@@ -6265,10 +6503,31 @@ var SealClient = class {
|
|
|
6265
6503
|
async send(options) {
|
|
6266
6504
|
return this.seals.create(options);
|
|
6267
6505
|
}
|
|
6268
|
-
async open(
|
|
6506
|
+
async open(link, options = {}) {
|
|
6269
6507
|
const { to, ...rest } = options;
|
|
6508
|
+
let url;
|
|
6509
|
+
if (typeof link === "string") {
|
|
6510
|
+
url = link;
|
|
6511
|
+
} else if (rest.keyPair) {
|
|
6512
|
+
url = await inboxLink(this.api, this.site, link, { keyPair: rest.keyPair, ...rest.signal ? { signal: rest.signal } : {} });
|
|
6513
|
+
} else {
|
|
6514
|
+
throw new SealError("An inbox item opens with the key it was sent to: pass `keyPair`", "VALIDATION_ERROR", 400);
|
|
6515
|
+
}
|
|
6270
6516
|
return to !== void 0 ? saveLink(this.api, url, to, rest) : openLink(this.api, url, rest);
|
|
6271
6517
|
}
|
|
6518
|
+
/**
|
|
6519
|
+
* What other agents or people sent to your key (your address,
|
|
6520
|
+
* `keyPair.publicKey`); `send({to})` puts a link there. `wait` seconds
|
|
6521
|
+
* holds the answer while the inbox is empty, or with `seen` (an earlier
|
|
6522
|
+
* `version`) until it changes.
|
|
6523
|
+
*/
|
|
6524
|
+
async inbox(options) {
|
|
6525
|
+
return inboxOf(this.api, options);
|
|
6526
|
+
}
|
|
6527
|
+
/** Take an item out of your inbox; its link keeps working for whoever holds it. */
|
|
6528
|
+
async dismiss(item, options) {
|
|
6529
|
+
return dismissItem(this.api, item, options);
|
|
6530
|
+
}
|
|
6272
6531
|
/**
|
|
6273
6532
|
* Ask a person for a file or a secret without it passing through a chat:
|
|
6274
6533
|
* show them `url` (or hand it to an MCP client as a URL-mode elicitation)
|
|
@@ -6294,7 +6553,7 @@ var SealClient = class {
|
|
|
6294
6553
|
return this.seals.revoke(sealId, ownerToken, options);
|
|
6295
6554
|
}
|
|
6296
6555
|
};
|
|
6297
|
-
var VERSION = "1.
|
|
6556
|
+
var VERSION = "1.2.0";
|
|
6298
6557
|
export {
|
|
6299
6558
|
SealClient,
|
|
6300
6559
|
SealError,
|