@btps/sdk 1.1.2 → 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 (112) hide show
  1. package/CHANGELOG.md +475 -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 +117 -19
  5. package/dist/client/btpsClient.d.ts +53 -7
  6. package/dist/client/btpsClient.js +266 -137
  7. package/dist/client/btpsTransporter.js +2 -1
  8. package/dist/client/index.d.ts +1 -1
  9. package/dist/client/index.js +3 -1
  10. package/dist/client/libs/schema.js +92 -15
  11. package/dist/client/libs/timeouts.d.ts +6 -0
  12. package/dist/client/libs/timeouts.js +2 -1
  13. package/dist/client/types/index.d.ts +60 -2
  14. package/dist/core/authentication/BtpsAuthentication.d.ts +43 -1
  15. package/dist/core/authentication/BtpsAuthentication.js +152 -36
  16. package/dist/core/authentication/refreshSuccessor.js +47 -0
  17. package/dist/core/authentication/storage/InMemoryTokenStore.d.ts +17 -1
  18. package/dist/core/authentication/storage/InMemoryTokenStore.js +16 -4
  19. package/dist/core/authentication/types.d.ts +82 -0
  20. package/dist/core/crypto/contentKey.d.ts +34 -0
  21. package/dist/core/crypto/contentKey.js +64 -0
  22. package/dist/core/crypto/decryptVerify.d.ts +7 -1
  23. package/dist/core/crypto/decryptVerify.js +23 -5
  24. package/dist/core/crypto/decrypter-interface.d.ts +6 -0
  25. package/dist/core/crypto/index.d.ts +28 -3
  26. package/dist/core/crypto/index.js +34 -20
  27. package/dist/core/crypto/keyResolver.d.ts +48 -0
  28. package/dist/core/crypto/keyResolver.js +46 -0
  29. package/dist/core/crypto/pem-decrypter.d.ts +2 -0
  30. package/dist/core/crypto/pem-decrypter.js +13 -8
  31. package/dist/core/crypto/signEncrypt.d.ts +4 -1
  32. package/dist/core/crypto/signEncrypt.js +20 -5
  33. package/dist/core/crypto/types.d.ts +8 -1
  34. package/dist/core/delegation/BtpsDelegator.d.ts +4 -0
  35. package/dist/core/delegation/BtpsDelegator.js +3 -2
  36. package/dist/core/delegation/verifyTransporterSignature.d.ts +104 -0
  37. package/dist/core/delegation/verifyTransporterSignature.js +224 -0
  38. package/dist/core/error/constant.d.ts +41 -0
  39. package/dist/core/error/constant.js +60 -0
  40. package/dist/core/server/constants/btps-protocol.d.ts +21 -5
  41. package/dist/core/server/constants/btps-protocol.js +46 -8
  42. package/dist/core/server/constants/index.d.ts +7 -3
  43. package/dist/core/server/constants/index.js +19 -4
  44. package/dist/core/server/constants/limits.d.ts +41 -1
  45. package/dist/core/server/constants/limits.js +45 -2
  46. package/dist/core/server/constants/permissions.d.ts +38 -0
  47. package/dist/core/server/constants/permissions.js +38 -0
  48. package/dist/core/server/schemas/artifacts/agentSchema.js +2 -1
  49. package/dist/core/server/schemas/artifacts/artifacts.js +7 -1
  50. package/dist/core/server/schemas/artifacts/controlSchema.js +1 -1
  51. package/dist/core/server/schemas/artifacts/identityLookupSchema.js +10 -1
  52. package/dist/core/server/schemas/artifacts/transporterSchema.js +92 -12
  53. package/dist/core/server/schemas/bounded.js +41 -0
  54. package/dist/core/server/schemas/btpsDocsSchema.d.ts +34522 -1421
  55. package/dist/core/server/schemas/btpsDocsSchema.js +355 -68
  56. package/dist/core/server/schemas/helpers.d.ts +9580 -0
  57. package/dist/core/server/schemas/helpers.js +76 -12
  58. package/dist/core/server/schemas/keyChainSchema.js +53 -0
  59. package/dist/core/server/schemas/responseSchema.js +88 -12
  60. package/dist/core/server/schemas/schema.js +6 -2
  61. package/dist/core/server/schemas/trustValues.d.ts +105 -0
  62. package/dist/core/server/schemas/trustValues.js +117 -0
  63. package/dist/core/server/types.d.ts +104 -6
  64. package/dist/core/storage/AbstractIdentityStore.d.ts +9 -0
  65. package/dist/core/storage/JsonIdentityStore.d.ts +3 -0
  66. package/dist/core/storage/JsonIdentityStore.js +3 -0
  67. package/dist/core/storage/types.d.ts +2 -0
  68. package/dist/core/trust/agreements.d.ts +107 -0
  69. package/dist/core/trust/agreements.js +116 -0
  70. package/dist/core/trust/evidence.d.ts +220 -0
  71. package/dist/core/trust/evidence.js +334 -0
  72. package/dist/core/trust/index.d.ts +10 -0
  73. package/dist/core/trust/index.js +14 -1
  74. package/dist/core/trust/keyRotation.d.ts +148 -0
  75. package/dist/core/trust/keyRotation.js +267 -0
  76. package/dist/core/trust/permissions.d.ts +114 -0
  77. package/dist/core/trust/permissions.js +115 -0
  78. package/dist/core/trust/shaping.d.ts +42 -0
  79. package/dist/core/trust/shaping.js +47 -0
  80. package/dist/core/trust/storage/AbstractTrustStore.d.ts +2 -1
  81. package/dist/core/trust/storage/JsonTrustStore.d.ts +3 -2
  82. package/dist/core/trust/timestamps.d.ts +49 -0
  83. package/dist/core/trust/timestamps.js +78 -0
  84. package/dist/core/trust/trustUtils.d.ts +13 -2
  85. package/dist/core/trust/trustUtils.js +28 -3
  86. package/dist/core/trust/types.d.ts +302 -2
  87. package/dist/core/trust/verification.d.ts +52 -0
  88. package/dist/core/trust/verification.js +55 -0
  89. package/dist/server/btpsServer.d.ts +72 -6
  90. package/dist/server/btpsServer.js +280 -157
  91. package/dist/server/index.d.ts +3 -0
  92. package/dist/server/index.js +17 -1
  93. package/dist/server/libs/agreementOrderCheck.d.ts +29 -0
  94. package/dist/server/libs/agreementOrderCheck.js +29 -0
  95. package/dist/server/libs/artifactTimeWindow.d.ts +2 -2
  96. package/dist/server/libs/artifactTimeWindow.js +2 -1
  97. package/dist/server/libs/detailsRequestLimit.d.ts +27 -0
  98. package/dist/server/libs/detailsRequestLimit.js +28 -0
  99. package/dist/server/libs/detailsResponseCheck.d.ts +27 -0
  100. package/dist/server/libs/detailsResponseCheck.js +27 -0
  101. package/dist/server/libs/eventChainCheck.d.ts +31 -0
  102. package/dist/server/libs/eventChainCheck.js +39 -0
  103. package/dist/server/libs/inFlightLimit.d.ts +10 -0
  104. package/dist/server/libs/inFlightLimit.js +7 -1
  105. package/dist/server/libs/index.d.ts +5 -0
  106. package/dist/server/libs/index.js +10 -0
  107. package/dist/server/libs/keyChains.d.ts +14 -0
  108. package/dist/server/libs/keyChains.js +17 -0
  109. package/dist/server/libs/wrapForAgent.d.ts +20 -0
  110. package/dist/server/libs/wrapForAgent.js +36 -0
  111. package/dist/server/types.d.ts +95 -9
  112. package/package.json +12 -3
