@transmute/did-key-common
Advanced tools
Comparing version 0.2.1-unstable.28 to 0.2.1-unstable.29
@@ -6,2 +6,10 @@ # Change Log | ||
## 0.2.1-unstable.29 (2020-12-13) | ||
**Note:** Version bump only for package @transmute/did-key-common | ||
## 0.2.1-unstable.28 (2020-11-17) | ||
@@ -8,0 +16,0 @@ |
@@ -101,3 +101,5 @@ 'use strict'; | ||
var getVerificationMethod = function getVerificationMethod(didKeyPairInstance, contentType) { | ||
var cbor = /*#__PURE__*/require('borc'); | ||
var getVerificationMethod = function getVerificationMethod(instance, contentType) { | ||
if (contentType === void 0) { | ||
@@ -107,26 +109,22 @@ contentType = 'application/did+ld+json'; | ||
var externalKeyRepresentation; | ||
switch (contentType) { | ||
case 'application/did+json': | ||
{ | ||
externalKeyRepresentation = didKeyPairInstance.toJsonWebKeyPair(); | ||
break; | ||
return instance.toJsonWebKeyPair(); | ||
} | ||
case '*/*': | ||
case 'application/did+ld+json': | ||
case 'application/did+cbor': | ||
{ | ||
externalKeyRepresentation = didKeyPairInstance.toKeyPair(); | ||
break; | ||
return instance.toJsonWebKeyPair(); | ||
} | ||
default: | ||
case 'application/did+ld+json': | ||
{ | ||
throw new Error('This implementation of did:key does not support: ' + contentType); | ||
return instance.toKeyPair(); | ||
} | ||
} | ||
return externalKeyRepresentation; | ||
throw new Error('This implementation of did:key does not support: ' + contentType); | ||
}; | ||
var supportedContentTypes = ['application/did+json', 'application/did+ld+json', 'application/did+cbor']; | ||
var keyToDidDoc = function keyToDidDoc(didKeyPairInstance, contentType) { | ||
@@ -139,13 +137,2 @@ if (contentType === void 0) { | ||
var _temp3 = function _temp3() { | ||
// imagine if people injected ads like this.... | ||
// verificationRelationships = { | ||
// ...verificationRelationships, | ||
// service: [ | ||
// { | ||
// id: '#provider', | ||
// type: 'ServiceProvider', | ||
// serviceEndpoint: 'https://transmute.industries', | ||
// }, | ||
// ], | ||
// }; | ||
var didDocument = _extends({ | ||
@@ -156,9 +143,11 @@ '@context': ['https://www.w3.org/ns/did/v1', { | ||
id: did | ||
}, verificationRelationships); // Here is were I would delete a property for JSON-only | ||
// If I wanted to conform to the DID Core JSON Production Rules. | ||
}, verificationRelationships); | ||
return didDocument; | ||
}; | ||
if (supportedContentTypes.indexOf(contentType) === -1) { | ||
throw new Error('Unsupported DID Document representation. ' + contentType); | ||
} | ||
var did = "did:key:" + didKeyPairInstance.fingerprint(); | ||
@@ -217,5 +206,5 @@ var externalKeyRepresentation = getVerificationMethod(didKeyPairInstance, contentType); | ||
})).then(function (publicKey) { | ||
return Promise.resolve(keyToDidDoc(publicKey, resolutionMetaData.accept)).then(function (_keyToDidDoc) { | ||
return { | ||
didDocument: _keyToDidDoc, | ||
return Promise.resolve(keyToDidDoc(publicKey, resolutionMetaData.accept)).then(function (didDocument) { | ||
var didResolutionResponse = { | ||
didDocument: didDocument, | ||
didDocumentMetaData: { | ||
@@ -226,2 +215,3 @@ 'content-type': resolutionMetaData.accept | ||
}; | ||
return resolutionMetaData.accept === 'application/did+cbor' ? cbor.encode(didResolutionResponse) : didResolutionResponse; | ||
}); | ||
@@ -228,0 +218,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("base64url")),t=e(require("canonicalize"));function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var i=function(e,r){var t;switch(void 0===r&&(r="application/did+ld+json"),r){case"application/did+json":t=e.toJsonWebKeyPair();break;case"*/*":case"application/did+ld+json":t=e.toKeyPair();break;default:throw new Error("This implementation of did:key does not support: "+r)}return t},o=function(e,r){void 0===r&&(r="application/did+ld+json");try{var t=function(){return n({"@context":["https://www.w3.org/ns/did/v1",{"@base":o}],id:o},u)},o="did:key:"+e.fingerprint(),c=i(e,r),u={verificationMethod:[c]};e.verifier&&(u=n({},u,{authentication:[c.id],assertionMethod:[c.id],capabilityInvocation:[c.id],capabilityDelegation:[c.id]})),e.deriveSecret&&(u=n({},u,{keyAgreement:[c.id]}));var a=function(){if("Ed25519VerificationKey2018"===e.type)return Promise.resolve(e.toX25519KeyPair(!1)).then((function(e){var t=i(e,r);u=n({},u,{verificationMethod:[].concat(u.verificationMethod,[t]),keyAgreement:[t.id]})}))}();return Promise.resolve(a&&a.then?a.then(t):t())}catch(e){return Promise.reject(e)}};exports.Jws={__proto__:null,createJws:function(e,n,i){try{var o=r.encode(t(i))+"."+r.encode(t(n));return Promise.resolve(e.sign(Buffer.from(o))).then((function(e){return o+"."+r.encode(Buffer.from(e))}))}catch(e){return Promise.reject(e)}},verifyJws:function(e,t){try{var n=t.split("."),i=n[2];return Promise.resolve(e.verify(Buffer.from(n[0]+"."+n[1]),r.toBuffer(i)))}catch(e){return Promise.reject(e)}},createDetachedJws:function(e,i,o){try{var c=r.encode(t(n({},o,{b64:!1,crit:["b64"]}))),u=new Uint8Array(Buffer.concat([Buffer.from(c,"utf-8"),Buffer.from(".","utf-8"),i]));return Promise.resolve(e.sign(Buffer.from(u))).then((function(e){var t=r.encode(Buffer.from(e));return c+".."+t}))}catch(e){return Promise.reject(e)}},verifyDetachedJws:function(e,t,n){try{var i=n.split(".."),o=i[1],c=new Uint8Array(Buffer.concat([Buffer.from(i[0],"utf-8"),Buffer.from(".","utf-8"),t]));return Promise.resolve(e.verify(Buffer.from(c),r.toBuffer(o)))}catch(e){return Promise.reject(e)}}},exports.getGet=function(e){return function(r){var t=void 0===r?{}:r,n=t.did,i=t.url;try{if(!(n=n||i))throw new TypeError('"did" must be a string.');return Promise.resolve(e(n)).then((function(e){return e.didDocument}))}catch(e){return Promise.reject(e)}}},exports.getResolve=function(e){return function(r,t){void 0===t&&(t={accept:"application/did+ld+json"});try{var n=r.split("#")[0].split("did:key:").pop();return Promise.resolve(e.fromFingerprint({fingerprint:n})).then((function(e){return Promise.resolve(o(e,t.accept)).then((function(e){return{didDocument:e,didDocumentMetaData:{"content-type":t.accept},didResolutionMetaData:{}}}))}))}catch(e){return Promise.reject(e)}}},exports.getVerificationMethod=i,exports.keyToDidDoc=o,exports.types={__proto__:null,staticImplements:function(){return function(e){return e}}}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("base64url")),t=e(require("canonicalize"));function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var i={__proto__:null,createJws:function(e,n,i){try{var o=r.encode(t(i))+"."+r.encode(t(n));return Promise.resolve(e.sign(Buffer.from(o))).then((function(e){return o+"."+r.encode(Buffer.from(e))}))}catch(e){return Promise.reject(e)}},verifyJws:function(e,t){try{var n=t.split("."),i=n[2];return Promise.resolve(e.verify(Buffer.from(n[0]+"."+n[1]),r.toBuffer(i)))}catch(e){return Promise.reject(e)}},createDetachedJws:function(e,i,o){try{var c=r.encode(t(n({},o,{b64:!1,crit:["b64"]}))),a=new Uint8Array(Buffer.concat([Buffer.from(c,"utf-8"),Buffer.from(".","utf-8"),i]));return Promise.resolve(e.sign(Buffer.from(a))).then((function(e){var t=r.encode(Buffer.from(e));return c+".."+t}))}catch(e){return Promise.reject(e)}},verifyDetachedJws:function(e,t,n){try{var i=n.split(".."),o=i[1],c=new Uint8Array(Buffer.concat([Buffer.from(i[0],"utf-8"),Buffer.from(".","utf-8"),t]));return Promise.resolve(e.verify(Buffer.from(c),r.toBuffer(o)))}catch(e){return Promise.reject(e)}}},o=require("borc"),c=function(e,r){switch(void 0===r&&(r="application/did+ld+json"),r){case"application/did+json":case"application/did+cbor":return e.toJsonWebKeyPair();case"application/did+ld+json":return e.toKeyPair()}throw new Error("This implementation of did:key does not support: "+r)},a=["application/did+json","application/did+ld+json","application/did+cbor"],u=function(e,r){void 0===r&&(r="application/did+ld+json");try{var t=function(){return n({"@context":["https://www.w3.org/ns/did/v1",{"@base":i}],id:i},u)};if(-1===a.indexOf(r))throw new Error("Unsupported DID Document representation. "+r);var i="did:key:"+e.fingerprint(),o=c(e,r),u={verificationMethod:[o]};e.verifier&&(u=n({},u,{authentication:[o.id],assertionMethod:[o.id],capabilityInvocation:[o.id],capabilityDelegation:[o.id]})),e.deriveSecret&&(u=n({},u,{keyAgreement:[o.id]}));var f=function(){if("Ed25519VerificationKey2018"===e.type)return Promise.resolve(e.toX25519KeyPair(!1)).then((function(e){var t=c(e,r);u=n({},u,{verificationMethod:[].concat(u.verificationMethod,[t]),keyAgreement:[t.id]})}))}();return Promise.resolve(f&&f.then?f.then(t):t())}catch(e){return Promise.reject(e)}};exports.Jws=i,exports.getGet=function(e){return function(r){var t=void 0===r?{}:r,n=t.did,i=t.url;try{if(!(n=n||i))throw new TypeError('"did" must be a string.');return Promise.resolve(e(n)).then((function(e){return e.didDocument}))}catch(e){return Promise.reject(e)}}},exports.getResolve=function(e){return function(r,t){void 0===t&&(t={accept:"application/did+ld+json"});try{var n=r.split("#")[0].split("did:key:").pop();return Promise.resolve(e.fromFingerprint({fingerprint:n})).then((function(e){return Promise.resolve(u(e,t.accept)).then((function(e){var r={didDocument:e,didDocumentMetaData:{"content-type":t.accept},didResolutionMetaData:{}};return"application/did+cbor"===t.accept?o.encode(r):r}))}))}catch(e){return Promise.reject(e)}}},exports.getVerificationMethod=c,exports.keyToDidDoc=u,exports.types={__proto__:null,staticImplements:function(){return function(e){return e}}}; | ||
//# sourceMappingURL=did-key-common.cjs.production.min.js.map |
@@ -95,3 +95,5 @@ import base64url from 'base64url'; | ||
var getVerificationMethod = function getVerificationMethod(didKeyPairInstance, contentType) { | ||
var cbor = /*#__PURE__*/require('borc'); | ||
var getVerificationMethod = function getVerificationMethod(instance, contentType) { | ||
if (contentType === void 0) { | ||
@@ -101,26 +103,22 @@ contentType = 'application/did+ld+json'; | ||
var externalKeyRepresentation; | ||
switch (contentType) { | ||
case 'application/did+json': | ||
{ | ||
externalKeyRepresentation = didKeyPairInstance.toJsonWebKeyPair(); | ||
break; | ||
return instance.toJsonWebKeyPair(); | ||
} | ||
case '*/*': | ||
case 'application/did+ld+json': | ||
case 'application/did+cbor': | ||
{ | ||
externalKeyRepresentation = didKeyPairInstance.toKeyPair(); | ||
break; | ||
return instance.toJsonWebKeyPair(); | ||
} | ||
default: | ||
case 'application/did+ld+json': | ||
{ | ||
throw new Error('This implementation of did:key does not support: ' + contentType); | ||
return instance.toKeyPair(); | ||
} | ||
} | ||
return externalKeyRepresentation; | ||
throw new Error('This implementation of did:key does not support: ' + contentType); | ||
}; | ||
var supportedContentTypes = ['application/did+json', 'application/did+ld+json', 'application/did+cbor']; | ||
var keyToDidDoc = function keyToDidDoc(didKeyPairInstance, contentType) { | ||
@@ -133,13 +131,2 @@ if (contentType === void 0) { | ||
var _temp3 = function _temp3() { | ||
// imagine if people injected ads like this.... | ||
// verificationRelationships = { | ||
// ...verificationRelationships, | ||
// service: [ | ||
// { | ||
// id: '#provider', | ||
// type: 'ServiceProvider', | ||
// serviceEndpoint: 'https://transmute.industries', | ||
// }, | ||
// ], | ||
// }; | ||
var didDocument = _extends({ | ||
@@ -150,9 +137,11 @@ '@context': ['https://www.w3.org/ns/did/v1', { | ||
id: did | ||
}, verificationRelationships); // Here is were I would delete a property for JSON-only | ||
// If I wanted to conform to the DID Core JSON Production Rules. | ||
}, verificationRelationships); | ||
return didDocument; | ||
}; | ||
if (supportedContentTypes.indexOf(contentType) === -1) { | ||
throw new Error('Unsupported DID Document representation. ' + contentType); | ||
} | ||
var did = "did:key:" + didKeyPairInstance.fingerprint(); | ||
@@ -211,5 +200,5 @@ var externalKeyRepresentation = getVerificationMethod(didKeyPairInstance, contentType); | ||
})).then(function (publicKey) { | ||
return Promise.resolve(keyToDidDoc(publicKey, resolutionMetaData.accept)).then(function (_keyToDidDoc) { | ||
return { | ||
didDocument: _keyToDidDoc, | ||
return Promise.resolve(keyToDidDoc(publicKey, resolutionMetaData.accept)).then(function (didDocument) { | ||
var didResolutionResponse = { | ||
didDocument: didDocument, | ||
didDocumentMetaData: { | ||
@@ -220,2 +209,3 @@ 'content-type': resolutionMetaData.accept | ||
}; | ||
return resolutionMetaData.accept === 'application/did+cbor' ? cbor.encode(didResolutionResponse) : didResolutionResponse; | ||
}); | ||
@@ -222,0 +212,0 @@ }); |
@@ -1,9 +0,3 @@ | ||
export declare const getVerificationMethod: (didKeyPairInstance: any, contentType?: string) => any; | ||
export declare const getVerificationMethod: (instance: any, contentType?: string) => any; | ||
export declare const keyToDidDoc: (didKeyPairInstance: any, contentType?: string) => Promise<any>; | ||
export declare const getResolve: (DidKeyPairClass: any) => (didUri: string, resolutionMetaData?: any) => Promise<{ | ||
didDocument: any; | ||
didDocumentMetaData: { | ||
'content-type': any; | ||
}; | ||
didResolutionMetaData: {}; | ||
}>; | ||
export declare const getResolve: (DidKeyPairClass: any) => (didUri: string, resolutionMetaData?: any) => Promise<any>; |
@@ -5,3 +5,3 @@ { | ||
"module": "dist/did-key-common.esm.js", | ||
"version": "0.2.1-unstable.28", | ||
"version": "0.2.1-unstable.29", | ||
"license": "Apache-2.0", | ||
@@ -34,5 +34,7 @@ "main": "dist/index.js", | ||
"base64url": "^3.0.1", | ||
"canonicalize": "^1.0.3" | ||
"borc": "^2.1.2", | ||
"canonicalize": "^1.0.3", | ||
"cbor": "^5.1.0" | ||
}, | ||
"gitHead": "4487e255b79b5caa60603c7b693eb9d5fe0264ec" | ||
"gitHead": "82574492449fedec9b4a54fa1b53ba4dfa2f467b" | ||
} |
@@ -0,25 +1,29 @@ | ||
const cbor = require('borc'); | ||
export const getVerificationMethod = ( | ||
didKeyPairInstance: any, | ||
instance: any, | ||
contentType: string = 'application/did+ld+json' | ||
) => { | ||
let externalKeyRepresentation; | ||
switch (contentType) { | ||
case 'application/did+json': { | ||
externalKeyRepresentation = didKeyPairInstance.toJsonWebKeyPair(); | ||
break; | ||
return instance.toJsonWebKeyPair(); | ||
} | ||
case '*/*': | ||
case 'application/did+cbor': { | ||
return instance.toJsonWebKeyPair(); | ||
} | ||
case 'application/did+ld+json': { | ||
externalKeyRepresentation = didKeyPairInstance.toKeyPair(); | ||
break; | ||
return instance.toKeyPair(); | ||
} | ||
default: { | ||
throw new Error( | ||
'This implementation of did:key does not support: ' + contentType | ||
); | ||
} | ||
} | ||
return externalKeyRepresentation; | ||
throw new Error( | ||
'This implementation of did:key does not support: ' + contentType | ||
); | ||
}; | ||
const supportedContentTypes = [ | ||
'application/did+json', | ||
'application/did+ld+json', | ||
'application/did+cbor', | ||
]; | ||
export const keyToDidDoc = async ( | ||
@@ -29,2 +33,5 @@ didKeyPairInstance: any, | ||
) => { | ||
if (supportedContentTypes.indexOf(contentType) === -1) { | ||
throw new Error('Unsupported DID Document representation. ' + contentType); | ||
} | ||
const did = `did:key:${didKeyPairInstance.fingerprint()}`; | ||
@@ -68,15 +75,2 @@ const externalKeyRepresentation = getVerificationMethod( | ||
} | ||
// imagine if people injected ads like this.... | ||
// verificationRelationships = { | ||
// ...verificationRelationships, | ||
// service: [ | ||
// { | ||
// id: '#provider', | ||
// type: 'ServiceProvider', | ||
// serviceEndpoint: 'https://transmute.industries', | ||
// }, | ||
// ], | ||
// }; | ||
const didDocument = { | ||
@@ -93,4 +87,2 @@ '@context': [ | ||
// Here is were I would delete a property for JSON-only | ||
// If I wanted to conform to the DID Core JSON Production Rules. | ||
return didDocument; | ||
@@ -111,4 +103,6 @@ }; | ||
const publicKey = await DidKeyPairClass.fromFingerprint({ fingerprint }); | ||
return { | ||
didDocument: await keyToDidDoc(publicKey, resolutionMetaData.accept), | ||
const didDocument = await keyToDidDoc(publicKey, resolutionMetaData.accept); | ||
const didResolutionResponse = { | ||
didDocument, | ||
didDocumentMetaData: { | ||
@@ -119,4 +113,8 @@ 'content-type': resolutionMetaData.accept, | ||
}; | ||
if (resolutionMetaData.accept === 'application/did+cbor') { | ||
return cbor.encode(didResolutionResponse); | ||
} | ||
return didResolutionResponse; | ||
}; | ||
return resolve; | ||
}; |
declare module 'canonicalize'; | ||
declare module 'cbor'; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81168
4
853
+ Addedborc@^2.1.2
+ Addedcbor@^5.1.0
+ Addedbase64-js@1.5.1(transitive)
+ Addedbignumber.js@9.1.2(transitive)
+ Addedborc@2.1.2(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedcbor@5.2.0(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addeddelimit-stream@0.1.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addediso-url@0.4.7(transitive)
+ Addedjson-text-sequence@0.1.1(transitive)
+ Addednofilter@1.0.4(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)