@walletconnect/ethereum-provider 1.7.7 → 2.0.0-2.0.0-beta.102
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/LICENSE +190 -0
- package/README.md +2 -172
- package/dist/cjs/index.d.ts +41 -11
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +141 -41
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +41 -11
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +138 -42
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +3004 -1
- package/dist/tsconfig.esm.tsbuildinfo +3004 -1
- package/dist/umd/index.min.js +12 -29
- package/package.json +66 -59
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2021 WalletConnect, Inc.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,173 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @walletconnect/ethereum-provider
|
|
2
2
|
|
|
3
|
-
Ethereum Provider for WalletConnect
|
|
4
|
-
|
|
5
|
-
For more details, read the [documentation](https://docs.walletconnect.org)
|
|
6
|
-
|
|
7
|
-
## Setup
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import Web3 from "web3";
|
|
11
|
-
import WalletConnectProvider from "@walletconnect/ethereum-provider";
|
|
12
|
-
|
|
13
|
-
// Create WalletConnect Provider
|
|
14
|
-
const provider = new WalletConnectProvider({
|
|
15
|
-
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1", // Required
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// Enable session (triggers QR Code modal)
|
|
19
|
-
await provider.enable();
|
|
20
|
-
|
|
21
|
-
// Create Web3
|
|
22
|
-
const web3 = new Web3(provider);
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Events (EIP-1193)
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
// Subscribe to accounts change
|
|
29
|
-
provider.on("accountsChanged", (accounts: string[]) => {
|
|
30
|
-
console.log(accounts);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Subscribe to chainId change
|
|
34
|
-
provider.on("chainChanged", (chainId: number) => {
|
|
35
|
-
console.log(chainId);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Subscribe to session connection
|
|
39
|
-
provider.on("connect", () => {
|
|
40
|
-
console.log("connect");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Subscribe to session disconnection
|
|
44
|
-
provider.on("disconnect", (code: number, reason: string) => {
|
|
45
|
-
console.log(code, reason);
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Provider Methods
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
interface RequestArguments {
|
|
53
|
-
method: string;
|
|
54
|
-
params?: unknown[] | object;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Send JSON RPC requests
|
|
58
|
-
const result = await provider.request(payload: RequestArguments);
|
|
59
|
-
|
|
60
|
-
// Close provider session
|
|
61
|
-
await provider.disconnect()
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Web3 Methods
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
// Get Accounts
|
|
68
|
-
const accounts = await web3.eth.getAccounts();
|
|
69
|
-
|
|
70
|
-
// Get Chain Id
|
|
71
|
-
const chainId = await web3.eth.chainId();
|
|
72
|
-
|
|
73
|
-
// Get Network Id
|
|
74
|
-
const networkId = await web3.eth.net.getId();
|
|
75
|
-
|
|
76
|
-
// Send Transaction
|
|
77
|
-
const txHash = await web3.eth.sendTransaction(tx);
|
|
78
|
-
|
|
79
|
-
// Sign Transaction
|
|
80
|
-
const signedTx = await web3.eth.signTransaction(tx);
|
|
81
|
-
|
|
82
|
-
// Sign Message
|
|
83
|
-
const signedMessage = await web3.eth.sign(msg);
|
|
84
|
-
|
|
85
|
-
// Sign Typed Data
|
|
86
|
-
const signedTypedData = await web3.eth.signTypedData(msg);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Provider Options
|
|
90
|
-
|
|
91
|
-
### Required
|
|
92
|
-
|
|
93
|
-
In order to resolve non-signing requests you need to provide one of the following:
|
|
94
|
-
|
|
95
|
-
#### Infura ID
|
|
96
|
-
|
|
97
|
-
The infuraId will support the following chainId's: Mainnet (1), Ropsten (3), Rinkeby(4), Goerli (5) and Kovan (42)
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
const provider = new WalletConnectProvider({
|
|
101
|
-
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
|
|
102
|
-
});
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
#### RPC URL Mapping
|
|
106
|
-
|
|
107
|
-
The RPC URL mapping should indexed by chainId and it requires at least one value.
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
const provider = new WalletConnectProvider({
|
|
111
|
-
rpc: {
|
|
112
|
-
1: "https://mainnet.mycustomnode.com",
|
|
113
|
-
3: "https://ropsten.mycustomnode.com",
|
|
114
|
-
100: "https://dai.poa.network",
|
|
115
|
-
// ...
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Optional
|
|
121
|
-
|
|
122
|
-
You can also customize the connector through the provider using the following options
|
|
123
|
-
|
|
124
|
-
#### Bridge URL
|
|
125
|
-
|
|
126
|
-
Use your own hosted bridge by providing the url
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
const provider = new WalletConnectProvider({
|
|
130
|
-
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
|
|
131
|
-
bridge: "https://bridge.myhostedserver.com",
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
#### Disable QR Code Modal
|
|
136
|
-
|
|
137
|
-
Use your own custom qrcode modal and disable the built-in one
|
|
138
|
-
|
|
139
|
-
```typescript
|
|
140
|
-
const provider = new WalletConnectProvider({
|
|
141
|
-
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
|
|
142
|
-
qrcode: false,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
provider.connector.on("display_uri", (err, payload) => {
|
|
146
|
-
const uri = payload.params[0];
|
|
147
|
-
CustomQRCodeModal.display(uri);
|
|
148
|
-
});
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### Filter Linking Options
|
|
152
|
-
|
|
153
|
-
If you would like to reduce the number of linking options or customize its order, you can provide an array of wallet names.
|
|
154
|
-
Providing empty whitelist disables linking.
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
const provider = new WalletConnectProvider({
|
|
158
|
-
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
|
|
159
|
-
qrcodeModalOptions: {
|
|
160
|
-
mobileLinks: [
|
|
161
|
-
"rainbow",
|
|
162
|
-
"metamask",
|
|
163
|
-
"argent",
|
|
164
|
-
"trust",
|
|
165
|
-
"imtoken",
|
|
166
|
-
"pillar",
|
|
167
|
-
],
|
|
168
|
-
desktopLinks: [
|
|
169
|
-
"encrypted ink",
|
|
170
|
-
]
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
```
|
|
3
|
+
Ethereum Provider for WalletConnect Protocol
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcProvider } from "@walletconnect/jsonrpc-provider";
|
|
2
|
+
import { SignerConnectionClientOpts } from "@walletconnect/signer-connection";
|
|
2
3
|
import { IEthereumProvider, ProviderAccounts, RequestArguments } from "eip1193-provider";
|
|
3
|
-
declare
|
|
4
|
+
export declare const signerMethods: string[];
|
|
5
|
+
export declare const signerEvents: string[];
|
|
6
|
+
export interface EthereumRpcMap {
|
|
7
|
+
[chainId: string]: string;
|
|
8
|
+
}
|
|
9
|
+
export interface EthereumRpcConfig {
|
|
10
|
+
chains: string[];
|
|
11
|
+
methods: string[];
|
|
12
|
+
events: string[];
|
|
13
|
+
rpcMap?: EthereumRpcMap;
|
|
14
|
+
}
|
|
15
|
+
export declare function getRpcConfig(opts: EthereumProviderOptions): EthereumRpcConfig;
|
|
16
|
+
export declare function getRpcUrl(chainId: string, rpc: EthereumRpcConfig): string | undefined;
|
|
17
|
+
export declare function getEthereumChainId(chains: string[]): number;
|
|
18
|
+
export interface EthereumProviderOptions {
|
|
19
|
+
chainId: number;
|
|
20
|
+
methods?: string[];
|
|
21
|
+
events?: string[];
|
|
22
|
+
rpcMap?: EthereumRpcMap;
|
|
23
|
+
client?: SignerConnectionClientOpts;
|
|
24
|
+
}
|
|
25
|
+
declare class EthereumProvider implements IEthereumProvider {
|
|
4
26
|
events: any;
|
|
27
|
+
namespace: string;
|
|
28
|
+
accounts: string[];
|
|
29
|
+
signer: JsonRpcProvider;
|
|
30
|
+
http: JsonRpcProvider | undefined;
|
|
31
|
+
chainId: number;
|
|
5
32
|
private rpc;
|
|
6
|
-
|
|
7
|
-
private http;
|
|
8
|
-
constructor(opts?: IWCEthRpcConnectionOptions);
|
|
9
|
-
get connected(): boolean;
|
|
10
|
-
get connector(): IConnector;
|
|
11
|
-
get accounts(): string[];
|
|
12
|
-
get chainId(): number;
|
|
13
|
-
get rpcUrl(): string;
|
|
33
|
+
constructor(opts: EthereumProviderOptions);
|
|
14
34
|
request<T = unknown>(args: RequestArguments): Promise<T>;
|
|
15
35
|
sendAsync(args: RequestArguments, callback: (error: Error | null, response: any) => void): void;
|
|
36
|
+
get connected(): boolean;
|
|
37
|
+
get connecting(): boolean;
|
|
16
38
|
enable(): Promise<ProviderAccounts>;
|
|
17
39
|
connect(): Promise<void>;
|
|
18
40
|
disconnect(): Promise<void>;
|
|
@@ -22,7 +44,15 @@ declare class WalletConnectProvider implements IEthereumProvider {
|
|
|
22
44
|
off(event: string, listener: any): void;
|
|
23
45
|
get isWalletConnect(): boolean;
|
|
24
46
|
private registerEventListeners;
|
|
47
|
+
private setSignerProvider;
|
|
25
48
|
private setHttpProvider;
|
|
49
|
+
private isCompatibleChainId;
|
|
50
|
+
private formatChainId;
|
|
51
|
+
private parseChainId;
|
|
52
|
+
private setChainIds;
|
|
53
|
+
private setChainId;
|
|
54
|
+
private parseAccountId;
|
|
55
|
+
private setAccounts;
|
|
26
56
|
}
|
|
27
|
-
export default
|
|
57
|
+
export default EthereumProvider;
|
|
28
58
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAIlE,OAAO,EAGL,0BAA0B,EAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzF,eAAO,MAAM,aAAa,UASzB,CAAC;AAEF,eAAO,MAAM,YAAY,UAAsC,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC7B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,uBAAuB,GAAG,iBAAiB,CAO7E;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAMrF;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAE3D;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,MAAM,CAAC,EAAE,0BAA0B,CAAC;CACrC;AAED,cAAM,gBAAiB,YAAW,iBAAiB;IAC1C,MAAM,EAAE,GAAG,CAAsB;IACjC,SAAS,SAAY;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAM;IACxB,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,GAAG,CAAoB;gBAEnB,IAAI,EAAE,uBAAuB;IAQ5B,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;IAqB9D,SAAS,CACd,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,IAAI,GACrD,IAAI;IAMP,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAEY,MAAM,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKnC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAGnC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAGxC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAGlD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAI9C,IAAI,eAAe,YAElB;IAID,OAAO,CAAC,sBAAsB;IAuC9B,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,WAAW;CAMpB;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,51 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEthereumChainId = exports.getRpcUrl = exports.getRpcConfig = exports.signerEvents = exports.signerMethods = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
5
|
+
const events_1 = require("events");
|
|
5
6
|
const jsonrpc_provider_1 = require("@walletconnect/jsonrpc-provider");
|
|
6
7
|
const jsonrpc_http_connection_1 = require("@walletconnect/jsonrpc-http-connection");
|
|
7
8
|
const utils_1 = require("@walletconnect/utils");
|
|
8
9
|
const signer_connection_1 = require("@walletconnect/signer-connection");
|
|
9
|
-
|
|
10
|
+
exports.signerMethods = [
|
|
11
|
+
"eth_requestAccounts",
|
|
12
|
+
"eth_accounts",
|
|
13
|
+
"eth_chainId",
|
|
14
|
+
"eth_sendTransaction",
|
|
15
|
+
"eth_signTransaction",
|
|
16
|
+
"eth_sign",
|
|
17
|
+
"eth_signTypedData",
|
|
18
|
+
"personal_sign",
|
|
19
|
+
];
|
|
20
|
+
exports.signerEvents = ["chainChanged", "accountsChanged"];
|
|
21
|
+
function getRpcConfig(opts) {
|
|
22
|
+
return {
|
|
23
|
+
chains: (opts === null || opts === void 0 ? void 0 : opts.chainId) ? [`eip155:${opts.chainId}`] : [],
|
|
24
|
+
methods: (opts === null || opts === void 0 ? void 0 : opts.methods) || [],
|
|
25
|
+
events: (opts === null || opts === void 0 ? void 0 : opts.events) || [],
|
|
26
|
+
rpcMap: (opts === null || opts === void 0 ? void 0 : opts.rpcMap) || undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.getRpcConfig = getRpcConfig;
|
|
30
|
+
function getRpcUrl(chainId, rpc) {
|
|
31
|
+
let rpcUrl;
|
|
32
|
+
if (rpc.rpcMap) {
|
|
33
|
+
rpcUrl = rpc.rpcMap[getEthereumChainId([chainId])];
|
|
34
|
+
}
|
|
35
|
+
return rpcUrl;
|
|
36
|
+
}
|
|
37
|
+
exports.getRpcUrl = getRpcUrl;
|
|
38
|
+
function getEthereumChainId(chains) {
|
|
39
|
+
return Number(chains[0].split(":")[1]);
|
|
40
|
+
}
|
|
41
|
+
exports.getEthereumChainId = getEthereumChainId;
|
|
42
|
+
class EthereumProvider {
|
|
10
43
|
constructor(opts) {
|
|
11
|
-
this.events = new
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
this.
|
|
44
|
+
this.events = new events_1.EventEmitter();
|
|
45
|
+
this.namespace = "eip155";
|
|
46
|
+
this.accounts = [];
|
|
47
|
+
this.rpc = getRpcConfig(opts);
|
|
48
|
+
this.signer = this.setSignerProvider(opts === null || opts === void 0 ? void 0 : opts.client);
|
|
49
|
+
this.chainId = getEthereumChainId(this.rpc.chains);
|
|
50
|
+
this.http = this.setHttpProvider(this.chainId);
|
|
16
51
|
this.registerEventListeners();
|
|
17
52
|
}
|
|
18
|
-
get connected() {
|
|
19
|
-
return this.signer.connection.connected;
|
|
20
|
-
}
|
|
21
|
-
get connector() {
|
|
22
|
-
return this.signer.connection.connector;
|
|
23
|
-
}
|
|
24
|
-
get accounts() {
|
|
25
|
-
return this.signer.connection.accounts;
|
|
26
|
-
}
|
|
27
|
-
get chainId() {
|
|
28
|
-
return this.signer.connection.chainId;
|
|
29
|
-
}
|
|
30
|
-
get rpcUrl() {
|
|
31
|
-
var _a;
|
|
32
|
-
return ((_a = this.http) === null || _a === void 0 ? void 0 : _a.connection).url || "";
|
|
33
|
-
}
|
|
34
53
|
request(args) {
|
|
35
54
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
55
|
switch (args.method) {
|
|
37
56
|
case "eth_requestAccounts":
|
|
38
57
|
yield this.connect();
|
|
39
|
-
return this.
|
|
58
|
+
return this.accounts;
|
|
40
59
|
case "eth_accounts":
|
|
41
|
-
return this.
|
|
60
|
+
return this.accounts;
|
|
42
61
|
case "eth_chainId":
|
|
43
|
-
return this.
|
|
62
|
+
return this.chainId;
|
|
44
63
|
default:
|
|
45
64
|
break;
|
|
46
65
|
}
|
|
47
|
-
if (
|
|
48
|
-
return this.signer.request(args);
|
|
66
|
+
if (args.method.startsWith("eth_signTypedData") || this.rpc.methods.includes(args.method)) {
|
|
67
|
+
return this.signer.request(args, { chainId: this.formatChainId(this.chainId) });
|
|
49
68
|
}
|
|
50
69
|
if (typeof this.http === "undefined") {
|
|
51
70
|
throw new Error(`Cannot request JSON-RPC method (${args.method}) without provided rpc url`);
|
|
@@ -58,6 +77,12 @@ class WalletConnectProvider {
|
|
|
58
77
|
.then(response => callback(null, response))
|
|
59
78
|
.catch(error => callback(error, undefined));
|
|
60
79
|
}
|
|
80
|
+
get connected() {
|
|
81
|
+
return this.signer.connection.connected;
|
|
82
|
+
}
|
|
83
|
+
get connecting() {
|
|
84
|
+
return this.signer.connection.connecting;
|
|
85
|
+
}
|
|
61
86
|
enable() {
|
|
62
87
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
88
|
const accounts = yield this.request({ method: "eth_requestAccounts" });
|
|
@@ -66,16 +91,12 @@ class WalletConnectProvider {
|
|
|
66
91
|
}
|
|
67
92
|
connect() {
|
|
68
93
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
|
|
70
|
-
yield this.signer.connect();
|
|
71
|
-
}
|
|
94
|
+
yield this.signer.connect();
|
|
72
95
|
});
|
|
73
96
|
}
|
|
74
97
|
disconnect() {
|
|
75
98
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
|
|
77
|
-
yield this.signer.disconnect();
|
|
78
|
-
}
|
|
99
|
+
yield this.signer.disconnect();
|
|
79
100
|
});
|
|
80
101
|
}
|
|
81
102
|
on(event, listener) {
|
|
@@ -94,24 +115,103 @@ class WalletConnectProvider {
|
|
|
94
115
|
return true;
|
|
95
116
|
}
|
|
96
117
|
registerEventListeners() {
|
|
97
|
-
this.signer.
|
|
98
|
-
this.
|
|
118
|
+
this.signer.on("connect", () => {
|
|
119
|
+
const chains = this.signer.connection.chains;
|
|
120
|
+
if (chains && chains.length)
|
|
121
|
+
this.setChainIds(chains);
|
|
122
|
+
const accounts = this.signer.connection.accounts;
|
|
123
|
+
if (accounts && accounts.length)
|
|
124
|
+
this.setAccounts(accounts);
|
|
125
|
+
});
|
|
126
|
+
this.signer.connection.on(signer_connection_1.SIGNER_EVENTS.created, (session) => {
|
|
127
|
+
const chains = utils_1.getChainsFromNamespaces(session.namespaces, [this.namespace]);
|
|
128
|
+
this.setChainIds(chains);
|
|
129
|
+
const accounts = utils_1.getAccountsFromNamespaces(session.namespaces, [this.namespace]);
|
|
130
|
+
this.setAccounts(accounts);
|
|
131
|
+
});
|
|
132
|
+
this.signer.connection.on(signer_connection_1.SIGNER_EVENTS.updated, (session) => {
|
|
133
|
+
const chains = utils_1.getChainsFromNamespaces(session.namespaces, [this.namespace]);
|
|
134
|
+
this.setChainIds(chains);
|
|
135
|
+
const accounts = utils_1.getAccountsFromNamespaces(session.namespaces, [this.namespace]);
|
|
136
|
+
if (accounts !== this.accounts) {
|
|
137
|
+
this.setAccounts(accounts);
|
|
138
|
+
}
|
|
99
139
|
});
|
|
100
|
-
this.signer.connection.on(
|
|
101
|
-
|
|
102
|
-
|
|
140
|
+
this.signer.connection.on(signer_connection_1.SIGNER_EVENTS.event, (params) => {
|
|
141
|
+
if (!this.rpc.chains.includes(params.chainId))
|
|
142
|
+
return;
|
|
143
|
+
const { event } = params;
|
|
144
|
+
if (event.name === "accountsChanged") {
|
|
145
|
+
this.accounts = event.data;
|
|
146
|
+
this.events.emit("accountsChanged", this.accounts);
|
|
147
|
+
}
|
|
148
|
+
else if (event.name === "chainChanged") {
|
|
149
|
+
this.setChainId(event.data);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this.events.emit(event.name, event.data);
|
|
153
|
+
}
|
|
103
154
|
});
|
|
104
155
|
this.signer.on("disconnect", () => {
|
|
105
156
|
this.events.emit("disconnect");
|
|
106
157
|
});
|
|
158
|
+
this.events.on("chainChanged", (chainId) => this.setHttpProvider(chainId));
|
|
159
|
+
}
|
|
160
|
+
setSignerProvider(client) {
|
|
161
|
+
const connection = new signer_connection_1.SignerConnection({
|
|
162
|
+
requiredNamespaces: {
|
|
163
|
+
[this.namespace]: {
|
|
164
|
+
chains: this.rpc.chains,
|
|
165
|
+
methods: this.rpc.methods,
|
|
166
|
+
events: this.rpc.events,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
client,
|
|
170
|
+
});
|
|
171
|
+
return new jsonrpc_provider_1.JsonRpcProvider(connection);
|
|
107
172
|
}
|
|
108
173
|
setHttpProvider(chainId) {
|
|
109
|
-
const rpcUrl = (
|
|
174
|
+
const rpcUrl = getRpcUrl(`${this.namespace}:${chainId}`, this.rpc);
|
|
110
175
|
if (typeof rpcUrl === "undefined")
|
|
111
176
|
return undefined;
|
|
112
177
|
const http = new jsonrpc_provider_1.JsonRpcProvider(new jsonrpc_http_connection_1.HttpConnection(rpcUrl));
|
|
113
178
|
return http;
|
|
114
179
|
}
|
|
180
|
+
isCompatibleChainId(chainId) {
|
|
181
|
+
return typeof chainId === "string" ? chainId.startsWith(`${this.namespace}:`) : false;
|
|
182
|
+
}
|
|
183
|
+
formatChainId(chainId) {
|
|
184
|
+
return `${this.namespace}:${chainId}`;
|
|
185
|
+
}
|
|
186
|
+
parseChainId(chainId) {
|
|
187
|
+
return Number(chainId.split(":")[1]);
|
|
188
|
+
}
|
|
189
|
+
setChainIds(chains) {
|
|
190
|
+
const compatible = chains.filter(x => this.isCompatibleChainId(x));
|
|
191
|
+
const chainIds = compatible.map(c => this.parseChainId(c)).filter(c => c !== this.chainId);
|
|
192
|
+
if (chainIds.length) {
|
|
193
|
+
this.chainId = chainIds[0];
|
|
194
|
+
this.events.emit("chainChanged", this.chainId);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
setChainId(chain) {
|
|
198
|
+
if (this.isCompatibleChainId(chain)) {
|
|
199
|
+
const chainId = this.parseChainId(chain);
|
|
200
|
+
this.chainId = chainId;
|
|
201
|
+
this.events.emit("chainChanged", this.chainId);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
parseAccountId(account) {
|
|
205
|
+
const [namespace, reference, address] = account.split(":");
|
|
206
|
+
const chainId = `${namespace}:${reference}`;
|
|
207
|
+
return { chainId, address };
|
|
208
|
+
}
|
|
209
|
+
setAccounts(accounts) {
|
|
210
|
+
this.accounts = accounts
|
|
211
|
+
.filter(x => this.parseChainId(this.parseAccountId(x).chainId) === this.chainId)
|
|
212
|
+
.map(x => this.parseAccountId(x).address);
|
|
213
|
+
this.events.emit("accountsChanged", this.accounts);
|
|
214
|
+
}
|
|
115
215
|
}
|
|
116
|
-
exports.default =
|
|
216
|
+
exports.default = EthereumProvider;
|
|
117
217
|
//# sourceMappingURL=index.js.map
|