segregated witness – Serialize a deterministic key to vpub and deserialize it again

0
9
segregated witness – Serialize a deterministic key to vpub and deserialize it again


I’m attempting to put in writing a easy Java software utilizing BitcoinJ to derive one little one publickey and get its prolonged model (vpub as I’m testing in Testnet and I wish to assist SegWit) after which have the ability to deserialize the vpub again to a deterministic key. However once I examine their output, pub and chain code look the identical however the different attributes like path, creationTime and relaxation aren’t the identical. What am I doing improper? Am I lacking one thing fully?

Right here is the code snippet and the outputs

    public static void important(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);
        Listing<ChildNumber> path = HDPath.parsePath("48H/1H/0H/2H/0");

        DeterministicKey deterministicKey1 = hierarchy.deriveChild(path, false, true, new ChildNumber(0));
        System.out.println("Prolonged publickey 1: " + deterministicKey1);
        System.out.println("Prolonged publickey getPublicKeyAsHex 1: " + deterministicKey1.getPublicKeyAsHex());
        System.out.println("Prolonged publickey serializePubB58 1: " +  deterministicKey1.serializePubB58(params));
        String vpub1 = deterministicKey1.serializePubB58(params, Script.ScriptType.P2WPKH);
        System.out.println("Prolonged publickey P2WPKH: " + vpub1);
        DeterministicKey deterministicKey1FromVpub = DeterministicKey.deserializeB58(vpub1, TestNet3Params.get());
        System.out.println("Prolonged publickey 1 from vpub: " + deterministicKey1FromVpub );
        System.out.println("Prolonged 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
Prolonged publickey 1: DeterministicKey{pub=030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01, chainCode=56bd3e8187e2fdcba0f3d4e830edbdd85d08762b8f5d3d769c98f60653d839e8, path=m/48H/1H/0H/2H/0/0, creationTimeSeconds=1738602151 (inherited), isEncrypted=false, isPubKeyOnly=false}
Prolonged publickey getPublicKeyAsHex 1: 030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01
Prolonged publickey serializePubB58 1: tpubDKW1so7KuXxqKUnrLUwbYbXTbASFFzMnTxER91HFHUWZgffWVtmqYD1TQVvV5dkL3vKvSmJDPuLqT1sDPEB2deZv4cLRVy4YLTpzrS6DeeT
Prolonged publickey P2WPKH: vpub5fTrkDwottvRM6DmDaPFvW15v73hPMsj66bgDfSLBYzuqBNLvMbd9e2M83vXZKVFSjZQLEbDwUogzG9UYyVm9jkRGLCGecmLD47JKHcvupC
Prolonged publickey 1 from vpub: DeterministicKey{pub=030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01, chainCode=56bd3e8187e2fdcba0f3d4e830edbdd85d08762b8f5d3d769c98f60653d839e8, path=M/0, creationTimeSeconds=0, isEncrypted=false, isPubKeyOnly=true}
Prolonged publickey 1 from tpub: DeterministicKey{pub=030b90ed2e86bad7f2a4fe9769bb417d7ba9caa1124807dbfb362dfbeeb65e7e01, chainCode=56bd3e8187e2fdcba0f3d4e830edbdd85d08762b8f5d3d769c98f60653d839e8, path=M/0, creationTimeSeconds=0, isEncrypted=false, isPubKeyOnly=true}

enter image description here

LEAVE A REPLY

Please enter your comment!
Please enter your name here