lightningdevkit
Version:
Lightning Development Kit
104 lines • 3.95 kB
JavaScript
import { Result_HumanReadableNameNoneZ } from '../structs/Result_HumanReadableNameNoneZ.mjs';
import { Result_HumanReadableNameDecodeErrorZ } from '../structs/Result_HumanReadableNameDecodeErrorZ.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* A struct containing the two parts of a BIP 353 Human Readable Name - the user and domain parts.
*
* The `user` and `domain` parts, together, cannot exceed 232 bytes in length, and both must be
* non-empty.
*
* To protect against [Homograph Attacks], both parts of a Human Readable Name must be plain
* ASCII.
*
* [Homograph Attacks]: https://en.wikipedia.org/wiki/IDN_homograph_attack
*/
export class HumanReadableName extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.HumanReadableName_free);
}
clone_ptr() {
const ret = bindings.HumanReadableName_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the HumanReadableName
*/
clone() {
const ret = bindings.HumanReadableName_clone(this.ptr);
const ret_hu_conv = new HumanReadableName(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Generates a non-cryptographic 64-bit hash of the HumanReadableName.
*/
hash() {
const ret = bindings.HumanReadableName_hash(this.ptr);
return ret;
}
/**
* Checks if two HumanReadableNames 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.HumanReadableName_eq(this.ptr, CommonBase.get_ptr_of(b));
CommonBase.add_ref_from(this, b);
return ret;
}
/**
* Constructs a new [`HumanReadableName`] from the `user` and `domain` parts. See the
* struct-level documentation for more on the requirements on each.
*/
static constructor_new(user, domain) {
const ret = bindings.HumanReadableName_new(bindings.encodeString(user), bindings.encodeString(domain));
const ret_hu_conv = Result_HumanReadableNameNoneZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Constructs a new [`HumanReadableName`] from the standard encoding - `user`@`domain`.
*
* If `user` includes the standard BIP 353 ₿ prefix it is automatically removed as required by
* BIP 353.
*/
static constructor_from_encoded(encoded) {
const ret = bindings.HumanReadableName_from_encoded(bindings.encodeString(encoded));
const ret_hu_conv = Result_HumanReadableNameNoneZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Gets the `user` part of this Human Readable Name
*/
user() {
const ret = bindings.HumanReadableName_user(this.ptr);
const ret_conv = bindings.decodeString(ret);
return ret_conv;
}
/**
* Gets the `domain` part of this Human Readable Name
*/
domain() {
const ret = bindings.HumanReadableName_domain(this.ptr);
const ret_conv = bindings.decodeString(ret);
return ret_conv;
}
/**
* Serialize the HumanReadableName object into a byte array which can be read by HumanReadableName_read
*/
write() {
const ret = bindings.HumanReadableName_write(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
/**
* Read a HumanReadableName from a byte array, created by HumanReadableName_write
*/
static constructor_read(ser) {
const ret = bindings.HumanReadableName_read(bindings.encodeUint8Array(ser));
const ret_hu_conv = Result_HumanReadableNameDecodeErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
}
//# sourceMappingURL=HumanReadableName.mjs.map