Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed May 2, 2024
2 parents 0770ff1 + 3abb717 commit 17f1b8b
Show file tree
Hide file tree
Showing 55 changed files with 2,264 additions and 302 deletions.
9 changes: 0 additions & 9 deletions .changeset/green-olive-goblin.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/olive-geese-melt.md

This file was deleted.

14 changes: 14 additions & 0 deletions .changeset/proud-bottles-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@web5/agent": patch
"@web5/identity-agent": patch
"@web5/proxy-agent": patch
"@web5/user-agent": patch
---

Extend and Test RPC DWN/Web5 Clients to support `http` and `ws`
- move `HttpDwnRpcClient` to `/prototyping` folder
- move `JSON RPC` related files to `/prototyping` folder
- create `WebSocketDwnRpcClient` in `/prototyping` folder
- create `WebSocketWeb5RpcClient` wrapper in `rpc-client`
- does not support `sendDidRequest` via sockets

5 changes: 5 additions & 0 deletions .changeset/shy-fireants-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web5/dids": patch
---

chore: bump ion
5 changes: 5 additions & 0 deletions .changeset/two-moons-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web5/dids": patch
---

DID:DHT - Only have <ID>. suffix for Root and Gateway Record names
2 changes: 1 addition & 1 deletion .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
report_changed_scope_only: false
fail_on_error: false
fail_on_error: true
group_docs: true
entry_points: |
- file: packages/api/src/index.ts
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ jobs:
- group: "A"
packages: "--filter agent"
- group: "B"
packages: "--filter credentials ----filter dids --filter identity-agent"
packages: "--filter dids --filter identity-agent"
- group: "C"
packages: "--filter api --filter common"
packages: "--filter api"
- group: "D"
packages: "--filter crypto --filter proxy-agent --filter user-agent"
packages: "--filter crypto"
- group: "E"
packages: "--filter common --filter credentials --filter proxy-agent --filter user-agent"
steps:
- name: Checkout source
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
Expand Down
14 changes: 7 additions & 7 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The format is described: https://github.blog/2017-07-06-introducing-code-owners/

# These owners will be the default owners for everything in the repo.
* @frankhinek @csuwildcat @mistermoe
* @frankhinek @csuwildcat @mistermoe @thehenrytsai

# These are owners of any file in the `common`, `crypto`, `crypto-aws-kms`, `dids`, and
# `credentials` packages and their sub-directories.
Expand All @@ -18,9 +18,9 @@

# These are owners of any file in the `agent`, `user-agent`, `proxy-agent`, `identity-agent`, and
# `api` packages and their sub-directories.
/packages/agent @lirancohen @frankhinek @csuwildcat @mistermoe
/packages/proxy-agent @lirancohen @frankhinek @csuwildcat @mistermoe
/packages/user-agent @lirancohen @frankhinek @csuwildcat @mistermoe
/packages/identity-agent @lirancohen @frankhinek @csuwildcat @mistermoe
/packages/api @lirancohen @frankhinek @csuwildcat @mistermoe

/packages/agent @lirancohen @frankhinek @csuwildcat @mistermoe @shamilovtim
/packages/proxy-agent @lirancohen @frankhinek @csuwildcat @mistermoe @shamilovtim
/packages/user-agent @lirancohen @frankhinek @csuwildcat @mistermoe @shamilovtim
/packages/identity-agent @lirancohen @frankhinek @csuwildcat @mistermoe @shamilovtim
/packages/api @lirancohen @frankhinek @csuwildcat @mistermoe @shamilovtim

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@changesets/cli": "^2.27.1",
"@npmcli/package-json": "5.0.0",
"@typescript-eslint/eslint-plugin": "6.4.0",
"@web5/dwn-server": "0.1.16",
"@web5/dwn-server": "0.2.1",
"eslint-plugin-mocha": "10.1.0",
"npkill": "0.11.3"
},
Expand Down
19 changes: 19 additions & 0 deletions packages/agent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @web5/agent

## 0.3.2

### Patch Changes

