-
Notifications
You must be signed in to change notification settings - Fork 11
/
flow-with-did-ethr.ts
81 lines (68 loc) · 3.25 KB
/
flow-with-did-ethr.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Copyright (c) 2024 DSR Corporation, Denver, Colorado.
* https://www.dsr-corporation.com
* SPDX-License-Identifier: Apache-2.0
*/
import environment from '../environment'
import { Actor } from './utils/actor'
import { ROLES } from '../contracts-ts'
import { createCredentialDefinitionObject, createSchemaObject } from '../utils'
async function demo() {
let receipt: any
const trustee = await new Actor(environment.accounts.account1).init()
const faber = await new Actor().init()
const alice = await new Actor().init()
const unauthorized = await new Actor().init()
console.log('1. Trustee assign ENDORSER role to Faber')
receipt = await trustee.roleControl.assignRole(ROLES.ENDORSER, faber.address)
console.log(`Role ${ROLES.ENDORSER} assigned to account ${faber.address}. Receipt: ${JSON.stringify(receipt)}`)
console.log('2. Faber sets service attribute to DID document (Optional)')
receipt = await faber.ethereumDIDRegistry.setAttribute(
faber.address,
'did/svc/did-communication',
'https://example.com',
86400,
)
console.log(`Attribute created for id ${faber.address}. Receipt: ${JSON.stringify(receipt)}`)
console.log("3. Faber creates a Test Schema using the 'did:ethr' DID as the issuer")
const { id: schemaId, schema } = createSchemaObject({ issuerId: faber.didEthr })
receipt = await faber.schemaRegistry.createSchema(faber.address, schemaId, faber.didEthr, schema)
console.log(`Schema created for id ${schemaId}. Receipt: ${JSON.stringify(receipt)}`)
console.log('4. Faber resolves Test Schema to ensure its written')
const resolvedSchema = await faber.schemaRegistry.resolveSchema(schemaId)
console.log(`Schema resolved for ${schemaId}. Schema: ${resolvedSchema.schema}`)
console.log("5. Faber create a Test Credential Definition using the 'did:ethr' DID as the issuer")
const { id: credentialDefinitionId, credDef: credentialDefinition } = createCredentialDefinitionObject({
issuerId: faber.didEthr,
schemaId: schemaId,
})
receipt = await faber.credentialDefinitionRegistry.createCredentialDefinition(
faber.address,
credentialDefinitionId,
faber.didEthr,
schemaId,
credentialDefinition,
)
console.log(`Credential Definition created for id ${credentialDefinitionId}. Receipt: ${JSON.stringify(receipt)}`)
console.log('6. Faber resolves Test Credential Definition to ensure its written')
const resolvedCredentialDefinition = await faber.credentialDefinitionRegistry.resolveCredentialDefinition(
credentialDefinitionId,
)
console.log(
`Credential Definition resolved for ${credentialDefinitionId}. Credential Definition: ${resolvedCredentialDefinition.credDef}`,
)
console.log('7. Alice resolves Test Schema')
const testSchema = await alice.schemaRegistry.resolveSchema(schemaId)
console.log(`Schema resolved for ${schemaId}. Schema: ${testSchema.schema}`)
console.log('8. Alice resolves Test Credential Definition')
const testCredentialDefinition = await alice.credentialDefinitionRegistry.resolveCredentialDefinition(
credentialDefinitionId,
)
console.log(
`Credential Definition resolved for ${credentialDefinitionId}. Credential Definition: ${testCredentialDefinition.credDef}`,
)
}
if (require.main === module) {
demo()
}
module.exports = exports = demo