@shapeshiftoss/hdwallet-ledger 1.55.2 → 1.55.4-alpha.1

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/cosmos.js CHANGED
@@ -1,61 +1,22 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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
- 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.cosmosSignTx = exports.cosmosGetAddress = void 0;
39
- const crypto_1 = require("@cosmjs/crypto");
40
- const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
41
- const base64_js_1 = require("base64-js");
42
- const p_lazy_1 = __importDefault(require("p-lazy"));
43
- const utils_1 = require("./utils");
44
- const protoTxBuilder = p_lazy_1.default.from(() => Promise.resolve().then(() => __importStar(require("@shapeshiftoss/proto-tx-builder"))));
1
+ import { Secp256k1Signature } from "@cosmjs/crypto";
2
+ import * as core from "@shapeshiftoss/hdwallet-core";
3
+ import { fromByteArray } from "base64-js";
4
+ import PLazy from "p-lazy";
5
+ import { handleError, stringifyKeysInOrder } from "./utils";
6
+ const protoTxBuilder = PLazy.from(() => import("@shapeshiftoss/proto-tx-builder"));
45
7
  const ATOM_CHAIN = "cosmoshub-4";
46
- const cosmosGetAddress = (transport, msg) => __awaiter(void 0, void 0, void 0, function* () {
8
+ export const cosmosGetAddress = async (transport, msg) => {
47
9
  const bip32path = core.addressNListToBIP32(msg.addressNList);
48
- const res = yield transport.call("Cosmos", "getAddress", bip32path, "cosmos");
49
- (0, utils_1.handleError)(res, transport, "Unable to obtain address from device.");
10
+ const res = await transport.call("Cosmos", "getAddress", bip32path, "cosmos");
11
+ handleError(res, transport, "Unable to obtain address from device.");
50
12
  return res.payload.address;
51
- });
52
- exports.cosmosGetAddress = cosmosGetAddress;
53
- const cosmosSignTx = (transport, msg) => __awaiter(void 0, void 0, void 0, function* () {
13
+ };
14
+ export const cosmosSignTx = async (transport, msg) => {
54
15
  const bip32path = core.addressNListToBIP32(msg.addressNList);
55
- const getAddressResponse = yield transport.call("Cosmos", "getAddress", bip32path, "cosmos");
56
- (0, utils_1.handleError)(getAddressResponse, transport, "Unable to obtain address and public key from device.");
16
+ const getAddressResponse = await transport.call("Cosmos", "getAddress", bip32path, "cosmos");
17
+ handleError(getAddressResponse, transport, "Unable to obtain address and public key from device.");
57
18
  const { address, publicKey } = getAddressResponse.payload;
58
- const unsignedTx = (0, utils_1.stringifyKeysInOrder)({
19
+ const unsignedTx = stringifyKeysInOrder({
59
20
  account_number: msg.account_number,
60
21
  chain_id: ATOM_CHAIN,
61
22
  fee: { amount: msg.tx.fee.amount, gas: msg.tx.fee.gas },
@@ -63,38 +24,34 @@ const cosmosSignTx = (transport, msg) => __awaiter(void 0, void 0, void 0, funct
63
24
  msgs: msg.tx.msg,
64
25
  sequence: msg.sequence,
65
26
  });
66
- const signResponse = yield transport.call("Cosmos", "sign", bip32path, unsignedTx);
67
- (0, utils_1.handleError)(signResponse, transport, "Unable to obtain signature from device.");
27
+ const signResponse = await transport.call("Cosmos", "sign", bip32path, unsignedTx);
28
+ handleError(signResponse, transport, "Unable to obtain signature from device.");
68
29
  const signature = signResponse.payload.signature;
69
30
  if (!signature)
70
31
  throw new Error("No signature returned from device");
71
32
  const offlineSigner = {
72
- getAccounts() {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- return [
75
- {
76
- address,
77
- algo: "secp256k1",
78
- pubkey: Buffer.from(publicKey, "hex"),
79
- },
80
- ];
81
- });
33
+ async getAccounts() {
34
+ return [
35
+ {
36
+ address,
37
+ algo: "secp256k1",
38
+ pubkey: Buffer.from(publicKey, "hex"),
39
+ },
40
+ ];
82
41
  },
83
- signAmino(signerAddress, signDoc) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- if (signerAddress !== address)
86
- throw new Error("expected signerAddress to match address");
87
- return {
88
- signed: signDoc,
89
- signature: {
90
- pub_key: {
91
- type: "tendermint/PubKeySecp256k1",
92
- value: publicKey,
93
- },
94
- signature: (0, base64_js_1.fromByteArray)(crypto_1.Secp256k1Signature.fromDer(signature).toFixedLength()),
42
+ async signAmino(signerAddress, signDoc) {
43
+ if (signerAddress !== address)
44
+ throw new Error("expected signerAddress to match address");
45
+ return {
46
+ signed: signDoc,
47
+ signature: {
48
+ pub_key: {
49
+ type: "tendermint/PubKeySecp256k1",
50
+ value: publicKey,
95
51
  },
96
- };
97
- });
52
+ signature: fromByteArray(Secp256k1Signature.fromDer(signature).toFixedLength()),
53
+ },
54
+ };
98
55
  },
99
56
  };
100
57
  const signerData = {
@@ -102,7 +59,6 @@ const cosmosSignTx = (transport, msg) => __awaiter(void 0, void 0, void 0, funct
102
59
  accountNumber: Number(msg.account_number),
103
60
  chainId: msg.chain_id,
104
61
  };
105
- return (yield protoTxBuilder).sign(address, msg.tx, offlineSigner, signerData, "cosmos");
106
- });
107
- exports.cosmosSignTx = cosmosSignTx;
62
+ return (await protoTxBuilder).sign(address, msg.tx, offlineSigner, signerData, "cosmos");
63
+ };
108
64
  //# sourceMappingURL=cosmos.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cosmos.js","sourceRoot":"","sources":["../src/cosmos.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAoD;AAEpD,mEAAqD;AACrD,yCAA0C;AAC1C,oDAA2B;AAG3B,mCAA4D;AAE5D,MAAM,cAAc,GAAG,gBAAK,CAAC,IAAI,CAAC,GAAG,EAAE,mDAAQ,iCAAiC,GAAC,CAAC,CAAC;AAEnF,MAAM,UAAU,GAAG,aAAa,CAAC;AAE1B,MAAM,gBAAgB,GAAG,CAAO,SAA0B,EAAE,GAA0B,EAAmB,EAAE;IAChH,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC7D,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAE9E,IAAA,mBAAW,EAAC,GAAG,EAAE,SAAS,EAAE,uCAAuC,CAAC,CAAC;IAErE,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;AAC7B,CAAC,CAAA,CAAC;AAPW,QAAA,gBAAgB,oBAO3B;AAEK,MAAM,YAAY,GAAG,CAC1B,SAA0B,EAC1B,GAAsB,EACQ,EAAE;IAChC,MAAM,SAAS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CAAC,CAAC;AACpG,CAAC,CAAC"}
@@ -1,8 +1,5 @@
1
- "use strict";
2
1
  // Taken from https://github.com/LedgerHQ/ledgerjs/blob/master/packages/cryptoassets/src/currencies.ts#L299
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.currencies = void 0;
5
- exports.currencies = {
2
+ export const currencies = {
6
3
  Bitcoin: {
7
4
  name: "Bitcoin",
8
5
  xpubVersion: 0x0488b21e,
@@ -1 +1 @@
1
- {"version":3,"file":"currencies.js","sourceRoot":"","sources":["../src/currencies.ts"],"names":[],"mappings":";AAAA,2GAA2G;;;AAI9F,QAAA,UAAU,GAA6B;IAClD,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,UAAU;KACxB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,UAAU;KACxB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,UAAU;KACxB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,UAAU;KACxB;CACF,CAAC"}
1
+ {"version":3,"file":"currencies.js","sourceRoot":"","sources":["../src/currencies.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAI3G,MAAM,CAAC,MAAM,UAAU,GAA6B;IAClD,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,UAAU;KACxB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,UAAU;KACxB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,UAAU;KACxB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,UAAU;KACxB;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ethereum.d.ts","sourceRoot":"","sources":["../src/ethereum.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,IAAI,MAAM,8BAA8B,CA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OAAO,CAAC,OAAO,CAAC,CAWnF"}
package/dist/ethereum.js CHANGED
@@ -1,155 +1,104 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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
- 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.ethVerifyMessage = exports.ethSignTypedData = exports.ethSignMessage = exports.ethGetAccountPaths = exports.ethSupportsEIP1559 = exports.ethSupportsNativeShapeShift = exports.ethSupportsSecureTransfer = exports.ethSignTx = exports.ethGetPublicKeys = exports.ethGetAddress = exports.ethSupportsNetwork = void 0;
39
- const common_1 = __importDefault(require("@ethereumjs/common"));
40
- const tx_1 = require("@ethereumjs/tx");
41
- const sigUtil = __importStar(require("@metamask/eth-sig-util"));
42
- const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
43
- const ethereumjs_tx_1 = __importDefault(require("ethereumjs-tx"));
1
+ import Common from "@ethereumjs/common";
2
+ import { Transaction } from "@ethereumjs/tx";
3
+ import * as sigUtil from "@metamask/eth-sig-util";
4
+ import * as core from "@shapeshiftoss/hdwallet-core";
5
+ import EthereumTx from "ethereumjs-tx";
44
6
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45
7
  // @ts-ignore
46
8
  // TODO: fix ts-ignore
47
- const ethereumUtil = __importStar(require("ethereumjs-util"));
48
- const utils_js_1 = require("ethers/lib/utils.js");
49
- const ethjs_util_1 = require("ethjs-util");
50
- const utils_1 = require("./utils");
51
- function ethSupportsNetwork(chain_id) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- return chain_id === 1;
54
- });
9
+ import * as ethereumUtil from "ethereumjs-util";
10
+ import { arrayify, isBytes, isHexString, joinSignature } from "ethers/lib/utils";
11
+ import { compressPublicKey, createXpub, handleError, networksUtil } from "./utils";
12
+ export async function ethSupportsNetwork(chain_id) {
13
+ return chain_id === 1;
55
14
  }
56
- exports.ethSupportsNetwork = ethSupportsNetwork;
57
- function ethGetAddress(transport, msg) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- const bip32path = core.addressNListToBIP32(msg.addressNList);
60
- const res = yield transport.call("Eth", "getAddress", bip32path, !!msg.showDisplay);
61
- (0, utils_1.handleError)(res, transport, "Unable to obtain ETH address from device.");
62
- return res.payload.address;
63
- });
15
+ export async function ethGetAddress(transport, msg) {
16
+ const bip32path = core.addressNListToBIP32(msg.addressNList);
17
+ const res = await transport.call("Eth", "getAddress", bip32path, !!msg.showDisplay);
18
+ handleError(res, transport, "Unable to obtain ETH address from device.");
19
+ return res.payload.address;
64
20
  }
65
- exports.ethGetAddress = ethGetAddress;
66
21
  // Adapted from https://github.com/LedgerHQ/ledger-wallet-webtool
67
- function ethGetPublicKeys(transport, msg) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- const xpubs = [];
70
- for (const getPublicKey of msg) {
71
- const { addressNList, coin } = getPublicKey;
72
- let { scriptType } = getPublicKey;
73
- if (!scriptType)
74
- scriptType = core.BTCInputScriptType.SpendAddress;
75
- // Only get public keys for ETH account paths
76
- if (!addressNList.includes(0x80000000 + 44, 0) || !addressNList.includes(0x80000000 + 60, 1)) {
77
- xpubs.push(null);
78
- continue;
79
- }
80
- const parentBip32path = core.addressNListToBIP32(addressNList.slice(0, -1)).substring(2); // i.e. "44'/0'"
81
- const bip32path = core.addressNListToBIP32(addressNList).substring(2); // i.e 44'/0'/0'
82
- const res1 = yield transport.call("Eth", "getAddress", parentBip32path, /* display */ false, /* chain code */ true);
83
- (0, utils_1.handleError)(res1, transport, "Unable to obtain public key from device.");
84
- const { payload: { publicKey: parentPublicKeyHex }, } = res1;
85
- const parentPublicKey = (0, utils_1.compressPublicKey)(Buffer.from(parentPublicKeyHex, "hex"));
86
- const parentFingerprint = new DataView(ethereumUtil.ripemd160(ethereumUtil.sha256(parentPublicKey), false).buffer).getUint32(0);
87
- const res2 = yield transport.call("Eth", "getAddress", bip32path, /* display */ false, /* chain code */ true);
88
- (0, utils_1.handleError)(res2, transport, "Unable to obtain public key from device.");
89
- const { payload: { publicKey: publicKeyHex, chainCode: chainCodeHex }, } = res2;
90
- const publicKey = (0, utils_1.compressPublicKey)(Buffer.from(publicKeyHex, "hex"));
91
- const chainCode = Buffer.from(core.mustBeDefined(chainCodeHex), "hex");
92
- const coinDetails = utils_1.networksUtil[core.mustBeDefined(core.slip44ByCoin(coin))];
93
- const childNum = addressNList[addressNList.length - 1];
94
- const networkMagic = coinDetails.bitcoinjs.bip32.public[scriptType];
95
- if (networkMagic === undefined)
96
- throw new Error(`scriptType ${scriptType} not supported`);
97
- xpubs.push({
98
- xpub: (0, utils_1.createXpub)(addressNList.length, parentFingerprint, childNum, chainCode, publicKey, networkMagic),
99
- });
22
+ export async function ethGetPublicKeys(transport, msg) {
23
+ const xpubs = [];
24
+ for (const getPublicKey of msg) {
25
+ const { addressNList, coin } = getPublicKey;
26
+ let { scriptType } = getPublicKey;
27
+ if (!scriptType)
28
+ scriptType = core.BTCInputScriptType.SpendAddress;
29
+ // Only get public keys for ETH account paths
30
+ if (!addressNList.includes(0x80000000 + 44, 0) || !addressNList.includes(0x80000000 + 60, 1)) {
31
+ xpubs.push(null);
32
+ continue;
100
33
  }
101
- return xpubs;
102
- });
34
+ const parentBip32path = core.addressNListToBIP32(addressNList.slice(0, -1)).substring(2); // i.e. "44'/0'"
35
+ const bip32path = core.addressNListToBIP32(addressNList).substring(2); // i.e 44'/0'/0'
36
+ const res1 = await transport.call("Eth", "getAddress", parentBip32path, /* display */ false, /* chain code */ true);
37
+ handleError(res1, transport, "Unable to obtain public key from device.");
38
+ const { payload: { publicKey: parentPublicKeyHex }, } = res1;
39
+ const parentPublicKey = compressPublicKey(Buffer.from(parentPublicKeyHex, "hex"));
40
+ const parentFingerprint = new DataView(ethereumUtil.ripemd160(ethereumUtil.sha256(parentPublicKey), false).buffer).getUint32(0);
41
+ const res2 = await transport.call("Eth", "getAddress", bip32path, /* display */ false, /* chain code */ true);
42
+ handleError(res2, transport, "Unable to obtain public key from device.");
43
+ const { payload: { publicKey: publicKeyHex, chainCode: chainCodeHex }, } = res2;
44
+ const publicKey = compressPublicKey(Buffer.from(publicKeyHex, "hex"));
45
+ const chainCode = Buffer.from(core.mustBeDefined(chainCodeHex), "hex");
46
+ const coinDetails = networksUtil[core.mustBeDefined(core.slip44ByCoin(coin))];
47
+ const childNum = addressNList[addressNList.length - 1];
48
+ const networkMagic = coinDetails.bitcoinjs.bip32.public[scriptType];
49
+ if (networkMagic === undefined)
50
+ throw new Error(`scriptType ${scriptType} not supported`);
51
+ xpubs.push({
52
+ xpub: createXpub(addressNList.length, parentFingerprint, childNum, chainCode, publicKey, networkMagic),
53
+ });
54
+ }
55
+ return xpubs;
103
56
  }
104
- exports.ethGetPublicKeys = ethGetPublicKeys;
105
- function ethSignTx(transport, msg) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const bip32path = core.addressNListToBIP32(msg.addressNList);
108
- const common = common_1.default.custom({ chainId: msg.chainId });
109
- const txParams = {
110
- to: msg.to,
111
- value: msg.value,
112
- data: msg.data,
113
- chainId: msg.chainId,
114
- nonce: msg.nonce,
115
- gasLimit: msg.gasLimit,
116
- gasPrice: msg.gasPrice,
117
- v: "0x" + msg.chainId.toString(16).padStart(2, "0"),
118
- r: "0x00",
119
- s: "0x00",
120
- };
121
- const utx = new ethereumjs_tx_1.default(txParams);
122
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
123
- // @ts-ignore transport.call is drunk, there *is* a third argument to eth.signTransaction
124
- // see https://github.com/LedgerHQ/ledgerjs/blob/master/packages/hw-app-eth/README.md#parameters-2
125
- const res = yield transport.call("Eth", "signTransaction", bip32path, utx.serialize().toString("hex"), null);
126
- (0, utils_1.handleError)(res, transport, "Could not sign ETH tx with Ledger");
127
- const { v, r, s } = res.payload;
128
- const tx = tx_1.Transaction.fromTxData(Object.assign(Object.assign({}, txParams), { v: "0x" + v, r: "0x" + r, s: "0x" + s }), { common });
129
- return {
130
- v: parseInt(v, 16),
131
- r: "0x" + r,
132
- s: "0x" + s,
133
- serialized: "0x" + core.toHexString(tx.serialize()),
134
- };
135
- });
57
+ export async function ethSignTx(transport, msg) {
58
+ const bip32path = core.addressNListToBIP32(msg.addressNList);
59
+ const common = Common.custom({ chainId: msg.chainId });
60
+ const txParams = {
61
+ to: msg.to,
62
+ value: msg.value,
63
+ data: msg.data,
64
+ chainId: msg.chainId,
65
+ nonce: msg.nonce,
66
+ gasLimit: msg.gasLimit,
67
+ gasPrice: msg.gasPrice,
68
+ v: "0x" + msg.chainId.toString(16).padStart(2, "0"),
69
+ r: "0x00",
70
+ s: "0x00",
71
+ };
72
+ const utx = new EthereumTx(txParams);
73
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
74
+ // @ts-ignore transport.call is drunk, there *is* a third argument to eth.signTransaction
75
+ // see https://github.com/LedgerHQ/ledgerjs/blob/master/packages/hw-app-eth/README.md#parameters-2
76
+ const res = await transport.call("Eth", "signTransaction", bip32path, utx.serialize().toString("hex"), null);
77
+ handleError(res, transport, "Could not sign ETH tx with Ledger");
78
+ const { v, r, s } = res.payload;
79
+ const tx = Transaction.fromTxData({
80
+ ...txParams,
81
+ v: "0x" + v,
82
+ r: "0x" + r,
83
+ s: "0x" + s,
84
+ }, { common });
85
+ return {
86
+ v: parseInt(v, 16),
87
+ r: "0x" + r,
88
+ s: "0x" + s,
89
+ serialized: "0x" + core.toHexString(tx.serialize()),
90
+ };
136
91
  }
