Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added wallet connect options for Web5.connect() #694

Merged
merged 9 commits into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/famous-otters-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@web5/crypto-aws-kms": patch
"@web5/identity-agent": patch
"@web5/credentials": patch
"@web5/proxy-agent": patch
"@web5/user-agent": patch
"@web5/common": patch
"@web5/crypto": patch
"@web5/agent": patch
"@web5/dids": patch
---

Dependency updates.
5 changes: 5 additions & 0 deletions .changeset/rare-garlics-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web5/api": minor
---

Added WalletConnectOptions and updated dwn-sdk-js dependencies.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -31,14 +31,15 @@
"@changesets/cli": "^2.27.5",
"@npmcli/package-json": "5.0.0",
"@typescript-eslint/eslint-plugin": "7.9.0",
"@web5/dwn-server": "0.2.3",
"@web5/dwn-server": "0.3.1",
"audit-ci": "^7.0.1",
"eslint-plugin-mocha": "10.4.3",
"npkill": "0.11.3"
},
"pnpm": {
"overrides": {
"express@<4.19.2": ">=4.19.2"
"express@<4.19.2": ">=4.19.2",
"ws@<8.17.1": ">=8.17.1"
}
}
}
6 changes: 3 additions & 3 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@
"dependencies": {
"@noble/ciphers": "0.4.1",
"@scure/bip39": "1.2.2",
"@tbd54566975/dwn-sdk-js": "0.3.5",
"@tbd54566975/dwn-sdk-js": "0.3.10",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.1.0",
@@ -93,8 +93,8 @@
"@types/node": "20.11.19",
"@types/sinon": "17.0.2",
"@typescript-eslint/eslint-plugin": "7.9.0",
"@typescript-eslint/parser": "7.9.0",
"@web/test-runner": "0.18.0",
"@typescript-eslint/parser": "7.14.1",
"@web/test-runner": "0.18.2",
"@web/test-runner-playwright": "0.11.0",
"abstract-level": "1.0.4",
"c8": "9.1.0",
8 changes: 5 additions & 3 deletions packages/agent/src/dwn-api.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import type { DwnConfig, GenericMessage, UnionMessageReply } from '@tbd54566975/
import { Convert, NodeStream } from '@web5/common';
import { utils as cryptoUtils } from '@web5/crypto';
import { DidDht, DidJwk, DidResolverCacheLevel, UniversalResolver } from '@web5/dids';
import { Cid, DataStoreLevel, Dwn, DwnMethodName, EventLogLevel, Message, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js';
import { Cid, DataStoreLevel, Dwn, DwnMethodName, EventLogLevel, Message, MessageStoreLevel, ResumableTaskStoreLevel } from '@tbd54566975/dwn-sdk-js';

import type { Web5PlatformAgent } from './types/agent.js';
import type { DwnMessage, DwnMessageInstance, DwnMessageParams, DwnMessageReply, DwnMessageWithData, DwnResponse, DwnSigner, MessageHandler, ProcessDwnRequest, SendDwnRequest } from './types/dwn.js';
@@ -95,7 +95,7 @@ export class AgentDwnApi {
}

public static async createDwn({
dataPath, dataStore, didResolver, eventLog, eventStream, messageStore, tenantGate
dataPath, dataStore, didResolver, eventLog, eventStream, messageStore, tenantGate, resumableTaskStore
}: DwnApiCreateDwnParams): Promise<Dwn> {
dataStore ??= new DataStoreLevel({ blockstoreLocation: `${dataPath}/DWN_DATASTORE` });

@@ -111,7 +111,9 @@ export class AgentDwnApi {
indexLocation : `${dataPath}/DWN_MESSAGEINDEX`
}));

return await Dwn.create({ dataStore, didResolver, eventLog, eventStream, messageStore, tenantGate });
resumableTaskStore ??= new ResumableTaskStoreLevel({ location: `${dataPath}/DWN_RESUMABLETASKSTORE` });

return await Dwn.create({ dataStore, didResolver, eventLog, eventStream, messageStore, tenantGate, resumableTaskStore });
}

