@tinycloud/node-sdk 2.11.0-beta.8 → 2.11.0
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-Bkptd8qZ.d.cts → core-Bq8TMY7Y.d.cts} +188 -8
- package/dist/{core-Bkptd8qZ.d.ts → core-Bq8TMY7Y.d.ts} +188 -8
- package/dist/core.cjs +675 -67
- 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 +693 -75
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +752 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -3
- package/dist/index.d.ts +85 -3
- package/dist/index.js +765 -76
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -239,7 +239,7 @@ interface NodeUserAuthorizationConfig {
|
|
|
239
239
|
manifest?: Manifest | Manifest[];
|
|
240
240
|
/** Pre-composed manifest request. Takes precedence over `manifest`. */
|
|
241
241
|
capabilityRequest?: ComposedManifestRequest;
|
|
242
|
-
/** Include
|
|
242
|
+
/** Include canonical account registry read/create-update/list permissions when composing `manifest` and plain sign-in. Default true. */
|
|
243
243
|
includeAccountRegistryPermissions?: boolean;
|
|
244
244
|
}
|
|
245
245
|
interface CreateBootstrapSessionOptions {
|
|
@@ -546,6 +546,153 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
546
546
|
spaceId: string;
|
|
547
547
|
verificationMethod: string;
|
|
548
548
|
}, signature: string, keyId: string, jwk: Record<string, unknown>): Promise<ClientSession>;
|
|
549
|
+
/**
|
|
550
|
+
* End-to-end sign-in via OpenKey `authorizeTinyCloud()` (Sol CRITICAL-4).
|
|
551
|
+
*
|
|
552
|
+
* This is the production entry point that wires
|
|
553
|
+
* {@link prepareSessionForSigning} → OpenKey `authorizeTinyCloud()` →
|
|
554
|
+
* {@link signInWithOpenKeyResult} into one call. Consumers pass in a
|
|
555
|
+
* caller-provided `authorizeFn` (typically a thin wrapper around
|
|
556
|
+
* `openkey.authorizeTinyCloud()`) so this method has no direct
|
|
557
|
+
* dependency on the OpenKey SDK — it works with any transport that
|
|
558
|
+
* conforms to the versioned protocol.
|
|
559
|
+
*
|
|
560
|
+
* The `authorizeFn` MUST:
|
|
561
|
+
* 1. Send the prepared SIWE bytes to OpenKey.
|
|
562
|
+
* 2. Return the exact `TinyCloudAuthorizationResultV1` shape (with
|
|
563
|
+
* `signedMessage` — the bytes the signature actually verifies
|
|
564
|
+
* against — plus `selectedActionKeys` and `permissions`).
|
|
565
|
+
*
|
|
566
|
+
* NodeUserAuthorization then completes the session with `signedMessage`
|
|
567
|
+
* (never the prepared bytes), verifying the signature, the immutable
|
|
568
|
+
* SIWE fields, and every subset invariant enforced by
|
|
569
|
+
* {@link signInWithOpenKeyResult}. This preserves the exact-byte
|
|
570
|
+
* guarantee: if the user did NOT narrow, the returned `signedMessage`
|
|
571
|
+
* equals the prepared SIWE byte-for-byte; if the user narrowed, only
|
|
572
|
+
* the ReCap block differs and every immutable header field survives.
|
|
573
|
+
*
|
|
574
|
+
* Legacy exact-byte {@link signIn} callers are unaffected — this method
|
|
575
|
+
* is opt-in.
|
|
576
|
+
*
|
|
577
|
+
* @param authorizeFn Callback that invokes the versioned OpenKey
|
|
578
|
+
* `authorizeTinyCloud()` protocol and returns the result. Receives
|
|
579
|
+
* the prepared SIWE bytes plus a `host` hint the widget should bind
|
|
580
|
+
* into its /authorize-sign-prepare context.
|
|
581
|
+
* @param options Optional overrides for the OpenKey request.
|
|
582
|
+
*/
|
|
583
|
+
signInWithOpenKey(authorizeFn: (input: {
|
|
584
|
+
protocolVersion: 1;
|
|
585
|
+
siwe: string;
|
|
586
|
+
jwk: Record<string, unknown>;
|
|
587
|
+
host?: string;
|
|
588
|
+
/**
|
|
589
|
+
* Sol MAJOR-3: OpenKey key ID (managed or external key) to sign
|
|
590
|
+
* with. When omitted, the OpenKey SDK falls back to the last
|
|
591
|
+
* connected key. Callers who want to bind the flow to a specific
|
|
592
|
+
* OpenKey key can override via options.openkeyKeyId; otherwise the
|
|
593
|
+
* bridge relies on the SDK's connected-key state.
|
|
594
|
+
*/
|
|
595
|
+
keyId?: string;
|
|
596
|
+
/**
|
|
597
|
+
* Optional presentation envelope forwarded to the OpenKey widget.
|
|
598
|
+
* Built from this instance's `_manifest` when set. Display-only —
|
|
599
|
+
* the widget/server MUST NOT let it expand authority. The envelope
|
|
600
|
+
* carries `manifests` payloads plus a stable SHA-256 digest so the
|
|
601
|
+
* OpenKey server can origin-bind the browser origin against the
|
|
602
|
+
* app's well-known manifest.
|
|
603
|
+
*/
|
|
604
|
+
presentation?: CapabilityPresentationEnvelopeV1;
|
|
605
|
+
}) => Promise<{
|
|
606
|
+
protocolVersion: 1;
|
|
607
|
+
address: string;
|
|
608
|
+
signature: string;
|
|
609
|
+
signedMessage: string;
|
|
610
|
+
selectedActionKeys: string[];
|
|
611
|
+
permissions: Array<{
|
|
612
|
+
service: string;
|
|
613
|
+
space: string;
|
|
614
|
+
path: string;
|
|
615
|
+
actions: string[];
|
|
616
|
+
}>;
|
|
617
|
+
}>, options?: {
|
|
618
|
+
host?: string;
|
|
619
|
+
openkeyKeyId?: string;
|
|
620
|
+
/**
|
|
621
|
+
* Optional caller-supplied reason string forwarded in the
|
|
622
|
+
* presentation envelope. Rendered as caller-supplied (never
|
|
623
|
+
* verified) in the widget.
|
|
624
|
+
*/
|
|
625
|
+
reason?: string;
|
|
626
|
+
}): Promise<ClientSession>;
|
|
627
|
+
/**
|
|
628
|
+
* Build a `CapabilityPresentationEnvelopeV1` from `this._manifest`. The
|
|
629
|
+
* envelope is display-only — the OpenKey widget renders it under an
|
|
630
|
+
* honest trust label, and the server /authorize-sign-prepare route
|
|
631
|
+
* decides whether to upgrade the label to `origin-bound` by fetching
|
|
632
|
+
* the well-known manifest and comparing its digest to
|
|
633
|
+
* `manifestDigest`.
|
|
634
|
+
*
|
|
635
|
+
* Returns `undefined` when no manifest is set — the widget renders as
|
|
636
|
+
* "no manifest supplied" (unsigned).
|
|
637
|
+
*
|
|
638
|
+
* The digest is a deterministic SHA-256 over canonical JSON of the
|
|
639
|
+
* first manifest payload; OpenKey parses the fetched well-known manifest
|
|
640
|
+
* and applies the same canonicalization before comparing digests.
|
|
641
|
+
*/
|
|
642
|
+
private buildPresentationEnvelope;
|
|
643
|
+
/**
|
|
644
|
+
* Complete sign-in with a versioned OpenKey authorization result.
|
|
645
|
+
*
|
|
646
|
+
* Where `signInWithPreparedSession` completes with a signature over the
|
|
647
|
+
* ORIGINAL prepared SIWE, this method completes with the SIWE bytes the
|
|
648
|
+
* OpenKey widget actually presented and signed (`signedMessage`). It
|
|
649
|
+
* exists because the versioned authorizeTinyCloud protocol lets the user
|
|
650
|
+
* narrow capabilities; the returned bytes may differ from the original
|
|
651
|
+
* request and are the only ones the signature actually verifies against.
|
|
652
|
+
*
|
|
653
|
+
* The `result` parameter is validated at the trust boundary via
|
|
654
|
+
* `validateAuthorizationResultV1` (in sdk-core). Callers should validate
|
|
655
|
+
* BEFORE calling this method so unknown/missing fields are rejected
|
|
656
|
+
* before any session state is created.
|
|
657
|
+
*
|
|
658
|
+
* Validation performed here (defence-in-depth: even a "valid" v1 payload
|
|
659
|
+
* must clear these checks before any session state is created):
|
|
660
|
+
* 1. `result.address` matches the local signer's address.
|
|
661
|
+
* 2. `result.signature` recovers to `result.address` when verified against
|
|
662
|
+
* `result.signedMessage`.
|
|
663
|
+
* 3. Every immutable SIWE header field (domain, address, URI, version,
|
|
664
|
+
* chainId, nonce, issuedAt) in the original prepared SIWE is preserved
|
|
665
|
+
* byte-for-byte in `result.signedMessage`. `statement` is NOT in this
|
|
666
|
+
* list because the WASM renders it from the ReCap contents; it MUST
|
|
667
|
+
* change when the ReCap is narrowed.
|
|
668
|
+
* 4. Every capability in `result.signedMessage`'s ReCap block was present
|
|
669
|
+
* in the original prepared SIWE — narrowing OK, broadening rejected.
|
|
670
|
+
* 5. Every `result.selectedActionKeys` entry corresponds to a
|
|
671
|
+
* (resource, action) pair in the returned SIWE.
|
|
672
|
+
*/
|
|
673
|
+
signInWithOpenKeyResult(result: {
|
|
674
|
+
protocolVersion: 1;
|
|
675
|
+
address: string;
|
|
676
|
+
signature: string;
|
|
677
|
+
signedMessage: string;
|
|
678
|
+
selectedActionKeys: string[];
|
|
679
|
+
permissions: Array<{
|
|
680
|
+
service: string;
|
|
681
|
+
space: string;
|
|
682
|
+
path: string;
|
|
683
|
+
actions: string[];
|
|
684
|
+
}>;
|
|
685
|
+
}, prepared: {
|
|
686
|
+
/**
|
|
687
|
+
* The ORIGINAL SIWE the SDK produced via {@link prepareSessionForSigning}.
|
|
688
|
+
* Used as the source-of-truth reference for immutable-header and
|
|
689
|
+
* capability-subset comparison against `result.signedMessage`.
|
|
690
|
+
*/
|
|
691
|
+
siwe: string;
|
|
692
|
+
jwk: Record<string, unknown>;
|
|
693
|
+
spaceId: string;
|
|
694
|
+
verificationMethod: string;
|
|
695
|
+
}, keyId: string, jwk: Record<string, unknown>): Promise<ClientSession>;
|
|
549
696
|
/**
|
|
550
697
|
* Clear persisted session data.
|
|
551
698
|
*/
|
|
@@ -828,6 +975,9 @@ declare class DelegatedAccess {
|
|
|
828
975
|
* ```
|
|
829
976
|
*/
|
|
830
977
|
|
|
978
|
+
declare const BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
|
|
979
|
+
declare const BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
|
|
980
|
+
declare const ACCEPTED_MARKER_VERSIONS: readonly number[];
|
|
831
981
|
/** Input for {@link TinyCloudNode.readSecret}. The target space is required. */
|
|
832
982
|
interface SecretReadInput {
|
|
833
983
|
/** Explicit full space URI or an owned-space name. */
|
|
@@ -957,7 +1107,7 @@ interface TinyCloudNodeConfig {
|
|
|
957
1107
|
manifest?: Manifest | Manifest[];
|
|
958
1108
|
/** Pre-composed manifest request. Takes precedence over `manifest`. */
|
|
959
1109
|
capabilityRequest?: ComposedManifestRequest;
|
|
960
|
-
/** Include
|
|
1110
|
+
/** Include account bootstrap support in plain sessions and implicit manifest permissions. Default true. */
|
|
961
1111
|
includeAccountRegistryPermissions?: boolean;
|
|
962
1112
|
/** Run canonical first-account bootstrap when fresh account state is detected. Default true. */
|
|
963
1113
|
autoBootstrapAccount?: boolean;
|
|
@@ -1043,6 +1193,12 @@ interface BootstrapWarning {
|
|
|
1043
1193
|
/** Human-readable detail. Diagnostics only — never parse this. */
|
|
1044
1194
|
message: string;
|
|
1045
1195
|
}
|
|
1196
|
+
/** Durable attestation that the canonical account bootstrap ceremony completed. */
|
|
1197
|
+
interface BootstrapCompletionMarker {
|
|
1198
|
+
v: number;
|
|
1199
|
+
stepIds: string[];
|
|
1200
|
+
completedAt: string;
|
|
1201
|
+
}
|
|
1046
1202
|
declare class TinyCloudNode {
|
|
1047
1203
|
/** @internal Registered by importing @tinycloud/node-sdk (not /core) */
|
|
1048
1204
|
private static nodeDefaults?;
|
|
@@ -1111,9 +1267,12 @@ declare class TinyCloudNode {
|
|
|
1111
1267
|
private _bootstrapSkipped;
|
|
1112
1268
|
/**
|
|
1113
1269
|
* Outcome of the last signIn()'s account-bootstrap attempt. `skipped` is
|
|
1114
|
-
* true when bootstrap did not complete (interactive signer,
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1270
|
+
* true when bootstrap did not complete in this invocation (interactive signer,
|
|
1271
|
+
* auto-bootstrap disabled, already provisioned, or a decision/provisioning
|
|
1272
|
+
* step failed). `already-provisioned` means the bootstrap was not run here;
|
|
1273
|
+
* it does not mean a prior provisioning attempt failed to complete.
|
|
1274
|
+
* `reason` carries the cause so apps can surface a "finish account setup"
|
|
1275
|
+
* call-to-action. `warnings` is
|
|
1117
1276
|
* present when bootstrap completed, but one or more steps recovered from
|
|
1118
1277
|
* an ambiguous failure (e.g. a KV batch write reconciled via per-space
|
|
1119
1278
|
* fallback) — clean vs. recovered runs are otherwise byte-identical.
|
|
@@ -1196,6 +1355,10 @@ declare class TinyCloudNode {
|
|
|
1196
1355
|
* Use this when you specifically need the session key, not the user identity.
|
|
1197
1356
|
*/
|
|
1198
1357
|
get sessionDid(): string;
|
|
1358
|
+
/** Bare did:key principal used as the credential subject and holder binding. */
|
|
1359
|
+
get credentialHolderDid(): string;
|
|
1360
|
+
/** Canonical verification method for the active credential holder key. */
|
|
1361
|
+
get credentialHolderKid(): string;
|
|
1199
1362
|
/**
|
|
1200
1363
|
* Return the current session's signed ReCap capabilities after the session
|
|
1201
1364
|
* has been authenticated or restored. This is intentionally distinct from
|
|
@@ -1249,7 +1412,11 @@ declare class TinyCloudNode {
|
|
|
1249
1412
|
signIn(options?: SignInOptions): Promise<void>;
|
|
1250
1413
|
private ownedSpaceId;
|
|
1251
1414
|
private bootstrapAccountIfNeeded;
|
|
1252
|
-
private
|
|
1415
|
+
private resolveBootstrapDecision;
|
|
1416
|
+
private readBootstrapCompletionMarker;
|
|
1417
|
+
private writeBootstrapCompletionMarker;
|
|
1418
|
+
private isAcceptedBootstrapCompletionMarker;
|
|
1419
|
+
private markerReadIsUnhostedSpace;
|
|
1253
1420
|
private runAccountBootstrap;
|
|
1254
1421
|
private registerBootstrapRuntimeGrant;
|
|
1255
1422
|
/**
|
|
@@ -1375,6 +1542,8 @@ declare class TinyCloudNode {
|
|
|
1375
1542
|
* @returns The hosted owned-space URI.
|
|
1376
1543
|
*/
|
|
1377
1544
|
ensureOwnedSpaceHosted(name: string): Promise<string>;
|
|
1545
|
+
/** Resolve and authenticate the owner encoded by an owned-space URI. */
|
|
1546
|
+
credentialSpaceOwnerDid(spaceId: string): string;
|
|
1378
1547
|
/**
|
|
1379
1548
|
* Check whether an owned space is already registered/hosted by consulting the
|
|
1380
1549
|
* account spaces registry.
|
|
@@ -1479,6 +1648,10 @@ declare class TinyCloudNode {
|
|
|
1479
1648
|
invokeAny(entries: Parameters<InvokeAnyFunction$1>[1], facts?: Parameters<InvokeAnyFunction$1>[2]): ReturnType<InvokeAnyFunction$1>;
|
|
1480
1649
|
/** Sign protocol bytes with the established in-memory session key. */
|
|
1481
1650
|
signSessionBytes(bytes: Uint8Array): Promise<Uint8Array>;
|
|
1651
|
+
/** Apply only an already-enabled signing policy to the exact credential request. */
|
|
1652
|
+
autoSignCredentialBytes(bytes: Uint8Array): Promise<Uint8Array | undefined>;
|
|
1653
|
+
/** Invoke the configured interactive approval strategy before session signing. */
|
|
1654
|
+
approveCredentialBytes(bytes: Uint8Array): Promise<Uint8Array>;
|
|
1482
1655
|
/** Bind a session-signed invocation to the canonical service audience. */
|
|
1483
1656
|
bindInvocationAudience(authorization: string, audience: string): Promise<string>;
|
|
1484
1657
|
/**
|
|
@@ -2154,6 +2327,13 @@ declare class TinyCloudNode {
|
|
|
2154
2327
|
disableSubDelegation?: boolean;
|
|
2155
2328
|
/** Expiration time in milliseconds from now (must be before parent's expiry) */
|
|
2156
2329
|
expiryMs?: number;
|
|
2330
|
+
/** Explicit multi-resource projection, including encryption networks. */
|
|
2331
|
+
resources?: Array<{
|
|
2332
|
+
service: string;
|
|
2333
|
+
space?: string;
|
|
2334
|
+
path: string;
|
|
2335
|
+
actions: string[];
|
|
2336
|
+
}>;
|
|
2157
2337
|
}): Promise<PortableDelegation>;
|
|
2158
2338
|
}
|
|
2159
2339
|
|
|
@@ -2265,4 +2445,4 @@ declare class WasmKeyProvider implements KeyProvider {
|
|
|
2265
2445
|
*/
|
|
2266
2446
|
declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
|
|
2267
2447
|
|
|
2268
|
-
export {
|
|
2448
|
+
export { ACCEPTED_MARKER_VERSIONS as A, BOOTSTRAP_COMPLETION_MARKER_KEY as B, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, type RestorableSession as R, type SecretPermissionHint as S, TinyCloudNode as T, UnsupportedSessionRestoreError as U, type ValidatedRuntimeDelegation as V, WasmKeyProvider as W, type AuthDelegationArtifact as a, type AuthRequestArtifact as b, BOOTSTRAP_COMPLETION_MARKER_VERSION as c, type BootstrapCompletionMarker as d, type BootstrapWarning as e, type DelegateToResult as f, DelegatedAccess as g, type DelegationAuthority as h, NodeUserAuthorization as i, type NodeUserAuthorizationConfig as j, type RuntimeDelegationActivator as k, type RuntimePermissionGrantOptions as l, type SecretReadInput as m, type SecretReadResult as n, type SignStrategy as o, type TinyCloudNodeConfig as p, type WasmKeyProviderConfig as q, activateValidatedRuntimeDelegation as r, createWasmKeyProvider as s, defaultSignStrategy as t, deserializeDelegation as u, grantAuthRequest as v, serializeDelegation as w };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -239,7 +239,7 @@ interface NodeUserAuthorizationConfig {
|
|
|
239
239
|
manifest?: Manifest | Manifest[];
|
|
240
240
|
/** Pre-composed manifest request. Takes precedence over `manifest`. */
|
|
241
241
|
capabilityRequest?: ComposedManifestRequest;
|
|
242
|
-
/** Include
|
|
242
|
+
/** Include canonical account registry read/create-update/list permissions when composing `manifest` and plain sign-in. Default true. */
|
|
243
243
|
includeAccountRegistryPermissions?: boolean;
|
|
244
244
|
}
|
|
245
245
|
interface CreateBootstrapSessionOptions {
|
|
@@ -546,6 +546,153 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
546
546
|
spaceId: string;
|
|
547
547
|
verificationMethod: string;
|
|
548
548
|
}, signature: string, keyId: string, jwk: Record<string, unknown>): Promise<ClientSession>;
|
|
549
|
+
/**
|
|
550
|
+
* End-to-end sign-in via OpenKey `authorizeTinyCloud()` (Sol CRITICAL-4).
|
|
551
|
+
*
|
|
552
|
+
* This is the production entry point that wires
|
|
553
|
+
* {@link prepareSessionForSigning} → OpenKey `authorizeTinyCloud()` →
|
|
554
|
+
* {@link signInWithOpenKeyResult} into one call. Consumers pass in a
|
|
555
|
+
* caller-provided `authorizeFn` (typically a thin wrapper around
|
|
556
|
+
* `openkey.authorizeTinyCloud()`) so this method has no direct
|
|
557
|
+
* dependency on the OpenKey SDK — it works with any transport that
|
|
558
|
+
* conforms to the versioned protocol.
|
|
559
|
+
*
|
|
560
|
+
* The `authorizeFn` MUST:
|
|
561
|
+
* 1. Send the prepared SIWE bytes to OpenKey.
|
|
562
|
+
* 2. Return the exact `TinyCloudAuthorizationResultV1` shape (with
|
|
563
|
+
* `signedMessage` — the bytes the signature actually verifies
|
|
564
|
+
* against — plus `selectedActionKeys` and `permissions`).
|
|
565
|
+
*
|
|
566
|
+
* NodeUserAuthorization then completes the session with `signedMessage`
|
|
567
|
+
* (never the prepared bytes), verifying the signature, the immutable
|
|
568
|
+
* SIWE fields, and every subset invariant enforced by
|
|
569
|
+
* {@link signInWithOpenKeyResult}. This preserves the exact-byte
|
|
570
|
+
* guarantee: if the user did NOT narrow, the returned `signedMessage`
|
|
571
|
+
* equals the prepared SIWE byte-for-byte; if the user narrowed, only
|
|
572
|
+
* the ReCap block differs and every immutable header field survives.
|
|
573
|
+
*
|
|
574
|
+
* Legacy exact-byte {@link signIn} callers are unaffected — this method
|
|
575
|
+
* is opt-in.
|
|
576
|
+
*
|
|
577
|
+
* @param authorizeFn Callback that invokes the versioned OpenKey
|
|
578
|
+
* `authorizeTinyCloud()` protocol and returns the result. Receives
|
|
579
|
+
* the prepared SIWE bytes plus a `host` hint the widget should bind
|
|
580
|
+
* into its /authorize-sign-prepare context.
|
|
581
|
+
* @param options Optional overrides for the OpenKey request.
|
|
582
|
+
*/
|
|
583
|
+
signInWithOpenKey(authorizeFn: (input: {
|
|
584
|
+
protocolVersion: 1;
|
|
585
|
+
siwe: string;
|
|
586
|
+
jwk: Record<string, unknown>;
|
|
587
|
+
host?: string;
|
|
588
|
+
/**
|
|
589
|
+
* Sol MAJOR-3: OpenKey key ID (managed or external key) to sign
|
|
590
|
+
* with. When omitted, the OpenKey SDK falls back to the last
|
|
591
|
+
* connected key. Callers who want to bind the flow to a specific
|
|
592
|
+
* OpenKey key can override via options.openkeyKeyId; otherwise the
|
|
593
|
+
* bridge relies on the SDK's connected-key state.
|
|
594
|
+
*/
|
|
595
|
+
keyId?: string;
|
|
596
|
+
/**
|
|
597
|
+
* Optional presentation envelope forwarded to the OpenKey widget.
|
|
598
|
+
* Built from this instance's `_manifest` when set. Display-only —
|
|
599
|
+
* the widget/server MUST NOT let it expand authority. The envelope
|
|
600
|
+
* carries `manifests` payloads plus a stable SHA-256 digest so the
|
|
601
|
+
* OpenKey server can origin-bind the browser origin against the
|
|
602
|
+
* app's well-known manifest.
|
|
603
|
+
*/
|
|
604
|
+
presentation?: CapabilityPresentationEnvelopeV1;
|
|
605
|
+
}) => Promise<{
|
|
606
|
+
protocolVersion: 1;
|
|
607
|
+
address: string;
|
|
608
|
+
signature: string;
|
|
609
|
+
signedMessage: string;
|
|
610
|
+
selectedActionKeys: string[];
|
|
611
|
+
permissions: Array<{
|
|
612
|
+
service: string;
|
|
613
|
+
space: string;
|
|
614
|
+
path: string;
|
|
615
|
+
actions: string[];
|
|
616
|
+
}>;
|
|
617
|
+
}>, options?: {
|
|
618
|
+
host?: string;
|
|
619
|
+
openkeyKeyId?: string;
|
|
620
|
+
/**
|
|
621
|
+
* Optional caller-supplied reason string forwarded in the
|
|
622
|
+
* presentation envelope. Rendered as caller-supplied (never
|
|
623
|
+
* verified) in the widget.
|
|
624
|
+
*/
|
|
625
|
+
reason?: string;
|
|
626
|
+
}): Promise<ClientSession>;
|
|
627
|
+
/**
|
|
628
|
+
* Build a `CapabilityPresentationEnvelopeV1` from `this._manifest`. The
|
|
629
|
+
* envelope is display-only — the OpenKey widget renders it under an
|
|
630
|
+
* honest trust label, and the server /authorize-sign-prepare route
|
|
631
|
+
* decides whether to upgrade the label to `origin-bound` by fetching
|
|
632
|
+
* the well-known manifest and comparing its digest to
|
|
633
|
+
* `manifestDigest`.
|
|
634
|
+
*
|
|
635
|
+
* Returns `undefined` when no manifest is set — the widget renders as
|
|
636
|
+
* "no manifest supplied" (unsigned).
|
|
637
|
+
*
|
|
638
|
+
* The digest is a deterministic SHA-256 over canonical JSON of the
|
|
639
|
+
* first manifest payload; OpenKey parses the fetched well-known manifest
|
|
640
|
+
* and applies the same canonicalization before comparing digests.
|
|
641
|
+
*/
|
|
642
|
+
private buildPresentationEnvelope;
|
|
643
|
+
/**
|
|
644
|
+
* Complete sign-in with a versioned OpenKey authorization result.
|
|
645
|
+
*
|
|
646
|
+
* Where `signInWithPreparedSession` completes with a signature over the
|
|
647
|
+
* ORIGINAL prepared SIWE, this method completes with the SIWE bytes the
|
|
648
|
+
* OpenKey widget actually presented and signed (`signedMessage`). It
|
|
649
|
+
* exists because the versioned authorizeTinyCloud protocol lets the user
|
|
650
|
+
* narrow capabilities; the returned bytes may differ from the original
|
|
651
|
+
* request and are the only ones the signature actually verifies against.
|
|
652
|
+
*
|
|
653
|
+
* The `result` parameter is validated at the trust boundary via
|
|
654
|
+
* `validateAuthorizationResultV1` (in sdk-core). Callers should validate
|
|
655
|
+
* BEFORE calling this method so unknown/missing fields are rejected
|
|
656
|
+
* before any session state is created.
|
|
657
|
+
*
|
|
658
|
+
* Validation performed here (defence-in-depth: even a "valid" v1 payload
|
|
659
|
+
* must clear these checks before any session state is created):
|
|
660
|
+
* 1. `result.address` matches the local signer's address.
|
|
661
|
+
* 2. `result.signature` recovers to `result.address` when verified against
|
|
662
|
+
* `result.signedMessage`.
|
|
663
|
+
* 3. Every immutable SIWE header field (domain, address, URI, version,
|
|
664
|
+
* chainId, nonce, issuedAt) in the original prepared SIWE is preserved
|
|
665
|
+
* byte-for-byte in `result.signedMessage`. `statement` is NOT in this
|
|
666
|
+
* list because the WASM renders it from the ReCap contents; it MUST
|
|
667
|
+
* change when the ReCap is narrowed.
|
|
668
|
+
* 4. Every capability in `result.signedMessage`'s ReCap block was present
|
|
669
|
+
* in the original prepared SIWE — narrowing OK, broadening rejected.
|
|
670
|
+
* 5. Every `result.selectedActionKeys` entry corresponds to a
|
|
671
|
+
* (resource, action) pair in the returned SIWE.
|
|
672
|
+
*/
|
|
673
|
+
signInWithOpenKeyResult(result: {
|
|
674
|
+
protocolVersion: 1;
|
|
675
|
+
address: string;
|
|
676
|
+
signature: string;
|
|
677
|
+
signedMessage: string;
|
|
678
|
+
selectedActionKeys: string[];
|
|
679
|
+
permissions: Array<{
|
|
680
|
+
service: string;
|
|
681
|
+
space: string;
|
|
682
|
+
path: string;
|
|
683
|
+
actions: string[];
|
|
684
|
+
}>;
|
|
685
|
+
}, prepared: {
|
|
686
|
+
/**
|
|
687
|
+
* The ORIGINAL SIWE the SDK produced via {@link prepareSessionForSigning}.
|
|
688
|
+
* Used as the source-of-truth reference for immutable-header and
|
|
689
|
+
* capability-subset comparison against `result.signedMessage`.
|
|
690
|
+
*/
|
|
691
|
+
siwe: string;
|
|
692
|
+
jwk: Record<string, unknown>;
|
|
693
|
+
spaceId: string;
|
|
694
|
+
verificationMethod: string;
|
|
695
|
+
}, keyId: string, jwk: Record<string, unknown>): Promise<ClientSession>;
|
|
549
696
|
/**
|
|
550
697
|
* Clear persisted session data.
|
|
551
698
|
*/
|
|
@@ -828,6 +975,9 @@ declare class DelegatedAccess {
|
|
|
828
975
|
* ```
|
|
829
976
|
*/
|
|
830
977
|
|
|
978
|
+
declare const BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
|
|
979
|
+
declare const BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
|
|
980
|
+
declare const ACCEPTED_MARKER_VERSIONS: readonly number[];
|
|
831
981
|
/** Input for {@link TinyCloudNode.readSecret}. The target space is required. */
|
|
832
982
|
interface SecretReadInput {
|
|
833
983
|
/** Explicit full space URI or an owned-space name. */
|
|
@@ -957,7 +1107,7 @@ interface TinyCloudNodeConfig {
|
|
|
957
1107
|
manifest?: Manifest | Manifest[];
|
|
958
1108
|
/** Pre-composed manifest request. Takes precedence over `manifest`. */
|
|
959
1109
|
capabilityRequest?: ComposedManifestRequest;
|
|
960
|
-
/** Include
|
|
1110
|
+
/** Include account bootstrap support in plain sessions and implicit manifest permissions. Default true. */
|
|
961
1111
|
includeAccountRegistryPermissions?: boolean;
|
|
962
1112
|
/** Run canonical first-account bootstrap when fresh account state is detected. Default true. */
|
|
963
1113
|
autoBootstrapAccount?: boolean;
|
|
@@ -1043,6 +1193,12 @@ interface BootstrapWarning {
|
|
|
1043
1193
|
/** Human-readable detail. Diagnostics only — never parse this. */
|
|
1044
1194
|
message: string;
|
|
1045
1195
|
}
|
|
1196
|
+
/** Durable attestation that the canonical account bootstrap ceremony completed. */
|
|
1197
|
+
interface BootstrapCompletionMarker {
|
|
1198
|
+
v: number;
|
|
1199
|
+
stepIds: string[];
|
|
1200
|
+
completedAt: string;
|
|
1201
|
+
}
|
|
1046
1202
|
declare class TinyCloudNode {
|
|
1047
1203
|
/** @internal Registered by importing @tinycloud/node-sdk (not /core) */
|
|
1048
1204
|
private static nodeDefaults?;
|
|
@@ -1111,9 +1267,12 @@ declare class TinyCloudNode {
|
|
|
1111
1267
|
private _bootstrapSkipped;
|
|
1112
1268
|
/**
|
|
1113
1269
|
* Outcome of the last signIn()'s account-bootstrap attempt. `skipped` is
|
|
1114
|
-
* true when bootstrap did not complete (interactive signer,
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1270
|
+
* true when bootstrap did not complete in this invocation (interactive signer,
|
|
1271
|
+
* auto-bootstrap disabled, already provisioned, or a decision/provisioning
|
|
1272
|
+
* step failed). `already-provisioned` means the bootstrap was not run here;
|
|
1273
|
+
* it does not mean a prior provisioning attempt failed to complete.
|
|
1274
|
+
* `reason` carries the cause so apps can surface a "finish account setup"
|
|
1275
|
+
* call-to-action. `warnings` is
|
|
1117
1276
|
* present when bootstrap completed, but one or more steps recovered from
|
|
1118
1277
|
* an ambiguous failure (e.g. a KV batch write reconciled via per-space
|
|
1119
1278
|
* fallback) — clean vs. recovered runs are otherwise byte-identical.
|
|
@@ -1196,6 +1355,10 @@ declare class TinyCloudNode {
|
|
|
1196
1355
|
* Use this when you specifically need the session key, not the user identity.
|
|
1197
1356
|
*/
|
|
1198
1357
|
get sessionDid(): string;
|
|
1358
|
+
/** Bare did:key principal used as the credential subject and holder binding. */
|
|
1359
|
+
get credentialHolderDid(): string;
|
|
1360
|
+
/** Canonical verification method for the active credential holder key. */
|
|
1361
|
+
get credentialHolderKid(): string;
|
|
1199
1362
|
/**
|
|
1200
1363
|
* Return the current session's signed ReCap capabilities after the session
|
|
1201
1364
|
* has been authenticated or restored. This is intentionally distinct from
|
|
@@ -1249,7 +1412,11 @@ declare class TinyCloudNode {
|
|
|
1249
1412
|
signIn(options?: SignInOptions): Promise<void>;
|
|
1250
1413
|
private ownedSpaceId;
|
|
1251
1414
|
private bootstrapAccountIfNeeded;
|
|
1252
|
-
private
|
|
1415
|
+
private resolveBootstrapDecision;
|
|
1416
|
+
private readBootstrapCompletionMarker;
|
|
1417
|
+
private writeBootstrapCompletionMarker;
|
|
1418
|
+
private isAcceptedBootstrapCompletionMarker;
|
|
1419
|
+
private markerReadIsUnhostedSpace;
|
|
1253
1420
|
private runAccountBootstrap;
|
|
1254
1421
|
private registerBootstrapRuntimeGrant;
|
|
1255
1422
|
/**
|
|
@@ -1375,6 +1542,8 @@ declare class TinyCloudNode {
|
|
|
1375
1542
|
* @returns The hosted owned-space URI.
|
|
1376
1543
|
*/
|
|
1377
1544
|
ensureOwnedSpaceHosted(name: string): Promise<string>;
|
|
1545
|
+
/** Resolve and authenticate the owner encoded by an owned-space URI. */
|
|
1546
|
+
credentialSpaceOwnerDid(spaceId: string): string;
|
|
1378
1547
|
/**
|
|
1379
1548
|
* Check whether an owned space is already registered/hosted by consulting the
|
|
1380
1549
|
* account spaces registry.
|
|
@@ -1479,6 +1648,10 @@ declare class TinyCloudNode {
|
|
|
1479
1648
|
invokeAny(entries: Parameters<InvokeAnyFunction$1>[1], facts?: Parameters<InvokeAnyFunction$1>[2]): ReturnType<InvokeAnyFunction$1>;
|
|
1480
1649
|
/** Sign protocol bytes with the established in-memory session key. */
|
|
1481
1650
|
signSessionBytes(bytes: Uint8Array): Promise<Uint8Array>;
|
|
1651
|
+
/** Apply only an already-enabled signing policy to the exact credential request. */
|
|
1652
|
+
autoSignCredentialBytes(bytes: Uint8Array): Promise<Uint8Array | undefined>;
|
|
1653
|
+
/** Invoke the configured interactive approval strategy before session signing. */
|
|
1654
|
+
approveCredentialBytes(bytes: Uint8Array): Promise<Uint8Array>;
|
|
1482
1655
|
/** Bind a session-signed invocation to the canonical service audience. */
|
|
1483
1656
|
bindInvocationAudience(authorization: string, audience: string): Promise<string>;
|
|
1484
1657
|
/**
|
|
@@ -2154,6 +2327,13 @@ declare class TinyCloudNode {
|
|
|
2154
2327
|
disableSubDelegation?: boolean;
|
|
2155
2328
|
/** Expiration time in milliseconds from now (must be before parent's expiry) */
|
|
2156
2329
|
expiryMs?: number;
|
|
2330
|
+
/** Explicit multi-resource projection, including encryption networks. */
|
|
2331
|
+
resources?: Array<{
|
|
2332
|
+
service: string;
|
|
2333
|
+
space?: string;
|
|
2334
|
+
path: string;
|
|
2335
|
+
actions: string[];
|
|
2336
|
+
}>;
|
|
2157
2337
|
}): Promise<PortableDelegation>;
|
|
2158
2338
|
}
|
|
2159
2339
|
|
|
@@ -2265,4 +2445,4 @@ declare class WasmKeyProvider implements KeyProvider {
|
|
|
2265
2445
|
*/
|
|
2266
2446
|
declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
|
|
2267
2447
|
|
|
2268
|
-
export {
|
|
2448
|
+
export { ACCEPTED_MARKER_VERSIONS as A, BOOTSTRAP_COMPLETION_MARKER_KEY as B, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, type RestorableSession as R, type SecretPermissionHint as S, TinyCloudNode as T, UnsupportedSessionRestoreError as U, type ValidatedRuntimeDelegation as V, WasmKeyProvider as W, type AuthDelegationArtifact as a, type AuthRequestArtifact as b, BOOTSTRAP_COMPLETION_MARKER_VERSION as c, type BootstrapCompletionMarker as d, type BootstrapWarning as e, type DelegateToResult as f, DelegatedAccess as g, type DelegationAuthority as h, NodeUserAuthorization as i, type NodeUserAuthorizationConfig as j, type RuntimeDelegationActivator as k, type RuntimePermissionGrantOptions as l, type SecretReadInput as m, type SecretReadResult as n, type SignStrategy as o, type TinyCloudNodeConfig as p, type WasmKeyProviderConfig as q, activateValidatedRuntimeDelegation as r, createWasmKeyProvider as s, defaultSignStrategy as t, deserializeDelegation as u, grantAuthRequest as v, serializeDelegation as w };
|