Alpha: use Base58 for displaying commitment
This commit is contained in:
parent
9ffead02d2
commit
4f2b2f8ece
@ -156,9 +156,6 @@ module type SIGNATURE = sig
|
|||||||
|
|
||||||
type t
|
type t
|
||||||
|
|
||||||
val hash_bytes: ?key:MBytes.t -> MBytes.t list -> t
|
|
||||||
val hash_string: ?key:string -> string list -> t
|
|
||||||
|
|
||||||
val pp: Format.formatter -> t -> unit
|
val pp: Format.formatter -> t -> unit
|
||||||
val pp_short: Format.formatter -> t -> unit
|
val pp_short: Format.formatter -> t -> unit
|
||||||
include Compare.S with type t := t
|
include Compare.S with type t := t
|
||||||
|
@ -209,9 +209,6 @@ module type SIGNATURE = sig
|
|||||||
|
|
||||||
type t
|
type t
|
||||||
|
|
||||||
val hash_bytes: ?key:MBytes.t -> MBytes.t list -> t
|
|
||||||
val hash_string: ?key:string -> string list -> t
|
|
||||||
|
|
||||||
val pp: Format.formatter -> t -> unit
|
val pp: Format.formatter -> t -> unit
|
||||||
val pp_short: Format.formatter -> t -> unit
|
val pp_short: Format.formatter -> t -> unit
|
||||||
include Compare.S with type t := t
|
include Compare.S with type t := t
|
||||||
|
@ -269,9 +269,6 @@ module Make (Context : CONTEXT) = struct
|
|||||||
|
|
||||||
type t
|
type t
|
||||||
|
|
||||||
val hash_bytes: ?key:MBytes.t -> MBytes.t list -> t
|
|
||||||
val hash_string: ?key:string -> string list -> t
|
|
||||||
|
|
||||||
val pp: Format.formatter -> t -> unit
|
val pp: Format.formatter -> t -> unit
|
||||||
val pp_short: Format.formatter -> t -> unit
|
val pp_short: Format.formatter -> t -> unit
|
||||||
include Compare.S with type t := t
|
include Compare.S with type t := t
|
||||||
|
@ -7,30 +7,24 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
type t = MBytes.t
|
include Blake2B.Make(Base58)(struct
|
||||||
|
let name = "Blinded public key hash"
|
||||||
|
let title = "A blinded public key hash"
|
||||||
|
let b58check_prefix = "\001\002\049\223"
|
||||||
|
let size = Some Ed25519.Public_key_hash.size
|
||||||
|
end)
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Base58.check_encoded_prefix b58check_encoding "btz1" 37
|
||||||
|
|
||||||
|
let of_ed25519_pkh secret pkh =
|
||||||
|
hash_bytes ~key:secret [ Ed25519.Public_key_hash.to_bytes pkh ]
|
||||||
|
|
||||||
type secret = MBytes.t
|
type secret = MBytes.t
|
||||||
|
|
||||||
let size = Ed25519.Public_key_hash.size
|
|
||||||
let secret_size = Ed25519.Public_key_hash.size
|
let secret_size = Ed25519.Public_key_hash.size
|
||||||
|
|
||||||
let encoding = Data_encoding.Fixed.bytes size
|
|
||||||
let secret_encoding = Data_encoding.Fixed.bytes secret_size
|
let secret_encoding = Data_encoding.Fixed.bytes secret_size
|
||||||
|
|
||||||
let of_ed25519_pkh secret pkh =
|
|
||||||
Ed25519.Public_key_hash.to_bytes @@
|
|
||||||
Ed25519.Public_key_hash.hash_bytes
|
|
||||||
~key:secret
|
|
||||||
[ Ed25519.Public_key_hash.to_bytes pkh ]
|
|
||||||
|
|
||||||
let compare = MBytes.compare
|
|
||||||
let (=) = MBytes.(=)
|
|
||||||
|
|
||||||
let of_hex h =
|
|
||||||
if Compare.Int.(String.length h <> size * 2) then
|
|
||||||
invalid_arg "Blinded_public_key_hash.of_hex" ;
|
|
||||||
MBytes.of_hex (`Hex h)
|
|
||||||
|
|
||||||
let secret_of_hex h =
|
let secret_of_hex h =
|
||||||
if Compare.Int.(String.length h <> secret_size * 2) then
|
if Compare.Int.(String.length h <> secret_size * 2) then
|
||||||
invalid_arg "Blinded_public_key_hash.secret_of_hex" ;
|
invalid_arg "Blinded_public_key_hash.secret_of_hex" ;
|
||||||
|
@ -7,16 +7,11 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
type t
|
include S.HASH
|
||||||
val encoding : t Data_encoding.t
|
|
||||||
|
|
||||||
type secret
|
type secret
|
||||||
val secret_encoding : secret Data_encoding.t
|
val secret_encoding : secret Data_encoding.t
|
||||||
|
|
||||||
val of_ed25519_pkh : secret -> Ed25519.Public_key_hash.t -> t
|
val of_ed25519_pkh : secret -> Ed25519.Public_key_hash.t -> t
|
||||||
|
|
||||||
val of_hex : string -> t
|
|
||||||
val secret_of_hex : string -> secret
|
val secret_of_hex : string -> secret
|
||||||
|
|
||||||
val compare : t -> t -> int
|
|
||||||
val (=) : t -> t -> bool
|
|
||||||
|
@ -10,22 +10,22 @@
|
|||||||
open Commitment_repr
|
open Commitment_repr
|
||||||
|
|
||||||
let test_commitments = [
|
let test_commitments = [
|
||||||
"dca88243fece75e9c22e", "4a6af2f5c466bf0a7a1001a1e9468cbfca82cef6", 1868898542104130027;
|
"tz1fkmDXEQdua3u71JBVh4eGUGqK4t1G8xhZ", "btz1T77Ly5U1bWNBR5KzDSgNFST5Bh5F1eB6g", 1868898542104130027L ;
|
||||||
"c736bfb7074f69bee133", "32d7b02afc218623b4e2fd85b84b06f0a1d202d2", 517697389496079974;
|
"tz1doNkK6RKaRswsuKJV4erT6HauYSm9fuHi", "btz1QxTPgszARgWioEor3eMehxW3osfhw3KoJ", 517697389496079974L ;
|
||||||
"e07bb6ba71082141eae0", "17a0241048b13857abe19db7fa11ac63de3eda5e", 962290491831710023;
|
"tz1g6zFsci4YR8p1MJrkyc6wAKizR6mqJmyQ", "btz1NUYc1tV5VBksMNuQG4AuZF9Xudh1sDJni", 962290491831710023L ;
|
||||||
"17efe5e32c28126c4e94", "7484c711d0cbd8ba6e7f9965311a4903ea17b80a", 1233665184704419921;
|
"tz1MpbcwGFWVBBWoxwm6iQH5Hzh9mCXbnETJ", "btz1Wwifd8vbQqnbuzSbQLvJEjQ9FUoxVJm68", 1233665184704419921L ;
|
||||||
"5c742b7e335b265cfa82", "3ca39ae8ddd026030af633561382d4e16c8c2cae", 131959324067470008;
|
"tz1U4t2PmX5cZVUui4BNaiRVokLa6AxB5G9Z", "btz1RrFkp9GmnypoNGRSyURkBQNUs4PPYG8SR", 131959324067470008L ;
|
||||||
"40196c01a502608d7f22", "ebb81e0f79c568c0181e9db9cdafde7a8db65f82", 112378240876120002;
|
"tz1RUxPjviua4XJM78XjSKGUCAS9R3y8Bdof", "btz1hozabzP9HdRakJddzyea7DgPHzJ5PB37N", 112378240876120002L ;
|
||||||
"d7abb1cd59a66ce3fc42", "f8e91e7adba8cc32ce848a43e440de7c3e4f0866", 1060667014046690017;
|
"tz1fJPeueQKJrTj2SFV2PmyCinLYJKXCEMf4", "btz1j1k4nrZB4r8RpTYiy8zbi3Fappopkb8ZF", 1060667014046690017L ;
|
||||||
"f7a1e97970689cce7291", "4f964fbe29971a85c7152541519b1dbb8e436184", 71300478465380003;
|
"tz1iDPZLxcGf5CqCNpTuuMdtu3zKpJ6HvvFR", "btz1TaSfoSNhFoqwqbPC9iC19rN24KJtB7skD", 71300478465380003L ;
|
||||||
"f59ee7283f7eda5b3c03", "591e167977f9c4739ab17cc9d40a672737b45fa1", 283380756728119992;
|
"tz1i2kbtVu65dP739qLGRpJNujRM8pdpkH3p", "btz1USqQRuvASPXwseXkGTWeWv4dn3VwMVPEk", 283380756728119992L ;
|
||||||
"076b7feedde492164ca3", "8a5bb1da65cbbc7f3acdc3a3dae22b43364d80a6", 1357762577679880028
|
"tz1LKGCg6ESJLDviHkT8Jc7tUwjw4h3d9MaF", "btz1YwCKMbBLRL1qkBjAHGCwjbWDqiTAEFpbw", 1357762577679880028L ;
|
||||||
]
|
]
|
||||||
|
|
||||||
let init_commitment ctxt (hpkh, blind, amount) =
|
let init_commitment ctxt (hpkh, blind, amount) =
|
||||||
let half_public_key_hash = Unclaimed_public_key_hash.of_hex hpkh in
|
let half_public_key_hash = Unclaimed_public_key_hash.of_b58check_exn hpkh in
|
||||||
let blinded_public_key_hash = Blinded_public_key_hash.of_hex blind in
|
let blinded_public_key_hash = Blinded_public_key_hash.of_b58check_exn blind in
|
||||||
let amount = Tez_repr.of_mutez_exn (Int64.of_int amount) in
|
let amount = Tez_repr.of_mutez_exn amount in
|
||||||
Storage.Commitments.init
|
Storage.Commitments.init
|
||||||
ctxt half_public_key_hash
|
ctxt half_public_key_hash
|
||||||
{ blinded_public_key_hash ; amount }
|
{ blinded_public_key_hash ; amount }
|
||||||
|
@ -14,12 +14,29 @@ let size = Ed25519.Public_key_hash.size / 2
|
|||||||
let of_ed25519_pkh pkh =
|
let of_ed25519_pkh pkh =
|
||||||
MBytes.sub (Ed25519.Public_key_hash.to_bytes pkh) 0 size
|
MBytes.sub (Ed25519.Public_key_hash.to_bytes pkh) 0 size
|
||||||
|
|
||||||
let encoding = Data_encoding.Fixed.bytes size
|
let zero = MBytes.of_string (String.make size '\000')
|
||||||
|
|
||||||
let of_hex h =
|
let to_b58check s =
|
||||||
if Compare.Int.(String.length h <> size * 2) then
|
Ed25519.Public_key_hash.to_b58check
|
||||||
invalid_arg "Blinded_public_key_hash.of_hex" ;
|
(Ed25519.Public_key_hash.of_bytes_exn
|
||||||
MBytes.of_hex (`Hex h)
|
(MBytes.concat s zero))
|
||||||
|
|
||||||
|
let of_b58check_exn s =
|
||||||
|
let pkh = Ed25519.Public_key_hash.of_b58check_exn s in
|
||||||
|
let padding = MBytes.sub (Ed25519.Public_key_hash.to_bytes pkh) size size in
|
||||||
|
if MBytes.(<>) zero padding then
|
||||||
|
failwith "invalid Base58Check-encoded unclaimed public-key hash" ;
|
||||||
|
of_ed25519_pkh pkh
|
||||||
|
|
||||||
|
let encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
splitted
|
||||||
|
~binary:(Fixed.bytes size)
|
||||||
|
~json:
|
||||||
|
(conv
|
||||||
|
to_b58check
|
||||||
|
of_b58check_exn
|
||||||
|
string)
|
||||||
|
|
||||||
module Index = struct
|
module Index = struct
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ type t
|
|||||||
val encoding : t Data_encoding.t
|
val encoding : t Data_encoding.t
|
||||||
|
|
||||||
val of_ed25519_pkh : Ed25519.Public_key_hash.t -> t
|
val of_ed25519_pkh : Ed25519.Public_key_hash.t -> t
|
||||||
val of_hex : string -> t
|
|
||||||
|
val to_b58check : t -> string
|
||||||
|
val of_b58check_exn : string -> t
|
||||||
|
|
||||||
module Index : sig
|
module Index : sig
|
||||||
type nonrec t = t
|
type nonrec t = t
|
||||||
|
@ -46,8 +46,8 @@ let given_secret =
|
|||||||
"c5422e3864b9e6c5260e2aac76ea0f3d28d4fff7"
|
"c5422e3864b9e6c5260e2aac76ea0f3d28d4fff7"
|
||||||
|
|
||||||
let expected_blinded_pkh =
|
let expected_blinded_pkh =
|
||||||
Blinded_public_key_hash.of_hex
|
Blinded_public_key_hash.of_b58check_exn
|
||||||
"4a6af2f5c466bf0a7a1001a1e9468cbfca82cef6"
|
"btz1T77Ly5U1bWNBR5KzDSgNFST5Bh5F1eB6g"
|
||||||
|
|
||||||
let expected_amount =
|
let expected_amount =
|
||||||
match Tez.of_mutez 1868898542104130027L with
|
match Tez.of_mutez 1868898542104130027L with
|
||||||
|
Loading…
Reference in New Issue
Block a user