Title: Python script to extract information from Peach wallet/software Post by: darkv0rt3x on May 16, 2024, 08:41:29 AM Hello.
So, this Peach piece of software to purchase Bitcoin via P2P. It has a non-custodial HD wallet. But as far as I know, it doesn't allow you to see your Bitcoin addresses and PKs. It allows you to backup the wallet with an encrypted file. So, I tried 2 things: 1 - Try to get the PKs out of the seed prase 2 - Try to check if the backup file would have the PKs in plain text after decryption Not needed to say that I couldn't make any of them to work, at least to get the PKs like Bitcoin Core shows when we use dumpprivkey, which if I'm not mistaken, is the random number in hex format and base58 enconded. As a starting point I went to Peach Github and tried to figure out which functions I coul be interested in. I found a couple. https://github.com/Peach2Peach/peach-app/blob/develop/src/utils/wallet/getDescriptorSecretKey.ts Code: import { DescriptorSecretKey, Mnemonic } from "bdk-rn"; https://github.com/Peach2Peach/peach-app/blob/develop/src/utils/file/writeFile.ts Code: import RNFS from "react-native-fs"; And also: https://github.com/Peach2Peach/peach-app/blob/develop/src/utils/file/readChunkOfFile.ts Code: import RNFS from "react-native-fs"; I know nothing about TypeScript and my Python knowledge is also quite limited. And I also don't know all details and aspects of HD wallets, derivation paths, etc, so I went for chatGPT for some help. I already knew about bitcoinlib python library so I asked chatGPT to use that library and after some adjustments I got one of the codes working for situation 1 where I provide the seed and I get the keys out. However, what the code gives me is an extended private key, as far as I can tell. And that's not what I'm looking for. This is the code I got working and returning the zrpv key: Code: from bitcoinlib.wallets import Wallet, wallet_create_or_open The output I get from this script is: Quote Wallet 'My Wallet' was deleted. Wallet Info: Address: bc1qd.........my Key: <WalletKey(key_id=8, name=address index 2, wif=zprvAh.......PU7v, path=m/84'/0'/0'/0/2)> As a last resort, I imported the seed phrase into Electrum and from there, I can get all the PKs of the wallet. So, what do I need to change to get the keys in Base58 format? Or what can I do to achieve my goal? Edited; There was someone that gave me a JavaScript code but I don't know how to work with JavaScript and I also tried to convert his function to Python but I got some UTF8 encoding issue that I didn't spend too much time trying to fix. Code: const CryptoJS = require('crypto-js'); Title: Re: Python script to exrtract information from Peach wallet/software Post by: darkv0rt3x on May 17, 2024, 10:46:26 PM So, I'm a little bit closer but the private key is still wrong and is presenting actually an extended public key instead:
Code: from bitcoinlib.keys import HDKey But the output I get is this: Quote Private key (WIF): xpub6Gds........................................NcHTzM Bitcoin address: bc1qn8l7k52dsl2kmpemq8ualqpc3uk8lyvt7grmyp So, ig anyone knows how to make this write, please gimme a help! :) Title: Re: Python script to exrtract information from Peach wallet/software Post by: darkv0rt3x on May 18, 2024, 09:41:26 AM A further bit closer. I can now obtain a PK in the format I want. It's just that it's not the correct PK.
The private key I'm looking for is: Quote KxEd..............B9L and the one I'm getting is: Quote 33.................3cZ This is the code I have now: Code: from bitcoinlib.keys import HDKey Title: Re: Python script to exrtract information from Peach wallet/software Post by: nc50lc on May 18, 2024, 11:54:58 AM The private key I'm looking for is: That's because WIF isn't just ECDSA Private key encoded to base58. (you've asked ChatGPT?)Quote KxEd..............B9L and the one I'm getting is: Quote 33.................3cZ It needs to have a "network byte", "compression flag" (to tell clients to derive compressed pubKey) and a 4-Byte "checksum". To do that, you can also use "bitcoinlib.encoding" and import "double_sha256" to calculate the checksum. With that, add these to your code: (remove 'print' if you do not want to output those) Code: . Title: Re: Python script to exrtract information from Peach wallet/software Post by: darkv0rt3x on May 19, 2024, 08:47:31 AM The private key I'm looking for is: That's because WIF isn't just ECDSA Private key encoded to base58. (you've asked ChatGPT?)Quote KxEd..............B9L and the one I'm getting is: Quote 33.................3cZ It needs to have a "network byte", "compression flag" (to tell clients to derive compressed pubKey) and a 4-Byte "checksum". To do that, you can also use "bitcoinlib.encoding" and import "double_sha256" to calculate the checksum. With that, add these to your code: (remove 'print' if you do not want to output those) Code: . Well, who knows, knows... Thank you. It computed correctly the private key in the format I wanted. Thank you Title: Re: Python script to extract information from Peach wallet/software Post by: Cricktor on May 19, 2024, 10:56:56 AM Do you mind correcting your spelling error (exrtract) in your thread's title? It hampers searching by keywords in thread titles somewhat and on a minor level it's also maybe a bit embarrassing to have errors in such prominent locations. You could also lock this thread, now that you got a working solution.
Title: Re: Python script to extract information from Peach wallet/software Post by: darkv0rt3x on May 19, 2024, 09:46:05 PM Do you mind correcting your spelling error (exrtract) in your thread's title? It hampers searching by keywords in thread titles somewhat and on a minor level it's also maybe a bit embarrassing to have errors in such prominent locations. You could also lock this thread, now that you got a working solution. Those typos comes from my laptop keyboard having some keys almost dead and I almot have to hammer them to make them to work. And then, what happens is that other keys also get pressed when I hammer the one I wanted. If I know ow to lock it, I'll will! Thanks |