Serialize a deterministic key to vpub and deserialize it back

I am trying to write a simple Java application using BitcoinJ to derive one child publickey and get its extended version (vpub as I am testing in Testnet and I want to support SegWit) and then be able to deserialize the vpub back to a deterministic key. But when I check their output, pub and chain code look the same but the other attributes like path, creationTime and rest are not the same. What am I doing wrong? Am I missing something completely?

Here is the code snippet and the outputs

    public static void main(String[] args) throws Exception {

        NetworkParameters params = TestNet3Params.get();
        String mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
        DeterministicSeed seed = new DeterministicSeed(mnemonic, null, "", 0);
        DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(Objects.requireNonNull(seed.getSeedBytes()));

        DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
        List<ChildNumber> path = HDPath.parsePath("48H/1H/0H/2H/0");

        DeterministicKey deterministicKey1 = hierarchy.deriveChild(path, false, true, new ChildNumber(0));
        System.out.println("Extended publickey 1: " + deterministicKey1);
        System.out.println("Extended publickey getPublicKeyAsHex 1: " + deterministicKey1.getPublicKeyAsHex());
        System.out.println("Extended publickey serializePubB58 1: " +  deterministicKey1.serializePubB58(params));
        String vpub1 = deterministicKey1.serializePubB58(params, Script.ScriptType.P2WPKH);
        System.out.println("Extended publickey P2WPKH: " + vpub1);
        DeterministicKey deterministicKey1FromVpub = DeterministicKey.deserializeB58(vpub1, TestNet3Params.get());
        System.out.println("Extended publickey 1 from vpub: " + deterministicKey1FromVpub );
        System.out.println("Extended publickey 1 from tpub: " + DeterministicKey.deserializeB58(deterministicKey1.serializePubB58(params), TestNet3Params.get()) );

    }

output

18:02:30.885 [main] INFO org.bitcoinj.crypto.MnemonicCode -- PBKDF2 took 120.0 ms
Extended publickey 1: DeterministicKey{pub=030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01, chainCode=56bd3e8187e2fdcba0f3d4e830edbdd85d08762b8f5d3d769c98f60653d839e8, path=m/48H/1H/0H/2H/0/0, creationTimeSeconds=1738602151 (inherited), isEncrypted=false, isPubKeyOnly=false}
Extended publickey getPublicKeyAsHex 1: 030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01
Extended publickey serializePubB58 1: tpubDKW1so7KuXxqKUnrLUwbYbXTbASFFzMnTxER91HFHUWZgffWVtmqYD1TQVvV5dkL3vKvSmJDPuLqT1sDPEB2deZv4cLRVy4YLTpzrS6DeeT
Extended publickey P2WPKH: vpub5fTrkDwottvRM6DmDaPFvW15v73hPMsj66bgDfSLBYzuqBNLvMbd9e2M83vXZKVFSjZQLEbDwUogzG9UYyVm9jkRGLCGecmLD47JKHcvupC
Extended publickey 1 from vpub: DeterministicKey{pub=030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01, chainCode=56bd3e8187e2fdcba0f3d4e830edbdd85d08762b8f5d3d769c98f60653d839e8, path=M/0, creationTimeSeconds=0, isEncrypted=false, isPubKeyOnly=true}
Extended publickey 1 from tpub: DeterministicKey{pub=030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01, chainCode=56bd3e8187e2fdcba0f3d4e830edbdd85d08762b8f5d3d769c98f60653d839e8, path=M/0, creationTimeSeconds=0, isEncrypted=false, isPubKeyOnly=true}

enter image description here



from Recent Questions - Bitcoin Stack Exchange https://ift.tt/ENz62RU
via IFTTT

Popular posts from this blog

Do Kwon’s Detention Prolonged Until 2024 As Montenegro Responds To Extradition Requests

Sam Bankman-Fried Trial Begins Tomorrow: 3 Reasons Ex-SEC Official Foresees Conviction

Future of Bitcoin encryption and security in a QC era