4 lines
49 KiB
JavaScript
4 lines
49 KiB
JavaScript
|
"use strict";var e=require("buffer"),r=require("stream"),t=require("util"),n=require("crypto"),o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var a={},s={exports:{}};
|
||
|
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||
|
!function(r,t){var n=e,o=n.Buffer;function i(e,r){for(var t in e)r[t]=e[t]}function a(e,r,t){return o(e,r,t)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?r.exports=n:(i(n,t),t.Buffer=a),a.prototype=Object.create(o.prototype),i(o,a),a.from=function(e,r,t){if("number"==typeof e)throw new TypeError("Argument must not be a number");return o(e,r,t)},a.alloc=function(e,r,t){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=o(e);return void 0!==r?"string"==typeof t?n.fill(r,t):n.fill(r):n.fill(0),n},a.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o(e)},a.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}}(s,s.exports);var u=s.exports,c=u.Buffer,f=r;function l(e){if(this.buffer=null,this.writable=!0,this.readable=!0,!e)return this.buffer=c.alloc(0),this;if("function"==typeof e.pipe)return this.buffer=c.alloc(0),e.pipe(this),this;if(e.length||"object"==typeof e)return this.buffer=e,this.writable=!1,process.nextTick(function(){this.emit("end",e),this.readable=!1,this.emit("close")}.bind(this)),this;throw new TypeError("Unexpected data type ("+typeof e+")")}t.inherits(l,f),l.prototype.write=function(e){this.buffer=c.concat([this.buffer,c.from(e)]),this.emit("data",e)},l.prototype.end=function(e){e&&this.write(e),this.emit("end",e),this.emit("close"),this.writable=!1,this.readable=!1};var p=l,h=e.Buffer,v=e.SlowBuffer,d=y;function y(e,r){if(!h.isBuffer(e)||!h.isBuffer(r))return!1;if(e.length!==r.length)return!1;for(var t=0,n=0;n<e.length;n++)t|=e[n]^r[n];return 0===t}y.install=function(){h.prototype.equal=v.prototype.equal=function(e){return y(this,e)}};var m=h.prototype.equal,g=v.prototype.equal;function b(e){return(e/8|0)+(e%8==0?0:1)}y.restore=function(){h.prototype.equal=m,v.prototype.equal=g};var w={ES256:b(256),ES384:b(384),ES512:b(521)};var j=function(e){var r=w[e];if(r)return r;throw new Error('Unknown algorithm "'+e+'"')},S=u.Buffer,_=j,E=128;function x(e){if(S.isBuffer(e))return e;if("string"==typeof e)return S.from(e,"base64");throw new TypeError("ECDSA signature must be a Base64 string or a Buffer")}function O(e,r,t){for(var n=0;r+n<t&&0===e[r+n];)++n;return e[r+n]>=E&&--n,n}var A={derToJose:function(e,r){e=x(e);var t=_(r),n=t+1,o=e.length,i=0;if(48!==e[i++])throw new Error('Could not find expected "seq"');var a=e[i++];if(a===(1|E)&&(a=e[i++]),o-i<a)throw new Error('"seq" specified length of "'+a+'", only "'+(o-i)+'" remaining');if(2!==e[i++])throw new Error('Could not find expected "int" for "r"');var s=e[i++];if(o-i-2<s)throw new Error('"r" specified length of "'+s+'", only "'+(o-i-2)+'" available');if(n<s)throw new Error('"r" specified length of "'+s+'", max of "'+n+'" is acceptable');var u=i;if(i+=s,2!==e[i++])throw new Error('Could not find expected "int" for "s"');var c=e[i++];if(o-i!==c)throw new Error('"s" specified length of "'+c+'", expected "'+(o-i)+'"');if(n<c)throw new Error('"s" specified length of "'+c+'", max of "'+n+'" is acceptable');var f=i;if((i+=c)!==o)throw new Error('Expected to consume entire buffer, but "'+(o-i)+'" bytes remain');var l=t-s,p=t-c,h=S.allocUnsafe(l+s+p+c);for(i=0;i<l;++i)h[i]=0;e.copy(h,i,u+Math.max(-l,0),u+s);for(var v=i=t;i<v+p;++i)h[i]=0;return e.copy(h,i,f+Math.max(-p,0),f+c),h=(h=h.toString("base64")).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},joseToDer:function(e,r){e=x(e);var t=_(r),n=e.length;if(n!==2*t)throw new TypeError('"'+r+'" signatures must be "'+2*t+'" bytes, saw "'+n+'"');var o=O(e,0,t),i=O(e,t,e.length),a=t-o,s=t-i,u=2+a+1+1+s,c=u<E,f=S.allocUnsafe((c?2:3)+u),l=0;return f[l++]=48,c?f[l++]=u:(f[l++]=1|E,f[l++]=255&u),f[l++]=2,f[l++]=a,o<0?(f[l++]=0,l+=e.copy(f,l,0,t)):l+=e.copy(f,l,o,t),f[l++]=2,f[l++]=s,i<0?(f[l++]=0,e.copy(f,l,t)):e.copy(f,l,t+i),f}},T=d,k=u.Buffer,P=n,R=A,B=t,$="secret must be a string or buffer",I="key must be a string or a buffer",V="key must be a string, a buffer or an object",N="function"==typeof P.createPublicKey;function M(e){if(!k.isBuffer(e)&&"string"!=typeof e){if(!
|