@0xsequence/provider 0.40.0 → 0.40.3

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.
@@ -593,19 +593,19 @@ class WalletRequestHandler {
593
593
  let sig = ''; // Message must be prefixed with "\x19Ethereum Signed Message:\n"
594
594
  // as defined by EIP-191
595
595
 
596
- message = prefixEIP191Message(message); // TODO:
596
+ const prefixedMessage = prefixEIP191Message(message); // TODO:
597
597
  // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
598
598
 
599
599
  if (_this.prompter === null) {
600
600
  // prompter is null, so we'll sign from here
601
- sig = await signer.signMessage(ethers.ethers.utils.arrayify(message), chainId);
601
+ sig = await signer.signMessage(prefixedMessage, chainId);
602
602
  } else {
603
603
  const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, signer, chainId);
604
604
 
605
605
  if (promptResultForDeployment) {
606
606
  sig = await _this.prompter.promptSignMessage({
607
607
  chainId: chainId,
608
- message
608
+ message: prefixedMessage
609
609
  }, _this.connectOptions);
610
610
  }
611
611
  }
@@ -3366,13 +3366,28 @@ class Wallet {
3366
3366
  this.useSession({
3367
3367
  walletContext: walletContext
3368
3368
  }, true);
3369
- }); // Load existing session from localStorage
3369
+ });
3370
+ };
3371
+
3372
+ this.loadSession = async function () {
3373
+ const data = await LocalStorage.getInstance().getItem('@sequence.session');
3374
+
3375
+ if (!data || data === '') {
3376
+ return undefined;
3377
+ }
3378
+
3379
+ try {
3380
+ const session = JSON.parse(data);
3370
3381
 
3371
- this.loadSession().then(session => {
3372
3382
  if (session) {
3373
- this.useSession(session, false);
3383
+ _this.useSession(session, false);
3374
3384
  }
3375
- });
3385
+
3386
+ return session;
3387
+ } catch (err) {
3388
+ utils.logger.warn('loadSession failed, unable to parse session payload from storage.');
3389
+ return undefined;
3390
+ }
3376
3391
  };
3377
3392
 
3378
3393
  this.connect = async function (options) {
@@ -3506,26 +3521,10 @@ class Wallet {
3506
3521
  this.transport.messageProvider.closeWallet();
3507
3522
  };
3508
3523
 
3509
- this.loadSession = async function () {
3510
- const data = await LocalStorage.getInstance().getItem('@sequence.session');
3511
-
3512
- if (!data || data === '') {
3513
- return undefined;
3514
- }
3515
-
3516
- try {
3517
- const session = JSON.parse(data);
3518
- return session;
3519
- } catch (err) {
3520
- utils.logger.warn('loadSession failed, unable to parse session payload from localStorage.');
3521
- return undefined;
3522
- }
3523
- };
3524
-
3525
- this.saveSession = session => {
3524
+ this.saveSession = async function (session) {
3526
3525
  utils.logger.debug('wallet provider: saving session');
3527
3526
  const data = JSON.stringify(session);
3528
- LocalStorage.getInstance().setItem('@sequence.session', data);
3527
+ await LocalStorage.getInstance().setItem('@sequence.session', data);
3529
3528
  };
3530
3529
 
3531
3530
  this.useSession = async function (session, autoSave = true) {
@@ -3805,12 +3804,13 @@ const DefaultProviderConfig = {
3805
3804
  }
3806
3805
  };
3807
3806
  let walletInstance;
3808
- const initWallet = (network, config) => {
3807
+ const initWallet = async (network, config) => {
3809
3808
  if (walletInstance && walletInstance.isOpened()) {
3810
3809
  walletInstance.closeWallet();
3811
3810
  }
3812
3811
 
3813
3812
  walletInstance = new Wallet(network, config);
3813
+ await walletInstance.loadSession();
3814
3814
  return walletInstance;
3815
3815
  };
3816
3816
  const getWallet = () => {
@@ -593,19 +593,19 @@ class WalletRequestHandler {
593
593
  let sig = ''; // Message must be prefixed with "\x19Ethereum Signed Message:\n"
594
594
  // as defined by EIP-191
595
595
 
596
- message = prefixEIP191Message(message); // TODO:
596
+ const prefixedMessage = prefixEIP191Message(message); // TODO:
597
597
  // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
598
598
 
599
599
  if (_this.prompter === null) {
600
600
  // prompter is null, so we'll sign from here
601
- sig = await signer.signMessage(ethers.ethers.utils.arrayify(message), chainId);
601
+ sig = await signer.signMessage(prefixedMessage, chainId);
602
602
  } else {
603
603
  const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, signer, chainId);
604
604
 
605
605
  if (promptResultForDeployment) {
606
606
  sig = await _this.prompter.promptSignMessage({
607
607
  chainId: chainId,
608
- message
608
+ message: prefixedMessage
609
609
  }, _this.connectOptions);
610
610
  }
611
611
  }
@@ -3366,13 +3366,28 @@ class Wallet {
3366
3366
  this.useSession({
3367
3367
  walletContext: walletContext
3368
3368
  }, true);
3369
- }); // Load existing session from localStorage
3369
+ });
3370
+ };
3371
+
3372
+ this.loadSession = async function () {
3373
+ const data = await LocalStorage.getInstance().getItem('@sequence.session');
3374
+
3375
+ if (!data || data === '') {
3376
+ return undefined;
3377
+ }
3378
+
3379
+ try {
3380
+ const session = JSON.parse(data);
3370
3381
 
3371
- this.loadSession().then(session => {
3372
3382
  if (session) {
3373
- this.useSession(session, false);
3383
+ _this.useSession(session, false);
3374
3384
  }
3375
- });
3385
+
3386
+ return session;
3387
+ } catch (err) {
3388
+ utils.logger.warn('loadSession failed, unable to parse session payload from storage.');
3389
+ return undefined;
3390
+ }
3376
3391
  };
