@tinycloud/node-sdk 2.10.0-beta.0 → 2.10.0
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-C4dXaqwM.d.cts → core-B_i2KfID.d.cts} +25 -1
- package/dist/{core-C4dXaqwM.d.ts → core-B_i2KfID.d.ts} +25 -1
- package/dist/core.cjs +63 -6
- 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 +66 -7
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +68 -11
- 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 +71 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -14963,10 +14963,10 @@ function randomBytes(length) {
|
|
|
14963
14963
|
logger21.throwArgumentError("invalid length", "length", length);
|
|
14964
14964
|
}
|
|
14965
14965
|
const result = new Uint8Array(length);
|
|
14966
|
-
|
|
14966
|
+
crypto2.getRandomValues(result);
|
|
14967
14967
|
return arrayify(result);
|
|
14968
14968
|
}
|
|
14969
|
-
var logger21, anyGlobal,
|
|
14969
|
+
var logger21, anyGlobal, crypto2;
|
|
14970
14970
|
var init_random = __esm({
|
|
14971
14971
|
"../../node_modules/@ethersproject/random/lib.esm/random.js"() {
|
|
14972
14972
|
"use strict";
|
|
@@ -14975,10 +14975,10 @@ var init_random = __esm({
|
|
|
14975
14975
|
init_version16();
|
|
14976
14976
|
logger21 = new Logger(version16);
|
|
14977
14977
|
anyGlobal = getGlobal();
|
|
14978
|
-
|
|
14979
|
-
if (!
|
|
14978
|
+
crypto2 = anyGlobal.crypto || anyGlobal.msCrypto;
|
|
14979
|
+
if (!crypto2 || !crypto2.getRandomValues) {
|
|
14980
14980
|
logger21.warn("WARNING: Missing strong random number source");
|
|
14981
|
-
|
|
14981
|
+
crypto2 = {
|
|
14982
14982
|
getRandomValues: function(buffer) {
|
|
14983
14983
|
return logger21.throwError("no secure random source avaialble", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
14984
14984
|
operation: "crypto.getRandomValues"
|
|
@@ -18753,8 +18753,8 @@ function decodeAuthorizationBytes(authorization) {
|
|
|
18753
18753
|
if (unpadded === void 0 || remainder === 1 || paddingLength !== 0 && paddingLength !== expectedPaddingLength) {
|
|
18754
18754
|
throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
|
|
18755
18755
|
}
|
|
18756
|
-
const decoded =
|
|
18757
|
-
if (
|
|
18756
|
+
const decoded = base64UrlDecode(unpadded);
|
|
18757
|
+
if (base64UrlEncode(decoded) !== unpadded) {
|
|
18758
18758
|
throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
|
|
18759
18759
|
}
|
|
18760
18760
|
return decoded;
|
|
@@ -20910,7 +20910,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20910
20910
|
const did = binding?.did ?? this.did;
|
|
20911
20911
|
const address = binding?.address ?? this._address;
|
|
20912
20912
|
const chainId = binding?.chainId ?? this._chainId;
|
|
20913
|
-
const
|
|
20913
|
+
const crypto3 = this.createEncryptionCrypto();
|
|
20914
20914
|
const descriptorCache = /* @__PURE__ */ new Map();
|
|
20915
20915
|
const transport = {
|
|
20916
20916
|
postDecrypt: async ({ networkId, authorization, canonicalBody, signal }) => {
|
|
@@ -20945,7 +20945,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20945
20945
|
}
|
|
20946
20946
|
};
|
|
20947
20947
|
return new import_sdk_core7.EncryptionService({
|
|
20948
|
-
crypto:
|
|
20948
|
+
crypto: crypto3,
|
|
20949
20949
|
signer: {
|
|
20950
20950
|
signDecryptInvocation: async (input) => {
|
|
20951
20951
|
graph.assertActive();
|
|
@@ -21354,6 +21354,63 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21354
21354
|
}
|
|
21355
21355
|
};
|
|
21356
21356
|
}
|
|
21357
|
+
/** Register a policy that is already bound to an activated owner delegation. */
|
|
21358
|
+
async registerOwnerSharePolicy(params) {
|
|
21359
|
+
this._serviceGraph.assertActive();
|
|
21360
|
+
if (params.policy.bytes.byteLength > 2 * 1024 * 1024) throw new Error("Owner share policy is too large");
|
|
21361
|
+
const response = await fetch(`${this.config.host}/share/v2/policies`, {
|
|
21362
|
+
method: "POST",
|
|
21363
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
21364
|
+
body: JSON.stringify({
|
|
21365
|
+
policy: { bytes: base64UrlEncode(params.policy.bytes), cid: params.policy.cid, proof: params.policy.proof },
|
|
21366
|
+
ownerDelegation: { cid: params.ownerDelegation.delegationCid, dagCbor: base64UrlEncode(params.ownerDelegation.signedDagCbor) },
|
|
21367
|
+
enforcementDelegation: params.enforcementDelegation,
|
|
21368
|
+
contentSourceDigest: params.contentSourceDigest
|
|
21369
|
+
})
|
|
21370
|
+
});
|
|
21371
|
+
if (!response.ok) {
|
|
21372
|
+
let code = "";
|
|
21373
|
+
try {
|
|
21374
|
+
const body = await response.clone().json();
|
|
21375
|
+
if (typeof body.error?.code === "string") code = ` ${body.error.code}`;
|
|
21376
|
+
} catch {
|
|
21377
|
+
}
|
|
21378
|
+
throw new Error(`Owner share policy registration failed: ${response.status}${code}`);
|
|
21379
|
+
}
|
|
21380
|
+
const responseBytes = new Uint8Array(await response.arrayBuffer());
|
|
21381
|
+
return (0, import_sdk_core7.validateOwnerSharePolicyRegistrationBytes)(responseBytes, params);
|
|
21382
|
+
}
|
|
21383
|
+
/** Authorize a short-lived, one-use v2 delivery using the authenticated invocation chain. */
|
|
21384
|
+
async authorizeShareDelivery(input) {
|
|
21385
|
+
const session = this.currentTinyCloudSession();
|
|
21386
|
+
const serviceSession = this._serviceContext?.session;
|
|
21387
|
+
if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
|
|
21388
|
+
const body = {
|
|
21389
|
+
envelopeCid: input.envelopeCid,
|
|
21390
|
+
shareCid: input.shareCid,
|
|
21391
|
+
shareId: input.shareId,
|
|
21392
|
+
registrationCid: input.registrationCid,
|
|
21393
|
+
policyCid: input.policyCid,
|
|
21394
|
+
delegationCid: input.delegationCid,
|
|
21395
|
+
enforcementDelegationCid: input.enforcementDelegationCid,
|
|
21396
|
+
recipientEmail: input.recipientEmail,
|
|
21397
|
+
shareUrl: input.shareUrl,
|
|
21398
|
+
documentName: input.documentName,
|
|
21399
|
+
jti: base64UrlEncode(crypto.getRandomValues(new Uint8Array(16))),
|
|
21400
|
+
expiresAt: input.expiresAt
|
|
21401
|
+
};
|
|
21402
|
+
const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core7.canonicalizeEncryptionJson)(body)))));
|
|
21403
|
+
const request = { ...body, requestBodyDigest };
|
|
21404
|
+
const authorization = authorizationHeader(this.invokeAnyWithRuntimePermissions(serviceSession, [{ spaceId: session.spaceId, service: "kv", path: input.resourcePath, action: "tinycloud.kv/get" }]));
|
|
21405
|
+
const response = await fetch(`${this.config.host}/share/v2/deliveries/authorize`, {
|
|
21406
|
+
method: "POST",
|
|
21407
|
+
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
21408
|
+
body: (0, import_sdk_core7.canonicalizeEncryptionJson)(request)
|
|
21409
|
+
});
|
|
21410
|
+
if (!response.ok) throw new Error(`Share delivery authorization failed: ${response.status}`);
|
|
21411
|
+
const responseBytes = new Uint8Array(await response.arrayBuffer());
|
|
21412
|
+
return (0, import_sdk_core7.validateShareDeliveryAuthorizationBytes)(responseBytes, { request, nodeProof: input.nodeProof, credentialsAudience: input.credentialsAudience });
|
|
21413
|
+
}
|
|
21357
21414
|
async createRootDelegationForSharing(params, assertActive) {
|
|
21358
21415
|
try {
|
|
21359
21416
|
return (await this.createOwnerDelegation({
|
|
@@ -21522,13 +21579,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21522
21579
|
ownerDid,
|
|
21523
21580
|
threshold: { n: 1, t: 1 }
|
|
21524
21581
|
};
|
|
21525
|
-
const
|
|
21582
|
+
const crypto3 = this.createEncryptionCrypto();
|
|
21526
21583
|
const facts = {
|
|
21527
21584
|
type: NETWORK_ADMIN_TYPE,
|
|
21528
21585
|
targetNode,
|
|
21529
21586
|
networkId,
|
|
21530
21587
|
bodyHash: (0, import_sdk_core7.canonicalHashHex)(
|
|
21531
|
-
|
|
21588
|
+
crypto3.sha256,
|
|
21532
21589
|
body
|
|
21533
21590
|
),
|
|
21534
21591
|
action: NETWORK_CREATE_ACTION2
|