mdenc 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 +15 -0
- package/README.md +141 -0
- package/dist/chunk-FFRUPAVV.js +669 -0
- package/dist/chunk-FFRUPAVV.js.map +1 -0
- package/dist/cli.js +548 -0
- package/dist/cli.js.map +1 -0
- package/dist/hooks-ZO2DIE5U.js +16 -0
- package/dist/hooks-ZO2DIE5U.js.map +1 -0
- package/dist/index.cjs +455 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +424 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface ScryptParams {
|
|
2
|
+
N: number;
|
|
3
|
+
r: number;
|
|
4
|
+
p: number;
|
|
5
|
+
}
|
|
6
|
+
declare const DEFAULT_SCRYPT_PARAMS: ScryptParams;
|
|
7
|
+
interface MdencHeader {
|
|
8
|
+
version: 'v1';
|
|
9
|
+
salt: Uint8Array;
|
|
10
|
+
fileId: Uint8Array;
|
|
11
|
+
scrypt: ScryptParams;
|
|
12
|
+
}
|
|
13
|
+
interface MdencChunk {
|
|
14
|
+
payload: Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
interface MdencFile {
|
|
17
|
+
header: MdencHeader;
|
|
18
|
+
headerLine: string;
|
|
19
|
+
headerHmac: Uint8Array;
|
|
20
|
+
chunks: MdencChunk[];
|
|
21
|
+
sealHmac: Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
declare enum ChunkingStrategy {
|
|
24
|
+
Paragraph = "paragraph",
|
|
25
|
+
FixedSize = "fixed-size"
|
|
26
|
+
}
|
|
27
|
+
interface EncryptOptions {
|
|
28
|
+
chunking?: ChunkingStrategy;
|
|
29
|
+
maxChunkSize?: number;
|
|
30
|
+
fixedChunkSize?: number;
|
|
31
|
+
scrypt?: ScryptParams;
|
|
32
|
+
previousFile?: string;
|
|
33
|
+
}
|
|
34
|
+
interface DecryptOptions {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare function encrypt(plaintext: string, password: string, options?: EncryptOptions): Promise<string>;
|
|
38
|
+
declare function decrypt(fileContent: string, password: string): Promise<string>;
|
|
39
|
+
|
|
40
|
+
declare function verifySeal(fileContent: string, password: string): Promise<boolean>;
|
|
41
|
+
|
|
42
|
+
export { ChunkingStrategy, DEFAULT_SCRYPT_PARAMS, type DecryptOptions, type EncryptOptions, type MdencChunk, type MdencFile, type MdencHeader, type ScryptParams, decrypt, encrypt, verifySeal };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface ScryptParams {
|
|
2
|
+
N: number;
|
|
3
|
+
r: number;
|
|
4
|
+
p: number;
|
|
5
|
+
}
|
|
6
|
+
declare const DEFAULT_SCRYPT_PARAMS: ScryptParams;
|
|
7
|
+
interface MdencHeader {
|
|
8
|
+
version: 'v1';
|
|
9
|
+
salt: Uint8Array;
|
|
10
|
+
fileId: Uint8Array;
|
|
11
|
+
scrypt: ScryptParams;
|
|
12
|
+
}
|
|
13
|
+
interface MdencChunk {
|
|
14
|
+
payload: Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
interface MdencFile {
|
|
17
|
+
header: MdencHeader;
|
|
18
|
+
headerLine: string;
|
|
19
|
+
headerHmac: Uint8Array;
|
|
20
|
+
chunks: MdencChunk[];
|
|
21
|
+
sealHmac: Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
declare enum ChunkingStrategy {
|
|
24
|
+
Paragraph = "paragraph",
|
|
25
|
+
FixedSize = "fixed-size"
|
|
26
|
+
}
|
|
27
|
+
interface EncryptOptions {
|
|
28
|
+
chunking?: ChunkingStrategy;
|
|
29
|
+
maxChunkSize?: number;
|
|
30
|
+
fixedChunkSize?: number;
|
|
31
|
+
scrypt?: ScryptParams;
|
|
32
|
+
previousFile?: string;
|
|
33
|
+
}
|
|
34
|
+
interface DecryptOptions {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare function encrypt(plaintext: string, password: string, options?: EncryptOptions): Promise<string>;
|
|
38
|
+
declare function decrypt(fileContent: string, password: string): Promise<string>;
|
|
39
|
+
|
|
40
|
+
declare function verifySeal(fileContent: string, password: string): Promise<boolean>;
|
|
41
|
+
|
|
42
|
+
export { ChunkingStrategy, DEFAULT_SCRYPT_PARAMS, type DecryptOptions, type EncryptOptions, type MdencChunk, type MdencFile, type MdencHeader, type ScryptParams, decrypt, encrypt, verifySeal };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var DEFAULT_SCRYPT_PARAMS = {
|
|
3
|
+
N: 16384,
|
|
4
|
+
r: 8,
|
|
5
|
+
p: 1
|
|
6
|
+
};
|
|
7
|
+
var SCRYPT_BOUNDS = {
|
|
8
|
+
N: { min: 1024, max: 1048576 },
|
|
9
|
+
// 2^10 – 2^20
|
|
10
|
+
r: { min: 1, max: 64 },
|
|
11
|
+
p: { min: 1, max: 16 }
|
|
12
|
+
};
|
|
13
|
+
var ChunkingStrategy = /* @__PURE__ */ ((ChunkingStrategy2) => {
|
|
14
|
+
ChunkingStrategy2["Paragraph"] = "paragraph";
|
|
15
|
+
ChunkingStrategy2["FixedSize"] = "fixed-size";
|
|
16
|
+
return ChunkingStrategy2;
|
|
17
|
+
})(ChunkingStrategy || {});
|
|
18
|
+
|
|
19
|
+
// src/encrypt.ts
|
|
20
|
+
import { hmac as hmac3 } from "@noble/hashes/hmac";
|
|
21
|
+
import { sha256 as sha2564 } from "@noble/hashes/sha256";
|
|
22
|
+
|
|
23
|
+
// src/chunking.ts
|
|
24
|
+
var DEFAULT_MAX_CHUNK_SIZE = 65536;
|
|
25
|
+
function chunkByParagraph(text, maxSize = DEFAULT_MAX_CHUNK_SIZE) {
|
|
26
|
+
const normalized = text.replace(/\r\n/g, "\n");
|
|
27
|
+
if (normalized.length === 0) {
|
|
28
|
+
return [""];
|
|
29
|
+
}
|
|
30
|
+
const chunks = [];
|
|
31
|
+
const boundary = /\n{2,}/g;
|
|
32
|
+
let lastEnd = 0;
|
|
33
|
+
let match;
|
|
34
|
+
while ((match = boundary.exec(normalized)) !== null) {
|
|
35
|
+
const chunkEnd = match.index + match[0].length;
|
|
36
|
+
chunks.push(normalized.slice(lastEnd, chunkEnd));
|
|
37
|
+
lastEnd = chunkEnd;
|
|
38
|
+
}
|
|
39
|
+
if (lastEnd < normalized.length) {
|
|
40
|
+
chunks.push(normalized.slice(lastEnd));
|
|
41
|
+
} else if (chunks.length === 0) {
|
|
42
|
+
chunks.push(normalized);
|
|
43
|
+
}
|
|
44
|
+
const result = [];
|
|
45
|
+
for (const chunk of chunks) {
|
|
46
|
+
if (byteLength(chunk) <= maxSize) {
|
|
47
|
+
result.push(chunk);
|
|
48
|
+
} else {
|
|
49
|
+
result.push(...splitAtByteLimit(chunk, maxSize));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
function chunkByFixedSize(text, size) {
|
|
55
|
+
const normalized = text.replace(/\r\n/g, "\n");
|
|
56
|
+
if (normalized.length === 0) {
|
|
57
|
+
return [""];
|
|
58
|
+
}
|
|
59
|
+
const bytes = new TextEncoder().encode(normalized);
|
|
60
|
+
if (bytes.length <= size) {
|
|
61
|
+
return [normalized];
|
|
62
|
+
}
|
|
63
|
+
const chunks = [];
|
|
64
|
+
const decoder = new TextDecoder();
|
|
65
|
+
let offset = 0;
|
|
66
|
+
while (offset < bytes.length) {
|
|
67
|
+
const end = Math.min(offset + size, bytes.length);
|
|
68
|
+
let adjusted = end;
|
|
69
|
+
if (adjusted < bytes.length) {
|
|
70
|
+
while (adjusted > offset && (bytes[adjusted] & 192) === 128) {
|
|
71
|
+
adjusted--;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
chunks.push(decoder.decode(bytes.slice(offset, adjusted)));
|
|
75
|
+
offset = adjusted;
|
|
76
|
+
}
|
|
77
|
+
return chunks;
|
|
78
|
+
}
|
|
79
|
+
function byteLength(s) {
|
|
80
|
+
return new TextEncoder().encode(s).length;
|
|
81
|
+
}
|
|
82
|
+
function splitAtByteLimit(text, maxSize) {
|
|
83
|
+
const bytes = new TextEncoder().encode(text);
|
|
84
|
+
const decoder = new TextDecoder();
|
|
85
|
+
const parts = [];
|
|
86
|
+
let offset = 0;
|
|
87
|
+
while (offset < bytes.length) {
|
|
88
|
+
let end = Math.min(offset + maxSize, bytes.length);
|
|
89
|
+
if (end < bytes.length) {
|
|
90
|
+
while (end > offset && (bytes[end] & 192) === 128) {
|
|
91
|
+
end--;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
parts.push(decoder.decode(bytes.slice(offset, end)));
|
|
95
|
+
offset = end;
|
|
96
|
+
}
|
|
97
|
+
return parts;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/kdf.ts
|
|
101
|
+
import { hkdf } from "@noble/hashes/hkdf";
|
|
102
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
103
|
+
import { scrypt } from "@noble/hashes/scrypt";
|
|
104
|
+
|
|
105
|
+
// src/crypto-utils.ts
|
|
106
|
+
function constantTimeEqual(a, b) {
|
|
107
|
+
if (a.length !== b.length) return false;
|
|
108
|
+
let diff = 0;
|
|
109
|
+
for (let i = 0; i < a.length; i++) {
|
|
110
|
+
diff |= a[i] ^ b[i];
|
|
111
|
+
}
|
|
112
|
+
return diff === 0;
|
|
113
|
+
}
|
|
114
|
+
function zeroize(...arrays) {
|
|
115
|
+
for (const arr of arrays) {
|
|
116
|
+
arr.fill(0);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/kdf.ts
|
|
121
|
+
var ENC_INFO = new TextEncoder().encode("mdenc-v1-enc");
|
|
122
|
+
var HDR_INFO = new TextEncoder().encode("mdenc-v1-hdr");
|
|
123
|
+
var NONCE_INFO = new TextEncoder().encode("mdenc-v1-nonce");
|
|
124
|
+
function normalizePassword(password) {
|
|
125
|
+
const normalized = password.normalize("NFKC");
|
|
126
|
+
return new TextEncoder().encode(normalized);
|
|
127
|
+
}
|
|
128
|
+
function deriveMasterKey(password, salt, params = DEFAULT_SCRYPT_PARAMS) {
|
|
129
|
+
const passwordBytes = normalizePassword(password);
|
|
130
|
+
try {
|
|
131
|
+
return scrypt(passwordBytes, salt, {
|
|
132
|
+
N: params.N,
|
|
133
|
+
r: params.r,
|
|
134
|
+
p: params.p,
|
|
135
|
+
dkLen: 32
|
|
136
|
+
});
|
|
137
|
+
} finally {
|
|
138
|
+
zeroize(passwordBytes);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function deriveKeys(masterKey) {
|
|
142
|
+
const encKey = hkdf(sha256, masterKey, void 0, ENC_INFO, 32);
|
|
143
|
+
const headerKey = hkdf(sha256, masterKey, void 0, HDR_INFO, 32);
|
|
144
|
+
const nonceKey = hkdf(sha256, masterKey, void 0, NONCE_INFO, 32);
|
|
145
|
+
return { encKey, headerKey, nonceKey };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/aead.ts
|
|
149
|
+
import { xchacha20poly1305 } from "@noble/ciphers/chacha";
|
|
150
|
+
import { hmac } from "@noble/hashes/hmac";
|
|
151
|
+
import { sha256 as sha2562 } from "@noble/hashes/sha256";
|
|
152
|
+
var NONCE_LENGTH = 24;
|
|
153
|
+
function buildAAD(fileId) {
|
|
154
|
+
const fileIdHex = bytesToHex(fileId);
|
|
155
|
+
const aadString = `mdenc:v1
|
|
156
|
+
${fileIdHex}`;
|
|
157
|
+
return new TextEncoder().encode(aadString);
|
|
158
|
+
}
|
|
159
|
+
function deriveNonce(nonceKey, plaintext) {
|
|
160
|
+
const full = hmac(sha2562, nonceKey, plaintext);
|
|
161
|
+
return full.slice(0, NONCE_LENGTH);
|
|
162
|
+
}
|
|
163
|
+
function encryptChunk(encKey, nonceKey, plaintext, fileId) {
|
|
164
|
+
const nonce = deriveNonce(nonceKey, plaintext);
|
|
165
|
+
const aad = buildAAD(fileId);
|
|
166
|
+
const cipher = xchacha20poly1305(encKey, nonce, aad);
|
|
167
|
+
const ciphertext = cipher.encrypt(plaintext);
|
|
168
|
+
const result = new Uint8Array(NONCE_LENGTH + ciphertext.length);
|
|
169
|
+
result.set(nonce, 0);
|
|
170
|
+
result.set(ciphertext, NONCE_LENGTH);
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
function decryptChunk(encKey, payload, fileId) {
|
|
174
|
+
if (payload.length < NONCE_LENGTH + 16) {
|
|
175
|
+
throw new Error("Chunk payload too short");
|
|
176
|
+
}
|
|
177
|
+
const nonce = payload.slice(0, NONCE_LENGTH);
|
|
178
|
+
const ciphertext = payload.slice(NONCE_LENGTH);
|
|
179
|
+
const aad = buildAAD(fileId);
|
|
180
|
+
const cipher = xchacha20poly1305(encKey, nonce, aad);
|
|
181
|
+
try {
|
|
182
|
+
return cipher.decrypt(ciphertext);
|
|
183
|
+
} catch {
|
|
184
|
+
throw new Error("Chunk authentication failed");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function bytesToHex(bytes) {
|
|
188
|
+
let hex = "";
|
|
189
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
190
|
+
hex += bytes[i].toString(16).padStart(2, "0");
|
|
191
|
+
}
|
|
192
|
+
return hex;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/header.ts
|
|
196
|
+
import { hmac as hmac2 } from "@noble/hashes/hmac";
|
|
197
|
+
import { sha256 as sha2563 } from "@noble/hashes/sha256";
|
|
198
|
+
import { randomBytes } from "@noble/ciphers/webcrypto";
|
|
199
|
+
function generateSalt() {
|
|
200
|
+
return randomBytes(16);
|
|
201
|
+
}
|
|
202
|
+
function generateFileId() {
|
|
203
|
+
return randomBytes(16);
|
|
204
|
+
}
|
|
205
|
+
function serializeHeader(header) {
|
|
206
|
+
const saltB64 = toBase64(header.salt);
|
|
207
|
+
const fileIdB64 = toBase64(header.fileId);
|
|
208
|
+
const { N, r, p } = header.scrypt;
|
|
209
|
+
return `mdenc:v1 salt_b64=${saltB64} file_id_b64=${fileIdB64} scrypt=N=${N},r=${r},p=${p}`;
|
|
210
|
+
}
|
|
211
|
+
function parseHeader(line) {
|
|
212
|
+
if (!line.startsWith("mdenc:v1 ")) {
|
|
213
|
+
throw new Error("Invalid header: missing mdenc:v1 prefix");
|
|
214
|
+
}
|
|
215
|
+
const saltMatch = line.match(/salt_b64=([A-Za-z0-9+/=]+)/);
|
|
216
|
+
if (!saltMatch) throw new Error("Invalid header: missing salt_b64");
|
|
217
|
+
const salt = fromBase64(saltMatch[1]);
|
|
218
|
+
if (salt.length !== 16) throw new Error("Invalid header: salt must be 16 bytes");
|
|
219
|
+
const fileIdMatch = line.match(/file_id_b64=([A-Za-z0-9+/=]+)/);
|
|
220
|
+
if (!fileIdMatch) throw new Error("Invalid header: missing file_id_b64");
|
|
221
|
+
const fileId = fromBase64(fileIdMatch[1]);
|
|
222
|
+
if (fileId.length !== 16) throw new Error("Invalid header: file_id must be 16 bytes");
|
|
223
|
+
const scryptMatch = line.match(/scrypt=N=(\d+),r=(\d+),p=(\d+)/);
|
|
224
|
+
if (!scryptMatch) throw new Error("Invalid header: missing scrypt parameters");
|
|
225
|
+
const scryptParams = {
|
|
226
|
+
N: parseInt(scryptMatch[1], 10),
|
|
227
|
+
r: parseInt(scryptMatch[2], 10),
|
|
228
|
+
p: parseInt(scryptMatch[3], 10)
|
|
229
|
+
};
|
|
230
|
+
validateScryptParams(scryptParams);
|
|
231
|
+
return { version: "v1", salt, fileId, scrypt: scryptParams };
|
|
232
|
+
}
|
|
233
|
+
function validateScryptParams(params) {
|
|
234
|
+
const { N, r, p } = SCRYPT_BOUNDS;
|
|
235
|
+
if (params.N < N.min || params.N > N.max) {
|
|
236
|
+
throw new Error(`Invalid scrypt N: ${params.N} (must be ${N.min}\u2013${N.max})`);
|
|
237
|
+
}
|
|
238
|
+
if (params.r < r.min || params.r > r.max) {
|
|
239
|
+
throw new Error(`Invalid scrypt r: ${params.r} (must be ${r.min}\u2013${r.max})`);
|
|
240
|
+
}
|
|
241
|
+
if (params.p < p.min || params.p > p.max) {
|
|
242
|
+
throw new Error(`Invalid scrypt p: ${params.p} (must be ${p.min}\u2013${p.max})`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function authenticateHeader(headerKey, headerLine) {
|
|
246
|
+
const headerBytes = new TextEncoder().encode(headerLine);
|
|
247
|
+
return hmac2(sha2563, headerKey, headerBytes);
|
|
248
|
+
}
|
|
249
|
+
function verifyHeader(headerKey, headerLine, hmacBytes) {
|
|
250
|
+
const computed = authenticateHeader(headerKey, headerLine);
|
|
251
|
+
return constantTimeEqual(computed, hmacBytes);
|
|
252
|
+
}
|
|
253
|
+
function toBase64(bytes) {
|
|
254
|
+
return Buffer.from(bytes).toString("base64");
|
|
255
|
+
}
|
|
256
|
+
function fromBase64(b64) {
|
|
257
|
+
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// src/encrypt.ts
|
|
261
|
+
async function encrypt(plaintext, password, options) {
|
|
262
|
+
const chunking = options?.chunking ?? "paragraph" /* Paragraph */;
|
|
263
|
+
const maxChunkSize = options?.maxChunkSize ?? 65536;
|
|
264
|
+
const scryptParams = options?.scrypt ?? DEFAULT_SCRYPT_PARAMS;
|
|
265
|
+
let chunks;
|
|
266
|
+
if (chunking === "fixed-size" /* FixedSize */) {
|
|
267
|
+
const fixedSize = options?.fixedChunkSize ?? 4096;
|
|
268
|
+
chunks = chunkByFixedSize(plaintext, fixedSize);
|
|
269
|
+
} else {
|
|
270
|
+
chunks = chunkByParagraph(plaintext, maxChunkSize);
|
|
271
|
+
}
|
|
272
|
+
let salt;
|
|
273
|
+
let fileId;
|
|
274
|
+
let masterKey;
|
|
275
|
+
const prev = options?.previousFile ? parsePreviousFileHeader(options.previousFile, password) : void 0;
|
|
276
|
+
if (prev) {
|
|
277
|
+
salt = prev.salt;
|
|
278
|
+
fileId = prev.fileId;
|
|
279
|
+
masterKey = prev.masterKey;
|
|
280
|
+
} else {
|
|
281
|
+
salt = generateSalt();
|
|
282
|
+
fileId = generateFileId();
|
|
283
|
+
masterKey = deriveMasterKey(password, salt, scryptParams);
|
|
284
|
+
}
|
|
285
|
+
const { encKey, headerKey, nonceKey } = deriveKeys(masterKey);
|
|
286
|
+
try {
|
|
287
|
+
const header = { version: "v1", salt, fileId, scrypt: scryptParams };
|
|
288
|
+
const headerLine = serializeHeader(header);
|
|
289
|
+
const headerHmac = authenticateHeader(headerKey, headerLine);
|
|
290
|
+
const headerAuthLine = `hdrauth_b64=${toBase64(headerHmac)}`;
|
|
291
|
+
const chunkLines = [];
|
|
292
|
+
for (const chunkText of chunks) {
|
|
293
|
+
const chunkBytes = new TextEncoder().encode(chunkText);
|
|
294
|
+
const payload = encryptChunk(encKey, nonceKey, chunkBytes, fileId);
|
|
295
|
+
chunkLines.push(toBase64(payload));
|
|
296
|
+
}
|
|
297
|
+
const sealInput = headerLine + "\n" + headerAuthLine + "\n" + chunkLines.join("\n");
|
|
298
|
+
const sealData = new TextEncoder().encode(sealInput);
|
|
299
|
+
const sealHmac = hmac3(sha2564, headerKey, sealData);
|
|
300
|
+
const sealLine = `seal_b64=${toBase64(sealHmac)}`;
|
|
301
|
+
return [headerLine, headerAuthLine, ...chunkLines, sealLine, ""].join("\n");
|
|
302
|
+
} finally {
|
|
303
|
+
zeroize(masterKey, encKey, headerKey, nonceKey);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async function decrypt(fileContent, password) {
|
|
307
|
+
const lines = fileContent.split("\n");
|
|
308
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
309
|
+
lines.pop();
|
|
310
|
+
}
|
|
311
|
+
if (lines.length < 3) {
|
|
312
|
+
throw new Error("Invalid mdenc file: too few lines");
|
|
313
|
+
}
|
|
314
|
+
const headerLine = lines[0];
|
|
315
|
+
const header = parseHeader(headerLine);
|
|
316
|
+
const authLine = lines[1];
|
|
317
|
+
const authMatch = authLine.match(/^hdrauth_b64=([A-Za-z0-9+/=]+)$/);
|
|
318
|
+
if (!authMatch) {
|
|
319
|
+
throw new Error("Invalid mdenc file: missing hdrauth_b64 line");
|
|
320
|
+
}
|
|
321
|
+
const headerHmac = fromBase64(authMatch[1]);
|
|
322
|
+
const masterKey = deriveMasterKey(password, header.salt, header.scrypt);
|
|
323
|
+
const { encKey, headerKey, nonceKey } = deriveKeys(masterKey);
|
|
324
|
+
try {
|
|
325
|
+
if (!verifyHeader(headerKey, headerLine, headerHmac)) {
|
|
326
|
+
throw new Error("Header authentication failed (wrong password or tampered header)");
|
|
327
|
+
}
|
|
328
|
+
const remaining = lines.slice(2);
|
|
329
|
+
const sealIndex = remaining.findIndex((l) => l.startsWith("seal_b64="));
|
|
330
|
+
if (sealIndex < 0) {
|
|
331
|
+
throw new Error("Invalid mdenc file: missing seal");
|
|
332
|
+
}
|
|
333
|
+
const chunkLines = remaining.slice(0, sealIndex);
|
|
334
|
+
if (chunkLines.length === 0) {
|
|
335
|
+
throw new Error("Invalid mdenc file: no chunk lines");
|
|
336
|
+
}
|
|
337
|
+
const sealMatch = remaining[sealIndex].match(/^seal_b64=([A-Za-z0-9+/=]+)$/);
|
|
338
|
+
if (!sealMatch) throw new Error("Invalid mdenc file: malformed seal line");
|
|
339
|
+
const storedSealHmac = fromBase64(sealMatch[1]);
|
|
340
|
+
const sealInput = headerLine + "\n" + authLine + "\n" + chunkLines.join("\n");
|
|
341
|
+
const sealData = new TextEncoder().encode(sealInput);
|
|
342
|
+
const computedSealHmac = hmac3(sha2564, headerKey, sealData);
|
|
343
|
+
if (!constantTimeEqual(computedSealHmac, storedSealHmac)) {
|
|
344
|
+
throw new Error("Seal verification failed (file tampered or chunks reordered)");
|
|
345
|
+
}
|
|
346
|
+
const plaintextParts = [];
|
|
347
|
+
for (const line of chunkLines) {
|
|
348
|
+
const payload = fromBase64(line);
|
|
349
|
+
const decrypted = decryptChunk(encKey, payload, header.fileId);
|
|
350
|
+
plaintextParts.push(new TextDecoder().decode(decrypted));
|
|
351
|
+
}
|
|
352
|
+
return plaintextParts.join("");
|
|
353
|
+
} finally {
|
|
354
|
+
zeroize(masterKey, encKey, headerKey, nonceKey);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function parsePreviousFileHeader(fileContent, password) {
|
|
358
|
+
try {
|
|
359
|
+
const lines = fileContent.split("\n");
|
|
360
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
361
|
+
if (lines.length < 3) return void 0;
|
|
362
|
+
const headerLine = lines[0];
|
|
363
|
+
const header = parseHeader(headerLine);
|
|
364
|
+
const authLine = lines[1];
|
|
365
|
+
const authMatch = authLine.match(/^hdrauth_b64=([A-Za-z0-9+/=]+)$/);
|
|
366
|
+
if (!authMatch) return void 0;
|
|
367
|
+
const headerHmac = fromBase64(authMatch[1]);
|
|
368
|
+
const masterKey = deriveMasterKey(password, header.salt, header.scrypt);
|
|
369
|
+
const { headerKey } = deriveKeys(masterKey);
|
|
370
|
+
if (!verifyHeader(headerKey, headerLine, headerHmac)) {
|
|
371
|
+
zeroize(masterKey, headerKey);
|
|
372
|
+
return void 0;
|
|
373
|
+
}
|
|
374
|
+
zeroize(headerKey);
|
|
375
|
+
return { salt: header.salt, fileId: header.fileId, masterKey };
|
|
376
|
+
} catch {
|
|
377
|
+
return void 0;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/seal.ts
|
|
382
|
+
import { hmac as hmac4 } from "@noble/hashes/hmac";
|
|
383
|
+
import { sha256 as sha2565 } from "@noble/hashes/sha256";
|
|
384
|
+
async function verifySeal(fileContent, password) {
|
|
385
|
+
const lines = fileContent.split("\n");
|
|
386
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
387
|
+
if (lines.length < 3) throw new Error("Invalid mdenc file: too few lines");
|
|
388
|
+
const headerLine = lines[0];
|
|
389
|
+
const header = parseHeader(headerLine);
|
|
390
|
+
const authLine = lines[1];
|
|
391
|
+
const authMatch = authLine.match(/^hdrauth_b64=([A-Za-z0-9+/=]+)$/);
|
|
392
|
+
if (!authMatch) throw new Error("Invalid mdenc file: missing hdrauth_b64 line");
|
|
393
|
+
const headerHmac = fromBase64(authMatch[1]);
|
|
394
|
+
const masterKey = deriveMasterKey(password, header.salt, header.scrypt);
|
|
395
|
+
const { headerKey, nonceKey } = deriveKeys(masterKey);
|
|
396
|
+
try {
|
|
397
|
+
if (!verifyHeader(headerKey, headerLine, headerHmac)) {
|
|
398
|
+
throw new Error("Header authentication failed");
|
|
399
|
+
}
|
|
400
|
+
const chunkAndSealLines = lines.slice(2);
|
|
401
|
+
const sealIndex = chunkAndSealLines.findIndex((l) => l.startsWith("seal_b64="));
|
|
402
|
+
if (sealIndex < 0) {
|
|
403
|
+
throw new Error("File is not sealed: no seal_b64 line found");
|
|
404
|
+
}
|
|
405
|
+
const chunkLines = chunkAndSealLines.slice(0, sealIndex);
|
|
406
|
+
const sealMatch = chunkAndSealLines[sealIndex].match(/^seal_b64=([A-Za-z0-9+/=]+)$/);
|
|
407
|
+
if (!sealMatch) throw new Error("Invalid seal line");
|
|
408
|
+
const storedHmac = fromBase64(sealMatch[1]);
|
|
409
|
+
const sealInput = headerLine + "\n" + authLine + "\n" + chunkLines.join("\n");
|
|
410
|
+
const sealData = new TextEncoder().encode(sealInput);
|
|
411
|
+
const computed = hmac4(sha2565, headerKey, sealData);
|
|
412
|
+
return constantTimeEqual(computed, storedHmac);
|
|
413
|
+
} finally {
|
|
414
|
+
zeroize(masterKey, headerKey, nonceKey);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
export {
|
|
418
|
+
ChunkingStrategy,
|
|
419
|
+
DEFAULT_SCRYPT_PARAMS,
|
|
420
|
+
decrypt,
|
|
421
|
+
encrypt,
|
|
422
|
+
verifySeal
|
|
423
|
+
};
|
|
424
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/encrypt.ts","../src/chunking.ts","../src/kdf.ts","../src/crypto-utils.ts","../src/aead.ts","../src/header.ts","../src/seal.ts"],"sourcesContent":["export interface ScryptParams {\n N: number; // CPU/memory cost (default 16384 = 2^14, ~16 MiB with r=8)\n r: number; // block size (default 8)\n p: number; // parallelism (default 1)\n}\n\nexport const DEFAULT_SCRYPT_PARAMS: ScryptParams = {\n N: 16384,\n r: 8,\n p: 1,\n};\n\nexport const SCRYPT_BOUNDS = {\n N: { min: 1024, max: 1048576 }, // 2^10 – 2^20\n r: { min: 1, max: 64 },\n p: { min: 1, max: 16 },\n} as const;\n\nexport interface MdencHeader {\n version: 'v1';\n salt: Uint8Array; // 16 bytes\n fileId: Uint8Array; // 16 bytes\n scrypt: ScryptParams;\n}\n\nexport interface MdencChunk {\n payload: Uint8Array; // nonce || ciphertext || tag\n}\n\nexport interface MdencFile {\n header: MdencHeader;\n headerLine: string;\n headerHmac: Uint8Array;\n chunks: MdencChunk[];\n sealHmac: Uint8Array; // file-level HMAC\n}\n\nexport enum ChunkingStrategy {\n Paragraph = 'paragraph',\n FixedSize = 'fixed-size',\n}\n\nexport interface EncryptOptions {\n chunking?: ChunkingStrategy;\n maxChunkSize?: number; // bytes, default 65536 (64 KiB)\n fixedChunkSize?: number; // bytes, for fixed-size chunking\n scrypt?: ScryptParams;\n previousFile?: string; // previous encrypted file content for ciphertext reuse\n}\n\nexport interface DecryptOptions {\n // Reserved for future options\n}\n","import { hmac } from '@noble/hashes/hmac';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { chunkByParagraph, chunkByFixedSize } from './chunking.js';\nimport { deriveMasterKey, deriveKeys } from './kdf.js';\nimport { encryptChunk, decryptChunk } from './aead.js';\nimport {\n serializeHeader,\n parseHeader,\n authenticateHeader,\n verifyHeader,\n generateSalt,\n generateFileId,\n toBase64,\n fromBase64,\n} from './header.js';\nimport { ChunkingStrategy, DEFAULT_SCRYPT_PARAMS } from './types.js';\nimport type { EncryptOptions, MdencHeader } from './types.js';\nimport { constantTimeEqual, zeroize } from './crypto-utils.js';\n\nexport async function encrypt(\n plaintext: string,\n password: string,\n options?: EncryptOptions,\n): Promise<string> {\n const chunking = options?.chunking ?? ChunkingStrategy.Paragraph;\n const maxChunkSize = options?.maxChunkSize ?? 65536;\n const scryptParams = options?.scrypt ?? DEFAULT_SCRYPT_PARAMS;\n\n // Chunk the plaintext\n let chunks: string[];\n if (chunking === ChunkingStrategy.FixedSize) {\n const fixedSize = options?.fixedChunkSize ?? 4096;\n chunks = chunkByFixedSize(plaintext, fixedSize);\n } else {\n chunks = chunkByParagraph(plaintext, maxChunkSize);\n }\n\n // If previousFile provided, extract salt/fileId/keys from its header to avoid\n // deriving the same master key twice (same password + same salt).\n let salt: Uint8Array;\n let fileId: Uint8Array;\n let masterKey: Uint8Array;\n\n const prev = options?.previousFile\n ? parsePreviousFileHeader(options.previousFile, password)\n : undefined;\n\n if (prev) {\n salt = prev.salt;\n fileId = prev.fileId;\n masterKey = prev.masterKey;\n } else {\n salt = generateSalt();\n fileId = generateFileId();\n masterKey = deriveMasterKey(password, salt, scryptParams);\n }\n\n const { encKey, headerKey, nonceKey } = deriveKeys(masterKey);\n\n try {\n // Build header\n const header: MdencHeader = { version: 'v1', salt, fileId, scrypt: scryptParams };\n const headerLine = serializeHeader(header);\n const headerHmac = authenticateHeader(headerKey, headerLine);\n const headerAuthLine = `hdrauth_b64=${toBase64(headerHmac)}`;\n\n // Encrypt chunks — deterministic encryption handles reuse automatically\n const chunkLines: string[] = [];\n for (const chunkText of chunks) {\n const chunkBytes = new TextEncoder().encode(chunkText);\n const payload = encryptChunk(encKey, nonceKey, chunkBytes, fileId);\n chunkLines.push(toBase64(payload));\n }\n\n // Compute seal HMAC over header + auth + chunk lines\n const sealInput = headerLine + '\\n' + headerAuthLine + '\\n' + chunkLines.join('\\n');\n const sealData = new TextEncoder().encode(sealInput);\n const sealHmac = hmac(sha256, headerKey, sealData);\n const sealLine = `seal_b64=${toBase64(sealHmac)}`;\n\n return [headerLine, headerAuthLine, ...chunkLines, sealLine, ''].join('\\n');\n } finally {\n zeroize(masterKey, encKey, headerKey, nonceKey);\n }\n}\n\nexport async function decrypt(\n fileContent: string,\n password: string,\n): Promise<string> {\n const lines = fileContent.split('\\n');\n\n // Remove trailing empty line if present\n if (lines.length > 0 && lines[lines.length - 1] === '') {\n lines.pop();\n }\n\n if (lines.length < 3) {\n throw new Error('Invalid mdenc file: too few lines');\n }\n\n // Parse header\n const headerLine = lines[0];\n const header = parseHeader(headerLine);\n\n // Parse header auth\n const authLine = lines[1];\n const authMatch = authLine.match(/^hdrauth_b64=([A-Za-z0-9+/=]+)$/);\n if (!authMatch) {\n throw new Error('Invalid mdenc file: missing hdrauth_b64 line');\n }\n const headerHmac = fromBase64(authMatch[1]);\n\n // Derive keys\n const masterKey = deriveMasterKey(password, header.salt, header.scrypt);\n const { encKey, headerKey, nonceKey } = deriveKeys(masterKey);\n\n try {\n // Verify header HMAC\n if (!verifyHeader(headerKey, headerLine, headerHmac)) {\n throw new Error('Header authentication failed (wrong password or tampered header)');\n }\n\n // Collect chunk lines and seal line\n const remaining = lines.slice(2);\n const sealIndex = remaining.findIndex(l => l.startsWith('seal_b64='));\n if (sealIndex < 0) {\n throw new Error('Invalid mdenc file: missing seal');\n }\n\n const chunkLines = remaining.slice(0, sealIndex);\n if (chunkLines.length === 0) {\n throw new Error('Invalid mdenc file: no chunk lines');\n }\n\n // Verify seal HMAC\n const sealMatch = remaining[sealIndex].match(/^seal_b64=([A-Za-z0-9+/=]+)$/);\n if (!sealMatch) throw new Error('Invalid mdenc file: malformed seal line');\n const storedSealHmac = fromBase64(sealMatch[1]);\n\n const sealInput = headerLine + '\\n' + authLine + '\\n' + chunkLines.join('\\n');\n const sealData = new TextEncoder().encode(sealInput);\n const computedSealHmac = hmac(sha256, headerKey, sealData);\n if (!constantTimeEqual(computedSealHmac, storedSealHmac)) {\n throw new Error('Seal verification failed (file tampered or chunks reordered)');\n }\n\n // Decrypt chunks\n const plaintextParts: string[] = [];\n for (const line of chunkLines) {\n const payload = fromBase64(line);\n const decrypted = decryptChunk(encKey, payload, header.fileId);\n plaintextParts.push(new TextDecoder().decode(decrypted));\n }\n\n return plaintextParts.join('');\n } finally {\n zeroize(masterKey, encKey, headerKey, nonceKey);\n }\n}\n\nfunction parsePreviousFileHeader(\n fileContent: string,\n password: string,\n): { salt: Uint8Array; fileId: Uint8Array; masterKey: Uint8Array } | undefined {\n try {\n const lines = fileContent.split('\\n');\n if (lines.length > 0 && lines[lines.length - 1] === '') lines.pop();\n if (lines.length < 3) return undefined;\n\n const headerLine = lines[0];\n const header = parseHeader(headerLine);\n\n // Parse and verify header HMAC before trusting\n const authLine = lines[1];\n const authMatch = authLine.match(/^hdrauth_b64=([A-Za-z0-9+/=]+)$/);\n if (!authMatch) return undefined;\n const headerHmac = fromBase64(authMatch[1]);\n\n const masterKey = deriveMasterKey(password, header.salt, header.scrypt);\n const { headerKey } = deriveKeys(masterKey);\n\n if (!verifyHeader(headerKey, headerLine, headerHmac)) {\n zeroize(masterKey, headerKey);\n return undefined;\n }\n\n zeroize(headerKey);\n // Return masterKey for reuse — same password + same salt produces the same key,\n // so the caller can skip a redundant scrypt derivation.\n return { salt: header.salt, fileId: header.fileId, masterKey };\n } catch {\n return undefined;\n }\n}\n","const DEFAULT_MAX_CHUNK_SIZE = 65536; // 64 KiB\n\nexport function chunkByParagraph(text: string, maxSize = DEFAULT_MAX_CHUNK_SIZE): string[] {\n // Normalize line endings\n const normalized = text.replace(/\\r\\n/g, '\\n');\n\n if (normalized.length === 0) {\n return [''];\n }\n\n // Split on runs of 2+ newlines, attaching each boundary to the preceding chunk\n const chunks: string[] = [];\n const boundary = /\\n{2,}/g;\n let lastEnd = 0;\n let match: RegExpExecArray | null;\n\n while ((match = boundary.exec(normalized)) !== null) {\n // Content up to and including the boundary goes to the preceding chunk\n const chunkEnd = match.index + match[0].length;\n chunks.push(normalized.slice(lastEnd, chunkEnd));\n lastEnd = chunkEnd;\n }\n\n // Remaining content after the last boundary (or the entire string if no boundary)\n if (lastEnd < normalized.length) {\n chunks.push(normalized.slice(lastEnd));\n } else if (chunks.length === 0) {\n // No boundaries found and nothing remaining — shouldn't happen since we checked length > 0\n chunks.push(normalized);\n }\n\n // Split any oversized chunks at byte boundaries\n const result: string[] = [];\n for (const chunk of chunks) {\n if (byteLength(chunk) <= maxSize) {\n result.push(chunk);\n } else {\n result.push(...splitAtByteLimit(chunk, maxSize));\n }\n }\n\n return result;\n}\n\nexport function chunkByFixedSize(text: string, size: number): string[] {\n const normalized = text.replace(/\\r\\n/g, '\\n');\n\n if (normalized.length === 0) {\n return [''];\n }\n\n const bytes = new TextEncoder().encode(normalized);\n if (bytes.length <= size) {\n return [normalized];\n }\n\n const chunks: string[] = [];\n const decoder = new TextDecoder();\n let offset = 0;\n while (offset < bytes.length) {\n const end = Math.min(offset + size, bytes.length);\n // Avoid splitting in the middle of a multi-byte UTF-8 character\n let adjusted = end;\n if (adjusted < bytes.length) {\n while (adjusted > offset && (bytes[adjusted] & 0xc0) === 0x80) {\n adjusted--;\n }\n }\n chunks.push(decoder.decode(bytes.slice(offset, adjusted)));\n offset = adjusted;\n }\n\n return chunks;\n}\n\nfunction byteLength(s: string): number {\n return new TextEncoder().encode(s).length;\n}\n\nfunction splitAtByteLimit(text: string, maxSize: number): string[] {\n const bytes = new TextEncoder().encode(text);\n const decoder = new TextDecoder();\n const parts: string[] = [];\n let offset = 0;\n while (offset < bytes.length) {\n let end = Math.min(offset + maxSize, bytes.length);\n // Avoid splitting multi-byte characters\n if (end < bytes.length) {\n while (end > offset && (bytes[end] & 0xc0) === 0x80) {\n end--;\n }\n }\n parts.push(decoder.decode(bytes.slice(offset, end)));\n offset = end;\n }\n return parts;\n}\n","import { hkdf } from '@noble/hashes/hkdf';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { scrypt } from '@noble/hashes/scrypt';\nimport type { ScryptParams } from './types.js';\nimport { DEFAULT_SCRYPT_PARAMS } from './types.js';\nimport { zeroize } from './crypto-utils.js';\n\nconst ENC_INFO = new TextEncoder().encode('mdenc-v1-enc');\nconst HDR_INFO = new TextEncoder().encode('mdenc-v1-hdr');\nconst NONCE_INFO = new TextEncoder().encode('mdenc-v1-nonce');\n\nexport function normalizePassword(password: string): Uint8Array {\n const normalized = password.normalize('NFKC');\n return new TextEncoder().encode(normalized);\n}\n\nexport function deriveMasterKey(\n password: string,\n salt: Uint8Array,\n params: ScryptParams = DEFAULT_SCRYPT_PARAMS,\n): Uint8Array {\n const passwordBytes = normalizePassword(password);\n try {\n return scrypt(passwordBytes, salt, {\n N: params.N,\n r: params.r,\n p: params.p,\n dkLen: 32,\n });\n } finally {\n zeroize(passwordBytes);\n }\n}\n\nexport function deriveKeys(masterKey: Uint8Array): { encKey: Uint8Array; headerKey: Uint8Array; nonceKey: Uint8Array } {\n const encKey = hkdf(sha256, masterKey, undefined, ENC_INFO, 32);\n const headerKey = hkdf(sha256, masterKey, undefined, HDR_INFO, 32);\n const nonceKey = hkdf(sha256, masterKey, undefined, NONCE_INFO, 32);\n return { encKey, headerKey, nonceKey };\n}\n","export function constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) {\n diff |= a[i] ^ b[i];\n }\n return diff === 0;\n}\n\nexport function zeroize(...arrays: Uint8Array[]): void {\n for (const arr of arrays) {\n arr.fill(0);\n }\n}\n","import { xchacha20poly1305 } from '@noble/ciphers/chacha';\nimport { hmac } from '@noble/hashes/hmac';\nimport { sha256 } from '@noble/hashes/sha256';\n\nconst NONCE_LENGTH = 24;\n\nexport function buildAAD(fileId: Uint8Array): Uint8Array {\n const fileIdHex = bytesToHex(fileId);\n const aadString = `mdenc:v1\\n${fileIdHex}`;\n return new TextEncoder().encode(aadString);\n}\n\nexport function deriveNonce(nonceKey: Uint8Array, plaintext: Uint8Array): Uint8Array {\n const full = hmac(sha256, nonceKey, plaintext);\n return full.slice(0, NONCE_LENGTH);\n}\n\nexport function encryptChunk(\n encKey: Uint8Array,\n nonceKey: Uint8Array,\n plaintext: Uint8Array,\n fileId: Uint8Array,\n): Uint8Array {\n const nonce = deriveNonce(nonceKey, plaintext);\n const aad = buildAAD(fileId);\n const cipher = xchacha20poly1305(encKey, nonce, aad);\n const ciphertext = cipher.encrypt(plaintext);\n // Output: nonce || ciphertext || tag (tag is appended by noble)\n const result = new Uint8Array(NONCE_LENGTH + ciphertext.length);\n result.set(nonce, 0);\n result.set(ciphertext, NONCE_LENGTH);\n return result;\n}\n\nexport function decryptChunk(\n encKey: Uint8Array,\n payload: Uint8Array,\n fileId: Uint8Array,\n): Uint8Array {\n if (payload.length < NONCE_LENGTH + 16) {\n throw new Error('Chunk payload too short');\n }\n const nonce = payload.slice(0, NONCE_LENGTH);\n const ciphertext = payload.slice(NONCE_LENGTH);\n const aad = buildAAD(fileId);\n const cipher = xchacha20poly1305(encKey, nonce, aad);\n try {\n return cipher.decrypt(ciphertext);\n } catch {\n throw new Error('Chunk authentication failed');\n }\n}\n\nfunction bytesToHex(bytes: Uint8Array): string {\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += bytes[i].toString(16).padStart(2, '0');\n }\n return hex;\n}\n","import { hmac } from '@noble/hashes/hmac';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport type { MdencHeader, ScryptParams } from './types.js';\nimport { SCRYPT_BOUNDS } from './types.js';\nimport { constantTimeEqual } from './crypto-utils.js';\n\nexport function generateSalt(): Uint8Array {\n return randomBytes(16);\n}\n\nexport function generateFileId(): Uint8Array {\n return randomBytes(16);\n}\n\nexport function serializeHeader(header: MdencHeader): string {\n const saltB64 = toBase64(header.salt);\n const fileIdB64 = toBase64(header.fileId);\n const { N, r, p } = header.scrypt;\n return `mdenc:v1 salt_b64=${saltB64} file_id_b64=${fileIdB64} scrypt=N=${N},r=${r},p=${p}`;\n}\n\nexport function parseHeader(line: string): MdencHeader {\n if (!line.startsWith('mdenc:v1 ')) {\n throw new Error('Invalid header: missing mdenc:v1 prefix');\n }\n\n const saltMatch = line.match(/salt_b64=([A-Za-z0-9+/=]+)/);\n if (!saltMatch) throw new Error('Invalid header: missing salt_b64');\n const salt = fromBase64(saltMatch[1]);\n if (salt.length !== 16) throw new Error('Invalid header: salt must be 16 bytes');\n\n const fileIdMatch = line.match(/file_id_b64=([A-Za-z0-9+/=]+)/);\n if (!fileIdMatch) throw new Error('Invalid header: missing file_id_b64');\n const fileId = fromBase64(fileIdMatch[1]);\n if (fileId.length !== 16) throw new Error('Invalid header: file_id must be 16 bytes');\n\n const scryptMatch = line.match(/scrypt=N=(\\d+),r=(\\d+),p=(\\d+)/);\n if (!scryptMatch) throw new Error('Invalid header: missing scrypt parameters');\n const scryptParams: ScryptParams = {\n N: parseInt(scryptMatch[1], 10),\n r: parseInt(scryptMatch[2], 10),\n p: parseInt(scryptMatch[3], 10),\n };\n\n validateScryptParams(scryptParams);\n\n return { version: 'v1', salt, fileId, scrypt: scryptParams };\n}\n\nexport function validateScryptParams(params: ScryptParams): void {\n const { N, r, p } = SCRYPT_BOUNDS;\n if (params.N < N.min || params.N > N.max) {\n throw new Error(`Invalid scrypt N: ${params.N} (must be ${N.min}–${N.max})`);\n }\n if (params.r < r.min || params.r > r.max) {\n throw new Error(`Invalid scrypt r: ${params.r} (must be ${r.min}–${r.max})`);\n }\n if (params.p < p.min || params.p > p.max) {\n throw new Error(`Invalid scrypt p: ${params.p} (must be ${p.min}–${p.max})`);\n }\n}\n\nexport function authenticateHeader(headerKey: Uint8Array, headerLine: string): Uint8Array {\n const headerBytes = new TextEncoder().encode(headerLine);\n return hmac(sha256, headerKey, headerBytes);\n}\n\nexport function verifyHeader(\n headerKey: Uint8Array,\n headerLine: string,\n hmacBytes: Uint8Array,\n): boolean {\n const computed = authenticateHeader(headerKey, headerLine);\n return constantTimeEqual(computed, hmacBytes);\n}\n\nexport function toBase64(bytes: Uint8Array): string {\n return Buffer.from(bytes).toString('base64');\n}\n\nexport function fromBase64(b64: string): Uint8Array {\n return new Uint8Array(Buffer.from(b64, 'base64'));\n}\n","import { hmac } from '@noble/hashes/hmac';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { deriveMasterKey, deriveKeys } from './kdf.js';\nimport {\n parseHeader,\n verifyHeader,\n fromBase64,\n} from './header.js';\nimport { constantTimeEqual, zeroize } from './crypto-utils.js';\n\nexport async function verifySeal(\n fileContent: string,\n password: string,\n): Promise<boolean> {\n const lines = fileContent.split('\\n');\n if (lines.length > 0 && lines[lines.length - 1] === '') lines.pop();\n if (lines.length < 3) throw new Error('Invalid mdenc file: too few lines');\n\n const headerLine = lines[0];\n const header = parseHeader(headerLine);\n\n // Parse header auth\n const authLine = lines[1];\n const authMatch = authLine.match(/^hdrauth_b64=([A-Za-z0-9+/=]+)$/);\n if (!authMatch) throw new Error('Invalid mdenc file: missing hdrauth_b64 line');\n const headerHmac = fromBase64(authMatch[1]);\n\n // Derive keys\n const masterKey = deriveMasterKey(password, header.salt, header.scrypt);\n const { headerKey, nonceKey } = deriveKeys(masterKey);\n\n try {\n // Verify header\n if (!verifyHeader(headerKey, headerLine, headerHmac)) {\n throw new Error('Header authentication failed');\n }\n\n // Find seal line\n const chunkAndSealLines = lines.slice(2);\n const sealIndex = chunkAndSealLines.findIndex(l => l.startsWith('seal_b64='));\n if (sealIndex < 0) {\n throw new Error('File is not sealed: no seal_b64 line found');\n }\n\n const chunkLines = chunkAndSealLines.slice(0, sealIndex);\n const sealMatch = chunkAndSealLines[sealIndex].match(/^seal_b64=([A-Za-z0-9+/=]+)$/);\n if (!sealMatch) throw new Error('Invalid seal line');\n const storedHmac = fromBase64(sealMatch[1]);\n\n // Verify seal HMAC (covers header + auth + chunk lines)\n const sealInput = headerLine + '\\n' + authLine + '\\n' + chunkLines.join('\\n');\n const sealData = new TextEncoder().encode(sealInput);\n const computed = hmac(sha256, headerKey, sealData);\n\n return constantTimeEqual(computed, storedHmac);\n } finally {\n zeroize(masterKey, headerKey, nonceKey);\n }\n}\n"],"mappings":";AAMO,IAAM,wBAAsC;AAAA,EACjD,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,IAAM,gBAAgB;AAAA,EAC3B,GAAG,EAAE,KAAK,MAAM,KAAK,QAAQ;AAAA;AAAA,EAC7B,GAAG,EAAE,KAAK,GAAG,KAAK,GAAG;AAAA,EACrB,GAAG,EAAE,KAAK,GAAG,KAAK,GAAG;AACvB;AAqBO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,eAAY;AACZ,EAAAA,kBAAA,eAAY;AAFF,SAAAA;AAAA,GAAA;;;ACrCZ,SAAS,QAAAC,aAAY;AACrB,SAAS,UAAAC,eAAc;;;ACDvB,IAAM,yBAAyB;AAExB,SAAS,iBAAiB,MAAc,UAAU,wBAAkC;AAEzF,QAAM,aAAa,KAAK,QAAQ,SAAS,IAAI;AAE7C,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO,CAAC,EAAE;AAAA,EACZ;AAGA,QAAM,SAAmB,CAAC;AAC1B,QAAM,WAAW;AACjB,MAAI,UAAU;AACd,MAAI;AAEJ,UAAQ,QAAQ,SAAS,KAAK,UAAU,OAAO,MAAM;AAEnD,UAAM,WAAW,MAAM,QAAQ,MAAM,CAAC,EAAE;AACxC,WAAO,KAAK,WAAW,MAAM,SAAS,QAAQ,CAAC;AAC/C,cAAU;AAAA,EACZ;AAGA,MAAI,UAAU,WAAW,QAAQ;AAC/B,WAAO,KAAK,WAAW,MAAM,OAAO,CAAC;AAAA,EACvC,WAAW,OAAO,WAAW,GAAG;AAE9B,WAAO,KAAK,UAAU;AAAA,EACxB;AAGA,QAAM,SAAmB,CAAC;AAC1B,aAAW,SAAS,QAAQ;AAC1B,QAAI,WAAW,KAAK,K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sha256","hmac","sha256","hmac","sha256","hmac","sha256","hmac","sha256"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mdenc",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Diff-friendly encrypted Markdown format",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"mdenc": "./dist/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "bun x tsup",
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"test:watch": "bun test --watch",
|
|
31
|
+
"lint": "bun x tsc --noEmit",
|
|
32
|
+
"prepublishOnly": "bun run build",
|
|
33
|
+
"release": "scripts/release.sh",
|
|
34
|
+
"release:minor": "scripts/release.sh minor",
|
|
35
|
+
"release:major": "scripts/release.sh major"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"markdown",
|
|
39
|
+
"encryption",
|
|
40
|
+
"git",
|
|
41
|
+
"diff-friendly",
|
|
42
|
+
"aead"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/yogh-io/mdenc-v1.git"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/yogh-io/mdenc-v1#readme",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/yogh-io/mdenc-v1/issues"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18"
|
|
54
|
+
},
|
|
55
|
+
"license": "ISC",
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@noble/ciphers": "^1.2.1",
|
|
58
|
+
"@noble/hashes": "^1.7.1"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/node": "^25.3.3",
|
|
62
|
+
"tsup": "^8.4.0",
|
|
63
|
+
"typescript": "^5.7.3",
|
|
64
|
+
"@types/bun": "^1.2.4"
|
|
65
|
+
}
|
|
66
|
+
}
|