@coasys/ad4m 0.13.1-staging.6 → 0.13.1-staging.7
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/lib/index.cjs +1130 -650
- package/lib/index.js +1130 -651
- package/lib/src/Ad4mClient.d.ts +3 -0
- package/lib/src/Ad4mClient.js +9 -2
- package/lib/src/agent/Agent.d.ts +5 -1
- package/lib/src/agent/Agent.js +3 -0
- package/lib/src/agent/AgentClient.d.ts +3 -0
- package/lib/src/agent/AgentClient.js +3 -0
- package/lib/src/agent/AgentStatus.d.ts +2 -0
- package/lib/src/agent/AgentStatus.js +2 -0
- package/lib/src/apiClient.d.ts +41 -0
- package/lib/src/apiClient.js +138 -1
- package/lib/src/generated/api/AgentStatus.d.ts +5 -0
- package/lib/src/generated/api/AgentWithIdentity.d.ts +14 -0
- package/lib/src/generated/api/AgentWithIdentity.js +1 -0
- package/lib/src/generated/api/BotView.d.ts +7 -0
- package/lib/src/generated/api/BotView.js +2 -0
- package/lib/src/generated/api/ClaimOfferParams.d.ts +13 -0
- package/lib/src/generated/api/ClaimOfferParams.js +2 -0
- package/lib/src/generated/api/ClaimOfferResult.d.ts +14 -0
- package/lib/src/generated/api/ClaimOfferResult.js +1 -0
- package/lib/src/generated/api/ClaimView.d.ts +11 -0
- package/lib/src/generated/api/ClaimView.js +2 -0
- package/lib/src/generated/api/CosignInceptParams.d.ts +10 -0
- package/lib/src/generated/api/CosignInceptParams.js +1 -0
- package/lib/src/generated/api/DeviceView.d.ts +17 -0
- package/lib/src/generated/api/DeviceView.js +1 -0
- package/lib/src/generated/api/DidBotScope.d.ts +7 -0
- package/lib/src/generated/api/DidBotScope.js +2 -0
- package/lib/src/generated/api/DidDocument.d.ts +16 -0
- package/lib/src/generated/api/DidDocument.js +1 -0
- package/lib/src/generated/api/DidDocumentMetadata.d.ts +18 -0
- package/lib/src/generated/api/DidDocumentMetadata.js +2 -0
- package/lib/src/generated/api/DidResolutionMetadata.d.ts +51 -0
- package/lib/src/generated/api/DidResolutionMetadata.js +1 -0
- package/lib/src/generated/api/DidResolutionResult.d.ts +16 -0
- package/lib/src/generated/api/DidResolutionResult.js +1 -0
- package/lib/src/generated/api/DidVerificationMethod.d.ts +17 -0
- package/lib/src/generated/api/DidVerificationMethod.js +1 -0
- package/lib/src/generated/api/Events.d.ts +2 -0
- package/lib/src/generated/api/ForkRecord.d.ts +11 -0
- package/lib/src/generated/api/ForkRecord.js +2 -0
- package/lib/src/generated/api/IdentityForkEvent.d.ts +10 -0
- package/lib/src/generated/api/IdentityForkEvent.js +2 -0
- package/lib/src/generated/api/IdentityLog.d.ts +18 -0
- package/lib/src/generated/api/IdentityLog.js +1 -0
- package/lib/src/generated/api/IdentityStatus.d.ts +48 -0
- package/lib/src/generated/api/IdentityStatus.js +1 -0
- package/lib/src/generated/api/JoinStatus.d.ts +10 -0
- package/lib/src/generated/api/JoinStatus.js +2 -0
- package/lib/src/generated/api/JoinStatusParams.d.ts +6 -0
- package/lib/src/generated/api/JoinStatusParams.js +2 -0
- package/lib/src/generated/api/LogParams.d.ts +17 -0
- package/lib/src/generated/api/LogParams.js +2 -0
- package/lib/src/generated/api/Offer.d.ts +14 -0
- package/lib/src/generated/api/Offer.js +1 -0
- package/lib/src/generated/api/OfferKind.d.ts +4 -0
- package/lib/src/generated/api/OfferKind.js +2 -0
- package/lib/src/generated/api/OfferListing.d.ts +9 -0
- package/lib/src/generated/api/OfferListing.js +1 -0
- package/lib/src/generated/api/OfferOpened.d.ts +6 -0
- package/lib/src/generated/api/OfferOpened.js +2 -0
- package/lib/src/generated/api/OfferState.d.ts +21 -0
- package/lib/src/generated/api/OfferState.js +1 -0
- package/lib/src/generated/api/OffersParams.d.ts +11 -0
- package/lib/src/generated/api/OffersParams.js +1 -0
- package/lib/src/generated/api/OpenOfferParams.d.ts +7 -0
- package/lib/src/generated/api/OpenOfferParams.js +1 -0
- package/lib/src/generated/api/PublishParams.d.ts +11 -0
- package/lib/src/generated/api/PublishParams.js +1 -0
- package/lib/src/generated/api/RequestBody.d.ts +15 -0
- package/lib/src/generated/api/RequestBody.js +2 -0
- package/lib/src/generated/api/ResetLogParams.d.ts +9 -0
- package/lib/src/generated/api/ResetLogParams.js +2 -0
- package/lib/src/generated/api/ResolveParams.d.ts +18 -0
- package/lib/src/generated/api/ResolveParams.js +2 -0
- package/lib/src/generated/api/RpcMethods.d.ts +68 -1
- package/lib/src/generated/api/RpcMethods.js +6 -0
- package/lib/src/generated/api/SignedBy.d.ts +8 -0
- package/lib/src/generated/api/SignedBy.js +2 -0
- package/lib/src/generated/api/SignedHead.d.ts +14 -0
- package/lib/src/generated/api/SignedHead.js +2 -0
- package/lib/src/generated/api/SignedOffer.d.ts +10 -0
- package/lib/src/generated/api/SignedOffer.js +1 -0
- package/lib/src/generated/api/SignedRequest.d.ts +8 -0
- package/lib/src/generated/api/SignedRequest.js +1 -0
- package/lib/src/generated/api/SkippedSource.d.ts +7 -0
- package/lib/src/generated/api/SkippedSource.js +2 -0
- package/lib/src/generated/api/StoreBehind.d.ts +13 -0
- package/lib/src/generated/api/StoreBehind.js +2 -0
- package/lib/src/generated/api/StoreInfo.d.ts +15 -0
- package/lib/src/generated/api/StoreInfo.js +2 -0
- package/lib/src/generated/api/index.d.ts +38 -0
- package/lib/src/identity/IdentityClient.d.ts +70 -0
- package/lib/src/identity/IdentityClient.js +97 -0
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.js +1 -0
- package/lib/src/model/Ad4mModel.d.ts +4 -0
- package/lib/src/model/Ad4mModel.js +12 -1
- package/lib/src/neighbourhood/MeshManager.d.ts +24 -0
- package/lib/src/neighbourhood/MeshManager.js +42 -1
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +10 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.js +16 -0
- package/lib/src/neighbourhood/Session.js +2 -0
- package/lib/src/neighbourhood/SfuManager.d.ts +30 -3
- package/lib/src/neighbourhood/SfuManager.js +78 -41
- package/lib/src/perspectives/FlowInstance.js +6 -4
- package/lib/src/shacl/SHACLFlow.d.ts +5 -3
- package/lib/src/shacl/SHACLFlow.js +121 -5
- package/package.json +2 -2
- package/src/Ad4mClient.test.ts +64 -4
- package/src/Ad4mClient.ts +8 -0
- package/src/agent/Agent.ts +9 -1
- package/src/agent/AgentClient.ts +5 -1
- package/src/agent/AgentStatus.ts +4 -0
- package/src/apiClient.test.ts +302 -0
- package/src/apiClient.ts +136 -1
- package/src/generated/api/AgentStatus.ts +6 -1
- package/src/generated/api/AgentWithIdentity.ts +12 -0
- package/src/generated/api/BotView.ts +6 -0
- package/src/generated/api/ClaimOfferParams.ts +14 -0
- package/src/generated/api/ClaimOfferResult.ts +11 -0
- package/src/generated/api/ClaimView.ts +6 -0
- package/src/generated/api/CosignInceptParams.ts +11 -0
- package/src/generated/api/DeviceView.ts +12 -0
- package/src/generated/api/DidBotScope.ts +6 -0
- package/src/generated/api/DidDocument.ts +8 -0
- package/src/generated/api/DidDocumentMetadata.ts +19 -0
- package/src/generated/api/DidResolutionMetadata.ts +52 -0
- package/src/generated/api/DidResolutionResult.ts +13 -0
- package/src/generated/api/DidVerificationMethod.ts +15 -0
- package/src/generated/api/Events.ts +2 -0
- package/src/generated/api/ForkRecord.ts +9 -0
- package/src/generated/api/IdentityForkEvent.ts +7 -0
- package/src/generated/api/IdentityLog.ts +17 -0
- package/src/generated/api/IdentityStatus.ts +49 -0
- package/src/generated/api/JoinStatus.ts +7 -0
- package/src/generated/api/JoinStatusParams.ts +6 -0
- package/src/generated/api/LogParams.ts +18 -0
- package/src/generated/api/Offer.ts +8 -0
- package/src/generated/api/OfferKind.ts +6 -0
- package/src/generated/api/OfferListing.ts +8 -0
- package/src/generated/api/OfferOpened.ts +6 -0
- package/src/generated/api/OfferState.ts +7 -0
- package/src/generated/api/OffersParams.ts +11 -0
- package/src/generated/api/OpenOfferParams.ts +7 -0
- package/src/generated/api/PublishParams.ts +12 -0
- package/src/generated/api/RequestBody.ts +7 -0
- package/src/generated/api/ResetLogParams.ts +10 -0
- package/src/generated/api/ResolveParams.ts +19 -0
- package/src/generated/api/RpcMethods.ts +38 -1
- package/src/generated/api/SignedBy.ts +6 -0
- package/src/generated/api/SignedHead.ts +10 -0
- package/src/generated/api/SignedOffer.ts +8 -0
- package/src/generated/api/SignedRequest.ts +7 -0
- package/src/generated/api/SkippedSource.ts +6 -0
- package/src/generated/api/StoreBehind.ts +14 -0
- package/src/generated/api/StoreInfo.ts +16 -0
- package/src/generated/api/index.ts +39 -0
- package/src/identity/IdentityClient.ts +111 -0
- package/src/index.ts +1 -0
- package/src/model/Ad4mModel.ts +11 -1
- package/src/model/write-round-trips.test.ts +111 -2
- package/src/neighbourhood/MeshManager.test.ts +87 -0
- package/src/neighbourhood/MeshManager.ts +50 -1
- package/src/neighbourhood/NeighbourhoodClient.test.ts +27 -0
- package/src/neighbourhood/NeighbourhoodClient.ts +19 -0
- package/src/neighbourhood/Session.test.ts +5 -0
- package/src/neighbourhood/Session.ts +2 -0
- package/src/neighbourhood/SfuManager.test.ts +293 -0
- package/src/neighbourhood/SfuManager.ts +92 -45
- package/src/perspectives/FlowInstance.ts +6 -4
- package/src/shacl/SHACLFlow.test.ts +221 -0
- package/src/shacl/SHACLFlow.ts +121 -5
package/lib/src/Ad4mClient.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { PerspectiveClient } from './perspectives/PerspectiveClient';
|
|
|
5
5
|
import { RuntimeClient } from './runtime/RuntimeClient';
|
|
6
6
|
import { ExpressionClient } from './expression/ExpressionClient';
|
|
7
7
|
import { AIClient } from './ai/AIClient';
|
|
8
|
+
import { IdentityClient } from './identity/IdentityClient';
|
|
8
9
|
import { EventFilter } from './apiClient';
|
|
9
10
|
import type { EventMap, EventName } from './generated/api/Events';
|
|
10
11
|
/**
|
|
@@ -31,6 +32,8 @@ export declare class Ad4mClient {
|
|
|
31
32
|
get perspective(): PerspectiveClient;
|
|
32
33
|
get runtime(): RuntimeClient;
|
|
33
34
|
get ai(): AIClient;
|
|
35
|
+
/** The executor's identity calls (`did:scid:coasys:1`). */
|
|
36
|
+
get identity(): IdentityClient;
|
|
34
37
|
/**
|
|
35
38
|
* Call `handler` with every `type` event, or only those about
|
|
36
39
|
* `filter.perspective`. The payload is typed by the executor's event
|
package/lib/src/Ad4mClient.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Ad4mClient_baseUrl, _Ad4mClient_token, _Ad4mClient_apiClient, _Ad4mClient_agentClient, _Ad4mClient_expressionClient, _Ad4mClient_languageClient, _Ad4mClient_neighbourhoodClient, _Ad4mClient_perspectiveClient, _Ad4mClient_runtimeClient, _Ad4mClient_aiClient;
|
|
12
|
+
var _Ad4mClient_baseUrl, _Ad4mClient_token, _Ad4mClient_apiClient, _Ad4mClient_agentClient, _Ad4mClient_expressionClient, _Ad4mClient_languageClient, _Ad4mClient_neighbourhoodClient, _Ad4mClient_perspectiveClient, _Ad4mClient_runtimeClient, _Ad4mClient_aiClient, _Ad4mClient_identityClient;
|
|
13
13
|
import { AgentClient } from './agent/AgentClient';
|
|
14
14
|
import { LanguageClient } from './language/LanguageClient';
|
|
15
15
|
import { NeighbourhoodClient } from './neighbourhood/NeighbourhoodClient';
|
|
@@ -17,6 +17,7 @@ import { PerspectiveClient } from './perspectives/PerspectiveClient';
|
|
|
17
17
|
import { RuntimeClient } from './runtime/RuntimeClient';
|
|
18
18
|
import { ExpressionClient } from './expression/ExpressionClient';
|
|
19
19
|
import { AIClient } from './ai/AIClient';
|
|
20
|
+
import { IdentityClient } from './identity/IdentityClient';
|
|
20
21
|
import { ApiClient } from './apiClient';
|
|
21
22
|
import { Ad4mModel } from './model/Ad4mModel';
|
|
22
23
|
/**
|
|
@@ -42,6 +43,7 @@ export class Ad4mClient {
|
|
|
42
43
|
_Ad4mClient_perspectiveClient.set(this, void 0);
|
|
43
44
|
_Ad4mClient_runtimeClient.set(this, void 0);
|
|
44
45
|
_Ad4mClient_aiClient.set(this, void 0);
|
|
46
|
+
_Ad4mClient_identityClient.set(this, void 0);
|
|
45
47
|
__classPrivateFieldSet(this, _Ad4mClient_baseUrl, baseUrl, "f");
|
|
46
48
|
__classPrivateFieldSet(this, _Ad4mClient_token, token, "f");
|
|
47
49
|
__classPrivateFieldSet(this, _Ad4mClient_apiClient, new ApiClient(baseUrl, token, options?.webSocketImpl, options?.fetchImpl), "f");
|
|
@@ -55,6 +57,7 @@ export class Ad4mClient {
|
|
|
55
57
|
__classPrivateFieldGet(this, _Ad4mClient_perspectiveClient, "f").setNeighbourhoodClient(__classPrivateFieldGet(this, _Ad4mClient_neighbourhoodClient, "f"));
|
|
56
58
|
__classPrivateFieldGet(this, _Ad4mClient_perspectiveClient, "f").setAIClient(__classPrivateFieldGet(this, _Ad4mClient_aiClient, "f"));
|
|
57
59
|
__classPrivateFieldSet(this, _Ad4mClient_runtimeClient, new RuntimeClient(baseUrl, token, __classPrivateFieldGet(this, _Ad4mClient_apiClient, "f")), "f");
|
|
60
|
+
__classPrivateFieldSet(this, _Ad4mClient_identityClient, new IdentityClient(baseUrl, token, __classPrivateFieldGet(this, _Ad4mClient_apiClient, "f")), "f");
|
|
58
61
|
// Register with AD4M DevTools if the bridge is installed (e.g. browser extension)
|
|
59
62
|
try {
|
|
60
63
|
const dt = globalThis.__AD4M_DEVTOOLS__;
|
|
@@ -86,6 +89,10 @@ export class Ad4mClient {
|
|
|
86
89
|
get ai() {
|
|
87
90
|
return __classPrivateFieldGet(this, _Ad4mClient_aiClient, "f");
|
|
88
91
|
}
|
|
92
|
+
/** The executor's identity calls (`did:scid:coasys:1`). */
|
|
93
|
+
get identity() {
|
|
94
|
+
return __classPrivateFieldGet(this, _Ad4mClient_identityClient, "f");
|
|
95
|
+
}
|
|
89
96
|
/**
|
|
90
97
|
* Call `handler` with every `type` event, or only those about
|
|
91
98
|
* `filter.perspective`. The payload is typed by the executor's event
|
|
@@ -118,4 +125,4 @@ export class Ad4mClient {
|
|
|
118
125
|
__classPrivateFieldGet(this, _Ad4mClient_apiClient, "f").closeAll();
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
|
-
_Ad4mClient_baseUrl = new WeakMap(), _Ad4mClient_token = new WeakMap(), _Ad4mClient_apiClient = new WeakMap(), _Ad4mClient_agentClient = new WeakMap(), _Ad4mClient_expressionClient = new WeakMap(), _Ad4mClient_languageClient = new WeakMap(), _Ad4mClient_neighbourhoodClient = new WeakMap(), _Ad4mClient_perspectiveClient = new WeakMap(), _Ad4mClient_runtimeClient = new WeakMap(), _Ad4mClient_aiClient = new WeakMap();
|
|
128
|
+
_Ad4mClient_baseUrl = new WeakMap(), _Ad4mClient_token = new WeakMap(), _Ad4mClient_apiClient = new WeakMap(), _Ad4mClient_agentClient = new WeakMap(), _Ad4mClient_expressionClient = new WeakMap(), _Ad4mClient_languageClient = new WeakMap(), _Ad4mClient_neighbourhoodClient = new WeakMap(), _Ad4mClient_perspectiveClient = new WeakMap(), _Ad4mClient_runtimeClient = new WeakMap(), _Ad4mClient_aiClient = new WeakMap(), _Ad4mClient_identityClient = new WeakMap();
|
package/lib/src/agent/Agent.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Perspective } from "../perspectives/Perspective";
|
|
2
2
|
import type { Agent as WireAgent } from "../generated/api/Agent";
|
|
3
|
+
import type { AgentWithIdentity } from "../generated/api/AgentWithIdentity";
|
|
3
4
|
/** AD4M's representation of an Agent
|
|
4
5
|
*
|
|
5
6
|
* AD4M Agents are build around DIDs, which are used to identify and authenticate the Agent.
|
|
@@ -30,9 +31,12 @@ export declare class Agent {
|
|
|
30
31
|
perspective?: Perspective;
|
|
31
32
|
/** Address of the Language by which the Agent will receive DMs */
|
|
32
33
|
directMessageLanguage?: string;
|
|
34
|
+
/** The `did:scid` this agent speaks for (`agent.me()`); absent when it speaks for no one,
|
|
35
|
+
* and on agents read from the agent language. `did` stays the device `did:key`. */
|
|
36
|
+
identity?: string;
|
|
33
37
|
constructor(did: string, perspective?: Perspective);
|
|
34
38
|
/** Build an Agent (with its perspective's query helpers) from the executor's wire shape. */
|
|
35
|
-
static fromWire(wire: WireAgent): Agent;
|
|
39
|
+
static fromWire(wire: WireAgent | AgentWithIdentity): Agent;
|
|
36
40
|
}
|
|
37
41
|
declare const AgentExpression_base: abstract new (author?: string, timestamp?: string, data?: Agent, proof?: import("../expression/Expression").ExpressionProof) => import("../expression/Expression").ExpressionShape<Agent, import("../expression/Expression").ExpressionProof>;
|
|
38
42
|
export declare class AgentExpression extends AgentExpression_base {
|
package/lib/src/agent/Agent.js
CHANGED
|
@@ -30,6 +30,9 @@ export class Agent {
|
|
|
30
30
|
static fromWire(wire) {
|
|
31
31
|
const agent = new Agent(wire.did, Perspective.fromWire(wire.perspective));
|
|
32
32
|
agent.directMessageLanguage = wire.directMessageLanguage;
|
|
33
|
+
if ("identity" in wire && wire.identity) {
|
|
34
|
+
agent.identity = wire.identity;
|
|
35
|
+
}
|
|
33
36
|
return agent;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
@@ -22,6 +22,9 @@ export declare class AgentClient {
|
|
|
22
22
|
constructor(baseUrl: string, token?: string, sharedApiClient?: ApiClient);
|
|
23
23
|
me(): Promise<Agent>;
|
|
24
24
|
status(): Promise<AgentStatus>;
|
|
25
|
+
/** Creates the agent's keys and DID on first run. The executor refuses (409)
|
|
26
|
+
* an agent that is already initialised — {@link unlock} it instead; a second
|
|
27
|
+
* `generate` never replaces the existing keys and DID. */
|
|
25
28
|
generate(passphrase: string, options?: CallOptions): Promise<AgentStatus>;
|
|
26
29
|
import(args: InitializeArgs): Promise<AgentStatus>;
|
|
27
30
|
lock(passphrase: string): Promise<AgentStatus>;
|
|
@@ -50,6 +50,9 @@ export class AgentClient {
|
|
|
50
50
|
const agentStatus = await __classPrivateFieldGet(this, _AgentClient_apiClient, "f").call('agent.status', {});
|
|
51
51
|
return new AgentStatus(agentStatus);
|
|
52
52
|
}
|
|
53
|
+
/** Creates the agent's keys and DID on first run. The executor refuses (409)
|
|
54
|
+
* an agent that is already initialised — {@link unlock} it instead; a second
|
|
55
|
+
* `generate` never replaces the existing keys and DID. */
|
|
53
56
|
async generate(passphrase, options) {
|
|
54
57
|
const result = await __classPrivateFieldGet(this, _AgentClient_apiClient, "f").call('agent.generate', { passphrase }, options);
|
|
55
58
|
return new AgentStatus(result);
|
package/lib/src/apiClient.d.ts
CHANGED
|
@@ -64,15 +64,40 @@ export declare class ApiClient {
|
|
|
64
64
|
* A message from the socket does not move it back: hearing from the executor says nothing
|
|
65
65
|
* about how much of a large upload has reached it. */
|
|
66
66
|
private _wsSentBy;
|
|
67
|
+
/** A `checkConnection` probe waiting for the open socket to say anything; null when none. */
|
|
68
|
+
private _wsProbeTimer;
|
|
67
69
|
private _watching;
|
|
68
70
|
private _watchScheduled;
|
|
69
71
|
private _watchDone;
|
|
70
72
|
private _watchSent;
|
|
71
73
|
private _watchRetries;
|
|
72
74
|
private _watchRetryTimer;
|
|
75
|
+
private _networkCallbacks;
|
|
76
|
+
/** Removes the network-change listeners; null while not listening. */
|
|
77
|
+
private _unlistenNetwork;
|
|
78
|
+
/** A network change waits for its socket to open, then tells `onNetworkChange`. */
|
|
79
|
+
private _networkChanged;
|
|
80
|
+
/** The socket dialled for the last network change. */
|
|
81
|
+
private _networkDial;
|
|
73
82
|
private _getWsUrl;
|
|
74
83
|
private _ensureWs;
|
|
75
84
|
private _onOpen;
|
|
85
|
+
/**
|
|
86
|
+
* Hear of network changes where the platform says so: `online` on the
|
|
87
|
+
* global object (browsers, Deno) redials at once, and `change` on
|
|
88
|
+
* `navigator.connection` (Chromium) runs `checkConnection`. Elsewhere,
|
|
89
|
+
* e.g. Node, nothing is heard and the ping deadline notices a dead
|
|
90
|
+
* socket on its own.
|
|
91
|
+
*/
|
|
92
|
+
private _listenForNetworkChanges;
|
|
93
|
+
/**
|
|
94
|
+
* The network changed: the open socket most likely runs over a path that
|
|
95
|
+
* is gone, and nothing would say so before the ping deadline. Drop it as
|
|
96
|
+
* a silent socket is dropped and dial the next one now, without backoff.
|
|
97
|
+
* `onNetworkChange` callbacks fire once that socket opens.
|
|
98
|
+
*/
|
|
99
|
+
private _onNetworkChange;
|
|
100
|
+
private _notifyNetworkChange;
|
|
76
101
|
/** `reason` is set when the executor asked to try again later; calls that fail carry it. */
|
|
77
102
|
private _onClose;
|
|
78
103
|
/** The executor refused the token: fail every call with 401, stop
|
|
@@ -86,6 +111,7 @@ export declare class ApiClient {
|
|
|
86
111
|
* since the close frame gets no answer either; `_onClose` ignores it then. */
|
|
87
112
|
private _dropSilentSocket;
|
|
88
113
|
private _stopPing;
|
|
114
|
+
private _endProbe;
|
|
89
115
|
private _scheduleReconnect;
|
|
90
116
|
/** End the wait for the next dial, if one is pending, without dialling. */
|
|
91
117
|
private _cancelReconnect;
|
|
@@ -142,6 +168,21 @@ export declare class ApiClient {
|
|
|
142
168
|
* Does NOT fire on the initial connection — only on reconnects.
|
|
143
169
|
* Returns an unsubscribe function. */
|
|
144
170
|
onReconnect(callback: () => void): () => void;
|
|
171
|
+
/** Register a callback that fires after the network changed (`online`,
|
|
172
|
+
* or a socket that failed `checkConnection`), once the socket dialled for the
|
|
173
|
+
* new network is open and its event watch sent. Calls made from it go
|
|
174
|
+
* out on that socket. Returns an unsubscribe function. */
|
|
175
|
+
onNetworkChange(callback: () => void): () => void;
|
|
176
|
+
/**
|
|
177
|
+
* Check the open socket now rather than at the next ping: send a ping,
|
|
178
|
+
* and if nothing at all arrives on that socket within `deadlineMs`,
|
|
179
|
+
* treat it as a network change (drop it, dial the next one at once,
|
|
180
|
+
* `onNetworkChange` callbacks fire when it opens). Any message keeps it.
|
|
181
|
+
* For a caller that has seen its network path break, e.g. ICE going
|
|
182
|
+
* disconnected, where the platform fired no `online` event. Without an
|
|
183
|
+
* open socket, or while a check runs, this does nothing.
|
|
184
|
+
*/
|
|
185
|
+
checkConnection(deadlineMs?: number): void;
|
|
145
186
|
/** Register a callback that fires once when the executor refuses this
|
|
146
187
|
* client's token: a 401 reply, or a socket closed with code 1008. Every
|
|
147
188
|
* call then fails with a 401 `RpcError` and the client does not reconnect;
|
package/lib/src/apiClient.js
CHANGED
|
@@ -35,6 +35,12 @@ const SLOWEST_LINK_BYTES_PER_MS = 16; // 16 kB/s
|
|
|
35
35
|
* behind a large write. Shorter than PING_INTERVAL_MS, so the few ms a small
|
|
36
36
|
* frame adds before a ping on an idle socket never cost a ping interval. */
|
|
37
37
|
const PONG_RETURN_MS = 5000;
|
|
38
|
+
/** How long `checkConnection` waits for the open socket to say anything
|
|
39
|
+
* after its ping. If a large write sent before it may still be on the way,
|
|
40
|
+
* the wait lasts until that write could have crossed, as for the periodic
|
|
41
|
+
* ping, and half of this more for the pong. On a working path the pong is
|
|
42
|
+
* one round trip away. */
|
|
43
|
+
const CHECK_CONNECTION_DEADLINE_MS = 2000;
|
|
38
44
|
/** The bytes `text` takes as UTF-8, as a WebSocket text frame sends it. */
|
|
39
45
|
function utf8Length(text) {
|
|
40
46
|
let bytes = text.length;
|
|
@@ -88,6 +94,8 @@ export class ApiClient {
|
|
|
88
94
|
* A message from the socket does not move it back: hearing from the executor says nothing
|
|
89
95
|
* about how much of a large upload has reached it. */
|
|
90
96
|
this._wsSentBy = 0;
|
|
97
|
+
/** A `checkConnection` probe waiting for the open socket to say anything; null when none. */
|
|
98
|
+
this._wsProbeTimer = null;
|
|
91
99
|
// The executor sends a socket only the events it asked for (`events.watch`).
|
|
92
100
|
// What the executor has for the open socket, as sent; a new socket has `{}`.
|
|
93
101
|
this._watching = '{}';
|
|
@@ -97,6 +105,13 @@ export class ApiClient {
|
|
|
97
105
|
this._watchSent = Promise.resolve();
|
|
98
106
|
this._watchRetries = 0;
|
|
99
107
|
this._watchRetryTimer = null;
|
|
108
|
+
this._networkCallbacks = new Set();
|
|
109
|
+
/** Removes the network-change listeners; null while not listening. */
|
|
110
|
+
this._unlistenNetwork = null;
|
|
111
|
+
/** A network change waits for its socket to open, then tells `onNetworkChange`. */
|
|
112
|
+
this._networkChanged = false;
|
|
113
|
+
/** The socket dialled for the last network change. */
|
|
114
|
+
this._networkDial = null;
|
|
100
115
|
this._wakeListening = false;
|
|
101
116
|
/** `online` always; `visibilitychange` only when the page became visible. */
|
|
102
117
|
this._onWake = (event) => {
|
|
@@ -127,6 +142,7 @@ export class ApiClient {
|
|
|
127
142
|
return;
|
|
128
143
|
if (this._authFailed !== null)
|
|
129
144
|
throw new RpcError(401, this._authFailed);
|
|
145
|
+
this._listenForNetworkChanges();
|
|
130
146
|
// A dial ends any wait for one: a call or subscriber that dials during the backoff
|
|
131
147
|
// leaves no timer behind to swallow the retry after this socket's own drop.
|
|
132
148
|
this._cancelReconnect();
|
|
@@ -154,8 +170,10 @@ export class ApiClient {
|
|
|
154
170
|
// Only watchApplied() awaits this; a close before open is not an error otherwise.
|
|
155
171
|
this._wsOpen.catch(() => { });
|
|
156
172
|
ws.onmessage = (event) => {
|
|
157
|
-
if (this._ws === ws)
|
|
173
|
+
if (this._ws === ws) {
|
|
158
174
|
this._wsPingedAt = null;
|
|
175
|
+
this._endProbe();
|
|
176
|
+
}
|
|
159
177
|
let parsed;
|
|
160
178
|
try {
|
|
161
179
|
parsed = JSON.parse(event.data);
|
|
@@ -227,6 +245,70 @@ export class ApiClient {
|
|
|
227
245
|
}
|
|
228
246
|
}
|
|
229
247
|
this._hasConnectedOnce = true;
|
|
248
|
+
if (this._networkChanged) {
|
|
249
|
+
this._networkChanged = false;
|
|
250
|
+
this._notifyNetworkChange();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Hear of network changes where the platform says so: `online` on the
|
|
255
|
+
* global object (browsers, Deno) redials at once, and `change` on
|
|
256
|
+
* `navigator.connection` (Chromium) runs `checkConnection`. Elsewhere,
|
|
257
|
+
* e.g. Node, nothing is heard and the ping deadline notices a dead
|
|
258
|
+
* socket on its own.
|
|
259
|
+
*/
|
|
260
|
+
_listenForNetworkChanges() {
|
|
261
|
+
if (this._unlistenNetwork)
|
|
262
|
+
return;
|
|
263
|
+
const handler = () => this._onNetworkChange();
|
|
264
|
+
const removers = [];
|
|
265
|
+
const target = globalThis;
|
|
266
|
+
if (typeof target.addEventListener === 'function') {
|
|
267
|
+
target.addEventListener('online', handler);
|
|
268
|
+
removers.push(() => target.removeEventListener?.('online', handler));
|
|
269
|
+
}
|
|
270
|
+
const connection = globalThis.navigator?.connection;
|
|
271
|
+
if (typeof connection?.addEventListener === 'function') {
|
|
272
|
+
// `change` also fires when Chromium's downlink or rtt estimate
|
|
273
|
+
// moves, as a busy call makes it do: probe rather than drop.
|
|
274
|
+
const probe = () => this.checkConnection();
|
|
275
|
+
connection.addEventListener('change', probe);
|
|
276
|
+
removers.push(() => connection.removeEventListener?.('change', probe));
|
|
277
|
+
}
|
|
278
|
+
this._unlistenNetwork = () => { for (const remove of removers)
|
|
279
|
+
remove(); };
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The network changed: the open socket most likely runs over a path that
|
|
283
|
+
* is gone, and nothing would say so before the ping deadline. Drop it as
|
|
284
|
+
* a silent socket is dropped and dial the next one now, without backoff.
|
|
285
|
+
* `onNetworkChange` callbacks fire once that socket opens.
|
|
286
|
+
*/
|
|
287
|
+
_onNetworkChange() {
|
|
288
|
+
if (this._authFailed !== null)
|
|
289
|
+
return;
|
|
290
|
+
const ws = this._ws;
|
|
291
|
+
// A socket dialled for an earlier change is on the new network already.
|
|
292
|
+
if (ws && ws === this._networkDial && ws.readyState === 0 /* CONNECTING */)
|
|
293
|
+
return;
|
|
294
|
+
if (ws) {
|
|
295
|
+
console.info('Network changed; reconnecting the WebSocket');
|
|
296
|
+
this._onClose(ws);
|
|
297
|
+
ws.close();
|
|
298
|
+
}
|
|
299
|
+
this._cancelReconnect();
|
|
300
|
+
this._wsReconnectDelay = INITIAL_RECONNECT_DELAY_MS;
|
|
301
|
+
if (this._handlers.size === 0 && this._pendingCalls.size === 0) {
|
|
302
|
+
this._notifyNetworkChange();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this._networkChanged = true;
|
|
306
|
+
this._ensureWs();
|
|
307
|
+
this._networkDial = this._ws;
|
|
308
|
+
}
|
|
309
|
+
_notifyNetworkChange() {
|
|
310
|
+
for (const cb of [...this._networkCallbacks])
|
|
311
|
+
callSafely(cb, 'Error in network-change callback:');
|
|
230
312
|
}
|
|
231
313
|
/** `reason` is set when the executor asked to try again later; calls that fail carry it. */
|
|
232
314
|
_onClose(ws, reason) {
|
|
@@ -270,6 +352,9 @@ export class ApiClient {
|
|
|
270
352
|
this._wsPingTimer = setInterval(() => {
|
|
271
353
|
if (this._ws !== ws)
|
|
272
354
|
return;
|
|
355
|
+
// A probe has its own, shorter deadline and decides for this ping.
|
|
356
|
+
if (this._wsProbeTimer)
|
|
357
|
+
return;
|
|
273
358
|
const ping = JSON.stringify({ type: 'ping' });
|
|
274
359
|
if (this._wsPingedAt === null) {
|
|
275
360
|
this._wsPingedAt = performance.now();
|
|
@@ -303,6 +388,13 @@ export class ApiClient {
|
|
|
303
388
|
clearInterval(this._wsPingTimer);
|
|
304
389
|
this._wsPingTimer = null;
|
|
305
390
|
}
|
|
391
|
+
this._endProbe();
|
|
392
|
+
}
|
|
393
|
+
_endProbe() {
|
|
394
|
+
if (this._wsProbeTimer) {
|
|
395
|
+
clearTimeout(this._wsProbeTimer);
|
|
396
|
+
this._wsProbeTimer = null;
|
|
397
|
+
}
|
|
306
398
|
}
|
|
307
399
|
_scheduleReconnect() {
|
|
308
400
|
if (this._wsReconnectTimer || this._authFailed !== null)
|
|
@@ -561,6 +653,46 @@ export class ApiClient {
|
|
|
561
653
|
this._reconnectCallbacks.add(callback);
|
|
562
654
|
return () => { this._reconnectCallbacks.delete(callback); };
|
|
563
655
|
}
|
|
656
|
+
/** Register a callback that fires after the network changed (`online`,
|
|
657
|
+
* or a socket that failed `checkConnection`), once the socket dialled for the
|
|
658
|
+
* new network is open and its event watch sent. Calls made from it go
|
|
659
|
+
* out on that socket. Returns an unsubscribe function. */
|
|
660
|
+
onNetworkChange(callback) {
|
|
661
|
+
this._networkCallbacks.add(callback);
|
|
662
|
+
this._listenForNetworkChanges();
|
|
663
|
+
return () => { this._networkCallbacks.delete(callback); };
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Check the open socket now rather than at the next ping: send a ping,
|
|
667
|
+
* and if nothing at all arrives on that socket within `deadlineMs`,
|
|
668
|
+
* treat it as a network change (drop it, dial the next one at once,
|
|
669
|
+
* `onNetworkChange` callbacks fire when it opens). Any message keeps it.
|
|
670
|
+
* For a caller that has seen its network path break, e.g. ICE going
|
|
671
|
+
* disconnected, where the platform fired no `online` event. Without an
|
|
672
|
+
* open socket, or while a check runs, this does nothing.
|
|
673
|
+
*/
|
|
674
|
+
checkConnection(deadlineMs = CHECK_CONNECTION_DEADLINE_MS) {
|
|
675
|
+
const ws = this._ws;
|
|
676
|
+
if (!ws || ws.readyState !== 1 /* OPEN */ || this._wsProbeTimer)
|
|
677
|
+
return;
|
|
678
|
+
const first = this._wsPingedAt === null;
|
|
679
|
+
if (first)
|
|
680
|
+
this._wsPingedAt = performance.now();
|
|
681
|
+
this._send(ws, JSON.stringify({ type: 'ping' }));
|
|
682
|
+
if (first)
|
|
683
|
+
this._wsPingArrivesBy = this._wsSentBy;
|
|
684
|
+
// Any message from the socket ends the probe (`onmessage` → `_endProbe`).
|
|
685
|
+
// The ping reaches the executor only after what was sent before it,
|
|
686
|
+
// and its pong gets half the deadline to come back after that.
|
|
687
|
+
const wait = Math.max(deadlineMs, this._wsSentBy - performance.now() + deadlineMs / 2);
|
|
688
|
+
this._wsProbeTimer = setTimeout(() => {
|
|
689
|
+
this._wsProbeTimer = null;
|
|
690
|
+
if (this._ws !== ws)
|
|
691
|
+
return;
|
|
692
|
+
console.warn(`WebSocket silent for ${wait} ms after a check; reconnecting`);
|
|
693
|
+
this._onNetworkChange();
|
|
694
|
+
}, wait);
|
|
695
|
+
}
|
|
564
696
|
/** Register a callback that fires once when the executor refuses this
|
|
565
697
|
* client's token: a 401 reply, or a socket closed with code 1008. Every
|
|
566
698
|
* call then fails with a 401 `RpcError` and the client does not reconnect;
|
|
@@ -578,6 +710,11 @@ export class ApiClient {
|
|
|
578
710
|
this._handlers.clear();
|
|
579
711
|
this._reconnectCallbacks.clear();
|
|
580
712
|
this._authFailedCallbacks.clear();
|
|
713
|
+
this._networkCallbacks.clear();
|
|
714
|
+
this._unlistenNetwork?.();
|
|
715
|
+
this._unlistenNetwork = null;
|
|
716
|
+
this._networkChanged = false;
|
|
717
|
+
this._networkDial = null;
|
|
581
718
|
// A reused client must not fire onReconnect on its next first open.
|
|
582
719
|
this._hasConnectedOnce = false;
|
|
583
720
|
}
|
|
@@ -5,4 +5,9 @@ export type AgentStatus = {
|
|
|
5
5
|
error: string | null;
|
|
6
6
|
isInitialized: boolean;
|
|
7
7
|
isUnlocked: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The `did:scid` the agent's device key speaks for, or `null`. `did` stays the device
|
|
10
|
+
* `did:key`, so links and profiles keep the author they had.
|
|
11
|
+
*/
|
|
12
|
+
identity: string | null;
|
|
8
13
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DecoratedPerspective } from "./DecoratedPerspective";
|
|
2
|
+
/**
|
|
3
|
+
* `agent.get`: the agent's profile, and the identity its device key speaks for (`did`
|
|
4
|
+
* stays the device `did:key`).
|
|
5
|
+
*/
|
|
6
|
+
export type AgentWithIdentity = {
|
|
7
|
+
/**
|
|
8
|
+
* The `did:scid` this agent speaks for, or `null`.
|
|
9
|
+
*/
|
|
10
|
+
identity: string | null;
|
|
11
|
+
did: string;
|
|
12
|
+
directMessageLanguage: string | null;
|
|
13
|
+
perspective: DecoratedPerspective | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `identity.claimOffer` params.
|
|
3
|
+
*/
|
|
4
|
+
export type ClaimOfferParams = {
|
|
5
|
+
/**
|
|
6
|
+
* The offer string (`coasys:offer:1:…`) or the offer link (`https://id.coasys.org/o#…`).
|
|
7
|
+
*/
|
|
8
|
+
offer: string;
|
|
9
|
+
/**
|
|
10
|
+
* A name for this device the holder sees on the confirm card (at most 64 characters).
|
|
11
|
+
*/
|
|
12
|
+
hint?: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OfferKind } from "./OfferKind";
|
|
2
|
+
/**
|
|
3
|
+
* `identity.claimOffer`: the claim is made; the holder confirms with the same match code.
|
|
4
|
+
*/
|
|
5
|
+
export type ClaimOfferResult = {
|
|
6
|
+
did: string;
|
|
7
|
+
offerId: string;
|
|
8
|
+
/**
|
|
9
|
+
* "R7K Q2M": the holder shows the same code.
|
|
10
|
+
*/
|
|
11
|
+
matchCode: string;
|
|
12
|
+
kind: OfferKind;
|
|
13
|
+
expires: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BotView } from "./BotView";
|
|
2
|
+
/**
|
|
3
|
+
* One device key of the identity, from its log. Names, places and the master-key holders
|
|
4
|
+
* will come from the private record, which the executor does not have yet.
|
|
5
|
+
*/
|
|
6
|
+
export type DeviceView = {
|
|
7
|
+
keyId: string;
|
|
8
|
+
sign: string;
|
|
9
|
+
bot: BotView | null;
|
|
10
|
+
expires: number | null;
|
|
11
|
+
addedSeq: number;
|
|
12
|
+
revokedSeq: number | null;
|
|
13
|
+
/**
|
|
14
|
+
* The key is this agent's device key.
|
|
15
|
+
*/
|
|
16
|
+
thisDevice: boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DidVerificationMethod } from "./DidVerificationMethod";
|
|
2
|
+
/**
|
|
3
|
+
* The JSON-LD of a `did:scid:coasys:1` DID document (the TypeScript contract of
|
|
4
|
+
* `DidResolutionResult.didDocument`; the executor passes on the core's own JSON).
|
|
5
|
+
*/
|
|
6
|
+
export type DidDocument = {
|
|
7
|
+
"@context": Array<string>;
|
|
8
|
+
id: string;
|
|
9
|
+
controller: string;
|
|
10
|
+
verificationMethod: Array<DidVerificationMethod>;
|
|
11
|
+
authentication: Array<string>;
|
|
12
|
+
assertionMethod: Array<string>;
|
|
13
|
+
keyAgreement: Array<string>;
|
|
14
|
+
capabilityInvocation: Array<string>;
|
|
15
|
+
alsoKnownAs?: Array<string>;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID document metadata: seqs as decimal strings (DID Core makes them strings). Empty on an
|
|
3
|
+
* error.
|
|
4
|
+
*/
|
|
5
|
+
export type DidDocumentMetadata = {
|
|
6
|
+
/**
|
|
7
|
+
* The seq whose state the document shows.
|
|
8
|
+
*/
|
|
9
|
+
versionId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The seq after it, when the log holds one.
|
|
12
|
+
*/
|
|
13
|
+
nextVersionId?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The log has ended (whatever the version).
|
|
16
|
+
*/
|
|
17
|
+
deactivated?: boolean;
|
|
18
|
+
};
|