X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FShutdownScript.mts;h=79688cf9a09b4a7db07da2e52ed569dfeedae7d1;hp=1de2c8a1c236952ae7b4f9d26d57fd1458fc88b3;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=d1d0121c000b713c10fd0bedd249eb8dda2e4db7 diff --git a/ts/structs/ShutdownScript.mts b/ts/structs/ShutdownScript.mts index 1de2c8a1..79688cf9 100644 --- a/ts/structs/ShutdownScript.mts +++ b/ts/structs/ShutdownScript.mts @@ -281,6 +281,11 @@ import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' +/** + * A script pubkey for shutting down a channel as defined by [BOLT #2]. + * + * [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md + */ export class ShutdownScript extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { @@ -292,6 +297,9 @@ export class ShutdownScript extends CommonBase { return ret; } + /** + * Creates a copy of the ShutdownScript + */ public clone(): ShutdownScript { const ret: number = bindings.ShutdownScript_clone(this.ptr); const ret_hu_conv: ShutdownScript = new ShutdownScript(null, ret); @@ -299,18 +307,27 @@ export class ShutdownScript extends CommonBase { return ret_hu_conv; } + /** + * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read + */ public write(): Uint8Array { const ret: number = bindings.ShutdownScript_write(this.ptr); const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); return ret_conv; } + /** + * Read a ShutdownScript from a byte array, created by ShutdownScript_write + */ public static constructor_read(ser: Uint8Array): Result_ShutdownScriptDecodeErrorZ { const ret: number = bindings.ShutdownScript_read(bindings.encodeUint8Array(ser)); const ret_hu_conv: Result_ShutdownScriptDecodeErrorZ = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } + /** + * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`]. + */ public static constructor_new_p2wpkh(pubkey_hash: Uint8Array): ShutdownScript { const ret: number = bindings.ShutdownScript_new_p2wpkh(bindings.encodeUint8Array(bindings.check_arr_len(pubkey_hash, 20))); const ret_hu_conv: ShutdownScript = new ShutdownScript(null, ret); @@ -318,6 +335,9 @@ export class ShutdownScript extends CommonBase { return ret_hu_conv; } + /** + * Generates a P2WSH script pubkey from the given [`WScriptHash`]. + */ public static constructor_new_p2wsh(script_hash: Uint8Array): ShutdownScript { const ret: number = bindings.ShutdownScript_new_p2wsh(bindings.encodeUint8Array(bindings.check_arr_len(script_hash, 32))); const ret_hu_conv: ShutdownScript = new ShutdownScript(null, ret); @@ -325,24 +345,47 @@ export class ShutdownScript extends CommonBase { return ret_hu_conv; } + /** + * Generates a witness script pubkey from the given segwit version and program. + * + * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or + * [`ShutdownScript::new_p2wsh`] instead. + * + * # Errors + * + * This function may return an error if `program` is invalid for the segwit `version`. + */ public static constructor_new_witness_program(version: number, program: Uint8Array): Result_ShutdownScriptInvalidShutdownScriptZ { const ret: number = bindings.ShutdownScript_new_witness_program(version, bindings.encodeUint8Array(program)); const ret_hu_conv: Result_ShutdownScriptInvalidShutdownScriptZ = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret); return ret_hu_conv; } + /** + * Converts the shutdown script into the underlying [`Script`]. + */ public into_inner(): Uint8Array { const ret: number = bindings.ShutdownScript_into_inner(this.ptr); const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); return ret_conv; } + /** + * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ public as_legacy_pubkey(): Uint8Array { const ret: number = bindings.ShutdownScript_as_legacy_pubkey(this.ptr); const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); return ret_conv; } + /** + * Returns whether the shutdown script is compatible with the features as defined by BOLT #2. + * + * Specifically, checks for compliance with feature `option_shutdown_anysegwit`. + */ public is_compatible(features: InitFeatures): boolean { const ret: boolean = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : CommonBase.get_ptr_of(features) & ~1); CommonBase.add_ref_from(this, features);