UNPKG

@4players/odin-tokens

Version:

A lightweight token generator for 4Players ODIN

50 lines (37 loc) 2.49 kB
# @4players/odin-tokens [![npm](https://img.shields.io/npm/v/@4players/odin-tokens.svg)][npm-badge-url] [![npm](https://img.shields.io/npm/l/@4players/odin-tokens.svg)][license-url] [![npm](https://img.shields.io/npm/dm/@4players/odin-tokens.svg)][npm-badge-url] This is a lightweight module to generate API keys and tokens used by [ODIN Voice](https://odin.4players.io/voice-chat/) by [4Players](https://www.4players.io/company/about_us/). ODIN Voice is a cross-platform software development kit (SDK) that enables developers to integrate voice and video chat technology into multiplayer games. Check out our full [online documentation](https://docs.4players.io/voice/). ## Flowchart ```mermaid graph TB RandomBytes[Random Bytes] --> AccessKey; AccessKey --> PublicKey; AccessKey --> SecretKey; PublicKey --> KeyId; ``` ## Example ```typescript import { TokenGenerator } from "@4players/odin-tokens"; const accessKey = "<YOUR API KEY HERE>"; const generator = new TokenGenerator(accessKey); const token = await generator.createToken("my room", "john doe"); console.log(`generated a new token: ${token}`); ``` ## Terminology | Term | Description | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | AccessKey | Gives access to the ODIN network for a customer. It is a 44 character long Base64-String, which consists of a version, random bytes and a checksum. | | SecretKey | Generated from the AccessKey, it is based on the Ed25519-Curve and used to sign a Token generated by the customer. | | PublicKey | Generated from the AccessKey, it is based on the Ed25519-Curve and must be uploaded to 4Players so that a generated Token can be verified. | | KeyId | A shortened PublicKey, included in Token, making it possible to identify what PublicKey must be used to verify the Token. | | Token | A [JWT] given to the game clients that allows them to connect to a voice/video chat room in the ODIN network. | [jwt]: https://en.wikipedia.org/wiki/JSON_Web_Token [npm-badge-url]: https://www.npmjs.com/package/@4players/odin-tokens [license-url]: https://github.com/4Players/odin-tokens/blob/master/LICENSE