Class: Bitcoin::BIP324::EllSwiftPubkey
- Inherits:
-
Object
- Object
- Bitcoin::BIP324::EllSwiftPubkey
- Includes:
- Schnorr::Util
- Defined in:
- lib/bitcoin/bip324/ell_swift_pubkey.rb
Overview
An ElligatorSwift-encoded public key.
Constant Summary collapse
- SIZE =
64
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Check whether same public key or not?.
-
#decode ⇒ Bitcoin::Key
Decode to public key.
-
#initialize(key) ⇒ EllSwiftPubkey
constructor
Constructor.
Constructor Details
#initialize(key) ⇒ EllSwiftPubkey
Constructor
14 15 16 17 |
# File 'lib/bitcoin/bip324/ell_swift_pubkey.rb', line 14 def initialize(key) @key = hex2bin(key) raise Bitcoin::BIP324::InvalidEllSwiftKey, 'key must be 64 bytes.' unless @key.bytesize == SIZE end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/bitcoin/bip324/ell_swift_pubkey.rb', line 9 def key @key end |
Instance Method Details
#==(other) ⇒ Boolean
Check whether same public key or not?
36 37 38 39 |
# File 'lib/bitcoin/bip324/ell_swift_pubkey.rb', line 36 def ==(other) return false unless other.is_a?(EllSwiftPubkey) key == other.key end |
#decode ⇒ Bitcoin::Key
Decode to public key.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bitcoin/bip324/ell_swift_pubkey.rb', line 21 def decode if Bitcoin.secp_impl.native? pubkey = Bitcoin.secp_impl.ellswift_decode(key) Bitcoin::Key.new(pubkey: pubkey, key_type: Bitcoin::Key::TYPES[:compressed]) else u = key[0...32].bth t = key[32..-1].bth x = BIP324.xswiftec(u, t) Bitcoin::Key.new(pubkey: "03#{x}") end end |