@shapeshiftoss/hdwallet-portis 1.55.2 → 1.55.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/adapter.js +64 -104
- package/dist/adapter.js.map +1 -1
- package/dist/bitcoin.js +72 -133
- package/dist/bitcoin.js.map +1 -1
- package/dist/ethereum.js +30 -76
- package/dist/ethereum.js.map +1 -1
- package/dist/index.js +2 -18
- package/dist/index.js.map +1 -1
- package/dist/portis.js +141 -264
- package/dist/portis.js.map +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
package/dist/adapter.js
CHANGED
|
@@ -1,47 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.PortisAdapter = void 0;
|
|
39
|
-
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
40
|
-
const p_lazy_1 = __importDefault(require("p-lazy"));
|
|
41
|
-
const portis_1 = require("./portis");
|
|
42
|
-
const Portis = p_lazy_1.default.from(() => __awaiter(void 0, void 0, void 0, function* () { return (yield Promise.resolve().then(() => __importStar(require("@portis/web3")))).default; }));
|
|
1
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
2
|
+
import PLazy from "p-lazy";
|
|
3
|
+
import { PortisHDWallet } from "./portis";
|
|
4
|
+
const Portis = PLazy.from(async () => (await import("@portis/web3")).default);
|
|
43
5
|
const INACTIVITY_LOGOUT_TIME = 10 * 60 * 1000;
|
|
44
|
-
class PortisAdapter {
|
|
6
|
+
export class PortisAdapter {
|
|
7
|
+
keyring;
|
|
8
|
+
portis;
|
|
9
|
+
portisAppId;
|
|
10
|
+
/// wallet id to remove from the keyring when the active wallet changes
|
|
11
|
+
currentDeviceId;
|
|
45
12
|
constructor(keyring, args) {
|
|
46
13
|
this.portis = args.portis;
|
|
47
14
|
this.portisAppId = args.portisAppId;
|
|
@@ -50,74 +17,67 @@ class PortisAdapter {
|
|
|
50
17
|
static useKeyring(keyring, args) {
|
|
51
18
|
return new PortisAdapter(keyring, args);
|
|
52
19
|
}
|
|
53
|
-
initialize() {
|
|
54
|
-
return
|
|
55
|
-
return Object.keys(this.keyring.wallets).length;
|
|
56
|
-
});
|
|
20
|
+
async initialize() {
|
|
21
|
+
return Object.keys(this.keyring.wallets).length;
|
|
57
22
|
}
|
|
58
|
-
pairDevice() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (!this.currentDeviceId || walletAddress.toLowerCase() !== this.currentDeviceId.toLowerCase()) {
|
|
66
|
-
const currentDeviceId = this.currentDeviceId;
|
|
67
|
-
if (currentDeviceId) {
|
|
68
|
-
this.keyring.emit(["Portis", currentDeviceId, core.Events.DISCONNECT], currentDeviceId);
|
|
69
|
-
this.keyring.remove(currentDeviceId);
|
|
70
|
-
}
|
|
71
|
-
this.pairPortisDevice();
|
|
72
|
-
}
|
|
73
|
-
}));
|
|
74
|
-
this.portis.onLogout(() => {
|
|
23
|
+
async pairDevice() {
|
|
24
|
+
try {
|
|
25
|
+
const wallet = await this.pairPortisDevice();
|
|
26
|
+
this.portis.onActiveWalletChanged(async (wallAddr) => {
|
|
27
|
+
// check if currentDeviceId has changed
|
|
28
|
+
const walletAddress = "portis:" + wallAddr;
|
|
29
|
+
if (!this.currentDeviceId || walletAddress.toLowerCase() !== this.currentDeviceId.toLowerCase()) {
|
|
75
30
|
const currentDeviceId = this.currentDeviceId;
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return wallet;
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
if (core.isIndexable(e) && String(e.message).includes("User denied login.")) {
|
|
85
|
-
throw new core.ActionCancelled();
|
|
31
|
+
if (currentDeviceId) {
|
|
32
|
+
this.keyring.emit(["Portis", currentDeviceId, core.Events.DISCONNECT], currentDeviceId);
|
|
33
|
+
this.keyring.remove(currentDeviceId);
|
|
34
|
+
}
|
|
35
|
+
this.pairPortisDevice();
|
|
86
36
|
}
|
|
87
|
-
|
|
37
|
+
});
|
|
38
|
+
this.portis.onLogout(() => {
|
|
39
|
+
const currentDeviceId = this.currentDeviceId;
|
|
40
|
+
if (!currentDeviceId)
|
|
41
|
+
return;
|
|
42
|
+
this.keyring.emit(["Portis", currentDeviceId, core.Events.DISCONNECT], currentDeviceId);
|
|
43
|
+
this.keyring.remove(currentDeviceId);
|
|
44
|
+
});
|
|
45
|
+
return wallet;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
if (core.isIndexable(e) && String(e.message).includes("User denied login.")) {
|
|
49
|
+
throw new core.ActionCancelled();
|
|
88
50
|
}
|
|
89
|
-
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
90
53
|
}
|
|
91
|
-
pairPortisDevice() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
54
|
+
async pairPortisDevice() {
|
|
55
|
+
this.portis = new (await Portis)(this.portisAppId, "mainnet");
|
|
56
|
+
const wallet = new PortisHDWallet(this.portis);
|
|
57
|
+
await wallet.initialize();
|
|
58
|
+
const deviceId = await wallet.getDeviceID();
|
|
59
|
+
this.keyring.add(wallet, deviceId);
|
|
60
|
+
this.currentDeviceId = deviceId;
|
|
61
|
+
this.keyring.emit(["Portis", deviceId, core.Events.CONNECT], deviceId);
|
|
62
|
+
const watchForInactivity = () => {
|
|
63
|
+
let time;
|
|
64
|
+
const resetTimer = () => {
|
|
65
|
+
clearTimeout(time);
|
|
66
|
+
time = setTimeout(() => {
|
|
67
|
+
window.onload = null;
|
|
68
|
+
document.onmousemove = null;
|
|
69
|
+
document.onkeypress = null;
|
|
103
70
|
clearTimeout(time);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
document.onmousemove = null;
|
|
107
|
-
document.onkeypress = null;
|
|
108
|
-
clearTimeout(time);
|
|
109
|
-
this.portis.logout();
|
|
110
|
-
}, INACTIVITY_LOGOUT_TIME);
|
|
111
|
-
};
|
|
112
|
-
window.onload = resetTimer;
|
|
113
|
-
document.onmousemove = resetTimer;
|
|
114
|
-
document.onkeypress = resetTimer;
|
|
115
|
-
resetTimer();
|
|
71
|
+
this.portis.logout();
|
|
72
|
+
}, INACTIVITY_LOGOUT_TIME);
|
|
116
73
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
74
|
+
window.onload = resetTimer;
|
|
75
|
+
document.onmousemove = resetTimer;
|
|
76
|
+
document.onkeypress = resetTimer;
|
|
77
|
+
resetTimer();
|
|
78
|
+
};
|
|
79
|
+
watchForInactivity();
|
|
80
|
+
return wallet;
|
|
120
81
|
}
|
|
121
82
|
}
|
|
122
|
-
exports.PortisAdapter = PortisAdapter;
|
|
123
83
|
//# sourceMappingURL=adapter.js.map
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AACrD,OAAO,KAAK,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAI9E,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9C,MAAM,OAAO,aAAa;IACxB,OAAO,CAAe;IACtB,MAAM,CAAM;IACZ,WAAW,CAAS;IAEpB,uEAAuE;IACvE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AAG,GAAG,EAAE;YAC9B,IAAI,IAAmC,CAAC;YACxC,MAAM,UAAU,GAAG,GAAG,EAAE;gBACtB,YAAY,CAAC,IAAI,CAAC,CAAC;gBACnB,IAAI,GAAG,UAAU,CAAC,GAAG,EAAE;oBACrB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;oBACrB,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC;oBAC5B,QAAQ,CAAC,UAAU,GAAG,IAAI,CAAC;oBAC3B,YAAY,CAAC,IAAI,CAAC,CAAC;oBACnB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBACvB,CAAC,EAAE,sBAAsB,CAAC,CAAC;YAC7B,CAAC,CAAC;YACF,MAAM,CAAC,MAAM,GAAG,UAAU,CAAC;YAC3B,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC;YAClC,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;YACjC,UAAU,EAAE,CAAC;QACf,CAAC,CAAC;QAEF,kBAAkB,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
package/dist/bitcoin.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.btcVerifyMessage = exports.btcSignTx = exports.btcSupportsCoin = exports.btcSupportsScriptType = exports.btcGetAccountPaths = exports.btcNextAccountPath = exports.segwitNativeAccount = exports.segwitAccount = exports.legacyAccount = exports.btcGetAddress = exports.verifyScriptTypePurpose = exports.describeUTXOPath = void 0;
|
|
39
|
-
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
40
|
-
const base64_js_1 = __importDefault(require("base64-js"));
|
|
41
|
-
const bip32 = __importStar(require("bip32"));
|
|
42
|
-
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
43
|
-
const bitcoinMsg = __importStar(require("bitcoinjs-message"));
|
|
44
|
-
function describeUTXOPath(path, coin, scriptType) {
|
|
45
|
-
var _a;
|
|
1
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
2
|
+
import Base64 from "base64-js";
|
|
3
|
+
import * as bip32 from "bip32";
|
|
4
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
5
|
+
import * as bitcoinMsg from "bitcoinjs-message";
|
|
6
|
+
export function describeUTXOPath(path, coin, scriptType) {
|
|
46
7
|
const pathStr = core.addressNListToBIP32(path);
|
|
47
8
|
const unknown = {
|
|
48
9
|
verbose: pathStr,
|
|
@@ -65,11 +26,11 @@ function describeUTXOPath(path, coin, scriptType) {
|
|
|
65
26
|
return unknown;
|
|
66
27
|
const wholeAccount = path.length === 3;
|
|
67
28
|
const script = scriptType
|
|
68
|
-
?
|
|
29
|
+
? {
|
|
69
30
|
[core.BTCInputScriptType.SpendAddress]: ["Legacy"],
|
|
70
31
|
[core.BTCInputScriptType.SpendP2SHWitness]: [],
|
|
71
32
|
[core.BTCInputScriptType.SpendWitness]: ["Segwit Native"],
|
|
72
|
-
}[scriptType]
|
|
33
|
+
}[scriptType] ?? []
|
|
73
34
|
: [];
|
|
74
35
|
let isPrefork = false;
|
|
75
36
|
const slip44 = core.slip44ByCoin(coin);
|
|
@@ -138,81 +99,72 @@ function describeUTXOPath(path, coin, scriptType) {
|
|
|
138
99
|
};
|
|
139
100
|
}
|
|
140
101
|
}
|
|
141
|
-
|
|
142
|
-
function verifyScriptTypePurpose(scriptType, purpose) {
|
|
102
|
+
export function verifyScriptTypePurpose(scriptType, purpose) {
|
|
143
103
|
return ((purpose === 0x80000000 + 44 && scriptType === core.BTCInputScriptType.SpendAddress) ||
|
|
144
104
|
(purpose === 0x80000000 + 49 && scriptType === core.BTCInputScriptType.SpendP2SHWitness) ||
|
|
145
105
|
(purpose === 0x80000000 + 84 && scriptType === core.BTCInputScriptType.SpendWitness));
|
|
146
106
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (!verifyScriptTypePurpose(scriptType, purpose)) {
|
|
178
|
-
throw new Error(`Invalid scriptType ${scriptType} for purpose ${purpose}`);
|
|
179
|
-
}
|
|
180
|
-
portis.showBitcoinWallet(core.addressNListToBIP32(msg.addressNList));
|
|
107
|
+
export async function btcGetAddress(msg, portis) {
|
|
108
|
+
if (!msg.addressNList.length)
|
|
109
|
+
throw new Error("Empty addressNList");
|
|
110
|
+
const scriptType = msg.scriptType;
|
|
111
|
+
const purpose = msg.addressNList[0];
|
|
112
|
+
const hardPath = core.hardenedPath(msg.addressNList);
|
|
113
|
+
const hardPathString = core.addressNListToBIP32(hardPath);
|
|
114
|
+
const { result: xpub } = await portis.getExtendedPublicKey(hardPathString, "Bitcoin");
|
|
115
|
+
const relPath = core.relativePath(msg.addressNList);
|
|
116
|
+
const relPathString = core.addressNListToBIP32(relPath).substr(2);
|
|
117
|
+
const args = { pubkey: bip32.fromBase58(xpub).derivePath(relPathString).publicKey };
|
|
118
|
+
let result;
|
|
119
|
+
switch (scriptType) {
|
|
120
|
+
case core.BTCInputScriptType.SpendAddress:
|
|
121
|
+
result = bitcoin.payments.p2pkh(args);
|
|
122
|
+
break;
|
|
123
|
+
case core.BTCInputScriptType.SpendWitness:
|
|
124
|
+
result = bitcoin.payments.p2wpkh(args);
|
|
125
|
+
break;
|
|
126
|
+
case core.BTCInputScriptType.SpendP2SHWitness:
|
|
127
|
+
result = bitcoin.payments.p2sh({
|
|
128
|
+
redeem: bitcoin.payments.p2wpkh(args),
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
throw new Error(`Unsupported scriptType ${scriptType}`);
|
|
133
|
+
}
|
|
134
|
+
if (msg.showDisplay === true) {
|
|
135
|
+
if (!verifyScriptTypePurpose(scriptType, purpose)) {
|
|
136
|
+
throw new Error(`Invalid scriptType ${scriptType} for purpose ${purpose}`);
|
|
181
137
|
}
|
|
182
|
-
|
|
183
|
-
}
|
|
138
|
+
portis.showBitcoinWallet(core.addressNListToBIP32(msg.addressNList));
|
|
139
|
+
}
|
|
140
|
+
return core.mustBeDefined(result.address);
|
|
184
141
|
}
|
|
185
|
-
|
|
186
|
-
function legacyAccount(coin, slip44, accountIdx) {
|
|
142
|
+
export function legacyAccount(coin, slip44, accountIdx) {
|
|
187
143
|
return {
|
|
188
144
|
coin,
|
|
189
145
|
scriptType: core.BTCInputScriptType.SpendAddress,
|
|
190
146
|
addressNList: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + accountIdx],
|
|
191
147
|
};
|
|
192
148
|
}
|
|
193
|
-
|
|
194
|
-
function segwitAccount(coin, slip44, accountIdx) {
|
|
149
|
+
export function segwitAccount(coin, slip44, accountIdx) {
|
|
195
150
|
return {
|
|
196
151
|
coin,
|
|
197
152
|
scriptType: core.BTCInputScriptType.SpendP2SHWitness,
|
|
198
153
|
addressNList: [0x80000000 + 49, 0x80000000 + slip44, 0x80000000 + accountIdx],
|
|
199
154
|
};
|
|
200
155
|
}
|
|
201
|
-
|
|
202
|
-
function segwitNativeAccount(coin, slip44, accountIdx) {
|
|
156
|
+
export function segwitNativeAccount(coin, slip44, accountIdx) {
|
|
203
157
|
return {
|
|
204
158
|
coin,
|
|
205
159
|
scriptType: core.BTCInputScriptType.SpendWitness,
|
|
206
160
|
addressNList: [0x80000000 + 84, 0x80000000 + slip44, 0x80000000 + accountIdx],
|
|
207
161
|
};
|
|
208
162
|
}
|
|
209
|
-
exports.segwitNativeAccount = segwitNativeAccount;
|
|
210
163
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
211
|
-
function btcNextAccountPath(msg) {
|
|
164
|
+
export function btcNextAccountPath(msg) {
|
|
212
165
|
return undefined;
|
|
213
166
|
}
|
|
214
|
-
|
|
215
|
-
function btcGetAccountPaths(msg) {
|
|
167
|
+
export function btcGetAccountPaths(msg) {
|
|
216
168
|
const slip44 = core.slip44ByCoin(msg.coin);
|
|
217
169
|
if (slip44 == undefined)
|
|
218
170
|
return [];
|
|
@@ -228,47 +180,34 @@ function btcGetAccountPaths(msg) {
|
|
|
228
180
|
});
|
|
229
181
|
return paths;
|
|
230
182
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
case core.BTCInputScriptType.SpendWitness:
|
|
239
|
-
case core.BTCInputScriptType.SpendP2SHWitness:
|
|
240
|
-
return true;
|
|
241
|
-
default:
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
exports.btcSupportsScriptType = btcSupportsScriptType;
|
|
247
|
-
function btcSupportsCoin(coin) {
|
|
248
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
if (coin === "Bitcoin")
|
|
183
|
+
export async function btcSupportsScriptType(coin, scriptType) {
|
|
184
|
+
if (coin !== "Bitcoin")
|
|
185
|
+
return Promise.resolve(false);
|
|
186
|
+
switch (scriptType) {
|
|
187
|
+
case core.BTCInputScriptType.SpendAddress:
|
|
188
|
+
case core.BTCInputScriptType.SpendWitness:
|
|
189
|
+
case core.BTCInputScriptType.SpendP2SHWitness:
|
|
250
190
|
return true;
|
|
251
|
-
|
|
191
|
+
default:
|
|
252
192
|
return false;
|
|
253
|
-
}
|
|
193
|
+
}
|
|
254
194
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
195
|
+
export async function btcSupportsCoin(coin) {
|
|
196
|
+
if (coin === "Bitcoin")
|
|
197
|
+
return true;
|
|
198
|
+
else
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
export async function btcSignTx(msg, portis) {
|
|
202
|
+
const { result } = await portis.signBitcoinTransaction(msg);
|
|
203
|
+
return {
|
|
204
|
+
// TODO: parse signatures out of serializedTx
|
|
205
|
+
signatures: core.untouchable("not implemented"),
|
|
206
|
+
serializedTx: result.serializedTx,
|
|
207
|
+
};
|
|
265
208
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return
|
|
269
|
-
const signature = base64_js_1.default.fromByteArray(core.fromHexString(msg.signature));
|
|
270
|
-
return bitcoinMsg.verify(msg.message, msg.address, signature);
|
|
271
|
-
});
|
|
209
|
+
export async function btcVerifyMessage(msg) {
|
|
210
|
+
const signature = Base64.fromByteArray(core.fromHexString(msg.signature));
|
|
211
|
+
return bitcoinMsg.verify(msg.message, msg.address, signature);
|
|
272
212
|
}
|
|
273
|
-
exports.btcVerifyMessage = btcVerifyMessage;
|
|
274
213
|
//# sourceMappingURL=bitcoin.js.map
|
package/dist/bitcoin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin.js","sourceRoot":"","sources":["../src/bitcoin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bitcoin.js","sourceRoot":"","sources":["../src/bitcoin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AACrD,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,MAAM,UAAU,gBAAgB,CAC9B,IAAoB,EACpB,IAAe,EACf,UAAoC;IAEpC,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAyB;QACpC,OAAO,EAAE,OAAO;QAChB,I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AAC;QACnB,KAAK,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC;QAC1C,KAAK,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC;QAC1C,KAAK,IAAI,CAAC,kBAAkB,CAAC,gBAAgB;YAC3C,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAe;IACnD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;;QAC/B,OAAO,KAAK,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAmB,EAAE,MAAW;IAC9D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC5D,OAAO;QACL,6CAA6C;QAC7C,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC;QAC/C,YAAY,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAA0B;IAC/D,MAAM,SAAS,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1E,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/ethereum.js
CHANGED
|
@@ -1,41 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.ethSignMessage = exports.ethSignTx = exports.ethGetAccountPaths = exports.ethVerifyMessage = exports.describeETHPath = void 0;
|
|
36
|
-
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
37
|
-
const utils_1 = require("ethers/lib/utils");
|
|
38
|
-
function describeETHPath(path) {
|
|
1
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
2
|
+
import { isHexString } from "ethers/lib/utils";
|
|
3
|
+
export function describeETHPath(path) {
|
|
39
4
|
const pathStr = core.addressNListToBIP32(path);
|
|
40
5
|
const unknown = {
|
|
41
6
|
verbose: pathStr,
|
|
@@ -63,15 +28,11 @@ function describeETHPath(path) {
|
|
|
63
28
|
isKnown: true,
|
|
64
29
|
};
|
|
65
30
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
const signingAddress = yield web3.eth.accounts.recover(msg.message, "0x" + msg.signature, false);
|
|
70
|
-
return signingAddress === msg.address;
|
|
71
|
-
});
|
|
31
|
+
export async function ethVerifyMessage(msg, web3) {
|
|
32
|
+
const signingAddress = await web3.eth.accounts.recover(msg.message, "0x" + msg.signature, false);
|
|
33
|
+
return signingAddress === msg.address;
|
|
72
34
|
}
|
|
73
|
-
|
|
74
|
-
function ethGetAccountPaths(msg) {
|
|
35
|
+
export function ethGetAccountPaths(msg) {
|
|
75
36
|
const slip44 = core.slip44ByCoin(msg.coin);
|
|
76
37
|
if (slip44 === undefined)
|
|
77
38
|
return [];
|
|
@@ -84,37 +45,30 @@ function ethGetAccountPaths(msg) {
|
|
|
84
45
|
},
|
|
85
46
|
];
|
|
86
47
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
data: msg.data,
|
|
97
|
-
nonce: msg.nonce,
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
v: result.tx.v,
|
|
101
|
-
r: result.tx.r,
|
|
102
|
-
s: result.tx.s,
|
|
103
|
-
serialized: result.raw,
|
|
104
|
-
};
|
|
48
|
+
export async function ethSignTx(msg, web3, from) {
|
|
49
|
+
const result = await web3.eth.signTransaction({
|
|
50
|
+
from,
|
|
51
|
+
to: msg.to,
|
|
52
|
+
value: msg.value,
|
|
53
|
+
gas: msg.gasLimit,
|
|
54
|
+
gasPrice: msg.gasPrice,
|
|
55
|
+
data: msg.data,
|
|
56
|
+
nonce: msg.nonce,
|
|
105
57
|
});
|
|
58
|
+
return {
|
|
59
|
+
v: result.tx.v,
|
|
60
|
+
r: result.tx.r,
|
|
61
|
+
s: result.tx.s,
|
|
62
|
+
serialized: result.raw,
|
|
63
|
+
};
|
|
106
64
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
signature: result,
|
|
116
|
-
};
|
|
117
|
-
});
|
|
65
|
+
export async function ethSignMessage(msg, web3, address) {
|
|
66
|
+
if (!isHexString(msg.message))
|
|
67
|
+
throw new Error("data is not an hex string");
|
|
68
|
+
const result = await web3.eth.sign(msg.message, address);
|
|
69
|
+
return {
|
|
70
|
+
address,
|
|
71
|
+
signature: result,
|
|
72
|
+
};
|
|
118
73
|
}
|
|
119
|
-
exports.ethSignMessage = ethSignMessage;
|
|
120
74
|
//# sourceMappingURL=ethereum.js.map
|