NAME
Bitcoin::Crypto::Key::NUMS - "Nothing up my sleeve" key generator
SYNOPSIS
use Bitcoin::Crypto::Key::NUMS;
$pub = Bitcoin::Crypto::Key::NUMS->new->get_public_key;
# create an address with disabled key spend path
my $addr = $pub->get_taproot_address($script_tree);
DESCRIPTION
This class implements NUMS public keys defined in BIP341. These public keys have no known discrete logarithm (private key) and they can be proven to be unspendable.
When using these public keys, a valid taproot script path spending must be provided by adding $script_tree argument to "get_taproot_address" in Bitcoin::Crypto::Key::Public method - otherwise coins will be unspendable.
Usage
This class is designed to have two modes of operation:
generating NUMS keys
In this mode, you let
tweakbe picked at random. You can at retrieve it after generating the public key to prove that this public key cannot be spent:my $nums = Bitcoin::Crypto::Key::NUMS->new; my $pubkey = $nums->get_public_key; my $r = $nums->tweak;verifying NUMS keys
Suppose you want to prove the unspendability of a public key. You create an instance of NUMS class, providing
tweak. You can compare the generated public key to the one you had beforehand:my $got_pubkey = 'key generated by third party'; my $got_tweak = 'tweak value they provided'; my $nums = Bitcoin::Crypto::Key::NUMS->new(tweak => $got_tweak); my $pubkey = $nums->get_public_key; die 'bad key' unless $pubkey->to_serialized eq $got_pubkey;
INTERFACE
Attributes
tweak
Available in the constructor. This is known as r value in BIP341. It should be a bytestring of length 32. If it is not provided, it will be picked at random with CSPRNG.
Note that generating the tweak at random may fail by throwing an exception, but the chances of that happening are extremely slim.
Methods
new
$nums = $class->new(%args)
This is a standard Moo constructor, which can be used to create the object. It takes arguments specified in "Attributes".
get_public_key
$pubkey = $obj->get_public_key()
This method generates a new NUMS public key and returns it as an instance of Bitcoin::Crypto::Key::Public.
Note that calling this method repeatedly without modifying "tweak" will keep yielding the same public key.