@tinycloud/cli 1.0.1-beta.4 → 1.1.0-beta.6
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/dist/index.js +2091 -1800
- package/dist/index.js.map +1 -1
- package/dist/legacy-entry.js +1682 -262
- package/dist/legacy-entry.js.map +1 -1
- package/package.json +5 -5
- package/skills/tc-cli/REFERENCE.md +14 -6
- package/skills/tc-cli/SKILL.md +5 -1
package/dist/legacy-entry.js
CHANGED
|
@@ -14,11 +14,11 @@ var __export = (target, all) => {
|
|
|
14
14
|
for (var name in all)
|
|
15
15
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
16
|
};
|
|
17
|
-
var __copyProps = (to,
|
|
18
|
-
if (
|
|
19
|
-
for (let key of __getOwnPropNames(
|
|
17
|
+
var __copyProps = (to, from4, except, desc) => {
|
|
18
|
+
if (from4 && typeof from4 === "object" || typeof from4 === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from4))
|
|
20
20
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
-
__defProp(to, key, { get: () =>
|
|
21
|
+
__defProp(to, key, { get: () => from4[key], enumerable: !(desc = __getOwnPropDesc(from4, key)) || desc.enumerable });
|
|
22
22
|
}
|
|
23
23
|
return to;
|
|
24
24
|
};
|
|
@@ -163,10 +163,10 @@ import ora from "ora";
|
|
|
163
163
|
function outputJson(data) {
|
|
164
164
|
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
165
165
|
}
|
|
166
|
-
function outputError(
|
|
166
|
+
function outputError(code3, message, hint) {
|
|
167
167
|
if (isInteractive()) {
|
|
168
168
|
process.stderr.write(
|
|
169
|
-
`${theme.error("\u2717")} ${theme.label(
|
|
169
|
+
`${theme.error("\u2717")} ${theme.label(code3)}: ${message}
|
|
170
170
|
`
|
|
171
171
|
);
|
|
172
172
|
if (hint) {
|
|
@@ -177,7 +177,7 @@ function outputError(code2, message, hint) {
|
|
|
177
177
|
}
|
|
178
178
|
} else {
|
|
179
179
|
const payload = {
|
|
180
|
-
error: { code:
|
|
180
|
+
error: { code: code3, message }
|
|
181
181
|
};
|
|
182
182
|
if (hint) payload.error.hint = hint;
|
|
183
183
|
process.stderr.write(JSON.stringify(payload, null, 2) + "\n");
|
|
@@ -380,9 +380,9 @@ var init_errors = __esm({
|
|
|
380
380
|
init_constants();
|
|
381
381
|
init_formatter();
|
|
382
382
|
CLIError = class extends Error {
|
|
383
|
-
constructor(
|
|
383
|
+
constructor(code3, message, exitCode = ExitCode.ERROR, metadata) {
|
|
384
384
|
super(message);
|
|
385
|
-
this.code =
|
|
385
|
+
this.code = code3;
|
|
386
386
|
this.exitCode = exitCode;
|
|
387
387
|
this.metadata = metadata;
|
|
388
388
|
this.name = "CLIError";
|
|
@@ -1325,12 +1325,12 @@ var init_md = __esm({
|
|
|
1325
1325
|
_cloneInto(to) {
|
|
1326
1326
|
to || (to = new this.constructor());
|
|
1327
1327
|
to.set(...this.get());
|
|
1328
|
-
const { blockLen, buffer, length:
|
|
1328
|
+
const { blockLen, buffer, length: length4, finished, destroyed, pos } = this;
|
|
1329
1329
|
to.destroyed = destroyed;
|
|
1330
1330
|
to.finished = finished;
|
|
1331
|
-
to.length =
|
|
1331
|
+
to.length = length4;
|
|
1332
1332
|
to.pos = pos;
|
|
1333
|
-
if (
|
|
1333
|
+
if (length4 % blockLen)
|
|
1334
1334
|
to.buffer.set(buffer);
|
|
1335
1335
|
return to;
|
|
1336
1336
|
}
|
|
@@ -1728,11 +1728,11 @@ var require_decrypt_transport_response_error = __commonJS({
|
|
|
1728
1728
|
for (var name in all)
|
|
1729
1729
|
__defProp3(target, name, { get: all[name], enumerable: true });
|
|
1730
1730
|
};
|
|
1731
|
-
var __copyProps2 = (to,
|
|
1732
|
-
if (
|
|
1733
|
-
for (let key of __getOwnPropNames2(
|
|
1731
|
+
var __copyProps2 = (to, from4, except, desc) => {
|
|
1732
|
+
if (from4 && typeof from4 === "object" || typeof from4 === "function") {
|
|
1733
|
+
for (let key of __getOwnPropNames2(from4))
|
|
1734
1734
|
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
1735
|
-
__defProp3(to, key, { get: () =>
|
|
1735
|
+
__defProp3(to, key, { get: () => from4[key], enumerable: !(desc = __getOwnPropDesc2(from4, key)) || desc.enumerable });
|
|
1736
1736
|
}
|
|
1737
1737
|
return to;
|
|
1738
1738
|
};
|
|
@@ -3322,8 +3322,8 @@ function isValidJWT(jwt, alg) {
|
|
|
3322
3322
|
const [header] = jwt.split(".");
|
|
3323
3323
|
if (!header)
|
|
3324
3324
|
return false;
|
|
3325
|
-
const
|
|
3326
|
-
const decoded = JSON.parse(atob(
|
|
3325
|
+
const base643 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
3326
|
+
const decoded = JSON.parse(atob(base643));
|
|
3327
3327
|
if (typeof decoded !== "object" || decoded === null)
|
|
3328
3328
|
return false;
|
|
3329
3329
|
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
@@ -5977,23 +5977,23 @@ var ZodEffects = class extends ZodType {
|
|
|
5977
5977
|
}
|
|
5978
5978
|
if (effect.type === "transform") {
|
|
5979
5979
|
if (ctx.common.async === false) {
|
|
5980
|
-
const
|
|
5980
|
+
const base4 = this._def.schema._parseSync({
|
|
5981
5981
|
data: ctx.data,
|
|
5982
5982
|
path: ctx.path,
|
|
5983
5983
|
parent: ctx
|
|
5984
5984
|
});
|
|
5985
|
-
if (!isValid(
|
|
5985
|
+
if (!isValid(base4))
|
|
5986
5986
|
return INVALID;
|
|
5987
|
-
const result = effect.transform(
|
|
5987
|
+
const result = effect.transform(base4.value, checkCtx);
|
|
5988
5988
|
if (result instanceof Promise) {
|
|
5989
5989
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
5990
5990
|
}
|
|
5991
5991
|
return { status: status.value, value: result };
|
|
5992
5992
|
} else {
|
|
5993
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((
|
|
5994
|
-
if (!isValid(
|
|
5993
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base4) => {
|
|
5994
|
+
if (!isValid(base4))
|
|
5995
5995
|
return INVALID;
|
|
5996
|
-
return Promise.resolve(effect.transform(
|
|
5996
|
+
return Promise.resolve(effect.transform(base4.value, checkCtx)).then((result) => ({
|
|
5997
5997
|
status: status.value,
|
|
5998
5998
|
value: result
|
|
5999
5999
|
}));
|
|
@@ -6432,9 +6432,9 @@ function ok(data) {
|
|
|
6432
6432
|
function err(error) {
|
|
6433
6433
|
return { ok: false, error };
|
|
6434
6434
|
}
|
|
6435
|
-
function serviceError(
|
|
6435
|
+
function serviceError(code3, message, service, options) {
|
|
6436
6436
|
return {
|
|
6437
|
-
code:
|
|
6437
|
+
code: code3,
|
|
6438
6438
|
message,
|
|
6439
6439
|
service,
|
|
6440
6440
|
cause: options?.cause,
|
|
@@ -7678,10 +7678,10 @@ var KVService = class extends BaseService {
|
|
|
7678
7678
|
errorText
|
|
7679
7679
|
);
|
|
7680
7680
|
}
|
|
7681
|
-
const
|
|
7681
|
+
const code3 = response.status === 400 ? ErrorCodes.INVALID_INPUT : ErrorCodes.NETWORK_ERROR;
|
|
7682
7682
|
return err(
|
|
7683
7683
|
serviceError(
|
|
7684
|
-
|
|
7684
|
+
code3,
|
|
7685
7685
|
`Failed to create signed read URL for key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
|
|
7686
7686
|
"kv",
|
|
7687
7687
|
{ meta: { status: response.status, statusText: response.statusText } }
|
|
@@ -12896,18 +12896,18 @@ function expandVaultPermissionEntry(entry) {
|
|
|
12896
12896
|
const byBase = /* @__PURE__ */ new Map();
|
|
12897
12897
|
for (const action of entry.actions) {
|
|
12898
12898
|
const expansion = vaultActionExpansion(action);
|
|
12899
|
-
for (const
|
|
12900
|
-
const actions = byBase.get(
|
|
12899
|
+
for (const base4 of expansion.bases) {
|
|
12900
|
+
const actions = byBase.get(base4) ?? [];
|
|
12901
12901
|
if (!actions.includes(expansion.action)) {
|
|
12902
12902
|
actions.push(expansion.action);
|
|
12903
12903
|
}
|
|
12904
|
-
byBase.set(
|
|
12904
|
+
byBase.set(base4, actions);
|
|
12905
12905
|
}
|
|
12906
12906
|
}
|
|
12907
|
-
return [...byBase.entries()].map(([
|
|
12907
|
+
return [...byBase.entries()].map(([base4, actions]) => ({
|
|
12908
12908
|
...entry,
|
|
12909
12909
|
service: "tinycloud.kv",
|
|
12910
|
-
path: vaultKVPath(
|
|
12910
|
+
path: vaultKVPath(base4, entry.path),
|
|
12911
12911
|
actions,
|
|
12912
12912
|
skipPrefix: true
|
|
12913
12913
|
}));
|
|
@@ -12950,9 +12950,9 @@ function normalizeVaultAction(action) {
|
|
|
12950
12950
|
}
|
|
12951
12951
|
return action;
|
|
12952
12952
|
}
|
|
12953
|
-
function vaultKVPath(
|
|
12953
|
+
function vaultKVPath(base4, path) {
|
|
12954
12954
|
const normalized = path.startsWith("/") ? path.slice(1) : path;
|
|
12955
|
-
return `${
|
|
12955
|
+
return `${base4}/${normalized}`;
|
|
12956
12956
|
}
|
|
12957
12957
|
function cloneResourceCapability(entry) {
|
|
12958
12958
|
return {
|
|
@@ -14018,8 +14018,8 @@ function buildAuthUrl(did, options = {}) {
|
|
|
14018
14018
|
params.set("expiry", String(options.expiry));
|
|
14019
14019
|
}
|
|
14020
14020
|
params.set("protocolVersion", "1");
|
|
14021
|
-
const
|
|
14022
|
-
return `${
|
|
14021
|
+
const base4 = options.openkeyHost ?? DEFAULT_OPENKEY_HOST;
|
|
14022
|
+
return `${base4}/delegate?${params.toString()}`;
|
|
14023
14023
|
}
|
|
14024
14024
|
function validateDelegationCallbackPayload(value) {
|
|
14025
14025
|
if (!value || typeof value !== "object") return "expected an object";
|
|
@@ -14989,20 +14989,20 @@ async function acquireDeviceDelegation(input) {
|
|
|
14989
14989
|
}
|
|
14990
14990
|
const startValue = await responseJson(startResponse);
|
|
14991
14991
|
if (!startResponse.ok) {
|
|
14992
|
-
const
|
|
14992
|
+
const code3 = errorCode(startValue);
|
|
14993
14993
|
const description = errorDescription(startValue);
|
|
14994
|
-
if (startResponse.status === 429 &&
|
|
14994
|
+
if (startResponse.status === 429 && code3 === "rate_limited") {
|
|
14995
14995
|
throw deviceAuthRateLimit(startResponse);
|
|
14996
14996
|
}
|
|
14997
|
-
if (
|
|
14997
|
+
if (code3 === "invalid_scope") {
|
|
14998
14998
|
throw new CLIError(
|
|
14999
14999
|
"SCOPE_REJECTED",
|
|
15000
15000
|
`OpenKey rejected the requested scope${description ? `: ${description}` : "."} Remove that capability from the manifest or use another approval flow.`,
|
|
15001
15001
|
ExitCode.PERMISSION_DENIED,
|
|
15002
|
-
{ openkeyError:
|
|
15002
|
+
{ openkeyError: code3, ...description ? { capability: description } : {} }
|
|
15003
15003
|
);
|
|
15004
15004
|
}
|
|
15005
|
-
throw new CLIError("DEVICE_AUTH_FAILED", `OpenKey device authorization failed: ${
|
|
15005
|
+
throw new CLIError("DEVICE_AUTH_FAILED", `OpenKey device authorization failed: ${code3 ?? `HTTP ${startResponse.status}`}${description ? ` (${description})` : ""}`, ExitCode.ERROR);
|
|
15006
15006
|
}
|
|
15007
15007
|
const started = validateStart(startValue, openkeyHost);
|
|
15008
15008
|
const deadline = Date.now() + started.expiresIn * 1e3;
|
|
@@ -15030,20 +15030,20 @@ async function acquireDeviceDelegation(input) {
|
|
|
15030
15030
|
continue;
|
|
15031
15031
|
}
|
|
15032
15032
|
const value = await responseJson(response);
|
|
15033
|
-
const
|
|
15034
|
-
if (response.status >= 500 || response.status === 429 &&
|
|
15035
|
-
if (
|
|
15033
|
+
const code3 = errorCode(value);
|
|
15034
|
+
if (response.status >= 500 || response.status === 429 && code3 !== "slow_down") continue;
|
|
15035
|
+
if (code3 === "slow_down") {
|
|
15036
15036
|
interval += 5;
|
|
15037
15037
|
continue;
|
|
15038
15038
|
}
|
|
15039
|
-
if (
|
|
15040
|
-
if (
|
|
15039
|
+
if (code3 === "authorization_pending") continue;
|
|
15040
|
+
if (code3 === "access_denied") {
|
|
15041
15041
|
throw new CLIError("DEVICE_AUTH_DENIED", "The owner denied the OpenKey device authorization. No session was saved.", ExitCode.PERMISSION_DENIED);
|
|
15042
15042
|
}
|
|
15043
|
-
if (
|
|
15043
|
+
if (code3 === "expired_token") {
|
|
15044
15044
|
throw new CLIError("DEVICE_AUTH_EXPIRED", "OpenKey device authorization expired_token: the approval window closed. Run the command again.", ExitCode.AUTH_REQUIRED);
|
|
15045
15045
|
}
|
|
15046
|
-
if (!response.ok) throw new CLIError("DEVICE_AUTH_FAILED", `OpenKey device authorization failed: ${
|
|
15046
|
+
if (!response.ok) throw new CLIError("DEVICE_AUTH_FAILED", `OpenKey device authorization failed: ${code3 ?? `HTTP ${response.status}`}`, ExitCode.ERROR);
|
|
15047
15047
|
const result = value;
|
|
15048
15048
|
if (result?.status === "pending") {
|
|
15049
15049
|
interval = Math.max(interval, Number.isSafeInteger(result.interval) ? result.interval : interval);
|
|
@@ -15996,7 +15996,7 @@ function execCapturedCommand(command) {
|
|
|
15996
15996
|
stdio: "inherit"
|
|
15997
15997
|
});
|
|
15998
15998
|
child.on("error", reject);
|
|
15999
|
-
child.on("exit", (
|
|
15999
|
+
child.on("exit", (code3, signal) => {
|
|
16000
16000
|
if (signal) {
|
|
16001
16001
|
reject(new CLIError(
|
|
16002
16002
|
"COMMAND_SIGNAL",
|
|
@@ -16005,8 +16005,8 @@ function execCapturedCommand(command) {
|
|
|
16005
16005
|
));
|
|
16006
16006
|
return;
|
|
16007
16007
|
}
|
|
16008
|
-
if (
|
|
16009
|
-
process.exitCode =
|
|
16008
|
+
if (code3 && code3 !== 0) {
|
|
16009
|
+
process.exitCode = code3;
|
|
16010
16010
|
}
|
|
16011
16011
|
resolve4();
|
|
16012
16012
|
});
|
|
@@ -17088,8 +17088,8 @@ function storageQuotaError(error) {
|
|
|
17088
17088
|
}
|
|
17089
17089
|
function assertAddressableKey(key) {
|
|
17090
17090
|
for (let i = 0; i < key.length; i++) {
|
|
17091
|
-
const
|
|
17092
|
-
if (
|
|
17091
|
+
const code3 = key.charCodeAt(i);
|
|
17092
|
+
if (code3 <= 32 || code3 === 127) {
|
|
17093
17093
|
throw new CLIError("USAGE_ERROR", "KV keys cannot contain spaces or control characters; use a URL-safe key", ExitCode.USAGE_ERROR);
|
|
17094
17094
|
}
|
|
17095
17095
|
}
|
|
@@ -17919,8 +17919,8 @@ async function writeSecretFile(path, value) {
|
|
|
17919
17919
|
if (created) {
|
|
17920
17920
|
await rm3(temp, { force: true }).catch(() => void 0);
|
|
17921
17921
|
}
|
|
17922
|
-
const
|
|
17923
|
-
throw new CLIError("ERROR", `Could not write secret output "${path}"${
|
|
17922
|
+
const code3 = error instanceof Error && "code" in error && typeof error.code === "string" ? ` (${error.code})` : "";
|
|
17923
|
+
throw new CLIError("ERROR", `Could not write secret output "${path}"${code3}.`, ExitCode.ERROR);
|
|
17924
17924
|
}
|
|
17925
17925
|
try {
|
|
17926
17926
|
const parent = await open2(parentPath, "r");
|
|
@@ -18058,8 +18058,8 @@ function shouldRequestSecretPermissions(error) {
|
|
|
18058
18058
|
function thrownPermissionError(error) {
|
|
18059
18059
|
const record = error;
|
|
18060
18060
|
const message = typeof record?.message === "string" ? record.message : String(error);
|
|
18061
|
-
const
|
|
18062
|
-
if (
|
|
18061
|
+
const code3 = typeof record?.code === "string" ? record.code : "PERMISSION_DENIED";
|
|
18062
|
+
if (code3 !== "PERMISSION_DENIED" && !/permission|session expired|autosign|capabilit/i.test(message)) {
|
|
18063
18063
|
return null;
|
|
18064
18064
|
}
|
|
18065
18065
|
return {
|
|
@@ -18267,9 +18267,9 @@ async function resolveDelegatedSecretSource(source, secretPath, space = SECRETS_
|
|
|
18267
18267
|
return { ...selected, source };
|
|
18268
18268
|
}
|
|
18269
18269
|
function mapEncryptionResultError(error) {
|
|
18270
|
-
const
|
|
18271
|
-
const exitCode =
|
|
18272
|
-
return new CLIError(
|
|
18270
|
+
const code3 = error.code || "DECRYPTION_FAILED";
|
|
18271
|
+
const exitCode = code3 === "PERMISSION_DENIED" ? ExitCode.PERMISSION_DENIED : code3 === "NOT_FOUND" ? ExitCode.NOT_FOUND : code3 === "NETWORK_ERROR" || code3 === "TRANSPORT_ERROR" ? ExitCode.NETWORK_ERROR : ExitCode.ERROR;
|
|
18272
|
+
return new CLIError(code3, error.message, exitCode);
|
|
18273
18273
|
}
|
|
18274
18274
|
function parseDecryptedSecretPayload(data, secretPath) {
|
|
18275
18275
|
const text = new TextDecoder().decode(data);
|
|
@@ -18803,13 +18803,13 @@ function _abool2(value, title = "") {
|
|
|
18803
18803
|
}
|
|
18804
18804
|
return value;
|
|
18805
18805
|
}
|
|
18806
|
-
function _abytes2(value,
|
|
18806
|
+
function _abytes2(value, length4, title = "") {
|
|
18807
18807
|
const bytes = isBytes(value);
|
|
18808
18808
|
const len = value?.length;
|
|
18809
|
-
const needsLen =
|
|
18810
|
-
if (!bytes || needsLen && len !==
|
|
18809
|
+
const needsLen = length4 !== void 0;
|
|
18810
|
+
if (!bytes || needsLen && len !== length4) {
|
|
18811
18811
|
const prefix = title && `"${title}" `;
|
|
18812
|
-
const ofLen = needsLen ? ` of length ${
|
|
18812
|
+
const ofLen = needsLen ? ` of length ${length4}` : "";
|
|
18813
18813
|
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
18814
18814
|
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
18815
18815
|
}
|
|
@@ -19332,15 +19332,15 @@ var wNAF = class {
|
|
|
19332
19332
|
const { windows, windowSize } = calcWOpts(W, this.bits);
|
|
19333
19333
|
const points = [];
|
|
19334
19334
|
let p = point;
|
|
19335
|
-
let
|
|
19335
|
+
let base4 = p;
|
|
19336
19336
|
for (let window = 0; window < windows; window++) {
|
|
19337
|
-
|
|
19338
|
-
points.push(
|
|
19337
|
+
base4 = p;
|
|
19338
|
+
points.push(base4);
|
|
19339
19339
|
for (let i = 1; i < windowSize; i++) {
|
|
19340
|
-
|
|
19341
|
-
points.push(
|
|
19340
|
+
base4 = base4.add(p);
|
|
19341
|
+
points.push(base4);
|
|
19342
19342
|
}
|
|
19343
|
-
p =
|
|
19343
|
+
p = base4.double();
|
|
19344
19344
|
}
|
|
19345
19345
|
return points;
|
|
19346
19346
|
}
|
|
@@ -20360,13 +20360,13 @@ var BLAKE2 = class extends Hash {
|
|
|
20360
20360
|
return res;
|
|
20361
20361
|
}
|
|
20362
20362
|
_cloneInto(to) {
|
|
20363
|
-
const { buffer, length:
|
|
20363
|
+
const { buffer, length: length4, finished, destroyed, outputLen, pos } = this;
|
|
20364
20364
|
to || (to = new this.constructor({ dkLen: outputLen }));
|
|
20365
20365
|
to.set(...this.get());
|
|
20366
20366
|
to.buffer.set(buffer);
|
|
20367
20367
|
to.destroyed = destroyed;
|
|
20368
20368
|
to.finished = finished;
|
|
20369
|
-
to.length =
|
|
20369
|
+
to.length = length4;
|
|
20370
20370
|
to.pos = pos;
|
|
20371
20371
|
to.outputLen = outputLen;
|
|
20372
20372
|
return to;
|
|
@@ -21600,8 +21600,8 @@ function isValidJWT2(jwt, alg) {
|
|
|
21600
21600
|
const [header] = jwt.split(".");
|
|
21601
21601
|
if (!header)
|
|
21602
21602
|
return false;
|
|
21603
|
-
const
|
|
21604
|
-
const decoded = JSON.parse(atob(
|
|
21603
|
+
const base6422 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
21604
|
+
const decoded = JSON.parse(atob(base6422));
|
|
21605
21605
|
if (typeof decoded !== "object" || decoded === null)
|
|
21606
21606
|
return false;
|
|
21607
21607
|
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
@@ -24255,23 +24255,23 @@ var ZodEffects2 = class extends ZodType2 {
|
|
|
24255
24255
|
}
|
|
24256
24256
|
if (effect.type === "transform") {
|
|
24257
24257
|
if (ctx.common.async === false) {
|
|
24258
|
-
const
|
|
24258
|
+
const base33 = this._def.schema._parseSync({
|
|
24259
24259
|
data: ctx.data,
|
|
24260
24260
|
path: ctx.path,
|
|
24261
24261
|
parent: ctx
|
|
24262
24262
|
});
|
|
24263
|
-
if (!isValid2(
|
|
24263
|
+
if (!isValid2(base33))
|
|
24264
24264
|
return INVALID2;
|
|
24265
|
-
const result = effect.transform(
|
|
24265
|
+
const result = effect.transform(base33.value, checkCtx);
|
|
24266
24266
|
if (result instanceof Promise) {
|
|
24267
24267
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
24268
24268
|
}
|
|
24269
24269
|
return { status: status.value, value: result };
|
|
24270
24270
|
} else {
|
|
24271
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((
|
|
24272
|
-
if (!isValid2(
|
|
24271
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base33) => {
|
|
24272
|
+
if (!isValid2(base33))
|
|
24273
24273
|
return INVALID2;
|
|
24274
|
-
return Promise.resolve(effect.transform(
|
|
24274
|
+
return Promise.resolve(effect.transform(base33.value, checkCtx)).then((result) => ({
|
|
24275
24275
|
status: status.value,
|
|
24276
24276
|
value: result
|
|
24277
24277
|
}));
|
|
@@ -25179,9 +25179,9 @@ var cache = /* @__PURE__ */ new WeakMap();
|
|
|
25179
25179
|
function baseCache(cid2) {
|
|
25180
25180
|
const baseCache22 = cache.get(cid2);
|
|
25181
25181
|
if (baseCache22 == null) {
|
|
25182
|
-
const
|
|
25183
|
-
cache.set(cid2,
|
|
25184
|
-
return
|
|
25182
|
+
const baseCache32 = /* @__PURE__ */ new Map();
|
|
25183
|
+
cache.set(cid2, baseCache32);
|
|
25184
|
+
return baseCache32;
|
|
25185
25185
|
}
|
|
25186
25186
|
return baseCache22;
|
|
25187
25187
|
}
|
|
@@ -26419,7 +26419,7 @@ function base2(ALPHABET, name) {
|
|
|
26419
26419
|
var LEADER = ALPHABET.charAt(0);
|
|
26420
26420
|
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
26421
26421
|
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
26422
|
-
function
|
|
26422
|
+
function encode52(source) {
|
|
26423
26423
|
if (source instanceof Uint8Array)
|
|
26424
26424
|
;
|
|
26425
26425
|
else if (ArrayBuffer.isView(source)) {
|
|
@@ -26434,7 +26434,7 @@ function base2(ALPHABET, name) {
|
|
|
26434
26434
|
return "";
|
|
26435
26435
|
}
|
|
26436
26436
|
var zeroes = 0;
|
|
26437
|
-
var
|
|
26437
|
+
var length32 = 0;
|
|
26438
26438
|
var pbegin = 0;
|
|
26439
26439
|
var pend = source.length;
|
|
26440
26440
|
while (pbegin !== pend && source[pbegin] === 0) {
|
|
@@ -26446,7 +26446,7 @@ function base2(ALPHABET, name) {
|
|
|
26446
26446
|
while (pbegin !== pend) {
|
|
26447
26447
|
var carry = source[pbegin];
|
|
26448
26448
|
var i2 = 0;
|
|
26449
|
-
for (var it1 = size - 1; (carry !== 0 || i2 <
|
|
26449
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length32) && it1 !== -1; it1--, i2++) {
|
|
26450
26450
|
carry += 256 * b58[it1] >>> 0;
|
|
26451
26451
|
b58[it1] = carry % BASE >>> 0;
|
|
26452
26452
|
carry = carry / BASE >>> 0;
|
|
@@ -26454,10 +26454,10 @@ function base2(ALPHABET, name) {
|
|
|
26454
26454
|
if (carry !== 0) {
|
|
26455
26455
|
throw new Error("Non-zero carry");
|
|
26456
26456
|
}
|
|
26457
|
-
|
|
26457
|
+
length32 = i2;
|
|
26458
26458
|
pbegin++;
|
|
26459
26459
|
}
|
|
26460
|
-
var it2 = size -
|
|
26460
|
+
var it2 = size - length32;
|
|
26461
26461
|
while (it2 !== size && b58[it2] === 0) {
|
|
26462
26462
|
it2++;
|
|
26463
26463
|
}
|
|
@@ -26479,7 +26479,7 @@ function base2(ALPHABET, name) {
|
|
|
26479
26479
|
return;
|
|
26480
26480
|
}
|
|
26481
26481
|
var zeroes = 0;
|
|
26482
|
-
var
|
|
26482
|
+
var length32 = 0;
|
|
26483
26483
|
while (source[psz] === LEADER) {
|
|
26484
26484
|
zeroes++;
|
|
26485
26485
|
psz++;
|
|
@@ -26492,7 +26492,7 @@ function base2(ALPHABET, name) {
|
|
|
26492
26492
|
return;
|
|
26493
26493
|
}
|
|
26494
26494
|
var i2 = 0;
|
|
26495
|
-
for (var it3 = size - 1; (carry !== 0 || i2 <
|
|
26495
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length32) && it3 !== -1; it3--, i2++) {
|
|
26496
26496
|
carry += BASE * b256[it3] >>> 0;
|
|
26497
26497
|
b256[it3] = carry % 256 >>> 0;
|
|
26498
26498
|
carry = carry / 256 >>> 0;
|
|
@@ -26500,13 +26500,13 @@ function base2(ALPHABET, name) {
|
|
|
26500
26500
|
if (carry !== 0) {
|
|
26501
26501
|
throw new Error("Non-zero carry");
|
|
26502
26502
|
}
|
|
26503
|
-
|
|
26503
|
+
length32 = i2;
|
|
26504
26504
|
psz++;
|
|
26505
26505
|
}
|
|
26506
26506
|
if (source[psz] === " ") {
|
|
26507
26507
|
return;
|
|
26508
26508
|
}
|
|
26509
|
-
var it4 = size -
|
|
26509
|
+
var it4 = size - length32;
|
|
26510
26510
|
while (it4 !== size && b256[it4] === 0) {
|
|
26511
26511
|
it4++;
|
|
26512
26512
|
}
|
|
@@ -26517,7 +26517,7 @@ function base2(ALPHABET, name) {
|
|
|
26517
26517
|
}
|
|
26518
26518
|
return vch;
|
|
26519
26519
|
}
|
|
26520
|
-
function
|
|
26520
|
+
function decode92(string) {
|
|
26521
26521
|
var buffer = decodeUnsafe(string);
|
|
26522
26522
|
if (buffer) {
|
|
26523
26523
|
return buffer;
|
|
@@ -26525,9 +26525,9 @@ function base2(ALPHABET, name) {
|
|
|
26525
26525
|
throw new Error(`Non-${name} character`);
|
|
26526
26526
|
}
|
|
26527
26527
|
return {
|
|
26528
|
-
encode:
|
|
26528
|
+
encode: encode52,
|
|
26529
26529
|
decodeUnsafe,
|
|
26530
|
-
decode:
|
|
26530
|
+
decode: decode92
|
|
26531
26531
|
};
|
|
26532
26532
|
}
|
|
26533
26533
|
var src2 = base2;
|
|
@@ -26625,16 +26625,16 @@ var Codec2 = class {
|
|
|
26625
26625
|
return this.decoder.decode(input);
|
|
26626
26626
|
}
|
|
26627
26627
|
};
|
|
26628
|
-
function from2({ name, prefix, encode:
|
|
26629
|
-
return new Codec2(name, prefix,
|
|
26628
|
+
function from2({ name, prefix, encode: encode52, decode: decode92 }) {
|
|
26629
|
+
return new Codec2(name, prefix, encode52, decode92);
|
|
26630
26630
|
}
|
|
26631
26631
|
function baseX2({ name, prefix, alphabet }) {
|
|
26632
|
-
const { encode:
|
|
26632
|
+
const { encode: encode52, decode: decode92 } = base_x_default2(alphabet, name);
|
|
26633
26633
|
return from2({
|
|
26634
26634
|
prefix,
|
|
26635
26635
|
name,
|
|
26636
|
-
encode:
|
|
26637
|
-
decode: (text) => coerce3(
|
|
26636
|
+
encode: encode52,
|
|
26637
|
+
decode: (text) => coerce3(decode92(text))
|
|
26638
26638
|
});
|
|
26639
26639
|
}
|
|
26640
26640
|
function decode5(string, alphabetIdx, bitsPerChar, name) {
|
|
@@ -27004,24 +27004,24 @@ var Digest2 = class {
|
|
|
27004
27004
|
this.bytes = bytes3;
|
|
27005
27005
|
}
|
|
27006
27006
|
};
|
|
27007
|
-
function format2(link2,
|
|
27007
|
+
function format2(link2, base33) {
|
|
27008
27008
|
const { bytes: bytes3, version } = link2;
|
|
27009
27009
|
switch (version) {
|
|
27010
27010
|
case 0:
|
|
27011
|
-
return toStringV02(bytes3, baseCache2(link2),
|
|
27011
|
+
return toStringV02(bytes3, baseCache2(link2), base33 ?? base58btc2.encoder);
|
|
27012
27012
|
default:
|
|
27013
|
-
return toStringV12(bytes3, baseCache2(link2),
|
|
27013
|
+
return toStringV12(bytes3, baseCache2(link2), base33 ?? base322.encoder);
|
|
27014
27014
|
}
|
|
27015
27015
|
}
|
|
27016
27016
|
var cache2 = /* @__PURE__ */ new WeakMap();
|
|
27017
27017
|
function baseCache2(cid2) {
|
|
27018
|
-
const
|
|
27019
|
-
if (
|
|
27018
|
+
const baseCache32 = cache2.get(cid2);
|
|
27019
|
+
if (baseCache32 == null) {
|
|
27020
27020
|
const baseCache4 = /* @__PURE__ */ new Map();
|
|
27021
27021
|
cache2.set(cid2, baseCache4);
|
|
27022
27022
|
return baseCache4;
|
|
27023
27023
|
}
|
|
27024
|
-
return
|
|
27024
|
+
return baseCache32;
|
|
27025
27025
|
}
|
|
27026
27026
|
var CID2 = class _CID2 {
|
|
27027
27027
|
code;
|
|
@@ -27100,8 +27100,8 @@ var CID2 = class _CID2 {
|
|
|
27100
27100
|
const unknown = other;
|
|
27101
27101
|
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals4(self.multihash, unknown.multihash);
|
|
27102
27102
|
}
|
|
27103
|
-
toString(
|
|
27104
|
-
return format2(this,
|
|
27103
|
+
toString(base33) {
|
|
27104
|
+
return format2(this, base33);
|
|
27105
27105
|
}
|
|
27106
27106
|
toJSON() {
|
|
27107
27107
|
return { "/": format2(this) };
|
|
@@ -27233,8 +27233,8 @@ var CID2 = class _CID2 {
|
|
|
27233
27233
|
static inspectBytes(initialBytes) {
|
|
27234
27234
|
let offset = 0;
|
|
27235
27235
|
const next = () => {
|
|
27236
|
-
const [i,
|
|
27237
|
-
offset +=
|
|
27236
|
+
const [i, length32] = decode7(initialBytes.subarray(offset));
|
|
27237
|
+
offset += length32;
|
|
27238
27238
|
return i;
|
|
27239
27239
|
};
|
|
27240
27240
|
let version = next();
|
|
@@ -27261,8 +27261,8 @@ var CID2 = class _CID2 {
|
|
|
27261
27261
|
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
27262
27262
|
* a default decoder).
|
|
27263
27263
|
*/
|
|
27264
|
-
static parse(source,
|
|
27265
|
-
const [prefix, bytes3] = parseCIDtoBytes2(source,
|
|
27264
|
+
static parse(source, base33) {
|
|
27265
|
+
const [prefix, bytes3] = parseCIDtoBytes2(source, base33);
|
|
27266
27266
|
const cid2 = _CID2.decode(bytes3);
|
|
27267
27267
|
if (cid2.version === 0 && source[0] !== "Q") {
|
|
27268
27268
|
throw Error("Version 0 CID string must not include multibase prefix");
|
|
@@ -27271,56 +27271,56 @@ var CID2 = class _CID2 {
|
|
|
27271
27271
|
return cid2;
|
|
27272
27272
|
}
|
|
27273
27273
|
};
|
|
27274
|
-
function parseCIDtoBytes2(source,
|
|
27274
|
+
function parseCIDtoBytes2(source, base33) {
|
|
27275
27275
|
switch (source[0]) {
|
|
27276
27276
|
// CIDv0 is parsed differently
|
|
27277
27277
|
case "Q": {
|
|
27278
|
-
const decoder =
|
|
27278
|
+
const decoder = base33 ?? base58btc2;
|
|
27279
27279
|
return [
|
|
27280
27280
|
base58btc2.prefix,
|
|
27281
27281
|
decoder.decode(`${base58btc2.prefix}${source}`)
|
|
27282
27282
|
];
|
|
27283
27283
|
}
|
|
27284
27284
|
case base58btc2.prefix: {
|
|
27285
|
-
const decoder =
|
|
27285
|
+
const decoder = base33 ?? base58btc2;
|
|
27286
27286
|
return [base58btc2.prefix, decoder.decode(source)];
|
|
27287
27287
|
}
|
|
27288
27288
|
case base322.prefix: {
|
|
27289
|
-
const decoder =
|
|
27289
|
+
const decoder = base33 ?? base322;
|
|
27290
27290
|
return [base322.prefix, decoder.decode(source)];
|
|
27291
27291
|
}
|
|
27292
27292
|
case base362.prefix: {
|
|
27293
|
-
const decoder =
|
|
27293
|
+
const decoder = base33 ?? base362;
|
|
27294
27294
|
return [base362.prefix, decoder.decode(source)];
|
|
27295
27295
|
}
|
|
27296
27296
|
default: {
|
|
27297
|
-
if (
|
|
27297
|
+
if (base33 == null) {
|
|
27298
27298
|
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
27299
27299
|
}
|
|
27300
|
-
return [source[0],
|
|
27300
|
+
return [source[0], base33.decode(source)];
|
|
27301
27301
|
}
|
|
27302
27302
|
}
|
|
27303
27303
|
}
|
|
27304
|
-
function toStringV02(bytes3,
|
|
27305
|
-
const { prefix } =
|
|
27304
|
+
function toStringV02(bytes3, cache32, base33) {
|
|
27305
|
+
const { prefix } = base33;
|
|
27306
27306
|
if (prefix !== base58btc2.prefix) {
|
|
27307
|
-
throw Error(`Cannot string encode V0 in ${
|
|
27307
|
+
throw Error(`Cannot string encode V0 in ${base33.name} encoding`);
|
|
27308
27308
|
}
|
|
27309
|
-
const cid2 =
|
|
27309
|
+
const cid2 = cache32.get(prefix);
|
|
27310
27310
|
if (cid2 == null) {
|
|
27311
|
-
const cid3 =
|
|
27312
|
-
|
|
27311
|
+
const cid3 = base33.encode(bytes3).slice(1);
|
|
27312
|
+
cache32.set(prefix, cid3);
|
|
27313
27313
|
return cid3;
|
|
27314
27314
|
} else {
|
|
27315
27315
|
return cid2;
|
|
27316
27316
|
}
|
|
27317
27317
|
}
|
|
27318
|
-
function toStringV12(bytes3,
|
|
27319
|
-
const { prefix } =
|
|
27320
|
-
const cid2 =
|
|
27318
|
+
function toStringV12(bytes3, cache32, base33) {
|
|
27319
|
+
const { prefix } = base33;
|
|
27320
|
+
const cid2 = cache32.get(prefix);
|
|
27321
27321
|
if (cid2 == null) {
|
|
27322
|
-
const cid3 =
|
|
27323
|
-
|
|
27322
|
+
const cid3 = base33.encode(bytes3);
|
|
27323
|
+
cache32.set(prefix, cid3);
|
|
27324
27324
|
return cid3;
|
|
27325
27325
|
} else {
|
|
27326
27326
|
return cid2;
|
|
@@ -27374,135 +27374,1482 @@ function historyRecordForPublishedShare(result, now = /* @__PURE__ */ new Date()
|
|
|
27374
27374
|
};
|
|
27375
27375
|
}
|
|
27376
27376
|
var ShareNotifyError = class extends Error {
|
|
27377
|
-
|
|
27378
|
-
constructor(message = "share delivery did not complete") {
|
|
27377
|
+
constructor(message = "share delivery did not complete", reason) {
|
|
27379
27378
|
super(message);
|
|
27379
|
+
this.reason = reason;
|
|
27380
27380
|
this.name = "ShareNotifyError";
|
|
27381
27381
|
}
|
|
27382
|
-
|
|
27383
|
-
|
|
27384
|
-
|
|
27385
|
-
const
|
|
27386
|
-
|
|
27387
|
-
if (
|
|
27388
|
-
if (matcher.kind === "
|
|
27389
|
-
return
|
|
27382
|
+
code = "delivery-failed";
|
|
27383
|
+
};
|
|
27384
|
+
function recipientMatchesShareRecord(record, recipient) {
|
|
27385
|
+
const matcher = record.recipientMatcher;
|
|
27386
|
+
const mailbox = canonicalMailbox(recipient);
|
|
27387
|
+
if (mailbox === void 0) return false;
|
|
27388
|
+
if (matcher.kind === "exactEmail") return canonicalMailbox(matcher.value)?.email === mailbox.email;
|
|
27389
|
+
if (matcher.kind === "emailDomain") return mailbox.domain === matcher.value;
|
|
27390
|
+
return false;
|
|
27391
|
+
}
|
|
27392
|
+
function shareDeliveryWindowExpiresAt(record) {
|
|
27393
|
+
const expiresAt = Math.min(Date.parse(record.expiresAt), Date.parse(record.registeredAt) + 5 * 60 * 1e3);
|
|
27394
|
+
if (!Number.isFinite(expiresAt)) throw new ShareNotifyError("share delivery history has invalid timestamps");
|
|
27395
|
+
return expiresAt;
|
|
27396
|
+
}
|
|
27397
|
+
async function notifyShare(input) {
|
|
27398
|
+
const mailbox = canonicalMailbox(input.recipient);
|
|
27399
|
+
if (!input.shareId || mailbox === void 0) throw new ShareNotifyError("recipient is invalid");
|
|
27400
|
+
const recipient = mailbox.email;
|
|
27401
|
+
if (input.record !== void 0 && !recipientMatchesShareRecord(input.record, recipient)) {
|
|
27402
|
+
throw new ShareNotifyError("recipient does not match the stored share target");
|
|
27403
|
+
}
|
|
27404
|
+
const idempotencyKey = input.idempotencyKey ?? await defaultIdempotencyKey(input.shareId, recipient);
|
|
27405
|
+
const attemptsLimit = input.maxAttempts ?? 3;
|
|
27406
|
+
if (!Number.isSafeInteger(attemptsLimit) || attemptsLimit < 1 || attemptsLimit > 8) throw new ShareNotifyError("maxAttempts is invalid");
|
|
27407
|
+
if (input.signal?.aborted) throw new ShareNotifyError("share delivery was cancelled");
|
|
27408
|
+
if (input.checkDeliveryWindow && input.record !== void 0 && shareDeliveryWindowExpiresAt(input.record) <= Date.now()) {
|
|
27409
|
+
return {
|
|
27410
|
+
protocol: "tinycloud-share",
|
|
27411
|
+
version: 1,
|
|
27412
|
+
shareId: input.shareId,
|
|
27413
|
+
state: "partial-failure",
|
|
27414
|
+
idempotencyKey,
|
|
27415
|
+
attempts: 1,
|
|
27416
|
+
retryable: false,
|
|
27417
|
+
reason: "delivery-window-expired"
|
|
27418
|
+
};
|
|
27419
|
+
}
|
|
27420
|
+
let attempts = 0;
|
|
27421
|
+
let lastError;
|
|
27422
|
+
while (attempts < attemptsLimit) {
|
|
27423
|
+
if (input.signal?.aborted) throw new ShareNotifyError("share delivery was cancelled");
|
|
27424
|
+
attempts += 1;
|
|
27425
|
+
try {
|
|
27426
|
+
const state = await input.adapter.deliver({ shareId: input.shareId, recipient, idempotencyKey, ...input.record === void 0 ? {} : { record: input.record }, ...input.signal === void 0 ? {} : { signal: input.signal } });
|
|
27427
|
+
return {
|
|
27428
|
+
protocol: "tinycloud-share",
|
|
27429
|
+
version: 1,
|
|
27430
|
+
shareId: input.shareId,
|
|
27431
|
+
state: state === "delivered" && input.record?.deliveredRecipients?.includes(recipient) ? "already-delivered" : state,
|
|
27432
|
+
idempotencyKey,
|
|
27433
|
+
attempts
|
|
27434
|
+
};
|
|
27435
|
+
} catch (error) {
|
|
27436
|
+
if (error instanceof ShareNotifyError && error.reason === "delivery-window-expired") {
|
|
27437
|
+
return {
|
|
27438
|
+
protocol: "tinycloud-share",
|
|
27439
|
+
version: 1,
|
|
27440
|
+
shareId: input.shareId,
|
|
27441
|
+
state: "partial-failure",
|
|
27442
|
+
idempotencyKey,
|
|
27443
|
+
attempts,
|
|
27444
|
+
retryable: false,
|
|
27445
|
+
reason: "delivery-window-expired"
|
|
27446
|
+
};
|
|
27447
|
+
}
|
|
27448
|
+
lastError = error;
|
|
27449
|
+
}
|
|
27450
|
+
}
|
|
27451
|
+
void lastError;
|
|
27452
|
+
return { protocol: "tinycloud-share", version: 1, shareId: input.shareId, state: "partial-failure", idempotencyKey, attempts, retryable: true };
|
|
27453
|
+
}
|
|
27454
|
+
async function defaultIdempotencyKey(shareId, recipient) {
|
|
27455
|
+
const canonicalRecipient = canonicalize2(recipient.trim().toLowerCase());
|
|
27456
|
+
const digest3 = new Uint8Array(await crypto.subtle.digest(
|
|
27457
|
+
"SHA-256",
|
|
27458
|
+
new TextEncoder().encode(canonicalRecipient)
|
|
27459
|
+
));
|
|
27460
|
+
return `tinycloud-share:${shareId}:${toBase64Url(digest3)}`;
|
|
27461
|
+
}
|
|
27462
|
+
function targetKind2(record) {
|
|
27463
|
+
if (record.targetKind !== void 0) return record.targetKind;
|
|
27464
|
+
return record.recipientMatcher.kind === "exactEmail" ? "email" : record.recipientMatcher.kind === "emailDomain" ? "emailDomain" : record.recipientMatcher.kind === "recipientDid" ? "recipientDid" : "bearer";
|
|
27465
|
+
}
|
|
27466
|
+
function policyNodeAudience(record) {
|
|
27467
|
+
const envelope = record.deliveryMaterial?.envelope;
|
|
27468
|
+
if (typeof envelope !== "object" || envelope === null || Array.isArray(envelope)) return record.target.nodeAudience;
|
|
27469
|
+
const binding = envelope.attestedEnforcerBinding;
|
|
27470
|
+
if (typeof binding !== "object" || binding === null || Array.isArray(binding)) return record.target.nodeAudience;
|
|
27471
|
+
const nodeAudience = binding.nodeAudience;
|
|
27472
|
+
return typeof nodeAudience === "string" ? nodeAudience : record.target.nodeAudience;
|
|
27473
|
+
}
|
|
27474
|
+
async function revokeShare(input) {
|
|
27475
|
+
const target = targetKind2(input.record);
|
|
27476
|
+
if (input.adapter === void 0) return { state: "unsupported", target, reason: "node revocation authority is required", code: "unsupported-target" };
|
|
27477
|
+
const scope = input.scope ?? "direct";
|
|
27478
|
+
const delegationCid = scope === "ancestor" ? input.record.ownerDelegationCid : input.record.enforcementDelegationCid;
|
|
27479
|
+
if (delegationCid === void 0) return { state: "unsupported", target, reason: "share has no node-enforced delegation receipt", code: "unsupported-target" };
|
|
27480
|
+
if (target === "bearer") {
|
|
27481
|
+
if (input.adapter.revokeDelegation === void 0) return { state: "unsupported", target, reason: "native delegation revocation authority is required", code: "unsupported-target" };
|
|
27482
|
+
await input.adapter.revokeDelegation({ delegationCid, scope });
|
|
27483
|
+
} else {
|
|
27484
|
+
if (input.record.ownerDid === void 0) return { state: "unsupported", target, reason: "share has no Policy/v3 owner receipt", code: "unsupported-target" };
|
|
27485
|
+
if (input.adapter.revokePolicyRoot === void 0) return { state: "unsupported", target, reason: "Policy/v3 root revocation authority is required", code: "unsupported-target" };
|
|
27486
|
+
await input.adapter.revokePolicyRoot({
|
|
27487
|
+
rootCid: delegationCid,
|
|
27488
|
+
targetRole: scope === "ancestor" ? "policy-authority" : "policy-enforcement",
|
|
27489
|
+
ownerDid: input.record.ownerDid,
|
|
27490
|
+
nodeOrigin: input.record.target.origin,
|
|
27491
|
+
nodeAudience: policyNodeAudience(input.record)
|
|
27492
|
+
});
|
|
27493
|
+
}
|
|
27494
|
+
const revokedAt = (input.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
27495
|
+
if (input.records?.update !== void 0) {
|
|
27496
|
+
await input.records.update(input.record.shareId, (record) => ({ ...record, revokedAt }));
|
|
27497
|
+
} else if (input.records !== void 0) {
|
|
27498
|
+
await input.records.put({ ...input.record, revokedAt });
|
|
27499
|
+
}
|
|
27500
|
+
return { state: "revoked", target, delegationCid, revokedAt };
|
|
27501
|
+
}
|
|
27502
|
+
function redactRecord(record, revealLink, link2) {
|
|
27503
|
+
const matcher = record.recipientMatcher;
|
|
27504
|
+
const revealedLink = revealLink ? link2 ?? record.link : void 0;
|
|
27505
|
+
return {
|
|
27506
|
+
shareId: record.shareId,
|
|
27507
|
+
target: matcher.kind === "exactEmail" ? "email" : matcher.kind === "emailDomain" ? "email-domain" : matcher.kind === "recipientDid" ? "recipient-did" : "bearer",
|
|
27508
|
+
...matcher.kind === "exactEmail" ? { recipient: matcher.value } : matcher.kind === "emailDomain" ? { recipient: `*@${matcher.value}` } : matcher.kind === "recipientDid" ? { recipient: matcher.value } : {},
|
|
27509
|
+
expiresAt: record.expiresAt,
|
|
27510
|
+
revoked: record.revokedAt !== void 0,
|
|
27511
|
+
...revealedLink === void 0 ? {} : { link: revealedLink }
|
|
27512
|
+
};
|
|
27513
|
+
}
|
|
27514
|
+
async function listShares(storage) {
|
|
27515
|
+
const records = await storage.list();
|
|
27516
|
+
return records.map((record) => redactRecord(record, false));
|
|
27517
|
+
}
|
|
27518
|
+
async function showShare(input) {
|
|
27519
|
+
const record = await input.storage.get(input.shareId);
|
|
27520
|
+
if (record === void 0) throw new Error("share not found");
|
|
27521
|
+
return redactRecord(record, input.revealLink === true, input.link);
|
|
27522
|
+
}
|
|
27523
|
+
var SHARE_V2_PROTOCOL = Object.freeze({
|
|
27524
|
+
challengeDomain: "xyz.tinycloud.share/policy-challenge/v2\0",
|
|
27525
|
+
sessionDomain: "xyz.tinycloud.share/policy-session/v2\0",
|
|
27526
|
+
invocationDomain: "xyz.tinycloud.share/invocation/v2\0",
|
|
27527
|
+
readResponseDomain: "xyz.tinycloud.share/read-response/v2\0",
|
|
27528
|
+
holderBindingDomain: "xyz.tinycloud.share/email-claim-holder-binding/v1\0",
|
|
27529
|
+
holderBindingName: "holderBinding",
|
|
27530
|
+
holderBindingType: "TinyCloudEmailClaimHolderBinding",
|
|
27531
|
+
holderBindingVersion: 1
|
|
27532
|
+
});
|
|
27533
|
+
var DOMAIN = SHARE_V2_PROTOCOL.challengeDomain;
|
|
27534
|
+
var PRESENTATION_DOMAIN = SHARE_V2_PROTOCOL.sessionDomain;
|
|
27535
|
+
var SESSION_DOMAIN = SHARE_V2_PROTOCOL.sessionDomain;
|
|
27536
|
+
var INVOCATION_DOMAIN = SHARE_V2_PROTOCOL.invocationDomain;
|
|
27537
|
+
var NATIVE_SHARE_FRAGMENT_PARAMETER = "tc1";
|
|
27538
|
+
function parseNativeShareUrl(value) {
|
|
27539
|
+
const url = new URL(value);
|
|
27540
|
+
if (url.search || url.pathname !== "/viewer") throw new TypeError("native shares must carry tc1 only in the /viewer URL fragment");
|
|
27541
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
27542
|
+
const token = fragment.get(NATIVE_SHARE_FRAGMENT_PARAMETER);
|
|
27543
|
+
if (!token || fragment.size !== 1) throw new TypeError("missing native share fragment");
|
|
27544
|
+
return token;
|
|
27545
|
+
}
|
|
27546
|
+
|
|
27547
|
+
// ../share-envelope/dist/index.js
|
|
27548
|
+
var empty3 = new Uint8Array(0);
|
|
27549
|
+
function equals5(aa, bb) {
|
|
27550
|
+
if (aa === bb) {
|
|
27551
|
+
return true;
|
|
27552
|
+
}
|
|
27553
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
27554
|
+
return false;
|
|
27555
|
+
}
|
|
27556
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
27557
|
+
if (aa[ii] !== bb[ii]) {
|
|
27558
|
+
return false;
|
|
27559
|
+
}
|
|
27560
|
+
}
|
|
27561
|
+
return true;
|
|
27562
|
+
}
|
|
27563
|
+
function coerce4(o) {
|
|
27564
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
27565
|
+
return o;
|
|
27566
|
+
}
|
|
27567
|
+
if (o instanceof ArrayBuffer) {
|
|
27568
|
+
return new Uint8Array(o);
|
|
27569
|
+
}
|
|
27570
|
+
if (ArrayBuffer.isView(o)) {
|
|
27571
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
27572
|
+
}
|
|
27573
|
+
throw new Error("Unknown type, must be binary type");
|
|
27574
|
+
}
|
|
27575
|
+
function base3(ALPHABET, name) {
|
|
27576
|
+
if (ALPHABET.length >= 255) {
|
|
27577
|
+
throw new TypeError("Alphabet too long");
|
|
27578
|
+
}
|
|
27579
|
+
var BASE_MAP = new Uint8Array(256);
|
|
27580
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
27581
|
+
BASE_MAP[j] = 255;
|
|
27582
|
+
}
|
|
27583
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
27584
|
+
var x = ALPHABET.charAt(i);
|
|
27585
|
+
var xc = x.charCodeAt(0);
|
|
27586
|
+
if (BASE_MAP[xc] !== 255) {
|
|
27587
|
+
throw new TypeError(x + " is ambiguous");
|
|
27588
|
+
}
|
|
27589
|
+
BASE_MAP[xc] = i;
|
|
27590
|
+
}
|
|
27591
|
+
var BASE = ALPHABET.length;
|
|
27592
|
+
var LEADER = ALPHABET.charAt(0);
|
|
27593
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
27594
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
27595
|
+
function encode32(source) {
|
|
27596
|
+
if (source instanceof Uint8Array)
|
|
27597
|
+
;
|
|
27598
|
+
else if (ArrayBuffer.isView(source)) {
|
|
27599
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
27600
|
+
} else if (Array.isArray(source)) {
|
|
27601
|
+
source = Uint8Array.from(source);
|
|
27602
|
+
}
|
|
27603
|
+
if (!(source instanceof Uint8Array)) {
|
|
27604
|
+
throw new TypeError("Expected Uint8Array");
|
|
27605
|
+
}
|
|
27606
|
+
if (source.length === 0) {
|
|
27607
|
+
return "";
|
|
27608
|
+
}
|
|
27609
|
+
var zeroes = 0;
|
|
27610
|
+
var length22 = 0;
|
|
27611
|
+
var pbegin = 0;
|
|
27612
|
+
var pend = source.length;
|
|
27613
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
27614
|
+
pbegin++;
|
|
27615
|
+
zeroes++;
|
|
27616
|
+
}
|
|
27617
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
27618
|
+
var b58 = new Uint8Array(size);
|
|
27619
|
+
while (pbegin !== pend) {
|
|
27620
|
+
var carry = source[pbegin];
|
|
27621
|
+
var i2 = 0;
|
|
27622
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length22) && it1 !== -1; it1--, i2++) {
|
|
27623
|
+
carry += 256 * b58[it1] >>> 0;
|
|
27624
|
+
b58[it1] = carry % BASE >>> 0;
|
|
27625
|
+
carry = carry / BASE >>> 0;
|
|
27626
|
+
}
|
|
27627
|
+
if (carry !== 0) {
|
|
27628
|
+
throw new Error("Non-zero carry");
|
|
27629
|
+
}
|
|
27630
|
+
length22 = i2;
|
|
27631
|
+
pbegin++;
|
|
27632
|
+
}
|
|
27633
|
+
var it2 = size - length22;
|
|
27634
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
27635
|
+
it2++;
|
|
27636
|
+
}
|
|
27637
|
+
var str = LEADER.repeat(zeroes);
|
|
27638
|
+
for (; it2 < size; ++it2) {
|
|
27639
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
27640
|
+
}
|
|
27641
|
+
return str;
|
|
27642
|
+
}
|
|
27643
|
+
function decodeUnsafe(source) {
|
|
27644
|
+
if (typeof source !== "string") {
|
|
27645
|
+
throw new TypeError("Expected String");
|
|
27646
|
+
}
|
|
27647
|
+
if (source.length === 0) {
|
|
27648
|
+
return new Uint8Array();
|
|
27649
|
+
}
|
|
27650
|
+
var psz = 0;
|
|
27651
|
+
if (source[psz] === " ") {
|
|
27652
|
+
return;
|
|
27653
|
+
}
|
|
27654
|
+
var zeroes = 0;
|
|
27655
|
+
var length22 = 0;
|
|
27656
|
+
while (source[psz] === LEADER) {
|
|
27657
|
+
zeroes++;
|
|
27658
|
+
psz++;
|
|
27659
|
+
}
|
|
27660
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
27661
|
+
var b256 = new Uint8Array(size);
|
|
27662
|
+
while (source[psz]) {
|
|
27663
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
27664
|
+
if (carry === 255) {
|
|
27665
|
+
return;
|
|
27666
|
+
}
|
|
27667
|
+
var i2 = 0;
|
|
27668
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length22) && it3 !== -1; it3--, i2++) {
|
|
27669
|
+
carry += BASE * b256[it3] >>> 0;
|
|
27670
|
+
b256[it3] = carry % 256 >>> 0;
|
|
27671
|
+
carry = carry / 256 >>> 0;
|
|
27672
|
+
}
|
|
27673
|
+
if (carry !== 0) {
|
|
27674
|
+
throw new Error("Non-zero carry");
|
|
27675
|
+
}
|
|
27676
|
+
length22 = i2;
|
|
27677
|
+
psz++;
|
|
27678
|
+
}
|
|
27679
|
+
if (source[psz] === " ") {
|
|
27680
|
+
return;
|
|
27681
|
+
}
|
|
27682
|
+
var it4 = size - length22;
|
|
27683
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
27684
|
+
it4++;
|
|
27685
|
+
}
|
|
27686
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
27687
|
+
var j2 = zeroes;
|
|
27688
|
+
while (it4 !== size) {
|
|
27689
|
+
vch[j2++] = b256[it4++];
|
|
27690
|
+
}
|
|
27691
|
+
return vch;
|
|
27692
|
+
}
|
|
27693
|
+
function decode52(string) {
|
|
27694
|
+
var buffer = decodeUnsafe(string);
|
|
27695
|
+
if (buffer) {
|
|
27696
|
+
return buffer;
|
|
27697
|
+
}
|
|
27698
|
+
throw new Error(`Non-${name} character`);
|
|
27699
|
+
}
|
|
27700
|
+
return {
|
|
27701
|
+
encode: encode32,
|
|
27702
|
+
decodeUnsafe,
|
|
27703
|
+
decode: decode52
|
|
27704
|
+
};
|
|
27705
|
+
}
|
|
27706
|
+
var src3 = base3;
|
|
27707
|
+
var _brrp__multiformats_scope_baseX3 = src3;
|
|
27708
|
+
var base_x_default3 = _brrp__multiformats_scope_baseX3;
|
|
27709
|
+
var Encoder3 = class {
|
|
27710
|
+
name;
|
|
27711
|
+
prefix;
|
|
27712
|
+
baseEncode;
|
|
27713
|
+
constructor(name, prefix, baseEncode) {
|
|
27714
|
+
this.name = name;
|
|
27715
|
+
this.prefix = prefix;
|
|
27716
|
+
this.baseEncode = baseEncode;
|
|
27717
|
+
}
|
|
27718
|
+
encode(bytes) {
|
|
27719
|
+
if (bytes instanceof Uint8Array) {
|
|
27720
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
27721
|
+
} else {
|
|
27722
|
+
throw Error("Unknown type, must be binary type");
|
|
27723
|
+
}
|
|
27724
|
+
}
|
|
27725
|
+
};
|
|
27726
|
+
var Decoder3 = class {
|
|
27727
|
+
name;
|
|
27728
|
+
prefix;
|
|
27729
|
+
baseDecode;
|
|
27730
|
+
prefixCodePoint;
|
|
27731
|
+
constructor(name, prefix, baseDecode) {
|
|
27732
|
+
this.name = name;
|
|
27733
|
+
this.prefix = prefix;
|
|
27734
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
27735
|
+
if (prefixCodePoint === void 0) {
|
|
27736
|
+
throw new Error("Invalid prefix character");
|
|
27737
|
+
}
|
|
27738
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
27739
|
+
this.baseDecode = baseDecode;
|
|
27740
|
+
}
|
|
27741
|
+
decode(text) {
|
|
27742
|
+
if (typeof text === "string") {
|
|
27743
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
27744
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
27745
|
+
}
|
|
27746
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
27747
|
+
} else {
|
|
27748
|
+
throw Error("Can only multibase decode strings");
|
|
27749
|
+
}
|
|
27750
|
+
}
|
|
27751
|
+
or(decoder) {
|
|
27752
|
+
return or3(this, decoder);
|
|
27753
|
+
}
|
|
27754
|
+
};
|
|
27755
|
+
var ComposedDecoder3 = class {
|
|
27756
|
+
decoders;
|
|
27757
|
+
constructor(decoders) {
|
|
27758
|
+
this.decoders = decoders;
|
|
27759
|
+
}
|
|
27760
|
+
or(decoder) {
|
|
27761
|
+
return or3(this, decoder);
|
|
27762
|
+
}
|
|
27763
|
+
decode(input) {
|
|
27764
|
+
const prefix = input[0];
|
|
27765
|
+
const decoder = this.decoders[prefix];
|
|
27766
|
+
if (decoder != null) {
|
|
27767
|
+
return decoder.decode(input);
|
|
27768
|
+
} else {
|
|
27769
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
27770
|
+
}
|
|
27771
|
+
}
|
|
27772
|
+
};
|
|
27773
|
+
function or3(left, right) {
|
|
27774
|
+
return new ComposedDecoder3({
|
|
27775
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
27776
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
27777
|
+
});
|
|
27778
|
+
}
|
|
27779
|
+
var Codec3 = class {
|
|
27780
|
+
name;
|
|
27781
|
+
prefix;
|
|
27782
|
+
baseEncode;
|
|
27783
|
+
baseDecode;
|
|
27784
|
+
encoder;
|
|
27785
|
+
decoder;
|
|
27786
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
27787
|
+
this.name = name;
|
|
27788
|
+
this.prefix = prefix;
|
|
27789
|
+
this.baseEncode = baseEncode;
|
|
27790
|
+
this.baseDecode = baseDecode;
|
|
27791
|
+
this.encoder = new Encoder3(name, prefix, baseEncode);
|
|
27792
|
+
this.decoder = new Decoder3(name, prefix, baseDecode);
|
|
27793
|
+
}
|
|
27794
|
+
encode(input) {
|
|
27795
|
+
return this.encoder.encode(input);
|
|
27796
|
+
}
|
|
27797
|
+
decode(input) {
|
|
27798
|
+
return this.decoder.decode(input);
|
|
27799
|
+
}
|
|
27800
|
+
};
|
|
27801
|
+
function from3({ name, prefix, encode: encode32, decode: decode52 }) {
|
|
27802
|
+
return new Codec3(name, prefix, encode32, decode52);
|
|
27803
|
+
}
|
|
27804
|
+
function baseX3({ name, prefix, alphabet }) {
|
|
27805
|
+
const { encode: encode32, decode: decode52 } = base_x_default3(alphabet, name);
|
|
27806
|
+
return from3({
|
|
27807
|
+
prefix,
|
|
27808
|
+
name,
|
|
27809
|
+
encode: encode32,
|
|
27810
|
+
decode: (text) => coerce4(decode52(text))
|
|
27811
|
+
});
|
|
27812
|
+
}
|
|
27813
|
+
function decode9(string, alphabetIdx, bitsPerChar, name) {
|
|
27814
|
+
let end = string.length;
|
|
27815
|
+
while (string[end - 1] === "=") {
|
|
27816
|
+
--end;
|
|
27817
|
+
}
|
|
27818
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
27819
|
+
let bits = 0;
|
|
27820
|
+
let buffer = 0;
|
|
27821
|
+
let written = 0;
|
|
27822
|
+
for (let i = 0; i < end; ++i) {
|
|
27823
|
+
const value = alphabetIdx[string[i]];
|
|
27824
|
+
if (value === void 0) {
|
|
27825
|
+
throw new SyntaxError(`Non-${name} character`);
|
|
27826
|
+
}
|
|
27827
|
+
buffer = buffer << bitsPerChar | value;
|
|
27828
|
+
bits += bitsPerChar;
|
|
27829
|
+
if (bits >= 8) {
|
|
27830
|
+
bits -= 8;
|
|
27831
|
+
out[written++] = 255 & buffer >> bits;
|
|
27832
|
+
}
|
|
27833
|
+
}
|
|
27834
|
+
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
27835
|
+
throw new SyntaxError("Unexpected end of data");
|
|
27836
|
+
}
|
|
27837
|
+
return out;
|
|
27838
|
+
}
|
|
27839
|
+
function encode5(data, alphabet, bitsPerChar) {
|
|
27840
|
+
const pad = alphabet[alphabet.length - 1] === "=";
|
|
27841
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
27842
|
+
let out = "";
|
|
27843
|
+
let bits = 0;
|
|
27844
|
+
let buffer = 0;
|
|
27845
|
+
for (let i = 0; i < data.length; ++i) {
|
|
27846
|
+
buffer = buffer << 8 | data[i];
|
|
27847
|
+
bits += 8;
|
|
27848
|
+
while (bits > bitsPerChar) {
|
|
27849
|
+
bits -= bitsPerChar;
|
|
27850
|
+
out += alphabet[mask & buffer >> bits];
|
|
27851
|
+
}
|
|
27852
|
+
}
|
|
27853
|
+
if (bits !== 0) {
|
|
27854
|
+
out += alphabet[mask & buffer << bitsPerChar - bits];
|
|
27855
|
+
}
|
|
27856
|
+
if (pad) {
|
|
27857
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
27858
|
+
out += "=";
|
|
27859
|
+
}
|
|
27860
|
+
}
|
|
27861
|
+
return out;
|
|
27862
|
+
}
|
|
27863
|
+
function createAlphabetIdx3(alphabet) {
|
|
27864
|
+
const alphabetIdx = {};
|
|
27865
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
27866
|
+
alphabetIdx[alphabet[i]] = i;
|
|
27867
|
+
}
|
|
27868
|
+
return alphabetIdx;
|
|
27869
|
+
}
|
|
27870
|
+
function rfc46483({ name, prefix, bitsPerChar, alphabet }) {
|
|
27871
|
+
const alphabetIdx = createAlphabetIdx3(alphabet);
|
|
27872
|
+
return from3({
|
|
27873
|
+
prefix,
|
|
27874
|
+
name,
|
|
27875
|
+
encode(input) {
|
|
27876
|
+
return encode5(input, alphabet, bitsPerChar);
|
|
27877
|
+
},
|
|
27878
|
+
decode(input) {
|
|
27879
|
+
return decode9(input, alphabetIdx, bitsPerChar, name);
|
|
27880
|
+
}
|
|
27881
|
+
});
|
|
27882
|
+
}
|
|
27883
|
+
var base323 = rfc46483({
|
|
27884
|
+
prefix: "b",
|
|
27885
|
+
name: "base32",
|
|
27886
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
27887
|
+
bitsPerChar: 5
|
|
27888
|
+
});
|
|
27889
|
+
var base32upper3 = rfc46483({
|
|
27890
|
+
prefix: "B",
|
|
27891
|
+
name: "base32upper",
|
|
27892
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
27893
|
+
bitsPerChar: 5
|
|
27894
|
+
});
|
|
27895
|
+
var base32pad3 = rfc46483({
|
|
27896
|
+
prefix: "c",
|
|
27897
|
+
name: "base32pad",
|
|
27898
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
27899
|
+
bitsPerChar: 5
|
|
27900
|
+
});
|
|
27901
|
+
var base32padupper3 = rfc46483({
|
|
27902
|
+
prefix: "C",
|
|
27903
|
+
name: "base32padupper",
|
|
27904
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
27905
|
+
bitsPerChar: 5
|
|
27906
|
+
});
|
|
27907
|
+
var base32hex3 = rfc46483({
|
|
27908
|
+
prefix: "v",
|
|
27909
|
+
name: "base32hex",
|
|
27910
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
27911
|
+
bitsPerChar: 5
|
|
27912
|
+
});
|
|
27913
|
+
var base32hexupper3 = rfc46483({
|
|
27914
|
+
prefix: "V",
|
|
27915
|
+
name: "base32hexupper",
|
|
27916
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
27917
|
+
bitsPerChar: 5
|
|
27918
|
+
});
|
|
27919
|
+
var base32hexpad3 = rfc46483({
|
|
27920
|
+
prefix: "t",
|
|
27921
|
+
name: "base32hexpad",
|
|
27922
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
27923
|
+
bitsPerChar: 5
|
|
27924
|
+
});
|
|
27925
|
+
var base32hexpadupper3 = rfc46483({
|
|
27926
|
+
prefix: "T",
|
|
27927
|
+
name: "base32hexpadupper",
|
|
27928
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
27929
|
+
bitsPerChar: 5
|
|
27930
|
+
});
|
|
27931
|
+
var base32z3 = rfc46483({
|
|
27932
|
+
prefix: "h",
|
|
27933
|
+
name: "base32z",
|
|
27934
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
27935
|
+
bitsPerChar: 5
|
|
27936
|
+
});
|
|
27937
|
+
var base363 = baseX3({
|
|
27938
|
+
prefix: "k",
|
|
27939
|
+
name: "base36",
|
|
27940
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
27941
|
+
});
|
|
27942
|
+
var base36upper3 = baseX3({
|
|
27943
|
+
prefix: "K",
|
|
27944
|
+
name: "base36upper",
|
|
27945
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
27946
|
+
});
|
|
27947
|
+
var base58btc3 = baseX3({
|
|
27948
|
+
name: "base58btc",
|
|
27949
|
+
prefix: "z",
|
|
27950
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
27951
|
+
});
|
|
27952
|
+
var base58flickr3 = baseX3({
|
|
27953
|
+
name: "base58flickr",
|
|
27954
|
+
prefix: "Z",
|
|
27955
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
27956
|
+
});
|
|
27957
|
+
var encode_13 = encode22;
|
|
27958
|
+
var MSB3 = 128;
|
|
27959
|
+
var REST3 = 127;
|
|
27960
|
+
var MSBALL3 = ~REST3;
|
|
27961
|
+
var INT3 = Math.pow(2, 31);
|
|
27962
|
+
function encode22(num, out, offset) {
|
|
27963
|
+
out = out || [];
|
|
27964
|
+
offset = offset || 0;
|
|
27965
|
+
var oldOffset = offset;
|
|
27966
|
+
while (num >= INT3) {
|
|
27967
|
+
out[offset++] = num & 255 | MSB3;
|
|
27968
|
+
num /= 128;
|
|
27969
|
+
}
|
|
27970
|
+
while (num & MSBALL3) {
|
|
27971
|
+
out[offset++] = num & 255 | MSB3;
|
|
27972
|
+
num >>>= 7;
|
|
27973
|
+
}
|
|
27974
|
+
out[offset] = num | 0;
|
|
27975
|
+
encode22.bytes = offset - oldOffset + 1;
|
|
27976
|
+
return out;
|
|
27977
|
+
}
|
|
27978
|
+
var decode22 = read3;
|
|
27979
|
+
var MSB$13 = 128;
|
|
27980
|
+
var REST$13 = 127;
|
|
27981
|
+
function read3(buf, offset) {
|
|
27982
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
27983
|
+
do {
|
|
27984
|
+
if (counter >= l) {
|
|
27985
|
+
read3.bytes = 0;
|
|
27986
|
+
throw new RangeError("Could not decode varint");
|
|
27987
|
+
}
|
|
27988
|
+
b = buf[counter++];
|
|
27989
|
+
res += shift < 28 ? (b & REST$13) << shift : (b & REST$13) * Math.pow(2, shift);
|
|
27990
|
+
shift += 7;
|
|
27991
|
+
} while (b >= MSB$13);
|
|
27992
|
+
read3.bytes = counter - offset;
|
|
27993
|
+
return res;
|
|
27994
|
+
}
|
|
27995
|
+
var N13 = Math.pow(2, 7);
|
|
27996
|
+
var N23 = Math.pow(2, 14);
|
|
27997
|
+
var N33 = Math.pow(2, 21);
|
|
27998
|
+
var N43 = Math.pow(2, 28);
|
|
27999
|
+
var N53 = Math.pow(2, 35);
|
|
28000
|
+
var N63 = Math.pow(2, 42);
|
|
28001
|
+
var N73 = Math.pow(2, 49);
|
|
28002
|
+
var N83 = Math.pow(2, 56);
|
|
28003
|
+
var N93 = Math.pow(2, 63);
|
|
28004
|
+
var length3 = function(value) {
|
|
28005
|
+
return value < N13 ? 1 : value < N23 ? 2 : value < N33 ? 3 : value < N43 ? 4 : value < N53 ? 5 : value < N63 ? 6 : value < N73 ? 7 : value < N83 ? 8 : value < N93 ? 9 : 10;
|
|
28006
|
+
};
|
|
28007
|
+
var varint3 = {
|
|
28008
|
+
encode: encode_13,
|
|
28009
|
+
decode: decode22,
|
|
28010
|
+
encodingLength: length3
|
|
28011
|
+
};
|
|
28012
|
+
var _brrp_varint3 = varint3;
|
|
28013
|
+
var varint_default3 = _brrp_varint3;
|
|
28014
|
+
function decode32(data, offset = 0) {
|
|
28015
|
+
const code22 = varint_default3.decode(data, offset);
|
|
28016
|
+
return [code22, varint_default3.decode.bytes];
|
|
28017
|
+
}
|
|
28018
|
+
function encodeTo3(int, target, offset = 0) {
|
|
28019
|
+
varint_default3.encode(int, target, offset);
|
|
28020
|
+
return target;
|
|
28021
|
+
}
|
|
28022
|
+
function encodingLength3(int) {
|
|
28023
|
+
return varint_default3.encodingLength(int);
|
|
28024
|
+
}
|
|
28025
|
+
function create3(code22, digest2) {
|
|
28026
|
+
const size = digest2.byteLength;
|
|
28027
|
+
const sizeOffset = encodingLength3(code22);
|
|
28028
|
+
const digestOffset = sizeOffset + encodingLength3(size);
|
|
28029
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
28030
|
+
encodeTo3(code22, bytes, 0);
|
|
28031
|
+
encodeTo3(size, bytes, sizeOffset);
|
|
28032
|
+
bytes.set(digest2, digestOffset);
|
|
28033
|
+
return new Digest3(code22, size, digest2, bytes);
|
|
28034
|
+
}
|
|
28035
|
+
function decode42(multihash) {
|
|
28036
|
+
const bytes = coerce4(multihash);
|
|
28037
|
+
const [code22, sizeOffset] = decode32(bytes);
|
|
28038
|
+
const [size, digestOffset] = decode32(bytes.subarray(sizeOffset));
|
|
28039
|
+
const digest2 = bytes.subarray(sizeOffset + digestOffset);
|
|
28040
|
+
if (digest2.byteLength !== size) {
|
|
28041
|
+
throw new Error("Incorrect length");
|
|
28042
|
+
}
|
|
28043
|
+
return new Digest3(code22, size, digest2, bytes);
|
|
28044
|
+
}
|
|
28045
|
+
function equals22(a, b) {
|
|
28046
|
+
if (a === b) {
|
|
28047
|
+
return true;
|
|
28048
|
+
} else {
|
|
28049
|
+
const data = b;
|
|
28050
|
+
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals5(a.bytes, data.bytes);
|
|
28051
|
+
}
|
|
28052
|
+
}
|
|
28053
|
+
var Digest3 = class {
|
|
28054
|
+
code;
|
|
28055
|
+
size;
|
|
28056
|
+
digest;
|
|
28057
|
+
bytes;
|
|
28058
|
+
/**
|
|
28059
|
+
* Creates a multihash digest.
|
|
28060
|
+
*/
|
|
28061
|
+
constructor(code22, size, digest2, bytes) {
|
|
28062
|
+
this.code = code22;
|
|
28063
|
+
this.size = size;
|
|
28064
|
+
this.digest = digest2;
|
|
28065
|
+
this.bytes = bytes;
|
|
28066
|
+
}
|
|
28067
|
+
};
|
|
28068
|
+
function format3(link2, base22) {
|
|
28069
|
+
const { bytes, version } = link2;
|
|
28070
|
+
switch (version) {
|
|
28071
|
+
case 0:
|
|
28072
|
+
return toStringV03(bytes, baseCache3(link2), base22 ?? base58btc3.encoder);
|
|
28073
|
+
default:
|
|
28074
|
+
return toStringV13(bytes, baseCache3(link2), base22 ?? base323.encoder);
|
|
28075
|
+
}
|
|
28076
|
+
}
|
|
28077
|
+
var cache3 = /* @__PURE__ */ new WeakMap();
|
|
28078
|
+
function baseCache3(cid) {
|
|
28079
|
+
const baseCache22 = cache3.get(cid);
|
|
28080
|
+
if (baseCache22 == null) {
|
|
28081
|
+
const baseCache32 = /* @__PURE__ */ new Map();
|
|
28082
|
+
cache3.set(cid, baseCache32);
|
|
28083
|
+
return baseCache32;
|
|
28084
|
+
}
|
|
28085
|
+
return baseCache22;
|
|
28086
|
+
}
|
|
28087
|
+
var CID3 = class _CID3 {
|
|
28088
|
+
code;
|
|
28089
|
+
version;
|
|
28090
|
+
multihash;
|
|
28091
|
+
bytes;
|
|
28092
|
+
"/";
|
|
28093
|
+
/**
|
|
28094
|
+
* @param version - Version of the CID
|
|
28095
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
28096
|
+
* @param multihash - (Multi)hash of the of the content.
|
|
28097
|
+
*/
|
|
28098
|
+
constructor(version, code22, multihash, bytes) {
|
|
28099
|
+
this.code = code22;
|
|
28100
|
+
this.version = version;
|
|
28101
|
+
this.multihash = multihash;
|
|
28102
|
+
this.bytes = bytes;
|
|
28103
|
+
this["/"] = bytes;
|
|
28104
|
+
}
|
|
28105
|
+
/**
|
|
28106
|
+
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
28107
|
+
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
28108
|
+
*
|
|
28109
|
+
* @deprecated
|
|
28110
|
+
*/
|
|
28111
|
+
get asCID() {
|
|
28112
|
+
return this;
|
|
28113
|
+
}
|
|
28114
|
+
// ArrayBufferView
|
|
28115
|
+
get byteOffset() {
|
|
28116
|
+
return this.bytes.byteOffset;
|
|
28117
|
+
}
|
|
28118
|
+
// ArrayBufferView
|
|
28119
|
+
get byteLength() {
|
|
28120
|
+
return this.bytes.byteLength;
|
|
28121
|
+
}
|
|
28122
|
+
toV0() {
|
|
28123
|
+
switch (this.version) {
|
|
28124
|
+
case 0: {
|
|
28125
|
+
return this;
|
|
28126
|
+
}
|
|
28127
|
+
case 1: {
|
|
28128
|
+
const { code: code22, multihash } = this;
|
|
28129
|
+
if (code22 !== DAG_PB_CODE3) {
|
|
28130
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
28131
|
+
}
|
|
28132
|
+
if (multihash.code !== SHA_256_CODE3) {
|
|
28133
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
28134
|
+
}
|
|
28135
|
+
return _CID3.createV0(multihash);
|
|
28136
|
+
}
|
|
28137
|
+
default: {
|
|
28138
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
28139
|
+
}
|
|
28140
|
+
}
|
|
28141
|
+
}
|
|
28142
|
+
toV1() {
|
|
28143
|
+
switch (this.version) {
|
|
28144
|
+
case 0: {
|
|
28145
|
+
const { code: code22, digest: digest2 } = this.multihash;
|
|
28146
|
+
const multihash = create3(code22, digest2);
|
|
28147
|
+
return _CID3.createV1(this.code, multihash);
|
|
28148
|
+
}
|
|
28149
|
+
case 1: {
|
|
28150
|
+
return this;
|
|
28151
|
+
}
|
|
28152
|
+
default: {
|
|
28153
|
+
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
28154
|
+
}
|
|
28155
|
+
}
|
|
28156
|
+
}
|
|
28157
|
+
equals(other) {
|
|
28158
|
+
return _CID3.equals(this, other);
|
|
28159
|
+
}
|
|
28160
|
+
static equals(self, other) {
|
|
28161
|
+
const unknown = other;
|
|
28162
|
+
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals22(self.multihash, unknown.multihash);
|
|
28163
|
+
}
|
|
28164
|
+
toString(base22) {
|
|
28165
|
+
return format3(this, base22);
|
|
28166
|
+
}
|
|
28167
|
+
toJSON() {
|
|
28168
|
+
return { "/": format3(this) };
|
|
28169
|
+
}
|
|
28170
|
+
link() {
|
|
28171
|
+
return this;
|
|
28172
|
+
}
|
|
28173
|
+
[Symbol.toStringTag] = "CID";
|
|
28174
|
+
// Legacy
|
|
28175
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
28176
|
+
return `CID(${this.toString()})`;
|
|
28177
|
+
}
|
|
28178
|
+
/**
|
|
28179
|
+
* Takes any input `value` and returns a `CID` instance if it was
|
|
28180
|
+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
28181
|
+
* it will return value back. If `value` is not instance of this CID
|
|
28182
|
+
* class, but is compatible CID it will return new instance of this
|
|
28183
|
+
* `CID` class. Otherwise returns null.
|
|
28184
|
+
*
|
|
28185
|
+
* This allows two different incompatible versions of CID library to
|
|
28186
|
+
* co-exist and interop as long as binary interface is compatible.
|
|
28187
|
+
*/
|
|
28188
|
+
static asCID(input) {
|
|
28189
|
+
if (input == null) {
|
|
28190
|
+
return null;
|
|
28191
|
+
}
|
|
28192
|
+
const value = input;
|
|
28193
|
+
if (value instanceof _CID3) {
|
|
28194
|
+
return value;
|
|
28195
|
+
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
28196
|
+
const { version, code: code22, multihash, bytes } = value;
|
|
28197
|
+
return new _CID3(version, code22, multihash, bytes ?? encodeCID3(version, code22, multihash.bytes));
|
|
28198
|
+
} else if (value[cidSymbol3] === true) {
|
|
28199
|
+
const { version, multihash, code: code22 } = value;
|
|
28200
|
+
const digest2 = decode42(multihash);
|
|
28201
|
+
return _CID3.create(version, code22, digest2);
|
|
28202
|
+
} else {
|
|
28203
|
+
return null;
|
|
28204
|
+
}
|
|
28205
|
+
}
|
|
28206
|
+
/**
|
|
28207
|
+
* @param version - Version of the CID
|
|
28208
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
28209
|
+
* @param digest - (Multi)hash of the of the content.
|
|
28210
|
+
*/
|
|
28211
|
+
static create(version, code22, digest2) {
|
|
28212
|
+
if (typeof code22 !== "number") {
|
|
28213
|
+
throw new Error("String codecs are no longer supported");
|
|
28214
|
+
}
|
|
28215
|
+
if (!(digest2.bytes instanceof Uint8Array)) {
|
|
28216
|
+
throw new Error("Invalid digest");
|
|
28217
|
+
}
|
|
28218
|
+
switch (version) {
|
|
28219
|
+
case 0: {
|
|
28220
|
+
if (code22 !== DAG_PB_CODE3) {
|
|
28221
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE3}) block encoding`);
|
|
28222
|
+
} else {
|
|
28223
|
+
return new _CID3(version, code22, digest2, digest2.bytes);
|
|
28224
|
+
}
|
|
28225
|
+
}
|
|
28226
|
+
case 1: {
|
|
28227
|
+
const bytes = encodeCID3(version, code22, digest2.bytes);
|
|
28228
|
+
return new _CID3(version, code22, digest2, bytes);
|
|
28229
|
+
}
|
|
28230
|
+
default: {
|
|
28231
|
+
throw new Error("Invalid version");
|
|
28232
|
+
}
|
|
28233
|
+
}
|
|
28234
|
+
}
|
|
28235
|
+
/**
|
|
28236
|
+
* Simplified version of `create` for CIDv0.
|
|
28237
|
+
*/
|
|
28238
|
+
static createV0(digest2) {
|
|
28239
|
+
return _CID3.create(0, DAG_PB_CODE3, digest2);
|
|
28240
|
+
}
|
|
28241
|
+
/**
|
|
28242
|
+
* Simplified version of `create` for CIDv1.
|
|
28243
|
+
*
|
|
28244
|
+
* @param code - Content encoding format code.
|
|
28245
|
+
* @param digest - Multihash of the content.
|
|
28246
|
+
*/
|
|
28247
|
+
static createV1(code22, digest2) {
|
|
28248
|
+
return _CID3.create(1, code22, digest2);
|
|
28249
|
+
}
|
|
28250
|
+
/**
|
|
28251
|
+
* Decoded a CID from its binary representation. The byte array must contain
|
|
28252
|
+
* only the CID with no additional bytes.
|
|
28253
|
+
*
|
|
28254
|
+
* An error will be thrown if the bytes provided do not contain a valid
|
|
28255
|
+
* binary representation of a CID.
|
|
28256
|
+
*/
|
|
28257
|
+
static decode(bytes) {
|
|
28258
|
+
const [cid, remainder] = _CID3.decodeFirst(bytes);
|
|
28259
|
+
if (remainder.length !== 0) {
|
|
28260
|
+
throw new Error("Incorrect length");
|
|
28261
|
+
}
|
|
28262
|
+
return cid;
|
|
28263
|
+
}
|
|
28264
|
+
/**
|
|
28265
|
+
* Decoded a CID from its binary representation at the beginning of a byte
|
|
28266
|
+
* array.
|
|
28267
|
+
*
|
|
28268
|
+
* Returns an array with the first element containing the CID and the second
|
|
28269
|
+
* element containing the remainder of the original byte array. The remainder
|
|
28270
|
+
* will be a zero-length byte array if the provided bytes only contained a
|
|
28271
|
+
* binary CID representation.
|
|
28272
|
+
*/
|
|
28273
|
+
static decodeFirst(bytes) {
|
|
28274
|
+
const specs = _CID3.inspectBytes(bytes);
|
|
28275
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
28276
|
+
const multihashBytes = coerce4(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
28277
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
28278
|
+
throw new Error("Incorrect length");
|
|
28279
|
+
}
|
|
28280
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
28281
|
+
const digest2 = new Digest3(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
28282
|
+
const cid = specs.version === 0 ? _CID3.createV0(digest2) : _CID3.createV1(specs.codec, digest2);
|
|
28283
|
+
return [cid, bytes.subarray(specs.size)];
|
|
28284
|
+
}
|
|
28285
|
+
/**
|
|
28286
|
+
* Inspect the initial bytes of a CID to determine its properties.
|
|
28287
|
+
*
|
|
28288
|
+
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
28289
|
+
* bytes but for larger multicodec code values and larger multihash digest
|
|
28290
|
+
* lengths these varints can be quite large. It is recommended that at least
|
|
28291
|
+
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
28292
|
+
* inspection.
|
|
28293
|
+
*/
|
|
28294
|
+
static inspectBytes(initialBytes) {
|
|
28295
|
+
let offset = 0;
|
|
28296
|
+
const next = () => {
|
|
28297
|
+
const [i, length22] = decode32(initialBytes.subarray(offset));
|
|
28298
|
+
offset += length22;
|
|
28299
|
+
return i;
|
|
28300
|
+
};
|
|
28301
|
+
let version = next();
|
|
28302
|
+
let codec = DAG_PB_CODE3;
|
|
28303
|
+
if (version === 18) {
|
|
28304
|
+
version = 0;
|
|
28305
|
+
offset = 0;
|
|
28306
|
+
} else {
|
|
28307
|
+
codec = next();
|
|
28308
|
+
}
|
|
28309
|
+
if (version !== 0 && version !== 1) {
|
|
28310
|
+
throw new RangeError(`Invalid CID version ${version}`);
|
|
28311
|
+
}
|
|
28312
|
+
const prefixSize = offset;
|
|
28313
|
+
const multihashCode = next();
|
|
28314
|
+
const digestSize = next();
|
|
28315
|
+
const size = offset + digestSize;
|
|
28316
|
+
const multihashSize = size - prefixSize;
|
|
28317
|
+
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
28318
|
+
}
|
|
28319
|
+
/**
|
|
28320
|
+
* Takes cid in a string representation and creates an instance. If `base`
|
|
28321
|
+
* decoder is not provided will use a default from the configuration. It will
|
|
28322
|
+
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
28323
|
+
* a default decoder).
|
|
28324
|
+
*/
|
|
28325
|
+
static parse(source, base22) {
|
|
28326
|
+
const [prefix, bytes] = parseCIDtoBytes3(source, base22);
|
|
28327
|
+
const cid = _CID3.decode(bytes);
|
|
28328
|
+
if (cid.version === 0 && source[0] !== "Q") {
|
|
28329
|
+
throw Error("Version 0 CID string must not include multibase prefix");
|
|
28330
|
+
}
|
|
28331
|
+
baseCache3(cid).set(prefix, source);
|
|
28332
|
+
return cid;
|
|
28333
|
+
}
|
|
28334
|
+
};
|
|
28335
|
+
function parseCIDtoBytes3(source, base22) {
|
|
28336
|
+
switch (source[0]) {
|
|
28337
|
+
// CIDv0 is parsed differently
|
|
28338
|
+
case "Q": {
|
|
28339
|
+
const decoder = base22 ?? base58btc3;
|
|
28340
|
+
return [
|
|
28341
|
+
base58btc3.prefix,
|
|
28342
|
+
decoder.decode(`${base58btc3.prefix}${source}`)
|
|
28343
|
+
];
|
|
28344
|
+
}
|
|
28345
|
+
case base58btc3.prefix: {
|
|
28346
|
+
const decoder = base22 ?? base58btc3;
|
|
28347
|
+
return [base58btc3.prefix, decoder.decode(source)];
|
|
28348
|
+
}
|
|
28349
|
+
case base323.prefix: {
|
|
28350
|
+
const decoder = base22 ?? base323;
|
|
28351
|
+
return [base323.prefix, decoder.decode(source)];
|
|
28352
|
+
}
|
|
28353
|
+
case base363.prefix: {
|
|
28354
|
+
const decoder = base22 ?? base363;
|
|
28355
|
+
return [base363.prefix, decoder.decode(source)];
|
|
28356
|
+
}
|
|
28357
|
+
default: {
|
|
28358
|
+
if (base22 == null) {
|
|
28359
|
+
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
28360
|
+
}
|
|
28361
|
+
return [source[0], base22.decode(source)];
|
|
28362
|
+
}
|
|
28363
|
+
}
|
|
28364
|
+
}
|
|
28365
|
+
function toStringV03(bytes, cache22, base22) {
|
|
28366
|
+
const { prefix } = base22;
|
|
28367
|
+
if (prefix !== base58btc3.prefix) {
|
|
28368
|
+
throw Error(`Cannot string encode V0 in ${base22.name} encoding`);
|
|
28369
|
+
}
|
|
28370
|
+
const cid = cache22.get(prefix);
|
|
28371
|
+
if (cid == null) {
|
|
28372
|
+
const cid2 = base22.encode(bytes).slice(1);
|
|
28373
|
+
cache22.set(prefix, cid2);
|
|
28374
|
+
return cid2;
|
|
28375
|
+
} else {
|
|
28376
|
+
return cid;
|
|
28377
|
+
}
|
|
28378
|
+
}
|
|
28379
|
+
function toStringV13(bytes, cache22, base22) {
|
|
28380
|
+
const { prefix } = base22;
|
|
28381
|
+
const cid = cache22.get(prefix);
|
|
28382
|
+
if (cid == null) {
|
|
28383
|
+
const cid2 = base22.encode(bytes);
|
|
28384
|
+
cache22.set(prefix, cid2);
|
|
28385
|
+
return cid2;
|
|
28386
|
+
} else {
|
|
28387
|
+
return cid;
|
|
28388
|
+
}
|
|
28389
|
+
}
|
|
28390
|
+
var DAG_PB_CODE3 = 112;
|
|
28391
|
+
var SHA_256_CODE3 = 18;
|
|
28392
|
+
function encodeCID3(version, code22, multihash) {
|
|
28393
|
+
const codeOffset = encodingLength3(version);
|
|
28394
|
+
const hashOffset = codeOffset + encodingLength3(code22);
|
|
28395
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
28396
|
+
encodeTo3(version, bytes, 0);
|
|
28397
|
+
encodeTo3(code22, bytes, codeOffset);
|
|
28398
|
+
bytes.set(multihash, hashOffset);
|
|
28399
|
+
return bytes;
|
|
28400
|
+
}
|
|
28401
|
+
var cidSymbol3 = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
|
|
28402
|
+
var code2 = 85;
|
|
28403
|
+
var SHA256_CODE2 = 18;
|
|
28404
|
+
function isCanonicalRawCid2(cidString) {
|
|
28405
|
+
let cid;
|
|
28406
|
+
try {
|
|
28407
|
+
cid = CID3.parse(cidString);
|
|
28408
|
+
} catch {
|
|
28409
|
+
return false;
|
|
28410
|
+
}
|
|
28411
|
+
return cid.version === 1 && cid.code === code2 && cid.multihash.code === SHA256_CODE2 && cid.toString() === cidString;
|
|
28412
|
+
}
|
|
28413
|
+
var base642 = rfc46483({
|
|
28414
|
+
prefix: "m",
|
|
28415
|
+
name: "base64",
|
|
28416
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
28417
|
+
bitsPerChar: 6
|
|
28418
|
+
});
|
|
28419
|
+
var base64pad2 = rfc46483({
|
|
28420
|
+
prefix: "M",
|
|
28421
|
+
name: "base64pad",
|
|
28422
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
28423
|
+
bitsPerChar: 6
|
|
28424
|
+
});
|
|
28425
|
+
var base64url2 = rfc46483({
|
|
28426
|
+
prefix: "u",
|
|
28427
|
+
name: "base64url",
|
|
28428
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
28429
|
+
bitsPerChar: 6
|
|
28430
|
+
});
|
|
28431
|
+
var base64urlpad2 = rfc46483({
|
|
28432
|
+
prefix: "U",
|
|
28433
|
+
name: "base64urlpad",
|
|
28434
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
28435
|
+
bitsPerChar: 6
|
|
28436
|
+
});
|
|
28437
|
+
function fromBase64Url2(text) {
|
|
28438
|
+
const bytes = base64url2.baseDecode(text);
|
|
28439
|
+
if (base64url2.baseEncode(bytes) !== text) {
|
|
28440
|
+
throw new TypeError("non-canonical base64url input");
|
|
28441
|
+
}
|
|
28442
|
+
return bytes;
|
|
27390
28443
|
}
|
|
27391
|
-
|
|
27392
|
-
|
|
27393
|
-
|
|
27394
|
-
|
|
27395
|
-
|
|
27396
|
-
|
|
27397
|
-
|
|
27398
|
-
|
|
27399
|
-
|
|
27400
|
-
if (!Number.isSafeInteger(attemptsLimit) || attemptsLimit < 1 || attemptsLimit > 8) throw new ShareNotifyError("maxAttempts is invalid");
|
|
27401
|
-
let attempts = 0;
|
|
27402
|
-
let lastError;
|
|
27403
|
-
while (attempts < attemptsLimit) {
|
|
27404
|
-
if (input.signal?.aborted) throw new ShareNotifyError("share delivery was cancelled");
|
|
27405
|
-
attempts += 1;
|
|
27406
|
-
try {
|
|
27407
|
-
const state = await input.adapter.deliver({ shareId: input.shareId, recipient, idempotencyKey, ...input.record === void 0 ? {} : { record: input.record }, ...input.signal === void 0 ? {} : { signal: input.signal } });
|
|
27408
|
-
return { protocol: "tinycloud-share", version: 1, shareId: input.shareId, state, idempotencyKey, attempts };
|
|
27409
|
-
} catch (error) {
|
|
27410
|
-
lastError = error;
|
|
27411
|
-
}
|
|
28444
|
+
function utf8Bytes2(text) {
|
|
28445
|
+
return new TextEncoder().encode(text);
|
|
28446
|
+
}
|
|
28447
|
+
var ED25519_MULTICODEC_PREFIX2 = Uint8Array.of(237, 1);
|
|
28448
|
+
function decodeBase64UrlOrNull2(value) {
|
|
28449
|
+
try {
|
|
28450
|
+
return fromBase64Url2(value);
|
|
28451
|
+
} catch {
|
|
28452
|
+
return null;
|
|
27412
28453
|
}
|
|
27413
|
-
void lastError;
|
|
27414
|
-
return { protocol: "tinycloud-share", version: 1, shareId: input.shareId, state: "partial-failure", idempotencyKey, attempts, retryable: true };
|
|
27415
28454
|
}
|
|
27416
|
-
|
|
27417
|
-
|
|
27418
|
-
|
|
27419
|
-
|
|
27420
|
-
|
|
27421
|
-
|
|
27422
|
-
|
|
28455
|
+
var base64UrlString2 = () => external_exports.string().refine((value) => decodeBase64UrlOrNull2(value) !== null, {
|
|
28456
|
+
message: "expected strictly-decodable unpadded base64url"
|
|
28457
|
+
});
|
|
28458
|
+
function isCanonicalHttpsOrigin2(value) {
|
|
28459
|
+
let url;
|
|
28460
|
+
try {
|
|
28461
|
+
url = new URL(value);
|
|
28462
|
+
} catch {
|
|
28463
|
+
return false;
|
|
28464
|
+
}
|
|
28465
|
+
return url.protocol === "https:" && url.origin === value;
|
|
27423
28466
|
}
|
|
27424
|
-
|
|
27425
|
-
|
|
27426
|
-
|
|
28467
|
+
var sessionJwkCommonFields2 = {
|
|
28468
|
+
alg: external_exports.string().min(1).optional(),
|
|
28469
|
+
use: external_exports.string().min(1).optional(),
|
|
28470
|
+
key_ops: external_exports.array(external_exports.string().min(1)).optional(),
|
|
28471
|
+
kid: external_exports.string().min(1).optional(),
|
|
28472
|
+
ext: external_exports.boolean().optional()
|
|
28473
|
+
};
|
|
28474
|
+
var okpPrivateJwkSchema2 = external_exports.object({
|
|
28475
|
+
kty: external_exports.literal("OKP"),
|
|
28476
|
+
crv: external_exports.string().min(1),
|
|
28477
|
+
x: base64UrlString2(),
|
|
28478
|
+
d: base64UrlString2(),
|
|
28479
|
+
...sessionJwkCommonFields2
|
|
28480
|
+
}).strict();
|
|
28481
|
+
var ecPrivateJwkSchema2 = external_exports.object({
|
|
28482
|
+
kty: external_exports.literal("EC"),
|
|
28483
|
+
crv: external_exports.string().min(1),
|
|
28484
|
+
x: base64UrlString2(),
|
|
28485
|
+
y: base64UrlString2(),
|
|
28486
|
+
d: base64UrlString2(),
|
|
28487
|
+
...sessionJwkCommonFields2
|
|
28488
|
+
}).strict();
|
|
28489
|
+
var sessionJwkSchema2 = external_exports.discriminatedUnion("kty", [
|
|
28490
|
+
okpPrivateJwkSchema2,
|
|
28491
|
+
ecPrivateJwkSchema2
|
|
28492
|
+
]);
|
|
28493
|
+
var policyTargetSchema2 = external_exports.object({
|
|
28494
|
+
kind: external_exports.literal("policy"),
|
|
28495
|
+
policyCid: external_exports.string().min(1),
|
|
28496
|
+
/** Canonical policy bytes, base64url-encoded (bytes are not JSON). */
|
|
28497
|
+
policyBytes: base64UrlString2()
|
|
28498
|
+
}).strict();
|
|
28499
|
+
var bearerKeyTargetSchema2 = external_exports.object({
|
|
28500
|
+
kind: external_exports.literal("bearerKey"),
|
|
28501
|
+
sessionJwk: sessionJwkSchema2
|
|
28502
|
+
}).strict();
|
|
28503
|
+
var recipientDidTargetSchema2 = external_exports.object({
|
|
28504
|
+
kind: external_exports.literal("recipientDid"),
|
|
28505
|
+
did: external_exports.string().regex(/^did:[a-z0-9]+:.+$/, "expected a DID")
|
|
28506
|
+
}).strict();
|
|
28507
|
+
var authorizationTargetSchema2 = external_exports.discriminatedUnion("kind", [
|
|
28508
|
+
policyTargetSchema2,
|
|
28509
|
+
bearerKeyTargetSchema2,
|
|
28510
|
+
recipientDidTargetSchema2
|
|
28511
|
+
]);
|
|
28512
|
+
function isCanonicalResourcePath2(value) {
|
|
28513
|
+
if (value.length === 0) return false;
|
|
28514
|
+
if (/[\u0000-\u001f\u007f\\]/.test(value)) return false;
|
|
28515
|
+
if (/%2f|%5c|%2e/i.test(value)) return false;
|
|
28516
|
+
return value.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
27427
28517
|
}
|
|
27428
|
-
function
|
|
27429
|
-
|
|
27430
|
-
if (typeof envelope !== "object" || envelope === null || Array.isArray(envelope)) return record.target.nodeAudience;
|
|
27431
|
-
const binding = envelope.attestedEnforcerBinding;
|
|
27432
|
-
if (typeof binding !== "object" || binding === null || Array.isArray(binding)) return record.target.nodeAudience;
|
|
27433
|
-
const nodeAudience = binding.nodeAudience;
|
|
27434
|
-
return typeof nodeAudience === "string" ? nodeAudience : record.target.nodeAudience;
|
|
28518
|
+
function isCanonicalPathSegment2(value) {
|
|
28519
|
+
return isCanonicalResourcePath2(value) && !value.includes("/");
|
|
27435
28520
|
}
|
|
27436
|
-
|
|
27437
|
-
|
|
27438
|
-
|
|
27439
|
-
|
|
27440
|
-
const
|
|
27441
|
-
if (
|
|
27442
|
-
|
|
27443
|
-
|
|
27444
|
-
|
|
27445
|
-
|
|
27446
|
-
if (input.record.ownerDid === void 0) return { state: "unsupported", target, reason: "share has no Policy/v3 owner receipt", code: "unsupported-target" };
|
|
27447
|
-
if (input.adapter.revokePolicyRoot === void 0) return { state: "unsupported", target, reason: "Policy/v3 root revocation authority is required", code: "unsupported-target" };
|
|
27448
|
-
await input.adapter.revokePolicyRoot({
|
|
27449
|
-
rootCid: delegationCid,
|
|
27450
|
-
targetRole: scope === "ancestor" ? "policy-authority" : "policy-enforcement",
|
|
27451
|
-
ownerDid: input.record.ownerDid,
|
|
27452
|
-
nodeOrigin: input.record.target.origin,
|
|
27453
|
-
nodeAudience: policyNodeAudience(input.record)
|
|
28521
|
+
var resourceSelectorSchema2 = external_exports.object({
|
|
28522
|
+
kind: external_exports.union([external_exports.literal("exact"), external_exports.literal("prefix")]),
|
|
28523
|
+
path: external_exports.string().min(1)
|
|
28524
|
+
}).strict().superRefine((selector, ctx) => {
|
|
28525
|
+
const body = selector.kind === "prefix" && selector.path.endsWith("/") ? selector.path.slice(0, -1) : selector.path;
|
|
28526
|
+
if (!isCanonicalResourcePath2(body)) {
|
|
28527
|
+
ctx.addIssue({
|
|
28528
|
+
code: external_exports.ZodIssueCode.custom,
|
|
28529
|
+
path: ["path"],
|
|
28530
|
+
message: "expected a canonical resource path (non-empty segments, no . or .. segments, no //, no backslash, no %2f/%5c/%2e, no control chars)"
|
|
27454
28531
|
});
|
|
27455
28532
|
}
|
|
27456
|
-
|
|
27457
|
-
|
|
27458
|
-
|
|
27459
|
-
|
|
27460
|
-
|
|
27461
|
-
|
|
27462
|
-
|
|
27463
|
-
|
|
27464
|
-
|
|
27465
|
-
|
|
27466
|
-
|
|
27467
|
-
|
|
27468
|
-
|
|
27469
|
-
|
|
27470
|
-
|
|
27471
|
-
|
|
27472
|
-
|
|
27473
|
-
|
|
27474
|
-
|
|
28533
|
+
});
|
|
28534
|
+
var targetSchema2 = external_exports.object({
|
|
28535
|
+
origin: external_exports.string().refine(isCanonicalHttpsOrigin2, {
|
|
28536
|
+
message: "expected a canonical https origin (https://host[:port], nothing else)"
|
|
28537
|
+
}),
|
|
28538
|
+
nodeAudience: external_exports.string().min(1),
|
|
28539
|
+
spaceId: external_exports.string().refine(isCanonicalPathSegment2, {
|
|
28540
|
+
message: "expected a single canonical path segment (spaceId joins the resource URI; separators/traversal would alias grants)"
|
|
28541
|
+
}),
|
|
28542
|
+
resource: resourceSelectorSchema2
|
|
28543
|
+
}).strict();
|
|
28544
|
+
var displaySchema2 = external_exports.object({
|
|
28545
|
+
senderName: external_exports.string().optional(),
|
|
28546
|
+
filename: external_exports.string().optional(),
|
|
28547
|
+
recipientHint: external_exports.string().optional(),
|
|
28548
|
+
/**
|
|
28549
|
+
* Presentation preference only (viewer spec §1): may narrow, never widen;
|
|
28550
|
+
* capabilities always win.
|
|
28551
|
+
*/
|
|
28552
|
+
mode: external_exports.union([external_exports.literal("document"), external_exports.literal("source"), external_exports.literal("folder")]).optional()
|
|
28553
|
+
}).strict();
|
|
28554
|
+
var contentPointerSchema2 = external_exports.object({
|
|
28555
|
+
cid: external_exports.string().refine(isCanonicalRawCid2, {
|
|
28556
|
+
message: "expected a canonical CIDv1 raw sha2-256 base32 CID"
|
|
28557
|
+
}),
|
|
28558
|
+
key: external_exports.string().refine((value) => decodeBase64UrlOrNull2(value)?.length === 32, {
|
|
28559
|
+
message: "expected base64url decoding to exactly 32 bytes"
|
|
28560
|
+
})
|
|
28561
|
+
}).strict();
|
|
28562
|
+
var signatureSchema2 = external_exports.object({
|
|
28563
|
+
/** did:key of the sender's ed25519 signing key. */
|
|
28564
|
+
signerDid: external_exports.string().regex(/^did:key:z[1-9A-HJ-NP-Za-km-z]+$/, "expected a did:key"),
|
|
28565
|
+
algorithm: external_exports.literal("Ed25519"),
|
|
28566
|
+
/** base64url-encoded ed25519 signature over the JCS bytes of all other fields. */
|
|
28567
|
+
value: external_exports.string().refine((value) => decodeBase64UrlOrNull2(value)?.length === 64, {
|
|
28568
|
+
message: "expected base64url decoding to exactly 64 bytes"
|
|
28569
|
+
})
|
|
28570
|
+
}).strict();
|
|
28571
|
+
var unsignedShareEnvelopeSchema2 = external_exports.object({
|
|
28572
|
+
version: external_exports.literal(1),
|
|
28573
|
+
shareId: external_exports.string().min(1),
|
|
28574
|
+
/** Full signed delegation chain, opaque serialized form. */
|
|
28575
|
+
delegation: external_exports.string().min(1),
|
|
28576
|
+
authorizationTarget: authorizationTargetSchema2,
|
|
28577
|
+
target: targetSchema2,
|
|
28578
|
+
display: displaySchema2,
|
|
28579
|
+
/** ISO 8601 UTC datetime. Advisory here; enforcement is the delegation's. */
|
|
28580
|
+
expiry: external_exports.string().datetime(),
|
|
28581
|
+
/** Bearer-slice sealed-content pointer (see contentPointerSchema). */
|
|
28582
|
+
content: contentPointerSchema2.optional()
|
|
28583
|
+
}).strict();
|
|
28584
|
+
var shareEnvelopeSchema2 = unsignedShareEnvelopeSchema2.extend({ signature: signatureSchema2 }).strict();
|
|
28585
|
+
var recipientMatcherSchema2 = external_exports.discriminatedUnion("kind", [
|
|
28586
|
+
external_exports.object({ kind: external_exports.literal("exactEmail"), value: external_exports.string().min(3).regex(/^[^@\s]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/) }).strict(),
|
|
28587
|
+
external_exports.object({ kind: external_exports.literal("emailDomain"), value: external_exports.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/) }).strict(),
|
|
28588
|
+
external_exports.object({ kind: external_exports.literal("recipientDid"), value: external_exports.string().regex(/^did:[a-z0-9]+:.+$/) }).strict(),
|
|
28589
|
+
external_exports.object({ kind: external_exports.literal("policyDigest"), value: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/) }).strict(),
|
|
28590
|
+
external_exports.object({ kind: external_exports.literal("bearer") }).strict()
|
|
28591
|
+
]);
|
|
28592
|
+
var shareActionSchema2 = external_exports.union([external_exports.literal("read"), external_exports.literal("list"), external_exports.literal("edit")]);
|
|
28593
|
+
var kvContentSourceSchema2 = external_exports.object({
|
|
28594
|
+
kind: external_exports.literal("kv"),
|
|
28595
|
+
space: external_exports.string().min(1),
|
|
28596
|
+
path: external_exports.string().min(1),
|
|
28597
|
+
action: external_exports.literal("tinycloud.kv/get")
|
|
28598
|
+
}).strict();
|
|
28599
|
+
var sqlContentSourceSchema2 = external_exports.object({
|
|
28600
|
+
kind: external_exports.literal("sql"),
|
|
28601
|
+
space: external_exports.string().min(1),
|
|
28602
|
+
database: external_exports.string().min(1),
|
|
28603
|
+
path: external_exports.string().min(1),
|
|
28604
|
+
statement: external_exports.string().min(1),
|
|
28605
|
+
arguments: external_exports.record(external_exports.string(), external_exports.number().int()),
|
|
28606
|
+
argumentsDigest: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
28607
|
+
action: external_exports.literal("tinycloud.sql/read")
|
|
28608
|
+
}).strict();
|
|
28609
|
+
var contentSourceSchema2 = external_exports.discriminatedUnion("kind", [kvContentSourceSchema2, sqlContentSourceSchema2]);
|
|
28610
|
+
var v2TargetSchema2 = external_exports.object({
|
|
28611
|
+
origin: external_exports.string().refine(isCanonicalHttpsOrigin2, { message: "expected a canonical https origin" }),
|
|
28612
|
+
nodeAudience: external_exports.string().min(1),
|
|
28613
|
+
spaceId: external_exports.string().refine(isCanonicalPathSegment2, { message: "expected a canonical space id" })
|
|
28614
|
+
}).strict();
|
|
28615
|
+
var shareDecryptionSchema2 = external_exports.object({
|
|
28616
|
+
networkId: external_exports.string().min(1),
|
|
28617
|
+
action: external_exports.literal("tinycloud.encryption/decrypt")
|
|
28618
|
+
}).strict();
|
|
28619
|
+
var ownerAuthoritySchema2 = external_exports.object({
|
|
28620
|
+
registrationCid: external_exports.string().min(1),
|
|
28621
|
+
shareCid: external_exports.string().min(1),
|
|
28622
|
+
envelopeCid: external_exports.string().min(1),
|
|
28623
|
+
enforcementDelegation: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
28624
|
+
outerEnvelope: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
28625
|
+
/** Node-signed registration evidence; required by trusted policy adapters. */
|
|
28626
|
+
registrationReceipt: external_exports.object({
|
|
28627
|
+
registration: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
28628
|
+
proof: external_exports.record(external_exports.string(), external_exports.unknown())
|
|
28629
|
+
}).strict().optional()
|
|
28630
|
+
}).strict();
|
|
28631
|
+
var contentMetadataSchema2 = external_exports.object({
|
|
28632
|
+
mediaType: external_exports.string().min(1).max(128).optional(),
|
|
28633
|
+
byteLength: external_exports.number().int().nonnegative().max(100 * 1024 * 1024).optional(),
|
|
28634
|
+
filename: external_exports.string().min(1).max(255).optional(),
|
|
28635
|
+
encoding: external_exports.literal("utf-8").optional(),
|
|
28636
|
+
/** Encrypted presentation discriminator. The fixed entry point is index.html. */
|
|
28637
|
+
artifact: external_exports.literal("html").optional()
|
|
28638
|
+
}).strict();
|
|
28639
|
+
var deliveryEmailSchema2 = external_exports.string().email();
|
|
28640
|
+
var unsignedShareEnvelopeV2BaseSchema2 = external_exports.object({
|
|
28641
|
+
version: external_exports.literal(2),
|
|
28642
|
+
shareId: external_exports.string().min(1),
|
|
28643
|
+
recipientMatcher: recipientMatcherSchema2,
|
|
28644
|
+
deliveryEmail: deliveryEmailSchema2.optional(),
|
|
28645
|
+
actions: external_exports.array(shareActionSchema2).min(1).max(3),
|
|
28646
|
+
resource: resourceSelectorSchema2,
|
|
28647
|
+
target: v2TargetSchema2,
|
|
28648
|
+
delegationCid: external_exports.string().min(1),
|
|
28649
|
+
authorityMaterialHandle: external_exports.string().min(1),
|
|
28650
|
+
authorityMaterialDigest: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
28651
|
+
decryption: shareDecryptionSchema2.optional(),
|
|
28652
|
+
contentSource: contentSourceSchema2,
|
|
28653
|
+
contentSourceDigest: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
28654
|
+
authorizationTarget: authorizationTargetSchema2,
|
|
28655
|
+
display: displaySchema2,
|
|
28656
|
+
expiry: external_exports.string().datetime(),
|
|
28657
|
+
encrypted: external_exports.boolean(),
|
|
28658
|
+
content: contentPointerSchema2.optional(),
|
|
28659
|
+
metadata: contentMetadataSchema2,
|
|
28660
|
+
ownerAuthority: ownerAuthoritySchema2.optional()
|
|
28661
|
+
}).strict();
|
|
28662
|
+
function validateV2Invariants2(value, ctx) {
|
|
28663
|
+
const actions = [...value.actions];
|
|
28664
|
+
if (new Set(actions).size !== actions.length) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["actions"], message: "actions must be unique" });
|
|
28665
|
+
if (actions.some((action, index) => action !== ["read", "list", "edit"].filter((candidate) => actions.includes(candidate))[index])) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["actions"], message: "actions must be canonically ordered" });
|
|
28666
|
+
if (!value.encrypted && value.recipientMatcher.kind !== "policyDigest") ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["recipientMatcher"], message: "safe plaintext must carry only a matcher digest" });
|
|
28667
|
+
if (!value.encrypted && value.authorizationTarget.kind !== "policy") ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["encrypted"], message: "unencrypted content requires a policy target" });
|
|
28668
|
+
if (!value.encrypted && value.content !== void 0) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["content"], message: "policy-only plaintext cannot carry content" });
|
|
28669
|
+
if (value.encrypted && (value.metadata.mediaType === void 0 || value.metadata.filename === void 0 || value.metadata.byteLength === void 0)) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["metadata"], message: "encrypted shares must describe their content" });
|
|
28670
|
+
if (!value.encrypted && Object.keys(value.metadata).length !== 0) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["metadata"], message: "policy-only plaintext cannot describe content" });
|
|
28671
|
+
if (!value.encrypted && value.metadata.encoding !== void 0) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["metadata", "encoding"], message: "policy-only plaintext cannot carry content encoding" });
|
|
28672
|
+
if (value.metadata.artifact === "html" && (!value.encrypted || value.resource.kind !== "prefix" || !value.actions.includes("read") || !value.actions.includes("list"))) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["metadata", "artifact"], message: "html artifacts require an encrypted readable prefix" });
|
|
28673
|
+
if (!value.encrypted && (value.display.senderName !== void 0 || value.display.filename !== void 0 || value.display.recipientHint !== void 0)) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["display"], message: "policy-only plaintext cannot carry display metadata" });
|
|
28674
|
+
if (!value.encrypted && value.deliveryEmail !== void 0) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["deliveryEmail"], message: "policy-only plaintext cannot carry delivery metadata" });
|
|
28675
|
+
if (value.recipientMatcher.kind === "exactEmail" && value.deliveryEmail !== void 0 && value.deliveryEmail !== value.recipientMatcher.value) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["deliveryEmail"], message: "delivery email must match the exact matcher" });
|
|
28676
|
+
if (value.recipientMatcher.kind === "emailDomain" && value.deliveryEmail !== void 0 && value.deliveryEmail.toLowerCase().endsWith(`@${value.recipientMatcher.value}`) === false) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["deliveryEmail"], message: "delivery email must belong to the matcher domain" });
|
|
28677
|
+
if (value.contentSource.kind === "kv" && value.contentSource.action !== "tinycloud.kv/get") ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource"], message: "source action mismatch" });
|
|
28678
|
+
if (value.contentSource.kind === "sql" && value.contentSource.action !== "tinycloud.sql/read") ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource"], message: "source action mismatch" });
|
|
28679
|
+
}
|
|
28680
|
+
var unsignedShareEnvelopeV2Schema2 = unsignedShareEnvelopeV2BaseSchema2.superRefine(validateV2Invariants2);
|
|
28681
|
+
var shareEnvelopeV2Schema2 = unsignedShareEnvelopeV2BaseSchema2.extend({ signature: signatureSchema2 }).strict().superRefine(validateV2Invariants2);
|
|
28682
|
+
var unifiedResourceSchema2 = external_exports.string().refine((value) => {
|
|
28683
|
+
const marker = value.indexOf("/kv/");
|
|
28684
|
+
if (marker < 1) return false;
|
|
28685
|
+
const space = value.slice(0, marker);
|
|
28686
|
+
const legacy = space.startsWith("tinycloud://");
|
|
28687
|
+
if (legacy ? /[:/?#%]/.test(space.slice("tinycloud://".length)) : !space.startsWith("tinycloud:") || /[/?#%]/.test(space)) return false;
|
|
28688
|
+
const path = value.slice(marker + 4);
|
|
28689
|
+
return !path.startsWith("/") && !path.endsWith("/") && !path.includes("//") && path.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
28690
|
+
}, { message: "expected canonical TinyCloud KV resource" });
|
|
28691
|
+
var unifiedEncryptionNetworkSchema2 = external_exports.string().refine((value) => {
|
|
28692
|
+
if (!value.startsWith("urn:tinycloud:encryption:")) return false;
|
|
28693
|
+
const rest = value.slice("urn:tinycloud:encryption:".length);
|
|
28694
|
+
const separator = rest.lastIndexOf(":");
|
|
28695
|
+
const owner = separator < 0 ? "" : rest.slice(0, separator);
|
|
28696
|
+
const network = separator < 0 ? "" : rest.slice(separator + 1);
|
|
28697
|
+
return owner.startsWith("did:") && owner.length > 4 && network.length > 0 && !/[:/%?#\s]/.test(network);
|
|
28698
|
+
}, { message: "expected canonical TinyCloud encryption network" });
|
|
28699
|
+
var unifiedKvCapabilitySchema2 = external_exports.object({
|
|
28700
|
+
kind: external_exports.literal("kv"),
|
|
28701
|
+
resource: unifiedResourceSchema2,
|
|
28702
|
+
selector: external_exports.union([external_exports.literal("exact"), external_exports.literal("prefix")]),
|
|
28703
|
+
actions: external_exports.array(external_exports.union([
|
|
28704
|
+
external_exports.literal("tinycloud.kv/get"),
|
|
28705
|
+
external_exports.literal("tinycloud.kv/list"),
|
|
28706
|
+
external_exports.literal("tinycloud.kv/metadata"),
|
|
28707
|
+
external_exports.literal("tinycloud.kv/put")
|
|
28708
|
+
])).min(1)
|
|
28709
|
+
}).strict();
|
|
28710
|
+
var unifiedEncryptionCapabilitySchema2 = external_exports.object({
|
|
28711
|
+
kind: external_exports.literal("encryption"),
|
|
28712
|
+
resource: unifiedEncryptionNetworkSchema2,
|
|
28713
|
+
action: external_exports.literal("tinycloud.encryption/decrypt")
|
|
28714
|
+
}).strict();
|
|
28715
|
+
var unifiedCapabilitySchema2 = external_exports.union([unifiedKvCapabilitySchema2, unifiedEncryptionCapabilitySchema2]);
|
|
28716
|
+
var unifiedContentSourceSchema2 = external_exports.object({
|
|
28717
|
+
shareId: external_exports.string().min(1),
|
|
28718
|
+
kvResource: unifiedResourceSchema2,
|
|
28719
|
+
selector: external_exports.union([external_exports.literal("exact"), external_exports.literal("prefix")]),
|
|
28720
|
+
encryptionNetwork: unifiedEncryptionNetworkSchema2,
|
|
28721
|
+
encryptedSymmetricKeyDigestHex: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
28722
|
+
keyVersion: external_exports.number().int().positive(),
|
|
28723
|
+
mode: external_exports.union([external_exports.literal("mutable"), external_exports.literal("immutable")]),
|
|
28724
|
+
initialCiphertextDigestHex: external_exports.string().regex(/^[0-9a-f]{64}$/).optional()
|
|
28725
|
+
}).strict();
|
|
28726
|
+
var unifiedPolicyV1Schema2 = external_exports.object({
|
|
28727
|
+
schema: external_exports.literal("xyz.tinycloud.policy/policy/v1"),
|
|
28728
|
+
policyId: external_exports.string().regex(/^pol_[a-z2-7]+$/),
|
|
28729
|
+
ownerDid: external_exports.string().min(1),
|
|
28730
|
+
createdAt: external_exports.string().datetime({ offset: true }),
|
|
28731
|
+
expiresAt: external_exports.string().datetime({ offset: true }).optional(),
|
|
28732
|
+
contentSource: unifiedContentSourceSchema2,
|
|
28733
|
+
capabilityCeiling: external_exports.array(unifiedCapabilitySchema2).min(2),
|
|
28734
|
+
signature: external_exports.object({ suite: external_exports.string().min(1), signerDid: external_exports.string().min(1), value: external_exports.string().min(1) }).strict()
|
|
28735
|
+
}).strict();
|
|
28736
|
+
var policyCredentialRequirementV1Schema2 = external_exports.object({
|
|
28737
|
+
type: external_exports.literal("TinyCloudPolicyCredentialRequirement"),
|
|
28738
|
+
version: external_exports.literal(1),
|
|
28739
|
+
requirementDigest: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
28740
|
+
descriptorDigest: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
28741
|
+
issuerDid: external_exports.string().min(1),
|
|
28742
|
+
issuerKid: external_exports.string().min(1),
|
|
28743
|
+
profile: external_exports.object({ id: external_exports.string().min(1), version: external_exports.literal(1) }).strict(),
|
|
28744
|
+
credentialType: external_exports.object({ id: external_exports.string().min(1), version: external_exports.literal(1) }).strict()
|
|
28745
|
+
}).strict();
|
|
28746
|
+
var unifiedPolicyV2Schema2 = external_exports.object({
|
|
28747
|
+
schema: external_exports.literal("xyz.tinycloud.policy/policy/v2"),
|
|
28748
|
+
policyId: external_exports.string().regex(/^pol_[a-z2-7]+$/),
|
|
28749
|
+
ownerDid: external_exports.string().min(1),
|
|
28750
|
+
createdAt: external_exports.string().datetime({ offset: true }),
|
|
28751
|
+
expiresAt: external_exports.string().datetime({ offset: true }).optional(),
|
|
28752
|
+
contentSource: unifiedContentSourceSchema2,
|
|
28753
|
+
capabilityCeiling: external_exports.array(unifiedCapabilitySchema2).min(2),
|
|
28754
|
+
credentialRequirement: policyCredentialRequirementV1Schema2,
|
|
28755
|
+
signature: external_exports.object({ suite: external_exports.literal("Ed25519"), signerDid: external_exports.string().min(1), value: external_exports.string().min(1) }).strict()
|
|
28756
|
+
}).strict();
|
|
28757
|
+
var unifiedPolicySchema2 = external_exports.discriminatedUnion("schema", [
|
|
28758
|
+
unifiedPolicyV1Schema2,
|
|
28759
|
+
unifiedPolicyV2Schema2
|
|
28760
|
+
]);
|
|
28761
|
+
var unifiedRootSchema2 = external_exports.object({
|
|
28762
|
+
cid: external_exports.string().min(1),
|
|
28763
|
+
authorization: external_exports.string().regex(/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/),
|
|
28764
|
+
role: external_exports.union([external_exports.literal("policy-authority"), external_exports.literal("policy-enforcement")])
|
|
28765
|
+
}).strict();
|
|
28766
|
+
var attestedEnforcerBindingV2Schema2 = external_exports.object({
|
|
28767
|
+
schema: external_exports.literal("xyz.tinycloud.policy/attested-enforcer/v2"),
|
|
28768
|
+
enforcerDid: external_exports.string().regex(/^did:key:z[1-9A-HJ-NP-Za-km-z]+$/),
|
|
28769
|
+
nodeAudience: external_exports.string().min(1),
|
|
28770
|
+
attestationBindingDigestHex: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
28771
|
+
issuedAt: external_exports.string().datetime({ offset: true }),
|
|
28772
|
+
expiresAt: external_exports.string().datetime({ offset: true }),
|
|
28773
|
+
signature: external_exports.object({ suite: external_exports.literal("Ed25519"), signerDid: external_exports.string().min(1), value: base64UrlString2() }).strict()
|
|
28774
|
+
}).strict();
|
|
28775
|
+
var v3TargetSchema2 = external_exports.object({
|
|
28776
|
+
origin: external_exports.string().refine(isCanonicalHttpsOrigin2, { message: "expected a canonical https origin" }),
|
|
28777
|
+
nodeAudience: external_exports.string().min(1),
|
|
28778
|
+
spaceId: external_exports.string().refine(isCanonicalPathSegment2, { message: "expected a canonical space id" })
|
|
28779
|
+
}).strict();
|
|
28780
|
+
var unsignedShareEnvelopeV3BaseSchema2 = external_exports.object({
|
|
28781
|
+
version: external_exports.literal(3),
|
|
28782
|
+
shareId: external_exports.string().min(1),
|
|
28783
|
+
recipientMatcher: recipientMatcherSchema2,
|
|
28784
|
+
deliveryEmail: deliveryEmailSchema2.optional(),
|
|
28785
|
+
actions: external_exports.array(shareActionSchema2).min(1).max(3),
|
|
28786
|
+
resource: resourceSelectorSchema2,
|
|
28787
|
+
target: v3TargetSchema2,
|
|
28788
|
+
policy: unifiedPolicySchema2,
|
|
28789
|
+
policyCid: external_exports.string().min(1),
|
|
28790
|
+
policyRoot: unifiedRootSchema2,
|
|
28791
|
+
enforcementRoot: unifiedRootSchema2,
|
|
28792
|
+
attestedEnforcerBinding: attestedEnforcerBindingV2Schema2,
|
|
28793
|
+
contentSource: unifiedContentSourceSchema2,
|
|
28794
|
+
contentSourceDigestHex: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
28795
|
+
encryptionNetwork: unifiedEncryptionNetworkSchema2,
|
|
28796
|
+
expiry: external_exports.string().datetime({ offset: true }),
|
|
28797
|
+
display: displaySchema2,
|
|
28798
|
+
encrypted: external_exports.literal(true),
|
|
28799
|
+
metadata: contentMetadataSchema2
|
|
28800
|
+
}).strict();
|
|
28801
|
+
function validateV3Invariants2(value, ctx) {
|
|
28802
|
+
const actions = [...value.actions];
|
|
28803
|
+
if (new Set(actions).size !== actions.length || actions.some((action, index) => action !== ["read", "list", "edit"].filter((candidate) => actions.includes(candidate))[index])) {
|
|
28804
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["actions"], message: "actions must be unique and canonically ordered" });
|
|
28805
|
+
}
|
|
28806
|
+
if (value.policyRoot.role !== "policy-authority" || value.enforcementRoot.role !== "policy-enforcement") {
|
|
28807
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policyRoot", "role"], message: "root roles are fixed" });
|
|
28808
|
+
}
|
|
28809
|
+
if (value.policyCid.length === 0 || value.policyCid === value.policyRoot.cid || value.policyCid === value.enforcementRoot.cid) {
|
|
28810
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policyCid"], message: "policy CID must be distinct from both roots" });
|
|
28811
|
+
}
|
|
28812
|
+
if (value.contentSource.encryptionNetwork !== value.encryptionNetwork) {
|
|
28813
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["encryptionNetwork"], message: "encryption network is not bound to the source" });
|
|
28814
|
+
}
|
|
28815
|
+
if (value.attestedEnforcerBinding.nodeAudience !== value.target.nodeAudience || value.attestedEnforcerBinding.signature.signerDid !== value.attestedEnforcerBinding.nodeAudience || Date.parse(value.attestedEnforcerBinding.expiresAt) < Date.parse(value.expiry)) {
|
|
28816
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["attestedEnforcerBinding"], message: "enforcer binding does not cover the target and share lifetime" });
|
|
28817
|
+
}
|
|
28818
|
+
if (value.policy.contentSource.shareId !== value.contentSource.shareId || value.policy.contentSource.kvResource !== value.contentSource.kvResource || value.policy.contentSource.selector !== value.contentSource.selector || value.policy.contentSource.encryptionNetwork !== value.encryptionNetwork || value.policy.contentSource.encryptedSymmetricKeyDigestHex !== value.contentSource.encryptedSymmetricKeyDigestHex || value.policy.contentSource.keyVersion !== value.contentSource.keyVersion || value.policy.contentSource.mode !== value.contentSource.mode || value.policy.contentSource.initialCiphertextDigestHex !== value.contentSource.initialCiphertextDigestHex) {
|
|
28819
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource"], message: "content source is not bound to policy" });
|
|
28820
|
+
}
|
|
28821
|
+
if (value.policy.signature.suite !== "Ed25519" || value.policy.signature.signerDid !== value.policy.ownerDid) {
|
|
28822
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "signature"], message: "policy must be signed by its owner" });
|
|
28823
|
+
}
|
|
28824
|
+
const kvCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "kv");
|
|
28825
|
+
const decryptCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "encryption" && capability.resource === value.encryptionNetwork && capability.action === "tinycloud.encryption/decrypt");
|
|
28826
|
+
if (value.policy.capabilityCeiling.length !== 2 || kvCapabilities.length !== 1 || decryptCapabilities.length !== 1 || kvCapabilities[0]?.resource !== value.contentSource.kvResource || kvCapabilities[0]?.selector !== value.contentSource.selector) {
|
|
28827
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "capabilityCeiling"], message: "policy ceiling must contain exact decrypt network" });
|
|
28828
|
+
}
|
|
27475
28829
|
}
|
|
27476
|
-
|
|
27477
|
-
|
|
27478
|
-
|
|
27479
|
-
|
|
28830
|
+
var unsignedShareEnvelopeV3Schema2 = unsignedShareEnvelopeV3BaseSchema2.superRefine(validateV3Invariants2);
|
|
28831
|
+
var shareEnvelopeV3Schema2 = unsignedShareEnvelopeV3BaseSchema2.extend({ signature: signatureSchema2 }).strict().superRefine(validateV3Invariants2);
|
|
28832
|
+
var ENVELOPE_AAD_LABEL2 = "tinycloud-share-envelope-v1";
|
|
28833
|
+
var AAD2 = utf8Bytes2(ENVELOPE_AAD_LABEL2);
|
|
28834
|
+
var LABEL2 = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
28835
|
+
function isCanonicalEmailDomain2(value) {
|
|
28836
|
+
if (value.length === 0 || value.length > 253) return false;
|
|
28837
|
+
const labels = value.split(".");
|
|
28838
|
+
return labels.length >= 2 && labels.every((label) => LABEL2.test(label)) && !/^[0-9]+$/.test(labels.at(-1));
|
|
27480
28839
|
}
|
|
27481
|
-
|
|
27482
|
-
|
|
27483
|
-
|
|
27484
|
-
|
|
27485
|
-
|
|
27486
|
-
|
|
27487
|
-
|
|
27488
|
-
|
|
27489
|
-
holderBindingVersion: 1
|
|
27490
|
-
});
|
|
27491
|
-
var DOMAIN = SHARE_V2_PROTOCOL.challengeDomain;
|
|
27492
|
-
var PRESENTATION_DOMAIN = SHARE_V2_PROTOCOL.sessionDomain;
|
|
27493
|
-
var SESSION_DOMAIN = SHARE_V2_PROTOCOL.sessionDomain;
|
|
27494
|
-
var INVOCATION_DOMAIN = SHARE_V2_PROTOCOL.invocationDomain;
|
|
27495
|
-
var NATIVE_SHARE_FRAGMENT_PARAMETER = "tc1";
|
|
27496
|
-
function parseNativeShareUrl(value) {
|
|
27497
|
-
const url = new URL(value);
|
|
27498
|
-
if (url.search || url.pathname !== "/viewer") throw new TypeError("native shares must carry tc1 only in the /viewer URL fragment");
|
|
27499
|
-
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
27500
|
-
const token = fragment.get(NATIVE_SHARE_FRAGMENT_PARAMETER);
|
|
27501
|
-
if (!token || fragment.size !== 1) throw new TypeError("missing native share fragment");
|
|
27502
|
-
return token;
|
|
28840
|
+
function canonicalMailbox2(value) {
|
|
28841
|
+
const email = value.trim().toLowerCase();
|
|
28842
|
+
const at = email.indexOf("@");
|
|
28843
|
+
if (at <= 0 || at !== email.lastIndexOf("@")) return void 0;
|
|
28844
|
+
const local = email.slice(0, at);
|
|
28845
|
+
const domain = email.slice(at + 1);
|
|
28846
|
+
if (local.length > 64 || !/^[a-z0-9#$&'*+/=?^_`{|}~-]+(?:\.[a-z0-9#$&'*+/=?^_`{|}~-]+)*$/.test(local) || !isCanonicalEmailDomain2(domain)) return void 0;
|
|
28847
|
+
return Object.freeze({ email, domain });
|
|
27503
28848
|
}
|
|
28849
|
+
var MAX_INLINE_BYTES2 = 256 * 1024;
|
|
27504
28850
|
|
|
27505
28851
|
// src/commands/share.ts
|
|
28852
|
+
import { ProfileLockTimeoutError as ProfileLockTimeoutError3 } from "@tinycloud/operations/state";
|
|
27506
28853
|
init_formatter();
|
|
27507
28854
|
init_errors();
|
|
27508
28855
|
|
|
@@ -27679,9 +29026,18 @@ var SharePublishAuthorityError = class extends Error {
|
|
|
27679
29026
|
this.name = "SharePublishAuthorityError";
|
|
27680
29027
|
}
|
|
27681
29028
|
};
|
|
29029
|
+
var ShareHistoryRetryError = class extends Error {
|
|
29030
|
+
constructor(profile) {
|
|
29031
|
+
super("sender history changed during the operation");
|
|
29032
|
+
this.profile = profile;
|
|
29033
|
+
this.name = "ShareHistoryRetryError";
|
|
29034
|
+
}
|
|
29035
|
+
code = "SHARE_HISTORY_RETRY";
|
|
29036
|
+
};
|
|
27682
29037
|
|
|
27683
29038
|
// src/commands/share.ts
|
|
27684
29039
|
var SHARE_ORIGIN = "https://share.tinycloud.xyz";
|
|
29040
|
+
var NOTIFY_WINDOW_MESSAGE = "Share notification authorization expired (at share expiry or 5 minutes after publication); publish a new share and invite the recipient then.\n";
|
|
27685
29041
|
var shareServices = {};
|
|
27686
29042
|
function parseShareTarget(value) {
|
|
27687
29043
|
if (value === "anyone" || value === "bearer") return { kind: "bearer" };
|
|
@@ -27698,8 +29054,17 @@ function canonicalMailboxTarget(target) {
|
|
|
27698
29054
|
throw new CLIError("INVALID_ARGUMENT", error instanceof TypeError ? error.message : "share recipient is invalid", 2);
|
|
27699
29055
|
}
|
|
27700
29056
|
}
|
|
27701
|
-
function shareCliError(error) {
|
|
29057
|
+
function shareCliError(error, operation = "publish") {
|
|
27702
29058
|
if (error instanceof CLIError) return error;
|
|
29059
|
+
if (error instanceof ProfileLockTimeoutError3) return wrapError(error);
|
|
29060
|
+
if (error instanceof ShareHistoryRetryError) {
|
|
29061
|
+
return new CLIError(
|
|
29062
|
+
"SHARE_HISTORY_RETRY",
|
|
29063
|
+
`sender history for profile ${JSON.stringify(error.profile)} changed or disappeared during this command`,
|
|
29064
|
+
1,
|
|
29065
|
+
{ hint: `Retry this command with --profile ${JSON.stringify(error.profile)}. If this was a revoke, check its node state first: revocation may already have succeeded.` }
|
|
29066
|
+
);
|
|
29067
|
+
}
|
|
27703
29068
|
if (error instanceof SharePublishAuthorityError) {
|
|
27704
29069
|
const failure = error.failure;
|
|
27705
29070
|
const profileName = "profileName" in failure ? failure.profileName : void 0;
|
|
@@ -27741,6 +29106,10 @@ function shareCliError(error) {
|
|
|
27741
29106
|
if (failure.kind === "registry-unavailable") {
|
|
27742
29107
|
return new CLIError("UNAVAILABLE", "the TinyCloud location registry could not be reached, so nothing was shared; try again shortly", 4);
|
|
27743
29108
|
}
|
|
29109
|
+
if (failure.kind === "node-info-unavailable") {
|
|
29110
|
+
const outcome = operation === "publish" ? "nothing was shared and no invitation was sent" : "no invitation was sent";
|
|
29111
|
+
return new CLIError("UNAVAILABLE", `could not verify TinyCloud node 1.17.3 domain delivery support; ${outcome}. Check the node and retry`, 4);
|
|
29112
|
+
}
|
|
27744
29113
|
if (failure.kind === "registry-rejected") {
|
|
27745
29114
|
return new CLIError("REGISTRY_REJECTED", "the TinyCloud location registry rejected this session's location record, so nothing was shared; retrying will not help. Log in again, and report the problem if it persists", 6);
|
|
27746
29115
|
}
|
|
@@ -27757,14 +29126,14 @@ function shareCliError(error) {
|
|
|
27757
29126
|
}
|
|
27758
29127
|
if (error instanceof SharePublishError) {
|
|
27759
29128
|
const exit = error.code === "authority-required" ? 3 : error.code === "max-bytes-exceeded" ? 7 : 2;
|
|
27760
|
-
const
|
|
27761
|
-
return new CLIError(
|
|
29129
|
+
const code3 = error.code === "authority-required" ? "AUTH_REQUIRED" : error.code === "max-bytes-exceeded" ? "MAX_BYTES_EXCEEDED" : "INVALID_ARGUMENT";
|
|
29130
|
+
return new CLIError(code3, error.message, exit);
|
|
27762
29131
|
}
|
|
27763
29132
|
if (error instanceof ShareReceiveError) {
|
|
27764
29133
|
const verification = /* @__PURE__ */ new Set(["cid-mismatch", "decrypt-failed", "envelope-invalid", "origin-mismatch", "signature-invalid", "capability-invalid", "content-integrity-failed"]);
|
|
27765
29134
|
const exit = error.code === "max-bytes-exceeded" ? 7 : verification.has(error.code) ? 5 : error.code === "expired" || error.code === "fetch-failed" ? 4 : error.code === "invalid-link" || error.code === "unsupported-target" ? 2 : 2;
|
|
27766
|
-
const
|
|
27767
|
-
return new CLIError(
|
|
29135
|
+
const code3 = error.code === "fetch-failed" ? "NOT_FOUND" : error.code.replaceAll("-", "_").toUpperCase();
|
|
29136
|
+
return new CLIError(code3, error.message, exit);
|
|
27768
29137
|
}
|
|
27769
29138
|
const message = error instanceof Error ? error.message : String(error);
|
|
27770
29139
|
const nodeCode = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
@@ -27809,8 +29178,33 @@ function expires(value) {
|
|
|
27809
29178
|
}
|
|
27810
29179
|
async function rememberPublishedShare(result) {
|
|
27811
29180
|
const record = historyRecordForPublishedShare(result);
|
|
27812
|
-
if (shareServices.records
|
|
27813
|
-
|
|
29181
|
+
if (shareServices.records === void 0) return { record, recorded: false };
|
|
29182
|
+
try {
|
|
29183
|
+
await shareServices.records.put(record);
|
|
29184
|
+
return { record, recorded: true };
|
|
29185
|
+
} catch {
|
|
29186
|
+
process.stderr.write("Warning: share was published but not recorded in sender history; future share list, share notify, and share revoke by ID will not find it.\n");
|
|
29187
|
+
return { record, recorded: false };
|
|
29188
|
+
}
|
|
29189
|
+
}
|
|
29190
|
+
async function notifyRecordedShare(record, recipient, adapter, storage) {
|
|
29191
|
+
const result = await notifyShare({ shareId: record.shareId, recipient, record, adapter, checkDeliveryWindow: true });
|
|
29192
|
+
if (result.state !== "partial-failure" && storage !== void 0) {
|
|
29193
|
+
const mailbox = canonicalMailbox2(recipient).email;
|
|
29194
|
+
if (!record.deliveredRecipients?.includes(mailbox)) {
|
|
29195
|
+
try {
|
|
29196
|
+
if (storage.update === void 0) throw new Error("atomic sender history update is unavailable");
|
|
29197
|
+
const updated = await storage.update(record.shareId, (current) => ({
|
|
29198
|
+
...current,
|
|
29199
|
+
deliveredRecipients: current.deliveredRecipients?.includes(mailbox) ? current.deliveredRecipients : [...current.deliveredRecipients ?? [], mailbox]
|
|
29200
|
+
}));
|
|
29201
|
+
if (updated === void 0) throw new Error("sender history record was removed");
|
|
29202
|
+
} catch {
|
|
29203
|
+
process.stderr.write("Warning: delivery succeeded, but could not record its confirmation in sender history.\n");
|
|
29204
|
+
}
|
|
29205
|
+
}
|
|
29206
|
+
}
|
|
29207
|
+
return result;
|
|
27814
29208
|
}
|
|
27815
29209
|
function byteLimit(value) {
|
|
27816
29210
|
if (value === void 0) return void 0;
|
|
@@ -27837,7 +29231,7 @@ function assertAggregateInputLimit(inputs, maxBytes) {
|
|
|
27837
29231
|
}
|
|
27838
29232
|
function registerShareCommand(program) {
|
|
27839
29233
|
const share = program.command("share").description("Publish and consume TinyCloud Share links");
|
|
27840
|
-
share.command("publish <files...>").description("Publish one or more bounded files as a Share").option("--name <filename>", "Filename for stdin input").option("--to <target>", "Share target", "anyone").option("--notify", "
|
|
29234
|
+
share.command("publish <files...>").description("Publish one or more bounded files as a Share").option("--name <filename>", "Filename for stdin input").option("--to <target>", "Share target", "anyone").option("--notify", "Email an exact-email recipient, or a domain mailbox on node 1.17.3+").option("--notify-to <address>", "Mailbox to invite for --to domain:<name> --notify (node 1.17.3+)").option("--expires <duration>", "Share lifetime").option("--max-bytes <bytes>", "Bound input bytes").option("--media-type <type>", "Media type for a single input").option("--action <actions...>", "Addressed permission: read, list, or edit").option("--prefix", "Publish multiple inputs beneath one addressed prefix").option("--binary", "Allow non-UTF-8 bearer content").option("--json", "Print versioned redacted JSON").option("--viewer-origin <origin>", "Canonical HTTPS viewer origin", SHARE_ORIGIN).action(async (files, options, command) => {
|
|
27841
29235
|
try {
|
|
27842
29236
|
const json = jsonOutput(options, command);
|
|
27843
29237
|
const maxBytes = byteLimit(options.maxBytes);
|
|
@@ -27851,7 +29245,21 @@ function registerShareCommand(program) {
|
|
|
27851
29245
|
if (options.prefix && target.kind === "bearer") throw new CLIError("INVALID_ARGUMENT", "--prefix requires an addressed target", 2);
|
|
27852
29246
|
if (inputs.length > 1 && target.kind === "bearer") throw new CLIError("UNSUPPORTED_LINK", "multiple files require an addressed target", 2);
|
|
27853
29247
|
if (inputs.length > 1 && !options.prefix) throw new CLIError("INVALID_ARGUMENT", "multiple files require --prefix", 2);
|
|
27854
|
-
if (options.notify === true &&
|
|
29248
|
+
if (options.notify === true && !actions.includes("read")) throw new CLIError("INVALID_ARGUMENT", "--notify requires the read action; nothing was shared", 2);
|
|
29249
|
+
if (options.notifyTo !== void 0 && (options.notify !== true || target.kind !== "emailDomain")) {
|
|
29250
|
+
throw new CLIError("INVALID_ARGUMENT", "--notify-to requires --to domain:<name> --notify", 2);
|
|
29251
|
+
}
|
|
29252
|
+
let notifyRecipient;
|
|
29253
|
+
if (options.notify === true && target.kind === "email") notifyRecipient = target.address;
|
|
29254
|
+
else if (options.notify === true && target.kind === "emailDomain") {
|
|
29255
|
+
const mailbox = options.notifyTo === void 0 ? void 0 : canonicalMailbox2(options.notifyTo);
|
|
29256
|
+
if (mailbox === void 0 || mailbox.domain !== target.domain) {
|
|
29257
|
+
throw new CLIError("INVALID_ARGUMENT", "--to domain:<name> --notify requires --notify-to <email> at that exact domain (node 1.17.3+)", 2);
|
|
29258
|
+
}
|
|
29259
|
+
notifyRecipient = mailbox.email;
|
|
29260
|
+
} else if (options.notify === true) {
|
|
29261
|
+
throw new CLIError("INVALID_ARGUMENT", "--notify requires an email target, or a domain target with --notify-to on node 1.17.3+", 2);
|
|
29262
|
+
}
|
|
27855
29263
|
const result = await publishTargetShare({
|
|
27856
29264
|
source: inputs[0].bytes,
|
|
27857
29265
|
filename: inputs[0].filename,
|
|
@@ -27876,16 +29284,17 @@ function registerShareCommand(program) {
|
|
|
27876
29284
|
}
|
|
27877
29285
|
throw new CLIError(result.method === "openkey-device" ? "DEVICE_AUTH_REQUIRED" : "CLAIM_REQUIRED", "recipient authorization is required; continue through the configured authority adapter", 6);
|
|
27878
29286
|
}
|
|
27879
|
-
const record = await rememberPublishedShare(result);
|
|
27880
|
-
|
|
29287
|
+
const { record, recorded } = await rememberPublishedShare(result);
|
|
29288
|
+
let notification;
|
|
29289
|
+
if (notifyRecipient !== void 0) {
|
|
27881
29290
|
if (shareServices.delivery === void 0) throw new CLIError("AUTH_REQUIRED", "delivery authority is not configured", 3);
|
|
27882
|
-
|
|
27883
|
-
|
|
27884
|
-
if (
|
|
29291
|
+
notification = await notifyRecordedShare(record, notifyRecipient, shareServices.delivery, recorded ? shareServices.records : void 0);
|
|
29292
|
+
if (notification.state === "partial-failure") process.exitCode = 9;
|
|
29293
|
+
if (notification.reason === "delivery-window-expired") process.stderr.write(NOTIFY_WINDOW_MESSAGE);
|
|
27885
29294
|
}
|
|
27886
29295
|
if (result.metadata.expiryClamped === true) process.stderr.write(`Share expiry clamped to session expiry (${result.metadata.expiresAt}).
|
|
27887
29296
|
`);
|
|
27888
|
-
if (json) writeJson2({ ...redactPublishedShare(result), expiryClamped: result.metadata.expiryClamped === true });
|
|
29297
|
+
if (json) writeJson2({ ...redactPublishedShare(result), expiryClamped: result.metadata.expiryClamped === true, ...notification === void 0 ? {} : { notification } });
|
|
27889
29298
|
else publishHuman(result);
|
|
27890
29299
|
} catch (error) {
|
|
27891
29300
|
handleError(shareCliError(error));
|
|
@@ -27972,20 +29381,31 @@ function registerShareCommand(program) {
|
|
|
27972
29381
|
handleError(shareCliError(error));
|
|
27973
29382
|
}
|
|
27974
29383
|
});
|
|
27975
|
-
share.command("notify <id>").description("Retry idempotent delivery
|
|
29384
|
+
share.command("notify <id>").description("Retry idempotent delivery within 5 minutes of publication; after that publish a new share").requiredOption("--to <address>", "Recipient email").option("--json", "Print versioned JSON").action(async (id, options, command) => {
|
|
27976
29385
|
try {
|
|
27977
29386
|
const json = jsonOutput(options, command);
|
|
27978
29387
|
if (shareServices.delivery === void 0) throw new CLIError("AUTH_REQUIRED", "delivery authority is not configured", 3);
|
|
27979
29388
|
if (shareServices.records === void 0) throw new CLIError("AUTH_REQUIRED", "sender history storage is not configured", 3);
|
|
27980
29389
|
const record = await shareServices.records.get(id);
|
|
27981
29390
|
if (record === void 0) throw new CLIError("NOT_FOUND", "share not found", 4);
|
|
27982
|
-
|
|
29391
|
+
if (!record.actions.includes("tinycloud.kv/get")) {
|
|
29392
|
+
throw new CLIError("INVALID_ARGUMENT", "share notify requires a stored share with the read action; no invitation was sent", 2);
|
|
29393
|
+
}
|
|
29394
|
+
const mailbox = canonicalMailbox2(options.to);
|
|
29395
|
+
if (mailbox === void 0) throw new ShareNotifyError("recipient is invalid");
|
|
29396
|
+
if (!recipientMatchesShareRecord(record, mailbox.email)) throw new ShareNotifyError("recipient does not match the stored share target");
|
|
29397
|
+
if (record.recipientMatcher.kind === "emailDomain" && shareDeliveryWindowExpiresAt(record) > Date.now()) {
|
|
29398
|
+
if (shareServices.assertDomainDelivery === void 0) throw new CLIError("UNAVAILABLE", "could not verify TinyCloud node 1.17.3 domain delivery support; no invitation was sent", 4);
|
|
29399
|
+
await shareServices.assertDomainDelivery();
|
|
29400
|
+
}
|
|
29401
|
+
const result = await notifyRecordedShare(record, options.to, shareServices.delivery, shareServices.records);
|
|
27983
29402
|
if (json) writeJson2(result);
|
|
27984
29403
|
else process.stdout.write(`${result.state}
|
|
27985
29404
|
`);
|
|
29405
|
+
if (result.reason === "delivery-window-expired") process.stderr.write(NOTIFY_WINDOW_MESSAGE);
|
|
27986
29406
|
if (result.state === "partial-failure") process.exitCode = 9;
|
|
27987
29407
|
} catch (error) {
|
|
27988
|
-
handleError(shareCliError(error));
|
|
29408
|
+
handleError(shareCliError(error, "notify"));
|
|
27989
29409
|
}
|
|
27990
29410
|
});
|
|
27991
29411
|
share.command("revoke <id>").description("Revoke addressed shares; report bearer retention honestly").option("--ancestor", "Revoke the owner delegation ancestry").option("--json", "Print versioned JSON").action(async (id, options, command) => {
|