UNPKG

lightningdevkit

Version:
80 lines 2.66 kB
import { Result_HostnameDecodeErrorZ } from '../structs/Result_HostnameDecodeErrorZ.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * Represents a hostname for serialization purposes. * Only the character set and length will be validated. * The character set consists of ASCII alphanumeric characters, hyphens, and periods. * Its length is guaranteed to be representable by a single byte. * This serialization is used by [`BOLT 7`] hostnames. * * [`BOLT 7`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md */ export class Hostname extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.Hostname_free); } clone_ptr() { const ret = bindings.Hostname_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the Hostname */ clone() { const ret = bindings.Hostname_clone(this.ptr); const ret_hu_conv = new Hostname(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the Hostname. */ hash() { const ret = bindings.Hostname_hash(this.ptr); return ret; } /** * Checks if two Hostnames contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. * Two objects with NULL inner values will be considered "equal" here. */ eq(b) { const ret = bindings.Hostname_eq(this.ptr, CommonBase.get_ptr_of(b)); CommonBase.add_ref_from(this, b); return ret; } /** * Returns the length of the hostname. */ len() { const ret = bindings.Hostname_len(this.ptr); return ret; } /** * Get the string representation of a Hostname object */ to_str() { const ret = bindings.Hostname_to_str(this.ptr); const ret_conv = bindings.decodeString(ret); return ret_conv; } /** * Serialize the Hostname object into a byte array which can be read by Hostname_read */ write() { const ret = bindings.Hostname_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a Hostname from a byte array, created by Hostname_write */ static constructor_read(ser) { const ret = bindings.Hostname_read(bindings.encodeUint8Array(ser)); const ret_hu_conv = Result_HostnameDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } } //# sourceMappingURL=Hostname.mjs.map