@tinycloud/node-sdk 2.2.0-beta.3 → 2.2.0-beta.5
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-NsTndW58.d.cts → core-DdMPUB5s.d.cts} +21 -3
- package/dist/{core-NsTndW58.d.ts → core-DdMPUB5s.d.ts} +21 -3
- package/dist/core.cjs +87 -14
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +89 -15
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +87 -14
- 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 +89 -15
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -17327,9 +17327,9 @@ var NodeUserAuthorization = class {
|
|
|
17327
17327
|
this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
|
|
17328
17328
|
this.autoCreateSpace = config.autoCreateSpace ?? false;
|
|
17329
17329
|
this.spaceCreationHandler = config.spaceCreationHandler;
|
|
17330
|
-
this.tinycloudHosts = config.tinycloudHosts
|
|
17331
|
-
|
|
17332
|
-
|
|
17330
|
+
this.tinycloudHosts = config.tinycloudHosts;
|
|
17331
|
+
this.tinycloudRegistryUrl = config.tinycloudRegistryUrl;
|
|
17332
|
+
this.tinycloudFallbackHosts = config.tinycloudFallbackHosts;
|
|
17333
17333
|
this.enablePublicSpace = config.enablePublicSpace ?? true;
|
|
17334
17334
|
this.nonce = config.nonce;
|
|
17335
17335
|
this.siweConfig = config.siweConfig;
|
|
@@ -17350,6 +17350,9 @@ var NodeUserAuthorization = class {
|
|
|
17350
17350
|
get capabilityRequest() {
|
|
17351
17351
|
return this.getCapabilityRequest();
|
|
17352
17352
|
}
|
|
17353
|
+
get hosts() {
|
|
17354
|
+
return this.tinycloudHosts ? [...this.tinycloudHosts] : [];
|
|
17355
|
+
}
|
|
17353
17356
|
/**
|
|
17354
17357
|
* Install or replace the stored manifest. Takes effect on the next
|
|
17355
17358
|
* `signIn()` call — the current session (if any) is not touched.
|
|
@@ -17374,6 +17377,26 @@ var NodeUserAuthorization = class {
|
|
|
17374
17377
|
get tinyCloudSession() {
|
|
17375
17378
|
return this._tinyCloudSession;
|
|
17376
17379
|
}
|
|
17380
|
+
async resolveTinyCloudHostsForSignIn(address, chainId) {
|
|
17381
|
+
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
17382
|
+
return;
|
|
17383
|
+
}
|
|
17384
|
+
const subject = `did:pkh:eip155:${chainId}:${address}`;
|
|
17385
|
+
const resolved = await (0, import_sdk_core.resolveTinyCloudHosts)(subject, {
|
|
17386
|
+
registryUrl: this.tinycloudRegistryUrl,
|
|
17387
|
+
fallbackHosts: this.tinycloudFallbackHosts
|
|
17388
|
+
});
|
|
17389
|
+
this.tinycloudHosts = resolved.hosts;
|
|
17390
|
+
}
|
|
17391
|
+
requireTinyCloudHosts() {
|
|
17392
|
+
if (!this.tinycloudHosts || this.tinycloudHosts.length === 0) {
|
|
17393
|
+
throw new Error("TinyCloud hosts have not been resolved. Call signIn() first.");
|
|
17394
|
+
}
|
|
17395
|
+
return this.tinycloudHosts;
|
|
17396
|
+
}
|
|
17397
|
+
get primaryTinyCloudHost() {
|
|
17398
|
+
return this.requireTinyCloudHosts()[0];
|
|
17399
|
+
}
|
|
17377
17400
|
get nodeFeatures() {
|
|
17378
17401
|
return this._nodeFeatures;
|
|
17379
17402
|
}
|
|
@@ -17505,7 +17528,7 @@ var NodeUserAuthorization = class {
|
|
|
17505
17528
|
if (!this._tinyCloudSession || !this._address || !this._chainId) {
|
|
17506
17529
|
throw new Error("Must be signed in to host space");
|
|
17507
17530
|
}
|
|
17508
|
-
const host = this.
|
|
17531
|
+
const host = this.primaryTinyCloudHost;
|
|
17509
17532
|
const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
|
|
17510
17533
|
const peerId = await (0, import_sdk_core.fetchPeerId)(host, spaceId);
|
|
17511
17534
|
const siwe = this.wasm.generateHostSIWEMessage({
|
|
@@ -17547,7 +17570,7 @@ var NodeUserAuthorization = class {
|
|
|
17547
17570
|
if (!this._tinyCloudSession) {
|
|
17548
17571
|
throw new Error("Must be signed in to ensure space exists");
|
|
17549
17572
|
}
|
|
17550
|
-
const host = this.
|
|
17573
|
+
const host = this.primaryTinyCloudHost;
|
|
17551
17574
|
const primarySpaceId = this._tinyCloudSession.spaceId;
|
|
17552
17575
|
const result = await (0, import_sdk_core.activateSessionWithHost)(
|
|
17553
17576
|
host,
|
|
@@ -17656,6 +17679,7 @@ var NodeUserAuthorization = class {
|
|
|
17656
17679
|
this._chainId = await this.signer.getChainId();
|
|
17657
17680
|
const address = this.wasm.ensureEip55(this._address);
|
|
17658
17681
|
const chainId = this._chainId;
|
|
17682
|
+
await this.resolveTinyCloudHostsForSignIn(address, chainId);
|
|
17659
17683
|
const keyId = `session-${Date.now()}`;
|
|
17660
17684
|
this.sessionManager.renameSessionKeyId("default", keyId);
|
|
17661
17685
|
const jwkString = this.sessionManager.jwk(keyId);
|
|
@@ -17734,7 +17758,7 @@ var NodeUserAuthorization = class {
|
|
|
17734
17758
|
this._address = address;
|
|
17735
17759
|
this._chainId = chainId;
|
|
17736
17760
|
const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
|
|
17737
|
-
this.
|
|
17761
|
+
this.primaryTinyCloudHost,
|
|
17738
17762
|
this.wasm.protocolVersion()
|
|
17739
17763
|
);
|
|
17740
17764
|
this._nodeFeatures = nodeInfo.features;
|
|
@@ -17850,6 +17874,7 @@ var NodeUserAuthorization = class {
|
|
|
17850
17874
|
});
|
|
17851
17875
|
const address = this.wasm.ensureEip55(await this.signer.getAddress());
|
|
17852
17876
|
const chainId = await this.signer.getChainId();
|
|
17877
|
+
await this.resolveTinyCloudHostsForSignIn(address, chainId);
|
|
17853
17878
|
const clientSession = {
|
|
17854
17879
|
address,
|
|
17855
17880
|
walletAddress: address,
|
|
@@ -17899,7 +17924,7 @@ var NodeUserAuthorization = class {
|
|
|
17899
17924
|
this._address = address;
|
|
17900
17925
|
this._chainId = chainId;
|
|
17901
17926
|
const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
|
|
17902
|
-
this.
|
|
17927
|
+
this.primaryTinyCloudHost,
|
|
17903
17928
|
this.wasm.protocolVersion()
|
|
17904
17929
|
);
|
|
17905
17930
|
this._nodeFeatures = nodeInfo.features;
|
|
@@ -18243,6 +18268,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18243
18268
|
this.auth = null;
|
|
18244
18269
|
this.tc = null;
|
|
18245
18270
|
this._chainId = 1;
|
|
18271
|
+
this.explicitHost = config.host;
|
|
18246
18272
|
this.config = {
|
|
18247
18273
|
...config,
|
|
18248
18274
|
host: config.host ?? DEFAULT_HOST
|
|
@@ -18324,7 +18350,6 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18324
18350
|
* @internal
|
|
18325
18351
|
*/
|
|
18326
18352
|
setupAuth(config) {
|
|
18327
|
-
const host = this.config.host;
|
|
18328
18353
|
this.auth = new NodeUserAuthorization({
|
|
18329
18354
|
signer: this.signer,
|
|
18330
18355
|
signStrategy: { type: "auto-sign" },
|
|
@@ -18333,7 +18358,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18333
18358
|
domain: this.siweDomain,
|
|
18334
18359
|
spacePrefix: config.prefix,
|
|
18335
18360
|
sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
|
|
18336
|
-
tinycloudHosts: [
|
|
18361
|
+
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
18362
|
+
tinycloudRegistryUrl: config.tinycloudRegistryUrl,
|
|
18363
|
+
tinycloudFallbackHosts: config.tinycloudFallbackHosts,
|
|
18337
18364
|
autoCreateSpace: config.autoCreateSpace,
|
|
18338
18365
|
enablePublicSpace: config.enablePublicSpace ?? true,
|
|
18339
18366
|
spaceCreationHandler: config.spaceCreationHandler,
|
|
@@ -18347,6 +18374,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18347
18374
|
invokeAny: this.wasmBindings.invokeAny
|
|
18348
18375
|
});
|
|
18349
18376
|
}
|
|
18377
|
+
syncResolvedHostFromAuth() {
|
|
18378
|
+
const host = this.auth?.hosts[0];
|
|
18379
|
+
if (host) {
|
|
18380
|
+
this.config.host = host;
|
|
18381
|
+
}
|
|
18382
|
+
}
|
|
18350
18383
|
/**
|
|
18351
18384
|
* Install or replace the manifest that drives the SIWE recap at
|
|
18352
18385
|
* sign-in. Takes effect on the next `signIn()` call — the current
|
|
@@ -18384,6 +18417,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18384
18417
|
get capabilityRequest() {
|
|
18385
18418
|
return this.auth?.capabilityRequest;
|
|
18386
18419
|
}
|
|
18420
|
+
get hosts() {
|
|
18421
|
+
const authHosts = this.auth?.hosts ?? [];
|
|
18422
|
+
return authHosts.length > 0 ? authHosts : [this.config.host];
|
|
18423
|
+
}
|
|
18387
18424
|
/**
|
|
18388
18425
|
* Get the primary identity DID for this user.
|
|
18389
18426
|
* - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
|
|
@@ -18456,6 +18493,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18456
18493
|
this._hooks = void 0;
|
|
18457
18494
|
this._serviceContext = void 0;
|
|
18458
18495
|
await this.tc.signIn(options);
|
|
18496
|
+
this.syncResolvedHostFromAuth();
|
|
18459
18497
|
this.initializeServices();
|
|
18460
18498
|
await this.writeManifestRegistryRecords();
|
|
18461
18499
|
this.notificationHandler.success("Successfully signed in");
|
|
@@ -18475,7 +18513,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18475
18513
|
throw new Error("Manifest registry write requires wallet mode");
|
|
18476
18514
|
}
|
|
18477
18515
|
const accountSpaceId = this.ownedSpaceId(import_sdk_core4.ACCOUNT_REGISTRY_SPACE);
|
|
18478
|
-
await this.
|
|
18516
|
+
await this.ensureOwnedSpaceHosted(accountSpaceId);
|
|
18479
18517
|
const accountKV = this.spaces.get(accountSpaceId).kv;
|
|
18480
18518
|
for (const record of request.registryRecords) {
|
|
18481
18519
|
const result = await accountKV.put(record.key, {
|
|
@@ -18490,6 +18528,39 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18490
18528
|
}
|
|
18491
18529
|
}
|
|
18492
18530
|
}
|
|
18531
|
+
async ensureOwnedSpaceHosted(spaceId) {
|
|
18532
|
+
if (!this.auth) {
|
|
18533
|
+
throw new Error("Owned space hosting requires wallet mode");
|
|
18534
|
+
}
|
|
18535
|
+
const session = this.auth.tinyCloudSession;
|
|
18536
|
+
if (!session) {
|
|
18537
|
+
throw new Error("Owned space hosting requires an active session");
|
|
18538
|
+
}
|
|
18539
|
+
const host = this.hosts[0] ?? this.config.host;
|
|
18540
|
+
if (!host) {
|
|
18541
|
+
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
18542
|
+
}
|
|
18543
|
+
const activation = await (0, import_sdk_core4.activateSessionWithHost)(host, session.delegationHeader);
|
|
18544
|
+
if (activation.success && !activation.skipped?.includes(spaceId)) {
|
|
18545
|
+
return;
|
|
18546
|
+
}
|
|
18547
|
+
if (!activation.success && activation.status !== 404) {
|
|
18548
|
+
throw new Error(
|
|
18549
|
+
`Failed to check owned space ${spaceId}: ${activation.error ?? activation.status}`
|
|
18550
|
+
);
|
|
18551
|
+
}
|
|
18552
|
+
const created = await this.auth.hostOwnedSpace(spaceId);
|
|
18553
|
+
if (!created) {
|
|
18554
|
+
throw new Error(`Failed to create owned space: ${spaceId}`);
|
|
18555
|
+
}
|
|
18556
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
18557
|
+
const retry = await (0, import_sdk_core4.activateSessionWithHost)(host, session.delegationHeader);
|
|
18558
|
+
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
18559
|
+
throw new Error(
|
|
18560
|
+
`Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
|
|
18561
|
+
);
|
|
18562
|
+
}
|
|
18563
|
+
}
|
|
18493
18564
|
/**
|
|
18494
18565
|
* Restore a previously established session from stored delegation data.
|
|
18495
18566
|
*
|
|
@@ -18607,7 +18678,6 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18607
18678
|
throw new Error("Wallet already connected. Cannot connect another wallet.");
|
|
18608
18679
|
}
|
|
18609
18680
|
const prefix = options?.prefix ?? "default";
|
|
18610
|
-
const host = this.config.host;
|
|
18611
18681
|
if (!_TinyCloudNode.nodeDefaults) {
|
|
18612
18682
|
throw new Error(
|
|
18613
18683
|
"connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
|
|
@@ -18622,7 +18692,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18622
18692
|
domain: this.siweDomain,
|
|
18623
18693
|
spacePrefix: prefix,
|
|
18624
18694
|
sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
|
|
18625
|
-
tinycloudHosts: [
|
|
18695
|
+
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
18696
|
+
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
18697
|
+
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
18626
18698
|
autoCreateSpace: this.config.autoCreateSpace,
|
|
18627
18699
|
enablePublicSpace: this.config.enablePublicSpace ?? true,
|
|
18628
18700
|
spaceCreationHandler: this.config.spaceCreationHandler,
|
|
@@ -18655,7 +18727,6 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18655
18727
|
throw new Error("Signer already connected. Cannot connect another signer.");
|
|
18656
18728
|
}
|
|
18657
18729
|
const prefix = options?.prefix ?? "default";
|
|
18658
|
-
const host = this.config.host;
|
|
18659
18730
|
this.signer = signer;
|
|
18660
18731
|
this.auth = new NodeUserAuthorization({
|
|
18661
18732
|
signer: this.signer,
|
|
@@ -18665,7 +18736,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18665
18736
|
domain: this.siweDomain,
|
|
18666
18737
|
spacePrefix: prefix,
|
|
18667
18738
|
sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
|
|
18668
|
-
tinycloudHosts: [
|
|
18739
|
+
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
18740
|
+
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
18741
|
+
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
18669
18742
|
autoCreateSpace: this.config.autoCreateSpace,
|
|
18670
18743
|
enablePublicSpace: this.config.enablePublicSpace ?? true,
|
|
18671
18744
|
spaceCreationHandler: this.config.spaceCreationHandler,
|