Skip to content

Draft: Added support for the different SecretFormat within the Vault

  • Adapted vault items filename to "{address}-{secret_format}" for new entries
  • Kept backward compatibility to still read "substrate" vault items from disk (without the SecretFormat in the filename)
  • Refactored methods in keys.rs and vault.rs to accommodate for the changes without duplicating code (i.e. for the secret prompts)
  • for "vault import" command, kept SecretFormat.Substrate as default so it's not mandatory to give the "-S" parameter

Performed manual tests using accounts:

  • 5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn
    • Identity: Nicolas80
    • Kept as "old" vault entry ~/.local/share/gcli/5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn
  • 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6-substrate
    • Identity: Nicolas80-GDev
  • 5GhAZBagx87sTGfMppfPPcWhxCKGWE8zDi1oHp7YiKosD9KZ-cesium
    • (old G1v1 for which I moved identity to 5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn)
  • 5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm-seed
    • New test account without Identity and created from seed only
  • 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
    • predefined Alice key

Saving the different key types in the vault

gcli vault list
available keys:
5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn


gcli vault import --help
Import key from (substrate)mnemonic or other format with interactive prompt

Usage: gcli vault import [OPTIONS]

Options:
  -S, --secret-format <SECRET_FORMAT>  Secret key format (substrate, seed, cesium) [default: substrate]
  -h, --help                           Print help

# Using default "substrate" secret format
gcli vault import
Mnemonic: 
Enter password to protect the key
Password: 
Stored secret for 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6

gcli vault import -S cesium
Cesium id: 
Cesium password: 
Enter password to protect the key
Password: 
Stored secret for 5GhAZBagx87sTGfMppfPPcWhxCKGWE8zDi1oHp7YiKosD9KZ

gcli vault import -S seed  
Seed: 
Enter password to protect the key
Password: 
Stored secret for 5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm

# Just for reference, also work for predefined key - but probably not useful
# Using "Alice" as derivation here
gcli vault import -S predefined
Enter derivation path: 
Enter password to protect the key
Password: 
Stored secret for 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

gcli vault list
available keys:
5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn
5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm-seed
5GhAZBagx87sTGfMppfPPcWhxCKGWE8zDi1oHp7YiKosD9KZ-cesium
5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6-substrate
5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY-predefined

Using the different vaults for transfers

# Using -a to select the source address for all commands
gcli -a 5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn account transfer 101 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6
Enter password to unlock account 5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn
Password: 
transaction submitted to the network, waiting 6 seconds...
transfered 1.01 ĞD (5Funkng8dL397H9ZEJ9sXDjFhStCqRYUj1a62ngcrEMy7ivn → 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6)

gcli -a 5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm account transfer 101 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6
Enter password to unlock account 5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm
Password: 
transaction submitted to the network, waiting 6 seconds...
transfered 1.01 ĞD (5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm → 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6)

gcli -a 5GhAZBagx87sTGfMppfPPcWhxCKGWE8zDi1oHp7YiKosD9KZ account transfer 101 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6
Enter password to unlock account 5GhAZBagx87sTGfMppfPPcWhxCKGWE8zDi1oHp7YiKosD9KZ
Password: 
transaction submitted to the network, waiting 6 seconds...
transfered 1.01 ĞD (5GhAZBagx87sTGfMppfPPcWhxCKGWE8zDi1oHp7YiKosD9KZ → 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6)

gcli -a 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6 account transfer 101 5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm
Enter password to unlock account 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6
Password: 
transaction submitted to the network, waiting 6 seconds...
transfered 1.01 ĞD (5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6 → 5GNadia4kktgt3Zg3QgTKL8Lse78XXMcisnRhkPKA4ombYDm)

# Using the address of the predefined key actually doesn't request the password (it's not even searching in the vault)
gcli -a 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY account transfer 101 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6
transaction submitted to the network, waiting 6 seconds...
transfered 1.01 ĞD (5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY → 5HE6gH87fVuGj6akXneNceBtgEiaUZua43TJbVBRQTT77gp6)

I'm still new to rust, so don't hesitate to give suggestions 😊

Edited by Nicolas80

Merge request reports