@majikah/majik-signature 0.0.3 → 0.0.5
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.
|
@@ -63,7 +63,7 @@ export declare class MajikSignatureEmbed {
|
|
|
63
63
|
*/
|
|
64
64
|
static verify(file: Blob, publicKeys: MajikSignerPublicKeys, MajikSig: MajikSignatureStaticAdapter, options?: ExtractOptions & {
|
|
65
65
|
expectedSignerId?: string;
|
|
66
|
-
}): Promise<EmbedVerifyResult>;
|
|
66
|
+
}, debug?: boolean): Promise<EmbedVerifyResult>;
|
|
67
67
|
/**
|
|
68
68
|
* Verify using a MajikKey instance instead of raw public keys.
|
|
69
69
|
* Called from MajikSignature.verifyFile() — MajikSig passed to avoid
|
|
@@ -71,7 +71,7 @@ export declare class MajikSignatureEmbed {
|
|
|
71
71
|
*/
|
|
72
72
|
static verifyWithKey(file: Blob, key: MajikKey, MajikSig: MajikSignatureStaticAdapter, options?: ExtractOptions & {
|
|
73
73
|
expectedSignerId?: string;
|
|
74
|
-
}): Promise<EmbedVerifyResult>;
|
|
74
|
+
}, debug?: boolean): Promise<EmbedVerifyResult>;
|
|
75
75
|
/**
|
|
76
76
|
* Return a clean copy of the file with any embedded signature removed.
|
|
77
77
|
*/
|
|
@@ -28,6 +28,7 @@ import { MkvHandler } from "./handlers/mkv";
|
|
|
28
28
|
import { OfficeHandler } from "./handlers/office";
|
|
29
29
|
import { TextHandler } from "./handlers/text";
|
|
30
30
|
import { FallbackHandler } from "./fallback";
|
|
31
|
+
import { bytesToBase64, hashContent } from "../hash";
|
|
31
32
|
// ─── Registry ─────────────────────────────────────────────────────────────────
|
|
32
33
|
const DEFAULT_REGISTRY = new FormatHandlerRegistry()
|
|
33
34
|
.register(new PdfHandler())
|
|
@@ -105,12 +106,14 @@ export class MajikSignatureEmbed {
|
|
|
105
106
|
* Requires the MajikSignature static class passed in as `MajikSig` to
|
|
106
107
|
* avoid a circular import. Called from MajikSignature.verifyFile().
|
|
107
108
|
*/
|
|
108
|
-
static async verify(file, publicKeys, MajikSig, options) {
|
|
109
|
+
static async verify(file, publicKeys, MajikSig, options, debug = false) {
|
|
109
110
|
const bytes = await blobToBytes(file);
|
|
110
111
|
const mimeType = options?.mimeType ?? detectMimeType(bytes, file.type);
|
|
111
112
|
const handler = DEFAULT_REGISTRY.resolve(bytes, mimeType);
|
|
112
113
|
const signatureJson = await handler.extract(bytes);
|
|
113
114
|
if (!signatureJson) {
|
|
115
|
+
if (debug)
|
|
116
|
+
console.error("No embedded signature found");
|
|
114
117
|
return {
|
|
115
118
|
valid: false,
|
|
116
119
|
reason: "No embedded signature found",
|
|
@@ -129,6 +132,12 @@ export class MajikSignatureEmbed {
|
|
|
129
132
|
};
|
|
130
133
|
}
|
|
131
134
|
const originalBytes = await handler.strip(bytes);
|
|
135
|
+
if (debug) {
|
|
136
|
+
const recomputedHash = bytesToBase64(hashContent(originalBytes));
|
|
137
|
+
console.log("Verify-side hash:", recomputedHash);
|
|
138
|
+
console.log("Embedded hash: ", parsedSig.contentHash);
|
|
139
|
+
console.log("match:", recomputedHash === parsedSig.contentHash);
|
|
140
|
+
}
|
|
132
141
|
if (options?.expectedSignerId &&
|
|
133
142
|
parsedSig.signerId !== options.expectedSignerId) {
|
|
134
143
|
return {
|
|
@@ -146,9 +155,9 @@ export class MajikSignatureEmbed {
|
|
|
146
155
|
* Called from MajikSignature.verifyFile() — MajikSig passed to avoid
|
|
147
156
|
* circular import.
|
|
148
157
|
*/
|
|
149
|
-
static async verifyWithKey(file, key, MajikSig, options) {
|
|
158
|
+
static async verifyWithKey(file, key, MajikSig, options, debug = false) {
|
|
150
159
|
const publicKeys = MajikSig.publicKeysFromMajikKey(key);
|
|
151
|
-
return MajikSignatureEmbed.verify(file, publicKeys, MajikSig, options);
|
|
160
|
+
return MajikSignatureEmbed.verify(file, publicKeys, MajikSig, options, debug);
|
|
152
161
|
}
|
|
153
162
|
/**
|
|
154
163
|
* Return a clean copy of the file with any embedded signature removed.
|
|
@@ -142,7 +142,7 @@ export declare class MajikSignature {
|
|
|
142
142
|
static verifyFile(file: Blob, keyOrPublicKeys: MajikKey | MajikSignerPublicKeys, options?: {
|
|
143
143
|
expectedSignerId?: string;
|
|
144
144
|
mimeType?: string;
|
|
145
|
-
}): Promise<VerificationResult & {
|
|
145
|
+
}, debug?: boolean): Promise<VerificationResult & {
|
|
146
146
|
handler?: string;
|
|
147
147
|
}>;
|
|
148
148
|
/**
|
package/dist/majik-signature.js
CHANGED
|
@@ -410,13 +410,17 @@ export class MajikSignature {
|
|
|
410
410
|
* const result = await MajikSignature.verifyFile(signedBlob, key);
|
|
411
411
|
* if (result.valid) console.log("Signed by", result.signerId);
|
|
412
412
|
*/
|
|
413
|
-
static async verifyFile(file, keyOrPublicKeys, options) {
|
|
413
|
+
static async verifyFile(file, keyOrPublicKeys, options, debug = false) {
|
|
414
414
|
if (MajikSignature._isMajikKey(keyOrPublicKeys)) {
|
|
415
|
+
if (debug)
|
|
416
|
+
console.log("Verifying with MajikKey");
|
|
415
417
|
return MajikSignatureEmbed.verifyWithKey(file, keyOrPublicKeys, MajikSignature, // ← adapter
|
|
416
|
-
options);
|
|
418
|
+
options, debug);
|
|
417
419
|
}
|
|
420
|
+
if (debug)
|
|
421
|
+
console.log("Verifying with public keys");
|
|
418
422
|
return MajikSignatureEmbed.verify(file, keyOrPublicKeys, MajikSignature, // ← adapter
|
|
419
|
-
options);
|
|
423
|
+
options, debug);
|
|
420
424
|
}
|
|
421
425
|
/**
|
|
422
426
|
* Embed this MajikSignature instance into a file.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@majikah/majik-signature",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Majik Signature is a hybrid post-quantum content signing and verification library for the Majikah ecosystem. Built on top of Majik Key, it provides tamper-proof, forgery-resistant digital signatures for any content format — using a dual-algorithm architecture that combines classical Ed25519 with post-quantum ML-DSA-87 (FIPS-204).",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.5",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": "Zelijah",
|
|
8
8
|
"main": "./dist/index.js",
|