@tinycloud/sdk-core 3.0.0-beta.8 → 3.0.0-beta.9
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 +24 -122
- 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 +25 -127
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +210 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -4
- package/dist/index.d.ts +57 -4
- package/dist/index.js +211 -129
- package/dist/index.js.map +1 -1
- package/dist/{recipient-types.schema-DjmM_yJu.d.cts → recipient-types.schema-C0igQ1kA.d.cts} +6 -100
- package/dist/{recipient-types.schema-DjmM_yJu.d.ts → recipient-types.schema-C0igQ1kA.d.ts} +6 -100
- package/package.json +3 -3
|
@@ -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 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
|
|
3
|
-
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage,
|
|
1
|
+
import { I as ICapabilityKeyRegistry, D as DelegationManager, R as Result, a as DelegationError } from '../recipient-types.schema-C0igQ1kA.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-C0igQ1kA.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 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
|
|
3
|
-
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage,
|
|
1
|
+
import { I as ICapabilityKeyRegistry, D as DelegationManager, R as Result, a as DelegationError } from '../recipient-types.schema-C0igQ1kA.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-C0igQ1kA.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
|
|
|
@@ -3287,25 +3287,33 @@ function parsePublishedShareLink(link, options = {}) {
|
|
|
3287
3287
|
}
|
|
3288
3288
|
const origin = normalizeOrigin(url.origin);
|
|
3289
3289
|
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.pathname === "/
|
|
3290
|
+
if (url.username !== "" || url.password !== "") throw new ShareEnvelopeError("invalid-link", "share link is not canonical");
|
|
3291
|
+
if (url.pathname === "/viewer") {
|
|
3292
|
+
const secretPayload = url.search === "" && url.hash.startsWith("#tc2=") ? url.hash.slice("#tc2=".length) : void 0;
|
|
3293
|
+
const publicPayload = url.hash === "" && url.searchParams.size === 1 ? url.searchParams.get("tc2") ?? void 0 : void 0;
|
|
3294
|
+
if (secretPayload === void 0 && publicPayload === void 0) throw new ShareEnvelopeError("invalid-link", "published share link is invalid");
|
|
3295
|
+
if (publicPayload !== void 0 && url.search !== `?tc2=${publicPayload}`) throw new ShareEnvelopeError("invalid-link", "published share link is not canonical");
|
|
3292
3296
|
let payload;
|
|
3293
3297
|
try {
|
|
3294
|
-
const bytes2 = base64UrlToBytes(
|
|
3298
|
+
const bytes2 = base64UrlToBytes(secretPayload ?? publicPayload);
|
|
3295
3299
|
if (bytes2.length > (options.maxInlineBytes ?? DEFAULT_MAX_INLINE_BYTES) * 2) throw new Error("inline payload too large");
|
|
3296
|
-
const
|
|
3300
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
|
|
3301
|
+
const value = JSON.parse(text);
|
|
3297
3302
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("inline payload shape");
|
|
3303
|
+
if (canonicalJson(value) !== text) throw new Error("inline payload is not canonical JSON");
|
|
3298
3304
|
payload = value;
|
|
3299
3305
|
} catch (error) {
|
|
3300
3306
|
throw new ShareEnvelopeError("invalid-link", error instanceof Error ? error.message : "invalid inline payload");
|
|
3301
3307
|
}
|
|
3302
|
-
|
|
3308
|
+
const payloadKeys = Object.keys(payload);
|
|
3309
|
+
if (payload.v !== 2 || typeof payload.c !== "string" || typeof payload.cid !== "string" || payload.k !== void 0 && typeof payload.k !== "string" || payloadKeys.some((key3) => !["v", "c", "cid", "k"].includes(key3)) || publicPayload !== void 0 && (payloadKeys.length !== 3 || payload.k !== void 0)) throw new ShareEnvelopeError("invalid-link", "inline payload fields are invalid");
|
|
3303
3310
|
const sealed = base64UrlToBytes(payload.c);
|
|
3304
3311
|
if (!verifyPublishedShareCid(payload.cid, sealed)) throw new ShareEnvelopeError("cid-mismatch", "inline payload CID does not match");
|
|
3305
3312
|
const key2 = payload.k === void 0 ? void 0 : base64UrlToBytes(payload.k);
|
|
3306
3313
|
if (key2 !== void 0 && key2.length !== 32) throw new ShareEnvelopeError("invalid-link", "inline payload key is invalid");
|
|
3307
3314
|
return { origin, cid: payload.cid, ...key2 === void 0 ? {} : { key: key2 }, sealed };
|
|
3308
3315
|
}
|
|
3316
|
+
if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share link is not canonical");
|
|
3309
3317
|
const match = /^\/s\/([a-z2-7]+)$/.exec(url.pathname);
|
|
3310
3318
|
if (match === null || !url.hash.startsWith("#k=")) throw new ShareEnvelopeError("invalid-link", "published share link is invalid");
|
|
3311
3319
|
const key = base64UrlToBytes(url.hash.slice(3));
|
|
@@ -3325,13 +3333,13 @@ function parseShareUrl(link, options = {}) {
|
|
|
3325
3333
|
} catch {
|
|
3326
3334
|
throw new ShareEnvelopeError("invalid-link", "share link must be an absolute URL");
|
|
3327
3335
|
}
|
|
3328
|
-
if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share links must not contain query parameters");
|
|
3329
3336
|
const origin = normalizeOrigin(url.origin);
|
|
3330
3337
|
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 === "/
|
|
3338
|
+
if (url.pathname === "/viewer" && (url.hash.startsWith("#tc2=") || url.searchParams.has("tc2"))) {
|
|
3332
3339
|
const published = parsePublishedShareLink(link, options);
|
|
3333
3340
|
return { kind: "inline", origin, cid: published.cid, key: published.key, url: `${url.origin}${url.pathname}`, protocol: "share-envelope-v2" };
|
|
3334
3341
|
}
|
|
3342
|
+
if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share links must not contain query parameters");
|
|
3335
3343
|
const match = url.pathname.match(/^\/s\/(i\/)?([^/]+)$/);
|
|
3336
3344
|
if (!match) throw new ShareEnvelopeError("invalid-link", "share link path is invalid");
|
|
3337
3345
|
const fragmentParams = url.hash === "" ? void 0 : new URLSearchParams(url.hash.slice(1));
|
|
@@ -3354,7 +3362,8 @@ function parseShareUrl(link, options = {}) {
|
|
|
3354
3362
|
}
|
|
3355
3363
|
function isV2ShareLink(link) {
|
|
3356
3364
|
try {
|
|
3357
|
-
|
|
3365
|
+
const url = new URL(link);
|
|
3366
|
+
return url.pathname.startsWith("/s/") || url.pathname === "/viewer";
|
|
3358
3367
|
} catch {
|
|
3359
3368
|
return link.startsWith(INLINE_PREFIX);
|
|
3360
3369
|
}
|
|
@@ -6593,114 +6602,13 @@ function validateOwnerSharePolicyRegistrationBytes(bytesValue, expected) {
|
|
|
6593
6602
|
return validateOwnerSharePolicyRegistration(value, expected);
|
|
6594
6603
|
}
|
|
6595
6604
|
|
|
6596
|
-
// src/delegations/share-delivery.ts
|
|
6597
|
-
import { ed25519 as ed255197 } from "@noble/curves/ed25519";
|
|
6598
|
-
var SHARE_DELIVERY_AUTHORIZATION_DOMAIN = "xyz.tinycloud.share/delivery-authorization/v2\0";
|
|
6599
|
-
function isCanonicalHttpsOrigin(value) {
|
|
6600
|
-
let url;
|
|
6601
|
-
try {
|
|
6602
|
-
url = new URL(value);
|
|
6603
|
-
} catch {
|
|
6604
|
-
return false;
|
|
6605
|
-
}
|
|
6606
|
-
return url.protocol === "https:" && url.origin === value && url.pathname === "/" && url.search === "" && url.hash === "" && url.username === "" && url.password === "";
|
|
6607
|
-
}
|
|
6608
|
-
var AUTHORIZATION_KEYS = [
|
|
6609
|
-
"type",
|
|
6610
|
-
"version",
|
|
6611
|
-
"jti",
|
|
6612
|
-
"shareCid",
|
|
6613
|
-
"shareId",
|
|
6614
|
-
"registrationCid",
|
|
6615
|
-
"delegationCid",
|
|
6616
|
-
"enforcementDelegationCid",
|
|
6617
|
-
"envelopeCid",
|
|
6618
|
-
"policyCid",
|
|
6619
|
-
"nodeAudience",
|
|
6620
|
-
"targetOrigin",
|
|
6621
|
-
"openCredentialsAudience",
|
|
6622
|
-
"holder",
|
|
6623
|
-
"recipientMatcher",
|
|
6624
|
-
"deliveryEmail",
|
|
6625
|
-
"shareUrl",
|
|
6626
|
-
"returnOrigin",
|
|
6627
|
-
"documentName",
|
|
6628
|
-
"senderDid",
|
|
6629
|
-
"senderTrust",
|
|
6630
|
-
"contentSource",
|
|
6631
|
-
"contentSourceDigest",
|
|
6632
|
-
"shareExpiresAt",
|
|
6633
|
-
"issuedAt",
|
|
6634
|
-
"reportAbuseToken",
|
|
6635
|
-
"actions",
|
|
6636
|
-
"resource",
|
|
6637
|
-
"authorityMaterialHandle",
|
|
6638
|
-
"authorityMaterialDigest",
|
|
6639
|
-
"requestBodyDigest",
|
|
6640
|
-
"idempotencyKey",
|
|
6641
|
-
"expiresAt",
|
|
6642
|
-
"dataAuthority"
|
|
6643
|
-
];
|
|
6644
|
-
function assertObject2(value, keys, label) {
|
|
6645
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} is invalid`);
|
|
6646
|
-
const record = value;
|
|
6647
|
-
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`);
|
|
6648
|
-
return record;
|
|
6649
|
-
}
|
|
6650
|
-
function fromB642(value) {
|
|
6651
|
-
if (!/^[A-Za-z0-9_-]+$/.test(value)) throw new Error("share delivery value is not canonical base64url");
|
|
6652
|
-
if (typeof atob === "function") {
|
|
6653
|
-
const padded = value.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - value.length % 4) % 4);
|
|
6654
|
-
return Uint8Array.from(atob(padded), (character) => character.charCodeAt(0));
|
|
6655
|
-
}
|
|
6656
|
-
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(value, "base64url"));
|
|
6657
|
-
throw new Error("base64url decoding is unavailable");
|
|
6658
|
-
}
|
|
6659
|
-
function validateShareDeliveryAuthorizationBytes(bytesValue, expected) {
|
|
6660
|
-
let value;
|
|
6661
|
-
try {
|
|
6662
|
-
value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytesValue));
|
|
6663
|
-
} catch {
|
|
6664
|
-
throw new Error("share delivery authorization response is not valid UTF-8 JSON");
|
|
6665
|
-
}
|
|
6666
|
-
const root = assertObject2(value, ["authorization", "proof"], "share delivery authorization response");
|
|
6667
|
-
const authorization = assertObject2(root.authorization, AUTHORIZATION_KEYS, "share delivery authorization");
|
|
6668
|
-
const proof = assertObject2(root.proof, ["alg", "kid", "signature"], "share delivery authorization proof");
|
|
6669
|
-
const request = expected.request;
|
|
6670
|
-
if (authorization.type !== "TinyCloudShareDeliveryAuthorization" || authorization.version !== 2 || authorization.dataAuthority !== false || authorization.jti !== request.jti || authorization.shareCid !== request.shareCid || authorization.shareId !== request.shareId || authorization.registrationCid !== request.registrationCid || authorization.delegationCid !== request.delegationCid || authorization.enforcementDelegationCid !== request.enforcementDelegationCid || authorization.envelopeCid !== request.envelopeCid || authorization.policyCid !== request.policyCid || authorization.deliveryEmail !== request.recipientEmail || authorization.shareUrl !== request.shareUrl || authorization.documentName !== request.documentName || authorization.requestBodyDigest !== request.requestBodyDigest || authorization.expiresAt !== request.expiresAt || authorization.idempotencyKey !== request.idempotencyKey || authorization.reportAbuseToken !== request.jti || authorization.authorityMaterialHandle !== request.registrationCid) {
|
|
6671
|
-
throw new Error("share delivery authorization is not bound to the submitted request");
|
|
6672
|
-
}
|
|
6673
|
-
if (typeof authorization.issuedAt !== "string" || Date.parse(authorization.issuedAt) > Date.now() + 6e4) throw new Error("share delivery authorization issuedAt is invalid");
|
|
6674
|
-
if (new Date(authorization.expiresAt).toISOString() !== authorization.expiresAt) throw new Error("share delivery authorization expiresAt is non-canonical");
|
|
6675
|
-
if (typeof authorization.openCredentialsAudience !== "string" || !isCanonicalHttpsOrigin(authorization.openCredentialsAudience) || authorization.openCredentialsAudience !== expected.credentialsAudience || authorization.openCredentialsAudience === authorization.nodeAudience || authorization.openCredentialsAudience === authorization.returnOrigin) {
|
|
6676
|
-
throw new Error("share delivery authorization openCredentialsAudience is missing or untrusted");
|
|
6677
|
-
}
|
|
6678
|
-
if (proof.alg !== "EdDSA" || typeof proof.kid !== "string" || typeof proof.signature !== "string") throw new Error("share delivery authorization proof is invalid");
|
|
6679
|
-
if (proof.kid !== expected.nodeProof.kid) throw new Error("share delivery authorization proof key is not trusted");
|
|
6680
|
-
const encodedKid = expected.nodeProof.publicKey;
|
|
6681
|
-
const publicKey = encodedKid.length === 34 && encodedKid[0] === 237 && encodedKid[1] === 1 ? encodedKid.slice(2) : encodedKid;
|
|
6682
|
-
if (publicKey.length !== 32) throw new Error("share delivery authorization proof key is invalid");
|
|
6683
|
-
const signatureBytes = fromB642(proof.signature);
|
|
6684
|
-
const signedBytes = new TextEncoder().encode(`${SHARE_DELIVERY_AUTHORIZATION_DOMAIN}${canonicalizeSignedObjectUnsigned(authorization)}`);
|
|
6685
|
-
if (signatureBytes.length !== 64 || !ed255197.verify(signatureBytes, signedBytes, publicKey)) throw new Error("share delivery authorization proof signature is invalid");
|
|
6686
|
-
return { authorization, proof };
|
|
6687
|
-
}
|
|
6688
|
-
function shareDeliveryTrustedKid(publicKey) {
|
|
6689
|
-
if (publicKey.length !== 32) throw new Error("share delivery node key must be a raw 32-byte Ed25519 public key");
|
|
6690
|
-
const prefixed = new Uint8Array(34);
|
|
6691
|
-
prefixed.set([237, 1]);
|
|
6692
|
-
prefixed.set(publicKey, 2);
|
|
6693
|
-
const did = `did:key:${base58btc.encode(prefixed)}`;
|
|
6694
|
-
return `${did}#${did.slice("did:key:".length)}`;
|
|
6695
|
-
}
|
|
6696
|
-
|
|
6697
6605
|
// src/delegations/share-delivery-v3.ts
|
|
6698
|
-
import { ed25519 as
|
|
6606
|
+
import { ed25519 as ed255197 } from "@noble/curves/ed25519";
|
|
6699
6607
|
import { sha256 as sha2568 } from "@noble/hashes/sha256";
|
|
6700
6608
|
var CREDENTIAL_INVITATION_REQUEST_DOMAIN = "xyz.tinycloud.credentials/invitation-request/v1\0";
|
|
6701
6609
|
var DELIVERY_ADMISSION_DOMAIN = "xyz.tinycloud.policy/delivery-admission/v0\0";
|
|
6702
|
-
var REQUEST_KEYS = ["schema", "policyId", "recipient", "resource", "credentialType", "returnLink", "envelopeRef", "audience", "issuedAt", "expiresAt", "nonce"];
|
|
6703
|
-
var ADMISSION_KEYS = ["schema", "policyId", "ownerDid", "recipient", "resource", "actions", "credentialType", "returnLink", "envelopeRef", "senderKeyDid", "audience", "issuedAt", "expiresAt", "nonce", "signature"];
|
|
6610
|
+
var REQUEST_KEYS = ["schema", "policyId", "recipient", "resource", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "audience", "issuedAt", "expiresAt", "nonce"];
|
|
6611
|
+
var ADMISSION_KEYS = ["schema", "policyId", "ownerDid", "recipient", "resource", "actions", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "senderKeyDid", "audience", "issuedAt", "expiresAt", "nonce", "signature"];
|
|
6704
6612
|
function exactObject(value, keys, label) {
|
|
6705
6613
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} is invalid`);
|
|
6706
6614
|
const record = value;
|
|
@@ -6744,15 +6652,16 @@ function validateShareDeliveryAuthorizationV3Bytes(bytes2, expected) {
|
|
|
6744
6652
|
const contentSource = object(envelope.contentSource, "v3 content source");
|
|
6745
6653
|
const envelopeSignature = object(envelope.signature, "v3 envelope signature");
|
|
6746
6654
|
const target = object(envelope.target, "v3 target");
|
|
6747
|
-
const
|
|
6748
|
-
|
|
6655
|
+
const binding = object(envelope.attestedEnforcerBinding, "v3 attested enforcer binding");
|
|
6656
|
+
const fields = ["policyId", "recipient", "resource", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "audience", "issuedAt", "expiresAt", "nonce"];
|
|
6657
|
+
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");
|
|
6749
6658
|
const issuedAt = Date.parse(String(request.issuedAt));
|
|
6750
6659
|
const expiresAt = Date.parse(String(request.expiresAt));
|
|
6751
6660
|
if (!Number.isFinite(issuedAt) || !Number.isFinite(expiresAt) || expiresAt <= issuedAt || expiresAt - issuedAt > 15 * 6e4) throw new Error("v3 share delivery authorization time is invalid");
|
|
6752
6661
|
const admissionSignature = decodeBase64Url2(signature.value);
|
|
6753
6662
|
const { signature: _signature, ...unsignedAdmission } = admission;
|
|
6754
6663
|
const digest4 = sha2568(new TextEncoder().encode(`${DELIVERY_ADMISSION_DOMAIN}${canonicalizeSignedObjectUnsigned(unsignedAdmission)}`));
|
|
6755
|
-
if (admissionSignature.length !== 64 || !
|
|
6664
|
+
if (admissionSignature.length !== 64 || !ed255197.verify(admissionSignature, digest4, didKeyBytes(String(signature.signerDid)))) throw new Error("v3 share delivery admission signature is invalid");
|
|
6756
6665
|
return { request, admission };
|
|
6757
6666
|
}
|
|
6758
6667
|
|
|
@@ -6876,9 +6785,6 @@ import {
|
|
|
6876
6785
|
publishPolicyShare,
|
|
6877
6786
|
claimShare,
|
|
6878
6787
|
resumeShareAuthorization,
|
|
6879
|
-
isLegacyShareLink,
|
|
6880
|
-
receiveLegacyShare,
|
|
6881
|
-
migrateShare,
|
|
6882
6788
|
MemoryEncryptedShareHistoryStorage,
|
|
6883
6789
|
EncryptedSenderShareHistory
|
|
6884
6790
|
} from "@tinycloud/share-sdk";
|
|
@@ -6886,8 +6792,7 @@ import {
|
|
|
6886
6792
|
inspectShare,
|
|
6887
6793
|
receiveShare,
|
|
6888
6794
|
ShareReceiveError,
|
|
6889
|
-
toShareErrorInfo
|
|
6890
|
-
verifyBearerEnvelope
|
|
6795
|
+
toShareErrorInfo
|
|
6891
6796
|
} from "@tinycloud/share-sdk";
|
|
6892
6797
|
export {
|
|
6893
6798
|
CREDENTIAL_INVITATION_REQUEST_DOMAIN,
|
|
@@ -6905,7 +6810,6 @@ export {
|
|
|
6905
6810
|
MemorySenderShareRecordStorage,
|
|
6906
6811
|
MemoryShareCache,
|
|
6907
6812
|
ReceiveOptionsSchema,
|
|
6908
|
-
SHARE_DELIVERY_AUTHORIZATION_DOMAIN,
|
|
6909
6813
|
SenderShareStore,
|
|
6910
6814
|
ShareAccessError,
|
|
6911
6815
|
ShareActionSchema,
|
|
@@ -6945,10 +6849,8 @@ export {
|
|
|
6945
6849
|
importPortableDelegation,
|
|
6946
6850
|
inspectShare,
|
|
6947
6851
|
intersectShareCapabilities,
|
|
6948
|
-
isLegacyShareLink,
|
|
6949
6852
|
isV2ShareLink,
|
|
6950
6853
|
listShares,
|
|
6951
|
-
migrateShare,
|
|
6952
6854
|
normalizeShareActions,
|
|
6953
6855
|
normalizeShareRecipientTarget,
|
|
6954
6856
|
normalizeShareResource,
|
|
@@ -6958,14 +6860,12 @@ export {
|
|
|
6958
6860
|
parseShareUrl,
|
|
6959
6861
|
publishPolicyShare,
|
|
6960
6862
|
publishTargetShare,
|
|
6961
|
-
receiveLegacyShare,
|
|
6962
6863
|
receiveShare,
|
|
6963
6864
|
restoreDelegatedShareKey,
|
|
6964
6865
|
resumeShareAuthorization,
|
|
6965
6866
|
revokeShare,
|
|
6966
6867
|
serializePortableDelegation,
|
|
6967
6868
|
shareCapabilityAllows,
|
|
6968
|
-
shareDeliveryTrustedKid,
|
|
6969
6869
|
showShare,
|
|
6970
6870
|
signShareEnvelope,
|
|
6971
6871
|
toShareErrorInfo,
|
|
@@ -6973,10 +6873,8 @@ export {
|
|
|
6973
6873
|
validateOwnerSharePolicyRegistration,
|
|
6974
6874
|
validateOwnerSharePolicyRegistrationBytes,
|
|
6975
6875
|
validateReceiveOptions,
|
|
6976
|
-
validateShareDeliveryAuthorizationBytes,
|
|
6977
6876
|
validateShareDeliveryAuthorizationV3Bytes,
|
|
6978
6877
|
validateSharingServiceConfig,
|
|
6979
|
-
verifyBearerEnvelope,
|
|
6980
6878
|
verifyShareCid,
|
|
6981
6879
|
verifyShareEnvelope
|
|
6982
6880
|
};
|