did-veres-one
Advanced tools
Comparing version
# did-veres-one ChangeLog | ||
## 12.1.1 - 2020-04-29 | ||
### Added | ||
- Implement fetching of keys from un-registered cryptonym DIDs. | ||
## 12.1.0 - 2020-04-13 | ||
@@ -4,0 +9,0 @@ |
@@ -143,2 +143,4 @@ /*! | ||
* @param [keys] {object} Hashmap of keys by key id, to import into DID Doc. | ||
* @param forceConstruct {boolean} Forces deterministic construction of | ||
* DID Document from cryptonym. | ||
* @param [autoObserve=false] {boolean} Start tracking changes to the DID Doc | ||
@@ -151,15 +153,5 @@ * (to generate a diff patch later). | ||
*/ | ||
async get({did, keys, autoObserve = false}) { | ||
async get({did, keys, forceConstruct = false, autoObserve = false}) { | ||
// fetch DID Document from ledger | ||
let result; | ||
try { | ||
result = await this.client.get({did}); | ||
} catch(error) { | ||
if(error.name === 'NotFoundError' && | ||
(did.startsWith('did:v1:nym:') || did.startsWith('did:v1:test:nym:'))) { | ||
result = await VeresOneDidDoc.fromNym({did}); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
const result = await this.client.get({did, forceConstruct}); | ||
@@ -166,0 +158,0 @@ const didDoc = new VeresOneDidDoc(result); |
@@ -12,2 +12,3 @@ /*! | ||
const VeresOneClientError = require('./VeresOneClientError'); | ||
const VeresOneDidDoc = require('./VeresOneDidDoc'); | ||
jsonld.documentLoader = require('./documentLoader'); | ||
@@ -48,6 +49,8 @@ | ||
* @param did {string} DID uri (possibly with hash fragment) | ||
* @param forceConstruct {boolean} Forces deterministic construction of | ||
* DID Document from cryptonym. | ||
* | ||
* @returns {Promise<object>} Resolves to DID Document Fetch Result | ||
*/ | ||
async get({did}) { | ||
async get({did, forceConstruct = false}) { | ||
if(!did) { | ||
@@ -57,7 +60,23 @@ throw new Error('Invalid or missing DID URI.'); | ||
const [docUri, hashFragment] = did.split('#'); | ||
const isNym = (did.startsWith('did:v1:nym:') || | ||
did.startsWith('did:v1:test:nym:')); | ||
let result = {}; | ||
let didDoc; | ||
const result = await this.ledger.getRecord({id: docUri}); | ||
// FIXME - remove, replace with cache | ||
if(isNym && forceConstruct) { | ||
didDoc = (await VeresOneDidDoc.fromNym({did: docUri})).doc; | ||
} else { | ||
try { | ||
result = await this.ledger.getRecord({id: docUri}); | ||
didDoc = result.record; | ||
} catch(error) { | ||
if(error.name === 'NotFoundError' && isNym) { | ||
didDoc = (await VeresOneDidDoc.fromNym({did: docUri})).doc; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
const didDoc = result.record; | ||
const context = didDoc['@context']; | ||
@@ -74,5 +93,7 @@ | ||
if(!subGraph) { | ||
throw new Error( | ||
const error = new Error( | ||
`Failed to get subgraph within a DID Document, uri: "${did}".` | ||
); | ||
error.name = 'NotFoundError'; | ||
throw error; | ||
} | ||
@@ -79,0 +100,0 @@ |
{ | ||
"name": "did-veres-one", | ||
"version": "12.1.0", | ||
"version": "12.1.1", | ||
"description": "A Decentralized Identifier utility library for Veres One", | ||
@@ -35,3 +35,3 @@ "main": "lib/index.js", | ||
"json-ld-patch-context": "^4.0.0", | ||
"jsonld": "^3.0.1", | ||
"jsonld": "^3.1.0", | ||
"jsonld-signatures": "^5.0.1", | ||
@@ -38,0 +38,0 @@ "ocapld": "^2.0.0", |
59680
1.25%1259
1.12%Updated