UNPKG

lightningdevkit

Version:
109 lines 4.37 kB
import { Result_RevocationKeyDecodeErrorZ } from '../structs/Result_RevocationKeyDecodeErrorZ.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * The revocation key is used to allow a channel party to revoke their state - giving their * counterparty the required material to claim all of their funds if they broadcast that state. * * Each commitment transaction has a revocation key based on the basepoint and * per_commitment_point which is used in both commitment and HTLC transactions. * * See [the BOLT spec for derivation details] * <https://github.com/lightning/bolts/blob/master/03-transactions.md#revocationpubkey-derivation> */ export class RevocationKey extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.RevocationKey_free); } get_a() { const ret = bindings.RevocationKey_get_a(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } set_a(val) { bindings.RevocationKey_set_a(this.ptr, bindings.encodeUint8Array(val)); } /** * Constructs a new RevocationKey given each field */ static constructor_new(a_arg) { const ret = bindings.RevocationKey_new(bindings.encodeUint8Array(a_arg)); const ret_hu_conv = new RevocationKey(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Checks if two RevocationKeys 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.RevocationKey_eq(this.ptr, CommonBase.get_ptr_of(b)); CommonBase.add_ref_from(this, b); return ret; } clone_ptr() { const ret = bindings.RevocationKey_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the RevocationKey */ clone() { const ret = bindings.RevocationKey_clone(this.ptr); const ret_hu_conv = new RevocationKey(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the RevocationKey. */ hash() { const ret = bindings.RevocationKey_hash(this.ptr); return ret; } /** * Derives a per-commitment-transaction revocation public key from one party's per-commitment * point and the other party's [`RevocationBasepoint`]. This is the public equivalent of * [`chan_utils::derive_private_revocation_key`] - using only public keys to derive a public * key instead of private keys. * * Note that this is infallible iff we trust that at least one of the two input keys are randomly * generated (ie our own). * * [`chan_utils::derive_private_revocation_key`]: crate::ln::chan_utils::derive_private_revocation_key */ static constructor_from_basepoint(countersignatory_basepoint, per_commitment_point) { const ret = bindings.RevocationKey_from_basepoint(CommonBase.get_ptr_of(countersignatory_basepoint), bindings.encodeUint8Array(per_commitment_point)); const ret_hu_conv = new RevocationKey(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); CommonBase.add_ref_from(ret_hu_conv, countersignatory_basepoint); return ret_hu_conv; } /** * Get inner Public Key */ to_public_key() { const ret = bindings.RevocationKey_to_public_key(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Serialize the RevocationKey object into a byte array which can be read by RevocationKey_read */ write() { const ret = bindings.RevocationKey_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a RevocationKey from a byte array, created by RevocationKey_write */ static constructor_read(ser) { const ret = bindings.RevocationKey_read(bindings.encodeUint8Array(ser)); const ret_hu_conv = Result_RevocationKeyDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } } //# sourceMappingURL=RevocationKey.mjs.map