- [#500](https://github.com/TBD54566975/web5-js/pull/500) [`41ac378`](https://github.com/TBD54566975/web5-js/commit/41ac378a0197e56aeb70cf2d80d6b3917d4c1490) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Upgrade DWN SDK with newest features

- remove `Permissions` interface and replace permissions with a first-class protocol representing it
- adding `RecordsTags` functionality

## 0.3.1

### Patch Changes

- [#484](https://github.com/TBD54566975/web5-js/pull/484) [`c47ea5e`](https://github.com/TBD54566975/web5-js/commit/c47ea5ee936c9164c6ead47caf1ad099c1a4b0f1) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Upgrade `dwn-sdk-js` to the latest version consuming `1.0.0` of `@web5/dids`

- [#482](https://github.com/TBD54566975/web5-js/pull/482) [`ddb38d0`](https://github.com/TBD54566975/web5-js/commit/ddb38d0da0c510e9af00afddffe228c22cb830cd) Thanks [@LiranCohen](https://github.com/LiranCohen)! - - Upgrade packages to consume `1.0.0` of foundational `web5` packages.
- Using foundational `dids` package instead
7 changes: 4 additions & 3 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web5/agent",
"version": "0.3.0",
"version": "0.3.2",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -71,12 +71,13 @@
"dependencies": {
"@noble/ciphers": "0.4.1",
"@scure/bip39": "1.2.2",
"@tbd54566975/dwn-sdk-js": "0.2.21",
"@tbd54566975/dwn-sdk-js": "0.3.1",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.0.0",
"@web5/dids": "1.0.1",
"abstract-level": "1.0.4",
"ed25519-keygen": "0.4.11",
"isomorphic-ws": "^5.0.0",
"level": "8.0.0",
"ms": "2.1.3",
"readable-web-to-node-stream": "3.0.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export * from './did-api.js';
export * from './dwn-api.js';
export * from './hd-identity-vault.js';
export * from './identity-api.js';
export * from './json-rpc.js';
export * from './local-key-manager.js';
export * from './rpc-client.js';
export * from './store-data.js';
Expand All @@ -22,4 +21,4 @@ export * from './store-key.js';
export * from './sync-api.js';
export * from './sync-engine-level.js';
export * from './test-harness.js';
export * from './utils.js';
export * from './utils.js';
55 changes: 55 additions & 0 deletions packages/agent/src/prototyping/clients/dwn-rpc-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { MessageEvent, RecordsReadReply, UnionMessageReply } from '@tbd54566975/dwn-sdk-js';

export interface SerializableDwnMessage {
toJSON(): string;
}

export type DwnEventSubscriptionHandler = (event: MessageEvent) => void;

/**
* Interface for communicating with {@link https://github.com/TBD54566975/dwn-server | DWN Servers}
* via JSON-RPC, supporting operations like sending DWN requests.
*/
export interface DwnRpc {
/**
* Lists the transport protocols supported by the DWN RPC client, such as HTTP or HTTPS.
* @returns An array of strings representing the supported transport protocols.
*/
get transportProtocols(): string[]

/**
* Sends a request to a DWN Server using the specified DWN RPC request parameters.
*
* @param request - The DWN RPC request containing the URL, target DID, message, and optional data.
* @returns A promise that resolves to the response from the DWN server.
*/
sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse>
}


/**
* Represents a JSON RPC request to a DWN server, including the URL, target DID, the message to be
* processed, and optional data.
*/
export type DwnRpcRequest = {
/** Optional data to be sent with the request. */
data?: any;

/** The URL of the DWN server to which the request is sent. */
dwnUrl: string;

/** The message to be processed by the DWN server, which can be a serializable DWN message. */
message: SerializableDwnMessage | any;

/** The DID of the target to which the message is addressed. */
targetDid: string;

/** Optional subscription handler for DWN events. */
subscriptionHandler?: DwnEventSubscriptionHandler;
}

/**
* Represents the JSON RPC response from a DWN server to a request, combining the results of various
* DWN operations.
*/
export type DwnRpcResponse = UnionMessageReply & RecordsReadReply;
68 changes: 68 additions & 0 deletions packages/agent/src/prototyping/clients/http-dwn-rpc-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { JsonRpcResponse } from './json-rpc.js';
import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './dwn-rpc-types.js';

import { createJsonRpcRequest, parseJson } from './json-rpc.js';
import { utils as cryptoUtils } from '@web5/crypto';

/**
* HTTP client that can be used to communicate with Dwn Servers
*/
export class HttpDwnRpcClient implements DwnRpc {
get transportProtocols() { return ['http:', 'https:']; }

async sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse> {
const requestId = cryptoUtils.randomUuid();
const jsonRpcRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', {
target : request.targetDid,
message : request.message
});

const fetchOpts = {
method : 'POST',
headers : {
'dwn-request': JSON.stringify(jsonRpcRequest)
}
};

if (request.data) {
// @ts-expect-error TODO: REMOVE
fetchOpts.headers['content-type'] = 'application/octet-stream';
// @ts-expect-error TODO: REMOVE
fetchOpts['body'] = request.data;
}

const resp = await fetch(request.dwnUrl, fetchOpts);
let dwnRpcResponse: JsonRpcResponse;

// check to see if response is in header first. if it is, that means the response is a ReadableStream
let dataStream;
const { headers } = resp;
if (headers.has('dwn-response')) {
// @ts-expect-error TODO: REMOVE
const jsonRpcResponse = parseJson(headers.get('dwn-response')) as JsonRpcResponse;

if (jsonRpcResponse == null) {
throw new Error(`failed to parse json rpc response. dwn url: ${request.dwnUrl}`);
}

dataStream = resp.body;
dwnRpcResponse = jsonRpcResponse;
} else {
// TODO: wonder if i need to try/catch this?
const responseBody = await resp.text();
dwnRpcResponse = JSON.parse(responseBody);
}

if (dwnRpcResponse.error) {
const { code, message } = dwnRpcResponse.error;
throw new Error(`(${code}) - ${message}`);
}

const { reply } = dwnRpcResponse.result;
if (dataStream) {
reply['record']['data'] = dataStream;
}

return reply as DwnRpcResponse;
}
}
Loading

0 comments on commit 17f1b8b

Please sign in to comment.