Class: CoinOp::Bit::MultiNode
- Inherits:
-
Object
- Object
- CoinOp::Bit::MultiNode
- Includes:
- Encodings
- Defined in:
- lib/coin-op/bit/multi_wallet.rb
Constant Summary collapse
- CODE_TO_NETWORK =
{ 0 => :bitcoin, 1 => :testnet3, 2 => :litecoin, 3 => :dogecoin }
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#private ⇒ Object
readonly
Returns the value of attribute private.
-
#public ⇒ Object
readonly
Returns the value of attribute public.
-
#public_keys ⇒ Object
readonly
Returns the value of attribute public_keys.
Instance Method Summary collapse
- #address ⇒ Object
-
#initialize(options) ⇒ MultiNode
constructor
A new instance of MultiNode.
- #network ⇒ Object
- #p2sh_address ⇒ Object
- #p2sh_script ⇒ Object
- #script(m = 2) ⇒ Object
- #script_sig(signatures) ⇒ Object
- #signatures(value, names:) ⇒ Object
Methods included from Encodings
#base58, #decode_base58, #decode_hex, #hex, #int_to_byte_array
Constructor Details
#initialize(options) ⇒ MultiNode
Returns a new instance of MultiNode.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 225 def initialize() @path = [:path] @keys = {} @public_keys = {} @private = [:private] @public = [:public] @private.each do |name, node| key = Bitcoin::Key.new(node.private_key.to_hex, node.public_key.to_hex) @keys[name] = key @public_keys[name] = key end @public.each do |name, node| @public_keys[name] = Bitcoin::Key.new(nil, node.public_key.to_hex) end end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
224 225 226 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 224 def keys @keys end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
224 225 226 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 224 def path @path end |
#private ⇒ Object (readonly)
Returns the value of attribute private.
224 225 226 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 224 def private @private end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
224 225 226 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 224 def public @public end |
#public_keys ⇒ Object (readonly)
Returns the value of attribute public_keys.
224 225 226 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 224 def public_keys @public_keys end |
Instance Method Details
#address ⇒ Object
253 254 255 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 253 def address script.address end |
#network ⇒ Object
243 244 245 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 243 def network CODE_TO_NETWORK.fetch(@path.split('/')[2].to_i) end |
#p2sh_address ⇒ Object
257 258 259 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 257 def p2sh_address script.p2sh_address end |
#p2sh_script ⇒ Object
261 262 263 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 261 def p2sh_script Script.new(:address => self.script.p2sh_address, network: network) end |
#script(m = 2) ⇒ Object
247 248 249 250 251 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 247 def script(m=2) # m of n keys = @public_keys.sort_by {|name, key| name }.map {|name, key| key.pub } Script.new(public_keys: keys, needed: m, network: network) end |
#script_sig(signatures) ⇒ Object
274 275 276 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 274 def script_sig(signatures) self.script.p2sh_sig(:signatures => signatures) end |
#signatures(value, names:) ⇒ Object
265 266 267 268 269 270 271 272 |
# File 'lib/coin-op/bit/multi_wallet.rb', line 265 def signatures(value, names:) out = {} @keys.each do |name, key| next unless names.include?(name) out[name] = base58(key.sign(value)) end out end |