lightningdevkit
Version:
Lightning Development Kit
121 lines • 4.68 kB
JavaScript
import { RawBolt11Invoice } from '../structs/RawBolt11Invoice.mjs';
import { Result_SignedRawBolt11InvoiceBolt11ParseErrorZ } from '../structs/Result_SignedRawBolt11InvoiceBolt11ParseErrorZ.mjs';
import { Bolt11InvoiceSignature } from '../structs/Bolt11InvoiceSignature.mjs';
import { ThreeTuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ } from '../structs/ThreeTuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ.mjs';
import { Result_PayeePubKeySecp256k1ErrorZ } from '../structs/Result_PayeePubKeySecp256k1ErrorZ.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
* invalid.
*
* # Invariants
* The hash has to be either from the deserialized invoice or from the serialized [`RawBolt11Invoice`].
*/
export class SignedRawBolt11Invoice extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.SignedRawBolt11Invoice_free);
}
/**
* Checks if two SignedRawBolt11Invoices 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.SignedRawBolt11Invoice_eq(this.ptr, CommonBase.get_ptr_of(b));
CommonBase.add_ref_from(this, b);
return ret;
}
clone_ptr() {
const ret = bindings.SignedRawBolt11Invoice_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the SignedRawBolt11Invoice
*/
clone() {
const ret = bindings.SignedRawBolt11Invoice_clone(this.ptr);
const ret_hu_conv = new SignedRawBolt11Invoice(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Generates a non-cryptographic 64-bit hash of the SignedRawBolt11Invoice.
*/
hash() {
const ret = bindings.SignedRawBolt11Invoice_hash(this.ptr);
return ret;
}
/**
* Disassembles the `SignedRawBolt11Invoice` into its three parts:
* 1. raw invoice
* 2. hash of the raw invoice
* 3. signature
*/
into_parts() {
const ret = bindings.SignedRawBolt11Invoice_into_parts(this.ptr);
const ret_hu_conv = new ThreeTuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* The [`RawBolt11Invoice`] which was signed.
*/
raw_invoice() {
const ret = bindings.SignedRawBolt11Invoice_raw_invoice(this.ptr);
const ret_hu_conv = new RawBolt11Invoice(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* The hash of the [`RawBolt11Invoice`] that was signed.
*/
signable_hash() {
const ret = bindings.SignedRawBolt11Invoice_signable_hash(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
/**
* Signature for the invoice.
*/
signature() {
const ret = bindings.SignedRawBolt11Invoice_signature(this.ptr);
const ret_hu_conv = new Bolt11InvoiceSignature(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Recovers the public key used for signing the invoice from the recoverable signature.
*/
recover_payee_pub_key() {
const ret = bindings.SignedRawBolt11Invoice_recover_payee_pub_key(this.ptr);
const ret_hu_conv = Result_PayeePubKeySecp256k1ErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Checks if the signature is valid for the included payee public key or if none exists if it's
* valid for the recovered signature (which should always be true?).
*/
check_signature() {
const ret = bindings.SignedRawBolt11Invoice_check_signature(this.ptr);
return ret;
}
/**
* Read a SignedRawBolt11Invoice object from a string
*/
static constructor_from_str(s) {
const ret = bindings.SignedRawBolt11Invoice_from_str(bindings.encodeString(s));
const ret_hu_conv = Result_SignedRawBolt11InvoiceBolt11ParseErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Get the string representation of a SignedRawBolt11Invoice object
*/
to_str() {
const ret = bindings.SignedRawBolt11Invoice_to_str(this.ptr);
const ret_conv = bindings.decodeString(ret);
return ret_conv;
}
}
//# sourceMappingURL=SignedRawBolt11Invoice.mjs.map