@tinycloud/node-sdk 3.2.6-beta.6 → 3.3.0-beta.11

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.
Files changed (43) hide show
  1. package/dist/{WasmKeyProvider-DEdSyQ0I.d.cts → TinyCloudNode-CcNh20QX.d.cts} +181 -286
  2. package/dist/{WasmKeyProvider-DEdSyQ0I.d.ts → TinyCloudNode-CcNh20QX.d.ts} +181 -286
  3. package/dist/WasmKeyProvider-5Ee7fcAw.d.cts +217 -0
  4. package/dist/WasmKeyProvider-5Ee7fcAw.d.ts +217 -0
  5. package/dist/authority-Cwotwza3.d.cts +118 -0
  6. package/dist/authority-D_u9a7Wl.d.ts +118 -0
  7. package/dist/core.cjs +401 -168
  8. package/dist/core.cjs.map +1 -1
  9. package/dist/core.d.cts +37 -4
  10. package/dist/core.d.ts +37 -4
  11. package/dist/core.js +408 -176
  12. package/dist/core.js.map +1 -1
  13. package/dist/gated-network-BEF2XSTC.d.cts +16 -0
  14. package/dist/gated-network-BEF2XSTC.d.ts +16 -0
  15. package/dist/index.cjs +2735 -545
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +35 -89
  18. package/dist/index.d.ts +35 -89
  19. package/dist/index.js +2730 -545
  20. package/dist/index.js.map +1 -1
  21. package/dist/replication/authority.cjs +153 -15
  22. package/dist/replication/authority.cjs.map +1 -1
  23. package/dist/replication/authority.d.cts +4 -1
  24. package/dist/replication/authority.d.ts +4 -1
  25. package/dist/replication/authority.js +147 -14
  26. package/dist/replication/authority.js.map +1 -1
  27. package/dist/replication/gated-network.cjs +90 -0
  28. package/dist/replication/gated-network.cjs.map +1 -0
  29. package/dist/replication/gated-network.d.cts +2 -0
  30. package/dist/replication/gated-network.d.ts +2 -0
  31. package/dist/replication/gated-network.js +65 -0
  32. package/dist/replication/gated-network.js.map +1 -0
  33. package/dist/replication/runtime.cjs +84 -6
  34. package/dist/replication/runtime.cjs.map +1 -1
  35. package/dist/replication/runtime.d.cts +2 -1
  36. package/dist/replication/runtime.d.ts +2 -1
  37. package/dist/replication/runtime.js +84 -6
  38. package/dist/replication/runtime.js.map +1 -1
  39. package/dist/{runtime-B5P5SRpC.d.ts → runtime-D1o9Eybt.d.cts} +14 -3
  40. package/dist/{runtime-B5P5SRpC.d.cts → runtime-v62FzQHz.d.ts} +14 -3
  41. package/package.json +14 -4
  42. package/dist/authority-DDGtccBK.d.cts +0 -96
  43. package/dist/authority-DDGtccBK.d.ts +0 -96
