memorable-unique-identifier
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

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:

Name Type Description
key string The 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:

Name Type Description
key string The 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:

Name Type Default Description
difficulty number 8 The 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:

Name Type Description
key string The 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:

Name Type
difficulty number
quota number

Returns: MinedKey[]

Static search

search(code: string): undefined | string

Return the spirit animal given the public identity

Parameters:

Name Type Description
code string The 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:

Name Type Description
source Buffer The 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:

Name Type Description
key string The 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.

Readme

Keywords

none

Package Sidebar

Install

npm i memorable-unique-identifier

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

2.3 MB

Total Files

9

Last publish

Collaborators

  • rustyconover