@0xsequence/dapp-client 0.0.0-20251119142848 → 3.0.0-beta.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.
@@ -1,5 +1,5 @@
1
1
 
2
2
  
3
- > @0xsequence/dapp-client@0.0.0-20251119142848 build /Users/taylan/Development/Horizon/sequence.js/packages/wallet/dapp-client
3
+ > @0xsequence/dapp-client@3.0.0-beta.1 build /Users/taylan/Development/Horizon/sequence.js/packages/wallet/dapp-client
4
4
  > tsc
5
5
 
package/CHANGELOG.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # @0xsequence/dapp-client
2
2
 
3
- ## 0.0.0-20251119142848
3
+ ## 3.0.0-beta.1
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - 3.0.0-beta.1
7
8
  - Updated dependencies
8
- - @0xsequence/guard@0.0.0-20251119142848
9
- - @0xsequence/relayer@0.0.0-20251119142848
10
- - @0xsequence/wallet-core@0.0.0-20251119142848
11
- - @0xsequence/wallet-primitives@0.0.0-20251119142848
9
+ - @0xsequence/guard@3.0.0-beta.1
10
+ - @0xsequence/relayer@3.0.0-beta.1
11
+ - @0xsequence/wallet-core@3.0.0-beta.1
12
+ - @0xsequence/wallet-primitives@3.0.0-beta.1
@@ -1 +1 @@
1
- {"version":3,"file":"ChainSessionManager.d.ts","sourceRoot":"","sources":["../src/ChainSessionManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,OAAO,EAAE,GAAG,EAAqC,MAAM,IAAI,CAAA;AAcjF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAWlD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,EAEL,4BAA4B,EAC5B,WAAW,EACX,kBAAkB,EAElB,WAAW,EAEX,WAAW,EAKX,SAAS,EAGV,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,Y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GAAG,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAC1E,OAAO,CAAC,OAAO,CAAC;IAsCnB;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI;IAI1C,QAAQ,IAAI,WAAW,GAAG,SAAS;IAInC;;;OAGG;IACH,mBAAmB,IAAI,eAAe,EAAE;IAIxC;;;OAGG;IACH,kBAAkB,IAAI,eAAe,GAAG,IAAI;IAI5C;;;;OAIG;YACW,kBAAkB;IAwDhC;;;;;OAKG;YACW,0BAA0B;IAcxC;;OAEG;IACH,OAAO,CAAC,WAAW;IAUnB;;OAEG;YACW,8BAA8B;CAM7C"}
@@ -46,7 +46,8 @@ export class ChainSessionManager {
46
46
  console.log(`ChainSessionManager instance created: ${this.instanceId} for chain ${chainId}`);
47
47
  const rpcUrl = getRpcUrl(chainId, nodesUrl, projectAccessKey);
48
48
  this.chainId = chainId;
49
- if (canUseIndexedDb) {
49
+ const canUseIndexedDbInEnv = canUseIndexedDb && typeof indexedDB !== 'undefined';
50
+ if (canUseIndexedDbInEnv) {
50
51
  this.stateProvider = new State.Cached({
51
52
  source: new State.Sequence.Provider(keyMachineUrl),
52
53
  cache: new State.Local.Provider(new State.Local.IndexedDbStore(CACHE_DB_NAME)),
@@ -37,6 +37,7 @@ export declare class DappClient {
37
37
  private chainSessionManagers;
38
38
  private walletUrl;
39
39
  private transport;
40
+ private transportModeSetting;
40
41
  private projectAccessKey;
41
42
  private nodesUrl;
42
43
  private relayerUrl;
@@ -52,6 +53,7 @@ export declare class DappClient {
52
53
  private hasSessionlessConnection;
53
54
  private cachedSessionlessConnection;
54
55
  private eventListeners;
56
+ private get isBrowser();
55
57
  /**
56
58
  * @param walletUrl The URL of the Wallet Webapp.
57
59
  * @param origin The origin of the dapp
@@ -429,6 +431,7 @@ export declare class DappClient {
429
431
  * @param args The data to emit with the event.
430
432
  */
431
433
  private emit;
434
+ private ensureTransport;
432
435
  private applySessionlessConnectionState;
433
436
  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oB;IAuClC;;;;OAIG;YACW,2BAA2B;IAiBzC;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;CAyB/B"}
@@ -34,7 +34,8 @@ export class DappClient {
34
34
  origin;
35
35
  chainSessionManagers = new Map();
36
36
  walletUrl;
37
- transport;
37
+ transport = null;
38
+ transportModeSetting;
38
39
  projectAccessKey;
39
40
  nodesUrl;
40
41
  relayerUrl;
@@ -50,6 +51,9 @@ export class DappClient {
50
51
  hasSessionlessConnection = false;
51
52
  cachedSessionlessConnection = null;
52
53
  eventListeners = {};
54
+ get isBrowser() {
55
+ return typeof window !== 'undefined' && typeof document !== 'undefined';
56
+ }
53
57
  /**
54
58
  * @param walletUrl The URL of the Wallet Webapp.
55
59
  * @param origin The origin of the dapp
@@ -68,8 +72,8 @@ export class DappClient {
68
72
  */
69
73
  constructor(walletUrl, origin, projectAccessKey, options) {
70
74
  const { transportMode = TransportMode.POPUP, keymachineUrl = KEYMACHINE_URL, redirectPath, sequenceStorage = new WebStorage(), sequenceSessionStorage, randomPrivateKeyFn, redirectActionHandler, canUseIndexedDb = true, } = options || {};
71
- this.transport = new DappTransport(walletUrl, transportMode, undefined, sequenceSessionStorage, redirectActionHandler);
72
75
  this.walletUrl = walletUrl;
76
+ this.transportModeSetting = transportMode;
73
77
  this.projectAccessKey = projectAccessKey;
74
78
  this.nodesUrl = options?.nodesUrl || NODES_URL;
75
79
  this.relayerUrl = options?.relayerUrl || RELAYER_URL;
@@ -86,7 +90,7 @@ export class DappClient {
86
90
  * @returns The transport mode of the client. {@link TransportMode}
87
91
  */
88
92
  get transportMode() {
89
- return this.transport.mode;
93
+ return this.transport?.mode ?? this.transportModeSetting;
90
94
  }
91
95
  /**
92
96
  * Registers an event listener for a specific event.
@@ -345,7 +349,10 @@ export class DappClient {
345
349
  */
346
350
  async handleRedirectResponse(url) {
347
351
  const pendingRequest = await this.sequenceStorage.peekPendingRequest();
348
- const response = await this.transport.getRedirectResponse(true, url);
352
+ if (!this.transport && this.transportMode === TransportMode.POPUP && !this.isBrowser) {
353
+ return;
354
+ }
355
+ const response = await this.ensureTransport().getRedirectResponse(true, url);
349
356
  if (!response) {
350
357
  return;
351
358
  }
@@ -441,7 +448,7 @@ export class DappClient {
441
448
  await chainSessionManager.createNewSession(this.origin, sessionConfig, options);
442
449
  // For popup mode, we need to manually update the state and emit an event.
443
450
  // For redirect mode, this code won't be reached; the page will navigate away.
444
- if (this.transport.mode === TransportMode.POPUP) {
451
+ if (this.transportMode === TransportMode.POPUP) {
445
452
  const hasImplicitSession = !!chainSessionManager.getImplicitSession();
446
453
  const hasExplicitSessions = chainSessionManager.getExplicitSessions().length > 0;
447
454
  if (shouldCreateSession && (hasImplicitSession || hasExplicitSessions)) {
@@ -496,7 +503,7 @@ export class DappClient {
496
503
  }
497
504
  chainSessionManager = chainSessionManager ?? this.getChainSessionManager(chainId);
498
505
  await chainSessionManager.createNewSession(this.origin, sessionConfig, options);
499
- if (this.transport.mode === TransportMode.POPUP) {
506
+ if (this.transportMode === TransportMode.POPUP) {
500
507
  const hasImplicitSession = !!chainSessionManager.getImplicitSession();
501
508
  const hasExplicitSessions = chainSessionManager.getExplicitSessions().length > 0;
502
509
  if (shouldCreateSession && (hasImplicitSession || hasExplicitSessions)) {
@@ -558,7 +565,7 @@ export class DappClient {
558
565
  chainSessionManager.initializeWithWallet(this.walletAddress);
559
566
  }
560
567
  await chainSessionManager.addExplicitSession(explicitSessionConfig);
561
- if (this.transport.mode === TransportMode.POPUP) {
568
+ if (this.transportMode === TransportMode.POPUP) {
562
569
  await this._loadStateFromStorage();
563
570
  }
564
571
  }
@@ -590,7 +597,7 @@ export class DappClient {
590
597
  chainSessionManager.initializeWithWallet(this.walletAddress);
591
598
  }
592
599
  await chainSessionManager.modifyExplicitSession(explicitSession);
593
- if (this.transport.mode === TransportMode.POPUP) {
600
+ if (this.transportMode === TransportMode.POPUP) {
594
601
  await this._loadStateFromStorage();
595
602
  }
596
603
  }
@@ -787,9 +794,11 @@ export class DappClient {
787
794
  */
788
795
  async disconnect(options) {
789
796
  const keepSessionlessConnection = options?.keepSessionlessConnection ?? true;
790
- const transportMode = this.transport.mode;
791
- this.transport.destroy();
792
- this.transport = new DappTransport(this.walletUrl, transportMode, undefined, this.sequenceSessionStorage, this.redirectActionHandler);
797
+ const transportMode = this.transportMode;
798
+ if (this.transport) {
799
+ this.transport.destroy();
800
+ }
801
+ this.transport = null;
793
802
  this.chainSessionManagers.clear();
794
803
  const sessionlessSnapshot = keepSessionlessConnection && this.walletAddress
795
804
  ? {
@@ -831,6 +840,15 @@ export class DappClient {
831
840
  listeners.forEach((listener) => listener(...args));
832
841
  }
833
842
  }
843
+ ensureTransport() {
844
+ if (!this.transport) {
845
+ if (this.transportModeSetting === TransportMode.POPUP && !this.isBrowser) {
846
+ throw new InitializationError('Popup transport requires a browser environment.');
847
+ }
848
+ this.transport = new DappTransport(this.walletUrl, this.transportModeSetting, undefined, this.sequenceSessionStorage, this.redirectActionHandler);
849
+ }
850
+ return this.transport;
851
+ }
834
852
  async applySessionlessConnectionState(walletAddress, loginMethod, userEmail, guard, persist = true) {
835
853
  this.walletAddress = walletAddress;
836
854
  this.loginMethod = loginMethod ?? null;
@@ -856,17 +874,18 @@ export class DappClient {
856
874
  try {
857
875
  const redirectUrl = this.origin + (this.redirectPath ? this.redirectPath : '');
858
876
  const path = action === RequestActionType.SEND_WALLET_TRANSACTION ? '/request/transaction' : '/request/sign';
859
- if (this.transport.mode === TransportMode.REDIRECT) {
877
+ const transport = this.ensureTransport();
878
+ if (transport.mode === TransportMode.REDIRECT) {
860
879
  await this.sequenceStorage.savePendingRequest({
861
880
  action,
862
881
  payload,
863
882
  chainId: chainId,
864
883
  });
865
884
  await this.sequenceStorage.setPendingRedirectRequest(true);
866
- await this.transport.sendRequest(action, redirectUrl, payload, { path });
885
+ await transport.sendRequest(action, redirectUrl, payload, { path });
867
886
  }
868
887
  else {
869
- const response = await this.transport.sendRequest(action, redirectUrl, payload, {
888
+ const response = await transport.sendRequest(action, redirectUrl, payload, {
870
889
  path,
871
890
  });
872
891
  this.emit('walletActionResponse', { action, response, chainId });
@@ -878,7 +897,7 @@ export class DappClient {
878
897
  throw error;
879
898
  }
880
899
  finally {
881
- if (this.transport.mode === TransportMode.POPUP) {
900
+ if (this.transportMode === TransportMode.POPUP && this.transport) {
882
901
  this.transport.closeWallet();
883
902
  }
884
903
  }
@@ -912,7 +931,8 @@ export class DappClient {
912
931
  getChainSessionManager(chainId) {
913
932
  let chainSessionManager = this.chainSessionManagers.get(chainId);
914
933
  if (!chainSessionManager) {
915
- chainSessionManager = new ChainSessionManager(chainId, this.transport, this.projectAccessKey, this.keymachineUrl, this.nodesUrl, this.relayerUrl, this.sequenceStorage, this.origin + (this.redirectPath ? this.redirectPath : ''), this.guard, this.randomPrivateKeyFn, this.canUseIndexedDb);
934
+ const transport = this.ensureTransport();
935
+ chainSessionManager = new ChainSessionManager(chainId, transport, this.projectAccessKey, this.keymachineUrl, this.nodesUrl, this.relayerUrl, this.sequenceStorage, this.origin + (this.redirectPath ? this.redirectPath : ''), this.guard, this.randomPrivateKeyFn, this.canUseIndexedDb);
916
936
  this.chainSessionManagers.set(chainId, chainSessionManager);
917
937
  chainSessionManager.on('explicitSessionResponse', (data) => {
918
938
  this.emit('explicitSessionResponse', { ...data, chainId });
@@ -17,6 +17,7 @@ export declare class DappTransport {
17
17
  private readonly handshakeTimeoutMs;
18
18
  private readonly sequenceSessionStorage;
19
19
  private readonly redirectActionHandler?;
20
+ private readonly isBrowser;
20
21
  readonly walletOrigin: string;
21
22
  constructor(walletUrl: string, mode?: TransportMode, popupModeOptions?: PopupModeOptions, sequenceSessionStorage?: SequenceSessionStorage, redirectActionHandler?: (url: string) => void);
22
23
  get isWalletOpen(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"DappTransport.d.ts","sourceRoot":"","sources":["../src/DappTransport.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EAEt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E,GAAG,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IA4EnF,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgExC,WAAW,IAAI,IAAI;IAgB1B,OAAO,IAAI,IAAI;IAYf,OAAO,CAAC,aAAa,CAuCpB;IAED,OAAO,CAAC,wBAAwB;IAiChC,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,mBAAmB;IAkD3B,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,UAAU;CAGnB"}
@@ -1,6 +1,25 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { jsonReplacers, jsonRevivers } from './utils/index.js';
3
3
  import { MessageType, TransportMode, WalletSize, } from './types/index.js';
4
+ const isBrowserEnvironment = typeof window !== 'undefined' && typeof document !== 'undefined';
5
+ const base64Encode = (value) => {
6
+ if (typeof btoa !== 'undefined') {
7
+ return btoa(value);
8
+ }
9
+ if (typeof Buffer !== 'undefined') {
10
+ return Buffer.from(value, 'utf-8').toString('base64');
11
+ }
12
+ throw new Error('Base64 encoding is not supported in this environment.');
13
+ };
14
+ const base64Decode = (value) => {
15
+ if (typeof atob !== 'undefined') {
16
+ return atob(value);
17
+ }
18
+ if (typeof Buffer !== 'undefined') {
19
+ return Buffer.from(value, 'base64').toString('utf-8');
20
+ }
21
+ throw new Error('Base64 decoding is not supported in this environment.');
22
+ };
4
23
  var ConnectionState;
5
24
  (function (ConnectionState) {
6
25
  ConnectionState["DISCONNECTED"] = "DISCONNECTED";
@@ -26,10 +45,12 @@ export class DappTransport {
26
45
  handshakeTimeoutMs;
27
46
  sequenceSessionStorage;
28
47
  redirectActionHandler;
48
+ isBrowser;
29
49
  walletOrigin;
30
50
  constructor(walletUrl, mode = TransportMode.POPUP, popupModeOptions = {}, sequenceSessionStorage, redirectActionHandler) {
31
51
  this.walletUrl = walletUrl;
32
52
  this.mode = mode;
53
+ this.isBrowser = isBrowserEnvironment;
33
54
  try {
34
55
  this.walletOrigin = new URL(walletUrl).origin;
35
56
  }
@@ -41,18 +62,24 @@ export class DappTransport {
41
62
  console.error('[DApp] Could not determine a valid wallet origin from the URL:', walletUrl);
42
63
  throw new Error('Invalid wallet origin derived from walletUrl.');
43
64
  }
44
- if (sequenceSessionStorage) {
45
- this.sequenceSessionStorage = sequenceSessionStorage;
46
- }
47
- else if (typeof window !== 'undefined' && window.sessionStorage) {
48
- this.sequenceSessionStorage = window.sessionStorage;
49
- }
50
- else {
51
- throw new Error('A storage implementation must be provided for non-browser environments.');
52
- }
65
+ this.sequenceSessionStorage =
66
+ sequenceSessionStorage ||
67
+ {
68
+ getItem: (key) => (this.isBrowser && window.sessionStorage ? window.sessionStorage.getItem(key) : null),
69
+ setItem: (key, value) => {
70
+ if (this.isBrowser && window.sessionStorage) {
71
+ window.sessionStorage.setItem(key, value);
72
+ }
73
+ },
74
+ removeItem: (key) => {
75
+ if (this.isBrowser && window.sessionStorage) {
76
+ window.sessionStorage.removeItem(key);
77
+ }
78
+ },
79
+ };
53
80
  this.requestTimeoutMs = popupModeOptions.requestTimeoutMs ?? 300000;
54
81
  this.handshakeTimeoutMs = popupModeOptions.handshakeTimeoutMs ?? 15000;
55
- if (this.mode === TransportMode.POPUP) {
82
+ if (this.mode === TransportMode.POPUP && this.isBrowser) {
56
83
  window.addEventListener('message', this.handleMessage);
57
84
  }
58
85
  this.redirectActionHandler = redirectActionHandler;
@@ -68,15 +95,21 @@ export class DappTransport {
68
95
  return this.connectionState === ConnectionState.CONNECTED;
69
96
  }
70
97
  async sendRequest(action, redirectUrl, payload, options = {}) {
98
+ if (!this.isBrowser && this.mode === TransportMode.POPUP) {
99
+ throw new Error('Popup transport requires a browser environment. Use redirect mode or provide a redirect handler.');
100
+ }
71
101
  if (this.mode === TransportMode.REDIRECT) {
72
102
  const url = await this.getRequestRedirectUrl(action, payload, redirectUrl, options.path);
73
103
  if (this.redirectActionHandler) {
74
104
  this.redirectActionHandler(url);
75
105
  }
76
- else {
106
+ else if (this.isBrowser) {
77
107
  console.info('[DappTransport] No redirectActionHandler provided. Using window.location.href to navigate.');
78
108
  window.location.href = url;
79
109
  }
110
+ else {
111
+ throw new Error('Redirect navigation is not possible outside the browser without a redirectActionHandler. Provide a handler to perform navigation.');
112
+ }
80
113
  return new Promise(() => { });
81
114
  }
82
115
  if (this.connectionState !== ConnectionState.CONNECTED) {
@@ -114,7 +147,7 @@ export class DappTransport {
114
147
  console.error('Failed to set redirect request in storage', e);
115
148
  throw new Error('Could not save redirect state to storage. Redirect flow is unavailable.');
116
149
  }
117
- const serializedPayload = btoa(JSON.stringify(payload || {}, jsonReplacers));
150
+ const serializedPayload = base64Encode(JSON.stringify(payload || {}, jsonReplacers));
118
151
  const fullWalletUrl = path ? `${this.walletUrl}${path}` : this.walletUrl;
119
152
  const url = new URL(fullWalletUrl);
120
153
  url.searchParams.set('action', action);
@@ -125,7 +158,11 @@ export class DappTransport {
125
158
  return url.toString();
126
159
  }
127
160
  async getRedirectResponse(cleanState = true, url) {
128
- const params = new URLSearchParams(url ? new URL(url).search : window.location.search);
161
+ if (!url && !this.isBrowser) {
162
+ throw new Error('A URL must be provided when handling redirect responses outside of a browser environment.');
163
+ }
164
+ const search = url ? new URL(url).search : this.isBrowser ? window.location.search : '';
165
+ const params = new URLSearchParams(search);
129
166
  const responseId = params.get('id');
130
167
  if (!responseId)
131
168
  return null;
@@ -150,10 +187,9 @@ export class DappTransport {
150
187
  }
151
188
  const responsePayloadB64 = params.get('payload');
152
189
  const responseErrorB64 = params.get('error');
153
- const isBrowser = typeof window !== 'undefined' && window.history;
154
190
  if (cleanState) {
155
191
  await this.sequenceSessionStorage.removeItem(REDIRECT_REQUEST_KEY);
156
- if (isBrowser && !url) {
192
+ if (this.isBrowser && !url && window.history) {
157
193
  const cleanUrl = new URL(window.location.href);
158
194
  ['id', 'payload', 'error', 'mode'].forEach((p) => cleanUrl.searchParams.delete(p));
159
195
  history.replaceState({}, document.title, cleanUrl.toString());
@@ -162,7 +198,7 @@ export class DappTransport {
162
198
  if (responseErrorB64) {
163
199
  try {
164
200
  return {
165
- error: JSON.parse(atob(responseErrorB64), jsonRevivers),
201
+ error: JSON.parse(base64Decode(responseErrorB64), jsonRevivers),
166
202
  action: originalRequest.action,
167
203
  };
168
204
  }
@@ -177,7 +213,7 @@ export class DappTransport {
177
213
  if (responsePayloadB64) {
178
214
  try {
179
215
  return {
180
- payload: JSON.parse(atob(responsePayloadB64), jsonRevivers),
216
+ payload: JSON.parse(base64Decode(responsePayloadB64), jsonRevivers),
181
217
  action: originalRequest.action,
182
218
  };
183
219
  }
@@ -198,6 +234,9 @@ export class DappTransport {
198
234
  if (this.mode === TransportMode.REDIRECT) {
199
235
  throw new Error("`openWallet` is not available in 'redirect' mode.");
200
236
  }
237
+ if (!this.isBrowser) {
238
+ throw new Error('Popup transport requires a browser environment.');
239
+ }
201
240
  if (this.connectionState !== ConnectionState.DISCONNECTED) {
202
241
  if (this.isWalletOpen)
203
242
  this.walletWindow?.focus();
@@ -264,13 +303,16 @@ export class DappTransport {
264
303
  this._resetConnection(new Error('Wallet closed intentionally by DApp.'), 'Wallet closed intentionally by DApp.');
265
304
  }
266
305
  destroy() {
267
- if (this.mode === TransportMode.POPUP) {
306
+ if (this.mode === TransportMode.POPUP && this.isBrowser) {
268
307
  window.removeEventListener('message', this.handleMessage);
269
308
  if (this.isWalletOpen) {
270
309
  this.walletWindow?.close();
271
310
  }
272
311
  this._resetConnection(new Error('Transport destroyed.'), 'Destroying transport...');
273
312
  }
313
+ else {
314
+ this._resetConnection(new Error('Transport destroyed.'), 'Destroying transport...');
315
+ }
274
316
  }
275
317
  handleMessage = (event) => {
276
318
  if (event.origin !== this.walletOrigin) {
@@ -421,7 +463,7 @@ export class DappTransport {
421
463
  const requestsToClear = new Map(this.pendingRequests);
422
464
  this.pendingRequests.clear();
423
465
  requestsToClear.forEach((pending) => {
424
- window.clearTimeout(pending.timer);
466
+ clearTimeout(pending.timer);
425
467
  const errorToSend = reason instanceof Error ? reason : new Error(`Operation failed: ${reason}`);
426
468
  pending.reject(errorToSend);
427
469
  });
@@ -429,11 +471,11 @@ export class DappTransport {
429
471
  }
430
472
  clearTimeouts() {
431
473
  if (this.handshakeTimeoutId !== undefined) {
432
- window.clearTimeout(this.handshakeTimeoutId);
474
+ clearTimeout(this.handshakeTimeoutId);
433
475
  this.handshakeTimeoutId = undefined;
434
476
  }
435
477
  if (this.closeCheckIntervalId !== undefined) {
436
- window.clearInterval(this.closeCheckIntervalId);
478
+ clearInterval(this.closeCheckIntervalId);
437
479
  this.closeCheckIntervalId = undefined;
438
480
  }
439
481
  }
@@ -1,6 +1,6 @@
1
1
  export declare const CACHE_DB_NAME = "sequence-cache";
2
2
  export declare const NODES_URL = "https://nodes.sequence.app/{network}";
3
3
  export declare const RELAYER_URL = "https://{network}-relayer.sequence.app";
4
- export declare const KEYMACHINE_URL = "https://v3-keymachine.sequence.app";
4
+ export declare const KEYMACHINE_URL = "https://keymachine.sequence.app";
5
5
  export declare const VALUE_FORWARDER_ADDRESS = "0xABAAd93EeE2a569cF0632f39B10A9f5D734777ca";
6
6
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAC7C,eAAO,MAAM,SAAS,yCAAyC,CAAA;AAC/D,eAAO,MAAM,WAAW,2CAA2C,CAAA;AACnE,eAAO,MAAM,cAAc,uCAAuC,CAAA;AAClE,eAAO,MAAM,uBAAuB,+CAA+C,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAC7C,eAAO,MAAM,SAAS,yCAAyC,CAAA;AAC/D,eAAO,MAAM,WAAW,2CAA2C,CAAA;AACnE,eAAO,MAAM,cAAc,oCAAoC,CAAA;AAC/D,eAAO,MAAM,uBAAuB,+CAA+C,CAAA"}
@@ -1,5 +1,5 @@
1
1
  export const CACHE_DB_NAME = 'sequence-cache';
2
2
  export const NODES_URL = 'https://nodes.sequence.app/{network}';
3
3
  export const RELAYER_URL = 'https://{network}-relayer.sequence.app';
4
- export const KEYMACHINE_URL = 'https://v3-keymachine.sequence.app';
4
+ export const KEYMACHINE_URL = 'https://keymachine.sequence.app';
5
5
  export const VALUE_FORWARDER_ADDRESS = '0xABAAd93EeE2a569cF0632f39B10A9f5D734777ca';
@@ -54,6 +54,7 @@ export interface SequenceStorage {
54
54
  clearAllData(): Promise<void>;
55
55
  }
56
56
  export declare class WebStorage implements SequenceStorage {
57
+ private inMemoryDb;
57
58
  private openDB;
58
59
  private getIDBItem;
59
60
  private setIDBItem;
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAA;AAEjC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,4BAA4B,EAC5B,4BAA4B,EAC5B,uBAAuB,EACvB,yBAAyB,EAC1B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,GAAG,CAAC,GAAG,CAAA;IACX,aAAa,EAAE,OAAO,CAAC,OAAO,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,WAAW,CAAA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CAAkC,IAAI,OAAO,CAAC,IAAI,CAAC;IASnD,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAmBpC"}
@@ -1,5 +1,8 @@
1
1
  import { Address } from 'ox';
2
2
  import { jsonReplacers, jsonRevivers } from './index.js';
3
+ const isBrowser = typeof window !== 'undefined';
4
+ const hasSessionStorage = isBrowser && typeof sessionStorage !== 'undefined';
5
+ const hasIndexedDb = typeof indexedDB !== 'undefined';
3
6
  const DB_NAME = 'SequenceDappStorage';
4
7
  const DB_VERSION = 1;
5
8
  const STORE_NAME = 'userKeys';
@@ -11,7 +14,11 @@ const PENDING_REDIRECT_REQUEST_KEY = 'SequencePendingRedirect';
11
14
  const TEMP_SESSION_PK_KEY = 'SequencePendingTempSessionPk';
12
15
  const PENDING_REQUEST_CONTEXT_KEY = 'SequencePendingRequestContext';
13
16
  export class WebStorage {
17
+ inMemoryDb = new Map();
14
18
  openDB() {
19
+ if (!hasIndexedDb) {
20
+ return Promise.reject(new Error('IndexedDB is not available in this environment.'));
21
+ }
15
22
  return new Promise((resolve, reject) => {
16
23
  const request = indexedDB.open(DB_NAME, DB_VERSION);
17
24
  request.onerror = (event) => reject(`IndexedDB error: ${event.target.error}`);
@@ -25,6 +32,9 @@ export class WebStorage {
25
32
  });
26
33
  }
27
34
  async getIDBItem(key) {
35
+ if (!hasIndexedDb) {
36
+ return this.inMemoryDb.get(key);
37
+ }
28
38
  const db = await this.openDB();
29
39
  return new Promise((resolve, reject) => {
30
40
  const request = db.transaction(STORE_NAME, 'readonly').objectStore(STORE_NAME).get(key);
@@ -33,6 +43,10 @@ export class WebStorage {
33
43
  });
34
44
  }
35
45
  async setIDBItem(key, value) {
46
+ if (!hasIndexedDb) {
47
+ this.inMemoryDb.set(key, value);
48
+ return;
49
+ }
36
50
  const db = await this.openDB();
37
51
  return new Promise((resolve, reject) => {
38
52
  const request = db.transaction(STORE_NAME, 'readwrite').objectStore(STORE_NAME).put(value, key);
@@ -41,6 +55,10 @@ export class WebStorage {
41
55
  });
42
56
  }
43
57
  async deleteIDBItem(key) {
58
+ if (!hasIndexedDb) {
59
+ this.inMemoryDb.delete(key);
60
+ return;
61
+ }
44
62
  const db = await this.openDB();
45
63
  return new Promise((resolve, reject) => {
46
64
  const request = db.transaction(STORE_NAME, 'readwrite').objectStore(STORE_NAME).delete(key);
@@ -50,12 +68,12 @@ export class WebStorage {
50
68
  }
51
69
  async setPendingRedirectRequest(isPending) {
52
70
  try {
53
- if (isPending) {
71
+ if (!hasSessionStorage)
72
+ return;
73
+ if (isPending)
54
74
  sessionStorage.setItem(PENDING_REDIRECT_REQUEST_KEY, 'true');
55
- }
56
- else {
75
+ else
57
76
  sessionStorage.removeItem(PENDING_REDIRECT_REQUEST_KEY);
58
- }
59
77
  }
60
78
  catch (error) {
61
79
  console.error('Failed to set pending redirect flag:', error);
@@ -63,6 +81,8 @@ export class WebStorage {
63
81
  }
64
82
  async isRedirectRequestPending() {
65
83
  try {
84
+ if (!hasSessionStorage)
85
+ return false;
66
86
  return sessionStorage.getItem(PENDING_REDIRECT_REQUEST_KEY) === 'true';
67
87
  }
68
88
  catch (error) {
@@ -72,6 +92,8 @@ export class WebStorage {
72
92
  }
73
93
  async saveTempSessionPk(pk) {
74
94
  try {
95
+ if (!hasSessionStorage)
96
+ return;
75
97
  sessionStorage.setItem(TEMP_SESSION_PK_KEY, pk);
76
98
  }
77
99
  catch (error) {
@@ -80,6 +102,8 @@ export class WebStorage {
80
102
  }
81
103
  async getAndClearTempSessionPk() {
82
104
  try {
105
+ if (!hasSessionStorage)
106
+ return null;
83
107
  const pk = sessionStorage.getItem(TEMP_SESSION_PK_KEY);
84
108
  sessionStorage.removeItem(TEMP_SESSION_PK_KEY);
85
109
  return pk;
@@ -91,6 +115,8 @@ export class WebStorage {
91
115
  }
92
116
  async savePendingRequest(context) {
93
117
  try {
118
+ if (!hasSessionStorage)
119
+ return;
94
120
  sessionStorage.setItem(PENDING_REQUEST_CONTEXT_KEY, JSON.stringify(context, jsonReplacers));
95
121
  }
96
122
  catch (error) {
@@ -99,6 +125,8 @@ export class WebStorage {
99
125
  }
100
126
  async getAndClearPendingRequest() {
101
127
  try {
128
+ if (!hasSessionStorage)
129
+ return null;
102
130
  const context = sessionStorage.getItem(PENDING_REQUEST_CONTEXT_KEY);
103
131
  if (!context)
104
132
  return null;
@@ -112,6 +140,8 @@ export class WebStorage {
112
140
  }
113
141
  async peekPendingRequest() {
114
142
  try {
143
+ if (!hasSessionStorage)
144
+ return null;
115
145
  const context = sessionStorage.getItem(PENDING_REQUEST_CONTEXT_KEY);
116
146
  if (!context)
117
147
  return null;
@@ -237,9 +267,11 @@ export class WebStorage {
237
267
  async clearAllData() {
238
268
  try {
239
269
  // Clear all session storage items
240
- sessionStorage.removeItem(PENDING_REDIRECT_REQUEST_KEY);
241
- sessionStorage.removeItem(TEMP_SESSION_PK_KEY);
242
- sessionStorage.removeItem(PENDING_REQUEST_CONTEXT_KEY);
270
+ if (hasSessionStorage) {
271
+ sessionStorage.removeItem(PENDING_REDIRECT_REQUEST_KEY);
272
+ sessionStorage.removeItem(TEMP_SESSION_PK_KEY);
273
+ sessionStorage.removeItem(PENDING_REQUEST_CONTEXT_KEY);
274
+ }
243
275
  // Clear all IndexedDB items
244
276
  await this.clearExplicitSessions();
245
277
  await this.clearImplicitSession();
package/eslint.config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { config } from "@repo/eslint-config/react-internal";
1
+ import { config as baseConfig } from "@repo/eslint-config/base"
2
2
 
3
3
  /** @type {import("eslint").Linter.Config} */
4
- export default config;
4
+ export default baseConfig
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/dapp-client",
3
- "version": "0.0.0-20251119142848",
3
+ "version": "3.0.0-beta.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "ox": "^0.7.2",
28
- "@0xsequence/relayer": "^0.0.0-20251119142848",
29
- "@0xsequence/wallet-primitives": "^0.0.0-20251119142848",
30
- "@0xsequence/guard": "^0.0.0-20251119142848",
31
- "@0xsequence/wallet-core": "^0.0.0-20251119142848"
28
+ "@0xsequence/guard": "^3.0.0-beta.1",
29
+ "@0xsequence/relayer": "^3.0.0-beta.1",
30
+ "@0xsequence/wallet-primitives": "^3.0.0-beta.1",
31
+ "@0xsequence/wallet-core": "^3.0.0-beta.1"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsc",
@@ -114,7 +114,8 @@ export class ChainSessionManager {
114
114
  const rpcUrl = getRpcUrl(chainId, nodesUrl, projectAccessKey)
115
115
  this.chainId = chainId
116
116
 
117
- if (canUseIndexedDb) {
117
+ const canUseIndexedDbInEnv = canUseIndexedDb && typeof indexedDB !== 'undefined'
118
+ if (canUseIndexedDbInEnv) {
118
119
  this.stateProvider = new State.Cached({
119
120
  source: new State.Sequence.Provider(keyMachineUrl),
120
121
  cache: new State.Local.Provider(new State.Local.IndexedDbStore(CACHE_DB_NAME)),
package/src/DappClient.ts CHANGED
@@ -69,7 +69,8 @@ export class DappClient {
69
69
  private chainSessionManagers: Map<number, ChainSessionManager> = new Map()
70
70
 
71
71
  private walletUrl: string
72
- private transport: DappTransport
72
+ private transport: DappTransport | null = null
73
+ private transportModeSetting: TransportMode
73
74
  private projectAccessKey: string
74
75
  private nodesUrl: string
75
76
  private relayerUrl: string
@@ -90,6 +91,10 @@ export class DappClient {
90
91
  [K in keyof DappClientEventMap]?: Set<DappClientEventMap[K]>
91
92
  } = {}
92
93
 
94
+ private get isBrowser(): boolean {
95
+ return typeof window !== 'undefined' && typeof document !== 'undefined'
96
+ }
97
+
93
98
  /**
94
99
  * @param walletUrl The URL of the Wallet Webapp.
95
100
  * @param origin The origin of the dapp
@@ -134,14 +139,8 @@ export class DappClient {
134
139
  canUseIndexedDb = true,
135
140
  } = options || {}
136
141
 
137
- this.transport = new DappTransport(
138
- walletUrl,
139
- transportMode,
140
- undefined,
141
- sequenceSessionStorage,
142
- redirectActionHandler,
143
- )
144
142
  this.walletUrl = walletUrl
143
+ this.transportModeSetting = transportMode
145
144
  this.projectAccessKey = projectAccessKey
146
145
  this.nodesUrl = options?.nodesUrl || NODES_URL
147
146
  this.relayerUrl = options?.relayerUrl || RELAYER_URL
@@ -159,7 +158,7 @@ export class DappClient {
159
158
  * @returns The transport mode of the client. {@link TransportMode}
160
159
  */
161
160
  public get transportMode(): TransportMode {
162
- return this.transport.mode
161
+ return this.transport?.mode ?? this.transportModeSetting
163
162
  }
164
163
 
165
164
  /**
@@ -445,7 +444,11 @@ export class DappClient {
445
444
  public async handleRedirectResponse(url?: string): Promise<void> {
446
445
  const pendingRequest = await this.sequenceStorage.peekPendingRequest()
447
446
 
448
- const response = await this.transport.getRedirectResponse(true, url)
447
+ if (!this.transport && this.transportMode === TransportMode.POPUP && !this.isBrowser) {
448
+ return
449
+ }
450
+
451
+ const response = await this.ensureTransport().getRedirectResponse(true, url)
449
452
  if (!response) {
450
453
  return
451
454
  }
@@ -570,7 +573,7 @@ export class DappClient {
570
573
 
571
574
  // For popup mode, we need to manually update the state and emit an event.
572
575
  // For redirect mode, this code won't be reached; the page will navigate away.
573
- if (this.transport.mode === TransportMode.POPUP) {
576
+ if (this.transportMode === TransportMode.POPUP) {
574
577
  const hasImplicitSession = !!chainSessionManager.getImplicitSession()
575
578
  const hasExplicitSessions = chainSessionManager.getExplicitSessions().length > 0
576
579
  if (shouldCreateSession && (hasImplicitSession || hasExplicitSessions)) {
@@ -645,7 +648,7 @@ export class DappClient {
645
648
  chainSessionManager = chainSessionManager ?? this.getChainSessionManager(chainId)
646
649
  await chainSessionManager.createNewSession(this.origin, sessionConfig, options)
647
650
 
648
- if (this.transport.mode === TransportMode.POPUP) {
651
+ if (this.transportMode === TransportMode.POPUP) {
649
652
  const hasImplicitSession = !!chainSessionManager.getImplicitSession()
650
653
  const hasExplicitSessions = chainSessionManager.getExplicitSessions().length > 0
651
654
 
@@ -719,7 +722,7 @@ export class DappClient {
719
722
  }
720
723
  await chainSessionManager.addExplicitSession(explicitSessionConfig)
721
724
 
722
- if (this.transport.mode === TransportMode.POPUP) {
725
+ if (this.transportMode === TransportMode.POPUP) {
723
726
  await this._loadStateFromStorage()
724
727
  }
725
728
  }
@@ -754,7 +757,7 @@ export class DappClient {
754
757
  }
755
758
  await chainSessionManager.modifyExplicitSession(explicitSession)
756
759
 
757
- if (this.transport.mode === TransportMode.POPUP) {
760
+ if (this.transportMode === TransportMode.POPUP) {
758
761
  await this._loadStateFromStorage()
759
762
  }
760
763
  }
@@ -962,16 +965,12 @@ export class DappClient {
962
965
  async disconnect(options?: { keepSessionlessConnection?: boolean }): Promise<void> {
963
966
  const keepSessionlessConnection = options?.keepSessionlessConnection ?? true
964
967
 
965
- const transportMode = this.transport.mode
968
+ const transportMode = this.transportMode
966
969
 
967
- this.transport.destroy()
968
- this.transport = new DappTransport(
969
- this.walletUrl,
970
- transportMode,
971
- undefined,
972
- this.sequenceSessionStorage,
973
- this.redirectActionHandler,
974
- )
970
+ if (this.transport) {
971
+ this.transport.destroy()
972
+ }
973
+ this.transport = null
975
974
 
976
975
  this.chainSessionManagers.clear()
977
976
  const sessionlessSnapshot =
@@ -1019,6 +1018,22 @@ export class DappClient {
1019
1018
  }
1020
1019
  }
1021
1020
 
1021
+ private ensureTransport(): DappTransport {
1022
+ if (!this.transport) {
1023
+ if (this.transportModeSetting === TransportMode.POPUP && !this.isBrowser) {
1024
+ throw new InitializationError('Popup transport requires a browser environment.')
1025
+ }
1026
+ this.transport = new DappTransport(
1027
+ this.walletUrl,
1028
+ this.transportModeSetting,
1029
+ undefined,
1030
+ this.sequenceSessionStorage,
1031
+ this.redirectActionHandler,
1032
+ )
1033
+ }
1034
+ return this.transport
1035
+ }
1036
+
1022
1037
  private async applySessionlessConnectionState(
1023
1038
  walletAddress: Address.Address,
1024
1039
  loginMethod?: LoginMethod | null,
@@ -1056,17 +1071,18 @@ export class DappClient {
1056
1071
  try {
1057
1072
  const redirectUrl = this.origin + (this.redirectPath ? this.redirectPath : '')
1058
1073
  const path = action === RequestActionType.SEND_WALLET_TRANSACTION ? '/request/transaction' : '/request/sign'
1074
+ const transport = this.ensureTransport()
1059
1075
 
1060
- if (this.transport.mode === TransportMode.REDIRECT) {
1076
+ if (transport.mode === TransportMode.REDIRECT) {
1061
1077
  await this.sequenceStorage.savePendingRequest({
1062
1078
  action,
1063
1079
  payload,
1064
1080
  chainId: chainId,
1065
1081
  })
1066
1082
  await this.sequenceStorage.setPendingRedirectRequest(true)
1067
- await this.transport.sendRequest(action, redirectUrl, payload, { path })
1083
+ await transport.sendRequest(action, redirectUrl, payload, { path })
1068
1084
  } else {
1069
- const response = await this.transport.sendRequest<WalletActionResponse>(action, redirectUrl, payload, {
1085
+ const response = await transport.sendRequest<WalletActionResponse>(action, redirectUrl, payload, {
1070
1086
  path,
1071
1087
  })
1072
1088
  this.emit('walletActionResponse', { action, response, chainId })
@@ -1076,7 +1092,7 @@ export class DappClient {
1076
1092
  this.emit('walletActionResponse', { action, error, chainId })
1077
1093
  throw error
1078
1094
  } finally {
1079
- if (this.transport.mode === TransportMode.POPUP) {
1095
+ if (this.transportMode === TransportMode.POPUP && this.transport) {
1080
1096
  this.transport.closeWallet()
1081
1097
  }
1082
1098
  }
@@ -1112,9 +1128,10 @@ export class DappClient {
1112
1128
  private getChainSessionManager(chainId: number): ChainSessionManager {
1113
1129
  let chainSessionManager = this.chainSessionManagers.get(chainId)
1114
1130
  if (!chainSessionManager) {
1131
+ const transport = this.ensureTransport()
1115
1132
  chainSessionManager = new ChainSessionManager(
1116
1133
  chainId,
1117
- this.transport,
1134
+ transport,
1118
1135
  this.projectAccessKey,
1119
1136
  this.keymachineUrl,
1120
1137
  this.nodesUrl,
@@ -12,6 +12,28 @@ import {
12
12
  WalletSize,
13
13
  } from './types/index.js'
14
14
 
15
+ const isBrowserEnvironment = typeof window !== 'undefined' && typeof document !== 'undefined'
16
+
17
+ const base64Encode = (value: string) => {
18
+ if (typeof btoa !== 'undefined') {
19
+ return btoa(value)
20
+ }
21
+ if (typeof Buffer !== 'undefined') {
22
+ return Buffer.from(value, 'utf-8').toString('base64')
23
+ }
24
+ throw new Error('Base64 encoding is not supported in this environment.')
25
+ }
26
+
27
+ const base64Decode = (value: string) => {
28
+ if (typeof atob !== 'undefined') {
29
+ return atob(value)
30
+ }
31
+ if (typeof Buffer !== 'undefined') {
32
+ return Buffer.from(value, 'base64').toString('utf-8')
33
+ }
34
+ throw new Error('Base64 decoding is not supported in this environment.')
35
+ }
36
+
15
37
  enum ConnectionState {
16
38
  DISCONNECTED = 'DISCONNECTED',
17
39
  CONNECTING = 'CONNECTING',
@@ -36,6 +58,7 @@ export class DappTransport {
36
58
  private readonly handshakeTimeoutMs: number
37
59
  private readonly sequenceSessionStorage: SequenceSessionStorage
38
60
  private readonly redirectActionHandler?: (url: string) => void
61
+ private readonly isBrowser: boolean
39
62
 
40
63
  public readonly walletOrigin: string
41
64
 
@@ -46,6 +69,7 @@ export class DappTransport {
46
69
  sequenceSessionStorage?: SequenceSessionStorage,
47
70
  redirectActionHandler?: (url: string) => void,
48
71
  ) {
72
+ this.isBrowser = isBrowserEnvironment
49
73
  try {
50
74
  this.walletOrigin = new URL(walletUrl).origin
51
75
  } catch (e) {
@@ -57,18 +81,26 @@ export class DappTransport {
57
81
  throw new Error('Invalid wallet origin derived from walletUrl.')
58
82
  }
59
83
 
60
- if (sequenceSessionStorage) {
61
- this.sequenceSessionStorage = sequenceSessionStorage
62
- } else if (typeof window !== 'undefined' && window.sessionStorage) {
63
- this.sequenceSessionStorage = window.sessionStorage
64
- } else {
65
- throw new Error('A storage implementation must be provided for non-browser environments.')
66
- }
84
+ this.sequenceSessionStorage =
85
+ sequenceSessionStorage ||
86
+ ({
87
+ getItem: (key: string) => (this.isBrowser && window.sessionStorage ? window.sessionStorage.getItem(key) : null),
88
+ setItem: (key: string, value: string) => {
89
+ if (this.isBrowser && window.sessionStorage) {
90
+ window.sessionStorage.setItem(key, value)
91
+ }
92
+ },
93
+ removeItem: (key: string) => {
94
+ if (this.isBrowser && window.sessionStorage) {
95
+ window.sessionStorage.removeItem(key)
96
+ }
97
+ },
98
+ } satisfies SequenceSessionStorage)
67
99
 
68
100
  this.requestTimeoutMs = popupModeOptions.requestTimeoutMs ?? 300000
69
101
  this.handshakeTimeoutMs = popupModeOptions.handshakeTimeoutMs ?? 15000
70
102
 
71
- if (this.mode === TransportMode.POPUP) {
103
+ if (this.mode === TransportMode.POPUP && this.isBrowser) {
72
104
  window.addEventListener('message', this.handleMessage)
73
105
  }
74
106
 
@@ -91,13 +123,23 @@ export class DappTransport {
91
123
  payload?: TRequest,
92
124
  options: SendRequestOptions = {},
93
125
  ): Promise<TResponse> {
126
+ if (!this.isBrowser && this.mode === TransportMode.POPUP) {
127
+ throw new Error(
128
+ 'Popup transport requires a browser environment. Use redirect mode or provide a redirect handler.',
129
+ )
130
+ }
131
+
94
132
  if (this.mode === TransportMode.REDIRECT) {
95
133
  const url = await this.getRequestRedirectUrl(action, payload, redirectUrl, options.path)
96
134
  if (this.redirectActionHandler) {
97
135
  this.redirectActionHandler(url)
98
- } else {
136
+ } else if (this.isBrowser) {
99
137
  console.info('[DappTransport] No redirectActionHandler provided. Using window.location.href to navigate.')
100
138
  window.location.href = url
139
+ } else {
140
+ throw new Error(
141
+ 'Redirect navigation is not possible outside the browser without a redirectActionHandler. Provide a handler to perform navigation.',
142
+ )
101
143
  }
102
144
  return new Promise<TResponse>(() => {})
103
145
  }
@@ -148,7 +190,7 @@ export class DappTransport {
148
190
  throw new Error('Could not save redirect state to storage. Redirect flow is unavailable.')
149
191
  }
150
192
 
151
- const serializedPayload = btoa(JSON.stringify(payload || {}, jsonReplacers))
193
+ const serializedPayload = base64Encode(JSON.stringify(payload || {}, jsonReplacers))
152
194
  const fullWalletUrl = path ? `${this.walletUrl}${path}` : this.walletUrl
153
195
  const url = new URL(fullWalletUrl)
154
196
  url.searchParams.set('action', action)
@@ -164,7 +206,12 @@ export class DappTransport {
164
206
  cleanState: boolean = true,
165
207
  url?: string,
166
208
  ): Promise<{ payload: TResponse; action: string } | { error: any; action: string } | null> {
167
- const params = new URLSearchParams(url ? new URL(url).search : window.location.search)
209
+ if (!url && !this.isBrowser) {
210
+ throw new Error('A URL must be provided when handling redirect responses outside of a browser environment.')
211
+ }
212
+
213
+ const search = url ? new URL(url).search : this.isBrowser ? window.location.search : ''
214
+ const params = new URLSearchParams(search)
168
215
  const responseId = params.get('id')
169
216
  if (!responseId) return null
170
217
 
@@ -191,11 +238,9 @@ export class DappTransport {
191
238
  const responsePayloadB64 = params.get('payload')
192
239
  const responseErrorB64 = params.get('error')
193
240
 
194
- const isBrowser = typeof window !== 'undefined' && window.history
195
-
196
241
  if (cleanState) {
197
242
  await this.sequenceSessionStorage.removeItem(REDIRECT_REQUEST_KEY)
198
- if (isBrowser && !url) {
243
+ if (this.isBrowser && !url && window.history) {
199
244
  const cleanUrl = new URL(window.location.href)
200
245
  ;['id', 'payload', 'error', 'mode'].forEach((p) => cleanUrl.searchParams.delete(p))
201
246
  history.replaceState({}, document.title, cleanUrl.toString())
@@ -205,7 +250,7 @@ export class DappTransport {
205
250
  if (responseErrorB64) {
206
251
  try {
207
252
  return {
208
- error: JSON.parse(atob(responseErrorB64), jsonRevivers),
253
+ error: JSON.parse(base64Decode(responseErrorB64), jsonRevivers),
209
254
  action: originalRequest.action,
210
255
  }
211
256
  } catch (e) {
@@ -219,7 +264,7 @@ export class DappTransport {
219
264
  if (responsePayloadB64) {
220
265
  try {
221
266
  return {
222
- payload: JSON.parse(atob(responsePayloadB64), jsonRevivers),
267
+ payload: JSON.parse(base64Decode(responsePayloadB64), jsonRevivers),
223
268
  action: originalRequest.action,
224
269
  }
225
270
  } catch (e) {
@@ -240,6 +285,9 @@ export class DappTransport {
240
285
  if (this.mode === TransportMode.REDIRECT) {
241
286
  throw new Error("`openWallet` is not available in 'redirect' mode.")
242
287
  }
288
+ if (!this.isBrowser) {
289
+ throw new Error('Popup transport requires a browser environment.')
290
+ }
243
291
  if (this.connectionState !== ConnectionState.DISCONNECTED) {
244
292
  if (this.isWalletOpen) this.walletWindow?.focus()
245
293
  return this.readyPromise || Promise.resolve()
@@ -314,12 +362,14 @@ export class DappTransport {
314
362
  }
315
363
 
316
364
  destroy(): void {
317
- if (this.mode === TransportMode.POPUP) {
365
+ if (this.mode === TransportMode.POPUP && this.isBrowser) {
318
366
  window.removeEventListener('message', this.handleMessage)
319
367
  if (this.isWalletOpen) {
320
368
  this.walletWindow?.close()
321
369
  }
322
370
  this._resetConnection(new Error('Transport destroyed.'), 'Destroying transport...')
371
+ } else {
372
+ this._resetConnection(new Error('Transport destroyed.'), 'Destroying transport...')
323
373
  }
324
374
  }
325
375
 
@@ -494,7 +544,7 @@ export class DappTransport {
494
544
  const requestsToClear = new Map(this.pendingRequests)
495
545
  this.pendingRequests.clear()
496
546
  requestsToClear.forEach((pending) => {
497
- window.clearTimeout(pending.timer)
547
+ clearTimeout(pending.timer)
498
548
  const errorToSend = reason instanceof Error ? reason : new Error(`Operation failed: ${reason}`)
499
549
  pending.reject(errorToSend)
500
550
  })
@@ -503,11 +553,11 @@ export class DappTransport {
503
553
 
504
554
  private clearTimeouts(): void {
505
555
  if (this.handshakeTimeoutId !== undefined) {
506
- window.clearTimeout(this.handshakeTimeoutId)
556
+ clearTimeout(this.handshakeTimeoutId)
507
557
  this.handshakeTimeoutId = undefined
508
558
  }
509
559
  if (this.closeCheckIntervalId !== undefined) {
510
- window.clearInterval(this.closeCheckIntervalId)
560
+ clearInterval(this.closeCheckIntervalId)
511
561
  this.closeCheckIntervalId = undefined
512
562
  }
513
563
  }
@@ -1,5 +1,5 @@
1
1
  export const CACHE_DB_NAME = 'sequence-cache'
2
2
  export const NODES_URL = 'https://nodes.sequence.app/{network}'
3
3
  export const RELAYER_URL = 'https://{network}-relayer.sequence.app'
4
- export const KEYMACHINE_URL = 'https://v3-keymachine.sequence.app'
4
+ export const KEYMACHINE_URL = 'https://keymachine.sequence.app'
5
5
  export const VALUE_FORWARDER_ADDRESS = '0xABAAd93EeE2a569cF0632f39B10A9f5D734777ca'
@@ -13,6 +13,10 @@ import {
13
13
 
14
14
  import { Attestation } from '../index.js'
15
15
 
16
+ const isBrowser = typeof window !== 'undefined'
17
+ const hasSessionStorage = isBrowser && typeof sessionStorage !== 'undefined'
18
+ const hasIndexedDb = typeof indexedDB !== 'undefined'
19
+
16
20
  export interface ExplicitSessionData {
17
21
  pk: Hex.Hex
18
22
  walletAddress: Address.Address
@@ -97,7 +101,12 @@ const TEMP_SESSION_PK_KEY = 'SequencePendingTempSessionPk'
97
101
  const PENDING_REQUEST_CONTEXT_KEY = 'SequencePendingRequestContext'
98
102
 
99
103
  export class WebStorage implements SequenceStorage {
104
+ private inMemoryDb = new Map<IDBValidKey, unknown>()
105
+
100
106
  private openDB(): Promise<IDBDatabase> {
107
+ if (!hasIndexedDb) {
108
+ return Promise.reject(new Error('IndexedDB is not available in this environment.'))
109
+ }
101
110
  return new Promise((resolve, reject) => {
102
111
  const request = indexedDB.open(DB_NAME, DB_VERSION)
103
112
  request.onerror = (event) => reject(`IndexedDB error: ${(event.target as IDBRequest).error}`)
@@ -112,6 +121,9 @@ export class WebStorage implements SequenceStorage {
112
121
  }
113
122
 
114
123
  private async getIDBItem<T>(key: IDBValidKey): Promise<T | undefined> {
124
+ if (!hasIndexedDb) {
125
+ return this.inMemoryDb.get(key) as T | undefined
126
+ }
115
127
  const db = await this.openDB()
116
128
  return new Promise((resolve, reject) => {
117
129
  const request = db.transaction(STORE_NAME, 'readonly').objectStore(STORE_NAME).get(key)
@@ -121,6 +133,10 @@ export class WebStorage implements SequenceStorage {
121
133
  }
122
134
 
123
135
  private async setIDBItem(key: IDBValidKey, value: unknown): Promise<void> {
136
+ if (!hasIndexedDb) {
137
+ this.inMemoryDb.set(key, value)
138
+ return
139
+ }
124
140
  const db = await this.openDB()
125
141
  return new Promise((resolve, reject) => {
126
142
  const request = db.transaction(STORE_NAME, 'readwrite').objectStore(STORE_NAME).put(value, key)
@@ -130,6 +146,10 @@ export class WebStorage implements SequenceStorage {
130
146
  }
131
147
 
132
148
  private async deleteIDBItem(key: IDBValidKey): Promise<void> {
149
+ if (!hasIndexedDb) {
150
+ this.inMemoryDb.delete(key)
151
+ return
152
+ }
133
153
  const db = await this.openDB()
134
154
  return new Promise((resolve, reject) => {
135
155
  const request = db.transaction(STORE_NAME, 'readwrite').objectStore(STORE_NAME).delete(key)
@@ -140,11 +160,9 @@ export class WebStorage implements SequenceStorage {
140
160
 
141
161
  async setPendingRedirectRequest(isPending: boolean): Promise<void> {
142
162
  try {
143
- if (isPending) {
144
- sessionStorage.setItem(PENDING_REDIRECT_REQUEST_KEY, 'true')
145
- } else {
146
- sessionStorage.removeItem(PENDING_REDIRECT_REQUEST_KEY)
147
- }
163
+ if (!hasSessionStorage) return
164
+ if (isPending) sessionStorage.setItem(PENDING_REDIRECT_REQUEST_KEY, 'true')
165
+ else sessionStorage.removeItem(PENDING_REDIRECT_REQUEST_KEY)
148
166
  } catch (error) {
149
167
  console.error('Failed to set pending redirect flag:', error)
150
168
  }
@@ -152,6 +170,7 @@ export class WebStorage implements SequenceStorage {
152
170
 
153
171
  async isRedirectRequestPending(): Promise<boolean> {
154
172
  try {
173
+ if (!hasSessionStorage) return false
155
174
  return sessionStorage.getItem(PENDING_REDIRECT_REQUEST_KEY) === 'true'
156
175
  } catch (error) {
157
176
  console.error('Failed to check pending redirect flag:', error)
@@ -161,6 +180,7 @@ export class WebStorage implements SequenceStorage {
161
180
 
162
181
  async saveTempSessionPk(pk: Hex.Hex): Promise<void> {
163
182
  try {
183
+ if (!hasSessionStorage) return
164
184
  sessionStorage.setItem(TEMP_SESSION_PK_KEY, pk)
165
185
  } catch (error) {
166
186
  console.error('Failed to save temp session PK:', error)
@@ -169,6 +189,7 @@ export class WebStorage implements SequenceStorage {
169
189
 
170
190
  async getAndClearTempSessionPk(): Promise<Hex.Hex | null> {
171
191
  try {
192
+ if (!hasSessionStorage) return null
172
193
  const pk = sessionStorage.getItem(TEMP_SESSION_PK_KEY)
173
194
  sessionStorage.removeItem(TEMP_SESSION_PK_KEY)
174
195
  return pk as Hex.Hex | null
@@ -180,6 +201,7 @@ export class WebStorage implements SequenceStorage {
180
201
 
181
202
  async savePendingRequest(context: PendingRequestContext): Promise<void> {
182
203
  try {
204
+ if (!hasSessionStorage) return
183
205
  sessionStorage.setItem(PENDING_REQUEST_CONTEXT_KEY, JSON.stringify(context, jsonReplacers))
184
206
  } catch (error) {
185
207
  console.error('Failed to save pending request context:', error)
@@ -188,6 +210,7 @@ export class WebStorage implements SequenceStorage {
188
210
 
189
211
  async getAndClearPendingRequest(): Promise<PendingRequestContext | null> {
190
212
  try {
213
+ if (!hasSessionStorage) return null
191
214
  const context = sessionStorage.getItem(PENDING_REQUEST_CONTEXT_KEY)
192
215
  if (!context) return null
193
216
  sessionStorage.removeItem(PENDING_REQUEST_CONTEXT_KEY)
@@ -200,6 +223,7 @@ export class WebStorage implements SequenceStorage {
200
223
 
201
224
  async peekPendingRequest(): Promise<PendingRequestContext | null> {
202
225
  try {
226
+ if (!hasSessionStorage) return null
203
227
  const context = sessionStorage.getItem(PENDING_REQUEST_CONTEXT_KEY)
204
228
  if (!context) return null
205
229
  return JSON.parse(context, jsonRevivers)
@@ -329,9 +353,11 @@ export class WebStorage implements SequenceStorage {
329
353
  async clearAllData(): Promise<void> {
330
354
  try {
331
355
  // Clear all session storage items
332
- sessionStorage.removeItem(PENDING_REDIRECT_REQUEST_KEY)
333
- sessionStorage.removeItem(TEMP_SESSION_PK_KEY)
334
- sessionStorage.removeItem(PENDING_REQUEST_CONTEXT_KEY)
356
+ if (hasSessionStorage) {
357
+ sessionStorage.removeItem(PENDING_REDIRECT_REQUEST_KEY)
358
+ sessionStorage.removeItem(TEMP_SESSION_PK_KEY)
359
+ sessionStorage.removeItem(PENDING_REQUEST_CONTEXT_KEY)
360
+ }
335
361
 
336
362
  // Clear all IndexedDB items
337
363
  await this.clearExplicitSessions()