@exodus/hw-ledger 3.9.1 → 3.9.2
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/CHANGELOG.md +14 -0
- package/lib/atoms/index.d.ts +3 -3
- package/lib/atoms/index.js +10 -7
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -9
- package/lib/module/assets/applications.js +3 -1
- package/lib/module/assets/basemainnet.d.ts +1 -1
- package/lib/module/assets/basemainnet.js +10 -5
- package/lib/module/assets/bitcoin.js +42 -37
- package/lib/module/assets/ethereum.js +59 -21
- package/lib/module/assets/index.js +28 -22
- package/lib/module/assets/matic.d.ts +1 -1
- package/lib/module/assets/matic.js +10 -5
- package/lib/module/assets/ripple.js +17 -12
- package/lib/module/assets/solana.js +19 -14
- package/lib/module/assets/tronmainnet.js +50 -12
- package/lib/module/assets/utils/bip322.js +43 -7
- package/lib/module/assets/utils/derivation-paths.js +28 -17
- package/lib/module/assets/utils/index.d.ts +3 -3
- package/lib/module/assets/utils/index.js +19 -3
- package/lib/module/assets/utils/psbt.d.ts +2 -2
- package/lib/module/assets/utils/psbt.js +46 -34
- package/lib/module/assets/utils/xpub.js +6 -3
- package/lib/module/constants.js +4 -1
- package/lib/module/device.d.ts +2 -2
- package/lib/module/device.js +28 -21
- package/lib/module/discovery.d.ts +3 -3
- package/lib/module/discovery.js +18 -14
- package/lib/module/errors.js +12 -5
- package/lib/module/index.d.ts +2 -2
- package/lib/module/index.js +23 -2
- package/lib/module/management/application.js +4 -1
- package/lib/module/types.js +2 -1
- package/lib/plugin/index.d.ts +3 -3
- package/lib/plugin/index.js +6 -4
- package/lib/redux/id.js +3 -1
- package/lib/redux/index.d.ts +3 -3
- package/lib/redux/index.js +12 -7
- package/lib/redux/initial-state.d.ts +1 -1
- package/lib/redux/initial-state.js +3 -1
- package/lib/redux/selectors/bluetoothScanning.d.ts +1 -1
- package/lib/redux/selectors/bluetoothScanning.js +5 -3
- package/lib/redux/selectors/bluetoothStatus.d.ts +2 -2
- package/lib/redux/selectors/bluetoothStatus.js +5 -3
- package/lib/redux/selectors/index.d.ts +2 -2
- package/lib/redux/selectors/index.js +9 -4
- package/package.json +8 -2
- package/redux.js +2 -0
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const hw_app_xrp_1 = __importDefault(require("@ledgerhq/hw-app-xrp"));
|
|
7
|
+
const minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
8
|
+
const hw_common_1 = require("@exodus/hw-common");
|
|
9
|
+
const ripple_binary_codec_1 = __importDefault(require("@exodus/ripple-binary-codec"));
|
|
10
|
+
const applications_js_1 = __importDefault(require("./applications.js"));
|
|
6
11
|
async function createHandler(transport) {
|
|
7
|
-
const app = new
|
|
12
|
+
const app = new hw_app_xrp_1.default(transport);
|
|
8
13
|
const getAddress = async (params) => {
|
|
9
14
|
const { address } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
10
15
|
return address;
|
|
11
16
|
};
|
|
12
17
|
const getXPub = async () => {
|
|
13
|
-
throw new XPubUnsupportedError();
|
|
18
|
+
throw new hw_common_1.XPubUnsupportedError();
|
|
14
19
|
};
|
|
15
20
|
const getPublicKey = async (params) => {
|
|
16
21
|
const { publicKey } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
17
22
|
return Buffer.from(publicKey, 'hex');
|
|
18
23
|
};
|
|
19
24
|
const signTransaction = async (params) => {
|
|
20
|
-
|
|
25
|
+
(0, minimalistic_assert_1.default)(Array.isArray(params.derivationPaths) && params.derivationPaths.length === 1, 'derivationsPath array must be one element long');
|
|
21
26
|
const { txData } = params.signableTransaction;
|
|
22
27
|
const derivationPath = params.derivationPaths[0].replace('m/', '');
|
|
23
28
|
const { address, publicKey } = await app.getAddress(derivationPath);
|
|
@@ -26,7 +31,7 @@ async function createHandler(transport) {
|
|
|
26
31
|
Account: address,
|
|
27
32
|
SigningPubKey: publicKey.toUpperCase(),
|
|
28
33
|
};
|
|
29
|
-
const encoded =
|
|
34
|
+
const encoded = ripple_binary_codec_1.default.encode(txForSigning);
|
|
30
35
|
const signature = await app.signTransaction(derivationPath, encoded);
|
|
31
36
|
return [
|
|
32
37
|
{
|
|
@@ -36,7 +41,7 @@ async function createHandler(transport) {
|
|
|
36
41
|
];
|
|
37
42
|
};
|
|
38
43
|
const signMessage = async () => {
|
|
39
|
-
throw new SignMessageUnsupportedError();
|
|
44
|
+
throw new hw_common_1.SignMessageUnsupportedError();
|
|
40
45
|
};
|
|
41
46
|
return {
|
|
42
47
|
getAddress,
|
|
@@ -47,7 +52,7 @@ async function createHandler(transport) {
|
|
|
47
52
|
};
|
|
48
53
|
}
|
|
49
54
|
const metadata = {
|
|
50
|
-
applications: [
|
|
55
|
+
applications: [applications_js_1.default.XRP],
|
|
51
56
|
handler: createHandler,
|
|
52
57
|
};
|
|
53
|
-
|
|
58
|
+
exports.default = metadata;
|
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const hw_app_solana_1 = __importDefault(require("@ledgerhq/hw-app-solana"));
|
|
7
|
+
const minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
8
|
+
const base58_js_1 = require("@exodus/bytes/base58.js");
|
|
9
|
+
const hw_common_1 = require("@exodus/hw-common");
|
|
10
|
+
const errors_js_1 = require("../errors.js");
|
|
11
|
+
const applications_js_1 = __importDefault(require("./applications.js"));
|
|
7
12
|
async function createHandler(transport) {
|
|
8
|
-
const app = new
|
|
13
|
+
const app = new hw_app_solana_1.default(transport);
|
|
9
14
|
const getAddress = async (params) => {
|
|
10
15
|
const { address } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
11
|
-
return toBase58(address);
|
|
16
|
+
return (0, base58_js_1.toBase58)(address);
|
|
12
17
|
};
|
|
13
18
|
const getXPub = async (params) => {
|
|
14
|
-
throw new XPubUnsupportedError();
|
|
19
|
+
throw new hw_common_1.XPubUnsupportedError();
|
|
15
20
|
};
|
|
16
21
|
const getPublicKey = async (params) => {
|
|
17
22
|
const { address } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
18
23
|
return address;
|
|
19
24
|
};
|
|
20
25
|
const signTransaction = async (params) => {
|
|
21
|
-
|
|
26
|
+
(0, minimalistic_assert_1.default)(Array.isArray(params.derivationPaths) && params.derivationPaths.length === 1, 'derivationsPath array must be one element long');
|
|
22
27
|
let serializedTransaction;
|
|
23
28
|
if (Buffer.isBuffer(params.signableTransaction)) {
|
|
24
29
|
serializedTransaction = params.signableTransaction;
|
|
@@ -36,7 +41,7 @@ async function createHandler(transport) {
|
|
|
36
41
|
.signTransaction(params.derivationPaths[0].replace('m/', ''), serializedTransaction)
|
|
37
42
|
.catch((err) => {
|
|
38
43
|
if (err.message.includes('Try enabling blind signature in the app')) {
|
|
39
|
-
throw new RequiresBlindSigningError();
|
|
44
|
+
throw new errors_js_1.RequiresBlindSigningError();
|
|
40
45
|
}
|
|
41
46
|
else {
|
|
42
47
|
throw err;
|
|
@@ -51,7 +56,7 @@ async function createHandler(transport) {
|
|
|
51
56
|
];
|
|
52
57
|
};
|
|
53
58
|
const signMessage = async (params) => {
|
|
54
|
-
|
|
59
|
+
(0, minimalistic_assert_1.default)(Buffer.isBuffer(params.message.rawMessage), 'rawMessage must be a buffer');
|
|
55
60
|
const { signature } = await app.signOffchainMessage(params.derivationPath.replace('m/', ''), params.message.rawMessage);
|
|
56
61
|
return signature;
|
|
57
62
|
};
|
|
@@ -64,7 +69,7 @@ async function createHandler(transport) {
|
|
|
64
69
|
};
|
|
65
70
|
}
|
|
66
71
|
const metadata = {
|
|
67
|
-
applications: [
|
|
72
|
+
applications: [applications_js_1.default.Solana],
|
|
68
73
|
handler: createHandler,
|
|
69
74
|
};
|
|
70
|
-
|
|
75
|
+
exports.default = metadata;
|
|
@@ -1,16 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const hw_app_trx_1 = __importDefault(require("@ledgerhq/hw-app-trx"));
|
|
40
|
+
const minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
41
|
+
const hw_common_1 = require("@exodus/hw-common");
|
|
42
|
+
const secp256k1 = __importStar(require("@exodus/crypto/secp256k1"));
|
|
43
|
+
const applications_js_1 = __importDefault(require("./applications.js"));
|
|
6
44
|
async function createHandler(transport) {
|
|
7
|
-
const app = new
|
|
45
|
+
const app = new hw_app_trx_1.default(transport);
|
|
8
46
|
const getAddress = async (params) => {
|
|
9
47
|
const { address } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
10
48
|
return address;
|
|
11
49
|
};
|
|
12
50
|
const getXPub = async (params) => {
|
|
13
|
-
throw new XPubUnsupportedError();
|
|
51
|
+
throw new hw_common_1.XPubUnsupportedError();
|
|
14
52
|
};
|
|
15
53
|
const getPublicKey = async (params) => {
|
|
16
54
|
const { publicKey } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
@@ -21,7 +59,7 @@ async function createHandler(transport) {
|
|
|
21
59
|
});
|
|
22
60
|
};
|
|
23
61
|
const signTransaction = async (params) => {
|
|
24
|
-
|
|
62
|
+
(0, minimalistic_assert_1.default)(Array.isArray(params.derivationPaths) && params.derivationPaths.length === 1, 'derivationsPath array must be one element long');
|
|
25
63
|
if (!Buffer.isBuffer(params.signableTransaction)) {
|
|
26
64
|
throw new TypeError(`signableTransaction must be Buffer or serializable to a Buffer.`);
|
|
27
65
|
}
|
|
@@ -34,7 +72,7 @@ async function createHandler(transport) {
|
|
|
34
72
|
};
|
|
35
73
|
const signMessage = async (params) => {
|
|
36
74
|
if (params.message.rawMessage) {
|
|
37
|
-
|
|
75
|
+
(0, minimalistic_assert_1.default)(Buffer.isBuffer(params.message.rawMessage), 'rawMessage must be a buffer');
|
|
38
76
|
const signature = await app.signPersonalMessage(params.derivationPath.replace('m/', ''), params.message.rawMessage.toString('hex'));
|
|
39
77
|
return Buffer.from(signature, 'hex');
|
|
40
78
|
}
|
|
@@ -42,7 +80,7 @@ async function createHandler(transport) {
|
|
|
42
80
|
throw new Error('TIP712 messages are not yet supported');
|
|
43
81
|
}
|
|
44
82
|
else {
|
|
45
|
-
|
|
83
|
+
(0, minimalistic_assert_1.default)(false, 'rawMessage or TIP712Message must be specified');
|
|
46
84
|
}
|
|
47
85
|
};
|
|
48
86
|
return {
|
|
@@ -54,7 +92,7 @@ async function createHandler(transport) {
|
|
|
54
92
|
};
|
|
55
93
|
}
|
|
56
94
|
const metadata = {
|
|
57
|
-
applications: [
|
|
95
|
+
applications: [applications_js_1.default.Tron],
|
|
58
96
|
handler: createHandler,
|
|
59
97
|
};
|
|
60
|
-
|
|
98
|
+
exports.default = metadata;
|
|
@@ -1,13 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.buildBip322PSBT = buildBip322PSBT;
|
|
37
|
+
const bitcoin = __importStar(require("@exodus/bitcoinjs"));
|
|
38
|
+
const bip322_js_1 = require("@exodus/bip322-js");
|
|
39
|
+
function buildBip322PSBT(message, address) {
|
|
40
|
+
const scriptPubKey = bip322_js_1.Address.convertAdressToScriptPubkey(address);
|
|
41
|
+
const toSpendTx = bip322_js_1.BIP322.buildToSpendTx(message, scriptPubKey);
|
|
6
42
|
const toSpendTxId = toSpendTx.getId();
|
|
7
|
-
if (Address.isP2SH(address)) {
|
|
43
|
+
if (bip322_js_1.Address.isP2SH(address)) {
|
|
8
44
|
throw new Error('Unable to sign BIP-322 message for unimplemented address type.');
|
|
9
45
|
}
|
|
10
|
-
else if (Address.isP2WPKH(address) || Address.isP2TR(address)) {
|
|
46
|
+
else if (bip322_js_1.Address.isP2WPKH(address) || bip322_js_1.Address.isP2TR(address)) {
|
|
11
47
|
return buildToSignNativeSegwitOrTaproot(toSpendTxId, scriptPubKey);
|
|
12
48
|
}
|
|
13
49
|
throw new Error('Unable to sign BIP-322 message for unsupported address type.');
|
|
@@ -1,34 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.splitDerivationPath = splitDerivationPath;
|
|
7
|
+
exports.assertBip44Path = assertBip44Path;
|
|
8
|
+
exports.splitBip44DerivationPath = splitBip44DerivationPath;
|
|
9
|
+
exports.assertBip44PathNumber = assertBip44PathNumber;
|
|
10
|
+
exports.buildBip44PathFromNumber = buildBip44PathFromNumber;
|
|
11
|
+
exports.splitBip44PathToNumber = splitBip44PathToNumber;
|
|
12
|
+
const minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
13
|
+
function splitDerivationPath(derivationPath) {
|
|
14
|
+
(0, minimalistic_assert_1.default)(typeof derivationPath === 'string', 'derivationPath must be string');
|
|
4
15
|
const parts = derivationPath.split('/');
|
|
5
|
-
|
|
6
|
-
|
|
16
|
+
(0, minimalistic_assert_1.default)(parts.length > 1, 'invalid derivationPath: must have length > 1');
|
|
17
|
+
(0, minimalistic_assert_1.default)(parts[0] === 'm', 'invalid derivationPath: must start with m');
|
|
7
18
|
return parts.slice(1);
|
|
8
19
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
function assertBip44Path(parts) {
|
|
21
|
+
(0, minimalistic_assert_1.default)(parts.length === 5, 'invalid bip44 derivation path: length must be 5');
|
|
22
|
+
(0, minimalistic_assert_1.default)(parts.every((part) => typeof part === 'string'), 'Invalid parts');
|
|
12
23
|
}
|
|
13
|
-
|
|
24
|
+
function splitBip44DerivationPath(derivationPath) {
|
|
14
25
|
const parts = splitDerivationPath(derivationPath);
|
|
15
26
|
assertBip44Path(parts);
|
|
16
27
|
const [purpose, coin, account, change, address] = parts;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
(0, minimalistic_assert_1.default)(purpose.endsWith("'"), 'invalid derivationPath: purpose must be hardened');
|
|
29
|
+
(0, minimalistic_assert_1.default)(coin.endsWith("'"), 'invalid derivationPath: coin must be hardened');
|
|
30
|
+
(0, minimalistic_assert_1.default)(account.endsWith("'"), 'invalid derivationPath: account must be hardened');
|
|
20
31
|
return [purpose, coin, account, change, address];
|
|
21
32
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
function assertBip44PathNumber(parts) {
|
|
34
|
+
(0, minimalistic_assert_1.default)(parts.length === 5, 'invalid bip44 derivation path: length must be 5');
|
|
35
|
+
(0, minimalistic_assert_1.default)(parts.every((part) => typeof part === 'number'), 'Invalid parts');
|
|
25
36
|
}
|
|
26
|
-
|
|
37
|
+
function buildBip44PathFromNumber(parts) {
|
|
27
38
|
const [purpose, coin, account, chainIndex, addressIndex] = parts;
|
|
28
39
|
const HARDENED_OFFSET = 0x80_00_00_00;
|
|
29
40
|
return `m/${purpose - HARDENED_OFFSET}'/${coin - HARDENED_OFFSET}'/${account - HARDENED_OFFSET}'/${chainIndex}/${addressIndex}`;
|
|
30
41
|
}
|
|
31
|
-
|
|
42
|
+
function splitBip44PathToNumber(derivationPath) {
|
|
32
43
|
const [purpose, coin, account, change, address] = splitBip44DerivationPath(derivationPath);
|
|
33
44
|
const HARDENED_OFFSET = 0x80_00_00_00;
|
|
34
45
|
return [
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './derivation-paths';
|
|
2
|
-
export * from './xpub';
|
|
3
|
-
export * from './psbt';
|
|
1
|
+
export * from './derivation-paths.js';
|
|
2
|
+
export * from './xpub.js';
|
|
3
|
+
export * from './psbt.js';
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./derivation-paths.js"), exports);
|
|
18
|
+
__exportStar(require("./xpub.js"), exports);
|
|
19
|
+
__exportStar(require("./psbt.js"), exports);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PsbtV2 } from '@exodus/ledger-bitcoin';
|
|
2
|
-
import {
|
|
2
|
+
import { WalletPolicy } from '@exodus/ledger-bitcoin';
|
|
3
3
|
import type { MultisigData } from '@exodus/hw-common';
|
|
4
4
|
export declare function assertPsbtOnlyHasAllowedDerivationPaths(psbt: PsbtV2, masterFingerprint: string, derivationPaths: string[]): void;
|
|
5
5
|
export declare function tagPsbtWithDerivationPaths(psbt: PsbtV2, masterFingerprint: string, derivationPathToPublicKeyMap: Record<string, Buffer>, addressToDerivationPathMap?: Record<string, string>): string[];
|
|
6
|
-
export declare const getWalletPolicy: (fpr: string, xpub: string, purpose: string, coin: string, account: string) =>
|
|
6
|
+
export declare const getWalletPolicy: (fpr: string, xpub: string, purpose: string, coin: string, account: string) => any;
|
|
7
7
|
export declare const getMultisigWalletPolicy: (fpr: string, xpub: string, purpose: string, coin: string, account: string, multisigData: MultisigData) => WalletPolicy;
|
|
8
8
|
export declare function derivationPathsToWalletPolicy(fpr: string, app: any, derivationPaths: string[], multisigData?: MultisigData): Promise<WalletPolicy[]>;
|
|
9
9
|
export declare function addDummyInputs(psbt: PsbtV2): void;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getMultisigWalletPolicy = exports.getWalletPolicy = void 0;
|
|
7
|
+
exports.assertPsbtOnlyHasAllowedDerivationPaths = assertPsbtOnlyHasAllowedDerivationPaths;
|
|
8
|
+
exports.tagPsbtWithDerivationPaths = tagPsbtWithDerivationPaths;
|
|
9
|
+
exports.derivationPathsToWalletPolicy = derivationPathsToWalletPolicy;
|
|
10
|
+
exports.addDummyInputs = addDummyInputs;
|
|
11
|
+
const minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
12
|
+
const ledger_bitcoin_1 = require("@exodus/ledger-bitcoin");
|
|
13
|
+
const bitcoinjs_1 = require("@exodus/bitcoinjs");
|
|
14
|
+
const derivation_paths_js_1 = require("./derivation-paths.js");
|
|
15
|
+
function assertPsbtOnlyHasAllowedDerivationPaths(psbt, masterFingerprint, derivationPaths) {
|
|
6
16
|
for (let i = 0; i < psbt.getGlobalInputCount(); i++) {
|
|
7
17
|
const BIP32_DERIVATION = 6;
|
|
8
18
|
const TAP_BIP32_DERIVATION = 22;
|
|
@@ -26,12 +36,12 @@ function assertAllowedDerivation(bip32Derivation, masterFingerprint, derivationP
|
|
|
26
36
|
const masterFingerprintToCheck = bip32Derivation.masterFingerprint.toString('hex');
|
|
27
37
|
const isOurMasterFingerprint = masterFingerprintToCheck === masterFingerprint;
|
|
28
38
|
if (isOurMasterFingerprint) {
|
|
29
|
-
assertBip44PathNumber(bip32Derivation.path);
|
|
30
|
-
const derivationPath = buildBip44PathFromNumber(bip32Derivation.path);
|
|
31
|
-
|
|
39
|
+
(0, derivation_paths_js_1.assertBip44PathNumber)(bip32Derivation.path);
|
|
40
|
+
const derivationPath = (0, derivation_paths_js_1.buildBip44PathFromNumber)(bip32Derivation.path);
|
|
41
|
+
(0, minimalistic_assert_1.default)(derivationPaths.includes(derivationPath), `found unsupported derivation path: ${derivationPath}`);
|
|
32
42
|
}
|
|
33
43
|
}
|
|
34
|
-
|
|
44
|
+
function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPathToPublicKeyMap, addressToDerivationPathMap) {
|
|
35
45
|
const masterFingerprintBuffer = Buffer.from(masterFingerprint, 'hex');
|
|
36
46
|
const scriptPubKeyToDerivationPathMap = computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap);
|
|
37
47
|
const derivationPathsToSignFor = [];
|
|
@@ -44,7 +54,7 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
44
54
|
}
|
|
45
55
|
else if (nonWitnessUtxo) {
|
|
46
56
|
const prevOutputIndex = psbt.getInputOutputIndex(inputIndex);
|
|
47
|
-
const decodedTransaction = Transaction.fromBuffer(nonWitnessUtxo);
|
|
57
|
+
const decodedTransaction = bitcoinjs_1.Transaction.fromBuffer(nonWitnessUtxo);
|
|
48
58
|
scriptPubKey = decodedTransaction.outs[prevOutputIndex].script;
|
|
49
59
|
}
|
|
50
60
|
else {
|
|
@@ -53,15 +63,15 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
53
63
|
let derivationPath = scriptPubKeyToDerivationPathMap[scriptPubKey.toString('hex')];
|
|
54
64
|
if (addressToDerivationPathMap && !derivationPath) {
|
|
55
65
|
try {
|
|
56
|
-
const address =
|
|
66
|
+
const address = bitcoinjs_1.address.fromOutputScript(scriptPubKey);
|
|
57
67
|
derivationPath = addressToDerivationPathMap[address];
|
|
58
68
|
}
|
|
59
69
|
catch { }
|
|
60
70
|
}
|
|
61
71
|
if (derivationPath) {
|
|
62
72
|
const publicKey = derivationPathToPublicKeyMap[derivationPath];
|
|
63
|
-
|
|
64
|
-
const derivationPathNumerical = splitBip44PathToNumber(derivationPath);
|
|
73
|
+
(0, minimalistic_assert_1.default)(Buffer.isBuffer(publicKey), `no public key found for derivation path`);
|
|
74
|
+
const derivationPathNumerical = (0, derivation_paths_js_1.splitBip44PathToNumber)(derivationPath);
|
|
65
75
|
if (isTaproot(scriptPubKey)) {
|
|
66
76
|
psbt.setInputTapBip32Derivation(inputIndex, publicKey.slice(1), [], masterFingerprintBuffer, derivationPathNumerical);
|
|
67
77
|
}
|
|
@@ -76,15 +86,15 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
76
86
|
let derivationPath = scriptPubKeyToDerivationPathMap[scriptPubKey.toString('hex')];
|
|
77
87
|
if (addressToDerivationPathMap && !derivationPath) {
|
|
78
88
|
try {
|
|
79
|
-
const address =
|
|
89
|
+
const address = bitcoinjs_1.address.fromOutputScript(scriptPubKey);
|
|
80
90
|
derivationPath = addressToDerivationPathMap[address];
|
|
81
91
|
}
|
|
82
92
|
catch { }
|
|
83
93
|
}
|
|
84
94
|
if (derivationPath) {
|
|
85
95
|
const publicKey = derivationPathToPublicKeyMap[derivationPath];
|
|
86
|
-
|
|
87
|
-
const derivationPathNumerical = splitBip44PathToNumber(derivationPath);
|
|
96
|
+
(0, minimalistic_assert_1.default)(Buffer.isBuffer(publicKey), `no public key found for derivation path`);
|
|
97
|
+
const derivationPathNumerical = (0, derivation_paths_js_1.splitBip44PathToNumber)(derivationPath);
|
|
88
98
|
if (isTaproot(scriptPubKey)) {
|
|
89
99
|
psbt.setOutputTapBip32Derivation(outputIndex, publicKey.slice(1), [], masterFingerprintBuffer, derivationPathNumerical);
|
|
90
100
|
}
|
|
@@ -98,37 +108,37 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
98
108
|
function computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap) {
|
|
99
109
|
return Object.entries(derivationPathToPublicKeyMap).reduce((acc, [derivationPath, publicKey]) => {
|
|
100
110
|
if (derivationPath.startsWith('m/44')) {
|
|
101
|
-
const p2pkh = payments.p2pkh({
|
|
111
|
+
const p2pkh = bitcoinjs_1.payments.p2pkh({
|
|
102
112
|
pubkey: publicKey,
|
|
103
113
|
}).output;
|
|
104
|
-
|
|
114
|
+
(0, minimalistic_assert_1.default)(p2pkh, 'failed to compute p2pkh scriptPubKey');
|
|
105
115
|
Object.assign(acc, {
|
|
106
116
|
[p2pkh.toString('hex')]: derivationPath,
|
|
107
117
|
});
|
|
108
118
|
}
|
|
109
119
|
else if (derivationPath.startsWith('m/49')) {
|
|
110
|
-
const nestedSegwit = payments.p2sh({
|
|
111
|
-
redeem: payments.p2wpkh({ pubkey: publicKey }),
|
|
120
|
+
const nestedSegwit = bitcoinjs_1.payments.p2sh({
|
|
121
|
+
redeem: bitcoinjs_1.payments.p2wpkh({ pubkey: publicKey }),
|
|
112
122
|
}).output;
|
|
113
|
-
|
|
123
|
+
(0, minimalistic_assert_1.default)(nestedSegwit, 'failed to compute p2sh scriptPubKey');
|
|
114
124
|
Object.assign(acc, {
|
|
115
125
|
[nestedSegwit.toString('hex')]: derivationPath,
|
|
116
126
|
});
|
|
117
127
|
}
|
|
118
128
|
else if (derivationPath.startsWith('m/84')) {
|
|
119
|
-
const p2wpkh = payments.p2wpkh({
|
|
129
|
+
const p2wpkh = bitcoinjs_1.payments.p2wpkh({
|
|
120
130
|
pubkey: publicKey,
|
|
121
131
|
}).output;
|
|
122
|
-
|
|
132
|
+
(0, minimalistic_assert_1.default)(p2wpkh, 'failed to compute p2wpkh scriptPubKey');
|
|
123
133
|
Object.assign(acc, {
|
|
124
134
|
[p2wpkh.toString('hex')]: derivationPath,
|
|
125
135
|
});
|
|
126
136
|
}
|
|
127
137
|
else if (derivationPath.startsWith('m/86')) {
|
|
128
|
-
const p2tr = payments.p2tr({
|
|
138
|
+
const p2tr = bitcoinjs_1.payments.p2tr({
|
|
129
139
|
internalPubkey: publicKey.slice(1),
|
|
130
140
|
}).output;
|
|
131
|
-
|
|
141
|
+
(0, minimalistic_assert_1.default)(p2tr, 'failed to compute p2tr scriptPubKey');
|
|
132
142
|
Object.assign(acc, {
|
|
133
143
|
[p2tr.toString('hex')]: derivationPath,
|
|
134
144
|
});
|
|
@@ -139,16 +149,17 @@ function computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap) {
|
|
|
139
149
|
function isTaproot(scriptPubKey) {
|
|
140
150
|
return scriptPubKey.length === 34 && scriptPubKey.at(0) === 0x51 && scriptPubKey.at(1) === 0x20;
|
|
141
151
|
}
|
|
142
|
-
|
|
152
|
+
const getWalletPolicy = (fpr, xpub, purpose, coin, account) => {
|
|
143
153
|
const desc = {
|
|
144
154
|
"44'": 'pkh(@0/**)',
|
|
145
155
|
"49'": 'sh(wpkh(@0/**))',
|
|
146
156
|
"84'": 'wpkh(@0/**)',
|
|
147
157
|
"86'": 'tr(@0/**)',
|
|
148
158
|
}[purpose];
|
|
149
|
-
return new DefaultWalletPolicy(desc, `[${fpr}/${purpose}/${coin}/${account}]${xpub}`);
|
|
159
|
+
return new ledger_bitcoin_1.DefaultWalletPolicy(desc, `[${fpr}/${purpose}/${coin}/${account}]${xpub}`);
|
|
150
160
|
};
|
|
151
|
-
|
|
161
|
+
exports.getWalletPolicy = getWalletPolicy;
|
|
162
|
+
const getMultisigWalletPolicy = (fpr, xpub, purpose, coin, account, multisigData) => {
|
|
152
163
|
let template = `tr(@0/**,sortedmulti_a(${multisigData.threshold}`;
|
|
153
164
|
const keys = [multisigData.internalXpub];
|
|
154
165
|
multisigData.xpubs.forEach((xpub2, i) => {
|
|
@@ -161,10 +172,11 @@ export const getMultisigWalletPolicy = (fpr, xpub, purpose, coin, account, multi
|
|
|
161
172
|
template += `,@${i + 1}/**`;
|
|
162
173
|
});
|
|
163
174
|
template += '))';
|
|
164
|
-
return new WalletPolicy('Multisig', template, keys);
|
|
175
|
+
return new ledger_bitcoin_1.WalletPolicy('Multisig', template, keys);
|
|
165
176
|
};
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
exports.getMultisigWalletPolicy = getMultisigWalletPolicy;
|
|
178
|
+
async function derivationPathsToWalletPolicy(fpr, app, derivationPaths, multisigData) {
|
|
179
|
+
const splittedDerivationPaths = derivationPaths.map(derivation_paths_js_1.splitBip44DerivationPath);
|
|
168
180
|
const dedupedPaths = Object.values(splittedDerivationPaths.reduce((prev, splittedDerivationPath) => {
|
|
169
181
|
const [purpose, coin, account] = splittedDerivationPath;
|
|
170
182
|
prev[[purpose, coin, account].toString()] = [purpose, coin, account];
|
|
@@ -175,10 +187,10 @@ export async function derivationPathsToWalletPolicy(fpr, app, derivationPaths, m
|
|
|
175
187
|
const [purpose, coin, account] = dedupedPath;
|
|
176
188
|
const xpub = await app.getExtendedPubkey(`m/${purpose}/${coin}/${account}`);
|
|
177
189
|
if (multisigData) {
|
|
178
|
-
walletPolicies.push(getMultisigWalletPolicy(fpr, xpub, purpose, coin, account, multisigData));
|
|
190
|
+
walletPolicies.push((0, exports.getMultisigWalletPolicy)(fpr, xpub, purpose, coin, account, multisigData));
|
|
179
191
|
}
|
|
180
192
|
else {
|
|
181
|
-
walletPolicies.push(getWalletPolicy(fpr, xpub, purpose, coin, account));
|
|
193
|
+
walletPolicies.push((0, exports.getWalletPolicy)(fpr, xpub, purpose, coin, account));
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
196
|
return walletPolicies;
|
|
@@ -194,7 +206,7 @@ function canModifyInputs(psbt) {
|
|
|
194
206
|
}
|
|
195
207
|
return true;
|
|
196
208
|
}
|
|
197
|
-
|
|
209
|
+
function addDummyInputs(psbt) {
|
|
198
210
|
const canAddDummy = canModifyInputs(psbt);
|
|
199
211
|
if (!canAddDummy) {
|
|
200
212
|
return;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildFauxXPUB = buildFauxXPUB;
|
|
4
|
+
const base58check_js_1 = require("@exodus/bytes/base58check.js");
|
|
5
|
+
function buildFauxXPUB(publicKey, chainCode) {
|
|
3
6
|
const LEN = 78;
|
|
4
7
|
const XPUB_PREFIX = 0x04_88_b2_1e;
|
|
5
8
|
const buffer = Buffer.alloc(LEN);
|
|
@@ -12,5 +15,5 @@ export function buildFauxXPUB(publicKey, chainCode) {
|
|
|
12
15
|
buffer.writeUInt32BE(index, 9);
|
|
13
16
|
chainCode.copy(buffer, 13);
|
|
14
17
|
publicKey.copy(buffer, 45);
|
|
15
|
-
return toBase58checkSync(buffer);
|
|
18
|
+
return (0, base58check_js_1.toBase58checkSync)(buffer);
|
|
16
19
|
}
|
package/lib/module/constants.js
CHANGED
package/lib/module/device.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnsureDeviceReadyParams, GetAddressParams, GetPublicKeyParams, GetXPubParams, HardwareWalletDescriptor, HardwareWalletDevice, SignMessageParams, SignTransactionParams } from '@exodus/hw-common';
|
|
2
|
-
import type { TransportFactory } from './types';
|
|
2
|
+
import type { TransportFactory } from './types.js';
|
|
3
3
|
import type { Atom } from '@exodus/atoms';
|
|
4
4
|
export type Dependencies = {
|
|
5
5
|
transportFactory: TransportFactory;
|
|
@@ -19,6 +19,6 @@ export declare class LedgerDevice implements HardwareWalletDevice {
|
|
|
19
19
|
getAddress: (params: GetAddressParams) => Promise<string>;
|
|
20
20
|
getXPub: (params: GetXPubParams) => Promise<string>;
|
|
21
21
|
getPublicKey: (params: GetPublicKeyParams) => Promise<Readonly<Uint8Array<ArrayBufferLike>>>;
|
|
22
|
-
signTransaction: (params: SignTransactionParams) => Promise<import("@exodus/hw-common").Signatures>;
|
|
22
|
+
signTransaction: (params: SignTransactionParams) => Promise<import("@exodus/hw-common", { with: { "resolution-mode": "import" } }).Signatures>;
|
|
23
23
|
signMessage: (params: SignMessageParams) => Promise<Readonly<Uint8Array<ArrayBufferLike>>>;
|
|
24
24
|
}
|