1.0.8 • Published 3 years ago

memorable-unique-identifier v1.0.8

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

Memorable Unique Identifiers for Node.js/TypeScript

A implementation of Memorable Unique Identifiers (Muids) in Node.js/TypeScript

Installation

npm install memorable-unique-identifier

Usage

import { MemorableUniqueIdentifier } from "memorable-unique-identifier";

// Create a key of difficulty 6 this should
// not take long at all.
const result = MemorableUniqueIdentifier.create(6);

console.error(result);

// Example result output (your result will vary)
//
// {
//  length: 6,
//  pretty: 'Sma Eel',
//  key: '1ed2798ec3f5d61270629ab6ad14f7e8',
//  hash: '53aee16014b2829688c2907ae010f90b'
// }

API

MemorableUniqueIdentifier

MemorableUniqueIdentifier:

Static animal

animal(key: string): undefined | string

Return the animal name from the specified key.

Parameters:

NameTypeDescription
keystringThe key to hash and retrieve the animal name.

Returns: undefined | string

Static bhash

bhash(key: string): string

Return the first 32 bytes a hex encoded string

Parameters:

NameTypeDescription
keystringThe key to hash (should be lowercase hex)

Returns: string

string A 32 byte hash

Static create

create(difficulty: number): MinedKey

Create a new memorable unique identifier with the specified difficulty.

Parameters:

NameTypeDefaultDescription
difficultynumber8The difficulty or length of the Muid to create.

Returns: MinedKey

Static difficulty

difficulty(key: string): number

The difficulty or length of the passed key

Parameters:

NameTypeDescription
keystringThe candidate key

Returns: number

number The difficulty of the key. 0 if the key is invalid.

Static mine_until

mine_until(difficulty: number, quota: number): MinedKey[]

Mine until the necessary number of keys are produced.

Parameters:

NameType
difficultynumber
quotanumber

Returns: MinedKey[]

Static search

search(code: string): undefined | string

Return the spirit animal given the public identity

Parameters:

NameTypeDescription
codestringThe code of which to extract the animal.

Returns: undefined | string

Static shash

shash(source: Buffer): string

Hash a Buffer and return the first 16 bytes encoded in hex as a 32 byte string.

Parameters:

NameTypeDescription
sourceBufferThe buffer to hash.

Returns: string

Static validate

validate(key: string): boolean

Check to see if the key is a memorable unique identifier by extracting the animal name.

Parameters:

NameTypeDescription
keystringThe candidate key

Returns: boolean

boolean Indicate if the key is a valid Muid

MinedKey

MinedKey:

hash

hash: string

key

key: string

length

length: number

pretty

pretty: string

TODO

Use the WebCrypto API's to allow these identifiers to be generated in the browser.

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago