예제 #1
0
        public void Test_debug_output()
        {
            var s   = Secp256K1.New();
            var sig = RecoverableSigniture.From_compact(s, new byte[] {
                0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f,
                0x04, 0x77, 0x2b, 0x6f, 0x92, 0x1f, 0x0b, 0xa6,
                0xaf, 0x0c, 0x1e, 0x77, 0xfc, 0x43, 0x9e, 0x65,
                0xc3, 0x6d, 0xed, 0xf4, 0x09, 0x2e, 0x88, 0x98,
                0x4c, 0x1a, 0x97, 0x16, 0x52, 0xe0, 0xad, 0xa8,
                0x80, 0x12, 0x0e, 0xf8, 0x02, 0x5e, 0x70, 0x9f,
                0xff, 0x20, 0x80, 0xc4, 0xa3, 0x9a, 0xae, 0x06,
                0x8d, 0x12, 0xee, 0xd0, 0x09, 0xb6, 0x8c, 0x89
            },
                                                        RecoveryId.from_i32(1));

            //TODO: Finish here
            Assert.Equal("RecoverableSignature(98882e09f4ed6dc3659e43fc771e0cafa60b1f926f2b77041f744721adff7366898cb609d0ee128d06ae9aa3c48020ff9f705e02f80e1280a8ade05216971a4c01)", $"{sig}");

            var msg = Message.from_slice(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8,
                                                      9, 10, 11, 12, 13, 14, 15, 16,
                                                      17, 18, 19, 20, 21, 22, 23, 24,
                                                      25, 26, 27, 28, 29, 30, 31, 255 });

            //TODO: Finish here
            Assert.Equal("Message(0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff)", $"{msg}");
        }
예제 #2
0
        public void Sign()
        {
            var s = Secp256K1.New();

            s.Randomize(RandomNumberGenerator.Create());

            var one = new byte[]
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
            };

            var sk  = SecretKey.From_slice(s, one);
            var msg = Message.from_slice(one);

            var sig  = s.sign_recoverable(msg, sk);
            var rsig = RecoverableSigniture.From_compact(s, new byte[]
            {
                0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f,
                0x04, 0x77, 0x2b, 0x6f, 0x92, 0x1f, 0x0b, 0xa6,
                0xaf, 0x0c, 0x1e, 0x77, 0xfc, 0x43, 0x9e, 0x65,
                0xc3, 0x6d, 0xed, 0xf4, 0x09, 0x2e, 0x88, 0x98,
                0x4c, 0x1a, 0x97, 0x16, 0x52, 0xe0, 0xad, 0xa8,
                0x80, 0x12, 0x0e, 0xf8, 0x02, 0x5e, 0x70, 0x9f,
                0xff, 0x20, 0x80, 0xc4, 0xa3, 0x9a, 0xae, 0x06,
                0x8d, 0x12, 0xee, 0xd0, 0x09, 0xb6, 0x8c, 0x89
            },
                                                         RecoveryId.from_i32(1));

            Assert.Equal(sig.Value, rsig.Value);
        }
예제 #3
0
        public void Test_recov_id_conversion_between_i32()
        {
            Assert.Throws <Exception>(() => { RecoveryId.from_i32(-1); });
            RecoveryId.from_i32(0);
            RecoveryId.from_i32(1);
            RecoveryId.from_i32(2);
            RecoveryId.from_i32(3);
            Assert.Throws <Exception>(() => { RecoveryId.from_i32(4); });

            var id0 = RecoveryId.from_i32(0);

            Assert.Equal(0, id0.Value);

            var id1 = RecoveryId.from_i32(1);

            Assert.Equal(1, id1.Value);
        }
예제 #4
0
        public void Bad_recovery()
        {
            var s = Secp256K1.New();

            s.Randomize(RandomNumberGenerator.Create());

            var msgBytes = ByteUtil.Get_bytes(0x55, 32);
            var msg      = Message.from_slice(msgBytes);

            // Zero is not a valid sig
            var sig = RecoverableSigniture.From_compact(s, new byte[64], RecoveryId.from_i32(0));
            var ex  = Assert.Throws <Exception>(() => { s.Recover(msg, sig); });

            Assert.Equal("InvalidSignature", ex.Message);

            // ...but 111..111 is
            var sig2 = RecoverableSigniture.From_compact(s, ByteUtil.Get_bytes(1, 64), RecoveryId.from_i32(0));

            s.Recover(msg, sig2);
        }
예제 #5
0
        public void Test_recov_sig_serialize_compact()
        {
            var s = Secp256K1.New();

            var recidIn = RecoveryId.from_i32(1);
            var bytesIn = new byte[]
            {
                0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f,
                0x04, 0x77, 0x2b, 0x6f, 0x92, 0x1f, 0x0b, 0xa6,
                0xaf, 0x0c, 0x1e, 0x77, 0xfc, 0x43, 0x9e, 0x65,
                0xc3, 0x6d, 0xed, 0xf4, 0x09, 0x2e, 0x88, 0x98,
                0x4c, 0x1a, 0x97, 0x16, 0x52, 0xe0, 0xad, 0xa8,
                0x80, 0x12, 0x0e, 0xf8, 0x02, 0x5e, 0x70, 0x9f,
                0xff, 0x20, 0x80, 0xc4, 0xa3, 0x9a, 0xae, 0x06,
                0x8d, 0x12, 0xee, 0xd0, 0x09, 0xb6, 0x8c, 0x89
            };
            var sig = RecoverableSigniture.From_compact(
                s, bytesIn, recidIn);

            var(recidOut, bytesOut) = sig.Serialize_compact(s);
            Assert.Equal(recidIn.Value, recidOut.Value);
            Assert.Equal(bytesIn, bytesOut);
        }
예제 #6
0
        public void Recid_sanity_check()
        {
            var one = RecoveryId.from_i32(1);

            Assert.Equal(one.Value, one.Clone().Value);
        }
예제 #7
0
        public void Invalid_pubkey()
        {
            var s        = Secp256K1.New();
            var sig      = RecoverableSigniture.From_compact(s, ByteUtil.Get_bytes(1, 64), RecoveryId.from_i32(0));
            var pk       = PublicKey.New();
            var msgBytes = ByteUtil.Get_random_bytes(RandomNumberGenerator.Create(), 32);
            var msg      = Message.from_slice(msgBytes);
            var ex       = Assert.Throws <Exception>(() => { s.Verify(msg, sig.To_standard(s), pk); });

            Assert.Equal("InvalidPublicKey", ex.Message);
        }