Skip to content

Commit

Permalink
Added usage of issuerDid in node agent functions
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Mircea <[email protected]>
  • Loading branch information
bobozaur committed Oct 4, 2023
1 parent 0dedeb2 commit 3a2d694
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 67 deletions.
12 changes: 6 additions & 6 deletions agents/node/vcxagent-core/demo/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { testTailsUrl, initRustLogger } = require('../src')

const tailsDir = '/tmp/tails'

async function runFaber (options) {
async function runFaber(options) {
logger.info(`Starting Faber. Revocation enabled=${options.revocation}`)
initRustLogger(process.env.RUST_LOG || 'vcx=error')

Expand Down Expand Up @@ -47,10 +47,10 @@ async function runFaber (options) {
await vcxAgent.acceptTaa()
}

const schemaId = await vcxAgent.serviceLedgerSchema.createSchema(getSampleSchemaData())
await sleep(500)
const vcxCredDef = await vcxAgent.serviceLedgerCredDef.createCredentialDefinitionV2(schemaId, getFaberCredDefName(), true, 'tag1')
const issuerDid = vcxAgent.getInstitutionDid()
const schemaId = await vcxAgent.serviceLedgerSchema.createSchema(getSampleSchemaData(), issuerDid)
await sleep(500)
const vcxCredDef = await vcxAgent.serviceLedgerCredDef.createCredentialDefinitionV2(issuerDid, schemaId, getFaberCredDefName(), true, 'tag1')
const { revReg, revRegId } = await vcxAgent.serviceLedgerRevReg.createRevocationRegistry(issuerDid, await vcxCredDef.getCredDefId(), 1, tailsDir, 5, testTailsUrl)

await vcxAgent.serviceConnections.inviterConnectionCreateAndAccept(connectionId, (invitationString) => {
Expand Down Expand Up @@ -87,7 +87,7 @@ async function runFaber (options) {
logger.info('Faber is revoking issued credential')
await vcxAgent.serviceCredIssuer.revokeCredentialLocal(issuerCredId)
logger.info('Faber is publishing revocation')
await revReg.publishRevocations()
await revReg.publishRevocations(issuerDid)
}

logger.info('#19 Create a Proof object')
Expand Down Expand Up @@ -193,7 +193,7 @@ const usage = [
}
]

function areOptionsValid (_options) {
function areOptionsValid(_options) {
return true
}

Expand Down
15 changes: 6 additions & 9 deletions agents/node/vcxagent-core/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const { createServiceLedgerRevocationRegistry } = require('./services/service-re
const { provisionAgentInAgency } = require('./utils/vcx-workflows')
const {
createAgencyClientForMainWallet,
initIssuerConfig,
openMainWallet,
openMainPool,
vcxUpdateWebhookUrl,
Expand All @@ -25,7 +24,7 @@ const { createStorageService } = require('./storage/storage-service')
const { waitUntilAgencyIsReady, getAgencyConfig } = require('./common')
const path = require('path')

async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, walletExtraConfigs, endpointInfo, logger }) {
async function createVcxAgent({ agentName, genesisPath, agencyUrl, seed, walletExtraConfigs, endpointInfo, logger }) {
genesisPath = genesisPath || path.join(__dirname, '/../resources/docker.txn')

await waitUntilAgencyIsReady(agencyUrl, logger)
Expand All @@ -39,12 +38,10 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, wallet
const agentProvision = await storageService.loadAgentProvision()
const issuerDid = agentProvision.issuerConfig.institution_did

async function agentInitVcx () {
async function agentInitVcx() {
logger.info(`Initializing ${agentName} vcx session.`)

logger.silly(`Using following agent provision to initialize VCX settings ${JSON.stringify(agentProvision, null, 2)}`)
logger.silly('Initializing issuer config')
await initIssuerConfig(agentProvision.issuerConfig)
logger.silly('Opening main wallet')
await openMainWallet(agentProvision.walletConfig)
logger.silly('Creating cloud agency config')
Expand All @@ -53,25 +50,25 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, wallet
await openMainPool({ genesis_path: genesisPath })
}

async function agentShutdownVcx () {
async function agentShutdownVcx() {
logger.debug(`Shutting down ${agentName} vcx session.`)
shutdownVcx()
}

async function updateWebhookUrl (webhookUrl) {
async function updateWebhookUrl(webhookUrl) {
logger.info(`Updating webhook url to ${webhookUrl}`)
await vcxUpdateWebhookUrl({ webhookUrl })
}

async function acceptTaa () {
async function acceptTaa() {
const taa = await getLedgerAuthorAgreement()
const taaJson = JSON.parse(taa)
const acceptanceMechanism = Object.keys(taaJson.aml)[0]
logger.info(`Accepting TAA using mechanism ${acceptanceMechanism}`)
await setActiveTxnAuthorAgreementMeta(taaJson.text, taaJson.version, acceptanceMechanism)
}

function getInstitutionDid () {
function getInstitutionDid() {
return issuerDid
}

Expand Down
11 changes: 6 additions & 5 deletions agents/node/vcxagent-core/src/services/service-ledger-creddef.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { CredentialDef } = require('@hyperledger/node-vcx-wrapper')

module.exports.createServiceLedgerCredDef = function createServiceLedgerCredDef ({ logger, saveCredDef, loadCredDef, listCredDefIds }) {
async function createCredentialDefinitionV2 (schemaId, credDefId, supportRevocation, tag = 'tag1') {
module.exports.createServiceLedgerCredDef = function createServiceLedgerCredDef({ logger, saveCredDef, loadCredDef, listCredDefIds }) {
async function createCredentialDefinitionV2(issuerDid, schemaId, credDefId, supportRevocation, tag = 'tag1') {
const data = {
issuerDid,
supportRevocation,
schemaId,
sourceId: credDefId,
Expand All @@ -16,19 +17,19 @@ module.exports.createServiceLedgerCredDef = function createServiceLedgerCredDef
return credDef
}

async function listIds () {
async function listIds() {
return listCredDefIds()
}

async function printInfo (credDefIds) {
async function printInfo(credDefIds) {
for (const id of credDefIds) {
const credDef = await loadCredDef(id)
const serCredDef = credDef.serialize()
logger.info(`Credential definition ${id}: ${JSON.stringify(serCredDef)}`)
}
}

async function getCredDefId (credDefId) {
async function getCredDefId(credDefId) {
const credDef = await loadCredDef(credDefId)
logger.info(`Getting credDefId for credential definition ${credDefId}`)
return credDef.getCredDefId()
Expand Down
10 changes: 5 additions & 5 deletions agents/node/vcxagent-core/src/services/service-ledger-schema.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const { Schema } = require('@hyperledger/node-vcx-wrapper')

module.exports.createServiceLedgerSchema = function createServiceLedgerSchema ({ logger, saveSchema, loadSchema, listSchemaIds }) {
async function createSchema (schemaData) {
module.exports.createServiceLedgerSchema = function createServiceLedgerSchema({ logger, saveSchema, loadSchema, listSchemaIds }) {
async function createSchema(schemaData, issuerDid) {
logger.info(`Creating a new schema on the ledger: ${JSON.stringify(schemaData, null, 2)}`)

const schema = await Schema.create(schemaData)
const schema = await Schema.create(schemaData, issuerDid)
const schemaId = await schema.getSchemaId()
await saveSchema(schemaId, schema)
return schemaId
}

async function listIds () {
async function listIds() {
return listSchemaIds()
}

async function printInfo (schemaIds) {
async function printInfo(schemaIds) {
for (const id of schemaIds) {
const serSchema = await loadSchema(id)
logger.info(`Schema ${id}: ${JSON.stringify(serSchema)}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ module.exports.createServiceLedgerRevocationRegistry = function createServiceLed
return { revReg: newRevReg, revRegId: newRevRegId }
}

async function publishRevocations (revRegId) {
async function publishRevocations (revRegId, submittderDid) {
logger.info(`Publishing revocations for revocation registry ${revRegId}`)
const revReg = await loadRevReg(revRegId)
await revReg.publishRevocations()
await revReg.publishRevocations(submittderDid)
}

async function getTailsFile (credDefId) {
Expand Down
Loading

0 comments on commit 3a2d694

Please sign in to comment.