Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ yarn-error.log*
didcomm-pkg
generated-docs
*.commit

tsconfig.*.tsbuildinfo
# Environment variables
.env
.env.local
Expand Down
105 changes: 105 additions & 0 deletions docs/develop/sdk/react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# React

The `@hyperledger/identus-react` package provides a suite of React context providers and hooks designed to seamlessly integrate the `@hyperledger/identus-sdk` into your React applications. By abstracting the complexities of agent lifecycle management, database connections, and asynchronous operations, this package allows you to focus on building your wallet or decentralized identity (DID) application.

## Installation

Install the React SDK package along with its peer dependencies:

```bash
npm install @hyperledger/identus-react @hyperledger/identus-sdk react react-dom
# or
yarn add @hyperledger/identus-react @hyperledger/identus-sdk react react-dom
```

## Architecture Concepts

The package uses a robust Provider pattern to manage state and connections across your application:
- **Providers**: Wrap your component tree to manage long-lived connections (e.g., `DatabaseProvider`, `AgentProvider`).
- **Contexts**: Maintain shared state for underlying SDK entities.
- **Hooks**: Provide clean, typed access to contexts (e.g., `useAgent`, `usePrismDID`) to execute identity operations directly within your components.

## Setup & Providers

To use the hooks, you first need to wrap your application in the appropriate providers. Providers handle the initialization and lifecycle of underlying SDK services.

### Core Providers

Here is an example setup initializing the core database and agent providers:

```tsx
import React, { useEffect } from 'react';
import { DatabaseProvider, AgentProvider, useDatabase, useAgent } from '@hyperledger/identus-react';
import { StorageType } from '@hyperledger/identus-sdk';

// A child component utilizing the providers
const AppContent = () => {
const { start: startDb, state: dbState } = useDatabase();
const { start: startAgent, state: agentState } = useAgent();

useEffect(() => {
// Initialize the local database
startDb({
name: 'my-identus-database',
storageType: StorageType.IndexDB
}).then(() => {
// Once the DB is ready, start the agent
startAgent();
});
}, [startDb, startAgent]);

return (
<div>
<p>Database State: {dbState}</p>
<p>Agent State: {agentState}</p>
</div>
);
};

// Application Root
const App = () => {
return (
<DatabaseProvider>
<AgentProvider>
{/* Other specialized providers like CredentialsProvider, ConnectionsProvider can be nested here */}
<AppContent />
</AgentProvider>
</DatabaseProvider>
);
};

export default App;
```

## Available Hooks

The SDK exposes specific hooks to manage DIDs, credentials, messaging, and connections. Each hook requires its corresponding provider (or a higher-level provider like `AgentProvider` or `DatabaseProvider`) to be present in the component tree.

### Connection & Agent Management
- **`useDatabase()`**: Access local database operations (Pluto), initialize storage, and manage global settings.
- **`useAgent()`**: Manage the active DIDComm agent's lifecycle (`start`, `stop`) and access its instance.
- **`useConnections()`**: Access and manage established peer-to-peer (DIDComm) connections.
- **`useMessages()`**: Access the message inbox, fetch unread messages, and mark messages as read.

### DID Management
- **`usePrismDID()`**: Create and manage long-lived, blockchain-anchored Prism DIDs.
- **`usePeerDID()`**: Quickly generate ephemeral Peer DIDs for direct, off-ledger communication.
- **`useCastor()`**: Access the underlying Castor service for advanced DID operations and resolution.

### Credential Issuance & Verification
- **`useCredentials()`**: Retrieve, organize, and delete stored Verifiable Credentials from the local wallet.
- **`useIssuer()`**: Expose operations for issuing credentials. Create Out-of-Band (OOB) offers and issue credentials directly to holders.
- **`useHolder()`**: Manage incoming credential offers and requests. Parse OOB messages, accept credential offers, and automatically handle presentation requests.
- **`useVerifier()`**: Issue presentation requests and verify incoming credential presentations.

## Configuration & Resolvers

The package provides utility configurations to simplify connecting to external services.
For example, you can create a custom DID resolver to interact with your specific node infrastructure:

```ts
import { createResolver } from '@hyperledger/identus-react/resolver';

// Produce a custom Prism DID resolver compatible with Castor
const MyCustomResolver = createResolver('https://my-node.example.com/prism-agent/dids');
```
2 changes: 1 addition & 1 deletion docs/develop/sdk/storage/default-store.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- sidebar_position: 2 -->

# Default Store (RIDB)
# Default Store

