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
//! Transaction building and signing for Bitcoin SV.
///
/// Supports P2PKH/P2SH, sighash computation (BIP-143 + forkid), and ECDSA signing.
///
/// # Examples
///
/// Sign a P2PKH transaction:
/// ```
/// use nour::messages::{Tx, TxIn};
/// use nour::transaction::{generate_signature, p2pkh::{create_lock_script, create_unlock_script}, sighash::{sighash, SigHashCache, SIGHASH_FORKID, SIGHASH_NONE}};
/// use nour::util::hash160;
///
/// // Use real values
/// let mut tx = Tx {
/// inputs: vec![TxIn { ..Default::default() }],
/// ..Default::default()
/// };
/// let private_key = [1; 32];
/// let public_key = [1; 33];
///
/// let lock_script = create_lock_script(&hash160(&public_key));
/// let mut cache = SigHashCache::new();
/// let sighash_type = SIGHASH_NONE | SIGHASH_FORKID;
/// let sighash_val = sighash(&tx, 0, &lock_script.0, 0, sighash_type, &mut cache).unwrap();
/// let signature = generate_signature(&private_key, &sighash_val, sighash_type).unwrap();
/// tx.inputs[0].unlock_script = create_unlock_script(&signature, &public_key);
/// ```
use crate;
use ;
/// Generates DER-encoded ECDSA signature for sighash + type.
///
/// Normalizes S (low); errors on invalid key.
///
/// # Errors
/// `Error::ScriptError` for invalid private key.