Class: Bitcoin::BIP324::EllSwiftPubkey

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ EllSwiftPubkey

Constructor

Parameters:

  • key (String)

    64 bytes of key data.

Raises:

  • Bitcoin::BIP324::InvalidEllSwiftKey If key is invalid.



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

#keyObject (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?

Parameters:

Returns:

  • (Boolean)


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

#decodeBitcoin::Key

Decode to public key.

Returns:



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