Hedera
Hedera is an open public network governed by leading organizations worldwide. Hedera uses revolutionary consensus technology based on hashgraph to support decentralized applications — all without compromising speed, efficiency, and security. The consensus is leaderless, meaning no single node controls the transaction order, which reduces the risk of a single point of failure and attacks. The codebase is managed by the Linux Foundation Decentralized Trust (LF Decentralized Trust) under the Hiero project, which provides vendor-independent code governance and peace of mind for developers.
Hedera is a large and trusted network and a great option for Self-Sovereign Identity (SSI), providing high performance and low costs of operations. In particular, Hedera can be used as Verifiable Data Registry (VDR) for Hedera DID Method and AnonCreds Verifiable Credentials by leveraging Hedera Consensus Service (HCS).
Details on Hedera AnonCreds VDR implementation approach can be found in Hiero AnonCreds Method.
Installing Hedera
To use Credo with Hedera, you need to install several additional dependencies. Specifically, the package @credo-ts/hedera must be installed, which implements the necessary interfaces for the agent. The @credo-ts/hedera package depends on a set of third-party packages from the @hiero-did-sdk-js family, which provide direct interaction with the Hedera network. Additionally, for proper functionality, you need to install extra libraries compatible with your chosen framework to support these dependencies.
Node
To use Hedera Credo module in Node environment, you need to install the ZSTD package.
- NPM
- Yarn
- PNPM
npm install zstd-napi
yarn add zstd-napi
pnpm install zstd-napi
React Native
To use Hedera Credo module in React Native environment, please make sure that your app has enabled support for package exports and optional dependencies (enabled in default config, but worth mentioning).
First, you need to install the ZSTD and crypto packages.
- NPM
- Yarn
- PNPM
npm install react-native-zstd
# If you're using React Native version prior to 0.74, please use the following Git dependency
# npm install react-native-zstd@git+https://github.com/DSRCorporation/react-native-zstd#react-native-0.73
npm install react-native-quick-crypto
npm install buffer
yarn add react-native-zstd
# If you're using React Native version prior to 0.74, please use the following Git dependency
# yarn add react-native-zstd@git+https://github.com/DSRCorporation/react-native-zstd#react-native-0.73
yarn add react-native-quick-crypto
yarn add buffer
pnpm install react-native-zstd
# If you're using React Native version prior to 0.74, please use the following Git dependency
# pnpm install react-native-zstd@git+https://github.com/DSRCorporation/react-native-zstd#react-native-0.73
pnpm install react-native-quick-crypto
pnpm install buffer
Following that we need to add a buffer polyfill. Create a shim.js file with the below code snippet
import { Buffer } from 'buffer'
global.Buffer = Buffer
Import shim.js file into your file where the App is imported
Adding the Hedera to the Agent
After installing the dependencies, we can register the Hedera Module on the agent by adding the below code snippet to the agent constructor.
import { Agent, DidDocument, DidDocumentService, DidsModule, KeyType } from '@credo-ts/core'
import { AskarModule } from '@credo-ts/askar'
import { AnonCredsModule } from '@credo-ts/anoncreds'
/* Should be used for Node */
import { agentDependencies } from '@credo-ts/node'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { anoncreds } from '@hyperledger/anoncreds-nodejs'
/* Should be used for ReactNative */
// import { agentDependencies } from '@credo-ts/react-native'
// import { askar } from '@openwallet-foundation/askar-react-native'
// import { anoncreds } from '@hyperledger/anoncreds-react-native'
import {
HederaAnonCredsRegistry,
HederaDidRegistrar,
HederaDidResolver,
HederaDidCreateOptions,
HederaModule,
} from '@credo-ts/hedera'
const agent = new Agent({
config: {
label: 'docs-agent',
},
dependencies: agentDependencies,
modules: {
// Dids
dids: new DidsModule({
registrars: [new HederaDidRegistrar()],
resolvers: [new HederaDidResolver()],
}),
// AnonCreds
anoncreds: new AnonCredsModule({
registries: [new HederaAnonCredsRegistry()],
anoncreds,
}),
// Add hedera module
hedera: new HederaModule({
networks: [
{
network: 'testnet', // '<mainnet or testnet or previewnet or local-node>'
operatorId: '<your operator ID on the Hedera network>',
operatorKey: '<your operator Key on the Hedera network in the DER format>',
},
],
}),
askar: new AskarModule({
ariesAskar,
}),
},
})
HederaModule allows you to use multiple networks simultaneously. It also supports both standard and custom networks built on top of Hedera. These network settings can be specified in the configuration. For more detailed information, you can refer to the client guide documentation available from the Hiero DID SDK JS project.