@blockcerts/blockcerts-verifier 1.56.3 → 1.57.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -1
- package/bundle-stats.html +4889 -0
- package/dist/EcdsaSecp256k1Signature2019-01e33e56-6efe219a.js +4 -0
- package/dist/Ed25519Signature2020-722d8d24-df100275.js +74 -0
- package/dist/HashlinkVerifier-40818bdd-2156022a.js +11 -0
- package/dist/MerkleProof2017-ac8d147b-dd9968ca.js +1 -0
- package/dist/MerkleProof2019-6596bc5f-6920f4ea.js +3 -0
- package/dist/Suite-e65d26ad-9eb797e9.js +1 -0
- package/dist/_commonjs-dynamic-modules-1e49c0dd-3e972b61.js +1 -0
- package/dist/checkRevocationStatusList2021-904b13ff-ca07e61e.js +17 -0
- package/dist/controlVerificationMethod-80d0e7f0-27e88021.js +1 -0
- package/dist/did-key-common.esm-2e9ab4e3-8e1d8d48.js +9 -0
- package/dist/did-key-ed25519.esm-54d2cbca-52ecc5b1.js +1 -0
- package/dist/did-key-secp256k1.esm-8a01b23c-75ec86fd.js +1 -0
- package/dist/elliptic-a9d84078-bc51730e.js +1 -0
- package/dist/ensureNotRevoked-2dc26afb-7b9df556.js +1 -0
- package/dist/ensureValidIssuingKey-b950fb8b-b8fdc4d0.js +1 -0
- package/dist/index-0469d008-3e0eb763.js +1 -0
- package/dist/index-69ba64e7.js +1 -0
- package/dist/index-6d4132ca-27a349f3.js +3 -0
- package/dist/index-85f56501-cfd39fda.js +4 -0
- package/dist/index-a93e1e88-967d29f5.js +1 -0
- package/dist/index.es-1e7b4e77.js +56 -0
- package/dist/jsonld-6909fb49-1ef9cd75.js +75 -0
- package/dist/jsonld-signatures-8ecbbaa2-fff3092d.js +66 -0
- package/dist/main.js +624 -984
- package/dist/pako.esm-7a9981ef-ce496ef7.js +2 -0
- package/dist/purify-b8d8e122.js +2 -0
- package/dist/sha256-71400caa-e7398231.js +1 -0
- package/dist/tslib.es6-28b6776b-35eb20e3.js +1 -0
- package/dist/verifier-es-b337491f.js +120 -0
- package/dist/x25519-08f432f1-3fdac820.js +1 -0
- package/package.json +6 -4
- package/rollup.config.mjs +15 -5
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{f as e,A as t,p as r,c as n,h as i,o,n as s,l as a,D as u,E as c,F as h,d as l}from"./main.js";import{j as d}from"./jsonld-signatures-8ecbbaa2-fff3092d.js";import{j as f}from"./jsonld-6909fb49-1ef9cd75.js";import{s as p,b as y,d as b,r as w,a as g,k as _,e as v}from"./index-6d4132ca-27a349f3.js";import{r as m,i as E,e as k}from"./elliptic-a9d84078-bc51730e.js";import{d as S,e as R}from"./index-85f56501-cfd39fda.js";import{S as T}from"./Suite-e65d26ad-9eb797e9.js";import"./pako.esm-7a9981ef-ce496ef7.js";import"./sha256-71400caa-e7398231.js";import"./index-0469d008-3e0eb763.js";var A,x,K={exports:{}},M={},P=u(c),L=P.EventEmitter;function I(e,t){C(e,t),O(e)}function O(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function C(e,t){e.emit("error",t)}var D={destroy:function(e,r){var n=this,i=this._readableState&&this._readableState.destroyed,o=this._writableState&&this._writableState.destroyed;return i||o?(r?r(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,t(C,this,e)):t(C,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!r&&e?n._writableState?n._writableState.errorEmitted?t(O,n):(n._writableState.errorEmitted=!0,t(I,n,e)):t(I,n,e):r?(t(O,n),r(e)):t(O,n)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}},N={};var B={};function j(e,t,r){r||(r=Error);var n=function(e){var r,n;function i(r,n,i){return e.call(this,function(e,r,n){return"string"==typeof t?t:t(e,r,n)}(r,n,i))||this}return n=e,(r=i).prototype=Object.create(n.prototype),r.prototype.constructor=r,r.__proto__=n,i}(r);n.prototype.name=r.name,n.prototype.code=e,B[e]=n}function U(e,t){if(Array.isArray(e)){var r=e.length;return e=e.map((function(e){return String(e)})),r>2?"one of ".concat(t," ").concat(e.slice(0,r-1).join(", "),", or ")+e[r-1]:2===r?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}j("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),j("ERR_INVALID_ARG_TYPE",(function(e,t,r){var n,i,o,s;if("string"==typeof t&&(i="not ",t.substr(!o||o<0?0:+o,i.length)===i)?(n="must not be",t=t.replace(/^not /,"")):n="must be",function(e,t,r){return(void 0===r||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}(e," argument"))s="The ".concat(e," ").concat(n," ").concat(U(t,"type"));else{var a=function(e,t,r){return"number"!=typeof r&&(r=0),!(r+t.length>e.length)&&-1!==e.indexOf(t,r)}(e,".")?"property":"argument";s='The "'.concat(e,'" ').concat(a," ").concat(n," ").concat(U(t,"type"))}return s+=". Received type ".concat(typeof r)}),TypeError),j("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),j("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),j("ERR_STREAM_PREMATURE_CLOSE","Premature close"),j("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),j("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),j("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),j("ERR_STREAM_WRITE_AFTER_END","write after end"),j("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),j("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),j("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),N.codes=B;var V=N.codes.ERR_INVALID_OPT_VALUE;var q,W={getHighWaterMark:function(e,t,r,n){var i=function(e,t,r){return null!=e.highWaterMark?e.highWaterMark:t?e[r]:null}(t,n,r);if(null!=i){if(!isFinite(i)||Math.floor(i)!==i||i<0)throw new V(n?r:"highWaterMark",i);return Math.floor(i)}return e.objectMode?16:16384}},F={};function z(){if(q)return F;q=1;var e=p.Buffer,t=e.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function r(r){var n;switch(this.encoding=function(r){var n=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(r);if("string"!=typeof n&&(e.isEncoding===t||!t(r)))throw new Error("Unknown encoding: "+r);return n||r}(r),this.encoding){case"utf16le":this.text=o,this.end=s,n=4;break;case"utf8":this.fillLast=i,n=4;break;case"base64":this.text=a,this.end=u,n=3;break;default:return this.write=c,void(this.end=h)}this.lastNeed=0,this.lastTotal=0,this.lastChar=e.allocUnsafe(n)}function n(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function i(e){var t=this.lastTotal-this.lastNeed,r=function(e,t,r){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==r?r:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function o(e,t){if((e.length-t)%2==0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function s(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function a(e,t){var r=(e.length-t)%3;return 0===r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function u(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function c(e){return e.toString(this.encoding)}function h(e){return e&&e.length?this.write(e):""}return F.StringDecoder=r,r.prototype.write=function(e){if(0===e.length)return"";var t,r;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""},r.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},r.prototype.text=function(e,t){var r=function(e,t,r){var i=t.length-1;if(i<r)return 0;var o=n(t[i]);if(o>=0)return o>0&&(e.lastNeed=o-1),o;if(--i<r||-2===o)return 0;if(o=n(t[i]),o>=0)return o>0&&(e.lastNeed=o-2),o;if(--i<r||-2===o)return 0;if(o=n(t[i]),o>=0)return o>0&&(2===o?o=0:e.lastNeed=o-3),o;return 0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var i=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,i),e.toString("utf8",t,i)},r.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length},F}var H=N.codes.ERR_STREAM_PREMATURE_CLOSE;function $(){}var Z,X,G,Y,J=function e(t,r,n){if("function"==typeof r)return e(t,null,r);r||(r={}),n=function(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];e.apply(this,n)}}}(n||$);var i=r.readable||!1!==r.readable&&t.readable,o=r.writable||!1!==r.writable&&t.writable,s=function(){t.writable||u()},a=t._writableState&&t._writableState.finished,u=function(){o=!1,a=!0,i||n.call(t)},c=t._readableState&&t._readableState.endEmitted,h=function(){i=!1,c=!0,o||n.call(t)},l=function(e){n.call(t,e)},d=function(){var e;return i&&!c?(t._readableState&&t._readableState.ended||(e=new H),n.call(t,e)):o&&!a?(t._writableState&&t._writableState.ended||(e=new H),n.call(t,e)):void 0},f=function(){t.req.on("finish",u)};return!function(e){return e.setHeader&&"function"==typeof e.abort}(t)?o&&!t._writableState&&(t.on("end",s),t.on("close",s)):(t.on("complete",u),t.on("abort",d),t.req?f():t.on("request",f)),t.on("end",h),t.on("finish",u),!1!==r.error&&t.on("error",l),t.on("close",d),function(){t.removeListener("complete",u),t.removeListener("abort",d),t.removeListener("request",f),t.req&&t.req.removeListener("finish",u),t.removeListener("end",s),t.removeListener("close",s),t.removeListener("finish",u),t.removeListener("end",h),t.removeListener("error",l),t.removeListener("close",d)}};function Q(){if(X)return Z;var e;function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}X=1;var n=J,i=Symbol("lastResolve"),o=Symbol("lastReject"),s=Symbol("error"),a=Symbol("ended"),u=Symbol("lastPromise"),c=Symbol("handlePromise"),h=Symbol("stream");function l(e,t){return{value:e,done:t}}function d(e){var t=e[i];if(null!==t){var r=e[h].read();null!==r&&(e[u]=null,e[i]=null,e[o]=null,t(l(r,!1)))}}function f(e){t(d,e)}var p=Object.getPrototypeOf((function(){})),y=Object.setPrototypeOf((r(e={get stream(){return this[h]},next:function(){var e=this,r=this[s];if(null!==r)return Promise.reject(r);if(this[a])return Promise.resolve(l(void 0,!0));if(this[h].destroyed)return new Promise((function(r,n){t((function(){e[s]?n(e[s]):r(l(void 0,!0))}))}));var n,i=this[u];if(i)n=new Promise(function(e,t){return function(r,n){e.then((function(){t[a]?r(l(void 0,!0)):t[c](r,n)}),n)}}(i,this));else{var o=this[h].read();if(null!==o)return Promise.resolve(l(o,!1));n=new Promise(this[c])}return this[u]=n,n}},Symbol.asyncIterator,(function(){return this})),r(e,"return",(function(){var e=this;return new Promise((function(t,r){e[h].destroy(null,(function(e){e?r(e):t(l(void 0,!0))}))}))})),e),p);return Z=function(e){var t,d=Object.create(y,(r(t={},h,{value:e,writable:!0}),r(t,i,{value:null,writable:!0}),r(t,o,{value:null,writable:!0}),r(t,s,{value:null,writable:!0}),r(t,a,{value:e._readableState.endEmitted,writable:!0}),r(t,c,{value:function(e,t){var r=d[h].read();r?(d[u]=null,d[i]=null,d[o]=null,e(l(r,!1))):(d[i]=e,d[o]=t)},writable:!0}),t));return d[u]=null,n(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=d[o];return null!==t&&(d[u]=null,d[i]=null,d[o]=null,t(e)),void(d[s]=e)}var r=d[i];null!==r&&(d[u]=null,d[i]=null,d[o]=null,r(l(void 0,!0))),d[a]=!0})),e.on("readable",f.bind(null,d)),d}}const ee=M;ee.Readable=me,me.ReadableState=ve,P.EventEmitter;var te=function(e,t){return e.listeners(t).length},re=L,ne=m.Buffer,ie=e.Uint8Array||function(){};var oe,se=g;oe=se&&se.debuglog?se.debuglog("stream"):function(){};var ae,ue,ce,he=function(){if(x)return A;function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}x=1;var n=m.Buffer,i=g.inspect,o=i&&i.custom||"inspect";return A=function(){function s(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),this.head=null,this.tail=null,this.length=0}var a,u,c;return a=s,u=[{key:"push",value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r}},{key:"concat",value:function(e){if(0===this.length)return n.alloc(0);for(var t,r,i,o=n.allocUnsafe(e>>>0),s=this.head,a=0;s;)t=s.data,r=o,i=a,n.prototype.copy.call(t,r,i),a+=s.data.length,s=s.next;return o}},{key:"consume",value:function(e,t){var r;return e<this.head.data.length?(r=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):r=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),r}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(e){var t=this.head,r=1,n=t.data;for(e-=n.length;t=t.next;){var i=t.data,o=e>i.length?i.length:e;if(o===i.length?n+=i:n+=i.slice(0,e),0==(e-=o)){o===i.length?(++r,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(o));break}++r}return this.length-=r,n}},{key:"_getBuffer",value:function(e){var t=n.allocUnsafe(e),r=this.head,i=1;for(r.data.copy(t),e-=r.data.length;r=r.next;){var o=r.data,s=e>o.length?o.length:e;if(o.copy(t,t.length-e,0,s),0==(e-=s)){s===o.length?(++i,r.next?this.head=r.next:this.head=this.tail=null):(this.head=r,r.data=o.slice(s));break}++i}return this.length-=i,t}},{key:o,value:function(r,n){return i(this,function(r){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){t(r,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))}))}return r}({},n,{depth:0,customInspect:!1}))}}],u&&r(a.prototype,u),c&&r(a,c),s}(),A}(),le=D,de=W.getHighWaterMark,fe=N.codes,pe=fe.ERR_INVALID_ARG_TYPE,ye=fe.ERR_STREAM_PUSH_AFTER_EOF,be=fe.ERR_METHOD_NOT_IMPLEMENTED,we=fe.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;E(me,re);var ge=le.errorOrDestroy,_e=["error","close","destroy","pause","resume"];function ve(e,t,r){e=e||{},"boolean"!=typeof r&&(r=t instanceof ee.Duplex),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=de(this,e,"readableHighWaterMark",r),this.buffer=new he,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(ae||(ae=z().StringDecoder),this.decoder=new ae(e.encoding),this.encoding=e.encoding)}function me(e){if(!(this instanceof me))return new me(e);var t=this instanceof ee.Duplex;this._readableState=new ve(e,this,t),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),re.call(this)}function Ee(e,t,r,n,i){oe("readableAddChunk",t);var o,s=e._readableState;if(null===t)s.reading=!1,function(e,t){if(oe("onEofChunk"),t.ended)return;if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,t.sync?Te(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,Ae(e)))}(e,s);else if(i||(o=function(e,t){var r;n=t,ne.isBuffer(n)||n instanceof ie||"string"==typeof t||void 0===t||e.objectMode||(r=new pe("chunk",["string","Buffer","Uint8Array"],t));var n;return r}(s,t)),o)ge(e,o);else if(s.objectMode||t&&t.length>0)if("string"==typeof t||s.objectMode||Object.getPrototypeOf(t)===ne.prototype||(t=function(e){return ne.from(e)}(t)),n)s.endEmitted?ge(e,new we):ke(e,s,t,!0);else if(s.ended)ge(e,new ye);else{if(s.destroyed)return!1;s.reading=!1,s.decoder&&!r?(t=s.decoder.write(t),s.objectMode||0!==t.length?ke(e,s,t,!1):xe(e,s)):ke(e,s,t,!1)}else n||(s.reading=!1,xe(e,s));return!s.ended&&(s.length<s.highWaterMark||0===s.length)}function ke(e,t,r,n){t.flowing&&0===t.length&&!t.sync?(t.awaitDrain=0,e.emit("data",r)):(t.length+=t.objectMode?1:r.length,n?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&Te(e)),xe(e,t)}Object.defineProperty(me.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),me.prototype.destroy=le.destroy,me.prototype._undestroy=le.undestroy,me.prototype._destroy=function(e,t){t(e)},me.prototype.push=function(e,t){var r,n=this._readableState;return n.objectMode?r=!0:"string"==typeof e&&((t=t||n.defaultEncoding)!==n.encoding&&(e=ne.from(e,t),t=""),r=!0),Ee(this,e,t,!1,r)},me.prototype.unshift=function(e){return Ee(this,e,null,!0,!1)},me.prototype.isPaused=function(){return!1===this._readableState.flowing},me.prototype.setEncoding=function(e){ae||(ae=z().StringDecoder);var t=new ae(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var r=this._readableState.buffer.head,n="";null!==r;)n+=t.write(r.data),r=r.next;return this._readableState.buffer.clear(),""!==n&&this._readableState.buffer.push(n),this._readableState.length=n.length,this};var Se=1073741824;function Re(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=function(e){return e>=Se?e=Se:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function Te(e){var r=e._readableState;oe("emitReadable",r.needReadable,r.emittedReadable),r.needReadable=!1,r.emittedReadable||(oe("emitReadable",r.flowing),r.emittedReadable=!0,t(Ae,e))}function Ae(e){var t=e._readableState;oe("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,Ie(e)}function xe(e,r){r.readingMore||(r.readingMore=!0,t(Ke,e,r))}function Ke(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){var r=t.length;if(oe("maybeReadMore read 0"),e.read(0),r===t.length)break}t.readingMore=!1}function Me(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function Pe(e){oe("readable nexttick read 0"),e.read(0)}function Le(e,t){oe("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),Ie(e),t.flowing&&!t.reading&&e.read(0)}function Ie(e){var t=e._readableState;for(oe("flow",t.flowing);t.flowing&&null!==e.read(););}function Oe(e,t){return 0===t.length?null:(t.objectMode?r=t.buffer.shift():!e||e>=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):r=t.buffer.consume(e,t.decoder),r);var r}function Ce(e){var r=e._readableState;oe("endReadable",r.endEmitted),r.endEmitted||(r.ended=!0,t(De,r,e))}function De(e,t){if(oe("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var r=t._writableState;(!r||r.autoDestroy&&r.finished)&&t.destroy()}}function Ne(e,t){for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}me.prototype.read=function(e){oe("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return oe("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?Ce(this):Te(this),null;if(0===(e=Re(e,t))&&t.ended)return 0===t.length&&Ce(this),null;var n,i=t.needReadable;return oe("need readable",i),(0===t.length||t.length-e<t.highWaterMark)&&oe("length less than watermark",i=!0),t.ended||t.reading?oe("reading or ended",i=!1):i&&(oe("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=Re(r,t))),null===(n=e>0?Oe(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&Ce(this)),null!==n&&this.emit("data",n),n},me.prototype._read=function(e){ge(this,new be("_read()"))},me.prototype.pipe=function(e,n){var i=this,o=this._readableState;switch(o.pipesCount){case 0:o.pipes=e;break;case 1:o.pipes=[o.pipes,e];break;default:o.pipes.push(e)}o.pipesCount+=1,oe("pipe count=%d opts=%j",o.pipesCount,n);var s=(!n||!1!==n.end)&&e!==r.stdout&&e!==r.stderr?u:y;function a(t,r){oe("onunpipe"),t===i&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,oe("cleanup"),e.removeListener("close",f),e.removeListener("finish",p),e.removeListener("drain",c),e.removeListener("error",d),e.removeListener("unpipe",a),i.removeListener("end",u),i.removeListener("end",y),i.removeListener("data",l),h=!0,!o.awaitDrain||e._writableState&&!e._writableState.needDrain||c())}function u(){oe("onend"),e.end()}o.endEmitted?t(s):i.once("end",s),e.on("unpipe",a);var c=function(e){return function(){var t=e._readableState;oe("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&te(e,"data")&&(t.flowing=!0,Ie(e))}}(i);e.on("drain",c);var h=!1;function l(t){oe("ondata");var r=e.write(t);oe("dest.write",r),!1===r&&((1===o.pipesCount&&o.pipes===e||o.pipesCount>1&&-1!==Ne(o.pipes,e))&&!h&&(oe("false write response, pause",o.awaitDrain),o.awaitDrain++),i.pause())}function d(t){oe("onerror",t),y(),e.removeListener("error",d),0===te(e,"error")&&ge(e,t)}function f(){e.removeListener("finish",p),y()}function p(){oe("onfinish"),e.removeListener("close",f),y()}function y(){oe("unpipe"),i.unpipe(e)}return i.on("data",l),function(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}(e,"error",d),e.once("close",f),e.once("finish",p),e.emit("pipe",i),o.flowing||(oe("pipe resume"),i.resume()),e},me.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r)),this;if(!e){var n=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<i;o++)n[o].emit("unpipe",this,{hasUnpiped:!1});return this}var s=Ne(t.pipes,e);return-1===s||(t.pipes.splice(s,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,r)),this},me.prototype.on=function(e,r){var n=re.prototype.on.call(this,e,r),i=this._readableState;return"data"===e?(i.readableListening=this.listenerCount("readable")>0,!1!==i.flowing&&this.resume()):"readable"===e&&(i.endEmitted||i.readableListening||(i.readableListening=i.needReadable=!0,i.flowing=!1,i.emittedReadable=!1,oe("on readable",i.length,i.reading),i.length?Te(this):i.reading||t(Pe,this))),n},me.prototype.addListener=me.prototype.on,me.prototype.removeListener=function(e,r){var n=re.prototype.removeListener.call(this,e,r);return"readable"===e&&t(Me,this),n},me.prototype.removeAllListeners=function(e){var r=re.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||t(Me,this),r},me.prototype.resume=function(){var e=this._readableState;return e.flowing||(oe("resume"),e.flowing=!e.readableListening,function(e,r){r.resumeScheduled||(r.resumeScheduled=!0,t(Le,e,r))}(this,e)),e.paused=!1,this},me.prototype.pause=function(){return oe("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(oe("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},me.prototype.wrap=function(e){var t=this,r=this._readableState,n=!1;for(var i in e.on("end",(function(){if(oe("wrapped end"),r.decoder&&!r.ended){var e=r.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){(oe("wrapped data"),r.decoder&&(i=r.decoder.write(i)),r.objectMode&&null==i)||(r.objectMode||i&&i.length)&&(t.push(i)||(n=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o<_e.length;o++)e.on(_e[o],this.emit.bind(this,_e[o]));return this._read=function(t){oe("wrapped _read",t),n&&(n=!1,e.resume())},this},"function"==typeof Symbol&&(me.prototype[Symbol.asyncIterator]=function(){return void 0===ue&&(ue=Q()),ue(this)}),Object.defineProperty(me.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(me.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(me.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),me._fromList=Oe,Object.defineProperty(me.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(me.from=function(e,t){return void 0===ce&&(ce=Y?G:(Y=1,G=function(){throw new Error("Readable.from is not available in the browser")})),ce(me,e,t)});var Be=function(e,t){if(je("noDeprecation"))return e;var r=!1;return function(){if(!r){if(je("throwDeprecation"))throw new Error(t);je("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}};function je(t){try{if(!e.localStorage)return!1}catch(e){return!1}var r=e.localStorage[t];return null!=r&&"true"===String(r).toLowerCase()}const Ue=M;function Ve(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,r){var n=e.entry;e.entry=null;for(;n;){var i=n.callback;t.pendingcb--,i(r),n=n.next}t.corkedRequestsFree.next=e}(t,e)}}Ue.Writable=at,at.WritableState=st;var qe={deprecate:Be},We=L,Fe=m.Buffer,ze=e.Uint8Array||function(){};var He,$e=D,Ze=W.getHighWaterMark,Xe=N.codes,Ge=Xe.ERR_INVALID_ARG_TYPE,Ye=Xe.ERR_METHOD_NOT_IMPLEMENTED,Je=Xe.ERR_MULTIPLE_CALLBACK,Qe=Xe.ERR_STREAM_CANNOT_PIPE,et=Xe.ERR_STREAM_DESTROYED,tt=Xe.ERR_STREAM_NULL_VALUES,rt=Xe.ERR_STREAM_WRITE_AFTER_END,nt=Xe.ERR_UNKNOWN_ENCODING,it=$e.errorOrDestroy;function ot(){}function st(e,r,n){e=e||{},"boolean"!=typeof n&&(n=r instanceof Ue.Duplex),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=Ze(this,e,"writableHighWaterMark",n),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var i=!1===e.decodeStrings;this.decodeStrings=!i,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,r){var n=e._writableState,i=n.sync,o=n.writecb;if("function"!=typeof o)throw new Je;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(n),r)!function(e,r,n,i,o){--r.pendingcb,n?(t(o,i),t(ft,e,r),e._writableState.errorEmitted=!0,it(e,i)):(o(i),e._writableState.errorEmitted=!0,it(e,i),ft(e,r))}(e,n,i,r,o);else{var s=lt(n)||e.destroyed;s||n.corked||n.bufferProcessing||!n.bufferedRequest||ht(e,n),i?t(ct,e,n,s,o):ct(e,n,s,o)}}(r,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new Ve(this)}function at(e){var t=this instanceof Ue.Duplex;if(!t&&!He.call(at,this))return new at(e);this._writableState=new st(e,this,t),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),We.call(this)}function ut(e,t,r,n,i,o,s){t.writelen=n,t.writecb=s,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new et("write")):r?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function ct(e,t,r,n){r||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,n(),ft(e,t)}function ht(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=t.bufferedRequestCount,i=new Array(n),o=t.corkedRequestsFree;o.entry=r;for(var s=0,a=!0;r;)i[s]=r,r.isBuf||(a=!1),r=r.next,s+=1;i.allBuffers=a,ut(e,t,!0,t.length,i,"",o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new Ve(t),t.bufferedRequestCount=0}else{for(;r;){var u=r.chunk,c=r.encoding,h=r.callback;if(ut(e,t,!1,t.objectMode?1:u.length,u,c,h),r=r.next,t.bufferedRequestCount--,t.writing)break}null===r&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}function lt(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function dt(e,t){e._final((function(r){t.pendingcb--,r&&it(e,r),t.prefinished=!0,e.emit("prefinish"),ft(e,t)}))}function ft(e,r){var n=lt(r);if(n&&(function(e,r){r.prefinished||r.finalCalled||("function"!=typeof e._final||r.destroyed?(r.prefinished=!0,e.emit("prefinish")):(r.pendingcb++,r.finalCalled=!0,t(dt,e,r)))}(e,r),0===r.pendingcb&&(r.finished=!0,e.emit("finish"),r.autoDestroy))){var i=e._readableState;(!i||i.autoDestroy&&i.endEmitted)&&e.destroy()}return n}E(at,We),st.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(st.prototype,"buffer",{get:qe.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(He=Function.prototype[Symbol.hasInstance],Object.defineProperty(at,Symbol.hasInstance,{value:function(e){return!!He.call(this,e)||this===at&&(e&&e._writableState instanceof st)}})):He=function(e){return e instanceof this},at.prototype.pipe=function(){it(this,new Qe)},at.prototype.write=function(e,r,n){var i,o=this._writableState,s=!1,a=!o.objectMode&&(i=e,Fe.isBuffer(i)||i instanceof ze);return a&&!Fe.isBuffer(e)&&(e=function(e){return Fe.from(e)}(e)),"function"==typeof r&&(n=r,r=null),a?r="buffer":r||(r=o.defaultEncoding),"function"!=typeof n&&(n=ot),o.ending?function(e,r){var n=new rt;it(e,n),t(r,n)}(this,n):(a||function(e,r,n,i){var o;return null===n?o=new tt:"string"==typeof n||r.objectMode||(o=new Ge("chunk",["string","Buffer"],n)),!o||(it(e,o),t(i,o),!1)}(this,o,e,n))&&(o.pendingcb++,s=function(e,t,r,n,i,o){if(!r){var s=function(e,t,r){e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=Fe.from(t,r));return t}(t,n,i);n!==s&&(r=!0,i="buffer",n=s)}var a=t.objectMode?1:n.length;t.length+=a;var u=t.length<t.highWaterMark;u||(t.needDrain=!0);if(t.writing||t.corked){var c=t.lastBufferedRequest;t.lastBufferedRequest={chunk:n,encoding:i,isBuf:r,callback:o,next:null},c?c.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else ut(e,t,!1,a,n,i,o);return u}(this,o,a,e,r,n)),s},at.prototype.cork=function(){this._writableState.corked++},at.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||ht(this,e))},at.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new nt(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(at.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(at.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),at.prototype._write=function(e,t,r){r(new Ye("_write()"))},at.prototype._writev=null,at.prototype.end=function(e,r,n){var i=this._writableState;return"function"==typeof e?(n=e,e=null,r=null):"function"==typeof r&&(n=r,r=null),null!=e&&this.write(e,r),i.corked&&(i.corked=1,this.uncork()),i.ending||function(e,r,n){r.ending=!0,ft(e,r),n&&(r.finished?t(n):e.once("finish",n));r.ended=!0,e.writable=!1}(this,i,n),this},Object.defineProperty(at.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(at.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),at.prototype.destroy=$e.destroy,at.prototype._undestroy=$e.undestroy,at.prototype._destroy=function(e,t){t(e)};var pt=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};const yt=M;yt.Duplex=_t,E(_t,yt.Readable);for(var bt=pt(yt.Writable.prototype),wt=0;wt<bt.length;wt++){var gt=bt[wt];_t.prototype[gt]||(_t.prototype[gt]=yt.Writable.prototype[gt])}function _t(e){if(!(this instanceof _t))return new _t(e);yt.Readable.call(this,e),yt.Writable.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",vt)))}function vt(){this._writableState.ended||t(mt,this)}function mt(e){e.end()}Object.defineProperty(_t.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(_t.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(_t.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(_t.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}});const Et=M;Et.Transform=Kt;var kt=N.codes,St=kt.ERR_METHOD_NOT_IMPLEMENTED,Rt=kt.ERR_MULTIPLE_CALLBACK,Tt=kt.ERR_TRANSFORM_ALREADY_TRANSFORMING,At=kt.ERR_TRANSFORM_WITH_LENGTH_0;function xt(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(null===n)return this.emit("error",new Rt);r.writechunk=null,r.writecb=null,null!=t&&this.push(t),n(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function Kt(e){if(!(this instanceof Kt))return new Kt(e);Et.Duplex.call(this,e),this._transformState={afterTransform:xt.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",Mt)}function Mt(){var e=this;"function"!=typeof this._flush||this._readableState.destroyed?Pt(this,null,null):this._flush((function(t,r){Pt(e,t,r)}))}function Pt(e,t,r){if(t)return e.emit("error",t);if(null!=r&&e.push(r),e._writableState.length)throw new At;if(e._transformState.transforming)throw new Tt;return e.push(null)}E(Kt,Et.Duplex),Kt.prototype.push=function(e,t){return this._transformState.needTransform=!1,Et.Duplex.prototype.push.call(this,e,t)},Kt.prototype._transform=function(e,t,r){r(new St("_transform()"))},Kt.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},Kt.prototype._read=function(e){var t=this._transformState;null===t.writechunk||t.transforming?t.needTransform=!0:(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform))},Kt.prototype._destroy=function(e,t){Et.Duplex.prototype._destroy.call(this,e,(function(e){t(e)}))};const Lt=M;function It(e){if(!(this instanceof It))return new It(e);Transform.call(this,e)}var Ot;Lt.PassThrough=It,E(It,Lt.Transform),It.prototype._transform=function(e,t,r){r(null,e)};var Ct=N.codes,Dt=Ct.ERR_MISSING_ARGS,Nt=Ct.ERR_STREAM_DESTROYED;function Bt(e){if(e)throw e}function jt(e){e()}function Ut(e,t){return e.pipe(t)}var Vt=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n,i=function(e){return e.length?"function"!=typeof e[e.length-1]?Bt:e.pop():Bt}(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new Dt("streams");var o=t.map((function(e,r){var s=r<t.length-1;return function(e,t,r,n){n=function(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}(n);var i=!1;e.on("close",(function(){i=!0})),void 0===Ot&&(Ot=J),Ot(e,{readable:t,writable:r},(function(e){if(e)return n(e);i=!0,n()}));var o=!1;return function(t){if(!i&&!o)return o=!0,function(e){return e.setHeader&&"function"==typeof e.abort}(e)?e.abort():"function"==typeof e.destroy?e.destroy():void n(t||new Nt("pipe"))}}(e,s,r>0,(function(e){n||(n=e),e&&o.forEach(jt),s||(o.forEach(jt),i(n))}))}));return t.reduce(Ut)};!function(e,t){const r=M;(t=K.exports=r.Readable).Stream=r.Readable,t.Readable=r.Readable,t.Writable=r.Writable,t.Duplex=r.Duplex,t.Transform=r.Transform,t.PassThrough=r.PassThrough,t.finished=J,t.pipeline=Vt}(0,K.exports);var qt=K.exports,Wt=p.Buffer,Ft=qt;function zt(e){Ft.Stream.Transform.call(this),this._block=Wt.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}E(zt,Ft.Stream.Transform),zt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(e){n=e}r(n)},zt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(e){t=e}e(t)},zt.prototype.update=function(e,t){if(function(e,t){if(!Wt.isBuffer(e)&&"string"!=typeof e)throw new TypeError(t+" must be a string or a buffer")}(e,"Data"),this._finalized)throw new Error("Digest already called");Wt.isBuffer(e)||(e=Wt.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var o=0,s=8*e.length;s>0;++o)this._length[o]+=s,(s=this._length[o]/4294967296|0)>0&&(this._length[o]-=4294967296*s);return this},zt.prototype._update=function(){throw new Error("_update is not implemented")},zt.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();void 0!==e&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t},zt.prototype._digest=function(){throw new Error("_digest is not implemented")};var Ht=zt,$t=E,Zt=Ht,Xt=p.Buffer,Gt=new Array(16);function Yt(){Zt.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}function Jt(e,t){return e<<t|e>>>32-t}function Qt(e,t,r,n,i,o,s){return Jt(e+(t&r|~t&n)+i+o|0,s)+t|0}function er(e,t,r,n,i,o,s){return Jt(e+(t&n|r&~n)+i+o|0,s)+t|0}function tr(e,t,r,n,i,o,s){return Jt(e+(t^r^n)+i+o|0,s)+t|0}function rr(e,t,r,n,i,o,s){return Jt(e+(r^(t|~n))+i+o|0,s)+t|0}$t(Yt,Zt),Yt.prototype._update=function(){for(var e=Gt,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);var r=this._a,n=this._b,i=this._c,o=this._d;r=Qt(r,n,i,o,e[0],3614090360,7),o=Qt(o,r,n,i,e[1],3905402710,12),i=Qt(i,o,r,n,e[2],606105819,17),n=Qt(n,i,o,r,e[3],3250441966,22),r=Qt(r,n,i,o,e[4],4118548399,7),o=Qt(o,r,n,i,e[5],1200080426,12),i=Qt(i,o,r,n,e[6],2821735955,17),n=Qt(n,i,o,r,e[7],4249261313,22),r=Qt(r,n,i,o,e[8],1770035416,7),o=Qt(o,r,n,i,e[9],2336552879,12),i=Qt(i,o,r,n,e[10],4294925233,17),n=Qt(n,i,o,r,e[11],2304563134,22),r=Qt(r,n,i,o,e[12],1804603682,7),o=Qt(o,r,n,i,e[13],4254626195,12),i=Qt(i,o,r,n,e[14],2792965006,17),r=er(r,n=Qt(n,i,o,r,e[15],1236535329,22),i,o,e[1],4129170786,5),o=er(o,r,n,i,e[6],3225465664,9),i=er(i,o,r,n,e[11],643717713,14),n=er(n,i,o,r,e[0],3921069994,20),r=er(r,n,i,o,e[5],3593408605,5),o=er(o,r,n,i,e[10],38016083,9),i=er(i,o,r,n,e[15],3634488961,14),n=er(n,i,o,r,e[4],3889429448,20),r=er(r,n,i,o,e[9],568446438,5),o=er(o,r,n,i,e[14],3275163606,9),i=er(i,o,r,n,e[3],4107603335,14),n=er(n,i,o,r,e[8],1163531501,20),r=er(r,n,i,o,e[13],2850285829,5),o=er(o,r,n,i,e[2],4243563512,9),i=er(i,o,r,n,e[7],1735328473,14),r=tr(r,n=er(n,i,o,r,e[12],2368359562,20),i,o,e[5],4294588738,4),o=tr(o,r,n,i,e[8],2272392833,11),i=tr(i,o,r,n,e[11],1839030562,16),n=tr(n,i,o,r,e[14],4259657740,23),r=tr(r,n,i,o,e[1],2763975236,4),o=tr(o,r,n,i,e[4],1272893353,11),i=tr(i,o,r,n,e[7],4139469664,16),n=tr(n,i,o,r,e[10],3200236656,23),r=tr(r,n,i,o,e[13],681279174,4),o=tr(o,r,n,i,e[0],3936430074,11),i=tr(i,o,r,n,e[3],3572445317,16),n=tr(n,i,o,r,e[6],76029189,23),r=tr(r,n,i,o,e[9],3654602809,4),o=tr(o,r,n,i,e[12],3873151461,11),i=tr(i,o,r,n,e[15],530742520,16),r=rr(r,n=tr(n,i,o,r,e[2],3299628645,23),i,o,e[0],4096336452,6),o=rr(o,r,n,i,e[7],1126891415,10),i=rr(i,o,r,n,e[14],2878612391,15),n=rr(n,i,o,r,e[5],4237533241,21),r=rr(r,n,i,o,e[12],1700485571,6),o=rr(o,r,n,i,e[3],2399980690,10),i=rr(i,o,r,n,e[10],4293915773,15),n=rr(n,i,o,r,e[1],2240044497,21),r=rr(r,n,i,o,e[8],1873313359,6),o=rr(o,r,n,i,e[15],4264355552,10),i=rr(i,o,r,n,e[6],2734768916,15),n=rr(n,i,o,r,e[13],1309151649,21),r=rr(r,n,i,o,e[4],4149444226,6),o=rr(o,r,n,i,e[11],3174756917,10),i=rr(i,o,r,n,e[2],718787259,15),n=rr(n,i,o,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+o|0},Yt.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=Xt.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};var nr=Yt,ir=m.Buffer,or=E,sr=Ht,ar=new Array(16),ur=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],cr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],hr=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],lr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],dr=[0,1518500249,1859775393,2400959708,2840853838],fr=[1352829926,1548603684,1836072691,2053994217,0];function pr(){sr.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}function yr(e,t){return e<<t|e>>>32-t}function br(e,t,r,n,i,o,s,a){return yr(e+(t^r^n)+o+s|0,a)+i|0}function wr(e,t,r,n,i,o,s,a){return yr(e+(t&r|~t&n)+o+s|0,a)+i|0}function gr(e,t,r,n,i,o,s,a){return yr(e+((t|~r)^n)+o+s|0,a)+i|0}function _r(e,t,r,n,i,o,s,a){return yr(e+(t&n|r&~n)+o+s|0,a)+i|0}function vr(e,t,r,n,i,o,s,a){return yr(e+(t^(r|~n))+o+s|0,a)+i|0}or(pr,sr),pr.prototype._update=function(){for(var e=ar,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);for(var r=0|this._a,n=0|this._b,i=0|this._c,o=0|this._d,s=0|this._e,a=0|this._a,u=0|this._b,c=0|this._c,h=0|this._d,l=0|this._e,d=0;d<80;d+=1){var f,p;d<16?(f=br(r,n,i,o,s,e[ur[d]],dr[0],hr[d]),p=vr(a,u,c,h,l,e[cr[d]],fr[0],lr[d])):d<32?(f=wr(r,n,i,o,s,e[ur[d]],dr[1],hr[d]),p=_r(a,u,c,h,l,e[cr[d]],fr[1],lr[d])):d<48?(f=gr(r,n,i,o,s,e[ur[d]],dr[2],hr[d]),p=gr(a,u,c,h,l,e[cr[d]],fr[2],lr[d])):d<64?(f=_r(r,n,i,o,s,e[ur[d]],dr[3],hr[d]),p=wr(a,u,c,h,l,e[cr[d]],fr[3],lr[d])):(f=vr(r,n,i,o,s,e[ur[d]],dr[4],hr[d]),p=br(a,u,c,h,l,e[cr[d]],fr[4],lr[d])),r=s,s=o,o=yr(i,10),i=n,n=f,a=l,l=h,h=yr(c,10),c=u,u=p}var y=this._b+i+h|0;this._b=this._c+o+l|0,this._c=this._d+s+a|0,this._d=this._e+r+u|0,this._e=this._a+n+c|0,this._a=y},pr.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=ir.alloc?ir.alloc(20):new ir(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};var mr=pr,Er={exports:{}},kr=p.Buffer;function Sr(e,t){this._block=kr.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}Sr.prototype.update=function(e,t){"string"==typeof e&&(t=t||"utf8",e=kr.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,o=this._len,s=0;s<i;){for(var a=o%n,u=Math.min(i-s,n-a),c=0;c<u;c++)r[a+c]=e[s+c];s+=u,(o+=u)%n==0&&this._update(r)}return this._len+=i,this},Sr.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=8*this._len;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(4294967295&r)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o},Sr.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Rr=Sr,Tr=E,Ar=Rr,xr=p.Buffer,Kr=[1518500249,1859775393,-1894007588,-899497514],Mr=new Array(80);function Pr(){this.init(),this._w=Mr,Ar.call(this,64,56)}function Lr(e){return e<<30|e>>>2}function Ir(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}Tr(Pr,Ar),Pr.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},Pr.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,s=0|this._d,a=0|this._e,u=0;u<16;++u)r[u]=e.readInt32BE(4*u);for(;u<80;++u)r[u]=r[u-3]^r[u-8]^r[u-14]^r[u-16];for(var c=0;c<80;++c){var h=~~(c/20),l=0|((t=n)<<5|t>>>27)+Ir(h,i,o,s)+a+r[c]+Kr[h];a=s,s=o,o=Lr(i),i=n,n=l}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=a+this._e|0},Pr.prototype._hash=function(){var e=xr.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var Or=Pr,Cr=E,Dr=Rr,Nr=p.Buffer,Br=[1518500249,1859775393,-1894007588,-899497514],jr=new Array(80);function Ur(){this.init(),this._w=jr,Dr.call(this,64,56)}function Vr(e){return e<<5|e>>>27}function qr(e){return e<<30|e>>>2}function Wr(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}Cr(Ur,Dr),Ur.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},Ur.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,s=0|this._d,a=0|this._e,u=0;u<16;++u)r[u]=e.readInt32BE(4*u);for(;u<80;++u)r[u]=(t=r[u-3]^r[u-8]^r[u-14]^r[u-16])<<1|t>>>31;for(var c=0;c<80;++c){var h=~~(c/20),l=Vr(n)+Wr(h,i,o,s)+a+r[c]+Br[h]|0;a=s,s=o,o=qr(i),i=n,n=l}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=a+this._e|0},Ur.prototype._hash=function(){var e=Nr.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var Fr=Ur,zr=E,Hr=Rr,$r=p.Buffer,Zr=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],Xr=new Array(64);function Gr(){this.init(),this._w=Xr,Hr.call(this,64,56)}function Yr(e,t,r){return r^e&(t^r)}function Jr(e,t,r){return e&t|r&(e|t)}function Qr(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function en(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function tn(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}zr(Gr,Hr),Gr.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},Gr.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,s=0|this._d,a=0|this._e,u=0|this._f,c=0|this._g,h=0|this._h,l=0;l<16;++l)r[l]=e.readInt32BE(4*l);for(;l<64;++l)r[l]=0|(((t=r[l-2])>>>17|t<<15)^(t>>>19|t<<13)^t>>>10)+r[l-7]+tn(r[l-15])+r[l-16];for(var d=0;d<64;++d){var f=h+en(a)+Yr(a,u,c)+Zr[d]+r[d]|0,p=Qr(n)+Jr(n,i,o)|0;h=c,c=u,u=a,a=s+f|0,s=o,o=i,i=n,n=f+p|0}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=a+this._e|0,this._f=u+this._f|0,this._g=c+this._g|0,this._h=h+this._h|0},Gr.prototype._hash=function(){var e=$r.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var rn=Gr,nn=E,on=rn,sn=Rr,an=p.Buffer,un=new Array(64);function cn(){this.init(),this._w=un,sn.call(this,64,56)}nn(cn,on),cn.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this},cn.prototype._hash=function(){var e=an.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var hn=cn,ln=E,dn=Rr,fn=p.Buffer,pn=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],yn=new Array(160);function bn(){this.init(),this._w=yn,dn.call(this,128,112)}function wn(e,t,r){return r^e&(t^r)}function gn(e,t,r){return e&t|r&(e|t)}function _n(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function vn(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function mn(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function En(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function kn(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function Sn(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function Rn(e,t){return e>>>0<t>>>0?1:0}ln(bn,dn),bn.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this},bn.prototype._update=function(e){for(var t=this._w,r=0|this._ah,n=0|this._bh,i=0|this._ch,o=0|this._dh,s=0|this._eh,a=0|this._fh,u=0|this._gh,c=0|this._hh,h=0|this._al,l=0|this._bl,d=0|this._cl,f=0|this._dl,p=0|this._el,y=0|this._fl,b=0|this._gl,w=0|this._hl,g=0;g<32;g+=2)t[g]=e.readInt32BE(4*g),t[g+1]=e.readInt32BE(4*g+4);for(;g<160;g+=2){var _=t[g-30],v=t[g-30+1],m=mn(_,v),E=En(v,_),k=kn(_=t[g-4],v=t[g-4+1]),S=Sn(v,_),R=t[g-14],T=t[g-14+1],A=t[g-32],x=t[g-32+1],K=E+T|0,M=m+R+Rn(K,E)|0;M=(M=M+k+Rn(K=K+S|0,S)|0)+A+Rn(K=K+x|0,x)|0,t[g]=M,t[g+1]=K}for(var P=0;P<160;P+=2){M=t[P],K=t[P+1];var L=gn(r,n,i),I=gn(h,l,d),O=_n(r,h),C=_n(h,r),D=vn(s,p),N=vn(p,s),B=pn[P],j=pn[P+1],U=wn(s,a,u),V=wn(p,y,b),q=w+N|0,W=c+D+Rn(q,w)|0;W=(W=(W=W+U+Rn(q=q+V|0,V)|0)+B+Rn(q=q+j|0,j)|0)+M+Rn(q=q+K|0,K)|0;var F=C+I|0,z=O+L+Rn(F,C)|0;c=u,w=b,u=a,b=y,a=s,y=p,s=o+W+Rn(p=f+q|0,f)|0,o=i,f=d,i=n,d=l,n=r,l=h,r=W+z+Rn(h=q+F|0,q)|0}this._al=this._al+h|0,this._bl=this._bl+l|0,this._cl=this._cl+d|0,this._dl=this._dl+f|0,this._el=this._el+p|0,this._fl=this._fl+y|0,this._gl=this._gl+b|0,this._hl=this._hl+w|0,this._ah=this._ah+r+Rn(this._al,h)|0,this._bh=this._bh+n+Rn(this._bl,l)|0,this._ch=this._ch+i+Rn(this._cl,d)|0,this._dh=this._dh+o+Rn(this._dl,f)|0,this._eh=this._eh+s+Rn(this._el,p)|0,this._fh=this._fh+a+Rn(this._fl,y)|0,this._gh=this._gh+u+Rn(this._gl,b)|0,this._hh=this._hh+c+Rn(this._hl,w)|0},bn.prototype._hash=function(){var e=fn.allocUnsafe(64);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var Tn=bn,An=E,xn=Tn,Kn=Rr,Mn=p.Buffer,Pn=new Array(160);function Ln(){this.init(),this._w=Pn,Kn.call(this,128,112)}An(Ln,xn),Ln.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this},Ln.prototype._hash=function(){var e=Mn.allocUnsafe(48);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var In=Ln;const On={};Er.exports=function(e){e=e.toLowerCase();var t=On[e];if(!t)throw new Error(e+" is not supported (we accept pull requests)");return new t},Er.exports.sha=On.sha=Or,Er.exports.sha1=On.sha1=Fr,Er.exports.sha224=On.sha224=hn,Er.exports.sha256=On.sha256=rn,Er.exports.sha384=On.sha384=In,Er.exports.sha512=On.sha512=Tn;var Cn=Er.exports,Dn=u(h),Nn=p.Buffer,Bn=y.Transform,jn=Dn.StringDecoder;function Un(e){Bn.call(this),this.hashMode="string"==typeof e,this.hashMode?this[e]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}E(Un,Bn),Un.prototype.update=function(e,t,r){"string"==typeof e&&(e=Nn.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)},Un.prototype.setAutoPadding=function(){},Un.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")},Un.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")},Un.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")},Un.prototype._transform=function(e,t,r){var n;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(e){n=e}finally{r(n)}},Un.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(e){t=e}e(t)},Un.prototype._finalOrDigest=function(e){var t=this.__final()||Nn.alloc(0);return e&&(t=this._toString(t,e,!0)),t},Un.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new jn(t),this._encoding=t),this._encoding!==t)throw new Error("can't switch encodings");var n=this._decoder.write(e);return r&&(n+=this._decoder.end()),n};var Vn=nr,qn=mr,Wn=Cn,Fn=Un;function zn(e){Fn.call(this,"digest"),this._hash=e}E(zn,Fn),zn.prototype._update=function(e){this._hash.update(e)},zn.prototype._final=function(){return this._hash.digest()};var Hn=l((function(e){return"md5"===(e=e.toLowerCase())?new Vn:"rmd160"===e||"ripemd160"===e?new qn:new zn(Wn(e))}));const $n="Impossible case. Please create issue.",Zn="The tweak was out of range or the resulted private key is invalid",Xn="The tweak was out of range or equal to zero",Gn="Unknow error on context randomization",Yn="Private Key is invalid",Jn="Public Key could not be parsed",Qn="Public Key serialization error",ei="The sum of the public keys is not valid",ti="Signature could not be parsed",ri="The nonce generation function failed, or the private key was invalid",ni="Public key could not be recover",ii="Scalar was invalid (zero or overflow)";function oi(e,t){if(!e)throw new Error(t)}function si(e,t,r){if(oi(t instanceof Uint8Array,`Expected ${e} to be an Uint8Array`),void 0!==r)if(Array.isArray(r)){const n=`Expected ${e} to be an Uint8Array with length [${r.join(", ")}]`;oi(r.includes(t.length),n)}else{const n=`Expected ${e} to be an Uint8Array with length ${r}`;oi(t.length===r,n)}}function ai(e){oi("Boolean"===ci(e),"Expected compressed to be a Boolean")}function ui(e=(e=>new Uint8Array(e)),t){return"function"==typeof e&&(e=e(t)),si("output",e,t),e}function ci(e){return Object.prototype.toString.call(e).slice(8,-1)}const hi=new(0,k.ec)("secp256k1"),li=hi.curve,di=li.n.constructor;function fi(e){const t=e[0];switch(t){case 2:case 3:return 33!==e.length?null:function(e,t){let r=new di(t);if(r.cmp(li.p)>=0)return null;r=r.toRed(li.red);let n=r.redSqr().redIMul(r).redIAdd(li.b).redSqrt();return 3===e!==n.isOdd()&&(n=n.redNeg()),hi.keyPair({pub:{x:r,y:n}})}(t,e.subarray(1,33));case 4:case 6:case 7:return 65!==e.length?null:function(e,t,r){let n=new di(t),i=new di(r);if(n.cmp(li.p)>=0||i.cmp(li.p)>=0)return null;if(n=n.toRed(li.red),i=i.toRed(li.red),(6===e||7===e)&&i.isOdd()!==(7===e))return null;const o=n.redSqr().redIMul(n);return i.redSqr().redISub(o.redIAdd(li.b)).isZero()?hi.keyPair({pub:{x:n,y:i}}):null}(t,e.subarray(1,33),e.subarray(33,65));default:return null}}function pi(e,t){const r=t.encode(null,33===e.length);for(let t=0;t<e.length;++t)e[t]=r[t]}var yi={contextRandomize:()=>0,privateKeyVerify(e){const t=new di(e);return t.cmp(li.n)<0&&!t.isZero()?0:1},privateKeyNegate(e){const t=new di(e),r=li.n.sub(t).umod(li.n).toArrayLike(Uint8Array,"be",32);return e.set(r),0},privateKeyTweakAdd(e,t){const r=new di(t);if(r.cmp(li.n)>=0)return 1;if(r.iadd(new di(e)),r.cmp(li.n)>=0&&r.isub(li.n),r.isZero())return 1;const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},privateKeyTweakMul(e,t){let r=new di(t);if(r.cmp(li.n)>=0||r.isZero())return 1;r.imul(new di(e)),r.cmp(li.n)>=0&&(r=r.umod(li.n));const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},publicKeyVerify:e=>null===fi(e)?1:0,publicKeyCreate(e,t){const r=new di(t);if(r.cmp(li.n)>=0||r.isZero())return 1;return pi(e,hi.keyFromPrivate(t).getPublic()),0},publicKeyConvert(e,t){const r=fi(t);if(null===r)return 1;return pi(e,r.getPublic()),0},publicKeyNegate(e,t){const r=fi(t);if(null===r)return 1;const n=r.getPublic();return n.y=n.y.redNeg(),pi(e,n),0},publicKeyCombine(e,t){const r=new Array(t.length);for(let e=0;e<t.length;++e)if(r[e]=fi(t[e]),null===r[e])return 1;let n=r[0].getPublic();for(let e=1;e<r.length;++e)n=n.add(r[e].pub);return n.isInfinity()?2:(pi(e,n),0)},publicKeyTweakAdd(e,t,r){const n=fi(t);if(null===n)return 1;if((r=new di(r)).cmp(li.n)>=0)return 2;const i=n.getPublic().add(li.g.mul(r));return i.isInfinity()?2:(pi(e,i),0)},publicKeyTweakMul(e,t,r){const n=fi(t);if(null===n)return 1;if((r=new di(r)).cmp(li.n)>=0||r.isZero())return 2;return pi(e,n.getPublic().mul(r)),0},signatureNormalize(e){const t=new di(e.subarray(0,32)),r=new di(e.subarray(32,64));return t.cmp(li.n)>=0||r.cmp(li.n)>=0?1:(1===r.cmp(hi.nh)&&e.set(li.n.sub(r).toArrayLike(Uint8Array,"be",32),32),0)},signatureExport(e,t){const r=t.subarray(0,32),n=t.subarray(32,64);if(new di(r).cmp(li.n)>=0)return 1;if(new di(n).cmp(li.n)>=0)return 1;const{output:i}=e;let o=i.subarray(4,37);o[0]=0,o.set(r,1);let s=33,a=0;for(;s>1&&0===o[a]&&!(128&o[a+1]);--s,++a);if(o=o.subarray(a),128&o[0])return 1;if(s>1&&0===o[0]&&!(128&o[1]))return 1;let u=i.subarray(39,72);u[0]=0,u.set(n,1);let c=33,h=0;for(;c>1&&0===u[h]&&!(128&u[h+1]);--c,++h);return u=u.subarray(h),128&u[0]||c>1&&0===u[0]&&!(128&u[1])?1:(e.outputlen=6+s+c,i[0]=48,i[1]=e.outputlen-2,i[2]=2,i[3]=o.length,i.set(o,4),i[4+s]=2,i[5+s]=u.length,i.set(u,6+s),0)},signatureImport(e,t){if(t.length<8)return 1;if(t.length>72)return 1;if(48!==t[0])return 1;if(t[1]!==t.length-2)return 1;if(2!==t[2])return 1;const r=t[3];if(0===r)return 1;if(5+r>=t.length)return 1;if(2!==t[4+r])return 1;const n=t[5+r];if(0===n)return 1;if(6+r+n!==t.length)return 1;if(128&t[4])return 1;if(r>1&&0===t[4]&&!(128&t[5]))return 1;if(128&t[r+6])return 1;if(n>1&&0===t[r+6]&&!(128&t[r+7]))return 1;let i=t.subarray(4,4+r);if(33===i.length&&0===i[0]&&(i=i.subarray(1)),i.length>32)return 1;let o=t.subarray(6+r);if(33===o.length&&0===o[0]&&(o=o.slice(1)),o.length>32)throw new Error("S length is too long");let s=new di(i);s.cmp(li.n)>=0&&(s=new di(0));let a=new di(t.subarray(6+r));return a.cmp(li.n)>=0&&(a=new di(0)),e.set(s.toArrayLike(Uint8Array,"be",32),0),e.set(a.toArrayLike(Uint8Array,"be",32),32),0},ecdsaSign(e,t,r,n,i){if(i){const e=i;i=i=>{const o=e(t,r,null,n,i);if(!(o instanceof Uint8Array&&32===o.length))throw new Error("This is the way");return new di(o)}}const o=new di(r);if(o.cmp(li.n)>=0||o.isZero())return 1;let s;try{s=hi.sign(t,r,{canonical:!0,k:i,pers:n})}catch(e){return 1}return e.signature.set(s.r.toArrayLike(Uint8Array,"be",32),0),e.signature.set(s.s.toArrayLike(Uint8Array,"be",32),32),e.recid=s.recoveryParam,0},ecdsaVerify(e,t,r){const n={r:e.subarray(0,32),s:e.subarray(32,64)},i=new di(n.r),o=new di(n.s);if(i.cmp(li.n)>=0||o.cmp(li.n)>=0)return 1;if(1===o.cmp(hi.nh)||i.isZero()||o.isZero())return 3;const s=fi(r);if(null===s)return 2;const a=s.getPublic();return hi.verify(t,n,a)?0:3},ecdsaRecover(e,t,r,n){const i={r:t.slice(0,32),s:t.slice(32,64)},o=new di(i.r),s=new di(i.s);if(o.cmp(li.n)>=0||s.cmp(li.n)>=0)return 1;if(o.isZero()||s.isZero())return 2;let a;try{a=hi.recoverPubKey(n,i,r)}catch(e){return 2}return pi(e,a),0},ecdh(e,t,r,n,i,o,s){const a=fi(t);if(null===a)return 1;const u=new di(r);if(u.cmp(li.n)>=0||u.isZero())return 2;const c=a.getPublic().mul(u);if(void 0===i){const t=c.encode(null,!0),r=hi.hash().update(t).digest();for(let t=0;t<32;++t)e[t]=r[t]}else{o||(o=new Uint8Array(32));const t=c.getX().toArray("be",32);for(let e=0;e<32;++e)o[e]=t[e];s||(s=new Uint8Array(32));const r=c.getY().toArray("be",32);for(let e=0;e<32;++e)s[e]=r[e];const a=i(o,s,n);if(!(a instanceof Uint8Array&&a.length===e.length))return 2;e.set(a)}return 0}},bi=(e=>({contextRandomize(t){if(oi(null===t||t instanceof Uint8Array,"Expected seed to be an Uint8Array or null"),null!==t&&si("seed",t,32),1===e.contextRandomize(t))throw new Error(Gn)},privateKeyVerify:t=>(si("private key",t,32),0===e.privateKeyVerify(t)),privateKeyNegate(t){switch(si("private key",t,32),e.privateKeyNegate(t)){case 0:return t;case 1:throw new Error($n)}},privateKeyTweakAdd(t,r){switch(si("private key",t,32),si("tweak",r,32),e.privateKeyTweakAdd(t,r)){case 0:return t;case 1:throw new Error(Zn)}},privateKeyTweakMul(t,r){switch(si("private key",t,32),si("tweak",r,32),e.privateKeyTweakMul(t,r)){case 0:return t;case 1:throw new Error(Xn)}},publicKeyVerify:t=>(si("public key",t,[33,65]),0===e.publicKeyVerify(t)),publicKeyCreate(t,r=!0,n){switch(si("private key",t,32),ai(r),n=ui(n,r?33:65),e.publicKeyCreate(n,t)){case 0:return n;case 1:throw new Error(Yn);case 2:throw new Error(Qn)}},publicKeyConvert(t,r=!0,n){switch(si("public key",t,[33,65]),ai(r),n=ui(n,r?33:65),e.publicKeyConvert(n,t)){case 0:return n;case 1:throw new Error(Jn);case 2:throw new Error(Qn)}},publicKeyNegate(t,r=!0,n){switch(si("public key",t,[33,65]),ai(r),n=ui(n,r?33:65),e.publicKeyNegate(n,t)){case 0:return n;case 1:throw new Error(Jn);case 2:throw new Error($n);case 3:throw new Error(Qn)}},publicKeyCombine(t,r=!0,n){oi(Array.isArray(t),"Expected public keys to be an Array"),oi(t.length>0,"Expected public keys array will have more than zero items");for(const e of t)si("public key",e,[33,65]);switch(ai(r),n=ui(n,r?33:65),e.publicKeyCombine(n,t)){case 0:return n;case 1:throw new Error(Jn);case 2:throw new Error(ei);case 3:throw new Error(Qn)}},publicKeyTweakAdd(t,r,n=!0,i){switch(si("public key",t,[33,65]),si("tweak",r,32),ai(n),i=ui(i,n?33:65),e.publicKeyTweakAdd(i,t,r)){case 0:return i;case 1:throw new Error(Jn);case 2:throw new Error(Zn)}},publicKeyTweakMul(t,r,n=!0,i){switch(si("public key",t,[33,65]),si("tweak",r,32),ai(n),i=ui(i,n?33:65),e.publicKeyTweakMul(i,t,r)){case 0:return i;case 1:throw new Error(Jn);case 2:throw new Error(Xn)}},signatureNormalize(t){switch(si("signature",t,64),e.signatureNormalize(t)){case 0:return t;case 1:throw new Error(ti)}},signatureExport(t,r){si("signature",t,64);const n={output:r=ui(r,72),outputlen:72};switch(e.signatureExport(n,t)){case 0:return r.slice(0,n.outputlen);case 1:throw new Error(ti);case 2:throw new Error($n)}},signatureImport(t,r){switch(si("signature",t),r=ui(r,64),e.signatureImport(r,t)){case 0:return r;case 1:throw new Error(ti);case 2:throw new Error($n)}},ecdsaSign(t,r,n={},i){si("message",t,32),si("private key",r,32),oi("Object"===ci(n),"Expected options to be an Object"),void 0!==n.data&&si("options.data",n.data),void 0!==n.noncefn&&oi("Function"===ci(n.noncefn),"Expected options.noncefn to be a Function");const o={signature:i=ui(i,64),recid:null};switch(e.ecdsaSign(o,t,r,n.data,n.noncefn)){case 0:return o;case 1:throw new Error(ri);case 2:throw new Error($n)}},ecdsaVerify(t,r,n){switch(si("signature",t,64),si("message",r,32),si("public key",n,[33,65]),e.ecdsaVerify(t,r,n)){case 0:return!0;case 3:return!1;case 1:throw new Error(ti);case 2:throw new Error(Jn)}},ecdsaRecover(t,r,n,i=!0,o){switch(si("signature",t,64),oi("Number"===ci(r)&&r>=0&&r<=3,"Expected recovery id to be a Number within interval [0, 3]"),si("message",n,32),ai(i),o=ui(o,i?33:65),e.ecdsaRecover(o,t,r,n)){case 0:return o;case 1:throw new Error(ti);case 2:throw new Error(ni);case 3:throw new Error($n)}},ecdh(t,r,n={},i){switch(si("public key",t,[33,65]),si("private key",r,32),oi("Object"===ci(n),"Expected options to be an Object"),void 0!==n.data&&si("options.data",n.data),void 0!==n.hashfn?(oi("Function"===ci(n.hashfn),"Expected options.hashfn to be a Function"),void 0!==n.xbuf&&si("options.xbuf",n.xbuf,32),void 0!==n.ybuf&&si("options.ybuf",n.ybuf,32),si("output",i)):i=ui(i,32),e.ecdh(i,t,r,n.data,n.hashfn,n.xbuf,n.ybuf)){case 0:return i;case 1:throw new Error(Jn);case 2:throw new Error(ii)}}}))(yi),wi={exports:{}},gi=65536,_i=4294967295;var vi=p.Buffer,mi=e.crypto||e.msCrypto;mi&&mi.getRandomValues?wi.exports=function(e,r){if(e>_i)throw new RangeError("requested too many random bytes");var n=vi.allocUnsafe(e);if(e>0)if(e>gi)for(var i=0;i<e;i+=gi)mi.getRandomValues(n.slice(i,i+gi));else mi.getRandomValues(n);if("function"==typeof r)return t((function(){r(null,n)}));return n}:wi.exports=function(){throw new Error("Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11")};var Ei=l(wi.exports);var ki={CryptoLD:class{constructor({suites:e}={}){this.suites=e||new Map}use(e){this.suites.set(e.suite,e)}async generate(e={}){return this._suiteForType(e).generate(e)}async from(e={}){const t=this._suiteForType(e);return e["@context"]?t.fromKeyDocument({document:e}):t.from(e)}async fromKeyDocument({document:e,checkContext:t=!0,checkRevoked:r=!0}={}){if(!e)throw new TypeError('The "document" parameter is required.');return this._suiteForType(e).fromKeyDocument({document:e,checkContext:t,checkRevoked:r})}async fromKeyId({id:e,documentLoader:t,checkContext:r=!0,checkRevoked:n=!0}={}){if(!e)throw new TypeError('The "id" parameter is required.');if(!t)throw new TypeError('The "documentLoader" parameter is required.');let i;try{if(({document:i}=await t(e)),!i)throw new Error('The "documentLoader" function must return a "document" object.')}catch(e){const t=new Error("Error fetching document: "+e.message);throw t.cause=e,t}const o=i.type;if(!o)throw new Error("Key suite type not found in fetched document.");const s=this.suites.get(o);if(!s)throw new Error(`Support for suite "${o}" is not installed.`);return s.fromKeyDocument({document:i,checkContext:r,checkRevoked:n})}_installed({type:e}){return this.suites.has(e)}_suiteForType(e){const t=e&&e.type;if(!t)throw new TypeError("Missing key type.");if(!this._installed({type:t}))throw new Error(`Support for key type "${t}" is not installed.`);return this.suites.get(t)}}};
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) 2018-2021 Digital Bazaar, Inc. All rights reserved.
|
|
4
|
+
*/let Si=class{constructor({id:e,controller:t,revoked:r}={}){this.id=e,this.controller=t,this.revoked=r}static async generate(){throw new Error("Abstract method, must be implemented in subclass.")}static async fromKeyDocument({document:e,checkContext:t=!0,checkRevoked:r=!0}={}){if(!e)throw new TypeError('The "document" parameter is required.');if(t){if(![].concat(e["@context"]).includes(this.SUITE_CONTEXT))throw new Error('Key document does not contain required context "'+this.SUITE_CONTEXT+'".')}if(r&&e.revoked)throw new Error(`Key has been revoked since: "${e.revoked}".`);return this.from(e)}static async from(){throw new Error("Abstract method from() must be implemented in subclass.")}export({publicKey:e=!1,privateKey:t=!1}={}){if(!e&&!t)throw new Error('Export requires specifying either "publicKey" or "privateKey".');const r={id:this.id,type:this.type,controller:this.controller};return this.revoked&&(r.revoked=this.revoked),r}fingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}verifyFingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}signer(){return{async sign({}){throw new Error("Abstract method, must be implemented in subclass.")}}}verifier(){return{async verify({}){throw new Error("Abstract method, must be implemented in subclass.")}}}};Si.SUITE_CONTEXT="INVALID LDKeyPair CONTEXT";var Ri={LDKeyPair:Si};const{CryptoLD:Ti}=ki,{LDKeyPair:Ai}=Ri;var xi=l({CryptoLD:Ti,LDKeyPair:Ai});const Ki="EcdsaSecp256k1VerificationKey2019",Mi=e=>Hn("sha256").update(e).digest();class Pi extends xi.LDKeyPair{constructor({publicKeyBase58:e,privateKeyBase58:t,...r}){if(super(r),this.type=void 0,this.publicKeyBase58=void 0,this.privateKeyBase58=void 0,t&&!e){const e=bi.publicKeyCreate(S(t));this.publicKeyBase58=R(e)}else this.publicKeyBase58=e;if(this.type=Ki,this.privateKeyBase58=t,!this.publicKeyBase58)throw new TypeError('The "publicKeyBase58" property is required.')}static from(e){if(e.publicKeyHex||e.privateKeyHex){const{publicKeyHex:t,privateKeyHex:r,...i}=e;return new Pi({...i,publicKeyBase58:t?R(n.from(t,"hex")):void 0,privateKeyBase58:r?R(n.from(r,"hex")):void 0})}return new Pi(e)}static async generate({seed:e,compressed:t,...r}){if(e&&!bi.privateKeyVerify(e))throw new Error("Provided seed is not a valid private key");let n=e;for(;void 0===n||!bi.privateKeyVerify(n);)n=new Uint8Array(Ei(32));const i=bi.publicKeyCreate(n,t);return new Pi({publicKeyBase58:R(i),privateKeyBase58:R(n),...r})}export({publicKey:e=!1,privateKey:t=!1,includeContext:r=!1}={}){if(!e&&!t)throw new TypeError('export requires specifying either "publicKey" or "privateKey".');if(t&&!this.privateKeyBase58)throw new TypeError("No privateKey to export.");if(e&&!this.publicKeyBase58)throw new TypeError("No publicKey to export.");const n={type:this.type,id:this.id,controller:this.controller,revoked:this.revoked};return r&&(n["@context"]=Pi.SUITE_CONTEXT),t&&(n.privateKeyBase58=this.privateKeyBase58),e&&(n.publicKeyBase58=this.publicKeyBase58),n}signer(){const{privateKeyBase58:e}=this;return e?{async sign({data:t}){const r=b.encode(JSON.stringify({alg:"ES256K",b64:!1,crit:["b64"]})),i=n.from(t.buffer,t.byteOffset,t.length),o=Mi(n.from(n.concat([n.from(`${r}.`,"utf8"),n.from(i.buffer,i.byteOffset,i.length)]))),{signature:s}=bi.ecdsaSign(o,S(e));return`${r}..${b.encode(n.from(s))}`},id:this.id}:{async sign(){throw new Error("No private key to sign with.")},id:this.id}}verifier(){const{publicKeyBase58:e}=this;return e?{async verify({data:t,signature:r}){if(r.indexOf("..")<0)return!1;const[i,o]=r.split(".."),s=JSON.parse(b.decode(i));if("ES256K"!==s.alg||!1!==s.b64||!s.crit||!s.crit.length||"b64"!==s.crit[0])return!1;const a=n.from(t.buffer,t.byteOffset,t.length),u=Mi(n.from(n.concat([n.from(`${i}.`,"utf8"),n.from(a.buffer,a.byteOffset,a.length)])));let c;try{c=bi.ecdsaVerify(n.from(b.decode(o,"hex"),"hex"),u,S(e))}catch(e){c=!1}return c},id:this.id}:{async verify(){throw new Error("No public key to verify against")},id:this.id}}}Pi.suite=Ki,Pi.SUITE_CONTEXT="https://ns.did.ai/suites/secp256k1-2019/v1";const Li="https://ns.did.ai/suites/secp256k1-2019/v1",Ii=({document:e,contextUrl:t})=>{const r=e["@context"];return r===t||Array.isArray(r)&&r.includes(t)},Oi=({document:e})=>{const t=Ii({document:e,contextUrl:Li}),r=Ii({document:e,contextUrl:"https://www.w3.org/2018/credentials/v1"}),n=Ii({document:e,contextUrl:"https://w3id.org/security/v2"});return t&&r?(console.warn("Warning: The secp256k1-2019/v1 and credentials/v1 contexts are incompatible."),console.warn("For VCs using EcdsaSecp256k1Signature2019 suite, using the credentials/v1 context is sufficient."),!1):t&&n?(console.warn("Warning: The secp256k1-2019/v1 and security/v2 contexts are incompatible."),console.warn("For VCs using EcdsaSecp256k1Signature2019 suite, using the security/v2 context is sufficient."),!1):t||r||n};let Ci=class extends d.suites.LinkedDataSignature{constructor(e={}){super({type:"EcdsaSecp256k1Signature2019",LDKeyClass:Pi,contextUrl:Li,...e}),this.requiredKeyType=void 0,this.requiredKeyType="EcdsaSecp256k1VerificationKey2019"}async sign({verifyData:e,proof:t}){if(!this.signer||"function"!=typeof this.signer.sign)throw new Error("A signer API has not been specified.");return{...t,jws:await this.signer.sign({data:e})}}async verifySignature({verifyData:e,verificationMethod:t,proof:r}){const{jws:n}=r;if(!n||"string"!=typeof n)throw new TypeError('The proof does not include a valid "jws" property.');let{verifier:i}=this;if(!i){i=(await this.LDKeyClass.from(t)).verifier()}return i.verify({data:e,signature:n})}async assertVerificationMethod({verificationMethod:e}){if(!Oi({document:e}))throw new TypeError(`The verification method (key) must contain "${this.contextUrl}".`);if(!f.hasValue(e,"type",this.requiredKeyType))throw new Error(`Invalid key type. Key type must be "${this.requiredKeyType}".`);if(void 0!==e.revoked)throw new Error("The verification method has been revoked.")}async getVerificationMethod({proof:e,documentLoader:t}){if(this.key)return this.key.export({publicKey:!0});const r="object"==typeof e.verificationMethod?e.verificationMethod.id:e.verificationMethod;if(!r)throw new Error('No "verificationMethod" found in proof.');const n=await f.frame(r,{"@context":this.contextUrl,"@embed":"@always",id:r},{documentLoader:t,compactToRelative:!1});if(!n)throw new Error(`Verification method ${r} not found.`);if(void 0!==n.revoked)throw new Error("The verification method has been revoked.");return await this.assertVerificationMethod({verificationMethod:n}),n}async matchProof({proof:e,document:t,purpose:r,documentLoader:n,expansionMap:i}){if(!Oi({document:t}))return!1;if(!await super.matchProof({proof:e,document:t,purpose:r,documentLoader:n,expansionMap:i}))return!1;if(!this.key)return!0;const{verificationMethod:o}=e,s="object"==typeof o?o.id:o;return this.isVerificationMethodMatchingKeyId(s)}ensureSuiteContext({document:e,addSuiteContext:t}){Oi({document:e})||super.ensureSuiteContext({document:e,addSuiteContext:t})}isVerificationMethodMatchingKeyId(e){return e===this.key.id||e===`${this.key.controller}${this.key.id}`}};Ci.CONTEXT_URL=Li,Ci.CONTEXT={"@context":{id:"@id",type:"@type","@protected":!0,proof:{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"},EcdsaSecp256k1VerificationKey2019:{"@id":"https://w3id.org/security#EcdsaSecp256k1VerificationKey2019","@context":{"@protected":!0,id:"@id",type:"@type",controller:{"@id":"https://w3id.org/security#controller","@type":"@id"},revoked:{"@id":"https://w3id.org/security#revoked","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},blockchainAccountId:{"@id":"https://w3id.org/security#blockchainAccountId"},publicKeyJwk:{"@id":"https://w3id.org/security#publicKeyJwk","@type":"@json"},publicKeyBase58:{"@id":"https://w3id.org/security#publicKeyBase58"},publicKeyMultibase:{"@id":"https://w3id.org/security#publicKeyMultibase","@type":"https://w3id.org/security#multibase"}}},EcdsaSecp256k1Signature2019:{"@id":"https://w3id.org/security#EcdsaSecp256k1Signature2019","@context":{"@protected":!0,id:"@id",type:"@type",challenge:"https://w3id.org/security#challenge",created:{"@id":"http://purl.org/dc/terms/created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},domain:"https://w3id.org/security#domain",expires:{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},nonce:"https://w3id.org/security#nonce",proofPurpose:{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":!0,id:"@id",type:"@type",assertionMethod:{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},capabilityInvocation:{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},capabilityDelegation:{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},keyAgreement:{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},jws:{"@id":"https://w3id.org/security#jws"},verificationMethod:{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}}}};const Di="Impossible case. Please create issue.",Ni="The tweak was out of range or the resulted private key is invalid",Bi="The tweak was out of range or equal to zero",ji="Unknow error on context randomization",Ui="Private Key is invalid",Vi="Public Key could not be parsed",qi="Public Key serialization error",Wi="The sum of the public keys is not valid",Fi="Signature could not be parsed",zi="The nonce generation function failed, or the private key was invalid",Hi="Public key could not be recover",$i="Scalar was invalid (zero or overflow)";function Zi(e,t){if(!e)throw new Error(t)}function Xi(e,t,r){if(Zi(t instanceof Uint8Array,`Expected ${e} to be an Uint8Array`),void 0!==r)if(Array.isArray(r)){const n=`Expected ${e} to be an Uint8Array with length [${r.join(", ")}]`;Zi(r.includes(t.length),n)}else{const n=`Expected ${e} to be an Uint8Array with length ${r}`;Zi(t.length===r,n)}}function Gi(e){Zi("Boolean"===Ji(e),"Expected compressed to be a Boolean")}function Yi(e=(e=>new Uint8Array(e)),t){return"function"==typeof e&&(e=e(t)),Xi("output",e,t),e}function Ji(e){return Object.prototype.toString.call(e).slice(8,-1)}const Qi=new(0,k.ec)("secp256k1"),eo=Qi.curve,to=eo.n.constructor;function ro(e){const t=e[0];switch(t){case 2:case 3:return 33!==e.length?null:function(e,t){let r=new to(t);if(r.cmp(eo.p)>=0)return null;r=r.toRed(eo.red);let n=r.redSqr().redIMul(r).redIAdd(eo.b).redSqrt();return 3===e!==n.isOdd()&&(n=n.redNeg()),Qi.keyPair({pub:{x:r,y:n}})}(t,e.subarray(1,33));case 4:case 6:case 7:return 65!==e.length?null:function(e,t,r){let n=new to(t),i=new to(r);if(n.cmp(eo.p)>=0||i.cmp(eo.p)>=0)return null;if(n=n.toRed(eo.red),i=i.toRed(eo.red),(6===e||7===e)&&i.isOdd()!==(7===e))return null;const o=n.redSqr().redIMul(n);return i.redSqr().redISub(o.redIAdd(eo.b)).isZero()?Qi.keyPair({pub:{x:n,y:i}}):null}(t,e.subarray(1,33),e.subarray(33,65));default:return null}}function no(e,t){const r=t.encode(null,33===e.length);for(let t=0;t<e.length;++t)e[t]=r[t]}var io={contextRandomize:()=>0,privateKeyVerify(e){const t=new to(e);return t.cmp(eo.n)<0&&!t.isZero()?0:1},privateKeyNegate(e){const t=new to(e),r=eo.n.sub(t).umod(eo.n).toArrayLike(Uint8Array,"be",32);return e.set(r),0},privateKeyTweakAdd(e,t){const r=new to(t);if(r.cmp(eo.n)>=0)return 1;if(r.iadd(new to(e)),r.cmp(eo.n)>=0&&r.isub(eo.n),r.isZero())return 1;const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},privateKeyTweakMul(e,t){let r=new to(t);if(r.cmp(eo.n)>=0||r.isZero())return 1;r.imul(new to(e)),r.cmp(eo.n)>=0&&(r=r.umod(eo.n));const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},publicKeyVerify:e=>null===ro(e)?1:0,publicKeyCreate(e,t){const r=new to(t);if(r.cmp(eo.n)>=0||r.isZero())return 1;return no(e,Qi.keyFromPrivate(t).getPublic()),0},publicKeyConvert(e,t){const r=ro(t);if(null===r)return 1;return no(e,r.getPublic()),0},publicKeyNegate(e,t){const r=ro(t);if(null===r)return 1;const n=r.getPublic();return n.y=n.y.redNeg(),no(e,n),0},publicKeyCombine(e,t){const r=new Array(t.length);for(let e=0;e<t.length;++e)if(r[e]=ro(t[e]),null===r[e])return 1;let n=r[0].getPublic();for(let e=1;e<r.length;++e)n=n.add(r[e].pub);return n.isInfinity()?2:(no(e,n),0)},publicKeyTweakAdd(e,t,r){const n=ro(t);if(null===n)return 1;if((r=new to(r)).cmp(eo.n)>=0)return 2;const i=n.getPublic().add(eo.g.mul(r));return i.isInfinity()?2:(no(e,i),0)},publicKeyTweakMul(e,t,r){const n=ro(t);if(null===n)return 1;if((r=new to(r)).cmp(eo.n)>=0||r.isZero())return 2;return no(e,n.getPublic().mul(r)),0},signatureNormalize(e){const t=new to(e.subarray(0,32)),r=new to(e.subarray(32,64));return t.cmp(eo.n)>=0||r.cmp(eo.n)>=0?1:(1===r.cmp(Qi.nh)&&e.set(eo.n.sub(r).toArrayLike(Uint8Array,"be",32),32),0)},signatureExport(e,t){const r=t.subarray(0,32),n=t.subarray(32,64);if(new to(r).cmp(eo.n)>=0)return 1;if(new to(n).cmp(eo.n)>=0)return 1;const{output:i}=e;let o=i.subarray(4,37);o[0]=0,o.set(r,1);let s=33,a=0;for(;s>1&&0===o[a]&&!(128&o[a+1]);--s,++a);if(o=o.subarray(a),128&o[0])return 1;if(s>1&&0===o[0]&&!(128&o[1]))return 1;let u=i.subarray(39,72);u[0]=0,u.set(n,1);let c=33,h=0;for(;c>1&&0===u[h]&&!(128&u[h+1]);--c,++h);return u=u.subarray(h),128&u[0]||c>1&&0===u[0]&&!(128&u[1])?1:(e.outputlen=6+s+c,i[0]=48,i[1]=e.outputlen-2,i[2]=2,i[3]=o.length,i.set(o,4),i[4+s]=2,i[5+s]=u.length,i.set(u,6+s),0)},signatureImport(e,t){if(t.length<8)return 1;if(t.length>72)return 1;if(48!==t[0])return 1;if(t[1]!==t.length-2)return 1;if(2!==t[2])return 1;const r=t[3];if(0===r)return 1;if(5+r>=t.length)return 1;if(2!==t[4+r])return 1;const n=t[5+r];if(0===n)return 1;if(6+r+n!==t.length)return 1;if(128&t[4])return 1;if(r>1&&0===t[4]&&!(128&t[5]))return 1;if(128&t[r+6])return 1;if(n>1&&0===t[r+6]&&!(128&t[r+7]))return 1;let i=t.subarray(4,4+r);if(33===i.length&&0===i[0]&&(i=i.subarray(1)),i.length>32)return 1;let o=t.subarray(6+r);if(33===o.length&&0===o[0]&&(o=o.slice(1)),o.length>32)throw new Error("S length is too long");let s=new to(i);s.cmp(eo.n)>=0&&(s=new to(0));let a=new to(t.subarray(6+r));return a.cmp(eo.n)>=0&&(a=new to(0)),e.set(s.toArrayLike(Uint8Array,"be",32),0),e.set(a.toArrayLike(Uint8Array,"be",32),32),0},ecdsaSign(e,t,r,n,i){if(i){const e=i;i=i=>{const o=e(t,r,null,n,i);if(!(o instanceof Uint8Array&&32===o.length))throw new Error("This is the way");return new to(o)}}const o=new to(r);if(o.cmp(eo.n)>=0||o.isZero())return 1;let s;try{s=Qi.sign(t,r,{canonical:!0,k:i,pers:n})}catch(e){return 1}return e.signature.set(s.r.toArrayLike(Uint8Array,"be",32),0),e.signature.set(s.s.toArrayLike(Uint8Array,"be",32),32),e.recid=s.recoveryParam,0},ecdsaVerify(e,t,r){const n={r:e.subarray(0,32),s:e.subarray(32,64)},i=new to(n.r),o=new to(n.s);if(i.cmp(eo.n)>=0||o.cmp(eo.n)>=0)return 1;if(1===o.cmp(Qi.nh)||i.isZero()||o.isZero())return 3;const s=ro(r);if(null===s)return 2;const a=s.getPublic();return Qi.verify(t,n,a)?0:3},ecdsaRecover(e,t,r,n){const i={r:t.slice(0,32),s:t.slice(32,64)},o=new to(i.r),s=new to(i.s);if(o.cmp(eo.n)>=0||s.cmp(eo.n)>=0)return 1;if(o.isZero()||s.isZero())return 2;let a;try{a=Qi.recoverPubKey(n,i,r)}catch(e){return 2}return no(e,a),0},ecdh(e,t,r,n,i,o,s){const a=ro(t);if(null===a)return 1;const u=new to(r);if(u.cmp(eo.n)>=0||u.isZero())return 2;const c=a.getPublic().mul(u);if(void 0===i){const t=c.encode(null,!0),r=Qi.hash().update(t).digest();for(let t=0;t<32;++t)e[t]=r[t]}else{o||(o=new Uint8Array(32));const t=c.getX().toArray("be",32);for(let e=0;e<32;++e)o[e]=t[e];s||(s=new Uint8Array(32));const r=c.getY().toArray("be",32);for(let e=0;e<32;++e)s[e]=r[e];const a=i(o,s,n);if(!(a instanceof Uint8Array&&a.length===e.length))return 2;e.set(a)}return 0}},oo=(e=>({contextRandomize(t){if(Zi(null===t||t instanceof Uint8Array,"Expected seed to be an Uint8Array or null"),null!==t&&Xi("seed",t,32),1===e.contextRandomize(t))throw new Error(ji)},privateKeyVerify:t=>(Xi("private key",t,32),0===e.privateKeyVerify(t)),privateKeyNegate(t){switch(Xi("private key",t,32),e.privateKeyNegate(t)){case 0:return t;case 1:throw new Error(Di)}},privateKeyTweakAdd(t,r){switch(Xi("private key",t,32),Xi("tweak",r,32),e.privateKeyTweakAdd(t,r)){case 0:return t;case 1:throw new Error(Ni)}},privateKeyTweakMul(t,r){switch(Xi("private key",t,32),Xi("tweak",r,32),e.privateKeyTweakMul(t,r)){case 0:return t;case 1:throw new Error(Bi)}},publicKeyVerify:t=>(Xi("public key",t,[33,65]),0===e.publicKeyVerify(t)),publicKeyCreate(t,r=!0,n){switch(Xi("private key",t,32),Gi(r),n=Yi(n,r?33:65),e.publicKeyCreate(n,t)){case 0:return n;case 1:throw new Error(Ui);case 2:throw new Error(qi)}},publicKeyConvert(t,r=!0,n){switch(Xi("public key",t,[33,65]),Gi(r),n=Yi(n,r?33:65),e.publicKeyConvert(n,t)){case 0:return n;case 1:throw new Error(Vi);case 2:throw new Error(qi)}},publicKeyNegate(t,r=!0,n){switch(Xi("public key",t,[33,65]),Gi(r),n=Yi(n,r?33:65),e.publicKeyNegate(n,t)){case 0:return n;case 1:throw new Error(Vi);case 2:throw new Error(Di);case 3:throw new Error(qi)}},publicKeyCombine(t,r=!0,n){Zi(Array.isArray(t),"Expected public keys to be an Array"),Zi(t.length>0,"Expected public keys array will have more than zero items");for(const e of t)Xi("public key",e,[33,65]);switch(Gi(r),n=Yi(n,r?33:65),e.publicKeyCombine(n,t)){case 0:return n;case 1:throw new Error(Vi);case 2:throw new Error(Wi);case 3:throw new Error(qi)}},publicKeyTweakAdd(t,r,n=!0,i){switch(Xi("public key",t,[33,65]),Xi("tweak",r,32),Gi(n),i=Yi(i,n?33:65),e.publicKeyTweakAdd(i,t,r)){case 0:return i;case 1:throw new Error(Vi);case 2:throw new Error(Ni)}},publicKeyTweakMul(t,r,n=!0,i){switch(Xi("public key",t,[33,65]),Xi("tweak",r,32),Gi(n),i=Yi(i,n?33:65),e.publicKeyTweakMul(i,t,r)){case 0:return i;case 1:throw new Error(Vi);case 2:throw new Error(Bi)}},signatureNormalize(t){switch(Xi("signature",t,64),e.signatureNormalize(t)){case 0:return t;case 1:throw new Error(Fi)}},signatureExport(t,r){Xi("signature",t,64);const n={output:r=Yi(r,72),outputlen:72};switch(e.signatureExport(n,t)){case 0:return r.slice(0,n.outputlen);case 1:throw new Error(Fi);case 2:throw new Error(Di)}},signatureImport(t,r){switch(Xi("signature",t),r=Yi(r,64),e.signatureImport(r,t)){case 0:return r;case 1:throw new Error(Fi);case 2:throw new Error(Di)}},ecdsaSign(t,r,n={},i){Xi("message",t,32),Xi("private key",r,32),Zi("Object"===Ji(n),"Expected options to be an Object"),void 0!==n.data&&Xi("options.data",n.data),void 0!==n.noncefn&&Zi("Function"===Ji(n.noncefn),"Expected options.noncefn to be a Function");const o={signature:i=Yi(i,64),recid:null};switch(e.ecdsaSign(o,t,r,n.data,n.noncefn)){case 0:return o;case 1:throw new Error(zi);case 2:throw new Error(Di)}},ecdsaVerify(t,r,n){switch(Xi("signature",t,64),Xi("message",r,32),Xi("public key",n,[33,65]),e.ecdsaVerify(t,r,n)){case 0:return!0;case 3:return!1;case 1:throw new Error(Fi);case 2:throw new Error(Vi)}},ecdsaRecover(t,r,n,i=!0,o){switch(Xi("signature",t,64),Zi("Number"===Ji(r)&&r>=0&&r<=3,"Expected recovery id to be a Number within interval [0, 3]"),Xi("message",n,32),Gi(i),o=Yi(o,i?33:65),e.ecdsaRecover(o,t,r,n)){case 0:return o;case 1:throw new Error(Fi);case 2:throw new Error(Hi);case 3:throw new Error(Di)}},ecdh(t,r,n={},i){switch(Xi("public key",t,[33,65]),Xi("private key",r,32),Zi("Object"===Ji(n),"Expected options to be an Object"),void 0!==n.data&&Xi("options.data",n.data),void 0!==n.hashfn?(Zi("Function"===Ji(n.hashfn),"Expected options.hashfn to be a Function"),void 0!==n.xbuf&&Xi("options.xbuf",n.xbuf,32),void 0!==n.ybuf&&Xi("options.ybuf",n.ybuf,32),Xi("output",i)):i=Yi(i,32),e.ecdh(i,t,r,n.data,n.hashfn,n.xbuf,n.ybuf)){case 0:return i;case 1:throw new Error(Vi);case 2:throw new Error($i)}}}))(io),so=l(oo);const ao="undefined"==typeof Buffer?n:Buffer,{purposes:{AssertionProofPurpose:uo}}=d;var co;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.checkDocumentSignature="checkDocumentSignature"}(co||(co={}));class ho extends T{verificationProcess=[co.retrieveVerificationMethodPublicKey,co.checkDocumentSignature];documentToVerify;issuer;proof;type="EcdsaSecp256k1Signature2019";verificationKey;publicKey;constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.issuer=e.issuer,this.proof=e.proof,this.validateProofType()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(e){return this.verificationProcess.map((t=>i.verifier.convertToVerificationSubsteps(e,t)))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(e){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(e,t,r){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}validateProofType(){const e=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}isProofChain(){return"ChainedProof2021"===this.proof.type}generateDocumentLoader(){o[this.documentToVerify.issuer]=this.getTargetVerificationMethodContainer();return function(e){return e in o?{contextUrl:null,document:o[e],documentUrl:e}:f.documentLoader(e)}}retrieveInitialDocument(){const e=s(this.documentToVerify);if(Array.isArray(e.proof)){const t=e.proof.find((e=>e.type===this.type));delete e.proof,e.proof=t}return e}getTargetVerificationMethodContainer(){return this.issuer.didDocument??this.issuer}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(co.retrieveVerificationMethodPublicKey,(async()=>{const e=await w(this.getTargetVerificationMethodContainer(),this.proof.verificationMethod);if(e.publicKeyJwk&&!e.publicKeyBase58){const r=(e=>{const t=_.from({...e,crv:"K-256"},"jwk").toString("blk","public"),r=so.publicKeyConvert(ao.from(t,"hex"),!0);return ao.from(r).toString("hex")})(e.publicKeyJwk);e.publicKeyBase58=(t=r,v.encode(ao.from(t,"hex")))}var t;this.publicKey=e.publicKeyBase58;const r=await Pi.from({...e});if(!r)throw new a(co.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(r.revoked)throw new a(co.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return r}),this.type)}async checkDocumentSignature(){await this.executeStep(co.checkDocumentSignature,(async()=>{const e=new Ci({key:this.verificationKey});e.date=new Date(Date.now()).toISOString();const t=await d.verify(this.retrieveInitialDocument(),{suite:e,purpose:new uo,documentLoader:this.generateDocumentLoader()});if(!t.verified)throw console.error(JSON.stringify(t,null,2)),new a(co.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed`);console.log("Credential Secp256k1 signature successfully verified")}),this.type)}}export{ho as default};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import{h as e,o as t,n as r,l as n,y as i,c as o,i as a}from"./main.js";import{j as s}from"./jsonld-signatures-8ecbbaa2-fff3092d.js";import{j as c}from"./jsonld-6909fb49-1ef9cd75.js";import{d as u,e as f}from"./index-85f56501-cfd39fda.js";import{_ as p}from"./tslib.es6-28b6776b-35eb20e3.js";import{x as l,e as y}from"./x25519-08f432f1-3fdac820.js";import{d as h}from"./index-a93e1e88-967d29f5.js";import{S as d}from"./Suite-e65d26ad-9eb797e9.js";import"./_commonjs-dynamic-modules-1e49c0dd-3e972b61.js";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
|
|
4
|
+
*/const w="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",v=[62,-1,-1,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,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,-1,-1,-1,-1,63,-1,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];function g(e){if(!(e instanceof Uint8Array||"string"==typeof e))throw new TypeError('"input" be a string or Uint8Array.');"string"==typeof e&&(e=(new TextEncoder).encode(e));let t,r,n,i="",o=0;for(;o<e.byteLength;)t=e[o++],r=e[o++],n=e[o++],i+=w.charAt(t>>2),i+=w.charAt((3&t)<<4|r>>4),isNaN(r)||(i+=w.charAt((15&r)<<2|n>>6),isNaN(n)||(i+=w.charAt(63&n)));return i}
|
|
5
|
+
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
|
6
|
+
const b=BigInt(0),m=BigInt(1),E=BigInt(2),K=BigInt(8),x=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),T=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:x,n:x,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")}),A=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),k=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742");const O=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),S=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),M=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),U=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");class B{constructor(e,t,r,n){this.x=e,this.y=t,this.z=r,this.t=n}static fromAffine(e){if(!(e instanceof R))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return e.equals(R.ZERO)?B.ZERO:new B(e.x,e.y,m,Z(e.x*e.y))}static toAffineBatch(e){const t=function(e,t=T.P){const r=new Array(e.length),n=H(e.reduce(((e,n,i)=>n===b?e:(r[i]=e,Z(e*n,t))),m),t);return e.reduceRight(((e,n,i)=>n===b?e:(r[i]=Z(e*r[i],t),Z(e*n,t))),n),r}(e.map((e=>e.z)));return e.map(((e,r)=>e.toAffine(t[r])))}static normalizeZ(e){return this.toAffineBatch(e).map(this.fromAffine)}equals(e){L(e);const{x:t,y:r,z:n}=this,{x:i,y:o,z:a}=e,s=Z(t*a),c=Z(i*n),u=Z(r*a),f=Z(o*n);return s===c&&u===f}negate(){return new B(Z(-this.x),this.y,this.z,Z(-this.t))}double(){const{x:e,y:t,z:r}=this,{a:n}=T,i=Z(e*e),o=Z(t*t),a=Z(E*Z(r*r)),s=Z(n*i),c=e+t,u=Z(Z(c*c)-i-o),f=s+o,p=f-a,l=s-o,y=Z(u*p),h=Z(f*l),d=Z(u*l),w=Z(p*f);return new B(y,h,w,d)}add(e){L(e);const{x:t,y:r,z:n,t:i}=this,{x:o,y:a,z:s,t:c}=e,u=Z((r-t)*(a+o)),f=Z((r+t)*(a-o)),p=Z(f-u);if(p===b)return this.double();const l=Z(n*E*c),y=Z(i*E*s),h=y+l,d=f+u,w=y-l,v=Z(h*p),g=Z(d*w),m=Z(h*w),K=Z(p*d);return new B(v,g,K,m)}subtract(e){return this.add(e.negate())}precomputeWindow(e){const t=1+256/e,r=[];let n=this,i=n;for(let o=0;o<t;o++){i=n,r.push(i);for(let t=1;t<2**(e-1);t++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(e,t){!t&&this.equals(B.BASE)&&(t=R.BASE);const r=t&&t._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=t&&C.get(t);n||(n=this.precomputeWindow(r),t&&1!==r&&(n=B.normalizeZ(n),C.set(t,n)));let i=B.ZERO,o=B.BASE;const a=1+256/r,s=2**(r-1),c=BigInt(2**r-1),u=2**r,f=BigInt(r);for(let t=0;t<a;t++){const r=t*s;let a=Number(e&c);e>>=f,a>s&&(a-=u,e+=m);const p=r,l=r+Math.abs(a)-1,y=t%2!=0,h=a<0;0===a?o=o.add(P(y,n[p])):i=i.add(P(h,n[l]))}return B.normalizeZ([i,o])[0]}multiply(e,t){return this.wNAF(ne(e,T.l),t)}multiplyUnsafe(e){let t=ne(e,T.l,!1);const r=B.BASE,n=B.ZERO;if(t===b)return n;if(this.equals(n)||t===m)return this;if(this.equals(r))return this.wNAF(t);let i=n,o=this;for(;t>b;)t&m&&(i=i.add(o)),o=o.double(),t>>=m;return i}isSmallOrder(){return this.multiplyUnsafe(T.h).equals(B.ZERO)}isTorsionFree(){let e=this.multiplyUnsafe(T.l/E).double();return T.l%E&&(e=e.add(this)),e.equals(B.ZERO)}toAffine(e){const{x:t,y:r,z:n}=this,i=this.equals(B.ZERO);null==e&&(e=i?K:H(n));const o=Z(t*e),a=Z(r*e),s=Z(n*e);if(i)return R.ZERO;if(s!==m)throw new Error("invZ was invalid");return new R(o,a)}fromRistrettoBytes(){N()}toRistrettoBytes(){N()}fromRistrettoHash(){N()}}function P(e,t){const r=t.negate();return e?r:t}function L(e){if(!(e instanceof B))throw new TypeError("ExtendedPoint expected")}function _(e){if(!(e instanceof I))throw new TypeError("RistrettoPoint expected")}function N(){throw new Error("Legacy method: switch to RistrettoPoint")}B.BASE=new B(T.Gx,T.Gy,m,Z(T.Gx*T.Gy)),B.ZERO=new B(b,m,m,b);class I{constructor(e){this.ep=e}static calcElligatorRistrettoMap(e){const{d:t}=T,r=Z(k*e*e),n=Z((r+m)*M);let i=BigInt(-1);const o=Z((i-t*r)*Z(r+t));let{isValid:a,value:s}=Q(n,o),c=Z(s*e);z(c)||(c=Z(-c)),a||(s=c),a||(i=r);const u=Z(i*(r-m)*U-o),f=s*s,p=Z((s+s)*o),l=Z(u*O),y=Z(m-f),h=Z(m+f);return new B(Z(p*h),Z(y*l),Z(l*h),Z(p*y))}static hashToCurve(e){const t=$((e=re(e,64)).slice(0,32)),r=this.calcElligatorRistrettoMap(t),n=$(e.slice(32,64)),i=this.calcElligatorRistrettoMap(n);return new I(r.add(i))}static fromHex(e){e=re(e,32);const{a:t,d:r}=T,n="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",i=$(e);if(!function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}(W(i),e)||z(i))throw new Error(n);const o=Z(i*i),a=Z(m+t*o),s=Z(m-t*o),c=Z(a*a),u=Z(s*s),f=Z(t*r*c-u),{isValid:p,value:l}=ee(Z(f*u)),y=Z(l*s),h=Z(l*y*f);let d=Z((i+i)*y);z(d)&&(d=Z(-d));const w=Z(a*h),v=Z(d*w);if(!p||z(v)||w===b)throw new Error(n);return new I(new B(d,w,m,v))}toRawBytes(){let{x:e,y:t,z:r,t:n}=this.ep;const i=Z(Z(r+t)*Z(r-t)),o=Z(e*t),a=Z(o*o),{value:s}=ee(Z(i*a)),c=Z(s*i),u=Z(s*o),f=Z(c*u*n);let p;if(z(n*f)){let r=Z(t*k),n=Z(e*k);e=r,t=n,p=Z(c*S)}else p=u;z(e*f)&&(t=Z(-t));let l=Z((r-t)*p);return z(l)&&(l=Z(-l)),W(l)}toHex(){return X(this.toRawBytes())}toString(){return this.toHex()}equals(e){_(e);const t=this.ep,r=e.ep,n=Z(t.x*r.y)===Z(t.y*r.x),i=Z(t.y*r.y)===Z(t.x*r.x);return n||i}add(e){return _(e),new I(this.ep.add(e.ep))}subtract(e){return _(e),new I(this.ep.subtract(e.ep))}multiply(e){return new I(this.ep.multiply(e))}multiplyUnsafe(e){return new I(this.ep.multiplyUnsafe(e))}}I.BASE=new I(B.BASE),I.ZERO=new I(B.ZERO);const C=new WeakMap;class R{constructor(e,t){this.x=e,this.y=t}_setWindowSize(e){this._WINDOW_SIZE=e,C.delete(this)}static fromHex(e,t=!0){const{d:r,P:n}=T,i=(e=re(e,32)).slice();i[31]=-129&e[31];const o=q(i);if(t&&o>=n)throw new Error("Expected 0 < hex < P");if(!t&&o>=A)throw new Error("Expected 0 < hex < 2**256");const a=Z(o*o),s=Z(a-m),c=Z(r*a+m);let{isValid:u,value:f}=Q(s,c);if(!u)throw new Error("Point.fromHex: invalid y coordinate");const p=(f&m)===m;return 0!=(128&e[31])!==p&&(f=Z(-f)),new R(f,o)}static async fromPrivateKey(e){return(await oe(e)).point}toRawBytes(){const e=W(this.y);return e[31]|=this.x&m?128:0,e}toHex(){return X(this.toRawBytes())}toX25519(){const{y:e}=this;return W(Z((m+e)*H(m-e)))}isTorsionFree(){return B.fromAffine(this).isTorsionFree()}equals(e){return this.x===e.x&&this.y===e.y}negate(){return new R(Z(-this.x),this.y)}add(e){return B.fromAffine(this).add(B.fromAffine(e)).toAffine()}subtract(e){return this.add(e.negate())}multiply(e){return B.fromAffine(this).multiply(e,this).toAffine()}}R.BASE=new R(T.Gx,T.Gy),R.ZERO=new R(b,m);class j{constructor(e,t){this.r=e,this.s=t,this.assertValidity()}static fromHex(e){const t=re(e,64),r=R.fromHex(t.slice(0,32),!1),n=q(t.slice(32,64));return new j(r,n)}assertValidity(){const{r:e,s:t}=this;if(!(e instanceof R))throw new Error("Expected Point instance");return ne(t,T.l,!1),this}toRawBytes(){const e=new Uint8Array(64);return e.set(this.r.toRawBytes()),e.set(W(this.s),32),e}toHex(){return X(this.toRawBytes())}}function V(...e){if(!e.every((e=>e instanceof Uint8Array)))throw new Error("Expected Uint8Array list");if(1===e.length)return e[0];const t=e.reduce(((e,t)=>e+t.length),0),r=new Uint8Array(t);for(let t=0,n=0;t<e.length;t++){const i=e[t];r.set(i,n),n+=i.length}return r}const J=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function X(e){if(!(e instanceof Uint8Array))throw new Error("Uint8Array expected");let t="";for(let r=0;r<e.length;r++)t+=J[e[r]];return t}function D(e){if("string"!=typeof e)throw new TypeError("hexToBytes: expected string, got "+typeof e);if(e.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const t=new Uint8Array(e.length/2);for(let r=0;r<t.length;r++){const n=2*r,i=e.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");t[r]=o}return t}function F(e){return D(e.toString(16).padStart(64,"0"))}function W(e){return F(e).reverse()}function z(e){return(Z(e)&m)===m}function q(e){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");return BigInt("0x"+X(Uint8Array.from(e).reverse()))}const G=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function $(e){return Z(q(e)&G)}function Z(e,t=T.P){const r=e%t;return r>=b?r:t+r}function H(e,t=T.P){if(e===b||t<=b)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let r=Z(e,t),n=t,i=b,o=m;for(;r!==b;){const e=n%r,t=i-o*(n/r);n=r,r=e,i=o,o=t}if(n!==m)throw new Error("invert: does not exist");return Z(i,t)}function Y(e,t){const{P:r}=T;let n=e;for(;t-- >b;)n*=n,n%=r;return n}function Q(e,t){const r=Z(t*t*t),n=function(e){const{P:t}=T,r=BigInt(5),n=BigInt(10),i=BigInt(20),o=BigInt(40),a=BigInt(80),s=e*e%t*e%t,c=Y(s,E)*s%t,u=Y(c,m)*e%t,f=Y(u,r)*u%t,p=Y(f,n)*f%t,l=Y(p,i)*p%t,y=Y(l,o)*l%t,h=Y(y,a)*y%t,d=Y(h,a)*y%t,w=Y(d,n)*f%t;return{pow_p_5_8:Y(w,E)*e%t,b2:s}}(e*Z(r*r*t)).pow_p_5_8;let i=Z(e*r*n);const o=Z(t*i*i),a=i,s=Z(i*k),c=o===e,u=o===Z(-e),f=o===Z(-e*k);return c&&(i=a),(u||f)&&(i=s),z(i)&&(i=Z(-i)),{isValid:c||u,value:i}}function ee(e){return Q(m,e)}function te(e){return Z(q(e),T.l)}function re(e,t){const r=e instanceof Uint8Array?Uint8Array.from(e):D(e);if("number"==typeof t&&r.length!==t)throw new Error(`Expected ${t} bytes`);return r}function ne(e,t,r=!0){if(!t)throw new TypeError("Specify max value");if("number"==typeof e&&Number.isSafeInteger(e)&&(e=BigInt(e)),"bigint"==typeof e&&e<t)if(r){if(b<e)return e}else if(b<=e)return e;throw new TypeError("Expected valid scalar: 0 < scalar < max")}let ie;async function oe(e){return function(e){const t=((r=e.slice(0,32))[0]&=248,r[31]&=127,r[31]|=64,r);var r;const n=e.slice(32,64),i=te(t),o=R.BASE.multiply(i),a=o.toRawBytes();return{head:t,prefix:n,scalar:i,point:o,pointBytes:a}}(await fe.sha512(function(e){if(32!==(e="bigint"==typeof e||"number"==typeof e?F(ne(e,A)):re(e)).length)throw new Error("Expected 32 bytes");return e}(e)))}async function ae(e){return(await oe(e)).pointBytes}async function se(e,t){e=re(e);const{prefix:r,scalar:n,pointBytes:i}=await oe(t),o=te(await fe.sha512(r,e)),a=R.BASE.multiply(o),s=Z(o+te(await fe.sha512(a.toRawBytes(),i,e))*n,T.l);return new j(a,s).toRawBytes()}async function ce(e,t,r){const{r:n,SB:i,msg:o,pub:a}=function(e,t,r){t=re(t),r instanceof R||(r=R.fromHex(r,!1));const{r:n,s:i}=e instanceof j?e.assertValidity():j.fromHex(e);return{r:n,s:i,SB:B.BASE.multiplyUnsafe(i),pub:r,msg:t}}(e,t,r),s=await fe.sha512(n.toRawBytes(),a.toRawBytes(),o);return function(e,t,r,n){const i=te(n),o=B.fromAffine(e).multiplyUnsafe(i);return B.fromAffine(t).add(o).subtract(r).multiplyUnsafe(T.h).equals(B.ZERO)}(a,n,i,s)}R.BASE._setWindowSize(8);const ue={node:i,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},fe={bytesToHex:X,hexToBytes:D,concatBytes:V,getExtendedPublicKey:oe,mod:Z,invert:H,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:e=>{if((e=re(e)).length<40||e.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return Z(q(e),T.l-m)+m},randomBytes:(e=32)=>{if(ue.web)return ue.web.getRandomValues(new Uint8Array(e));if(ue.node){const{randomBytes:t}=ue.node;return new Uint8Array(t(e).buffer)}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>fe.randomBytes(32),sha512:async(...e)=>{const t=V(...e);if(ue.web){const e=await ue.web.subtle.digest("SHA-512",t.buffer);return new Uint8Array(e)}if(ue.node)return Uint8Array.from(ue.node.createHash("sha512").update(t).digest());throw new Error("The environment doesn't have sha512 function")},precompute(e=8,t=R.BASE){const r=t.equals(R.BASE)?t:new R(t.x,t.y);return r._setWindowSize(e),r.multiply(E),r},sha512Sync:void 0};Object.defineProperties(fe,{sha512Sync:{configurable:!1,get:()=>ie,set(e){ie||(ie=e)}}});
|
|
7
|
+
/*!
|
|
8
|
+
* Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved.
|
|
9
|
+
*/
|
|
10
|
+
const pe=self.crypto;if(!pe.getRandomValues)throw new Error('Browser does not provide "crypto.getRandomValues".');var le={async generateKeyPair(){const e=new Uint8Array(32);pe.getRandomValues(e);const t=await ye(e);return e.fill(0),t},generateKeyPairFromSeed:ye,sign:async(e,t)=>se(t,e.slice(0,32)),verify:async(e,t,r)=>ce(r,t,e),sha256digest:async({data:e})=>pe.subtle.digest("SHA-256",e)};async function ye(e){const t=await ae(e),r=new Uint8Array(64);return r.set(e),r.set(t,e.length),{publicKey:t,secretKey:r}}
|
|
11
|
+
/*!
|
|
12
|
+
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
|
|
13
|
+
*/let he=class{constructor({id:e,controller:t,revoked:r}={}){this.id=e,this.controller=t,this.revoked=r}static async generate(){throw new Error("Abstract method, must be implemented in subclass.")}static async fromKeyDocument({document:e,checkContext:t=!0,checkRevoked:r=!0}={}){if(!e)throw new TypeError('The "document" parameter is required.');if(t){if(![].concat(e["@context"]).includes(this.SUITE_CONTEXT))throw new Error('Key document does not contain required context "'+this.SUITE_CONTEXT+'".')}if(r&&e.revoked)throw new Error(`Key has been revoked since: "${e.revoked}".`);return this.from(e)}static async from(){throw new Error("Abstract method from() must be implemented in subclass.")}export({publicKey:e=!1,privateKey:t=!1}={}){if(!e&&!t)throw new Error('Export requires specifying either "publicKey" or "privateKey".');const r={id:this.id,type:this.type,controller:this.controller};return this.revoked&&(r.revoked=this.revoked),r}fingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}verifyFingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}signer(){return{async sign({}){throw new Error("Abstract method, must be implemented in subclass.")}}}verifier(){return{async verify({}){throw new Error("Abstract method, must be implemented in subclass.")}}}};he.SUITE_CONTEXT="INVALID LDKeyPair CONTEXT";
|
|
14
|
+
/*!
|
|
15
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
16
|
+
*/
|
|
17
|
+
const de="Ed25519VerificationKey2020",we=new Uint8Array([237,1]),ve=new Uint8Array([128,38]);let ge=class e extends he{constructor(e={}){super(e),this.type=de;const{publicKeyMultibase:t,privateKeyMultibase:r}=e;if(!t)throw new TypeError('The "publicKeyMultibase" property is required.');if(!t||!be(t,we))throw new Error(`"publicKeyMultibase" has invalid header bytes: "${t}".`);if(r&&!be(r,ve))throw new Error('"privateKeyMultibase" has invalid header bytes.');this.publicKeyMultibase=t,this.privateKeyMultibase=r,this.controller&&!this.id&&(this.id=`${this.controller}#${this.fingerprint()}`)}static async from(t){return"Ed25519VerificationKey2018"===t.type?e.fromEd25519VerificationKey2018(t):"JsonWebKey2020"===t.type?e.fromJsonWebKey2020(t):new e(t)}static fromEd25519VerificationKey2018({keyPair:t}={}){const r=me(we,u(t.publicKeyBase58)),n=new e({id:t.id,controller:t.controller,publicKeyMultibase:r});return t.privateKeyBase58&&(n.privateKeyMultibase=me(ve,u(t.privateKeyBase58))),n}static fromJsonWebKey2020({id:t,type:r,controller:n,publicKeyJwk:i}={}){if("JsonWebKey2020"!==r)throw new TypeError(`Invalid key type: "${r}".`);if(!i)throw new TypeError('"publicKeyJwk" property is required.');const{kty:o,crv:a}=i;if("OKP"!==o)throw new TypeError('"kty" is required to be "OKP".');if("Ed25519"!==a)throw new TypeError('"crv" is required to be "Ed25519".');const{x:s}=i,c=me(we,function(e){let t=e.length;const r=t%4;if(1===r)throw new Error("Illegal base64 string.");let n=0;r>0&&(n=4-r,t+=n);const i=new Uint8Array(t/4*3-n);let o,a,s,c,u=0,f=0;for(;u<t;)o=v[e.charCodeAt(u++)-45],a=v[e.charCodeAt(u++)-45],i[f++]=o<<2|a>>4,u<e.length&&(s=v[e.charCodeAt(u++)-45],i[f++]=(15&a)<<4|s>>2,u<e.length&&(c=v[e.charCodeAt(u++)-45],i[f++]=(3&s)<<6|c));return i}(s));return e.from({id:t,controller:n,publicKeyMultibase:c})}static async generate({seed:t,...r}={}){let n;n=t?await le.generateKeyPairFromSeed(t):await le.generateKeyPair();const i=me(we,n.publicKey),o=me(ve,n.secretKey);return new e({publicKeyMultibase:i,privateKeyMultibase:o,...r})}static fromFingerprint({fingerprint:t}={}){return new e({publicKeyMultibase:t})}get _publicKeyBuffer(){if(!this.publicKeyMultibase)return;return u(this.publicKeyMultibase.substr(1)).slice(we.length)}get _privateKeyBuffer(){if(!this.privateKeyMultibase)return;return u(this.privateKeyMultibase.substr(1)).slice(ve.length)}fingerprint(){return this.publicKeyMultibase}export({publicKey:t=!1,privateKey:r=!1,includeContext:n=!1}={}){if(!t&&!r)throw new TypeError('Export requires specifying either "publicKey" or "privateKey".');const i={id:this.id,type:this.type};return n&&(i["@context"]=e.SUITE_CONTEXT),this.controller&&(i.controller=this.controller),t&&(i.publicKeyMultibase=this.publicKeyMultibase),r&&(i.privateKeyMultibase=this.privateKeyMultibase),this.revoked&&(i.revoked=this.revoked),i}toJwk({publicKey:e=!0,privateKey:t=!1}={}){if(!e&&!t)throw TypeError('Either a "publicKey" or a "privateKey" is required.');const r={crv:"Ed25519",kty:"OKP"};return e&&(r.x=g(this._publicKeyBuffer)),t&&(r.d=g(this._privateKeyBuffer)),r}async jwkThumbprint(){const e=`{"crv":"Ed25519","kty":"OKP","x":"${g(this._publicKeyBuffer)}"}`,t=(new TextEncoder).encode(e);return g(new Uint8Array(await le.sha256digest({data:t})))}async toJsonWebKey2020(){return{"@context":"https://w3id.org/security/jws/v1",id:this.controller+"#"+await this.jwkThumbprint(),type:"JsonWebKey2020",controller:this.controller,publicKeyJwk:this.toJwk({publicKey:!0})}}verifyFingerprint({fingerprint:e}={}){if("string"!=typeof e||"z"!==e[0])return{error:new Error('"fingerprint" must be a multibase encoded string.'),valid:!1};let t;try{if(t=u(e.substr(1)),!t)throw new TypeError("Invalid encoding of fingerprint.")}catch(e){return{error:e,valid:!1}}const r=function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}(this._publicKeyBuffer,t.slice(2)),n=t[0]===we[0]&&t[1]===we[1]&&r;return n?{valid:n}:{error:new Error("The fingerprint does not match the public key."),valid:!1}}signer(){const e=this._privateKeyBuffer;return{async sign({data:t}){if(!e)throw new Error("A private key is not available for signing.");return le.sign(e,t)},id:this.id}}verifier(){const e=this._publicKeyBuffer;return{async verify({data:t,signature:r}){if(!e)throw new Error("A public key is not available for verifying.");return le.verify(e,t,r)},id:this.id}}};function be(e,t){if("string"!=typeof e||"z"!==e[0])return!1;const r=u(e.slice(1));return t.every(((e,t)=>r[t]===e))}function me(e,t){const r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),"z"+f(r)}ge.suite=de,ge.SUITE_CONTEXT="https://w3id.org/security/suites/ed25519-2020/v1";var Ee,Ke,xe=(function(e,t){!function(e,t){for(var r in t)e[r]=t[r]}(t,function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){
|
|
18
|
+
/*!
|
|
19
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
20
|
+
*/
|
|
21
|
+
e.exports={"@context":{id:"@id",type:"@type","@protected":!0,proof:{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"},Ed25519VerificationKey2020:{"@id":"https://w3id.org/security#Ed25519VerificationKey2020","@context":{"@protected":!0,id:"@id",type:"@type",controller:{"@id":"https://w3id.org/security#controller","@type":"@id"},revoked:{"@id":"https://w3id.org/security#revoked","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},publicKeyMultibase:{"@id":"https://w3id.org/security#publicKeyMultibase","@type":"https://w3id.org/security#multibase"}}},Ed25519Signature2020:{"@id":"https://w3id.org/security#Ed25519Signature2020","@context":{"@protected":!0,id:"@id",type:"@type",challenge:"https://w3id.org/security#challenge",created:{"@id":"http://purl.org/dc/terms/created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},domain:"https://w3id.org/security#domain",expires:{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},nonce:"https://w3id.org/security#nonce",proofPurpose:{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":!0,id:"@id",type:"@type",assertionMethod:{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},capabilityInvocation:{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},capabilityDelegation:{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},keyAgreement:{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},proofValue:{"@id":"https://w3id.org/security#proofValue","@type":"https://w3id.org/security#multibase"},verificationMethod:{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}}}}},function(e,t,r){
|
|
22
|
+
/*!
|
|
23
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
24
|
+
*/
|
|
25
|
+
e.exports={CONTEXT_FILENAME:"ed25519-signature-2020-v1.jsonld",CONTEXT_URL:"https://w3id.org/security/suites/ed25519-2020/v1",CBORLD_CODEC_VALUE:20}},function(e,t,r){
|
|
26
|
+
/*!
|
|
27
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
28
|
+
*/
|
|
29
|
+
const n=r(0),i=r(1),{documentLoader:o}=r(3),{CONTEXT_URL:a,CBORLD_CODEC_VALUE:s}=i,c=new Map;c.set(i.CONTEXT_URL,n);const u=new Map;u.set(a,s),e.exports={constants:i,contexts:c,appContextMap:u,documentLoader:o,CONTEXT_URL:a,CONTEXT:n}},function(e,t,r){
|
|
30
|
+
/*!
|
|
31
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
32
|
+
*/
|
|
33
|
+
const{CONTEXT_URL:n}=r(1),i=r(0);e.exports={documentLoader(e){if(e!==n)throw new Error(`Loading document "${e}" is not allowed.`);return{contextUrl:null,document:i,documentUrl:e}}}}]))}(Ee={exports:{}},Ee.exports),Ee.exports),Te=(Ke=xe)&&Ke.__esModule&&Object.prototype.hasOwnProperty.call(Ke,"default")?Ke.default:Ke;xe.contexts,xe.constants,xe.CONTEXT,xe.CONTEXT_URL,xe.appContextMap,xe.documentLoader;const Ae={};
|
|
34
|
+
/*!
|
|
35
|
+
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
36
|
+
*/
|
|
37
|
+
const ke="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function Oe(e,t){return function(e,t,r){if(!(e instanceof Uint8Array))throw new TypeError('"input" must be a Uint8Array.');if("string"!=typeof t)throw new TypeError('"alphabet" must be a string.');if(void 0!==r&&"number"!=typeof r)throw new TypeError('"maxline" must be a number.');if(0===e.length)return"";let n="",i=0;const o=t.length,a=t.charAt(0),s=[0];for(i=0;i<e.length;++i){let t=e[i];for(let e=0;e<s.length;++e)t+=s[e]<<8,s[e]=t%o,t=t/o|0;for(;t>0;)s.push(t%o),t=t/o|0}for(i=0;0===e[i]&&i<e.length-1;++i)n+=a;for(i=s.length-1;i>=0;--i)n+=t[s[i]];if(r){const e=new RegExp(".{1,"+r+"}","g");n=n.match(e).join("\r\n")}return n}(e,ke,t)}function Se(e){return function(e,t){if("string"!=typeof e)throw new TypeError('"input" must be a string.');if("string"!=typeof t)throw new TypeError('"alphabet" must be a string.');if(0===e.length)return new Uint8Array;let r=Ae[t];if(!r){r=Ae[t]=[];for(let e=0;e<t.length;++e)r[t.charCodeAt(e)]=e}e=e.replace(/\s/g,"");const n=t.length,i=t.charAt(0),o=[0];for(let t=0;t<e.length;t++){const i=r[e.charCodeAt(t)];if(void 0===i)return;let a=i;for(let e=0;e<o.length;++e)a+=o[e]*n,o[e]=255&a,a>>=8;for(;a>0;)o.push(255&a),a>>=8}for(let t=0;e[t]===i&&t<e.length-1;++t)o.push(0);return new Uint8Array(o.reverse())}(e,ke)}
|
|
38
|
+
/*!
|
|
39
|
+
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
|
|
40
|
+
*/const Me="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",Ue=[62,-1,-1,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,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,-1,-1,-1,-1,63,-1,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];function Be(e){if(!(e instanceof Uint8Array||"string"==typeof e))throw new TypeError('"input" be a string or Uint8Array.');"string"==typeof e&&(e=(new TextEncoder).encode(e));let t,r,n,i="",o=0;for(;o<e.byteLength;)t=e[o++],r=e[o++],n=e[o++],i+=Me.charAt(t>>2),i+=Me.charAt((3&t)<<4|r>>4),isNaN(r)||(i+=Me.charAt((15&r)<<2|n>>6),isNaN(n)||(i+=Me.charAt(63&n)));return i}
|
|
41
|
+
/*!
|
|
42
|
+
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
|
|
43
|
+
*/
|
|
44
|
+
function Pe({bytes:e,expectedLength:t=32,code:r}){if(!(e instanceof Uint8Array))throw new TypeError('"bytes" must be a Uint8Array.');if(e.length!==t){const e=new Error(`"bytes" must be a ${t}-byte Uint8Array.`);throw e.name="DataError",r&&(e.code=r),e}}
|
|
45
|
+
/*!
|
|
46
|
+
* Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved.
|
|
47
|
+
*/const Le=globalThis.crypto;if(!Le.getRandomValues)throw new Error('Browser does not provide "crypto.getRandomValues".');var _e={async generateKeyPair(){const e=new Uint8Array(32);Le.getRandomValues(e);const t=await Ne(e);return e.fill(0),t},generateKeyPairFromSeed:Ne,sign:async(e,t)=>se(t,e.slice(0,32)),verify:async(e,t,r)=>ce(r,t,e),sha256digest:async({data:e})=>Le.subtle.digest("SHA-256",e)};async function Ne(e){Pe({bytes:e,expectedLength:32});const t=await ae(e),r=new Uint8Array(64);return r.set(e),r.set(t,e.length),{publicKey:t,secretKey:r}}
|
|
48
|
+
/*!
|
|
49
|
+
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
|
|
50
|
+
*/class Ie{constructor({id:e,controller:t,revoked:r}={}){this.id=e,this.controller=t,this.revoked=r}static async generate(){throw new Error("Abstract method, must be implemented in subclass.")}static async fromKeyDocument({document:e,checkContext:t=!0,checkRevoked:r=!0}={}){if(!e)throw new TypeError('The "document" parameter is required.');if(t){if(![].concat(e["@context"]).includes(this.SUITE_CONTEXT))throw new Error('Key document does not contain required context "'+this.SUITE_CONTEXT+'".')}if(r&&e.revoked)throw new Error(`Key has been revoked since: "${e.revoked}".`);return this.from(e)}static async from(){throw new Error("Abstract method from() must be implemented in subclass.")}export({publicKey:e=!1,privateKey:t=!1}={}){if(!e&&!t)throw new Error('Export requires specifying either "publicKey" or "privateKey".');const r={id:this.id,type:this.type,controller:this.controller};return this.revoked&&(r.revoked=this.revoked),r}fingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}verifyFingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}signer(){return{async sign({}){throw new Error("Abstract method, must be implemented in subclass.")}}}verifier(){return{async verify({}){throw new Error("Abstract method, must be implemented in subclass.")}}}}Ie.SUITE_CONTEXT="INVALID LDKeyPair CONTEXT";
|
|
51
|
+
/*!
|
|
52
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
53
|
+
*/
|
|
54
|
+
const Ce="Ed25519VerificationKey2020",Re=new Uint8Array([237,1]),je=new Uint8Array([128,38]);class Ve extends Ie{constructor(e={}){super(e),this.type=Ce;const{publicKeyMultibase:t,privateKeyMultibase:r}=e;if(!t)throw new TypeError('The "publicKeyMultibase" property is required.');if(!t||!Je(t,Re))throw new Error(`"publicKeyMultibase" has invalid header bytes: "${t}".`);if(r&&!Je(r,je))throw new Error('"privateKeyMultibase" has invalid header bytes.');this.publicKeyMultibase=t,this.privateKeyMultibase=r,this.controller&&!this.id&&(this.id=`${this.controller}#${this.fingerprint()}`),Pe({bytes:this._publicKeyBuffer,code:"invalidPublicKeyLength",expectedLength:32})}static async from(e){return"Ed25519VerificationKey2018"===e.type?Ve.fromEd25519VerificationKey2018(e):"JsonWebKey2020"===e.type?Ve.fromJsonWebKey2020(e):new Ve(e)}static fromEd25519VerificationKey2018({keyPair:e}={}){const t=Xe(Re,Se(e.publicKeyBase58)),r=new Ve({id:e.id,controller:e.controller,publicKeyMultibase:t});return e.privateKeyBase58&&(r.privateKeyMultibase=Xe(je,Se(e.privateKeyBase58))),r}static fromJsonWebKey2020({id:e,type:t,controller:r,publicKeyJwk:n}={}){if("JsonWebKey2020"!==t)throw new TypeError(`Invalid key type: "${t}".`);if(!n)throw new TypeError('"publicKeyJwk" property is required.');const{kty:i,crv:o}=n;if("OKP"!==i)throw new TypeError('"kty" is required to be "OKP".');if("Ed25519"!==o)throw new TypeError('"crv" is required to be "Ed25519".');const{x:a}=n,s=Xe(Re,function(e){let t=e.length;const r=t%4;if(1===r)throw new Error("Illegal base64 string.");let n=0;r>0&&(n=4-r,t+=n);const i=new Uint8Array(t/4*3-n);let o,a,s,c,u=0,f=0;for(;u<t;)o=Ue[e.charCodeAt(u++)-45],a=Ue[e.charCodeAt(u++)-45],i[f++]=o<<2|a>>4,u<e.length&&(s=Ue[e.charCodeAt(u++)-45],i[f++]=(15&a)<<4|s>>2,u<e.length&&(c=Ue[e.charCodeAt(u++)-45],i[f++]=(3&s)<<6|c));return i}(a));return Ve.from({id:e,controller:r,publicKeyMultibase:s})}static async generate({seed:e,...t}={}){let r;r=e?await _e.generateKeyPairFromSeed(e):await _e.generateKeyPair();const n=Xe(Re,r.publicKey),i=Xe(je,r.secretKey);return new Ve({publicKeyMultibase:n,privateKeyMultibase:i,...t})}static fromFingerprint({fingerprint:e}={}){return new Ve({publicKeyMultibase:e})}get _publicKeyBuffer(){if(!this.publicKeyMultibase)return;return Se(this.publicKeyMultibase.substr(1)).slice(Re.length)}get _privateKeyBuffer(){if(!this.privateKeyMultibase)return;return Se(this.privateKeyMultibase.substr(1)).slice(je.length)}fingerprint(){return this.publicKeyMultibase}export({publicKey:e=!1,privateKey:t=!1,includeContext:r=!1}={}){if(!e&&!t)throw new TypeError('Export requires specifying either "publicKey" or "privateKey".');const n={id:this.id,type:this.type};return r&&(n["@context"]=Ve.SUITE_CONTEXT),this.controller&&(n.controller=this.controller),e&&(n.publicKeyMultibase=this.publicKeyMultibase),t&&(n.privateKeyMultibase=this.privateKeyMultibase),this.revoked&&(n.revoked=this.revoked),n}toJwk({publicKey:e=!0,privateKey:t=!1}={}){if(!e&&!t)throw TypeError('Either a "publicKey" or a "privateKey" is required.');const r={crv:"Ed25519",kty:"OKP"};return e&&(r.x=Be(this._publicKeyBuffer)),t&&(r.d=Be(this._privateKeyBuffer)),r}async jwkThumbprint(){const e=`{"crv":"Ed25519","kty":"OKP","x":"${Be(this._publicKeyBuffer)}"}`,t=(new TextEncoder).encode(e);return Be(new Uint8Array(await _e.sha256digest({data:t})))}async toJsonWebKey2020(){return{"@context":"https://w3id.org/security/jws/v1",id:this.controller+"#"+await this.jwkThumbprint(),type:"JsonWebKey2020",controller:this.controller,publicKeyJwk:this.toJwk({publicKey:!0})}}verifyFingerprint({fingerprint:e}={}){if("string"!=typeof e||"z"!==e[0])return{error:new Error('"fingerprint" must be a multibase encoded string.'),valid:!1};let t;try{if(t=Se(e.substr(1)),!t)throw new TypeError("Invalid encoding of fingerprint.")}catch(e){return{error:e,valid:!1}}const r=function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}(this._publicKeyBuffer,t.slice(2)),n=t[0]===Re[0]&&t[1]===Re[1]&&r;return n?{valid:n}:{error:new Error("The fingerprint does not match the public key."),valid:!1}}signer(){const e=this._privateKeyBuffer;return{async sign({data:t}){if(!e)throw new Error("A private key is not available for signing.");return _e.sign(e,t)},id:this.id}}verifier(){const e=this._publicKeyBuffer;return{async verify({data:t,signature:r}){if(!e)throw new Error("A public key is not available for verifying.");return _e.verify(e,t,r)},id:this.id}}}function Je(e,t){if("string"!=typeof e||"z"!==e[0])return!1;const r=Se(e.slice(1));return t.every(((e,t)=>r[t]===e))}function Xe(e,t){const r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),"z"+Oe(r)}Ve.suite=Ce,Ve.SUITE_CONTEXT="https://w3id.org/security/suites/ed25519-2020/v1";var De=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){!function(e,t){for(var r in t)e[r]=t[r]}(t,function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){
|
|
55
|
+
/*!
|
|
56
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
57
|
+
*/
|
|
58
|
+
e.exports={"@context":{id:"@id",type:"@type","@protected":!0,proof:{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"},Ed25519VerificationKey2018:{"@id":"https://w3id.org/security#Ed25519VerificationKey2018","@context":{"@protected":!0,id:"@id",type:"@type",controller:{"@id":"https://w3id.org/security#controller","@type":"@id"},revoked:{"@id":"https://w3id.org/security#revoked","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},publicKeyBase58:{"@id":"https://w3id.org/security#publicKeyBase58"}}},Ed25519Signature2018:{"@id":"https://w3id.org/security#Ed25519Signature2018","@context":{"@protected":!0,id:"@id",type:"@type",challenge:"https://w3id.org/security#challenge",created:{"@id":"http://purl.org/dc/terms/created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},domain:"https://w3id.org/security#domain",expires:{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},nonce:"https://w3id.org/security#nonce",proofPurpose:{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":!0,id:"@id",type:"@type",assertionMethod:{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},capabilityInvocation:{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},capabilityDelegation:{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},keyAgreement:{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},jws:{"@id":"https://w3id.org/security#jws"},verificationMethod:{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}}}}},function(e,t,r){
|
|
59
|
+
/*!
|
|
60
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
61
|
+
*/
|
|
62
|
+
e.exports={CONTEXT_FILENAME:"ed25519-signature-2018-v1.jsonld",CONTEXT_URL:"https://w3id.org/security/suites/ed25519-2018/v1",CBORLD_CODEC_VALUE:19}},function(e,t,r){
|
|
63
|
+
/*!
|
|
64
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
65
|
+
*/
|
|
66
|
+
const n=r(0),i=r(1),{documentLoader:o}=r(3),{CONTEXT_URL:a,CBORLD_CODEC_VALUE:s}=i,c=new Map;c.set(a,n);const u=new Map;u.set(a,s),e.exports={constants:i,contexts:c,appContextMap:u,documentLoader:o,CONTEXT_URL:a,CONTEXT:n}},function(e,t,r){
|
|
67
|
+
/*!
|
|
68
|
+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
69
|
+
*/
|
|
70
|
+
const{CONTEXT_URL:n}=r(1),i=r(0);e.exports={documentLoader(e){if(e!==n)throw new Error(`Loading document "${e}" is not allowed.`);return{contextUrl:null,document:i,documentUrl:e}}}}]))})),Fe=function(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}(De);De.contexts,De.constants,De.CONTEXT,De.CONTEXT_URL,De.appContextMap,De.documentLoader;
|
|
71
|
+
/*!
|
|
72
|
+
* Copyright (c) 2020-2021 Digital Bazaar, Inc. All rights reserved.
|
|
73
|
+
*/
|
|
74
|
+
const{suites:{LinkedDataSignature:We}}=s,ze=Te.constants.CONTEXT_URL,qe=Fe.constants.CONTEXT_URL;let Ge=class extends We{constructor({key:e,signer:t,verifier:r,proof:n,date:i,useNativeCanonize:o,canonizeOptions:a}={}){super({type:"Ed25519Signature2020",LDKeyClass:Ve,contextUrl:ze,key:e,signer:t,verifier:r,proof:n,date:i,useNativeCanonize:o,canonizeOptions:a}),this.requiredKeyType="Ed25519VerificationKey2020"}async sign({verifyData:e,proof:t}){if(!this.signer||"function"!=typeof this.signer.sign)throw new Error("A signer API has not been specified.");const r=await this.signer.sign({data:e});return t.proofValue="z"+Oe(r),t}async verifySignature({verifyData:e,verificationMethod:t,proof:r}){const{proofValue:n}=r;if(!n||"string"!=typeof n)throw new TypeError('The proof does not include a valid "proofValue" property.');if("z"!==n[0])throw new Error("Only base58btc multibase encoding is supported.");const i=Se(n.substr(1));let{verifier:o}=this;if(!o){o=(await this.LDKeyClass.from(t)).verifier()}return o.verify({data:e,signature:i})}async assertVerificationMethod({verificationMethod:e}){let t;if("Ed25519VerificationKey2020"===e.type)t=ze;else{if("Ed25519VerificationKey2018"!==e.type)throw new Error(`Unsupported key type "${e.type}".`);t=qe}if(!$e({document:e,contextUrl:t}))throw new TypeError(`The verification method (key) must contain "${t}" context.`);if(void 0!==e.revoked)throw new Error("The verification method has been revoked.")}async getVerificationMethod({proof:e,documentLoader:t}){if(this.key)return this.key.export({publicKey:!0});let{verificationMethod:r}=e;if("object"==typeof r&&(r=r.id),!r)throw new Error('No "verificationMethod" found in proof.');const{document:n}=await t(r);return r="string"==typeof n?JSON.parse(n):n,await this.assertVerificationMethod({verificationMethod:r}),"Ed25519VerificationKey2018"===r.type&&(r=(await Ve.fromEd25519VerificationKey2018({keyPair:r})).export({publicKey:!0,includeContext:!0})),r}async matchProof({proof:e,document:t,purpose:r,documentLoader:n}){if(!$e({document:t,contextUrl:ze}))return!1;if(!await super.matchProof({proof:e,document:t,purpose:r,documentLoader:n}))return!1;if(!this.key)return!0;const{verificationMethod:i}=e;return"object"==typeof i?i.id===this.key.id:i===this.key.id}};function $e({document:e,contextUrl:t}){const r=e["@context"];return r===t||Array.isArray(r)&&r.includes(t)}function Ze(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function He(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){Ze(o,n,i,a,s,"next",e)}function s(e){Ze(o,n,i,a,s,"throw",e)}a(void 0)}))}}function Ye(){return Ye=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ye.apply(this,arguments)}Ge.CONTEXT_URL=ze,Ge.CONTEXT=Te.contexts.get(ze);var Qe=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e){var t=function(e){var t,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=t&&t.prototype instanceof w?t:w,o=Object.create(i.prototype),a=new S(n||[]);return o._invoke=function(e,t,r){var n=p;return function(i,o){if(n===y)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return U()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var s=A(a,r);if(s){if(s===d)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=y;var c=f(e,t,r);if("normal"===c.type){if(n=r.done?h:l,c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=h,r.method="throw",r.arg=c.arg)}}}(e,r,a),o}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p="suspendedStart",l="suspendedYield",y="executing",h="completed",d={};function w(){}function v(){}function g(){}var b={};b[o]=function(){return this};var m=Object.getPrototypeOf,E=m&&m(m(M([])));E&&E!==r&&n.call(E,o)&&(b=E);var K=g.prototype=w.prototype=Object.create(b);function x(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function T(e,t){function r(i,o,a,s){var c=f(e[i],e,o);if("throw"!==c.type){var u=c.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?t.resolve(p.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(p).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}var i;this._invoke=function(e,n){function o(){return new t((function(t,i){r(e,n,t,i)}))}return i=i?i.then(o,o):o()}}function A(e,r){var n=e.iterator[r.method];if(n===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=t,A(e,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function k(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function M(e){if(e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,a=function r(){for(;++i<e.length;)if(n.call(e,i))return r.value=e[i],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}return{next:U}}function U(){return{value:t,done:!0}}return v.prototype=K.constructor=g,g.constructor=v,v.displayName=c(g,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,c(e,s,"GeneratorFunction")),e.prototype=Object.create(K),e},e.awrap=function(e){return{__await:e}},x(T.prototype),T.prototype[a]=function(){return this},e.AsyncIterator=T,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new T(u(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},x(K),c(K,s,"Generator"),K[o]=function(){return this},K.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=M,S.prototype={constructor:S,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(O),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function i(n,i){return s.type="throw",s.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:M(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));function et(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(255!==t[s])throw new TypeError(i+" is ambiguous");t[s]=n}var c=e.length,u=e.charAt(0),f=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function l(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return o.alloc(0);var r=0;if(" "!==e[r]){for(var n=0,i=0;e[r]===u;)n++,r++;for(var a=(e.length-r)*f+1>>>0,s=new Uint8Array(a);e[r];){var p=t[e.charCodeAt(r)];if(255===p)return;for(var l=0,y=a-1;(0!==p||l<i)&&-1!==y;y--,l++)p+=c*s[y]>>>0,s[y]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=l,r++}if(" "!==e[r]){for(var h=a-i;h!==a&&0===s[h];)h++;var d=o.allocUnsafe(n+(a-h));d.fill(0,0,n);for(var w=n;h!==a;)d[w++]=s[h++];return d}}}return{encode:function(t){if((Array.isArray(t)||t instanceof Uint8Array)&&(t=o.from(t)),!a(t))throw new TypeError("Expected Buffer");if(0===t.length)return"";for(var r=0,n=0,i=0,s=t.length;i!==s&&0===t[i];)i++,r++;for(var f=(s-i)*p+1>>>0,l=new Uint8Array(f);i!==s;){for(var y=t[i],h=0,d=f-1;(0!==y||h<n)&&-1!==d;d--,h++)y+=256*l[d]>>>0,l[d]=y%c>>>0,y=y/c>>>0;if(0!==y)throw new Error("Non-zero carry");n=h,i++}for(var w=f-n;w!==f&&0===l[w];)w++;for(var v=u.repeat(r);w<f;++w)v+=e.charAt(l[w]);return v},decodeUnsafe:l,decode:function(e){var t=l(e);if(t)return t;throw new Error("Non-base"+c+" character")}}}var tt,rt=et("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),nt=function(e){return o.from(e||"").toString("base64")},it=function(e){return nt(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},ot=function(e,t){void 0===t&&(t="base58btc");var r=new Uint8Array(2+e.length);if(r[0]=236,r[1]=1,r.set(e,2),"base58btc"===t)return"z"+rt.encode(r);if("base64url"===t)return"u"+it(r);throw new Error("Unsupported encoding: "+t)},at=function(e){return Uint8Array.from(o.from(e.x,"base64"))},st={JsonWebKey2020:function(e){var t,r=at(e.publicKeyJwk),n=void 0;e.privateKeyJwk&&(n=(t=e.privateKeyJwk,{publicKey:at(t),privateKey:Uint8Array.from(o.from(t.d,"base64"))}).privateKey);return{publicKey:r,privateKey:n}},X25519KeyAgreementKey2019:function(e){var t=rt.decode(e.publicKeyBase58),r=void 0;return e.privateKeyBase58&&(r=Uint8Array.from(rt.decode(e.privateKeyBase58))),{publicKey:t,privateKey:r}}},ct={JsonWebKey2020:function(e,t,r,n){var i={kty:"OKP",crv:"X25519",x:it(r)},o={id:e,type:"JsonWebKey2020",controller:t,publicKeyJwk:i};return n&&(o.privateKeyJwk=Ye({},i,{d:it(n)})),o},X25519KeyAgreementKey2019:function(e,t,r,n){var i={id:e,type:"X25519KeyAgreementKey2019",controller:t,publicKeyBase58:rt.encode(r)};return n&&(i.privateKeyBase58=rt.encode(n)),i}},ut=tt=function(){function e(e){this.type="JsonWebKey2020",this.id=e.id,this.type=e.type||"JsonWebKey2020",this.controller=e.controller,this.publicKey=e.publicKey,this.privateKey=e.privateKey}e.fingerprintFromPublicKey=function(){var e=He(Qe.mark((function e(t){var r,n;return Qe.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,tt.from(t);case 2:return r=e.sent,n=r.publicKey,e.abrupt("return",ot(n));case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.fromFingerprint=function(){var e=He(Qe.mark((function e(t){var r,n,i,o;return Qe.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.fingerprint,236!==(n=rt.decode(r.substring(1)))[0]||1!==n[1]){e.next=12;break}return e.next=5,tt.from({id:"",controller:"",type:"X25519KeyAgreementKey2019",publicKeyBase58:rt.encode(n.slice(2))});case 5:return i=e.sent,e.next=8,i.fingerprint();case 8:return o=e.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,e.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();var t=e.prototype;return t.fingerprint=function(){var e=He(Qe.mark((function e(){return Qe.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",ot(this.publicKey));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.export=function(){var e=He(Qe.mark((function e(t){return Qe.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===t&&(t={privateKey:!1,type:"JsonWebKey2020"}),!ct[t.type]){e.next=3;break}return e.abrupt("return",ct[t.type](this.id,this.controller,this.publicKey,t.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(t));case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.deriveSecret=function(){var e=He(Qe.mark((function e(t){var r,n,i;return Qe.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.publicKey,e.next=3,tt.from(r);case 3:if(n=e.sent,this.privateKey){e.next=6;break}throw new Error("No private key available for deriveSecret");case 6:return i=l.sharedKey(this.privateKey,n.publicKey,!0),e.abrupt("return",i);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e}();function ft(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function pt(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){ft(o,n,i,a,s,"next",e)}function s(e){ft(o,n,i,a,s,"throw",e)}a(void 0)}))}}function lt(){return lt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},lt.apply(this,arguments)}ut.generate=function(){var e=He(Qe.mark((function e(t){var r,n,i,o,a;return Qe.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.secureRandom,n=l.generateKeyPair({isAvailable:!0,randomBytes:r}),i=ot(n.publicKey),a=(o="did:key:"+i)+"#"+i,e.abrupt("return",new tt({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),ut.from=function(){var e=He(Qe.mark((function e(t){var r,n,i;return Qe.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=st[t.type](t),n=r.publicKey,i=r.privateKey,e.abrupt("return",new tt({id:t.id,type:t.type,controller:t.controller,publicKey:n,privateKey:i}));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),ut=tt=p([h.staticImplements()],ut);var yt=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e){var t=function(e){var t,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=t&&t.prototype instanceof w?t:w,o=Object.create(i.prototype),a=new S(n||[]);return o._invoke=function(e,t,r){var n=p;return function(i,o){if(n===y)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return U()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var s=A(a,r);if(s){if(s===d)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=y;var c=f(e,t,r);if("normal"===c.type){if(n=r.done?h:l,c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=h,r.method="throw",r.arg=c.arg)}}}(e,r,a),o}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p="suspendedStart",l="suspendedYield",y="executing",h="completed",d={};function w(){}function v(){}function g(){}var b={};b[o]=function(){return this};var m=Object.getPrototypeOf,E=m&&m(m(M([])));E&&E!==r&&n.call(E,o)&&(b=E);var K=g.prototype=w.prototype=Object.create(b);function x(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function T(e,t){function r(i,o,a,s){var c=f(e[i],e,o);if("throw"!==c.type){var u=c.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?t.resolve(p.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(p).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}var i;this._invoke=function(e,n){function o(){return new t((function(t,i){r(e,n,t,i)}))}return i=i?i.then(o,o):o()}}function A(e,r){var n=e.iterator[r.method];if(n===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=t,A(e,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function k(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function M(e){if(e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,a=function r(){for(;++i<e.length;)if(n.call(e,i))return r.value=e[i],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}return{next:U}}function U(){return{value:t,done:!0}}return v.prototype=K.constructor=g,g.constructor=v,v.displayName=c(g,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,c(e,s,"GeneratorFunction")),e.prototype=Object.create(K),e},e.awrap=function(e){return{__await:e}},x(T.prototype),T.prototype[a]=function(){return this},e.AsyncIterator=T,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new T(u(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},x(K),c(K,s,"Generator"),K[o]=function(){return this},K.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=M,S.prototype={constructor:S,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(O),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function i(n,i){return s.type="throw",s.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:M(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));function ht(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(255!==t[s])throw new TypeError(i+" is ambiguous");t[s]=n}var c=e.length,u=e.charAt(0),f=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function l(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return o.alloc(0);var r=0;if(" "!==e[r]){for(var n=0,i=0;e[r]===u;)n++,r++;for(var a=(e.length-r)*f+1>>>0,s=new Uint8Array(a);e[r];){var p=t[e.charCodeAt(r)];if(255===p)return;for(var l=0,y=a-1;(0!==p||l<i)&&-1!==y;y--,l++)p+=c*s[y]>>>0,s[y]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=l,r++}if(" "!==e[r]){for(var h=a-i;h!==a&&0===s[h];)h++;var d=o.allocUnsafe(n+(a-h));d.fill(0,0,n);for(var w=n;h!==a;)d[w++]=s[h++];return d}}}return{encode:function(t){if((Array.isArray(t)||t instanceof Uint8Array)&&(t=o.from(t)),!a(t))throw new TypeError("Expected Buffer");if(0===t.length)return"";for(var r=0,n=0,i=0,s=t.length;i!==s&&0===t[i];)i++,r++;for(var f=(s-i)*p+1>>>0,l=new Uint8Array(f);i!==s;){for(var y=t[i],h=0,d=f-1;(0!==y||h<n)&&-1!==d;d--,h++)y+=256*l[d]>>>0,l[d]=y%c>>>0,y=y/c>>>0;if(0!==y)throw new Error("Non-zero carry");n=h,i++}for(var w=f-n;w!==f&&0===l[w];)w++;for(var v=u.repeat(r);w<f;++w)v+=e.charAt(l[w]);return v},decodeUnsafe:l,decode:function(e){var t=l(e);if(t)return t;throw new Error("Non-base"+c+" character")}}}var dt,wt=ht("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),vt=function(e){return o.from(e||"").toString("base64")},gt=function(e){return vt(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},bt=function(e,t){void 0===t&&(t="base58btc");var r=new Uint8Array(2+e.length);if(r[0]=237,r[1]=1,r.set(e,2),"base58btc"===t)return"z"+wt.encode(r);if("base64url"===t)return"u"+gt(r);throw new Error("Unsupported encoding: "+t)},mt=function(e){return Uint8Array.from(o.from(e.x,"base64"))},Et={JsonWebKey2020:function(e){var t,r=mt(e.publicKeyJwk),n=void 0;e.privateKeyJwk&&(n=(t=e.privateKeyJwk,{publicKey:mt(t),privateKey:Uint8Array.from(o.concat([o.from(t.d,"base64"),o.from(t.x,"base64")]))}).privateKey);return{publicKey:r,privateKey:n}},Ed25519VerificationKey2018:function(e){var t=wt.decode(e.publicKeyBase58),r=void 0;return e.privateKeyBase58&&(r=Uint8Array.from(wt.decode(e.privateKeyBase58))),{publicKey:t,privateKey:r}}},Kt=function(e){if(!Et[e.type])throw new Error("Cannot import from unsupported type: "+JSON.stringify(e,null,2));return Et[e.type](e)},xt={JsonWebKey2020:function(e,t,r,n){var i={kty:"OKP",crv:"Ed25519",x:gt(r)},o={id:e,type:"JsonWebKey2020",controller:t,publicKeyJwk:i};return n&&(o.privateKeyJwk=lt({},i,{d:gt(n.slice(0,n.length/2))})),o},Ed25519VerificationKey2018:function(e,t,r,n){var i={id:e,type:"Ed25519VerificationKey2018",controller:t,publicKeyBase58:wt.encode(r)};return n&&(i.privateKeyBase58=wt.encode(n)),i}},Tt={EdDsa:{__proto__:null,signer:function(e){return{sign:function(t){return pt(yt.mark((function r(){var n;return yt.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=t.data,r.abrupt("return",y.sign(e,n));case 2:case"end":return r.stop()}}),r)})))()}}},verifier:function(e){return{verify:function(t){return pt(yt.mark((function r(){var n,i,o;return yt.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=t.data,i=t.signature,o=!1;try{o=y.verify(e,n,i)}catch(e){}return r.abrupt("return",o);case 4:case"end":return r.stop()}}),r)})))()}}}}},At=dt=function(){function e(e){this.type="JsonWebKey2020",this.id=e.id,this.type=e.type||"JsonWebKey2020",this.controller=e.controller,this.publicKey=e.publicKey,this.privateKey=e.privateKey}e.fingerprintFromPublicKey=function(){var e=pt(yt.mark((function e(t){var r,n;return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,dt.from(t);case 2:return r=e.sent,n=r.publicKey,e.abrupt("return",bt(n));case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.toX25519KeyPair=function(){var e=pt(yt.mark((function e(t){var r,n,i;return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=y.convertPublicKeyToX25519(t.publicKey),n=void 0,t.privateKey&&(n=y.convertSecretKeyToX25519(t.privateKey)),i=new ut({id:"",type:"X25519KeyAgreementKey2019",controller:t.controller,publicKey:r,privateKey:n}),e.t0=t.controller+"#",e.next=7,i.fingerprint();case 7:return e.t1=e.sent,i.id=e.t0+e.t1,e.abrupt("return",i);case 10:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.fromFingerprint=function(){var e=pt(yt.mark((function e(t){var r,n,i,o;return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.fingerprint,237!==(n=wt.decode(r.substring(1)))[0]||1!==n[1]){e.next=12;break}return e.next=5,dt.from({id:"",controller:"",type:"Ed25519VerificationKey2018",publicKeyBase58:wt.encode(n.slice(2))});case 5:return i=e.sent,e.next=8,i.fingerprint();case 8:return o=e.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,e.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();var t=e.prototype;return t.fingerprint=function(){var e=pt(yt.mark((function e(){return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",bt(this.publicKey));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.export=function(){var e=pt(yt.mark((function e(t){return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===t&&(t={privateKey:!1,type:"JsonWebKey2020"}),!xt[t.type]){e.next=3;break}return e.abrupt("return",xt[t.type](this.id,this.controller,this.publicKey,t.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(t));case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.signer=function(e){if(void 0===e&&(e="EdDsa"),!this.privateKey)throw new Error("No private key to sign with.");if(Tt[e])return Tt[e].signer(this.privateKey);throw new Error("Unsupported suite type "+e)},t.verifier=function(e){if(void 0===e&&(e="EdDsa"),!this.publicKey)throw new Error("No public key to verify with.");if(Tt[e])return Tt[e].verifier(this.publicKey);throw new Error("Unsupported suite type "+e)},t.getDerivedKeyPairs=function(){var e=pt(yt.mark((function e(){return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=this,e.next=3,dt.toX25519KeyPair(this);case 3:return e.t1=e.sent,e.abrupt("return",[e.t0,e.t1]);case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),e}();At.generate=function(){var e=pt(yt.mark((function e(t){var r,n,i,o,a;return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.secureRandom,n=y.generateKeyPair({isAvailable:!0,randomBytes:r}),i=bt(n.publicKey),a=(o="did:key:"+i)+"#"+i,e.abrupt("return",new dt({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),At.from=function(){var e=pt(yt.mark((function e(t){var r,n,i;return yt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=Kt(t),n=r.publicKey,i=r.privateKey,e.abrupt("return",new dt({id:t.id,type:t.type,controller:t.controller,publicKey:n,privateKey:i}));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),At=dt=p([h.staticImplements()],At);const{purposes:{AssertionProofPurpose:kt}}=s;var Ot;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.checkDocumentSignature="checkDocumentSignature"}(Ot||(Ot={}));class St extends d{verificationProcess=[Ot.retrieveVerificationMethodPublicKey,Ot.checkDocumentSignature];documentToVerify;issuer;proof;type="Ed25519Signature2020";verificationKey;publicKey;constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.issuer=e.issuer,this.proof=e.proof,this.validateProofType()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(t){return this.verificationProcess.map((r=>e.verifier.convertToVerificationSubsteps(t,r)))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(e){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(e,t,r){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}async publicKeyJwkToString(e){return await At.fingerprintFromPublicKey(e)}validateProofType(){const e=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}isProofChain(){return"ChainedProof2021"===this.proof.type}generateDocumentLoader(){t[this.documentToVerify.issuer]=this.issuer.didDocument;return function(e){return e in t?{contextUrl:null,document:t[e],documentUrl:e}:c.documentLoader(e)}}retrieveInitialDocument(){const e=r(this.documentToVerify);if(Array.isArray(e.proof)){const t=e.proof.find((e=>e.type===this.type));delete e.proof,e.proof=t}return e}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(Ot.retrieveVerificationMethodPublicKey,(async()=>{const e=this.issuer.didDocument.verificationMethod.find((e=>e.id===this.proof.verificationMethod));if(!e)throw new n(Ot.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.");try{this.publicKey=e.publicKeyMultibase||await this.publicKeyJwkToString(e)}catch(e){console.error("ERROR retrieving Ed25519Signature2020 public key",e)}const t=await ge.from({...e});if(!t)throw new n(Ot.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(t.revoked)throw new n(Ot.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return t}),this.type)}async checkDocumentSignature(){await this.executeStep(Ot.checkDocumentSignature,(async()=>{const e=new Ge({key:this.verificationKey});e.date=new Date(Date.now()).toISOString();const t=await s.verify(this.retrieveInitialDocument(),{suite:e,purpose:new kt,documentLoader:this.generateDocumentLoader()});if(!t.verified)throw console.error(JSON.stringify(t,null,2)),new n(Ot.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed`);console.log("Credential Ed25519 signature successfully verified")}),this.type)}}export{St as default};
|