@0xsequence/provider 1.1.0 → 1.1.2
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 +38 -17
- package/dist/0xsequence-provider.cjs.prod.js +38 -17
- package/dist/0xsequence-provider.esm.js +38 -17
- 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/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/transactions.ts +23 -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 +67 -40
- 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
|
@@ -2096,7 +2096,7 @@ class MuxMessageProvider {
|
|
|
2096
2096
|
|
|
2097
2097
|
function toExtended(transactions) {
|
|
2098
2098
|
if (transactions.length === 0) {
|
|
2099
|
-
throw new Error(
|
|
2099
|
+
throw new Error('No transaction provided');
|
|
2100
2100
|
}
|
|
2101
2101
|
const [first, ...rest] = transactions;
|
|
2102
2102
|
return _extends({}, first, {
|
|
@@ -2107,6 +2107,25 @@ function fromExtended(transaction) {
|
|
|
2107
2107
|
return [transaction, ...(transaction.auxiliary || [])];
|
|
2108
2108
|
}
|
|
2109
2109
|
|
|
2110
|
+
function validateTransactionRequest(wallet, transaction) {
|
|
2111
|
+
const transactions = core.commons.transaction.fromTransactionish(wallet, transaction);
|
|
2112
|
+
const unwound = core.commons.transaction.unwind(wallet, transactions);
|
|
2113
|
+
unwound.forEach(transaction => validateTransaction(wallet, transaction));
|
|
2114
|
+
}
|
|
2115
|
+
function validateTransaction(wallet, transaction) {
|
|
2116
|
+
if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
|
|
2117
|
+
if (transaction.data) {
|
|
2118
|
+
const data = ethers.ethers.utils.arrayify(transaction.data);
|
|
2119
|
+
if (data.length >= 4) {
|
|
2120
|
+
throw new Error('self calls are forbidden');
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
if (transaction.delegateCall) {
|
|
2125
|
+
throw new Error('delegate calls are forbidden');
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2110
2129
|
const SIGNER_READY_TIMEOUT = 10000;
|
|
2111
2130
|
class WalletRequestHandler {
|
|
2112
2131
|
constructor(_account, prompter, networks) {
|
|
@@ -2297,6 +2316,7 @@ class WalletRequestHandler {
|
|
|
2297
2316
|
}
|
|
2298
2317
|
return tx;
|
|
2299
2318
|
});
|
|
2319
|
+
validateTransactionRequest(account.address, transactionParams);
|
|
2300
2320
|
let txnHash = '';
|
|
2301
2321
|
if (_this.prompter === null) {
|
|
2302
2322
|
// prompter is null, so we'll send from here
|
|
@@ -2322,6 +2342,7 @@ class WalletRequestHandler {
|
|
|
2322
2342
|
if (sender !== account.address) {
|
|
2323
2343
|
throw new Error('sender address does not match wallet');
|
|
2324
2344
|
}
|
|
2345
|
+
validateTransactionRequest(account.address, transaction);
|
|
2325
2346
|
if (_this.prompter === null) {
|
|
2326
2347
|
// The eth_signTransaction method expects a `string` return value we instead return a `SignedTransactions` object,
|
|
2327
2348
|
// this can only be broadcasted using an RPC provider with support for signed Sequence transactions, like this one.
|
|
@@ -2635,7 +2656,7 @@ class WalletRequestHandler {
|
|
|
2635
2656
|
const chainId = (_this$prompter$getDef2 = (_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.getDefaultChainId()) != null ? _this$prompter$getDef2 : 1;
|
|
2636
2657
|
const connectDetails = {
|
|
2637
2658
|
connected: true,
|
|
2638
|
-
chainId: ethers.ethers.
|
|
2659
|
+
chainId: ethers.ethers.utils.hexValue(chainId)
|
|
2639
2660
|
};
|
|
2640
2661
|
if (options && options.authorize) {
|
|
2641
2662
|
// Perform ethauth eip712 request and construct the ConnectDetails response
|
|
@@ -2849,7 +2870,7 @@ class SequenceSigner {
|
|
|
2849
2870
|
// it exists to maintain compatibility with ethers.Signer
|
|
2850
2871
|
connect(provider) {
|
|
2851
2872
|
if (!SequenceProvider.is(provider)) {
|
|
2852
|
-
throw new Error(
|
|
2873
|
+
throw new Error('SequenceSigner can only be connected to a SequenceProvider');
|
|
2853
2874
|
}
|
|
2854
2875
|
return new SequenceSigner(this.client, provider);
|
|
2855
2876
|
}
|
|
@@ -2963,35 +2984,35 @@ class SequenceSigner {
|
|
|
2963
2984
|
// We always have a provider, so this is a noop
|
|
2964
2985
|
}
|
|
2965
2986
|
populateTransaction(_transaction) {
|
|
2966
|
-
throw new Error(
|
|
2987
|
+
throw new Error('SequenceSigner does not support populateTransaction');
|
|
2967
2988
|
}
|
|
2968
2989
|
checkTransaction(_transaction) {
|
|
2969
|
-
throw new Error(
|
|
2990
|
+
throw new Error('SequenceSigner does not support checkTransaction');
|
|
2970
2991
|
}
|
|
2971
2992
|
getTransactionCount(_blockTag) {
|
|
2972
2993
|
// We could try returning the sequence nonce here
|
|
2973
2994
|
// but we aren't sure how ethers will use this nonce
|
|
2974
|
-
throw new Error(
|
|
2995
|
+
throw new Error('SequenceSigner does not support getTransactionCount');
|
|
2975
2996
|
}
|
|
2976
2997
|
signTransaction(_transaction) {
|
|
2977
2998
|
// We could implement signTransaction/sendTransaction here
|
|
2978
2999
|
// but first we need a way of serializing these signed transactions
|
|
2979
3000
|
// and it could lead to more trouble, because the dapp could try to send this transaction
|
|
2980
3001
|
// using a different provider, which would fail.
|
|
2981
|
-
throw new Error(
|
|
3002
|
+
throw new Error('SequenceWallet does not support signTransaction, use sendTransaction instead.');
|
|
2982
3003
|
}
|
|
2983
3004
|
static is(cand) {
|
|
2984
|
-
return cand && typeof cand ===
|
|
3005
|
+
return cand && typeof cand === 'object' && cand._isSequenceSigner === true;
|
|
2985
3006
|
}
|
|
2986
3007
|
}
|
|
2987
3008
|
|
|
2988
3009
|
/**
|
|
2989
3010
|
* This is the same provider, but it only allows a single network at a time.
|
|
2990
3011
|
* the network defined by the constructor is the only one that can be used.
|
|
2991
|
-
*
|
|
3012
|
+
*
|
|
2992
3013
|
* Attempting to call any method with a different network will throw an error.
|
|
2993
3014
|
* Attempting to change the network of this provider will throw an error.
|
|
2994
|
-
*
|
|
3015
|
+
*
|
|
2995
3016
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
2996
3017
|
*/
|
|
2997
3018
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
@@ -3029,7 +3050,7 @@ class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
|
3029
3050
|
return this;
|
|
3030
3051
|
}
|
|
3031
3052
|
static is(cand) {
|
|
3032
|
-
return cand && typeof cand ===
|
|
3053
|
+
return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceSigner === true;
|
|
3033
3054
|
}
|
|
3034
3055
|
}
|
|
3035
3056
|
|
|
@@ -3254,7 +3275,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3254
3275
|
var _provider$prepareRequ;
|
|
3255
3276
|
// First we check if the method should be handled by the client
|
|
3256
3277
|
if (method === 'eth_chainId') {
|
|
3257
|
-
return this.useChainId();
|
|
3278
|
+
return ethers.ethers.utils.hexValue(await this.useChainId());
|
|
3258
3279
|
}
|
|
3259
3280
|
if (method === 'eth_accounts') {
|
|
3260
3281
|
return [this.client.getAddress()];
|
|
@@ -3412,10 +3433,10 @@ function normalizeChainId(chainId) {
|
|
|
3412
3433
|
/**
|
|
3413
3434
|
* This is the same provider, but it only allows a single network at a time.
|
|
3414
3435
|
* the network defined by the constructor is the only one that can be used.
|
|
3415
|
-
*
|
|
3436
|
+
*
|
|
3416
3437
|
* Attempting to call any method with a different network will throw an error.
|
|
3417
3438
|
* Attempting to change the network of this provider will throw an error.
|
|
3418
|
-
*
|
|
3439
|
+
*
|
|
3419
3440
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3420
3441
|
*/
|
|
3421
3442
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
@@ -3548,7 +3569,7 @@ class DefaultChainIdTracker {
|
|
|
3548
3569
|
/**
|
|
3549
3570
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3550
3571
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3551
|
-
*
|
|
3572
|
+
*
|
|
3552
3573
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3553
3574
|
*/
|
|
3554
3575
|
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
@@ -3573,7 +3594,7 @@ class SequenceClient {
|
|
|
3573
3594
|
});
|
|
3574
3595
|
this.transport.on('connect', response => {
|
|
3575
3596
|
var _this$callbacks$conne;
|
|
3576
|
-
const chainIdHex = ethers.ethers.
|
|
3597
|
+
const chainIdHex = ethers.ethers.utils.hexValue(this.getChainId());
|
|
3577
3598
|
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3578
3599
|
// Ignore the full connect response
|
|
3579
3600
|
// use the chainId defined locally
|
|
@@ -3605,7 +3626,7 @@ class SequenceClient {
|
|
|
3605
3626
|
// instead we handle it locally, so we listen for changes in the store
|
|
3606
3627
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3607
3628
|
var _this$callbacks$chain;
|
|
3608
|
-
const chainIdHex = ethers.ethers.
|
|
3629
|
+
const chainIdHex = ethers.ethers.utils.hexValue(chainId);
|
|
3609
3630
|
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3610
3631
|
});
|
|
3611
3632
|
}
|
|
@@ -2096,7 +2096,7 @@ class MuxMessageProvider {
|
|
|
2096
2096
|
|
|
2097
2097
|
function toExtended(transactions) {
|
|
2098
2098
|
if (transactions.length === 0) {
|
|
2099
|
-
throw new Error(
|
|
2099
|
+
throw new Error('No transaction provided');
|
|
2100
2100
|
}
|
|
2101
2101
|
const [first, ...rest] = transactions;
|
|
2102
2102
|
return _extends({}, first, {
|
|
@@ -2107,6 +2107,25 @@ function fromExtended(transaction) {
|
|
|
2107
2107
|
return [transaction, ...(transaction.auxiliary || [])];
|
|
2108
2108
|
}
|
|
2109
2109
|
|
|
2110
|
+
function validateTransactionRequest(wallet, transaction) {
|
|
2111
|
+
const transactions = core.commons.transaction.fromTransactionish(wallet, transaction);
|
|
2112
|
+
const unwound = core.commons.transaction.unwind(wallet, transactions);
|
|
2113
|
+
unwound.forEach(transaction => validateTransaction(wallet, transaction));
|
|
2114
|
+
}
|
|
2115
|
+
function validateTransaction(wallet, transaction) {
|
|
2116
|
+
if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
|
|
2117
|
+
if (transaction.data) {
|
|
2118
|
+
const data = ethers.ethers.utils.arrayify(transaction.data);
|
|
2119
|
+
if (data.length >= 4) {
|
|
2120
|
+
throw new Error('self calls are forbidden');
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
if (transaction.delegateCall) {
|
|
2125
|
+
throw new Error('delegate calls are forbidden');
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2110
2129
|
const SIGNER_READY_TIMEOUT = 10000;
|
|
2111
2130
|
class WalletRequestHandler {
|
|
2112
2131
|
constructor(_account, prompter, networks) {
|
|
@@ -2297,6 +2316,7 @@ class WalletRequestHandler {
|
|
|
2297
2316
|
}
|
|
2298
2317
|
return tx;
|
|
2299
2318
|
});
|
|
2319
|
+
validateTransactionRequest(account.address, transactionParams);
|
|
2300
2320
|
let txnHash = '';
|
|
2301
2321
|
if (_this.prompter === null) {
|
|
2302
2322
|
// prompter is null, so we'll send from here
|
|
@@ -2322,6 +2342,7 @@ class WalletRequestHandler {
|
|
|
2322
2342
|
if (sender !== account.address) {
|
|
2323
2343
|
throw new Error('sender address does not match wallet');
|
|
2324
2344
|
}
|
|
2345
|
+
validateTransactionRequest(account.address, transaction);
|
|
2325
2346
|
if (_this.prompter === null) {
|
|
2326
2347
|
// The eth_signTransaction method expects a `string` return value we instead return a `SignedTransactions` object,
|
|
2327
2348
|
// this can only be broadcasted using an RPC provider with support for signed Sequence transactions, like this one.
|
|
@@ -2635,7 +2656,7 @@ class WalletRequestHandler {
|
|
|
2635
2656
|
const chainId = (_this$prompter$getDef2 = (_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.getDefaultChainId()) != null ? _this$prompter$getDef2 : 1;
|
|
2636
2657
|
const connectDetails = {
|
|
2637
2658
|
connected: true,
|
|
2638
|
-
chainId: ethers.ethers.
|
|
2659
|
+
chainId: ethers.ethers.utils.hexValue(chainId)
|
|
2639
2660
|
};
|
|
2640
2661
|
if (options && options.authorize) {
|
|
2641
2662
|
// Perform ethauth eip712 request and construct the ConnectDetails response
|
|
@@ -2849,7 +2870,7 @@ class SequenceSigner {
|
|
|
2849
2870
|
// it exists to maintain compatibility with ethers.Signer
|
|
2850
2871
|
connect(provider) {
|
|
2851
2872
|
if (!SequenceProvider.is(provider)) {
|
|
2852
|
-
throw new Error(
|
|
2873
|
+
throw new Error('SequenceSigner can only be connected to a SequenceProvider');
|
|
2853
2874
|
}
|
|
2854
2875
|
return new SequenceSigner(this.client, provider);
|
|
2855
2876
|
}
|
|
@@ -2963,35 +2984,35 @@ class SequenceSigner {
|
|
|
2963
2984
|
// We always have a provider, so this is a noop
|
|
2964
2985
|
}
|
|
2965
2986
|
populateTransaction(_transaction) {
|
|
2966
|
-
throw new Error(
|
|
2987
|
+
throw new Error('SequenceSigner does not support populateTransaction');
|
|
2967
2988
|
}
|
|
2968
2989
|
checkTransaction(_transaction) {
|
|
2969
|
-
throw new Error(
|
|
2990
|
+
throw new Error('SequenceSigner does not support checkTransaction');
|
|
2970
2991
|
}
|
|
2971
2992
|
getTransactionCount(_blockTag) {
|
|
2972
2993
|
// We could try returning the sequence nonce here
|
|
2973
2994
|
// but we aren't sure how ethers will use this nonce
|
|
2974
|
-
throw new Error(
|
|
2995
|
+
throw new Error('SequenceSigner does not support getTransactionCount');
|
|
2975
2996
|
}
|
|
2976
2997
|
signTransaction(_transaction) {
|
|
2977
2998
|
// We could implement signTransaction/sendTransaction here
|
|
2978
2999
|
// but first we need a way of serializing these signed transactions
|
|
2979
3000
|
// and it could lead to more trouble, because the dapp could try to send this transaction
|
|
2980
3001
|
// using a different provider, which would fail.
|
|
2981
|
-
throw new Error(
|
|
3002
|
+
throw new Error('SequenceWallet does not support signTransaction, use sendTransaction instead.');
|
|
2982
3003
|
}
|
|
2983
3004
|
static is(cand) {
|
|
2984
|
-
return cand && typeof cand ===
|
|
3005
|
+
return cand && typeof cand === 'object' && cand._isSequenceSigner === true;
|
|
2985
3006
|
}
|
|
2986
3007
|
}
|
|
2987
3008
|
|
|
2988
3009
|
/**
|
|
2989
3010
|
* This is the same provider, but it only allows a single network at a time.
|
|
2990
3011
|
* the network defined by the constructor is the only one that can be used.
|
|
2991
|
-
*
|
|
3012
|
+
*
|
|
2992
3013
|
* Attempting to call any method with a different network will throw an error.
|
|
2993
3014
|
* Attempting to change the network of this provider will throw an error.
|
|
2994
|
-
*
|
|
3015
|
+
*
|
|
2995
3016
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
2996
3017
|
*/
|
|
2997
3018
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
@@ -3029,7 +3050,7 @@ class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
|
3029
3050
|
return this;
|
|
3030
3051
|
}
|
|
3031
3052
|
static is(cand) {
|
|
3032
|
-
return cand && typeof cand ===
|
|
3053
|
+
return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceSigner === true;
|
|
3033
3054
|
}
|
|
3034
3055
|
}
|
|
3035
3056
|
|
|
@@ -3254,7 +3275,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3254
3275
|
var _provider$prepareRequ;
|
|
3255
3276
|
// First we check if the method should be handled by the client
|
|
3256
3277
|
if (method === 'eth_chainId') {
|
|
3257
|
-
return this.useChainId();
|
|
3278
|
+
return ethers.ethers.utils.hexValue(await this.useChainId());
|
|
3258
3279
|
}
|
|
3259
3280
|
if (method === 'eth_accounts') {
|
|
3260
3281
|
return [this.client.getAddress()];
|
|
@@ -3412,10 +3433,10 @@ function normalizeChainId(chainId) {
|
|
|
3412
3433
|
/**
|
|
3413
3434
|
* This is the same provider, but it only allows a single network at a time.
|
|
3414
3435
|
* the network defined by the constructor is the only one that can be used.
|
|
3415
|
-
*
|
|
3436
|
+
*
|
|
3416
3437
|
* Attempting to call any method with a different network will throw an error.
|
|
3417
3438
|
* Attempting to change the network of this provider will throw an error.
|
|
3418
|
-
*
|
|
3439
|
+
*
|
|
3419
3440
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3420
3441
|
*/
|
|
3421
3442
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
@@ -3548,7 +3569,7 @@ class DefaultChainIdTracker {
|
|
|
3548
3569
|
/**
|
|
3549
3570
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3550
3571
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3551
|
-
*
|
|
3572
|
+
*
|
|
3552
3573
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3553
3574
|
*/
|
|
3554
3575
|
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
@@ -3573,7 +3594,7 @@ class SequenceClient {
|
|
|
3573
3594
|
});
|
|
3574
3595
|
this.transport.on('connect', response => {
|
|
3575
3596
|
var _this$callbacks$conne;
|
|
3576
|
-
const chainIdHex = ethers.ethers.
|
|
3597
|
+
const chainIdHex = ethers.ethers.utils.hexValue(this.getChainId());
|
|
3577
3598
|
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3578
3599
|
// Ignore the full connect response
|
|
3579
3600
|
// use the chainId defined locally
|
|
@@ -3605,7 +3626,7 @@ class SequenceClient {
|
|
|
3605
3626
|
// instead we handle it locally, so we listen for changes in the store
|
|
3606
3627
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3607
3628
|
var _this$callbacks$chain;
|
|
3608
|
-
const chainIdHex = ethers.ethers.
|
|
3629
|
+
const chainIdHex = ethers.ethers.utils.hexValue(chainId);
|
|
3609
3630
|
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3610
3631
|
});
|
|
3611
3632
|
}
|
|
@@ -2092,7 +2092,7 @@ class MuxMessageProvider {
|
|
|
2092
2092
|
|
|
2093
2093
|
function toExtended(transactions) {
|
|
2094
2094
|
if (transactions.length === 0) {
|
|
2095
|
-
throw new Error(
|
|
2095
|
+
throw new Error('No transaction provided');
|
|
2096
2096
|
}
|
|
2097
2097
|
const [first, ...rest] = transactions;
|
|
2098
2098
|
return _extends({}, first, {
|
|
@@ -2103,6 +2103,25 @@ function fromExtended(transaction) {
|
|
|
2103
2103
|
return [transaction, ...(transaction.auxiliary || [])];
|
|
2104
2104
|
}
|
|
2105
2105
|
|
|
2106
|
+
function validateTransactionRequest(wallet, transaction) {
|
|
2107
|
+
const transactions = commons.transaction.fromTransactionish(wallet, transaction);
|
|
2108
|
+
const unwound = commons.transaction.unwind(wallet, transactions);
|
|
2109
|
+
unwound.forEach(transaction => validateTransaction(wallet, transaction));
|
|
2110
|
+
}
|
|
2111
|
+
function validateTransaction(wallet, transaction) {
|
|
2112
|
+
if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
|
|
2113
|
+
if (transaction.data) {
|
|
2114
|
+
const data = ethers.utils.arrayify(transaction.data);
|
|
2115
|
+
if (data.length >= 4) {
|
|
2116
|
+
throw new Error('self calls are forbidden');
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
if (transaction.delegateCall) {
|
|
2121
|
+
throw new Error('delegate calls are forbidden');
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2106
2125
|
const SIGNER_READY_TIMEOUT = 10000;
|
|
2107
2126
|
class WalletRequestHandler {
|
|
2108
2127
|
constructor(_account, prompter, networks) {
|
|
@@ -2293,6 +2312,7 @@ class WalletRequestHandler {
|
|
|
2293
2312
|
}
|
|
2294
2313
|
return tx;
|
|
2295
2314
|
});
|
|
2315
|
+
validateTransactionRequest(account.address, transactionParams);
|
|
2296
2316
|
let txnHash = '';
|
|
2297
2317
|
if (_this.prompter === null) {
|
|
2298
2318
|
// prompter is null, so we'll send from here
|
|
@@ -2318,6 +2338,7 @@ class WalletRequestHandler {
|
|
|
2318
2338
|
if (sender !== account.address) {
|
|
2319
2339
|
throw new Error('sender address does not match wallet');
|
|
2320
2340
|
}
|
|
2341
|
+
validateTransactionRequest(account.address, transaction);
|
|
2321
2342
|
if (_this.prompter === null) {
|
|
2322
2343
|
// The eth_signTransaction method expects a `string` return value we instead return a `SignedTransactions` object,
|
|
2323
2344
|
// this can only be broadcasted using an RPC provider with support for signed Sequence transactions, like this one.
|
|
@@ -2631,7 +2652,7 @@ class WalletRequestHandler {
|
|
|
2631
2652
|
const chainId = (_this$prompter$getDef2 = (_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.getDefaultChainId()) != null ? _this$prompter$getDef2 : 1;
|
|
2632
2653
|
const connectDetails = {
|
|
2633
2654
|
connected: true,
|
|
2634
|
-
chainId: ethers.
|
|
2655
|
+
chainId: ethers.utils.hexValue(chainId)
|
|
2635
2656
|
};
|
|
2636
2657
|
if (options && options.authorize) {
|
|
2637
2658
|
// Perform ethauth eip712 request and construct the ConnectDetails response
|
|
@@ -2845,7 +2866,7 @@ class SequenceSigner {
|
|
|
2845
2866
|
// it exists to maintain compatibility with ethers.Signer
|
|
2846
2867
|
connect(provider) {
|
|
2847
2868
|
if (!SequenceProvider.is(provider)) {
|
|
2848
|
-
throw new Error(
|
|
2869
|
+
throw new Error('SequenceSigner can only be connected to a SequenceProvider');
|
|
2849
2870
|
}
|
|
2850
2871
|
return new SequenceSigner(this.client, provider);
|
|
2851
2872
|
}
|
|
@@ -2959,35 +2980,35 @@ class SequenceSigner {
|
|
|
2959
2980
|
// We always have a provider, so this is a noop
|
|
2960
2981
|
}
|
|
2961
2982
|
populateTransaction(_transaction) {
|
|
2962
|
-
throw new Error(
|
|
2983
|
+
throw new Error('SequenceSigner does not support populateTransaction');
|
|
2963
2984
|
}
|
|
2964
2985
|
checkTransaction(_transaction) {
|
|
2965
|
-
throw new Error(
|
|
2986
|
+
throw new Error('SequenceSigner does not support checkTransaction');
|
|
2966
2987
|
}
|
|
2967
2988
|
getTransactionCount(_blockTag) {
|
|
2968
2989
|
// We could try returning the sequence nonce here
|
|
2969
2990
|
// but we aren't sure how ethers will use this nonce
|
|
2970
|
-
throw new Error(
|
|
2991
|
+
throw new Error('SequenceSigner does not support getTransactionCount');
|
|
2971
2992
|
}
|
|
2972
2993
|
signTransaction(_transaction) {
|
|
2973
2994
|
// We could implement signTransaction/sendTransaction here
|
|
2974
2995
|
// but first we need a way of serializing these signed transactions
|
|
2975
2996
|
// and it could lead to more trouble, because the dapp could try to send this transaction
|
|
2976
2997
|
// using a different provider, which would fail.
|
|
2977
|
-
throw new Error(
|
|
2998
|
+
throw new Error('SequenceWallet does not support signTransaction, use sendTransaction instead.');
|
|
2978
2999
|
}
|
|
2979
3000
|
static is(cand) {
|
|
2980
|
-
return cand && typeof cand ===
|
|
3001
|
+
return cand && typeof cand === 'object' && cand._isSequenceSigner === true;
|
|
2981
3002
|
}
|
|
2982
3003
|
}
|
|
2983
3004
|
|
|
2984
3005
|
/**
|
|
2985
3006
|
* This is the same provider, but it only allows a single network at a time.
|
|
2986
3007
|
* the network defined by the constructor is the only one that can be used.
|
|
2987
|
-
*
|
|
3008
|
+
*
|
|
2988
3009
|
* Attempting to call any method with a different network will throw an error.
|
|
2989
3010
|
* Attempting to change the network of this provider will throw an error.
|
|
2990
|
-
*
|
|
3011
|
+
*
|
|
2991
3012
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
2992
3013
|
*/
|
|
2993
3014
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
@@ -3025,7 +3046,7 @@ class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
|
3025
3046
|
return this;
|
|
3026
3047
|
}
|
|
3027
3048
|
static is(cand) {
|
|
3028
|
-
return cand && typeof cand ===
|
|
3049
|
+
return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceSigner === true;
|
|
3029
3050
|
}
|
|
3030
3051
|
}
|
|
3031
3052
|
|
|
@@ -3250,7 +3271,7 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3250
3271
|
var _provider$prepareRequ;
|
|
3251
3272
|
// First we check if the method should be handled by the client
|
|
3252
3273
|
if (method === 'eth_chainId') {
|
|
3253
|
-
return this.useChainId();
|
|
3274
|
+
return ethers.utils.hexValue(await this.useChainId());
|
|
3254
3275
|
}
|
|
3255
3276
|
if (method === 'eth_accounts') {
|
|
3256
3277
|
return [this.client.getAddress()];
|
|
@@ -3408,10 +3429,10 @@ function normalizeChainId(chainId) {
|
|
|
3408
3429
|
/**
|
|
3409
3430
|
* This is the same provider, but it only allows a single network at a time.
|
|
3410
3431
|
* the network defined by the constructor is the only one that can be used.
|
|
3411
|
-
*
|
|
3432
|
+
*
|
|
3412
3433
|
* Attempting to call any method with a different network will throw an error.
|
|
3413
3434
|
* Attempting to change the network of this provider will throw an error.
|
|
3414
|
-
*
|
|
3435
|
+
*
|
|
3415
3436
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
3416
3437
|
*/
|
|
3417
3438
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
@@ -3544,7 +3565,7 @@ class DefaultChainIdTracker {
|
|
|
3544
3565
|
/**
|
|
3545
3566
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3546
3567
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3547
|
-
*
|
|
3568
|
+
*
|
|
3548
3569
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3549
3570
|
*/
|
|
3550
3571
|
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
@@ -3569,7 +3590,7 @@ class SequenceClient {
|
|
|
3569
3590
|
});
|
|
3570
3591
|
this.transport.on('connect', response => {
|
|
3571
3592
|
var _this$callbacks$conne;
|
|
3572
|
-
const chainIdHex = ethers.
|
|
3593
|
+
const chainIdHex = ethers.utils.hexValue(this.getChainId());
|
|
3573
3594
|
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3574
3595
|
// Ignore the full connect response
|
|
3575
3596
|
// use the chainId defined locally
|
|
@@ -3601,7 +3622,7 @@ class SequenceClient {
|
|
|
3601
3622
|
// instead we handle it locally, so we listen for changes in the store
|
|
3602
3623
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3603
3624
|
var _this$callbacks$chain;
|
|
3604
|
-
const chainIdHex = ethers.
|
|
3625
|
+
const chainIdHex = ethers.utils.hexValue(chainId);
|
|
3605
3626
|
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3606
3627
|
});
|
|
3607
3628
|
}
|
|
@@ -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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
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": "1.1.
|
|
15
|
-
"@0xsequence/account": "1.1.
|
|
16
|
-
"@0xsequence/auth": "1.1.
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/
|
|
20
|
-
"@0xsequence/
|
|
21
|
-
"@0xsequence/
|
|
22
|
-
"@0xsequence/
|
|
14
|
+
"@0xsequence/abi": "1.1.2",
|
|
15
|
+
"@0xsequence/account": "1.1.2",
|
|
16
|
+
"@0xsequence/auth": "1.1.2",
|
|
17
|
+
"@0xsequence/migration": "1.1.2",
|
|
18
|
+
"@0xsequence/core": "1.1.2",
|
|
19
|
+
"@0xsequence/network": "1.1.2",
|
|
20
|
+
"@0xsequence/relayer": "1.1.2",
|
|
21
|
+
"@0xsequence/utils": "1.1.2",
|
|
22
|
+
"@0xsequence/wallet": "1.1.2"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|