@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,66 @@
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 { BTPError } from './types.js';
8
+ export declare const BTP_ERROR_SOCKET_CLOSED: BTPError;
9
+ export declare const BTP_ERROR_IDENTITY: BTPError;
10
+ export declare const BTP_ERROR_IDENTITY_NOT_FOUND: BTPError;
11
+ export declare const BTP_ERROR_TRUST_NON_EXISTENT: BTPError;
12
+ export declare const BTPS_ERROR_ACTION_TYPE: BTPError;
13
+ export declare const BTP_ERROR_TRUST_BLOCKED: BTPError;
14
+ export declare const BTP_ERROR_TRUST_NOT_ALLOWED: BTPError;
15
+ /**
16
+ * An expired trust record gets its own distinct response `message` on the
17
+ * wire, separate from BTP_ERROR_TRUST_NOT_ALLOWED. This distinction lives
18
+ * only in the response body text - sendBtpsError's `typeof error.code ===
19
+ * 'number' ? error.code : 500` fallback means the numeric `status.code` is
20
+ * 500 for this and every other application error today.
21
+ */
22
+ export declare const BTP_ERROR_TRUST_EXPIRED: BTPError;
23
+ /**
24
+ * The precise, server-side-only reason for a revoked trust record.
25
+ * On the wire this collapses onto BTP_ERROR_TRUST_NOT_ALLOWED -
26
+ * same response `message`, same `status.code` - so a revoked sender cannot
27
+ * distinguish their refusal from a never-trusted one.
28
+ */
29
+ export declare const BTP_ERROR_TRUST_REVOKED: BTPError;
30
+ export declare const BTP_ERROR_TRUST_ALREADY_ACTIVE: BTPError;
31
+ export declare const BTP_ERROR_EVENT_UNRELATED: BTPError;
32
+ export declare const BTP_ERROR_RESOLVE_DNS: BTPError;
33
+ export declare const BTP_ERROR_RESOLVE_PUBKEY: BTPError;
34
+ export declare const BTP_ERROR_RATE_LIMITER: BTPError;
35
+ export declare const BTP_ERROR_INVALID_ACTION: BTPError;
36
+ export declare const BTP_ERROR_INVALID_JSON: {
37
+ code: string;
38
+ message: string;
39
+ status: number;
40
+ };
41
+ export declare const BTP_ERROR_VALIDATION: {
42
+ code: string;
43
+ message: string;
44
+ status: number;
45
+ };
46
+ export declare const BTP_ERROR_SIG_MISMATCH: BTPError;
47
+ export declare const BTP_ERROR_SIG_VERIFICATION: BTPError;
48
+ export declare const BTP_ERROR_CANONICAL_JSON: BTPError;
49
+ export declare const BTP_ERROR_DELEGATION_SIG_VERIFICATION: BTPError;
50
+ export declare const BTP_ERROR_ATTESTATION_VERIFICATION: BTPError;
51
+ export declare const BTP_ERROR_DELEGATION_INVALID: BTPError;
52
+ export declare const BTP_ERROR_UNSUPPORTED_ENCRYPT: BTPError;
53
+ export declare const BTP_ERROR_DECRYPTION_UNINTENDED: BTPError;
54
+ export declare const BTP_ERROR_UNKNOWN: BTPError;
55
+ export declare const BTP_ERROR_AGENT_ID: BTPError;
56
+ export declare const BTP_ERROR_KEY_ROTATION_PROOF: BTPError;
57
+ export declare const BTP_ERROR_ARTIFACT_TIME_WINDOW: BTPError;
58
+ export declare const BTP_ERROR_ARTIFACT_TOO_LARGE: BTPError;
59
+ export declare const BTP_ERROR_VERSION_UNSUPPORTED: BTPError;
60
+ export declare const BTP_ERROR_PRIVACY_TYPE: BTPError;
61
+ export declare const BTP_ERROR_ARTIFACT_NOT_ACCEPTED: BTPError;
62
+ export declare const BTP_ERROR_SOCKET_TIMEOUT: BTPError;
63
+ export declare const BTP_ERROR_AUTHENTICATION_INVALID: BTPError;
64
+ export declare const BTP_ERROR_TIMEOUT: BTPError;
65
+ export declare const BTP_ERROR_CONNECTION_CLOSED: BTPError;
66
+ export declare const BTP_ERROR_CONNECTION_ENDED: BTPError;
@@ -0,0 +1,194 @@
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 BTP_ERROR_SOCKET_CLOSED = {
9
+ code: "BTP_ERROR_SOCKET_CLOSED",
10
+ message: "Socket already closed"
11
+ }, BTP_ERROR_IDENTITY = {
12
+ code: "BTP_ERROR_IDENTITY",
13
+ message: "BTPS identity is expected in the format username$domain.",
14
+ status: 400
15
+ }, BTP_ERROR_IDENTITY_NOT_FOUND = {
16
+ code: "BTP_ERROR_IDENTITY_NOT_FOUND",
17
+ message: "Identity not found",
18
+ status: 404
19
+ }, BTP_ERROR_TRUST_NON_EXISTENT = {
20
+ code: "BTP_ERROR_TRUST_NON_EXISTENT",
21
+ message: "BTPS trust record does not exist",
22
+ status: 403
23
+ }, BTPS_ERROR_ACTION_TYPE = {
24
+ code: "BTPS_ERROR_ACTION_TYPE",
25
+ message: "BTPS action type is not valid",
26
+ status: 400
27
+ }, BTP_ERROR_TRUST_BLOCKED = {
28
+ code: "BTP_ERROR_TRUST_BLOCKED",
29
+ message: "BTPS trust request is not allowed. Contact receiver",
30
+ status: 403
31
+ }, BTP_ERROR_TRUST_NOT_ALLOWED = {
32
+ code: "BTP_ERROR_TRUST_NOT_ALLOWED",
33
+ message: "BTPS trust request is not allowed at this time. Contact receiver",
34
+ status: 403
35
+ }, BTP_ERROR_TRUST_EXPIRED = {
36
+ code: "BTP_ERROR_TRUST_EXPIRED",
37
+ message: "BTPS trust record has expired",
38
+ status: 403
39
+ }, BTP_ERROR_TRUST_REVOKED = {
40
+ code: "BTP_ERROR_TRUST_REVOKED",
41
+ message: "BTPS trust record has been revoked",
42
+ status: 403
43
+ }, BTP_ERROR_TRUST_ALREADY_ACTIVE = {
44
+ code: "BTP_ERROR_TRUST_ALREADY_ACTIVE",
45
+ message: "BTPS trust record already exist. Request invalid",
46
+ status: 409
47
+ }, BTP_ERROR_EVENT_UNRELATED = {
48
+ code: "BTP_ERROR_EVENT_UNRELATED",
49
+ message: "Event does not relate to an artifact exchanged between its parties",
50
+ status: 400
51
+ }, BTP_ERROR_RESOLVE_DNS = {
52
+ code: "BTP_ERROR_RESOLVE_DNS",
53
+ message: "No valid DNS record found"
54
+ }, BTP_ERROR_RESOLVE_PUBKEY = {
55
+ code: "BTP_ERROR_RESOLVE_PUBKEY",
56
+ message: "No valid public-key found",
57
+ status: 401
58
+ }, BTP_ERROR_RATE_LIMITER = {
59
+ code: "BTP_ERROR_RATE_LIMITER",
60
+ message: "Too many request than its allowed",
61
+ status: 429
62
+ }, BTP_ERROR_INVALID_ACTION = {
63
+ code: "BTP_ERROR_INVALID_ACTION",
64
+ message: "Invalid action",
65
+ status: 400
66
+ }, BTP_ERROR_INVALID_JSON = {
67
+ code: "BTP_ERROR_INVALID_JSON",
68
+ message: "Invalid JSON format",
69
+ status: 400
70
+ }, BTP_ERROR_VALIDATION = {
71
+ code: "BTP_ERROR_VALIDATION",
72
+ message: "BTPS artifact validation failed",
73
+ status: 400
74
+ }, BTP_ERROR_SIG_MISMATCH = {
75
+ code: "BTP_ERROR_SIG_MISMATCH",
76
+ message: "fingerprint mis-match",
77
+ status: 401
78
+ }, BTP_ERROR_SIG_VERIFICATION = {
79
+ code: "BTP_ERROR_SIG_VERIFICATION",
80
+ message: "Signature verification failed",
81
+ status: 401
82
+ }, BTP_ERROR_CANONICAL_JSON = {
83
+ code: "BTP_ERROR_CANONICAL_JSON",
84
+ message: "Payload cannot be canonicalized (RFC 8785)",
85
+ status: 400
86
+ }, BTP_ERROR_DELEGATION_SIG_VERIFICATION = {
87
+ code: "BTP_ERROR_DELEGATION_SIG_VERIFICATION",
88
+ message: "Delegation signature verification failed",
89
+ status: 401
90
+ }, BTP_ERROR_ATTESTATION_VERIFICATION = {
91
+ code: "BTP_ERROR_ATTESTATION_VERIFICATION",
92
+ message: "Attestation verification failed",
93
+ status: 401
94
+ }, BTP_ERROR_DELEGATION_INVALID = {
95
+ code: "BTP_ERROR_DELEGATION_INVALID",
96
+ message: "Delegation is invalid",
97
+ status: 401
98
+ }, BTP_ERROR_UNSUPPORTED_ENCRYPT = {
99
+ code: "BTP_ERROR_UNSUPPORTED_ENCRYPT",
100
+ message: "Unsupported encryption algorithm",
101
+ status: 400
102
+ }, BTP_ERROR_DECRYPTION_UNINTENDED = {
103
+ code: "BTP_ERROR_DECRYPTION_UNINTENDED",
104
+ message: "Decryption failed: Message was not intended for this receiver."
105
+ }, BTP_ERROR_UNKNOWN = {
106
+ code: "BTP_UNKNOWN_ERROR",
107
+ message: "Unknown error",
108
+ status: 500
109
+ }, BTP_ERROR_AGENT_ID = {
110
+ code: "BTP_ERROR_AGENT_ID",
111
+ message: "An agent id names a registered device, not an identity",
112
+ status: 403
113
+ }, BTP_ERROR_KEY_ROTATION_PROOF = {
114
+ code: "BTP_ERROR_KEY_ROTATION_PROOF",
115
+ message: "A new device key needs a proof signed by that key",
116
+ status: 401
117
+ }, BTP_ERROR_ARTIFACT_TIME_WINDOW = {
118
+ code: "BTP_ERROR_ARTIFACT_TIME_WINDOW",
119
+ message: "Artifact was not issued within the time window of this server",
120
+ status: 400
121
+ }, BTP_ERROR_ARTIFACT_TOO_LARGE = {
122
+ code: "BTP_ERROR_ARTIFACT_TOO_LARGE",
123
+ message: "Artifact exceeds the size limit of this server",
124
+ status: 413
125
+ }, BTP_ERROR_VERSION_UNSUPPORTED = {
126
+ code: "BTP_ERROR_VERSION_UNSUPPORTED",
127
+ message: "This server does not support the artifact protocol version",
128
+ status: 400
129
+ }, BTP_ERROR_PRIVACY_TYPE = {
130
+ code: "BTP_ERROR_PRIVACY_TYPE",
131
+ message: "Artifact does not use the encryption its trust requires",
132
+ status: 400
133
+ }, BTP_ERROR_ARTIFACT_NOT_ACCEPTED = {
134
+ code: "BTP_ERROR_ARTIFACT_NOT_ACCEPTED",
135
+ message: "This server does not accept this kind of artifact",
136
+ status: 503
137
+ }, BTP_ERROR_SOCKET_TIMEOUT = {
138
+ code: "BTP_ERROR_SOCKET_TIMEOUT",
139
+ message: "Socket timeout. Connection closed",
140
+ status: 408
141
+ }, BTP_ERROR_AUTHENTICATION_INVALID = {
142
+ code: "BTP_ERROR_AUTHENTICATION_INVALID",
143
+ message: "Authentication failed",
144
+ status: 401
145
+ }, BTP_ERROR_TIMEOUT = {
146
+ code: "BTP_ERROR_TIMEOUT",
147
+ message: "Timeout"
148
+ }, BTP_ERROR_CONNECTION_CLOSED = {
149
+ code: "BTP_ERROR_CONNECTION_CLOSED",
150
+ message: "Connection closed"
151
+ }, BTP_ERROR_CONNECTION_ENDED = {
152
+ code: "BTP_ERROR_CONNECTION_ENDED",
153
+ message: "Connection ended"
154
+ };
155
+ export {
156
+ BTPS_ERROR_ACTION_TYPE,
157
+ BTP_ERROR_AGENT_ID,
158
+ BTP_ERROR_ARTIFACT_NOT_ACCEPTED,
159
+ BTP_ERROR_ARTIFACT_TIME_WINDOW,
160
+ BTP_ERROR_ARTIFACT_TOO_LARGE,
161
+ BTP_ERROR_ATTESTATION_VERIFICATION,
162
+ BTP_ERROR_AUTHENTICATION_INVALID,
163
+ BTP_ERROR_CANONICAL_JSON,
164
+ BTP_ERROR_CONNECTION_CLOSED,
165
+ BTP_ERROR_CONNECTION_ENDED,
166
+ BTP_ERROR_DECRYPTION_UNINTENDED,
167
+ BTP_ERROR_DELEGATION_INVALID,
168
+ BTP_ERROR_DELEGATION_SIG_VERIFICATION,
169
+ BTP_ERROR_EVENT_UNRELATED,
170
+ BTP_ERROR_IDENTITY,
171
+ BTP_ERROR_IDENTITY_NOT_FOUND,
172
+ BTP_ERROR_INVALID_ACTION,
173
+ BTP_ERROR_INVALID_JSON,
174
+ BTP_ERROR_KEY_ROTATION_PROOF,
175
+ BTP_ERROR_PRIVACY_TYPE,
176
+ BTP_ERROR_RATE_LIMITER,
177
+ BTP_ERROR_RESOLVE_DNS,
178
+ BTP_ERROR_RESOLVE_PUBKEY,
179
+ BTP_ERROR_SIG_MISMATCH,
180
+ BTP_ERROR_SIG_VERIFICATION,
181
+ BTP_ERROR_SOCKET_CLOSED,
182
+ BTP_ERROR_SOCKET_TIMEOUT,
183
+ BTP_ERROR_TIMEOUT,
184
+ BTP_ERROR_TRUST_ALREADY_ACTIVE,
185
+ BTP_ERROR_TRUST_BLOCKED,
186
+ BTP_ERROR_TRUST_EXPIRED,
187
+ BTP_ERROR_TRUST_NON_EXISTENT,
188
+ BTP_ERROR_TRUST_NOT_ALLOWED,
189
+ BTP_ERROR_TRUST_REVOKED,
190
+ BTP_ERROR_UNKNOWN,
191
+ BTP_ERROR_UNSUPPORTED_ENCRYPT,
192
+ BTP_ERROR_VALIDATION,
193
+ BTP_ERROR_VERSION_UNSUPPORTED
194
+ };
@@ -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
+ import { BTPError } from './types.js';
8
+ export * from './constant.js';
9
+ export * from './types.js';
10
+ export declare class BTPErrorException extends Error {
11
+ readonly code?: string | number;
12
+ readonly status?: number;
13
+ readonly cause?: unknown;
14
+ readonly meta?: Record<string, unknown>;
15
+ constructor(btpError: BTPError, options?: {
16
+ cause?: unknown;
17
+ meta?: Record<string, unknown>;
18
+ });
19
+ /**
20
+ * Optional JSON representation for logs or APIs
21
+ */
22
+ toJSON(): {
23
+ cause?: {} | undefined;
24
+ meta?: Record<string, unknown> | undefined;
25
+ message: string;
26
+ stack: string | undefined;
27
+ status?: number | undefined;
28
+ name: string;
29
+ code: string | number | undefined;
30
+ };
31
+ }
32
+ export declare const transformToBTPErrorException: (err: unknown, options?: {
33
+ cause?: unknown;
34
+ meta?: Record<string, unknown>;
35
+ }) => BTPErrorException;
@@ -0,0 +1,52 @@
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 { BTP_ERROR_UNKNOWN } from "./constant.js";
9
+ export * from "./constant.js";
10
+ export * from "./types.js";
11
+ class BTPErrorException extends Error {
12
+ code;
13
+ status;
14
+ cause;
15
+ meta;
16
+ constructor(btpError, options) {
17
+ super(btpError.message), this.name = "BTPErrorException", this.code = btpError.code, this.status = btpError.status, this.cause = options?.cause, this.meta = options?.meta, Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace && Error.captureStackTrace(this, BTPErrorException);
18
+ }
19
+ toJSON() {
20
+ return {
21
+ name: this.name,
22
+ code: this.code,
23
+ ...this.status ? { status: this.status } : {},
24
+ message: this.message,
25
+ stack: this.stack,
26
+ ...this.meta ? { meta: this.meta } : {},
27
+ ...this.cause ? { cause: this.cause } : {}
28
+ };
29
+ }
30
+ }
31
+ const transformToBTPErrorException = (err, options) => {
32
+ if (err instanceof BTPErrorException)
33
+ return err;
34
+ if (err instanceof Error) {
35
+ const code = err?.code;
36
+ return new BTPErrorException(
37
+ { message: err?.message ?? err.name, code: code ?? BTP_ERROR_UNKNOWN.code },
38
+ {
39
+ cause: options?.cause ?? err.cause,
40
+ meta: { ...err, ...options?.meta ?? {} }
41
+ }
42
+ );
43
+ }
44
+ return new BTPErrorException(BTP_ERROR_UNKNOWN, {
45
+ cause: options?.cause ?? JSON.stringify(err),
46
+ meta: options?.meta ?? { err }
47
+ });
48
+ };
49
+ export {
50
+ BTPErrorException,
51
+ transformToBTPErrorException
52
+ };
@@ -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
+ export type BTPError = {
8
+ code?: string | number;
9
+ message: string;
10
+ /** The numeric status a server answers this error with (4xx: do not resend as is; 429 and 5xx: resend later) */
11
+ status?: number;
12
+ };
13
+ export type BTPErrorResponse<T = unknown> = {
14
+ data: T;
15
+ errors: BTPError[];
16
+ };
@@ -0,0 +1,7 @@
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
+
@@ -0,0 +1,17 @@
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 declare const BTP_PROTOCOL_VERSION = "1.1.0";
8
+ export declare const MIN_SUPPORTED_VERSION = "1.1.0";
9
+ export declare const MAX_SUPPORTED_VERSION = "1.1.0";
10
+ /**
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.
14
+ */
15
+ export declare const isSupportedVersion: (version: unknown) => boolean;
16
+ export declare const BTPS_DNS_HOST_NAME_SPACE = "_btps.host";
17
+ export declare const BTPS_DNS_IDENTITY_NAME_SPACE = "_btps.identity";
@@ -0,0 +1,25 @@
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 BTP_PROTOCOL_VERSION = "1.1.0", MIN_SUPPORTED_VERSION = "1.1.0", MAX_SUPPORTED_VERSION = "1.1.0", majorMinor = (version) => {
9
+ const match = /^(\d+)\.(\d+)(?:\.\d+)?$/.exec(version);
10
+ return match ? [Number(match[1]), Number(match[2])] : void 0;
11
+ }, isSupportedVersion = (version) => {
12
+ 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";
18
+ export {
19
+ BTPS_DNS_HOST_NAME_SPACE,
20
+ BTPS_DNS_IDENTITY_NAME_SPACE,
21
+ BTP_PROTOCOL_VERSION,
22
+ MAX_SUPPORTED_VERSION,
23
+ MIN_SUPPORTED_VERSION,
24
+ isSupportedVersion
25
+ };
@@ -0,0 +1,7 @@
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 declare const CONTROL_ACTIONS: readonly ["QUIT", "PING"];
@@ -0,0 +1,11 @@
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 CONTROL_ACTIONS = ["QUIT", "PING"];
9
+ export {
10
+ CONTROL_ACTIONS
11
+ };
@@ -0,0 +1,7 @@
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 declare const CURRENCY_CODES: readonly ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KID", "KMF", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWL"];