@walletconnect/ethereum-provider 2.0.0-beta.2 → 2.0.0-beta.20.3
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/cjs/index.d.ts +14 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +66 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +64 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +196 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +779 -418
- package/dist/tsconfig.esm.tsbuildinfo +2151 -0
- package/dist/umd/index.min.js +10 -14
- package/package.json +15 -11
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonRpcProvider } from "@
|
|
1
|
+
import { JsonRpcProvider } from "@walletconnect/jsonrpc-provider";
|
|
2
2
|
import { SignerConnectionClientOpts } from "@walletconnect/signer-connection";
|
|
3
3
|
import { IEthereumProvider, ProviderAccounts, RequestArguments } from "eip1193-provider";
|
|
4
4
|
export declare const signerMethods: string[];
|
|
@@ -9,6 +9,12 @@ export declare const infuraNetworks: {
|
|
|
9
9
|
5: string;
|
|
10
10
|
42: string;
|
|
11
11
|
};
|
|
12
|
+
export declare const providerEvents: {
|
|
13
|
+
changed: {
|
|
14
|
+
chain: string;
|
|
15
|
+
accounts: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
12
18
|
export interface EthereumRpcConfig {
|
|
13
19
|
infuraId?: string;
|
|
14
20
|
custom?: {
|
|
@@ -26,6 +32,7 @@ export interface EthereumProviderOptions {
|
|
|
26
32
|
declare class EthereumProvider implements IEthereumProvider {
|
|
27
33
|
events: any;
|
|
28
34
|
private rpc;
|
|
35
|
+
namespace: string;
|
|
29
36
|
chainId: number;
|
|
30
37
|
methods: string[];
|
|
31
38
|
accounts: string[];
|
|
@@ -33,6 +40,8 @@ declare class EthereumProvider implements IEthereumProvider {
|
|
|
33
40
|
http: JsonRpcProvider | undefined;
|
|
34
41
|
constructor(opts?: EthereumProviderOptions);
|
|
35
42
|
request<T = unknown>(args: RequestArguments): Promise<T>;
|
|
43
|
+
get connected(): boolean;
|
|
44
|
+
get connecting(): boolean;
|
|
36
45
|
enable(): Promise<ProviderAccounts>;
|
|
37
46
|
connect(): Promise<void>;
|
|
38
47
|
disconnect(): Promise<void>;
|
|
@@ -44,7 +53,11 @@ declare class EthereumProvider implements IEthereumProvider {
|
|
|
44
53
|
private registerEventListeners;
|
|
45
54
|
private setSignerProvider;
|
|
46
55
|
private setHttpProvider;
|
|
56
|
+
private isCompatibleChainId;
|
|
57
|
+
private formatChainId;
|
|
58
|
+
private parseChainId;
|
|
47
59
|
private setChainId;
|
|
60
|
+
private parseAccountId;
|
|
48
61
|
private setAccounts;
|
|
49
62
|
}
|
|
50
63
|
export default EthereumProvider;
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGlE,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,cAAc;;;;;;CAM1B,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;CAK1B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QACP,CAAC,OAAO,EAAE,MAAM,GAA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G,GAAG,IAAI;IAGlD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAI9C,IAAI,eAAe,YAElB;IAID,OAAO,CAAC,sBAAsB;IAwC9B,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,WAAW;CAMpB;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRpcUrl = exports.getInfuraRpcUrl = exports.infuraNetworks = exports.signerMethods = void 0;
|
|
3
|
+
exports.getRpcUrl = exports.getInfuraRpcUrl = exports.providerEvents = exports.infuraNetworks = exports.signerMethods = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
const jsonrpc_provider_1 = require("@walletconnect/jsonrpc-provider");
|
|
7
|
+
const jsonrpc_http_connection_1 = require("@walletconnect/jsonrpc-http-connection");
|
|
7
8
|
const signer_connection_1 = require("@walletconnect/signer-connection");
|
|
8
9
|
exports.signerMethods = [
|
|
9
10
|
"eth_requestAccounts",
|
|
@@ -22,6 +23,12 @@ exports.infuraNetworks = {
|
|
|
22
23
|
5: "goerli",
|
|
23
24
|
42: "kovan",
|
|
24
25
|
};
|
|
26
|
+
exports.providerEvents = {
|
|
27
|
+
changed: {
|
|
28
|
+
chain: "chainChanged",
|
|
29
|
+
accounts: "accountsChanged",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
25
32
|
function getInfuraRpcUrl(chainId, infuraId) {
|
|
26
33
|
let rpcUrl;
|
|
27
34
|
const network = exports.infuraNetworks[chainId];
|
|
@@ -45,7 +52,8 @@ function getRpcUrl(chainId, rpc) {
|
|
|
45
52
|
exports.getRpcUrl = getRpcUrl;
|
|
46
53
|
class EthereumProvider {
|
|
47
54
|
constructor(opts) {
|
|
48
|
-
this.events = new
|
|
55
|
+
this.events = new events_1.EventEmitter();
|
|
56
|
+
this.namespace = "eip155";
|
|
49
57
|
this.chainId = 1;
|
|
50
58
|
this.methods = exports.signerMethods;
|
|
51
59
|
this.accounts = [];
|
|
@@ -70,7 +78,7 @@ class EthereumProvider {
|
|
|
70
78
|
break;
|
|
71
79
|
}
|
|
72
80
|
if (args.method.startsWith("eth_signTypedData") || this.methods.includes(args.method)) {
|
|
73
|
-
return this.signer.request(args);
|
|
81
|
+
return this.signer.request(args, { chainId: this.formatChainId(this.chainId) });
|
|
74
82
|
}
|
|
75
83
|
if (typeof this.http === "undefined") {
|
|
76
84
|
throw new Error(`Cannot request JSON-RPC method (${args.method}) without provided rpc url`);
|
|
@@ -78,6 +86,12 @@ class EthereumProvider {
|
|
|
78
86
|
return this.http.request(args);
|
|
79
87
|
});
|
|
80
88
|
}
|
|
89
|
+
get connected() {
|
|
90
|
+
return this.signer.connection.connected;
|
|
91
|
+
}
|
|
92
|
+
get connecting() {
|
|
93
|
+
return this.signer.connection.connecting;
|
|
94
|
+
}
|
|
81
95
|
enable() {
|
|
82
96
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
97
|
const accounts = yield this.request({ method: "eth_requestAccounts" });
|
|
@@ -110,12 +124,20 @@ class EthereumProvider {
|
|
|
110
124
|
return true;
|
|
111
125
|
}
|
|
112
126
|
registerEventListeners() {
|
|
127
|
+
this.signer.on("connect", () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const chains = this.signer.connection.chains;
|
|
129
|
+
if (chains && chains.length)
|
|
130
|
+
this.setChainId(chains);
|
|
131
|
+
const accounts = this.signer.connection.accounts;
|
|
132
|
+
if (accounts && accounts.length)
|
|
133
|
+
this.setAccounts(accounts);
|
|
134
|
+
}));
|
|
113
135
|
this.signer.connection.on(signer_connection_1.SIGNER_EVENTS.created, (session) => {
|
|
114
136
|
this.setChainId(session.permissions.blockchain.chains);
|
|
115
137
|
this.setAccounts(session.state.accounts);
|
|
116
138
|
});
|
|
117
139
|
this.signer.connection.on(signer_connection_1.SIGNER_EVENTS.updated, (session) => {
|
|
118
|
-
const chain =
|
|
140
|
+
const chain = this.formatChainId(this.chainId);
|
|
119
141
|
if (!session.permissions.blockchain.chains.includes(chain)) {
|
|
120
142
|
this.setChainId(session.permissions.blockchain.chains);
|
|
121
143
|
}
|
|
@@ -124,37 +146,64 @@ class EthereumProvider {
|
|
|
124
146
|
}
|
|
125
147
|
});
|
|
126
148
|
this.signer.connection.on(signer_connection_1.SIGNER_EVENTS.notification, (notification) => {
|
|
127
|
-
|
|
149
|
+
if (notification.type === exports.providerEvents.changed.accounts) {
|
|
150
|
+
this.accounts = notification.data;
|
|
151
|
+
this.events.emit(exports.providerEvents.changed.accounts, this.accounts);
|
|
152
|
+
}
|
|
153
|
+
else if (notification.type === exports.providerEvents.changed.chain) {
|
|
154
|
+
this.chainId = notification.data;
|
|
155
|
+
this.events.emit(exports.providerEvents.changed.chain, this.chainId);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.events.emit(notification.type, notification.data);
|
|
159
|
+
}
|
|
128
160
|
});
|
|
129
|
-
this.
|
|
161
|
+
this.signer.on("disconnect", () => {
|
|
162
|
+
this.events.emit("disconnect");
|
|
163
|
+
});
|
|
164
|
+
this.events.on(exports.providerEvents.changed.chain, chainId => this.setHttpProvider(chainId));
|
|
130
165
|
}
|
|
131
166
|
setSignerProvider(client) {
|
|
132
167
|
const connection = new signer_connection_1.SignerConnection({
|
|
133
|
-
chains: [
|
|
168
|
+
chains: [this.formatChainId(this.chainId)],
|
|
134
169
|
methods: this.methods,
|
|
135
170
|
client,
|
|
136
171
|
});
|
|
137
|
-
return new
|
|
172
|
+
return new jsonrpc_provider_1.JsonRpcProvider(connection);
|
|
138
173
|
}
|
|
139
174
|
setHttpProvider(chainId) {
|
|
140
175
|
const rpcUrl = getRpcUrl(chainId, this.rpc);
|
|
141
176
|
if (typeof rpcUrl === "undefined")
|
|
142
177
|
return undefined;
|
|
143
|
-
const http = new
|
|
178
|
+
const http = new jsonrpc_provider_1.JsonRpcProvider(new jsonrpc_http_connection_1.HttpConnection(rpcUrl));
|
|
144
179
|
return http;
|
|
145
180
|
}
|
|
181
|
+
isCompatibleChainId(chainId) {
|
|
182
|
+
return chainId.startsWith(`${this.namespace}:`);
|
|
183
|
+
}
|
|
184
|
+
formatChainId(chainId) {
|
|
185
|
+
return `${this.namespace}:${chainId}`;
|
|
186
|
+
}
|
|
187
|
+
parseChainId(chainId) {
|
|
188
|
+
return Number(chainId.split(":")[1]);
|
|
189
|
+
}
|
|
146
190
|
setChainId(chains) {
|
|
147
|
-
const compatible = chains.filter(x =>
|
|
191
|
+
const compatible = chains.filter(x => this.isCompatibleChainId(x));
|
|
148
192
|
if (compatible.length) {
|
|
149
|
-
this.chainId =
|
|
150
|
-
this.events.emit(
|
|
193
|
+
this.chainId = this.parseChainId(compatible[0]);
|
|
194
|
+
this.events.emit(exports.providerEvents.changed.chain, this.chainId);
|
|
151
195
|
}
|
|
152
196
|
}
|
|
197
|
+
parseAccountId(account) {
|
|
198
|
+
const [namespace, reference, address] = account.split(":");
|
|
199
|
+
const chainId = `${namespace}:${reference}`;
|
|
200
|
+
return { chainId, address };
|
|
201
|
+
}
|
|
153
202
|
setAccounts(accounts) {
|
|
154
203
|
this.accounts = accounts
|
|
155
|
-
.filter(x =>
|
|
156
|
-
.map(x =>
|
|
157
|
-
this.events.emit(
|
|
204
|
+
.filter(x => this.parseChainId(this.parseAccountId(x).chainId) === this.chainId)
|
|
205
|
+
.map(x => this.parseAccountId(x).address);
|
|
206
|
+
this.events.emit(exports.providerEvents.changed.accounts, this.accounts);
|
|
158
207
|
}
|
|
159
208
|
}
|
|
160
209
|
exports.default = EthereumProvider;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,mCAAsC;AACtC,sEAAkE;AAClE,oFAAwE;AAExE,wEAI0C;AAG7B,QAAA,aAAa,GAAG;IAC3B,qBAAqB;IACrB,cAAc;IACd,aAAa;IACb,qBAAqB;IACrB,qBAAqB;IACrB,UAAU;IACV,mBAAmB;IACnB,eAAe;CAChB,CAAC;AAEW,QAAA,cAAc,GAAG;IAC5B,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,OAAO;CACZ,CAAC;AAEW,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE;QACP,KAAK,EAAE,cAAc;QACrB,QAAQ,EAAE,iBAAiB;KAC5B;CACF,CAAC;AASF,SAAgB,eAAe,CAAC,OAAe,EAAE,QAAiB;IAChE,IAAI,MAA0B,CAAC;IAC/B,MAAM,OAAO,GAAG,sBAAc,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,OAAO,EAAE;QACX,MAAM,GAAG,WAAW,OAAO,iBAAiB,QAAQ,EAAE,CAAC;KACxD;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAPD,0CAOC;AAED,SAAgB,SAAS,CAAC,OAAe,EAAE,GAAuB;IAChE,IAAI,MAA0B,CAAC;IAC/B,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,CAAC,CAAC;IAC1D,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE;QACrB,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC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{ IEthereumProvider, ProviderAccounts, RequestArguments } from "eip1193-provider";
|
|
4
|
+
export declare const signerMethods: string[];
|
|
5
|
+
export declare const infuraNetworks: {
|
|
6
|
+
1: string;
|
|
7
|
+
3: string;
|
|
8
|
+
4: string;
|
|
9
|
+
5: string;
|
|
10
|
+
42: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const providerEvents: {
|
|
13
|
+
changed: {
|
|
14
|
+
chain: string;
|
|
15
|
+
accounts: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export interface EthereumRpcConfig {
|
|
19
|
+
infuraId?: string;
|
|
20
|
+
custom?: {
|
|
21
|
+
[chainId: number]: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare function getInfuraRpcUrl(chainId: number, infuraId?: string): string | undefined;
|
|
25
|
+
export declare function getRpcUrl(chainId: number, rpc?: EthereumRpcConfig): string | undefined;
|
|
26
|
+
export interface EthereumProviderOptions {
|
|
27
|
+
chainId: number;
|
|
28
|
+
methods?: string[];
|
|
29
|
+
rpc?: EthereumRpcConfig;
|
|
30
|
+
client?: SignerConnectionClientOpts;
|
|
31
|
+
}
|
|
32
|
+
declare class EthereumProvider implements IEthereumProvider {
|
|
33
|
+
events: any;
|
|
34
|
+
private rpc;
|
|
35
|
+
namespace: string;
|
|
36
|
+
chainId: number;
|
|
37
|
+
methods: string[];
|
|
38
|
+
accounts: string[];
|
|
39
|
+
signer: JsonRpcProvider;
|
|
40
|
+
http: JsonRpcProvider | undefined;
|
|
41
|
+
constructor(opts?: EthereumProviderOptions);
|
|
42
|
+
request<T = unknown>(args: RequestArguments): Promise<T>;
|
|
43
|
+
get connected(): boolean;
|
|
44
|
+
get connecting(): boolean;
|
|
45
|
+
enable(): Promise<ProviderAccounts>;
|
|
46
|
+
connect(): Promise<void>;
|
|
47
|
+
disconnect(): Promise<void>;
|
|
48
|
+
on(event: any, listener: any): void;
|
|
49
|
+
once(event: string, listener: any): void;
|
|
50
|
+
removeListener(event: string, listener: any): void;
|
|
51
|
+
off(event: string, listener: any): void;
|
|
52
|
+
get isWalletConnect(): boolean;
|
|
53
|
+
private registerEventListeners;
|
|
54
|
+
private setSignerProvider;
|
|
55
|
+
private setHttpProvider;
|
|
56
|
+
private isCompatibleChainId;
|
|
57
|
+
private formatChainId;
|
|
58
|
+
private parseChainId;
|
|
59
|
+
private setChainId;
|
|
60
|
+
private parseAccountId;
|
|
61
|
+
private setAccounts;
|
|
62
|
+
}
|
|
63
|
+
export default EthereumProvider;
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGlE,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,cAAc;;;;;;CAM1B,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;CAK1B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QACP,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;KAC3B,CAAC;CACH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOtF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAStF;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,G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MpB;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { JsonRpcProvider } from "@walletconnect/jsonrpc-provider";
|
|
3
|
+
import { HttpConnection } from "@walletconnect/jsonrpc-http-connection";
|
|
4
|
+
import { SignerConnection, SIGNER_EVENTS, } from "@walletconnect/signer-connection";
|
|
5
|
+
export const signerMethods = [
|
|
6
|
+
"eth_requestAccounts",
|
|
7
|
+
"eth_accounts",
|
|
8
|
+
"eth_chainId",
|
|
9
|
+
"eth_sendTransaction",
|
|
10
|
+
"eth_signTransaction",
|
|
11
|
+
"eth_sign",
|
|
12
|
+
"eth_signTypedData",
|
|
13
|
+
"personal_sign",
|
|
14
|
+
];
|
|
15
|
+
export const infuraNetworks = {
|
|
16
|
+
1: "mainnet",
|
|
17
|
+
3: "ropsten",
|
|
18
|
+
4: "rinkeby",
|
|
19
|
+
5: "goerli",
|
|
20
|
+
42: "kovan",
|
|
21
|
+
};
|
|
22
|
+
export const providerEvents = {
|
|
23
|
+
changed: {
|
|
24
|
+
chain: "chainChanged",
|
|
25
|
+
accounts: "accountsChanged",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export function getInfuraRpcUrl(chainId, infuraId) {
|
|
29
|
+
let rpcUrl;
|
|
30
|
+
const network = infuraNetworks[chainId];
|
|
31
|
+
if (network) {
|
|
32
|
+
rpcUrl = `https://${network}.infura.io/v3/${infuraId}`;
|
|
33
|
+
}
|
|
34
|
+
return rpcUrl;
|
|
35
|
+
}
|
|
36
|
+
export function getRpcUrl(chainId, rpc) {
|
|
37
|
+
let rpcUrl;
|
|
38
|
+
const infuraUrl = getInfuraRpcUrl(chainId, rpc === null || rpc === void 0 ? void 0 : rpc.infuraId);
|
|
39
|
+
if (rpc && rpc.custom) {
|
|
40
|
+
rpcUrl = rpc.custom[chainId];
|
|
41
|
+
}
|
|
42
|
+
else if (infuraUrl) {
|
|
43
|
+
rpcUrl = infuraUrl;
|
|
44
|
+
}
|
|
45
|
+
return rpcUrl;
|
|
46
|
+
}
|
|
47
|
+
class EthereumProvider {
|
|
48
|
+
constructor(opts) {
|
|
49
|
+
this.events = new EventEmitter();
|
|
50
|
+
this.namespace = "eip155";
|
|
51
|
+
this.chainId = 1;
|
|
52
|
+
this.methods = signerMethods;
|
|
53
|
+
this.accounts = [];
|
|
54
|
+
this.rpc = opts === null || opts === void 0 ? void 0 : opts.rpc;
|
|
55
|
+
this.chainId = (opts === null || opts === void 0 ? void 0 : opts.chainId) || this.chainId;
|
|
56
|
+
this.methods = (opts === null || opts === void 0 ? void 0 : opts.methods) ? [...opts === null || opts === void 0 ? void 0 : opts.methods, ...this.methods] : this.methods;
|
|
57
|
+
this.signer = this.setSignerProvider(opts === null || opts === void 0 ? void 0 : opts.client);
|
|
58
|
+
this.http = this.setHttpProvider(this.chainId);
|
|
59
|
+
this.registerEventListeners();
|
|
60
|
+
}
|
|
61
|
+
async request(args) {
|
|
62
|
+
switch (args.method) {
|
|
63
|
+
case "eth_requestAccounts":
|
|
64
|
+
await this.connect();
|
|
65
|
+
return this.accounts;
|
|
66
|
+
case "eth_accounts":
|
|
67
|
+
return this.accounts;
|
|
68
|
+
case "eth_chainId":
|
|
69
|
+
return this.chainId;
|
|
70
|
+
default:
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (args.method.startsWith("eth_signTypedData") || this.methods.includes(args.method)) {
|
|
74
|
+
return this.signer.request(args, { chainId: this.formatChainId(this.chainId) });
|
|
75
|
+
}
|
|
76
|
+
if (typeof this.http === "undefined") {
|
|
77
|
+
throw new Error(`Cannot request JSON-RPC method (${args.method}) without provided rpc url`);
|
|
78
|
+
}
|
|
79
|
+
return this.http.request(args);
|
|
80
|
+
}
|
|
81
|
+
get connected() {
|
|
82
|
+
return this.signer.connection.connected;
|
|
83
|
+
}
|
|
84
|
+
get connecting() {
|
|
85
|
+
return this.signer.connection.connecting;
|
|
86
|
+
}
|
|
87
|
+
async enable() {
|
|
88
|
+
const accounts = await this.request({ method: "eth_requestAccounts" });
|
|
89
|
+
return accounts;
|
|
90
|
+
}
|
|
91
|
+
async connect() {
|
|
92
|
+
await this.signer.connect();
|
|
93
|
+
}
|
|
94
|
+
async disconnect() {
|
|
95
|
+
await this.signer.disconnect();
|
|
96
|
+
}
|
|
97
|
+
on(event, listener) {
|
|
98
|
+
this.events.on(event, listener);
|
|
99
|
+
}
|
|
100
|
+
once(event, listener) {
|
|
101
|
+
this.events.once(event, listener);
|
|
102
|
+
}
|
|
103
|
+
removeListener(event, listener) {
|
|
104
|
+
this.events.removeListener(event, listener);
|
|
105
|
+
}
|
|
106
|
+
off(event, listener) {
|
|
107
|
+
this.events.off(event, listener);
|
|
108
|
+
}
|
|
109
|
+
get isWalletConnect() {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
registerEventListeners() {
|
|
113
|
+
this.signer.on("connect", async () => {
|
|
114
|
+
const chains = this.signer.connection.chains;
|
|
115
|
+
if (chains && chains.length)
|
|
116
|
+
this.setChainId(chains);
|
|
117
|
+
const accounts = this.signer.connection.accounts;
|
|
118
|
+
if (accounts && accounts.length)
|
|
119
|
+
this.setAccounts(accounts);
|
|
120
|
+
});
|
|
121
|
+
this.signer.connection.on(SIGNER_EVENTS.created, (session) => {
|
|
122
|
+
this.setChainId(session.permissions.blockchain.chains);
|
|
123
|
+
this.setAccounts(session.state.accounts);
|
|
124
|
+
});
|
|
125
|
+
this.signer.connection.on(SIGNER_EVENTS.updated, (session) => {
|
|
126
|
+
const chain = this.formatChainId(this.chainId);
|
|
127
|
+
if (!session.permissions.blockchain.chains.includes(chain)) {
|
|
128
|
+
this.setChainId(session.permissions.blockchain.chains);
|
|
129
|
+
}
|
|
130
|
+
if (session.state.accounts !== this.accounts) {
|
|
131
|
+
this.setAccounts(session.state.accounts);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
this.signer.connection.on(SIGNER_EVENTS.notification, (notification) => {
|
|
135
|
+
if (notification.type === providerEvents.changed.accounts) {
|
|
136
|
+
this.accounts = notification.data;
|
|
137
|
+
this.events.emit(providerEvents.changed.accounts, this.accounts);
|
|
138
|
+
}
|
|
139
|
+
else if (notification.type === providerEvents.changed.chain) {
|
|
140
|
+
this.chainId = notification.data;
|
|
141
|
+
this.events.emit(providerEvents.changed.chain, this.chainId);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.events.emit(notification.type, notification.data);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
this.signer.on("disconnect", () => {
|
|
148
|
+
this.events.emit("disconnect");
|
|
149
|
+
});
|
|
150
|
+
this.events.on(providerEvents.changed.chain, chainId => this.setHttpProvider(chainId));
|
|
151
|
+
}
|
|
152
|
+
setSignerProvider(client) {
|
|
153
|
+
const connection = new SignerConnection({
|
|
154
|
+
chains: [this.formatChainId(this.chainId)],
|
|
155
|
+
methods: this.methods,
|
|
156
|
+
client,
|
|
157
|
+
});
|
|
158
|
+
return new JsonRpcProvider(connection);
|
|
159
|
+
}
|
|
160
|
+
setHttpProvider(chainId) {
|
|
161
|
+
const rpcUrl = getRpcUrl(chainId, this.rpc);
|
|
162
|
+
if (typeof rpcUrl === "undefined")
|
|
163
|
+
return undefined;
|
|
164
|
+
const http = new JsonRpcProvider(new HttpConnection(rpcUrl));
|
|
165
|
+
return http;
|
|
166
|
+
}
|
|
167
|
+
isCompatibleChainId(chainId) {
|
|
168
|
+
return chainId.startsWith(`${this.namespace}:`);
|
|
169
|
+
}
|
|
170
|
+
formatChainId(chainId) {
|
|
171
|
+
return `${this.namespace}:${chainId}`;
|
|
172
|
+
}
|
|
173
|
+
parseChainId(chainId) {
|
|
174
|
+
return Number(chainId.split(":")[1]);
|
|
175
|
+
}
|
|
176
|
+
setChainId(chains) {
|
|
177
|
+
const compatible = chains.filter(x => this.isCompatibleChainId(x));
|
|
178
|
+
if (compatible.length) {
|
|
179
|
+
this.chainId = this.parseChainId(compatible[0]);
|
|
180
|
+
this.events.emit(providerEvents.changed.chain, this.chainId);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
parseAccountId(account) {
|
|
184
|
+
const [namespace, reference, address] = account.split(":");
|
|
185
|
+
const chainId = `${namespace}:${reference}`;
|
|
186
|
+
return { chainId, address };
|
|
187
|
+
}
|
|
188
|
+
setAccounts(accounts) {
|
|
189
|
+
this.accounts = accounts
|
|
190
|
+
.filter(x => this.parseChainId(this.parseAccountId(x).chainId) === this.chainId)
|
|
191
|
+
.map(x => this.parseAccountId(x).address);
|
|
192
|
+
this.events.emit(providerEvents.changed.accounts, this.accounts);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export default EthereumProvider;
|
|
196
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAExE,OAAO,EACL,gBAAgB,EAChB,aAAa,GAEd,MAAM,kCAAkC,CAAC;AAG1C,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,qBAAqB;IACrB,cAAc;IACd,aAAa;IACb,qBAAqB;IACrB,qBAAqB;IACrB,UAAU;IACV,mBAAmB;IACnB,eAAe;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,OAAO;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE;QACP,KAAK,EAAE,cAAc;QACrB,QAAQ,EAAE,iBAAiB;KAC5B;CACF,CAAC;AASF,MA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