This repository has been archived by the owner on Feb 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
metahash.js
185 lines (169 loc) · 113 KB
/
metahash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
class MetaHash {
constructor() {
this.apiUrl = 'http://172.104.157.248:5795';
this.tokenPrefix = 'MHC';
}
request(method, callback, params) {
const query = {
//id: 1,
method: method,
params: params
};
fetch(this.apiUrl, {
method: 'POST',
body: JSON.stringify(query)
})
.then((response) => { return response.json(); })
.then((data) => {
if ( ! data.error) {
if ( ! data.params) data = data.result;
callback(data);
}
else callback(null, data.error);
});
}
balanceFormatter(value) {
return (value / 1000000).toFixed(6) + (this.tokenPrefix ? ' ' + this.tokenPrefix : '');
}
fetchBalance(address, callback) {
this.request('fetch-balance', (res, err) => {
if (res) {
res.balance = this.balanceFormatter(res.received - res.spent);
res.transaction_count = res.count_received + res.count_spent;
}
callback(res, err);
}, {
address
});
}
fetchHistory(address, callback) {
this.request('fetch-history', (res, err) => {
if (res) {
res = res.reverse();
// for is for best perfomance
for (let i = 0; i < res.length; i++) {
res[i].value = this.balanceFormatter(res[i].value);
}
}
callback(res, err);
}, {
address
});
}
getTx(hash, callback) {
this.request('get-tx', (res, err) => {
if (res) {
res = res.transaction;
res.value = this.balanceFormatter(res.value);
}
callback(res, err);
}, {
hash
});
}
intToHexHandler(firstFormat, firstValue, secondFormat, SecondValue) {
return this.binToHex(pack(firstFormat, firstValue)) + (secondFormat ? this.binToHex(pack(secondFormat, SecondValue)) : '');
}
intToHex(value) {
if (value < 250) return this.intToHexHandler('C', value);
else if (value < 65536) return this.intToHexHandler('C', 250, 'v', value);
else if (value < 4294967296) return this.intToHexHandler('C', 251, 'V', value);
else return this.intToHexHandler('C', 252, '@', value);
}
strToHex(value) {
let str = '';
for (let i = 0 ; i < value.length ; i++ ) {
if (value.charCodeAt(i) < 256) str += '\\x' + value.charCodeAt(i).toString(16) + '';
else if (value.charCodeAt(i) < 4096) str += '\\u0' + value.charCodeAt(i).toString(16) + '';
else str += '\\u' + value.charCodeAt(i).toString(16) + '';
}
return str;
}
binToHex(value) {
let i, l, o = '', n;
value += '';
for (i = 0, l = value.length; i < l; i++) {
n = value.charCodeAt(i).toString(16);
o += n.length < 2 ? '0' + n : n;
}
return o;
}
base64toHex(base64) {
let raw = atob(base64);
let hex = '';
for (let i = 0; i < raw.length; i++ ) {
let _hex = raw.charCodeAt(i).toString(16);
hex += (_hex.length==2?_hex:'0'+_hex);
}
return hex;
}
createTx(to, value, fee, nonce, data, pubkey, privateKey, youHashAddress, callback) {
value = value.toString();
fee = fee.toString();
// need refactoring!
if ( ! nonce) {
this.apiUrl = 'http://172.104.224.65:5795';
const address = youHashAddress;
this.fetchBalance(address, (res, err) => {
this.apiUrl = 'http://139.162.42.43:9999';
res.count_spent++;
this.createTxHandler(to, value, fee, res.count_spent, data, pubkey, privateKey, callback)
});
}
else this.createTxHandler(to, value, fee, nonce, data, pubkey, privateKey, callback);
}
createTxHandler(to, value, fee, nonce, data, pubkey, privateKey, callback) {
nonce = nonce.toString();
const message = to.substr(2) + this.intToHex(value) + this.intToHex(fee) + this.intToHex(nonce) + '00';
const sig = new KJUR.crypto.Signature({'alg': 'SHA256withECDSA'});
sig.init({d: privateKey, curve: 'secp256k1'});
sig.updateHex(message);
const sign = sig.sign();
this.request('mhc_send', (res, err) => {
callback(res, err);
}, {
to,
value,
fee,
nonce,
data,
pubkey,
sign
});
}
}
const metahash = new MetaHash();
// Copyright (c) 2011, Yahoo! Inc. All rights reserved.
if(void 0===YAHOO)var YAHOO={};YAHOO.lang={extend:function(t,o,e){if(!o||!t)throw new Error("YAHOO.lang.extend failed, please check that all dependencies are included.");var r=function(){};if(r.prototype=o.prototype,t.prototype=new r,t.prototype.constructor=t,t.superclass=o.prototype,o.prototype.constructor==Object.prototype.constructor&&(o.prototype.constructor=o),e){var n;for(n in e)t.prototype[n]=e[n];var p=function(){},c=["toString","valueOf"];try{/MSIE/.test(navigator.userAgent)&&(p=function(t,o){for(n=0;n<c.length;n+=1){var e=c[n],r=o[e];"function"==typeof r&&r!=Object.prototype[e]&&(t[e]=r)}})}catch(t){}p(t.prototype,e)}}};
// CryptoJS v3.1.2 core-fix.js
var CryptoJS=CryptoJS||function(t,n){var i={},r=i.lib={},e=r.Base=function(){function t(){}return{extend:function(n){t.prototype=this;var i=new t;return n&&i.mixIn(n),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),s=r.WordArray=e.extend({init:function(t,n){t=this.words=t||[],this.sigBytes=void 0!=n?n:4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var n=this.words,i=t.words,r=this.sigBytes,e=t.sigBytes;if(this.clamp(),r%4)for(var s=0;s<e;s++){var o=i[s>>>2]>>>24-s%4*8&255;n[r+s>>>2]|=o<<24-(r+s)%4*8}else for(s=0;s<e;s+=4)n[r+s>>>2]=i[s>>>2];return this.sigBytes+=e,this},clamp:function(){var n=this.words,i=this.sigBytes;n[i>>>2]&=4294967295<<32-i%4*8,n.length=t.ceil(i/4)},clone:function(){var t=e.clone.call(this);return t.words=this.words.slice(0),t},random:function(n){for(var i=[],r=0;r<n;r+=4)i.push(4294967296*t.random()|0);return new s.init(i,n)}}),o=i.enc={},a=o.Hex={stringify:function(t){for(var n=t.words,i=t.sigBytes,r=[],e=0;e<i;e++){var s=n[e>>>2]>>>24-e%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")},parse:function(t){for(var n=t.length,i=[],r=0;r<n;r+=2)i[r>>>3]|=parseInt(t.substr(r,2),16)<<24-r%8*4;return new s.init(i,n/2)}},c=o.Latin1={stringify:function(t){for(var n=t.words,i=t.sigBytes,r=[],e=0;e<i;e++){var s=n[e>>>2]>>>24-e%4*8&255;r.push(String.fromCharCode(s))}return r.join("")},parse:function(t){for(var n=t.length,i=[],r=0;r<n;r++)i[r>>>2]|=(255&t.charCodeAt(r))<<24-r%4*8;return new s.init(i,n)}},u=o.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},f=r.BufferedBlockAlgorithm=e.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(n){var i=this._data,r=i.words,e=i.sigBytes,o=this.blockSize,a=e/(4*o),c=(a=n?t.ceil(a):t.max((0|a)-this._minBufferSize,0))*o,u=t.min(4*c,e);if(c){for(var f=0;f<c;f+=o)this._doProcessBlock(r,f);var h=r.splice(0,c);i.sigBytes-=u}return new s.init(h,u)},clone:function(){var t=e.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0}),h=(r.Hasher=f.extend({cfg:e.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize()},blockSize:16,_createHelper:function(t){return function(n,i){return new t.init(i).finalize(n)}},_createHmacHelper:function(t){return function(n,i){return new h.HMAC.init(t,i).finalize(n)}}}),i.algo={});return i}(Math);
// (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/
var dbits,canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);function BigInteger(t,i,r){null!=t&&("number"==typeof t?this.fromNumber(t,i,r):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function nbi(){return new BigInteger(null)}function am1(t,i,r,o,n,e){for(;--e>=0;){var s=i*this[t++]+r[o]+n;n=Math.floor(s/67108864),r[o++]=67108863&s}return n}function am2(t,i,r,o,n,e){for(var s=32767&i,h=i>>15;--e>=0;){var p=32767&this[t],a=this[t++]>>15,f=h*p+a*s;n=((p=s*p+((32767&f)<<15)+r[o]+(1073741823&n))>>>30)+(f>>>15)+h*a+(n>>>30),r[o++]=1073741823&p}return n}function am3(t,i,r,o,n,e){for(var s=16383&i,h=i>>14;--e>=0;){var p=16383&this[t],a=this[t++]>>14,f=h*p+a*s;n=((p=s*p+((16383&f)<<14)+r[o]+n)>>28)+(f>>14)+h*a,r[o++]=268435455&p}return n}j_lm&&"Microsoft Internet Explorer"==navigator.appName?(BigInteger.prototype.am=am2,dbits=30):j_lm&&"Netscape"!=navigator.appName?(BigInteger.prototype.am=am1,dbits=26):(BigInteger.prototype.am=am3,dbits=28),BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<<dbits)-1,BigInteger.prototype.DV=1<<dbits;var BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP),BigInteger.prototype.F1=BI_FP-dbits,BigInteger.prototype.F2=2*dbits-BI_FP;var rr,vv,BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(t){return BI_RM.charAt(t)}function intAt(t,i){var r=BI_RC[t.charCodeAt(i)];return null==r?-1:r}function bnpCopyTo(t){for(var i=this.t-1;i>=0;--i)t[i]=this[i];t.t=this.t,t.s=this.s}function bnpFromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}function nbv(t){var i=nbi();return i.fromInt(t),i}function bnpFromString(t,i){var r;if(16==i)r=4;else if(8==i)r=3;else if(256==i)r=8;else if(2==i)r=1;else if(32==i)r=5;else{if(4!=i)return void this.fromRadix(t,i);r=2}this.t=0,this.s=0;for(var o=t.length,n=!1,e=0;--o>=0;){var s=8==r?255&t[o]:intAt(t,o);s<0?"-"==t.charAt(o)&&(n=!0):(n=!1,0==e?this[this.t++]=s:e+r>this.DB?(this[this.t-1]|=(s&(1<<this.DB-e)-1)<<e,this[this.t++]=s>>this.DB-e):this[this.t-1]|=s<<e,(e+=r)>=this.DB&&(e-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,e>0&&(this[this.t-1]|=(1<<this.DB-e)-1<<e)),this.clamp(),n&&BigInteger.ZERO.subTo(this,this)}function bnpClamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function bnToString(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var r,o=(1<<i)-1,n=!1,e="",s=this.t,h=this.DB-s*this.DB%i;if(s-- >0)for(h<this.DB&&(r=this[s]>>h)>0&&(n=!0,e=int2char(r));s>=0;)h<i?(r=(this[s]&(1<<h)-1)<<i-h,r|=this[--s]>>(h+=this.DB-i)):(r=this[s]>>(h-=i)&o,h<=0&&(h+=this.DB,--s)),r>0&&(n=!0),n&&(e+=int2char(r));return n?e:"0"}function bnNegate(){var t=nbi();return BigInteger.ZERO.subTo(this,t),t}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(t){var i=this.s-t.s;if(0!=i)return i;var r=this.t;if(0!=(i=r-t.t))return this.s<0?-i:i;for(;--r>=0;)if(0!=(i=this[r]-t[r]))return i;return 0}function nbits(t){var i,r=1;return 0!=(i=t>>>16)&&(t=i,r+=16),0!=(i=t>>8)&&(t=i,r+=8),0!=(i=t>>4)&&(t=i,r+=4),0!=(i=t>>2)&&(t=i,r+=2),0!=(i=t>>1)&&(t=i,r+=1),r}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(t,i){var r;for(r=this.t-1;r>=0;--r)i[r+t]=this[r];for(r=t-1;r>=0;--r)i[r]=0;i.t=this.t+t,i.s=this.s}function bnpDRShiftTo(t,i){for(var r=t;r<this.t;++r)i[r-t]=this[r];i.t=Math.max(this.t-t,0),i.s=this.s}function bnpLShiftTo(t,i){var r,o=t%this.DB,n=this.DB-o,e=(1<<n)-1,s=Math.floor(t/this.DB),h=this.s<<o&this.DM;for(r=this.t-1;r>=0;--r)i[r+s+1]=this[r]>>n|h,h=(this[r]&e)<<o;for(r=s-1;r>=0;--r)i[r]=0;i[s]=h,i.t=this.t+s+1,i.s=this.s,i.clamp()}function bnpRShiftTo(t,i){i.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)i.t=0;else{var o=t%this.DB,n=this.DB-o,e=(1<<o)-1;i[0]=this[r]>>o;for(var s=r+1;s<this.t;++s)i[s-r-1]|=(this[s]&e)<<n,i[s-r]=this[s]>>o;o>0&&(i[this.t-r-1]|=(this.s&e)<<n),i.t=this.t-r,i.clamp()}}function bnpSubTo(t,i){for(var r=0,o=0,n=Math.min(t.t,this.t);r<n;)o+=this[r]-t[r],i[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o-=t.s;r<this.t;)o+=this[r],i[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o-=t[r],i[r++]=o&this.DM,o>>=this.DB;o-=t.s}i.s=o<0?-1:0,o<-1?i[r++]=this.DV+o:o>0&&(i[r++]=o),i.t=r,i.clamp()}function bnpMultiplyTo(t,i){var r=this.abs(),o=t.abs(),n=r.t;for(i.t=n+o.t;--n>=0;)i[n]=0;for(n=0;n<o.t;++n)i[n+r.t]=r.am(0,o[n],i,n,0,r.t);i.s=0,i.clamp(),this.s!=t.s&&BigInteger.ZERO.subTo(i,i)}function bnpSquareTo(t){for(var i=this.abs(),r=t.t=2*i.t;--r>=0;)t[r]=0;for(r=0;r<i.t-1;++r){var o=i.am(r,i[r],t,2*r,0,1);(t[r+i.t]+=i.am(r+1,2*i[r],t,2*r+1,o,i.t-r-1))>=i.DV&&(t[r+i.t]-=i.DV,t[r+i.t+1]=1)}t.t>0&&(t[t.t-1]+=i.am(r,i[r],t,2*r,0,1)),t.s=0,t.clamp()}function bnpDivRemTo(t,i,r){var o=t.abs();if(!(o.t<=0)){var n=this.abs();if(n.t<o.t)return null!=i&&i.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=nbi());var e=nbi(),s=this.s,h=t.s,p=this.DB-nbits(o[o.t-1]);p>0?(o.lShiftTo(p,e),n.lShiftTo(p,r)):(o.copyTo(e),n.copyTo(r));var a=e.t,f=e[a-1];if(0!=f){var u=f*(1<<this.F1)+(a>1?e[a-2]>>this.F2:0),g=this.FV/u,m=(1<<this.F1)/u,c=1<<this.F2,v=r.t,b=v-a,l=null==i?nbi():i;for(e.dlShiftTo(b,l),r.compareTo(l)>=0&&(r[r.t++]=1,r.subTo(l,r)),BigInteger.ONE.dlShiftTo(a,l),l.subTo(e,e);e.t<a;)e[e.t++]=0;for(;--b>=0;){var T=r[--v]==f?this.DM:Math.floor(r[v]*g+(r[v-1]+c)*m);if((r[v]+=e.am(0,T,r,b,0,a))<T)for(e.dlShiftTo(b,l),r.subTo(l,r);r[v]<--T;)r.subTo(l,r)}null!=i&&(r.drShiftTo(a,i),s!=h&&BigInteger.ZERO.subTo(i,i)),r.t=a,r.clamp(),p>0&&r.rShiftTo(p,r),s<0&&BigInteger.ZERO.subTo(r,r)}}}function bnMod(t){var i=nbi();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(BigInteger.ZERO)>0&&t.subTo(i,i),i}function Classic(t){this.m=t}function cConvert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function cRevert(t){return t}function cReduce(t){t.divRemTo(this.m,null,t)}function cMulTo(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function cSqrTo(t,i){t.squareTo(i),this.reduce(i)}function bnpInvDigit(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var i=3&t;return(i=(i=(i=(i=i*(2-(15&t)*i)&15)*(2-(255&t)*i)&255)*(2-((65535&t)*i&65535))&65535)*(2-t*i%this.DV)%this.DV)>0?this.DV-i:-i}function Montgomery(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function montConvert(t){var i=nbi();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(BigInteger.ZERO)>0&&this.m.subTo(i,i),i}function montRevert(t){var i=nbi();return t.copyTo(i),this.reduce(i),i}function montReduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var i=0;i<this.m.t;++i){var r=32767&t[i],o=r*this.mpl+((r*this.mph+(t[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[r=i+this.m.t]+=this.m.am(0,o,t,i,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function montSqrTo(t,i){t.squareTo(i),this.reduce(i)}function montMulTo(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(t,i){if(t>4294967295||t<1)return BigInteger.ONE;var r=nbi(),o=nbi(),n=i.convert(this),e=nbits(t)-1;for(n.copyTo(r);--e>=0;)if(i.sqrTo(r,o),(t&1<<e)>0)i.mulTo(o,n,r);else{var s=r;r=o,o=s}return i.revert(r)}function bnModPowInt(t,i){var r;return r=t<256||i.isEven()?new Classic(i):new Montgomery(i),this.exp(t,r)}Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,BigInteger.prototype.copyTo=bnpCopyTo,BigInteger.prototype.fromInt=bnpFromInt,BigInteger.prototype.fromString=bnpFromString,BigInteger.prototype.clamp=bnpClamp,BigInteger.prototype.dlShiftTo=bnpDLShiftTo,BigInteger.prototype.drShiftTo=bnpDRShiftTo,BigInteger.prototype.lShiftTo=bnpLShiftTo,BigInteger.prototype.rShiftTo=bnpRShiftTo,BigInteger.prototype.subTo=bnpSubTo,BigInteger.prototype.multiplyTo=bnpMultiplyTo,BigInteger.prototype.squareTo=bnpSquareTo,BigInteger.prototype.divRemTo=bnpDivRemTo,BigInteger.prototype.invDigit=bnpInvDigit,BigInteger.prototype.isEven=bnpIsEven,BigInteger.prototype.exp=bnpExp,BigInteger.prototype.toString=bnToString,BigInteger.prototype.negate=bnNegate,BigInteger.prototype.abs=bnAbs,BigInteger.prototype.compareTo=bnCompareTo,BigInteger.prototype.bitLength=bnBitLength,BigInteger.prototype.mod=bnMod,BigInteger.prototype.modPowInt=bnModPowInt,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1);
// (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/
function bnClone(){var t=nbi();return this.copyTo(t),t}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var i=this.chunkSize(t),r=Math.pow(t,i),e=nbv(r),n=nbi(),o=nbi(),s="";for(this.divRemTo(e,n,o);n.signum()>0;)s=(r+o.intValue()).toString(t).substr(1)+s,n.divRemTo(e,n,o);return o.intValue().toString(t)+s}function bnpFromRadix(t,i){this.fromInt(0),null==i&&(i=10);for(var r=this.chunkSize(i),e=Math.pow(i,r),n=!1,o=0,s=0,h=0;h<t.length;++h){var u=intAt(t,h);u<0?"-"==t.charAt(h)&&0==this.signum()&&(n=!0):(s=i*s+u,++o>=r&&(this.dMultiply(e),this.dAddOffset(s,0),o=0,s=0))}o>0&&(this.dMultiply(Math.pow(i,o)),this.dAddOffset(s,0)),n&&BigInteger.ZERO.subTo(this,this)}function bnpFromNumber(t,i,r){if("number"==typeof i)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(t-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(BigInteger.ONE.shiftLeft(t-1),this);else{var e=new Array,n=7&t;e.length=1+(t>>3),i.nextBytes(e),n>0?e[0]&=(1<<n)-1:e[0]=0,this.fromString(e,256)}}function bnToByteArray(){var t=this.t,i=new Array;i[0]=this.s;var r,e=this.DB-t*this.DB%8,n=0;if(t-- >0)for(e<this.DB&&(r=this[t]>>e)!=(this.s&this.DM)>>e&&(i[n++]=r|this.s<<this.DB-e);t>=0;)e<8?(r=(this[t]&(1<<e)-1)<<8-e,r|=this[--t]>>(e+=this.DB-8)):(r=this[t]>>(e-=8)&255,e<=0&&(e+=this.DB,--t)),0!=(128&r)&&(r|=-256),0==n&&(128&this.s)!=(128&r)&&++n,(n>0||r!=this.s)&&(i[n++]=r);return i}function bnEquals(t){return 0==this.compareTo(t)}function bnMin(t){return this.compareTo(t)<0?this:t}function bnMax(t){return this.compareTo(t)>0?this:t}function bnpBitwiseTo(t,i,r){var e,n,o=Math.min(t.t,this.t);for(e=0;e<o;++e)r[e]=i(this[e],t[e]);if(t.t<this.t){for(n=t.s&this.DM,e=o;e<this.t;++e)r[e]=i(this[e],n);r.t=this.t}else{for(n=this.s&this.DM,e=o;e<t.t;++e)r[e]=i(n,t[e]);r.t=t.t}r.s=i(this.s,t.s),r.clamp()}function op_and(t,i){return t&i}function bnAnd(t){var i=nbi();return this.bitwiseTo(t,op_and,i),i}function op_or(t,i){return t|i}function bnOr(t){var i=nbi();return this.bitwiseTo(t,op_or,i),i}function op_xor(t,i){return t^i}function bnXor(t){var i=nbi();return this.bitwiseTo(t,op_xor,i),i}function op_andnot(t,i){return t&~i}function bnAndNot(t){var i=nbi();return this.bitwiseTo(t,op_andnot,i),i}function bnNot(){for(var t=nbi(),i=0;i<this.t;++i)t[i]=this.DM&~this[i];return t.t=this.t,t.s=~this.s,t}function bnShiftLeft(t){var i=nbi();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i}function bnShiftRight(t){var i=nbi();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i}function lbit(t){if(0==t)return-1;var i=0;return 0==(65535&t)&&(t>>=16,i+=16),0==(255&t)&&(t>>=8,i+=8),0==(15&t)&&(t>>=4,i+=4),0==(3&t)&&(t>>=2,i+=2),0==(1&t)&&++i,i}function bnGetLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+lbit(this[t]);return this.s<0?this.t*this.DB:-1}function cbit(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function bnBitCount(){for(var t=0,i=this.s&this.DM,r=0;r<this.t;++r)t+=cbit(this[r]^i);return t}function bnTestBit(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:0!=(this[i]&1<<t%this.DB)}function bnpChangeBit(t,i){var r=BigInteger.ONE.shiftLeft(t);return this.bitwiseTo(r,i,r),r}function bnSetBit(t){return this.changeBit(t,op_or)}function bnClearBit(t){return this.changeBit(t,op_andnot)}function bnFlipBit(t){return this.changeBit(t,op_xor)}function bnpAddTo(t,i){for(var r=0,e=0,n=Math.min(t.t,this.t);r<n;)e+=this[r]+t[r],i[r++]=e&this.DM,e>>=this.DB;if(t.t<this.t){for(e+=t.s;r<this.t;)e+=this[r],i[r++]=e&this.DM,e>>=this.DB;e+=this.s}else{for(e+=this.s;r<t.t;)e+=t[r],i[r++]=e&this.DM,e>>=this.DB;e+=t.s}i.s=e<0?-1:0,e>0?i[r++]=e:e<-1&&(i[r++]=this.DV+e),i.t=r,i.clamp()}function bnAdd(t){var i=nbi();return this.addTo(t,i),i}function bnSubtract(t){var i=nbi();return this.subTo(t,i),i}function bnMultiply(t){var i=nbi();return this.multiplyTo(t,i),i}function bnSquare(){var t=nbi();return this.squareTo(t),t}function bnDivide(t){var i=nbi();return this.divRemTo(t,i,null),i}function bnRemainder(t){var i=nbi();return this.divRemTo(t,null,i),i}function bnDivideAndRemainder(t){var i=nbi(),r=nbi();return this.divRemTo(t,i,r),new Array(i,r)}function bnpDMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(t,i){if(0!=t){for(;this.t<=i;)this[this.t++]=0;for(this[i]+=t;this[i]>=this.DV;)this[i]-=this.DV,++i>=this.t&&(this[this.t++]=0),++this[i]}}function NullExp(){}function nNop(t){return t}function nMulTo(t,i,r){t.multiplyTo(i,r)}function nSqrTo(t,i){t.squareTo(i)}function bnPow(t){return this.exp(t,new NullExp)}function bnpMultiplyLowerTo(t,i,r){var e,n=Math.min(this.t+t.t,i);for(r.s=0,r.t=n;n>0;)r[--n]=0;for(e=r.t-this.t;n<e;++n)r[n+this.t]=this.am(0,t[n],r,n,0,this.t);for(e=Math.min(t.t,i);n<e;++n)this.am(0,t[n],r,n,0,i-n);r.clamp()}function bnpMultiplyUpperTo(t,i,r){--i;var e=r.t=this.t+t.t-i;for(r.s=0;--e>=0;)r[e]=0;for(e=Math.max(i-this.t,0);e<t.t;++e)r[this.t+e-i]=this.am(i-e,t[e],r,0,0,this.t+e-i);r.clamp(),r.drShiftTo(1,r)}function Barrett(t){this.r2=nbi(),this.q3=nbi(),BigInteger.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function barrettConvert(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var i=nbi();return t.copyTo(i),this.reduce(i),i}function barrettRevert(t){return t}function barrettReduce(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)}function barrettSqrTo(t,i){t.squareTo(i),this.reduce(i)}function barrettMulTo(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function bnModPow(t,i){var r,e,n=t.bitLength(),o=nbv(1);if(n<=0)return o;r=n<18?1:n<48?3:n<144?4:n<768?5:6,e=n<8?new Classic(i):i.isEven()?new Barrett(i):new Montgomery(i);var s=new Array,h=3,u=r-1,p=(1<<r)-1;if(s[1]=e.convert(this),r>1){var f=nbi();for(e.sqrTo(s[1],f);h<=p;)s[h]=nbi(),e.mulTo(f,s[h-2],s[h]),h+=2}var a,b,g=t.t-1,l=!0,m=nbi();for(n=nbits(t[g])-1;g>=0;){for(n>=u?a=t[g]>>n-u&p:(a=(t[g]&(1<<n+1)-1)<<u-n,g>0&&(a|=t[g-1]>>this.DB+n-u)),h=r;0==(1&a);)a>>=1,--h;if((n-=h)<0&&(n+=this.DB,--g),l)s[a].copyTo(o),l=!1;else{for(;h>1;)e.sqrTo(o,m),e.sqrTo(m,o),h-=2;h>0?e.sqrTo(o,m):(b=o,o=m,m=b),e.mulTo(m,s[a],o)}for(;g>=0&&0==(t[g]&1<<n);)e.sqrTo(o,m),b=o,o=m,m=b,--n<0&&(n=this.DB-1,--g)}return e.revert(o)}function bnGCD(t){var i=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(i.compareTo(r)<0){var e=i;i=r,r=e}var n=i.getLowestSetBit(),o=r.getLowestSetBit();if(o<0)return i;for(n<o&&(o=n),o>0&&(i.rShiftTo(o,i),r.rShiftTo(o,r));i.signum()>0;)(n=i.getLowestSetBit())>0&&i.rShiftTo(n,i),(n=r.getLowestSetBit())>0&&r.rShiftTo(n,r),i.compareTo(r)>=0?(i.subTo(r,i),i.rShiftTo(1,i)):(r.subTo(i,r),r.rShiftTo(1,r));return o>0&&r.lShiftTo(o,r),r}function bnpModInt(t){if(t<=0)return 0;var i=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==i)r=this[0]%t;else for(var e=this.t-1;e>=0;--e)r=(i*r+this[e])%t;return r}function bnModInverse(t){var i=t.isEven();if(this.isEven()&&i||0==t.signum())return BigInteger.ZERO;for(var r=t.clone(),e=this.clone(),n=nbv(1),o=nbv(0),s=nbv(0),h=nbv(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),i?(n.isEven()&&o.isEven()||(n.addTo(this,n),o.subTo(t,o)),n.rShiftTo(1,n)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;e.isEven();)e.rShiftTo(1,e),i?(s.isEven()&&h.isEven()||(s.addTo(this,s),h.subTo(t,h)),s.rShiftTo(1,s)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);r.compareTo(e)>=0?(r.subTo(e,r),i&&n.subTo(s,n),o.subTo(h,o)):(e.subTo(r,e),i&&s.subTo(n,s),h.subTo(o,h))}return 0!=e.compareTo(BigInteger.ONE)?BigInteger.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h}NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo;var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],lplim=(1<<26)/lowprimes[lowprimes.length-1];function bnIsProbablePrime(t){var i,r=this.abs();if(1==r.t&&r[0]<=lowprimes[lowprimes.length-1]){for(i=0;i<lowprimes.length;++i)if(r[0]==lowprimes[i])return!0;return!1}if(r.isEven())return!1;for(i=1;i<lowprimes.length;){for(var e=lowprimes[i],n=i+1;n<lowprimes.length&&e<lplim;)e*=lowprimes[n++];for(e=r.modInt(e);i<n;)if(e%lowprimes[i++]==0)return!1}return r.millerRabin(t)}function bnpMillerRabin(t){var i=this.subtract(BigInteger.ONE),r=i.getLowestSetBit();if(r<=0)return!1;var e=i.shiftRight(r);(t=t+1>>1)>lowprimes.length&&(t=lowprimes.length);for(var n=nbi(),o=0;o<t;++o){n.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var s=n.modPow(e,this);if(0!=s.compareTo(BigInteger.ONE)&&0!=s.compareTo(i)){for(var h=1;h++<r&&0!=s.compareTo(i);)if(0==(s=s.modPowInt(2,this)).compareTo(BigInteger.ONE))return!1;if(0!=s.compareTo(i))return!1}}return!0}BigInteger.prototype.chunkSize=bnpChunkSize,BigInteger.prototype.toRadix=bnpToRadix,BigInteger.prototype.fromRadix=bnpFromRadix,BigInteger.prototype.fromNumber=bnpFromNumber,BigInteger.prototype.bitwiseTo=bnpBitwiseTo,BigInteger.prototype.changeBit=bnpChangeBit,BigInteger.prototype.addTo=bnpAddTo,BigInteger.prototype.dMultiply=bnpDMultiply,BigInteger.prototype.dAddOffset=bnpDAddOffset,BigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo,BigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo,BigInteger.prototype.modInt=bnpModInt,BigInteger.prototype.millerRabin=bnpMillerRabin,BigInteger.prototype.clone=bnClone,BigInteger.prototype.intValue=bnIntValue,BigInteger.prototype.byteValue=bnByteValue,BigInteger.prototype.shortValue=bnShortValue,BigInteger.prototype.signum=bnSigNum,BigInteger.prototype.toByteArray=bnToByteArray,BigInteger.prototype.equals=bnEquals,BigInteger.prototype.min=bnMin,BigInteger.prototype.max=bnMax,BigInteger.prototype.and=bnAnd,BigInteger.prototype.or=bnOr,BigInteger.prototype.xor=bnXor,BigInteger.prototype.andNot=bnAndNot,BigInteger.prototype.not=bnNot,BigInteger.prototype.shiftLeft=bnShiftLeft,BigInteger.prototype.shiftRight=bnShiftRight,BigInteger.prototype.getLowestSetBit=bnGetLowestSetBit,BigInteger.prototype.bitCount=bnBitCount,BigInteger.prototype.testBit=bnTestBit,BigInteger.prototype.setBit=bnSetBit,BigInteger.prototype.clearBit=bnClearBit,BigInteger.prototype.flipBit=bnFlipBit,BigInteger.prototype.add=bnAdd,BigInteger.prototype.subtract=bnSubtract,BigInteger.prototype.multiply=bnMultiply,BigInteger.prototype.divide=bnDivide,BigInteger.prototype.remainder=bnRemainder,BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder,BigInteger.prototype.modPow=bnModPow,BigInteger.prototype.modInverse=bnModInverse,BigInteger.prototype.pow=bnPow,BigInteger.prototype.gcd=bnGCD,BigInteger.prototype.isProbablePrime=bnIsProbablePrime,BigInteger.prototype.square=bnSquare;
// (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/
function ECFieldElementFp(t,e){this.x=e,this.q=t}function feFpEquals(t){return t==this||this.q.equals(t.q)&&this.x.equals(t.x)}function feFpToBigInteger(){return this.x}function feFpNegate(){return new ECFieldElementFp(this.q,this.x.negate().mod(this.q))}function feFpAdd(t){return new ECFieldElementFp(this.q,this.x.add(t.toBigInteger()).mod(this.q))}function feFpSubtract(t){return new ECFieldElementFp(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}function feFpMultiply(t){return new ECFieldElementFp(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}function feFpSquare(){return new ECFieldElementFp(this.q,this.x.square().mod(this.q))}function feFpDivide(t){return new ECFieldElementFp(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}function ECPointFp(t,e,i,n){this.curve=t,this.x=e,this.y=i,this.z=null==n?BigInteger.ONE:n,this.zinv=null}function pointFpGetX(){return null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpGetY(){return null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpEquals(t){return t==this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO))}function pointFpIsInfinity(){return null==this.x&&null==this.y||this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)}function pointFpNegate(){return new ECPointFp(this.curve,this.x,this.y.negate(),this.z)}function pointFpAdd(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q),i=t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(i))return BigInteger.ZERO.equals(e)?this.twice():this.curve.getInfinity();var n=new BigInteger("3"),r=this.x.toBigInteger(),u=this.y.toBigInteger(),s=(t.x.toBigInteger(),t.y.toBigInteger(),i.square()),p=s.multiply(i),o=r.multiply(s),l=e.square().multiply(this.z),h=l.subtract(o.shiftLeft(1)).multiply(t.z).subtract(p).multiply(i).mod(this.curve.q),g=o.multiply(n).multiply(e).subtract(u.multiply(p)).subtract(l.multiply(e)).multiply(t.z).add(e.multiply(p)).mod(this.curve.q),F=p.multiply(this.z).multiply(t.z).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(h),this.curve.fromBigInteger(g),F)}function pointFpTwice(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=new BigInteger("3"),e=this.x.toBigInteger(),i=this.y.toBigInteger(),n=i.multiply(this.z),r=n.multiply(i).mod(this.curve.q),u=this.curve.a.toBigInteger(),s=e.square().multiply(t);BigInteger.ZERO.equals(u)||(s=s.add(this.z.square().multiply(u)));var p=(s=s.mod(this.curve.q)).square().subtract(e.shiftLeft(3).multiply(r)).shiftLeft(1).multiply(n).mod(this.curve.q),o=s.multiply(t).multiply(e).subtract(r.shiftLeft(1)).shiftLeft(2).multiply(r).subtract(s.square().multiply(s)).mod(this.curve.q),l=n.square().multiply(n).shiftLeft(3).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(o),l)}function pointFpMultiply(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new BigInteger("3")),r=this.negate(),u=this;for(e=n.bitLength()-2;e>0;--e){u=u.twice();var s=n.testBit(e);s!=i.testBit(e)&&(u=u.add(s?this:r))}return u}function pointFpMultiplyTwo(t,e,i){var n;n=t.bitLength()>i.bitLength()?t.bitLength()-1:i.bitLength()-1;for(var r=this.curve.getInfinity(),u=this.add(e);n>=0;)r=r.twice(),t.testBit(n)?r=i.testBit(n)?r.add(u):r.add(this):i.testBit(n)&&(r=r.add(e)),--n;return r}function ECCurveFp(t,e,i){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(i),this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(t){return t==this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(t){return new ECFieldElementFp(this.q,t)}function curveFpDecodePointHex(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var e=(t.length-2)/2,i=t.substr(2,e),n=t.substr(e+2,e);return new ECPointFp(this,this.fromBigInteger(new BigInteger(i,16)),this.fromBigInteger(new BigInteger(n,16)));default:return null}}ECFieldElementFp.prototype.equals=feFpEquals,ECFieldElementFp.prototype.toBigInteger=feFpToBigInteger,ECFieldElementFp.prototype.negate=feFpNegate,ECFieldElementFp.prototype.add=feFpAdd,ECFieldElementFp.prototype.subtract=feFpSubtract,ECFieldElementFp.prototype.multiply=feFpMultiply,ECFieldElementFp.prototype.square=feFpSquare,ECFieldElementFp.prototype.divide=feFpDivide,ECPointFp.prototype.getX=pointFpGetX,ECPointFp.prototype.getY=pointFpGetY,ECPointFp.prototype.equals=pointFpEquals,ECPointFp.prototype.isInfinity=pointFpIsInfinity,ECPointFp.prototype.negate=pointFpNegate,ECPointFp.prototype.add=pointFpAdd,ECPointFp.prototype.twice=pointFpTwice,ECPointFp.prototype.multiply=pointFpMultiply,ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo,ECCurveFp.prototype.getQ=curveFpGetQ,ECCurveFp.prototype.getA=curveFpGetA,ECCurveFp.prototype.getB=curveFpGetB,ECCurveFp.prototype.equals=curveFpEquals,ECCurveFp.prototype.getInfinity=curveFpGetInfinity,ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger,ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex;
// ! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/
function Arcfour(){this.i=0,this.j=0,this.S=new Array}function ARC4init(i){var t,s,h;for(t=0;t<256;++t)this.S[t]=t;for(s=0,t=0;t<256;++t)s=s+this.S[t]+i[t%i.length]&255,h=this.S[t],this.S[t]=this.S[s],this.S[s]=h;this.i=0,this.j=0}function ARC4next(){var i;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,i=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=i,this.S[i+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}Arcfour.prototype.init=ARC4init,Arcfour.prototype.next=ARC4next;var rng_psize=256;
// (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/
var rng_state,rng_pool,rng_pptr;function rng_seed_int(r){rng_pool[rng_pptr++]^=255&r,rng_pool[rng_pptr++]^=r>>8&255,rng_pool[rng_pptr++]^=r>>16&255,rng_pool[rng_pptr++]^=r>>24&255,rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}function rng_seed_time(){rng_seed_int((new Date).getTime())}if(null==rng_pool){var t;if(rng_pool=new Array,rng_pptr=0,void 0!==window&&(void 0!==window.crypto||void 0!==window.msCrypto)){var crypto=window.crypto||window.msCrypto;if(crypto.getRandomValues){var ua=new Uint8Array(32);for(crypto.getRandomValues(ua),t=0;t<32;++t)rng_pool[rng_pptr++]=ua[t]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var z=window.crypto.random(32);for(t=0;t<z.length;++t)rng_pool[rng_pptr++]=255&z.charCodeAt(t)}}for(;rng_pptr<rng_psize;)t=Math.floor(65536*Math.random()),rng_pool[rng_pptr++]=t>>>8,rng_pool[rng_pptr++]=255&t;rng_pptr=0,rng_seed_time()}function rng_get_byte(){if(null==rng_state){for(rng_seed_time(),(rng_state=prng_newstate()).init(rng_pool),rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr)rng_pool[rng_pptr]=0;rng_pptr=0}return rng_state.next()}function rng_get_bytes(r){var n;for(n=0;n<r.length;++n)r[n]=rng_get_byte()}function SecureRandom(){}SecureRandom.prototype.nextBytes=rng_get_bytes;
// (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/
function parseBigInt(t,n){return new BigInteger(t,n)}function linebrk(t,n){for(var r="",e=0;e+n<t.length;)r+=t.substring(e,e+n)+"\n",e+=n;return r+t.substring(e,t.length)}function byte2Hex(t){return t<16?"0"+t.toString(16):t.toString(16)}function pkcs1pad2(t,n){if(n<t.length+11)throw"Message too long for RSA";for(var r=new Array,e=t.length-1;e>=0&&n>0;){var i=t.charCodeAt(e--);i<128?r[--n]=i:i>127&&i<2048?(r[--n]=63&i|128,r[--n]=i>>6|192):(r[--n]=63&i|128,r[--n]=i>>6&63|128,r[--n]=i>>12|224)}r[--n]=0;for(var o=new SecureRandom,l=new Array;n>2;){for(l[0]=0;0==l[0];)o.nextBytes(l);r[--n]=l[0]}return r[--n]=2,r[--n]=0,new BigInteger(r)}function oaep_mgf1_arr(t,n,r){for(var e="",i=0;e.length<n;)e+=r(String.fromCharCode.apply(String,t.concat([(4278190080&i)>>24,(16711680&i)>>16,(65280&i)>>8,255&i]))),i+=1;return e}function oaep_pad(t,n,r,e){var i=KJUR.crypto.MessageDigest,o=KJUR.crypto.Util,l=null;if(r||(r="sha1"),"string"==typeof r&&(l=i.getCanonicalAlgName(r),e=i.getHashLength(l),r=function(t){return hextorstr(o.hashHex(rstrtohex(t),l))}),t.length+2*e+2>n)throw"Message too long for RSA";var u,a="";for(u=0;u<n-t.length-2*e-2;u+=1)a+="\0";var h=r("")+a+""+t,s=new Array(e);(new SecureRandom).nextBytes(s);var g=oaep_mgf1_arr(s,h.length,r),c=[];for(u=0;u<h.length;u+=1)c[u]=h.charCodeAt(u)^g.charCodeAt(u);var p=oaep_mgf1_arr(c,s.length,r),f=[0];for(u=0;u<s.length;u+=1)f[u+1]=s[u]^p.charCodeAt(u);return new BigInteger(f.concat(c))}function RSAKey(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}function RSASetPublic(t,n){if(this.isPublic=!0,this.isPrivate=!1,"string"!=typeof t)this.n=t,this.e=n;else{if(!(null!=t&&null!=n&&t.length>0&&n.length>0))throw"Invalid RSA public key";this.n=parseBigInt(t,16),this.e=parseInt(n,16)}}function RSADoPublic(t){return t.modPowInt(this.e,this.n)}function RSAEncrypt(t){var n=pkcs1pad2(t,this.n.bitLength()+7>>3);if(null==n)return null;var r=this.doPublic(n);if(null==r)return null;var e=r.toString(16);return 0==(1&e.length)?e:"0"+e}function RSAEncryptOAEP(t,n,r){var e=oaep_pad(t,this.n.bitLength()+7>>3,n,r);if(null==e)return null;var i=this.doPublic(e);if(null==i)return null;var o=i.toString(16);return 0==(1&o.length)?o:"0"+o}RSAKey.prototype.doPublic=RSADoPublic,RSAKey.prototype.setPublic=RSASetPublic,RSAKey.prototype.encrypt=RSAEncrypt,RSAKey.prototype.encryptOAEP=RSAEncryptOAEP,RSAKey.prototype.type="RSA";
// CryptoJS v3.1.2
!function(r){var t=CryptoJS,e=t.lib,n=e.WordArray,o=e.Hasher,s=t.algo,a=[],i=[];!function(){function t(t){for(var e=r.sqrt(t),n=2;n<=e;n++)if(!(t%n))return!1;return!0}function e(r){return 4294967296*(r-(0|r))|0}for(var n=2,o=0;o<64;)t(n)&&(o<8&&(a[o]=e(r.pow(n,.5))),i[o]=e(r.pow(n,1/3)),o++),n++}();var h=[],c=s.SHA256=o.extend({_doReset:function(){this._hash=new n.init(a.slice(0))},_doProcessBlock:function(r,t){for(var e=this._hash.words,n=e[0],o=e[1],s=e[2],a=e[3],c=e[4],l=e[5],f=e[6],u=e[7],_=0;_<64;_++){if(_<16)h[_]=0|r[t+_];else{var v=h[_-15],d=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,H=h[_-2],p=(H<<15|H>>>17)^(H<<13|H>>>19)^H>>>10;h[_]=d+h[_-7]+p+h[_-16]}var w=n&o^n&s^o&s,y=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),g=u+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&l^~c&f)+i[_]+h[_];u=f,f=l,l=c,c=a+g|0,a=s,s=o,o=n,n=g+(y+w)|0}e[0]=e[0]+n|0,e[1]=e[1]+o|0,e[2]=e[2]+s|0,e[3]=e[3]+a|0,e[4]=e[4]+c|0,e[5]=e[5]+l|0,e[6]=e[6]+f|0,e[7]=e[7]+u|0},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,o=8*t.sigBytes;return e[o>>>5]|=128<<24-o%32,e[14+(o+64>>>9<<4)]=r.floor(n/4294967296),e[15+(o+64>>>9<<4)]=n,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var r=o.clone.call(this);return r._hash=this._hash.clone(),r}});t.SHA256=o._createHelper(c),t.HmacSHA256=o._createHmacHelper(c)}(Math);
// asn1-1.0.14.js (c) 2013-2018 Kenji Urushima | kjur.github.com/jsrsasign/license
"undefined"!=typeof KJUR&&KJUR||(KJUR={}),void 0!==KJUR.asn1&&KJUR.asn1||(KJUR.asn1={}),KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",s=0;s<i;s++)n+="f";e=new BigInteger(n,16).xor(t).add(BigInteger.ONE).toString(16).replace(/^-/,"")}return e},this.getPEMStringFromHex=function(t,e){return hextopem(t,e)},this.newObject=function(t){var e=KJUR.asn1,i=e.DERBoolean,n=e.DERInteger,s=e.DERBitString,r=e.DEROctetString,h=e.DERNull,a=e.DERObjectIdentifier,o=e.DEREnumerated,l=e.DERUTF8String,u=e.DERNumericString,c=e.DERPrintableString,g=e.DERTeletexString,d=e.DERIA5String,f=e.DERUTCTime,R=e.DERGeneralizedTime,S=e.DERSequence,U=e.DERSet,x=e.DERTaggedObject,E=e.ASN1Util.newObject,D=Object.keys(t);if(1!=D.length)throw"key of param shall be only one.";var b=D[0];if(-1==":bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:seq:set:tag:".indexOf(":"+b+":"))throw"undefined key: "+b;if("bool"==b)return new i(t[b]);if("int"==b)return new n(t[b]);if("bitstr"==b)return new s(t[b]);if("octstr"==b)return new r(t[b]);if("null"==b)return new h(t[b]);if("oid"==b)return new a(t[b]);if("enum"==b)return new o(t[b]);if("utf8str"==b)return new l(t[b]);if("numstr"==b)return new u(t[b]);if("prnstr"==b)return new c(t[b]);if("telstr"==b)return new g(t[b]);if("ia5str"==b)return new d(t[b]);if("utctime"==b)return new f(t[b]);if("gentime"==b)return new R(t[b]);if("seq"==b){for(var v=t[b],V=[],J=0;J<v.length;J++){var K=E(v[J]);V.push(K)}return new S({array:V})}if("set"==b){for(v=t[b],V=[],J=0;J<v.length;J++){K=E(v[J]);V.push(K)}return new U({array:V})}if("tag"==b){var T=t[b];if("[object Array]"===Object.prototype.toString.call(T)&&3==T.length){var O=E(T[2]);return new x({tag:T[0],explicit:T[1],obj:O})}var A={};if(void 0!==T.explicit&&(A.explicit=T.explicit),void 0!==T.tag&&(A.tag=T.tag),void 0===T.obj)throw"obj shall be specified for 'tag'.";return A.obj=E(T.obj),new x(A)}},this.jsonToASN1HEX=function(t){return this.newObject(t).getEncodedHex()}},KJUR.asn1.ASN1Util.oidHexToInt=function(t){for(var e="",i=parseInt(t.substr(0,2),16),n=(e=Math.floor(i/40)+"."+i%40,""),s=2;s<t.length;s+=2){var r=("00000000"+parseInt(t.substr(s,2),16).toString(2)).slice(-8);if(n+=r.substr(1,7),"0"==r.substr(0,1))e=e+"."+new BigInteger(n,2).toString(10),n=""}return e},KJUR.asn1.ASN1Util.oidIntToHex=function(t){var e=function(t){var e=t.toString(16);return 1==e.length&&(e="0"+e),e},i=function(t){var i="",n=new BigInteger(t,10).toString(2),s=7-n.length%7;7==s&&(s=0);for(var r="",h=0;h<s;h++)r+="0";n=r+n;for(h=0;h<n.length-1;h+=7){var a=n.substr(h,7);h!=n.length-7&&(a="1"+a),i+=e(parseInt(a,2))}return i};if(!t.match(/^[0-9.]+$/))throw"malformed oid string: "+t;var n="",s=t.split("."),r=40*parseInt(s[0])+parseInt(s[1]);n+=e(r),s.splice(0,2);for(var h=0;h<s.length;h++)n+=i(s[h]);return n},KJUR.asn1.ASN1Object=function(){this.getLengthHexFromValue=function(){if(void 0===this.hV||null==this.hV)throw"this.hV is null or undefined.";if(this.hV.length%2==1)throw"value hex must be even length: n="+"".length+",v="+this.hV;var t=this.hV.length/2,e=t.toString(16);if(e.length%2==1&&(e="0"+e),t<128)return e;var i=e.length/2;if(i>15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},KJUR.asn1.DERAbstractString=function(t){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=utf8tohex(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},YAHOO.lang.extend(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object),KJUR.asn1.DERAbstractTime=function(t){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,s=this.localDateToUTC(t),r=String(s.getFullYear());"utc"==e&&(r=r.substr(2,2));var h=r+n(String(s.getMonth()+1),2)+n(String(s.getDate()),2)+n(String(s.getHours()),2)+n(String(s.getMinutes()),2)+n(String(s.getSeconds()),2);if(!0===i){var a=s.getMilliseconds();if(0!=a){var o=n(String(a),3);h=h+"."+(o=o.replace(/[0]+$/,""))}}return h+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=stohex(t)},this.setByDateValue=function(t,e,i,n,s,r){var h=new Date(Date.UTC(t,e-1,i,n,s,r,0));this.setByDate(h)},this.getFreshValueHex=function(){return this.hV}},YAHOO.lang.extend(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object),KJUR.asn1.DERAbstractStructured=function(t){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},YAHOO.lang.extend(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object),KJUR.asn1.DERBoolean=function(){KJUR.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},YAHOO.lang.extend(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object),KJUR.asn1.DERInteger=function(t){KJUR.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new BigInteger(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},YAHOO.lang.extend(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object),KJUR.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=KJUR.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7<t)throw"unused bits shall be from 0 to 7: u = "+t;var i="0"+t;this.hTLV=null,this.isModified=!0,this.hV=i+e},this.setByBinaryString=function(t){var e=8-(t=t.replace(/0+$/,"")).length%8;8==e&&(e=0);for(var i=0;i<=e;i++)t+="0";var n="";for(i=0;i<t.length-1;i+=8){var s=t.substr(i,8),r=parseInt(s,2).toString(16);1==r.length&&(r="0"+r),n+=r}this.hTLV=null,this.isModified=!0,this.hV="0"+e+n},this.setByBooleanArray=function(t){for(var e="",i=0;i<t.length;i++)1==t[i]?e+="1":e+="0";this.setByBinaryString(e)},this.newFalseArray=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=!1;return e},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t&&t.toLowerCase().match(/^[0-9a-f]+$/)?this.setHexValueIncludingUnusedBits(t):void 0!==t.hex?this.setHexValueIncludingUnusedBits(t.hex):void 0!==t.bin?this.setByBinaryString(t.bin):void 0!==t.array&&this.setByBooleanArray(t.array))},YAHOO.lang.extend(KJUR.asn1.DERBitString,KJUR.asn1.ASN1Object),KJUR.asn1.DEROctetString=function(t){if(void 0!==t&&void 0!==t.obj){var e=KJUR.asn1.ASN1Util.newObject(t.obj);t.hex=e.getEncodedHex()}KJUR.asn1.DEROctetString.superclass.constructor.call(this,t),this.hT="04"},YAHOO.lang.extend(KJUR.asn1.DEROctetString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERNull=function(){KJUR.asn1.DERNull.superclass.constructor.call(this),this.hT="05",this.hTLV="0500"},YAHOO.lang.extend(KJUR.asn1.DERNull,KJUR.asn1.ASN1Object),KJUR.asn1.DERObjectIdentifier=function(t){var e=function(t){var e=t.toString(16);return 1==e.length&&(e="0"+e),e},i=function(t){var i="",n=new BigInteger(t,10).toString(2),s=7-n.length%7;7==s&&(s=0);for(var r="",h=0;h<s;h++)r+="0";n=r+n;for(h=0;h<n.length-1;h+=7){var a=n.substr(h,7);h!=n.length-7&&(a="1"+a),i+=e(parseInt(a,2))}return i};KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this),this.hT="06",this.setValueHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.setValueOidString=function(t){if(!t.match(/^[0-9.]+$/))throw"malformed oid string: "+t;var n="",s=t.split("."),r=40*parseInt(s[0])+parseInt(s[1]);n+=e(r),s.splice(0,2);for(var h=0;h<s.length;h++)n+=i(s[h]);this.hTLV=null,this.isModified=!0,this.s=null,this.hV=n},this.setValueName=function(t){var e=KJUR.asn1.x509.OID.name2oid(t);if(""===e)throw"DERObjectIdentifier oidName undefined: "+t;this.setValueOidString(e)},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?t.match(/^[0-2].[0-9.]+$/)?this.setValueOidString(t):this.setValueName(t):void 0!==t.oid?this.setValueOidString(t.oid):void 0!==t.hex?this.setValueHex(t.hex):void 0!==t.name&&this.setValueName(t.name))},YAHOO.lang.extend(KJUR.asn1.DERObjectIdentifier,KJUR.asn1.ASN1Object),KJUR.asn1.DEREnumerated=function(t){KJUR.asn1.DEREnumerated.superclass.constructor.call(this),this.hT="0a",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new BigInteger(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},YAHOO.lang.extend(KJUR.asn1.DEREnumerated,KJUR.asn1.ASN1Object),KJUR.asn1.DERUTF8String=function(t){KJUR.asn1.DERUTF8String.superclass.constructor.call(this,t),this.hT="0c"},YAHOO.lang.extend(KJUR.asn1.DERUTF8String,KJUR.asn1.DERAbstractString),KJUR.asn1.DERNumericString=function(t){KJUR.asn1.DERNumericString.superclass.constructor.call(this,t),this.hT="12"},YAHOO.lang.extend(KJUR.asn1.DERNumericString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERPrintableString=function(t){KJUR.asn1.DERPrintableString.superclass.constructor.call(this,t),this.hT="13"},YAHOO.lang.extend(KJUR.asn1.DERPrintableString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERTeletexString=function(t){KJUR.asn1.DERTeletexString.superclass.constructor.call(this,t),this.hT="14"},YAHOO.lang.extend(KJUR.asn1.DERTeletexString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERIA5String=function(t){KJUR.asn1.DERIA5String.superclass.constructor.call(this,t),this.hT="16"},YAHOO.lang.extend(KJUR.asn1.DERIA5String,KJUR.asn1.DERAbstractString),KJUR.asn1.DERUTCTime=function(t){KJUR.asn1.DERUTCTime.superclass.constructor.call(this,t),this.hT="17",this.setByDate=function(t){this.hTLV=null,this.isModified=!0,this.date=t,this.s=this.formatDate(this.date,"utc"),this.hV=stohex(this.s)},this.getFreshValueHex=function(){return void 0===this.date&&void 0===this.s&&(this.date=new Date,this.s=this.formatDate(this.date,"utc"),this.hV=stohex(this.s)),this.hV},void 0!==t&&(void 0!==t.str?this.setString(t.str):"string"==typeof t&&t.match(/^[0-9]{12}Z$/)?this.setString(t):void 0!==t.hex?this.setStringHex(t.hex):void 0!==t.date&&this.setByDate(t.date))},YAHOO.lang.extend(KJUR.asn1.DERUTCTime,KJUR.asn1.DERAbstractTime),KJUR.asn1.DERGeneralizedTime=function(t){KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this,t),this.hT="18",this.withMillis=!1,this.setByDate=function(t){this.hTLV=null,this.isModified=!0,this.date=t,this.s=this.formatDate(this.date,"gen",this.withMillis),this.hV=stohex(this.s)},this.getFreshValueHex=function(){return void 0===this.date&&void 0===this.s&&(this.date=new Date,this.s=this.formatDate(this.date,"gen",this.withMillis),this.hV=stohex(this.s)),this.hV},void 0!==t&&(void 0!==t.str?this.setString(t.str):"string"==typeof t&&t.match(/^[0-9]{14}Z$/)?this.setString(t):void 0!==t.hex?this.setStringHex(t.hex):void 0!==t.date&&this.setByDate(t.date),!0===t.millis&&(this.withMillis=!0))},YAHOO.lang.extend(KJUR.asn1.DERGeneralizedTime,KJUR.asn1.DERAbstractTime),KJUR.asn1.DERSequence=function(t){KJUR.asn1.DERSequence.superclass.constructor.call(this,t),this.hT="30",this.getFreshValueHex=function(){for(var t="",e=0;e<this.asn1Array.length;e++){t+=this.asn1Array[e].getEncodedHex()}return this.hV=t,this.hV}},YAHOO.lang.extend(KJUR.asn1.DERSequence,KJUR.asn1.DERAbstractStructured),KJUR.asn1.DERSet=function(t){KJUR.asn1.DERSet.superclass.constructor.call(this,t),this.hT="31",this.sortFlag=!0,this.getFreshValueHex=function(){for(var t=new Array,e=0;e<this.asn1Array.length;e++){var i=this.asn1Array[e];t.push(i.getEncodedHex())}return 1==this.sortFlag&&t.sort(),this.hV=t.join(""),this.hV},void 0!==t&&void 0!==t.sortflag&&0==t.sortflag&&(this.sortFlag=!1)},YAHOO.lang.extend(KJUR.asn1.DERSet,KJUR.asn1.DERAbstractStructured),KJUR.asn1.DERTaggedObject=function(t){KJUR.asn1.DERTaggedObject.superclass.constructor.call(this),this.hT="a0",this.hV="",this.isExplicit=!0,this.asn1Object=null,this.setASN1Object=function(t,e,i){this.hT=e,this.isExplicit=t,this.asn1Object=i,this.isExplicit?(this.hV=this.asn1Object.getEncodedHex(),this.hTLV=null,this.isModified=!0):(this.hV=null,this.hTLV=i.getEncodedHex(),this.hTLV=this.hTLV.replace(/^../,e),this.isModified=!1)},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.tag&&(this.hT=t.tag),void 0!==t.explicit&&(this.isExplicit=t.explicit),void 0!==t.obj&&(this.asn1Object=t.obj,this.setASN1Object(this.isExplicit,this.hT,this.asn1Object)))},YAHOO.lang.extend(KJUR.asn1.DERTaggedObject,KJUR.asn1.ASN1Object);
// asn1hex-1.2.0.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
var ASN1HEX=new function(){};ASN1HEX.getLblen=function(t,r){if("8"!=t.substr(r+2,1))return 1;var n=parseInt(t.substr(r+3,1));return 0==n?-1:0<n&&n<10?n+1:-2},ASN1HEX.getL=function(t,r){var n=ASN1HEX.getLblen(t,r);return n<1?"":t.substr(r+2,2*n)},ASN1HEX.getVblen=function(t,r){var n;return""==(n=ASN1HEX.getL(t,r))?-1:("8"===n.substr(0,1)?new BigInteger(n.substr(2),16):new BigInteger(n,16)).intValue()},ASN1HEX.getVidx=function(t,r){var n=ASN1HEX.getLblen(t,r);return n<0?n:r+2*(n+1)},ASN1HEX.getV=function(t,r){var n=ASN1HEX.getVidx(t,r),e=ASN1HEX.getVblen(t,r);return t.substr(n,2*e)},ASN1HEX.getTLV=function(t,r){return t.substr(r,2)+ASN1HEX.getL(t,r)+ASN1HEX.getV(t,r)},ASN1HEX.getNextSiblingIdx=function(t,r){return ASN1HEX.getVidx(t,r)+2*ASN1HEX.getVblen(t,r)},ASN1HEX.getChildIdx=function(t,r){var n=ASN1HEX,e=new Array,i=n.getVidx(t,r);"03"==t.substr(r,2)?e.push(i+2):e.push(i);for(var u=n.getVblen(t,r),s=i,g=0;;){var o=n.getNextSiblingIdx(t,s);if(null==o||o-i>=2*u)break;if(g>=200)break;e.push(o),s=o,g++}return e},ASN1HEX.getNthChildIdx=function(t,r,n){return ASN1HEX.getChildIdx(t,r)[n]},ASN1HEX.getIdxbyList=function(t,r,n,e){var i,u,s=ASN1HEX;if(0==n.length){if(void 0!==e&&t.substr(r,2)!==e)throw"checking tag doesn't match: "+t.substr(r,2)+"!="+e;return r}return i=n.shift(),u=s.getChildIdx(t,r),s.getIdxbyList(t,u[i],n,e)},ASN1HEX.getTLVbyList=function(t,r,n,e){var i=ASN1HEX,u=i.getIdxbyList(t,r,n);if(void 0===u)throw"can't find nthList object";if(void 0!==e&&t.substr(u,2)!=e)throw"checking tag doesn't match: "+t.substr(u,2)+"!="+e;return i.getTLV(t,u)},ASN1HEX.getVbyList=function(t,r,n,e,i){var u,s,g=ASN1HEX;if(void 0===(u=g.getIdxbyList(t,r,n,e)))throw"can't find nthList object";return s=g.getV(t,u),!0===i&&(s=s.substr(2)),s},ASN1HEX.hextooidstr=function(t){var r=function(t,r){return t.length>=r?t:new Array(r-t.length+1).join("0")+t},n=[],e=t.substr(0,2),i=parseInt(e,16);n[0]=new String(Math.floor(i/40)),n[1]=new String(i%40);for(var u=t.substr(2),s=[],g=0;g<u.length/2;g++)s.push(parseInt(u.substr(2*g,2),16));var o=[],a="";for(g=0;g<s.length;g++)128&s[g]?a+=r((127&s[g]).toString(2),7):(a+=r((127&s[g]).toString(2),7),o.push(new String(parseInt(a,2))),a="");var f=n.join(".");return o.length>0&&(f=f+"."+o.join(".")),f},ASN1HEX.dump=function(t,r,n,e){var i=ASN1HEX,u=i.getV,s=i.dump,g=i.getChildIdx,o=t;t instanceof KJUR.asn1.ASN1Object&&(o=t.getEncodedHex());var a=function(t,r){return t.length<=2*r?t:t.substr(0,r)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-r,r)};void 0===r&&(r={ommit_long_octet:32}),void 0===n&&(n=0),void 0===e&&(e="");var f=r.ommit_long_octet;if("01"==o.substr(n,2))return"00"==(b=u(o,n))?e+"BOOLEAN FALSE\n":e+"BOOLEAN TRUE\n";if("02"==o.substr(n,2))return e+"INTEGER "+a(b=u(o,n),f)+"\n";if("03"==o.substr(n,2))return e+"BITSTRING "+a(b=u(o,n),f)+"\n";if("04"==o.substr(n,2)){var b=u(o,n);if(i.isASN1HEX(b)){var S=e+"OCTETSTRING, encapsulates\n";return S+=s(b,r,0,e+" ")}return e+"OCTETSTRING "+a(b,f)+"\n"}if("05"==o.substr(n,2))return e+"NULL\n";if("06"==o.substr(n,2)){var N=u(o,n),E=KJUR.asn1.ASN1Util.oidHexToInt(N),h=KJUR.asn1.x509.OID.oid2name(E),l=E.replace(/\./g," ");return""!=h?e+"ObjectIdentifier "+h+" ("+l+")\n":e+"ObjectIdentifier ("+l+")\n"}if("0c"==o.substr(n,2))return e+"UTF8String '"+hextoutf8(u(o,n))+"'\n";if("13"==o.substr(n,2))return e+"PrintableString '"+hextoutf8(u(o,n))+"'\n";if("14"==o.substr(n,2))return e+"TeletexString '"+hextoutf8(u(o,n))+"'\n";if("16"==o.substr(n,2))return e+"IA5String '"+hextoutf8(u(o,n))+"'\n";if("17"==o.substr(n,2))return e+"UTCTime "+hextoutf8(u(o,n))+"\n";if("18"==o.substr(n,2))return e+"GeneralizedTime "+hextoutf8(u(o,n))+"\n";if("30"==o.substr(n,2)){if("3000"==o.substr(n,4))return e+"SEQUENCE {}\n";S=e+"SEQUENCE\n";var d=r;if((2==(v=g(o,n)).length||3==v.length)&&"06"==o.substr(v[0],2)&&"04"==o.substr(v[v.length-1],2)){h=i.oidname(u(o,v[0]));var A=JSON.parse(JSON.stringify(r));A.x509ExtName=h,d=A}for(var c=0;c<v.length;c++)S+=s(o,d,v[c],e+" ");return S}if("31"==o.substr(n,2)){S=e+"SET\n";var v=g(o,n);for(c=0;c<v.length;c++)S+=s(o,r,v[c],e+" ");return S}var H=parseInt(o.substr(n,2),16);if(0!=(128&H)){var x=31&H;if(0!=(32&H)){var S=e+"["+x+"]\n";for(v=g(o,n),c=0;c<v.length;c++)S+=s(o,r,v[c],e+" ");return S}return"68747470"==(b=u(o,n)).substr(0,8)&&(b=hextoutf8(b)),"subjectAltName"===r.x509ExtName&&2==x&&(b=hextoutf8(b)),S=e+"["+x+"] "+b+"\n"}return e+"UNKNOWN("+o.substr(n,2)+") "+u(o,n)+"\n"},ASN1HEX.isASN1HEX=function(t){var r=ASN1HEX;if(t.length%2==1)return!1;var n=r.getVblen(t,0),e=t.substr(0,2),i=r.getL(t,0);return t.length-e.length-i.length==2*n},ASN1HEX.oidname=function(t){var r=KJUR.asn1;KJUR.lang.String.isHex(t)&&(t=r.ASN1Util.oidHexToInt(t));var n=r.x509.OID.oid2name(t);return""===n&&(n=t),n};
// base64x-1.1.14 (c) 2012-2018 Kenji Urushima | kjur.github.com/jsrsasign/license
var KJUR,utf8tob64u,b64utoutf8;function Base64x(){}function stoBA(t){for(var e=new Array,r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function BAtos(t){for(var e="",r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e}function BAtohex(t){for(var e="",r=0;r<t.length;r++){var n=t[r].toString(16);1==n.length&&(n="0"+n),e+=n}return e}function stohex(t){return BAtohex(stoBA(t))}function stob64(t){return hex2b64(stohex(t))}function stob64u(t){return b64tob64u(hex2b64(stohex(t)))}function b64utos(t){return BAtos(b64toBA(b64utob64(t)))}function b64tob64u(t){return t=(t=(t=t.replace(/\=/g,"")).replace(/\+/g,"-")).replace(/\//g,"_")}function b64utob64(t){return t.length%4==2?t+="==":t.length%4==3&&(t+="="),t=(t=t.replace(/-/g,"+")).replace(/_/g,"/")}function hextob64u(t){return t.length%2==1&&(t="0"+t),b64tob64u(hex2b64(t))}function b64utohex(t){return b64tohex(b64utob64(t))}function utf8tob64(t){return hex2b64(uricmptohex(encodeURIComponentAll(t)))}function b64toutf8(t){return decodeURIComponent(hextouricmp(b64tohex(t)))}function utf8tohex(t){return uricmptohex(encodeURIComponentAll(t))}function hextoutf8(t){return decodeURIComponent(hextouricmp(t))}function hextorstr(t){for(var e="",r=0;r<t.length-1;r+=2)e+=String.fromCharCode(parseInt(t.substr(r,2),16));return e}function rstrtohex(t){for(var e="",r=0;r<t.length;r++)e+=("0"+t.charCodeAt(r).toString(16)).slice(-2);return e}function hextob64(t){return hex2b64(t)}function hextob64nl(t){var e=hextob64(t).replace(/(.{64})/g,"$1\r\n");return e=e.replace(/\r\n$/,"")}function b64nltohex(t){var e=t.replace(/[^0-9A-Za-z\/+=]*/g,"");return b64tohex(e)}function hextopem(t,e){return"-----BEGIN "+e+"-----\r\n"+hextob64nl(t)+"\r\n-----END "+e+"-----\r\n"}function pemtohex(t,e){if(-1==t.indexOf("-----BEGIN "))throw"can't find PEM header: "+e;return b64nltohex(t=void 0!==e?(t=t.replace("-----BEGIN "+e+"-----","")).replace("-----END "+e+"-----",""):(t=t.replace(/-----BEGIN [^-]+-----/,"")).replace(/-----END [^-]+-----/,""))}function hextoArrayBuffer(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),r=new DataView(e),n=0;n<t.length/2;n++)r.setUint8(n,parseInt(t.substr(2*n,2),16));return e}function ArrayBuffertohex(t){for(var e="",r=new DataView(t),n=0;n<t.byteLength;n++)e+=("00"+r.getUint8(n).toString(16)).slice(-2);return e}function zulutomsec(t){var e,r,n,o,u,a,i,c,f,h,l;if(l=t.match(/^(\d{2}|\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/))return c=l[1],e=parseInt(c),2===c.length&&(50<=e&&e<100?e=1900+e:0<=e&&e<50&&(e=2e3+e)),r=parseInt(l[2])-1,n=parseInt(l[3]),o=parseInt(l[4]),u=parseInt(l[5]),a=parseInt(l[6]),i=0,""!==(f=l[7])&&(h=(f.substr(1)+"00").substr(0,3),i=parseInt(h)),Date.UTC(e,r,n,o,u,a,i);throw"unsupported zulu format: "+t}function zulutosec(t){return~~(zulutomsec(t)/1e3)}function zulutodate(t){return new Date(zulutomsec(t))}function datetozulu(t,e,r){var n,o=t.getUTCFullYear();if(e){if(o<1950||2049<o)throw"not proper year for UTCTime: "+o;n=(""+o).slice(-2)}else n=("000"+o).slice(-4);if(n+=("0"+(t.getUTCMonth()+1)).slice(-2),n+=("0"+t.getUTCDate()).slice(-2),n+=("0"+t.getUTCHours()).slice(-2),n+=("0"+t.getUTCMinutes()).slice(-2),n+=("0"+t.getUTCSeconds()).slice(-2),r){var u=t.getUTCMilliseconds();0!==u&&(n+="."+(u=(u=("00"+u).slice(-3)).replace(/0+$/g,"")))}return n+="Z"}function uricmptohex(t){return t.replace(/%/g,"")}function hextouricmp(t){return t.replace(/(..)/g,"%$1")}function ipv6tohex(t){var e="malformed IPv6 address";if(!t.match(/^[0-9A-Fa-f:]+$/))throw e;var r=(t=t.toLowerCase()).split(":").length-1;if(r<2)throw e;var n=":".repeat(7-r+2),o=(t=t.replace("::",n)).split(":");if(8!=o.length)throw e;for(var u=0;u<8;u++)o[u]=("0000"+o[u]).slice(-4);return o.join("")}function hextoipv6(t){if(!t.match(/^[0-9A-Fa-f]{32}$/))throw"malformed IPv6 address octet";for(var e=(t=t.toLowerCase()).match(/.{1,4}/g),r=0;r<8;r++)e[r]=e[r].replace(/^0+/,""),""==e[r]&&(e[r]="0");var n=(t=":"+e.join(":")+":").match(/:(0:){2,}/g);if(null===n)return t.slice(1,-1);var o="";for(r=0;r<n.length;r++)n[r].length>o.length&&(o=n[r]);return(t=t.replace(o,"::")).slice(1,-1)}function hextoip(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?hextoipv6(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function iptohex(t){var e="malformed IP address";if(!(t=t.toLowerCase(t)).match(/^[0-9.]+$/)){if(t.match(/^[0-9a-f:]+$/)&&-1!==t.indexOf(":"))return ipv6tohex(t);throw e}var r=t.split(".");if(4!==r.length)throw e;var n="";try{for(var o=0;o<4;o++){n+=("0"+parseInt(r[o]).toString(16)).slice(-2)}return n}catch(t){throw e}}function encodeURIComponentAll(t){for(var e=encodeURIComponent(t),r="",n=0;n<e.length;n++)"%"==e[n]?(r+=e.substr(n,3),n+=2):r=r+"%"+stohex(e[n]);return r}function newline_toUnix(t){return t=t.replace(/\r\n/gm,"\n")}function newline_toDos(t){return t=(t=t.replace(/\r\n/gm,"\n")).replace(/\n/gm,"\r\n")}function hextoposhex(t){return t.length%2==1?"0"+t:t.substr(0,1)>"7"?"00"+t:t}function intarystrtohex(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,r){var n=parseInt(t);if(n<0||255<n)throw"integer not in range 0-255";return("00"+n.toString(16)).slice(-2)}).join("")}catch(t){throw"malformed integer array string: "+t}}void 0!==KJUR&&KJUR||(KJUR={}),void 0!==KJUR.lang&&KJUR.lang||(KJUR.lang={}),KJUR.lang.String=function(){},"function"==typeof Buffer?(utf8tob64u=function(t){return b64tob64u(new Buffer(t,"utf8").toString("base64"))},b64utoutf8=function(t){return new Buffer(b64utob64(t),"base64").toString("utf8")}):(utf8tob64u=function(t){return hextob64u(uricmptohex(encodeURIComponentAll(t)))},b64utoutf8=function(t){return decodeURIComponent(hextouricmp(b64utohex(t)))}),KJUR.lang.String.isInteger=function(t){return!!t.match(/^[0-9]+$/)||!!t.match(/^-[0-9]+$/)},KJUR.lang.String.isHex=function(t){return!(t.length%2!=0||!t.match(/^[0-9a-f]+$/)&&!t.match(/^[0-9A-F]+$/))},KJUR.lang.String.isBase64=function(t){return!(!(t=t.replace(/\s+/g,"")).match(/^[0-9A-Za-z+\/]+={0,3}$/)||t.length%4!=0)},KJUR.lang.String.isBase64URL=function(t){return!t.match(/[+/=]/)&&(t=b64utob64(t),KJUR.lang.String.isBase64(t))},KJUR.lang.String.isIntegerArray=function(t){return!!(t=t.replace(/\s+/g,"")).match(/^\[[0-9,]+\]$/)};var strdiffidx=function(t,e){var r=t.length;t.length>e.length&&(r=e.length);for(var n=0;n<r;n++)if(t.charCodeAt(n)!=e.charCodeAt(n))return n;return t.length!=e.length?r:-1};
// crypto-1.2.1.js (c) 2013-2017 Kenji Urushima | kjur.github.io/jsrsasign/license
"undefined"!=typeof KJUR&&KJUR||(KJUR={}),void 0!==KJUR.crypto&&KJUR.crypto||(KJUR.crypto={}),KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414"},this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa"},this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160},this.getDigestInfoHex=function(t,s){if(void 0===this.DIGESTINFOHEAD[s])throw"alg not supported in Util.DIGESTINFOHEAD: "+s;return this.DIGESTINFOHEAD[s]+t},this.getPaddedDigestInfoHex=function(t,s,e){var i=this.getDigestInfoHex(t,s),r=e/4;if(i.length+22>r)throw"key is too short for SigAlg: keylen="+e+","+s;for(var o="0001",a="00"+i,h="",n=r-o.length-a.length,p=0;p<n;p+=2)h+="ff";return o+h+a},this.hashString=function(t,s){return new KJUR.crypto.MessageDigest({alg:s}).digestString(t)},this.hashHex=function(t,s){return new KJUR.crypto.MessageDigest({alg:s}).digestHex(t)},this.sha1=function(t){return new KJUR.crypto.MessageDigest({alg:"sha1",prov:"cryptojs"}).digestString(t)},this.sha256=function(t){return new KJUR.crypto.MessageDigest({alg:"sha256",prov:"cryptojs"}).digestString(t)},this.sha256Hex=function(t){return new KJUR.crypto.MessageDigest({alg:"sha256",prov:"cryptojs"}).digestHex(t)},this.sha512=function(t){return new KJUR.crypto.MessageDigest({alg:"sha512",prov:"cryptojs"}).digestString(t)},this.sha512Hex=function(t){return new KJUR.crypto.MessageDigest({alg:"sha512",prov:"cryptojs"}).digestHex(t)}},KJUR.crypto.Util.md5=function(t){return new KJUR.crypto.MessageDigest({alg:"md5",prov:"cryptojs"}).digestString(t)},KJUR.crypto.Util.ripemd160=function(t){return new KJUR.crypto.MessageDigest({alg:"ripemd160",prov:"cryptojs"}).digestString(t)},KJUR.crypto.Util.SECURERANDOMGEN=new SecureRandom,KJUR.crypto.Util.getRandomHexOfNbytes=function(t){var s=new Array(t);return KJUR.crypto.Util.SECURERANDOMGEN.nextBytes(s),BAtohex(s)},KJUR.crypto.Util.getRandomBigIntegerOfNbytes=function(t){return new BigInteger(KJUR.crypto.Util.getRandomHexOfNbytes(t),16)},KJUR.crypto.Util.getRandomHexOfNbits=function(t){var s=t%8,e=new Array((t-s)/8+1);return KJUR.crypto.Util.SECURERANDOMGEN.nextBytes(e),e[0]=(255<<s&255^255)&e[0],BAtohex(e)},KJUR.crypto.Util.getRandomBigIntegerOfNbits=function(t){return new BigInteger(KJUR.crypto.Util.getRandomHexOfNbits(t),16)},KJUR.crypto.Util.getRandomBigIntegerZeroToMax=function(t){for(var s=t.bitLength();;){var e=KJUR.crypto.Util.getRandomBigIntegerOfNbits(s);if(-1!=t.compareTo(e))return e}},KJUR.crypto.Util.getRandomBigIntegerMinToMax=function(t,s){var e=t.compareTo(s);if(1==e)throw"biMin is greater than biMax";if(0==e)return t;var i=s.subtract(t);return KJUR.crypto.Util.getRandomBigIntegerZeroToMax(i).add(t)},KJUR.crypto.MessageDigest=function(t){this.setAlgAndProvider=function(t,s){if(null!==(t=KJUR.crypto.MessageDigest.getCanonicalAlgName(t))&&void 0===s&&(s=KJUR.crypto.Util.DEFAULTPROVIDER[t]),-1!=":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:".indexOf(t)&&"cryptojs"==s){try{this.md=KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[t].create()}catch(s){throw"setAlgAndProvider hash alg set fail alg="+t+"/"+s}this.updateString=function(t){this.md.update(t)},this.updateHex=function(t){var s=CryptoJS.enc.Hex.parse(t);this.md.update(s)},this.digest=function(){return this.md.finalize().toString(CryptoJS.enc.Hex)},this.digestString=function(t){return this.updateString(t),this.digest()},this.digestHex=function(t){return this.updateHex(t),this.digest()}}if(-1!=":sha256:".indexOf(t)&&"sjcl"==s){try{this.md=new sjcl.hash.sha256}catch(s){throw"setAlgAndProvider hash alg set fail alg="+t+"/"+s}this.updateString=function(t){this.md.update(t)},this.updateHex=function(t){var s=sjcl.codec.hex.toBits(t);this.md.update(s)},this.digest=function(){var t=this.md.finalize();return sjcl.codec.hex.fromBits(t)},this.digestString=function(t){return this.updateString(t),this.digest()},this.digestHex=function(t){return this.updateHex(t),this.digest()}}},this.updateString=function(t){throw"updateString(str) not supported for this alg/prov: "+this.algName+"/"+this.provName},this.updateHex=function(t){throw"updateHex(hex) not supported for this alg/prov: "+this.algName+"/"+this.provName},this.digest=function(){throw"digest() not supported for this alg/prov: "+this.algName+"/"+this.provName},this.digestString=function(t){throw"digestString(str) not supported for this alg/prov: "+this.algName+"/"+this.provName},this.digestHex=function(t){throw"digestHex(hex) not supported for this alg/prov: "+this.algName+"/"+this.provName},void 0!==t&&void 0!==t.alg&&(this.algName=t.alg,void 0===t.prov&&(this.provName=KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]),this.setAlgAndProvider(this.algName,this.provName))},KJUR.crypto.MessageDigest.getCanonicalAlgName=function(t){return"string"==typeof t&&(t=(t=t.toLowerCase()).replace(/-/,"")),t},KJUR.crypto.MessageDigest.getHashLength=function(t){var s=KJUR.crypto.MessageDigest,e=s.getCanonicalAlgName(t);if(void 0===s.HASHLENGTH[e])throw"not supported algorithm: "+t;return s.HASHLENGTH[e]},KJUR.crypto.MessageDigest.HASHLENGTH={md5:16,sha1:20,sha224:28,sha256:32,sha384:48,sha512:64,ripemd160:20},KJUR.crypto.Mac=function(t){this.setAlgAndProvider=function(t,s){if(null==(t=t.toLowerCase())&&(t="hmacsha1"),"hmac"!=(t=t.toLowerCase()).substr(0,4))throw"setAlgAndProvider unsupported HMAC alg: "+t;void 0===s&&(s=KJUR.crypto.Util.DEFAULTPROVIDER[t]),this.algProv=t+"/"+s;var e=t.substr(4);if(-1!=":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:".indexOf(e)&&"cryptojs"==s){try{var i=KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[e];this.mac=CryptoJS.algo.HMAC.create(i,this.pass)}catch(t){throw"setAlgAndProvider hash alg set fail hashAlg="+e+"/"+t}this.updateString=function(t){this.mac.update(t)},this.updateHex=function(t){var s=CryptoJS.enc.Hex.parse(t);this.mac.update(s)},this.doFinal=function(){return this.mac.finalize().toString(CryptoJS.enc.Hex)},this.doFinalString=function(t){return this.updateString(t),this.doFinal()},this.doFinalHex=function(t){return this.updateHex(t),this.doFinal()}}},this.updateString=function(t){throw"updateString(str) not supported for this alg/prov: "+this.algProv},this.updateHex=function(t){throw"updateHex(hex) not supported for this alg/prov: "+this.algProv},this.doFinal=function(){throw"digest() not supported for this alg/prov: "+this.algProv},this.doFinalString=function(t){throw"digestString(str) not supported for this alg/prov: "+this.algProv},this.doFinalHex=function(t){throw"digestHex(hex) not supported for this alg/prov: "+this.algProv},this.setPassword=function(t){if("string"==typeof t){var s=t;return t.length%2!=1&&t.match(/^[0-9A-Fa-f]+$/)||(s=rstrtohex(t)),void(this.pass=CryptoJS.enc.Hex.parse(s))}if("object"!=typeof t)throw"KJUR.crypto.Mac unsupported password type: "+t;s=null;if(void 0!==t.hex){if(t.hex.length%2!=0||!t.hex.match(/^[0-9A-Fa-f]+$/))throw"Mac: wrong hex password: "+t.hex;s=t.hex}if(void 0!==t.utf8&&(s=utf8tohex(t.utf8)),void 0!==t.rstr&&(s=rstrtohex(t.rstr)),void 0!==t.b64&&(s=b64tohex(t.b64)),void 0!==t.b64u&&(s=b64utohex(t.b64u)),null==s)throw"KJUR.crypto.Mac unsupported password type: "+t;this.pass=CryptoJS.enc.Hex.parse(s)},void 0!==t&&(void 0!==t.pass&&this.setPassword(t.pass),void 0!==t.alg&&(this.algName=t.alg,void 0===t.prov&&(this.provName=KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]),this.setAlgAndProvider(this.algName,this.provName)))},KJUR.crypto.Signature=function(t){var s=null;if(this._setAlgNames=function(){var t=this.algName.match(/^(.+)with(.+)$/);t&&(this.mdAlgName=t[1].toLowerCase(),this.pubkeyAlgName=t[2].toLowerCase())},this._zeroPaddingOfSignature=function(t,s){for(var e="",i=s/4-t.length,r=0;r<i;r++)e+="0";return e+t},this.setAlgAndProvider=function(t,s){if(this._setAlgNames(),"cryptojs/jsrsa"!=s)throw"provider not supported: "+s;if(-1!=":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:".indexOf(this.mdAlgName)){try{this.md=new KJUR.crypto.MessageDigest({alg:this.mdAlgName})}catch(t){throw"setAlgAndProvider hash alg set fail alg="+this.mdAlgName+"/"+t}this.init=function(t,s){var e=null;try{e=void 0===s?KEYUTIL.getKey(t):KEYUTIL.getKey(t,s)}catch(t){throw"init failed:"+t}if(!0===e.isPrivate)this.prvKey=e,this.state="SIGN";else{if(!0!==e.isPublic)throw"init failed.:"+e;this.pubKey=e,this.state="VERIFY"}},this.updateString=function(t){this.md.updateString(t)},this.updateHex=function(t){this.md.updateHex(t)},this.sign=function(){if(this.sHashHex=this.md.digest(),void 0!==this.ecprvhex&&void 0!==this.eccurvename){var t=new KJUR.crypto.ECDSA({curve:this.eccurvename});this.hSign=t.signHex(this.sHashHex,this.ecprvhex)}else if(this.prvKey instanceof RSAKey&&"rsaandmgf1"===this.pubkeyAlgName)this.hSign=this.prvKey.signWithMessageHashPSS(this.sHashHex,this.mdAlgName,this.pssSaltLen);else if(this.prvKey instanceof RSAKey&&"rsa"===this.pubkeyAlgName)this.hSign=this.prvKey.signWithMessageHash(this.sHashHex,this.mdAlgName);else if(this.prvKey instanceof KJUR.crypto.ECDSA)this.hSign=this.prvKey.signWithMessageHash(this.sHashHex);else{if(!(this.prvKey instanceof KJUR.crypto.DSA))throw"Signature: unsupported private key alg: "+this.pubkeyAlgName;this.hSign=this.prvKey.signWithMessageHash(this.sHashHex)}return this.hSign},this.signString=function(t){return this.updateString(t),this.sign()},this.signHex=function(t){return this.updateHex(t),this.sign()},this.verify=function(t){if(this.sHashHex=this.md.digest(),void 0!==this.ecpubhex&&void 0!==this.eccurvename)return new KJUR.crypto.ECDSA({curve:this.eccurvename}).verifyHex(this.sHashHex,t,this.ecpubhex);if(this.pubKey instanceof RSAKey&&"rsaandmgf1"===this.pubkeyAlgName)return this.pubKey.verifyWithMessageHashPSS(this.sHashHex,t,this.mdAlgName,this.pssSaltLen);if(this.pubKey instanceof RSAKey&&"rsa"===this.pubkeyAlgName)return this.pubKey.verifyWithMessageHash(this.sHashHex,t);if(void 0!==KJUR.crypto.ECDSA&&this.pubKey instanceof KJUR.crypto.ECDSA)return this.pubKey.verifyWithMessageHash(this.sHashHex,t);if(void 0!==KJUR.crypto.DSA&&this.pubKey instanceof KJUR.crypto.DSA)return this.pubKey.verifyWithMessageHash(this.sHashHex,t);throw"Signature: unsupported public key alg: "+this.pubkeyAlgName}}},this.init=function(t,s){throw"init(key, pass) not supported for this alg:prov="+this.algProvName},this.updateString=function(t){throw"updateString(str) not supported for this alg:prov="+this.algProvName},this.updateHex=function(t){throw"updateHex(hex) not supported for this alg:prov="+this.algProvName},this.sign=function(){throw"sign() not supported for this alg:prov="+this.algProvName},this.signString=function(t){throw"digestString(str) not supported for this alg:prov="+this.algProvName},this.signHex=function(t){throw"digestHex(hex) not supported for this alg:prov="+this.algProvName},this.verify=function(t){throw"verify(hSigVal) not supported for this alg:prov="+this.algProvName},this.initParams=t,void 0!==t&&(void 0!==t.alg&&(this.algName=t.alg,void 0===t.prov?this.provName=KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]:this.provName=t.prov,this.algProvName=this.algName+":"+this.provName,this.setAlgAndProvider(this.algName,this.provName),this._setAlgNames()),void 0!==t.psssaltlen&&(this.pssSaltLen=t.psssaltlen),void 0!==t.prvkeypem)){if(void 0!==t.prvkeypas)throw"both prvkeypem and prvkeypas parameters not supported";try{s=KEYUTIL.getKey(t.prvkeypem);this.init(s)}catch(t){throw"fatal error to load pem private key: "+t}}},KJUR.crypto.Cipher=function(t){},KJUR.crypto.Cipher.encrypt=function(t,s,e){if(s instanceof RSAKey&&s.isPublic){var i=KJUR.crypto.Cipher.getAlgByKeyAndName(s,e);if("RSA"===i)return s.encrypt(t);if("RSAOAEP"===i)return s.encryptOAEP(t,"sha1");var r=i.match(/^RSAOAEP(\d+)$/);if(null!==r)return s.encryptOAEP(t,"sha"+r[1]);throw"Cipher.encrypt: unsupported algorithm for RSAKey: "+e}throw"Cipher.encrypt: unsupported key or algorithm"},KJUR.crypto.Cipher.decrypt=function(t,s,e){if(s instanceof RSAKey&&s.isPrivate){var i=KJUR.crypto.Cipher.getAlgByKeyAndName(s,e);if("RSA"===i)return s.decrypt(t);if("RSAOAEP"===i)return s.decryptOAEP(t,"sha1");var r=i.match(/^RSAOAEP(\d+)$/);if(null!==r)return s.decryptOAEP(t,"sha"+r[1]);throw"Cipher.decrypt: unsupported algorithm for RSAKey: "+e}throw"Cipher.decrypt: unsupported key or algorithm"},KJUR.crypto.Cipher.getAlgByKeyAndName=function(t,s){if(t instanceof RSAKey){if(-1!=":RSA:RSAOAEP:RSAOAEP224:RSAOAEP256:RSAOAEP384:RSAOAEP512:".indexOf(s))return s;if(null===s||void 0===s)return"RSA";throw"getAlgByKeyAndName: not supported algorithm name for RSAKey: "+s}throw"getAlgByKeyAndName: not supported algorithm name: "+s},KJUR.crypto.OID=new function(){this.oidhex2name={"2a864886f70d010101":"rsaEncryption","2a8648ce3d0201":"ecPublicKey","2a8648ce380401":"dsa","2a8648ce3d030107":"secp256r1","2b8104001f":"secp192k1","2b81040021":"secp224r1","2b8104000a":"secp256k1","2b81040023":"secp521r1","2b81040022":"secp384r1","2a8648ce380403":"SHA1withDSA","608648016503040301":"SHA224withDSA","608648016503040302":"SHA256withDSA"}};
// ecdsa-modified-1.1.1.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE
"undefined"!=typeof KJUR&&KJUR||(KJUR={}),void 0!==KJUR.crypto&&KJUR.crypto||(KJUR.crypto={}),KJUR.crypto.ECDSA=function(e){var t=new SecureRandom;this.type="EC",this.isPrivate=!1,this.isPublic=!1,this.getBigRandom=function(e){return new BigInteger(e.bitLength(),t).mod(e.subtract(BigInteger.ONE)).add(BigInteger.ONE)},this.setNamedCurve=function(e){this.ecparams=KJUR.crypto.ECParameterDB.getByName(e),this.prvKeyHex=null,this.pubKeyHex=null,this.curveName=e},this.setPrivateKeyHex=function(e){this.isPrivate=!0,this.prvKeyHex=e},this.setPublicKeyHex=function(e){this.isPublic=!0,this.pubKeyHex=e},this.getPublicKeyXYHex=function(){var e=this.pubKeyHex;if("04"!==e.substr(0,2))throw"this method supports uncompressed format(04) only";var t=this.ecparams.keylen/4;if(e.length!==2+2*t)throw"malformed public key hex length";var r={};return r.x=e.substr(2,t),r.y=e.substr(2+t),r},this.getShortNISTPCurveName=function(){var e=this.curveName;return"secp256r1"===e||"NIST P-256"===e||"P-256"===e||"prime256v1"===e?"P-256":"secp384r1"===e||"NIST P-384"===e||"P-384"===e?"P-384":null},this.generateKeyPairHex=function(){var e=this.ecparams.n,t=this.getBigRandom(e),r=this.ecparams.G.multiply(t),i=r.getX().toBigInteger(),s=r.getY().toBigInteger(),n=this.ecparams.keylen/4,a=("0000000000"+t.toString(16)).slice(-n),o="04"+("0000000000"+i.toString(16)).slice(-n)+("0000000000"+s.toString(16)).slice(-n);return this.setPrivateKeyHex(a),this.setPublicKeyHex(o),{ecprvhex:a,ecpubhex:o}},this.signWithMessageHash=function(e){return this.signHex(e,this.prvKeyHex)},this.signHex=function(e,t){var r=new BigInteger(t,16),i=this.ecparams.n,s=new BigInteger(e,16);do{var n=this.getBigRandom(i),a=this.ecparams.G.multiply(n).getX().toBigInteger().mod(i)}while(a.compareTo(BigInteger.ZERO)<=0);var o=n.modInverse(i).multiply(s.add(r.multiply(a))).mod(i);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(a,o)},this.sign=function(e,t){var r=t,i=this.ecparams.n,s=BigInteger.fromByteArrayUnsigned(e);do{var n=this.getBigRandom(i),a=this.ecparams.G.multiply(n).getX().toBigInteger().mod(i)}while(a.compareTo(BigInteger.ZERO)<=0);var o=n.modInverse(i).multiply(s.add(r.multiply(a))).mod(i);return this.serializeSig(a,o)},this.verifyWithMessageHash=function(e,t){return this.verifyHex(e,t,this.pubKeyHex)},this.verifyHex=function(e,t,r){var i,s,n,a=KJUR.crypto.ECDSA.parseSigHex(t);i=a.r,s=a.s,n=ECPointFp.decodeFromHex(this.ecparams.curve,r);var o=new BigInteger(e,16);return this.verifyRaw(o,i,s,n)},this.verify=function(e,t,r){var i,s,n;if(Bitcoin.Util.isArray(t)){var a=this.parseSig(t);i=a.r,s=a.s}else{if("object"!=typeof t||!t.r||!t.s)throw"Invalid value for signature";i=t.r,s=t.s}if(r instanceof ECPointFp)n=r;else{if(!Bitcoin.Util.isArray(r))throw"Invalid format for pubkey value, must be byte array or ECPointFp";n=ECPointFp.decodeFrom(this.ecparams.curve,r)}var o=BigInteger.fromByteArrayUnsigned(e);return this.verifyRaw(o,i,s,n)},this.verifyRaw=function(e,t,r,i){var s=this.ecparams.n,n=this.ecparams.G;if(t.compareTo(BigInteger.ONE)<0||t.compareTo(s)>=0)return!1;if(r.compareTo(BigInteger.ONE)<0||r.compareTo(s)>=0)return!1;var a=r.modInverse(s),o=e.multiply(a).mod(s),u=t.multiply(a).mod(s);return n.multiply(o).add(i.multiply(u)).getX().toBigInteger().mod(s).equals(t)},this.serializeSig=function(e,t){var r=e.toByteArraySigned(),i=t.toByteArraySigned(),s=[];return s.push(2),s.push(r.length),(s=s.concat(r)).push(2),s.push(i.length),(s=s.concat(i)).unshift(s.length),s.unshift(48),s},this.parseSig=function(e){var t;if(48!=e[0])throw new Error("Signature not a valid DERSequence");if(2!=e[t=2])throw new Error("First element in signature must be a DERInteger");var r=e.slice(t+2,t+2+e[t+1]);if(2!=e[t+=2+e[t+1]])throw new Error("Second element in signature must be a DERInteger");var i=e.slice(t+2,t+2+e[t+1]);return t+=2+e[t+1],{r:BigInteger.fromByteArrayUnsigned(r),s:BigInteger.fromByteArrayUnsigned(i)}},this.parseSigCompact=function(e){if(65!==e.length)throw"Signature has the wrong length";var t=e[0]-27;if(t<0||t>7)throw"Invalid signature type";var r=this.ecparams.n;return{r:BigInteger.fromByteArrayUnsigned(e.slice(1,33)).mod(r),s:BigInteger.fromByteArrayUnsigned(e.slice(33,65)).mod(r),i:t}},this.readPKCS5PrvKeyHex=function(e){var t,r,i,s=ASN1HEX,n=KJUR.crypto.ECDSA.getName,a=s.getVbyList;if(!1===s.isASN1HEX(e))throw"not ASN.1 hex string";try{t=a(e,0,[2,0],"06"),r=a(e,0,[1],"04");try{i=a(e,0,[3,0],"03").substr(2)}catch(e){}}catch(e){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=n(t),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i),this.setPrivateKeyHex(r),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(e){var t,r,i,s=ASN1HEX,n=KJUR.crypto.ECDSA.getName,a=s.getVbyList;if(!1===s.isASN1HEX(e))throw"not ASN.1 hex string";try{a(e,0,[1,0],"06"),t=a(e,0,[1,1],"06"),r=a(e,0,[2,0,1],"04");try{i=a(e,0,[2,0,2,0],"03").substr(2)}catch(e){}}catch(e){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=n(t),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i),this.setPrivateKeyHex(r),this.isPublic=!1},this.readPKCS8PubKeyHex=function(e){var t,r,i=ASN1HEX,s=KJUR.crypto.ECDSA.getName,n=i.getVbyList;if(!1===i.isASN1HEX(e))throw"not ASN.1 hex string";try{n(e,0,[0,0],"06"),t=n(e,0,[0,1],"06"),r=n(e,0,[1],"03").substr(2)}catch(e){throw"malformed PKCS#8 ECC public key"}if(this.curveName=s(t),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(r)},this.readCertPubKeyHex=function(e,t){5!==t&&(t=6);var r,i,s=ASN1HEX,n=KJUR.crypto.ECDSA.getName,a=s.getVbyList;if(!1===s.isASN1HEX(e))throw"not ASN.1 hex string";try{r=a(e,0,[0,t,0,1],"06"),i=a(e,0,[0,t,1],"03").substr(2)}catch(e){throw"malformed X.509 certificate ECC public key"}if(this.curveName=n(r),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},void 0!==e&&void 0!==e.curve&&(this.curveName=e.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==e&&(void 0!==e.prv&&this.setPrivateKeyHex(e.prv),void 0!==e.pub&&this.setPublicKeyHex(e.pub))},KJUR.crypto.ECDSA.parseSigHex=function(e){var t=KJUR.crypto.ECDSA.parseSigHexInHexRS(e);return{r:new BigInteger(t.r,16),s:new BigInteger(t.s,16)}},KJUR.crypto.ECDSA.parseSigHexInHexRS=function(e){var t=ASN1HEX,r=t.getChildIdx,i=t.getV;if("30"!=e.substr(0,2))throw"signature is not a ASN.1 sequence";var s=r(e,0);if(2!=s.length)throw"number of signature ASN.1 sequence elements seem wrong";var n=s[0],a=s[1];if("02"!=e.substr(n,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=e.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:i(e,n),s:i(e,a)}},KJUR.crypto.ECDSA.asn1SigToConcatSig=function(e){var t=KJUR.crypto.ECDSA.parseSigHexInHexRS(e),r=t.r,i=t.s;if("00"==r.substr(0,2)&&r.length%32==2&&(r=r.substr(2)),"00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),r.length%32==30&&(r="00"+r),i.length%32==30&&(i="00"+i),r.length%32!=0)throw"unknown ECDSA sig r length error";if(i.length%32!=0)throw"unknown ECDSA sig s length error";return r+i},KJUR.crypto.ECDSA.concatSigToASN1Sig=function(e){if(e.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var t=e.substr(0,e.length/2),r=e.substr(e.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(t,r)},KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(e,t){var r=new BigInteger(e,16),i=new BigInteger(t,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(r,i)},KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(e,t){var r=KJUR.asn1,i=new r.DERInteger({bigint:e}),s=new r.DERInteger({bigint:t});return new r.DERSequence({array:[i,s]}).getEncodedHex()},KJUR.crypto.ECDSA.getName=function(e){return"2a8648ce3d030107"===e?"secp256r1":"2b8104000a"===e?"secp256k1":"2b81040022"===e?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(e)?"secp256r1":-1!=="|secp256k1|".indexOf(e)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(e)?"secp384r1":null};
// ecparam-1.0.0.js (c) 2013 Kenji Urushima | kjur.github.com/jsrsasign/license
"undefined"!=typeof KJUR&&KJUR||(KJUR={}),void 0!==KJUR.crypto&&KJUR.crypto||(KJUR.crypto={}),KJUR.crypto.ECParameterDB=new function(){var F={},B={};function E(F){return new BigInteger(F,16)}this.getByName=function(E){var C=E;if(void 0!==B[C]&&(C=B[E]),void 0!==F[C])return F[C];throw"unregistered EC curve name: "+C},this.regist=function(C,D,A,e,r,t,c,a,i,p,o,s){F[C]={};var d=E(A),f=E(e),n=E(r),m=E(t),P=E(c),v=new ECCurveFp(d,f,n),y=v.decodePointHex("04"+a+i);F[C].name=C,F[C].keylen=D,F[C].curve=v,F[C].G=y,F[C].n=m,F[C].h=P,F[C].oid=o,F[C].info=s;for(var J=0;J<p.length;J++)B[p[J]]=C}},KJUR.crypto.ECParameterDB.regist("secp128r1",128,"FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF","FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC","E87579C11079F43DD824993C2CEE5ED3","FFFFFFFE0000000075A30D1B9038A115","1","161FF7528B899B2D0C28607CA52C5B86","CF5AC8395BAFEB13C02DA292DDED7A83",[],"","secp128r1 : SECG curve over a 128 bit prime field"),KJUR.crypto.ECParameterDB.regist("secp160k1",160,"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73","0","7","0100000000000000000001B8FA16DFAB9ACA16B6B3","1","3B4C382CE37AA192A4019E763036F4F5DD4D7EBB","938CF935318FDCED6BC28286531733C3F03C4FEE",[],"","secp160k1 : SECG curve over a 160 bit prime field"),KJUR.crypto.ECParameterDB.regist("secp160r1",160,"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC","1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45","0100000000000000000001F4C8F927AED3CA752257","1","4A96B5688EF573284664698968C38BB913CBFC82","23A628553168947D59DCC912042351377AC5FB32",[],"","secp160r1 : SECG curve over a 160 bit prime field"),KJUR.crypto.ECParameterDB.regist("secp192k1",192,"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37","0","3","FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D","1","DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D","9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D",[]),KJUR.crypto.ECParameterDB.regist("secp192r1",192,"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC","64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1","FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831","1","188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012","07192B95FFC8DA78631011ED6B24CDD573F977A11E794811",[]),KJUR.crypto.ECParameterDB.regist("secp224r1",224,"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE","B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4","FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D","1","B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21","BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34",[]),KJUR.crypto.ECParameterDB.regist("secp256k1",256,"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F","0","7","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141","1","79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798","483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8",[]),KJUR.crypto.ECParameterDB.regist("secp256r1",256,"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF","FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC","5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B","FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551","1","6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296","4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5",["NIST P-256","P-256","prime256v1"]),KJUR.crypto.ECParameterDB.regist("secp384r1",384,"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC","B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973","1","AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7","3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f",["NIST P-384","P-384"]),KJUR.crypto.ECParameterDB.regist("secp521r1",521,"1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC","051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00","1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409","1","C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66","011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650",["NIST P-521","P-521"]);
// keyutil-1.2.0.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
var KEYUTIL=function(){var e=function(e,r,i){return t(CryptoJS.AES,e,r,i)},t=function(e,t,r,i){var n=CryptoJS.enc.Hex.parse(t),o=CryptoJS.enc.Hex.parse(r),a=CryptoJS.enc.Hex.parse(i),d={};d.key=o,d.iv=a,d.ciphertext=n;var c=e.decrypt(d,o,{iv:a});return CryptoJS.enc.Hex.stringify(c)},r=function(e,t,r){return i(CryptoJS.AES,e,t,r)},i=function(e,t,r,i){var n=CryptoJS.enc.Hex.parse(t),o=CryptoJS.enc.Hex.parse(r),a=CryptoJS.enc.Hex.parse(i),d=e.encrypt(n,o,{iv:a}),c=CryptoJS.enc.Hex.parse(d.toString());return CryptoJS.enc.Base64.stringify(c)},n={"AES-256-CBC":{proc:e,eproc:r,keylen:32,ivlen:16},"AES-192-CBC":{proc:e,eproc:r,keylen:24,ivlen:16},"AES-128-CBC":{proc:e,eproc:r,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(e,r,i){return t(CryptoJS.TripleDES,e,r,i)},eproc:function(e,t,r){return i(CryptoJS.TripleDES,e,t,r)},keylen:24,ivlen:8},"DES-CBC":{proc:function(e,r,i){return t(CryptoJS.DES,e,r,i)},eproc:function(e,t,r){return i(CryptoJS.DES,e,t,r)},keylen:8,ivlen:8}},o=function(e){var t={},r=e.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));r&&(t.cipher=r[1],t.ivsalt=r[2]);var i=e.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));i&&(t.type=i[1]);var n=-1,o=0;-1!=e.indexOf("\r\n\r\n")&&(n=e.indexOf("\r\n\r\n"),o=2),-1!=e.indexOf("\n\n")&&(n=e.indexOf("\n\n"),o=1);var a=e.indexOf("-----END");if(-1!=n&&-1!=a){var d=e.substring(n+2*o,a-o);d=d.replace(/\s+/g,""),t.data=d}return t},a=function(e,t,r){for(var i=r.substring(0,16),o=CryptoJS.enc.Hex.parse(i),a=CryptoJS.enc.Utf8.parse(t),d=n[e].keylen+n[e].ivlen,c="",u=null;;){var p=CryptoJS.algo.MD5.create();if(null!=u&&p.update(u),p.update(a),p.update(o),u=p.finalize(),(c+=CryptoJS.enc.Hex.stringify(u)).length>=2*d)break}var v={};return v.keyhex=c.substr(0,2*n[e].keylen),v.ivhex=c.substr(2*n[e].keylen,2*n[e].ivlen),v},d=function(e,t,r,i){var o=CryptoJS.enc.Base64.parse(e),a=CryptoJS.enc.Hex.stringify(o);return(0,n[t].proc)(a,r,i)};return{version:"1.0.0",parsePKCS5PEM:function(e){return o(e)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(e,t,r){return a(e,t,r)},decryptKeyB64:function(e,t,r,i){return d(e,t,r,i)},getDecryptedKeyHex:function(e,t){var r=o(e),i=(r.type,r.cipher),n=r.ivsalt,c=r.data,u=a(i,t,n).keyhex;return d(c,i,u,n)},getEncryptedPKCS5PEMFromPrvKeyHex:function(e,t,r,i,o){var d,c,u="";if(void 0!==i&&null!=i||(i="AES-256-CBC"),void 0===n[i])throw"KEYUTIL unsupported algorithm: "+i;if(void 0===o||null==o){var p=n[i].ivlen;o=(d=p,c=CryptoJS.lib.WordArray.random(d),CryptoJS.enc.Hex.stringify(c)).toUpperCase()}var v,s,f,E=a(i,r,o).keyhex;u="-----BEGIN "+e+" PRIVATE KEY-----\r\n";return u+="Proc-Type: 4,ENCRYPTED\r\n",u+="DEK-Info: "+i+","+o+"\r\n",u+="\r\n",u+=(v=t,s=E,f=o,(0,n[i].eproc)(v,s,f)).replace(/(.{64})/g,"$1\r\n"),u+="\r\n-----END "+e+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(e){var t=ASN1HEX,r=t.getChildIdx,i=t.getV,n={},o=r(e,0);if(2!=o.length)throw"malformed format: SEQUENCE(0).items != 2: "+o.length;n.ciphertext=i(e,o[1]);var a=r(e,o[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=i(e,a[0]))throw"this only supports pkcs5PBES2";var d=r(e,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+d.length;var c=r(e,d[1]);if(2!=c.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+c.length;if("2a864886f70d0307"!=i(e,c[0]))throw"this only supports TripleDES";n.encryptionSchemeAlg="TripleDES",n.encryptionSchemeIV=i(e,c[1]);var u=r(e,d[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=i(e,u[0]))throw"this only supports pkcs5PBKDF2";var p=r(e,u[1]);if(p.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+p.length;n.pbkdf2Salt=i(e,p[0]);var v=i(e,p[1]);try{n.pbkdf2Iter=parseInt(v,16)}catch(e){throw"malformed format pbkdf2Iter: "+v}return n},getPBKDF2KeyHexFromParam:function(e,t){var r=CryptoJS.enc.Hex.parse(e.pbkdf2Salt),i=e.pbkdf2Iter,n=CryptoJS.PBKDF2(t,r,{keySize:6,iterations:i});return CryptoJS.enc.Hex.stringify(n)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(e,t){var r=pemtohex(e,"ENCRYPTED PRIVATE KEY"),i=this.parseHexOfEncryptedPKCS8(r),n=KEYUTIL.getPBKDF2KeyHexFromParam(i,t),o={};o.ciphertext=CryptoJS.enc.Hex.parse(i.ciphertext);var a=CryptoJS.enc.Hex.parse(n),d=CryptoJS.enc.Hex.parse(i.encryptionSchemeIV),c=CryptoJS.TripleDES.decrypt(o,a,{iv:d});return CryptoJS.enc.Hex.stringify(c)},getKeyFromEncryptedPKCS8PEM:function(e,t){var r=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(e,t);return this.getKeyFromPlainPrivatePKCS8Hex(r)},parsePlainPrivatePKCS8Hex:function(e){var t=ASN1HEX,r=t.getChildIdx,i=t.getV,n={};if(n.algparam=null,"30"!=e.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var o=r(e,0);if(3!=o.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=e.substr(o[1],2))throw"malformed PKCS8 private key(code:003)";var a=r(e,o[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=e.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(n.algoid=i(e,a[0]),"06"==e.substr(a[1],2)&&(n.algparam=i(e,a[1])),"04"!=e.substr(o[2],2))throw"malformed PKCS8 private key(code:006)";return n.keyidx=t.getVidx(e,o[2]),n},getKeyFromPlainPrivatePKCS8PEM:function(e){var t=pemtohex(e,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(t)},getKeyFromPlainPrivatePKCS8Hex:function(e){var t,r=this.parsePlainPrivatePKCS8Hex(e);if("2a864886f70d010101"==r.algoid)t=new RSAKey;else if("2a8648ce380401"==r.algoid)t=new KJUR.crypto.DSA;else{if("2a8648ce3d0201"!=r.algoid)throw"unsupported private key algorithm";t=new KJUR.crypto.ECDSA}return t.readPKCS8PrvKeyHex(e),t},_getKeyFromPublicPKCS8Hex:function(e){var t,r=ASN1HEX.getVbyList(e,0,[0,0],"06");if("2a864886f70d010101"===r)t=new RSAKey;else if("2a8648ce380401"===r)t=new KJUR.crypto.DSA;else{if("2a8648ce3d0201"!==r)throw"unsupported PKCS#8 public key hex";t=new KJUR.crypto.ECDSA}return t.readPKCS8PubKeyHex(e),t},parsePublicRawRSAKeyHex:function(e){var t=ASN1HEX,r=t.getChildIdx,i=t.getV,n={};if("30"!=e.substr(0,2))throw"malformed RSA key(code:001)";var o=r(e,0);if(2!=o.length)throw"malformed RSA key(code:002)";if("02"!=e.substr(o[0],2))throw"malformed RSA key(code:003)";if(n.n=i(e,o[0]),"02"!=e.substr(o[1],2))throw"malformed RSA key(code:004)";return n.e=i(e,o[1]),n},parsePublicPKCS8Hex:function(e){var t=ASN1HEX,r=t.getChildIdx,i=t.getV,n={algparam:null},o=r(e,0);if(2!=o.length)throw"outer DERSequence shall have 2 elements: "+o.length;var a=o[0];if("30"!=e.substr(a,2))throw"malformed PKCS8 public key(code:001)";var d=r(e,a);if(2!=d.length)throw"malformed PKCS8 public key(code:002)";if("06"!=e.substr(d[0],2))throw"malformed PKCS8 public key(code:003)";if(n.algoid=i(e,d[0]),"06"==e.substr(d[1],2)?n.algparam=i(e,d[1]):"30"==e.substr(d[1],2)&&(n.algparam={},n.algparam.p=t.getVbyList(e,d[1],[0],"02"),n.algparam.q=t.getVbyList(e,d[1],[1],"02"),n.algparam.g=t.getVbyList(e,d[1],[2],"02")),"03"!=e.substr(o[1],2))throw"malformed PKCS8 public key(code:004)";return n.key=i(e,o[1]).substr(2),n}}}();KEYUTIL.getKey=function(e,t,r){var i=(x=ASN1HEX).getChildIdx,n=(x.getV,x.getVbyList),o=KJUR.crypto,a=o.ECDSA,d=o.DSA,c=RSAKey,u=pemtohex,p=KEYUTIL;if(void 0!==c&&e instanceof c)return e;if(void 0!==a&&e instanceof a)return e;if(void 0!==d&&e instanceof d)return e;if(void 0!==e.curve&&void 0!==e.xy&&void 0===e.d)return new a({pub:e.xy,curve:e.curve});if(void 0!==e.curve&&void 0!==e.d)return new a({prv:e.d,curve:e.curve});if(void 0===e.kty&&void 0!==e.n&&void 0!==e.e&&void 0===e.d)return(A=new c).setPublic(e.n,e.e),A;if(void 0===e.kty&&void 0!==e.n&&void 0!==e.e&&void 0!==e.d&&void 0!==e.p&&void 0!==e.q&&void 0!==e.dp&&void 0!==e.dq&&void 0!==e.co&&void 0===e.qi)return(A=new c).setPrivateEx(e.n,e.e,e.d,e.p,e.q,e.dp,e.dq,e.co),A;if(void 0===e.kty&&void 0!==e.n&&void 0!==e.e&&void 0!==e.d&&void 0===e.p)return(A=new c).setPrivate(e.n,e.e,e.d),A;if(void 0!==e.p&&void 0!==e.q&&void 0!==e.g&&void 0!==e.y&&void 0===e.x)return(A=new d).setPublic(e.p,e.q,e.g,e.y),A;if(void 0!==e.p&&void 0!==e.q&&void 0!==e.g&&void 0!==e.y&&void 0!==e.x)return(A=new d).setPrivate(e.p,e.q,e.g,e.y,e.x),A;if("RSA"===e.kty&&void 0!==e.n&&void 0!==e.e&&void 0===e.d)return(A=new c).setPublic(b64utohex(e.n),b64utohex(e.e)),A;if("RSA"===e.kty&&void 0!==e.n&&void 0!==e.e&&void 0!==e.d&&void 0!==e.p&&void 0!==e.q&&void 0!==e.dp&&void 0!==e.dq&&void 0!==e.qi)return(A=new c).setPrivateEx(b64utohex(e.n),b64utohex(e.e),b64utohex(e.d),b64utohex(e.p),b64utohex(e.q),b64utohex(e.dp),b64utohex(e.dq),b64utohex(e.qi)),A;if("RSA"===e.kty&&void 0!==e.n&&void 0!==e.e&&void 0!==e.d)return(A=new c).setPrivate(b64utohex(e.n),b64utohex(e.e),b64utohex(e.d)),A;if("EC"===e.kty&&void 0!==e.crv&&void 0!==e.x&&void 0!==e.y&&void 0===e.d){var v=(R=new a({curve:e.crv})).ecparams.keylen/4,s="04"+("0000000000"+b64utohex(e.x)).slice(-v)+("0000000000"+b64utohex(e.y)).slice(-v);return R.setPublicKeyHex(s),R}if("EC"===e.kty&&void 0!==e.crv&&void 0!==e.x&&void 0!==e.y&&void 0!==e.d){v=(R=new a({curve:e.crv})).ecparams.keylen/4,s="04"+("0000000000"+b64utohex(e.x)).slice(-v)+("0000000000"+b64utohex(e.y)).slice(-v);var f=("0000000000"+b64utohex(e.d)).slice(-v);return R.setPublicKeyHex(s),R.setPrivateKeyHex(f),R}if("pkcs5prv"===r){var E,y=e,x=ASN1HEX;if(9===(E=i(y,0)).length)(A=new c).readPKCS5PrvKeyHex(y);else if(6===E.length)(A=new d).readPKCS5PrvKeyHex(y);else{if(!(E.length>2&&"04"===y.substr(E[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(A=new a).readPKCS5PrvKeyHex(y)}return A}if("pkcs8prv"===r)return A=p.getKeyFromPlainPrivatePKCS8Hex(e);if("pkcs8pub"===r)return p._getKeyFromPublicPKCS8Hex(e);if("x509pub"===r)return X509.getPublicKeyFromCertHex(e);if(-1!=e.indexOf("-END CERTIFICATE-",0)||-1!=e.indexOf("-END X509 CERTIFICATE-",0)||-1!=e.indexOf("-END TRUSTED CERTIFICATE-",0))return X509.getPublicKeyFromCertPEM(e);if(-1!=e.indexOf("-END PUBLIC KEY-")){var P=pemtohex(e,"PUBLIC KEY");return p._getKeyFromPublicPKCS8Hex(P)}if(-1!=e.indexOf("-END RSA PRIVATE KEY-")&&-1==e.indexOf("4,ENCRYPTED")){var S=u(e,"RSA PRIVATE KEY");return p.getKey(S,null,"pkcs5prv")}if(-1!=e.indexOf("-END DSA PRIVATE KEY-")&&-1==e.indexOf("4,ENCRYPTED")){var l=n(I=u(e,"DSA PRIVATE KEY"),0,[1],"02"),g=n(I,0,[2],"02"),K=n(I,0,[3],"02"),C=n(I,0,[4],"02"),h=n(I,0,[5],"02");return(A=new d).setPrivate(new BigInteger(l,16),new BigInteger(g,16),new BigInteger(K,16),new BigInteger(C,16),new BigInteger(h,16)),A}if(-1!=e.indexOf("-END PRIVATE KEY-"))return p.getKeyFromPlainPrivatePKCS8PEM(e);if(-1!=e.indexOf("-END RSA PRIVATE KEY-")&&-1!=e.indexOf("4,ENCRYPTED")){var m=p.getDecryptedKeyHex(e,t),b=new RSAKey;return b.readPKCS5PrvKeyHex(m),b}if(-1!=e.indexOf("-END EC PRIVATE KEY-")&&-1!=e.indexOf("4,ENCRYPTED")){var R,A=n(I=p.getDecryptedKeyHex(e,t),0,[1],"04"),H=n(I,0,[2,0],"06"),w=n(I,0,[3,0],"03").substr(2);if(void 0===KJUR.crypto.OID.oidhex2name[H])throw"undefined OID(hex) in KJUR.crypto.OID: "+H;return(R=new a({curve:KJUR.crypto.OID.oidhex2name[H]})).setPublicKeyHex(w),R.setPrivateKeyHex(A),R.isPublic=!1,R}if(-1!=e.indexOf("-END DSA PRIVATE KEY-")&&-1!=e.indexOf("4,ENCRYPTED")){var I;l=n(I=p.getDecryptedKeyHex(e,t),0,[1],"02"),g=n(I,0,[2],"02"),K=n(I,0,[3],"02"),C=n(I,0,[4],"02"),h=n(I,0,[5],"02");return(A=new d).setPrivate(new BigInteger(l,16),new BigInteger(g,16),new BigInteger(K,16),new BigInteger(C,16),new BigInteger(h,16)),A}if(-1!=e.indexOf("-END ENCRYPTED PRIVATE KEY-"))return p.getKeyFromEncryptedPKCS8PEM(e,t);throw"not supported argument"},KEYUTIL.generateKeypair=function(e,t){if("RSA"==e){var r=t;(a=new RSAKey).generate(r,"10001"),a.isPrivate=!0,a.isPublic=!0;var i=new RSAKey,n=a.n.toString(16),o=a.e.toString(16);return i.setPublic(n,o),i.isPrivate=!1,i.isPublic=!0,(d={}).prvKeyObj=a,d.pubKeyObj=i,d}if("EC"==e){var a,d,c=t,u=new KJUR.crypto.ECDSA({curve:c}).generateKeyPairHex();return(a=new KJUR.crypto.ECDSA({curve:c})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(i=new KJUR.crypto.ECDSA({curve:c})).setPublicKeyHex(u.ecpubhex),i.isPrivate=!1,i.isPublic=!0,(d={}).prvKeyObj=a,d.pubKeyObj=i,d}throw"unknown algorithm: "+e},KEYUTIL.getPEM=function(e,t,r,i,n,o){var a=KJUR,d=a.asn1,c=d.DERObjectIdentifier,u=d.DERInteger,p=d.ASN1Util.newObject,v=d.x509.SubjectPublicKeyInfo,s=a.crypto,f=s.DSA,E=s.ECDSA,y=RSAKey;function x(e){return p({seq:[{int:0},{int:{bigint:e.n}},{int:e.e},{int:{bigint:e.d}},{int:{bigint:e.p}},{int:{bigint:e.q}},{int:{bigint:e.dmp1}},{int:{bigint:e.dmq1}},{int:{bigint:e.coeff}}]})}function P(e){return p({seq:[{int:1},{octstr:{hex:e.prvKeyHex}},{tag:["a0",!0,{oid:{name:e.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+e.pubKeyHex}}]}]})}function S(e){return p({seq:[{int:0},{int:{bigint:e.p}},{int:{bigint:e.q}},{int:{bigint:e.g}},{int:{bigint:e.y}},{int:{bigint:e.x}}]})}if((void 0!==y&&e instanceof y||void 0!==f&&e instanceof f||void 0!==E&&e instanceof E)&&1==e.isPublic&&(void 0===t||"PKCS8PUB"==t)){var l=new v(e).getEncodedHex();return hextopem(l,"PUBLIC KEY")}if("PKCS1PRV"==t&&void 0!==y&&e instanceof y&&(void 0===r||null==r)&&1==e.isPrivate){l=x(e).getEncodedHex();return hextopem(l,"RSA PRIVATE KEY")}if("PKCS1PRV"==t&&void 0!==E&&e instanceof E&&(void 0===r||null==r)&&1==e.isPrivate){var g=new c({name:e.curveName}).getEncodedHex(),K=P(e).getEncodedHex(),C="";return C+=hextopem(g,"EC PARAMETERS"),C+=hextopem(K,"EC PRIVATE KEY")}if("PKCS1PRV"==t&&void 0!==f&&e instanceof f&&(void 0===r||null==r)&&1==e.isPrivate){l=S(e).getEncodedHex();return hextopem(l,"DSA PRIVATE KEY")}if("PKCS5PRV"==t&&void 0!==y&&e instanceof y&&void 0!==r&&null!=r&&1==e.isPrivate){l=x(e).getEncodedHex();return void 0===i&&(i="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",l,r,i,o)}if("PKCS5PRV"==t&&void 0!==E&&e instanceof E&&void 0!==r&&null!=r&&1==e.isPrivate){l=P(e).getEncodedHex();return void 0===i&&(i="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",l,r,i,o)}if("PKCS5PRV"==t&&void 0!==f&&e instanceof f&&void 0!==r&&null!=r&&1==e.isPrivate){l=S(e).getEncodedHex();return void 0===i&&(i="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",l,r,i,o)}var h=function(e,t){var r=m(e,t);return new p({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:r.pbkdf2Salt}},{int:r.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:r.encryptionSchemeIV}}]}]}]},{octstr:{hex:r.ciphertext}}]}).getEncodedHex()},m=function(e,t){var r=CryptoJS.lib.WordArray.random(8),i=CryptoJS.lib.WordArray.random(8),n=CryptoJS.PBKDF2(t,r,{keySize:6,iterations:100}),o=CryptoJS.enc.Hex.parse(e),a=CryptoJS.TripleDES.encrypt(o,n,{iv:i})+"",d={};return d.ciphertext=a,d.pbkdf2Salt=CryptoJS.enc.Hex.stringify(r),d.pbkdf2Iter=100,d.encryptionSchemeAlg="DES-EDE3-CBC",d.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(i),d};if("PKCS8PRV"==t&&void 0!=y&&e instanceof y&&1==e.isPrivate){var b=x(e).getEncodedHex();l=p({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:b}}]}).getEncodedHex();if(void 0===r||null==r)return hextopem(l,"PRIVATE KEY");K=h(l,r);return hextopem(K,"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==t&&void 0!==E&&e instanceof E&&1==e.isPrivate){b=new p({seq:[{int:1},{octstr:{hex:e.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+e.pubKeyHex}}]}]}).getEncodedHex(),l=p({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:e.curveName}}]},{octstr:{hex:b}}]}).getEncodedHex();if(void 0===r||null==r)return hextopem(l,"PRIVATE KEY");K=h(l,r);return hextopem(K,"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==t&&void 0!==f&&e instanceof f&&1==e.isPrivate){b=new u({bigint:e.x}).getEncodedHex(),l=p({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:e.p}},{int:{bigint:e.q}},{int:{bigint:e.g}}]}]},{octstr:{hex:b}}]}).getEncodedHex();if(void 0===r||null==r)return hextopem(l,"PRIVATE KEY");K=h(l,r);return hextopem(K,"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},KEYUTIL.getKeyFromCSRPEM=function(e){var t=pemtohex(e,"CERTIFICATE REQUEST");return KEYUTIL.getKeyFromCSRHex(t)},KEYUTIL.getKeyFromCSRHex=function(e){var t=KEYUTIL.parseCSRHex(e);return KEYUTIL.getKey(t.p8pubkeyhex,null,"pkcs8pub")},KEYUTIL.parseCSRHex=function(e){var t=ASN1HEX,r=t.getChildIdx,i=t.getTLV,n={},o=e;if("30"!=o.substr(0,2))throw"malformed CSR(code:001)";var a=r(o,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=o.substr(a[0],2))throw"malformed CSR(code:003)";var d=r(o,a[0]);if(d.length<3)throw"malformed CSR(code:004)";return n.p8pubkeyhex=i(o,d[2]),n},KEYUTIL.getJWKFromKey=function(e){var t={};if(e instanceof RSAKey&&e.isPrivate)return t.kty="RSA",t.n=hextob64u(e.n.toString(16)),t.e=hextob64u(e.e.toString(16)),t.d=hextob64u(e.d.toString(16)),t.p=hextob64u(e.p.toString(16)),t.q=hextob64u(e.q.toString(16)),t.dp=hextob64u(e.dmp1.toString(16)),t.dq=hextob64u(e.dmq1.toString(16)),t.qi=hextob64u(e.coeff.toString(16)),t;if(e instanceof RSAKey&&e.isPublic)return t.kty="RSA",t.n=hextob64u(e.n.toString(16)),t.e=hextob64u(e.e.toString(16)),t;if(e instanceof KJUR.crypto.ECDSA&&e.isPrivate){if("P-256"!==(i=e.getShortNISTPCurveName())&&"P-384"!==i)throw"unsupported curve name for JWT: "+i;var r=e.getPublicKeyXYHex();return t.kty="EC",t.crv=i,t.x=hextob64u(r.x),t.y=hextob64u(r.y),t.d=hextob64u(e.prvKeyHex),t}if(e instanceof KJUR.crypto.ECDSA&&e.isPublic){var i;if("P-256"!==(i=e.getShortNISTPCurveName())&&"P-384"!==i)throw"unsupported curve name for JWT: "+i;r=e.getPublicKeyXYHex();return t.kty="EC",t.crv=i,t.x=hextob64u(r.x),t.y=hextob64u(r.y),t}throw"not supported key object"};
// discuss at: http://locutus.io/php/pack/
function pack(r){for(var e,o,n,a,t,g,h,i,f,c,s,w,C,l,d,p,m,k,u,S,b,y,E=0,W=1,T="",v="",A=0,M=[];E<r.length;){for(e=r.charAt(E),o="",E++;E<r.length&&null!==r.charAt(E).match(/[\d*]/);)o+=r.charAt(E),E++;switch(""===o&&(o="1"),e){case"a":case"A":if(void 0===arguments[W])throw new Error("Warning: pack() Type "+e+": not enough arguments");for(v=String(arguments[W]),"*"===o&&(o=v.length),A=0;A<o;A++)void 0===v[A]?T+="a"===e?String.fromCharCode(0):" ":T+=v[A];W++;break;case"h":case"H":if(void 0===arguments[W])throw new Error("Warning: pack() Type "+e+": not enough arguments");if(v=arguments[W],"*"===o&&(o=v.length),o>v.length)throw new Error("Warning: pack() Type "+e+": not enough characters in string");for(A=0;A<o;A+=2)n=v[A],A+1>=o||void 0===v[A+1]?n+="0":n+=v[A+1],"h"===e&&(n=n[1]+n[0]),T+=String.fromCharCode(parseInt(n,16));W++;break;case"c":case"C":if("*"===o&&(o=arguments.length-W),o>arguments.length-W)throw new Error("Warning: pack() Type "+e+": too few arguments");for(A=0;A<o;A++)T+=String.fromCharCode(arguments[W]),W++;break;case"s":case"S":case"v":if("*"===o&&(o=arguments.length-W),o>arguments.length-W)throw new Error("Warning: pack() Type "+e+": too few arguments");for(A=0;A<o;A++)T+=String.fromCharCode(255&arguments[W]),T+=String.fromCharCode(arguments[W]>>8&255),W++;break;case"n":if("*"===o&&(o=arguments.length-W),o>arguments.length-W)throw new Error("Warning: pack() Type "+e+": too few arguments");for(A=0;A<o;A++)T+=String.fromCharCode(arguments[W]>>8&255),T+=String.fromCharCode(255&arguments[W]),W++;break;case"i":case"I":case"l":case"L":case"V":if("*"===o&&(o=arguments.length-W),o>arguments.length-W)throw new Error("Warning: pack() Type "+e+": too few arguments");for(A=0;A<o;A++)T+=String.fromCharCode(255&arguments[W]),T+=String.fromCharCode(arguments[W]>>8&255),T+=String.fromCharCode(arguments[W]>>16&255),T+=String.fromCharCode(arguments[W]>>24&255),W++;break;case"N":if("*"===o&&(o=arguments.length-W),o>arguments.length-W)throw new Error("Warning: pack() Type "+e+": too few arguments");for(A=0;A<o;A++)T+=String.fromCharCode(arguments[W]>>24&255),T+=String.fromCharCode(arguments[W]>>16&255),T+=String.fromCharCode(arguments[W]>>8&255),T+=String.fromCharCode(255&arguments[W]),W++;break;case"f":case"d":if(a=23,t=8,"d"===e&&(a=52,t=11),"*"===o&&(o=arguments.length-W),o>arguments.length-W)throw new Error("Warning: pack() Type "+e+": too few arguments");for(A=0;A<o;A++){for(v=arguments[W],f=h=Math.pow(2,t-1)-1,(i=1-h)-a,c=isNaN(d=parseFloat(v))||d===-1/0||d===1/0?d:0,s=0,w=2*h+1+a+3,C=new Array(w),l=(d=0!==c?0:d)<0,m=(d=Math.abs(d))-(p=Math.floor(d)),b=w;b;)C[--b]=0;for(b=h+2;p&&b;)C[--b]=p%2,p=Math.floor(p/2);for(b=h+1;m>0&&b;--m)C[++b]=((m*=2)>=1)-0;for(b=-1;++b<w&&!C[b];);if(C[(k=a-1+(b=(s=h+1-b)>=i&&s<=f?b+1:h+1-(s=i-1)))+1]){if(!(u=C[k]))for(S=k+2;!u&&S<w;u=C[S++]);for(S=k+1;u&&--S>=0;(C[S]=!C[S]-0)&&(u=0));}for(b=b-2<0?-1:b-3;++b<w&&!C[b];);for((s=h+1-b)>=i&&s<=f?++b:s<i&&(b=h+1-(s=i-1)),(p||0!==c)&&(s=f+1,b=h+2,c===-1/0?l=1:isNaN(c)&&(C[b]=1)),d=Math.abs(s+h),y="",S=t+1;--S;)y=d%2+y,d=d>>=1;for(d=0,S=0,b=(y=(l?"1":"0")+y+C.slice(b,b+a).join("")).length,M=[];b;)d+=(1<<S)*y.charAt(--b),7===S&&(M[M.length]=String.fromCharCode(d),d=0),S=(S+1)%8;M[M.length]=d?String.fromCharCode(d):"",T+=M.join(""),W++}break;case"x":if("*"===o)throw new Error("Warning: pack(): Type x: '*' ignored");for(A=0;A<o;A++)T+=String.fromCharCode(0);break;case"X":if("*"===o)throw new Error("Warning: pack(): Type X: '*' ignored");for(A=0;A<o;A++){if(0===T.length)throw new Error("Warning: pack(): Type X: outside of string");T=T.substring(0,T.length-1)}break;case"@":if("*"===o)throw new Error("Warning: pack(): Type X: '*' ignored");if(o>T.length)for(g=o-T.length,A=0;A<g;A++)T+=String.fromCharCode(0);o<T.length&&(T=T.substring(0,o));break;default:throw new Error("Warning: pack() Type "+e+": unknown format code")}}if(W<arguments.length){var N="Warning: pack(): "+(arguments.length-W)+" arguments unused";throw new Error(N)}return T}