Skip to content

Commit

Permalink
Merge branch 'main' into jc-add-healthz
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand authored Nov 22, 2024
2 parents d078106 + 6f5d8a4 commit 7c9ef5b
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [16.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
30 changes: 30 additions & 0 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
}

readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
exit $exitCode
fi

exit 0
fi
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# transaction-manager-service Changelog

## 1.0.0 - TBD
## 0.2.0 - 2024-10-11

### Changed

- updated libs to support VC2

## 0.1.1 - 2023-12-11

### Changed

- added optional metadata property on stored object

## 0.1.0 - 2023-09-26

### Added

Expand Down
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@digitalcredentials/transaction-service",
"description": "An express app for managing challenges in a DIDAuth exchange.",
"version": "0.0.1",
"version": "0.2.0",
"type": "module",
"scripts": {
"start": "node -r dotenv/config server.js",
Expand All @@ -14,22 +14,16 @@
"lint-fix": "eslint --fix"
},
"dependencies": {
"@digitalbazaar/did-io": "^2.0.0",
"@digitalbazaar/did-method-key": "^5.1.0",
"@digitalbazaar/ed25519-signature-2020": "^5.2.0",
"@digitalbazaar/ed25519-signature-2020": "^5.4.0",
"@digitalbazaar/ed25519-verification-key-2020": "^4.1.0",
"@digitalbazaar/vc": "^6.0.1",
"axios": "^1.7.2",
"@digitalbazaar/vc": "^7.0.0",
"@digitalcredentials/security-document-loader": "^6.0.0",
"cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"credentials-context": "^2.0.0",
"crypto": "^1.0.1",
"debug": "~2.6.9",
"did-context": "^3.1.1",
"dotenv": "^16.0.3",
"ed25519-signature-2020-context": "^1.1.0",
"express": "~4.16.1",
"jsonld-document-loader": "^2.0.0",
"keyv": "^4.5.2",
"keyv-file": "^0.2.0",
"morgan": "~1.9.1",
Expand Down
41 changes: 40 additions & 1 deletion src/app.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { expect } from 'chai'

import request from 'supertest'
import crypto from 'crypto'
import { build } from './app.js'
import { getDataForExchangeSetupPost } from './test-fixtures/testData.js'
import { getDataForExchangeSetupPost, testVC } from './test-fixtures/testData.js'
import { getSignedDIDAuth } from './didAuth.js'
import {
clearKeyv,
initializeTransactionManager
} from './transactionManager.js'
import TransactionException from './TransactionException.js'
const tempKeyvFile = process.env.PERSIST_TO_FILE

let app

describe('api', function () {
Expand Down Expand Up @@ -51,6 +53,43 @@ describe('api', function () {
expect(response.body.length).to.eql(testData.data.length)
})

it('returns array of wallet queries', async () => {
const testData = getDataForExchangeSetupPost('test')
const response = await request(app)
.post("/exchange")
.send(testData)
expect(response.header["content-type"]).to.have.string("json");
expect(response.status).to.eql(200);
expect(response.body)
expect(response.body.length).to.eql(testData.data.length)

const walletQuerys = response.body
const walletQuery = walletQuerys.find(q => q.retrievalId === 'someId')
const url = walletQuery.directDeepLink

const parsedDeepLink = new URL(url)
const requestURI = parsedDeepLink.searchParams.get('vc_request_url'); //should be http://localhost:4004/exchange?challenge=VOclS8ZiMs&auth_type=bearer
// here we need to pull out just the path
// since we are calling the endpoint via
// supertest
const path = (new URL(requestURI)).pathname
const challenge = parsedDeepLink.searchParams.get('challenge'); // the challenge that the exchange service generated
const didAuth = await getSignedDIDAuth('did:ex:223234', challenge)

const exchangeResponse = await request(app)
.post(path)
.send(didAuth)

expect(exchangeResponse.header["content-type"]).to.have.string("json");
expect(exchangeResponse.status).to.eql(200);
expect(exchangeResponse.body)

const signedVC = exchangeResponse.body.vc
expect(signedVC).to.eql(testVC)

})


it('returns error if missing exchangeHost', async function () {
const testData = getDataForExchangeSetupPost('test')
delete testData.exchangeHost
Expand Down
23 changes: 14 additions & 9 deletions src/didAuth.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {signPresentation, createPresentation, verify} from '@digitalbazaar/vc';
import {Ed25519VerificationKey2020} from '@digitalbazaar/ed25519-verification-key-2020';

import {verify,signPresentation, createPresentation} from '@digitalbazaar/vc';

import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020';
import { securityLoader } from './securityLoader.js';
import { securityLoader } from '@digitalcredentials/security-document-loader';
import {Ed25519VerificationKey2020} from '@digitalbazaar/ed25519-verification-key-2020';

const documentLoader = securityLoader().build()

const signingKeyPairForTesting = await Ed25519VerificationKey2020.generate(
const key = await Ed25519VerificationKey2020.generate(
{
seed: new Uint8Array ([
217, 87, 166, 30, 75, 106, 132, 55,
Expand All @@ -16,18 +18,21 @@ const signingKeyPairForTesting = await Ed25519VerificationKey2020.generate(
controller: "did:key:z6MkvL5yVCgPhYvQwSoSRQou6k6ZGfD5mNM57HKxufEXwfnP"
}
)
const suiteForSigning = new Ed25519Signature2020({key: signingKeyPairForTesting});
const suiteForVerification = new Ed25519Signature2020();



const suite = new Ed25519Signature2020({key});

export const getSignedDIDAuth = async (holder = 'did:ex:12345', challenge) => {
const presentation = createPresentation({holder});
return await signPresentation({
presentation, suite: suiteForSigning, challenge, documentLoader
presentation, suite, challenge, documentLoader
});
}

const verificationSuite = new Ed25519Signature2020();

export const verifyDIDAuth = async ({presentation, challenge}) => {
const result = await verify({presentation, challenge, suite: suiteForVerification, documentLoader});
const result = await verify({presentation, challenge, suite: verificationSuite, documentLoader});
return result.verified
}

35 changes: 0 additions & 35 deletions src/securityLoader.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/test-fixtures/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ const getDataForExchangeSetupPost = (
return fakeData
}

export { getDataForExchangeSetupPost }
export { getDataForExchangeSetupPost, testVC }

0 comments on commit 7c9ef5b

Please sign in to comment.