Skip to content

Commit

Permalink
Use credx anoncreds in napi wrapper (#927)
Browse files Browse the repository at this point in the history
* Build napi wrapper with credx

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas authored Oct 4, 2023
1 parent 55f0df0 commit ff6a060
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 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,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
Expand Down
16 changes: 9 additions & 7 deletions agents/node/vcxagent-core/test/distribute-tails.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
17 changes: 9 additions & 8 deletions agents/node/vcxagent-core/test/issue-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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()

Expand All @@ -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 {
Expand Down Expand Up @@ -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()

Expand All @@ -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 {
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
2 changes: 1 addition & 1 deletion wrappers/vcx-napi-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit ff6a060

Please sign in to comment.