From 41c8d2471e0908325b7f1668e469312443220534 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 30 Sep 2022 11:58:57 +0200 Subject: [PATCH 1/7] update cardano-addresses --- cabal.project | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal.project b/cabal.project index c070da6cf80..11241d75efd 100644 --- a/cabal.project +++ b/cabal.project @@ -115,8 +115,8 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/cardano-addresses - tag: d6dcd277d92c76e45d1024f7d82837fc0907aa12 - --sha256: 1fhinmf9s99h2sbwjvwyh7nx7phmqk8bz1mhv3caq9vk87yawfnk + tag: 5094fb9d304ed69adedc99513634a00cbf850fca + --sha256: 1zhi8kvr2yhn50dm3dwwb1jlm5yl0y6c6hg39cs6abbxqmsj5jlv subdir: command-line core From 26b5260ec91c981dd955cab581ae831927783e3f Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 30 Sep 2022 12:53:00 +0200 Subject: [PATCH 2/7] Test cardano-wallet mnemonic_snd_factor parity with cardano-addresses --- test/e2e/helpers/cardano_addresses.rb | 5 ++- test/e2e/spec/shelley_spec.rb | 52 ++++++++++++++++++++++++--- test/e2e/spec/spec_helper.rb | 1 + 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/test/e2e/helpers/cardano_addresses.rb b/test/e2e/helpers/cardano_addresses.rb index 809d9a2e8cf..734c3077f9d 100644 --- a/test/e2e/helpers/cardano_addresses.rb +++ b/test/e2e/helpers/cardano_addresses.rb @@ -4,9 +4,8 @@ class CardanoAddresses ## # @param mnemonics - # @param type = Byron | Icarus | Shelley | Shared - def prv_key_from_recovery_phrase(mnemonics, type) - cmd(%(echo #{mnemonics.join(' ')}| cardano-address key from-recovery-phrase #{type})).gsub("\n", '') + def prv_key_from_recovery_phrase(mnemonics, cmd_params) + cmd(%(echo #{mnemonics.join(' ')}| cardano-address key from-recovery-phrase #{cmd_params})).gsub("\n", '') end def key_public(key, with_chain_code = true) diff --git a/test/e2e/spec/shelley_spec.rb b/test/e2e/spec/shelley_spec.rb index 4693dfb9214..c922f08e687 100644 --- a/test/e2e/spec/shelley_spec.rb +++ b/test/e2e/spec/shelley_spec.rb @@ -569,6 +569,20 @@ end end + it "Create account public key - non_extended" do + m24 = mnemonic_sentence(24) + wid = create_shelley_wallet("Wallet", m24) + ["0H", "1H", "2147483647H", "44H"].each do |index| + payload = { passphrase: PASS, format: 'non_extended' } + res = SHELLEY.keys.create_acc_public_key(wid, index, payload) + expect(res.to_s).to include cardano_address_get_acc_xpub(m24, + "1852H/1815H/#{index}", + hex = false, + "Shelley", + "--without-chain-code") + end + end + it "Create account public key - extended with purpose" do m24 = mnemonic_sentence(24) wid = create_shelley_wallet("Wallet", m24) @@ -614,10 +628,40 @@ end it "Get account public key - wallet from mnemonics" do - wid = create_shelley_wallet - res = SHELLEY.keys.get_acc_public_key(wid, { format: "extended" }) - expect(res).to be_correct_and_respond 200 - expect(res.to_s).to include "acct_xvk" + m24 = mnemonic_sentence(24) + wid = create_shelley_wallet("Wallet", m24) + + # Get account pub key from the wallet + w_acct_key = SHELLEY.keys.get_acc_public_key(wid, { format: "extended" }) + expect(w_acct_key).to be_correct_and_respond 200 + + # Get equivalent account pub key using cardano-addresses + root_xsk = CA.prv_key_from_recovery_phrase(m24, "Shelley") + acct_key = CA.key_child(root_xsk, "1852H/1815H/0H") + pub_key = CA.key_public(acct_key, with_chain_code = true) + + expect(pub_key).to eq w_acct_key.parsed_response + end + + it "Get account public key (mnemonic_snd_factor)" do + m24 = mnemonic_sentence(24) + m12 = mnemonic_sentence(12) + wid = create_shelley_wallet("Wallet", m24, m12) + + # Get account pub key from the wallet + w_acct_key = SHELLEY.keys.get_acc_public_key(wid, {format: 'extended'}) + expect(w_acct_key).to be_correct_and_respond 200 + + # Get equivalent account pub key using cardano-addresses + pub_key = Dir.mktmpdir do |dir| + sndfactor_file = File.join(dir, 'sndfactor.prv') + File.open(sndfactor_file, 'w') { |file| file.write(m12.join ' ') } + root_xsk = CA.prv_key_from_recovery_phrase(m24, "Shelley --passphrase from-mnemonic --from-file #{sndfactor_file}") + acct_key = CA.key_child(root_xsk, "1852H/1815H/0H") + CA.key_public(acct_key, with_chain_code = true) + end + + expect(pub_key).to eq w_acct_key.parsed_response end it "I can create and get policy key and it's hash" do diff --git a/test/e2e/spec/spec_helper.rb b/test/e2e/spec/spec_helper.rb index 0f1bb478bcf..a835e760eb4 100644 --- a/test/e2e/spec/spec_helper.rb +++ b/test/e2e/spec/spec_helper.rb @@ -4,6 +4,7 @@ require "blake2b" require "mustache" require "cbor" +require 'tmpdir' require_relative "../env" require_relative "../helpers/utils" require_relative "../helpers/matchers" From 85ecdffccaab719eef425a50e034bb0d1b8f1a04 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 30 Sep 2022 12:58:34 +0200 Subject: [PATCH 3/7] More strict assertions in Key tests --- test/e2e/spec/shelley_spec.rb | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/test/e2e/spec/shelley_spec.rb b/test/e2e/spec/shelley_spec.rb index c922f08e687..47199af2b09 100644 --- a/test/e2e/spec/shelley_spec.rb +++ b/test/e2e/spec/shelley_spec.rb @@ -548,7 +548,7 @@ payload = { passphrase: PASS, format: 'extended' } res = SHELLEY.keys.create_acc_public_key(wid, index, payload) expect(res).to be_correct_and_respond 202 - expect(res.to_s).to include cardano_address_get_acc_xpub(m24, + expect(res.parsed_response).to eq cardano_address_get_acc_xpub(m24, "1852H/1815H/#{index}", hex = false, "Shelley") @@ -561,21 +561,7 @@ ["0H", "1H", "2147483647H", "44H"].each do |index| payload = { passphrase: PASS, format: 'non_extended' } res = SHELLEY.keys.create_acc_public_key(wid, index, payload) - expect(res.to_s).to include cardano_address_get_acc_xpub(m24, - "1852H/1815H/#{index}", - hex = false, - "Shelley", - "--without-chain-code") - end - end - - it "Create account public key - non_extended" do - m24 = mnemonic_sentence(24) - wid = create_shelley_wallet("Wallet", m24) - ["0H", "1H", "2147483647H", "44H"].each do |index| - payload = { passphrase: PASS, format: 'non_extended' } - res = SHELLEY.keys.create_acc_public_key(wid, index, payload) - expect(res.to_s).to include cardano_address_get_acc_xpub(m24, + expect(res.parsed_response).to eq cardano_address_get_acc_xpub(m24, "1852H/1815H/#{index}", hex = false, "Shelley", @@ -591,7 +577,7 @@ res = SHELLEY.keys.create_acc_public_key(wid, index_purpose, payload) expect(res).to be_correct_and_respond 202 type_for_cardano_address = index_purpose == "1854H" ? "Shared" : "Shelley" - expect(res.to_s).to include cardano_address_get_acc_xpub(m24, + expect(res.parsed_response).to eq cardano_address_get_acc_xpub(m24, "#{index_purpose}/1815H/#{index_purpose}", hex = false, type_for_cardano_address) @@ -606,7 +592,7 @@ res = SHELLEY.keys.create_acc_public_key(wid, index_purpose, payload) expect(res).to be_correct_and_respond 202 type_for_cardano_address = index_purpose == "1854H" ? "Shared" : "Shelley" - expect(res.to_s).to include cardano_address_get_acc_xpub(m24, + expect(res.parsed_response).to eq cardano_address_get_acc_xpub(m24, "#{index_purpose}/1815H/#{index_purpose}", hex = false, type_for_cardano_address, @@ -624,7 +610,7 @@ res = SHELLEY.keys.get_acc_public_key(wallet['id'], { format: "non_extended" }) expect(res).to be_correct_and_respond 200 - expect(res.to_s).to include "acct_vk" + expect(res.parsed_response).to include "acct_vk" end it "Get account public key - wallet from mnemonics" do From 52df74cd56513bb55568b7b61f7cbcfff1345bba Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 30 Sep 2022 13:01:25 +0200 Subject: [PATCH 4/7] update test deps --- test/e2e/Gemfile | 3 +-- test/e2e/Gemfile.lock | 6 +++--- test/e2e/gemset.nix | 46 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/test/e2e/Gemfile b/test/e2e/Gemfile index 1d3d11ea2c8..4ece58fe25e 100644 --- a/test/e2e/Gemfile +++ b/test/e2e/Gemfile @@ -1,8 +1,7 @@ source 'https://rubygems.org' -gem 'cardano_wallet', '~> 0.3.26' +gem 'cardano_wallet', '~> 0.3.27' # gem 'cardano_wallet', path: "~/wb/cardano_wallet" -gem 'bip_mnemonic', '0.0.4' gem 'rake', '12.3.3' gem 'rspec', '3.10.0' gem 'mustache', '1.1.1' diff --git a/test/e2e/Gemfile.lock b/test/e2e/Gemfile.lock index 0d2ff60bb17..d0d9a213951 100644 --- a/test/e2e/Gemfile.lock +++ b/test/e2e/Gemfile.lock @@ -3,7 +3,8 @@ GEM specs: bip_mnemonic (0.0.4) blake2b (0.10.0) - cardano_wallet (0.3.26) + cardano_wallet (0.3.27) + bip_mnemonic (~> 0.0.4) httparty (~> 0.18.0) cbor (0.5.9.6) diff-lcs (1.4.4) @@ -34,9 +35,8 @@ PLATFORMS ruby DEPENDENCIES - bip_mnemonic (= 0.0.4) blake2b (= 0.10.0) - cardano_wallet (~> 0.3.26) + cardano_wallet (~> 0.3.27) cbor (= 0.5.9.6) mustache (= 1.1.1) rake (= 12.3.3) diff --git a/test/e2e/gemset.nix b/test/e2e/gemset.nix index 81cc819c0d2..dfbc03d4a17 100644 --- a/test/e2e/gemset.nix +++ b/test/e2e/gemset.nix @@ -9,16 +9,36 @@ }; version = "0.0.4"; }; + blake2b = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1i7kxnnvv2lqglc1crhkqp0s9hybx20wgrl04jqkk7y2sawyb6hg"; + type = "gem"; + }; + version = "0.10.0"; + }; cardano_wallet = { - dependencies = ["httparty"]; + dependencies = ["bip_mnemonic" "httparty"]; groups = ["default"]; platforms = []; source = { remotes = ["https://rubygems.org"]; - sha256 = "03xsp9v8za8xm9ry0vld2ygqaa60c14gq3wjnvll62pxr3ablwj6"; + sha256 = "1ay11nh7wcri87zzvn4i3n9lx0wnv2d5wfknk5nx8zyvlk8305r7"; type = "gem"; }; - version = "0.3.7"; + version = "0.3.27"; + }; + cbor = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "0511idr8xps9625nh3kxr68sdy6l3xy2kcz7r57g47fxb1v18jj3"; + type = "gem"; + }; + version = "0.5.9.6"; }; diff-lcs = { groups = ["default"]; @@ -47,20 +67,20 @@ platforms = []; source = { remotes = ["https://rubygems.org"]; - sha256 = "1zj12l9qk62anvk9bjvandpa6vy4xslil15wl6wlivyf51z773vh"; + sha256 = "0ipw892jbksbxxcrlx9g5ljq60qx47pm24ywgfbyjskbcl78pkvb"; type = "gem"; }; - version = "3.3.1"; + version = "3.4.1"; }; mime-types-data = { groups = ["default"]; platforms = []; source = { remotes = ["https://rubygems.org"]; - sha256 = "1phcq7z0zpipwd7y4fbqmlaqghv07fjjgrx99mwq3z3n0yvy7fmi"; + sha256 = "003gd7mcay800k2q4pb2zn8lwwgci4bhi42v2jvlidm8ksx03i6q"; type = "gem"; }; - version = "3.2021.0225"; + version = "3.2022.0105"; }; multi_xml = { groups = ["default"]; @@ -72,6 +92,16 @@ }; version = "0.6.0"; }; + mustache = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1l0p4wx15mi3wnamfv92ipkia4nsx8qi132c6g51jfdma3fiz2ch"; + type = "gem"; + }; + version = "1.1.1"; + }; rake = { groups = ["default"]; platforms = []; @@ -136,4 +166,4 @@ }; version = "3.10.2"; }; -} \ No newline at end of file +} From c6c27571e313c74728495023cbac388a2fb92e3d Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 30 Sep 2022 14:14:18 +0200 Subject: [PATCH 5/7] Remove bip_mnemonic dependency --- test/e2e/Rakefile | 40 +++++++++---------- test/e2e/helpers/utils.rb | 23 +---------- test/e2e/spec/byron_spec.rb | 10 ++--- test/e2e/spec/lightmode_spec.rb | 4 +- test/e2e/spec/shared_spec.rb | 68 ++++++++++++++++----------------- test/e2e/spec/shelley_spec.rb | 48 +++++++++++------------ test/e2e/spec/spec_helper.rb | 4 +- 7 files changed, 88 insertions(+), 109 deletions(-) diff --git a/test/e2e/Rakefile b/test/e2e/Rakefile index c517a01d6c9..4a4393a14db 100644 --- a/test/e2e/Rakefile +++ b/test/e2e/Rakefile @@ -58,38 +58,38 @@ end task :fixture_wallets_template do log ">> Creating #{FIXTURES_FILE}" - + utils = CardanoWallet.new.utils fixture_wallets = { :linux => { - :fixture => { :shelley => mnemonic_sentence(24), - :icarus => mnemonic_sentence(15), - :random => mnemonic_sentence(12), - :shelley_light => mnemonic_sentence(24) + :fixture => { :shelley => utils.mnemonic_sentence(24), + :icarus => utils.mnemonic_sentence(15), + :random => utils.mnemonic_sentence(12), + :shelley_light => utils.mnemonic_sentence(24) }, - :target => { :shelley => mnemonic_sentence(24), - :shared => mnemonic_sentence(24) + :target => { :shelley => utils.mnemonic_sentence(24), + :shared => utils.mnemonic_sentence(24) } }, :macos => { - :fixture => { :shelley => mnemonic_sentence(24), - :icarus => mnemonic_sentence(15), - :random => mnemonic_sentence(12), - :shelley_light => mnemonic_sentence(24) + :fixture => { :shelley => utils.mnemonic_sentence(24), + :icarus => utils.mnemonic_sentence(15), + :random => utils.mnemonic_sentence(12), + :shelley_light => utils.mnemonic_sentence(24) }, - :target => { :shelley => mnemonic_sentence(24), - :shared => mnemonic_sentence(24) + :target => { :shelley => utils.mnemonic_sentence(24), + :shared => utils.mnemonic_sentence(24) } }, :windows => { - :fixture => { :shelley => mnemonic_sentence(24), - :icarus => mnemonic_sentence(15), - :random => mnemonic_sentence(12), - :shelley_light => mnemonic_sentence(24) + :fixture => { :shelley => utils.mnemonic_sentence(24), + :icarus => utils.mnemonic_sentence(15), + :random => utils.mnemonic_sentence(12), + :shelley_light => utils.mnemonic_sentence(24) }, - :target => { :shelley => mnemonic_sentence(24), - :shared => mnemonic_sentence(24) + :target => { :shelley => utils.mnemonic_sentence(24), + :shared => utils.mnemonic_sentence(24) } }, - :currency_contract_wallet => mnemonic_sentence(24) + :currency_contract_wallet => utils.mnemonic_sentence(24) } if File.exists?(FIXTURES_FILE) err = " diff --git a/test/e2e/helpers/utils.rb b/test/e2e/helpers/utils.rb index f1a9fedbffd..9206c94f70b 100644 --- a/test/e2e/helpers/utils.rb +++ b/test/e2e/helpers/utils.rb @@ -1,4 +1,3 @@ -require 'bip_mnemonic' require 'httparty' require 'fileutils' @@ -93,26 +92,6 @@ def get_fixture_wallet_mnemonics(kind, type) end end - def mnemonic_sentence(word_count = 15) - case word_count - when 9 - bits = 96 - when 12 - bits = 128 - when 15 - bits = 164 - when 18 - bits = 196 - when 21 - bits = 224 - when 24 - bits = 256 - else - raise "Non-supported no of words #{word_count}!" - end - BipMnemonic.to_mnemonic(bits: bits, language: 'english').split - end - def wget(url, file = nil) file ||= File.basename(url) resp = HTTParty.get(url) @@ -195,7 +174,7 @@ def get_protocol_magic(env) def base64?(value) value.is_a?(String) && Base64.strict_encode64(Base64.decode64(value)) == value end - + def base16?(value) value.is_a?(String) && value.match?(/^[[:xdigit:]]+$/) end diff --git a/test/e2e/spec/byron_spec.rb b/test/e2e/spec/byron_spec.rb index 511c88c26a1..eafe7d67198 100644 --- a/test/e2e/spec/byron_spec.rb +++ b/test/e2e/spec/byron_spec.rb @@ -24,7 +24,7 @@ payload = { style: "icarus", name: "Wallet from mnemonic_sentence", passphrase: "Secure Passphrase", - mnemonic_sentence: mnemonic_sentence(15) + mnemonic_sentence: CW.utils.mnemonic_sentence(15) } wallet = WalletFactory.create(:byron, payload) expect(wallet).to be_correct_and_respond 201 @@ -38,7 +38,7 @@ payload = { style: "random", name: "Wallet from mnemonic_sentence", passphrase: "Secure Passphrase", - mnemonic_sentence: mnemonic_sentence(12) + mnemonic_sentence: CW.utils.mnemonic_sentence(12) } wallet = WalletFactory.create(:byron, payload) expect(wallet).to be_correct_and_respond 201 @@ -99,7 +99,7 @@ wallet_type = m[0] wallet_style = m[1] it "I can get #{wallet_type} #{wallet_style} walletid using cardano-addresses" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) wid = create_byron_wallet(style = wallet_style, "Wallet - ID", mnemonics) # based on root prv key @@ -114,7 +114,7 @@ end it "#{wallet_type} walletid is not based on acct key" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) wid = create_byron_wallet(style = wallet_style, "Wallet - ID", mnemonics) # based on acct prv key @@ -206,7 +206,7 @@ end it "I can import address - random" do - mnemonics = mnemonic_sentence(15) + mnemonics = CW.utils.mnemonic_sentence(15) derivation_path = '14H/42H' id = create_byron_wallet("random", "Wallet - import", mnemonics) diff --git a/test/e2e/spec/lightmode_spec.rb b/test/e2e/spec/lightmode_spec.rb index 315e112e319..0af9af733f3 100644 --- a/test/e2e/spec/lightmode_spec.rb +++ b/test/e2e/spec/lightmode_spec.rb @@ -16,8 +16,8 @@ wait_for_shelley_wallet_to_sync(wid) wallet = SHELLEY.wallets.get(wid) txs = SHELLEY.transactions.list(wid) - expect(wallet['balance']['total']['quantity']).to eq 500000000 - expect(txs.size).to eq 1 + expect(wallet['balance']['total']['quantity']).to > 0 + expect(txs.size).to eq > 0 end describe "Network" do diff --git a/test/e2e/spec/shared_spec.rb b/test/e2e/spec/shared_spec.rb index 6644b9cc803..802f5cde399 100644 --- a/test/e2e/spec/shared_spec.rb +++ b/test/e2e/spec/shared_spec.rb @@ -8,7 +8,7 @@ describe "Create wallets" do it "I can create, get and delete wallet from mnemonics getting acc_xpub from cardano-address" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") script_template = { "cosigners" => @@ -43,7 +43,7 @@ end it "I can create, get and delete wallet from pub key getting acc_xpub from cardano-address" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") @@ -88,9 +88,9 @@ end it "Cannot create wallet with different acc xpub - derived from different mnemonic sentence" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' - acc_xpub_wrong = cardano_address_get_acc_xpub(mnemonic_sentence(24), + acc_xpub_wrong = cardano_address_get_acc_xpub(CW.utils.mnemonic_sentence(24), "1854H/1815H/0H") payment_script_template = { "cosigners" => @@ -129,7 +129,7 @@ end it "Cannot create wallet with different acc xpub - derived from different acc ix" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub_wrong = cardano_address_get_acc_xpub(m24, "1854H/1815H/255H") @@ -169,14 +169,14 @@ end it "I can create incomplete wallet and update cosigners with acc_xpub from cardano-address" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) addr = SHARED.addresses.list(incomplete_wid) expect(addr).to be_correct_and_respond 200 expect(addr.size).to eq 0 - acc_xpub_upd = cardano_address_get_acc_xpub(mnemonic_sentence(24), + acc_xpub_upd = cardano_address_get_acc_xpub(CW.utils.mnemonic_sentence(24), "1854H/1815H/0H") update_payment = SHARED.wallets.update_payment_script(incomplete_wid, @@ -205,11 +205,11 @@ end it "Create / update partially / get / list / delete" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) - acc_xpub_upd = cardano_address_get_acc_xpub(mnemonic_sentence(24), + acc_xpub_upd = cardano_address_get_acc_xpub(CW.utils.mnemonic_sentence(24), "1854H/1815H/0H") update_payment = SHARED.wallets.update_payment_script(incomplete_wid, @@ -227,10 +227,10 @@ end it "Cannot update main cosigner" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) - acc_xpub_upd = cardano_address_get_acc_xpub(mnemonic_sentence(24), + acc_xpub_upd = cardano_address_get_acc_xpub(CW.utils.mnemonic_sentence(24), "1854H/1815H/0H") update_payment = SHARED.wallets.update_payment_script(incomplete_wid, @@ -247,7 +247,7 @@ end it "Cannot update cosigner with main cosigner's xpub" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) @@ -265,7 +265,7 @@ end it "I can create/get/list/delete wallet using cosigner: 'self' - from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' script_template = { "cosigners" => { "cosigner#0" => "self" }, @@ -300,7 +300,7 @@ end it "I can create/get/list/delete wallet using cosigner: 'self' - from pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") payment_script_template = { "cosigners" => @@ -347,7 +347,7 @@ describe "Wallet id" do it "Shared walletid with only spending template from cardano-addresses" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) acc_ix = '0H' script_template = { "cosigners" => { "cosigner#0" => "self" }, "template" => @@ -385,7 +385,7 @@ end it "Shared walletid with spending and delegation template from cardano-addresses" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) acc_ix = '0H' script_template = { "cosigners" => { "cosigner#0" => "self" }, "template" => @@ -438,7 +438,7 @@ describe "Addresses" do it "Can list addresses on active shared wallet - from pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") active_wid = create_active_shared_wallet(acc_xpub, acc_ix, "self") @@ -457,7 +457,7 @@ end it "Can list addresses on active shared wallet - from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) active_wid = create_active_shared_wallet(m24, '0H', "self") a = SHARED.addresses.list(active_wid) @@ -474,7 +474,7 @@ end it "Lists empty addresses on incomplete shared wallet - from pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") incomplete_wid = create_incomplete_shared_wallet(acc_xpub, acc_ix, "self") @@ -491,7 +491,7 @@ expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 - acc_xpub = cardano_address_get_acc_xpub(mnemonic_sentence(24), "1854H/1815H/0H") + acc_xpub = cardano_address_get_acc_xpub(CW.utils.mnemonic_sentence(24), "1854H/1815H/0H") patch_incomplete_shared_wallet(incomplete_wid, {"cosigner#1" => acc_xpub}, {"cosigner#1" => acc_xpub}) @@ -510,7 +510,7 @@ end it "Lists empty addresses on incomplete shared wallet - from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) incomplete_wid = create_incomplete_shared_wallet(m24, '0H', "self") a = SHARED.addresses.list(incomplete_wid) @@ -525,7 +525,7 @@ expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 - acc_xpub = cardano_address_get_acc_xpub(mnemonic_sentence(24), "1854H/1815H/0H") + acc_xpub = cardano_address_get_acc_xpub(CW.utils.mnemonic_sentence(24), "1854H/1815H/0H") patch_incomplete_shared_wallet(incomplete_wid, {"cosigner#1" => acc_xpub}, {"cosigner#1" => acc_xpub}) @@ -557,7 +557,7 @@ } it "Get public key - incomplete wallet from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) @@ -577,7 +577,7 @@ end it "Get public key - incomplete wallet from acc pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") incomplete_wid = create_incomplete_shared_wallet(acc_xpub, acc_ix, acc_xpub) @@ -598,7 +598,7 @@ end it "Get public key - active wallet from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) active_wid = create_incomplete_shared_wallet(m24, '11H', 'self') matrix.each do |role, addr_prefix| @@ -617,7 +617,7 @@ end it "Get public key - active wallet from acc pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") active_wid = create_active_shared_wallet(acc_xpub, acc_ix, "self") @@ -641,7 +641,7 @@ describe "Account Public Keys" do it "Create account public key - incomplete wallet from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) der_path = "1854H/1815H/0H" acc_xpub = cardano_address_get_acc_xpub(m24, der_path) incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) @@ -667,7 +667,7 @@ end it "Cannot create account public key - incomplete wallet from acc pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") incomplete_wid = create_incomplete_shared_wallet(acc_xpub, acc_ix, "self") @@ -683,7 +683,7 @@ end it "Create account public key - active wallet from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") active_wid = create_active_shared_wallet(m24, '0H', acc_xpub) ["0H", "1H", "2147483647H", "44H"].each do |index| @@ -705,7 +705,7 @@ end it "Cannot create account public key - active wallet from acc pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") active_wid = create_active_shared_wallet(acc_xpub, acc_ix, "self") @@ -721,7 +721,7 @@ end it "Get account public key - active wallet from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") active_wid = create_active_shared_wallet(m24, '0H', acc_xpub) @@ -739,7 +739,7 @@ end it "Get account public key - active wallet from acc pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") active_wid = create_active_shared_wallet(acc_xpub, acc_ix, "self") @@ -758,7 +758,7 @@ end it "Get account public key - incomplete wallet from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) @@ -776,7 +776,7 @@ end it "Get account public key - incomplete wallet from acc pub key" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") incomplete_wid = create_incomplete_shared_wallet(acc_xpub, acc_ix, "self") diff --git a/test/e2e/spec/shelley_spec.rb b/test/e2e/spec/shelley_spec.rb index 47199af2b09..3e06c58ab18 100644 --- a/test/e2e/spec/shelley_spec.rb +++ b/test/e2e/spec/shelley_spec.rb @@ -30,7 +30,7 @@ it "I can create, get and delete wallet from mnemonics" do payload = { name: "Wallet from mnemonic_sentence", passphrase: "Secure Passphrase", - mnemonic_sentence: mnemonic_sentence(15), + mnemonic_sentence: CW.utils.mnemonic_sentence(15), } wallet = WalletFactory.create(:shelley, payload) expect(wallet).to be_correct_and_respond 201 @@ -45,8 +45,8 @@ it "I can create, get and delete wallet from mnemonics / second factor" do payload = { name: "Wallet from mnemonic_sentence", passphrase: "Secure Passphrase", - mnemonic_sentence: mnemonic_sentence(15), - mnemonic_second_factor: mnemonic_sentence(12) + mnemonic_sentence: CW.utils.mnemonic_sentence(15), + mnemonic_second_factor: CW.utils.mnemonic_sentence(12) } wallet = WalletFactory.create(:shelley, payload) expect(wallet).to be_correct_and_respond 201 @@ -61,7 +61,7 @@ pool_gap = 55 payload = { name: "Wallet from mnemonic_sentence", passphrase: "Secure Passphrase", - mnemonic_sentence: mnemonic_sentence(15), + mnemonic_sentence: CW.utils.mnemonic_sentence(15), address_pool_gap: pool_gap } wallet = WalletFactory.create(:shelley, payload) @@ -87,7 +87,7 @@ describe "Wallet id" do it "I can get Shelley walletid using cardano-addresses" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) wid = create_shelley_wallet("Shelley Wallet", mnemonics) # based on root prv key @@ -102,7 +102,7 @@ end it "Shelley walletid is not based on acct key" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) wid = create_shelley_wallet("Shelley Wallet", mnemonics) # based on acct prv key @@ -151,7 +151,7 @@ it "Can update_passphrase, mnemonics" do w = SHELLEY.wallets - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) id = create_shelley_wallet('Wallet', mnemonics) upd = w.update_passphrase(id, { mnemonic_sentence: mnemonics, new_passphrase: "Securer Passphrase" }) @@ -160,8 +160,8 @@ it "Can update_passphrase, mnemonics, mnemonic_second_factor" do w = SHELLEY.wallets - mnemonics = mnemonic_sentence(24) - mnemonic_second_factor = mnemonic_sentence(12) + mnemonics = CW.utils.mnemonic_sentence(24) + mnemonic_second_factor = CW.utils.mnemonic_sentence(12) id = create_shelley_wallet('Wallet', mnemonics, mnemonic_second_factor) upd = w.update_passphrase(id, { mnemonic_sentence: mnemonics, mnemonic_second_factor: mnemonic_second_factor, @@ -171,8 +171,8 @@ it "Cannot update_passphrase with wrong mnemonics" do w = SHELLEY.wallets - mnemonics = mnemonic_sentence(24) - wrong_mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) + wrong_mnemonics = CW.utils.mnemonic_sentence(24) id = create_shelley_wallet('Wallet', mnemonics) upd = w.update_passphrase(id, { mnemonic_sentence: wrong_mnemonics, new_passphrase: "Securer Passphrase" }) @@ -182,9 +182,9 @@ it "Cannot update_passphrase with wrong mnemonic_second_factor" do w = SHELLEY.wallets - mnemonics = mnemonic_sentence(24) - mnemonic_second_factor = mnemonic_sentence(12) - wrong_mnemonic_second_factor = mnemonic_sentence(12) + mnemonics = CW.utils.mnemonic_sentence(24) + mnemonic_second_factor = CW.utils.mnemonic_sentence(12) + wrong_mnemonic_second_factor = CW.utils.mnemonic_sentence(12) id = create_shelley_wallet('Wallet', mnemonics, mnemonic_second_factor) upd = w.update_passphrase(id, { mnemonic_sentence: mnemonics, mnemonic_second_factor: wrong_mnemonic_second_factor, @@ -209,7 +209,7 @@ end it "Can update_passphrase of wallet from pub key using mnemonics from which pub key is derived" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shelley") acct_key = CA.key_child(root_xsk, "1852H/1815H/0H") pub_key = CA.key_public(acct_key, with_chain_code = true) @@ -237,7 +237,7 @@ end it "Cannot update_passphrase of wallet from pub key using wrong mnemonics" do - mnemonics = mnemonic_sentence(24) + mnemonics = CW.utils.mnemonic_sentence(24) root_xsk = CA.prv_key_from_recovery_phrase(mnemonics, "Shelley") acct_key = CA.key_child(root_xsk, "1852H/1815H/0H") pub_key = CA.key_public(acct_key, with_chain_code = true) @@ -251,7 +251,7 @@ expect(wallet).to be_correct_and_respond 201 wid = wallet['id'] - wrong_mnemonics = mnemonic_sentence(24) + wrong_mnemonics = CW.utils.mnemonic_sentence(24) upd = SHELLEY.wallets.update_passphrase(wid, { mnemonic_sentence: wrong_mnemonics, new_passphrase: "Securer Passphrase" }) expect(upd).to be_correct_and_respond 403 @@ -542,7 +542,7 @@ end it "Create account public key - extended" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) wid = create_shelley_wallet("Wallet", m24) ["0H", "1H", "2147483647H", "44H"].each do |index| payload = { passphrase: PASS, format: 'extended' } @@ -556,7 +556,7 @@ end it "Create account public key - non_extended" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) wid = create_shelley_wallet("Wallet", m24) ["0H", "1H", "2147483647H", "44H"].each do |index| payload = { passphrase: PASS, format: 'non_extended' } @@ -570,7 +570,7 @@ end it "Create account public key - extended with purpose" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) wid = create_shelley_wallet("Wallet", m24) ["0H", "1H", "2147483647H", "1854H"].each do |index_purpose| payload = { passphrase: PASS, format: 'extended', purpose: index_purpose } @@ -585,7 +585,7 @@ end it "Create account public key - non_extended with purpose" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) wid = create_shelley_wallet("Wallet", m24) ["0H", "1H", "2147483647H", "1854H"].each do |index_purpose| payload = { passphrase: PASS, format: 'non_extended', purpose: index_purpose } @@ -614,7 +614,7 @@ end it "Get account public key - wallet from mnemonics" do - m24 = mnemonic_sentence(24) + m24 = CW.utils.mnemonic_sentence(24) wid = create_shelley_wallet("Wallet", m24) # Get account pub key from the wallet @@ -630,8 +630,8 @@ end it "Get account public key (mnemonic_snd_factor)" do - m24 = mnemonic_sentence(24) - m12 = mnemonic_sentence(12) + m24 = CW.utils.mnemonic_sentence(24) + m12 = CW.utils.mnemonic_sentence(12) wid = create_shelley_wallet("Wallet", m24, m12) # Get account pub key from the wallet diff --git a/test/e2e/spec/spec_helper.rb b/test/e2e/spec/spec_helper.rb index a835e760eb4..610de51a647 100644 --- a/test/e2e/spec/spec_helper.rb +++ b/test/e2e/spec/spec_helper.rb @@ -204,7 +204,7 @@ def wait_for_all_shared_wallets(wids) end def create_shelley_wallet(name = "Wallet from mnemonic_sentence", - mnemonic_sentence = mnemonic_sentence(24), + mnemonic_sentence = CW.utils.mnemonic_sentence(24), mnemonic_second_factor = nil) payload = { name: name, passphrase: PASS, @@ -240,7 +240,7 @@ def wait_for_all_shelley_wallets(wids) def create_byron_wallet(style = "random", name = "Wallet from mnemonic_sentence", - mnemonics = mnemonic_sentence(24)) + mnemonics = CW.utils.mnemonic_sentence(24)) payload = { style: style, name: name, passphrase: PASS, From 8f5f1ea4f395760fe326906cd64255a257a52d7a Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 3 Oct 2022 11:10:35 +0200 Subject: [PATCH 6/7] remove minimum_utxo_value assertion --- test/e2e/spec/misc_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/spec/misc_spec.rb b/test/e2e/spec/misc_spec.rb index 8023cd8db2a..bedf4703926 100644 --- a/test/e2e/spec/misc_spec.rb +++ b/test/e2e/spec/misc_spec.rb @@ -39,7 +39,6 @@ "minimum_collateral_percentage", "active_slot_coefficient", "security_parameter", - "minimum_utxo_value", "maximum_collateral_input_count"] res = NETWORK.parameters expect(res).to be_correct_and_respond 200 From 835bc802409cd5c4ad7ea93fa1a6614983bdb654 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 3 Oct 2022 13:02:34 +0200 Subject: [PATCH 7/7] update CLISpec golden test for key from-recovery-phrase --- .../CLISpec/key from-recovery-phrase --help | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/wallet/test/data/Cardano/CLISpec/key from-recovery-phrase --help b/lib/wallet/test/data/Cardano/CLISpec/key from-recovery-phrase --help index 2809e328073..2b7dbd531be 100644 --- a/lib/wallet/test/data/Cardano/CLISpec/key from-recovery-phrase --help +++ b/lib/wallet/test/data/Cardano/CLISpec/key from-recovery-phrase --help @@ -1,13 +1,51 @@ -Usage: key from-recovery-phrase STYLE +Usage: key from-recovery-phrase STYLE [--passphrase FORMAT] + [--sensitive | --silent] + [--from-file FILE] Convert a recovery phrase to an extended private key Available options: -h,--help Show this help text STYLE Byron | Icarus | Shelley | Shared + --passphrase FORMAT (from-mnemonic | from-hex | + from-base64 | from-utf8 | from-octets) + User chosen passphrase to be read from + stdin for the generation phase. Valid + for Icarus, Shelley and Shared styles. + Accepting mnemonic (9- or 12 words) or + arbitrary passphrase encoded as + base16, base64, plain utf8 or raw + bytes in the form of octet array. + --sensitive Input is shown as * in interactive + mode. + --silent Input is not shown in interactive + mode. + --from-file FILE Passphrase from specified filepath. -The recovery phrase is read from stdin. +The recovery phrase without passphrase is read from stdin. Example: $ cardano-wallet recovery-phrase generate \ | cardano-wallet key from-recovery-phrase Icarus + +The recovery phrase with passphrase can be entered interactively or from file. +In both cases passhrase can take form of mnemonic, base16, base64, utf8 or octet array. +In interactive case one can select explicit, sensitive or silent mode. + +Example: + $ cardano-wallet key from-recovery-phrase Shelley --passphrase from-mnemonic --sensitive + Please enter a [9, 12, 15, 18, 21, 24] word mnemonic: + ********************************************************************************************************** + Please enter a 9–12 word second factor: + ************************************************************* + +In case of passphrase reading from file the recovery phrase is read from stdin. + +Example: + $ echo "Secret Secondary Phrase" > sndfactor.prv + $ cardano-wallet recovery-phrase generate \ + | cardano-wallet key from-recovery-phrase Shelley --from-file "./sndfactor.prv" + + $ cardano-wallet recovery-phrase generate --size 12 > sndfactor.prv + $ cardano-wallet recovery-phrase generate \ + | cardano-wallet key from-recovery-phrase Shelley --passphrase from-mnemonic --from-file "./sndfactor.prv"