X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FErrorMessage.mts;h=1b0098436135ed8cde9b114f24c479f7eac81acc;hp=5b7f460011acd4495f86c6d00e094c8e3270a688;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=2a65456aa0b540060dcf3ca707a54dc98cc3f38a diff --git a/ts/structs/ErrorMessage.mts b/ts/structs/ErrorMessage.mts index 5b7f4600..1b009843 100644 --- a/ts/structs/ErrorMessage.mts +++ b/ts/structs/ErrorMessage.mts @@ -279,35 +279,60 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** + * An error message to be sent or received from a peer + */ export class ErrorMessage extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { super(ptr, bindings.ErrorMessage_free); } + /** + * The channel ID involved in the error + */ public get_channel_id(): Uint8Array { - const ret: Uint8Array = bindings.ErrorMessage_get_channel_id(this.ptr); - return ret; + const ret: number = bindings.ErrorMessage_get_channel_id(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } + /** + * The channel ID involved in the error + */ public set_channel_id(val: Uint8Array): void { - bindings.ErrorMessage_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32)); + bindings.ErrorMessage_set_channel_id(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(val, 32))); } - public get_data(): String { - const ret: String = bindings.ErrorMessage_get_data(this.ptr); - return ret; + /** + * A possibly human-readable error description. + * The string should be sanitized before it is used (e.g. emitted to logs + * or printed to stdout). Otherwise, a well crafted error message may trigger a security + * vulnerability in the terminal emulator or the logging subsystem. + */ + public get_data(): string { + const ret: number = bindings.ErrorMessage_get_data(this.ptr); + const ret_conv: string = bindings.decodeString(ret); + return ret_conv; } - public set_data(val: String): void { - bindings.ErrorMessage_set_data(this.ptr, val); + /** + * A possibly human-readable error description. + * The string should be sanitized before it is used (e.g. emitted to logs + * or printed to stdout). Otherwise, a well crafted error message may trigger a security + * vulnerability in the terminal emulator or the logging subsystem. + */ + public set_data(val: string): void { + bindings.ErrorMessage_set_data(this.ptr, bindings.encodeString(val)); } - public static constructor_new(channel_id_arg: Uint8Array, data_arg: String): ErrorMessage { - const ret: number = bindings.ErrorMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg); + /** + * Constructs a new ErrorMessage given each field + */ + public static constructor_new(channel_id_arg: Uint8Array, data_arg: string): ErrorMessage { + const ret: number = bindings.ErrorMessage_new(bindings.encodeUint8Array(bindings.check_arr_len(channel_id_arg, 32)), bindings.encodeString(data_arg)); const ret_hu_conv: ErrorMessage = new ErrorMessage(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; @@ -318,6 +343,9 @@ export class ErrorMessage extends CommonBase { return ret; } + /** + * Creates a copy of the ErrorMessage + */ public clone(): ErrorMessage { const ret: number = bindings.ErrorMessage_clone(this.ptr); const ret_hu_conv: ErrorMessage = new ErrorMessage(null, ret); @@ -325,13 +353,20 @@ export class ErrorMessage extends CommonBase { return ret_hu_conv; } + /** + * Serialize the ErrorMessage object into a byte array which can be read by ErrorMessage_read + */ public write(): Uint8Array { - const ret: Uint8Array = bindings.ErrorMessage_write(this.ptr); - return ret; + const ret: number = bindings.ErrorMessage_write(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } + /** + * Read a ErrorMessage from a byte array, created by ErrorMessage_write + */ public static constructor_read(ser: Uint8Array): Result_ErrorMessageDecodeErrorZ { - const ret: number = bindings.ErrorMessage_read(ser); + const ret: number = bindings.ErrorMessage_read(bindings.encodeUint8Array(ser)); const ret_hu_conv: Result_ErrorMessageDecodeErrorZ = Result_ErrorMessageDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; }