Class: Xpring::Wallet
- Inherits:
-
Object
- Object
- Xpring::Wallet
- Defined in:
- lib/xpring/wallet.rb
Overview
Representation of a XRP wallet
Instance Attribute Summary collapse
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Class Method Summary collapse
- .from_mnemonic(mnemonic, derivation_path: nil, test: false) ⇒ Xpring::Wallet
- .from_seed(seed, test: false) ⇒ Xpring::Wallet
Instance Method Summary collapse
- #address ⇒ String
-
#initialize(public_key, private_key, test) ⇒ Wallet
constructor
A new instance of Wallet.
- #sign(input) ⇒ String
-
#to_javascript ⇒ String
Javascript constructor expression for this Wallet.
- #valid?(message, signature) ⇒ true, false
Constructor Details
#initialize(public_key, private_key, test) ⇒ Wallet
Returns a new instance of Wallet.
55 56 57 58 59 |
# File 'lib/xpring/wallet.rb', line 55 def initialize(public_key, private_key, test) @public_key = public_key.to_s @private_key = private_key.to_s @test = test end |
Instance Attribute Details
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
13 14 15 |
# File 'lib/xpring/wallet.rb', line 13 def private_key @private_key end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
13 14 15 |
# File 'lib/xpring/wallet.rb', line 13 def public_key @public_key end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
13 14 15 |
# File 'lib/xpring/wallet.rb', line 13 def test @test end |
Class Method Details
.from_mnemonic(mnemonic, derivation_path: nil, test: false) ⇒ Xpring::Wallet
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/xpring/wallet.rb', line 20 def self.from_mnemonic(mnemonic, derivation_path: nil, test: false) result = Javascript.run do <<~JAVASCRIPT #{Javascript::ENTRY_POINT}.Wallet.generateWalletFromMnemonic( '#{mnemonic}', '#{derivation_path&.to_s}' || #{Javascript::ENTRY_POINT}.Wallet.getDefaultDerivationPath(), #{test}, ); JAVASCRIPT end raise Error.new(INVALID_MNEMONIC_OR_DERIVATION_PATH_MSG) if result.nil? new(result[:publicKey], result[:privateKey], result[:test]) end |
.from_seed(seed, test: false) ⇒ Xpring::Wallet
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xpring/wallet.rb', line 40 def self.from_seed(seed, test: false) result = Javascript.run do <<~JAVASCRIPT #{Javascript::ENTRY_POINT}.Wallet.generateWalletFromSeed( '#{seed}', #{test}, ); JAVASCRIPT end new(result[:publicKey], result[:privateKey], result[:test]) end |
Instance Method Details
#address ⇒ String
62 63 64 65 66 67 68 |
# File 'lib/xpring/wallet.rb', line 62 def address @address ||= Javascript.run do <<~JAVASCRIPT #{to_javascript}.getAddress(); JAVASCRIPT end end |
#sign(input) ⇒ String
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/xpring/wallet.rb', line 73 def sign(input) signed = Javascript.run do <<~JAVASCRIPT #{to_javascript}.sign('#{input}'); JAVASCRIPT end raise Error.new(SIGN_ERROR_MSG) if signed.nil? signed end |
#to_javascript ⇒ String
Returns Javascript constructor expression for this Wallet.
96 97 98 99 100 101 102 103 104 |
# File 'lib/xpring/wallet.rb', line 96 def to_javascript <<~JAVASCRIPT new #{Javascript::ENTRY_POINT}.Wallet( '#{public_key}', '#{private_key}', #{test}, ) JAVASCRIPT end |
#valid?(message, signature) ⇒ true, false
87 88 89 90 91 92 93 |
# File 'lib/xpring/wallet.rb', line 87 def valid?(, signature) Javascript.run do <<~JAVASCRIPT #{to_javascript}.verify('#{}', '#{signature}'); JAVASCRIPT end == true end |