@tinycloud/node-sdk 2.3.1-beta.0 → 2.4.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/{core-D2hPECHW.d.cts → core-BucTrpWH.d.cts} +86 -2
- package/dist/{core-D2hPECHW.d.ts → core-BucTrpWH.d.ts} +86 -2
- package/dist/core.cjs +46 -0
- 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 +46 -0
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +74 -0
- 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 +73 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry,
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -540,6 +540,69 @@ interface PortableDelegation extends Omit<Delegation, "isRevoked"> {
|
|
|
540
540
|
*/
|
|
541
541
|
resources?: DelegatedResource[];
|
|
542
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* The transport shape `tc auth request --emit` produces and that an owner
|
|
545
|
+
* grants to its requester. Only the fields the grant logic needs are declared;
|
|
546
|
+
* the CLI artifact carries more (posture, captured command, ...) and remains a
|
|
547
|
+
* structural superset of this interface.
|
|
548
|
+
*/
|
|
549
|
+
interface AuthRequestArtifact {
|
|
550
|
+
kind: "tinycloud.auth.request";
|
|
551
|
+
version: 1;
|
|
552
|
+
requestId: string;
|
|
553
|
+
/** The requester's session DID — the audience the grant is issued to. */
|
|
554
|
+
sessionDid: string;
|
|
555
|
+
/** The capabilities the requester is asking the owner to delegate. */
|
|
556
|
+
requested: PermissionEntry[];
|
|
557
|
+
/** Optional lifetime override carried from the request. */
|
|
558
|
+
requestedExpiry?: string | number;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* The transport shape returned by {@link grantAuthRequest} (and written by
|
|
562
|
+
* `tc auth grant`). `tc auth import` accepts this artifact directly.
|
|
563
|
+
*/
|
|
564
|
+
interface AuthDelegationArtifact {
|
|
565
|
+
kind: "tinycloud.auth.delegation";
|
|
566
|
+
version: 1;
|
|
567
|
+
requestId: string;
|
|
568
|
+
delegationCid: string;
|
|
569
|
+
delegation: PortableDelegation;
|
|
570
|
+
permissions: PermissionEntry[];
|
|
571
|
+
expiry: string;
|
|
572
|
+
/** Whether issuing the delegation triggered a wallet prompt. */
|
|
573
|
+
prompted: boolean;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Minimal owner-side capability {@link grantAuthRequest} needs: the signed
|
|
577
|
+
* `delegateTo` primitive. `TinyCloudNode` satisfies this directly; web/SDK
|
|
578
|
+
* contexts can supply any object that exposes the same method.
|
|
579
|
+
*/
|
|
580
|
+
interface DelegationAuthority {
|
|
581
|
+
delegateTo(did: string, permissions: PermissionEntry[], options?: {
|
|
582
|
+
expiry?: string | number;
|
|
583
|
+
forceWalletSign?: boolean;
|
|
584
|
+
}): Promise<{
|
|
585
|
+
delegation: PortableDelegation;
|
|
586
|
+
prompted: boolean;
|
|
587
|
+
}>;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Turn a delegation REQUEST into a signed GRANT.
|
|
591
|
+
*
|
|
592
|
+
* Lifts the body of `tc auth grant` into the SDK so the request→grant
|
|
593
|
+
* handshake is callable programmatically (future SDK/web owner tooling and the
|
|
594
|
+
* KV delegation inbox), with the CLI verb reduced to a thin wrapper. The owner
|
|
595
|
+
* `authority` (a `TinyCloudNode`) signs a delegation scoped to exactly the
|
|
596
|
+
* requested caps, audienced to the requester's `sessionDid`, honoring the
|
|
597
|
+
* request's expiry. The returned artifact round-trips through `tc auth import`.
|
|
598
|
+
*
|
|
599
|
+
* Authorization is enforced cryptographically by `delegateTo`: caps that are
|
|
600
|
+
* not derivable from the owner's own session capability chain are rejected
|
|
601
|
+
* (it throws), so this never widens authority the owner doesn't hold.
|
|
602
|
+
*/
|
|
603
|
+
declare function grantAuthRequest(authority: DelegationAuthority, request: AuthRequestArtifact, options?: {
|
|
604
|
+
expiry?: string | number;
|
|
605
|
+
}): Promise<AuthDelegationArtifact>;
|
|
543
606
|
/**
|
|
544
607
|
* Serialize a PortableDelegation for transport (e.g., over network).
|
|
545
608
|
*/
|
|
@@ -914,6 +977,27 @@ declare class TinyCloudNode {
|
|
|
914
977
|
private ownedSpaceId;
|
|
915
978
|
private writeManifestRegistryRecords;
|
|
916
979
|
private ensureOwnedSpaceHosted;
|
|
980
|
+
/**
|
|
981
|
+
* Host one of this user's owned spaces by name (e.g. `"applications"`).
|
|
982
|
+
*
|
|
983
|
+
* Resolves the name to the owned space URI
|
|
984
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and registers it on the
|
|
985
|
+
* server via the host-SIWE delegation flow, so subsequent KV/SQL writes to
|
|
986
|
+
* that space succeed instead of returning `404 - Space not found`. The
|
|
987
|
+
* caller is the root authority of their own owned spaces, so no additional
|
|
988
|
+
* delegation is required.
|
|
989
|
+
*
|
|
990
|
+
* Unlike {@link ensureOwnedSpaceHosted}, this always submits the host
|
|
991
|
+
* delegation rather than inferring hosting from session activation: a space
|
|
992
|
+
* the current session has never referenced is reported neither as
|
|
993
|
+
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
994
|
+
* skip the host. The host SIWE is idempotent server-side, so re-hosting an
|
|
995
|
+
* existing space is a safe no-op. Must be called after {@link signIn}.
|
|
996
|
+
*
|
|
997
|
+
* @param name - The owned space name (e.g. `"applications"`).
|
|
998
|
+
* @returns The hosted space URI.
|
|
999
|
+
*/
|
|
1000
|
+
hostOwnedSpace(name: string): Promise<string>;
|
|
917
1001
|
/**
|
|
918
1002
|
* Restore a previously established session from stored delegation data.
|
|
919
1003
|
*
|
|
@@ -1648,4 +1732,4 @@ declare class WasmKeyProvider implements KeyProvider {
|
|
|
1648
1732
|
*/
|
|
1649
1733
|
declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
|
|
1650
1734
|
|
|
1651
|
-
export { type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type
|
|
1735
|
+
export { type AuthDelegationArtifact as A, type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type AuthRequestArtifact as a, type DelegateToResult as b, DelegatedAccess as c, type DelegationAuthority as d, NodeUserAuthorization as e, type NodeUserAuthorizationConfig as f, type RuntimePermissionGrantOptions as g, type TinyCloudNodeConfig as h, type WasmKeyProviderConfig as i, createWasmKeyProvider as j, defaultSignStrategy as k, deserializeDelegation as l, grantAuthRequest as m, serializeDelegation as s };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry,
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -540,6 +540,69 @@ interface PortableDelegation extends Omit<Delegation, "isRevoked"> {
|
|
|
540
540
|
*/
|
|
541
541
|
resources?: DelegatedResource[];
|
|
542
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* The transport shape `tc auth request --emit` produces and that an owner
|
|
545
|
+
* grants to its requester. Only the fields the grant logic needs are declared;
|
|
546
|
+
* the CLI artifact carries more (posture, captured command, ...) and remains a
|
|
547
|
+
* structural superset of this interface.
|
|
548
|
+
*/
|
|
549
|
+
interface AuthRequestArtifact {
|
|
550
|
+
kind: "tinycloud.auth.request";
|
|
551
|
+
version: 1;
|
|
552
|
+
requestId: string;
|
|
553
|
+
/** The requester's session DID — the audience the grant is issued to. */
|
|
554
|
+
sessionDid: string;
|
|
555
|
+
/** The capabilities the requester is asking the owner to delegate. */
|
|
556
|
+
requested: PermissionEntry[];
|
|
557
|
+
/** Optional lifetime override carried from the request. */
|
|
558
|
+
requestedExpiry?: string | number;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* The transport shape returned by {@link grantAuthRequest} (and written by
|
|
562
|
+
* `tc auth grant`). `tc auth import` accepts this artifact directly.
|
|
563
|
+
*/
|
|
564
|
+
interface AuthDelegationArtifact {
|
|
565
|
+
kind: "tinycloud.auth.delegation";
|
|
566
|
+
version: 1;
|
|
567
|
+
requestId: string;
|
|
568
|
+
delegationCid: string;
|
|
569
|
+
delegation: PortableDelegation;
|
|
570
|
+
permissions: PermissionEntry[];
|
|
571
|
+
expiry: string;
|
|
572
|
+
/** Whether issuing the delegation triggered a wallet prompt. */
|
|
573
|
+
prompted: boolean;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Minimal owner-side capability {@link grantAuthRequest} needs: the signed
|
|
577
|
+
* `delegateTo` primitive. `TinyCloudNode` satisfies this directly; web/SDK
|
|
578
|
+
* contexts can supply any object that exposes the same method.
|
|
579
|
+
*/
|
|
580
|
+
interface DelegationAuthority {
|
|
581
|
+
delegateTo(did: string, permissions: PermissionEntry[], options?: {
|
|
582
|
+
expiry?: string | number;
|
|
583
|
+
forceWalletSign?: boolean;
|
|
584
|
+
}): Promise<{
|
|
585
|
+
delegation: PortableDelegation;
|
|
586
|
+
prompted: boolean;
|
|
587
|
+
}>;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Turn a delegation REQUEST into a signed GRANT.
|
|
591
|
+
*
|
|
592
|
+
* Lifts the body of `tc auth grant` into the SDK so the request→grant
|
|
593
|
+
* handshake is callable programmatically (future SDK/web owner tooling and the
|
|
594
|
+
* KV delegation inbox), with the CLI verb reduced to a thin wrapper. The owner
|
|
595
|
+
* `authority` (a `TinyCloudNode`) signs a delegation scoped to exactly the
|
|
596
|
+
* requested caps, audienced to the requester's `sessionDid`, honoring the
|
|
597
|
+
* request's expiry. The returned artifact round-trips through `tc auth import`.
|
|
598
|
+
*
|
|
599
|
+
* Authorization is enforced cryptographically by `delegateTo`: caps that are
|
|
600
|
+
* not derivable from the owner's own session capability chain are rejected
|
|
601
|
+
* (it throws), so this never widens authority the owner doesn't hold.
|
|
602
|
+
*/
|
|
603
|
+
declare function grantAuthRequest(authority: DelegationAuthority, request: AuthRequestArtifact, options?: {
|
|
604
|
+
expiry?: string | number;
|
|
605
|
+
}): Promise<AuthDelegationArtifact>;
|
|
543
606
|
/**
|
|
544
607
|
* Serialize a PortableDelegation for transport (e.g., over network).
|
|
545
608
|
*/
|
|
@@ -914,6 +977,27 @@ declare class TinyCloudNode {
|
|
|
914
977
|
private ownedSpaceId;
|
|
915
978
|
private writeManifestRegistryRecords;
|
|
916
979
|
private ensureOwnedSpaceHosted;
|
|
980
|
+
/**
|
|
981
|
+
* Host one of this user's owned spaces by name (e.g. `"applications"`).
|
|
982
|
+
*
|
|
983
|
+
* Resolves the name to the owned space URI
|
|
984
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and registers it on the
|
|
985
|
+
* server via the host-SIWE delegation flow, so subsequent KV/SQL writes to
|
|
986
|
+
* that space succeed instead of returning `404 - Space not found`. The
|
|
987
|
+
* caller is the root authority of their own owned spaces, so no additional
|
|
988
|
+
* delegation is required.
|
|
989
|
+
*
|
|
990
|
+
* Unlike {@link ensureOwnedSpaceHosted}, this always submits the host
|
|
991
|
+
* delegation rather than inferring hosting from session activation: a space
|
|
992
|
+
* the current session has never referenced is reported neither as
|
|
993
|
+
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
994
|
+
* skip the host. The host SIWE is idempotent server-side, so re-hosting an
|
|
995
|
+
* existing space is a safe no-op. Must be called after {@link signIn}.
|
|
996
|
+
*
|
|
997
|
+
* @param name - The owned space name (e.g. `"applications"`).
|
|
998
|
+
* @returns The hosted space URI.
|
|
999
|
+
*/
|
|
1000
|
+
hostOwnedSpace(name: string): Promise<string>;
|
|
917
1001
|
/**
|
|
918
1002
|
* Restore a previously established session from stored delegation data.
|
|
919
1003
|
*
|
|
@@ -1648,4 +1732,4 @@ declare class WasmKeyProvider implements KeyProvider {
|
|
|
1648
1732
|
*/
|
|
1649
1733
|
declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
|
|
1650
1734
|
|
|
1651
|
-
export { type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type
|
|
1735
|
+
export { type AuthDelegationArtifact as A, type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type AuthRequestArtifact as a, type DelegateToResult as b, DelegatedAccess as c, type DelegationAuthority as d, NodeUserAuthorization as e, type NodeUserAuthorizationConfig as f, type RuntimePermissionGrantOptions as g, type TinyCloudNodeConfig as h, type WasmKeyProviderConfig as i, createWasmKeyProvider as j, defaultSignStrategy as k, deserializeDelegation as l, grantAuthRequest as m, serializeDelegation as s };
|
package/dist/core.cjs
CHANGED
|
@@ -1971,6 +1971,52 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1971
1971
|
);
|
|
1972
1972
|
}
|
|
1973
1973
|
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Host one of this user's owned spaces by name (e.g. `"applications"`).
|
|
1976
|
+
*
|
|
1977
|
+
* Resolves the name to the owned space URI
|
|
1978
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and registers it on the
|
|
1979
|
+
* server via the host-SIWE delegation flow, so subsequent KV/SQL writes to
|
|
1980
|
+
* that space succeed instead of returning `404 - Space not found`. The
|
|
1981
|
+
* caller is the root authority of their own owned spaces, so no additional
|
|
1982
|
+
* delegation is required.
|
|
1983
|
+
*
|
|
1984
|
+
* Unlike {@link ensureOwnedSpaceHosted}, this always submits the host
|
|
1985
|
+
* delegation rather than inferring hosting from session activation: a space
|
|
1986
|
+
* the current session has never referenced is reported neither as
|
|
1987
|
+
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
1988
|
+
* skip the host. The host SIWE is idempotent server-side, so re-hosting an
|
|
1989
|
+
* existing space is a safe no-op. Must be called after {@link signIn}.
|
|
1990
|
+
*
|
|
1991
|
+
* @param name - The owned space name (e.g. `"applications"`).
|
|
1992
|
+
* @returns The hosted space URI.
|
|
1993
|
+
*/
|
|
1994
|
+
async hostOwnedSpace(name) {
|
|
1995
|
+
if (!this.auth || !this.auth.tinyCloudSession) {
|
|
1996
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
1997
|
+
}
|
|
1998
|
+
const spaceId = this.ownedSpaceId(name);
|
|
1999
|
+
const host = this.hosts[0] ?? this.config.host;
|
|
2000
|
+
if (!host) {
|
|
2001
|
+
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
2002
|
+
}
|
|
2003
|
+
const hosted = await this.auth.hostOwnedSpace(
|
|
2004
|
+
spaceId
|
|
2005
|
+
);
|
|
2006
|
+
if (!hosted) {
|
|
2007
|
+
throw new Error(`Failed to host owned space: ${spaceId}`);
|
|
2008
|
+
}
|
|
2009
|
+
const activation = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
2010
|
+
host,
|
|
2011
|
+
this.auth.tinyCloudSession.delegationHeader
|
|
2012
|
+
);
|
|
2013
|
+
if (!activation.success || activation.skipped?.includes(spaceId)) {
|
|
2014
|
+
throw new Error(
|
|
2015
|
+
`Failed to activate session for owned space ${spaceId}: ${activation.error ?? "space was skipped"}`
|
|
2016
|
+
);
|
|
2017
|
+
}
|
|
2018
|
+
return spaceId;
|
|
2019
|
+
}
|
|
1974
2020
|
/**
|
|
1975
2021
|
* Restore a previously established session from stored delegation data.
|
|
1976
2022
|
*
|