@0xsequence/provider 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/0xsequence-provider.cjs.dev.js +27 -21
- package/dist/0xsequence-provider.cjs.prod.js +27 -21
- package/dist/0xsequence-provider.esm.js +28 -22
- package/dist/declarations/src/client.d.ts +5 -5
- package/dist/declarations/src/init.d.ts +1 -1
- package/dist/declarations/src/provider.d.ts +3 -3
- package/dist/declarations/src/signer.d.ts +5 -5
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +3 -3
- package/package.json +10 -10
- package/src/client.ts +76 -76
- package/src/extended.ts +3 -4
- package/src/init.ts +30 -27
- package/src/provider.ts +36 -66
- package/src/signer.ts +38 -54
- package/src/transports/base-wallet-transport.ts +6 -0
- package/src/transports/extension-transport/extension-message-handler.ts +4 -1
- package/src/transports/extension-transport/index.ts +1 -1
- package/src/transports/mux-transport/mux-message-provider.ts +15 -14
- package/src/transports/proxy-transport/proxy-message-channel.ts +0 -1
- package/src/transports/proxy-transport/proxy-message-provider.ts +12 -8
- package/src/transports/unreal-transport/index.ts +1 -1
- package/src/transports/unreal-transport/overridelogs.ts +1 -3
- package/src/transports/wallet-request-handler.ts +77 -52
- package/src/transports/window-transport/window-message-provider.ts +4 -3
- package/src/types.ts +25 -12
- package/src/utils/index.ts +2 -12
- package/src/utils.ts +12 -13
|
@@ -835,6 +835,11 @@ class BaseWalletTransport {
|
|
|
835
835
|
if (connectOptions.app) {
|
|
836
836
|
connectOptions.app = utils.sanitizeAlphanumeric(connectOptions.app);
|
|
837
837
|
}
|
|
838
|
+
if (connectOptions.networkId) {
|
|
839
|
+
networkId = connectOptions.networkId;
|
|
840
|
+
} else if (networkId) {
|
|
841
|
+
connectOptions.networkId = networkId;
|
|
842
|
+
}
|
|
838
843
|
|
|
839
844
|
// Set connect options on the walletRequestHandler as our primary
|
|
840
845
|
// wallet controller, and fall back to networkId if necessary
|
|
@@ -2096,7 +2101,7 @@ class MuxMessageProvider {
|
|
|
2096
2101
|
|
|
2097
2102
|
function toExtended(transactions) {
|
|
2098
2103
|
if (transactions.length === 0) {
|
|
2099
|
-
throw new Error(
|
|
2104
|
+
throw new Error('No transaction provided');
|
|
2100
2105
|
}
|
|
2101
2106
|
const [first, ...rest] = transactions;
|
|
2102
2107
|
return _extends({}, first, {
|
|
@@ -2645,7 +2650,7 @@ class WalletRequestHandler {
|
|
|
2645
2650
|
});
|
|
2646
2651
|
}
|
|
2647
2652
|
async connect(options) {
|
|
2648
|
-
var
|
|
2653
|
+
var _ref, _options$networkId;
|
|
2649
2654
|
if (!this.account) {
|
|
2650
2655
|
return {
|
|
2651
2656
|
connected: false,
|
|
@@ -2653,10 +2658,11 @@ class WalletRequestHandler {
|
|
|
2653
2658
|
error: 'unable to connect without signed in account'
|
|
2654
2659
|
};
|
|
2655
2660
|
}
|
|
2656
|
-
const
|
|
2661
|
+
const networkId = (_ref = (_options$networkId = options == null ? void 0 : options.networkId) != null ? _options$networkId : this.defaultChainId()) != null ? _ref : network.ChainId.MAINNET;
|
|
2662
|
+
const chainId = network.findSupportedNetwork(networkId).chainId;
|
|
2657
2663
|
const connectDetails = {
|
|
2658
2664
|
connected: true,
|
|
2659
|
-
chainId: ethers.ethers.
|
|
2665
|
+
chainId: ethers.ethers.utils.hexValue(chainId)
|
|
2660
2666
|
};
|
|
2661
2667
|
if (options && options.authorize) {
|
|
2662
2668
|
// Perform ethauth eip712 request and construct the ConnectDetails response
|
|
@@ -2730,8 +2736,8 @@ class WalletRequestHandler {
|
|
|
2730
2736
|
(_this$onConnectOption = this.onConnectOptionsChange) == null ? void 0 : _this$onConnectOption.call(this, options);
|
|
2731
2737
|
}
|
|
2732
2738
|
async setDefaultChainId(chainId) {
|
|
2733
|
-
var _this$
|
|
2734
|
-
await ((_this$
|
|
2739
|
+
var _this$prompter4;
|
|
2740
|
+
await ((_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.promptChangeNetwork(chainId));
|
|
2735
2741
|
return this.defaultChainId();
|
|
2736
2742
|
}
|
|
2737
2743
|
async getNetworks(jsonRpcResponse) {
|
|
@@ -2870,7 +2876,7 @@ class SequenceSigner {
|
|
|
2870
2876
|
// it exists to maintain compatibility with ethers.Signer
|
|
2871
2877
|
connect(provider) {
|
|
2872
2878
|
if (!SequenceProvider.is(provider)) {
|
|
2873
|
-
throw new Error(
|
|
2879
|
+
throw new Error('SequenceSigner can only be connected to a SequenceProvider');
|
|
2874
2880
|
}
|
|
2875
2881
|
return new SequenceSigner(this.client, provider);
|
|
2876
2882
|
}
|
|
@@ -2984,35 +2990,35 @@ class SequenceSigner {
|
|
|
2984
2990
|
// We always have a provider, so this is a noop
|
|
2985
2991
|
}
|
|
2986
2992
|
populateTransaction(_transaction) {
|
|
2987
|
-
throw new Error(
|
|
2993
|
+
throw new Error('SequenceSigner does not support populateTransaction');
|
|
2988
2994
|
}
|
|
2989
2995
|
checkTransaction(_transaction) {
|
|
2990
|
-
throw new Error(
|
|
2996
|
+
throw new Error('SequenceSigner does not support checkTransaction');
|
|
2991
2997
|
}
|
|
2992
2998
|
getTransactionCount(_blockTag) {
|
|
2993
2999
|
// We could try returning the sequence nonce here
|
|
2994
3000
|
// but we aren't sure how ethers will use this nonce
|
|
2995
|
-
throw new Error(
|
|
3001
|
+
throw new Error('SequenceSigner does not support getTransactionCount');
|
|
2996
3002
|
}
|
|
2997
3003
|
signTransaction(_transaction) {
|
|
2998
3004
|
// We could implement signTransaction/sendTransaction here
|
|
2999
3005
|
// but first we need a way of serializing these signed transactions
|
|
3000
3006
|
// and it could lead to more trouble, because the dapp could try to send this transaction
|
|
3001
3007
|
// using a different provider, which would fail.
|
|
3002
|
-
throw new Error(
|
|
3008
|
+
throw new Error('SequenceWallet does not support signTransaction, use sendTransaction instead.');
|
|
3003
3009
|
}
|
|
3004
3010
|
static is(cand) {
|
|
3005
|
-
return cand && typeof cand ===
|
|
3011
|
+
return cand && typeof cand === 'object' && cand._isSequenceSigner === true;
|
|
3006
3012
|
}
|
|
3007
3013
|
}
|
|
3008
3014
|
|
|
3009
3015
|
/**
|
|
3010
3016
|
* This is the same provider, but it only allows a single network at a time.
|
|
3011
3017
|
* the network defined by the constructor is the only one that can be used.
|
|
3012
|
-
*
|
|
3018
|
+
*
|
|
3013
3019
|
* Attempting to call any method with a different network will throw an error.
|
|
3014
3020
|
* Attempting to change the network of this provider will throw an error.
|
|
3015
|
-
*
|
|
3021
|
+
*
|
|
3016
3022
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3017
3023
|
*/
|
|
3018
3024
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
@@ -3050,7 +3056,7 @@ class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
|
3050
3056
|
return this;
|
|
3051
3057
|
}
|
|
3052
3058
|
static is(cand) {
|
|
3053
|
-
return cand && typeof cand ===
|
|
3059
|
+
return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceSigner === true;
|
|
3054
3060
|
}
|
|
3055
3061
|
}
|
|
3056
3062
|
|
|
@@ -3275,7 +3281,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3275
3281
|
var _provider$prepareRequ;
|
|
3276
3282
|
// First we check if the method should be handled by the client
|
|
3277
3283
|
if (method === 'eth_chainId') {
|
|
3278
|
-
return this.useChainId();
|
|
3284
|
+
return ethers.ethers.utils.hexValue(await this.useChainId());
|
|
3279
3285
|
}
|
|
3280
3286
|
if (method === 'eth_accounts') {
|
|
3281
3287
|
return [this.client.getAddress()];
|
|
@@ -3433,10 +3439,10 @@ function normalizeChainId(chainId) {
|
|
|
3433
3439
|
/**
|
|
3434
3440
|
* This is the same provider, but it only allows a single network at a time.
|
|
3435
3441
|
* the network defined by the constructor is the only one that can be used.
|
|
3436
|
-
*
|
|
3442
|
+
*
|
|
3437
3443
|
* Attempting to call any method with a different network will throw an error.
|
|
3438
3444
|
* Attempting to change the network of this provider will throw an error.
|
|
3439
|
-
*
|
|
3445
|
+
*
|
|
3440
3446
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3441
3447
|
*/
|
|
3442
3448
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
@@ -3569,7 +3575,7 @@ class DefaultChainIdTracker {
|
|
|
3569
3575
|
/**
|
|
3570
3576
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3571
3577
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3572
|
-
*
|
|
3578
|
+
*
|
|
3573
3579
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3574
3580
|
*/
|
|
3575
3581
|
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
@@ -3594,7 +3600,7 @@ class SequenceClient {
|
|
|
3594
3600
|
});
|
|
3595
3601
|
this.transport.on('connect', response => {
|
|
3596
3602
|
var _this$callbacks$conne;
|
|
3597
|
-
const chainIdHex = ethers.ethers.
|
|
3603
|
+
const chainIdHex = ethers.ethers.utils.hexValue(this.getChainId());
|
|
3598
3604
|
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3599
3605
|
// Ignore the full connect response
|
|
3600
3606
|
// use the chainId defined locally
|
|
@@ -3626,7 +3632,7 @@ class SequenceClient {
|
|
|
3626
3632
|
// instead we handle it locally, so we listen for changes in the store
|
|
3627
3633
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3628
3634
|
var _this$callbacks$chain;
|
|
3629
|
-
const chainIdHex = ethers.ethers.
|
|
3635
|
+
const chainIdHex = ethers.ethers.utils.hexValue(chainId);
|
|
3630
3636
|
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3631
3637
|
});
|
|
3632
3638
|
}
|
|
@@ -835,6 +835,11 @@ class BaseWalletTransport {
|
|
|
835
835
|
if (connectOptions.app) {
|
|
836
836
|
connectOptions.app = utils.sanitizeAlphanumeric(connectOptions.app);
|
|
837
837
|
}
|
|
838
|
+
if (connectOptions.networkId) {
|
|
839
|
+
networkId = connectOptions.networkId;
|
|
840
|
+
} else if (networkId) {
|
|
841
|
+
connectOptions.networkId = networkId;
|
|
842
|
+
}
|
|
838
843
|
|
|
839
844
|
// Set connect options on the walletRequestHandler as our primary
|
|
840
845
|
// wallet controller, and fall back to networkId if necessary
|
|
@@ -2096,7 +2101,7 @@ class MuxMessageProvider {
|
|
|
2096
2101
|
|
|
2097
2102
|
function toExtended(transactions) {
|
|
2098
2103
|
if (transactions.length === 0) {
|
|
2099
|
-
throw new Error(
|
|
2104
|
+
throw new Error('No transaction provided');
|
|
2100
2105
|
}
|
|
2101
2106
|
const [first, ...rest] = transactions;
|
|
2102
2107
|
return _extends({}, first, {
|
|
@@ -2645,7 +2650,7 @@ class WalletRequestHandler {
|
|
|
2645
2650
|
});
|
|
2646
2651
|
}
|
|
2647
2652
|
async connect(options) {
|
|
2648
|
-
var
|
|
2653
|
+
var _ref, _options$networkId;
|
|
2649
2654
|
if (!this.account) {
|
|
2650
2655
|
return {
|
|
2651
2656
|
connected: false,
|
|
@@ -2653,10 +2658,11 @@ class WalletRequestHandler {
|
|
|
2653
2658
|
error: 'unable to connect without signed in account'
|
|
2654
2659
|
};
|
|
2655
2660
|
}
|
|
2656
|
-
const
|
|
2661
|
+
const networkId = (_ref = (_options$networkId = options == null ? void 0 : options.networkId) != null ? _options$networkId : this.defaultChainId()) != null ? _ref : network.ChainId.MAINNET;
|
|
2662
|
+
const chainId = network.findSupportedNetwork(networkId).chainId;
|
|
2657
2663
|
const connectDetails = {
|
|
2658
2664
|
connected: true,
|
|
2659
|
-
chainId: ethers.ethers.
|
|
2665
|
+
chainId: ethers.ethers.utils.hexValue(chainId)
|
|
2660
2666
|
};
|
|
2661
2667
|
if (options && options.authorize) {
|
|
2662
2668
|
// Perform ethauth eip712 request and construct the ConnectDetails response
|
|
@@ -2730,8 +2736,8 @@ class WalletRequestHandler {
|
|
|
2730
2736
|
(_this$onConnectOption = this.onConnectOptionsChange) == null ? void 0 : _this$onConnectOption.call(this, options);
|
|
2731
2737
|
}
|
|
2732
2738
|
async setDefaultChainId(chainId) {
|
|
2733
|
-
var _this$
|
|
2734
|
-
await ((_this$
|
|
2739
|
+
var _this$prompter4;
|
|
2740
|
+
await ((_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.promptChangeNetwork(chainId));
|
|
2735
2741
|
return this.defaultChainId();
|
|
2736
2742
|
}
|
|
2737
2743
|
async getNetworks(jsonRpcResponse) {
|
|
@@ -2870,7 +2876,7 @@ class SequenceSigner {
|
|
|
2870
2876
|
// it exists to maintain compatibility with ethers.Signer
|
|
2871
2877
|
connect(provider) {
|
|
2872
2878
|
if (!SequenceProvider.is(provider)) {
|
|
2873
|
-
throw new Error(
|
|
2879
|
+
throw new Error('SequenceSigner can only be connected to a SequenceProvider');
|
|
2874
2880
|
}
|
|
2875
2881
|
return new SequenceSigner(this.client, provider);
|
|
2876
2882
|
}
|
|
@@ -2984,35 +2990,35 @@ class SequenceSigner {
|
|
|
2984
2990
|
// We always have a provider, so this is a noop
|
|
2985
2991
|
}
|
|
2986
2992
|
populateTransaction(_transaction) {
|
|
2987
|
-
throw new Error(
|
|
2993
|
+
throw new Error('SequenceSigner does not support populateTransaction');
|
|
2988
2994
|
}
|
|
2989
2995
|
checkTransaction(_transaction) {
|
|
2990
|
-
throw new Error(
|
|
2996
|
+
throw new Error('SequenceSigner does not support checkTransaction');
|
|
2991
2997
|
}
|
|
2992
2998
|
getTransactionCount(_blockTag) {
|
|
2993
2999
|
// We could try returning the sequence nonce here
|
|
2994
3000
|
// but we aren't sure how ethers will use this nonce
|
|
2995
|
-
throw new Error(
|
|
3001
|
+
throw new Error('SequenceSigner does not support getTransactionCount');
|
|
2996
3002
|
}
|
|
2997
3003
|
signTransaction(_transaction) {
|
|
2998
3004
|
// We could implement signTransaction/sendTransaction here
|
|
2999
3005
|
// but first we need a way of serializing these signed transactions
|
|
3000
3006
|
// and it could lead to more trouble, because the dapp could try to send this transaction
|
|
3001
3007
|
// using a different provider, which would fail.
|
|
3002
|
-
throw new Error(
|
|
3008
|
+
throw new Error('SequenceWallet does not support signTransaction, use sendTransaction instead.');
|
|
3003
3009
|
}
|
|
3004
3010
|
static is(cand) {
|
|
3005
|
-
return cand && typeof cand ===
|
|
3011
|
+
return cand && typeof cand === 'object' && cand._isSequenceSigner === true;
|
|
3006
3012
|
}
|
|
3007
3013
|
}
|
|
3008
3014
|
|
|
3009
3015
|
/**
|
|
3010
3016
|
* This is the same provider, but it only allows a single network at a time.
|
|
3011
3017
|
* the network defined by the constructor is the only one that can be used.
|
|
3012
|
-
*
|
|
3018
|
+
*
|
|
3013
3019
|
* Attempting to call any method with a different network will throw an error.
|
|
3014
3020
|
* Attempting to change the network of this provider will throw an error.
|
|
3015
|
-
*
|
|
3021
|
+
*
|
|
3016
3022
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3017
3023
|
*/
|
|
3018
3024
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
@@ -3050,7 +3056,7 @@ class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
|
3050
3056
|
return this;
|
|
3051
3057
|
}
|
|
3052
3058
|
static is(cand) {
|
|
3053
|
-
return cand && typeof cand ===
|
|
3059
|
+
return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceSigner === true;
|
|
3054
3060
|
}
|
|
3055
3061
|
}
|
|
3056
3062
|
|
|
@@ -3275,7 +3281,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3275
3281
|
var _provider$prepareRequ;
|
|
3276
3282
|
// First we check if the method should be handled by the client
|
|
3277
3283
|
if (method === 'eth_chainId') {
|
|
3278
|
-
return this.useChainId();
|
|
3284
|
+
return ethers.ethers.utils.hexValue(await this.useChainId());
|
|
3279
3285
|
}
|
|
3280
3286
|
if (method === 'eth_accounts') {
|
|
3281
3287
|
return [this.client.getAddress()];
|
|
@@ -3433,10 +3439,10 @@ function normalizeChainId(chainId) {
|
|
|
3433
3439
|
/**
|
|
3434
3440
|
* This is the same provider, but it only allows a single network at a time.
|
|
3435
3441
|
* the network defined by the constructor is the only one that can be used.
|
|
3436
|
-
*
|
|
3442
|
+
*
|
|
3437
3443
|
* Attempting to call any method with a different network will throw an error.
|
|
3438
3444
|
* Attempting to change the network of this provider will throw an error.
|
|
3439
|
-
*
|
|
3445
|
+
*
|
|
3440
3446
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3441
3447
|
*/
|
|
3442
3448
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
@@ -3569,7 +3575,7 @@ class DefaultChainIdTracker {
|
|
|
3569
3575
|
/**
|
|
3570
3576
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3571
3577
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3572
|
-
*
|
|
3578
|
+
*
|
|
3573
3579
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3574
3580
|
*/
|
|
3575
3581
|
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
@@ -3594,7 +3600,7 @@ class SequenceClient {
|
|
|
3594
3600
|
});
|
|
3595
3601
|
this.transport.on('connect', response => {
|
|
3596
3602
|
var _this$callbacks$conne;
|
|
3597
|
-
const chainIdHex = ethers.ethers.
|
|
3603
|
+
const chainIdHex = ethers.ethers.utils.hexValue(this.getChainId());
|
|
3598
3604
|
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3599
3605
|
// Ignore the full connect response
|
|
3600
3606
|
// use the chainId defined locally
|
|
@@ -3626,7 +3632,7 @@ class SequenceClient {
|
|
|
3626
3632
|
// instead we handle it locally, so we listen for changes in the store
|
|
3627
3633
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3628
3634
|
var _this$callbacks$chain;
|
|
3629
|
-
const chainIdHex = ethers.ethers.
|
|
3635
|
+
const chainIdHex = ethers.ethers.utils.hexValue(chainId);
|
|
3630
3636
|
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3631
3637
|
});
|
|
3632
3638
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter2 } from 'eventemitter2';
|
|
2
2
|
import { logger, encodeMessageDigest, encodeTypedDataDigest, sanitizeNumberString, sanitizeHost, sanitizeAlphanumeric, base64EncodeObject, base64DecodeObject } from '@0xsequence/utils';
|
|
3
3
|
import { ethers, BigNumber } from 'ethers';
|
|
4
|
-
import { findSupportedNetwork, allNetworks, findNetworkConfig, JsonRpcRouter, loggingProviderMiddleware, exceptionProviderMiddleware, CachedProvider, JsonRpcSender } from '@0xsequence/network';
|
|
4
|
+
import { findSupportedNetwork, ChainId, allNetworks, findNetworkConfig, JsonRpcRouter, loggingProviderMiddleware, exceptionProviderMiddleware, CachedProvider, JsonRpcSender } from '@0xsequence/network';
|
|
5
5
|
import { commons } from '@0xsequence/core';
|
|
6
6
|
import { signAuthorization } from '@0xsequence/auth';
|
|
7
7
|
|
|
@@ -831,6 +831,11 @@ class BaseWalletTransport {
|
|
|
831
831
|
if (connectOptions.app) {
|
|
832
832
|
connectOptions.app = sanitizeAlphanumeric(connectOptions.app);
|
|
833
833
|
}
|
|
834
|
+
if (connectOptions.networkId) {
|
|
835
|
+
networkId = connectOptions.networkId;
|
|
836
|
+
} else if (networkId) {
|
|
837
|
+
connectOptions.networkId = networkId;
|
|
838
|
+
}
|
|
834
839
|
|
|
835
840
|
// Set connect options on the walletRequestHandler as our primary
|
|
836
841
|
// wallet controller, and fall back to networkId if necessary
|
|
@@ -2092,7 +2097,7 @@ class MuxMessageProvider {
|
|
|
2092
2097
|
|
|
2093
2098
|
function toExtended(transactions) {
|
|
2094
2099
|
if (transactions.length === 0) {
|
|
2095
|
-
throw new Error(
|
|
2100
|
+
throw new Error('No transaction provided');
|
|
2096
2101
|
}
|
|
2097
2102
|
const [first, ...rest] = transactions;
|
|
2098
2103
|
return _extends({}, first, {
|
|
@@ -2641,7 +2646,7 @@ class WalletRequestHandler {
|
|
|
2641
2646
|
});
|
|
2642
2647
|
}
|
|
2643
2648
|
async connect(options) {
|
|
2644
|
-
var
|
|
2649
|
+
var _ref, _options$networkId;
|
|
2645
2650
|
if (!this.account) {
|
|
2646
2651
|
return {
|
|
2647
2652
|
connected: false,
|
|
@@ -2649,10 +2654,11 @@ class WalletRequestHandler {
|
|
|
2649
2654
|
error: 'unable to connect without signed in account'
|
|
2650
2655
|
};
|
|
2651
2656
|
}
|
|
2652
|
-
const
|
|
2657
|
+
const networkId = (_ref = (_options$networkId = options == null ? void 0 : options.networkId) != null ? _options$networkId : this.defaultChainId()) != null ? _ref : ChainId.MAINNET;
|
|
2658
|
+
const chainId = findSupportedNetwork(networkId).chainId;
|
|
2653
2659
|
const connectDetails = {
|
|
2654
2660
|
connected: true,
|
|
2655
|
-
chainId: ethers.
|
|
2661
|
+
chainId: ethers.utils.hexValue(chainId)
|
|
2656
2662
|
};
|
|
2657
2663
|
if (options && options.authorize) {
|
|
2658
2664
|
// Perform ethauth eip712 request and construct the ConnectDetails response
|
|
@@ -2726,8 +2732,8 @@ class WalletRequestHandler {
|
|
|
2726
2732
|
(_this$onConnectOption = this.onConnectOptionsChange) == null ? void 0 : _this$onConnectOption.call(this, options);
|
|
2727
2733
|
}
|
|
2728
2734
|
async setDefaultChainId(chainId) {
|
|
2729
|
-
var _this$
|
|
2730
|
-
await ((_this$
|
|
2735
|
+
var _this$prompter4;
|
|
2736
|
+
await ((_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.promptChangeNetwork(chainId));
|
|
2731
2737
|
return this.defaultChainId();
|
|
2732
2738
|
}
|
|
2733
2739
|
async getNetworks(jsonRpcResponse) {
|
|
@@ -2866,7 +2872,7 @@ class SequenceSigner {
|
|
|
2866
2872
|
// it exists to maintain compatibility with ethers.Signer
|
|
2867
2873
|
connect(provider) {
|
|
2868
2874
|
if (!SequenceProvider.is(provider)) {
|
|
2869
|
-
throw new Error(
|
|
2875
|
+
throw new Error('SequenceSigner can only be connected to a SequenceProvider');
|
|
2870
2876
|
}
|
|
2871
2877
|
return new SequenceSigner(this.client, provider);
|
|
2872
2878
|
}
|
|
@@ -2980,35 +2986,35 @@ class SequenceSigner {
|
|
|
2980
2986
|
// We always have a provider, so this is a noop
|
|
2981
2987
|
}
|
|
2982
2988
|
populateTransaction(_transaction) {
|
|
2983
|
-
throw new Error(
|
|
2989
|
+
throw new Error('SequenceSigner does not support populateTransaction');
|
|
2984
2990
|
}
|
|
2985
2991
|
checkTransaction(_transaction) {
|
|
2986
|
-
throw new Error(
|
|
2992
|
+
throw new Error('SequenceSigner does not support checkTransaction');
|
|
2987
2993
|
}
|
|
2988
2994
|
getTransactionCount(_blockTag) {
|
|
2989
2995
|
// We could try returning the sequence nonce here
|
|
2990
2996
|
// but we aren't sure how ethers will use this nonce
|
|
2991
|
-
throw new Error(
|
|
2997
|
+
throw new Error('SequenceSigner does not support getTransactionCount');
|
|
2992
2998
|
}
|
|
2993
2999
|
signTransaction(_transaction) {
|
|
2994
3000
|
// We could implement signTransaction/sendTransaction here
|
|
2995
3001
|
// but first we need a way of serializing these signed transactions
|
|
2996
3002
|
// and it could lead to more trouble, because the dapp could try to send this transaction
|
|
2997
3003
|
// using a different provider, which would fail.
|
|
2998
|
-
throw new Error(
|
|
3004
|
+
throw new Error('SequenceWallet does not support signTransaction, use sendTransaction instead.');
|
|
2999
3005
|
}
|
|
3000
3006
|
static is(cand) {
|
|
3001
|
-
return cand && typeof cand ===
|
|
3007
|
+
return cand && typeof cand === 'object' && cand._isSequenceSigner === true;
|
|
3002
3008
|
}
|
|
3003
3009
|
}
|
|
3004
3010
|
|
|
3005
3011
|
/**
|
|
3006
3012
|
* This is the same provider, but it only allows a single network at a time.
|
|
3007
3013
|
* the network defined by the constructor is the only one that can be used.
|
|
3008
|
-
*
|
|
3014
|
+
*
|
|
3009
3015
|
* Attempting to call any method with a different network will throw an error.
|
|
3010
3016
|
* Attempting to change the network of this provider will throw an error.
|
|
3011
|
-
*
|
|
3017
|
+
*
|
|
3012
3018
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3013
3019
|
*/
|
|
3014
3020
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
@@ -3046,7 +3052,7 @@ class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
|
3046
3052
|
return this;
|
|
3047
3053
|
}
|
|
3048
3054
|
static is(cand) {
|
|
3049
|
-
return cand && typeof cand ===
|
|
3055
|
+
return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceSigner === true;
|
|
3050
3056
|
}
|
|
3051
3057
|
}
|
|
3052
3058
|
|
|
@@ -3271,7 +3277,7 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3271
3277
|
var _provider$prepareRequ;
|
|
3272
3278
|
// First we check if the method should be handled by the client
|
|
3273
3279
|
if (method === 'eth_chainId') {
|
|
3274
|
-
return this.useChainId();
|
|
3280
|
+
return ethers.utils.hexValue(await this.useChainId());
|
|
3275
3281
|
}
|
|
3276
3282
|
if (method === 'eth_accounts') {
|
|
3277
3283
|
return [this.client.getAddress()];
|
|
@@ -3429,10 +3435,10 @@ function normalizeChainId(chainId) {
|
|
|
3429
3435
|
/**
|
|
3430
3436
|
* This is the same provider, but it only allows a single network at a time.
|
|
3431
3437
|
* the network defined by the constructor is the only one that can be used.
|
|
3432
|
-
*
|
|
3438
|
+
*
|
|
3433
3439
|
* Attempting to call any method with a different network will throw an error.
|
|
3434
3440
|
* Attempting to change the network of this provider will throw an error.
|
|
3435
|
-
*
|
|
3441
|
+
*
|
|
3436
3442
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3437
3443
|
*/
|
|
3438
3444
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
@@ -3565,7 +3571,7 @@ class DefaultChainIdTracker {
|
|
|
3565
3571
|
/**
|
|
3566
3572
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3567
3573
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3568
|
-
*
|
|
3574
|
+
*
|
|
3569
3575
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3570
3576
|
*/
|
|
3571
3577
|
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
@@ -3590,7 +3596,7 @@ class SequenceClient {
|
|
|
3590
3596
|
});
|
|
3591
3597
|
this.transport.on('connect', response => {
|
|
3592
3598
|
var _this$callbacks$conne;
|
|
3593
|
-
const chainIdHex = ethers.
|
|
3599
|
+
const chainIdHex = ethers.utils.hexValue(this.getChainId());
|
|
3594
3600
|
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3595
3601
|
// Ignore the full connect response
|
|
3596
3602
|
// use the chainId defined locally
|
|
@@ -3622,7 +3628,7 @@ class SequenceClient {
|
|
|
3622
3628
|
// instead we handle it locally, so we listen for changes in the store
|
|
3623
3629
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3624
3630
|
var _this$callbacks$chain;
|
|
3625
|
-
const chainIdHex = ethers.
|
|
3631
|
+
const chainIdHex = ethers.utils.hexValue(chainId);
|
|
3626
3632
|
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3627
3633
|
});
|
|
3628
3634
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { JsonRpcRequest, NetworkConfig } from
|
|
1
|
+
import { JsonRpcRequest, NetworkConfig } from '@0xsequence/network';
|
|
2
2
|
import { ConnectDetails, ConnectOptions, ItemStore, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletEventTypes, WalletSession } from "./index.js";
|
|
3
|
-
import { commons } from
|
|
4
|
-
import { TypedData } from
|
|
5
|
-
import { ethers } from
|
|
3
|
+
import { commons } from '@0xsequence/core';
|
|
4
|
+
import { TypedData } from '@0xsequence/utils';
|
|
5
|
+
import { ethers } from 'ethers';
|
|
6
6
|
/**
|
|
7
7
|
* This session class is meant to persist the state of the wallet connection
|
|
8
8
|
* whitin the dapp. This enables the client to retain the wallet address (and some more)
|
|
@@ -68,7 +68,7 @@ export declare class SequenceClient {
|
|
|
68
68
|
getNetworks(pull?: boolean): Promise<NetworkConfig[]>;
|
|
69
69
|
signMessage(message: ethers.BytesLike, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
|
70
70
|
signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
|
71
|
-
sendTransaction(tx:
|
|
71
|
+
sendTransaction(tx: ethers.providers.TransactionRequest[] | ethers.providers.TransactionRequest, options?: OptionalChainId): Promise<string>;
|
|
72
72
|
getWalletContext(): Promise<commons.context.VersionedContext>;
|
|
73
73
|
getOnchainWalletConfig(options?: OptionalChainId): Promise<commons.config.Config>;
|
|
74
74
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainIdLike, NetworkConfig } from
|
|
1
|
+
import { ChainIdLike, NetworkConfig } from '@0xsequence/network';
|
|
2
2
|
import { MuxTransportTemplate } from "./transports/index.js";
|
|
3
3
|
import { ItemStore } from "./utils.js";
|
|
4
4
|
import { SequenceProvider } from "./provider.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ethers } from
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
2
|
import { SequenceClient } from "./client.js";
|
|
3
|
-
import { ChainIdLike, NetworkConfig } from
|
|
3
|
+
import { ChainIdLike, NetworkConfig } from '@0xsequence/network';
|
|
4
4
|
import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types.js";
|
|
5
|
-
import { commons } from
|
|
5
|
+
import { commons } from '@0xsequence/core';
|
|
6
6
|
import { WalletUtils } from "./utils/index.js";
|
|
7
7
|
import { SequenceSigner, SingleNetworkSequenceSigner } from "./signer.js";
|
|
8
8
|
export interface ISequenceProvider {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ethers } from
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
2
|
import { SequenceProvider, SingleNetworkSequenceProvider } from "./provider.js";
|
|
3
3
|
import { SequenceClient } from "./client.js";
|
|
4
|
-
import { commons } from
|
|
5
|
-
import { ChainIdLike, NetworkConfig } from
|
|
4
|
+
import { commons } from '@0xsequence/core';
|
|
5
|
+
import { ChainIdLike, NetworkConfig } from '@0xsequence/network';
|
|
6
6
|
import { WalletUtils } from "./utils/index.js";
|
|
7
7
|
import { OptionalChainIdLike, OptionalEIP6492 } from "./types.js";
|
|
8
8
|
export interface ISequenceSigner extends ethers.Signer {
|
|
@@ -16,7 +16,7 @@ export interface ISequenceSigner extends ethers.Signer {
|
|
|
16
16
|
getNetworks(): Promise<NetworkConfig[]>;
|
|
17
17
|
signMessage(message: ethers.BytesLike, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
|
|
18
18
|
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, message: Record<string, any>, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
|
|
19
|
-
sendTransaction(transaction:
|
|
19
|
+
sendTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>[] | ethers.utils.Deferrable<ethers.providers.TransactionRequest>, options?: OptionalChainIdLike): Promise<commons.transaction.TransactionResponse>;
|
|
20
20
|
utils: WalletUtils;
|
|
21
21
|
}
|
|
22
22
|
export declare class SequenceSigner implements ISequenceSigner {
|
|
@@ -43,7 +43,7 @@ export declare class SequenceSigner implements ISequenceSigner {
|
|
|
43
43
|
getProvider(): SequenceProvider;
|
|
44
44
|
getProvider(chainId: ChainIdLike): SingleNetworkSequenceProvider;
|
|
45
45
|
getProvider(chainId?: ChainIdLike): SingleNetworkSequenceProvider | SequenceProvider;
|
|
46
|
-
sendTransaction(transaction:
|
|
46
|
+
sendTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>[] | ethers.utils.Deferrable<ethers.providers.TransactionRequest>, options?: OptionalChainIdLike): Promise<ethers.providers.TransactionResponse>;
|
|
47
47
|
getWalletConfig(chainId?: ChainIdLike | undefined): Promise<commons.config.Config>;
|
|
48
48
|
getNetworks(): Promise<NetworkConfig[]>;
|
|
49
49
|
getBalance(blockTag?: ethers.providers.BlockTag | undefined, optionals?: OptionalChainIdLike): Promise<ethers.BigNumber>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Account } from '@0xsequence/account';
|
|
2
2
|
import { commons } from '@0xsequence/core';
|
|
3
|
-
import {
|
|
3
|
+
import { JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback, NetworkConfig } from '@0xsequence/network';
|
|
4
4
|
import { providers } from 'ethers';
|
|
5
|
-
import {
|
|
5
|
+
import { ConnectDetails, ConnectOptions, MessageToSign, NetworkedConnectOptions, OpenWalletIntent, PromptConnectDetails, ProviderEventTypes, ProviderMessageRequest, ProviderMessageRequestHandler, ProviderMessageResponse, ProviderRpcError, WalletSession } from "../types.js";
|
|
6
6
|
type ExternalProvider = providers.ExternalProvider;
|
|
7
7
|
export interface WalletSignInOptions {
|
|
8
8
|
connect?: boolean;
|
|
@@ -23,7 +23,7 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
23
23
|
signOut(): void;
|
|
24
24
|
signerReset(): void;
|
|
25
25
|
signerReady(timeout?: number): Promise<void>;
|
|
26
|
-
connect(options?:
|
|
26
|
+
connect(options?: NetworkedConnectOptions): Promise<ConnectDetails>;
|
|
27
27
|
promptConnect: (options?: ConnectOptions) => Promise<ConnectDetails>;
|
|
28
28
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
29
29
|
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "provider sub-package for Sequence",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"eventemitter2": "^6.4.5",
|
|
13
13
|
"webextension-polyfill": "^0.10.0",
|
|
14
|
-
"@0xsequence/
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/auth": "1.1.
|
|
17
|
-
"@0xsequence/core": "1.1.
|
|
18
|
-
"@0xsequence/migration": "1.1.
|
|
19
|
-
"@0xsequence/network": "1.1.
|
|
20
|
-
"@0xsequence/relayer": "1.1.
|
|
21
|
-
"@0xsequence/utils": "1.1.
|
|
22
|
-
"@0xsequence/wallet": "1.1.
|
|
14
|
+
"@0xsequence/abi": "1.1.3",
|
|
15
|
+
"@0xsequence/account": "1.1.3",
|
|
16
|
+
"@0xsequence/auth": "1.1.3",
|
|
17
|
+
"@0xsequence/core": "1.1.3",
|
|
18
|
+
"@0xsequence/migration": "1.1.3",
|
|
19
|
+
"@0xsequence/network": "1.1.3",
|
|
20
|
+
"@0xsequence/relayer": "1.1.3",
|
|
21
|
+
"@0xsequence/utils": "1.1.3",
|
|
22
|
+
"@0xsequence/wallet": "1.1.3"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|