@litert/tokens
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

LiteRT/Tokens

Strict TypeScript Checked npm version License node GitHub issues GitHub Releases

A token serialization & unserialization library.

Requirement

  • TypeScript v4.0.x (or newer)
  • Node.js v12.0.0 (or newer)

Installation

npm i @litert/tokens --save

Usage

import * as Tokens from "@litert/tokens";

// Create a JWT encoder.
const jwts = Tokens.createJWTEncoder();

// Register a profile with HMAC-SHA-512 algorithm.
jwts.registerHMACProfile({
    name: 'test-hs512',
    algorithm: 'sha512',
    key: 'hello world',
    predefinedPayload: {
        aud: 'https://litert.org'
    },
    predefinedHeaders: {
        vid: 123456
    }
});

// Create a JWT with hs512 profile.
const testJWT = jwts.create("test-hs512", {
    "iss": "Heaven",
    "name": "Hik"
});

// Print the JWT string.
console.log(testJWT);

// Try to verify it, if verified successfully, check the testInfo.signature.
const testInfo = jwts.verify(testJWT, "test-hs512");

if (testInfo.signature.verified) {

    console.info("Success!");
}
else {

    console.error("Failed!");
}

// Print the JWT structure.
console.log(JSON.stringify(testInfo, null, 2));

Document

Preparing yet.

License

This library is published under Apache-2.0 license.

Readme

Keywords

Package Sidebar

Install

npm i @litert/tokens

Weekly Downloads

4

Version

0.3.0

License

Apache-2.0

Unpacked Size

60.8 kB

Total Files

25

Last publish

Collaborators

  • fenying