forked from hashgraph/guardian
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hashgraph#2163 from hashgraph/feature/1498
upload and verify vc
- Loading branch information
Showing
23 changed files
with
1,268 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { DidRootKey, DocumentLoader, IDocumentFormat } from '../hedera-modules'; | ||
import { DataBaseHelper } from '../helpers'; | ||
import { DidDocument, DryRun } from '../entity'; | ||
|
||
/** | ||
* Dry Run loader | ||
*/ | ||
export class DryRunLoader extends DocumentLoader { | ||
/** | ||
* Has context | ||
* @param iri | ||
*/ | ||
public async has(iri: string): Promise<boolean> { | ||
const did = DidRootKey.create(iri).getController(); | ||
const document= await new DataBaseHelper(DryRun).findOne({did, dryRunClass: 'DidDocumentCollection'}); | ||
return !!document; | ||
} | ||
|
||
/** | ||
* Get formatted document | ||
* @param iri | ||
*/ | ||
public async get(iri: string): Promise<IDocumentFormat> { | ||
const did = DidRootKey.create(iri).getController(); | ||
const document= await new DataBaseHelper(DryRun).findOne({did, dryRunClass: 'DidDocumentCollection'}); | ||
return { | ||
documentUrl: iri, | ||
document: document.document | ||
}; | ||
} | ||
|
||
/** | ||
* Get document | ||
* @param iri | ||
*/ | ||
public async getDocument(iri: string): Promise<any> { | ||
const did = DidRootKey.create(iri).getController(); | ||
const didDocuments = await new DataBaseHelper(DidDocument).findOne({ did }); | ||
if (didDocuments) { | ||
return didDocuments.document; | ||
} | ||
throw new Error(`DID not found: ${iri}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { DidRootKey, DocumentLoader, IDocumentFormat } from '../hedera-modules'; | ||
import { DataBaseHelper, IPFS, Workers } from '../helpers'; | ||
import { DidDocument } from '../entity'; | ||
import { WorkerTaskType } from '@guardian/interfaces'; | ||
|
||
/** | ||
* Hedera loader | ||
*/ | ||
export class HederaLoader extends DocumentLoader { | ||
/** | ||
* Has context | ||
* @param iri | ||
*/ | ||
public async has(iri: string): Promise<boolean> { | ||
if (!iri.startsWith('did:hedera:')) { | ||
return false; | ||
} | ||
const document = await this.getDocument(iri); | ||
return !document; | ||
|
||
} | ||
|
||
/** | ||
* Get formatted document | ||
* @param iri | ||
*/ | ||
public async get(iri: string): Promise<IDocumentFormat> { | ||
const did = DidRootKey.create(iri).getController(); | ||
const splittedDid = did.split('_'); | ||
const topicId = splittedDid[splittedDid.length - 1]; | ||
|
||
const messages = await new Workers().addRetryableTask( | ||
{ | ||
type: WorkerTaskType.GET_TOPIC_MESSAGES, | ||
data: { | ||
operatorId: null, | ||
operatorKey: null, | ||
dryRun: false, | ||
topic: topicId, | ||
}, | ||
}, | ||
10 | ||
); | ||
const didMessage = messages | ||
.map(m => { | ||
try { | ||
return JSON.parse(m.message); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
}) | ||
.find(m => { | ||
return (m.type === 'DID-Document') && (m.did === did) | ||
}); | ||
if (!didMessage) { | ||
return null | ||
} | ||
const didDocument = await IPFS.getFile(didMessage.cid, 'json') | ||
|
||
return { | ||
documentUrl: iri, | ||
document: didDocument | ||
}; | ||
} | ||
|
||
/** | ||
* Get document | ||
* @param iri | ||
*/ | ||
public async getDocument(iri: string): Promise<any> { | ||
const did = DidRootKey.create(iri).getController(); | ||
const didDocuments = await new DataBaseHelper(DidDocument).findOne({ did }); | ||
if (didDocuments) { | ||
return didDocuments.document; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.