@tinycloud/sdk-core 2.11.0-beta.10 → 2.11.0-beta.12
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/{capability-BjzXwtNw.d.cts → capability-BA49Uboq.d.cts} +1 -1
- package/dist/{capability-BjzXwtNw.d.ts → capability-BA49Uboq.d.ts} +1 -1
- package/dist/delegations/index.cjs +620 -221
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +8 -8
- package/dist/delegations/index.d.ts +8 -8
- package/dist/delegations/index.js +621 -222
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +1576 -762
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +1548 -732
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +867 -175
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.d.cts +5 -4
- package/dist/policy/index.d.ts +5 -4
- package/dist/policy/index.js +867 -175
- package/dist/policy/index.js.map +1 -1
- package/dist/{recipient-types.schema-D5pDlIqn.d.cts → recipient-types.schema-CuDpskPd.d.cts} +172 -115
- package/dist/{recipient-types.schema-D5pDlIqn.d.ts → recipient-types.schema-CuDpskPd.d.ts} +172 -115
- package/dist/requester/index.d.cts +1 -1
- package/dist/requester/index.d.ts +1 -1
- package/dist/unified-DbySI5wW.d.cts +429 -0
- package/dist/unified-tCGtc-Wx.d.ts +429 -0
- package/package.json +5 -5
- package/dist/signed-object-C6mWbTbB.d.ts +0 -149
- package/dist/signed-object-IMAm5a32.d.cts +0 -149
package/dist/index.js
CHANGED
|
@@ -147,8 +147,8 @@ function makePkhSpaceId(address, chainId, name2) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// src/requester/index.ts
|
|
150
|
-
import { bytesToHex as bytesToHex3, sha256 as
|
|
151
|
-
import { blake3 } from "@noble/hashes/blake3";
|
|
150
|
+
import { bytesToHex as bytesToHex3, sha256 as sha2565 } from "viem";
|
|
151
|
+
import { blake3 as blake32 } from "@noble/hashes/blake3";
|
|
152
152
|
|
|
153
153
|
// ../../node_modules/multiformats/dist/src/bases/base32.js
|
|
154
154
|
var base32_exports = {};
|
|
@@ -1056,7 +1056,7 @@ function encodeCID(version, code3, multihash) {
|
|
|
1056
1056
|
var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
|
|
1057
1057
|
|
|
1058
1058
|
// src/requester/index.ts
|
|
1059
|
-
import { z as
|
|
1059
|
+
import { z as z3 } from "zod";
|
|
1060
1060
|
|
|
1061
1061
|
// src/policy/errors.ts
|
|
1062
1062
|
var SignedObjectProfileError = class extends Error {
|
|
@@ -1365,16 +1365,16 @@ function policyCapabilityContains(authority, request) {
|
|
|
1365
1365
|
return caveatsContain(auth.caveats, req.caveats);
|
|
1366
1366
|
}
|
|
1367
1367
|
function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
1368
|
-
const
|
|
1369
|
-
assertExactKeys(
|
|
1370
|
-
const service = requiredString(
|
|
1368
|
+
const object2 = expectObject(input, "$");
|
|
1369
|
+
assertExactKeys(object2, ["service", "space", "path", "actions", "caveats"], "$");
|
|
1370
|
+
const service = requiredString(object2, "service", "$", "policy-capability-malformed-service");
|
|
1371
1371
|
if (!CEILING_SERVICES.has(service)) {
|
|
1372
1372
|
throw new PolicyCapabilityError(
|
|
1373
1373
|
"policy-capability-malformed-service",
|
|
1374
1374
|
"$.service is outside the frozen permissionsCeiling vocabulary"
|
|
1375
1375
|
);
|
|
1376
1376
|
}
|
|
1377
|
-
const space = requiredString(
|
|
1377
|
+
const space = requiredString(object2, "space", "$", "policy-capability-malformed-space");
|
|
1378
1378
|
validateConcreteSpace(space);
|
|
1379
1379
|
const canonicalSpace = space.normalize("NFC");
|
|
1380
1380
|
if (options2.requireCanonical && canonicalSpace !== space) {
|
|
@@ -1383,7 +1383,7 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1383
1383
|
"$.space must already be canonical NFC"
|
|
1384
1384
|
);
|
|
1385
1385
|
}
|
|
1386
|
-
const rawPath = requiredString(
|
|
1386
|
+
const rawPath = requiredString(object2, "path", "$", "policy-capability-malformed-path");
|
|
1387
1387
|
validateRawPath(rawPath, options2);
|
|
1388
1388
|
const path = normalizePath(rawPath);
|
|
1389
1389
|
if (options2.requireCanonical && path !== rawPath) {
|
|
@@ -1394,7 +1394,7 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1394
1394
|
}
|
|
1395
1395
|
validateRawPath(path, options2);
|
|
1396
1396
|
const actions = normalizeActions(
|
|
1397
|
-
requiredArray(
|
|
1397
|
+
requiredArray(object2, "actions", "$", "policy-capability-malformed-action"),
|
|
1398
1398
|
service,
|
|
1399
1399
|
options2
|
|
1400
1400
|
);
|
|
@@ -1403,9 +1403,9 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1403
1403
|
output.space = canonicalSpace;
|
|
1404
1404
|
output.path = path;
|
|
1405
1405
|
output.actions = actions;
|
|
1406
|
-
if (hasOwn(
|
|
1406
|
+
if (hasOwn(object2, "caveats")) {
|
|
1407
1407
|
output.caveats = validateCaveats(
|
|
1408
|
-
requiredValue(
|
|
1408
|
+
requiredValue(object2, "caveats", "$", "policy-capability-malformed-caveats"),
|
|
1409
1409
|
output.service
|
|
1410
1410
|
);
|
|
1411
1411
|
}
|
|
@@ -1428,9 +1428,9 @@ function expectObject(input, path) {
|
|
|
1428
1428
|
);
|
|
1429
1429
|
}
|
|
1430
1430
|
}
|
|
1431
|
-
function assertExactKeys(
|
|
1431
|
+
function assertExactKeys(object2, allowed, path) {
|
|
1432
1432
|
const allowedSet = new Set(allowed);
|
|
1433
|
-
for (const key of Object.keys(
|
|
1433
|
+
for (const key of Object.keys(object2)) {
|
|
1434
1434
|
if (!allowedSet.has(key)) {
|
|
1435
1435
|
throw new PolicyCapabilityError(
|
|
1436
1436
|
key === "id" || key === "scope" ? "policy-capability-malformed" : "policy-capability-unknown-key",
|
|
@@ -1439,21 +1439,21 @@ function assertExactKeys(object, allowed, path) {
|
|
|
1439
1439
|
}
|
|
1440
1440
|
}
|
|
1441
1441
|
}
|
|
1442
|
-
function requiredValue(
|
|
1443
|
-
if (!hasOwn(
|
|
1442
|
+
function requiredValue(object2, key, path, code3) {
|
|
1443
|
+
if (!hasOwn(object2, key)) {
|
|
1444
1444
|
throw new PolicyCapabilityError(code3, `${path}.${key} is required`);
|
|
1445
1445
|
}
|
|
1446
|
-
return
|
|
1446
|
+
return object2[key];
|
|
1447
1447
|
}
|
|
1448
|
-
function requiredString(
|
|
1449
|
-
const value = requiredValue(
|
|
1448
|
+
function requiredString(object2, key, path, code3) {
|
|
1449
|
+
const value = requiredValue(object2, key, path, code3);
|
|
1450
1450
|
if (typeof value !== "string" || value.length === 0) {
|
|
1451
1451
|
throw new PolicyCapabilityError(code3, `${path}.${key} must be a non-empty string`);
|
|
1452
1452
|
}
|
|
1453
1453
|
return value;
|
|
1454
1454
|
}
|
|
1455
|
-
function requiredArray(
|
|
1456
|
-
const value = requiredValue(
|
|
1455
|
+
function requiredArray(object2, key, path, code3) {
|
|
1456
|
+
const value = requiredValue(object2, key, path, code3);
|
|
1457
1457
|
if (!Array.isArray(value)) {
|
|
1458
1458
|
throw new PolicyCapabilityError(code3, `${path}.${key} must be an array`);
|
|
1459
1459
|
}
|
|
@@ -1598,11 +1598,11 @@ function validateSqlStatement(input, path) {
|
|
|
1598
1598
|
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
1599
1599
|
throw new PolicyCapabilityError("policy-capability-malformed-caveats", `${path} must be an object`);
|
|
1600
1600
|
}
|
|
1601
|
-
const
|
|
1602
|
-
assertCaveatKeys(
|
|
1603
|
-
caveatString(
|
|
1604
|
-
caveatString(
|
|
1605
|
-
const fixedParams = requiredCaveat(
|
|
1601
|
+
const object2 = input;
|
|
1602
|
+
assertCaveatKeys(object2, ["name", "sql", "fixedParams"], path);
|
|
1603
|
+
caveatString(object2, "name", path);
|
|
1604
|
+
caveatString(object2, "sql", path);
|
|
1605
|
+
const fixedParams = requiredCaveat(object2, "fixedParams", path);
|
|
1606
1606
|
if (!Array.isArray(fixedParams)) {
|
|
1607
1607
|
throw new PolicyCapabilityError(
|
|
1608
1608
|
"policy-capability-malformed-caveats",
|
|
@@ -1617,20 +1617,20 @@ function validateFixedParam(input, path) {
|
|
|
1617
1617
|
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
1618
1618
|
throw new PolicyCapabilityError("policy-capability-malformed-caveats", `${path} must be an object`);
|
|
1619
1619
|
}
|
|
1620
|
-
const
|
|
1621
|
-
assertCaveatKeys(
|
|
1622
|
-
const index = requiredCaveat(
|
|
1620
|
+
const object2 = input;
|
|
1621
|
+
assertCaveatKeys(object2, ["index", "value"], path);
|
|
1622
|
+
const index = requiredCaveat(object2, "index", path);
|
|
1623
1623
|
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) {
|
|
1624
1624
|
throw new PolicyCapabilityError(
|
|
1625
1625
|
"policy-capability-malformed-caveats",
|
|
1626
1626
|
`${path}.index must be a non-negative integer`
|
|
1627
1627
|
);
|
|
1628
1628
|
}
|
|
1629
|
-
requiredCaveat(
|
|
1629
|
+
requiredCaveat(object2, "value", path);
|
|
1630
1630
|
}
|
|
1631
|
-
function assertCaveatKeys(
|
|
1631
|
+
function assertCaveatKeys(object2, allowed, path) {
|
|
1632
1632
|
const allowedSet = new Set(allowed);
|
|
1633
|
-
for (const key of Object.keys(
|
|
1633
|
+
for (const key of Object.keys(object2)) {
|
|
1634
1634
|
if (!allowedSet.has(key)) {
|
|
1635
1635
|
throw new PolicyCapabilityError(
|
|
1636
1636
|
"policy-capability-malformed-caveats",
|
|
@@ -1639,17 +1639,17 @@ function assertCaveatKeys(object, allowed, path) {
|
|
|
1639
1639
|
}
|
|
1640
1640
|
}
|
|
1641
1641
|
}
|
|
1642
|
-
function requiredCaveat(
|
|
1643
|
-
if (!hasOwn(
|
|
1642
|
+
function requiredCaveat(object2, key, path) {
|
|
1643
|
+
if (!hasOwn(object2, key)) {
|
|
1644
1644
|
throw new PolicyCapabilityError(
|
|
1645
1645
|
"policy-capability-malformed-caveats",
|
|
1646
1646
|
`${path}.${key} is required`
|
|
1647
1647
|
);
|
|
1648
1648
|
}
|
|
1649
|
-
return
|
|
1649
|
+
return object2[key];
|
|
1650
1650
|
}
|
|
1651
|
-
function caveatString(
|
|
1652
|
-
const value = requiredCaveat(
|
|
1651
|
+
function caveatString(object2, key, path) {
|
|
1652
|
+
const value = requiredCaveat(object2, key, path);
|
|
1653
1653
|
if (typeof value !== "string" || value.length === 0) {
|
|
1654
1654
|
throw new PolicyCapabilityError(
|
|
1655
1655
|
"policy-capability-malformed-caveats",
|
|
@@ -1680,8 +1680,8 @@ function caveatsContain(authority, request) {
|
|
|
1680
1680
|
(statement) => authorityStatements.some((candidate) => jcsCanonicalize(candidate) === jcsCanonicalize(statement))
|
|
1681
1681
|
);
|
|
1682
1682
|
}
|
|
1683
|
-
function hasOwn(
|
|
1684
|
-
return objectHasOwn2(
|
|
1683
|
+
function hasOwn(object2, key) {
|
|
1684
|
+
return objectHasOwn2(object2, key);
|
|
1685
1685
|
}
|
|
1686
1686
|
|
|
1687
1687
|
// src/policy/signed-object.ts
|
|
@@ -2009,17 +2009,17 @@ async function createAndSignSignedObject(input, signer) {
|
|
|
2009
2009
|
}
|
|
2010
2010
|
function createAndSignPolicy(input, signer) {
|
|
2011
2011
|
return createAndSignSignedObject(input, signer).then(
|
|
2012
|
-
(
|
|
2012
|
+
(object2) => validatePolicySignedShape(object2)
|
|
2013
2013
|
);
|
|
2014
2014
|
}
|
|
2015
2015
|
function createAndSignPolicyStatus(input, signer) {
|
|
2016
2016
|
return createAndSignSignedObject(input, signer).then(
|
|
2017
|
-
(
|
|
2017
|
+
(object2) => validatePolicyStatusSignedShape(object2)
|
|
2018
2018
|
);
|
|
2019
2019
|
}
|
|
2020
2020
|
function createAndSignPolicyEngineRecord(input, signer) {
|
|
2021
2021
|
return createAndSignSignedObject(input, signer).then(
|
|
2022
|
-
(
|
|
2022
|
+
(object2) => validatePolicyEngineRecordSignedShape(object2)
|
|
2023
2023
|
);
|
|
2024
2024
|
}
|
|
2025
2025
|
async function verifySignedObject(input) {
|
|
@@ -2123,9 +2123,9 @@ function validateUnsignedForDescriptor(input, descriptor) {
|
|
|
2123
2123
|
}
|
|
2124
2124
|
}
|
|
2125
2125
|
function validatePolicyShape(input, signed) {
|
|
2126
|
-
const
|
|
2126
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2127
2127
|
assertExactKeys2(
|
|
2128
|
-
|
|
2128
|
+
object2,
|
|
2129
2129
|
signed ? [
|
|
2130
2130
|
"schema",
|
|
2131
2131
|
"policyId",
|
|
@@ -2153,30 +2153,30 @@ function validatePolicyShape(input, signed) {
|
|
|
2153
2153
|
],
|
|
2154
2154
|
"$"
|
|
2155
2155
|
);
|
|
2156
|
-
expectConst(requiredString2(
|
|
2156
|
+
expectConst(requiredString2(object2, "schema", "$"), POLICY_SCHEMA, "$.schema");
|
|
2157
2157
|
if (signed) {
|
|
2158
|
-
requiredString2(
|
|
2159
|
-
validateSignature(requiredValue2(
|
|
2158
|
+
requiredString2(object2, "policyId", "$");
|
|
2159
|
+
validateSignature(requiredValue2(object2, "signature", "$"));
|
|
2160
2160
|
}
|
|
2161
|
-
requiredString2(
|
|
2162
|
-
requiredString2(
|
|
2163
|
-
requiredDateString(
|
|
2164
|
-
optionalDateString(
|
|
2165
|
-
validatePolicyResource(requiredValue2(
|
|
2166
|
-
validateExpression(requiredValue2(
|
|
2167
|
-
validateGrant(requiredValue2(
|
|
2168
|
-
if (hasOwn2(
|
|
2169
|
-
validateDisclosure(requiredValue2(
|
|
2161
|
+
requiredString2(object2, "ownerDid", "$");
|
|
2162
|
+
requiredString2(object2, "signingKeyDid", "$");
|
|
2163
|
+
requiredDateString(object2, "createdAt", "$");
|
|
2164
|
+
optionalDateString(object2, "expiresAt", "$");
|
|
2165
|
+
validatePolicyResource(requiredValue2(object2, "resource", "$"), "$.resource");
|
|
2166
|
+
validateExpression(requiredValue2(object2, "when", "$"), "$.when");
|
|
2167
|
+
validateGrant(requiredValue2(object2, "grant", "$"), "$.grant");
|
|
2168
|
+
if (hasOwn2(object2, "disclosure")) {
|
|
2169
|
+
validateDisclosure(requiredValue2(object2, "disclosure", "$"), "$.disclosure");
|
|
2170
2170
|
}
|
|
2171
|
-
if (hasOwn2(
|
|
2172
|
-
validateAudit(requiredValue2(
|
|
2171
|
+
if (hasOwn2(object2, "audit")) {
|
|
2172
|
+
validateAudit(requiredValue2(object2, "audit", "$"), "$.audit");
|
|
2173
2173
|
}
|
|
2174
|
-
return
|
|
2174
|
+
return object2;
|
|
2175
2175
|
}
|
|
2176
2176
|
function validatePolicyStatusShape(input, signed) {
|
|
2177
|
-
const
|
|
2177
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2178
2178
|
assertExactKeys2(
|
|
2179
|
-
|
|
2179
|
+
object2,
|
|
2180
2180
|
signed ? [
|
|
2181
2181
|
"schema",
|
|
2182
2182
|
"statusId",
|
|
@@ -2200,28 +2200,28 @@ function validatePolicyStatusShape(input, signed) {
|
|
|
2200
2200
|
],
|
|
2201
2201
|
"$"
|
|
2202
2202
|
);
|
|
2203
|
-
expectConst(requiredString2(
|
|
2203
|
+
expectConst(requiredString2(object2, "schema", "$"), POLICY_STATUS_SCHEMA, "$.schema");
|
|
2204
2204
|
if (signed) {
|
|
2205
|
-
requiredString2(
|
|
2206
|
-
validateSignature(requiredValue2(
|
|
2205
|
+
requiredString2(object2, "statusId", "$");
|
|
2206
|
+
validateSignature(requiredValue2(object2, "signature", "$"));
|
|
2207
2207
|
}
|
|
2208
|
-
requiredString2(
|
|
2209
|
-
requiredString2(
|
|
2210
|
-
requiredInteger(
|
|
2211
|
-
expectOneOf(requiredString2(
|
|
2208
|
+
requiredString2(object2, "policyId", "$");
|
|
2209
|
+
requiredString2(object2, "ownerDid", "$");
|
|
2210
|
+
requiredInteger(object2, "sequence", "$", 0);
|
|
2211
|
+
expectOneOf(requiredString2(object2, "disposition", "$"), [
|
|
2212
2212
|
"active",
|
|
2213
2213
|
"suspended",
|
|
2214
2214
|
"revoked"
|
|
2215
2215
|
], "$.disposition");
|
|
2216
|
-
requiredDateString(
|
|
2217
|
-
optionalString(
|
|
2218
|
-
requiredString2(
|
|
2219
|
-
return
|
|
2216
|
+
requiredDateString(object2, "effectiveAt", "$");
|
|
2217
|
+
optionalString(object2, "reasonCode", "$");
|
|
2218
|
+
requiredString2(object2, "signingKeyDid", "$");
|
|
2219
|
+
return object2;
|
|
2220
2220
|
}
|
|
2221
2221
|
function validatePolicyEngineRecordShape(input, signed) {
|
|
2222
|
-
const
|
|
2222
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2223
2223
|
assertExactKeys2(
|
|
2224
|
-
|
|
2224
|
+
object2,
|
|
2225
2225
|
signed ? [
|
|
2226
2226
|
"schema",
|
|
2227
2227
|
"engineRecordId",
|
|
@@ -2246,44 +2246,44 @@ function validatePolicyEngineRecordShape(input, signed) {
|
|
|
2246
2246
|
"$"
|
|
2247
2247
|
);
|
|
2248
2248
|
expectConst(
|
|
2249
|
-
requiredString2(
|
|
2249
|
+
requiredString2(object2, "schema", "$"),
|
|
2250
2250
|
POLICY_ENGINE_RECORD_SCHEMA,
|
|
2251
2251
|
"$.schema"
|
|
2252
2252
|
);
|
|
2253
2253
|
if (signed) {
|
|
2254
|
-
requiredString2(
|
|
2255
|
-
validateSignature(requiredValue2(
|
|
2254
|
+
requiredString2(object2, "engineRecordId", "$");
|
|
2255
|
+
validateSignature(requiredValue2(object2, "signature", "$"));
|
|
2256
2256
|
}
|
|
2257
|
-
requiredString2(
|
|
2258
|
-
requiredString2(
|
|
2259
|
-
requiredString2(
|
|
2257
|
+
requiredString2(object2, "ownerDid", "$");
|
|
2258
|
+
requiredString2(object2, "endpoint", "$");
|
|
2259
|
+
requiredString2(object2, "audience", "$");
|
|
2260
2260
|
requiredStringArray(
|
|
2261
|
-
|
|
2261
|
+
object2,
|
|
2262
2262
|
"supportedPolicyVersions",
|
|
2263
2263
|
"$",
|
|
2264
2264
|
(value, path) => expectConst(value, "v0", path)
|
|
2265
2265
|
);
|
|
2266
|
-
requiredStringArray(
|
|
2267
|
-
requiredString2(
|
|
2268
|
-
requiredDateString(
|
|
2269
|
-
return
|
|
2266
|
+
requiredStringArray(object2, "supportedEvidenceVerifiers", "$");
|
|
2267
|
+
requiredString2(object2, "grantIssuerDid", "$");
|
|
2268
|
+
requiredDateString(object2, "expiresAt", "$");
|
|
2269
|
+
return object2;
|
|
2270
2270
|
}
|
|
2271
2271
|
function validateSignature(input) {
|
|
2272
|
-
const
|
|
2273
|
-
assertExactKeys2(
|
|
2274
|
-
const suite = requiredString2(
|
|
2272
|
+
const object2 = expectJsonObject(input, "$.signature");
|
|
2273
|
+
assertExactKeys2(object2, ["suite", "signerDid", "value"], "$.signature");
|
|
2274
|
+
const suite = requiredString2(object2, "suite", "$.signature");
|
|
2275
2275
|
assertSupportedSignatureSuite(suite);
|
|
2276
|
-
const signerDid = requiredString2(
|
|
2277
|
-
const value = requiredString2(
|
|
2276
|
+
const signerDid = requiredString2(object2, "signerDid", "$.signature");
|
|
2277
|
+
const value = requiredString2(object2, "value", "$.signature");
|
|
2278
2278
|
decodeSignatureValue(value, suite);
|
|
2279
2279
|
return { suite, signerDid, value };
|
|
2280
2280
|
}
|
|
2281
2281
|
function validatePolicyResource(input, path) {
|
|
2282
|
-
const
|
|
2283
|
-
assertExactKeys2(
|
|
2284
|
-
requiredString2(
|
|
2285
|
-
requiredString2(
|
|
2286
|
-
const ceiling = requiredArray2(
|
|
2282
|
+
const object2 = expectJsonObject(input, path);
|
|
2283
|
+
assertExactKeys2(object2, ["resourceType", "resourceId", "permissionsCeiling"], path);
|
|
2284
|
+
requiredString2(object2, "resourceType", path);
|
|
2285
|
+
requiredString2(object2, "resourceId", path);
|
|
2286
|
+
const ceiling = requiredArray2(object2, "permissionsCeiling", path, 1);
|
|
2287
2287
|
for (let index = 0; index < ceiling.length; index++) {
|
|
2288
2288
|
validatePolicyCapability(ceiling[index], `${path}.permissionsCeiling[${index}]`);
|
|
2289
2289
|
}
|
|
@@ -2299,10 +2299,10 @@ function validatePolicyPermissionsCeilingForSigning(input) {
|
|
|
2299
2299
|
}
|
|
2300
2300
|
}
|
|
2301
2301
|
function validatePolicyCapability(input, path) {
|
|
2302
|
-
const
|
|
2302
|
+
const object2 = expectJsonObject(input, path);
|
|
2303
2303
|
try {
|
|
2304
|
-
const canonical = canonicalizePolicyCapability(
|
|
2305
|
-
if (jcsCanonicalize(
|
|
2304
|
+
const canonical = canonicalizePolicyCapability(object2);
|
|
2305
|
+
if (jcsCanonicalize(object2) !== jcsCanonicalize(canonical)) {
|
|
2306
2306
|
throw new SignedObjectSchemaError(`${path} must be canonical PolicyCapability JSON`);
|
|
2307
2307
|
}
|
|
2308
2308
|
} catch (error) {
|
|
@@ -2315,10 +2315,10 @@ function validatePolicyCapability(input, path) {
|
|
|
2315
2315
|
}
|
|
2316
2316
|
}
|
|
2317
2317
|
function validatePolicyCapabilityForSigning(input, path) {
|
|
2318
|
-
const
|
|
2318
|
+
const object2 = expectJsonObject(input, path);
|
|
2319
2319
|
try {
|
|
2320
|
-
const canonical = normalizePolicyCapability(
|
|
2321
|
-
if (jcsCanonicalize(
|
|
2320
|
+
const canonical = normalizePolicyCapability(object2);
|
|
2321
|
+
if (jcsCanonicalize(object2) !== jcsCanonicalize(canonical)) {
|
|
2322
2322
|
throw new SignedObjectSchemaError(`${path} must be strict canonical PolicyCapability JSON`);
|
|
2323
2323
|
}
|
|
2324
2324
|
} catch (error) {
|
|
@@ -2331,43 +2331,43 @@ function validatePolicyCapabilityForSigning(input, path) {
|
|
|
2331
2331
|
}
|
|
2332
2332
|
}
|
|
2333
2333
|
function validateExpression(input, path) {
|
|
2334
|
-
const
|
|
2335
|
-
const keys = Object.keys(
|
|
2334
|
+
const object2 = expectJsonObject(input, path);
|
|
2335
|
+
const keys = Object.keys(object2);
|
|
2336
2336
|
if (keys.length !== 1) {
|
|
2337
2337
|
throw new SignedObjectSchemaError(`${path} must have exactly one expression key`);
|
|
2338
2338
|
}
|
|
2339
2339
|
const key = keys[0];
|
|
2340
2340
|
if (key === "allOf" || key === "anyOf") {
|
|
2341
|
-
const values = requiredArray2(
|
|
2341
|
+
const values = requiredArray2(object2, key, path, 1);
|
|
2342
2342
|
for (let index = 0; index < values.length; index++) {
|
|
2343
2343
|
validateExpression(values[index], `${path}.${key}[${index}]`);
|
|
2344
2344
|
}
|
|
2345
2345
|
return;
|
|
2346
2346
|
}
|
|
2347
2347
|
if (key === "subject") {
|
|
2348
|
-
const subject = expectJsonObject(requiredValue2(
|
|
2348
|
+
const subject = expectJsonObject(requiredValue2(object2, "subject", path), `${path}.subject`);
|
|
2349
2349
|
assertExactKeys2(subject, ["did"], `${path}.subject`);
|
|
2350
2350
|
requiredString2(subject, "did", `${path}.subject`);
|
|
2351
2351
|
return;
|
|
2352
2352
|
}
|
|
2353
2353
|
if (key === "evidence") {
|
|
2354
|
-
validateEvidenceRequirement(requiredValue2(
|
|
2354
|
+
validateEvidenceRequirement(requiredValue2(object2, "evidence", path), `${path}.evidence`);
|
|
2355
2355
|
return;
|
|
2356
2356
|
}
|
|
2357
2357
|
throw new SignedObjectSchemaError(`${path} has unknown expression key ${key}`);
|
|
2358
2358
|
}
|
|
2359
2359
|
function validateEvidenceRequirement(input, path) {
|
|
2360
|
-
const
|
|
2360
|
+
const object2 = expectJsonObject(input, path);
|
|
2361
2361
|
assertExactKeys2(
|
|
2362
|
-
|
|
2362
|
+
object2,
|
|
2363
2363
|
["requirementId", "verifier", "requirements", "authority", "freshness"],
|
|
2364
2364
|
path
|
|
2365
2365
|
);
|
|
2366
|
-
requiredString2(
|
|
2367
|
-
requiredString2(
|
|
2368
|
-
requiredValue2(
|
|
2369
|
-
if (hasOwn2(
|
|
2370
|
-
const authority = expectJsonObject(requiredValue2(
|
|
2366
|
+
requiredString2(object2, "requirementId", path);
|
|
2367
|
+
requiredString2(object2, "verifier", path);
|
|
2368
|
+
requiredValue2(object2, "requirements", path);
|
|
2369
|
+
if (hasOwn2(object2, "authority")) {
|
|
2370
|
+
const authority = expectJsonObject(requiredValue2(object2, "authority", path), `${path}.authority`);
|
|
2371
2371
|
assertExactKeys2(
|
|
2372
2372
|
authority,
|
|
2373
2373
|
["profile", "acceptedIssuers", "allowOwnerAuthorizedIssuer"],
|
|
@@ -2379,35 +2379,35 @@ function validateEvidenceRequirement(input, path) {
|
|
|
2379
2379
|
}
|
|
2380
2380
|
optionalBoolean(authority, "allowOwnerAuthorizedIssuer", `${path}.authority`);
|
|
2381
2381
|
}
|
|
2382
|
-
if (hasOwn2(
|
|
2383
|
-
const freshness = expectJsonObject(requiredValue2(
|
|
2382
|
+
if (hasOwn2(object2, "freshness")) {
|
|
2383
|
+
const freshness = expectJsonObject(requiredValue2(object2, "freshness", path), `${path}.freshness`);
|
|
2384
2384
|
assertExactKeys2(freshness, ["maxStatusAgeSeconds"], `${path}.freshness`);
|
|
2385
2385
|
requiredInteger(freshness, "maxStatusAgeSeconds", `${path}.freshness`, 0);
|
|
2386
2386
|
}
|
|
2387
2387
|
}
|
|
2388
2388
|
function validateGrant(input, path) {
|
|
2389
|
-
const
|
|
2390
|
-
assertExactKeys2(
|
|
2391
|
-
expectConst(requiredString2(
|
|
2392
|
-
requiredInteger(
|
|
2393
|
-
expectOneOf(requiredString2(
|
|
2389
|
+
const object2 = expectJsonObject(input, path);
|
|
2390
|
+
assertExactKeys2(object2, ["output", "maxTtlSeconds", "delegationMode", "revocation"], path);
|
|
2391
|
+
expectConst(requiredString2(object2, "output", path), "portable-delegation", `${path}.output`);
|
|
2392
|
+
requiredInteger(object2, "maxTtlSeconds", path, 1);
|
|
2393
|
+
expectOneOf(requiredString2(object2, "delegationMode", path), [
|
|
2394
2394
|
"terminal",
|
|
2395
2395
|
"attenuable"
|
|
2396
2396
|
], `${path}.delegationMode`);
|
|
2397
|
-
expectOneOf(requiredString2(
|
|
2397
|
+
expectOneOf(requiredString2(object2, "revocation", path), [
|
|
2398
2398
|
"refresh_only",
|
|
2399
2399
|
"active_cutoff"
|
|
2400
2400
|
], `${path}.revocation`);
|
|
2401
2401
|
}
|
|
2402
2402
|
function validateDisclosure(input, path) {
|
|
2403
|
-
const
|
|
2404
|
-
assertExactKeys2(
|
|
2405
|
-
expectOneOf(requiredString2(
|
|
2403
|
+
const object2 = expectJsonObject(input, path);
|
|
2404
|
+
assertExactKeys2(object2, ["denial"], path);
|
|
2405
|
+
expectOneOf(requiredString2(object2, "denial", path), ["none", "code", "debug"], `${path}.denial`);
|
|
2406
2406
|
}
|
|
2407
2407
|
function validateAudit(input, path) {
|
|
2408
|
-
const
|
|
2409
|
-
assertExactKeys2(
|
|
2410
|
-
expectOneOf(requiredString2(
|
|
2408
|
+
const object2 = expectJsonObject(input, path);
|
|
2409
|
+
assertExactKeys2(object2, ["issuance"], path);
|
|
2410
|
+
expectOneOf(requiredString2(object2, "issuance", path), ["off", "security", "full"], `${path}.issuance`);
|
|
2411
2411
|
}
|
|
2412
2412
|
function materialForUnsigned(unsigned, descriptor) {
|
|
2413
2413
|
const jcs = jcsCanonicalize(unsigned);
|
|
@@ -2556,9 +2556,9 @@ function encodeSignatureValue(value, suite) {
|
|
|
2556
2556
|
decodeSignatureValue(encoded, suite);
|
|
2557
2557
|
return encoded;
|
|
2558
2558
|
}
|
|
2559
|
-
function stripOwnIdAndSignature(
|
|
2559
|
+
function stripOwnIdAndSignature(object2, descriptor) {
|
|
2560
2560
|
const output = /* @__PURE__ */ Object.create(null);
|
|
2561
|
-
for (const [key, value] of Object.entries(
|
|
2561
|
+
for (const [key, value] of Object.entries(object2)) {
|
|
2562
2562
|
if (key === descriptor.idField || key === "signature") {
|
|
2563
2563
|
continue;
|
|
2564
2564
|
}
|
|
@@ -2567,8 +2567,8 @@ function stripOwnIdAndSignature(object, descriptor) {
|
|
|
2567
2567
|
return output;
|
|
2568
2568
|
}
|
|
2569
2569
|
function descriptorForUnsigned(input) {
|
|
2570
|
-
const
|
|
2571
|
-
return descriptorForSchema(requiredString2(
|
|
2570
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2571
|
+
return descriptorForSchema(requiredString2(object2, "schema", "$"));
|
|
2572
2572
|
}
|
|
2573
2573
|
function descriptorForSchema(schema) {
|
|
2574
2574
|
if (schema === POLICY_SCHEMA) return DESCRIPTORS.Policy;
|
|
@@ -2582,28 +2582,28 @@ function expectJsonObject(input, path) {
|
|
|
2582
2582
|
}
|
|
2583
2583
|
return input;
|
|
2584
2584
|
}
|
|
2585
|
-
function assertExactKeys2(
|
|
2585
|
+
function assertExactKeys2(object2, allowed, path) {
|
|
2586
2586
|
const allowedSet = new Set(allowed);
|
|
2587
|
-
for (const key of Object.keys(
|
|
2587
|
+
for (const key of Object.keys(object2)) {
|
|
2588
2588
|
if (!allowedSet.has(key)) {
|
|
2589
2589
|
throw new SignedObjectSchemaError(`${path} has unknown field ${key}`);
|
|
2590
2590
|
}
|
|
2591
2591
|
}
|
|
2592
2592
|
}
|
|
2593
|
-
function requiredValue2(
|
|
2594
|
-
if (!hasOwn2(
|
|
2593
|
+
function requiredValue2(object2, key, path) {
|
|
2594
|
+
if (!hasOwn2(object2, key)) {
|
|
2595
2595
|
throw new SignedObjectSchemaError(`${path}.${key} is required`);
|
|
2596
2596
|
}
|
|
2597
|
-
return
|
|
2597
|
+
return object2[key];
|
|
2598
2598
|
}
|
|
2599
|
-
function requiredString2(
|
|
2600
|
-
return requireStringType(requiredValue2(
|
|
2599
|
+
function requiredString2(object2, key, path) {
|
|
2600
|
+
return requireStringType(requiredValue2(object2, key, path), `${path}.${key}`);
|
|
2601
2601
|
}
|
|
2602
|
-
function optionalString(
|
|
2603
|
-
if (!hasOwn2(
|
|
2602
|
+
function optionalString(object2, key, path) {
|
|
2603
|
+
if (!hasOwn2(object2, key)) {
|
|
2604
2604
|
return;
|
|
2605
2605
|
}
|
|
2606
|
-
requireStringType(requiredValue2(
|
|
2606
|
+
requireStringType(requiredValue2(object2, key, path), `${path}.${key}`);
|
|
2607
2607
|
}
|
|
2608
2608
|
function requireStringType(value, path) {
|
|
2609
2609
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2611,16 +2611,16 @@ function requireStringType(value, path) {
|
|
|
2611
2611
|
}
|
|
2612
2612
|
return value;
|
|
2613
2613
|
}
|
|
2614
|
-
function optionalBoolean(
|
|
2615
|
-
if (!hasOwn2(
|
|
2614
|
+
function optionalBoolean(object2, key, path) {
|
|
2615
|
+
if (!hasOwn2(object2, key)) {
|
|
2616
2616
|
return;
|
|
2617
2617
|
}
|
|
2618
|
-
if (typeof requiredValue2(
|
|
2618
|
+
if (typeof requiredValue2(object2, key, path) !== "boolean") {
|
|
2619
2619
|
throw new SignedObjectSchemaError(`${path}.${key} must be a boolean`);
|
|
2620
2620
|
}
|
|
2621
2621
|
}
|
|
2622
|
-
function requiredInteger(
|
|
2623
|
-
const value = requiredValue2(
|
|
2622
|
+
function requiredInteger(object2, key, path, minimum) {
|
|
2623
|
+
const value = requiredValue2(object2, key, path);
|
|
2624
2624
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum) {
|
|
2625
2625
|
throw new SignedObjectSchemaError(
|
|
2626
2626
|
`${path}.${key} must be an integer >= ${minimum}`
|
|
@@ -2628,8 +2628,8 @@ function requiredInteger(object, key, path, minimum) {
|
|
|
2628
2628
|
}
|
|
2629
2629
|
return value;
|
|
2630
2630
|
}
|
|
2631
|
-
function requiredArray2(
|
|
2632
|
-
const value = requiredValue2(
|
|
2631
|
+
function requiredArray2(object2, key, path, minimum) {
|
|
2632
|
+
const value = requiredValue2(object2, key, path);
|
|
2633
2633
|
if (!Array.isArray(value) || value.length < minimum) {
|
|
2634
2634
|
throw new SignedObjectSchemaError(
|
|
2635
2635
|
`${path}.${key} must be an array with at least ${minimum} item(s)`
|
|
@@ -2637,22 +2637,22 @@ function requiredArray2(object, key, path, minimum) {
|
|
|
2637
2637
|
}
|
|
2638
2638
|
return value;
|
|
2639
2639
|
}
|
|
2640
|
-
function requiredStringArray(
|
|
2641
|
-
const values = requiredArray2(
|
|
2640
|
+
function requiredStringArray(object2, key, path, check) {
|
|
2641
|
+
const values = requiredArray2(object2, key, path, 0);
|
|
2642
2642
|
for (let index = 0; index < values.length; index++) {
|
|
2643
2643
|
const itemPath = `${path}.${key}[${index}]`;
|
|
2644
2644
|
const value = requireStringType(values[index], itemPath);
|
|
2645
2645
|
check?.(value, itemPath);
|
|
2646
2646
|
}
|
|
2647
2647
|
}
|
|
2648
|
-
function requiredDateString(
|
|
2649
|
-
assertRfc3339(requiredString2(
|
|
2648
|
+
function requiredDateString(object2, key, path) {
|
|
2649
|
+
assertRfc3339(requiredString2(object2, key, path), `${path}.${key}`);
|
|
2650
2650
|
}
|
|
2651
|
-
function optionalDateString(
|
|
2652
|
-
if (!hasOwn2(
|
|
2651
|
+
function optionalDateString(object2, key, path) {
|
|
2652
|
+
if (!hasOwn2(object2, key)) {
|
|
2653
2653
|
return;
|
|
2654
2654
|
}
|
|
2655
|
-
assertRfc3339(requiredString2(
|
|
2655
|
+
assertRfc3339(requiredString2(object2, key, path), `${path}.${key}`);
|
|
2656
2656
|
}
|
|
2657
2657
|
function assertRfc3339(value, path) {
|
|
2658
2658
|
const match = value.match(
|
|
@@ -2684,8 +2684,8 @@ function expectOneOf(actual, allowed, path) {
|
|
|
2684
2684
|
}
|
|
2685
2685
|
throw new SignedObjectSchemaError(`${path} has unsupported value ${actual}`);
|
|
2686
2686
|
}
|
|
2687
|
-
function hasOwn2(
|
|
2688
|
-
return objectHasOwn3(
|
|
2687
|
+
function hasOwn2(object2, key) {
|
|
2688
|
+
return objectHasOwn3(object2, key);
|
|
2689
2689
|
}
|
|
2690
2690
|
function assertSupportedSignatureSuite(suite) {
|
|
2691
2691
|
if (suite !== ED25519_JCS_SIGNATURE_SUITE && suite !== EIP191_JCS_SIGNATURE_SUITE) {
|
|
@@ -2764,13 +2764,13 @@ function base64UrlDecode(value) {
|
|
|
2764
2764
|
return decoded;
|
|
2765
2765
|
}
|
|
2766
2766
|
function hexToBytes(value) {
|
|
2767
|
-
const
|
|
2768
|
-
if (
|
|
2767
|
+
const hex2 = value.slice(2);
|
|
2768
|
+
if (hex2.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(hex2)) {
|
|
2769
2769
|
throw new SignatureMaterialError("hex signature must have even length");
|
|
2770
2770
|
}
|
|
2771
|
-
const output = new Uint8Array(
|
|
2771
|
+
const output = new Uint8Array(hex2.length / 2);
|
|
2772
2772
|
for (let index = 0; index < output.length; index++) {
|
|
2773
|
-
output[index] = Number.parseInt(
|
|
2773
|
+
output[index] = Number.parseInt(hex2.slice(index * 2, index * 2 + 2), 16);
|
|
2774
2774
|
}
|
|
2775
2775
|
return output;
|
|
2776
2776
|
}
|
|
@@ -2912,9 +2912,9 @@ function expectObject2(input, path, code3) {
|
|
|
2912
2912
|
);
|
|
2913
2913
|
}
|
|
2914
2914
|
}
|
|
2915
|
-
function assertExactKeys3(
|
|
2915
|
+
function assertExactKeys3(object2, allowed, path) {
|
|
2916
2916
|
const allowedSet = new Set(allowed);
|
|
2917
|
-
for (const key of Object.keys(
|
|
2917
|
+
for (const key of Object.keys(object2)) {
|
|
2918
2918
|
if (!allowedSet.has(key)) {
|
|
2919
2919
|
throw new PolicyAuthoringError(
|
|
2920
2920
|
"policy-authoring-unknown-key",
|
|
@@ -2923,17 +2923,17 @@ function assertExactKeys3(object, allowed, path) {
|
|
|
2923
2923
|
}
|
|
2924
2924
|
}
|
|
2925
2925
|
}
|
|
2926
|
-
function requiredValue3(
|
|
2927
|
-
if (!hasOwn3(
|
|
2926
|
+
function requiredValue3(object2, key, path) {
|
|
2927
|
+
if (!hasOwn3(object2, key)) {
|
|
2928
2928
|
throw new PolicyAuthoringError(
|
|
2929
2929
|
"policy-authoring-malformed",
|
|
2930
2930
|
`${path}.${key} is required`
|
|
2931
2931
|
);
|
|
2932
2932
|
}
|
|
2933
|
-
return
|
|
2933
|
+
return object2[key];
|
|
2934
2934
|
}
|
|
2935
|
-
function requiredString3(
|
|
2936
|
-
const value = requiredValue3(
|
|
2935
|
+
function requiredString3(object2, key, path) {
|
|
2936
|
+
const value = requiredValue3(object2, key, path);
|
|
2937
2937
|
if (typeof value !== "string" || value.length === 0) {
|
|
2938
2938
|
throw new PolicyAuthoringError(
|
|
2939
2939
|
"policy-authoring-malformed",
|
|
@@ -2942,11 +2942,11 @@ function requiredString3(object, key, path) {
|
|
|
2942
2942
|
}
|
|
2943
2943
|
return value;
|
|
2944
2944
|
}
|
|
2945
|
-
function fieldString(
|
|
2946
|
-
if (!hasOwn3(
|
|
2945
|
+
function fieldString(object2, key, path, code3) {
|
|
2946
|
+
if (!hasOwn3(object2, key)) {
|
|
2947
2947
|
throw new PolicyAuthoringError(code3, `${path}.${key} is required`);
|
|
2948
2948
|
}
|
|
2949
|
-
const value =
|
|
2949
|
+
const value = object2[key];
|
|
2950
2950
|
if (typeof value !== "string" || value.length === 0) {
|
|
2951
2951
|
throw new PolicyAuthoringError(
|
|
2952
2952
|
code3,
|
|
@@ -2984,8 +2984,609 @@ function parseStrictRfc3339(value, path) {
|
|
|
2984
2984
|
var objectHasOwn4 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
|
|
2985
2985
|
Object.prototype.hasOwnProperty
|
|
2986
2986
|
);
|
|
2987
|
-
function hasOwn3(
|
|
2988
|
-
return objectHasOwn4(
|
|
2987
|
+
function hasOwn3(object2, key) {
|
|
2988
|
+
return objectHasOwn4(object2, key);
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
// src/policy/unified.ts
|
|
2992
|
+
import { sha256 as sha2564 } from "@noble/hashes/sha256";
|
|
2993
|
+
import { blake3 } from "@noble/hashes/blake3";
|
|
2994
|
+
import { ed25519 as ed255192 } from "@noble/curves/ed25519";
|
|
2995
|
+
import { z as z2 } from "zod";
|
|
2996
|
+
var POLICY_V1_SCHEMA = "xyz.tinycloud.policy/policy/v1";
|
|
2997
|
+
var POLICY_CAPABILITY_V1_SCHEMA = "xyz.tinycloud.policy/capability/v1";
|
|
2998
|
+
var POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA = "xyz.tinycloud.policy/enforcement-delegation/v2";
|
|
2999
|
+
var ATTESTED_ENFORCER_BINDING_V2_SCHEMA = "xyz.tinycloud.policy/attested-enforcer/v2";
|
|
3000
|
+
var ROOT_STATUS_CHECKPOINT_V1_SCHEMA = "xyz.tinycloud.policy/root-status/v1";
|
|
3001
|
+
var ROOT_REVOCATION_V1_SCHEMA = "xyz.tinycloud.policy/root-revocation/v1";
|
|
3002
|
+
var POLICY_SESSION_UCAN_V1_PROFILE = "policy-session-ucan/v1";
|
|
3003
|
+
var POLICY_V1_DOMAIN = "xyz.tinycloud.policy/policy/v1\0";
|
|
3004
|
+
var POLICY_CAPABILITY_V1_DOMAIN = "xyz.tinycloud.policy/PolicyCapability/v1\0";
|
|
3005
|
+
var CONTENT_SOURCE_V1_DOMAIN = "xyz.tinycloud.policy/ContentSource/v1\0";
|
|
3006
|
+
var NATIVE_PROJECTION_V1_DOMAIN = "xyz.tinycloud.policy/NativeProjection/v1\0";
|
|
3007
|
+
var ROOT_STATUS_V1_DOMAIN = "xyz.tinycloud.policy/RootStatusCheckpoint/v1\0";
|
|
3008
|
+
var ROOT_STATUS_RENEWAL_V1_DOMAIN = "xyz.tinycloud.policy/RootStatusRenewal/v1\0";
|
|
3009
|
+
var ROOT_REVOCATION_V1_DOMAIN = "xyz.tinycloud.policy/RootRevocation/v1\0";
|
|
3010
|
+
var LAST_V2_CREATE_AT = "2026-09-30T00:00:00Z";
|
|
3011
|
+
var MAX_LEGACY_ENVELOPE_EXPIRES_AT = "2026-12-29T00:00:00Z";
|
|
3012
|
+
var LAST_V2_READ_AT = "2027-01-05T00:00:00Z";
|
|
3013
|
+
function verifyPolicyRootStatusCheckpointV3(input) {
|
|
3014
|
+
const checkpoint = input.checkpoint;
|
|
3015
|
+
const allowed = /* @__PURE__ */ new Set(["schema", "targetCid", "targetRole", "ownerDid", "nodeAudience", "state", "sequence", "checkedAt", "freshUntil", "revokedAt", "revocationCid", "previousCheckpointDigestHex", "issuerDid", "signature"]);
|
|
3016
|
+
if (Object.keys(checkpoint).some((key) => !allowed.has(key)) || checkpoint.schema !== ROOT_STATUS_CHECKPOINT_V1_SCHEMA || checkpoint.targetCid !== input.rootCid || checkpoint.targetRole !== "policy-authority" && checkpoint.targetRole !== "policy-enforcement" || checkpoint.state !== "active" && checkpoint.state !== "revoked" || typeof checkpoint.ownerDid !== "string" || typeof checkpoint.nodeAudience !== "string" || checkpoint.issuerDid !== checkpoint.nodeAudience || input.expectedNodeAudience !== void 0 && checkpoint.nodeAudience !== input.expectedNodeAudience || !Number.isInteger(checkpoint.sequence) || checkpoint.sequence < 1 || typeof checkpoint.checkedAt !== "string" || typeof checkpoint.freshUntil !== "string") return false;
|
|
3017
|
+
const checkedAt = Date.parse(checkpoint.checkedAt);
|
|
3018
|
+
const freshUntil = Date.parse(checkpoint.freshUntil);
|
|
3019
|
+
const now = (input.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
3020
|
+
if (!Number.isFinite(checkedAt) || !Number.isFinite(freshUntil) || freshUntil < now || freshUntil <= checkedAt || freshUntil - checkedAt > 3e5) return false;
|
|
3021
|
+
if (checkpoint.sequence === 1 !== (checkpoint.previousCheckpointDigestHex === void 0)) return false;
|
|
3022
|
+
if (checkpoint.sequence !== 1 && (typeof checkpoint.previousCheckpointDigestHex !== "string" || !/^[0-9a-f]{64}$/.test(checkpoint.previousCheckpointDigestHex))) return false;
|
|
3023
|
+
if (checkpoint.state === "active" && (checkpoint.revokedAt !== void 0 || checkpoint.revocationCid !== void 0)) return false;
|
|
3024
|
+
if (checkpoint.state === "revoked" && (typeof checkpoint.revokedAt !== "string" || typeof checkpoint.revocationCid !== "string")) return false;
|
|
3025
|
+
const signature = checkpoint.signature;
|
|
3026
|
+
if (!isRecordValue(signature) || Object.keys(signature).length !== 3 || signature.suite !== "Ed25519" || signature.signerDid !== checkpoint.issuerDid || typeof signature.value !== "string") return false;
|
|
3027
|
+
try {
|
|
3028
|
+
const principal = checkpoint.issuerDid.split("#", 1)[0];
|
|
3029
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3030
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1) return false;
|
|
3031
|
+
const unsigned = { ...checkpoint };
|
|
3032
|
+
delete unsigned.signature;
|
|
3033
|
+
return ed255192.verify(
|
|
3034
|
+
decodeBase64Url(signature.value),
|
|
3035
|
+
sha2564(new TextEncoder().encode(ROOT_STATUS_V1_DOMAIN + jcsCanonicalize(unsigned))),
|
|
3036
|
+
didMaterial.slice(2)
|
|
3037
|
+
);
|
|
3038
|
+
} catch {
|
|
3039
|
+
return false;
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
async function getPolicyRootStatusV3(input) {
|
|
3043
|
+
const fetchFn = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
3044
|
+
const response = await fetchFn(new URL(`/share/v3/policy/status/${encodeURIComponent(input.rootCid)}`, input.nodeOrigin), {
|
|
3045
|
+
method: "GET",
|
|
3046
|
+
redirect: "error",
|
|
3047
|
+
headers: { accept: "application/json" }
|
|
3048
|
+
});
|
|
3049
|
+
if (!response.ok) throw new Error(`policy root status rejected (${response.status})`);
|
|
3050
|
+
const value = object(await response.json(), "policy root status");
|
|
3051
|
+
const checkpoint = object(value.checkpoint, "policy root checkpoint");
|
|
3052
|
+
if (value.rootCid !== input.rootCid || value.state !== "active" && value.state !== "revoked" || value.state !== checkpoint.state || !verifyPolicyRootStatusCheckpointV3({ rootCid: input.rootCid, checkpoint, expectedNodeAudience: input.expectedNodeAudience, now: input.now }))
|
|
3053
|
+
throw new Error("policy root status binding is invalid");
|
|
3054
|
+
const revocation = value.revocation === void 0 ? void 0 : object(value.revocation, "policy root revocation");
|
|
3055
|
+
if (value.state === "revoked" !== (revocation !== void 0) || revocation !== void 0 && !verifyPolicyRootRevocationV3({
|
|
3056
|
+
rootCid: input.rootCid,
|
|
3057
|
+
checkpoint,
|
|
3058
|
+
revocation,
|
|
3059
|
+
expectedEnforcerDid: input.expectedEnforcerDid
|
|
3060
|
+
})) throw new Error("policy root status revocation evidence is invalid");
|
|
3061
|
+
return { rootCid: input.rootCid, state: value.state, checkpoint, ...revocation === void 0 ? {} : { revocation } };
|
|
3062
|
+
}
|
|
3063
|
+
function verifyPolicyRootRevocationV3(input) {
|
|
3064
|
+
const value = input.revocation;
|
|
3065
|
+
const allowed = ["schema", "targetCid", "targetRole", "ownerDid", "nodeAudience", "revokedAt", "reason", "issuerDid", "signature"];
|
|
3066
|
+
if (Object.keys(value).length !== allowed.length || Object.keys(value).some((key) => !allowed.includes(key)) || value.schema !== ROOT_REVOCATION_V1_SCHEMA || value.targetCid !== input.rootCid || value.targetRole !== input.checkpoint.targetRole || value.ownerDid !== input.checkpoint.ownerDid || value.nodeAudience !== input.checkpoint.nodeAudience || value.revokedAt !== input.checkpoint.revokedAt || typeof value.reason !== "string" || value.reason.length === 0 || typeof value.issuerDid !== "string") return false;
|
|
3067
|
+
const authorized = value.issuerDid === value.ownerDid || value.targetRole === "policy-enforcement" && value.issuerDid === input.expectedEnforcerDid;
|
|
3068
|
+
if (!authorized) return false;
|
|
3069
|
+
const signature = value.signature;
|
|
3070
|
+
if (!isRecordValue(signature) || Object.keys(signature).length !== 3 || signature.suite !== "Ed25519" || signature.signerDid !== value.issuerDid || typeof signature.value !== "string") return false;
|
|
3071
|
+
try {
|
|
3072
|
+
const principal = value.issuerDid.split("#", 1)[0];
|
|
3073
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3074
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1) return false;
|
|
3075
|
+
const unsigned = { ...value };
|
|
3076
|
+
delete unsigned.signature;
|
|
3077
|
+
const digest4 = sha2564(new TextEncoder().encode(ROOT_REVOCATION_V1_DOMAIN + jcsCanonicalize(unsigned)));
|
|
3078
|
+
return input.checkpoint.revocationCid === hex(digest4) && ed255192.verify(decodeBase64Url(signature.value), digest4, didMaterial.slice(2));
|
|
3079
|
+
} catch {
|
|
3080
|
+
return false;
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
async function renewPolicyRootStatusV3(input) {
|
|
3084
|
+
const fetchFn = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
3085
|
+
const current = await getPolicyRootStatusV3({ nodeOrigin: input.nodeOrigin, rootCid: input.rootCid, expectedNodeAudience: input.nodeAudience, now: input.now, fetch: fetchFn });
|
|
3086
|
+
if (current.state !== "active" || current.checkpoint.ownerDid !== input.ownerDid || current.checkpoint.nodeAudience !== input.nodeAudience || current.checkpoint.state !== "active" || !Number.isInteger(current.checkpoint.sequence))
|
|
3087
|
+
throw new Error("policy root status cannot be renewed");
|
|
3088
|
+
const currentUnsigned = { ...current.checkpoint };
|
|
3089
|
+
delete currentUnsigned.signature;
|
|
3090
|
+
const previousCheckpointDigestHex = hex(sha2564(new TextEncoder().encode(ROOT_STATUS_V1_DOMAIN + jcsCanonicalize(currentUnsigned))));
|
|
3091
|
+
const unsigned = {
|
|
3092
|
+
schema: "xyz.tinycloud.policy/root-status-renewal/v1",
|
|
3093
|
+
targetCid: input.rootCid,
|
|
3094
|
+
ownerDid: input.ownerDid,
|
|
3095
|
+
nodeAudience: input.nodeAudience,
|
|
3096
|
+
issuedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
3097
|
+
nonce: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16))),
|
|
3098
|
+
sequence: current.checkpoint.sequence + 1,
|
|
3099
|
+
previousCheckpointDigestHex
|
|
3100
|
+
};
|
|
3101
|
+
const signature = await input.sign(sha2564(new TextEncoder().encode(ROOT_STATUS_RENEWAL_V1_DOMAIN + jcsCanonicalize(unsigned))));
|
|
3102
|
+
if (signature.length !== 64) throw new Error("policy root renewal signature must be Ed25519");
|
|
3103
|
+
const response = await fetchFn(new URL("/share/v3/policy/status", input.nodeOrigin), {
|
|
3104
|
+
method: "POST",
|
|
3105
|
+
redirect: "error",
|
|
3106
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3107
|
+
body: JSON.stringify({ rootCid: input.rootCid, renewal: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.ownerDid, value: encodeBase64Url(signature) } } })
|
|
3108
|
+
});
|
|
3109
|
+
if (!response.ok) throw new Error(`policy root renewal rejected (${response.status})`);
|
|
3110
|
+
return object(await response.json(), "policy root renewal");
|
|
3111
|
+
}
|
|
3112
|
+
async function revokePolicyRootV3(input) {
|
|
3113
|
+
if (input.reason.length === 0) throw new Error("policy root revocation reason is required");
|
|
3114
|
+
const unsigned = {
|
|
3115
|
+
schema: ROOT_REVOCATION_V1_SCHEMA,
|
|
3116
|
+
targetCid: input.rootCid,
|
|
3117
|
+
targetRole: input.targetRole,
|
|
3118
|
+
ownerDid: input.ownerDid,
|
|
3119
|
+
nodeAudience: input.nodeAudience,
|
|
3120
|
+
revokedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
3121
|
+
reason: input.reason,
|
|
3122
|
+
issuerDid: input.issuerDid
|
|
3123
|
+
};
|
|
3124
|
+
const signature = await input.sign(sha2564(new TextEncoder().encode(ROOT_REVOCATION_V1_DOMAIN + jcsCanonicalize(unsigned))));
|
|
3125
|
+
if (signature.length !== 64) throw new Error("policy root revocation signature must be Ed25519");
|
|
3126
|
+
const fetchFn = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
3127
|
+
const response = await fetchFn(new URL("/revoke", input.nodeOrigin), {
|
|
3128
|
+
method: "POST",
|
|
3129
|
+
redirect: "error",
|
|
3130
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3131
|
+
body: JSON.stringify({ revocation: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.issuerDid, value: encodeBase64Url(signature) } } })
|
|
3132
|
+
});
|
|
3133
|
+
if (!response.ok) throw new Error(`policy root revocation rejected (${response.status})`);
|
|
3134
|
+
return object(await response.json(), "policy root revocation");
|
|
3135
|
+
}
|
|
3136
|
+
var POLICY_SESSION_FACT_KEYS = [
|
|
3137
|
+
"profile",
|
|
3138
|
+
"ownerDid",
|
|
3139
|
+
"policyId",
|
|
3140
|
+
"policyDigestHex",
|
|
3141
|
+
"policyCid",
|
|
3142
|
+
"policyDelegationCid",
|
|
3143
|
+
"enforcementDelegationCid",
|
|
3144
|
+
"contentSourceDigestHex",
|
|
3145
|
+
"capabilityCeilingHashHex",
|
|
3146
|
+
"nativeProjectionHashHex",
|
|
3147
|
+
"enforcerDid",
|
|
3148
|
+
"nodeAudience",
|
|
3149
|
+
"recipientDid",
|
|
3150
|
+
"challengeId",
|
|
3151
|
+
"claimDigestHex",
|
|
3152
|
+
"claimJti",
|
|
3153
|
+
"vpDigestHex",
|
|
3154
|
+
"credentialEvidenceDigestHex",
|
|
3155
|
+
"decisionContextDigestHex",
|
|
3156
|
+
"issuanceAuditDigestHex",
|
|
3157
|
+
"remainingRedelegationDepth"
|
|
3158
|
+
];
|
|
3159
|
+
var KV_ACTIONS = /* @__PURE__ */ new Set([
|
|
3160
|
+
"tinycloud.kv/get",
|
|
3161
|
+
"tinycloud.kv/list",
|
|
3162
|
+
"tinycloud.kv/metadata",
|
|
3163
|
+
"tinycloud.kv/put"
|
|
3164
|
+
]);
|
|
3165
|
+
function object(value, label) {
|
|
3166
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
3167
|
+
throw new Error(`${label} must be an object`);
|
|
3168
|
+
}
|
|
3169
|
+
return value;
|
|
3170
|
+
}
|
|
3171
|
+
function exactKeys(value, allowed, label) {
|
|
3172
|
+
const keys = new Set(allowed);
|
|
3173
|
+
if (Object.keys(value).some((key) => !keys.has(key)))
|
|
3174
|
+
throw new Error(`${label} contains an unknown field`);
|
|
3175
|
+
}
|
|
3176
|
+
function nonEmptyString(value, label) {
|
|
3177
|
+
if (typeof value !== "string" || value.length === 0)
|
|
3178
|
+
throw new Error(`${label} must be a non-empty string`);
|
|
3179
|
+
return value;
|
|
3180
|
+
}
|
|
3181
|
+
function parseKvResource(resource) {
|
|
3182
|
+
const match = /^tinycloud:\/\/([^/]+)\/kv\/(.+)$/.exec(resource);
|
|
3183
|
+
if (!match || match[1].includes(":") || match[1].includes("?") || match[1].includes("#") || match[1].includes("%") || match[2].startsWith("/") || match[2].endsWith("/") || match[2].includes("//") || match[2].split("/").some((part) => part === "." || part === ".." || part.length === 0)) {
|
|
3184
|
+
throw new Error("KV resource is not canonical");
|
|
3185
|
+
}
|
|
3186
|
+
return { space: match[1], path: match[2] };
|
|
3187
|
+
}
|
|
3188
|
+
function parseEncryptionResource(resource) {
|
|
3189
|
+
if (!resource.startsWith("urn:tinycloud:encryption:")) throw new Error("encryption capability is invalid");
|
|
3190
|
+
const rest = resource.slice("urn:tinycloud:encryption:".length);
|
|
3191
|
+
const separator = rest.lastIndexOf(":");
|
|
3192
|
+
const ownerDid = separator < 0 ? "" : rest.slice(0, separator);
|
|
3193
|
+
const network = separator < 0 ? "" : rest.slice(separator + 1);
|
|
3194
|
+
if (!ownerDid.startsWith("did:") || network.length === 0 || network.includes(":") || network.includes("/") || network.includes("%") || network.includes("?") || network.includes("#")) {
|
|
3195
|
+
throw new Error("encryption capability is invalid");
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
function normalizeUnifiedPolicyCapability(input) {
|
|
3199
|
+
const value = object(input, "capability");
|
|
3200
|
+
const kind = nonEmptyString(value.kind, "capability.kind");
|
|
3201
|
+
if (kind === "kv") {
|
|
3202
|
+
exactKeys(
|
|
3203
|
+
value,
|
|
3204
|
+
["kind", "resource", "selector", "actions"],
|
|
3205
|
+
"KV capability"
|
|
3206
|
+
);
|
|
3207
|
+
const resource = nonEmptyString(value.resource, "capability.resource");
|
|
3208
|
+
parseKvResource(resource);
|
|
3209
|
+
if (value.selector !== "exact" && value.selector !== "prefix")
|
|
3210
|
+
throw new Error("capability.selector is invalid");
|
|
3211
|
+
if (!Array.isArray(value.actions) || value.actions.length === 0)
|
|
3212
|
+
throw new Error("capability.actions is invalid");
|
|
3213
|
+
const actions = value.actions.map(
|
|
3214
|
+
(action) => nonEmptyString(action, "capability.actions[]")
|
|
3215
|
+
);
|
|
3216
|
+
if (new Set(actions).size !== actions.length || actions.some((action) => !KV_ACTIONS.has(action)))
|
|
3217
|
+
throw new Error("capability.actions is invalid");
|
|
3218
|
+
return {
|
|
3219
|
+
kind: "kv",
|
|
3220
|
+
resource,
|
|
3221
|
+
selector: value.selector,
|
|
3222
|
+
actions: [...actions].sort()
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
if (kind === "encryption") {
|
|
3226
|
+
exactKeys(value, ["kind", "resource", "action"], "encryption capability");
|
|
3227
|
+
const resource = nonEmptyString(value.resource, "capability.resource");
|
|
3228
|
+
if (value.action !== "tinycloud.encryption/decrypt")
|
|
3229
|
+
throw new Error("encryption capability is invalid");
|
|
3230
|
+
parseEncryptionResource(resource);
|
|
3231
|
+
return {
|
|
3232
|
+
kind: "encryption",
|
|
3233
|
+
resource,
|
|
3234
|
+
action: "tinycloud.encryption/decrypt"
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
throw new Error("capability.kind is invalid");
|
|
3238
|
+
}
|
|
3239
|
+
function canonicalizeUnifiedPolicyCapability(input) {
|
|
3240
|
+
return normalizeUnifiedPolicyCapability(input);
|
|
3241
|
+
}
|
|
3242
|
+
function unifiedPolicyCapabilityDigestHex(input) {
|
|
3243
|
+
return hex(
|
|
3244
|
+
sha2564(
|
|
3245
|
+
new TextEncoder().encode(
|
|
3246
|
+
POLICY_CAPABILITY_V1_DOMAIN + jcsCanonicalize(normalizeUnifiedPolicyCapability(input))
|
|
3247
|
+
)
|
|
3248
|
+
)
|
|
3249
|
+
);
|
|
3250
|
+
}
|
|
3251
|
+
function unifiedPolicyCapabilityContains(authorityInput, requestedInput) {
|
|
3252
|
+
try {
|
|
3253
|
+
const authority = normalizeUnifiedPolicyCapability(authorityInput);
|
|
3254
|
+
const requested = normalizeUnifiedPolicyCapability(requestedInput);
|
|
3255
|
+
if (authority.kind !== requested.kind) return false;
|
|
3256
|
+
if (authority.kind === "encryption" && requested.kind === "encryption")
|
|
3257
|
+
return authority.resource === requested.resource && authority.action === requested.action;
|
|
3258
|
+
if (authority.kind !== "kv" || requested.kind !== "kv") return false;
|
|
3259
|
+
const { resource: authorized } = authority;
|
|
3260
|
+
const { resource: requestedResource } = requested;
|
|
3261
|
+
const pathContained = authority.selector === "exact" ? authorized === requestedResource : authorized === requestedResource || requestedResource.startsWith(`${authorized}/`);
|
|
3262
|
+
if (!pathContained || authority.selector === "exact" && requested.selector === "prefix")
|
|
3263
|
+
return false;
|
|
3264
|
+
return requested.actions.every(
|
|
3265
|
+
(action) => authority.actions.includes(action)
|
|
3266
|
+
);
|
|
3267
|
+
} catch {
|
|
3268
|
+
return false;
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
function projectUnifiedPolicyCapability(input) {
|
|
3272
|
+
const capability = normalizeUnifiedPolicyCapability(input);
|
|
3273
|
+
if (capability.kind === "encryption") {
|
|
3274
|
+
return {
|
|
3275
|
+
service: "tinycloud.encryption",
|
|
3276
|
+
space: capability.resource,
|
|
3277
|
+
path: capability.resource,
|
|
3278
|
+
actions: [capability.action]
|
|
3279
|
+
};
|
|
3280
|
+
}
|
|
3281
|
+
const { space, path } = parseKvResource(capability.resource);
|
|
3282
|
+
return {
|
|
3283
|
+
service: "tinycloud.kv",
|
|
3284
|
+
space,
|
|
3285
|
+
path,
|
|
3286
|
+
actions: [...capability.actions],
|
|
3287
|
+
caveat: {
|
|
3288
|
+
type: "xyz.tinycloud.resource/selector",
|
|
3289
|
+
kind: capability.selector,
|
|
3290
|
+
value: capability.resource
|
|
3291
|
+
}
|
|
3292
|
+
};
|
|
3293
|
+
}
|
|
3294
|
+
function projectUnifiedPolicyCapabilities(input) {
|
|
3295
|
+
return input.map(projectUnifiedPolicyCapability).sort((left, right) => {
|
|
3296
|
+
const a = jcsCanonicalize(left);
|
|
3297
|
+
const b = jcsCanonicalize(right);
|
|
3298
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
3299
|
+
});
|
|
3300
|
+
}
|
|
3301
|
+
function unifiedNativeProjectionHashHex(input) {
|
|
3302
|
+
return hex(
|
|
3303
|
+
sha2564(
|
|
3304
|
+
new TextEncoder().encode(
|
|
3305
|
+
NATIVE_PROJECTION_V1_DOMAIN + jcsCanonicalize(projectUnifiedPolicyCapabilities(input))
|
|
3306
|
+
)
|
|
3307
|
+
)
|
|
3308
|
+
);
|
|
3309
|
+
}
|
|
3310
|
+
function unifiedPolicyCapabilityFromNative(input) {
|
|
3311
|
+
const value = object(input, "native capability");
|
|
3312
|
+
exactKeys(
|
|
3313
|
+
value,
|
|
3314
|
+
["service", "space", "path", "actions", "caveat"],
|
|
3315
|
+
"native capability"
|
|
3316
|
+
);
|
|
3317
|
+
const service = nonEmptyString(value.service, "native.service");
|
|
3318
|
+
const actions = value.actions;
|
|
3319
|
+
if (!Array.isArray(actions)) throw new Error("native.actions is invalid");
|
|
3320
|
+
if (service === "tinycloud.encryption" && value.caveat === void 0 && value.space === value.path && actions.length === 1 && actions[0] === "tinycloud.encryption/decrypt") {
|
|
3321
|
+
return normalizeUnifiedPolicyCapability({
|
|
3322
|
+
kind: "encryption",
|
|
3323
|
+
resource: value.space,
|
|
3324
|
+
action: actions[0]
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
if (service !== "tinycloud.kv" || typeof value.space !== "string" || typeof value.path !== "string")
|
|
3328
|
+
throw new Error("native capability is not supported");
|
|
3329
|
+
const caveat = object(value.caveat, "native.caveat");
|
|
3330
|
+
exactKeys(caveat, ["type", "kind", "value"], "native selector caveat");
|
|
3331
|
+
if (caveat.type !== "xyz.tinycloud.resource/selector" || caveat.kind !== "exact" && caveat.kind !== "prefix" || caveat.value !== `tinycloud://${value.space}/kv/${value.path}`)
|
|
3332
|
+
throw new Error("native selector caveat does not match capability");
|
|
3333
|
+
return normalizeUnifiedPolicyCapability({
|
|
3334
|
+
kind: "kv",
|
|
3335
|
+
resource: caveat.value,
|
|
3336
|
+
selector: caveat.kind,
|
|
3337
|
+
actions
|
|
3338
|
+
});
|
|
3339
|
+
}
|
|
3340
|
+
function contentSourceDigestHex(input) {
|
|
3341
|
+
return hex(
|
|
3342
|
+
sha2564(
|
|
3343
|
+
new TextEncoder().encode(
|
|
3344
|
+
CONTENT_SOURCE_V1_DOMAIN + jcsCanonicalize(input)
|
|
3345
|
+
)
|
|
3346
|
+
)
|
|
3347
|
+
);
|
|
3348
|
+
}
|
|
3349
|
+
function policyDigestHex(policy) {
|
|
3350
|
+
const canonicalPolicy = {
|
|
3351
|
+
...policy,
|
|
3352
|
+
capabilityCeiling: policy.capabilityCeiling.map(
|
|
3353
|
+
normalizeUnifiedPolicyCapability
|
|
3354
|
+
)
|
|
3355
|
+
};
|
|
3356
|
+
return hex(
|
|
3357
|
+
sha2564(
|
|
3358
|
+
new TextEncoder().encode(
|
|
3359
|
+
POLICY_V1_DOMAIN + jcsCanonicalize(canonicalPolicy)
|
|
3360
|
+
)
|
|
3361
|
+
)
|
|
3362
|
+
);
|
|
3363
|
+
}
|
|
3364
|
+
function policyIdForDigestHex(digestHex) {
|
|
3365
|
+
const digest4 = Uint8Array.from(
|
|
3366
|
+
(digestHex.match(/.{2}/g) ?? []).map((byte) => Number.parseInt(byte, 16))
|
|
3367
|
+
);
|
|
3368
|
+
if (digest4.length !== 32) throw new Error("policy digest must be 32 bytes");
|
|
3369
|
+
return `pol_${base32Lower(digest4)}`;
|
|
3370
|
+
}
|
|
3371
|
+
function policyCidFromCanonicalBytes(bytes2) {
|
|
3372
|
+
return CID.createV1(85, create(18, sha2564(bytes2))).toString();
|
|
3373
|
+
}
|
|
3374
|
+
var CompactHeaderSchema = z2.object({
|
|
3375
|
+
alg: z2.literal("EdDSA"),
|
|
3376
|
+
jwk: z2.object({ alg: z2.literal("EdDSA"), crv: z2.literal("Ed25519"), kty: z2.literal("OKP"), x: z2.string().min(1) }).strict(),
|
|
3377
|
+
typ: z2.literal("JWT"),
|
|
3378
|
+
ucv: z2.literal("0.10.0")
|
|
3379
|
+
}).strict();
|
|
3380
|
+
var CompactPayloadSchema = z2.object({
|
|
3381
|
+
att: z2.record(z2.record(z2.array(z2.unknown()).min(1))),
|
|
3382
|
+
aud: z2.string().min(1),
|
|
3383
|
+
exp: z2.number().int(),
|
|
3384
|
+
fct: z2.array(z2.record(z2.unknown())).length(1),
|
|
3385
|
+
iss: z2.string().min(1),
|
|
3386
|
+
nbf: z2.number().int(),
|
|
3387
|
+
nnc: z2.string().min(1),
|
|
3388
|
+
prf: z2.array(z2.string().min(1))
|
|
3389
|
+
}).strict();
|
|
3390
|
+
async function signCompactUcanAuthorization(input) {
|
|
3391
|
+
if (input.notBefore >= input.expiresAt || input.expiresAt - input.notBefore > 60)
|
|
3392
|
+
throw new Error("compact invocation lifetime must be between one and 60 seconds");
|
|
3393
|
+
const principal = input.issuerDid.split("#", 1)[0];
|
|
3394
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3395
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1)
|
|
3396
|
+
throw new Error("compact UCAN signer must be did:key Ed25519");
|
|
3397
|
+
const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(didMaterial.slice(2)) }, typ: "JWT", ucv: "0.10.0" };
|
|
3398
|
+
const payload = {
|
|
3399
|
+
att: input.attenuation,
|
|
3400
|
+
aud: input.audienceDid,
|
|
3401
|
+
exp: input.expiresAt,
|
|
3402
|
+
fct: input.facts,
|
|
3403
|
+
iss: input.issuerDid.includes("#") ? input.issuerDid : `${principal}#${principal.slice("did:key:".length)}`,
|
|
3404
|
+
nbf: input.notBefore,
|
|
3405
|
+
nnc: input.nonce,
|
|
3406
|
+
prf: input.proofs
|
|
3407
|
+
};
|
|
3408
|
+
const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
|
|
3409
|
+
const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
|
|
3410
|
+
const signature = await input.sign(new TextEncoder().encode(`${protectedSegment}.${payloadSegment}`));
|
|
3411
|
+
if (signature.length !== 64) throw new Error("compact Authorization signature must be Ed25519");
|
|
3412
|
+
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3413
|
+
}
|
|
3414
|
+
function createCompactPolicyInvocation(input) {
|
|
3415
|
+
const session = parsePolicySessionUcan(input.sessionAuthorization);
|
|
3416
|
+
if (session.cid !== input.sessionCid || session.aud !== input.recipientDid)
|
|
3417
|
+
throw new Error("policy session does not bind the recipient signer");
|
|
3418
|
+
const principal = input.recipientDid.split("#", 1)[0];
|
|
3419
|
+
const didMaterial = base58btc.decode(principal.slice("did:key:".length));
|
|
3420
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1)
|
|
3421
|
+
throw new Error("policy invocation signer must be did:key Ed25519");
|
|
3422
|
+
const publicKey = ed255192.getPublicKey(input.privateKey);
|
|
3423
|
+
if (!equalBytes(publicKey, didMaterial.slice(2)))
|
|
3424
|
+
throw new Error("policy invocation private key does not bind recipient DID");
|
|
3425
|
+
const now = input.now ?? Math.floor(Date.now() / 1e3);
|
|
3426
|
+
const exp = Math.min(now + 60, session.exp);
|
|
3427
|
+
if (exp <= now) throw new Error("policy session has expired");
|
|
3428
|
+
const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(publicKey) }, typ: "JWT", ucv: "0.10.0" };
|
|
3429
|
+
const payload = {
|
|
3430
|
+
att: { [input.resource]: { [input.action]: [input.caveat ?? {}] } },
|
|
3431
|
+
aud: input.audienceDid,
|
|
3432
|
+
exp,
|
|
3433
|
+
fct: [input.facts ?? { type: "tinycloud.policy.invocation/v1", policyCid: session.fact.policyCid, sessionCid: session.cid }],
|
|
3434
|
+
iss: input.recipientDid.includes("#") ? input.recipientDid : `${principal}#${principal.slice("did:key:".length)}`,
|
|
3435
|
+
nbf: now,
|
|
3436
|
+
nnc: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16))),
|
|
3437
|
+
prf: [session.cid]
|
|
3438
|
+
};
|
|
3439
|
+
const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
|
|
3440
|
+
const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
|
|
3441
|
+
const signingInput = new TextEncoder().encode(`${protectedSegment}.${payloadSegment}`);
|
|
3442
|
+
const signature = ed255192.sign(signingInput, input.privateKey);
|
|
3443
|
+
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3444
|
+
}
|
|
3445
|
+
function createCompactPolicyDescendant(input) {
|
|
3446
|
+
const parent = parseCompactUcanAuthorization(input.parentAuthorization, input.parentCid);
|
|
3447
|
+
if (parent.payload.aud !== input.issuerDid) throw new Error("policy descendant issuer is not the parent audience");
|
|
3448
|
+
const parentFact = parent.payload.fct[0];
|
|
3449
|
+
const depth = parentFact.remainingRedelegationDepth;
|
|
3450
|
+
if (!Number.isInteger(depth) || depth <= 0) throw new Error("policy descendant depth is exhausted");
|
|
3451
|
+
if (!compactAttenuationContains(parent.payload.att, input.attenuation))
|
|
3452
|
+
throw new Error("policy descendant exceeds the parent attenuation");
|
|
3453
|
+
const principal = input.issuerDid.split("#", 1)[0];
|
|
3454
|
+
const didMaterial = base58btc.decode(principal.slice("did:key:".length));
|
|
3455
|
+
const publicKey = ed255192.getPublicKey(input.privateKey);
|
|
3456
|
+
if (didMaterial.length !== 34 || !equalBytes(publicKey, didMaterial.slice(2))) throw new Error("policy descendant signer does not bind issuer DID");
|
|
3457
|
+
const now = Math.max(input.now ?? Math.floor(Date.now() / 1e3), parent.payload.nbf + 1);
|
|
3458
|
+
const exp = Math.min(input.expiresAt ?? now + 60, now + 60, parent.payload.exp - 1);
|
|
3459
|
+
if (exp <= now) throw new Error("policy parent has no strictly narrower validity window");
|
|
3460
|
+
const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(publicKey) }, typ: "JWT", ucv: "0.10.0" };
|
|
3461
|
+
const payload = {
|
|
3462
|
+
att: input.attenuation,
|
|
3463
|
+
aud: input.audienceDid,
|
|
3464
|
+
exp,
|
|
3465
|
+
fct: [{ ...parentFact, remainingRedelegationDepth: depth - 1 }],
|
|
3466
|
+
iss: input.issuerDid.includes("#") ? input.issuerDid : `${principal}#${principal.slice("did:key:".length)}`,
|
|
3467
|
+
nbf: now,
|
|
3468
|
+
nnc: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16))),
|
|
3469
|
+
prf: [parent.cid]
|
|
3470
|
+
};
|
|
3471
|
+
const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
|
|
3472
|
+
const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
|
|
3473
|
+
const signature = ed255192.sign(new TextEncoder().encode(`${protectedSegment}.${payloadSegment}`), input.privateKey);
|
|
3474
|
+
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3475
|
+
}
|
|
3476
|
+
function compactAttenuationContains(parent, child) {
|
|
3477
|
+
const selector = (value) => {
|
|
3478
|
+
if (value.length !== 1 || !isRecordValue(value[0])) return void 0;
|
|
3479
|
+
const caveat = value[0];
|
|
3480
|
+
if (Object.keys(caveat).length !== 3 || caveat.type !== "xyz.tinycloud.resource/selector" || caveat.kind !== "exact" && caveat.kind !== "prefix" || typeof caveat.value !== "string") return void 0;
|
|
3481
|
+
return { kind: caveat.kind, value: caveat.value };
|
|
3482
|
+
};
|
|
3483
|
+
const equal = (left, right) => jcsCanonicalize(left) === jcsCanonicalize(right);
|
|
3484
|
+
return Object.entries(child).every(
|
|
3485
|
+
([childResource, childActions]) => Object.entries(childActions).every(
|
|
3486
|
+
([action, childCaveats]) => Object.entries(parent).some(([parentResource, parentActions]) => {
|
|
3487
|
+
const parentCaveats = parentActions[action];
|
|
3488
|
+
if (parentCaveats === void 0) return false;
|
|
3489
|
+
if (parentResource === childResource && equal(parentCaveats, childCaveats)) return true;
|
|
3490
|
+
const parentSelector = selector(parentCaveats);
|
|
3491
|
+
const childSelector = selector(childCaveats);
|
|
3492
|
+
return parentSelector?.kind === "prefix" && childSelector !== void 0 && parentSelector.value === parentResource && childSelector.value === childResource && (childResource === parentResource || childResource.startsWith(`${parentResource}/`));
|
|
3493
|
+
})
|
|
3494
|
+
)
|
|
3495
|
+
);
|
|
3496
|
+
}
|
|
3497
|
+
function isRecordValue(value) {
|
|
3498
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3499
|
+
}
|
|
3500
|
+
function parseCompactUcanAuthorization(input, expectedCid) {
|
|
3501
|
+
if (typeof input !== "string" || /\s/.test(input))
|
|
3502
|
+
throw new Error("Authorization must be compact UCAN bytes");
|
|
3503
|
+
const segments = input.split(".");
|
|
3504
|
+
if (segments.length !== 3 || segments.some((segment) => segment.length === 0))
|
|
3505
|
+
throw new Error("Authorization must have three compact segments");
|
|
3506
|
+
const [headerSegment, payloadSegment, signatureSegment] = segments;
|
|
3507
|
+
const headerBytes = decodeBase64Url(headerSegment);
|
|
3508
|
+
const payloadBytes = decodeBase64Url(payloadSegment);
|
|
3509
|
+
const signature = decodeBase64Url(signatureSegment);
|
|
3510
|
+
const headerValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(headerBytes));
|
|
3511
|
+
const payloadValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(payloadBytes));
|
|
3512
|
+
if (jcsCanonicalize(headerValue) !== new TextDecoder().decode(headerBytes) || jcsCanonicalize(payloadValue) !== new TextDecoder().decode(payloadBytes))
|
|
3513
|
+
throw new Error("compact UCAN segments are not canonical JCS");
|
|
3514
|
+
const header = CompactHeaderSchema.parse(headerValue);
|
|
3515
|
+
const payload = CompactPayloadSchema.parse(payloadValue);
|
|
3516
|
+
if (payload.nbf >= payload.exp) throw new Error("compact UCAN validity is empty");
|
|
3517
|
+
const principal = payload.iss.split("#", 1)[0];
|
|
3518
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3519
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1)
|
|
3520
|
+
throw new Error("compact UCAN issuer must be did:key Ed25519");
|
|
3521
|
+
const publicKey = didMaterial.slice(2);
|
|
3522
|
+
if (!equalBytes(publicKey, decodeBase64Url(header.jwk.x)))
|
|
3523
|
+
throw new Error("compact UCAN JWK does not bind issuer");
|
|
3524
|
+
if (!ed255192.verify(signature, new TextEncoder().encode(`${headerSegment}.${payloadSegment}`), publicKey))
|
|
3525
|
+
throw new Error("compact UCAN signature is invalid");
|
|
3526
|
+
const cid2 = CID.createV1(85, create(30, blake3(new TextEncoder().encode(input)))).toString();
|
|
3527
|
+
if (expectedCid !== void 0 && cid2 !== expectedCid)
|
|
3528
|
+
throw new Error("compact UCAN CID does not match exact Authorization bytes");
|
|
3529
|
+
return { authorization: input, cid: cid2, header, payload };
|
|
3530
|
+
}
|
|
3531
|
+
function parsePolicySessionUcan(authorization, expectedProofs) {
|
|
3532
|
+
const parsed = parseCompactUcanAuthorization(authorization);
|
|
3533
|
+
const fact = parsed.payload.fct[0];
|
|
3534
|
+
if (parsed.payload.prf.length !== 2 || parsed.payload.prf[0] === parsed.payload.prf[1])
|
|
3535
|
+
throw new Error("policy session UCAN requires two distinct ordered proofs");
|
|
3536
|
+
if (expectedProofs !== void 0 && (parsed.payload.prf[0] !== expectedProofs[0] || parsed.payload.prf[1] !== expectedProofs[1]))
|
|
3537
|
+
throw new Error("policy session UCAN ordered proofs do not match");
|
|
3538
|
+
const factKeys = Object.keys(fact);
|
|
3539
|
+
if (factKeys.length !== POLICY_SESSION_FACT_KEYS.length || factKeys.some((key) => !POLICY_SESSION_FACT_KEYS.includes(key)) || POLICY_SESSION_FACT_KEYS.some((key) => !(key in fact)))
|
|
3540
|
+
throw new Error("policy session UCAN fact is incomplete");
|
|
3541
|
+
if (fact.profile !== POLICY_SESSION_UCAN_V1_PROFILE || typeof fact.remainingRedelegationDepth !== "number" || !Number.isInteger(fact.remainingRedelegationDepth) || fact.remainingRedelegationDepth < 0 || fact.remainingRedelegationDepth > 8 || parsed.payload.exp - parsed.payload.nbf > 60 || parsed.payload.iss.split("#", 1)[0] !== fact.enforcerDid || parsed.payload.aud !== fact.recipientDid)
|
|
3542
|
+
throw new Error("policy session UCAN fact is invalid");
|
|
3543
|
+
return {
|
|
3544
|
+
authorization,
|
|
3545
|
+
cid: parsed.cid,
|
|
3546
|
+
iss: parsed.payload.iss,
|
|
3547
|
+
aud: parsed.payload.aud,
|
|
3548
|
+
prf: parsed.payload.prf,
|
|
3549
|
+
att: parsed.payload.att,
|
|
3550
|
+
nbf: parsed.payload.nbf,
|
|
3551
|
+
exp: parsed.payload.exp,
|
|
3552
|
+
nnc: parsed.payload.nnc,
|
|
3553
|
+
fact
|
|
3554
|
+
};
|
|
3555
|
+
}
|
|
3556
|
+
function decodeBase64Url(value) {
|
|
3557
|
+
if (!/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1)
|
|
3558
|
+
throw new Error("value is not canonical base64url");
|
|
3559
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
3560
|
+
const binary = typeof Buffer !== "undefined" ? Buffer.from(normalized, "base64").toString("binary") : atob(normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "="));
|
|
3561
|
+
const bytes2 = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
3562
|
+
const encoded = typeof Buffer !== "undefined" ? Buffer.from(bytes2).toString("base64url") : btoa(String.fromCharCode(...bytes2)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
3563
|
+
if (encoded !== value) throw new Error("value is not canonical base64url");
|
|
3564
|
+
return bytes2;
|
|
3565
|
+
}
|
|
3566
|
+
function encodeBase64Url(value) {
|
|
3567
|
+
return typeof Buffer !== "undefined" ? Buffer.from(value).toString("base64url") : btoa(String.fromCharCode(...value)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
3568
|
+
}
|
|
3569
|
+
function equalBytes(left, right) {
|
|
3570
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
3571
|
+
}
|
|
3572
|
+
function hex(bytes2) {
|
|
3573
|
+
return [...bytes2].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
3574
|
+
}
|
|
3575
|
+
function base32Lower(bytes2) {
|
|
3576
|
+
const alphabet2 = "abcdefghijklmnopqrstuvwxyz234567";
|
|
3577
|
+
let output = "";
|
|
3578
|
+
let buffer = 0;
|
|
3579
|
+
let bits = 0;
|
|
3580
|
+
for (const byte of bytes2) {
|
|
3581
|
+
buffer = buffer << 8 | byte;
|
|
3582
|
+
bits += 8;
|
|
3583
|
+
while (bits >= 5) {
|
|
3584
|
+
output += alphabet2[buffer >>> bits - 5 & 31];
|
|
3585
|
+
bits -= 5;
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
if (bits > 0) output += alphabet2[buffer << 5 - bits & 31];
|
|
3589
|
+
return output;
|
|
2989
3590
|
}
|
|
2990
3591
|
|
|
2991
3592
|
// src/requester/index.ts
|
|
@@ -3064,109 +3665,109 @@ var TranscriptRequesterError = class extends Error {
|
|
|
3064
3665
|
this.status = status;
|
|
3065
3666
|
}
|
|
3066
3667
|
};
|
|
3067
|
-
var JsonValueSchema =
|
|
3068
|
-
() =>
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3668
|
+
var JsonValueSchema = z3.lazy(
|
|
3669
|
+
() => z3.union([
|
|
3670
|
+
z3.string(),
|
|
3671
|
+
z3.number().finite(),
|
|
3672
|
+
z3.boolean(),
|
|
3673
|
+
z3.null(),
|
|
3674
|
+
z3.array(JsonValueSchema),
|
|
3675
|
+
z3.record(JsonValueSchema)
|
|
3075
3676
|
])
|
|
3076
3677
|
);
|
|
3077
|
-
var Rfc3339Schema =
|
|
3678
|
+
var Rfc3339Schema = z3.string().refine((value) => parseStrictRfc33392(value) !== void 0, {
|
|
3078
3679
|
message: "must be strict RFC 3339 date-time with timezone"
|
|
3079
3680
|
});
|
|
3080
|
-
var SignedRecordSchema =
|
|
3081
|
-
schema:
|
|
3082
|
-
engineRecordId:
|
|
3083
|
-
ownerDid:
|
|
3084
|
-
endpoint:
|
|
3085
|
-
audience:
|
|
3086
|
-
supportedPolicyVersions:
|
|
3087
|
-
supportedEvidenceVerifiers:
|
|
3088
|
-
grantIssuerDid:
|
|
3681
|
+
var SignedRecordSchema = z3.object({
|
|
3682
|
+
schema: z3.string(),
|
|
3683
|
+
engineRecordId: z3.string(),
|
|
3684
|
+
ownerDid: z3.string(),
|
|
3685
|
+
endpoint: z3.string(),
|
|
3686
|
+
audience: z3.string(),
|
|
3687
|
+
supportedPolicyVersions: z3.array(z3.string()),
|
|
3688
|
+
supportedEvidenceVerifiers: z3.array(z3.string()),
|
|
3689
|
+
grantIssuerDid: z3.string(),
|
|
3089
3690
|
expiresAt: Rfc3339Schema,
|
|
3090
|
-
signature:
|
|
3091
|
-
suite:
|
|
3092
|
-
signerDid:
|
|
3093
|
-
value:
|
|
3691
|
+
signature: z3.object({
|
|
3692
|
+
suite: z3.string(),
|
|
3693
|
+
signerDid: z3.string(),
|
|
3694
|
+
value: z3.string()
|
|
3094
3695
|
}).strict()
|
|
3095
3696
|
}).strict();
|
|
3096
|
-
var PolicyEngineSchema =
|
|
3097
|
-
endpoint:
|
|
3098
|
-
audience:
|
|
3099
|
-
supportedEvidenceVerifiers:
|
|
3100
|
-
|
|
3697
|
+
var PolicyEngineSchema = z3.object({
|
|
3698
|
+
endpoint: z3.string().url(),
|
|
3699
|
+
audience: z3.string(),
|
|
3700
|
+
supportedEvidenceVerifiers: z3.tuple([
|
|
3701
|
+
z3.literal(W3C_VC_CREDENTIAL_VERIFIER)
|
|
3101
3702
|
]),
|
|
3102
3703
|
signedRecord: SignedRecordSchema
|
|
3103
3704
|
}).strict();
|
|
3104
|
-
var OwnerNodeSchema =
|
|
3105
|
-
schema:
|
|
3106
|
-
endpoint:
|
|
3107
|
-
spaceId:
|
|
3705
|
+
var OwnerNodeSchema = z3.object({
|
|
3706
|
+
schema: z3.literal(OWNER_NODE_ENDPOINT_SCHEMA),
|
|
3707
|
+
endpoint: z3.string().url(),
|
|
3708
|
+
spaceId: z3.string().min(1)
|
|
3108
3709
|
}).strict();
|
|
3109
|
-
var ResourceHintSchema =
|
|
3110
|
-
resourceType:
|
|
3111
|
-
resourceId:
|
|
3112
|
-
requestedCapabilities:
|
|
3710
|
+
var ResourceHintSchema = z3.object({
|
|
3711
|
+
resourceType: z3.string(),
|
|
3712
|
+
resourceId: z3.string(),
|
|
3713
|
+
requestedCapabilities: z3.array(JsonValueSchema).min(1)
|
|
3113
3714
|
}).strict();
|
|
3114
|
-
var BootstrapSchema =
|
|
3115
|
-
schema:
|
|
3116
|
-
policyId:
|
|
3715
|
+
var BootstrapSchema = z3.object({
|
|
3716
|
+
schema: z3.literal(TRANSCRIPT_SHARE_BOOTSTRAP_SCHEMA),
|
|
3717
|
+
policyId: z3.string(),
|
|
3117
3718
|
policyEngine: PolicyEngineSchema,
|
|
3118
3719
|
ownerNode: OwnerNodeSchema,
|
|
3119
3720
|
resourceHint: ResourceHintSchema
|
|
3120
3721
|
}).strict();
|
|
3121
|
-
var SignatureSchema =
|
|
3122
|
-
suite:
|
|
3123
|
-
signerDid:
|
|
3124
|
-
value:
|
|
3722
|
+
var SignatureSchema = z3.object({
|
|
3723
|
+
suite: z3.string(),
|
|
3724
|
+
signerDid: z3.string(),
|
|
3725
|
+
value: z3.string()
|
|
3125
3726
|
}).strict();
|
|
3126
|
-
var ChallengeSchema =
|
|
3127
|
-
schema:
|
|
3128
|
-
challengeId:
|
|
3129
|
-
policyId:
|
|
3130
|
-
audience:
|
|
3131
|
-
nonce:
|
|
3727
|
+
var ChallengeSchema = z3.object({
|
|
3728
|
+
schema: z3.literal(POLICY_ENGINE_CHALLENGE_RESPONSE_SCHEMA),
|
|
3729
|
+
challengeId: z3.string(),
|
|
3730
|
+
policyId: z3.string(),
|
|
3731
|
+
audience: z3.string(),
|
|
3732
|
+
nonce: z3.string().min(16),
|
|
3132
3733
|
challengeExpiresAt: Rfc3339Schema,
|
|
3133
|
-
acceptedSuites:
|
|
3134
|
-
requestedCapabilitiesTemplate:
|
|
3734
|
+
acceptedSuites: z3.array(z3.string()).min(1),
|
|
3735
|
+
requestedCapabilitiesTemplate: z3.array(JsonValueSchema).optional(),
|
|
3135
3736
|
signature: SignatureSchema
|
|
3136
3737
|
}).strict();
|
|
3137
|
-
var ChallengeResponseSchema =
|
|
3138
|
-
var DenialSchema =
|
|
3139
|
-
schema:
|
|
3140
|
-
code:
|
|
3141
|
-
message:
|
|
3738
|
+
var ChallengeResponseSchema = z3.object({ challenge: ChallengeSchema }).strict();
|
|
3739
|
+
var DenialSchema = z3.object({
|
|
3740
|
+
schema: z3.literal(POLICY_ENGINE_DENIAL_SCHEMA),
|
|
3741
|
+
code: z3.enum(POLICY_ENGINE_GRANT_PRESENTATION_DENIAL_CODES),
|
|
3742
|
+
message: z3.string().optional()
|
|
3142
3743
|
}).strict();
|
|
3143
|
-
var ErrorEnvelopeDenialSchema =
|
|
3144
|
-
error:
|
|
3145
|
-
code:
|
|
3146
|
-
message:
|
|
3744
|
+
var ErrorEnvelopeDenialSchema = z3.object({
|
|
3745
|
+
error: z3.object({
|
|
3746
|
+
code: z3.enum(POLICY_ENGINE_GRANT_PRESENTATION_DENIAL_CODES),
|
|
3747
|
+
message: z3.string().optional()
|
|
3147
3748
|
}).strict()
|
|
3148
3749
|
}).strict();
|
|
3149
|
-
var WireDelegationSchema =
|
|
3150
|
-
delegationId:
|
|
3151
|
-
issuanceId:
|
|
3152
|
-
issuerDid:
|
|
3153
|
-
holderDid:
|
|
3154
|
-
policyId:
|
|
3155
|
-
capabilityHashHex:
|
|
3156
|
-
revocationMode:
|
|
3750
|
+
var WireDelegationSchema = z3.object({
|
|
3751
|
+
delegationId: z3.string(),
|
|
3752
|
+
issuanceId: z3.string().min(1),
|
|
3753
|
+
issuerDid: z3.string(),
|
|
3754
|
+
holderDid: z3.string(),
|
|
3755
|
+
policyId: z3.string(),
|
|
3756
|
+
capabilityHashHex: z3.string().regex(/^[0-9a-f]{64}$/),
|
|
3757
|
+
revocationMode: z3.literal("refresh_only"),
|
|
3157
3758
|
issuedAt: Rfc3339Schema,
|
|
3158
3759
|
expiresAt: Rfc3339Schema,
|
|
3159
|
-
terminal:
|
|
3160
|
-
encoded:
|
|
3760
|
+
terminal: z3.boolean(),
|
|
3761
|
+
encoded: z3.string()
|
|
3161
3762
|
}).strict();
|
|
3162
|
-
var ResolveResponseSchema =
|
|
3163
|
-
var DelegateReceiptSchema =
|
|
3164
|
-
cid:
|
|
3165
|
-
activated:
|
|
3166
|
-
skipped:
|
|
3763
|
+
var ResolveResponseSchema = z3.object({ delegation: WireDelegationSchema }).strict();
|
|
3764
|
+
var DelegateReceiptSchema = z3.object({
|
|
3765
|
+
cid: z3.string().min(1),
|
|
3766
|
+
activated: z3.array(z3.string()),
|
|
3767
|
+
skipped: z3.array(z3.string())
|
|
3167
3768
|
}).strict();
|
|
3168
|
-
var SqlReadResponseSchema =
|
|
3169
|
-
var KvReadResponseSchema =
|
|
3769
|
+
var SqlReadResponseSchema = z3.object({ rows: z3.array(JsonValueSchema) }).strict();
|
|
3770
|
+
var KvReadResponseSchema = z3.object({ value: JsonValueSchema }).strict();
|
|
3170
3771
|
var LISTEN_SQL_STATEMENT_CATALOG = [
|
|
3171
3772
|
{
|
|
3172
3773
|
name: "listen.getConversation",
|
|
@@ -3901,7 +4502,7 @@ function requestedCapabilitiesHash(capabilities) {
|
|
|
3901
4502
|
const bytes2 = new Uint8Array(domain.length + body.length);
|
|
3902
4503
|
bytes2.set(domain, 0);
|
|
3903
4504
|
bytes2.set(body, domain.length);
|
|
3904
|
-
return bytesToHex3(
|
|
4505
|
+
return bytesToHex3(sha2565(bytes2, "bytes")).slice(2);
|
|
3905
4506
|
}
|
|
3906
4507
|
function normalizeWireDelegation(delegation) {
|
|
3907
4508
|
const signed = delegationAuthorityFromCompactJws(delegation.encoded);
|
|
@@ -4156,7 +4757,7 @@ function nodeErrorMessage(body) {
|
|
|
4156
4757
|
return "native node refusal";
|
|
4157
4758
|
}
|
|
4158
4759
|
function deriveDelegationCid(encoded) {
|
|
4159
|
-
const digest4 = create(30,
|
|
4760
|
+
const digest4 = create(30, blake32(new TextEncoder().encode(encoded)));
|
|
4160
4761
|
return CID.createV1(85, digest4).toString();
|
|
4161
4762
|
}
|
|
4162
4763
|
function headersRecord(headers) {
|
|
@@ -4303,55 +4904,55 @@ function parseStrictRfc33392(value) {
|
|
|
4303
4904
|
}
|
|
4304
4905
|
|
|
4305
4906
|
// src/delegations/types.schema.ts
|
|
4306
|
-
import { z as
|
|
4307
|
-
var JWKSchema =
|
|
4907
|
+
import { z as z4 } from "zod";
|
|
4908
|
+
var JWKSchema = z4.object({
|
|
4308
4909
|
/** Key type (e.g., "EC", "RSA", "OKP") */
|
|
4309
|
-
kty:
|
|
4910
|
+
kty: z4.string(),
|
|
4310
4911
|
/** Curve for EC/OKP keys (e.g., "P-256", "Ed25519") */
|
|
4311
|
-
crv:
|
|
4912
|
+
crv: z4.string().optional(),
|
|
4312
4913
|
/** X coordinate for EC keys, public key for OKP */
|
|
4313
|
-
x:
|
|
4914
|
+
x: z4.string().optional(),
|
|
4314
4915
|
/** Y coordinate for EC keys */
|
|
4315
|
-
y:
|
|
4916
|
+
y: z4.string().optional(),
|
|
4316
4917
|
/** Private key value (d parameter) */
|
|
4317
|
-
d:
|
|
4918
|
+
d: z4.string().optional(),
|
|
4318
4919
|
/** Public exponent for RSA keys */
|
|
4319
|
-
e:
|
|
4920
|
+
e: z4.string().optional(),
|
|
4320
4921
|
/** Modulus for RSA keys */
|
|
4321
|
-
n:
|
|
4922
|
+
n: z4.string().optional(),
|
|
4322
4923
|
/** Key ID */
|
|
4323
|
-
kid:
|
|
4924
|
+
kid: z4.string().optional(),
|
|
4324
4925
|
/** Algorithm */
|
|
4325
|
-
alg:
|
|
4926
|
+
alg: z4.string().optional(),
|
|
4326
4927
|
/** Key use (e.g., "sig", "enc") */
|
|
4327
|
-
use:
|
|
4928
|
+
use: z4.string().optional(),
|
|
4328
4929
|
/** Key operations (e.g., ["sign", "verify"]) */
|
|
4329
|
-
key_ops:
|
|
4930
|
+
key_ops: z4.array(z4.string()).optional()
|
|
4330
4931
|
});
|
|
4331
|
-
var KeyTypeSchema =
|
|
4332
|
-
var KeyInfoSchema =
|
|
4932
|
+
var KeyTypeSchema = z4.enum(["main", "session", "ingested"]);
|
|
4933
|
+
var KeyInfoSchema = z4.object({
|
|
4333
4934
|
/** Unique identifier for this key */
|
|
4334
|
-
id:
|
|
4935
|
+
id: z4.string(),
|
|
4335
4936
|
/** DID associated with this key */
|
|
4336
|
-
did:
|
|
4937
|
+
did: z4.string(),
|
|
4337
4938
|
/** Type of key determining its authority level */
|
|
4338
4939
|
type: KeyTypeSchema,
|
|
4339
4940
|
/** Private key in JWK format */
|
|
4340
4941
|
jwk: JWKSchema.optional(),
|
|
4341
4942
|
/** Priority for key selection (lower = higher priority) */
|
|
4342
|
-
priority:
|
|
4943
|
+
priority: z4.number()
|
|
4343
4944
|
});
|
|
4344
|
-
var DelegationErrorSchema =
|
|
4945
|
+
var DelegationErrorSchema = z4.object({
|
|
4345
4946
|
/** Error code for programmatic handling */
|
|
4346
|
-
code:
|
|
4947
|
+
code: z4.string(),
|
|
4347
4948
|
/** Human-readable error message */
|
|
4348
|
-
message:
|
|
4949
|
+
message: z4.string(),
|
|
4349
4950
|
/** The service that produced the error */
|
|
4350
|
-
service:
|
|
4951
|
+
service: z4.literal("delegation"),
|
|
4351
4952
|
/** Original error if wrapping another error */
|
|
4352
|
-
cause:
|
|
4953
|
+
cause: z4.instanceof(Error).optional(),
|
|
4353
4954
|
/** Additional metadata about the error */
|
|
4354
|
-
meta:
|
|
4955
|
+
meta: z4.record(z4.string(), z4.unknown()).optional()
|
|
4355
4956
|
});
|
|
4356
4957
|
var DelegationErrorCodes = {
|
|
4357
4958
|
AUTH_REQUIRED: "AUTH_REQUIRED",
|
|
@@ -4371,313 +4972,313 @@ var DelegationErrorCodes = {
|
|
|
4371
4972
|
DATA_FETCH_FAILED: "DATA_FETCH_FAILED",
|
|
4372
4973
|
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
4373
4974
|
};
|
|
4374
|
-
var DelegationSchema =
|
|
4975
|
+
var DelegationSchema = z4.object({
|
|
4375
4976
|
/** Content identifier (CID) of the delegation */
|
|
4376
|
-
cid:
|
|
4977
|
+
cid: z4.string(),
|
|
4377
4978
|
/** DID of the delegate (the party receiving the delegation) */
|
|
4378
|
-
delegateDID:
|
|
4979
|
+
delegateDID: z4.string(),
|
|
4379
4980
|
/** Space ID this delegation applies to */
|
|
4380
|
-
spaceId:
|
|
4981
|
+
spaceId: z4.string(),
|
|
4381
4982
|
/** Resource path this delegation grants access to */
|
|
4382
|
-
path:
|
|
4983
|
+
path: z4.string(),
|
|
4383
4984
|
/** Actions this delegation authorizes */
|
|
4384
|
-
actions:
|
|
4985
|
+
actions: z4.array(z4.string()),
|
|
4385
4986
|
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
4386
|
-
caveats:
|
|
4987
|
+
caveats: z4.array(z4.record(z4.string(), z4.unknown())).optional(),
|
|
4387
4988
|
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
4388
|
-
expiry:
|
|
4989
|
+
expiry: z4.coerce.date(),
|
|
4389
4990
|
/** Whether this delegation has been revoked */
|
|
4390
|
-
isRevoked:
|
|
4991
|
+
isRevoked: z4.boolean(),
|
|
4391
4992
|
/** DID of the delegator (the party granting the delegation) */
|
|
4392
|
-
delegatorDID:
|
|
4993
|
+
delegatorDID: z4.string().optional(),
|
|
4393
4994
|
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
4394
|
-
createdAt:
|
|
4995
|
+
createdAt: z4.coerce.date().optional(),
|
|
4395
4996
|
/** Parent delegation CID if this is a sub-delegation */
|
|
4396
|
-
parentCid:
|
|
4997
|
+
parentCid: z4.string().optional(),
|
|
4397
4998
|
/** Whether sub-delegation is allowed */
|
|
4398
|
-
allowSubDelegation:
|
|
4999
|
+
allowSubDelegation: z4.boolean().optional(),
|
|
4399
5000
|
/** Authorization header (UCAN bearer token) */
|
|
4400
|
-
authHeader:
|
|
5001
|
+
authHeader: z4.string().optional()
|
|
4401
5002
|
});
|
|
4402
|
-
var DelegationStatusSchema =
|
|
4403
|
-
cid:
|
|
4404
|
-
status:
|
|
4405
|
-
exists:
|
|
4406
|
-
active:
|
|
4407
|
-
revoked:
|
|
4408
|
-
expired:
|
|
5003
|
+
var DelegationStatusSchema = z4.object({
|
|
5004
|
+
cid: z4.string().min(1),
|
|
5005
|
+
status: z4.enum(["active", "revoked", "expired", "unavailable", "not_found"]),
|
|
5006
|
+
exists: z4.boolean(),
|
|
5007
|
+
active: z4.boolean(),
|
|
5008
|
+
revoked: z4.boolean(),
|
|
5009
|
+
expired: z4.boolean()
|
|
4409
5010
|
}).strict().superRefine((value, context) => {
|
|
4410
5011
|
const valid = value.status === "active" ? value.exists && value.active && !value.revoked && !value.expired : value.status === "revoked" ? value.exists && !value.active && value.revoked && !value.expired : value.status === "expired" ? value.exists && !value.active && !value.revoked && value.expired : value.status === "unavailable" ? value.exists && !value.active && !value.revoked && !value.expired : !value.exists && !value.active && !value.revoked && !value.expired;
|
|
4411
5012
|
if (!valid) {
|
|
4412
5013
|
context.addIssue({
|
|
4413
|
-
code:
|
|
5014
|
+
code: z4.ZodIssueCode.custom,
|
|
4414
5015
|
message: "delegation status flags do not match status"
|
|
4415
5016
|
});
|
|
4416
5017
|
}
|
|
4417
5018
|
});
|
|
4418
|
-
var DelegationRevocationReceiptSchema =
|
|
4419
|
-
revoked:
|
|
4420
|
-
cid:
|
|
5019
|
+
var DelegationRevocationReceiptSchema = z4.object({
|
|
5020
|
+
revoked: z4.literal(true),
|
|
5021
|
+
cid: z4.string().min(1)
|
|
4421
5022
|
}).strict();
|
|
4422
|
-
var AccountDelegationResourceSchema =
|
|
4423
|
-
resource:
|
|
4424
|
-
actions:
|
|
4425
|
-
caveats:
|
|
5023
|
+
var AccountDelegationResourceSchema = z4.object({
|
|
5024
|
+
resource: z4.string().min(1),
|
|
5025
|
+
actions: z4.array(z4.string()),
|
|
5026
|
+
caveats: z4.array(z4.record(z4.string(), z4.unknown()))
|
|
4426
5027
|
}).strict();
|
|
4427
|
-
var AccountDelegationDateSchema =
|
|
4428
|
-
var AccountDelegationRecordSchema =
|
|
4429
|
-
cid:
|
|
4430
|
-
direction:
|
|
4431
|
-
delegatorDid:
|
|
4432
|
-
delegateDid:
|
|
4433
|
-
resources:
|
|
4434
|
-
parents:
|
|
5028
|
+
var AccountDelegationDateSchema = z4.string().datetime({ offset: true }).transform((value) => new Date(value));
|
|
5029
|
+
var AccountDelegationRecordSchema = z4.object({
|
|
5030
|
+
cid: z4.string().min(1),
|
|
5031
|
+
direction: z4.enum(["granted", "received"]),
|
|
5032
|
+
delegatorDid: z4.string().min(1),
|
|
5033
|
+
delegateDid: z4.string().min(1),
|
|
5034
|
+
resources: z4.array(AccountDelegationResourceSchema),
|
|
5035
|
+
parents: z4.array(z4.string()),
|
|
4435
5036
|
issuedAt: AccountDelegationDateSchema.nullable(),
|
|
4436
5037
|
notBefore: AccountDelegationDateSchema.nullable(),
|
|
4437
5038
|
expiresAt: AccountDelegationDateSchema.nullable(),
|
|
4438
|
-
status:
|
|
5039
|
+
status: z4.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]),
|
|
4439
5040
|
revokedAt: AccountDelegationDateSchema.nullable().optional(),
|
|
4440
|
-
revokedBy:
|
|
4441
|
-
revokedAncestorCid:
|
|
5041
|
+
revokedBy: z4.string().optional(),
|
|
5042
|
+
revokedAncestorCid: z4.string().optional()
|
|
4442
5043
|
}).strict();
|
|
4443
|
-
var AccountDelegationPageSchema =
|
|
4444
|
-
schemaVersion:
|
|
4445
|
-
items:
|
|
4446
|
-
nextCursor:
|
|
5044
|
+
var AccountDelegationPageSchema = z4.object({
|
|
5045
|
+
schemaVersion: z4.literal(2),
|
|
5046
|
+
items: z4.array(AccountDelegationRecordSchema),
|
|
5047
|
+
nextCursor: z4.string().optional()
|
|
4447
5048
|
}).strict();
|
|
4448
|
-
var AccountDelegationQueryOptionsSchema =
|
|
4449
|
-
direction:
|
|
4450
|
-
status:
|
|
4451
|
-
space:
|
|
4452
|
-
limit:
|
|
4453
|
-
cursor:
|
|
5049
|
+
var AccountDelegationQueryOptionsSchema = z4.object({
|
|
5050
|
+
direction: z4.enum(["granted", "received", "all"]).optional(),
|
|
5051
|
+
status: z4.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]).optional(),
|
|
5052
|
+
space: z4.string().trim().min(1).optional(),
|
|
5053
|
+
limit: z4.number().int().min(1).max(100).optional(),
|
|
5054
|
+
cursor: z4.string().min(1).optional()
|
|
4454
5055
|
}).strict();
|
|
4455
|
-
var CapabilityEntrySchema =
|
|
5056
|
+
var CapabilityEntrySchema = z4.object({
|
|
4456
5057
|
/** Resource URI this capability applies to */
|
|
4457
|
-
resource:
|
|
5058
|
+
resource: z4.string(),
|
|
4458
5059
|
/** Action this capability authorizes */
|
|
4459
|
-
action:
|
|
5060
|
+
action: z4.string(),
|
|
4460
5061
|
/** Keys that can exercise this capability, ordered by priority */
|
|
4461
|
-
keys:
|
|
5062
|
+
keys: z4.array(KeyInfoSchema),
|
|
4462
5063
|
/** The delegation that grants this capability */
|
|
4463
5064
|
delegation: DelegationSchema,
|
|
4464
5065
|
/** When this capability expires (accepts Date or ISO string from JSON) */
|
|
4465
|
-
expiresAt:
|
|
5066
|
+
expiresAt: z4.coerce.date().optional()
|
|
4466
5067
|
});
|
|
4467
|
-
var DelegationRecordSchema =
|
|
5068
|
+
var DelegationRecordSchema = z4.object({
|
|
4468
5069
|
/** Content identifier (CID) of the delegation */
|
|
4469
|
-
cid:
|
|
5070
|
+
cid: z4.string(),
|
|
4470
5071
|
/** Space ID this delegation applies to */
|
|
4471
|
-
spaceId:
|
|
5072
|
+
spaceId: z4.string(),
|
|
4472
5073
|
/** DID of the delegator (grantor) */
|
|
4473
|
-
delegator:
|
|
5074
|
+
delegator: z4.string(),
|
|
4474
5075
|
/** DID of the delegatee (recipient) */
|
|
4475
|
-
delegatee:
|
|
5076
|
+
delegatee: z4.string(),
|
|
4476
5077
|
/** Key ID used to sign/exercise this delegation */
|
|
4477
|
-
keyId:
|
|
5078
|
+
keyId: z4.string().optional(),
|
|
4478
5079
|
/** Resource path pattern this delegation grants access to */
|
|
4479
|
-
path:
|
|
5080
|
+
path: z4.string(),
|
|
4480
5081
|
/** Actions this delegation authorizes */
|
|
4481
|
-
actions:
|
|
5082
|
+
actions: z4.array(z4.string()),
|
|
4482
5083
|
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
4483
|
-
expiry:
|
|
5084
|
+
expiry: z4.coerce.date().optional(),
|
|
4484
5085
|
/** When this delegation becomes valid (not before) (accepts Date or ISO string) */
|
|
4485
|
-
notBefore:
|
|
5086
|
+
notBefore: z4.coerce.date().optional(),
|
|
4486
5087
|
/** Whether this delegation has been revoked */
|
|
4487
|
-
isRevoked:
|
|
5088
|
+
isRevoked: z4.boolean(),
|
|
4488
5089
|
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
4489
|
-
createdAt:
|
|
5090
|
+
createdAt: z4.coerce.date(),
|
|
4490
5091
|
/** Parent delegation CID if this is a sub-delegation */
|
|
4491
|
-
parentCid:
|
|
5092
|
+
parentCid: z4.string().optional()
|
|
4492
5093
|
});
|
|
4493
|
-
var CreateDelegationParamsSchema =
|
|
5094
|
+
var CreateDelegationParamsSchema = z4.object({
|
|
4494
5095
|
/** DID of the delegate (the party receiving the delegation) */
|
|
4495
|
-
delegateDID:
|
|
5096
|
+
delegateDID: z4.string(),
|
|
4496
5097
|
/** Resource path this delegation grants access to */
|
|
4497
|
-
path:
|
|
5098
|
+
path: z4.string(),
|
|
4498
5099
|
/** Actions to authorize */
|
|
4499
|
-
actions:
|
|
5100
|
+
actions: z4.array(z4.string()),
|
|
4500
5101
|
/** When this delegation expires (accepts Date or ISO string) */
|
|
4501
|
-
expiry:
|
|
5102
|
+
expiry: z4.coerce.date().optional(),
|
|
4502
5103
|
/** Whether to disable sub-delegation */
|
|
4503
|
-
disableSubDelegation:
|
|
5104
|
+
disableSubDelegation: z4.boolean().optional(),
|
|
4504
5105
|
/** Optional statement for the SIWE message */
|
|
4505
|
-
statement:
|
|
5106
|
+
statement: z4.string().optional()
|
|
4506
5107
|
});
|
|
4507
|
-
var DelegationChainSchema =
|
|
4508
|
-
var DelegationChainV2Schema =
|
|
5108
|
+
var DelegationChainSchema = z4.array(DelegationSchema);
|
|
5109
|
+
var DelegationChainV2Schema = z4.object({
|
|
4509
5110
|
/** The root delegation from the original authority */
|
|
4510
5111
|
root: DelegationSchema,
|
|
4511
5112
|
/** Intermediate delegations in the chain (may be empty) */
|
|
4512
|
-
chain:
|
|
5113
|
+
chain: z4.array(DelegationSchema),
|
|
4513
5114
|
/** The final delegation to the current user */
|
|
4514
5115
|
leaf: DelegationSchema
|
|
4515
5116
|
});
|
|
4516
|
-
var DelegationDirectionSchema =
|
|
4517
|
-
var DelegationFiltersSchema =
|
|
5117
|
+
var DelegationDirectionSchema = z4.enum(["granted", "received", "all"]);
|
|
5118
|
+
var DelegationFiltersSchema = z4.object({
|
|
4518
5119
|
/** Filter by delegation direction */
|
|
4519
5120
|
direction: DelegationDirectionSchema.optional(),
|
|
4520
5121
|
/** Filter by resource path pattern */
|
|
4521
|
-
path:
|
|
5122
|
+
path: z4.string().optional(),
|
|
4522
5123
|
/** Filter by required actions */
|
|
4523
|
-
actions:
|
|
5124
|
+
actions: z4.array(z4.string()).optional(),
|
|
4524
5125
|
/** Include revoked delegations */
|
|
4525
|
-
includeRevoked:
|
|
5126
|
+
includeRevoked: z4.boolean().optional(),
|
|
4526
5127
|
/** Filter by delegator DID */
|
|
4527
|
-
delegator:
|
|
5128
|
+
delegator: z4.string().optional(),
|
|
4528
5129
|
/** Filter by delegatee DID */
|
|
4529
|
-
delegatee:
|
|
5130
|
+
delegatee: z4.string().optional(),
|
|
4530
5131
|
/** Only include delegations valid at this time */
|
|
4531
|
-
validAt:
|
|
5132
|
+
validAt: z4.coerce.date().optional(),
|
|
4532
5133
|
/** Maximum number of results to return */
|
|
4533
|
-
limit:
|
|
5134
|
+
limit: z4.number().optional(),
|
|
4534
5135
|
/** Cursor for pagination */
|
|
4535
|
-
cursor:
|
|
5136
|
+
cursor: z4.string().optional()
|
|
4536
5137
|
});
|
|
4537
|
-
var SpaceOwnershipSchema =
|
|
4538
|
-
var SpaceInfoSchema =
|
|
5138
|
+
var SpaceOwnershipSchema = z4.enum(["owned", "delegated"]);
|
|
5139
|
+
var SpaceInfoSchema = z4.object({
|
|
4539
5140
|
/** Space identifier */
|
|
4540
|
-
id:
|
|
5141
|
+
id: z4.string(),
|
|
4541
5142
|
/** Human-readable name for the space */
|
|
4542
|
-
name:
|
|
5143
|
+
name: z4.string().optional(),
|
|
4543
5144
|
/** DID of the space owner */
|
|
4544
|
-
owner:
|
|
5145
|
+
owner: z4.string(),
|
|
4545
5146
|
/** Whether user owns or has delegated access */
|
|
4546
5147
|
type: SpaceOwnershipSchema,
|
|
4547
5148
|
/** Permissions the user has in this space */
|
|
4548
|
-
permissions:
|
|
5149
|
+
permissions: z4.array(z4.string()).optional(),
|
|
4549
5150
|
/** When the access expires (for delegated spaces) */
|
|
4550
|
-
expiresAt:
|
|
5151
|
+
expiresAt: z4.coerce.date().optional()
|
|
4551
5152
|
});
|
|
4552
|
-
var ShareSchemaSchema =
|
|
4553
|
-
var ShareLinkSchema =
|
|
5153
|
+
var ShareSchemaSchema = z4.enum(["base64", "compact", "ipfs"]);
|
|
5154
|
+
var ShareLinkSchema = z4.object({
|
|
4554
5155
|
/** Unique token identifying this share link */
|
|
4555
|
-
token:
|
|
5156
|
+
token: z4.string(),
|
|
4556
5157
|
/** Full URL for sharing */
|
|
4557
|
-
url:
|
|
5158
|
+
url: z4.string(),
|
|
4558
5159
|
/** The delegation this link grants access to */
|
|
4559
5160
|
delegation: DelegationSchema,
|
|
4560
5161
|
/** Encoding schema used for the link */
|
|
4561
5162
|
schema: ShareSchemaSchema,
|
|
4562
5163
|
/** When this share link expires */
|
|
4563
|
-
expiresAt:
|
|
5164
|
+
expiresAt: z4.coerce.date().optional(),
|
|
4564
5165
|
/** Human-readable description of what is being shared */
|
|
4565
|
-
description:
|
|
5166
|
+
description: z4.string().optional()
|
|
4566
5167
|
});
|
|
4567
5168
|
function createShareLinkDataSchema(dataSchema) {
|
|
4568
|
-
return
|
|
5169
|
+
return z4.object({
|
|
4569
5170
|
/** The retrieved data */
|
|
4570
5171
|
data: dataSchema,
|
|
4571
5172
|
/** The delegation that authorized this access */
|
|
4572
5173
|
delegation: DelegationSchema,
|
|
4573
5174
|
/** The space the data belongs to */
|
|
4574
|
-
spaceId:
|
|
5175
|
+
spaceId: z4.string(),
|
|
4575
5176
|
/** The resource path that was accessed */
|
|
4576
|
-
path:
|
|
5177
|
+
path: z4.string()
|
|
4577
5178
|
});
|
|
4578
5179
|
}
|
|
4579
|
-
var ShareLinkDataSchema = createShareLinkDataSchema(
|
|
4580
|
-
var IngestOptionsSchema =
|
|
5180
|
+
var ShareLinkDataSchema = createShareLinkDataSchema(z4.unknown());
|
|
5181
|
+
var IngestOptionsSchema = z4.object({
|
|
4581
5182
|
/** Whether to persist the delegation to storage */
|
|
4582
|
-
persist:
|
|
5183
|
+
persist: z4.boolean().optional(),
|
|
4583
5184
|
/** Whether to validate the full delegation chain */
|
|
4584
|
-
validateChain:
|
|
5185
|
+
validateChain: z4.boolean().optional(),
|
|
4585
5186
|
/** Name for the ingested key */
|
|
4586
|
-
keyName:
|
|
5187
|
+
keyName: z4.string().optional(),
|
|
4587
5188
|
/** Whether to create a session key for this delegation */
|
|
4588
|
-
createSessionKey:
|
|
5189
|
+
createSessionKey: z4.boolean().optional(),
|
|
4589
5190
|
/** Override the priority for the ingested key */
|
|
4590
|
-
priority:
|
|
5191
|
+
priority: z4.number().optional()
|
|
4591
5192
|
});
|
|
4592
|
-
var GenerateShareParamsSchema =
|
|
5193
|
+
var GenerateShareParamsSchema = z4.object({
|
|
4593
5194
|
/** Resource path to share */
|
|
4594
|
-
path:
|
|
5195
|
+
path: z4.string(),
|
|
4595
5196
|
/** Actions to authorize */
|
|
4596
|
-
actions:
|
|
5197
|
+
actions: z4.array(z4.string()).optional(),
|
|
4597
5198
|
/** When the share link expires */
|
|
4598
|
-
expiry:
|
|
5199
|
+
expiry: z4.coerce.date().optional(),
|
|
4599
5200
|
/** Encoding schema for the link */
|
|
4600
5201
|
schema: ShareSchemaSchema.optional(),
|
|
4601
5202
|
/** Human-readable description */
|
|
4602
|
-
description:
|
|
5203
|
+
description: z4.string().optional(),
|
|
4603
5204
|
/** Base URL for the share link */
|
|
4604
|
-
baseUrl:
|
|
5205
|
+
baseUrl: z4.string().optional()
|
|
4605
5206
|
});
|
|
4606
|
-
var DelegationManagerConfigSchema =
|
|
5207
|
+
var DelegationManagerConfigSchema = z4.object({
|
|
4607
5208
|
/** TinyCloud host URLs */
|
|
4608
|
-
hosts:
|
|
5209
|
+
hosts: z4.array(z4.string()),
|
|
4609
5210
|
/** Account space used by account-wide delegation history queries */
|
|
4610
|
-
accountSpaceId:
|
|
5211
|
+
accountSpaceId: z4.string().min(1).optional(),
|
|
4611
5212
|
/** Active session for authentication */
|
|
4612
|
-
session:
|
|
5213
|
+
session: z4.unknown().refine(
|
|
4613
5214
|
(val) => val !== null && typeof val === "object",
|
|
4614
5215
|
{ message: "Expected a ServiceSession object" }
|
|
4615
5216
|
),
|
|
4616
5217
|
/** Platform-specific invoke function */
|
|
4617
|
-
invoke:
|
|
5218
|
+
invoke: z4.unknown().refine(
|
|
4618
5219
|
(val) => typeof val === "function",
|
|
4619
5220
|
{ message: "Expected an invoke function" }
|
|
4620
5221
|
),
|
|
4621
5222
|
/** Platform-specific invoke function for raw resource URIs */
|
|
4622
|
-
invokeAny:
|
|
5223
|
+
invokeAny: z4.unknown().refine(
|
|
4623
5224
|
(val) => val === void 0 || typeof val === "function",
|
|
4624
5225
|
{ message: "Expected an invokeAny function or undefined" }
|
|
4625
5226
|
).optional(),
|
|
4626
5227
|
/** Optional custom fetch implementation */
|
|
4627
|
-
fetch:
|
|
5228
|
+
fetch: z4.unknown().refine(
|
|
4628
5229
|
(val) => val === void 0 || typeof val === "function",
|
|
4629
5230
|
{ message: "Expected a fetch function or undefined" }
|
|
4630
5231
|
).optional()
|
|
4631
5232
|
});
|
|
4632
|
-
var KeyProviderSchema =
|
|
5233
|
+
var KeyProviderSchema = z4.object({
|
|
4633
5234
|
/** Generate a new session key, returns key ID */
|
|
4634
|
-
createSessionKey:
|
|
5235
|
+
createSessionKey: z4.unknown().refine(
|
|
4635
5236
|
(val) => typeof val === "function",
|
|
4636
5237
|
{ message: "Expected a function" }
|
|
4637
5238
|
),
|
|
4638
5239
|
/** Get JWK for a key */
|
|
4639
|
-
getJWK:
|
|
5240
|
+
getJWK: z4.unknown().refine(
|
|
4640
5241
|
(val) => typeof val === "function",
|
|
4641
5242
|
{ message: "Expected a function" }
|
|
4642
5243
|
),
|
|
4643
5244
|
/** Get DID for a key */
|
|
4644
|
-
getDID:
|
|
5245
|
+
getDID: z4.unknown().refine(
|
|
4645
5246
|
(val) => typeof val === "function",
|
|
4646
5247
|
{ message: "Expected a function" }
|
|
4647
5248
|
)
|
|
4648
5249
|
});
|
|
4649
|
-
var DelegationApiResponseSchema =
|
|
5250
|
+
var DelegationApiResponseSchema = z4.object({
|
|
4650
5251
|
/** SIWE message content */
|
|
4651
|
-
siwe:
|
|
5252
|
+
siwe: z4.string(),
|
|
4652
5253
|
/** Signature of the SIWE message */
|
|
4653
|
-
signature:
|
|
5254
|
+
signature: z4.string(),
|
|
4654
5255
|
/** Delegation version */
|
|
4655
|
-
version:
|
|
5256
|
+
version: z4.number(),
|
|
4656
5257
|
/** CID of the created delegation */
|
|
4657
|
-
cid:
|
|
5258
|
+
cid: z4.string().optional()
|
|
4658
5259
|
});
|
|
4659
|
-
var DelegatedResourceSchema =
|
|
5260
|
+
var DelegatedResourceSchema = z4.object({
|
|
4660
5261
|
/** Short-form service name, e.g. "kv", "sql", "duckdb", "capabilities", "hooks". */
|
|
4661
|
-
service:
|
|
5262
|
+
service: z4.string(),
|
|
4662
5263
|
/** Full space id string, e.g. "tinycloud:pkh:eip155:1:0x....:default". */
|
|
4663
|
-
space:
|
|
5264
|
+
space: z4.string(),
|
|
4664
5265
|
/** Resource path; empty string when the resource URI had no path segment. */
|
|
4665
|
-
path:
|
|
5266
|
+
path: z4.string(),
|
|
4666
5267
|
/** Full-URN ability strings, e.g. ["tinycloud.kv/get", "tinycloud.kv/put"]. */
|
|
4667
|
-
actions:
|
|
5268
|
+
actions: z4.array(z4.string()),
|
|
4668
5269
|
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
4669
|
-
caveats:
|
|
5270
|
+
caveats: z4.array(z4.record(z4.string(), z4.unknown())).optional()
|
|
4670
5271
|
});
|
|
4671
|
-
var CreateDelegationWasmParamsSchema =
|
|
5272
|
+
var CreateDelegationWasmParamsSchema = z4.object({
|
|
4672
5273
|
/** The session containing delegation credentials */
|
|
4673
|
-
session:
|
|
5274
|
+
session: z4.unknown().refine(
|
|
4674
5275
|
(val) => val !== null && typeof val === "object",
|
|
4675
5276
|
{ message: "Expected a ServiceSession object" }
|
|
4676
5277
|
),
|
|
4677
5278
|
/** DID of the delegate */
|
|
4678
|
-
delegateDID:
|
|
5279
|
+
delegateDID: z4.string(),
|
|
4679
5280
|
/** Space ID this delegation applies to */
|
|
4680
|
-
spaceId:
|
|
5281
|
+
spaceId: z4.string(),
|
|
4681
5282
|
/**
|
|
4682
5283
|
* Multi-resource abilities map: short-service → path → full-URN actions.
|
|
4683
5284
|
* Matches the shape accepted by `prepareSession`.
|
|
@@ -4694,26 +5295,26 @@ var CreateDelegationWasmParamsSchema = z3.object({
|
|
|
4694
5295
|
* }
|
|
4695
5296
|
* ```
|
|
4696
5297
|
*/
|
|
4697
|
-
abilities:
|
|
5298
|
+
abilities: z4.record(z4.string(), z4.record(z4.string(), z4.array(z4.string()))),
|
|
4698
5299
|
/** Expiration time in seconds since Unix epoch */
|
|
4699
|
-
expirationSecs:
|
|
5300
|
+
expirationSecs: z4.number(),
|
|
4700
5301
|
/** Optional not-before time in seconds since Unix epoch */
|
|
4701
|
-
notBeforeSecs:
|
|
5302
|
+
notBeforeSecs: z4.number().optional()
|
|
4702
5303
|
});
|
|
4703
|
-
var CreateDelegationWasmResultSchema =
|
|
5304
|
+
var CreateDelegationWasmResultSchema = z4.object({
|
|
4704
5305
|
/** Base64url-encoded UCAN delegation */
|
|
4705
|
-
delegation:
|
|
5306
|
+
delegation: z4.string(),
|
|
4706
5307
|
/** CID of the delegation */
|
|
4707
|
-
cid:
|
|
5308
|
+
cid: z4.string(),
|
|
4708
5309
|
/** DID of the delegate */
|
|
4709
|
-
delegateDID:
|
|
5310
|
+
delegateDID: z4.string(),
|
|
4710
5311
|
/** Expiration time */
|
|
4711
|
-
expiry:
|
|
5312
|
+
expiry: z4.coerce.date(),
|
|
4712
5313
|
/**
|
|
4713
5314
|
* All (service, space, path, actions) entries granted by this delegation.
|
|
4714
5315
|
* Always non-empty on success.
|
|
4715
5316
|
*/
|
|
4716
|
-
resources:
|
|
5317
|
+
resources: z4.array(DelegatedResourceSchema)
|
|
4717
5318
|
});
|
|
4718
5319
|
|
|
4719
5320
|
// src/expiry.ts
|
|
@@ -5408,66 +6009,66 @@ var DelegationManager = class {
|
|
|
5408
6009
|
};
|
|
5409
6010
|
|
|
5410
6011
|
// src/delegations/SharingService.schema.ts
|
|
5411
|
-
import { z as
|
|
5412
|
-
var EncodedShareDataSchema =
|
|
6012
|
+
import { z as z5 } from "zod";
|
|
6013
|
+
var EncodedShareDataSchema = z5.object({
|
|
5413
6014
|
/** Private key in JWK format (must include d parameter) */
|
|
5414
6015
|
key: JWKSchema.refine(
|
|
5415
6016
|
(jwk) => typeof jwk.d === "string" && jwk.d.length > 0,
|
|
5416
6017
|
{ message: "JWK must include private key (d parameter)" }
|
|
5417
6018
|
),
|
|
5418
6019
|
/** DID of the key */
|
|
5419
|
-
keyDid:
|
|
6020
|
+
keyDid: z5.string().min(1, "keyDid is required"),
|
|
5420
6021
|
/** The delegation granting access */
|
|
5421
6022
|
delegation: DelegationSchema,
|
|
5422
6023
|
/** Resource path this link grants access to */
|
|
5423
|
-
path:
|
|
6024
|
+
path: z5.string().min(1, "path is required"),
|
|
5424
6025
|
/** TinyCloud host URL */
|
|
5425
|
-
host:
|
|
6026
|
+
host: z5.string().url("host must be a valid URL"),
|
|
5426
6027
|
/** Space ID */
|
|
5427
|
-
spaceId:
|
|
6028
|
+
spaceId: z5.string().min(1, "spaceId is required"),
|
|
5428
6029
|
/** Schema version (must be 1) */
|
|
5429
|
-
version:
|
|
6030
|
+
version: z5.literal(1)
|
|
5430
6031
|
});
|
|
5431
|
-
var ReceiveOptionsSchema =
|
|
6032
|
+
var ReceiveOptionsSchema = z5.object({
|
|
5432
6033
|
/**
|
|
5433
6034
|
* Whether to automatically create a sub-delegation to the current session key.
|
|
5434
6035
|
* Default: true
|
|
5435
6036
|
*/
|
|
5436
|
-
autoSubdelegate:
|
|
6037
|
+
autoSubdelegate: z5.boolean().optional(),
|
|
5437
6038
|
/**
|
|
5438
6039
|
* Whether to use the current session key for operations (requires autoSubdelegate).
|
|
5439
6040
|
* Default: true
|
|
5440
6041
|
*/
|
|
5441
|
-
useSessionKey:
|
|
6042
|
+
useSessionKey: z5.boolean().optional(),
|
|
5442
6043
|
/**
|
|
5443
6044
|
* Ingestion options passed to CapabilityKeyRegistry.
|
|
5444
6045
|
*/
|
|
5445
6046
|
ingestOptions: IngestOptionsSchema.optional()
|
|
5446
6047
|
});
|
|
5447
|
-
var SharingServiceConfigSchema =
|
|
6048
|
+
var SharingServiceConfigSchema = z5.object({
|
|
5448
6049
|
/** TinyCloud host URLs */
|
|
5449
|
-
hosts:
|
|
6050
|
+
hosts: z5.array(z5.string().url()).min(1, "At least one host URL is required"),
|
|
5450
6051
|
/**
|
|
5451
6052
|
* Active session for authentication.
|
|
5452
6053
|
* Required for generate(), optional for receive().
|
|
5453
6054
|
*/
|
|
5454
|
-
session:
|
|
6055
|
+
session: z5.unknown().refine(
|
|
5455
6056
|
(val) => val === void 0 || val !== null && typeof val === "object",
|
|
5456
6057
|
{ message: "Expected a ServiceSession object or undefined" }
|
|
5457
6058
|
).optional(),
|
|
5458
6059
|
/** Platform-specific invoke function */
|
|
5459
|
-
invoke:
|
|
6060
|
+
invoke: z5.unknown().refine((val) => typeof val === "function", {
|
|
5460
6061
|
message: "Expected an invoke function"
|
|
5461
6062
|
}),
|
|
5462
6063
|
/** Optional custom fetch implementation */
|
|
5463
|
-
fetch:
|
|
6064
|
+
fetch: z5.unknown().refine(
|
|
5464
6065
|
(val) => val === void 0 || typeof val === "function",
|
|
5465
6066
|
{ message: "Expected a fetch function or undefined" }
|
|
5466
6067
|
).optional(),
|
|
5467
6068
|
/** Key provider for cryptographic operations */
|
|
5468
6069
|
keyProvider: KeyProviderSchema,
|
|
5469
6070
|
/** Capability key registry for key/delegation management */
|
|
5470
|
-
registry:
|
|
6071
|
+
registry: z5.unknown().refine(
|
|
5471
6072
|
(val) => val !== null && typeof val === "object",
|
|
5472
6073
|
{ message: "Expected an ICapabilityKeyRegistry object" }
|
|
5473
6074
|
),
|
|
@@ -5475,47 +6076,47 @@ var SharingServiceConfigSchema = z4.object({
|
|
|
5475
6076
|
* Delegation manager for creating delegations.
|
|
5476
6077
|
* Required for generate(), optional for receive().
|
|
5477
6078
|
*/
|
|
5478
|
-
delegationManager:
|
|
6079
|
+
delegationManager: z5.unknown().refine(
|
|
5479
6080
|
(val) => val === void 0 || val !== null && typeof val === "object",
|
|
5480
6081
|
{ message: "Expected a DelegationManager object or undefined" }
|
|
5481
6082
|
).optional(),
|
|
5482
6083
|
/** Factory for creating KV service instances */
|
|
5483
|
-
createKVService:
|
|
6084
|
+
createKVService: z5.unknown().refine(
|
|
5484
6085
|
(val) => typeof val === "function",
|
|
5485
6086
|
{ message: "Expected a createKVService factory function" }
|
|
5486
6087
|
),
|
|
5487
6088
|
/** Base URL for sharing links (e.g., "https://share.myapp.com") */
|
|
5488
|
-
baseUrl:
|
|
6089
|
+
baseUrl: z5.string().optional(),
|
|
5489
6090
|
/**
|
|
5490
6091
|
* Custom delegation creation function.
|
|
5491
6092
|
*/
|
|
5492
|
-
createDelegation:
|
|
6093
|
+
createDelegation: z5.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5493
6094
|
message: "Expected a createDelegation function or undefined"
|
|
5494
6095
|
}).optional(),
|
|
5495
6096
|
/**
|
|
5496
6097
|
* WASM function for client-side delegation creation.
|
|
5497
6098
|
*/
|
|
5498
|
-
createDelegationWasm:
|
|
6099
|
+
createDelegationWasm: z5.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5499
6100
|
message: "Expected a createDelegationWasm function or undefined"
|
|
5500
6101
|
}).optional(),
|
|
5501
6102
|
/** CID computation used to verify transportable child delegations. */
|
|
5502
|
-
computeCid:
|
|
6103
|
+
computeCid: z5.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5503
6104
|
message: "Expected a computeCid function or undefined"
|
|
5504
6105
|
}).optional(),
|
|
5505
6106
|
/**
|
|
5506
6107
|
* Path prefix for KV operations.
|
|
5507
6108
|
*/
|
|
5508
|
-
pathPrefix:
|
|
6109
|
+
pathPrefix: z5.string().optional(),
|
|
5509
6110
|
/**
|
|
5510
6111
|
* Session expiry time.
|
|
5511
6112
|
*/
|
|
5512
|
-
sessionExpiry:
|
|
6113
|
+
sessionExpiry: z5.date().optional(),
|
|
5513
6114
|
/**
|
|
5514
6115
|
* Callback to create a DIRECT delegation from wallet to share key.
|
|
5515
6116
|
* This is the preferred method for long-lived share links because it
|
|
5516
6117
|
* bypasses the session delegation chain entirely.
|
|
5517
6118
|
*/
|
|
5518
|
-
onRootDelegationNeeded:
|
|
6119
|
+
onRootDelegationNeeded: z5.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5519
6120
|
message: "Expected an onRootDelegationNeeded function or undefined"
|
|
5520
6121
|
}).optional()
|
|
5521
6122
|
});
|
|
@@ -5537,6 +6138,7 @@ function validateEncodedShareData(data) {
|
|
|
5537
6138
|
|
|
5538
6139
|
// src/manifest.ts
|
|
5539
6140
|
import ms from "ms";
|
|
6141
|
+
import { ACCOUNT_MANIFEST_PERMISSIONS } from "@tinycloud/bootstrap";
|
|
5540
6142
|
import { resolveSecretPath, SECRET_NAME_RE } from "@tinycloud/sdk-services";
|
|
5541
6143
|
var DEFAULT_KNOWLEDGE_ROOT = "knowledge/index.md";
|
|
5542
6144
|
var ManifestValidationError = class extends Error {
|
|
@@ -6195,30 +6797,6 @@ function withCapabilitiesReadForSpaces(resources) {
|
|
|
6195
6797
|
...[...spaces].map(capabilitiesReadPermission)
|
|
6196
6798
|
]);
|
|
6197
6799
|
}
|
|
6198
|
-
function accountRegistryPermissions() {
|
|
6199
|
-
return [
|
|
6200
|
-
...[ACCOUNT_REGISTRY_PATH, "spaces/"].map((path) => ({
|
|
6201
|
-
service: "tinycloud.kv",
|
|
6202
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
6203
|
-
path,
|
|
6204
|
-
actions: ["tinycloud.kv/get", "tinycloud.kv/put", "tinycloud.kv/list"]
|
|
6205
|
-
})),
|
|
6206
|
-
{
|
|
6207
|
-
service: "tinycloud.delegation",
|
|
6208
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
6209
|
-
path: "",
|
|
6210
|
-
actions: ["tinycloud.delegation/list"]
|
|
6211
|
-
}
|
|
6212
|
-
];
|
|
6213
|
-
}
|
|
6214
|
-
function accountRegistryIndexPermission() {
|
|
6215
|
-
return {
|
|
6216
|
-
service: "tinycloud.sql",
|
|
6217
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
6218
|
-
path: "account",
|
|
6219
|
-
actions: ["tinycloud.sql/read", "tinycloud.sql/write", "tinycloud.sql/schema"]
|
|
6220
|
-
};
|
|
6221
|
-
}
|
|
6222
6800
|
function composeManifestRequest(inputs, options2 = {}) {
|
|
6223
6801
|
if (!Array.isArray(inputs) || inputs.length === 0) {
|
|
6224
6802
|
throw new ManifestValidationError(
|
|
@@ -6236,8 +6814,12 @@ function composeManifestRequest(inputs, options2 = {}) {
|
|
|
6236
6814
|
}))
|
|
6237
6815
|
);
|
|
6238
6816
|
if (includeAccountRegistryPermissions) {
|
|
6239
|
-
resources.push(
|
|
6240
|
-
|
|
6817
|
+
resources.push(
|
|
6818
|
+
...ACCOUNT_MANIFEST_PERMISSIONS.map((resource) => ({
|
|
6819
|
+
...resource,
|
|
6820
|
+
actions: [...resource.actions]
|
|
6821
|
+
}))
|
|
6822
|
+
);
|
|
6241
6823
|
}
|
|
6242
6824
|
const resourcesWithImplicitCapabilities = withCapabilitiesReadForSpaces(resources);
|
|
6243
6825
|
const manifestsByAppId = /* @__PURE__ */ new Map();
|
|
@@ -6412,13 +6994,13 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
6412
6994
|
}
|
|
6413
6995
|
if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
|
|
6414
6996
|
if (typeof value === "object") {
|
|
6415
|
-
const
|
|
6416
|
-
const prototype = Object.getPrototypeOf(
|
|
6997
|
+
const object2 = value;
|
|
6998
|
+
const prototype = Object.getPrototypeOf(object2);
|
|
6417
6999
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
6418
7000
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
6419
7001
|
}
|
|
6420
|
-
return `{${Object.keys(
|
|
6421
|
-
(key) => `${JSON.stringify(key)}:${canonicalize(
|
|
7002
|
+
return `{${Object.keys(object2).sort().map(
|
|
7003
|
+
(key) => `${JSON.stringify(key)}:${canonicalize(object2[key])}`
|
|
6422
7004
|
).join(",")}}`;
|
|
6423
7005
|
}
|
|
6424
7006
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
@@ -6490,7 +7072,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
6490
7072
|
}
|
|
6491
7073
|
|
|
6492
7074
|
// src/delegations/SharingService.ts
|
|
6493
|
-
import { ed25519 as
|
|
7075
|
+
import { ed25519 as ed255195 } from "@noble/curves/ed25519";
|
|
6494
7076
|
|
|
6495
7077
|
// src/delegations/ShareRecipientClient.ts
|
|
6496
7078
|
import {
|
|
@@ -6498,13 +7080,13 @@ import {
|
|
|
6498
7080
|
KVService,
|
|
6499
7081
|
ServiceContext
|
|
6500
7082
|
} from "@tinycloud/sdk-services";
|
|
6501
|
-
import { ed25519 as
|
|
6502
|
-
import { sha256 as
|
|
7083
|
+
import { ed25519 as ed255194 } from "@noble/curves/ed25519";
|
|
7084
|
+
import { sha256 as sha2568 } from "@noble/hashes/sha256";
|
|
6503
7085
|
|
|
6504
7086
|
// src/delegations/share-envelope.ts
|
|
6505
|
-
import { ed25519 as
|
|
6506
|
-
import { blake3 as
|
|
6507
|
-
import { sha256 as
|
|
7087
|
+
import { ed25519 as ed255193 } from "@noble/curves/ed25519";
|
|
7088
|
+
import { blake3 as blake33 } from "@noble/hashes/blake3";
|
|
7089
|
+
import { sha256 as sha2566 } from "@noble/hashes/sha256";
|
|
6508
7090
|
var ENVELOPE_SCHEMA = "xyz.tinycloud.share/envelope";
|
|
6509
7091
|
var INLINE_PREFIX = "tc2:";
|
|
6510
7092
|
var RAW_CID_CODEC = 85;
|
|
@@ -6553,8 +7135,8 @@ function canonicalJson(value) {
|
|
|
6553
7135
|
}
|
|
6554
7136
|
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
6555
7137
|
if (typeof value === "object") {
|
|
6556
|
-
const
|
|
6557
|
-
return `{${Object.keys(
|
|
7138
|
+
const object2 = value;
|
|
7139
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(object2[key])}`).join(",")}}`;
|
|
6558
7140
|
}
|
|
6559
7141
|
throw new ShareEnvelopeError("invalid-envelope", "unsupported JSON value");
|
|
6560
7142
|
}
|
|
@@ -6723,17 +7305,17 @@ function createSharePolicy(input) {
|
|
|
6723
7305
|
};
|
|
6724
7306
|
}
|
|
6725
7307
|
function contentDigest(bytes2) {
|
|
6726
|
-
return bytesToBase64Url(
|
|
7308
|
+
return bytesToBase64Url(sha2566(bytes2));
|
|
6727
7309
|
}
|
|
6728
7310
|
function computeShareCid(bytes2) {
|
|
6729
|
-
const digest4 = create(BLAKE3_256_CODE,
|
|
7311
|
+
const digest4 = create(BLAKE3_256_CODE, blake33(bytes2));
|
|
6730
7312
|
return CID.createV1(RAW_CID_CODEC, digest4).toString();
|
|
6731
7313
|
}
|
|
6732
7314
|
function verifyShareCid(cid2, bytes2) {
|
|
6733
7315
|
try {
|
|
6734
7316
|
const parsed = CID.parse(cid2);
|
|
6735
7317
|
if (parsed.toString() !== cid2 || parsed.multihash.code !== BLAKE3_256_CODE) return false;
|
|
6736
|
-
return parsed.equals(CID.createV1(parsed.code, create(parsed.multihash.code,
|
|
7318
|
+
return parsed.equals(CID.createV1(parsed.code, create(parsed.multihash.code, blake33(bytes2))));
|
|
6737
7319
|
} catch {
|
|
6738
7320
|
return false;
|
|
6739
7321
|
}
|
|
@@ -6743,7 +7325,7 @@ function envelopeSigningBytes(envelope) {
|
|
|
6743
7325
|
}
|
|
6744
7326
|
function signShareEnvelope(input) {
|
|
6745
7327
|
if (input.signerPrivateKey.length !== 32) throw new ShareEnvelopeError("invalid-envelope", "Ed25519 private key must be 32 bytes");
|
|
6746
|
-
const publicKey =
|
|
7328
|
+
const publicKey = ed255193.getPublicKey(input.signerPrivateKey);
|
|
6747
7329
|
const unsigned = {
|
|
6748
7330
|
schema: ENVELOPE_SCHEMA,
|
|
6749
7331
|
version: 2,
|
|
@@ -6758,7 +7340,7 @@ function signShareEnvelope(input) {
|
|
|
6758
7340
|
expiresAt: new Date(input.expiresAt).toISOString(),
|
|
6759
7341
|
signer: { did: input.signerDid, publicKey: bytesToBase64Url(publicKey) }
|
|
6760
7342
|
};
|
|
6761
|
-
return { ...unsigned, signature: bytesToBase64Url(
|
|
7343
|
+
return { ...unsigned, signature: bytesToBase64Url(ed255193.sign(envelopeSigningBytes(unsigned), input.signerPrivateKey)) };
|
|
6762
7344
|
}
|
|
6763
7345
|
function verifyShareEnvelope(envelope, options2 = {}) {
|
|
6764
7346
|
try {
|
|
@@ -6790,7 +7372,7 @@ function verifyShareEnvelope(envelope, options2 = {}) {
|
|
|
6790
7372
|
const signature = base64UrlToBytes(envelope.signature);
|
|
6791
7373
|
const unsigned = { ...envelope };
|
|
6792
7374
|
delete unsigned.signature;
|
|
6793
|
-
if (publicKey.length !== 32 || signature.length !== 64 || !
|
|
7375
|
+
if (publicKey.length !== 32 || signature.length !== 64 || !ed255193.verify(signature, envelopeSigningBytes(unsigned), publicKey)) throw new ShareEnvelopeError("signature-invalid", "share envelope signature is invalid");
|
|
6794
7376
|
if (options2.trustedSignerDids !== void 0 && envelope.recipientKind !== void 0 && !options2.trustedSignerDids.includes(envelope.signer.did)) throw new ShareEnvelopeError("signature-invalid", "share signer is not trusted");
|
|
6795
7377
|
return envelope;
|
|
6796
7378
|
} catch (error) {
|
|
@@ -6838,7 +7420,7 @@ function encodeInlineShareUrl(input) {
|
|
|
6838
7420
|
}
|
|
6839
7421
|
var PUBLISHED_AAD = new TextEncoder().encode("tinycloud-share-envelope-v1");
|
|
6840
7422
|
function publishedCid(bytes2) {
|
|
6841
|
-
return CID.create(1, code, create(sha2562.code,
|
|
7423
|
+
return CID.create(1, code, create(sha2562.code, sha2566(bytes2))).toString();
|
|
6842
7424
|
}
|
|
6843
7425
|
function isPublishedCid(value) {
|
|
6844
7426
|
try {
|
|
@@ -6878,7 +7460,7 @@ function publishedArtifact(envelope, plaintext, policy) {
|
|
|
6878
7460
|
content: {
|
|
6879
7461
|
mimeType: "application/octet-stream",
|
|
6880
7462
|
size: plaintext.byteLength,
|
|
6881
|
-
digest: bytesToBase64Url(
|
|
7463
|
+
digest: bytesToBase64Url(sha2566(plaintext))
|
|
6882
7464
|
},
|
|
6883
7465
|
// Addressed policy metadata is confidential even though this function
|
|
6884
7466
|
// is called after the outer envelope has been opened. Keep the
|
|
@@ -6982,9 +7564,9 @@ function parsePolicyMetadata(policyBytes, target, expectedExpiry) {
|
|
|
6982
7564
|
assertKeys(source, ["kind", "space", "database", "path", "statement", "arguments", "argumentsDigest", "action"], "published SQL content source");
|
|
6983
7565
|
if (typeof source.space !== "string" || typeof source.database !== "string" || typeof source.path !== "string" || typeof source.statement !== "string" || !source.arguments || typeof source.arguments !== "object" || Array.isArray(source.arguments) || typeof source.argumentsDigest !== "string" || source.action !== "tinycloud.sql/read") throw new ShareEnvelopeError("invalid-envelope", "published SQL content source is invalid");
|
|
6984
7566
|
for (const argument of Object.values(source.arguments)) if (!Number.isSafeInteger(argument)) throw new ShareEnvelopeError("invalid-envelope", "published SQL arguments are invalid");
|
|
6985
|
-
if (bytesToBase64Url(
|
|
7567
|
+
if (bytesToBase64Url(sha2566(new TextEncoder().encode(canonicalJson(source.arguments)))) !== source.argumentsDigest) throw new ShareEnvelopeError("invalid-envelope", "published SQL argument digest is invalid");
|
|
6986
7568
|
} else throw new ShareEnvelopeError("invalid-envelope", "policy content source kind is invalid");
|
|
6987
|
-
if (typeof policy.contentSourceDigest !== "string" || bytesToBase64Url(
|
|
7569
|
+
if (typeof policy.contentSourceDigest !== "string" || bytesToBase64Url(sha2566(new TextEncoder().encode(canonicalJson(source)))) !== policy.contentSourceDigest) throw new ShareEnvelopeError("invalid-envelope", "policy content source digest is invalid");
|
|
6988
7570
|
return { recipientKind, actions, resource };
|
|
6989
7571
|
}
|
|
6990
7572
|
function parseCanonicalPublishedV2(value, options2) {
|
|
@@ -7032,7 +7614,7 @@ function parseCanonicalPublishedV2(value, options2) {
|
|
|
7032
7614
|
const signingBytes = new Uint8Array(domain.length + body.length);
|
|
7033
7615
|
signingBytes.set(domain);
|
|
7034
7616
|
signingBytes.set(body, domain.length);
|
|
7035
|
-
if (signatureBytes.length !== 64 || !
|
|
7617
|
+
if (signatureBytes.length !== 64 || !ed255193.verify(signatureBytes, signingBytes, signerKey)) throw new ShareEnvelopeError("signature-invalid", "published v2 envelope signature is invalid");
|
|
7036
7618
|
const content = options2.plaintext ?? new Uint8Array();
|
|
7037
7619
|
const normalized = {
|
|
7038
7620
|
schema: ENVELOPE_SCHEMA,
|
|
@@ -7042,7 +7624,7 @@ function parseCanonicalPublishedV2(value, options2) {
|
|
|
7042
7624
|
recipientKind: normalizedMatcher.kind,
|
|
7043
7625
|
resource,
|
|
7044
7626
|
actions,
|
|
7045
|
-
content: { mimeType: typeof contentSource.mimeType === "string" ? contentSource.mimeType : "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url(
|
|
7627
|
+
content: { mimeType: typeof contentSource.mimeType === "string" ? contentSource.mimeType : "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url(sha2566(content)) },
|
|
7046
7628
|
encrypted: true,
|
|
7047
7629
|
expiresAt: value.expiry,
|
|
7048
7630
|
signer: { did: signature.signerDid, publicKey: bytesToBase64Url(signerKey) },
|
|
@@ -7141,7 +7723,7 @@ function parsePublishedShareEnvelope(bytes2, options2 = {}) {
|
|
|
7141
7723
|
if (envelope.authorizationTarget.kind !== "bearerKey" && (options2.trustedSignerDids === void 0 || !options2.trustedSignerDids.includes(envelope.signature.signerDid))) throw new ShareEnvelopeError("signature-invalid", "a trusted authority is required for addressed shares");
|
|
7142
7724
|
const signature = base64UrlToBytes(envelope.signature.value);
|
|
7143
7725
|
const publicKey = publishedPublicKey(envelope.signature.signerDid);
|
|
7144
|
-
if (signature.length !== 64 || !
|
|
7726
|
+
if (signature.length !== 64 || !ed255193.verify(signature, publishedEnvelopeSigningBytes(envelope), publicKey)) throw new ShareEnvelopeError("signature-invalid", "published envelope signature is invalid");
|
|
7145
7727
|
return { envelope, artifact: publishedArtifact(envelope, options2.plaintext ?? new Uint8Array(), policy) };
|
|
7146
7728
|
}
|
|
7147
7729
|
function parseLegacyPublishedShareEnvelope(bytes2, options2 = {}) {
|
|
@@ -7180,7 +7762,7 @@ function parseLegacyPublishedShareEnvelope(bytes2, options2 = {}) {
|
|
|
7180
7762
|
const signingBytes = new Uint8Array(domain.length + body.length);
|
|
7181
7763
|
signingBytes.set(domain);
|
|
7182
7764
|
signingBytes.set(body, domain.length);
|
|
7183
|
-
if (signatureBytes.length !== 64 || !
|
|
7765
|
+
if (signatureBytes.length !== 64 || !ed255193.verify(signatureBytes, signingBytes, signerKey)) throw new ShareEnvelopeError("signature-invalid", "published v1 envelope signature is invalid");
|
|
7184
7766
|
const content = options2.plaintext ?? new Uint8Array();
|
|
7185
7767
|
const artifact = {
|
|
7186
7768
|
envelope: {
|
|
@@ -7191,7 +7773,7 @@ function parseLegacyPublishedShareEnvelope(bytes2, options2 = {}) {
|
|
|
7191
7773
|
resource: { kind: resource.kind, path: resource.path },
|
|
7192
7774
|
recipientKind: authorizationTarget.kind === "bearer" ? "bearer" : authorizationTarget.kind === "exact-email" ? "exactEmail" : authorizationTarget.kind === "email-domain" ? "emailDomain" : void 0,
|
|
7193
7775
|
actions: ["read"],
|
|
7194
|
-
content: { mimeType: "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url(
|
|
7776
|
+
content: { mimeType: "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url(sha2566(content)) },
|
|
7195
7777
|
encrypted: true,
|
|
7196
7778
|
expiresAt: envelope.expiry,
|
|
7197
7779
|
signer: { did: signature.signerDid, publicKey: bytesToBase64Url(signerKey) },
|
|
@@ -7378,15 +7960,15 @@ function shareCapabilityAllows(capability, action, path) {
|
|
|
7378
7960
|
}
|
|
7379
7961
|
|
|
7380
7962
|
// src/delegations/ShareCache.ts
|
|
7381
|
-
import { sha256 as
|
|
7963
|
+
import { sha256 as sha2567 } from "@noble/hashes/sha256";
|
|
7382
7964
|
function cacheKey(key) {
|
|
7383
7965
|
if (!key.cid || !key.expiresAt) throw new Error("share cache keys require CID and expiry");
|
|
7384
7966
|
return `${key.cid}\0${key.expiresAt}`;
|
|
7385
7967
|
}
|
|
7386
7968
|
function digest2(bytes2) {
|
|
7387
|
-
return
|
|
7969
|
+
return sha2567(bytes2);
|
|
7388
7970
|
}
|
|
7389
|
-
function
|
|
7971
|
+
function equalBytes2(left, right) {
|
|
7390
7972
|
if (left.byteLength !== right.byteLength) return false;
|
|
7391
7973
|
return left.every((byte, index) => byte === right[index]);
|
|
7392
7974
|
}
|
|
@@ -7399,7 +7981,7 @@ var MemoryShareCache = class {
|
|
|
7399
7981
|
const mapKey = cacheKey(key);
|
|
7400
7982
|
const entry = this.entries.get(mapKey);
|
|
7401
7983
|
if (entry === void 0) return void 0;
|
|
7402
|
-
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !
|
|
7984
|
+
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !equalBytes2(entry.digest, digest2(entry.bytes))) {
|
|
7403
7985
|
this.entries.delete(mapKey);
|
|
7404
7986
|
return void 0;
|
|
7405
7987
|
}
|
|
@@ -7408,7 +7990,7 @@ var MemoryShareCache = class {
|
|
|
7408
7990
|
async getByCid(cid2, now = /* @__PURE__ */ new Date()) {
|
|
7409
7991
|
const entries = [...this.entries.values()].filter((entry) => entry.key.cid === cid2);
|
|
7410
7992
|
for (const entry of entries) {
|
|
7411
|
-
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !
|
|
7993
|
+
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !equalBytes2(entry.digest, digest2(entry.bytes))) {
|
|
7412
7994
|
this.entries.delete(cacheKey(entry.key));
|
|
7413
7995
|
continue;
|
|
7414
7996
|
}
|
|
@@ -7458,138 +8040,234 @@ var ShareAccessError = class extends Error {
|
|
|
7458
8040
|
};
|
|
7459
8041
|
|
|
7460
8042
|
// src/delegations/recipient-types.schema.ts
|
|
7461
|
-
import { z as
|
|
7462
|
-
var ShareRecipientTargetSchema =
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
8043
|
+
import { z as z6 } from "zod";
|
|
8044
|
+
var ShareRecipientTargetSchema = z6.discriminatedUnion("kind", [
|
|
8045
|
+
z6.object({ kind: z6.literal("exactEmail"), value: z6.string().min(1) }).strict(),
|
|
8046
|
+
z6.object({ kind: z6.literal("emailDomain"), value: z6.string().min(1) }).strict(),
|
|
8047
|
+
z6.object({ kind: z6.literal("recipientDid"), value: z6.string().regex(/^did:[a-z0-9]+:.+$/) }).strict(),
|
|
8048
|
+
z6.object({ kind: z6.literal("bearer") }).strict()
|
|
7467
8049
|
]);
|
|
7468
|
-
var ShareResourceSchema =
|
|
7469
|
-
|
|
7470
|
-
|
|
8050
|
+
var ShareResourceSchema = z6.discriminatedUnion("kind", [
|
|
8051
|
+
z6.object({ kind: z6.literal("exact"), path: z6.string().min(1) }).strict(),
|
|
8052
|
+
z6.object({ kind: z6.literal("prefix"), path: z6.string().min(1) }).strict()
|
|
7471
8053
|
]);
|
|
7472
|
-
var ShareActionSchema =
|
|
7473
|
-
var ShareRecipientPolicySchema =
|
|
8054
|
+
var ShareActionSchema = z6.enum(["read", "list", "edit"]);
|
|
8055
|
+
var ShareRecipientPolicySchema = z6.object({
|
|
7474
8056
|
recipientMatcher: ShareRecipientTargetSchema,
|
|
7475
|
-
spaceId:
|
|
8057
|
+
spaceId: z6.string().min(1),
|
|
7476
8058
|
resource: ShareResourceSchema,
|
|
7477
|
-
actions:
|
|
7478
|
-
expiresAt:
|
|
8059
|
+
actions: z6.array(ShareActionSchema).min(1),
|
|
8060
|
+
expiresAt: z6.date()
|
|
7479
8061
|
}).strict();
|
|
7480
|
-
var ShareRecipientClientOptionsSchema =
|
|
7481
|
-
trustedOrigins:
|
|
7482
|
-
maxInlineBytes:
|
|
7483
|
-
maxArtifactBytes:
|
|
7484
|
-
maxContentBytes:
|
|
7485
|
-
maxSealedContentBytes:
|
|
8062
|
+
var ShareRecipientClientOptionsSchema = z6.object({
|
|
8063
|
+
trustedOrigins: z6.array(z6.string().url()).min(1),
|
|
8064
|
+
maxInlineBytes: z6.number().int().positive().optional(),
|
|
8065
|
+
maxArtifactBytes: z6.number().int().positive().optional(),
|
|
8066
|
+
maxContentBytes: z6.number().int().positive().optional(),
|
|
8067
|
+
maxSealedContentBytes: z6.number().int().positive().optional()
|
|
7486
8068
|
}).strict();
|
|
7487
|
-
var ShareNativeActionSchema =
|
|
7488
|
-
var ShareWireActionSchema =
|
|
7489
|
-
var ShareContentSourceSchema =
|
|
7490
|
-
|
|
7491
|
-
kind:
|
|
8069
|
+
var ShareNativeActionSchema = z6.enum(["tinycloud.kv/get", "tinycloud.kv/metadata", "tinycloud.kv/list", "tinycloud.kv/put"]);
|
|
8070
|
+
var ShareWireActionSchema = z6.enum(["tinycloud.kv/get", "tinycloud.kv/metadata", "tinycloud.kv/list", "tinycloud.kv/put", "tinycloud.sql/read"]);
|
|
8071
|
+
var ShareContentSourceSchema = z6.discriminatedUnion("kind", [
|
|
8072
|
+
z6.object({
|
|
8073
|
+
kind: z6.literal("kv"),
|
|
7492
8074
|
action: ShareNativeActionSchema,
|
|
7493
|
-
space:
|
|
7494
|
-
path:
|
|
8075
|
+
space: z6.string().min(1),
|
|
8076
|
+
path: z6.string().min(1)
|
|
7495
8077
|
}).strict(),
|
|
7496
|
-
|
|
7497
|
-
kind:
|
|
7498
|
-
action:
|
|
7499
|
-
space:
|
|
7500
|
-
database:
|
|
7501
|
-
path:
|
|
7502
|
-
statement:
|
|
7503
|
-
arguments:
|
|
7504
|
-
argumentsDigest:
|
|
8078
|
+
z6.object({
|
|
8079
|
+
kind: z6.literal("sql"),
|
|
8080
|
+
action: z6.literal("tinycloud.sql/read"),
|
|
8081
|
+
space: z6.string().min(1),
|
|
8082
|
+
database: z6.string().min(1),
|
|
8083
|
+
path: z6.string().min(1),
|
|
8084
|
+
statement: z6.string().min(1),
|
|
8085
|
+
arguments: z6.record(z6.number().int().safe()),
|
|
8086
|
+
argumentsDigest: z6.string().min(1)
|
|
7505
8087
|
}).strict()
|
|
7506
8088
|
]);
|
|
7507
|
-
var ShareAddressedRecipientSchema =
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
8089
|
+
var ShareAddressedRecipientSchema = z6.discriminatedUnion("kind", [
|
|
8090
|
+
z6.object({ kind: z6.literal("exactEmail"), value: z6.string().min(1) }).strict(),
|
|
8091
|
+
z6.object({ kind: z6.literal("emailDomain"), value: z6.string().min(1) }).strict(),
|
|
8092
|
+
z6.object({ kind: z6.literal("recipientDid"), value: z6.string().regex(/^did:[a-z0-9]+:.+$/) }).strict()
|
|
7511
8093
|
]);
|
|
7512
|
-
var ShareAddressedDelegationRequestV2Schema =
|
|
7513
|
-
version:
|
|
7514
|
-
nonce:
|
|
7515
|
-
jti:
|
|
7516
|
-
senderDid:
|
|
8094
|
+
var ShareAddressedDelegationRequestV2Schema = z6.object({
|
|
8095
|
+
version: z6.literal(2),
|
|
8096
|
+
nonce: z6.string().min(1),
|
|
8097
|
+
jti: z6.string().min(1),
|
|
8098
|
+
senderDid: z6.string().min(1),
|
|
7517
8099
|
recipientMatcher: ShareAddressedRecipientSchema,
|
|
7518
|
-
targetOrigin:
|
|
7519
|
-
nodeAudience:
|
|
7520
|
-
shareCid:
|
|
7521
|
-
shareId:
|
|
7522
|
-
delegationCid:
|
|
7523
|
-
authorityMaterialHandle:
|
|
7524
|
-
authorityMaterialDigest:
|
|
8100
|
+
targetOrigin: z6.string().url(),
|
|
8101
|
+
nodeAudience: z6.string().min(1),
|
|
8102
|
+
shareCid: z6.string().min(1),
|
|
8103
|
+
shareId: z6.string().min(1),
|
|
8104
|
+
delegationCid: z6.string().min(1),
|
|
8105
|
+
authorityMaterialHandle: z6.string().min(1),
|
|
8106
|
+
authorityMaterialDigest: z6.string().min(1),
|
|
7525
8107
|
contentSource: ShareContentSourceSchema,
|
|
7526
|
-
contentSourceDigest:
|
|
7527
|
-
actions:
|
|
7528
|
-
resource:
|
|
7529
|
-
expiresAt:
|
|
7530
|
-
requestBodyDigest:
|
|
8108
|
+
contentSourceDigest: z6.string().min(1),
|
|
8109
|
+
actions: z6.array(ShareWireActionSchema).min(1).refine((actions) => new Set(actions).size === actions.length),
|
|
8110
|
+
resource: z6.object({ kind: z6.enum(["exact", "prefix"]), value: z6.string().min(1) }).strict(),
|
|
8111
|
+
expiresAt: z6.string().datetime({ offset: true }),
|
|
8112
|
+
requestBodyDigest: z6.string().min(1)
|
|
7531
8113
|
}).strict();
|
|
7532
|
-
var ShareAddressedDelegationEnvelopeV2Schema =
|
|
8114
|
+
var ShareAddressedDelegationEnvelopeV2Schema = z6.object({
|
|
7533
8115
|
request: ShareAddressedDelegationRequestV2Schema,
|
|
7534
|
-
proof:
|
|
8116
|
+
proof: z6.object({ alg: z6.literal("EdDSA"), kid: z6.string().min(1), signature: z6.string().min(1) }).strict()
|
|
7535
8117
|
}).strict();
|
|
7536
|
-
var ShareAddressedDelegationResponseV2Schema =
|
|
7537
|
-
type:
|
|
7538
|
-
version:
|
|
7539
|
-
nonce:
|
|
7540
|
-
jti:
|
|
7541
|
-
policyCid:
|
|
7542
|
-
policyBytes:
|
|
7543
|
-
policyDigest:
|
|
7544
|
-
delegationCid:
|
|
7545
|
-
delegationBytes:
|
|
7546
|
-
delegationDigest:
|
|
7547
|
-
authorityMaterialHandle:
|
|
7548
|
-
authorityMaterialDigest:
|
|
7549
|
-
actions:
|
|
7550
|
-
resource:
|
|
7551
|
-
expiresAt:
|
|
7552
|
-
proof:
|
|
8118
|
+
var ShareAddressedDelegationResponseV2Schema = z6.object({
|
|
8119
|
+
type: z6.literal("TinyCloudShareAddressedDelegation"),
|
|
8120
|
+
version: z6.literal(2),
|
|
8121
|
+
nonce: z6.string().min(1),
|
|
8122
|
+
jti: z6.string().min(1),
|
|
8123
|
+
policyCid: z6.string().min(1),
|
|
8124
|
+
policyBytes: z6.string().min(1),
|
|
8125
|
+
policyDigest: z6.string().min(1),
|
|
8126
|
+
delegationCid: z6.string().min(1),
|
|
8127
|
+
delegationBytes: z6.string().min(1),
|
|
8128
|
+
delegationDigest: z6.string().min(1),
|
|
8129
|
+
authorityMaterialHandle: z6.string().min(1),
|
|
8130
|
+
authorityMaterialDigest: z6.string().min(1),
|
|
8131
|
+
actions: z6.array(ShareWireActionSchema).min(1).refine((actions) => new Set(actions).size === actions.length),
|
|
8132
|
+
resource: z6.object({ kind: z6.enum(["exact", "prefix"]), value: z6.string().min(1) }).strict(),
|
|
8133
|
+
expiresAt: z6.string().datetime({ offset: true }),
|
|
8134
|
+
proof: z6.object({ alg: z6.literal("EdDSA"), kid: z6.string().min(1), signature: z6.string().min(1) }).strict()
|
|
7553
8135
|
}).strict();
|
|
7554
|
-
var ShareNativeResponseEntrySchema =
|
|
7555
|
-
path:
|
|
7556
|
-
kind:
|
|
8136
|
+
var ShareNativeResponseEntrySchema = z6.object({
|
|
8137
|
+
path: z6.string().min(1),
|
|
8138
|
+
kind: z6.enum(["file", "folder"])
|
|
7557
8139
|
}).strict();
|
|
7558
8140
|
var ShareNativeResponseBase = {
|
|
7559
|
-
type:
|
|
7560
|
-
version:
|
|
7561
|
-
resource:
|
|
8141
|
+
type: z6.literal("TinyCloudShareInvokeResponse"),
|
|
8142
|
+
version: z6.literal(2),
|
|
8143
|
+
resource: z6.string().min(1)
|
|
7562
8144
|
};
|
|
7563
|
-
var ShareNativeResponseSchema =
|
|
7564
|
-
|
|
8145
|
+
var ShareNativeResponseSchema = z6.discriminatedUnion("action", [
|
|
8146
|
+
z6.object({
|
|
7565
8147
|
...ShareNativeResponseBase,
|
|
7566
|
-
action:
|
|
7567
|
-
metadata:
|
|
7568
|
-
etag:
|
|
8148
|
+
action: z6.literal("tinycloud.kv/metadata"),
|
|
8149
|
+
metadata: z6.record(z6.string()),
|
|
8150
|
+
etag: z6.string().min(1).nullable()
|
|
7569
8151
|
}).strict(),
|
|
7570
|
-
|
|
8152
|
+
z6.object({
|
|
7571
8153
|
...ShareNativeResponseBase,
|
|
7572
|
-
action:
|
|
7573
|
-
mediaType:
|
|
7574
|
-
content:
|
|
7575
|
-
bodyDigest:
|
|
7576
|
-
etag:
|
|
8154
|
+
action: z6.literal("tinycloud.kv/get"),
|
|
8155
|
+
mediaType: z6.string().min(1),
|
|
8156
|
+
content: z6.string(),
|
|
8157
|
+
bodyDigest: z6.string().min(1),
|
|
8158
|
+
etag: z6.string().min(1).nullable()
|
|
7577
8159
|
}).strict(),
|
|
7578
|
-
|
|
8160
|
+
z6.object({
|
|
7579
8161
|
...ShareNativeResponseBase,
|
|
7580
|
-
action:
|
|
7581
|
-
entries:
|
|
7582
|
-
nextCursor:
|
|
8162
|
+
action: z6.literal("tinycloud.kv/list"),
|
|
8163
|
+
entries: z6.array(ShareNativeResponseEntrySchema),
|
|
8164
|
+
nextCursor: z6.string().min(1).nullable()
|
|
7583
8165
|
}).strict(),
|
|
7584
|
-
|
|
8166
|
+
z6.object({
|
|
7585
8167
|
...ShareNativeResponseBase,
|
|
7586
|
-
action:
|
|
7587
|
-
etag:
|
|
7588
|
-
bodyDigest:
|
|
7589
|
-
contentType:
|
|
8168
|
+
action: z6.literal("tinycloud.kv/put"),
|
|
8169
|
+
etag: z6.string().min(1),
|
|
8170
|
+
bodyDigest: z6.string().min(1),
|
|
8171
|
+
contentType: z6.string().min(1)
|
|
7590
8172
|
}).strict()
|
|
7591
8173
|
]);
|
|
7592
8174
|
|
|
8175
|
+
// src/delegations/portable.ts
|
|
8176
|
+
import { z as z7 } from "zod";
|
|
8177
|
+
var ResourceSchema = z7.object({
|
|
8178
|
+
service: z7.string().min(1),
|
|
8179
|
+
space: z7.string().min(1),
|
|
8180
|
+
path: z7.string(),
|
|
8181
|
+
actions: z7.array(z7.string().min(1)).min(1),
|
|
8182
|
+
caveats: z7.array(z7.record(z7.unknown())).optional()
|
|
8183
|
+
}).strict();
|
|
8184
|
+
var PortableDelegationSchema = z7.object({
|
|
8185
|
+
cid: z7.string().min(1),
|
|
8186
|
+
delegationHeader: z7.object({ Authorization: z7.string().min(1) }).strict(),
|
|
8187
|
+
ownerAddress: z7.string().min(1),
|
|
8188
|
+
chainId: z7.number().int().nonnegative(),
|
|
8189
|
+
host: z7.string().url().optional(),
|
|
8190
|
+
spaceId: z7.string().min(1),
|
|
8191
|
+
path: z7.string(),
|
|
8192
|
+
actions: z7.array(z7.string().min(1)).min(1),
|
|
8193
|
+
caveats: z7.array(z7.record(z7.unknown())).optional(),
|
|
8194
|
+
expiry: z7.coerce.date(),
|
|
8195
|
+
delegateDID: z7.string().min(1),
|
|
8196
|
+
delegatorDID: z7.string().min(1).optional(),
|
|
8197
|
+
parentCid: z7.string().min(1).optional(),
|
|
8198
|
+
disableSubDelegation: z7.boolean().optional(),
|
|
8199
|
+
resources: z7.array(ResourceSchema).min(1).optional()
|
|
8200
|
+
}).strict();
|
|
8201
|
+
function parsePortableDelegation(input) {
|
|
8202
|
+
const parsed = PortableDelegationSchema.parse(input);
|
|
8203
|
+
if (parsed.resources !== void 0 && parsed.resources.length === 0)
|
|
8204
|
+
throw new Error("portable delegation resources must not be empty");
|
|
8205
|
+
return parsed;
|
|
8206
|
+
}
|
|
8207
|
+
function serializePortableDelegation(delegation) {
|
|
8208
|
+
return JSON.stringify({
|
|
8209
|
+
...delegation,
|
|
8210
|
+
expiry: delegation.expiry.toISOString()
|
|
8211
|
+
});
|
|
8212
|
+
}
|
|
8213
|
+
async function importPortableDelegation(fetchFn, host, delegation) {
|
|
8214
|
+
const parsed = parsePortableDelegation(delegation);
|
|
8215
|
+
const response = await fetchFn(`${host.replace(/\/+$/, "")}/delegate`, {
|
|
8216
|
+
method: "POST",
|
|
8217
|
+
headers: { Authorization: parsed.delegationHeader.Authorization }
|
|
8218
|
+
});
|
|
8219
|
+
if (!response.ok)
|
|
8220
|
+
throw new Error(`node rejected delegation import (${response.status})`);
|
|
8221
|
+
const body = await response.json().catch(() => ({}));
|
|
8222
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
8223
|
+
return {};
|
|
8224
|
+
return body;
|
|
8225
|
+
}
|
|
8226
|
+
async function delegatePortablePolicySession(input) {
|
|
8227
|
+
const parent = parsePortableDelegation(input.parent);
|
|
8228
|
+
const descendant = createCompactPolicyDescendant({
|
|
8229
|
+
parentAuthorization: parent.delegationHeader.Authorization.replace(/^Bearer\s+/i, ""),
|
|
8230
|
+
parentCid: parent.cid,
|
|
8231
|
+
issuerDid: parent.delegateDID,
|
|
8232
|
+
audienceDid: input.delegateDID,
|
|
8233
|
+
attenuation: input.attenuation,
|
|
8234
|
+
privateKey: input.issuerPrivateKey,
|
|
8235
|
+
...input.now === void 0 ? {} : { now: input.now },
|
|
8236
|
+
...input.expiresAt === void 0 ? {} : { expiresAt: input.expiresAt },
|
|
8237
|
+
...input.nonce === void 0 ? {} : { nonce: input.nonce }
|
|
8238
|
+
});
|
|
8239
|
+
const resources = Object.entries(descendant.payload.att).map(([resource, abilities]) => {
|
|
8240
|
+
const actions = Object.keys(abilities);
|
|
8241
|
+
if (resource.startsWith("urn:tinycloud:encryption:")) {
|
|
8242
|
+
return { service: "encryption", space: "encryption", path: resource, actions };
|
|
8243
|
+
}
|
|
8244
|
+
const match = /^tinycloud:\/\/([^/]+)\/kv\/(.+)$/.exec(resource);
|
|
8245
|
+
if (match === null) throw new Error("policy descendant resource is invalid");
|
|
8246
|
+
const caveats = Object.values(abilities).flat().filter((value) => value !== null && typeof value === "object" && !Array.isArray(value));
|
|
8247
|
+
return { service: "kv", space: match[1], path: match[2], actions, ...caveats.length === 0 ? {} : { caveats } };
|
|
8248
|
+
});
|
|
8249
|
+
const primary = resources.find((resource) => resource.service === "kv") ?? resources[0];
|
|
8250
|
+
if (primary === void 0) throw new Error("policy descendant attenuation is empty");
|
|
8251
|
+
const portable = {
|
|
8252
|
+
cid: descendant.cid,
|
|
8253
|
+
delegationHeader: { Authorization: descendant.authorization },
|
|
8254
|
+
ownerAddress: parent.ownerAddress,
|
|
8255
|
+
chainId: parent.chainId,
|
|
8256
|
+
host: input.host,
|
|
8257
|
+
spaceId: primary.space,
|
|
8258
|
+
path: primary.path,
|
|
8259
|
+
actions: primary.actions,
|
|
8260
|
+
expiry: new Date(descendant.payload.exp * 1e3),
|
|
8261
|
+
delegateDID: input.delegateDID,
|
|
8262
|
+
delegatorDID: parent.delegateDID,
|
|
8263
|
+
parentCid: parent.cid,
|
|
8264
|
+
disableSubDelegation: descendant.payload.fct[0]?.remainingRedelegationDepth === 0,
|
|
8265
|
+
resources
|
|
8266
|
+
};
|
|
8267
|
+
await importPortableDelegation(input.fetch, input.host, portable);
|
|
8268
|
+
return portable;
|
|
8269
|
+
}
|
|
8270
|
+
|
|
7593
8271
|
// src/delegations/ShareRecipientClient.ts
|
|
7594
8272
|
var DEFAULT_MAX_ARTIFACT_BYTES2 = MAX_SHARE_ARTIFACT_BYTES;
|
|
7595
8273
|
var DEFAULT_MAX_CONTENT_BYTES = MAX_SHARE_CONTENT_BYTES;
|
|
@@ -7640,8 +8318,8 @@ function canonicalJsonForProof(value) {
|
|
|
7640
8318
|
}
|
|
7641
8319
|
if (Array.isArray(value)) return `[${value.map(canonicalJsonForProof).join(",")}]`;
|
|
7642
8320
|
if (typeof value === "object") {
|
|
7643
|
-
const
|
|
7644
|
-
return `{${Object.keys(
|
|
8321
|
+
const object2 = value;
|
|
8322
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJsonForProof(object2[key])}`).join(",")}}`;
|
|
7645
8323
|
}
|
|
7646
8324
|
throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
7647
8325
|
}
|
|
@@ -7665,7 +8343,7 @@ function randomJti() {
|
|
|
7665
8343
|
return bytesToBase64Url2(bytes2);
|
|
7666
8344
|
}
|
|
7667
8345
|
function digestCanonical(value) {
|
|
7668
|
-
return bytesToBase64Url2(
|
|
8346
|
+
return bytesToBase64Url2(sha2568(new TextEncoder().encode(canonicalJsonForProof(value))));
|
|
7669
8347
|
}
|
|
7670
8348
|
function actionWire(action) {
|
|
7671
8349
|
return action === "get" ? "tinycloud.kv/get" : action === "metadata" ? "tinycloud.kv/metadata" : action === "list" ? "tinycloud.kv/list" : "tinycloud.kv/put";
|
|
@@ -7777,9 +8455,31 @@ var ShareRecipientClient = class {
|
|
|
7777
8455
|
if (policy && this.options.bearerSession !== void 0) throw new ShareAccessError("SHARE_POLICY_BEARER_MISMATCH");
|
|
7778
8456
|
if (bearer && this.options.presentation !== void 0) throw new ShareAccessError("SHARE_BEARER_PRESENTATION_MISMATCH");
|
|
7779
8457
|
const session = bearer || legacyBearer ? this.options.bearerSession : recipientDidSession ? recipientDidSession : policy && this.options.establishPolicySession !== void 0 ? await this.options.establishPolicySession({ envelope, presentation: this.options.presentation }) : policy ? await this.establishPolicySession(envelope) : void 0;
|
|
7780
|
-
const kv = bearer || legacyBearer ? session === void 0 ? void 0 : this.createKV(envelope.origin, session) : void 0;
|
|
7781
8458
|
const policySession = policy ? session : void 0;
|
|
7782
8459
|
if (policySession !== void 0) this.assertProvidedPolicySession(policySession, envelope);
|
|
8460
|
+
const portableDelegation = policySession === void 0 ? void 0 : this.policySessionDelegation(policySession, envelope.origin);
|
|
8461
|
+
const portableInvoke = portableDelegation === void 0 ? void 0 : this.policyInvocationSigner(portableDelegation);
|
|
8462
|
+
if (portableDelegation !== void 0) {
|
|
8463
|
+
if (this.options.importDelegation === void 0) {
|
|
8464
|
+
await importPortableDelegation(this.fetchFn, envelope.origin, portableDelegation);
|
|
8465
|
+
} else {
|
|
8466
|
+
const imported = await this.options.importDelegation(portableDelegation);
|
|
8467
|
+
if (imported !== void 0) {
|
|
8468
|
+
const normalized = parsePortableDelegation(imported);
|
|
8469
|
+
if (normalized.delegationHeader.Authorization !== portableDelegation.delegationHeader.Authorization) {
|
|
8470
|
+
throw new ShareAccessError("SHARE_SESSION_INVALID", "delegation importer changed authorization bytes");
|
|
8471
|
+
}
|
|
8472
|
+
}
|
|
8473
|
+
}
|
|
8474
|
+
}
|
|
8475
|
+
const ordinarySession = portableDelegation === void 0 ? void 0 : {
|
|
8476
|
+
delegationHeader: portableDelegation.delegationHeader,
|
|
8477
|
+
delegationCid: portableDelegation.cid,
|
|
8478
|
+
spaceId: this.policySessionProjection(portableDelegation).spaceId,
|
|
8479
|
+
verificationMethod: portableDelegation.delegateDID,
|
|
8480
|
+
jwk: this.options.bearerSession?.jwk ?? {}
|
|
8481
|
+
};
|
|
8482
|
+
const kv = bearer || legacyBearer || ordinarySession !== void 0 ? session === void 0 && ordinarySession === void 0 ? void 0 : this.createKV(envelope.origin, ordinarySession ?? session, portableInvoke) : void 0;
|
|
7783
8483
|
const advertisedCapability = { spaceId: envelope.spaceId, resource: envelope.resource, actions: envelope.actions };
|
|
7784
8484
|
const capability = policySession?.capability === void 0 ? advertisedCapability : intersectShareCapabilities(advertisedCapability, policySession.capability);
|
|
7785
8485
|
if (capability === void 0) throw new ShareAccessError("SHARE_CAPABILITY_EMPTY");
|
|
@@ -7804,6 +8504,11 @@ var ShareRecipientClient = class {
|
|
|
7804
8504
|
const scope = normalizePath2(input.path ?? envelope.resource.path);
|
|
7805
8505
|
this.assertAllowed(capability, "list", scope);
|
|
7806
8506
|
if (kv === void 0 && policySession === void 0) throw new ShareAccessError("SHARE_SESSION_REQUIRED");
|
|
8507
|
+
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
8508
|
+
const result2 = await kv.list({ path: scope, limit: input.limit, cursor: input.cursor });
|
|
8509
|
+
if (!result2.ok) throw result2.error;
|
|
8510
|
+
return { keys: result2.data.keys, truncated: result2.data.truncated, nextCursor: result2.data.nextCursor };
|
|
8511
|
+
}
|
|
7807
8512
|
if (policySession !== void 0) return this.nativeList(envelope, policySession, scope, input.limit, input.cursor);
|
|
7808
8513
|
const result = await kv.list({ path: scope, limit: input.limit, cursor: input.cursor });
|
|
7809
8514
|
if (!result.ok) throw result.error;
|
|
@@ -7817,6 +8522,14 @@ var ShareRecipientClient = class {
|
|
|
7817
8522
|
const resolvedPath = normalizePath2(path);
|
|
7818
8523
|
this.assertAllowed(capability, "save", resolvedPath);
|
|
7819
8524
|
if (kv === void 0 && policySession === void 0) throw new ShareAccessError("SHARE_SESSION_REQUIRED");
|
|
8525
|
+
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
8526
|
+
const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
8527
|
+
if (!result2.ok) {
|
|
8528
|
+
if (result2.error.code === ErrorCodes.KV_PRECONDITION_FAILED || result2.error.code === ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
|
|
8529
|
+
throw result2.error;
|
|
8530
|
+
}
|
|
8531
|
+
return { etag: result2.data.headers.etag };
|
|
8532
|
+
}
|
|
7820
8533
|
if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
|
|
7821
8534
|
const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
7822
8535
|
if (!result.ok) {
|
|
@@ -7832,22 +8545,79 @@ var ShareRecipientClient = class {
|
|
|
7832
8545
|
const metadata = async (path = envelope.resource.kind === "exact" ? envelope.resource.path : "") => {
|
|
7833
8546
|
const resolvedPath = normalizePath2(path);
|
|
7834
8547
|
this.assertAllowed(capability, "metadata", resolvedPath);
|
|
8548
|
+
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
8549
|
+
const result2 = await kv.head(resolvedPath);
|
|
8550
|
+
if (!result2.ok) throw result2.error;
|
|
8551
|
+
return { metadata: { "content-type": result2.data.headers.contentType ?? "application/octet-stream", "content-length": String(result2.data.headers.contentLength ?? ""), ...result2.data.headers.lastModified === void 0 ? {} : { "last-modified": result2.data.headers.lastModified } }, etag: result2.data.headers.etag, contentType: result2.data.headers.contentType, size: result2.data.headers.contentLength };
|
|
8552
|
+
}
|
|
7835
8553
|
if (policySession !== void 0) return this.nativeMetadata(envelope, policySession, resolvedPath);
|
|
7836
8554
|
if (kv === void 0) throw new ShareAccessError("SHARE_SESSION_REQUIRED");
|
|
7837
8555
|
const result = await kv.head(resolvedPath);
|
|
7838
8556
|
if (!result.ok) throw result.error;
|
|
7839
8557
|
return { metadata: { "content-type": result.data.headers.contentType ?? "application/octet-stream", "content-length": String(result.data.headers.contentLength ?? ""), ...result.data.headers.lastModified === void 0 ? {} : { "last-modified": result.data.headers.lastModified } }, etag: result.data.headers.etag, contentType: result.data.headers.contentType, size: result.data.headers.contentLength };
|
|
7840
8558
|
};
|
|
7841
|
-
return { kind: "share-v2", envelope, location: { ...location, key: void 0 }, resource: envelope.resource, actions: envelope.actions, expiresAt: new Date(envelope.expiresAt), kv, get, listChildren, save, metadata };
|
|
8559
|
+
return { kind: "share-v2", envelope, location: { ...location, key: void 0 }, resource: envelope.resource, actions: envelope.actions, expiresAt: new Date(envelope.expiresAt), kv, portableDelegation, get, listChildren, save, metadata };
|
|
7842
8560
|
} catch (error) {
|
|
7843
8561
|
throw asError(error);
|
|
7844
8562
|
}
|
|
7845
8563
|
}
|
|
7846
|
-
|
|
8564
|
+
policySessionDelegation(session, origin) {
|
|
8565
|
+
if (session.runtimeDelegation === void 0) return void 0;
|
|
8566
|
+
const delegation = parsePortableDelegation(session.runtimeDelegation);
|
|
8567
|
+
if (delegation.host !== void 0 && delegation.host.replace(/\/+$/, "") !== origin.replace(/\/+$/, "")) throw new ShareAccessError("SHARE_ORIGIN_MISMATCH", "delegation host does not match the trusted share origin");
|
|
8568
|
+
return delegation;
|
|
8569
|
+
}
|
|
8570
|
+
policyInvocationSigner(delegation) {
|
|
8571
|
+
const privateKey = this.options.policySessionPrivateKey;
|
|
8572
|
+
if (privateKey === void 0) throw new ShareAccessError("SHARE_SESSION_SIGNER_REQUIRED");
|
|
8573
|
+
const session = parsePolicySessionUcan(delegation.delegationHeader.Authorization);
|
|
8574
|
+
if (session.cid !== delegation.cid || session.aud !== delegation.delegateDID)
|
|
8575
|
+
throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
8576
|
+
return (_serviceSession, service, path, action, facts) => {
|
|
8577
|
+
const serviceName = service.replace(/^tinycloud\./, "");
|
|
8578
|
+
const cleanPath = path.replace(/^\//, "").replace(/\/$/, "");
|
|
8579
|
+
const authority = Object.entries(session.att).find(([parentResource, abilities]) => {
|
|
8580
|
+
if (!(action in abilities)) return false;
|
|
8581
|
+
if (serviceName === "encryption") return parentResource.startsWith("urn:tinycloud:encryption:") && parentResource === cleanPath;
|
|
8582
|
+
const match = /^tinycloud:\/\/[^/]+\/kv\/(.+)$/.exec(parentResource);
|
|
8583
|
+
if (match === null) return false;
|
|
8584
|
+
const parentPath = match[1];
|
|
8585
|
+
const caveats = abilities[action] ?? [];
|
|
8586
|
+
const prefix = caveats.some((value) => isRecord(value) && value.kind === "prefix");
|
|
8587
|
+
return cleanPath === parentPath || prefix && cleanPath.startsWith(`${parentPath}/`);
|
|
8588
|
+
});
|
|
8589
|
+
if (authority === void 0) throw new ShareAccessError("SHARE_OUT_OF_SCOPE");
|
|
8590
|
+
const resource = serviceName === "encryption" ? authority[0] : `${authority[0].slice(0, authority[0].indexOf("/kv/") + 4)}${cleanPath}`;
|
|
8591
|
+
const caveat = serviceName === "encryption" ? {} : { type: "xyz.tinycloud.resource/selector", kind: "exact", value: resource };
|
|
8592
|
+
const invocation = createCompactPolicyInvocation({
|
|
8593
|
+
sessionAuthorization: delegation.delegationHeader.Authorization,
|
|
8594
|
+
sessionCid: delegation.cid,
|
|
8595
|
+
recipientDid: delegation.delegateDID,
|
|
8596
|
+
audienceDid: String(session.fact.nodeAudience),
|
|
8597
|
+
resource,
|
|
8598
|
+
action,
|
|
8599
|
+
caveat,
|
|
8600
|
+
...facts?.length === 1 ? { facts: facts[0] } : {},
|
|
8601
|
+
privateKey,
|
|
8602
|
+
now: Math.floor(this.now().getTime() / 1e3)
|
|
8603
|
+
});
|
|
8604
|
+
return { Authorization: invocation.authorization };
|
|
8605
|
+
};
|
|
8606
|
+
}
|
|
8607
|
+
policySessionProjection(delegation) {
|
|
8608
|
+
const session = parsePolicySessionUcan(delegation.delegationHeader.Authorization);
|
|
8609
|
+
if (session.cid !== delegation.cid || session.aud !== delegation.delegateDID) throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
8610
|
+
const kvResource = Object.keys(session.att).find((resource) => /^tinycloud:\/\/[^/]+\/kv\/.+$/.test(resource));
|
|
8611
|
+
const match = kvResource === void 0 ? void 0 : /^tinycloud:\/\/([^/]+)\/kv\/(.+)$/.exec(kvResource);
|
|
8612
|
+
if (match === void 0 || match === null) throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
8613
|
+
return { spaceId: match[1] };
|
|
8614
|
+
}
|
|
8615
|
+
createKV(origin, session, invokeOverride) {
|
|
8616
|
+
const invoke = invokeOverride ?? this.options.invoke ?? nativeInvoke;
|
|
7847
8617
|
if (this.options.createKVService !== void 0) {
|
|
7848
|
-
return this.options.createKVService({ hosts: [origin], session, invoke
|
|
8618
|
+
return this.options.createKVService({ hosts: [origin], session, invoke, fetch: this.fetchFn });
|
|
7849
8619
|
}
|
|
7850
|
-
const context = new ServiceContext({ hosts: [origin], session, invoke
|
|
8620
|
+
const context = new ServiceContext({ hosts: [origin], session, invoke, fetch: this.fetchFn });
|
|
7851
8621
|
const service = new KVService({ prefix: "" });
|
|
7852
8622
|
context.registerService("kv", service);
|
|
7853
8623
|
service.initialize(context);
|
|
@@ -7890,7 +8660,7 @@ var ShareRecipientClient = class {
|
|
|
7890
8660
|
if (bytes2.byteLength > (this.options.maxContentBytes ?? DEFAULT_MAX_CONTENT_BYTES)) throw new ShareAccessError("SHARE_TOO_LARGE");
|
|
7891
8661
|
const contentType = input.contentType ?? envelope.content.mimeType;
|
|
7892
8662
|
if (contentType !== envelope.content.mimeType && !/^text\/(?:plain|markdown)(?:;|$)/i.test(contentType)) throw new ShareAccessError("SHARE_CONTENT_TYPE_INVALID");
|
|
7893
|
-
const result = await this.invokeNative({ envelope, session, action: "put", resource: path, body: bytes2, bodyDigest: bytesToBase64Url2(
|
|
8663
|
+
const result = await this.invokeNative({ envelope, session, action: "put", resource: path, body: bytes2, bodyDigest: bytesToBase64Url2(sha2568(bytes2)), contentType, ifMatch: input.etag, mediaType: "application/vnd.tinycloud.share+json" });
|
|
7894
8664
|
if (result.status === 412 || result.status === 409) throw new ShareConflict(path, result.headers?.etag);
|
|
7895
8665
|
if (result.status === 401 || result.status === 403) throw new ShareAccessError("SHARE_DENIED");
|
|
7896
8666
|
if (result.status < 200 || result.status >= 300) throw new ShareAccessError("SHARE_WRITE_FAILED");
|
|
@@ -8012,7 +8782,7 @@ var ShareRecipientClient = class {
|
|
|
8012
8782
|
};
|
|
8013
8783
|
const signed = this.options.signNativeInvoke === void 0 ? void 0 : await this.options.signNativeInvoke({ envelope: input.envelope, session: input.session, request: body });
|
|
8014
8784
|
const transport = this.options.invoke !== void 0 || session.authorization !== void 0 || session.delegationHeader !== void 0 ? this.defaultNativeHeaders(session, input.action, input.resource, body) : void 0;
|
|
8015
|
-
const response = await this.fetchFn(
|
|
8785
|
+
const response = await this.fetchFn(`${base3}/invoke`, {
|
|
8016
8786
|
method: "POST",
|
|
8017
8787
|
headers: { ...headersRecord2(transport), ...headersRecord2(signed), "content-type": input.mediaType, accept: input.mediaType },
|
|
8018
8788
|
body: JSON.stringify(body),
|
|
@@ -8136,7 +8906,7 @@ var ShareRecipientClient = class {
|
|
|
8136
8906
|
}]);
|
|
8137
8907
|
}
|
|
8138
8908
|
digestMatches(value, bytes2) {
|
|
8139
|
-
const digest4 = bytesToBase64Url2(
|
|
8909
|
+
const digest4 = bytesToBase64Url2(sha2568(bytes2));
|
|
8140
8910
|
return value === digest4 || value === `sha-256=:${digest4}:`;
|
|
8141
8911
|
}
|
|
8142
8912
|
assertNativeRequestBounds(envelope, session, operation, path, limit, cursor) {
|
|
@@ -8258,12 +9028,12 @@ var ShareRecipientClient = class {
|
|
|
8258
9028
|
this.assertDetachedProof(request.proof);
|
|
8259
9029
|
}
|
|
8260
9030
|
parseSessionCapability(value) {
|
|
8261
|
-
const
|
|
8262
|
-
if (typeof
|
|
8263
|
-
if (!Array.isArray(
|
|
8264
|
-
const resource = this.requireObject(
|
|
9031
|
+
const object2 = this.requireObject(value, "session capability");
|
|
9032
|
+
if (typeof object2.spaceId !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability space is invalid");
|
|
9033
|
+
if (!Array.isArray(object2.actions) || object2.actions.some((action) => !["read", "list", "edit"].includes(action))) throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability actions are invalid");
|
|
9034
|
+
const resource = this.requireObject(object2.resource, "session capability resource");
|
|
8265
9035
|
if (resource.kind !== "exact" && resource.kind !== "prefix" || typeof resource.path !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability resource is invalid");
|
|
8266
|
-
return { spaceId:
|
|
9036
|
+
return { spaceId: object2.spaceId, actions: [...new Set(object2.actions)], resource: { kind: resource.kind, path: resource.path } };
|
|
8267
9037
|
}
|
|
8268
9038
|
assertProvidedPolicySession(session, envelope) {
|
|
8269
9039
|
const sessionExpiry = dateValue(session.expiresAt);
|
|
@@ -8354,7 +9124,7 @@ var ShareRecipientClient = class {
|
|
|
8354
9124
|
nodeAudience: binding.nodeAudience,
|
|
8355
9125
|
...isV2 ? {
|
|
8356
9126
|
enforcerDid: challenge.enforcerDid,
|
|
8357
|
-
credentialDigest: typeof presentation.credentialDigest === "string" ? presentation.credentialDigest : bytesToBase64Url2(
|
|
9127
|
+
credentialDigest: typeof presentation.credentialDigest === "string" ? presentation.credentialDigest : bytesToBase64Url2(sha2568(new TextEncoder().encode(credential)))
|
|
8358
9128
|
} : {},
|
|
8359
9129
|
action,
|
|
8360
9130
|
...binding.actions === void 0 ? {} : { actions: [...binding.actions] },
|
|
@@ -8420,7 +9190,7 @@ var ShareRecipientClient = class {
|
|
|
8420
9190
|
}
|
|
8421
9191
|
if (isJwsProof && detached.kid !== `${signerDid}#${encoded}` || isEd25519Proof && detached.signerDid !== signerDid || signature.length !== 64) throw new ShareAccessError("SHARE_SESSION_INVALID", "Node proof binding is invalid");
|
|
8422
9192
|
const bytes2 = new TextEncoder().encode(`${domain}${canonicalJsonForProof(message)}`);
|
|
8423
|
-
if (!
|
|
9193
|
+
if (!ed255194.verify(signature, bytes2, key)) throw new ShareAccessError("SHARE_SESSION_INVALID", "Node proof signature is invalid");
|
|
8424
9194
|
}
|
|
8425
9195
|
assertChallengeRequestBinding(request, challenge) {
|
|
8426
9196
|
const source = isRecord(request.body) ? request.body : request;
|
|
@@ -9624,7 +10394,7 @@ function shareKeyMatchesDid(key, didUrl) {
|
|
|
9624
10394
|
if (!publicKey) return false;
|
|
9625
10395
|
const jwkBytes = decodeBase64UrlBytes(key.x);
|
|
9626
10396
|
const privateKey = decodeBase64UrlBytes(key.d);
|
|
9627
|
-
const derivedPublicKey =
|
|
10397
|
+
const derivedPublicKey = ed255195.getPublicKey(privateKey);
|
|
9628
10398
|
return privateKey.length === 32 && publicKey.length === jwkBytes.length && publicKey.every((byte, index) => byte === jwkBytes[index]) && derivedPublicKey.length === jwkBytes.length && derivedPublicKey.every((byte, index) => byte === jwkBytes[index]);
|
|
9629
10399
|
} catch {
|
|
9630
10400
|
return false;
|
|
@@ -9674,8 +10444,8 @@ function verifySignedChild(result, expected, computeCid) {
|
|
|
9674
10444
|
}
|
|
9675
10445
|
|
|
9676
10446
|
// src/delegations/owner-policy.ts
|
|
9677
|
-
import { ed25519 as
|
|
9678
|
-
import { sha256 as
|
|
10447
|
+
import { ed25519 as ed255196 } from "@noble/curves/ed25519";
|
|
10448
|
+
import { sha256 as sha2569 } from "@noble/hashes/sha256";
|
|
9679
10449
|
var MAX_CONTENT_BYTES = 100 * 1024 * 1024;
|
|
9680
10450
|
var ENFORCEMENT_DOMAIN = "xyz.tinycloud.share/policy-enforcement/v2\0";
|
|
9681
10451
|
var POLICY_DOMAIN = "xyz.tinycloud.share/policy/v2\0";
|
|
@@ -9702,10 +10472,10 @@ function fromB64(value) {
|
|
|
9702
10472
|
throw new Error("base64url decoding is unavailable");
|
|
9703
10473
|
}
|
|
9704
10474
|
function cid(bytesValue) {
|
|
9705
|
-
return CID.createV1(code, create(sha2562.code,
|
|
10475
|
+
return CID.createV1(code, create(sha2562.code, sha2569(bytesValue))).toString(base32.encoder);
|
|
9706
10476
|
}
|
|
9707
10477
|
function digest3(bytesValue) {
|
|
9708
|
-
return b64(
|
|
10478
|
+
return b64(sha2569(bytesValue));
|
|
9709
10479
|
}
|
|
9710
10480
|
function didKeyFromEd25519PublicKey(publicKey) {
|
|
9711
10481
|
if (publicKey.length !== 32) throw new Error("share key public key must be 32 bytes");
|
|
@@ -9890,7 +10660,7 @@ function validateOwnerSharePolicyRegistration(value, expected) {
|
|
|
9890
10660
|
const publicKey = encodedKid.length === 34 ? encodedKid.slice(2) : encodedKid;
|
|
9891
10661
|
const signatureBytes = fromB64(proof.signature);
|
|
9892
10662
|
const signedBytes = new TextEncoder().encode(`${OWNER_SHARE_REGISTRATION_DOMAIN}${canonicalizeSignedObjectUnsigned(registrationCore)}`);
|
|
9893
|
-
if (signatureBytes.length !== 64 || !
|
|
10663
|
+
if (signatureBytes.length !== 64 || !ed255196.verify(signatureBytes, signedBytes, publicKey)) throw new Error("owner-share registration proof signature is invalid");
|
|
9894
10664
|
return { registration, proof };
|
|
9895
10665
|
}
|
|
9896
10666
|
function validateOwnerSharePolicyRegistrationBytes(bytesValue, expected) {
|
|
@@ -9904,7 +10674,7 @@ function validateOwnerSharePolicyRegistrationBytes(bytesValue, expected) {
|
|
|
9904
10674
|
}
|
|
9905
10675
|
|
|
9906
10676
|
// src/delegations/share-delivery.ts
|
|
9907
|
-
import { ed25519 as
|
|
10677
|
+
import { ed25519 as ed255197 } from "@noble/curves/ed25519";
|
|
9908
10678
|
var SHARE_DELIVERY_AUTHORIZATION_DOMAIN = "xyz.tinycloud.share/delivery-authorization/v2\0";
|
|
9909
10679
|
function isCanonicalHttpsOrigin(value) {
|
|
9910
10680
|
let url;
|
|
@@ -9992,7 +10762,7 @@ function validateShareDeliveryAuthorizationBytes(bytesValue, expected) {
|
|
|
9992
10762
|
if (publicKey.length !== 32) throw new Error("share delivery authorization proof key is invalid");
|
|
9993
10763
|
const signatureBytes = fromB642(proof.signature);
|
|
9994
10764
|
const signedBytes = new TextEncoder().encode(`${SHARE_DELIVERY_AUTHORIZATION_DOMAIN}${canonicalizeSignedObjectUnsigned(authorization)}`);
|
|
9995
|
-
if (signatureBytes.length !== 64 || !
|
|
10765
|
+
if (signatureBytes.length !== 64 || !ed255197.verify(signatureBytes, signedBytes, publicKey)) throw new Error("share delivery authorization proof signature is invalid");
|
|
9996
10766
|
return { authorization, proof };
|
|
9997
10767
|
}
|
|
9998
10768
|
function shareDeliveryTrustedKid(publicKey) {
|
|
@@ -10153,47 +10923,47 @@ function parseCanonicalNetworkId(networkId) {
|
|
|
10153
10923
|
}
|
|
10154
10924
|
|
|
10155
10925
|
// src/storage.schema.ts
|
|
10156
|
-
import { z as
|
|
10926
|
+
import { z as z8 } from "zod";
|
|
10157
10927
|
var ethereumAddressPattern = /^0x[a-fA-F0-9]{40}$/;
|
|
10158
|
-
var EnsDataSchema2 =
|
|
10928
|
+
var EnsDataSchema2 = z8.object({
|
|
10159
10929
|
/** ENS name/domain. */
|
|
10160
|
-
domain:
|
|
10930
|
+
domain: z8.string().nullable().optional(),
|
|
10161
10931
|
/** ENS avatar URL. */
|
|
10162
|
-
avatarUrl:
|
|
10932
|
+
avatarUrl: z8.string().nullable().optional()
|
|
10163
10933
|
});
|
|
10164
|
-
var PersistedTinyCloudSessionSchema =
|
|
10934
|
+
var PersistedTinyCloudSessionSchema = z8.object({
|
|
10165
10935
|
/** The delegation header containing the UCAN */
|
|
10166
|
-
delegationHeader:
|
|
10167
|
-
Authorization:
|
|
10936
|
+
delegationHeader: z8.object({
|
|
10937
|
+
Authorization: z8.string()
|
|
10168
10938
|
}),
|
|
10169
10939
|
/** The delegation CID */
|
|
10170
|
-
delegationCid:
|
|
10940
|
+
delegationCid: z8.string(),
|
|
10171
10941
|
/** The space ID for this session */
|
|
10172
|
-
spaceId:
|
|
10942
|
+
spaceId: z8.string(),
|
|
10173
10943
|
/** Additional spaces included in this session's capabilities. Key is logical name, value is full spaceId URI */
|
|
10174
|
-
spaces:
|
|
10944
|
+
spaces: z8.record(z8.string(), z8.string()).optional(),
|
|
10175
10945
|
/** The verification method DID */
|
|
10176
|
-
verificationMethod:
|
|
10946
|
+
verificationMethod: z8.string()
|
|
10177
10947
|
});
|
|
10178
|
-
var PersistedSessionDataSchema =
|
|
10948
|
+
var PersistedSessionDataSchema = z8.object({
|
|
10179
10949
|
/** User's Ethereum address */
|
|
10180
|
-
address:
|
|
10950
|
+
address: z8.string().regex(ethereumAddressPattern, "Invalid Ethereum address"),
|
|
10181
10951
|
/** EIP-155 Chain ID */
|
|
10182
|
-
chainId:
|
|
10952
|
+
chainId: z8.number().int().positive(),
|
|
10183
10953
|
/** Session key in JWK format (stringified) */
|
|
10184
|
-
sessionKey:
|
|
10954
|
+
sessionKey: z8.string(),
|
|
10185
10955
|
/** The signed SIWE message */
|
|
10186
|
-
siwe:
|
|
10956
|
+
siwe: z8.string(),
|
|
10187
10957
|
/** User's signature of the SIWE message */
|
|
10188
|
-
signature:
|
|
10958
|
+
signature: z8.string(),
|
|
10189
10959
|
/** TinyCloud delegation data if available */
|
|
10190
10960
|
tinycloudSession: PersistedTinyCloudSessionSchema.optional(),
|
|
10191
10961
|
/** Session expiration timestamp (ISO 8601 with timezone offset) */
|
|
10192
|
-
expiresAt:
|
|
10962
|
+
expiresAt: z8.string().datetime({ offset: true }),
|
|
10193
10963
|
/** Session creation timestamp (ISO 8601 with timezone offset) */
|
|
10194
|
-
createdAt:
|
|
10964
|
+
createdAt: z8.string().datetime({ offset: true }),
|
|
10195
10965
|
/** Schema version for migrations */
|
|
10196
|
-
version:
|
|
10966
|
+
version: z8.string(),
|
|
10197
10967
|
/** Optional ENS data */
|
|
10198
10968
|
ens: EnsDataSchema2.optional(),
|
|
10199
10969
|
/**
|
|
@@ -10203,33 +10973,33 @@ var PersistedSessionDataSchema = z6.object({
|
|
|
10203
10973
|
* for backward compatibility with sessions persisted before this field
|
|
10204
10974
|
* existed — those restore and lazily re-resolve their hosts.
|
|
10205
10975
|
*/
|
|
10206
|
-
tinycloudHosts:
|
|
10976
|
+
tinycloudHosts: z8.array(z8.string()).optional()
|
|
10207
10977
|
});
|
|
10208
|
-
var TinyCloudSessionSchema =
|
|
10978
|
+
var TinyCloudSessionSchema = z8.object({
|
|
10209
10979
|
/** User's Ethereum address */
|
|
10210
|
-
address:
|
|
10980
|
+
address: z8.string().regex(ethereumAddressPattern, "Invalid Ethereum address"),
|
|
10211
10981
|
/** EIP-155 Chain ID */
|
|
10212
|
-
chainId:
|
|
10982
|
+
chainId: z8.number().int().positive(),
|
|
10213
10983
|
/** Session key ID */
|
|
10214
|
-
sessionKey:
|
|
10984
|
+
sessionKey: z8.string(),
|
|
10215
10985
|
/** The space ID for this session */
|
|
10216
|
-
spaceId:
|
|
10986
|
+
spaceId: z8.string(),
|
|
10217
10987
|
/** Additional spaces included in this session's capabilities. Key is logical name, value is full spaceId URI */
|
|
10218
|
-
spaces:
|
|
10988
|
+
spaces: z8.record(z8.string(), z8.string()).optional(),
|
|
10219
10989
|
/** The delegation CID */
|
|
10220
|
-
delegationCid:
|
|
10990
|
+
delegationCid: z8.string(),
|
|
10221
10991
|
/** The delegation header for API calls */
|
|
10222
|
-
delegationHeader:
|
|
10223
|
-
Authorization:
|
|
10992
|
+
delegationHeader: z8.object({
|
|
10993
|
+
Authorization: z8.string()
|
|
10224
10994
|
}),
|
|
10225
10995
|
/** The verification method DID */
|
|
10226
|
-
verificationMethod:
|
|
10996
|
+
verificationMethod: z8.string(),
|
|
10227
10997
|
/** The session key JWK (required for invoke operations) */
|
|
10228
|
-
jwk:
|
|
10998
|
+
jwk: z8.object({}).passthrough(),
|
|
10229
10999
|
/** The signed SIWE message */
|
|
10230
|
-
siwe:
|
|
11000
|
+
siwe: z8.string(),
|
|
10231
11001
|
/** User's signature of the SIWE message */
|
|
10232
|
-
signature:
|
|
11002
|
+
signature: z8.string()
|
|
10233
11003
|
});
|
|
10234
11004
|
function validatePersistedSessionData(data) {
|
|
10235
11005
|
const result = PersistedSessionDataSchema.safeParse(data);
|
|
@@ -10342,112 +11112,112 @@ var Space = class {
|
|
|
10342
11112
|
};
|
|
10343
11113
|
|
|
10344
11114
|
// src/spaces/spaces.schema.ts
|
|
10345
|
-
import { z as
|
|
10346
|
-
var SpaceConfigSchema =
|
|
11115
|
+
import { z as z9 } from "zod";
|
|
11116
|
+
var SpaceConfigSchema = z9.object({
|
|
10347
11117
|
/** The space identifier (full URI) */
|
|
10348
|
-
id:
|
|
11118
|
+
id: z9.string(),
|
|
10349
11119
|
/** The short name of the space */
|
|
10350
|
-
name:
|
|
11120
|
+
name: z9.string(),
|
|
10351
11121
|
/** Factory function to create a space-scoped KV service */
|
|
10352
|
-
createKV:
|
|
11122
|
+
createKV: z9.function(),
|
|
10353
11123
|
/** Factory function to create a space-scoped Data Vault service */
|
|
10354
|
-
createVault:
|
|
11124
|
+
createVault: z9.function(),
|
|
10355
11125
|
/** Optional factory function to create a space-scoped secrets service */
|
|
10356
|
-
createSecrets:
|
|
11126
|
+
createSecrets: z9.function().optional(),
|
|
10357
11127
|
/** Factory function to create space-scoped delegations */
|
|
10358
|
-
createDelegations:
|
|
11128
|
+
createDelegations: z9.function(),
|
|
10359
11129
|
/** Factory function to create space-scoped sharing */
|
|
10360
|
-
createSharing:
|
|
11130
|
+
createSharing: z9.function(),
|
|
10361
11131
|
/** Function to get space info */
|
|
10362
|
-
getInfo:
|
|
11132
|
+
getInfo: z9.function()
|
|
10363
11133
|
});
|
|
10364
|
-
var SpaceServiceConfigSchema =
|
|
11134
|
+
var SpaceServiceConfigSchema = z9.object({
|
|
10365
11135
|
/** TinyCloud host URLs */
|
|
10366
|
-
hosts:
|
|
11136
|
+
hosts: z9.array(z9.string()),
|
|
10367
11137
|
/** Active session for authentication */
|
|
10368
|
-
session:
|
|
11138
|
+
session: z9.unknown(),
|
|
10369
11139
|
/** Platform-specific invoke function */
|
|
10370
|
-
invoke:
|
|
11140
|
+
invoke: z9.function(),
|
|
10371
11141
|
/** Optional custom fetch implementation */
|
|
10372
|
-
fetch:
|
|
11142
|
+
fetch: z9.function().optional(),
|
|
10373
11143
|
/** Optional capability key registry for delegated space discovery */
|
|
10374
|
-
capabilityRegistry:
|
|
11144
|
+
capabilityRegistry: z9.unknown().optional(),
|
|
10375
11145
|
/** Factory function to create a space-scoped KV service */
|
|
10376
|
-
createKVService:
|
|
11146
|
+
createKVService: z9.function().optional(),
|
|
10377
11147
|
/** Factory function to create a space-scoped Data Vault service */
|
|
10378
|
-
createVaultService:
|
|
11148
|
+
createVaultService: z9.function().optional(),
|
|
10379
11149
|
/** Factory function to create a space-scoped secrets service */
|
|
10380
|
-
createSecretsService:
|
|
11150
|
+
createSecretsService: z9.function().optional(),
|
|
10381
11151
|
/** User's PKH DID (derived from address or provided explicitly) */
|
|
10382
|
-
userDid:
|
|
11152
|
+
userDid: z9.string().optional(),
|
|
10383
11153
|
/** Optional SharingService for v2 sharing links (client-side) */
|
|
10384
|
-
sharingService:
|
|
11154
|
+
sharingService: z9.unknown().optional(),
|
|
10385
11155
|
/** Factory function to create delegations using SIWE-based flow */
|
|
10386
|
-
createDelegation:
|
|
11156
|
+
createDelegation: z9.function().optional()
|
|
10387
11157
|
});
|
|
10388
11158
|
var SpaceDelegationParamsSchema = CreateDelegationParamsSchema.extend({
|
|
10389
11159
|
/** The space ID to create the delegation for */
|
|
10390
|
-
spaceId:
|
|
11160
|
+
spaceId: z9.string()
|
|
10391
11161
|
});
|
|
10392
|
-
var ServerDelegationInfoSchema =
|
|
11162
|
+
var ServerDelegationInfoSchema = z9.object({
|
|
10393
11163
|
/** DID of the delegator */
|
|
10394
|
-
delegator:
|
|
11164
|
+
delegator: z9.string(),
|
|
10395
11165
|
/** DID of the delegate */
|
|
10396
|
-
delegate:
|
|
11166
|
+
delegate: z9.string(),
|
|
10397
11167
|
/** Parent delegation CIDs - accepts string or byte array format from server */
|
|
10398
|
-
parents:
|
|
11168
|
+
parents: z9.array(z9.union([z9.string(), z9.array(z9.number())])),
|
|
10399
11169
|
/** Expiration time (ISO8601 string) */
|
|
10400
|
-
expiry:
|
|
11170
|
+
expiry: z9.string().optional(),
|
|
10401
11171
|
/** Not-before time (ISO8601 string) */
|
|
10402
|
-
not_before:
|
|
11172
|
+
not_before: z9.string().optional(),
|
|
10403
11173
|
/** Issued-at time (ISO8601 string) */
|
|
10404
|
-
issued_at:
|
|
11174
|
+
issued_at: z9.string().optional(),
|
|
10405
11175
|
/** Capabilities granted by this delegation */
|
|
10406
|
-
capabilities:
|
|
10407
|
-
|
|
10408
|
-
resource:
|
|
10409
|
-
ability:
|
|
11176
|
+
capabilities: z9.array(
|
|
11177
|
+
z9.object({
|
|
11178
|
+
resource: z9.string(),
|
|
11179
|
+
ability: z9.string()
|
|
10410
11180
|
})
|
|
10411
11181
|
)
|
|
10412
11182
|
});
|
|
10413
|
-
var ServerDelegationsResponseSchema =
|
|
10414
|
-
|
|
11183
|
+
var ServerDelegationsResponseSchema = z9.record(
|
|
11184
|
+
z9.string(),
|
|
10415
11185
|
ServerDelegationInfoSchema
|
|
10416
11186
|
);
|
|
10417
|
-
var ServerOwnedSpaceSchema =
|
|
11187
|
+
var ServerOwnedSpaceSchema = z9.object({
|
|
10418
11188
|
/** Space identifier */
|
|
10419
|
-
id:
|
|
11189
|
+
id: z9.string(),
|
|
10420
11190
|
/** Space name (optional, can be derived from id) */
|
|
10421
|
-
name:
|
|
11191
|
+
name: z9.string().optional(),
|
|
10422
11192
|
/** Owner DID */
|
|
10423
|
-
owner:
|
|
11193
|
+
owner: z9.string(),
|
|
10424
11194
|
/** Creation timestamp */
|
|
10425
|
-
createdAt:
|
|
11195
|
+
createdAt: z9.string().optional()
|
|
10426
11196
|
});
|
|
10427
|
-
var ServerOwnedSpacesResponseSchema =
|
|
10428
|
-
var ServerCreateSpaceResponseSchema =
|
|
11197
|
+
var ServerOwnedSpacesResponseSchema = z9.array(ServerOwnedSpaceSchema);
|
|
11198
|
+
var ServerCreateSpaceResponseSchema = z9.object({
|
|
10429
11199
|
/** Space identifier */
|
|
10430
|
-
id:
|
|
11200
|
+
id: z9.string(),
|
|
10431
11201
|
/** Space name */
|
|
10432
|
-
name:
|
|
11202
|
+
name: z9.string(),
|
|
10433
11203
|
/** Owner DID */
|
|
10434
|
-
owner:
|
|
11204
|
+
owner: z9.string(),
|
|
10435
11205
|
/** Creation timestamp */
|
|
10436
|
-
createdAt:
|
|
11206
|
+
createdAt: z9.string().optional()
|
|
10437
11207
|
});
|
|
10438
|
-
var ServerSpaceInfoResponseSchema =
|
|
11208
|
+
var ServerSpaceInfoResponseSchema = z9.object({
|
|
10439
11209
|
/** Space identifier */
|
|
10440
|
-
id:
|
|
11210
|
+
id: z9.string(),
|
|
10441
11211
|
/** Space name (optional) */
|
|
10442
|
-
name:
|
|
11212
|
+
name: z9.string().optional(),
|
|
10443
11213
|
/** Owner DID */
|
|
10444
|
-
owner:
|
|
11214
|
+
owner: z9.string(),
|
|
10445
11215
|
/** Ownership type */
|
|
10446
|
-
type:
|
|
11216
|
+
type: z9.enum(["owned", "delegated"]).optional(),
|
|
10447
11217
|
/** Permissions the user has in this space */
|
|
10448
|
-
permissions:
|
|
11218
|
+
permissions: z9.array(z9.string()).optional(),
|
|
10449
11219
|
/** Expiration for delegated access */
|
|
10450
|
-
expiresAt:
|
|
11220
|
+
expiresAt: z9.string().optional()
|
|
10451
11221
|
});
|
|
10452
11222
|
function validateServerDelegationsResponse(data) {
|
|
10453
11223
|
if (data === null || data === void 0) {
|
|
@@ -12764,8 +13534,8 @@ function stableJson(value) {
|
|
|
12764
13534
|
if (Array.isArray(value)) {
|
|
12765
13535
|
return `[${value.map(stableJson).join(",")}]`;
|
|
12766
13536
|
}
|
|
12767
|
-
const
|
|
12768
|
-
return `{${Object.keys(
|
|
13537
|
+
const object2 = value;
|
|
13538
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${stableJson(object2[key])}`).join(",")}}`;
|
|
12769
13539
|
}
|
|
12770
13540
|
function indexedDelegationFromRow(row) {
|
|
12771
13541
|
const [
|
|
@@ -13856,8 +14626,10 @@ async function checkNodeInfo(host, sdkProtocol, fetchFn = globalThis.fetch.bind(
|
|
|
13856
14626
|
|
|
13857
14627
|
// src/index.ts
|
|
13858
14628
|
import {
|
|
14629
|
+
ACCOUNT_MANIFEST_PERMISSIONS as ACCOUNT_MANIFEST_PERMISSIONS2,
|
|
13859
14630
|
ACCOUNT_INDEX_SCHEMA as ACCOUNT_INDEX_SCHEMA2,
|
|
13860
14631
|
BOOTSTRAP_ALLOWLIST,
|
|
14632
|
+
BOOTSTRAP_DEFAULT_ONLY_SESSION_REQUEST,
|
|
13861
14633
|
BOOTSTRAP_DEFAULT_SPACE,
|
|
13862
14634
|
BOOTSTRAP_ENCRYPTION_NETWORK_NAME,
|
|
13863
14635
|
BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE,
|
|
@@ -15536,7 +16308,7 @@ function portForProtocol(protocol) {
|
|
|
15536
16308
|
}
|
|
15537
16309
|
|
|
15538
16310
|
// src/location.ts
|
|
15539
|
-
import { ed25519 as
|
|
16311
|
+
import { ed25519 as ed255198 } from "@noble/curves/ed25519";
|
|
15540
16312
|
import { verifyMessage as verifyMessage2 } from "viem";
|
|
15541
16313
|
var DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
|
|
15542
16314
|
var DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
|
|
@@ -16102,13 +16874,13 @@ async function verifyPkhSignature(did, payload, signature) {
|
|
|
16102
16874
|
}
|
|
16103
16875
|
function verifyDidKeySignature(did, payload, signature) {
|
|
16104
16876
|
const publicKey = ed25519PublicKeyFromDidKey2(did);
|
|
16105
|
-
const signatureBytes =
|
|
16877
|
+
const signatureBytes = decodeBase64Url2(signature);
|
|
16106
16878
|
if (signatureBytes.length !== 64) {
|
|
16107
16879
|
throw new LocationRecordValidationError(
|
|
16108
16880
|
"did:key signature must be a base64url Ed25519 signature"
|
|
16109
16881
|
);
|
|
16110
16882
|
}
|
|
16111
|
-
return
|
|
16883
|
+
return ed255198.verify(
|
|
16112
16884
|
signatureBytes,
|
|
16113
16885
|
new TextEncoder().encode(payload),
|
|
16114
16886
|
publicKey
|
|
@@ -16116,7 +16888,7 @@ function verifyDidKeySignature(did, payload, signature) {
|
|
|
16116
16888
|
}
|
|
16117
16889
|
function verifyDidKeyEd25519Signature(did, payload, signature) {
|
|
16118
16890
|
const publicKey = ed25519PublicKeyFromDidKey2(did);
|
|
16119
|
-
return
|
|
16891
|
+
return ed255198.verify(signature, payload, publicKey);
|
|
16120
16892
|
}
|
|
16121
16893
|
function ed25519PublicKeyFromDidKey2(did) {
|
|
16122
16894
|
const identifier = did.slice("did:key:".length);
|
|
@@ -16155,7 +16927,7 @@ function base64UrlEncode3(bytes2) {
|
|
|
16155
16927
|
}
|
|
16156
16928
|
return output;
|
|
16157
16929
|
}
|
|
16158
|
-
function
|
|
16930
|
+
function decodeBase64Url2(value) {
|
|
16159
16931
|
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
16160
16932
|
const bytes2 = [];
|
|
16161
16933
|
let buffer = 0;
|
|
@@ -16178,11 +16950,14 @@ function decodeBase64Url(value) {
|
|
|
16178
16950
|
}
|
|
16179
16951
|
export {
|
|
16180
16952
|
ACCOUNT_INDEX_SCHEMA2 as ACCOUNT_INDEX_SCHEMA,
|
|
16953
|
+
ACCOUNT_MANIFEST_PERMISSIONS2 as ACCOUNT_MANIFEST_PERMISSIONS,
|
|
16181
16954
|
ACCOUNT_REGISTRY_PATH,
|
|
16182
16955
|
ACCOUNT_REGISTRY_SPACE,
|
|
16956
|
+
ATTESTED_ENFORCER_BINDING_V2_SCHEMA,
|
|
16183
16957
|
AccountService,
|
|
16184
16958
|
AutoApproveSpaceCreationHandler,
|
|
16185
16959
|
BOOTSTRAP_ALLOWLIST,
|
|
16960
|
+
BOOTSTRAP_DEFAULT_ONLY_SESSION_REQUEST,
|
|
16186
16961
|
BOOTSTRAP_DEFAULT_SPACE,
|
|
16187
16962
|
BOOTSTRAP_ENCRYPTION_NETWORK_NAME,
|
|
16188
16963
|
BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE,
|
|
@@ -16194,6 +16969,7 @@ export {
|
|
|
16194
16969
|
BOOTSTRAP_SPACE_NAMES,
|
|
16195
16970
|
CAPABILITIES,
|
|
16196
16971
|
CAPABILITY_REGISTRY2 as CAPABILITY_REGISTRY,
|
|
16972
|
+
CONTENT_SOURCE_V1_DOMAIN,
|
|
16197
16973
|
CapabilityKeyRegistry,
|
|
16198
16974
|
CapabilityKeyRegistryErrorCodes,
|
|
16199
16975
|
CaveatedDelegationUnsupportedError,
|
|
@@ -16242,12 +17018,15 @@ export {
|
|
|
16242
17018
|
IdentityParseError,
|
|
16243
17019
|
KV,
|
|
16244
17020
|
KVService3 as KVService,
|
|
17021
|
+
LAST_V2_CREATE_AT,
|
|
17022
|
+
LAST_V2_READ_AT,
|
|
16245
17023
|
LISTEN_SQL_STATEMENT_CATALOG,
|
|
16246
17024
|
LOCAL_LINK_HOST_SUFFIX,
|
|
16247
17025
|
LOCAL_LINK_PROBE_TIMEOUT_MS,
|
|
16248
17026
|
LOCAL_LOOPBACK_PROBE_TIMEOUT_MS,
|
|
16249
17027
|
LocationRecordValidationError,
|
|
16250
17028
|
MAX_CONTENT_BYTES,
|
|
17029
|
+
MAX_LEGACY_ENVELOPE_EXPIRES_AT,
|
|
16251
17030
|
MAX_SEALED_SHARE_CONTENT_BYTES,
|
|
16252
17031
|
MAX_SHARE_ARTIFACT_BYTES,
|
|
16253
17032
|
MAX_SHARE_CONTENT_BYTES,
|
|
@@ -16255,9 +17034,13 @@ export {
|
|
|
16255
17034
|
MemorySenderShareKeyStorage,
|
|
16256
17035
|
MemorySenderShareRecordStorage,
|
|
16257
17036
|
MemoryShareCache,
|
|
17037
|
+
NATIVE_PROJECTION_V1_DOMAIN,
|
|
16258
17038
|
NETWORK_NAME_PATTERN,
|
|
16259
17039
|
NetworkIdError,
|
|
16260
17040
|
OPENKEY_ACTION_ID_SEPARATOR,
|
|
17041
|
+
POLICY_CAPABILITY_V1_DOMAIN,
|
|
17042
|
+
POLICY_CAPABILITY_V1_SCHEMA,
|
|
17043
|
+
POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA,
|
|
16261
17044
|
POLICY_ENGINE_CHALLENGE_REQUEST_SCHEMA,
|
|
16262
17045
|
POLICY_ENGINE_CHALLENGE_RESPONSE_SCHEMA,
|
|
16263
17046
|
POLICY_ENGINE_DENIAL_SCHEMA,
|
|
@@ -16265,7 +17048,10 @@ export {
|
|
|
16265
17048
|
POLICY_ENGINE_RECORD_SCHEMA,
|
|
16266
17049
|
POLICY_ENGINE_RESOLVE_REQUEST_SCHEMA,
|
|
16267
17050
|
POLICY_SCHEMA,
|
|
17051
|
+
POLICY_SESSION_UCAN_V1_PROFILE,
|
|
16268
17052
|
POLICY_STATUS_SCHEMA,
|
|
17053
|
+
POLICY_V1_DOMAIN,
|
|
17054
|
+
POLICY_V1_SCHEMA,
|
|
16269
17055
|
PORTABLE_DELEGATION_SCHEMA,
|
|
16270
17056
|
PermissionNotInManifestError,
|
|
16271
17057
|
PrefixedKVService,
|
|
@@ -16273,6 +17059,11 @@ export {
|
|
|
16273
17059
|
REQUESTER_ENGINE_RETRY_ATTEMPTS,
|
|
16274
17060
|
REQUESTER_ENGINE_RETRY_MAX_DELAY_MS,
|
|
16275
17061
|
REQUESTER_NEAR_EXPIRY_SECONDS,
|
|
17062
|
+
ROOT_REVOCATION_V1_DOMAIN,
|
|
17063
|
+
ROOT_REVOCATION_V1_SCHEMA,
|
|
17064
|
+
ROOT_STATUS_CHECKPOINT_V1_SCHEMA,
|
|
17065
|
+
ROOT_STATUS_RENEWAL_V1_DOMAIN,
|
|
17066
|
+
ROOT_STATUS_V1_DOMAIN,
|
|
16276
17067
|
SECRETS_SPACE,
|
|
16277
17068
|
SECRET_NAME_RE2 as SECRET_NAME_RE,
|
|
16278
17069
|
SECRET_RECORDS_SCHEMA,
|
|
@@ -16350,13 +17141,16 @@ export {
|
|
|
16350
17141
|
canonicalizeRecapCaveats,
|
|
16351
17142
|
canonicalizeSecretScope,
|
|
16352
17143
|
canonicalizeSignedObjectUnsigned,
|
|
17144
|
+
canonicalizeUnifiedPolicyCapability,
|
|
16353
17145
|
checkDecryptInvocationInput,
|
|
16354
17146
|
checkNodeInfo,
|
|
16355
17147
|
clearTinyCloudDebugLogs,
|
|
17148
|
+
compactAttenuationContains,
|
|
16356
17149
|
composeBootstrapSpaceManifest,
|
|
16357
17150
|
composeManifestRequest,
|
|
16358
17151
|
computeOwnerShareRegistrationCid,
|
|
16359
17152
|
computeShareCid,
|
|
17153
|
+
contentSourceDigestHex,
|
|
16360
17154
|
createAndSignPolicy,
|
|
16361
17155
|
createAndSignPolicyEngineRecord,
|
|
16362
17156
|
createAndSignPolicyStatus,
|
|
@@ -16379,6 +17173,7 @@ export {
|
|
|
16379
17173
|
defaultRetryPolicy2 as defaultRetryPolicy,
|
|
16380
17174
|
defaultSignStrategy,
|
|
16381
17175
|
defaultSpaceCreationHandler,
|
|
17176
|
+
delegatePortablePolicySession,
|
|
16382
17177
|
deriveDelegationCid,
|
|
16383
17178
|
deriveSignedObjectMaterial,
|
|
16384
17179
|
deriveSignedReceiverKey,
|
|
@@ -16410,10 +17205,12 @@ export {
|
|
|
16410
17205
|
fetchLocationRecord,
|
|
16411
17206
|
fetchPeerId,
|
|
16412
17207
|
generateRandomReceiverKey,
|
|
17208
|
+
getPolicyRootStatusV3,
|
|
16413
17209
|
getTinyCloudDebugLogs,
|
|
16414
17210
|
hexDecode,
|
|
16415
17211
|
hexEncode,
|
|
16416
17212
|
httpUrlToMultiaddr,
|
|
17213
|
+
importPortableDelegation,
|
|
16417
17214
|
installTinyCloudDebugGlobals,
|
|
16418
17215
|
intersectShareCapabilities,
|
|
16419
17216
|
isCapabilitySubset,
|
|
@@ -16434,22 +17231,32 @@ export {
|
|
|
16434
17231
|
normalizeShareActions,
|
|
16435
17232
|
normalizeShareRecipientTarget,
|
|
16436
17233
|
normalizeShareResource,
|
|
17234
|
+
normalizeUnifiedPolicyCapability,
|
|
16437
17235
|
ok5 as ok,
|
|
16438
17236
|
openWrappedKey,
|
|
16439
17237
|
parseCanonicalNetworkId,
|
|
16440
17238
|
parseCanonicalRecapResource,
|
|
17239
|
+
parseCompactUcanAuthorization,
|
|
16441
17240
|
parseExpiry,
|
|
16442
17241
|
parseNetworkId2 as parseNetworkId,
|
|
16443
17242
|
parseNodeNativePortableDelegation,
|
|
16444
17243
|
parsePkhDid,
|
|
17244
|
+
parsePolicySessionUcan,
|
|
17245
|
+
parsePortableDelegation,
|
|
16445
17246
|
parseRecapCapabilities,
|
|
16446
17247
|
parseShareArtifact,
|
|
16447
17248
|
parseShareUrl,
|
|
16448
17249
|
parseSpaceUri,
|
|
16449
17250
|
pkhDid,
|
|
17251
|
+
policyCidFromCanonicalBytes,
|
|
17252
|
+
policyDigestHex,
|
|
17253
|
+
policyIdForDigestHex,
|
|
16450
17254
|
principalDid,
|
|
16451
17255
|
principalDidEquals,
|
|
17256
|
+
projectUnifiedPolicyCapabilities,
|
|
17257
|
+
projectUnifiedPolicyCapability,
|
|
16452
17258
|
recapCaveatsEqual,
|
|
17259
|
+
renewPolicyRootStatusV3,
|
|
16453
17260
|
resolveCloudLocation,
|
|
16454
17261
|
resolveManifest,
|
|
16455
17262
|
resolveManifestKnowledgeRoot,
|
|
@@ -16459,10 +17266,13 @@ export {
|
|
|
16459
17266
|
resourceCapabilitiesToAbilitiesMap,
|
|
16460
17267
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
16461
17268
|
restoreDelegatedShareKey,
|
|
17269
|
+
revokePolicyRootV3,
|
|
16462
17270
|
serialize as serializeJcsJson,
|
|
17271
|
+
serializePortableDelegation,
|
|
16463
17272
|
serviceError5 as serviceError,
|
|
16464
17273
|
shareCapabilityAllows,
|
|
16465
17274
|
shareDeliveryTrustedKid,
|
|
17275
|
+
signCompactUcanAuthorization,
|
|
16466
17276
|
signLocationRecord,
|
|
16467
17277
|
signShareEnvelope,
|
|
16468
17278
|
signedObjectIdFor,
|
|
@@ -16470,6 +17280,10 @@ export {
|
|
|
16470
17280
|
tinyCloudDebugLogger,
|
|
16471
17281
|
toSignedObjectError,
|
|
16472
17282
|
unauthorizedRecapCapabilities,
|
|
17283
|
+
unifiedNativeProjectionHashHex,
|
|
17284
|
+
unifiedPolicyCapabilityContains,
|
|
17285
|
+
unifiedPolicyCapabilityDigestHex,
|
|
17286
|
+
unifiedPolicyCapabilityFromNative,
|
|
16473
17287
|
validateAuthorizationResultV1,
|
|
16474
17288
|
validateClientSession,
|
|
16475
17289
|
validateEnvelope,
|
|
@@ -16494,6 +17308,8 @@ export {
|
|
|
16494
17308
|
verifyLocationRecord,
|
|
16495
17309
|
verifyPolicy,
|
|
16496
17310
|
verifyPolicyEngineRecord,
|
|
17311
|
+
verifyPolicyRootRevocationV3,
|
|
17312
|
+
verifyPolicyRootStatusCheckpointV3,
|
|
16497
17313
|
verifyPolicyStatus,
|
|
16498
17314
|
verifyShareCid,
|
|
16499
17315
|
verifyShareEnvelope,
|