@btps/sdk 0.0.0-stage → 1.1.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/CHANGELOG.md +149 -0
- package/LICENSE +190 -0
- package/NOTICE +25 -0
- package/README.md +261 -2
- package/dist/client/btpsAgent.d.ts +20 -0
- package/dist/client/btpsAgent.js +172 -0
- package/dist/client/btpsClient.d.ts +202 -0
- package/dist/client/btpsClient.js +602 -0
- package/dist/client/btpsTransporter.d.ts +52 -0
- package/dist/client/btpsTransporter.js +249 -0
- package/dist/client/constants.ts/index.d.ts +11 -0
- package/dist/client/constants.ts/index.js +20 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.js +27 -0
- package/dist/client/libs/schema.d.ts +27604 -0
- package/dist/client/libs/schema.js +56 -0
- package/dist/client/libs/timeouts.d.ts +22 -0
- package/dist/client/libs/timeouts.js +19 -0
- package/dist/client/types/index.d.ts +155 -0
- package/dist/client/types/index.js +7 -0
- package/dist/core/authentication/BtpsAuthentication.d.ts +128 -0
- package/dist/core/authentication/BtpsAuthentication.js +293 -0
- package/dist/core/authentication/index.d.ts +11 -0
- package/dist/core/authentication/index.js +12 -0
- package/dist/core/authentication/keyProof.d.ts +18 -0
- package/dist/core/authentication/keyProof.js +16 -0
- package/dist/core/authentication/storage/InMemoryAuthSessionStore.d.ts +55 -0
- package/dist/core/authentication/storage/InMemoryAuthSessionStore.js +62 -0
- package/dist/core/authentication/storage/InMemoryTokenStore.d.ts +63 -0
- package/dist/core/authentication/storage/InMemoryTokenStore.js +63 -0
- package/dist/core/authentication/types.d.ts +135 -0
- package/dist/core/authentication/types.js +7 -0
- package/dist/core/crypto/decryptVerify.d.ts +9 -0
- package/dist/core/crypto/decryptVerify.js +45 -0
- package/dist/core/crypto/decrypter-interface.d.ts +25 -0
- package/dist/core/crypto/decrypter-interface.js +7 -0
- package/dist/core/crypto/index.d.ts +77 -0
- package/dist/core/crypto/index.js +210 -0
- package/dist/core/crypto/jcs.d.ts +28 -0
- package/dist/core/crypto/jcs.js +60 -0
- package/dist/core/crypto/keygen.d.ts +9 -0
- package/dist/core/crypto/keygen.js +35 -0
- package/dist/core/crypto/pem-decrypter.d.ts +26 -0
- package/dist/core/crypto/pem-decrypter.js +52 -0
- package/dist/core/crypto/pem-signer.d.ts +21 -0
- package/dist/core/crypto/pem-signer.js +34 -0
- package/dist/core/crypto/signEncrypt.d.ts +34 -0
- package/dist/core/crypto/signEncrypt.js +75 -0
- package/dist/core/crypto/signer-interface.d.ts +22 -0
- package/dist/core/crypto/signer-interface.js +7 -0
- package/dist/core/crypto/types.d.ts +79 -0
- package/dist/core/crypto/types.js +7 -0
- package/dist/core/delegation/BtpsDelegator.d.ts +102 -0
- package/dist/core/delegation/BtpsDelegator.js +118 -0
- package/dist/core/delegation/index.d.ts +7 -0
- package/dist/core/delegation/index.js +8 -0
- package/dist/core/error/constant.d.ts +66 -0
- package/dist/core/error/constant.js +194 -0
- package/dist/core/error/index.d.ts +35 -0
- package/dist/core/error/index.js +52 -0
- package/dist/core/error/types.d.ts +16 -0
- package/dist/core/error/types.js +7 -0
- package/dist/core/server/constants/btps-protocol.d.ts +17 -0
- package/dist/core/server/constants/btps-protocol.js +25 -0
- package/dist/core/server/constants/control.d.ts +7 -0
- package/dist/core/server/constants/control.js +11 -0
- package/dist/core/server/constants/currency.d.ts +7 -0
- package/dist/core/server/constants/currency.js +332 -0
- package/dist/core/server/constants/index.d.ts +26 -0
- package/dist/core/server/constants/index.js +61 -0
- package/dist/core/server/constants/limits.d.ts +50 -0
- package/dist/core/server/constants/limits.js +50 -0
- package/dist/core/server/helpers/BtpsMessageQueue.d.ts +13 -0
- package/dist/core/server/helpers/BtpsMessageQueue.js +12 -0
- package/dist/core/server/helpers/InMemoryQueue.d.ts +16 -0
- package/dist/core/server/helpers/InMemoryQueue.js +35 -0
- package/dist/core/server/helpers/index.d.ts +8 -0
- package/dist/core/server/helpers/index.js +9 -0
- package/dist/core/server/schemas/artifacts/agentSchema.d.ts +4565 -0
- package/dist/core/server/schemas/artifacts/agentSchema.js +51 -0
- package/dist/core/server/schemas/artifacts/artifacts.d.ts +4920 -0
- package/dist/core/server/schemas/artifacts/artifacts.js +21 -0
- package/dist/core/server/schemas/artifacts/controlSchema.d.ts +23 -0
- package/dist/core/server/schemas/artifacts/controlSchema.js +18 -0
- package/dist/core/server/schemas/artifacts/identityLookupSchema.d.ts +32 -0
- package/dist/core/server/schemas/artifacts/identityLookupSchema.js +21 -0
- package/dist/core/server/schemas/artifacts/transporterSchema.d.ts +553 -0
- package/dist/core/server/schemas/artifacts/transporterSchema.js +60 -0
- package/dist/core/server/schemas/btpsDocsSchema.d.ts +4519 -0
- package/dist/core/server/schemas/btpsDocsSchema.js +272 -0
- package/dist/core/server/schemas/helpers.d.ts +1612 -0
- package/dist/core/server/schemas/helpers.js +87 -0
- package/dist/core/server/schemas/responseSchema.d.ts +6918 -0
- package/dist/core/server/schemas/responseSchema.js +86 -0
- package/dist/core/server/schemas/schema.d.ts +4916 -0
- package/dist/core/server/schemas/schema.js +70 -0
- package/dist/core/server/schemas/shared.d.ts +21 -0
- package/dist/core/server/schemas/shared.js +18 -0
- package/dist/core/server/types.d.ts +172 -0
- package/dist/core/server/types.js +7 -0
- package/dist/core/storage/AbstractIdentityStore.d.ts +17 -0
- package/dist/core/storage/AbstractIdentityStore.js +13 -0
- package/dist/core/storage/AbstractStorageStore.d.ts +16 -0
- package/dist/core/storage/AbstractStorageStore.js +17 -0
- package/dist/core/storage/JsonIdentityStore.d.ts +29 -0
- package/dist/core/storage/JsonIdentityStore.js +39 -0
- package/dist/core/storage/JsonStorageStore.d.ts +59 -0
- package/dist/core/storage/JsonStorageStore.js +110 -0
- package/dist/core/storage/index.d.ts +11 -0
- package/dist/core/storage/index.js +18 -0
- package/dist/core/storage/types.d.ts +28 -0
- package/dist/core/storage/types.js +7 -0
- package/dist/core/trust/index.d.ts +10 -0
- package/dist/core/trust/index.js +15 -0
- package/dist/core/trust/storage/AbstractTrustStore.d.ts +23 -0
- package/dist/core/trust/storage/AbstractTrustStore.js +13 -0
- package/dist/core/trust/storage/JsonTrustStore.d.ts +33 -0
- package/dist/core/trust/storage/JsonTrustStore.js +42 -0
- package/dist/core/trust/trustUtils.d.ts +78 -0
- package/dist/core/trust/trustUtils.js +41 -0
- package/dist/core/trust/types.d.ts +53 -0
- package/dist/core/trust/types.js +7 -0
- package/dist/core/utils/identity.d.ts +20 -0
- package/dist/core/utils/identity.js +22 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.js +124 -0
- package/dist/core/utils/types.d.ts +10 -0
- package/dist/core/utils/types.js +7 -0
- package/dist/core/utils/validation.d.ts +14 -0
- package/dist/core/utils/validation.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/server/btpsServer.d.ts +292 -0
- package/dist/server/btpsServer.js +827 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +15 -0
- package/dist/server/libs/abstractRateLimiter.d.ts +10 -0
- package/dist/server/libs/abstractRateLimiter.js +15 -0
- package/dist/server/libs/artifactSizeGuard.d.ts +27 -0
- package/dist/server/libs/artifactSizeGuard.js +44 -0
- package/dist/server/libs/artifactTimeWindow.d.ts +24 -0
- package/dist/server/libs/artifactTimeWindow.js +30 -0
- package/dist/server/libs/btpsFactory.d.ts +29 -0
- package/dist/server/libs/btpsFactory.js +49 -0
- package/dist/server/libs/btpsLightweightFactory.d.ts +35 -0
- package/dist/server/libs/btpsLightweightFactory.js +37 -0
- package/dist/server/libs/btpsRegistry.d.ts +14 -0
- package/dist/server/libs/btpsRegistry.js +16 -0
- package/dist/server/libs/btpsSimpleMetricsTracker.d.ts +13 -0
- package/dist/server/libs/btpsSimpleMetricsTracker.js +21 -0
- package/dist/server/libs/btpsSimpleRateLimiter.d.ts +28 -0
- package/dist/server/libs/btpsSimpleRateLimiter.js +46 -0
- package/dist/server/libs/connectionTimeout.d.ts +16 -0
- package/dist/server/libs/connectionTimeout.js +14 -0
- package/dist/server/libs/defaultMiddleware.d.ts +8 -0
- package/dist/server/libs/defaultMiddleware.js +128 -0
- package/dist/server/libs/inFlightLimit.d.ts +18 -0
- package/dist/server/libs/inFlightLimit.js +17 -0
- package/dist/server/libs/index.d.ts +18 -0
- package/dist/server/libs/index.js +34 -0
- package/dist/server/libs/middlewareManager.d.ts +59 -0
- package/dist/server/libs/middlewareManager.js +126 -0
- package/dist/server/libs/type.d.ts +22 -0
- package/dist/server/libs/type.js +7 -0
- package/dist/server/types.d.ts +236 -0
- package/dist/server/types.js +7 -0
- package/package.json +126 -4
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
BTPErrorException,
|
|
10
|
+
BTP_ERROR_RESOLVE_DNS,
|
|
11
|
+
BTP_ERROR_UNSUPPORTED_ENCRYPT,
|
|
12
|
+
BTP_ERROR_VALIDATION,
|
|
13
|
+
transformToBTPErrorException
|
|
14
|
+
} from "../core/error/index.js";
|
|
15
|
+
import { BtpsClient } from "./btpsClient.js";
|
|
16
|
+
import { BtpsAgentCommandCallSchema } from "./libs/schema.js";
|
|
17
|
+
import { BtpLifecycleEventSchema } from "../core/server/schemas/btpsDocsSchema.js";
|
|
18
|
+
import { validate } from "../core/utils/validation.js";
|
|
19
|
+
import {
|
|
20
|
+
AGENT_ACTIONS_REQUIRING_DOCUMENT,
|
|
21
|
+
AGENT_TRANSPORTER_ACTIONS
|
|
22
|
+
} from "../core/server/constants/index.js";
|
|
23
|
+
import { encryptBtpPayload, signBtpPayload, signBtpPayloadWithSigner } from "../core/crypto/index.js";
|
|
24
|
+
import { randomUUID } from "crypto";
|
|
25
|
+
import { isValidIdentity } from "../core/utils/index.js";
|
|
26
|
+
const mappedTransporterAction = AGENT_TRANSPORTER_ACTIONS;
|
|
27
|
+
class BtpsAgent extends BtpsClient {
|
|
28
|
+
agentId;
|
|
29
|
+
signingKey;
|
|
30
|
+
decryptionKey;
|
|
31
|
+
constructor(agentOptions) {
|
|
32
|
+
const { agent, btpIdentity, ...restOptions } = agentOptions;
|
|
33
|
+
super({
|
|
34
|
+
to: btpIdentity,
|
|
35
|
+
...restOptions
|
|
36
|
+
}), "signer" in agent ? (this.signingKey = agent.signer, this.decryptionKey = agent.decrypter) : (this.signingKey = {
|
|
37
|
+
publicKey: agent.identityCert,
|
|
38
|
+
privateKey: agent.identityKey
|
|
39
|
+
}, this.decryptionKey = agent.identityKey), this.agentId = agent.id;
|
|
40
|
+
const hasKey = "signer" in agent ? !!agent.signer : !!(agent.identityKey && agent.identityCert);
|
|
41
|
+
if (!agent.id || !hasKey || !btpIdentity || !isValidIdentity(btpIdentity))
|
|
42
|
+
throw new BTPErrorException({ message: "Invalid agent or btpIdentity" });
|
|
43
|
+
}
|
|
44
|
+
async getAgentArtifact(commandParams) {
|
|
45
|
+
const { actionType, options, document: providedDocument } = commandParams, agentArtifact = {
|
|
46
|
+
action: actionType,
|
|
47
|
+
agentId: this.agentId,
|
|
48
|
+
to: commandParams.to
|
|
49
|
+
};
|
|
50
|
+
if (AGENT_ACTIONS_REQUIRING_DOCUMENT.includes(
|
|
51
|
+
commandParams.actionType
|
|
52
|
+
) && !providedDocument)
|
|
53
|
+
return await this.buildClientErrorResponse(
|
|
54
|
+
new BTPErrorException(BTP_ERROR_VALIDATION, {
|
|
55
|
+
cause: `Document is required for ${commandParams.actionType}`
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
if (providedDocument && (agentArtifact.document = providedDocument), Object.keys(mappedTransporterAction).includes(actionType)) {
|
|
59
|
+
const { payload: transporterPayload, error: transporterError } = await this.buildTransportArtifact({
|
|
60
|
+
...commandParams,
|
|
61
|
+
to: commandParams.to
|
|
62
|
+
});
|
|
63
|
+
if (transporterError)
|
|
64
|
+
return await this.buildClientErrorResponse(transporterError);
|
|
65
|
+
transporterPayload && (agentArtifact.document = transporterPayload);
|
|
66
|
+
}
|
|
67
|
+
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 = this.getProtocolVersion();
|
|
69
|
+
try {
|
|
70
|
+
const signature = "sign" in this.signingKey ? await signBtpPayloadWithSigner(agentArtifact, this.signingKey) : signBtpPayload(agentArtifact, this.signingKey);
|
|
71
|
+
return agentArtifact.signature = signature, {
|
|
72
|
+
payload: agentArtifact,
|
|
73
|
+
error: void 0
|
|
74
|
+
};
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return await this.buildClientErrorResponse(transformToBTPErrorException(error));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async buildTransportArtifact(commandParams) {
|
|
80
|
+
const { document, actionType, to, options } = commandParams;
|
|
81
|
+
if (!document)
|
|
82
|
+
return await this.buildClientErrorResponse(
|
|
83
|
+
new BTPErrorException(BTP_ERROR_VALIDATION, {
|
|
84
|
+
cause: `Document is required for ${actionType}`
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
const receiverDnsTxt = options?.encryption ? (await this.resolveIdentity(to, this.options.to, this.decryptionKey)).response : await this.resolveBtpsHostDnsTxt(to);
|
|
88
|
+
if (!receiverDnsTxt)
|
|
89
|
+
return await this.buildClientErrorResponse(
|
|
90
|
+
new BTPErrorException(BTP_ERROR_RESOLVE_DNS, {
|
|
91
|
+
cause: options?.encryption ? `Could not resolve identity or host and selector for: ${to}` : `Could not resolve host and selector for: ${to}`
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
let encryptedDocument = document, encryption = null;
|
|
95
|
+
if (options?.encryption) {
|
|
96
|
+
const { publicKey } = receiverDnsTxt;
|
|
97
|
+
try {
|
|
98
|
+
const { data, encryption: encryptionInfo } = encryptBtpPayload(
|
|
99
|
+
document,
|
|
100
|
+
publicKey,
|
|
101
|
+
options.encryption
|
|
102
|
+
);
|
|
103
|
+
encryptedDocument = data, encryption = encryptionInfo;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return await this.buildClientErrorResponse(
|
|
106
|
+
new BTPErrorException(BTP_ERROR_UNSUPPORTED_ENCRYPT, {
|
|
107
|
+
cause: `Failed to encrypt document for ${to}`,
|
|
108
|
+
meta: {
|
|
109
|
+
error
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const artifactType = mappedTransporterAction[actionType], event = artifactType === "BTPS_EVENT" ? BtpLifecycleEventSchema.safeParse(document) : void 0, senderSelector = (await this.resolveBtpsHostDnsTxt(this.options.to))?.selector;
|
|
116
|
+
if (!senderSelector)
|
|
117
|
+
return await this.buildClientErrorResponse(
|
|
118
|
+
new BTPErrorException(BTP_ERROR_RESOLVE_DNS, {
|
|
119
|
+
cause: `Could not resolve the selector of ${this.options.to}`
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
const transporterArtifact = {
|
|
123
|
+
id: event?.success ? event.data.id : randomUUID(),
|
|
124
|
+
issuedAt: ( new Date()).toISOString(),
|
|
125
|
+
version: this.getProtocolVersion(),
|
|
126
|
+
type: artifactType,
|
|
127
|
+
document: encryptedDocument,
|
|
128
|
+
from: this.options.to,
|
|
129
|
+
to,
|
|
130
|
+
selector: senderSelector,
|
|
131
|
+
encryption,
|
|
132
|
+
...options?.relatesTo !== void 0 && { relatesTo: options.relatesTo }
|
|
133
|
+
};
|
|
134
|
+
try {
|
|
135
|
+
const signature = "sign" in this.signingKey ? await signBtpPayloadWithSigner(transporterArtifact, this.signingKey) : signBtpPayload(transporterArtifact, this.signingKey);
|
|
136
|
+
return {
|
|
137
|
+
payload: {
|
|
138
|
+
...transporterArtifact,
|
|
139
|
+
signature
|
|
140
|
+
},
|
|
141
|
+
error: void 0
|
|
142
|
+
};
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return this.buildClientErrorResponse(error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async command(actionType, identity, document, options, timeoutMs) {
|
|
148
|
+
const commandParams = {
|
|
149
|
+
actionType,
|
|
150
|
+
document,
|
|
151
|
+
to: identity,
|
|
152
|
+
options
|
|
153
|
+
}, validationResult = validate(BtpsAgentCommandCallSchema, commandParams);
|
|
154
|
+
if (!validationResult.success) {
|
|
155
|
+
const errorDetails = validationResult.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ");
|
|
156
|
+
return await this.buildClientErrorResponse(
|
|
157
|
+
new BTPErrorException(BTP_ERROR_VALIDATION, {
|
|
158
|
+
cause: `Command validation failed: ${errorDetails}`,
|
|
159
|
+
meta: { validationErrors: validationResult.error.issues }
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const { payload, error } = await this.getAgentArtifact(commandParams);
|
|
164
|
+
return error ? await this.buildClientErrorResponse(error) : this.send(payload, timeoutMs);
|
|
165
|
+
}
|
|
166
|
+
destroy(soft = !1) {
|
|
167
|
+
soft ? super.end() : super.destroy();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
BtpsAgent
|
|
172
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
import { type TLSSocket } from 'tls';
|
|
8
|
+
import { EventEmitter } from 'events';
|
|
9
|
+
import { BTPClientOptions, BTPClientResponse, BtpsClientEvents, BtpsHostDnsTxt, BTPSRetryInfo, ConnectionStates, TypedEventEmitter, UpdateBTPClientOptions } from './types/index.js';
|
|
10
|
+
import { BTPErrorException } from '../core/error/index.js';
|
|
11
|
+
import type { BTPArtifact, BTPIdentityResDoc, BTPServerResponse } from '../core/server/types.js';
|
|
12
|
+
import { BTPCryptoResponse, BTPDecryptionKey, VerifyEncryptedPayload } from '../core/crypto/types.js';
|
|
13
|
+
export declare class BtpsClient {
|
|
14
|
+
protected options: BTPClientOptions;
|
|
15
|
+
protected socket?: TLSSocket;
|
|
16
|
+
protected emitter: EventEmitter;
|
|
17
|
+
protected retries: number;
|
|
18
|
+
protected backpressureQueue: string[];
|
|
19
|
+
protected states: ConnectionStates;
|
|
20
|
+
protected queue: Map<string, {
|
|
21
|
+
artifact: BTPArtifact;
|
|
22
|
+
resolve: (v: BTPClientResponse) => void;
|
|
23
|
+
timeout: NodeJS.Timeout;
|
|
24
|
+
}>;
|
|
25
|
+
protected connectTimeoutMs: number;
|
|
26
|
+
protected replyTimeoutMs: number;
|
|
27
|
+
constructor(options: BTPClientOptions);
|
|
28
|
+
protected getSocket(): Promise<{
|
|
29
|
+
socket: TLSSocket;
|
|
30
|
+
error: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
socket: undefined;
|
|
33
|
+
error: BTPErrorException;
|
|
34
|
+
}>;
|
|
35
|
+
protected attachListeners(socket: TLSSocket, receiverId: string): void;
|
|
36
|
+
protected onData(line: string): Promise<void>;
|
|
37
|
+
protected pumpNextQueue(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Unref the socket when there are no pending requests to allow process termination
|
|
40
|
+
*/
|
|
41
|
+
protected unrefSocketIfNoQueue(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Flush the backpressure queue
|
|
44
|
+
*/
|
|
45
|
+
protected flushBackpressure(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Retry the connection to the server
|
|
48
|
+
* @param receiverId - The identity of the receiver
|
|
49
|
+
*/
|
|
50
|
+
protected retryConnect(receiverId: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the error
|
|
53
|
+
* @param error - The error to resolve
|
|
54
|
+
* @returns The error info
|
|
55
|
+
*/
|
|
56
|
+
protected resolveError(error?: BTPErrorException): void;
|
|
57
|
+
/**
|
|
58
|
+
* Cleanup the queue
|
|
59
|
+
* @param resolveError - The error to resolve
|
|
60
|
+
*/
|
|
61
|
+
protected cleanupQueue(resolveError?: BTPErrorException): void;
|
|
62
|
+
/**
|
|
63
|
+
* Hands an error to the client's 'error' listeners, or logs it when there are
|
|
64
|
+
* none: an 'error' event nobody listens to throws inside the SDK.
|
|
65
|
+
*/
|
|
66
|
+
protected emitError(errorInfo: BTPSRetryInfo & {
|
|
67
|
+
error: Error;
|
|
68
|
+
}): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get the retry info
|
|
71
|
+
* @param forError - The error to get the retry info
|
|
72
|
+
* @returns The retry info
|
|
73
|
+
*/
|
|
74
|
+
protected getRetryInfo(forError?: unknown): BTPSRetryInfo;
|
|
75
|
+
/**
|
|
76
|
+
* Build the client error response
|
|
77
|
+
* @param error - The error to build the response
|
|
78
|
+
* @returns The client error response
|
|
79
|
+
*/
|
|
80
|
+
buildClientErrorResponse<T>(error: BTPErrorException, responseProp?: string): Promise<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Update the client options
|
|
83
|
+
* @param options - The options to update
|
|
84
|
+
*/
|
|
85
|
+
update(options: UpdateBTPClientOptions): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get the connection states
|
|
88
|
+
* @returns The connection states
|
|
89
|
+
*/
|
|
90
|
+
getConnectionStates(): ConnectionStates;
|
|
91
|
+
/**
|
|
92
|
+
* Resolve the btp host and dns config
|
|
93
|
+
* @param receiverId - The identity of the receiver
|
|
94
|
+
* @returns The btp host and dns config
|
|
95
|
+
*/
|
|
96
|
+
resolveBtpsHostDnsTxt(receiverId: string): Promise<BtpsHostDnsTxt | undefined>;
|
|
97
|
+
protected processResolveOnError(artifactId: string, error: BTPErrorException, resolveOnError?: {
|
|
98
|
+
resolve: (v: BTPClientResponse) => void;
|
|
99
|
+
timeout: NodeJS.Timeout;
|
|
100
|
+
}): void;
|
|
101
|
+
/**
|
|
102
|
+
* Send the artifact to the server
|
|
103
|
+
* @param artifact - The artifact to send
|
|
104
|
+
*/
|
|
105
|
+
protected sendArtifact(artifact: BTPArtifact, resolveOnError?: {
|
|
106
|
+
resolve: (v: BTPClientResponse) => void;
|
|
107
|
+
timeout: NodeJS.Timeout;
|
|
108
|
+
}): void;
|
|
109
|
+
/**
|
|
110
|
+
* Dispatch the artifact to the server
|
|
111
|
+
* @param job - The job to dispatch
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
protected dispatch(job: {
|
|
115
|
+
artifact: BTPArtifact;
|
|
116
|
+
resolve: (v: BTPClientResponse) => void;
|
|
117
|
+
timeoutMs: number;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Check if the error is non-retryable
|
|
121
|
+
* @param err - The error to check
|
|
122
|
+
* @returns True if the error is non-retryable, false otherwise
|
|
123
|
+
*/
|
|
124
|
+
protected isNonRetryableError(err: unknown): boolean;
|
|
125
|
+
protected verifyServerMessage(msg: BTPServerResponse): Promise<{
|
|
126
|
+
isValid: true;
|
|
127
|
+
error: undefined;
|
|
128
|
+
} | {
|
|
129
|
+
isValid: false;
|
|
130
|
+
error: BTPErrorException;
|
|
131
|
+
}>;
|
|
132
|
+
protected validateArtifact(artifact: BTPArtifact): {
|
|
133
|
+
isValid: true;
|
|
134
|
+
error: undefined;
|
|
135
|
+
} | {
|
|
136
|
+
isValid: false;
|
|
137
|
+
error: BTPErrorException;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Send the artifact to the server
|
|
141
|
+
* @param artifact - The artifact to send
|
|
142
|
+
* @param timeoutMs - How long to wait for the answer, in ms: the client's `replyTimeoutMs` by default, never below 10000
|
|
143
|
+
* @returns The response from the server
|
|
144
|
+
*/
|
|
145
|
+
send(artifact: BTPArtifact, timeoutMs?: number): Promise<BTPClientResponse>;
|
|
146
|
+
/**
|
|
147
|
+
* Decrypt and verify the artifact
|
|
148
|
+
* @param artifact - The artifact to decrypt and verify
|
|
149
|
+
* @param senderPubPem - The public key of the sender
|
|
150
|
+
* @returns The decrypted and verified artifact
|
|
151
|
+
*/
|
|
152
|
+
decryptVerifyArtifact: <T = Record<string, unknown>>(artifact: VerifyEncryptedPayload<T>, senderPubPem: string, receiverKey?: BTPDecryptionKey) => Promise<BTPCryptoResponse<T>>;
|
|
153
|
+
/**
|
|
154
|
+
* Resolve the identity
|
|
155
|
+
* @param identity - The identity to resolve
|
|
156
|
+
* @param from - The from identity
|
|
157
|
+
* @param receiverKey - The receiver's private key, or a Decrypter holding it
|
|
158
|
+
* @returns The resolved identity
|
|
159
|
+
*/
|
|
160
|
+
resolveIdentity(identity: string, from: string, receiverKey?: BTPDecryptionKey): Promise<{
|
|
161
|
+
response: BTPIdentityResDoc & {
|
|
162
|
+
hostname: string;
|
|
163
|
+
port: number;
|
|
164
|
+
version: string;
|
|
165
|
+
};
|
|
166
|
+
error: undefined;
|
|
167
|
+
} | {
|
|
168
|
+
response: undefined;
|
|
169
|
+
error: BTPErrorException;
|
|
170
|
+
}>;
|
|
171
|
+
/**
|
|
172
|
+
* Add a listener to the client
|
|
173
|
+
* @param event - The event to listen to
|
|
174
|
+
* @param listener - The listener to add
|
|
175
|
+
* @returns The client instance
|
|
176
|
+
*/
|
|
177
|
+
on: TypedEventEmitter<BtpsClientEvents>['on'];
|
|
178
|
+
/**
|
|
179
|
+
* Remove a listener from the client
|
|
180
|
+
* @param event - The event to remove the listener from
|
|
181
|
+
* @param listener - The listener to remove
|
|
182
|
+
* @returns The client instance
|
|
183
|
+
*/
|
|
184
|
+
off: TypedEventEmitter<BtpsClientEvents>['off'];
|
|
185
|
+
/**
|
|
186
|
+
* Cleanup the listeners
|
|
187
|
+
*/
|
|
188
|
+
removeAllListeners(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Get the protocol version
|
|
191
|
+
* @returns The protocol version
|
|
192
|
+
*/
|
|
193
|
+
getProtocolVersion(): string;
|
|
194
|
+
/**
|
|
195
|
+
* End the connection
|
|
196
|
+
*/
|
|
197
|
+
end(): void;
|
|
198
|
+
/**
|
|
199
|
+
* Destroy the client
|
|
200
|
+
*/
|
|
201
|
+
destroy(): void;
|
|
202
|
+
}
|