Skip to content

Commit

Permalink
Update vcxagent-cli
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Oct 9, 2020
1 parent aafc86f commit 8d50e4b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
22 changes: 12 additions & 10 deletions agents/node/vcxagent-cli/vcxclient-interactive.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const readlineSync = require('readline-sync')
const { getSampleSchemaData } = require('vcxagent-core/src')
const { createVcxAgent } = require('vcxagent-core')
const { initRustapi, getSampleSchemaData, createVcxAgent } = require('../vcxagent-core')
const logger = require('./logger')('VCX Client')

async function createInteractiveClient (agentName, seed, acceptTaa, protocolType, rustLogLevel) {
logger.info(`Creating interactive client ${agentName} seed=${seed} protocolType=${protocolType}`)

await initRustapi(rustLogLevel)

const ariesAgent = await createVcxAgent({
agentName,
protocolType,
Expand Down Expand Up @@ -44,8 +46,8 @@ async function createInteractiveClient (agentName, seed, acceptTaa, protocolType
logger.info('Taa accepted.\n')
} else if (cmd === '1') {
logger.info(`Cmd was ${cmd}, going to create schema\n`)
const schema = await ariesAgent.serviceLedgerSchema.createSchema(getSampleSchemaData())
logger.info(`Schema created ${JSON.stringify(await schema.serialize())}`)
const schemaId = await ariesAgent.serviceLedgerSchema.createSchema(getSampleSchemaData())
await ariesAgent.serviceLedgerSchema.printInfo([schemaId])
} else if (cmd === '2') {
const schemaId = readlineSync.question('Enter schemaId:\n')
const name = readlineSync.question('Enter credDef name:\n')
Expand All @@ -66,20 +68,20 @@ async function createInteractiveClient (agentName, seed, acceptTaa, protocolType
await ariesAgent.serviceConnections.connectionAutoupdate(connectionId)
} else if (cmd === '13') {
const connectionId = readlineSync.question('Enter connection id:\n')
await ariesAgent.connectionPrintInfo(connectionId)
await ariesAgent.serviceConnections.printInfo([connectionId])
} else if (cmd === '14') {
logger.info('Listing connections:')
await ariesAgent.connectionsList()
const connectionIds = await ariesAgent.serviceConnections.listIds()
await ariesAgent.serviceConnections.printInfo(connectionIds)
} else if (cmd === '20') {
const connectionId = readlineSync.question('Enter connection id:\n')
await ariesAgent.getCredentialOffers(connectionId) // use waitForCredentialOffers with minimal timeoutMs tolerance
await ariesAgent.serviceCredHolder.waitForCredentialOffer(connectionId, null, 1, 0)
} else if (cmd === '30') {
const connectionId = readlineSync.question('Enter connection id:\n')
const message = readlineSync.question('Enter message to send:\n')
await ariesAgent.sendMessage(connectionId, message)
await ariesAgent.serviceConnections.sendMessage(connectionId, message)
} else if (cmd === '31') {
const connectionId = readlineSync.question('Enter connection id:\n')
const messages = await ariesAgent.getMessages(connectionId, [], [])
const messages = await ariesAgent.serviceConnections.getMessages(connectionId, [], [])
logger.info(`Found messages\n:${JSON.stringify(messages, null, 2)}`)
} else {
logger.error(`Unknown command ${cmd}`)
Expand Down
2 changes: 1 addition & 1 deletion agents/node/vcxagent-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@absaoss/vcxagent-core",
"description": "NodeJS LibVCX based Aries agent",
"license": "Apache-2.0",
"main": "index.js",
"main": "src/index.js",
"directories": {
"test": "test",
"lib": "src"
Expand Down
4 changes: 3 additions & 1 deletion agents/node/vcxagent-core/src/agent/vcx-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ async function createVcxAgent ({ agentName, genesisPath, protocolType, agencyUrl
const taa = await getLedgerAuthorAgreement()
const taaJson = JSON.parse(taa)
const utime = Math.floor(new Date() / 1000)
await setActiveTxnAuthorAgreementMeta(taaJson.text, taaJson.version, null, Object.keys(taaJson.aml)[0], utime)
const acceptanceMechanism = Object.keys(taaJson.aml)[0]
logger.info(`Accepting TAA using mechanism ${acceptanceMechanism} at time ${utime}`)
await setActiveTxnAuthorAgreementMeta(taaJson.text, taaJson.version, null, acceptanceMechanism, utime)
}

function getInstitutionDid () {
Expand Down

0 comments on commit 8d50e4b

Please sign in to comment.