@0xsequence/provider 1.0.2 → 1.0.4
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 +28 -58
- package/dist/0xsequence-provider.cjs.prod.js +28 -58
- package/dist/0xsequence-provider.esm.js +29 -59
- package/dist/declarations/src/utils.d.ts +3 -12
- package/package.json +10 -10
- package/src/transports/base-wallet-transport.ts +20 -24
- package/src/utils/index.ts +2 -2
- package/src/utils.ts +7 -35
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var eventemitter2 = require('eventemitter2');
|
|
6
6
|
var utils = require('@0xsequence/utils');
|
|
7
7
|
var ethers = require('ethers');
|
|
8
|
+
var network = require('@0xsequence/network');
|
|
8
9
|
var core = require('@0xsequence/core');
|
|
9
10
|
var auth = require('@0xsequence/auth');
|
|
10
|
-
var network = require('@0xsequence/network');
|
|
11
11
|
var wallet = require('@0xsequence/wallet');
|
|
12
12
|
|
|
13
13
|
function _extends() {
|
|
@@ -586,48 +586,22 @@ const trimEIP191Prefix = prefixedMessage => {
|
|
|
586
586
|
const prefixRevertedMessage = ethereumSignedMessagePartSlicedArray.slice(prefixCharLenght);
|
|
587
587
|
return prefixRevertedMessage;
|
|
588
588
|
};
|
|
589
|
-
const isValidSignature = async (address, digest, sig, provider
|
|
590
|
-
const
|
|
591
|
-
const reader = new core.commons.reader.OnChainReader(provider, contexts || deployedContexts);
|
|
589
|
+
const isValidSignature = async (address, digest, sig, provider) => {
|
|
590
|
+
const reader = new core.commons.reader.OnChainReader(provider);
|
|
592
591
|
return reader.isValidSignature(address, digest, sig);
|
|
593
592
|
};
|
|
594
593
|
|
|
595
594
|
// Verify message signature
|
|
596
|
-
const isValidMessageSignature = async (address, message, signature, provider
|
|
597
|
-
const deployedContexts = core.allVersions.map(v => v.DeployedWalletContext);
|
|
595
|
+
const isValidMessageSignature = async (address, message, signature, provider) => {
|
|
598
596
|
const prefixed = prefixEIP191Message(message);
|
|
599
597
|
const digest = utils.encodeMessageDigest(prefixed);
|
|
600
|
-
return isValidSignature(address, digest, signature, provider
|
|
598
|
+
return isValidSignature(address, digest, signature, provider);
|
|
601
599
|
};
|
|
602
600
|
|
|
603
601
|
// Verify typedData signature
|
|
604
|
-
const isValidTypedDataSignature = (address, typedData, signature, provider
|
|
605
|
-
|
|
606
|
-
return isValidSignature(address, utils.encodeTypedDataDigest(typedData), signature, provider, contexts || deployedContexts);
|
|
602
|
+
const isValidTypedDataSignature = (address, typedData, signature, provider) => {
|
|
603
|
+
return isValidSignature(address, utils.encodeTypedDataDigest(typedData), signature, provider);
|
|
607
604
|
};
|
|
608
|
-
|
|
609
|
-
// export const recoverWalletConfig = async (
|
|
610
|
-
// address: string,
|
|
611
|
-
// digest: BytesLike,
|
|
612
|
-
// signature: string | commons.signature.UnrecoveredSignature | commons.signature.Signature<commons.config.Config>,
|
|
613
|
-
// chainId: BigNumberish,
|
|
614
|
-
// walletContext?: WalletContext
|
|
615
|
-
// ): Promise<commons.config.Config> => {
|
|
616
|
-
// const subDigest = packMessageData(address, chainId, digest)
|
|
617
|
-
// const config = await recoverConfig(subDigest, signature)
|
|
618
|
-
|
|
619
|
-
// if (walletContext) {
|
|
620
|
-
// const recoveredWalletAddress = addressOf(config, walletContext)
|
|
621
|
-
// if (config.address && config.address !== recoveredWalletAddress) {
|
|
622
|
-
// throw new Error('recovered address does not match the WalletConfig address, check the WalletContext')
|
|
623
|
-
// } else {
|
|
624
|
-
// config.address = recoveredWalletAddress
|
|
625
|
-
// }
|
|
626
|
-
// }
|
|
627
|
-
|
|
628
|
-
// return config
|
|
629
|
-
// }
|
|
630
|
-
|
|
631
605
|
const isBrowserExtension = () => window.location.protocol === 'chrome-extension:' || window.location.protocol === 'moz-extension:';
|
|
632
606
|
const isUnityPlugin = () => !!navigator.userAgent.match(/UnitySequence/i);
|
|
633
607
|
|
|
@@ -786,6 +760,24 @@ class BaseWalletTransport {
|
|
|
786
760
|
// origin host of the dapp.
|
|
787
761
|
await _this.init();
|
|
788
762
|
|
|
763
|
+
// determine chainId from networkId (string or number)
|
|
764
|
+
let chainId = undefined;
|
|
765
|
+
try {
|
|
766
|
+
if (networkId) {
|
|
767
|
+
const network$1 = network.findSupportedNetwork(networkId);
|
|
768
|
+
if (network$1) {
|
|
769
|
+
chainId = network$1.chainId;
|
|
770
|
+
} else {
|
|
771
|
+
throw new Error(`unknown network ${networkId}`);
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
// if not provided, use defaultChainId
|
|
775
|
+
chainId = _this.walletRequestHandler.defaultChainId();
|
|
776
|
+
}
|
|
777
|
+
} catch (err) {
|
|
778
|
+
console.error(err);
|
|
779
|
+
}
|
|
780
|
+
|
|
789
781
|
// Prepare connect options from intent
|
|
790
782
|
if (intent && intent.type === 'connect' && intent.options) {
|
|
791
783
|
const connectOptions = intent.options;
|
|
@@ -839,17 +831,6 @@ class BaseWalletTransport {
|
|
|
839
831
|
// upon cancellation by user, the walletRequestHandler will throw an error
|
|
840
832
|
|
|
841
833
|
if (intent && intent.type === 'connect') {
|
|
842
|
-
let chainId = undefined;
|
|
843
|
-
try {
|
|
844
|
-
if (networkId) {
|
|
845
|
-
const networkIdNumber = ethers.ethers.BigNumber.from(networkId).toNumber();
|
|
846
|
-
chainId = await _this.walletRequestHandler.setDefaultChainId(networkIdNumber);
|
|
847
|
-
} else {
|
|
848
|
-
chainId = _this.walletRequestHandler.defaultChainId();
|
|
849
|
-
}
|
|
850
|
-
} catch (err) {
|
|
851
|
-
console.error(err);
|
|
852
|
-
}
|
|
853
834
|
// Failed to set default network on open
|
|
854
835
|
// Fail silently here so we can continue with connect flow and ask
|
|
855
836
|
// user to connect on a different network if necessary
|
|
@@ -875,18 +856,7 @@ class BaseWalletTransport {
|
|
|
875
856
|
}
|
|
876
857
|
}
|
|
877
858
|
} else {
|
|
878
|
-
//
|
|
879
|
-
let chainId = undefined;
|
|
880
|
-
try {
|
|
881
|
-
if (networkId) {
|
|
882
|
-
const networkIdNumber = ethers.ethers.BigNumber.from(networkId).toNumber();
|
|
883
|
-
chainId = await _this.walletRequestHandler.setDefaultChainId(networkIdNumber);
|
|
884
|
-
} else {
|
|
885
|
-
chainId = _this.walletRequestHandler.defaultChainId();
|
|
886
|
-
}
|
|
887
|
-
} catch (err) {
|
|
888
|
-
console.error(err);
|
|
889
|
-
}
|
|
859
|
+
// Using default network
|
|
890
860
|
|
|
891
861
|
// Failed to set default network on open -- quit + close
|
|
892
862
|
if (!chainId || chainId <= 0) {
|
|
@@ -3261,7 +3231,7 @@ class WalletUtils {
|
|
|
3261
3231
|
async isValidSignature(address, digest, signature, chainId) {
|
|
3262
3232
|
const provider = this.wallet.getProvider(chainId);
|
|
3263
3233
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`);
|
|
3264
|
-
return isValidSignature(address, digest, signature, provider
|
|
3234
|
+
return isValidSignature(address, digest, signature, provider);
|
|
3265
3235
|
}
|
|
3266
3236
|
|
|
3267
3237
|
// Verify message signature
|
|
@@ -3270,7 +3240,7 @@ class WalletUtils {
|
|
|
3270
3240
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`);
|
|
3271
3241
|
const prefixed = prefixEIP191Message(message);
|
|
3272
3242
|
const digest = utils.encodeMessageDigest(prefixed);
|
|
3273
|
-
return isValidSignature(address, digest, signature, provider
|
|
3243
|
+
return isValidSignature(address, digest, signature, provider);
|
|
3274
3244
|
}
|
|
3275
3245
|
|
|
3276
3246
|
// Verify typedData signature
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var eventemitter2 = require('eventemitter2');
|
|
6
6
|
var utils = require('@0xsequence/utils');
|
|
7
7
|
var ethers = require('ethers');
|
|
8
|
+
var network = require('@0xsequence/network');
|
|
8
9
|
var core = require('@0xsequence/core');
|
|
9
10
|
var auth = require('@0xsequence/auth');
|
|
10
|
-
var network = require('@0xsequence/network');
|
|
11
11
|
var wallet = require('@0xsequence/wallet');
|
|
12
12
|
|
|
13
13
|
function _extends() {
|
|
@@ -586,48 +586,22 @@ const trimEIP191Prefix = prefixedMessage => {
|
|
|
586
586
|
const prefixRevertedMessage = ethereumSignedMessagePartSlicedArray.slice(prefixCharLenght);
|
|
587
587
|
return prefixRevertedMessage;
|
|
588
588
|
};
|
|
589
|
-
const isValidSignature = async (address, digest, sig, provider
|
|
590
|
-
const
|
|
591
|
-
const reader = new core.commons.reader.OnChainReader(provider, contexts || deployedContexts);
|
|
589
|
+
const isValidSignature = async (address, digest, sig, provider) => {
|
|
590
|
+
const reader = new core.commons.reader.OnChainReader(provider);
|
|
592
591
|
return reader.isValidSignature(address, digest, sig);
|
|
593
592
|
};
|
|
594
593
|
|
|
595
594
|
// Verify message signature
|
|
596
|
-
const isValidMessageSignature = async (address, message, signature, provider
|
|
597
|
-
const deployedContexts = core.allVersions.map(v => v.DeployedWalletContext);
|
|
595
|
+
const isValidMessageSignature = async (address, message, signature, provider) => {
|
|
598
596
|
const prefixed = prefixEIP191Message(message);
|
|
599
597
|
const digest = utils.encodeMessageDigest(prefixed);
|
|
600
|
-
return isValidSignature(address, digest, signature, provider
|
|
598
|
+
return isValidSignature(address, digest, signature, provider);
|
|
601
599
|
};
|
|
602
600
|
|
|
603
601
|
// Verify typedData signature
|
|
604
|
-
const isValidTypedDataSignature = (address, typedData, signature, provider
|
|
605
|
-
|
|
606
|
-
return isValidSignature(address, utils.encodeTypedDataDigest(typedData), signature, provider, contexts || deployedContexts);
|
|
602
|
+
const isValidTypedDataSignature = (address, typedData, signature, provider) => {
|
|
603
|
+
return isValidSignature(address, utils.encodeTypedDataDigest(typedData), signature, provider);
|
|
607
604
|
};
|
|
608
|
-
|
|
609
|
-
// export const recoverWalletConfig = async (
|
|
610
|
-
// address: string,
|
|
611
|
-
// digest: BytesLike,
|
|
612
|
-
// signature: string | commons.signature.UnrecoveredSignature | commons.signature.Signature<commons.config.Config>,
|
|
613
|
-
// chainId: BigNumberish,
|
|
614
|
-
// walletContext?: WalletContext
|
|
615
|
-
// ): Promise<commons.config.Config> => {
|
|
616
|
-
// const subDigest = packMessageData(address, chainId, digest)
|
|
617
|
-
// const config = await recoverConfig(subDigest, signature)
|
|
618
|
-
|
|
619
|
-
// if (walletContext) {
|
|
620
|
-
// const recoveredWalletAddress = addressOf(config, walletContext)
|
|
621
|
-
// if (config.address && config.address !== recoveredWalletAddress) {
|
|
622
|
-
// throw new Error('recovered address does not match the WalletConfig address, check the WalletContext')
|
|
623
|
-
// } else {
|
|
624
|
-
// config.address = recoveredWalletAddress
|
|
625
|
-
// }
|
|
626
|
-
// }
|
|
627
|
-
|
|
628
|
-
// return config
|
|
629
|
-
// }
|
|
630
|
-
|
|
631
605
|
const isBrowserExtension = () => window.location.protocol === 'chrome-extension:' || window.location.protocol === 'moz-extension:';
|
|
632
606
|
const isUnityPlugin = () => !!navigator.userAgent.match(/UnitySequence/i);
|
|
633
607
|
|
|
@@ -786,6 +760,24 @@ class BaseWalletTransport {
|
|
|
786
760
|
// origin host of the dapp.
|
|
787
761
|
await _this.init();
|
|
788
762
|
|
|
763
|
+
// determine chainId from networkId (string or number)
|
|
764
|
+
let chainId = undefined;
|
|
765
|
+
try {
|
|
766
|
+
if (networkId) {
|
|
767
|
+
const network$1 = network.findSupportedNetwork(networkId);
|
|
768
|
+
if (network$1) {
|
|
769
|
+
chainId = network$1.chainId;
|
|
770
|
+
} else {
|
|
771
|
+
throw new Error(`unknown network ${networkId}`);
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
// if not provided, use defaultChainId
|
|
775
|
+
chainId = _this.walletRequestHandler.defaultChainId();
|
|
776
|
+
}
|
|
777
|
+
} catch (err) {
|
|
778
|
+
console.error(err);
|
|
779
|
+
}
|
|
780
|
+
|
|
789
781
|
// Prepare connect options from intent
|
|
790
782
|
if (intent && intent.type === 'connect' && intent.options) {
|
|
791
783
|
const connectOptions = intent.options;
|
|
@@ -839,17 +831,6 @@ class BaseWalletTransport {
|
|
|
839
831
|
// upon cancellation by user, the walletRequestHandler will throw an error
|
|
840
832
|
|
|
841
833
|
if (intent && intent.type === 'connect') {
|
|
842
|
-
let chainId = undefined;
|
|
843
|
-
try {
|
|
844
|
-
if (networkId) {
|
|
845
|
-
const networkIdNumber = ethers.ethers.BigNumber.from(networkId).toNumber();
|
|
846
|
-
chainId = await _this.walletRequestHandler.setDefaultChainId(networkIdNumber);
|
|
847
|
-
} else {
|
|
848
|
-
chainId = _this.walletRequestHandler.defaultChainId();
|
|
849
|
-
}
|
|
850
|
-
} catch (err) {
|
|
851
|
-
console.error(err);
|
|
852
|
-
}
|
|
853
834
|
// Failed to set default network on open
|
|
854
835
|
// Fail silently here so we can continue with connect flow and ask
|
|
855
836
|
// user to connect on a different network if necessary
|
|
@@ -875,18 +856,7 @@ class BaseWalletTransport {
|
|
|
875
856
|
}
|
|
876
857
|
}
|
|
877
858
|
} else {
|
|
878
|
-
//
|
|
879
|
-
let chainId = undefined;
|
|
880
|
-
try {
|
|
881
|
-
if (networkId) {
|
|
882
|
-
const networkIdNumber = ethers.ethers.BigNumber.from(networkId).toNumber();
|
|
883
|
-
chainId = await _this.walletRequestHandler.setDefaultChainId(networkIdNumber);
|
|
884
|
-
} else {
|
|
885
|
-
chainId = _this.walletRequestHandler.defaultChainId();
|
|
886
|
-
}
|
|
887
|
-
} catch (err) {
|
|
888
|
-
console.error(err);
|
|
889
|
-
}
|
|
859
|
+
// Using default network
|
|
890
860
|
|
|
891
861
|
// Failed to set default network on open -- quit + close
|
|
892
862
|
if (!chainId || chainId <= 0) {
|
|
@@ -3261,7 +3231,7 @@ class WalletUtils {
|
|
|
3261
3231
|
async isValidSignature(address, digest, signature, chainId) {
|
|
3262
3232
|
const provider = this.wallet.getProvider(chainId);
|
|
3263
3233
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`);
|
|
3264
|
-
return isValidSignature(address, digest, signature, provider
|
|
3234
|
+
return isValidSignature(address, digest, signature, provider);
|
|
3265
3235
|
}
|
|
3266
3236
|
|
|
3267
3237
|
// Verify message signature
|
|
@@ -3270,7 +3240,7 @@ class WalletUtils {
|
|
|
3270
3240
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`);
|
|
3271
3241
|
const prefixed = prefixEIP191Message(message);
|
|
3272
3242
|
const digest = utils.encodeMessageDigest(prefixed);
|
|
3273
|
-
return isValidSignature(address, digest, signature, provider
|
|
3243
|
+
return isValidSignature(address, digest, signature, provider);
|
|
3274
3244
|
}
|
|
3275
3245
|
|
|
3276
3246
|
// Verify typedData signature
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventEmitter2 } from 'eventemitter2';
|
|
2
2
|
import { logger, encodeMessageDigest, encodeTypedDataDigest, sanitizeNumberString, sanitizeHost, sanitizeAlphanumeric, base64EncodeObject, base64DecodeObject, shallowCopy, resolveProperties, getDefaultConnectionInfo } from '@0xsequence/utils';
|
|
3
3
|
import { ethers, BigNumber, providers } from 'ethers';
|
|
4
|
-
import {
|
|
4
|
+
import { findSupportedNetwork, getChainId, JsonRpcSender, maybeChainId, allowProviderMiddleware, networkProviderMiddleware, findNetworkConfig, CachedProvider, JsonRpcRouter, loggingProviderMiddleware, exceptionProviderMiddleware, sortNetworks, EagerProvider, SigningProvider, updateNetworkConfig, ensureValidNetworks } from '@0xsequence/network';
|
|
5
|
+
import { commons, universal } from '@0xsequence/core';
|
|
5
6
|
import { signAuthorization } from '@0xsequence/auth';
|
|
6
|
-
import { getChainId, JsonRpcSender, maybeChainId, allowProviderMiddleware, networkProviderMiddleware, findNetworkConfig, CachedProvider, JsonRpcRouter, loggingProviderMiddleware, exceptionProviderMiddleware, findSupportedNetwork, sortNetworks, EagerProvider, SigningProvider, updateNetworkConfig, ensureValidNetworks } from '@0xsequence/network';
|
|
7
7
|
import { Signer, resolveArrayProperties } from '@0xsequence/wallet';
|
|
8
8
|
|
|
9
9
|
function _extends() {
|
|
@@ -582,48 +582,22 @@ const trimEIP191Prefix = prefixedMessage => {
|
|
|
582
582
|
const prefixRevertedMessage = ethereumSignedMessagePartSlicedArray.slice(prefixCharLenght);
|
|
583
583
|
return prefixRevertedMessage;
|
|
584
584
|
};
|
|
585
|
-
const isValidSignature = async (address, digest, sig, provider
|
|
586
|
-
const
|
|
587
|
-
const reader = new commons.reader.OnChainReader(provider, contexts || deployedContexts);
|
|
585
|
+
const isValidSignature = async (address, digest, sig, provider) => {
|
|
586
|
+
const reader = new commons.reader.OnChainReader(provider);
|
|
588
587
|
return reader.isValidSignature(address, digest, sig);
|
|
589
588
|
};
|
|
590
589
|
|
|
591
590
|
// Verify message signature
|
|
592
|
-
const isValidMessageSignature = async (address, message, signature, provider
|
|
593
|
-
const deployedContexts = allVersions.map(v => v.DeployedWalletContext);
|
|
591
|
+
const isValidMessageSignature = async (address, message, signature, provider) => {
|
|
594
592
|
const prefixed = prefixEIP191Message(message);
|
|
595
593
|
const digest = encodeMessageDigest(prefixed);
|
|
596
|
-
return isValidSignature(address, digest, signature, provider
|
|
594
|
+
return isValidSignature(address, digest, signature, provider);
|
|
597
595
|
};
|
|
598
596
|
|
|
599
597
|
// Verify typedData signature
|
|
600
|
-
const isValidTypedDataSignature = (address, typedData, signature, provider
|
|
601
|
-
|
|
602
|
-
return isValidSignature(address, encodeTypedDataDigest(typedData), signature, provider, contexts || deployedContexts);
|
|
598
|
+
const isValidTypedDataSignature = (address, typedData, signature, provider) => {
|
|
599
|
+
return isValidSignature(address, encodeTypedDataDigest(typedData), signature, provider);
|
|
603
600
|
};
|
|
604
|
-
|
|
605
|
-
// export const recoverWalletConfig = async (
|
|
606
|
-
// address: string,
|
|
607
|
-
// digest: BytesLike,
|
|
608
|
-
// signature: string | commons.signature.UnrecoveredSignature | commons.signature.Signature<commons.config.Config>,
|
|
609
|
-
// chainId: BigNumberish,
|
|
610
|
-
// walletContext?: WalletContext
|
|
611
|
-
// ): Promise<commons.config.Config> => {
|
|
612
|
-
// const subDigest = packMessageData(address, chainId, digest)
|
|
613
|
-
// const config = await recoverConfig(subDigest, signature)
|
|
614
|
-
|
|
615
|
-
// if (walletContext) {
|
|
616
|
-
// const recoveredWalletAddress = addressOf(config, walletContext)
|
|
617
|
-
// if (config.address && config.address !== recoveredWalletAddress) {
|
|
618
|
-
// throw new Error('recovered address does not match the WalletConfig address, check the WalletContext')
|
|
619
|
-
// } else {
|
|
620
|
-
// config.address = recoveredWalletAddress
|
|
621
|
-
// }
|
|
622
|
-
// }
|
|
623
|
-
|
|
624
|
-
// return config
|
|
625
|
-
// }
|
|
626
|
-
|
|
627
601
|
const isBrowserExtension = () => window.location.protocol === 'chrome-extension:' || window.location.protocol === 'moz-extension:';
|
|
628
602
|
const isUnityPlugin = () => !!navigator.userAgent.match(/UnitySequence/i);
|
|
629
603
|
|
|
@@ -782,6 +756,24 @@ class BaseWalletTransport {
|
|
|
782
756
|
// origin host of the dapp.
|
|
783
757
|
await _this.init();
|
|
784
758
|
|
|
759
|
+
// determine chainId from networkId (string or number)
|
|
760
|
+
let chainId = undefined;
|
|
761
|
+
try {
|
|
762
|
+
if (networkId) {
|
|
763
|
+
const network = findSupportedNetwork(networkId);
|
|
764
|
+
if (network) {
|
|
765
|
+
chainId = network.chainId;
|
|
766
|
+
} else {
|
|
767
|
+
throw new Error(`unknown network ${networkId}`);
|
|
768
|
+
}
|
|
769
|
+
} else {
|
|
770
|
+
// if not provided, use defaultChainId
|
|
771
|
+
chainId = _this.walletRequestHandler.defaultChainId();
|
|
772
|
+
}
|
|
773
|
+
} catch (err) {
|
|
774
|
+
console.error(err);
|
|
775
|
+
}
|
|
776
|
+
|
|
785
777
|
// Prepare connect options from intent
|
|
786
778
|
if (intent && intent.type === 'connect' && intent.options) {
|
|
787
779
|
const connectOptions = intent.options;
|
|
@@ -835,17 +827,6 @@ class BaseWalletTransport {
|
|
|
835
827
|
// upon cancellation by user, the walletRequestHandler will throw an error
|
|
836
828
|
|
|
837
829
|
if (intent && intent.type === 'connect') {
|
|
838
|
-
let chainId = undefined;
|
|
839
|
-
try {
|
|
840
|
-
if (networkId) {
|
|
841
|
-
const networkIdNumber = ethers.BigNumber.from(networkId).toNumber();
|
|
842
|
-
chainId = await _this.walletRequestHandler.setDefaultChainId(networkIdNumber);
|
|
843
|
-
} else {
|
|
844
|
-
chainId = _this.walletRequestHandler.defaultChainId();
|
|
845
|
-
}
|
|
846
|
-
} catch (err) {
|
|
847
|
-
console.error(err);
|
|
848
|
-
}
|
|
849
830
|
// Failed to set default network on open
|
|
850
831
|
// Fail silently here so we can continue with connect flow and ask
|
|
851
832
|
// user to connect on a different network if necessary
|
|
@@ -871,18 +852,7 @@ class BaseWalletTransport {
|
|
|
871
852
|
}
|
|
872
853
|
}
|
|
873
854
|
} else {
|
|
874
|
-
//
|
|
875
|
-
let chainId = undefined;
|
|
876
|
-
try {
|
|
877
|
-
if (networkId) {
|
|
878
|
-
const networkIdNumber = ethers.BigNumber.from(networkId).toNumber();
|
|
879
|
-
chainId = await _this.walletRequestHandler.setDefaultChainId(networkIdNumber);
|
|
880
|
-
} else {
|
|
881
|
-
chainId = _this.walletRequestHandler.defaultChainId();
|
|
882
|
-
}
|
|
883
|
-
} catch (err) {
|
|
884
|
-
console.error(err);
|
|
885
|
-
}
|
|
855
|
+
// Using default network
|
|
886
856
|
|
|
887
857
|
// Failed to set default network on open -- quit + close
|
|
888
858
|
if (!chainId || chainId <= 0) {
|
|
@@ -3257,7 +3227,7 @@ class WalletUtils {
|
|
|
3257
3227
|
async isValidSignature(address, digest, signature, chainId) {
|
|
3258
3228
|
const provider = this.wallet.getProvider(chainId);
|
|
3259
3229
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`);
|
|
3260
|
-
return isValidSignature(address, digest, signature, provider
|
|
3230
|
+
return isValidSignature(address, digest, signature, provider);
|
|
3261
3231
|
}
|
|
3262
3232
|
|
|
3263
3233
|
// Verify message signature
|
|
@@ -3266,7 +3236,7 @@ class WalletUtils {
|
|
|
3266
3236
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`);
|
|
3267
3237
|
const prefixed = prefixEIP191Message(message);
|
|
3268
3238
|
const digest = encodeMessageDigest(prefixed);
|
|
3269
|
-
return isValidSignature(address, digest, signature, provider
|
|
3239
|
+
return isValidSignature(address, digest, signature, provider);
|
|
3270
3240
|
}
|
|
3271
3241
|
|
|
3272
3242
|
// Verify typedData signature
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
|
|
2
1
|
import { ethers, BytesLike } from 'ethers';
|
|
3
|
-
import { Web3Provider } from './provider';
|
|
4
2
|
import { AccountStatus } from '@0xsequence/account';
|
|
5
|
-
import { commons } from '@0xsequence/core';
|
|
6
3
|
import { TypedData } from '@0xsequence/utils';
|
|
7
4
|
export declare const messageToBytes: (message: BytesLike) => Uint8Array;
|
|
8
5
|
export declare const prefixEIP191Message: (message: BytesLike) => Uint8Array;
|
|
9
6
|
export declare const trimEIP191Prefix: (prefixedMessage: Uint8Array) => Uint8Array;
|
|
10
|
-
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export declare const isValidMessageSignature: (address: string, message: string | Uint8Array, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, contexts?: {
|
|
14
|
-
[key: number]: commons.context.WalletContext;
|
|
15
|
-
} | undefined) => Promise<boolean>;
|
|
16
|
-
export declare const isValidTypedDataSignature: (address: string, typedData: TypedData, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, contexts?: {
|
|
17
|
-
[key: number]: commons.context.WalletContext;
|
|
18
|
-
} | undefined) => Promise<boolean>;
|
|
7
|
+
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: ethers.providers.Provider) => Promise<boolean>;
|
|
8
|
+
export declare const isValidMessageSignature: (address: string, message: string | Uint8Array, signature: string, provider: ethers.providers.Provider) => Promise<boolean>;
|
|
9
|
+
export declare const isValidTypedDataSignature: (address: string, typedData: TypedData, signature: string, provider: ethers.providers.Provider) => Promise<boolean>;
|
|
19
10
|
export declare const isBrowserExtension: () => boolean;
|
|
20
11
|
export declare const isUnityPlugin: () => boolean;
|
|
21
12
|
export declare const isWalletUpToDate: (status: AccountStatus) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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.0.
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/network": "1.0.
|
|
20
|
-
"@0xsequence/relayer": "1.0.
|
|
21
|
-
"@0xsequence/
|
|
22
|
-
"@0xsequence/
|
|
14
|
+
"@0xsequence/abi": "1.0.4",
|
|
15
|
+
"@0xsequence/auth": "1.0.4",
|
|
16
|
+
"@0xsequence/migration": "1.0.4",
|
|
17
|
+
"@0xsequence/account": "1.0.4",
|
|
18
|
+
"@0xsequence/core": "1.0.4",
|
|
19
|
+
"@0xsequence/network": "1.0.4",
|
|
20
|
+
"@0xsequence/relayer": "1.0.4",
|
|
21
|
+
"@0xsequence/utils": "1.0.4",
|
|
22
|
+
"@0xsequence/wallet": "1.0.4"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
|
|
15
15
|
import { WalletRequestHandler } from './wallet-request-handler'
|
|
16
16
|
|
|
17
|
-
import { NetworkConfig, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'
|
|
17
|
+
import { NetworkConfig, JsonRpcRequest, JsonRpcResponseCallback, findSupportedNetwork } from '@0xsequence/network'
|
|
18
18
|
import { logger, sanitizeAlphanumeric, sanitizeHost, sanitizeNumberString } from '@0xsequence/utils'
|
|
19
19
|
import { AuthorizationOptions } from '@0xsequence/auth'
|
|
20
20
|
|
|
@@ -327,6 +327,24 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
327
327
|
// origin host of the dapp.
|
|
328
328
|
await this.init()
|
|
329
329
|
|
|
330
|
+
// determine chainId from networkId (string or number)
|
|
331
|
+
let chainId: number | undefined = undefined
|
|
332
|
+
try {
|
|
333
|
+
if (networkId) {
|
|
334
|
+
const network = findSupportedNetwork(networkId)
|
|
335
|
+
if (network) {
|
|
336
|
+
chainId = network.chainId
|
|
337
|
+
} else {
|
|
338
|
+
throw new Error(`unknown network ${networkId}`)
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
// if not provided, use defaultChainId
|
|
342
|
+
chainId = this.walletRequestHandler.defaultChainId()
|
|
343
|
+
}
|
|
344
|
+
} catch (err) {
|
|
345
|
+
console.error(err)
|
|
346
|
+
}
|
|
347
|
+
|
|
330
348
|
// Prepare connect options from intent
|
|
331
349
|
if (intent && intent.type === 'connect' && intent.options) {
|
|
332
350
|
const connectOptions = intent.options
|
|
@@ -382,17 +400,6 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
382
400
|
// upon cancellation by user, the walletRequestHandler will throw an error
|
|
383
401
|
|
|
384
402
|
if (intent && intent.type === 'connect') {
|
|
385
|
-
let chainId: number | undefined = undefined
|
|
386
|
-
try {
|
|
387
|
-
if (networkId) {
|
|
388
|
-
const networkIdNumber = ethers.BigNumber.from(networkId).toNumber()
|
|
389
|
-
chainId = await this.walletRequestHandler.setDefaultChainId(networkIdNumber)
|
|
390
|
-
} else {
|
|
391
|
-
chainId = this.walletRequestHandler.defaultChainId()
|
|
392
|
-
}
|
|
393
|
-
} catch (err) {
|
|
394
|
-
console.error(err)
|
|
395
|
-
}
|
|
396
403
|
// Failed to set default network on open
|
|
397
404
|
// Fail silently here so we can continue with connect flow and ask
|
|
398
405
|
// user to connect on a different network if necessary
|
|
@@ -419,18 +426,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
419
426
|
}
|
|
420
427
|
}
|
|
421
428
|
} else {
|
|
422
|
-
//
|
|
423
|
-
let chainId: number | undefined = undefined
|
|
424
|
-
try {
|
|
425
|
-
if (networkId) {
|
|
426
|
-
const networkIdNumber = ethers.BigNumber.from(networkId).toNumber()
|
|
427
|
-
chainId = await this.walletRequestHandler.setDefaultChainId(networkIdNumber)
|
|
428
|
-
} else {
|
|
429
|
-
chainId = this.walletRequestHandler.defaultChainId()
|
|
430
|
-
}
|
|
431
|
-
} catch (err) {
|
|
432
|
-
console.error(err)
|
|
433
|
-
}
|
|
429
|
+
// Using default network
|
|
434
430
|
|
|
435
431
|
// Failed to set default network on open -- quit + close
|
|
436
432
|
if (!chainId || chainId <= 0) {
|
package/src/utils/index.ts
CHANGED
|
@@ -59,7 +59,7 @@ export class WalletUtils {
|
|
|
59
59
|
): Promise<boolean> {
|
|
60
60
|
const provider = this.wallet.getProvider(chainId)
|
|
61
61
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`)
|
|
62
|
-
return isValidSignature(address, digest, signature, provider
|
|
62
|
+
return isValidSignature(address, digest, signature, provider)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// Verify message signature
|
|
@@ -73,7 +73,7 @@ export class WalletUtils {
|
|
|
73
73
|
if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`)
|
|
74
74
|
const prefixed = prefixEIP191Message(message)
|
|
75
75
|
const digest = encodeMessageDigest(prefixed)
|
|
76
|
-
return isValidSignature(address, digest, signature, provider
|
|
76
|
+
return isValidSignature(address, digest, signature, provider)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// Verify typedData signature
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ethers, BytesLike } from 'ethers'
|
|
2
|
-
import { Web3Provider } from './provider'
|
|
3
2
|
import { messageIsExemptFromEIP191Prefix } from './eip191exceptions'
|
|
4
3
|
import { AccountStatus } from '@0xsequence/account'
|
|
5
|
-
import { commons
|
|
4
|
+
import { commons } from '@0xsequence/core'
|
|
6
5
|
import { encodeMessageDigest, TypedData, encodeTypedDataDigest } from '@0xsequence/utils'
|
|
7
6
|
|
|
8
7
|
const eip191prefix = ethers.utils.toUtf8Bytes('\x19Ethereum Signed Message:\n')
|
|
@@ -68,11 +67,9 @@ export const isValidSignature = async (
|
|
|
68
67
|
address: string,
|
|
69
68
|
digest: Uint8Array,
|
|
70
69
|
sig: string,
|
|
71
|
-
provider:
|
|
72
|
-
contexts?: { [key: number]: commons.context.WalletContext }
|
|
70
|
+
provider: ethers.providers.Provider
|
|
73
71
|
): Promise<boolean> => {
|
|
74
|
-
const
|
|
75
|
-
const reader = new commons.reader.OnChainReader(provider, contexts || deployedContexts)
|
|
72
|
+
const reader = new commons.reader.OnChainReader(provider)
|
|
76
73
|
return reader.isValidSignature(address, digest, sig)
|
|
77
74
|
}
|
|
78
75
|
|
|
@@ -81,13 +78,11 @@ export const isValidMessageSignature = async (
|
|
|
81
78
|
address: string,
|
|
82
79
|
message: string | Uint8Array,
|
|
83
80
|
signature: string,
|
|
84
|
-
provider:
|
|
85
|
-
contexts?: { [key: number]: commons.context.WalletContext }
|
|
81
|
+
provider: ethers.providers.Provider
|
|
86
82
|
): Promise<boolean> => {
|
|
87
|
-
const deployedContexts = allVersions.map(v => v.DeployedWalletContext)
|
|
88
83
|
const prefixed = prefixEIP191Message(message)
|
|
89
84
|
const digest = encodeMessageDigest(prefixed)
|
|
90
|
-
return isValidSignature(address, digest, signature, provider
|
|
85
|
+
return isValidSignature(address, digest, signature, provider)
|
|
91
86
|
}
|
|
92
87
|
|
|
93
88
|
// Verify typedData signature
|
|
@@ -95,34 +90,11 @@ export const isValidTypedDataSignature = (
|
|
|
95
90
|
address: string,
|
|
96
91
|
typedData: TypedData,
|
|
97
92
|
signature: string,
|
|
98
|
-
provider:
|
|
99
|
-
contexts?: { [key: number]: commons.context.WalletContext }
|
|
93
|
+
provider: ethers.providers.Provider
|
|
100
94
|
): Promise<boolean> => {
|
|
101
|
-
|
|
102
|
-
return isValidSignature(address, encodeTypedDataDigest(typedData), signature, provider, contexts || deployedContexts)
|
|
95
|
+
return isValidSignature(address, encodeTypedDataDigest(typedData), signature, provider)
|
|
103
96
|
}
|
|
104
97
|
|
|
105
|
-
// export const recoverWalletConfig = async (
|
|
106
|
-
// address: string,
|
|
107
|
-
// digest: BytesLike,
|
|
108
|
-
// signature: string | commons.signature.UnrecoveredSignature | commons.signature.Signature<commons.config.Config>,
|
|
109
|
-
// chainId: BigNumberish,
|
|
110
|
-
// walletContext?: WalletContext
|
|
111
|
-
// ): Promise<commons.config.Config> => {
|
|
112
|
-
// const subDigest = packMessageData(address, chainId, digest)
|
|
113
|
-
// const config = await recoverConfig(subDigest, signature)
|
|
114
|
-
|
|
115
|
-
// if (walletContext) {
|
|
116
|
-
// const recoveredWalletAddress = addressOf(config, walletContext)
|
|
117
|
-
// if (config.address && config.address !== recoveredWalletAddress) {
|
|
118
|
-
// throw new Error('recovered address does not match the WalletConfig address, check the WalletContext')
|
|
119
|
-
// } else {
|
|
120
|
-
// config.address = recoveredWalletAddress
|
|
121
|
-
// }
|
|
122
|
-
// }
|
|
123
|
-
|
|
124
|
-
// return config
|
|
125
|
-
// }
|
|
126
98
|
|
|
127
99
|
export const isBrowserExtension = (): boolean =>
|
|
128
100
|
window.location.protocol === 'chrome-extension:' || window.location.protocol === 'moz-extension:'
|