@tinycloud/node-sdk 3.8.0-beta.10 → 3.8.0-beta.13
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/{TinyCloudNode-Dy65bxqs.d.cts → TinyCloudNode-BVDUdEcf.d.cts} +27 -2
- package/dist/{TinyCloudNode-DnD-SH6t.d.ts → TinyCloudNode-jMK_2Uj8.d.ts} +27 -2
- package/dist/{WasmKeyProvider-5Ee7fcAw.d.cts → WasmKeyProvider-BKCPRC-c.d.cts} +21 -1
- package/dist/{WasmKeyProvider-5Ee7fcAw.d.ts → WasmKeyProvider-BKCPRC-c.d.ts} +21 -1
- package/dist/{authority-Rbye1U4o.d.cts → authority-DJ-PE4Xo.d.cts} +1 -1
- package/dist/{authority-BQnTX3fI.d.ts → authority-i22vHbbp.d.ts} +1 -1
- package/dist/core.cjs +125 -7
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +122 -6
- package/dist/core.js.map +1 -1
- package/dist/encryption-keys.d.cts +1 -1
- package/dist/encryption-keys.d.ts +1 -1
- package/dist/index.cjs +79 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +78 -7
- package/dist/index.js.map +1 -1
- package/dist/replication/authority.d.cts +2 -2
- package/dist/replication/authority.d.ts +2 -2
- package/package.json +1 -1
|
@@ -81,6 +81,8 @@ interface OpenKeyAuthorizeTinyCloud {
|
|
|
81
81
|
* validates and size-bounds it before use.
|
|
82
82
|
*/
|
|
83
83
|
presentation?: CapabilityPresentationEnvelopeV1;
|
|
84
|
+
}, opts?: {
|
|
85
|
+
mode?: "iframe" | "popup" | "redirect";
|
|
84
86
|
}): Promise<{
|
|
85
87
|
protocolVersion: 1;
|
|
86
88
|
address: string;
|
|
@@ -143,9 +145,22 @@ type NodeUserAuthorizationAuthorizeFn = (input: OpenKeyBridgeInput) => Promise<{
|
|
|
143
145
|
* const clientSession = await nodeAuth.signInWithOpenKey(authorize);
|
|
144
146
|
* ```
|
|
145
147
|
*/
|
|
146
|
-
declare function wireOpenKeyAuthorize(openkey: OpenKeyAuthorizeTinyCloud
|
|
148
|
+
declare function wireOpenKeyAuthorize(openkey: OpenKeyAuthorizeTinyCloud, opts?: {
|
|
149
|
+
mode?: "iframe" | "popup" | "redirect";
|
|
150
|
+
}): NodeUserAuthorizationAuthorizeFn;
|
|
147
151
|
|
|
148
152
|
type OpenKeyAuthorizeInput = OpenKeyBridgeInput;
|
|
153
|
+
/** SIWE and session key prepared before an OpenKey approval click. */
|
|
154
|
+
interface PreparedOpenKeyAuthorization {
|
|
155
|
+
readonly request: OpenKeyAuthorizeInput;
|
|
156
|
+
readonly prepared: PreparedOpenKeySession;
|
|
157
|
+
readonly keyId: string;
|
|
158
|
+
readonly jwk: Record<string, unknown>;
|
|
159
|
+
readonly address: string;
|
|
160
|
+
readonly chainId: number;
|
|
161
|
+
readonly generation: number;
|
|
162
|
+
readonly createdAt: number;
|
|
163
|
+
}
|
|
149
164
|
type OpenKeyAuthorizationResultV1 = Awaited<ReturnType<NodeUserAuthorizationAuthorizeFn>>;
|
|
150
165
|
type PreparedOpenKeySession = {
|
|
151
166
|
siwe: string;
|
|
@@ -366,6 +381,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
366
381
|
private readonly includeAccountRegistryPermissions;
|
|
367
382
|
private sessionManager;
|
|
368
383
|
private activeSessionKeyId;
|
|
384
|
+
private preparedSessionCounter;
|
|
369
385
|
/** Incremented by resetSession; a sign-in started earlier publishes nothing. */
|
|
370
386
|
private sessionGeneration;
|
|
371
387
|
/**
|
|
@@ -738,6 +754,10 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
738
754
|
*/
|
|
739
755
|
retryResult?: (error: Error, originalRequest: OpenKeyAuthorizeInput, attempt: number) => Promise<OpenKeyAuthorizationResultV1 | null>;
|
|
740
756
|
}): Promise<ClientSession>;
|
|
757
|
+
/** Finish address, host and SIWE preparation before an approval click. */
|
|
758
|
+
prepareOpenKeySignIn(options?: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[1]): Promise<PreparedOpenKeyAuthorization>;
|
|
759
|
+
/** Complete a prepared approval. The caller starts authorization before awaiting this method. */
|
|
760
|
+
completeOpenKeySignIn(pending: PreparedOpenKeyAuthorization, authorization: Promise<OpenKeyAuthorizationResultV1>, options?: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[1]): Promise<ClientSession>;
|
|
741
761
|
/**
|
|
742
762
|
* Build a `CapabilityPresentationEnvelopeV1` from `this._manifest`. The
|
|
743
763
|
* envelope is display-only — the OpenKey widget renders it under an
|
|
@@ -1280,6 +1300,7 @@ declare class TinyCloudNode {
|
|
|
1280
1300
|
private readonly explicitHost?;
|
|
1281
1301
|
private signer;
|
|
1282
1302
|
private auth;
|
|
1303
|
+
private readonly consumedOpenKeyPendings;
|
|
1283
1304
|
private tc;
|
|
1284
1305
|
private _address?;
|
|
1285
1306
|
private _chainId;
|
|
@@ -1656,6 +1677,10 @@ declare class TinyCloudNode {
|
|
|
1656
1677
|
* bytes before the network session or replica stamp is committed.
|
|
1657
1678
|
*/
|
|
1658
1679
|
signInWithOpenKey(authorizeFn: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[0], options?: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[1]): Promise<void>;
|
|
1680
|
+
/** Prepare the OpenKey request before the approval click. */
|
|
1681
|
+
prepareOpenKeySignIn(): Promise<PreparedOpenKeyAuthorization>;
|
|
1682
|
+
/** Start OpenKey authorization synchronously, then complete normal session setup. */
|
|
1683
|
+
signInWithPreparedOpenKey(pending: PreparedOpenKeyAuthorization, authorizeFn: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[0]): Promise<void>;
|
|
1659
1684
|
private signInWith;
|
|
1660
1685
|
private establishSignIn;
|
|
1661
1686
|
/**
|
|
@@ -2708,4 +2733,4 @@ declare class TinyCloudNode {
|
|
|
2708
2733
|
}): Promise<PortableDelegation>;
|
|
2709
2734
|
}
|
|
2710
2735
|
|
|
2711
|
-
export { ACCEPTED_MARKER_VERSIONS as A, type BootstrapWarning as B, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, InvalidRestoredSessionError as I, type NodeEventEmitterStrategy as N, type
|
|
2736
|
+
export { ACCEPTED_MARKER_VERSIONS as A, type BootstrapWarning as B, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, InvalidRestoredSessionError as I, type NodeEventEmitterStrategy as N, type OpenKeyAuthorizeTinyCloud as O, type PreparedOpenKeyAuthorization as P, type RuntimePermissionGrantOptions as R, type SecretPermissionHint as S, TinyCloudNode as T, type UnifiedOwnerRootInput as U, type DelegateToResult as a, DelegatedAccess as b, NodeUserAuthorization as c, type NodeUserAuthorizationConfig as d, type OwnerDelegationReceipt as e, type SecretReadInput as f, type SecretReadResult as g, type SignStrategy as h, type TinyCloudNodeConfig as i, type UnifiedOwnerRootReceipt as j, UnsupportedSessionRestoreError as k, defaultSignStrategy as l, BOOTSTRAP_COMPLETION_MARKER_KEY as m, BOOTSTRAP_COMPLETION_MARKER_VERSION as n, type BootstrapCompletionMarker as o, type NodeUserAuthorizationAuthorizeFn as p, type OpenKeyAuthorizationResultV1 as q, type OpenKeyAuthorizeInput as r, type OpenKeyBridgeInput as s, type RestorableSession as t, wireOpenKeyAuthorize as w };
|
|
@@ -81,6 +81,8 @@ interface OpenKeyAuthorizeTinyCloud {
|
|
|
81
81
|
* validates and size-bounds it before use.
|
|
82
82
|
*/
|
|
83
83
|
presentation?: CapabilityPresentationEnvelopeV1;
|
|
84
|
+
}, opts?: {
|
|
85
|
+
mode?: "iframe" | "popup" | "redirect";
|
|
84
86
|
}): Promise<{
|
|
85
87
|
protocolVersion: 1;
|
|
86
88
|
address: string;
|
|
@@ -143,9 +145,22 @@ type NodeUserAuthorizationAuthorizeFn = (input: OpenKeyBridgeInput) => Promise<{
|
|
|
143
145
|
* const clientSession = await nodeAuth.signInWithOpenKey(authorize);
|
|
144
146
|
* ```
|
|
145
147
|
*/
|
|
146
|
-
declare function wireOpenKeyAuthorize(openkey: OpenKeyAuthorizeTinyCloud
|
|
148
|
+
declare function wireOpenKeyAuthorize(openkey: OpenKeyAuthorizeTinyCloud, opts?: {
|
|
149
|
+
mode?: "iframe" | "popup" | "redirect";
|
|
150
|
+
}): NodeUserAuthorizationAuthorizeFn;
|
|
147
151
|
|
|
148
152
|
type OpenKeyAuthorizeInput = OpenKeyBridgeInput;
|
|
153
|
+
/** SIWE and session key prepared before an OpenKey approval click. */
|
|
154
|
+
interface PreparedOpenKeyAuthorization {
|
|
155
|
+
readonly request: OpenKeyAuthorizeInput;
|
|
156
|
+
readonly prepared: PreparedOpenKeySession;
|
|
157
|
+
readonly keyId: string;
|
|
158
|
+
readonly jwk: Record<string, unknown>;
|
|
159
|
+
readonly address: string;
|
|
160
|
+
readonly chainId: number;
|
|
161
|
+
readonly generation: number;
|
|
162
|
+
readonly createdAt: number;
|
|
163
|
+
}
|
|
149
164
|
type OpenKeyAuthorizationResultV1 = Awaited<ReturnType<NodeUserAuthorizationAuthorizeFn>>;
|
|
150
165
|
type PreparedOpenKeySession = {
|
|
151
166
|
siwe: string;
|
|
@@ -366,6 +381,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
366
381
|
private readonly includeAccountRegistryPermissions;
|
|
367
382
|
private sessionManager;
|
|
368
383
|
private activeSessionKeyId;
|
|
384
|
+
private preparedSessionCounter;
|
|
369
385
|
/** Incremented by resetSession; a sign-in started earlier publishes nothing. */
|
|
370
386
|
private sessionGeneration;
|
|
371
387
|
/**
|
|
@@ -738,6 +754,10 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
738
754
|
*/
|
|
739
755
|
retryResult?: (error: Error, originalRequest: OpenKeyAuthorizeInput, attempt: number) => Promise<OpenKeyAuthorizationResultV1 | null>;
|
|
740
756
|
}): Promise<ClientSession>;
|
|
757
|
+
/** Finish address, host and SIWE preparation before an approval click. */
|
|
758
|
+
prepareOpenKeySignIn(options?: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[1]): Promise<PreparedOpenKeyAuthorization>;
|
|
759
|
+
/** Complete a prepared approval. The caller starts authorization before awaiting this method. */
|
|
760
|
+
completeOpenKeySignIn(pending: PreparedOpenKeyAuthorization, authorization: Promise<OpenKeyAuthorizationResultV1>, options?: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[1]): Promise<ClientSession>;
|
|
741
761
|
/**
|
|
742
762
|
* Build a `CapabilityPresentationEnvelopeV1` from `this._manifest`. The
|
|
743
763
|
* envelope is display-only — the OpenKey widget renders it under an
|
|
@@ -1280,6 +1300,7 @@ declare class TinyCloudNode {
|
|
|
1280
1300
|
private readonly explicitHost?;
|
|
1281
1301
|
private signer;
|
|
1282
1302
|
private auth;
|
|
1303
|
+
private readonly consumedOpenKeyPendings;
|
|
1283
1304
|
private tc;
|
|
1284
1305
|
private _address?;
|
|
1285
1306
|
private _chainId;
|
|
@@ -1656,6 +1677,10 @@ declare class TinyCloudNode {
|
|
|
1656
1677
|
* bytes before the network session or replica stamp is committed.
|
|
1657
1678
|
*/
|
|
1658
1679
|
signInWithOpenKey(authorizeFn: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[0], options?: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[1]): Promise<void>;
|
|
1680
|
+
/** Prepare the OpenKey request before the approval click. */
|
|
1681
|
+
prepareOpenKeySignIn(): Promise<PreparedOpenKeyAuthorization>;
|
|
1682
|
+
/** Start OpenKey authorization synchronously, then complete normal session setup. */
|
|
1683
|
+
signInWithPreparedOpenKey(pending: PreparedOpenKeyAuthorization, authorizeFn: Parameters<NodeUserAuthorization["signInWithOpenKey"]>[0]): Promise<void>;
|
|
1659
1684
|
private signInWith;
|
|
1660
1685
|
private establishSignIn;
|
|
1661
1686
|
/**
|
|
@@ -2708,4 +2733,4 @@ declare class TinyCloudNode {
|
|
|
2708
2733
|
}): Promise<PortableDelegation>;
|
|
2709
2734
|
}
|
|
2710
2735
|
|
|
2711
|
-
export { ACCEPTED_MARKER_VERSIONS as A, type BootstrapWarning as B, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, InvalidRestoredSessionError as I, type NodeEventEmitterStrategy as N, type
|
|
2736
|
+
export { ACCEPTED_MARKER_VERSIONS as A, type BootstrapWarning as B, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, InvalidRestoredSessionError as I, type NodeEventEmitterStrategy as N, type OpenKeyAuthorizeTinyCloud as O, type PreparedOpenKeyAuthorization as P, type RuntimePermissionGrantOptions as R, type SecretPermissionHint as S, TinyCloudNode as T, type UnifiedOwnerRootInput as U, type DelegateToResult as a, DelegatedAccess as b, NodeUserAuthorization as c, type NodeUserAuthorizationConfig as d, type OwnerDelegationReceipt as e, type SecretReadInput as f, type SecretReadResult as g, type SignStrategy as h, type TinyCloudNodeConfig as i, type UnifiedOwnerRootReceipt as j, UnsupportedSessionRestoreError as k, defaultSignStrategy as l, BOOTSTRAP_COMPLETION_MARKER_KEY as m, BOOTSTRAP_COMPLETION_MARKER_VERSION as n, type BootstrapCompletionMarker as o, type NodeUserAuthorizationAuthorizeFn as p, type OpenKeyAuthorizationResultV1 as q, type OpenKeyAuthorizeInput as r, type OpenKeyBridgeInput as s, type RestorableSession as t, wireOpenKeyAuthorize as w };
|
|
@@ -106,6 +106,26 @@ declare class FileSessionStorage implements ISessionStorage {
|
|
|
106
106
|
isAvailable(): boolean;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Whether sign-in at `origin` can be granted named-key abilities for the app
|
|
111
|
+
* whose manifest `keys_app_id` (or `app_id`) is `keysAppId`.
|
|
112
|
+
*
|
|
113
|
+
* "Bound" means the key app id equals the reversed host of the origin, or
|
|
114
|
+
* extends it with further dot-separated labels: `tinycloud.chat` binds
|
|
115
|
+
* `chat.tinycloud.tinychat` and `chat.tinycloud.tinychat.worker`. Origins with
|
|
116
|
+
* no registrable host (`localhost`, `tauri.localhost`, IP addresses) or with
|
|
117
|
+
* lookalike hosts (`evil-tinycloud.chat`, `tinycloud.chat.evil.com`) are not
|
|
118
|
+
* bound. `origin` is a URL, an origin string such as `https://tinycloud.chat`,
|
|
119
|
+
* or a bare SIWE domain such as `tinycloud.chat`; the host (including any
|
|
120
|
+
* non-default port, which makes the origin unbound) is what is checked.
|
|
121
|
+
*
|
|
122
|
+
* This is the check `NodeUserAuthorization` applies when it decides whether a
|
|
123
|
+
* manifest's `keys` rows are granted at sign-in. A bound origin still needs a
|
|
124
|
+
* node that lists `encryption-named-keys-v1` in `/info` to actually receive
|
|
125
|
+
* the row.
|
|
126
|
+
*/
|
|
127
|
+
declare function isAppKeyHostBound(keysAppId: string, origin: string | URL): boolean;
|
|
128
|
+
|
|
109
129
|
/**
|
|
110
130
|
* WasmKeyProvider - KeyProvider implementation using WASM session manager.
|
|
111
131
|
*
|
|
@@ -214,4 +234,4 @@ declare class WasmKeyProvider implements KeyProvider {
|
|
|
214
234
|
*/
|
|
215
235
|
declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
|
|
216
236
|
|
|
217
|
-
export { FileSessionStorage as F, MemorySessionStorage as M, WasmKeyProvider as W, type WasmKeyProviderConfig as a, createWasmKeyProvider as c };
|
|
237
|
+
export { FileSessionStorage as F, MemorySessionStorage as M, WasmKeyProvider as W, type WasmKeyProviderConfig as a, createWasmKeyProvider as c, isAppKeyHostBound as i };
|
|
@@ -106,6 +106,26 @@ declare class FileSessionStorage implements ISessionStorage {
|
|
|
106
106
|
isAvailable(): boolean;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Whether sign-in at `origin` can be granted named-key abilities for the app
|
|
111
|
+
* whose manifest `keys_app_id` (or `app_id`) is `keysAppId`.
|
|
112
|
+
*
|
|
113
|
+
* "Bound" means the key app id equals the reversed host of the origin, or
|
|
114
|
+
* extends it with further dot-separated labels: `tinycloud.chat` binds
|
|
115
|
+
* `chat.tinycloud.tinychat` and `chat.tinycloud.tinychat.worker`. Origins with
|
|
116
|
+
* no registrable host (`localhost`, `tauri.localhost`, IP addresses) or with
|
|
117
|
+
* lookalike hosts (`evil-tinycloud.chat`, `tinycloud.chat.evil.com`) are not
|
|
118
|
+
* bound. `origin` is a URL, an origin string such as `https://tinycloud.chat`,
|
|
119
|
+
* or a bare SIWE domain such as `tinycloud.chat`; the host (including any
|
|
120
|
+
* non-default port, which makes the origin unbound) is what is checked.
|
|
121
|
+
*
|
|
122
|
+
* This is the check `NodeUserAuthorization` applies when it decides whether a
|
|
123
|
+
* manifest's `keys` rows are granted at sign-in. A bound origin still needs a
|
|
124
|
+
* node that lists `encryption-named-keys-v1` in `/info` to actually receive
|
|
125
|
+
* the row.
|
|
126
|
+
*/
|
|
127
|
+
declare function isAppKeyHostBound(keysAppId: string, origin: string | URL): boolean;
|
|
128
|
+
|
|
109
129
|
/**
|
|
110
130
|
* WasmKeyProvider - KeyProvider implementation using WASM session manager.
|
|
111
131
|
*
|
|
@@ -214,4 +234,4 @@ declare class WasmKeyProvider implements KeyProvider {
|
|
|
214
234
|
*/
|
|
215
235
|
declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
|
|
216
236
|
|
|
217
|
-
export { FileSessionStorage as F, MemorySessionStorage as M, WasmKeyProvider as W, type WasmKeyProviderConfig as a, createWasmKeyProvider as c };
|
|
237
|
+
export { FileSessionStorage as F, MemorySessionStorage as M, WasmKeyProvider as W, type WasmKeyProviderConfig as a, createWasmKeyProvider as c, isAppKeyHostBound as i };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReplicationOptions, PermissionEntry, TinyCloudSession, KVReplicaStorage, ServiceContext, IWasmBindings, WasmRecapEntry } from '@tinycloud/sdk-core';
|
|
2
2
|
import { ReplicaConsentAnchor, AuthorityRefusal, ReplicationAuthority } from '@tinycloud/sdk-services';
|
|
3
3
|
import { ReplicaLocalEraseOutcome, ReplicaPurgeLocalCopyResult, ReplicaPurgeTrigger, ReplicaPurgeFailedEvent, ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
|
|
4
|
-
import { T as TinyCloudNode } from './TinyCloudNode-
|
|
4
|
+
import { T as TinyCloudNode } from './TinyCloudNode-BVDUdEcf.cjs';
|
|
5
5
|
|
|
6
6
|
/** Constructor-time validation; the space-dependent secrets check runs at sign-in and open. */
|
|
7
7
|
declare function assertValidReplicationConfig(replication: (ReplicationOptions & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReplicationOptions, PermissionEntry, TinyCloudSession, KVReplicaStorage, ServiceContext, IWasmBindings, WasmRecapEntry } from '@tinycloud/sdk-core';
|
|
2
2
|
import { ReplicaConsentAnchor, AuthorityRefusal, ReplicationAuthority } from '@tinycloud/sdk-services';
|
|
3
3
|
import { ReplicaLocalEraseOutcome, ReplicaPurgeLocalCopyResult, ReplicaPurgeTrigger, ReplicaPurgeFailedEvent, ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
|
|
4
|
-
import { T as TinyCloudNode } from './TinyCloudNode-
|
|
4
|
+
import { T as TinyCloudNode } from './TinyCloudNode-jMK_2Uj8.js';
|
|
5
5
|
|
|
6
6
|
/** Constructor-time validation; the space-dependent secrets check runs at sign-in and open. */
|
|
7
7
|
declare function assertValidReplicationConfig(replication: (ReplicationOptions & {
|
package/dist/core.cjs
CHANGED
|
@@ -111,6 +111,7 @@ __export(core_exports, {
|
|
|
111
111
|
getNodeReplicationLoaders: () => getNodeReplicationLoaders,
|
|
112
112
|
getTinyCloudDebugLogs: () => import_sdk_core13.getTinyCloudDebugLogs,
|
|
113
113
|
installTinyCloudDebugGlobals: () => import_sdk_core13.installTinyCloudDebugGlobals,
|
|
114
|
+
isAppKeyHostBound: () => isAppKeyHostBound,
|
|
114
115
|
isCapabilitySubset: () => import_sdk_core14.isCapabilitySubset,
|
|
115
116
|
isEvmAddress: () => import_sdk_core13.isEvmAddress,
|
|
116
117
|
loadManifest: () => import_sdk_core14.loadManifest,
|
|
@@ -132,7 +133,8 @@ __export(core_exports, {
|
|
|
132
133
|
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core14.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
133
134
|
serializeDelegation: () => serializeDelegation,
|
|
134
135
|
tinyCloudDebugLogger: () => import_sdk_core13.tinyCloudDebugLogger,
|
|
135
|
-
validateManifest: () => import_sdk_core14.validateManifest
|
|
136
|
+
validateManifest: () => import_sdk_core14.validateManifest,
|
|
137
|
+
wireOpenKeyAuthorize: () => wireOpenKeyAuthorize
|
|
136
138
|
});
|
|
137
139
|
module.exports = __toCommonJS(core_exports);
|
|
138
140
|
var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
@@ -373,6 +375,18 @@ function appKeyHostBinding(domain, appId) {
|
|
|
373
375
|
const reversed = labels.reverse().join(".");
|
|
374
376
|
return appId === reversed || appId.startsWith(`${reversed}.`);
|
|
375
377
|
}
|
|
378
|
+
function isAppKeyHostBound(keysAppId, origin) {
|
|
379
|
+
if (typeof origin === "string" && !origin.includes("://")) {
|
|
380
|
+
return appKeyHostBinding(origin, keysAppId);
|
|
381
|
+
}
|
|
382
|
+
let url;
|
|
383
|
+
try {
|
|
384
|
+
url = typeof origin === "string" ? new URL(origin) : origin;
|
|
385
|
+
} catch {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
return appKeyHostBinding(url.host, keysAppId);
|
|
389
|
+
}
|
|
376
390
|
|
|
377
391
|
// src/replication/authority-sign-in.ts
|
|
378
392
|
var import_sdk_core2 = require("@tinycloud/sdk-core");
|
|
@@ -504,6 +518,7 @@ function cloneAbilitiesMap(actions) {
|
|
|
504
518
|
var NodeUserAuthorization = class {
|
|
505
519
|
constructor(config) {
|
|
506
520
|
this.activeSessionKeyId = "default";
|
|
521
|
+
this.preparedSessionCounter = 0;
|
|
507
522
|
/** Incremented by resetSession; a sign-in started earlier publishes nothing. */
|
|
508
523
|
this.sessionGeneration = 0;
|
|
509
524
|
/**
|
|
@@ -1637,9 +1652,8 @@ var NodeUserAuthorization = class {
|
|
|
1637
1652
|
const address = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1638
1653
|
const chainId = await this.signer.getChainId();
|
|
1639
1654
|
await this.refreshNamedKeyFeatureForSignIn(address, chainId);
|
|
1640
|
-
const keyId = `session-${Date.now()}`;
|
|
1641
|
-
this.sessionManager.
|
|
1642
|
-
this.activeSessionKeyId = keyId;
|
|
1655
|
+
const keyId = `openkey-session-${Date.now()}-${++this.preparedSessionCounter}`;
|
|
1656
|
+
this.sessionManager.createSessionKey(keyId);
|
|
1643
1657
|
const jwkString = this.sessionManager.jwk(keyId);
|
|
1644
1658
|
if (!jwkString) {
|
|
1645
1659
|
throw new Error("Failed to create session key");
|
|
@@ -1720,6 +1734,7 @@ var NodeUserAuthorization = class {
|
|
|
1720
1734
|
await this.sessionStorage.save(address, persistedData);
|
|
1721
1735
|
this._session = clientSession;
|
|
1722
1736
|
this._tinyCloudSession = tinyCloudSession;
|
|
1737
|
+
this.activeSessionKeyId = keyId;
|
|
1723
1738
|
this._address = address;
|
|
1724
1739
|
this._chainId = chainId;
|
|
1725
1740
|
await this.refreshNodeInfo();
|
|
@@ -1766,6 +1781,11 @@ var NodeUserAuthorization = class {
|
|
|
1766
1781
|
* @param options Optional overrides for the OpenKey request.
|
|
1767
1782
|
*/
|
|
1768
1783
|
async signInWithOpenKey(authorizeFn, options) {
|
|
1784
|
+
const pending = await this.prepareOpenKeySignIn(options);
|
|
1785
|
+
return this.completeOpenKeySignIn(pending, authorizeFn(pending.request), options);
|
|
1786
|
+
}
|
|
1787
|
+
/** Finish address, host and SIWE preparation before an approval click. */
|
|
1788
|
+
async prepareOpenKeySignIn(options) {
|
|
1769
1789
|
refuseCaveated(this.getCapabilityRequest()?.manifests);
|
|
1770
1790
|
if (options?.host !== void 0) {
|
|
1771
1791
|
const overrideHost = options.host.trim();
|
|
@@ -1777,7 +1797,7 @@ var NodeUserAuthorization = class {
|
|
|
1777
1797
|
const signingAddress = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1778
1798
|
const signingChainId = await this.signer.getChainId();
|
|
1779
1799
|
await this.resolveTinyCloudHostsForSignIn(signingAddress, signingChainId);
|
|
1780
|
-
const { prepared, keyId, jwk } = await this.prepareSessionForSigning();
|
|
1800
|
+
const { prepared, keyId, jwk, address, chainId } = await this.prepareSessionForSigning();
|
|
1781
1801
|
const presentation = this.buildPresentationEnvelope(options?.reason);
|
|
1782
1802
|
const hostHint = this.primaryTinyCloudHost;
|
|
1783
1803
|
const originalRequest = {
|
|
@@ -1789,12 +1809,32 @@ var NodeUserAuthorization = class {
|
|
|
1789
1809
|
keyId: options?.openkeyKeyId,
|
|
1790
1810
|
presentation
|
|
1791
1811
|
};
|
|
1812
|
+
return {
|
|
1813
|
+
request: originalRequest,
|
|
1814
|
+
prepared,
|
|
1815
|
+
keyId,
|
|
1816
|
+
jwk,
|
|
1817
|
+
address,
|
|
1818
|
+
chainId,
|
|
1819
|
+
generation: this.sessionGeneration,
|
|
1820
|
+
createdAt: Date.now()
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
/** Complete a prepared approval. The caller starts authorization before awaiting this method. */
|
|
1824
|
+
async completeOpenKeySignIn(pending, authorization, options) {
|
|
1825
|
+
if (Date.now() - pending.createdAt > 5 * 6e4) {
|
|
1826
|
+
throw new Error("Prepared OpenKey sign-in expired; prepare again");
|
|
1827
|
+
}
|
|
1828
|
+
if (pending.generation !== this.sessionGeneration) {
|
|
1829
|
+
throw new Error("Prepared OpenKey sign-in expired after sign-out");
|
|
1830
|
+
}
|
|
1831
|
+
const { request: originalRequest, prepared, keyId, jwk } = pending;
|
|
1792
1832
|
let result;
|
|
1793
1833
|
let signed;
|
|
1794
1834
|
let signature;
|
|
1795
1835
|
for (let attempt = 0; ; ) {
|
|
1796
1836
|
try {
|
|
1797
|
-
result ?? (result = await
|
|
1837
|
+
result ?? (result = await authorization);
|
|
1798
1838
|
signed = await this.verifyOpenKeyResult(result, prepared);
|
|
1799
1839
|
signature = result.signature;
|
|
1800
1840
|
break;
|
|
@@ -2215,6 +2255,50 @@ var NodeUserAuthorization = class {
|
|
|
2215
2255
|
}
|
|
2216
2256
|
};
|
|
2217
2257
|
|
|
2258
|
+
// src/authorization/openKeyBridge.ts
|
|
2259
|
+
function wireOpenKeyAuthorize(openkey, opts) {
|
|
2260
|
+
return async (input) => {
|
|
2261
|
+
const result = await openkey.authorizeTinyCloud({
|
|
2262
|
+
protocolVersion: 1,
|
|
2263
|
+
siwe: input.siwe,
|
|
2264
|
+
keyId: input.keyId,
|
|
2265
|
+
jwk: input.jwk,
|
|
2266
|
+
host: input.host,
|
|
2267
|
+
// Forward the presentation envelope verbatim — the OpenKey SDK
|
|
2268
|
+
// validates and size-bounds it before use.
|
|
2269
|
+
presentation: input.presentation
|
|
2270
|
+
}, opts);
|
|
2271
|
+
if (result.protocolVersion !== 1) {
|
|
2272
|
+
throw new Error(
|
|
2273
|
+
`wireOpenKeyAuthorize: OpenKey returned unsupported protocolVersion ${result.protocolVersion}`
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2276
|
+
if (typeof result.signedMessage !== "string" || !result.signedMessage) {
|
|
2277
|
+
throw new Error(
|
|
2278
|
+
"wireOpenKeyAuthorize: OpenKey returned no signedMessage \u2014 cannot complete a TinyCloud session"
|
|
2279
|
+
);
|
|
2280
|
+
}
|
|
2281
|
+
if (!Array.isArray(result.selectedActionKeys)) {
|
|
2282
|
+
throw new Error(
|
|
2283
|
+
"wireOpenKeyAuthorize: OpenKey returned no selectedActionKeys"
|
|
2284
|
+
);
|
|
2285
|
+
}
|
|
2286
|
+
if (!Array.isArray(result.permissions)) {
|
|
2287
|
+
throw new Error(
|
|
2288
|
+
"wireOpenKeyAuthorize: OpenKey returned no permissions"
|
|
2289
|
+
);
|
|
2290
|
+
}
|
|
2291
|
+
return {
|
|
2292
|
+
protocolVersion: 1,
|
|
2293
|
+
address: result.address,
|
|
2294
|
+
signature: result.signature,
|
|
2295
|
+
signedMessage: result.signedMessage,
|
|
2296
|
+
selectedActionKeys: result.selectedActionKeys,
|
|
2297
|
+
permissions: result.permissions
|
|
2298
|
+
};
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2218
2302
|
// src/recordingServiceContext.ts
|
|
2219
2303
|
var import_sdk_services3 = require("@tinycloud/sdk-services");
|
|
2220
2304
|
var import_requestLog = require("@tinycloud/sdk-services/telemetry/requestLog");
|
|
@@ -3834,6 +3918,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3834
3918
|
constructor(config = {}) {
|
|
3835
3919
|
this.signer = null;
|
|
3836
3920
|
this.auth = null;
|
|
3921
|
+
this.consumedOpenKeyPendings = /* @__PURE__ */ new WeakSet();
|
|
3837
3922
|
this.tc = null;
|
|
3838
3923
|
this._chainId = 1;
|
|
3839
3924
|
this.replicaPurgeFailedHandlers = /* @__PURE__ */ new Set();
|
|
@@ -4774,6 +4859,37 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4774
4859
|
}
|
|
4775
4860
|
await this.signInWith(() => this.auth.signInWithOpenKey(authorizeFn, options));
|
|
4776
4861
|
}
|
|
4862
|
+
/** Prepare the OpenKey request before the approval click. */
|
|
4863
|
+
async prepareOpenKeySignIn() {
|
|
4864
|
+
if (!this.signer || !this.tc || !this.auth) {
|
|
4865
|
+
throw new Error("Cannot prepare OpenKey sign-in in session-only mode. Provide a signer in config.");
|
|
4866
|
+
}
|
|
4867
|
+
await this.signOutInFlight;
|
|
4868
|
+
await this.accountRegistryTail;
|
|
4869
|
+
await this.wasmBindings.ensureInitialized?.();
|
|
4870
|
+
return this.auth.prepareOpenKeySignIn();
|
|
4871
|
+
}
|
|
4872
|
+
/** Start OpenKey authorization synchronously, then complete normal session setup. */
|
|
4873
|
+
signInWithPreparedOpenKey(pending, authorizeFn) {
|
|
4874
|
+
if (!this.signer || !this.tc || !this.auth || this.signOutInFlight) {
|
|
4875
|
+
throw new Error("Prepared OpenKey sign-in is unavailable");
|
|
4876
|
+
}
|
|
4877
|
+
if (this.consumedOpenKeyPendings.has(pending)) {
|
|
4878
|
+
throw new Error("Prepared OpenKey sign-in was already used");
|
|
4879
|
+
}
|
|
4880
|
+
if (Date.now() - pending.createdAt > 5 * 6e4) {
|
|
4881
|
+
throw new Error("Prepared OpenKey sign-in expired; prepare again");
|
|
4882
|
+
}
|
|
4883
|
+
this.consumedOpenKeyPendings.add(pending);
|
|
4884
|
+
const authorization = authorizeFn(pending.request);
|
|
4885
|
+
void authorization.catch(() => void 0);
|
|
4886
|
+
return this.signInWith(() => {
|
|
4887
|
+
if (this._address !== pending.address || this._chainId !== pending.chainId) {
|
|
4888
|
+
throw new Error("OpenKey account changed after sign-in preparation");
|
|
4889
|
+
}
|
|
4890
|
+
return this.auth.completeOpenKeySignIn(pending, authorization);
|
|
4891
|
+
});
|
|
4892
|
+
}
|
|
4777
4893
|
async signInWith(performSignIn) {
|
|
4778
4894
|
refuseCaveated(this.auth?.capabilityRequest?.manifests);
|
|
4779
4895
|
const epoch = this.sessionEpoch;
|
|
@@ -10222,6 +10338,7 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
|
|
|
10222
10338
|
getNodeReplicationLoaders,
|
|
10223
10339
|
getTinyCloudDebugLogs,
|
|
10224
10340
|
installTinyCloudDebugGlobals,
|
|
10341
|
+
isAppKeyHostBound,
|
|
10225
10342
|
isCapabilitySubset,
|
|
10226
10343
|
isEvmAddress,
|
|
10227
10344
|
loadManifest,
|
|
@@ -10243,6 +10360,7 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
|
|
|
10243
10360
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
10244
10361
|
serializeDelegation,
|
|
10245
10362
|
tinyCloudDebugLogger,
|
|
10246
|
-
validateManifest
|
|
10363
|
+
validateManifest,
|
|
10364
|
+
wireOpenKeyAuthorize
|
|
10247
10365
|
});
|
|
10248
10366
|
//# sourceMappingURL=core.cjs.map
|