@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -1513,6 +1513,30 @@ declare class TinyCloudNode {
|
|
|
1513
1513
|
* @internal
|
|
1514
1514
|
*/
|
|
1515
1515
|
createOwnerDelegation(params: CreateOwnerDelegationParams, assertActive?: () => void): Promise<OwnerDelegationReceipt>;
|
|
1516
|
+
/** Register a policy that is already bound to an activated owner delegation. */
|
|
1517
|
+
registerOwnerSharePolicy(params: RegisterOwnerSharePolicyParams): Promise<OwnerSharePolicyRegistrationReceipt>;
|
|
1518
|
+
/** Authorize a short-lived, one-use v2 delivery using the authenticated invocation chain. */
|
|
1519
|
+
authorizeShareDelivery(input: {
|
|
1520
|
+
readonly envelopeCid: string;
|
|
1521
|
+
readonly shareCid: string;
|
|
1522
|
+
readonly shareId: string;
|
|
1523
|
+
readonly registrationCid: string;
|
|
1524
|
+
readonly policyCid: string;
|
|
1525
|
+
readonly delegationCid: string;
|
|
1526
|
+
readonly enforcementDelegationCid: string;
|
|
1527
|
+
readonly resourcePath: string;
|
|
1528
|
+
readonly recipientEmail: string;
|
|
1529
|
+
readonly shareUrl: string;
|
|
1530
|
+
readonly documentName: string;
|
|
1531
|
+
readonly expiresAt: string;
|
|
1532
|
+
/** The enrolled receipt key from the node trust bundle. */
|
|
1533
|
+
readonly nodeProof: {
|
|
1534
|
+
readonly kid: string;
|
|
1535
|
+
readonly publicKey: Uint8Array;
|
|
1536
|
+
};
|
|
1537
|
+
/** The trusted OpenCredentials witness origin from the same trust bundle as `nodeProof`. */
|
|
1538
|
+
readonly credentialsAudience: string;
|
|
1539
|
+
}): Promise<ShareDeliveryAuthorizationReceipt>;
|
|
1516
1540
|
private createRootDelegationForSharing;
|
|
1517
1541
|
/**
|
|
1518
1542
|
* Track a received delegation in the capability registry.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -1513,6 +1513,30 @@ declare class TinyCloudNode {
|
|
|
1513
1513
|
* @internal
|
|
1514
1514
|
*/
|
|
1515
1515
|
createOwnerDelegation(params: CreateOwnerDelegationParams, assertActive?: () => void): Promise<OwnerDelegationReceipt>;
|
|
1516
|
+
/** Register a policy that is already bound to an activated owner delegation. */
|
|
1517
|
+
registerOwnerSharePolicy(params: RegisterOwnerSharePolicyParams): Promise<OwnerSharePolicyRegistrationReceipt>;
|
|
1518
|
+
/** Authorize a short-lived, one-use v2 delivery using the authenticated invocation chain. */
|
|
1519
|
+
authorizeShareDelivery(input: {
|
|
1520
|
+
readonly envelopeCid: string;
|
|
1521
|
+
readonly shareCid: string;
|
|
1522
|
+
readonly shareId: string;
|
|
1523
|
+
readonly registrationCid: string;
|
|
1524
|
+
readonly policyCid: string;
|
|
1525
|
+
readonly delegationCid: string;
|
|
1526
|
+
readonly enforcementDelegationCid: string;
|
|
1527
|
+
readonly resourcePath: string;
|
|
1528
|
+
readonly recipientEmail: string;
|
|
1529
|
+
readonly shareUrl: string;
|
|
1530
|
+
readonly documentName: string;
|
|
1531
|
+
readonly expiresAt: string;
|
|
1532
|
+
/** The enrolled receipt key from the node trust bundle. */
|
|
1533
|
+
readonly nodeProof: {
|
|
1534
|
+
readonly kid: string;
|
|
1535
|
+
readonly publicKey: Uint8Array;
|
|
1536
|
+
};
|
|
1537
|
+
/** The trusted OpenCredentials witness origin from the same trust bundle as `nodeProof`. */
|
|
1538
|
+
readonly credentialsAudience: string;
|
|
1539
|
+
}): Promise<ShareDeliveryAuthorizationReceipt>;
|
|
1516
1540
|
private createRootDelegationForSharing;
|
|
1517
1541
|
/**
|
|
1518
1542
|
* Track a received delegation in the capability registry.
|
package/dist/core.cjs
CHANGED
|
@@ -1730,8 +1730,8 @@ function decodeAuthorizationBytes(authorization) {
|
|
|
1730
1730
|
if (unpadded === void 0 || remainder === 1 || paddingLength !== 0 && paddingLength !== expectedPaddingLength) {
|
|
1731
1731
|
throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
|
|
1732
1732
|
}
|
|
1733
|
-
const decoded =
|
|
1734
|
-
if (
|
|
1733
|
+
const decoded = base64UrlDecode(unpadded);
|
|
1734
|
+
if (base64UrlEncode(decoded) !== unpadded) {
|
|
1735
1735
|
throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
|
|
1736
1736
|
}
|
|
1737
1737
|
return decoded;
|
|
@@ -3887,7 +3887,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3887
3887
|
const did = binding?.did ?? this.did;
|
|
3888
3888
|
const address = binding?.address ?? this._address;
|
|
3889
3889
|
const chainId = binding?.chainId ?? this._chainId;
|
|
3890
|
-
const
|
|
3890
|
+
const crypto2 = this.createEncryptionCrypto();
|
|
3891
3891
|
const descriptorCache = /* @__PURE__ */ new Map();
|
|
3892
3892
|
const transport = {
|
|
3893
3893
|
postDecrypt: async ({ networkId, authorization, canonicalBody, signal }) => {
|
|
@@ -3922,7 +3922,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3922
3922
|
}
|
|
3923
3923
|
};
|
|
3924
3924
|
return new import_sdk_core8.EncryptionService({
|
|
3925
|
-
crypto,
|
|
3925
|
+
crypto: crypto2,
|
|
3926
3926
|
signer: {
|
|
3927
3927
|
signDecryptInvocation: async (input) => {
|
|
3928
3928
|
graph.assertActive();
|
|
@@ -4331,6 +4331,63 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4331
4331
|
}
|
|
4332
4332
|
};
|
|
4333
4333
|
}
|
|
4334
|
+
/** Register a policy that is already bound to an activated owner delegation. */
|
|
4335
|
+
async registerOwnerSharePolicy(params) {
|
|
4336
|
+
this._serviceGraph.assertActive();
|
|
4337
|
+
if (params.policy.bytes.byteLength > 2 * 1024 * 1024) throw new Error("Owner share policy is too large");
|
|
4338
|
+
const response = await fetch(`${this.config.host}/share/v2/policies`, {
|
|
4339
|
+
method: "POST",
|
|
4340
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
4341
|
+
body: JSON.stringify({
|
|
4342
|
+
policy: { bytes: base64UrlEncode(params.policy.bytes), cid: params.policy.cid, proof: params.policy.proof },
|
|
4343
|
+
ownerDelegation: { cid: params.ownerDelegation.delegationCid, dagCbor: base64UrlEncode(params.ownerDelegation.signedDagCbor) },
|
|
4344
|
+
enforcementDelegation: params.enforcementDelegation,
|
|
4345
|
+
contentSourceDigest: params.contentSourceDigest
|
|
4346
|
+
})
|
|
4347
|
+
});
|
|
4348
|
+
if (!response.ok) {
|
|
4349
|
+
let code = "";
|
|
4350
|
+
try {
|
|
4351
|
+
const body = await response.clone().json();
|
|
4352
|
+
if (typeof body.error?.code === "string") code = ` ${body.error.code}`;
|
|
4353
|
+
} catch {
|
|
4354
|
+
}
|
|
4355
|
+
throw new Error(`Owner share policy registration failed: ${response.status}${code}`);
|
|
4356
|
+
}
|
|
4357
|
+
const responseBytes = new Uint8Array(await response.arrayBuffer());
|
|
4358
|
+
return (0, import_sdk_core8.validateOwnerSharePolicyRegistrationBytes)(responseBytes, params);
|
|
4359
|
+
}
|
|
4360
|
+
/** Authorize a short-lived, one-use v2 delivery using the authenticated invocation chain. */
|
|
4361
|
+
async authorizeShareDelivery(input) {
|
|
4362
|
+
const session = this.currentTinyCloudSession();
|
|
4363
|
+
const serviceSession = this._serviceContext?.session;
|
|
4364
|
+
if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
|
|
4365
|
+
const body = {
|
|
4366
|
+
envelopeCid: input.envelopeCid,
|
|
4367
|
+
shareCid: input.shareCid,
|
|
4368
|
+
shareId: input.shareId,
|
|
4369
|
+
registrationCid: input.registrationCid,
|
|
4370
|
+
policyCid: input.policyCid,
|
|
4371
|
+
delegationCid: input.delegationCid,
|
|
4372
|
+
enforcementDelegationCid: input.enforcementDelegationCid,
|
|
4373
|
+
recipientEmail: input.recipientEmail,
|
|
4374
|
+
shareUrl: input.shareUrl,
|
|
4375
|
+
documentName: input.documentName,
|
|
4376
|
+
jti: base64UrlEncode(crypto.getRandomValues(new Uint8Array(16))),
|
|
4377
|
+
expiresAt: input.expiresAt
|
|
4378
|
+
};
|
|
4379
|
+
const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core8.canonicalizeEncryptionJson)(body)))));
|
|
4380
|
+
const request = { ...body, requestBodyDigest };
|
|
4381
|
+
const authorization = authorizationHeader(this.invokeAnyWithRuntimePermissions(serviceSession, [{ spaceId: session.spaceId, service: "kv", path: input.resourcePath, action: "tinycloud.kv/get" }]));
|
|
4382
|
+
const response = await fetch(`${this.config.host}/share/v2/deliveries/authorize`, {
|
|
4383
|
+
method: "POST",
|
|
4384
|
+
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
4385
|
+
body: (0, import_sdk_core8.canonicalizeEncryptionJson)(request)
|
|
4386
|
+
});
|
|
4387
|
+
if (!response.ok) throw new Error(`Share delivery authorization failed: ${response.status}`);
|
|
4388
|
+
const responseBytes = new Uint8Array(await response.arrayBuffer());
|
|
4389
|
+
return (0, import_sdk_core8.validateShareDeliveryAuthorizationBytes)(responseBytes, { request, nodeProof: input.nodeProof, credentialsAudience: input.credentialsAudience });
|
|
4390
|
+
}
|
|
4334
4391
|
async createRootDelegationForSharing(params, assertActive) {
|
|
4335
4392
|
try {
|
|
4336
4393
|
return (await this.createOwnerDelegation({
|
|
@@ -4499,13 +4556,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4499
4556
|
ownerDid,
|
|
4500
4557
|
threshold: { n: 1, t: 1 }
|
|
4501
4558
|
};
|
|
4502
|
-
const
|
|
4559
|
+
const crypto2 = this.createEncryptionCrypto();
|
|
4503
4560
|
const facts = {
|
|
4504
4561
|
type: NETWORK_ADMIN_TYPE,
|
|
4505
4562
|
targetNode,
|
|
4506
4563
|
networkId,
|
|
4507
4564
|
bodyHash: (0, import_sdk_core8.canonicalHashHex)(
|
|
4508
|
-
|
|
4565
|
+
crypto2.sha256,
|
|
4509
4566
|
body
|
|
4510
4567
|
),
|
|
4511
4568
|
action: NETWORK_CREATE_ACTION2
|