UNPKG

@tkey/default

Version:

TKey default library

2 lines 519 kB
/*! For license information please see default.umd.min.js.LICENSE.txt */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Default=t():e.Default=t()}(self,(()=>(()=>{var e={36:(e,t,r)=>{"use strict";r.d(t,{Vw:()=>h,Fc:()=>c,O8:()=>s,qv:()=>a,po:()=>f,ZJ:()=>d,DH:()=>o,ld:()=>u});const n="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;var i=r(6879);function o(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function s(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}const a=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();function c(e){for(let r=0;r<e.length;r++)e[r]=(t=e[r])<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;var t}function d(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),(0,i.DO)(e),e}class h{clone(){return this._cloneInto()}}function u(e){const t=t=>e().update(d(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function f(e=32){if(n&&"function"==typeof n.getRandomValues)return n.getRandomValues(new Uint8Array(e));if(n&&"function"==typeof n.randomBytes)return n.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}},46:e=>{"use strict";var t,r="object"==typeof Reflect?Reflect:null,n=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};t=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise((function(r,n){function i(r){e.removeListener(t,o),n(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}y(e,t,o,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&y(e,"error",t,{once:!0})}(e,i)}))},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function d(e,t,r,n){var i,o,s,d;if(a(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),s=o[t]),void 0===s)s=o[t]=r,++e._eventsCount;else if("function"==typeof s?s=o[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(i=c(e))>0&&s.length>i&&!s.warned){s.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=s.length,d=h,console&&console.warn&&console.warn(d)}return e}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function u(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=h.bind(n);return i.listener=r,n.wrapFn=i,i}function f(e,t,r){var n=e._events;if(void 0===n)return[];var i=n[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):p(i,i.length)}function l(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function p(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function y(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(o){n.once&&e.removeEventListener(t,i),r(o)}))}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)n(c,this,t);else{var d=c.length,h=p(c,d);for(r=0;r<d;++r)n(h[r],this,t)}return!0},o.prototype.addListener=function(e,t){return d(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return d(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,u(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,u(this,e,t)),this},o.prototype.removeListener=function(e,t){var r,n,i,o,s;if(a(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){s=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,s||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,o=Object.keys(r);for(n=0;n<o.length;++n)"removeListener"!==(i=o[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},o.prototype.listeners=function(e){return f(this,e,!0)},o.prototype.rawListeners=function(e){return f(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):l.call(e,t)},o.prototype.listenerCount=l,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},110:(e,t,r)=>{"use strict";r.d(t,{So:()=>E});var n=r(6879),i=r(9964),o=r(36);const s=[],a=[],c=[],d=BigInt(0),h=BigInt(1),u=BigInt(2),f=BigInt(7),l=BigInt(256),p=BigInt(113);for(let e=0,t=h,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],s.push(2*(5*n+r)),a.push((e+1)*(e+2)/2%64);let i=d;for(let e=0;e<7;e++)t=(t<<h^(t>>f)*p)%l,t&u&&(i^=h<<(h<<BigInt(e))-h);c.push(i)}const[y,b]=(0,i.lD)(c,!0),m=(e,t,r)=>r>32?(0,i.WM)(e,t,r):(0,i.P5)(e,t,r),g=(e,t,r)=>r>32?(0,i.im)(e,t,r):(0,i.B4)(e,t,r);class v extends o.Vw{constructor(e,t,r,i=!1,s=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,n.Fe)(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,o.DH)(this.state)}keccak(){o.qv||(0,o.Fc)(this.state32),function(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const n=(t+8)%10,i=(t+2)%10,o=r[i],s=r[i+1],a=m(o,s,1)^r[n],c=g(o,s,1)^r[n+1];for(let r=0;r<50;r+=10)e[t+r]^=a,e[t+r+1]^=c}let t=e[2],i=e[3];for(let r=0;r<24;r++){const n=a[r],o=m(t,i,n),c=g(t,i,n),d=s[r];t=e[d],i=e[d+1],e[d]=o,e[d+1]=c}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=y[n],e[1]^=b[n]}r.fill(0)}(this.state32,this.rounds),o.qv||(0,o.Fc)(this.state32),this.posOut=0,this.pos=0}update(e){(0,n.CC)(this);const{blockLen:t,state:r}=this,i=(e=(0,o.ZJ)(e)).length;for(let n=0;n<i;){const o=Math.min(t-this.pos,i-n);for(let t=0;t<o;t++)r[this.pos++]^=e[n++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,128&t&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){(0,n.CC)(this,!1),(0,n.DO)(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,i=e.length;n<i;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,i-n);e.set(t.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,n.Fe)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,n.Ht)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:n,rounds:i,enableXOF:o}=this;return e||(e=new v(t,r,n,o,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=r,e.outputLen=n,e.enableXOF=o,e.destroyed=this.destroyed,e}}const w=(e,t,r)=>(0,o.ld)((()=>new v(t,e,r))),S=w(1,144,28),_=w(1,136,32),A=w(1,104,48),k=w(1,72,64);var P=r(9502);(0,P.RS)(S);const E=(()=>{const e=(0,P.RS)(_);return e.create=_.create,e})();(0,P.RS)(A),(0,P.RS)(k)},183:e=>{"use strict";e.exports={rE:"6.6.1"}},206:(e,t,r)=>{"use strict";var n=r(8212),i=r(2823),o=r(2768),s=r(5185);class a{constructor(e,t){n(this,"share",void 0),n(this,"shareIndex",void 0),this.share=new i(t,"hex"),this.shareIndex=new i(e,"hex")}static fromJSON(e){const{share:t,shareIndex:r}=e;return new a(r,t)}getPublicShare(){return new s(this.shareIndex,o.getPubKeyPoint(this.share))}toJSON(){return{share:this.share.toString("hex"),shareIndex:this.shareIndex.toString("hex")}}}e.exports=a},277:(e,t,r)=>{"use strict";var n=r(1874),i=r(2823),o=r(5615),s=r(5174),a=n.assert;function c(e){s.call(this,"short",e),this.a=new i(e.a,16).toRed(this.red),this.b=new i(e.b,16).toRed(this.red),this.tinv=this.two.redInvm(),this.zeroA=0===this.a.fromRed().cmpn(0),this.threeA=0===this.a.fromRed().sub(this.p).cmpn(-3),this.endo=this._getEndomorphism(e),this._endoWnafT1=new Array(4),this._endoWnafT2=new Array(4)}function d(e,t,r,n){s.BasePoint.call(this,e,"affine"),null===t&&null===r?(this.x=null,this.y=null,this.inf=!0):(this.x=new i(t,16),this.y=new i(r,16),n&&(this.x.forceRed(this.curve.red),this.y.forceRed(this.curve.red)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.inf=!1)}function h(e,t,r,n){s.BasePoint.call(this,e,"jacobian"),null===t&&null===r&&null===n?(this.x=this.curve.one,this.y=this.curve.one,this.z=new i(0)):(this.x=new i(t,16),this.y=new i(r,16),this.z=new i(n,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}o(c,s),e.exports=c,c.prototype._getEndomorphism=function(e){if(this.zeroA&&this.g&&this.n&&1===this.p.modn(3)){var t,r;if(e.beta)t=new i(e.beta,16).toRed(this.red);else{var n=this._getEndoRoots(this.p);t=(t=n[0].cmp(n[1])<0?n[0]:n[1]).toRed(this.red)}if(e.lambda)r=new i(e.lambda,16);else{var o=this._getEndoRoots(this.n);0===this.g.mul(o[0]).x.cmp(this.g.x.redMul(t))?r=o[0]:(r=o[1],a(0===this.g.mul(r).x.cmp(this.g.x.redMul(t))))}return{beta:t,lambda:r,basis:e.basis?e.basis.map((function(e){return{a:new i(e.a,16),b:new i(e.b,16)}})):this._getEndoBasis(r)}}},c.prototype._getEndoRoots=function(e){var t=e===this.p?this.red:i.mont(e),r=new i(2).toRed(t).redInvm(),n=r.redNeg(),o=new i(3).toRed(t).redNeg().redSqrt().redMul(r);return[n.redAdd(o).fromRed(),n.redSub(o).fromRed()]},c.prototype._getEndoBasis=function(e){for(var t,r,n,o,s,a,c,d,h,u=this.n.ushrn(Math.floor(this.n.bitLength()/2)),f=e,l=this.n.clone(),p=new i(1),y=new i(0),b=new i(0),m=new i(1),g=0;0!==f.cmpn(0);){var v=l.div(f);d=l.sub(v.mul(f)),h=b.sub(v.mul(p));var w=m.sub(v.mul(y));if(!n&&d.cmp(u)<0)t=c.neg(),r=p,n=d.neg(),o=h;else if(n&&2==++g)break;c=d,l=f,f=d,b=p,p=h,m=y,y=w}s=d.neg(),a=h;var S=n.sqr().add(o.sqr());return s.sqr().add(a.sqr()).cmp(S)>=0&&(s=t,a=r),n.negative&&(n=n.neg(),o=o.neg()),s.negative&&(s=s.neg(),a=a.neg()),[{a:n,b:o},{a:s,b:a}]},c.prototype._endoSplit=function(e){var t=this.endo.basis,r=t[0],n=t[1],i=n.b.mul(e).divRound(this.n),o=r.b.neg().mul(e).divRound(this.n),s=i.mul(r.a),a=o.mul(n.a),c=i.mul(r.b),d=o.mul(n.b);return{k1:e.sub(s).sub(a),k2:c.add(d).neg()}},c.prototype.pointFromX=function(e,t){(e=new i(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),n=r.redSqrt();if(0!==n.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var o=n.fromRed().isOdd();return(t&&!o||!t&&o)&&(n=n.redNeg()),this.point(e,n)},c.prototype.validate=function(e){if(e.inf)return!0;var t=e.x,r=e.y,n=this.a.redMul(t),i=t.redSqr().redMul(t).redIAdd(n).redIAdd(this.b);return 0===r.redSqr().redISub(i).cmpn(0)},c.prototype._endoWnafMulAdd=function(e,t,r){for(var n=this._endoWnafT1,i=this._endoWnafT2,o=0;o<e.length;o++){var s=this._endoSplit(t[o]),a=e[o],c=a._getBeta();s.k1.negative&&(s.k1.ineg(),a=a.neg(!0)),s.k2.negative&&(s.k2.ineg(),c=c.neg(!0)),n[2*o]=a,n[2*o+1]=c,i[2*o]=s.k1,i[2*o+1]=s.k2}for(var d=this._wnafMulAdd(1,n,i,2*o,r),h=0;h<2*o;h++)n[h]=null,i[h]=null;return d},o(d,s.BasePoint),c.prototype.point=function(e,t,r){return new d(this,e,t,r)},c.prototype.pointFromJSON=function(e,t){return d.fromJSON(this,e,t)},d.prototype._getBeta=function(){if(this.curve.endo){var e=this.precomputed;if(e&&e.beta)return e.beta;var t=this.curve.point(this.x.redMul(this.curve.endo.beta),this.y);if(e){var r=this.curve,n=function(e){return r.point(e.x.redMul(r.endo.beta),e.y)};e.beta=t,t.precomputed={beta:null,naf:e.naf&&{wnd:e.naf.wnd,points:e.naf.points.map(n)},doubles:e.doubles&&{step:e.doubles.step,points:e.doubles.points.map(n)}}}return t}},d.prototype.toJSON=function(){return this.precomputed?[this.x,this.y,this.precomputed&&{doubles:this.precomputed.doubles&&{step:this.precomputed.doubles.step,points:this.precomputed.doubles.points.slice(1)},naf:this.precomputed.naf&&{wnd:this.precomputed.naf.wnd,points:this.precomputed.naf.points.slice(1)}}]:[this.x,this.y]},d.fromJSON=function(e,t,r){"string"==typeof t&&(t=JSON.parse(t));var n=e.point(t[0],t[1],r);if(!t[2])return n;function i(t){return e.point(t[0],t[1],r)}var o=t[2];return n.precomputed={beta:null,doubles:o.doubles&&{step:o.doubles.step,points:[n].concat(o.doubles.points.map(i))},naf:o.naf&&{wnd:o.naf.wnd,points:[n].concat(o.naf.points.map(i))}},n},d.prototype.inspect=function(){return this.isInfinity()?"<EC Point Infinity>":"<EC Point x: "+this.x.fromRed().toString(16,2)+" y: "+this.y.fromRed().toString(16,2)+">"},d.prototype.isInfinity=function(){return this.inf},d.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(0===this.x.cmp(e.x))return this.curve.point(null,null);var t=this.y.redSub(e.y);0!==t.cmpn(0)&&(t=t.redMul(this.x.redSub(e.x).redInvm()));var r=t.redSqr().redISub(this.x).redISub(e.x),n=t.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,n)},d.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(0===e.cmpn(0))return this.curve.point(null,null);var t=this.curve.a,r=this.x.redSqr(),n=e.redInvm(),i=r.redAdd(r).redIAdd(r).redIAdd(t).redMul(n),o=i.redSqr().redISub(this.x.redAdd(this.x)),s=i.redMul(this.x.redSub(o)).redISub(this.y);return this.curve.point(o,s)},d.prototype.getX=function(){return this.x.fromRed()},d.prototype.getY=function(){return this.y.fromRed()},d.prototype.mul=function(e){return e=new i(e,16),this.isInfinity()?this:this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)},d.prototype.mulAdd=function(e,t,r){var n=[this,t],i=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i):this.curve._wnafMulAdd(1,n,i,2)},d.prototype.jmulAdd=function(e,t,r){var n=[this,t],i=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i,!0):this.curve._wnafMulAdd(1,n,i,2,!0)},d.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||0===this.x.cmp(e.x)&&0===this.y.cmp(e.y))},d.prototype.neg=function(e){if(this.inf)return this;var t=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var r=this.precomputed,n=function(e){return e.neg()};t.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(n)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(n)}}}return t},d.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},o(h,s.BasePoint),c.prototype.jpoint=function(e,t,r){return new h(this,e,t,r)},h.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),t=e.redSqr(),r=this.x.redMul(t),n=this.y.redMul(t).redMul(e);return this.curve.point(r,n)},h.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},h.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.z.redSqr(),r=this.z.redSqr(),n=this.x.redMul(t),i=e.x.redMul(r),o=this.y.redMul(t.redMul(e.z)),s=e.y.redMul(r.redMul(this.z)),a=n.redSub(i),c=o.redSub(s);if(0===a.cmpn(0))return 0!==c.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var d=a.redSqr(),h=d.redMul(a),u=n.redMul(d),f=c.redSqr().redIAdd(h).redISub(u).redISub(u),l=c.redMul(u.redISub(f)).redISub(o.redMul(h)),p=this.z.redMul(e.z).redMul(a);return this.curve.jpoint(f,l,p)},h.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var t=this.z.redSqr(),r=this.x,n=e.x.redMul(t),i=this.y,o=e.y.redMul(t).redMul(this.z),s=r.redSub(n),a=i.redSub(o);if(0===s.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=s.redSqr(),d=c.redMul(s),h=r.redMul(c),u=a.redSqr().redIAdd(d).redISub(h).redISub(h),f=a.redMul(h.redISub(u)).redISub(i.redMul(d)),l=this.z.redMul(s);return this.curve.jpoint(u,f,l)},h.prototype.dblp=function(e){if(0===e)return this;if(this.isInfinity())return this;if(!e)return this.dbl();var t;if(this.curve.zeroA||this.curve.threeA){var r=this;for(t=0;t<e;t++)r=r.dbl();return r}var n=this.curve.a,i=this.curve.tinv,o=this.x,s=this.y,a=this.z,c=a.redSqr().redSqr(),d=s.redAdd(s);for(t=0;t<e;t++){var h=o.redSqr(),u=d.redSqr(),f=u.redSqr(),l=h.redAdd(h).redIAdd(h).redIAdd(n.redMul(c)),p=o.redMul(u),y=l.redSqr().redISub(p.redAdd(p)),b=p.redISub(y),m=l.redMul(b);m=m.redIAdd(m).redISub(f);var g=d.redMul(a);t+1<e&&(c=c.redMul(f)),o=y,a=g,d=m}return this.curve.jpoint(o,d.redMul(i),a)},h.prototype.dbl=function(){return this.isInfinity()?this:this.curve.zeroA?this._zeroDbl():this.curve.threeA?this._threeDbl():this._dbl()},h.prototype._zeroDbl=function(){var e,t,r;if(this.zOne){var n=this.x.redSqr(),i=this.y.redSqr(),o=i.redSqr(),s=this.x.redAdd(i).redSqr().redISub(n).redISub(o);s=s.redIAdd(s);var a=n.redAdd(n).redIAdd(n),c=a.redSqr().redISub(s).redISub(s),d=o.redIAdd(o);d=(d=d.redIAdd(d)).redIAdd(d),e=c,t=a.redMul(s.redISub(c)).redISub(d),r=this.y.redAdd(this.y)}else{var h=this.x.redSqr(),u=this.y.redSqr(),f=u.redSqr(),l=this.x.redAdd(u).redSqr().redISub(h).redISub(f);l=l.redIAdd(l);var p=h.redAdd(h).redIAdd(h),y=p.redSqr(),b=f.redIAdd(f);b=(b=b.redIAdd(b)).redIAdd(b),e=y.redISub(l).redISub(l),t=p.redMul(l.redISub(e)).redISub(b),r=(r=this.y.redMul(this.z)).redIAdd(r)}return this.curve.jpoint(e,t,r)},h.prototype._threeDbl=function(){var e,t,r;if(this.zOne){var n=this.x.redSqr(),i=this.y.redSqr(),o=i.redSqr(),s=this.x.redAdd(i).redSqr().redISub(n).redISub(o);s=s.redIAdd(s);var a=n.redAdd(n).redIAdd(n).redIAdd(this.curve.a),c=a.redSqr().redISub(s).redISub(s);e=c;var d=o.redIAdd(o);d=(d=d.redIAdd(d)).redIAdd(d),t=a.redMul(s.redISub(c)).redISub(d),r=this.y.redAdd(this.y)}else{var h=this.z.redSqr(),u=this.y.redSqr(),f=this.x.redMul(u),l=this.x.redSub(h).redMul(this.x.redAdd(h));l=l.redAdd(l).redIAdd(l);var p=f.redIAdd(f),y=(p=p.redIAdd(p)).redAdd(p);e=l.redSqr().redISub(y),r=this.y.redAdd(this.z).redSqr().redISub(u).redISub(h);var b=u.redSqr();b=(b=(b=b.redIAdd(b)).redIAdd(b)).redIAdd(b),t=l.redMul(p.redISub(e)).redISub(b)}return this.curve.jpoint(e,t,r)},h.prototype._dbl=function(){var e=this.curve.a,t=this.x,r=this.y,n=this.z,i=n.redSqr().redSqr(),o=t.redSqr(),s=r.redSqr(),a=o.redAdd(o).redIAdd(o).redIAdd(e.redMul(i)),c=t.redAdd(t),d=(c=c.redIAdd(c)).redMul(s),h=a.redSqr().redISub(d.redAdd(d)),u=d.redISub(h),f=s.redSqr();f=(f=(f=f.redIAdd(f)).redIAdd(f)).redIAdd(f);var l=a.redMul(u).redISub(f),p=r.redAdd(r).redMul(n);return this.curve.jpoint(h,l,p)},h.prototype.trpl=function(){if(!this.curve.zeroA)return this.dbl().add(this);var e=this.x.redSqr(),t=this.y.redSqr(),r=this.z.redSqr(),n=t.redSqr(),i=e.redAdd(e).redIAdd(e),o=i.redSqr(),s=this.x.redAdd(t).redSqr().redISub(e).redISub(n),a=(s=(s=(s=s.redIAdd(s)).redAdd(s).redIAdd(s)).redISub(o)).redSqr(),c=n.redIAdd(n);c=(c=(c=c.redIAdd(c)).redIAdd(c)).redIAdd(c);var d=i.redIAdd(s).redSqr().redISub(o).redISub(a).redISub(c),h=t.redMul(d);h=(h=h.redIAdd(h)).redIAdd(h);var u=this.x.redMul(a).redISub(h);u=(u=u.redIAdd(u)).redIAdd(u);var f=this.y.redMul(d.redMul(c.redISub(d)).redISub(s.redMul(a)));f=(f=(f=f.redIAdd(f)).redIAdd(f)).redIAdd(f);var l=this.z.redAdd(s).redSqr().redISub(r).redISub(a);return this.curve.jpoint(u,f,l)},h.prototype.mul=function(e,t){return e=new i(e,t),this.curve._wnafMul(this,e)},h.prototype.eq=function(e){if("affine"===e.type)return this.eq(e.toJ());if(this===e)return!0;var t=this.z.redSqr(),r=e.z.redSqr();if(0!==this.x.redMul(r).redISub(e.x.redMul(t)).cmpn(0))return!1;var n=t.redMul(this.z),i=r.redMul(e.z);return 0===this.y.redMul(i).redISub(e.y.redMul(n)).cmpn(0)},h.prototype.eqXToP=function(e){var t=this.z.redSqr(),r=e.toRed(this.curve.red).redMul(t);if(0===this.x.cmp(r))return!0;for(var n=e.clone(),i=this.curve.redN.redMul(t);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(r.redIAdd(i),0===this.x.cmp(r))return!0}},h.prototype.inspect=function(){return this.isInfinity()?"<EC JPoint Infinity>":"<EC JPoint x: "+this.x.toString(16,2)+" y: "+this.y.toString(16,2)+" z: "+this.z.toString(16,2)+">"},h.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}},335:(e,t,r)=>{"use strict";r.d(t,{A:()=>m});var n=r(8158),i=r(3890),o=r(3628),s=r(2823),a=r.n(s),c=r(3360),d=r(6122),h=r(888),u=r(6073),f=r(789),l=r(3259),p=r(8935),y=r(1498),b=r(1048).hp;class m{constructor({enableOneKey:e=!1,clientId:t,network:r,serverTimeOffset:o=0,allowHost:s,legacyMetadataHost:a,keyType:d=i.PN.SECP256K1}){if((0,n.A)(this,"allowHost",void 0),(0,n.A)(this,"serverTimeOffset",void 0),(0,n.A)(this,"network",void 0),(0,n.A)(this,"clientId",void 0),(0,n.A)(this,"ec",void 0),(0,n.A)(this,"enableOneKey",void 0),(0,n.A)(this,"legacyMetadataHost",void 0),(0,n.A)(this,"keyType",i.PN.SECP256K1),!t)throw new Error("Please provide a valid clientId in constructor");if(!r)throw new Error("Please provide a valid network in constructor");if(d===i.PN.ED25519&&i.$o[r])throw new Error(`keyType: ${d} is not supported by ${r} network`);this.keyType=d,this.ec=new c.ec(this.keyType),this.serverTimeOffset=o||0,this.network=r,this.clientId=t,this.allowHost=s||`${i.Q2[r]}/api/allow`,this.enableOneKey=e,this.legacyMetadataHost=a||i.xE[r]}static enableLogging(e=!0){e?(h.A.enableAll(),d.$.logRequestTracing=!0):h.A.disableAll()}static setAPIKey(e){(0,o.Qv)(e)}static setEmbedHost(e){(0,o.KL)(e)}static setSessionTime(e){m.sessionTime=e}static isGetOrSetNonceError(e){return e instanceof u.l}static getPostboxKey(e){return"v1"===e.metadata.typeOfUser&&e.finalKeyData.privKey||e.postboxKeyData.privKey}async retrieveShares(e){const{verifier:t,verifierParams:r,idToken:n,nodePubkeys:o,indexes:s,endpoints:a,useDkg:c,extraParams:d={},checkCommitment:h=!0}=e;if(0===o.length)throw new Error("nodePubkeys param is required");if(o.length!==s.length)throw new Error("nodePubkeys length must be same as indexes length");if(o.length!==a.length)throw new Error("nodePubkeys length must be same as endpoints length");let u;if("boolean"==typeof c){if(!1===c&&i.$o[this.network])throw new Error(`useDkg cannot be false for legacy network; ${this.network}`);u=this.keyType!==i.PN.ED25519&&c}else u=this.keyType!==i.PN.ED25519;if(!u&&0===o.length)throw new Error("nodePubkeys param is required");return d.session_token_exp_second||(d.session_token_exp_second=m.sessionTime),(0,f.G)({legacyMetadataHost:this.legacyMetadataHost,serverTimeOffset:this.serverTimeOffset,enableOneKey:this.enableOneKey,ecCurve:this.ec,keyType:this.keyType,allowHost:this.allowHost,network:this.network,clientId:this.clientId,endpoints:a,indexes:s,verifier:t,verifierParams:r,idToken:n,useDkg:u,newImportedShares:[],overrideExistingKey:!1,nodePubkeys:o,extraParams:d,checkCommitment:h})}async getPublicAddress(e,t,{verifier:r,verifierId:n,extendedVerifierId:i,keyType:o}){h.A.info(t,{verifier:r,verifierId:n,extendedVerifierId:i});const s=null!=o?o:this.keyType;return this.getNewPublicAddress(e,{verifier:r,verifierId:n,extendedVerifierId:i,keyType:s},this.enableOneKey)}async importPrivateKey(e){const{nodeIndexes:t,newPrivateKey:r,verifier:n,verifierParams:o,idToken:s,nodePubkeys:a,endpoints:c,extraParams:d={},checkCommitment:h=!0}=e;if(i.$o[this.network])throw new Error(`importPrivateKey is not supported by legacy network; ${this.network}`);if(c.length!==t.length)throw new Error("length of endpoints array must be same as length of nodeIndexes array");let u;if(d.session_token_exp_second||(d.session_token_exp_second=m.sessionTime),this.keyType===i.PN.SECP256K1&&(u=b.from(r.padStart(64,"0"),"hex"),32!==u.length))throw new Error("Invalid private key length for given secp256k1 key");if(this.keyType===i.PN.ED25519&&(u=b.from(r.padStart(64,"0"),"hex"),32!==u.length))throw new Error("Invalid private key length for given ed25519 key");const p=await(0,l.qV)(this.ec,this.keyType,this.serverTimeOffset,t,a,u);if(this.keyType===i.PN.ED25519){const e=(0,l.Hu)(u),t=(0,l.Cn)(e.point),r=(0,l.Cn)(p[0].final_user_point);if(b.from(t).toString("hex")!==r.toString("hex"))throw new Error("invalid shares data for ed25519 key, public key is not matching after generating shares")}return(0,f.G)({legacyMetadataHost:this.legacyMetadataHost,serverTimeOffset:this.serverTimeOffset,enableOneKey:this.enableOneKey,ecCurve:this.ec,keyType:this.keyType,allowHost:this.allowHost,network:this.network,clientId:this.clientId,endpoints:c,indexes:t,verifier:n,verifierParams:o,idToken:s,useDkg:!1,overrideExistingKey:!0,newImportedShares:p,nodePubkeys:a,extraParams:d,checkCommitment:h})}async getUserTypeAndAddress(e,{verifier:t,verifierId:r,extendedVerifierId:n}){return this.getNewPublicAddress(e,{verifier:t,verifierId:r,extendedVerifierId:n},!0)}async getNewPublicAddress(e,{verifier:t,verifierId:r,extendedVerifierId:n,keyType:o},s){const c=null!=o?o:this.keyType,d=(0,p.tO)(c);if(c===i.PN.ED25519&&i.$o[this.network])throw new Error(`keyType: ${o} is not supported by ${this.network} network`);const h=await(0,f.Gj)({endpoints:e,network:this.network,verifier:t,verifierId:r,keyType:c,extendedVerifierId:n}),{errorResult:y,keyResult:b,nodeIndexes:m=[],serverTimeOffset:g}=h,v=this.serverTimeOffset||g,{nonceResult:w}=h;if(y&&JSON.stringify(y).toLowerCase().includes("verifier not supported"))throw new Error("Verifier not supported. Check if you: \n\n 1. Are on the right network (Torus testnet/mainnet) \n\n 2. Have setup a verifier on dashboard.web3auth.io?");if(y)throw new Error(`node results do not match at first lookup ${JSON.stringify(b||{})}, ${JSON.stringify(y||{})}`);if(null==b||!b.keys)throw new Error(`node results do not match at final lookup ${JSON.stringify(b||{})}, ${JSON.stringify(y||{})}`);if(!w&&!n&&!i.$o[this.network])throw new u.l("metadata nonce is missing in share response");const{pub_key_X:S,pub_key_Y:_}=b.keys[0];let A;const k=new(a())((null==w?void 0:w.nonce)||"0",16);let P,E;if(n)E=d.keyFromPublic({x:S,y:_}).getPublic(),P=E;else{if(i.$o[this.network])return this.formatLegacyPublicKeyData({isNewKey:b.is_new_key,enableOneKey:s,finalKeyResult:{keys:b.keys},serverTimeOffset:v});{const e=w;P=d.keyFromPublic({x:S,y:_}).getPublic(),E=d.keyFromPublic({x:S,y:_}).getPublic().add(d.keyFromPublic({x:e.pubNonce.x,y:e.pubNonce.y}).getPublic()),A={X:e.pubNonce.x,Y:e.pubNonce.y}}}if(!P)throw new Error("Unable to derive oAuthPubKey");const x=P.getX().toString(16,64),M=P.getY().toString(16,64),I=(0,l.qA)(c,P.getX(),P.getY());if(!E)throw new Error("Unable to derive finalPubKey");const O=E?E.getX().toString(16,64):"",T=E?E.getY().toString(16,64):"";return{oAuthKeyData:{walletAddress:I,X:x,Y:M},finalKeyData:{walletAddress:E?(0,l.qA)(c,E.getX(),E.getY()):"",X:O,Y:T},metadata:{pubNonce:A,nonce:k,upgraded:(null==w?void 0:w.upgraded)||!1,typeOfUser:"v2",serverTimeOffset:v},nodesData:{nodeIndexes:m}}}async formatLegacyPublicKeyData(e){var t;const{finalKeyResult:r,enableOneKey:n,isNewKey:i,serverTimeOffset:o,keyType:s}=e,c=null!=s?s:this.keyType,d=(0,p.tO)(c),{pub_key_X:h,pub_key_Y:f}=r.keys[0];let b,m,g,v,w;const S=d.keyFromPublic({x:h,y:f}).getPublic(),_=this.serverTimeOffset||o;if(n){try{b=await(0,y.Ri)(this.legacyMetadataHost,d,_,h,f,void 0,!i),m=new(a())(b.nonce||"0",16),v=b.typeOfUser}catch{throw new u.l}if("v1"===b.typeOfUser)m=await(0,y.yb)(this.legacyMetadataHost,{pub_key_X:h,pub_key_Y:f}),g=d.keyFromPublic({x:h,y:f}).getPublic().add(d.keyFromPrivate(m.toString(16,64),"hex").getPublic());else{if("v2"!==b.typeOfUser)throw new Error("getOrSetNonce should always return typeOfUser.");g=d.keyFromPublic({x:h,y:f}).getPublic().add(d.keyFromPublic({x:b.pubNonce.x,y:b.pubNonce.y}).getPublic()),w={X:b.pubNonce.x,Y:b.pubNonce.y}}}else v="v1",m=await(0,y.yb)(this.legacyMetadataHost,{pub_key_X:h,pub_key_Y:f}),g=d.keyFromPublic({x:h,y:f}).getPublic().add(d.keyFromPrivate(m.toString(16,64),"hex").getPublic());if(!S)throw new Error("Unable to derive oAuthPubKey");const A=S.getX().toString(16,64),k=S.getY().toString(16,64),P=(0,l.qA)(c,S.getX(),S.getY());if("v2"===v&&!g)throw new Error("Unable to derive finalPubKey");const E=g?g.getX().toString(16,64):"",x=g?g.getY().toString(16,64):"";return{oAuthKeyData:{walletAddress:P,X:A,Y:k},finalKeyData:{walletAddress:g?(0,l.qA)(c,g.getX(),g.getY()):"",X:E,Y:x},metadata:{pubNonce:w,nonce:m,upgraded:(null===(t=b)||void 0===t?void 0:t.upgraded)||!1,typeOfUser:v,serverTimeOffset:_},nodesData:{nodeIndexes:[]}}}}(0,n.A)(m,"sessionTime",86400)},346:(e,t,r)=>{"use strict";r.r(t),r.d(t,{decrypt:()=>x,derive:()=>A,derivePadded:()=>P,deriveUnpadded:()=>k,encrypt:()=>E,generatePrivate:()=>g,getPublic:()=>v,getPublicCompressed:()=>w,sign:()=>S,verify:()=>_});var n=r(3360),i=r(1048).hp;const o=new n.ec("secp256k1"),s=globalThis.crypto||globalThis.msCrypto||{},a=s.subtle||s.webkitSubtle,c=i.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex"),d=i.alloc(32,0);function h(e,t){if(!e)throw new Error(t||"Assertion failed")}function u(e){return t=e,!(!i.isBuffer(t)||32!==t.length)&&e.compare(d)>0&&e.compare(c)<0;var t}function f(e){if(void 0===s.getRandomValues)return i.from(s.randomBytes(e));const t=new Uint8Array(e);return s.getRandomValues(t),i.from(t)}async function l(e){if(!s.createHash){const t=await a.digest("SHA-512",e);return new Uint8Array(t)}const t=s.createHash("sha512").update(e).digest();return new Uint8Array(t)}function p(e){return async function(t,r,n){if(a&&a[e]&&a.importKey){const o={name:"AES-CBC"},s=await a.importKey("raw",r,o,!1,[e]),c={name:"AES-CBC",iv:t},d=await a[e](c,s,n);return i.from(new Uint8Array(d))}if("encrypt"===e&&s.createCipheriv){const e=s.createCipheriv("aes-256-cbc",r,t),o=e.update(n),a=e.final();return i.concat([o,a])}if("decrypt"===e&&s.createDecipheriv){const e=s.createDecipheriv("aes-256-cbc",r,t),o=e.update(n),a=e.final();return i.concat([o,a])}throw new Error(`Unsupported operation: ${e}`)}}const y=p("encrypt"),b=p("decrypt");async function m(e,t){if(!s.createHmac){const r={name:"HMAC",hash:{name:"SHA-256"}},n=await a.importKey("raw",new Uint8Array(e),r,!1,["sign","verify"]),o=await a.sign("HMAC",n,t);return i.from(new Uint8Array(o))}const r=s.createHmac("sha256",i.from(e));return r.update(t),r.digest()}const g=function(){let e=f(32);for(;!u(e);)e=f(32);return e},v=function(e){return h(32===e.length,"Bad private key"),h(u(e),"Bad private key"),i.from(o.keyFromPrivate(e).getPublic("array"))},w=function(e){return h(32===e.length,"Bad private key"),h(u(e),"Bad private key"),i.from(o.keyFromPrivate(e).getPublic(!0,"array"))},S=async function(e,t){return h(32===e.length,"Bad private key"),h(u(e),"Bad private key"),h(t.length>0,"Message should not be empty"),h(t.length<=32,"Message is too long"),i.from(o.sign(t,e,{canonical:!0}).toDER())},_=async function(e,t,r){if(h(65===e.length||33===e.length,"Bad public key"),65===e.length&&h(4===e[0],"Bad public key"),33===e.length&&h(2===e[0]||3===e[0],"Bad public key"),h(t.length>0,"Message should not be empty"),h(t.length<=32,"Message is too long"),o.verify(t,r,e))return null;throw new Error("Bad signature")},A=async function(e,t){h(i.isBuffer(e),"Bad private key"),h(i.isBuffer(t),"Bad public key"),h(32===e.length,"Bad private key"),h(u(e),"Bad private key"),h(65===t.length||33===t.length,"Bad public key"),65===t.length&&h(4===t[0],"Bad public key"),33===t.length&&h(2===t[0]||3===t[0],"Bad public key");const r=o.keyFromPrivate(e),n=o.keyFromPublic(t),s=r.derive(n.getPublic());return i.from(s.toArray())},k=A,P=async function(e,t){h(i.isBuffer(e),"Bad private key"),h(i.isBuffer(t),"Bad public key"),h(32===e.length,"Bad private key"),h(u(e),"Bad private key"),h(65===t.length||33===t.length,"Bad public key"),65===t.length&&h(4===t[0],"Bad public key"),33===t.length&&h(2===t[0]||3===t[0],"Bad public key");const r=o.keyFromPrivate(e),n=o.keyFromPublic(t),s=r.derive(n.getPublic());return i.from(s.toString(16,64),"hex")},E=async function(e,t,r){let n=(r=r||{}).ephemPrivateKey||f(32);for(;!u(n);)n=r.ephemPrivateKey||f(32);const o=v(n),s=await k(n,e),a=await l(s),c=r.iv||f(16),d=a.slice(0,32),h=a.slice(32),p=await y(c,i.from(d),t),b=i.concat([c,o,p]);return{iv:c,ephemPublicKey:o,ciphertext:p,mac:await m(i.from(h),b)}},x=async function(e,t,r){const n=null!=r&&r,o=n?P:k,s=await o(e,t.ephemPublicKey),a=await l(s),c=a.slice(0,32),d=a.slice(32),h=i.concat([t.iv,t.ephemPublicKey,t.ciphertext]),u=await async function(e,t,r){return function(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r}(await m(e,t),r)}(i.from(d),h,t.mac);if(!u&&!1===n)return x(e,t,!0);if(!u&&!0===n)throw new Error("bad MAC after trying padded");const f=await b(t.iv,i.from(c),t.ciphertext);return i.from(new Uint8Array(f))}},448:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.shake256=t.shake128=t.keccak_512=t.keccak_384=t.keccak_256=t.keccak_224=t.sha3_512=t.sha3_384=t.sha3_256=t.sha3_224=t.Keccak=void 0,t.keccakP=v;const n=r(8460),i=r(8081),o=r(9074),s=[],a=[],c=[],d=BigInt(0),h=BigInt(1),u=BigInt(2),f=BigInt(7),l=BigInt(256),p=BigInt(113);for(let e=0,t=h,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],s.push(2*(5*n+r)),a.push((e+1)*(e+2)/2%64);let i=d;for(let e=0;e<7;e++)t=(t<<h^(t>>f)*p)%l,t&u&&(i^=h<<(h<<BigInt(e))-h);c.push(i)}const[y,b]=(0,i.split)(c,!0),m=(e,t,r)=>r>32?(0,i.rotlBH)(e,t,r):(0,i.rotlSH)(e,t,r),g=(e,t,r)=>r>32?(0,i.rotlBL)(e,t,r):(0,i.rotlSL)(e,t,r);function v(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const n=(t+8)%10,i=(t+2)%10,o=r[i],s=r[i+1],a=m(o,s,1)^r[n],c=g(o,s,1)^r[n+1];for(let r=0;r<50;r+=10)e[t+r]^=a,e[t+r+1]^=c}let t=e[2],i=e[3];for(let r=0;r<24;r++){const n=a[r],o=m(t,i,n),c=g(t,i,n),d=s[r];t=e[d],i=e[d+1],e[d]=o,e[d+1]=c}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=y[n],e[1]^=b[n]}r.fill(0)}class w extends o.Hash{constructor(e,t,r,i=!1,s=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,n.anumber)(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,o.u32)(this.state)}keccak(){o.isLE||(0,o.byteSwap32)(this.state32),v(this.state32,this.rounds),o.isLE||(0,o.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,n.aexists)(this);const{blockLen:t,state:r}=this,i=(e=(0,o.toBytes)(e)).length;for(let n=0;n<i;){const o=Math.min(t-this.pos,i-n);for(let t=0;t<o;t++)r[this.pos++]^=e[n++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,128&t&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){(0,n.aexists)(this,!1),(0,n.abytes)(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,i=e.length;n<i;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,i-n);e.set(t.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,n.anumber)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,n.aoutput)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:n,rounds:i,enableXOF:o}=this;return e||(e=new w(t,r,n,o,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=r,e.outputLen=n,e.enableXOF=o,e.destroyed=this.destroyed,e}}t.Keccak=w;const S=(e,t,r)=>(0,o.wrapConstructor)((()=>new w(t,e,r)));t.sha3_224=S(6,144,28),t.sha3_256=S(6,136,32),t.sha3_384=S(6,104,48),t.sha3_512=S(6,72,64),t.keccak_224=S(1,144,28),t.keccak_256=S(1,136,32),t.keccak_384=S(1,104,48),t.keccak_512=S(1,72,64);const _=(e,t,r)=>(0,o.wrapXOFConstructorWithOpts)(((n={})=>new w(t,e,void 0===n.dkLen?r:n.dkLen,!0)));t.shake128=_(31,168,16),t.shake256=_(31,136,32)},453:(e,t,r)=>{"use strict";var n=r(8212),i=r(8947),o=r(5172);class s{constructor({dataMap:e,lockMap:t}={dataMap:{},lockMap:{}}){n(this,"dataMap",void 0),n(this,"storageLayerName",void 0),n(this,"lockMap",void 0),n(this,"serviceProvider",void 0),this.dataMap=e||{},this.lockMap=t||{},this.storageLayerName="MockStorageLayer"}static fromJSON(e){const{dataMap:t,lockMap:r,storageLayerName:n}=e;if("MockStorageLayer"===n)return new s({dataMap:t,lockMap:r})}async getMetadata(e){const{serviceProvider:t,privKey:r}=e;let n;return n=r?i.getPubKeyPoint(r).x:t.retrievePubKeyPoint().getX(),this.dataMap[n.toString("hex")]?JSON.parse(this.dataMap[n.toString("hex")]):{message:i.KEY_NOT_FOUND}}async setMetadata(e){const{serviceProvider:t,privKey:r,input:n}=e;let s;return s=r?i.getPubKeyPoint(r).x:t.retrievePubKeyPoint().getX(),this.dataMap[s.toString("hex")]=o(n),{message:"success"}}async setMetadataStream(e){const{serviceProvider:t,privKey:r,input:n}=e;return n.forEach(((e,n)=>{let s;s=r&&r[n]?i.getPubKeyPoint(r[n]).x:t.retrievePubKeyPoint().getX(),this.dataMap[s.toString("hex")]=o(e)})),{message:"success"}}async acquireWriteLock(e){const{serviceProvider:t,privKey:r}=e;let n;if(n=r?i.getPubKeyPoint(r).x:t.retrievePubKeyPoint().getX(),this.lockMap[n.toString("hex")])return{status:0};const o=i.generateID();return this.lockMap[n.toString("hex")]=o,{status:1,id:o}}async releaseWriteLock(e){const{serviceProvider:t,privKey:r,id:n}=e;let o;return o=r?i.getPubKeyPoint(r).x:t.retrievePubKeyPoint().getX(),this.lockMap[o.toString("hex")]?n!==this.lockMap[o.toString("hex")]?{status:2}:(this.lockMap[o.toString("hex")]=null,{status:1}):{status:0}}toJSON(){return{dataMap:this.dataMap,serviceProvider:this.serviceProvider,storageLayerName:this.storageLayerName}}}e.exports=s},461:(e,t,r)=>{"use strict";var n=r(7784),i=r(5615);function o(e,t){return 55296==(64512&e.charCodeAt(t))&&!(t<0||t+1>=e.length)&&56320==(64512&e.charCodeAt(t+1))}function s(e){return(e>>>24|e>>>8&65280|e<<8&16711680|(255&e)<<24)>>>0}function a(e){return 1===e.length?"0"+e:e}function c(e){return 7===e.length?"0"+e:6===e.length?"00"+e:5===e.length?"000"+e:4===e.length?"0000"+e:3===e.length?"00000"+e:2===e.length?"000000"+e:1===e.length?"0000000"+e:e}t.inherits=i,t.toArray=function(e,t){if(Array.isArray(e))return e.slice();if(!e)return[];var r=[];if("string"==typeof e)if(t){if("hex"===t)for((e=e.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(e="0"+e),i=0;i<e.length;i+=2)r.push(parseInt(e[i]+e[i+1],16))}else for(var n=0,i=0;i<e.length;i++){var s=e.charCodeAt(i);s<128?r[n++]=s:s<2048?(r[n++]=s>>6|192,r[n++]=63&s|128):o(e,i)?(s=65536+((1023&s)<<10)+(1023&e.charCodeAt(++i)),r[n++]=s>>18|240,r[n++]=s>>12&63|128,r[n++]=s>>6&63|128,r[n++]=63&s|128):(r[n++]=s>>12|224,r[n++]=s>>6&63|128,r[n++]=63&s|128)}else for(i=0;i<e.length;i++)r[i]=0|e[i];return r},t.toHex=function(e){for(var t="",r=0;r<e.length;r++)t+=a(e[r].toString(16));return t},t.htonl=s,t.toHex32=function(e,t){for(var r="",n=0;n<e.length;n++){var i=e[n];"little"===t&&(i=s(i)),r+=c(i.toString(16))}return r},t.zero2=a,t.zero8=c,t.join32=function(e,t,r,i){var o=r-t;n(o%4==0);for(var s=new Array(o/4),a=0,c=t;a<s.length;a++,c+=4){var d;d="big"===i?e[c]<<24|e[c+1]<<16|e[c+2]<<8|e[c+3]:e[c+3]<<24|e[c+2]<<16|e[c+1]<<8|e[c],s[a]=d>>>0}return s},t.split32=function(e,t){for(var r=new Array(4*e.length),n=0,i=0;n<e.length;n++,i+=4){var o=e[n];"big"===t?(r[i]=o>>>24,r[i+1]=o>>>16&255,r[i+2]=o>>>8&255,r[i+3]=255&o):(r[i+3]=o>>>24,r[i+2]=o>>>16&255,r[i+1]=o>>>8&255,r[i]=255&o)}return r},t.rotr32=function(e,t){return e>>>t|e<<32-t},t.rotl32=function(e,t){return e<<t|e>>>32-t},t.sum32=function(e,t){return e+t>>>0},t.sum32_3=function(e,t,r){return e+t+r>>>0},t.sum32_4=function(e,t,r,n){return e+t+r+n>>>0},t.sum32_5=function(e,t,r,n,i){return e+t+r+n+i>>>0},t.sum64=function(e,t,r,n){var i=e[t],o=n+e[t+1]>>>0,s=(o<n?1:0)+r+i;e[t]=s>>>0,e[t+1]=o},t.sum64_hi=function(e,t,r,n){return(t+n>>>0<t?1:0)+e+r>>>0},t.sum64_lo=function(e,t,r,n){return t+n>>>0},t.sum64_4_hi=function(e,t,r,n,i,o,s,a){var c=0,d=t;return c+=(d=d+n>>>0)<t?1:0,c+=(d=d+o>>>0)<o?1:0,e+r+i+s+(c+=(d=d+a>>>0)<a?1:0)>>>0},t.sum64_4_lo=function(e,t,r,n,i,o,s,a){return t+n+o+a>>>0},t.sum64_5_hi=function(e,t,r,n,i,o,s,a,c,d){var h=0,u=t;return h+=(u=u+n>>>0)<t?1:0,h+=(u=u+o>>>0)<o?1:0,h+=(u=u+a>>>0)<a?1:0,e+r+i+s+c+(h+=(u=u+d>>>0)<d?1:0)>>>0},t.sum64_5_lo=function(e,t,r,n,i,o,s,a,c,d){return t+n+o+a+d>>>0},t.rotr64_hi=function(e,t,r){return(t<<32-r|e>>>r)>>>0},t.rotr64_lo=function(e,t,r){return(e<<32-r|t>>>r)>>>0},t.shr64_hi=function(e,t,r){return e>>>r},t.shr64_lo=function(e,t,r){return(e<<32-r|t>>>r)>>>0}},527:(e,t,r)=>{"use strict";var n=r(1048).hp,i=r(3330);function o(e,t){return void 0===t&&(t="utf8"),n.isBuffer(e)?a(e.toString("base64")):a(n.from(e,t).toString("base64"))}function s(e){return e=e.toString(),i.default(e).replace(/\-/g,"+").replace(/_/g,"/")}function a(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var c=o;c.encode=o,c.decode=function(e,t){return void 0===t&&(t="utf8"),n.from(s(e),"base64").toString(t)},c.toBase64=s,c.fromBase64=a,c.toBuffer=function(e){return n.from(s(e),"base64")},t.default=c},528:(e,t,r)=>{"use strict";var n,i=r(9629),o=r(9838),s=r(9110),a=r(1155),c=r(4943),d=r(5731),h=r(3468),u=r(2140),f=r(8479),l=r(8449),p=r(8129),y=r(2387),b=r(5865),m=r(1319),g=r(6882),v=Function,w=function(e){try{return v('"use strict"; return ('+e+").constructor;")()}catch(e){}},S=r(9336),_=r(4940),A=function(){throw new h},k=S?function(){try{return A}catch(e){try{return S(arguments,"callee").get}catch(e){return A}}}():A,P=r(3558)(),E=r(6369),x=r(7345),M=r(7859),I=r(6095),O=r(4531),T={},C="undefined"!=typeof Uint8Array&&E?E(Uint8Array):n,L={__proto__:null,"%AggregateError%":"undefined"==typeof AggregateError?n:AggregateError,"%Array%":Array,"%ArrayBuffer%":"undefined"==typeof ArrayBuffer?n:ArrayBuffer,"%ArrayIteratorPrototype%":P&&E?E([][Symbol.iterator]()):n,"%AsyncFromSyncIteratorPrototype%":n,"%AsyncFunction%":T,"%AsyncGenerator%":T,"%AsyncGeneratorFunction%":T,"%AsyncIteratorPrototype%":T,"%Atomics%":"undefined"==typeof Atomics?n:Atomics,"%BigInt%":"undefined"==typeof BigInt?n:BigInt,"%BigInt64Array%":"undefined"==typeof BigInt64Array?n:BigInt64Array,"%BigUint64Array%":"undefined"==typeof BigUint64Array?n:BigUint64Array,"%Boolean%":Boolean,"%DataView%":"undefined"==typeof DataView?n:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":o,"%eval%":eval,"%EvalError%":s,"%Float32Array%":"undefined"==typeof Float32Array?n:Float32Array,"%Float64Array%":"undefined"==typeof Float64Array?n:Float64Array,"%FinalizationRegistry%":"undefined"==typeof FinalizationRegistry?n:FinalizationRegistry,"%Function%":v,"%GeneratorFunction%":T,"%Int8Array%":"undefined"==typeof Int8Array?n:Int8Array,"%Int16Array%":"undefined"==typeof Int16Array?n:Int16Array,"%Int32Array%":"undefined"==typeof Int32Array?n:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":P&&E?E(E([][Symbol.iterator]())):n,"%JSON%":"object"==typeof JSON?JSON:n,"%Map%":"undefined"==typeof Map?n:Map,"%MapIteratorPrototype%":"undefined"!=typeof Map&&P&&E?E((new Map)[Symbol.iterator]()):n,"%Math%":Math,"%Number%":Number,"%Object%":i,"%Object.getOwnPropertyDescriptor%":S,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":"undefined"==typeof Promise?n:Promise,"%Proxy%":"undefined"==typeof Proxy?n:Proxy,"%RangeError%":a,"%ReferenceError%":c,"%Reflect%":"undefined"==typeof Reflect?n:Reflect,"%RegExp%":RegExp,"%Set%":"undefined"==typeof Set?n:Set,"%SetIteratorPrototype%":"undefined"!=typeof Set&&P&&E?E((new Set)[Symbol.iterator]()):n,"%SharedArrayBuffer%":"undefined"==typeof SharedArrayBuffer?n:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":P&&E?E(""[Symbol.iterator]()):n,"%Symbol%":P?Symbol:n,"%SyntaxError%":d,"%ThrowTypeError%":k,"%TypedArray%":C,"%TypeError%":h,"%Uint8Array%":"undefined"==typeof Uint8Array?n:Uint8Array,"%Uint8ClampedArray%":"undefined"==typeof Uint8ClampedArray?n:Uint8ClampedArray,"%Uint16Array%":"undefined"==typeof Uint16Array?n:Uint16Array,"%Uint32Array%":"undefined"==typeof Uint32Array?n:Uint32Array,"%URIError%":u,"%WeakMap%":"undefined"==typeof WeakMap?n:WeakMap,"%WeakRef%":"undefined"==typeof WeakRef?n:WeakRef,"%WeakSet%":"undefined"==typeof WeakSet?n:WeakSet,"%Function.prototype.call%":O,"%Function.prototype.apply%":I,"%Object.defineProperty%":_,"%Object.getPrototypeOf%":x,"%Math.abs%":f,"%Math.floor%":l,"%Math.max%":p,"%Math.min%":y,"%Math.pow%":b,"%Math.round%":m,"%Math.sign%":g,"%Reflect.getPrototypeOf%":M};if(E)try{null.error}catch(e){var N=E(E(e));L["%Error.prototype%"]=N}var R=function e(t){var r;if("%AsyncFunction%"===t)r=w("async function () {}");else if("%GeneratorFunction%"===t)r=w("function* () {}");else if("%AsyncGeneratorFunction%"===t)r=w("async function* () {}");else if("%AsyncGenerator%"===t){var n=e("%AsyncGeneratorFunction%");n&&(r=n.prototype)}else if("%AsyncIteratorPrototype%"===t){var i=e("%AsyncGenerator%");i&&E&&(r=E(i.prototype))}return L[t]=r,r},B={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototyp