Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğ
Ğcli-v2s
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
Rust
Ğcli-v2s
Commits
da66773d
Commit
da66773d
authored
3 months ago
by
Nicolas80
Browse files
Options
Downloads
Patches
Plain Diff
* Small refactorings & rewordings
parent
90f5f2aa
No related branches found
No related tags found
1 merge request
!41
Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/commands/vault.rs
+23
-28
23 additions, 28 deletions
src/commands/vault.rs
src/entities/vault_account.rs
+2
-2
2 additions, 2 deletions
src/entities/vault_account.rs
src/keys.rs
+17
-6
17 additions, 6 deletions
src/keys.rs
with
42 additions
and
36 deletions
src/commands/vault.rs
+
23
−
28
View file @
da66773d
...
...
@@ -177,7 +177,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
let
table
=
compute_vault_key_files_table
(
&
vault_key_addresses
)
.await
?
;
println!
(
"available key files (needs to be migrated with command
\"
vault migrate
\"
in order to use them):"
);
println!
(
"available key files (needs to be migrated with command
`
vault migrate
`
in order to use them):"
);
println!
(
"{table}"
);
}
Subcommand
::
Use
{
...
...
@@ -190,7 +190,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
data
.cfg.address
=
Some
(
AccountId
::
from_str
(
&
derivation
.address
)
.expect
(
"invalid address"
));
println!
(
"Using
key
{}"
,
derivation
);
println!
(
"Using
:
{}"
,
derivation
);
conf
::
save_config
(
&
data
);
}
Subcommand
::
Generate
=>
{
...
...
@@ -213,8 +213,8 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
.await
?
{
println!
(
"Vault entry already exists for address:
'
{}
'
"
,
vault_data_for_import
.address
"Vault entry already exists for
that
address:
{}"
,
derivation
);
let
linked_derivations
=
vault_derivation
::
fetch_all_linked_derivations_in_order
(
...
...
@@ -222,7 +222,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
&
derivation
.root_address
.clone
(),
)
.await
?
;
println!
(
"Here are all the
linked derivations already presen
t in the vault:"
);
println!
(
"Here are all the
SS58 Addresses linked to i
t in the vault:"
);
let
table
=
compute_vault_derivations_table
(
data
.connection
.as_ref
()
.unwrap
(),
...
...
@@ -260,12 +260,12 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
let
root_derivation
=
retrieve_vault_derivation
(
&
data
,
address_or_vault_name
)
.await
?
;
if
root_derivation
.path
.is_some
()
{
println!
(
"Can only add derivation on a
ROOT key.
"
);
println!
(
"Can only add derivation on a
n <Account>
"
);
println!
(
"The selected
key with
address:'{}' already has a
ROOT
with address:'{}'"
,
"The selected address:'{}' already has a
n <Account>
with address:'{}'"
,
root_derivation
.address
,
root_derivation
.root_address
);
println!
(
"You can check for available
ROOT key
s with command 'vault list
roo
t'"
);
println!
(
"You can check for available
<Account> addresse
s with command 'vault list
accoun
t'"
);
return
Ok
(());
}
...
...
@@ -273,7 +273,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
.one
(
data
.connection
.as_ref
()
.unwrap
())
.await
?
.ok_or
(
GcliError
::
Input
(
format!
(
"Could not find
(root)
vault
account for address:'{}'"
,
"Could not find vault
_
account for address:'{}'"
,
root_derivation
.address
)))
?
;
...
...
@@ -283,13 +283,15 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
Into
::
<&
str
>
::
into
(
SecretFormat
::
Substrate
),
Into
::
<&
str
>
::
into
(
SecretFormat
::
Seed
)
);
println!
(
"Use command `vault list root` to see available <Account> and their format"
);
println!
(
"Use command `vault list account` to see available <Account> and their format"
);
return
Ok
(());
}
println!
(
"Adding derivation to
root key
: {root_derivation}"
);
println!
(
"Adding derivation to: {root_derivation}"
);
println!
(
"Enter password to decrypt the
root
key"
);
println!
(
"Enter password to decrypt the
<Account>
key"
);
let
root_secret_suri
=
retrieve_suri_from_vault_account
(
&
vault_account
)
?
;
...
...
@@ -321,7 +323,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
root_address
:
Set
(
root_derivation
.root_address
.clone
()),
};
let
derivation
=
derivation
.insert
(
data
.connection
.as_ref
()
.unwrap
())
.await
?
;
println!
(
"Created
derivation
{}"
,
derivation
);
println!
(
"Created
:
{}"
,
derivation
);
}
Subcommand
::
Rename
{
address
}
=>
{
let
derivation
=
vault_derivation
::
Entity
::
find_by_id
(
address
.to_string
())
...
...
@@ -341,7 +343,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
derivation
.name
);
println!
(
"Enter new
vault
name for
the key
(leave empty to remove the name)"
);
println!
(
"Enter new name for
address
(leave empty to remove the name)"
);
let
name
=
inputs
::
prompt_vault_name
()
?
;
let
old_name
=
derivation
.name
.clone
();
...
...
@@ -373,16 +375,16 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
let
table
=
compute_vault_derivations_table
(
&
txn
,
&
all_derivations_to_delete
)
.await
?
;
println!
(
"All
derivation
s linked to
the root
derivation
:
"
);
println!
(
"All
addresse
s linked to
: {
derivation
}
"
);
println!
(
"{table}"
);
println!
(
"This
root derivation has {} derivation
s in total"
,
"This
<Account> has {} addresse
s in total"
,
all_derivations_to_delete
.len
()
);
let
confirmed
=
inputs
::
confirm_action
(
"Are you sure you want to delete it along with the
vault account (and
saved key
)
?"
.to_string
()
)
?
;
"Are you sure you want to delete it along with the saved key
?"
.to_string
()
,
)
?
;
if
!
confirmed
{
return
Ok
(());
...
...
@@ -390,7 +392,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
for
derivation_to_delete
in
all_derivations_to_delete
{
let
delete_result
=
derivation_to_delete
.delete
(
&
txn
)
.await
?
;
println!
(
"Deleted {}
derivation
"
,
delete_result
.rows_affected
);
println!
(
"Deleted {}
address
"
,
delete_result
.rows_affected
);
}
let
delete_result
=
vault_account
::
Entity
::
delete_by_id
(
&
address_to_delete
)
...
...
@@ -399,7 +401,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
println!
(
"Deleted {} vault account"
,
delete_result
.rows_affected
);
}
else
{
let
delete_result
=
derivation
.delete
(
&
txn
)
.await
?
;
println!
(
"Deleted {}
derivation
"
,
delete_result
.rows_affected
);
println!
(
"Deleted {}
address
"
,
delete_result
.rows_affected
);
}
txn
.commit
()
.await
?
;
...
...
@@ -550,7 +552,7 @@ where
for
derivation
in
derivations_ordered
{
if
derivation
.root_address
!=
current_root_address
{
// First entry
should be a
root derivation
// First entry
when changing root address should be an account ("
root
"
derivation
)
if
derivation
.path
.is_some
()
{
return
Err
(
GcliError
::
Input
(
"Order of derivations parameter is wrong"
.to_string
(),
...
...
@@ -571,13 +573,6 @@ where
CryptoType
::
Sr25519Seed
=>
Some
(
SecretFormat
::
Seed
.into
()),
CryptoType
::
Ed25519Seed
=>
Some
(
SecretFormat
::
Cesium
.into
()),
};
}
else
{
// Validate that the RootAddress is the same as current_root_address
if
derivation
.root_address
!=
current_root_address
{
return
Err
(
GcliError
::
Input
(
"Order of derivations parameter is wrong"
.to_string
(),
));
}
}
let
address
=
if
derivation
.path
.is_none
()
{
...
...
This diff is collapsed.
Click to expand it.
src/entities/vault_account.rs
+
2
−
2
View file @
da66773d
...
...
@@ -77,7 +77,7 @@ where
Ok
(
match
vault_account
{
Some
(
vault_account
)
=>
{
println!
(
"Already existing
(root)
vault account {vault_account}"
);
println!
(
"Already existing vault account {vault_account}"
);
let
overwrite_key
=
inputs
::
confirm_action
(
"Do you want to overwrite with the new encrypted key ?"
)
?
;
...
...
@@ -85,7 +85,7 @@ where
let
mut
vault_account
:
ActiveModel
=
vault_account
.into
();
vault_account
.encrypted_private_key
=
Set
(
encrypted_private_key
);
let
vault_account
=
vault_account
.update
(
db
)
.await
?
;
println!
(
"Updated
(root)
vault account {vault_account}"
);
println!
(
"Updated vault account {vault_account}"
);
vault_account
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/keys.rs
+
17
−
6
View file @
da66773d
...
...
@@ -191,7 +191,7 @@ pub fn pair_from_cesium(id: String, pwd: String) -> nacl::sign::Keypair {
fn
seed_from_cesium
(
id
:
&
str
,
pwd
:
&
str
)
->
[
u8
;
32
]
{
let
params
=
scrypt
::
Params
::
new
(
12u8
,
16u32
,
1u32
,
32
)
.unwrap
();
let
mut
seed
=
[
0u8
;
32
];
scrypt
::
scrypt
(
&
pwd
.as_bytes
(),
&
id
.as_bytes
(),
&
params
,
&
mut
seed
)
.unwrap
();
scrypt
::
scrypt
(
pwd
.as_bytes
(),
id
.as_bytes
(),
&
params
,
&
mut
seed
)
.unwrap
();
seed
}
...
...
@@ -582,7 +582,8 @@ mod tests {
let
cesium_id
=
"test_cesium_id"
.to_string
();
let
cesium_pwd
=
"test_cesium_pwd"
.to_string
();
let
expected_cesium_v1_ss58_address
:
String
=
"5ET2jhgJFoNQUpgfdSkdwftK8DKWdqZ1FKm5GKWdPfMWhPr4"
.to_string
();
let
expected_cesium_v1_ss58_address
:
String
=
"5ET2jhgJFoNQUpgfdSkdwftK8DKWdqZ1FKm5GKWdPfMWhPr4"
.to_string
();
let
cesium_keypair
=
pair_from_cesium
(
cesium_id
,
cesium_pwd
);
...
...
@@ -597,7 +598,10 @@ mod tests {
let
cesium_v1_address
:
AccountId
=
cesium_keypair
.pkey
.into
();
println!
(
"SS58 Address: '{}'"
,
cesium_v1_address
);
assert_eq!
(
expected_cesium_v1_ss58_address
,
cesium_v1_address
.to_string
());
assert_eq!
(
expected_cesium_v1_ss58_address
,
cesium_v1_address
.to_string
()
);
//ed25519 seed **seems** to be the first 32 bytes of the secret key from nacl keypair
let
mut
seed
:
[
u8
;
32
]
=
[
0
;
32
];
...
...
@@ -692,7 +696,8 @@ mod tests {
let
cesium_id
=
"test_cesium_id"
.to_string
();
let
cesium_pwd
=
"test_cesium_pwd"
.to_string
();
let
expected_cesium_v1_ss58_address
:
String
=
"5ET2jhgJFoNQUpgfdSkdwftK8DKWdqZ1FKm5GKWdPfMWhPr4"
.to_string
();
let
expected_cesium_v1_ss58_address
:
String
=
"5ET2jhgJFoNQUpgfdSkdwftK8DKWdqZ1FKm5GKWdPfMWhPr4"
.to_string
();
// retrieving seed using scrypt
let
seed
=
seed_from_cesium
(
&
cesium_id
,
&
cesium_pwd
);
...
...
@@ -712,7 +717,10 @@ mod tests {
"ed25519 keypair from seed : public SS58 Address:'{}'"
,
ed25519_address_from_seed
);
assert_eq!
(
expected_cesium_v1_ss58_address
,
ed25519_address_from_seed
.to_string
());
assert_eq!
(
expected_cesium_v1_ss58_address
,
ed25519_address_from_seed
.to_string
()
);
let
root_suri
=
"0x"
.to_string
()
+
&
hex
::
encode
(
seed
);
let
ed25519_pair_from_suri
=
...
...
@@ -722,7 +730,10 @@ mod tests {
"ed25519 keypair from suri : public SS58 Address:'{}'"
,
ed25519_address_from_suri
);
assert_eq!
(
expected_cesium_v1_ss58_address
,
ed25519_address_from_suri
.to_string
());
assert_eq!
(
expected_cesium_v1_ss58_address
,
ed25519_address_from_suri
.to_string
()
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment