0.3.12 • Published 3 years ago
@mey-sdk-js/crypto v0.3.12
Multi-purpose javascript crypto library for mey
It is used by MeyCoin 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 @mey-sdk-js/crypto
Transaction signing
import { createIdentity, signTransaction, hashTransaction } from '@mey-sdk-js/crypto';
async () => {
const identity = createIdentity();
const tx = {
nonce: 1,
from: identity.address,
to: identity.address,
amount: '100 gas',
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 '@mey-sdk-js/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);
}()