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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Module that contains known test keys.

// TODO: Should be derived from seeds once implemented in the Rust version.

/// Define an ed25519 test key.
macro_rules! test_key_ed25519 {
    ($doc:expr, $name:ident, $pk:expr) => {
        #[doc = " Test key "]
        #[doc=$doc]
        #[doc = "."]
        pub mod $name {
            use crate::{
                crypto::signature::{ed25519, PublicKey},
                types::address::{Address, SignatureAddressSpec},
            };

            #[doc = " Test public key "]
            #[doc=$doc]
            #[doc = "."]
            pub fn pk() -> PublicKey {
                PublicKey::Ed25519(pk_ed25519())
            }

            #[doc = " Test Ed25519 public key "]
            #[doc=$doc]
            #[doc = "."]
            pub fn pk_ed25519() -> ed25519::PublicKey {
                $pk.into()
            }

            #[doc = " Test address derivation information "]
            #[doc=$doc]
            #[doc = "."]
            pub fn sigspec() -> SignatureAddressSpec {
                SignatureAddressSpec::Ed25519(pk_ed25519())
            }

            #[doc = " Test address "]
            #[doc=$doc]
            #[doc = "."]
            pub fn address() -> Address {
                Address::from_sigspec(&sigspec())
            }
        }
    };
}

/// Define a secp256k1 test key.
macro_rules! test_key_secp256k1 {
    ($doc:expr, $name:ident, $pk:expr) => {
        #[doc = " Test key "]
        #[doc=$doc]
        #[doc = "."]
        pub mod $name {
            use crate::{
                crypto::signature::{secp256k1, PublicKey},
                types::address::{Address, SignatureAddressSpec},
            };

            #[doc = " Test public key "]
            #[doc=$doc]
            #[doc = "."]
            pub fn pk() -> PublicKey {
                PublicKey::Secp256k1(pk_secp256k1())
            }

            #[doc = " Test Secp256k1 public key "]
            #[doc=$doc]
            #[doc = "."]
            pub fn pk_secp256k1() -> secp256k1::PublicKey {
                $pk.into()
            }

            #[doc = " Test address derivation information "]
            #[doc=$doc]
            #[doc = "."]
            pub fn sigspec() -> SignatureAddressSpec {
                SignatureAddressSpec::Secp256k1Eth(pk_secp256k1())
            }

            #[doc = " Test address "]
            #[doc=$doc]
            #[doc = "."]
            pub fn address() -> Address {
                Address::from_sigspec(&sigspec())
            }
        }
    };
}

/// Define an sr25519 test key.
macro_rules! test_key_sr25519 {
    ($doc:expr, $name:ident, $pk:expr) => {
        #[doc = " Test key "]
        #[doc=$doc]
        #[doc = "."]
        pub mod $name {
            use crate::{
                crypto::signature::{sr25519, PublicKey},
                types::address::{Address, SignatureAddressSpec},
            };

            #[doc = " Test public key "]
            #[doc=$doc]
            #[doc = "."]
            pub fn pk() -> PublicKey {
                PublicKey::Sr25519(pk_sr25519())
            }

            #[doc = " Test Sr25519 public key "]
            #[doc=$doc]
            #[doc = "."]
            pub fn pk_sr25519() -> sr25519::PublicKey {
                $pk.into()
            }

            #[doc = " Test address derivation information "]
            #[doc=$doc]
            #[doc = "."]
            pub fn sigspec() -> SignatureAddressSpec {
                SignatureAddressSpec::Sr25519(pk_sr25519())
            }

            #[doc = " Test address "]
            #[doc=$doc]
            #[doc = "."]
            pub fn address() -> Address {
                Address::from_sigspec(&sigspec())
            }
        }
    };
}

test_key_ed25519!("A", alice, "NcPzNW3YU2T+ugNUtUWtoQnRvbOL9dYSaBfbjHLP1pE=");
test_key_ed25519!("B", bob, "YgkEiVSR4SMQdfXw+ppuFYlqH0seutnCKk8KG8PyAx0=");
test_key_ed25519!("C", charlie, "8l1AQE+ETOPLckiNJ7NOD+AfZdaPw6wguir/vSF11YI=");
test_key_secp256k1!("D", dave, "AwF6GNjbybMzhi3XRj5R1oTiMMkO1nAwB7NZAlH1X4BE");
test_key_secp256k1!("E", erin, "A9i0oSK+5sLSONbMYGmaFUA+Fb8zzqYEMUMspacIgO09");
test_key_sr25519!("F", frank, "ljm9ZwdAldhlyWM2B4C+3gQZis+ceaxnt6QA4rOcP0k=");
test_key_sr25519!("G", grace, "0MHrNhjVTOFWmsOgpWcC3L8jIX3ZatKr0/yxMPtwckc=");