@shapeshiftoss/hdwallet-walletconnect 1.23.1-alpha.0
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.md +21 -0
- package/README.md +23 -0
- package/dist/adapter.d.ts +18 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +70 -0
- package/dist/adapter.js.map +1 -0
- package/dist/ethereum.d.ts +13 -0
- package/dist/ethereum.d.ts.map +1 -0
- package/dist/ethereum.js +80 -0
- package/dist/ethereum.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/walletconnect.d.ts +127 -0
- package/dist/walletconnect.d.ts.map +1 -0
- package/dist/walletconnect.js +417 -0
- package/dist/walletconnect.js.map +1 -0
- package/package.json +26 -0
- package/src/adapter.ts +44 -0
- package/src/ethereum.ts +52 -0
- package/src/index.ts +2 -0
- package/src/walletconnect.ts +394 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.WalletConnectHDWallet = exports.WalletConnectWalletInfo = exports.isWalletConnect = void 0;
|
|
35
|
+
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
36
|
+
const isObject_1 = __importDefault(require("lodash/isObject"));
|
|
37
|
+
const eth = __importStar(require("./ethereum"));
|
|
38
|
+
function isWalletConnect(wallet) {
|
|
39
|
+
return isObject_1.default(wallet) && wallet._isWalletConnect;
|
|
40
|
+
}
|
|
41
|
+
exports.isWalletConnect = isWalletConnect;
|
|
42
|
+
/**
|
|
43
|
+
* WalletConnect Wallet Info
|
|
44
|
+
*
|
|
45
|
+
* Supported JSON-RPC API Methods:
|
|
46
|
+
* - personal_sign
|
|
47
|
+
* - eth_sign
|
|
48
|
+
* - eth_signTypedData
|
|
49
|
+
* - eth_sendTransaction
|
|
50
|
+
* - eth_signTransaction
|
|
51
|
+
* 🚧 eth_sendRawTransaction
|
|
52
|
+
* @see https://docs.walletconnect.com/
|
|
53
|
+
*/
|
|
54
|
+
class WalletConnectWalletInfo {
|
|
55
|
+
constructor() {
|
|
56
|
+
this._supportsETHInfo = true;
|
|
57
|
+
this._supportsBTCInfo = false;
|
|
58
|
+
}
|
|
59
|
+
getVendor() {
|
|
60
|
+
return "WalletConnect";
|
|
61
|
+
}
|
|
62
|
+
hasOnDevicePinEntry() {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
hasOnDevicePassphrase() {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
hasOnDeviceDisplay() {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
hasOnDeviceRecovery() {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
hasNativeShapeShift() {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
supportsOfflineSigning() {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
supportsBroadcast() {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
describePath(msg) {
|
|
84
|
+
switch (msg.coin) {
|
|
85
|
+
case "Ethereum":
|
|
86
|
+
return eth.describeETHPath(msg.path);
|
|
87
|
+
default:
|
|
88
|
+
throw new Error("Unsupported path");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
92
|
+
ethNextAccountPath(_msg) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
ethSupportsNetwork(chainId = 1) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
return chainId === 1;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
ethSupportsSecureTransfer() {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return false;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
ethSupportsNativeShapeShift() {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
ethSupportsEIP1559() {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
return false;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
ethGetAccountPaths(msg) {
|
|
114
|
+
const slip44 = core.slip44ByCoin(msg.coin);
|
|
115
|
+
if (slip44 === undefined)
|
|
116
|
+
return [];
|
|
117
|
+
return [
|
|
118
|
+
{
|
|
119
|
+
addressNList: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx, 0, 0],
|
|
120
|
+
hardenedPath: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx],
|
|
121
|
+
relPath: [0, 0],
|
|
122
|
+
description: "WalletConnect",
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.WalletConnectWalletInfo = WalletConnectWalletInfo;
|
|
128
|
+
class WalletConnectHDWallet {
|
|
129
|
+
constructor(provider) {
|
|
130
|
+
this._supportsETH = true;
|
|
131
|
+
this._supportsETHInfo = true;
|
|
132
|
+
this._supportsBTCInfo = false;
|
|
133
|
+
this._supportsBTC = false;
|
|
134
|
+
this._isWalletConnect = true;
|
|
135
|
+
this.connected = false;
|
|
136
|
+
this.chainId = -1;
|
|
137
|
+
this.accounts = [];
|
|
138
|
+
this.ethAddress = "";
|
|
139
|
+
this.provider = provider;
|
|
140
|
+
this.info = new WalletConnectWalletInfo();
|
|
141
|
+
}
|
|
142
|
+
getFeatures() {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
return {};
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
isLocked() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
return false;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
getVendor() {
|
|
153
|
+
return "WalletConnect";
|
|
154
|
+
}
|
|
155
|
+
getModel() {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
return "WalletConnect";
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
getLabel() {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
return "WalletConnect";
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Initialize
|
|
167
|
+
*
|
|
168
|
+
* Subscribes to EIP-1193 events
|
|
169
|
+
*/
|
|
170
|
+
initialize() {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
this.provider.connector.on("session_update", (error, payload) => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
if (error) {
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
const { chainId, accounts } = payload.params[0];
|
|
177
|
+
this.onSessionUpdate(accounts, chainId);
|
|
178
|
+
}));
|
|
179
|
+
this.provider.connector.on("connect", (error, payload) => {
|
|
180
|
+
if (error) {
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
this.onConnect(payload);
|
|
184
|
+
});
|
|
185
|
+
this.provider.connector.on("disconnect", (error) => {
|
|
186
|
+
if (error) {
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
this.onDisconnect();
|
|
190
|
+
});
|
|
191
|
+
// Display QR modal to connect
|
|
192
|
+
yield this.provider.enable();
|
|
193
|
+
if (this.provider.connector.connected) {
|
|
194
|
+
const { chainId, accounts } = this.provider.connector;
|
|
195
|
+
const [address] = accounts;
|
|
196
|
+
this.setState({ connected: true, chainId, accounts, address });
|
|
197
|
+
this.onSessionUpdate(accounts, chainId);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
hasOnDevicePinEntry() {
|
|
202
|
+
return this.info.hasOnDevicePinEntry();
|
|
203
|
+
}
|
|
204
|
+
hasOnDevicePassphrase() {
|
|
205
|
+
return this.info.hasOnDevicePassphrase();
|
|
206
|
+
}
|
|
207
|
+
hasOnDeviceDisplay() {
|
|
208
|
+
return this.info.hasOnDeviceDisplay();
|
|
209
|
+
}
|
|
210
|
+
hasOnDeviceRecovery() {
|
|
211
|
+
return this.info.hasOnDeviceRecovery();
|
|
212
|
+
}
|
|
213
|
+
hasNativeShapeShift(srcCoin, dstCoin) {
|
|
214
|
+
return this.info.hasNativeShapeShift(srcCoin, dstCoin);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Supports Offline Signing
|
|
218
|
+
*
|
|
219
|
+
* Offline signing is supported when `signTransaction` does not broadcast
|
|
220
|
+
* the tx message. WalletConnect's core Connector implementation always
|
|
221
|
+
* makes a request, so offline signing is not supported.
|
|
222
|
+
* @see https://github.com/WalletConnect/walletconnect-monorepo/blob/7573fa9e1d91588d4af3409159b4fd2f9448a0e2/packages/clients/core/src/index.ts#L630
|
|
223
|
+
*/
|
|
224
|
+
supportsOfflineSigning() {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
supportsBroadcast() {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
clearSession() {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
this.disconnect();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
ping(msg) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
// ping function for Wallet Connect?
|
|
238
|
+
return { msg: msg.msg };
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
242
|
+
sendPin(_pin) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
// no concept of pin in WalletConnect
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
248
|
+
sendPassphrase(_passphrase) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
// cannot send passphrase. Could show the widget?
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
254
|
+
sendCharacter(_character) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
// no concept of sendCharacter
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
260
|
+
sendWord(_word) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
// no concept of sendWord
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
cancel() {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
// no concept of cancel
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
wipe() {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
return;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
276
|
+
reset(_msg) {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
return;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
282
|
+
recover(_msg) {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
// no concept of recover
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
288
|
+
loadDevice(_msg) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
return;
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
describePath(msg) {
|
|
294
|
+
return this.info.describePath(msg);
|
|
295
|
+
}
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
297
|
+
getPublicKeys(_msg) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
// Ethereum public keys are not exposed by the RPC API
|
|
300
|
+
return [];
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
isInitialized() {
|
|
304
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
return true;
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
disconnect() {
|
|
309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
this.provider.disconnect();
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
ethSupportsNetwork(chainId = 1) {
|
|
314
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
315
|
+
return chainId === 1;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
ethSupportsSecureTransfer() {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
return false;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
ethSupportsNativeShapeShift() {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
ethSupportsEIP1559() {
|
|
327
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
328
|
+
return false;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
ethGetAccountPaths(msg) {
|
|
332
|
+
return this.info.ethGetAccountPaths(msg);
|
|
333
|
+
}
|
|
334
|
+
ethNextAccountPath(msg) {
|
|
335
|
+
return this.info.ethNextAccountPath(msg);
|
|
336
|
+
}
|
|
337
|
+
ethGetAddress() {
|
|
338
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
339
|
+
return this.ethAddress;
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Ethereum Signed Transaction
|
|
344
|
+
*
|
|
345
|
+
* @see https://docs.walletconnect.com/client-api#sign-transaction-eth_signtransaction
|
|
346
|
+
*/
|
|
347
|
+
ethSignTx(msg) {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
return eth.ethSignTx(Object.assign(Object.assign({}, msg), { from: this.ethAddress }), this.provider);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Ethereum Send Transaction
|
|
354
|
+
*
|
|
355
|
+
* @see https://docs.walletconnect.com/client-api#send-transaction-eth_sendtransaction
|
|
356
|
+
*/
|
|
357
|
+
ethSendTx(msg) {
|
|
358
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
+
return eth.ethSendTx(Object.assign(Object.assign({}, msg), { from: this.ethAddress }), this.provider);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Ethereum Sign Message
|
|
364
|
+
*
|
|
365
|
+
* @see https://docs.walletconnect.com/client-api#sign-message-eth_sign
|
|
366
|
+
*/
|
|
367
|
+
ethSignMessage(msg) {
|
|
368
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
369
|
+
return eth.ethSignMessage({ data: msg.message, fromAddress: this.ethAddress }, this.provider);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
373
|
+
ethVerifyMessage(msg) {
|
|
374
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
375
|
+
console.error("Method ethVerifyMessage unsupported for WalletConnect wallet!");
|
|
376
|
+
return null;
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
getDeviceID() {
|
|
380
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
381
|
+
return "wc:" + (yield this.ethGetAddress());
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
getFirmwareVersion() {
|
|
385
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
+
return "WalletConnect";
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
onConnect(payload) {
|
|
390
|
+
const { accounts, chainId } = payload.params[0];
|
|
391
|
+
const [address] = accounts;
|
|
392
|
+
this.setState({ connected: true, chainId, accounts, address });
|
|
393
|
+
}
|
|
394
|
+
onSessionUpdate(accounts, chainId) {
|
|
395
|
+
const [address] = accounts;
|
|
396
|
+
this.setState({ accounts, address, chainId });
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* onDisconnect
|
|
400
|
+
*
|
|
401
|
+
* Resets state
|
|
402
|
+
*/
|
|
403
|
+
onDisconnect() {
|
|
404
|
+
this.setState({ connected: false, chainId: 1, accounts: [], address: "" });
|
|
405
|
+
}
|
|
406
|
+
setState(config) {
|
|
407
|
+
const { connected, chainId, accounts, address } = config;
|
|
408
|
+
if (connected !== undefined) {
|
|
409
|
+
this.connected = connected;
|
|
410
|
+
}
|
|
411
|
+
this.chainId = chainId;
|
|
412
|
+
this.accounts = accounts;
|
|
413
|
+
this.ethAddress = address;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
exports.WalletConnectHDWallet = WalletConnectHDWallet;
|
|
417
|
+
//# sourceMappingURL=walletconnect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletconnect.js","sourceRoot":"","sources":["../src/walletconnect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAAqD;AAErD,+DAAuC;AAEvC,gDAAkC;AASlC,SAAgB,eAAe,CAAC,MAAqB;IACnD,OAAO,kBAAQ,CAAC,MAAM,CAAC,IAAK,MAAc,CAAC,gBAAgB,CAAC;AAC9D,CAAC;AAFD,0CAEC;AAED;;;;;;;;;;;GAWG;AACH,MAAa,uBAAuB;IAApC;QACW,qBAAgB,GAAG,IAAI,CAAC;QACxB,qBAAgB,GAAG,KAAK,CAAC;IA2EpC,CAAC;IA1EQ,SAAS;QACd,OAAO,eAAe,CAAC;IACzB,CAAC;IAEM,mBAAmB;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,qBAAqB;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,kBAAkB;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,mBAAmB;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DA6RC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shapeshiftoss/hdwallet-walletconnect",
|
|
3
|
+
"version": "1.23.1-alpha.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"source": "src/index.ts",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc --build",
|
|
13
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
14
|
+
"prepublishOnly": "yarn clean && yarn build"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@shapeshiftoss/hdwallet-core": "1.22.0",
|
|
18
|
+
"@walletconnect/qrcode-modal": "^1.7.8",
|
|
19
|
+
"@walletconnect/web3-provider": "^1.7.8",
|
|
20
|
+
"ethers": "^5.6.5"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^4.3.2"
|
|
24
|
+
},
|
|
25
|
+
"gitHead": "d9956921202d57707940ac2a8c43b0ab51e5dd9e"
|
|
26
|
+
}
|
package/src/adapter.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
2
|
+
import WalletConnectProvider from "@walletconnect/web3-provider";
|
|
3
|
+
|
|
4
|
+
import { WalletConnectHDWallet } from "./walletconnect";
|
|
5
|
+
|
|
6
|
+
type WalletConnectConfig =
|
|
7
|
+
| {
|
|
8
|
+
infuraId: string;
|
|
9
|
+
}
|
|
10
|
+
| { rpc: { [key: number]: string } };
|
|
11
|
+
|
|
12
|
+
export class WalletConnectAdapter {
|
|
13
|
+
keyring: core.Keyring;
|
|
14
|
+
|
|
15
|
+
private constructor(keyring: core.Keyring) {
|
|
16
|
+
this.keyring = keyring;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static useKeyring(keyring: core.Keyring) {
|
|
20
|
+
return new WalletConnectAdapter(keyring);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async initialize(): Promise<number> {
|
|
24
|
+
return Object.keys(this.keyring.wallets).length;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async pairDevice(config: WalletConnectConfig): Promise<WalletConnectHDWallet> {
|
|
28
|
+
try {
|
|
29
|
+
const provider = new WalletConnectProvider(config);
|
|
30
|
+
const wallet = new WalletConnectHDWallet(provider);
|
|
31
|
+
|
|
32
|
+
// Enable session (triggers QR Code modal)
|
|
33
|
+
await wallet.initialize();
|
|
34
|
+
|
|
35
|
+
const deviceID = await wallet.getDeviceID();
|
|
36
|
+
this.keyring.add(wallet, deviceID);
|
|
37
|
+
this.keyring.emit(["WalletConnect", deviceID, core.Events.CONNECT], deviceID);
|
|
38
|
+
return wallet;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("Could not pair WalletConnect");
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/ethereum.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
2
|
+
|
|
3
|
+
export function describeETHPath(path: core.BIP32Path): core.PathDescription {
|
|
4
|
+
const pathStr = core.addressNListToBIP32(path);
|
|
5
|
+
const unknown: core.PathDescription = {
|
|
6
|
+
verbose: pathStr,
|
|
7
|
+
coin: "Ethereum",
|
|
8
|
+
isKnown: false,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (path.length !== 5) return unknown;
|
|
12
|
+
|
|
13
|
+
if (path[0] !== 0x80000000 + 44) return unknown;
|
|
14
|
+
|
|
15
|
+
if (path[1] !== 0x80000000 + core.slip44ByCoin("Ethereum")) return unknown;
|
|
16
|
+
|
|
17
|
+
if ((path[2] & 0x80000000) >>> 0 !== 0x80000000) return unknown;
|
|
18
|
+
|
|
19
|
+
if (path[3] !== 0) return unknown;
|
|
20
|
+
|
|
21
|
+
if (path[4] !== 0) return unknown;
|
|
22
|
+
|
|
23
|
+
const index = path[2] & 0x7fffffff;
|
|
24
|
+
return {
|
|
25
|
+
verbose: `Ethereum Account #${index}`,
|
|
26
|
+
accountIdx: index,
|
|
27
|
+
wholeAccount: true,
|
|
28
|
+
coin: "Ethereum",
|
|
29
|
+
isKnown: true,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function ethSignTx(
|
|
34
|
+
args: core.ETHSignTx & { from: string },
|
|
35
|
+
provider: any
|
|
36
|
+
): Promise<core.ETHSignedTx | null> {
|
|
37
|
+
return await provider.wc.signTransaction(args);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function ethSendTx(
|
|
41
|
+
args: core.ETHSignTx & { from: string },
|
|
42
|
+
provider: any
|
|
43
|
+
): Promise<core.ETHTxHash | null> {
|
|
44
|
+
return await provider.wc.sendTransaction(args);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function ethSignMessage(
|
|
48
|
+
args: { data: string; fromAddress: string },
|
|
49
|
+
provider: any
|
|
50
|
+
): Promise<core.ETHSignedMessage | null> {
|
|
51
|
+
return await provider.wc.signMessage([Buffer.from(args.data).toString("hex"), args.fromAddress]);
|
|
52
|
+
}
|
package/src/index.ts
ADDED