swtc-keypairs
Version:
swtc keypairs
14 lines (13 loc) • 31.5 kB
JavaScript
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("inherits")),n=t(require("brorand")),r=require("elliptic"),i=require("swtc-address-codec"),o=require("swtc-chains"),s=t(require("bn.js")),u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(t,e){return t(e={exports:{}},e.exports),e.exports
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/}var h=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;function l(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var p=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={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(t){r[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var n,r,i=l(t),o=1;o<arguments.length;o++){for(var s in n=Object(arguments[o]))a.call(n,s)&&(i[s]=n[s]);if(h){r=h(n);for(var u=0;u<r.length;u++)f.call(n,r[u])&&(i[r[u]]=n[r[u]])}}return i},d=function(t){return t instanceof Buffer},g=c((function(t,n){var r=/%[sdj%]/g;n.format=function(t){if(!m(t)){for(var e=[],n=0;n<arguments.length;n++)e.push(s(arguments[n]));return e.join(" ")}n=1;for(var i=arguments,o=i.length,u=String(t).replace(r,(function(t){if("%%"===t)return"%";if(n>=o)return t;switch(t){case"%s":return String(i[n++]);case"%d":return Number(i[n++]);case"%j":try{return JSON.stringify(i[n++])}catch(t){return"[Circular]"}default:return t}})),c=i[n];n<o;c=i[++n])y(c)||!S(c)?u+=" "+c:u+=" "+s(c);return u},n.deprecate=function(t,e){if(b(u.process))return function(){return n.deprecate(t,e).apply(this,arguments)};if(!0===process.noDeprecation)return t;var r=!1;return function(){if(!r){if(process.throwDeprecation)throw new Error(e);process.traceDeprecation?console.trace(e):console.error(e),r=!0}return t.apply(this,arguments)}};var i,o={};function s(t,e){var r={seen:[],stylize:h};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),g(e)?r.showHidden=e:e&&n._extend(r,e),b(r.showHidden)&&(r.showHidden=!1),b(r.depth)&&(r.depth=2),b(r.colors)&&(r.colors=!1),b(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=c),a(r,t,r.depth)}function c(t,e){var n=s.styles[e];return n?"["+s.colors[n][0]+"m"+t+"["+s.colors[n][1]+"m":t}function h(t,e){return t}function a(t,e,r){if(t.customInspect&&e&&E(e.inspect)&&e.inspect!==n.inspect&&(!e.constructor||e.constructor.prototype!==e)){var i=e.inspect(r,t);return m(i)||(i=a(t,i,r)),i}var o=function(t,e){if(b(e))return t.stylize("undefined","undefined");if(m(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}if(v(e))return t.stylize(""+e,"number");if(g(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,n){e[t]=!0})),e}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(e)),w(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(x(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(_(e))return t.stylize(Date.prototype.toString.call(e),"date");if(w(e))return f(e)}var h,d="",S=!1,j=["{","}"];(p(e)&&(S=!0,j=["[","]"]),E(e))&&(d=" [Function"+(e.name?": "+e.name:"")+"]");return x(e)&&(d=" "+RegExp.prototype.toString.call(e)),_(e)&&(d=" "+Date.prototype.toUTCString.call(e)),w(e)&&(d=" "+f(e)),0!==s.length||S&&0!=e.length?r<0?x(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special"):(t.seen.push(e),h=S?function(t,e,n,r,i){for(var o=[],s=0,u=e.length;s<u;++s)B(e,String(s))?o.push(l(t,e,n,r,String(s),!0)):o.push("");return i.forEach((function(i){i.match(/^\d+$/)||o.push(l(t,e,n,r,i,!0))})),o}(t,e,r,u,s):s.map((function(n){return l(t,e,r,u,n,S)})),t.seen.pop(),function(t,e,n){if(t.reduce((function(t,e){return e.indexOf("\n"),t+e.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60)return n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1];return n[0]+e+" "+t.join(", ")+" "+n[1]}(h,d,j)):j[0]+d+j[1]}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function l(t,e,n,r,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")),B(r,i)||(s="["+i+"]"),u||(t.seen.indexOf(c.value)<0?(u=y(n)?a(t,c.value,null):a(t,c.value,n-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 g(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 x(t){return S(t)&&"[object RegExp]"===j(t)}function S(t){return"object"==typeof t&&null!==t}function _(t){return S(t)&&"[object Date]"===j(t)}function w(t){return S(t)&&("[object Error]"===j(t)||t instanceof Error)}function E(t){return"function"==typeof t}function j(t){return Object.prototype.toString.call(t)}function k(t){return t<10?"0"+t.toString(10):t.toString(10)}n.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 r=n.format.apply(n,arguments);console.error("%s %d: %s",t,e,r)}}else o[t]=function(){};return o[t]},n.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"},n.isArray=p,n.isBoolean=g,n.isNull=y,n.isNullOrUndefined=function(t){return null==t},n.isNumber=v,n.isString=m,n.isSymbol=function(t){return"symbol"==typeof t},n.isUndefined=b,n.isRegExp=x,n.isObject=S,n.isDate=_,n.isError=w,n.isFunction=E,n.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},n.isBuffer=d;var O=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function A(){var t=new Date,e=[k(t.getHours()),k(t.getMinutes()),k(t.getSeconds())].join(":");return[t.getDate(),O[t.getMonth()],e].join(" ")}function B(t,e){return Object.prototype.hasOwnProperty.call(t,e)}n.log=function(){console.log("%s - %s",A(),n.format.apply(n,arguments))},n.inherits=e,n._extend=function(t,e){if(!e||!S(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}})),y=(g.format,g.deprecate,g.debuglog,g.inspect,g.isArray,g.isBoolean,g.isNull,g.isNullOrUndefined,g.isNumber,g.isString,g.isSymbol,g.isUndefined,g.isRegExp,g.isObject,g.isDate,g.isError,g.isFunction,g.isPrimitive,g.isBuffer,g.log,g.inherits,g._extend,c((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 n=t.length,r=e.length,i=0,o=Math.min(n,r);i<o;++i)if(t[i]!==e[i]){n=t[i],r=e[i];break}return n<r?-1:r<n?1:0}function n(t){return u.Buffer&&"function"==typeof u.Buffer.isBuffer?u.Buffer.isBuffer(t):!(null==t||!t._isBuffer)}var r=Object.prototype.hasOwnProperty,i=Array.prototype.slice,o="foo"===function(){}.name;function s(t){return Object.prototype.toString.call(t)}function c(t){return!n(t)&&("function"==typeof u.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(g.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 d(t){if(o||!g.isFunction(t))return g.inspect(t);var e=f(t);return"[Function"+(e?": "+e:"")+"]"}function y(t,e,n,r,i){throw new h.AssertionError({message:n,actual:t,expected:e,operator:r,stackStartFunction:i})}function v(t,e){t||y(t,!0,e,"==",h.ok)}function m(t,r,o,u){if(t===r)return!0;if(n(t)&&n(r))return 0===e(t,r);if(g.isDate(t)&&g.isDate(r))return t.getTime()===r.getTime();if(g.isRegExp(t)&&g.isRegExp(r))return t.source===r.source&&t.global===r.global&&t.multiline===r.multiline&&t.lastIndex===r.lastIndex&&t.ignoreCase===r.ignoreCase;if(null!==t&&"object"==typeof t||null!==r&&"object"==typeof r){if(c(t)&&c(r)&&s(t)===s(r)&&!(t instanceof Float32Array||t instanceof Float64Array))return 0===e(new Uint8Array(t.buffer),new Uint8Array(r.buffer));if(n(t)!==n(r))return!1;var h=(u=u||{actual:[],expected:[]}).actual.indexOf(t);return-1!==h&&h===u.expected.indexOf(r)||(u.actual.push(t),u.expected.push(r),function(t,e,n,r){if(null==t||null==e)return!1;if(g.isPrimitive(t)||g.isPrimitive(e))return t===e;if(n&&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,n);var u,c,h=_(t),a=_(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],n,r))return!1;return!0}(t,r,o,u))}return o?t===r:t==r}function b(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function x(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 S(t,e,n,r){var i;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof n&&(r=n,n=null),i=function(t){var e;try{t()}catch(t){e=t}return e}(e),r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),t&&!i&&y(i,n,"Missing expected exception"+r);var o="string"==typeof r,s=!t&&i&&!n;if((!t&&g.isError(i)&&o&&x(i,n)||s)&&y(i,n,"Got unwanted exception"+r),t&&i&&n&&!x(i,n)||!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(d(t.actual),128)+" "+t.operator+" "+l(d(t.expected),128)}(this),this.generatedMessage=!0);var e=t.stackStartFunction||y;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var n=new Error;if(n.stack){var r=n.stack,i=f(e),o=r.indexOf("\n"+i);if(o>=0){var s=r.indexOf("\n",o+1);r=r.substring(s+1)}this.stack=r}}},g.inherits(h.AssertionError,Error),h.fail=y,h.ok=v,h.equal=function(t,e,n){t!=e&&y(t,e,n,"==",h.equal)},h.notEqual=function(t,e,n){t==e&&y(t,e,n,"!=",h.notEqual)},h.deepEqual=function(t,e,n){m(t,e,!1)||y(t,e,n,"deepEqual",h.deepEqual)},h.deepStrictEqual=function(t,e,n){m(t,e,!0)||y(t,e,n,"deepStrictEqual",h.deepStrictEqual)},h.notDeepEqual=function(t,e,n){m(t,e,!1)&&y(t,e,n,"notDeepEqual",h.notDeepEqual)},h.notDeepStrictEqual=function t(e,n,r){m(e,n,!0)&&y(e,n,r,"notDeepStrictEqual",t)},h.strictEqual=function(t,e,n){t!==e&&y(t,e,n,"===",h.strictEqual)},h.notStrictEqual=function(t,e,n){t===e&&y(t,e,n,"!==",h.notStrictEqual)},h.throws=function(t,e,n){S(!0,t,e,n)},h.doesNotThrow=function(t,e,n){S(!1,t,e,n)},h.ifError=function(t){if(t)throw t},h.strict=p((function t(e,n){e||y(e,!0,n,"==",t)}),h,{equal:h.strictEqual,deepEqual:h.deepStrictEqual,notEqual:h.notStrictEqual,notDeepEqual:h.notDeepStrictEqual}),h.strict.strict=h.strict;var _=Object.keys||function(t){var e=[];for(var n in t)r.call(t,n)&&e.push(n);return e}}))),v=m;function m(t,e){if(!t)throw new Error(e||"Assertion failed")}function b(t,e){return 55296==(64512&t.charCodeAt(e))&&(!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1)))}function x(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function S(t){return 1===t.length?"0"+t:t}function _(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}m.equal=function(t,e,n){if(t!=e)throw new Error(n||"Assertion failed: "+t+" != "+e)};var w={inherits:e,toArray:function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var n=[];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)n.push(parseInt(t[i]+t[i+1],16))}else for(var r=0,i=0;i<t.length;i++){var o=t.charCodeAt(i);o<128?n[r++]=o:o<2048?(n[r++]=o>>6|192,n[r++]=63&o|128):b(t,i)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++i)),n[r++]=o>>18|240,n[r++]=o>>12&63|128,n[r++]=o>>6&63|128,n[r++]=63&o|128):(n[r++]=o>>12|224,n[r++]=o>>6&63|128,n[r++]=63&o|128)}else for(i=0;i<t.length;i++)n[i]=0|t[i];return n},toHex:function(t){for(var e="",n=0;n<t.length;n++)e+=S(t[n].toString(16));return e},htonl:x,toHex32:function(t,e){for(var n="",r=0;r<t.length;r++){var i=t[r];"little"===e&&(i=x(i)),n+=_(i.toString(16))}return n},zero2:S,zero8:_,join32:function(t,e,n,r){var i=n-e;v(i%4==0);for(var o=new Array(i/4),s=0,u=e;s<o.length;s++,u+=4){var c;c="big"===r?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 n=new Array(4*t.length),r=0,i=0;r<t.length;r++,i+=4){var o=t[r];"big"===e?(n[i]=o>>>24,n[i+1]=o>>>16&255,n[i+2]=o>>>8&255,n[i+3]=255&o):(n[i+3]=o>>>24,n[i+2]=o>>>16&255,n[i+1]=o>>>8&255,n[i]=255&o)}return n},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,n){return t+e+n>>>0},sum32_4:function(t,e,n,r){return t+e+n+r>>>0},sum32_5:function(t,e,n,r,i){return t+e+n+r+i>>>0},sum64:function(t,e,n,r){var i=t[e],o=r+t[e+1]>>>0,s=(o<r?1:0)+n+i;t[e]=s>>>0,t[e+1]=o},sum64_hi:function(t,e,n,r){return(e+r>>>0<e?1:0)+t+n>>>0},sum64_lo:function(t,e,n,r){return e+r>>>0},sum64_4_hi:function(t,e,n,r,i,o,s,u){var c=0,h=e;return c+=(h=h+r>>>0)<e?1:0,c+=(h=h+o>>>0)<o?1:0,t+n+i+s+(c+=(h=h+u>>>0)<u?1:0)>>>0},sum64_4_lo:function(t,e,n,r,i,o,s,u){return e+r+o+u>>>0},sum64_5_hi:function(t,e,n,r,i,o,s,u,c,h){var a=0,f=e;return a+=(f=f+r>>>0)<e?1:0,a+=(f=f+o>>>0)<o?1:0,a+=(f=f+u>>>0)<u?1:0,t+n+i+s+c+(a+=(f=f+h>>>0)<h?1:0)>>>0},sum64_5_lo:function(t,e,n,r,i,o,s,u,c,h){return e+r+o+u+h>>>0},rotr64_hi:function(t,e,n){return(e<<32-n|t>>>n)>>>0},rotr64_lo:function(t,e,n){return(t<<32-n|e>>>n)>>>0},shr64_hi:function(t,e,n){return t>>>n},shr64_lo:function(t,e,n){return(t<<32-n|e>>>n)>>>0}};function E(){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 j=E;E.prototype.update=function(t,e){if(t=w.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var n=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-n,t.length),0===this.pending.length&&(this.pending=null),t=w.join32(t,0,t.length-n,this.endian);for(var r=0;r<t.length;r+=this._delta32)this._update(t,r,r+this._delta32)}return this},E.prototype.digest=function(t){return this.update(this._pad()),v(null===this.pending),this._digest(t)},E.prototype._pad=function(){var t=this.pendingTotal,e=this._delta8,n=e-(t+this.padLength)%e,r=new Array(n+this.padLength);r[0]=128;for(var i=1;i<n;i++)r[i]=0;if(t<<=3,"big"===this.endian){for(var o=8;o<this.padLength;o++)r[i++]=0;r[i++]=0,r[i++]=0,r[i++]=0,r[i++]=0,r[i++]=t>>>24&255,r[i++]=t>>>16&255,r[i++]=t>>>8&255,r[i++]=255&t}else for(r[i++]=255&t,r[i++]=t>>>8&255,r[i++]=t>>>16&255,r[i++]=t>>>24&255,r[i++]=0,r[i++]=0,r[i++]=0,r[i++]=0,o=8;o<this.padLength;o++)r[i++]=0;return r};var k={BlockHash:j},O=w.rotr32;function A(t,e,n){return t&e^~t&n}function B(t,e,n){return t&e^t&n^e&n}function z(t,e,n){return t^e^n}var T={ft_1:function(t,e,n,r){return 0===t?A(e,n,r):1===t||3===t?z(e,n,r):2===t?B(e,n,r):void 0},ch32:A,maj32:B,p32:z,s0_256:function(t){return O(t,2)^O(t,13)^O(t,22)},s1_256:function(t){return O(t,6)^O(t,11)^O(t,25)},g0_256:function(t){return O(t,7)^O(t,18)^t>>>3},g1_256:function(t){return O(t,17)^O(t,19)^t>>>10}},H=w.rotl32,q=w.sum32,D=w.sum32_5,N=T.ft_1,P=k.BlockHash,C=[1518500249,1859775393,2400959708,3395469782];function F(){if(!(this instanceof F))return new F;P.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}w.inherits(F,P);var U=F;F.blockSize=512,F.outSize=160,F.hmacStrength=80,F.padLength=64,F.prototype._update=function(t,e){for(var n=this.W,r=0;r<16;r++)n[r]=t[e+r];for(;r<n.length;r++)n[r]=H(n[r-3]^n[r-8]^n[r-14]^n[r-16],1);var i=this.h[0],o=this.h[1],s=this.h[2],u=this.h[3],c=this.h[4];for(r=0;r<n.length;r++){var h=~~(r/20),a=D(H(i,5),N(h,o,s,u),c,n[r],C[h]);c=u,u=s,s=H(o,30),o=i,i=a}this.h[0]=q(this.h[0],i),this.h[1]=q(this.h[1],o),this.h[2]=q(this.h[2],s),this.h[3]=q(this.h[3],u),this.h[4]=q(this.h[4],c)},F.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"big"):w.split32(this.h,"big")};var K=w.sum32,L=w.sum32_4,R=w.sum32_5,I=T.ch32,M=T.maj32,J=T.s0_256,W=T.s1_256,V=T.g0_256,$=T.g1_256,G=k.BlockHash,Z=[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 Q(){if(!(this instanceof Q))return new Q;G.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=Z,this.W=new Array(64)}w.inherits(Q,G);var X=Q;function Y(){if(!(this instanceof Y))return new Y;X.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}Q.blockSize=512,Q.outSize=256,Q.hmacStrength=192,Q.padLength=64,Q.prototype._update=function(t,e){for(var n=this.W,r=0;r<16;r++)n[r]=t[e+r];for(;r<n.length;r++)n[r]=L($(n[r-2]),n[r-7],V(n[r-15]),n[r-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(v(this.k.length===n.length),r=0;r<n.length;r++){var l=R(f,W(c),I(c,h,a),this.k[r],n[r]),p=K(J(i),M(i,o,s));f=a,a=h,h=c,c=K(u,l),u=s,s=o,o=i,i=K(l,p)}this.h[0]=K(this.h[0],i),this.h[1]=K(this.h[1],o),this.h[2]=K(this.h[2],s),this.h[3]=K(this.h[3],u),this.h[4]=K(this.h[4],c),this.h[5]=K(this.h[5],h),this.h[6]=K(this.h[6],a),this.h[7]=K(this.h[7],f)},Q.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"big"):w.split32(this.h,"big")},w.inherits(Y,X);var tt=Y;Y.blockSize=512,Y.outSize=224,Y.hmacStrength=192,Y.padLength=64,Y.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h.slice(0,7),"big"):w.split32(this.h.slice(0,7),"big")};var et=w.rotr64_hi,nt=w.rotr64_lo,rt=w.shr64_hi,it=w.shr64_lo,ot=w.sum64,st=w.sum64_hi,ut=w.sum64_lo,ct=w.sum64_4_hi,ht=w.sum64_4_lo,at=w.sum64_5_hi,ft=w.sum64_5_lo,lt=k.BlockHash,pt=[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 dt(){if(!(this instanceof dt))return new dt;lt.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=pt,this.W=new Array(160)}w.inherits(dt,lt);var gt=dt;function yt(t,e,n,r,i){var o=t&n^~t&i;return o<0&&(o+=4294967296),o}function vt(t,e,n,r,i,o){var s=e&r^~e&o;return s<0&&(s+=4294967296),s}function mt(t,e,n,r,i){var o=t&n^t&i^n&i;return o<0&&(o+=4294967296),o}function bt(t,e,n,r,i,o){var s=e&r^e&o^r&o;return s<0&&(s+=4294967296),s}function xt(t,e){var n=et(t,e,28)^et(e,t,2)^et(e,t,7);return n<0&&(n+=4294967296),n}function St(t,e){var n=nt(t,e,28)^nt(e,t,2)^nt(e,t,7);return n<0&&(n+=4294967296),n}function _t(t,e){var n=et(t,e,14)^et(t,e,18)^et(e,t,9);return n<0&&(n+=4294967296),n}function wt(t,e){var n=nt(t,e,14)^nt(t,e,18)^nt(e,t,9);return n<0&&(n+=4294967296),n}function Et(t,e){var n=et(t,e,1)^et(t,e,8)^rt(t,e,7);return n<0&&(n+=4294967296),n}function jt(t,e){var n=nt(t,e,1)^nt(t,e,8)^it(t,e,7);return n<0&&(n+=4294967296),n}function kt(t,e){var n=et(t,e,19)^et(e,t,29)^rt(t,e,6);return n<0&&(n+=4294967296),n}function Ot(t,e){var n=nt(t,e,19)^nt(e,t,29)^it(t,e,6);return n<0&&(n+=4294967296),n}function At(){if(!(this instanceof At))return new At;gt.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}dt.blockSize=1024,dt.outSize=512,dt.hmacStrength=192,dt.padLength=128,dt.prototype._prepareBlock=function(t,e){for(var n=this.W,r=0;r<32;r++)n[r]=t[e+r];for(;r<n.length;r+=2){var i=kt(n[r-4],n[r-3]),o=Ot(n[r-4],n[r-3]),s=n[r-14],u=n[r-13],c=Et(n[r-30],n[r-29]),h=jt(n[r-30],n[r-29]),a=n[r-32],f=n[r-31];n[r]=ct(i,o,s,u,c,h,a,f),n[r+1]=ht(i,o,s,u,c,h,a,f)}},dt.prototype._update=function(t,e){this._prepareBlock(t,e);var n=this.W,r=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],m=this.h[14],b=this.h[15];v(this.k.length===n.length);for(var x=0;x<n.length;x+=2){var S=m,_=b,w=_t(f,l),E=wt(f,l),j=yt(f,l,p,d,g),k=vt(f,l,p,d,g,y),O=this.k[x],A=this.k[x+1],B=n[x],z=n[x+1],T=at(S,_,w,E,j,k,O,A,B,z),H=ft(S,_,w,E,j,k,O,A,B,z);S=xt(r,i),_=St(r,i),w=mt(r,i,o,s,u),E=bt(r,i,o,s,u,c);var q=st(S,_,w,E),D=ut(S,_,w,E);m=g,b=y,g=p,y=d,p=f,d=l,f=st(h,a,T,H),l=ut(a,a,T,H),h=u,a=c,u=o,c=s,o=r,s=i,r=st(T,H,q,D),i=ut(T,H,q,D)}ot(this.h,0,r,i),ot(this.h,2,o,s),ot(this.h,4,u,c),ot(this.h,6,h,a),ot(this.h,8,f,l),ot(this.h,10,p,d),ot(this.h,12,g,y),ot(this.h,14,m,b)},dt.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"big"):w.split32(this.h,"big")},w.inherits(At,gt);var Bt=At;At.blockSize=1024,At.outSize=384,At.hmacStrength=192,At.padLength=128,At.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h.slice(0,12),"big"):w.split32(this.h.slice(0,12),"big")};var zt={sha1:U,sha224:tt,sha256:X,sha384:Bt,sha512:gt},Tt=w.rotl32,Ht=w.sum32,qt=w.sum32_3,Dt=w.sum32_4,Nt=k.BlockHash;function Pt(){if(!(this instanceof Pt))return new Pt;Nt.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}w.inherits(Pt,Nt);var Ct=Pt;function Ft(t,e,n,r){return t<=15?e^n^r:t<=31?e&n|~e&r:t<=47?(e|~n)^r:t<=63?e&r|n&~r:e^(n|~r)}function Ut(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function Kt(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}Pt.blockSize=512,Pt.outSize=160,Pt.hmacStrength=192,Pt.padLength=64,Pt.prototype._update=function(t,e){for(var n=this.h[0],r=this.h[1],i=this.h[2],o=this.h[3],s=this.h[4],u=n,c=r,h=i,a=o,f=s,l=0;l<80;l++){var p=Ht(Tt(Dt(n,Ft(l,r,i,o),t[Lt[l]+e],Ut(l)),It[l]),s);n=s,s=o,o=Tt(i,10),i=r,r=p,p=Ht(Tt(Dt(u,Ft(79-l,c,h,a),t[Rt[l]+e],Kt(l)),Mt[l]),f),u=f,f=a,a=Tt(h,10),h=c,c=p}p=qt(this.h[1],i,a),this.h[1]=qt(this.h[2],o,f),this.h[2]=qt(this.h[3],s,u),this.h[3]=qt(this.h[4],n,c),this.h[4]=qt(this.h[0],r,h),this.h[0]=p},Pt.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"little"):w.split32(this.h,"little")};var Lt=[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],Rt=[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],It=[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],Mt=[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],Jt={ripemd160:Ct};function Wt(t,e,n){if(!(this instanceof Wt))return new Wt(t,e,n);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(w.toArray(e,n))}var Vt=Wt;Wt.prototype._init=function(t){t.length>this.blockSize&&(t=(new this.Hash).update(t).digest()),v(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)},Wt.prototype.update=function(t,e){return this.inner.update(t,e),this},Wt.prototype.digest=function(t){return this.outer.update(this.inner.digest()),this.outer.digest(t)};var $t=c((function(t,e){var n=e;n.utils=w,n.common=k,n.sha=zt,n.ripemd=Jt,n.hmac=Vt,n.sha1=n.sha.sha1,n.sha256=n.sha.sha256,n.sha224=n.sha.sha224,n.sha384=n.sha.sha384,n.sha512=n.sha.sha512,n.ripemd160=n.ripemd.ripemd160}));class Gt{constructor(){this.hash=$t.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 s(this.first256())}}const Zt=r.ec("secp256k1");function Qt(t,e){const n=Zt.curve.n;for(let r=0;r<=4294967295;r++){const i=(new Gt).add(t);void 0!==e&&i.addU32(e),i.addU32(r);const o=i.first256BN();if(o.cmpn(0)>0&&o.cmp(n)<0)return o}throw new Error("impossible unicorn ;)")}const Xt=r.eddsa("ed25519"),Yt=r.ec("secp256k1");function te(t){return $t.sha512().update(t).digest().slice(0,32)}const ee={deriveKeypair:(t,e={})=>{const n="00"+function(t,e={}){const n=e.validator,r=Zt.curve.n,i=Qt(t);if(n)return i;const o=Zt.g.mul(i),s=e.accountIndex||0;return Qt(o.encodeCompressed(),s).add(i).mod(r)}(t,e).toString(16,64).toUpperCase(),r=o.funcBytesToHex(Yt.keyFromPrivate(n.slice(2)).getPublic().encodeCompressed());return{privateKey:n,publicKey:r}},sign:(t,e)=>o.funcBytesToHex(Yt.sign(te(t),o.funcHexToBytes(e),{canonical:!0}).toDER()),verify:(t,e,n)=>Yt.verify(te(t),e,o.funcHexToBytes(n)),signTx:(t,e)=>o.funcBytesToHex(Yt.sign(t,o.funcHexToBytes(e),{canonical:!0}).toDER()),verifyTx:(t,e,n)=>Yt.verify(t,e,o.funcHexToBytes(n))},ne={deriveKeypair:t=>{const e=te(t);return{privateKey:"ED"+o.funcBytesToHex(e),publicKey:"ED"+o.funcBytesToHex(Xt.keyFromSecret(e).pubBytes())}},sign:(t,e)=>(y(Array.isArray(t),"message must be array of octets"),o.funcBytesToHex(Xt.sign(t,o.funcHexToBytes(e).slice(1)).toBytes())),verify:(t,e,n)=>Xt.verify(t,o.funcHexToBytes(e),o.funcHexToBytes(n).slice(1)),signTx:(t,e)=>Xt.sign(t,o.funcHexToBytes(e).slice(1)).toHex(),verifyTx:(t,e,n)=>Xt.verify(t,o.funcHexToBytes(e),o.funcHexToBytes(n).slice(1))};function re(t){return{"ecdsa-secp256k1":ee,ed25519:ne}[t]}function ie(t){const e=o.funcHexToBytes(t);return 33===e.length&&237===e[0]?"ed25519":"ecdsa-secp256k1"}function oe(t,e){return re(ie(e)).sign(o.funcHexToBytes(t),e)}function se(t,e,n){return re(ie(n)).verify(o.funcHexToBytes(t),e,n)}function ue(t,e){return re(ie(e)).signTx(t,e)}function ce(t,e,n){return re(ie(n)).verifyTx(t,e,n)}function he(t="jingtum"){const e=i.Factory(t);function r(t,n={}){const r=e.decodeSeed(t),i=re("ed25519"===r.type?"ed25519":"ecdsa-secp256k1"),o=i.deriveKeypair(r.bytes,n),s=te("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 e.encodeAccountID(Buffer.from(function(t){const e=$t.sha256().update(t).digest();return $t.ripemd160().update(e).digest()}(t)))}return{addressCodec:e,chain:e.chain,deriveKeyPair:r,hash:te,signTx:ue,verifyTx:ce,convertAddressToBytes:function(t){return e.decodeAddress(t).toJSON().data},convertBytesToAddress:function(t){return e.encodeAddress(t)},checkAddress:e.isValidAddress,isValidAddress:e.isValidAddress,deriveKeypair:r,generateSeed:function(t={}){y(!t.entropy||t.entropy.length>=16,"entropy too short");const r=t.entropy?t.entropy.slice(0,16):n(16),i="ed25519"===t.algorithm?"ed25519":"secp256k1";return e.encodeSeed(r,i)},sign:oe,verify:se,deriveAddress:function(t){return s(o.funcHexToBytes(t))},deriveNodeAddress:function(t){return s(function(t){const e=Zt.curve.decodePoint(t),n=Qt(t,0),r=Zt.g.mul(n);return e.add(r).encodeCompressed()}(e.decodeNodePublic(t)))}}}const ae=he();exports.Factory=he,exports.Keypairs=ae;