-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathphash.py
54 lines (28 loc) · 1.02 KB
/
phash.py
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
import hashlib
TAG_HASH_CACHE = {}
def tagged_hash(tag: bytes, msg: bytes) -> bytes:
if TAG_HASH_CACHE.get(tag) is None:
TAG_HASH_CACHE[tag] = hashlib.sha256(tag).digest() * 2
return hashlib.sha256(TAG_HASH_CACHE[tag] + msg).digest()
def hash_aux(msg):
return tagged_hash(b"BIP0340/aux", msg)
def hash_challenge(msg):
return tagged_hash(b"BIP0340/challenge", msg)
def hash_keyaggcoef(msg):
return tagged_hash(b"KeyAgg coefficient", msg)
def hash_keyagglist(msg):
return tagged_hash(b"KeyAgg list", msg)
def hash_musignonce(msg):
return tagged_hash(b"MuSig/noncecoef", msg)
def hash_nonce(msg):
return tagged_hash(b"BIP0340/nonce", msg)
def hash_tapbranch(msg):
return tagged_hash(b"TapBranch", msg)
def hash_tapleaf(msg):
return tagged_hash(b"TapLeaf", msg)
def hash_tapsighash(msg):
return tagged_hash(b"TapSighash", msg)
def hash_taptweak(msg):
return tagged_hash(b"TapTweak", msg)
def hash_bip322message(msg):
return tagged_hash(b"BIP0322-signed-message",msg)