137
- exports.ethSignTx = ethSignTx;
138
- function ethSupportsSecureTransfer() {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- return false;
141
- });
92
+ export async function ethSupportsSecureTransfer() {
93
+ return false;
142
94
  }
143
- exports.ethSupportsSecureTransfer = ethSupportsSecureTransfer;
144
- function ethSupportsNativeShapeShift() {
95
+ export function ethSupportsNativeShapeShift() {
145
96
  return false;
146
97
  }
147
- exports.ethSupportsNativeShapeShift = ethSupportsNativeShapeShift;
148
- function ethSupportsEIP1559() {
98
+ export function ethSupportsEIP1559() {
149
99
  return false;
150
100
  }
151
- exports.ethSupportsEIP1559 = ethSupportsEIP1559;
152
- function ethGetAccountPaths(msg) {
101
+ export function ethGetAccountPaths(msg) {
153
102
  const slip44 = core.slip44ByCoin(msg.coin);
154
103
  if (slip44 === undefined)
155
104
  return [];
@@ -168,73 +117,65 @@ function ethGetAccountPaths(msg) {
168
117
  },
169
118
  ];
170
119
  }
171
- exports.ethGetAccountPaths = ethGetAccountPaths;
172
- function ethSignMessage(transport, msg) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- const bip32path = core.addressNListToBIP32(msg.addressNList);
175
- if (!(0, ethjs_util_1.isHexString)(msg.message))
176
- throw new Error("data is not an hex string");
177
- // Ledger's inner implementation does a Buffer.from(messageHex, "hex").length on our message
178
- // However, Buffer.from method with the "hex" encoding expects a valid hexadecimal string without the 0x prefix
179
- // so we need to strip it in case it's present
180
- const sanitizedMessageHex = msg.message.startsWith("0x") ? msg.message.slice(2) : msg.message;
181
- const res = yield transport.call("Eth", "signPersonalMessage", bip32path, sanitizedMessageHex);
182
- (0, utils_1.handleError)(res, transport, "Could not sign ETH message with Ledger");
183
- let { v } = res.payload;
184
- const { r, s } = res.payload;
185
- v = v - 27;
186
- const vStr = v.toString(16).padStart(2, "0");
187
- const addressRes = yield transport.call("Eth", "getAddress", bip32path, false);
188
- (0, utils_1.handleError)(addressRes, transport, "Unable to obtain ETH address from Ledger.");
189
- return {
190
- address: addressRes.payload.address,
191
- signature: "0x" + r + s + vStr,
192
- };
193
- });
120
+ export async function ethSignMessage(transport, msg) {
121
+ const bip32path = core.addressNListToBIP32(msg.addressNList);
122
+ if (!isHexString(msg.message))
123
+ throw new Error("data is not an hex string");
124
+ // Ledger's inner implementation does a Buffer.from(messageHex, "hex").length on our message
125
+ // However, Buffer.from method with the "hex" encoding expects a valid hexadecimal string without the 0x prefix
126
+ // so we need to strip it in case it's present
127
+ const sanitizedMessageHex = msg.message.startsWith("0x") ? msg.message.slice(2) : msg.message;
128
+ const res = await transport.call("Eth", "signPersonalMessage", bip32path, sanitizedMessageHex);
129
+ handleError(res, transport, "Could not sign ETH message with Ledger");
130
+ let { v } = res.payload;
131
+ const { r, s } = res.payload;
132
+ v = v - 27;
133
+ const vStr = v.toString(16).padStart(2, "0");
134
+ const addressRes = await transport.call("Eth", "getAddress", bip32path, false);
135
+ handleError(addressRes, transport, "Unable to obtain ETH address from Ledger.");
136
+ return {
137
+ address: addressRes.payload.address,
138
+ signature: "0x" + r + s + vStr,
139
+ };
194
140
  }
