0.0.7 • Published 2 years ago
@fresh-js/crypto v0.0.7
Fresh Crypto
:warning: This package is a work in progress and has not yet been vetted for production use.
The @fresh-js/crypto
package provides JavaScript cryptographic utilities needed to manage keys,
sign transactions and verify signatures for the Flow blockchain.
Functionality
Currently this package only supports ECDSA key generation and signing on the NIST P-256 and secp25k1 curves, using either SHA2 or SHA3 hashing.
- ECDSA signing and verification is provided by indutny/elliptic.
- SHA2 hashing is provided by the Node.js crypto module.
- SHA3 hashing is provided by phusion/node-sha3.
Install
npm i @fresh-js/crypto
Usage Examples
Sign a message
Sign a message with a P-256 private key and SHA3 hashing:
import { HashAlgorithm, InMemoryECPrivateKey, InMemoryECSigner, SignatureAlgorithm } from '@fresh-js/crypto';
const PRIVATE_KEY_HEX = 'xxxx';
const privateKey = InMemoryECPrivateKey.fromHex(PRIVATE_KEY_HEX, SignatureAlgorithm.ECDSA_P256);
const signer = new InMemoryECSigner(privateKey, HashAlgorithm.SHA3_256);
const message = Buffer.from("deadbeef", "hex");
const signature = signer.sign(message);