@transmute/bls12381-key-pair
Version:
``` npm i @transmute/bls12381-key-pair@latest --save ```
3 lines (2 loc) • 22.2 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var r,e=require("tslib"),t=require("@mattrglobal/bls12381-key-pair"),n=require("@transmute/ld-key-pair"),i=require("@mattrglobal/bbs-signatures");function o(r,e,t,n,i,o,a){try{var u=r[o](a),c=u.value}catch(r){return void t(r)}u.done?e(c):Promise.resolve(c).then(n,i)}function a(r){return function(){var e=this,t=arguments;return new Promise((function(n,i){var a=r.apply(e,t);function u(r){o(a,n,i,u,c,"next",r)}function c(r){o(a,n,i,u,c,"throw",r)}u(void 0)}))}}function u(){return(u=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}(r=exports.BlsCurveName||(exports.BlsCurveName={})).G1="BLS12381_G1",r.G2="BLS12381_G2";var c,s=(function(r){var e=function(r){var e=Object.prototype,t=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(r,e,t){return Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),r[e]}try{u({},"")}catch(r){u=function(r,e,t){return r[e]=t}}function c(r,e,t,n){var i=Object.create((e&&e.prototype instanceof f?e:f).prototype),o=new B(n||[]);return i._invoke=function(r,e,t){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(t.method=i,t.arg=o;;){var a=t.delegate;if(a){var u=b(a,t);if(u){if(u===p)continue;return u}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var c=s(r,e,t);if("normal"===c.type){if(n=t.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:t.done}}"throw"===c.type&&(n="completed",t.method="throw",t.arg=c.arg)}}}(r,t,o),i}function s(r,e,t){try{return{type:"normal",arg:r.call(e,t)}}catch(r){return{type:"throw",arg:r}}}r.wrap=c;var p={};function f(){}function l(){}function y(){}var h={};h[i]=function(){return this};var d=Object.getPrototypeOf,v=d&&d(d(G([])));v&&v!==e&&t.call(v,i)&&(h=v);var K=y.prototype=f.prototype=Object.create(h);function g(r){["next","throw","return"].forEach((function(e){u(r,e,(function(r){return this._invoke(e,r)}))}))}function w(r,e){var n;this._invoke=function(i,o){function a(){return new e((function(n,a){!function n(i,o,a,u){var c=s(r[i],r,o);if("throw"!==c.type){var p=c.arg,f=p.value;return f&&"object"==typeof f&&t.call(f,"__await")?e.resolve(f.__await).then((function(r){n("next",r,a,u)}),(function(r){n("throw",r,a,u)})):e.resolve(f).then((function(r){p.value=r,a(p)}),(function(r){return n("throw",r,a,u)}))}u(c.arg)}(i,o,n,a)}))}return n=n?n.then(a,a):a()}}function b(r,e){var t=r.iterator[e.method];if(void 0===t){if(e.delegate=null,"throw"===e.method){if(r.iterator.return&&(e.method="return",e.arg=void 0,b(r,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=s(t,r.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var i=n.arg;return i?i.done?(e[r.resultName]=i.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function m(r){var e={tryLoc:r[0]};1 in r&&(e.catchLoc=r[1]),2 in r&&(e.finallyLoc=r[2],e.afterLoc=r[3]),this.tryEntries.push(e)}function x(r){var e=r.completion||{};e.type="normal",delete e.arg,r.completion=e}function B(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(m,this),this.reset(!0)}function G(r){if(r){var e=r[i];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,o=function e(){for(;++n<r.length;)if(t.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return l.prototype=K.constructor=y,y.constructor=l,l.displayName=u(y,a,"GeneratorFunction"),r.isGeneratorFunction=function(r){var e="function"==typeof r&&r.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,y):(r.__proto__=y,u(r,a,"GeneratorFunction")),r.prototype=Object.create(K),r},r.awrap=function(r){return{__await:r}},g(w.prototype),w.prototype[o]=function(){return this},r.AsyncIterator=w,r.async=function(e,t,n,i,o){void 0===o&&(o=Promise);var a=new w(c(e,t,n,i),o);return r.isGeneratorFunction(t)?a:a.next().then((function(r){return r.done?r.value:a.next()}))},g(K),u(K,a,"Generator"),K[i]=function(){return this},K.toString=function(){return"[object Generator]"},r.keys=function(r){var e=[];for(var t in r)e.push(t);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=G,B.prototype={constructor:B,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!r)for(var e in this)"t"===e.charAt(0)&&t.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var r=this.tryEntries[0].completion;if("throw"===r.type)throw r.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(t,n){return a.type="throw",a.arg=r,e.next=t,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var u=t.call(o,"catchLoc"),c=t.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(r,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&t.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===r||"continue"===r)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=r,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(a)},complete:function(r,e){if("throw"===r.type)throw r.arg;return"break"===r.type||"continue"===r.type?this.next=r.arg:"return"===r.type?(this.rval=this.arg=r.arg,this.method="return",this.next="end"):"normal"===r.type&&e&&(this.next=e),p},finish:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===r)return this.complete(t.completion,t.afterLoc),x(t),p}},catch:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===r){var n=t.completion;if("throw"===n.type){var i=n.arg;x(t)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,t){return this.delegate={iterator:G(r),resultName:e,nextLoc:t},"next"===this.method&&(this.arg=void 0),p}},r}(r.exports);try{regeneratorRuntime=e}catch(r){Function("r","regeneratorRuntime = r")(e)}}(c={exports:{}}),c.exports);function p(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var i=r.charAt(n),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=n}var a=r.length,u=r.charAt(0),c=Math.log(a)/Math.log(256),s=Math.log(256)/Math.log(a);function p(r){if("string"!=typeof r)throw new TypeError("Expected String");if(0===r.length)return Buffer.alloc(0);var t=0;if(" "!==r[t]){for(var n=0,i=0;r[t]===u;)n++,t++;for(var o=(r.length-t)*c+1>>>0,s=new Uint8Array(o);r[t];){var p=e[r.charCodeAt(t)];if(255===p)return;for(var f=0,l=o-1;(0!==p||f<i)&&-1!==l;l--,f++)s[l]=(p+=a*s[l]>>>0)%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=f,t++}if(" "!==r[t]){for(var y=o-i;y!==o&&0===s[y];)y++;var h=Buffer.allocUnsafe(n+(o-y));h.fill(0,0,n);for(var d=n;y!==o;)h[d++]=s[y++];return h}}}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=Buffer.from(e)),!Buffer.isBuffer(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var t=0,n=0,i=0,o=e.length;i!==o&&0===e[i];)i++,t++;for(var c=(o-i)*s+1>>>0,p=new Uint8Array(c);i!==o;){for(var f=e[i],l=0,y=c-1;(0!==f||l<n)&&-1!==y;y--,l++)p[y]=(f+=256*p[y]>>>0)%a>>>0,f=f/a>>>0;if(0!==f)throw new Error("Non-zero carry");n=l,i++}for(var h=c-n;h!==c&&0===p[h];)h++;for(var d=u.repeat(t);h<c;++h)d+=r.charAt(p[h]);return d},decodeUnsafe:p,decode:function(r){var e=p(r);if(e)return e;throw new Error("Non-base"+a+" character")}}}var f,l=p("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),y=function(r){return function(r){return Buffer.from(r||"").toString("base64")}(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},h=function(r,e,t){void 0===t&&(t="base58btc");var n=new Uint8Array(2+e.length);if(n[0]=r,n[1]=1,n.set(e,2),"base58btc"===t)return"z"+l.encode(n);if("base64url"===t)return"u"+y(n);throw new Error("Unsupported encoding: "+t)},d=function(r){return Uint8Array.from(Buffer.from(r.x,"base64"))},v={JsonWebKey2020:function(r){var e,t=d(r.publicKeyJwk),n=void 0;return r.privateKeyJwk&&(d(e=r.privateKeyJwk),n=Uint8Array.from(Buffer.from(e.d,"base64"))),{publicKey:t,privateKey:n}},Bls12381G1Key2020:function(r){var e=l.decode(r.publicKeyBase58),t=void 0;return r.privateKeyBase58&&(t=Uint8Array.from(l.decode(r.privateKeyBase58))),{publicKey:e,privateKey:t}},Bls12381G2Key2020:function(r){var e=l.decode(r.publicKeyBase58),t=void 0;return r.privateKeyBase58&&(t=Uint8Array.from(l.decode(r.privateKeyBase58))),{publicKey:e,privateKey:t}}},K={JsonWebKey2020:function(r,e,t,n,i){var o={kty:"EC",crv:r,x:y(n)},a={id:e,type:"JsonWebKey2020",controller:t,publicKeyJwk:o};return i&&(a.privateKeyJwk=u({},o,{d:y(i)})),a},Bls12381G1Key2020:function(r,e,t,n,i){if(r!==exports.BlsCurveName.G1)throw new Error("Unexpected curve name: "+r);var o={id:e,type:"Bls12381G1Key2020",controller:t,publicKeyBase58:l.encode(n)};return i&&(o.privateKeyBase58=l.encode(i)),o},Bls12381G2Key2020:function(r,e,t,n,i){if(r!==exports.BlsCurveName.G2)throw new Error("Unexpected curve name: "+r);var o={id:e,type:"Bls12381G2Key2020",controller:t,publicKeyBase58:l.encode(n)};return i&&(o.privateKeyBase58=l.encode(i)),o}},g={Bls12381G1Key2020:exports.BlsCurveName.G1,Bls12381G2Key2020:exports.BlsCurveName.G2},w=function(r){var e={id:r.id,controller:r.controller,type:"JsonWebKey2020",publicKeyJwk:{kty:"EC",crv:g[r.type],x:y(l.decode(r.publicKeyBase58))}};return r.privateKeyBase58&&(e.privateKeyJwk={kty:"EC",crv:g[r.type],x:y(l.decode(r.publicKeyBase58)),d:y(l.decode(r.privateKeyBase58))}),e},b=function(r){if("z"!==r[0])throw new Error('base58 encoded fingerprint must start with "z"');var e=l.decode(r.substring(1));if(234===e[0]&&1===e[1])return{bls12381G1KeyPair:u({},w({type:"Bls12381G1Key2020",publicKeyBase58:l.encode(e.slice(2))}),{id:"did:key:"+r+"#"+r,controller:"did:key:"+r})};if(235===e[0]&&1===e[1])return{bls12381G2KeyPair:u({},w({type:"Bls12381G2Key2020",publicKeyBase58:l.encode(e.slice(2))}),{id:"did:key:"+r+"#"+r,controller:"did:key:"+r})};if(238===e[0]&&1===e[1]){var t=w({type:"Bls12381G1Key2020",publicKeyBase58:l.encode(e.slice(2,50))}),n=w({type:"Bls12381G2Key2020",publicKeyBase58:l.encode(e.slice(50))});return{bls12381G1KeyPair:u({},t,{id:"did:key:"+r+"#"+r,controller:"did:key:"+r}),bls12381G2KeyPair:u({},n,{id:"did:key:"+r+"#"+r,controller:"did:key:"+r})}}throw new Error("unsupported fingerprint is not g1, g2 or g1 and g2.")};exports.Bls12381G1KeyPair=f=function(){function r(r){this.type="JsonWebKey2020",this.id=r.id,this.type=r.type||"JsonWebKey2020",this.controller=r.controller,this.publicKey=r.publicKey,this.privateKey=r.privateKey}r.fingerprintFromPublicKey=function(){var r=a(s.mark((function r(e){return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,f.from(e);case 2:return r.abrupt("return",h(234,r.sent.publicKey));case 5:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),r.fromFingerprint=function(){var r=a(s.mark((function r(e){var t;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=b(e.fingerprint),r.abrupt("return",f.from(t.bls12381G1KeyPair));case 3:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}();var e=r.prototype;return e.fingerprint=function(){var r=a(s.mark((function r(){var e,t;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=this.publicKey,(t=new Uint8Array(2+e.length))[0]=234,t[1]=1,t.set(e,2),r.abrupt("return","z"+l.encode(t));case 6:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),e.export=function(){var r=a(s.mark((function r(e){return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!K[e.type]){r.next=3;break}return r.abrupt("return",K[e.type](exports.BlsCurveName.G1,this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return r.stop()}}),r,this)})));return function(e){return r.apply(this,arguments)}}(),e.signer=function(r){throw void 0===r&&(r="Bbs"),new Error("Not implemented for "+r)},e.verifier=function(r){throw void 0===r&&(r="Bbs"),new Error("Not implemented for "+r)},r}(),exports.Bls12381G1KeyPair.generate=function(){var r=a(s.mark((function r(e){var n,i,o,a;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=(0,e.secureRandom)(),r.next=4,t.Bls12381G1KeyPair.generate({seed:n});case 4:return o=(i=r.sent).fingerprint(),r.abrupt("return",new f({id:(a="did:key:"+o)+"#"+o,type:"JsonWebKey2020",controller:a,publicKey:Uint8Array.from(i.publicKeyBuffer),privateKey:Uint8Array.from(i.privateKeyBuffer)}));case 9:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),exports.Bls12381G1KeyPair.from=function(){var r=a(s.mark((function r(e){var t;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=v[e.type](e),r.abrupt("return",new f({id:e.id,type:e.type,controller:e.controller,publicKey:t.publicKey,privateKey:t.privateKey}));case 2:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),exports.Bls12381G1KeyPair=f=e.__decorate([n.staticImplements()],exports.Bls12381G1KeyPair);var m,x={BbsUsingG2:{__proto__:null,signer:function(r,e){return{sign:function(n){return a(s.mark((function i(){var o,a,u;return s.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return o=n.data,a=new t.Bls12381G2KeyPair({id:"",publicKeyBase58:l.encode(e),privateKeyBase58:l.encode(r)}),u=a.signer(),i.abrupt("return",u.sign({data:o}));case 4:case"end":return i.stop()}}),i)})))()}}},verifier:function(r){return{verify:function(e){return a(s.mark((function n(){var i,o,a,u;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.data,o=e.signature,a=new t.Bls12381G2KeyPair({id:"",publicKeyBase58:l.encode(r)}),u=a.verifier(),n.abrupt("return",u.verify({data:i,signature:o}));case 4:case"end":return n.stop()}}),n)})))()}}}}};exports.Bls12381G2KeyPair=m=function(){function r(r){this.type="JsonWebKey2020",this.id=r.id,this.type=r.type||"JsonWebKey2020",this.controller=r.controller,this.publicKey=r.publicKey,this.privateKey=r.privateKey}r.fingerprintFromPublicKey=function(){var r=a(s.mark((function r(e){return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,m.from(e);case 2:return r.abrupt("return",h(235,r.sent.publicKey));case 5:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),r.fromFingerprint=function(){var r=a(s.mark((function r(e){var t;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=b(e.fingerprint),r.abrupt("return",m.from(t.bls12381G2KeyPair));case 3:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}();var e=r.prototype;return e.fingerprint=function(){var r=a(s.mark((function r(){var e,t;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=this.publicKey,(t=new Uint8Array(2+e.length))[0]=235,t[1]=1,t.set(e,2),r.abrupt("return","z"+l.encode(t));case 6:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),e.export=function(){var r=a(s.mark((function r(e){return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!K[e.type]){r.next=3;break}return r.abrupt("return",K[e.type](exports.BlsCurveName.G2,this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return r.stop()}}),r,this)})));return function(e){return r.apply(this,arguments)}}(),e.signer=function(r){if(void 0===r&&(r="BbsUsingG2"),!this.privateKey)throw new Error("No private key to sign with.");if(x[r])return x[r].signer(this.privateKey,this.publicKey);throw new Error("Unsupported suite type "+r)},e.verifier=function(r){if(void 0===r&&(r="BbsUsingG2"),!this.publicKey)throw new Error("No public key to verify with.");if(x[r])return x[r].verifier(this.publicKey);throw new Error("Unsupported suite type "+r)},r}(),exports.Bls12381G2KeyPair.generate=function(){var r=a(s.mark((function r(e){var n,i,o,a;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=(0,e.secureRandom)(),r.next=4,t.Bls12381G2KeyPair.generate({seed:n});case 4:return o=(i=r.sent).fingerprint(),r.abrupt("return",new m({id:(a="did:key:"+o)+"#"+o,type:"JsonWebKey2020",controller:a,publicKey:Uint8Array.from(i.publicKeyBuffer),privateKey:Uint8Array.from(i.privateKeyBuffer)}));case 9:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),exports.Bls12381G2KeyPair.from=function(){var r=a(s.mark((function r(e){var t;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=v[e.type](e),r.abrupt("return",new m({id:e.id,type:e.type,controller:e.controller,publicKey:t.publicKey,privateKey:t.privateKey}));case 2:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),exports.Bls12381G2KeyPair=m=e.__decorate([n.staticImplements()],exports.Bls12381G2KeyPair);var B=function(){var r=a(s.mark((function r(e){var t,n,o,a;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,i.generateBls12381G1KeyPair(e);case 2:return t=r.sent,r.next=5,i.generateBls12381G2KeyPair(e);case 5:return n=r.sent,o=new exports.Bls12381G1KeyPair({id:"",type:"Bls12381G1Key2020",controller:"",publicKey:t.publicKey,privateKey:t.secretKey}),a=new exports.Bls12381G2KeyPair({id:"",type:"Bls12381G2Key2020",controller:"",publicKey:n.publicKey,privateKey:n.secretKey}),r.abrupt("return",{bls12381G1KeyPair:o,bls12381G2KeyPair:a});case 9:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),G={z:l.decode},k={ea01:exports.Bls12381G1KeyPair,eb01:exports.Bls12381G2KeyPair},P=function(){function r(r){this.id=r.id,this.type=r.type,this.controller=r.controller,this.g1KeyPair=r.g1KeyPair,this.g2KeyPair=r.g2KeyPair}r.generate=function(){var e=a(s.mark((function e(t){var n,i,o,a,u,c;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=void 0,t.secureRandom&&(n=Uint8Array.from(t.secureRandom())),e.next=4,B(n);case 4:return u=new r({id:"",type:"Bls12381KeyPairs",controller:"",g1KeyPair:o=(i=e.sent).bls12381G1KeyPair,g2KeyPair:a=i.bls12381G2KeyPair}),e.next=10,u.fingerprint();case 10:return u.id="did:key:"+(c=e.sent)+"#"+c,u.controller="did:key:"+c,o.controller=u.controller,a.controller=u.controller,e.t0=u.controller+"#",e.next=18,o.fingerprint();case 18:return e.t1=e.sent,o.id=e.t0+e.t1,e.t2=u.controller+"#",e.next=23,a.fingerprint();case 23:return e.t3=e.sent,a.id=e.t2+e.t3,u.g1KeyPair=o,u.g2KeyPair=a,e.abrupt("return",u);case 28:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),r.fromFingerprint=function(){var e=a(s.mark((function e(t){var n,i,o,a,u,c,p;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=G[(n=t.fingerprint)[0]](n.substring(1)),o=i.slice(0,2),!k[o.toString("hex")]){e.next=6;break}return e.abrupt("return",k[o.toString("hex")].fromFingerprint({fingerprint:n}));case 6:if("ee01"!==o.toString("hex")){e.next=20;break}return a="z"+l.encode(Buffer.concat([Buffer.from("ea01","hex"),i.slice(2,50)])),u="z"+l.encode(Buffer.concat([Buffer.from("eb01","hex"),i.slice(50)])),e.next=11,exports.Bls12381G1KeyPair.fromFingerprint({fingerprint:a});case 11:return(c=e.sent).id="did:key:"+n+"#"+c.id.split("#").pop(),c.controller="did:key:"+n,e.next=16,exports.Bls12381G2KeyPair.fromFingerprint({fingerprint:u});case 16:return(p=e.sent).id="did:key:"+n+"#"+p.id.split("#").pop(),p.controller="did:key:"+n,e.abrupt("return",new r({id:"did:key:"+n+"#"+n,type:"Bls12381KeyPairs",controller:"did:key:"+n,g1KeyPair:c,g2KeyPair:p}));case 20:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}();var e=r.prototype;return e.fingerprint=function(){var r=a(s.mark((function r(){var e,t,n,i;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=Buffer.from(this.g1KeyPair.publicKey),t=Buffer.from(this.g2KeyPair.publicKey),n=Buffer.concat([e,t]),(i=new Uint8Array(2+n.length))[0]=238,i[1]=1,i.set(n,2),r.abrupt("return","z"+l.encode(i));case 8:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),e.getPairedKeyPairs=function(){var r=a(s.mark((function r(){return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",[this.g1KeyPair,this.g2KeyPair]);case 1:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),r}();exports.Bls12381KeyPairs=P;
//# sourceMappingURL=bls12381-key-pair.cjs.production.min.js.map
;