195
- exports.ethSignMessage = ethSignMessage;
196
- // TODO(gomes): Implement signEIP712Message instead and fallback to signEIP712HashedMessage only if it fails (incompatible with Nano S)
197
- // https://github.com/LedgerHQ/ledger-live/blob/1de4de022b4e3abc02fcb823ae6ef1f9a64adba2/libs/ledgerjs/packages/hw-app-eth/README.md#signeip712message
198
- // The reason why we don't do that now is because bumping hw-app-eth to latest means problems
199
- function ethSignTypedData(transport, msg) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- const bip32path = core.addressNListToBIP32(msg.addressNList);
202
- if (!("EIP712Domain" in msg.typedData.types))
203
- throw new Error("msg.typedData missing EIP712Domain");
204
- const typedData = msg.typedData;
205
- const { types, primaryType, message } = sigUtil.TypedDataUtils.sanitizeData(typedData);
206
- const domainSeparatorHex = sigUtil.TypedDataUtils.eip712DomainHash(typedData, sigUtil.SignTypedDataVersion.V4).toString("hex");
207
- const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct(primaryType, message, types, sigUtil.SignTypedDataVersion.V4).toString("hex");
208
- const res = yield transport.call("Eth", "signEIP712HashedMessage", bip32path, domainSeparatorHex, hashStructMessageHex);
209
- (0, utils_1.handleError)(res, transport, "Could not sign typed data with Ledger");
210
- const { r, s, v } = res.payload;
211
- const signature = (0, utils_js_1.joinSignature)({
212
- r: `0x${r}`,
213
- s: `0x${s}`,
214
- v: typeof v === "string" ? parseInt(v, 16) : v,
215
- });
216
- const addressRes = yield transport.call("Eth", "getAddress", bip32path, false);
217
- (0, utils_1.handleError)(addressRes, transport, "Unable to obtain ETH address from Ledger.");
218
- return {
219
- address: addressRes.payload.address,
220
- signature,
221
- };
141
+ export async function ethSignTypedData(transport, msg) {
142
+ const bip32path = core.addressNListToBIP32(msg.addressNList);
143
+ if (!("EIP712Domain" in msg.typedData.types))
144
+ throw new Error("msg.typedData missing EIP712Domain");
145
+ const typedData = msg.typedData;
146
+ const { types, primaryType, message } = sigUtil.TypedDataUtils.sanitizeData(typedData);
147
+ const domainSeparatorHex = sigUtil.TypedDataUtils.eip712DomainHash(typedData, sigUtil.SignTypedDataVersion.V4).toString("hex");
148
+ const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct(primaryType, message, types, sigUtil.SignTypedDataVersion.V4).toString("hex");
149
+ // The old Ledger Nano S (not S+) doesn't support signEIP712Message, so we have to fallback to signEIP712HashedMessage only if it fails
150
+ // https://github.com/LedgerHQ/ledger-live/blob/1de4de022b4e3abc02fcb823ae6ef1f9a64adba2/libs/ledgerjs/packages/hw-app-eth/README.md#signeip712message
151
+ const res = await transport.call("Eth", "signEIP712Message", bip32path, msg.typedData).catch((e) => {
152
+ console.error(e);
153
+ return transport.call("Eth", "signEIP712HashedMessage", bip32path, domainSeparatorHex, hashStructMessageHex);
154
+ });
155
+ handleError(res, transport, "Could not sign typed data with Ledger");
156
+ const { r, s, v } = res.payload;
157
+ const signature = joinSignature({
158
+ r: `0x${r}`,
159
+ s: `0x${s}`,
160
+ v: typeof v === "string" ? parseInt(v, 16) : v,
222
161
  });
162
+ const addressRes = await transport.call("Eth", "getAddress", bip32path, false);
163
+ handleError(addressRes, transport, "Unable to obtain ETH address from Ledger.");
164
+ return {
165
+ address: addressRes.payload.address,
166
+ signature,
167
+ };
223
168
  }
