@tinycloud/node-sdk 3.11.1-beta.0 → 3.12.0-beta.2
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/NodeUserAuthorization-B05Wjjpb.d.cts +900 -0
- package/dist/NodeUserAuthorization-B05Wjjpb.d.ts +900 -0
- package/dist/{TinyCloudNode-AUotFGzy.d.ts → TinyCloudNode-6_IumWu0.d.cts} +32 -875
- package/dist/{TinyCloudNode-BmpjkpWR.d.cts → TinyCloudNode-CEFGtSWn.d.ts} +32 -875
- package/dist/{authority-BYSEyjDI.d.cts → authority-DODDXxoP.d.cts} +1 -1
- package/dist/{authority-dRnJD4iL.d.ts → authority-DXpnuId1.d.ts} +1 -1
- package/dist/core.cjs +182 -109
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +5 -4
- package/dist/core.d.ts +5 -4
- package/dist/core.js +182 -109
- package/dist/core.js.map +1 -1
- package/dist/credentials-core.d.cts +1 -1
- package/dist/credentials-core.d.ts +1 -1
- package/dist/credentials.d.cts +1 -1
- package/dist/credentials.d.ts +1 -1
- package/dist/{delegation-Ckc3UETl.d.cts → delegation-BQbAuKad.d.cts} +1 -1
- package/dist/{delegation-Ckc3UETl.d.ts → delegation-BQbAuKad.d.ts} +1 -1
- package/dist/encryption-keys.d.cts +3 -2
- package/dist/encryption-keys.d.ts +3 -2
- package/dist/index.cjs +182 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +182 -109
- package/dist/index.js.map +1 -1
- package/dist/replication/authority.d.cts +4 -3
- package/dist/replication/authority.d.ts +4 -3
- package/dist/space-hosting.cjs +183 -0
- package/dist/space-hosting.cjs.map +1 -0
- package/dist/space-hosting.d.cts +84 -0
- package/dist/space-hosting.d.ts +84 -0
- package/dist/space-hosting.js +157 -0
- package/dist/space-hosting.js.map +1 -0
- package/package.json +11 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CredentialFlowDescriptor, CredentialRequirement, CredentialHolderBinding, IssuedCredentialEnvelope, CredentialIssuerMetadata, ClientSession, IKVService, StoredCredentialRecord, VerifiedCredential, CredentialProgressEvent, CredentialStorageReceipt, UnifiedPolicyV2, UnifiedPolicyCapability, PolicyCredentialAdmissionV3 } from '@tinycloud/sdk-core';
|
|
2
|
-
import { V as ValidatedRuntimeDelegation } from './delegation-
|
|
2
|
+
import { V as ValidatedRuntimeDelegation } from './delegation-BQbAuKad.cjs';
|
|
3
3
|
|
|
4
4
|
interface CredentialClient {
|
|
5
5
|
readonly sessionDid: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CredentialFlowDescriptor, CredentialRequirement, CredentialHolderBinding, IssuedCredentialEnvelope, CredentialIssuerMetadata, ClientSession, IKVService, StoredCredentialRecord, VerifiedCredential, CredentialProgressEvent, CredentialStorageReceipt, UnifiedPolicyV2, UnifiedPolicyCapability, PolicyCredentialAdmissionV3 } from '@tinycloud/sdk-core';
|
|
2
|
-
import { V as ValidatedRuntimeDelegation } from './delegation-
|
|
2
|
+
import { V as ValidatedRuntimeDelegation } from './delegation-BQbAuKad.js';
|
|
3
3
|
|
|
4
4
|
interface CredentialClient {
|
|
5
5
|
readonly sessionDid: string;
|
package/dist/credentials.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CredentialAcquisitionTheme, CredentialAcquisitionTransport, CredentialBrowserInteractionAdapter, CredentialClient, CredentialInlineInteractionAdapter, CredentialInputRequest, CredentialInteractionAdapter, CredentialInteractionKind, CredentialInteractionSurface, CredentialProofSubject, CredentialRedirectResumeState, CredentialRedirectStore, CredentialRequestState, CredentialSigningAdapter, CredentialsAcquireOptions, CredentialsEnsureOptions, CredentialsEnsureResult, CredentialsOperationOptions, CredentialsPolicyAdmissionOptions, CredentialsPolicyAdmissionResult, HolderSignatureKey, InlineCredentialProofHandler, InlineCredentialProofRequest, OpenCredentialsHttpTransport, PrimitiveStepHandler, PrimitiveStepResult, ReceiverCredentialCustody, interpretCredentialFlow, mailboxSubject } from './credentials-core.cjs';
|
|
2
2
|
export { D as DEFAULT_EMAIL_PROOF_PROFILE, b as EMAIL_PROOF_CREDENTIAL_TYPE, c as EMAIL_PROOF_PENDING_MAX_MS, d as EmailProofAcquireInput, e as EmailProofAcquisition, f as EmailProofError, g as EmailProofErrorCode, h as EmailProofOptions, a as EmailProofPending, E as EmailProofPendingStore, i as EmailProofProfileId, j as EmailProofRequestInput, k as EmailProofResult, l as EmailProofStep, H as HolderAlgorithm, m as HolderSigner, S as StoredEmailProofInput, n as StoredEmailProofRecord, o as acquireEmailProof, p as completeEmailProof, q as createEd25519HolderSigner, r as createMemoryEmailProofPendingStore, s as emailProofRequirement, t as isTicketEmailProofResult, u as requestEmailProofCode, v as verifyStoredEmailProof } from './email-proof-B4DRizIL.cjs';
|
|
3
3
|
import '@tinycloud/sdk-core';
|
|
4
|
-
import './delegation-
|
|
4
|
+
import './delegation-BQbAuKad.cjs';
|
|
5
5
|
import '@tinycloud/sdk-core/held-credentials';
|
|
6
6
|
|
|
7
7
|
/** Production pins. Credentials verify only against these values. Tests pin them literally. */
|
package/dist/credentials.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CredentialAcquisitionTheme, CredentialAcquisitionTransport, CredentialBrowserInteractionAdapter, CredentialClient, CredentialInlineInteractionAdapter, CredentialInputRequest, CredentialInteractionAdapter, CredentialInteractionKind, CredentialInteractionSurface, CredentialProofSubject, CredentialRedirectResumeState, CredentialRedirectStore, CredentialRequestState, CredentialSigningAdapter, CredentialsAcquireOptions, CredentialsEnsureOptions, CredentialsEnsureResult, CredentialsOperationOptions, CredentialsPolicyAdmissionOptions, CredentialsPolicyAdmissionResult, HolderSignatureKey, InlineCredentialProofHandler, InlineCredentialProofRequest, OpenCredentialsHttpTransport, PrimitiveStepHandler, PrimitiveStepResult, ReceiverCredentialCustody, interpretCredentialFlow, mailboxSubject } from './credentials-core.js';
|
|
2
2
|
export { D as DEFAULT_EMAIL_PROOF_PROFILE, b as EMAIL_PROOF_CREDENTIAL_TYPE, c as EMAIL_PROOF_PENDING_MAX_MS, d as EmailProofAcquireInput, e as EmailProofAcquisition, f as EmailProofError, g as EmailProofErrorCode, h as EmailProofOptions, a as EmailProofPending, E as EmailProofPendingStore, i as EmailProofProfileId, j as EmailProofRequestInput, k as EmailProofResult, l as EmailProofStep, H as HolderAlgorithm, m as HolderSigner, S as StoredEmailProofInput, n as StoredEmailProofRecord, o as acquireEmailProof, p as completeEmailProof, q as createEd25519HolderSigner, r as createMemoryEmailProofPendingStore, s as emailProofRequirement, t as isTicketEmailProofResult, u as requestEmailProofCode, v as verifyStoredEmailProof } from './email-proof-B4DRizIL.js';
|
|
3
3
|
import '@tinycloud/sdk-core';
|
|
4
|
-
import './delegation-
|
|
4
|
+
import './delegation-BQbAuKad.js';
|
|
5
5
|
import '@tinycloud/sdk-core/held-credentials';
|
|
6
6
|
|
|
7
7
|
/** Production pins. Credentials verify only against these values. Tests pin them literally. */
|
|
@@ -248,4 +248,4 @@ declare function serializeDelegation(delegation: PortableDelegation): string;
|
|
|
248
248
|
*/
|
|
249
249
|
declare function deserializeDelegation(data: string): PortableDelegation;
|
|
250
250
|
|
|
251
|
-
export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type
|
|
251
|
+
export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type VerifiedSessionGrant as e, type AuthRequestArtifact as f, RUNTIME_DELEGATION_REJECTIONS as g, type RuntimeDelegationActivator as h, grantAuthRequest as i, signedCompactUcanExpiry as j, siweRuntimeDelegation as k, serializeDelegation as s };
|
|
@@ -248,4 +248,4 @@ declare function serializeDelegation(delegation: PortableDelegation): string;
|
|
|
248
248
|
*/
|
|
249
249
|
declare function deserializeDelegation(data: string): PortableDelegation;
|
|
250
250
|
|
|
251
|
-
export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type
|
|
251
|
+
export { type AuthDelegationArtifact as A, type CompactRuntimeDelegationInput as C, type DelegationAuthority as D, type PortableDelegation as P, RuntimeDelegationRejectedError as R, type SessionGrantProof as S, type ValidatedRuntimeDelegation as V, type RuntimeDelegationRejection as a, activateCompactRuntimeDelegation as b, activateValidatedRuntimeDelegation as c, deserializeDelegation as d, type VerifiedSessionGrant as e, type AuthRequestArtifact as f, RUNTIME_DELEGATION_REJECTIONS as g, type RuntimeDelegationActivator as h, grantAuthRequest as i, signedCompactUcanExpiry as j, siweRuntimeDelegation as k, serializeDelegation as s };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { NamedKeyClient } from '@tinycloud/sdk-services/encryption/named-keys';
|
|
2
2
|
export { DecryptManyResult, KeyCallOptions, KeyDescriptor, KeyEncryptOptions, NamedKeyClient, NamedKeyEnvelope, NamedKeyError, NamedKeyErrorCode, PublicKeyDescriptor, buildKeyAdminFacts, buildKeyDescribeFacts } from '@tinycloud/sdk-services/encryption/named-keys';
|
|
3
|
-
import { T as TinyCloudNode } from './TinyCloudNode-
|
|
3
|
+
import { T as TinyCloudNode } from './TinyCloudNode-6_IumWu0.cjs';
|
|
4
4
|
import '@tinycloud/sdk-core';
|
|
5
5
|
import '@tinycloud/sdk-services/kv/replication';
|
|
6
6
|
import '@tinycloud/sdk-services';
|
|
7
|
+
import './NodeUserAuthorization-B05Wjjpb.cjs';
|
|
7
8
|
import 'events';
|
|
8
|
-
import './delegation-
|
|
9
|
+
import './delegation-BQbAuKad.cjs';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Named encryption keys for a signed-in {@link TinyCloudNode}.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { NamedKeyClient } from '@tinycloud/sdk-services/encryption/named-keys';
|
|
2
2
|
export { DecryptManyResult, KeyCallOptions, KeyDescriptor, KeyEncryptOptions, NamedKeyClient, NamedKeyEnvelope, NamedKeyError, NamedKeyErrorCode, PublicKeyDescriptor, buildKeyAdminFacts, buildKeyDescribeFacts } from '@tinycloud/sdk-services/encryption/named-keys';
|
|
3
|
-
import { T as TinyCloudNode } from './TinyCloudNode-
|
|
3
|
+
import { T as TinyCloudNode } from './TinyCloudNode-CEFGtSWn.js';
|
|
4
4
|
import '@tinycloud/sdk-core';
|
|
5
5
|
import '@tinycloud/sdk-services/kv/replication';
|
|
6
6
|
import '@tinycloud/sdk-services';
|
|
7
|
+
import './NodeUserAuthorization-B05Wjjpb.js';
|
|
7
8
|
import 'events';
|
|
8
|
-
import './delegation-
|
|
9
|
+
import './delegation-BQbAuKad.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Named encryption keys for a signed-in {@link TinyCloudNode}.
|
package/dist/index.cjs
CHANGED
|
@@ -19073,6 +19073,8 @@ var NodeUserAuthorization = class {
|
|
|
19073
19073
|
* delegation lists them: the node answers a repeat with empty lists.
|
|
19074
19074
|
*/
|
|
19075
19075
|
this._lastActivationActivatedSpaceIds = [];
|
|
19076
|
+
/** See {@link spaceHosting}. Written only from node answers. */
|
|
19077
|
+
this._spaceHosting = "unknown";
|
|
19076
19078
|
this.wasm = config.wasmBindings;
|
|
19077
19079
|
this.signer = config.signer;
|
|
19078
19080
|
this.signStrategy = config.signStrategy ?? defaultSignStrategy;
|
|
@@ -19232,6 +19234,7 @@ var NodeUserAuthorization = class {
|
|
|
19232
19234
|
this.registryVerdict = void 0;
|
|
19233
19235
|
this._lastActivationSkippedSpaceIds = [];
|
|
19234
19236
|
this._lastActivationActivatedSpaceIds = [];
|
|
19237
|
+
this._spaceHosting = "unknown";
|
|
19235
19238
|
if (!session) {
|
|
19236
19239
|
this._session = void 0;
|
|
19237
19240
|
this._tinyCloudSession = void 0;
|
|
@@ -19372,6 +19375,18 @@ var NodeUserAuthorization = class {
|
|
|
19372
19375
|
get lastActivationActivatedSpaceIds() {
|
|
19373
19376
|
return [...this._lastActivationActivatedSpaceIds];
|
|
19374
19377
|
}
|
|
19378
|
+
/**
|
|
19379
|
+
* The node's last answer for whether this session's primary space is hosted:
|
|
19380
|
+
* recorded from the sign-in activation, or by {@link noteSpaceHosting}.
|
|
19381
|
+
* `unknown` until one of them answers, and after a restore.
|
|
19382
|
+
*/
|
|
19383
|
+
get spaceHosting() {
|
|
19384
|
+
return this._spaceHosting;
|
|
19385
|
+
}
|
|
19386
|
+
/** @internal Record the hosting probe's answer for the primary space. */
|
|
19387
|
+
noteSpaceHosting(hosting) {
|
|
19388
|
+
this._spaceHosting = hosting;
|
|
19389
|
+
}
|
|
19375
19390
|
/**
|
|
19376
19391
|
* Compute the `abilities` map the WASM `prepareSession` call should
|
|
19377
19392
|
* see at sign-in time.
|
|
@@ -19751,23 +19766,35 @@ var NodeUserAuthorization = class {
|
|
|
19751
19766
|
* Create the space on the TinyCloud server (host delegation).
|
|
19752
19767
|
* This registers the user as the owner of the space.
|
|
19753
19768
|
*/
|
|
19754
|
-
async hostSpace(targetSpaceId, purpose, signal) {
|
|
19755
|
-
|
|
19769
|
+
async hostSpace(targetSpaceId, purpose, signal, assertCurrent, siweParameters) {
|
|
19770
|
+
const context = typeof targetSpaceId === "object" ? targetSpaceId : void 0;
|
|
19771
|
+
const address = context?.address ?? this._address;
|
|
19772
|
+
const chainId = context?.chainId ?? this._chainId;
|
|
19773
|
+
if (!address || chainId === void 0 || !this._tinyCloudSession) {
|
|
19756
19774
|
throw new Error("Must be signed in to host space");
|
|
19757
19775
|
}
|
|
19776
|
+
const checkCurrent = () => {
|
|
19777
|
+
signal?.throwIfAborted();
|
|
19778
|
+
assertCurrent?.();
|
|
19779
|
+
};
|
|
19780
|
+
checkCurrent();
|
|
19758
19781
|
await this.ensureTinyCloudHosts();
|
|
19759
|
-
|
|
19760
|
-
const
|
|
19782
|
+
checkCurrent();
|
|
19783
|
+
const host = context?.host ?? this.primaryTinyCloudHost;
|
|
19784
|
+
const spaceId = context?.spaceId ?? (typeof targetSpaceId === "string" ? targetSpaceId : this._tinyCloudSession.spaceId);
|
|
19761
19785
|
const peerId = await (0, import_sdk_core5.fetchPeerId)(host, spaceId, signal);
|
|
19762
|
-
|
|
19763
|
-
|
|
19764
|
-
|
|
19765
|
-
|
|
19766
|
-
|
|
19767
|
-
|
|
19768
|
-
|
|
19769
|
-
|
|
19770
|
-
|
|
19786
|
+
checkCurrent();
|
|
19787
|
+
const siwe = this.wasm.generateHostSIWEMessage(
|
|
19788
|
+
context && siweParameters ? siweParameters(peerId) : {
|
|
19789
|
+
address,
|
|
19790
|
+
chainId,
|
|
19791
|
+
domain: this.domain,
|
|
19792
|
+
issuedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19793
|
+
spaceId,
|
|
19794
|
+
peerId
|
|
19795
|
+
}
|
|
19796
|
+
);
|
|
19797
|
+
checkCurrent();
|
|
19771
19798
|
const signing = this.signMessage(siwe, purpose);
|
|
19772
19799
|
let signature2;
|
|
19773
19800
|
if (!signal) {
|
|
@@ -19786,8 +19813,9 @@ var NodeUserAuthorization = class {
|
|
|
19786
19813
|
signal.removeEventListener("abort", onAbort);
|
|
19787
19814
|
}
|
|
19788
19815
|
}
|
|
19789
|
-
|
|
19816
|
+
checkCurrent();
|
|
19790
19817
|
const headers = this.wasm.siweToDelegationHeaders({ siwe, signature: signature2 });
|
|
19818
|
+
checkCurrent();
|
|
19791
19819
|
return (0, import_sdk_core5.submitHostDelegation)(host, headers, signal);
|
|
19792
19820
|
}
|
|
19793
19821
|
/**
|
|
@@ -19832,103 +19860,48 @@ var NodeUserAuthorization = class {
|
|
|
19832
19860
|
this._tinyCloudSession.delegationHeader
|
|
19833
19861
|
);
|
|
19834
19862
|
this.recordActivationSkippedSpaces(result, primarySpaceId);
|
|
19835
|
-
|
|
19836
|
-
|
|
19837
|
-
|
|
19838
|
-
|
|
19839
|
-
chainId: this._chainId,
|
|
19840
|
-
host
|
|
19841
|
-
};
|
|
19842
|
-
if (result.success) {
|
|
19843
|
-
const primarySkipped = result.skipped?.includes(primarySpaceId);
|
|
19844
|
-
if (!primarySkipped) {
|
|
19845
|
-
return;
|
|
19846
|
-
}
|
|
19847
|
-
if (!handler) {
|
|
19848
|
-
return;
|
|
19849
|
-
}
|
|
19850
|
-
await this.guardSpaceCreation(handler, creationContext);
|
|
19851
|
-
const confirmed = await handler.confirmSpaceCreation(creationContext);
|
|
19852
|
-
if (!confirmed) {
|
|
19853
|
-
return;
|
|
19854
|
-
}
|
|
19855
|
-
try {
|
|
19856
|
-
const created = await this.hostSpace();
|
|
19857
|
-
if (!created.success) {
|
|
19858
|
-
const err2 = Object.assign(
|
|
19859
|
-
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
19860
|
-
{ cause: created }
|
|
19861
|
-
);
|
|
19862
|
-
throw err2;
|
|
19863
|
-
}
|
|
19864
|
-
} catch (error) {
|
|
19865
|
-
handler.onSpaceCreationFailed?.(
|
|
19866
|
-
creationContext,
|
|
19867
|
-
error instanceof Error ? error : new Error(String(error))
|
|
19868
|
-
);
|
|
19869
|
-
throw error;
|
|
19870
|
-
}
|
|
19871
|
-
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
19872
|
-
const retryResult = await (0, import_sdk_core5.activateSessionWithHost)(
|
|
19873
|
-
host,
|
|
19874
|
-
this._tinyCloudSession.delegationHeader
|
|
19875
|
-
);
|
|
19876
|
-
if (!retryResult.success) {
|
|
19877
|
-
const err2 = Object.assign(
|
|
19878
|
-
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
19879
|
-
{ cause: retryResult }
|
|
19880
|
-
);
|
|
19881
|
-
handler.onSpaceCreationFailed?.(creationContext, err2);
|
|
19882
|
-
throw err2;
|
|
19883
|
-
}
|
|
19884
|
-
handler.onSpaceCreated?.(creationContext);
|
|
19885
|
-
return;
|
|
19886
|
-
}
|
|
19887
|
-
if (result.status === 404) {
|
|
19888
|
-
if (!handler) {
|
|
19889
|
-
return;
|
|
19890
|
-
}
|
|
19891
|
-
await this.guardSpaceCreation(handler, creationContext);
|
|
19892
|
-
const confirmed = await handler.confirmSpaceCreation(creationContext);
|
|
19893
|
-
if (!confirmed) {
|
|
19894
|
-
return;
|
|
19895
|
-
}
|
|
19896
|
-
try {
|
|
19897
|
-
const created = await this.hostSpace();
|
|
19898
|
-
if (!created.success) {
|
|
19899
|
-
const err2 = Object.assign(
|
|
19900
|
-
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
19901
|
-
{ cause: created }
|
|
19902
|
-
);
|
|
19903
|
-
throw err2;
|
|
19904
|
-
}
|
|
19905
|
-
} catch (error) {
|
|
19906
|
-
handler.onSpaceCreationFailed?.(
|
|
19907
|
-
creationContext,
|
|
19908
|
-
error instanceof Error ? error : new Error(String(error))
|
|
19909
|
-
);
|
|
19910
|
-
throw error;
|
|
19911
|
-
}
|
|
19912
|
-
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
19913
|
-
const retryResult = await (0, import_sdk_core5.activateSessionWithHost)(
|
|
19914
|
-
host,
|
|
19915
|
-
this._tinyCloudSession.delegationHeader
|
|
19863
|
+
if (!result.success && result.status !== 404) {
|
|
19864
|
+
throw Object.assign(
|
|
19865
|
+
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
19866
|
+
{ cause: result }
|
|
19916
19867
|
);
|
|
19917
|
-
if (!retryResult.success) {
|
|
19918
|
-
const err2 = Object.assign(
|
|
19919
|
-
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
19920
|
-
{ cause: retryResult }
|
|
19921
|
-
);
|
|
19922
|
-
handler.onSpaceCreationFailed?.(creationContext, err2);
|
|
19923
|
-
throw err2;
|
|
19924
|
-
}
|
|
19925
|
-
handler.onSpaceCreated?.(creationContext);
|
|
19926
|
-
return;
|
|
19927
19868
|
}
|
|
19928
|
-
|
|
19929
|
-
|
|
19930
|
-
|
|
19931
|
-
|
|
19869
|
+
await this.ensurePrimarySpaceHosted(this._spaceHosting);
|
|
19870
|
+
}
|
|
19871
|
+
/**
|
|
19872
|
+
* The create step of {@link ensureSpaceExists}: given the node's answer for
|
|
19873
|
+
* the primary space, host it through the space creation handler when it is
|
|
19874
|
+
* `not-hosted`. Any other answer, and a missing handler, change nothing. The
|
|
19875
|
+
* caller supplies the answer (sign-in's activation, or the hosting probe);
|
|
19876
|
+
* an empty activation list is never one.
|
|
19877
|
+
*
|
|
19878
|
+
* @throws Error if the creation handler fails or times out, or hosting fails
|
|
19879
|
+
*/
|
|
19880
|
+
async ensurePrimarySpaceHosted(hosting, signal) {
|
|
19881
|
+
const session = this._tinyCloudSession;
|
|
19882
|
+
if (hosting !== "not-hosted") return;
|
|
19883
|
+
if (!session) throw new Error("Must be signed in to host the primary space");
|
|
19884
|
+
const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core5.AutoApproveSpaceCreationHandler() : void 0);
|
|
19885
|
+
if (!handler) return;
|
|
19886
|
+
const { createPrimarySpace } = await import("./space-hosting.cjs");
|
|
19887
|
+
await createPrimarySpace({
|
|
19888
|
+
handler,
|
|
19889
|
+
session,
|
|
19890
|
+
currentSession: () => this._tinyCloudSession,
|
|
19891
|
+
signerAddress: () => this.signer.getAddress(),
|
|
19892
|
+
resolveHost: async () => {
|
|
19893
|
+
await this.ensureTinyCloudHosts();
|
|
19894
|
+
return this.primaryTinyCloudHost;
|
|
19895
|
+
},
|
|
19896
|
+
domain: this.domain,
|
|
19897
|
+
guard: (context) => this.guardSpaceCreation(handler, context),
|
|
19898
|
+
host: (context, assertCurrent, siweParameters) => this.hostSpace(context, void 0, signal, assertCurrent, siweParameters),
|
|
19899
|
+
onHosted: () => {
|
|
19900
|
+
this._spaceHosting = "hosted";
|
|
19901
|
+
},
|
|
19902
|
+
activate: (context) => (0, import_sdk_core5.activateSessionWithHost)(context.host, session.delegationHeader),
|
|
19903
|
+
signal
|
|
19904
|
+
});
|
|
19932
19905
|
}
|
|
19933
19906
|
/** {@link assertMayCreateSpace}, reporting a refusal to the creation handler before rethrowing it. */
|
|
19934
19907
|
async guardSpaceCreation(handler, context) {
|
|
@@ -19944,10 +19917,12 @@ var NodeUserAuthorization = class {
|
|
|
19944
19917
|
if (result.success) {
|
|
19945
19918
|
this._lastActivationSkippedSpaceIds = result.skipped ?? [];
|
|
19946
19919
|
this._lastActivationActivatedSpaceIds = result.activated ?? [];
|
|
19920
|
+
this._spaceHosting = this._lastActivationSkippedSpaceIds.includes(primarySpaceId) ? "not-hosted" : this._lastActivationActivatedSpaceIds.includes(primarySpaceId) ? "hosted" : "unknown";
|
|
19947
19921
|
return;
|
|
19948
19922
|
}
|
|
19949
19923
|
this._lastActivationActivatedSpaceIds = [];
|
|
19950
19924
|
this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
|
|
19925
|
+
this._spaceHosting = result.status === 404 ? "not-hosted" : "unknown";
|
|
19951
19926
|
}
|
|
19952
19927
|
async createBootstrapSession(options) {
|
|
19953
19928
|
refuseCaveated(options.capabilityRequest.manifests);
|
|
@@ -21886,6 +21861,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21886
21861
|
* hosting is confirmed against the session that was active at the time.
|
|
21887
21862
|
*/
|
|
21888
21863
|
this.confirmedHostedSpaceIds = /* @__PURE__ */ new Set();
|
|
21864
|
+
/** The primary space's hosting answer when no authorization layer holds it (a session-only restore). */
|
|
21865
|
+
this._restoredSpaceHosting = "unknown";
|
|
21889
21866
|
/**
|
|
21890
21867
|
* Owned space ids known to be hosted for the current session: the sign-in
|
|
21891
21868
|
* activation listed them as `activated`, or this session hosted them. Unlike
|
|
@@ -22224,6 +22201,96 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22224
22201
|
));
|
|
22225
22202
|
}
|
|
22226
22203
|
}
|
|
22204
|
+
/**
|
|
22205
|
+
* Whether the TinyCloud node hosts the primary space (the default) or a named
|
|
22206
|
+
* or full-id space: `"hosted"`, `"not-hosted"`, or `"unknown"` when the node
|
|
22207
|
+
* cannot say.
|
|
22208
|
+
*
|
|
22209
|
+
* Sends one authorized read the session already holds on that space (a kv
|
|
22210
|
+
* list under a granted prefix, else kv metadata, `tinycloud.space/info`, or
|
|
22211
|
+
* a kv get of a key that does not exist), signed for that space. A session
|
|
22212
|
+
* with no such read sends nothing and answers `unknown`. A 401/403 registers
|
|
22213
|
+
* the session delegation with the node once and asks again once. Network
|
|
22214
|
+
* failures, 5xx and a 5 s timeout answer `unknown`; this never throws.
|
|
22215
|
+
*
|
|
22216
|
+
* `hosted` is remembered for the session and `not-hosted` never is. The
|
|
22217
|
+
* answer for the primary space is also what {@link spaceHosting} reports; a
|
|
22218
|
+
* `unknown` answer leaves the previous one in place.
|
|
22219
|
+
*/
|
|
22220
|
+
async checkSpaceHosting(space) {
|
|
22221
|
+
try {
|
|
22222
|
+
return await this.probeSpaceHosting(space);
|
|
22223
|
+
} catch {
|
|
22224
|
+
return "unknown";
|
|
22225
|
+
}
|
|
22226
|
+
}
|
|
22227
|
+
/** Run the existing primary-space creation flow for the restored session. */
|
|
22228
|
+
async ensurePrimarySpaceHosted(hosting) {
|
|
22229
|
+
const graph = this._serviceGraph;
|
|
22230
|
+
const epoch = this.sessionEpoch;
|
|
22231
|
+
graph.assertActive();
|
|
22232
|
+
this.assertSessionEpoch(epoch, "Space hosting");
|
|
22233
|
+
const auth = this.auth;
|
|
22234
|
+
if (!auth || !this.session) return;
|
|
22235
|
+
await auth.ensurePrimarySpaceHosted(hosting, graph.signal);
|
|
22236
|
+
graph.assertActive();
|
|
22237
|
+
this.assertSessionEpoch(epoch, "Space hosting");
|
|
22238
|
+
}
|
|
22239
|
+
/**
|
|
22240
|
+
* The node's last answer for the primary space: recorded at sign-in from the
|
|
22241
|
+
* activation, or by {@link checkSpaceHosting}. `unknown` after a restore until
|
|
22242
|
+
* something asks.
|
|
22243
|
+
*/
|
|
22244
|
+
get spaceHosting() {
|
|
22245
|
+
return this.auth ? this.auth.spaceHosting : this._restoredSpaceHosting;
|
|
22246
|
+
}
|
|
22247
|
+
async probeSpaceHosting(space) {
|
|
22248
|
+
const context = this._serviceContext;
|
|
22249
|
+
const session = context?.session;
|
|
22250
|
+
const host = context?.hosts[0];
|
|
22251
|
+
if (!context || !session || !host) {
|
|
22252
|
+
return "unknown";
|
|
22253
|
+
}
|
|
22254
|
+
const spaceId = space === void 0 ? session.spaceId : space.startsWith("tinycloud:") ? space : this.ownedSpaceId(space);
|
|
22255
|
+
const graph = this._serviceGraph;
|
|
22256
|
+
const epoch = this.sessionEpoch;
|
|
22257
|
+
const assertCurrent = () => {
|
|
22258
|
+
graph.assertActive();
|
|
22259
|
+
if (epoch !== this.sessionEpoch || graph !== this._serviceGraph || this._serviceContext !== context) {
|
|
22260
|
+
throw new Error("The session changed during the hosting check.");
|
|
22261
|
+
}
|
|
22262
|
+
};
|
|
22263
|
+
const { askSpaceHosting } = await import("./space-hosting.cjs");
|
|
22264
|
+
assertCurrent();
|
|
22265
|
+
this.pruneExpiredRuntimePermissionGrants();
|
|
22266
|
+
const primary = this.currentTinyCloudSession();
|
|
22267
|
+
const answer = await askSpaceHosting({
|
|
22268
|
+
spaceId,
|
|
22269
|
+
operations: [
|
|
22270
|
+
...this.runtimePermissionGrants.flatMap((grant) => grant.operations),
|
|
22271
|
+
...primary ? this.recapOperationsFromSession(primary) : []
|
|
22272
|
+
],
|
|
22273
|
+
covers: (granted, requested) => this.operationCovers(granted, requested),
|
|
22274
|
+
scope: context,
|
|
22275
|
+
host,
|
|
22276
|
+
fetch: unrecordedFetchOf(context),
|
|
22277
|
+
sign: (entries) => {
|
|
22278
|
+
assertCurrent();
|
|
22279
|
+
return graph.invokeAny({ ...session, spaceId }, entries);
|
|
22280
|
+
},
|
|
22281
|
+
// A session saved but never registered on this node is refused: it registers once.
|
|
22282
|
+
activate: (signal) => {
|
|
22283
|
+
assertCurrent();
|
|
22284
|
+
return (0, import_sdk_core10.activateSessionWithHost)(host, session.delegationHeader, AbortSignal.any([signal, graph.signal]));
|
|
22285
|
+
}
|
|
22286
|
+
});
|
|
22287
|
+
assertCurrent();
|
|
22288
|
+
if (answer !== "unknown" && this.spaceIdsEqual(spaceId, session.spaceId)) {
|
|
22289
|
+
if (this.auth) this.auth.noteSpaceHosting(answer);
|
|
22290
|
+
else this._restoredSpaceHosting = answer;
|
|
22291
|
+
}
|
|
22292
|
+
return answer;
|
|
22293
|
+
}
|
|
22227
22294
|
get nodeFeatures() {
|
|
22228
22295
|
return this.auth?.nodeFeatures ?? this._restoredNodeFeatures ?? [];
|
|
22229
22296
|
}
|
|
@@ -22715,6 +22782,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22715
22782
|
this._spaceService = void 0;
|
|
22716
22783
|
this.runtimePermissionGrants = [];
|
|
22717
22784
|
this._recapOperationsCache = void 0;
|
|
22785
|
+
this._restoredSpaceHosting = "unknown";
|
|
22718
22786
|
this.confirmedHostedSpaceIds.clear();
|
|
22719
22787
|
this.hostedOwnedSpaceIds.clear();
|
|
22720
22788
|
this.cancelOwnedSpaceHosts();
|
|
@@ -22908,6 +22976,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22908
22976
|
const primarySession = this.currentTinyCloudSession();
|
|
22909
22977
|
if (primarySession) {
|
|
22910
22978
|
this.registerPrimarySessionGrant(primarySession);
|
|
22979
|
+
if (this.auth?.spaceHosting === "unknown") {
|
|
22980
|
+
await this.checkSpaceHosting();
|
|
22981
|
+
this.assertSessionEpoch(epoch, "Sign-in");
|
|
22982
|
+
}
|
|
22911
22983
|
}
|
|
22912
22984
|
const bootstrapped = await this.bootstrapAccountIfNeeded();
|
|
22913
22985
|
this.assertSessionEpoch(epoch, "Sign-in");
|
|
@@ -24287,6 +24359,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
24287
24359
|
this.tc = stagedGraph.core;
|
|
24288
24360
|
this._recapOperationsCache = stagedPrimary.cache;
|
|
24289
24361
|
this.runtimePermissionGrants = stagedPrimary.grants;
|
|
24362
|
+
this._restoredSpaceHosting = "unknown";
|
|
24290
24363
|
this.confirmedHostedSpaceIds.clear();
|
|
24291
24364
|
this.hostedOwnedSpaceIds.clear();
|
|
24292
24365
|
this.cancelOwnedSpaceHosts();
|