@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,10 @@
|
|
|
1
|
+
import { MajikahError } from "./MajikahError";
|
|
2
|
+
// errors/ValidationError.ts — client-side, thrown before any network call
|
|
3
|
+
export class ValidationError extends MajikahError {
|
|
4
|
+
issues;
|
|
5
|
+
constructor(message, issues) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.issues = issues;
|
|
8
|
+
this.name = "ValidationError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { APIError } from "./APIError";
|
|
2
|
+
export { AuthenticationError } from "./AuthenticationError";
|
|
3
|
+
export { MajikahError } from "./MajikahError";
|
|
4
|
+
export { QuotaExhaustedError } from "./QuotaExhaustedError";
|
|
5
|
+
export { RateLimitError } from "./RateLimitError";
|
|
6
|
+
export { ServiceUnavailableError } from "./ServiceUnavailableError";
|
|
7
|
+
export { ValidationError } from "./ValidationError";
|
|
8
|
+
export { mapError } from "./mapError";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { APIError } from "./APIError";
|
|
2
|
+
export { AuthenticationError } from "./AuthenticationError";
|
|
3
|
+
export { MajikahError } from "./MajikahError";
|
|
4
|
+
export { QuotaExhaustedError } from "./QuotaExhaustedError";
|
|
5
|
+
export { RateLimitError } from "./RateLimitError";
|
|
6
|
+
export { ServiceUnavailableError } from "./ServiceUnavailableError";
|
|
7
|
+
export { ValidationError } from "./ValidationError";
|
|
8
|
+
export { mapError } from "./mapError";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// errors/mapError.ts
|
|
2
|
+
import { APIError } from "./APIError";
|
|
3
|
+
import { AuthenticationError } from "./AuthenticationError";
|
|
4
|
+
import { QuotaExhaustedError } from "./QuotaExhaustedError";
|
|
5
|
+
import { RateLimitError } from "./RateLimitError";
|
|
6
|
+
import { ServiceUnavailableError } from "./ServiceUnavailableError";
|
|
7
|
+
export function mapError(status, body, requestId, retryAfterMs) {
|
|
8
|
+
const message = body?.error ?? `Request failed with status ${status}`;
|
|
9
|
+
const code = body?.code ?? "UNKNOWN_ERROR";
|
|
10
|
+
switch (status) {
|
|
11
|
+
case 401:
|
|
12
|
+
return new AuthenticationError(message, status, code, requestId);
|
|
13
|
+
case 402:
|
|
14
|
+
return new QuotaExhaustedError(message, status, code, requestId);
|
|
15
|
+
case 429:
|
|
16
|
+
return new RateLimitError(message, status, code, retryAfterMs, requestId);
|
|
17
|
+
case 503:
|
|
18
|
+
return new ServiceUnavailableError(message, status, code, requestId);
|
|
19
|
+
default:
|
|
20
|
+
return new APIError(message, status, code, requestId);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./errors";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./services";
|
|
4
|
+
export { MajikahSDKClient } from "./client/MajikahSDKClient";
|
|
5
|
+
export { HttpClient } from "./transport/HttpClient";
|
|
6
|
+
export * from "@majikah/majik-key";
|
|
7
|
+
export * from "@majikah/majik-signature";
|
|
8
|
+
export { MajikUniversalID, type MajikUniversalIDJSON, type MajikID, type PublicProfile, type MajikKeyPublicBundle, type MajikSignerPublicKeys, type ResolvedSignerPublicKeys, MajikIDPublicView, MajikUser, } from "@majikah/majik-universal-id";
|
|
9
|
+
export { createMuidPublicKeyResolver } from "./services/muid/key-resolver";
|
|
10
|
+
export { base64ToBytes, bytesToBase64 } from "./services/shared/encoding";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./errors";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./services";
|
|
4
|
+
export { MajikahSDKClient } from "./client/MajikahSDKClient";
|
|
5
|
+
export { HttpClient } from "./transport/HttpClient";
|
|
6
|
+
export * from "@majikah/majik-key";
|
|
7
|
+
export * from "@majikah/majik-signature";
|
|
8
|
+
export { MajikUniversalID, } from "@majikah/majik-universal-id";
|
|
9
|
+
export { createMuidPublicKeyResolver } from "./services/muid/key-resolver";
|
|
10
|
+
export { base64ToBytes, bytesToBase64 } from "./services/shared/encoding";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type EnvelopeInput, type FileLike } from "@majikah/majik-signature";
|
|
2
|
+
import type { HttpClient } from "../../transport/HttpClient";
|
|
3
|
+
import type { MajikIDPublicView, MuidPublicLookupResult, MuidVerifyRequestBody, MuidVerifyResult, VerifyFileDetachedOptions, VerifyFileOptions } from "../../types/muid";
|
|
4
|
+
/**
|
|
5
|
+
* Client for interacting with the Majik Universal ID (MUID) API.
|
|
6
|
+
*
|
|
7
|
+
* Provides direct MUID API operations as well as convenience methods for
|
|
8
|
+
* verifying signatures embedded in files or stored in detached envelopes.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MUIDClient {
|
|
11
|
+
private readonly http;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a MUID client using the provided HTTP transport.
|
|
14
|
+
*
|
|
15
|
+
* @param http HTTP client used to communicate with the Majikah API.
|
|
16
|
+
*/
|
|
17
|
+
constructor(http: HttpClient);
|
|
18
|
+
/**
|
|
19
|
+
* Returns the MUID associated with the current API credentials.
|
|
20
|
+
*
|
|
21
|
+
* @returns Public identity information for the authenticated MUID.
|
|
22
|
+
*/
|
|
23
|
+
me(): Promise<MajikIDPublicView>;
|
|
24
|
+
/**
|
|
25
|
+
* Verifies a signature against a MUID.
|
|
26
|
+
*
|
|
27
|
+
* @param body Signature verification request containing the signature and
|
|
28
|
+
* optional MUID identifier.
|
|
29
|
+
* @returns The result of the MUID verification.
|
|
30
|
+
* @throws ValidationError When no signature is provided.
|
|
31
|
+
*/
|
|
32
|
+
verify(body: MuidVerifyRequestBody): Promise<MuidVerifyResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Looks up the public MUID associated with an ID or username.
|
|
35
|
+
*
|
|
36
|
+
* @param idOrUsername MUID ID or username to look up.
|
|
37
|
+
* @returns Public MUID information.
|
|
38
|
+
* @throws ValidationError When the identifier is empty.
|
|
39
|
+
*/
|
|
40
|
+
lookup(idOrUsername: string): Promise<MuidPublicLookupResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Verifies a signature embedded in a file against a MUID.
|
|
43
|
+
*
|
|
44
|
+
* The file must already contain a Majik Signature. No signing key is
|
|
45
|
+
* required because this method only extracts and verifies an existing
|
|
46
|
+
* signature.
|
|
47
|
+
*
|
|
48
|
+
* When the file contains exactly one signature, it is selected
|
|
49
|
+
* automatically. Multi-signature files require `expectedSignerId` to
|
|
50
|
+
* explicitly select the signature being verified.
|
|
51
|
+
*
|
|
52
|
+
* @param file File containing an embedded Majik Signature.
|
|
53
|
+
* @param options Optional signer, MUID, and MIME type settings.
|
|
54
|
+
* @returns The result of the MUID verification.
|
|
55
|
+
* @throws ValidationError When the file contains no signatures or a
|
|
56
|
+
* requested signer cannot be resolved.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const result = await majikah.muid.verifyFile(file);
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const result = await majikah.muid.verifyFile(file, {
|
|
66
|
+
* expectedSignerId: bobFingerprint,
|
|
67
|
+
* muid: "bob",
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
verifyFile(file: FileLike, options?: VerifyFileOptions): Promise<MuidVerifyResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Verifies a signature contained in a detached envelope against a MUID.
|
|
74
|
+
*
|
|
75
|
+
* The envelope supplies the signature and its content hash. The actual
|
|
76
|
+
* content verification is performed server-side.
|
|
77
|
+
*
|
|
78
|
+
* When the envelope contains exactly one signature, it is selected
|
|
79
|
+
* automatically. Multi-signature envelopes require `expectedSignerId`.
|
|
80
|
+
*
|
|
81
|
+
* @param envelope Detached Majik Signature envelope.
|
|
82
|
+
* @param options Optional signer and MUID settings.
|
|
83
|
+
* @returns The result of the MUID verification.
|
|
84
|
+
* @throws ValidationError When the envelope contains no signatures or a
|
|
85
|
+
* requested signer cannot be resolved.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const result = await majikah.muid.verifyFileDetached(envelope, {
|
|
90
|
+
* muid: "alice",
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
verifyFileDetached(envelope: EnvelopeInput, options?: VerifyFileDetachedOptions): Promise<MuidVerifyResult>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { MajikSignature, MajikSignatureEnvelope, } from "@majikah/majik-signature";
|
|
2
|
+
import { ValidationError } from "../../errors/ValidationError";
|
|
3
|
+
import { resolveTargetSignature } from "../shared/resolve-signature";
|
|
4
|
+
const NO_SIGNATURE_HINT = "Sign the file first via @majikah/majik-signature before verifying it against a MUID.";
|
|
5
|
+
/**
|
|
6
|
+
* Client for interacting with the Majik Universal ID (MUID) API.
|
|
7
|
+
*
|
|
8
|
+
* Provides direct MUID API operations as well as convenience methods for
|
|
9
|
+
* verifying signatures embedded in files or stored in detached envelopes.
|
|
10
|
+
*/
|
|
11
|
+
export class MUIDClient {
|
|
12
|
+
http;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a MUID client using the provided HTTP transport.
|
|
15
|
+
*
|
|
16
|
+
* @param http HTTP client used to communicate with the Majikah API.
|
|
17
|
+
*/
|
|
18
|
+
constructor(http) {
|
|
19
|
+
this.http = http;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the MUID associated with the current API credentials.
|
|
23
|
+
*
|
|
24
|
+
* @returns Public identity information for the authenticated MUID.
|
|
25
|
+
*/
|
|
26
|
+
async me() {
|
|
27
|
+
return this.http.request("muid", "/me", {
|
|
28
|
+
method: "GET",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Verifies a signature against a MUID.
|
|
33
|
+
*
|
|
34
|
+
* @param body Signature verification request containing the signature and
|
|
35
|
+
* optional MUID identifier.
|
|
36
|
+
* @returns The result of the MUID verification.
|
|
37
|
+
* @throws ValidationError When no signature is provided.
|
|
38
|
+
*/
|
|
39
|
+
async verify(body) {
|
|
40
|
+
if (!body?.signature) {
|
|
41
|
+
throw new ValidationError("signature is required", body);
|
|
42
|
+
}
|
|
43
|
+
return this.http.request("muid", "/verify", {
|
|
44
|
+
method: "POST",
|
|
45
|
+
body,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Looks up the public MUID associated with an ID or username.
|
|
50
|
+
*
|
|
51
|
+
* @param idOrUsername MUID ID or username to look up.
|
|
52
|
+
* @returns Public MUID information.
|
|
53
|
+
* @throws ValidationError When the identifier is empty.
|
|
54
|
+
*/
|
|
55
|
+
async lookup(idOrUsername) {
|
|
56
|
+
if (!idOrUsername) {
|
|
57
|
+
throw new ValidationError("id or username is required", idOrUsername);
|
|
58
|
+
}
|
|
59
|
+
return this.http.request("muid", `/${encodeURIComponent(idOrUsername)}/public`, { method: "GET" });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Verifies a signature embedded in a file against a MUID.
|
|
63
|
+
*
|
|
64
|
+
* The file must already contain a Majik Signature. No signing key is
|
|
65
|
+
* required because this method only extracts and verifies an existing
|
|
66
|
+
* signature.
|
|
67
|
+
*
|
|
68
|
+
* When the file contains exactly one signature, it is selected
|
|
69
|
+
* automatically. Multi-signature files require `expectedSignerId` to
|
|
70
|
+
* explicitly select the signature being verified.
|
|
71
|
+
*
|
|
72
|
+
* @param file File containing an embedded Majik Signature.
|
|
73
|
+
* @param options Optional signer, MUID, and MIME type settings.
|
|
74
|
+
* @returns The result of the MUID verification.
|
|
75
|
+
* @throws ValidationError When the file contains no signatures or a
|
|
76
|
+
* requested signer cannot be resolved.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const result = await majikah.muid.verifyFile(file);
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const result = await majikah.muid.verifyFile(file, {
|
|
86
|
+
* expectedSignerId: bobFingerprint,
|
|
87
|
+
* muid: "bob",
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async verifyFile(file, options) {
|
|
92
|
+
const signatures = await MajikSignature.extractFrom(file, {
|
|
93
|
+
mimeType: options?.mimeType,
|
|
94
|
+
});
|
|
95
|
+
const target = resolveTargetSignature(signatures, options?.expectedSignerId, {
|
|
96
|
+
noSignatureHint: NO_SIGNATURE_HINT,
|
|
97
|
+
});
|
|
98
|
+
return this.verify({
|
|
99
|
+
id: options?.muid,
|
|
100
|
+
signature: target.toJSON(),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Verifies a signature contained in a detached envelope against a MUID.
|
|
105
|
+
*
|
|
106
|
+
* The envelope supplies the signature and its content hash. The actual
|
|
107
|
+
* content verification is performed server-side.
|
|
108
|
+
*
|
|
109
|
+
* When the envelope contains exactly one signature, it is selected
|
|
110
|
+
* automatically. Multi-signature envelopes require `expectedSignerId`.
|
|
111
|
+
*
|
|
112
|
+
* @param envelope Detached Majik Signature envelope.
|
|
113
|
+
* @param options Optional signer and MUID settings.
|
|
114
|
+
* @returns The result of the MUID verification.
|
|
115
|
+
* @throws ValidationError When the envelope contains no signatures or a
|
|
116
|
+
* requested signer cannot be resolved.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const result = await majikah.muid.verifyFileDetached(envelope, {
|
|
121
|
+
* muid: "alice",
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
async verifyFileDetached(envelope, options) {
|
|
126
|
+
const env = await MajikSignatureEnvelope.from(envelope);
|
|
127
|
+
const signatures = env.signatures.map((s) => MajikSignature.fromJSON(s));
|
|
128
|
+
const target = resolveTargetSignature(signatures, options?.expectedSignerId, {
|
|
129
|
+
noSignatureHint: NO_SIGNATURE_HINT,
|
|
130
|
+
});
|
|
131
|
+
return this.verify({
|
|
132
|
+
id: options?.muid,
|
|
133
|
+
signature: target.toJSON(),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
Object.freeze(MUIDClient);
|
|
138
|
+
Object.freeze(MUIDClient.prototype);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MUIDClient } from "./MUIDClient";
|
|
2
|
+
import { PublicKeyResolver } from "../../types/slink";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a public key resolver backed by MUID lookups.
|
|
5
|
+
*
|
|
6
|
+
* The resolver fetches the signer's MUID profile and converts its Base64-
|
|
7
|
+
* encoded signing keys into the `Uint8Array` format required by
|
|
8
|
+
* `PublicKeyResolver`.
|
|
9
|
+
*
|
|
10
|
+
* @param muidClient MUID client used to resolve public identity information.
|
|
11
|
+
* @returns A public key resolver suitable for `verifyUrlWithProof()` or
|
|
12
|
+
* `verifyMatches()`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const resolvePublicKeys = createMuidPublicKeyResolver(majikah.muid);
|
|
17
|
+
*
|
|
18
|
+
* const results = await majikah.slink.verifyUrlWithProof(
|
|
19
|
+
* "thezelijah.world",
|
|
20
|
+
* resolvePublicKeys,
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createMuidPublicKeyResolver(muidClient: MUIDClient): PublicKeyResolver;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { base64ToBytes } from "../shared/encoding";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a public key resolver backed by MUID lookups.
|
|
4
|
+
*
|
|
5
|
+
* The resolver fetches the signer's MUID profile and converts its Base64-
|
|
6
|
+
* encoded signing keys into the `Uint8Array` format required by
|
|
7
|
+
* `PublicKeyResolver`.
|
|
8
|
+
*
|
|
9
|
+
* @param muidClient MUID client used to resolve public identity information.
|
|
10
|
+
* @returns A public key resolver suitable for `verifyUrlWithProof()` or
|
|
11
|
+
* `verifyMatches()`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const resolvePublicKeys = createMuidPublicKeyResolver(majikah.muid);
|
|
16
|
+
*
|
|
17
|
+
* const results = await majikah.slink.verifyUrlWithProof(
|
|
18
|
+
* "thezelijah.world",
|
|
19
|
+
* resolvePublicKeys,
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function createMuidPublicKeyResolver(muidClient) {
|
|
24
|
+
return async (muid, signerId) => {
|
|
25
|
+
const profile = await muidClient.lookup(muid);
|
|
26
|
+
return {
|
|
27
|
+
signerId,
|
|
28
|
+
edPublicKey: base64ToBytes(profile.muid.signing_key.ed_public_key),
|
|
29
|
+
mlDsaPublicKey: base64ToBytes(profile.muid.signing_key.ml_dsa_public_key),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { MajikKey } from "@majikah/majik-key";
|
|
2
|
+
import { type FileLike, type MajikChainAnchor } from "@majikah/majik-signature";
|
|
3
|
+
import type { HttpClient } from "../../transport/HttpClient";
|
|
4
|
+
import type { InitiateNotarizationResult, NotaryPaymentResult, PollOptions, SignSealOptions } from "../../types/notary";
|
|
5
|
+
/**
|
|
6
|
+
* Client for notarizing sealed Majik Signature documents on-chain.
|
|
7
|
+
*
|
|
8
|
+
* Notarization uses a two-phase flow:
|
|
9
|
+
*
|
|
10
|
+
* 1. A sealed document is identified by its `sealHash` and payment is
|
|
11
|
+
* initiated or detected.
|
|
12
|
+
* 2. After payment is complete, the seal is registered on-chain and the
|
|
13
|
+
* resulting anchor is embedded back into the document.
|
|
14
|
+
*
|
|
15
|
+
* Lower-level methods such as `payment()`, `register()`, and `status()`
|
|
16
|
+
* expose the individual API operations, while the higher-level methods
|
|
17
|
+
* provide complete file-aware workflows.
|
|
18
|
+
*/
|
|
19
|
+
export declare class NotaryClient {
|
|
20
|
+
private readonly http;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a Notary client using the provided HTTP transport.
|
|
23
|
+
*
|
|
24
|
+
* @param http HTTP client used to communicate with the Majikah API.
|
|
25
|
+
*/
|
|
26
|
+
constructor(http: HttpClient);
|
|
27
|
+
/**
|
|
28
|
+
* Creates or resumes payment for a sealed document.
|
|
29
|
+
*
|
|
30
|
+
* If the seal has already been anchored, the existing chain anchor is
|
|
31
|
+
* returned and no payment is required.
|
|
32
|
+
*
|
|
33
|
+
* If payment has not yet been completed, the response contains checkout
|
|
34
|
+
* information that can be presented to the user.
|
|
35
|
+
*
|
|
36
|
+
* @param sealHash Unique hash identifying the sealed document.
|
|
37
|
+
* @returns Either an existing chain anchor or payment checkout information.
|
|
38
|
+
* @throws APIError When payment has already been completed for the seal.
|
|
39
|
+
*/
|
|
40
|
+
payment(sealHash: string): Promise<NotaryPaymentResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Submits a paid seal for on-chain notarization.
|
|
43
|
+
*
|
|
44
|
+
* Registration returns immediately. If the anchor is still being confirmed,
|
|
45
|
+
* use {@link status} or {@link pollUntilTerminal} to track its progress.
|
|
46
|
+
*
|
|
47
|
+
* Payment must already be completed for the supplied `sealHash`.
|
|
48
|
+
*
|
|
49
|
+
* @param sealHash Unique hash identifying the paid sealed document.
|
|
50
|
+
* @returns The newly created or existing chain anchor.
|
|
51
|
+
* @throws APIError When no completed payment exists for the seal hash.
|
|
52
|
+
*/
|
|
53
|
+
register(sealHash: string): Promise<MajikChainAnchor>;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the current confirmation status of a notarization anchor.
|
|
56
|
+
*
|
|
57
|
+
* @param anchorId Identifier of the chain anchor.
|
|
58
|
+
* @returns The current chain anchor state.
|
|
59
|
+
* @throws ValidationError When the anchor ID is empty.
|
|
60
|
+
*/
|
|
61
|
+
status(anchorId: string): Promise<MajikChainAnchor>;
|
|
62
|
+
/**
|
|
63
|
+
* Polls a notarization anchor until it reaches a terminal state.
|
|
64
|
+
*
|
|
65
|
+
* Resolves when the anchor becomes `confirmed`, `finalized`, or `failed`.
|
|
66
|
+
* A failed anchor is returned normally rather than thrown as an exception;
|
|
67
|
+
* callers should inspect `anchor.status` to determine the outcome.
|
|
68
|
+
*
|
|
69
|
+
* @param anchorId Identifier of the chain anchor to monitor.
|
|
70
|
+
* @param options Polling interval and timeout settings.
|
|
71
|
+
* @returns The anchor in its terminal state.
|
|
72
|
+
* @throws MajikahError When the anchor remains pending until the timeout.
|
|
73
|
+
*/
|
|
74
|
+
pollUntilTerminal(anchorId: string, options?: PollOptions): Promise<MajikChainAnchor>;
|
|
75
|
+
/**
|
|
76
|
+
* Starts the payment-aware notarization flow for an already-sealed file.
|
|
77
|
+
*
|
|
78
|
+
* This method does not wait for payment or blockchain confirmation.
|
|
79
|
+
* Its result tells the caller what action is required next:
|
|
80
|
+
*
|
|
81
|
+
* - `anchored`: The document was already anchored and the returned blob
|
|
82
|
+
* contains the existing anchor.
|
|
83
|
+
* - `payment_required`: Present the checkout information to the user,
|
|
84
|
+
* then call {@link finalizeNotarization} after payment completes.
|
|
85
|
+
* - `ready_to_finalize`: Payment was previously completed, so
|
|
86
|
+
* {@link finalizeNotarization} can be called immediately.
|
|
87
|
+
*
|
|
88
|
+
* @param file Sealed file to notarize.
|
|
89
|
+
* @param options Optional MIME type used when reading and updating the file.
|
|
90
|
+
* @returns The current state of the notarization flow.
|
|
91
|
+
* @throws ValidationError When the file is not sealed.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const result = await majikah.notary.initiateNotarization(sealedFile);
|
|
96
|
+
*
|
|
97
|
+
* if (result.status === "payment_required") {
|
|
98
|
+
* showQrCode(result.checkout.checkout_url);
|
|
99
|
+
*
|
|
100
|
+
* // After the user completes payment:
|
|
101
|
+
* const { blob, anchor } =
|
|
102
|
+
* await majikah.notary.finalizeNotarization(
|
|
103
|
+
* sealedFile,
|
|
104
|
+
* result.sealHash,
|
|
105
|
+
* );
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
initiateNotarization(file: FileLike, options?: {
|
|
110
|
+
mimeType?: string;
|
|
111
|
+
}): Promise<InitiateNotarizationResult>;
|
|
112
|
+
/**
|
|
113
|
+
* Completes notarization after payment has been completed.
|
|
114
|
+
*
|
|
115
|
+
* Registers the sealed document's `sealHash`, waits for confirmation when
|
|
116
|
+
* necessary, and embeds the resulting chain anchor back into the file.
|
|
117
|
+
*
|
|
118
|
+
* Call this after {@link initiateNotarization} returns either
|
|
119
|
+
* `payment_required` and the user has paid, or `ready_to_finalize`.
|
|
120
|
+
*
|
|
121
|
+
* @param file Sealed file being notarized.
|
|
122
|
+
* @param sealHash Seal hash returned by {@link initiateNotarization}.
|
|
123
|
+
* @param options MIME type and polling settings.
|
|
124
|
+
* @returns The notarized file and its chain anchor.
|
|
125
|
+
*/
|
|
126
|
+
finalizeNotarization(file: FileLike, sealHash: string, options?: {
|
|
127
|
+
mimeType?: string;
|
|
128
|
+
poll?: PollOptions;
|
|
129
|
+
}): Promise<{
|
|
130
|
+
blob: Blob;
|
|
131
|
+
anchor: MajikChainAnchor;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Seals an already-signed file and starts the notarization flow.
|
|
135
|
+
*
|
|
136
|
+
* Use this when all required signers have already signed the document and
|
|
137
|
+
* the issuer is ready to seal the signature envelope and begin payment.
|
|
138
|
+
*
|
|
139
|
+
* @param file Already-signed file.
|
|
140
|
+
* @param issuerKey Unlocked MajikKey belonging to the issuer sealing the file.
|
|
141
|
+
* @param options MIME type and seal timestamp settings.
|
|
142
|
+
* @returns The current state of the notarization flow.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const result =
|
|
147
|
+
* await majikah.notary.sealAndInitiateNotarization(
|
|
148
|
+
* signedFile,
|
|
149
|
+
* issuerKey,
|
|
150
|
+
* );
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
sealAndInitiateNotarization(file: FileLike, issuerKey: MajikKey, options?: {
|
|
154
|
+
mimeType?: string;
|
|
155
|
+
sealTimestamp?: string;
|
|
156
|
+
}): Promise<InitiateNotarizationResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Signs, seals, and starts notarization for a single-signer document.
|
|
159
|
+
*
|
|
160
|
+
* This is the complete convenience flow for documents where the supplied
|
|
161
|
+
* key is the only signer:
|
|
162
|
+
*
|
|
163
|
+
* `sign → seal → initiate notarization`
|
|
164
|
+
*
|
|
165
|
+
* Sealing makes the envelope immutable to further signatures, so this
|
|
166
|
+
* method should not be used when additional signers still need to sign.
|
|
167
|
+
* For multi-signature documents, have all signers sign first and then use
|
|
168
|
+
* {@link sealAndInitiateNotarization}.
|
|
169
|
+
*
|
|
170
|
+
* @param file File to sign and notarize.
|
|
171
|
+
* @param key Unlocked MajikKey used for both signing and sealing.
|
|
172
|
+
* @param options Signing, MIME type, validity, and sealing settings.
|
|
173
|
+
* @returns The current state of the notarization flow.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const result =
|
|
178
|
+
* await majikah.notary.signSealAndInitiateNotarization(
|
|
179
|
+
* file,
|
|
180
|
+
* aliceKey,
|
|
181
|
+
* {
|
|
182
|
+
* contentType: "application/pdf",
|
|
183
|
+
* },
|
|
184
|
+
* );
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
signSealAndInitiateNotarization(file: FileLike, key: MajikKey, options?: SignSealOptions): Promise<InitiateNotarizationResult>;
|
|
188
|
+
}
|