This project provides a WalletProvider class that can generate wallets that store ED25519 keys, sign messages, and verify signatures. It also includes functionality to export keys to an encrypted file.
To install the necessary dependencies, run:
npm installYou can create a new wallet with a randomly generated mnemonic phrase:
import { WalletProvider } from 'trac-wallet';
const provider = new WalletProvider({ networkPrefix: 'trac' });
const wallet = await provider.generate('optional-seed');
console.log(wallet.publicKey.toString('hex')); // Prints the public keyYou can also create a wallet with a specific mnemonic phrase:
const mnemonic = 'session attitude weekend sign collect mobile return vacuum pool afraid wagon client';
const wallet = await provider.fromMnemonic({ mnemonic });
console.log(wallet.publicKey.toString('hex')); // Prints the public keyYou can sign a message with the wallet's secret key and verify the signature with the public key:
const message = 'Hello, world!';
const signature = wallet.signMessage(message);
const isValid = wallet.verify(message, signature);
console.log(isValid); // Prints true if the signature is validYou can export the wallet's keys to a JSON file:
const filePath = './wallet.json';
exportToFile(wallet, filePath);To run the tests, use the following command:
npm run test