@btps/sdk 0.0.0-stage → 1.1.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 (155) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/LICENSE +190 -0
  3. package/NOTICE +25 -0
  4. package/README.md +261 -2
  5. package/dist/client/btpsAgent.d.ts +20 -0
  6. package/dist/client/btpsAgent.js +172 -0
  7. package/dist/client/btpsClient.d.ts +202 -0
  8. package/dist/client/btpsClient.js +602 -0
  9. package/dist/client/btpsTransporter.d.ts +52 -0
  10. package/dist/client/btpsTransporter.js +249 -0
  11. package/dist/client/constants/index.d.ts +11 -0
  12. package/dist/client/constants/index.js +20 -0
  13. package/dist/client/index.d.ts +12 -0
  14. package/dist/client/index.js +27 -0
  15. package/dist/client/libs/schema.js +56 -0
  16. package/dist/client/libs/timeouts.d.ts +22 -0
  17. package/dist/client/libs/timeouts.js +19 -0
  18. package/dist/client/types/index.d.ts +155 -0
  19. package/dist/client/types/index.js +7 -0
  20. package/dist/core/authentication/BtpsAuthentication.d.ts +128 -0
  21. package/dist/core/authentication/BtpsAuthentication.js +293 -0
  22. package/dist/core/authentication/index.d.ts +11 -0
  23. package/dist/core/authentication/index.js +12 -0
  24. package/dist/core/authentication/keyProof.d.ts +18 -0
  25. package/dist/core/authentication/keyProof.js +16 -0
  26. package/dist/core/authentication/storage/InMemoryAuthSessionStore.d.ts +55 -0
  27. package/dist/core/authentication/storage/InMemoryAuthSessionStore.js +62 -0
  28. package/dist/core/authentication/storage/InMemoryTokenStore.d.ts +63 -0
  29. package/dist/core/authentication/storage/InMemoryTokenStore.js +63 -0
  30. package/dist/core/authentication/types.d.ts +135 -0
  31. package/dist/core/authentication/types.js +7 -0
  32. package/dist/core/crypto/decryptVerify.d.ts +9 -0
  33. package/dist/core/crypto/decryptVerify.js +45 -0
  34. package/dist/core/crypto/decrypter-interface.d.ts +25 -0
  35. package/dist/core/crypto/decrypter-interface.js +7 -0
  36. package/dist/core/crypto/index.d.ts +77 -0
  37. package/dist/core/crypto/index.js +210 -0
  38. package/dist/core/crypto/jcs.d.ts +28 -0
  39. package/dist/core/crypto/jcs.js +60 -0
  40. package/dist/core/crypto/keygen.d.ts +9 -0
  41. package/dist/core/crypto/keygen.js +35 -0
  42. package/dist/core/crypto/pem-decrypter.d.ts +26 -0
  43. package/dist/core/crypto/pem-decrypter.js +52 -0
  44. package/dist/core/crypto/pem-signer.d.ts +21 -0
  45. package/dist/core/crypto/pem-signer.js +34 -0
  46. package/dist/core/crypto/signEncrypt.d.ts +34 -0
  47. package/dist/core/crypto/signEncrypt.js +75 -0
  48. package/dist/core/crypto/signer-interface.d.ts +22 -0
  49. package/dist/core/crypto/signer-interface.js +7 -0
  50. package/dist/core/crypto/types.d.ts +79 -0
  51. package/dist/core/crypto/types.js +7 -0
  52. package/dist/core/delegation/BtpsDelegator.d.ts +102 -0
  53. package/dist/core/delegation/BtpsDelegator.js +118 -0
  54. package/dist/core/delegation/index.d.ts +7 -0
  55. package/dist/core/delegation/index.js +8 -0
  56. package/dist/core/error/constant.d.ts +66 -0
  57. package/dist/core/error/constant.js +194 -0
  58. package/dist/core/error/index.d.ts +35 -0
  59. package/dist/core/error/index.js +52 -0
  60. package/dist/core/error/types.d.ts +16 -0
  61. package/dist/core/error/types.js +7 -0
  62. package/dist/core/server/constants/btps-protocol.d.ts +17 -0
  63. package/dist/core/server/constants/btps-protocol.js +25 -0
  64. package/dist/core/server/constants/control.d.ts +7 -0
  65. package/dist/core/server/constants/control.js +11 -0
  66. package/dist/core/server/constants/currency.d.ts +7 -0
  67. package/dist/core/server/constants/currency.js +332 -0
  68. package/dist/core/server/constants/index.d.ts +26 -0
  69. package/dist/core/server/constants/index.js +61 -0
  70. package/dist/core/server/constants/limits.d.ts +50 -0
  71. package/dist/core/server/constants/limits.js +50 -0
  72. package/dist/core/server/helpers/BtpsMessageQueue.d.ts +13 -0
  73. package/dist/core/server/helpers/BtpsMessageQueue.js +12 -0
  74. package/dist/core/server/helpers/InMemoryQueue.d.ts +16 -0
  75. package/dist/core/server/helpers/InMemoryQueue.js +35 -0
  76. package/dist/core/server/helpers/index.d.ts +8 -0
  77. package/dist/core/server/helpers/index.js +9 -0
  78. package/dist/core/server/schemas/artifacts/agentSchema.js +51 -0
  79. package/dist/core/server/schemas/artifacts/artifacts.js +21 -0
  80. package/dist/core/server/schemas/artifacts/controlSchema.js +18 -0
  81. package/dist/core/server/schemas/artifacts/identityLookupSchema.js +21 -0
  82. package/dist/core/server/schemas/artifacts/transporterSchema.js +60 -0
  83. package/dist/core/server/schemas/btpsDocsSchema.d.ts +4519 -0
  84. package/dist/core/server/schemas/btpsDocsSchema.js +272 -0
  85. package/dist/core/server/schemas/helpers.js +87 -0
  86. package/dist/core/server/schemas/responseSchema.js +86 -0
  87. package/dist/core/server/schemas/schema.js +70 -0
  88. package/dist/core/server/schemas/shared.js +18 -0
  89. package/dist/core/server/types.d.ts +172 -0
  90. package/dist/core/server/types.js +7 -0
  91. package/dist/core/storage/AbstractIdentityStore.d.ts +17 -0
  92. package/dist/core/storage/AbstractIdentityStore.js +13 -0
  93. package/dist/core/storage/AbstractStorageStore.d.ts +16 -0
  94. package/dist/core/storage/AbstractStorageStore.js +17 -0
  95. package/dist/core/storage/JsonIdentityStore.d.ts +29 -0
  96. package/dist/core/storage/JsonIdentityStore.js +39 -0
  97. package/dist/core/storage/JsonStorageStore.d.ts +59 -0
  98. package/dist/core/storage/JsonStorageStore.js +110 -0
  99. package/dist/core/storage/index.d.ts +11 -0
  100. package/dist/core/storage/index.js +18 -0
  101. package/dist/core/storage/types.d.ts +28 -0
  102. package/dist/core/storage/types.js +7 -0
  103. package/dist/core/trust/index.d.ts +10 -0
  104. package/dist/core/trust/index.js +15 -0
  105. package/dist/core/trust/storage/AbstractTrustStore.d.ts +23 -0
  106. package/dist/core/trust/storage/AbstractTrustStore.js +13 -0
  107. package/dist/core/trust/storage/JsonTrustStore.d.ts +33 -0
  108. package/dist/core/trust/storage/JsonTrustStore.js +42 -0
  109. package/dist/core/trust/trustUtils.d.ts +78 -0
  110. package/dist/core/trust/trustUtils.js +41 -0
  111. package/dist/core/trust/types.d.ts +53 -0
  112. package/dist/core/trust/types.js +7 -0
  113. package/dist/core/utils/identity.d.ts +20 -0
  114. package/dist/core/utils/identity.js +22 -0
  115. package/dist/core/utils/index.d.ts +70 -0
  116. package/dist/core/utils/index.js +124 -0
  117. package/dist/core/utils/types.d.ts +10 -0
  118. package/dist/core/utils/types.js +7 -0
  119. package/dist/core/utils/validation.js +13 -0
  120. package/dist/index.d.ts +7 -0
  121. package/dist/index.js +8 -0
  122. package/dist/server/btpsServer.d.ts +292 -0
  123. package/dist/server/btpsServer.js +827 -0
  124. package/dist/server/index.d.ts +11 -0
  125. package/dist/server/index.js +15 -0
  126. package/dist/server/libs/abstractRateLimiter.d.ts +10 -0
  127. package/dist/server/libs/abstractRateLimiter.js +15 -0
  128. package/dist/server/libs/artifactSizeGuard.d.ts +27 -0
  129. package/dist/server/libs/artifactSizeGuard.js +44 -0
  130. package/dist/server/libs/artifactTimeWindow.d.ts +24 -0
  131. package/dist/server/libs/artifactTimeWindow.js +30 -0
  132. package/dist/server/libs/btpsFactory.d.ts +29 -0
  133. package/dist/server/libs/btpsFactory.js +49 -0
  134. package/dist/server/libs/btpsLightweightFactory.d.ts +35 -0
  135. package/dist/server/libs/btpsLightweightFactory.js +37 -0
  136. package/dist/server/libs/btpsRegistry.d.ts +14 -0
  137. package/dist/server/libs/btpsRegistry.js +16 -0
  138. package/dist/server/libs/btpsSimpleMetricsTracker.d.ts +13 -0
  139. package/dist/server/libs/btpsSimpleMetricsTracker.js +21 -0
  140. package/dist/server/libs/btpsSimpleRateLimiter.d.ts +28 -0
  141. package/dist/server/libs/btpsSimpleRateLimiter.js +46 -0
  142. package/dist/server/libs/connectionTimeout.d.ts +16 -0
  143. package/dist/server/libs/connectionTimeout.js +14 -0
  144. package/dist/server/libs/defaultMiddleware.d.ts +8 -0
  145. package/dist/server/libs/defaultMiddleware.js +128 -0
  146. package/dist/server/libs/inFlightLimit.d.ts +18 -0
  147. package/dist/server/libs/inFlightLimit.js +17 -0
  148. package/dist/server/libs/index.d.ts +18 -0
  149. package/dist/server/libs/index.js +34 -0
  150. package/dist/server/libs/middlewareManager.js +126 -0
  151. package/dist/server/libs/type.d.ts +22 -0
  152. package/dist/server/libs/type.js +7 -0
  153. package/dist/server/types.d.ts +236 -0
  154. package/dist/server/types.js +7 -0
  155. package/package.json +126 -4
