@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.
Files changed (111) hide show
  1. package/CHANGELOG.md +422 -0
  2. package/bin/verify-evidence-bundle.mjs +96 -0
  3. package/dist/client/btpsAgent.d.ts +10 -1
  4. package/dist/client/btpsAgent.js +116 -18
  5. package/dist/client/btpsClient.d.ts +53 -7
  6. package/dist/client/btpsClient.js +265 -147
  7. package/dist/client/index.d.ts +1 -1
  8. package/dist/client/index.js +3 -1
  9. package/dist/client/libs/schema.js +78 -13
  10. package/dist/client/libs/timeouts.d.ts +6 -0
  11. package/dist/client/libs/timeouts.js +2 -1
  12. package/dist/client/types/index.d.ts +54 -2
  13. package/dist/core/authentication/BtpsAuthentication.d.ts +43 -1
  14. package/dist/core/authentication/BtpsAuthentication.js +152 -36
  15. package/dist/core/authentication/refreshSuccessor.js +47 -0
  16. package/dist/core/authentication/storage/InMemoryTokenStore.d.ts +17 -1
  17. package/dist/core/authentication/storage/InMemoryTokenStore.js +16 -4
  18. package/dist/core/authentication/types.d.ts +82 -0
  19. package/dist/core/crypto/contentKey.d.ts +34 -0
  20. package/dist/core/crypto/contentKey.js +64 -0
  21. package/dist/core/crypto/decryptVerify.d.ts +7 -1
  22. package/dist/core/crypto/decryptVerify.js +23 -5
  23. package/dist/core/crypto/decrypter-interface.d.ts +6 -0
  24. package/dist/core/crypto/index.d.ts +12 -0
  25. package/dist/core/crypto/index.js +7 -1
  26. package/dist/core/crypto/keyResolver.d.ts +48 -0
  27. package/dist/core/crypto/keyResolver.js +46 -0
  28. package/dist/core/crypto/pem-decrypter.d.ts +2 -0
  29. package/dist/core/crypto/pem-decrypter.js +13 -8
  30. package/dist/core/crypto/signEncrypt.d.ts +4 -1
  31. package/dist/core/crypto/signEncrypt.js +20 -5
  32. package/dist/core/crypto/types.d.ts +8 -1
  33. package/dist/core/delegation/BtpsDelegator.d.ts +4 -0
  34. package/dist/core/delegation/BtpsDelegator.js +3 -2
  35. package/dist/core/delegation/verifyTransporterSignature.d.ts +104 -0
  36. package/dist/core/delegation/verifyTransporterSignature.js +224 -0
  37. package/dist/core/error/constant.d.ts +39 -0
  38. package/dist/core/error/constant.js +55 -0
  39. package/dist/core/server/constants/btps-protocol.d.ts +21 -5
  40. package/dist/core/server/constants/btps-protocol.js +46 -8
  41. package/dist/core/server/constants/index.d.ts +7 -3
  42. package/dist/core/server/constants/index.js +19 -4
  43. package/dist/core/server/constants/limits.d.ts +18 -0
  44. package/dist/core/server/constants/limits.js +19 -1
  45. package/dist/core/server/constants/permissions.d.ts +38 -0
  46. package/dist/core/server/constants/permissions.js +38 -0
  47. package/dist/core/server/schemas/artifacts/agentSchema.js +2 -1
  48. package/dist/core/server/schemas/artifacts/artifacts.js +7 -1
  49. package/dist/core/server/schemas/artifacts/controlSchema.js +1 -1
  50. package/dist/core/server/schemas/artifacts/identityLookupSchema.js +10 -1
  51. package/dist/core/server/schemas/artifacts/transporterSchema.js +92 -12
  52. package/dist/core/server/schemas/bounded.js +2 -2
  53. package/dist/core/server/schemas/btpsDocsSchema.d.ts +34185 -1084
  54. package/dist/core/server/schemas/btpsDocsSchema.js +300 -42
  55. package/dist/core/server/schemas/helpers.d.ts +9580 -0
  56. package/dist/core/server/schemas/helpers.js +76 -12
  57. package/dist/core/server/schemas/keyChainSchema.js +53 -0
  58. package/dist/core/server/schemas/responseSchema.js +52 -9
  59. package/dist/core/server/schemas/schema.js +3 -1
  60. package/dist/core/server/schemas/trustValues.d.ts +105 -0
  61. package/dist/core/server/schemas/trustValues.js +117 -0
  62. package/dist/core/server/types.d.ts +104 -6
  63. package/dist/core/storage/AbstractIdentityStore.d.ts +9 -0
  64. package/dist/core/storage/JsonIdentityStore.d.ts +3 -0
  65. package/dist/core/storage/JsonIdentityStore.js +3 -0
  66. package/dist/core/storage/types.d.ts +2 -0
  67. package/dist/core/trust/agreements.d.ts +107 -0
  68. package/dist/core/trust/agreements.js +116 -0
  69. package/dist/core/trust/evidence.d.ts +220 -0
  70. package/dist/core/trust/evidence.js +334 -0
  71. package/dist/core/trust/index.d.ts +10 -0
  72. package/dist/core/trust/index.js +14 -1
  73. package/dist/core/trust/keyRotation.d.ts +148 -0
  74. package/dist/core/trust/keyRotation.js +267 -0
  75. package/dist/core/trust/permissions.d.ts +114 -0
  76. package/dist/core/trust/permissions.js +115 -0
  77. package/dist/core/trust/shaping.d.ts +42 -0
  78. package/dist/core/trust/shaping.js +47 -0
  79. package/dist/core/trust/storage/AbstractTrustStore.d.ts +2 -1
  80. package/dist/core/trust/storage/JsonTrustStore.d.ts +3 -2
  81. package/dist/core/trust/timestamps.d.ts +49 -0
  82. package/dist/core/trust/timestamps.js +78 -0
  83. package/dist/core/trust/trustUtils.d.ts +13 -2
  84. package/dist/core/trust/trustUtils.js +28 -3
  85. package/dist/core/trust/types.d.ts +302 -2
  86. package/dist/core/trust/verification.d.ts +52 -0
  87. package/dist/core/trust/verification.js +55 -0
  88. package/dist/server/btpsServer.d.ts +70 -5
  89. package/dist/server/btpsServer.js +263 -143
  90. package/dist/server/index.d.ts +3 -0
  91. package/dist/server/index.js +17 -1
  92. package/dist/server/libs/agreementOrderCheck.d.ts +29 -0
  93. package/dist/server/libs/agreementOrderCheck.js +29 -0
  94. package/dist/server/libs/artifactTimeWindow.d.ts +2 -2
  95. package/dist/server/libs/artifactTimeWindow.js +2 -1
  96. package/dist/server/libs/detailsRequestLimit.d.ts +27 -0
  97. package/dist/server/libs/detailsRequestLimit.js +28 -0
  98. package/dist/server/libs/detailsResponseCheck.d.ts +27 -0
  99. package/dist/server/libs/detailsResponseCheck.js +27 -0
  100. package/dist/server/libs/eventChainCheck.d.ts +31 -0
  101. package/dist/server/libs/eventChainCheck.js +39 -0
  102. package/dist/server/libs/inFlightLimit.d.ts +10 -0
  103. package/dist/server/libs/inFlightLimit.js +7 -1
  104. package/dist/server/libs/index.d.ts +5 -0
  105. package/dist/server/libs/index.js +10 -0
  106. package/dist/server/libs/keyChains.d.ts +14 -0
  107. package/dist/server/libs/keyChains.js +17 -0
  108. package/dist/server/libs/wrapForAgent.d.ts +20 -0
  109. package/dist/server/libs/wrapForAgent.js +36 -0
  110. package/dist/server/types.d.ts +95 -9
  111. package/package.json +12 -3
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { BTPTrustRecord } from '../core/trust/index.js';
8
8
  import type { BTPAgentArtifact, BTPServerResponse, BTPStatus, BTPTransporterArtifact } from '../core/server/types.js';
