3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export class KeysInterface extends CommonBase {
10 bindings_instance?: bindings.LDKKeysInterface;
12 constructor(ptr?: number, arg?: bindings.LDKKeysInterface) {
13 if (Number.isFinite(ptr)) {
15 this.bindings_instance = null;
17 // TODO: private constructor instantiation
18 super(bindings.LDKKeysInterface_new(arg));
19 this.ptrs_to.push(arg);
24 protected finalize() {
26 bindings.KeysInterface_free(this.ptr);
31 static new_impl(arg: KeysInterfaceInterface): KeysInterface {
32 const impl_holder: LDKKeysInterfaceHolder = new LDKKeysInterfaceHolder();
33 let structImplementation = <bindings.LDKKeysInterface>{
34 // todo: in-line interface filling
35 get_node_secret (): Uint8Array {
36 Uint8Array ret = arg.get_node_secret();
40 get_destination_script (): Uint8Array {
41 Uint8Array ret = arg.get_destination_script();
45 get_shutdown_scriptpubkey (): number {
46 ShutdownScript ret = arg.get_shutdown_scriptpubkey();
47 result: number = ret == null ? 0 : ret.ptr & ~1;
51 get_channel_signer (inbound: boolean, channel_value_satoshis: number): number {
52 Sign ret = arg.get_channel_signer(inbound, channel_value_satoshis);
53 result: number = ret == null ? 0 : ret.ptr;
54 impl_holder.held.ptrs_to.add(ret);
58 get_secure_random_bytes (): Uint8Array {
59 Uint8Array ret = arg.get_secure_random_bytes();
63 read_chan_signer (reader: Uint8Array): number {
64 Result_SignDecodeErrorZ ret = arg.read_chan_signer(reader);
65 result: number = ret != null ? ret.ptr : 0;
69 sign_invoice (invoice_preimage: Uint8Array): number {
70 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(invoice_preimage);
71 result: number = ret != null ? ret.ptr : 0;
77 impl_holder.held = new KeysInterface (null, structImplementation);
81 export interface KeysInterfaceInterface {
82 get_node_secret(): Uint8Array;
83 get_destination_script(): Uint8Array;
84 get_shutdown_scriptpubkey(): ShutdownScript;
85 get_channel_signer(inbound: boolean, channel_value_satoshis: number): Sign;
86 get_secure_random_bytes(): Uint8Array;
87 read_chan_signer(reader: Uint8Array): Result_SignDecodeErrorZ;
88 sign_invoice(invoice_preimage: Uint8Array): Result_RecoverableSignatureNoneZ;
92 class LDKKeysInterfaceHolder {
95 public Uint8Array get_node_secret() {
96 Uint8Array ret = bindings.KeysInterface_get_node_secret(this.ptr);
100 public Uint8Array get_destination_script() {
101 Uint8Array ret = bindings.KeysInterface_get_destination_script(this.ptr);
105 public ShutdownScript get_shutdown_scriptpubkey() {
106 number ret = bindings.KeysInterface_get_shutdown_scriptpubkey(this.ptr);
107 const ret_hu_conv: ShutdownScript = new ShutdownScript(null, ret);
108 ret_hu_conv.ptrs_to.add(this);
112 public Sign get_channel_signer(boolean inbound, number channel_value_satoshis) {
113 number ret = bindings.KeysInterface_get_channel_signer(this.ptr, inbound, channel_value_satoshis);
114 Sign ret_hu_conv = new Sign(null, ret);
115 ret_hu_conv.ptrs_to.add(this);
119 public Uint8Array get_secure_random_bytes() {
120 Uint8Array ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
124 public Result_SignDecodeErrorZ read_chan_signer(Uint8Array reader) {
125 number ret = bindings.KeysInterface_read_chan_signer(this.ptr, reader);
126 Result_SignDecodeErrorZ ret_hu_conv = Result_SignDecodeErrorZ.constr_from_ptr(ret);
130 public Result_RecoverableSignatureNoneZ sign_invoice(Uint8Array invoice_preimage) {
131 number ret = bindings.KeysInterface_sign_invoice(this.ptr, invoice_preimage);
132 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);