public async processRequest<T extends DwnInterface>(
4 changes: 2 additions & 2 deletions packages/agent/src/prototyping/clients/dwn-rpc-types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { RecordsReadReply, UnionMessageReply, EventSubscriptionHandler, RecordSubscriptionHandler } from '@tbd54566975/dwn-sdk-js';
import type { RecordsReadReply, UnionMessageReply, MessageSubscriptionHandler, RecordSubscriptionHandler } from '@tbd54566975/dwn-sdk-js';

export interface SerializableDwnMessage {
toJSON(): string;
}

export type DwnSubscriptionHandler = EventSubscriptionHandler | RecordSubscriptionHandler;
export type DwnSubscriptionHandler = MessageSubscriptionHandler | RecordSubscriptionHandler;

/**
* Interface for communicating with {@link https://github.com/TBD54566975/dwn-server | DWN Servers}
16 changes: 8 additions & 8 deletions packages/agent/src/sync-engine-level.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ULIDFactory } from 'ulidx';
import type { AbstractBatchOperation, AbstractLevel } from 'abstract-level';
import type {
EventsGetReply,
EventsQueryReply,
GenericMessage,
MessagesGetReply,
PaginationCursor,
@@ -355,22 +355,22 @@ export class SyncEngineLevel implements SyncEngine {
syncDirection: SyncDirection,
cursor?: PaginationCursor
}) {
let eventsReply = {} as EventsGetReply;
let eventsReply = {} as EventsQueryReply;

if (syncDirection === 'pull') {
// When sync is a pull, get the event log from the remote DWN.
const eventsGetMessage = await this.agent.dwn.createMessage({
author : did,
messageType : DwnInterface.EventsGet,
messageParams : { cursor }
messageType : DwnInterface.EventsQuery,
messageParams : { filters: [], cursor }
});

try {
eventsReply = await this.agent.rpc.sendDwnRequest({
dwnUrl : dwnUrl,
targetDid : did,
message : eventsGetMessage
}) as EventsGetReply;
}) as EventsQueryReply;
} catch {
// If a particular DWN service endpoint is unreachable, silently ignore.
}
@@ -380,10 +380,10 @@ export class SyncEngineLevel implements SyncEngine {
const eventsGetDwnResponse = await this.agent.dwn.processRequest({
author : did,
target : did,
messageType : DwnInterface.EventsGet,
messageParams : { cursor }
messageType : DwnInterface.EventsQuery,
messageParams : { filters: [], cursor }
});
eventsReply = eventsGetDwnResponse.reply as EventsGetReply;
eventsReply = eventsGetDwnResponse.reply as EventsQueryReply;
}

const eventLog = eventsReply.entries ?? [];
22 changes: 15 additions & 7 deletions packages/agent/src/test-harness.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import type { AbstractLevel } from 'abstract-level';

import { Level } from 'level';
import { LevelStore, MemoryStore } from '@web5/common';
import { DataStoreLevel, Dwn, EventEmitterStream, EventLogLevel, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js';
import { DataStoreLevel, Dwn, EventEmitterStream, EventLogLevel, MessageStoreLevel, ResumableTaskStoreLevel } from '@tbd54566975/dwn-sdk-js';
import { DidDht, DidJwk, DidResolutionResult, DidResolverCache, DidResolverCacheLevel } from '@web5/dids';

import type { Web5PlatformAgent } from './types/agent.js';
@@ -32,6 +32,7 @@ type PlatformAgentTestHarnessParams = {
dwnDataStore: DataStoreLevel;
dwnEventLog: EventLogLevel;
dwnMessageStore: MessageStoreLevel;
dwnResumableTaskStore: ResumableTaskStoreLevel;
syncStore: AbstractLevel<string | Buffer | Uint8Array>;
vaultStore: KeyValueStore<string, string>;
}
@@ -51,6 +52,7 @@ export class PlatformAgentTestHarness {
public dwnDataStore: DataStoreLevel;
public dwnEventLog: EventLogLevel;
public dwnMessageStore: MessageStoreLevel;
public dwnResumableTaskStore: ResumableTaskStoreLevel;
public syncStore: AbstractLevel<string | Buffer | Uint8Array>;
public vaultStore: KeyValueStore<string, string>;

@@ -64,6 +66,7 @@ export class PlatformAgentTestHarness {
this.dwnMessageStore = params.dwnMessageStore;
this.syncStore = params.syncStore;
this.vaultStore = params.vaultStore;
this.dwnResumableTaskStore = params.dwnResumableTaskStore;
}

public async clearStorage(): Promise<void> {
@@ -73,6 +76,7 @@ export class PlatformAgentTestHarness {
await this.dwnDataStore.clear();
await this.dwnEventLog.clear();
await this.dwnMessageStore.clear();
await this.dwnResumableTaskStore.clear();
await this.syncStore.clear();
await this.vaultStore.clear();

@@ -98,6 +102,7 @@ export class PlatformAgentTestHarness {
await this.dwnDataStore.close();
await this.dwnEventLog.close();
await this.dwnMessageStore.close();
await this.dwnResumableTaskStore.close();
await this.syncStore.close();
await this.vaultStore.close();
}
@@ -181,6 +186,7 @@ export class PlatformAgentTestHarness {
const dwnDataStore = new DataStoreLevel({ blockstoreLocation: testDataPath('DWN_DATASTORE') });
const dwnEventLog = new EventLogLevel({ location: testDataPath('DWN_EVENTLOG') });
const dwnEventStream = new EventEmitterStream();
const dwnResumableTaskStore = new ResumableTaskStoreLevel({ location: testDataPath('DWN_RESUMABLETASKSTORE') });

const dwnMessageStore = new MessageStoreLevel({
blockstoreLocation : testDataPath('DWN_MESSAGESTORE'),
@@ -189,12 +195,13 @@ export class PlatformAgentTestHarness {

// Instantiate DWN instance using the custom stores.
const dwn = await AgentDwnApi.createDwn({
dataPath : testDataLocation,
dataStore : dwnDataStore,
didResolver : didApi,
eventLog : dwnEventLog,
eventStream : dwnEventStream,
messageStore : dwnMessageStore,
dataPath : testDataLocation,
dataStore : dwnDataStore,
didResolver : didApi,
eventLog : dwnEventLog,
eventStream : dwnEventStream,
messageStore : dwnMessageStore,
resumableTaskStore : dwnResumableTaskStore
});

// Instantiate Agent's DWN API using the custom DWN instance.
@@ -225,6 +232,7 @@ export class PlatformAgentTestHarness {
dwnDataStore,
dwnEventLog,
dwnMessageStore,
dwnResumableTaskStore,
syncStore,
vaultStore
});
23 changes: 8 additions & 15 deletions packages/agent/src/types/dwn.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { DidService } from '@web5/dids';
import type { Readable, RequireOnly } from '@web5/common';
import type {
EventsGetReply,
EventsGetOptions,
EventsGetMessage,
EventsQueryReply,
MessagesGetReply,
RecordsReadReply,
@@ -32,12 +29,11 @@ import type {
RecordsSubscribeOptions,
EventsSubscribeReply,
RecordsSubscribeReply,
MessageSubscriptionHandler,
RecordSubscriptionHandler,
EventSubscriptionHandler,
} from '@tbd54566975/dwn-sdk-js';

import {
EventsGet,
MessagesGet,
RecordsRead,
RecordsQuery,
@@ -91,7 +87,6 @@ export interface DwnDidService extends DidService {
}

export enum DwnInterface {
EventsGet = DwnInterfaceName.Events + DwnMethodName.Get,
EventsQuery = DwnInterfaceName.Events + DwnMethodName.Query,
EventsSubscribe = DwnInterfaceName.Events + DwnMethodName.Subscribe,
MessagesGet = DwnInterfaceName.Messages + DwnMethodName.Get,
@@ -105,7 +100,6 @@ export enum DwnInterface {
}

export interface DwnMessage {
[DwnInterface.EventsGet] : EventsGetMessage;
[DwnInterface.EventsSubscribe] : EventsSubscribeMessage;
[DwnInterface.EventsQuery] : EventsQueryMessage;
[DwnInterface.MessagesGet] : MessagesGetMessage;
@@ -119,7 +113,6 @@ export interface DwnMessage {
}

export interface DwnMessageDescriptor {
[DwnInterface.EventsGet] : EventsGetMessage['descriptor'];
[DwnInterface.EventsSubscribe] : EventsSubscribeMessage['descriptor'];
[DwnInterface.EventsQuery] : EventsQueryMessage['descriptor'];
[DwnInterface.MessagesGet] : MessagesGetMessage['descriptor'];
@@ -133,7 +126,6 @@ export interface DwnMessageDescriptor {
}

export interface DwnMessageParams {
[DwnInterface.EventsGet] : Partial<EventsGetOptions>;
[DwnInterface.EventsQuery] : RequireOnly<EventsQueryOptions, 'filters'>;
[DwnInterface.EventsSubscribe] : Partial<EventsSubscribeOptions>;
[DwnInterface.MessagesGet] : RequireOnly<MessagesGetOptions, 'messageCids'>;
@@ -147,7 +139,6 @@ export interface DwnMessageParams {
}

export interface DwnMessageReply {
[DwnInterface.EventsGet] : EventsGetReply;
[DwnInterface.EventsQuery] : EventsQueryReply;
[DwnInterface.EventsSubscribe] : EventsSubscribeReply;
[DwnInterface.MessagesGet] : MessagesGetReply;
@@ -161,11 +152,10 @@ export interface DwnMessageReply {
}

export interface MessageHandler {
[DwnInterface.EventsSubscribe] : EventSubscriptionHandler;
[DwnInterface.EventsSubscribe] : MessageSubscriptionHandler;
[DwnInterface.RecordsSubscribe] : RecordSubscriptionHandler;

// define all of them individually as undefined
[DwnInterface.EventsGet] : undefined;
[DwnInterface.EventsQuery] : undefined;
[DwnInterface.MessagesGet] : undefined;
[DwnInterface.ProtocolsConfigure] : undefined;
@@ -220,7 +210,6 @@ export interface DwnMessageConstructor<T extends DwnInterface> {
}

export const dwnMessageConstructors: { [T in DwnInterface]: DwnMessageConstructor<T> } = {
[DwnInterface.EventsGet] : EventsGet as any,
[DwnInterface.EventsQuery] : EventsQuery as any,
[DwnInterface.EventsSubscribe] : EventsSubscribe as any,
[DwnInterface.MessagesGet] : MessagesGet as any,
@@ -236,7 +225,6 @@ export const dwnMessageConstructors: { [T in DwnInterface]: DwnMessageConstructo
export type DwnMessageConstructors = typeof dwnMessageConstructors;

export interface DwnMessageInstance {
[DwnInterface.EventsGet] : EventsGet;
[DwnInterface.EventsQuery] : EventsQuery;
[DwnInterface.EventsSubscribe] : EventsSubscribe;
[DwnInterface.MessagesGet] : MessagesGet;
@@ -264,9 +252,14 @@ export {
DateSort as DwnDateSort,
PublicJwk as DwnPublicKeyJwk, // TODO: Remove once DWN SDK switches to Jwk from @web5/crypto
PaginationCursor as DwnPaginationCursor,
EventSubscriptionHandler as DwnEventSubscriptionHandler,
MessageSubscriptionHandler as DwnMessageSubscriptionHandler,
RecordSubscriptionHandler as DwnRecordSubscriptionHandler,
MessageSubscription as DwnMessageSubscription,
EncryptionAlgorithm as DwnEncryptionAlgorithm,
KeyDerivationScheme as DwnKeyDerivationScheme,
PermissionGrant as DwnPermissionGrant,
PermissionRequest as DwnPermissionRequest,
PermissionsProtocol as DwnPermissionsProtocol,
ProtocolDefinition as DwnProtocolDefinition,
RecordsPermissionScope as DwnRecordsPermissionScope,
} from '@tbd54566975/dwn-sdk-js';
Loading
Loading