Class: Round::WalletCollection

Inherits:
Collection show all
Defined in:
lib/round/wallet.rb

Instance Attribute Summary

Attributes inherited from Collection

#collection

Attributes inherited from Base

#resource

Instance Method Summary collapse

Methods inherited from Collection

#[], #add, #method_missing, #populate_data, #refresh

Methods inherited from Base

association, #hash_identifier, hash_identifier, #method_missing, #refresh

Constructor Details

#initialize(options, &block) ⇒ WalletCollection

Returns a new instance of WalletCollection.



41
42
43
44
# File 'lib/round/wallet.rb', line 41

def initialize(options, &block)
  super
  @application = options[:application]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Round::Collection

Instance Method Details

#content_typeObject



46
47
48
# File 'lib/round/wallet.rb', line 46

def content_type
  Round::Wallet
end

#create(name, passphrase, network: 'bitcoin_testnet', multiwallet: CoinOp::Bit::MultiWallet.generate([:primary, :backup])) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/round/wallet.rb', line 50

def create(name, passphrase, network: 'bitcoin_testnet',
           multiwallet: CoinOp::Bit::MultiWallet.generate([:primary, :backup]))
  backup = multiwallet.private_seed(:backup, network: :bitcoin)
  multiwallet.drop_private(:backup)
  backup_master = multiwallet.trees[:backup]
  new_bmaster = MoneyTree::Master.new(public_key: backup_master.public_key, chain_code: backup_master.chain_code)
  multiwallet.trees[:backup] = new_bmaster
  wallet_resource = create_wallet_resource(multiwallet, passphrase, name)
  multiwallet.import(
    cosigner_public_seed: wallet_resource.cosigner_public_seed
  )
  wallet = Round::Wallet.new(
    resource: wallet_resource,
    multiwallet: multiwallet,
    application: @application,
    client: @client
  )
  add(wallet)
  [backup, wallet]
end

#create_wallet_resource(multiwallet, passphrase, name) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/round/wallet.rb', line 71

def create_wallet_resource(multiwallet, passphrase, name)
  primary_seed = CoinOp::Encodings.hex(multiwallet.trees[:primary].seed)
  ## Encrypt the primary seed using a passphrase-derived key
  encrypted_seed = CoinOp::Crypto::PassphraseBox.encrypt(passphrase, primary_seed)

  @resource.create(
    name: name,
    backup_public_seed: multiwallet.trees[:backup].to_bip32,
    primary_public_seed: multiwallet.trees[:primary].to_bip32,
    primary_private_seed: encrypted_seed
  )
end