diff --git a/lib/cardano_wallet/misc.rb b/lib/cardano_wallet/misc.rb index 91b1211..0ffd641 100644 --- a/lib/cardano_wallet/misc.rb +++ b/lib/cardano_wallet/misc.rb @@ -88,7 +88,7 @@ def initialize opt super end - # @see http://localhost:8000/specifications/api/#operation/signMetadata + # @see https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata def sign_metadata(wid, role, index, pass, metadata) payload = { passphrase: pass } payload[:metadata] = metadata if metadata @@ -99,6 +99,11 @@ def sign_metadata(wid, role, index, pass, metadata) 'Accept' => 'application/octet-stream'} ) end + # @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey + def get_public_key(wid, role, index) + self.class.get("/wallets/#{wid}/keys/#{role}/#{index}") + end + # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/inspectAddress def addresses(address_id) self.class.get("/addresses/#{address_id}") diff --git a/lib/cardano_wallet/shelley.rb b/lib/cardano_wallet/shelley.rb index 698a431..0f77d9d 100644 --- a/lib/cardano_wallet/shelley.rb +++ b/lib/cardano_wallet/shelley.rb @@ -48,6 +48,35 @@ def migrations Migrations.new @opt end + # API for Keys + # @see https://input-output-hk.github.io/cardano-wallet/api/#tag/Keys + def keys + Keys.new @opt + end + + end + + class Keys < Base + def initialize opt + super + end + + # @see https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata + def sign_metadata(wid, role, index, pass, metadata) + payload = { passphrase: pass } + payload[:metadata] = metadata if metadata + + self.class.post("/wallets/#{wid}/signatures/#{role}/#{index}", + :body => payload.to_json, + :headers => { 'Content-Type' => 'application/json', + 'Accept' => 'application/octet-stream'} ) + end + + # @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey + def get_public_key(wid, role, index) + self.class.get("/wallets/#{wid}/keys/#{role}/#{index}") + end + end # API for Wallets diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 4b54317..de7efc2 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -23,25 +23,6 @@ UTILS = CardanoWallet.new.misc.utils end - after(:all) do - teardown - end - - it "Get signed metadata" do - wid = create_shelley_wallet - ["utxo_internal", "utxo_external", "mutable_account", "multisig_script"].each do |role| - id = [*0..100000].sample - res = UTILS.sign_metadata(wid, - role, - id, - "Secure Passphrase", - { "0"=>{ "string"=>"cardano" } }) - puts "#{wid}/#{role}/#{id}" - expect(res.code).to eq 200 - end - - end - it "Inspect invalid address" do addr = "addr" res = UTILS.addresses addr diff --git a/spec/shelley_spec.rb b/spec/shelley_spec.rb index 11bec57..56d645b 100644 --- a/spec/shelley_spec.rb +++ b/spec/shelley_spec.rb @@ -580,4 +580,35 @@ end end + describe CardanoWallet::Shelley::Keys do + after(:each) do + teardown + end + + it "Get signed metadata" do + wid = create_shelley_wallet + ["utxo_internal", "utxo_external", "mutable_account", "multisig_script"].each do |role| + id = [*0..100000].sample + res = SHELLEY.keys.sign_metadata(wid, + role, + id, + "Secure Passphrase", + { "0"=>{ "string"=>"cardano" } }) + puts "#{wid}/#{role}/#{id}" + expect(res.code).to eq 200 + end + end + + it "Get public key" do + wid = create_shelley_wallet + ["utxo_internal", "utxo_external", "mutable_account", "multisig_script"].each do |role| + id = [*0..100000].sample + res = SHELLEY.keys.get_public_key(wid, role, id) + puts "#{wid}/#{role}/#{id}" + expect(res.code).to eq 200 + end + end + + end + end