Home Reference Source
import {Util} from '@token-io/core/src/Util.js'
public class | source

Util

Class to provide static utility functions.

Static Method Summary

Static Public Methods
public static

Converts a key from a string to buffer.

public static

async callAsync(method: function, fn: function): Promise

Helper method to handle promise exceptions.

public static

callSync(method: function, fn: function): Object

Helper method similar to the one above, but without promises

public static

Count the number of decimal points in a number

public static

Generates a random nonce

public static

getByte(word: number, index: number): number

Gets the specified byte of the 4 byte word, according to index.

public static

getSigningKey(keys: Array, signature: Object): Object

Gets the signing key from a list of keys corresponding to the signature.

public static

Support alias hashing

public static

Hash a string value.

public static

parseParamsFromUrl(url: *): *

public static

randomAlias(type: *): Object

Generates a random alias.

public static

setUpCustomResponseInterceptor(instance: *, cri: *)

public static

setUpHttpErrorLogging(instance: *)

public static

Converts a key to string.

public static

Tests if a string ends with a suffix,

public static

Returns the token alias.

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 async callAsync(method: function, fn: function): Promise source

Helper method to handle promise exceptions. The function will be executed, and if anything fails, a rejected promise is returned, with the method name that failed, included in the rejection.

Params:

NameTypeAttributeDescription
method function

outside method that is being executed

fn function

function to try to execute

Return:

Promise

successful or rejected promise

public static callSync(method: function, fn: function): Object source

Helper method similar to the one above, but without promises

Params:

NameTypeAttributeDescription
method function

outside method that is being executed

fn function

function to try to execute

Return:

Object

successful result or thrown error

public static countDecimals(value: Number): Number source

Count the number of decimal points in a number

Params:

NameTypeAttributeDescription
value Number

number

Return:

Number

number of decimals

public static generateNonce(): string source

Generates a random nonce

Return:

string

random string

public static getByte(word: number, index: number): number source

Gets the specified byte of the 4 byte word, according to index. Assumes 2s complement representation of the word

Params:

NameTypeAttributeDescription
word number

32 bit value number, in 2s complement

index number

index of the byte to return

Return:

number

the desired byte [0, 255]

public static getSigningKey(keys: Array, signature: Object): Object source

Gets the signing key from a list of keys corresponding to the signature.

Params:

NameTypeAttributeDescription
keys Array

list of keys

signature Object

signature

Return:

Object

the signing key

public static hashAndSerializeAlias(alias: Object): String source

Support alias hashing

Params:

NameTypeAttributeDescription
alias Object

alias to be hashed

Return:

String

hashed alias

public static hashString(value: string): string source

Hash a string value.

Params:

NameTypeAttributeDescription
value string

value to be hahsed

Return:

string

hashed value

public static parseParamsFromUrl(url: *): * source

Params:

NameTypeAttributeDescription
url *

Return:

*

public static randomAlias(type: *): Object source

Generates a random alias. Handy for tests.

Params:

NameTypeAttributeDescription
type *
  • optional
  • default: EMAIL

Return:

Object

alias protobuf

public static setUpCustomResponseInterceptor(instance: *, cri: *) source

Params:

NameTypeAttributeDescription
instance *
cri *

public static setUpHttpErrorLogging(instance: *) source

Params:

NameTypeAttributeDescription
instance *

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 stringEndsWith(str: string, suffix: string): boolean source

Tests if a string ends with a suffix,

Params:

NameTypeAttributeDescription
str string

the string to test

suffix string

the suffix to test

Return:

boolean

true if it does

public static tokenAlias(): Object source

Returns the token alias.

Return:

Object

token alias protobuf

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

Wraps buffer as an Uint8Array object.

Params:

NameTypeAttributeDescription
buffer string | Buffer

data

Return:

Uint8Array

data