https://github.com/litert/tokens.js
A token serialization & unserialization library.
https://github.com/litert/tokens.js
Last synced: 4 months ago
JSON representation
A token serialization & unserialization library.
- Host: GitHub
- URL: https://github.com/litert/tokens.js
- Owner: litert
- License: apache-2.0
- Created: 2019-07-05T06:17:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T22:44:55.000Z (about 2 years ago)
- Last Synced: 2025-09-20T03:27:26.798Z (11 months ago)
- Language: TypeScript
- Size: 229 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# LiteRT/Tokens
[](https://www.typescriptlang.org)
[](https://www.npmjs.com/package/@litert/tokens "Stable Version")
[](https://github.com/litert/tokens/blob/master/LICENSE)
[](https://nodejs.org/dist/latest-v8.x/)
[](https://github.com/litert/tokens.js/issues)
[](https://github.com/litert/tokens.js/releases "Stable Release")
A token serialization & unserialization library.
## Requirement
- TypeScript v4.0.x (or newer)
- Node.js v12.0.0 (or newer)
## Installation
```sh
npm i @litert/tokens --save
```
## Usage
```ts
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) license.