You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@tonomy/antelope-ssi-toolkit

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tonomy/antelope-ssi-toolkit - npm Package Compare versions

Comparing version

to
1.0.3

61

dist/antelope-ssi-toolkit.cjs.development.js

@@ -6,4 +6,6 @@ 'use strict';

var didJwtVc = require('@tonomy/did-jwt-vc');
require('@greymass/eosio');
require('@tonomy/did-jwt');
var antelopeDidResolver = require('@tonomy/antelope-did-resolver');
var eosio = require('@greymass/eosio');
var didJwt = require('@tonomy/did-jwt');
var didResolver = require('@tonomy/did-resolver');

@@ -391,8 +393,6 @@ function _regeneratorRuntime() {

var OutputType;
(function (OutputType) {
OutputType["JWT"] = "JWT";
OutputType["JSONLD"] = "JSONLD";
})(OutputType || (OutputType = {}));
})(exports.OutputType || (exports.OutputType = {}));

@@ -429,9 +429,27 @@ (function (OutputType) {

OutputType.from = from;
})(OutputType || (OutputType = {}));
})(exports.OutputType || (exports.OutputType = {}));
/* Creates a signer from a private key that can be used to sign a JWT
*
* @param privateKey the private key to use to sign the JWT
* @returns a signer (function) that can be used to sign a JWT
*/
function createSigner(privateKey) {
if (privateKey.type === eosio.KeyType.K1) {
return didJwt.ES256KSigner(privateKey.data.array, true);
}
if (privateKey.type === eosio.KeyType.R1 || privateKey.type === eosio.KeyType.WA) {
return didJwt.ES256Signer(privateKey.data.array);
}
throw new Error('Unsupported key type');
}
/**
* Issues a verifiable credential
* @param credential the verfiable credential to issue
*
* @param credential the verifiable credential to issue
* @param credentialOptions the options to issue the credential with
* @returns the issued credential signed by one or more issuers
* @returns the issued jwt credential signed by one or more issuers
*/

@@ -441,6 +459,12 @@

return _issue.apply(this, arguments);
} // TODO asynchroneously add signatures to the credential
// export async function addSignature(credential: VerifiableCredential, credentialOptions: CredentialOptions, options?: EosioOptions): Promise<CredentialSigned> {
// throw Error("Not implemented");
// }
}
/**
* Verifies a credential signed by a did:antelope or did:eosio issuer
* For a more complete verification result, use the verifyCredential function from @tonomy/did-jwt-vc
*
* @param credential the signed jwt verifiable credential to verify
* @param credentialOptions the options to verify the credential with
*
* @returns true if the signature matches the issuer
*/

