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