@tinycloud/node-sdk 2.0.4 → 2.1.0-beta.1
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.cjs +428 -93
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +102 -3
- package/dist/core.d.ts +102 -3
- package/dist/core.js +363 -17
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +435 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +380 -19
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -17025,53 +17025,63 @@ var require_utils2 = __commonJS({
|
|
|
17025
17025
|
// src/index.ts
|
|
17026
17026
|
var index_exports = {};
|
|
17027
17027
|
__export(index_exports, {
|
|
17028
|
-
AutoApproveSpaceCreationHandler: () =>
|
|
17029
|
-
CapabilityKeyRegistry: () =>
|
|
17030
|
-
CapabilityKeyRegistryErrorCodes: () =>
|
|
17031
|
-
DataVaultService: () =>
|
|
17032
|
-
DatabaseHandle: () =>
|
|
17028
|
+
AutoApproveSpaceCreationHandler: () => import_sdk_core7.AutoApproveSpaceCreationHandler,
|
|
17029
|
+
CapabilityKeyRegistry: () => import_sdk_core15.CapabilityKeyRegistry,
|
|
17030
|
+
CapabilityKeyRegistryErrorCodes: () => import_sdk_core15.CapabilityKeyRegistryErrorCodes,
|
|
17031
|
+
DataVaultService: () => import_sdk_core12.DataVaultService,
|
|
17032
|
+
DatabaseHandle: () => import_sdk_core10.DatabaseHandle,
|
|
17033
17033
|
DelegatedAccess: () => DelegatedAccess,
|
|
17034
|
-
DelegationErrorCodes: () =>
|
|
17035
|
-
DelegationManager: () =>
|
|
17036
|
-
DuckDbAction: () =>
|
|
17037
|
-
DuckDbDatabaseHandle: () =>
|
|
17038
|
-
DuckDbService: () =>
|
|
17034
|
+
DelegationErrorCodes: () => import_sdk_core14.DelegationErrorCodes,
|
|
17035
|
+
DelegationManager: () => import_sdk_core14.DelegationManager,
|
|
17036
|
+
DuckDbAction: () => import_sdk_core11.DuckDbAction,
|
|
17037
|
+
DuckDbDatabaseHandle: () => import_sdk_core11.DuckDbDatabaseHandle,
|
|
17038
|
+
DuckDbService: () => import_sdk_core11.DuckDbService,
|
|
17039
17039
|
FileSessionStorage: () => FileSessionStorage,
|
|
17040
|
-
|
|
17040
|
+
HooksService: () => import_sdk_core13.HooksService,
|
|
17041
|
+
KVService: () => import_sdk_core9.KVService,
|
|
17042
|
+
ManifestValidationError: () => import_sdk_core8.ManifestValidationError,
|
|
17041
17043
|
MemorySessionStorage: () => MemorySessionStorage,
|
|
17042
17044
|
NodeUserAuthorization: () => NodeUserAuthorization,
|
|
17043
17045
|
NodeWasmBindings: () => NodeWasmBindings,
|
|
17044
|
-
|
|
17046
|
+
PermissionNotInManifestError: () => import_sdk_core8.PermissionNotInManifestError,
|
|
17047
|
+
PrefixedKVService: () => import_sdk_core9.PrefixedKVService,
|
|
17045
17048
|
PrivateKeySigner: () => PrivateKeySigner,
|
|
17046
|
-
ProtocolMismatchError: () =>
|
|
17047
|
-
SQLAction: () =>
|
|
17048
|
-
SQLService: () =>
|
|
17049
|
-
ServiceContext: () =>
|
|
17050
|
-
|
|
17051
|
-
|
|
17052
|
-
|
|
17053
|
-
|
|
17054
|
-
|
|
17055
|
-
|
|
17049
|
+
ProtocolMismatchError: () => import_sdk_core17.ProtocolMismatchError,
|
|
17050
|
+
SQLAction: () => import_sdk_core10.SQLAction,
|
|
17051
|
+
SQLService: () => import_sdk_core10.SQLService,
|
|
17052
|
+
ServiceContext: () => import_sdk_core18.ServiceContext,
|
|
17053
|
+
SessionExpiredError: () => import_sdk_core8.SessionExpiredError,
|
|
17054
|
+
SharingService: () => import_sdk_core14.SharingService,
|
|
17055
|
+
SilentNotificationHandler: () => import_sdk_core7.SilentNotificationHandler,
|
|
17056
|
+
Space: () => import_sdk_core16.Space,
|
|
17057
|
+
SpaceErrorCodes: () => import_sdk_core16.SpaceErrorCodes,
|
|
17058
|
+
SpaceService: () => import_sdk_core16.SpaceService,
|
|
17059
|
+
TinyCloud: () => import_sdk_core6.TinyCloud,
|
|
17056
17060
|
TinyCloudNode: () => TinyCloudNode,
|
|
17057
|
-
UnsupportedFeatureError: () =>
|
|
17058
|
-
VaultHeaders: () =>
|
|
17059
|
-
VaultPublicSpaceKVActions: () =>
|
|
17060
|
-
VersionCheckError: () =>
|
|
17061
|
+
UnsupportedFeatureError: () => import_sdk_core17.UnsupportedFeatureError,
|
|
17062
|
+
VaultHeaders: () => import_sdk_core12.VaultHeaders,
|
|
17063
|
+
VaultPublicSpaceKVActions: () => import_sdk_core12.VaultPublicSpaceKVActions,
|
|
17064
|
+
VersionCheckError: () => import_sdk_core17.VersionCheckError,
|
|
17061
17065
|
WasmKeyProvider: () => WasmKeyProvider,
|
|
17062
|
-
buildSpaceUri: () =>
|
|
17063
|
-
checkNodeInfo: () =>
|
|
17064
|
-
createCapabilityKeyRegistry: () =>
|
|
17065
|
-
createSharingService: () =>
|
|
17066
|
-
createSpaceService: () =>
|
|
17067
|
-
createVaultCrypto: () =>
|
|
17066
|
+
buildSpaceUri: () => import_sdk_core16.buildSpaceUri,
|
|
17067
|
+
checkNodeInfo: () => import_sdk_core17.checkNodeInfo,
|
|
17068
|
+
createCapabilityKeyRegistry: () => import_sdk_core15.createCapabilityKeyRegistry,
|
|
17069
|
+
createSharingService: () => import_sdk_core14.createSharingService,
|
|
17070
|
+
createSpaceService: () => import_sdk_core16.createSpaceService,
|
|
17071
|
+
createVaultCrypto: () => import_sdk_core12.createVaultCrypto,
|
|
17068
17072
|
createWasmKeyProvider: () => createWasmKeyProvider,
|
|
17069
17073
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
17070
|
-
defaultSpaceCreationHandler: () =>
|
|
17074
|
+
defaultSpaceCreationHandler: () => import_sdk_core7.defaultSpaceCreationHandler,
|
|
17071
17075
|
deserializeDelegation: () => deserializeDelegation,
|
|
17072
|
-
|
|
17073
|
-
|
|
17074
|
-
|
|
17076
|
+
expandActionShortNames: () => import_sdk_core8.expandActionShortNames,
|
|
17077
|
+
isCapabilitySubset: () => import_sdk_core8.isCapabilitySubset,
|
|
17078
|
+
loadManifest: () => import_sdk_core8.loadManifest,
|
|
17079
|
+
makePublicSpaceId: () => import_sdk_core16.makePublicSpaceId,
|
|
17080
|
+
parseExpiry: () => import_sdk_core8.parseExpiry,
|
|
17081
|
+
parseSpaceUri: () => import_sdk_core16.parseSpaceUri,
|
|
17082
|
+
resolveManifest: () => import_sdk_core8.resolveManifest,
|
|
17083
|
+
serializeDelegation: () => serializeDelegation,
|
|
17084
|
+
validateManifest: () => import_sdk_core8.validateManifest
|
|
17075
17085
|
});
|
|
17076
17086
|
module.exports = __toCommonJS(index_exports);
|
|
17077
17087
|
|
|
@@ -17080,11 +17090,13 @@ var import_node_sdk_wasm = require("@tinycloud/node-sdk-wasm");
|
|
|
17080
17090
|
var _NodeWasmBindings = class _NodeWasmBindings {
|
|
17081
17091
|
constructor() {
|
|
17082
17092
|
this.invoke = import_node_sdk_wasm.invoke;
|
|
17093
|
+
this.invokeAny = import_node_sdk_wasm.invokeAny;
|
|
17083
17094
|
this.prepareSession = import_node_sdk_wasm.prepareSession;
|
|
17084
17095
|
this.completeSessionSetup = import_node_sdk_wasm.completeSessionSetup;
|
|
17085
17096
|
this.ensureEip55 = import_node_sdk_wasm.ensureEip55;
|
|
17086
17097
|
this.makeSpaceId = import_node_sdk_wasm.makeSpaceId;
|
|
17087
17098
|
this.createDelegation = import_node_sdk_wasm.createDelegation;
|
|
17099
|
+
this.parseRecapFromSiwe = import_node_sdk_wasm.parseRecapFromSiwe;
|
|
17088
17100
|
this.generateHostSIWEMessage = import_node_sdk_wasm.generateHostSIWEMessage;
|
|
17089
17101
|
this.siweToDelegationHeaders = import_node_sdk_wasm.siweToDelegationHeaders;
|
|
17090
17102
|
this.protocolVersion = import_node_sdk_wasm.protocolVersion;
|
|
@@ -17173,7 +17185,7 @@ var PrivateKeySigner = class {
|
|
|
17173
17185
|
};
|
|
17174
17186
|
|
|
17175
17187
|
// src/TinyCloudNode.ts
|
|
17176
|
-
var
|
|
17188
|
+
var import_sdk_core4 = require("@tinycloud/sdk-core");
|
|
17177
17189
|
|
|
17178
17190
|
// src/authorization/NodeUserAuthorization.ts
|
|
17179
17191
|
var import_sdk_core = require("@tinycloud/sdk-core");
|
|
@@ -17296,12 +17308,22 @@ var NodeUserAuthorization = class {
|
|
|
17296
17308
|
},
|
|
17297
17309
|
capabilities: {
|
|
17298
17310
|
"": ["tinycloud.capabilities/read"]
|
|
17311
|
+
},
|
|
17312
|
+
hooks: {
|
|
17313
|
+
"": [
|
|
17314
|
+
"tinycloud.hooks/subscribe",
|
|
17315
|
+
"tinycloud.hooks/register",
|
|
17316
|
+
"tinycloud.hooks/list",
|
|
17317
|
+
"tinycloud.hooks/unregister"
|
|
17318
|
+
]
|
|
17299
17319
|
}
|
|
17300
17320
|
};
|
|
17301
17321
|
this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
|
|
17302
17322
|
this.autoCreateSpace = config.autoCreateSpace ?? false;
|
|
17303
17323
|
this.spaceCreationHandler = config.spaceCreationHandler;
|
|
17304
|
-
this.tinycloudHosts = config.tinycloudHosts ?? [
|
|
17324
|
+
this.tinycloudHosts = config.tinycloudHosts ?? [
|
|
17325
|
+
"https://node.tinycloud.xyz"
|
|
17326
|
+
];
|
|
17305
17327
|
this.enablePublicSpace = config.enablePublicSpace ?? true;
|
|
17306
17328
|
this.nonce = config.nonce;
|
|
17307
17329
|
this.siweConfig = config.siweConfig;
|
|
@@ -17441,7 +17463,10 @@ var NodeUserAuthorization = class {
|
|
|
17441
17463
|
throw err;
|
|
17442
17464
|
}
|
|
17443
17465
|
} catch (error) {
|
|
17444
|
-
handler.onSpaceCreationFailed?.(
|
|
17466
|
+
handler.onSpaceCreationFailed?.(
|
|
17467
|
+
creationContext,
|
|
17468
|
+
error instanceof Error ? error : new Error(String(error))
|
|
17469
|
+
);
|
|
17445
17470
|
throw error;
|
|
17446
17471
|
}
|
|
17447
17472
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -17475,7 +17500,10 @@ var NodeUserAuthorization = class {
|
|
|
17475
17500
|
throw err;
|
|
17476
17501
|
}
|
|
17477
17502
|
} catch (error) {
|
|
17478
|
-
handler.onSpaceCreationFailed?.(
|
|
17503
|
+
handler.onSpaceCreationFailed?.(
|
|
17504
|
+
creationContext,
|
|
17505
|
+
error instanceof Error ? error : new Error(String(error))
|
|
17506
|
+
);
|
|
17479
17507
|
throw error;
|
|
17480
17508
|
}
|
|
17481
17509
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -17584,7 +17612,10 @@ var NodeUserAuthorization = class {
|
|
|
17584
17612
|
this._tinyCloudSession = tinyCloudSession;
|
|
17585
17613
|
this._address = address;
|
|
17586
17614
|
this._chainId = chainId;
|
|
17587
|
-
const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
|
|
17615
|
+
const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
|
|
17616
|
+
this.tinycloudHosts[0],
|
|
17617
|
+
this.wasm.protocolVersion()
|
|
17618
|
+
);
|
|
17588
17619
|
this._nodeFeatures = nodeInfo.features;
|
|
17589
17620
|
for (const ext of this.extensions) {
|
|
17590
17621
|
if (ext.afterSignIn) {
|
|
@@ -17744,7 +17775,10 @@ var NodeUserAuthorization = class {
|
|
|
17744
17775
|
this._tinyCloudSession = tinyCloudSession;
|
|
17745
17776
|
this._address = address;
|
|
17746
17777
|
this._chainId = chainId;
|
|
17747
|
-
const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
|
|
17778
|
+
const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
|
|
17779
|
+
this.tinycloudHosts[0],
|
|
17780
|
+
this.wasm.protocolVersion()
|
|
17781
|
+
);
|
|
17748
17782
|
this._nodeFeatures = nodeInfo.features;
|
|
17749
17783
|
for (const ext of this.extensions) {
|
|
17750
17784
|
if (ext.afterSignIn) {
|
|
@@ -17795,7 +17829,9 @@ var NodeUserAuthorization = class {
|
|
|
17795
17829
|
);
|
|
17796
17830
|
}
|
|
17797
17831
|
default:
|
|
17798
|
-
throw new Error(
|
|
17832
|
+
throw new Error(
|
|
17833
|
+
`Unknown sign strategy: ${this.signStrategy.type}`
|
|
17834
|
+
);
|
|
17799
17835
|
}
|
|
17800
17836
|
}
|
|
17801
17837
|
/**
|
|
@@ -17844,6 +17880,9 @@ var DelegatedAccess = class {
|
|
|
17844
17880
|
this._duckdb = new import_sdk_core2.DuckDbService({});
|
|
17845
17881
|
this._duckdb.initialize(this._serviceContext);
|
|
17846
17882
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
17883
|
+
this._hooks = new import_sdk_core2.HooksService({});
|
|
17884
|
+
this._hooks.initialize(this._serviceContext);
|
|
17885
|
+
this._serviceContext.registerService("hooks", this._hooks);
|
|
17847
17886
|
const serviceSession = {
|
|
17848
17887
|
delegationHeader: session.delegationHeader,
|
|
17849
17888
|
delegationCid: session.delegationCid,
|
|
@@ -17889,6 +17928,12 @@ var DelegatedAccess = class {
|
|
|
17889
17928
|
get duckdb() {
|
|
17890
17929
|
return this._duckdb;
|
|
17891
17930
|
}
|
|
17931
|
+
/**
|
|
17932
|
+
* Hooks write-stream subscriptions on the delegated space.
|
|
17933
|
+
*/
|
|
17934
|
+
get hooks() {
|
|
17935
|
+
return this._hooks;
|
|
17936
|
+
}
|
|
17892
17937
|
};
|
|
17893
17938
|
|
|
17894
17939
|
// src/keys/WasmKeyProvider.ts
|
|
@@ -17966,9 +18011,69 @@ function createWasmKeyProvider(sessionManager) {
|
|
|
17966
18011
|
return new WasmKeyProvider({ sessionManager });
|
|
17967
18012
|
}
|
|
17968
18013
|
|
|
18014
|
+
// src/delegateToHelpers.ts
|
|
18015
|
+
var import_sdk_core3 = require("@tinycloud/sdk-core");
|
|
18016
|
+
function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
18017
|
+
const byService = /* @__PURE__ */ new Map();
|
|
18018
|
+
for (const a of actions) {
|
|
18019
|
+
const slashIdx = a.indexOf("/");
|
|
18020
|
+
if (slashIdx === -1) {
|
|
18021
|
+
continue;
|
|
18022
|
+
}
|
|
18023
|
+
const service = a.slice(0, slashIdx);
|
|
18024
|
+
if (!service.startsWith("tinycloud.")) {
|
|
18025
|
+
continue;
|
|
18026
|
+
}
|
|
18027
|
+
const list = byService.get(service);
|
|
18028
|
+
if (list === void 0) {
|
|
18029
|
+
byService.set(service, [a]);
|
|
18030
|
+
} else {
|
|
18031
|
+
list.push(a);
|
|
18032
|
+
}
|
|
18033
|
+
}
|
|
18034
|
+
const space = spaceIdOverride ?? "default";
|
|
18035
|
+
const entries = [];
|
|
18036
|
+
for (const [service, actionList] of byService) {
|
|
18037
|
+
entries.push({
|
|
18038
|
+
service,
|
|
18039
|
+
space,
|
|
18040
|
+
path,
|
|
18041
|
+
actions: actionList
|
|
18042
|
+
});
|
|
18043
|
+
}
|
|
18044
|
+
return entries;
|
|
18045
|
+
}
|
|
18046
|
+
function resolveExpiryMs(expiry) {
|
|
18047
|
+
if (expiry === void 0) {
|
|
18048
|
+
return 60 * 60 * 1e3;
|
|
18049
|
+
}
|
|
18050
|
+
if (typeof expiry === "number") {
|
|
18051
|
+
if (!Number.isFinite(expiry) || expiry <= 0) {
|
|
18052
|
+
throw new Error(
|
|
18053
|
+
`delegateTo expiry must be a positive finite number (got ${expiry})`
|
|
18054
|
+
);
|
|
18055
|
+
}
|
|
18056
|
+
return expiry;
|
|
18057
|
+
}
|
|
18058
|
+
return (0, import_sdk_core3.parseExpiry)(expiry);
|
|
18059
|
+
}
|
|
18060
|
+
function extractSiweExpiration(siwe) {
|
|
18061
|
+
const parsed = new import_sdk_core3.SiweMessage(siwe);
|
|
18062
|
+
if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
|
|
18063
|
+
return void 0;
|
|
18064
|
+
}
|
|
18065
|
+
const d = new Date(parsed.expirationTime);
|
|
18066
|
+
if (Number.isNaN(d.getTime())) {
|
|
18067
|
+
throw new Error(
|
|
18068
|
+
`Session SIWE has unparseable expirationTime: ${parsed.expirationTime}`
|
|
18069
|
+
);
|
|
18070
|
+
}
|
|
18071
|
+
return d;
|
|
18072
|
+
}
|
|
18073
|
+
|
|
17969
18074
|
// src/TinyCloudNode.ts
|
|
17970
18075
|
var DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
17971
|
-
var
|
|
18076
|
+
var _TinyCloudNode = class _TinyCloudNode {
|
|
17972
18077
|
/**
|
|
17973
18078
|
* Create a new TinyCloudNode instance.
|
|
17974
18079
|
*
|
|
@@ -18023,12 +18128,12 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18023
18128
|
throw new Error("Failed to get session key JWK");
|
|
18024
18129
|
}
|
|
18025
18130
|
this.sessionKeyJwk = JSON.parse(jwkStr);
|
|
18026
|
-
this._capabilityRegistry = new
|
|
18131
|
+
this._capabilityRegistry = new import_sdk_core4.CapabilityKeyRegistry();
|
|
18027
18132
|
this._keyProvider = new WasmKeyProvider({
|
|
18028
18133
|
sessionManager: this.sessionManager
|
|
18029
18134
|
});
|
|
18030
|
-
this.notificationHandler = config.notificationHandler ?? new
|
|
18031
|
-
this._sharingService = new
|
|
18135
|
+
this.notificationHandler = config.notificationHandler ?? new import_sdk_core4.SilentNotificationHandler();
|
|
18136
|
+
this._sharingService = new import_sdk_core4.SharingService({
|
|
18032
18137
|
hosts: [this.config.host],
|
|
18033
18138
|
// session: undefined - not needed for receive()
|
|
18034
18139
|
invoke: this.wasmBindings.invoke,
|
|
@@ -18038,8 +18143,8 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18038
18143
|
// delegationManager: undefined - not needed for receive()
|
|
18039
18144
|
createKVService: (config2) => {
|
|
18040
18145
|
const prefix = config2.pathPrefix?.replace(/\/$/, "");
|
|
18041
|
-
const kvService = new
|
|
18042
|
-
const kvContext = new
|
|
18146
|
+
const kvService = new import_sdk_core4.KVService({ prefix });
|
|
18147
|
+
const kvContext = new import_sdk_core4.ServiceContext({
|
|
18043
18148
|
invoke: config2.invoke,
|
|
18044
18149
|
fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
|
|
18045
18150
|
hosts: config2.hosts
|
|
@@ -18094,7 +18199,9 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18094
18199
|
nonce: config.nonce,
|
|
18095
18200
|
siweConfig: config.siweConfig
|
|
18096
18201
|
});
|
|
18097
|
-
this.tc = new
|
|
18202
|
+
this.tc = new import_sdk_core4.TinyCloud(this.auth, {
|
|
18203
|
+
invokeAny: this.wasmBindings.invokeAny
|
|
18204
|
+
});
|
|
18098
18205
|
}
|
|
18099
18206
|
/**
|
|
18100
18207
|
* Get the primary identity DID for this user.
|
|
@@ -18163,6 +18270,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18163
18270
|
this._kv = void 0;
|
|
18164
18271
|
this._sql = void 0;
|
|
18165
18272
|
this._duckdb = void 0;
|
|
18273
|
+
this._hooks = void 0;
|
|
18166
18274
|
this._serviceContext = void 0;
|
|
18167
18275
|
await this.tc.signIn();
|
|
18168
18276
|
this.initializeServices();
|
|
@@ -18182,6 +18290,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18182
18290
|
this._kv = void 0;
|
|
18183
18291
|
this._sql = void 0;
|
|
18184
18292
|
this._duckdb = void 0;
|
|
18293
|
+
this._hooks = void 0;
|
|
18185
18294
|
this._serviceContext = void 0;
|
|
18186
18295
|
if (sessionData.address) {
|
|
18187
18296
|
this._address = sessionData.address;
|
|
@@ -18189,20 +18298,24 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18189
18298
|
if (sessionData.chainId) {
|
|
18190
18299
|
this._chainId = sessionData.chainId;
|
|
18191
18300
|
}
|
|
18192
|
-
this._serviceContext = new
|
|
18301
|
+
this._serviceContext = new import_sdk_core4.ServiceContext({
|
|
18193
18302
|
invoke: this.wasmBindings.invoke,
|
|
18303
|
+
invokeAny: this.wasmBindings.invokeAny,
|
|
18194
18304
|
fetch: globalThis.fetch.bind(globalThis),
|
|
18195
18305
|
hosts: [this.config.host]
|
|
18196
18306
|
});
|
|
18197
|
-
this._kv = new
|
|
18307
|
+
this._kv = new import_sdk_core4.KVService({});
|
|
18198
18308
|
this._kv.initialize(this._serviceContext);
|
|
18199
18309
|
this._serviceContext.registerService("kv", this._kv);
|
|
18200
|
-
this._sql = new
|
|
18310
|
+
this._sql = new import_sdk_core4.SQLService({});
|
|
18201
18311
|
this._sql.initialize(this._serviceContext);
|
|
18202
18312
|
this._serviceContext.registerService("sql", this._sql);
|
|
18203
|
-
this._duckdb = new
|
|
18313
|
+
this._duckdb = new import_sdk_core4.DuckDbService({});
|
|
18204
18314
|
this._duckdb.initialize(this._serviceContext);
|
|
18205
18315
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
18316
|
+
this._hooks = new import_sdk_core4.HooksService({});
|
|
18317
|
+
this._hooks.initialize(this._serviceContext);
|
|
18318
|
+
this._serviceContext.registerService("hooks", this._hooks);
|
|
18206
18319
|
const serviceSession = {
|
|
18207
18320
|
delegationHeader: sessionData.delegationHeader,
|
|
18208
18321
|
delegationCid: sessionData.delegationCid,
|
|
@@ -18212,7 +18325,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18212
18325
|
};
|
|
18213
18326
|
this._serviceContext.setSession(serviceSession);
|
|
18214
18327
|
const wasm = this.wasmBindings;
|
|
18215
|
-
const vaultCrypto = (0,
|
|
18328
|
+
const vaultCrypto = (0, import_sdk_core4.createVaultCrypto)({
|
|
18216
18329
|
vault_encrypt: wasm.vault_encrypt,
|
|
18217
18330
|
vault_decrypt: wasm.vault_decrypt,
|
|
18218
18331
|
vault_derive_key: wasm.vault_derive_key,
|
|
@@ -18222,7 +18335,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18222
18335
|
vault_sha256: wasm.vault_sha256
|
|
18223
18336
|
});
|
|
18224
18337
|
const self2 = this;
|
|
18225
|
-
this._vault = new
|
|
18338
|
+
this._vault = new import_sdk_core4.DataVaultService({
|
|
18226
18339
|
spaceId: sessionData.spaceId,
|
|
18227
18340
|
crypto: vaultCrypto,
|
|
18228
18341
|
tc: {
|
|
@@ -18238,8 +18351,8 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18238
18351
|
get publicKV() {
|
|
18239
18352
|
return self2._publicKV ?? self2.tc.publicKV;
|
|
18240
18353
|
},
|
|
18241
|
-
readPublicSpace: (host, spaceId, key2) =>
|
|
18242
|
-
makePublicSpaceId:
|
|
18354
|
+
readPublicSpace: (host, spaceId, key2) => import_sdk_core4.TinyCloud.readPublicSpace(host, spaceId, key2),
|
|
18355
|
+
makePublicSpaceId: import_sdk_core4.TinyCloud.makePublicSpaceId,
|
|
18243
18356
|
did: this.did,
|
|
18244
18357
|
address: sessionData.address ?? this._address ?? "",
|
|
18245
18358
|
chainId: sessionData.chainId ?? this._chainId,
|
|
@@ -18302,7 +18415,9 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18302
18415
|
nonce: this.config.nonce,
|
|
18303
18416
|
siweConfig: this.config.siweConfig
|
|
18304
18417
|
});
|
|
18305
|
-
this.tc = new
|
|
18418
|
+
this.tc = new import_sdk_core4.TinyCloud(this.auth, {
|
|
18419
|
+
invokeAny: this.wasmBindings.invokeAny
|
|
18420
|
+
});
|
|
18306
18421
|
this.config.prefix = prefix;
|
|
18307
18422
|
}
|
|
18308
18423
|
/**
|
|
@@ -18340,7 +18455,9 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18340
18455
|
nonce: this.config.nonce,
|
|
18341
18456
|
siweConfig: this.config.siweConfig
|
|
18342
18457
|
});
|
|
18343
|
-
this.tc = new
|
|
18458
|
+
this.tc = new import_sdk_core4.TinyCloud(this.auth, {
|
|
18459
|
+
invokeAny: this.wasmBindings.invokeAny
|
|
18460
|
+
});
|
|
18344
18461
|
this.config.prefix = prefix;
|
|
18345
18462
|
}
|
|
18346
18463
|
/**
|
|
@@ -18353,25 +18470,29 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18353
18470
|
return;
|
|
18354
18471
|
}
|
|
18355
18472
|
this.tc.initializeServices(this.wasmBindings.invoke, [this.config.host]);
|
|
18356
|
-
this._serviceContext = new
|
|
18473
|
+
this._serviceContext = new import_sdk_core4.ServiceContext({
|
|
18357
18474
|
invoke: this.wasmBindings.invoke,
|
|
18475
|
+
invokeAny: this.wasmBindings.invokeAny,
|
|
18358
18476
|
fetch: globalThis.fetch.bind(globalThis),
|
|
18359
18477
|
hosts: [this.config.host]
|
|
18360
18478
|
});
|
|
18361
|
-
this._kv = new
|
|
18479
|
+
this._kv = new import_sdk_core4.KVService({});
|
|
18362
18480
|
this._kv.initialize(this._serviceContext);
|
|
18363
18481
|
this._serviceContext.registerService("kv", this._kv);
|
|
18364
18482
|
const features = this.nodeFeatures;
|
|
18365
18483
|
if (features.length === 0 || features.includes("sql")) {
|
|
18366
|
-
this._sql = new
|
|
18484
|
+
this._sql = new import_sdk_core4.SQLService({});
|
|
18367
18485
|
this._sql.initialize(this._serviceContext);
|
|
18368
18486
|
this._serviceContext.registerService("sql", this._sql);
|
|
18369
18487
|
}
|
|
18370
18488
|
if (features.length === 0 || features.includes("duckdb")) {
|
|
18371
|
-
this._duckdb = new
|
|
18489
|
+
this._duckdb = new import_sdk_core4.DuckDbService({});
|
|
18372
18490
|
this._duckdb.initialize(this._serviceContext);
|
|
18373
18491
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
18374
18492
|
}
|
|
18493
|
+
this._hooks = new import_sdk_core4.HooksService({});
|
|
18494
|
+
this._hooks.initialize(this._serviceContext);
|
|
18495
|
+
this._serviceContext.registerService("hooks", this._hooks);
|
|
18375
18496
|
const serviceSession = {
|
|
18376
18497
|
delegationHeader: session.delegationHeader,
|
|
18377
18498
|
delegationCid: session.delegationCid,
|
|
@@ -18382,7 +18503,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18382
18503
|
this._serviceContext.setSession(serviceSession);
|
|
18383
18504
|
this.tc.serviceContext.setSession(serviceSession);
|
|
18384
18505
|
const wasm = this.wasmBindings;
|
|
18385
|
-
const vaultCrypto = (0,
|
|
18506
|
+
const vaultCrypto = (0, import_sdk_core4.createVaultCrypto)({
|
|
18386
18507
|
vault_encrypt: wasm.vault_encrypt,
|
|
18387
18508
|
vault_decrypt: wasm.vault_decrypt,
|
|
18388
18509
|
vault_derive_key: wasm.vault_derive_key,
|
|
@@ -18392,7 +18513,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18392
18513
|
vault_sha256: wasm.vault_sha256
|
|
18393
18514
|
});
|
|
18394
18515
|
const self2 = this;
|
|
18395
|
-
this._vault = new
|
|
18516
|
+
this._vault = new import_sdk_core4.DataVaultService({
|
|
18396
18517
|
spaceId: session.spaceId,
|
|
18397
18518
|
crypto: vaultCrypto,
|
|
18398
18519
|
tc: {
|
|
@@ -18408,8 +18529,8 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18408
18529
|
get publicKV() {
|
|
18409
18530
|
return self2._publicKV ?? self2.tc.publicKV;
|
|
18410
18531
|
},
|
|
18411
|
-
readPublicSpace: (host, spaceId, key2) =>
|
|
18412
|
-
makePublicSpaceId:
|
|
18532
|
+
readPublicSpace: (host, spaceId, key2) => import_sdk_core4.TinyCloud.readPublicSpace(host, spaceId, key2),
|
|
18533
|
+
makePublicSpaceId: import_sdk_core4.TinyCloud.makePublicSpaceId,
|
|
18413
18534
|
did: this.did,
|
|
18414
18535
|
address: this._address,
|
|
18415
18536
|
chainId: this._chainId,
|
|
@@ -18425,7 +18546,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18425
18546
|
* @internal
|
|
18426
18547
|
*/
|
|
18427
18548
|
initializeV2Services(serviceSession) {
|
|
18428
|
-
this._capabilityRegistry = new
|
|
18549
|
+
this._capabilityRegistry = new import_sdk_core4.CapabilityKeyRegistry();
|
|
18429
18550
|
const tcSession = this.auth?.tinyCloudSession;
|
|
18430
18551
|
if (tcSession && this._address) {
|
|
18431
18552
|
const sessionKey = {
|
|
@@ -18499,13 +18620,13 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18499
18620
|
}
|
|
18500
18621
|
this._capabilityRegistry.registerKey(sessionKey, delegations);
|
|
18501
18622
|
}
|
|
18502
|
-
this._delegationManager = new
|
|
18623
|
+
this._delegationManager = new import_sdk_core4.DelegationManager({
|
|
18503
18624
|
hosts: [this.config.host],
|
|
18504
18625
|
session: serviceSession,
|
|
18505
18626
|
invoke: this.wasmBindings.invoke,
|
|
18506
18627
|
fetch: globalThis.fetch.bind(globalThis)
|
|
18507
18628
|
});
|
|
18508
|
-
this._spaceService = new
|
|
18629
|
+
this._spaceService = new import_sdk_core4.SpaceService({
|
|
18509
18630
|
hosts: [this.config.host],
|
|
18510
18631
|
session: serviceSession,
|
|
18511
18632
|
invoke: this.wasmBindings.invoke,
|
|
@@ -18513,9 +18634,9 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18513
18634
|
capabilityRegistry: this._capabilityRegistry,
|
|
18514
18635
|
userDid: this.did,
|
|
18515
18636
|
createKVService: (spaceId) => {
|
|
18516
|
-
const kvService = new
|
|
18637
|
+
const kvService = new import_sdk_core4.KVService({});
|
|
18517
18638
|
if (this._serviceContext) {
|
|
18518
|
-
const spaceScopedContext = new
|
|
18639
|
+
const spaceScopedContext = new import_sdk_core4.ServiceContext({
|
|
18519
18640
|
invoke: this._serviceContext.invoke,
|
|
18520
18641
|
fetch: this._serviceContext.fetch,
|
|
18521
18642
|
hosts: this._serviceContext.hosts
|
|
@@ -18654,7 +18775,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18654
18775
|
...prepared,
|
|
18655
18776
|
signature: signature2
|
|
18656
18777
|
});
|
|
18657
|
-
const activateResult = await (0,
|
|
18778
|
+
const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
|
|
18658
18779
|
host,
|
|
18659
18780
|
delegationSession.delegationHeader
|
|
18660
18781
|
);
|
|
@@ -18721,7 +18842,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18721
18842
|
if (!this._sql) {
|
|
18722
18843
|
const features = this.nodeFeatures;
|
|
18723
18844
|
if (features.length > 0 && !features.includes("sql")) {
|
|
18724
|
-
throw new
|
|
18845
|
+
throw new import_sdk_core4.UnsupportedFeatureError("sql", this.config.host, features);
|
|
18725
18846
|
}
|
|
18726
18847
|
throw new Error("Not signed in. Call signIn() first.");
|
|
18727
18848
|
}
|
|
@@ -18734,7 +18855,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18734
18855
|
if (!this._duckdb) {
|
|
18735
18856
|
const features = this.nodeFeatures;
|
|
18736
18857
|
if (features.length > 0 && !features.includes("duckdb")) {
|
|
18737
|
-
throw new
|
|
18858
|
+
throw new import_sdk_core4.UnsupportedFeatureError("duckdb", this.config.host, features);
|
|
18738
18859
|
}
|
|
18739
18860
|
throw new Error("Not signed in. Call signIn() first.");
|
|
18740
18861
|
}
|
|
@@ -18750,6 +18871,15 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18750
18871
|
}
|
|
18751
18872
|
return this._vault;
|
|
18752
18873
|
}
|
|
18874
|
+
/**
|
|
18875
|
+
* Hooks write stream subscription API.
|
|
18876
|
+
*/
|
|
18877
|
+
get hooks() {
|
|
18878
|
+
if (!this._hooks) {
|
|
18879
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
18880
|
+
}
|
|
18881
|
+
return this._hooks;
|
|
18882
|
+
}
|
|
18753
18883
|
// ===========================================================================
|
|
18754
18884
|
// v2 Service Accessors
|
|
18755
18885
|
// ===========================================================================
|
|
@@ -18964,7 +19094,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18964
19094
|
...prepared,
|
|
18965
19095
|
signature: signature2
|
|
18966
19096
|
});
|
|
18967
|
-
const activateResult = await (0,
|
|
19097
|
+
const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
|
|
18968
19098
|
this.config.host,
|
|
18969
19099
|
delegationSession.delegationHeader
|
|
18970
19100
|
);
|
|
@@ -18991,8 +19121,8 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
18991
19121
|
}]);
|
|
18992
19122
|
}
|
|
18993
19123
|
if (this._serviceContext) {
|
|
18994
|
-
const publicKV = new
|
|
18995
|
-
const publicContext = new
|
|
19124
|
+
const publicKV = new import_sdk_core4.KVService({ prefix: "" });
|
|
19125
|
+
const publicContext = new import_sdk_core4.ServiceContext({
|
|
18996
19126
|
invoke: this.wasmBindings.invoke,
|
|
18997
19127
|
fetch: this._serviceContext.fetch,
|
|
18998
19128
|
hosts: this._serviceContext.hosts
|
|
@@ -19077,6 +19207,150 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19077
19207
|
async checkPermission(path, action) {
|
|
19078
19208
|
return this.delegationManager.checkPermission(path, action);
|
|
19079
19209
|
}
|
|
19210
|
+
/**
|
|
19211
|
+
* Issue a delegation using the capability-chain flow.
|
|
19212
|
+
*
|
|
19213
|
+
* When the requested permissions are a subset of the current session's
|
|
19214
|
+
* recap, the delegation is signed by the session key via WASM — no wallet
|
|
19215
|
+
* prompt. When they are not, a {@link PermissionNotInManifestError} is
|
|
19216
|
+
* raised so the caller can trigger an escalation flow (e.g.
|
|
19217
|
+
* `TinyCloudWeb.requestPermissions`). Passing `forceWalletSign: true`
|
|
19218
|
+
* bypasses the derivability check and always uses the wallet-signed SIWE
|
|
19219
|
+
* path — used by the legacy `createDelegation` fallback and by callers
|
|
19220
|
+
* that want explicit wallet confirmation.
|
|
19221
|
+
*
|
|
19222
|
+
* Current limitation: exactly one {@link PermissionEntry} per call. For
|
|
19223
|
+
* multi-resource delegation, call `delegateTo` multiple times. This keeps
|
|
19224
|
+
* each delegation a single `(spaceId, path)` grant, which matches the
|
|
19225
|
+
* underlying `PortableDelegation` shape.
|
|
19226
|
+
*
|
|
19227
|
+
* @throws {@link SessionExpiredError} when there is no session or the
|
|
19228
|
+
* current session has expired (or will within the 60s safety margin).
|
|
19229
|
+
* @throws {@link PermissionNotInManifestError} when the requested entries
|
|
19230
|
+
* are not a subset of the granted session capabilities and
|
|
19231
|
+
* `forceWalletSign` is not set.
|
|
19232
|
+
*/
|
|
19233
|
+
async delegateTo(did, permissions, options) {
|
|
19234
|
+
const session = this.auth?.tinyCloudSession;
|
|
19235
|
+
if (!session) {
|
|
19236
|
+
throw new import_sdk_core4.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
19237
|
+
}
|
|
19238
|
+
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
19239
|
+
if (sessionExpiry !== void 0) {
|
|
19240
|
+
const now2 = Date.now();
|
|
19241
|
+
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
19242
|
+
if (sessionExpiry.getTime() <= now2 + marginMs) {
|
|
19243
|
+
throw new import_sdk_core4.SessionExpiredError(sessionExpiry);
|
|
19244
|
+
}
|
|
19245
|
+
}
|
|
19246
|
+
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
19247
|
+
throw new Error(
|
|
19248
|
+
"delegateTo requires a non-empty permissions array"
|
|
19249
|
+
);
|
|
19250
|
+
}
|
|
19251
|
+
if (permissions.length > 1) {
|
|
19252
|
+
throw new Error(
|
|
19253
|
+
"delegateTo currently supports one permission entry per call. Call delegateTo multiple times for multi-resource delegation."
|
|
19254
|
+
);
|
|
19255
|
+
}
|
|
19256
|
+
const entry = permissions[0];
|
|
19257
|
+
const expandedEntry = {
|
|
19258
|
+
...entry,
|
|
19259
|
+
actions: (0, import_sdk_core4.expandActionShortNames)(entry.service, entry.actions)
|
|
19260
|
+
};
|
|
19261
|
+
const now = /* @__PURE__ */ new Date();
|
|
19262
|
+
const expiryMs = resolveExpiryMs(options?.expiry);
|
|
19263
|
+
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
19264
|
+
let effectiveExpiration = expirationTime;
|
|
19265
|
+
if (sessionExpiry !== void 0 && sessionExpiry < expirationTime) {
|
|
19266
|
+
effectiveExpiration = sessionExpiry;
|
|
19267
|
+
}
|
|
19268
|
+
if (options?.forceWalletSign) {
|
|
19269
|
+
const delegation2 = await this.createDelegationLegacyWalletPath(
|
|
19270
|
+
did,
|
|
19271
|
+
expandedEntry,
|
|
19272
|
+
effectiveExpiration
|
|
19273
|
+
);
|
|
19274
|
+
return { delegation: delegation2, prompted: true };
|
|
19275
|
+
}
|
|
19276
|
+
const granted = (0, import_sdk_core4.parseRecapCapabilities)(
|
|
19277
|
+
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
19278
|
+
session.siwe
|
|
19279
|
+
);
|
|
19280
|
+
const requested = [expandedEntry];
|
|
19281
|
+
const { subset, missing } = (0, import_sdk_core4.isCapabilitySubset)(requested, granted);
|
|
19282
|
+
if (!subset) {
|
|
19283
|
+
throw new import_sdk_core4.PermissionNotInManifestError(missing, granted);
|
|
19284
|
+
}
|
|
19285
|
+
const delegation = await this.createDelegationViaWasmPath(
|
|
19286
|
+
did,
|
|
19287
|
+
expandedEntry,
|
|
19288
|
+
effectiveExpiration,
|
|
19289
|
+
session
|
|
19290
|
+
);
|
|
19291
|
+
return { delegation, prompted: false };
|
|
19292
|
+
}
|
|
19293
|
+
/**
|
|
19294
|
+
* Issue a delegation via the session-key UCAN WASM path.
|
|
19295
|
+
*
|
|
19296
|
+
* The caller has already verified the request is derivable from the
|
|
19297
|
+
* current session; we just need to shape the inputs for
|
|
19298
|
+
* {@link createDelegationWrapper}.
|
|
19299
|
+
*
|
|
19300
|
+
* @internal
|
|
19301
|
+
*/
|
|
19302
|
+
async createDelegationViaWasmPath(did, entry, expirationTime, session) {
|
|
19303
|
+
const spaceId = entry.space === "default" ? session.spaceId : entry.space;
|
|
19304
|
+
const serviceSession = {
|
|
19305
|
+
delegationHeader: session.delegationHeader,
|
|
19306
|
+
delegationCid: session.delegationCid,
|
|
19307
|
+
jwk: session.jwk,
|
|
19308
|
+
spaceId,
|
|
19309
|
+
verificationMethod: session.verificationMethod
|
|
19310
|
+
};
|
|
19311
|
+
const expirationSecs = Math.floor(expirationTime.getTime() / 1e3);
|
|
19312
|
+
const result = this.createDelegationWrapper({
|
|
19313
|
+
session: serviceSession,
|
|
19314
|
+
delegateDID: did,
|
|
19315
|
+
spaceId,
|
|
19316
|
+
path: entry.path,
|
|
19317
|
+
actions: entry.actions,
|
|
19318
|
+
expirationSecs
|
|
19319
|
+
});
|
|
19320
|
+
return {
|
|
19321
|
+
cid: result.cid,
|
|
19322
|
+
delegationHeader: { Authorization: `Bearer ${result.delegation}` },
|
|
19323
|
+
spaceId,
|
|
19324
|
+
path: entry.path,
|
|
19325
|
+
actions: entry.actions,
|
|
19326
|
+
disableSubDelegation: false,
|
|
19327
|
+
expiry: result.expiry,
|
|
19328
|
+
delegateDID: did,
|
|
19329
|
+
ownerAddress: session.address,
|
|
19330
|
+
chainId: session.chainId,
|
|
19331
|
+
host: this.config.host
|
|
19332
|
+
};
|
|
19333
|
+
}
|
|
19334
|
+
/**
|
|
19335
|
+
* Issue a delegation via the legacy wallet-signed SIWE path for a single
|
|
19336
|
+
* {@link PermissionEntry}. Shares the implementation with the public
|
|
19337
|
+
* `createDelegation` method via {@link createDelegationWalletPath} so
|
|
19338
|
+
* both entry points hit exactly the same SIWE / signer / public-space
|
|
19339
|
+
* logic without mutual recursion.
|
|
19340
|
+
*
|
|
19341
|
+
* @internal
|
|
19342
|
+
*/
|
|
19343
|
+
async createDelegationLegacyWalletPath(delegateDID, entry, expirationTime) {
|
|
19344
|
+
const spaceIdOverride = entry.space === "default" ? void 0 : entry.space;
|
|
19345
|
+
return this.createDelegationWalletPath({
|
|
19346
|
+
path: entry.path,
|
|
19347
|
+
actions: entry.actions,
|
|
19348
|
+
delegateDID,
|
|
19349
|
+
includePublicSpace: true,
|
|
19350
|
+
expiryMs: Math.max(0, expirationTime.getTime() - Date.now()),
|
|
19351
|
+
spaceIdOverride
|
|
19352
|
+
});
|
|
19353
|
+
}
|
|
19080
19354
|
/**
|
|
19081
19355
|
* Create a delegation from this user to another user.
|
|
19082
19356
|
*
|
|
@@ -19087,6 +19361,51 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19087
19361
|
* @returns A portable delegation that can be sent to the recipient
|
|
19088
19362
|
*/
|
|
19089
19363
|
async createDelegation(params) {
|
|
19364
|
+
if (!this.signer) {
|
|
19365
|
+
throw new Error("Cannot createDelegation() in session-only mode. Requires wallet mode.");
|
|
19366
|
+
}
|
|
19367
|
+
if (!this.auth?.tinyCloudSession) {
|
|
19368
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
19369
|
+
}
|
|
19370
|
+
let resolvedDelegateDID = params.delegateDID;
|
|
19371
|
+
if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
19372
|
+
const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
|
|
19373
|
+
if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
|
|
19374
|
+
resolvedDelegateDID = `did:pkh:eip155:1:${address}`;
|
|
19375
|
+
}
|
|
19376
|
+
const entries = legacyParamsToPermissionEntries(
|
|
19377
|
+
params.actions,
|
|
19378
|
+
params.path,
|
|
19379
|
+
params.spaceIdOverride
|
|
19380
|
+
);
|
|
19381
|
+
if (entries.length === 1) {
|
|
19382
|
+
try {
|
|
19383
|
+
const result = await this.delegateTo(
|
|
19384
|
+
resolvedDelegateDID,
|
|
19385
|
+
[entries[0]],
|
|
19386
|
+
params.expiryMs !== void 0 ? { expiry: params.expiryMs } : void 0
|
|
19387
|
+
);
|
|
19388
|
+
return result.delegation;
|
|
19389
|
+
} catch (err) {
|
|
19390
|
+
if (err instanceof import_sdk_core4.PermissionNotInManifestError) {
|
|
19391
|
+
} else {
|
|
19392
|
+
throw err;
|
|
19393
|
+
}
|
|
19394
|
+
}
|
|
19395
|
+
}
|
|
19396
|
+
return this.createDelegationWalletPath({
|
|
19397
|
+
...params,
|
|
19398
|
+
delegateDID: resolvedDelegateDID
|
|
19399
|
+
});
|
|
19400
|
+
}
|
|
19401
|
+
/**
|
|
19402
|
+
* Legacy wallet-signed SIWE delegation path. Lifted from the original
|
|
19403
|
+
* `createDelegation` body verbatim so both the legacy public method and
|
|
19404
|
+
* `delegateTo({ forceWalletSign: true })` hit the same code.
|
|
19405
|
+
*
|
|
19406
|
+
* @internal
|
|
19407
|
+
*/
|
|
19408
|
+
async createDelegationWalletPath(params) {
|
|
19090
19409
|
if (!this.signer) {
|
|
19091
19410
|
throw new Error("Cannot createDelegation() in session-only mode. Requires wallet mode.");
|
|
19092
19411
|
}
|
|
@@ -19094,11 +19413,6 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19094
19413
|
if (!session) {
|
|
19095
19414
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19096
19415
|
}
|
|
19097
|
-
if (params.delegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
19098
|
-
const address = await this.config.ensResolver.resolveAddress(params.delegateDID);
|
|
19099
|
-
if (!address) throw new Error(`Could not resolve ENS name: ${params.delegateDID}`);
|
|
19100
|
-
params = { ...params, delegateDID: `did:pkh:eip155:1:${address}` };
|
|
19101
|
-
}
|
|
19102
19416
|
const abilities = {};
|
|
19103
19417
|
const kvActions = params.actions.filter((a) => a.startsWith("tinycloud.kv/"));
|
|
19104
19418
|
const sqlActions = params.actions.filter((a) => a.startsWith("tinycloud.sql/"));
|
|
@@ -19131,7 +19445,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19131
19445
|
...prepared,
|
|
19132
19446
|
signature: signature2
|
|
19133
19447
|
});
|
|
19134
|
-
const activateResult = await (0,
|
|
19448
|
+
const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
|
|
19135
19449
|
this.config.host,
|
|
19136
19450
|
delegationSession.delegationHeader
|
|
19137
19451
|
);
|
|
@@ -19153,7 +19467,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19153
19467
|
};
|
|
19154
19468
|
const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
|
|
19155
19469
|
if (hasKvActions && params.includePublicSpace !== false) {
|
|
19156
|
-
const publicSpaceId = (0,
|
|
19470
|
+
const publicSpaceId = (0, import_sdk_core4.makePublicSpaceId)(
|
|
19157
19471
|
this.wasmBindings.ensureEip55(session.address),
|
|
19158
19472
|
session.chainId
|
|
19159
19473
|
);
|
|
@@ -19176,7 +19490,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19176
19490
|
...publicPrepared,
|
|
19177
19491
|
signature: publicSignature
|
|
19178
19492
|
});
|
|
19179
|
-
const publicActivateResult = await (0,
|
|
19493
|
+
const publicActivateResult = await (0, import_sdk_core4.activateSessionWithHost)(
|
|
19180
19494
|
this.config.host,
|
|
19181
19495
|
publicSession.delegationHeader
|
|
19182
19496
|
);
|
|
@@ -19275,7 +19589,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19275
19589
|
...prepared,
|
|
19276
19590
|
signature: signature2
|
|
19277
19591
|
});
|
|
19278
|
-
const activateResult = await (0,
|
|
19592
|
+
const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
|
|
19279
19593
|
targetHost,
|
|
19280
19594
|
invokerSession.delegationHeader
|
|
19281
19595
|
);
|
|
@@ -19364,7 +19678,7 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19364
19678
|
...prepared,
|
|
19365
19679
|
signature: signature2
|
|
19366
19680
|
});
|
|
19367
|
-
const activateResult = await (0,
|
|
19681
|
+
const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
|
|
19368
19682
|
targetHost,
|
|
19369
19683
|
subDelegationSession.delegationHeader
|
|
19370
19684
|
);
|
|
@@ -19386,6 +19700,18 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19386
19700
|
};
|
|
19387
19701
|
}
|
|
19388
19702
|
};
|
|
19703
|
+
// ===========================================================================
|
|
19704
|
+
// Capability-chain delegation (spec: .claude/specs/capability-chain.md)
|
|
19705
|
+
// ===========================================================================
|
|
19706
|
+
/**
|
|
19707
|
+
* Safety margin before the session's own expiry at which {@link delegateTo}
|
|
19708
|
+
* will refuse to issue a derived delegation. Prevents issuing sub-delegations
|
|
19709
|
+
* that would be invalid by the time the recipient used them. Spec: 60 seconds.
|
|
19710
|
+
*
|
|
19711
|
+
* @internal
|
|
19712
|
+
*/
|
|
19713
|
+
_TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS = 6e4;
|
|
19714
|
+
var TinyCloudNode = _TinyCloudNode;
|
|
19389
19715
|
|
|
19390
19716
|
// src/nodeDefaults.ts
|
|
19391
19717
|
TinyCloudNode.registerNodeDefaults({
|
|
@@ -19394,11 +19720,11 @@ TinyCloudNode.registerNodeDefaults({
|
|
|
19394
19720
|
});
|
|
19395
19721
|
|
|
19396
19722
|
// src/index.ts
|
|
19397
|
-
var import_sdk_core5 = require("@tinycloud/sdk-core");
|
|
19398
19723
|
var import_sdk_core6 = require("@tinycloud/sdk-core");
|
|
19724
|
+
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
19399
19725
|
|
|
19400
19726
|
// src/storage/FileSessionStorage.ts
|
|
19401
|
-
var
|
|
19727
|
+
var import_sdk_core5 = require("@tinycloud/sdk-core");
|
|
19402
19728
|
var import_fs = require("fs");
|
|
19403
19729
|
var import_path = require("path");
|
|
19404
19730
|
var FileSessionStorage = class {
|
|
@@ -19453,7 +19779,7 @@ var FileSessionStorage = class {
|
|
|
19453
19779
|
try {
|
|
19454
19780
|
const data = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
19455
19781
|
const parsed = JSON.parse(data);
|
|
19456
|
-
const validation = (0,
|
|
19782
|
+
const validation = (0, import_sdk_core5.validatePersistedSessionData)(parsed);
|
|
19457
19783
|
if (!validation.ok) {
|
|
19458
19784
|
console.warn(`Invalid session data for ${address}:`, validation.error.message);
|
|
19459
19785
|
(0, import_fs.unlinkSync)(filePath);
|
|
@@ -19517,6 +19843,9 @@ var FileSessionStorage = class {
|
|
|
19517
19843
|
}
|
|
19518
19844
|
};
|
|
19519
19845
|
|
|
19846
|
+
// src/index.ts
|
|
19847
|
+
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
19848
|
+
|
|
19520
19849
|
// src/delegation.ts
|
|
19521
19850
|
function serializeDelegation(delegation) {
|
|
19522
19851
|
return JSON.stringify({
|
|
@@ -19534,8 +19863,6 @@ function deserializeDelegation(data) {
|
|
|
19534
19863
|
}
|
|
19535
19864
|
|
|
19536
19865
|
// src/index.ts
|
|
19537
|
-
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
19538
|
-
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
19539
19866
|
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
19540
19867
|
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
19541
19868
|
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
@@ -19543,6 +19870,9 @@ var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
|
19543
19870
|
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
19544
19871
|
var import_sdk_core14 = require("@tinycloud/sdk-core");
|
|
19545
19872
|
var import_sdk_core15 = require("@tinycloud/sdk-core");
|
|
19873
|
+
var import_sdk_core16 = require("@tinycloud/sdk-core");
|
|
19874
|
+
var import_sdk_core17 = require("@tinycloud/sdk-core");
|
|
19875
|
+
var import_sdk_core18 = require("@tinycloud/sdk-core");
|
|
19546
19876
|
// Annotate the CommonJS export names for ESM import in node:
|
|
19547
19877
|
0 && (module.exports = {
|
|
19548
19878
|
AutoApproveSpaceCreationHandler,
|
|
@@ -19557,16 +19887,20 @@ var import_sdk_core15 = require("@tinycloud/sdk-core");
|
|
|
19557
19887
|
DuckDbDatabaseHandle,
|
|
19558
19888
|
DuckDbService,
|
|
19559
19889
|
FileSessionStorage,
|
|
19890
|
+
HooksService,
|
|
19560
19891
|
KVService,
|
|
19892
|
+
ManifestValidationError,
|
|
19561
19893
|
MemorySessionStorage,
|
|
19562
19894
|
NodeUserAuthorization,
|
|
19563
19895
|
NodeWasmBindings,
|
|
19896
|
+
PermissionNotInManifestError,
|
|
19564
19897
|
PrefixedKVService,
|
|
19565
19898
|
PrivateKeySigner,
|
|
19566
19899
|
ProtocolMismatchError,
|
|
19567
19900
|
SQLAction,
|
|
19568
19901
|
SQLService,
|
|
19569
19902
|
ServiceContext,
|
|
19903
|
+
SessionExpiredError,
|
|
19570
19904
|
SharingService,
|
|
19571
19905
|
SilentNotificationHandler,
|
|
19572
19906
|
Space,
|
|
@@ -19589,9 +19923,15 @@ var import_sdk_core15 = require("@tinycloud/sdk-core");
|
|
|
19589
19923
|
defaultSignStrategy,
|
|
19590
19924
|
defaultSpaceCreationHandler,
|
|
19591
19925
|
deserializeDelegation,
|
|
19926
|
+
expandActionShortNames,
|
|
19927
|
+
isCapabilitySubset,
|
|
19928
|
+
loadManifest,
|
|
19592
19929
|
makePublicSpaceId,
|
|
19930
|
+
parseExpiry,
|
|
19593
19931
|
parseSpaceUri,
|
|
19594
|
-
|
|
19932
|
+
resolveManifest,
|
|
19933
|
+
serializeDelegation,
|
|
19934
|
+
validateManifest
|
|
19595
19935
|
});
|
|
19596
19936
|
/*! Bundled license information:
|
|
19597
19937
|
|