Example #1
0
        public void Slip77Tests()
        {
            //test vector: https://github.com/vulpemventures/slip77/commit/bc0fa0c712512d27cf1e2d6e1aaee5c36a3d38fa
            var allMnemonic = new Mnemonic("all all all all all all all all all all all all");
            var master      = Slip21Node.FromSeed(allMnemonic.DeriveSeed());

            Assert.Equal("dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756", master.Key.ToHex());
            var slip77                = Slip21Node.FromSeed(allMnemonic.DeriveSeed()).GetSlip77Node();
            var script                = Script.FromHex("76a914a579388225827d9f2fe9014add644487808c695d88ac");
            var privateBlindingKey    = slip77.DeriveSlip77BlindingKey(script);
            var unconfidentialAddress =
                BitcoinAddress.Create("2dpWh6jbhAowNsQ5agtFzi7j6nKscj6UnEr", Altcoins.Liquid.Instance.Regtest);
            var publicBlindingKey = privateBlindingKey.PubKey;

            Assert.Equal("4e6e94df28448c7bb159271fe546da464ea863b3887d2eec6afd841184b70592",
                         privateBlindingKey.ToHex());
            Assert.Equal("0223ef5cf5d1185f86204b9386c8541061a24b6f72fa4a29e3a0b60e1c20ffaf5b",
                         publicBlindingKey.ToHex());
            Assert.Equal("CTEkf75DFff5ReB7juTg2oehrj41aMj21kvvJaQdWsEAQohz1EDhu7Ayh6goxpz3GZRVKidTtaXaXYEJ",
                         new BitcoinBlindedAddress(publicBlindingKey, unconfidentialAddress).ToString());


            //test vector: https://github.com/trezor/trezor-firmware/pull/398/files#diff-afc9a622fb2281269983493a9da47a364e94f8bd338e5322f4a7cef99f98ee69R119
            var abusiveWords =
                new Mnemonic("alcohol woman abuse must during monitor noble actual mixed trade anger aisle");
            var derived       = abusiveWords.DeriveExtKey().Derive(new KeyPath("44'/1'/0'/0/0"));
            var addr          = derived.PrivateKey.ScriptPubKey.GetDestinationAddress(Liquid.Instance.Regtest);
            var abusiveslip77 = Slip21Node.FromSeed(abusiveWords.DeriveSeed()).GetSlip77Node();

            Assert.Equal("26f1dc2c52222394236d76e0809516255cfcca94069fd5187c0f090d18f42ad6",
                         abusiveslip77.DeriveSlip77BlindingKey(addr.ScriptPubKey).ToHex());
        }
Example #2
0
    public OwnershipProof GetOwnershipProof(IDestination destination, CoinJoinInputCommitmentData commitmentData)
    {
        var secret = GetBitcoinSecret(destination.ScriptPubKey);

        var masterKey = KeyManager.GetMasterExtKey(Kitchen.SaltSoup()).PrivateKey;
        var identificationMasterKey = Slip21Node.FromSeed(masterKey.ToBytes());
        var identificationKey       = identificationMasterKey.DeriveChild("SLIP-0019").DeriveChild("Ownership identification key").Key;

        var signingKey     = secret.PrivateKey;
        var ownershipProof = OwnershipProof.GenerateCoinJoinInputProof(
            signingKey,
            new OwnershipIdentifier(identificationKey, destination.ScriptPubKey),
            commitmentData);

        return(ownershipProof);
    }
Example #3
0
        public void Slip21Tests()
        {
            var allMnemonic = new Mnemonic("all all all all all all all all all all all all");
            var master      = Slip21Node.FromSeed(allMnemonic.DeriveSeed());

            Assert.Equal("dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756", master.Key.ToHex());

            var child1 = master.DeriveChild("SLIP-0021");

            Assert.Equal("1d065e3ac1bbe5c7fad32cf2305f7d709dc070d672044a19e610c77cdf33de0d", child1.Key.ToHex());

            var child2 = child1.DeriveChild("Master encryption key");

            Assert.Equal("ea163130e35bbafdf5ddee97a17b39cef2be4b4f390180d65b54cf05c6a82fde", child2.Key.ToHex());

            var child3 = child1.DeriveChild("Authentication key");

            Assert.Equal("47194e938ab24cc82bfa25f6486ed54bebe79c40ae2a5a32ea6db294d81861a6", child3.Key.ToHex());
        }
Example #4
0
        public void OwnershipProofEncodingDecoding()
        {
            // Trezor test vector
            // [all all all all all all all all all all all all]/84'/0'/0'/1/0
            var allMnemonic             = new Mnemonic("all all all all all all all all all all all all");
            var identificationMasterKey = Slip21Node.FromSeed(allMnemonic.DeriveSeed());
            var identificationKey       = identificationMasterKey.DeriveChild("SLIP-0019").DeriveChild("Ownership identification key").Key;

            using var key = new Key(Encoders.Hex.DecodeData("3460814214450E864EC722FF1F84F96C41746CD6BBE2F1C09B33972761032E9F"));

            var ownershipIdentifier = new OwnershipIdentifier(identificationKey, key.PubKey.WitHash.ScriptPubKey);
            var commitmentData      = Array.Empty <byte>();
            var ownershipProof      = OwnershipProof.Generate(key, ownershipIdentifier, commitmentData, false, ScriptPubKeyType.Segwit);
            var scriptPubKey        = PayToWitPubKeyHashTemplate.Instance.GenerateScriptPubKey(key.PubKey);

            var ownershipProofBytes = Encoders.Hex.DecodeData("534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100e5eaf2cb0a473b4545115c7b85323809e75cb106175ace38129fd62323d73df30220363dbc7acb7afcda022b1f8d97acb8f47c42043cfe0595583aa26e30bc8b3bb50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b");

            Assert.True(ownershipProofBytes.SequenceEqual(ownershipProof.ToBytes()));
            var deserializedOwnershipProof = OwnershipProof.FromBytes(ownershipProofBytes);

            Assert.True(ownershipProofBytes.SequenceEqual(deserializedOwnershipProof.ToBytes()));
        }
    public void OwnershipProofEncodingDecoding()
    {
        // Trezor test vector
        // [all all all all all all all all all all all all]/84'/0'/0'/1/0
        var allMnemonic             = new Mnemonic("all all all all all all all all all all all all");
        var identificationMasterKey = Slip21Node.FromSeed(allMnemonic.DeriveSeed());
        var identificationKey       = identificationMasterKey.DeriveChild("SLIP-0019").DeriveChild("Ownership identification key").Key;

        using var key = new Key(Encoders.Hex.DecodeData("3460814214450E864EC722FF1F84F96C41746CD6BBE2F1C09B33972761032E9F"));

        var ownershipIdentifier = new OwnershipIdentifier(identificationKey, key.PubKey.WitHash.ScriptPubKey);
        var commitmentData      = Array.Empty <byte>();
        var ownershipProof      = OwnershipProof.Generate(key, ownershipIdentifier, commitmentData, false, ScriptPubKeyType.Segwit);
        var scriptPubKey        = PayToWitPubKeyHashTemplate.Instance.GenerateScriptPubKey(key.PubKey);

        var ownershipProofBytes = Encoders.Hex.DecodeData("534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b");

        Assert.True(ownershipProofBytes.SequenceEqual(ownershipProof.ToBytes()));
        var deserializedOwnershipProof = OwnershipProof.FromBytes(ownershipProofBytes);

        Assert.True(ownershipProofBytes.SequenceEqual(deserializedOwnershipProof.ToBytes()));
    }