@xchainjs/xchain-thorchain
Version:
Custom Thorchain client and utilities used by XChainJS clients
1,206 lines (1,120 loc) • 168 kB
JavaScript
import { EnglishMnemonic, Bip39, Slip10, Slip10Curve, Secp256k1 } from '@cosmjs/crypto';
import { toBase64, fromBase64 } from '@cosmjs/encoding';
import { decodeTxRaw, DirectSecp256k1HdWallet, encodePubkey, makeAuthInfoBytes } from '@cosmjs/proto-signing';
import { SigningStargateClient, AminoTypes } from '@cosmjs/stargate';
import { Client as Client$1, MsgTypes, bech32ToBase64, makeClientPath, base64ToBech32 } from '@xchainjs/xchain-cosmos-sdk';
import { getSeed } from '@xchainjs/xchain-crypto';
import { bech32 } from '@scure/base';
import BigNumber from 'bignumber.js';
import { HDKey } from '@scure/bip32';
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
import { createHash } from 'crypto';
import * as secp from '@bitcoin-js/tiny-secp256k1-asmjs';
import { isSynthAsset, assetToString, isSecuredAsset, AssetType, assetToBase, assetAmount, eqAsset, assetFromString, assetFromStringEx } from '@xchainjs/xchain-util';
import { Network } from '@xchainjs/xchain-client';
import * as minimal from 'protobufjs/minimal.js';
import { Uint53 } from '@cosmjs/math';
import axios from 'axios';
import THORChainApp, { extractSignatureFromTLV } from '@xchainjs/ledger-thorchain';
import { SignMode } from 'cosmjs-types/cosmos/tx/signing/v1beta1/signing.js';
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function getAugmentedNamespace(n) {
if (n.__esModule) return n;
var f = n.default;
if (typeof f == "function") {
var a = function a () {
if (this instanceof a) {
return Reflect.construct(f, arguments, this.constructor);
}
return f.apply(this, arguments);
};
a.prototype = f.prototype;
} else a = {};
Object.defineProperty(a, '__esModule', {value: true});
Object.keys(n).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(n, k);
Object.defineProperty(a, k, d.get ? d : {
enumerable: true,
get: function () {
return n[k];
}
});
});
return a;
}
var require$$0 = /*@__PURE__*/getAugmentedNamespace(minimal);
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
var MsgCompiled;
var hasRequiredMsgCompiled;
function requireMsgCompiled () {
if (hasRequiredMsgCompiled) return MsgCompiled;
hasRequiredMsgCompiled = 1;
var $protobuf = require$$0;
// Common aliases
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
// Exported root namespace
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
$root.common = (function() {
/**
* Namespace common.
* @exports common
* @namespace
*/
var common = {};
common.Asset = (function() {
/**
* Properties of an Asset.
* @memberof common
* @interface IAsset
* @property {string|null} [chain] Asset chain
* @property {string|null} [symbol] Asset symbol
* @property {string|null} [ticker] Asset ticker
* @property {boolean|null} [synth] Asset synth
* @property {boolean|null} [trade] Asset trade
* @property {boolean|null} [secured] Asset secured
*/
/**
* Constructs a new Asset.
* @memberof common
* @classdesc Represents an Asset.
* @implements IAsset
* @constructor
* @param {common.IAsset=} [properties] Properties to set
*/
function Asset(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* Asset chain.
* @member {string} chain
* @memberof common.Asset
* @instance
*/
Asset.prototype.chain = "";
/**
* Asset symbol.
* @member {string} symbol
* @memberof common.Asset
* @instance
*/
Asset.prototype.symbol = "";
/**
* Asset ticker.
* @member {string} ticker
* @memberof common.Asset
* @instance
*/
Asset.prototype.ticker = "";
/**
* Asset synth.
* @member {boolean} synth
* @memberof common.Asset
* @instance
*/
Asset.prototype.synth = false;
/**
* Asset trade.
* @member {boolean} trade
* @memberof common.Asset
* @instance
*/
Asset.prototype.trade = false;
/**
* Asset secured.
* @member {boolean} secured
* @memberof common.Asset
* @instance
*/
Asset.prototype.secured = false;
/**
* Creates a new Asset instance using the specified properties.
* @function create
* @memberof common.Asset
* @static
* @param {common.IAsset=} [properties] Properties to set
* @returns {common.Asset} Asset instance
*/
Asset.create = function create(properties) {
return new Asset(properties);
};
/**
* Encodes the specified Asset message. Does not implicitly {@link common.Asset.verify|verify} messages.
* @function encode
* @memberof common.Asset
* @static
* @param {common.IAsset} message Asset message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Asset.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.chain != null && Object.hasOwnProperty.call(message, "chain"))
writer.uint32(/* id 1, wireType 2 =*/10).string(message.chain);
if (message.symbol != null && Object.hasOwnProperty.call(message, "symbol"))
writer.uint32(/* id 2, wireType 2 =*/18).string(message.symbol);
if (message.ticker != null && Object.hasOwnProperty.call(message, "ticker"))
writer.uint32(/* id 3, wireType 2 =*/26).string(message.ticker);
if (message.synth != null && Object.hasOwnProperty.call(message, "synth"))
writer.uint32(/* id 4, wireType 0 =*/32).bool(message.synth);
if (message.trade != null && Object.hasOwnProperty.call(message, "trade"))
writer.uint32(/* id 5, wireType 0 =*/40).bool(message.trade);
if (message.secured != null && Object.hasOwnProperty.call(message, "secured"))
writer.uint32(/* id 6, wireType 0 =*/48).bool(message.secured);
return writer;
};
/**
* Encodes the specified Asset message, length delimited. Does not implicitly {@link common.Asset.verify|verify} messages.
* @function encodeDelimited
* @memberof common.Asset
* @static
* @param {common.IAsset} message Asset message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Asset.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes an Asset message from the specified reader or buffer.
* @function decode
* @memberof common.Asset
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.Asset} Asset
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Asset.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.Asset();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.chain = reader.string();
break;
case 2:
message.symbol = reader.string();
break;
case 3:
message.ticker = reader.string();
break;
case 4:
message.synth = reader.bool();
break;
case 5:
message.trade = reader.bool();
break;
case 6:
message.secured = reader.bool();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes an Asset message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.Asset
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.Asset} Asset
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Asset.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies an Asset message.
* @function verify
* @memberof common.Asset
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Asset.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.chain != null && message.hasOwnProperty("chain"))
if (!$util.isString(message.chain))
return "chain: string expected";
if (message.symbol != null && message.hasOwnProperty("symbol"))
if (!$util.isString(message.symbol))
return "symbol: string expected";
if (message.ticker != null && message.hasOwnProperty("ticker"))
if (!$util.isString(message.ticker))
return "ticker: string expected";
if (message.synth != null && message.hasOwnProperty("synth"))
if (typeof message.synth !== "boolean")
return "synth: boolean expected";
if (message.trade != null && message.hasOwnProperty("trade"))
if (typeof message.trade !== "boolean")
return "trade: boolean expected";
if (message.secured != null && message.hasOwnProperty("secured"))
if (typeof message.secured !== "boolean")
return "secured: boolean expected";
return null;
};
/**
* Creates an Asset message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.Asset
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.Asset} Asset
*/
Asset.fromObject = function fromObject(object) {
if (object instanceof $root.common.Asset)
return object;
var message = new $root.common.Asset();
if (object.chain != null)
message.chain = String(object.chain);
if (object.symbol != null)
message.symbol = String(object.symbol);
if (object.ticker != null)
message.ticker = String(object.ticker);
if (object.synth != null)
message.synth = Boolean(object.synth);
if (object.trade != null)
message.trade = Boolean(object.trade);
if (object.secured != null)
message.secured = Boolean(object.secured);
return message;
};
/**
* Creates a plain object from an Asset message. Also converts values to other types if specified.
* @function toObject
* @memberof common.Asset
* @static
* @param {common.Asset} message Asset
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Asset.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.defaults) {
object.chain = "";
object.symbol = "";
object.ticker = "";
object.synth = false;
object.trade = false;
object.secured = false;
}
if (message.chain != null && message.hasOwnProperty("chain"))
object.chain = message.chain;
if (message.symbol != null && message.hasOwnProperty("symbol"))
object.symbol = message.symbol;
if (message.ticker != null && message.hasOwnProperty("ticker"))
object.ticker = message.ticker;
if (message.synth != null && message.hasOwnProperty("synth"))
object.synth = message.synth;
if (message.trade != null && message.hasOwnProperty("trade"))
object.trade = message.trade;
if (message.secured != null && message.hasOwnProperty("secured"))
object.secured = message.secured;
return object;
};
/**
* Converts this Asset to JSON.
* @function toJSON
* @memberof common.Asset
* @instance
* @returns {Object.<string,*>} JSON object
*/
Asset.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
return Asset;
})();
common.Coin = (function() {
/**
* Properties of a Coin.
* @memberof common
* @interface ICoin
* @property {common.IAsset|null} [asset] Coin asset
* @property {string|null} [amount] Coin amount
* @property {number|Long|null} [decimals] Coin decimals
*/
/**
* Constructs a new Coin.
* @memberof common
* @classdesc Represents a Coin.
* @implements ICoin
* @constructor
* @param {common.ICoin=} [properties] Properties to set
*/
function Coin(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* Coin asset.
* @member {common.IAsset|null|undefined} asset
* @memberof common.Coin
* @instance
*/
Coin.prototype.asset = null;
/**
* Coin amount.
* @member {string} amount
* @memberof common.Coin
* @instance
*/
Coin.prototype.amount = "";
/**
* Coin decimals.
* @member {number|Long} decimals
* @memberof common.Coin
* @instance
*/
Coin.prototype.decimals = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
/**
* Creates a new Coin instance using the specified properties.
* @function create
* @memberof common.Coin
* @static
* @param {common.ICoin=} [properties] Properties to set
* @returns {common.Coin} Coin instance
*/
Coin.create = function create(properties) {
return new Coin(properties);
};
/**
* Encodes the specified Coin message. Does not implicitly {@link common.Coin.verify|verify} messages.
* @function encode
* @memberof common.Coin
* @static
* @param {common.ICoin} message Coin message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Coin.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.asset != null && Object.hasOwnProperty.call(message, "asset"))
$root.common.Asset.encode(message.asset, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim();
if (message.amount != null && Object.hasOwnProperty.call(message, "amount"))
writer.uint32(/* id 2, wireType 2 =*/18).string(message.amount);
if (message.decimals != null && Object.hasOwnProperty.call(message, "decimals"))
writer.uint32(/* id 3, wireType 0 =*/24).int64(message.decimals);
return writer;
};
/**
* Encodes the specified Coin message, length delimited. Does not implicitly {@link common.Coin.verify|verify} messages.
* @function encodeDelimited
* @memberof common.Coin
* @static
* @param {common.ICoin} message Coin message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Coin.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Coin message from the specified reader or buffer.
* @function decode
* @memberof common.Coin
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.Coin} Coin
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Coin.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.Coin();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.asset = $root.common.Asset.decode(reader, reader.uint32());
break;
case 2:
message.amount = reader.string();
break;
case 3:
message.decimals = reader.int64();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Coin message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.Coin
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.Coin} Coin
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Coin.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Coin message.
* @function verify
* @memberof common.Coin
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Coin.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.asset != null && message.hasOwnProperty("asset")) {
var error = $root.common.Asset.verify(message.asset);
if (error)
return "asset." + error;
}
if (message.amount != null && message.hasOwnProperty("amount"))
if (!$util.isString(message.amount))
return "amount: string expected";
if (message.decimals != null && message.hasOwnProperty("decimals"))
if (!$util.isInteger(message.decimals) && !(message.decimals && $util.isInteger(message.decimals.low) && $util.isInteger(message.decimals.high)))
return "decimals: integer|Long expected";
return null;
};
/**
* Creates a Coin message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.Coin
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.Coin} Coin
*/
Coin.fromObject = function fromObject(object) {
if (object instanceof $root.common.Coin)
return object;
var message = new $root.common.Coin();
if (object.asset != null) {
if (typeof object.asset !== "object")
throw TypeError(".common.Coin.asset: object expected");
message.asset = $root.common.Asset.fromObject(object.asset);
}
if (object.amount != null)
message.amount = String(object.amount);
if (object.decimals != null)
if ($util.Long)
(message.decimals = $util.Long.fromValue(object.decimals)).unsigned = false;
else if (typeof object.decimals === "string")
message.decimals = parseInt(object.decimals, 10);
else if (typeof object.decimals === "number")
message.decimals = object.decimals;
else if (typeof object.decimals === "object")
message.decimals = new $util.LongBits(object.decimals.low >>> 0, object.decimals.high >>> 0).toNumber();
return message;
};
/**
* Creates a plain object from a Coin message. Also converts values to other types if specified.
* @function toObject
* @memberof common.Coin
* @static
* @param {common.Coin} message Coin
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Coin.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.defaults) {
object.asset = null;
object.amount = "";
if ($util.Long) {
var long = new $util.Long(0, 0, false);
object.decimals = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
} else
object.decimals = options.longs === String ? "0" : 0;
}
if (message.asset != null && message.hasOwnProperty("asset"))
object.asset = $root.common.Asset.toObject(message.asset, options);
if (message.amount != null && message.hasOwnProperty("amount"))
object.amount = message.amount;
if (message.decimals != null && message.hasOwnProperty("decimals"))
if (typeof message.decimals === "number")
object.decimals = options.longs === String ? String(message.decimals) : message.decimals;
else
object.decimals = options.longs === String ? $util.Long.prototype.toString.call(message.decimals) : options.longs === Number ? new $util.LongBits(message.decimals.low >>> 0, message.decimals.high >>> 0).toNumber() : message.decimals;
return object;
};
/**
* Converts this Coin to JSON.
* @function toJSON
* @memberof common.Coin
* @instance
* @returns {Object.<string,*>} JSON object
*/
Coin.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
return Coin;
})();
common.PubKeySet = (function() {
/**
* Properties of a PubKeySet.
* @memberof common
* @interface IPubKeySet
* @property {string|null} [secp256k1] PubKeySet secp256k1
* @property {string|null} [ed25519] PubKeySet ed25519
*/
/**
* Constructs a new PubKeySet.
* @memberof common
* @classdesc Represents a PubKeySet.
* @implements IPubKeySet
* @constructor
* @param {common.IPubKeySet=} [properties] Properties to set
*/
function PubKeySet(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* PubKeySet secp256k1.
* @member {string} secp256k1
* @memberof common.PubKeySet
* @instance
*/
PubKeySet.prototype.secp256k1 = "";
/**
* PubKeySet ed25519.
* @member {string} ed25519
* @memberof common.PubKeySet
* @instance
*/
PubKeySet.prototype.ed25519 = "";
/**
* Creates a new PubKeySet instance using the specified properties.
* @function create
* @memberof common.PubKeySet
* @static
* @param {common.IPubKeySet=} [properties] Properties to set
* @returns {common.PubKeySet} PubKeySet instance
*/
PubKeySet.create = function create(properties) {
return new PubKeySet(properties);
};
/**
* Encodes the specified PubKeySet message. Does not implicitly {@link common.PubKeySet.verify|verify} messages.
* @function encode
* @memberof common.PubKeySet
* @static
* @param {common.IPubKeySet} message PubKeySet message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
PubKeySet.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.secp256k1 != null && Object.hasOwnProperty.call(message, "secp256k1"))
writer.uint32(/* id 1, wireType 2 =*/10).string(message.secp256k1);
if (message.ed25519 != null && Object.hasOwnProperty.call(message, "ed25519"))
writer.uint32(/* id 2, wireType 2 =*/18).string(message.ed25519);
return writer;
};
/**
* Encodes the specified PubKeySet message, length delimited. Does not implicitly {@link common.PubKeySet.verify|verify} messages.
* @function encodeDelimited
* @memberof common.PubKeySet
* @static
* @param {common.IPubKeySet} message PubKeySet message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
PubKeySet.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a PubKeySet message from the specified reader or buffer.
* @function decode
* @memberof common.PubKeySet
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.PubKeySet} PubKeySet
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
PubKeySet.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.PubKeySet();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.secp256k1 = reader.string();
break;
case 2:
message.ed25519 = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a PubKeySet message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.PubKeySet
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.PubKeySet} PubKeySet
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
PubKeySet.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a PubKeySet message.
* @function verify
* @memberof common.PubKeySet
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
PubKeySet.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.secp256k1 != null && message.hasOwnProperty("secp256k1"))
if (!$util.isString(message.secp256k1))
return "secp256k1: string expected";
if (message.ed25519 != null && message.hasOwnProperty("ed25519"))
if (!$util.isString(message.ed25519))
return "ed25519: string expected";
return null;
};
/**
* Creates a PubKeySet message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.PubKeySet
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.PubKeySet} PubKeySet
*/
PubKeySet.fromObject = function fromObject(object) {
if (object instanceof $root.common.PubKeySet)
return object;
var message = new $root.common.PubKeySet();
if (object.secp256k1 != null)
message.secp256k1 = String(object.secp256k1);
if (object.ed25519 != null)
message.ed25519 = String(object.ed25519);
return message;
};
/**
* Creates a plain object from a PubKeySet message. Also converts values to other types if specified.
* @function toObject
* @memberof common.PubKeySet
* @static
* @param {common.PubKeySet} message PubKeySet
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
PubKeySet.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.defaults) {
object.secp256k1 = "";
object.ed25519 = "";
}
if (message.secp256k1 != null && message.hasOwnProperty("secp256k1"))
object.secp256k1 = message.secp256k1;
if (message.ed25519 != null && message.hasOwnProperty("ed25519"))
object.ed25519 = message.ed25519;
return object;
};
/**
* Converts this PubKeySet to JSON.
* @function toJSON
* @memberof common.PubKeySet
* @instance
* @returns {Object.<string,*>} JSON object
*/
PubKeySet.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
return PubKeySet;
})();
common.Tx = (function() {
/**
* Properties of a Tx.
* @memberof common
* @interface ITx
* @property {string|null} [id] Tx id
* @property {string|null} [chain] Tx chain
* @property {string|null} [fromAddress] Tx fromAddress
* @property {string|null} [toAddress] Tx toAddress
* @property {Array.<common.ICoin>|null} [coins] Tx coins
* @property {Array.<common.ICoin>|null} [gas] Tx gas
* @property {string|null} [memo] Tx memo
*/
/**
* Constructs a new Tx.
* @memberof common
* @classdesc Represents a Tx.
* @implements ITx
* @constructor
* @param {common.ITx=} [properties] Properties to set
*/
function Tx(properties) {
this.coins = [];
this.gas = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* Tx id.
* @member {string} id
* @memberof common.Tx
* @instance
*/
Tx.prototype.id = "";
/**
* Tx chain.
* @member {string} chain
* @memberof common.Tx
* @instance
*/
Tx.prototype.chain = "";
/**
* Tx fromAddress.
* @member {string} fromAddress
* @memberof common.Tx
* @instance
*/
Tx.prototype.fromAddress = "";
/**
* Tx toAddress.
* @member {string} toAddress
* @memberof common.Tx
* @instance
*/
Tx.prototype.toAddress = "";
/**
* Tx coins.
* @member {Array.<common.ICoin>} coins
* @memberof common.Tx
* @instance
*/
Tx.prototype.coins = $util.emptyArray;
/**
* Tx gas.
* @member {Array.<common.ICoin>} gas
* @memberof common.Tx
* @instance
*/
Tx.prototype.gas = $util.emptyArray;
/**
* Tx memo.
* @member {string} memo
* @memberof common.Tx
* @instance
*/
Tx.prototype.memo = "";
/**
* Creates a new Tx instance using the specified properties.
* @function create
* @memberof common.Tx
* @static
* @param {common.ITx=} [properties] Properties to set
* @returns {common.Tx} Tx instance
*/
Tx.create = function create(properties) {
return new Tx(properties);
};
/**
* Encodes the specified Tx message. Does not implicitly {@link common.Tx.verify|verify} messages.
* @function encode
* @memberof common.Tx
* @static
* @param {common.ITx} message Tx message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Tx.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.id != null && Object.hasOwnProperty.call(message, "id"))
writer.uint32(/* id 1, wireType 2 =*/10).string(message.id);
if (message.chain != null && Object.hasOwnProperty.call(message, "chain"))
writer.uint32(/* id 2, wireType 2 =*/18).string(message.chain);
if (message.fromAddress != null && Object.hasOwnProperty.call(message, "fromAddress"))
writer.uint32(/* id 3, wireType 2 =*/26).string(message.fromAddress);
if (message.toAddress != null && Object.hasOwnProperty.call(message, "toAddress"))
writer.uint32(/* id 4, wireType 2 =*/34).string(message.toAddress);
if (message.coins != null && message.coins.length)
for (var i = 0; i < message.coins.length; ++i)
$root.common.Coin.encode(message.coins[i], writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim();
if (message.gas != null && message.gas.length)
for (var i = 0; i < message.gas.length; ++i)
$root.common.Coin.encode(message.gas[i], writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim();
if (message.memo != null && Object.hasOwnProperty.call(message, "memo"))
writer.uint32(/* id 7, wireType 2 =*/58).string(message.memo);
return writer;
};
/**
* Encodes the specified Tx message, length delimited. Does not implicitly {@link common.Tx.verify|verify} messages.
* @function encodeDelimited
* @memberof common.Tx
* @static
* @param {common.ITx} message Tx message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Tx.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Tx message from the specified reader or buffer.
* @function decode
* @memberof common.Tx
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.Tx} Tx
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Tx.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.Tx();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.id = reader.string();
break;
case 2:
message.chain = reader.string();
break;
case 3:
message.fromAddress = reader.string();
break;
case 4:
message.toAddress = reader.string();
break;
case 5:
if (!(message.coins && message.coins.length))
message.coins = [];
message.coins.push($root.common.Coin.decode(reader, reader.uint32()));
break;
case 6:
if (!(message.gas && message.gas.length))
message.gas = [];
message.gas.push($root.common.Coin.decode(reader, reader.uint32()));
break;
case 7:
message.memo = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Tx message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.Tx
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.Tx} Tx
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Tx.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Tx message.
* @function verify
* @memberof common.Tx
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Tx.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.id != null && message.hasOwnProperty("id"))
if (!$util.isString(message.id))
return "id: string expected";
if (message.chain != null && message.hasOwnProperty("chain"))
if (!$util.isString(message.chain))
return "chain: string expected";
if (message.fromAddress != null && message.hasOwnProperty("fromAddress"))
if (!$util.isString(message.fromAddress))
return "fromAddress: string expected";
if (message.toAddress != null && message.hasOwnProperty("toAddress"))
if (!$util.isString(message.toAddress))
return "toAddress: string expected";
if (message.coins != null && message.hasOwnProperty("coins")) {
if (!Array.isArray(message.coins))
return "coins: array expected";
for (var i = 0; i < message.coins.length; ++i) {
var error = $root.common.Coin.verify(message.coins[i]);
if (error)
return "coins." + error;
}
}
if (message.gas != null && message.hasOwnProperty("gas")) {
if (!Array.isArray(message.gas))
return "gas: array expected";
for (var i = 0; i < message.gas.length; ++i) {
var error = $root.common.Coin.verify(message.gas[i]);
if (error)
return "gas." + error;
}
}
if (message.memo != null && message.hasOwnProperty("memo"))
if (!$util.isString(message.memo))
return "memo: string expected";
return null;
};
/**
* Creates a Tx message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.Tx
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.Tx} Tx
*/
Tx.fromObject = function fromObject(object) {
if (object instanceof $root.common.Tx)
return object;
var message = new $root.common.Tx();
if (object.id != null)
message.id = String(object.id);
if (object.chain != null)
message.chain = String(object.chain);
if (object.fromAddress != null)
message.fromAddress = String(object.fromAddress);
if (object.toAddress != null)
message.toAddress = String(object.toAddress);
if (object.coins) {
if (!Array.isArray(object.coins))
throw TypeError(".common.Tx.coins: array expected");
message.coins = [];
for (var i = 0; i < object.coins.length; ++i) {
if (typeof object.coins[i] !== "object")
throw TypeError(".common.Tx.coins: object expected");
message.coins[i] = $root.common.Coin.fromObject(object.coins[i]);
}
}
if (object.gas) {
if (!Array.isArray(object.gas))
throw TypeError(".common.Tx.gas: array expected");
message.gas = [];
for (var i = 0; i < object.gas.length; ++i) {
if (typeof object.gas[i] !== "object")
throw TypeError(".common.Tx.gas: object expected");
message.gas[i] = $root.common.Coin.fromObject(object.gas[i]);
}
}
if (object.memo != null)
message.memo = String(object.memo);
return message;
};
/**
* Creates a plain object from a Tx message. Also converts values to other types if specified.
* @function toObject
* @memberof common.Tx
* @static
* @param {common.Tx} message Tx
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Tx.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.arrays || options.defaults) {
object.coins = [];
object.gas = [];
}
if (options.defaults) {
object.id = "";
object.chain = "";
object.fromAddress = "";
object.toAddress = "";
object.memo = "";
}
if (message.id != null && message.hasOwnProperty("id"))
object.id = message.id;
if (message.chain != null && message.hasOwnProperty("chain"))
object.chain = message.chain;
if (message.fromAddress != null && message.hasOwnProperty("fromAddress"))
object.fromAddress = message.fromAddress;
if (message.toAddress != null && message.hasOwnProperty("toAddress"))
object.toAddress = message.toAddress;
if (message.coins && message.coins.length) {
object.coins = [];