@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
package/dist/index.cjs
CHANGED
|
@@ -17157,6 +17157,7 @@ __export(index_exports, {
|
|
|
17157
17157
|
parseExpiry: () => import_sdk_core12.parseExpiry,
|
|
17158
17158
|
parseNetworkId: () => import_sdk_core17.parseNetworkId,
|
|
17159
17159
|
parsePkhDid: () => import_sdk_core11.parsePkhDid,
|
|
17160
|
+
parseSecretCatalogKey: () => import_sdk_core16.parseSecretCatalogKey,
|
|
17160
17161
|
parseSpaceUri: () => import_sdk_core21.parseSpaceUri,
|
|
17161
17162
|
pkhDid: () => import_sdk_core11.pkhDid,
|
|
17162
17163
|
principalDid: () => import_sdk_core11.principalDid,
|
|
@@ -19108,6 +19109,11 @@ var NodeSecretsService = class {
|
|
|
19108
19109
|
if (!permission.ok) return permission;
|
|
19109
19110
|
return options === void 0 ? this.service.list() : this.service.list(options);
|
|
19110
19111
|
}
|
|
19112
|
+
async listAll() {
|
|
19113
|
+
const permission = await this.ensurePermission("", void 0, "list");
|
|
19114
|
+
if (!permission.ok) return permission;
|
|
19115
|
+
return this.service.listAll();
|
|
19116
|
+
}
|
|
19111
19117
|
get service() {
|
|
19112
19118
|
return this.config.getService();
|
|
19113
19119
|
}
|
|
@@ -19169,7 +19175,11 @@ var NodeSecretsService = class {
|
|
|
19169
19175
|
(entry) => manifests.some((candidate) => {
|
|
19170
19176
|
const resolved = (0, import_sdk_core6.resolveManifest)(candidate);
|
|
19171
19177
|
return resolved.resources.some(
|
|
19172
|
-
(resource) => resource.service === entry.service && spaceMatches(
|
|
19178
|
+
(resource) => resource.service === entry.service && spaceMatches(
|
|
19179
|
+
resource.space,
|
|
19180
|
+
entry.space,
|
|
19181
|
+
this.config.resolveSpace
|
|
19182
|
+
) && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
|
|
19173
19183
|
);
|
|
19174
19184
|
})
|
|
19175
19185
|
);
|
|
@@ -19864,6 +19874,29 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19864
19874
|
const authHosts = this.auth?.hosts ?? [];
|
|
19865
19875
|
return authHosts.length > 0 ? authHosts : [this.config.host];
|
|
19866
19876
|
}
|
|
19877
|
+
/** The registry-resolved Node endpoint and the identity returned by that exact Node. */
|
|
19878
|
+
async activeNodeIdentity() {
|
|
19879
|
+
const host = this.hosts[0];
|
|
19880
|
+
if (host === void 0) throw new Error("TinyCloud node host has not been resolved");
|
|
19881
|
+
const parsed = new URL(host);
|
|
19882
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && (parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost")) || parsed.origin !== host) {
|
|
19883
|
+
throw new Error("TinyCloud node host is not a canonical origin");
|
|
19884
|
+
}
|
|
19885
|
+
const nodeDid = await this.fetchNodeId();
|
|
19886
|
+
if (!nodeDid.startsWith("did:key:z")) throw new Error("TinyCloud node identity is not a did:key");
|
|
19887
|
+
return Object.freeze({ origin: parsed.origin, nodeDid });
|
|
19888
|
+
}
|
|
19889
|
+
/** Publish the active owner Node as a session-signed registry record. */
|
|
19890
|
+
async publishActiveNodeLocation(registryUrl, fetchFn = globalThis.fetch.bind(globalThis)) {
|
|
19891
|
+
const node = await this.activeNodeIdentity();
|
|
19892
|
+
return (0, import_sdk_core7.publishLocationRecord)({
|
|
19893
|
+
registryUrl,
|
|
19894
|
+
subject: this.credentialHolderDid,
|
|
19895
|
+
nodeOrigin: node.origin,
|
|
19896
|
+
signer: { type: "did:key", signBytes: (bytes) => this.signSessionBytes(bytes) },
|
|
19897
|
+
fetch: fetchFn
|
|
19898
|
+
});
|
|
19899
|
+
}
|
|
19867
19900
|
/**
|
|
19868
19901
|
* Get the primary identity DID for this user.
|
|
19869
19902
|
* - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
|
|
@@ -22211,63 +22244,62 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22211
22244
|
}
|
|
22212
22245
|
};
|
|
22213
22246
|
}
|
|
22214
|
-
/** Register a policy
|
|
22215
|
-
async
|
|
22247
|
+
/** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
|
|
22248
|
+
async registerPolicy(params) {
|
|
22216
22249
|
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
|
-
})
|
|
22250
|
+
return (0, import_sdk_core7.registerPolicyV3)({
|
|
22251
|
+
...params,
|
|
22252
|
+
nodeOrigin: this.config.host,
|
|
22253
|
+
fetch: globalThis.fetch.bind(globalThis)
|
|
22227
22254
|
});
|
|
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
22255
|
}
|
|
22240
|
-
/** Authorize
|
|
22241
|
-
async
|
|
22256
|
+
/** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
|
|
22257
|
+
async authorizeShareDeliveryV3(input) {
|
|
22242
22258
|
const session = this.currentTinyCloudSession();
|
|
22243
22259
|
const serviceSession = this._serviceContext?.session;
|
|
22244
22260
|
if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
|
|
22261
|
+
const idempotencyBytes = new TextEncoder().encode(input.idempotencyKey);
|
|
22262
|
+
if (idempotencyBytes.byteLength === 0 || idempotencyBytes.byteLength > 512) {
|
|
22263
|
+
throw new Error("Share delivery idempotency key is invalid");
|
|
22264
|
+
}
|
|
22265
|
+
const jtiDigest = new Uint8Array(await crypto.subtle.digest("SHA-256", idempotencyBytes));
|
|
22245
22266
|
const body = {
|
|
22246
|
-
|
|
22267
|
+
envelope: input.envelope,
|
|
22268
|
+
sealedEnvelope: input.sealedEnvelope,
|
|
22269
|
+
envelopeKey: input.envelopeKey,
|
|
22247
22270
|
shareCid: input.shareCid,
|
|
22248
|
-
shareId: input.shareId,
|
|
22249
|
-
registrationCid: input.registrationCid,
|
|
22250
|
-
policyCid: input.policyCid,
|
|
22251
|
-
delegationCid: input.delegationCid,
|
|
22252
|
-
enforcementDelegationCid: input.enforcementDelegationCid,
|
|
22253
22271
|
recipientEmail: input.recipientEmail,
|
|
22254
22272
|
shareUrl: input.shareUrl,
|
|
22255
22273
|
documentName: input.documentName,
|
|
22256
|
-
jti: base64UrlEncode(
|
|
22257
|
-
|
|
22258
|
-
expiresAt: input.expiresAt
|
|
22274
|
+
jti: base64UrlEncode(jtiDigest.slice(0, 16)),
|
|
22275
|
+
expiresAt: new Date(input.expiresAt).toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
22259
22276
|
};
|
|
22260
22277
|
const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core7.canonicalizeEncryptionJson)(body)))));
|
|
22261
22278
|
const request = { ...body, requestBodyDigest };
|
|
22262
22279
|
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}/
|
|
22280
|
+
const response = await fetch(`${this.config.host}/policy/v3/deliveries/authorize`, {
|
|
22264
22281
|
method: "POST",
|
|
22265
22282
|
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
22266
22283
|
body: (0, import_sdk_core7.canonicalizeEncryptionJson)(request)
|
|
22267
22284
|
});
|
|
22268
|
-
if (!response.ok) throw new Error(`
|
|
22269
|
-
const
|
|
22270
|
-
|
|
22285
|
+
if (!response.ok) throw new Error(`V3 share delivery authorization failed: ${response.status}`);
|
|
22286
|
+
const verified = (0, import_sdk_core7.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
|
|
22287
|
+
request,
|
|
22288
|
+
senderKeyDid: this.credentialHolderDid,
|
|
22289
|
+
deliveryAudience: input.deliveryAudience
|
|
22290
|
+
});
|
|
22291
|
+
const requestDigest = new Uint8Array(await crypto.subtle.digest(
|
|
22292
|
+
"SHA-256",
|
|
22293
|
+
new TextEncoder().encode(`${import_sdk_core7.CREDENTIAL_INVITATION_REQUEST_DOMAIN}${(0, import_sdk_core7.canonicalizeEncryptionJson)(verified.request)}`)
|
|
22294
|
+
));
|
|
22295
|
+
return {
|
|
22296
|
+
...verified,
|
|
22297
|
+
proof: {
|
|
22298
|
+
alg: "EdDSA",
|
|
22299
|
+
kid: this.credentialHolderDid,
|
|
22300
|
+
signature: base64UrlEncode(await this.signSessionBytes(requestDigest))
|
|
22301
|
+
}
|
|
22302
|
+
};
|
|
22271
22303
|
}
|
|
22272
22304
|
async createRootDelegationForSharing(params, assertActive) {
|
|
22273
22305
|
try {
|
|
@@ -25066,6 +25098,7 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
|
|
|
25066
25098
|
parseExpiry,
|
|
25067
25099
|
parseNetworkId,
|
|
25068
25100
|
parsePkhDid,
|
|
25101
|
+
parseSecretCatalogKey,
|
|
25069
25102
|
parseSpaceUri,
|
|
25070
25103
|
pkhDid,
|
|
25071
25104
|
principalDid,
|