@tinycloud/node-sdk 3.2.0-beta.4 → 3.2.0-beta.6
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/{WasmKeyProvider-DjfRu9aL.d.cts → WasmKeyProvider-C3NFgOmv.d.cts} +24 -5
- package/dist/{WasmKeyProvider-DjfRu9aL.d.ts → WasmKeyProvider-C3NFgOmv.d.ts} +24 -5
- package/dist/{authority-mTQEgN56.d.cts → authority-DDGtccBK.d.cts} +5 -6
- package/dist/{authority-mTQEgN56.d.ts → authority-DDGtccBK.d.ts} +5 -6
- package/dist/core.cjs +78 -44
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +80 -45
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +130 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +121 -65
- package/dist/index.js.map +1 -1
- package/dist/replication/authority.cjs +51 -37
- package/dist/replication/authority.cjs.map +1 -1
- package/dist/replication/authority.d.cts +1 -1
- package/dist/replication/authority.d.ts +1 -1
- package/dist/replication/authority.js +48 -36
- package/dist/replication/authority.js.map +1 -1
- package/dist/replication/runtime.cjs +1 -0
- package/dist/replication/runtime.cjs.map +1 -1
- package/dist/replication/runtime.d.cts +1 -1
- package/dist/replication/runtime.d.ts +1 -1
- package/dist/replication/runtime.js +1 -0
- package/dist/replication/runtime.js.map +1 -1
- package/dist/{runtime-DyYwHW8j.d.cts → runtime-B5P5SRpC.d.cts} +1 -0
- package/dist/{runtime-DyYwHW8j.d.ts → runtime-B5P5SRpC.d.ts} +1 -0
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -17040,38 +17040,39 @@ function assertValidReplicationConfig(replication) {
|
|
|
17040
17040
|
throw new TypeError("replication.prefixes must be a non-empty array");
|
|
17041
17041
|
}
|
|
17042
17042
|
for (const prefix of replication.prefixes) {
|
|
17043
|
-
|
|
17044
|
-
|
|
17043
|
+
try {
|
|
17044
|
+
(0, import_prefix.assertFolderPrefix)(prefix);
|
|
17045
|
+
} catch (error) {
|
|
17046
|
+
throw new TypeError(error instanceof Error ? error.message : String(error));
|
|
17045
17047
|
}
|
|
17046
17048
|
}
|
|
17047
17049
|
for (const [index, prefix] of replication.prefixes.entries()) {
|
|
17048
17050
|
for (const other of replication.prefixes.slice(index + 1)) {
|
|
17049
|
-
if ((0,
|
|
17051
|
+
if ((0, import_prefix.kvPrefixCovers)(prefix, other) || (0, import_prefix.kvPrefixCovers)(other, prefix)) {
|
|
17050
17052
|
throw new TypeError(
|
|
17051
17053
|
`replication.prefixes must not overlap: ${JSON.stringify(prefix)} and ${JSON.stringify(other)}`
|
|
17052
17054
|
);
|
|
17053
17055
|
}
|
|
17054
17056
|
}
|
|
17055
|
-
if (prefix.split("/", 1)[0] === "vault" && replication.allowSecrets !== true) {
|
|
17057
|
+
if ((prefix === "/" || prefix.split("/", 1)[0] === "vault") && replication.allowSecrets !== true) {
|
|
17056
17058
|
throw new TypeError(
|
|
17057
17059
|
`replication prefix ${JSON.stringify(prefix)} overlaps the vault namespace; pass allowSecrets to opt in`
|
|
17058
17060
|
);
|
|
17059
17061
|
}
|
|
17060
17062
|
}
|
|
17061
17063
|
}
|
|
17062
|
-
var
|
|
17064
|
+
var import_prefix;
|
|
17063
17065
|
var init_config = __esm({
|
|
17064
17066
|
"src/replication/config.ts"() {
|
|
17065
17067
|
"use strict";
|
|
17066
|
-
|
|
17068
|
+
import_prefix = require("@tinycloud/sdk-services/kv/replication/prefix");
|
|
17067
17069
|
}
|
|
17068
17070
|
});
|
|
17069
17071
|
|
|
17070
17072
|
// src/replication/authority-sign-in.ts
|
|
17071
17073
|
function hasUnrestrictedGetCoverage(entries, spaceId, prefix) {
|
|
17072
|
-
const requiredPaths = (0, import_sdk_core2.grantPathsForSelector)(prefix);
|
|
17073
17074
|
return (0, import_sdk_core2.isCapabilitySubset)(
|
|
17074
|
-
|
|
17075
|
+
[{ service: KV_SERVICE, space: spaceId, path: prefix, actions: [KV_GET] }],
|
|
17075
17076
|
[...entries]
|
|
17076
17077
|
).subset;
|
|
17077
17078
|
}
|
|
@@ -17079,30 +17080,43 @@ function augmentSignInEntriesWithReplication(input) {
|
|
|
17079
17080
|
const out = [];
|
|
17080
17081
|
const replication = input.replication;
|
|
17081
17082
|
if (replication === void 0) return out;
|
|
17083
|
+
const eligiblePaths = [];
|
|
17082
17084
|
for (const prefix of replication.prefixes) {
|
|
17083
|
-
|
|
17085
|
+
(0, import_prefix2.assertFolderPrefix)(prefix);
|
|
17086
|
+
const path = prefix === "/" ? "" : prefix;
|
|
17087
|
+
if ((0, import_sdk_services.requiresSecretsOptIn)(input.primarySpaceId, prefix) && replication.allowSecrets !== true) {
|
|
17084
17088
|
continue;
|
|
17085
17089
|
}
|
|
17086
|
-
if (!hasUnrestrictedGetCoverage(input.entries, input.primarySpaceId,
|
|
17090
|
+
if (!hasUnrestrictedGetCoverage(input.entries, input.primarySpaceId, path)) {
|
|
17087
17091
|
continue;
|
|
17088
17092
|
}
|
|
17089
|
-
|
|
17090
|
-
|
|
17091
|
-
|
|
17092
|
-
|
|
17093
|
-
|
|
17094
|
-
|
|
17095
|
-
|
|
17096
|
-
|
|
17093
|
+
eligiblePaths.push(path);
|
|
17094
|
+
}
|
|
17095
|
+
if (eligiblePaths.length === replication.prefixes.length && eligiblePaths.length > 0 && hasUnrestrictedGetCoverage(input.entries, input.primarySpaceId, "")) {
|
|
17096
|
+
return [{
|
|
17097
|
+
service: KV_SERVICE,
|
|
17098
|
+
space: input.primarySpaceId,
|
|
17099
|
+
path: "",
|
|
17100
|
+
actions: [KV_GET, KV_SYNC]
|
|
17101
|
+
}];
|
|
17102
|
+
}
|
|
17103
|
+
for (const path of eligiblePaths) {
|
|
17104
|
+
out.push({
|
|
17105
|
+
service: KV_SERVICE,
|
|
17106
|
+
space: input.primarySpaceId,
|
|
17107
|
+
path,
|
|
17108
|
+
actions: [KV_GET, KV_SYNC]
|
|
17109
|
+
});
|
|
17097
17110
|
}
|
|
17098
17111
|
return out;
|
|
17099
17112
|
}
|
|
17100
|
-
var import_sdk_core2,
|
|
17113
|
+
var import_sdk_core2, import_sdk_services, import_prefix2, KV_GET, KV_SYNC, KV_SERVICE;
|
|
17101
17114
|
var init_authority_sign_in = __esm({
|
|
17102
17115
|
"src/replication/authority-sign-in.ts"() {
|
|
17103
17116
|
"use strict";
|
|
17104
17117
|
import_sdk_core2 = require("@tinycloud/sdk-core");
|
|
17105
|
-
|
|
17118
|
+
import_sdk_services = require("@tinycloud/sdk-services");
|
|
17119
|
+
import_prefix2 = require("@tinycloud/sdk-services/kv/replication/prefix");
|
|
17106
17120
|
KV_GET = import_sdk_core2.KV.GET;
|
|
17107
17121
|
KV_SYNC = import_sdk_core2.KV.SYNC;
|
|
17108
17122
|
KV_SERVICE = "tinycloud.kv";
|
|
@@ -17257,6 +17271,7 @@ var init_runtime = __esm({
|
|
|
17257
17271
|
scheduler: this.clock,
|
|
17258
17272
|
emit,
|
|
17259
17273
|
fetch: context.fetch,
|
|
17274
|
+
nodeFeatures: input.nodeFeatures,
|
|
17260
17275
|
previous: previousClose
|
|
17261
17276
|
});
|
|
17262
17277
|
this.current = controller;
|
|
@@ -17318,12 +17333,12 @@ __export(authority_exports, {
|
|
|
17318
17333
|
ucanAttUnconstrainedFor: () => ucanAttUnconstrainedFor
|
|
17319
17334
|
});
|
|
17320
17335
|
function replicationEntries(spaceId, prefix) {
|
|
17321
|
-
return
|
|
17336
|
+
return [{
|
|
17322
17337
|
service: KV_SERVICE2,
|
|
17323
17338
|
space: spaceId,
|
|
17324
|
-
path,
|
|
17339
|
+
path: prefix === "/" ? "" : prefix,
|
|
17325
17340
|
actions: [KV_GET2, KV_SYNC2]
|
|
17326
|
-
}
|
|
17341
|
+
}];
|
|
17327
17342
|
}
|
|
17328
17343
|
function caveatBranchesUnconstrained(value) {
|
|
17329
17344
|
if (value === void 0 || value === null) return true;
|
|
@@ -17338,28 +17353,28 @@ function caveatBranchesUnconstrained(value) {
|
|
|
17338
17353
|
}
|
|
17339
17354
|
}
|
|
17340
17355
|
function kvPathInResource(resource, space) {
|
|
17356
|
+
for (const root of [`${space}/kv`, `tinycloud://${space}/kv`]) {
|
|
17357
|
+
if (resource === root || resource === `${root}/`) return "/";
|
|
17358
|
+
}
|
|
17341
17359
|
for (const base2 of [`${space}/kv/`, `tinycloud://${space}/kv/`]) {
|
|
17342
17360
|
if (resource.startsWith(base2)) return resource.slice(base2.length);
|
|
17343
17361
|
}
|
|
17344
17362
|
return void 0;
|
|
17345
17363
|
}
|
|
17346
17364
|
function ucanAttCovers(att, space, prefix, ability, options) {
|
|
17347
|
-
const
|
|
17348
|
-
|
|
17349
|
-
|
|
17350
|
-
|
|
17351
|
-
if (
|
|
17352
|
-
|
|
17353
|
-
|
|
17354
|
-
|
|
17355
|
-
|
|
17356
|
-
|
|
17357
|
-
).subset) continue;
|
|
17358
|
-
if (options?.ignoreCaveats === true || caveatBranchesUnconstrained(caveats)) return true;
|
|
17359
|
-
}
|
|
17365
|
+
for (const [resource, abilities] of Object.entries(att)) {
|
|
17366
|
+
const path = kvPathInResource(resource, space);
|
|
17367
|
+
if (path === void 0) continue;
|
|
17368
|
+
for (const [granted, caveats] of Object.entries(abilities)) {
|
|
17369
|
+
if (!(0, import_sdk_core11.actionContains)(granted, ability)) continue;
|
|
17370
|
+
if (!(0, import_sdk_core11.isCapabilitySubset)(
|
|
17371
|
+
[{ service: KV_SERVICE2, space, path: prefix, actions: [ability] }],
|
|
17372
|
+
[{ service: KV_SERVICE2, space, path, actions: [granted] }]
|
|
17373
|
+
).subset) continue;
|
|
17374
|
+
if (options?.ignoreCaveats === true || caveatBranchesUnconstrained(caveats)) return true;
|
|
17360
17375
|
}
|
|
17361
|
-
|
|
17362
|
-
|
|
17376
|
+
}
|
|
17377
|
+
return false;
|
|
17363
17378
|
}
|
|
17364
17379
|
function ucanAttUnconstrainedFor(att, space, prefix) {
|
|
17365
17380
|
return ucanAttCovers(att, space, prefix, KV_GET2) && ucanAttCovers(att, space, prefix, KV_SYNC2);
|
|
@@ -17374,7 +17389,7 @@ function replicationScopeFromSignedSession(input) {
|
|
|
17374
17389
|
const bareDid = (value) => value.split("#", 1)[0];
|
|
17375
17390
|
if (grant.cid !== input.delegationCid || bareDid(grant.audience) !== bareDid(input.verificationMethod)) return void 0;
|
|
17376
17391
|
for (const resource of Object.keys(grant.att)) {
|
|
17377
|
-
const space = resource.match(/^(?:tinycloud:\/\/)?(.+?)\/kv
|
|
17392
|
+
const space = resource.match(/^(?:tinycloud:\/\/)?(.+?)\/kv(?:\/|$)/)?.[1];
|
|
17378
17393
|
if (space !== input.persistedSpace) continue;
|
|
17379
17394
|
const owner = (0, import_sdk_core11.parseSpaceUri)(space);
|
|
17380
17395
|
if (owner?.owner && owner.address && owner.chainId) return { space, principal: owner.owner };
|
|
@@ -17648,6 +17663,7 @@ __export(src_exports, {
|
|
|
17648
17663
|
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core16.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
17649
17664
|
serializeDelegation: () => serializeDelegation,
|
|
17650
17665
|
signedCompactUcanExpiry: () => signedCompactUcanExpiry,
|
|
17666
|
+
siweRuntimeDelegation: () => siweRuntimeDelegation,
|
|
17651
17667
|
sqliteReplicaStorage: () => sqliteReplicaStorage,
|
|
17652
17668
|
tinyCloudDebugLogger: () => import_sdk_core15.tinyCloudDebugLogger,
|
|
17653
17669
|
validateEnvelope: () => import_sdk_core21.validateEnvelope,
|
|
@@ -18218,18 +18234,45 @@ async function activateCompactRuntimeDelegation(node, input) {
|
|
|
18218
18234
|
throw new Error("Compact runtime delegation CID does not match authorization bytes.");
|
|
18219
18235
|
}
|
|
18220
18236
|
const signed2 = signedAuthorityFromCompactUcan(authorization);
|
|
18237
|
+
return activateValidatedRuntimeDelegation(
|
|
18238
|
+
node,
|
|
18239
|
+
portableFromSignedAuthority(cid, authorization, signed2, input),
|
|
18240
|
+
{ host: input.host }
|
|
18241
|
+
);
|
|
18242
|
+
}
|
|
18243
|
+
function siweRuntimeDelegation(node, input) {
|
|
18244
|
+
const cid = node.computeDelegationCid(input.authorization);
|
|
18245
|
+
if (cid !== input.cid) {
|
|
18246
|
+
throw new Error("SIWE runtime delegation CID does not match authorization bytes.");
|
|
18247
|
+
}
|
|
18248
|
+
const proof = { siwe: input.siwe, signature: input.signature };
|
|
18249
|
+
const signed2 = signedAuthorityFromSessionGrant(
|
|
18250
|
+
node,
|
|
18251
|
+
{ siweProof: proof, spaceId: input.spaceId, ownerAddress: input.ownerAddress, chainId: input.chainId },
|
|
18252
|
+
input.authorization,
|
|
18253
|
+
cid
|
|
18254
|
+
);
|
|
18255
|
+
if (signed2.expiry.getTime() <= Date.now()) {
|
|
18256
|
+
reject("expired", "Runtime delegation is expired.");
|
|
18257
|
+
}
|
|
18258
|
+
return {
|
|
18259
|
+
...portableFromSignedAuthority(cid, input.authorization, signed2, input),
|
|
18260
|
+
siweProof: proof
|
|
18261
|
+
};
|
|
18262
|
+
}
|
|
18263
|
+
function portableFromSignedAuthority(cid, authorization, signed2, transport) {
|
|
18221
18264
|
const primary = signed2.resources[0];
|
|
18222
18265
|
const signedSpace = signed2.permissions.find(
|
|
18223
18266
|
(permission) => permission.service !== "tinycloud.encryption"
|
|
18224
18267
|
)?.space;
|
|
18225
|
-
|
|
18268
|
+
return {
|
|
18226
18269
|
cid,
|
|
18227
18270
|
delegationHeader: { Authorization: authorization },
|
|
18228
|
-
ownerAddress:
|
|
18229
|
-
chainId:
|
|
18271
|
+
ownerAddress: transport.ownerAddress,
|
|
18272
|
+
chainId: transport.chainId,
|
|
18230
18273
|
delegatorDID: signed2.issuer,
|
|
18231
18274
|
authHeader: authorization,
|
|
18232
|
-
spaceId: signedSpace ?? primary.space,
|
|
18275
|
+
spaceId: signedSpace ?? transport.spaceId ?? primary.space,
|
|
18233
18276
|
path: primary.path,
|
|
18234
18277
|
actions: [...primary.actions],
|
|
18235
18278
|
...primary.caveats === void 0 ? {} : { caveats: primary.caveats },
|
|
@@ -18239,11 +18282,8 @@ async function activateCompactRuntimeDelegation(node, input) {
|
|
|
18239
18282
|
})),
|
|
18240
18283
|
expiry: new Date(signed2.expiry),
|
|
18241
18284
|
delegateDID: signed2.audience,
|
|
18242
|
-
host: normalizedHost(
|
|
18285
|
+
host: normalizedHost(transport.host)
|
|
18243
18286
|
};
|
|
18244
|
-
return activateValidatedRuntimeDelegation(node, delegation, {
|
|
18245
|
-
host: input.host
|
|
18246
|
-
});
|
|
18247
18287
|
}
|
|
18248
18288
|
async function grantAuthRequest(authority, request, options) {
|
|
18249
18289
|
if (request.kind !== "tinycloud.auth.request") {
|
|
@@ -18303,7 +18343,7 @@ function getNodeReplicationLoaders() {
|
|
|
18303
18343
|
|
|
18304
18344
|
// src/TinyCloudNode.ts
|
|
18305
18345
|
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
18306
|
-
var
|
|
18346
|
+
var import_sdk_services2 = require("@tinycloud/sdk-services");
|
|
18307
18347
|
|
|
18308
18348
|
// src/authorization/NodeUserAuthorization.ts
|
|
18309
18349
|
var import_node_crypto = require("crypto");
|
|
@@ -18446,6 +18486,7 @@ var NodeUserAuthorization = class {
|
|
|
18446
18486
|
this.activeSessionKeyId = "default";
|
|
18447
18487
|
this.extensions = [];
|
|
18448
18488
|
this._nodeFeatures = [];
|
|
18489
|
+
this._nodeFeaturesKnown = false;
|
|
18449
18490
|
this._lastActivationSkippedSpaceIds = [];
|
|
18450
18491
|
this.wasm = config.wasmBindings;
|
|
18451
18492
|
this.signer = config.signer;
|
|
@@ -18569,8 +18610,11 @@ var NodeUserAuthorization = class {
|
|
|
18569
18610
|
}
|
|
18570
18611
|
}
|
|
18571
18612
|
/** @internal Atomically adopt the state staged by TinyCloudNode.restoreSession. */
|
|
18572
|
-
installRestoredSession(sessionManager, session, hosts) {
|
|
18613
|
+
installRestoredSession(sessionManager, session, hosts, nodeFeatures) {
|
|
18573
18614
|
this.sessionManager = sessionManager;
|
|
18615
|
+
this._nodeFeatures = nodeFeatures === void 0 ? [] : [...nodeFeatures];
|
|
18616
|
+
this._nodeFeaturesKnown = nodeFeatures !== void 0;
|
|
18617
|
+
this._nodeInfoIdentity = void 0;
|
|
18574
18618
|
this.tinycloudHosts = hosts && hosts.length > 0 ? [...hosts] : void 0;
|
|
18575
18619
|
this._lastActivationSkippedSpaceIds = [];
|
|
18576
18620
|
if (!session) {
|
|
@@ -18645,6 +18689,16 @@ var NodeUserAuthorization = class {
|
|
|
18645
18689
|
get nodeFeatures() {
|
|
18646
18690
|
return this._nodeFeatures;
|
|
18647
18691
|
}
|
|
18692
|
+
get nodeFeaturesKnown() {
|
|
18693
|
+
return this._nodeFeaturesKnown;
|
|
18694
|
+
}
|
|
18695
|
+
async refreshNodeInfo() {
|
|
18696
|
+
const infoHost = this.primaryTinyCloudHost;
|
|
18697
|
+
const nodeInfo = await (0, import_sdk_core4.checkNodeInfo)(infoHost, this.wasm.protocolVersion());
|
|
18698
|
+
this._nodeFeatures = nodeInfo.features;
|
|
18699
|
+
this._nodeFeaturesKnown = true;
|
|
18700
|
+
this._nodeInfoIdentity = nodeInfo.nodeId ? { host: infoHost, nodeId: nodeInfo.nodeId } : void 0;
|
|
18701
|
+
}
|
|
18648
18702
|
/**
|
|
18649
18703
|
* The node DID reported by `GET /info` for `host`, if the sign-in (or
|
|
18650
18704
|
* restore) that populated it targeted that same host. Returns `undefined`
|
|
@@ -19308,13 +19362,7 @@ var NodeUserAuthorization = class {
|
|
|
19308
19362
|
this._tinyCloudSession = tinyCloudSession;
|
|
19309
19363
|
this._address = address;
|
|
19310
19364
|
this._chainId = chainId;
|
|
19311
|
-
|
|
19312
|
-
const nodeInfo = await (0, import_sdk_core4.checkNodeInfo)(
|
|
19313
|
-
infoHost,
|
|
19314
|
-
this.wasm.protocolVersion()
|
|
19315
|
-
);
|
|
19316
|
-
this._nodeFeatures = nodeInfo.features;
|
|
19317
|
-
this._nodeInfoIdentity = nodeInfo.nodeId ? { host: infoHost, nodeId: nodeInfo.nodeId } : void 0;
|
|
19365
|
+
await this.refreshNodeInfo();
|
|
19318
19366
|
for (const ext of this.extensions) {
|
|
19319
19367
|
if (ext.afterSignIn) {
|
|
19320
19368
|
await ext.afterSignIn(clientSession);
|
|
@@ -19480,13 +19528,7 @@ var NodeUserAuthorization = class {
|
|
|
19480
19528
|
this._tinyCloudSession = tinyCloudSession;
|
|
19481
19529
|
this._address = address;
|
|
19482
19530
|
this._chainId = chainId;
|
|
19483
|
-
|
|
19484
|
-
const nodeInfo = await (0, import_sdk_core4.checkNodeInfo)(
|
|
19485
|
-
infoHost,
|
|
19486
|
-
this.wasm.protocolVersion()
|
|
19487
|
-
);
|
|
19488
|
-
this._nodeFeatures = nodeInfo.features;
|
|
19489
|
-
this._nodeInfoIdentity = nodeInfo.nodeId ? { host: infoHost, nodeId: nodeInfo.nodeId } : void 0;
|
|
19531
|
+
await this.refreshNodeInfo();
|
|
19490
19532
|
for (const ext of this.extensions) {
|
|
19491
19533
|
if (ext.afterSignIn) {
|
|
19492
19534
|
await ext.afterSignIn(clientSession);
|
|
@@ -21053,7 +21095,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21053
21095
|
return this._bootstrapStatus;
|
|
21054
21096
|
}
|
|
21055
21097
|
get nodeFeatures() {
|
|
21056
|
-
return this.auth?.nodeFeatures ?? [];
|
|
21098
|
+
return this.auth?.nodeFeatures ?? this._restoredNodeFeatures ?? [];
|
|
21099
|
+
}
|
|
21100
|
+
get replicationNodeFeatures() {
|
|
21101
|
+
if (this.auth) return this.auth.nodeFeaturesKnown ? this.auth.nodeFeatures : void 0;
|
|
21102
|
+
return this._restoredNodeFeatures;
|
|
21057
21103
|
}
|
|
21058
21104
|
/** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
|
|
21059
21105
|
get siweDomain() {
|
|
@@ -22406,6 +22452,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22406
22452
|
sessionData.chainId
|
|
22407
22453
|
);
|
|
22408
22454
|
const stagedHost = resolvedHost ?? this.config.host;
|
|
22455
|
+
let restoredNodeFeatures;
|
|
22456
|
+
if (this.config.replication?.enabled) {
|
|
22457
|
+
try {
|
|
22458
|
+
restoredNodeFeatures = (await (0, import_sdk_core9.checkNodeInfo)(stagedHost, this.wasmBindings.protocolVersion())).features;
|
|
22459
|
+
} catch (error) {
|
|
22460
|
+
if (!(error instanceof import_sdk_core9.VersionCheckError)) throw error;
|
|
22461
|
+
}
|
|
22462
|
+
}
|
|
22409
22463
|
const stagedAddress = restoredAddress;
|
|
22410
22464
|
const stagedChainId = sessionData.chainId ?? 1;
|
|
22411
22465
|
let replicationPrincipal;
|
|
@@ -22508,8 +22562,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22508
22562
|
this._recapOperationsCache = stagedPrimary.cache;
|
|
22509
22563
|
this.runtimePermissionGrants = stagedPrimary.grants;
|
|
22510
22564
|
this.confirmedHostedSpaceIds.clear();
|
|
22565
|
+
this._restoredNodeFeatures = restoredNodeFeatures;
|
|
22511
22566
|
if (this.auth) {
|
|
22512
|
-
this.auth.installRestoredSession(stagedManager, stagedTcSession, [stagedHost]);
|
|
22567
|
+
this.auth.installRestoredSession(stagedManager, stagedTcSession, [stagedHost], restoredNodeFeatures);
|
|
22513
22568
|
this._restoredTcSession = void 0;
|
|
22514
22569
|
} else {
|
|
22515
22570
|
this._restoredTcSession = stagedTcSession;
|
|
@@ -23339,7 +23394,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
23339
23394
|
);
|
|
23340
23395
|
graph.assertActive();
|
|
23341
23396
|
if (!response.ok) {
|
|
23342
|
-
const permissionHint = response.status === 401 || response.status === 403 ? (0,
|
|
23397
|
+
const permissionHint = response.status === 401 || response.status === 403 ? (0, import_sdk_services2.parsePermissionHint)({
|
|
23343
23398
|
service: "tinycloud.encryption",
|
|
23344
23399
|
path: networkId,
|
|
23345
23400
|
actions: ["tinycloud.encryption/decrypt"]
|
|
@@ -24107,7 +24162,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
24107
24162
|
);
|
|
24108
24163
|
if (result.status !== "ok") {
|
|
24109
24164
|
if (result.status === "permission_required") {
|
|
24110
|
-
const hint = (0,
|
|
24165
|
+
const hint = (0, import_sdk_services2.parsePermissionHint)(result.hint);
|
|
24111
24166
|
if (hint === void 0) return { status: "read_failed" };
|
|
24112
24167
|
return {
|
|
24113
24168
|
status: "permission_required",
|
|
@@ -25083,6 +25138,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
25083
25138
|
session,
|
|
25084
25139
|
principal: identityPrincipal,
|
|
25085
25140
|
authority,
|
|
25141
|
+
nodeFeatures: this.replicationNodeFeatures,
|
|
25086
25142
|
primaryKV: [{ space: session.spaceId, kv }]
|
|
25087
25143
|
});
|
|
25088
25144
|
}
|
|
@@ -26405,7 +26461,7 @@ var import_node_crypto2 = require("crypto");
|
|
|
26405
26461
|
var import_promises = require("fs/promises");
|
|
26406
26462
|
var import_node_path = require("path");
|
|
26407
26463
|
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
26408
|
-
var
|
|
26464
|
+
var import_sdk_services3 = require("@tinycloud/sdk-services");
|
|
26409
26465
|
init_authority();
|
|
26410
26466
|
var ReplicaStorageError = class extends Error {
|
|
26411
26467
|
constructor(code, message, options) {
|
|
@@ -26453,7 +26509,7 @@ function sha256Base32(material) {
|
|
|
26453
26509
|
return out.slice(0, 26);
|
|
26454
26510
|
}
|
|
26455
26511
|
function partitionDirOf(root, identity) {
|
|
26456
|
-
return (0, import_node_path.join)(root, sha256Base32((0,
|
|
26512
|
+
return (0, import_node_path.join)(root, sha256Base32((0, import_sdk_services3.replicationIdentityKey)(identity)));
|
|
26457
26513
|
}
|
|
26458
26514
|
function replicaHashOf(prefix, deviceDid) {
|
|
26459
26515
|
return sha256Base32(`${prefix}
|
|
@@ -26527,8 +26583,8 @@ function deviceRecordOf(value) {
|
|
|
26527
26583
|
}
|
|
26528
26584
|
function sameIdentity(a, b) {
|
|
26529
26585
|
try {
|
|
26530
|
-
const left = (0,
|
|
26531
|
-
const right = (0,
|
|
26586
|
+
const left = (0, import_sdk_services3.canonicalReplicationIdentity)(a);
|
|
26587
|
+
const right = (0, import_sdk_services3.canonicalReplicationIdentity)(b);
|
|
26532
26588
|
return left.host === right.host && left.space === right.space && left.principal === right.principal;
|
|
26533
26589
|
} catch {
|
|
26534
26590
|
return false;
|
|
@@ -26544,7 +26600,7 @@ async function ensurePartitionIdentity(dir, identity, dirSync) {
|
|
|
26544
26600
|
const file = (0, import_node_path.join)(dir, "identity.json");
|
|
26545
26601
|
const existing = await readJsonFile(file);
|
|
26546
26602
|
if (existing === void 0) {
|
|
26547
|
-
await writeJsonAtomic(file, { v: 1, ...(0,
|
|
26603
|
+
await writeJsonAtomic(file, { v: 1, ...(0, import_sdk_services3.canonicalReplicationIdentity)(identity) }, dirSync);
|
|
26548
26604
|
return;
|
|
26549
26605
|
}
|
|
26550
26606
|
const record = identityRecordOf(existing);
|
|
@@ -27012,7 +27068,7 @@ function createSqliteReplicaStorage(options) {
|
|
|
27012
27068
|
// @ts-ignore — same as above.
|
|
27013
27069
|
import("@tinycloud/replica/sqlite")
|
|
27014
27070
|
]);
|
|
27015
|
-
if ((0,
|
|
27071
|
+
if ((0, import_sdk_services3.requiresSecretsOptIn)(spec.space, spec.prefix) && spec.allowSecrets !== true) {
|
|
27016
27072
|
throw new replica.ReplicaError(
|
|
27017
27073
|
replica.ReplicaErrorCode.SECRETS_OPT_IN_REQUIRED,
|
|
27018
27074
|
`Replicating ${spec.space}/kv/${spec.prefix} copies secret material to disk; pass allowSecrets to opt in.`
|
|
@@ -27393,6 +27449,7 @@ function sqliteReplicaStorage(options) {
|
|
|
27393
27449
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
27394
27450
|
serializeDelegation,
|
|
27395
27451
|
signedCompactUcanExpiry,
|
|
27452
|
+
siweRuntimeDelegation,
|
|
27396
27453
|
sqliteReplicaStorage,
|
|
27397
27454
|
tinyCloudDebugLogger,
|
|
27398
27455
|
validateEnvelope,
|