From ff6a06014d9f02173612219a357a234eaea3adfe Mon Sep 17 00:00:00 2001 From: Patrik Date: Wed, 4 Oct 2023 14:30:57 +0200 Subject: [PATCH] Use credx anoncreds in napi wrapper (#927) * Build napi wrapper with credx Signed-off-by: Patrik Stas --- agents/node/vcxagent-core/demo/alice.js | 5 ++++- agents/node/vcxagent-core/demo/faber.js | 2 ++ .../vcxagent-core/test/distribute-tails.spec.js | 16 +++++++++------- .../vcxagent-core/test/issue-verify.spec.js | 17 +++++++++-------- .../node/vcxagent-core/test/out-of-band.spec.js | 13 +++++++------ wrappers/vcx-napi-rs/Cargo.toml | 2 +- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/agents/node/vcxagent-core/demo/alice.js b/agents/node/vcxagent-core/demo/alice.js index 5b3b0df949..e7ec0aa58e 100644 --- a/agents/node/vcxagent-core/demo/alice.js +++ b/agents/node/vcxagent-core/demo/alice.js @@ -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 diff --git a/agents/node/vcxagent-core/demo/faber.js b/agents/node/vcxagent-core/demo/faber.js index 8a03749fc4..ea7616e56c 100644 --- a/agents/node/vcxagent-core/demo/faber.js +++ b/agents/node/vcxagent-core/demo/faber.js @@ -13,11 +13,13 @@ 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) { logger.info(`Starting Faber. Revocation enabled=${options.revocation}`) + mkdirp.sync(tailsDir) initRustLogger(process.env.RUST_LOG || 'vcx=error') let faberServer diff --git a/agents/node/vcxagent-core/test/distribute-tails.spec.js b/agents/node/vcxagent-core/test/distribute-tails.spec.js index 6a465c448d..cbe9ef3a61 100644 --- a/agents/node/vcxagent-core/test/distribute-tails.spec.js +++ b/agents/node/vcxagent-core/test/distribute-tails.spec.js @@ -9,12 +9,16 @@ const uuid = require('uuid') const sleep = require('sleep-promise') const fs = require('fs') const mkdirp = require('mkdirp') -const path = require('path') const { proofRequestDataStandard } = require('./utils/data') +const TAILS_DIR_ALICE = '/tmp/alice/tails' +const TAILS_DIR_FABER = '/tmp/faber/tails' + beforeAll(async () => { jest.setTimeout(1000 * 60 * 4) initRustLogger(process.env.RUST_LOG || 'vcx=error') + mkdirp(TAILS_DIR_ALICE) + mkdirp(TAILS_DIR_FABER) }) describe('test tails distribution', () => { @@ -26,7 +30,7 @@ describe('test tails distribution', () => { const port = 5468 const tailsUrlId = uuid.v4() const tailsUrl = `http://127.0.0.1:${port}/${tailsUrlId}` - await faber.buildLedgerPrimitives(buildRevocationDetails({ supportRevocation: true, tailsDir: path.join(__dirname, '/tmp/faber/tails'), maxCreds: 5, tailsUrl })) + await faber.buildLedgerPrimitives(buildRevocationDetails({ supportRevocation: true, tailsDir: TAILS_DIR_FABER, maxCreds: 5, tailsUrl })) await faber.sendCredentialOffer() await alice.acceptCredentialOffer() await faber.updateStateCredential(IssuerStateType.RequestReceived) @@ -35,20 +39,18 @@ describe('test tails distribution', () => { const faberTailsHash = await faber.getTailsHash() const app = express() - app.use(`/${tailsUrlId}`, express.static(path.join(__dirname, `/tmp/faber/tails/${faberTailsHash}`))) + app.use(`/${tailsUrlId}`, express.static(`${TAILS_DIR_FABER}/${faberTailsHash}`)) server = app.listen(port) const aliceTailsLocation = await alice.getTailsLocation() const aliceTailsHash = await alice.getTailsHash() - const aliceTailsFileDir = path.join(__dirname, '/tmp/alice/tails') - const aliceTailsFilePath = aliceTailsFileDir + `/${aliceTailsHash}` - await mkdirp(aliceTailsFileDir) + const aliceTailsFilePath = TAILS_DIR_ALICE + `/${aliceTailsHash}` axios.default.get(`${aliceTailsLocation}`, { responseType: 'stream' }).then(res => { res.data.pipe(fs.createWriteStream(aliceTailsFilePath)) }) const issuerDid = faber.getFaberDid() const request = await faber.requestProofFromAlice(proofRequestDataStandard(issuerDid)) - await alice.sendHolderProof(JSON.parse(request), revRegId => aliceTailsFileDir, { attr_nickname: 'Smith' }) + await alice.sendHolderProof(JSON.parse(request), revRegId => TAILS_DIR_ALICE, { attr_nickname: 'Smith' }) await faber.updateStateVerifierProof(VerifierStateType.Finished) await alice.updateStateHolderProof(ProverStateType.Finished) } catch (err) { diff --git a/agents/node/vcxagent-core/test/issue-verify.spec.js b/agents/node/vcxagent-core/test/issue-verify.spec.js index 5e86e114f3..08445453a7 100644 --- a/agents/node/vcxagent-core/test/issue-verify.spec.js +++ b/agents/node/vcxagent-core/test/issue-verify.spec.js @@ -11,11 +11,14 @@ const { 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 () => { @@ -26,9 +29,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() @@ -38,7 +40,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 { @@ -124,8 +126,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() @@ -136,7 +137,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 { diff --git a/agents/node/vcxagent-core/test/out-of-band.spec.js b/agents/node/vcxagent-core/test/out-of-band.spec.js index 3eaa8d99d1..2d5ff29882 100644 --- a/agents/node/vcxagent-core/test/out-of-band.spec.js +++ b/agents/node/vcxagent-core/test/out-of-band.spec.js @@ -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', () => { @@ -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) @@ -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) @@ -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) diff --git a/wrappers/vcx-napi-rs/Cargo.toml b/wrappers/vcx-napi-rs/Cargo.toml index 3e6ff1e40d..6e089db995 100644 --- a/wrappers/vcx-napi-rs/Cargo.toml +++ b/wrappers/vcx-napi-rs/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] doctest = false [features] -default = ["anoncreds_vdrtools"] +default = ["anoncreds_credx"] anoncreds_credx = ["libvcx_core/anoncreds_credx"] anoncreds_vdrtools = ["libvcx_core/anoncreds_vdrtools"]