The SDK ships with a ready-to-use store backed by [RIDB](https://www.npmjs.com/package/@trust0/ridb) — a TypeScript-first reactive database that supports encryption, schema migrations, and pluggable storage backends.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/sdk/_category_.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"label": "TS SDK",
"position": 5,
"position": 1,
"collapsed": true,
"collapsible": true,
"link": {
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/sdk/overview/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"label": "Overview",
"position": 1,
"collapsed": true,
"collapsible": true,
"link": {
"type": "doc",
"id": "sdk-ts/docs/sdk/overview/README.md"
}
}
10 changes: 10 additions & 0 deletions docs/reference/sdk/plugins/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"label": "Plugins",
"position": 2,
"collapsed": true,
"collapsible": true,
"link": {
"type": "generated-index",
"title": "Plugins"
}
}
10 changes: 10 additions & 0 deletions docs/reference/sdk/react/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"label": "React",
"position": 3,
"collapsed": true,
"collapsible": true,
"link": {
"type": "doc",
"id": "sdk-ts/docs/react/README.md"
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"vitest": "^3.1.1"
},
"dependencies": {
"@trust0/identus-store": "^2.0.0",
"multiformats": "^13.4.2"
},
"peerDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/lib/protos/tsconfig.lib.tsbuildinfo

This file was deleted.

15 changes: 15 additions & 0 deletions packages/lib/react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- title: React -->
<!-- sidebar_label: React -->
<!-- sidebar_position: 3 -->

You can install the SDK with npm, yarn, etc.

```sh
npm i @hyperledger/identus-react --save

```

Or using yarn:
```sh
yarn add @hyperledger/identus-react
```
3 changes: 3 additions & 0 deletions packages/lib/react/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "../../../eslint.config.mjs";

export default config;
61 changes: 61 additions & 0 deletions packages/lib/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@hyperledger/identus-react",
"version": "0.0.0",
"description": "Identus SDK - React hooks and wrappers",
"type": "module",
"main": "./build/index.cjs",
"module": "./build/index.js",
"exports": {
".": {
"types": "./build/index.d.ts",
"import": "./build/index.js",
"require": "./build/index.cjs",
"default": "./build/index.js"
}
},
"types": "./build/index.d.ts",
"files": [
"build/**/*",
"README.MD",
"preinstall.sh",
"postinstall.sh",
"patches/*.patch"
],
"browserslist": [
"last 2 chrome version",
"last 2 firefox version",
"last 2 safari version",
"last 2 edge version"
],
"scripts": {
"prepare": "npx husky",
"lint": "npx eslint ."
},
"author": "IOHK",
"repository": {
"type": "git",
"url": "https://github.com/hyperledger-identus/sdk-ts.git"
},
"license": "Apache-2.0",
"keywords": [],
"devDependencies": {
"@hyperledger/identus-sdk": "workspace:*",
"@testing-library/dom": "^10.4.1",
"@testing-library/react": "^16",
"@types/react": "^18",
"@types/react-dom": "^18",
"react": "^18",
"react-dom": "^18"
},
"dependencies": {
"multiformats": "^9.9.0",
"react": "^18",
"react-dom": "^18",
"uuid": "^11.1.0"
},
"peerDependencies": {
"@hyperledger/identus-sdk": "workspace:*",
"react": "^18",
"react-dom": "^18"
}
}
72 changes: 72 additions & 0 deletions packages/lib/react/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"projectType": "library",
"implicitDependencies": [
"@hyperledger/identus-domain",
"@hyperledger/identus-didcomm",
"@hyperledger/identus-anoncreds",
"@hyperledger/identus-jwe",
"@hyperledger/identus-protos"
],
"tags": [
"scope:building-block"
],
"targets": {
"build": {
"dependsOn": [
"^build"
],
"executor": "nx:run-commands",
"outputs": [
"{projectRoot}/build"
],
"options": {
"commands": [
"rm -rf build/*",
"tsup --config tsup.config.ts --format esm,cjs",
"tsup --config tsup.types.config.ts --dts-only"
],
"cwd": "{projectRoot}",
"parallel": false
}
},
"test": {
"executor": "nx:run-commands",
"options": {
"command": "vitest --config=vitest.config.js --run",
"cwd": "{projectRoot}"
}
},
"test-watch": {
"executor": "nx:run-commands",
"options": {
"command": "vitest watch --config=vitest.config.js",
"cwd": "{projectRoot}"
}
},
"coverage": {
"dependsOn": [],
"executor": "nx:run-commands",
"options": {
"command": "vitest --config=vitest.config.js --run --coverage",
"cwd": "{projectRoot}"
}
},
"lint": {
"executor": "nx:run-commands",
"options": {
"command": "eslint .",
"cwd": "{projectRoot}"
}
},
"docs": {
"executor": "nx:run-commands",
"outputs": [
"{workspaceRoot}/docs/sdk"
],
"options": {
"command": "typedoc --options typedoc.js --out ../../../docs/react",
"cwd": "{projectRoot}"
}
}
}
}
5 changes: 5 additions & 0 deletions packages/lib/react/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const PRISM_RESOLVER_URL_KEY = "prism-resolver-url";
export const BLOCKFROST_KEY_NAME = "blockfrost-key";
export const WALLET_NAME = "wallet-name";
export const MEDIATOR_DID = "mediator";
export const FEATURES = 'enabled-features';
Loading
Loading