Skip to content

Commit

Permalink
enable different configuration for schema owner/issuer/verifier
Browse files Browse the repository at this point in the history
Signed-off-by: Clécio Varjão <[email protected]>
  • Loading branch information
cvarjao committed Aug 9, 2024
1 parent c004348 commit 819803b
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 185 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
## Setup
1. Clone Repository
1. Install dependencied
```
yarn install
```
```
git clone <git repository url>
```
1. Install dependencies
```
yarn install
```
## Configure your traction instance
### Automatically Generate using traction sandbox enrionment
```
yarn ts-node src/setup-from-sandbox.ts
```
### Automatically Generate using traction sandbox environment

```
yarn ts-node src/setup-from-sandbox.ts
```

### Manually create the local env file
1. Copy file `sample.local.env.json` to `local.env.json`
2. Configure agent:
Expand All @@ -17,11 +22,11 @@
- `tenant_id`: Traction tenant ID
- `api_key`: Traction API Key

## Start ngrok service
## In terminal 1, start ngrok service
```
ngrok http "file://${PWD}/tmp"
```
## Run Test
## In terminal 2, run tests
```
yarn jest --runInBand --detectOpenHandles --forceExit
```
10 changes: 6 additions & 4 deletions src/AgentTraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,12 @@ export class AgentTraction implements AriesAgent {
}
})
const credDef = credential_definition.data
if (!credDefBuilder.getSupportRevocation() && credDef.credential_definition.value.revocation === undefined){
credential_definitions.push(credDef)
} else if (credDefBuilder.getSupportRevocation() && credDef.credential_definition.value.revocation !== undefined){
credential_definitions.push(credDef)
if (credDef.credential_definition.tag === credDefBuilder.getTag()) {
if (!credDefBuilder.getSupportRevocation() && credDef.credential_definition.value.revocation === undefined){
credential_definitions.push(credDef)
} else if (credDefBuilder.getSupportRevocation() && credDef.credential_definition.value.revocation !== undefined){
credential_definitions.push(credDef)
}
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ describe("AppAttestation", () => {
throw error
}
}, stepTimeout)
test("connected/v1", async () => {
test("connected/v1/prod", async () => {
const verifier = agentA
const holder = agentB
logger.info(`Executing ${expect.getState().currentTestName}`)
const remoteInvitation = await verifier.createInvitationToConnect() as ResponseCreateInvitationV1
logger.info(`waiting for holder to accept connection`)
const agentBConnectionRef1 = await holder.receiveInvitation(remoteInvitation)
logger.info(`waiting for issuer to accept connection`)
await verifier.waitForConnectionReady(remoteInvitation.payload.connection_id)
await verifier.waitForConnectionReady(remoteInvitation.payload.connection_id as string)
logger.info(`${remoteInvitation.payload.connection_id} connected to ${agentBConnectionRef1.connectionRecord?.connection_id}`)
logger.info('agentBConnectionRef1', agentBConnectionRef1)

Expand All @@ -94,9 +94,12 @@ describe("AppAttestation", () => {
"operating_system",
"app_version",
])
.addRestriction({ "schema_name": schema.getName(), "schema_version": schema.getVersion(), "issuer_did": credDef.getId()?.split(':')[0] })
.addRestriction({
cred_def_id: "XqaRXJt4sXE6TRpfGpVbGw:3:CL:655:bcwallet",
})
//.addRestriction({ "schema_name": schema.getName(), "schema_version": schema.getVersion(), "issuer_did": credDef.getId()?.split(':')[0] })
)
const proofRequestSent: any = await verifier.sendProofRequestV1(remoteInvitation.payload.connection_id, proofRequest)
const proofRequestSent: any = await verifier.sendProofRequestV1(remoteInvitation.payload.connection_id as string, proofRequest)
logger.info('Proof Request Sent:', proofRequestSent)
await verifier.waitForPresentation(proofRequestSent.presentation_exchange_id)
}, shortTimeout);
Expand Down
139 changes: 139 additions & 0 deletions src/axios-traction-serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { InternalAxiosRequestConfig } from "axios"
import { dir as console_dir } from "console"

export const cache_requests = (requests: unknown[] = []) =>{
return (request: InternalAxiosRequestConfig<any>) => {
//take a copy
const req = JSON.parse(JSON.stringify({
headers:request.headers,
data:request.data,
params:request.params,
baseUrl: '--redacted--', //request.baseURL,
method: request.method,
url: request.url
}))
if (req.headers['Authorization']) {
req.headers['Authorization'] = '--redacted--'
}
if (req.url.startsWith('/connections/')){
const regex = /^(\/connections\/)([^/]+)(\/[^/]+)?$/mg;
req.url = req.url.replace(regex, '$1{connection_id}$3');
}
if (req.url.startsWith('/issue-credential/records/')){
const regex = /^(\/issue-credential\/records\/)([^/]+)(\/[^/]+)?$/mg;
req.url = req.url.replace(regex, '$1{record_id}$3');
}
if (req.url.startsWith('/present-proof/records/')){
const regex = /^(\/present-proof\/records\/)([^/]+)(\/[^/]+)?$/mg;
req.url = req.url.replace(regex, '$1{record_id}$3');
}
if (req.url.startsWith('/present-proof-2.0/records/')){
const regex = /^(\/present-proof-2.0\/records\/)([^/]+)(\/[^/]+)?$/mg;
req.url = req.url.replace(regex, '$1{record_id}$3');
}
if (req.url.startsWith('/credential-definitions/')){
if (!(req.url === '/credential-definitions/created')){
const regex = /^(\/credential-definitions\/)([^/]+)(\/[^/]+)?$/mg;
req.url = req.url.replace(regex, '$1{cred_def_id}$3');
}
}
if (req.method === 'get' && req.url === '/basicmessages' && req.params?.connection_id) {
req.params.connection_id = '{connection_id}'
}
if (req.method === 'post' && req.url === '/present-proof/send-request' && req.data) {
req.data.proof_request = '--redacted--'
req.data.connection_id = '{connection_id}'
req.data.cred_def_id = '{cred_def_id}'
}
if (req.method === 'post' && req.url === '/issue-credential/send-offer' && req.data) {
req.data.credential_preview = '{--redacted--}'
req.data.cred_def_id = '{cred_def_id}'
req.data.connection_id = '{connection_id}'
}
if (req.method === 'post' && req.url === '/present-proof/create-request' && req.data) {
req.data.proof_request = '{--redacted--}'
}
if (req.method === 'post' && req.url === '/out-of-band/create-invitation' && req.data?.attachments) {
//req.data.attachments = '--redacted--'
for (const attachment of req.data.attachments) {
if (attachment?.id){
attachment.id = '--redacted--'
}
if (attachment.data?.json){
if (attachment?.data?.id){
attachment.data.id = '--redacted--'
}
if (attachment?.data?.json?.id){
attachment.data.json.id = '--redacted--'
}
if (attachment.data?.json?.thread_id) {
attachment.data.json.thread_id = '--redacted--'
}
if (attachment.data?.json?.created_at){
attachment.data.json.created_at = '--redacted--'
}
if (attachment.data?.json?.updated_at){
attachment.data.json.updated_at = '--redacted--'
}
if (attachment.data?.json?.presentation_exchange_id) {
attachment.data.json.presentation_exchange_id = '--redacted--'
}
if (attachment.data?.json?.pres_ex_id) {
attachment.data.json.pres_ex_id = '--redacted--'
}
if (attachment.data?.json?.presentation_request) {
attachment.data.json.presentation_request = '{--redacted--}'
}
if (attachment.data?.json?.presentation_request_dict) {
attachment.data.json.presentation_request_dict = '{--redacted--}'
}
if (attachment.data?.json?.by_format?.pres_request?.indy) {
attachment.data.json.by_format.pres_request.indy.nonce = '--redacted--'
const requested_attributes = attachment.data?.json?.by_format.pres_request?.indy?.requested_attributes
if (requested_attributes){
for (const key in requested_attributes) {
if (Object.prototype.hasOwnProperty.call(requested_attributes, key)) {
const item = requested_attributes[key];
if (item.non_revoked?.from) {
item.non_revoked.from = '--redacted--'
}
if (item.non_revoked?.to) {
item.non_revoked.to = '--redacted--'
}
if (item.restrictions) {
for (const restriction of item.restrictions) {
if (restriction.issuer_did) {
restriction.issuer_did = '--redacted--'
}
}
}
}
}
}
}
if (attachment.data?.json?.pres_request) {
attachment.data.json.pres_request = '{--redacted--}'
}
}
}
}
if (req.method === 'post' && req.url === '/present-proof-2.0/create-request' && req.data) {
req.data.presentation_request = '{--redacted--}'
}
if (req.method === 'post' && req.url === '/connections/{connection_id}' && req.data?.my_label) {
const regex = /(- \d+$)/mg;
req.data.my_label = req.data.my_label.replace(regex, '- {timestamp}');
}
// do not add consecutive duplicates
if (requests.length > 0) {
const prev = requests[requests.length - 1]
if (JSON.stringify(prev) === JSON.stringify(req)) {
//console_dir(request, {depth: 6})
return request
}
}
//console_dir(req, {depth: 6})
requests.push(req)
return request
}
}
Loading

0 comments on commit 819803b

Please sign in to comment.