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
4752e207
Commit
4752e207
authored
3 months ago
by
Nicolas80
Browse files
Options
Downloads
Patches
Plain Diff
Renamed vault_account CryptoType enum values and encrypted_private_key field into encrypted_suri
parent
4eafec2a
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
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/commands/vault.rs
+13
-13
13 additions, 13 deletions
src/commands/vault.rs
src/entities/vault_account.rs
+10
-10
10 additions, 10 deletions
src/entities/vault_account.rs
with
23 additions
and
23 deletions
src/commands/vault.rs
+
13
−
13
View file @
4752e207
...
@@ -274,7 +274,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
...
@@ -274,7 +274,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
root_derivation
.address
root_derivation
.address
)))
?
;
)))
?
;
if
vault_account
.crypto_type
==
CryptoType
::
Ed25519
Seed
{
if
vault_account
.crypto_type
==
CryptoType
::
G1v1
Seed
{
println!
(
println!
(
"Only
\"
{}
\"
and
\"
{}
\"
format are supported for derivations"
,
"Only
\"
{}
\"
and
\"
{}
\"
format are supported for derivations"
,
Into
::
<&
str
>
::
into
(
SecretFormat
::
Substrate
),
Into
::
<&
str
>
::
into
(
SecretFormat
::
Substrate
),
...
@@ -487,10 +487,10 @@ fn parse_prefix_and_derivation_path_from_string(
...
@@ -487,10 +487,10 @@ fn parse_prefix_and_derivation_path_from_string(
fn
map_secret_format_to_crypto_type
(
secret_format
:
SecretFormat
)
->
CryptoType
{
fn
map_secret_format_to_crypto_type
(
secret_format
:
SecretFormat
)
->
CryptoType
{
match
secret_format
{
match
secret_format
{
SecretFormat
::
Seed
=>
vault_account
::
CryptoType
::
Sr25519
Seed
,
SecretFormat
::
Seed
=>
vault_account
::
CryptoType
::
EntropyKdf
Seed
,
SecretFormat
::
Substrate
=>
vault_account
::
CryptoType
::
Sr2551
9Mnemonic
,
SecretFormat
::
Substrate
=>
vault_account
::
CryptoType
::
Bip3
9Mnemonic
,
SecretFormat
::
Predefined
=>
vault_account
::
CryptoType
::
Sr2551
9Mnemonic
,
SecretFormat
::
Predefined
=>
vault_account
::
CryptoType
::
Bip3
9Mnemonic
,
SecretFormat
::
Cesium
=>
vault_account
::
CryptoType
::
Ed25519
Seed
,
SecretFormat
::
Cesium
=>
vault_account
::
CryptoType
::
G1v1
Seed
,
}
}
}
}
...
@@ -565,9 +565,9 @@ where
...
@@ -565,9 +565,9 @@ where
)))
?
;
)))
?
;
current_vault_format
=
match
vault_account
.crypto_type
{
current_vault_format
=
match
vault_account
.crypto_type
{
CryptoType
::
Sr2551
9Mnemonic
=>
Some
(
SecretFormat
::
Substrate
.into
()),
CryptoType
::
Bip3
9Mnemonic
=>
Some
(
SecretFormat
::
Substrate
.into
()),
CryptoType
::
Sr25519
Seed
=>
Some
(
SecretFormat
::
Seed
.into
()),
CryptoType
::
EntropyKdf
Seed
=>
Some
(
SecretFormat
::
Seed
.into
()),
CryptoType
::
Ed25519
Seed
=>
Some
(
SecretFormat
::
Cesium
.into
()),
CryptoType
::
G1v1
Seed
=>
Some
(
SecretFormat
::
Cesium
.into
()),
};
};
}
}
...
@@ -752,14 +752,14 @@ where
...
@@ -752,14 +752,14 @@ where
)));
)));
}
}
let
encrypted_
private_key
=
let
encrypted_
suri
=
encrypt
(
root_secret_suri
.as_bytes
(),
password
.to_string
())
.map_err
(|
e
|
anyhow!
(
e
))
?
;
encrypt
(
root_secret_suri
.as_bytes
(),
password
.to_string
())
.map_err
(|
e
|
anyhow!
(
e
))
?
;
let
_root_account
=
vault_account
::
create_vault_account
(
let
_root_account
=
vault_account
::
create_vault_account
(
db
,
db
,
&
root_address
,
&
root_address
,
map_secret_format_to_crypto_type
(
secret_format
),
map_secret_format_to_crypto_type
(
secret_format
),
encrypted_
private_key
,
encrypted_
suri
,
)
)
.await
?
;
.await
?
;
...
@@ -914,7 +914,7 @@ pub fn retrieve_suri_from_vault_account(
...
@@ -914,7 +914,7 @@ pub fn retrieve_suri_from_vault_account(
)
->
Result
<
String
,
GcliError
>
{
)
->
Result
<
String
,
GcliError
>
{
let
password
=
inputs
::
prompt_password
()
?
;
let
password
=
inputs
::
prompt_password
()
?
;
let
cypher
=
&
vault_account
.encrypted_
private_key
;
let
cypher
=
&
vault_account
.encrypted_
suri
;
let
secret_vec
=
let
secret_vec
=
decrypt
(
cypher
,
password
.clone
())
.map_err
(|
e
|
GcliError
::
Input
(
e
.to_string
()))
?
;
decrypt
(
cypher
,
password
.clone
())
.map_err
(|
e
|
GcliError
::
Input
(
e
.to_string
()))
?
;
let
secret_suri
=
String
::
from_utf8
(
secret_vec
)
.map_err
(|
e
|
anyhow!
(
e
))
?
;
let
secret_suri
=
String
::
from_utf8
(
secret_vec
)
.map_err
(|
e
|
anyhow!
(
e
))
?
;
...
@@ -924,10 +924,10 @@ pub fn retrieve_suri_from_vault_account(
...
@@ -924,10 +924,10 @@ pub fn retrieve_suri_from_vault_account(
pub
fn
compute_keypair
(
crypto_type
:
CryptoType
,
secret_suri
:
&
str
)
->
Result
<
KeyPair
,
GcliError
>
{
pub
fn
compute_keypair
(
crypto_type
:
CryptoType
,
secret_suri
:
&
str
)
->
Result
<
KeyPair
,
GcliError
>
{
let
key_pair
=
match
crypto_type
{
let
key_pair
=
match
crypto_type
{
CryptoType
::
Sr2551
9Mnemonic
|
CryptoType
::
Sr25519
Seed
=>
{
CryptoType
::
Bip3
9Mnemonic
|
CryptoType
::
EntropyKdf
Seed
=>
{
pair_from_sr25519_str
(
secret_suri
)
?
.into
()
pair_from_sr25519_str
(
secret_suri
)
?
.into
()
}
}
CryptoType
::
Ed25519
Seed
=>
pair_from_ed25519_str
(
secret_suri
)
?
.into
(),
CryptoType
::
G1v1
Seed
=>
pair_from_ed25519_str
(
secret_suri
)
?
.into
(),
};
};
Ok
(
key_pair
)
Ok
(
key_pair
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/entities/vault_account.rs
+
10
−
10
View file @
4752e207
...
@@ -17,7 +17,7 @@ pub struct Model {
...
@@ -17,7 +17,7 @@ pub struct Model {
#[sea_orm(primary_key,
auto_increment
=
false
)]
#[sea_orm(primary_key,
auto_increment
=
false
)]
pub
address
:
String
,
pub
address
:
String
,
pub
crypto_type
:
CryptoType
,
pub
crypto_type
:
CryptoType
,
pub
encrypted_
private_key
:
Vec
<
u8
>
,
pub
encrypted_
suri
:
Vec
<
u8
>
,
}
}
impl
Display
for
Model
{
impl
Display
for
Model
{
...
@@ -33,12 +33,12 @@ impl Display for Model {
...
@@ -33,12 +33,12 @@ impl Display for Model {
rename_all
=
"PascalCase"
rename_all
=
"PascalCase"
)]
)]
pub
enum
CryptoType
{
pub
enum
CryptoType
{
/// The
secret key or
BIP39 mnemonic
/// The BIP39 mnemonic
phrase (?12 words) (SR25519)
Sr2551
9Mnemonic
,
Bip3
9Mnemonic
,
/// The 32B
SR25519
seed with
out
"0x" prefix
/// The 32B
hexadecimal
seed with "0x" prefix
(64+2 characters when unencrypted) (SR25519)
Sr25519
Seed
,
EntropyKdf
Seed
,
/// The 32B
ED25519
seed with
out
"0x" prefix
(
for cesium)
/// The 32B
hexadecimal
seed with "0x" prefix for cesium
v1 (64+2 characters when unencrypted) (ED25519
)
Ed25519
Seed
,
G1v1
Seed
,
}
}
#[derive(Copy,
Clone,
Debug,
EnumIter)]
#[derive(Copy,
Clone,
Debug,
EnumIter)]
...
@@ -68,7 +68,7 @@ pub async fn create_vault_account<C>(
...
@@ -68,7 +68,7 @@ pub async fn create_vault_account<C>(
db
:
&
C
,
db
:
&
C
,
address
:
&
str
,
address
:
&
str
,
crypto_type
:
CryptoType
,
crypto_type
:
CryptoType
,
encrypted_
private_key
:
Vec
<
u8
>
,
encrypted_
suri
:
Vec
<
u8
>
,
)
->
Result
<
Model
,
GcliError
>
)
->
Result
<
Model
,
GcliError
>
where
where
C
:
ConnectionTrait
,
C
:
ConnectionTrait
,
...
@@ -83,7 +83,7 @@ where
...
@@ -83,7 +83,7 @@ where
inputs
::
confirm_action
(
"Do you want to overwrite with the new encrypted key ?"
)
?
;
inputs
::
confirm_action
(
"Do you want to overwrite with the new encrypted key ?"
)
?
;
if
overwrite_key
{
if
overwrite_key
{
let
mut
vault_account
:
ActiveModel
=
vault_account
.into
();
let
mut
vault_account
:
ActiveModel
=
vault_account
.into
();
vault_account
.encrypted_
private_key
=
Set
(
encrypted_
private_key
);
vault_account
.encrypted_
suri
=
Set
(
encrypted_
suri
);
let
vault_account
=
vault_account
.update
(
db
)
.await
?
;
let
vault_account
=
vault_account
.update
(
db
)
.await
?
;
println!
(
"Updated vault account {vault_account}"
);
println!
(
"Updated vault account {vault_account}"
);
...
@@ -96,7 +96,7 @@ where
...
@@ -96,7 +96,7 @@ where
let
vault_account
=
ActiveModel
{
let
vault_account
=
ActiveModel
{
address
:
Set
(
address
.to_owned
()),
address
:
Set
(
address
.to_owned
()),
crypto_type
:
Set
(
crypto_type
),
crypto_type
:
Set
(
crypto_type
),
encrypted_
private_key
:
Set
(
encrypted_
private_key
),
encrypted_
suri
:
Set
(
encrypted_
suri
),
};
};
let
vault_account
=
vault_account
.insert
(
db
)
.await
?
;
let
vault_account
=
vault_account
.insert
(
db
)
.await
?
;
println!
(
"Created vault account {}"
,
vault_account
);
println!
(
"Created vault account {}"
,
vault_account
);
...
...
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