Class: Bitcoin::Descriptor::Sp
- Inherits:
-
Expression
- Object
- Expression
- Bitcoin::Descriptor::Sp
- Defined in:
- lib/bitcoin/descriptor/sp.rb
Overview
sp() expression for Silent Payment descriptor. Supports both single-argument (spscan/spspend) and two-argument forms.
Constant Summary collapse
- SPSCAN_HRP =
HRP for spscan/spspend encoding
'spscan'- SPSPEND_HRP =
'spspend'- TSPSCAN_HRP =
'tspscan'- TSPSPEND_HRP =
'tspspend'
Instance Attribute Summary collapse
-
#key_arg ⇒ Object
readonly
Returns the value of attribute key_arg.
-
#scan_key ⇒ Object
readonly
Returns the value of attribute scan_key.
-
#spend_key ⇒ Object
readonly
Returns the value of attribute spend_key.
Instance Method Summary collapse
- #args ⇒ Object
-
#has_spend_private_key? ⇒ Boolean
Check if this descriptor has spend private key (spspend form).
-
#initialize(key_or_scan_key, spend_key = nil) ⇒ Sp
constructor
Constructor.
-
#single_key? ⇒ Boolean
Check if this is a single-argument form (spscan/spspend).
-
#to_addr ⇒ Bech32::SilentPaymentAddr
Generate silent payment address.
-
#to_script ⇒ Object
Silent payment descriptors do not produce a single script.
- #top_level? ⇒ Boolean
- #type ⇒ Object
Methods inherited from Expression
#==, #compressed_key?, #derive_path, #extract_pubkey, #to_hex, #to_s
Constructor Details
#initialize(key_or_scan_key, spend_key = nil) ⇒ Sp
Constructor.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bitcoin/descriptor/sp.rb', line 22 def initialize(key_or_scan_key, spend_key = nil) raise ArgumentError, "key_or_scan_key must be a String." unless key_or_scan_key.is_a?(String) unless spend_key.nil? || spend_key.is_a?(String) || spend_key.is_a?(Expression) raise ArgumentError, "spend_key must be a String, Expression, or nil." end if spend_key.nil? # Single argument form: spscan or spspend encoded key @key_arg = key_or_scan_key parse_encoded_key(key_or_scan_key) else # Two argument form: separate scan and spend keys @key_arg = nil @scan_key = key_or_scan_key @spend_key = spend_key end validate_keys! end |
Instance Attribute Details
#key_arg ⇒ Object (readonly)
Returns the value of attribute key_arg.
14 15 16 |
# File 'lib/bitcoin/descriptor/sp.rb', line 14 def key_arg @key_arg end |
#scan_key ⇒ Object (readonly)
Returns the value of attribute scan_key.
15 16 17 |
# File 'lib/bitcoin/descriptor/sp.rb', line 15 def scan_key @scan_key end |
#spend_key ⇒ Object (readonly)
Returns the value of attribute spend_key.
16 17 18 |
# File 'lib/bitcoin/descriptor/sp.rb', line 16 def spend_key @spend_key end |
Instance Method Details
#args ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bitcoin/descriptor/sp.rb', line 48 def args if key_arg # Single argument form key_arg else # Two argument form spend_arg = spend_key.is_a?(Expression) ? spend_key.to_s : spend_key "#{scan_key},#{spend_arg}" end end |
#has_spend_private_key? ⇒ Boolean
Check if this descriptor has spend private key (spspend form).
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bitcoin/descriptor/sp.rb', line 67 def has_spend_private_key? return @has_spend_private_key if defined?(@has_spend_private_key) if single_key? @has_spend_private_key else # Check if spend_key is a private key return false if spend_key.is_a?(Expression) begin key = extract_pubkey(spend_key) !key.priv_key.nil? rescue false end end end |
#single_key? ⇒ Boolean
Check if this is a single-argument form (spscan/spspend).
61 62 63 |
# File 'lib/bitcoin/descriptor/sp.rb', line 61 def single_key? !key_arg.nil? end |
#to_addr ⇒ Bech32::SilentPaymentAddr
Generate silent payment address.
85 86 87 88 89 90 91 92 |
# File 'lib/bitcoin/descriptor/sp.rb', line 85 def to_addr Bech32::SilentPaymentAddr.new( address_hrp, 0, extracted_scan_pubkey, extracted_spend_pubkey ) end |
#to_script ⇒ Object
Silent payment descriptors do not produce a single script. Use to_address to get the silent payment address.
97 98 99 |
# File 'lib/bitcoin/descriptor/sp.rb', line 97 def to_script raise RuntimeError, "sp() descriptor does not produce a fixed script. Use to_address instead." end |
#top_level? ⇒ Boolean
44 45 46 |
# File 'lib/bitcoin/descriptor/sp.rb', line 44 def top_level? true end |
#type ⇒ Object
40 41 42 |
# File 'lib/bitcoin/descriptor/sp.rb', line 40 def type :sp end |