Client: don't try to generate vanity keys with wrong first letter
This commit is contained in:
parent
7e4a0f3368
commit
89c018f31b
@ -38,15 +38,36 @@ let gen_keys_containing
|
|||||||
~containing ~name (cctxt : #Client_context.io_wallet) =
|
~containing ~name (cctxt : #Client_context.io_wallet) =
|
||||||
let unrepresentable =
|
let unrepresentable =
|
||||||
List.filter (fun s -> not @@ Base58.Alphabet.all_in_alphabet Base58.Alphabet.bitcoin s) containing in
|
List.filter (fun s -> not @@ Base58.Alphabet.all_in_alphabet Base58.Alphabet.bitcoin s) containing in
|
||||||
|
let good_initial_char = "KLMNPQRSTUVWXYZabcdefghi" in
|
||||||
|
let bad_initial_char = "123456789ABCDEFGHJjkmnopqrstuvwxyz" in
|
||||||
match unrepresentable with
|
match unrepresentable with
|
||||||
| _ :: _ ->
|
| _ :: _ ->
|
||||||
cctxt#warning
|
cctxt#error
|
||||||
"The following can't be written in the key alphabet (%a): %a"
|
"@[<v 0>The following words can't be written in the key alphabet: %a.@,\
|
||||||
Base58.Alphabet.pp Base58.Alphabet.bitcoin
|
Valid characters: %a@,\
|
||||||
|
Extra restriction for the first character: %s@]"
|
||||||
(Format.pp_print_list
|
(Format.pp_print_list
|
||||||
~pp_sep:(fun ppf () -> Format.fprintf ppf ", ")
|
~pp_sep:(fun ppf () -> Format.fprintf ppf ", ")
|
||||||
(fun ppf s -> Format.fprintf ppf "'%s'" s))
|
(fun ppf s -> Format.fprintf ppf "'%s'" s))
|
||||||
unrepresentable >>= return
|
unrepresentable
|
||||||
|
Base58.Alphabet.pp Base58.Alphabet.bitcoin
|
||||||
|
good_initial_char
|
||||||
|
| [] ->
|
||||||
|
let unrepresentable =
|
||||||
|
List.filter (fun s -> prefix &&
|
||||||
|
String.contains bad_initial_char s.[0]) containing in
|
||||||
|
match unrepresentable with
|
||||||
|
| _ :: _ ->
|
||||||
|
cctxt#error
|
||||||
|
"@[<v 0>The following words don't respect the first character restriction: %a.@,\
|
||||||
|
Valid characters: %a@,\
|
||||||
|
Extra restriction for the first character: %s@]"
|
||||||
|
(Format.pp_print_list
|
||||||
|
~pp_sep:(fun ppf () -> Format.fprintf ppf ", ")
|
||||||
|
(fun ppf s -> Format.fprintf ppf "'%s'" s))
|
||||||
|
unrepresentable
|
||||||
|
Base58.Alphabet.pp Base58.Alphabet.bitcoin
|
||||||
|
good_initial_char
|
||||||
| [] ->
|
| [] ->
|
||||||
Public_key_hash.mem cctxt name >>=? fun name_exists ->
|
Public_key_hash.mem cctxt name >>=? fun name_exists ->
|
||||||
if name_exists && not force
|
if name_exists && not force
|
||||||
@ -86,7 +107,8 @@ let gen_keys_containing
|
|||||||
(public_key_hash, pk_uri, sk_uri) name >>=? fun () ->
|
(public_key_hash, pk_uri, sk_uri) name >>=? fun () ->
|
||||||
return hash
|
return hash
|
||||||
else begin if attempts mod 25_000 = 0
|
else begin if attempts mod 25_000 = 0
|
||||||
then cctxt#message "Tried %d keys without finding a match" attempts
|
then
|
||||||
|
cctxt#message "Tried %d keys without finding a match" attempts
|
||||||
else Lwt.return () end >>= fun () ->
|
else Lwt.return () end >>= fun () ->
|
||||||
loop (attempts + 1) in
|
loop (attempts + 1) in
|
||||||
loop 1 >>=? fun key_hash ->
|
loop 1 >>=? fun key_hash ->
|
||||||
|
Loading…
Reference in New Issue
Block a user