Last active
November 20, 2020 20:57
-
-
Save mflaxman/d72d25ad00941cea8241b6667cf008a8 to your computer and use it in GitHub Desktop.
Using a BIP32 Path as a Blinding Factor for 1 key in your p2wsh - RESEARCH IDEA, DO NOT USE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha256 | |
# https://bitcoin.stackexchange.com/questions/92056/what-is-the-max-allowed-depth-for-bip32-derivation-paths | |
MAX_BIP32 = 2 ** 31 - 1 | |
def encode(num, base=MAX_BIP32): | |
result = [] | |
while num > 0: | |
num, remainder = divmod(num, base) | |
result.append(remainder) | |
return result | |
def decode(encoded, base=MAX_BIP32): | |
res = 0 | |
for cnt, r in enumerate(encoded): | |
res += r * base ** cnt | |
return res | |
# Poor test coverage | |
NUM, BASE = 98278243937, 34 | |
assert decode(encode(NUM, BASE), BASE) == NUM | |
def passphrase_to_bip32path(passphrase_as_string): | |
passphrase_as_int = int(sha256(passphrase_as_string.encode()).hexdigest(), 16) | |
return "m/" + "/".join( | |
[str(x) for x in encode(num=passphrase_as_int, base=MAX_BIP32)] | |
) | |
##### | |
from buidl.hd import HDPrivateKey, HDPublicKey | |
SECRET_PASSPHRASE = "correct horse battery staple" | |
MNEMONIC = "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo abstract" | |
print(f"Service creates seed from good source of randomness: {MNEMONIC}") | |
hd_priv = HDPrivateKey.from_mnemonic(MNEMONIC) | |
print( | |
"Service gives xpub to user (in practice they'd give a child public key but let's ignore that):" | |
) | |
print(hd_priv.pub) | |
print("\n" + "-" * 70) | |
print( | |
f"User creates secret passphrase to give to family member and their software uses that to create BIP32 paths: {SECRET_PASSPHRASE}" | |
) | |
path = passphrase_to_bip32path(SECRET_PASSPHRASE) | |
print("This results in the following path:", path) | |
print( | |
'User "blinds" xpub with this path resulting in new child xpub to use in the quorum:' | |
) | |
hd_pub = HDPublicKey.parse(hd_priv.pub.xpub()) | |
print(hd_pub.traverse(path=path)) | |
print("User stacks many sats...") | |
print("\n" + "-" * 70) | |
print( | |
"User is hit by a bus and their family member presents the passphphase (which can calculate the path) or the path itself to the service." | |
) | |
print("Here is confirmation the service has the corresponding xpriv from before") | |
child_priv = hd_priv.traverse(path=path) | |
print(child_priv) | |
print(child_priv.pub) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3 blinding.py | |
Service creates seed from good source of randomness: zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo abstract | |
Service gives xpub to user (in practice they'd give a child public key but let's ignore that): | |
xpub661MyMwAqRbcGTGRjiWquQ5BqBY18kdxCET7URgUDhzs2uBNwsgvToGYSW6FJziJUMkK49N8ivbdAKj4T4ZY5eZchRXNoFHuAVM5eGW5xWi | |
---------------------------------------------------------------------- | |
User creates secret passphrase to give to family member and their software uses that to create BIP32 paths: correct horse battery staple | |
This results in the following path: m/805017443/1460853890/917824691/16906294/771442409/1299979404/1135500815/1575327236/196 | |
User "blinds" xpub with this path resulting in new child xpub to use in the quorum: | |
xpub6PTRGqvJk8jfGaEDJUvHUZTwPytvQawprpbc4GC2DW4ymui3fRSezj7g3tKEdP5Nk8cZQDkUF71UT1EoDrsWK1kH6S3J7a1GmJL2ymvFy5D | |
User stacks many sats... | |
---------------------------------------------------------------------- | |
User is hit by a bus and their family member presents the passphphase (which can calculate the path) or the path itself to the service. | |
Here is confirmation the service has the corresponding xpriv from before | |
xprvAAU4sLPQumBN469kCTPH7RXCqx4S18DyVbg1FsnQfAXzu7Nu7t8QSvoCCcqVdyhWqPxKFRmenqCH6uMRCJiqm3Gj71HHVE7f1miG2fqghmx | |
xpub6PTRGqvJk8jfGaEDJUvHUZTwPytvQawprpbc4GC2DW4ymui3fRSezj7g3tKEdP5Nk8cZQDkUF71UT1EoDrsWK1kH6S3J7a1GmJL2ymvFy5D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pros:
Cons:
2-of-2
situation.