@majikah/sdk 0.1.0
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.
- package/LICENSE +67 -0
- package/README.md +1112 -0
- package/dist/client/MajikahSDKClient.d.ts +308 -0
- package/dist/client/MajikahSDKClient.js +318 -0
- package/dist/errors/APIError.d.ts +7 -0
- package/dist/errors/APIError.js +14 -0
- package/dist/errors/AuthenticationError.d.ts +3 -0
- package/dist/errors/AuthenticationError.js +4 -0
- package/dist/errors/MajikahError.d.ts +4 -0
- package/dist/errors/MajikahError.js +9 -0
- package/dist/errors/QuotaExhaustedError.d.ts +3 -0
- package/dist/errors/QuotaExhaustedError.js +4 -0
- package/dist/errors/RateLimitError.d.ts +5 -0
- package/dist/errors/RateLimitError.js +10 -0
- package/dist/errors/ServiceUnavailableError.d.ts +3 -0
- package/dist/errors/ServiceUnavailableError.js +4 -0
- package/dist/errors/ValidationError.d.ts +5 -0
- package/dist/errors/ValidationError.js +10 -0
- package/dist/errors/index.d.ts +8 -0
- package/dist/errors/index.js +8 -0
- package/dist/errors/mapError.d.ts +3 -0
- package/dist/errors/mapError.js +22 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +4 -0
- package/dist/services/muid/MUIDClient.d.ts +95 -0
- package/dist/services/muid/MUIDClient.js +138 -0
- package/dist/services/muid/key-resolver.d.ts +24 -0
- package/dist/services/muid/key-resolver.js +32 -0
- package/dist/services/notary/NotaryClient.d.ts +188 -0
- package/dist/services/notary/NotaryClient.js +291 -0
- package/dist/services/notary/validation.d.ts +7 -0
- package/dist/services/notary/validation.js +19 -0
- package/dist/services/shared/encoding.d.ts +21 -0
- package/dist/services/shared/encoding.js +43 -0
- package/dist/services/shared/resolve-signature.d.ts +23 -0
- package/dist/services/shared/resolve-signature.js +31 -0
- package/dist/services/shared/sleep.d.ts +1 -0
- package/dist/services/shared/sleep.js +3 -0
- package/dist/services/shared/validation.d.ts +9 -0
- package/dist/services/shared/validation.js +16 -0
- package/dist/services/slink/SLinkClient.d.ts +174 -0
- package/dist/services/slink/SLinkClient.js +231 -0
- package/dist/services/slink/validation.d.ts +24 -0
- package/dist/services/slink/validation.js +31 -0
- package/dist/services/tsa/TSAClient.d.ts +101 -0
- package/dist/services/tsa/TSAClient.js +178 -0
- package/dist/services/tsa/validation.d.ts +2 -0
- package/dist/services/tsa/validation.js +12 -0
- package/dist/transport/HttpClient.d.ts +85 -0
- package/dist/transport/HttpClient.js +135 -0
- package/dist/transport/RouteResolver.d.ts +54 -0
- package/dist/transport/RouteResolver.js +67 -0
- package/dist/transport/retry-after.d.ts +17 -0
- package/dist/transport/retry-after.js +39 -0
- package/dist/transport/retry.d.ts +8 -0
- package/dist/transport/retry.js +61 -0
- package/dist/types/common.d.ts +133 -0
- package/dist/types/common.js +42 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +1 -0
- package/dist/types/muid.d.ts +80 -0
- package/dist/types/muid.js +1 -0
- package/dist/types/notary.d.ts +243 -0
- package/dist/types/notary.js +1 -0
- package/dist/types/slink.d.ts +60 -0
- package/dist/types/slink.js +1 -0
- package/dist/types/tsa.d.ts +144 -0
- package/dist/types/tsa.js +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { TSAClient } from "../services/tsa/TSAClient";
|
|
2
|
+
import { MUIDClient } from "../services/muid/MUIDClient";
|
|
3
|
+
import { SLinkClient } from "../services/slink/SLinkClient";
|
|
4
|
+
import { NotaryClient } from "../services/notary/NotaryClient";
|
|
5
|
+
import type { MajikahClientOptions } from "../types/common";
|
|
6
|
+
/**
|
|
7
|
+
* Primary entry point for the Majikah TypeScript SDK.
|
|
8
|
+
*
|
|
9
|
+
* `MajikahSDKClient` composes the SDK's service-specific clients behind a
|
|
10
|
+
* single authenticated transport layer.
|
|
11
|
+
*
|
|
12
|
+
* Each service is exposed through a dedicated namespace:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const majikah = new MajikahSDKClient({
|
|
16
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* await majikah.muid.lookup("alice");
|
|
20
|
+
* await majikah.tsa.timestampFile(signedFile);
|
|
21
|
+
* await majikah.slink.verifyUrl("example.com");
|
|
22
|
+
* await majikah.notary.initiateNotarization(sealedFile);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* The root client is intentionally thin. Service-specific functionality
|
|
26
|
+
* belongs to the corresponding client:
|
|
27
|
+
*
|
|
28
|
+
* - {@link MUIDClient} — identity lookup and signature verification
|
|
29
|
+
* - {@link TSAClient} — trusted timestamping
|
|
30
|
+
* - {@link SLinkClient} — signed link registration, lookup, and verification
|
|
31
|
+
* - {@link NotaryClient} — payment-aware on-chain notarization
|
|
32
|
+
*
|
|
33
|
+
* All service clients created by this class share the same underlying
|
|
34
|
+
* {@link HttpClient} instance. This provides a consistent transport and
|
|
35
|
+
* authentication configuration across the SDK while allowing each service to
|
|
36
|
+
* maintain its own public API and domain-specific behavior.
|
|
37
|
+
*
|
|
38
|
+
* ## Architecture
|
|
39
|
+
*
|
|
40
|
+
* ```text
|
|
41
|
+
* MajikahSDKClient
|
|
42
|
+
* │
|
|
43
|
+
* shared HttpClient
|
|
44
|
+
* │
|
|
45
|
+
* ┌────────────────┼────────────────┐
|
|
46
|
+
* │ │ │
|
|
47
|
+
* ▼ ▼ ▼
|
|
48
|
+
* MUID TSA SLink
|
|
49
|
+
* │
|
|
50
|
+
* └─────────────────────────────────┐
|
|
51
|
+
* ▼
|
|
52
|
+
* Notary
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* The root client is responsible for SDK composition and configuration.
|
|
56
|
+
* It does not duplicate service methods or local cryptographic primitives.
|
|
57
|
+
* Operations that belong to a specific service should be accessed through
|
|
58
|
+
* that service's namespace.
|
|
59
|
+
*
|
|
60
|
+
* ## Getting an API key
|
|
61
|
+
*
|
|
62
|
+
* API keys are issued through the Majikah Developer Portal:
|
|
63
|
+
*
|
|
64
|
+
* https://developers.majikah.solutions/early-access
|
|
65
|
+
*
|
|
66
|
+
* To obtain an API key:
|
|
67
|
+
*
|
|
68
|
+
* 1. Create a Majikah account.
|
|
69
|
+
* 2. Create your **Majik Universal ID (MUID)**.
|
|
70
|
+
* 3. Complete the required **KYC verification** for your MUID.
|
|
71
|
+
* 4. Submit the **Early Access application** in the developer portal.
|
|
72
|
+
* 5. Wait for the application to be reviewed and approved by Majikah.
|
|
73
|
+
* 6. After approval, you will receive an email confirmation and gain access
|
|
74
|
+
* to API key generation in the developer portal.
|
|
75
|
+
*
|
|
76
|
+
* Public API access is currently subject to developer approval. An API key
|
|
77
|
+
* cannot be generated until the Early Access application has been approved.
|
|
78
|
+
*
|
|
79
|
+
* Example:
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* const majikah = new MajikahSDKClient({
|
|
83
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* Keep your API key secure. Do not commit it to source control, embed
|
|
88
|
+
* privileged keys in public client bundles, or expose it through logs.
|
|
89
|
+
*
|
|
90
|
+
* ## Authentication
|
|
91
|
+
*
|
|
92
|
+
* The API key supplied through {@link MajikahClientOptions} is shared by the
|
|
93
|
+
* underlying HTTP transport and is automatically applied to authenticated
|
|
94
|
+
* API requests.
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* const majikah = new MajikahSDKClient({
|
|
98
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* API keys should be treated as credentials and stored using the runtime's
|
|
103
|
+
* secure secret-management facilities. Do not commit production keys to
|
|
104
|
+
* source control or expose privileged keys in public browser bundles.
|
|
105
|
+
*
|
|
106
|
+
* ## Transport and configuration
|
|
107
|
+
*
|
|
108
|
+
* The constructor accepts the full {@link MajikahClientOptions} configuration,
|
|
109
|
+
* including the API base URL, API version configuration, request timeout,
|
|
110
|
+
* additional headers, retry policy, and optional custom `fetch`
|
|
111
|
+
* implementation.
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* const majikah = new MajikahSDKClient({
|
|
115
|
+
* apiKey,
|
|
116
|
+
* baseUrl: "https://api-public.majikah.solutions",
|
|
117
|
+
* version: 1,
|
|
118
|
+
* timeoutMs: 15_000,
|
|
119
|
+
* retry: {
|
|
120
|
+
* maxAttempts: 3,
|
|
121
|
+
* initialDelayMs: 300,
|
|
122
|
+
* jitterFactor: 0.4,
|
|
123
|
+
* capDelayMs: 5_000,
|
|
124
|
+
* },
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* All configured services inherit the same transport configuration unless
|
|
129
|
+
* their own service-level behavior explicitly overrides it.
|
|
130
|
+
*
|
|
131
|
+
* ## Local cryptography
|
|
132
|
+
*
|
|
133
|
+
* `MajikahSDKClient` does not hold or manage application private keys.
|
|
134
|
+
* Signing, sealing, and verification operations that require private
|
|
135
|
+
* cryptographic material are delegated to the corresponding Majikah
|
|
136
|
+
* cryptographic libraries, such as `@majikah/majik-key` and
|
|
137
|
+
* `@majikah/majik-signature`.
|
|
138
|
+
*
|
|
139
|
+
* For example:
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* const stamped = await majikah.tsa.stampFile(
|
|
143
|
+
* file,
|
|
144
|
+
* unlockedKey,
|
|
145
|
+
* );
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* The SDK coordinates the service request but does not require private
|
|
149
|
+
* signing keys to be uploaded to the Majikah API.
|
|
150
|
+
*
|
|
151
|
+
* ## Service namespaces
|
|
152
|
+
*
|
|
153
|
+
* ### `muid`
|
|
154
|
+
*
|
|
155
|
+
* {@link MUIDClient} provides identity lookup and signature verification
|
|
156
|
+
* functionality through Majik Universal ID.
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const profile = await majikah.muid.lookup("alice");
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* ### `tsa`
|
|
163
|
+
*
|
|
164
|
+
* {@link TSAClient} provides trusted timestamping operations.
|
|
165
|
+
*
|
|
166
|
+
* ```ts
|
|
167
|
+
* const result = await majikah.tsa.timestampFile(signedFile);
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* ### `slink`
|
|
171
|
+
*
|
|
172
|
+
* {@link SLinkClient} provides signed link registration, lookup,
|
|
173
|
+
* pagination, and cryptographic verification workflows.
|
|
174
|
+
*
|
|
175
|
+
* ```ts
|
|
176
|
+
* const result = await majikah.slink.verifyUrl("example.com");
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* ### `notary`
|
|
180
|
+
*
|
|
181
|
+
* {@link NotaryClient} provides payment-aware file notarization and
|
|
182
|
+
* on-chain anchor workflows.
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* const result =
|
|
186
|
+
* await majikah.notary.initiateNotarization(sealedFile);
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* ## Immutability
|
|
190
|
+
*
|
|
191
|
+
* The client class and its prototype are frozen after definition.
|
|
192
|
+
*
|
|
193
|
+
* Service properties are exposed as `readonly` references so consumers
|
|
194
|
+
* cannot replace the configured service clients through normal TypeScript
|
|
195
|
+
* usage.
|
|
196
|
+
*
|
|
197
|
+
* Freezing the class and prototype helps preserve the SDK's public service
|
|
198
|
+
* topology and prevents accidental mutation of the SDK's core methods at
|
|
199
|
+
* runtime.
|
|
200
|
+
*
|
|
201
|
+
* This does not freeze the internal state of the service clients or prevent
|
|
202
|
+
* normal object-level reflection capabilities provided by the JavaScript
|
|
203
|
+
* runtime.
|
|
204
|
+
*
|
|
205
|
+
* @param options SDK configuration used to initialize the shared HTTP
|
|
206
|
+
* transport and all service clients.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { MajikahSDKClient } from "@majikah/sdk";
|
|
211
|
+
*
|
|
212
|
+
* const majikah = new MajikahSDKClient({
|
|
213
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* const majikah = new MajikahSDKClient({
|
|
220
|
+
* apiKey,
|
|
221
|
+
* version: {
|
|
222
|
+
* muid: 2,
|
|
223
|
+
* tsa: 1,
|
|
224
|
+
* slink: 1,
|
|
225
|
+
* notary: 1,
|
|
226
|
+
* },
|
|
227
|
+
* timeoutMs: 15_000,
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* const profile = await majikah.muid.lookup("alice");
|
|
231
|
+
* const quota = await majikah.tsa.quota();
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* Create one root client per application integration or logical
|
|
236
|
+
* configuration rather than constructing separate service clients manually.
|
|
237
|
+
* This ensures that all services share the same transport, authentication,
|
|
238
|
+
* retry policy, timeout configuration, and API version strategy.
|
|
239
|
+
*/
|
|
240
|
+
export declare class MajikahSDKClient {
|
|
241
|
+
/**
|
|
242
|
+
* Trusted Timestamping Authority service client.
|
|
243
|
+
*
|
|
244
|
+
* Use this namespace for trusted timestamp issuance, timestamping existing
|
|
245
|
+
* signatures, detached timestamp envelopes, and TSA quota operations.
|
|
246
|
+
*
|
|
247
|
+
* @see {@link TSAClient}
|
|
248
|
+
*/
|
|
249
|
+
readonly tsa: TSAClient;
|
|
250
|
+
/**
|
|
251
|
+
* Majik Universal ID service client.
|
|
252
|
+
*
|
|
253
|
+
* Use this namespace for public MUID lookup, authenticated MUID retrieval,
|
|
254
|
+
* and signature verification against MUID identities.
|
|
255
|
+
*
|
|
256
|
+
* @see {@link MUIDClient}
|
|
257
|
+
*/
|
|
258
|
+
readonly muid: MUIDClient;
|
|
259
|
+
/**
|
|
260
|
+
* Signed Link service client.
|
|
261
|
+
*
|
|
262
|
+
* Use this namespace for SLink registration, lookup, pagination, and
|
|
263
|
+
* cryptographic verification workflows.
|
|
264
|
+
*
|
|
265
|
+
* @see {@link SLinkClient}
|
|
266
|
+
*/
|
|
267
|
+
readonly slink: SLinkClient;
|
|
268
|
+
/**
|
|
269
|
+
* File Notarization service client.
|
|
270
|
+
*
|
|
271
|
+
* Use this namespace for payment-aware notarization, seal registration,
|
|
272
|
+
* anchor status, polling, and higher-level seal-and-notarize workflows.
|
|
273
|
+
*
|
|
274
|
+
* @see {@link NotaryClient}
|
|
275
|
+
*/
|
|
276
|
+
readonly notary: NotaryClient;
|
|
277
|
+
/**
|
|
278
|
+
* Creates a configured Majikah SDK client and initializes all public
|
|
279
|
+
* service namespaces over a shared HTTP transport.
|
|
280
|
+
*
|
|
281
|
+
* The supplied options are passed to a single {@link HttpClient} instance,
|
|
282
|
+
* which is then shared by the MUID, TSA, SLink, and Notary clients.
|
|
283
|
+
*
|
|
284
|
+
* This means authentication, base URL, request timeout, retry behavior,
|
|
285
|
+
* custom headers, API versioning, and custom `fetch` behavior are
|
|
286
|
+
* consistently applied across the service clients.
|
|
287
|
+
*
|
|
288
|
+
* @param options SDK client configuration and transport options.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const majikah = new MajikahSDKClient({
|
|
293
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* const majikah = new MajikahSDKClient({
|
|
300
|
+
* apiKey,
|
|
301
|
+
* baseUrl: "https://api-public.majikah.solutions",
|
|
302
|
+
* timeoutMs: 15_000,
|
|
303
|
+
* version: 1,
|
|
304
|
+
* });
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
constructor(options: MajikahClientOptions);
|
|
308
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { HttpClient } from "../transport/HttpClient";
|
|
2
|
+
import { TSAClient } from "../services/tsa/TSAClient";
|
|
3
|
+
import { MUIDClient } from "../services/muid/MUIDClient";
|
|
4
|
+
import { SLinkClient } from "../services/slink/SLinkClient";
|
|
5
|
+
import { NotaryClient } from "../services/notary/NotaryClient";
|
|
6
|
+
/**
|
|
7
|
+
* Primary entry point for the Majikah TypeScript SDK.
|
|
8
|
+
*
|
|
9
|
+
* `MajikahSDKClient` composes the SDK's service-specific clients behind a
|
|
10
|
+
* single authenticated transport layer.
|
|
11
|
+
*
|
|
12
|
+
* Each service is exposed through a dedicated namespace:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const majikah = new MajikahSDKClient({
|
|
16
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* await majikah.muid.lookup("alice");
|
|
20
|
+
* await majikah.tsa.timestampFile(signedFile);
|
|
21
|
+
* await majikah.slink.verifyUrl("example.com");
|
|
22
|
+
* await majikah.notary.initiateNotarization(sealedFile);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* The root client is intentionally thin. Service-specific functionality
|
|
26
|
+
* belongs to the corresponding client:
|
|
27
|
+
*
|
|
28
|
+
* - {@link MUIDClient} — identity lookup and signature verification
|
|
29
|
+
* - {@link TSAClient} — trusted timestamping
|
|
30
|
+
* - {@link SLinkClient} — signed link registration, lookup, and verification
|
|
31
|
+
* - {@link NotaryClient} — payment-aware on-chain notarization
|
|
32
|
+
*
|
|
33
|
+
* All service clients created by this class share the same underlying
|
|
34
|
+
* {@link HttpClient} instance. This provides a consistent transport and
|
|
35
|
+
* authentication configuration across the SDK while allowing each service to
|
|
36
|
+
* maintain its own public API and domain-specific behavior.
|
|
37
|
+
*
|
|
38
|
+
* ## Architecture
|
|
39
|
+
*
|
|
40
|
+
* ```text
|
|
41
|
+
* MajikahSDKClient
|
|
42
|
+
* │
|
|
43
|
+
* shared HttpClient
|
|
44
|
+
* │
|
|
45
|
+
* ┌────────────────┼────────────────┐
|
|
46
|
+
* │ │ │
|
|
47
|
+
* ▼ ▼ ▼
|
|
48
|
+
* MUID TSA SLink
|
|
49
|
+
* │
|
|
50
|
+
* └─────────────────────────────────┐
|
|
51
|
+
* ▼
|
|
52
|
+
* Notary
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* The root client is responsible for SDK composition and configuration.
|
|
56
|
+
* It does not duplicate service methods or local cryptographic primitives.
|
|
57
|
+
* Operations that belong to a specific service should be accessed through
|
|
58
|
+
* that service's namespace.
|
|
59
|
+
*
|
|
60
|
+
* ## Getting an API key
|
|
61
|
+
*
|
|
62
|
+
* API keys are issued through the Majikah Developer Portal:
|
|
63
|
+
*
|
|
64
|
+
* https://developers.majikah.solutions/early-access
|
|
65
|
+
*
|
|
66
|
+
* To obtain an API key:
|
|
67
|
+
*
|
|
68
|
+
* 1. Create a Majikah account.
|
|
69
|
+
* 2. Create your **Majik Universal ID (MUID)**.
|
|
70
|
+
* 3. Complete the required **KYC verification** for your MUID.
|
|
71
|
+
* 4. Submit the **Early Access application** in the developer portal.
|
|
72
|
+
* 5. Wait for the application to be reviewed and approved by Majikah.
|
|
73
|
+
* 6. After approval, you will receive an email confirmation and gain access
|
|
74
|
+
* to API key generation in the developer portal.
|
|
75
|
+
*
|
|
76
|
+
* Public API access is currently subject to developer approval. An API key
|
|
77
|
+
* cannot be generated until the Early Access application has been approved.
|
|
78
|
+
*
|
|
79
|
+
* Example:
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* const majikah = new MajikahSDKClient({
|
|
83
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* Keep your API key secure. Do not commit it to source control, embed
|
|
88
|
+
* privileged keys in public client bundles, or expose it through logs.
|
|
89
|
+
*
|
|
90
|
+
* ## Authentication
|
|
91
|
+
*
|
|
92
|
+
* The API key supplied through {@link MajikahClientOptions} is shared by the
|
|
93
|
+
* underlying HTTP transport and is automatically applied to authenticated
|
|
94
|
+
* API requests.
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* const majikah = new MajikahSDKClient({
|
|
98
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* API keys should be treated as credentials and stored using the runtime's
|
|
103
|
+
* secure secret-management facilities. Do not commit production keys to
|
|
104
|
+
* source control or expose privileged keys in public browser bundles.
|
|
105
|
+
*
|
|
106
|
+
* ## Transport and configuration
|
|
107
|
+
*
|
|
108
|
+
* The constructor accepts the full {@link MajikahClientOptions} configuration,
|
|
109
|
+
* including the API base URL, API version configuration, request timeout,
|
|
110
|
+
* additional headers, retry policy, and optional custom `fetch`
|
|
111
|
+
* implementation.
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* const majikah = new MajikahSDKClient({
|
|
115
|
+
* apiKey,
|
|
116
|
+
* baseUrl: "https://api-public.majikah.solutions",
|
|
117
|
+
* version: 1,
|
|
118
|
+
* timeoutMs: 15_000,
|
|
119
|
+
* retry: {
|
|
120
|
+
* maxAttempts: 3,
|
|
121
|
+
* initialDelayMs: 300,
|
|
122
|
+
* jitterFactor: 0.4,
|
|
123
|
+
* capDelayMs: 5_000,
|
|
124
|
+
* },
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* All configured services inherit the same transport configuration unless
|
|
129
|
+
* their own service-level behavior explicitly overrides it.
|
|
130
|
+
*
|
|
131
|
+
* ## Local cryptography
|
|
132
|
+
*
|
|
133
|
+
* `MajikahSDKClient` does not hold or manage application private keys.
|
|
134
|
+
* Signing, sealing, and verification operations that require private
|
|
135
|
+
* cryptographic material are delegated to the corresponding Majikah
|
|
136
|
+
* cryptographic libraries, such as `@majikah/majik-key` and
|
|
137
|
+
* `@majikah/majik-signature`.
|
|
138
|
+
*
|
|
139
|
+
* For example:
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* const stamped = await majikah.tsa.stampFile(
|
|
143
|
+
* file,
|
|
144
|
+
* unlockedKey,
|
|
145
|
+
* );
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* The SDK coordinates the service request but does not require private
|
|
149
|
+
* signing keys to be uploaded to the Majikah API.
|
|
150
|
+
*
|
|
151
|
+
* ## Service namespaces
|
|
152
|
+
*
|
|
153
|
+
* ### `muid`
|
|
154
|
+
*
|
|
155
|
+
* {@link MUIDClient} provides identity lookup and signature verification
|
|
156
|
+
* functionality through Majik Universal ID.
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const profile = await majikah.muid.lookup("alice");
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* ### `tsa`
|
|
163
|
+
*
|
|
164
|
+
* {@link TSAClient} provides trusted timestamping operations.
|
|
165
|
+
*
|
|
166
|
+
* ```ts
|
|
167
|
+
* const result = await majikah.tsa.timestampFile(signedFile);
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* ### `slink`
|
|
171
|
+
*
|
|
172
|
+
* {@link SLinkClient} provides signed link registration, lookup,
|
|
173
|
+
* pagination, and cryptographic verification workflows.
|
|
174
|
+
*
|
|
175
|
+
* ```ts
|
|
176
|
+
* const result = await majikah.slink.verifyUrl("example.com");
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* ### `notary`
|
|
180
|
+
*
|
|
181
|
+
* {@link NotaryClient} provides payment-aware file notarization and
|
|
182
|
+
* on-chain anchor workflows.
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* const result =
|
|
186
|
+
* await majikah.notary.initiateNotarization(sealedFile);
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* ## Immutability
|
|
190
|
+
*
|
|
191
|
+
* The client class and its prototype are frozen after definition.
|
|
192
|
+
*
|
|
193
|
+
* Service properties are exposed as `readonly` references so consumers
|
|
194
|
+
* cannot replace the configured service clients through normal TypeScript
|
|
195
|
+
* usage.
|
|
196
|
+
*
|
|
197
|
+
* Freezing the class and prototype helps preserve the SDK's public service
|
|
198
|
+
* topology and prevents accidental mutation of the SDK's core methods at
|
|
199
|
+
* runtime.
|
|
200
|
+
*
|
|
201
|
+
* This does not freeze the internal state of the service clients or prevent
|
|
202
|
+
* normal object-level reflection capabilities provided by the JavaScript
|
|
203
|
+
* runtime.
|
|
204
|
+
*
|
|
205
|
+
* @param options SDK configuration used to initialize the shared HTTP
|
|
206
|
+
* transport and all service clients.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { MajikahSDKClient } from "@majikah/sdk";
|
|
211
|
+
*
|
|
212
|
+
* const majikah = new MajikahSDKClient({
|
|
213
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* const majikah = new MajikahSDKClient({
|
|
220
|
+
* apiKey,
|
|
221
|
+
* version: {
|
|
222
|
+
* muid: 2,
|
|
223
|
+
* tsa: 1,
|
|
224
|
+
* slink: 1,
|
|
225
|
+
* notary: 1,
|
|
226
|
+
* },
|
|
227
|
+
* timeoutMs: 15_000,
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* const profile = await majikah.muid.lookup("alice");
|
|
231
|
+
* const quota = await majikah.tsa.quota();
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* Create one root client per application integration or logical
|
|
236
|
+
* configuration rather than constructing separate service clients manually.
|
|
237
|
+
* This ensures that all services share the same transport, authentication,
|
|
238
|
+
* retry policy, timeout configuration, and API version strategy.
|
|
239
|
+
*/
|
|
240
|
+
export class MajikahSDKClient {
|
|
241
|
+
/**
|
|
242
|
+
* Trusted Timestamping Authority service client.
|
|
243
|
+
*
|
|
244
|
+
* Use this namespace for trusted timestamp issuance, timestamping existing
|
|
245
|
+
* signatures, detached timestamp envelopes, and TSA quota operations.
|
|
246
|
+
*
|
|
247
|
+
* @see {@link TSAClient}
|
|
248
|
+
*/
|
|
249
|
+
tsa;
|
|
250
|
+
/**
|
|
251
|
+
* Majik Universal ID service client.
|
|
252
|
+
*
|
|
253
|
+
* Use this namespace for public MUID lookup, authenticated MUID retrieval,
|
|
254
|
+
* and signature verification against MUID identities.
|
|
255
|
+
*
|
|
256
|
+
* @see {@link MUIDClient}
|
|
257
|
+
*/
|
|
258
|
+
muid;
|
|
259
|
+
/**
|
|
260
|
+
* Signed Link service client.
|
|
261
|
+
*
|
|
262
|
+
* Use this namespace for SLink registration, lookup, pagination, and
|
|
263
|
+
* cryptographic verification workflows.
|
|
264
|
+
*
|
|
265
|
+
* @see {@link SLinkClient}
|
|
266
|
+
*/
|
|
267
|
+
slink;
|
|
268
|
+
/**
|
|
269
|
+
* File Notarization service client.
|
|
270
|
+
*
|
|
271
|
+
* Use this namespace for payment-aware notarization, seal registration,
|
|
272
|
+
* anchor status, polling, and higher-level seal-and-notarize workflows.
|
|
273
|
+
*
|
|
274
|
+
* @see {@link NotaryClient}
|
|
275
|
+
*/
|
|
276
|
+
notary;
|
|
277
|
+
/**
|
|
278
|
+
* Creates a configured Majikah SDK client and initializes all public
|
|
279
|
+
* service namespaces over a shared HTTP transport.
|
|
280
|
+
*
|
|
281
|
+
* The supplied options are passed to a single {@link HttpClient} instance,
|
|
282
|
+
* which is then shared by the MUID, TSA, SLink, and Notary clients.
|
|
283
|
+
*
|
|
284
|
+
* This means authentication, base URL, request timeout, retry behavior,
|
|
285
|
+
* custom headers, API versioning, and custom `fetch` behavior are
|
|
286
|
+
* consistently applied across the service clients.
|
|
287
|
+
*
|
|
288
|
+
* @param options SDK client configuration and transport options.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const majikah = new MajikahSDKClient({
|
|
293
|
+
* apiKey: process.env.MAJIKAH_API_KEY!,
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* const majikah = new MajikahSDKClient({
|
|
300
|
+
* apiKey,
|
|
301
|
+
* baseUrl: "https://api-public.majikah.solutions",
|
|
302
|
+
* timeoutMs: 15_000,
|
|
303
|
+
* version: 1,
|
|
304
|
+
* });
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
constructor(options) {
|
|
308
|
+
const http = new HttpClient(options);
|
|
309
|
+
this.tsa = new TSAClient(http);
|
|
310
|
+
this.muid = new MUIDClient(http);
|
|
311
|
+
this.slink = new SLinkClient(http);
|
|
312
|
+
this.notary = new NotaryClient(http);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// Freeze static methods
|
|
316
|
+
Object.freeze(MajikahSDKClient);
|
|
317
|
+
// Freeze instance methods
|
|
318
|
+
Object.freeze(MajikahSDKClient.prototype);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MajikahError } from "./MajikahError";
|
|
2
|
+
export declare class APIError extends MajikahError {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly requestId?: string | undefined;
|
|
6
|
+
constructor(message: string, status: number, code: string, requestId?: string | undefined);
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MajikahError } from "./MajikahError";
|
|
2
|
+
// errors/APIError.ts
|
|
3
|
+
export class APIError extends MajikahError {
|
|
4
|
+
status;
|
|
5
|
+
code;
|
|
6
|
+
requestId;
|
|
7
|
+
constructor(message, status, code, requestId) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.requestId = requestId;
|
|
12
|
+
this.name = "APIError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { APIError } from "./APIError";
|
|
2
|
+
// errors/RateLimitError.ts — 429
|
|
3
|
+
export class RateLimitError extends APIError {
|
|
4
|
+
retryAfterMs;
|
|
5
|
+
constructor(message, status, code, retryAfterMs, requestId) {
|
|
6
|
+
super(message, status, code, requestId);
|
|
7
|
+
this.retryAfterMs = retryAfterMs;
|
|
8
|
+
this.name = "RateLimitError";
|
|
9
|
+
}
|
|
10
|
+
}
|