Skip to content

Commit

Permalink
Commit to resolve merge conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek committed Apr 19, 2023
1 parent a7b0e83 commit 4362ce2
Show file tree
Hide file tree
Showing 42 changed files with 2,956 additions and 903 deletions.
8 changes: 3 additions & 5 deletions examples/simple-agent/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Agent Specific

BLOCKSTORE/
DATASTORE/
INDEX/
DATASTORE-*
INDEX-*
MESSAGESTORE-*
6 changes: 3 additions & 3 deletions examples/simple-agent/etc/did.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"content": {
"publicKeys": [
{
"id": "key-1",
"id": "dwn",
"type": "JsonWebKey2020",
"purposes": [
"authentication"
Expand Down Expand Up @@ -68,9 +68,9 @@
],
"keys": [
{
"id": "key-1",
"id": "dwn",
"type": "JsonWebKey2020",
"keypair": {
"keyPair": {
"publicJwk": {
"kty": "EC",
"crv": "secp256k1",
Expand Down
14 changes: 10 additions & 4 deletions examples/simple-agent/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ router.post('/dwn', async (ctx, _next) => {
try {
const response = await receiveHttp(ctx);

// Normalize DWN MessageReply and HTTP Reponse
ctx.status = response?.status?.code ?? response?.status;
ctx.statusText = response?.status?.detail ?? response?.statusText;
ctx.body = 'entries' in response ? { entries: response.entries } : response.body;
console.log('SIMPLE AGENT receiveHTTP response:', response);

// // All DWN MessageReply responses contain a `status` object.
// // DWN RecordsQuery responses contain an `entries` array of query results.
// // DWN RecordsRead responses contain a data property which is a Readable stream.
// const { message, ...retainedResponse } = response;

// ctx.body = retainedResponse;
// ctx.status = retainedResponse?.status?.code;
// ctx.statusText = retainedResponse?.status?.detail;
}
catch(err) {
console.error(err);
Expand Down
21 changes: 15 additions & 6 deletions examples/simple-agent/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import getRawBody from 'raw-body';
import { DataStoreLevel, Dwn, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js';
import { Web5 } from '@tbd54566975/web5';
import fs from 'node:fs';
import mkdirp from 'mkdirp';
import { createRequire } from 'node:module';

const web5 = new Web5();
// Use custom names for the block, message, and data stores to make it possible to launch multiple simple agents
// in the same directory. If you don't do this, you will get LevelDB lock errors.
const port = await getPort(process.argv);
const dataStore = new DataStoreLevel({ blockstoreLocation: `DATASTORE-${port}` });
const messageStore = new MessageStoreLevel({
blockstoreLocation : `MESSAGESTORE-${port}`,
indexLocation : `INDEX-${port}`,
});

const dwnNode = await Dwn.create({ messageStore, dataStore });

const web5 = new Web5({ dwn: { node: dwnNode }});

const etcPath = './etc';
const didStoragePath = `${etcPath}/did.json`;
Expand Down Expand Up @@ -42,11 +54,10 @@ async function loadConfig() {
didState = await initOperatorDid();
fs.writeFileSync(didStoragePath, JSON.stringify(didState, null, 2));
}
web5.did.register({
web5.did.manager.set(didState.id, {
connected: true,
did: didState.id,
endpoint: 'app://dwn',
keys: didState.keys[0].keypair,
keys: didState.keys['#dwn'].keyPair,
});
}

Expand Down Expand Up @@ -99,8 +110,6 @@ async function receiveHttp(ctx) {

const data = await getRawBody(ctx.req);

console.log('TRACE - receiveHttp() - message:', message);

return await web5.send(target, {
author,
data,
Expand Down
Loading

0 comments on commit 4362ce2

Please sign in to comment.