@tinycloud/node-sdk 3.0.0-beta.5 → 3.0.0-beta.7
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/{core-C6Czyr52.d.cts → core-WJQ9KiSD.d.cts} +21 -4
- package/dist/{core-C6Czyr52.d.ts → core-WJQ9KiSD.d.ts} +21 -4
- package/dist/core.cjs +36 -36
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +39 -38
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +36 -36
- 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 +39 -38
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -22211,63 +22211,63 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22211
22211
|
}
|
|
22212
22212
|
};
|
|
22213
22213
|
}
|
|
22214
|
-
/** Register a policy
|
|
22215
|
-
async
|
|
22214
|
+
/** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
|
|
22215
|
+
async registerPolicy(params) {
|
|
22216
22216
|
this._serviceGraph.assertActive();
|
|
22217
|
-
|
|
22218
|
-
|
|
22219
|
-
|
|
22220
|
-
|
|
22221
|
-
body: JSON.stringify({
|
|
22222
|
-
policy: { bytes: base64UrlEncode(params.policy.bytes), cid: params.policy.cid, proof: params.policy.proof },
|
|
22223
|
-
ownerDelegation: { cid: params.ownerDelegation.delegationCid, dagCbor: base64UrlEncode(params.ownerDelegation.signedDagCbor) },
|
|
22224
|
-
enforcementDelegation: params.enforcementDelegation,
|
|
22225
|
-
contentSourceDigest: params.contentSourceDigest
|
|
22226
|
-
})
|
|
22217
|
+
return (0, import_sdk_core7.registerPolicyV3)({
|
|
22218
|
+
...params,
|
|
22219
|
+
nodeOrigin: this.config.host,
|
|
22220
|
+
fetch: globalThis.fetch.bind(globalThis)
|
|
22227
22221
|
});
|
|
22228
|
-
if (!response.ok) {
|
|
22229
|
-
let code = "";
|
|
22230
|
-
try {
|
|
22231
|
-
const body = await response.clone().json();
|
|
22232
|
-
if (typeof body.error?.code === "string") code = ` ${body.error.code}`;
|
|
22233
|
-
} catch {
|
|
22234
|
-
}
|
|
22235
|
-
throw new Error(`Owner share policy registration failed: ${response.status}${code}`);
|
|
22236
|
-
}
|
|
22237
|
-
const responseBytes = new Uint8Array(await response.arrayBuffer());
|
|
22238
|
-
return (0, import_sdk_core7.validateOwnerSharePolicyRegistrationBytes)(responseBytes, params);
|
|
22239
22222
|
}
|
|
22240
|
-
/**
|
|
22223
|
+
/** @deprecated Policy/v2 delivery transport is retired. Use authorizeShareDeliveryV3. */
|
|
22241
22224
|
async authorizeShareDelivery(input) {
|
|
22225
|
+
void input;
|
|
22226
|
+
throw new Error("Policy/v2 share delivery is retired; use authorizeShareDeliveryV3");
|
|
22227
|
+
}
|
|
22228
|
+
/** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
|
|
22229
|
+
async authorizeShareDeliveryV3(input) {
|
|
22242
22230
|
const session = this.currentTinyCloudSession();
|
|
22243
22231
|
const serviceSession = this._serviceContext?.session;
|
|
22244
22232
|
if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
|
|
22245
22233
|
const body = {
|
|
22246
|
-
|
|
22234
|
+
envelope: input.envelope,
|
|
22235
|
+
sealedEnvelope: input.sealedEnvelope,
|
|
22236
|
+
envelopeKey: input.envelopeKey,
|
|
22247
22237
|
shareCid: input.shareCid,
|
|
22248
|
-
shareId: input.shareId,
|
|
22249
|
-
registrationCid: input.registrationCid,
|
|
22250
|
-
policyCid: input.policyCid,
|
|
22251
|
-
delegationCid: input.delegationCid,
|
|
22252
|
-
enforcementDelegationCid: input.enforcementDelegationCid,
|
|
22253
22238
|
recipientEmail: input.recipientEmail,
|
|
22254
22239
|
shareUrl: input.shareUrl,
|
|
22255
22240
|
documentName: input.documentName,
|
|
22256
22241
|
jti: base64UrlEncode(crypto.getRandomValues(new Uint8Array(16))),
|
|
22257
|
-
|
|
22258
|
-
expiresAt: input.expiresAt
|
|
22242
|
+
expiresAt: new Date(input.expiresAt).toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
22259
22243
|
};
|
|
22260
22244
|
const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core7.canonicalizeEncryptionJson)(body)))));
|
|
22261
22245
|
const request = { ...body, requestBodyDigest };
|
|
22262
22246
|
const authorization = authorizationHeader(this.invokeAnyWithRuntimePermissions(serviceSession, [{ spaceId: session.spaceId, service: "kv", path: input.resourcePath, action: "tinycloud.kv/get" }]));
|
|
22263
|
-
const response = await fetch(`${this.config.host}/
|
|
22247
|
+
const response = await fetch(`${this.config.host}/policy/v3/deliveries/authorize`, {
|
|
22264
22248
|
method: "POST",
|
|
22265
22249
|
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
22266
22250
|
body: (0, import_sdk_core7.canonicalizeEncryptionJson)(request)
|
|
22267
22251
|
});
|
|
22268
|
-
if (!response.ok) throw new Error(`
|
|
22269
|
-
const
|
|
22270
|
-
|
|
22252
|
+
if (!response.ok) throw new Error(`V3 share delivery authorization failed: ${response.status}`);
|
|
22253
|
+
const verified = (0, import_sdk_core7.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
|
|
22254
|
+
request,
|
|
22255
|
+
senderKeyDid: this.credentialHolderDid,
|
|
22256
|
+
credentialsAudience: input.credentialsAudience
|
|
22257
|
+
});
|
|
22258
|
+
void input.nodeProof;
|
|
22259
|
+
const requestDigest = new Uint8Array(await crypto.subtle.digest(
|
|
22260
|
+
"SHA-256",
|
|
22261
|
+
new TextEncoder().encode(`${import_sdk_core7.CREDENTIAL_INVITATION_REQUEST_DOMAIN}${(0, import_sdk_core7.canonicalizeEncryptionJson)(verified.request)}`)
|
|
22262
|
+
));
|
|
22263
|
+
return {
|
|
22264
|
+
...verified,
|
|
22265
|
+
proof: {
|
|
22266
|
+
alg: "EdDSA",
|
|
22267
|
+
kid: this.credentialHolderDid,
|
|
22268
|
+
signature: base64UrlEncode(await this.signSessionBytes(requestDigest))
|
|
22269
|
+
}
|
|
22270
|
+
};
|
|
22271
22271
|
}
|
|
22272
22272
|
async createRootDelegationForSharing(params, assertActive) {
|
|
22273
22273
|
try {
|