@cere/cere-signer
v2.0.0
Published
This lib provides an ability to sign data and verify signed data using blake2b algorithm.
Downloads
422
Readme
Description
This lib provides an ability to sign data and verify signed data using blake2b algorithm.
Release Notes
v1.3.3
- Updated permission
v1.3.0
- Change Stub signature to properly generated by user's private key
v1.2.0
- Added substrate signer function
Installation
nvm exec npm i
Test
nvm exec npm test
Using
Sign whole object
import { signObject } from '@cere-io/cere-signer';
const obj = { id: 1 };
signObject(obj);
// after that inside our object a new field called 'signature' will be appeared
console.log(obj.signature);
Sign object with pointing a sequence of fields
import { signObject } from '@cere-io/cere-signer';
const obj = { id: 1, event_type: 'checkin', payload: {} };
// we can provide any additional fields as varargs. Order is important!
signObject(obj, 'id', 'event_type', 'payload');
// after that inside our object a new field called 'signature' will be appeared
console.log(obj.signature);
Verify signature
Here we use the same approach as above: we can verify a whole object as well as provide a sequence of fields:
import { verifySignature } from '@cere-io/cere-signer';
const signature = 'sig';
const obj = { id: 1 };
const res = verifySignature(obj, signature); // result as boolean
import { verifySignature } from '@cere-io/cere-signer';
const signature = 'sig';
const obj = { id: 1, event_type: 'checkin', payload: {} };
// the order of fields is important! use the same order as you provided to signObject method.
const res = verifySignature(obj, signature, 'id', 'event_type', 'payload'); // result as boolean