224
- exports.ethSignTypedData = ethSignTypedData;
225
169
  // Adapted from https://github.com/kvhnuke/etherwallet/blob/2a5bc0db1c65906b14d8c33ce9101788c70d3774/app/scripts/controllers/signMsgCtrl.js#L118
226
- function ethVerifyMessage(msg) {
227
- return __awaiter(this, void 0, void 0, function* () {
228
- const sigb = Buffer.from(core.stripHexPrefixAndLower(msg.signature), "hex");
229
- if (sigb.length !== 65) {
230
- return false;
231
- }
232
- sigb[64] = sigb[64] === 0 || sigb[64] === 1 ? sigb[64] + 27 : sigb[64];
233
- const buffer = (0, utils_js_1.isBytes)(msg.message) ? Buffer.from((0, utils_js_1.arrayify)(msg.message)) : Buffer.from(msg.message);
234
- const hash = ethereumUtil.hashPersonalMessage(buffer);
235
- const pubKey = ethereumUtil.ecrecover(hash, sigb[64], sigb.slice(0, 32), sigb.slice(32, 64));
236
- return core.stripHexPrefixAndLower(msg.address) === ethereumUtil.pubToAddress(pubKey).toString("hex");
237
- });
170
+ export async function ethVerifyMessage(msg) {
171
+ const sigb = Buffer.from(core.stripHexPrefixAndLower(msg.signature), "hex");
172
+ if (sigb.length !== 65) {
173
+ return false;
174
+ }
175
+ sigb[64] = sigb[64] === 0 || sigb[64] === 1 ? sigb[64] + 27 : sigb[64];
176
+ const buffer = isBytes(msg.message) ? Buffer.from(arrayify(msg.message)) : Buffer.from(msg.message);
177
+ const hash = ethereumUtil.hashPersonalMessage(buffer);
178
+ const pubKey = ethereumUtil.ecrecover(hash, sigb[64], sigb.slice(0, 32), sigb.slice(32, 64));
179
+ return core.stripHexPrefixAndLower(msg.address) === ethereumUtil.pubToAddress(pubKey).toString("hex");
238
180
  }
239
- exports.ethVerifyMessage = ethVerifyMessage;
240
181
  //# sourceMappingURL=ethereum.js.map