Class: Bitcoin::SilentPayment::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/silent_payment/output.rb

Overview

Represents a detected silent payment output.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tx_out, tweak, label = nil) ⇒ Output

Returns a new instance of Output.

Parameters:

  • tx_out (Bitcoin::TxOut)

    The detected transaction output.

  • tweak (String)

    The tweak value (t_k) as 32 bytes binary.

  • label (Integer, nil) (defaults to: nil)

    The label integer, or nil if no label was used.

Raises:

  • (ArgumentError)

    If any parameter has an invalid type.



18
19
20
21
22
23
24
25
# File 'lib/bitcoin/silent_payment/output.rb', line 18

def initialize(tx_out, tweak, label = nil)
  raise ArgumentError, "tx_out must be a Bitcoin::TxOut." unless tx_out.is_a?(Bitcoin::TxOut)
  raise ArgumentError, "tweak must be a 32-byte String." unless tweak.is_a?(String) && tweak.bytesize == 32
  raise ArgumentError, "label must be an Integer or nil." unless label.nil? || label.is_a?(Integer)
  @tx_out = tx_out
  @tweak = tweak
  @label = label
end

Instance Attribute Details

#labelInteger? (readonly)

Returns The label used for this output, or nil if no label was used.

Returns:

  • (Integer, nil)

    The label used for this output, or nil if no label was used.



12
13
14
# File 'lib/bitcoin/silent_payment/output.rb', line 12

def label
  @label
end

#tweakString (readonly)

Returns The tweak value (t_k) used to derive the output key (32 bytes binary).

Returns:

  • (String)

    The tweak value (t_k) used to derive the output key (32 bytes binary).



9
10
11
# File 'lib/bitcoin/silent_payment/output.rb', line 9

def tweak
  @tweak
end

#tx_outBitcoin::TxOut (readonly)

Returns The detected transaction output.

Returns:



6
7
8
# File 'lib/bitcoin/silent_payment/output.rb', line 6

def tx_out
  @tx_out
end

Instance Method Details

#labeled?Boolean

Returns whether this output was detected using a label.

Returns:

  • (Boolean)


41
42
43
# File 'lib/bitcoin/silent_payment/output.rb', line 41

def labeled?
  !label.nil?
end

#pubkeyString

Returns the x-only public key of the output.

Returns:

  • (String)

    The x-only public key as hex string.



29
30
31
# File 'lib/bitcoin/silent_payment/output.rb', line 29

def pubkey
  tx_out.script_pubkey.witness_data[1].bth
end

#tweak_hexString

Returns the tweak as hex string.

Returns:

  • (String)

    The tweak value as hex string.



35
36
37
# File 'lib/bitcoin/silent_payment/output.rb', line 35

def tweak_hex
  tweak.bth
end