Class: Bip44::Wallet
- Inherits:
-
Object
- Object
- Bip44::Wallet
- Includes:
- Bitcoin, BitcoinCash, Ethereum, Litecoin, Zcoin
- Defined in:
- lib/bip44/wallet.rb
Overview
“44’”, # bip 44 “60’”, # coin, 0’: bitcoin, 60’: ethereum “0’”, # wallet “0” # 0 - public, 1 = private “0” # index
Class Method Summary collapse
- .from_mnemonic(mnemonic, path) ⇒ Object
- .from_seed(seed, path) ⇒ Object
- .from_xprv(xprv) ⇒ Object
- .from_xpub(xpub) ⇒ Object
Instance Method Summary collapse
- #private_key ⇒ Object
- #public_key ⇒ Object
- #sub_wallet(path) ⇒ Object
- #wif(compressed: true, testnet: false) ⇒ Object
- #xprv(testnet: :false) ⇒ Object
- #xpub(testnet: false) ⇒ Object
Methods included from Zcoin
Methods included from Litecoin
Methods included from BitcoinCash
Methods included from Ethereum
Methods included from Bitcoin
Class Method Details
.from_mnemonic(mnemonic, path) ⇒ Object
21 22 23 24 |
# File 'lib/bip44/wallet.rb', line 21 def self.from_mnemonic(mnemonic, path) seed = BipMnemonic.to_seed(mnemonic: mnemonic) # 2. 该助记词使用 PBKDF2 转化为种子(参见 BIP39) Wallet.from_seed(seed, path) end |
.from_seed(seed, path) ⇒ Object
15 16 17 18 19 |
# File 'lib/bip44/wallet.rb', line 15 def self.from_seed(seed, path) master = MoneyTree::Master.new(seed_hex: seed) # 3. 种子用于使用 HMAC-SHA512 生成根私钥(参见 BIP32) wallet_node = master.node_for_path(path) # 4. 从该根私钥,导出子私钥(参见 BIP32),其中节点布局由BIP44设置 Wallet.new(wallet_node) end |
.from_xprv(xprv) ⇒ Object
31 32 33 34 |
# File 'lib/bip44/wallet.rb', line 31 def self.from_xprv(xprv) wallet_node = MoneyTree::Node.from_bip32(xprv) Wallet.new(wallet_node) end |
.from_xpub(xpub) ⇒ Object
26 27 28 29 |
# File 'lib/bip44/wallet.rb', line 26 def self.from_xpub(xpub) wallet_node = MoneyTree::Node.from_bip32(xpub) Wallet.new(wallet_node) end |
Instance Method Details
#private_key ⇒ Object
55 56 57 |
# File 'lib/bip44/wallet.rb', line 55 def private_key @wallet_node.private_key.to_hex end |
#public_key ⇒ Object
59 60 61 |
# File 'lib/bip44/wallet.rb', line 59 def public_key @wallet_node.public_key.uncompressed.to_hex end |
#sub_wallet(path) ⇒ Object
36 37 38 |
# File 'lib/bip44/wallet.rb', line 36 def sub_wallet(path) Wallet.new(@wallet_node.node_for_path(path)) end |
#wif(compressed: true, testnet: false) ⇒ Object
50 51 52 53 |
# File 'lib/bip44/wallet.rb', line 50 def wif(compressed: true, testnet: false) return @wallet_node.private_key.to_wif(compressed: compressed, network: :bitcoin_testnet) if testnet @wallet_node.private_key.to_wif(compressed: compressed) end |
#xprv(testnet: :false) ⇒ Object
45 46 47 48 |
# File 'lib/bip44/wallet.rb', line 45 def xprv(testnet: :false) return @wallet_node.to_bip32(:private, network: :bitcoin_testnet) if testnet @wallet_node.to_bip32(:private) end |
#xpub(testnet: false) ⇒ Object
40 41 42 43 |
# File 'lib/bip44/wallet.rb', line 40 def xpub(testnet: false) return @wallet_node.to_bip32(:public, network: :bitcoin_testnet) if testnet @wallet_node.to_bip32(:public) end |