Home Reference Source
import Crypto from 'token-io/src/security/Crypto.js'
public class | source

Crypto

Class providing static crypto primitives.

Static Method Summary

Static Public Methods
public static

Converts a key from a string to buffer.

public static

Helper function for crypto engine createSigner: returns a signer that uses a key pair.

public static

Helper function for crypto engine createVerifier: returns a signer that uses a key pair.

public static

async generateKeys(keyLevel: string, expirationMs: number, extractable: boolean): Object

Generates a key pair to use with the Token system.

public static

async sign(message: string, keys: Object): string

Signs a string and returns the signature.

public static

async signJson(json: Object, keys: Object): string

Signs a json object and returns the signature

public static

Converts a key to string.

public static

async verify(message: string, signature: string, publicKey: Uint8Array)

Verifies a signature on a string.

public static

async verifyJson(json: Object, signature: string, publicKey: Uint8Array)

Verifies a signature on a JSON object.

public static

wrapBuffer(buffer: string | Buffer): Uint8Array

Wraps buffer as an Uint8Array object.

Static Public Methods

public static bufferKey(key: string): Uint8Array source

Converts a key from a string to buffer.

Params:

NameTypeAttributeDescription
key string

base64url encoded key

Return:

Uint8Array

buffered key

public static createSignerFromKeypair(keyPair: Object): Object source

Helper function for crypto engine createSigner: returns a signer that uses a key pair.

Params:

NameTypeAttributeDescription
keyPair Object

such as returned by Token.Crypto.generateKeys

Return:

Object

signer object

public static createVerifierFromKeypair(keyPair: Object): Object source

Helper function for crypto engine createVerifier: returns a signer that uses a key pair.

Params:

NameTypeAttributeDescription
keyPair Object

such as returned by Token.Crypto.generateKeys, private key optional

Return:

Object

verifier object

public static async generateKeys(keyLevel: string, expirationMs: number, extractable: boolean): Object source

Generates a key pair to use with the Token system.

Params:

NameTypeAttributeDescription
keyLevel string

'LOW', 'STANDARD', or 'PRIVILEGED'

expirationMs number

(optional) expiration duration of the key in milliseconds

extractable boolean

whether the private key can be extracted into raw data

Return:

Object

generated key pair

public static async sign(message: string, keys: Object): string source

Signs a string and returns the signature.

Params:

NameTypeAttributeDescription
message string

message to sign

keys Object

keys to sign with

Return:

string

signature

public static async signJson(json: Object, keys: Object): string source

Signs a json object and returns the signature

Params:

NameTypeAttributeDescription
json Object

object to sign

keys Object

keys to sign with

Return:

string

signature

public static strKey(key: Uint8Array): string source

Converts a key to string.

Params:

NameTypeAttributeDescription
key Uint8Array

key to encode

Return:

string

encoded key

public static async verify(message: string, signature: string, publicKey: Uint8Array) source

Verifies a signature on a string. Throws if verification fails.

Params:

NameTypeAttributeDescription
message string

string to verify

signature string

signature to verify

publicKey Uint8Array

public key to use for verification

public static async verifyJson(json: Object, signature: string, publicKey: Uint8Array) source

Verifies a signature on a JSON object. Throws if verification fails.

Params:

NameTypeAttributeDescription
json Object

JSON object to verify

signature string

signature to verify

publicKey Uint8Array

public key to use for verification

public static wrapBuffer(buffer: string | Buffer): Uint8Array source

Wraps buffer as an Uint8Array object.

Params:

NameTypeAttributeDescription
buffer string | Buffer

data

Return:

Uint8Array

data