@0xsequence/provider 0.35.8 → 0.35.12
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 -2023
- package/dist/0xsequence-provider.cjs.prod.js +2046 -2023
- package/dist/0xsequence-provider.esm.js +2047 -2026
- package/dist/declarations/src/{commands → utils}/index.d.ts +1 -1
- package/dist/declarations/src/utils.d.ts +5 -2
- package/dist/declarations/src/wallet.d.ts +3 -3
- package/package.json +8 -8
- package/src/provider.ts +1 -0
- package/src/transports/window-transport/window-message-provider.ts +3 -1
- package/src/{commands → utils}/index.ts +10 -3
- package/src/utils.ts +38 -6
- package/src/wallet.ts +4 -4
|
@@ -4,7 +4,7 @@ import { WalletContext, ChainIdLike } from '@0xsequence/network';
|
|
|
4
4
|
import { TypedData } from '@0xsequence/utils';
|
|
5
5
|
import { DecodedSignature, WalletConfig } from '@0xsequence/config';
|
|
6
6
|
import { Wallet } from '../wallet';
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class WalletUtils {
|
|
8
8
|
private wallet;
|
|
9
9
|
constructor(walletProvider: Wallet);
|
|
10
10
|
signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
|
|
@@ -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
|
/**
|
|
@@ -3,7 +3,7 @@ import { WalletConfig, WalletState } from '@0xsequence/config';
|
|
|
3
3
|
import { Web3Provider, Web3Signer } from './provider';
|
|
4
4
|
import { ProxyMessageChannelPort } from './transports';
|
|
5
5
|
import { WalletSession, ProviderEventTypes, ConnectOptions, OpenWalletIntent, ConnectDetails } from './types';
|
|
6
|
-
import {
|
|
6
|
+
import { WalletUtils } from './utils/index';
|
|
7
7
|
import { Runtime } from 'webextension-polyfill-ts';
|
|
8
8
|
export interface WalletProvider {
|
|
9
9
|
connect(options?: ConnectOptions): Promise<ConnectDetails>;
|
|
@@ -26,10 +26,10 @@ export interface WalletProvider {
|
|
|
26
26
|
getProviderConfig(): ProviderConfig;
|
|
27
27
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
28
28
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
29
|
-
|
|
29
|
+
utils: WalletUtils;
|
|
30
30
|
}
|
|
31
31
|
export declare class Wallet implements WalletProvider {
|
|
32
|
-
|
|
32
|
+
utils: WalletUtils;
|
|
33
33
|
private config;
|
|
34
34
|
private session?;
|
|
35
35
|
private connectedSites;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.12",
|
|
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.12",
|
|
17
|
+
"@0xsequence/auth": "^0.35.12",
|
|
18
|
+
"@0xsequence/config": "^0.35.12",
|
|
19
|
+
"@0xsequence/network": "^0.35.12",
|
|
20
|
+
"@0xsequence/transactions": "^0.35.12",
|
|
21
|
+
"@0xsequence/utils": "^0.35.12",
|
|
22
|
+
"@0xsequence/wallet": "^0.35.12",
|
|
23
23
|
"@ethersproject/abstract-signer": "^5.5.0",
|
|
24
24
|
"@ethersproject/hash": "^5.5.0",
|
|
25
25
|
"@ethersproject/providers": "^5.5.1",
|
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
|
|
|
@@ -17,7 +17,9 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
17
17
|
|
|
18
18
|
register = () => {
|
|
19
19
|
if (registeredWindowMessageProvider) {
|
|
20
|
-
|
|
20
|
+
// overriding the registered message provider
|
|
21
|
+
registeredWindowMessageProvider.unregister()
|
|
22
|
+
registeredWindowMessageProvider = this
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// listen for incoming messages from wallet
|
|
@@ -1,12 +1,13 @@
|
|
|
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
|
-
export class
|
|
10
|
+
export class WalletUtils {
|
|
10
11
|
private wallet: Wallet
|
|
11
12
|
|
|
12
13
|
constructor(walletProvider: 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/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,
|
package/src/wallet.ts
CHANGED
|
@@ -31,10 +31,10 @@ import { JsonRpcProvider, JsonRpcSigner, ExternalProvider } from '@ethersproject
|
|
|
31
31
|
import { Web3Provider, Web3Signer } from './provider'
|
|
32
32
|
import { MuxMessageProvider, WindowMessageProvider, ProxyMessageProvider, ProxyMessageChannelPort } from './transports'
|
|
33
33
|
import { WalletSession, ProviderEventTypes, ConnectOptions, OpenWalletIntent, ConnectDetails } from './types'
|
|
34
|
-
import { WalletCommands } from './commands'
|
|
35
34
|
import { ethers } from 'ethers'
|
|
36
35
|
import { ExtensionMessageProvider } from './transports/extension-transport/extension-message-provider'
|
|
37
36
|
import { LocalStore } from './utils'
|
|
37
|
+
import { WalletUtils } from './utils/index'
|
|
38
38
|
|
|
39
39
|
import { Runtime } from 'webextension-polyfill-ts'
|
|
40
40
|
|
|
@@ -68,11 +68,11 @@ export interface WalletProvider {
|
|
|
68
68
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void
|
|
69
69
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
utils: WalletUtils
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export class Wallet implements WalletProvider {
|
|
75
|
-
public
|
|
75
|
+
public utils: WalletUtils
|
|
76
76
|
|
|
77
77
|
private config: ProviderConfig
|
|
78
78
|
private session?: WalletSession
|
|
@@ -116,7 +116,7 @@ export class Wallet implements WalletProvider {
|
|
|
116
116
|
this.networks = []
|
|
117
117
|
this.providers = {}
|
|
118
118
|
this.connectedSites = new LocalStore('@sequence.connectedSites', [])
|
|
119
|
-
this.
|
|
119
|
+
this.utils = new WalletUtils(this)
|
|
120
120
|
this.init()
|
|
121
121
|
}
|
|
122
122
|
|