@block-auth.io/core 0.4.1 → 0.5.1
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/index.cjs +364 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -6
- package/dist/index.d.ts +78 -6
- package/dist/index.js +364 -72
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -91,6 +91,7 @@ declare function createDeletionService(deps: DeletionServiceDeps): {
|
|
|
91
91
|
*/
|
|
92
92
|
declare class WsClient {
|
|
93
93
|
private _wsUrl;
|
|
94
|
+
private _apiUrl?;
|
|
94
95
|
private _wsConfig;
|
|
95
96
|
private _uiConfig;
|
|
96
97
|
private _ws;
|
|
@@ -101,7 +102,17 @@ declare class WsClient {
|
|
|
101
102
|
private _roles;
|
|
102
103
|
private _logs;
|
|
103
104
|
private _kycIssuerByAddress;
|
|
104
|
-
|
|
105
|
+
/**
|
|
106
|
+
* @param url - the wss:// endpoint to connect to.
|
|
107
|
+
* @param reconnect - allow socket.io to auto-reconnect.
|
|
108
|
+
* @param apiUrl - backend base url used to fetch the short-lived WS
|
|
109
|
+
* connect ticket (GET /auth/ws-ticket) right before opening the socket.
|
|
110
|
+
* Defaults to https://api.block-auth.io. The cookie set by
|
|
111
|
+
* POST /auth/session is host-only to the API origin, so it can't reach
|
|
112
|
+
* this (different-host) WS endpoint directly — the ticket is what
|
|
113
|
+
* actually authenticates the connection now.
|
|
114
|
+
*/
|
|
115
|
+
constructor(url?: string, reconnect?: boolean, apiUrl?: string);
|
|
105
116
|
/**
|
|
106
117
|
* Check if the WebSocket API is connected
|
|
107
118
|
* to Block-Auth service
|
|
@@ -115,6 +126,19 @@ declare class WsClient {
|
|
|
115
126
|
* @returns Promise<void>
|
|
116
127
|
*/
|
|
117
128
|
connect(url?: string, waitMs?: number, retries?: number): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Re-authenticates the CURRENT connection in place: fetches a fresh
|
|
131
|
+
* ws-ticket and sends it over the already-open socket, so the server
|
|
132
|
+
* updates its view of who this connection belongs to without a
|
|
133
|
+
* disconnect/reconnect. A full reconnect would replace `this._ws` with a
|
|
134
|
+
* brand new socket.io instance, silently dropping every listener
|
|
135
|
+
* authRuntime registered on the old one (e.g. the response side of
|
|
136
|
+
* requestSignin -> user:txns:create -> sign) - this avoids that.
|
|
137
|
+
* No-op if there is no open connection yet (connect() will pick up a
|
|
138
|
+
* ticket on its own once one exists).
|
|
139
|
+
* @returns Promise<void>
|
|
140
|
+
*/
|
|
141
|
+
refreshAuth(): Promise<void>;
|
|
118
142
|
/**
|
|
119
143
|
* Allow you to subscribe to an event, and
|
|
120
144
|
* verify if the event is already subscribed
|
|
@@ -390,12 +414,20 @@ declare const hasAnyRoleBySlug: (user: BlockAuthUserProfile | null | undefined,
|
|
|
390
414
|
* const provider = new BlockAuthProvider();
|
|
391
415
|
*
|
|
392
416
|
*/
|
|
417
|
+
interface BlockAuthProviderOptions {
|
|
418
|
+
/**
|
|
419
|
+
* Backend base url forwarded to `WsClient` to fetch the short-lived WS
|
|
420
|
+
* connect ticket (GET /auth/ws-ticket). Defaults to
|
|
421
|
+
* https://api.block-auth.io.
|
|
422
|
+
*/
|
|
423
|
+
apiUrl?: string;
|
|
424
|
+
}
|
|
393
425
|
declare class BlockAuthProvider {
|
|
394
426
|
private _rpc;
|
|
395
427
|
private _wsc;
|
|
396
428
|
private _apiKey;
|
|
397
429
|
private _apiSecret;
|
|
398
|
-
constructor(apiKey?: string, apiSecret?: string, wsUrl?: string);
|
|
430
|
+
constructor(apiKey?: string, apiSecret?: string, wsUrl?: string, options?: BlockAuthProviderOptions);
|
|
399
431
|
/**
|
|
400
432
|
* Allow you to connect to the WebSocket API
|
|
401
433
|
* for Block-Auth service
|
|
@@ -747,6 +779,11 @@ interface BlockAuthClientConfig {
|
|
|
747
779
|
apiKey: string;
|
|
748
780
|
apiSecret: string;
|
|
749
781
|
wsUrl?: string;
|
|
782
|
+
/** Backend base url used for the session-cookie bridge (POST
|
|
783
|
+
* /auth/session), logout (POST /auth/logout) and the WS connect ticket
|
|
784
|
+
* (GET /auth/ws-ticket). Defaults to https://api.block-auth.io, mirroring
|
|
785
|
+
* how `wsUrl` defaults to wss://wss.block-auth.io. */
|
|
786
|
+
apiUrl?: string;
|
|
750
787
|
/** Timeout (ms) por intento del connect inicial del WS. Default 300 —
|
|
751
788
|
* puede quedarse corto en orígenes con más latencia (p.ej. PRE sin CDN). */
|
|
752
789
|
wsConnectTimeout?: number;
|
|
@@ -775,6 +812,8 @@ declare function createBlockAuthClient(config: BlockAuthClientConfig): {
|
|
|
775
812
|
$openModals: nanostores.WritableAtom<ModalName[]>;
|
|
776
813
|
$user: nanostores.MapStore<UserState>;
|
|
777
814
|
};
|
|
815
|
+
/** App apiKey from client config (also seeded into $ws). */
|
|
816
|
+
apiKey: string;
|
|
778
817
|
connect: (waitMs?: number | undefined, url?: string | undefined, retries?: number | undefined) => Promise<void>;
|
|
779
818
|
disconnect: () => Promise<void>;
|
|
780
819
|
signin: () => Promise<any>;
|
|
@@ -1129,6 +1168,7 @@ declare function createBlockAuthClient(config: BlockAuthClientConfig): {
|
|
|
1129
1168
|
closeAllModals: () => void;
|
|
1130
1169
|
wsConnectTimeout: number;
|
|
1131
1170
|
wsConnectRetries: number;
|
|
1171
|
+
apiUrl: string | undefined;
|
|
1132
1172
|
provider: BlockAuthProvider;
|
|
1133
1173
|
};
|
|
1134
1174
|
type BlockAuthClient = ReturnType<typeof createBlockAuthClient>;
|
|
@@ -1505,8 +1545,14 @@ interface SetSessionParams {
|
|
|
1505
1545
|
token?: string;
|
|
1506
1546
|
externalService?: Partial<ExternalServiceConfig>;
|
|
1507
1547
|
serviceName?: string;
|
|
1548
|
+
/** Optional override for the backend base url used to reach
|
|
1549
|
+
* `/auth/session` (defaults to `https://api.block-auth.io`). Mirrors how
|
|
1550
|
+
* `WsClient`'s `url` is overridden. */
|
|
1551
|
+
apiUrl?: string;
|
|
1508
1552
|
}
|
|
1509
1553
|
declare class BrowserBase {
|
|
1554
|
+
private _sessionToken;
|
|
1555
|
+
private _externalToken;
|
|
1510
1556
|
/**
|
|
1511
1557
|
* Wipe every SDK-owned localStorage key and reseed the defaults. Unlike a
|
|
1512
1558
|
* per-key reset it also clears the `blockauth-logged-out` /
|
|
@@ -1519,6 +1565,13 @@ declare class BrowserBase {
|
|
|
1519
1565
|
reset(target?: 'all' | 'ui' | 'session' | 'external', { keepExtensionInstalled }?: {
|
|
1520
1566
|
keepExtensionInstalled?: boolean | undefined;
|
|
1521
1567
|
}): void;
|
|
1568
|
+
/**
|
|
1569
|
+
* Stable id for this browser, generated once and persisted in localStorage
|
|
1570
|
+
* (every tab of this browser shares it, and it survives logout). Lets the
|
|
1571
|
+
* server scope a signout to just this browser instead of every device
|
|
1572
|
+
* signed in with the same account.
|
|
1573
|
+
*/
|
|
1574
|
+
getDeviceSessionId(): string;
|
|
1522
1575
|
/**
|
|
1523
1576
|
* Obtains the current UI configuration using localStorage as the
|
|
1524
1577
|
* source of truth, seeding the default if none is stored.
|
|
@@ -1529,16 +1582,35 @@ declare class BrowserBase {
|
|
|
1529
1582
|
*/
|
|
1530
1583
|
setUILocked(isLocked: boolean): void;
|
|
1531
1584
|
setUI({ installed, isUser, isUserActive, isLocked, }?: Partial<UiConfig>): void;
|
|
1585
|
+
/**
|
|
1586
|
+
* `did` is read from localStorage; `token` is never persisted there (see
|
|
1587
|
+
* the SECURITY NOTE above) and comes from the in-memory field instead, so
|
|
1588
|
+
* it reads back as '' after a page reload even though `did` survives.
|
|
1589
|
+
*/
|
|
1532
1590
|
getSession(): SessionConfig;
|
|
1533
1591
|
/**
|
|
1534
|
-
* Obtains the configuration about the address and the service
|
|
1535
|
-
*
|
|
1592
|
+
* Obtains the configuration about the address and the service where the
|
|
1593
|
+
* user is connected. As with `getSession()`, `token` is never persisted
|
|
1594
|
+
* to localStorage - it's overlaid here from the in-memory field.
|
|
1536
1595
|
*/
|
|
1537
1596
|
getExternalService(): ExternalServiceConfig;
|
|
1538
1597
|
/**
|
|
1539
|
-
* Auxiliary method to update the SESSION configuration using websocket
|
|
1598
|
+
* Auxiliary method to update the SESSION configuration using websocket
|
|
1599
|
+
* events.
|
|
1600
|
+
*
|
|
1601
|
+
* IMPORTANT: the wallet JWT (`token`) is never persisted to localStorage
|
|
1602
|
+
* anymore (see the SECURITY NOTE at the top of this file). It's kept in
|
|
1603
|
+
* the `_sessionToken`/`_externalToken` in-memory fields instead, and -
|
|
1604
|
+
* when it's a fresh/changed `blockauth` token - bridged into an httpOnly
|
|
1605
|
+
* `blockauth-session` cookie via the `/auth/session` backend endpoint.
|
|
1606
|
+
* Only the (non-sensitive) `did` is persisted, for UI/reload purposes.
|
|
1607
|
+
*
|
|
1608
|
+
* Returns a Promise once the (best-effort) session-bridge call has
|
|
1609
|
+
* settled; callers that don't need to wait for it can keep calling this
|
|
1610
|
+
* without awaiting, same as before - every state mutation below happens
|
|
1611
|
+
* synchronously, before the `await`.
|
|
1540
1612
|
*/
|
|
1541
|
-
setSession({ installed, isUser, isUserActive, isLocked, did, token, externalService, serviceName, }?: SetSessionParams): void
|
|
1613
|
+
setSession({ installed, isUser, isUserActive, isLocked, did, token, externalService, serviceName, apiUrl, }?: SetSessionParams): Promise<void>;
|
|
1542
1614
|
externalServiceDisconnect(): void;
|
|
1543
1615
|
getLang(): string;
|
|
1544
1616
|
setLang(lang: string): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,7 @@ declare function createDeletionService(deps: DeletionServiceDeps): {
|
|
|
91
91
|
*/
|
|
92
92
|
declare class WsClient {
|
|
93
93
|
private _wsUrl;
|
|
94
|
+
private _apiUrl?;
|
|
94
95
|
private _wsConfig;
|
|
95
96
|
private _uiConfig;
|
|
96
97
|
private _ws;
|
|
@@ -101,7 +102,17 @@ declare class WsClient {
|
|
|
101
102
|
private _roles;
|
|
102
103
|
private _logs;
|
|
103
104
|
private _kycIssuerByAddress;
|
|
104
|
-
|
|
105
|
+
/**
|
|
106
|
+
* @param url - the wss:// endpoint to connect to.
|
|
107
|
+
* @param reconnect - allow socket.io to auto-reconnect.
|
|
108
|
+
* @param apiUrl - backend base url used to fetch the short-lived WS
|
|
109
|
+
* connect ticket (GET /auth/ws-ticket) right before opening the socket.
|
|
110
|
+
* Defaults to https://api.block-auth.io. The cookie set by
|
|
111
|
+
* POST /auth/session is host-only to the API origin, so it can't reach
|
|
112
|
+
* this (different-host) WS endpoint directly — the ticket is what
|
|
113
|
+
* actually authenticates the connection now.
|
|
114
|
+
*/
|
|
115
|
+
constructor(url?: string, reconnect?: boolean, apiUrl?: string);
|
|
105
116
|
/**
|
|
106
117
|
* Check if the WebSocket API is connected
|
|
107
118
|
* to Block-Auth service
|
|
@@ -115,6 +126,19 @@ declare class WsClient {
|
|
|
115
126
|
* @returns Promise<void>
|
|
116
127
|
*/
|
|
117
128
|
connect(url?: string, waitMs?: number, retries?: number): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Re-authenticates the CURRENT connection in place: fetches a fresh
|
|
131
|
+
* ws-ticket and sends it over the already-open socket, so the server
|
|
132
|
+
* updates its view of who this connection belongs to without a
|
|
133
|
+
* disconnect/reconnect. A full reconnect would replace `this._ws` with a
|
|
134
|
+
* brand new socket.io instance, silently dropping every listener
|
|
135
|
+
* authRuntime registered on the old one (e.g. the response side of
|
|
136
|
+
* requestSignin -> user:txns:create -> sign) - this avoids that.
|
|
137
|
+
* No-op if there is no open connection yet (connect() will pick up a
|
|
138
|
+
* ticket on its own once one exists).
|
|
139
|
+
* @returns Promise<void>
|
|
140
|
+
*/
|
|
141
|
+
refreshAuth(): Promise<void>;
|
|
118
142
|
/**
|
|
119
143
|
* Allow you to subscribe to an event, and
|
|
120
144
|
* verify if the event is already subscribed
|
|
@@ -390,12 +414,20 @@ declare const hasAnyRoleBySlug: (user: BlockAuthUserProfile | null | undefined,
|
|
|
390
414
|
* const provider = new BlockAuthProvider();
|
|
391
415
|
*
|
|
392
416
|
*/
|
|
417
|
+
interface BlockAuthProviderOptions {
|
|
418
|
+
/**
|
|
419
|
+
* Backend base url forwarded to `WsClient` to fetch the short-lived WS
|
|
420
|
+
* connect ticket (GET /auth/ws-ticket). Defaults to
|
|
421
|
+
* https://api.block-auth.io.
|
|
422
|
+
*/
|
|
423
|
+
apiUrl?: string;
|
|
424
|
+
}
|
|
393
425
|
declare class BlockAuthProvider {
|
|
394
426
|
private _rpc;
|
|
395
427
|
private _wsc;
|
|
396
428
|
private _apiKey;
|
|
397
429
|
private _apiSecret;
|
|
398
|
-
constructor(apiKey?: string, apiSecret?: string, wsUrl?: string);
|
|
430
|
+
constructor(apiKey?: string, apiSecret?: string, wsUrl?: string, options?: BlockAuthProviderOptions);
|
|
399
431
|
/**
|
|
400
432
|
* Allow you to connect to the WebSocket API
|
|
401
433
|
* for Block-Auth service
|
|
@@ -747,6 +779,11 @@ interface BlockAuthClientConfig {
|
|
|
747
779
|
apiKey: string;
|
|
748
780
|
apiSecret: string;
|
|
749
781
|
wsUrl?: string;
|
|
782
|
+
/** Backend base url used for the session-cookie bridge (POST
|
|
783
|
+
* /auth/session), logout (POST /auth/logout) and the WS connect ticket
|
|
784
|
+
* (GET /auth/ws-ticket). Defaults to https://api.block-auth.io, mirroring
|
|
785
|
+
* how `wsUrl` defaults to wss://wss.block-auth.io. */
|
|
786
|
+
apiUrl?: string;
|
|
750
787
|
/** Timeout (ms) por intento del connect inicial del WS. Default 300 —
|
|
751
788
|
* puede quedarse corto en orígenes con más latencia (p.ej. PRE sin CDN). */
|
|
752
789
|
wsConnectTimeout?: number;
|
|
@@ -775,6 +812,8 @@ declare function createBlockAuthClient(config: BlockAuthClientConfig): {
|
|
|
775
812
|
$openModals: nanostores.WritableAtom<ModalName[]>;
|
|
776
813
|
$user: nanostores.MapStore<UserState>;
|
|
777
814
|
};
|
|
815
|
+
/** App apiKey from client config (also seeded into $ws). */
|
|
816
|
+
apiKey: string;
|
|
778
817
|
connect: (waitMs?: number | undefined, url?: string | undefined, retries?: number | undefined) => Promise<void>;
|
|
779
818
|
disconnect: () => Promise<void>;
|
|
780
819
|
signin: () => Promise<any>;
|
|
@@ -1129,6 +1168,7 @@ declare function createBlockAuthClient(config: BlockAuthClientConfig): {
|
|
|
1129
1168
|
closeAllModals: () => void;
|
|
1130
1169
|
wsConnectTimeout: number;
|
|
1131
1170
|
wsConnectRetries: number;
|
|
1171
|
+
apiUrl: string | undefined;
|
|
1132
1172
|
provider: BlockAuthProvider;
|
|
1133
1173
|
};
|
|
1134
1174
|
type BlockAuthClient = ReturnType<typeof createBlockAuthClient>;
|
|
@@ -1505,8 +1545,14 @@ interface SetSessionParams {
|
|
|
1505
1545
|
token?: string;
|
|
1506
1546
|
externalService?: Partial<ExternalServiceConfig>;
|
|
1507
1547
|
serviceName?: string;
|
|
1548
|
+
/** Optional override for the backend base url used to reach
|
|
1549
|
+
* `/auth/session` (defaults to `https://api.block-auth.io`). Mirrors how
|
|
1550
|
+
* `WsClient`'s `url` is overridden. */
|
|
1551
|
+
apiUrl?: string;
|
|
1508
1552
|
}
|
|
1509
1553
|
declare class BrowserBase {
|
|
1554
|
+
private _sessionToken;
|
|
1555
|
+
private _externalToken;
|
|
1510
1556
|
/**
|
|
1511
1557
|
* Wipe every SDK-owned localStorage key and reseed the defaults. Unlike a
|
|
1512
1558
|
* per-key reset it also clears the `blockauth-logged-out` /
|
|
@@ -1519,6 +1565,13 @@ declare class BrowserBase {
|
|
|
1519
1565
|
reset(target?: 'all' | 'ui' | 'session' | 'external', { keepExtensionInstalled }?: {
|
|
1520
1566
|
keepExtensionInstalled?: boolean | undefined;
|
|
1521
1567
|
}): void;
|
|
1568
|
+
/**
|
|
1569
|
+
* Stable id for this browser, generated once and persisted in localStorage
|
|
1570
|
+
* (every tab of this browser shares it, and it survives logout). Lets the
|
|
1571
|
+
* server scope a signout to just this browser instead of every device
|
|
1572
|
+
* signed in with the same account.
|
|
1573
|
+
*/
|
|
1574
|
+
getDeviceSessionId(): string;
|
|
1522
1575
|
/**
|
|
1523
1576
|
* Obtains the current UI configuration using localStorage as the
|
|
1524
1577
|
* source of truth, seeding the default if none is stored.
|
|
@@ -1529,16 +1582,35 @@ declare class BrowserBase {
|
|
|
1529
1582
|
*/
|
|
1530
1583
|
setUILocked(isLocked: boolean): void;
|
|
1531
1584
|
setUI({ installed, isUser, isUserActive, isLocked, }?: Partial<UiConfig>): void;
|
|
1585
|
+
/**
|
|
1586
|
+
* `did` is read from localStorage; `token` is never persisted there (see
|
|
1587
|
+
* the SECURITY NOTE above) and comes from the in-memory field instead, so
|
|
1588
|
+
* it reads back as '' after a page reload even though `did` survives.
|
|
1589
|
+
*/
|
|
1532
1590
|
getSession(): SessionConfig;
|
|
1533
1591
|
/**
|
|
1534
|
-
* Obtains the configuration about the address and the service
|
|
1535
|
-
*
|
|
1592
|
+
* Obtains the configuration about the address and the service where the
|
|
1593
|
+
* user is connected. As with `getSession()`, `token` is never persisted
|
|
1594
|
+
* to localStorage - it's overlaid here from the in-memory field.
|
|
1536
1595
|
*/
|
|
1537
1596
|
getExternalService(): ExternalServiceConfig;
|
|
1538
1597
|
/**
|
|
1539
|
-
* Auxiliary method to update the SESSION configuration using websocket
|
|
1598
|
+
* Auxiliary method to update the SESSION configuration using websocket
|
|
1599
|
+
* events.
|
|
1600
|
+
*
|
|
1601
|
+
* IMPORTANT: the wallet JWT (`token`) is never persisted to localStorage
|
|
1602
|
+
* anymore (see the SECURITY NOTE at the top of this file). It's kept in
|
|
1603
|
+
* the `_sessionToken`/`_externalToken` in-memory fields instead, and -
|
|
1604
|
+
* when it's a fresh/changed `blockauth` token - bridged into an httpOnly
|
|
1605
|
+
* `blockauth-session` cookie via the `/auth/session` backend endpoint.
|
|
1606
|
+
* Only the (non-sensitive) `did` is persisted, for UI/reload purposes.
|
|
1607
|
+
*
|
|
1608
|
+
* Returns a Promise once the (best-effort) session-bridge call has
|
|
1609
|
+
* settled; callers that don't need to wait for it can keep calling this
|
|
1610
|
+
* without awaiting, same as before - every state mutation below happens
|
|
1611
|
+
* synchronously, before the `await`.
|
|
1540
1612
|
*/
|
|
1541
|
-
setSession({ installed, isUser, isUserActive, isLocked, did, token, externalService, serviceName, }?: SetSessionParams): void
|
|
1613
|
+
setSession({ installed, isUser, isUserActive, isLocked, did, token, externalService, serviceName, apiUrl, }?: SetSessionParams): Promise<void>;
|
|
1542
1614
|
externalServiceDisconnect(): void;
|
|
1543
1615
|
getLang(): string;
|
|
1544
1616
|
setLang(lang: string): void;
|