generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,264 additions
and
302 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@web5/dids": patch | ||
--- | ||
|
||
chore: bump ion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
68
packages/agent/src/prototyping/clients/http-dwn-rpc-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.