@tangle-js/anchors
Version:
Anchoring messages to the Tangle. Powered by IOTA Streams
1,531 lines (1,451 loc) • 1.47 MB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var fetch$1 = require('node-fetch');
var require$$1 = require('util');
var require$$2 = require('path');
var require$$3 = require('fs');
var crypto = require('crypto');
var iota_js = require('@iota/iota.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch$1);
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
class AnchoringChannelError extends Error {
constructor(name, message) {
super();
this.type = AnchoringChannelError.ERR_TYPE;
this.name = name;
this.message = message;
}
}
AnchoringChannelError.ERR_TYPE = "AnchoringChannelError";
class AnchoringChannelErrorNames {
}
AnchoringChannelErrorNames.CHANNEL_NOT_BOUND = "Not_Bound";
AnchoringChannelErrorNames.ANCHORAGE_NOT_FOUND = "Anchorage_Not_Found";
AnchoringChannelErrorNames.MSG_NOT_FOUND = "Message_Not_Found";
AnchoringChannelErrorNames.CHANNEL_BINDING_ERROR = "Channel_Binding_Error";
AnchoringChannelErrorNames.CHANNEL_ALREADY_BOUND = "Channel_Already_Bound";
AnchoringChannelErrorNames.OTHER_ERROR = "Runtime_Error";
AnchoringChannelErrorNames.INVALID_NODE = "Invalid_Node";
AnchoringChannelErrorNames.L1_MSG_NOT_FOUND = "Layer1_Message_Not_Found";
AnchoringChannelErrorNames.CHANNEL_BINDING_PERMISSION_ERROR = "Channel_Binding_Permission_Error";
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
var streams$1 = {exports: {}};
(function (module) {
const fetch = fetch__default["default"];
commonjsGlobal.Headers = fetch.Headers;
commonjsGlobal.Request = fetch.Request;
commonjsGlobal.Response = fetch.Response;
commonjsGlobal.fetch = fetch;
let imports = {};
imports['__wbindgen_placeholder__'] = module.exports;
let wasm;
const { TextDecoder, TextEncoder } = require$$1__default["default"];
const heap = new Array(32).fill(undefined);
heap.push(undefined, null, true, false);
function getObject(idx) { return heap[idx]; }
let heap_next = heap.length;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
let cachegetUint8Memory0 = null;
function getUint8Memory0() {
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
}
function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
let WASM_VECTOR_LEN = 0;
let cachedTextEncoder = new TextEncoder('utf-8');
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
}
: function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
});
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length);
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len);
const mem = getUint8Memory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3);
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
offset += ret.written;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
}
function isLikeNone(x) {
return x === undefined || x === null;
}
function debugString(val) {
// primitive types
const type = typeof val;
if (type == 'number' || type == 'boolean' || val == null) {
return `${val}`;
}
if (type == 'string') {
return `"${val}"`;
}
if (type == 'symbol') {
const description = val.description;
if (description == null) {
return 'Symbol';
} else {
return `Symbol(${description})`;
}
}
if (type == 'function') {
const name = val.name;
if (typeof name == 'string' && name.length > 0) {
return `Function(${name})`;
} else {
return 'Function';
}
}
// objects
if (Array.isArray(val)) {
const length = val.length;
let debug = '[';
if (length > 0) {
debug += debugString(val[0]);
}
for(let i = 1; i < length; i++) {
debug += ', ' + debugString(val[i]);
}
debug += ']';
return debug;
}
// Test for built-in
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
let className;
if (builtInMatches.length > 1) {
className = builtInMatches[1];
} else {
// Failed to match the standard '[object ClassName]'
return toString.call(val);
}
if (className == 'Object') {
// we're a user defined class or Object
// JSON.stringify avoids problems with cycles, and is generally much
// easier than looping through ownProperties of `val`.
try {
return 'Object(' + JSON.stringify(val) + ')';
} catch (_) {
return 'Object';
}
}
// errors
if (val instanceof Error) {
return `${val.name}: ${val.message}\n${val.stack}`;
}
// TODO we could test for more things here, like `Set`s and `Map`s.
return className;
}
function makeMutClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const real = (...args) => {
// First up with a closure we increment the internal reference
// count. This ensures that the Rust closure environment won't
// be deallocated while we're invoking it.
state.cnt++;
const a = state.a;
state.a = 0;
try {
return f(a, state.b, ...args);
} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
} else {
state.a = a;
}
}
};
real.original = state;
return real;
}
function __wbg_adapter_34(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h45c87d7cad3bb951(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_37(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd67b012b38ff8c15(arg0, arg1);
}
function _assertClass(instance, klass) {
if (!(instance instanceof klass)) {
throw new Error(`expected instance of ${klass.name}`);
}
return instance.ptr;
}
function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1);
getUint8Memory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
const u32CvtShim = new Uint32Array(2);
const uint64CvtShim = new BigUint64Array(u32CvtShim.buffer);
/**
*/
module.exports.set_panic_hook = function() {
wasm.set_panic_hook();
};
/**
* Initializes the console error panic hook for better error messages
*/
module.exports.start = function() {
wasm.start();
};
function handleError(f, args) {
try {
return f.apply(this, args);
} catch (e) {
wasm.__wbindgen_exn_store(addHeapObject(e));
}
}
function __wbg_adapter_393(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h943e05907d25c2a8(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}
/**
*/
module.exports.ChannelType = Object.freeze({ SingleBranch:0,"0":"SingleBranch",MultiBranch:1,"1":"MultiBranch",SingleDepth:2,"2":"SingleDepth", });
/**
*/
module.exports.LedgerInclusionState = Object.freeze({ Conflicting:0,"0":"Conflicting",Included:1,"1":"Included",NoTransaction:2,"2":"NoTransaction", });
/**
* Tangle representation of a Message Link.
*
* An `Address` is comprised of 2 distinct parts: the channel identifier
* ({@link ChannelAddress}) and the message identifier
* ({@link MsgId}). The channel identifier is unique per channel and is common in the
* `Address` of all messages published in it. The message identifier is
* produced pseudo-randomly out of the the message's sequence number, the
* previous message identifier, and other internal properties.
*/
class Address {
static __wrap(ptr) {
const obj = Object.create(Address.prototype);
obj.ptr = ptr;
return obj;
}
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_address_free(ptr);
}
/**
* @param {ChannelAddress} channel_address
* @param {MsgId} msgid
*/
constructor(channel_address, msgid) {
_assertClass(channel_address, ChannelAddress);
var ptr0 = channel_address.ptr;
channel_address.ptr = 0;
_assertClass(msgid, MsgId);
var ptr1 = msgid.ptr;
msgid.ptr = 0;
const ret = wasm.address_new(ptr0, ptr1);
return Address.__wrap(ret);
}
/**
* @returns {ChannelAddress}
*/
get channelAddress() {
const ret = wasm.address_channelAddress(this.ptr);
return ChannelAddress.__wrap(ret);
}
/**
* @returns {MsgId}
*/
get msgId() {
const ret = wasm.address_msgId(this.ptr);
return MsgId.__wrap(ret);
}
/**
* Generate the hash used to index the {@link Message} published in this address.
*
* Currently this hash is computed with {@link https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2|Blake2b256}.
* The returned Uint8Array contains the binary digest of the hash. To obtain the hexadecimal representation of the
* hash, use the convenience method {@link Address#toMsgIndexHex}.
* @returns {Uint8Array}
*/
toMsgIndex() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.address_toMsgIndex(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var v0 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Generate the hash used to index the {@link Message} published in this address.
*
* Currently this hash is computed with {@link https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2|Blake2b256}.
* The returned String contains the hexadecimal digest of the hash. To obtain the binary digest of the hash,
* use the method {@link Address#toMsgIndex}.
* @returns {string}
*/
toMsgIndexHex() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.address_toMsgIndexHex(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Render the `Address` as a colon-separated String of the hex-encoded {@link Address#channelAddress} and
* {@link Address#msgId} (`<channelAddressHex>:<msgIdHex>`) suitable for exchanging the `Address` between
* participants. To convert the String back to an `Address`, use {@link Address.parse}.
*
* @see Address.parse
* @returns {string}
*/
toString() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.address_toString(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Decode an `Address` out of a String. The String must follow the format used by {@link Address#toString}
*
* @throws Throws an error if String does not follow the format `<channelAddressHex>:<msgIdHex>`
*
* @see Address#toString
* @see ChannelAddress#hex
* @see MsgId#hex
* @param {string} string
* @returns {Address}
*/
static parse(string) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.address_parse(retptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return Address.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @returns {Address}
*/
copy() {
const ret = wasm.address_copy(this.ptr);
return Address.__wrap(ret);
}
}
module.exports.Address = Address;
/**
*/
class AddressGetter {
static __wrap(ptr) {
const obj = Object.create(AddressGetter.prototype);
obj.ptr = ptr;
return obj;
}
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_addressgetter_free(ptr);
}
/**
* @param {Client} client
* @param {string} seed
* @returns {AddressGetter}
*/
static new(client, seed) {
_assertClass(client, Client);
var ptr0 = client.ptr;
client.ptr = 0;
const ptr1 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
const ret = wasm.addressgetter_new(ptr0, ptr1, len1);
return AddressGetter.__wrap(ret);
}
/**
* Set the account index
* @param {number} index
* @returns {AddressGetter}
*/
accountIndex(index) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.addressgetter_accountIndex(retptr, this.ptr, index);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return AddressGetter.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Set the address range
* @param {number} start
* @param {number} end
* @returns {AddressGetter}
*/
range(start, end) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.addressgetter_range(retptr, this.ptr, start, end);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return AddressGetter.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Set the bech32 hrp
* @param {string} bech32_hrp
* @returns {AddressGetter}
*/
bech32Hrp(bech32_hrp) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(bech32_hrp, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.addressgetter_bech32Hrp(retptr, this.ptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return AddressGetter.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Include internal addresses
* @returns {AddressGetter}
*/
includeInternal() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.addressgetter_includeInternal(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return AddressGetter.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Get the addresses.
* @returns {Promise<any>}
*/
get() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.addressgetter_get(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return takeObject(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
}
module.exports.AddressGetter = AddressGetter;
/**
*/
class Author {
static __wrap(ptr) {
const obj = Object.create(Author.prototype);
obj.ptr = ptr;
return obj;
}
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_author_free(ptr);
}
/**
* @param {string} seed
* @param {SendOptions} options
* @param {number} implementation
*/
constructor(seed, options, implementation) {
const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
_assertClass(options, SendOptions);
var ptr1 = options.ptr;
options.ptr = 0;
const ret = wasm.author_new(ptr0, len0, ptr1, implementation);
return Author.__wrap(ret);
}
/**
* @param {StreamsClient} client
* @param {string} seed
* @param {number} implementation
* @returns {Author}
*/
static fromClient(client, seed, implementation) {
_assertClass(client, StreamsClient);
var ptr0 = client.ptr;
client.ptr = 0;
const ptr1 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
const ret = wasm.author_fromClient(ptr0, ptr1, len1, implementation);
return Author.__wrap(ret);
}
/**
* @param {StreamsClient} client
* @param {Uint8Array} bytes
* @param {string} password
* @returns {Author}
*/
static import(client, bytes, password) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
_assertClass(client, StreamsClient);
var ptr0 = client.ptr;
client.ptr = 0;
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len2 = WASM_VECTOR_LEN;
wasm.author_import(retptr, ptr0, ptr1, len1, ptr2, len2);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return Author.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @param {string} password
* @returns {Uint8Array}
*/
export(password) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.author_export(retptr, this.ptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
var r3 = getInt32Memory0()[retptr / 4 + 3];
if (r3) {
throw takeObject(r2);
}
var v1 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @param {string} seed
* @param {Address} ann_address
* @param {number} implementation
* @param {SendOptions} options
* @returns {Promise<Author>}
*/
static recover(seed, ann_address, implementation, options) {
const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
_assertClass(ann_address, Address);
var ptr1 = ann_address.ptr;
ann_address.ptr = 0;
_assertClass(options, SendOptions);
var ptr2 = options.ptr;
options.ptr = 0;
const ret = wasm.author_recover(ptr0, len0, ptr1, implementation, ptr2);
return takeObject(ret);
}
/**
* @returns {Author}
*/
clone() {
const ret = wasm.author_clone(this.ptr);
return Author.__wrap(ret);
}
/**
* @returns {string}
*/
channel_address() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.author_channel_address(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
var r3 = getInt32Memory0()[retptr / 4 + 3];
var ptr0 = r0;
var len0 = r1;
if (r3) {
ptr0 = 0; len0 = 0;
throw takeObject(r2);
}
return getStringFromWasm0(ptr0, len0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(ptr0, len0);
}
}
/**
* @returns {string | undefined}
*/
announcementLink() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.author_announcementLink(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
let v0;
if (r0 !== 0) {
v0 = getStringFromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
}
return v0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @returns {boolean}
*/
is_multi_branching() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.author_is_multi_branching(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return r0 !== 0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @returns {StreamsClient}
*/
get_client() {
const ret = wasm.author_get_client(this.ptr);
return StreamsClient.__wrap(ret);
}
/**
* @param {string} psk_seed_str
* @returns {string}
*/
store_psk(psk_seed_str) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(psk_seed_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.author_store_psk(retptr, this.ptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
var r3 = getInt32Memory0()[retptr / 4 + 3];
var ptr1 = r0;
var len1 = r1;
if (r3) {
ptr1 = 0; len1 = 0;
throw takeObject(r2);
}
return getStringFromWasm0(ptr1, len1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(ptr1, len1);
}
}
/**
* @returns {string}
*/
get_public_key() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.author_get_public_key(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
var r3 = getInt32Memory0()[retptr / 4 + 3];
var ptr0 = r0;
var len0 = r1;
if (r3) {
ptr0 = 0; len0 = 0;
throw takeObject(r2);
}
return getStringFromWasm0(ptr0, len0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(ptr0, len0);
}
}
/**
* @returns {Promise<UserResponse>}
*/
send_announce() {
const ptr = this.__destroy_into_raw();
const ret = wasm.author_send_announce(ptr);
return takeObject(ret);
}
/**
* @param {Address} link
* @returns {Promise<UserResponse>}
*/
send_keyload_for_everyone(link) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ret = wasm.author_send_keyload_for_everyone(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} link
* @param {PskIds} psk_ids
* @param {PublicKeys} sig_pks
* @returns {Promise<UserResponse>}
*/
send_keyload(link, psk_ids, sig_pks) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
_assertClass(psk_ids, PskIds);
var ptr1 = psk_ids.ptr;
psk_ids.ptr = 0;
_assertClass(sig_pks, PublicKeys);
var ptr2 = sig_pks.ptr;
sig_pks.ptr = 0;
const ret = wasm.author_send_keyload(ptr, ptr0, ptr1, ptr2);
return takeObject(ret);
}
/**
* @param {Address} link
* @param {Uint8Array} public_payload
* @param {Uint8Array} masked_payload
* @returns {Promise<UserResponse>}
*/
send_tagged_packet(link, public_payload, masked_payload) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ptr1 = passArray8ToWasm0(public_payload, wasm.__wbindgen_malloc);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passArray8ToWasm0(masked_payload, wasm.__wbindgen_malloc);
const len2 = WASM_VECTOR_LEN;
const ret = wasm.author_send_tagged_packet(ptr, ptr0, ptr1, len1, ptr2, len2);
return takeObject(ret);
}
/**
* @param {Address} link
* @param {Uint8Array} public_payload
* @param {Uint8Array} masked_payload
* @returns {Promise<UserResponse>}
*/
send_signed_packet(link, public_payload, masked_payload) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ptr1 = passArray8ToWasm0(public_payload, wasm.__wbindgen_malloc);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passArray8ToWasm0(masked_payload, wasm.__wbindgen_malloc);
const len2 = WASM_VECTOR_LEN;
const ret = wasm.author_send_signed_packet(ptr, ptr0, ptr1, len1, ptr2, len2);
return takeObject(ret);
}
/**
* @param {Address} link_to
* @returns {Promise<void>}
*/
receive_subscribe(link_to) {
const ptr = this.__destroy_into_raw();
_assertClass(link_to, Address);
var ptr0 = link_to.ptr;
link_to.ptr = 0;
const ret = wasm.author_receive_subscribe(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} link_to
* @returns {Promise<void>}
*/
receive_unsubscribe(link_to) {
const ptr = this.__destroy_into_raw();
_assertClass(link_to, Address);
var ptr0 = link_to.ptr;
link_to.ptr = 0;
const ret = wasm.author_receive_unsubscribe(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} link
* @returns {Promise<UserResponse>}
*/
receive_tagged_packet(link) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ret = wasm.author_receive_tagged_packet(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} link
* @returns {Promise<UserResponse>}
*/
receive_signed_packet(link) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ret = wasm.author_receive_signed_packet(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} link
* @returns {Promise<Address>}
*/
receive_sequence(link) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ret = wasm.author_receive_sequence(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} link
* @returns {Promise<UserResponse>}
*/
receive_msg(link) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ret = wasm.author_receive_msg(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} anchor_link
* @param {number} msg_num
* @returns {Promise<UserResponse>}
*/
receive_msg_by_sequence_number(anchor_link, msg_num) {
const ptr = this.__destroy_into_raw();
_assertClass(anchor_link, Address);
var ptr0 = anchor_link.ptr;
anchor_link.ptr = 0;
const ret = wasm.author_receive_msg_by_sequence_number(ptr, ptr0, msg_num);
return takeObject(ret);
}
/**
* Fetch all the pending messages that the user can read so as to bring the state of the user up to date
*
* This is the main method to bring the user to the latest state of the channel in order to be able to
* publish new messages to it. It makes sure that the messages are processed in topologically order
* (ie parent messages before child messages), ensuring a consistent state regardless of the order of publication.
*
* @returns {number} the amount of messages processed
* @throws Throws error if an error has happened during message retrieval.
* @see {@link Author#fetchNextMsg} for a method that retrieves the immediately next message that the user can read
* @see {@link Author#fetchNextMsgs} for a method that retrieves all pending messages and collects
* them into an Array.
* @returns {Promise<number>}
*/
syncState() {
const ptr = this.__destroy_into_raw();
const ret = wasm.author_syncState(ptr);
return takeObject(ret);
}
/**
* Fetch all the pending messages that the user can read and collect them into an Array
*
* This is the main method to traverse the a channel forward at once. It
* makes sure that the messages in the Array are topologically ordered (ie
* parent messages before child messages), ensuring a consistent state regardless
* of the order of publication.
*
* @returns {UserResponse[]}
* @throws Throws error if an error has happened during message retrieval.
* @see {@link Author#fetchNextMsg} for a method that retrieves the immediately next message that the user can read
* @see {@link Author#syncState} for a method that traverses all pending messages to update the state
* without accumulating them.
* @returns {Promise<Array<any>>}
*/
fetchNextMsgs() {
const ptr = this.__destroy_into_raw();
const ret = wasm.author_fetchNextMsgs(ptr);
return takeObject(ret);
}
/**
* Fetch the immediately next message that the user can read
*
* This is the main method to traverse the a channel forward message by message, as it
* makes sure that no message is returned unless its parent message in the branches tree has already
* been returned, ensuring a consistent state regardless of the order of publication.
*
* Keep in mind that internally this method might have to fetch multiple messages until the correct
* message to be returned is found.
*
* @throws Throws error if an error has happened during message retrieval.
* @see {@link Author#fetchNextMsgs} for a method that retrieves all pending messages and collects
* them into an Array.
* @see {@link Author#syncState} for a method that traverses all pending messages to update the state
* without accumulating them.
* @returns {Promise<UserResponse | undefined>}
*/
fetchNextMsg() {
const ptr = this.__destroy_into_raw();
const ret = wasm.author_fetchNextMsg(ptr);
return takeObject(ret);
}
/**
* @param {Address} link
* @returns {Promise<UserResponse>}
*/
fetch_prev_msg(link) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ret = wasm.author_fetch_prev_msg(ptr, ptr0);
return takeObject(ret);
}
/**
* @param {Address} link
* @param {number} num_msgs
* @returns {Promise<Array<any>>}
*/
fetch_prev_msgs(link, num_msgs) {
const ptr = this.__destroy_into_raw();
_assertClass(link, Address);
var ptr0 = link.ptr;
link.ptr = 0;
const ret = wasm.author_fetch_prev_msgs(ptr, ptr0, num_msgs);
return takeObject(ret);
}
/**
* Generate the next batch of message {@link Address} to poll
*
* Given the set of users registered as participants of the channel and their current registered
* sequencing position, this method generates a set of new {@link Address} to poll for new messages
* (one for each user, represented by its identifier). However, beware that it is not recommended to
* use this method as a means to implement message traversal, as there's no guarantee that the addresses
* returned are the immediately next addresses to be processed. use {@link Author#fetchNextMsg} instead.
*
* Keep in mind that in multi-branch channels, the link returned corresponds to the next sequence message.
*
* @see Author#fetchNextMsg
* @see Author#fetchNextMsgs
* @returns {NextMsgAddress[]}
* @returns {Array<any>}
*/
genNextMsgAddresses() {
const ret = wasm.author_genNextMsgAddresses(this.ptr);
return takeObject(ret);
}
/**
* @returns {Array<any>}
*/
fetch_state() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.author_fetch_state(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return takeObject(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
*/
reset_state() {
try {
const ptr = this.__destroy_into_raw();
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.author_reset_state(retptr, ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @param {string} pk_str
*/
store_new_subscriber(pk_str) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(pk_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.author_store_new_subscriber(retptr, this.ptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @param {string} pk_str
*/
remove_subscriber(pk_str) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(pk_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.author_remove_subscriber(retptr, this.ptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @param {string} pskid_str
*/
remove_psk(pskid_str) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(pskid_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.author_remove_psk(retptr, this.ptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
}
module.exports.Author = Author;
/**
*/
class BalanceGetter {
static __wrap(ptr) {
const obj = Object.create(BalanceGetter.prototype);
obj.ptr = ptr;
return obj;
}
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_balancegetter_free(ptr);
}
/**
* @param {Client} client
* @param {string} seed
* @returns {BalanceGetter}
*/
static new(client, seed) {
_assertClass(client, Client);
var ptr0 = client.ptr;
client.ptr = 0;
const ptr1 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
const ret = wasm.balancegetter_new(ptr0, ptr1, len1);
return BalanceGetter.__wrap(ret);
}
/**
* Sets the account index
* @param {number} index
* @returns {BalanceGetter}
*/
accountIndex(index) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.balancegetter_accountIndex(retptr, this.ptr, index);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return BalanceGetter.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Sets the address index from which to start looking for balance
* @param {number} initial_address_index
* @returns {BalanceGetter}
*/
initialAddressIndex(initial_address_index) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.balancegetter_initialAddressIndex(retptr, this.ptr, initial_address_index);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return BalanceGetter.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Sets the gap limit to specify how many addresses will be checked each round.
* If gap_limit amount of addresses in a row have no balance the function will return.
* @param {number} gap_limit
* @returns {BalanceGetter}
*/
gap_limit(gap_limit) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.balancegetter_gap_limit(retptr, this.ptr, gap_limit);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return BalanceGetter.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Get the balance.
* @returns {Promise<any>}
*/
get() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.balancegetter_get(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return takeObject(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
}
module.exports.BalanceGetter = BalanceGetter;
/**
* Channel application instance identifier (40 Byte)
*/
class ChannelAddress {
static __wrap(ptr) {
const obj = Object.create(ChannelAddress.prototype);
obj.ptr = ptr;
return obj;
}
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_channeladdress_free(ptr);
}
/**
* Render the `ChannelAddress` as a 40 Byte {@link https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array|Uint8Array}
*
* @see ChannelAddress#hex
* @returns {Uint8Array}
*/
bytes() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.channeladdress_bytes(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var v0 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Render the `ChannelAddress` as a 40 Byte (80 char) hexadecimal String
*
* @see ChannelAddress#bytes
* @returns {string}
*/
hex() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.channeladdress_hex(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Render the `ChannelAddress` as an exchangeable String. Currently
* outputs the same as {@link ChannelAddress#hex}.
*
* @see ChannelAddress#hex
* @see ChannelAddress.parse
* @returns {string}
*/
toString() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.channeladdress_toString(retptr, this.ptr);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Decode a `ChannelAddress` out of a String. The string must be a 80 char long hexadecimal string.
*
* @see ChannelAddress#toString
* @throws Throws error if string does not follow the expected format
* @param {string} string
* @returns {ChannelAddress}
*/
static parse(string) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.channeladdress_parse(retptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return ChannelAddress.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @returns {ChannelAddress}
*/
copy() {
const ret = wasm.address_channelAddress(this.ptr);
return ChannelAddress.__wrap(ret);
}
}
module.exports.ChannelAddress = ChannelAddress;
/**
*/
class Client {
static __wrap(ptr) {
const obj = Object.create(Client.prototype);
obj.ptr = ptr;
return obj;
}
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_client_free(ptr);
}
/**
* Send a message to the Tangle.
* @returns {MessageBuilder}
*/
message() {
const ret = wasm.client_message(this.ptr);
return MessageBuilder.__wrap(ret);
}
/**
* Get a message from the Tangle.
* @returns {MessageGetter}
*/
getMessage() {
const ret = wasm.client_getAddress(this.ptr);
return MessageGetter.__wrap(ret);
}
/**
* Generate addresses.
* @param {string} seed
* @returns {AddressGetter}
*/
getAddresses(seed) {
const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.client_getAddresses(this.ptr, ptr0, len0);
return AddressGetter.__wrap(ret);
}
/**
* Get an unspent address.
* @param {string} seed
* @returns {UnspentAddressGetter}
*/
getUnspentAddress(seed) {
const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.client_getUnspentAddress(this.ptr, ptr0, len0);
return UnspentAddressGetter.__wrap(ret);
}
/**
* Get the account balance.
* @param {string} seed
* @returns {BalanceGetter}
*/
getBalance(seed) {
const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc