Skip to content

Instantly share code, notes, and snippets.

@maxux
Created January 12, 2023 23:09
Show Gist options
  • Save maxux/d4a61178894effe0964daeca3c6b29e0 to your computer and use it in GitHub Desktop.
Save maxux/d4a61178894effe0964daeca3c6b29e0 to your computer and use it in GitHub Desktop.
module main
import os
import libsodium
import freeflowuniverse.crystallib.mnemonic
fn seed_from_random() []u8 {
mut seed := []u8{}
for _ in 0 .. 32 {
seed << u8(libsodium.randombytes_random())
}
return seed
}
fn seed_from_args() []u8 {
return mnemonic.parse(os.args[1])
}
fn main() {
println("libsodium check")
mut seed := []u8{}
if os.args.len > 1 {
println("loading seed from command line")
seed = seed_from_args()
} else {
println("generating new seed")
seed = seed_from_random()
println(seed)
str := mnemonic.dumps(seed)
println(str)
}
a := libsodium.crypto_kx_seed_keypair(seed)
println(a)
x := libsodium.new_signing_key_seed(seed)
s := x.sign_string("HELLO WORLD")
println(s)
println(x.verify_key.verify_string(s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment