UNPKG

swtc-keypairs

Version:
14 lines (13 loc) 31.1 kB
import t from"inherits";import e from"brorand";import{ec as r,eddsa as n}from"elliptic";import{Factory as i}from"swtc-address-codec";import{funcHexToBytes as o,funcBytesToHex as s}from"swtc-chains";import u from"bn.js";var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function h(t,e){return t(e={exports:{}},e.exports),e.exports /* object-assign (c) Sindre Sorhus @license MIT */}var a=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable;function p(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var d=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach((function(t){n[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var r,n,i=p(t),o=1;o<arguments.length;o++){for(var s in r=Object(arguments[o]))f.call(r,s)&&(i[s]=r[s]);if(a){n=a(r);for(var u=0;u<n.length;u++)l.call(r,n[u])&&(i[n[u]]=r[n[u]])}}return i},g=function(t){return t instanceof Buffer},y=h((function(e,r){var n=/%[sdj%]/g;r.format=function(t){if(!m(t)){for(var e=[],r=0;r<arguments.length;r++)e.push(s(arguments[r]));return e.join(" ")}r=1;for(var i=arguments,o=i.length,u=String(t).replace(n,(function(t){if("%%"===t)return"%";if(r>=o)return t;switch(t){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":try{return JSON.stringify(i[r++])}catch(t){return"[Circular]"}default:return t}})),c=i[r];r<o;c=i[++r])y(c)||!_(c)?u+=" "+c:u+=" "+s(c);return u},r.deprecate=function(t,e){if(b(c.process))return function(){return r.deprecate(t,e).apply(this,arguments)};if(!0===process.noDeprecation)return t;var n=!1;return function(){if(!n){if(process.throwDeprecation)throw new Error(e);process.traceDeprecation?console.trace(e):console.error(e),n=!0}return t.apply(this,arguments)}};var i,o={};function s(t,e){var n={seen:[],stylize:h};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),d(e)?n.showHidden=e:e&&r._extend(n,e),b(n.showHidden)&&(n.showHidden=!1),b(n.depth)&&(n.depth=2),b(n.colors)&&(n.colors=!1),b(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=u),a(n,t,n.depth)}function u(t,e){var r=s.styles[e];return r?"["+s.colors[r][0]+"m"+t+"["+s.colors[r][1]+"m":t}function h(t,e){return t}function a(t,e,n){if(t.customInspect&&e&&E(e.inspect)&&e.inspect!==r.inspect&&(!e.constructor||e.constructor.prototype!==e)){var i=e.inspect(n,t);return m(i)||(i=a(t,i,n)),i}var o=function(t,e){if(b(e))return t.stylize("undefined","undefined");if(m(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}if(v(e))return t.stylize(""+e,"number");if(d(e))return t.stylize(""+e,"boolean");if(y(e))return t.stylize("null","null")}(t,e);if(o)return o;var s=Object.keys(e),u=function(t){var e={};return t.forEach((function(t,r){e[t]=!0})),e}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(e)),x(e)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(e);if(0===s.length){if(E(e)){var c=e.name?": "+e.name:"";return t.stylize("[Function"+c+"]","special")}if(S(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(w(e))return t.stylize(Date.prototype.toString.call(e),"date");if(x(e))return f(e)}var h,g="",_=!1,k=["{","}"];(p(e)&&(_=!0,k=["[","]"]),E(e))&&(g=" [Function"+(e.name?": "+e.name:"")+"]");return S(e)&&(g=" "+RegExp.prototype.toString.call(e)),w(e)&&(g=" "+Date.prototype.toUTCString.call(e)),x(e)&&(g=" "+f(e)),0!==s.length||_&&0!=e.length?n<0?S(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special"):(t.seen.push(e),h=_?function(t,e,r,n,i){for(var o=[],s=0,u=e.length;s<u;++s)z(e,String(s))?o.push(l(t,e,r,n,String(s),!0)):o.push("");return i.forEach((function(i){i.match(/^\d+$/)||o.push(l(t,e,r,n,i,!0))})),o}(t,e,n,u,s):s.map((function(r){return l(t,e,n,u,r,_)})),t.seen.pop(),function(t,e,r){if(t.reduce((function(t,e){return e.indexOf("\n"),t+e.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60)return r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1];return r[0]+e+" "+t.join(", ")+" "+r[1]}(h,g,k)):k[0]+g+k[1]}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function l(t,e,r,n,i,o){var s,u,c;if((c=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?u=c.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):c.set&&(u=t.stylize("[Setter]","special")),z(n,i)||(s="["+i+"]"),u||(t.seen.indexOf(c.value)<0?(u=y(r)?a(t,c.value,null):a(t,c.value,r-1)).indexOf("\n")>-1&&(u=o?u.split("\n").map((function(t){return" "+t})).join("\n").substr(2):"\n"+u.split("\n").map((function(t){return" "+t})).join("\n")):u=t.stylize("[Circular]","special")),b(s)){if(o&&i.match(/^\d+$/))return u;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+u}function p(t){return Array.isArray(t)}function d(t){return"boolean"==typeof t}function y(t){return null===t}function v(t){return"number"==typeof t}function m(t){return"string"==typeof t}function b(t){return void 0===t}function S(t){return _(t)&&"[object RegExp]"===k(t)}function _(t){return"object"==typeof t&&null!==t}function w(t){return _(t)&&"[object Date]"===k(t)}function x(t){return _(t)&&("[object Error]"===k(t)||t instanceof Error)}function E(t){return"function"==typeof t}function k(t){return Object.prototype.toString.call(t)}function O(t){return t<10?"0"+t.toString(10):t.toString(10)}r.debuglog=function(t){if(b(i)&&(i=process.env.NODE_DEBUG||""),t=t.toUpperCase(),!o[t])if(new RegExp("\\b"+t+"\\b","i").test(i)){var e=process.pid;o[t]=function(){var n=r.format.apply(r,arguments);console.error("%s %d: %s",t,e,n)}}else o[t]=function(){};return o[t]},r.inspect=s,s.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},s.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=p,r.isBoolean=d,r.isNull=y,r.isNullOrUndefined=function(t){return null==t},r.isNumber=v,r.isString=m,r.isSymbol=function(t){return"symbol"==typeof t},r.isUndefined=b,r.isRegExp=S,r.isObject=_,r.isDate=w,r.isError=x,r.isFunction=E,r.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},r.isBuffer=g;var j=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function A(){var t=new Date,e=[O(t.getHours()),O(t.getMinutes()),O(t.getSeconds())].join(":");return[t.getDate(),j[t.getMonth()],e].join(" ")}function z(t,e){return Object.prototype.hasOwnProperty.call(t,e)}r.log=function(){console.log("%s - %s",A(),r.format.apply(r,arguments))},r.inherits=t,r._extend=function(t,e){if(!e||!_(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}})),v=(y.format,y.deprecate,y.debuglog,y.inspect,y.isArray,y.isBoolean,y.isNull,y.isNullOrUndefined,y.isNumber,y.isString,y.isSymbol,y.isUndefined,y.isRegExp,y.isObject,y.isDate,y.isError,y.isFunction,y.isPrimitive,y.isBuffer,y.log,y.inherits,y._extend,h((function(t){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * @license MIT */ function e(t,e){if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0}function r(t){return c.Buffer&&"function"==typeof c.Buffer.isBuffer?c.Buffer.isBuffer(t):!(null==t||!t._isBuffer)}var n=Object.prototype.hasOwnProperty,i=Array.prototype.slice,o="foo"===function(){}.name;function s(t){return Object.prototype.toString.call(t)}function u(t){return!r(t)&&("function"==typeof c.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):!!t&&(t instanceof DataView||!!(t.buffer&&t.buffer instanceof ArrayBuffer))))}var h=t.exports=v,a=/\s*function\s+([^\(\s]*)\s*/;function f(t){if(y.isFunction(t)){if(o)return t.name;var e=t.toString().match(a);return e&&e[1]}}function l(t,e){return"string"==typeof t?t.length<e?t:t.slice(0,e):t}function p(t){if(o||!y.isFunction(t))return y.inspect(t);var e=f(t);return"[Function"+(e?": "+e:"")+"]"}function g(t,e,r,n,i){throw new h.AssertionError({message:r,actual:t,expected:e,operator:n,stackStartFunction:i})}function v(t,e){t||g(t,!0,e,"==",h.ok)}function m(t,n,o,c){if(t===n)return!0;if(r(t)&&r(n))return 0===e(t,n);if(y.isDate(t)&&y.isDate(n))return t.getTime()===n.getTime();if(y.isRegExp(t)&&y.isRegExp(n))return t.source===n.source&&t.global===n.global&&t.multiline===n.multiline&&t.lastIndex===n.lastIndex&&t.ignoreCase===n.ignoreCase;if(null!==t&&"object"==typeof t||null!==n&&"object"==typeof n){if(u(t)&&u(n)&&s(t)===s(n)&&!(t instanceof Float32Array||t instanceof Float64Array))return 0===e(new Uint8Array(t.buffer),new Uint8Array(n.buffer));if(r(t)!==r(n))return!1;var h=(c=c||{actual:[],expected:[]}).actual.indexOf(t);return-1!==h&&h===c.expected.indexOf(n)||(c.actual.push(t),c.expected.push(n),function(t,e,r,n){if(null==t||null==e)return!1;if(y.isPrimitive(t)||y.isPrimitive(e))return t===e;if(r&&Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;var o=b(t),s=b(e);if(o&&!s||!o&&s)return!1;if(o)return t=i.call(t),e=i.call(e),m(t,e,r);var u,c,h=w(t),a=w(e);if(h.length!==a.length)return!1;for(h.sort(),a.sort(),c=h.length-1;c>=0;c--)if(h[c]!==a[c])return!1;for(c=h.length-1;c>=0;c--)if(u=h[c],!m(t[u],e[u],r,n))return!1;return!0}(t,n,o,c))}return o?t===n:t==n}function b(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function S(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&!0===e.call({},t)}function _(t,e,r,n){var i;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof r&&(n=r,r=null),i=function(t){var e;try{t()}catch(t){e=t}return e}(e),n=(r&&r.name?" ("+r.name+").":".")+(n?" "+n:"."),t&&!i&&g(i,r,"Missing expected exception"+n);var o="string"==typeof n,s=!t&&i&&!r;if((!t&&y.isError(i)&&o&&S(i,r)||s)&&g(i,r,"Got unwanted exception"+n),t&&i&&r&&!S(i,r)||!t&&i)throw i}h.AssertionError=function(t){this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=function(t){return l(p(t.actual),128)+" "+t.operator+" "+l(p(t.expected),128)}(this),this.generatedMessage=!0);var e=t.stackStartFunction||g;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var r=new Error;if(r.stack){var n=r.stack,i=f(e),o=n.indexOf("\n"+i);if(o>=0){var s=n.indexOf("\n",o+1);n=n.substring(s+1)}this.stack=n}}},y.inherits(h.AssertionError,Error),h.fail=g,h.ok=v,h.equal=function(t,e,r){t!=e&&g(t,e,r,"==",h.equal)},h.notEqual=function(t,e,r){t==e&&g(t,e,r,"!=",h.notEqual)},h.deepEqual=function(t,e,r){m(t,e,!1)||g(t,e,r,"deepEqual",h.deepEqual)},h.deepStrictEqual=function(t,e,r){m(t,e,!0)||g(t,e,r,"deepStrictEqual",h.deepStrictEqual)},h.notDeepEqual=function(t,e,r){m(t,e,!1)&&g(t,e,r,"notDeepEqual",h.notDeepEqual)},h.notDeepStrictEqual=function t(e,r,n){m(e,r,!0)&&g(e,r,n,"notDeepStrictEqual",t)},h.strictEqual=function(t,e,r){t!==e&&g(t,e,r,"===",h.strictEqual)},h.notStrictEqual=function(t,e,r){t===e&&g(t,e,r,"!==",h.notStrictEqual)},h.throws=function(t,e,r){_(!0,t,e,r)},h.doesNotThrow=function(t,e,r){_(!1,t,e,r)},h.ifError=function(t){if(t)throw t},h.strict=d((function t(e,r){e||g(e,!0,r,"==",t)}),h,{equal:h.strictEqual,deepEqual:h.deepStrictEqual,notEqual:h.notStrictEqual,notDeepEqual:h.notDeepStrictEqual}),h.strict.strict=h.strict;var w=Object.keys||function(t){var e=[];for(var r in t)n.call(t,r)&&e.push(r);return e}}))),m=b;function b(t,e){if(!t)throw new Error(e||"Assertion failed")}function S(t,e){return 55296==(64512&t.charCodeAt(e))&&(!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1)))}function _(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function w(t){return 1===t.length?"0"+t:t}function x(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}b.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var E={inherits:t,toArray:function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),i=0;i<t.length;i+=2)r.push(parseInt(t[i]+t[i+1],16))}else for(var n=0,i=0;i<t.length;i++){var o=t.charCodeAt(i);o<128?r[n++]=o:o<2048?(r[n++]=o>>6|192,r[n++]=63&o|128):S(t,i)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++i)),r[n++]=o>>18|240,r[n++]=o>>12&63|128,r[n++]=o>>6&63|128,r[n++]=63&o|128):(r[n++]=o>>12|224,r[n++]=o>>6&63|128,r[n++]=63&o|128)}else for(i=0;i<t.length;i++)r[i]=0|t[i];return r},toHex:function(t){for(var e="",r=0;r<t.length;r++)e+=w(t[r].toString(16));return e},htonl:_,toHex32:function(t,e){for(var r="",n=0;n<t.length;n++){var i=t[n];"little"===e&&(i=_(i)),r+=x(i.toString(16))}return r},zero2:w,zero8:x,join32:function(t,e,r,n){var i=r-e;m(i%4==0);for(var o=new Array(i/4),s=0,u=e;s<o.length;s++,u+=4){var c;c="big"===n?t[u]<<24|t[u+1]<<16|t[u+2]<<8|t[u+3]:t[u+3]<<24|t[u+2]<<16|t[u+1]<<8|t[u],o[s]=c>>>0}return o},split32:function(t,e){for(var r=new Array(4*t.length),n=0,i=0;n<t.length;n++,i+=4){var o=t[n];"big"===e?(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},rotr32:function(t,e){return t>>>e|t<<32-e},rotl32:function(t,e){return t<<e|t>>>32-e},sum32:function(t,e){return t+e>>>0},sum32_3:function(t,e,r){return t+e+r>>>0},sum32_4:function(t,e,r,n){return t+e+r+n>>>0},sum32_5:function(t,e,r,n,i){return t+e+r+n+i>>>0},sum64:function(t,e,r,n){var i=t[e],o=n+t[e+1]>>>0,s=(o<n?1:0)+r+i;t[e]=s>>>0,t[e+1]=o},sum64_hi:function(t,e,r,n){return(e+n>>>0<e?1:0)+t+r>>>0},sum64_lo:function(t,e,r,n){return e+n>>>0},sum64_4_hi:function(t,e,r,n,i,o,s,u){var c=0,h=e;return c+=(h=h+n>>>0)<e?1:0,c+=(h=h+o>>>0)<o?1:0,t+r+i+s+(c+=(h=h+u>>>0)<u?1:0)>>>0},sum64_4_lo:function(t,e,r,n,i,o,s,u){return e+n+o+u>>>0},sum64_5_hi:function(t,e,r,n,i,o,s,u,c,h){var a=0,f=e;return a+=(f=f+n>>>0)<e?1:0,a+=(f=f+o>>>0)<o?1:0,a+=(f=f+u>>>0)<u?1:0,t+r+i+s+c+(a+=(f=f+h>>>0)<h?1:0)>>>0},sum64_5_lo:function(t,e,r,n,i,o,s,u,c,h){return e+n+o+u+h>>>0},rotr64_hi:function(t,e,r){return(e<<32-r|t>>>r)>>>0},rotr64_lo:function(t,e,r){return(t<<32-r|e>>>r)>>>0},shr64_hi:function(t,e,r){return t>>>r},shr64_lo:function(t,e,r){return(t<<32-r|e>>>r)>>>0}};function k(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}var O=k;k.prototype.update=function(t,e){if(t=E.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=E.join32(t,0,t.length-r,this.endian);for(var n=0;n<t.length;n+=this._delta32)this._update(t,n,n+this._delta32)}return this},k.prototype.digest=function(t){return this.update(this._pad()),m(null===this.pending),this._digest(t)},k.prototype._pad=function(){var t=this.pendingTotal,e=this._delta8,r=e-(t+this.padLength)%e,n=new Array(r+this.padLength);n[0]=128;for(var i=1;i<r;i++)n[i]=0;if(t<<=3,"big"===this.endian){for(var o=8;o<this.padLength;o++)n[i++]=0;n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=t>>>24&255,n[i++]=t>>>16&255,n[i++]=t>>>8&255,n[i++]=255&t}else for(n[i++]=255&t,n[i++]=t>>>8&255,n[i++]=t>>>16&255,n[i++]=t>>>24&255,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,o=8;o<this.padLength;o++)n[i++]=0;return n};var j={BlockHash:O},A=E.rotr32;function z(t,e,r){return t&e^~t&r}function q(t,e,r){return t&e^t&r^e&r}function B(t,e,r){return t^e^r}var D={ft_1:function(t,e,r,n){return 0===t?z(e,r,n):1===t||3===t?B(e,r,n):2===t?q(e,r,n):void 0},ch32:z,maj32:q,p32:B,s0_256:function(t){return A(t,2)^A(t,13)^A(t,22)},s1_256:function(t){return A(t,6)^A(t,11)^A(t,25)},g0_256:function(t){return A(t,7)^A(t,18)^t>>>3},g1_256:function(t){return A(t,17)^A(t,19)^t>>>10}},T=E.rotl32,H=E.sum32,N=E.sum32_5,P=D.ft_1,C=j.BlockHash,F=[1518500249,1859775393,2400959708,3395469782];function U(){if(!(this instanceof U))return new U;C.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}E.inherits(U,C);var L=U;U.blockSize=512,U.outSize=160,U.hmacStrength=80,U.padLength=64,U.prototype._update=function(t,e){for(var r=this.W,n=0;n<16;n++)r[n]=t[e+n];for(;n<r.length;n++)r[n]=T(r[n-3]^r[n-8]^r[n-14]^r[n-16],1);var i=this.h[0],o=this.h[1],s=this.h[2],u=this.h[3],c=this.h[4];for(n=0;n<r.length;n++){var h=~~(n/20),a=N(T(i,5),P(h,o,s,u),c,r[n],F[h]);c=u,u=s,s=T(o,30),o=i,i=a}this.h[0]=H(this.h[0],i),this.h[1]=H(this.h[1],o),this.h[2]=H(this.h[2],s),this.h[3]=H(this.h[3],u),this.h[4]=H(this.h[4],c)},U.prototype._digest=function(t){return"hex"===t?E.toHex32(this.h,"big"):E.split32(this.h,"big")};var R=E.sum32,K=E.sum32_4,I=E.sum32_5,M=D.ch32,J=D.maj32,W=D.s0_256,V=D.s1_256,$=D.g0_256,G=D.g1_256,Z=j.BlockHash,Q=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function X(){if(!(this instanceof X))return new X;Z.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=Q,this.W=new Array(64)}E.inherits(X,Z);var Y=X;function tt(){if(!(this instanceof tt))return new tt;Y.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}X.blockSize=512,X.outSize=256,X.hmacStrength=192,X.padLength=64,X.prototype._update=function(t,e){for(var r=this.W,n=0;n<16;n++)r[n]=t[e+n];for(;n<r.length;n++)r[n]=K(G(r[n-2]),r[n-7],$(r[n-15]),r[n-16]);var i=this.h[0],o=this.h[1],s=this.h[2],u=this.h[3],c=this.h[4],h=this.h[5],a=this.h[6],f=this.h[7];for(m(this.k.length===r.length),n=0;n<r.length;n++){var l=I(f,V(c),M(c,h,a),this.k[n],r[n]),p=R(W(i),J(i,o,s));f=a,a=h,h=c,c=R(u,l),u=s,s=o,o=i,i=R(l,p)}this.h[0]=R(this.h[0],i),this.h[1]=R(this.h[1],o),this.h[2]=R(this.h[2],s),this.h[3]=R(this.h[3],u),this.h[4]=R(this.h[4],c),this.h[5]=R(this.h[5],h),this.h[6]=R(this.h[6],a),this.h[7]=R(this.h[7],f)},X.prototype._digest=function(t){return"hex"===t?E.toHex32(this.h,"big"):E.split32(this.h,"big")},E.inherits(tt,Y);var et=tt;tt.blockSize=512,tt.outSize=224,tt.hmacStrength=192,tt.padLength=64,tt.prototype._digest=function(t){return"hex"===t?E.toHex32(this.h.slice(0,7),"big"):E.split32(this.h.slice(0,7),"big")};var rt=E.rotr64_hi,nt=E.rotr64_lo,it=E.shr64_hi,ot=E.shr64_lo,st=E.sum64,ut=E.sum64_hi,ct=E.sum64_lo,ht=E.sum64_4_hi,at=E.sum64_4_lo,ft=E.sum64_5_hi,lt=E.sum64_5_lo,pt=j.BlockHash,dt=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function gt(){if(!(this instanceof gt))return new gt;pt.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=dt,this.W=new Array(160)}E.inherits(gt,pt);var yt=gt;function vt(t,e,r,n,i){var o=t&r^~t&i;return o<0&&(o+=4294967296),o}function mt(t,e,r,n,i,o){var s=e&n^~e&o;return s<0&&(s+=4294967296),s}function bt(t,e,r,n,i){var o=t&r^t&i^r&i;return o<0&&(o+=4294967296),o}function St(t,e,r,n,i,o){var s=e&n^e&o^n&o;return s<0&&(s+=4294967296),s}function _t(t,e){var r=rt(t,e,28)^rt(e,t,2)^rt(e,t,7);return r<0&&(r+=4294967296),r}function wt(t,e){var r=nt(t,e,28)^nt(e,t,2)^nt(e,t,7);return r<0&&(r+=4294967296),r}function xt(t,e){var r=rt(t,e,14)^rt(t,e,18)^rt(e,t,9);return r<0&&(r+=4294967296),r}function Et(t,e){var r=nt(t,e,14)^nt(t,e,18)^nt(e,t,9);return r<0&&(r+=4294967296),r}function kt(t,e){var r=rt(t,e,1)^rt(t,e,8)^it(t,e,7);return r<0&&(r+=4294967296),r}function Ot(t,e){var r=nt(t,e,1)^nt(t,e,8)^ot(t,e,7);return r<0&&(r+=4294967296),r}function jt(t,e){var r=rt(t,e,19)^rt(e,t,29)^it(t,e,6);return r<0&&(r+=4294967296),r}function At(t,e){var r=nt(t,e,19)^nt(e,t,29)^ot(t,e,6);return r<0&&(r+=4294967296),r}function zt(){if(!(this instanceof zt))return new zt;yt.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}gt.blockSize=1024,gt.outSize=512,gt.hmacStrength=192,gt.padLength=128,gt.prototype._prepareBlock=function(t,e){for(var r=this.W,n=0;n<32;n++)r[n]=t[e+n];for(;n<r.length;n+=2){var i=jt(r[n-4],r[n-3]),o=At(r[n-4],r[n-3]),s=r[n-14],u=r[n-13],c=kt(r[n-30],r[n-29]),h=Ot(r[n-30],r[n-29]),a=r[n-32],f=r[n-31];r[n]=ht(i,o,s,u,c,h,a,f),r[n+1]=at(i,o,s,u,c,h,a,f)}},gt.prototype._update=function(t,e){this._prepareBlock(t,e);var r=this.W,n=this.h[0],i=this.h[1],o=this.h[2],s=this.h[3],u=this.h[4],c=this.h[5],h=this.h[6],a=this.h[7],f=this.h[8],l=this.h[9],p=this.h[10],d=this.h[11],g=this.h[12],y=this.h[13],v=this.h[14],b=this.h[15];m(this.k.length===r.length);for(var S=0;S<r.length;S+=2){var _=v,w=b,x=xt(f,l),E=Et(f,l),k=vt(f,l,p,d,g),O=mt(f,l,p,d,g,y),j=this.k[S],A=this.k[S+1],z=r[S],q=r[S+1],B=ft(_,w,x,E,k,O,j,A,z,q),D=lt(_,w,x,E,k,O,j,A,z,q);_=_t(n,i),w=wt(n,i),x=bt(n,i,o,s,u),E=St(n,i,o,s,u,c);var T=ut(_,w,x,E),H=ct(_,w,x,E);v=g,b=y,g=p,y=d,p=f,d=l,f=ut(h,a,B,D),l=ct(a,a,B,D),h=u,a=c,u=o,c=s,o=n,s=i,n=ut(B,D,T,H),i=ct(B,D,T,H)}st(this.h,0,n,i),st(this.h,2,o,s),st(this.h,4,u,c),st(this.h,6,h,a),st(this.h,8,f,l),st(this.h,10,p,d),st(this.h,12,g,y),st(this.h,14,v,b)},gt.prototype._digest=function(t){return"hex"===t?E.toHex32(this.h,"big"):E.split32(this.h,"big")},E.inherits(zt,yt);var qt=zt;zt.blockSize=1024,zt.outSize=384,zt.hmacStrength=192,zt.padLength=128,zt.prototype._digest=function(t){return"hex"===t?E.toHex32(this.h.slice(0,12),"big"):E.split32(this.h.slice(0,12),"big")};var Bt={sha1:L,sha224:et,sha256:Y,sha384:qt,sha512:yt},Dt=E.rotl32,Tt=E.sum32,Ht=E.sum32_3,Nt=E.sum32_4,Pt=j.BlockHash;function Ct(){if(!(this instanceof Ct))return new Ct;Pt.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}E.inherits(Ct,Pt);var Ft=Ct;function Ut(t,e,r,n){return t<=15?e^r^n:t<=31?e&r|~e&n:t<=47?(e|~r)^n:t<=63?e&n|r&~n:e^(r|~n)}function Lt(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function Rt(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}Ct.blockSize=512,Ct.outSize=160,Ct.hmacStrength=192,Ct.padLength=64,Ct.prototype._update=function(t,e){for(var r=this.h[0],n=this.h[1],i=this.h[2],o=this.h[3],s=this.h[4],u=r,c=n,h=i,a=o,f=s,l=0;l<80;l++){var p=Tt(Dt(Nt(r,Ut(l,n,i,o),t[Kt[l]+e],Lt(l)),Mt[l]),s);r=s,s=o,o=Dt(i,10),i=n,n=p,p=Tt(Dt(Nt(u,Ut(79-l,c,h,a),t[It[l]+e],Rt(l)),Jt[l]),f),u=f,f=a,a=Dt(h,10),h=c,c=p}p=Ht(this.h[1],i,a),this.h[1]=Ht(this.h[2],o,f),this.h[2]=Ht(this.h[3],s,u),this.h[3]=Ht(this.h[4],r,c),this.h[4]=Ht(this.h[0],n,h),this.h[0]=p},Ct.prototype._digest=function(t){return"hex"===t?E.toHex32(this.h,"little"):E.split32(this.h,"little")};var Kt=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],It=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],Mt=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],Jt=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],Wt={ripemd160:Ft};function Vt(t,e,r){if(!(this instanceof Vt))return new Vt(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(E.toArray(e,r))}var $t=Vt;Vt.prototype._init=function(t){t.length>this.blockSize&&(t=(new this.Hash).update(t).digest()),m(t.length<=this.blockSize);for(var e=t.length;e<this.blockSize;e++)t.push(0);for(e=0;e<t.length;e++)t[e]^=54;for(this.inner=(new this.Hash).update(t),e=0;e<t.length;e++)t[e]^=106;this.outer=(new this.Hash).update(t)},Vt.prototype.update=function(t,e){return this.inner.update(t,e),this},Vt.prototype.digest=function(t){return this.outer.update(this.inner.digest()),this.outer.digest(t)};var Gt=h((function(t,e){var r=e;r.utils=E,r.common=j,r.sha=Bt,r.ripemd=Wt,r.hmac=$t,r.sha1=r.sha.sha1,r.sha256=r.sha.sha256,r.sha224=r.sha.sha224,r.sha384=r.sha.sha384,r.sha512=r.sha.sha512,r.ripemd160=r.ripemd.ripemd160}));class Zt{constructor(){this.hash=Gt.sha512()}add(t){return this.hash.update(t),this}addU32(t){return this.add([t>>>24&255,t>>>16&255,t>>>8&255,255&t])}finish(){return this.hash.digest()}first256(){return this.finish().slice(0,32)}first256BN(){return new u(this.first256())}}const Qt=r("secp256k1");function Xt(t,e){const r=Qt.curve.n;for(let n=0;n<=4294967295;n++){const i=(new Zt).add(t);void 0!==e&&i.addU32(e),i.addU32(n);const o=i.first256BN();if(o.cmpn(0)>0&&o.cmp(r)<0)return o}throw new Error("impossible unicorn ;)")}const Yt=n("ed25519"),te=r("secp256k1");function ee(t){return Gt.sha512().update(t).digest().slice(0,32)}const re={deriveKeypair:(t,e={})=>{const r="00"+function(t,e={}){const r=e.validator,n=Qt.curve.n,i=Xt(t);if(r)return i;const o=Qt.g.mul(i),s=e.accountIndex||0;return Xt(o.encodeCompressed(),s).add(i).mod(n)}(t,e).toString(16,64).toUpperCase(),n=s(te.keyFromPrivate(r.slice(2)).getPublic().encodeCompressed());return{privateKey:r,publicKey:n}},sign:(t,e)=>s(te.sign(ee(t),o(e),{canonical:!0}).toDER()),verify:(t,e,r)=>te.verify(ee(t),e,o(r)),signTx:(t,e)=>s(te.sign(t,o(e),{canonical:!0}).toDER()),verifyTx:(t,e,r)=>te.verify(t,e,o(r))},ne={deriveKeypair:t=>{const e=ee(t);return{privateKey:"ED"+s(e),publicKey:"ED"+s(Yt.keyFromSecret(e).pubBytes())}},sign:(t,e)=>(v(Array.isArray(t),"message must be array of octets"),s(Yt.sign(t,o(e).slice(1)).toBytes())),verify:(t,e,r)=>Yt.verify(t,o(e),o(r).slice(1)),signTx:(t,e)=>Yt.sign(t,o(e).slice(1)).toHex(),verifyTx:(t,e,r)=>Yt.verify(t,o(e),o(r).slice(1))};function ie(t){return{"ecdsa-secp256k1":re,ed25519:ne}[t]}function oe(t){const e=o(t);return 33===e.length&&237===e[0]?"ed25519":"ecdsa-secp256k1"}function se(t,e){return ie(oe(e)).sign(o(t),e)}function ue(t,e,r){return ie(oe(r)).verify(o(t),e,r)}function ce(t,e){return ie(oe(e)).signTx(t,e)}function he(t,e,r){return ie(oe(r)).verifyTx(t,e,r)}function ae(t="jingtum"){const r=i(t);function n(t,e={}){const n=r.decodeSeed(t),i=ie("ed25519"===n.type?"ed25519":"ecdsa-secp256k1"),o=i.deriveKeypair(n.bytes,e),s=ee("This test message should verify."),u=i.sign(s,o.privateKey);if(!0!==i.verify(s,u,o.publicKey))throw new Error("derived keypair did not generate verifiable signature");return o}function s(t){return r.encodeAccountID(Buffer.from(function(t){const e=Gt.sha256().update(t).digest();return Gt.ripemd160().update(e).digest()}(t)))}return{addressCodec:r,chain:r.chain,deriveKeyPair:n,hash:ee,signTx:ce,verifyTx:he,convertAddressToBytes:function(t){return r.decodeAddress(t).toJSON().data},convertBytesToAddress:function(t){return r.encodeAddress(t)},checkAddress:r.isValidAddress,isValidAddress:r.isValidAddress,deriveKeypair:n,generateSeed:function(t={}){v(!t.entropy||t.entropy.length>=16,"entropy too short");const n=t.entropy?t.entropy.slice(0,16):e(16),i="ed25519"===t.algorithm?"ed25519":"secp256k1";return r.encodeSeed(n,i)},sign:se,verify:ue,deriveAddress:function(t){return s(o(t))},deriveNodeAddress:function(t){return s(function(t){const e=Qt.curve.decodePoint(t),r=Xt(t,0),n=Qt.g.mul(r);return e.add(n).encodeCompressed()}(r.decodeNodePublic(t)))}}}const fe=ae();export{ae as Factory,fe as Keypairs};