Crypto library for deriving mnemonics and keypairs, signing and verifying messages, and authentication
Install @0xver/crypto with npm:
npm install @0xver/crypto
Import:
import Keys from "@0xver/crypto";
Generate 12-word English mnemonic:
const mnemonic = Keys.mnemonic({ words: 12, language: "english" });
Generate 18-word English mnemonic:
const mnemonic = Keys.mnemonic({ words: 18, language: "english" });
Generate 24-word English mnemonic:
const mnemonic = Keys.mnemonic({ words: 24, language: "english" });
Define curve type for keypair generation:
const type = "ed25519" || "secp256k1";
Generate keypair:
Keys.keypair({ type });
CAUTION: The keypairFromMnemonic function derives a single keypair directly from the seed (private key) without adhering to HD wallet standards typically used by most wallets. As a result, importing the same mnemonic into other wallets will likely generate different keypairs due to those wallets’ use of hierarchical deterministic paths. While the keypair generated by this function is secure, it is important to understand that it is not compatible with HD wallet-compatible systems, limiting its interoperability with standard wallets. This approach is intended to keep the package lightweight.
Generate keypair from mnemonic:
Keys.keypairFromMnemonic({ mnemonic, type });
Generate keypair from mnemonic and passphrase:
Keys.keypairFromMnemonic({ mnemonic, passphrase: "passphrase123", type });
Import:
import Signature from "@0xver/crypto";
Define ed25519 or secp256k1 type:
const type = "ed25519" || "secp256k1";
Optionally create keypair:
import Keys from "@0xver/crypto";
const keypair = Keys.keypair({ type });
Create message:
const message = "Hello, world!";
Sign ed25519 message with secret key:
const signedMessage = Signature.sign({ message, secretKey: keypair.secretKey, type });
Sign secp256k1 message with private key:
const signedMessage = Signature.sign({ message, privateKey: keypair.privateKey, type });
Verify message:
Signature.verify({ message, publicKey: keypair.publicKey, signature: signedMessage.signature, type });
Import:
import Auth from "@0xver/crypto";
Define token params:
import { keypair } from "@0xver/crypto";
const type = "ed25519" || "secp256k1";
const domain = "example.com";
const keys = keypair({ type });
const statement = Auth.prepare({ domain, publicKey: keys.publicKey });
Sign ed25519 message with secret key:
import { sign } from "@0xver/crypto";
const signature = sign({ message, secretKey: keys.secretKey, type });
Sign secp256k1 message with private key:
import { sign } from "@0xver/crypto";
const signature = sign({ message, privateKey: keys.privateKey, type });
Generate token that never expires:
const token = Auth.token({ domain, publicKey: keypair.publicKey, statement, signature });
Generate token that expires in 24 hours:
const token = Auth.token({ domain, publicKey: keypair.publicKey, statement, signature, expires: 86400000 });
Create certificate:
Auth.certificate({ token, type });
Import:
import { wordFromNumber } from "@0xver/crypto";
English word from number:
const word = wordFromNumber({ number: 42, language: "english" });
Import:
import { numberFromWord } from "@0xver/crypto";
Number from English word:
const number = numberFromWord({ word: "aim", language: "english" });
Import:
import Auth, { response } from "@0xver/crypto";
Usage on certificate:
const certificate = Auth.certificate({ token, type });
return new Response(response({ data: certificate }), {
headers: { "Content-Type": "application/json" }
});