@enbox/agent 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +11 -11
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/anonymous-dwn-api.js +1 -1
- package/dist/esm/anonymous-dwn-api.js.map +1 -1
- package/dist/esm/connect.js +4 -10
- package/dist/esm/connect.js.map +1 -1
- package/dist/esm/dwn-api.js +144 -195
- package/dist/esm/dwn-api.js.map +1 -1
- package/dist/esm/dwn-protocol-cache.js +149 -0
- package/dist/esm/dwn-protocol-cache.js.map +1 -0
- package/dist/esm/dwn-record-upgrade.js +3 -3
- package/dist/esm/dwn-record-upgrade.js.map +1 -1
- package/dist/esm/hd-identity-vault.js +6 -5
- package/dist/esm/hd-identity-vault.js.map +1 -1
- package/dist/esm/identity-api.js +0 -2
- package/dist/esm/identity-api.js.map +1 -1
- package/dist/esm/oidc.js +2 -1
- package/dist/esm/oidc.js.map +1 -1
- package/dist/esm/permissions-api.js +24 -6
- package/dist/esm/permissions-api.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe.js +11 -3
- package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -1
- package/dist/esm/store-data-protocols.js +2 -2
- package/dist/esm/store-data-protocols.js.map +1 -1
- package/dist/esm/sync-api.js +3 -0
- package/dist/esm/sync-api.js.map +1 -1
- package/dist/esm/sync-engine-level.js +447 -29
- package/dist/esm/sync-engine-level.js.map +1 -1
- package/dist/esm/test-harness.js +3 -5
- package/dist/esm/test-harness.js.map +1 -1
- package/dist/esm/types/dwn.js.map +1 -1
- package/dist/types/anonymous-dwn-api.d.ts +3 -3
- package/dist/types/anonymous-dwn-api.d.ts.map +1 -1
- package/dist/types/connect.d.ts.map +1 -1
- package/dist/types/dwn-api.d.ts +11 -18
- package/dist/types/dwn-api.d.ts.map +1 -1
- package/dist/types/dwn-protocol-cache.d.ts +76 -0
- package/dist/types/dwn-protocol-cache.d.ts.map +1 -0
- package/dist/types/hd-identity-vault.d.ts.map +1 -1
- package/dist/types/identity-api.d.ts.map +1 -1
- package/dist/types/oidc.d.ts.map +1 -1
- package/dist/types/permissions-api.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe.d.ts +12 -2
- package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -1
- package/dist/types/sync-api.d.ts +3 -4
- package/dist/types/sync-api.d.ts.map +1 -1
- package/dist/types/sync-engine-level.d.ts +63 -5
- package/dist/types/sync-engine-level.d.ts.map +1 -1
- package/dist/types/test-harness.d.ts.map +1 -1
- package/dist/types/types/dwn.d.ts +18 -19
- package/dist/types/types/dwn.d.ts.map +1 -1
- package/dist/types/types/sync.d.ts +47 -5
- package/dist/types/types/sync.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/anonymous-dwn-api.ts +4 -4
- package/src/connect.ts +4 -10
- package/src/dwn-api.ts +192 -250
- package/src/dwn-protocol-cache.ts +216 -0
- package/src/dwn-record-upgrade.ts +3 -3
- package/src/hd-identity-vault.ts +6 -5
- package/src/identity-api.ts +0 -2
- package/src/oidc.ts +2 -1
- package/src/permissions-api.ts +28 -6
- package/src/prototyping/crypto/jose/jwe-flattened.ts +4 -1
- package/src/prototyping/crypto/jose/jwe.ts +24 -2
- package/src/store-data-protocols.ts +2 -2
- package/src/sync-api.ts +7 -3
- package/src/sync-engine-level.ts +509 -32
- package/src/test-harness.ts +3 -5
- package/src/types/dwn.ts +19 -21
- package/src/types/sync.ts +56 -5
package/src/types/dwn.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
MessagesSubscribeReply,
|
|
12
12
|
MessagesSyncMessage,
|
|
13
13
|
MessagesSyncReply,
|
|
14
|
-
MessageSubscriptionHandler,
|
|
15
14
|
ProtocolsConfigureMessage,
|
|
16
15
|
ProtocolsConfigureOptions,
|
|
17
16
|
ProtocolsQueryMessage,
|
|
@@ -28,9 +27,9 @@ import type {
|
|
|
28
27
|
RecordsSubscribeMessage,
|
|
29
28
|
RecordsSubscribeOptions,
|
|
30
29
|
RecordsSubscribeReply,
|
|
31
|
-
RecordSubscriptionHandler,
|
|
32
30
|
RecordsWriteMessage,
|
|
33
31
|
RecordsWriteOptions,
|
|
32
|
+
SubscriptionListener,
|
|
34
33
|
} from '@enbox/dwn-sdk-js';
|
|
35
34
|
|
|
36
35
|
import type { MessagesSyncOptions } from '@enbox/dwn-sdk-js';
|
|
@@ -54,38 +53,37 @@ import {
|
|
|
54
53
|
* Represents a Decentralized Web Node (DWN) service in a DID Document.
|
|
55
54
|
*
|
|
56
55
|
* A DWN DID service is a specialized type of DID service with the `type` set to
|
|
57
|
-
* `DecentralizedWebNode`.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
56
|
+
* `DecentralizedWebNode`. Encryption and signing keys are resolved from the DID document's
|
|
57
|
+
* verification methods, not from the service entry.
|
|
58
|
+
*
|
|
59
|
+
* The `enc` and `sig` properties are optional legacy fields that may be present on existing
|
|
60
|
+
* DID documents for backward compatibility. New implementations should resolve keys from the
|
|
61
|
+
* DID document's verification methods by purpose (`keyAgreement` for encryption,
|
|
62
|
+
* `authentication`/`assertionMethod` for signing).
|
|
63
63
|
*
|
|
64
64
|
* @example
|
|
65
65
|
* ```ts
|
|
66
66
|
* const service: DwnDidService = {
|
|
67
67
|
* id: 'did:example:123#dwn',
|
|
68
68
|
* type: 'DecentralizedWebNode',
|
|
69
|
-
* serviceEndpoint: 'https://enbox-dwn.fly.dev'
|
|
70
|
-
* enc: 'did:example:123#key-1',
|
|
71
|
-
* sig: 'did:example:123#key-2'
|
|
69
|
+
* serviceEndpoint: 'https://enbox-dwn.fly.dev'
|
|
72
70
|
* }
|
|
73
71
|
* ```
|
|
74
72
|
*
|
|
75
|
-
* @see {@link https://
|
|
73
|
+
* @see {@link https://github.com/enboxorg/dwn-spec | Enbox DWN Specification}
|
|
76
74
|
*/
|
|
77
75
|
export interface DwnDidService extends DidService {
|
|
78
76
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
77
|
+
* @deprecated Optional legacy field. Resolve encryption keys from the DID document's
|
|
78
|
+
* `keyAgreement` verification methods instead.
|
|
81
79
|
*/
|
|
82
80
|
enc?: string | string[];
|
|
83
81
|
|
|
84
82
|
/**
|
|
85
|
-
*
|
|
86
|
-
* or
|
|
83
|
+
* @deprecated Optional legacy field. Resolve signing keys from the DID document's
|
|
84
|
+
* `authentication` or `assertionMethod` verification methods instead.
|
|
87
85
|
*/
|
|
88
|
-
sig
|
|
86
|
+
sig?: string | string[];
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
export enum DwnInterface {
|
|
@@ -158,8 +156,8 @@ export interface DwnMessageReply {
|
|
|
158
156
|
}
|
|
159
157
|
|
|
160
158
|
export interface MessageHandler {
|
|
161
|
-
[DwnInterface.MessagesSubscribe] :
|
|
162
|
-
[DwnInterface.RecordsSubscribe] :
|
|
159
|
+
[DwnInterface.MessagesSubscribe] : SubscriptionListener;
|
|
160
|
+
[DwnInterface.RecordsSubscribe] : SubscriptionListener;
|
|
163
161
|
|
|
164
162
|
// define all of them individually as undefined
|
|
165
163
|
[DwnInterface.MessagesRead] : undefined;
|
|
@@ -273,7 +271,6 @@ export type {
|
|
|
273
271
|
DataEncodedRecordsWriteMessage as DwnDataEncodedRecordsWriteMessage,
|
|
274
272
|
MessageSigner as DwnSigner,
|
|
275
273
|
MessageSubscription as DwnMessageSubscription,
|
|
276
|
-
MessageSubscriptionHandler as DwnMessageSubscriptionHandler,
|
|
277
274
|
MessagesPermissionScope as DwnMessagesPermissionScope,
|
|
278
275
|
PaginationCursor as DwnPaginationCursor,
|
|
279
276
|
PermissionConditions as DwnPermissionConditions,
|
|
@@ -283,6 +280,7 @@ export type {
|
|
|
283
280
|
ProtocolDefinition as DwnProtocolDefinition,
|
|
284
281
|
ProtocolPermissionScope as DwnProtocolPermissionScope,
|
|
285
282
|
PublicKeyJwk as DwnPublicKeyJwk,
|
|
286
|
-
RecordSubscriptionHandler as DwnRecordSubscriptionHandler,
|
|
287
283
|
RecordsPermissionScope as DwnRecordsPermissionScope,
|
|
284
|
+
SubscriptionListener as DwnSubscriptionListener,
|
|
285
|
+
SubscriptionMessage as DwnSubscriptionMessage,
|
|
288
286
|
} from '@enbox/dwn-sdk-js';
|
package/src/types/sync.ts
CHANGED
|
@@ -11,13 +11,62 @@ export type SyncIdentityOptions = {
|
|
|
11
11
|
/**
|
|
12
12
|
* The protocols that should be synced for this identity, if an empty array is provided, all messages for all protocols will be synced.
|
|
13
13
|
*/
|
|
14
|
-
protocols: string[]
|
|
14
|
+
protocols: string[];
|
|
15
15
|
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Connectivity state of the sync engine.
|
|
19
|
+
*/
|
|
20
|
+
export type SyncConnectivityState = 'online' | 'offline' | 'unknown';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Describes the sync mode: `'poll'` for periodic SMT reconciliation,
|
|
24
|
+
* `'live'` for `MessagesSubscribe`-based real-time sync with SMT fallback.
|
|
25
|
+
*/
|
|
26
|
+
export type SyncMode = 'poll' | 'live';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parameters for {@link SyncEngine.startSync}.
|
|
30
|
+
*/
|
|
31
|
+
export type StartSyncParams = {
|
|
32
|
+
/**
|
|
33
|
+
* The sync mode to use. Default: `'poll'`.
|
|
34
|
+
*
|
|
35
|
+
* - `'live'`: Opens `MessagesSubscribe` WebSocket subscriptions to remote
|
|
36
|
+
* DWNs for real-time pull, and listens to the local EventLog for immediate
|
|
37
|
+
* push. Falls back to SMT reconciliation on cold start or long disconnect.
|
|
38
|
+
* An infrequent SMT integrity check still runs at `interval`.
|
|
39
|
+
*
|
|
40
|
+
* - `'poll'`: Legacy mode. Performs a full SMT set-reconciliation sync on a
|
|
41
|
+
* fixed interval. No WebSocket subscriptions are used.
|
|
42
|
+
*/
|
|
43
|
+
mode?: SyncMode;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The interval at which the sync operation should be performed.
|
|
47
|
+
* Accepts any value recognised by `ms()`, e.g. `'30s'`, `'2m'`, `'10m'`.
|
|
48
|
+
*
|
|
49
|
+
* In `'live'` mode this controls the frequency of the SMT integrity check.
|
|
50
|
+
* In `'poll'` mode this controls the polling frequency.
|
|
51
|
+
*
|
|
52
|
+
* Default: `'2m'` (in poll mode), `'5m'` (in live mode).
|
|
53
|
+
*/
|
|
54
|
+
interval?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
16
57
|
export interface SyncEngine {
|
|
17
58
|
/**
|
|
18
59
|
* The agent that the SyncEngine is attached to.
|
|
19
60
|
*/
|
|
20
61
|
agent: Web5PlatformAgent;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Current connectivity state as observed by the sync engine.
|
|
65
|
+
* Updated when WebSocket subscriptions connect/disconnect or when the
|
|
66
|
+
* browser `online`/`offline` events fire.
|
|
67
|
+
*/
|
|
68
|
+
readonly connectivityState: SyncConnectivityState;
|
|
69
|
+
|
|
21
70
|
/**
|
|
22
71
|
* Register an identity to be managed by the SyncEngine for syncing.
|
|
23
72
|
* The options can define specific protocols that should only be synced, or a delegate DID that should be used to sign the sync messages.
|
|
@@ -43,11 +92,13 @@ export interface SyncEngine {
|
|
|
43
92
|
*/
|
|
44
93
|
sync(direction?: 'push' | 'pull'): Promise<void>;
|
|
45
94
|
/**
|
|
46
|
-
* Starts
|
|
95
|
+
* Starts sync. In `'live'` mode opens real-time subscriptions with SMT
|
|
96
|
+
* fallback; in `'poll'` mode uses periodic SMT reconciliation.
|
|
47
97
|
*
|
|
48
|
-
*
|
|
98
|
+
* Subsequent calls update the mode/interval. Calling with a different mode
|
|
99
|
+
* tears down the previous mode's resources before starting the new one.
|
|
49
100
|
*/
|
|
50
|
-
startSync(params:
|
|
101
|
+
startSync(params: StartSyncParams): Promise<void>;
|
|
51
102
|
/**
|
|
52
103
|
* Stops the periodic sync operation, will complete the current sync operation if one is already in progress.
|
|
53
104
|
*
|
|
@@ -55,4 +106,4 @@ export interface SyncEngine {
|
|
|
55
106
|
* @throws {Error} if the sync operation fails to stop before the timeout.
|
|
56
107
|
*/
|
|
57
108
|
stopSync(timeout?: number): Promise<void>;
|
|
58
|
-
}
|
|
109
|
+
}
|