Motoko implementation of ed25519.
This library is a porting version of noble-ed25519.
Dependencies :
- https://github.com/ZenVoich/fuzz // random byte (create private key)
- https://github.com/timohanke/motoko-iterext
- https://github.com/timohanke/motoko-sha2 // sha256 + sha512
Vessel are supported:
Setting of dfx.json :
{
"defaults": {
"build": {
"packtool": "vessel sources"
}
},
"version": 1
}
Setting of package-set.dhall :
let additions = [
{ name = "ed25519"
, version = "v1.0.0"
, repo = "https://github.com/nirvana369/ed25519.git"
, dependencies = [ "base" ] : List Text
}
]
How to use :
import Lib "mo:ed25519";
let privateKey = Lib.Utils.randomPrivateKey();
let message : [Nat8] = [0xab, 0xbc, 0xcd, 0xde];
let publicKey = Lib.ED25519.getPublicKey(privateKey);
let signature = Lib.ED25519.sign(message, privateKey);
let isValid = Lib.ED25519.verify(signature, message, publicKey);
The randomPrivateKey() function is designed based on a simple algorithm using the fuzz library to generate random bytes, which does not provide strong cryptographic randomness. Please use an external library if you have high security requirements.