@@ -48,6 +48,14 @@ const BTP_ERROR_SOCKET_CLOSED = {
48
48
  code: "BTP_ERROR_EVENT_UNRELATED",
49
49
  message: "Event does not relate to an artifact exchanged between its parties",
50
50
  status: 400
51
+ }, BTP_ERROR_EVENT_CHAIN = {
52
+ code: "BTP_ERROR_EVENT_CHAIN",
53
+ message: "Event names an earlier event it cannot follow or withdraw",
54
+ status: 400
55
+ }, BTP_ERROR_AGREEMENT_ORDER = {
56
+ code: "BTP_ERROR_AGREEMENT_ORDER",
57
+ message: "Answer is not its sender's turn",
58
+ status: 400
51
59
  }, BTP_ERROR_RESOLVE_DNS = {
52
60
  code: "BTP_ERROR_RESOLVE_DNS",
53
61
  message: "No valid DNS record found"
@@ -110,10 +118,46 @@ const BTP_ERROR_SOCKET_CLOSED = {
110
118
  code: "BTP_ERROR_AGENT_ID",
111
119
  message: "An agent id names a registered device, not an identity",
112
120
  status: 403
121
+ }, BTP_ERROR_SYNC_NOT_ALLOWED = {
122
+ code: "BTP_ERROR_SYNC_NOT_ALLOWED",
123
+ message: "A sync comes only from a device of its own address, inside that device's artifact.send",
124
+ status: 403
125
+ }, BTP_ERROR_PERMISSION = {
126
+ code: "BTP_ERROR_PERMISSION",
127
+ message: "This trust does not permit it",
128
+ status: 403
129
+ }, BTP_ERROR_PERMISSION_REQUIRED = {
130
+ code: "BTP_ERROR_PERMISSION_REQUIRED",
131
+ message: "The answer does not grant every permission the request requires",
132
+ status: 403
133
+ }, BTP_ERROR_DOCUMENT_TYPE_MISMATCH = {
134
+ code: "BTP_ERROR_DOCUMENT_TYPE_MISMATCH",
135
+ message: "The document is not the type its envelope names",
136
+ status: 400
137
+ }, BTP_ERROR_DETAILS_NOT_HELD = {
138
+ code: "BTP_ERROR_DETAILS_NOT_HELD",
139
+ message: "That detail is not held by this trust",
140
+ status: 403
141
+ }, BTP_ERROR_DETAILS_RATE_LIMITED = {
142
+ code: "BTP_ERROR_DETAILS_RATE_LIMITED",
143
+ message: "Too many details requests on this trust. Ask again later",
144
+ status: 429
113
145
  }, BTP_ERROR_KEY_ROTATION_PROOF = {
114
146
  code: "BTP_ERROR_KEY_ROTATION_PROOF",
115
147
  message: "A new device key needs a proof signed by that key",
116
148
  status: 401
149
+ }, BTP_ERROR_KEY_TOO_OLD = {
150
+ code: "BTP_ERROR_KEY_TOO_OLD",
151
+ message: "This device key is older than the server allows. Move to a new key first",
152
+ status: 401
153
+ }, BTP_ERROR_KEY_RETIRED = {
154
+ code: "BTP_ERROR_KEY_RETIRED",
155
+ message: "The key that signed this is retired. Sign with the current key",
156
+ status: 401
157
+ }, BTP_ERROR_KEY_REVOKED = {
158
+ code: "BTP_ERROR_KEY_REVOKED",
159
+ message: "The key that signed this is revoked: it may be in other hands",
160
+ status: 401
117
161
  }, BTP_ERROR_ARTIFACT_TIME_WINDOW = {
118
162
  code: "BTP_ERROR_ARTIFACT_TIME_WINDOW",
119
163
  message: "Artifact was not issued within the time window of this server",
@@ -134,6 +178,10 @@ const BTP_ERROR_SOCKET_CLOSED = {
134
178
  code: "BTP_ERROR_ARTIFACT_NOT_ACCEPTED",
135
179
  message: "This server does not accept this kind of artifact",
136
180
  status: 503
181
+ }, BTP_ERROR_TEMPORARILY_UNAVAILABLE = {
182
+ code: "BTP_ERROR_TEMPORARILY_UNAVAILABLE",
183
+ message: "The server cannot take this artifact right now. Send it again later",
184
+ status: 503
137
185
  }, BTP_ERROR_SOCKET_TIMEOUT = {
138
186
  code: "BTP_ERROR_SOCKET_TIMEOUT",
139
187
  message: "Socket timeout. Connection closed",
@@ -155,6 +203,7 @@ const BTP_ERROR_SOCKET_CLOSED = {
155
203
  export {
156
204
  BTPS_ERROR_ACTION_TYPE,
157
205
  BTP_ERROR_AGENT_ID,
206
+ BTP_ERROR_AGREEMENT_ORDER,
158
207
  BTP_ERROR_ARTIFACT_NOT_ACCEPTED,
159
208
  BTP_ERROR_ARTIFACT_TIME_WINDOW,
160
209
  BTP_ERROR_ARTIFACT_TOO_LARGE,
@@ -166,12 +215,21 @@ export {
166
215
  BTP_ERROR_DECRYPTION_UNINTENDED,
167
216
  BTP_ERROR_DELEGATION_INVALID,
168
217
  BTP_ERROR_DELEGATION_SIG_VERIFICATION,
218
+ BTP_ERROR_DETAILS_NOT_HELD,
219
+ BTP_ERROR_DETAILS_RATE_LIMITED,
220
+ BTP_ERROR_DOCUMENT_TYPE_MISMATCH,
221
+ BTP_ERROR_EVENT_CHAIN,
169
222
  BTP_ERROR_EVENT_UNRELATED,
170
223
  BTP_ERROR_IDENTITY,
171
224
  BTP_ERROR_IDENTITY_NOT_FOUND,
172
225
  BTP_ERROR_INVALID_ACTION,
173
226
  BTP_ERROR_INVALID_JSON,
227
+ BTP_ERROR_KEY_RETIRED,
228
+ BTP_ERROR_KEY_REVOKED,
174
229
  BTP_ERROR_KEY_ROTATION_PROOF,
230
+ BTP_ERROR_KEY_TOO_OLD,
231
+ BTP_ERROR_PERMISSION,
232
+ BTP_ERROR_PERMISSION_REQUIRED,
175
233
  BTP_ERROR_PRIVACY_TYPE,
176
234
  BTP_ERROR_RATE_LIMITER,
177
235
  BTP_ERROR_RESOLVE_DNS,
@@ -180,6 +238,8 @@ export {
180
238
  BTP_ERROR_SIG_VERIFICATION,
181
239
  BTP_ERROR_SOCKET_CLOSED,
182
240
  BTP_ERROR_SOCKET_TIMEOUT,
241
+ BTP_ERROR_SYNC_NOT_ALLOWED,
242
+ BTP_ERROR_TEMPORARILY_UNAVAILABLE,
183
243
  BTP_ERROR_TIMEOUT,
184
244
  BTP_ERROR_TRUST_ALREADY_ACTIVE,
185
245
  BTP_ERROR_TRUST_BLOCKED,
@@ -4,14 +4,30 @@
4
4
  * Licensed under the Apache License, Version 2.0
5
5
  * https://www.apache.org/licenses/LICENSE-2.0
6
6
  */
7
- export declare const BTP_PROTOCOL_VERSION = "1.1.0";
7
+ export declare const BTP_PROTOCOL_VERSION = "1.2.0";
8
8
  export declare const MIN_SUPPORTED_VERSION = "1.1.0";
9
- export declare const MAX_SUPPORTED_VERSION = "1.1.0";
9
+ export declare const MAX_SUPPORTED_VERSION = "1.2.0";
10
+ /** How far a server lets an artifact's `issuedAt` be from its own clock unless it sets `maxArtifactAgeSeconds`: 5 minutes. */
11
+ export declare const DEFAULT_MAX_ARTIFACT_AGE_SECONDS = 300;
10
12
  /**
11
- * Whether an artifact's `version` is one this SDK speaks. Compared by major and
12
- * minor only, so a later 1.1.x is still 1.1. 1.1 refuses 1.0: no independent
13
- * provider runs 1.0, so the break costs nothing now.
13
+ * Whether an artifact's `version` is one this SDK speaks: 1.1 and 1.2. It
14
+ * refuses 1.0: no independent provider runs 1.0, so the break costs nothing.
14
15
  */
15
16
  export declare const isSupportedVersion: (version: unknown) => boolean;
17
+ /** Whether `version` is older than `than`, by major and minor. One that is not a version is older. */
18
+ export declare const isVersionBelow: (version: string, than: string) => boolean;
19
+ /** An artifact before it is signed: its type, its document, and the rest of its envelope. */
20
+ export type BTPVersionedArtifact = {
21
+ type?: string;
22
+ document?: unknown;
23
+ [key: string]: unknown;
24
+ };
25
+ /**
26
+ * The version an artifact is stamped with: 1.1.0 whenever everything in it can
27
+ * be said in 1.1, so a 1.1 receiver takes it, and 1.2.0 only when it uses
28
+ * something 1.2 adds. An encrypted artifact is stamped from its document before
29
+ * it is encrypted.
30
+ */
31
+ export declare const artifactVersion: (artifact: BTPVersionedArtifact) => string;
16
32
  export declare const BTPS_DNS_HOST_NAME_SPACE = "_btps.host";
17
33
  export declare const BTPS_DNS_IDENTITY_NAME_SPACE = "_btps.identity";
@@ -5,21 +5,59 @@
5
5
  * https://www.apache.org/licenses/LICENSE-2.0
6
6
  */
7
7
 
8
- const BTP_PROTOCOL_VERSION = "1.1.0", MIN_SUPPORTED_VERSION = "1.1.0", MAX_SUPPORTED_VERSION = "1.1.0", majorMinor = (version) => {
8
+ import { DETAILS_ARTIFACT_TYPES, PERMISSION_ENVELOPE_FIELDS } from "./permissions.js";
9
+ const BTP_PROTOCOL_VERSION = "1.2.0", MIN_SUPPORTED_VERSION = "1.1.0", MAX_SUPPORTED_VERSION = "1.2.0", DEFAULT_MAX_ARTIFACT_AGE_SECONDS = 300, rank = (version) => {
9
10
  const match = /^(\d+)\.(\d+)(?:\.\d+)?$/.exec(version);
10
- return match ? [Number(match[1]), Number(match[2])] : void 0;
11
+ return match ? Number(match[1]) * 1e3 + Number(match[2]) : void 0;
11
12
  }, isSupportedVersion = (version) => {
12
13
  if (typeof version != "string") return !1;
13
- const given = majorMinor(version), min = majorMinor(MIN_SUPPORTED_VERSION), max = majorMinor(MAX_SUPPORTED_VERSION);
14
- if (!given || !min || !max) return !1;
15
- const rank = ([major, minor]) => major * 1e3 + minor;
16
- return rank(given) >= rank(min) && rank(given) <= rank(max);
17
- }, BTPS_DNS_HOST_NAME_SPACE = "_btps.host", BTPS_DNS_IDENTITY_NAME_SPACE = "_btps.identity";
14
+ const given = rank(version), min = rank(MIN_SUPPORTED_VERSION), max = rank(MAX_SUPPORTED_VERSION);
15
+ return given === void 0 || min === void 0 || max === void 0 ? !1 : given >= min && given <= max;
16
+ }, isVersionBelow = (version, than) => {
17
+ const given = rank(version), needed = rank(than);
18
+ return given === void 0 || needed !== void 0 && given < needed;
19
+ }, documentOf = (artifact) => typeof artifact.document == "object" && artifact.document !== null ? artifact.document : void 0, USES_1_2 = [
20
+
21
+ (artifact) => {
22
+ const event = documentOf(artifact);
23
+ return artifact.type === "BTPS_EVENT" && event !== void 0 && (event.eventType === "withdrawn" || event.follows !== void 0);
24
+ },
25
+
26
+ (artifact) => artifact.syncOf !== void 0,
27
+
28
+ (artifact) => documentOf(artifact)?.type === "agreement_event",
29
+
30
+ (artifact) => {
31
+ const document = documentOf(artifact), isNote = (value) => typeof value == "object" && value !== null;
32
+ return document !== void 0 && (isNote(document.description) || isNote(document.message));
33
+ },
34
+
35
+ (artifact) => documentOf(artifact)?.discount !== void 0,
36
+
37
+ (artifact) => documentOf(artifact)?.type === "agreement",
38
+
39
+ (artifact) => {
40
+ const document = documentOf(artifact);
41
+ return (document?.type === "letter" || document?.type === "payslip") && document.template !== void 0;
42
+ },
43
+
44
+ (artifact) => Object.keys(PERMISSION_ENVELOPE_FIELDS).some((field) => artifact[field] !== void 0),
45
+
46
+ (artifact) => {
47
+ const document = documentOf(artifact);
48
+ return artifact.type === "TRUST_REQ" && (document?.own !== void 0 || document?.verification !== void 0) || artifact.type === "TRUST_RES" && document?.details !== void 0;
49
+ },
50
+
51
+ (artifact) => DETAILS_ARTIFACT_TYPES.includes(artifact.type)
52
+ ], artifactVersion = (artifact) => USES_1_2.some((uses) => uses(artifact)) ? "1.2.0" : MIN_SUPPORTED_VERSION, BTPS_DNS_HOST_NAME_SPACE = "_btps.host", BTPS_DNS_IDENTITY_NAME_SPACE = "_btps.identity";
18
53
  export {
19
54
  BTPS_DNS_HOST_NAME_SPACE,
20
55
  BTPS_DNS_IDENTITY_NAME_SPACE,
21
56
  BTP_PROTOCOL_VERSION,
57
+ DEFAULT_MAX_ARTIFACT_AGE_SECONDS,
22
58
  MAX_SUPPORTED_VERSION,
23
59
  MIN_SUPPORTED_VERSION,
24
- isSupportedVersion
60
+ artifactVersion,
61
+ isSupportedVersion,
62
+ isVersionBelow
25
63
  };
@@ -8,9 +8,10 @@ export * from './btps-protocol.js';
8
8
  export * from './control.js';
9
9
  export * from './currency.js';
10
10
  export * from './limits.js';
11
+ export * from './permissions.js';
11
12
  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"];
13
+ 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", "details.changed", "details.request", "details.respond"];
14
+ export declare const TRANSPORTER_ACTIONS: readonly ["TRUST_REQ", "TRUST_RES", "BTPS_DOC", "BTPS_EVENT", "DETAILS_CHANGED", "DETAILS_REQ", "DETAILS_RES"];
14
15
  /**
15
16
  * Agent actions that carry a transporter artifact, built by the device, and its
16
17
  * type. trust.update and trust.delete are not among them: they edit the user's
@@ -21,6 +22,9 @@ export declare const AGENT_TRANSPORTER_ACTIONS: {
21
22
  readonly 'trust.respond': "TRUST_RES";
22
23
  readonly 'artifact.send': "BTPS_DOC";
23
24
  readonly 'event.send': "BTPS_EVENT";
25
+ readonly 'details.changed': "DETAILS_CHANGED";
26
+ readonly 'details.request': "DETAILS_REQ";
27
+ readonly 'details.respond': "DETAILS_RES";
24
28
  };
25
29
  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"];
30
+ export declare const AGENT_ACTIONS_REQUIRING_DOCUMENT: readonly ["trust.request", "trust.respond", "trust.update", "trust.delete", "artifact.send", "event.send", "details.changed", "details.request", "details.respond", "auth.request", "auth.refresh", "inbox.seen", "inbox.delete", "sentbox.delete", "outbox.cancel", "draft.create", "draft.update", "draft.delete", "trash.delete"];
@@ -9,7 +9,8 @@ export * from "./btps-protocol.js";
9
9
  export * from "./control.js";
10
10
  export * from "./currency.js";
11
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 = [
12
+ export * from "./permissions.js";
13
+ 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"], DETAILS_ACTIONS = ["details.changed", "details.request", "details.respond"], AGENT_ACTIONS = [
13
14
  ...TRUST_ACTIONS,
14
15
  ...TRUST_IMMEDIATE_ACTIONS,
15
16
  ...INBOX_ACTIONS,
@@ -20,12 +21,25 @@ const TRUST_ACTIONS = ["trust.request", "trust.respond"], TRUST_IMMEDIATE_ACTION
20
21
  ...AUTH_ACTIONS,
21
22
  ...ARTIFACT_ACTIONS,
22
23
  ...EVENT_ACTIONS,
23
- ...TRASH_ACTIONS
24
- ], TRANSPORTER_ACTIONS = ["TRUST_REQ", "TRUST_RES", "BTPS_DOC", "BTPS_EVENT"], AGENT_TRANSPORTER_ACTIONS = {
24
+ ...TRASH_ACTIONS,
25
+ ...DETAILS_ACTIONS
26
+ ], TRANSPORTER_ACTIONS = [
27
+ "TRUST_REQ",
28
+ "TRUST_RES",
29
+ "BTPS_DOC",
30
+ "BTPS_EVENT",
31
+
32
+ "DETAILS_CHANGED",
33
+ "DETAILS_REQ",
34
+ "DETAILS_RES"
35
+ ], AGENT_TRANSPORTER_ACTIONS = {
25
36
  "trust.request": "TRUST_REQ",
26
37
  "trust.respond": "TRUST_RES",
27
38
  "artifact.send": "BTPS_DOC",
28
- "event.send": "BTPS_EVENT"
39
+ "event.send": "BTPS_EVENT",
40
+ "details.changed": "DETAILS_CHANGED",
41
+ "details.request": "DETAILS_REQ",
42
+ "details.respond": "DETAILS_RES"
29
43
  }, IMMEDIATE_ACTIONS = [
30
44
  ...SYSTEM_ACTIONS,
31
45
  ...AUTH_ACTIONS,
@@ -41,6 +55,7 @@ const TRUST_ACTIONS = ["trust.request", "trust.respond"], TRUST_IMMEDIATE_ACTION
41
55
  "trust.delete",
42
56
  ...ARTIFACT_ACTIONS,
43
57
  ...EVENT_ACTIONS,
58
+ ...DETAILS_ACTIONS,
44
59
  ...AUTH_ACTIONS,
45
60
  "inbox.seen",
46
61
  "inbox.delete",
@@ -5,7 +5,8 @@
5
5
  * https://www.apache.org/licenses/LICENSE-2.0
6
6
  */
7
7
  /**
8
- * The longest each field may be, in characters. The protocol fixes these,
8
+ * The longest each field may be: a text in characters, a list in entries, a
9
+ * record in keys. The protocol fixes these,
9
10
  * so every provider accepts the same documents: a provider may be stricter
10
11
  * in its own middleware, but cannot raise them. They are raised only by a
11
12
  * protocol version.
@@ -38,6 +39,10 @@ export declare const BTPS_FIELD_LIMITS: {
38
39
  };
39
40
  readonly payslip: {
40
41
  readonly code: 64;
42
+ readonly earnings: 200;
43
+ readonly deductions: 200;
44
+ readonly contributions: 200;
45
+ readonly leave: 200;
41
46
  };
42
47
  readonly letter: {
43
48
  readonly title: 200;
@@ -45,6 +50,41 @@ export declare const BTPS_FIELD_LIMITS: {
45
50
  readonly attachments: 10;
46
51
  readonly references: 20;
47
52
  };
53
+ readonly agreement: {
54
+ readonly signers: 20;
55
+ };
56
+ readonly keyChain: {
57
+ readonly records: 100;
58
+ readonly publicKey: 2048;
59
+ };
60
+ readonly attachments: 10;
61
+ readonly references: 20;
62
+ readonly lineItems: {
63
+ readonly rows: 10000;
64
+ readonly columns: 50;
65
+ };
66
+ readonly query: {
67
+ readonly in: 1000;
68
+ readonly notIn: 1000;
69
+ readonly results: 1000;
70
+ };
71
+ readonly ids: 1000;
72
+ readonly agentInfoValues: 50;
73
+ readonly trustRecord: {
74
+ readonly keyHistory: 1000;
75
+ };
76
+ readonly recordKeys: 100;
48
77
  readonly documentId: 100;
49
78
  readonly referenceType: 64;
79
+ readonly note: 5000;
80
+ readonly url: 2048;
81
+ readonly signature: {
82
+ readonly text: 100;
83
+ readonly strokes: 32;
84
+ readonly strokePoints: 512;
85
+ readonly points: 2048;
86
+ readonly width: 1000;
87
+ readonly height: 300;
88
+ };
89
+ readonly detailNumber: 64;
50
90
  };
@@ -33,7 +33,11 @@ const BTPS_FIELD_LIMITS = {
33
33
  },
34
34
  payslip: {
35
35
 
36
- code: 64
36
+ code: 64,
37
+ earnings: 200,
38
+ deductions: 200,
39
+ contributions: 200,
40
+ leave: 200
37
41
  },
38
42
  letter: {
39
43
  title: 200,
@@ -42,8 +46,47 @@ const BTPS_FIELD_LIMITS = {
42
46
  references: 20
43
47
  },
44
48
 
49
+ agreement: {
50
+ signers: 20
51
+ },
52
+
53
+ keyChain: {
54
+ records: 100,
55
+ publicKey: 2048
56
+ },
57
+
58
+ attachments: 10,
59
+ references: 20,
60
+
61
+ lineItems: {
62
+ rows: 1e4,
63
+ columns: 50
64
+ },
65
+ query: {
66
+ in: 1e3,
67
+ notIn: 1e3,
68
+ results: 1e3
69
+ },
70
+
71
+ ids: 1e3,
72
+ agentInfoValues: 50,
73
+ trustRecord: {
74
+ keyHistory: 1e3
75
+ },
76
+
77
+ recordKeys: 100,
78
+
45
79
  documentId: 100,
46
- referenceType: 64
80
+ referenceType: 64,
81
+
82
+ note: 5e3,
83
+
84
+ url: 2048,
85
+
86
+
87
+ signature: { text: 100, strokes: 32, strokePoints: 512, points: 2048, width: 1e3, height: 300 },
88
+
89
+ detailNumber: 64
47
90
  };
48
91
  export {
49
92
  BTPS_FIELD_LIMITS
@@ -0,0 +1,38 @@
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
+ * Since 1.2: the document types a `BTPS_DOC` carries. Each names a `send:`
9
+ * permission and a `documentType`, so a new type is added here, with its schema.
10
+ */
11
+ export declare const DOCUMENT_TYPES: readonly ["invoice", "receipt", "payslip", "letter", "agreement"];
12
+ /** Since 1.2: the details a trust may ask for, each a `detail:` permission. */
13
+ export declare const DETAIL_TYPES: readonly ["legalName", "profile", "email", "phone", "address", "taxNo", "dob", "registrationNumber"];
14
+ /** Since 1.2: what owns a BTPS address. */
15
+ export declare const ENTITY_TYPES: readonly ["person", "organisation"];
16
+ export declare const SEND_PERMISSIONS: ("send:payslip" | "send:letter" | "send:agreement" | "send:invoice" | "send:receipt")[];
17
+ export declare const DETAIL_PERMISSIONS: ("detail:legalName" | "detail:profile" | "detail:email" | "detail:phone" | "detail:address" | "detail:taxNo" | "detail:dob" | "detail:registrationNumber")[];
18
+ /** Since 1.2: details refresh: a notice that details changed, a request for some, and its answer. */
19
+ export declare const DETAILS_ARTIFACT_TYPES: readonly ["DETAILS_CHANGED", "DETAILS_REQ", "DETAILS_RES"];
20
+ /** Since 1.2: the envelope fields of trust permissions, and the artifact types each is on. */
21
+ export declare const PERMISSION_ENVELOPE_FIELDS: {
22
+ readonly permissions: readonly ["TRUST_REQ"];
23
+ readonly entityType: readonly ["TRUST_REQ", "TRUST_RES"];
24
+ readonly given: readonly ["TRUST_REQ"];
25
+ readonly change: readonly ["TRUST_REQ"];
26
+ readonly granted: readonly ["TRUST_RES"];
27
+ readonly documentType: readonly ["BTPS_DOC"];
28
+ readonly details: readonly ["DETAILS_CHANGED", "DETAILS_REQ", "DETAILS_RES"];
29
+ };
30
+ /**
31
+ * The one detail each kind gives that the other never does: a person its date
32
+ * of birth, an organisation its registration number. Asking for either is met
33
+ * by giving your own.
34
+ */
35
+ export declare const IDENTITY_DETAIL: {
36
+ readonly person: "detail:dob";
37
+ readonly organisation: "detail:registrationNumber";
38
+ };
@@ -0,0 +1,38 @@
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 DOCUMENT_TYPES = ["invoice", "receipt", "payslip", "letter", "agreement"], DETAIL_TYPES = [
9
+ "legalName",
10
+ "profile",
11
+ "email",
12
+ "phone",
13
+ "address",
14
+ "taxNo",
15
+ "dob",
16
+ "registrationNumber"
17
+ ], ENTITY_TYPES = ["person", "organisation"], SEND_PERMISSIONS = DOCUMENT_TYPES.map((type) => `send:${type}`), DETAIL_PERMISSIONS = DETAIL_TYPES.map((type) => `detail:${type}`), DETAILS_ARTIFACT_TYPES = ["DETAILS_CHANGED", "DETAILS_REQ", "DETAILS_RES"], PERMISSION_ENVELOPE_FIELDS = {
18
+ permissions: ["TRUST_REQ"],
19
+ entityType: ["TRUST_REQ", "TRUST_RES"],
20
+ given: ["TRUST_REQ"],
21
+ change: ["TRUST_REQ"],
22
+ granted: ["TRUST_RES"],
23
+ documentType: ["BTPS_DOC"],
24
+ details: DETAILS_ARTIFACT_TYPES
25
+ }, IDENTITY_DETAIL = {
26
+ person: "detail:dob",
27
+ organisation: "detail:registrationNumber"
28
+ };
29
+ export {
30
+ DETAILS_ARTIFACT_TYPES,
31
+ DETAIL_PERMISSIONS,
32
+ DETAIL_TYPES,
33
+ DOCUMENT_TYPES,
34
+ ENTITY_TYPES,
35
+ IDENTITY_DETAIL,
36
+ PERMISSION_ENVELOPE_FIELDS,
37
+ SEND_PERMISSIONS
38
+ };
@@ -44,7 +44,8 @@ const BtpAgentArtifactSchema = z.object({
44
44
  if (!(action in AGENT_TRANSPORTER_ACTIONS))
45
45
  return validateAgentDocument(action, encryption, document);
46
46
  const carried = BtpTransporterArtifactSchema.safeParse(document);
47
- return carried.success && carried.data.type === AGENT_TRANSPORTER_ACTIONS[action];
47
+ return carried.success && carried.data.type === AGENT_TRANSPORTER_ACTIONS[action] &&
48
+ (carried.data.syncOf === void 0 || action === "artifact.send");
48
49
  };
49
50
  export {
50
51
  BtpAgentArtifactSchema
@@ -10,12 +10,18 @@ import { BtpAgentArtifactSchema } from "./agentSchema.js";
10
10
  import { BtpTransporterArtifactSchema } from "./transporterSchema.js";
11
11
  import { BtpControlArtifactSchema } from "./controlSchema.js";
12
12
  import { BtpIdentityLookupRequestSchema } from "./identityLookupSchema.js";
13
- const BtpArtifactServerSchema = z.union([
13
+ const BtpArtifactSchemaByType = {
14
+ agent: BtpAgentArtifactSchema,
15
+ transporter: BtpTransporterArtifactSchema,
16
+ control: BtpControlArtifactSchema,
17
+ identityLookup: BtpIdentityLookupRequestSchema
18
+ }, BtpArtifactServerSchema = z.union([
14
19
  BtpAgentArtifactSchema,
15
20
  BtpTransporterArtifactSchema,
16
21
  BtpControlArtifactSchema,
17
22
  BtpIdentityLookupRequestSchema
18
23
  ]);
19
24
  export {
25
+ BtpArtifactSchemaByType,
20
26
  BtpArtifactServerSchema
21
27
  };
@@ -12,7 +12,7 @@ const BtpControlArtifactSchema = z.object({
12
12
  id: z.string(),
13
13
  issuedAt: z.string().datetime(),
14
14
  action: z.enum(CONTROL_ACTIONS)
15
- });
15
+ }).strict();
16
16
  export {
17
17
  BtpControlArtifactSchema
18
18
  };
@@ -7,6 +7,7 @@
7
7
 
8
8
  import { z } from "zod";
9
9
  import { identitySchema } from "../shared.js";
10
+ import { isVersionBelow } from "../../constants/index.js";
10
11
  const BtpIdentityLookupRequestSchema = z.object({
11
12
  version: z.string(),
12
13
  id: z.string(),
@@ -14,7 +15,15 @@ const BtpIdentityLookupRequestSchema = z.object({
14
15
  identity: identitySchema,
15
16
  from: identitySchema,
16
17
  hostSelector: z.string(),
17
- identitySelector: z.string().optional()
18
+ identitySelector: z.string().optional(),
19
+
20
+ keyChain: z.literal(!0).optional()
21
+ }).strict().superRefine((data, ctx) => {
22
+ data.keyChain !== void 0 && isVersionBelow(data.version, "1.2.0") && ctx.addIssue({
23
+ path: ["keyChain"],
24
+ code: z.ZodIssueCode.custom,
25
+ message: "keyChain is only in a 1.2.0 lookup"
26
+ });
18
27
  });
19
28
  export {
20
29
  BtpIdentityLookupRequestSchema