Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

did-veres-one

Package Overview
Dependencies
Maintainers
6
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

did-veres-one - npm Package Compare versions

Comparing version 9.0.0 to 9.1.0

8

CHANGELOG.md
# did-veres-one ChangeLog
## 9.1.0 - 2019-12-05
### Added
- Implemented `rotateKey()`
### Changed
- Fixed setting of controllers for newly generated did doc keys.
## 9.0.0 - 2019-11-20

@@ -4,0 +12,0 @@

4

lib/constants.js

@@ -24,4 +24,6 @@ /*!

capabilityInvocation: 'capabilityInvocation',
assertionMethod: 'assertionMethod'
assertionMethod: 'assertionMethod',
keyAgreement: 'keyAgreement',
contractAgreement: 'contractAgreement'
}
};

@@ -94,2 +94,16 @@ /*!

// Generate a capabilityInvocation key pair
if(!invokeKey) {
invokeKey = await LDKeyPair.generate(keyOptions);
}
// Use the generated capabilityInvocation key to base the DID URI on
const did = this.generateId({keyPair: invokeKey, didType, mode});
this.doc.id = did;
// Assign the DID as a default controller for the keys
keyOptions.controller = did;
// Now that we have a DID, generate the other keys
// Generate an authentication key pair

@@ -100,7 +114,2 @@ if(!authKey) {

// Generate a capabilityInvocation key pair
if(!invokeKey) {
invokeKey = await LDKeyPair.generate(keyOptions);
}
// Generate a capabilityDelegation key pair

@@ -116,13 +125,11 @@ if(!delegateKey) {

// Use the generated capabilityInvocation key to base the DID URI on
const did = this.generateId({keyPair: invokeKey, didType, mode});
this.doc.id = did;
for(const keyPair of [authKey, invokeKey, delegateKey, assertionKey]) {
keyPair.controller = did;
if(!keyPair.id) {
keyPair.id = this.generateKeyId({did, keyPair});
}
}
// Assign the DID as the controller for the keys
invokeKey.controller = did;
keyOptions.controller = did;
// Generate an authentication proof purpose node
authKey.id = this.generateKeyId({did, keyPair: authKey});
this.doc[constants.PROOF_PURPOSES.authentication] =
this.doc[constants.PROOF_PURPOSES.authentication] =
[authKey.publicNode()];

@@ -132,3 +139,2 @@ this.keys[authKey.id] = authKey;

// Generate a capabilityInvocation proof purpose node
invokeKey.id = this.generateKeyId({did, keyPair: invokeKey});
this.doc[constants.PROOF_PURPOSES.capabilityInvocation] =

@@ -139,3 +145,2 @@ [invokeKey.publicNode()];

// Generate a capabilityDelegation proof purpose node
delegateKey.id = this.generateKeyId({did, keyPair: delegateKey});
this.doc[constants.PROOF_PURPOSES.capabilityDelegation] =

@@ -145,5 +150,3 @@ [delegateKey.publicNode()];

// Generate an assertionMethod purpose node
assertionKey.id = this.generateKeyId({did, keyPair: assertionKey});
this.doc[constants.PROOF_PURPOSES.assertionMethod] =

@@ -184,2 +187,4 @@ [assertionKey.publicNode()];

/**
* Returns all verification methods (keys) for a given proof purpose.
*
* @param proofPurpose {string} proof purpose identifier

@@ -224,2 +229,54 @@ * @returns {object|undefined}

/**
* Alias for `findVerificationMethod()`.
* Example:
* ```
* findKey({id: 'did:ex:123#abcd'})
* // ->
* // {proofPurpose: 'authentication', key: { ... }}
* ```
* @returns {{proofPurpose: string, key: object}}
*/
findKey({id}) {
const {proofPurpose, method: key} = this.findVerificationMethod({id});
return {proofPurpose, key};
}
/**
* Finds a verification method for a given id, and returns it along with the
* proof purpose in which it resides. (Note that if a key is included in
* multiple proof purpose sections, the first occurrence is returned.)
*
* Useful for operations like rotate, since you need to know which proof
* purpose section to add a new key to (after removing the old one).
*
* Example:
* ```
* findVerificationMethod({id: 'did:ex:123#abcd'})
* // ->
* // {proofPurpose: 'authentication', method: { ... }}
* ```
*
* @param {string} id - Verification method id.
* @returns {{proofPurpose: string, method: object}}
*/
findVerificationMethod({id}) {
if(!id) {
throw new Error('Method id is required.');
}
for(const proofPurpose in constants.PROOF_PURPOSES) {
let method;
try {
method = this.getVerificationMethod({proofPurpose, methodId: id});
if(method) {
return {proofPurpose, method};
}
} catch(error) {
// Method not found for that purpose, continue searching
}
}
return {};
}
/**
* Creates a cryptonym DID from a given key pair.

@@ -349,2 +406,6 @@ *

const methods = this.getAllVerificationMethods(proofPurpose);
if(!methods) {
// This DID document does not contain any methods for this purpose
continue;
}
for(const method of methods) {

@@ -557,3 +618,3 @@ // TODO: support methods that are not LDKeyPairs

for(const proofPurposeType of Object.values(constants.PROOF_PURPOSES)) {
if (this.doc[proofPurposeType]) {
if(this.doc[proofPurposeType]) {
this.doc[proofPurposeType] = this.doc[proofPurposeType]

@@ -568,2 +629,38 @@ .filter(k => k.id !== key.id);

/**
* Rotates a key in this did document (removes the old one, and generates and
* adds a new one to the same proof purpose section). Key id is not re-used.
*
* One of the following is required:
* @param {LDKeyPair} [key] - Key object (with an .id)
* @param {string} [id] - Key id
*
* @param {string} [passphrase] - Optional passphrase to encrypt the new key.
*
* @returns {Promise<LDKeyPair>} Returns new key (after removing the old one)
*/
async rotateKey({key, id, passphrase}) {
if(!key && !id) {
throw new Error('A key id or key object is required to rotate.');
}
const keyId = id || key.id;
const {proofPurpose, key: oldKey} = this.findKey({id: keyId});
if(!oldKey) {
throw new Error(`Key ${keyId} is not found in did document.`);
}
const keyType = oldKey.type;
const controller = oldKey.controller;
// First, remove the old key
this.removeKey({id: keyId});
// Generate an add a new key to the same proof purpose (key id not re-used)
const newKey = await LDKeyPair.generate({type: keyType, passphrase});
newKey.id = this.generateKeyId({id: this.id, keyPair: newKey});
newKey.controller = controller;
this.addKey({key: newKey, proofPurpose, controller});
return newKey;
}
async exportKeys() {

@@ -570,0 +667,0 @@ const exportedKeys = {};

{
"name": "did-veres-one",
"version": "9.0.0",
"version": "9.1.0",
"description": "A Decentralized Identifier utility library for Veres One",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc