Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest)!: upgrade to credo 0.5 #256

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dcb0ad5
Upgrade rest package afj to 0.4.0
mattdean-digicatapult Jul 28, 2023
8fec3f0
Add proof request attribute/predicate restrictions
mattdean-digicatapult Jul 31, 2023
0418ab9
Configuration improvements
mattdean-digicatapult Jul 31, 2023
044d9da
cleanup CredentialDefinition controller
mattdean-digicatapult Aug 2, 2023
039948d
Changes from review
mattdean-digicatapult Aug 23, 2023
2e26389
Implement did create and import routes
mattdean-digicatapult Aug 23, 2023
973eaeb
Add did import and create
mattdean-digicatapult Sep 4, 2023
cb8a4f5
Merge branch 'main' into upgrade-afj-0-4-0
genaris Sep 28, 2023
19ab152
chore!: update to credo 0.5
TimoGlastra Feb 13, 2024
215d83f
disable node 16 for now
TimoGlastra Feb 13, 2024
ad54f51
Merge branch 'chore/update-050' into upgrade-afj-0-4-0
TimoGlastra Feb 13, 2024
30eaa00
fix: all type errors
TimoGlastra Feb 13, 2024
4f6a89f
temp
TimoGlastra Feb 13, 2024
b266a30
temp
TimoGlastra Feb 13, 2024
d131430
Merge remote-tracking branch 'upstream/main' into upgrade-afj-0-4-0
TimoGlastra Feb 14, 2024
a02caa4
Merge remote-tracking branch 'upstream/main' into upgrade-afj-0-4-0
TimoGlastra Mar 25, 2024
4361ec1
feat: updated to 0.5.0
TimoGlastra Mar 26, 2024
3b8fc1f
feat: multi-tenant support
TimoGlastra Mar 27, 2024
413c0e1
eslint fixes
TimoGlastra Mar 27, 2024
2a9ec56
cleanup
TimoGlastra Mar 27, 2024
0071487
address feedback
TimoGlastra Mar 27, 2024
3f26d51
feat: add docker image
TimoGlastra Mar 27, 2024
af9aaa4
build pr
TimoGlastra Mar 27, 2024
c1f77c9
changes
TimoGlastra Mar 27, 2024
5392cb0
Merge remote-tracking branch 'upstream/main' into feat/upgrade-rest-a…
TimoGlastra Mar 27, 2024
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
29 changes: 0 additions & 29 deletions .github/actions/setup-indy-pool/action.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/actions/setup-libindy/action.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ jobs:
- name: Checkout credo-ts-ext
uses: actions/checkout@v4

# Some packages need indy-sdk for node as part of yarn install
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup node v18
uses: actions/setup-node@v4
with:
Expand Down
25 changes: 2 additions & 23 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
push:
branches: [main, 'credo-**']

env:
TEST_AGENT_PUBLIC_DID_SEED: 000000000000000000000000Trustee9
GENESIS_TXN_PATH: network/genesis/local-genesis.txn

# Make sure we're not running multiple release steps at the same time as this can give issues with determining the next npm version to release.
# 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."
Expand Down Expand Up @@ -81,14 +77,6 @@ jobs:
- name: Checkout credo-ts-ext
uses: actions/checkout@v4

# setup dependencies
- name: Setup Libindy
uses: ./.github/actions/setup-libindy
- name: Setup Indy Pool
uses: ./.github/actions/setup-indy-pool
with:
seed: ${TEST_AGENT_PUBLIC_DID_SEED}

- name: Setup node ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand All @@ -99,17 +87,8 @@ jobs:
- name: Install dependencies
run: yarn install

- name: Run tests for Push notifications
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test push-notifications --coverage

- name: Run tests for React hooks
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test react-hooks --coverage

- name: Run tests for Redux store
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test redux-store --coverage

- name: Run tests for Rest
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test rest --coverage
- name: Run tests
run: yarn test --coverage

- uses: codecov/codecov-action@v1
if: always()
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ If you're just getting started the [Credo repo](https://github.com/openwallet-fo

All packages are placed in the [`packages/`](./packages) directory.

