X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FSign.mts;h=1b7765c311fcc75ffb8b8771d2264bfe78d8f1dd;hb=0fcde6be16ac8c2d63bd5398d5396da5890461d7;hp=32683e6667b5e31969d9b25749827baafd79636c;hpb=bf08029c1ad5244b59902eada723b634dcade62d;p=ldk-java diff --git a/ts/structs/Sign.mts b/ts/structs/Sign.mts index 32683e66..1b7765c3 100644 --- a/ts/structs/Sign.mts +++ b/ts/structs/Sign.mts @@ -280,11 +280,13 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** An implementation of Sign */ export interface SignInterface { + /**Serialize the object into a byte array + */ write(): Uint8Array; } @@ -292,6 +294,13 @@ class LDKSignHolder { held: Sign; } +/** + * A cloneable signer. + * + * Although we require signers to be cloneable, it may be useful for developers to be able to use + * signers in an un-sized way, for example as `dyn BaseSign`. Therefore we separate the Clone trait, + * which implies Sized, into this derived trait. + */ export class Sign extends CommonBase { /* @internal */ public bindings_instance?: bindings.LDKSign; @@ -302,12 +311,14 @@ export class Sign extends CommonBase { this.bindings_instance = null; } - static new_impl(arg: SignInterface, baseSign_impl: BaseSignInterface, pubkeys: ChannelPublicKeys): Sign { + /** Creates a new instance of Sign from a given implementation */ + public static new_impl(arg: SignInterface, baseSign_impl: BaseSignInterface, pubkeys: ChannelPublicKeys): Sign { const impl_holder: LDKSignHolder = new LDKSignHolder(); let structImplementation = { - write (): Uint8Array { + write (): number { const ret: Uint8Array = arg.write(); - return ret; + const result: number = bindings.encodeUint8Array(ret); + return result; }, } as bindings.LDKSign; const baseSign = BaseSign.new_impl(baseSign_impl, pubkeys, ); @@ -318,9 +329,14 @@ export class Sign extends CommonBase { impl_holder.held.ptrs_to.push(baseSign); return impl_holder.held; } + + /** + * Serialize the object into a byte array + */ public write(): Uint8Array { - const ret: Uint8Array = bindings.Sign_write(this.ptr); - return ret; + const ret: number = bindings.Sign_write(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } public clone_ptr(): number { @@ -328,6 +344,9 @@ export class Sign extends CommonBase { return ret; } + /** + * Creates a copy of a Sign + */ public clone(): Sign { const ret: number = bindings.Sign_clone(this.ptr); const ret_hu_conv: Sign = new Sign(null, ret);