@@ -453,3 +477,3 @@ function _issue() {

case 0:
if (!(credentialOptions.outputType && credentialOptions.outputType !== OutputType.JWT)) {
if (!(credentialOptions.outputType && credentialOptions.outputType !== exports.OutputType.JWT)) {
_context.next = 2;

@@ -486,2 +510,3 @@ break;

_verify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(verifiableCredential, options) {
var resolver;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {

@@ -491,9 +516,10 @@ while (1) {

case 0:
_context2.next = 2;
return didJwtVc.verifyCredential(verifiableCredential, {}, options);
resolver = new didResolver.Resolver(antelopeDidResolver.getResolver());
_context2.next = 3;
return didJwtVc.verifyCredential(verifiableCredential, resolver, options);
case 2:
case 3:
return _context2.abrupt("return", !!_context2.sent);
case 3:
case 4:
case "end":

@@ -508,4 +534,5 @@ return _context2.stop();

exports.createSigner = createSigner;
exports.issue = issue;
exports.verify = verify;
//# sourceMappingURL=antelope-ssi-toolkit.cjs.development.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=require("@tonomy/did-jwt-vc");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=Object.create((r&&r.prototype instanceof l?r:l).prototype),i=new O(n||[]);return o._invoke=function(t,r,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=L(a,e);if(u){if(u===h)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(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,i),o}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var h={};function l(){}function p(){}function y(){}var v={};c(v,i,(function(){return this}));var d=Object.getPrototypeOf,g=d&&d(d(_([])));g&&g!==r&&n.call(g,i)&&(v=g);var m=y.prototype=l.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function x(t,r){var e;this._invoke=function(o,i){function a(){return new r((function(e,a){!function e(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,h=s.value;return h&&"object"==typeof h&&n.call(h,"__await")?r.resolve(h.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(h).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}(o,i,e,a)}))}return e=e?e.then(a,a):a()}}function L(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,L(t,r),"throw"===r.method))return h;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=f(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,h;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,h):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function b(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function E(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function _(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,o=function r(){for(;++e<t.length;)if(n.call(t,e))return r.value=t[e],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:j}}function j(){return{value:void 0,done:!0}}return p.prototype=y,c(m,"constructor",y),c(y,"constructor",p),p.displayName=c(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,c(t,u,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),c(x.prototype,a,(function(){return this})),t.AsyncIterator=x,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new x(s(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),c(m,u,"Generator"),c(m,i,(function(){return this})),c(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=_,O.prototype={constructor:O,reset:function(t){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(E),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function e(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.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 e("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return e(i.catchLoc,!0);if(this.prev<i.finallyLoc)return e(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return e(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return e(i.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),h},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),E(e),h}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;E(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:_(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),h}},t}function n(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function o(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function u(t){n(a,o,i,u,c,"next",t)}function c(t){n(a,o,i,u,c,"throw",t)}u(void 0)}))}}function i(){return(i=o(e().mark((function n(o,i){return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!i.outputType||i.outputType===t.JWT){e.next=2;break}throw new Error("Only JWT output type is supported for now");case 2:return e.next=4,r.createVerifiableCredentialJwt(o,i.issuer,{canonicalize:!0});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),n)})))).apply(this,arguments)}function a(){return(a=o(e().mark((function t(n,o){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.verifyCredential(n,{},o);case 2:return t.abrupt("return",!!t.sent);case 3:case"end":return t.stop()}}),t)})))).apply(this,arguments)}require("@greymass/eosio"),require("@tonomy/did-jwt"),function(t){t.JWT="JWT",t.JSONLD="JSONLD"}(t||(t={})),function(t){t.indexFor=function(r){return Object.keys(t).indexOf(r)},t.from=function(r){var e;return e="number"!=typeof r?t.indexFor(r):r,Object.values(t)[e]}}(t||(t={})),exports.issue=function(t,r){return i.apply(this,arguments)},exports.verify=function(t,r){return a.apply(this,arguments)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=require("@tonomy/did-jwt-vc"),e=require("@tonomy/antelope-did-resolver"),n=require("@greymass/eosio"),o=require("@tonomy/did-jwt"),i=require("@tonomy/did-resolver");function a(){a=function(){return t};var t={},r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",u=n.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=Object.create((r&&r.prototype instanceof p?r:p).prototype),i=new O(n||[]);return o._invoke=function(t,r,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=L(a,e);if(u){if(u===h)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(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,i),o}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var h={};function p(){}function l(){}function y(){}var v={};c(v,o,(function(){return this}));var d=Object.getPrototypeOf,g=d&&d(d(T([])));g&&g!==r&&e.call(g,o)&&(v=g);var m=y.prototype=p.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function x(t,r){var n;this._invoke=function(o,i){function a(){return new r((function(n,a){!function n(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,h=s.value;return h&&"object"==typeof h&&e.call(h,"__await")?r.resolve(h.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(h).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function L(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,L(t,r),"throw"===r.method))return h;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=f(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,h;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,h):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function b(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function E(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function T(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:_}}function _(){return{value:void 0,done:!0}}return l.prototype=y,c(m,"constructor",y),c(y,"constructor",l),l.displayName=c(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===l||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,c(t,u,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),c(x.prototype,i,(function(){return this})),t.AsyncIterator=x,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new x(s(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),c(m,u,"Generator"),c(m,o,(function(){return this})),c(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=T,O.prototype={constructor:O,reset:function(t){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(E),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.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(t,r){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"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),h},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),E(e),h}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;E(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:T(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),h}},t}function u(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function c(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var i=t.apply(r,e);function a(t){u(i,n,o,a,c,"next",t)}function c(t){u(i,n,o,a,c,"throw",t)}a(void 0)}))}}function s(){return(s=c(a().mark((function t(e,n){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!n.outputType||n.outputType===exports.OutputType.JWT){t.next=2;break}throw new Error("Only JWT output type is supported for now");case 2:return t.next=4,r.createVerifiableCredentialJwt(e,n.issuer,{canonicalize:!0});case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function f(){return(f=c(a().mark((function t(n,o){var u;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return u=new i.Resolver(e.getResolver()),t.next=3,r.verifyCredential(n,u,o);case 3:return t.abrupt("return",!!t.sent);case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}(t=exports.OutputType||(exports.OutputType={})).JWT="JWT",t.JSONLD="JSONLD",function(t){t.indexFor=function(r){return Object.keys(t).indexOf(r)},t.from=function(r){var e;return e="number"!=typeof r?t.indexFor(r):r,Object.values(t)[e]}}(exports.OutputType||(exports.OutputType={})),exports.createSigner=function(t){if(t.type===n.KeyType.K1)return o.ES256KSigner(t.data.array,!0);if(t.type===n.KeyType.R1||t.type===n.KeyType.WA)return o.ES256Signer(t.data.array);throw new Error("Unsupported key type")},exports.issue=function(t,r){return s.apply(this,arguments)},exports.verify=function(t,r){return f.apply(this,arguments)};
//# sourceMappingURL=antelope-ssi-toolkit.cjs.production.min.js.map
import { verifyCredential, createVerifiableCredentialJwt } from '@tonomy/did-jwt-vc';
import '@greymass/eosio';
import '@tonomy/did-jwt';
import { getResolver } from '@tonomy/antelope-did-resolver';
import { KeyType } from '@greymass/eosio';
import { ES256KSigner, ES256Signer } from '@tonomy/did-jwt';
import { Resolver } from '@tonomy/did-resolver';

@@ -425,7 +427,25 @@ function _regeneratorRuntime() {

/* Creates a signer from a private key that can be used to sign a JWT
*
* @param privateKey the private key to use to sign the JWT
* @returns a signer (function) that can be used to sign a JWT
*/
function createSigner(privateKey) {
if (privateKey.type === KeyType.K1) {
return ES256KSigner(privateKey.data.array, true);
}
if (privateKey.type === KeyType.R1 || privateKey.type === KeyType.WA) {
return ES256Signer(privateKey.data.array);
}
throw new Error('Unsupported key type');
}
/**
* Issues a verifiable credential
* @param credential the verfiable credential to issue
*
* @param credential the verifiable credential to issue
* @param credentialOptions the options to issue the credential with
* @returns the issued credential signed by one or more issuers
* @returns the issued jwt credential signed by one or more issuers
*/

@@ -435,6 +455,12 @@

return _issue.apply(this, arguments);
} // TODO asynchroneously add signatures to the credential
// export async function addSignature(credential: VerifiableCredential, credentialOptions: CredentialOptions, options?: EosioOptions): Promise<CredentialSigned> {
// throw Error("Not implemented");
// }
}
/**
* Verifies a credential signed by a did:antelope or did:eosio issuer
* For a more complete verification result, use the verifyCredential function from @tonomy/did-jwt-vc
*
* @param credential the signed jwt verifiable credential to verify
* @param credentialOptions the options to verify the credential with
*
* @returns true if the signature matches the issuer
*/

@@ -479,2 +505,3 @@ function _issue() {

_verify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(verifiableCredential, options) {
var resolver;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {

@@ -484,9 +511,10 @@ while (1) {

case 0:
_context2.next = 2;
return verifyCredential(verifiableCredential, {}, options);
resolver = new Resolver(getResolver());
_context2.next = 3;
return verifyCredential(verifiableCredential, resolver, options);
case 2:
case 3:
return _context2.abrupt("return", !!_context2.sent);
case 3:
case 4:
case "end":

@@ -501,3 +529,3 @@ return _context2.stop();

export { issue, verify };
export { OutputType, createSigner, issue, verify };
//# sourceMappingURL=antelope-ssi-toolkit.esm.js.map
import { CredentialOptions } from './credentials.types';
import { W3CCredential } from '@tonomy/did-jwt-vc';
import { PrivateKey, PublicKey } from '@greymass/eosio';
import { PrivateKey } from '@greymass/eosio';
import { Signer } from '@tonomy/did-jwt';
import { JWT } from '@tonomy/did-jwt-vc/lib/types';
export declare function createSigner(privateKey: PrivateKey): import("@tonomy/did-jwt").Signer;
export declare function keyToJwsAlgo(publicKey: PublicKey): string;
export declare function createSigner(privateKey: PrivateKey): Signer;
/**
* Issues a verifiable credential
* @param credential the verfiable credential to issue
*
* @param credential the verifiable credential to issue
* @param credentialOptions the options to issue the credential with
* @returns the issued credential signed by one or more issuers
* @returns the issued jwt credential signed by one or more issuers
*/
export declare function issue(credential: W3CCredential, credentialOptions: CredentialOptions): Promise<JWT>;
/**
* Verifies a credential signed by a did:antelope or did:eosio issuer
* For a more complete verification result, use the verifyCredential function from @tonomy/did-jwt-vc
*
* @param credential the signed jwt verifiable credential to verify
* @param credentialOptions the options to verify the credential with
*
* @returns true if the signature matches the issuer
*/
export declare function verify(verifiableCredential: JWT, options?: CredentialOptions): Promise<boolean>;

@@ -1,2 +0,2 @@

import { issue, verify } from './credentials';
export { issue, verify };
export * from './credentials';
export * from './credentials.types';
{
"name": "@tonomy/antelope-ssi-toolkit",
"author": "Jack Tanner",
"version": "1.0.1",
"version": "1.0.3",
"license": "MIT",

@@ -67,6 +67,6 @@ "main": "dist/index.js",

"@tonomy/antelope-did": "^0.1.3",
"@tonomy/did-jwt": "^6.9.0",
"@tonomy/did-jwt-vc": "^3.1.2",
"@tonomy/did-jwt": "^6.9.2",
"@tonomy/did-jwt-vc": "^3.1.3",
"@tonomy/did-resolver": "^4.0.4"
}
}

@@ -1,59 +0,53 @@

# Antelope (formerly EOSIO) Self-sovereign identity (SSI) Toolkit
# Antelope Self-sovereign identity (SSI) Toolkit
A toolkit allowing Antelope accounts to send verifiable credentials and use DIDComm.
A toolkit allowing Antelope (formerly EOSIO) accounts to use SSI components:
# Usage
- Verifiable Credentials
- DIDComm (planned)
## Create a and verify a credential
## Install
```ts
const privateKey = '5J...';
const myId = "did:eosio:telos:mytelosaccount";
const universityId = "did:eosio:telos:exampleuniversity";
const universityVerificationMethod = "did:eosio:telos:exampleuniversity#active";
```bash
npm i @tonomy/antelope-ssi-toolkit
```
## Usage
const credential = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
id: myId,
type: ["VerifiableCredential", "AlumniCredential"],
issuer: universityId,
issuanceDate: new Date("2010-01-01T19:23:24Z"),
credentialSubject: {
id: myId,
alumniOf: "Example University"
}
};
### Create a and verify a credential
const credentials = new Credentials();
```typescript
import { createSigner, issue, verify } from '@tonomy/antelope-ssi-toolkit';
import { PrivateKey } from "@greymass/eosio";
const vc = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
id: "https://example.com/id/1234324",
type: ['VerifiableCredential'],
issuer: {
id: `did:antelope:telos:university`,
},
issuanceDate: (new Date()).toISOString(),
credentialSubject: {
degree: {
type: 'BachelorDegree',
name: 'Bachelor of Music'
}
}
}
const issuer = {
did: universityVerificationMethod,
signer: credentials.signer(privateKey)
did: "did:antelope:telos:university#active",
signer: createSigner(PrivateKey.from("PVT_K1_2bfGi9rYsXQSXXTvJbDAPhHLQUojjaNLomdm3cEJ1XTzMqUt3V")),
alg: 'ES256K-R'
}
const signedCredential = await credentials.issue(credential,{
issuer,
outputType: OutputType.JWT
} );
console.log(signedCredential);
//"ewogICJhbGciOiAiUlMyNTYiLAogICJraWQiOiAiMTMzNzQ3MTQxMjU1IiwKICAiaWF0IjogMCwKICAiaXNzIjogIkM9R0IsIEw9TG9uZG9uLCBPVT1OdWFwYXkgQVBJLCBPPU51YXBheSwgQ049eWJvcXlheTkycSIsCiAgImI2NCI6IGZhbHNlLAogICJjcml0IjogWwogICAgImlhdCIsCiAgICAiaXNzIiwKICAgICJiNjQiCiAgXQp9..d_cZ46lwNiaFHAu_saC-Zz4rSzNbevWirO94EmBlbOwkB1L78vGbAnNjUsmFSU7t_HhL-cyMiQUDyRWswsEnlDljJsRi8s8ft48ipy2SMuZrjPpyYYMgink8nZZK7l-eFJcTiS9ZWezAAXF_IJFXSTO5ax9z6xty3zTNPNMV9W7aH8fEAvbUIiueOhH5xNHcsuqlOGygKdFz2rbjTGffoE_6zS4Dry-uX5mts2duLorobUimGsdlUcSM6P6vZEtcXaJCdjrT9tuFMh4CkX9nqk19Bq2z3i-SX4JCPvhD2r3ghRmX0gG08UcvyFVbrnVZJnpl4MU8V4Nr3-2M5URZOg"
//
const verifiedCreedential = await credentials.verify(signedCredential);
console.log(verifiedCreedential);
// verifiedCreedential true
const vcJwt = await issue(vc, {
issuer
});
const isVerified = await verify(vcJwt);
```
# Development and Testing
## Development
## Install dependencies
- clone ``https://github.com/Tonomy-Foundation/did-jwt.git`` into the parent directory of this repo and run ``npm install``
- clone ``https://github.com/Tonomy-Foundation/did-jwt-vc.git`` into the parent directory of this repo and run ``npm install``
## Run
TSDX scaffolds your new library inside `/src`.

@@ -73,80 +67,7 @@

## Configuration
## Publish
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
### Jest
Jest tests are set up to run with `npm test` or `yarn test`.
### Bundle Analysis
[`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library with `npm run size` and visualize the bundle with `npm run analyze`.
#### Setup Files
This is the folder structure we set up for you:
```txt
/src
index.tsx # EDIT THIS
/test
blah.test.tsx # EDIT THIS
.gitignore
package.json
README.md # EDIT THIS
tsconfig.json
```bash
npm run build
npm publish
```
### Rollup
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
### TypeScript
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
## Continuous Integration
### GitHub Actions
Two actions are added by default:
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
## Optimizations
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
```js
// ./types/index.d.ts
declare var __DEV__: boolean;
// inside your code...
if (__DEV__) {
console.log('foo');
}
```
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
## Module Formats
CJS, ESModules, and UMD module formats are supported.
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
## Named Exports
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
## Including Styles
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
## Publishing to NPM
We recommend using [np](https://github.com/sindresorhus/np).
import { CredentialOptions, OutputType } from './credentials.types';
import { createVerifiableCredentialJwt, verifyCredential, W3CCredential } from '@tonomy/did-jwt-vc';
import { PrivateKey, KeyType, PublicKey } from '@greymass/eosio';
import { ES256KSigner, ES256Signer } from '@tonomy/did-jwt'
import { getResolver } from '@tonomy/antelope-did-resolver';
import { PrivateKey, KeyType } from '@greymass/eosio';
import { ES256KSigner, ES256Signer, Signer } from '@tonomy/did-jwt'
import { JWT } from '@tonomy/did-jwt-vc/lib/types';
import { Resolver } from '@tonomy/did-resolver'
export function createSigner(privateKey: PrivateKey) {
/* Creates a signer from a private key that can be used to sign a JWT
*
* @param privateKey the private key to use to sign the JWT
* @returns a signer (function) that can be used to sign a JWT
*/
export function createSigner(privateKey: PrivateKey): Signer {
if (privateKey.type === KeyType.K1) {

@@ -17,17 +24,8 @@ return ES256KSigner(privateKey.data.array, true);

export function keyToJwsAlgo(publicKey: PublicKey): string {
if (publicKey.type === KeyType.K1) {
return 'ES256K';
}
if (publicKey.type === KeyType.R1) {
return 'ES256R';
}
throw new Error('Unsupported key type');
}
/**
* Issues a verifiable credential
* @param credential the verfiable credential to issue
*
* @param credential the verifiable credential to issue
* @param credentialOptions the options to issue the credential with
* @returns the issued credential signed by one or more issuers
* @returns the issued jwt credential signed by one or more issuers
*/

@@ -39,14 +37,18 @@ export async function issue(credential: W3CCredential, credentialOptions: CredentialOptions): Promise<JWT> {

// TODO return the full version as well?
// TODO return the full W3C version as well?
return await createVerifiableCredentialJwt(credential, credentialOptions.issuer, { canonicalize: true });
}
// TODO asynchroneously add signatures to the credential
// export async function addSignature(credential: VerifiableCredential, credentialOptions: CredentialOptions, options?: EosioOptions): Promise<CredentialSigned> {
// throw Error("Not implemented");
// }
/**
* Verifies a credential signed by a did:antelope or did:eosio issuer
* For a more complete verification result, use the verifyCredential function from @tonomy/did-jwt-vc
*
* @param credential the signed jwt verifiable credential to verify
* @param credentialOptions the options to verify the credential with
*
* @returns true if the signature matches the issuer
*/
export async function verify(verifiableCredential: JWT, options?: CredentialOptions): Promise<boolean> {
// return false
return !! await verifyCredential(verifiableCredential, {} as any, options);
const resolver = new Resolver(getResolver());
return !! await verifyCredential(verifiableCredential, resolver, options);
}
import { issue , verify} from './credentials';
export { issue , verify };
export * from './credentials';
export * from './credentials.types';

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