proof of work start
This commit is contained in:
parent
ba014261dc
commit
0398a66423
@ -15,6 +15,7 @@ type secret_key = Sodium.Box.secret_key
|
|||||||
type public_key = Sodium.Box.public_key
|
type public_key = Sodium.Box.public_key
|
||||||
type channel_key = Sodium.Box.channel_key
|
type channel_key = Sodium.Box.channel_key
|
||||||
type nonce = Sodium.Box.nonce
|
type nonce = Sodium.Box.nonce
|
||||||
|
type difficulty = int
|
||||||
|
|
||||||
let random_keypair = Sodium.Box.random_keypair
|
let random_keypair = Sodium.Box.random_keypair
|
||||||
let random_nonce = Sodium.Box.random_nonce
|
let random_nonce = Sodium.Box.random_nonce
|
||||||
@ -24,6 +25,13 @@ let box_open sk pk msg nonce =
|
|||||||
try Some (Sodium.Box.Bigbytes.box_open sk pk msg nonce) with
|
try Some (Sodium.Box.Bigbytes.box_open sk pk msg nonce) with
|
||||||
| Sodium.Verification_failure -> None
|
| Sodium.Verification_failure -> None
|
||||||
|
|
||||||
|
let check_proof_of_work pk nonce difficulty = assert false
|
||||||
|
let generate_proof_of_work pk difficulty =
|
||||||
|
let rec loop nonce =
|
||||||
|
if check_proof_of_work pk nonce difficulty then nonce
|
||||||
|
else loop (increment_nonce nonce) in
|
||||||
|
loop (random_nonce ())
|
||||||
|
|
||||||
let public_key_encoding =
|
let public_key_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
conv
|
conv
|
||||||
@ -44,4 +52,3 @@ let nonce_encoding =
|
|||||||
Sodium.Box.Bigbytes.of_nonce
|
Sodium.Box.Bigbytes.of_nonce
|
||||||
Sodium.Box.Bigbytes.to_nonce
|
Sodium.Box.Bigbytes.to_nonce
|
||||||
(Fixed.bytes Sodium.Box.nonce_size)
|
(Fixed.bytes Sodium.Box.nonce_size)
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
(** Tezos - X25519/XSalsa20-Poly1305 cryptography *)
|
(** Tezos - X25519/XSalsa20-Poly1305 cryptography *)
|
||||||
|
|
||||||
type nonce
|
type nonce
|
||||||
|
type difficulty
|
||||||
|
|
||||||
val random_nonce : unit -> nonce
|
val random_nonce : unit -> nonce
|
||||||
val increment_nonce : ?step:int -> nonce -> nonce
|
val increment_nonce : ?step:int -> nonce -> nonce
|
||||||
@ -28,3 +29,5 @@ val box : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
|
|||||||
|
|
||||||
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t option
|
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t option
|
||||||
|
|
||||||
|
val check_proof_of_work : public_key -> nonce -> difficulty -> bool
|
||||||
|
val generate_proof_of_work : public_key -> difficulty -> nonce
|
||||||
|
Loading…
Reference in New Issue
Block a user