Class: Bitcoin::Descriptor::MuSig
- Inherits:
-
Expression
- Object
- Expression
- Bitcoin::Descriptor::MuSig
- Defined in:
- lib/bitcoin/descriptor/musig.rb
Overview
musig() descriptor class.
Constant Summary collapse
- CHAINCODE =
SHA256 of ‘MuSig2MuSig2MuSig2` github.com/bitcoin/bips/blob/master/bip-0328.mediawiki
'868087ca02a6f974c4598924c36b57762d32cb45717167e300622c7167e38965'.htb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(keys, path = nil) ⇒ Bitcoin::Descriptor::MuSig
constructor
Constructor.
-
#to_hex ⇒ String
Convert to single key with hex format.
- #to_s(checksum: nil) ⇒ Object
- #top_level? ⇒ Boolean
- #type ⇒ Object
Methods inherited from Expression
#==, #args, #compressed_key?, #derive_path, #extract_pubkey, #to_script
Constructor Details
#initialize(keys, path = nil) ⇒ Bitcoin::Descriptor::MuSig
Constructor.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bitcoin/descriptor/musig.rb', line 19 def initialize(keys, path = nil) raise ArgumentError, "keys must be an array." unless keys.is_a?(Array) unless path.nil? raise ArgumentError, "path must be String." unless path.is_a?(String) raise ArgumentError, "path must be start with /." unless path.start_with?("/") end validate_keys!(keys, path) @keys = keys @path = path end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
12 13 14 |
# File 'lib/bitcoin/descriptor/musig.rb', line 12 def keys @keys end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/bitcoin/descriptor/musig.rb', line 13 def path @path end |
Instance Method Details
#to_hex ⇒ String
Convert to single key with hex format.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bitcoin/descriptor/musig.rb', line 40 def to_hex sorted_key = Schnorr::MuSig2.sort_pubkeys(keys.map{|k| extract_pubkey(k).pubkey}) agg_key = Schnorr::MuSig2.aggregate(sorted_key) if path.nil? agg_key.x_only_pubkey else ext_key = Bitcoin::ExtPubkey.new ext_key.pubkey = agg_key.q.to_hex ext_key.depth = 0 ext_key.chain_code = CHAINCODE _, *paths = path.split('/') derived_key = derive_path(ext_key, paths) derived_key.key.xonly_pubkey end end |
#to_s(checksum: nil) ⇒ Object
56 57 58 59 60 |
# File 'lib/bitcoin/descriptor/musig.rb', line 56 def to_s(checksum: nil) desc = "#{type.to_s}(#{keys.join(',')})" desc << path if path checksum ? Checksum.descsum_create(desc) : desc end |
#top_level? ⇒ Boolean
34 35 36 |
# File 'lib/bitcoin/descriptor/musig.rb', line 34 def top_level? false end |
#type ⇒ Object
30 31 32 |
# File 'lib/bitcoin/descriptor/musig.rb', line 30 def type :musig end |