2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class NetAddress extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.NetAddress_free(this.ptr); }
11 static constr_from_ptr(ptr: number): NetAddress {
12 const raw_val: bindings.LDKNetAddress = bindings.LDKNetAddress_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKNetAddress.IPv4) {
14 return new IPv4(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKNetAddress.IPv6) {
17 return new IPv6(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKNetAddress.OnionV2) {
20 return new OnionV2(this.ptr, raw_val);
22 if (raw_val instanceof bindings.LDKNetAddress.OnionV3) {
23 return new OnionV3(this.ptr, raw_val);
25 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
29 export class IPv4 extends NetAddress {
30 public addr: Uint8Array;
32 private constructor(ptr: number, obj: bindings.LDKNetAddress.IPv4) {
38 export class IPv6 extends NetAddress {
39 public addr: Uint8Array;
41 private constructor(ptr: number, obj: bindings.LDKNetAddress.IPv6) {
47 export class OnionV2 extends NetAddress {
48 public addr: Uint8Array;
50 private constructor(ptr: number, obj: bindings.LDKNetAddress.OnionV2) {
56 export class OnionV3 extends NetAddress {
57 public ed25519_pubkey: Uint8Array;
58 public checksum: number;
59 public version: number;
61 private constructor(ptr: number, obj: bindings.LDKNetAddress.OnionV3) {
63 this.ed25519_pubkey = obj.ed25519_pubkey;
64 this.checksum = obj.checksum;
65 this.version = obj.version;