@0xsequence/provider 0.35.10 → 0.35.11
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 +2046 -2025
- package/dist/0xsequence-provider.cjs.prod.js +2046 -2025
- package/dist/0xsequence-provider.esm.js +2047 -2028
- package/dist/declarations/src/utils.d.ts +5 -2
- package/package.json +8 -8
- package/src/commands/index.ts +9 -2
- package/src/provider.ts +1 -0
- package/src/utils.ts +38 -6
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { BigNumberish, BytesLike } from 'ethers';
|
|
1
|
+
import { ethers, BigNumberish, BytesLike } from 'ethers';
|
|
2
2
|
import { WalletContext } from '@0xsequence/network';
|
|
3
3
|
import { WalletConfig, DecodedSignature } from '@0xsequence/config';
|
|
4
|
+
import { TypedData } from '@0xsequence/utils';
|
|
4
5
|
import { Web3Provider } from './provider';
|
|
5
6
|
import { Signer } from '@0xsequence/wallet';
|
|
6
|
-
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: Web3Provider, chainId?: number | undefined, walletContext?: WalletContext | undefined) => Promise<boolean | undefined>;
|
|
7
|
+
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number | undefined, walletContext?: WalletContext | undefined) => Promise<boolean | undefined>;
|
|
8
|
+
export declare const isValidMessageSignature: (address: string, message: string | Uint8Array, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number | undefined, walletContext?: WalletContext | undefined) => Promise<boolean | undefined>;
|
|
9
|
+
export declare const isValidTypedDataSignature: (address: string, typedData: TypedData, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number | undefined, walletContext?: WalletContext | undefined) => Promise<boolean | undefined>;
|
|
7
10
|
export declare const recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext | undefined) => Promise<WalletConfig>;
|
|
8
11
|
export declare const isBrowserExtension: () => boolean;
|
|
9
12
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.11",
|
|
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",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"typecheck": "tsc --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@0xsequence/abi": "^0.35.
|
|
17
|
-
"@0xsequence/auth": "^0.35.
|
|
18
|
-
"@0xsequence/config": "^0.35.
|
|
19
|
-
"@0xsequence/network": "^0.35.
|
|
20
|
-
"@0xsequence/transactions": "^0.35.
|
|
21
|
-
"@0xsequence/utils": "^0.35.
|
|
22
|
-
"@0xsequence/wallet": "^0.35.
|
|
16
|
+
"@0xsequence/abi": "^0.35.11",
|
|
17
|
+
"@0xsequence/auth": "^0.35.11",
|
|
18
|
+
"@0xsequence/config": "^0.35.11",
|
|
19
|
+
"@0xsequence/network": "^0.35.11",
|
|
20
|
+
"@0xsequence/transactions": "^0.35.11",
|
|
21
|
+
"@0xsequence/utils": "^0.35.11",
|
|
22
|
+
"@0xsequence/wallet": "^0.35.11",
|
|
23
23
|
"@ethersproject/abstract-signer": "^5.5.0",
|
|
24
24
|
"@ethersproject/hash": "^5.5.0",
|
|
25
25
|
"@ethersproject/providers": "^5.5.1",
|
package/src/commands/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { BigNumberish, BytesLike } from 'ethers'
|
|
1
|
+
import { ethers, BigNumberish, BytesLike } from 'ethers'
|
|
2
2
|
import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer'
|
|
3
3
|
import { WalletContext, ChainIdLike } from '@0xsequence/network'
|
|
4
4
|
import { encodeMessageDigest, TypedData, encodeTypedDataDigest } from '@0xsequence/utils'
|
|
5
5
|
import { DecodedSignature, WalletConfig } from '@0xsequence/config'
|
|
6
6
|
import { Wallet } from '../wallet'
|
|
7
7
|
import { isValidSignature, recoverWalletConfig } from '../utils'
|
|
8
|
+
import { isValidEIP712Signature, isValidEthSignSignature } from '@0xsequence/wallet'
|
|
8
9
|
|
|
9
10
|
export class WalletCommands {
|
|
10
11
|
private wallet: Wallet
|
|
@@ -66,13 +67,19 @@ export class WalletCommands {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
// Verify message signature
|
|
69
|
-
isValidMessageSignature(
|
|
70
|
+
async isValidMessageSignature(
|
|
70
71
|
address: string,
|
|
71
72
|
message: string | Uint8Array,
|
|
72
73
|
signature: string,
|
|
73
74
|
chainId: number,
|
|
74
75
|
walletContext?: WalletContext
|
|
75
76
|
): Promise<boolean | undefined> {
|
|
77
|
+
const msgDigest = ethers.utils.arrayify(ethers.utils.hashMessage(message))
|
|
78
|
+
if (
|
|
79
|
+
isValidEIP712Signature(address, msgDigest, signature) ||
|
|
80
|
+
isValidEthSignSignature(address, msgDigest, signature)
|
|
81
|
+
) return true
|
|
82
|
+
|
|
76
83
|
return this.isValidSignature(address, encodeMessageDigest(message), signature, chainId, walletContext)
|
|
77
84
|
}
|
|
78
85
|
|
package/src/provider.ts
CHANGED
|
@@ -72,6 +72,7 @@ export class Web3Provider extends EthersWeb3Provider implements JsonRpcHandler {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async getChainId(): Promise<number> {
|
|
75
|
+
// TODO: is it safe to memoize this?
|
|
75
76
|
const result = await this.send('eth_chainId', [])
|
|
76
77
|
const chainId = ethers.BigNumber.from(result).toNumber()
|
|
77
78
|
|
package/src/utils.ts
CHANGED
|
@@ -1,23 +1,55 @@
|
|
|
1
|
-
import { BigNumberish, BytesLike } from 'ethers'
|
|
1
|
+
import { ethers, BigNumberish, BytesLike } from 'ethers'
|
|
2
2
|
import { WalletContext } from '@0xsequence/network'
|
|
3
3
|
import { WalletConfig, addressOf, DecodedSignature, isConfigEqual } from '@0xsequence/config'
|
|
4
|
-
import { packMessageData } from '@0xsequence/utils'
|
|
4
|
+
import { packMessageData, encodeMessageDigest, TypedData, encodeTypedDataDigest } from '@0xsequence/utils'
|
|
5
5
|
import { Web3Provider } from './provider'
|
|
6
|
-
import { isValidSignature as _isValidSignature, recoverConfig, Signer } from '@0xsequence/wallet'
|
|
6
|
+
import { isValidSignature as _isValidSignature, recoverConfig, Signer, isValidEIP712Signature, isValidEthSignSignature } from '@0xsequence/wallet'
|
|
7
7
|
|
|
8
8
|
export const isValidSignature = async (
|
|
9
9
|
address: string,
|
|
10
10
|
digest: Uint8Array,
|
|
11
11
|
sig: string,
|
|
12
|
-
provider: Web3Provider,
|
|
12
|
+
provider: Web3Provider | ethers.providers.Web3Provider,
|
|
13
13
|
chainId?: number,
|
|
14
14
|
walletContext?: WalletContext
|
|
15
15
|
): Promise<boolean | undefined> => {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (!chainId) {
|
|
17
|
+
chainId = (await provider.getNetwork())?.chainId
|
|
18
|
+
}
|
|
19
|
+
if (!walletContext && Web3Provider.isSequenceProvider(provider)) {
|
|
20
|
+
walletContext = await provider.getSigner().getWalletContext()
|
|
21
|
+
}
|
|
18
22
|
return _isValidSignature(address, digest, sig, provider, walletContext, chainId)
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
export const isValidMessageSignature = async (
|
|
26
|
+
address: string,
|
|
27
|
+
message: string | Uint8Array,
|
|
28
|
+
signature: string,
|
|
29
|
+
provider: Web3Provider | ethers.providers.Web3Provider,
|
|
30
|
+
chainId?: number,
|
|
31
|
+
walletContext?: WalletContext
|
|
32
|
+
): Promise<boolean | undefined> => {
|
|
33
|
+
const msgDigest = ethers.utils.arrayify(ethers.utils.hashMessage(message))
|
|
34
|
+
if (
|
|
35
|
+
isValidEIP712Signature(address, msgDigest, signature) ||
|
|
36
|
+
isValidEthSignSignature(address, msgDigest, signature)
|
|
37
|
+
) return true
|
|
38
|
+
|
|
39
|
+
return isValidSignature(address, encodeMessageDigest(message), signature, provider, chainId, walletContext)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const isValidTypedDataSignature = (
|
|
43
|
+
address: string,
|
|
44
|
+
typedData: TypedData,
|
|
45
|
+
signature: string,
|
|
46
|
+
provider: Web3Provider | ethers.providers.Web3Provider,
|
|
47
|
+
chainId?: number,
|
|
48
|
+
walletContext?: WalletContext
|
|
49
|
+
): Promise<boolean | undefined> => {
|
|
50
|
+
return isValidSignature(address, encodeTypedDataDigest(typedData), signature, provider, chainId, walletContext)
|
|
51
|
+
}
|
|
52
|
+
|
|
21
53
|
export const recoverWalletConfig = async (
|
|
22
54
|
address: string,
|
|
23
55
|
digest: BytesLike,
|