@tinycloud/sdk-core 3.0.0-beta.5 → 3.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/delegations/index.cjs +106 -13
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +2 -2
- package/dist/delegations/index.d.ts +2 -2
- package/dist/delegations/index.js +106 -13
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +278 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +278 -185
- package/dist/index.js.map +1 -1
- package/dist/{recipient-types.schema-G8NEKRoo.d.cts → recipient-types.schema-BdCeDExl.d.cts} +64 -1
- package/dist/{recipient-types.schema-G8NEKRoo.d.ts → recipient-types.schema-BdCeDExl.d.ts} +64 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1790,16 +1790,16 @@ function policyCapabilityContains(authority, request) {
|
|
|
1790
1790
|
return caveatsContain(auth.caveats, req.caveats);
|
|
1791
1791
|
}
|
|
1792
1792
|
function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
1793
|
-
const
|
|
1794
|
-
assertExactKeys(
|
|
1795
|
-
const service = requiredString(
|
|
1793
|
+
const object4 = expectObject(input, "$");
|
|
1794
|
+
assertExactKeys(object4, ["service", "space", "path", "actions", "caveats"], "$");
|
|
1795
|
+
const service = requiredString(object4, "service", "$", "policy-capability-malformed-service");
|
|
1796
1796
|
if (!CEILING_SERVICES.has(service)) {
|
|
1797
1797
|
throw new PolicyCapabilityError(
|
|
1798
1798
|
"policy-capability-malformed-service",
|
|
1799
1799
|
"$.service is outside the frozen permissionsCeiling vocabulary"
|
|
1800
1800
|
);
|
|
1801
1801
|
}
|
|
1802
|
-
const space = requiredString(
|
|
1802
|
+
const space = requiredString(object4, "space", "$", "policy-capability-malformed-space");
|
|
1803
1803
|
validateConcreteSpace(space);
|
|
1804
1804
|
const canonicalSpace = space.normalize("NFC");
|
|
1805
1805
|
if (options2.requireCanonical && canonicalSpace !== space) {
|
|
@@ -1808,7 +1808,7 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1808
1808
|
"$.space must already be canonical NFC"
|
|
1809
1809
|
);
|
|
1810
1810
|
}
|
|
1811
|
-
const rawPath = requiredString(
|
|
1811
|
+
const rawPath = requiredString(object4, "path", "$", "policy-capability-malformed-path");
|
|
1812
1812
|
validateRawPath(rawPath, options2);
|
|
1813
1813
|
const path = normalizePath(rawPath);
|
|
1814
1814
|
if (options2.requireCanonical && path !== rawPath) {
|
|
@@ -1819,7 +1819,7 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1819
1819
|
}
|
|
1820
1820
|
validateRawPath(path, options2);
|
|
1821
1821
|
const actions = normalizeActions(
|
|
1822
|
-
requiredArray(
|
|
1822
|
+
requiredArray(object4, "actions", "$", "policy-capability-malformed-action"),
|
|
1823
1823
|
service,
|
|
1824
1824
|
options2
|
|
1825
1825
|
);
|
|
@@ -1828,9 +1828,9 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1828
1828
|
output.space = canonicalSpace;
|
|
1829
1829
|
output.path = path;
|
|
1830
1830
|
output.actions = actions;
|
|
1831
|
-
if (hasOwn(
|
|
1831
|
+
if (hasOwn(object4, "caveats")) {
|
|
1832
1832
|
output.caveats = validateCaveats(
|
|
1833
|
-
requiredValue(
|
|
1833
|
+
requiredValue(object4, "caveats", "$", "policy-capability-malformed-caveats"),
|
|
1834
1834
|
output.service
|
|
1835
1835
|
);
|
|
1836
1836
|
}
|
|
@@ -1853,9 +1853,9 @@ function expectObject(input, path) {
|
|
|
1853
1853
|
);
|
|
1854
1854
|
}
|
|
1855
1855
|
}
|
|
1856
|
-
function assertExactKeys(
|
|
1856
|
+
function assertExactKeys(object4, allowed, path) {
|
|
1857
1857
|
const allowedSet = new Set(allowed);
|
|
1858
|
-
for (const key of Object.keys(
|
|
1858
|
+
for (const key of Object.keys(object4)) {
|
|
1859
1859
|
if (!allowedSet.has(key)) {
|
|
1860
1860
|
throw new PolicyCapabilityError(
|
|
1861
1861
|
key === "id" || key === "scope" ? "policy-capability-malformed" : "policy-capability-unknown-key",
|
|
@@ -1864,21 +1864,21 @@ function assertExactKeys(object3, allowed, path) {
|
|
|
1864
1864
|
}
|
|
1865
1865
|
}
|
|
1866
1866
|
}
|
|
1867
|
-
function requiredValue(
|
|
1868
|
-
if (!hasOwn(
|
|
1867
|
+
function requiredValue(object4, key, path, code3) {
|
|
1868
|
+
if (!hasOwn(object4, key)) {
|
|
1869
1869
|
throw new PolicyCapabilityError(code3, `${path}.${key} is required`);
|
|
1870
1870
|
}
|
|
1871
|
-
return
|
|
1871
|
+
return object4[key];
|
|
1872
1872
|
}
|
|
1873
|
-
function requiredString(
|
|
1874
|
-
const value = requiredValue(
|
|
1873
|
+
function requiredString(object4, key, path, code3) {
|
|
1874
|
+
const value = requiredValue(object4, key, path, code3);
|
|
1875
1875
|
if (typeof value !== "string" || value.length === 0) {
|
|
1876
1876
|
throw new PolicyCapabilityError(code3, `${path}.${key} must be a non-empty string`);
|
|
1877
1877
|
}
|
|
1878
1878
|
return value;
|
|
1879
1879
|
}
|
|
1880
|
-
function requiredArray(
|
|
1881
|
-
const value = requiredValue(
|
|
1880
|
+
function requiredArray(object4, key, path, code3) {
|
|
1881
|
+
const value = requiredValue(object4, key, path, code3);
|
|
1882
1882
|
if (!Array.isArray(value)) {
|
|
1883
1883
|
throw new PolicyCapabilityError(code3, `${path}.${key} must be an array`);
|
|
1884
1884
|
}
|
|
@@ -2023,11 +2023,11 @@ function validateSqlStatement(input, path) {
|
|
|
2023
2023
|
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
2024
2024
|
throw new PolicyCapabilityError("policy-capability-malformed-caveats", `${path} must be an object`);
|
|
2025
2025
|
}
|
|
2026
|
-
const
|
|
2027
|
-
assertCaveatKeys(
|
|
2028
|
-
caveatString(
|
|
2029
|
-
caveatString(
|
|
2030
|
-
const fixedParams = requiredCaveat(
|
|
2026
|
+
const object4 = input;
|
|
2027
|
+
assertCaveatKeys(object4, ["name", "sql", "fixedParams"], path);
|
|
2028
|
+
caveatString(object4, "name", path);
|
|
2029
|
+
caveatString(object4, "sql", path);
|
|
2030
|
+
const fixedParams = requiredCaveat(object4, "fixedParams", path);
|
|
2031
2031
|
if (!Array.isArray(fixedParams)) {
|
|
2032
2032
|
throw new PolicyCapabilityError(
|
|
2033
2033
|
"policy-capability-malformed-caveats",
|
|
@@ -2042,20 +2042,20 @@ function validateFixedParam(input, path) {
|
|
|
2042
2042
|
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
2043
2043
|
throw new PolicyCapabilityError("policy-capability-malformed-caveats", `${path} must be an object`);
|
|
2044
2044
|
}
|
|
2045
|
-
const
|
|
2046
|
-
assertCaveatKeys(
|
|
2047
|
-
const index = requiredCaveat(
|
|
2045
|
+
const object4 = input;
|
|
2046
|
+
assertCaveatKeys(object4, ["index", "value"], path);
|
|
2047
|
+
const index = requiredCaveat(object4, "index", path);
|
|
2048
2048
|
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) {
|
|
2049
2049
|
throw new PolicyCapabilityError(
|
|
2050
2050
|
"policy-capability-malformed-caveats",
|
|
2051
2051
|
`${path}.index must be a non-negative integer`
|
|
2052
2052
|
);
|
|
2053
2053
|
}
|
|
2054
|
-
requiredCaveat(
|
|
2054
|
+
requiredCaveat(object4, "value", path);
|
|
2055
2055
|
}
|
|
2056
|
-
function assertCaveatKeys(
|
|
2056
|
+
function assertCaveatKeys(object4, allowed, path) {
|
|
2057
2057
|
const allowedSet = new Set(allowed);
|
|
2058
|
-
for (const key of Object.keys(
|
|
2058
|
+
for (const key of Object.keys(object4)) {
|
|
2059
2059
|
if (!allowedSet.has(key)) {
|
|
2060
2060
|
throw new PolicyCapabilityError(
|
|
2061
2061
|
"policy-capability-malformed-caveats",
|
|
@@ -2064,17 +2064,17 @@ function assertCaveatKeys(object3, allowed, path) {
|
|
|
2064
2064
|
}
|
|
2065
2065
|
}
|
|
2066
2066
|
}
|
|
2067
|
-
function requiredCaveat(
|
|
2068
|
-
if (!hasOwn(
|
|
2067
|
+
function requiredCaveat(object4, key, path) {
|
|
2068
|
+
if (!hasOwn(object4, key)) {
|
|
2069
2069
|
throw new PolicyCapabilityError(
|
|
2070
2070
|
"policy-capability-malformed-caveats",
|
|
2071
2071
|
`${path}.${key} is required`
|
|
2072
2072
|
);
|
|
2073
2073
|
}
|
|
2074
|
-
return
|
|
2074
|
+
return object4[key];
|
|
2075
2075
|
}
|
|
2076
|
-
function caveatString(
|
|
2077
|
-
const value = requiredCaveat(
|
|
2076
|
+
function caveatString(object4, key, path) {
|
|
2077
|
+
const value = requiredCaveat(object4, key, path);
|
|
2078
2078
|
if (typeof value !== "string" || value.length === 0) {
|
|
2079
2079
|
throw new PolicyCapabilityError(
|
|
2080
2080
|
"policy-capability-malformed-caveats",
|
|
@@ -2105,8 +2105,8 @@ function caveatsContain(authority, request) {
|
|
|
2105
2105
|
(statement) => authorityStatements.some((candidate) => jcsCanonicalize(candidate) === jcsCanonicalize(statement))
|
|
2106
2106
|
);
|
|
2107
2107
|
}
|
|
2108
|
-
function hasOwn(
|
|
2109
|
-
return objectHasOwn2(
|
|
2108
|
+
function hasOwn(object4, key) {
|
|
2109
|
+
return objectHasOwn2(object4, key);
|
|
2110
2110
|
}
|
|
2111
2111
|
|
|
2112
2112
|
// src/policy/signed-object.ts
|
|
@@ -2434,17 +2434,17 @@ async function createAndSignSignedObject(input, signer) {
|
|
|
2434
2434
|
}
|
|
2435
2435
|
function createAndSignPolicy(input, signer) {
|
|
2436
2436
|
return createAndSignSignedObject(input, signer).then(
|
|
2437
|
-
(
|
|
2437
|
+
(object4) => validatePolicySignedShape(object4)
|
|
2438
2438
|
);
|
|
2439
2439
|
}
|
|
2440
2440
|
function createAndSignPolicyStatus(input, signer) {
|
|
2441
2441
|
return createAndSignSignedObject(input, signer).then(
|
|
2442
|
-
(
|
|
2442
|
+
(object4) => validatePolicyStatusSignedShape(object4)
|
|
2443
2443
|
);
|
|
2444
2444
|
}
|
|
2445
2445
|
function createAndSignPolicyEngineRecord(input, signer) {
|
|
2446
2446
|
return createAndSignSignedObject(input, signer).then(
|
|
2447
|
-
(
|
|
2447
|
+
(object4) => validatePolicyEngineRecordSignedShape(object4)
|
|
2448
2448
|
);
|
|
2449
2449
|
}
|
|
2450
2450
|
async function verifySignedObject(input) {
|
|
@@ -2548,9 +2548,9 @@ function validateUnsignedForDescriptor(input, descriptor) {
|
|
|
2548
2548
|
}
|
|
2549
2549
|
}
|
|
2550
2550
|
function validatePolicyShape(input, signed) {
|
|
2551
|
-
const
|
|
2551
|
+
const object4 = expectJsonObject(normalizeJson(input), "$");
|
|
2552
2552
|
assertExactKeys2(
|
|
2553
|
-
|
|
2553
|
+
object4,
|
|
2554
2554
|
signed ? [
|
|
2555
2555
|
"schema",
|
|
2556
2556
|
"policyId",
|
|
@@ -2578,30 +2578,30 @@ function validatePolicyShape(input, signed) {
|
|
|
2578
2578
|
],
|
|
2579
2579
|
"$"
|
|
2580
2580
|
);
|
|
2581
|
-
expectConst(requiredString2(
|
|
2581
|
+
expectConst(requiredString2(object4, "schema", "$"), POLICY_SCHEMA, "$.schema");
|
|
2582
2582
|
if (signed) {
|
|
2583
|
-
requiredString2(
|
|
2584
|
-
validateSignature(requiredValue2(
|
|
2583
|
+
requiredString2(object4, "policyId", "$");
|
|
2584
|
+
validateSignature(requiredValue2(object4, "signature", "$"));
|
|
2585
2585
|
}
|
|
2586
|
-
requiredString2(
|
|
2587
|
-
requiredString2(
|
|
2588
|
-
requiredDateString(
|
|
2589
|
-
optionalDateString(
|
|
2590
|
-
validatePolicyResource(requiredValue2(
|
|
2591
|
-
validateExpression(requiredValue2(
|
|
2592
|
-
validateGrant(requiredValue2(
|
|
2593
|
-
if (hasOwn2(
|
|
2594
|
-
validateDisclosure(requiredValue2(
|
|
2586
|
+
requiredString2(object4, "ownerDid", "$");
|
|
2587
|
+
requiredString2(object4, "signingKeyDid", "$");
|
|
2588
|
+
requiredDateString(object4, "createdAt", "$");
|
|
2589
|
+
optionalDateString(object4, "expiresAt", "$");
|
|
2590
|
+
validatePolicyResource(requiredValue2(object4, "resource", "$"), "$.resource");
|
|
2591
|
+
validateExpression(requiredValue2(object4, "when", "$"), "$.when");
|
|
2592
|
+
validateGrant(requiredValue2(object4, "grant", "$"), "$.grant");
|
|
2593
|
+
if (hasOwn2(object4, "disclosure")) {
|
|
2594
|
+
validateDisclosure(requiredValue2(object4, "disclosure", "$"), "$.disclosure");
|
|
2595
2595
|
}
|
|
2596
|
-
if (hasOwn2(
|
|
2597
|
-
validateAudit(requiredValue2(
|
|
2596
|
+
if (hasOwn2(object4, "audit")) {
|
|
2597
|
+
validateAudit(requiredValue2(object4, "audit", "$"), "$.audit");
|
|
2598
2598
|
}
|
|
2599
|
-
return
|
|
2599
|
+
return object4;
|
|
2600
2600
|
}
|
|
2601
2601
|
function validatePolicyStatusShape(input, signed) {
|
|
2602
|
-
const
|
|
2602
|
+
const object4 = expectJsonObject(normalizeJson(input), "$");
|
|
2603
2603
|
assertExactKeys2(
|
|
2604
|
-
|
|
2604
|
+
object4,
|
|
2605
2605
|
signed ? [
|
|
2606
2606
|
"schema",
|
|
2607
2607
|
"statusId",
|
|
@@ -2625,28 +2625,28 @@ function validatePolicyStatusShape(input, signed) {
|
|
|
2625
2625
|
],
|
|
2626
2626
|
"$"
|
|
2627
2627
|
);
|
|
2628
|
-
expectConst(requiredString2(
|
|
2628
|
+
expectConst(requiredString2(object4, "schema", "$"), POLICY_STATUS_SCHEMA, "$.schema");
|
|
2629
2629
|
if (signed) {
|
|
2630
|
-
requiredString2(
|
|
2631
|
-
validateSignature(requiredValue2(
|
|
2630
|
+
requiredString2(object4, "statusId", "$");
|
|
2631
|
+
validateSignature(requiredValue2(object4, "signature", "$"));
|
|
2632
2632
|
}
|
|
2633
|
-
requiredString2(
|
|
2634
|
-
requiredString2(
|
|
2635
|
-
requiredInteger(
|
|
2636
|
-
expectOneOf(requiredString2(
|
|
2633
|
+
requiredString2(object4, "policyId", "$");
|
|
2634
|
+
requiredString2(object4, "ownerDid", "$");
|
|
2635
|
+
requiredInteger(object4, "sequence", "$", 0);
|
|
2636
|
+
expectOneOf(requiredString2(object4, "disposition", "$"), [
|
|
2637
2637
|
"active",
|
|
2638
2638
|
"suspended",
|
|
2639
2639
|
"revoked"
|
|
2640
2640
|
], "$.disposition");
|
|
2641
|
-
requiredDateString(
|
|
2642
|
-
optionalString(
|
|
2643
|
-
requiredString2(
|
|
2644
|
-
return
|
|
2641
|
+
requiredDateString(object4, "effectiveAt", "$");
|
|
2642
|
+
optionalString(object4, "reasonCode", "$");
|
|
2643
|
+
requiredString2(object4, "signingKeyDid", "$");
|
|
2644
|
+
return object4;
|
|
2645
2645
|
}
|
|
2646
2646
|
function validatePolicyEngineRecordShape(input, signed) {
|
|
2647
|
-
const
|
|
2647
|
+
const object4 = expectJsonObject(normalizeJson(input), "$");
|
|
2648
2648
|
assertExactKeys2(
|
|
2649
|
-
|
|
2649
|
+
object4,
|
|
2650
2650
|
signed ? [
|
|
2651
2651
|
"schema",
|
|
2652
2652
|
"engineRecordId",
|
|
@@ -2671,44 +2671,44 @@ function validatePolicyEngineRecordShape(input, signed) {
|
|
|
2671
2671
|
"$"
|
|
2672
2672
|
);
|
|
2673
2673
|
expectConst(
|
|
2674
|
-
requiredString2(
|
|
2674
|
+
requiredString2(object4, "schema", "$"),
|
|
2675
2675
|
POLICY_ENGINE_RECORD_SCHEMA,
|
|
2676
2676
|
"$.schema"
|
|
2677
2677
|
);
|
|
2678
2678
|
if (signed) {
|
|
2679
|
-
requiredString2(
|
|
2680
|
-
validateSignature(requiredValue2(
|
|
2679
|
+
requiredString2(object4, "engineRecordId", "$");
|
|
2680
|
+
validateSignature(requiredValue2(object4, "signature", "$"));
|
|
2681
2681
|
}
|
|
2682
|
-
requiredString2(
|
|
2683
|
-
requiredString2(
|
|
2684
|
-
requiredString2(
|
|
2682
|
+
requiredString2(object4, "ownerDid", "$");
|
|
2683
|
+
requiredString2(object4, "endpoint", "$");
|
|
2684
|
+
requiredString2(object4, "audience", "$");
|
|
2685
2685
|
requiredStringArray(
|
|
2686
|
-
|
|
2686
|
+
object4,
|
|
2687
2687
|
"supportedPolicyVersions",
|
|
2688
2688
|
"$",
|
|
2689
2689
|
(value, path) => expectConst(value, "v0", path)
|
|
2690
2690
|
);
|
|
2691
|
-
requiredStringArray(
|
|
2692
|
-
requiredString2(
|
|
2693
|
-
requiredDateString(
|
|
2694
|
-
return
|
|
2691
|
+
requiredStringArray(object4, "supportedEvidenceVerifiers", "$");
|
|
2692
|
+
requiredString2(object4, "grantIssuerDid", "$");
|
|
2693
|
+
requiredDateString(object4, "expiresAt", "$");
|
|
2694
|
+
return object4;
|
|
2695
2695
|
}
|
|
2696
2696
|
function validateSignature(input) {
|
|
2697
|
-
const
|
|
2698
|
-
assertExactKeys2(
|
|
2699
|
-
const suite = requiredString2(
|
|
2697
|
+
const object4 = expectJsonObject(input, "$.signature");
|
|
2698
|
+
assertExactKeys2(object4, ["suite", "signerDid", "value"], "$.signature");
|
|
2699
|
+
const suite = requiredString2(object4, "suite", "$.signature");
|
|
2700
2700
|
assertSupportedSignatureSuite(suite);
|
|
2701
|
-
const signerDid = requiredString2(
|
|
2702
|
-
const value = requiredString2(
|
|
2701
|
+
const signerDid = requiredString2(object4, "signerDid", "$.signature");
|
|
2702
|
+
const value = requiredString2(object4, "value", "$.signature");
|
|
2703
2703
|
decodeSignatureValue(value, suite);
|
|
2704
2704
|
return { suite, signerDid, value };
|
|
2705
2705
|
}
|
|
2706
2706
|
function validatePolicyResource(input, path) {
|
|
2707
|
-
const
|
|
2708
|
-
assertExactKeys2(
|
|
2709
|
-
requiredString2(
|
|
2710
|
-
requiredString2(
|
|
2711
|
-
const ceiling = requiredArray2(
|
|
2707
|
+
const object4 = expectJsonObject(input, path);
|
|
2708
|
+
assertExactKeys2(object4, ["resourceType", "resourceId", "permissionsCeiling"], path);
|
|
2709
|
+
requiredString2(object4, "resourceType", path);
|
|
2710
|
+
requiredString2(object4, "resourceId", path);
|
|
2711
|
+
const ceiling = requiredArray2(object4, "permissionsCeiling", path, 1);
|
|
2712
2712
|
for (let index = 0; index < ceiling.length; index++) {
|
|
2713
2713
|
validatePolicyCapability(ceiling[index], `${path}.permissionsCeiling[${index}]`);
|
|
2714
2714
|
}
|
|
@@ -2724,10 +2724,10 @@ function validatePolicyPermissionsCeilingForSigning(input) {
|
|
|
2724
2724
|
}
|
|
2725
2725
|
}
|
|
2726
2726
|
function validatePolicyCapability(input, path) {
|
|
2727
|
-
const
|
|
2727
|
+
const object4 = expectJsonObject(input, path);
|
|
2728
2728
|
try {
|
|
2729
|
-
const canonical = canonicalizePolicyCapability(
|
|
2730
|
-
if (jcsCanonicalize(
|
|
2729
|
+
const canonical = canonicalizePolicyCapability(object4);
|
|
2730
|
+
if (jcsCanonicalize(object4) !== jcsCanonicalize(canonical)) {
|
|
2731
2731
|
throw new SignedObjectSchemaError(`${path} must be canonical PolicyCapability JSON`);
|
|
2732
2732
|
}
|
|
2733
2733
|
} catch (error) {
|
|
@@ -2740,10 +2740,10 @@ function validatePolicyCapability(input, path) {
|
|
|
2740
2740
|
}
|
|
2741
2741
|
}
|
|
2742
2742
|
function validatePolicyCapabilityForSigning(input, path) {
|
|
2743
|
-
const
|
|
2743
|
+
const object4 = expectJsonObject(input, path);
|
|
2744
2744
|
try {
|
|
2745
|
-
const canonical = normalizePolicyCapability(
|
|
2746
|
-
if (jcsCanonicalize(
|
|
2745
|
+
const canonical = normalizePolicyCapability(object4);
|
|
2746
|
+
if (jcsCanonicalize(object4) !== jcsCanonicalize(canonical)) {
|
|
2747
2747
|
throw new SignedObjectSchemaError(`${path} must be strict canonical PolicyCapability JSON`);
|
|
2748
2748
|
}
|
|
2749
2749
|
} catch (error) {
|
|
@@ -2756,43 +2756,43 @@ function validatePolicyCapabilityForSigning(input, path) {
|
|
|
2756
2756
|
}
|
|
2757
2757
|
}
|
|
2758
2758
|
function validateExpression(input, path) {
|
|
2759
|
-
const
|
|
2760
|
-
const keys = Object.keys(
|
|
2759
|
+
const object4 = expectJsonObject(input, path);
|
|
2760
|
+
const keys = Object.keys(object4);
|
|
2761
2761
|
if (keys.length !== 1) {
|
|
2762
2762
|
throw new SignedObjectSchemaError(`${path} must have exactly one expression key`);
|
|
2763
2763
|
}
|
|
2764
2764
|
const key = keys[0];
|
|
2765
2765
|
if (key === "allOf" || key === "anyOf") {
|
|
2766
|
-
const values = requiredArray2(
|
|
2766
|
+
const values = requiredArray2(object4, key, path, 1);
|
|
2767
2767
|
for (let index = 0; index < values.length; index++) {
|
|
2768
2768
|
validateExpression(values[index], `${path}.${key}[${index}]`);
|
|
2769
2769
|
}
|
|
2770
2770
|
return;
|
|
2771
2771
|
}
|
|
2772
2772
|
if (key === "subject") {
|
|
2773
|
-
const subject = expectJsonObject(requiredValue2(
|
|
2773
|
+
const subject = expectJsonObject(requiredValue2(object4, "subject", path), `${path}.subject`);
|
|
2774
2774
|
assertExactKeys2(subject, ["did"], `${path}.subject`);
|
|
2775
2775
|
requiredString2(subject, "did", `${path}.subject`);
|
|
2776
2776
|
return;
|
|
2777
2777
|
}
|
|
2778
2778
|
if (key === "evidence") {
|
|
2779
|
-
validateEvidenceRequirement(requiredValue2(
|
|
2779
|
+
validateEvidenceRequirement(requiredValue2(object4, "evidence", path), `${path}.evidence`);
|
|
2780
2780
|
return;
|
|
2781
2781
|
}
|
|
2782
2782
|
throw new SignedObjectSchemaError(`${path} has unknown expression key ${key}`);
|
|
2783
2783
|
}
|
|
2784
2784
|
function validateEvidenceRequirement(input, path) {
|
|
2785
|
-
const
|
|
2785
|
+
const object4 = expectJsonObject(input, path);
|
|
2786
2786
|
assertExactKeys2(
|
|
2787
|
-
|
|
2787
|
+
object4,
|
|
2788
2788
|
["requirementId", "verifier", "requirements", "authority", "freshness"],
|
|
2789
2789
|
path
|
|
2790
2790
|
);
|
|
2791
|
-
requiredString2(
|
|
2792
|
-
requiredString2(
|
|
2793
|
-
requiredValue2(
|
|
2794
|
-
if (hasOwn2(
|
|
2795
|
-
const authority = expectJsonObject(requiredValue2(
|
|
2791
|
+
requiredString2(object4, "requirementId", path);
|
|
2792
|
+
requiredString2(object4, "verifier", path);
|
|
2793
|
+
requiredValue2(object4, "requirements", path);
|
|
2794
|
+
if (hasOwn2(object4, "authority")) {
|
|
2795
|
+
const authority = expectJsonObject(requiredValue2(object4, "authority", path), `${path}.authority`);
|
|
2796
2796
|
assertExactKeys2(
|
|
2797
2797
|
authority,
|
|
2798
2798
|
["profile", "acceptedIssuers", "allowOwnerAuthorizedIssuer"],
|
|
@@ -2804,35 +2804,35 @@ function validateEvidenceRequirement(input, path) {
|
|
|
2804
2804
|
}
|
|
2805
2805
|
optionalBoolean(authority, "allowOwnerAuthorizedIssuer", `${path}.authority`);
|
|
2806
2806
|
}
|
|
2807
|
-
if (hasOwn2(
|
|
2808
|
-
const freshness = expectJsonObject(requiredValue2(
|
|
2807
|
+
if (hasOwn2(object4, "freshness")) {
|
|
2808
|
+
const freshness = expectJsonObject(requiredValue2(object4, "freshness", path), `${path}.freshness`);
|
|
2809
2809
|
assertExactKeys2(freshness, ["maxStatusAgeSeconds"], `${path}.freshness`);
|
|
2810
2810
|
requiredInteger(freshness, "maxStatusAgeSeconds", `${path}.freshness`, 0);
|
|
2811
2811
|
}
|
|
2812
2812
|
}
|
|
2813
2813
|
function validateGrant(input, path) {
|
|
2814
|
-
const
|
|
2815
|
-
assertExactKeys2(
|
|
2816
|
-
expectConst(requiredString2(
|
|
2817
|
-
requiredInteger(
|
|
2818
|
-
expectOneOf(requiredString2(
|
|
2814
|
+
const object4 = expectJsonObject(input, path);
|
|
2815
|
+
assertExactKeys2(object4, ["output", "maxTtlSeconds", "delegationMode", "revocation"], path);
|
|
2816
|
+
expectConst(requiredString2(object4, "output", path), "portable-delegation", `${path}.output`);
|
|
2817
|
+
requiredInteger(object4, "maxTtlSeconds", path, 1);
|
|
2818
|
+
expectOneOf(requiredString2(object4, "delegationMode", path), [
|
|
2819
2819
|
"terminal",
|
|
2820
2820
|
"attenuable"
|
|
2821
2821
|
], `${path}.delegationMode`);
|
|
2822
|
-
expectOneOf(requiredString2(
|
|
2822
|
+
expectOneOf(requiredString2(object4, "revocation", path), [
|
|
2823
2823
|
"refresh_only",
|
|
2824
2824
|
"active_cutoff"
|
|
2825
2825
|
], `${path}.revocation`);
|
|
2826
2826
|
}
|
|
2827
2827
|
function validateDisclosure(input, path) {
|
|
2828
|
-
const
|
|
2829
|
-
assertExactKeys2(
|
|
2830
|
-
expectOneOf(requiredString2(
|
|
2828
|
+
const object4 = expectJsonObject(input, path);
|
|
2829
|
+
assertExactKeys2(object4, ["denial"], path);
|
|
2830
|
+
expectOneOf(requiredString2(object4, "denial", path), ["none", "code", "debug"], `${path}.denial`);
|
|
2831
2831
|
}
|
|
2832
2832
|
function validateAudit(input, path) {
|
|
2833
|
-
const
|
|
2834
|
-
assertExactKeys2(
|
|
2835
|
-
expectOneOf(requiredString2(
|
|
2833
|
+
const object4 = expectJsonObject(input, path);
|
|
2834
|
+
assertExactKeys2(object4, ["issuance"], path);
|
|
2835
|
+
expectOneOf(requiredString2(object4, "issuance", path), ["off", "security", "full"], `${path}.issuance`);
|
|
2836
2836
|
}
|
|
2837
2837
|
function materialForUnsigned(unsigned, descriptor) {
|
|
2838
2838
|
const jcs = jcsCanonicalize(unsigned);
|
|
@@ -2981,9 +2981,9 @@ function encodeSignatureValue(value, suite) {
|
|
|
2981
2981
|
decodeSignatureValue(encoded, suite);
|
|
2982
2982
|
return encoded;
|
|
2983
2983
|
}
|
|
2984
|
-
function stripOwnIdAndSignature(
|
|
2984
|
+
function stripOwnIdAndSignature(object4, descriptor) {
|
|
2985
2985
|
const output = /* @__PURE__ */ Object.create(null);
|
|
2986
|
-
for (const [key, value] of Object.entries(
|
|
2986
|
+
for (const [key, value] of Object.entries(object4)) {
|
|
2987
2987
|
if (key === descriptor.idField || key === "signature") {
|
|
2988
2988
|
continue;
|
|
2989
2989
|
}
|
|
@@ -2992,8 +2992,8 @@ function stripOwnIdAndSignature(object3, descriptor) {
|
|
|
2992
2992
|
return output;
|
|
2993
2993
|
}
|
|
2994
2994
|
function descriptorForUnsigned(input) {
|
|
2995
|
-
const
|
|
2996
|
-
return descriptorForSchema(requiredString2(
|
|
2995
|
+
const object4 = expectJsonObject(normalizeJson(input), "$");
|
|
2996
|
+
return descriptorForSchema(requiredString2(object4, "schema", "$"));
|
|
2997
2997
|
}
|
|
2998
2998
|
function descriptorForSchema(schema) {
|
|
2999
2999
|
if (schema === POLICY_SCHEMA) return DESCRIPTORS.Policy;
|
|
@@ -3007,28 +3007,28 @@ function expectJsonObject(input, path) {
|
|
|
3007
3007
|
}
|
|
3008
3008
|
return input;
|
|
3009
3009
|
}
|
|
3010
|
-
function assertExactKeys2(
|
|
3010
|
+
function assertExactKeys2(object4, allowed, path) {
|
|
3011
3011
|
const allowedSet = new Set(allowed);
|
|
3012
|
-
for (const key of Object.keys(
|
|
3012
|
+
for (const key of Object.keys(object4)) {
|
|
3013
3013
|
if (!allowedSet.has(key)) {
|
|
3014
3014
|
throw new SignedObjectSchemaError(`${path} has unknown field ${key}`);
|
|
3015
3015
|
}
|
|
3016
3016
|
}
|
|
3017
3017
|
}
|
|
3018
|
-
function requiredValue2(
|
|
3019
|
-
if (!hasOwn2(
|
|
3018
|
+
function requiredValue2(object4, key, path) {
|
|
3019
|
+
if (!hasOwn2(object4, key)) {
|
|
3020
3020
|
throw new SignedObjectSchemaError(`${path}.${key} is required`);
|
|
3021
3021
|
}
|
|
3022
|
-
return
|
|
3022
|
+
return object4[key];
|
|
3023
3023
|
}
|
|
3024
|
-
function requiredString2(
|
|
3025
|
-
return requireStringType(requiredValue2(
|
|
3024
|
+
function requiredString2(object4, key, path) {
|
|
3025
|
+
return requireStringType(requiredValue2(object4, key, path), `${path}.${key}`);
|
|
3026
3026
|
}
|
|
3027
|
-
function optionalString(
|
|
3028
|
-
if (!hasOwn2(
|
|
3027
|
+
function optionalString(object4, key, path) {
|
|
3028
|
+
if (!hasOwn2(object4, key)) {
|
|
3029
3029
|
return;
|
|
3030
3030
|
}
|
|
3031
|
-
requireStringType(requiredValue2(
|
|
3031
|
+
requireStringType(requiredValue2(object4, key, path), `${path}.${key}`);
|
|
3032
3032
|
}
|
|
3033
3033
|
function requireStringType(value, path) {
|
|
3034
3034
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -3036,16 +3036,16 @@ function requireStringType(value, path) {
|
|
|
3036
3036
|
}
|
|
3037
3037
|
return value;
|
|
3038
3038
|
}
|
|
3039
|
-
function optionalBoolean(
|
|
3040
|
-
if (!hasOwn2(
|
|
3039
|
+
function optionalBoolean(object4, key, path) {
|
|
3040
|
+
if (!hasOwn2(object4, key)) {
|
|
3041
3041
|
return;
|
|
3042
3042
|
}
|
|
3043
|
-
if (typeof requiredValue2(
|
|
3043
|
+
if (typeof requiredValue2(object4, key, path) !== "boolean") {
|
|
3044
3044
|
throw new SignedObjectSchemaError(`${path}.${key} must be a boolean`);
|
|
3045
3045
|
}
|
|
3046
3046
|
}
|
|
3047
|
-
function requiredInteger(
|
|
3048
|
-
const value = requiredValue2(
|
|
3047
|
+
function requiredInteger(object4, key, path, minimum) {
|
|
3048
|
+
const value = requiredValue2(object4, key, path);
|
|
3049
3049
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum) {
|
|
3050
3050
|
throw new SignedObjectSchemaError(
|
|
3051
3051
|
`${path}.${key} must be an integer >= ${minimum}`
|
|
@@ -3053,8 +3053,8 @@ function requiredInteger(object3, key, path, minimum) {
|
|
|
3053
3053
|
}
|
|
3054
3054
|
return value;
|
|
3055
3055
|
}
|
|
3056
|
-
function requiredArray2(
|
|
3057
|
-
const value = requiredValue2(
|
|
3056
|
+
function requiredArray2(object4, key, path, minimum) {
|
|
3057
|
+
const value = requiredValue2(object4, key, path);
|
|
3058
3058
|
if (!Array.isArray(value) || value.length < minimum) {
|
|
3059
3059
|
throw new SignedObjectSchemaError(
|
|
3060
3060
|
`${path}.${key} must be an array with at least ${minimum} item(s)`
|
|
@@ -3062,22 +3062,22 @@ function requiredArray2(object3, key, path, minimum) {
|
|
|
3062
3062
|
}
|
|
3063
3063
|
return value;
|
|
3064
3064
|
}
|
|
3065
|
-
function requiredStringArray(
|
|
3066
|
-
const values = requiredArray2(
|
|
3065
|
+
function requiredStringArray(object4, key, path, check) {
|
|
3066
|
+
const values = requiredArray2(object4, key, path, 0);
|
|
3067
3067
|
for (let index = 0; index < values.length; index++) {
|
|
3068
3068
|
const itemPath = `${path}.${key}[${index}]`;
|
|
3069
3069
|
const value = requireStringType(values[index], itemPath);
|
|
3070
3070
|
check?.(value, itemPath);
|
|
3071
3071
|
}
|
|
3072
3072
|
}
|
|
3073
|
-
function requiredDateString(
|
|
3074
|
-
assertRfc3339(requiredString2(
|
|
3073
|
+
function requiredDateString(object4, key, path) {
|
|
3074
|
+
assertRfc3339(requiredString2(object4, key, path), `${path}.${key}`);
|
|
3075
3075
|
}
|
|
3076
|
-
function optionalDateString(
|
|
3077
|
-
if (!hasOwn2(
|
|
3076
|
+
function optionalDateString(object4, key, path) {
|
|
3077
|
+
if (!hasOwn2(object4, key)) {
|
|
3078
3078
|
return;
|
|
3079
3079
|
}
|
|
3080
|
-
assertRfc3339(requiredString2(
|
|
3080
|
+
assertRfc3339(requiredString2(object4, key, path), `${path}.${key}`);
|
|
3081
3081
|
}
|
|
3082
3082
|
function assertRfc3339(value, path) {
|
|
3083
3083
|
const match = value.match(
|
|
@@ -3109,8 +3109,8 @@ function expectOneOf(actual, allowed, path) {
|
|
|
3109
3109
|
}
|
|
3110
3110
|
throw new SignedObjectSchemaError(`${path} has unsupported value ${actual}`);
|
|
3111
3111
|
}
|
|
3112
|
-
function hasOwn2(
|
|
3113
|
-
return objectHasOwn3(
|
|
3112
|
+
function hasOwn2(object4, key) {
|
|
3113
|
+
return objectHasOwn3(object4, key);
|
|
3114
3114
|
}
|
|
3115
3115
|
function assertSupportedSignatureSuite(suite) {
|
|
3116
3116
|
if (suite !== ED25519_JCS_SIGNATURE_SUITE && suite !== EIP191_JCS_SIGNATURE_SUITE) {
|
|
@@ -3337,9 +3337,9 @@ function expectObject2(input, path, code3) {
|
|
|
3337
3337
|
);
|
|
3338
3338
|
}
|
|
3339
3339
|
}
|
|
3340
|
-
function assertExactKeys3(
|
|
3340
|
+
function assertExactKeys3(object4, allowed, path) {
|
|
3341
3341
|
const allowedSet = new Set(allowed);
|
|
3342
|
-
for (const key of Object.keys(
|
|
3342
|
+
for (const key of Object.keys(object4)) {
|
|
3343
3343
|
if (!allowedSet.has(key)) {
|
|
3344
3344
|
throw new PolicyAuthoringError(
|
|
3345
3345
|
"policy-authoring-unknown-key",
|
|
@@ -3348,17 +3348,17 @@ function assertExactKeys3(object3, allowed, path) {
|
|
|
3348
3348
|
}
|
|
3349
3349
|
}
|
|
3350
3350
|
}
|
|
3351
|
-
function requiredValue3(
|
|
3352
|
-
if (!hasOwn3(
|
|
3351
|
+
function requiredValue3(object4, key, path) {
|
|
3352
|
+
if (!hasOwn3(object4, key)) {
|
|
3353
3353
|
throw new PolicyAuthoringError(
|
|
3354
3354
|
"policy-authoring-malformed",
|
|
3355
3355
|
`${path}.${key} is required`
|
|
3356
3356
|
);
|
|
3357
3357
|
}
|
|
3358
|
-
return
|
|
3358
|
+
return object4[key];
|
|
3359
3359
|
}
|
|
3360
|
-
function requiredString3(
|
|
3361
|
-
const value = requiredValue3(
|
|
3360
|
+
function requiredString3(object4, key, path) {
|
|
3361
|
+
const value = requiredValue3(object4, key, path);
|
|
3362
3362
|
if (typeof value !== "string" || value.length === 0) {
|
|
3363
3363
|
throw new PolicyAuthoringError(
|
|
3364
3364
|
"policy-authoring-malformed",
|
|
@@ -3367,11 +3367,11 @@ function requiredString3(object3, key, path) {
|
|
|
3367
3367
|
}
|
|
3368
3368
|
return value;
|
|
3369
3369
|
}
|
|
3370
|
-
function fieldString(
|
|
3371
|
-
if (!hasOwn3(
|
|
3370
|
+
function fieldString(object4, key, path, code3) {
|
|
3371
|
+
if (!hasOwn3(object4, key)) {
|
|
3372
3372
|
throw new PolicyAuthoringError(code3, `${path}.${key} is required`);
|
|
3373
3373
|
}
|
|
3374
|
-
const value =
|
|
3374
|
+
const value = object4[key];
|
|
3375
3375
|
if (typeof value !== "string" || value.length === 0) {
|
|
3376
3376
|
throw new PolicyAuthoringError(
|
|
3377
3377
|
code3,
|
|
@@ -3409,8 +3409,8 @@ function parseStrictRfc3339(value, path) {
|
|
|
3409
3409
|
var objectHasOwn4 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
|
|
3410
3410
|
Object.prototype.hasOwnProperty
|
|
3411
3411
|
);
|
|
3412
|
-
function hasOwn3(
|
|
3413
|
-
return objectHasOwn4(
|
|
3412
|
+
function hasOwn3(object4, key) {
|
|
3413
|
+
return objectHasOwn4(object4, key);
|
|
3414
3414
|
}
|
|
3415
3415
|
|
|
3416
3416
|
// src/policy/unified.ts
|
|
@@ -7929,13 +7929,13 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
7929
7929
|
}
|
|
7930
7930
|
if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
|
|
7931
7931
|
if (typeof value === "object") {
|
|
7932
|
-
const
|
|
7933
|
-
const prototype = Object.getPrototypeOf(
|
|
7932
|
+
const object4 = value;
|
|
7933
|
+
const prototype = Object.getPrototypeOf(object4);
|
|
7934
7934
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
7935
7935
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
7936
7936
|
}
|
|
7937
|
-
return `{${Object.keys(
|
|
7938
|
-
(key) => `${JSON.stringify(key)}:${canonicalize(
|
|
7937
|
+
return `{${Object.keys(object4).sort().map(
|
|
7938
|
+
(key) => `${JSON.stringify(key)}:${canonicalize(object4[key])}`
|
|
7939
7939
|
).join(",")}}`;
|
|
7940
7940
|
}
|
|
7941
7941
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
@@ -8070,8 +8070,8 @@ function canonicalJson(value) {
|
|
|
8070
8070
|
}
|
|
8071
8071
|
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
8072
8072
|
if (typeof value === "object") {
|
|
8073
|
-
const
|
|
8074
|
-
return `{${Object.keys(
|
|
8073
|
+
const object4 = value;
|
|
8074
|
+
return `{${Object.keys(object4).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(object4[key])}`).join(",")}}`;
|
|
8075
8075
|
}
|
|
8076
8076
|
throw new ShareEnvelopeError("invalid-envelope", "unsupported JSON value");
|
|
8077
8077
|
}
|
|
@@ -9253,8 +9253,8 @@ function canonicalJsonForProof(value) {
|
|
|
9253
9253
|
}
|
|
9254
9254
|
if (Array.isArray(value)) return `[${value.map(canonicalJsonForProof).join(",")}]`;
|
|
9255
9255
|
if (typeof value === "object") {
|
|
9256
|
-
const
|
|
9257
|
-
return `{${Object.keys(
|
|
9256
|
+
const object4 = value;
|
|
9257
|
+
return `{${Object.keys(object4).sort().map((key) => `${JSON.stringify(key)}:${canonicalJsonForProof(object4[key])}`).join(",")}}`;
|
|
9258
9258
|
}
|
|
9259
9259
|
throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
9260
9260
|
}
|
|
@@ -9963,12 +9963,12 @@ var ShareRecipientClient = class {
|
|
|
9963
9963
|
this.assertDetachedProof(request.proof);
|
|
9964
9964
|
}
|
|
9965
9965
|
parseSessionCapability(value) {
|
|
9966
|
-
const
|
|
9967
|
-
if (typeof
|
|
9968
|
-
if (!Array.isArray(
|
|
9969
|
-
const resource = this.requireObject(
|
|
9966
|
+
const object4 = this.requireObject(value, "session capability");
|
|
9967
|
+
if (typeof object4.spaceId !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability space is invalid");
|
|
9968
|
+
if (!Array.isArray(object4.actions) || object4.actions.some((action) => !["read", "list", "edit"].includes(action))) throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability actions are invalid");
|
|
9969
|
+
const resource = this.requireObject(object4.resource, "session capability resource");
|
|
9970
9970
|
if (resource.kind !== "exact" && resource.kind !== "prefix" || typeof resource.path !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability resource is invalid");
|
|
9971
|
-
return { spaceId:
|
|
9971
|
+
return { spaceId: object4.spaceId, actions: [...new Set(object4.actions)], resource: { kind: resource.kind, path: resource.path } };
|
|
9972
9972
|
}
|
|
9973
9973
|
assertProvidedPolicySession(session, envelope) {
|
|
9974
9974
|
const sessionExpiry = dateValue(session.expiresAt);
|
|
@@ -11709,6 +11709,97 @@ function shareDeliveryTrustedKid(publicKey) {
|
|
|
11709
11709
|
return `${did}#${did.slice("did:key:".length)}`;
|
|
11710
11710
|
}
|
|
11711
11711
|
|
|
11712
|
+
// src/delegations/share-delivery-v3.ts
|
|
11713
|
+
import { ed25519 as ed2551910 } from "@noble/curves/ed25519";
|
|
11714
|
+
var SHARE_DELIVERY_AUTHORIZATION_V3_DOMAIN = "xyz.tinycloud.share/delivery-authorization/v3\0";
|
|
11715
|
+
var AUTHORIZATION_KEYS2 = [
|
|
11716
|
+
"type",
|
|
11717
|
+
"version",
|
|
11718
|
+
"jti",
|
|
11719
|
+
"shareCid",
|
|
11720
|
+
"shareId",
|
|
11721
|
+
"policyCid",
|
|
11722
|
+
"policyRootCid",
|
|
11723
|
+
"enforcementRootCid",
|
|
11724
|
+
"nodeAudience",
|
|
11725
|
+
"enforcerDid",
|
|
11726
|
+
"targetOrigin",
|
|
11727
|
+
"openCredentialsAudience",
|
|
11728
|
+
"holder",
|
|
11729
|
+
"recipientMatcher",
|
|
11730
|
+
"deliveryEmail",
|
|
11731
|
+
"shareUrl",
|
|
11732
|
+
"returnOrigin",
|
|
11733
|
+
"documentName",
|
|
11734
|
+
"senderDid",
|
|
11735
|
+
"senderTrust",
|
|
11736
|
+
"contentSource",
|
|
11737
|
+
"contentSourceDigestHex",
|
|
11738
|
+
"shareExpiresAt",
|
|
11739
|
+
"issuedAt",
|
|
11740
|
+
"reportAbuseToken",
|
|
11741
|
+
"actions",
|
|
11742
|
+
"resource",
|
|
11743
|
+
"requestBodyDigest",
|
|
11744
|
+
"idempotencyKey",
|
|
11745
|
+
"expiresAt",
|
|
11746
|
+
"dataAuthority"
|
|
11747
|
+
];
|
|
11748
|
+
function exactObject(value, keys, label) {
|
|
11749
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} is invalid`);
|
|
11750
|
+
const record2 = value;
|
|
11751
|
+
if (Object.keys(record2).length !== keys.length || keys.some((key) => !Object.prototype.hasOwnProperty.call(record2, key))) throw new Error(`${label} has unknown or missing fields`);
|
|
11752
|
+
return record2;
|
|
11753
|
+
}
|
|
11754
|
+
function decodeBase64Url3(value) {
|
|
11755
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9_-]+$/.test(value)) throw new Error("share delivery value is not canonical base64url");
|
|
11756
|
+
if (typeof atob === "function") {
|
|
11757
|
+
const padded = value.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - value.length % 4) % 4);
|
|
11758
|
+
return Uint8Array.from(atob(padded), (character) => character.charCodeAt(0));
|
|
11759
|
+
}
|
|
11760
|
+
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(value, "base64url"));
|
|
11761
|
+
throw new Error("base64url decoding is unavailable");
|
|
11762
|
+
}
|
|
11763
|
+
function object3(value, label) {
|
|
11764
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} is invalid`);
|
|
11765
|
+
return value;
|
|
11766
|
+
}
|
|
11767
|
+
function validateShareDeliveryAuthorizationV3Bytes(bytes2, expected) {
|
|
11768
|
+
let parsed;
|
|
11769
|
+
try {
|
|
11770
|
+
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes2));
|
|
11771
|
+
} catch {
|
|
11772
|
+
throw new Error("v3 share delivery response is not valid UTF-8 JSON");
|
|
11773
|
+
}
|
|
11774
|
+
const root = exactObject(parsed, ["authorization", "proof"], "v3 share delivery response");
|
|
11775
|
+
const authorization = exactObject(root.authorization, AUTHORIZATION_KEYS2, "v3 share delivery authorization");
|
|
11776
|
+
const proof = exactObject(root.proof, ["alg", "kid", "signature"], "v3 share delivery proof");
|
|
11777
|
+
const envelope = object3(expected.request.envelope, "v3 share envelope");
|
|
11778
|
+
const policyRoot = object3(envelope.policyRoot, "v3 policy root");
|
|
11779
|
+
const enforcementRoot = object3(envelope.enforcementRoot, "v3 enforcement root");
|
|
11780
|
+
const target = object3(envelope.target, "v3 target");
|
|
11781
|
+
const display = object3(envelope.display, "v3 display");
|
|
11782
|
+
const resource = object3(envelope.resource, "v3 resource");
|
|
11783
|
+
const envelopeSignature = object3(envelope.signature, "v3 envelope signature");
|
|
11784
|
+
const shareUrl = new URL(expected.request.shareUrl);
|
|
11785
|
+
const targetOrigin = String(target.origin);
|
|
11786
|
+
const targetUrl = new URL(targetOrigin);
|
|
11787
|
+
const targetHost = targetUrl.hostname;
|
|
11788
|
+
const expectedNodeAudience = `did:web:${targetHost}`;
|
|
11789
|
+
if (authorization.type !== "TinyCloudShareDeliveryAuthorization" || authorization.version !== 3 || authorization.dataAuthority !== false || authorization.jti !== expected.request.jti || authorization.shareCid !== expected.request.shareCid || authorization.shareId !== envelope.shareId || authorization.policyCid !== envelope.policyCid || authorization.policyRootCid !== policyRoot.cid || authorization.enforcementRootCid !== enforcementRoot.cid || authorization.enforcerDid !== target.nodeAudience || authorization.targetOrigin !== target.origin || authorization.nodeAudience !== expectedNodeAudience || expected.nodeProof.kid.split("#", 1)[0] !== expectedNodeAudience || authorization.recipientMatcher === void 0 || canonicalizeSignedObjectUnsigned(authorization.recipientMatcher) !== canonicalizeSignedObjectUnsigned(envelope.recipientMatcher) || canonicalizeSignedObjectUnsigned(authorization.contentSource) !== canonicalizeSignedObjectUnsigned(envelope.contentSource) || authorization.contentSourceDigestHex !== envelope.contentSourceDigestHex || authorization.deliveryEmail !== expected.request.recipientEmail || authorization.shareUrl !== expected.request.shareUrl || authorization.documentName !== expected.request.documentName || authorization.documentName !== display.filename || authorization.senderDid !== envelopeSignature.signerDid || authorization.senderTrust !== "verified" || canonicalizeSignedObjectUnsigned(authorization.actions) !== canonicalizeSignedObjectUnsigned(envelope.actions) || authorization.resource !== resource.path || authorization.shareExpiresAt !== envelope.expiry || authorization.requestBodyDigest !== expected.request.requestBodyDigest || authorization.expiresAt !== expected.request.expiresAt || authorization.idempotencyKey !== expected.request.jti || authorization.reportAbuseToken !== expected.request.jti || authorization.returnOrigin !== shareUrl.origin || shareUrl.pathname !== `/s/${authorization.shareCid}` || shareUrl.hash !== `#k=${expected.request.envelopeKey}` || targetUrl.protocol !== "https:" || shareUrl.protocol !== "https:") throw new Error("v3 share delivery authorization is not bound to the submitted request");
|
|
11790
|
+
if (typeof authorization.openCredentialsAudience !== "string" || authorization.openCredentialsAudience !== expected.credentialsAudience || authorization.openCredentialsAudience === authorization.nodeAudience || authorization.openCredentialsAudience === authorization.returnOrigin) throw new Error("v3 share delivery credentials audience is untrusted");
|
|
11791
|
+
if (proof.alg !== "EdDSA" || proof.kid !== expected.nodeProof.kid || typeof proof.signature !== "string") throw new Error("v3 share delivery proof is invalid");
|
|
11792
|
+
const issuedAt = Date.parse(String(authorization.issuedAt));
|
|
11793
|
+
const expiresAt = Date.parse(String(authorization.expiresAt));
|
|
11794
|
+
const shareExpiresAt = Date.parse(String(authorization.shareExpiresAt));
|
|
11795
|
+
if (!Number.isFinite(issuedAt) || !Number.isFinite(expiresAt) || !Number.isFinite(shareExpiresAt) || expiresAt <= issuedAt || expiresAt - issuedAt > 5 * 6e4 || shareExpiresAt <= issuedAt || typeof authorization.holder !== "string" || !authorization.holder.startsWith("did:")) throw new Error("v3 share delivery authorization time or holder is invalid");
|
|
11796
|
+
const publicKey = expected.nodeProof.publicKey.length === 34 ? expected.nodeProof.publicKey.slice(2) : expected.nodeProof.publicKey;
|
|
11797
|
+
const signature = decodeBase64Url3(proof.signature);
|
|
11798
|
+
const signed = new TextEncoder().encode(`${SHARE_DELIVERY_AUTHORIZATION_V3_DOMAIN}${canonicalizeSignedObjectUnsigned(authorization)}`);
|
|
11799
|
+
if (publicKey.length !== 32 || signature.length !== 64 || !ed2551910.verify(signature, signed, publicKey)) throw new Error("v3 share delivery proof signature is invalid");
|
|
11800
|
+
return { authorization, proof };
|
|
11801
|
+
}
|
|
11802
|
+
|
|
11712
11803
|
// src/delegations/sender-share-store.ts
|
|
11713
11804
|
var MemorySenderShareRecordStorage = class {
|
|
11714
11805
|
constructor() {
|
|
@@ -14469,8 +14560,8 @@ function stableJson(value) {
|
|
|
14469
14560
|
if (Array.isArray(value)) {
|
|
14470
14561
|
return `[${value.map(stableJson).join(",")}]`;
|
|
14471
14562
|
}
|
|
14472
|
-
const
|
|
14473
|
-
return `{${Object.keys(
|
|
14563
|
+
const object4 = value;
|
|
14564
|
+
return `{${Object.keys(object4).sort().map((key) => `${JSON.stringify(key)}:${stableJson(object4[key])}`).join(",")}}`;
|
|
14474
14565
|
}
|
|
14475
14566
|
function indexedDelegationFromRow(row) {
|
|
14476
14567
|
const [
|
|
@@ -17475,7 +17566,7 @@ function portForProtocol(protocol) {
|
|
|
17475
17566
|
}
|
|
17476
17567
|
|
|
17477
17568
|
// src/location.ts
|
|
17478
|
-
import { ed25519 as
|
|
17569
|
+
import { ed25519 as ed2551911 } from "@noble/curves/ed25519";
|
|
17479
17570
|
import { verifyMessage as verifyMessage2 } from "viem";
|
|
17480
17571
|
var DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
|
|
17481
17572
|
var DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
|
|
@@ -18041,13 +18132,13 @@ async function verifyPkhSignature(did, payload, signature) {
|
|
|
18041
18132
|
}
|
|
18042
18133
|
function verifyDidKeySignature(did, payload, signature) {
|
|
18043
18134
|
const publicKey = ed25519PublicKeyFromDidKey2(did);
|
|
18044
|
-
const signatureBytes =
|
|
18135
|
+
const signatureBytes = decodeBase64Url4(signature);
|
|
18045
18136
|
if (signatureBytes.length !== 64) {
|
|
18046
18137
|
throw new LocationRecordValidationError(
|
|
18047
18138
|
"did:key signature must be a base64url Ed25519 signature"
|
|
18048
18139
|
);
|
|
18049
18140
|
}
|
|
18050
|
-
return
|
|
18141
|
+
return ed2551911.verify(
|
|
18051
18142
|
signatureBytes,
|
|
18052
18143
|
new TextEncoder().encode(payload),
|
|
18053
18144
|
publicKey
|
|
@@ -18055,7 +18146,7 @@ function verifyDidKeySignature(did, payload, signature) {
|
|
|
18055
18146
|
}
|
|
18056
18147
|
function verifyDidKeyEd25519Signature(did, payload, signature) {
|
|
18057
18148
|
const publicKey = ed25519PublicKeyFromDidKey2(did);
|
|
18058
|
-
return
|
|
18149
|
+
return ed2551911.verify(signature, payload, publicKey);
|
|
18059
18150
|
}
|
|
18060
18151
|
function ed25519PublicKeyFromDidKey2(did) {
|
|
18061
18152
|
const identifier = did.slice("did:key:".length);
|
|
@@ -18094,7 +18185,7 @@ function base64UrlEncode3(bytes2) {
|
|
|
18094
18185
|
}
|
|
18095
18186
|
return output;
|
|
18096
18187
|
}
|
|
18097
|
-
function
|
|
18188
|
+
function decodeBase64Url4(value) {
|
|
18098
18189
|
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
18099
18190
|
const bytes2 = [];
|
|
18100
18191
|
let buffer = 0;
|
|
@@ -18254,6 +18345,7 @@ export {
|
|
|
18254
18345
|
SERVICE_LONG_TO_SHORT,
|
|
18255
18346
|
SERVICE_SHORT_TO_LONG,
|
|
18256
18347
|
SHARE_DELIVERY_AUTHORIZATION_DOMAIN,
|
|
18348
|
+
SHARE_DELIVERY_AUTHORIZATION_V3_DOMAIN,
|
|
18257
18349
|
SPACE,
|
|
18258
18350
|
SQL,
|
|
18259
18351
|
SQLAction,
|
|
@@ -18524,6 +18616,7 @@ export {
|
|
|
18524
18616
|
validatePolicyStatusUnsigned,
|
|
18525
18617
|
validatePolicyUnsigned,
|
|
18526
18618
|
validateShareDeliveryAuthorizationBytes,
|
|
18619
|
+
validateShareDeliveryAuthorizationV3Bytes,
|
|
18527
18620
|
validateUnifiedPolicyV2,
|
|
18528
18621
|
verifyDecryptResponse,
|
|
18529
18622
|
verifyDidKeyEd25519Signature,
|