Skip to content

Commit

Permalink
Fix tails directory setup in nodejs
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 Aug 19, 2023
1 parent 8b7313e commit 3de52be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
5 changes: 4 additions & 1 deletion agents/node/vcxagent-core/demo/alice.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ const { extractProofRequestAttachement } = require('../src/utils/proofs')
const assert = require('assert')
const { getStorageInfoMysql } = require('./wallet-common')
const { initRustLogger } = require('../src')
const mkdirp = require('mkdirp')

const mapRevRegIdToTailsFile = (_revRegId) => '/tmp/tails'
const tailsDir = '/tmp/tails'
const mapRevRegIdToTailsFile = (_revRegId) => tailsDir

async function getInvitationString (fetchInviteUrl) {
mkdirp.sync(tailsDir)
let invitationString
if (fetchInviteUrl) {
const fetchInviteAttemptThreshold = 30
Expand Down
2 changes: 2 additions & 0 deletions agents/node/vcxagent-core/demo/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ require('@hyperledger/node-vcx-wrapper')
const { getStorageInfoMysql } = require('./wallet-common')
const sleep = require('sleep-promise')
const { testTailsUrl, initRustLogger } = require('../src')
const mkdirp = require('mkdirp')

const tailsDir = '/tmp/tails'

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

Expand Down
16 changes: 9 additions & 7 deletions agents/node/vcxagent-core/test/issue-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ const sleep = require('sleep-promise')
const { initRustLogger } = require('../src')
const { proofRequestDataStandard, proofRequestDataSelfAttest } = require('./utils/data')
const path = require('path')
const mkdirp = require('mkdirp')

const TAILS_DIR = '/tmp/faber/tails'

beforeAll(async () => {
jest.setTimeout(1000 * 60 * 4)
initRustLogger(process.env.RUST_LOG || 'vcx=error')
mkdirp(TAILS_DIR)
})

afterAll(async () => {
Expand All @@ -26,9 +30,8 @@ describe('test update state', () => {
it('Faber should issue credential, verify proof', async () => {
const { alice, faber } = await createPairedAliceAndFaber()
const issuerDid = faber.getFaberDid()
const tailsDir = path.join(__dirname, '/tmp/faber/tails')
await faber.buildLedgerPrimitives({ tailsDir, maxCreds: 5 })
await faber.rotateRevReg(tailsDir, 5)
await faber.buildLedgerPrimitives({ tailsDir: TAILS_DIR, maxCreds: 5 })
await faber.rotateRevReg(TAILS_DIR, 5)
await faber.sendCredentialOffer()
await alice.acceptCredentialOffer()

Expand All @@ -38,7 +41,7 @@ describe('test update state', () => {
await faber.receiveCredentialAck()

const request = await faber.requestProofFromAlice(proofRequestDataStandard(issuerDid))
await alice.sendHolderProof(JSON.parse(request), revRegId => tailsDir, { attr_nickname: 'Smith' })
await alice.sendHolderProof(JSON.parse(request), revRegId => TAILS_DIR, { attr_nickname: 'Smith' })
await faber.updateStateVerifierProof(VerifierStateType.Finished)
await alice.updateStateHolderProof(ProverStateType.Finished)
const {
Expand Down Expand Up @@ -124,8 +127,7 @@ describe('test update state', () => {
it('Faber should issue credential, revoke credential, verify proof', async () => {
const { alice, faber } = await createPairedAliceAndFaber()
const issuerDid = faber.getFaberDid()
const tailsDir = path.join(__dirname, '/tmp/faber/tails')
await faber.buildLedgerPrimitives({ tailsDir, maxCreds: 5 })
await faber.buildLedgerPrimitives({ tailsDir: TAILS_DIR, maxCreds: 5 })
await faber.sendCredentialOffer()
await alice.acceptCredentialOffer()

Expand All @@ -136,7 +138,7 @@ describe('test update state', () => {
await faber.revokeCredential()

const request = await faber.requestProofFromAlice(proofRequestDataStandard(issuerDid))
await alice.sendHolderProof(JSON.parse(request), revRegId => tailsDir, { attr_nickname: 'Smith' })
await alice.sendHolderProof(JSON.parse(request), revRegId => TAILS_DIR, { attr_nickname: 'Smith' })
await faber.updateStateVerifierProof(VerifierStateType.Finished)
await alice.updateStateHolderProof(ProverStateType.Failed)
const {
Expand Down
13 changes: 7 additions & 6 deletions agents/node/vcxagent-core/test/out-of-band.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ const { createPairedAliceAndFaberViaOobMsg, createAliceAndFaber, connectViaOobMe
const { IssuerStateType, HolderStateType, OutOfBandReceiver } = require('@hyperledger/node-vcx-wrapper')
const { initRustLogger } = require('../src')
const { proofRequestDataStandard } = require('./utils/data')
const path = require('path')
const mkdirp = require('mkdirp')
const logger = require('../demo/logger')('out-of-band-test')

const TAILS_DIR = '/tmp/faber/tails'

beforeAll(async () => {
jest.setTimeout(1000 * 60 * 4)
initRustLogger(process.env.RUST_LOG || 'vcx=error')
mkdirp(TAILS_DIR)
})

describe('test out of band communication', () => {
Expand Down Expand Up @@ -56,8 +59,7 @@ describe('test out of band communication', () => {
it('Faber issues credential via OOB', async () => {
try {
const { alice, faber } = await createAliceAndFaber()
const tailsDir = path.join(__dirname, '/tmp/faber/tails')
await faber.buildLedgerPrimitives({ tailsDir, maxCreds: 5 })
await faber.buildLedgerPrimitives({ tailsDir: TAILS_DIR, maxCreds: 5 })
const oobCredOfferMsg = await faber.createOobCredOffer()

await connectViaOobMessage(alice, faber, oobCredOfferMsg)
Expand All @@ -75,8 +77,7 @@ describe('test out of band communication', () => {
it('Faber requests proof via OOB', async () => {
try {
const { alice, faber } = await createPairedAliceAndFaber()
const tailsDir = path.join(__dirname, '/tmp/faber/tails')
await faber.buildLedgerPrimitives({ tailsDir, maxCreds: 5 })
await faber.buildLedgerPrimitives({ tailsDir: TAILS_DIR, maxCreds: 5 })
await faber.sendCredentialOffer()
await alice.acceptCredentialOffer()
await faber.updateStateCredential(IssuerStateType.RequestReceived)
Expand All @@ -88,7 +89,7 @@ describe('test out of band communication', () => {

const oobReceiver = await OutOfBandReceiver.createWithMessage(oobPresentationRequestMsg)
const presentationRequest = oobReceiver.extractMessage()
await alice.sendHolderProof(presentationRequest, revRegId => tailsDir, { attr_nickname: 'Smith' })
await alice.sendHolderProof(presentationRequest, revRegId => TAILS_DIR, { attr_nickname: 'Smith' })
await faber.updateStateVerifierProof(VerifierStateType.Finished)
} catch (e) {
console.error(e.stack)
Expand Down

0 comments on commit 3de52be

Please sign in to comment.