Identity Node.js SDK
Installation
Our Node.js SDK is distributed via npm, and can be installed using your preferred package manager.
Terminal
# Install using npm
npm install --save @zalter/identity
# Install using Yarn
yarn add @zalter/identity
Initialization
Configure the identity client.
JavaScript
import { IdentityClient } from '@zalter/identity';
const config = {
projectId: '<your-project-id>',
credentials: '<your-credentials>' // service account credentials
};
export const identityClient = new IdentityClient(config);
Get user public key
Get user singing public key by keyId
. The requested key should be used to verify the signature of the requests
that arrive at your server.
JavaScript
const keyRecord = await identityClient.getPublicKey('<key-id>');
console.log(keyRecord);
/*
{
id: string; // same as key-id
alg: 'Ed25519';
key: Uint8Array; // public key raw bytes as Uint8Array
subId: string; // subject (user) ID
}
*/
Verify user signature
JavaScript
import { Verifier } from '@zalter/identity';
const sig = new Uint8Array(0); // raw bytes of the signature
const dataToVerify = new Uint8Array(0); // raw bytes of the data signed
const keyRecord = {}; // result of `identityClient.getPublicKey()`
let isValid;
try {
isValid = Verifier.verify(
keyRecord.key,
keyRecord.alg,
sig,
dataToVerify
);
} catch (err) {
console.error(err);
}
console.log(isValid); // boolean