Skip to content

Commit

Permalink
feat: rename to credo-ts and add caching (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
genaris authored Feb 1, 2024
1 parent cf93847 commit 49b5a85
Show file tree
Hide file tree
Showing 18 changed files with 931 additions and 302 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
# Ideally we only add this to the 'release' job so it doesn't limit PR runs, but github can't guarantee the job order in that case:
# "When concurrency is specified at the job level, order is not guaranteed for jobs or runs that queue within 5 minutes of each other."
concurrency:
group: aries-framework-${{ github.ref }}-${{ github.repository }}-${{ github.event_name }}
group: credo-ts-${{ github.ref }}-${{ github.repository }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
Expand All @@ -38,7 +38,7 @@ jobs:
needs: [ci-trigger]
if: needs.ci-trigger.outputs.triggered == 'true'
steps:
- name: Checkout aries-javascript-indy-vdr-proxy
- name: Checkout credo-ts-indy-vdr-proxy
uses: actions/checkout@v2

- name: Setup NodeJS
Expand All @@ -60,12 +60,12 @@ jobs:

package-finder:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.repository == '2060-io/aries-javascript-indy-vdr-proxy' && github.event_name == 'push'
if: github.ref == 'refs/heads/main' && github.repository == '2060-io/credo-ts-indy-vdr-proxy' && github.event_name == 'push'
needs: [validate]
outputs:
packages: ${{ steps.get-packages.outputs.packages }}
steps:
- name: Checkout aries-javascript-indy-vdr-proxy
- name: Checkout credo-ts-indy-vdr-proxy
uses: actions/checkout@v2

- name: Setup NodeJS
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
signoff: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"

# Initiate release process if release was created
- name: Checkout aries-javascript-indy-vdr-proxy
- name: Checkout credo-ts-indy-vdr-proxy
uses: actions/checkout@v2
if: ${{ steps.release-please.outputs.release_created }}
- name: Setup NodeJS
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Aries JavaScript Indy VDR Proxy
# Credo Indy VDR Proxy

This repository contains a server exposing a REST API to resolve objects in Indy ledgers and a client for usage with an [Aries Framework JavaScript](https://github.com/hyperledger/aries-framework-javascript) Agent.
This repository contains a server exposing a REST API to resolve objects in Indy ledgers and a client for usage with a [Credo](https://github.com/openwallet-foundation/credo-ts) Agent .

By using these components, your mobile application based on AFJ can delegate Indy object resolution to a trusted server supporting any Indy networks you want. This makes the app lighter and avoids the need of managing ZMQ sockets within the mobile environment, which could cause troubles in certain situations.
By using these components, your mobile application based on Credo can delegate Indy object resolution to a trusted server supporting any Indy networks you want. This makes the app lighter and avoids the need of managing ZMQ sockets within the mobile environment, which could cause troubles in certain situations.

Take a look at the documentation of [client](./packages/client/README.md) and [server](./packages/server/README.md) for more details.
52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "aries-framework-indy-vdr-proxy",
"name": "credo-ts-indy-vdr-proxy",
"private": true,
"license": "Apache-2.0",
"description": "Monorepo containing Indy VDR Proxy client and server for Aries Framework JavaScript",
"description": "Monorepo containing Indy VDR Proxy client and server for Credo",
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"@aries-framework/askar",
"**/@aries-framework/askar",
"**/@aries-framework/askar/**",
"@aries-framework/askar/**",
"@aries-framework/anoncreds",
"**/@aries-framework/anoncreds",
"**/@aries-framework/anoncreds/**",
"@aries-framework/anoncreds/**",
"@aries-framework/anoncreds-rs",
"**/@aries-framework/anoncreds-rs",
"**/@aries-framework/anoncreds-rs/**",
"@aries-framework/anoncreds-rs/**",
"@aries-framework/indy-vdr",
"**/@aries-framework/indy-vdr",
"**/@aries-framework/indy-vdr/**",
"@aries-framework/indy-vdr/**",
"@aries-framework/node",
"**/@aries-framework/node",
"**/@aries-framework/node/**",
"@aries-framework/node/**",
"@aries-framework/core",
"**/@aries-framework/core",
"**/@aries-framework/core/**",
"@aries-framework/core/**",
"@credo-ts/askar",
"**/@credo-ts/askar",
"**/@credo-ts/askar/**",
"@credo-ts/askar/**",
"@credo-ts/anoncreds",
"**/@credo-ts/anoncreds",
"**/@credo-ts/anoncreds/**",
"@credo-ts/anoncreds/**",
"@credo-ts/anoncreds-rs",
"**/@credo-ts/anoncreds-rs",
"**/@credo-ts/anoncreds-rs/**",
"@credo-ts/anoncreds-rs/**",
"@credo-ts/indy-vdr",
"**/@credo-ts/indy-vdr",
"**/@credo-ts/indy-vdr/**",
"@credo-ts/indy-vdr/**",
"@credo-ts/node",
"**/@credo-ts/node",
"**/@credo-ts/node/**",
"@credo-ts/node/**",
"@credo-ts/core",
"**/@credo-ts/core",
"**/@credo-ts/core/**",
"@credo-ts/core/**",
"@hyperledger/aries-askar-nodejs",
"**/@hyperledger/aries-askar-nodejs",
"**/@hyperledger/aries-askar-nodejs/**",
Expand Down
10 changes: 5 additions & 5 deletions packages/client/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Aries JavaScript Indy VDR Proxy client

This package provides some convenient classes to allow an Agent built on [Aries Framework JavaScript](https://github.com/hyperledger/aries-framework-javascript) resolve DIDs and AnonCreds objects from a number of Indy networks without the need of embedding any [indy-vdr](https://github.com/hyperledger/indy-vdr) client binary.
This package provides some convenient classes to allow an Agent built on [Credo](https://github.com/openwallet-foundation/credo-ts) resolve DIDs and AnonCreds objects from a number of Indy networks without the need of embedding any [indy-vdr](https://github.com/hyperledger/indy-vdr) client binary.

Especially conceived for mobile agents use case, this makes the app lighter and avoids the need of managing ZMQ sockets, as only a simple HTTP REST API is used to retrieve Indy objects.

It works with its companion [Aries JavaScript Indy VDR Proxy Server](https://github.com/2060-io/aries-javascript-indy-vdr-proxy/tree/main/packages/server), expected to be run as a server trusted by the mobile app (as all Indy transactions will go through it).
It works with its companion [Credo Indy VDR Proxy Server](https://github.com/2060-io/credo-ts-indy-vdr-proxy/tree/main/packages/server), expected to be run as a server trusted by the mobile app (as all Indy transactions will go through it).

## Usage

As of AFJ 0.4.0, the most convenient way to use the classes provided by this package is by injecting them in Agent constructor:
As of Credo 0.5.0, the most convenient way to use the classes provided by this package is by injecting them in Agent constructor:

```ts
import { IndyVdrProxyAnonCredsRegistry, IndyVdrProxyDidResolver } from 'aries-javascript-indy-vdr-proxy-client'
import { IndyVdrProxyAnonCredsRegistry, IndyVdrProxyDidResolver } from 'credo-ts-indy-vdr-proxy-client'

const proxyBaseUrl = 'https://proxy-host.com'

Expand All @@ -34,4 +34,4 @@ const agent = new Agent({
And that's it!
Keep in mind that these implementation collide with other resolvers and registries for Indy networks, such as the ones from `@aries-framework/indy-vdr` package, so you'll need to choose to use one or the another when setting up an Agent.
Keep in mind that these implementation collide with other resolvers and registries for Indy networks, such as the ones from `@credo-ts/indy-vdr` package, so you'll need to choose to use one or the another when setting up an Agent.
14 changes: 7 additions & 7 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "aries-framework-indy-vdr-proxy-client",
"name": "credo-ts-indy-vdr-proxy-client",
"version": "0.1.4",
"description": "Indy VDR Proxy client for aries-framework-javascript",
"description": "Indy VDR Proxy client for credo-ts",
"author": "2060.io",
"homepage": "https://github.com/2060-io/aries-javascript-indy-vdr-proxy",
"homepage": "https://github.com/2060-io/credo-ts-indy-vdr-proxy",
"license": "ISC",
"main": "build/index.js",
"types": "build/index.js",
Expand All @@ -22,11 +22,11 @@
},
"repository": {
"type": "git",
"url": "https://github.com/2060-io/aries-javascript-indy-vdr-proxy",
"url": "https://github.com/2060-io/credo-ts-indy-vdr-proxy",
"directory": "packages/client"
},
"bugs": {
"url": "https://github.com/2060-io/aries-javascript-indy-vdr-proxy/issues"
"url": "https://github.com/2060-io/credo-ts-indy-vdr-proxy/issues"
},
"publishConfig": {
"access": "public"
Expand All @@ -41,8 +41,8 @@
"typescript": "~4.9.5"
},
"dependencies": {
"@aries-framework/anoncreds": "^0.5.0-alpha.71",
"@aries-framework/core": "^0.5.0-alpha.71",
"@credo-ts/anoncreds": "^0.5.0-alpha.116",
"@credo-ts/core": "^0.5.0-alpha.116",
"uuid": "^9.0.0"
}
}
141 changes: 125 additions & 16 deletions packages/client/src/anoncreds/IndyVdrProxyAnonCredsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,56 @@ import type {
RegisterCredentialDefinitionReturn,
GetRevocationStatusListReturn,
GetRevocationRegistryDefinitionReturn,
RegisterRevocationRegistryDefinitionOptions,
RegisterRevocationRegistryDefinitionReturn,
RegisterRevocationStatusListOptions,
RegisterRevocationStatusListReturn,
} from "@aries-framework/anoncreds"
import type { AgentContext } from "@aries-framework/core"
} from "@credo-ts/anoncreds"

import { CacheModuleConfig, type AgentContext } from "@credo-ts/core"

import { indyVdrAnonCredsRegistryIdentifierRegex } from "./identifiers"

export interface CacheSettings {
allowCaching: boolean
cacheDurationInSeconds: number
}

export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
public readonly methodName = "indy"

public readonly supportedIdentifier = indyVdrAnonCredsRegistryIdentifierRegex

private proxyBaseUrl: string

public constructor(proxyBaseUrl: string) {
private cacheSettings: CacheSettings

public constructor(options: { proxyBaseUrl: string; cacheOptions?: CacheSettings }) {
const { proxyBaseUrl, cacheOptions } = options
this.proxyBaseUrl = proxyBaseUrl

this.cacheSettings = cacheOptions ?? { allowCaching: true, cacheDurationInSeconds: 300 }
}

public async getSchema(agentContext: AgentContext, schemaId: string): Promise<GetSchemaReturn> {
const cacheKey = `anoncreds:schema:${schemaId}`

if (this.cacheSettings.allowCaching) {
const cache = agentContext.dependencyManager.resolve(CacheModuleConfig).cache

const cachedObject = await cache.get<GetSchemaReturn>(agentContext, cacheKey)

if (cachedObject) {
return {
schema: cachedObject.schema,
schemaId,
schemaMetadata: cachedObject.schemaMetadata,
resolutionMetadata: {
...cachedObject.resolutionMetadata,
servedFromCache: true,
},
}
}
}

try {
const response = await agentContext.config.agentDependencies.fetch(
`${this.proxyBaseUrl}/schema/${encodeURIComponent(schemaId)}`
Expand All @@ -43,8 +72,22 @@ export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
schemaMetadata: {},
}
}
const result = (await response.json()) as GetSchemaReturn
if (result.schema && this.cacheSettings.allowCaching) {
const cache = agentContext.dependencyManager.resolve(CacheModuleConfig).cache
await cache.set(
agentContext,
cacheKey,
{
resolutionMetadata: result.resolutionMetadata,
schema: result.schema,
schemaMetadata: result.schemaMetadata,
},
this.cacheSettings.cacheDurationInSeconds
)
}

return (await response.json()) as GetSchemaReturn
return result
} catch (error) {
agentContext.config.logger.error(`Error retrieving schema '${schemaId}'`, {
error,
Expand Down Expand Up @@ -80,6 +123,26 @@ export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
agentContext: AgentContext,
credentialDefinitionId: string
): Promise<GetCredentialDefinitionReturn> {
const cacheKey = `anoncreds:credentialDefinition:${credentialDefinitionId}`

if (this.cacheSettings.allowCaching) {
const cache = agentContext.dependencyManager.resolve(CacheModuleConfig).cache

const cachedObject = await cache.get<GetCredentialDefinitionReturn>(agentContext, cacheKey)

if (cachedObject) {
return {
credentialDefinition: cachedObject.credentialDefinition,
credentialDefinitionId,
credentialDefinitionMetadata: cachedObject.credentialDefinitionMetadata,
resolutionMetadata: {
...cachedObject.resolutionMetadata,
servedFromCache: true,
},
}
}
}

try {
const response = await agentContext.config.agentDependencies.fetch(
`${this.proxyBaseUrl}/credential-definition/${encodeURIComponent(credentialDefinitionId)}`
Expand All @@ -95,7 +158,23 @@ export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
credentialDefinitionMetadata: {},
}
}
return (await response.json()) as GetCredentialDefinitionReturn
const result = (await response.json()) as GetCredentialDefinitionReturn

if (result.credentialDefinition && this.cacheSettings.allowCaching) {
const cache = agentContext.dependencyManager.resolve(CacheModuleConfig).cache
await cache.set(
agentContext,
cacheKey,
{
resolutionMetadata: result.resolutionMetadata,
schema: result.credentialDefinition,
schemaMetadata: result.credentialDefinitionMetadata,
},
this.cacheSettings.cacheDurationInSeconds
)
}

return result
} catch (error) {
agentContext.config.logger.error(`Error retrieving credential definition '${credentialDefinitionId}'`, {
error,
Expand Down Expand Up @@ -132,6 +211,26 @@ export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
agentContext: AgentContext,
revocationRegistryDefinitionId: string
): Promise<GetRevocationRegistryDefinitionReturn> {
const cacheKey = `anoncreds:revocationRegistryDefinition:${revocationRegistryDefinitionId}`

if (this.cacheSettings.allowCaching) {
const cache = agentContext.dependencyManager.resolve(CacheModuleConfig).cache

const cachedObject = await cache.get<GetRevocationRegistryDefinitionReturn>(agentContext, cacheKey)

if (cachedObject) {
return {
revocationRegistryDefinition: cachedObject.revocationRegistryDefinition,
revocationRegistryDefinitionId,
revocationRegistryDefinitionMetadata: cachedObject.revocationRegistryDefinitionMetadata,
resolutionMetadata: {
...cachedObject.resolutionMetadata,
servedFromCache: true,
},
}
}
}

try {
const response = await agentContext.config.agentDependencies.fetch(
`${this.proxyBaseUrl}/revocation-registry-definition/${encodeURIComponent(revocationRegistryDefinitionId)}`
Expand All @@ -147,7 +246,23 @@ export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
}
}

return (await response.json()) as GetRevocationRegistryDefinitionReturn
const result = (await response.json()) as GetRevocationRegistryDefinitionReturn

if (result.revocationRegistryDefinition && this.cacheSettings.allowCaching) {
const cache = agentContext.dependencyManager.resolve(CacheModuleConfig).cache
await cache.set(
agentContext,
cacheKey,
{
resolutionMetadata: result.resolutionMetadata,
revocationRegistryDefinition: result.revocationRegistryDefinition,
revocationRegistryDefinitionMetadata: result.revocationRegistryDefinitionMetadata,
},
this.cacheSettings.cacheDurationInSeconds
)
}

return result
} catch (error) {
agentContext.config.logger.error(
`Error retrieving revocation registry definition '${revocationRegistryDefinitionId}' from ledger`,
Expand All @@ -168,10 +283,7 @@ export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
}
}

public async registerRevocationRegistryDefinition(
agentContext: AgentContext,
options: RegisterRevocationRegistryDefinitionOptions
): Promise<RegisterRevocationRegistryDefinitionReturn> {
public async registerRevocationRegistryDefinition(): Promise<RegisterRevocationRegistryDefinitionReturn> {
return {
registrationMetadata: {},
revocationRegistryDefinitionMetadata: {},
Expand Down Expand Up @@ -223,10 +335,7 @@ export class IndyVdrProxyAnonCredsRegistry implements AnonCredsRegistry {
}
}

public async registerRevocationStatusList(
agentContext: AgentContext,
options: RegisterRevocationStatusListOptions
): Promise<RegisterRevocationStatusListReturn> {
public async registerRevocationStatusList(): Promise<RegisterRevocationStatusListReturn> {
return {
registrationMetadata: {},
revocationStatusListMetadata: {},
Expand Down
Loading

0 comments on commit 49b5a85

Please sign in to comment.