@tinycloud/node-sdk 3.8.0-beta.10 → 3.8.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.
- 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/{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 +111 -7
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +109 -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 +65 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +65 -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 };
|
|
@@ -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
|
@@ -132,7 +132,8 @@ __export(core_exports, {
|
|
|
132
132
|
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core14.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
133
133
|
serializeDelegation: () => serializeDelegation,
|
|
134
134
|
tinyCloudDebugLogger: () => import_sdk_core13.tinyCloudDebugLogger,
|
|
135
|
-
validateManifest: () => import_sdk_core14.validateManifest
|
|
135
|
+
validateManifest: () => import_sdk_core14.validateManifest,
|
|
136
|
+
wireOpenKeyAuthorize: () => wireOpenKeyAuthorize
|
|
136
137
|
});
|
|
137
138
|
module.exports = __toCommonJS(core_exports);
|
|
138
139
|
var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
@@ -504,6 +505,7 @@ function cloneAbilitiesMap(actions) {
|
|
|
504
505
|
var NodeUserAuthorization = class {
|
|
505
506
|
constructor(config) {
|
|
506
507
|
this.activeSessionKeyId = "default";
|
|
508
|
+
this.preparedSessionCounter = 0;
|
|
507
509
|
/** Incremented by resetSession; a sign-in started earlier publishes nothing. */
|
|
508
510
|
this.sessionGeneration = 0;
|
|
509
511
|
/**
|
|
@@ -1637,9 +1639,8 @@ var NodeUserAuthorization = class {
|
|
|
1637
1639
|
const address = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1638
1640
|
const chainId = await this.signer.getChainId();
|
|
1639
1641
|
await this.refreshNamedKeyFeatureForSignIn(address, chainId);
|
|
1640
|
-
const keyId = `session-${Date.now()}`;
|
|
1641
|
-
this.sessionManager.
|
|
1642
|
-
this.activeSessionKeyId = keyId;
|
|
1642
|
+
const keyId = `openkey-session-${Date.now()}-${++this.preparedSessionCounter}`;
|
|
1643
|
+
this.sessionManager.createSessionKey(keyId);
|
|
1643
1644
|
const jwkString = this.sessionManager.jwk(keyId);
|
|
1644
1645
|
if (!jwkString) {
|
|
1645
1646
|
throw new Error("Failed to create session key");
|
|
@@ -1720,6 +1721,7 @@ var NodeUserAuthorization = class {
|
|
|
1720
1721
|
await this.sessionStorage.save(address, persistedData);
|
|
1721
1722
|
this._session = clientSession;
|
|
1722
1723
|
this._tinyCloudSession = tinyCloudSession;
|
|
1724
|
+
this.activeSessionKeyId = keyId;
|
|
1723
1725
|
this._address = address;
|
|
1724
1726
|
this._chainId = chainId;
|
|
1725
1727
|
await this.refreshNodeInfo();
|
|
@@ -1766,6 +1768,11 @@ var NodeUserAuthorization = class {
|
|
|
1766
1768
|
* @param options Optional overrides for the OpenKey request.
|
|
1767
1769
|
*/
|
|
1768
1770
|
async signInWithOpenKey(authorizeFn, options) {
|
|
1771
|
+
const pending = await this.prepareOpenKeySignIn(options);
|
|
1772
|
+
return this.completeOpenKeySignIn(pending, authorizeFn(pending.request), options);
|
|
1773
|
+
}
|
|
1774
|
+
/** Finish address, host and SIWE preparation before an approval click. */
|
|
1775
|
+
async prepareOpenKeySignIn(options) {
|
|
1769
1776
|
refuseCaveated(this.getCapabilityRequest()?.manifests);
|
|
1770
1777
|
if (options?.host !== void 0) {
|
|
1771
1778
|
const overrideHost = options.host.trim();
|
|
@@ -1777,7 +1784,7 @@ var NodeUserAuthorization = class {
|
|
|
1777
1784
|
const signingAddress = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1778
1785
|
const signingChainId = await this.signer.getChainId();
|
|
1779
1786
|
await this.resolveTinyCloudHostsForSignIn(signingAddress, signingChainId);
|
|
1780
|
-
const { prepared, keyId, jwk } = await this.prepareSessionForSigning();
|
|
1787
|
+
const { prepared, keyId, jwk, address, chainId } = await this.prepareSessionForSigning();
|
|
1781
1788
|
const presentation = this.buildPresentationEnvelope(options?.reason);
|
|
1782
1789
|
const hostHint = this.primaryTinyCloudHost;
|
|
1783
1790
|
const originalRequest = {
|
|
@@ -1789,12 +1796,32 @@ var NodeUserAuthorization = class {
|
|
|
1789
1796
|
keyId: options?.openkeyKeyId,
|
|
1790
1797
|
presentation
|
|
1791
1798
|
};
|
|
1799
|
+
return {
|
|
1800
|
+
request: originalRequest,
|
|
1801
|
+
prepared,
|
|
1802
|
+
keyId,
|
|
1803
|
+
jwk,
|
|
1804
|
+
address,
|
|
1805
|
+
chainId,
|
|
1806
|
+
generation: this.sessionGeneration,
|
|
1807
|
+
createdAt: Date.now()
|
|
1808
|
+
};
|
|
1809
|
+
}
|
|
1810
|
+
/** Complete a prepared approval. The caller starts authorization before awaiting this method. */
|
|
1811
|
+
async completeOpenKeySignIn(pending, authorization, options) {
|
|
1812
|
+
if (Date.now() - pending.createdAt > 5 * 6e4) {
|
|
1813
|
+
throw new Error("Prepared OpenKey sign-in expired; prepare again");
|
|
1814
|
+
}
|
|
1815
|
+
if (pending.generation !== this.sessionGeneration) {
|
|
1816
|
+
throw new Error("Prepared OpenKey sign-in expired after sign-out");
|
|
1817
|
+
}
|
|
1818
|
+
const { request: originalRequest, prepared, keyId, jwk } = pending;
|
|
1792
1819
|
let result;
|
|
1793
1820
|
let signed;
|
|
1794
1821
|
let signature;
|
|
1795
1822
|
for (let attempt = 0; ; ) {
|
|
1796
1823
|
try {
|
|
1797
|
-
result ?? (result = await
|
|
1824
|
+
result ?? (result = await authorization);
|
|
1798
1825
|
signed = await this.verifyOpenKeyResult(result, prepared);
|
|
1799
1826
|
signature = result.signature;
|
|
1800
1827
|
break;
|
|
@@ -2215,6 +2242,50 @@ var NodeUserAuthorization = class {
|
|
|
2215
2242
|
}
|
|
2216
2243
|
};
|
|
2217
2244
|
|
|
2245
|
+
// src/authorization/openKeyBridge.ts
|
|
2246
|
+
function wireOpenKeyAuthorize(openkey, opts) {
|
|
2247
|
+
return async (input) => {
|
|
2248
|
+
const result = await openkey.authorizeTinyCloud({
|
|
2249
|
+
protocolVersion: 1,
|
|
2250
|
+
siwe: input.siwe,
|
|
2251
|
+
keyId: input.keyId,
|
|
2252
|
+
jwk: input.jwk,
|
|
2253
|
+
host: input.host,
|
|
2254
|
+
// Forward the presentation envelope verbatim — the OpenKey SDK
|
|
2255
|
+
// validates and size-bounds it before use.
|
|
2256
|
+
presentation: input.presentation
|
|
2257
|
+
}, opts);
|
|
2258
|
+
if (result.protocolVersion !== 1) {
|
|
2259
|
+
throw new Error(
|
|
2260
|
+
`wireOpenKeyAuthorize: OpenKey returned unsupported protocolVersion ${result.protocolVersion}`
|
|
2261
|
+
);
|
|
2262
|
+
}
|
|
2263
|
+
if (typeof result.signedMessage !== "string" || !result.signedMessage) {
|
|
2264
|
+
throw new Error(
|
|
2265
|
+
"wireOpenKeyAuthorize: OpenKey returned no signedMessage \u2014 cannot complete a TinyCloud session"
|
|
2266
|
+
);
|
|
2267
|
+
}
|
|
2268
|
+
if (!Array.isArray(result.selectedActionKeys)) {
|
|
2269
|
+
throw new Error(
|
|
2270
|
+
"wireOpenKeyAuthorize: OpenKey returned no selectedActionKeys"
|
|
2271
|
+
);
|
|
2272
|
+
}
|
|
2273
|
+
if (!Array.isArray(result.permissions)) {
|
|
2274
|
+
throw new Error(
|
|
2275
|
+
"wireOpenKeyAuthorize: OpenKey returned no permissions"
|
|
2276
|
+
);
|
|
2277
|
+
}
|
|
2278
|
+
return {
|
|
2279
|
+
protocolVersion: 1,
|
|
2280
|
+
address: result.address,
|
|
2281
|
+
signature: result.signature,
|
|
2282
|
+
signedMessage: result.signedMessage,
|
|
2283
|
+
selectedActionKeys: result.selectedActionKeys,
|
|
2284
|
+
permissions: result.permissions
|
|
2285
|
+
};
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2218
2289
|
// src/recordingServiceContext.ts
|
|
2219
2290
|
var import_sdk_services3 = require("@tinycloud/sdk-services");
|
|
2220
2291
|
var import_requestLog = require("@tinycloud/sdk-services/telemetry/requestLog");
|
|
@@ -3834,6 +3905,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3834
3905
|
constructor(config = {}) {
|
|
3835
3906
|
this.signer = null;
|
|
3836
3907
|
this.auth = null;
|
|
3908
|
+
this.consumedOpenKeyPendings = /* @__PURE__ */ new WeakSet();
|
|
3837
3909
|
this.tc = null;
|
|
3838
3910
|
this._chainId = 1;
|
|
3839
3911
|
this.replicaPurgeFailedHandlers = /* @__PURE__ */ new Set();
|
|
@@ -4774,6 +4846,37 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4774
4846
|
}
|
|
4775
4847
|
await this.signInWith(() => this.auth.signInWithOpenKey(authorizeFn, options));
|
|
4776
4848
|
}
|
|
4849
|
+
/** Prepare the OpenKey request before the approval click. */
|
|
4850
|
+
async prepareOpenKeySignIn() {
|
|
4851
|
+
if (!this.signer || !this.tc || !this.auth) {
|
|
4852
|
+
throw new Error("Cannot prepare OpenKey sign-in in session-only mode. Provide a signer in config.");
|
|
4853
|
+
}
|
|
4854
|
+
await this.signOutInFlight;
|
|
4855
|
+
await this.accountRegistryTail;
|
|
4856
|
+
await this.wasmBindings.ensureInitialized?.();
|
|
4857
|
+
return this.auth.prepareOpenKeySignIn();
|
|
4858
|
+
}
|
|
4859
|
+
/** Start OpenKey authorization synchronously, then complete normal session setup. */
|
|
4860
|
+
signInWithPreparedOpenKey(pending, authorizeFn) {
|
|
4861
|
+
if (!this.signer || !this.tc || !this.auth || this.signOutInFlight) {
|
|
4862
|
+
throw new Error("Prepared OpenKey sign-in is unavailable");
|
|
4863
|
+
}
|
|
4864
|
+
if (this.consumedOpenKeyPendings.has(pending)) {
|
|
4865
|
+
throw new Error("Prepared OpenKey sign-in was already used");
|
|
4866
|
+
}
|
|
4867
|
+
if (Date.now() - pending.createdAt > 5 * 6e4) {
|
|
4868
|
+
throw new Error("Prepared OpenKey sign-in expired; prepare again");
|
|
4869
|
+
}
|
|
4870
|
+
this.consumedOpenKeyPendings.add(pending);
|
|
4871
|
+
const authorization = authorizeFn(pending.request);
|
|
4872
|
+
void authorization.catch(() => void 0);
|
|
4873
|
+
return this.signInWith(() => {
|
|
4874
|
+
if (this._address !== pending.address || this._chainId !== pending.chainId) {
|
|
4875
|
+
throw new Error("OpenKey account changed after sign-in preparation");
|
|
4876
|
+
}
|
|
4877
|
+
return this.auth.completeOpenKeySignIn(pending, authorization);
|
|
4878
|
+
});
|
|
4879
|
+
}
|
|
4777
4880
|
async signInWith(performSignIn) {
|
|
4778
4881
|
refuseCaveated(this.auth?.capabilityRequest?.manifests);
|
|
4779
4882
|
const epoch = this.sessionEpoch;
|
|
@@ -10243,6 +10346,7 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
|
|
|
10243
10346
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
10244
10347
|
serializeDelegation,
|
|
10245
10348
|
tinyCloudDebugLogger,
|
|
10246
|
-
validateManifest
|
|
10349
|
+
validateManifest,
|
|
10350
|
+
wireOpenKeyAuthorize
|
|
10247
10351
|
});
|
|
10248
10352
|
//# sourceMappingURL=core.cjs.map
|