@tinycloud/node-sdk 3.0.0-beta.0 → 3.0.0-beta.10
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-DMhQYBmA.d.cts} +22 -53
- package/dist/{core-C6Czyr52.d.ts → core-DMhQYBmA.d.ts} +22 -53
- package/dist/core.cjs +72 -39
- 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 +76 -41
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +72 -39
- 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 +76 -41
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
|
|
2
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
4
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
5
|
|
|
@@ -955,39 +956,6 @@ declare class DelegatedAccess {
|
|
|
955
956
|
get restorable(): RestorableSession;
|
|
956
957
|
}
|
|
957
958
|
|
|
958
|
-
/**
|
|
959
|
-
* TinyCloudNode - High-level API for Node.js users.
|
|
960
|
-
*
|
|
961
|
-
* Each user has their own TinyCloudNode instance with their own key.
|
|
962
|
-
* This class provides a simplified interface for:
|
|
963
|
-
* - Signing in and managing sessions
|
|
964
|
-
* - Key-value storage operations on own space
|
|
965
|
-
* - Creating and using delegations
|
|
966
|
-
*
|
|
967
|
-
* @example
|
|
968
|
-
* ```typescript
|
|
969
|
-
* const alice = new TinyCloudNode({
|
|
970
|
-
* privateKey: process.env.ALICE_PRIVATE_KEY,
|
|
971
|
-
* host: "https://node.tinycloud.xyz",
|
|
972
|
-
* prefix: "myapp",
|
|
973
|
-
* });
|
|
974
|
-
*
|
|
975
|
-
* await alice.signIn();
|
|
976
|
-
* await alice.kv.put("greeting", "Hello, world!");
|
|
977
|
-
*
|
|
978
|
-
* // Delegate access to Bob
|
|
979
|
-
* const delegation = await alice.createDelegation({
|
|
980
|
-
* path: "shared/",
|
|
981
|
-
* actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
|
|
982
|
-
* delegateDID: bob.did,
|
|
983
|
-
* });
|
|
984
|
-
*
|
|
985
|
-
* // Bob uses the delegation
|
|
986
|
-
* const access = await bob.useDelegation(delegation);
|
|
987
|
-
* const data = await access.kv.get("shared/data");
|
|
988
|
-
* ```
|
|
989
|
-
*/
|
|
990
|
-
|
|
991
959
|
declare const BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
|
|
992
960
|
declare const BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
|
|
993
961
|
declare const ACCEPTED_MARKER_VERSIONS: readonly number[];
|
|
@@ -1382,6 +1350,13 @@ declare class TinyCloudNode {
|
|
|
1382
1350
|
get manifest(): Manifest | Manifest[] | undefined;
|
|
1383
1351
|
get capabilityRequest(): ComposedManifestRequest | undefined;
|
|
1384
1352
|
get hosts(): string[];
|
|
1353
|
+
/** The registry-resolved Node endpoint and the identity returned by that exact Node. */
|
|
1354
|
+
activeNodeIdentity(): Promise<{
|
|
1355
|
+
readonly origin: string;
|
|
1356
|
+
readonly nodeDid: string;
|
|
1357
|
+
}>;
|
|
1358
|
+
/** Publish the active owner Node as a session-signed registry record. */
|
|
1359
|
+
publishActiveNodeLocation(registryUrl: string, fetchFn?: typeof fetch): Promise<_tinycloud_sdk_core.LocationRecord>;
|
|
1385
1360
|
/**
|
|
1386
1361
|
* Get the primary identity DID for this user.
|
|
1387
1362
|
* - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
|
|
@@ -1811,31 +1786,25 @@ declare class TinyCloudNode {
|
|
|
1811
1786
|
* @internal
|
|
1812
1787
|
*/
|
|
1813
1788
|
createOwnerDelegation(params: CreateOwnerDelegationParams, assertActive?: () => void): Promise<OwnerDelegationReceipt>;
|
|
1814
|
-
/** Register a policy
|
|
1815
|
-
|
|
1816
|
-
/** Authorize
|
|
1817
|
-
|
|
1818
|
-
readonly
|
|
1789
|
+
/** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
|
|
1790
|
+
registerPolicy(params: Omit<RegisterPolicyV3Input, "nodeOrigin" | "fetch">): Promise<RegisterPolicyV3Receipt>;
|
|
1791
|
+
/** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
|
|
1792
|
+
authorizeShareDeliveryV3(input: {
|
|
1793
|
+
readonly envelope: Record<string, CanonicalJson | undefined>;
|
|
1794
|
+
/** Canonical sealed recipient envelope: version || nonce || ciphertext+tag. */
|
|
1795
|
+
readonly sealedEnvelope: string;
|
|
1796
|
+
/** Base64url 32-byte envelope key; it must also be the URL fragment key. */
|
|
1797
|
+
readonly envelopeKey: string;
|
|
1819
1798
|
readonly shareCid: string;
|
|
1820
|
-
readonly shareId: string;
|
|
1821
|
-
readonly registrationCid: string;
|
|
1822
|
-
readonly policyCid: string;
|
|
1823
|
-
readonly delegationCid: string;
|
|
1824
|
-
readonly enforcementDelegationCid: string;
|
|
1825
1799
|
readonly resourcePath: string;
|
|
1826
1800
|
readonly recipientEmail: string;
|
|
1827
1801
|
readonly shareUrl: string;
|
|
1828
1802
|
readonly documentName: string;
|
|
1829
|
-
readonly idempotencyKey: string;
|
|
1830
1803
|
readonly expiresAt: string;
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
};
|
|
1836
|
-
/** The trusted OpenCredentials witness origin from the same trust bundle as `nodeProof`. */
|
|
1837
|
-
readonly credentialsAudience: string;
|
|
1838
|
-
}): Promise<ShareDeliveryAuthorizationReceipt>;
|
|
1804
|
+
readonly deliveryAudience: string;
|
|
1805
|
+
/** Stable caller retry identity. It is hashed into the protocol's 16-byte JTI. */
|
|
1806
|
+
readonly idempotencyKey: string;
|
|
1807
|
+
}): Promise<ShareDeliveryAuthorizationV3Receipt>;
|
|
1839
1808
|
private createRootDelegationForSharing;
|
|
1840
1809
|
/**
|
|
1841
1810
|
* Track a received delegation in the capability registry.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
|
|
2
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
4
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
5
|
|
|
@@ -955,39 +956,6 @@ declare class DelegatedAccess {
|
|
|
955
956
|
get restorable(): RestorableSession;
|
|
956
957
|
}
|
|
957
958
|
|
|
958
|
-
/**
|
|
959
|
-
* TinyCloudNode - High-level API for Node.js users.
|
|
960
|
-
*
|
|
961
|
-
* Each user has their own TinyCloudNode instance with their own key.
|
|
962
|
-
* This class provides a simplified interface for:
|
|
963
|
-
* - Signing in and managing sessions
|
|
964
|
-
* - Key-value storage operations on own space
|
|
965
|
-
* - Creating and using delegations
|
|
966
|
-
*
|
|
967
|
-
* @example
|
|
968
|
-
* ```typescript
|
|
969
|
-
* const alice = new TinyCloudNode({
|
|
970
|
-
* privateKey: process.env.ALICE_PRIVATE_KEY,
|
|
971
|
-
* host: "https://node.tinycloud.xyz",
|
|
972
|
-
* prefix: "myapp",
|
|
973
|
-
* });
|
|
974
|
-
*
|
|
975
|
-
* await alice.signIn();
|
|
976
|
-
* await alice.kv.put("greeting", "Hello, world!");
|
|
977
|
-
*
|
|
978
|
-
* // Delegate access to Bob
|
|
979
|
-
* const delegation = await alice.createDelegation({
|
|
980
|
-
* path: "shared/",
|
|
981
|
-
* actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
|
|
982
|
-
* delegateDID: bob.did,
|
|
983
|
-
* });
|
|
984
|
-
*
|
|
985
|
-
* // Bob uses the delegation
|
|
986
|
-
* const access = await bob.useDelegation(delegation);
|
|
987
|
-
* const data = await access.kv.get("shared/data");
|
|
988
|
-
* ```
|
|
989
|
-
*/
|
|
990
|
-
|
|
991
959
|
declare const BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
|
|
992
960
|
declare const BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
|
|
993
961
|
declare const ACCEPTED_MARKER_VERSIONS: readonly number[];
|
|
@@ -1382,6 +1350,13 @@ declare class TinyCloudNode {
|
|
|
1382
1350
|
get manifest(): Manifest | Manifest[] | undefined;
|
|
1383
1351
|
get capabilityRequest(): ComposedManifestRequest | undefined;
|
|
1384
1352
|
get hosts(): string[];
|
|
1353
|
+
/** The registry-resolved Node endpoint and the identity returned by that exact Node. */
|
|
1354
|
+
activeNodeIdentity(): Promise<{
|
|
1355
|
+
readonly origin: string;
|
|
1356
|
+
readonly nodeDid: string;
|
|
1357
|
+
}>;
|
|
1358
|
+
/** Publish the active owner Node as a session-signed registry record. */
|
|
1359
|
+
publishActiveNodeLocation(registryUrl: string, fetchFn?: typeof fetch): Promise<_tinycloud_sdk_core.LocationRecord>;
|
|
1385
1360
|
/**
|
|
1386
1361
|
* Get the primary identity DID for this user.
|
|
1387
1362
|
* - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
|
|
@@ -1811,31 +1786,25 @@ declare class TinyCloudNode {
|
|
|
1811
1786
|
* @internal
|
|
1812
1787
|
*/
|
|
1813
1788
|
createOwnerDelegation(params: CreateOwnerDelegationParams, assertActive?: () => void): Promise<OwnerDelegationReceipt>;
|
|
1814
|
-
/** Register a policy
|
|
1815
|
-
|
|
1816
|
-
/** Authorize
|
|
1817
|
-
|
|
1818
|
-
readonly
|
|
1789
|
+
/** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
|
|
1790
|
+
registerPolicy(params: Omit<RegisterPolicyV3Input, "nodeOrigin" | "fetch">): Promise<RegisterPolicyV3Receipt>;
|
|
1791
|
+
/** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
|
|
1792
|
+
authorizeShareDeliveryV3(input: {
|
|
1793
|
+
readonly envelope: Record<string, CanonicalJson | undefined>;
|
|
1794
|
+
/** Canonical sealed recipient envelope: version || nonce || ciphertext+tag. */
|
|
1795
|
+
readonly sealedEnvelope: string;
|
|
1796
|
+
/** Base64url 32-byte envelope key; it must also be the URL fragment key. */
|
|
1797
|
+
readonly envelopeKey: string;
|
|
1819
1798
|
readonly shareCid: string;
|
|
1820
|
-
readonly shareId: string;
|
|
1821
|
-
readonly registrationCid: string;
|
|
1822
|
-
readonly policyCid: string;
|
|
1823
|
-
readonly delegationCid: string;
|
|
1824
|
-
readonly enforcementDelegationCid: string;
|
|
1825
1799
|
readonly resourcePath: string;
|
|
1826
1800
|
readonly recipientEmail: string;
|
|
1827
1801
|
readonly shareUrl: string;
|
|
1828
1802
|
readonly documentName: string;
|
|
1829
|
-
readonly idempotencyKey: string;
|
|
1830
1803
|
readonly expiresAt: string;
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
};
|
|
1836
|
-
/** The trusted OpenCredentials witness origin from the same trust bundle as `nodeProof`. */
|
|
1837
|
-
readonly credentialsAudience: string;
|
|
1838
|
-
}): Promise<ShareDeliveryAuthorizationReceipt>;
|
|
1804
|
+
readonly deliveryAudience: string;
|
|
1805
|
+
/** Stable caller retry identity. It is hashed into the protocol's 16-byte JTI. */
|
|
1806
|
+
readonly idempotencyKey: string;
|
|
1807
|
+
}): Promise<ShareDeliveryAuthorizationV3Receipt>;
|
|
1839
1808
|
private createRootDelegationForSharing;
|
|
1840
1809
|
/**
|
|
1841
1810
|
* Track a received delegation in the capability registry.
|
package/dist/core.cjs
CHANGED
|
@@ -115,6 +115,7 @@ __export(core_exports, {
|
|
|
115
115
|
parseCanonicalNetworkId: () => import_sdk_core11.parseCanonicalNetworkId,
|
|
116
116
|
parseExpiry: () => import_sdk_core12.parseExpiry,
|
|
117
117
|
parsePkhDid: () => import_sdk_core11.parsePkhDid,
|
|
118
|
+
parseSecretCatalogKey: () => import_sdk_core16.parseSecretCatalogKey,
|
|
118
119
|
parseSpaceUri: () => import_sdk_core19.parseSpaceUri,
|
|
119
120
|
pkhDid: () => import_sdk_core11.pkhDid,
|
|
120
121
|
principalDid: () => import_sdk_core11.principalDid,
|
|
@@ -2081,6 +2082,11 @@ var NodeSecretsService = class {
|
|
|
2081
2082
|
if (!permission.ok) return permission;
|
|
2082
2083
|
return options === void 0 ? this.service.list() : this.service.list(options);
|
|
2083
2084
|
}
|
|
2085
|
+
async listAll() {
|
|
2086
|
+
const permission = await this.ensurePermission("", void 0, "list");
|
|
2087
|
+
if (!permission.ok) return permission;
|
|
2088
|
+
return this.service.listAll();
|
|
2089
|
+
}
|
|
2084
2090
|
get service() {
|
|
2085
2091
|
return this.config.getService();
|
|
2086
2092
|
}
|
|
@@ -2142,7 +2148,11 @@ var NodeSecretsService = class {
|
|
|
2142
2148
|
(entry) => manifests.some((candidate) => {
|
|
2143
2149
|
const resolved = (0, import_sdk_core7.resolveManifest)(candidate);
|
|
2144
2150
|
return resolved.resources.some(
|
|
2145
|
-
(resource) => resource.service === entry.service && spaceMatches(
|
|
2151
|
+
(resource) => resource.service === entry.service && spaceMatches(
|
|
2152
|
+
resource.space,
|
|
2153
|
+
entry.space,
|
|
2154
|
+
this.config.resolveSpace
|
|
2155
|
+
) && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
|
|
2146
2156
|
);
|
|
2147
2157
|
})
|
|
2148
2158
|
);
|
|
@@ -2837,6 +2847,29 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2837
2847
|
const authHosts = this.auth?.hosts ?? [];
|
|
2838
2848
|
return authHosts.length > 0 ? authHosts : [this.config.host];
|
|
2839
2849
|
}
|
|
2850
|
+
/** The registry-resolved Node endpoint and the identity returned by that exact Node. */
|
|
2851
|
+
async activeNodeIdentity() {
|
|
2852
|
+
const host = this.hosts[0];
|
|
2853
|
+
if (host === void 0) throw new Error("TinyCloud node host has not been resolved");
|
|
2854
|
+
const parsed = new URL(host);
|
|
2855
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && (parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost")) || parsed.origin !== host) {
|
|
2856
|
+
throw new Error("TinyCloud node host is not a canonical origin");
|
|
2857
|
+
}
|
|
2858
|
+
const nodeDid = await this.fetchNodeId();
|
|
2859
|
+
if (!nodeDid.startsWith("did:key:z")) throw new Error("TinyCloud node identity is not a did:key");
|
|
2860
|
+
return Object.freeze({ origin: parsed.origin, nodeDid });
|
|
2861
|
+
}
|
|
2862
|
+
/** Publish the active owner Node as a session-signed registry record. */
|
|
2863
|
+
async publishActiveNodeLocation(registryUrl, fetchFn = globalThis.fetch.bind(globalThis)) {
|
|
2864
|
+
const node = await this.activeNodeIdentity();
|
|
2865
|
+
return (0, import_sdk_core8.publishLocationRecord)({
|
|
2866
|
+
registryUrl,
|
|
2867
|
+
subject: this.credentialHolderDid,
|
|
2868
|
+
nodeOrigin: node.origin,
|
|
2869
|
+
signer: { type: "did:key", signBytes: (bytes) => this.signSessionBytes(bytes) },
|
|
2870
|
+
fetch: fetchFn
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2840
2873
|
/**
|
|
2841
2874
|
* Get the primary identity DID for this user.
|
|
2842
2875
|
* - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
|
|
@@ -5184,63 +5217,62 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5184
5217
|
}
|
|
5185
5218
|
};
|
|
5186
5219
|
}
|
|
5187
|
-
/** Register a policy
|
|
5188
|
-
async
|
|
5220
|
+
/** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
|
|
5221
|
+
async registerPolicy(params) {
|
|
5189
5222
|
this._serviceGraph.assertActive();
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
body: JSON.stringify({
|
|
5195
|
-
policy: { bytes: base64UrlEncode(params.policy.bytes), cid: params.policy.cid, proof: params.policy.proof },
|
|
5196
|
-
ownerDelegation: { cid: params.ownerDelegation.delegationCid, dagCbor: base64UrlEncode(params.ownerDelegation.signedDagCbor) },
|
|
5197
|
-
enforcementDelegation: params.enforcementDelegation,
|
|
5198
|
-
contentSourceDigest: params.contentSourceDigest
|
|
5199
|
-
})
|
|
5223
|
+
return (0, import_sdk_core8.registerPolicyV3)({
|
|
5224
|
+
...params,
|
|
5225
|
+
nodeOrigin: this.config.host,
|
|
5226
|
+
fetch: globalThis.fetch.bind(globalThis)
|
|
5200
5227
|
});
|
|
5201
|
-
if (!response.ok) {
|
|
5202
|
-
let code = "";
|
|
5203
|
-
try {
|
|
5204
|
-
const body = await response.clone().json();
|
|
5205
|
-
if (typeof body.error?.code === "string") code = ` ${body.error.code}`;
|
|
5206
|
-
} catch {
|
|
5207
|
-
}
|
|
5208
|
-
throw new Error(`Owner share policy registration failed: ${response.status}${code}`);
|
|
5209
|
-
}
|
|
5210
|
-
const responseBytes = new Uint8Array(await response.arrayBuffer());
|
|
5211
|
-
return (0, import_sdk_core8.validateOwnerSharePolicyRegistrationBytes)(responseBytes, params);
|
|
5212
5228
|
}
|
|
5213
|
-
/** Authorize
|
|
5214
|
-
async
|
|
5229
|
+
/** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
|
|
5230
|
+
async authorizeShareDeliveryV3(input) {
|
|
5215
5231
|
const session = this.currentTinyCloudSession();
|
|
5216
5232
|
const serviceSession = this._serviceContext?.session;
|
|
5217
5233
|
if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
|
|
5234
|
+
const idempotencyBytes = new TextEncoder().encode(input.idempotencyKey);
|
|
5235
|
+
if (idempotencyBytes.byteLength === 0 || idempotencyBytes.byteLength > 512) {
|
|
5236
|
+
throw new Error("Share delivery idempotency key is invalid");
|
|
5237
|
+
}
|
|
5238
|
+
const jtiDigest = new Uint8Array(await crypto.subtle.digest("SHA-256", idempotencyBytes));
|
|
5218
5239
|
const body = {
|
|
5219
|
-
|
|
5240
|
+
envelope: input.envelope,
|
|
5241
|
+
sealedEnvelope: input.sealedEnvelope,
|
|
5242
|
+
envelopeKey: input.envelopeKey,
|
|
5220
5243
|
shareCid: input.shareCid,
|
|
5221
|
-
shareId: input.shareId,
|
|
5222
|
-
registrationCid: input.registrationCid,
|
|
5223
|
-
policyCid: input.policyCid,
|
|
5224
|
-
delegationCid: input.delegationCid,
|
|
5225
|
-
enforcementDelegationCid: input.enforcementDelegationCid,
|
|
5226
5244
|
recipientEmail: input.recipientEmail,
|
|
5227
5245
|
shareUrl: input.shareUrl,
|
|
5228
5246
|
documentName: input.documentName,
|
|
5229
|
-
jti: base64UrlEncode(
|
|
5230
|
-
|
|
5231
|
-
expiresAt: input.expiresAt
|
|
5247
|
+
jti: base64UrlEncode(jtiDigest.slice(0, 16)),
|
|
5248
|
+
expiresAt: new Date(input.expiresAt).toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
5232
5249
|
};
|
|
5233
5250
|
const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core8.canonicalizeEncryptionJson)(body)))));
|
|
5234
5251
|
const request = { ...body, requestBodyDigest };
|
|
5235
5252
|
const authorization = authorizationHeader(this.invokeAnyWithRuntimePermissions(serviceSession, [{ spaceId: session.spaceId, service: "kv", path: input.resourcePath, action: "tinycloud.kv/get" }]));
|
|
5236
|
-
const response = await fetch(`${this.config.host}/
|
|
5253
|
+
const response = await fetch(`${this.config.host}/policy/v3/deliveries/authorize`, {
|
|
5237
5254
|
method: "POST",
|
|
5238
5255
|
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
5239
5256
|
body: (0, import_sdk_core8.canonicalizeEncryptionJson)(request)
|
|
5240
5257
|
});
|
|
5241
|
-
if (!response.ok) throw new Error(`
|
|
5242
|
-
const
|
|
5243
|
-
|
|
5258
|
+
if (!response.ok) throw new Error(`V3 share delivery authorization failed: ${response.status}`);
|
|
5259
|
+
const verified = (0, import_sdk_core8.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
|
|
5260
|
+
request,
|
|
5261
|
+
senderKeyDid: this.credentialHolderDid,
|
|
5262
|
+
deliveryAudience: input.deliveryAudience
|
|
5263
|
+
});
|
|
5264
|
+
const requestDigest = new Uint8Array(await crypto.subtle.digest(
|
|
5265
|
+
"SHA-256",
|
|
5266
|
+
new TextEncoder().encode(`${import_sdk_core8.CREDENTIAL_INVITATION_REQUEST_DOMAIN}${(0, import_sdk_core8.canonicalizeEncryptionJson)(verified.request)}`)
|
|
5267
|
+
));
|
|
5268
|
+
return {
|
|
5269
|
+
...verified,
|
|
5270
|
+
proof: {
|
|
5271
|
+
alg: "EdDSA",
|
|
5272
|
+
kid: this.credentialHolderDid,
|
|
5273
|
+
signature: base64UrlEncode(await this.signSessionBytes(requestDigest))
|
|
5274
|
+
}
|
|
5275
|
+
};
|
|
5244
5276
|
}
|
|
5245
5277
|
async createRootDelegationForSharing(params, assertActive) {
|
|
5246
5278
|
try {
|
|
@@ -7790,6 +7822,7 @@ var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
|
7790
7822
|
parseCanonicalNetworkId,
|
|
7791
7823
|
parseExpiry,
|
|
7792
7824
|
parsePkhDid,
|
|
7825
|
+
parseSecretCatalogKey,
|
|
7793
7826
|
parseSpaceUri,
|
|
7794
7827
|
pkhDid,
|
|
7795
7828
|
principalDid,
|