The folder where you want the keys to be saved. If the folder does not exist, it will be created. Keys are saved as utf8 encoded hex strings on the disk.
If you are initializing a secret key you already have, input it here.
If you already have a cert, you may input it here. You must supply the cert if you have connected with this keypair before.
This is emitted whenever the keyring is done initializing. In the initialization process, it will either load or create the key folder and key files at the specified path.
Example:
keyring.on("ready", () => {
const signed = keyring.sign(keyring.getPub());
const verified = keyring.verify(keyring.getPub(), signed, keyring.getPub());
if (verified) {
console.log("The signature is verified!");
}
});
keyring.on("error", (error: Error) => {
// do something with the error
});
This is emitted whenever the keyring experiences an error initializing.
Example:
keyring.on("error", (error: Error) => {
// do something with the error
});
Get the current cert, if there is one. There will not be a cert if the keyring has never been used to connect to a cordinator before.
The cert, or null.
Get the keyring directory path.
The key folder path.
Get the private key.
The public key.
Get the public key.
The public key.
Re-initializes the keyring. This may be useful if you've made changes to the key files on disk and want them to update.
Sets the current cert. This is used internally by the Channel class.
Signs a message with the keyring private key.
The message to sign.
The resulting signature.
Verifies a message signature is valid for a given public key.
The message to sign.
The signature to verify.
The public key to verify against.
true if the signature verifies, false if it doesn't.
Generated using TypeDoc
The KeyRing provides an interface that allows you to generate and store a pair of ed25519 keys, as well as sign and verify ed25519 signatures.
It takes a directory as the only argument of the constructor. It will create a new keyring in this directory or load the keyring from the directory if it is already present.
It also takes the special string
:memory:
as a parameter to only store the keys in memory, so this module an run in a browser. Make sure you provide a way for the client to export the keys and cert if you do this.Keyrings can only be used with one coordinator. You can not connect to two different coordinators with one keyring, you must generate a new keyring for each coordinator.
Example Usage:
const keyring = new KeyRing("./keyring"); // If you want to perform operations with the keyring, wait for the ready event. keyring.on("ready", () => { const signed = keyring.sign(keyring.getPub()); const verified = keyring.verify(keyring.getPub(), signed, keyring.getPub()); if (verified) { console.log("The signature is verified!"); } }); keyring.on("error", (error: Error) => { // do something with the error });
Note that the sign() and verify() functions take uint8 arrays. If you need to convert hex strings into Uint8 arrays, use the helper functions in the Utils class.