3377
3392
 
3378
3393
  this.connect = async function (options) {
@@ -3506,26 +3521,10 @@ class Wallet {
3506
3521
  this.transport.messageProvider.closeWallet();
3507
3522
  };
3508
3523
 
3509
- this.loadSession = async function () {
3510
- const data = await LocalStorage.getInstance().getItem('@sequence.session');
3511
-
3512
- if (!data || data === '') {
3513
- return undefined;
3514
- }
3515
-
3516
- try {
3517
- const session = JSON.parse(data);
3518
- return session;
3519
- } catch (err) {
3520
- utils.logger.warn('loadSession failed, unable to parse session payload from localStorage.');
3521
- return undefined;
3522
- }
3523
- };
3524
-
3525
- this.saveSession = session => {
3524
+ this.saveSession = async function (session) {
3526
3525
  utils.logger.debug('wallet provider: saving session');
3527
3526
  const data = JSON.stringify(session);
3528
- LocalStorage.getInstance().setItem('@sequence.session', data);
3527
+ await LocalStorage.getInstance().setItem('@sequence.session', data);
3529
3528
  };
3530
3529
 
3531
3530
  this.useSession = async function (session, autoSave = true) {
@@ -3805,12 +3804,13 @@ const DefaultProviderConfig = {
3805
3804
  }
3806
3805
  };
3807
3806
  let walletInstance;
3808
- const initWallet = (network, config) => {
3807
+ const initWallet = async (network, config) => {
3809
3808
  if (walletInstance && walletInstance.isOpened()) {
3810
3809
  walletInstance.closeWallet();
3811
3810
  }
3812
3811
 
3813
3812
  walletInstance = new Wallet(network, config);
3813
+ await walletInstance.loadSession();
3814
3814
  return walletInstance;
3815
3815
  };
3816
3816
  const getWallet = () => {
@@ -589,19 +589,19 @@ class WalletRequestHandler {
589
589
  let sig = ''; // Message must be prefixed with "\x19Ethereum Signed Message:\n"
590
590
  // as defined by EIP-191
591
591
 
592
- message = prefixEIP191Message(message); // TODO:
592
+ const prefixedMessage = prefixEIP191Message(message); // TODO:
593
593
  // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
594
594
 
595
595
  if (_this.prompter === null) {
596
596
  // prompter is null, so we'll sign from here
597
- sig = await signer.signMessage(ethers.utils.arrayify(message), chainId);
597
+ sig = await signer.signMessage(prefixedMessage, chainId);
598
598
  } else {
599
599
  const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, signer, chainId);
600
600
 
601
601
  if (promptResultForDeployment) {
602
602
  sig = await _this.prompter.promptSignMessage({
603
603
  chainId: chainId,
604
- message
604
+ message: prefixedMessage
605
605
  }, _this.connectOptions);
606
606
  }
607
607
  }
@@ -3362,13 +3362,28 @@ class Wallet {
3362
3362
  this.useSession({
3363
3363
  walletContext: walletContext
3364
3364
  }, true);
3365
- }); // Load existing session from localStorage
3365
+ });
3366
+ };
3367
+
3368
+ this.loadSession = async function () {
3369
+ const data = await LocalStorage.getInstance().getItem('@sequence.session');
3370
+
3371
+ if (!data || data === '') {
3372
+ return undefined;
3373
+ }
3374
+
3375
+ try {
3376
+ const session = JSON.parse(data);
3366
3377
 
3367
- this.loadSession().then(session => {
3368
3378
  if (session) {
3369
- this.useSession(session, false);
3379
+ _this.useSession(session, false);
3370
3380
  }
3371
- });
3381
+
3382
+ return session;
3383
+ } catch (err) {
3384
+ logger.warn('loadSession failed, unable to parse session payload from storage.');
3385
+ return undefined;
3386
+ }
3372
3387
  };
