UNPKG

lightningdevkit

Version:
96 lines 3.82 kB
import { Result_HtlcBasepointDecodeErrorZ } from '../structs/Result_HtlcBasepointDecodeErrorZ.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * Base key used in conjunction with a `per_commitment_point` to generate an [`HtlcKey`]. * * HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC * preimage and that only the sender of an HTLC can claim it on-chain after it has timed out. * Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script. */ export class HtlcBasepoint extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.HtlcBasepoint_free); } get_a() { const ret = bindings.HtlcBasepoint_get_a(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } set_a(val) { bindings.HtlcBasepoint_set_a(this.ptr, bindings.encodeUint8Array(val)); } /** * Constructs a new HtlcBasepoint given each field */ static constructor_new(a_arg) { const ret = bindings.HtlcBasepoint_new(bindings.encodeUint8Array(a_arg)); const ret_hu_conv = new HtlcBasepoint(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Checks if two HtlcBasepoints 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.HtlcBasepoint_eq(this.ptr, CommonBase.get_ptr_of(b)); CommonBase.add_ref_from(this, b); return ret; } clone_ptr() { const ret = bindings.HtlcBasepoint_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the HtlcBasepoint */ clone() { const ret = bindings.HtlcBasepoint_clone(this.ptr); const ret_hu_conv = new HtlcBasepoint(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the HtlcBasepoint. */ hash() { const ret = bindings.HtlcBasepoint_hash(this.ptr); return ret; } /** * Get inner Public Key */ to_public_key() { const ret = bindings.HtlcBasepoint_to_public_key(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Derives the \"tweak\" used in calculate [`HtlcKey::from_basepoint`].\n\n[`HtlcKey::from_basepoint`] calculates a private key as:\n`privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`\n\nThis calculates the hash part in the tweak derivation process, which is used to\nensure that each key is unique and cannot be guessed by an external party. */ derive_add_tweak(per_commitment_point) { const ret = bindings.HtlcBasepoint_derive_add_tweak(this.ptr, bindings.encodeUint8Array(per_commitment_point)); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Serialize the HtlcBasepoint object into a byte array which can be read by HtlcBasepoint_read */ write() { const ret = bindings.HtlcBasepoint_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a HtlcBasepoint from a byte array, created by HtlcBasepoint_write */ static constructor_read(ser) { const ret = bindings.HtlcBasepoint_read(bindings.encodeUint8Array(ser)); const ret_hu_conv = Result_HtlcBasepointDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } } //# sourceMappingURL=HtlcBasepoint.mjs.map