@btps/sdk 1.1.3 → 1.2.0-rc.2

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 +461 -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 +99 -12
  52. package/dist/core/server/schemas/bounded.js +2 -2
  53. package/dist/core/server/schemas/btpsDocsSchema.d.ts +36009 -1083
  54. package/dist/core/server/schemas/btpsDocsSchema.js +305 -42
  55. package/dist/core/server/schemas/helpers.d.ts +10090 -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 +312 -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 +79 -5
  89. package/dist/server/btpsServer.js +297 -145
  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 +103 -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,18 @@ 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: what each of this server's identities is, as its platform says. */
32
+ private readonly entityTypeOf?;
33
+ /** Since 1.2: how a sender's, a delegator's and an attestor's key is checked against its key chain. */
34
+ private readonly keyChains;
35
+ /** Since 1.2: what `on(…)` tells its listeners, apart from the artifact handlers. */
36
+ private readonly events;
37
+ /** With signAnswers: each connection's last answer, which the next waits for. */
38
+ private readonly answersOnSocket;
28
39
  private readonly dependencies;
29
40
  private readonly port;
30
41
  private server;
@@ -99,6 +110,19 @@ export declare class BtpsServer {
99
110
  * Core agent trust verification (non-negotiable)
100
111
  */
101
112
  private verifyAgentTrust;
113
+ /**
114
+ * Since 1.2: a device's send checked by its own provider before it goes, as
115
+ * its receiver will check it: under a trust with permissions it names a
116
+ * documentType the receiver granted. A trust without them, or none, adds nothing here.
117
+ */
118
+ private verifyDocumentSend;
119
+ /**
120
+ * Since 1.2: a details refresh a device sends, checked by its own provider
121
+ * before it goes, as its receiver will check it: from the user's own record
122
+ * of the trust, where what the user shares is what the receiver holds. A
123
+ * response answers a request the user received from that receiver.
124
+ */
125
+ private verifyDetailsSend;
102
126
  /**
103
127
  * Verifies attestation signatures for delegated artifacts
104
128
  *
@@ -170,10 +194,43 @@ export declare class BtpsServer {
170
194
  * too. Other artifacts pass.
171
195
  */
172
196
  private verifyEventRelation;
197
+ /**
198
+ * Since 1.2: a details refresh, on an active trust in either direction, read
199
+ * from the receiver's own record of it: its names against what each side
200
+ * holds, and a response against a request it knows. Nothing is decrypted.
201
+ */
202
+ private verifyDetailsTrust;
203
+ /**
204
+ * Since 1.2: tell listeners of a details refresh only once every check has
205
+ * passed, the platform's own middleware included: a request that arrived,
206
+ * or a response one of this provider's devices sends.
207
+ */
208
+ private tellDetails;
209
+ /**
210
+ * Since 1.2: tell every listener, each on its own: one that throws is warned
211
+ * about and never stops the others or the artifact.
212
+ */
213
+ private tell;
214
+ /**
215
+ * Since 1.2: listen for `detailsRequested`, emitted when a details request
216
+ * arrives and passes its checks, and `detailsShared`, emitted when one of
217
+ * this provider's devices sends a details response that passes them: who
218
+ * asked or gave whom which details, and when.
219
+ */
220
+ on<K extends keyof BtpsServerEvents>(event: K, listener: BtpsServerEvents[K]): void;
221
+ /** Since 1.2: stop listening. */
222
+ off<K extends keyof BtpsServerEvents>(event: K, listener: BtpsServerEvents[K]): void;
173
223
  /**
174
224
  * Core trust verification (non-negotiable)
175
225
  */
176
226
  private verifyTrust;
227
+ /**
228
+ * Since 1.2: a person's trust request that asks for details without giving its own. It is
229
+ * refused unless its receiver is an organisation, as `entityTypeOf` says: a person asking an
230
+ * organisation gives nothing in return. A receiver this server cannot say is held to be a
231
+ * person. An organisation's request is held to it by the schema, whoever receives it.
232
+ */
233
+ private detailsOwedByPerson;
177
234
  /**
178
235
  * A trust records how its artifacts are sent: 'encrypted' refuses one sent in
179
236
  * the clear, 'unencrypted' one the receiver did not agree to decrypt, and
@@ -208,6 +265,12 @@ export declare class BtpsServer {
208
265
  * metrics do, so it takes nothing.
209
266
  */
210
267
  private acceptsArtifacts;
268
+ /**
269
+ * Whether the implementor takes errors into its own logs, through the
270
+ * onError option or onError middleware. Then the server does not also write
271
+ * them to console.error.
272
+ */
273
+ private takesErrors;
211
274
  private noHandlerWarning;
212
275
  /**
213
276
  * Core message processing (non-negotiable)
@@ -240,12 +303,16 @@ export declare class BtpsServer {
240
303
  * Sends a BTPS error response to the client
241
304
  */
242
305
  /**
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.
306
+ * What a sender is told about an error. A BTPS error, from its constant,
307
+ * carries its status and its code; a numeric code middleware sends with
308
+ * `res.sendError` goes as given. Anything else, a thrown error with a code
309
+ * of its own included, is internal: a generic 500, so no internal detail
310
+ * ever reaches the wire. The full error stays with the server, keyed by the
311
+ * response id. Since 1.2, a 429 also carries its meta.retryAfter, in whole
312
+ * seconds; nothing else from meta, and never cause.
247
313
  */
248
314
  private wireStatus;
315
+ private errorStatus;
249
316
  private sendBtpsError;
250
317
  /**
251
318
  * Sends a BTPS response to the client
@@ -253,6 +320,13 @@ export declare class BtpsServer {
253
320
  * @param artifact - The artifact to send
254
321
  */
255
322
  private sendBtpsResponse;
323
+ /**
324
+ * The answer signed as this server, under its own selector, so a device that
325
+ * requires its server's signature can read it, a refusal included. Unsigned
326
+ * when signing fails, which the failure reports to onError.
327
+ */
328
+ private signAnswer;
329
+ private writeAnswer;
256
330
  /**
257
331
  * Returns the BTPS protocol version
258
332
  */