3373
3388
 
3374
3389
  this.connect = async function (options) {
@@ -3502,26 +3517,10 @@ class Wallet {
3502
3517
  this.transport.messageProvider.closeWallet();
3503
3518
  };
3504
3519
 
3505
- this.loadSession = async function () {
3506
- const data = await LocalStorage.getInstance().getItem('@sequence.session');
3507
-
3508
- if (!data || data === '') {
3509
- return undefined;
3510
- }
3511
-
3512
- try {
3513
- const session = JSON.parse(data);
3514
- return session;
3515
- } catch (err) {
3516
- logger.warn('loadSession failed, unable to parse session payload from localStorage.');
3517
- return undefined;
3518
- }
3519
- };
3520
-
3521
- this.saveSession = session => {
3520
+ this.saveSession = async function (session) {
3522
3521
  logger.debug('wallet provider: saving session');
3523
3522
  const data = JSON.stringify(session);
3524
- LocalStorage.getInstance().setItem('@sequence.session', data);
3523
+ await LocalStorage.getInstance().setItem('@sequence.session', data);
3525
3524
  };
3526
3525
 
3527
3526
  this.useSession = async function (session, autoSave = true) {
@@ -3801,12 +3800,13 @@ const DefaultProviderConfig = {
3801
3800
  }
3802
3801
  };
3803
3802
  let walletInstance;
3804
- const initWallet = (network, config) => {
3803
+ const initWallet = async (network, config) => {
3805
3804
  if (walletInstance && walletInstance.isOpened()) {
3806
3805
  walletInstance.closeWallet();
3807
3806
  }
3808
3807
 
3809
3808
  walletInstance = new Wallet(network, config);
3809
+ await walletInstance.loadSession();
3810
3810
  return walletInstance;
3811
3811
  };
3812
3812
  const getWallet = () => {
@@ -192,7 +192,7 @@ export declare type OpenWalletIntent = {
192
192
  method: string;
193
193
  };
194
194
  export interface MessageToSign {
195
- message?: string;
195
+ message?: Uint8Array;
196
196
  typedData?: TypedData;
197
197
  chainId?: number;
198
198
  }
@@ -6,17 +6,16 @@ import { WalletSession, ProviderEventTypes, ConnectOptions, OpenWalletIntent, Co
6
6
  import { ItemStore } from './utils';
7
7
  import { WalletUtils } from './utils/index';
8
8
  import { Runtime } from 'webextension-polyfill-ts';
9
- import { sequence } from '../../0xsequence/src';
10
9
  export interface WalletProvider {
11
10
  connect(options?: ConnectOptions): Promise<ConnectDetails>;
12
11
  disconnect(): void;
13
- isOpened(): boolean;
14
12
  isConnected(): boolean;
15
13
  getSession(): WalletSession | undefined;
16
14
  getAddress(): Promise<string>;
17
15
  getNetworks(chainId?: ChainIdLike): Promise<NetworkConfig[]>;
18
16
  getChainId(): Promise<number>;
19
17
  getAuthChainId(): Promise<number>;
18
+ isOpened(): boolean;
20
19
  openWallet(path?: string, intent?: OpenWalletIntent, networkId?: string | number): Promise<boolean>;
21
20
  closeWallet(): void;
22
21
  getProvider(chainId?: ChainIdLike): Web3Provider | undefined;
@@ -40,6 +39,7 @@ export declare class Wallet implements WalletProvider {
40
39
  private providers;
41
40
  constructor(network?: string | number, config?: Partial<ProviderConfig>);
42
41
  private init;
42
+ loadSession: () => Promise<WalletSession | undefined>;
43
43
  connect: (options?: ConnectOptions | undefined) => Promise<ConnectDetails>;
44
44
  addConnectedSite(origin: string | undefined): Promise<void>;
45
45
  removeConnectedSite(origin: string): Promise<void>;
@@ -71,7 +71,6 @@ export declare class Wallet implements WalletProvider {
71
71
  isDeployed(chainId?: ChainIdLike): Promise<boolean>;
72
72
  on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
73
73
  once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
74
- private loadSession;
75
74
  private saveSession;
76
75
  private useSession;
77
76
  private useAccountAddress;
@@ -100,5 +99,5 @@ export interface ProviderConfig {
100
99
  walletContext?: WalletContext;
101
100
  }
102
101
  export declare const DefaultProviderConfig: ProviderConfig;
103
- export declare const initWallet: (network?: string | number | undefined, config?: Partial<sequence.provider.ProviderConfig> | undefined) => sequence.provider.Wallet;
104
- export declare const getWallet: () => sequence.provider.Wallet;
102
+ export declare const initWallet: (network?: string | number | undefined, config?: Partial<ProviderConfig> | undefined) => Promise<Wallet>;
103
+ export declare const getWallet: () => Wallet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.40.0",
3
+ "version": "0.40.3",
4
4
  "description": "provider sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
6
6
  "source": "src/index.ts",
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@0xsequence/abi": "^0.40.0",
17
- "@0xsequence/auth": "^0.40.0",
18
- "@0xsequence/config": "^0.40.0",
19
- "@0xsequence/network": "^0.40.0",
20
- "@0xsequence/transactions": "^0.40.0",
21
- "@0xsequence/utils": "^0.40.0",
22
- "@0xsequence/wallet": "^0.40.0",
16
+ "@0xsequence/abi": "^0.40.3",
17
+ "@0xsequence/auth": "^0.40.3",
18
+ "@0xsequence/config": "^0.40.3",
19
+ "@0xsequence/network": "^0.40.3",
20
+ "@0xsequence/transactions": "^0.40.3",
21
+ "@0xsequence/utils": "^0.40.3",
22
+ "@0xsequence/wallet": "^0.40.3",
23
23
  "@ethersproject/abstract-signer": "^5.5.0",
24
24
  "@ethersproject/hash": "^5.5.0",
25
25
  "@ethersproject/providers": "^5.5.1",
@@ -300,17 +300,17 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
300
300
 
301
301
  // Message must be prefixed with "\x19Ethereum Signed Message:\n"
302
302
  // as defined by EIP-191
303
- message = prefixEIP191Message(message)
303
+ const prefixedMessage = prefixEIP191Message(message)
304
304
 
305
305
  // TODO:
306
306
  // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
307
307
  if (this.prompter === null) {
308
308
  // prompter is null, so we'll sign from here
309
- sig = await signer.signMessage(ethers.utils.arrayify(message), chainId)
309
+ sig = await signer.signMessage(prefixedMessage, chainId)
310
310
  } else {
311
311
  const promptResultForDeployment = await this.handleConfirmWalletDeployPrompt(this.prompter, signer, chainId)
312
312
  if (promptResultForDeployment) {
313
- sig = await this.prompter.promptSignMessage({ chainId: chainId, message }, this.connectOptions)
313
+ sig = await this.prompter.promptSignMessage({ chainId: chainId, message: prefixedMessage }, this.connectOptions)
314
314
  }
315
315
  }
316
316
 
package/src/types.ts CHANGED
@@ -247,7 +247,7 @@ export type OpenWalletIntent =
247
247
  | { type: 'jsonRpcRequest'; method: string }
248
248
 
249
249
  export interface MessageToSign {
250
- message?: string
250
+ message?: Uint8Array
251
251
  typedData?: TypedData
252
252
  chainId?: number
253
253
  }
package/src/wallet.ts CHANGED
@@ -29,22 +29,20 @@ import { LocalStore, ItemStore, LocalStorage } from './utils'
29
29
  import { WalletUtils } from './utils/index'
30
30
 
31
31
  import { Runtime } from 'webextension-polyfill-ts'
32
- import { sequence } from '../../0xsequence/src'
33
32
 
34
33
  export interface WalletProvider {
35
34
  connect(options?: ConnectOptions): Promise<ConnectDetails>
36
- // authorize(options?: ConnectOptions): Promise<ConnectDetails>
37
35
  disconnect(): void
38
36
 
39
- isOpened(): boolean
40
37
  isConnected(): boolean
41
38
  getSession(): WalletSession | undefined
42
-
39
+
43
40
  getAddress(): Promise<string>
44
41
  getNetworks(chainId?: ChainIdLike): Promise<NetworkConfig[]>
45
42
  getChainId(): Promise<number>
46
43
  getAuthChainId(): Promise<number>
47
-
44
+
45
+ isOpened(): boolean
48
46
  openWallet(path?: string, intent?: OpenWalletIntent, networkId?: string | number): Promise<boolean>
49
47
  closeWallet(): void
50
48
 
@@ -238,13 +236,23 @@ export class Wallet implements WalletProvider {
238
236
  this.transport.messageProvider.on('walletContext', (walletContext: WalletContext) => {
239
237
  this.useSession({ walletContext: walletContext }, true)
240
238
  })
239
+ }
241
240
 
242
- // Load existing session from localStorage
243
- this.loadSession().then(session => {
241
+ loadSession = async (): Promise<WalletSession | undefined> => {
242
+ const data = await LocalStorage.getInstance().getItem('@sequence.session')
243
+ if (!data || data === '') {
244
+ return undefined
245
+ }
246
+ try {
247
+ const session = JSON.parse(data) as WalletSession
244
248
  if (session) {
245
249
  this.useSession(session, false)
246
250
  }
247
- })
251
+ return session
252
+ } catch (err) {
253
+ logger.warn('loadSession failed, unable to parse session payload from storage.')
254
+ return undefined
255
+ }
248
256
  }
249
257
 
250
258
  connect = async (options?: ConnectOptions): Promise<ConnectDetails> => {
@@ -549,24 +557,10 @@ export class Wallet implements WalletProvider {
549
557
  this.transport.messageProvider!.once(event, fn)
550
558
  }
551
559
 
552
- private loadSession = async (): Promise<WalletSession | undefined> => {
553
- const data = await LocalStorage.getInstance().getItem('@sequence.session')
554
- if (!data || data === '') {
555
- return undefined
556
- }
557
- try {
558
- const session = JSON.parse(data) as WalletSession
559
- return session
560
- } catch (err) {
561
- logger.warn('loadSession failed, unable to parse session payload from localStorage.')
562
- return undefined
563
- }
564
- }
565
-
566
- private saveSession = (session: WalletSession) => {
560
+ private saveSession = async (session: WalletSession) => {
567
561
  logger.debug('wallet provider: saving session')
568
562
  const data = JSON.stringify(session)
569
- LocalStorage.getInstance().setItem('@sequence.session', data)
563
+ await LocalStorage.getInstance().setItem('@sequence.session', data)
570
564
  }
571
565
 
572
566
  private useSession = async (session: WalletSession, autoSave: boolean = true) => {
@@ -720,11 +714,12 @@ export const DefaultProviderConfig: ProviderConfig = {
720
714
 
721
715
  let walletInstance: Wallet | undefined
722
716
 
723
- export const initWallet = (network?: string | number, config?: Partial<ProviderConfig>) => {
717
+ export const initWallet = async (network?: string | number, config?: Partial<ProviderConfig>) => {
724
718
  if (walletInstance && walletInstance.isOpened()) {
725
719
  walletInstance.closeWallet()
726
720
  }
727
721
  walletInstance = new Wallet(network, config)
722
+ await walletInstance.loadSession()
728
723
  return walletInstance
729
724
  }
730
725