Class: Arweave::Wallet

Inherits:
Object
  • Object
show all
Defined in:
lib/arweave/wallet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jwk) ⇒ Wallet

Returns a new instance of Wallet.



10
11
12
13
# File 'lib/arweave/wallet.rb', line 10

def initialize(jwk)
  @api = Api.instance
  @jwk = jwk.transform_keys!(&:to_sym)
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



8
9
10
# File 'lib/arweave/wallet.rb', line 8

def address
  @address
end

#apiObject (readonly)

Returns the value of attribute api.



8
9
10
# File 'lib/arweave/wallet.rb', line 8

def api
  @api
end

#ownerObject (readonly)

Returns the value of attribute owner.



8
9
10
# File 'lib/arweave/wallet.rb', line 8

def owner
  @owner
end

Instance Method Details

#balanceObject



34
35
36
37
38
39
40
41
# File 'lib/arweave/wallet.rb', line 34

def balance
  balance_in_winstons = BigDecimal(api.get_wallet_balance(address).body)

  OpenStruct.new(
    ar: balance_in_winstons / 1e12,
    winston: balance_in_winstons
  )
end

#last_transaction_idObject



43
44
45
# File 'lib/arweave/wallet.rb', line 43

def last_transaction_id
  api.get_last_transaction_id(address).body
end

#sign(message) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/arweave/wallet.rb', line 26

def sign(message)
  private_key.sign_pss(
    'SHA256',
    message,
    salt_length: 0, mgf1_hash: 'SHA256'
  )
end