Skip to content

Commit

Permalink
Sign metadata and get public key tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Oct 23, 2020
1 parent ad1327c commit b1f6835
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 20 deletions.
7 changes: 6 additions & 1 deletion lib/cardano_wallet/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand Down
29 changes: 29 additions & 0 deletions lib/cardano_wallet/shelley.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions spec/misc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/shelley_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b1f6835

Please sign in to comment.