| Package | Version | Description |
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| [`@credo-ts/rest`](https://www.npmjs.com/package/@credo-ts/rest) | ![@credo-ts/rest version](https://img.shields.io/npm/v/@credo-ts/rest) | REST endpoint wrapper for using your agent over HTTP |
| [`@credo-ts/react-hooks`](https://www.npmjs.com/package/@credo-ts/react-hooks) | ![@credo-ts/react-hooks version](https://img.shields.io/npm/v/@credo-ts/react-hooks) | React Hooks for data handling and agent interaction |
| [`@credo-ts/redux-store`](https://www.npmjs.com/package/@credo-ts/redux-store) | ![@credo-ts/redux-store version](https://img.shields.io/npm/v/@credo-ts/redux-store) | Redux Toolkit wrapper around Credo |
| [`@credo-ts/push-notifications`](https://www.npmjs.com/package/@credo-ts/push-notifications) | ![@credo-ts/push-notifications version](https://img.shields.io/npm/v/@credo-ts/push-notifications) | Push notification plugin for Credo |
| [`@credo-ts/transport-ble`](https://www.npmjs.com/package/@credo-ts/transport-ble) | ![@credo-ts/transport-ble version](https://img.shields.io/npm/v/@credo-ts/transport-ble) | Bluetooth Low Energy transport for Credo |
| Package | Version | Description |
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| [`@credo-ts/rest`](https://www.npmjs.com/package/@credo-ts/rest) | ![@credo-ts/rest version](https://img.shields.io/npm/v/@credo-ts/rest) | Rest API for using Credo over HTTP |
| [`@credo-ts/react-hooks`](https://www.npmjs.com/package/@credo-ts/react-hooks) | ![@credo-ts/react-hooks version](https://img.shields.io/npm/v/@credo-ts/react-hooks) | React Hooks for data handling and agent interaction |
| [`@credo-ts/redux-store`](https://www.npmjs.com/package/@credo-ts/redux-store) | ![@credo-ts/redux-store version](https://img.shields.io/npm/v/@credo-ts/redux-store) | Redux Toolkit wrapper around Credo |
| [`@credo-ts/push-notifications`](https://www.npmjs.com/package/@credo-ts/push-notifications) | ![@credo-ts/push-notifications version](https://img.shields.io/npm/v/@credo-ts/push-notifications) | Push notification plugin for Credo |
| [`@credo-ts/transport-ble`](https://www.npmjs.com/package/@credo-ts/transport-ble) | ![@credo-ts/transport-ble version](https://img.shields.io/npm/v/@credo-ts/transport-ble) | Bluetooth Low Energy transport for Credo |

## Contributing

Expand Down
45 changes: 4 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,9 @@
"private": true,
"license": "Apache-2.0",
"description": "Monorepo containing extensions for Credo",
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"@credo-ts/*",
"**/@credo-ts/*",
"**/@credo-ts/*/**",
"@credo-ts/*/**",
"@aries-framework/*",
"**/@aries-framework/*",
"**/@aries-framework/*/**",
"@aries-framework/*/**",
"@hyperledger/*",
"**/@hyperledger/*",
"**/@hyperledger/*/**",
"@hyperledger/*/**",
"tsyringe",
"**/tsyringe",
"**/tsyringe/**",
"tsyringe/**",
"node-fetch",
"**/node-fetch",
"**/node-fetch/**",
"node-fetch/**",
"reflect-metadata",
"**/reflect-metadata",
"**/reflect-metadata/**",
"reflect-metadata/**",
"class-validator",
"**/class-validator",
"**/class-validator/**",
"class-validator/**",
"class-transformer",
"**/class-transformer",
"**/class-transformer/**",
"class-transformer/**"
]
},
"workspaces": [
"packages/*"
],
"repository": {
"url": "https://github.com/openwallet-foundation/credo-ts-ext",
"type": "git"
Expand Down Expand Up @@ -78,10 +42,9 @@
"rimraf": "^5.0.5"
},
"engines": {
"node": ">= 16"
"node": ">= 18"
},
"resolutions": {
"@types/indy-sdk": "1.16.9",
"@jest/types": "^29.5.0",
"@types/node": "^18.0.0"
}
Expand Down
30 changes: 1 addition & 29 deletions packages/rest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
FROM ubuntu:18.04 as base

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -y && apt-get install -y \
software-properties-common \
apt-transport-https \
curl \
# Only needed to build indy-sdk
build-essential

# libindy
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CE7709D068DB5E88
RUN add-apt-repository "deb https://repo.sovrin.org/sdk/deb bionic stable"

# nodejs
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash

# yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

# install depdencies
RUN apt-get update -y && apt-get install -y --allow-unauthenticated \
libindy \
nodejs

# Install yarn seperately due to `no-install-recommends` to skip nodejs install
RUN apt-get install -y --no-install-recommends yarn
FROM node:18 as base

# Credo specifc setup
WORKDIR /www
Expand Down
149 changes: 2 additions & 147 deletions packages/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,153 +32,8 @@ The Credo REST API is the most convenient way for self-sovereign identity (SSI)

- ⭐ **Endpoints** to create connections, issue credentials, and request proofs.
- 💻 **CLI** that makes it super easy to start an instance of the REST API.
- 🌐 **Interoperable** with all major Aries implementations.
- 🌐 **Interoperable** with all major Aries implementations and support for OpenID4VC.
TimoGlastra marked this conversation as resolved.
Show resolved Hide resolved

### Quick start

The REST API provides an OpenAPI schema that can easily be viewed using the SwaggerUI that is provided with the server. The docs can be viewed on the `/docs` endpoint (e.g. http://localhost:3000/docs).

> The OpenAPI spec is generated from the model classes used by Credo. Due to limitations in the inspection of these classes, the generated schema does not always exactly match the expected format. Keep this in mind when using this package. If you encounter any issues, feel free to open an issue.

#### Using the CLI

Using the CLI is the easiest way to get started with the REST API.

**With Docker (easiest)**

Make sure you have [Docker](https://docs.docker.com/get-docker/) installed. To get a minimal version of the agent running the following command is sufficient:

```sh
docker run -p 5000:5000 -p 3000:3000 ghcr.io/openwallet-foundation/credo-rest \
--label "Credo Rest" \
--wallet-id "walletId" \
--wallet-key "walletKey" \
--endpoint http://localhost:5000 \
--admin-port 3000 \
--outbound-transport http \
--inbound-transport http 5000
```

See the [docker-compose.yml](https://github.com/openwallet-foundation/credo-ts-ext/tree/main/docker-compose.yml) file for an example of using the credo-rest image with Docker Compose.

> ⚠️ The Docker image is not optimized for ARM architectures and won't work on Apple Silicon Macs. See the **Directly on Computer** below on how to run it directly on your computer without Docker.

**Directly on Computer**

To run Credo REST API directly on your computer you need to have the indy-sdk installed. Follow the Indy [installation steps](https://github.com/openwallet-foundation/credo-ts/tree/main/docs/libindy) for your platform and verify Indy is installed.

Once you have installed Indy, you can start the REST server using the following command:

```sh
npx -p @credo-ts/rest credo-rest start \
--label "Credo Rest" \
--wallet-id "walletId" \
--wallet-key "walletKey" \
--endpoint http://localhost:5000 \
--admin-port 3000 \
--outbound-transport http \
--inbound-transport http 5000
```

**Configuration**

To find out all available configuration options from the CLI, you can run the CLI command with `--help`. This will print a full list of all available options.

```sh
# With docker
docker run ghcr.io/openwallet-foundation/credo-rest --help

# Directly on computer
npx -p @credo-ts/rest credo-rest start --help
```

It is also possible to configure the REST API using a json config. When providing a lot of configuration options, this is definitely the easiest way to use configure the agent. All properties should use camelCase for the key names. See the example [CLI Config](https://github.com/openwallet-foundation/credo-ts-ext/tree/main/packages/rest/samples/cliConfig.json) for an detailed example.

```json
{
"label": "Credo Rest Agent",
"walletId": "walletId",
"walletKey": "walletKey"
// ... other config options ... //
}
```

As a final option it is possible to configure the agent using environment variables. All properties are prefixed by `CREDO_REST` transformed to UPPER_SNAKE_CASE.

```sh
# With docker
docker run -e CREDO_REST_WALLET_KEY=my-secret-key ghcr.io/hyperledger/credo-rest ...

# Directly on computer
CREDO_REST_WALLET_KEY="my-secret-key" npx -p @credo-ts/rest credo-rest start ...
```

#### Starting Own Server

Starting your own server is more involved than using the CLI, but allows more fine-grained control over the settings and allows you to extend the REST API with custom endpoints.

You can create an agent instance and import the `startServer` method from the `rest` package. That's all you have to do.

```ts
import { startServer } from '@credo-ts/rest'
import { Agent } from '@aries-framework/core'
import { agentDependencies } from '@aries-framework/node'

// The startServer function requires an initialized agent and a port.
// An example of how to setup an agent is located in the `samples` directory.
const run = async () => {
const agent = new Agent(
{
// ... Credo Config ... //
},
agentDependencies,
)
await startServer(agent, { port: 3000 })
}

// A Swagger (OpenAPI) definition is exposed on http://localhost:3000/docs
run()
```

### WebSocket & webhooks

The REST API provides the option to connect as a client and receive events emitted from your agent using WebSocket and webhooks.

You can hook into the events listener using webhooks, or connect a WebSocket client directly to the default server.

The currently supported events are:

- `Basic messages`
- `Connections`
- `Credentials`
- `Proofs`

When using the CLI, a webhook url can be specified using the `--webhook-url` config option.

When using the REST server as an library, the WebSocket server and webhook url can be configured in the `startServer` and `setupServer` methods.

```ts
// You can either call startServer() or setupServer() and pass the ServerConfig interface with a webhookUrl and/or a WebSocket server

const run = async (agent: Agent) => {
const config = {
port: 3000,
webhookUrl: 'http://test.com',
socketServer: new Server({ port: 8080 }),
}
await startServer(agent, config)
}
run()
```

The `startServer` method will create and start a WebSocket server on the default http port if no socketServer is provided, and will use the provided socketServer if available.

However, the `setupServer` method does not automatically create a socketServer, if one is not provided in the config options.

In case of an event, we will send the event to the webhookUrl with the topic of the event added to the url (http://test.com/{topic}).

So in this case when a connection event is triggered, it will be sent to: http://test.com/connections

The payload of the webhook contains the serialized record related to the topic of the event. For the `connections` topic this will be a `ConnectionRecord`, for the `credentials` topic it will be a `CredentialRecord`, and so on.

For the WebSocket clients, the events are sent as JSON stringified objects
See the [Credo REST API docs](https://credo.js.org/guides/extensions/rest) for installation instructions.
Loading
Loading