9
- import type { BtpsServerOptions, ProcessedArtifact, ArtifactResCtx } from './types.js';
9
+ import type { BtpsServerEvents, BtpsServerOptions, ProcessedArtifact, ArtifactResCtx } from './types.js';
10
10
  import type { AbstractTrustStore } from '../core/trust/storage/AbstractTrustStore.js';
11
11
  import type { BTPIdentityRecord } from '../core/storage/types.js';
12
12
  import type { AbstractIdentityStore } from '../core/storage/AbstractIdentityStore.js';
@@ -24,7 +24,16 @@ export declare class BtpsServer {
24
24
  private readonly connectionTimeoutMs;
25
25
  private readonly maxArtifactSizeKb;
26
26
  private readonly maxInFlightPerConnection;
27
+ private readonly maxConsecutiveInvalidLines;
27
28
  private readonly maxArtifactAgeSeconds;
29
+ private readonly signAnswers;
30
+ private readonly keyResolver?;
31
+ /** Since 1.2: how a sender's, a delegator's and an attestor's key is checked against its key chain. */
32
+ private readonly keyChains;
33
+ /** Since 1.2: what `on(…)` tells its listeners, apart from the artifact handlers. */
34
+ private readonly events;
35
+ /** With signAnswers: each connection's last answer, which the next waits for. */
36
+ private readonly answersOnSocket;
28
37
  private readonly dependencies;
29
38
  private readonly port;
30
39
  private server;
@@ -99,6 +108,19 @@ export declare class BtpsServer {
99
108
  * Core agent trust verification (non-negotiable)
100
109
  */
101
110
  private verifyAgentTrust;
111
+ /**
112
+ * Since 1.2: a device's send checked by its own provider before it goes, as
113
+ * its receiver will check it: under a trust with permissions it names a
114
+ * documentType the receiver granted. A trust without them, or none, adds nothing here.
115
+ */
116
+ private verifyDocumentSend;
117
+ /**
118
+ * Since 1.2: a details refresh a device sends, checked by its own provider
119
+ * before it goes, as its receiver will check it: from the user's own record
120
+ * of the trust, where what the user shares is what the receiver holds. A
121
+ * response answers a request the user received from that receiver.
122
+ */
123
+ private verifyDetailsSend;
102
124
  /**
103
125
  * Verifies attestation signatures for delegated artifacts
104
126
  *
@@ -170,6 +192,32 @@ export declare class BtpsServer {
170
192
  * too. Other artifacts pass.
171
193
  */
172
194
  private verifyEventRelation;
195
+ /**
196
+ * Since 1.2: a details refresh, on an active trust in either direction, read
197
+ * from the receiver's own record of it: its names against what each side
198
+ * holds, and a response against a request it knows. Nothing is decrypted.
199
+ */
200
+ private verifyDetailsTrust;
201
+ /**
202
+ * Since 1.2: tell listeners of a details refresh only once every check has
203
+ * passed, the platform's own middleware included: a request that arrived,
204
+ * or a response one of this provider's devices sends.
205
+ */
206
+ private tellDetails;
207
+ /**
208
+ * Since 1.2: tell every listener, each on its own: one that throws is warned
209
+ * about and never stops the others or the artifact.
210
+ */
211
+ private tell;
212
+ /**
213
+ * Since 1.2: listen for `detailsRequested`, emitted when a details request
214
+ * arrives and passes its checks, and `detailsShared`, emitted when one of
215
+ * this provider's devices sends a details response that passes them: who
216
+ * asked or gave whom which details, and when.
217
+ */
218
+ on<K extends keyof BtpsServerEvents>(event: K, listener: BtpsServerEvents[K]): void;
219
+ /** Since 1.2: stop listening. */
220
+ off<K extends keyof BtpsServerEvents>(event: K, listener: BtpsServerEvents[K]): void;
173
221
  /**
174
222
  * Core trust verification (non-negotiable)
175
223
  */
@@ -208,6 +256,12 @@ export declare class BtpsServer {
208
256
  * metrics do, so it takes nothing.
209
257
  */
210
258
  private acceptsArtifacts;
259
+ /**
260
+ * Whether the implementor takes errors into its own logs, through the
261
+ * onError option or onError middleware. Then the server does not also write
262
+ * them to console.error.
263
+ */
264
+ private takesErrors;
211
265
  private noHandlerWarning;
212
266
  /**
213
267
  * Core message processing (non-negotiable)
@@ -240,12 +294,16 @@ export declare class BtpsServer {
240
294
  * Sends a BTPS error response to the client
241
295
  */
242
296
  /**
243
- * What a sender is told about an error. A BTPS error carries its status and
244
- * its code; a numeric code set by middleware is sent as given. Anything else
245
- * is internal: a generic 500, so no internal detail ever reaches the wire.
246
- * The full error stays with the server, keyed by the response id.
297
+ * What a sender is told about an error. A BTPS error, from its constant,
298
+ * carries its status and its code; a numeric code middleware sends with
299
+ * `res.sendError` goes as given. Anything else, a thrown error with a code
300
+ * of its own included, is internal: a generic 500, so no internal detail
301
+ * ever reaches the wire. The full error stays with the server, keyed by the
302
+ * response id. Since 1.2, a 429 also carries its meta.retryAfter, in whole
303
+ * seconds; nothing else from meta, and never cause.
247
304
  */
248
305
  private wireStatus;
306
+ private errorStatus;
249
307
  private sendBtpsError;
250
308
  /**
251
309
  * Sends a BTPS response to the client
@@ -253,6 +311,13 @@ export declare class BtpsServer {
253
311
  * @param artifact - The artifact to send
254
312
  */
255
313
  private sendBtpsResponse;
314
+ /**
315
+ * The answer signed as this server, under its own selector, so a device that
316
+ * requires its server's signature can read it, a refusal included. Unsigned
317
+ * when signing fails, which the failure reports to onError.
318
+ */
319
+ private signAnswer;
320
+ private writeAnswer;
256
321
  /**
257
322
  * Returns the BTPS protocol version
258
323
  */