UNPKG

@pokt-network/pocket-js

Version:

Pocket-js core package with the main functionalities to interact with the Pocket Network.

58 lines 5.7 MB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.PocketJS = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ window.Buffer=require("buffer/").Buffer,module.exports=require("./dist/index.js"),window.cryptoLib=require("crypto"); },{"./dist/index.js":4,"buffer/":262,"crypto":272}],2:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Configuration=void 0;var Configuration=function(){function e(e,s,i,t,o,n,r,u,a,c,d){if(void 0===e&&(e=50),void 0===s&&(s=0),void 0===i&&(i=0),void 0===t&&(t=0),void 0===o&&(o=!1),void 0===n&&(n=25),void 0===r&&(r=6e4),void 0===u&&(u=1),void 0===a&&(a=!0),void 0===c&&(c=!0),void 0===d&&(d=!1),this.maxDispatchers=50,this.maxSessions=0,this.consensusNodeCount=0,this.requestTimeOut=0,this.acceptDisputedResponses=!1,this.sessionBlockFrequency=4,this.blockTime=9e5,this.maxSessionRefreshRetries=1,this.validateRelayResponses=!0,this.rejectSelfSignedCertificates=!0,this.useLegacyTxCodec=!1,this.maxDispatchers=e,this.maxSessions=s,i%2!=1&&0!==i)throw new Error("Failed to instantiate a Configuration class object due to consensusNodeCount not being an odd number.");this.consensusNodeCount=i,this.requestTimeOut=t,this.acceptDisputedResponses=o,this.sessionBlockFrequency=n,this.blockTime=r,this.maxSessionRefreshRetries=u,this.validateRelayResponses=a,this.rejectSelfSignedCertificates=c,this.useLegacyTxCodec=d}return e.prototype.setconsensusNodeCount=function(e){this.consensusNodeCount=e},e}();exports.Configuration=Configuration; },{}],3:[function(require,module,exports){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||t.hasOwnProperty(r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./configuration"),exports); },{"./configuration":2}],4:[function(require,module,exports){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t),Object.defineProperty(e,o,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||r.hasOwnProperty(t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./config"),exports),__exportStar(require("./keybase"),exports),__exportStar(require("./routing-table"),exports),__exportStar(require("./rpc"),exports),__exportStar(require("./session"),exports),__exportStar(require("./storage"),exports),__exportStar(require("./transactions"),exports),__exportStar(require("./utils"),exports),__exportStar(require("./pocket"),exports); },{"./config":3,"./keybase":5,"./pocket":10,"./routing-table":11,"./rpc":15,"./session":96,"./storage":100,"./transactions":109,"./utils":143}],5:[function(require,module,exports){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||t.hasOwnProperty(r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./models"),exports),__exportStar(require("./keybase"),exports); },{"./keybase":6,"./models":8}],6:[function(require,module,exports){ (function (Buffer){(function (){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__awaiter=this&&this.__awaiter||function(e,t,r,n){function o(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function u(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){e.done?r(e.value):o(e.value).then(a,u)}s((n=n.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(e,t){function r(e){return function(t){return n([e,t])}}function n(r){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,i&&(a=2&r[0]?i.return:r[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,r[1])).done)return a;switch(i=0,a&&(r=[2&r[0],a.value]),r[0]){case 0:case 1:a=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(a=s.trys,!(a=a.length>0&&a[a.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!a||r[1]>a[0]&&r[1]<a[3])){s.label=r[1];break}if(6===r[0]&&s.label<a[1]){s.label=a[1],a=r;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(r);break}a[2]&&s.ops.pop(),s.trys.pop();continue}r=t.call(e,s)}catch(e){r=[6,e],i=0}finally{o=a=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}var o,i,a,u,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return u={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Keybase=void 0;var account_1=require("./models/account"),libsodium_wrappers_1=__importDefault(require("libsodium-wrappers")),unlocked_account_1=require("./models/unlocked-account"),pbkdf2_1=__importDefault(require("pbkdf2")),js_sha256_1=require("js-sha256"),aes_js_1=__importDefault(require("aes-js")),type_guard_1=require("../utils/type-guard"),key_pair_1=require("../utils/key-pair"),__1=require(".."),cryptoLib=__importStar(require("crypto")),scrypt_js_1=__importDefault(require("scrypt-js")),Keybase=function(){function e(e){this.ACCOUNT_STORE_PREFIX="account_",this.ACCOUNT_INDEX_KEY="account_index",this.store=e,this.unlockedAccounts={}}return e.signWith=function(e,t){return __awaiter(this,void 0,void 0,function(){var r;return __generator(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,libsodium_wrappers_1.default.ready];case 1:return n.sent(),[2,Buffer.from(libsodium_wrappers_1.default.crypto_sign_detached(t,e))];case 2:return r=n.sent(),[2,r];case 3:return[2]}})})},e.prototype.createAccount=function(e){return __awaiter(this,void 0,void 0,function(){var t,r;return __generator(this,function(n){switch(n.label){case 0:if(0===e.length)return[2,new Error("Empty passphrase")];n.label=1;case 1:return n.trys.push([1,4,,5]),[4,libsodium_wrappers_1.default.ready];case 2:return n.sent(),t=libsodium_wrappers_1.default.crypto_sign_keypair(),[4,this.importAccount(Buffer.from(t.privateKey),e)];case 3:return[2,n.sent()];case 4:return r=n.sent(),[2,r];case 5:return[2]}})})},e.prototype.listAccounts=function(){return __awaiter(this,void 0,void 0,function(){var e,t,r,n,o,i,a;return __generator(this,function(u){switch(u.label){case 0:if(e=new Array,t=this.store.get(this.ACCOUNT_INDEX_KEY),type_guard_1.typeGuard(t,Array))t=t;else{if(void 0!==t)return[2,new Error("Error fetching account index")];t=[]}r=[];for(n in t)r.push(n);o=0,u.label=1;case 1:return o<r.length?(i=r[o],[4,this.getAccount(t[i])]):[3,4];case 2:if(a=u.sent(),!type_guard_1.typeGuard(a,account_1.Account))return[2,a];e.push(a),u.label=3;case 3:return o++,[3,1];case 4:return[2,e]}})})},e.prototype.getAccount=function(e){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(t){return[2,this.getAccountFromStore(e)]})})},e.prototype.getUnlockedAccount=function(e,t){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(r){return[2,this.unlockAccountFromPersistence(e,t)]})})},e.prototype.deleteAccount=function(e,t){return __awaiter(this,void 0,void 0,function(){var r,n,o,i;return __generator(this,function(a){switch(a.label){case 0:return r=key_pair_1.validateAddressHex(e),r?[2,r]:[4,this.unlockAccountFromPersistence(e,t)];case 1:return o=a.sent(),type_guard_1.typeGuard(o,unlocked_account_1.UnlockedAccount)?(i=o,[2,this.removeAccountRecord(i)]):(n=type_guard_1.typeGuard(o,Error)?o:new Error("Unknown error decrypting Account"),[2,n])}})})},e.prototype.updateAccountPassphrase=function(e,t,r){return __awaiter(this,void 0,void 0,function(){var n,o,i,a,u,s;return __generator(this,function(c){switch(c.label){case 0:return n=key_pair_1.validateAddressHex(e),n?[2,n]:[4,this.unlockAccountFromPersistence(e,t)];case 1:return i=c.sent(),type_guard_1.typeGuard(i,unlocked_account_1.UnlockedAccount)?(a=i,[4,this.removeAccountRecord(a)]):[3,3];case 2:return u=c.sent(),type_guard_1.typeGuard(u,Error)?o=u:(s=this.importAccount(a.privateKey,r),type_guard_1.typeGuard(s,Error)&&(o=s)),[3,4];case 3:o=type_guard_1.typeGuard(i,Error)?i:new Error("Unknown error decrypting Account"),c.label=4;case 4:return[2,o]}})})},e.prototype.sign=function(e,t,r){return __awaiter(this,void 0,void 0,function(){var n,o,i;return __generator(this,function(a){switch(a.label){case 0:return[4,this.unlockAccountFromPersistence(e,t)];case 1:if(n=a.sent(),type_guard_1.typeGuard(n,Error))return[2,n];o=n,a.label=2;case 2:return a.trys.push([2,4,,5]),[4,libsodium_wrappers_1.default.ready];case 3:return a.sent(),[2,Buffer.from(libsodium_wrappers_1.default.crypto_sign_detached(r,o.privateKey))];case 4:return i=a.sent(),[2,i];case 5:return[2]}})})},e.prototype.signWithUnlockedAccount=function(e,t){return __awaiter(this,void 0,void 0,function(){var r,n,o,i;return __generator(this,function(a){switch(a.label){case 0:return r=key_pair_1.validateAddressHex(e),r?[2,r]:[4,this.isUnlocked(e)];case 1:if(!(n=a.sent()))return[2,new Error("Account is not unlocked")];a.label=2;case 2:return a.trys.push([2,4,,5]),o=this.unlockedAccounts[e],[4,libsodium_wrappers_1.default.ready];case 3:return a.sent(),[2,Buffer.from(libsodium_wrappers_1.default.crypto_sign_detached(t,o.privateKey))];case 4:return i=a.sent(),[2,i];case 5:return[2]}})})},e.prototype.verifySignature=function(e,t,r){return __awaiter(this,void 0,void 0,function(){var n;return __generator(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,libsodium_wrappers_1.default.ready];case 1:return o.sent(),[2,libsodium_wrappers_1.default.crypto_sign_verify_detached(r,t,e)];case 2:return n=o.sent(),[2,!1];case 3:return[2]}})})},e.prototype.unlockAccount=function(e,t,r){return void 0===r&&(r=6e5),__awaiter(this,void 0,void 0,function(){var n,o;return __generator(this,function(i){switch(i.label){case 0:return[4,this.unlockAccountFromPersistence(e,t)];case 1:return n=i.sent(),type_guard_1.typeGuard(n,Error)?[2,n]:(r>0&&setTimeout(function(e,t){e.lockAccount(t)},r,this,e),o=n,this.unlockedAccounts[o.addressHex]=o,[2,void 0])}})})},e.prototype.lockAccount=function(e){return __awaiter(this,void 0,void 0,function(){var t,r;return __generator(this,function(n){switch(n.label){case 0:return t=key_pair_1.validateAddressHex(e),t?[2,t]:[4,this.isUnlocked(e)];case 1:return(r=n.sent())?(delete this.unlockedAccounts[e],[2,void 0]):[2,new Error("Account is not unlocked")]}})})},e.prototype.isUnlocked=function(e){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(t){return[2,!!this.unlockedAccounts[e]]})})},e.prototype.importAccount=function(e,t){return __awaiter(this,void 0,void 0,function(){var r,n,o,i,a,u;return __generator(this,function(s){switch(s.label){case 0:if(0===t.length)return[2,new Error("Empty passphrase")];if(!key_pair_1.validatePrivateKey(e))return[2,new Error("Invalid private key")];s.label=1;case 1:return s.trys.push([1,3,,4]),r=key_pair_1.publicKeyFromPrivate(e),n=pbkdf2_1.default.pbkdf2Sync(t,js_sha256_1.sha256(t),1,32),o=aes_js_1.default.utils.hex.fromBytes(new aes_js_1.default.ModeOfOperation.ctr(n,void 0).encrypt(e)),i=new account_1.Account(r,o),[4,this.persistAccount(i)];case 2:return a=s.sent(),type_guard_1.typeGuard(a,Error)?[2,a]:[2,i];case 3:return u=s.sent(),[2,u];case 4:return[2]}})})},e.prototype.exportAccount=function(e,t){return __awaiter(this,void 0,void 0,function(){var r,n;return __generator(this,function(o){switch(o.label){case 0:return[4,this.unlockAccountFromPersistence(e,t)];case 1:return r=o.sent(),type_guard_1.typeGuard(r,Error)?[2,r]:(n=r,[2,n.privateKey])}})})},e.prototype.exportPPKfromAccount=function(e,t,r,n){return void 0===r&&(r=""),__awaiter(this,void 0,void 0,function(){var o,i;return __generator(this,function(a){switch(a.label){case 0:return t.length<=0||n.length<=0?[2,new Error("Wrong password or passphrase format, please try again with valid information.")]:[4,this.getUnlockedAccount(e,n)];case 1:return o=a.sent(),type_guard_1.typeGuard(o,Error)?[3,3]:[4,this.exportPPK(o.privateKey.toString("hex"),t,r)];case 2:return i=a.sent(),[2,i];case 3:return[2,o]}})})},e.prototype.exportPPK=function(e,t,r){return void 0===r&&(r=""),__awaiter(this,void 0,void 0,function(){var n,o,i,a,u,s,c,_,d,p,f;return __generator(this,function(l){switch(l.label){case 0:if(e.length<=0||t.length<=0)return[2,new Error("Invalid export PPK properties, please try again with valid information.")];n=32,o={N:32768,r:8,p:1,maxmem:4294967290},i=12,a="aes-256-gcm",l.label=1;case 1:return l.trys.push([1,5,,6]),[4,cryptoLib.randomBytes(16)];case 2:return u=l.sent(),[4,scrypt_js_1.default.syncScrypt(Buffer.from(t,"utf8"),u,o.N,o.r,o.p,n)];case 3:return s=l.sent(),c=Buffer.from(s),_=Buffer.allocUnsafe(i),c.copy(_,0,0,i),[4,cryptoLib.createCipheriv(a,c,_)];case 4:return d=l.sent(),p=d.update(e,"utf8","hex"),p+=d.final("hex"),p+=d.getAuthTag().toString("hex"),[2,JSON.stringify({kdf:"scrypt",salt:u.toString("hex"),secparam:i.toString(),hint:r,ciphertext:Buffer.from(p,"hex").toString("base64")})];case 5:return f=l.sent(),[2,f];case 6:return[2]}})})},e.prototype.importPPK=function(e,t,r,n,o,i){return void 0===r&&(r=12),void 0===n&&(n=""),__awaiter(this,void 0,void 0,function(){var a,u,s;return __generator(this,function(c){switch(c.label){case 0:return a="scrypt",0!==e.length&&0!==i.length?[3,1]:[2,new Error("The password or passphrase is invalid.")];case 1:return u=JSON.stringify({kdf:a,salt:t,secparam:r,hint:n,ciphertext:o}),this.validatePPKJSON(u)?[4,this.importPPKFromJSON(e,u,i)]:[2,new Error("Failed to validate the ppk information, please try again with valid information.")];case 2:return s=c.sent(),[2,s]}})})},e.prototype.importPPKFromJSON=function(e,t,r){return __awaiter(this,void 0,void 0,function(){var n,o,i,a,u,s,c,_,d,p,f,l,h,y,v;return __generator(this,function(g){switch(g.label){case 0:if(0===e.length||!this.validatePPKJSON(t)||0===r.length)return[2,new Error("One or more parameters are empty strings.")];g.label=1;case 1:return g.trys.push([1,4,,5]),n=JSON.parse(t),o=32,i=Number(n.secparam),a=16,u="aes-256-gcm",s={N:32768,r:8,p:1,maxmem:4294967290},c=Buffer.from(n.salt,"hex"),[4,scrypt_js_1.default.syncScrypt(Buffer.from(e,"utf8"),c,s.N,s.r,s.p,o)];case 2:return _=g.sent(),d=Buffer.from(n.ciphertext,"base64"),p=_.slice(0,i),f=d.slice(d.length-a),l=d.slice(0,d.length-a),h=cryptoLib.createDecipheriv(u,Buffer.from(_),p),h.setAuthTag(f),y=h.update(l,void 0,"utf8"),y+=h.final("utf8"),[4,this.importAccount(Buffer.from(y,"hex"),r)];case 3:return[2,g.sent()];case 4:return v=g.sent(),[2,v];case 5:return[2]}})})},e.prototype.unlockAccountFromPersistence=function(e,t){return __awaiter(this,void 0,void 0,function(){var r,n,o,i,a,u,s,c,_,d;return __generator(this,function(p){switch(p.label){case 0:return r=key_pair_1.validateAddressHex(e),r?[2,r]:[4,this.getAccount(e)];case 1:if(o=p.sent(),type_guard_1.typeGuard(o,account_1.Account)){i=o;try{return a=pbkdf2_1.default.pbkdf2Sync(t,js_sha256_1.sha256(t),1,32),(u=aes_js_1.default.utils.hex.toBytes(i.encryptedPrivateKeyHex),s=aes_js_1.default.utils.hex.fromBytes(new aes_js_1.default.ModeOfOperation.ctr(a,void 0).decrypt(u)),c=s.slice(s.length/2,s.length),_=key_pair_1.addressFromPublickey(Buffer.from(c,"hex")),i.addressHex!==_.toString("hex"))?[2,new Error("Wrong passphrase for account")]:(d=new unlocked_account_1.UnlockedAccount(i,Buffer.from(s,"hex")),[2,d])}catch(e){return[2,e]}}else n=type_guard_1.typeGuard(o,Error)?o:new Error("Unknown error getting account");return[2,n]}})})},e.prototype.persistAccount=function(e){return __awaiter(this,void 0,void 0,function(){var t,r;return __generator(this,function(n){if(t=this.generateAccountStoreKey(e),this.store.add(t,e),r=this.store.get(this.ACCOUNT_INDEX_KEY),type_guard_1.typeGuard(r,Array))r=r;else{if(void 0!==r)return[2,new Error("Error fetching the account index")];r=[]}return r.push(e.addressHex),this.store.add(this.ACCOUNT_INDEX_KEY,r),[2,void 0]})})},e.prototype.removeAccountRecord=function(e){return __awaiter(this,void 0,void 0,function(){var t,r,n;return __generator(this,function(o){return t=this.generateAccountStoreKey(e),this.store.remove(t),r=this.store.get(this.ACCOUNT_INDEX_KEY),type_guard_1.typeGuard(r,Array)&&(r=r,n=r.indexOf(e.addressHex,0),n>-1&&r.splice(n,1),this.store.add(this.ACCOUNT_INDEX_KEY,r)),[2,void 0]})})},e.prototype.getAccountFromStore=function(e){return __awaiter(this,void 0,void 0,function(){var t,r,n;return __generator(this,function(o){return(r=key_pair_1.validateAddressHex(e))?[2,r]:(n=this.store.get(this.generateAccountStoreKeyFromAddressHex(e)),t=void 0===n?new Error("Account not found"):type_guard_1.typeGuard(n,account_1.Account)?n:new Error("Error fetching account from store"),[2,t])})})},e.prototype.generateAccountStoreKey=function(e){return this.ACCOUNT_STORE_PREFIX+e.addressHex},e.prototype.generateAccountStoreKeyFromAddressHex=function(e){return this.ACCOUNT_STORE_PREFIX+e},e.prototype.validatePPKJSON=function(e){var t=JSON.parse(e);return void 0!==t.kdf&&void 0!==t.salt&&void 0!==t.secparam&&void 0!==t.ciphertext&&!("scrypt"!==t.kdf||!__1.Hex.isHex(t.salt)||t.secparam<=0||t.ciphertext.length<=0)},e}();exports.Keybase=Keybase; }).call(this)}).call(this,require("buffer").Buffer) },{"..":4,"../utils/key-pair":144,"../utils/type-guard":148,"./models/account":7,"./models/unlocked-account":9,"aes-js":169,"buffer":260,"crypto":272,"js-sha256":337,"libsodium-wrappers":339,"pbkdf2":353,"scrypt-js":403}],7:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Account=void 0;var key_pair_1=require("../../utils/key-pair"),Account=function(){function e(e,t){this.publicKey=e,this.encryptedPrivateKeyHex=t,this.address=key_pair_1.addressFromPublickey(this.publicKey),this.addressHex=this.address.toString("hex")}return e}();exports.Account=Account; },{"../../utils/key-pair":144}],8:[function(require,module,exports){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||t.hasOwnProperty(r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./account"),exports),__exportStar(require("./unlocked-account"),exports); },{"./account":7,"./unlocked-account":9}],9:[function(require,module,exports){ "use strict";var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.UnlockedAccount=void 0;var account_1=require("./account"),UnlockedAccount=function(t){function e(e,n){var o=t.call(this,e.publicKey,e.encryptedPrivateKeyHex)||this;return o.privateKey=n,o}return __extends(e,t),e}(account_1.Account);exports.UnlockedAccount=UnlockedAccount; },{"./account":7}],10:[function(require,module,exports){ (function (Buffer){(function (){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,s,t){void 0===t&&(t=s),Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[s]}})}:function(e,r,s,t){void 0===t&&(t=s),e[t]=r[s]}),__exportStar=this&&this.__exportStar||function(e,r){for(var s in e)"default"===s||r.hasOwnProperty(s)||__createBinding(r,e,s)},__awaiter=this&&this.__awaiter||function(e,r,s,t){function n(e){return e instanceof s?e:new s(function(r){r(e)})}return new(s||(s=Promise))(function(s,o){function i(e){try{a(t.next(e))}catch(e){o(e)}}function u(e){try{a(t.throw(e))}catch(e){o(e)}}function a(e){e.done?s(e.value):n(e.value).then(i,u)}a((t=t.apply(e,r||[])).next())})},__generator=this&&this.__generator||function(e,r){function s(e){return function(r){return t([e,r])}}function t(s){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(i=a.trys,!(i=i.length>0&&i[i.length-1])&&(6===s[0]||2===s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=r.call(e,a)}catch(e){s=[6,e],o=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}var n,o,i,u,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return u={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Pocket=exports.HTTPMethod=void 0;var config_1=require("./config"),models_1=require("./rpc/models"),utils_1=require("./utils"),session_manager_1=require("./session/session-manager"),rpc_1=require("./rpc"),keybase_1=require("./keybase/keybase"),models_2=require("./keybase/models"),_1=require("./"),consensus_relay_response_1=require("./rpc/models/output/consensus-relay-response"),consensus_node_1=require("./rpc/models/consensus-node"),request_hash_1=require("./rpc/models/input/request-hash"),challenge_request_1=require("./rpc/models/input/challenge-request"),challenge_response_1=require("./rpc/models/output/challenge-response"),relay_meta_1=require("./rpc/models/input/relay-meta"),profile_result_1=require("./utils/models/profile-result"),no_op_profiler_1=require("./utils/no-op-profiler"),proto_tx_decoder_1=require("./transactions/factory/proto-tx-decoder"),HTTPMethod;!function(e){e.POST="POST",e.GET="GET",e.DELETE="DELETE",e.NA=""}(HTTPMethod=exports.HTTPMethod||(exports.HTTPMethod={}));var Pocket=function(){function e(e,r,s,t,n){void 0===s&&(s=new config_1.Configuration),void 0===t&&(t=new _1.InMemoryKVStore),void 0===n&&(n=new no_op_profiler_1.NoOpProfiler),this.configuration=s,this.sessionManager=new session_manager_1.SessionManager(e,s,t),this.keybase=new keybase_1.Keybase(t),this.profiler=n,void 0!==r&&(this.innerRpc=new rpc_1.RPC(r))}return e.prototype.getDispatchersCount=function(){return this.sessionManager.getDispatchersCount()},e.prototype.rpc=function(e){if(void 0!==e&&(this.innerRpc=new rpc_1.RPC(e)),void 0!==this.innerRpc)return this.innerRpc},e.prototype.sendConsensusRelay=function(e,r,s,t,n,o,i,u){return void 0===t&&(t=this.configuration),void 0===o&&(o=HTTPMethod.NA),void 0===i&&(i=""),__awaiter(this,void 0,void 0,function(){var a,c,l,p,_,d,h,f;return __generator(this,function(y){switch(y.label){case 0:a=[],y.label=1;case 1:if(y.trys.push([1,11,,12]),0===this.configuration.consensusNodeCount)return[2,new rpc_1.RpcError("NA","Failed to send a relay with local consensus, configuration consensusNodeCount is 0")];l=0,y.label=2;case 2:return l<this.configuration.consensusNodeCount?[4,this.sendRelay(e,r,s,t,n||void 0,o,i,u,!0)]:[3,5];case 3:if(p=y.sent(),utils_1.typeGuard(p,consensus_node_1.ConsensusNode))0===l&&(c=p.relayResponse),a.push(p);else if(utils_1.typeGuard(p,Error))return[2,p];y.label=4;case 4:return l++,[3,2];case 5:return 0===a.length||void 0===c?[2,new rpc_1.RpcError("NA","Failed to send a relay with local consensus, no responses.")]:(_=new consensus_relay_response_1.ConsensusRelayResponse(c.signature,c.payload,a),_.consensusResult?[2,_]:[3,6]);case 6:return t.acceptDisputedResponses?[2,_]:[3,7];case 7:return void 0===_.majorityResponse||void 0===_.minorityResponse?[3,9]:(d=new challenge_request_1.ChallengeRequest(_.majorityResponse,_.minorityResponse),[4,this.rpc().query.requestChallenge(d)]);case 8:return h=y.sent(),utils_1.typeGuard(h,challenge_response_1.ChallengeResponse),[2,h];case 9:return[2,new rpc_1.RpcError("NA","Failed to send a consensus relay due to false consensus result, not accepting disputed responses without proper majority and minority responses.")];case 10:return[3,12];case 11:return f=y.sent(),[2,rpc_1.RpcError.fromError(f)];case 12:return[2]}})})},e.prototype.sendRelay=function(e,r,s,t,n,o,i,u,a,c){return void 0===t&&(t=this.configuration),void 0===o&&(o=HTTPMethod.NA),void 0===i&&(i=""),void 0===a&&(a=!1),void 0===c&&(c=""),__awaiter(this,void 0,void 0,function(){var l,p,_,d,h,f,y,y,w,g,v,R,m,b,P,k,E,q,x,T,N,S,C,H,A,M,G,B,G,B,D,I;return __generator(this,function(K){switch(K.label){case 0:return K.trys.push([0,25,,26]),l=[],p="send_relay",_=new profile_result_1.ProfileResult("get_current_session"),[4,this.sessionManager.getCurrentSession(s,r,t)];case 1:if(d=K.sent(),_.save(),l.push(_),utils_1.typeGuard(d,Error))return[2,rpc_1.RpcError.fromError(d)];if(h=d,f=void 0,a){if(this.configuration.consensusNodeCount>h.sessionNodes.length)return[2,new rpc_1.RpcError("NA","Failed to send a consensus relay, number of max consensus nodes is higher thant the actual nodes in current session")];if(_=new profile_result_1.ProfileResult("get_unique_session_node"),y=h.getUniqueSessionNode(),_.save(),l.push(_),utils_1.typeGuard(y,Error))return[2,rpc_1.RpcError.fromError(y)];f=y}else if(void 0!==u){if(!h.isNodeInSession(u))return[2,new rpc_1.RpcError("NA","Provided Node is not part of the current session for this application, check your PocketAAT")];f=u}else{if(_=new profile_result_1.ProfileResult("get_session_node"),y=h.getSessionNode(),_.save(),l.push(_),utils_1.typeGuard(y,Error))return[2,rpc_1.RpcError.fromError(y)];f=y}return void 0===f?[2,new rpc_1.RpcError("NA","Could not determine a Service Node to submit this relay")]:(w=new rpc_1.HttpRpcProvider(f.serviceURL),g=new rpc_1.RPC(w),v=new models_1.RelayPayload(e,o,i,n||null),_=new profile_result_1.ProfileResult("address_from_public_key"),R=utils_1.addressFromPublickey(Buffer.from(s.clientPublicKey,"hex")).toString("hex"),_.save(),l.push(_),_=new profile_result_1.ProfileResult("keybase_is_unlocked"),[4,this.keybase.isUnlocked(R)]);case 2:return m=K.sent(),(_.save(),l.push(_),m)?(b=new relay_meta_1.RelayMeta(h.sessionHeader.sessionBlockHeight),P=new request_hash_1.RequestHash(v,b),k=BigInt(Math.floor(1e17*Math.random())),_=new profile_result_1.ProfileResult("relay_proof_bytes"),E=models_1.RelayProof.bytes(k,h.sessionHeader.sessionBlockHeight,f.publicKey,r,s,P),_.save(),l.push(_),_=new profile_result_1.ProfileResult("sign_with_unlocked_account"),[4,this.keybase.signWithUnlockedAccount(R,E)]):[2,new rpc_1.RpcError("NA","Client account "+R+" for this AAT is not unlocked")];case 3:return q=K.sent(),_.save(),l.push(_),utils_1.typeGuard(q,Error)?[4,this.profiler.flushResults({requestID:c,blockchain:r},p,l)]:[3,5];case 4:return K.sent(),[2,new rpc_1.RpcError("NA","Error signing Relay proof: "+q.message)];case 5:return x=q,T=x.toString("hex"),N=new models_1.RelayProof(k,h.sessionHeader.sessionBlockHeight,f.publicKey,r,s,T,P),S=new models_1.RelayRequest(v,b,N),_=new profile_result_1.ProfileResult("rpc_client_relay"),[4,g.client.relay(S,t.validateRelayResponses,t.requestTimeOut,t.rejectSelfSignedCertificates)];case 6:if(C=K.sent(),_.save(),l.push(_),!utils_1.typeGuard(C,rpc_1.RpcError))return[3,21];if(H=C,"60"!==H.code&&"75"!==H.code&&"14"!==H.code)return[3,18];_=new profile_result_1.ProfileResult("destroy_session"),this.sessionManager.destroySession(s,r),_.save(),l.push(_),A=!1,M=0,K.label=7;case 7:return M<t.maxSessionRefreshRetries?void 0===H.session?[3,9]:(_=new profile_result_1.ProfileResult("update_current_session"),[4,this.sessionManager.updateCurrentSession(H.session,s,r,t)]):[3,12];case 8:if(G=K.sent(),_.save(),l.push(_),utils_1.typeGuard(G,Error))return[3,11];if(utils_1.typeGuard(G,models_1.Session)){if(B=G,B.sessionHeader.sessionBlockHeight===h.sessionHeader.sessionBlockHeight)return[3,11];h=B}return A=!0,[3,12];case 9:return _=new profile_result_1.ProfileResult("request_new_session"),[4,this.sessionManager.requestNewSession(s,r,t)];case 10:if(G=K.sent(),_.save(),l.push(_),utils_1.typeGuard(G,Error))return[3,11];if(utils_1.typeGuard(G,models_1.Session)){if(B=G,B.sessionHeader.sessionBlockHeight===h.sessionHeader.sessionBlockHeight)return[3,11];h=B}return A=!0,[3,12];case 11:return M++,[3,7];case 12:return A?(_=new profile_result_1.ProfileResult("session_refreshed_send_relay"),[4,this.sendRelay(e,r,s,t,n,o,i,u,a,c)]):[3,15];case 13:return D=K.sent(),_.save(),l.push(_),[4,this.profiler.flushResults({requestID:c,blockchain:r},p,l)];case 14:return K.sent(),[2,D];case 15:return[4,this.profiler.flushResults({requestID:c,blockchain:r},p,l)];case 16:return K.sent(),[2,new rpc_1.RpcError(H.code,H.message,void 0,f.publicKey)];case 17:return[3,20];case 18:return[4,this.profiler.flushResults({requestID:c,blockchain:r},p,l)];case 19:return K.sent(),[2,new rpc_1.RpcError(H.code,H.message,void 0,f.publicKey)];case 20:return[3,24];case 21:return a&&utils_1.typeGuard(C,models_1.RelayResponse)?(h.sessionNodes.indexOf(f)&&(h.sessionNodes[h.sessionNodes.indexOf(f)].alreadyInConsensus=!0),[2,new consensus_node_1.ConsensusNode(f,!1,C)]):[3,22];case 22:return _=new profile_result_1.ProfileResult("add_new_dispatcher"),this.sessionManager.addNewDispatcher(f),_.save(),[4,this.profiler.flushResults({requestID:c,blockchain:r},p,l)];case 23:return K.sent(),[2,C];case 24:return[3,26];case 25:return I=K.sent(),[2,rpc_1.RpcError.fromError(I)];case 26:return[2]}})})},e.prototype.withPrivateKey=function(e){try{var r=utils_1.typeGuard(e,Buffer)?e:Buffer.from(e,"hex");if(!utils_1.validatePrivateKey(r))throw new Error("Invalid private key");var s=utils_1.publicKeyFromPrivate(r),t=new models_2.UnlockedAccount(new models_2.Account(s,""),r);return new _1.TransactionSender(this,t)}catch(e){return e}},e.prototype.withImportedAccount=function(e,r){return __awaiter(this,void 0,void 0,function(){var s;return __generator(this,function(t){switch(t.label){case 0:return[4,this.keybase.getUnlockedAccount(utils_1.typeGuard(e,"string")?e:e.toString("hex"),r)];case 1:return s=t.sent(),utils_1.typeGuard(s,Error)?[2,s]:[2,new _1.TransactionSender(this,s)]}})})},e.prototype.withTxSigner=function(e){try{return new _1.TransactionSender(this,void 0,e)}catch(e){return e}},e.prototype.withProtoTxDecoder=function(){try{return new proto_tx_decoder_1.ProtoTxDecoder}catch(e){return e}},e}();exports.Pocket=Pocket,__exportStar(require("@pokt-network/aat-js"),exports); }).call(this)}).call(this,require("buffer").Buffer) },{"./":4,"./config":3,"./keybase/keybase":6,"./keybase/models":8,"./rpc":15,"./rpc/models":28,"./rpc/models/consensus-node":24,"./rpc/models/input/challenge-request":29,"./rpc/models/input/relay-meta":36,"./rpc/models/input/request-hash":39,"./rpc/models/output/challenge-response":44,"./rpc/models/output/consensus-relay-response":45,"./session/session-manager":98,"./transactions/factory/proto-tx-decoder":105,"./utils":143,"./utils/models/profile-result":146,"./utils/no-op-profiler":147,"@pokt-network/aat-js":151,"buffer":260}],11:[function(require,module,exports){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||t.hasOwnProperty(r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./routing-table"),exports); },{"./routing-table":12}],12:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RoutingTable=void 0;var type_guard_1=require("../utils/type-guard"),RoutingTable=function(){function t(t,e,r){if(void 0===t&&(t=[]),this.localNodesFileName="",this.dispatchersKey="DISPATCHER_KEY",t.length>e.maxDispatchers&&e.maxDispatchers>0)throw new Error("Routing table cannot contain more than the specified maxDispatcher per blockchain.");if(t.length<1)throw new Error("Routing table must be initialized with at least one Dispatch node.");this.configuration=e,this.store=r,this.store.add(this.dispatchersKey,t)}return Object.defineProperty(t.prototype,"dispatchersCount",{get:function(){var t=this.store.get(this.dispatchersKey);return void 0!==t&&Array.isArray(t)?t.length:0},enumerable:!1,configurable:!0}),t.prototype.getRandomDispatchers=function(t){var e=this.store.get(this.dispatchersKey),r=e.sort(function(){return.5-Math.random()});return e.length<=0?new Error("Unable to readRandomDispatchers(), No dispatcher's available."):r.slice(0,t)},t.prototype.getRandomDispatcher=function(){var t=this.store.get(this.dispatchersKey);return t.length<=0?new Error("Unable to readRandomDispatcher(), No dispatcher's available."):t[Math.floor(Math.random()*t.length)]},t.prototype.getDispatcher=function(t){var e,r=this.store.get(this.dispatchersKey.toUpperCase()),i=t.toString();return r.forEach(function(r){r.toString()===i&&(e=t)}),type_guard_1.typeGuard(e,URL)?e:new Error("Dispatcher not found in routing table.")},t.prototype.addDispatcher=function(t){var e=this.store.get(this.dispatchersKey),r=t.toString();return void 0===e.find(function(t){return t.toString()===r})&&(e.push(t),e.length>this.configuration.maxDispatchers&&this.configuration.maxDispatchers>0&&e.splice(0,1),this.store.add(this.dispatchersKey,e),!0)},t}();exports.RoutingTable=RoutingTable; },{"../utils/type-guard":148}],13:[function(require,module,exports){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t),Object.defineProperty(e,i,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||r.hasOwnProperty(t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./rpc-error"),exports); },{"./rpc-error":14}],14:[function(require,module,exports){ "use strict";var __extends=this&&this.__extends||function(){var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var t in e)e.hasOwnProperty(t)&&(r[t]=e[t])})(e,t)};return function(e,t){function o(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}}(),__read=this&&this.__read||function(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var o,n,s=t.call(r),i=[];try{for(;(void 0===e||e-- >0)&&!(o=s.next()).done;)i.push(o.value)}catch(r){n={error:r}}finally{try{o&&!o.done&&(t=s.return)&&t.call(s)}finally{if(n)throw n.error}}return i},__spread=this&&this.__spread||function(){for(var r=[],e=0;e<arguments.length;e++)r=r.concat(__read(arguments[e]));return r};Object.defineProperty(exports,"__esModule",{value:!0}),exports.RpcError=void 0;var RpcError=function(r){function e(t,o,n,s){var i=r.apply(this,__spread(arguments))||this;return i.code=t,i.message=o,i.session=n,i.nodePubKey=s,Object.setPrototypeOf(i,e.prototype),i}return __extends(e,r),e.fromError=function(r){return new e("0",r.message)},e.fromRelayError=function(r,t){return new e(r,t)},e.fromJSON=function(r){var t=JSON.parse(r);return new e(t.code,t.message,void 0,void 0)},e.prototype.toJSON=function(){return{code:this.code,message:this.message,session:void 0!==this.session?this.session.toJSON():{},node_public_key:void 0!==this.nodePubKey?this.nodePubKey:""}},e}(Error);exports.RpcError=RpcError; },{}],15:[function(require,module,exports){ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t),Object.defineProperty(e,o,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||r.hasOwnProperty(t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./errors"),exports),__exportStar(require("./models"),exports),__exportStar(require("./namespaces"),exports),__exportStar(require("./providers"),exports),__exportStar(require("./rpc"),exports); },{"./errors":13,"./models":28,"./namespaces":89,"./providers":93,"./rpc":95}],16:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ApplicationParams=void 0;var ApplicationParams=function(){function t(t,i,a,n,e,s){if(this.unstakingTime=t,this.maxApplications=i,this.appStakeMin=a,this.baseRelaysPerPokt=n,this.stabilityAdjustment=e,this.participationRateOn=s,!this.isValid())throw new TypeError("Invalid ApplicationParams properties.")}return t.fromJSON=function(i){try{var a=JSON.parse(i);return new t(a.unstaking_time,BigInt(a.max_applications),BigInt(a.app_stake_minimum),BigInt(a.base_relays_per_pokt),BigInt(a.stability_adjustment),a.participation_rate_on)}catch(t){throw t}},t.prototype.toJSON=function(){return{app_stake_minimum:Number(this.appStakeMin.toString()),base_relays_per_pokt:Number(this.baseRelaysPerPokt.toString()),max_applications:Number(this.maxApplications.toString()),participation_rate_on:this.participationRateOn,stability_adjustment:Number(this.stabilityAdjustment.toString()),unstaking_time:this.unstakingTime}},t.prototype.isValid=function(){return Number(this.appStakeMin.toString())>=0&&Number(this.baseRelaysPerPokt.toString())>=0&&Number(this.maxApplications.toString())>=0&&Number(this.stabilityAdjustment.toString())>=0&&this.unstakingTime.length>=0&&void 0!==this.participationRateOn},t}();exports.ApplicationParams=ApplicationParams; },{}],17:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Application=void 0;var __1=require("../.."),staking_status_1=require("./staking-status"),Application=function(){function t(t,i,s,e,a,n,r,o){if(void 0===a&&(a=[]),void 0===o&&(o=""),this.address=t,this.publicKey=i,this.jailed=s,this.status=e,this.chains=a,this.stakedTokens=n,this.maxRelays=r,this.unstakingCompletionTime=o,!this.isValid())throw new TypeError("Invalid Application properties.")}return t.fromJSON=function(i){try{var s=JSON.parse(i),e=staking_status_1.StakingStatus.getStatus(s.status);return new t(s.address,s.public_key,s.jailed,e,s.chains,BigInt(s.staked_tokens),BigInt(s.max_relays),s.unstaking_time)}catch(t){throw t}},t.prototype.toJSON=function(){return{address:this.address,chains:this.chains,public_key:this.publicKey,jailed:this.jailed,max_relays:Number(this.maxRelays.toString()),status:this.status,staked_tokens:Number(this.stakedTokens.toString()),unstaking_time:this.unstakingCompletionTime}},t.prototype.isValid=function(){var t=!0,i=!0;return this.address&&(t=__1.Hex.validateAddress(this.address)),this.publicKey&&(i=__1.Hex.validatePublicKey(this.publicKey)),t&&this.chains.length>0&&i&&void 0!==this.jailed&&Number(this.maxRelays.toString())>=0&&void 0!==this.status&&Number(this.stakedTokens.toString())>=0},t}();exports.Application=Application; },{"../..":4,"./staking-status":83}],18:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlockHeader=void 0;var block_id_1=require("./block-id"),BlockHeader=function(){function s(s,t,h,i,a,e,o,r,n,l,d,_,c,u,p){if(this.chainID=s,this.height=t,this.time=h,this.numTXs=i,this.totalTxs=a,this.lastBlockID=e,this.lastCommitHash=o,this.dataHash=r,this.validatorsHash=n,this.nextValidatorsHash=l,this.consensusHash=d,this.appHash=_,this.lastResultsHash=c,this.evidenceHash=u,this.proposerAddress=p,!this.isValid())throw new TypeError("Invalid BlockHeader properties.")}return s.fromJSON=function(t){try{var h=JSON.parse(t);return new s(h.chain_id,BigInt(h.height),h.time,BigInt(h.num_txs),BigInt(h.total_txs),block_id_1.BlockID.fromJSON(JSON.stringify(h.last_block_id)),h.last_commit_hash,h.data_hash,h.validators_hash,h.next_validators_hash,h.consensus_hash,h.app_hash,h.last_results_hash,h.evidence_hash,h.proposer_address)}catch(s){throw s}},s.prototype.toJSON=function(){return{app_hash:this.appHash,chain_id:this.chainID,consensus_hash:this.consensusHash,data_hash:this.dataHash,evidence_hash:this.evidenceHash,height:Number(this.height.toString()),last_block_id:this.lastBlockID.toJSON(),last_commit_hash:this.lastCommitHash,last_results_hash:this.lastResultsHash,next_validators_hash:this.nextValidatorsHash,num_txs:Number(this.numTXs.toString()),proposer_address:this.proposerAddress,time:this.time,total_txs:Number(this.totalTxs.toString()),validators_hash:this.validatorsHash}},s.prototype.isValid=function(){return 0!==this.chainID.length&&Number(this.height.toString())>=0&&this.lastBlockID.isValid()&&Number(this.numTXs.toString())>=0&&0!==this.time.length&&Number(this.totalTxs.toString())>=0},s}();exports.BlockHeader=BlockHeader; },{"./block-id":19}],19:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlockID=void 0;var part_set_header_1=require("./part-set-header"),hex_1=require("../../utils/hex"),BlockID=function(){function t(t,r){if(this.hash=t,this.parts=r,!this.isValid())throw new TypeError("Invalid BlockID properties.")}return t.fromJSON=function(r){try{var e=JSON.parse(r),s=part_set_header_1.PartSetHeader.fromJSON(JSON.stringify(e.parts));return new t(e.hash,s)}catch(t){throw t}},t.prototype.toJSON=function(){return{hash:this.hash,parts:this.parts.toJSON()}},t.prototype.isValid=function(){var t=!0;return this.hash&&(t=hex_1.Hex.isHex(this.hash)),t&&this.parts.isValid()},t}();exports.BlockID=BlockID; },{"../../utils/hex":142,"./part-set-header":76}],20:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlockMeta=void 0;var block_id_1=require("./block-id"),block_header_1=require("./block-header"),BlockMeta=function(){function e(e,r){if(this.blockID=e,this.header=r,!this.isValid())throw new TypeError("Invalid BlockMeta properties length.")}return e.fromJSON=function(r){var o=JSON.parse(r);return new e(block_id_1.BlockID.fromJSON(JSON.stringify(o.block_id)),block_header_1.BlockHeader.fromJSON(JSON.stringify(o.header)))},e.prototype.toJSON=function(){return{block_id:this.blockID.toJSON(),header:this.header.toJSON()}},e.prototype.isValid=function(){return this.blockID.isValid()&&this.header.isValid()},e}();exports.BlockMeta=BlockMeta; },{"./block-header":18,"./block-id":19}],21:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Block=void 0;var block_header_1=require("./block-header"),commit_1=require("./commit"),Block=function(){function t(t,e,i,r){if(this.header=t,this.data=e,this.evidence=i,this.lastCommit=r,!this.isValid())throw new TypeError("Invalid Block properties.")}return t.fromJSON=function(e){var i=JSON.parse(e);return new t(block_header_1.BlockHeader.fromJSON(JSON.stringify(i.header)),JSON.stringify(i.data),JSON.stringify(i.evidence),commit_1.Commit.fromJSON(JSON.stringify(i.last_commit)))},t.prototype.toJSON=function(){return{data:this.data,evidence:this.evidence,header:this.header.toJSON(),last_commit:this.lastCommit.toJSON()}},t.prototype.isValid=function(){return 0!==this.data.length&&0!==this.evidence.length&&this.header.isValid()&&this.lastCommit.isValid()},t}();exports.Block=Block; },{"./block-header":18,"./commit":23}],22:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CommitSignature=void 0;var block_id_1=require("./block-id"),hex_1=require("../../utils/hex"),CommitSignature=function(){function t(t,i,e,r,s,o,a,d){if(this.type=t,this.height=i,this.round=e,this.blockID=r,this.timestamp=s,this.validatorAddress=o,this.validatorIndex=a,this.signature=d,!this.isValid())throw new TypeError("Invalid CommitSignature properties.")}return t.fromJSON=function(i){try{var e=JSON.parse(i);return new t(e.type,BigInt(e.height),e.round,block_id_1.BlockID.fromJSON(JSON.stringify(e.block_id)),e.timestamp,e.validator_address,e.validator_index,e.signature)}catch(t){throw t}},t.prototype.toJSON=function(){return{block_id:this.blockID.toJSON(),height:Number(this.height.toString()),round:this.round,signature:this.signature,timestamp:this.timestamp,type:this.type,validator_address:this.validatorAddress,validator_index:this.validatorIndex}},t.prototype.isValid=function(){var t=!0;return this.validatorAddress&&(t=hex_1.Hex.isHex(this.validatorAddress)),this.blockID.isValid()&&Number(this.height.toString())>=0&&this.round>=0&&0!==this.signature.length&&0!==this.timestamp.length&&t},t}();exports.CommitSignature=CommitSignature; },{"../../utils/hex":142,"./block-id":19}],23:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Commit=void 0;var block_id_1=require("./block-id"),commit_signature_1=require("./commit-signature"),Commit=function(){function t(t,i){if(this.blockID=t,this.precommits=i,!this.isValid())throw new TypeError("Invalid Commit properties.")}return t.fromJSON=function(i){try{var o=JSON.parse(i),r=[],e=block_id_1.BlockID.fromJSON(JSON.stringify(o.block_id));return o.precommits&&o.precommits.forEach(function(t){if(null!==t){var i=new commit_signature_1.CommitSignature(t.type,BigInt(t.height),t.round,block_id_1.BlockID.fromJSON(JSON.stringify(t.block_id)),t.timestamp,t.validator_address,t.validator_index,t.signature);r.push(i)}}),new t(e,r)}catch(t){throw t}},t.prototype.toJSON=function(){var t=[];return this.precommits.length>0&&this.precommits.forEach(function(i){t.push(i.toJSON())}),{block_id:this.blockID.toJSON(),precommits:t}},t.prototype.isValid=function(){return this.blockID.isValid()},t}();exports.Commit=Commit; },{"./block-id":19,"./commit-signature":22}],24:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConsensusNode=void 0;var ConsensusNode=function(){function s(s,e,t){if(this.node=s,this.status=e,this.relayResponse=t,!this.isValid())throw new TypeError("Invalid ConsensusNode properties.")}return s.fromJSON=function(e){try{var t=JSON.parse(e);return new s(t.node,t.status,t.relay_response)}catch(s){throw s}},s.prototype.toJSON=function(){return{node:this.node.toJSON(),status:this.status,relay_response:this.relayResponse.toJSON()}},s.prototype.isValid=function(){return this.node.isValid()&&void 0!==this.status&&this.relayResponse.isValid()},s}();exports.ConsensusNode=ConsensusNode; },{}],25:[function(require,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Consensus=void 0;var Consensus=function(){function o(o,t){if(this.block=o,this.app=t,!this.isValid())throw new TypeError("Invalid Consensus properties .")}return o.fromJSON=function(t){var s=JSON.parse(t);return new o(s.block,s.app)},o.prototype.toJSON=function(){return{app:this.app.toString(16),block:this.block.toString(16)}},o.prototype.isValid=function(){return void 0!==this.block&&void 0!==this.app},o}();exports.Consensus=Consensus; },{}],26:[function(require,module,exports){ (function (Buffer){(function (){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Event=void 0;var Event=function(){function t(t,e){if(this.type=t,this.attributes=e,!this.isValid())throw new TypeError("Invalid Event properties.")}return t.fromJSON=function(e){try{var r=JSON.parse(e),i=[];return r.attributes&&r.attributes.forEach(function(t){var e=Buffer.from(t.key,"base64").toString("ascii"),r=Buffer.from(t.value,"base64").toString("ascii"),n={key:e,value:r};i.push(n)}),new t(r.type,i)}catch(t){throw t}},t.prototype.toJSON=function(){return{type:this.type,attributes:this.attributes}},t.prototype.isValid=function(){return this.type.length>0&&void 0!==this.attributes},t}();exports.Event=Event; }).cal