bloxbean / cardano-client-lib

Cardano client library in Java
https://cardano-client.dev
MIT License
118 stars 51 forks source link

Missing VkeyWitness when submiting txn using cborhex of private key used as skey in derived address skey #117

Closed ShristiShrestha closed 2 years ago

ShristiShrestha commented 2 years ago

I am using HD wallet generation using derivation path altering account and index field between 0 to 2^32. I am using thus created account to submit txn against cardano cli.

Issues

  1. Create skey

    fun Account.toJsonTextEnvelope(): Pair<String, String> {
        val (privateCbor, publicCbor) = this.toCborHex()
        return Pair(
            """{
                    "type": "PaymentExtendedSigningKeyShelley_ed25519_bip32",
                    "description" : "Payment Signing Key",
                    "cborHex": "$privateCbor"
                }""".trimIndent(),
            """{
                    "type": "PaymentExtendedVerificationKeyShelley_ed25519_bip32",
                    "description" : "Payment Verification Key",
                    "cborHex": "$publicCbor"
                }""".trimIndent()
        )
    }
    
    fun Account.toCborHex(): Pair<String, String> {
        val hdKeyPair = this.hdKeyPair()
        return Pair(
            KeyGenCborUtil.bytesToCbor(hdKeyPair.privateKey.keyData),
            KeyGenCborUtil.bytesToCbor(hdKeyPair.publicKey.keyData),
        )
    }
  2. The using this content to write in a file and use that file as skey in cardano cli.

ShristiShrestha commented 2 years ago

I have tried using PaymentVerificationKeyShelley_ed25519 and PaymentSigningKeyShelley_ed25519 as types but no luck so far.

satran004 commented 2 years ago

Have you checked the following section here https://github.com/input-output-hk/cardano-addresses (Last section in Command-Line) ?

"Correspondence between keys in cardano-addresses and cardano-cli (key.xsk key.xvk key.vk key.hash)"

The prv key generated by the cardano-client-lib is an extended signing key with 64 bytes. If you want to use it through CLI, check the below section for cbor format.

You can use the same mnemonic in Java and CLI and verify. You can get private key bytes, chain code from HDPrivateKey.

Create extended signing key using cardano-cli
$ cardano-cli key convert-cardano-address-key --shelley-payment-key --signing-key-file key.xsk --out-file key.skey
{
    "type": "PaymentExtendedSigningKeyShelley_ed25519_bip32",
    "description": "",
    "cborHex": "5880b0bf46232c7f0f58ad333030e43ffbea7c2bb6f8135bd05fb0d343ade8453c5eacc7ac09f77e16b635832522107eaa9f56db88c615f537aa6025e6c23da98ae8fbbbf6410e24532f35e9279febb085d2cc05b3b2ada1df77ea1951eb694f3834b0be1868d1c36ef9089b3b094f5fe1d783e4d5fea14e2034c0397bee50e65a1a"
}

The cborhex here contains of 4 parts:
1. prefix 5880 - bytestring of 128 bytes
2. signing key (64 bytes) - b0bf46232c7f0f58ad333030e43ffbea7c2bb6f8135bd05fb0d343ade8453c5eacc7ac09f77e16b635832522107eaa9f56db88c615f537aa6025e6c23da98ae8
3. verification key (32 bytes) - fbbbf6410e24532f35e9279febb085d2cc05b3b2ada1df77ea1951eb694f3834
4. chain code (32 bytes) - b0be1868d1c36ef9089b3b094f5fe1d783e4d5fea14e2034c0397bee50e65a1a
ShristiShrestha commented 2 years ago

Thank you for the help. The issue has been resolved.