Skip to content

Commit 36781b0

Browse files
authored
Bump @web5/dids and add DID Resolver cache (#685)
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 <[email protected]>
1 parent e762e0f commit 36781b0

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ try.js
1414
MESSAGESTORE
1515
DATASTORE
1616
EVENTLOG
17+
RESOLVERCACHE
1718
# location for levelDB data storage for non-browser tests
1819
TEST-DATASTORE
1920
TEST-MESSAGESTORE

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tbd54566975/dwn-sdk-js",
3-
"version": "0.2.16",
3+
"version": "0.2.17",
44
"description": "A reference implementation of https://identity.foundation/decentralized-web-node/spec/",
55
"repository": {
66
"type": "git",
@@ -65,7 +65,7 @@
6565
"@js-temporal/polyfill": "0.4.4",
6666
"@noble/ed25519": "2.0.0",
6767
"@noble/secp256k1": "2.0.0",
68-
"@web5/dids": "0.3.0",
68+
"@web5/dids": "0.4.0",
6969
"abstract-level": "1.0.3",
7070
"ajv": "8.12.0",
7171
"blockstore-core": "4.2.0",

src/dwn.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { RecordsQueryHandler } from './handlers/records-query.js';
3030
import { RecordsReadHandler } from './handlers/records-read.js';
3131
import { RecordsSubscribeHandler } from './handlers/records-subscribe.js';
3232
import { RecordsWriteHandler } from './handlers/records-write.js';
33-
import { DidDht, DidIon, DidKey, DidResolver } from '@web5/dids';
33+
import { DidDht, DidIon, DidKey, DidResolver, DidResolverCacheLevel } from '@web5/dids';
3434
import { DwnInterfaceName, DwnMethodName } from './enums/dwn-interface-method.js';
3535

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

140143
const dwn = new Dwn(config);

tests/utils/test-data-generator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,13 +1000,13 @@ export class TestDataGenerator {
10001000
public static async generateDidKeyPersona(): Promise<Persona> {
10011001

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

10121012
return {

0 commit comments

Comments
 (0)