@tinycloud/sdk-core 3.0.0-beta.1 → 3.0.0-beta.10
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/{credential-admission-C_cO1QqB.d.cts → credential-admission-CFjUChF8.d.cts} +122 -2
- package/dist/{credential-admission-cvHe-HUC.d.ts → credential-admission-DIEPgQ0o.d.ts} +122 -2
- package/dist/delegations/index.cjs +80 -133
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +3 -3
- package/dist/delegations/index.d.ts +3 -3
- package/dist/delegations/index.js +81 -138
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +756 -306
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -7
- package/dist/index.d.ts +66 -7
- package/dist/index.js +758 -311
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +323 -8
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.d.cts +2 -2
- package/dist/policy/index.d.ts +2 -2
- package/dist/policy/index.js +323 -8
- package/dist/policy/index.js.map +1 -1
- package/dist/{recipient-types.schema-G8NEKRoo.d.cts → recipient-types.schema-Cz5zJzED.d.cts} +50 -77
- package/dist/{recipient-types.schema-G8NEKRoo.d.ts → recipient-types.schema-Cz5zJzED.d.ts} +50 -77
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as ICapabilityKeyRegistry, D as DelegationManager, R as Result, a as DelegationError } from '../recipient-types.schema-
|
|
2
|
-
export { A as AccountDelegationPage, b as AccountDelegationQueryOptions, c as AccountDelegationRecord, d as AccountDelegationResource, C as
|
|
3
|
-
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage,
|
|
1
|
+
import { I as ICapabilityKeyRegistry, D as DelegationManager, R as Result, a as DelegationError } from '../recipient-types.schema-Cz5zJzED.cjs';
|
|
2
|
+
export { A as AccountDelegationPage, b as AccountDelegationQueryOptions, c as AccountDelegationRecord, d as AccountDelegationResource, C as CREDENTIAL_INVITATION_REQUEST_DOMAIN, e as CapabilityEntry, f as CreateDelegationParams, g as CreateDelegationWasmParams, h as CreateDelegationWasmResult, i as CreateOwnerDelegationParams, j as CredentialInvitationRequest, k as DELIVERY_ADMISSION_DOMAIN, l as DelegateReceivedShareParams, m as DelegatedResource, n as DelegatedShareAccess, o as DelegatedShareKey, p as Delegation, q as DelegationApiResponse, r as DelegationChain, s as DelegationChainV2, t as DelegationDirection, u as DelegationErrorCode, v as DelegationErrorCodes, w as DelegationFilters, x as DelegationManagerConfig, y as DelegationRecord, z as DelegationRevocationReceipt, B as DelegationStatus, E as DeliveryAdmission, F as EncodedShareData, G as GenerateShareParams, H as ISharingService, J as IngestOptions, K as JWK, L as KeyInfo, M as KeyProvider, N as KeyType, O as MAX_CONTENT_BYTES, P as MAX_SEALED_SHARE_CONTENT_BYTES, Q as MAX_SHARE_ARTIFACT_BYTES, S as MAX_SHARE_CONTENT_BYTES, T as MemorySenderShareKeyStorage, U as MemorySenderShareRecordStorage, V as MemoryShareCache, W as OwnerDelegationPermission, X as OwnerDelegationReceipt, Y as OwnerShareAction, Z as OwnerShareDecryption, _ as OwnerShareMatcher, $ as OwnerSharePolicyRegistration, a0 as OwnerSharePolicyRegistrationReceipt, a1 as OwnerSharePolicyV2, a2 as PortableDelegationImportReceipt, a3 as ReceiveOptions, a4 as RegisterOwnerSharePolicyParams, a5 as SenderShareKeyStorage, a6 as SenderShareRecord, a7 as SenderShareRecordStorage, a8 as SenderShareRevocationScope, a9 as SenderShareStore, aa as ShareAccess, ab as ShareAccessError, ac as ShareAccessV2, ad as ShareAction, ae as ShareActionSchema, af as ShareAddressedDelegationEnvelopeV2, ag as ShareAddressedDelegationEnvelopeV2Schema, ah as ShareAddressedDelegationRequestV2, ai as ShareAddressedDelegationRequestV2Schema, aj as ShareAddressedDelegationResponseV2, ak as ShareAddressedDelegationResponseV2Schema, al as ShareAddressedRecipientMatcher, am as ShareArtifactInput, an as ShareArtifactResult, ao as ShareArtifactV2, ap as ShareCache, aq as ShareCacheEntry, ar as ShareCacheKey, as as ShareCacheMetadata, at as ShareCapabilityLike, au as ShareConflict, av as ShareContentMetadata, aw as ShareContentSource, ax as ShareDeliveryAuthorizationV3Receipt, ay as ShareDeliveryAuthorizationV3Request, az as ShareDetachedProof, aA as ShareEnvelopeError, aB as ShareEnvelopeV2, aC as ShareExpiryBounds, aD as ShareKvContentSource, aE as ShareLink, aF as ShareLinkData, aG as ShareLinkLocation, aH as ShareListEntry, aI as ShareListResult, aJ as ShareNativeAction, aK as ShareNativeInvokeEnvelopeV1, aL as ShareNativeInvokeErrorResult, aM as ShareNativeInvokeInput, aN as ShareNativeInvokeResult, aO as ShareNativeInvokeSuccessResult, aP as ShareNativeResponse, aQ as ShareNativeResponseSchema, aR as SharePolicy, aS as SharePolicyBinding, aT as SharePolicySession, aU as SharePolicySessionV1, aV as SharePolicySessionWireV1, aW as SharePortableDelegation, aX as ShareReadInvocationV1, aY as ShareReadResult, aZ as ShareRecipientClient, a_ as ShareRecipientClientOptions, a$ as ShareRecipientClientOptionsSchema, b0 as ShareRecipientPolicy, b1 as ShareRecipientPolicySchema, b2 as ShareRecipientResult, b3 as ShareRecipientTarget, b4 as ShareRecipientTargetSchema, b5 as ShareResource, b6 as ShareResourceSchema, b7 as ShareSaveOptions, b8 as ShareSchema, b9 as ShareSqlContentSource, ba as ShareWireAction, bb as SharingService, bc as SharingServiceConfig, bd as SignedDelegation, be as SpaceInfo, bf as SpaceOwnership, bg as VerifyShareEnvelopeOptions, bh as canonicalOwnerSharePolicy, bi as computeOwnerShareRegistrationCid, bj as computeShareCid, bk as createDelegatedShareKey, bl as createPolicyEnforcementDelegation, bm as createShareArtifact, bn as createShareArtifactAsync, bo as createSharePolicy, bp as createSharingService, bq as decryptShareBytesAsync, br as delegatePortablePolicySession, bs as encodeInlineShareUrl, bt as encodeShareArtifact, bu as encodeShareUrl, bv as encryptShareBytes, bw as encryptShareBytesAsync, bx as importPortableDelegation, by as intersectShareCapabilities, bz as isV2ShareLink, bA as normalizeShareActions, bB as normalizeShareRecipientTarget, bC as normalizeShareResource, bD as parsePortableDelegation, bE as parseShareArtifact, bF as parseShareUrl, bG as restoreDelegatedShareKey, bH as serializePortableDelegation, bI as shareCapabilityAllows, bJ as signShareEnvelope, bK as validateOwnerSharePolicyRegistration, bL as validateOwnerSharePolicyRegistrationBytes, bM as validateShareDeliveryAuthorizationV3Bytes, bN as verifyShareCid, bO as verifyShareEnvelope } from '../recipient-types.schema-Cz5zJzED.cjs';
|
|
3
|
+
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage, MemoryEncryptedShareHistoryStorage, ShareAuthorizationAdapter, ShareAuthorizationDenied, ShareAuthorizationMethod, ShareAuthorizationReady, ShareAuthorizationRequired, ShareAuthorizationResult, ShareDeliveryAdapter, ShareErrorCode, ShareErrorInfo, ShareFetchOptions, ShareHistoryView, ShareInspection, ShareMetadata, ShareNotifyResult, ShareNotifyState, SharePolicyPublishAdapter, ShareReceiveError, ShareReceiveResult, ShareRevocationAdapter, ShareRevocationResult, ShareTarget, TargetPublishAdapter, TargetPublishInput, TargetPublishOutcome, authorizationMethodForTarget, authorizeShare, claimShare, inspectShare, listShares, notifyShare, publishPolicyShare, publishTargetShare, receiveShare, resumeShareAuthorization, revokeShare, showShare, toShareErrorInfo } from '@tinycloud/share-sdk';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ServiceSession, InvokeFunction, FetchFunction, IKVService } from '@tinycloud/sdk-services';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as ICapabilityKeyRegistry, D as DelegationManager, R as Result, a as DelegationError } from '../recipient-types.schema-
|
|
2
|
-
export { A as AccountDelegationPage, b as AccountDelegationQueryOptions, c as AccountDelegationRecord, d as AccountDelegationResource, C as
|
|
3
|
-
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage,
|
|
1
|
+
import { I as ICapabilityKeyRegistry, D as DelegationManager, R as Result, a as DelegationError } from '../recipient-types.schema-Cz5zJzED.js';
|
|
2
|
+
export { A as AccountDelegationPage, b as AccountDelegationQueryOptions, c as AccountDelegationRecord, d as AccountDelegationResource, C as CREDENTIAL_INVITATION_REQUEST_DOMAIN, e as CapabilityEntry, f as CreateDelegationParams, g as CreateDelegationWasmParams, h as CreateDelegationWasmResult, i as CreateOwnerDelegationParams, j as CredentialInvitationRequest, k as DELIVERY_ADMISSION_DOMAIN, l as DelegateReceivedShareParams, m as DelegatedResource, n as DelegatedShareAccess, o as DelegatedShareKey, p as Delegation, q as DelegationApiResponse, r as DelegationChain, s as DelegationChainV2, t as DelegationDirection, u as DelegationErrorCode, v as DelegationErrorCodes, w as DelegationFilters, x as DelegationManagerConfig, y as DelegationRecord, z as DelegationRevocationReceipt, B as DelegationStatus, E as DeliveryAdmission, F as EncodedShareData, G as GenerateShareParams, H as ISharingService, J as IngestOptions, K as JWK, L as KeyInfo, M as KeyProvider, N as KeyType, O as MAX_CONTENT_BYTES, P as MAX_SEALED_SHARE_CONTENT_BYTES, Q as MAX_SHARE_ARTIFACT_BYTES, S as MAX_SHARE_CONTENT_BYTES, T as MemorySenderShareKeyStorage, U as MemorySenderShareRecordStorage, V as MemoryShareCache, W as OwnerDelegationPermission, X as OwnerDelegationReceipt, Y as OwnerShareAction, Z as OwnerShareDecryption, _ as OwnerShareMatcher, $ as OwnerSharePolicyRegistration, a0 as OwnerSharePolicyRegistrationReceipt, a1 as OwnerSharePolicyV2, a2 as PortableDelegationImportReceipt, a3 as ReceiveOptions, a4 as RegisterOwnerSharePolicyParams, a5 as SenderShareKeyStorage, a6 as SenderShareRecord, a7 as SenderShareRecordStorage, a8 as SenderShareRevocationScope, a9 as SenderShareStore, aa as ShareAccess, ab as ShareAccessError, ac as ShareAccessV2, ad as ShareAction, ae as ShareActionSchema, af as ShareAddressedDelegationEnvelopeV2, ag as ShareAddressedDelegationEnvelopeV2Schema, ah as ShareAddressedDelegationRequestV2, ai as ShareAddressedDelegationRequestV2Schema, aj as ShareAddressedDelegationResponseV2, ak as ShareAddressedDelegationResponseV2Schema, al as ShareAddressedRecipientMatcher, am as ShareArtifactInput, an as ShareArtifactResult, ao as ShareArtifactV2, ap as ShareCache, aq as ShareCacheEntry, ar as ShareCacheKey, as as ShareCacheMetadata, at as ShareCapabilityLike, au as ShareConflict, av as ShareContentMetadata, aw as ShareContentSource, ax as ShareDeliveryAuthorizationV3Receipt, ay as ShareDeliveryAuthorizationV3Request, az as ShareDetachedProof, aA as ShareEnvelopeError, aB as ShareEnvelopeV2, aC as ShareExpiryBounds, aD as ShareKvContentSource, aE as ShareLink, aF as ShareLinkData, aG as ShareLinkLocation, aH as ShareListEntry, aI as ShareListResult, aJ as ShareNativeAction, aK as ShareNativeInvokeEnvelopeV1, aL as ShareNativeInvokeErrorResult, aM as ShareNativeInvokeInput, aN as ShareNativeInvokeResult, aO as ShareNativeInvokeSuccessResult, aP as ShareNativeResponse, aQ as ShareNativeResponseSchema, aR as SharePolicy, aS as SharePolicyBinding, aT as SharePolicySession, aU as SharePolicySessionV1, aV as SharePolicySessionWireV1, aW as SharePortableDelegation, aX as ShareReadInvocationV1, aY as ShareReadResult, aZ as ShareRecipientClient, a_ as ShareRecipientClientOptions, a$ as ShareRecipientClientOptionsSchema, b0 as ShareRecipientPolicy, b1 as ShareRecipientPolicySchema, b2 as ShareRecipientResult, b3 as ShareRecipientTarget, b4 as ShareRecipientTargetSchema, b5 as ShareResource, b6 as ShareResourceSchema, b7 as ShareSaveOptions, b8 as ShareSchema, b9 as ShareSqlContentSource, ba as ShareWireAction, bb as SharingService, bc as SharingServiceConfig, bd as SignedDelegation, be as SpaceInfo, bf as SpaceOwnership, bg as VerifyShareEnvelopeOptions, bh as canonicalOwnerSharePolicy, bi as computeOwnerShareRegistrationCid, bj as computeShareCid, bk as createDelegatedShareKey, bl as createPolicyEnforcementDelegation, bm as createShareArtifact, bn as createShareArtifactAsync, bo as createSharePolicy, bp as createSharingService, bq as decryptShareBytesAsync, br as delegatePortablePolicySession, bs as encodeInlineShareUrl, bt as encodeShareArtifact, bu as encodeShareUrl, bv as encryptShareBytes, bw as encryptShareBytesAsync, bx as importPortableDelegation, by as intersectShareCapabilities, bz as isV2ShareLink, bA as normalizeShareActions, bB as normalizeShareRecipientTarget, bC as normalizeShareResource, bD as parsePortableDelegation, bE as parseShareArtifact, bF as parseShareUrl, bG as restoreDelegatedShareKey, bH as serializePortableDelegation, bI as shareCapabilityAllows, bJ as signShareEnvelope, bK as validateOwnerSharePolicyRegistration, bL as validateOwnerSharePolicyRegistrationBytes, bM as validateShareDeliveryAuthorizationV3Bytes, bN as verifyShareCid, bO as verifyShareEnvelope } from '../recipient-types.schema-Cz5zJzED.js';
|
|
3
|
+
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage, MemoryEncryptedShareHistoryStorage, ShareAuthorizationAdapter, ShareAuthorizationDenied, ShareAuthorizationMethod, ShareAuthorizationReady, ShareAuthorizationRequired, ShareAuthorizationResult, ShareDeliveryAdapter, ShareErrorCode, ShareErrorInfo, ShareFetchOptions, ShareHistoryView, ShareInspection, ShareMetadata, ShareNotifyResult, ShareNotifyState, SharePolicyPublishAdapter, ShareReceiveError, ShareReceiveResult, ShareRevocationAdapter, ShareRevocationResult, ShareTarget, TargetPublishAdapter, TargetPublishInput, TargetPublishOutcome, authorizationMethodForTarget, authorizeShare, claimShare, inspectShare, listShares, notifyShare, publishPolicyShare, publishTargetShare, receiveShare, resumeShareAuthorization, revokeShare, showShare, toShareErrorInfo } from '@tinycloud/share-sdk';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ServiceSession, InvokeFunction, FetchFunction, IKVService } from '@tinycloud/sdk-services';
|
|
6
6
|
|
|
@@ -1378,13 +1378,13 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
1378
1378
|
}
|
|
1379
1379
|
if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
|
|
1380
1380
|
if (typeof value === "object") {
|
|
1381
|
-
const
|
|
1382
|
-
const prototype = Object.getPrototypeOf(
|
|
1381
|
+
const object2 = value;
|
|
1382
|
+
const prototype = Object.getPrototypeOf(object2);
|
|
1383
1383
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
1384
1384
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
1385
1385
|
}
|
|
1386
|
-
return `{${Object.keys(
|
|
1387
|
-
(key) => `${JSON.stringify(key)}:${canonicalize(
|
|
1386
|
+
return `{${Object.keys(object2).sort().map(
|
|
1387
|
+
(key) => `${JSON.stringify(key)}:${canonicalize(object2[key])}`
|
|
1388
1388
|
).join(",")}}`;
|
|
1389
1389
|
}
|
|
1390
1390
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
@@ -2582,7 +2582,6 @@ import { ed25519 } from "@noble/curves/ed25519";
|
|
|
2582
2582
|
import { blake3 } from "@noble/hashes/blake3";
|
|
2583
2583
|
import { sha256 as sha2562 } from "@noble/hashes/sha256";
|
|
2584
2584
|
var ENVELOPE_SCHEMA = "xyz.tinycloud.share/envelope";
|
|
2585
|
-
var INLINE_PREFIX = "tc2:";
|
|
2586
2585
|
var RAW_CID_CODEC = 85;
|
|
2587
2586
|
var BLAKE3_256_CODE = 30;
|
|
2588
2587
|
var DEFAULT_MAX_INLINE_BYTES = 256 * 1024;
|
|
@@ -2629,8 +2628,8 @@ function canonicalJson(value) {
|
|
|
2629
2628
|
}
|
|
2630
2629
|
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
2631
2630
|
if (typeof value === "object") {
|
|
2632
|
-
const
|
|
2633
|
-
return `{${Object.keys(
|
|
2631
|
+
const object2 = value;
|
|
2632
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(object2[key])}`).join(",")}}`;
|
|
2634
2633
|
}
|
|
2635
2634
|
throw new ShareEnvelopeError("invalid-envelope", "unsupported JSON value");
|
|
2636
2635
|
}
|
|
@@ -3287,25 +3286,8 @@ function parsePublishedShareLink(link, options = {}) {
|
|
|
3287
3286
|
}
|
|
3288
3287
|
const origin = normalizeOrigin(url.origin);
|
|
3289
3288
|
if (options.trustedOrigins !== void 0 && !options.trustedOrigins.map(normalizeOrigin).includes(origin)) throw new ShareEnvelopeError("origin-mismatch", "share link origin is not trusted");
|
|
3290
|
-
if (url.
|
|
3291
|
-
if (url.
|
|
3292
|
-
let payload;
|
|
3293
|
-
try {
|
|
3294
|
-
const bytes2 = base64UrlToBytes(url.hash.slice("#v=2&p=".length));
|
|
3295
|
-
if (bytes2.length > (options.maxInlineBytes ?? DEFAULT_MAX_INLINE_BYTES) * 2) throw new Error("inline payload too large");
|
|
3296
|
-
const value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes2));
|
|
3297
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("inline payload shape");
|
|
3298
|
-
payload = value;
|
|
3299
|
-
} catch (error) {
|
|
3300
|
-
throw new ShareEnvelopeError("invalid-link", error instanceof Error ? error.message : "invalid inline payload");
|
|
3301
|
-
}
|
|
3302
|
-
if (payload.v !== 2 || typeof payload.c !== "string" || typeof payload.cid !== "string" || payload.k !== void 0 && typeof payload.k !== "string" || Object.keys(payload).some((key3) => !["v", "c", "cid", "k"].includes(key3))) throw new ShareEnvelopeError("invalid-link", "inline payload fields are invalid");
|
|
3303
|
-
const sealed = base64UrlToBytes(payload.c);
|
|
3304
|
-
if (!verifyPublishedShareCid(payload.cid, sealed)) throw new ShareEnvelopeError("cid-mismatch", "inline payload CID does not match");
|
|
3305
|
-
const key2 = payload.k === void 0 ? void 0 : base64UrlToBytes(payload.k);
|
|
3306
|
-
if (key2 !== void 0 && key2.length !== 32) throw new ShareEnvelopeError("invalid-link", "inline payload key is invalid");
|
|
3307
|
-
return { origin, cid: payload.cid, ...key2 === void 0 ? {} : { key: key2 }, sealed };
|
|
3308
|
-
}
|
|
3289
|
+
if (url.username !== "" || url.password !== "") throw new ShareEnvelopeError("invalid-link", "share link is not canonical");
|
|
3290
|
+
if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share link is not canonical");
|
|
3309
3291
|
const match = /^\/s\/([a-z2-7]+)$/.exec(url.pathname);
|
|
3310
3292
|
if (match === null || !url.hash.startsWith("#k=")) throw new ShareEnvelopeError("invalid-link", "published share link is invalid");
|
|
3311
3293
|
const key = base64UrlToBytes(url.hash.slice(3));
|
|
@@ -3325,13 +3307,10 @@ function parseShareUrl(link, options = {}) {
|
|
|
3325
3307
|
} catch {
|
|
3326
3308
|
throw new ShareEnvelopeError("invalid-link", "share link must be an absolute URL");
|
|
3327
3309
|
}
|
|
3328
|
-
if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share links must not contain query parameters");
|
|
3329
3310
|
const origin = normalizeOrigin(url.origin);
|
|
3330
3311
|
if (options.trustedOrigins !== void 0 && !options.trustedOrigins.map(normalizeOrigin).includes(origin)) throw new ShareEnvelopeError("origin-mismatch", "share link origin is not trusted");
|
|
3331
|
-
if (url.pathname === "/
|
|
3332
|
-
|
|
3333
|
-
return { kind: "inline", origin, cid: published.cid, key: published.key, url: `${url.origin}${url.pathname}`, protocol: "share-envelope-v2" };
|
|
3334
|
-
}
|
|
3312
|
+
if (url.pathname === "/viewer") throw new ShareEnvelopeError("invalid-link", "retired viewer links are not accepted");
|
|
3313
|
+
if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share links must not contain query parameters");
|
|
3335
3314
|
const match = url.pathname.match(/^\/s\/(i\/)?([^/]+)$/);
|
|
3336
3315
|
if (!match) throw new ShareEnvelopeError("invalid-link", "share link path is invalid");
|
|
3337
3316
|
const fragmentParams = url.hash === "" ? void 0 : new URLSearchParams(url.hash.slice(1));
|
|
@@ -3354,9 +3333,10 @@ function parseShareUrl(link, options = {}) {
|
|
|
3354
3333
|
}
|
|
3355
3334
|
function isV2ShareLink(link) {
|
|
3356
3335
|
try {
|
|
3357
|
-
|
|
3336
|
+
const url = new URL(link);
|
|
3337
|
+
return url.search === "" && url.pathname.startsWith("/s/");
|
|
3358
3338
|
} catch {
|
|
3359
|
-
return
|
|
3339
|
+
return false;
|
|
3360
3340
|
}
|
|
3361
3341
|
}
|
|
3362
3342
|
async function encryptShareBytes(bytes2, key) {
|
|
@@ -3896,6 +3876,11 @@ var POLICY_SESSION_FACT_KEYS = [
|
|
|
3896
3876
|
"issuanceAuditDigestHex",
|
|
3897
3877
|
"remainingRedelegationDepth"
|
|
3898
3878
|
];
|
|
3879
|
+
var POLICY_SESSION_V4_AUDIT_FACT_KEYS = [
|
|
3880
|
+
"credentialIdAuditDigestHex",
|
|
3881
|
+
"presentationJtiAuditDigestHex"
|
|
3882
|
+
];
|
|
3883
|
+
var LOWER_SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
3899
3884
|
var CompactHeaderSchema = z4.object({
|
|
3900
3885
|
alg: z4.literal("EdDSA"),
|
|
3901
3886
|
jwk: z4.object({ alg: z4.literal("EdDSA"), crv: z4.literal("Ed25519"), kty: z4.literal("OKP"), x: z4.string().min(1) }).strict(),
|
|
@@ -4037,9 +4022,13 @@ function parsePolicySessionUcan(authorization, expectedProofs) {
|
|
|
4037
4022
|
if (expectedProofs !== void 0 && (parsed.payload.prf[0] !== expectedProofs[0] || parsed.payload.prf[1] !== expectedProofs[1]))
|
|
4038
4023
|
throw new Error("policy session UCAN ordered proofs do not match");
|
|
4039
4024
|
const factKeys = Object.keys(fact);
|
|
4040
|
-
|
|
4025
|
+
const hasLegacyFactShape = factKeys.length === POLICY_SESSION_FACT_KEYS.length && factKeys.every((key) => POLICY_SESSION_FACT_KEYS.includes(key)) && POLICY_SESSION_FACT_KEYS.every((key) => key in fact);
|
|
4026
|
+
const hasV4AuditFactShape = factKeys.length === POLICY_SESSION_FACT_KEYS.length + POLICY_SESSION_V4_AUDIT_FACT_KEYS.length && factKeys.every((key) => POLICY_SESSION_FACT_KEYS.includes(key) || POLICY_SESSION_V4_AUDIT_FACT_KEYS.includes(key)) && POLICY_SESSION_FACT_KEYS.every((key) => key in fact) && POLICY_SESSION_V4_AUDIT_FACT_KEYS.every((key) => key in fact);
|
|
4027
|
+
if (!hasLegacyFactShape && !hasV4AuditFactShape)
|
|
4041
4028
|
throw new Error("policy session UCAN fact is incomplete");
|
|
4042
|
-
if (
|
|
4029
|
+
if (hasV4AuditFactShape && (!LOWER_SHA256_HEX.test(fact.credentialIdAuditDigestHex) || !LOWER_SHA256_HEX.test(fact.presentationJtiAuditDigestHex)))
|
|
4030
|
+
throw new Error("policy session UCAN v4 audit facts are invalid");
|
|
4031
|
+
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.nodeAudience || parsed.payload.aud !== fact.recipientDid)
|
|
4043
4032
|
throw new Error("policy session UCAN fact is invalid");
|
|
4044
4033
|
return {
|
|
4045
4034
|
authorization,
|
|
@@ -4216,8 +4205,8 @@ function canonicalJsonForProof(value) {
|
|
|
4216
4205
|
}
|
|
4217
4206
|
if (Array.isArray(value)) return `[${value.map(canonicalJsonForProof).join(",")}]`;
|
|
4218
4207
|
if (typeof value === "object") {
|
|
4219
|
-
const
|
|
4220
|
-
return `{${Object.keys(
|
|
4208
|
+
const object2 = value;
|
|
4209
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJsonForProof(object2[key])}`).join(",")}}`;
|
|
4221
4210
|
}
|
|
4222
4211
|
throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
4223
4212
|
}
|
|
@@ -4926,12 +4915,12 @@ var ShareRecipientClient = class {
|
|
|
4926
4915
|
this.assertDetachedProof(request.proof);
|
|
4927
4916
|
}
|
|
4928
4917
|
parseSessionCapability(value) {
|
|
4929
|
-
const
|
|
4930
|
-
if (typeof
|
|
4931
|
-
if (!Array.isArray(
|
|
4932
|
-
const resource = this.requireObject(
|
|
4918
|
+
const object2 = this.requireObject(value, "session capability");
|
|
4919
|
+
if (typeof object2.spaceId !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability space is invalid");
|
|
4920
|
+
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");
|
|
4921
|
+
const resource = this.requireObject(object2.resource, "session capability resource");
|
|
4933
4922
|
if (resource.kind !== "exact" && resource.kind !== "prefix" || typeof resource.path !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability resource is invalid");
|
|
4934
|
-
return { spaceId:
|
|
4923
|
+
return { spaceId: object2.spaceId, actions: [...new Set(object2.actions)], resource: { kind: resource.kind, path: resource.path } };
|
|
4935
4924
|
}
|
|
4936
4925
|
assertProvidedPolicySession(session, envelope) {
|
|
4937
4926
|
const sessionExpiry = dateValue(session.expiresAt);
|
|
@@ -6584,62 +6573,21 @@ function validateOwnerSharePolicyRegistrationBytes(bytesValue, expected) {
|
|
|
6584
6573
|
return validateOwnerSharePolicyRegistration(value, expected);
|
|
6585
6574
|
}
|
|
6586
6575
|
|
|
6587
|
-
// src/delegations/share-delivery.ts
|
|
6576
|
+
// src/delegations/share-delivery-v3.ts
|
|
6588
6577
|
import { ed25519 as ed255197 } from "@noble/curves/ed25519";
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
return false;
|
|
6596
|
-
}
|
|
6597
|
-
return url.protocol === "https:" && url.origin === value && url.pathname === "/" && url.search === "" && url.hash === "" && url.username === "" && url.password === "";
|
|
6598
|
-
}
|
|
6599
|
-
var AUTHORIZATION_KEYS = [
|
|
6600
|
-
"type",
|
|
6601
|
-
"version",
|
|
6602
|
-
"jti",
|
|
6603
|
-
"shareCid",
|
|
6604
|
-
"shareId",
|
|
6605
|
-
"registrationCid",
|
|
6606
|
-
"delegationCid",
|
|
6607
|
-
"enforcementDelegationCid",
|
|
6608
|
-
"envelopeCid",
|
|
6609
|
-
"policyCid",
|
|
6610
|
-
"nodeAudience",
|
|
6611
|
-
"targetOrigin",
|
|
6612
|
-
"openCredentialsAudience",
|
|
6613
|
-
"holder",
|
|
6614
|
-
"recipientMatcher",
|
|
6615
|
-
"deliveryEmail",
|
|
6616
|
-
"shareUrl",
|
|
6617
|
-
"returnOrigin",
|
|
6618
|
-
"documentName",
|
|
6619
|
-
"senderDid",
|
|
6620
|
-
"senderTrust",
|
|
6621
|
-
"contentSource",
|
|
6622
|
-
"contentSourceDigest",
|
|
6623
|
-
"shareExpiresAt",
|
|
6624
|
-
"issuedAt",
|
|
6625
|
-
"reportAbuseToken",
|
|
6626
|
-
"actions",
|
|
6627
|
-
"resource",
|
|
6628
|
-
"authorityMaterialHandle",
|
|
6629
|
-
"authorityMaterialDigest",
|
|
6630
|
-
"requestBodyDigest",
|
|
6631
|
-
"idempotencyKey",
|
|
6632
|
-
"expiresAt",
|
|
6633
|
-
"dataAuthority"
|
|
6634
|
-
];
|
|
6635
|
-
function assertObject2(value, keys, label) {
|
|
6578
|
+
import { sha256 as sha2568 } from "@noble/hashes/sha256";
|
|
6579
|
+
var CREDENTIAL_INVITATION_REQUEST_DOMAIN = "xyz.tinycloud.credentials/invitation-request/v1\0";
|
|
6580
|
+
var DELIVERY_ADMISSION_DOMAIN = "xyz.tinycloud.policy/delivery-admission/v0\0";
|
|
6581
|
+
var REQUEST_KEYS = ["schema", "policyId", "recipient", "resource", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "audience", "issuedAt", "expiresAt", "nonce"];
|
|
6582
|
+
var ADMISSION_KEYS = ["schema", "policyId", "ownerDid", "recipient", "resource", "actions", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "senderKeyDid", "audience", "issuedAt", "expiresAt", "nonce", "signature"];
|
|
6583
|
+
function exactObject(value, keys, label) {
|
|
6636
6584
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} is invalid`);
|
|
6637
6585
|
const record = value;
|
|
6638
6586
|
if (Object.keys(record).length !== keys.length || keys.some((key) => !Object.prototype.hasOwnProperty.call(record, key))) throw new Error(`${label} has unknown or missing fields`);
|
|
6639
6587
|
return record;
|
|
6640
6588
|
}
|
|
6641
|
-
function
|
|
6642
|
-
if (!/^[A-Za-z0-9_-]+$/.test(value)) throw new Error("share delivery value is not canonical base64url");
|
|
6589
|
+
function decodeBase64Url2(value) {
|
|
6590
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9_-]+$/.test(value)) throw new Error("share delivery value is not canonical base64url");
|
|
6643
6591
|
if (typeof atob === "function") {
|
|
6644
6592
|
const padded = value.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - value.length % 4) % 4);
|
|
6645
6593
|
return Uint8Array.from(atob(padded), (character) => character.charCodeAt(0));
|
|
@@ -6647,42 +6595,45 @@ function fromB642(value) {
|
|
|
6647
6595
|
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(value, "base64url"));
|
|
6648
6596
|
throw new Error("base64url decoding is unavailable");
|
|
6649
6597
|
}
|
|
6650
|
-
function
|
|
6651
|
-
|
|
6598
|
+
function object(value, label) {
|
|
6599
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} is invalid`);
|
|
6600
|
+
return value;
|
|
6601
|
+
}
|
|
6602
|
+
function didKeyBytes(did) {
|
|
6603
|
+
if (!did.startsWith("did:key:z") || /[#/?]/.test(did.slice("did:key:".length))) throw new Error("v3 delivery admission signer is invalid");
|
|
6604
|
+
const decoded = base58btc.decode(did.slice("did:key:".length));
|
|
6605
|
+
if (decoded.length !== 34 || decoded[0] !== 237 || decoded[1] !== 1) throw new Error("v3 delivery admission signer is invalid");
|
|
6606
|
+
return decoded.slice(2);
|
|
6607
|
+
}
|
|
6608
|
+
function validateShareDeliveryAuthorizationV3Bytes(bytes2, expected) {
|
|
6609
|
+
let parsed;
|
|
6652
6610
|
try {
|
|
6653
|
-
|
|
6611
|
+
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes2));
|
|
6654
6612
|
} catch {
|
|
6655
|
-
throw new Error("share delivery
|
|
6656
|
-
}
|
|
6657
|
-
const root =
|
|
6658
|
-
const
|
|
6659
|
-
const
|
|
6660
|
-
const
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
if (
|
|
6671
|
-
const
|
|
6672
|
-
const
|
|
6673
|
-
if (
|
|
6674
|
-
const
|
|
6675
|
-
const
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
}
|
|
6679
|
-
function shareDeliveryTrustedKid(publicKey) {
|
|
6680
|
-
if (publicKey.length !== 32) throw new Error("share delivery node key must be a raw 32-byte Ed25519 public key");
|
|
6681
|
-
const prefixed = new Uint8Array(34);
|
|
6682
|
-
prefixed.set([237, 1]);
|
|
6683
|
-
prefixed.set(publicKey, 2);
|
|
6684
|
-
const did = `did:key:${base58btc.encode(prefixed)}`;
|
|
6685
|
-
return `${did}#${did.slice("did:key:".length)}`;
|
|
6613
|
+
throw new Error("v3 share delivery response is not valid UTF-8 JSON");
|
|
6614
|
+
}
|
|
6615
|
+
const root = exactObject(parsed, ["request", "admission"], "v3 share delivery response");
|
|
6616
|
+
const request = exactObject(root.request, REQUEST_KEYS, "credential invitation request");
|
|
6617
|
+
const admission = exactObject(root.admission, ADMISSION_KEYS, "delivery admission");
|
|
6618
|
+
const signature = exactObject(admission.signature, ["suite", "signerDid", "value"], "delivery admission signature");
|
|
6619
|
+
const envelope = object(expected.request.envelope, "v3 share envelope");
|
|
6620
|
+
const policy = object(envelope.policy, "v3 share policy");
|
|
6621
|
+
const requirement = object(policy.credentialRequirement, "v3 credential requirement");
|
|
6622
|
+
const credentialType = object(requirement.credentialType, "v3 credential type");
|
|
6623
|
+
const contentSource = object(envelope.contentSource, "v3 content source");
|
|
6624
|
+
const envelopeSignature = object(envelope.signature, "v3 envelope signature");
|
|
6625
|
+
const target = object(envelope.target, "v3 target");
|
|
6626
|
+
const binding = object(envelope.attestedEnforcerBinding, "v3 attested enforcer binding");
|
|
6627
|
+
const fields = ["policyId", "recipient", "resource", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "audience", "issuedAt", "expiresAt", "nonce"];
|
|
6628
|
+
if (request.schema !== "xyz.tinycloud.credentials/invitation-request/v1" || admission.schema !== "xyz.tinycloud.policy/delivery-admission/v0" || fields.some((field) => request[field] !== admission[field]) || request.policyId !== envelope.policyCid || request.recipient !== expected.request.recipientEmail || request.resource !== contentSource.kvResource || request.credentialType !== credentialType.id || request.credentialType !== "opencredentials.email/v1" || request.returnLink !== expected.request.shareUrl || request.envelopeRef !== expected.request.shareCid || request.label !== expected.request.documentName || request.shareExpiresAt !== envelope.expiry || request.audience !== expected.deliveryAudience || request.expiresAt !== expected.request.expiresAt || request.nonce !== expected.request.jti || admission.ownerDid !== envelopeSignature.signerDid || admission.senderKeyDid !== expected.senderKeyDid || canonicalizeSignedObjectUnsigned(admission.actions) !== canonicalizeSignedObjectUnsigned(["tinycloud.kv/get"]) || signature.suite !== "eddsa-ed25519-sha256-jcs-v1" || target.nodeAudience !== binding.nodeAudience || signature.signerDid !== binding.nodeAudience) throw new Error("v3 share delivery authorization is not bound to the submitted request");
|
|
6629
|
+
const issuedAt = Date.parse(String(request.issuedAt));
|
|
6630
|
+
const expiresAt = Date.parse(String(request.expiresAt));
|
|
6631
|
+
if (!Number.isFinite(issuedAt) || !Number.isFinite(expiresAt) || expiresAt <= issuedAt || expiresAt - issuedAt > 15 * 6e4) throw new Error("v3 share delivery authorization time is invalid");
|
|
6632
|
+
const admissionSignature = decodeBase64Url2(signature.value);
|
|
6633
|
+
const { signature: _signature, ...unsignedAdmission } = admission;
|
|
6634
|
+
const digest4 = sha2568(new TextEncoder().encode(`${DELIVERY_ADMISSION_DOMAIN}${canonicalizeSignedObjectUnsigned(unsignedAdmission)}`));
|
|
6635
|
+
if (admissionSignature.length !== 64 || !ed255197.verify(admissionSignature, digest4, didKeyBytes(String(signature.signerDid)))) throw new Error("v3 share delivery admission signature is invalid");
|
|
6636
|
+
return { request, admission };
|
|
6686
6637
|
}
|
|
6687
6638
|
|
|
6688
6639
|
// src/delegations/sender-share-store.ts
|
|
@@ -6805,9 +6756,6 @@ import {
|
|
|
6805
6756
|
publishPolicyShare,
|
|
6806
6757
|
claimShare,
|
|
6807
6758
|
resumeShareAuthorization,
|
|
6808
|
-
isLegacyShareLink,
|
|
6809
|
-
receiveLegacyShare,
|
|
6810
|
-
migrateShare,
|
|
6811
6759
|
MemoryEncryptedShareHistoryStorage,
|
|
6812
6760
|
EncryptedSenderShareHistory
|
|
6813
6761
|
} from "@tinycloud/share-sdk";
|
|
@@ -6815,10 +6763,11 @@ import {
|
|
|
6815
6763
|
inspectShare,
|
|
6816
6764
|
receiveShare,
|
|
6817
6765
|
ShareReceiveError,
|
|
6818
|
-
toShareErrorInfo
|
|
6819
|
-
verifyBearerEnvelope
|
|
6766
|
+
toShareErrorInfo
|
|
6820
6767
|
} from "@tinycloud/share-sdk";
|
|
6821
6768
|
export {
|
|
6769
|
+
CREDENTIAL_INVITATION_REQUEST_DOMAIN,
|
|
6770
|
+
DELIVERY_ADMISSION_DOMAIN,
|
|
6822
6771
|
DelegationErrorCodes,
|
|
6823
6772
|
DelegationManager,
|
|
6824
6773
|
EncodedShareDataSchema,
|
|
@@ -6832,7 +6781,6 @@ export {
|
|
|
6832
6781
|
MemorySenderShareRecordStorage,
|
|
6833
6782
|
MemoryShareCache,
|
|
6834
6783
|
ReceiveOptionsSchema,
|
|
6835
|
-
SHARE_DELIVERY_AUTHORIZATION_DOMAIN,
|
|
6836
6784
|
SenderShareStore,
|
|
6837
6785
|
ShareAccessError,
|
|
6838
6786
|
ShareActionSchema,
|
|
@@ -6872,10 +6820,8 @@ export {
|
|
|
6872
6820
|
importPortableDelegation,
|
|
6873
6821
|
inspectShare,
|
|
6874
6822
|
intersectShareCapabilities,
|
|
6875
|
-
isLegacyShareLink,
|
|
6876
6823
|
isV2ShareLink,
|
|
6877
6824
|
listShares,
|
|
6878
|
-
migrateShare,
|
|
6879
6825
|
normalizeShareActions,
|
|
6880
6826
|
normalizeShareRecipientTarget,
|
|
6881
6827
|
normalizeShareResource,
|
|
@@ -6885,14 +6831,12 @@ export {
|
|
|
6885
6831
|
parseShareUrl,
|
|
6886
6832
|
publishPolicyShare,
|
|
6887
6833
|
publishTargetShare,
|
|
6888
|
-
receiveLegacyShare,
|
|
6889
6834
|
receiveShare,
|
|
6890
6835
|
restoreDelegatedShareKey,
|
|
6891
6836
|
resumeShareAuthorization,
|
|
6892
6837
|
revokeShare,
|
|
6893
6838
|
serializePortableDelegation,
|
|
6894
6839
|
shareCapabilityAllows,
|
|
6895
|
-
shareDeliveryTrustedKid,
|
|
6896
6840
|
showShare,
|
|
6897
6841
|
signShareEnvelope,
|
|
6898
6842
|
toShareErrorInfo,
|
|
@@ -6900,9 +6844,8 @@ export {
|
|
|
6900
6844
|
validateOwnerSharePolicyRegistration,
|
|
6901
6845
|
validateOwnerSharePolicyRegistrationBytes,
|
|
6902
6846
|
validateReceiveOptions,
|
|
6903
|
-
|
|
6847
|
+
validateShareDeliveryAuthorizationV3Bytes,
|
|
6904
6848
|
validateSharingServiceConfig,
|
|
6905
|
-
verifyBearerEnvelope,
|
|
6906
6849
|
verifyShareCid,
|
|
6907
6850
|
verifyShareEnvelope
|
|
6908
6851
|
};
|