Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stacks/encryption

Package Overview
Dependencies
Maintainers
6
Versions
644
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stacks/encryption - npm Package Compare versions

Comparing version 1.0.0-beta.8 to 1.0.0-beta.9

2

dist/encryption.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("elliptic"),r=require("randombytes"),t=require("@stacks/common"),n=require("bitcoinjs-lib"),o=require("sha.js"),i=require("ripemd160-min"),a=require("bip39");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=c(r),s=c(i);function p(e,r,t,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void t(e)}c.done?r(u):Promise.resolve(u).then(n,o)}function f(e){return function(){var r=this,t=arguments;return new Promise((function(n,o){var i=e.apply(r,t);function a(e){p(i,n,o,a,c,"next",e)}function c(e){p(i,n,o,a,c,"throw",e)}a(void 0)}))}}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,r){return(l=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function y(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function d(e,r,t){return(d=y()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);var o=new(Function.bind.apply(e,n));return t&&l(o,t.prototype),o}).apply(null,arguments)}function v(e){var r="function"==typeof Map?new Map:void 0;return(v=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,t)}function t(){return d(e,arguments,h(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),l(t,e)})(e)}function b(e,r){return e(r={exports:{}},r.exports),r.exports}var x=b((function(e){var r=function(e){var r=Object.prototype,t=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{c({},"")}catch(e){c=function(e,r,t){return e[r]=t}}function u(e,r,t,n){var o=Object.create((r&&r.prototype instanceof f?r:f).prototype),i=new E(n||[]);return o._invoke=function(e,r,t){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(t.method=o,t.arg=i;;){var a=t.delegate;if(a){var c=m(a,t);if(c){if(c===p)continue;return c}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var u=s(e,r,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}(e,t,i),o}function s(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p={};function f(){}function h(){}function l(){}var y={};y[o]=function(){return this};var d=Object.getPrototypeOf,v=d&&d(d(C([])));v&&v!==r&&t.call(v,o)&&(y=v);var b=l.prototype=f.prototype=Object.create(y);function x(e){["next","throw","return"].forEach((function(r){c(e,r,(function(e){return this._invoke(r,e)}))}))}function g(e,r){var n;this._invoke=function(o,i){function a(){return new r((function(n,a){!function n(o,i,a,c){var u=s(e[o],e,i);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&t.call(f,"__await")?r.resolve(f.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):r.resolve(f).then((function(e){p.value=e,a(p)}),(function(e){return n("throw",e,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function m(e,r){var t=e.iterator[r.method];if(void 0===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=void 0,m(e,r),"throw"===r.method))return p;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=s(t,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,p;var o=n.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,p):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,p)}function w(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function k(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function C(e){if(e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function r(){for(;++n<e.length;)if(t.call(e,n))return r.value=e[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=b.constructor=l,l.constructor=h,h.displayName=c(l,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===h||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,c(e,a,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},x(g.prototype),g.prototype[i]=function(){return this},e.AsyncIterator=g,e.async=function(r,t,n,o,i){void 0===i&&(i=Promise);var a=new g(u(r,t,n,o),i);return e.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},x(b),c(b,a,"Generator"),b[o]=function(){return this},b.toString=function(){return"[object Generator]"},e.keys=function(e){var r=[];for(var t in e)r.push(t);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=C,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var r in this)"t"===r.charAt(0)&&t.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t,n){return a.type="throw",a.arg=e,r.next=t,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=t.call(i,"catchLoc"),u=t.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&t.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),p},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),k(t),p}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var o=n.arg;k(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:C(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=void 0),p}},e}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}}));function g(){return"undefined"!=typeof crypto&&void 0!==crypto.subtle}var m='Crypto lib not found. Either the WebCrypto "crypto.subtle" or Node.js "crypto" module must be available.';function w(){return k.apply(this,arguments)}function k(){return(k=f(x.mark((function e(){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!g()){e.next=4;break}return e.abrupt("return",{lib:crypto.subtle,name:"subtleCrypto"});case 4:return e.prev=4,r=require("crypto"),e.abrupt("return",{lib:r,name:"nodeCrypto"});case 9:throw e.prev=9,e.t0=e.catch(4),new Error(m);case 12:case"end":return e.stop()}}),e,null,[[4,9]])})))).apply(this,arguments)}var E=function(){function e(e){this.createHash=e}return e.prototype.digest=function(){var e=f(x.mark((function e(r,t){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t="sha256"),e.prev=1,n=this.createHash(t).update(r).digest(),e.abrupt("return",Promise.resolve(n));case 6:return e.prev=6,e.t0=e.catch(1),console.log(e.t0),console.log("Error performing "+t+" digest with Node.js 'crypto.createHash', falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===t?P(r):K(r)));case 11:case"end":return e.stop()}}),e,this,[[1,6]])})));return function(r,t){return e.apply(this,arguments)}}(),e}(),C=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=f(x.mark((function e(r,t){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===t&&(t="sha256"),"sha256"!==t){e.next=5;break}n="SHA-256",e.next=10;break;case 5:if("sha512"!==t){e.next=9;break}n="SHA-512",e.next=10;break;case 9:throw new Error("Unsupported hash algorithm "+t);case 10:return e.prev=10,e.next=13,this.subtleCrypto.digest(n,r);case 13:return e.abrupt("return",Buffer.from(e.sent));case 17:return e.prev=17,e.t0=e.catch(10),console.log(e.t0),console.log("Error performing "+t+" digest with WebCrypto, falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===t?P(r):K(r)));case 22:case"end":return e.stop()}}),e,this,[[10,17]])})));return function(r,t){return e.apply(this,arguments)}}(),e}();function S(){return B.apply(this,arguments)}function B(){return(B=f(x.mark((function e(){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(r=e.sent).name){e.next=7;break}return e.abrupt("return",new C(r.lib));case 7:return e.abrupt("return",new E(r.lib.createHash));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function P(e){var r=new o.sha256;return r.update(e),r.digest()}function K(e){var r=new o.sha512;return r.update(e),r.digest()}var L=function(){function e(){}return e.prototype.digest=function(e){var r=new s.default;r.update(e);var t=r.digest();return Array.isArray(t)?Buffer.from(t):Buffer.from(t.buffer)},e}(),T=function(){function e(e){this.nodeCryptoCreateHash=e}return e.prototype.digest=function(e){try{return this.nodeCryptoCreateHash("rmd160").update(e).digest()}catch(r){try{return this.nodeCryptoCreateHash("ripemd160").update(e).digest()}catch(t){return console.log(r),console.log("Node.js `crypto.createHash` exists but failing to digest for ripemd160, falling back to js implementation"),(new L).digest(e)}}},e}();function O(e){return(r=function(e){try{if(!require.resolve("crypto"))return!1;var r=require("crypto");return!!r&&(!e||e(r))}catch(e){return!1}}((function(e){return"function"==typeof e.createHash&&e.createHash})),r?new T(r):new L).digest(e);var r}function j(e){return e||(e=32),u.default(e)}function H(e){var r=Buffer.isBuffer(e)?e:Buffer.from(e,"hex");return n.ECPair.fromPrivateKey(r).publicKey.toString("hex")}var A=function(){function e(e){this.createHmac=e}return e.prototype.digest=function(){var e=f(x.mark((function e(r,t){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.createHmac("sha256",r).update(t).digest(),e.abrupt("return",Promise.resolve(n));case 2:case"end":return e.stop()}}),e,this)})));return function(r,t){return e.apply(this,arguments)}}(),e}(),_=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=f(x.mark((function e(r,t){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.subtleCrypto.importKey("raw",r,{name:"HMAC",hash:"SHA-256"},!0,["sign"]);case 2:return n=e.sent,e.next=5,this.subtleCrypto.sign({name:"HMAC",hash:"SHA-256"},n,t);case 5:return e.abrupt("return",Buffer.from(e.sent));case 7:case"end":return e.stop()}}),e,this)})));return function(r,t){return e.apply(this,arguments)}}(),e}();function F(){return N.apply(this,arguments)}function N(){return(N=f(x.mark((function e(){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(r=e.sent).name){e.next=7;break}return e.abrupt("return",new _(r.lib));case 7:return e.abrupt("return",new A(r.lib.createHmac));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var M=function(){function e(e,r){this.createCipher=e,this.createDecipher=r}var r=e.prototype;return r.encrypt=function(){var e=f(x.mark((function e(r,t,n,o){var i,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===r||"aes-256-cbc"===r){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+r+'"');case 2:return i=this.createCipher(r,t,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(r,t,n,o){return e.apply(this,arguments)}}(),r.decrypt=function(){var e=f(x.mark((function e(r,t,n,o){var i,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===r||"aes-256-cbc"===r){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+r+'"');case 2:return i=this.createDecipher(r,t,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(r,t,n,o){return e.apply(this,arguments)}}(),e}(),U=function(){function e(e){this.subtleCrypto=e}var r=e.prototype;return r.encrypt=function(){var e=f(x.mark((function e(r,t,n,o){var i,a,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==r){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==r){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+r+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",t,{name:i,length:a},!1,["encrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.encrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(r,t,n,o){return e.apply(this,arguments)}}(),r.decrypt=function(){var e=f(x.mark((function e(r,t,n,o){var i,a,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==r){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==r){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+r+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",t,{name:i,length:a},!1,["decrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.decrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(r,t,n,o){return e.apply(this,arguments)}}(),e}();function D(){return q.apply(this,arguments)}function q(){return(q=f(x.mark((function e(){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(r=e.sent).name){e.next=7;break}return e.abrupt("return",new U(r.lib));case 7:return e.abrupt("return",new M(r.lib.createCipheriv,r.lib.createDecipheriv));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var G=new e.ec("secp256k1");function R(e,r,t){return I.apply(this,arguments)}function I(){return(I=f(x.mark((function e(r,t,n){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,D();case 2:return o=e.sent,e.next=5,o.encrypt("aes-256-cbc",t,r,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function J(e,r,t){return W.apply(this,arguments)}function W(){return(W=f(x.mark((function e(r,t,n){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,D();case 2:return o=e.sent,e.next=5,o.decrypt("aes-256-cbc",t,r,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function V(e,r){return Y.apply(this,arguments)}function Y(){return(Y=f(x.mark((function e(r,t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,F();case 2:return e.abrupt("return",e.sent.digest(r,t));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function z(e,r){if(e.length!==r.length)return!1;for(var t=0,n=0;n<e.length;n++)t|=e[n]^r[n];return 0===t}function Q(e){var r=K(e);return{encryptionKey:r.slice(0,32),hmacKey:r.slice(32)}}function X(e){var r=e.toArrayLike(Buffer,"be",32);if(32!==r.byteLength)throw new Error("Generated a 32-byte BN for encryption. Failing.");return r}function Z(e){var r={iv:"",ephemeralPK:"",mac:"",cipherText:"",wasString:!!e.wasString};return"base64"===e.cipherTextEncoding&&(r.cipherTextEncoding="base64"),{payloadValuesLength:162,payloadShell:JSON.stringify(r)}}function $(e){return{signedPayloadValuesLength:210,signedPayloadShell:JSON.stringify({signature:"",publicKey:"",cipherText:e})}}function ee(e,r,t,n){return re.apply(this,arguments)}function re(){return(re=f(x.mark((function e(r,t,n,o){var i,a,c,s,p,f,h,l,y,d,v,b;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=G.keyFromPublic(r,"hex").getPublic(),a=G.genKeyPair(),c=Buffer.from(a.getPublic().encodeCompressed()),s=a.derive(i),p=X(s),f=Q(p),h=u.default(16),e.next=9,R(h,f.encryptionKey,t);case 9:return l=e.sent,y=Buffer.concat([h,c,l]),e.next=13,V(f.hmacKey,y);case 13:if(d=e.sent,o&&"hex"!==o){e.next=18;break}v=l.toString("hex"),e.next=23;break;case 18:if("base64"!==o){e.next=22;break}v=l.toString("base64"),e.next=23;break;case 22:throw new Error('Unexpected cipherTextEncoding "'+o+'"');case 23:return b={iv:h.toString("hex"),ephemeralPK:c.toString("hex"),cipherText:v,mac:d.toString("hex"),wasString:!!n},o&&"hex"!==o&&(b.cipherTextEncoding=o),e.abrupt("return",b);case 26:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function te(e,r){return ne.apply(this,arguments)}function ne(){return(ne=f(x.mark((function e(r,n){var o,i,a,c,u,s,p,f,h,l;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=G.keyFromPrivate(r,"hex"),i=null,e.prev=2,i=G.keyFromPublic(n.ephemeralPK,"hex").getPublic(),e.next=9;break;case 6:throw e.prev=6,e.t0=e.catch(2),new t.FailedDecryptionError("Unable to get public key from cipher object. You might be trying to decrypt an unencrypted object.");case 9:if(a=o.derive(i),c=X(a),u=Q(c),s=Buffer.from(n.iv,"hex"),n.cipherTextEncoding&&"hex"!==n.cipherTextEncoding){e.next=17;break}p=Buffer.from(n.cipherText,"hex"),e.next=22;break;case 17:if("base64"!==n.cipherTextEncoding){e.next=21;break}p=Buffer.from(n.cipherText,"base64"),e.next=22;break;case 21:throw new Error('Unexpected cipherTextEncoding "'+n.cipherText+'"');case 22:return f=Buffer.concat([s,Buffer.from(i.encodeCompressed()),p]),e.next=25,V(u.hmacKey,f);case 25:if(h=e.sent,z(Buffer.from(n.mac,"hex"),h)){e.next=29;break}throw new t.FailedDecryptionError("Decryption failed: failure in MAC check");case 29:return e.next=31,J(s,u.encryptionKey,p);case 31:if(l=e.sent,!n.wasString){e.next=36;break}return e.abrupt("return",l.toString());case 36:return e.abrupt("return",l);case 37:case"end":return e.stop()}}),e,null,[[2,6]])})))).apply(this,arguments)}function oe(e,r){var t=r instanceof Buffer?r:Buffer.from(r),n=G.keyFromPrivate(e,"hex"),o=H(e),i=P(t);return{signature:n.sign(i).toDER("hex"),publicKey:o}}var ie=function(){function e(e){this.nodePbkdf2=e}return e.prototype.derive=function(){var e=f(x.mark((function e(r,t,n,o,i){var a=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha512"===i||"sha256"===i){e.next=2;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 2:return e.abrupt("return",new Promise((function(e,c){a.nodePbkdf2(r,t,n,o,i,(function(r,t){r&&c(r),e(t)}))})));case 3:case"end":return e.stop()}}),e)})));return function(r,t,n,o,i){return e.apply(this,arguments)}}(),e}(),ae=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=f(x.mark((function e(r,t,n,o,i){var a,c,u,s,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha256"!==i){e.next=4;break}a="SHA-256",e.next=9;break;case 4:if("sha512"!==i){e.next=8;break}a="SHA-512",e.next=9;break;case 8:throw new Error('Unsupported Pbkdf2 digest algorithm "'+i+'"');case 9:return u=Buffer.from(r,"utf8"),e.prev=10,e.next=13,this.subtleCrypto.importKey("raw",u,"PBKDF2",!1,["deriveBits"]);case 13:return s=e.sent,e.next=16,this.subtleCrypto.deriveBits({name:"PBKDF2",salt:t,iterations:n,hash:{name:a}},s,8*o);case 16:c=e.sent,e.next=23;break;case 19:return e.prev=19,e.t0=e.catch(10),p=new ce(this.subtleCrypto),e.abrupt("return",p.derive(r,t,n,o,i));case 23:return e.abrupt("return",Buffer.from(c));case 24:case"end":return e.stop()}}),e,this,[[10,19]])})));return function(r,t,n,o,i){return e.apply(this,arguments)}}(),e}(),ce=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=f(x.mark((function e(r,t,n,o,i){var a,c,u,s,p,f,h,l,y,d,v,b,g,m,w,k=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d=function(e,r,t){return e[t>>>=0]=(r=+r)>>>24,e[t+1]=r>>>16,e[t+2]=r>>>8,e[t+3]=255&r,t+4},"sha512"===i||"sha256"===i){e.next=3;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 3:a=Buffer.from(r,"utf8"),c={name:"HMAC",hash:"sha512"===i?"SHA-512":"SHA-256"},u=function(e,r){return k.subtleCrypto.importKey("raw",e,c,!0,["sign"]).then((function(e){return k.subtleCrypto.sign(c,e,r)})).then((function(e){return new Uint8Array(e)}))},s=new Uint8Array(o),p=t.length,(f=new Uint8Array(p+4)).set(t),h=0,l="sha512"===i?64:32,y=Math.ceil(o/l),v=1;case 15:if(!(v<=y)){e.next=35;break}return d(f,v,p),e.next=19,u(a,f);case 19:g=b=e.sent,m=1;case 22:if(!(m<n)){e.next=30;break}return e.next=25,u(a,g);case 25:for(g=e.sent,w=0;w<l;w++)b[w]^=g[w];case 27:m++,e.next=22;break;case 30:s.set(b.subarray(0,s.byteLength-h),h),h+=l;case 32:v++,e.next=15;break;case 35:return e.abrupt("return",Buffer.from(s.buffer));case 36:case"end":return e.stop()}}),e)})));return function(r,t,n,o,i){return e.apply(this,arguments)}}(),e}();function ue(){return se.apply(this,arguments)}function se(){return(se=f(x.mark((function e(){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(r=e.sent).name){e.next=7;break}return e.abrupt("return",new ae(r.lib));case 7:return e.abrupt("return",new ie(r.lib.pbkdf2));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function pe(){return(pe=f(x.mark((function e(r,t,n){var o,i,c,s,p,f,h,l,y,d,v,b,g;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,o=a.mnemonicToEntropy(r),e.next=9;break;case 4:throw e.prev=4,e.t0=e.catch(0),console.error("Invalid mnemonic phrase provided"),console.error(e.t0),new Error("Not a valid bip39 mnemonic");case 9:return i=Buffer.from(o,"hex"),e.next=12,ue();case 12:return c=e.sent,s=n&&n.getRandomBytes?n.getRandomBytes(16):u.default(16),e.next=16,c.derive(t,s,1e5,48,"sha512");case 16:return f=(p=e.sent).slice(0,16),h=p.slice(16,32),l=p.slice(32,48),e.next=22,D();case 22:return y=e.sent,e.next=25,y.encrypt("aes-128-cbc",f,l,i);case 25:return d=e.sent,v=Buffer.concat([s,d]),e.next=29,F();case 29:return b=e.sent,e.next=32,b.digest(h,v);case 32:return g=Buffer.concat([s,e.sent,d]),e.abrupt("return",g);case 35:case"end":return e.stop()}}),e,null,[[0,4]])})))).apply(this,arguments)}var fe=function(e){var r,t;function n(){return e.apply(this,arguments)||this}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,n}(v(Error));function he(e,r){return le.apply(this,arguments)}function le(){return(le=f(x.mark((function e(r,t){var n,o,i,c,u,s,p,f,h,l,y,d,v,b,g,m;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.slice(0,16),o=r.slice(16,48),i=r.slice(48),c=Buffer.concat([n,i]),e.next=6,ue();case 6:return u=e.sent,e.next=9,u.derive(t,n,1e5,48,"sha512");case 9:return p=(s=e.sent).slice(0,16),f=s.slice(16,32),h=s.slice(32,48),e.next=15,D();case 15:return l=e.sent,e.next=18,l.decrypt("aes-128-cbc",p,h,i);case 18:return y=e.sent,e.next=21,F();case 21:return d=e.sent,e.next=24,d.digest(f,c);case 24:return v=e.sent,e.next=27,S();case 27:return b=e.sent,e.next=30,b.digest(o);case 30:return g=e.sent,e.next=33,b.digest(v);case 33:if(g.equals(e.sent)){e.next=36;break}throw new fe("Wrong password (HMAC mismatch)");case 36:e.prev=36,m=a.entropyToMnemonic(y),e.next=45;break;case 40:throw e.prev=40,e.t0=e.catch(36),console.error("Error thrown by `entropyToMnemonic`"),console.error(e.t0),new fe("Wrong password (invalid plaintext)");case 45:if(a.validateMnemonic(m)){e.next=47;break}throw new fe("Wrong password (invalid plaintext)");case 47:return e.abrupt("return",m);case 48:case"end":return e.stop()}}),e,null,[[36,40]])})))).apply(this,arguments)}function ye(e,r,t){return new Promise((function(n,o){t||o(new Error("The `triplesec.decrypt` function must be provided")),t({key:Buffer.from(r),data:e},(function(e,r){e?o(e):n(r)}))}))}function de(){return(de=f(x.mark((function e(r,t,n){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=Buffer.isBuffer(r)?r:Buffer.from(r,"hex"),e.prev=1,e.next=4,he(o,t);case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(1),!(e.t0 instanceof fe)){e.next=11;break}throw e.t0;case 11:return e.next=13,ye(o,t,n);case 13:return e.abrupt("return",e.sent.toString());case 15:case"end":return e.stop()}}),e,null,[[1,7]])})))).apply(this,arguments)}function ve(){return(ve=f(x.mark((function e(r,t){var n,o,i,a,c,u;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=Object.assign({},t)).publicKey){e.next=5;break}if(n.privateKey){e.next=4;break}throw new Error("Either public key or private key must be supplied for encryption.");case 4:n.publicKey=H(n.privateKey);case 5:return i="boolean"==typeof n.wasString?n.wasString:"string"==typeof r,a="string"==typeof r?Buffer.from(r):r,e.next=9,ee(n.publicKey,a,i,n.cipherTextEncoding);case 9:return c=JSON.stringify(e.sent),n.sign&&("string"==typeof n.sign?o=n.sign:o||(o=n.privateKey),u=oe(o,c),c=JSON.stringify({signature:u.signature,publicKey:u.publicKey,cipherText:c})),e.abrupt("return",c);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}Object.defineProperty(exports,"randomBytes",{enumerable:!0,get:function(){return u.default}}),exports.NodeCryptoSha2Hash=E,exports.WebCryptoSha2Hash=C,exports.aes256CbcEncrypt=R,exports.createSha2Hash=S,exports.decryptContent=function(e,r){var t=Object.assign({},r);if(!t.privateKey)throw new Error("Private key is required for decryption.");try{var n=JSON.parse(e);return te(t.privateKey,n)}catch(e){throw e instanceof SyntaxError?new Error("Failed to parse encrypted content JSON. The content may not be encrypted. If using getFile, try passing { decrypt: false }."):e}},exports.decryptECIES=te,exports.decryptMnemonic=function(e,r,t){return de.apply(this,arguments)},exports.ecPairToAddress=function(e){var r=O(P(e.publicKey));return n.address.toBase58Check(r,e.network.pubKeyHash)},exports.ecPairToHexString=function(e){var r=e.privateKey.toString("hex");return e.compressed?r+"01":r},exports.eciesGetJsonStringLength=function(e){var r,t=Z(e),n=t.payloadShell,o=t.payloadValuesLength,i=16*(Math.floor(e.contentLength/16)+1);if(e.cipherTextEncoding&&"hex"!==e.cipherTextEncoding){if("base64"!==e.cipherTextEncoding)throw new Error('Unexpected cipherTextEncoding "'+e.cipherTextEncoding+'"');r=4*Math.ceil(i/3)}else r=2*i;if(e.sign){var a=$(n);return a.signedPayloadShell.length+a.signedPayloadValuesLength+o+r}return n.length+o+r},exports.encryptContent=function(e,r){return ve.apply(this,arguments)},exports.encryptECIES=ee,exports.encryptMnemonic=function(e,r,t){return pe.apply(this,arguments)},exports.getBufferFromBN=X,exports.getCipherObjectWrapper=Z,exports.getEntropy=j,exports.getHexFromBN=function(e){var r=e.toString("hex",64);if(64===r.length)return r;if(r.length<64)return""+"0".repeat(64-r.length)+r;throw new Error("Generated a > 32-byte BN for encryption. Failing.")},exports.getPublicKeyFromPrivate=H,exports.getSignedCipherObjectWrapper=$,exports.hashSha256Sync=P,exports.hashSha512Sync=K,exports.hexStringToECPair=function(e,r){var t={network:r||n.networks.bitcoin,compressed:!0};if(66===e.length){if("01"!==e.slice(64))throw new Error("Improperly formatted private-key hex string. 66-length hex usually indicates compressed key, but last byte must be == 1");return n.ECPair.fromPrivateKey(Buffer.from(e.slice(0,64),"hex"),t)}if(64===e.length)return t.compressed=!1,n.ECPair.fromPrivateKey(Buffer.from(e,"hex"),t);throw new Error("Improperly formatted private-key hex string: length should be 64 or 66.")},exports.makeECPrivateKey=function(){return n.ECPair.makeRandom({rng:j}).privateKey.toString("hex")},exports.publicKeyToAddress=function(e){var r=O(P(Buffer.isBuffer(e)?e:Buffer.from(e,"hex")));return n.address.toBase58Check(r,n.networks.bitcoin.pubKeyHash)},exports.signECDSA=oe,exports.verifyECDSA=function(e,r,t){var n=function(e){return e instanceof Buffer?e:(ArrayBuffer,Buffer.from(e))}(e),o=G.keyFromPublic(r,"hex"),i=P(n);return o.verify(i,t)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("elliptic"),t=require("randombytes"),r=require("@stacks/common"),n=require("bitcoinjs-lib"),o=require("sha.js"),i=require("ripemd160-min"),a=require("bip39");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=c(t),s=c(i);function p(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function f(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){p(i,n,o,a,c,"next",e)}function c(e){p(i,n,o,a,c,"throw",e)}a(void 0)}))}}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function y(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function d(e,t,r){return(d=y()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&l(o,r.prototype),o}).apply(null,arguments)}function v(e){var t="function"==typeof Map?new Map:void 0;return(v=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return d(e,arguments,h(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),l(r,e)})(e)}function b(e,t){return e(t={exports:{}},t.exports),t.exports}var x=b((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),i=new E(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=m(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,i),o}function s(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p={};function f(){}function h(){}function l(){}var y={};y[o]=function(){return this};var d=Object.getPrototypeOf,v=d&&d(d(C([])));v&&v!==t&&r.call(v,o)&&(y=v);var b=l.prototype=f.prototype=Object.create(y);function x(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function g(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,c){var u=s(e[o],e,i);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(f).then((function(e){p.value=e,a(p)}),(function(e){return n("throw",e,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function m(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,m(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=s(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function C(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=b.constructor=l,l.constructor=h,h.displayName=c(l,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,c(e,a,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},x(g.prototype),g.prototype[i]=function(){return this},e.AsyncIterator=g,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new g(u(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},x(b),c(b,a,"Generator"),b[o]=function(){return this},b.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=C,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));function g(){return"undefined"!=typeof crypto&&void 0!==crypto.subtle}var m='Crypto lib not found. Either the WebCrypto "crypto.subtle" or Node.js "crypto" module must be available.';function w(){return k.apply(this,arguments)}function k(){return(k=f(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!g()){e.next=4;break}return e.abrupt("return",{lib:crypto.subtle,name:"subtleCrypto"});case 4:return e.prev=4,t=require("crypto"),e.abrupt("return",{lib:t,name:"nodeCrypto"});case 9:throw e.prev=9,e.t0=e.catch(4),new Error(m);case 12:case"end":return e.stop()}}),e,null,[[4,9]])})))).apply(this,arguments)}var E=function(){function e(e){this.createHash=e}return e.prototype.digest=function(){var e=f(x.mark((function e(t,r){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===r&&(r="sha256"),e.prev=1,n=this.createHash(r).update(t).digest(),e.abrupt("return",Promise.resolve(n));case 6:return e.prev=6,e.t0=e.catch(1),console.log(e.t0),console.log("Error performing "+r+" digest with Node.js 'crypto.createHash', falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===r?P(t):K(t)));case 11:case"end":return e.stop()}}),e,this,[[1,6]])})));return function(t,r){return e.apply(this,arguments)}}(),e}(),C=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=f(x.mark((function e(t,r){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r="sha256"),"sha256"!==r){e.next=5;break}n="SHA-256",e.next=10;break;case 5:if("sha512"!==r){e.next=9;break}n="SHA-512",e.next=10;break;case 9:throw new Error("Unsupported hash algorithm "+r);case 10:return e.prev=10,e.next=13,this.subtleCrypto.digest(n,t);case 13:return e.abrupt("return",Buffer.from(e.sent));case 17:return e.prev=17,e.t0=e.catch(10),console.log(e.t0),console.log("Error performing "+r+" digest with WebCrypto, falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===r?P(t):K(t)));case 22:case"end":return e.stop()}}),e,this,[[10,17]])})));return function(t,r){return e.apply(this,arguments)}}(),e}();function S(){return B.apply(this,arguments)}function B(){return(B=f(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new C(t.lib));case 7:return e.abrupt("return",new E(t.lib.createHash));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function P(e){var t=new o.sha256;return t.update(e),t.digest()}function K(e){var t=new o.sha512;return t.update(e),t.digest()}var L=function(){function e(){}return e.prototype.digest=function(e){var t=new s.default;t.update(e);var r=t.digest();return Array.isArray(r)?Buffer.from(r):Buffer.from(r.buffer)},e}(),O=function(){function e(e){this.nodeCryptoCreateHash=e}return e.prototype.digest=function(e){try{return this.nodeCryptoCreateHash("rmd160").update(e).digest()}catch(t){try{return this.nodeCryptoCreateHash("ripemd160").update(e).digest()}catch(r){return console.log(t),console.log("Node.js `crypto.createHash` exists but failing to digest for ripemd160, falling back to js implementation"),(new L).digest(e)}}},e}();function T(e){return(t=function(e){try{if(!require.resolve("crypto"))return!1;var t=require("crypto");return!!t&&(!e||e(t))}catch(e){return!1}}((function(e){return"function"==typeof e.createHash&&e.createHash})),t?new O(t):new L).digest(e);var t}function j(e){return e||(e=32),u.default(e)}function A(e){var t=Buffer.isBuffer(e)?e:Buffer.from(e,"hex");return n.ECPair.fromPrivateKey(t).publicKey.toString("hex")}var H=function(){function e(e){this.createHmac=e}return e.prototype.digest=function(){var e=f(x.mark((function e(t,r){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.createHmac("sha256",t).update(r).digest(),e.abrupt("return",Promise.resolve(n));case 2:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),e}(),_=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=f(x.mark((function e(t,r){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.subtleCrypto.importKey("raw",t,{name:"HMAC",hash:"SHA-256"},!0,["sign"]);case 2:return n=e.sent,e.next=5,this.subtleCrypto.sign({name:"HMAC",hash:"SHA-256"},n,r);case 5:return e.abrupt("return",Buffer.from(e.sent));case 7:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),e}();function F(){return N.apply(this,arguments)}function N(){return(N=f(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new _(t.lib));case 7:return e.abrupt("return",new H(t.lib.createHmac));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var M=function(){function e(e,t){this.createCipher=e,this.createDecipher=t}var t=e.prototype;return t.encrypt=function(){var e=f(x.mark((function e(t,r,n,o){var i,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===t||"aes-256-cbc"===t){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+t+'"');case 2:return i=this.createCipher(t,r,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),t.decrypt=function(){var e=f(x.mark((function e(t,r,n,o){var i,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===t||"aes-256-cbc"===t){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+t+'"');case 2:return i=this.createDecipher(t,r,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),e}(),U=function(){function e(e){this.subtleCrypto=e}var t=e.prototype;return t.encrypt=function(){var e=f(x.mark((function e(t,r,n,o){var i,a,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==t){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==t){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+t+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",r,{name:i,length:a},!1,["encrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.encrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),t.decrypt=function(){var e=f(x.mark((function e(t,r,n,o){var i,a,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==t){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==t){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+t+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",r,{name:i,length:a},!1,["decrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.decrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),e}();function D(){return q.apply(this,arguments)}function q(){return(q=f(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new U(t.lib));case 7:return e.abrupt("return",new M(t.lib.createCipheriv,t.lib.createDecipheriv));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function G(e){return 16*(Math.floor(e/16)+1)}function R(e){return 4*Math.ceil(e/3)}var I=new e.ec("secp256k1");function J(e,t,r){return W.apply(this,arguments)}function W(){return(W=f(x.mark((function e(t,r,n){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,D();case 2:return o=e.sent,e.next=5,o.encrypt("aes-256-cbc",r,t,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function V(e,t,r){return Y.apply(this,arguments)}function Y(){return(Y=f(x.mark((function e(t,r,n){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,D();case 2:return o=e.sent,e.next=5,o.decrypt("aes-256-cbc",r,t,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function z(e,t){return Q.apply(this,arguments)}function Q(){return(Q=f(x.mark((function e(t,r){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,F();case 2:return e.abrupt("return",e.sent.digest(t,r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function X(e,t){if(e.length!==t.length)return!1;for(var r=0,n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r}function Z(e){var t=K(e);return{encryptionKey:t.slice(0,32),hmacKey:t.slice(32)}}function $(e){var t=e.toArrayLike(Buffer,"be",32);if(32!==t.byteLength)throw new Error("Generated a 32-byte BN for encryption. Failing.");return t}function ee(e){var t={iv:"",ephemeralPK:"",mac:"",cipherText:"",wasString:!!e.wasString};return"base64"===e.cipherTextEncoding&&(t.cipherTextEncoding="base64"),{payloadValuesLength:162,payloadShell:JSON.stringify(t)}}function te(e){return{signedPayloadValuesLength:210,signedPayloadShell:JSON.stringify({signature:"",publicKey:"",cipherText:e})}}function re(e,t,r,n){return ne.apply(this,arguments)}function ne(){return(ne=f(x.mark((function e(t,r,n,o){var i,a,c,s,p,f,h,l,y,d,v,b;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=I.keyFromPublic(t,"hex").getPublic(),a=I.genKeyPair(),c=Buffer.from(a.getPublic().encodeCompressed()),s=a.derive(i),p=$(s),f=Z(p),h=u.default(16),e.next=9,J(h,f.encryptionKey,r);case 9:return l=e.sent,y=Buffer.concat([h,c,l]),e.next=13,z(f.hmacKey,y);case 13:if(d=e.sent,o&&"hex"!==o){e.next=18;break}v=l.toString("hex"),e.next=23;break;case 18:if("base64"!==o){e.next=22;break}v=l.toString("base64"),e.next=23;break;case 22:throw new Error('Unexpected cipherTextEncoding "'+o+'"');case 23:return b={iv:h.toString("hex"),ephemeralPK:c.toString("hex"),cipherText:v,mac:d.toString("hex"),wasString:!!n},o&&"hex"!==o&&(b.cipherTextEncoding=o),e.abrupt("return",b);case 26:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oe(e,t){return ie.apply(this,arguments)}function ie(){return(ie=f(x.mark((function e(t,n){var o,i,a,c,u,s,p,f,h,l;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=I.keyFromPrivate(t,"hex"),i=null,e.prev=2,i=I.keyFromPublic(n.ephemeralPK,"hex").getPublic(),e.next=9;break;case 6:throw e.prev=6,e.t0=e.catch(2),new r.FailedDecryptionError("Unable to get public key from cipher object. You might be trying to decrypt an unencrypted object.");case 9:if(a=o.derive(i),c=$(a),u=Z(c),s=Buffer.from(n.iv,"hex"),n.cipherTextEncoding&&"hex"!==n.cipherTextEncoding){e.next=17;break}p=Buffer.from(n.cipherText,"hex"),e.next=22;break;case 17:if("base64"!==n.cipherTextEncoding){e.next=21;break}p=Buffer.from(n.cipherText,"base64"),e.next=22;break;case 21:throw new Error('Unexpected cipherTextEncoding "'+n.cipherText+'"');case 22:return f=Buffer.concat([s,Buffer.from(i.encodeCompressed()),p]),e.next=25,z(u.hmacKey,f);case 25:if(h=e.sent,X(Buffer.from(n.mac,"hex"),h)){e.next=29;break}throw new r.FailedDecryptionError("Decryption failed: failure in MAC check");case 29:return e.next=31,V(s,u.encryptionKey,p);case 31:if(l=e.sent,!n.wasString){e.next=36;break}return e.abrupt("return",l.toString());case 36:return e.abrupt("return",l);case 37:case"end":return e.stop()}}),e,null,[[2,6]])})))).apply(this,arguments)}function ae(e,t){var r=t instanceof Buffer?t:Buffer.from(t),n=I.keyFromPrivate(e,"hex"),o=A(e),i=P(r);return{signature:n.sign(i).toDER("hex"),publicKey:o}}var ce=function(){function e(e){this.nodePbkdf2=e}return e.prototype.derive=function(){var e=f(x.mark((function e(t,r,n,o,i){var a=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha512"===i||"sha256"===i){e.next=2;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 2:return e.abrupt("return",new Promise((function(e,c){a.nodePbkdf2(t,r,n,o,i,(function(t,r){t&&c(t),e(r)}))})));case 3:case"end":return e.stop()}}),e)})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}(),ue=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=f(x.mark((function e(t,r,n,o,i){var a,c,u,s,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha256"!==i){e.next=4;break}a="SHA-256",e.next=9;break;case 4:if("sha512"!==i){e.next=8;break}a="SHA-512",e.next=9;break;case 8:throw new Error('Unsupported Pbkdf2 digest algorithm "'+i+'"');case 9:return u=Buffer.from(t,"utf8"),e.prev=10,e.next=13,this.subtleCrypto.importKey("raw",u,"PBKDF2",!1,["deriveBits"]);case 13:return s=e.sent,e.next=16,this.subtleCrypto.deriveBits({name:"PBKDF2",salt:r,iterations:n,hash:{name:a}},s,8*o);case 16:c=e.sent,e.next=23;break;case 19:return e.prev=19,e.t0=e.catch(10),p=new se(this.subtleCrypto),e.abrupt("return",p.derive(t,r,n,o,i));case 23:return e.abrupt("return",Buffer.from(c));case 24:case"end":return e.stop()}}),e,this,[[10,19]])})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}(),se=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=f(x.mark((function e(t,r,n,o,i){var a,c,u,s,p,f,h,l,y,d,v,b,g,m,w,k=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d=function(e,t,r){return e[r>>>=0]=(t=+t)>>>24,e[r+1]=t>>>16,e[r+2]=t>>>8,e[r+3]=255&t,r+4},"sha512"===i||"sha256"===i){e.next=3;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 3:a=Buffer.from(t,"utf8"),c={name:"HMAC",hash:"sha512"===i?"SHA-512":"SHA-256"},u=function(e,t){return k.subtleCrypto.importKey("raw",e,c,!0,["sign"]).then((function(e){return k.subtleCrypto.sign(c,e,t)})).then((function(e){return new Uint8Array(e)}))},s=new Uint8Array(o),p=r.length,(f=new Uint8Array(p+4)).set(r),h=0,l="sha512"===i?64:32,y=Math.ceil(o/l),v=1;case 15:if(!(v<=y)){e.next=35;break}return d(f,v,p),e.next=19,u(a,f);case 19:g=b=e.sent,m=1;case 22:if(!(m<n)){e.next=30;break}return e.next=25,u(a,g);case 25:for(g=e.sent,w=0;w<l;w++)b[w]^=g[w];case 27:m++,e.next=22;break;case 30:s.set(b.subarray(0,s.byteLength-h),h),h+=l;case 32:v++,e.next=15;break;case 35:return e.abrupt("return",Buffer.from(s.buffer));case 36:case"end":return e.stop()}}),e)})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}();function pe(){return fe.apply(this,arguments)}function fe(){return(fe=f(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new ue(t.lib));case 7:return e.abrupt("return",new ce(t.lib.pbkdf2));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function he(){return(he=f(x.mark((function e(t,r,n){var o,i,c,s,p,f,h,l,y,d,v,b,g;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,o=a.mnemonicToEntropy(t),e.next=9;break;case 4:throw e.prev=4,e.t0=e.catch(0),console.error("Invalid mnemonic phrase provided"),console.error(e.t0),new Error("Not a valid bip39 mnemonic");case 9:return i=Buffer.from(o,"hex"),e.next=12,pe();case 12:return c=e.sent,s=n&&n.getRandomBytes?n.getRandomBytes(16):u.default(16),e.next=16,c.derive(r,s,1e5,48,"sha512");case 16:return f=(p=e.sent).slice(0,16),h=p.slice(16,32),l=p.slice(32,48),e.next=22,D();case 22:return y=e.sent,e.next=25,y.encrypt("aes-128-cbc",f,l,i);case 25:return d=e.sent,v=Buffer.concat([s,d]),e.next=29,F();case 29:return b=e.sent,e.next=32,b.digest(h,v);case 32:return g=Buffer.concat([s,e.sent,d]),e.abrupt("return",g);case 35:case"end":return e.stop()}}),e,null,[[0,4]])})))).apply(this,arguments)}var le=function(e){var t,r;function n(){return e.apply(this,arguments)||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(v(Error));function ye(e,t){return de.apply(this,arguments)}function de(){return(de=f(x.mark((function e(t,r){var n,o,i,c,u,s,p,f,h,l,y,d,v,b,g,m;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.slice(0,16),o=t.slice(16,48),i=t.slice(48),c=Buffer.concat([n,i]),e.next=6,pe();case 6:return u=e.sent,e.next=9,u.derive(r,n,1e5,48,"sha512");case 9:return p=(s=e.sent).slice(0,16),f=s.slice(16,32),h=s.slice(32,48),e.next=15,D();case 15:return l=e.sent,e.next=18,l.decrypt("aes-128-cbc",p,h,i);case 18:return y=e.sent,e.next=21,F();case 21:return d=e.sent,e.next=24,d.digest(f,c);case 24:return v=e.sent,e.next=27,S();case 27:return b=e.sent,e.next=30,b.digest(o);case 30:return g=e.sent,e.next=33,b.digest(v);case 33:if(g.equals(e.sent)){e.next=36;break}throw new le("Wrong password (HMAC mismatch)");case 36:e.prev=36,m=a.entropyToMnemonic(y),e.next=45;break;case 40:throw e.prev=40,e.t0=e.catch(36),console.error("Error thrown by `entropyToMnemonic`"),console.error(e.t0),new le("Wrong password (invalid plaintext)");case 45:if(a.validateMnemonic(m)){e.next=47;break}throw new le("Wrong password (invalid plaintext)");case 47:return e.abrupt("return",m);case 48:case"end":return e.stop()}}),e,null,[[36,40]])})))).apply(this,arguments)}function ve(e,t,r){return new Promise((function(n,o){r||o(new Error("The `triplesec.decrypt` function must be provided")),r({key:Buffer.from(t),data:e},(function(e,t){e?o(e):n(t)}))}))}function be(){return(be=f(x.mark((function e(t,r,n){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=Buffer.isBuffer(t)?t:Buffer.from(t,"hex"),e.prev=1,e.next=4,ye(o,r);case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(1),!(e.t0 instanceof le)){e.next=11;break}throw e.t0;case 11:return e.next=13,ve(o,r,n);case 13:return e.abrupt("return",e.sent.toString());case 15:case"end":return e.stop()}}),e,null,[[1,7]])})))).apply(this,arguments)}function xe(){return(xe=f(x.mark((function e(t,r){var n,o,i,a,c,u;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=Object.assign({},r)).publicKey){e.next=5;break}if(n.privateKey){e.next=4;break}throw new Error("Either public key or private key must be supplied for encryption.");case 4:n.publicKey=A(n.privateKey);case 5:return i="boolean"==typeof n.wasString?n.wasString:"string"==typeof t,a="string"==typeof t?Buffer.from(t):t,e.next=9,re(n.publicKey,a,i,n.cipherTextEncoding);case 9:return c=JSON.stringify(e.sent),n.sign&&("string"==typeof n.sign?o=n.sign:o||(o=n.privateKey),u=ae(o,c),c=JSON.stringify({signature:u.signature,publicKey:u.publicKey,cipherText:c})),e.abrupt("return",c);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}Object.defineProperty(exports,"randomBytes",{enumerable:!0,get:function(){return u.default}}),exports.NodeCryptoSha2Hash=E,exports.WebCryptoSha2Hash=C,exports.aes256CbcEncrypt=J,exports.createSha2Hash=S,exports.decryptContent=function(e,t){var r=Object.assign({},t);if(!r.privateKey)throw new Error("Private key is required for decryption.");try{var n=JSON.parse(e);return oe(r.privateKey,n)}catch(e){throw e instanceof SyntaxError?new Error("Failed to parse encrypted content JSON. The content may not be encrypted. If using getFile, try passing { decrypt: false }."):e}},exports.decryptECIES=oe,exports.decryptMnemonic=function(e,t,r){return be.apply(this,arguments)},exports.ecPairToAddress=function(e){var t=T(P(e.publicKey));return n.address.toBase58Check(t,e.network.pubKeyHash)},exports.ecPairToHexString=function(e){var t=e.privateKey.toString("hex");return e.compressed?t+"01":t},exports.eciesGetJsonStringLength=function(e){var t,r=ee(e),n=r.payloadShell,o=r.payloadValuesLength,i=G(e.contentLength);if(e.cipherTextEncoding&&"hex"!==e.cipherTextEncoding){if("base64"!==e.cipherTextEncoding)throw new Error('Unexpected cipherTextEncoding "'+e.cipherTextEncoding+'"');t=R(i)}else t=2*i;if(e.sign){var a=te(n);return a.signedPayloadShell.length+a.signedPayloadValuesLength+o+t}return n.length+o+t},exports.encryptContent=function(e,t){return xe.apply(this,arguments)},exports.encryptECIES=re,exports.encryptMnemonic=function(e,t,r){return he.apply(this,arguments)},exports.getAesCbcOutputLength=G,exports.getBase64OutputLength=R,exports.getBufferFromBN=$,exports.getCipherObjectWrapper=ee,exports.getEntropy=j,exports.getHexFromBN=function(e){var t=e.toString("hex",64);if(64===t.length)return t;if(t.length<64)return""+"0".repeat(64-t.length)+t;throw new Error("Generated a > 32-byte BN for encryption. Failing.")},exports.getPublicKeyFromPrivate=A,exports.getSignedCipherObjectWrapper=te,exports.hashCode=function(e){var t=0;if(0===e.length)return t;for(var r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return 2147483647&t},exports.hashSha256Sync=P,exports.hashSha512Sync=K,exports.hexStringToECPair=function(e,t){var r={network:t||n.networks.bitcoin,compressed:!0};if(66===e.length){if("01"!==e.slice(64))throw new Error("Improperly formatted private-key hex string. 66-length hex usually indicates compressed key, but last byte must be == 1");return n.ECPair.fromPrivateKey(Buffer.from(e.slice(0,64),"hex"),r)}if(64===e.length)return r.compressed=!1,n.ECPair.fromPrivateKey(Buffer.from(e,"hex"),r);throw new Error("Improperly formatted private-key hex string: length should be 64 or 66.")},exports.makeECPrivateKey=function(){return n.ECPair.makeRandom({rng:j}).privateKey.toString("hex")},exports.publicKeyToAddress=function(e){var t=T(P(Buffer.isBuffer(e)?e:Buffer.from(e,"hex")));return n.address.toBase58Check(t,n.networks.bitcoin.pubKeyHash)},exports.signECDSA=ae,exports.verifyECDSA=function(e,t,r){var n=function(e){return e instanceof Buffer?e:(ArrayBuffer,Buffer.from(e))}(e),o=I.keyFromPublic(t,"hex"),i=P(n);return o.verify(i,r)};
//# sourceMappingURL=encryption.cjs.production.min.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("elliptic"),require("randombytes"),require("@stacks/common"),require("bitcoinjs-lib"),require("sha.js"),require("ripemd160-min"),require("bip39")):"function"==typeof define&&define.amd?define(["exports","elliptic","randombytes","@stacks/common","bitcoinjs-lib","sha.js","ripemd160-min","bip39"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@stacks/encryption"]={},e.elliptic,e.randomBytes,e.common,e.bitcoinjsLib,e.sha_js,e.Ripemd160Polyfill,e.bip39)}(this,(function(e,t,r,n,o,i,a,c){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=u(r),p=u(a);function f(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){f(i,n,o,a,c,"next",e)}function c(e){f(i,n,o,a,c,"throw",e)}a(void 0)}))}}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function y(e,t){return(y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function d(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function v(e,t,r){return(v=d()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&y(o,r.prototype),o}).apply(null,arguments)}function b(e){var t="function"==typeof Map?new Map:void 0;return(b=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return v(e,arguments,l(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)})(e)}function m(e,t){return e(t={exports:{}},t.exports),t.exports}var g=m((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),i=new E(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,i),o}function s(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p={};function f(){}function h(){}function l(){}var y={};y[o]=function(){return this};var d=Object.getPrototypeOf,v=d&&d(d(C([])));v&&v!==t&&r.call(v,o)&&(y=v);var b=l.prototype=f.prototype=Object.create(y);function m(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function g(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,c){var u=s(e[o],e,i);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(f).then((function(e){p.value=e,a(p)}),(function(e){return n("throw",e,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=s(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function C(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=b.constructor=l,l.constructor=h,h.displayName=c(l,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,c(e,a,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},m(g.prototype),g.prototype[i]=function(){return this},e.AsyncIterator=g,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new g(u(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},m(b),c(b,a,"Generator"),b[o]=function(){return this},b.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=C,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));function x(){return"undefined"!=typeof crypto&&void 0!==crypto.subtle}var w='Crypto lib not found. Either the WebCrypto "crypto.subtle" or Node.js "crypto" module must be available.';function k(){return E.apply(this,arguments)}function E(){return(E=h(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!x()){e.next=4;break}return e.abrupt("return",{lib:crypto.subtle,name:"subtleCrypto"});case 4:return e.prev=4,t=require("crypto"),e.abrupt("return",{lib:t,name:"nodeCrypto"});case 9:throw e.prev=9,e.t0=e.catch(4),new Error(w);case 12:case"end":return e.stop()}}),e,null,[[4,9]])})))).apply(this,arguments)}var C=function(){function e(e){this.createHash=e}return e.prototype.digest=function(){var e=h(g.mark((function e(t,r){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===r&&(r="sha256"),e.prev=1,n=this.createHash(r).update(t).digest(),e.abrupt("return",Promise.resolve(n));case 6:return e.prev=6,e.t0=e.catch(1),console.log(e.t0),console.log("Error performing "+r+" digest with Node.js 'crypto.createHash', falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===r?K(t):L(t)));case 11:case"end":return e.stop()}}),e,this,[[1,6]])})));return function(t,r){return e.apply(this,arguments)}}(),e}(),S=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=h(g.mark((function e(t,r){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r="sha256"),"sha256"!==r){e.next=5;break}n="SHA-256",e.next=10;break;case 5:if("sha512"!==r){e.next=9;break}n="SHA-512",e.next=10;break;case 9:throw new Error("Unsupported hash algorithm "+r);case 10:return e.prev=10,e.next=13,this.subtleCrypto.digest(n,t);case 13:return e.abrupt("return",Buffer.from(e.sent));case 17:return e.prev=17,e.t0=e.catch(10),console.log(e.t0),console.log("Error performing "+r+" digest with WebCrypto, falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===r?K(t):L(t)));case 22:case"end":return e.stop()}}),e,this,[[10,17]])})));return function(t,r){return e.apply(this,arguments)}}(),e}();function B(){return P.apply(this,arguments)}function P(){return(P=h(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new S(t.lib));case 7:return e.abrupt("return",new C(t.lib.createHash));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function K(e){var t=new i.sha256;return t.update(e),t.digest()}function L(e){var t=new i.sha512;return t.update(e),t.digest()}var T=function(){function e(){}return e.prototype.digest=function(e){var t=new p.default;t.update(e);var r=t.digest();return Array.isArray(r)?Buffer.from(r):Buffer.from(r.buffer)},e}(),j=function(){function e(e){this.nodeCryptoCreateHash=e}return e.prototype.digest=function(e){try{return this.nodeCryptoCreateHash("rmd160").update(e).digest()}catch(t){try{return this.nodeCryptoCreateHash("ripemd160").update(e).digest()}catch(r){return console.log(t),console.log("Node.js `crypto.createHash` exists but failing to digest for ripemd160, falling back to js implementation"),(new T).digest(e)}}},e}();function O(e){return(t=function(e){try{if(!require.resolve("crypto"))return!1;var t=require("crypto");return!!t&&(!e||e(t))}catch(e){return!1}}((function(e){return"function"==typeof e.createHash&&e.createHash})),t?new j(t):new T).digest(e);var t}function H(e){return e||(e=32),s.default(e)}function A(e){var t=Buffer.isBuffer(e)?e:Buffer.from(e,"hex");return o.ECPair.fromPrivateKey(t).publicKey.toString("hex")}var _=function(){function e(e){this.createHmac=e}return e.prototype.digest=function(){var e=h(g.mark((function e(t,r){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.createHmac("sha256",t).update(r).digest(),e.abrupt("return",Promise.resolve(n));case 2:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),e}(),F=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=h(g.mark((function e(t,r){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.subtleCrypto.importKey("raw",t,{name:"HMAC",hash:"SHA-256"},!0,["sign"]);case 2:return n=e.sent,e.next=5,this.subtleCrypto.sign({name:"HMAC",hash:"SHA-256"},n,r);case 5:return e.abrupt("return",Buffer.from(e.sent));case 7:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),e}();function N(){return M.apply(this,arguments)}function M(){return(M=h(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new F(t.lib));case 7:return e.abrupt("return",new _(t.lib.createHmac));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var U=function(){function e(e,t){this.createCipher=e,this.createDecipher=t}var t=e.prototype;return t.encrypt=function(){var e=h(g.mark((function e(t,r,n,o){var i,a;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===t||"aes-256-cbc"===t){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+t+'"');case 2:return i=this.createCipher(t,r,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),t.decrypt=function(){var e=h(g.mark((function e(t,r,n,o){var i,a;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===t||"aes-256-cbc"===t){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+t+'"');case 2:return i=this.createDecipher(t,r,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),e}(),D=function(){function e(e){this.subtleCrypto=e}var t=e.prototype;return t.encrypt=function(){var e=h(g.mark((function e(t,r,n,o){var i,a,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==t){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==t){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+t+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",r,{name:i,length:a},!1,["encrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.encrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),t.decrypt=function(){var e=h(g.mark((function e(t,r,n,o){var i,a,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==t){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==t){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+t+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",r,{name:i,length:a},!1,["decrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.decrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),e}();function q(){return R.apply(this,arguments)}function R(){return(R=h(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new D(t.lib));case 7:return e.abrupt("return",new U(t.lib.createCipheriv,t.lib.createDecipheriv));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var G=new t.ec("secp256k1");function I(e,t,r){return J.apply(this,arguments)}function J(){return(J=h(g.mark((function e(t,r,n){var o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,q();case 2:return o=e.sent,e.next=5,o.encrypt("aes-256-cbc",r,t,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function W(e,t,r){return V.apply(this,arguments)}function V(){return(V=h(g.mark((function e(t,r,n){var o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,q();case 2:return o=e.sent,e.next=5,o.decrypt("aes-256-cbc",r,t,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Y(e,t){return z.apply(this,arguments)}function z(){return(z=h(g.mark((function e(t,r){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,N();case 2:return e.abrupt("return",e.sent.digest(t,r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Q(e,t){if(e.length!==t.length)return!1;for(var r=0,n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r}function X(e){var t=L(e);return{encryptionKey:t.slice(0,32),hmacKey:t.slice(32)}}function Z(e){var t=e.toArrayLike(Buffer,"be",32);if(32!==t.byteLength)throw new Error("Generated a 32-byte BN for encryption. Failing.");return t}function $(e){var t={iv:"",ephemeralPK:"",mac:"",cipherText:"",wasString:!!e.wasString};return"base64"===e.cipherTextEncoding&&(t.cipherTextEncoding="base64"),{payloadValuesLength:162,payloadShell:JSON.stringify(t)}}function ee(e){return{signedPayloadValuesLength:210,signedPayloadShell:JSON.stringify({signature:"",publicKey:"",cipherText:e})}}function te(e,t,r,n){return re.apply(this,arguments)}function re(){return(re=h(g.mark((function e(t,r,n,o){var i,a,c,u,p,f,h,l,y,d,v,b;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=G.keyFromPublic(t,"hex").getPublic(),a=G.genKeyPair(),c=Buffer.from(a.getPublic().encodeCompressed()),u=a.derive(i),p=Z(u),f=X(p),h=s.default(16),e.next=9,I(h,f.encryptionKey,r);case 9:return l=e.sent,y=Buffer.concat([h,c,l]),e.next=13,Y(f.hmacKey,y);case 13:if(d=e.sent,o&&"hex"!==o){e.next=18;break}v=l.toString("hex"),e.next=23;break;case 18:if("base64"!==o){e.next=22;break}v=l.toString("base64"),e.next=23;break;case 22:throw new Error('Unexpected cipherTextEncoding "'+o+'"');case 23:return b={iv:h.toString("hex"),ephemeralPK:c.toString("hex"),cipherText:v,mac:d.toString("hex"),wasString:!!n},o&&"hex"!==o&&(b.cipherTextEncoding=o),e.abrupt("return",b);case 26:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ne(e,t){return oe.apply(this,arguments)}function oe(){return(oe=h(g.mark((function e(t,r){var o,i,a,c,u,s,p,f,h,l;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=G.keyFromPrivate(t,"hex"),i=null,e.prev=2,i=G.keyFromPublic(r.ephemeralPK,"hex").getPublic(),e.next=9;break;case 6:throw e.prev=6,e.t0=e.catch(2),new n.FailedDecryptionError("Unable to get public key from cipher object. You might be trying to decrypt an unencrypted object.");case 9:if(a=o.derive(i),c=Z(a),u=X(c),s=Buffer.from(r.iv,"hex"),r.cipherTextEncoding&&"hex"!==r.cipherTextEncoding){e.next=17;break}p=Buffer.from(r.cipherText,"hex"),e.next=22;break;case 17:if("base64"!==r.cipherTextEncoding){e.next=21;break}p=Buffer.from(r.cipherText,"base64"),e.next=22;break;case 21:throw new Error('Unexpected cipherTextEncoding "'+r.cipherText+'"');case 22:return f=Buffer.concat([s,Buffer.from(i.encodeCompressed()),p]),e.next=25,Y(u.hmacKey,f);case 25:if(h=e.sent,Q(Buffer.from(r.mac,"hex"),h)){e.next=29;break}throw new n.FailedDecryptionError("Decryption failed: failure in MAC check");case 29:return e.next=31,W(s,u.encryptionKey,p);case 31:if(l=e.sent,!r.wasString){e.next=36;break}return e.abrupt("return",l.toString());case 36:return e.abrupt("return",l);case 37:case"end":return e.stop()}}),e,null,[[2,6]])})))).apply(this,arguments)}function ie(e,t){var r=t instanceof Buffer?t:Buffer.from(t),n=G.keyFromPrivate(e,"hex"),o=A(e),i=K(r);return{signature:n.sign(i).toDER("hex"),publicKey:o}}var ae=function(){function e(e){this.nodePbkdf2=e}return e.prototype.derive=function(){var e=h(g.mark((function e(t,r,n,o,i){var a=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha512"===i||"sha256"===i){e.next=2;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 2:return e.abrupt("return",new Promise((function(e,c){a.nodePbkdf2(t,r,n,o,i,(function(t,r){t&&c(t),e(r)}))})));case 3:case"end":return e.stop()}}),e)})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}(),ce=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=h(g.mark((function e(t,r,n,o,i){var a,c,u,s,p;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha256"!==i){e.next=4;break}a="SHA-256",e.next=9;break;case 4:if("sha512"!==i){e.next=8;break}a="SHA-512",e.next=9;break;case 8:throw new Error('Unsupported Pbkdf2 digest algorithm "'+i+'"');case 9:return u=Buffer.from(t,"utf8"),e.prev=10,e.next=13,this.subtleCrypto.importKey("raw",u,"PBKDF2",!1,["deriveBits"]);case 13:return s=e.sent,e.next=16,this.subtleCrypto.deriveBits({name:"PBKDF2",salt:r,iterations:n,hash:{name:a}},s,8*o);case 16:c=e.sent,e.next=23;break;case 19:return e.prev=19,e.t0=e.catch(10),p=new ue(this.subtleCrypto),e.abrupt("return",p.derive(t,r,n,o,i));case 23:return e.abrupt("return",Buffer.from(c));case 24:case"end":return e.stop()}}),e,this,[[10,19]])})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}(),ue=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=h(g.mark((function e(t,r,n,o,i){var a,c,u,s,p,f,h,l,y,d,v,b,m,x,w,k=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d=function(e,t,r){return e[r>>>=0]=(t=+t)>>>24,e[r+1]=t>>>16,e[r+2]=t>>>8,e[r+3]=255&t,r+4},"sha512"===i||"sha256"===i){e.next=3;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 3:a=Buffer.from(t,"utf8"),c={name:"HMAC",hash:"sha512"===i?"SHA-512":"SHA-256"},u=function(e,t){return k.subtleCrypto.importKey("raw",e,c,!0,["sign"]).then((function(e){return k.subtleCrypto.sign(c,e,t)})).then((function(e){return new Uint8Array(e)}))},s=new Uint8Array(o),p=r.length,(f=new Uint8Array(p+4)).set(r),h=0,l="sha512"===i?64:32,y=Math.ceil(o/l),v=1;case 15:if(!(v<=y)){e.next=35;break}return d(f,v,p),e.next=19,u(a,f);case 19:m=b=e.sent,x=1;case 22:if(!(x<n)){e.next=30;break}return e.next=25,u(a,m);case 25:for(m=e.sent,w=0;w<l;w++)b[w]^=m[w];case 27:x++,e.next=22;break;case 30:s.set(b.subarray(0,s.byteLength-h),h),h+=l;case 32:v++,e.next=15;break;case 35:return e.abrupt("return",Buffer.from(s.buffer));case 36:case"end":return e.stop()}}),e)})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}();function se(){return pe.apply(this,arguments)}function pe(){return(pe=h(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new ce(t.lib));case 7:return e.abrupt("return",new ae(t.lib.pbkdf2));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function fe(){return(fe=h(g.mark((function e(t,r,n){var o,i,a,u,p,f,h,l,y,d,v,b,m;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,o=c.mnemonicToEntropy(t),e.next=9;break;case 4:throw e.prev=4,e.t0=e.catch(0),console.error("Invalid mnemonic phrase provided"),console.error(e.t0),new Error("Not a valid bip39 mnemonic");case 9:return i=Buffer.from(o,"hex"),e.next=12,se();case 12:return a=e.sent,u=n&&n.getRandomBytes?n.getRandomBytes(16):s.default(16),e.next=16,a.derive(r,u,1e5,48,"sha512");case 16:return f=(p=e.sent).slice(0,16),h=p.slice(16,32),l=p.slice(32,48),e.next=22,q();case 22:return y=e.sent,e.next=25,y.encrypt("aes-128-cbc",f,l,i);case 25:return d=e.sent,v=Buffer.concat([u,d]),e.next=29,N();case 29:return b=e.sent,e.next=32,b.digest(h,v);case 32:return m=Buffer.concat([u,e.sent,d]),e.abrupt("return",m);case 35:case"end":return e.stop()}}),e,null,[[0,4]])})))).apply(this,arguments)}var he=function(e){var t,r;function n(){return e.apply(this,arguments)||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(b(Error));function le(e,t){return ye.apply(this,arguments)}function ye(){return(ye=h(g.mark((function e(t,r){var n,o,i,a,u,s,p,f,h,l,y,d,v,b,m,x;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.slice(0,16),o=t.slice(16,48),i=t.slice(48),a=Buffer.concat([n,i]),e.next=6,se();case 6:return u=e.sent,e.next=9,u.derive(r,n,1e5,48,"sha512");case 9:return p=(s=e.sent).slice(0,16),f=s.slice(16,32),h=s.slice(32,48),e.next=15,q();case 15:return l=e.sent,e.next=18,l.decrypt("aes-128-cbc",p,h,i);case 18:return y=e.sent,e.next=21,N();case 21:return d=e.sent,e.next=24,d.digest(f,a);case 24:return v=e.sent,e.next=27,B();case 27:return b=e.sent,e.next=30,b.digest(o);case 30:return m=e.sent,e.next=33,b.digest(v);case 33:if(m.equals(e.sent)){e.next=36;break}throw new he("Wrong password (HMAC mismatch)");case 36:e.prev=36,x=c.entropyToMnemonic(y),e.next=45;break;case 40:throw e.prev=40,e.t0=e.catch(36),console.error("Error thrown by `entropyToMnemonic`"),console.error(e.t0),new he("Wrong password (invalid plaintext)");case 45:if(c.validateMnemonic(x)){e.next=47;break}throw new he("Wrong password (invalid plaintext)");case 47:return e.abrupt("return",x);case 48:case"end":return e.stop()}}),e,null,[[36,40]])})))).apply(this,arguments)}function de(e,t,r){return new Promise((function(n,o){r||o(new Error("The `triplesec.decrypt` function must be provided")),r({key:Buffer.from(t),data:e},(function(e,t){e?o(e):n(t)}))}))}function ve(){return(ve=h(g.mark((function e(t,r,n){var o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=Buffer.isBuffer(t)?t:Buffer.from(t,"hex"),e.prev=1,e.next=4,le(o,r);case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(1),!(e.t0 instanceof he)){e.next=11;break}throw e.t0;case 11:return e.next=13,de(o,r,n);case 13:return e.abrupt("return",e.sent.toString());case 15:case"end":return e.stop()}}),e,null,[[1,7]])})))).apply(this,arguments)}function be(){return(be=h(g.mark((function e(t,r){var n,o,i,a,c,u;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=Object.assign({},r)).publicKey){e.next=5;break}if(n.privateKey){e.next=4;break}throw new Error("Either public key or private key must be supplied for encryption.");case 4:n.publicKey=A(n.privateKey);case 5:return i="boolean"==typeof n.wasString?n.wasString:"string"==typeof t,a="string"==typeof t?Buffer.from(t):t,e.next=9,te(n.publicKey,a,i,n.cipherTextEncoding);case 9:return c=JSON.stringify(e.sent),n.sign&&("string"==typeof n.sign?o=n.sign:o||(o=n.privateKey),u=ie(o,c),c=JSON.stringify({signature:u.signature,publicKey:u.publicKey,cipherText:c})),e.abrupt("return",c);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}Object.defineProperty(e,"randomBytes",{enumerable:!0,get:function(){return s.default}}),e.NodeCryptoSha2Hash=C,e.WebCryptoSha2Hash=S,e.aes256CbcEncrypt=I,e.createSha2Hash=B,e.decryptContent=function(e,t){var r=Object.assign({},t);if(!r.privateKey)throw new Error("Private key is required for decryption.");try{var n=JSON.parse(e);return ne(r.privateKey,n)}catch(e){throw e instanceof SyntaxError?new Error("Failed to parse encrypted content JSON. The content may not be encrypted. If using getFile, try passing { decrypt: false }."):e}},e.decryptECIES=ne,e.decryptMnemonic=function(e,t,r){return ve.apply(this,arguments)},e.ecPairToAddress=function(e){var t=O(K(e.publicKey));return o.address.toBase58Check(t,e.network.pubKeyHash)},e.ecPairToHexString=function(e){var t=e.privateKey.toString("hex");return e.compressed?t+"01":t},e.eciesGetJsonStringLength=function(e){var t,r=$(e),n=r.payloadShell,o=r.payloadValuesLength,i=16*(Math.floor(e.contentLength/16)+1);if(e.cipherTextEncoding&&"hex"!==e.cipherTextEncoding){if("base64"!==e.cipherTextEncoding)throw new Error('Unexpected cipherTextEncoding "'+e.cipherTextEncoding+'"');t=4*Math.ceil(i/3)}else t=2*i;if(e.sign){var a=ee(n);return a.signedPayloadShell.length+a.signedPayloadValuesLength+o+t}return n.length+o+t},e.encryptContent=function(e,t){return be.apply(this,arguments)},e.encryptECIES=te,e.encryptMnemonic=function(e,t,r){return fe.apply(this,arguments)},e.getBufferFromBN=Z,e.getCipherObjectWrapper=$,e.getEntropy=H,e.getHexFromBN=function(e){var t=e.toString("hex",64);if(64===t.length)return t;if(t.length<64)return""+"0".repeat(64-t.length)+t;throw new Error("Generated a > 32-byte BN for encryption. Failing.")},e.getPublicKeyFromPrivate=A,e.getSignedCipherObjectWrapper=ee,e.hashSha256Sync=K,e.hashSha512Sync=L,e.hexStringToECPair=function(e,t){var r={network:t||o.networks.bitcoin,compressed:!0};if(66===e.length){if("01"!==e.slice(64))throw new Error("Improperly formatted private-key hex string. 66-length hex usually indicates compressed key, but last byte must be == 1");return o.ECPair.fromPrivateKey(Buffer.from(e.slice(0,64),"hex"),r)}if(64===e.length)return r.compressed=!1,o.ECPair.fromPrivateKey(Buffer.from(e,"hex"),r);throw new Error("Improperly formatted private-key hex string: length should be 64 or 66.")},e.makeECPrivateKey=function(){return o.ECPair.makeRandom({rng:H}).privateKey.toString("hex")},e.publicKeyToAddress=function(e){var t=O(K(Buffer.isBuffer(e)?e:Buffer.from(e,"hex")));return o.address.toBase58Check(t,o.networks.bitcoin.pubKeyHash)},e.signECDSA=ie,e.verifyECDSA=function(e,t,r){var n=function(e){return e instanceof Buffer?e:(ArrayBuffer,Buffer.from(e))}(e),o=G.keyFromPublic(t,"hex"),i=K(n);return o.verify(i,r)},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("elliptic"),require("randombytes"),require("@stacks/common"),require("bitcoinjs-lib"),require("sha.js"),require("ripemd160-min"),require("bip39")):"function"==typeof define&&define.amd?define(["exports","elliptic","randombytes","@stacks/common","bitcoinjs-lib","sha.js","ripemd160-min","bip39"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@stacks/encryption"]={},e.elliptic,e.randomBytes,e.common,e.bitcoinjsLib,e.sha_js,e.Ripemd160Polyfill,e.bip39)}(this,(function(e,t,r,n,o,i,a,c){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=u(r),p=u(a);function f(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){f(i,n,o,a,c,"next",e)}function c(e){f(i,n,o,a,c,"throw",e)}a(void 0)}))}}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function y(e,t){return(y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function d(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function v(e,t,r){return(v=d()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&y(o,r.prototype),o}).apply(null,arguments)}function b(e){var t="function"==typeof Map?new Map:void 0;return(b=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return v(e,arguments,l(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)})(e)}function g(e,t){return e(t={exports:{}},t.exports),t.exports}var m=g((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),i=new E(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,i),o}function s(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p={};function f(){}function h(){}function l(){}var y={};y[o]=function(){return this};var d=Object.getPrototypeOf,v=d&&d(d(C([])));v&&v!==t&&r.call(v,o)&&(y=v);var b=l.prototype=f.prototype=Object.create(y);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function m(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,c){var u=s(e[o],e,i);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(f).then((function(e){p.value=e,a(p)}),(function(e){return n("throw",e,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=s(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function C(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=b.constructor=l,l.constructor=h,h.displayName=c(l,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,c(e,a,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},g(m.prototype),m.prototype[i]=function(){return this},e.AsyncIterator=m,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new m(u(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},g(b),c(b,a,"Generator"),b[o]=function(){return this},b.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=C,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));function x(){return"undefined"!=typeof crypto&&void 0!==crypto.subtle}var w='Crypto lib not found. Either the WebCrypto "crypto.subtle" or Node.js "crypto" module must be available.';function k(){return E.apply(this,arguments)}function E(){return(E=h(m.mark((function e(){var t;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!x()){e.next=4;break}return e.abrupt("return",{lib:crypto.subtle,name:"subtleCrypto"});case 4:return e.prev=4,t=require("crypto"),e.abrupt("return",{lib:t,name:"nodeCrypto"});case 9:throw e.prev=9,e.t0=e.catch(4),new Error(w);case 12:case"end":return e.stop()}}),e,null,[[4,9]])})))).apply(this,arguments)}var C=function(){function e(e){this.createHash=e}return e.prototype.digest=function(){var e=h(m.mark((function e(t,r){var n;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===r&&(r="sha256"),e.prev=1,n=this.createHash(r).update(t).digest(),e.abrupt("return",Promise.resolve(n));case 6:return e.prev=6,e.t0=e.catch(1),console.log(e.t0),console.log("Error performing "+r+" digest with Node.js 'crypto.createHash', falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===r?K(t):L(t)));case 11:case"end":return e.stop()}}),e,this,[[1,6]])})));return function(t,r){return e.apply(this,arguments)}}(),e}(),S=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=h(m.mark((function e(t,r){var n;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r="sha256"),"sha256"!==r){e.next=5;break}n="SHA-256",e.next=10;break;case 5:if("sha512"!==r){e.next=9;break}n="SHA-512",e.next=10;break;case 9:throw new Error("Unsupported hash algorithm "+r);case 10:return e.prev=10,e.next=13,this.subtleCrypto.digest(n,t);case 13:return e.abrupt("return",Buffer.from(e.sent));case 17:return e.prev=17,e.t0=e.catch(10),console.log(e.t0),console.log("Error performing "+r+" digest with WebCrypto, falling back to JS implementation."),e.abrupt("return",Promise.resolve("sha256"===r?K(t):L(t)));case 22:case"end":return e.stop()}}),e,this,[[10,17]])})));return function(t,r){return e.apply(this,arguments)}}(),e}();function B(){return P.apply(this,arguments)}function P(){return(P=h(m.mark((function e(){var t;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new S(t.lib));case 7:return e.abrupt("return",new C(t.lib.createHash));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function K(e){var t=new i.sha256;return t.update(e),t.digest()}function L(e){var t=new i.sha512;return t.update(e),t.digest()}var T=function(){function e(){}return e.prototype.digest=function(e){var t=new p.default;t.update(e);var r=t.digest();return Array.isArray(r)?Buffer.from(r):Buffer.from(r.buffer)},e}(),j=function(){function e(e){this.nodeCryptoCreateHash=e}return e.prototype.digest=function(e){try{return this.nodeCryptoCreateHash("rmd160").update(e).digest()}catch(t){try{return this.nodeCryptoCreateHash("ripemd160").update(e).digest()}catch(r){return console.log(t),console.log("Node.js `crypto.createHash` exists but failing to digest for ripemd160, falling back to js implementation"),(new T).digest(e)}}},e}();function O(e){return(t=function(e){try{if(!require.resolve("crypto"))return!1;var t=require("crypto");return!!t&&(!e||e(t))}catch(e){return!1}}((function(e){return"function"==typeof e.createHash&&e.createHash})),t?new j(t):new T).digest(e);var t}function A(e){return e||(e=32),s.default(e)}function H(e){var t=Buffer.isBuffer(e)?e:Buffer.from(e,"hex");return o.ECPair.fromPrivateKey(t).publicKey.toString("hex")}var _=function(){function e(e){this.createHmac=e}return e.prototype.digest=function(){var e=h(m.mark((function e(t,r){var n;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.createHmac("sha256",t).update(r).digest(),e.abrupt("return",Promise.resolve(n));case 2:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),e}(),F=function(){function e(e){this.subtleCrypto=e}return e.prototype.digest=function(){var e=h(m.mark((function e(t,r){var n;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.subtleCrypto.importKey("raw",t,{name:"HMAC",hash:"SHA-256"},!0,["sign"]);case 2:return n=e.sent,e.next=5,this.subtleCrypto.sign({name:"HMAC",hash:"SHA-256"},n,r);case 5:return e.abrupt("return",Buffer.from(e.sent));case 7:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),e}();function N(){return M.apply(this,arguments)}function M(){return(M=h(m.mark((function e(){var t;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new F(t.lib));case 7:return e.abrupt("return",new _(t.lib.createHmac));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var U=function(){function e(e,t){this.createCipher=e,this.createDecipher=t}var t=e.prototype;return t.encrypt=function(){var e=h(m.mark((function e(t,r,n,o){var i,a;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===t||"aes-256-cbc"===t){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+t+'"');case 2:return i=this.createCipher(t,r,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),t.decrypt=function(){var e=h(m.mark((function e(t,r,n,o){var i,a;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"===t||"aes-256-cbc"===t){e.next=2;break}throw new Error('Unsupported cipher algorithm "'+t+'"');case 2:return i=this.createDecipher(t,r,n),a=Buffer.concat([i.update(o),i.final()]),e.abrupt("return",Promise.resolve(a));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),e}(),D=function(){function e(e){this.subtleCrypto=e}var t=e.prototype;return t.encrypt=function(){var e=h(m.mark((function e(t,r,n,o){var i,a,c;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==t){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==t){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+t+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",r,{name:i,length:a},!1,["encrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.encrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),t.decrypt=function(){var e=h(m.mark((function e(t,r,n,o){var i,a,c;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("aes-128-cbc"!==t){e.next=5;break}i="AES-CBC",a=128,e.next=11;break;case 5:if("aes-256-cbc"!==t){e.next=10;break}i="AES-CBC",a=256,e.next=11;break;case 10:throw new Error('Unsupported cipher algorithm "'+t+'"');case 11:return e.next=13,this.subtleCrypto.importKey("raw",r,{name:i,length:a},!1,["decrypt"]);case 13:return c=e.sent,e.next=16,this.subtleCrypto.decrypt({name:i,iv:n},c,o);case 16:return e.abrupt("return",Buffer.from(e.sent));case 18:case"end":return e.stop()}}),e,this)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),e}();function q(){return R.apply(this,arguments)}function R(){return(R=h(m.mark((function e(){var t;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new D(t.lib));case 7:return e.abrupt("return",new U(t.lib.createCipheriv,t.lib.createDecipheriv));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function G(e){return 16*(Math.floor(e/16)+1)}function I(e){return 4*Math.ceil(e/3)}var J=new t.ec("secp256k1");function W(e,t,r){return V.apply(this,arguments)}function V(){return(V=h(m.mark((function e(t,r,n){var o;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,q();case 2:return o=e.sent,e.next=5,o.encrypt("aes-256-cbc",r,t,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Y(e,t,r){return z.apply(this,arguments)}function z(){return(z=h(m.mark((function e(t,r,n){var o;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,q();case 2:return o=e.sent,e.next=5,o.decrypt("aes-256-cbc",r,t,n);case 5:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Q(e,t){return X.apply(this,arguments)}function X(){return(X=h(m.mark((function e(t,r){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,N();case 2:return e.abrupt("return",e.sent.digest(t,r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Z(e,t){if(e.length!==t.length)return!1;for(var r=0,n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r}function $(e){var t=L(e);return{encryptionKey:t.slice(0,32),hmacKey:t.slice(32)}}function ee(e){var t=e.toArrayLike(Buffer,"be",32);if(32!==t.byteLength)throw new Error("Generated a 32-byte BN for encryption. Failing.");return t}function te(e){var t={iv:"",ephemeralPK:"",mac:"",cipherText:"",wasString:!!e.wasString};return"base64"===e.cipherTextEncoding&&(t.cipherTextEncoding="base64"),{payloadValuesLength:162,payloadShell:JSON.stringify(t)}}function re(e){return{signedPayloadValuesLength:210,signedPayloadShell:JSON.stringify({signature:"",publicKey:"",cipherText:e})}}function ne(e,t,r,n){return oe.apply(this,arguments)}function oe(){return(oe=h(m.mark((function e(t,r,n,o){var i,a,c,u,p,f,h,l,y,d,v,b;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=J.keyFromPublic(t,"hex").getPublic(),a=J.genKeyPair(),c=Buffer.from(a.getPublic().encodeCompressed()),u=a.derive(i),p=ee(u),f=$(p),h=s.default(16),e.next=9,W(h,f.encryptionKey,r);case 9:return l=e.sent,y=Buffer.concat([h,c,l]),e.next=13,Q(f.hmacKey,y);case 13:if(d=e.sent,o&&"hex"!==o){e.next=18;break}v=l.toString("hex"),e.next=23;break;case 18:if("base64"!==o){e.next=22;break}v=l.toString("base64"),e.next=23;break;case 22:throw new Error('Unexpected cipherTextEncoding "'+o+'"');case 23:return b={iv:h.toString("hex"),ephemeralPK:c.toString("hex"),cipherText:v,mac:d.toString("hex"),wasString:!!n},o&&"hex"!==o&&(b.cipherTextEncoding=o),e.abrupt("return",b);case 26:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ie(e,t){return ae.apply(this,arguments)}function ae(){return(ae=h(m.mark((function e(t,r){var o,i,a,c,u,s,p,f,h,l;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=J.keyFromPrivate(t,"hex"),i=null,e.prev=2,i=J.keyFromPublic(r.ephemeralPK,"hex").getPublic(),e.next=9;break;case 6:throw e.prev=6,e.t0=e.catch(2),new n.FailedDecryptionError("Unable to get public key from cipher object. You might be trying to decrypt an unencrypted object.");case 9:if(a=o.derive(i),c=ee(a),u=$(c),s=Buffer.from(r.iv,"hex"),r.cipherTextEncoding&&"hex"!==r.cipherTextEncoding){e.next=17;break}p=Buffer.from(r.cipherText,"hex"),e.next=22;break;case 17:if("base64"!==r.cipherTextEncoding){e.next=21;break}p=Buffer.from(r.cipherText,"base64"),e.next=22;break;case 21:throw new Error('Unexpected cipherTextEncoding "'+r.cipherText+'"');case 22:return f=Buffer.concat([s,Buffer.from(i.encodeCompressed()),p]),e.next=25,Q(u.hmacKey,f);case 25:if(h=e.sent,Z(Buffer.from(r.mac,"hex"),h)){e.next=29;break}throw new n.FailedDecryptionError("Decryption failed: failure in MAC check");case 29:return e.next=31,Y(s,u.encryptionKey,p);case 31:if(l=e.sent,!r.wasString){e.next=36;break}return e.abrupt("return",l.toString());case 36:return e.abrupt("return",l);case 37:case"end":return e.stop()}}),e,null,[[2,6]])})))).apply(this,arguments)}function ce(e,t){var r=t instanceof Buffer?t:Buffer.from(t),n=J.keyFromPrivate(e,"hex"),o=H(e),i=K(r);return{signature:n.sign(i).toDER("hex"),publicKey:o}}var ue=function(){function e(e){this.nodePbkdf2=e}return e.prototype.derive=function(){var e=h(m.mark((function e(t,r,n,o,i){var a=this;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha512"===i||"sha256"===i){e.next=2;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 2:return e.abrupt("return",new Promise((function(e,c){a.nodePbkdf2(t,r,n,o,i,(function(t,r){t&&c(t),e(r)}))})));case 3:case"end":return e.stop()}}),e)})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}(),se=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=h(m.mark((function e(t,r,n,o,i){var a,c,u,s,p;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("sha256"!==i){e.next=4;break}a="SHA-256",e.next=9;break;case 4:if("sha512"!==i){e.next=8;break}a="SHA-512",e.next=9;break;case 8:throw new Error('Unsupported Pbkdf2 digest algorithm "'+i+'"');case 9:return u=Buffer.from(t,"utf8"),e.prev=10,e.next=13,this.subtleCrypto.importKey("raw",u,"PBKDF2",!1,["deriveBits"]);case 13:return s=e.sent,e.next=16,this.subtleCrypto.deriveBits({name:"PBKDF2",salt:r,iterations:n,hash:{name:a}},s,8*o);case 16:c=e.sent,e.next=23;break;case 19:return e.prev=19,e.t0=e.catch(10),p=new pe(this.subtleCrypto),e.abrupt("return",p.derive(t,r,n,o,i));case 23:return e.abrupt("return",Buffer.from(c));case 24:case"end":return e.stop()}}),e,this,[[10,19]])})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}(),pe=function(){function e(e){this.subtleCrypto=e}return e.prototype.derive=function(){var e=h(m.mark((function e(t,r,n,o,i){var a,c,u,s,p,f,h,l,y,d,v,b,g,x,w,k=this;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d=function(e,t,r){return e[r>>>=0]=(t=+t)>>>24,e[r+1]=t>>>16,e[r+2]=t>>>8,e[r+3]=255&t,r+4},"sha512"===i||"sha256"===i){e.next=3;break}throw new Error('Unsupported digest "'+i+'" for Pbkdf2');case 3:a=Buffer.from(t,"utf8"),c={name:"HMAC",hash:"sha512"===i?"SHA-512":"SHA-256"},u=function(e,t){return k.subtleCrypto.importKey("raw",e,c,!0,["sign"]).then((function(e){return k.subtleCrypto.sign(c,e,t)})).then((function(e){return new Uint8Array(e)}))},s=new Uint8Array(o),p=r.length,(f=new Uint8Array(p+4)).set(r),h=0,l="sha512"===i?64:32,y=Math.ceil(o/l),v=1;case 15:if(!(v<=y)){e.next=35;break}return d(f,v,p),e.next=19,u(a,f);case 19:g=b=e.sent,x=1;case 22:if(!(x<n)){e.next=30;break}return e.next=25,u(a,g);case 25:for(g=e.sent,w=0;w<l;w++)b[w]^=g[w];case 27:x++,e.next=22;break;case 30:s.set(b.subarray(0,s.byteLength-h),h),h+=l;case 32:v++,e.next=15;break;case 35:return e.abrupt("return",Buffer.from(s.buffer));case 36:case"end":return e.stop()}}),e)})));return function(t,r,n,o,i){return e.apply(this,arguments)}}(),e}();function fe(){return he.apply(this,arguments)}function he(){return(he=h(m.mark((function e(){var t;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k();case 2:if("subtleCrypto"!==(t=e.sent).name){e.next=7;break}return e.abrupt("return",new se(t.lib));case 7:return e.abrupt("return",new ue(t.lib.pbkdf2));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function le(){return(le=h(m.mark((function e(t,r,n){var o,i,a,u,p,f,h,l,y,d,v,b,g;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,o=c.mnemonicToEntropy(t),e.next=9;break;case 4:throw e.prev=4,e.t0=e.catch(0),console.error("Invalid mnemonic phrase provided"),console.error(e.t0),new Error("Not a valid bip39 mnemonic");case 9:return i=Buffer.from(o,"hex"),e.next=12,fe();case 12:return a=e.sent,u=n&&n.getRandomBytes?n.getRandomBytes(16):s.default(16),e.next=16,a.derive(r,u,1e5,48,"sha512");case 16:return f=(p=e.sent).slice(0,16),h=p.slice(16,32),l=p.slice(32,48),e.next=22,q();case 22:return y=e.sent,e.next=25,y.encrypt("aes-128-cbc",f,l,i);case 25:return d=e.sent,v=Buffer.concat([u,d]),e.next=29,N();case 29:return b=e.sent,e.next=32,b.digest(h,v);case 32:return g=Buffer.concat([u,e.sent,d]),e.abrupt("return",g);case 35:case"end":return e.stop()}}),e,null,[[0,4]])})))).apply(this,arguments)}var ye=function(e){var t,r;function n(){return e.apply(this,arguments)||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(b(Error));function de(e,t){return ve.apply(this,arguments)}function ve(){return(ve=h(m.mark((function e(t,r){var n,o,i,a,u,s,p,f,h,l,y,d,v,b,g,x;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.slice(0,16),o=t.slice(16,48),i=t.slice(48),a=Buffer.concat([n,i]),e.next=6,fe();case 6:return u=e.sent,e.next=9,u.derive(r,n,1e5,48,"sha512");case 9:return p=(s=e.sent).slice(0,16),f=s.slice(16,32),h=s.slice(32,48),e.next=15,q();case 15:return l=e.sent,e.next=18,l.decrypt("aes-128-cbc",p,h,i);case 18:return y=e.sent,e.next=21,N();case 21:return d=e.sent,e.next=24,d.digest(f,a);case 24:return v=e.sent,e.next=27,B();case 27:return b=e.sent,e.next=30,b.digest(o);case 30:return g=e.sent,e.next=33,b.digest(v);case 33:if(g.equals(e.sent)){e.next=36;break}throw new ye("Wrong password (HMAC mismatch)");case 36:e.prev=36,x=c.entropyToMnemonic(y),e.next=45;break;case 40:throw e.prev=40,e.t0=e.catch(36),console.error("Error thrown by `entropyToMnemonic`"),console.error(e.t0),new ye("Wrong password (invalid plaintext)");case 45:if(c.validateMnemonic(x)){e.next=47;break}throw new ye("Wrong password (invalid plaintext)");case 47:return e.abrupt("return",x);case 48:case"end":return e.stop()}}),e,null,[[36,40]])})))).apply(this,arguments)}function be(e,t,r){return new Promise((function(n,o){r||o(new Error("The `triplesec.decrypt` function must be provided")),r({key:Buffer.from(t),data:e},(function(e,t){e?o(e):n(t)}))}))}function ge(){return(ge=h(m.mark((function e(t,r,n){var o;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=Buffer.isBuffer(t)?t:Buffer.from(t,"hex"),e.prev=1,e.next=4,de(o,r);case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(1),!(e.t0 instanceof ye)){e.next=11;break}throw e.t0;case 11:return e.next=13,be(o,r,n);case 13:return e.abrupt("return",e.sent.toString());case 15:case"end":return e.stop()}}),e,null,[[1,7]])})))).apply(this,arguments)}function me(){return(me=h(m.mark((function e(t,r){var n,o,i,a,c,u;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((n=Object.assign({},r)).publicKey){e.next=5;break}if(n.privateKey){e.next=4;break}throw new Error("Either public key or private key must be supplied for encryption.");case 4:n.publicKey=H(n.privateKey);case 5:return i="boolean"==typeof n.wasString?n.wasString:"string"==typeof t,a="string"==typeof t?Buffer.from(t):t,e.next=9,ne(n.publicKey,a,i,n.cipherTextEncoding);case 9:return c=JSON.stringify(e.sent),n.sign&&("string"==typeof n.sign?o=n.sign:o||(o=n.privateKey),u=ce(o,c),c=JSON.stringify({signature:u.signature,publicKey:u.publicKey,cipherText:c})),e.abrupt("return",c);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}Object.defineProperty(e,"randomBytes",{enumerable:!0,get:function(){return s.default}}),e.NodeCryptoSha2Hash=C,e.WebCryptoSha2Hash=S,e.aes256CbcEncrypt=W,e.createSha2Hash=B,e.decryptContent=function(e,t){var r=Object.assign({},t);if(!r.privateKey)throw new Error("Private key is required for decryption.");try{var n=JSON.parse(e);return ie(r.privateKey,n)}catch(e){throw e instanceof SyntaxError?new Error("Failed to parse encrypted content JSON. The content may not be encrypted. If using getFile, try passing { decrypt: false }."):e}},e.decryptECIES=ie,e.decryptMnemonic=function(e,t,r){return ge.apply(this,arguments)},e.ecPairToAddress=function(e){var t=O(K(e.publicKey));return o.address.toBase58Check(t,e.network.pubKeyHash)},e.ecPairToHexString=function(e){var t=e.privateKey.toString("hex");return e.compressed?t+"01":t},e.eciesGetJsonStringLength=function(e){var t,r=te(e),n=r.payloadShell,o=r.payloadValuesLength,i=G(e.contentLength);if(e.cipherTextEncoding&&"hex"!==e.cipherTextEncoding){if("base64"!==e.cipherTextEncoding)throw new Error('Unexpected cipherTextEncoding "'+e.cipherTextEncoding+'"');t=I(i)}else t=2*i;if(e.sign){var a=re(n);return a.signedPayloadShell.length+a.signedPayloadValuesLength+o+t}return n.length+o+t},e.encryptContent=function(e,t){return me.apply(this,arguments)},e.encryptECIES=ne,e.encryptMnemonic=function(e,t,r){return le.apply(this,arguments)},e.getAesCbcOutputLength=G,e.getBase64OutputLength=I,e.getBufferFromBN=ee,e.getCipherObjectWrapper=te,e.getEntropy=A,e.getHexFromBN=function(e){var t=e.toString("hex",64);if(64===t.length)return t;if(t.length<64)return""+"0".repeat(64-t.length)+t;throw new Error("Generated a > 32-byte BN for encryption. Failing.")},e.getPublicKeyFromPrivate=H,e.getSignedCipherObjectWrapper=re,e.hashCode=function(e){var t=0;if(0===e.length)return t;for(var r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return 2147483647&t},e.hashSha256Sync=K,e.hashSha512Sync=L,e.hexStringToECPair=function(e,t){var r={network:t||o.networks.bitcoin,compressed:!0};if(66===e.length){if("01"!==e.slice(64))throw new Error("Improperly formatted private-key hex string. 66-length hex usually indicates compressed key, but last byte must be == 1");return o.ECPair.fromPrivateKey(Buffer.from(e.slice(0,64),"hex"),r)}if(64===e.length)return r.compressed=!1,o.ECPair.fromPrivateKey(Buffer.from(e,"hex"),r);throw new Error("Improperly formatted private-key hex string: length should be 64 or 66.")},e.makeECPrivateKey=function(){return o.ECPair.makeRandom({rng:A}).privateKey.toString("hex")},e.publicKeyToAddress=function(e){var t=O(K(Buffer.isBuffer(e)?e:Buffer.from(e,"hex")));return o.address.toBase58Check(t,o.networks.bitcoin.pubKeyHash)},e.signECDSA=ce,e.verifyECDSA=function(e,t,r){var n=function(e){return e instanceof Buffer?e:(ArrayBuffer,Buffer.from(e))}(e),o=J.keyFromPublic(t,"hex"),i=K(n);return o.verify(i,r)},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=encryption.umd.production.min.js.map

@@ -7,1 +7,2 @@ export * from './ec';

export * from './encryption';
export * from './utils';
export declare function getAesCbcOutputLength(inputByteLength: number): number;
export declare function getBase64OutputLength(inputByteLength: number): number;
export declare function hashCode(string: string): number;
export { default as randomBytes } from 'randombytes';
export { NodeCryptoSha2Hash, WebCryptoSha2Hash, createSha2Hash, hashSha256Sync, hashSha512Sync } from './sha2Hash.esm.js';
export { ecPairToAddress, ecPairToHexString, getEntropy, getPublicKeyFromPrivate, hexStringToECPair, makeECPrivateKey, publicKeyToAddress } from './keys.esm.js';
export { getAesCbcOutputLength, getBase64OutputLength, hashCode } from './utils.esm.js';
export { aes256CbcEncrypt, decryptECIES, eciesGetJsonStringLength, encryptECIES, getBufferFromBN, getCipherObjectWrapper, getHexFromBN, getSignedCipherObjectWrapper, signECDSA, verifyECDSA } from './ec.esm.js';

@@ -5,0 +6,0 @@ export { decryptMnemonic, encryptMnemonic } from './wallet.esm.js';

@@ -9,4 +9,16 @@ function getAesCbcOutputLength(inputByteLength) {

}
function hashCode(string) {
var hash = 0;
if (string.length === 0) return hash;
export { getAesCbcOutputLength, getBase64OutputLength };
for (var i = 0; i < string.length; i++) {
var character = string.charCodeAt(i);
hash = (hash << 5) - hash + character;
hash &= hash;
}
return hash & 0x7fffffff;
}
export { getAesCbcOutputLength, getBase64OutputLength, hashCode };
//# sourceMappingURL=utils.esm.js.map
{
"name": "@stacks/encryption",
"version": "1.0.0-beta.8",
"version": "1.0.0-beta.9",
"description": "Encryption utilities for Stacks",

@@ -40,3 +40,3 @@ "author": "yknl <yukanliao@gmail.com>",

"dependencies": {
"@stacks/common": "^1.0.0-beta.8",
"@stacks/common": "^1.0.0-beta.9",
"bip39": "^3.0.2",

@@ -43,0 +43,0 @@ "bitcoinjs-lib": "^5.1.10",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc