Skip to content

Commit

Permalink
DIDResolver/UniversalResolver alpha (#709)
Browse files Browse the repository at this point in the history
Bump `@web5/dids` to `0.4.2`
Bump `dwn-sdk-js` to `0.2.20`

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: Frank Hinek <[email protected]>
  • Loading branch information
LiranCohen and frankhinek authored Mar 22, 2024
1 parent b66d4e7 commit 2b4b848
Show file tree
Hide file tree
Showing 31 changed files with 120 additions and 83 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/npm-publish-unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ on:
branches:
- main
workflow_dispatch:
inputs:
branchName:
description: 'Branch name to run the workflow on'
required: true
default: 'main'

jobs:

Expand Down
31 changes: 25 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tbd54566975/dwn-sdk-js",
"version": "0.2.18",
"version": "0.2.20",
"description": "A reference implementation of https://identity.foundation/decentralized-web-node/spec/",
"repository": {
"type": "git",
Expand Down Expand Up @@ -65,7 +65,7 @@
"@js-temporal/polyfill": "0.4.4",
"@noble/ed25519": "2.0.0",
"@noble/secp256k1": "2.0.0",
"@web5/dids": "0.4.1",
"@web5/dids": "0.4.2",
"abstract-level": "1.0.3",
"ajv": "8.12.0",
"blockstore-core": "4.2.0",
Expand Down
6 changes: 4 additions & 2 deletions src/dwn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import type { DataStore } from './types/data-store.js';
import type { DidResolver } from '@web5/dids';
import type { EventLog } from './types/event-log.js';
import type { EventStream } from './types/subscriptions.js';
import type { MessageStore } from './types/message-store.js';
Expand Down Expand Up @@ -30,7 +32,7 @@ import { RecordsQueryHandler } from './handlers/records-query.js';
import { RecordsReadHandler } from './handlers/records-read.js';
import { RecordsSubscribeHandler } from './handlers/records-subscribe.js';
import { RecordsWriteHandler } from './handlers/records-write.js';
import { DidDht, DidIon, DidKey, DidResolver, DidResolverCacheLevel } from '@web5/dids';
import { DidDht, DidIon, DidKey, DidResolverCacheLevel, UniversalResolver } from '@web5/dids';
import { DwnInterfaceName, DwnMethodName } from './enums/dwn-interface-method.js';

export class Dwn {
Expand Down Expand Up @@ -134,7 +136,7 @@ export class Dwn {
* Creates an instance of the DWN.
*/
public static async create(config: DwnConfig): Promise<Dwn> {
config.didResolver ??= new DidResolver({
config.didResolver ??= new UniversalResolver({
didResolvers : [DidDht, DidIon, DidKey],
cache : new DidResolverCacheLevel({ location: 'RESOLVERCACHE' }),
});
Expand Down
4 changes: 2 additions & 2 deletions tests/core/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { authenticate } from '../../src/core/auth.js';
import { DwnErrorCode } from '../../src/core/dwn-error.js';
import { expect } from 'chai';
import { DidDht, DidResolver } from '@web5/dids';
import { DidDht, UniversalResolver } from '@web5/dids';

describe('Auth', () => {
describe('authenticate()', () => {
it('should throw if given JWS is `undefined`', async () => {
const jws = undefined;
await expect(authenticate(jws, new DidResolver({ didResolvers: [DidDht] }))).to.be.rejectedWith(DwnErrorCode.AuthenticateJwsMissing);
await expect(authenticate(jws, new UniversalResolver({ didResolvers: [DidDht] }))).to.be.rejectedWith(DwnErrorCode.AuthenticateJwsMissing);
});
});
});
7 changes: 5 additions & 2 deletions tests/features/author-delegated-grant.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DelegatedGrantMessage } from '../../src/types/delegated-grant-message.js';
import type { DidResolver } from '@web5/dids';
import type { EventStream } from '../../src/types/subscriptions.js';
import type { DataStore, EventLog, MessageStore, PermissionScope } from '../../src/index.js';
import type { RecordEvent, RecordsWriteMessage } from '../../src/types/records-types.js';
Expand All @@ -22,7 +23,7 @@ import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { Time } from '../../src/utils/time.js';

import { DidKey, DidResolver } from '@web5/dids';
import { DidKey, UniversalResolver } from '@web5/dids';
import { DwnInterfaceName, DwnMethodName, Encoder, Message, PermissionsGrant, PermissionsRevoke, RecordsDelete, RecordsQuery, RecordsRead, RecordsSubscribe } from '../../src/index.js';

chai.use(chaiAsPromised);
Expand All @@ -39,7 +40,7 @@ export function testAuthorDelegatedGrant(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down Expand Up @@ -1134,6 +1135,8 @@ export function testAuthorDelegatedGrant(): void {
signer : Jws.createSigner(alice)
});

await Time.minimalSleep();

const deviceXGrant2 = await PermissionsGrant.create({
delegated : true,
dateExpires : Time.createOffsetTimestamp({ seconds: 100 }),
Expand Down
7 changes: 5 additions & 2 deletions tests/features/owner-delegated-grant.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DelegatedGrantMessage } from '../../src/types/delegated-grant-message.js';
import type { DidResolver } from '@web5/dids';
import type { EventStream } from '../../src/types/subscriptions.js';
import type { DataStore, EventLog, MessageStore, PermissionScope } from '../../src/index.js';

Expand All @@ -18,7 +19,7 @@ import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { Time } from '../../src/utils/time.js';

import { DidKey, DidResolver } from '@web5/dids';
import { DidKey, UniversalResolver } from '@web5/dids';
import { DwnInterfaceName, DwnMethodName, Encoder, Message, PermissionsGrant, PermissionsRevoke, ProtocolsConfigure } from '../../src/index.js';

chai.use(chaiAsPromised);
Expand All @@ -35,7 +36,7 @@ export function testOwnerDelegatedGrant(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down Expand Up @@ -528,6 +529,8 @@ export function testOwnerDelegatedGrant(): void {
signer : Jws.createSigner(alice)
});

await Time.minimalSleep();

const appXGrant2 = await PermissionsGrant.create({
delegated : true,
dateExpires : Time.createOffsetTimestamp({ seconds: 100 }),
Expand Down
6 changes: 3 additions & 3 deletions tests/features/owner-signature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DidResolver } from '@web5/dids';
import type { EventStream } from '../../src/types/subscriptions.js';
import type { DataStore, EventLog, MessageStore } from '../../src/index.js';

Expand All @@ -8,8 +9,6 @@ import chai, { expect } from 'chai';

import { ArrayUtility } from '../../src/utils/array.js';
import { DataStream } from '../../src/utils/data-stream.js';
import { DidKey } from '@web5/dids';
import { DidResolver } from '@web5/dids';
import { Dwn } from '../../src/dwn.js';
import { DwnErrorCode } from '../../src/core/dwn-error.js';
import { Jws } from '../../src/utils/jws.js';
Expand All @@ -18,6 +17,7 @@ import { RecordsWrite } from '../../src/interfaces/records-write.js';
import { TestDataGenerator } from '../utils/test-data-generator.js';
import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { DidKey, UniversalResolver } from '@web5/dids';

chai.use(chaiAsPromised);

Expand All @@ -33,7 +33,7 @@ export function testOwnerSignature(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down
6 changes: 3 additions & 3 deletions tests/features/protocol-create-action.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DidResolver } from '@web5/dids';
import type { EventStream } from '../../src/types/subscriptions.js';
import type { ProtocolDefinition } from '../../src/types/protocols-types.js';
import type { DataStore, EventLog, MessageStore } from '../../src/index.js';
Expand All @@ -7,15 +8,14 @@ import sinon from 'sinon';
import chai, { expect } from 'chai';

import { DataStream } from '../../src/utils/data-stream.js';
import { DidKey } from '@web5/dids';
import { DidResolver } from '@web5/dids';
import { Dwn } from '../../src/dwn.js';
import { Jws } from '../../src/utils/jws.js';
import { ProtocolAction } from '../../src/types/protocols-types.js';
import { RecordsWrite } from '../../src/interfaces/records-write.js';
import { TestDataGenerator } from '../utils/test-data-generator.js';
import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { DidKey, UniversalResolver } from '@web5/dids';

import { DwnErrorCode, ProtocolsConfigure } from '../../src/index.js';

Expand All @@ -33,7 +33,7 @@ export function testProtocolCreateAction(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down
6 changes: 3 additions & 3 deletions tests/features/protocol-delete-action.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DidResolver } from '@web5/dids';
import type { EventStream } from '../../src/types/subscriptions.js';
import type { DataStore, EventLog, MessageStore } from '../../src/index.js';
import type { ProtocolDefinition, ProtocolsConfigureDescriptor } from '../../src/types/protocols-types.js';
Expand All @@ -7,8 +8,6 @@ import sinon from 'sinon';
import chai, { expect } from 'chai';

import { DataStream } from '../../src/utils/data-stream.js';
import { DidKey } from '@web5/dids';
import { DidResolver } from '@web5/dids';
import { Dwn } from '../../src/dwn.js';
import { Jws } from '../../src/utils/jws.js';
import { ProtocolAction } from '../../src/types/protocols-types.js';
Expand All @@ -18,6 +17,7 @@ import { RecordsWrite } from '../../src/interfaces/records-write.js';
import { TestDataGenerator } from '../utils/test-data-generator.js';
import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { DidKey, UniversalResolver } from '@web5/dids';
import { DwnErrorCode, DwnInterfaceName, DwnMethodName, Message, ProtocolsConfigure, RecordsDelete, Time } from '../../src/index.js';

chai.use(chaiAsPromised);
Expand All @@ -34,7 +34,7 @@ export function testProtocolDeleteAction(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down
6 changes: 3 additions & 3 deletions tests/features/protocol-update-action.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DidResolver } from '@web5/dids';
import type { EventStream } from '../../src/types/subscriptions.js';
import type { DataStore, EventLog, MessageStore } from '../../src/index.js';
import type { ProtocolDefinition, ProtocolsConfigureDescriptor } from '../../src/types/protocols-types.js';
Expand All @@ -7,8 +8,6 @@ import sinon from 'sinon';
import chai, { expect } from 'chai';

import { DataStream } from '../../src/utils/data-stream.js';
import { DidKey } from '@web5/dids';
import { DidResolver } from '@web5/dids';
import { Dwn } from '../../src/dwn.js';
import { Jws } from '../../src/utils/jws.js';
import { ProtocolAction } from '../../src/types/protocols-types.js';
Expand All @@ -17,6 +16,7 @@ import { RecordsWrite } from '../../src/interfaces/records-write.js';
import { TestDataGenerator } from '../utils/test-data-generator.js';
import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { DidKey, UniversalResolver } from '@web5/dids';
import { DwnErrorCode, DwnInterfaceName, DwnMethodName, Message, ProtocolsConfigure, Time } from '../../src/index.js';

chai.use(chaiAsPromised);
Expand All @@ -33,7 +33,7 @@ export function testProtocolUpdateAction(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down
5 changes: 3 additions & 2 deletions tests/handlers/events-get.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DidResolver } from '@web5/dids';
import type { EventStream } from '../../src/types/subscriptions.js';
import type {
DataStore,
Expand All @@ -14,7 +15,7 @@ import { TestDataGenerator } from '../utils/test-data-generator.js';
import { Message } from '../../src/core/message.js';
import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { DidKey, DidResolver } from '@web5/dids';
import { DidKey, UniversalResolver } from '@web5/dids';

export function testEventsGetHandler(): void {
describe('EventsGetHandler.handle()', () => {
Expand All @@ -28,7 +29,7 @@ export function testEventsGetHandler(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down
5 changes: 3 additions & 2 deletions tests/handlers/events-query.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DidResolver } from '@web5/dids';
import type {
DataStore,
EventLog,
Expand All @@ -11,7 +12,7 @@ import { expect } from 'chai';
import { TestDataGenerator } from '../utils/test-data-generator.js';
import { TestEventStream } from '../test-event-stream.js';
import { TestStores } from '../test-stores.js';
import { DidKey, DidResolver } from '@web5/dids';
import { DidKey, UniversalResolver } from '@web5/dids';


export function testEventsQueryHandler(): void {
Expand All @@ -26,7 +27,7 @@ export function testEventsQueryHandler(): void {
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
// so that different test suites can reuse the same backend store for testing
before(async () => {
didResolver = new DidResolver({ didResolvers: [DidKey] });
didResolver = new UniversalResolver({ didResolvers: [DidKey] });

const stores = TestStores.get();
messageStore = stores.messageStore;
Expand Down
Loading

0 comments on commit 2b4b848

Please sign in to comment.