@transmute/ed25519-key-pair
Advanced tools
Comparing version 0.6.1-unstable.34 to 0.6.1-unstable.35
@@ -5,3 +5,5 @@ 'use strict'; | ||
var tslib = require('tslib'); | ||
var ed25519 = require('@stablelib/ed25519'); | ||
var ldKeyPair = require('@transmute/ld-key-pair'); | ||
var x25519KeyPair = require('@transmute/x25519-key-pair'); | ||
@@ -1221,3 +1223,5 @@ | ||
var Ed25519KeyPair = /*#__PURE__*/function () { | ||
var Ed25519KeyPair_1; | ||
exports.Ed25519KeyPair = Ed25519KeyPair_1 = /*#__PURE__*/function () { | ||
function Ed25519KeyPair(opts) { | ||
@@ -1241,3 +1245,3 @@ this.type = 'JsonWebKey2020'; | ||
_context.next = 2; | ||
return Ed25519KeyPair.from(importableType); | ||
return Ed25519KeyPair_1.from(importableType); | ||
@@ -1280,3 +1284,3 @@ case 2: | ||
id: '', | ||
type: 'X25519KeyAgreementKey2018', | ||
type: 'X25519KeyAgreementKey2019', | ||
controller: kp.controller, | ||
@@ -1326,3 +1330,3 @@ publicKey: publicKey, | ||
_context3.next = 5; | ||
return Ed25519KeyPair.from({ | ||
return Ed25519KeyPair_1.from({ | ||
id: '', | ||
@@ -1388,16 +1392,39 @@ controller: '', | ||
_proto["export"] = function _export(options) { | ||
if (options === void 0) { | ||
options = { | ||
privateKey: false, | ||
type: 'JsonWebKey2020' | ||
}; | ||
} | ||
_proto["export"] = /*#__PURE__*/function () { | ||
var _export2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(options) { | ||
return runtime_1.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
if (options === void 0) { | ||
options = { | ||
privateKey: false, | ||
type: 'JsonWebKey2020' | ||
}; | ||
} | ||
if (exportableTypes[options.type]) { | ||
return exportableTypes[options.type](this.id, this.controller, this.publicKey, options.privateKey ? this.privateKey : undefined); | ||
if (!exportableTypes[options.type]) { | ||
_context5.next = 3; | ||
break; | ||
} | ||
return _context5.abrupt("return", exportableTypes[options.type](this.id, this.controller, this.publicKey, options.privateKey ? this.privateKey : undefined)); | ||
case 3: | ||
throw new Error('Unsupported export options: ' + JSON.stringify(options)); | ||
case 4: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function _export(_x4) { | ||
return _export2.apply(this, arguments); | ||
} | ||
throw new Error('Unsupported export options: ' + JSON.stringify(options)); | ||
}; | ||
return _export; | ||
}(); | ||
@@ -1436,7 +1463,36 @@ _proto.signer = function signer(type) { | ||
_proto.getDerivedKeyPairs = /*#__PURE__*/function () { | ||
var _getDerivedKeyPairs = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6() { | ||
return runtime_1.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_context6.t0 = this; | ||
_context6.next = 3; | ||
return Ed25519KeyPair_1.toX25519KeyPair(this); | ||
case 3: | ||
_context6.t1 = _context6.sent; | ||
return _context6.abrupt("return", [_context6.t0, _context6.t1]); | ||
case 5: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
function getDerivedKeyPairs() { | ||
return _getDerivedKeyPairs.apply(this, arguments); | ||
} | ||
return getDerivedKeyPairs; | ||
}(); | ||
_proto.toJsonWebKeyPair = /*#__PURE__*/function () { | ||
var _toJsonWebKeyPair = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(exportPrivateKey) { | ||
return runtime_1.wrap(function _callee5$(_context5) { | ||
var _toJsonWebKeyPair = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(exportPrivateKey) { | ||
return runtime_1.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
@@ -1448,13 +1504,13 @@ if (exportPrivateKey === void 0) { | ||
console.warn("DEPRECATION WARNING: .toJsonWebKeyPair should be replaced with .export({type:'JsonWebKey2020'})."); | ||
return _context5.abrupt("return", exportableTypes['JsonWebKey2020'](this.id, this.controller, this.publicKey, exportPrivateKey ? this.privateKey : undefined)); | ||
return _context7.abrupt("return", exportableTypes['JsonWebKey2020'](this.id, this.controller, this.publicKey, exportPrivateKey ? this.privateKey : undefined)); | ||
case 3: | ||
case "end": | ||
return _context5.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
}, _callee7, this); | ||
})); | ||
function toJsonWebKeyPair(_x4) { | ||
function toJsonWebKeyPair(_x5) { | ||
return _toJsonWebKeyPair.apply(this, arguments); | ||
@@ -1469,8 +1525,8 @@ } | ||
Ed25519KeyPair.generate = /*#__PURE__*/function () { | ||
var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(_ref2) { | ||
exports.Ed25519KeyPair.generate = /*#__PURE__*/function () { | ||
var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(_ref2) { | ||
var secureRandom, key, fingerprint, controller, id; | ||
return runtime_1.wrap(function _callee6$(_context6) { | ||
return runtime_1.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
@@ -1485,3 +1541,3 @@ secureRandom = _ref2.secureRandom; | ||
id = controller + "#" + fingerprint; | ||
return _context6.abrupt("return", new Ed25519KeyPair({ | ||
return _context8.abrupt("return", new Ed25519KeyPair_1({ | ||
id: id, | ||
@@ -1496,9 +1552,9 @@ type: 'JsonWebKey2020', | ||
case "end": | ||
return _context6.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee6); | ||
}, _callee8); | ||
})); | ||
return function (_x5) { | ||
return function (_x6) { | ||
return _ref3.apply(this, arguments); | ||
@@ -1508,12 +1564,12 @@ }; | ||
Ed25519KeyPair.from = /*#__PURE__*/function () { | ||
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(k) { | ||
exports.Ed25519KeyPair.from = /*#__PURE__*/function () { | ||
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(k) { | ||
var _importableTypes$k$ty, publicKey, privateKey; | ||
return runtime_1.wrap(function _callee7$(_context7) { | ||
return runtime_1.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
_importableTypes$k$ty = importableTypes[k.type](k), publicKey = _importableTypes$k$ty.publicKey, privateKey = _importableTypes$k$ty.privateKey; | ||
return _context7.abrupt("return", new Ed25519KeyPair({ | ||
return _context9.abrupt("return", new Ed25519KeyPair_1({ | ||
id: k.id, | ||
@@ -1528,9 +1584,9 @@ type: k.type, | ||
case "end": | ||
return _context7.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee7); | ||
}, _callee9); | ||
})); | ||
return function (_x6) { | ||
return function (_x7) { | ||
return _ref4.apply(this, arguments); | ||
@@ -1540,3 +1596,3 @@ }; | ||
exports.Ed25519KeyPair = Ed25519KeyPair; | ||
exports.Ed25519KeyPair = Ed25519KeyPair_1 = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/ldKeyPair.staticImplements()], exports.Ed25519KeyPair); | ||
//# sourceMappingURL=ed25519-key-pair.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@stablelib/ed25519"),t=require("@transmute/x25519-key-pair");function e(r,t,e,n,o,i,a){try{var u=r[i](a),c=u.value}catch(r){return void e(r)}u.done?t(c):Promise.resolve(c).then(n,o)}function n(r){return function(){var t=this,n=arguments;return new Promise((function(o,i){var a=r.apply(t,n);function u(r){e(a,o,i,u,c,"next",r)}function c(r){e(a,o,i,u,c,"throw",r)}u(void 0)}))}}function o(){return(o=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}var i,a=(function(r){var t=function(r){var t=Object.prototype,e=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(r,t,e){return Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}),r[t]}try{u({},"")}catch(r){u=function(r,t,e){return r[t]=e}}function c(r,t,e,n){var o=Object.create((t&&t.prototype instanceof p?t:p).prototype),i=new E(n||[]);return o._invoke=function(r,t,e){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(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=m(a,e);if(u){if(u===s)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=f(r,t,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===s)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(r,e,i),o}function f(r,t,e){try{return{type:"normal",arg:r.call(t,e)}}catch(r){return{type:"throw",arg:r}}}r.wrap=c;var s={};function p(){}function l(){}function h(){}var y={};y[o]=function(){return this};var v=Object.getPrototypeOf,d=v&&v(v(k([])));d&&d!==t&&e.call(d,o)&&(y=d);var w=h.prototype=p.prototype=Object.create(y);function g(r){["next","throw","return"].forEach((function(t){u(r,t,(function(r){return this._invoke(t,r)}))}))}function b(r,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var c=f(r[o],r,i);if("throw"!==c.type){var s=c.arg,p=s.value;return p&&"object"==typeof p&&e.call(p,"__await")?t.resolve(p.__await).then((function(r){n("next",r,a,u)}),(function(r){n("throw",r,a,u)})):t.resolve(p).then((function(r){s.value=r,a(s)}),(function(r){return n("throw",r,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function m(r,t){var e=r.iterator[t.method];if(void 0===e){if(t.delegate=null,"throw"===t.method){if(r.iterator.return&&(t.method="return",t.arg=void 0,m(r,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=f(e,r.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,s;var o=n.arg;return o?o.done?(t[r.resultName]=o.value,t.next=r.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function K(r){var t={tryLoc:r[0]};1 in r&&(t.catchLoc=r[1]),2 in r&&(t.finallyLoc=r[2],t.afterLoc=r[3]),this.tryEntries.push(t)}function x(r){var t=r.completion||{};t.type="normal",delete t.arg,r.completion=t}function E(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(K,this),this.reset(!0)}function k(r){if(r){var t=r[o];if(t)return t.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function t(){for(;++n<r.length;)if(e.call(r,n))return t.value=r[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:L}}function L(){return{value:void 0,done:!0}}return l.prototype=w.constructor=h,h.constructor=l,l.displayName=u(h,a,"GeneratorFunction"),r.isGeneratorFunction=function(r){var t="function"==typeof r&&r.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,h):(r.__proto__=h,u(r,a,"GeneratorFunction")),r.prototype=Object.create(w),r},r.awrap=function(r){return{__await:r}},g(b.prototype),b.prototype[i]=function(){return this},r.AsyncIterator=b,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new b(c(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(r){return r.done?r.value:a.next()}))},g(w),u(w,a,"Generator"),w[o]=function(){return this},w.toString=function(){return"[object Generator]"},r.keys=function(r){var t=[];for(var e in r)t.push(e);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=k,E.prototype={constructor:E,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 t in this)"t"===t.charAt(0)&&e.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=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 t=this;function n(e,n){return a.type="throw",a.arg=r,t.next=e,n&&(t.method="next",t.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 u=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(r,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===r||"continue"===r)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=r,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(a)},complete:function(r,t){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&&t&&(this.next=t),s},finish:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.finallyLoc===r)return this.complete(e.completion,e.afterLoc),x(e),s}},catch:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.tryLoc===r){var n=e.completion;if("throw"===n.type){var o=n.arg;x(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,t,e){return this.delegate={iterator:k(r),resultName:t,nextLoc:e},"next"===this.method&&(this.arg=void 0),s}},r}(r.exports);try{regeneratorRuntime=t}catch(r){Function("r","regeneratorRuntime = r")(t)}}(i={exports:{}}),i.exports);function u(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),e=0;e<t.length;e++)t[e]=255;for(var n=0;n<r.length;n++){var o=r.charAt(n),i=o.charCodeAt(0);if(255!==t[i])throw new TypeError(o+" is ambiguous");t[i]=n}var a=r.length,u=r.charAt(0),c=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function s(r){if("string"!=typeof r)throw new TypeError("Expected String");if(0===r.length)return Buffer.alloc(0);var e=0;if(" "!==r[e]){for(var n=0,o=0;r[e]===u;)n++,e++;for(var i=(r.length-e)*c+1>>>0,f=new Uint8Array(i);r[e];){var s=t[r.charCodeAt(e)];if(255===s)return;for(var p=0,l=i-1;(0!==s||p<o)&&-1!==l;l--,p++)f[l]=(s+=a*f[l]>>>0)%256>>>0,s=s/256>>>0;if(0!==s)throw new Error("Non-zero carry");o=p,e++}if(" "!==r[e]){for(var h=i-o;h!==i&&0===f[h];)h++;var y=Buffer.allocUnsafe(n+(i-h));y.fill(0,0,n);for(var v=n;h!==i;)y[v++]=f[h++];return y}}}return{encode:function(t){if((Array.isArray(t)||t instanceof Uint8Array)&&(t=Buffer.from(t)),!Buffer.isBuffer(t))throw new TypeError("Expected Buffer");if(0===t.length)return"";for(var e=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,e++;for(var c=(i-o)*f+1>>>0,s=new Uint8Array(c);o!==i;){for(var p=t[o],l=0,h=c-1;(0!==p||l<n)&&-1!==h;h--,l++)s[h]=(p+=256*s[h]>>>0)%a>>>0,p=p/a>>>0;if(0!==p)throw new Error("Non-zero carry");n=l,o++}for(var y=c-n;y!==c&&0===s[y];)y++;for(var v=u.repeat(e);y<c;++y)v+=r.charAt(s[y]);return v},decodeUnsafe:s,decode:function(r){var t=s(r);if(t)return t;throw new Error("Non-base"+a+" character")}}}var c=u("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),f=function(r){return function(r){return Buffer.from(r||"").toString("base64")}(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},s=function(r,t){void 0===t&&(t="base58btc");var e=new Uint8Array(2+r.length);if(e[0]=237,e[1]=1,e.set(r,2),"base58btc"===t)return"z"+c.encode(e);if("base64url"===t)return"u"+f(e);throw new Error("Unsupported encoding: "+t)},p=function(r){return Uint8Array.from(Buffer.from(r.x,"base64"))},l={JsonWebKey2020:function(r){var t,e=p(r.publicKeyJwk),n=void 0;return r.privateKeyJwk&&(p(t=r.privateKeyJwk),n=Uint8Array.from(Buffer.from(t.d,"base64"))),{publicKey:e,privateKey:n}},Ed25519VerificationKey2018:function(r){var t=c.decode(r.publicKeyBase58),e=void 0;return r.privateKeyBase58&&(e=Uint8Array.from(c.decode(r.privateKeyBase58))),{publicKey:t,privateKey:e}}},h={JsonWebKey2020:function(r,t,e,n){var i={kty:"OKP",crv:"Ed25519",x:f(e)},a={id:r,type:"JsonWebKey2020",controller:t,publicKeyJwk:i};return n&&(a.privateKeyJwk=o({},i,{d:f(n)})),a},Ed25519VerificationKey2018:function(r,t,e,n){var o={id:r,type:"Ed25519VerificationKey2018",controller:t,publicKeyBase58:c.encode(e)};return n&&(o.privateKeyBase58=c.encode(n)),o}},y={EdDsa:{__proto__:null,signer:function(t){return{sign:function(e){return n(a.mark((function n(){return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",r.sign(t,e.data));case 2:case"end":return n.stop()}}),n)})))()}}},verifier:function(t){return{verify:function(e){return n(a.mark((function n(){var o,i,u;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:o=e.data,i=e.signature,u=!1;try{u=r.verify(t,o,i)}catch(r){}return n.abrupt("return",u);case 4:case"end":return n.stop()}}),n)})))()}}}}},v=function(){function e(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}e.fingerprintFromPublicKey=function(){var r=n(a.mark((function r(t){return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,e.from(t);case 2:return r.abrupt("return",s(r.sent.publicKey));case 5:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}(),e.toX25519KeyPair=function(){var e=n(a.mark((function e(n){var o,i,u;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=r.convertPublicKeyToX25519(n.publicKey),i=void 0,n.privateKey&&(i=r.convertSecretKeyToX25519(n.privateKey)),u=new t.X25519KeyPair({id:"",type:"X25519KeyAgreementKey2018",controller:n.controller,publicKey:o,privateKey:i}),e.t0=n.controller+"#",e.next=7,u.fingerprint();case 7:return e.t1=e.sent,u.id=e.t0+e.t1,e.abrupt("return",u);case 10:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),e.fromFingerprint=function(){var r=n(a.mark((function r(t){var n,o,i,u;return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(237!==(o=c.decode((n=t.fingerprint).substring(1)))[0]||1!==o[1]){r.next=12;break}return r.next=5,e.from({id:"",controller:"",type:"Ed25519VerificationKey2018",publicKeyBase58:c.encode(o.slice(2))});case 5:return i=r.sent,r.next=8,i.fingerprint();case 8:return i.id="did:key:"+(u=r.sent)+"#"+u,i.controller="did:key:"+u,r.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+n);case 13:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}();var o=e.prototype;return o.fingerprint=function(){var r=n(a.mark((function r(){return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",s(this.publicKey));case 1:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),o.export=function(r){if(void 0===r&&(r={privateKey:!1,type:"JsonWebKey2020"}),h[r.type])return h[r.type](this.id,this.controller,this.publicKey,r.privateKey?this.privateKey:void 0);throw new Error("Unsupported export options: "+JSON.stringify(r))},o.signer=function(r){if(void 0===r&&(r="EdDsa"),!this.privateKey)throw new Error("No private key to sign with.");if(y[r])return y[r].signer(this.privateKey);throw new Error("Unsupported suite type "+r)},o.verifier=function(r){if(void 0===r&&(r="EdDsa"),!this.publicKey)throw new Error("No public key to verify with.");if(y[r])return y[r].verifier(this.publicKey);throw new Error("Unsupported suite type "+r)},o.toJsonWebKeyPair=function(){var r=n(a.mark((function r(t){return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return void 0===t&&(t=!1),console.warn("DEPRECATION WARNING: .toJsonWebKeyPair should be replaced with .export({type:'JsonWebKey2020'})."),r.abrupt("return",h.JsonWebKey2020(this.id,this.controller,this.publicKey,t?this.privateKey:void 0));case 3:case"end":return r.stop()}}),r,this)})));return function(t){return r.apply(this,arguments)}}(),e}();v.generate=function(){var t=n(a.mark((function t(e){var n,o,i;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.generateKeyPair({isAvailable:!0,randomBytes:e.secureRandom}),o=s(n.publicKey),t.abrupt("return",new v({id:(i="did:key:"+o)+"#"+o,type:"JsonWebKey2020",controller:i,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),v.from=function(){var r=n(a.mark((function r(t){var e;return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=l[t.type](t),r.abrupt("return",new v({id:t.id,type:t.type,controller:t.controller,publicKey:e.publicKey,privateKey:e.privateKey}));case 2:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}(),exports.Ed25519KeyPair=v; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),t=require("@stablelib/ed25519"),e=require("@transmute/ld-key-pair"),n=require("@transmute/x25519-key-pair");function o(r,t,e,n,o,i,a){try{var u=r[i](a),c=u.value}catch(r){return void e(r)}u.done?t(c):Promise.resolve(c).then(n,o)}function i(r){return function(){var t=this,e=arguments;return new Promise((function(n,i){var a=r.apply(t,e);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 a(){return(a=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}var u,c=(function(r){var t=function(r){var t=Object.prototype,e=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(r,t,e){return Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}),r[t]}try{u({},"")}catch(r){u=function(r,t,e){return r[t]=e}}function c(r,t,e,n){var o=Object.create((t&&t.prototype instanceof p?t:p).prototype),i=new E(n||[]);return o._invoke=function(r,t,e){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(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=m(a,e);if(u){if(u===f)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=s(r,t,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(r,e,i),o}function s(r,t,e){try{return{type:"normal",arg:r.call(t,e)}}catch(r){return{type:"throw",arg:r}}}r.wrap=c;var f={};function p(){}function l(){}function h(){}var y={};y[o]=function(){return this};var v=Object.getPrototypeOf,d=v&&v(v(k([])));d&&d!==t&&e.call(d,o)&&(y=d);var w=h.prototype=p.prototype=Object.create(y);function g(r){["next","throw","return"].forEach((function(t){u(r,t,(function(r){return this._invoke(t,r)}))}))}function b(r,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var c=s(r[o],r,i);if("throw"!==c.type){var f=c.arg,p=f.value;return p&&"object"==typeof p&&e.call(p,"__await")?t.resolve(p.__await).then((function(r){n("next",r,a,u)}),(function(r){n("throw",r,a,u)})):t.resolve(p).then((function(r){f.value=r,a(f)}),(function(r){return n("throw",r,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function m(r,t){var e=r.iterator[t.method];if(void 0===e){if(t.delegate=null,"throw"===t.method){if(r.iterator.return&&(t.method="return",t.arg=void 0,m(r,t),"throw"===t.method))return f;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(e,r.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,f;var o=n.arg;return o?o.done?(t[r.resultName]=o.value,t.next=r.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,f):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function K(r){var t={tryLoc:r[0]};1 in r&&(t.catchLoc=r[1]),2 in r&&(t.finallyLoc=r[2],t.afterLoc=r[3]),this.tryEntries.push(t)}function x(r){var t=r.completion||{};t.type="normal",delete t.arg,r.completion=t}function E(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(K,this),this.reset(!0)}function k(r){if(r){var t=r[o];if(t)return t.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function t(){for(;++n<r.length;)if(e.call(r,n))return t.value=r[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:L}}function L(){return{value:void 0,done:!0}}return l.prototype=w.constructor=h,h.constructor=l,l.displayName=u(h,a,"GeneratorFunction"),r.isGeneratorFunction=function(r){var t="function"==typeof r&&r.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,h):(r.__proto__=h,u(r,a,"GeneratorFunction")),r.prototype=Object.create(w),r},r.awrap=function(r){return{__await:r}},g(b.prototype),b.prototype[i]=function(){return this},r.AsyncIterator=b,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new b(c(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(r){return r.done?r.value:a.next()}))},g(w),u(w,a,"Generator"),w[o]=function(){return this},w.toString=function(){return"[object Generator]"},r.keys=function(r){var t=[];for(var e in r)t.push(e);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=k,E.prototype={constructor:E,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 t in this)"t"===t.charAt(0)&&e.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=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 t=this;function n(e,n){return a.type="throw",a.arg=r,t.next=e,n&&(t.method="next",t.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 u=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(r,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===r||"continue"===r)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=r,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(r,t){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&&t&&(this.next=t),f},finish:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.finallyLoc===r)return this.complete(e.completion,e.afterLoc),x(e),f}},catch:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.tryLoc===r){var n=e.completion;if("throw"===n.type){var o=n.arg;x(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,t,e){return this.delegate={iterator:k(r),resultName:t,nextLoc:e},"next"===this.method&&(this.arg=void 0),f}},r}(r.exports);try{regeneratorRuntime=t}catch(r){Function("r","regeneratorRuntime = r")(t)}}(u={exports:{}}),u.exports);function s(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),e=0;e<t.length;e++)t[e]=255;for(var n=0;n<r.length;n++){var o=r.charAt(n),i=o.charCodeAt(0);if(255!==t[i])throw new TypeError(o+" is ambiguous");t[i]=n}var a=r.length,u=r.charAt(0),c=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 e=0;if(" "!==r[e]){for(var n=0,o=0;r[e]===u;)n++,e++;for(var i=(r.length-e)*c+1>>>0,s=new Uint8Array(i);r[e];){var f=t[r.charCodeAt(e)];if(255===f)return;for(var p=0,l=i-1;(0!==f||p<o)&&-1!==l;l--,p++)s[l]=(f+=a*s[l]>>>0)%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");o=p,e++}if(" "!==r[e]){for(var h=i-o;h!==i&&0===s[h];)h++;var y=Buffer.allocUnsafe(n+(i-h));y.fill(0,0,n);for(var v=n;h!==i;)y[v++]=s[h++];return y}}}return{encode:function(t){if((Array.isArray(t)||t instanceof Uint8Array)&&(t=Buffer.from(t)),!Buffer.isBuffer(t))throw new TypeError("Expected Buffer");if(0===t.length)return"";for(var e=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,e++;for(var c=(i-o)*s+1>>>0,f=new Uint8Array(c);o!==i;){for(var p=t[o],l=0,h=c-1;(0!==p||l<n)&&-1!==h;h--,l++)f[h]=(p+=256*f[h]>>>0)%a>>>0,p=p/a>>>0;if(0!==p)throw new Error("Non-zero carry");n=l,o++}for(var y=c-n;y!==c&&0===f[y];)y++;for(var v=u.repeat(e);y<c;++y)v+=r.charAt(f[y]);return v},decodeUnsafe:f,decode:function(r){var t=f(r);if(t)return t;throw new Error("Non-base"+a+" character")}}}var f,p=s("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),l=function(r){return function(r){return Buffer.from(r||"").toString("base64")}(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},h=function(r,t){void 0===t&&(t="base58btc");var e=new Uint8Array(2+r.length);if(e[0]=237,e[1]=1,e.set(r,2),"base58btc"===t)return"z"+p.encode(e);if("base64url"===t)return"u"+l(e);throw new Error("Unsupported encoding: "+t)},y=function(r){return Uint8Array.from(Buffer.from(r.x,"base64"))},v={JsonWebKey2020:function(r){var t,e=y(r.publicKeyJwk),n=void 0;return r.privateKeyJwk&&(y(t=r.privateKeyJwk),n=Uint8Array.from(Buffer.from(t.d,"base64"))),{publicKey:e,privateKey:n}},Ed25519VerificationKey2018:function(r){var t=p.decode(r.publicKeyBase58),e=void 0;return r.privateKeyBase58&&(e=Uint8Array.from(p.decode(r.privateKeyBase58))),{publicKey:t,privateKey:e}}},d={JsonWebKey2020:function(r,t,e,n){var o={kty:"OKP",crv:"Ed25519",x:l(e)},i={id:r,type:"JsonWebKey2020",controller:t,publicKeyJwk:o};return n&&(i.privateKeyJwk=a({},o,{d:l(n)})),i},Ed25519VerificationKey2018:function(r,t,e,n){var o={id:r,type:"Ed25519VerificationKey2018",controller:t,publicKeyBase58:p.encode(e)};return n&&(o.privateKeyBase58=p.encode(n)),o}},w={EdDsa:{__proto__:null,signer:function(r){return{sign:function(e){return i(c.mark((function n(){return c.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",t.sign(r,e.data));case 2:case"end":return n.stop()}}),n)})))()}}},verifier:function(r){return{verify:function(e){return i(c.mark((function n(){var o,i,a;return c.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:o=e.data,i=e.signature,a=!1;try{a=t.verify(r,o,i)}catch(r){}return n.abrupt("return",a);case 4:case"end":return n.stop()}}),n)})))()}}}}};exports.Ed25519KeyPair=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=i(c.mark((function r(t){return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,f.from(t);case 2:return r.abrupt("return",h(r.sent.publicKey));case 5:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}(),r.toX25519KeyPair=function(){var r=i(c.mark((function r(e){var o,i,a;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=t.convertPublicKeyToX25519(e.publicKey),i=void 0,e.privateKey&&(i=t.convertSecretKeyToX25519(e.privateKey)),a=new n.X25519KeyPair({id:"",type:"X25519KeyAgreementKey2019",controller:e.controller,publicKey:o,privateKey:i}),r.t0=e.controller+"#",r.next=7,a.fingerprint();case 7:return r.t1=r.sent,a.id=r.t0+r.t1,r.abrupt("return",a);case 10:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}(),r.fromFingerprint=function(){var r=i(c.mark((function r(t){var e,n,o,i;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(237!==(n=p.decode((e=t.fingerprint).substring(1)))[0]||1!==n[1]){r.next=12;break}return r.next=5,f.from({id:"",controller:"",type:"Ed25519VerificationKey2018",publicKeyBase58:p.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: "+e);case 13:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}();var e=r.prototype;return e.fingerprint=function(){var r=i(c.mark((function r(){return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",h(this.publicKey));case 1:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),e.export=function(){var r=i(c.mark((function r(t){return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0===t&&(t={privateKey:!1,type:"JsonWebKey2020"}),!d[t.type]){r.next=3;break}return r.abrupt("return",d[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 r.stop()}}),r,this)})));return function(t){return r.apply(this,arguments)}}(),e.signer=function(r){if(void 0===r&&(r="EdDsa"),!this.privateKey)throw new Error("No private key to sign with.");if(w[r])return w[r].signer(this.privateKey);throw new Error("Unsupported suite type "+r)},e.verifier=function(r){if(void 0===r&&(r="EdDsa"),!this.publicKey)throw new Error("No public key to verify with.");if(w[r])return w[r].verifier(this.publicKey);throw new Error("Unsupported suite type "+r)},e.getDerivedKeyPairs=function(){var r=i(c.mark((function r(){return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.t0=this,r.next=3,f.toX25519KeyPair(this);case 3:return r.t1=r.sent,r.abrupt("return",[r.t0,r.t1]);case 5:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),e.toJsonWebKeyPair=function(){var r=i(c.mark((function r(t){return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return void 0===t&&(t=!1),console.warn("DEPRECATION WARNING: .toJsonWebKeyPair should be replaced with .export({type:'JsonWebKey2020'})."),r.abrupt("return",d.JsonWebKey2020(this.id,this.controller,this.publicKey,t?this.privateKey:void 0));case 3:case"end":return r.stop()}}),r,this)})));return function(t){return r.apply(this,arguments)}}(),r}(),exports.Ed25519KeyPair.generate=function(){var r=i(c.mark((function r(e){var n,o,i;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=t.generateKeyPair({isAvailable:!0,randomBytes:e.secureRandom}),o=h(n.publicKey),r.abrupt("return",new f({id:(i="did:key:"+o)+"#"+o,type:"JsonWebKey2020",controller:i,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}(),exports.Ed25519KeyPair.from=function(){var r=i(c.mark((function r(t){var e;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=v[t.type](t),r.abrupt("return",new f({id:t.id,type:t.type,controller:t.controller,publicKey:e.publicKey,privateKey:e.privateKey}));case 2:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}(),exports.Ed25519KeyPair=f=r.__decorate([e.staticImplements()],exports.Ed25519KeyPair); | ||
//# sourceMappingURL=ed25519-key-pair.cjs.production.min.js.map |
@@ -0,2 +1,4 @@ | ||
import { __decorate } from 'tslib'; | ||
import { sign, verify, generateKeyPair, convertPublicKeyToX25519, convertSecretKeyToX25519 } from '@stablelib/ed25519'; | ||
import { staticImplements } from '@transmute/ld-key-pair'; | ||
import { X25519KeyPair } from '@transmute/x25519-key-pair'; | ||
@@ -1216,3 +1218,5 @@ | ||
var Ed25519KeyPair = /*#__PURE__*/function () { | ||
var Ed25519KeyPair_1; | ||
var Ed25519KeyPair = Ed25519KeyPair_1 = /*#__PURE__*/function () { | ||
function Ed25519KeyPair(opts) { | ||
@@ -1236,3 +1240,3 @@ this.type = 'JsonWebKey2020'; | ||
_context.next = 2; | ||
return Ed25519KeyPair.from(importableType); | ||
return Ed25519KeyPair_1.from(importableType); | ||
@@ -1275,3 +1279,3 @@ case 2: | ||
id: '', | ||
type: 'X25519KeyAgreementKey2018', | ||
type: 'X25519KeyAgreementKey2019', | ||
controller: kp.controller, | ||
@@ -1321,3 +1325,3 @@ publicKey: publicKey, | ||
_context3.next = 5; | ||
return Ed25519KeyPair.from({ | ||
return Ed25519KeyPair_1.from({ | ||
id: '', | ||
@@ -1383,16 +1387,39 @@ controller: '', | ||
_proto["export"] = function _export(options) { | ||
if (options === void 0) { | ||
options = { | ||
privateKey: false, | ||
type: 'JsonWebKey2020' | ||
}; | ||
} | ||
_proto["export"] = /*#__PURE__*/function () { | ||
var _export2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(options) { | ||
return runtime_1.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
if (options === void 0) { | ||
options = { | ||
privateKey: false, | ||
type: 'JsonWebKey2020' | ||
}; | ||
} | ||
if (exportableTypes[options.type]) { | ||
return exportableTypes[options.type](this.id, this.controller, this.publicKey, options.privateKey ? this.privateKey : undefined); | ||
if (!exportableTypes[options.type]) { | ||
_context5.next = 3; | ||
break; | ||
} | ||
return _context5.abrupt("return", exportableTypes[options.type](this.id, this.controller, this.publicKey, options.privateKey ? this.privateKey : undefined)); | ||
case 3: | ||
throw new Error('Unsupported export options: ' + JSON.stringify(options)); | ||
case 4: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function _export(_x4) { | ||
return _export2.apply(this, arguments); | ||
} | ||
throw new Error('Unsupported export options: ' + JSON.stringify(options)); | ||
}; | ||
return _export; | ||
}(); | ||
@@ -1431,7 +1458,36 @@ _proto.signer = function signer(type) { | ||
_proto.getDerivedKeyPairs = /*#__PURE__*/function () { | ||
var _getDerivedKeyPairs = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6() { | ||
return runtime_1.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_context6.t0 = this; | ||
_context6.next = 3; | ||
return Ed25519KeyPair_1.toX25519KeyPair(this); | ||
case 3: | ||
_context6.t1 = _context6.sent; | ||
return _context6.abrupt("return", [_context6.t0, _context6.t1]); | ||
case 5: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
function getDerivedKeyPairs() { | ||
return _getDerivedKeyPairs.apply(this, arguments); | ||
} | ||
return getDerivedKeyPairs; | ||
}(); | ||
_proto.toJsonWebKeyPair = /*#__PURE__*/function () { | ||
var _toJsonWebKeyPair = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(exportPrivateKey) { | ||
return runtime_1.wrap(function _callee5$(_context5) { | ||
var _toJsonWebKeyPair = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(exportPrivateKey) { | ||
return runtime_1.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
@@ -1443,13 +1499,13 @@ if (exportPrivateKey === void 0) { | ||
console.warn("DEPRECATION WARNING: .toJsonWebKeyPair should be replaced with .export({type:'JsonWebKey2020'})."); | ||
return _context5.abrupt("return", exportableTypes['JsonWebKey2020'](this.id, this.controller, this.publicKey, exportPrivateKey ? this.privateKey : undefined)); | ||
return _context7.abrupt("return", exportableTypes['JsonWebKey2020'](this.id, this.controller, this.publicKey, exportPrivateKey ? this.privateKey : undefined)); | ||
case 3: | ||
case "end": | ||
return _context5.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
}, _callee7, this); | ||
})); | ||
function toJsonWebKeyPair(_x4) { | ||
function toJsonWebKeyPair(_x5) { | ||
return _toJsonWebKeyPair.apply(this, arguments); | ||
@@ -1465,7 +1521,7 @@ } | ||
Ed25519KeyPair.generate = /*#__PURE__*/function () { | ||
var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(_ref2) { | ||
var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(_ref2) { | ||
var secureRandom, key, fingerprint, controller, id; | ||
return runtime_1.wrap(function _callee6$(_context6) { | ||
return runtime_1.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
@@ -1480,3 +1536,3 @@ secureRandom = _ref2.secureRandom; | ||
id = controller + "#" + fingerprint; | ||
return _context6.abrupt("return", new Ed25519KeyPair({ | ||
return _context8.abrupt("return", new Ed25519KeyPair_1({ | ||
id: id, | ||
@@ -1491,9 +1547,9 @@ type: 'JsonWebKey2020', | ||
case "end": | ||
return _context6.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee6); | ||
}, _callee8); | ||
})); | ||
return function (_x5) { | ||
return function (_x6) { | ||
return _ref3.apply(this, arguments); | ||
@@ -1504,11 +1560,11 @@ }; | ||
Ed25519KeyPair.from = /*#__PURE__*/function () { | ||
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(k) { | ||
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(k) { | ||
var _importableTypes$k$ty, publicKey, privateKey; | ||
return runtime_1.wrap(function _callee7$(_context7) { | ||
return runtime_1.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
_importableTypes$k$ty = importableTypes[k.type](k), publicKey = _importableTypes$k$ty.publicKey, privateKey = _importableTypes$k$ty.privateKey; | ||
return _context7.abrupt("return", new Ed25519KeyPair({ | ||
return _context9.abrupt("return", new Ed25519KeyPair_1({ | ||
id: k.id, | ||
@@ -1523,9 +1579,9 @@ type: k.type, | ||
case "end": | ||
return _context7.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee7); | ||
}, _callee9); | ||
})); | ||
return function (_x6) { | ||
return function (_x7) { | ||
return _ref4.apply(this, arguments); | ||
@@ -1535,3 +1591,5 @@ }; | ||
Ed25519KeyPair = Ed25519KeyPair_1 = /*#__PURE__*/__decorate([/*#__PURE__*/staticImplements()], Ed25519KeyPair); | ||
export { Ed25519KeyPair }; | ||
//# sourceMappingURL=ed25519-key-pair.esm.js.map |
import { JsonWebKey2020, Ed25519VerificationKey2018 } from './types'; | ||
import { LdKeyPairInstance } from '@transmute/ld-key-pair'; | ||
import { X25519KeyPair } from '@transmute/x25519-key-pair'; | ||
export declare class Ed25519KeyPair { | ||
export declare class Ed25519KeyPair implements LdKeyPairInstance { | ||
id: string; | ||
@@ -29,3 +30,3 @@ type: string; | ||
type: 'JsonWebKey2020' | 'Ed25519VerificationKey2018'; | ||
}): JsonWebKey2020 | Ed25519VerificationKey2018; | ||
}): Promise<JsonWebKey2020 | Ed25519VerificationKey2018>; | ||
signer(type?: 'EdDsa'): { | ||
@@ -37,3 +38,4 @@ sign({ data }: any): Promise<Uint8Array>; | ||
}; | ||
getDerivedKeyPairs(): Promise<(this | X25519KeyPair)[]>; | ||
toJsonWebKeyPair(exportPrivateKey?: boolean): Promise<JsonWebKey2020>; | ||
} |
@@ -5,3 +5,3 @@ { | ||
"module": "dist/ed25519-key-pair.esm.js", | ||
"version": "0.6.1-unstable.34", | ||
"version": "0.6.1-unstable.35", | ||
"license": "Apache-2.0", | ||
@@ -61,5 +61,6 @@ "homepage": "https://github.com/transmute-industries/verifiable-data/tree/main/packages/ed25519-key-pair", | ||
"@stablelib/ed25519": "^1.0.1", | ||
"@transmute/x25519-key-pair": "^0.6.1-unstable.34" | ||
"@transmute/ld-key-pair": "^0.6.1-unstable.35", | ||
"@transmute/x25519-key-pair": "^0.6.1-unstable.35" | ||
}, | ||
"gitHead": "9a364d71c17a796491afc9a60c178b9e750bab56" | ||
"gitHead": "6502aa3ec909e96f0f7102941f3ac4bd19a8b33f" | ||
} |
@@ -104,3 +104,3 @@ import { Ed25519KeyPair, JsonWebKey2020 } from '../index'; | ||
}); | ||
const kx = kn.export({ type: 'JsonWebKey2020' }); | ||
const kx = await kn.export({ type: 'JsonWebKey2020' }); | ||
expect(kx).toEqual({ | ||
@@ -107,0 +107,0 @@ id: |
@@ -5,3 +5,7 @@ import * as ed25519 from '@stablelib/ed25519'; | ||
import { JsonWebKey2020, Ed25519VerificationKey2018 } from './types'; | ||
import { | ||
LdKeyPairStatic, | ||
LdKeyPairInstance, | ||
staticImplements, | ||
} from '@transmute/ld-key-pair'; | ||
import { importableTypes } from './importFrom'; | ||
@@ -19,3 +23,4 @@ import { exportableTypes } from './exportAs'; | ||
export class Ed25519KeyPair { | ||
@staticImplements<LdKeyPairStatic>() | ||
export class Ed25519KeyPair implements LdKeyPairInstance { | ||
public id: string; | ||
@@ -40,3 +45,3 @@ public type: string = 'JsonWebKey2020'; | ||
id: '', | ||
type: 'X25519KeyAgreementKey2018', | ||
type: 'X25519KeyAgreementKey2019', | ||
controller: kp.controller, | ||
@@ -125,3 +130,3 @@ publicKey, | ||
export( | ||
async export( | ||
options: { | ||
@@ -134,3 +139,3 @@ privateKey?: boolean; | ||
} | ||
): JsonWebKey2020 | Ed25519VerificationKey2018 { | ||
): Promise<JsonWebKey2020 | Ed25519VerificationKey2018> { | ||
if (exportableTypes[options.type]) { | ||
@@ -166,2 +171,6 @@ return exportableTypes[options.type]( | ||
async getDerivedKeyPairs() { | ||
return [this, await Ed25519KeyPair.toX25519KeyPair(this)]; | ||
} | ||
async toJsonWebKeyPair(exportPrivateKey = false) { | ||
@@ -168,0 +177,0 @@ console.warn( |
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
362880
3579
3