Skip to content

Commit

Permalink
Bump @web5/dids and add DID Resolver cache (#685)
Browse files Browse the repository at this point in the history
This PR will:
- Bump the `@web5/dids` package from `0.3.0` to `0.4.0`.
- Adds a DID resolver cache to the default instantiate of a `Dwn`. The
cache is a TTL cache with a 15 minute default timeout. It uses a
persistent LevelDB cache which will keep approximately 8,000 DID
documents in an in-memory cache before flushing to disk. Since the cache
entries are persisted to disk, they will survive process restarts.
- Bump `@tbd54566975/dwn-sdk-js` to `0.2.17` so it can be published to
NPM Registry.

---------

Signed-off-by: Frank Hinek <frankhinek@users.noreply.github.com>
  • Loading branch information
frankhinek committed Feb 10, 2024
1 parent e762e0f commit 36781b0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,6 +14,7 @@ try.js
MESSAGESTORE
DATASTORE
EVENTLOG
RESOLVERCACHE
# location for levelDB data storage for non-browser tests
TEST-DATASTORE
TEST-MESSAGESTORE
Expand Down
12 changes: 6 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
@@ -1,6 +1,6 @@
{
"name": "@tbd54566975/dwn-sdk-js",
"version": "0.2.16",
"version": "0.2.17",
"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.3.0",
"@web5/dids": "0.4.0",
"abstract-level": "1.0.3",
"ajv": "8.12.0",
"blockstore-core": "4.2.0",
Expand Down
7 changes: 5 additions & 2 deletions src/dwn.ts
Expand Up @@ -30,7 +30,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 } from '@web5/dids';
import { DidDht, DidIon, DidKey, DidResolver, DidResolverCacheLevel } from '@web5/dids';
import { DwnInterfaceName, DwnMethodName } from './enums/dwn-interface-method.js';

export class Dwn {
Expand Down Expand Up @@ -134,7 +134,10 @@ export class Dwn {
* Creates an instance of the DWN.
*/
public static async create(config: DwnConfig): Promise<Dwn> {
config.didResolver ??= new DidResolver({ didResolvers: [DidKey, DidIon, DidDht] });
config.didResolver ??= new DidResolver({
didResolvers : [DidDht, DidIon, DidKey],
cache : new DidResolverCacheLevel({ location: 'RESOLVERCACHE' }),
});
config.tenantGate ??= new AllowAllTenantGate();

const dwn = new Dwn(config);
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/test-data-generator.ts
Expand Up @@ -1000,13 +1000,13 @@ export class TestDataGenerator {
public static async generateDidKeyPersona(): Promise<Persona> {

const did = await DidKey.create();
const signingMethod = await DidKey.getSigningMethod({ didDocument: did.didDocument });
const keyId = signingMethod!.id;
const portableDid = await DidKey.toKeys({ did });
const signingMethod = await DidKey.getSigningMethod({ didDocument: did.document });
const keyId = signingMethod.id;
const portableDid = await did.export();
const keyPair = {
// TODO: #672 - port and use type from @web5/crypto - https://github.com/TBD54566975/dwn-sdk-js/issues/672
publicJwk : portableDid.verificationMethods[0].publicKeyJwk as PublicJwk,
privateJwk : portableDid.verificationMethods[0].privateKeyJwk as PrivateJwk,
publicJwk : signingMethod.publicKeyJwk as PublicJwk,
privateJwk : portableDid.privateKeys![0] as PrivateJwk,
};

return {
Expand Down

0 comments on commit 36781b0

Please sign in to comment.