endpointjs
Version:
Endpoint.js enables modules within a web application to discover and use each other, whether that be on the same web page, other browser windows and tabs, iframes, servers and web workers in a reactive way by providing robust discovery, execution and stre
9 lines • 529 kB
JavaScript
/**
* endpointjs - v0.4.1
* Built 2016-04-26
* Created in collaboration with Booz Allen Hamilton (www.boozallen.com)
* (C) 2016 Booz Allen Hamilton, All rights reserved
* Powered by InnoVision, created by the GIAT
*/
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c){"use strict";function d(a,b){return this instanceof d?(this._linkId=a,this._settings=b,void h.log(h.DEBUG,"Link initialized: [Type: %s] [ID: %s]",this.getType(),this.getId())):new d(a,b)}var e=a("events").EventEmitter,f=a("util").inherits,g=a("../util/appUtils"),h=g.getLogger(c);f(d,e),b.exports=d,d.prototype.getHeartbeatTimeout=function(){return this._settings.heartbeatTimeout},d.prototype.getTransformFactory=function(){return this._settings.transformFactory},d.prototype.getType=function(){return new Error("not implemented")},d.prototype.getId=function(){return this._linkId},d.prototype.getCost=function(){return 0},d.prototype.isExternal=function(){return!1},d.prototype.close=function(){h.log(h.DEBUG,"Link closed: [Type: %s] [ID: %s]",this.getType(),this.getId())}}).call(this,"/js\\app\\link\\link.js")},{"../util/appUtils":4,events:107,util:244}],2:[function(a,b,c){(function(c){"use strict";function d(a,b,c){return this instanceof d?(this._instanceId=a,e.call(this,b,c),this._handshakes=h(15,"Protocol link: "+b),this._handshakes.on("expired",function(a,b){j.log(j.WARN,"Host exchange expired"),b.closeFn()}),void(this._streams={})):new d(a,b,c)}var e=a("./link"),f=a("util").inherits,g=a("node-uuid"),h=a("../util/expirable-hash"),i=a("../util/appUtils"),j=i.getLogger(c),k=a("through2");f(d,e),b.exports=d,d.prototype._handleGreeting=function(a,b,c){function d(){l||(j.log(j.DEBUG,"Lost connection: [Link Type: %s] [Link ID: %s] [Edge ID: %s] [From: %s]",m.getType(),m.getId(),h.edgeId,h.instanceId),l=!0,h.readTransport.push(null),h.readTransport.end(),h.ready?(delete m._streams[e],m.emit("connection-close",m,h.edgeId)):(m._handshakes.remove(e),h.sendTransport.push(null),h.sendTransport.end()))}var e=g();if(c=c||a.s,b=b||g(),!i.isUuid(c)||!i.isUuid(b))throw new Error("Invalid instance or edge id");var f={d:a.s,s:e},h={streamId:e,instanceId:c||a.s,edgeId:this.isExternal()?b:c,ready:!1,readTransport:k.obj(),sendTransport:this._createInjectStream(f,a),closeFn:d},l=!1,m=this;return h.sendTransport.on("finish",d),h.sendTransport.on("end",d),this._handshakes.add(e,h),j.log(j.DEBUG,"New connection: [Link Type: %s] [Link ID: %s] [Edge ID: %s] [From: %s]",this.getType(),this.getId(),h.edgeId,h.instanceId),h},d.prototype._handleGoodbye=function(a){var b=this._streams[a.d];b&&(b.readTransport.push(null),b.readTransport.end())},d.prototype._sendProtocolCommand=function(a,b,c){var d=this._streams[a]||this._handshakes.get(a);d&&this._sendProtocolCommandTo(d.sendTransport,b,c)},d.prototype._sendProtocolCommandTo=function(a,b,c){a.write({p:b,m:c})},d.prototype._createInjectStream=function(a,b){var c=k.obj(function(b,c,d){for(var e in a)b[e]=a[e];this.push(b),d()});return c.updateInject=function(b){a=b},c.pipe(this._createSenderStream(b)),c},d.prototype._handleReady=function(a,b){var c=a.d,d=this._handshakes.get(c);if(d&&!d.ready){if(b){if(!i.isUuid(b))throw new Error("Invalid instance id");d.instanceId=b}return d.sendTransport.updateInject({d:a.s}),d.ready=!0,this._streams[d.streamId]=d,this._handshakes.remove(d.streamId),this.emit("connection",this,d.edgeId,{read:d.readTransport,write:d.sendTransport},d.instanceId),!0}return!1},d.prototype._handleReader=function(a){var b={},c=function(a){b[a]||(b[a]=this._streams[a].readTransport,b[a].once("end",function(){delete b[a]}))}.bind(this),d=function(){for(var b;null!==(b=a.read());)if(b&&b.d)try{var d;if(b.p)switch(b.p){case"greetings":"broadcast"==b.d&&b.s!=this._instanceId&&(d=this._handleGreeting(b),this._sendProtocolCommand(d.streamId,"hi",{i:this._instanceId,e:d.edgeId}));break;case"hi":b.d==this._instanceId&&b.m&&(d=this._handleGreeting(b,b.m.e,b.m.i),this._sendProtocolCommand(d.streamId,"ready"),b.d=d.streamId,this._handleReady(b,b.m.i),c(b.d));break;case"ready":this._handleReady(b)&&c(b.d);break;case"goodbye":this._handleGoodbye(b)}else d=this._streams[b.d],d&&d.readTransport.push(b)}catch(e){j.log(j.ERROR,"Exception reading: %s",e.stack)}}.bind(this),e=function(){a.removeListener("readable",d);for(var c in b)b[c].push(null);b={}}.bind(this);a.once("end",e),a.on("readable",d)},d.prototype._announce=function(a){var b={d:"broadcast",s:this._instanceId},c=this._createInjectStream(b,a);this._sendProtocolCommandTo(c,"greetings"),c.end()},d.prototype._createSenderStream=function(a){return new Error("not implemented")},d.prototype.closeLink=function(a){var b=this._streams[a];b&&(this._sendProtocolCommandTo(b.sendTransport,"goodbye"),b.closeFn())},d.prototype.close=function(){var a=Object.keys(this._streams);a.forEach(function(a){this.closeLink(a)},this),e.prototype.close.call(this)}}).call(this,"/js\\app\\link\\protocol-link.js")},{"../util/appUtils":4,"../util/expirable-hash":6,"./link":1,"node-uuid":126,through2:237,util:244}],3:[function(a,b,c){"use strict";function d(a,b,c){var e=c(a,b);if(b!==e)return e;if(e&&"object"==typeof e)for(var f in e)Object.prototype.hasOwnProperty.call(e,f)&&e[f]&&(e[f]=d(f,e[f],c));return b}var e=a("through2"),f=a("util").isBuffer,g=a("buffer").Buffer;b.exports={},b.exports.encode=function(a){return e.obj(function(c,d,e){this.push(b.exports.encodeFunction(a,c)),e()})},b.exports.encodeFunction=function(a,b){var c;if(a)b=d("",b,function(a,b){return(b._isBuffer||f(b))&&(b={type:"buffer-i",data:b.toString("base64")}),b}),c=JSON.stringify(b);else{var e=[],g=0;b=d("",b,function(a,c){if(b._isBuffer||f(c)){var d={type:"buffer-o",index:g++};return e.push(c.toArrayBuffer()),d}return c}),c=JSON.stringify(b),c={data:c,transfer:e}}return c},b.exports.decode=function(a){return e.obj(function(c,d,e){this.push(b.exports.decodeFunction(a,c)),e()})},b.exports.decodeFunction=function(a,b){var c;return a?(c=JSON.parse(b),c=d("",c,function(a,b){return b&&"buffer-i"==b.type?new g(b.data,"base64"):b})):(c=JSON.parse(b.data),c=d("",c,function(a,c){return c&&"buffer-o"==c.type?new g(b.transfer[c.index]):c})),c}},{buffer:59,through2:237,util:244}],4:[function(a,b,c){(function(c,d){"use strict";var e=a("./logger").Logger,f=a("./constants"),g=a("util").isString,h={_scriptName:null,initScriptName:function(){if(!this._scriptName){var a=this.getGlobalObject();if(a.document){var b=a.document.getElementsByTagName("script"),c=b[b.length-1];this._scriptName=c.src}}},isUuid:function(a){return!(!g(a)||36!=a.length)},isExtUuid:function(a){return!(!g(a)||40!=a.length||36!==a.indexOf("-ext"))},getScriptName:function(){return this._scriptName},getGlobalObject:function(){return d},nextTick:function(a){c.nextTick(a)},getScriptBasename:function(a){if(a&&"string"==typeof a&&("/"==a[0]||"\\"==a[0])){a=a.replace(/\\/g,"/");var b=a.split("/");a=b[b.length-1]}return a},getLogger:function(a){return e(this.getScriptBasename(a))},addEventListener:function(a,b,c,d){"addEventListener"in a?a.addEventListener(b,c,d):a.attachEvent("on"+b,c)},removeEventListener:function(a,b,c,d){"removeEventListener"in a?a.removeEventListener(b,c,d):a.detachEvent("on"+b,c)},getNeighborhood:function(a,b){var c=f.Neighborhood[(b+"").toUpperCase()],d=f.Neighborhood[(a+"").toUpperCase()];return"undefined"==typeof d?c:d}};b.exports=h}).call(this,a("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./constants":5,"./logger":7,_process:149,util:244}],5:[function(a,b,c){"use strict";b.exports={EndpointType:{CLIENT:"Client",CLIENT_INSTANCE:"Client Instance",FACADE:"Facade",ADAPTER:"Adapter",OBJECT_INSTANCE:"Object Instance",CALL:"Call",QUERY:"Query"},LinkType:{SERVER:"server",WORKER:"worker",TAB:"tab",WINDOW:"window"},Neighborhood:{UNIVERSAL:3,GLOBAL:2,GROUP:1,LOCAL:0}}},{}],6:[function(a,b,c){"use strict";function d(a,b){return this instanceof d?(g.call(this),this._duration=1e3*a,this._items=0,this._itemsArray=[],this._itemsHash={},this._timer=e(b||"Expirable Hash",this._duration),void this._timer.on("period",this._check.bind(this))):new d(a,b)}var e=a("./periodic-timer"),f=a("util").inherits,g=a("events").EventEmitter;f(d,g),b.exports=d,d.prototype.add=function(a,b){this._clean(),this.remove(a);var c={k:a,v:b,t:(new Date).getTime()+this._duration};this._items+=1,this._itemsArray.push(c),this._itemsHash[a]=c,this._timer.addReference()},d.prototype.get=function(a){this._check();var b=this._itemsHash[a];return b?b.v:void 0},d.prototype.touch=function(a){var b=this.get(a);b&&(this.remove(a),this.add(a,b))},d.prototype.remove=function(a){var b=this._itemsHash[a];b&&(this._items-=1,b.v=b.k=null,b.t=0,delete this._itemsHash[a],this._timer.removeReference())},d.prototype._check=function(){for(var a=(new Date).getTime();this._itemsArray.length>0;){var b=this._itemsArray[0];if(b.t>a)break;b.t>0&&(this.emit("expired",b.k,b.v),this.remove(b.k)),this._itemsArray.shift()}},d.prototype._clean=function(){if(this._itemsArray.length>10&&this._itemsArray.length>2*this._items){var a=[];this._itemsArray.forEach(function(b){b.t>0&&a.push(b)}),this._itemsArray=a}}},{"./periodic-timer":8,events:107,util:244}],7:[function(a,b,c){"use strict";function d(a){if(!(this instanceof d))return new d(a);a=a||"Unknown";var b="Unknown";"string"==typeof a?b=a:"object"==typeof a&&a.constructor&&(b=a.constructor.name),this._location=a}var e=a("util").format;b.exports={Logger:d,logLevel:"warn"},d.prototype.TRACE="trace",d.prototype.DEBUG3="debug3",d.prototype.DEBUG2="debug2",d.prototype.DEBUG="debug",d.prototype.INFO="info",d.prototype.WARN="warn",d.prototype.ERROR="error",d.prototype.NONE="none",d.prototype._LevelPriority={trace:8,debug3:7,debug2:6,debug:5,info:4,warn:3,error:2,none:1},d.prototype._ConsoleMap={trace:"debug",debug3:"debug",debug2:"debug",debug:"debug",info:"info",warn:"warn",error:"error"},d.prototype.log=function(a,c){if("undefined"!=typeof console){this._LevelPriority[a]||(a=this.DEBUG);var d=this._LevelPriority[b.exports.logLevel],f=this._LevelPriority[a];if(d>=f){if(arguments.length>2){var g=Array.prototype.slice.call(arguments,2);g.unshift(c),c=e.apply(e,g)}var h=new Date,i=e("%s:%s:%s - [%s] [%s] %s",h.getHours(),h.getMinutes(),h.getSeconds(),a,this._location,c);"function"==typeof console[this._ConsoleMap[a]]?console[this._ConsoleMap[a]](i):console.log(i)}}}},{util:244}],8:[function(a,b,c){(function(c){"use strict";function d(a,b){return this instanceof d?(h.call(this),this._name=a,this._timeout=b||15e3,this._references=0,void(this._timerId=null)):new d(a,b)}var e=a("../util/appUtils"),f=e.getLogger(c),g=a("util").inherits,h=a("events").EventEmitter;g(d,h),b.exports=d,d.prototype.getReferenceCounter=function(){return this._references},d.prototype.addReference=function(){return this._references++,this._checkTimer()},d.prototype.removeReference=function(){return this._references--,this._checkTimer()},d.prototype._checkTimer=function(){var a=this._timerId;return 0===this._references&&null!==this._timerId?(f.log(f.DEBUG2,"Stopping [%s] interval timer: %s",this._name,this._timerId),clearInterval(this._timerId),this._timerId=null,this.emit("period",!0)):this._references>0&&null===this._timerId&&(this._timerId=setInterval(function(){this.emit("period")}.bind(this),this._timeout),f.log(f.DEBUG2,"Starting [%s] interval timer: %s",this._name,this._timerId),a=this._timerId),a}}).call(this,"/js\\app\\util\\periodic-timer.js")},{"../util/appUtils":4,events:107,util:244}],9:[function(a,b,c){var d=a("events").EventEmitter,e=a("../../app/util/logger"),f=a("./webrtc-link"),g=a("stream-to-pull-stream"),h=a("rtc-quickconnect"),i=a("../../app/util/appUtils"),j=i.getGlobalObject(),k=j.endpoint;if(!k)throw new Error("Cannot find Endpoint.js (window.endpoint)");e.logLevel=j.endpointLogLevel;var l="webrtc",m=function(a,b,c){return f(a,b,c)};j.endpoint.getConfiguration().addCustomLinkType(l,m),j.endpointWebRTC=function(a){var b=new d;a=a||{};var c=a.settings||{};if(c.neighborhood=c.neighborhood||"global",c.linkId){var e=k.getConfiguration().createBridge([c.linkId]);c.bridgeId=e.getId()}var f=k.manageFacades(["web-rtc-discovery","1.0",c]);return f.on("ready",function(){var d=f.getApi("web-rtc-discovery").register().stream(),e=!1;d.on("finish",function(){e=!0});var i=function(){return function(a){if(e)return void a(new Error("stream has ended"));var b=g.duplex(d);a(null,b.source,b.sink)}},j=a.quickconnect||{};j.room=c.room||j.room||"endpointjs-room",j.messenger=i;var k=h("fake",j);b.emit("ready",k)}),b}},{"../../app/util/appUtils":4,"../../app/util/logger":7,"./webrtc-link":10,events:107,"rtc-quickconnect":194,"stream-to-pull-stream":229}],10:[function(a,b,c){(function(c){function d(a,b,c){return this instanceof d?(this._channel=c.channel||"data-channel",this._external=c.hasOwnProperty("external")?!!c.external:!0,void e.call(this,a,b,c)):new d(a,b,c)}var e=a("../../app/link/protocol-link"),f=a("util").inherits,g=a("through2"),h=a("../../app/streams/stringify-stream"),i=a("../../app/util/appUtils"),j=i.getLogger(c);f(d,e),b.exports=d,d.prototype.isExternal=function(){return this._external},d.prototype.getCost=function(){return 25},d.prototype.getType=function(){return"webrtc"},d.prototype.addConference=function(a){j.log(j.DEBUG,"Adding new conference to WebRTC link");var b={},c=a.createDataChannel(this._channel,{ordered:!0,maxRetransmits:12}),d=this;c.on("channel:opened:"+this._channel,function(a,e){j.log(j.DEBUG2,"WebRTC channel [%s] opened from %s",d._channel,a),b[a]={readStream:g.obj(),channel:e,id:a};var f=h.decodeFunction;e.onmessage=function(c){var d=f(!0,c.data);j.log(j.TRACE,"Received message: [%s]",c.data),d.channel=e,b[a].readStream.write(d)},d._handleReader(b[a].readStream),c.id>a&&d.announceChannel(e)}),c.on("channel:closed:"+this._channel,function(a){j.log(j.DEBUG2,"WebRTC channel [%s] closed from %s",d._channel,a),b[a].readStream.push(null),delete b[a]})},d.prototype._createSenderStream=function(a){var b=g.obj(),c=h.encodeFunction;return b.on("readable",function(){for(var d;null!==(d=b.read());)j.log(j.TRACE,"Sending message: [%j]",d),a.channel.send(c(!0,d))}),b},d.prototype.announceChannel=function(a){this._announce({channel:a})}}).call(this,"/js\\plugins\\webrtc\\webrtc-link.js")},{"../../app/link/protocol-link":2,"../../app/streams/stringify-stream":3,"../../app/util/appUtils":4,through2:237,util:244}],11:[function(a,b,c){var d=c;d.bignum=a("bn.js"),d.define=a("./asn1/api").define,d.base=a("./asn1/base"),d.constants=a("./asn1/constants"),d.decoders=a("./asn1/decoders"),d.encoders=a("./asn1/encoders")},{"./asn1/api":12,"./asn1/base":14,"./asn1/constants":18,"./asn1/decoders":20,"./asn1/encoders":23,"bn.js":28}],12:[function(a,b,c){function d(a,b){this.name=a,this.body=b,this.decoders={},this.encoders={}}var e=a("../asn1"),f=a("inherits"),g=c;g.define=function(a,b){return new d(a,b)},d.prototype._createNamed=function(b){var c;try{c=a("vm").runInThisContext("(function "+this.name+"(entity) {\n this._initNamed(entity);\n})")}catch(d){c=function(a){this._initNamed(a)}}return f(c,b),c.prototype._initNamed=function(a){b.call(this,a)},new c(this)},d.prototype._getDecoder=function(a){return this.decoders.hasOwnProperty(a)||(this.decoders[a]=this._createNamed(e.decoders[a])),this.decoders[a]},d.prototype.decode=function(a,b,c){return this._getDecoder(b).decode(a,c)},d.prototype._getEncoder=function(a){return this.encoders.hasOwnProperty(a)||(this.encoders[a]=this._createNamed(e.encoders[a])),this.encoders[a]},d.prototype.encode=function(a,b,c){return this._getEncoder(b).encode(a,c)}},{"../asn1":11,inherits:119,vm:245}],13:[function(a,b,c){function d(a,b){return g.call(this,b),h.isBuffer(a)?(this.base=a,this.offset=0,void(this.length=a.length)):void this.error("Input not Buffer")}function e(a,b){if(Array.isArray(a))this.length=0,this.value=a.map(function(a){return a instanceof e||(a=new e(a,b)),this.length+=a.length,a},this);else if("number"==typeof a){if(!(a>=0&&255>=a))return b.error("non-byte EncoderBuffer value");this.value=a,this.length=1}else if("string"==typeof a)this.value=a,this.length=h.byteLength(a);else{if(!h.isBuffer(a))return b.error("Unsupported type: "+typeof a);this.value=a,this.length=a.length}}var f=a("inherits"),g=a("../base").Reporter,h=a("buffer").Buffer;f(d,g),c.DecoderBuffer=d,d.prototype.save=function(){return{offset:this.offset,reporter:g.prototype.save.call(this)}},d.prototype.restore=function(a){var b=new d(this.base);return b.offset=a.offset,b.length=this.offset,this.offset=a.offset,g.prototype.restore.call(this,a.reporter),b},d.prototype.isEmpty=function(){return this.offset===this.length},d.prototype.readUInt8=function(a){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(a||"DecoderBuffer overrun")},d.prototype.skip=function(a,b){if(!(this.offset+a<=this.length))return this.error(b||"DecoderBuffer overrun");var c=new d(this.base);return c._reporterState=this._reporterState,c.offset=this.offset,c.length=this.offset+a,this.offset+=a,c},d.prototype.raw=function(a){return this.base.slice(a?a.offset:this.offset,this.length)},c.EncoderBuffer=e,e.prototype.join=function(a,b){return a||(a=new h(this.length)),b||(b=0),0===this.length?a:(Array.isArray(this.value)?this.value.forEach(function(c){c.join(a,b),b+=c.length}):("number"==typeof this.value?a[b]=this.value:"string"==typeof this.value?a.write(this.value,b):h.isBuffer(this.value)&&this.value.copy(a,b),b+=this.length),a)}},{"../base":14,buffer:59,inherits:119}],14:[function(a,b,c){var d=c;d.Reporter=a("./reporter").Reporter,d.DecoderBuffer=a("./buffer").DecoderBuffer,d.EncoderBuffer=a("./buffer").EncoderBuffer,d.Node=a("./node")},{"./buffer":13,"./node":15,"./reporter":16}],15:[function(a,b,c){function d(a,b){var c={};this._baseState=c,c.enc=a,c.parent=b||null,c.children=null,c.tag=null,c.args=null,c.reverseArgs=null,c.choice=null,c.optional=!1,c.any=!1,c.obj=!1,c.use=null,c.useDecoder=null,c.key=null,c["default"]=null,c.explicit=null,c.implicit=null,c.contains=null,c.parent||(c.children=[],this._wrap())}var e=a("../base").Reporter,f=a("../base").EncoderBuffer,g=a("../base").DecoderBuffer,h=a("minimalistic-assert"),i=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],j=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(i),k=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];b.exports=d;var l=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit"];d.prototype.clone=function(){var a=this._baseState,b={};l.forEach(function(c){b[c]=a[c]});var c=new this.constructor(b.parent);return c._baseState=b,c},d.prototype._wrap=function(){var a=this._baseState;j.forEach(function(b){this[b]=function(){var c=new this.constructor(this);return a.children.push(c),c[b].apply(c,arguments)}},this)},d.prototype._init=function(a){var b=this._baseState;h(null===b.parent),a.call(this),b.children=b.children.filter(function(a){return a._baseState.parent===this},this),h.equal(b.children.length,1,"Root node can have only one child")},d.prototype._useArgs=function(a){var b=this._baseState,c=a.filter(function(a){return a instanceof this.constructor},this);a=a.filter(function(a){return!(a instanceof this.constructor)},this),0!==c.length&&(h(null===b.children),b.children=c,c.forEach(function(a){a._baseState.parent=this},this)),0!==a.length&&(h(null===b.args),b.args=a,b.reverseArgs=a.map(function(a){if("object"!=typeof a||a.constructor!==Object)return a;var b={};return Object.keys(a).forEach(function(c){c==(0|c)&&(c|=0);var d=a[c];b[d]=c}),b}))},k.forEach(function(a){d.prototype[a]=function(){var b=this._baseState;throw new Error(a+" not implemented for encoding: "+b.enc)}}),i.forEach(function(a){d.prototype[a]=function(){var b=this._baseState,c=Array.prototype.slice.call(arguments);return h(null===b.tag),b.tag=a,this._useArgs(c),this}}),d.prototype.use=function(a){var b=this._baseState;return h(null===b.use),b.use=a,this},d.prototype.optional=function(){var a=this._baseState;return a.optional=!0,this},d.prototype.def=function(a){var b=this._baseState;return h(null===b["default"]),b["default"]=a,b.optional=!0,this},d.prototype.explicit=function(a){var b=this._baseState;return h(null===b.explicit&&null===b.implicit),b.explicit=a,this},d.prototype.implicit=function(a){var b=this._baseState;return h(null===b.explicit&&null===b.implicit),b.implicit=a,this},d.prototype.obj=function(){var a=this._baseState,b=Array.prototype.slice.call(arguments);return a.obj=!0,0!==b.length&&this._useArgs(b),this},d.prototype.key=function(a){var b=this._baseState;return h(null===b.key),b.key=a,this},d.prototype.any=function(){var a=this._baseState;return a.any=!0,this},d.prototype.choice=function(a){var b=this._baseState;return h(null===b.choice),b.choice=a,this._useArgs(Object.keys(a).map(function(b){return a[b]})),this},d.prototype.contains=function(a){var b=this._baseState;return h(null===b.use),b.contains=a,this},d.prototype._decode=function(a){var b=this._baseState;if(null===b.parent)return a.wrapResult(b.children[0]._decode(a));var c,d=b["default"],e=!0;if(null!==b.key&&(c=a.enterKey(b.key)),b.optional){var f=null;if(null!==b.explicit?f=b.explicit:null!==b.implicit?f=b.implicit:null!==b.tag&&(f=b.tag),null!==f||b.any){if(e=this._peekTag(a,f,b.any),a.isError(e))return e}else{var h=a.save();try{null===b.choice?this._decodeGeneric(b.tag,a):this._decodeChoice(a),e=!0}catch(i){e=!1}a.restore(h)}}var j;if(b.obj&&e&&(j=a.enterObject()),e){if(null!==b.explicit){var k=this._decodeTag(a,b.explicit);if(a.isError(k))return k;a=k}if(null===b.use&&null===b.choice){if(b.any)var h=a.save();var l=this._decodeTag(a,null!==b.implicit?b.implicit:b.tag,b.any);if(a.isError(l))return l;b.any?d=a.raw(h):a=l}if(d=b.any?d:null===b.choice?this._decodeGeneric(b.tag,a):this._decodeChoice(a),a.isError(d))return d;if(b.any||null!==b.choice||null===b.children||b.children.forEach(function(b){b._decode(a)}),b.contains&&("octstr"===b.tag||"bitstr"===b.tag)){var m=new g(d);d=this._getUse(b.contains,a._reporterState.obj)._decode(m)}}return b.obj&&e&&(d=a.leaveObject(j)),null===b.key||null===d&&e!==!0||a.leaveKey(c,b.key,d),d},d.prototype._decodeGeneric=function(a,b){var c=this._baseState;return"seq"===a||"set"===a?null:"seqof"===a||"setof"===a?this._decodeList(b,a,c.args[0]):/str$/.test(a)?this._decodeStr(b,a):"objid"===a&&c.args?this._decodeObjid(b,c.args[0],c.args[1]):"objid"===a?this._decodeObjid(b,null,null):"gentime"===a||"utctime"===a?this._decodeTime(b,a):"null_"===a?this._decodeNull(b):"bool"===a?this._decodeBool(b):"int"===a||"enum"===a?this._decodeInt(b,c.args&&c.args[0]):null!==c.use?this._getUse(c.use,b._reporterState.obj)._decode(b):b.error("unknown tag: "+a)},d.prototype._getUse=function(a,b){var c=this._baseState;return c.useDecoder=this._use(a,b),h(null===c.useDecoder._baseState.parent),c.useDecoder=c.useDecoder._baseState.children[0],c.implicit!==c.useDecoder._baseState.implicit&&(c.useDecoder=c.useDecoder.clone(),c.useDecoder._baseState.implicit=c.implicit),c.useDecoder},d.prototype._decodeChoice=function(a){var b=this._baseState,c=null,d=!1;return Object.keys(b.choice).some(function(e){var f=a.save(),g=b.choice[e];try{var h=g._decode(a);if(a.isError(h))return!1;c={type:e,value:h},d=!0}catch(i){return a.restore(f),!1}return!0},this),d?c:a.error("Choice not matched")},d.prototype._createEncoderBuffer=function(a){return new f(a,this.reporter)},d.prototype._encode=function(a,b,c){var d=this._baseState;if(null===d["default"]||d["default"]!==a){var e=this._encodeValue(a,b,c);if(void 0!==e&&!this._skipDefault(e,b,c))return e}},d.prototype._encodeValue=function(a,b,c){var d=this._baseState;if(null===d.parent)return d.children[0]._encode(a,b||new e);var f=null;if(this.reporter=b,d.optional&&void 0===a){if(null===d["default"])return;a=d["default"]}var g=null,h=!1;if(d.any)f=this._createEncoderBuffer(a);else if(d.choice)f=this._encodeChoice(a,b);else if(d.contains)g=this._getUse(d.contains,c)._encode(a,b),h=!0;else if(d.children)g=d.children.map(function(c){if("null_"===c._baseState.tag)return c._encode(null,b,a);if(null===c._baseState.key)return b.error("Child should have a key");var d=b.enterKey(c._baseState.key);if("object"!=typeof a)return b.error("Child expected, but input is not object");var e=c._encode(a[c._baseState.key],b,a);return b.leaveKey(d),e},this).filter(function(a){return a}),g=this._createEncoderBuffer(g);else if("seqof"===d.tag||"setof"===d.tag){if(!d.args||1!==d.args.length)return b.error("Too many args for : "+d.tag);if(!Array.isArray(a))return b.error("seqof/setof, but data is not Array");var i=this.clone();i._baseState.implicit=null,g=this._createEncoderBuffer(a.map(function(c){var d=this._baseState;return this._getUse(d.args[0],a)._encode(c,b)},i))}else null!==d.use?f=this._getUse(d.use,c)._encode(a,b):(g=this._encodePrimitive(d.tag,a),h=!0);var f;if(!d.any&&null===d.choice){var j=null!==d.implicit?d.implicit:d.tag,k=null===d.implicit?"universal":"context";null===j?null===d.use&&b.error("Tag could be ommited only for .use()"):null===d.use&&(f=this._encodeComposite(j,h,k,g))}return null!==d.explicit&&(f=this._encodeComposite(d.explicit,!1,"context",f)),f},d.prototype._encodeChoice=function(a,b){var c=this._baseState,d=c.choice[a.type];return d||h(!1,a.type+" not found in "+JSON.stringify(Object.keys(c.choice))),d._encode(a.value,b)},d.prototype._encodePrimitive=function(a,b){var c=this._baseState;if(/str$/.test(a))return this._encodeStr(b,a);if("objid"===a&&c.args)return this._encodeObjid(b,c.reverseArgs[0],c.args[1]);if("objid"===a)return this._encodeObjid(b,null,null);if("gentime"===a||"utctime"===a)return this._encodeTime(b,a);if("null_"===a)return this._encodeNull();if("int"===a||"enum"===a)return this._encodeInt(b,c.args&&c.reverseArgs[0]);if("bool"===a)return this._encodeBool(b);throw new Error("Unsupported tag: "+a)},d.prototype._isNumstr=function(a){return/^[0-9 ]*$/.test(a)},d.prototype._isPrintstr=function(a){return/^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(a)}},{"../base":14,"minimalistic-assert":125}],16:[function(a,b,c){function d(a){this._reporterState={obj:null,path:[],options:a||{},errors:[]}}function e(a,b){this.path=a,this.rethrow(b)}var f=a("inherits");c.Reporter=d,d.prototype.isError=function(a){return a instanceof e},d.prototype.save=function(){var a=this._reporterState;return{obj:a.obj,pathLen:a.path.length}},d.prototype.restore=function(a){var b=this._reporterState;b.obj=a.obj,b.path=b.path.slice(0,a.pathLen)},d.prototype.enterKey=function(a){return this._reporterState.path.push(a)},d.prototype.leaveKey=function(a,b,c){var d=this._reporterState;d.path=d.path.slice(0,a-1),null!==d.obj&&(d.obj[b]=c)},d.prototype.enterObject=function(){var a=this._reporterState,b=a.obj;return a.obj={},b},d.prototype.leaveObject=function(a){var b=this._reporterState,c=b.obj;return b.obj=a,c},d.prototype.error=function(a){var b,c=this._reporterState,d=a instanceof e;if(b=d?a:new e(c.path.map(function(a){return"["+JSON.stringify(a)+"]"}).join(""),a.message||a,a.stack),!c.options.partial)throw b;return d||c.errors.push(b),b},d.prototype.wrapResult=function(a){var b=this._reporterState;return b.options.partial?{result:this.isError(a)?null:a,errors:b.errors}:a},f(e,Error),e.prototype.rethrow=function(a){return this.message=a+" at: "+(this.path||"(shallow)"),Error.captureStackTrace(this,e),this}},{inherits:119}],17:[function(a,b,c){var d=a("../constants");c.tagClass={0:"universal",1:"application",2:"context",3:"private"},c.tagClassByName=d._reverse(c.tagClass),c.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},c.tagByName=d._reverse(c.tag)},{"../constants":18}],18:[function(a,b,c){var d=c;d._reverse=function(a){var b={};return Object.keys(a).forEach(function(c){(0|c)==c&&(c=0|c);var d=a[c];b[d]=c}),b},d.der=a("./der")},{"./der":17}],19:[function(a,b,c){function d(a){this.enc="der",this.name=a.name,this.entity=a,this.tree=new e,this.tree._init(a.body)}function e(a){j.Node.call(this,"der",a)}function f(a,b){var c=a.readUInt8(b);if(a.isError(c))return c;var d=l.tagClass[c>>6],e=0===(32&c);if(31===(31&c)){var f=c;for(c=0;128===(128&f);){if(f=a.readUInt8(b),a.isError(f))return f;c<<=7,c|=127&f}}else c&=31;var g=l.tag[c];return{cls:d,primitive:e,tag:c,tagStr:g}}function g(a,b,c){var d=a.readUInt8(c);if(a.isError(d))return d;if(!b&&128===d)return null;if(0===(128&d))return d;var e=127&d;if(e>=4)return a.error("length octect is too long");d=0;for(var f=0;e>f;f++){d<<=8;var g=a.readUInt8(c);if(a.isError(g))return g;d|=g}return d}var h=a("inherits"),i=a("../../asn1"),j=i.base,k=i.bignum,l=i.constants.der;b.exports=d,d.prototype.decode=function(a,b){return a instanceof j.DecoderBuffer||(a=new j.DecoderBuffer(a,b)),this.tree._decode(a,b)},h(e,j.Node),e.prototype._peekTag=function(a,b,c){if(a.isEmpty())return!1;var d=a.save(),e=f(a,'Failed to peek tag: "'+b+'"');return a.isError(e)?e:(a.restore(d),e.tag===b||e.tagStr===b||e.tagStr+"of"===b||c)},e.prototype._decodeTag=function(a,b,c){var d=f(a,'Failed to decode tag of "'+b+'"');if(a.isError(d))return d;var e=g(a,d.primitive,'Failed to get length of "'+b+'"');if(a.isError(e))return e;if(!c&&d.tag!==b&&d.tagStr!==b&&d.tagStr+"of"!==b)return a.error('Failed to match tag: "'+b+'"');if(d.primitive||null!==e)return a.skip(e,'Failed to match body of: "'+b+'"');var h=a.save(),i=this._skipUntilEnd(a,'Failed to skip indefinite length body: "'+this.tag+'"');return a.isError(i)?i:(e=a.offset-h.offset,a.restore(h),a.skip(e,'Failed to match body of: "'+b+'"'))},e.prototype._skipUntilEnd=function(a,b){for(;;){var c=f(a,b);if(a.isError(c))return c;var d=g(a,c.primitive,b);if(a.isError(d))return d;var e;if(e=c.primitive||null!==d?a.skip(d):this._skipUntilEnd(a,b),a.isError(e))return e;if("end"===c.tagStr)break}},e.prototype._decodeList=function(a,b,c){for(var d=[];!a.isEmpty();){var e=this._peekTag(a,"end");if(a.isError(e))return e;var f=c.decode(a,"der");if(a.isError(f)&&e)break;d.push(f)}return d},e.prototype._decodeStr=function(a,b){if("bitstr"===b){var c=a.readUInt8();return a.isError(c)?c:{unused:c,data:a.raw()}}if("bmpstr"===b){var d=a.raw();if(d.length%2===1)return a.error("Decoding of string type: bmpstr length mismatch");for(var e="",f=0;f<d.length/2;f++)e+=String.fromCharCode(d.readUInt16BE(2*f));return e}if("numstr"===b){var g=a.raw().toString("ascii");return this._isNumstr(g)?g:a.error("Decoding of string type: numstr unsupported characters")}if("octstr"===b)return a.raw();if("printstr"===b){var h=a.raw().toString("ascii");return this._isPrintstr(h)?h:a.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(b)?a.raw().toString():a.error("Decoding of string type: "+b+" unsupported")},e.prototype._decodeObjid=function(a,b,c){for(var d,e=[],f=0;!a.isEmpty();){var g=a.readUInt8();f<<=7,f|=127&g,0===(128&g)&&(e.push(f),f=0)}128&g&&e.push(f);var h=e[0]/40|0,i=e[0]%40;if(d=c?e:[h,i].concat(e.slice(1)),b){var j=b[d.join(" ")];void 0===j&&(j=b[d.join(".")]),void 0!==j&&(d=j)}return d},e.prototype._decodeTime=function(a,b){var c=a.raw().toString();if("gentime"===b)var d=0|c.slice(0,4),e=0|c.slice(4,6),f=0|c.slice(6,8),g=0|c.slice(8,10),h=0|c.slice(10,12),i=0|c.slice(12,14);else{
if("utctime"!==b)return a.error("Decoding "+b+" time is not supported yet");var d=0|c.slice(0,2),e=0|c.slice(2,4),f=0|c.slice(4,6),g=0|c.slice(6,8),h=0|c.slice(8,10),i=0|c.slice(10,12);d=70>d?2e3+d:1900+d}return Date.UTC(d,e-1,f,g,h,i,0)},e.prototype._decodeNull=function(a){return null},e.prototype._decodeBool=function(a){var b=a.readUInt8();return a.isError(b)?b:0!==b},e.prototype._decodeInt=function(a,b){var c=a.raw(),d=new k(c);return b&&(d=b[d.toString(10)]||d),d},e.prototype._use=function(a,b){return"function"==typeof a&&(a=a(b)),a._getDecoder("der").tree}},{"../../asn1":11,inherits:119}],20:[function(a,b,c){var d=c;d.der=a("./der"),d.pem=a("./pem")},{"./der":19,"./pem":21}],21:[function(a,b,c){function d(a){g.call(this,a),this.enc="pem"}var e=a("inherits"),f=a("buffer").Buffer,g=(a("../../asn1"),a("./der"));e(d,g),b.exports=d,d.prototype.decode=function(a,b){for(var c=a.toString().split(/[\r\n]+/g),d=b.label.toUpperCase(),e=/^-----(BEGIN|END) ([^-]+)-----$/,h=-1,i=-1,j=0;j<c.length;j++){var k=c[j].match(e);if(null!==k&&k[2]===d){if(-1!==h){if("END"!==k[1])break;i=j;break}if("BEGIN"!==k[1])break;h=j}}if(-1===h||-1===i)throw new Error("PEM section not found for: "+d);var l=c.slice(h+1,i).join("");l.replace(/[^a-z0-9\+\/=]+/gi,"");var m=new f(l,"base64");return g.prototype.decode.call(this,m,b)}},{"../../asn1":11,"./der":19,buffer:59,inherits:119}],22:[function(a,b,c){function d(a){this.enc="der",this.name=a.name,this.entity=a,this.tree=new e,this.tree._init(a.body)}function e(a){k.Node.call(this,"der",a)}function f(a){return 10>a?"0"+a:a}function g(a,b,c,d){var e;if("seqof"===a?a="seq":"setof"===a&&(a="set"),l.tagByName.hasOwnProperty(a))e=l.tagByName[a];else{if("number"!=typeof a||(0|a)!==a)return d.error("Unknown tag: "+a);e=a}return e>=31?d.error("Multi-octet tag encoding unsupported"):(b||(e|=32),e|=l.tagClassByName[c||"universal"]<<6)}var h=a("inherits"),i=a("buffer").Buffer,j=a("../../asn1"),k=j.base,l=(j.bignum,j.constants.der);b.exports=d,d.prototype.encode=function(a,b){return this.tree._encode(a,b).join()},h(e,k.Node),e.prototype._encodeComposite=function(a,b,c,d){var e=g(a,b,c,this.reporter);if(d.length<128){var f=new i(2);return f[0]=e,f[1]=d.length,this._createEncoderBuffer([f,d])}for(var h=1,j=d.length;j>=256;j>>=8)h++;var f=new i(2+h);f[0]=e,f[1]=128|h;for(var j=1+h,k=d.length;k>0;j--,k>>=8)f[j]=255&k;return this._createEncoderBuffer([f,d])},e.prototype._encodeStr=function(a,b){if("bitstr"===b)return this._createEncoderBuffer([0|a.unused,a.data]);if("bmpstr"===b){for(var c=new i(2*a.length),d=0;d<a.length;d++)c.writeUInt16BE(a.charCodeAt(d),2*d);return this._createEncoderBuffer(c)}return"numstr"===b?this._isNumstr(a)?this._createEncoderBuffer(a):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===b?this._isPrintstr(a)?this._createEncoderBuffer(a):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(b)?this._createEncoderBuffer(a):this.reporter.error("Encoding of string type: "+b+" unsupported")},e.prototype._encodeObjid=function(a,b,c){if("string"==typeof a){if(!b)return this.reporter.error("string objid given, but no values map found");if(!b.hasOwnProperty(a))return this.reporter.error("objid not found in values map");a=b[a].split(/[\s\.]+/g);for(var d=0;d<a.length;d++)a[d]|=0}else if(Array.isArray(a)){a=a.slice();for(var d=0;d<a.length;d++)a[d]|=0}if(!Array.isArray(a))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(a));if(!c){if(a[1]>=40)return this.reporter.error("Second objid identifier OOB");a.splice(0,2,40*a[0]+a[1])}for(var e=0,d=0;d<a.length;d++){var f=a[d];for(e++;f>=128;f>>=7)e++}for(var g=new i(e),h=g.length-1,d=a.length-1;d>=0;d--){var f=a[d];for(g[h--]=127&f;(f>>=7)>0;)g[h--]=128|127&f}return this._createEncoderBuffer(g)},e.prototype._encodeTime=function(a,b){var c,d=new Date(a);return"gentime"===b?c=[f(d.getFullYear()),f(d.getUTCMonth()+1),f(d.getUTCDate()),f(d.getUTCHours()),f(d.getUTCMinutes()),f(d.getUTCSeconds()),"Z"].join(""):"utctime"===b?c=[f(d.getFullYear()%100),f(d.getUTCMonth()+1),f(d.getUTCDate()),f(d.getUTCHours()),f(d.getUTCMinutes()),f(d.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+b+" time is not supported yet"),this._encodeStr(c,"octstr")},e.prototype._encodeNull=function(){return this._createEncoderBuffer("")},e.prototype._encodeInt=function(a,b){if("string"==typeof a){if(!b)return this.reporter.error("String int or enum given, but no values map");if(!b.hasOwnProperty(a))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(a));a=b[a]}if("number"!=typeof a&&!i.isBuffer(a)){var c=a.toArray();!a.sign&&128&c[0]&&c.unshift(0),a=new i(c)}if(i.isBuffer(a)){var d=a.length;0===a.length&&d++;var e=new i(d);return a.copy(e),0===a.length&&(e[0]=0),this._createEncoderBuffer(e)}if(128>a)return this._createEncoderBuffer(a);if(256>a)return this._createEncoderBuffer([0,a]);for(var d=1,f=a;f>=256;f>>=8)d++;for(var e=new Array(d),f=e.length-1;f>=0;f--)e[f]=255&a,a>>=8;return 128&e[0]&&e.unshift(0),this._createEncoderBuffer(new i(e))},e.prototype._encodeBool=function(a){return this._createEncoderBuffer(a?255:0)},e.prototype._use=function(a,b){return"function"==typeof a&&(a=a(b)),a._getEncoder("der").tree},e.prototype._skipDefault=function(a,b,c){var d,e=this._baseState;if(null===e["default"])return!1;var f=a.join();if(void 0===e.defaultBuffer&&(e.defaultBuffer=this._encodeValue(e["default"],b,c).join()),f.length!==e.defaultBuffer.length)return!1;for(d=0;d<f.length;d++)if(f[d]!==e.defaultBuffer[d])return!1;return!0}},{"../../asn1":11,buffer:59,inherits:119}],23:[function(a,b,c){var d=c;d.der=a("./der"),d.pem=a("./pem")},{"./der":22,"./pem":24}],24:[function(a,b,c){function d(a){f.call(this,a),this.enc="pem"}var e=a("inherits"),f=(a("buffer").Buffer,a("../../asn1"),a("./der"));e(d,f),b.exports=d,d.prototype.encode=function(a,b){for(var c=f.prototype.encode.call(this,a),d=c.toString("base64"),e=["-----BEGIN "+b.label+"-----"],g=0;g<d.length;g+=64)e.push(d.slice(g,g+64));return e.push("-----END "+b.label+"-----"),e.join("\n")}},{"../../asn1":11,"./der":22,buffer:59,inherits:119}],25:[function(a,b,c){function d(a,b){return n.isUndefined(b)?""+b:n.isNumber(b)&&!isFinite(b)?b.toString():n.isFunction(b)||n.isRegExp(b)?b.toString():b}function e(a,b){return n.isString(a)?a.length<b?a:a.slice(0,b):a}function f(a){return e(JSON.stringify(a.actual,d),128)+" "+a.operator+" "+e(JSON.stringify(a.expected,d),128)}function g(a,b,c,d,e){throw new q.AssertionError({message:c,actual:a,expected:b,operator:d,stackStartFunction:e})}function h(a,b){a||g(a,!0,b,"==",q.ok)}function i(a,b){if(a===b)return!0;if(n.isBuffer(a)&&n.isBuffer(b)){if(a.length!=b.length)return!1;for(var c=0;c<a.length;c++)if(a[c]!==b[c])return!1;return!0}return n.isDate(a)&&n.isDate(b)?a.getTime()===b.getTime():n.isRegExp(a)&&n.isRegExp(b)?a.source===b.source&&a.global===b.global&&a.multiline===b.multiline&&a.lastIndex===b.lastIndex&&a.ignoreCase===b.ignoreCase:n.isObject(a)||n.isObject(b)?k(a,b):a==b}function j(a){return"[object Arguments]"==Object.prototype.toString.call(a)}function k(a,b){if(n.isNullOrUndefined(a)||n.isNullOrUndefined(b))return!1;if(a.prototype!==b.prototype)return!1;if(n.isPrimitive(a)||n.isPrimitive(b))return a===b;var c=j(a),d=j(b);if(c&&!d||!c&&d)return!1;if(c)return a=o.call(a),b=o.call(b),i(a,b);var e,f,g=r(a),h=r(b);if(g.length!=h.length)return!1;for(g.sort(),h.sort(),f=g.length-1;f>=0;f--)if(g[f]!=h[f])return!1;for(f=g.length-1;f>=0;f--)if(e=g[f],!i(a[e],b[e]))return!1;return!0}function l(a,b){return a&&b?"[object RegExp]"==Object.prototype.toString.call(b)?b.test(a):a instanceof b?!0:b.call({},a)===!0:!1}function m(a,b,c,d){var e;n.isString(c)&&(d=c,c=null);try{b()}catch(f){e=f}if(d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&g(e,c,"Missing expected exception"+d),!a&&l(e,c)&&g(e,c,"Got unwanted exception"+d),a&&e&&c&&!l(e,c)||!a&&e)throw e}var n=a("util/"),o=Array.prototype.slice,p=Object.prototype.hasOwnProperty,q=b.exports=h;q.AssertionError=function(a){this.name="AssertionError",this.actual=a.actual,this.expected=a.expected,this.operator=a.operator,a.message?(this.message=a.message,this.generatedMessage=!1):(this.message=f(this),this.generatedMessage=!0);var b=a.stackStartFunction||g;if(Error.captureStackTrace)Error.captureStackTrace(this,b);else{var c=new Error;if(c.stack){var d=c.stack,e=b.name,h=d.indexOf("\n"+e);if(h>=0){var i=d.indexOf("\n",h+1);d=d.substring(i+1)}this.stack=d}}},n.inherits(q.AssertionError,Error),q.fail=g,q.ok=h,q.equal=function(a,b,c){a!=b&&g(a,b,c,"==",q.equal)},q.notEqual=function(a,b,c){a==b&&g(a,b,c,"!=",q.notEqual)},q.deepEqual=function(a,b,c){i(a,b)||g(a,b,c,"deepEqual",q.deepEqual)},q.notDeepEqual=function(a,b,c){i(a,b)&&g(a,b,c,"notDeepEqual",q.notDeepEqual)},q.strictEqual=function(a,b,c){a!==b&&g(a,b,c,"===",q.strictEqual)},q.notStrictEqual=function(a,b,c){a===b&&g(a,b,c,"!==",q.notStrictEqual)},q["throws"]=function(a,b,c){m.apply(this,[!0].concat(o.call(arguments)))},q.doesNotThrow=function(a,b){m.apply(this,[!1].concat(o.call(arguments)))},q.ifError=function(a){if(a)throw a};var r=Object.keys||function(a){var b=[];for(var c in a)p.call(a,c)&&b.push(c);return b}},{"util/":244}],26:[function(a,b,c){var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(a){"use strict";function b(a){var b=a.charCodeAt(0);return b===g||b===l?62:b===h||b===m?63:i>b?-1:i+10>b?b-i+26+26:k+26>b?b-k:j+26>b?b-j+26:void 0}function c(a){function c(a){j[l++]=a}var d,e,g,h,i,j;if(a.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var k=a.length;i="="===a.charAt(k-2)?2:"="===a.charAt(k-1)?1:0,j=new f(3*a.length/4-i),g=i>0?a.length-4:a.length;var l=0;for(d=0,e=0;g>d;d+=4,e+=3)h=b(a.charAt(d))<<18|b(a.charAt(d+1))<<12|b(a.charAt(d+2))<<6|b(a.charAt(d+3)),c((16711680&h)>>16),c((65280&h)>>8),c(255&h);return 2===i?(h=b(a.charAt(d))<<2|b(a.charAt(d+1))>>4,c(255&h)):1===i&&(h=b(a.charAt(d))<<10|b(a.charAt(d+1))<<4|b(a.charAt(d+2))>>2,c(h>>8&255),c(255&h)),j}function e(a){function b(a){return d.charAt(a)}function c(a){return b(a>>18&63)+b(a>>12&63)+b(a>>6&63)+b(63&a)}var e,f,g,h=a.length%3,i="";for(e=0,g=a.length-h;g>e;e+=3)f=(a[e]<<16)+(a[e+1]<<8)+a[e+2],i+=c(f);switch(h){case 1:f=a[a.length-1],i+=b(f>>2),i+=b(f<<4&63),i+="==";break;case 2:f=(a[a.length-2]<<8)+a[a.length-1],i+=b(f>>10),i+=b(f>>4&63),i+=b(f<<2&63),i+="="}return i}var f="undefined"!=typeof Uint8Array?Uint8Array:Array,g="+".charCodeAt(0),h="/".charCodeAt(0),i="0".charCodeAt(0),j="a".charCodeAt(0),k="A".charCodeAt(0),l="-".charCodeAt(0),m="_".charCodeAt(0);a.toByteArray=c,a.fromByteArray=e}("undefined"==typeof c?this.base64js={}:c)},{}],27:[function(a,b,c){(function(d,e){function f(b){"string"==typeof b?b={bindings:b}:b||(b={}),b.__proto__=l,b.module_root||(b.module_root=c.getRoot(c.getFileName())),".node"!=h.extname(b.bindings)&&(b.bindings+=".node");for(var d,e,f,g=[],j=0,k=b["try"].length;k>j;j++){d=i.apply(null,b["try"][j].map(function(a){return b[a]||a})),g.push(d);try{return e=b.path?a.resolve(d):a(d),b.path||(e.path=d),e}catch(m){if(!/not find/i.test(m.message))throw m}}throw f=new Error("Could not locate the bindings file. Tried:\n"+g.map(function(a){return b.arrow+a}).join("\n")),f.tries=g,f}var g=a("fs"),h=a("path"),i=h.join,j=h.dirname,k=g.existsSync||h.existsSync,l={arrow:d.env.NODE_BINDINGS_ARROW||" → ",compiled:d.env.NODE_BINDINGS_COMPILED_DIR||"compiled",platform:d.platform,arch:d.arch,version:d.versions.node,bindings:"bindings.node","try":[["module_root","build","bindings"],["module_root","build","Debug","bindings"],["module_root","build","Release","bindings"],["module_root","out","Debug","bindings"],["module_root","Debug","bindings"],["module_root","out","Release","bindings"],["module_root","Release","bindings"],["module_root","build","default","bindings"],["module_root","compiled","version","platform","arch","bindings"]]};b.exports=c=f,c.getFileName=function(a){var b,c=Error.prepareStackTrace,d=Error.stackTraceLimit,f={};return Error.stackTraceLimit=10,Error.prepareStackTrace=function(c,d){for(var f=0,g=d.length;g>f;f++)if(b=d[f].getFileName(),b!==e){if(!a)return;if(b!==a)return}},Error.captureStackTrace(f),f.stack,Error.prepareStackTrace=c,Error.stackTraceLimit=d,b},c.getRoot=function(a){for(var b,c=j(a);;){if("."===c&&(c=d.cwd()),k(i(c,"package.json"))||k(i(c,"node_modules")))return c;if(b===c)throw new Error('Could not find module root given file: "'+a+'". Do you have a `package.json` file? ');b=c,c=i(c,"..")}}}).call(this,a("_process"),"/node_modules\\bindings\\bindings.js")},{_process:149,fs:57,path:145}],28:[function(a,b,c){!function(b,c){"use strict";function d(a,b){if(!a)throw new Error(b||"Assertion failed")}function e(a,b){a.super_=b;var c=function(){};c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a}function f(a,b,c){return f.isBN(a)?a:(this.negative=0,this.words=null,this.length=0,this.red=null,void(null!==a&&("le"!==b&&"be"!==b||(c=b,b=10),this._init(a||0,b||10,c||"be"))))}function g(a,b,c){for(var d=0,e=Math.min(a.length,c),f=b;e>f;f++){var g=a.charCodeAt(f)-48;d<<=4,d|=g>=49&&54>=g?g-49+10:g>=17&&22>=g?g-17+10:15&g}return d}function h(a,b,c,d){for(var e=0,f=Math.min(a.length,c),g=b;f>g;g++){var h=a.charCodeAt(g)-48;e*=d,e+=h>=49?h-49+10:h>=17?h-17+10:h}return e}function i(a){for(var b=new Array(a.bitLength()),c=0;c<b.length;c++){var d=c/26|0,e=c%26;b[c]=(a.words[d]&1<<e)>>>e}return b}function j(a,b,c){c.negative=b.negative^a.negative;var d=a.length+b.length|0;c.length=d,d=d-1|0;var e=0|a.words[0],f=0|b.words[0],g=e*f,h=67108863&g,i=g/67108864|0;c.words[0]=h;for(var j=1;d>j;j++){for(var k=i>>>26,l=67108863&i,m=Math.min(j,b.length-1),n=Math.max(0,j-a.length+1);m>=n;n++){var o=j-n|0;e=0|a.words[o],f=0|b.words[n],g=e*f+l,k+=g/67108864|0,l=67108863&g}c.words[j]=0|l,i=0|k}return 0!==i?c.words[j]=0|i:c.length--,c.strip()}function k(a,b,c){c.negative=b.negative^a.negative,c.length=a.length+b.length;for(var d=0,e=0,f=0;f<c.length-1;f++){var g=e;e=0;for(var h=67108863&d,i=Math.min(f,b.length-1),j=Math.max(0,f-a.length+1);i>=j;j++){var k=f-j,l=0|a.words[k],m=0|b.words[j],n=l*m,o=67108863&n;g=g+(n/67108864|0)|0,o=o+h|0,h=67108863&o,g=g+(o>>>26)|0,e+=g>>>26,g&=67108863}c.words[f]=h,d=g,g=e}return 0!==d?c.words[f]=d:c.length--,c.strip()}function l(a,b,c){var d=new m;return d.mulp(a,b,c)}function m(a,b){this.x=a,this.y=b}function n(a,b){this.name=a,this.p=new f(b,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function o(){n.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function p(){n.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function q(){n.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function r(){n.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function s(a){if("string"==typeof a){var b=f._prime(a);this.m=b.p,this.prime=b}else d(a.gtn(1),"modulus must be greater than 1"),this.m=a,this.prime=null}function t(a){s.call(this,a),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}"object"==typeof b?b.exports=f:c.BN=f,f.BN=f,f.wordSize=26;var u;try{u=a("buffer").Buffer}catch(v){}f.isBN=function(a){return null!==a&&"object"==typeof a&&"BN"===a.constructor.name&&Array.isArray(a.words)},f.max=function(a,b){return a.cmp(b)>0?a:b},f.min=function(a,b){return a.cmp(b)<0?a:b},f.prototype._init=function(a,b,c){if("number"==typeof a)return this._initNumber(a,b,c);if("object"==typeof a)return this._initArray(a,b,c);"hex"===b&&(b=16),d(b===(0|b)&&b>=2&&36>=b),a=a.toString().replace(/\s+/g,"");var e=0;"-"===a[0]&&e++,16===b?this._parseHex(a,e):this._parseBase(a,b,e),"-"===a[0]&&(this.negative=1),this.strip(),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initNumber=function(a,b,c){0>a&&(this.negative=1,a=-a),67108864>a?(this.words=[67108863&a],this.length=1):4503599627370496>a?(this.words=[67108863&a,a/67108864&67108863],this.length=2):(d(9007199254740992>a),this.words=[67108863&a,a/67108864&67108863,1],this.length=3),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initArray=function(a,b,c){if(d("number"==typeof a.length),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var f,g,h=0;if("be"===c)for(e=a.length-1,f=0;e>=0;e-=3)g=a[e]|a[e-1]<<8|a[e-2]<<16,this.words[f]|=g<<h&67108863,this.words[f+1]=g>>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);else if("le"===c)for(e=0,f=0;e<a.length;e+=3)g=a[e]|a[e+1]<<8|a[e+2]<<16,this.words[f]|=g<<h&67108863,this.words[f+1]=g>>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);return this.strip()},f.prototype._parseHex=function(a,b){this.length=Math.ceil((a.length-b)/6),this.words=new Array(this.length);for(var c=0;c<this.length;c++)this.words[c]=0;var d,e,f=0;for(c=a.length-6,d=0;c>=b;c-=6)e=g(a,c,c+6),this.words[d]|=e<<f&67108863,this.words[d+1]|=e>>>26-f&4194303,f+=24,f>=26&&(f-=26,d++);c+6!==b&&(e=g(a,b,c+6),this.words[d]|=e<<f&67108863,this.words[d+1]|=e>>>26-f&4194303),this.strip()},f.prototype._parseBase=function(a,b,c){this.words=[0],this.length=1;for(var d=0,e=1;67108863>=e;e*=b)d++;d--,e=e/b|0;for(var f=a.length-c,g=f%d,i=Math.min(f,f-g)