3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export class ChannelKeys extends CommonBase {
10 bindings_instance?: bindings.LDKChannelKeys;
12 constructor(ptr?: number, arg?: bindings.LDKChannelKeys, pubkeys?: ChannelPublicKeys) {
13 if (Number.isFinite(ptr)) {
15 this.bindings_instance = null;
17 // TODO: private constructor instantiation
18 super(bindings.LDKChannelKeys_new(arg, pubkeys == null ? 0 : pubkeys.ptr & ~1));
19 this.ptrs_to.push(arg);
20 this.ptrs_to.add(pubkeys);
25 protected finalize() {
27 bindings.ChannelKeys_free(this.ptr);
32 static new_impl(arg: ChannelKeysInterface, pubkeys: ChannelPublicKeys): ChannelKeys {
33 const impl_holder: LDKChannelKeysHolder = new LDKChannelKeysHolder();
34 let structImplementation = <bindings.LDKChannelKeys>{
35 // todo: in-line interface filling
36 get_per_commitment_point (idx: number): Uint8Array {
37 Uint8Array ret = arg.get_per_commitment_point(idx);
41 release_commitment_secret (idx: number): Uint8Array {
42 Uint8Array ret = arg.release_commitment_secret(idx);
46 key_derivation_params (): number {
47 TwoTuple<Number, Number> ret = arg.key_derivation_params();
48 result: number = bindings.C2Tuple_u64u64Z_new(ret.a, ret.b);
52 sign_counterparty_commitment (commitment_tx: number): number {
53 const commitment_tx_hu_conv: CommitmentTransaction = new CommitmentTransaction(null, commitment_tx);
54 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(commitment_tx_hu_conv);
55 result: number = ret != null ? ret.ptr : 0;
59 sign_holder_commitment_and_htlcs (commitment_tx: number): number {
60 const commitment_tx_hu_conv: HolderCommitmentTransaction = new HolderCommitmentTransaction(null, commitment_tx);
61 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_holder_commitment_and_htlcs(commitment_tx_hu_conv);
62 result: number = ret != null ? ret.ptr : 0;
66 sign_justice_transaction (justice_tx: Uint8Array, input: number, amount: number, per_commitment_key: Uint8Array, htlc: number): number {
67 const htlc_hu_conv: HTLCOutputInCommitment = new HTLCOutputInCommitment(null, htlc);
68 Result_SignatureNoneZ ret = arg.sign_justice_transaction(justice_tx, input, amount, per_commitment_key, htlc_hu_conv);
69 result: number = ret != null ? ret.ptr : 0;
73 sign_counterparty_htlc_transaction (htlc_tx: Uint8Array, input: number, amount: number, per_commitment_point: Uint8Array, htlc: number): number {
74 const htlc_hu_conv: HTLCOutputInCommitment = new HTLCOutputInCommitment(null, htlc);
75 Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc_hu_conv);
76 result: number = ret != null ? ret.ptr : 0;
80 sign_closing_transaction (closing_tx: Uint8Array): number {
81 Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx);
82 result: number = ret != null ? ret.ptr : 0;
86 sign_channel_announcement (msg: number): number {
87 const msg_hu_conv: UnsignedChannelAnnouncement = new UnsignedChannelAnnouncement(null, msg);
88 Result_SignatureNoneZ ret = arg.sign_channel_announcement(msg_hu_conv);
89 result: number = ret != null ? ret.ptr : 0;
93 ready_channel (channel_parameters: number): void {
94 const channel_parameters_hu_conv: ChannelTransactionParameters = new ChannelTransactionParameters(null, channel_parameters);
95 arg.ready_channel(channel_parameters_hu_conv);
98 write (): Uint8Array {
99 Uint8Array ret = arg.write();
105 impl_holder.held = new ChannelKeys (null, structImplementation, pubkeys);
109 export interface ChannelKeysInterface {
110 get_per_commitment_point(idx: number): Uint8Array;
111 release_commitment_secret(idx: number): Uint8Array;
112 key_derivation_params(): TwoTuple<Number, Number>;
113 sign_counterparty_commitment(commitment_tx: CommitmentTransaction): Result_C2Tuple_SignatureCVec_SignatureZZNoneZ;
114 sign_holder_commitment_and_htlcs(commitment_tx: HolderCommitmentTransaction): Result_C2Tuple_SignatureCVec_SignatureZZNoneZ;
115 sign_justice_transaction(justice_tx: Uint8Array, input: number, amount: number, per_commitment_key: Uint8Array, htlc: HTLCOutputInCommitment): Result_SignatureNoneZ;
116 sign_counterparty_htlc_transaction(htlc_tx: Uint8Array, input: number, amount: number, per_commitment_point: Uint8Array, htlc: HTLCOutputInCommitment): Result_SignatureNoneZ;
117 sign_closing_transaction(closing_tx: Uint8Array): Result_SignatureNoneZ;
118 sign_channel_announcement(msg: UnsignedChannelAnnouncement): Result_SignatureNoneZ;
119 ready_channel(channel_parameters: ChannelTransactionParameters): void;
124 class LDKChannelKeysHolder {
127 public Uint8Array get_per_commitment_point(number idx) {
128 Uint8Array ret = bindings.ChannelKeys_get_per_commitment_point(this.ptr, idx);
132 public Uint8Array release_commitment_secret(number idx) {
133 Uint8Array ret = bindings.ChannelKeys_release_commitment_secret(this.ptr, idx);
137 public TwoTuple<Number, Number> key_derivation_params() {
138 number ret = bindings.ChannelKeys_key_derivation_params(this.ptr);
139 number ret_a = bindings.LDKC2Tuple_u64u64Z_get_a(ret);
140 number ret_b = bindings.LDKC2Tuple_u64u64Z_get_b(ret);
141 TwoTuple<Number, Number> ret_conv = new TwoTuple<Number, Number>(ret_a, ret_b, () -> {
142 bindings.C2Tuple_u64u64Z_free(ret);
147 public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx) {
148 number ret = bindings.ChannelKeys_sign_counterparty_commitment(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1);
149 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
150 this.ptrs_to.add(commitment_tx);
154 public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction commitment_tx) {
155 number ret = bindings.ChannelKeys_sign_holder_commitment_and_htlcs(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1);
156 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
157 this.ptrs_to.add(commitment_tx);
161 public Result_SignatureNoneZ sign_justice_transaction(Uint8Array justice_tx, number input, number amount, Uint8Array per_commitment_key, HTLCOutputInCommitment htlc) {
162 number ret = bindings.ChannelKeys_sign_justice_transaction(this.ptr, justice_tx, input, amount, per_commitment_key, htlc == null ? 0 : htlc.ptr & ~1);
163 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
164 this.ptrs_to.add(htlc);
168 public Result_SignatureNoneZ sign_counterparty_htlc_transaction(Uint8Array htlc_tx, number input, number amount, Uint8Array per_commitment_point, HTLCOutputInCommitment htlc) {
169 number ret = bindings.ChannelKeys_sign_counterparty_htlc_transaction(this.ptr, htlc_tx, input, amount, per_commitment_point, htlc == null ? 0 : htlc.ptr & ~1);
170 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
171 this.ptrs_to.add(htlc);
175 public Result_SignatureNoneZ sign_closing_transaction(Uint8Array closing_tx) {
176 number ret = bindings.ChannelKeys_sign_closing_transaction(this.ptr, closing_tx);
177 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
181 public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) {
182 number ret = bindings.ChannelKeys_sign_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
183 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
184 this.ptrs_to.add(msg);
188 public void ready_channel(ChannelTransactionParameters channel_parameters) {
189 bindings.ChannelKeys_ready_channel(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr & ~1);
190 this.ptrs_to.add(channel_parameters);
193 public Uint8Array write() {
194 Uint8Array ret = bindings.ChannelKeys_write(this.ptr);
198 public ChannelPublicKeys get_pubkeys() {
199 number ret = bindings.ChannelKeys_get_pubkeys(this.ptr);
200 const ret_hu_conv: ChannelPublicKeys = new ChannelPublicKeys(null, ret);
201 ret_hu_conv.ptrs_to.add(this);
205 public ChannelKeys clone() {
206 number ret = bindings.ChannelKeys_clone(this.ptr);
207 ChannelKeys ret_hu_conv = new ChannelKeys(null, ret);
208 ret_hu_conv.ptrs_to.add(this);