@transmute/secp256k1-key-pair
Advanced tools
Comparing version 0.7.0-unstable.1 to 0.7.0-unstable.2
@@ -1127,3 +1127,3 @@ 'use strict'; | ||
var expandedPublicKey = secp256k1.publicKeyConvert(publicKey, false, new Uint8Array(65)); | ||
var x = Buffer.from(expandedPublicKey).toString('hex').substr(2, 65); | ||
var x = Buffer.from(expandedPublicKey).toString('hex').substr(2, 64); | ||
var y = Buffer.from(expandedPublicKey).toString('hex').substr(66); | ||
@@ -1130,0 +1130,0 @@ var publicKeyJwk = { |
@@ -1,2 +0,2 @@ | ||
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=r(require("secp256k1")),n=require("@transmute/ld-key-pair"),o=r(require("crypto")),i=require("@bitauth/libauth");function a(r,e,t,n,o,i,a){try{var c=r[i](a),u=c.value}catch(r){return void t(r)}c.done?e(u):Promise.resolve(u).then(n,o)}function c(r){return function(){var e=this,t=arguments;return new Promise((function(n,o){var i=r.apply(e,t);function c(r){a(i,n,o,c,u,"next",r)}function u(r){a(i,n,o,c,u,"throw",r)}c(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)}var s,f=(function(r){var e=function(r){var e=Object.prototype,t=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(r,e,t){return Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),r[e]}try{c({},"")}catch(r){c=function(r,e,t){return r[e]=t}}function u(r,e,t,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new k(n||[]);return o._invoke=function(r,e,t){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(t.method=o,t.arg=i;;){var a=t.delegate;if(a){var c=b(a,t);if(c){if(c===f)continue;return c}}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 u=s(r,e,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}(r,t,i),o}function s(r,e,t){try{return{type:"normal",arg:r.call(e,t)}}catch(r){return{type:"throw",arg:r}}}r.wrap=u;var f={};function p(){}function h(){}function l(){}var y={};y[o]=function(){return this};var v=Object.getPrototypeOf,d=v&&v(v(E([])));d&&d!==e&&t.call(d,o)&&(y=d);var g=l.prototype=p.prototype=Object.create(y);function w(r){["next","throw","return"].forEach((function(e){c(r,e,(function(r){return this._invoke(e,r)}))}))}function m(r,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(r[o],r,i);if("throw"!==u.type){var f=u.arg,p=f.value;return p&&"object"==typeof p&&t.call(p,"__await")?e.resolve(p.__await).then((function(r){n("next",r,a,c)}),(function(r){n("throw",r,a,c)})):e.resolve(p).then((function(r){f.value=r,a(f)}),(function(r){return n("throw",r,a,c)}))}c(u.arg)}(o,i,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 f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(t,r.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[r.resultName]=o.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function x(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 K(r){var e=r.completion||{};e.type="normal",delete e.arg,r.completion=e}function k(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(x,this),this.reset(!0)}function E(r){if(r){var e=r[o];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=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 i.next=i}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=g.constructor=l,l.constructor=h,h.displayName=c(l,a,"GeneratorFunction"),r.isGeneratorFunction=function(r){var e="function"==typeof r&&r.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,l):(r.__proto__=l,c(r,a,"GeneratorFunction")),r.prototype=Object.create(g),r},r.awrap=function(r){return{__await:r}},w(m.prototype),m.prototype[i]=function(){return this},r.AsyncIterator=m,r.async=function(e,t,n,o,i){void 0===i&&(i=Promise);var a=new m(u(e,t,n,o),i);return r.isGeneratorFunction(t)?a:a.next().then((function(r){return r.done?r.value:a.next()}))},w(g),c(g,a,"Generator"),g[o]=function(){return this},g.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=E,k.prototype={constructor:k,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(K),!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 o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=t.call(i,"catchLoc"),u=t.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(r,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&t.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===r||"continue"===r)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=r,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):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),f},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),K(t),f}},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 o=n.arg;K(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,t){return this.delegate={iterator:E(r),resultName:e,nextLoc:t},"next"===this.method&&(this.arg=void 0),f}},r}(r.exports);try{regeneratorRuntime=e}catch(r){Function("r","regeneratorRuntime = r")(e)}}(s={exports:{}}),s.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 o=r.charAt(n),i=o.charCodeAt(0);if(255!==e[i])throw new TypeError(o+" is ambiguous");e[i]=n}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),s=Math.log(256)/Math.log(a);function f(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,o=0;r[t]===c;)n++,t++;for(var i=(r.length-t)*u+1>>>0,s=new Uint8Array(i);r[t];){var f=e[r.charCodeAt(t)];if(255===f)return;for(var p=0,h=i-1;(0!==f||p<o)&&-1!==h;h--,p++)s[h]=(f+=a*s[h]>>>0)%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");o=p,t++}if(" "!==r[t]){for(var l=i-o;l!==i&&0===s[l];)l++;var y=Buffer.allocUnsafe(n+(i-l));y.fill(0,0,n);for(var v=n;l!==i;)y[v++]=s[l++];return y}}}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,o=0,i=e.length;o!==i&&0===e[o];)o++,t++;for(var u=(i-o)*s+1>>>0,f=new Uint8Array(u);o!==i;){for(var p=e[o],h=0,l=u-1;(0!==p||h<n)&&-1!==l;l--,h++)f[l]=(p+=256*f[l]>>>0)%a>>>0,p=p/a>>>0;if(0!==p)throw new Error("Non-zero carry");n=h,o++}for(var y=u-n;y!==u&&0===f[y];)y++;for(var v=c.repeat(t);y<u;++y)v+=r.charAt(f[y]);return v},decodeUnsafe:f,decode:function(r){var e=f(r);if(e)return e;throw new Error("Non-base"+a+" character")}}}var h,l=p("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),y=function(r){return function(r){return Buffer.from(r||"").toString("base64")}(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},v=function(r,e){void 0===e&&(e="base58btc");var t=new Uint8Array(2+r.length);if(t[0]=231,t[1]=1,t.set(r,2),"base58btc"===e)return"z"+l.encode(t);if("base64url"===e)return"u"+y(t);throw new Error("Unsupported encoding: "+e)},d=function(r){var e=Buffer.concat([Buffer.from("04","hex"),Buffer.from(r.x,"base64"),Buffer.from(r.y,"base64")]);return t.publicKeyConvert(e,!0,new Uint8Array(33))},g={JsonWebKey2020:function(r){var e,t,n=d(r.publicKeyJwk),o=void 0;return r.privateKeyJwk&&(o=(e=r.privateKeyJwk,(t=Buffer.from(e.d,"base64").toString("hex")).padStart(64,"0"),{publicKey:d(e),privateKey:Uint8Array.from(Buffer.from(t,"hex"))}).privateKey),{publicKey:n,privateKey:o}},EcdsaSecp256k1VerificationKey2020:function(r){throw new Error("EcdsaSecp256k1VerificationKey2020 cannot be imported becuase it does not support private keys.")},EcdsaSecp256k1VerificationKey2019:function(r){return{publicKey:l.decode(r.publicKeyBase58),privateKey:r.privateKeyBase58?l.decode(r.privateKeyBase58):void 0}}},w={JsonWebKey2020:function(r,e,n,o){var i=t.publicKeyConvert(n,!1,new Uint8Array(65)),a=Buffer.from(i).toString("hex").substr(2,65),c=Buffer.from(i).toString("hex").substr(66),s={kty:"EC",crv:"secp256k1",x:y(Buffer.from(a,"hex")),y:y(Buffer.from(c,"hex"))},f={id:r,type:"JsonWebKey2020",controller:e,publicKeyJwk:s};return o&&(f.privateKeyJwk=u({},s,{d:y(o)})),f},EcdsaSecp256k1VerificationKey2020:function(r,e,t,n){var o={id:r,type:"EcdsaSecp256k1VerificationKey2020",controller:e,publicKeyMultibase:v(t)};if(n)throw new Error("Unable to represent secp256k1 private key in multibase. See https://github.com/multiformats/multicodec/pull/210");return o},EcdsaSecp256k1VerificationKey2019:function(r,e,t,n){var o={id:r,type:"EcdsaSecp256k1VerificationKey2019",controller:e,publicKeyBase58:l.encode(t)};return n&&(o.privateKeyBase58=l.encode(n)),o}},m={Ecdsa:{__proto__:null,signer:function(r){return{sign:function(e){return c(f.mark((function n(){var i,a,c;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.data,a=o.createHash("sha256").update(i).digest(),c=t.ecdsaSign(a,new Uint8Array(r)),n.abrupt("return",c.signature);case 4:case"end":return n.stop()}}),n)})))()}}},verifier:function(r){return{verify:function(e){return c(f.mark((function n(){var i,a,c,u;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:i=e.data,a=e.signature,c=o.createHash("sha256").update(i).digest(),u=!1;try{u=t.ecdsaVerify(a,c,new Uint8Array(r))}catch(r){}return n.abrupt("return",u);case 5:case"end":return n.stop()}}),n)})))()}}}},EcRecover:{__proto__:null,signer:function(r){return{sign:function(e){return c(f.mark((function n(){var i,a,c,u;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.data,a=o.createHash("sha256").update(i).digest(),c=t.ecdsaSign(a,r),u=c.recid,n.abrupt("return",Uint8Array.from(Buffer.concat([Buffer.from(c.signature),Buffer.from(new Uint8Array([u]))])));case 4:case"end":return n.stop()}}),n)})))()}}},verifier:function(r){return{verify:function(e){return c(f.mark((function n(){var i,a,c,u,s;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:i=e.data,a=e.signature,c=o.createHash("sha256").update(i).digest(),u=!1,s=t.ecdsaRecover(a.slice(0,64),a[64],c);try{u=Buffer.from(r).toString("hex")===Buffer.from(s).toString("hex")}catch(r){console.error("An error occurred when verifying signature: ",r)}return n.abrupt("return",u);case 6:case"end":return n.stop()}}),n)})))()}}}},Schnorr:{__proto__:null,signer:function(r){return{sign:function(e){return c(f.mark((function t(){var n,a,c;return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.data,t.next=3,i.instantiateSecp256k1();case 3:return a=t.sent,c=o.createHash("sha256").update(n).digest(),t.abrupt("return",a.signMessageHashSchnorr(r,c));case 6:case"end":return t.stop()}}),t)})))()}}},verifier:function(r){return{verify:function(e){return c(f.mark((function t(){var n,a,c,u,s;return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.data,a=e.signature,t.next=3,i.instantiateSecp256k1();case 3:c=t.sent,u=o.createHash("sha256").update(n).digest(),s=!1;try{s=c.verifySignatureSchnorr(a,r,u)}catch(r){console.error("An error occurred when verifying signature: ",r)}return t.abrupt("return",s);case 8:case"end":return t.stop()}}),t)})))()}}}}},b=function(){var r=c(f.mark((function r(e){var n,o;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:do{n=e()}while(!t.privateKeyVerify(n));return o=t.publicKeyCreate(n),r.abrupt("return",{publicKey:o,privateKey:new Uint8Array(n)});case 3:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}();exports.Secp256k1KeyPair=h=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.fromFingerprint=function(){var r=c(f.mark((function r(e){var t,n,o,i;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(231!==(n=l.decode((t=e.fingerprint).substring(1)))[0]||1!==n[1]){r.next=12;break}return r.next=5,h.from({id:"",controller:"",type:"EcdsaSecp256k1VerificationKey2019",publicKeyBase58:l.encode(n.slice(2))});case 5:return o=r.sent,r.next=8,o.fingerprint();case 8:return o.id="did:key:"+(i=r.sent)+"#"+i,o.controller="did:key:"+i,r.abrupt("return",o);case 12:throw new Error("Unsupported fingerprint type: "+t);case 13:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),r.fingerprintFromPublicKey=function(){var r=c(f.mark((function r(e){return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,h.from(e);case 2:return r.abrupt("return",v(r.sent.publicKey));case 5:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}();var e=r.prototype;return e.fingerprint=function(){var r=c(f.mark((function r(){return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",v(this.publicKey));case 1:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),e.signer=function(r){if(void 0===r&&(r="Ecdsa"),!this.privateKey)throw new Error("No private key to sign with.");if(m[r])return m[r].signer(this.privateKey);throw new Error("Unsupported suite type "+r)},e.verifier=function(r){if(void 0===r&&(r="Ecdsa"),!this.publicKey)throw new Error("No public key to verify with.");if(m[r])return m[r].verifier(this.publicKey);throw new Error("Unsupported suite type "+r)},e.deriveSecret=function(){var r=c(f.mark((function r(e){var n;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.publicKey,r.next=3,h.from(n);case 3:return r.abrupt("return",t.ecdh(r.sent.publicKey,this.privateKey));case 5:case"end":return r.stop()}}),r,this)})));return function(e){return r.apply(this,arguments)}}(),e.export=function(){var r=c(f.mark((function r(e){return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!w[e.type]){r.next=3;break}return r.abrupt("return",w[e.type](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)}}(),r}(),exports.Secp256k1KeyPair.generate=function(){var r=c(f.mark((function r(e){var t,n,o,i,a,c;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=e.secureRandom,r.next=3,b(t);case 3:return i=(n=r.sent).privateKey,a=v(o=n.publicKey),r.abrupt("return",new h({id:(c="did:key:"+a)+"#"+a,type:"JsonWebKey2020",controller:c,publicKey:o,privateKey:i}));case 10:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),exports.Secp256k1KeyPair.from=function(){var r=c(f.mark((function r(e){var t;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=g[e.type](e),r.abrupt("return",new h({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.Secp256k1KeyPair=h=e.__decorate([n.staticImplements()],exports.Secp256k1KeyPair); | ||
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=r(require("secp256k1")),n=require("@transmute/ld-key-pair"),o=r(require("crypto")),i=require("@bitauth/libauth");function a(r,e,t,n,o,i,a){try{var c=r[i](a),u=c.value}catch(r){return void t(r)}c.done?e(u):Promise.resolve(u).then(n,o)}function c(r){return function(){var e=this,t=arguments;return new Promise((function(n,o){var i=r.apply(e,t);function c(r){a(i,n,o,c,u,"next",r)}function u(r){a(i,n,o,c,u,"throw",r)}c(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)}var s,f=(function(r){var e=function(r){var e=Object.prototype,t=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(r,e,t){return Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),r[e]}try{c({},"")}catch(r){c=function(r,e,t){return r[e]=t}}function u(r,e,t,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new k(n||[]);return o._invoke=function(r,e,t){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(t.method=o,t.arg=i;;){var a=t.delegate;if(a){var c=b(a,t);if(c){if(c===f)continue;return c}}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 u=s(r,e,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}(r,t,i),o}function s(r,e,t){try{return{type:"normal",arg:r.call(e,t)}}catch(r){return{type:"throw",arg:r}}}r.wrap=u;var f={};function p(){}function h(){}function l(){}var y={};y[o]=function(){return this};var v=Object.getPrototypeOf,d=v&&v(v(E([])));d&&d!==e&&t.call(d,o)&&(y=d);var g=l.prototype=p.prototype=Object.create(y);function w(r){["next","throw","return"].forEach((function(e){c(r,e,(function(r){return this._invoke(e,r)}))}))}function m(r,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(r[o],r,i);if("throw"!==u.type){var f=u.arg,p=f.value;return p&&"object"==typeof p&&t.call(p,"__await")?e.resolve(p.__await).then((function(r){n("next",r,a,c)}),(function(r){n("throw",r,a,c)})):e.resolve(p).then((function(r){f.value=r,a(f)}),(function(r){return n("throw",r,a,c)}))}c(u.arg)}(o,i,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 f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(t,r.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[r.resultName]=o.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function x(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 K(r){var e=r.completion||{};e.type="normal",delete e.arg,r.completion=e}function k(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(x,this),this.reset(!0)}function E(r){if(r){var e=r[o];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=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 i.next=i}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=g.constructor=l,l.constructor=h,h.displayName=c(l,a,"GeneratorFunction"),r.isGeneratorFunction=function(r){var e="function"==typeof r&&r.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,l):(r.__proto__=l,c(r,a,"GeneratorFunction")),r.prototype=Object.create(g),r},r.awrap=function(r){return{__await:r}},w(m.prototype),m.prototype[i]=function(){return this},r.AsyncIterator=m,r.async=function(e,t,n,o,i){void 0===i&&(i=Promise);var a=new m(u(e,t,n,o),i);return r.isGeneratorFunction(t)?a:a.next().then((function(r){return r.done?r.value:a.next()}))},w(g),c(g,a,"Generator"),g[o]=function(){return this},g.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=E,k.prototype={constructor:k,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(K),!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 o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=t.call(i,"catchLoc"),u=t.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(r,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&t.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===r||"continue"===r)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=r,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):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),f},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),K(t),f}},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 o=n.arg;K(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,t){return this.delegate={iterator:E(r),resultName:e,nextLoc:t},"next"===this.method&&(this.arg=void 0),f}},r}(r.exports);try{regeneratorRuntime=e}catch(r){Function("r","regeneratorRuntime = r")(e)}}(s={exports:{}}),s.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 o=r.charAt(n),i=o.charCodeAt(0);if(255!==e[i])throw new TypeError(o+" is ambiguous");e[i]=n}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),s=Math.log(256)/Math.log(a);function f(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,o=0;r[t]===c;)n++,t++;for(var i=(r.length-t)*u+1>>>0,s=new Uint8Array(i);r[t];){var f=e[r.charCodeAt(t)];if(255===f)return;for(var p=0,h=i-1;(0!==f||p<o)&&-1!==h;h--,p++)s[h]=(f+=a*s[h]>>>0)%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");o=p,t++}if(" "!==r[t]){for(var l=i-o;l!==i&&0===s[l];)l++;var y=Buffer.allocUnsafe(n+(i-l));y.fill(0,0,n);for(var v=n;l!==i;)y[v++]=s[l++];return y}}}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,o=0,i=e.length;o!==i&&0===e[o];)o++,t++;for(var u=(i-o)*s+1>>>0,f=new Uint8Array(u);o!==i;){for(var p=e[o],h=0,l=u-1;(0!==p||h<n)&&-1!==l;l--,h++)f[l]=(p+=256*f[l]>>>0)%a>>>0,p=p/a>>>0;if(0!==p)throw new Error("Non-zero carry");n=h,o++}for(var y=u-n;y!==u&&0===f[y];)y++;for(var v=c.repeat(t);y<u;++y)v+=r.charAt(f[y]);return v},decodeUnsafe:f,decode:function(r){var e=f(r);if(e)return e;throw new Error("Non-base"+a+" character")}}}var h,l=p("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),y=function(r){return function(r){return Buffer.from(r||"").toString("base64")}(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},v=function(r,e){void 0===e&&(e="base58btc");var t=new Uint8Array(2+r.length);if(t[0]=231,t[1]=1,t.set(r,2),"base58btc"===e)return"z"+l.encode(t);if("base64url"===e)return"u"+y(t);throw new Error("Unsupported encoding: "+e)},d=function(r){var e=Buffer.concat([Buffer.from("04","hex"),Buffer.from(r.x,"base64"),Buffer.from(r.y,"base64")]);return t.publicKeyConvert(e,!0,new Uint8Array(33))},g={JsonWebKey2020:function(r){var e,t,n=d(r.publicKeyJwk),o=void 0;return r.privateKeyJwk&&(o=(e=r.privateKeyJwk,(t=Buffer.from(e.d,"base64").toString("hex")).padStart(64,"0"),{publicKey:d(e),privateKey:Uint8Array.from(Buffer.from(t,"hex"))}).privateKey),{publicKey:n,privateKey:o}},EcdsaSecp256k1VerificationKey2020:function(r){throw new Error("EcdsaSecp256k1VerificationKey2020 cannot be imported becuase it does not support private keys.")},EcdsaSecp256k1VerificationKey2019:function(r){return{publicKey:l.decode(r.publicKeyBase58),privateKey:r.privateKeyBase58?l.decode(r.privateKeyBase58):void 0}}},w={JsonWebKey2020:function(r,e,n,o){var i=t.publicKeyConvert(n,!1,new Uint8Array(65)),a=Buffer.from(i).toString("hex").substr(2,64),c=Buffer.from(i).toString("hex").substr(66),s={kty:"EC",crv:"secp256k1",x:y(Buffer.from(a,"hex")),y:y(Buffer.from(c,"hex"))},f={id:r,type:"JsonWebKey2020",controller:e,publicKeyJwk:s};return o&&(f.privateKeyJwk=u({},s,{d:y(o)})),f},EcdsaSecp256k1VerificationKey2020:function(r,e,t,n){var o={id:r,type:"EcdsaSecp256k1VerificationKey2020",controller:e,publicKeyMultibase:v(t)};if(n)throw new Error("Unable to represent secp256k1 private key in multibase. See https://github.com/multiformats/multicodec/pull/210");return o},EcdsaSecp256k1VerificationKey2019:function(r,e,t,n){var o={id:r,type:"EcdsaSecp256k1VerificationKey2019",controller:e,publicKeyBase58:l.encode(t)};return n&&(o.privateKeyBase58=l.encode(n)),o}},m={Ecdsa:{__proto__:null,signer:function(r){return{sign:function(e){return c(f.mark((function n(){var i,a,c;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.data,a=o.createHash("sha256").update(i).digest(),c=t.ecdsaSign(a,new Uint8Array(r)),n.abrupt("return",c.signature);case 4:case"end":return n.stop()}}),n)})))()}}},verifier:function(r){return{verify:function(e){return c(f.mark((function n(){var i,a,c,u;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:i=e.data,a=e.signature,c=o.createHash("sha256").update(i).digest(),u=!1;try{u=t.ecdsaVerify(a,c,new Uint8Array(r))}catch(r){}return n.abrupt("return",u);case 5:case"end":return n.stop()}}),n)})))()}}}},EcRecover:{__proto__:null,signer:function(r){return{sign:function(e){return c(f.mark((function n(){var i,a,c,u;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.data,a=o.createHash("sha256").update(i).digest(),c=t.ecdsaSign(a,r),u=c.recid,n.abrupt("return",Uint8Array.from(Buffer.concat([Buffer.from(c.signature),Buffer.from(new Uint8Array([u]))])));case 4:case"end":return n.stop()}}),n)})))()}}},verifier:function(r){return{verify:function(e){return c(f.mark((function n(){var i,a,c,u,s;return f.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:i=e.data,a=e.signature,c=o.createHash("sha256").update(i).digest(),u=!1,s=t.ecdsaRecover(a.slice(0,64),a[64],c);try{u=Buffer.from(r).toString("hex")===Buffer.from(s).toString("hex")}catch(r){console.error("An error occurred when verifying signature: ",r)}return n.abrupt("return",u);case 6:case"end":return n.stop()}}),n)})))()}}}},Schnorr:{__proto__:null,signer:function(r){return{sign:function(e){return c(f.mark((function t(){var n,a,c;return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.data,t.next=3,i.instantiateSecp256k1();case 3:return a=t.sent,c=o.createHash("sha256").update(n).digest(),t.abrupt("return",a.signMessageHashSchnorr(r,c));case 6:case"end":return t.stop()}}),t)})))()}}},verifier:function(r){return{verify:function(e){return c(f.mark((function t(){var n,a,c,u,s;return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.data,a=e.signature,t.next=3,i.instantiateSecp256k1();case 3:c=t.sent,u=o.createHash("sha256").update(n).digest(),s=!1;try{s=c.verifySignatureSchnorr(a,r,u)}catch(r){console.error("An error occurred when verifying signature: ",r)}return t.abrupt("return",s);case 8:case"end":return t.stop()}}),t)})))()}}}}},b=function(){var r=c(f.mark((function r(e){var n,o;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:do{n=e()}while(!t.privateKeyVerify(n));return o=t.publicKeyCreate(n),r.abrupt("return",{publicKey:o,privateKey:new Uint8Array(n)});case 3:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}();exports.Secp256k1KeyPair=h=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.fromFingerprint=function(){var r=c(f.mark((function r(e){var t,n,o,i;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(231!==(n=l.decode((t=e.fingerprint).substring(1)))[0]||1!==n[1]){r.next=12;break}return r.next=5,h.from({id:"",controller:"",type:"EcdsaSecp256k1VerificationKey2019",publicKeyBase58:l.encode(n.slice(2))});case 5:return o=r.sent,r.next=8,o.fingerprint();case 8:return o.id="did:key:"+(i=r.sent)+"#"+i,o.controller="did:key:"+i,r.abrupt("return",o);case 12:throw new Error("Unsupported fingerprint type: "+t);case 13:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),r.fingerprintFromPublicKey=function(){var r=c(f.mark((function r(e){return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,h.from(e);case 2:return r.abrupt("return",v(r.sent.publicKey));case 5:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}();var e=r.prototype;return e.fingerprint=function(){var r=c(f.mark((function r(){return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",v(this.publicKey));case 1:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),e.signer=function(r){if(void 0===r&&(r="Ecdsa"),!this.privateKey)throw new Error("No private key to sign with.");if(m[r])return m[r].signer(this.privateKey);throw new Error("Unsupported suite type "+r)},e.verifier=function(r){if(void 0===r&&(r="Ecdsa"),!this.publicKey)throw new Error("No public key to verify with.");if(m[r])return m[r].verifier(this.publicKey);throw new Error("Unsupported suite type "+r)},e.deriveSecret=function(){var r=c(f.mark((function r(e){var n;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.publicKey,r.next=3,h.from(n);case 3:return r.abrupt("return",t.ecdh(r.sent.publicKey,this.privateKey));case 5:case"end":return r.stop()}}),r,this)})));return function(e){return r.apply(this,arguments)}}(),e.export=function(){var r=c(f.mark((function r(e){return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!w[e.type]){r.next=3;break}return r.abrupt("return",w[e.type](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)}}(),r}(),exports.Secp256k1KeyPair.generate=function(){var r=c(f.mark((function r(e){var t,n,o,i,a,c;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=e.secureRandom,r.next=3,b(t);case 3:return i=(n=r.sent).privateKey,a=v(o=n.publicKey),r.abrupt("return",new h({id:(c="did:key:"+a)+"#"+a,type:"JsonWebKey2020",controller:c,publicKey:o,privateKey:i}));case 10:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),exports.Secp256k1KeyPair.from=function(){var r=c(f.mark((function r(e){var t;return f.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=g[e.type](e),r.abrupt("return",new h({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.Secp256k1KeyPair=h=e.__decorate([n.staticImplements()],exports.Secp256k1KeyPair); | ||
//# sourceMappingURL=secp256k1-key-pair.cjs.production.min.js.map |
@@ -1121,3 +1121,3 @@ import { __decorate } from 'tslib'; | ||
var expandedPublicKey = secp256k1.publicKeyConvert(publicKey, false, new Uint8Array(65)); | ||
var x = Buffer.from(expandedPublicKey).toString('hex').substr(2, 65); | ||
var x = Buffer.from(expandedPublicKey).toString('hex').substr(2, 64); | ||
var y = Buffer.from(expandedPublicKey).toString('hex').substr(66); | ||
@@ -1124,0 +1124,0 @@ var publicKeyJwk = { |
@@ -5,3 +5,3 @@ { | ||
"module": "dist/secp256k1-key-pair.esm.js", | ||
"version": "0.7.0-unstable.1", | ||
"version": "0.7.0-unstable.2", | ||
"license": "Apache-2.0", | ||
@@ -62,6 +62,6 @@ "homepage": "https://github.com/transmute-industries/verifiable-data/tree/main/packages/secp256k1-key-pair", | ||
"@bitauth/libauth": "^1.18.1", | ||
"@transmute/ld-key-pair": "^0.7.0-unstable.1", | ||
"@transmute/ld-key-pair": "^0.7.0-unstable.2", | ||
"secp256k1": "^4.0.2" | ||
}, | ||
"gitHead": "c0e32f49a38443eb941383a2742a2f8a3bf3a310" | ||
"gitHead": "149713cb96a715ddd2b6f186864552f09997b872" | ||
} |
@@ -25,6 +25,8 @@ import secp256k1 from 'secp256k1'; | ||
.toString('hex') | ||
.substr(2, 65); | ||
.substr(2, 64); | ||
const y = Buffer.from(expandedPublicKey) | ||
.toString('hex') | ||
.substr(66); | ||
const publicKeyJwk = { | ||
@@ -31,0 +33,0 @@ kty: 'EC', |
@@ -184,4 +184,2 @@ import secp256k1 from 'secp256k1'; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
412288
59
4234