@@ -0,0 +1,217 @@
1
+ import { ISessionStorage, PersistedSessionData, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
+
3
+ /**
4
+ * In-memory session storage for Node.js.
5
+ *
6
+ * Sessions are stored in memory and lost when the process exits.
7
+ * Suitable for:
8
+ * - Development and testing
9
+ * - Stateless server deployments
10
+ * - Short-lived processes
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const storage = new MemorySessionStorage();
15
+ * await storage.save("0x123...", sessionData);
16
+ * const session = await storage.load("0x123...");
17
+ * ```
18
+ */
19
+ declare class MemorySessionStorage implements ISessionStorage {
20
+ private sessions;
21
+ /**
22
+ * Save a session for an address.
23
+ */
24
+ save(address: string, session: PersistedSessionData): Promise<void>;
25
+ /**
26
+ * Load a session for an address.
27
+ */
28
+ load(address: string): Promise<PersistedSessionData | null>;
29
+ /**
30
+ * Clear a session for an address.
31
+ */
32
+ clear(address: string): Promise<void>;
33
+ /**
34
+ * Check if a session exists for an address.
35
+ */
36
+ exists(address: string): boolean;
37
+ /**
38
+ * Memory storage is always available.
39
+ */
40
+ isAvailable(): boolean;
41
+ /**
42
+ * Clear all sessions.
43
+ */
44
+ clearAll(): void;
45
+ /**
46
+ * Get the number of stored sessions.
47
+ */
48
+ size(): number;
49
+ }
50
+
51
+ /**
52
+ * File-based session storage for Node.js.
53
+ *
54
+ * Sessions are persisted to the file system and survive process restarts.
55
+ * Suitable for:
56
+ * - CLI applications
57
+ * - Long-running server processes
58
+ * - Development environments
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const storage = new FileSessionStorage("/tmp/tinycloud-sessions");
63
+ * await storage.save("0x123...", sessionData);
64
+ * // Session persists across process restarts
65
+ * ```
66
+ */
67
+ declare class FileSessionStorage implements ISessionStorage {
68
+ private readonly baseDir;
69
+ /**
70
+ * Create a new FileSessionStorage.
71
+ *
72
+ * @param baseDir - Directory to store session files (default: ~/.tinycloud/sessions)
73
+ */
74
+ constructor(baseDir?: string);
75
+ /**
76
+ * Get the default session storage directory.
77
+ */
78
+ private getDefaultDir;
79
+ /**
80
+ * Ensure the storage directory exists.
81
+ */
82
+ private ensureDirectoryExists;
83
+ /**
84
+ * Get the file path for an address.
85
+ */
86
+ private getFilePath;
87
+ /**
88
+ * Save a session for an address.
89
+ */
90
+ save(address: string, session: PersistedSessionData): Promise<void>;
91
+ /**
92
+ * Load a session for an address.
93
+ */
94
+ load(address: string): Promise<PersistedSessionData | null>;
95
+ /**
96
+ * Clear a session for an address.
97
+ */
98
+ clear(address: string): Promise<void>;
99
+ /**
100
+ * Check if a session exists for an address.
101
+ */
102
+ exists(address: string): boolean;
103
+ /**
104
+ * Check if file system storage is available.
105
+ */
106
+ isAvailable(): boolean;
107
+ }
108
+
109
+ /**
110
+ * WasmKeyProvider - KeyProvider implementation using WASM session manager.
111
+ *
112
+ * This provider wraps the SessionManager from node-sdk-wasm to provide
113
+ * cryptographic key operations required by the SharingService.
114
+ *
115
+ * @packageDocumentation
116
+ */
117
+
118
+ /**
119
+ * Extended session manager with optional key listing support.
120
+ * The base ISessionManager doesn't include listSessionKeys(),
121
+ * but concrete implementations (e.g., TCWSessionManager) may provide it.
122
+ */
123
+ interface SessionManagerWithListing extends ISessionManager {
124
+ listSessionKeys?(): string[];
125
+ }
126
+ /**
127
+ * Configuration for WasmKeyProvider.
128
+ */
129
+ interface WasmKeyProviderConfig {
130
+ /**
131
+ * The WASM session manager instance.
132
+ * Must be created before constructing the KeyProvider.
133
+ */
134
+ sessionManager: SessionManagerWithListing;
135
+ }
136
+ /**
137
+ * KeyProvider implementation that wraps the WASM session manager.
138
+ *
139
+ * This allows the SharingService to create new session keys for sharing links
140
+ * using the same cryptographic operations as the main session management.
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // sessionManager from wasmBindings.createSessionManager()
145
+ * import { WasmKeyProvider } from "@tinycloud/node-sdk";
146
+ *
147
+ * const sessionManager = new SessionManager();
148
+ * const keyProvider = new WasmKeyProvider({ sessionManager });
149
+ *
150
+ * // Create a session key for a sharing link
151
+ * const keyId = await keyProvider.createSessionKey("share:abc123");
152
+ * const jwk = keyProvider.getJWK(keyId);
153
+ * const did = await keyProvider.getDID(keyId);
154
+ * ```
155
+ */
156
+ declare class WasmKeyProvider implements KeyProvider {
157
+ private sessionManager;
158
+ /**
159
+ * Create a new WasmKeyProvider.
160
+ *
161
+ * @param config - Configuration with the WASM session manager
162
+ */
163
+ constructor(config: WasmKeyProviderConfig);
164
+ /**
165
+ * Generate a new session key with the given name.
166
+ *
167
+ * This creates a new Ed25519 key pair in the WASM session manager.
168
+ * The key can then be used for signing delegations in sharing links.
169
+ *
170
+ * @param name - A unique name/ID for the key (e.g., "share:timestamp:random")
171
+ * @returns The key ID (same as the name provided)
172
+ */
173
+ createSessionKey(name: string): Promise<string>;
174
+ /**
175
+ * Get the JWK (JSON Web Key) for a key.
176
+ *
177
+ * Returns the full JWK including the private key (d parameter),
178
+ * which is required for signing and for embedding in sharing links.
179
+ *
180
+ * @param keyId - The key ID to retrieve
181
+ * @returns The JWK object with public and private key components
182
+ * @throws Error if the key is not found
183
+ */
184
+ getJWK(keyId: string): JWK;
185
+ /**
186
+ * Get the DID (Decentralized Identifier) for a key.
187
+ *
188
+ * Returns the did:key format DID derived from the key's public key.
189
+ * This DID can be used as the delegatee in delegations.
190
+ *
191
+ * @param keyId - The key ID to retrieve
192
+ * @returns The DID in did:key format (e.g., "did:key:z6Mk...")
193
+ */
194
+ getDID(keyId: string): Promise<string>;
195
+ /**
196
+ * List all session keys currently held by the provider.
197
+ *
198
+ * @returns Array of key IDs
199
+ */
200
+ listKeys(): string[];
201
+ /**
202
+ * Check if a key exists in the provider.
203
+ *
204
+ * @param keyId - The key ID to check
205
+ * @returns True if the key exists
206
+ */
207
+ hasKey(keyId: string): boolean;
208
+ }
209
+ /**
210
+ * Create a new WasmKeyProvider instance.
211
+ *
212
+ * @param sessionManager - The WASM session manager
213
+ * @returns A new WasmKeyProvider instance
214
+ */
215
+ declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
216
+
217
+ export { FileSessionStorage as F, MemorySessionStorage as M, WasmKeyProvider as W, type WasmKeyProviderConfig as a, createWasmKeyProvider as c };
@@ -0,0 +1,217 @@
1
+ import { ISessionStorage, PersistedSessionData, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
+
3
+ /**
4
+ * In-memory session storage for Node.js.
5
+ *
6
+ * Sessions are stored in memory and lost when the process exits.
7
+ * Suitable for:
8
+ * - Development and testing
9
+ * - Stateless server deployments
10
+ * - Short-lived processes
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const storage = new MemorySessionStorage();
15
+ * await storage.save("0x123...", sessionData);
16
+ * const session = await storage.load("0x123...");
17
+ * ```
18
+ */
19
+ declare class MemorySessionStorage implements ISessionStorage {
20
+ private sessions;
21
+ /**
22
+ * Save a session for an address.
23
+ */
24
+ save(address: string, session: PersistedSessionData): Promise<void>;
25
+ /**
26
+ * Load a session for an address.
27
+ */
28
+ load(address: string): Promise<PersistedSessionData | null>;
29
+ /**
30
+ * Clear a session for an address.
31
+ */
32
+ clear(address: string): Promise<void>;
33
+ /**
34
+ * Check if a session exists for an address.
35
+ */
36
+ exists(address: string): boolean;
37
+ /**
38
+ * Memory storage is always available.
39
+ */
40
+ isAvailable(): boolean;
41
+ /**
42
+ * Clear all sessions.
43
+ */
44
+ clearAll(): void;
45
+ /**
46
+ * Get the number of stored sessions.
47
+ */
48
+ size(): number;
49
+ }
50
+
51
+ /**
52
+ * File-based session storage for Node.js.
53
+ *
54
+ * Sessions are persisted to the file system and survive process restarts.
55
+ * Suitable for:
56
+ * - CLI applications
57
+ * - Long-running server processes
58
+ * - Development environments
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const storage = new FileSessionStorage("/tmp/tinycloud-sessions");
63
+ * await storage.save("0x123...", sessionData);
64
+ * // Session persists across process restarts
65
+ * ```
66
+ */
67
+ declare class FileSessionStorage implements ISessionStorage {
68
+ private readonly baseDir;
69
+ /**
70
+ * Create a new FileSessionStorage.
71
+ *
72
+ * @param baseDir - Directory to store session files (default: ~/.tinycloud/sessions)
73
+ */
74
+ constructor(baseDir?: string);
75
+ /**
76
+ * Get the default session storage directory.
77
+ */
78
+ private getDefaultDir;
79
+ /**
80
+ * Ensure the storage directory exists.
81
+ */
82
+ private ensureDirectoryExists;
83
+ /**
84
+ * Get the file path for an address.
85
+ */
86
+ private getFilePath;
87
+ /**
88
+ * Save a session for an address.
89
+ */
90
+ save(address: string, session: PersistedSessionData): Promise<void>;
91
+ /**
92
+ * Load a session for an address.
93
+ */
94
+ load(address: string): Promise<PersistedSessionData | null>;
95
+ /**
96
+ * Clear a session for an address.
97
+ */
98
+ clear(address: string): Promise<void>;
99
+ /**
100
+ * Check if a session exists for an address.
101
+ */
102
+ exists(address: string): boolean;
103
+ /**
104
+ * Check if file system storage is available.
105
+ */
106
+ isAvailable(): boolean;
107
+ }
108
+
109
+ /**
110
+ * WasmKeyProvider - KeyProvider implementation using WASM session manager.
111
+ *
112
+ * This provider wraps the SessionManager from node-sdk-wasm to provide
113
+ * cryptographic key operations required by the SharingService.
114
+ *
115
+ * @packageDocumentation
116
+ */
117
+
118
+ /**
119
+ * Extended session manager with optional key listing support.
120
+ * The base ISessionManager doesn't include listSessionKeys(),
121
+ * but concrete implementations (e.g., TCWSessionManager) may provide it.
122
+ */
123
+ interface SessionManagerWithListing extends ISessionManager {
124
+ listSessionKeys?(): string[];
125
+ }
126
+ /**
127
+ * Configuration for WasmKeyProvider.
128
+ */
129
+ interface WasmKeyProviderConfig {
130
+ /**
131
+ * The WASM session manager instance.
132
+ * Must be created before constructing the KeyProvider.
133
+ */
134
+ sessionManager: SessionManagerWithListing;
135
+ }
136
+ /**
137
+ * KeyProvider implementation that wraps the WASM session manager.
138
+ *
139
+ * This allows the SharingService to create new session keys for sharing links
140
+ * using the same cryptographic operations as the main session management.
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // sessionManager from wasmBindings.createSessionManager()
145
+ * import { WasmKeyProvider } from "@tinycloud/node-sdk";
146
+ *
147
+ * const sessionManager = new SessionManager();
148
+ * const keyProvider = new WasmKeyProvider({ sessionManager });
149
+ *
150
+ * // Create a session key for a sharing link
151
+ * const keyId = await keyProvider.createSessionKey("share:abc123");
152
+ * const jwk = keyProvider.getJWK(keyId);
153
+ * const did = await keyProvider.getDID(keyId);
154
+ * ```
155
+ */
156
+ declare class WasmKeyProvider implements KeyProvider {
157
+ private sessionManager;
158
+ /**
159
+ * Create a new WasmKeyProvider.
160
+ *
161
+ * @param config - Configuration with the WASM session manager
162
+ */
163
+ constructor(config: WasmKeyProviderConfig);
164
+ /**
165
+ * Generate a new session key with the given name.
166
+ *
167
+ * This creates a new Ed25519 key pair in the WASM session manager.
168
+ * The key can then be used for signing delegations in sharing links.
169
+ *
170
+ * @param name - A unique name/ID for the key (e.g., "share:timestamp:random")
171
+ * @returns The key ID (same as the name provided)
172
+ */
173
+ createSessionKey(name: string): Promise<string>;
174
+ /**
175
+ * Get the JWK (JSON Web Key) for a key.
176
+ *
177
+ * Returns the full JWK including the private key (d parameter),
178
+ * which is required for signing and for embedding in sharing links.
179
+ *
180
+ * @param keyId - The key ID to retrieve
181
+ * @returns The JWK object with public and private key components
182
+ * @throws Error if the key is not found
183
+ */
184
+ getJWK(keyId: string): JWK;
185
+ /**
186
+ * Get the DID (Decentralized Identifier) for a key.
187
+ *
188
+ * Returns the did:key format DID derived from the key's public key.
189
+ * This DID can be used as the delegatee in delegations.
190
+ *
191
+ * @param keyId - The key ID to retrieve
192
+ * @returns The DID in did:key format (e.g., "did:key:z6Mk...")
193
+ */
194
+ getDID(keyId: string): Promise<string>;
195
+ /**
196
+ * List all session keys currently held by the provider.
197
+ *
198
+ * @returns Array of key IDs
199
+ */
200
+ listKeys(): string[];
201
+ /**
202
+ * Check if a key exists in the provider.
203
+ *
204
+ * @param keyId - The key ID to check
205
+ * @returns True if the key exists
206
+ */
207
+ hasKey(keyId: string): boolean;
208
+ }
209
+ /**
210
+ * Create a new WasmKeyProvider instance.
211
+ *
212
+ * @param sessionManager - The WASM session manager
213
+ * @returns A new WasmKeyProvider instance
214
+ */
215
+ declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
216
+
217
+ export { FileSessionStorage as F, MemorySessionStorage as M, WasmKeyProvider as W, type WasmKeyProviderConfig as a, createWasmKeyProvider as c };
@@ -0,0 +1,118 @@
1
+ import { ReplicationOptions, PermissionEntry, TinyCloudSession, KVReplicaStorage, ServiceContext, IWasmBindings, WasmRecapEntry } from '@tinycloud/sdk-core';
2
+ import { ReplicaConsentAnchor, AuthorityRefusal, ReplicationAuthority } from '@tinycloud/sdk-services';
3
+ import { ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-CcNh20QX.cjs';
5
+
6
+ /** Constructor-time validation; the space-dependent secrets check runs at sign-in and open. */
7
+ declare function assertValidReplicationConfig(replication: (ReplicationOptions & {
8
+ storage?: unknown;
9
+ }) | undefined): void;
10
+
11
+ declare function hasUnrestrictedGetCoverage(entries: readonly PermissionEntry[], spaceId: string, prefix: string): boolean;
12
+ declare function augmentSignInEntriesWithReplication(input: {
13
+ entries: readonly PermissionEntry[];
14
+ primarySpaceId: string;
15
+ replication?: Pick<ReplicationOptions, "prefixes" | "allowSecrets">;
16
+ }): PermissionEntry[];
17
+
18
+ /** Report a completed deny from the already-loaded authority; delivery was revoked synchronously. */
19
+ declare function reportReplicaDenial(result: {
20
+ status: string;
21
+ code?: string;
22
+ intents?: number;
23
+ }, reason: ReplicaDenyInput["reason"], onEvent: ReplicationOptions["onEvent"], context?: ServiceContext): void;
24
+ /** The verified owner proof is signed, finite, exact-space, and uncaveated on one get+sync scope. */
25
+ declare function verifiedOwnerConsentAnchor(session: TinyCloudSession, wasmBindings: Pick<IWasmBindings, "validatePersistedSession">, exactVerifiedRecap: (verified: {
26
+ verifiedRecap?: unknown;
27
+ }) => WasmRecapEntry[]): ReplicaConsentAnchor | null;
28
+ /** Fresh sign-in only: the lifecycle creates keys; restore never calls this. */
29
+ declare function establishReplicaSessionStamp(storage: KVReplicaStorage, principal: string, anchor: ReplicaConsentAnchor): Promise<ReplicaSessionStamp>;
30
+ /** Existing persisted stamp only: never manufactures an authority on restore. */
31
+ declare function restoreReplicaSessionStamp(storage: KVReplicaStorage, principal: string, persisted: ReplicaSessionStamp | undefined): Promise<ReplicaSessionStamp>;
32
+ /**
33
+ * Whether the signed `att` grants `ability` over the folder prefix, with
34
+ * unrestricted authority unless explicitly asked to ignore caveats.
35
+ */
36
+ declare function ucanAttCovers(att: Record<string, Record<string, unknown>>, space: string, prefix: string, ability: string, options?: {
37
+ ignoreCaveats?: boolean;
38
+ }): boolean;
39
+ /** `unconstrained` for `ReplicaGrantInfo` (§2.1): get AND sync on the prefix carry no caveats. */
40
+ declare function ucanAttUnconstrainedFor(att: Record<string, Record<string, unknown>>, space: string, prefix: string): boolean;
41
+ interface DelegationPlanResult {
42
+ path: "session" | "runtime";
43
+ parentCid: string;
44
+ expiresAt: number;
45
+ }
46
+ /**
47
+ * The `TinyCloudNode` internals the authority needs. `planDelegation` is the
48
+ * pure extraction of `delegateTo`'s parent selection (§4.3), so `plan` and
49
+ * `mint` can never disagree about which parent or expiry a delegation gets.
50
+ */
51
+ type ReplicationAuthoritySession = Pick<TinyCloudSession, "delegationHeader" | "delegationCid" | "spaceId" | "verificationMethod" | "jwk"> & Partial<Pick<TinyCloudSession, "siwe" | "signature" | "address" | "chainId">>;
52
+ interface ReplicationAuthorityHost {
53
+ replicationSession(): ReplicationAuthoritySession | undefined;
54
+ /** Validated owner proof only; never infer consent from a compact child UCAN. */
55
+ verifiedConsentAnchor?(session: ReplicationAuthoritySession): ReplicaConsentAnchor | null;
56
+ /** The SIWE "Expiration Time" of the session — the delegateTo delegation cap. */
57
+ siweExpiration(siwe: string): Date | undefined;
58
+ planDelegation(entries: PermissionEntry[], options?: {
59
+ expiry?: string | number;
60
+ }): ({
61
+ grant?: unknown;
62
+ } & DelegationPlanResult) | AuthorityRefusal;
63
+ mintDelegation(deviceDid: string, entries: PermissionEntry[], options?: {
64
+ expiryMs?: number;
65
+ renewalOnly?: boolean;
66
+ }): Promise<{
67
+ ucan: string;
68
+ expiresAt: number;
69
+ }>;
70
+ }
71
+ /** Delegate a replica grant only through the selected owner parent for silent renewal. */
72
+ declare function mintNodeReplicationGrant(deviceDid: string, entries: PermissionEntry[], options: {
73
+ expiryMs?: number;
74
+ renewalOnly?: boolean;
75
+ } | undefined, renewalSession: ReplicationAuthoritySession | undefined, node: Pick<TinyCloudNode, "delegateTo">): Promise<{
76
+ ucan: string;
77
+ expiresAt: number;
78
+ }>;
79
+ /** Milliseconds of validity a session or parent must have left for authority reuse (delegateTo's margin). */
80
+ declare const AUTHORITY_EXPIRY_MARGIN_MS = 60000;
81
+ /** Verify a compact session delegation before using any persisted space metadata. */
82
+ declare function replicationScopeFromSignedSession(input: {
83
+ delegationHeader: {
84
+ Authorization: string;
85
+ };
86
+ delegationCid: string;
87
+ verificationMethod: string;
88
+ persistedSpace: string;
89
+ }): {
90
+ space: string;
91
+ principal: string;
92
+ } | undefined;
93
+ /** Runs before host activation; a replan cannot silently switch a renewal to a runtime parent. */
94
+ declare function assertRenewalParent(authorization: string, session: ReplicationAuthoritySession): void;
95
+ declare function createReplicationAuthority(host: ReplicationAuthorityHost): ReplicationAuthority;
96
+
97
+ declare const __authority_AUTHORITY_EXPIRY_MARGIN_MS: typeof AUTHORITY_EXPIRY_MARGIN_MS;
98
+ type __authority_DelegationPlanResult = DelegationPlanResult;
99
+ type __authority_ReplicationAuthorityHost = ReplicationAuthorityHost;
100
+ type __authority_ReplicationAuthoritySession = ReplicationAuthoritySession;
101
+ declare const __authority_assertRenewalParent: typeof assertRenewalParent;
102
+ declare const __authority_assertValidReplicationConfig: typeof assertValidReplicationConfig;
103
+ declare const __authority_augmentSignInEntriesWithReplication: typeof augmentSignInEntriesWithReplication;
104
+ declare const __authority_createReplicationAuthority: typeof createReplicationAuthority;
105
+ declare const __authority_establishReplicaSessionStamp: typeof establishReplicaSessionStamp;
106
+ declare const __authority_hasUnrestrictedGetCoverage: typeof hasUnrestrictedGetCoverage;
107
+ declare const __authority_mintNodeReplicationGrant: typeof mintNodeReplicationGrant;
108
+ declare const __authority_replicationScopeFromSignedSession: typeof replicationScopeFromSignedSession;
109
+ declare const __authority_reportReplicaDenial: typeof reportReplicaDenial;
110
+ declare const __authority_restoreReplicaSessionStamp: typeof restoreReplicaSessionStamp;
111
+ declare const __authority_ucanAttCovers: typeof ucanAttCovers;
112
+ declare const __authority_ucanAttUnconstrainedFor: typeof ucanAttUnconstrainedFor;
113
+ declare const __authority_verifiedOwnerConsentAnchor: typeof verifiedOwnerConsentAnchor;
114
+ declare namespace __authority {
115
+ export { __authority_AUTHORITY_EXPIRY_MARGIN_MS as AUTHORITY_EXPIRY_MARGIN_MS, type __authority_DelegationPlanResult as DelegationPlanResult, type __authority_ReplicationAuthorityHost as ReplicationAuthorityHost, type __authority_ReplicationAuthoritySession as ReplicationAuthoritySession, __authority_assertRenewalParent as assertRenewalParent, __authority_assertValidReplicationConfig as assertValidReplicationConfig, __authority_augmentSignInEntriesWithReplication as augmentSignInEntriesWithReplication, __authority_createReplicationAuthority as createReplicationAuthority, __authority_establishReplicaSessionStamp as establishReplicaSessionStamp, __authority_hasUnrestrictedGetCoverage as hasUnrestrictedGetCoverage, __authority_mintNodeReplicationGrant as mintNodeReplicationGrant, __authority_replicationScopeFromSignedSession as replicationScopeFromSignedSession, __authority_reportReplicaDenial as reportReplicaDenial, __authority_restoreReplicaSessionStamp as restoreReplicaSessionStamp, __authority_ucanAttCovers as ucanAttCovers, __authority_ucanAttUnconstrainedFor as ucanAttUnconstrainedFor, __authority_verifiedOwnerConsentAnchor as verifiedOwnerConsentAnchor };
116
+ }
117
+
118
+ export { AUTHORITY_EXPIRY_MARGIN_MS as A, type DelegationPlanResult as D, type ReplicationAuthorityHost as R, __authority as _, type ReplicationAuthoritySession as a, assertRenewalParent as b, assertValidReplicationConfig as c, augmentSignInEntriesWithReplication as d, createReplicationAuthority as e, establishReplicaSessionStamp as f, reportReplicaDenial as g, hasUnrestrictedGetCoverage as h, restoreReplicaSessionStamp as i, ucanAttUnconstrainedFor as j, mintNodeReplicationGrant as m, replicationScopeFromSignedSession as r, ucanAttCovers as u, verifiedOwnerConsentAnchor as v };
@@ -0,0 +1,118 @@
1
+ import { ReplicationOptions, PermissionEntry, TinyCloudSession, KVReplicaStorage, ServiceContext, IWasmBindings, WasmRecapEntry } from '@tinycloud/sdk-core';
2
+ import { ReplicaConsentAnchor, AuthorityRefusal, ReplicationAuthority } from '@tinycloud/sdk-services';
3
+ import { ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-CcNh20QX.js';
5
+
6
+ /** Constructor-time validation; the space-dependent secrets check runs at sign-in and open. */
7
+ declare function assertValidReplicationConfig(replication: (ReplicationOptions & {
8
+ storage?: unknown;
9
+ }) | undefined): void;
10
+
11
+ declare function hasUnrestrictedGetCoverage(entries: readonly PermissionEntry[], spaceId: string, prefix: string): boolean;
12
+ declare function augmentSignInEntriesWithReplication(input: {
13
+ entries: readonly PermissionEntry[];
14
+ primarySpaceId: string;
15
+ replication?: Pick<ReplicationOptions, "prefixes" | "allowSecrets">;
16
+ }): PermissionEntry[];
17
+
18
+ /** Report a completed deny from the already-loaded authority; delivery was revoked synchronously. */
19
+ declare function reportReplicaDenial(result: {
20
+ status: string;
21
+ code?: string;
22
+ intents?: number;
23
+ }, reason: ReplicaDenyInput["reason"], onEvent: ReplicationOptions["onEvent"], context?: ServiceContext): void;
24
+ /** The verified owner proof is signed, finite, exact-space, and uncaveated on one get+sync scope. */
25
+ declare function verifiedOwnerConsentAnchor(session: TinyCloudSession, wasmBindings: Pick<IWasmBindings, "validatePersistedSession">, exactVerifiedRecap: (verified: {
26
+ verifiedRecap?: unknown;
27
+ }) => WasmRecapEntry[]): ReplicaConsentAnchor | null;
28
+ /** Fresh sign-in only: the lifecycle creates keys; restore never calls this. */
29
+ declare function establishReplicaSessionStamp(storage: KVReplicaStorage, principal: string, anchor: ReplicaConsentAnchor): Promise<ReplicaSessionStamp>;
30
+ /** Existing persisted stamp only: never manufactures an authority on restore. */
31
+ declare function restoreReplicaSessionStamp(storage: KVReplicaStorage, principal: string, persisted: ReplicaSessionStamp | undefined): Promise<ReplicaSessionStamp>;
32
+ /**
33
+ * Whether the signed `att` grants `ability` over the folder prefix, with
34
+ * unrestricted authority unless explicitly asked to ignore caveats.
35
+ */
36
+ declare function ucanAttCovers(att: Record<string, Record<string, unknown>>, space: string, prefix: string, ability: string, options?: {
37
+ ignoreCaveats?: boolean;
38
+ }): boolean;
39
+ /** `unconstrained` for `ReplicaGrantInfo` (§2.1): get AND sync on the prefix carry no caveats. */
40
+ declare function ucanAttUnconstrainedFor(att: Record<string, Record<string, unknown>>, space: string, prefix: string): boolean;
41
+ interface DelegationPlanResult {
42
+ path: "session" | "runtime";
43
+ parentCid: string;
44
+ expiresAt: number;
45
+ }
46
+ /**
47
+ * The `TinyCloudNode` internals the authority needs. `planDelegation` is the
48
+ * pure extraction of `delegateTo`'s parent selection (§4.3), so `plan` and
49
+ * `mint` can never disagree about which parent or expiry a delegation gets.
50
+ */
51
+ type ReplicationAuthoritySession = Pick<TinyCloudSession, "delegationHeader" | "delegationCid" | "spaceId" | "verificationMethod" | "jwk"> & Partial<Pick<TinyCloudSession, "siwe" | "signature" | "address" | "chainId">>;
52
+ interface ReplicationAuthorityHost {
53
+ replicationSession(): ReplicationAuthoritySession | undefined;
54
+ /** Validated owner proof only; never infer consent from a compact child UCAN. */
55
+ verifiedConsentAnchor?(session: ReplicationAuthoritySession): ReplicaConsentAnchor | null;
56
+ /** The SIWE "Expiration Time" of the session — the delegateTo delegation cap. */
57
+ siweExpiration(siwe: string): Date | undefined;
58
+ planDelegation(entries: PermissionEntry[], options?: {
59
+ expiry?: string | number;
60
+ }): ({
61
+ grant?: unknown;
62
+ } & DelegationPlanResult) | AuthorityRefusal;
63
+ mintDelegation(deviceDid: string, entries: PermissionEntry[], options?: {
64
+ expiryMs?: number;
65
+ renewalOnly?: boolean;
66
+ }): Promise<{
67
+ ucan: string;
68
+ expiresAt: number;
69
+ }>;
70
+ }
71
+ /** Delegate a replica grant only through the selected owner parent for silent renewal. */
72
+ declare function mintNodeReplicationGrant(deviceDid: string, entries: PermissionEntry[], options: {
73
+ expiryMs?: number;
74
+ renewalOnly?: boolean;
75
+ } | undefined, renewalSession: ReplicationAuthoritySession | undefined, node: Pick<TinyCloudNode, "delegateTo">): Promise<{
76
+ ucan: string;
77
+ expiresAt: number;
78
+ }>;
79
+ /** Milliseconds of validity a session or parent must have left for authority reuse (delegateTo's margin). */
80
+ declare const AUTHORITY_EXPIRY_MARGIN_MS = 60000;
81
+ /** Verify a compact session delegation before using any persisted space metadata. */
82
+ declare function replicationScopeFromSignedSession(input: {
83
+ delegationHeader: {
84
+ Authorization: string;
85
+ };
86
+ delegationCid: string;
87
+ verificationMethod: string;
88
+ persistedSpace: string;
89
+ }): {
90
+ space: string;
91
+ principal: string;
92
+ } | undefined;
93
+ /** Runs before host activation; a replan cannot silently switch a renewal to a runtime parent. */
94
+ declare function assertRenewalParent(authorization: string, session: ReplicationAuthoritySession): void;
95
+ declare function createReplicationAuthority(host: ReplicationAuthorityHost): ReplicationAuthority;
96
+
97
+ declare const __authority_AUTHORITY_EXPIRY_MARGIN_MS: typeof AUTHORITY_EXPIRY_MARGIN_MS;
98
+ type __authority_DelegationPlanResult = DelegationPlanResult;
99
+ type __authority_ReplicationAuthorityHost = ReplicationAuthorityHost;
100
+ type __authority_ReplicationAuthoritySession = ReplicationAuthoritySession;
101
+ declare const __authority_assertRenewalParent: typeof assertRenewalParent;
102
+ declare const __authority_assertValidReplicationConfig: typeof assertValidReplicationConfig;
103
+ declare const __authority_augmentSignInEntriesWithReplication: typeof augmentSignInEntriesWithReplication;
104
+ declare const __authority_createReplicationAuthority: typeof createReplicationAuthority;
105
+ declare const __authority_establishReplicaSessionStamp: typeof establishReplicaSessionStamp;
106
+ declare const __authority_hasUnrestrictedGetCoverage: typeof hasUnrestrictedGetCoverage;
107
+ declare const __authority_mintNodeReplicationGrant: typeof mintNodeReplicationGrant;
108
+ declare const __authority_replicationScopeFromSignedSession: typeof replicationScopeFromSignedSession;
109
+ declare const __authority_reportReplicaDenial: typeof reportReplicaDenial;
110
+ declare const __authority_restoreReplicaSessionStamp: typeof restoreReplicaSessionStamp;
111
+ declare const __authority_ucanAttCovers: typeof ucanAttCovers;
112
+ declare const __authority_ucanAttUnconstrainedFor: typeof ucanAttUnconstrainedFor;
113
+ declare const __authority_verifiedOwnerConsentAnchor: typeof verifiedOwnerConsentAnchor;
114
+ declare namespace __authority {
115
+ export { __authority_AUTHORITY_EXPIRY_MARGIN_MS as AUTHORITY_EXPIRY_MARGIN_MS, type __authority_DelegationPlanResult as DelegationPlanResult, type __authority_ReplicationAuthorityHost as ReplicationAuthorityHost, type __authority_ReplicationAuthoritySession as ReplicationAuthoritySession, __authority_assertRenewalParent as assertRenewalParent, __authority_assertValidReplicationConfig as assertValidReplicationConfig, __authority_augmentSignInEntriesWithReplication as augmentSignInEntriesWithReplication, __authority_createReplicationAuthority as createReplicationAuthority, __authority_establishReplicaSessionStamp as establishReplicaSessionStamp, __authority_hasUnrestrictedGetCoverage as hasUnrestrictedGetCoverage, __authority_mintNodeReplicationGrant as mintNodeReplicationGrant, __authority_replicationScopeFromSignedSession as replicationScopeFromSignedSession, __authority_reportReplicaDenial as reportReplicaDenial, __authority_restoreReplicaSessionStamp as restoreReplicaSessionStamp, __authority_ucanAttCovers as ucanAttCovers, __authority_ucanAttUnconstrainedFor as ucanAttUnconstrainedFor, __authority_verifiedOwnerConsentAnchor as verifiedOwnerConsentAnchor };
116
+ }
117
+
118
+ export { AUTHORITY_EXPIRY_MARGIN_MS as A, type DelegationPlanResult as D, type ReplicationAuthorityHost as R, __authority as _, type ReplicationAuthoritySession as a, assertRenewalParent as b, assertValidReplicationConfig as c, augmentSignInEntriesWithReplication as d, createReplicationAuthority as e, establishReplicaSessionStamp as f, reportReplicaDenial as g, hasUnrestrictedGetCoverage as h, restoreReplicaSessionStamp as i, ucanAttUnconstrainedFor as j, mintNodeReplicationGrant as m, replicationScopeFromSignedSession as r, ucanAttCovers as u, verifiedOwnerConsentAnchor as v };