ThreadID class
ThreadID represents a self-describing Thread identifier.
It is formed by a Version, a Variant, and a random number of a given length.
Signature:
export declare class ThreadID
Example 1
Create a new random ThreadID
import { ThreadID } from '@textile/hub'
const id = ThreadID.fromRandom()
console.log(id)
Example 2
Convert a ThreadID to/from a Base32 string
import { ThreadID } from '@textile/hub'
const id = ThreadID.fromRandom()
const str = id.toString()
const restored = ThreadID.fromString(str)
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(buf) | Constructs a new instance of the ThreadID class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
buf | Uint8Array | ||
V1 | static | number | Versions. Currently only V1 is supported. |
Variant | static | typeof Variant |
Methods
Method | Modifiers | Description |
---|---|---|
equals(o) | equals checks that two IDs are the same. | |
fromBytes(data) | static | fromBytes takes an ID data slice, parses it and returns an ID. For IDV1, the data bytes are arranged as: |
fromRandom(variant, size) | static | fromRandom creates a new random ID object. |
fromString(v) | static | fromString parses an ID-encoded string and returns an ID object. For IDV1, an ID-encoded string is primarily a multibase string: <multibase-type-code><base-encoded-string> The base-encoded string represents a: |
getEncoding(v) | static | getEncoding returns the multibase encoding for a multibase encoded string. Returns the name of the encoding if it is encoded, and throws an error otherwise. |
isDefined() | isDefined returns true if an ID is defined. Calling any other methods on an undefined ID will result in undefined behavior. | |
toBytes() | toBytes returns the byte representation of an ID. The output of bytes can be parsed back into an ID with fromBytes. | |
toString(base) | toString returns the (multibase encoded) string representation of an ID. | |
variant() | variant returns the variant of an ID. | |
version() | version returns the ID version. |