Пример #1
0
        public void AdaptorUtilTest()
        {
            var msg          = new ByteData("024bdd11f2144e825db05759bdd9041367a420fad14b665fd08af5b42056e5e2");
            var adaptor      = new Pubkey("038d48057fc4ce150482114d43201b333bf3706f3cd527e8767ceb4b443ab5d349");
            var sk           = new Privkey("90ac0d5dc0a1a9ab352afb02005a5cc6c4df0da61d8149d729ff50db9b5a5215");
            var pubkey       = new Pubkey("03490cec9a53cd8f2f664aea61922f26ee920c42d2489778bb7c9d9ece44d149a7");
            var adaptorSig   = new ByteData("00cbe0859638c3600ea1872ed7a55b8182a251969f59d7d2da6bd4afedf25f5021a49956234cbbbbede8ca72e0113319c84921bf1224897a6abd89dc96b9c5b208");
            var adaptorProof = new ByteData("00b02472be1ba09f5675488e841a10878b38c798ca63eff3650c8e311e3e2ebe2e3b6fee5654580a91cc5149a71bf25bcbeae63dea3ac5ad157a0ab7373c3011d0fc2592a07f719c5fc1323f935569ecd010db62f045e965cc1d564eb42cce8d6d");
            var adaptorSig2  = new ByteData("01099c91aa1fe7f25c41085c1d3c9e73fe04a9d24dac3f9c2172d6198628e57f47bb90e2ad6630900b69f55674c8ad74a419e6ce113c10a21a79345a6e47bc74c1");
            // var sigDer = new ByteData("30440220099c91aa1fe7f25c41085c1d3c9e73fe04a9d24dac3f9c2172d6198628e57f4702204d13456e98d8989043fd4674302ce90c432e2f8bb0269f02c72aafec60b72de101");
            var sig    = new ByteData("099c91aa1fe7f25c41085c1d3c9e73fe04a9d24dac3f9c2172d6198628e57f474d13456e98d8989043fd4674302ce90c432e2f8bb0269f02c72aafec60b72de1");
            var secret = new Privkey("475697a71a74ff3f2a8f150534e9b67d4b0b6561fab86fcaa51f8c9d6c9db8c6");

            var pair = EcdsaAdaptorUtil.Sign(msg, sk, adaptor);

            Assert.Equal(adaptorSig.ToHexString(), pair.Signature.ToHexString());
            Assert.Equal(adaptorProof.ToHexString(), pair.Proof.ToHexString());

            var isVerify = EcdsaAdaptorUtil.Verify(pair.Signature, pair.Proof, adaptor, msg, pubkey);

            Assert.True(isVerify);

            var adaptSig = EcdsaAdaptorUtil.Adapt(adaptorSig2, secret);

            Assert.Equal(sig.ToHexString(), adaptSig.ToHexString());

            var adaptorSecret = EcdsaAdaptorUtil.ExtractSecret(adaptorSig2, adaptSig, adaptor);

            Assert.Equal(secret.ToHexString(), adaptorSecret.ToHexString());
        }
Пример #2
0
        public void ConvertMnemonicToEntropyTest()
        {
            string   mnemonicEn = "horn tenant knee talent sponsor spell gate clip pulse soap slush warm silver nephew swap uncle crack brave";
            ByteData entropy    = HDWallet.ConvertMnemonicToEntropy(mnemonicEn, "en");

            Assert.Equal("6d9be1ee6ebd27a258115aad99b7317b9c8d28b6d76431c3", entropy.ToHexString());

            string[] mnemonicWords = HDWallet.ConvertEntropyToMnemonic(entropy, "en");
            string   mnemonic      = string.Join(' ', mnemonicWords);

            Assert.Equal(mnemonicEn, mnemonic);
        }
Пример #3
0
        public void SignParameterTest()
        {
            SignParameter data = new SignParameter("0e68b55347fe37338beb3c28920267c5915a0c474d1dcafc65b087b9b3819cae6ae5e8fb12d669a63127abb4724070f8bd232a9efe3704e6544296a843a64f2c");

            Assert.Equal("0e68b55347fe37338beb3c28920267c5915a0c474d1dcafc65b087b9b3819cae6ae5e8fb12d669a63127abb4724070f8bd232a9efe3704e6544296a843a64f2c", data.ToHexString());
            SignParameter data2 = new SignParameter(data.GetBytes());

            Assert.Equal(data.ToHexString(), data2.ToHexString());

            ByteData normalize = SignParameter.NormalizeSignature(data.GetData());

            Assert.Equal(data.ToHexString(), normalize.ToHexString());
        }
Пример #4
0
        public void ByteDataTest()
        {
            ByteData emptyData = new ByteData();

            Assert.True(emptyData.IsEmpty());

            ByteData data           = new ByteData("773420c0ded41a55b1f1205cfb632f08f3f911a53e7338a0dac73ec6cbe3ca471907434d046185abedc5afddc2761a642bccc70af6d22b46394f1d04a8b24226");
            ByteData serializedData = data.Serialize();

            Assert.Equal("40773420c0ded41a55b1f1205cfb632f08f3f911a53e7338a0dac73ec6cbe3ca471907434d046185abedc5afddc2761a642bccc70af6d22b46394f1d04a8b24226", serializedData.ToHexString());
            Assert.Equal((uint)65, serializedData.GetLength());
        }
Пример #5
0
        public void EncodeToDerTest()
        {
            ByteData sig        = new ByteData("773420c0ded41a55b1f1205cfb632f08f3f911a53e7338a0dac73ec6cbe3ca471907434d046185abedc5afddc2761a642bccc70af6d22b46394f1d04a8b24226");
            ByteData derencData = SignParameter.EncodeToDer(sig, new SignatureHashType(CfdSighashType.All, false));

            Assert.Equal("30440220773420c0ded41a55b1f1205cfb632f08f3f911a53e7338a0dac73ec6cbe3ca4702201907434d046185abedc5afddc2761a642bccc70af6d22b46394f1d04a8b2422601", derencData.ToHexString());
        }