cogny2
v1.0.3
Published
Implementation of Cogny2 Module Sets
Downloads
66
Maintainers
Readme
Cogny2
Implementation of Cogny2 Module Sets
Installation
Install cogny2 with npm
npm install cogny2
VerificationToken
Usage/Examples
Get the genratorKey and verificationKey
const { TokenPair } = require('cogny2');
const tokenPair = new TokenPair();
const { generatorKey, verifierKey } = tokenPair.generateAccessTokenPair();
Generation of the token
const { VerificationToken } = require('cogny2');
const vt1 = new VerificationToken({generatorKey});
const tokenPayloadToEncrypt{
"_id": "658005dd25b068ae229b58e3",
"index": 1,
"guid": "f79877ed-0c1e-407f-91a9-95f8f1d2c9d1",
"isActive": false,
"balance": "$2,732.74",
"picture": "http://placehold.it/32x32",
"age": 35,
"eyeColor": "brown",
"name": "Knapp Buckley",
"gender": "male",
"company": "EARTHMARK",
"latitude": -29.080935,
"longitude": 128.138971
}
vt1.generate(tokenPayloadToEncrypt)
Verification of the token
const { VerificationToken } = require('cogny2');
const vt2 = new VerificationToken({verifierKey});
// returns true/false
const generatedTokenVerified = await vt2.verify(encryptedToken);
console.log('tokenVerification :: ', generatedTokenVerified);
// get the decrypted token payload
const tokenDecryptedPayload = vt2.getPayload();
console.log('tokenPayload ::: ', tokenDecryptedPayload);