@0xsequence/provider 0.0.0-20231117190010 → 0.0.0-20231121142317

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.
@@ -8,7 +8,6 @@ var ethers = require('ethers');
8
8
  var network = require('@0xsequence/network');
9
9
  var core = require('@0xsequence/core');
10
10
  var auth = require('@0xsequence/auth');
11
- var abi = require('@0xsequence/abi');
12
11
 
13
12
  function _extends() {
14
13
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -360,7 +359,7 @@ class BaseProviderTransport {
360
359
 
361
360
  // CHAIN_CHANGED -- when a user changes their default chain
362
361
  if (message.type === EventType.CHAIN_CHANGED) {
363
- this.events.emit('chainChanged', message.data, message.origin);
362
+ this.events.emit('chainChanged', message.data);
364
363
  return;
365
364
  }
366
365
 
@@ -394,7 +393,7 @@ class BaseProviderTransport {
394
393
  // NOTIFY DISCONNECT -- when wallet instructs to disconnect
395
394
  if (message.type === EventType.DISCONNECT) {
396
395
  if (this.isConnected()) {
397
- this.events.emit('disconnect', message.data, message.origin);
396
+ this.events.emit('disconnect', message.data);
398
397
  this.close();
399
398
  }
400
399
  }
@@ -934,10 +933,10 @@ class BaseWalletTransport {
934
933
  // means user has logged in and wallet is connected to the app
935
934
  this.notifyConnect(connectDetails);
936
935
  });
937
- this.walletRequestHandler.on('disconnect', (error, origin) => {
936
+ this.walletRequestHandler.on('disconnect', error => {
938
937
  if (!this.registered) return;
939
938
  // means user has logged out the app / disconnected wallet from the app
940
- this.notifyDisconnect(error, origin);
939
+ this.notifyDisconnect(error);
941
940
  });
942
941
  this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
943
942
  if (!this.registered) return;
@@ -949,12 +948,9 @@ class BaseWalletTransport {
949
948
  if (!networks || networks.length === 0) {
950
949
  this.notifyChainChanged('0x0');
951
950
  } else {
952
- this.notifyChainChanged(ethers.ethers.utils.hexValue(networks.find(network => network.isDefaultChain).chainId));
951
+ this.notifyChainChanged(ethers.ethers.utils.hexlify(networks.find(network => network.isDefaultChain).chainId));
953
952
  }
954
953
  });
955
- this.walletRequestHandler.on('chainChanged', (chainIdHex, origin) => {
956
- this.notifyChainChanged(chainIdHex, origin);
957
- });
958
954
  this.walletRequestHandler.on('walletContext', walletContext => {
959
955
  if (!this.registered || !walletContext) return;
960
956
  this.notifyWalletContext(walletContext);
@@ -1010,14 +1006,13 @@ class BaseWalletTransport {
1010
1006
  data: connectDetails
1011
1007
  });
1012
1008
  }
1013
- notifyDisconnect(error, origin) {
1009
+ notifyDisconnect(error) {
1014
1010
  this.sendMessage({
1015
1011
  idx: -1,
1016
1012
  type: EventType.DISCONNECT,
1017
1013
  data: error ? {
1018
1014
  error
1019
- } : null,
1020
- origin
1015
+ } : null
1021
1016
  });
1022
1017
  }
1023
1018
  notifyAccountsChanged(accounts, origin) {
@@ -1025,15 +1020,14 @@ class BaseWalletTransport {
1025
1020
  idx: -1,
1026
1021
  type: EventType.ACCOUNTS_CHANGED,
1027
1022
  data: accounts,
1028
- origin
1023
+ origin: origin
1029
1024
  });
1030
1025
  }
1031
- notifyChainChanged(chainIdHex, origin) {
1026
+ notifyChainChanged(chainIdHex) {
1032
1027
  this.sendMessage({
1033
1028
  idx: -1,
1034
1029
  type: EventType.CHAIN_CHANGED,
1035
- data: chainIdHex,
1036
- origin
1030
+ data: chainIdHex
1037
1031
  });
1038
1032
  }
1039
1033
  notifyNetworks(networks) {
@@ -2129,7 +2123,7 @@ function validateTransaction(wallet, transaction) {
2129
2123
  if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
2130
2124
  if (transaction.data) {
2131
2125
  const data = ethers.ethers.utils.arrayify(transaction.data);
2132
- if (data.length >= 4 && !isCreateContractCall(data)) {
2126
+ if (data.length >= 4) {
2133
2127
  throw new Error('self calls are forbidden');
2134
2128
  }
2135
2129
  }
@@ -2138,15 +2132,6 @@ function validateTransaction(wallet, transaction) {
2138
2132
  throw new Error('delegate calls are forbidden');
2139
2133
  }
2140
2134
  }
2141
- function isCreateContractCall(data) {
2142
- const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
2143
- try {
2144
- walletInterface.decodeFunctionData('createContract', data);
2145
- return true;
2146
- } catch (_unused) {
2147
- return false;
2148
- }
2149
- }
2150
2135
 
2151
2136
  const SIGNER_READY_TIMEOUT = 10000;
2152
2137
  class WalletRequestHandler {
@@ -2199,7 +2184,7 @@ class WalletRequestHandler {
2199
2184
  if (!account) throw new Error('WalletRequestHandler: wallet account is not configured');
2200
2185
 
2201
2186
  // fetch the provider for the specific chain, or undefined will select defaultChain
2202
- const provider = (_this$account = _this.account) == null ? void 0 : _this$account.providerFor(chainId != null ? chainId : _this.defaultChainId());
2187
+ const provider = (_this$account = _this.account) == null ? void 0 : _this$account.provider(chainId != null ? chainId : _this.defaultChainId());
2203
2188
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`);
2204
2189
  const jsonRpcProvider = provider instanceof ethers.ethers.providers.JsonRpcProvider ? provider : undefined;
2205
2190
  switch (request.method) {
@@ -2341,10 +2326,9 @@ class WalletRequestHandler {
2341
2326
  validateTransactionRequest(account.address, transactionParams);
2342
2327
  let txnHash = '';
2343
2328
  if (_this.prompter === null) {
2344
- var _txnResponse$hash;
2345
2329
  // prompter is null, so we'll send from here
2346
2330
  const txnResponse = await account.sendTransaction(transactionParams, chainId != null ? chainId : _this.defaultChainId());
2347
- txnHash = (_txnResponse$hash = txnResponse == null ? void 0 : txnResponse.hash) != null ? _txnResponse$hash : '';
2331
+ txnHash = txnResponse.hash;
2348
2332
  } else {
2349
2333
  // prompt user to provide the response
2350
2334
  txnHash = await _this.prompter.promptSendTransaction(transactionParams, chainId, _this.connectOptions);
@@ -2688,8 +2672,7 @@ class WalletRequestHandler {
2688
2672
  const authOptions = {
2689
2673
  app: options.app,
2690
2674
  origin: options.origin,
2691
- expiry: options.expiry,
2692
- nonce: options.authorizeNonce
2675
+ expiry: options.expiry
2693
2676
  };
2694
2677
  // if (typeof(options.authorize) === 'object') {
2695
2678
  // authOptions = { ...authOptions, ...options.authorize }
@@ -2709,7 +2692,7 @@ class WalletRequestHandler {
2709
2692
  }
2710
2693
 
2711
2694
  // Build session response for connect details
2712
- connectDetails.session = this.walletSession(chainId);
2695
+ connectDetails.session = await this.walletSession(chainId);
2713
2696
  return connectDetails;
2714
2697
  }
2715
2698
  // sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
@@ -2813,10 +2796,7 @@ class WalletRequestHandler {
2813
2796
  }
2814
2797
  notifyDisconnect(origin) {
2815
2798
  this.events.emit('accountsChanged', [], origin);
2816
- this.events.emit('disconnect', undefined, origin);
2817
- }
2818
- notifyChainChanged(chainId, origin) {
2819
- this.events.emit('chainChanged', ethers.ethers.utils.hexValue(chainId), origin);
2799
+ this.events.emit('disconnect');
2820
2800
  }
2821
2801
  async notifyNetworks(networks) {
2822
2802
  const n = networks || (await this.getNetworks(true));
@@ -2824,7 +2804,7 @@ class WalletRequestHandler {
2824
2804
  if (n.length > 0) {
2825
2805
  const defaultNetwork = n.find(network => network.chainId === this.defaultChainId());
2826
2806
  if (defaultNetwork) {
2827
- this.events.emit('chainChanged', ethers.ethers.utils.hexValue(defaultNetwork.chainId));
2807
+ this.events.emit('chainChanged', ethers.ethers.utils.hexlify(defaultNetwork.chainId));
2828
2808
  }
2829
2809
  } else {
2830
2810
  this.events.emit('chainChanged', '0x0');
@@ -3533,7 +3513,7 @@ class SingleNetworkSequenceProvider extends SequenceProvider {
3533
3513
 
3534
3514
  var packageJson = {
3535
3515
  name: "@0xsequence/provider",
3536
- version: "0.0.0-20231117190010",
3516
+ version: "0.0.0-20231121142317",
3537
3517
  description: "provider sub-package for Sequence",
3538
3518
  repository: "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
3539
3519
  source: "src/index.ts",
@@ -3661,12 +3641,11 @@ DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
3661
3641
  * and it allows to perform all sequence specific (or write) operations related to the wallet.
3662
3642
  *s
3663
3643
  * It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
3664
- */ // TODO: rename Client to transport.. or something.. like SequenceTransport ..
3644
+ */
3665
3645
  class SequenceClient {
3666
- constructor(transport, store, options, projectAccessKey) {
3646
+ constructor(transport, store, options) {
3667
3647
  var _options$defaultEIP;
3668
3648
  this.callbacks = {};
3669
- this.projectAccessKey = projectAccessKey;
3670
3649
  if (isMuxTransportTemplate(transport)) {
3671
3650
  this.transport = MuxMessageProvider.new(transport);
3672
3651
  } else if (isProviderTransport(transport)) {
@@ -3694,9 +3673,9 @@ class SequenceClient {
3694
3673
  chainId: chainIdHex
3695
3674
  })));
3696
3675
  });
3697
- this.transport.on('disconnect', (error, origin) => {
3676
+ this.transport.on('disconnect', error => {
3698
3677
  var _this$callbacks$disco;
3699
- (_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error, origin));
3678
+ (_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error));
3700
3679
  });
3701
3680
  this.transport.on('networks', networks => {
3702
3681
  var _this$callbacks$netwo;
@@ -3714,17 +3693,13 @@ class SequenceClient {
3714
3693
  var _this$callbacks$close;
3715
3694
  (_this$callbacks$close = this.callbacks.close) == null ? void 0 : _this$callbacks$close.forEach(cb => cb());
3716
3695
  });
3717
- this.transport.on('chainChanged', (chainIdHex, origin) => {
3718
- var _this$callbacks$chain;
3719
- (_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex, origin));
3720
- });
3721
3696
 
3722
3697
  // We don't listen for the transport chainChanged event
3723
3698
  // instead we handle it locally, so we listen for changes in the store
3724
3699
  this.defaultChainId.onDefaultChainIdChanged(chainId => {
3725
- var _this$callbacks$chain2;
3700
+ var _this$callbacks$chain;
3726
3701
  const chainIdHex = ethers.ethers.utils.hexValue(chainId);
3727
- (_this$callbacks$chain2 = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain2.forEach(cb => cb(chainIdHex));
3702
+ (_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
3728
3703
  });
3729
3704
  }
3730
3705
 
@@ -3765,9 +3740,6 @@ class SequenceClient {
3765
3740
  onWalletContext(callback) {
3766
3741
  return this.registerCallback('walletContext', callback);
3767
3742
  }
3768
- onChainChanged(callback) {
3769
- return this.registerCallback('chainChanged', callback);
3770
- }
3771
3743
  onDefaultChainIdChanged(callback) {
3772
3744
  return this.registerCallback('chainChanged', callback);
3773
3745
  }
@@ -3811,7 +3783,6 @@ class SequenceClient {
3811
3783
  if ((options == null ? void 0 : options.refresh) === true) {
3812
3784
  this.disconnect();
3813
3785
  }
3814
- options.projectAccessKey = this.projectAccessKey;
3815
3786
  if (options) {
3816
3787
  if (options.authorize) {
3817
3788
  if (!options.app) {
@@ -4007,10 +3978,6 @@ const DefaultProviderConfig = {
4007
3978
  let sequenceWalletProvider;
4008
3979
  const initWallet = partialConfig => {
4009
3980
  var _config$networks$filt, _config$networks, _findNetworkConfig;
4010
- const projectAccessKey = partialConfig == null ? void 0 : partialConfig.projectAccessKey;
4011
- if (!projectAccessKey) {
4012
- console.warn('Please pass a projectAccessKey in initWallet config as it will be required in near future.');
4013
- }
4014
3981
  if (sequenceWalletProvider) {
4015
3982
  return sequenceWalletProvider;
4016
3983
  }
@@ -4032,13 +3999,9 @@ const initWallet = partialConfig => {
4032
3999
  var _config$networks2;
4033
4000
  const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
4034
4001
  return network ? _extends({}, n, network) : n;
4035
- }).concat(newNetworks).map(network => {
4036
- const toAppend = projectAccessKey ? `/${projectAccessKey}` : '';
4037
- network.rpcUrl = network.rpcUrl + toAppend;
4038
- return network;
4039
- });
4002
+ }).concat(newNetworks);
4040
4003
 
4041
- // This builds a "public rpc" on demand, we build them on demand because we don't want to
4004
+ // This build a "public rpc" on demand, we build them on demand because we don't want to
4042
4005
  // generate a bunch of providers for networks that aren't used.
4043
4006
  const providerForChainId = chainId => {
4044
4007
  if (!rpcProviders[chainId]) {
@@ -4069,7 +4032,7 @@ const initWallet = partialConfig => {
4069
4032
  const client = new SequenceClient(config.transports, itemStore, {
4070
4033
  defaultChainId: defaultNetwork,
4071
4034
  defaultEIP6492: config.defaultEIP6492
4072
- }, projectAccessKey);
4035
+ });
4073
4036
  sequenceWalletProvider = new SequenceProvider(client, providerForChainId);
4074
4037
  return sequenceWalletProvider;
4075
4038
  };
@@ -8,7 +8,6 @@ var ethers = require('ethers');
8
8
  var network = require('@0xsequence/network');
9
9
  var core = require('@0xsequence/core');
10
10
  var auth = require('@0xsequence/auth');
11
- var abi = require('@0xsequence/abi');
12
11
 
13
12
  function _extends() {
14
13
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -360,7 +359,7 @@ class BaseProviderTransport {
360
359
 
361
360
  // CHAIN_CHANGED -- when a user changes their default chain
362
361
  if (message.type === EventType.CHAIN_CHANGED) {
363
- this.events.emit('chainChanged', message.data, message.origin);
362
+ this.events.emit('chainChanged', message.data);
364
363
  return;
365
364
  }
366
365
 
@@ -394,7 +393,7 @@ class BaseProviderTransport {
394
393
  // NOTIFY DISCONNECT -- when wallet instructs to disconnect
395
394
  if (message.type === EventType.DISCONNECT) {
396
395
  if (this.isConnected()) {
397
- this.events.emit('disconnect', message.data, message.origin);
396
+ this.events.emit('disconnect', message.data);
398
397
  this.close();
399
398
  }
400
399
  }
@@ -934,10 +933,10 @@ class BaseWalletTransport {
934
933
  // means user has logged in and wallet is connected to the app
935
934
  this.notifyConnect(connectDetails);
936
935
  });
937
- this.walletRequestHandler.on('disconnect', (error, origin) => {
936
+ this.walletRequestHandler.on('disconnect', error => {
938
937
  if (!this.registered) return;
939
938
  // means user has logged out the app / disconnected wallet from the app
940
- this.notifyDisconnect(error, origin);
939
+ this.notifyDisconnect(error);
941
940
  });
942
941
  this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
943
942
  if (!this.registered) return;
@@ -949,12 +948,9 @@ class BaseWalletTransport {
949
948
  if (!networks || networks.length === 0) {
950
949
  this.notifyChainChanged('0x0');
951
950
  } else {
952
- this.notifyChainChanged(ethers.ethers.utils.hexValue(networks.find(network => network.isDefaultChain).chainId));
951
+ this.notifyChainChanged(ethers.ethers.utils.hexlify(networks.find(network => network.isDefaultChain).chainId));
953
952
  }
954
953
  });
955
- this.walletRequestHandler.on('chainChanged', (chainIdHex, origin) => {
956
- this.notifyChainChanged(chainIdHex, origin);
957
- });
958
954
  this.walletRequestHandler.on('walletContext', walletContext => {
959
955
  if (!this.registered || !walletContext) return;
960
956
  this.notifyWalletContext(walletContext);
@@ -1010,14 +1006,13 @@ class BaseWalletTransport {
1010
1006
  data: connectDetails
1011
1007
  });
1012
1008
  }
1013
- notifyDisconnect(error, origin) {
1009
+ notifyDisconnect(error) {
1014
1010
  this.sendMessage({
1015
1011
  idx: -1,
1016
1012
  type: EventType.DISCONNECT,
1017
1013
  data: error ? {
1018
1014
  error
1019
- } : null,
1020
- origin
1015
+ } : null
1021
1016
  });
1022
1017
  }
1023
1018
  notifyAccountsChanged(accounts, origin) {
@@ -1025,15 +1020,14 @@ class BaseWalletTransport {
1025
1020
  idx: -1,
1026
1021
  type: EventType.ACCOUNTS_CHANGED,
1027
1022
  data: accounts,
1028
- origin
1023
+ origin: origin
1029
1024
  });
1030
1025
  }
1031
- notifyChainChanged(chainIdHex, origin) {
1026
+ notifyChainChanged(chainIdHex) {
1032
1027
  this.sendMessage({
1033
1028
  idx: -1,
1034
1029
  type: EventType.CHAIN_CHANGED,
1035
- data: chainIdHex,
1036
- origin
1030
+ data: chainIdHex
1037
1031
  });
1038
1032
  }
1039
1033
  notifyNetworks(networks) {
@@ -2129,7 +2123,7 @@ function validateTransaction(wallet, transaction) {
2129
2123
  if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
2130
2124
  if (transaction.data) {
2131
2125
  const data = ethers.ethers.utils.arrayify(transaction.data);
2132
- if (data.length >= 4 && !isCreateContractCall(data)) {
2126
+ if (data.length >= 4) {
2133
2127
  throw new Error('self calls are forbidden');
2134
2128
  }
2135
2129
  }
@@ -2138,15 +2132,6 @@ function validateTransaction(wallet, transaction) {
2138
2132
  throw new Error('delegate calls are forbidden');
2139
2133
  }
2140
2134
  }
2141
- function isCreateContractCall(data) {
2142
- const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
2143
- try {
2144
- walletInterface.decodeFunctionData('createContract', data);
2145
- return true;
2146
- } catch (_unused) {
2147
- return false;
2148
- }
2149
- }
2150
2135
 
2151
2136
  const SIGNER_READY_TIMEOUT = 10000;
2152
2137
  class WalletRequestHandler {
@@ -2199,7 +2184,7 @@ class WalletRequestHandler {
2199
2184
  if (!account) throw new Error('WalletRequestHandler: wallet account is not configured');
2200
2185
 
2201
2186
  // fetch the provider for the specific chain, or undefined will select defaultChain
2202
- const provider = (_this$account = _this.account) == null ? void 0 : _this$account.providerFor(chainId != null ? chainId : _this.defaultChainId());
2187
+ const provider = (_this$account = _this.account) == null ? void 0 : _this$account.provider(chainId != null ? chainId : _this.defaultChainId());
2203
2188
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`);
2204
2189
  const jsonRpcProvider = provider instanceof ethers.ethers.providers.JsonRpcProvider ? provider : undefined;
2205
2190
  switch (request.method) {
@@ -2341,10 +2326,9 @@ class WalletRequestHandler {
2341
2326
  validateTransactionRequest(account.address, transactionParams);
2342
2327
  let txnHash = '';
2343
2328
  if (_this.prompter === null) {
2344
- var _txnResponse$hash;
2345
2329
  // prompter is null, so we'll send from here
2346
2330
  const txnResponse = await account.sendTransaction(transactionParams, chainId != null ? chainId : _this.defaultChainId());
2347
- txnHash = (_txnResponse$hash = txnResponse == null ? void 0 : txnResponse.hash) != null ? _txnResponse$hash : '';
2331
+ txnHash = txnResponse.hash;
2348
2332
  } else {
2349
2333
  // prompt user to provide the response
2350
2334
  txnHash = await _this.prompter.promptSendTransaction(transactionParams, chainId, _this.connectOptions);
@@ -2688,8 +2672,7 @@ class WalletRequestHandler {
2688
2672
  const authOptions = {
2689
2673
  app: options.app,
2690
2674
  origin: options.origin,
2691
- expiry: options.expiry,
2692
- nonce: options.authorizeNonce
2675
+ expiry: options.expiry
2693
2676
  };
2694
2677
  // if (typeof(options.authorize) === 'object') {
2695
2678
  // authOptions = { ...authOptions, ...options.authorize }
@@ -2709,7 +2692,7 @@ class WalletRequestHandler {
2709
2692
  }
2710
2693
 
2711
2694
  // Build session response for connect details
2712
- connectDetails.session = this.walletSession(chainId);
2695
+ connectDetails.session = await this.walletSession(chainId);
2713
2696
  return connectDetails;
2714
2697
  }
2715
2698
  // sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
@@ -2813,10 +2796,7 @@ class WalletRequestHandler {
2813
2796
  }
2814
2797
  notifyDisconnect(origin) {
2815
2798
  this.events.emit('accountsChanged', [], origin);
2816
- this.events.emit('disconnect', undefined, origin);
2817
- }
2818
- notifyChainChanged(chainId, origin) {
2819
- this.events.emit('chainChanged', ethers.ethers.utils.hexValue(chainId), origin);
2799
+ this.events.emit('disconnect');
2820
2800
  }
2821
2801
  async notifyNetworks(networks) {
2822
2802
  const n = networks || (await this.getNetworks(true));
@@ -2824,7 +2804,7 @@ class WalletRequestHandler {
2824
2804
  if (n.length > 0) {
2825
2805
  const defaultNetwork = n.find(network => network.chainId === this.defaultChainId());
2826
2806
  if (defaultNetwork) {
2827
- this.events.emit('chainChanged', ethers.ethers.utils.hexValue(defaultNetwork.chainId));
2807
+ this.events.emit('chainChanged', ethers.ethers.utils.hexlify(defaultNetwork.chainId));
2828
2808
  }
2829
2809
  } else {
2830
2810
  this.events.emit('chainChanged', '0x0');
@@ -3533,7 +3513,7 @@ class SingleNetworkSequenceProvider extends SequenceProvider {
3533
3513
 
3534
3514
  var packageJson = {
3535
3515
  name: "@0xsequence/provider",
3536
- version: "0.0.0-20231117190010",
3516
+ version: "0.0.0-20231121142317",
3537
3517
  description: "provider sub-package for Sequence",
3538
3518
  repository: "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
3539
3519
  source: "src/index.ts",
@@ -3661,12 +3641,11 @@ DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
3661
3641
  * and it allows to perform all sequence specific (or write) operations related to the wallet.
3662
3642
  *s
3663
3643
  * It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
3664
- */ // TODO: rename Client to transport.. or something.. like SequenceTransport ..
3644
+ */
3665
3645
  class SequenceClient {
3666
- constructor(transport, store, options, projectAccessKey) {
3646
+ constructor(transport, store, options) {
3667
3647
  var _options$defaultEIP;
3668
3648
  this.callbacks = {};
3669
- this.projectAccessKey = projectAccessKey;
3670
3649
  if (isMuxTransportTemplate(transport)) {
3671
3650
  this.transport = MuxMessageProvider.new(transport);
3672
3651
  } else if (isProviderTransport(transport)) {
@@ -3694,9 +3673,9 @@ class SequenceClient {
3694
3673
  chainId: chainIdHex
3695
3674
  })));
3696
3675
  });
3697
- this.transport.on('disconnect', (error, origin) => {
3676
+ this.transport.on('disconnect', error => {
3698
3677
  var _this$callbacks$disco;
3699
- (_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error, origin));
3678
+ (_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error));
3700
3679
  });
3701
3680
  this.transport.on('networks', networks => {
3702
3681
  var _this$callbacks$netwo;
@@ -3714,17 +3693,13 @@ class SequenceClient {
3714
3693
  var _this$callbacks$close;
3715
3694
  (_this$callbacks$close = this.callbacks.close) == null ? void 0 : _this$callbacks$close.forEach(cb => cb());
3716
3695
  });
3717
- this.transport.on('chainChanged', (chainIdHex, origin) => {
3718
- var _this$callbacks$chain;
3719
- (_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex, origin));
3720
- });
3721
3696
 
3722
3697
  // We don't listen for the transport chainChanged event
3723
3698
  // instead we handle it locally, so we listen for changes in the store
3724
3699
  this.defaultChainId.onDefaultChainIdChanged(chainId => {
3725
- var _this$callbacks$chain2;
3700
+ var _this$callbacks$chain;
3726
3701
  const chainIdHex = ethers.ethers.utils.hexValue(chainId);
3727
- (_this$callbacks$chain2 = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain2.forEach(cb => cb(chainIdHex));
3702
+ (_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
3728
3703
  });
3729
3704
  }
3730
3705
 
@@ -3765,9 +3740,6 @@ class SequenceClient {
3765
3740
  onWalletContext(callback) {
3766
3741
  return this.registerCallback('walletContext', callback);
3767
3742
  }
3768
- onChainChanged(callback) {
3769
- return this.registerCallback('chainChanged', callback);
3770
- }
3771
3743
  onDefaultChainIdChanged(callback) {
3772
3744
  return this.registerCallback('chainChanged', callback);
3773
3745
  }
@@ -3811,7 +3783,6 @@ class SequenceClient {
3811
3783
  if ((options == null ? void 0 : options.refresh) === true) {
3812
3784
  this.disconnect();
3813
3785
  }
3814
- options.projectAccessKey = this.projectAccessKey;
3815
3786
  if (options) {
3816
3787
  if (options.authorize) {
3817
3788
  if (!options.app) {
@@ -4007,10 +3978,6 @@ const DefaultProviderConfig = {
4007
3978
  let sequenceWalletProvider;
4008
3979
  const initWallet = partialConfig => {
4009
3980
  var _config$networks$filt, _config$networks, _findNetworkConfig;
4010
- const projectAccessKey = partialConfig == null ? void 0 : partialConfig.projectAccessKey;
4011
- if (!projectAccessKey) {
4012
- console.warn('Please pass a projectAccessKey in initWallet config as it will be required in near future.');
4013
- }
4014
3981
  if (sequenceWalletProvider) {
4015
3982
  return sequenceWalletProvider;
4016
3983
  }
@@ -4032,13 +3999,9 @@ const initWallet = partialConfig => {
4032
3999
  var _config$networks2;
4033
4000
  const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
4034
4001
  return network ? _extends({}, n, network) : n;
4035
- }).concat(newNetworks).map(network => {
4036
- const toAppend = projectAccessKey ? `/${projectAccessKey}` : '';
4037
- network.rpcUrl = network.rpcUrl + toAppend;
4038
- return network;
4039
- });
4002
+ }).concat(newNetworks);
4040
4003
 
4041
- // This builds a "public rpc" on demand, we build them on demand because we don't want to
4004
+ // This build a "public rpc" on demand, we build them on demand because we don't want to
4042
4005
  // generate a bunch of providers for networks that aren't used.
4043
4006
  const providerForChainId = chainId => {
4044
4007
  if (!rpcProviders[chainId]) {
@@ -4069,7 +4032,7 @@ const initWallet = partialConfig => {
4069
4032
  const client = new SequenceClient(config.transports, itemStore, {
4070
4033
  defaultChainId: defaultNetwork,
4071
4034
  defaultEIP6492: config.defaultEIP6492
4072
- }, projectAccessKey);
4035
+ });
4073
4036
  sequenceWalletProvider = new SequenceProvider(client, providerForChainId);
4074
4037
  return sequenceWalletProvider;
4075
4038
  };
@@ -4,7 +4,6 @@ import { ethers, BigNumber } from 'ethers';
4
4
  import { findSupportedNetwork, ChainId, findNetworkConfig, allNetworks, JsonRpcRouter, loggingProviderMiddleware, exceptionProviderMiddleware, CachedProvider, JsonRpcSender } from '@0xsequence/network';
5
5
  import { commons } from '@0xsequence/core';
6
6
  import { signAuthorization } from '@0xsequence/auth';
7
- import { walletContracts } from '@0xsequence/abi';
8
7
 
9
8
  function _extends() {
10
9
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -356,7 +355,7 @@ class BaseProviderTransport {
356
355
 
357
356
  // CHAIN_CHANGED -- when a user changes their default chain
358
357
  if (message.type === EventType.CHAIN_CHANGED) {
359
- this.events.emit('chainChanged', message.data, message.origin);
358
+ this.events.emit('chainChanged', message.data);
360
359
  return;
361
360
  }
362
361
 
@@ -390,7 +389,7 @@ class BaseProviderTransport {
390
389
  // NOTIFY DISCONNECT -- when wallet instructs to disconnect
391
390
  if (message.type === EventType.DISCONNECT) {
392
391
  if (this.isConnected()) {
393
- this.events.emit('disconnect', message.data, message.origin);
392
+ this.events.emit('disconnect', message.data);
394
393
  this.close();
395
394
  }
396
395
  }
@@ -930,10 +929,10 @@ class BaseWalletTransport {
930
929
  // means user has logged in and wallet is connected to the app
931
930
  this.notifyConnect(connectDetails);
932
931
  });
933
- this.walletRequestHandler.on('disconnect', (error, origin) => {
932
+ this.walletRequestHandler.on('disconnect', error => {
934
933
  if (!this.registered) return;
935
934
  // means user has logged out the app / disconnected wallet from the app
936
- this.notifyDisconnect(error, origin);
935
+ this.notifyDisconnect(error);
937
936
  });
938
937
  this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
939
938
  if (!this.registered) return;
@@ -945,12 +944,9 @@ class BaseWalletTransport {
945
944
  if (!networks || networks.length === 0) {
946
945
  this.notifyChainChanged('0x0');
947
946
  } else {
948
- this.notifyChainChanged(ethers.utils.hexValue(networks.find(network => network.isDefaultChain).chainId));
947
+ this.notifyChainChanged(ethers.utils.hexlify(networks.find(network => network.isDefaultChain).chainId));
949
948
  }
950
949
  });
951
- this.walletRequestHandler.on('chainChanged', (chainIdHex, origin) => {
952
- this.notifyChainChanged(chainIdHex, origin);
953
- });
954
950
  this.walletRequestHandler.on('walletContext', walletContext => {
955
951
  if (!this.registered || !walletContext) return;
956
952
  this.notifyWalletContext(walletContext);
@@ -1006,14 +1002,13 @@ class BaseWalletTransport {
1006
1002
  data: connectDetails
1007
1003
  });
1008
1004
  }
1009
- notifyDisconnect(error, origin) {
1005
+ notifyDisconnect(error) {
1010
1006
  this.sendMessage({
1011
1007
  idx: -1,
1012
1008
  type: EventType.DISCONNECT,
1013
1009
  data: error ? {
1014
1010
  error
1015
- } : null,
1016
- origin
1011
+ } : null
1017
1012
  });
1018
1013
  }
1019
1014
  notifyAccountsChanged(accounts, origin) {
@@ -1021,15 +1016,14 @@ class BaseWalletTransport {
1021
1016
  idx: -1,
1022
1017
  type: EventType.ACCOUNTS_CHANGED,
1023
1018
  data: accounts,
1024
- origin
1019
+ origin: origin
1025
1020
  });
1026
1021
  }
1027
- notifyChainChanged(chainIdHex, origin) {
1022
+ notifyChainChanged(chainIdHex) {
1028
1023
  this.sendMessage({
1029
1024
  idx: -1,
1030
1025
  type: EventType.CHAIN_CHANGED,
1031
- data: chainIdHex,
1032
- origin
1026
+ data: chainIdHex
1033
1027
  });
1034
1028
  }
1035
1029
  notifyNetworks(networks) {
@@ -2125,7 +2119,7 @@ function validateTransaction(wallet, transaction) {
2125
2119
  if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
2126
2120
  if (transaction.data) {
2127
2121
  const data = ethers.utils.arrayify(transaction.data);
2128
- if (data.length >= 4 && !isCreateContractCall(data)) {
2122
+ if (data.length >= 4) {
2129
2123
  throw new Error('self calls are forbidden');
2130
2124
  }
2131
2125
  }
@@ -2134,15 +2128,6 @@ function validateTransaction(wallet, transaction) {
2134
2128
  throw new Error('delegate calls are forbidden');
2135
2129
  }
2136
2130
  }
2137
- function isCreateContractCall(data) {
2138
- const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi);
2139
- try {
2140
- walletInterface.decodeFunctionData('createContract', data);
2141
- return true;
2142
- } catch (_unused) {
2143
- return false;
2144
- }
2145
- }
2146
2131
 
2147
2132
  const SIGNER_READY_TIMEOUT = 10000;
2148
2133
  class WalletRequestHandler {
@@ -2195,7 +2180,7 @@ class WalletRequestHandler {
2195
2180
  if (!account) throw new Error('WalletRequestHandler: wallet account is not configured');
2196
2181
 
2197
2182
  // fetch the provider for the specific chain, or undefined will select defaultChain
2198
- const provider = (_this$account = _this.account) == null ? void 0 : _this$account.providerFor(chainId != null ? chainId : _this.defaultChainId());
2183
+ const provider = (_this$account = _this.account) == null ? void 0 : _this$account.provider(chainId != null ? chainId : _this.defaultChainId());
2199
2184
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`);
2200
2185
  const jsonRpcProvider = provider instanceof ethers.providers.JsonRpcProvider ? provider : undefined;
2201
2186
  switch (request.method) {
@@ -2337,10 +2322,9 @@ class WalletRequestHandler {
2337
2322
  validateTransactionRequest(account.address, transactionParams);
2338
2323
  let txnHash = '';
2339
2324
  if (_this.prompter === null) {
2340
- var _txnResponse$hash;
2341
2325
  // prompter is null, so we'll send from here
2342
2326
  const txnResponse = await account.sendTransaction(transactionParams, chainId != null ? chainId : _this.defaultChainId());
2343
- txnHash = (_txnResponse$hash = txnResponse == null ? void 0 : txnResponse.hash) != null ? _txnResponse$hash : '';
2327
+ txnHash = txnResponse.hash;
2344
2328
  } else {
2345
2329
  // prompt user to provide the response
2346
2330
  txnHash = await _this.prompter.promptSendTransaction(transactionParams, chainId, _this.connectOptions);
@@ -2684,8 +2668,7 @@ class WalletRequestHandler {
2684
2668
  const authOptions = {
2685
2669
  app: options.app,
2686
2670
  origin: options.origin,
2687
- expiry: options.expiry,
2688
- nonce: options.authorizeNonce
2671
+ expiry: options.expiry
2689
2672
  };
2690
2673
  // if (typeof(options.authorize) === 'object') {
2691
2674
  // authOptions = { ...authOptions, ...options.authorize }
@@ -2705,7 +2688,7 @@ class WalletRequestHandler {
2705
2688
  }
2706
2689
 
2707
2690
  // Build session response for connect details
2708
- connectDetails.session = this.walletSession(chainId);
2691
+ connectDetails.session = await this.walletSession(chainId);
2709
2692
  return connectDetails;
2710
2693
  }
2711
2694
  // sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
@@ -2809,10 +2792,7 @@ class WalletRequestHandler {
2809
2792
  }
2810
2793
  notifyDisconnect(origin) {
2811
2794
  this.events.emit('accountsChanged', [], origin);
2812
- this.events.emit('disconnect', undefined, origin);
2813
- }
2814
- notifyChainChanged(chainId, origin) {
2815
- this.events.emit('chainChanged', ethers.utils.hexValue(chainId), origin);
2795
+ this.events.emit('disconnect');
2816
2796
  }
2817
2797
  async notifyNetworks(networks) {
2818
2798
  const n = networks || (await this.getNetworks(true));
@@ -2820,7 +2800,7 @@ class WalletRequestHandler {
2820
2800
  if (n.length > 0) {
2821
2801
  const defaultNetwork = n.find(network => network.chainId === this.defaultChainId());
2822
2802
  if (defaultNetwork) {
2823
- this.events.emit('chainChanged', ethers.utils.hexValue(defaultNetwork.chainId));
2803
+ this.events.emit('chainChanged', ethers.utils.hexlify(defaultNetwork.chainId));
2824
2804
  }
2825
2805
  } else {
2826
2806
  this.events.emit('chainChanged', '0x0');
@@ -3529,7 +3509,7 @@ class SingleNetworkSequenceProvider extends SequenceProvider {
3529
3509
 
3530
3510
  var packageJson = {
3531
3511
  name: "@0xsequence/provider",
3532
- version: "0.0.0-20231117190010",
3512
+ version: "0.0.0-20231121142317",
3533
3513
  description: "provider sub-package for Sequence",
3534
3514
  repository: "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
3535
3515
  source: "src/index.ts",
@@ -3657,12 +3637,11 @@ DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
3657
3637
  * and it allows to perform all sequence specific (or write) operations related to the wallet.
3658
3638
  *s
3659
3639
  * It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
3660
- */ // TODO: rename Client to transport.. or something.. like SequenceTransport ..
3640
+ */
3661
3641
  class SequenceClient {
3662
- constructor(transport, store, options, projectAccessKey) {
3642
+ constructor(transport, store, options) {
3663
3643
  var _options$defaultEIP;
3664
3644
  this.callbacks = {};
3665
- this.projectAccessKey = projectAccessKey;
3666
3645
  if (isMuxTransportTemplate(transport)) {
3667
3646
  this.transport = MuxMessageProvider.new(transport);
3668
3647
  } else if (isProviderTransport(transport)) {
@@ -3690,9 +3669,9 @@ class SequenceClient {
3690
3669
  chainId: chainIdHex
3691
3670
  })));
3692
3671
  });
3693
- this.transport.on('disconnect', (error, origin) => {
3672
+ this.transport.on('disconnect', error => {
3694
3673
  var _this$callbacks$disco;
3695
- (_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error, origin));
3674
+ (_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error));
3696
3675
  });
3697
3676
  this.transport.on('networks', networks => {
3698
3677
  var _this$callbacks$netwo;
@@ -3710,17 +3689,13 @@ class SequenceClient {
3710
3689
  var _this$callbacks$close;
3711
3690
  (_this$callbacks$close = this.callbacks.close) == null ? void 0 : _this$callbacks$close.forEach(cb => cb());
3712
3691
  });
3713
- this.transport.on('chainChanged', (chainIdHex, origin) => {
3714
- var _this$callbacks$chain;
3715
- (_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex, origin));
3716
- });
3717
3692
 
3718
3693
  // We don't listen for the transport chainChanged event
3719
3694
  // instead we handle it locally, so we listen for changes in the store
3720
3695
  this.defaultChainId.onDefaultChainIdChanged(chainId => {
3721
- var _this$callbacks$chain2;
3696
+ var _this$callbacks$chain;
3722
3697
  const chainIdHex = ethers.utils.hexValue(chainId);
3723
- (_this$callbacks$chain2 = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain2.forEach(cb => cb(chainIdHex));
3698
+ (_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
3724
3699
  });
3725
3700
  }
3726
3701
 
@@ -3761,9 +3736,6 @@ class SequenceClient {
3761
3736
  onWalletContext(callback) {
3762
3737
  return this.registerCallback('walletContext', callback);
3763
3738
  }
3764
- onChainChanged(callback) {
3765
- return this.registerCallback('chainChanged', callback);
3766
- }
3767
3739
  onDefaultChainIdChanged(callback) {
3768
3740
  return this.registerCallback('chainChanged', callback);
3769
3741
  }
@@ -3807,7 +3779,6 @@ class SequenceClient {
3807
3779
  if ((options == null ? void 0 : options.refresh) === true) {
3808
3780
  this.disconnect();
3809
3781
  }
3810
- options.projectAccessKey = this.projectAccessKey;
3811
3782
  if (options) {
3812
3783
  if (options.authorize) {
3813
3784
  if (!options.app) {
@@ -4003,10 +3974,6 @@ const DefaultProviderConfig = {
4003
3974
  let sequenceWalletProvider;
4004
3975
  const initWallet = partialConfig => {
4005
3976
  var _config$networks$filt, _config$networks, _findNetworkConfig;
4006
- const projectAccessKey = partialConfig == null ? void 0 : partialConfig.projectAccessKey;
4007
- if (!projectAccessKey) {
4008
- console.warn('Please pass a projectAccessKey in initWallet config as it will be required in near future.');
4009
- }
4010
3977
  if (sequenceWalletProvider) {
4011
3978
  return sequenceWalletProvider;
4012
3979
  }
@@ -4028,13 +3995,9 @@ const initWallet = partialConfig => {
4028
3995
  var _config$networks2;
4029
3996
  const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
4030
3997
  return network ? _extends({}, n, network) : n;
4031
- }).concat(newNetworks).map(network => {
4032
- const toAppend = projectAccessKey ? `/${projectAccessKey}` : '';
4033
- network.rpcUrl = network.rpcUrl + toAppend;
4034
- return network;
4035
- });
3998
+ }).concat(newNetworks);
4036
3999
 
4037
- // This builds a "public rpc" on demand, we build them on demand because we don't want to
4000
+ // This build a "public rpc" on demand, we build them on demand because we don't want to
4038
4001
  // generate a bunch of providers for networks that aren't used.
4039
4002
  const providerForChainId = chainId => {
4040
4003
  if (!rpcProviders[chainId]) {
@@ -4065,7 +4028,7 @@ const initWallet = partialConfig => {
4065
4028
  const client = new SequenceClient(config.transports, itemStore, {
4066
4029
  defaultChainId: defaultNetwork,
4067
4030
  defaultEIP6492: config.defaultEIP6492
4068
- }, projectAccessKey);
4031
+ });
4069
4032
  sequenceWalletProvider = new SequenceProvider(client, providerForChainId);
4070
4033
  return sequenceWalletProvider;
4071
4034
  };
@@ -44,13 +44,12 @@ export type SequenceClientOptions = {
44
44
  * It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
45
45
  */
46
46
  export declare class SequenceClient {
47
- projectAccessKey?: string | undefined;
48
47
  private readonly session;
49
48
  private readonly defaultChainId;
50
49
  private readonly callbacks;
51
50
  readonly transport: ProviderTransport;
52
51
  readonly defaultEIP6492: boolean;
53
- constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, options?: SequenceClientOptions | number, projectAccessKey?: string | undefined);
52
+ constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, options?: SequenceClientOptions | number);
54
53
  registerCallback<K extends keyof WalletEventTypes>(eventName: K, callback: WalletEventTypes[K]): () => void;
55
54
  onOpen(callback: WalletEventTypes['open']): () => void;
56
55
  onClose(callback: WalletEventTypes['close']): () => void;
@@ -59,7 +58,6 @@ export declare class SequenceClient {
59
58
  onNetworks(callback: WalletEventTypes['networks']): () => void;
60
59
  onAccountsChanged(callback: WalletEventTypes['accountsChanged']): () => void;
61
60
  onWalletContext(callback: WalletEventTypes['walletContext']): () => void;
62
- onChainChanged(callback: WalletEventTypes['chainChanged']): () => void;
63
61
  onDefaultChainIdChanged(callback: WalletEventTypes['chainChanged']): () => void;
64
62
  getChainId(): number;
65
63
  setDefaultChainId(chainId: number): void;
@@ -3,7 +3,6 @@ import { MuxTransportTemplate } from "./transports/index.js";
3
3
  import { ItemStore } from "./utils.js";
4
4
  import { SequenceProvider } from "./provider.js";
5
5
  export interface ProviderConfig {
6
- projectAccessKey?: string;
7
6
  localStorage?: ItemStore;
8
7
  defaultNetwork?: ChainIdLike;
9
8
  defaultEIP6492?: boolean;
@@ -26,9 +26,9 @@ export declare abstract class BaseWalletTransport implements WalletTransport {
26
26
  }): void;
27
27
  notifyClose(error?: ProviderRpcError): void;
28
28
  notifyConnect(connectDetails: ConnectDetails): void;
29
- notifyDisconnect(error?: ProviderRpcError, origin?: string): void;
29
+ notifyDisconnect(error?: ProviderRpcError): void;
30
30
  notifyAccountsChanged(accounts: string[], origin?: string): void;
31
- notifyChainChanged(chainIdHex: string, origin?: string): void;
31
+ notifyChainChanged(chainIdHex: string): void;
32
32
  notifyNetworks(networks: NetworkConfig[]): void;
33
33
  notifyWalletContext(walletContext: commons.context.VersionedContext): void;
34
34
  protected isValidInitAck(message: ProviderMessage<any>): boolean;
@@ -39,7 +39,6 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
39
39
  walletSession(networkId?: ChainIdLike): WalletSession | undefined;
40
40
  notifyConnect(connectDetails: ConnectDetails, origin?: string): void;
41
41
  notifyDisconnect(origin?: string): void;
42
- notifyChainChanged(chainId: number, origin?: string): void;
43
42
  notifyNetworks(networks?: NetworkConfig[]): Promise<void>;
44
43
  notifyWalletContext(): Promise<void>;
45
44
  notifyClose(error?: ProviderRpcError): void;
@@ -84,9 +84,9 @@ export interface WalletEventTypes {
84
84
  }) => void;
85
85
  close: (error?: ProviderRpcError) => void;
86
86
  connect: (connectDetails: ConnectDetails) => void;
87
- disconnect: (error?: ProviderRpcError, origin?: string) => void;
87
+ disconnect: (error?: ProviderRpcError) => void;
88
88
  accountsChanged: (accounts: string[], origin?: string) => void;
89
- chainChanged: (chainIdHex: string, origin?: string) => void;
89
+ chainChanged: (chainIdHex: string) => void;
90
90
  networks: (networks: NetworkConfig[]) => void;
91
91
  walletContext: (walletContext: commons.context.VersionedContext) => void;
92
92
  }
@@ -111,15 +111,10 @@ export interface ConnectOptions {
111
111
  /** origin hint of the dapp's host opening the wallet. This value will automatically
112
112
  * be determined and verified for integrity, and can be omitted. */
113
113
  origin?: string;
114
- /** access key for the project that can be obtained from Sequence Builder on sequence.build.
115
- * This value will be automatically populated using the key passed in initWallet. */
116
- projectAccessKey?: string;
117
- /** expiry number (in seconds) that is used for ETHAuth proof. Default is 1 week in seconds. */
114
+ /** expiry number (in seconds) to expire connect session. default is 1 week of seconds. */
118
115
  expiry?: number;
119
116
  /** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
120
117
  authorize?: boolean;
121
- /** authorizeNonce is an optional number to be passed as ETHAuth's nonce claim for replay protection. **/
122
- authorizeNonce?: number;
123
118
  /** authorizeVersion is the version of the SDK that will validate the ETHAuth proof. */
124
119
  authorizeVersion?: number;
125
120
  /** askForEmail will prompt to give permission to the dapp to access email address */
@@ -194,7 +189,7 @@ export interface Settings {
194
189
  * you can use the camel case version of the name in the wallet settings.
195
190
  * For example: "Blue Dark" on wallet UI can be passed as "blueDark" */
196
191
  export type ThemeOption = 'light' | 'dark' | string;
197
- export type PaymentProviderOption = 'ramp' | 'moonpay' | 'transak' | 'onmeta' | 'paytrie' | 'sardine';
192
+ export type PaymentProviderOption = 'moonpay' | 'wyre' | 'ramp';
198
193
  export type CurrencyOption = 'usdc' | 'eth' | 'matic';
199
194
  export type SignInOption = 'email' | 'google' | 'apple' | 'facebook' | 'discord' | 'twitch';
200
195
  export type BannerSize = 'small' | 'medium';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.0.0-20231117190010",
3
+ "version": "0.0.0-20231121142317",
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",
@@ -11,15 +11,15 @@
11
11
  "dependencies": {
12
12
  "eventemitter2": "^6.4.5",
13
13
  "webextension-polyfill": "^0.10.0",
14
- "@0xsequence/abi": "0.0.0-20231117190010",
15
- "@0xsequence/account": "0.0.0-20231117190010",
16
- "@0xsequence/auth": "0.0.0-20231117190010",
17
- "@0xsequence/core": "0.0.0-20231117190010",
18
- "@0xsequence/network": "0.0.0-20231117190010",
19
- "@0xsequence/migration": "0.0.0-20231117190010",
20
- "@0xsequence/relayer": "0.0.0-20231117190010",
21
- "@0xsequence/utils": "0.0.0-20231117190010",
22
- "@0xsequence/wallet": "0.0.0-20231117190010"
14
+ "@0xsequence/abi": "0.0.0-20231121142317",
15
+ "@0xsequence/account": "0.0.0-20231121142317",
16
+ "@0xsequence/auth": "0.0.0-20231121142317",
17
+ "@0xsequence/migration": "0.0.0-20231121142317",
18
+ "@0xsequence/core": "0.0.0-20231121142317",
19
+ "@0xsequence/network": "0.0.0-20231121142317",
20
+ "@0xsequence/relayer": "0.0.0-20231121142317",
21
+ "@0xsequence/utils": "0.0.0-20231121142317",
22
+ "@0xsequence/wallet": "0.0.0-20231121142317"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "ethers": ">=5.5 < 6"
package/src/client.ts CHANGED
@@ -125,8 +125,6 @@ export type SequenceClientOptions = {
125
125
  *s
126
126
  * It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
127
127
  */
128
-
129
- // TODO: rename Client to transport.. or something.. like SequenceTransport ..
130
128
  export class SequenceClient {
131
129
  private readonly session: SequenceClientSession
132
130
  private readonly defaultChainId: DefaultChainIdTracker
@@ -136,12 +134,7 @@ export class SequenceClient {
136
134
 
137
135
  public readonly defaultEIP6492: boolean
138
136
 
139
- constructor(
140
- transport: ProviderTransport | MuxTransportTemplate,
141
- store: ItemStore,
142
- options?: SequenceClientOptions | number,
143
- public projectAccessKey?: string
144
- ) {
137
+ constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, options?: SequenceClientOptions | number) {
145
138
  if (isMuxTransportTemplate(transport)) {
146
139
  this.transport = MuxMessageProvider.new(transport)
147
140
  } else if (isProviderTransport(transport)) {
@@ -176,8 +169,8 @@ export class SequenceClient {
176
169
  )
177
170
  })
178
171
 
179
- this.transport.on('disconnect', (error, origin) => {
180
- this.callbacks.disconnect?.forEach(cb => cb(error, origin))
172
+ this.transport.on('disconnect', error => {
173
+ this.callbacks.disconnect?.forEach(cb => cb(error))
181
174
  })
182
175
 
183
176
  this.transport.on('networks', networks => {
@@ -196,10 +189,6 @@ export class SequenceClient {
196
189
  this.callbacks.close?.forEach(cb => cb())
197
190
  })
198
191
 
199
- this.transport.on('chainChanged', (chainIdHex, origin) => {
200
- this.callbacks.chainChanged?.forEach(cb => cb(chainIdHex, origin))
201
- })
202
-
203
192
  // We don't listen for the transport chainChanged event
204
193
  // instead we handle it locally, so we listen for changes in the store
205
194
  this.defaultChainId.onDefaultChainIdChanged((chainId: number) => {
@@ -253,10 +242,6 @@ export class SequenceClient {
253
242
  return this.registerCallback('walletContext', callback)
254
243
  }
255
244
 
256
- onChainChanged(callback: WalletEventTypes['chainChanged']) {
257
- return this.registerCallback('chainChanged', callback)
258
- }
259
-
260
245
  onDefaultChainIdChanged(callback: WalletEventTypes['chainChanged']) {
261
246
  return this.registerCallback('chainChanged', callback)
262
247
  }
@@ -309,8 +294,6 @@ export class SequenceClient {
309
294
  this.disconnect()
310
295
  }
311
296
 
312
- options.projectAccessKey = this.projectAccessKey
313
-
314
297
  if (options) {
315
298
  if (options.authorize) {
316
299
  if (!options.app) {
package/src/init.ts CHANGED
@@ -16,9 +16,6 @@ import { SequenceClient } from './client'
16
16
  import { SequenceProvider } from './provider'
17
17
 
18
18
  export interface ProviderConfig {
19
- // Access key for the project that can be obtained from Sequence Builder on sequence.build
20
- projectAccessKey?: string
21
-
22
19
  // The local storage dependency for the wallet provider, defaults to window.localStorage.
23
20
  // For example, this option should be used when using React Native since window.localStorage is not available.
24
21
  localStorage?: ItemStore
@@ -58,12 +55,6 @@ export const DefaultProviderConfig = {
58
55
  let sequenceWalletProvider: SequenceProvider | undefined
59
56
 
60
57
  export const initWallet = (partialConfig?: Partial<ProviderConfig>) => {
61
- const projectAccessKey = partialConfig?.projectAccessKey
62
-
63
- if (!projectAccessKey) {
64
- console.warn('Please pass a projectAccessKey in initWallet config as it will be required in near future.')
65
- }
66
-
67
58
  if (sequenceWalletProvider) {
68
59
  return sequenceWalletProvider
69
60
  }
@@ -93,13 +84,8 @@ export const initWallet = (partialConfig?: Partial<ProviderConfig>) => {
93
84
  return network ? { ...n, ...network } : n
94
85
  })
95
86
  .concat(newNetworks)
96
- .map(network => {
97
- const toAppend = projectAccessKey ? `/${projectAccessKey}` : ''
98
- network.rpcUrl = network.rpcUrl + toAppend
99
- return network
100
- })
101
87
 
102
- // This builds a "public rpc" on demand, we build them on demand because we don't want to
88
+ // This build a "public rpc" on demand, we build them on demand because we don't want to
103
89
  // generate a bunch of providers for networks that aren't used.
104
90
  const providerForChainId = (chainId: number) => {
105
91
  if (!rpcProviders[chainId]) {
@@ -132,15 +118,10 @@ export const initWallet = (partialConfig?: Partial<ProviderConfig>) => {
132
118
  const itemStore = config.localStorage || useBestStore()
133
119
 
134
120
  // Create client, provider and return signer
135
- const client = new SequenceClient(
136
- config.transports,
137
- itemStore,
138
- {
139
- defaultChainId: defaultNetwork,
140
- defaultEIP6492: config.defaultEIP6492
141
- },
142
- projectAccessKey
143
- )
121
+ const client = new SequenceClient(config.transports, itemStore, {
122
+ defaultChainId: defaultNetwork,
123
+ defaultEIP6492: config.defaultEIP6492
124
+ })
144
125
 
145
126
  sequenceWalletProvider = new SequenceProvider(client, providerForChainId)
146
127
  return sequenceWalletProvider
@@ -157,5 +138,6 @@ export const getWallet = () => {
157
138
  if (!sequenceWalletProvider) {
158
139
  throw new Error('Wallet has not been initialized, call sequence.initWallet(config) first.')
159
140
  }
141
+
160
142
  return sequenceWalletProvider
161
143
  }
@@ -1,4 +1,3 @@
1
- import { walletContracts } from '@0xsequence/abi'
2
1
  import { commons } from '@0xsequence/core'
3
2
  import { ethers } from 'ethers'
4
3
 
@@ -12,7 +11,7 @@ function validateTransaction(wallet: string, transaction: commons.transaction.Tr
12
11
  if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
13
12
  if (transaction.data) {
14
13
  const data = ethers.utils.arrayify(transaction.data)
15
- if (data.length >= 4 && !isCreateContractCall(data)) {
14
+ if (data.length >= 4) {
16
15
  throw new Error('self calls are forbidden')
17
16
  }
18
17
  }
@@ -22,13 +21,3 @@ function validateTransaction(wallet: string, transaction: commons.transaction.Tr
22
21
  throw new Error('delegate calls are forbidden')
23
22
  }
24
23
  }
25
-
26
- function isCreateContractCall(data: ethers.BytesLike): boolean {
27
- const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi)
28
- try {
29
- walletInterface.decodeFunctionData('createContract', data)
30
- return true
31
- } catch {
32
- return false
33
- }
34
- }
@@ -240,7 +240,7 @@ export abstract class BaseProviderTransport implements ProviderTransport {
240
240
 
241
241
  // CHAIN_CHANGED -- when a user changes their default chain
242
242
  if (message.type === EventType.CHAIN_CHANGED) {
243
- this.events.emit('chainChanged', message.data, message.origin)
243
+ this.events.emit('chainChanged', message.data)
244
244
  return
245
245
  }
246
246
 
@@ -274,7 +274,7 @@ export abstract class BaseProviderTransport implements ProviderTransport {
274
274
  // NOTIFY DISCONNECT -- when wallet instructs to disconnect
275
275
  if (message.type === EventType.DISCONNECT) {
276
276
  if (this.isConnected()) {
277
- this.events.emit('disconnect', message.data, message.origin)
277
+ this.events.emit('disconnect', message.data)
278
278
  this.close()
279
279
  }
280
280
  }
@@ -48,10 +48,10 @@ export abstract class BaseWalletTransport implements WalletTransport {
48
48
  this.notifyConnect(connectDetails)
49
49
  })
50
50
 
51
- this.walletRequestHandler.on('disconnect', (error?: ProviderRpcError, origin?: string) => {
51
+ this.walletRequestHandler.on('disconnect', (error?: ProviderRpcError) => {
52
52
  if (!this.registered) return
53
53
  // means user has logged out the app / disconnected wallet from the app
54
- this.notifyDisconnect(error, origin)
54
+ this.notifyDisconnect(error)
55
55
  })
56
56
 
57
57
  this.walletRequestHandler.on('accountsChanged', (accounts: string[], origin?: string) => {
@@ -65,14 +65,10 @@ export abstract class BaseWalletTransport implements WalletTransport {
65
65
  if (!networks || networks.length === 0) {
66
66
  this.notifyChainChanged('0x0')
67
67
  } else {
68
- this.notifyChainChanged(ethers.utils.hexValue(networks.find(network => network.isDefaultChain)!.chainId))
68
+ this.notifyChainChanged(ethers.utils.hexlify(networks.find(network => network.isDefaultChain)!.chainId))
69
69
  }
70
70
  })
71
71
 
72
- this.walletRequestHandler.on('chainChanged', (chainIdHex: string, origin?: string) => {
73
- this.notifyChainChanged(chainIdHex, origin)
74
- })
75
-
76
72
  this.walletRequestHandler.on('walletContext', (walletContext: commons.context.VersionedContext) => {
77
73
  if (!this.registered || !walletContext) return
78
74
  this.notifyWalletContext(walletContext)
@@ -201,12 +197,11 @@ export abstract class BaseWalletTransport implements WalletTransport {
201
197
  })
202
198
  }
203
199
 
204
- notifyDisconnect(error?: ProviderRpcError, origin?: string) {
200
+ notifyDisconnect(error?: ProviderRpcError) {
205
201
  this.sendMessage({
206
202
  idx: -1,
207
203
  type: EventType.DISCONNECT,
208
- data: error ? { error } : null,
209
- origin
204
+ data: error ? { error } : null
210
205
  })
211
206
  }
212
207
 
@@ -215,16 +210,15 @@ export abstract class BaseWalletTransport implements WalletTransport {
215
210
  idx: -1,
216
211
  type: EventType.ACCOUNTS_CHANGED,
217
212
  data: accounts,
218
- origin
213
+ origin: origin
219
214
  })
220
215
  }
221
216
 
222
- notifyChainChanged(chainIdHex: string, origin?: string) {
217
+ notifyChainChanged(chainIdHex: string) {
223
218
  this.sendMessage({
224
219
  idx: -1,
225
220
  type: EventType.CHAIN_CHANGED,
226
- data: chainIdHex,
227
- origin
221
+ data: chainIdHex
228
222
  })
229
223
  }
230
224
 
@@ -159,8 +159,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
159
159
  const authOptions: AuthorizationOptions = {
160
160
  app: options.app,
161
161
  origin: options.origin,
162
- expiry: options.expiry,
163
- nonce: options.authorizeNonce
162
+ expiry: options.expiry
164
163
  }
165
164
  // if (typeof(options.authorize) === 'object') {
166
165
  // authOptions = { ...authOptions, ...options.authorize }
@@ -180,7 +179,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
180
179
  }
181
180
 
182
181
  // Build session response for connect details
183
- connectDetails.session = this.walletSession(chainId)
182
+ connectDetails.session = await this.walletSession(chainId)
184
183
 
185
184
  return connectDetails
186
185
  }
@@ -254,7 +253,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
254
253
  if (!account) throw new Error('WalletRequestHandler: wallet account is not configured')
255
254
 
256
255
  // fetch the provider for the specific chain, or undefined will select defaultChain
257
- const provider = this.account?.providerFor(chainId ?? this.defaultChainId())
256
+ const provider = this.account?.provider(chainId ?? this.defaultChainId())
258
257
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`)
259
258
  const jsonRpcProvider = provider instanceof ethers.providers.JsonRpcProvider ? provider : undefined
260
259
 
@@ -424,7 +423,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
424
423
  if (this.prompter === null) {
425
424
  // prompter is null, so we'll send from here
426
425
  const txnResponse = await account.sendTransaction(transactionParams, chainId ?? this.defaultChainId())
427
- txnHash = txnResponse?.hash ?? ''
426
+ txnHash = txnResponse.hash
428
427
  } else {
429
428
  // prompt user to provide the response
430
429
  txnHash = await this.prompter.promptSendTransaction(transactionParams, chainId, this.connectOptions)
@@ -768,11 +767,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
768
767
 
769
768
  notifyDisconnect(origin?: string) {
770
769
  this.events.emit('accountsChanged', [], origin)
771
- this.events.emit('disconnect', undefined, origin)
772
- }
773
-
774
- notifyChainChanged(chainId: number, origin?: string) {
775
- this.events.emit('chainChanged', ethers.utils.hexValue(chainId), origin)
770
+ this.events.emit('disconnect')
776
771
  }
777
772
 
778
773
  async notifyNetworks(networks?: NetworkConfig[]) {
@@ -781,7 +776,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
781
776
  if (n.length > 0) {
782
777
  const defaultNetwork = n.find(network => network.chainId === this.defaultChainId())
783
778
  if (defaultNetwork) {
784
- this.events.emit('chainChanged', ethers.utils.hexValue(defaultNetwork.chainId))
779
+ this.events.emit('chainChanged', ethers.utils.hexlify(defaultNetwork.chainId))
785
780
  }
786
781
  } else {
787
782
  this.events.emit('chainChanged', '0x0')
package/src/types.ts CHANGED
@@ -129,10 +129,10 @@ export interface WalletEventTypes {
129
129
  close: (error?: ProviderRpcError) => void
130
130
 
131
131
  connect: (connectDetails: ConnectDetails) => void
132
- disconnect: (error?: ProviderRpcError, origin?: string) => void
132
+ disconnect: (error?: ProviderRpcError) => void
133
133
 
134
134
  accountsChanged: (accounts: string[], origin?: string) => void
135
- chainChanged: (chainIdHex: string, origin?: string) => void
135
+ chainChanged: (chainIdHex: string) => void
136
136
 
137
137
  networks: (networks: NetworkConfig[]) => void
138
138
  walletContext: (walletContext: commons.context.VersionedContext) => void
@@ -165,19 +165,12 @@ export interface ConnectOptions {
165
165
  * be determined and verified for integrity, and can be omitted. */
166
166
  origin?: string
167
167
 
168
- /** access key for the project that can be obtained from Sequence Builder on sequence.build.
169
- * This value will be automatically populated using the key passed in initWallet. */
170
- projectAccessKey?: string
171
-
172
- /** expiry number (in seconds) that is used for ETHAuth proof. Default is 1 week in seconds. */
168
+ /** expiry number (in seconds) to expire connect session. default is 1 week of seconds. */
173
169
  expiry?: number
174
170
 
175
171
  /** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
176
172
  authorize?: boolean
177
173
 
178
- /** authorizeNonce is an optional number to be passed as ETHAuth's nonce claim for replay protection. **/
179
- authorizeNonce?: number
180
-
181
174
  /** authorizeVersion is the version of the SDK that will validate the ETHAuth proof. */
182
175
  authorizeVersion?: number
183
176
 
@@ -270,7 +263,7 @@ export interface Settings {
270
263
  * you can use the camel case version of the name in the wallet settings.
271
264
  * For example: "Blue Dark" on wallet UI can be passed as "blueDark" */
272
265
  export type ThemeOption = 'light' | 'dark' | string
273
- export type PaymentProviderOption = 'ramp' | 'moonpay' | 'transak' | 'onmeta' | 'paytrie' | 'sardine'
266
+ export type PaymentProviderOption = 'moonpay' | 'wyre' | 'ramp'
274
267
  export type CurrencyOption = 'usdc' | 'eth' | 'matic'
275
268
  export type SignInOption = 'email' | 'google' | 'apple' | 'facebook' | 'discord' | 'twitch'
276
269
  export type BannerSize = 'small' | 'medium' // | 'large'