diff --git a/examples/node/stream-data.js b/examples/node/stream-data.js index 194e5ab..fb6bf00 100644 --- a/examples/node/stream-data.js +++ b/examples/node/stream-data.js @@ -1,16 +1,15 @@ -import { RecordsRead } from '@tbd54566975/dwn-sdk-js'; +import { RecordsRead, DidKeyResolver } from '@tbd54566975/dwn-sdk-js'; import fetch from 'node-fetch'; import { v4 as uuidv4 } from 'uuid'; import { createJsonRpcRequest } from '../../dist/src/lib/json-rpc.js'; import { - createProfile, createRecordsWriteMessage, getFileAsReadStream, } from '../../dist/tests/utils.js'; -const alice = await createProfile(); +const alice = await DidKeyResolver(); const { stream, size, cid } = await getFileAsReadStream('fixtures/test.jpeg'); const { recordsWrite } = await createRecordsWriteMessage(alice, { dataCid: cid, diff --git a/package-lock.json b/package-lock.json index d135190..75bffa6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "@web5/dwn-server", "version": "0.1.8", "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.2.9", + "@tbd54566975/dwn-sdk-js": "0.2.10", "@tbd54566975/dwn-sql-store": "0.2.5", "better-sqlite3": "^8.5.0", "bytes": "3.1.2", @@ -828,9 +828,9 @@ "dev": true }, "node_modules/@tbd54566975/dwn-sdk-js": { - "version": "0.2.9", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.2.9.tgz", - "integrity": "sha512-p9wv0GrNq0BgUMvlS54osLKAZE/WhTV89Oh0nvGUk9NH5iwvswlbG4aygw4vDqdVo7XruzfGienW0X/eNWZL0g==", + "version": "0.2.10", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.2.10.tgz", + "integrity": "sha512-CoKO8+NciwWNzD4xRoAAgeElqQCXKM4Fc+zEHsUWD0M3E9v67hRWiTHI6AenUfQv1RSEB2H4GHUeUOHuEV72uw==", "dependencies": { "@ipld/dag-cbor": "9.0.3", "@js-temporal/polyfill": "0.4.4", @@ -896,6 +896,78 @@ "npm": ">=7.0.0" } }, + "node_modules/@tbd54566975/dwn-sql-store/node_modules/@tbd54566975/dwn-sdk-js": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.2.9.tgz", + "integrity": "sha512-p9wv0GrNq0BgUMvlS54osLKAZE/WhTV89Oh0nvGUk9NH5iwvswlbG4aygw4vDqdVo7XruzfGienW0X/eNWZL0g==", + "dependencies": { + "@ipld/dag-cbor": "9.0.3", + "@js-temporal/polyfill": "0.4.4", + "@noble/ed25519": "2.0.0", + "@noble/secp256k1": "2.0.0", + "abstract-level": "1.0.3", + "ajv": "8.12.0", + "blockstore-core": "4.2.0", + "cross-fetch": "4.0.0", + "eciesjs": "0.4.5", + "interface-blockstore": "5.2.3", + "interface-store": "5.1.2", + "ipfs-unixfs-exporter": "13.1.5", + "ipfs-unixfs-importer": "15.1.5", + "level": "8.0.0", + "lodash": "4.17.21", + "lru-cache": "9.1.2", + "ms": "2.1.3", + "multiformats": "11.0.2", + "randombytes": "2.1.0", + "readable-stream": "4.4.2", + "ulidx": "2.1.0", + "uuid": "8.3.2", + "varint": "6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@tbd54566975/dwn-sql-store/node_modules/@tbd54566975/dwn-sdk-js/node_modules/@ipld/dag-cbor": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-9.0.3.tgz", + "integrity": "sha512-A2UFccS0+sARK9xwXiVZIaWbLbPxLGP3UZOjBeOMWfDY04SXi8h1+t4rHBzOlKYF/yWNm3RbFLyclWO7hZcy4g==", + "dependencies": { + "cborg": "^2.0.1", + "multiformats": "^12.0.1" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@tbd54566975/dwn-sql-store/node_modules/@tbd54566975/dwn-sdk-js/node_modules/@ipld/dag-cbor/node_modules/multiformats": { + "version": "12.1.3", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.1.3.tgz", + "integrity": "sha512-eajQ/ZH7qXZQR2AgtfpmSMizQzmyYVmCql7pdhldPuYQi4atACekbJaQplk6dWyIi10jCaFnd6pqvcEFXjbaJw==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@tbd54566975/dwn-sql-store/node_modules/@tbd54566975/dwn-sdk-js/node_modules/cborg": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/cborg/-/cborg-2.0.5.tgz", + "integrity": "sha512-xVW1rSIw1ZXbkwl2XhJ7o/jAv0vnVoQv/QlfQxV8a7V5PlA4UU/AcIiXqmpyybwNWy/GPQU1m/aBVNIWr7/T0w==", + "bin": { + "cborg": "cli.js" + } + }, + "node_modules/@tbd54566975/dwn-sql-store/node_modules/@tbd54566975/dwn-sdk-js/node_modules/multiformats": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", + "integrity": "sha512-b5mYMkOkARIuVZCpvijFj9a6m5wMVLC7cf/jIPd5D/ARDOfLC5+IFkbgDXQgcU2goIsTD/O9NY4DI/Mt4OGvlg==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, "node_modules/@tbd54566975/dwn-sql-store/node_modules/cborg": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/cborg/-/cborg-4.0.5.tgz", @@ -913,6 +985,14 @@ "npm": ">=7.0.0" } }, + "node_modules/@tbd54566975/dwn-sql-store/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@tootallnate/quickjs-emscripten": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", diff --git a/package.json b/package.json index db8d108..6cff1e2 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "url": "https://github.com/TBD54566975/dwn-server/issues" }, "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.2.9", + "@tbd54566975/dwn-sdk-js": "0.2.10", "@tbd54566975/dwn-sql-store": "0.2.5", "better-sqlite3": "^8.5.0", "bytes": "3.1.2", diff --git a/tests/dwn-process-message.spec.ts b/tests/dwn-process-message.spec.ts index e6da39e..d85f53f 100644 --- a/tests/dwn-process-message.spec.ts +++ b/tests/dwn-process-message.spec.ts @@ -1,3 +1,5 @@ +import { DidKeyResolver } from '@tbd54566975/dwn-sdk-js'; + import { expect } from 'chai'; import { v4 as uuidv4 } from 'uuid'; @@ -5,7 +7,7 @@ import { handleDwnProcessMessage } from '../src/json-rpc-handlers/dwn/process-me import type { RequestContext } from '../src/lib/json-rpc-router.js'; import { createJsonRpcRequest } from '../src/lib/json-rpc.js'; import { clear as clearDwn, dwn } from './test-dwn.js'; -import { createProfile, createRecordsWriteMessage } from './utils.js'; +import { createRecordsWriteMessage } from './utils.js'; describe('handleDwnProcessMessage', function () { afterEach(async function () { @@ -13,7 +15,7 @@ describe('handleDwnProcessMessage', function () { }); it('returns a JSON RPC Success Response when DWN returns a 2XX status code', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); // Construct a well-formed DWN Request that will be successfully processed. const { recordsWrite, dataStream } = await createRecordsWriteMessage(alice); diff --git a/tests/http-api.spec.ts b/tests/http-api.spec.ts index b9e878f..ba18731 100644 --- a/tests/http-api.spec.ts +++ b/tests/http-api.spec.ts @@ -2,6 +2,7 @@ import { Cid, DataStream, + DidKeyResolver, RecordsQuery, RecordsRead, } from '@tbd54566975/dwn-sdk-js'; @@ -24,7 +25,6 @@ import { } from '../src/lib/json-rpc.js'; import { clear as clearDwn, dwn } from './test-dwn.js'; import { - createProfile, createRecordsWriteMessage, getFileAsReadStream, streamHttpRequest, @@ -77,7 +77,7 @@ describe('http api', function () { }); it('responds with a 2XX HTTP status if JSON RPC handler returns 4XX/5XX DWN status code', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite, dataStream } = await createRecordsWriteMessage(alice); // Intentionally delete a required property to produce an invalid RecordsWrite message. @@ -135,7 +135,7 @@ describe('http api', function () { }); it('works fine when no request body is provided', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const recordsQuery = await RecordsQuery.create({ filter: { schema: 'woosa', @@ -165,7 +165,7 @@ describe('http api', function () { const filePath = './fixtures/test.jpeg'; const { cid, size, stream } = await getFileAsReadStream(filePath); - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite } = await createRecordsWriteMessage(alice, { dataCid: cid, dataSize: size, @@ -200,7 +200,7 @@ describe('http api', function () { }); it('handles RecordsWrite overwrite that does not mutate data', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); // First RecordsWrite that creates the record. const { recordsWrite: initialWrite, dataStream } = @@ -258,7 +258,7 @@ describe('http api', function () { }); it('handles a RecordsWrite tombstone', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite: tombstone } = await createRecordsWriteMessage(alice); @@ -306,7 +306,7 @@ describe('http api', function () { stream, } = await getFileAsReadStream(filePath); - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite } = await createRecordsWriteMessage(alice, { dataCid: expectedCid, dataSize: size, @@ -390,7 +390,7 @@ describe('http api', function () { stream, } = await getFileAsReadStream(filePath); - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite } = await createRecordsWriteMessage(alice, { dataCid: expectedCid, dataSize: size, @@ -436,7 +436,7 @@ describe('http api', function () { stream, } = await getFileAsReadStream(filePath); - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite } = await createRecordsWriteMessage(alice, { dataCid: expectedCid, dataSize: size, @@ -473,7 +473,7 @@ describe('http api', function () { }); it('returns a 404 if record doesnt exist', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite } = await createRecordsWriteMessage(alice); const response = await fetch( @@ -483,7 +483,7 @@ describe('http api', function () { }); it('returns a 404 for invalid did', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite } = await createRecordsWriteMessage(alice); const response = await fetch( @@ -493,7 +493,7 @@ describe('http api', function () { }); it('returns a 404 for invalid record id', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const response = await fetch( `http://localhost:3000/${alice.did}/records/kaka`, ); diff --git a/tests/utils.ts b/tests/utils.ts index 703a76c..5cb1d9b 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -1,11 +1,5 @@ import type { PrivateJwk, PublicJwk, Signer } from '@tbd54566975/dwn-sdk-js'; -import { - Cid, - DataStream, - DidKeyResolver, - PrivateKeySigner, - RecordsWrite, -} from '@tbd54566975/dwn-sdk-js'; +import { Cid, DataStream, RecordsWrite } from '@tbd54566975/dwn-sdk-js'; import type { ReadStream } from 'node:fs'; import fs from 'node:fs'; @@ -28,23 +22,6 @@ export type Profile = { signer: Signer; }; -export async function createProfile(): Promise { - const { did, keyPair, keyId } = await DidKeyResolver.generate(); - - // signer is required by all dwn message classes. it's used to sign messages - const signer = new PrivateKeySigner({ - privateJwk: keyPair.privateJwk, - algorithm: keyPair.privateJwk.alg, - keyId: `${did}#${keyId}`, - }); - - return { - did, - keyPair, - signer, - }; -} - export type CreateRecordsWriteOverrides = | ({ dataCid?: string; diff --git a/tests/ws-api.spec.ts b/tests/ws-api.spec.ts index 6e836aa..f478194 100644 --- a/tests/ws-api.spec.ts +++ b/tests/ws-api.spec.ts @@ -1,4 +1,4 @@ -import { DataStream } from '@tbd54566975/dwn-sdk-js'; +import { DataStream, DidKeyResolver } from '@tbd54566975/dwn-sdk-js'; import { expect } from 'chai'; import { base64url } from 'multiformats/bases/base64'; @@ -12,11 +12,7 @@ import { } from '../src/lib/json-rpc.js'; import { WsApi } from '../src/ws-api.js'; import { clear as clearDwn, dwn } from './test-dwn.js'; -import { - createProfile, - createRecordsWriteMessage, - sendWsMessage, -} from './utils.js'; +import { createRecordsWriteMessage, sendWsMessage } from './utils.js'; let server: http.Server; let wsServer: WebSocketServer; @@ -60,7 +56,7 @@ describe('websocket api', function () { }); it('handles RecordsWrite messages', async function () { - const alice = await createProfile(); + const alice = await DidKeyResolver.generate(); const { recordsWrite, dataStream } = await createRecordsWriteMessage(alice); const dataBytes = await DataStream.toBytes(dataStream); const encodedData = base64url.baseEncode(dataBytes);