1
1
//! This module contains `Verifier` implementations for simple signature checking.
2
2
//! This is the most common way to implement private ownership in a UTXO chain and will
3
3
//! likely be used by most chains.
4
- //!
5
- //! Currently there is only an implementation for SR25519 signatures that makes use of
4
+ //!
5
+ //! Directly locking a UTXO to a public key is supported as well as locking behind a
6
+ //! public key hash like bitcoin's P2PKH. For the merits of each approach see:
7
+ //! https://bitcoin.stackexchange.com/q/72184
8
+ //!
9
+ //! Currently there are only implementations for SR25519 signatures that makes use of
6
10
//! Substrate's host functions to do the actual cryptography. Other signature schemes or
7
11
//! pure wasm implementations are also welcome here.
8
12
9
13
/// A very commonly used verifier that checks an sr25519 signature.
10
- ///
14
+ ///
11
15
/// This verifier relies on Substrate's host functions to perform the signature checking
12
16
/// natively and gain performance.
13
-
14
17
use super :: Verifier ;
15
18
use parity_scale_codec:: { Decode , Encode } ;
16
19
use scale_info:: TypeInfo ;
17
20
use serde:: { Deserialize , Serialize } ;
18
- use sp_core:: { H256 , sr25519:: { Public , Signature } } ;
21
+ use sp_core:: {
22
+ sr25519:: { Public , Signature } ,
23
+ H256 ,
24
+ } ;
19
25
26
+ /// Require a signature from the private key corresponding to the given public key.
27
+ /// This is the simplest way to require a signature. If you prefer not to expose the
28
+ /// public key until spend time, use P2PKH instead.
29
+ ///
30
+ /// Uses the Sr25519 signature scheme and Substrate's host functions.
20
31
#[ derive( Serialize , Deserialize , Encode , Decode , Debug , PartialEq , Eq , Clone , TypeInfo ) ]
21
32
pub struct Sr25519Signature {
22
33
pub owner_pubkey : H256 ,
@@ -42,6 +53,28 @@ impl Verifier for Sr25519Signature {
42
53
}
43
54
}
44
55
56
+ /// Pay To Public Key Hash (P2PKH)
57
+ ///
58
+ /// Require a signature from the private key corresponding to the public key whose _hash_ is given.
59
+ /// This is the most common way to represent private ownership in UTXO networks like Bitcoin.
60
+ /// It is more complex than providing the public key directly but does not reveal the public key until spend time.
61
+ ///
62
+ /// Uses the Sr25519 signature scheme and Substrate's host functions.
63
+ #[ derive( Serialize , Deserialize , Encode , Decode , Debug , PartialEq , Eq , Clone , TypeInfo ) ]
64
+ pub struct Sr25519P2PKH {
65
+ pub owner_pubkey_hash : H256 ,
66
+ }
67
+
68
+ impl Verifier for Sr25519P2PKH {
69
+ fn verify ( & self , simplified_tx : & [ u8 ] , _: u32 , redeemer : & [ u8 ] ) -> bool {
70
+ //TODO verifier trait should have associated type for decoding the redeemer. Otherwise each and every redeemer impl has to do it.
71
+ // Decode the redeemer and expect to find both a pubkey and a signature.
72
+ // Check that the hash stored matches the pubkey given.
73
+ // Check that the signature given is valid over the tx from the pubkey given.
74
+ todo ! ( )
75
+ }
76
+ }
77
+
45
78
#[ cfg( test) ]
46
79
mod test {
47
80
use super :: * ;
@@ -61,7 +94,6 @@ mod test {
61
94
assert ! ( sr25519_signature. verify( simplified_tx, 0 , redeemer) ) ;
62
95
}
63
96
64
-
65
97
#[ test]
66
98
fn sr25519_signature_with_bad_sig ( ) {
67
99
let simplified_tx = b"hello world" . as_slice ( ) ;
@@ -73,5 +105,4 @@ mod test {
73
105
74
106
assert ! ( !sr25519_signature. verify( simplified_tx, 0 , redeemer) ) ;
75
107
}
76
-
77
- }
108
+ }
0 commit comments