Skip to content

Commit

Permalink
Merge #3521
Browse files Browse the repository at this point in the history
3521: Update cardano-addresses and test mnemonic_snd_factor r=piotr-iohk a=piotr-iohk

- [x] update cardano-addresses (101921f) 
- [x] Test cardano-wallet mnemonic_snd_factor parity with cardano-addresses (84ade7a) 
- [x] More strict assertions in Key tests (997dfab) 
- [x] update test deps (5cf1d99) 
- [x] Remove bip_mnemonic dependency (58978da) 

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number

ADP-2143


Co-authored-by: Piotr Stachyra <[email protected]>
  • Loading branch information
iohk-bors[bot] and Piotr Stachyra authored Oct 4, 2022
2 parents 3d722b2 + 835bc80 commit e550f38
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 136 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 1 addition & 2 deletions test/e2e/Gemfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 20 additions & 20 deletions test/e2e/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "
Expand Down
46 changes: 38 additions & 8 deletions test/e2e/gemset.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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"];
Expand All @@ -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 = [];
Expand Down Expand Up @@ -136,4 +166,4 @@
};
version = "3.10.2";
};
}
}
5 changes: 2 additions & 3 deletions test/e2e/helpers/cardano_addresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 1 addition & 22 deletions test/e2e/helpers/utils.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'bip_mnemonic'
require 'httparty'
require 'fileutils'

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/spec/byron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/spec/lightmode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/e2e/spec/misc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e550f38

Please sign in to comment.