-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
actions: Add ledger backend functions. #3869
Conversation
7278544
to
5ab2419
Compare
This comment was marked as outdated.
This comment was marked as outdated.
5ab2419
to
0a458f1
Compare
0a458f1
to
b1c1525
Compare
e18069f
to
32050eb
Compare
32050eb
to
afece2a
Compare
I changed the helper method a bit so need to fix the tests then should be good. |
6e1d68c
to
aed9703
Compare
app/helpers/ledger.js
Outdated
// bitshift right (>>>) does not seem to throw away the lower half, so | ||
// subtracting. | ||
const upper = n - lower; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, this doesnt work. hmm..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division with the max uint32 works correct? What is the correct syntax to bitshift right though? Is it not n>>32
or n>>>32
?
Not using Buffer.writeUint64LE
as this version of Buffer does not seem to have it.
aed9703
to
bfdb28b
Compare
@matheusd ok, I'll look into it... |
@matheusd it looks like we might need electron/electron#36289 We are using whats in the package.json And of course it breaks if I try to update. |
Definitely working with electron v23.3.8. I guess I will put up a pr increasing the version and see what happens. #3884 |
bfdb28b
to
632d455
Compare
Now using "@ledgerhq/hw-transport-webusb" and everything looks alot better. Glad we took this route. |
app/actions/LedgerActions.js
Outdated
// TODO: Enable on mainnet. | ||
const isTestnet = true; | ||
try { | ||
const payload = await getAddress("44'/42'/0'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of btc.getWalletPublicKey()
(which is what this call cashes out into), maybe you could use btc.getWalletXpub()
?
I haven't thoroughly checked the correctness of the next line's call to pubkeyToHDPubkey()
, but I'd be very afraid a mistake in there is going to render the resulting wallet either unusable or incompatible to other software, making recovery of the funds using other software impossible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally missed getWalletXpub
, thank you. Now using that. It uses a sha256 checksum so replacing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependencies look ok to me now!
632d455
to
77583e9
Compare
// fixPubKeyChecksum replaces the sha256 checksum, or last four bytes, of a | ||
// pubkey with a blake256 checksum. | ||
export function fixPubKeyChecksum(pubKey) { | ||
const buff = bs58.decode(pubKey).slice(0, -4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make it into a valid xpub, ok.
However, this means you can't go from seed to wallet using the standard decred software or my BIP0039 -> raw seed tool.
My concern here is that, if the user (say) gets its ledger stolen and wants to withdraw all funds as fast as possible using only software, there will be no fully compatible software to do so, because this particular path from mnemonic seed -> raw seed bytes -> account is not replicated on any software.
At the very least we'll need a tool that can go from the ledger mnemonic seed to either a raw seed or account xprivs that can be imported into decrediton/dcrwallet so that we can accurately recreate the wallet in software only if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, this means you can't go from seed to wallet using the standard decred software or my BIP0039 -> raw seed tool.
Where was the tool again? In the decred repo? I'm unsure why it would not work but I trust you are correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matheusd I was able to use the tool at https://github.com/matheusd/bip39-to-dcr-seed to restore a decred wallet from seed.
I made a mainnet wallet with decrediton and ledger. Send it a small amount of funds. After restoring using your tool, the seed words, and dcrwallet I was able to access the funds. It works!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should mention that the tool will not work on testnet because the ledger testnet app forces cointype 42' although dcrwallet wants 1'. This is fine for mainnet though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that testnet cointype restriction apply even if you change the following line:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change "44'/42'/0'" to "44'/1'/0'"? Ledger will give me the error "Ledger device: Internal error, please report (0x6f15)"
.
77583e9
to
f615386
Compare
Just removed the origin here and it is working for the package https://github.com/decred/decrediton/compare/77583e96a8774c61c8ee2a3c4891216e93b24410..f6153862fef4af2b2622e264916cce7abf636059 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been testing this for bit in both Linux and Windows, and while there are a few testing nits, this is good to go as a first pass implementation.
This is currently disabled in mainnet, so we'll keep iterating on it.
if (numOuts > 2) { | ||
throw "more than two outputs is not expected"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok if we don't support more than two outputs in the first version, but we really should eventually support it (unless ledger itself limits this somehow).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buff.set(writeUint16LE(out.version), i); | ||
i += 2; | ||
// TODO: Clean this up for production? Should use smarter logic to get varInts? | ||
buff[i] = out.script.length; // varInt for 23/25 bytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this won't be a problem for standard outputs, because the varints for 23/25 bytes is itself, but could be an issue in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Leaving for now...
f615386
to
74284d2
Compare
part of #3865