@exodus/hw-ledger 3.3.0 → 3.4.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/CHANGELOG.md +13 -0
- package/lib/module/assets/applications.d.ts +5 -0
- package/lib/module/assets/applications.js +6 -0
- package/lib/module/assets/index.js +2 -0
- package/lib/module/assets/tronmainnet.d.ts +19 -0
- package/lib/module/assets/tronmainnet.js +60 -0
- package/lib/module/assets/utils/psbt.js +46 -19
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.4.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.3.1...@exodus/hw-ledger@3.4.0) (2024-10-30)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add Tron support to ledger ([#10108](https://github.com/ExodusMovement/exodus-hydra/issues/10108)) ([ce6cace](https://github.com/ExodusMovement/exodus-hydra/commit/ce6cace76803c08841976cfa7fc2f8e2ea346923))
|
|
11
|
+
- drop unused exports from bip322 ([#10142](https://github.com/ExodusMovement/exodus-hydra/issues/10142)) ([6c1a268](https://github.com/ExodusMovement/exodus-hydra/commit/6c1a2687130bdf88ff78c38a599c950c84ae8f60))
|
|
12
|
+
|
|
13
|
+
## [3.3.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.3.0...@exodus/hw-ledger@3.3.1) (2024-10-24)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- support legacy transaction signing ([#10154](https://github.com/ExodusMovement/exodus-hydra/issues/10154)) ([55c3d63](https://github.com/ExodusMovement/exodus-hydra/commit/55c3d63e809397b94aa08309b03715fe6d0ed831))
|
|
18
|
+
|
|
6
19
|
## [3.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.2.0...@exodus/hw-ledger@3.3.0) (2024-10-22)
|
|
7
20
|
|
|
8
21
|
### Features
|
|
@@ -18,10 +18,16 @@ const Polygon = {
|
|
|
18
18
|
supportedVersions: '^1.10.0',
|
|
19
19
|
primaryAssetName: 'matic',
|
|
20
20
|
};
|
|
21
|
+
const Tron = {
|
|
22
|
+
applicationName: 'Tron',
|
|
23
|
+
supportedVersions: '^0.7.0',
|
|
24
|
+
primaryAssetName: 'tronmainnet',
|
|
25
|
+
};
|
|
21
26
|
const applications = {
|
|
22
27
|
Bitcoin,
|
|
23
28
|
Solana,
|
|
24
29
|
Ethereum,
|
|
25
30
|
Polygon,
|
|
31
|
+
Tron,
|
|
26
32
|
};
|
|
27
33
|
export default applications;
|
|
@@ -3,6 +3,7 @@ import basemainnet from './basemainnet';
|
|
|
3
3
|
import ethereum from './ethereum';
|
|
4
4
|
import matic from './matic';
|
|
5
5
|
import solana from './solana';
|
|
6
|
+
import tronmainnet from './tronmainnet';
|
|
6
7
|
import applications from './applications';
|
|
7
8
|
export const assetApplications = {
|
|
8
9
|
basemainnet,
|
|
@@ -13,6 +14,7 @@ export const assetApplications = {
|
|
|
13
14
|
solana,
|
|
14
15
|
ethereum,
|
|
15
16
|
ethereumsepolia: ethereum,
|
|
17
|
+
tronmainnet,
|
|
16
18
|
};
|
|
17
19
|
export const supportedBaseAssetNames = Object.keys(assetApplications);
|
|
18
20
|
export const applicationNameToBaseAssetNames = Object.entries(assetApplications).reduce((mapping, [assetName, metadata]) => {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type Transport from '@ledgerhq/hw-transport';
|
|
2
|
+
import type { Bytes, HardwareWalletAssetHandler } from '@exodus/hw-common';
|
|
3
|
+
export interface TronMessage {
|
|
4
|
+
rawMessage?: Bytes;
|
|
5
|
+
TIP712Message?: {
|
|
6
|
+
address: string;
|
|
7
|
+
message: Bytes;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
declare function createHandler(transport: Transport): Promise<HardwareWalletAssetHandler<TronMessage>>;
|
|
11
|
+
declare const metadata: {
|
|
12
|
+
applications: {
|
|
13
|
+
applicationName: string;
|
|
14
|
+
supportedVersions: string;
|
|
15
|
+
primaryAssetName: string;
|
|
16
|
+
}[];
|
|
17
|
+
handler: typeof createHandler;
|
|
18
|
+
};
|
|
19
|
+
export default metadata;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import AppTron from '@ledgerhq/hw-app-trx';
|
|
2
|
+
import assert from 'minimalistic-assert';
|
|
3
|
+
import { XPubUnsupportedError } from '@exodus/hw-common';
|
|
4
|
+
import * as secp256k1 from '@exodus/crypto/secp256k1';
|
|
5
|
+
import applications from './applications';
|
|
6
|
+
async function createHandler(transport) {
|
|
7
|
+
const app = new AppTron(transport);
|
|
8
|
+
const getAddress = async (params) => {
|
|
9
|
+
const { address } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
10
|
+
return address;
|
|
11
|
+
};
|
|
12
|
+
const getXPub = async (params) => {
|
|
13
|
+
throw new XPubUnsupportedError();
|
|
14
|
+
};
|
|
15
|
+
const getPublicKey = async (params) => {
|
|
16
|
+
const { publicKey } = await app.getAddress(params.derivationPath.replace('m/', ''));
|
|
17
|
+
return secp256k1.publicKeyConvert({
|
|
18
|
+
publicKey: Buffer.from(publicKey, 'hex'),
|
|
19
|
+
compressed: true,
|
|
20
|
+
format: 'buffer',
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const signTransaction = async (params) => {
|
|
24
|
+
assert(Array.isArray(params.derivationPaths) && params.derivationPaths.length === 1, 'derivationsPath array must be one element long');
|
|
25
|
+
if (!Buffer.isBuffer(params.signableTransaction)) {
|
|
26
|
+
throw new TypeError(`signableTransaction must be Buffer or serializable to a Buffer.`);
|
|
27
|
+
}
|
|
28
|
+
const signature = await app.signTransaction(params.derivationPaths[0].replace('m/', ''), params.signableTransaction.toString('hex'), []);
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
signature: Buffer.from(signature, 'hex'),
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
};
|
|
35
|
+
const signMessage = async (params) => {
|
|
36
|
+
if (params.message.rawMessage) {
|
|
37
|
+
assert(Buffer.isBuffer(params.message.rawMessage), 'rawMessage must be a buffer');
|
|
38
|
+
const signature = await app.signPersonalMessage(params.derivationPath.replace('m/', ''), params.message.rawMessage.toString('hex'));
|
|
39
|
+
return Buffer.from(signature, 'hex');
|
|
40
|
+
}
|
|
41
|
+
if (params.message.TIP712Message) {
|
|
42
|
+
throw new Error('TIP712 messages are not yet supported');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
assert(false, 'rawMessage or TIP712Message must be specified');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
getAddress,
|
|
50
|
+
getPublicKey,
|
|
51
|
+
getXPub,
|
|
52
|
+
signTransaction,
|
|
53
|
+
signMessage,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const metadata = {
|
|
57
|
+
applications: [applications.Tron],
|
|
58
|
+
handler: createHandler,
|
|
59
|
+
};
|
|
60
|
+
export default metadata;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert';
|
|
2
2
|
import { DefaultWalletPolicy, WalletPolicy } from '@exodus/ledger-bitcoin';
|
|
3
|
-
import { payments, address as baddress } from '@exodus/bitcoinjs';
|
|
3
|
+
import { payments, address as baddress, Transaction } from '@exodus/bitcoinjs';
|
|
4
4
|
import { buildBip44PathFromNumber, assertBip44PathNumber, splitBip44PathToNumber, splitBip44DerivationPath, } from './derivation-paths';
|
|
5
5
|
export function assertPsbtOnlyHasAllowedDerivationPaths(psbt, masterFingerprint, derivationPaths) {
|
|
6
6
|
for (let i = 0; i < psbt.getGlobalInputCount(); i++) {
|
|
@@ -36,12 +36,23 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
36
36
|
const scriptPubKeyToDerivationPathMap = computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap);
|
|
37
37
|
for (let inputIndex = 0; inputIndex < psbt.getGlobalInputCount(); inputIndex++) {
|
|
38
38
|
const witnessUtxo = psbt.getInputWitnessUtxo(inputIndex);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const nonWitnessUtxo = psbt.getInputNonWitnessUtxo(inputIndex);
|
|
40
|
+
let scriptPubKey;
|
|
41
|
+
if (witnessUtxo) {
|
|
42
|
+
scriptPubKey = witnessUtxo.scriptPubKey;
|
|
43
|
+
}
|
|
44
|
+
else if (nonWitnessUtxo) {
|
|
45
|
+
const prevOutputIndex = psbt.getInputOutputIndex(inputIndex);
|
|
46
|
+
const decodedTransaction = Transaction.fromBuffer(nonWitnessUtxo);
|
|
47
|
+
scriptPubKey = decodedTransaction.outs[prevOutputIndex].script;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error('missing witnessUtxo or nonWitnessUtxo');
|
|
51
|
+
}
|
|
52
|
+
let derivationPath = scriptPubKeyToDerivationPathMap[scriptPubKey.toString('hex')];
|
|
42
53
|
if (addressToDerivationPathMap && !derivationPath) {
|
|
43
54
|
try {
|
|
44
|
-
const address = baddress.fromOutputScript(
|
|
55
|
+
const address = baddress.fromOutputScript(scriptPubKey);
|
|
45
56
|
derivationPath = addressToDerivationPathMap[address];
|
|
46
57
|
}
|
|
47
58
|
catch { }
|
|
@@ -50,7 +61,7 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
50
61
|
const publicKey = derivationPathToPublicKeyMap[derivationPath];
|
|
51
62
|
assert(Buffer.isBuffer(publicKey), `no public key found for derivation path`);
|
|
52
63
|
const derivationPathNumerical = splitBip44PathToNumber(derivationPath);
|
|
53
|
-
if (isTaproot(
|
|
64
|
+
if (isTaproot(scriptPubKey)) {
|
|
54
65
|
psbt.setInputTapBip32Derivation(inputIndex, publicKey.slice(1), [], masterFingerprintBuffer, derivationPathNumerical);
|
|
55
66
|
}
|
|
56
67
|
else {
|
|
@@ -83,25 +94,41 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
83
94
|
}
|
|
84
95
|
function computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap) {
|
|
85
96
|
return Object.entries(derivationPathToPublicKeyMap).reduce((acc, [derivationPath, publicKey]) => {
|
|
86
|
-
if (derivationPath.startsWith('m/
|
|
87
|
-
const
|
|
97
|
+
if (derivationPath.startsWith('m/44')) {
|
|
98
|
+
const p2pkh = payments.p2pkh({
|
|
88
99
|
pubkey: publicKey,
|
|
89
100
|
}).output;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
assert(p2pkh, 'failed to compute p2pkh scriptPubKey');
|
|
102
|
+
Object.assign(acc, {
|
|
103
|
+
[p2pkh.toString('hex')]: derivationPath,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else if (derivationPath.startsWith('m/49')) {
|
|
107
|
+
const nestedSegwit = payments.p2sh({
|
|
108
|
+
redeem: payments.p2wpkh({ pubkey: publicKey }),
|
|
109
|
+
}).output;
|
|
110
|
+
assert(nestedSegwit, 'failed to compute p2pkh scriptPubKey');
|
|
111
|
+
Object.assign(acc, {
|
|
112
|
+
[nestedSegwit.toString('hex')]: derivationPath,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
else if (derivationPath.startsWith('m/84')) {
|
|
116
|
+
const p2wpkh = payments.p2wpkh({
|
|
117
|
+
pubkey: publicKey,
|
|
118
|
+
}).output;
|
|
119
|
+
assert(p2wpkh, 'failed to compute p2wpkh scriptPubKey');
|
|
120
|
+
Object.assign(acc, {
|
|
121
|
+
[p2wpkh.toString('hex')]: derivationPath,
|
|
122
|
+
});
|
|
95
123
|
}
|
|
96
124
|
else if (derivationPath.startsWith('m/86')) {
|
|
97
|
-
const
|
|
125
|
+
const p2tr = payments.p2tr({
|
|
98
126
|
internalPubkey: publicKey.slice(1),
|
|
99
127
|
}).output;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
128
|
+
assert(p2tr, 'failed to compute p2tr scriptPubKey');
|
|
129
|
+
Object.assign(acc, {
|
|
130
|
+
[p2tr.toString('hex')]: derivationPath,
|
|
131
|
+
});
|
|
105
132
|
}
|
|
106
133
|
return acc;
|
|
107
134
|
}, Object.create(null));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/hw-ledger",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "The ledger module",
|
|
5
5
|
"author": "Exodus Movement, Inc.",
|
|
6
6
|
"repository": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@exodus/ledgerhq-hw-app-eth": "^6.33.7-exodus.8",
|
|
42
42
|
"@exodus/redux-dependency-injection": "^4.0.0",
|
|
43
43
|
"@ledgerhq/hw-app-solana": "^7.0.10",
|
|
44
|
+
"@ledgerhq/hw-app-trx": "^6.29.4",
|
|
44
45
|
"@ledgerhq/hw-transport": "^6.28.5",
|
|
45
46
|
"@metamask/eth-sig-util": "^4.0.1",
|
|
46
47
|
"bs58": "^4.0.0",
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
"redux": "^4.2.1",
|
|
65
66
|
"tiny-secp256k1": "^2.2.3"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "6e5284fe84bcaee8b2640f98ea0bf2f19db5e5ff"
|
|
68
69
|
}
|