BSV.Contract.P2RPH (BSV v2.0.0) View Source
Pay to R-Puzzle Hash contract.
P2RPH scripts are used to lock Bitcoin to a hash puzzle based on the R value of an ECDSA signature. The Bitcoin can later be unlocked with knowledge of the corresponding K value used in that signature.
The technique allows for the spending party to sign the unlocking script using
any BSV.KeyPair.t/0
.
Examples
iex> contract = P2RPH.lock(1000, %{r: <<0, 248, 31, 103, 64, 90, 206, 189, 241, 179, 82, 21, 21, 93, 182, 235, 240, 79, 251, 243, 151, 251, 106, 1, 172, 52, 67, 147, 228, 160, 37, 243, 37>>})
iex> Contract.to_script(contract)
%Script{chunks: [
:OP_OVER,
:OP_3,
:OP_SPLIT,
:OP_NIP,
:OP_1,
:OP_SPLIT,
:OP_SWAP,
:OP_SPLIT,
:OP_DROP,
:OP_HASH160,
<<54, 64, 230, 57, 244, 115, 17, 120, 225, 185, 95, 98, 204, 108, 116, 34, 51, 156, 70, 82>>,
:OP_EQUALVERIFY,
:OP_TUCK,
:OP_CHECKSIGVERIFY,
:OP_CHECKSIG
]}
iex> contract = P2RPH.unlock(%UTXO{}, %{keypair: @keypair, k: <<194, 223, 63, 16, 71, 231, 76, 36, 240, 165, 106, 139, 60, 110, 89, 72, 165, 137, 83, 102, 50, 141, 163, 159, 131, 133, 220, 164, 218, 224, 121, 81>>})
iex> Contract.to_script(contract)
%Script{chunks: [
<<0::568>>, # signatures are zero'd out until the transaction context is attached
<<0::568>>,
<<3, 248, 31, 140, 139, 144, 245, 236, 6, 238, 66, 69, 234, 177, 102, 232, 175, 144, 63, 199, 58, 109, 215, 54, 54, 104, 126, 240, 39, 135, 10, 190, 57>>
]}
Link to this section Summary
Functions
Generates a new random K value binary.
Returns the corresponding R value of the given K value.
Returns a locking script contract with the given parameters.
Returns an unlocking script contract with the given parameters.
Link to this section Functions
Specs
generate_k() :: binary()
Generates a new random K value binary.
Specs
Returns the corresponding R value of the given K value.
Specs
lock(non_neg_integer(), map(), keyword()) :: BSV.Contract.t()
Returns a locking script contract with the given parameters.
Specs
unlock(BSV.UTXO.t(), map(), keyword()) :: BSV.Contract.t()
Returns an unlocking script contract with the given parameters.