@@ -0,0 +1,332 @@
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
+ const CURRENCY_CODES = [
9
+ "AED",
10
+
11
+ "AFN",
12
+
13
+ "ALL",
14
+
15
+ "AMD",
16
+
17
+ "ANG",
18
+
19
+ "AOA",
20
+
21
+ "ARS",
22
+
23
+ "AUD",
24
+
25
+ "AWG",
26
+
27
+ "AZN",
28
+
29
+ "BAM",
30
+
31
+ "BBD",
32
+
33
+ "BDT",
34
+
35
+ "BGN",
36
+
37
+ "BHD",
38
+
39
+ "BIF",
40
+
41
+ "BMD",
42
+
43
+ "BND",
44
+
45
+ "BOB",
46
+
47
+ "BRL",
48
+
49
+ "BSD",
50
+
51
+ "BTN",
52
+
53
+ "BWP",
54
+
55
+ "BYN",
56
+
57
+ "BZD",
58
+
59
+ "CAD",
60
+
61
+ "CDF",
62
+
63
+ "CHF",
64
+
65
+ "CLP",
66
+
67
+ "CNY",
68
+
69
+ "COP",
70
+
71
+ "CRC",
72
+
73
+ "CUP",
74
+
75
+ "CVE",
76
+
77
+ "CZK",
78
+
79
+ "DJF",
80
+
81
+ "DKK",
82
+
83
+ "DOP",
84
+
85
+ "DZD",
86
+
87
+ "EGP",
88
+
89
+ "ERN",
90
+
91
+ "ETB",
92
+
93
+ "EUR",
94
+
95
+ "FJD",
96
+
97
+ "FKP",
98
+
99
+ "FOK",
100
+
101
+ "GBP",
102
+
103
+ "GEL",
104
+
105
+ "GGP",
106
+
107
+ "GHS",
108
+
109
+ "GIP",
110
+
111
+ "GMD",
112
+
113
+ "GNF",
114
+
115
+ "GTQ",
116
+
117
+ "GYD",
118
+
119
+ "HKD",
120
+
121
+ "HNL",
122
+
123
+ "HRK",
124
+
125
+ "HTG",
126
+
127
+ "HUF",
128
+
129
+ "IDR",
130
+
131
+ "ILS",
132
+
133
+ "IMP",
134
+
135
+ "INR",
136
+
137
+ "IQD",
138
+
139
+ "IRR",
140
+
141
+ "ISK",
142
+
143
+ "JEP",
144
+
145
+ "JMD",
146
+
147
+ "JOD",
148
+
149
+ "JPY",
150
+
151
+ "KES",
152
+
153
+ "KGS",
154
+
155
+ "KHR",
156
+
157
+ "KID",
158
+
159
+ "KMF",
160
+
161
+ "KRW",
162
+
163
+ "KWD",
164
+
165
+ "KYD",
166
+
167
+ "KZT",
168
+
169
+ "LAK",
170
+
171
+ "LBP",
172
+
173
+ "LKR",
174
+
175
+ "LRD",
176
+
177
+ "LSL",
178
+
179
+ "LYD",
180
+
181
+ "MAD",
182
+
183
+ "MDL",
184
+
185
+ "MGA",
186
+
187
+ "MKD",
188
+
189
+ "MMK",
190
+
191
+ "MNT",
192
+
193
+ "MOP",
194
+
195
+ "MRU",
196
+
197
+ "MUR",
198
+
199
+ "MVR",
200
+
201
+ "MWK",
202
+
203
+ "MXN",
204
+
205
+ "MYR",
206
+
207
+ "MZN",
208
+
209
+ "NAD",
210
+
211
+ "NGN",
212
+
213
+ "NIO",
214
+
215
+ "NOK",
216
+
217
+ "NPR",
218
+
219
+ "NZD",
220
+
221
+ "OMR",
222
+
223
+ "PAB",
224
+
225
+ "PEN",
226
+
227
+ "PGK",
228
+
229
+ "PHP",
230
+
231
+ "PKR",
232
+
233
+ "PLN",
234
+
235
+ "PYG",
236
+
237
+ "QAR",
238
+
239
+ "RON",
240
+
241
+ "RSD",
242
+
243
+ "RUB",
244
+
245
+ "RWF",
246
+
247
+ "SAR",
248
+
249
+ "SBD",
250
+
251
+ "SCR",
252
+
253
+ "SDG",
254
+
255
+ "SEK",
256
+
257
+ "SGD",
258
+
259
+ "SHP",
260
+
261
+ "SLL",
262
+
263
+ "SOS",
264
+
265
+ "SRD",
266
+
267
+ "SSP",
268
+
269
+ "STN",
270
+
271
+ "SYP",
272
+
273
+ "SZL",
274
+
275
+ "THB",
276
+
277
+ "TJS",
278
+
279
+ "TMT",
280
+
281
+ "TND",
282
+
283
+ "TOP",
284
+
285
+ "TRY",
286
+
287
+ "TTD",
288
+
289
+ "TVD",
290
+
291
+ "TWD",
292
+
293
+ "TZS",
294
+
295
+ "UAH",
296
+
297
+ "UGX",
298
+
299
+ "USD",
300
+
301
+ "UYU",
302
+
303
+ "UZS",
304
+
305
+ "VES",
306
+
307
+ "VND",
308
+
309
+ "VUV",
310
+
311
+ "WST",
312
+
313
+ "XAF",
314
+
315
+ "XCD",
316
+
317
+ "XOF",
318
+
319
+ "XPF",
320
+
321
+ "YER",
322
+
323
+ "ZAR",
324
+
325
+ "ZMW",
326
+
327
+ "ZWL"
328
+
329
+ ];
330
+ export {
331
+ CURRENCY_CODES
332
+ };
@@ -0,0 +1,26 @@
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
+ export * from './btps-protocol.js';
8
+ export * from './control.js';
9
+ export * from './currency.js';
10
+ export * from './limits.js';
11
+ export declare const AUTH_ACTIONS: readonly ["auth.request", "auth.refresh"];
12
+ export declare const AGENT_ACTIONS: readonly ["trust.request", "trust.respond", "trust.update", "trust.delete", "trust.fetch", "inbox.fetch", "inbox.delete", "inbox.seen", "outbox.fetch", "outbox.cancel", "sentbox.fetch", "sentbox.delete", "draft.fetch", "draft.create", "draft.update", "draft.delete", "system.ping", "auth.request", "auth.refresh", "artifact.send", "event.send", "trash.fetch", "trash.delete"];
13
+ export declare const TRANSPORTER_ACTIONS: readonly ["TRUST_REQ", "TRUST_RES", "BTPS_DOC", "BTPS_EVENT"];
14
+ /**
15
+ * Agent actions that carry a transporter artifact, built by the device, and its
16
+ * type. trust.update and trust.delete are not among them: they edit the user's
17
+ * own trust records at their provider and send nothing.
18
+ */
19
+ export declare const AGENT_TRANSPORTER_ACTIONS: {
20
+ readonly 'trust.request': "TRUST_REQ";
21
+ readonly 'trust.respond': "TRUST_RES";
22
+ readonly 'artifact.send': "BTPS_DOC";
23
+ readonly 'event.send': "BTPS_EVENT";
24
+ };
25
+ export declare const IMMEDIATE_ACTIONS: readonly ["system.ping", "auth.request", "auth.refresh", "inbox.fetch", "inbox.delete", "inbox.seen", "outbox.fetch", "outbox.cancel", "draft.fetch", "draft.create", "draft.update", "draft.delete", "trust.update", "trust.delete", "trust.fetch", "sentbox.fetch", "sentbox.delete", "trash.fetch", "trash.delete"];
26
+ export declare const AGENT_ACTIONS_REQUIRING_DOCUMENT: readonly ["trust.request", "trust.respond", "trust.update", "trust.delete", "artifact.send", "event.send", "auth.request", "auth.refresh", "inbox.seen", "inbox.delete", "sentbox.delete", "outbox.cancel", "draft.create", "draft.update", "draft.delete", "trash.delete"];
@@ -0,0 +1,61 @@
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
+ export * from "./btps-protocol.js";
9
+ export * from "./control.js";
10
+ export * from "./currency.js";
11
+ export * from "./limits.js";
12
+ const TRUST_ACTIONS = ["trust.request", "trust.respond"], TRUST_IMMEDIATE_ACTIONS = ["trust.update", "trust.delete", "trust.fetch"], INBOX_ACTIONS = ["inbox.fetch", "inbox.delete", "inbox.seen"], OUTBOX_ACTIONS = ["outbox.fetch", "outbox.cancel"], SENTBOX_ACTIONS = ["sentbox.fetch", "sentbox.delete"], DRAFT_ACTIONS = ["draft.fetch", "draft.create", "draft.update", "draft.delete"], TRASH_ACTIONS = ["trash.fetch", "trash.delete"], SYSTEM_ACTIONS = ["system.ping"], AUTH_ACTIONS = ["auth.request", "auth.refresh"], ARTIFACT_ACTIONS = ["artifact.send"], EVENT_ACTIONS = ["event.send"], AGENT_ACTIONS = [
13
+ ...TRUST_ACTIONS,
14
+ ...TRUST_IMMEDIATE_ACTIONS,
15
+ ...INBOX_ACTIONS,
16
+ ...OUTBOX_ACTIONS,
17
+ ...SENTBOX_ACTIONS,
18
+ ...DRAFT_ACTIONS,
19
+ ...SYSTEM_ACTIONS,
20
+ ...AUTH_ACTIONS,
21
+ ...ARTIFACT_ACTIONS,
22
+ ...EVENT_ACTIONS,
23
+ ...TRASH_ACTIONS
24
+ ], TRANSPORTER_ACTIONS = ["TRUST_REQ", "TRUST_RES", "BTPS_DOC", "BTPS_EVENT"], AGENT_TRANSPORTER_ACTIONS = {
25
+ "trust.request": "TRUST_REQ",
26
+ "trust.respond": "TRUST_RES",
27
+ "artifact.send": "BTPS_DOC",
28
+ "event.send": "BTPS_EVENT"
29
+ }, IMMEDIATE_ACTIONS = [
30
+ ...SYSTEM_ACTIONS,
31
+ ...AUTH_ACTIONS,
32
+ ...INBOX_ACTIONS,
33
+ ...OUTBOX_ACTIONS,
34
+ ...DRAFT_ACTIONS,
35
+ ...TRUST_IMMEDIATE_ACTIONS,
36
+ ...SENTBOX_ACTIONS,
37
+ ...TRASH_ACTIONS
38
+ ], AGENT_ACTIONS_REQUIRING_DOCUMENT = [
39
+ ...TRUST_ACTIONS,
40
+ "trust.update",
41
+ "trust.delete",
42
+ ...ARTIFACT_ACTIONS,
43
+ ...EVENT_ACTIONS,
44
+ ...AUTH_ACTIONS,
45
+ "inbox.seen",
46
+ "inbox.delete",
47
+ "sentbox.delete",
48
+ "outbox.cancel",
49
+ "draft.create",
50
+ "draft.update",
51
+ "draft.delete",
52
+ "trash.delete"
53
+ ];
54
+ export {
55
+ AGENT_ACTIONS,
56
+ AGENT_ACTIONS_REQUIRING_DOCUMENT,
57
+ AGENT_TRANSPORTER_ACTIONS,
58
+ AUTH_ACTIONS,
59
+ IMMEDIATE_ACTIONS,
60
+ TRANSPORTER_ACTIONS
61
+ };
@@ -0,0 +1,50 @@
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
+ * The longest each field may be, in characters. The protocol fixes these,
9
+ * so every provider accepts the same documents: a provider may be stricter
10
+ * in its own middleware, but cannot raise them. They are raised only by a
11
+ * protocol version.
12
+ */
13
+ export declare const BTPS_FIELD_LIMITS: {
14
+ readonly trustRequest: {
15
+ readonly id: 100;
16
+ readonly name: 200;
17
+ readonly displayName: 200;
18
+ readonly email: 254;
19
+ readonly phone: 32;
20
+ readonly address: 1000;
21
+ readonly reason: 2000;
22
+ readonly message: 5000;
23
+ readonly logoUrl: 2048;
24
+ readonly websiteUrl: 2048;
25
+ };
26
+ readonly trustResponse: {
27
+ readonly id: 100;
28
+ readonly decidedBy: 254;
29
+ readonly message: 5000;
30
+ };
31
+ readonly event: {
32
+ readonly message: 5000;
33
+ readonly reason: 64;
34
+ };
35
+ readonly receipt: {
36
+ readonly paymentMethod: 64;
37
+ readonly paymentReference: 100;
38
+ };
39
+ readonly payslip: {
40
+ readonly code: 64;
41
+ };
42
+ readonly letter: {
43
+ readonly title: 200;
44
+ readonly content: 100000;
45
+ readonly attachments: 10;
46
+ readonly references: 20;
47
+ };
48
+ readonly documentId: 100;
49
+ readonly referenceType: 64;
50
+ };
@@ -0,0 +1,50 @@
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
+ const BTPS_FIELD_LIMITS = {
9
+ trustRequest: {
10
+ id: 100,
11
+ name: 200,
12
+ displayName: 200,
13
+ email: 254,
14
+ phone: 32,
15
+ address: 1e3,
16
+ reason: 2e3,
17
+ message: 5e3,
18
+ logoUrl: 2048,
19
+ websiteUrl: 2048
20
+ },
21
+ trustResponse: {
22
+ id: 100,
23
+ decidedBy: 254,
24
+ message: 5e3
25
+ },
26
+ event: {
27
+ message: 5e3,
28
+ reason: 64
29
+ },
30
+ receipt: {
31
+ paymentMethod: 64,
32
+ paymentReference: 100
33
+ },
34
+ payslip: {
35
+
36
+ code: 64
37
+ },
38
+ letter: {
39
+ title: 200,
40
+ content: 1e5,
41
+ attachments: 10,
42
+ references: 20
43
+ },
44
+
45
+ documentId: 100,
46
+ referenceType: 64
47
+ };
48
+ export {
49
+ BTPS_FIELD_LIMITS
50
+ };
@@ -0,0 +1,13 @@
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 { BTPArtifact } from '../../server/types.js';
8
+ export declare abstract class BTPSMessageQueue {
9
+ abstract add(message: BTPArtifact): Promise<void>;
10
+ abstract getPending(): Promise<BTPArtifact[]>;
11
+ abstract on(event: 'message', handler: (msg: BTPArtifact) => void): void;
12
+ abstract markHandled(id: string): Promise<void>;
13
+ }
@@ -0,0 +1,12 @@
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
+ class BTPSMessageQueue {
9
+ }
10
+ export {
11
+ BTPSMessageQueue
12
+ };
@@ -0,0 +1,16 @@
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 { BTPArtifact } from '../../server/types.js';
8
+ import { BTPSMessageQueue } from './BtpsMessageQueue.js';
9
+ export declare class InMemoryQueue extends BTPSMessageQueue {
10
+ private queues;
11
+ private emitter;
12
+ add(message: BTPArtifact): Promise<void>;
13
+ getPending(identity?: string): Promise<BTPArtifact[]>;
14
+ markHandled(id: string): Promise<void>;
15
+ on(event: 'message', handler: (msg: BTPArtifact) => void): void;
16
+ }
@@ -0,0 +1,35 @@
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 { BTPSMessageQueue } from "./BtpsMessageQueue.js";
9
+ import { EventEmitter } from "events";
10
+ import {
11
+ isBtpsControlArtifact,
12
+ isBtpsIdentityRequest,
13
+ isBtpsTransportArtifact
14
+ } from "../../utils/index.js";
15
+ class InMemoryQueue extends BTPSMessageQueue {
16
+ queues = {};
17
+ emitter = new EventEmitter();
18
+ async add(message) {
19
+ const key = isBtpsTransportArtifact(message) ? message.to : isBtpsIdentityRequest(message) ? message.from : !isBtpsControlArtifact(message) && "agentId" in message ? message.agentId : "unknown-control-request";
20
+ this.queues[key] || (this.queues[key] = []), this.queues[key].push(message), this.emitter.emit("message", message);
21
+ }
22
+ async getPending(identity) {
23
+ return identity ? [...this.queues[identity] || []] : Object.values(this.queues).flat();
24
+ }
25
+ async markHandled(id) {
26
+ for (const key in this.queues)
27
+ this.queues[key] = this.queues[key].filter((msg) => msg.id !== id);
28
+ }
29
+ on(event, handler) {
30
+ this.emitter.on(event, handler);
31
+ }
32
+ }
33
+ export {
34
+ InMemoryQueue
35
+ };
@@ -0,0 +1,8 @@
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
+ export * from './BtpsMessageQueue.js';
8
+ export * from './InMemoryQueue.js';
@@ -0,0 +1,9 @@
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
+ export * from "./BtpsMessageQueue.js";
9
+ export * from "./InMemoryQueue.js";
@@ -0,0 +1,51 @@
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
+ BtpAgentQuerySchema,
10
+ BtpAgentMutationSchema,
11
+ BtpIdsPayloadSchema,
12
+ BtpSignatureSchema,
13
+ BtpEncryptionSchema
14
+ } from "../schema.js";
15
+ import { identitySchema } from "../shared.js";
16
+ import { AGENT_ACTIONS, AGENT_TRANSPORTER_ACTIONS } from "../../constants/index.js";
17
+ import { z } from "zod";
18
+ import { BtpAuthReqDocSchema } from "../btpsDocsSchema.js";
19
+ import { validateAgentDocument } from "../helpers.js";
20
+ import {
21
+ BtpTransporterArtifactBaseSchema,
22
+ BtpTransporterArtifactSchema
23
+ } from "./transporterSchema.js";
24
+ const BtpAgentArtifactSchema = z.object({
25
+ id: z.string(),
26
+ action: z.enum(AGENT_ACTIONS),
27
+ document: z.union([
28
+ BtpTransporterArtifactBaseSchema,
29
+ BtpAuthReqDocSchema,
30
+ BtpAgentQuerySchema,
31
+ BtpAgentMutationSchema,
32
+ BtpIdsPayloadSchema,
33
+ z.string()
34
+ ]).optional(),
35
+ agentId: z.string(),
36
+ to: identitySchema,
37
+ issuedAt: z.string().datetime(),
38
+ signature: BtpSignatureSchema,
39
+ encryption: BtpEncryptionSchema.nullable()
40
+ }).refine((data) => validateAgentArtifactDocument(data.action, data.encryption, data.document), {
41
+ message: "Document is required for this action type or document format is invalid",
42
+ path: ["document"]
43
+ }), validateAgentArtifactDocument = (action, encryption, document) => {
44
+ if (!(action in AGENT_TRANSPORTER_ACTIONS))
45
+ return validateAgentDocument(action, encryption, document);
46
+ const carried = BtpTransporterArtifactSchema.safeParse(document);
47
+ return carried.success && carried.data.type === AGENT_TRANSPORTER_ACTIONS[action];
48
+ };
49
+ export {
50
+ BtpAgentArtifactSchema
51
+ };
@@ -0,0 +1,21 @@
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 { z } from "zod";
9
+ import { BtpAgentArtifactSchema } from "./agentSchema.js";
10
+ import { BtpTransporterArtifactSchema } from "./transporterSchema.js";
11
+ import { BtpControlArtifactSchema } from "./controlSchema.js";
12
+ import { BtpIdentityLookupRequestSchema } from "./identityLookupSchema.js";
13
+ const BtpArtifactServerSchema = z.union([
14
+ BtpAgentArtifactSchema,
15
+ BtpTransporterArtifactSchema,
16
+ BtpControlArtifactSchema,
17
+ BtpIdentityLookupRequestSchema
18
+ ]);
19
+ export {
20
+ BtpArtifactServerSchema
21
+ };