@btps/sdk 1.1.3 → 1.2.0-rc.1
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/CHANGELOG.md +422 -0
- package/bin/verify-evidence-bundle.mjs +96 -0
- package/dist/client/btpsAgent.d.ts +10 -1
- package/dist/client/btpsAgent.js +116 -18
- package/dist/client/btpsClient.d.ts +53 -7
- package/dist/client/btpsClient.js +265 -147
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +3 -1
- package/dist/client/libs/schema.js +78 -13
- package/dist/client/libs/timeouts.d.ts +6 -0
- package/dist/client/libs/timeouts.js +2 -1
- package/dist/client/types/index.d.ts +54 -2
- package/dist/core/authentication/BtpsAuthentication.d.ts +43 -1
- package/dist/core/authentication/BtpsAuthentication.js +152 -36
- package/dist/core/authentication/refreshSuccessor.js +47 -0
- package/dist/core/authentication/storage/InMemoryTokenStore.d.ts +17 -1
- package/dist/core/authentication/storage/InMemoryTokenStore.js +16 -4
- package/dist/core/authentication/types.d.ts +82 -0
- package/dist/core/crypto/contentKey.d.ts +34 -0
- package/dist/core/crypto/contentKey.js +64 -0
- package/dist/core/crypto/decryptVerify.d.ts +7 -1
- package/dist/core/crypto/decryptVerify.js +23 -5
- package/dist/core/crypto/decrypter-interface.d.ts +6 -0
- package/dist/core/crypto/index.d.ts +12 -0
- package/dist/core/crypto/index.js +7 -1
- package/dist/core/crypto/keyResolver.d.ts +48 -0
- package/dist/core/crypto/keyResolver.js +46 -0
- package/dist/core/crypto/pem-decrypter.d.ts +2 -0
- package/dist/core/crypto/pem-decrypter.js +13 -8
- package/dist/core/crypto/signEncrypt.d.ts +4 -1
- package/dist/core/crypto/signEncrypt.js +20 -5
- package/dist/core/crypto/types.d.ts +8 -1
- package/dist/core/delegation/BtpsDelegator.d.ts +4 -0
- package/dist/core/delegation/BtpsDelegator.js +3 -2
- package/dist/core/delegation/verifyTransporterSignature.d.ts +104 -0
- package/dist/core/delegation/verifyTransporterSignature.js +224 -0
- package/dist/core/error/constant.d.ts +39 -0
- package/dist/core/error/constant.js +55 -0
- package/dist/core/server/constants/btps-protocol.d.ts +21 -5
- package/dist/core/server/constants/btps-protocol.js +46 -8
- package/dist/core/server/constants/index.d.ts +7 -3
- package/dist/core/server/constants/index.js +19 -4
- package/dist/core/server/constants/limits.d.ts +18 -0
- package/dist/core/server/constants/limits.js +19 -1
- package/dist/core/server/constants/permissions.d.ts +38 -0
- package/dist/core/server/constants/permissions.js +38 -0
- package/dist/core/server/schemas/artifacts/agentSchema.js +2 -1
- package/dist/core/server/schemas/artifacts/artifacts.js +7 -1
- package/dist/core/server/schemas/artifacts/controlSchema.js +1 -1
- package/dist/core/server/schemas/artifacts/identityLookupSchema.js +10 -1
- package/dist/core/server/schemas/artifacts/transporterSchema.js +92 -12
- package/dist/core/server/schemas/bounded.js +2 -2
- package/dist/core/server/schemas/btpsDocsSchema.d.ts +34185 -1084
- package/dist/core/server/schemas/btpsDocsSchema.js +300 -42
- package/dist/core/server/schemas/helpers.d.ts +9580 -0
- package/dist/core/server/schemas/helpers.js +76 -12
- package/dist/core/server/schemas/keyChainSchema.js +53 -0
- package/dist/core/server/schemas/responseSchema.js +52 -9
- package/dist/core/server/schemas/schema.js +3 -1
- package/dist/core/server/schemas/trustValues.d.ts +105 -0
- package/dist/core/server/schemas/trustValues.js +117 -0
- package/dist/core/server/types.d.ts +104 -6
- package/dist/core/storage/AbstractIdentityStore.d.ts +9 -0
- package/dist/core/storage/JsonIdentityStore.d.ts +3 -0
- package/dist/core/storage/JsonIdentityStore.js +3 -0
- package/dist/core/storage/types.d.ts +2 -0
- package/dist/core/trust/agreements.d.ts +107 -0
- package/dist/core/trust/agreements.js +116 -0
- package/dist/core/trust/evidence.d.ts +220 -0
- package/dist/core/trust/evidence.js +334 -0
- package/dist/core/trust/index.d.ts +10 -0
- package/dist/core/trust/index.js +14 -1
- package/dist/core/trust/keyRotation.d.ts +148 -0
- package/dist/core/trust/keyRotation.js +267 -0
- package/dist/core/trust/permissions.d.ts +114 -0
- package/dist/core/trust/permissions.js +115 -0
- package/dist/core/trust/shaping.d.ts +42 -0
- package/dist/core/trust/shaping.js +47 -0
- package/dist/core/trust/storage/AbstractTrustStore.d.ts +2 -1
- package/dist/core/trust/storage/JsonTrustStore.d.ts +3 -2
- package/dist/core/trust/timestamps.d.ts +49 -0
- package/dist/core/trust/timestamps.js +78 -0
- package/dist/core/trust/trustUtils.d.ts +13 -2
- package/dist/core/trust/trustUtils.js +28 -3
- package/dist/core/trust/types.d.ts +302 -2
- package/dist/core/trust/verification.d.ts +52 -0
- package/dist/core/trust/verification.js +55 -0
- package/dist/server/btpsServer.d.ts +70 -5
- package/dist/server/btpsServer.js +263 -143
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +17 -1
- package/dist/server/libs/agreementOrderCheck.d.ts +29 -0
- package/dist/server/libs/agreementOrderCheck.js +29 -0
- package/dist/server/libs/artifactTimeWindow.d.ts +2 -2
- package/dist/server/libs/artifactTimeWindow.js +2 -1
- package/dist/server/libs/detailsRequestLimit.d.ts +27 -0
- package/dist/server/libs/detailsRequestLimit.js +28 -0
- package/dist/server/libs/detailsResponseCheck.d.ts +27 -0
- package/dist/server/libs/detailsResponseCheck.js +27 -0
- package/dist/server/libs/eventChainCheck.d.ts +31 -0
- package/dist/server/libs/eventChainCheck.js +39 -0
- package/dist/server/libs/inFlightLimit.d.ts +10 -0
- package/dist/server/libs/inFlightLimit.js +7 -1
- package/dist/server/libs/index.d.ts +5 -0
- package/dist/server/libs/index.js +10 -0
- package/dist/server/libs/keyChains.d.ts +14 -0
- package/dist/server/libs/keyChains.js +17 -0
- package/dist/server/libs/wrapForAgent.d.ts +20 -0
- package/dist/server/libs/wrapForAgent.js +36 -0
- package/dist/server/types.d.ts +95 -9
- package/package.json +12 -3
package/dist/client/btpsAgent.js
CHANGED
|
@@ -8,21 +8,32 @@
|
|
|
8
8
|
import {
|
|
9
9
|
BTPErrorException,
|
|
10
10
|
BTP_ERROR_RESOLVE_DNS,
|
|
11
|
+
BTP_ERROR_SIG_VERIFICATION,
|
|
11
12
|
BTP_ERROR_UNSUPPORTED_ENCRYPT,
|
|
12
13
|
BTP_ERROR_VALIDATION,
|
|
13
14
|
transformToBTPErrorException
|
|
14
15
|
} from "../core/error/index.js";
|
|
15
16
|
import { BtpsClient } from "./btpsClient.js";
|
|
16
17
|
import { BtpsAgentCommandCallSchema } from "./libs/schema.js";
|
|
17
|
-
import {
|
|
18
|
+
import { BtpEventSchema } from "../core/server/schemas/btpsDocsSchema.js";
|
|
19
|
+
import { BtpTransporterArtifactSchema } from "../core/server/schemas/artifacts/transporterSchema.js";
|
|
20
|
+
import { composeTrustRequestFor } from "../core/trust/shaping.js";
|
|
18
21
|
import { validate } from "../core/utils/validation.js";
|
|
19
22
|
import {
|
|
20
23
|
AGENT_ACTIONS_REQUIRING_DOCUMENT,
|
|
21
|
-
AGENT_TRANSPORTER_ACTIONS
|
|
24
|
+
AGENT_TRANSPORTER_ACTIONS,
|
|
25
|
+
artifactVersion
|
|
22
26
|
} from "../core/server/constants/index.js";
|
|
23
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
decryptVerify,
|
|
29
|
+
encryptBtpPayload,
|
|
30
|
+
getFingerprintFromPem,
|
|
31
|
+
signBtpPayload,
|
|
32
|
+
signBtpPayloadWithSigner
|
|
33
|
+
} from "../core/crypto/index.js";
|
|
24
34
|
import { randomUUID } from "crypto";
|
|
25
35
|
import { isValidIdentity } from "../core/utils/index.js";
|
|
36
|
+
import { verifyTransporterSignature } from "../core/delegation/verifyTransporterSignature.js";
|
|
26
37
|
const mappedTransporterAction = AGENT_TRANSPORTER_ACTIONS;
|
|
27
38
|
class BtpsAgent extends BtpsClient {
|
|
28
39
|
agentId;
|
|
@@ -55,35 +66,60 @@ class BtpsAgent extends BtpsClient {
|
|
|
55
66
|
cause: `Document is required for ${commandParams.actionType}`
|
|
56
67
|
})
|
|
57
68
|
);
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
providedDocument && (agentArtifact.document = providedDocument);
|
|
70
|
+
let carriedVersion, shaped;
|
|
71
|
+
if (Object.keys(mappedTransporterAction).includes(actionType)) {
|
|
72
|
+
const built = await this.buildTransportArtifact({
|
|
60
73
|
...commandParams,
|
|
61
74
|
to: commandParams.to
|
|
62
|
-
});
|
|
63
|
-
if (transporterError)
|
|
75
|
+
}), { payload: transporterPayload, error: transporterError } = built;
|
|
76
|
+
if (shaped = built.shaped, transporterError)
|
|
64
77
|
return await this.buildClientErrorResponse(transporterError);
|
|
65
|
-
transporterPayload && (agentArtifact.document = transporterPayload);
|
|
78
|
+
transporterPayload && (agentArtifact.document = transporterPayload, carriedVersion = transporterPayload.version);
|
|
66
79
|
}
|
|
67
80
|
const cryptoOptions = options ? { ...options } : void 0;
|
|
68
|
-
cryptoOptions && actionType === "auth.request" && delete cryptoOptions.encryption, agentArtifact.encryption = null, agentArtifact.id = randomUUID(), agentArtifact.issuedAt = ( new Date()).toISOString(), agentArtifact.version =
|
|
81
|
+
cryptoOptions && actionType === "auth.request" && delete cryptoOptions.encryption, agentArtifact.encryption = null, agentArtifact.id = randomUUID(), agentArtifact.issuedAt = ( new Date()).toISOString(), agentArtifact.version = carriedVersion ?? artifactVersion({ document: agentArtifact.document });
|
|
69
82
|
try {
|
|
70
83
|
const signature = "sign" in this.signingKey ? await signBtpPayloadWithSigner(agentArtifact, this.signingKey) : signBtpPayload(agentArtifact, this.signingKey);
|
|
71
84
|
return agentArtifact.signature = signature, {
|
|
72
85
|
payload: agentArtifact,
|
|
73
|
-
error: void 0
|
|
86
|
+
error: void 0,
|
|
87
|
+
...shaped && { shaped }
|
|
74
88
|
};
|
|
75
89
|
} catch (error) {
|
|
76
90
|
return await this.buildClientErrorResponse(transformToBTPErrorException(error));
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
93
|
async buildTransportArtifact(commandParams) {
|
|
80
|
-
const {
|
|
94
|
+
const { actionType, to } = commandParams;
|
|
95
|
+
let { document, options } = commandParams, shaped;
|
|
96
|
+
if (actionType === "trust.request" && options?.permissions !== void 0) {
|
|
97
|
+
const { permissions, given, entityType, change } = options, composed = await composeTrustRequestFor(
|
|
98
|
+
to,
|
|
99
|
+
{ type: "TRUST_REQ", document, permissions, given, entityType, change },
|
|
100
|
+
{ versionFallback: options.versionFallback, btpMtsOptions: this.options.btpMtsOptions }
|
|
101
|
+
);
|
|
102
|
+
if (composed.error) return await this.buildClientErrorResponse(composed.error);
|
|
103
|
+
composed.shaped && (shaped = composed.shaped, document = composed.payload.document, options = {
|
|
104
|
+
...options,
|
|
105
|
+
permissions: void 0,
|
|
106
|
+
given: void 0,
|
|
107
|
+
entityType: void 0,
|
|
108
|
+
change: void 0
|
|
109
|
+
});
|
|
110
|
+
}
|
|
81
111
|
if (!document)
|
|
82
112
|
return await this.buildClientErrorResponse(
|
|
83
113
|
new BTPErrorException(BTP_ERROR_VALIDATION, {
|
|
84
114
|
cause: `Document is required for ${actionType}`
|
|
85
115
|
})
|
|
86
116
|
);
|
|
117
|
+
if (options?.syncOf !== void 0 && to.toLowerCase() !== this.options.to.toLowerCase())
|
|
118
|
+
return await this.buildClientErrorResponse(
|
|
119
|
+
new BTPErrorException(BTP_ERROR_VALIDATION, {
|
|
120
|
+
cause: `A sync goes to the device's own address, ${this.options.to}, not ${to}`
|
|
121
|
+
})
|
|
122
|
+
);
|
|
87
123
|
const receiverDnsTxt = options?.encryption ? (await this.resolveIdentity(to, this.options.to, this.decryptionKey)).response : await this.resolveBtpsHostDnsTxt(to);
|
|
88
124
|
if (!receiverDnsTxt)
|
|
89
125
|
return await this.buildClientErrorResponse(
|
|
@@ -112,33 +148,63 @@ class BtpsAgent extends BtpsClient {
|
|
|
112
148
|
);
|
|
113
149
|
}
|
|
114
150
|
}
|
|
115
|
-
const artifactType = mappedTransporterAction[actionType], event = artifactType === "BTPS_EVENT" ?
|
|
151
|
+
const artifactType = mappedTransporterAction[actionType], event = artifactType === "BTPS_EVENT" ? BtpEventSchema.safeParse(document) : void 0, senderSelector = (await this.resolveBtpsHostDnsTxt(this.options.to))?.selector;
|
|
116
152
|
if (!senderSelector)
|
|
117
153
|
return await this.buildClientErrorResponse(
|
|
118
154
|
new BTPErrorException(BTP_ERROR_RESOLVE_DNS, {
|
|
119
155
|
cause: `Could not resolve the selector of ${this.options.to}`
|
|
120
156
|
})
|
|
121
157
|
);
|
|
122
|
-
const
|
|
158
|
+
const trustFields = {
|
|
159
|
+
...options?.permissions !== void 0 && { permissions: options.permissions },
|
|
160
|
+
...options?.entityType !== void 0 && { entityType: options.entityType },
|
|
161
|
+
...options?.given !== void 0 && { given: options.given },
|
|
162
|
+
...options?.change !== void 0 && { change: options.change },
|
|
163
|
+
...options?.granted !== void 0 && { granted: options.granted }
|
|
164
|
+
}, transporterArtifact = {
|
|
123
165
|
id: event?.success ? event.data.id : options?.id ?? randomUUID(),
|
|
124
166
|
issuedAt: ( new Date()).toISOString(),
|
|
125
|
-
|
|
167
|
+
|
|
168
|
+
version: artifactVersion({
|
|
169
|
+
type: artifactType,
|
|
170
|
+
document,
|
|
171
|
+
syncOf: options?.syncOf,
|
|
172
|
+
documentType: options?.documentType,
|
|
173
|
+
...trustFields
|
|
174
|
+
}),
|
|
126
175
|
type: artifactType,
|
|
127
176
|
document: encryptedDocument,
|
|
128
177
|
from: this.options.to,
|
|
129
178
|
to,
|
|
130
179
|
selector: senderSelector,
|
|
131
180
|
encryption,
|
|
132
|
-
...options?.relatesTo !== void 0 && { relatesTo: options.relatesTo }
|
|
181
|
+
...options?.relatesTo !== void 0 && { relatesTo: options.relatesTo },
|
|
182
|
+
...options?.syncOf !== void 0 && { syncOf: options.syncOf },
|
|
183
|
+
...options?.documentType !== void 0 && { documentType: options.documentType },
|
|
184
|
+
...options?.details !== void 0 && { details: options.details },
|
|
185
|
+
...trustFields
|
|
133
186
|
};
|
|
134
187
|
try {
|
|
135
188
|
const signature = "sign" in this.signingKey ? await signBtpPayloadWithSigner(transporterArtifact, this.signingKey) : signBtpPayload(transporterArtifact, this.signingKey);
|
|
189
|
+
if (Object.keys(trustFields).length > 0) {
|
|
190
|
+
const checked = BtpTransporterArtifactSchema.safeParse({
|
|
191
|
+
...transporterArtifact,
|
|
192
|
+
signature
|
|
193
|
+
});
|
|
194
|
+
if (!checked.success)
|
|
195
|
+
return await this.buildClientErrorResponse(
|
|
196
|
+
new BTPErrorException(BTP_ERROR_VALIDATION, {
|
|
197
|
+
cause: checked.error.issues.map((issue) => issue.message).join("; ")
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
}
|
|
136
201
|
return {
|
|
137
202
|
payload: {
|
|
138
203
|
...transporterArtifact,
|
|
139
204
|
signature
|
|
140
205
|
},
|
|
141
|
-
error: void 0
|
|
206
|
+
error: void 0,
|
|
207
|
+
...shaped && { shaped }
|
|
142
208
|
};
|
|
143
209
|
} catch (error) {
|
|
144
210
|
return this.buildClientErrorResponse(error);
|
|
@@ -160,8 +226,40 @@ class BtpsAgent extends BtpsClient {
|
|
|
160
226
|
})
|
|
161
227
|
);
|
|
162
228
|
}
|
|
163
|
-
const { payload, error } = await this.getAgentArtifact(commandParams);
|
|
164
|
-
|
|
229
|
+
const { payload, error, shaped } = await this.getAgentArtifact(commandParams);
|
|
230
|
+
if (error)
|
|
231
|
+
return await this.buildClientErrorResponse(error);
|
|
232
|
+
const sent = await this.send(payload, timeoutMs);
|
|
233
|
+
return shaped ? { ...sent, shaped } : sent;
|
|
234
|
+
}
|
|
235
|
+
async openResult(entry) {
|
|
236
|
+
const { artifact, agentKey } = entry, refuse = (cause, error = BTP_ERROR_UNSUPPORTED_ENCRYPT) => ({
|
|
237
|
+
payload: void 0,
|
|
238
|
+
error: new BTPErrorException(error, { cause })
|
|
239
|
+
});
|
|
240
|
+
if (!agentKey) return refuse("The result has no agentKey for this device");
|
|
241
|
+
if (!this.decryptionKey) return refuse("This device holds no key to decrypt with");
|
|
242
|
+
if (!("selector" in artifact) || !artifact.encryption)
|
|
243
|
+
return refuse("Only an encrypted transporter artifact is opened with an agentKey");
|
|
244
|
+
const ownPublicKey = "sign" in this.signingKey ? (await this.signingKey.getPublicKey()).publicKey : this.signingKey.publicKey;
|
|
245
|
+
if (getFingerprintFromPem(ownPublicKey) !== agentKey.fingerprint)
|
|
246
|
+
return refuse(
|
|
247
|
+
`The agentKey is wrapped to the device key ${agentKey.fingerprint}, not the one this device holds: finish moving to the new key first`
|
|
248
|
+
);
|
|
249
|
+
try {
|
|
250
|
+
const signed = await verifyTransporterSignature(artifact, this.options.keyResolver);
|
|
251
|
+
return !signed.isValid || !signed.signerKey ? {
|
|
252
|
+
payload: void 0,
|
|
253
|
+
error: signed.error ?? new BTPErrorException(BTP_ERROR_SIG_VERIFICATION)
|
|
254
|
+
} : await decryptVerify(
|
|
255
|
+
signed.signerKey,
|
|
256
|
+
{ ...artifact },
|
|
257
|
+
this.decryptionKey,
|
|
258
|
+
agentKey.key
|
|
259
|
+
);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
return { payload: void 0, error: transformToBTPErrorException(error) };
|
|
262
|
+
}
|
|
165
263
|
}
|
|
166
264
|
destroy(soft = !1) {
|
|
167
265
|
soft ? super.end() : super.destroy();
|
|
@@ -10,6 +10,7 @@ import { BTPClientOptions, BTPClientResponse, BtpsClientEvents, BtpsHostDnsTxt,
|
|
|
10
10
|
import { BTPErrorException } from '../core/error/index.js';
|
|
11
11
|
import type { BTPArtifact, BTPIdentityResDoc, BTPServerResponse } from '../core/server/types.js';
|
|
12
12
|
import { BTPCryptoResponse, BTPDecryptionKey, VerifyEncryptedPayload } from '../core/crypto/types.js';
|
|
13
|
+
import type { BTPKeyChainLookup } from '../core/trust/types.js';
|
|
13
14
|
type SocketResult = {
|
|
14
15
|
socket: TLSSocket;
|
|
15
16
|
error: undefined;
|
|
@@ -22,7 +23,6 @@ export declare class BtpsClient {
|
|
|
22
23
|
protected socket?: TLSSocket;
|
|
23
24
|
protected emitter: EventEmitter;
|
|
24
25
|
protected retries: number;
|
|
25
|
-
protected backpressureQueue: string[];
|
|
26
26
|
protected states: ConnectionStates;
|
|
27
27
|
protected queue: Map<string, {
|
|
28
28
|
artifact: BTPArtifact;
|
|
@@ -56,16 +56,12 @@ export declare class BtpsClient {
|
|
|
56
56
|
protected attachListeners(socket: TLSSocket): void;
|
|
57
57
|
/** Answers every send written to `socket` that is still waiting, with `error`. */
|
|
58
58
|
protected failSendsOn(socket: TLSSocket, error: BTPErrorException): void;
|
|
59
|
-
protected onData(line: string): Promise<void>;
|
|
60
|
-
protected readLine(line: string): Promise<void>;
|
|
59
|
+
protected onData(line: string, socket?: TLSSocket): Promise<void>;
|
|
60
|
+
protected readLine(line: string, socket?: TLSSocket): Promise<void>;
|
|
61
61
|
/**
|
|
62
62
|
* Unref the socket when there are no pending requests to allow process termination
|
|
63
63
|
*/
|
|
64
64
|
protected unrefSocketIfNoQueue(): void;
|
|
65
|
-
/**
|
|
66
|
-
* Flush the backpressure queue
|
|
67
|
-
*/
|
|
68
|
-
protected flushBackpressure(): Promise<void>;
|
|
69
65
|
/**
|
|
70
66
|
* Cleanup the queue
|
|
71
67
|
* @param resolveError - The error to resolve
|
|
@@ -134,6 +130,8 @@ export declare class BtpsClient {
|
|
|
134
130
|
* @returns True if the error is non-retryable, false otherwise
|
|
135
131
|
*/
|
|
136
132
|
protected isNonRetryableError(err: unknown): boolean;
|
|
133
|
+
/** A signature key: from the keyResolver when one is given, else from DNS, as without one. */
|
|
134
|
+
protected signatureKey(identity: string, selector: string): Promise<string | undefined>;
|
|
137
135
|
protected verifyServerMessage(msg: BTPServerResponse): Promise<{
|
|
138
136
|
isValid: true;
|
|
139
137
|
error: undefined;
|
|
@@ -148,6 +146,29 @@ export declare class BtpsClient {
|
|
|
148
146
|
isValid: false;
|
|
149
147
|
error: BTPErrorException;
|
|
150
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Why an artifact is stamped lower than it needs, or undefined. One that uses
|
|
151
|
+
* what 1.2 adds under 1.1.0 would be read by a 1.1 receiver as something
|
|
152
|
+
* else, and an agent artifact needs its server to speak what it carries.
|
|
153
|
+
*/
|
|
154
|
+
protected understamped(artifact: BTPArtifact): string | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* A receiver's refusal of the artifact's version, as an error naming the
|
|
157
|
+
* version the receiver speaks (the version of its answer), so a sender can
|
|
158
|
+
* decide what to send it instead. Undefined for any other answer.
|
|
159
|
+
*/
|
|
160
|
+
protected versionRefusal(msg: BTPServerResponse): BTPErrorException | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* The protocol version the server speaks, from its answer to a PING. The
|
|
163
|
+
* PING is stamped 1.1.0, so every 1.1 and 1.2 server answers it.
|
|
164
|
+
*/
|
|
165
|
+
getServerVersion(): Promise<{
|
|
166
|
+
version: string;
|
|
167
|
+
error: undefined;
|
|
168
|
+
} | {
|
|
169
|
+
version: undefined;
|
|
170
|
+
error: BTPErrorException;
|
|
171
|
+
}>;
|
|
151
172
|
/**
|
|
152
173
|
* Send the artifact to the server
|
|
153
174
|
* @param artifact - The artifact to send
|
|
@@ -174,12 +195,37 @@ export declare class BtpsClient {
|
|
|
174
195
|
hostname: string;
|
|
175
196
|
port: number;
|
|
176
197
|
version: string;
|
|
198
|
+
/** When the host answered: the protocol version its server speaks, from its signed answer. */
|
|
199
|
+
serverVersion?: string;
|
|
177
200
|
};
|
|
178
201
|
error: undefined;
|
|
179
202
|
} | {
|
|
180
203
|
response: undefined;
|
|
181
204
|
error: BTPErrorException;
|
|
182
205
|
}>;
|
|
206
|
+
/**
|
|
207
|
+
* Since 1.2: `identity`'s key chain, from its host: the operator's signed
|
|
208
|
+
* answer to a 1.2.0 lookup that asks for it, checked as `askHost` checks
|
|
209
|
+
* it. A host that cannot be reached, or answers with an error (a 1.1 host
|
|
210
|
+
* refuses the lookup), gives no chain: `unavailable`, and the identity's
|
|
211
|
+
* keys are checked by DNS. An answer that fails its checks is `invalid`.
|
|
212
|
+
*
|
|
213
|
+
* It is asked for on an arrival, which waits for it, so the host gets the
|
|
214
|
+
* client's connect timeout and then `replyTimeoutMs` (default
|
|
215
|
+
* KEY_CHAIN_REPLY_TIMEOUT_MS, 5 seconds) to answer, not the send's.
|
|
216
|
+
*/
|
|
217
|
+
lookupKeyChain(identity: string, from: string, options?: {
|
|
218
|
+
replyTimeoutMs?: number;
|
|
219
|
+
}): Promise<BTPKeyChainLookup>;
|
|
220
|
+
/**
|
|
221
|
+
* Asks `identity`'s host, as its domain's operator answers: one lookup over
|
|
222
|
+
* its own connection, taken only when signed by `host.operator`. Since 1.2,
|
|
223
|
+
* a 1.2.0 lookup's answer must be this lookup's (`reqId`), fresh (`issuedAt`
|
|
224
|
+
* within the default maxArtifactAgeSeconds), about this identity, and carry
|
|
225
|
+
* the key chain when asked. The host gets `timeouts.connectMs` to take the
|
|
226
|
+
* connection and `timeouts.replyMs` to answer: the client's own, unless given.
|
|
227
|
+
*/
|
|
228
|
+
private askHost;
|
|
183
229
|
/**
|
|
184
230
|
* Add a listener to the client
|
|
185
231
|
* @param event - The event to listen to
|