@tinycloud/node-sdk 2.11.0-beta.9 → 3.0.0-beta.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.
@@ -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, UnifiedPolicyCapability, 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 implicit account registry permissions when composing `manifest`. Default true. */
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
  */
@@ -681,6 +828,13 @@ interface ValidatedRuntimeDelegation {
681
828
  /** Host selected for, and used by, the runtime activation. */
682
829
  readonly host: string;
683
830
  }
831
+ interface CompactRuntimeDelegationInput {
832
+ readonly authorization: string;
833
+ readonly cid: string;
834
+ readonly host: string;
835
+ readonly ownerAddress: string;
836
+ readonly chainId: number;
837
+ }
684
838
  /**
685
839
  * CID-bind and activate one compact runtime delegation.
686
840
  *
@@ -692,6 +846,12 @@ interface ValidatedRuntimeDelegation {
692
846
  declare function activateValidatedRuntimeDelegation(node: RuntimeDelegationActivator, delegation: PortableDelegation, options: {
693
847
  host: string;
694
848
  }): Promise<ValidatedRuntimeDelegation>;
849
+ /**
850
+ * Import compact UCAN bytes returned by an authority ceremony through the
851
+ * ordinary runtime-delegation activation path. All transport projections are
852
+ * derived from signed bytes before `/delegate` is called.
853
+ */
854
+ declare function activateCompactRuntimeDelegation(node: RuntimeDelegationActivator, input: CompactRuntimeDelegationInput): Promise<ValidatedRuntimeDelegation>;
695
855
  /**
696
856
  * Turn a delegation REQUEST into a signed GRANT.
697
857
  *
@@ -828,6 +988,9 @@ declare class DelegatedAccess {
828
988
  * ```
829
989
  */
830
990
 
991
+ declare const BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
992
+ declare const BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
993
+ declare const ACCEPTED_MARKER_VERSIONS: readonly number[];
831
994
  /** Input for {@link TinyCloudNode.readSecret}. The target space is required. */
