AnonCreds RS
AnonCreds RS is a direct implementation of the AnonCreds V1.0 specification that provides functionality like; creating a schema object, creating a credential definition object, creating a credential, verifying a proof presentation and much more.
Support for the AnonCreds RS library in Aries Framework JavaScript is currently experimental. We recommend new projects to use AnonCreds RS from the start, and also to migrate existing projects to AnonCreds, from the Indy Sdk. However, projects may experience some issues. If you encounter any issues, please open an issue.
Currently, there are few limitations to using AnonCreds RS.
- When running in Node.JS, only Node.JS 18 is supported for now. See Supported Node.JS versions for AnonCreds RS
- Install scripts rely on bash command substitution to get the proper binaries for each system architecture and platform. Therefore, if you are under Windows, you must configure
npm
oryarn
to use a bash-compliant shell (e.g.npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"
)
Installing AnonCreds RS
When using Aries Framework JavaScript with AnonCreds RS, there are a few extra dependencies that need to be installed. We need to install @hyperledger/anoncreds
package, which contains the interfaces, and @hyperledger/anoncreds-rs
package which is an implementation which depends on a wrapper of anoncreds-rs. Secondly, we need to add native bindings for the specific platform @hyperledger/anoncreds-<platform>
. Currently there are bindings for Node.JS, as @hyperledger/anoncreds-nodejs
, and React Native as @hyperlegder/anoncreds-react-native
.
- Node.JS
- React Native
yarn add @aries-framework/anoncreds@^0.4.0 @aries-framework/anoncreds-rs@^0.4.0 @hyperledger/anoncreds-nodejs@^0.1.0
yarn add @aries-framework/anoncreds@^0.4.0 @aries-framework/anoncreds-rs@^0.4.0 @hyperledger/anoncreds-react-native@^0.1.0
Adding AnonCreds RS to the agent
After installing the dependencies, we should register both the AnonCreds
and AnonCredsRs
module on the agent.
- Node.JS
- React Native
import { Agent } from '@aries-framework/core'
import { agentDependencies } from '@aries-framework/node'
import { AskarModule } from '@aries-framework/askar'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { anoncreds } from '@hyperledger/anoncreds-nodejs'
import { AnonCredsModule } from '@aries-framework/anoncreds'
import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs'
import { IndyVdrAnonCredsRegistry } from '@aries-framework/indy-vdr'
const agent = new Agent({
config,
dependencies: agentDependencies,
modules: {
// Register the Askar module on the agent
// This is included as we need a wallet on our agent
askar: new AskarModule({
ariesAskar,
}),
anoncredsRs: new AnonCredsRsModule({
anoncreds,
}),
anoncreds: new AnonCredsModule({
// Here we add an Indy VDR registry as an example, any AnonCreds registry
// can be used
registries: [new IndyVdrAnonCredsRegistry()],
}),
},
})
import { Agent } from '@aries-framework/core'
import { agentDependencies } from '@aries-framework/react-native'
import { AskarModule } from '@aries-framework/askar'
import { ariesAskar } from '@hyperledger/aries-askar-react-native'
import { anoncreds } from '@hyperledger/anoncreds-react-native'
import { AnonCredsModule } from '@aries-framework/anoncreds'
import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs'
import { IndyVdrAnonCredsRegistry } from '@aries-framework/indy-vdr'
const agent = new Agent({
config,
dependencies: agentDependencies,
modules: {
// Register the Askar module on the agent
// This is included as we need a wallet on our agent
askar: new AskarModule({
ariesAskar,
}),
anoncredsRs: new AnonCredsRsModule({
anoncreds,
}),
anoncreds: new AnonCredsModule({
// Here we add an Indy VDR registry as an example, any AnonCreds registry
// can be used
registries: [new IndyVdrAnonCredsRegistry()],
}),
},
})
Configuration
As you can see, the AnonCreds module takes a list of registry modules. These modules will be used to resolve the AnonCreds objects. We recommend Indy VDR as an AnonCreds registry for Hyperledger Indy networks, but Indy SDK can also be used.
Supported Node.JS versions for AnonCreds RS
Due to an issue in ref-napi
(which is used in the Node.JS bindings for AnonCreds RS), performance for AnonCreds RS in Node.JS is not as expected. A patched version for ref-napi
has been published that fixes this issue, but this only works in Node.JS 18+.
To use AnonCreds RS in Node.JS, make sure you're using Node.JS 18 and patch the ref-napi
package to point towards @2060.io/ref-napi
in your package.json
:
- NPM
- Yarn
Using NPM overrides
we can point the ref-napi
package to @2060.io/ref-napi
.
{
"overrides": {
"ref-napi": "npm:@2060.io/ref-napi"
}
}
Using Yarn resolutions
we can point the ref-napi
package to @2060.io/ref-napi
.
{
"resolutions": {
"ref-napi": "npm:@2060.io/ref-napi"
}
}
See the following issues for more information on the performance botleneck