@tinycloud/sdk-core 3.6.1 → 3.7.0-beta.1
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 +35 -6
- 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 +35 -6
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +35 -6
- 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 +35 -6
- package/dist/index.js.map +1 -1
- package/dist/{recipient-types.schema-DbCAdUKc.d.cts → recipient-types.schema-BApcOn1t.d.cts} +32 -9
- package/dist/{recipient-types.schema-DbCAdUKc.d.ts → recipient-types.schema-BApcOn1t.d.ts} +32 -9
- package/package.json +3 -3
|
@@ -54,6 +54,7 @@ __export(delegations_exports, {
|
|
|
54
54
|
ShareAddressedDelegationRequestV2Schema: () => ShareAddressedDelegationRequestV2Schema,
|
|
55
55
|
ShareAddressedDelegationResponseV2Schema: () => ShareAddressedDelegationResponseV2Schema,
|
|
56
56
|
ShareConflict: () => ShareConflict,
|
|
57
|
+
ShareDeliveryRefusedError: () => ShareDeliveryRefusedError,
|
|
57
58
|
ShareEnvelopeError: () => ShareEnvelopeError,
|
|
58
59
|
ShareNativeResponseSchema: () => ShareNativeResponseSchema,
|
|
59
60
|
ShareReceiveError: () => import_share_sdk2.ShareReceiveError,
|
|
@@ -103,6 +104,7 @@ __export(delegations_exports, {
|
|
|
103
104
|
revokeShare: () => import_share_sdk.revokeShare,
|
|
104
105
|
serializePortableDelegation: () => serializePortableDelegation,
|
|
105
106
|
shareCapabilityAllows: () => shareCapabilityAllows,
|
|
107
|
+
shortDeliveryLinkBodyCid: () => shortDeliveryLinkBodyCid,
|
|
106
108
|
showShare: () => import_share_sdk.showShare,
|
|
107
109
|
signShareEnvelope: () => signShareEnvelope,
|
|
108
110
|
toShareErrorInfo: () => import_share_sdk2.toShareErrorInfo,
|
|
@@ -110,10 +112,11 @@ __export(delegations_exports, {
|
|
|
110
112
|
validateOwnerSharePolicyRegistration: () => validateOwnerSharePolicyRegistration,
|
|
111
113
|
validateOwnerSharePolicyRegistrationBytes: () => validateOwnerSharePolicyRegistrationBytes,
|
|
112
114
|
validateReceiveOptions: () => validateReceiveOptions,
|
|
113
|
-
validateShareDeliveryAuthorizationV3Bytes: () => validateShareDeliveryAuthorizationV3Bytes,
|
|
114
115
|
validateSharingServiceConfig: () => validateSharingServiceConfig,
|
|
115
116
|
verifyShareCid: () => verifyShareCid,
|
|
116
|
-
|
|
117
|
+
verifyShareDeliveryAuthorizationV3Bytes: () => verifyShareDeliveryAuthorizationV3Bytes,
|
|
118
|
+
verifyShareEnvelope: () => verifyShareEnvelope,
|
|
119
|
+
withoutShareLink: () => withoutShareLink
|
|
117
120
|
});
|
|
118
121
|
module.exports = __toCommonJS(delegations_exports);
|
|
119
122
|
|
|
@@ -6625,7 +6628,7 @@ function validateOwnerSharePolicyRegistrationBytes(bytesValue, expected) {
|
|
|
6625
6628
|
var import_ed255197 = require("@noble/curves/ed25519");
|
|
6626
6629
|
var import_sha2566 = require("@noble/hashes/sha256");
|
|
6627
6630
|
var CREDENTIAL_INVITATION_REQUEST_DOMAIN = "xyz.tinycloud.credentials/invitation-request/v1\0";
|
|
6628
|
-
var DELIVERY_ADMISSION_DOMAIN = "xyz.tinycloud.policy/delivery-admission/
|
|
6631
|
+
var DELIVERY_ADMISSION_DOMAIN = "xyz.tinycloud.policy/delivery-admission/v1\0";
|
|
6629
6632
|
var REQUEST_KEYS = ["schema", "policyId", "recipient", "resource", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "audience", "issuedAt", "expiresAt", "nonce"];
|
|
6630
6633
|
var ADMISSION_KEYS = ["schema", "policyId", "ownerDid", "recipient", "resource", "actions", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "senderKeyDid", "audience", "issuedAt", "expiresAt", "nonce", "signature"];
|
|
6631
6634
|
function exactObject(value, keys, label) {
|
|
@@ -6664,7 +6667,7 @@ function validateShareDeliveryAuthorizationV3Bytes(bytes2, expected) {
|
|
|
6664
6667
|
const request = exactObject(root.request, REQUEST_KEYS, "credential invitation request");
|
|
6665
6668
|
const admission = exactObject(root.admission, ADMISSION_KEYS, "delivery admission");
|
|
6666
6669
|
const signature = exactObject(admission.signature, ["suite", "signerDid", "value"], "delivery admission signature");
|
|
6667
|
-
const envelope = object(expected.
|
|
6670
|
+
const envelope = object(expected.envelope, "v3 share envelope");
|
|
6668
6671
|
const policy = object(envelope.policy, "v3 share policy");
|
|
6669
6672
|
const requirement = object(policy.credentialRequirement, "v3 credential requirement");
|
|
6670
6673
|
const credentialType = object(requirement.credentialType, "v3 credential type");
|
|
@@ -6673,16 +6676,42 @@ function validateShareDeliveryAuthorizationV3Bytes(bytes2, expected) {
|
|
|
6673
6676
|
const target = object(envelope.target, "v3 target");
|
|
6674
6677
|
const binding = object(envelope.attestedEnforcerBinding, "v3 attested enforcer binding");
|
|
6675
6678
|
const fields = ["policyId", "recipient", "resource", "credentialType", "returnLink", "envelopeRef", "label", "shareExpiresAt", "audience", "issuedAt", "expiresAt", "nonce"];
|
|
6676
|
-
if (request.schema !== "xyz.tinycloud.credentials/invitation-request/v1" || admission.schema !== "xyz.tinycloud.policy/delivery-admission/
|
|
6679
|
+
if (request.schema !== "xyz.tinycloud.credentials/invitation-request/v1" || admission.schema !== "xyz.tinycloud.policy/delivery-admission/v1" || 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.envelopeRef || 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");
|
|
6677
6680
|
const issuedAt = Date.parse(String(request.issuedAt));
|
|
6678
6681
|
const expiresAt = Date.parse(String(request.expiresAt));
|
|
6679
6682
|
if (!Number.isFinite(issuedAt) || !Number.isFinite(expiresAt) || expiresAt <= issuedAt || expiresAt - issuedAt > 15 * 6e4) throw new Error("v3 share delivery authorization time is invalid");
|
|
6680
6683
|
const admissionSignature = decodeBase64Url2(signature.value);
|
|
6681
6684
|
const { signature: _signature, ...unsignedAdmission } = admission;
|
|
6682
|
-
const digest4 = (
|
|
6685
|
+
const digest4 = admissionDigest(unsignedAdmission);
|
|
6683
6686
|
if (admissionSignature.length !== 64 || !import_ed255197.ed25519.verify(admissionSignature, digest4, didKeyBytes(String(signature.signerDid)))) throw new Error("v3 share delivery admission signature is invalid");
|
|
6684
6687
|
return { request, admission };
|
|
6685
6688
|
}
|
|
6689
|
+
function admissionDigest(unsignedAdmission) {
|
|
6690
|
+
return (0, import_sha2566.sha256)(new TextEncoder().encode(`${DELIVERY_ADMISSION_DOMAIN}${canonicalizeSignedObjectUnsigned(unsignedAdmission)}`));
|
|
6691
|
+
}
|
|
6692
|
+
async function verifyShareDeliveryAuthorizationV3Bytes(bytes2, expected) {
|
|
6693
|
+
const verified = validateShareDeliveryAuthorizationV3Bytes(bytes2, expected);
|
|
6694
|
+
const { signature, ...unsignedAdmission } = verified.admission;
|
|
6695
|
+
(await import("@tinycloud/share-envelope/links")).assertDidKeySignature(signature.signerDid, admissionDigest(unsignedAdmission), signature.value);
|
|
6696
|
+
return verified;
|
|
6697
|
+
}
|
|
6698
|
+
async function shortDeliveryLinkBodyCid(shareUrl, trustedOrigins) {
|
|
6699
|
+
const links = await import("@tinycloud/share-envelope/links");
|
|
6700
|
+
const cid2 = links.shortShareLinkCid(shareUrl, { trustedOrigins: trustedOrigins ?? links.DEFAULT_SHARE_ORIGINS });
|
|
6701
|
+
if (cid2 === void 0) throw new Error("share delivery requires a short share link");
|
|
6702
|
+
return cid2;
|
|
6703
|
+
}
|
|
6704
|
+
async function withoutShareLink(text, shareUrl) {
|
|
6705
|
+
return (await import("@tinycloud/share-envelope/links")).redactLink(text, shareUrl);
|
|
6706
|
+
}
|
|
6707
|
+
var ShareDeliveryRefusedError = class extends Error {
|
|
6708
|
+
constructor() {
|
|
6709
|
+
super("share delivery authorization refused");
|
|
6710
|
+
this.code = "delivery-authorization-invalid";
|
|
6711
|
+
this.status = 400;
|
|
6712
|
+
this.name = "ShareDeliveryRefusedError";
|
|
6713
|
+
}
|
|
6714
|
+
};
|
|
6686
6715
|
|
|
6687
6716
|
// src/delegations/sender-share-store.ts
|
|
6688
6717
|
var MemorySenderShareRecordStorage = class {
|