832
995
  interface SecretReadInput {
833
996
  /** Explicit full space URI or an owned-space name. */
@@ -870,6 +1033,32 @@ type SecretReadResult = {
870
1033
  status: "invalid_payload";
871
1034
  };
872
1035
  type CreateOwnerDelegationParams = CreateOwnerDelegationParams$1;
1036
+ interface UnifiedOwnerRootInput {
1037
+ readonly ownerDid: string;
1038
+ readonly role: "policy-authority" | "policy-enforcement";
1039
+ readonly audienceDid: string;
1040
+ readonly policyId: string;
1041
+ readonly policyDigestHex: string;
1042
+ readonly policyCid: string;
1043
+ readonly contentSourceDigestHex: string;
1044
+ readonly capabilityCeilingHashHex: string;
1045
+ readonly nativeProjectionHashHex: string;
1046
+ readonly notBefore: Date;
1047
+ readonly expiresAt: Date;
1048
+ readonly nodeAudience: string;
1049
+ readonly capabilities: readonly UnifiedPolicyCapability[];
1050
+ }
1051
+ interface UnifiedOwnerRootReceipt {
1052
+ readonly cid: string;
1053
+ readonly delegationHeader: {
1054
+ readonly Authorization: string;
1055
+ };
1056
+ readonly delegateDID: string;
1057
+ readonly spaceId: string;
1058
+ readonly path: string;
1059
+ readonly actions: readonly string[];
1060
+ readonly expiry: Date;
1061
+ }
873
1062
  interface OwnerDelegationReceipt extends OwnerDelegationReceipt$1 {
874
1063
  readonly delegation: Delegation;
875
1064
  readonly nodeReceipt: {
@@ -957,7 +1146,7 @@ interface TinyCloudNodeConfig {
957
1146
  manifest?: Manifest | Manifest[];
958
1147
  /** Pre-composed manifest request. Takes precedence over `manifest`. */
959
1148
  capabilityRequest?: ComposedManifestRequest;
960
- /** Include implicit account registry permissions when composing `manifest`. Default true. */
1149
+ /** Include account bootstrap support in plain sessions and implicit manifest permissions. Default true. */
961
1150
  includeAccountRegistryPermissions?: boolean;
962
1151
  /** Run canonical first-account bootstrap when fresh account state is detected. Default true. */
963
1152
  autoBootstrapAccount?: boolean;
@@ -1043,6 +1232,12 @@ interface BootstrapWarning {
1043
1232
  /** Human-readable detail. Diagnostics only — never parse this. */
1044
1233
  message: string;
1045
1234
  }
1235
+ /** Durable attestation that the canonical account bootstrap ceremony completed. */
1236
+ interface BootstrapCompletionMarker {
1237
+ v: number;
1238
+ stepIds: string[];
1239
+ completedAt: string;
1240
+ }
1046
1241
  declare class TinyCloudNode {
1047
1242
  /** @internal Registered by importing @tinycloud/node-sdk (not /core) */
1048
1243
  private static nodeDefaults?;
@@ -1095,6 +1290,9 @@ declare class TinyCloudNode {
1095
1290
  * hosting is confirmed against the session that was active at the time.
1096
1291
  */
1097
1292
  private readonly confirmedHostedSpaceIds;
1293
+ /** Serializes account-registry writes for the active node instance. */
1294
+ private accountRegistryTail;
1295
+ private pendingAccountRegistrySync?;
1098
1296
  /**
1099
1297
  * TinyCloudSession captured by {@link restoreSession} when there's no
1100
1298
  * auth-layer signer available (session-only mode used by OpenKey-backed
@@ -1111,9 +1309,12 @@ declare class TinyCloudNode {
1111
1309
  private _bootstrapSkipped;
1112
1310
  /**
1113
1311
  * Outcome of the last signIn()'s account-bootstrap attempt. `skipped` is
1114
- * true when bootstrap did not complete (interactive signer, auto-sign
1115
- * denied, or a bootstrap step failed); `reason` carries the cause so apps
1116
- * can surface a "finish account setup" call-to-action. `warnings` is
1312
+ * true when bootstrap did not complete in this invocation (interactive signer,
1313
+ * auto-bootstrap disabled, already provisioned, or a decision/provisioning
1314
+ * step failed). `already-provisioned` means the bootstrap was not run here;
1315
+ * it does not mean a prior provisioning attempt failed to complete.
1316
+ * `reason` carries the cause so apps can surface a "finish account setup"
1317
+ * call-to-action. `warnings` is
1117
1318
  * present when bootstrap completed, but one or more steps recovered from
1118
1319
  * an ambiguous failure (e.g. a KV batch write reconciled via per-space
1119
1320
  * fallback) — clean vs. recovered runs are otherwise byte-identical.
@@ -1196,6 +1397,10 @@ declare class TinyCloudNode {
1196
1397
  * Use this when you specifically need the session key, not the user identity.
1197
1398
  */
1198
1399
  get sessionDid(): string;
1400
+ /** Bare did:key principal used as the credential subject and holder binding. */
1401
+ get credentialHolderDid(): string;
1402
+ /** Canonical verification method for the active credential holder key. */
1403
+ get credentialHolderKid(): string;
1199
1404
  /**
1200
1405
  * Return the current session's signed ReCap capabilities after the session
1201
1406
  * has been authenticated or restored. This is intentionally distinct from
@@ -1249,7 +1454,11 @@ declare class TinyCloudNode {
1249
1454
  signIn(options?: SignInOptions): Promise<void>;
1250
1455
  private ownedSpaceId;
1251
1456
  private bootstrapAccountIfNeeded;
1252
- private isFreshBootstrapAccount;
1457
+ private resolveBootstrapDecision;
1458
+ private readBootstrapCompletionMarker;
1459
+ private writeBootstrapCompletionMarker;
1460
+ private isAcceptedBootstrapCompletionMarker;
1461
+ private markerReadIsUnhostedSpace;
1253
1462
  private runAccountBootstrap;
1254
1463
  private registerBootstrapRuntimeGrant;
1255
1464
  /**
@@ -1290,6 +1499,7 @@ declare class TinyCloudNode {
1290
1499
  private registerPrimarySessionGrant;
1291
1500
  private writeManifestRegistryRecords;
1292
1501
  private scheduleAccountRegistrySync;
1502
+ private enqueueAccountRegistryOperation;
1293
1503
  /**
1294
1504
  * Whether the current primary session may invoke `tinycloud.space/list`.
1295
1505
  *
@@ -1375,6 +1585,8 @@ declare class TinyCloudNode {
1375
1585
  * @returns The hosted owned-space URI.
1376
1586
  */
1377
1587
  ensureOwnedSpaceHosted(name: string): Promise<string>;
1588
+ /** Resolve and authenticate the owner encoded by an owned-space URI. */
1589
+ credentialSpaceOwnerDid(spaceId: string): string;
1378
1590
  /**
1379
1591
  * Check whether an owned space is already registered/hosted by consulting the
1380
1592
  * account spaces registry.
@@ -1479,6 +1691,12 @@ declare class TinyCloudNode {
1479
1691
  invokeAny(entries: Parameters<InvokeAnyFunction$1>[1], facts?: Parameters<InvokeAnyFunction$1>[2]): ReturnType<InvokeAnyFunction$1>;
1480
1692
  /** Sign protocol bytes with the established in-memory session key. */
1481
1693
  signSessionBytes(bytes: Uint8Array): Promise<Uint8Array>;
1694
+ /** Author a proofless Policy/v3 owner root with the authenticated holder key. */
1695
+ createUnifiedOwnerRoot(input: UnifiedOwnerRootInput): Promise<UnifiedOwnerRootReceipt>;
1696
+ /** Apply only an already-enabled signing policy to the exact credential request. */
1697
+ autoSignCredentialBytes(bytes: Uint8Array): Promise<Uint8Array | undefined>;
1698
+ /** Invoke the configured interactive approval strategy before session signing. */
1699
+ approveCredentialBytes(bytes: Uint8Array): Promise<Uint8Array>;
1482
1700
  /** Bind a session-signed invocation to the canonical service audience. */
1483
1701
  bindInvocationAudience(authorization: string, audience: string): Promise<string>;
1484
1702
  /**
@@ -2154,6 +2372,13 @@ declare class TinyCloudNode {
2154
2372
  disableSubDelegation?: boolean;
2155
2373
  /** Expiration time in milliseconds from now (must be before parent's expiry) */
2156
2374
  expiryMs?: number;
2375
+ /** Explicit multi-resource projection, including encryption networks. */
2376
+ resources?: Array<{
2377
+ service: string;
2378
+ space?: string;
2379
+ path: string;
2380
+ actions: string[];
2381
+ }>;
2157
2382
  }): Promise<PortableDelegation>;
2158
2383
  }
2159
2384
 
@@ -2265,4 +2490,4 @@ declare class WasmKeyProvider implements KeyProvider {
2265
2490
  */
2266
2491
  declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
2267
2492
 
2268
- export { type AuthDelegationArtifact as A, type BootstrapWarning 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 AuthRequestArtifact as a, type DelegateToResult as b, DelegatedAccess as c, type DelegationAuthority as d, NodeUserAuthorization as e, type NodeUserAuthorizationConfig as f, type RuntimeDelegationActivator as g, type RuntimePermissionGrantOptions as h, type SecretReadInput as i, type SecretReadResult as j, type SignStrategy as k, type TinyCloudNodeConfig as l, type WasmKeyProviderConfig as m, activateValidatedRuntimeDelegation as n, createWasmKeyProvider as o, defaultSignStrategy as p, deserializeDelegation as q, grantAuthRequest as r, serializeDelegation as s };
2493
+ export { ACCEPTED_MARKER_VERSIONS as A, BOOTSTRAP_COMPLETION_MARKER_KEY as B, type CompactRuntimeDelegationInput as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, FileSessionStorage as F, serializeDelegation as G, 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, type UnifiedOwnerRootInput 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 CreateOwnerDelegationParams as f, type DelegateToResult as g, DelegatedAccess as h, type DelegationAuthority as i, NodeUserAuthorization as j, type NodeUserAuthorizationConfig as k, type RuntimeDelegationActivator as l, type RuntimePermissionGrantOptions as m, type SecretReadInput as n, type SecretReadResult as o, type SignStrategy as p, type TinyCloudNodeConfig as q, type UnifiedOwnerRootReceipt as r, UnsupportedSessionRestoreError as s, type WasmKeyProviderConfig as t, activateCompactRuntimeDelegation as u, activateValidatedRuntimeDelegation as v, createWasmKeyProvider as w, defaultSignStrategy as x, deserializeDelegation as y, grantAuthRequest as z };