Hy everyone,
I'm doing a hd wallet generator (normal child) with only use xpub key. Therefore, can someone help me pls. With library of golang or main flow of generating from: (xpub key, index) -> ethereum address
Example:
- Master public key
xpub661MyMwAqRbcEchqhvjmDox2feNsqWwWTw4hWTemBx9asYS8r9SYKUkZr4a2DkEE7UpeZMhqcX4EsxDpEQBJTjn2ytnZ5EBnj6H8gf4S9P6
- index: 0 (or path m/0)
0xB6ff335fa47F0e3dC6491f21a02527dDc3bd21d3
Related
We are using BlockCypher API to create transaction in a HD Wallet.
As a return object, you'll receive a TXSkeleton containing a
slightly-more complete TX alongside data you need to sign in the
tosign array. You'll need this object for the next steps of the
transaction creation process.
Locally Sign Your Transaction
With your TXSkeleton returned from the New Transaction Endpoint, you
now need to use your private key(s) to sign the data provided in the
tosign array.
$PRIVATEKEY here is a hex-encoded private key corresponding to the input from address CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9
My problem is how do we obtain the private key of each address in HD Wallet? With HD Wallet addresses are generated using the Derive Address Endpoint. This returns a HDWallet object which contains and HDChain object which contains an HDAddress Object. The HDAddress object contains address, path and public.
An HD Address object contains an address and its BIP32 HD path
(location of the address in the HD tree). It also contains the
hex-encoded public key when returned from the Derive Address in Wallet
endpoint.
As you can see, the private key is not included in HDAddress object response. So how can we know the private key to use with tosign method if the private key is not included in HDAddress object response? And without access to private key, how can we sign the **tosign** array?
Thanks
I have investigated and played with corda-settler project. Following the recommendations within the documentation, I have created a custom ethereum module (with an outline similar to the ripple module), providing the option to settle obligations using off-ledger payments in ETH. The implementation (https://github.com/vladichhh/corda-settler)
consists of the following significant pieces:
flows
MakeEthPayment
services
ETHClient
ETHService
types
EthPayment
EthSettlement
token
registered DigitalCurrency for ETH
oracle
added logic for ETH payment verification
MakeEthPayment.kt
#Suspendable
override fun makePayment(obligation: Obligation<*>, amount: Amount<T>): EthPayment<T> {
// get ETHService client
val ethClient = serviceHub.cordaService(ETHService::class.java).client
val recipient = obligation.settlementMethod?.accountToPay.toString()
val amountToSend = amount.quantity.toString()
// trigger ETH transfer
val txHash = ethClient.sendEth(recipient, amountToSend)
// return the payment
return EthPayment(txHash, amount, PaymentStatus.SENT)
}
ETHClient.kt
fun sendEth(recipient: String, amount: String): String {
val weiAmount: BigInteger = Convert.toWei(amount, Convert.Unit.GWEI).toBigInteger()
val credentials: Credentials = WalletUtils.loadCredentials(walletPassword, walletFile)
val transactionReceipt: TransactionReceipt = Transfer
.sendFunds(web3j, credentials, recipient, BigDecimal(weiAmount), Convert.Unit.WEI)
.send()
return transactionReceipt.transactionHash
}
In order to send the required ETH amount to the specified recipient account, we have to do some Ethereum specific stuff:
we are connecting to Ethereum public blockchain environment, using “web3j” library
in order to trigger am Etherem transaction and transfer specified ETH amount, "web3j" requires an access to the file, containing encrypted sender's wallet
thus we have to provide password (to decrypt wallet) and location of the file, containing encrypted sender's wallet
And here are the issues:
I got the exception that the file could not be found, no matter where I am putting it. I have checked even the “swift” implementation and tried to use the class loader to load my file, but without success.
I suppose, the file with encrypted sender’s wallet should be located on one of the following places:
corda-settler/ethereum/src/main/resources/file.tmp
corda-settler/cordapp/src/main/resources/file.tmp
Finally I have hardcoded the location in that way:
/Users/vladimirhristov/WebstormProjects/Corda/corda-settler/cordapp/src/main/resources/file.tmp
and seems that the file was found but got another exception:
java.lang.OutOfMemoryError - screenshot
Seems that the operation of wallet decryption is highly consuming, which breaks maybe the flow. There is an option to reduce the algorithm complexity of the wallet generation, which will reflect in lower resources required to decrypt the same wallet at the next step, but this will reduce the security as well.
And here are my three basic questions ...
How could I specify (location/mechanism) and make flow to find successfully my file, containing the sender’s encrypted wallet ?
How could I access a files in the flow, or if there is another mechanism to attach only the file with encrypted wallet and pass the decryption to core Corda ?
Do I need just to increase node resources (tuning JVM params increasing -Xms/-Xmx) in order to avoid OutOfMemoryError ?
Content of the file (containing encrypted sender’s wallet):
file.tmp
{"version":3,"id":"ecb51768-8564-498a-bb11-3a5a5c8dc0bb","address":"2bafc482bd227dfd5ba250521a00be3a4cc88bbd","crypto":{"ciphertext":"e0511415792dfa7221ba1b8f32b8ec98e1410f45e612e2100df1aceddfdb22bd","cipherparams":{"iv":"7ffa2af08f502c63d57e62440ad77539"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"8051a5df1c02eb3eba81d2920fbb84b76b948a1248bbba62ffff684e733948cf","n":131072,"r":8,"p":1},"mac":"be23fe0e261ba38892581d80afd0c86563748377b5cc702b6ed3285a13cceff6"}}
I will appreciate any help! Thanks in advance :)
VERY strange that Corda is giving you an out of memory error when running that flow.
I'd actually say that we'd need to be able to see the code for the flow in order to know how it could have run out of memory.
Are you running it in a container? Just make sure that you're meeting the requirements to run a JVM with an application on top.
tl;dr use a 8GB RAM machine to run your Corda node on the latest version of corda that should hopefully solve this issue.
Here's the docs page on the memory requirements;
https://docs.corda.net/docs/corda-enterprise/4.5/node/performance-results.html#sizing
I am trying to understand the usage of SCP DEK in store data command.
As per GP Card spec 2.2.1- "The data encryption key (DEK) for decrypting sensitive data, e.g. secret or private keys. This key is a double length DES key and is used as a static key."
I requirement to encrypt the Store data APDU data. Now I have 3 questions
Is indeed SCP DEK used to encrypt EMV AUKs (Application Unique Keys) present in one of these store data commands?
If statement #1 is correct the which key is used to encrypt data field in the APDU?
Is the an indicator in commands prior to store data which says that data field in store data command would be Encrypted or NOT?
I would be able to set store data CLA, INS, P1 and P2 as per GP card 2.2.1 and Amendment D spec.
Asking this question here since crypto.stackexchange does not have global platform and cryptography tags
Any help is appreciated
Nevermind, I found answer
Yes
S-ENC Secure Channel Protocol '03' – Public Release v1.1.1
section 6.2.6 APDU Command C-MAC and C-DECRYPTION Generation and
Verification
External Authenticate command P1 as per 7.1.2.1 Reference Control Parameter P1 – Security Level - (Encrypted value =03 - C-DECRYPTION and C-MAC/ Clear value = 01 - C-MAC)
Is there a way to check a wallet balance from the 1st generated address (parent address) not knowing the child addresses? Need to do it automatically from Linux (API-style) not copy-paste in browser.
Parent address: 1H7wwfstu4e8yianuPtk9CSxUonq4pzLju
0 BTC
Child address: 14ZcreY3y3XxcsRCzfvzz6fWZfBTp6a2ZX
0.00336455 BTC
$ curl -s 'https://blockchain.info/q/addressbalance/1H7wwfstu4e8yianuPtk9CSxUonq4pzLju'
0
$ curl -s 'https://blockchain.info/q/addressbalance/14ZcreY3y3XxcsRCzfvzz6fWZfBTp6a2ZX'
336455
EDIT:
I know the "BIP32 Root Key" and the "BIP32 Extended Public Key", can I do it using any of those?
NEW EDIT:
Thought about using Extended Public Key, can someone confirm if I'm right?
https://blockchain.info/xpub/xpub6Exa9kqjZDFBtx2qftFG3nhqiZ7wZsde2PtygviSLrSunmJeaugdFY67Cv9JSMocDojpvMEykWjzcJFzH8bQtfJdogNSpz5Dy4E6L6yUECV
This can be done using Extended Public Key:
https://blockchain.info/xpub/xpub6Exa9kqjZDFBtx2qftFG3nhqiZ7wZsde2PtygviSLrSunmJeaugdFY67Cv9JSMocDojpvMEykWjzcJFzH8bQtfJdogNSpz5Dy4E6L6yUECV
I have generated the xpub using bip32.org and derieved random address using xpub
var hdNode = bitcoinjs.HDNode.fromBase58(derivedPubKey);
hdNode.derive(index).pubKey.getAddress().toString();
the Private wif generated via bip32.org imported in the Bitcoin core. On transferring amount on the address generated by above code., amount is not showing in my bitcoin-core..
If you have imported the main pubkey into Core but the address you send to is a derived address then you are just sending to different address than you are expecting the funds to receive at.
Every derived address has its own private key so you have to import the keys of individual derived addresses not just the key of the chain:
var addr = hdNode.derive(i);
/* Derived address: */
addr.getAddress();
/* Corresponding privkey: */
addr.keyPair.toWIF();
In fact every derived address is possibly also a new chain (derive() returns a new HDNode). Also your hdNode is intended to be used only for address derivation yet it has own address too (the one you have sent your funds too), just because there are no separate datatypes for addresses and for chains. To access that funds just generate private key without derivation:
hdNode.keyPair.toWIF();
On the other hand if you use Electrum instead of Core you may just extract the main key of one of address chains of an Electrum wallet (it does not work the opposite way as Electrum uses checksum for wallet seed and you cannot just import non-electrum chain). This way you will be able to independently generate new addresses (also just new addresses without privKeys, for security reasons) which would be recognized by the wallet without importing them explicitly.
By the way, https://bitcoin.stackexchange.com/ is better place to ask bitcoin-related questions.
Yes you can create address from private key using below code
const bitcoin = require('bitcoinjs-lib');
let testnet = bitcoin.networks.testnet;
const keyPair = bitcoin.ECPair.fromWIF('cQnWufBcGz5fDtAPH8DVzrayXY1BJVCohCSHhgHXV8xnWfkGKQGL', testnet )
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey })
console.log(address)