@block-auth.io/core 0.4.2 → 0.5.2

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.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
- constructor(url?: string, reconnect?: boolean);
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;
@@ -1131,6 +1168,7 @@ declare function createBlockAuthClient(config: BlockAuthClientConfig): {
1131
1168
  closeAllModals: () => void;
1132
1169
  wsConnectTimeout: number;
1133
1170
  wsConnectRetries: number;
1171
+ apiUrl: string | undefined;
1134
1172
  provider: BlockAuthProvider;
1135
1173
  };
1136
1174
  type BlockAuthClient = ReturnType<typeof createBlockAuthClient>;
@@ -1507,8 +1545,14 @@ interface SetSessionParams {
1507
1545
  token?: string;
1508
1546
  externalService?: Partial<ExternalServiceConfig>;
1509
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;
1510
1552
  }
1511
1553
  declare class BrowserBase {
1554
+ private _sessionToken;
1555
+ private _externalToken;
1512
1556
  /**
1513
1557
  * Wipe every SDK-owned localStorage key and reseed the defaults. Unlike a
1514
1558
  * per-key reset it also clears the `blockauth-logged-out` /
@@ -1538,16 +1582,35 @@ declare class BrowserBase {
1538
1582
  */
1539
1583
  setUILocked(isLocked: boolean): void;
1540
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
+ */
1541
1590
  getSession(): SessionConfig;
1542
1591
  /**
1543
- * Obtains the configuration about the address and the service
1544
- * where the user is connected.
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.
1545
1595
  */
1546
1596
  getExternalService(): ExternalServiceConfig;
1547
1597
  /**
1548
- * Auxiliary method to update the SESSION configuration using websocket events.
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`.
1549
1612
  */
1550
- 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>;
1551
1614
  externalServiceDisconnect(): void;
1552
1615
  getLang(): string;
1553
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
- constructor(url?: string, reconnect?: boolean);
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;
@@ -1131,6 +1168,7 @@ declare function createBlockAuthClient(config: BlockAuthClientConfig): {
1131
1168
  closeAllModals: () => void;
1132
1169
  wsConnectTimeout: number;
1133
1170
  wsConnectRetries: number;
1171
+ apiUrl: string | undefined;
1134
1172
  provider: BlockAuthProvider;
1135
1173
  };
1136
1174
  type BlockAuthClient = ReturnType<typeof createBlockAuthClient>;
@@ -1507,8 +1545,14 @@ interface SetSessionParams {
1507
1545
  token?: string;
1508
1546
  externalService?: Partial<ExternalServiceConfig>;
1509
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;
1510
1552
  }
1511
1553
  declare class BrowserBase {
1554
+ private _sessionToken;
1555
+ private _externalToken;
1512
1556
  /**
1513
1557
  * Wipe every SDK-owned localStorage key and reseed the defaults. Unlike a
1514
1558
  * per-key reset it also clears the `blockauth-logged-out` /
@@ -1538,16 +1582,35 @@ declare class BrowserBase {
1538
1582
  */
1539
1583
  setUILocked(isLocked: boolean): void;
1540
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
+ */
1541
1590
  getSession(): SessionConfig;
1542
1591
  /**
1543
- * Obtains the configuration about the address and the service
1544
- * where the user is connected.
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.
1545
1595
  */
1546
1596
  getExternalService(): ExternalServiceConfig;
1547
1597
  /**
1548
- * Auxiliary method to update the SESSION configuration using websocket events.
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`.
1549
1612
  */
1550
- 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>;
1551
1614
  externalServiceDisconnect(): void;
1552
1615
  getLang(): string;
1553
1616
  setLang(lang: string): void;