@herajs/crypto
v2.1.1
Published
Cryptography tools for aergo
Downloads
155
Readme
Multi-purpose javascript crypto library for aergo
It is used by Aergo dapps to manage keys and sign transactions offline.
Features:
- Key generation and importing
- Hashing
- Signing
- Simple AES-GCM encryption
How to use
npm install --save @herajs/crypto
Transaction signing
import { createIdentity, signTransaction, hashTransaction } from '@herajs/crypto';
async () => {
const identity = createIdentity();
const tx = {
nonce: 1,
from: identity.address,
to: identity.address,
amount: '100 aer',
payload: '',
};
tx.sign = await signTransaction(tx, identity.keyPair);
tx.hash = await hashTransaction(tx);
console.log(JSON.stringify(tx));
}()
Arbitrary message signing
import { createIdentity, signMessage, verifySignature, publicKeyFromAddress } from '@herajs/crypto';
async () => {
const identity = createIdentity();
const msg = Buffer.from('hello');
const signature = await signMessage(msg, identity.keyPair);
const pubkey = publicKeyFromAddress(identity.address);
const check = await verifySignature(msg, pubkey, signature);
console.log(check);
}()