@signature-kit/crypto 0.2.1 → 0.2.2
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/CHANGELOG.md +20 -0
- package/dist/base64.d.ts +1 -1
- package/dist/base64.d.ts.map +1 -1
- package/dist/base64.js +15 -14
- package/dist/config.d.ts +3 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -7
- package/dist/pem.d.ts +1 -1
- package/dist/pem.d.ts.map +1 -1
- package/dist/pem.js +14 -8
- package/dist/pkcs12.d.ts +2 -10
- package/dist/pkcs12.d.ts.map +1 -1
- package/dist/pkcs12.js +368 -124
- package/dist/primitives/aes.d.ts +1 -14
- package/dist/primitives/aes.d.ts.map +1 -1
- package/dist/primitives/aes.js +8 -47
- package/dist/primitives/des.d.ts +1 -20
- package/dist/primitives/des.d.ts.map +1 -1
- package/dist/primitives/des.js +6 -67
- package/dist/primitives/hmac.d.ts +0 -30
- package/dist/primitives/hmac.d.ts.map +1 -1
- package/dist/primitives/hmac.js +4 -46
- package/dist/primitives/padding.d.ts +1 -8
- package/dist/primitives/padding.d.ts.map +1 -1
- package/dist/primitives/padding.js +2 -11
- package/dist/primitives/pbkdf2.d.ts +1 -17
- package/dist/primitives/pbkdf2.d.ts.map +1 -1
- package/dist/primitives/pbkdf2.js +8 -30
- package/dist/primitives/rc2.d.ts +1 -20
- package/dist/primitives/rc2.d.ts.map +1 -1
- package/dist/primitives/rc2.js +11 -69
- package/dist/primitives/sha1.d.ts +0 -13
- package/dist/primitives/sha1.d.ts.map +1 -1
- package/dist/primitives/sha1.js +1 -28
- package/dist/primitives/sha256.d.ts +0 -26
- package/dist/primitives/sha256.d.ts.map +1 -1
- package/dist/primitives/sha256.js +0 -34
- package/dist/primitives/sha512.d.ts +0 -19
- package/dist/primitives/sha512.d.ts.map +1 -1
- package/dist/primitives/sha512.js +1 -32
- package/package.json +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## @signature-kit/crypto@0.2.2
|
|
2
|
+
|
|
3
|
+
### Simplify Effect programs
|
|
4
|
+
|
|
5
|
+
Use native void effects and value-discarding combinators while preserving public success, error, and dependency contracts. The workspace now enforces Effect correctness and selected simplification rules through the official Effect TypeScript-Go integration with Oxlint.
|
|
6
|
+
|
|
7
|
+
### Runtime updates and signature inspection
|
|
8
|
+
|
|
9
|
+
Update to stable Effect 4 and current compatible dependencies. Error classes use the native branded Schema.TaggedError constructor. Use TypeScript 7 for builds and checks with the official TypeScript 6 API compatibility alias. Upgrade direct ASN.1 dependencies to v4, interchange SDK values through DER, and encode timestamp requests with the native RFC 3161 schema. Packages do not require a consumer ASN.1 override.
|
|
10
|
+
|
|
11
|
+
Add per-signature PDF verification, certificate-validity inspection through the Effect clock, and cancellable polling for final request states in all five remote signers. Applications control polling deadlines and retry policy; a terminal request is not necessarily completed.
|
|
12
|
+
|
|
13
|
+
Update the documentation runtime, use the loading task for PDF.js cleanup, and fix dynamic Node routes by forwarding Request.duplex in the Hono adapter. Keep the app and Fumapress on a single Waku runtime.
|
|
14
|
+
|
|
15
|
+
Reject non-finite domain numbers, validate XML signature methods before WebCrypto verification, and preserve unexpected SDK failures as defects. Strengthen native Effect and accessibility lint checks.
|
|
16
|
+
|
|
17
|
+
Add branded PDF stamps with proportional PNG logos and handwriting, theme/title controls, and a PDF-rendered preview. Run browser PDF preparation and preview rendering through native Effect worker RPC with scoped termination and typed validation failures. Preserve caller buffers and signing dates across the worker boundary.
|
|
18
|
+
|
|
19
|
+
Fix structured batch stamp option conflicts, reject badges without usable drawing space, and prevent premeasured text from wrapping into adjacent rows. Restore signer interaction after React StrictMode mount replay and register localized Fumapress demo routes through the framework's native locale option. Add real worker, StrictMode, PDF text-stream, cropped/rotated page, cancellation, and invalid-image regressions.
|
|
20
|
+
|
|
1
21
|
# Changelog
|
|
2
22
|
|
|
3
23
|
## 0.2.1
|
package/dist/base64.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { CryptoError } from "./config";
|
|
2
|
+
import { CryptoError } from "./config.js";
|
|
3
3
|
export declare const bytesToBase64: (bytes: Uint8Array) => string;
|
|
4
4
|
export declare const base64ToBytes: (base64: string) => Effect.Effect<Uint8Array<ArrayBuffer>, CryptoError>;
|
|
5
5
|
//# sourceMappingURL=base64.d.ts.map
|
package/dist/base64.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAA8C,MAAM,
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAA8C,MAAM,aAAa,CAAC;AActF,eAAO,MAAM,aAAa,UAAW,UAAU,KAAG,MAajD,CAAC;AAEF,eAAO,MAAM,aAAa,WAChB,MAAM,KACb,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,WAAW,CAwDjD,CAAC"}
|
package/dist/base64.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { CryptoError, CryptoErrorCodeValue, CryptoOperationValue } from "./config";
|
|
2
|
+
import { CryptoError, CryptoErrorCodeValue, CryptoOperationValue } from "./config.js";
|
|
3
3
|
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4
4
|
const base64Value = (char) => {
|
|
5
5
|
const code = char.charCodeAt(0);
|
|
@@ -32,26 +32,19 @@ export const bytesToBase64 = (bytes) => {
|
|
|
32
32
|
export const base64ToBytes = (base64) => Effect.gen(function* () {
|
|
33
33
|
const clean = base64.replace(/[\t\n\r ]/g, "");
|
|
34
34
|
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(clean)) {
|
|
35
|
-
return yield*
|
|
35
|
+
return yield* new CryptoError({
|
|
36
36
|
code: CryptoErrorCodeValue.invalidFormat,
|
|
37
37
|
reason: "Base64 input contains invalid characters.",
|
|
38
38
|
operation: CryptoOperationValue.base64Decode,
|
|
39
|
-
})
|
|
39
|
+
});
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const hasPadding = clean.endsWith("=");
|
|
42
|
+
if (clean.length % 4 === 1 || (hasPadding && clean.length % 4 !== 0)) {
|
|
43
|
+
return yield* new CryptoError({
|
|
43
44
|
code: CryptoErrorCodeValue.invalidFormat,
|
|
44
45
|
reason: "Base64 input has an invalid length.",
|
|
45
46
|
operation: CryptoOperationValue.base64Decode,
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
const firstPadding = clean.indexOf("=");
|
|
49
|
-
if (firstPadding >= 0 && firstPadding < clean.length - (clean.endsWith("==") ? 2 : 1)) {
|
|
50
|
-
return yield* Effect.fail(new CryptoError({
|
|
51
|
-
code: CryptoErrorCodeValue.invalidFormat,
|
|
52
|
-
reason: "Base64 padding must be at the end.",
|
|
53
|
-
operation: CryptoOperationValue.base64Decode,
|
|
54
|
-
}));
|
|
47
|
+
});
|
|
55
48
|
}
|
|
56
49
|
const normalized = clean.padEnd(Math.ceil(clean.length / 4) * 4, "=");
|
|
57
50
|
const padding = normalized.endsWith("==") ? 2 : normalized.endsWith("=") ? 1 : 0;
|
|
@@ -62,6 +55,14 @@ export const base64ToBytes = (base64) => Effect.gen(function* () {
|
|
|
62
55
|
const second = base64Value(normalized[offset + 1] ?? "");
|
|
63
56
|
const third = base64Value(normalized[offset + 2] ?? "");
|
|
64
57
|
const fourth = base64Value(normalized[offset + 3] ?? "");
|
|
58
|
+
if (offset + 4 === normalized.length &&
|
|
59
|
+
((padding === 2 && (second & 0x0f) !== 0) || (padding === 1 && (third & 0x03) !== 0))) {
|
|
60
|
+
return yield* new CryptoError({
|
|
61
|
+
code: CryptoErrorCodeValue.invalidFormat,
|
|
62
|
+
reason: "Base64 input has non-zero padding bits.",
|
|
63
|
+
operation: CryptoOperationValue.base64Decode,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
65
66
|
const chunk = (first << 18) | (second << 12) | (third << 6) | fourth;
|
|
66
67
|
if (outputOffset < output.length) {
|
|
67
68
|
output[outputOffset] = (chunk >> 16) & 0xff;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @signature-kit/crypto — typed error catalog and the PKCS#12 result contract.
|
|
3
|
-
*
|
|
4
|
-
* The cipher primitives and the PKCS#12 parser construct `CryptoError` at the
|
|
5
|
-
* exact decision point (bad padding, unsupported algorithm, missing material).
|
|
6
|
-
*/
|
|
7
1
|
import { Schema } from "effect";
|
|
8
2
|
export declare const CryptoErrorCodeSchema: Schema.Literals<readonly ["crypto.DECODE_ERROR", "crypto.INVALID_FORMAT", "crypto.UNSUPPORTED_ALGORITHM", "crypto.WRONG_PASSWORD", "crypto.NO_CERTIFICATE", "crypto.NO_PRIVATE_KEY", "crypto.CORRUPTED_FILE", "crypto.CIPHER_ERROR", "crypto.UNKNOWN"]>;
|
|
9
3
|
export type CryptoErrorCode = (typeof CryptoErrorCodeSchema)["Type"];
|
|
@@ -62,7 +56,9 @@ declare const CryptoError_base: Schema.Class<CryptoError, Schema.TaggedStruct<"C
|
|
|
62
56
|
readonly code: Schema.Literals<readonly ["crypto.DECODE_ERROR", "crypto.INVALID_FORMAT", "crypto.UNSUPPORTED_ALGORITHM", "crypto.WRONG_PASSWORD", "crypto.NO_CERTIFICATE", "crypto.NO_PRIVATE_KEY", "crypto.CORRUPTED_FILE", "crypto.CIPHER_ERROR", "crypto.UNKNOWN"]>;
|
|
63
57
|
readonly reason: Schema.optional<Schema.String>;
|
|
64
58
|
readonly operation: Schema.optional<Schema.Literals<readonly ["base64.decode", "pem.decode", "pkcs12.decode", "pkcs12.mac", "pkcs12.decrypt", "cipher.aes", "cipher.des", "cipher.rc2"]>>;
|
|
65
|
-
}>, import("effect/Cause").YieldableError
|
|
59
|
+
}>, import("effect/Cause").YieldableError & {
|
|
60
|
+
readonly brand: unique symbol;
|
|
61
|
+
}>;
|
|
66
62
|
export declare class CryptoError extends CryptoError_base {
|
|
67
63
|
get message(): string;
|
|
68
64
|
}
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,qBAAqB,yPAUhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,eAAO,MAAM,oBAAoB;;;;;;;;;;CAUU,CAAC;AAE5C,eAAO,MAAM,qBAAqB,sJAShC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,eAAO,MAAM,oBAAoB;;;;;;;;;CASU,CAAC;AAE5C,eAAO,MAAM,8BAA8B,8CAAsC,CAAC;AAClF,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAC;AACvF,eAAO,MAAM,yBAAyB,sVAGrC,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,eAAO,MAAM,mBAAmB;;QAE5B,qBAAqB;QACrB,uBAAuB;QACvB,8BAA8B;QAC9B,uBAAuB;QACvB,uBAAuB;QACvB,uBAAuB;QACvB,uBAAuB;QACvB,qBAAqB;QACrB,gBAAgB;;;QAGhB,qBAAqB;QACrB,uBAAuB;QACvB,8BAA8B;QAC9B,uBAAuB;QACvB,uBAAuB;QACvB,uBAAuB;QACvB,uBAAuB;QACvB,qBAAqB;QACrB,gBAAgB;;CAEyD,CAAC;;;;;;oBAgB1D,OAAO,MAAM;;AAFjC,qBAAa,WAAY,SAAQ,gBAO/B;IACA,IAAI,OAAO,IAAI,MAAM,CAKpB;CACF;AAED,eAAO,MAAM,kBAAkB;;;;EAI7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @signature-kit/crypto — typed error catalog and the PKCS#12 result contract.
|
|
3
|
-
*
|
|
4
|
-
* The cipher primitives and the PKCS#12 parser construct `CryptoError` at the
|
|
5
|
-
* exact decision point (bad padding, unsupported algorithm, missing material).
|
|
6
|
-
*/
|
|
7
1
|
import { Schema } from "effect";
|
|
8
2
|
export const CryptoErrorCodeSchema = Schema.Literals([
|
|
9
3
|
"crypto.DECODE_ERROR",
|
|
@@ -84,7 +78,7 @@ const cryptoErrorReasonOverridableByCode = {
|
|
|
84
78
|
"crypto.CIPHER_ERROR": true,
|
|
85
79
|
"crypto.UNKNOWN": true,
|
|
86
80
|
};
|
|
87
|
-
export class CryptoError extends Schema.
|
|
81
|
+
export class CryptoError extends Schema.TaggedError()("CryptoError", {
|
|
88
82
|
code: CryptoErrorCodeSchema,
|
|
89
83
|
reason: Schema.optional(Schema.String),
|
|
90
84
|
operation: Schema.optional(CryptoOperationSchema),
|
package/dist/pem.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { CryptoError } from "./config";
|
|
2
|
+
import { CryptoError } from "./config.js";
|
|
3
3
|
export declare const pemToDer: (pem: string) => Effect.Effect<Uint8Array, CryptoError>;
|
|
4
4
|
export declare const derToPem: (der: Uint8Array, label: string) => string;
|
|
5
5
|
//# sourceMappingURL=pem.d.ts.map
|
package/dist/pem.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pem.d.ts","sourceRoot":"","sources":["../src/pem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAA8C,MAAM,
|
|
1
|
+
{"version":3,"file":"pem.d.ts","sourceRoot":"","sources":["../src/pem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAA8C,MAAM,aAAa,CAAC;AAMtF,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,WAAW,CAsB3E,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAS,UAAU,SAAS,MAAM,KAAG,MASzD,CAAC"}
|
package/dist/pem.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { CryptoError, CryptoErrorCodeValue, CryptoOperationValue } from "./config";
|
|
3
|
-
import { base64ToBytes, bytesToBase64 } from "./base64";
|
|
2
|
+
import { CryptoError, CryptoErrorCodeValue, CryptoOperationValue } from "./config.js";
|
|
3
|
+
import { base64ToBytes, bytesToBase64 } from "./base64.js";
|
|
4
|
+
const PEM_ENVELOPE = /^[\t \r\n]*-----BEGIN ([^\r\n]+)-----\r?\n([\s\S]*?)\r?\n-----END \1-----[\t \r\n]*$/;
|
|
4
5
|
export const pemToDer = (pem) => {
|
|
5
|
-
const base64 = pem
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const base64 = PEM_ENVELOPE.exec(pem)?.[2];
|
|
7
|
+
if (base64 === undefined || base64.includes("-----")) {
|
|
8
|
+
return Effect.fail(new CryptoError({
|
|
9
|
+
code: CryptoErrorCodeValue.invalidFormat,
|
|
10
|
+
reason: "PEM input must contain exactly one matching BEGIN/END envelope.",
|
|
11
|
+
operation: CryptoOperationValue.pemDecode,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
const normalizedBase64 = base64.replace(/[\t\n\r ]/g, "");
|
|
15
|
+
if (normalizedBase64.length === 0) {
|
|
10
16
|
return Effect.fail(new CryptoError({
|
|
11
17
|
code: CryptoErrorCodeValue.invalidFormat,
|
|
12
18
|
reason: "PEM input does not contain base64 DER content.",
|
|
13
19
|
operation: CryptoOperationValue.pemDecode,
|
|
14
20
|
}));
|
|
15
21
|
}
|
|
16
|
-
return base64ToBytes(
|
|
22
|
+
return base64ToBytes(normalizedBase64);
|
|
17
23
|
};
|
|
18
24
|
export const derToPem = (der, label) => {
|
|
19
25
|
const base64 = bytesToBase64(der);
|
package/dist/pkcs12.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PKCS#12 (.pfx/.p12) parser — fully Effect-native.
|
|
3
|
-
*
|
|
4
|
-
* Navigates the ASN.1 structure with the typed `@signature-kit/asn1` accessors, so
|
|
5
|
-
* every read narrows without a cast. The MAC check is the password gate; once it
|
|
6
|
-
* passes, a later cipher failure is treated as a corrupt file. All failures are
|
|
7
|
-
* `CryptoError` constructed at the decision point — nothing throws.
|
|
8
|
-
*/
|
|
9
1
|
import { Effect, Redacted } from "effect";
|
|
10
|
-
import { CryptoError
|
|
11
|
-
|
|
2
|
+
import { CryptoError } from "./config.js";
|
|
3
|
+
import type { Pkcs12Result } from "./config.js";
|
|
12
4
|
export declare const parsePkcs12: (data: Uint8Array, password: Redacted.Redacted<string>) => Effect.Effect<Pkcs12Result, CryptoError>;
|
|
13
5
|
//# sourceMappingURL=pkcs12.d.ts.map
|
package/dist/pkcs12.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkcs12.d.ts","sourceRoot":"","sources":["../src/pkcs12.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pkcs12.d.ts","sourceRoot":"","sources":["../src/pkcs12.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,WAAW,EAA8C,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA2yBhD,eAAO,MAAM,WAAW,SAChB,UAAU,YACN,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAClC,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAiLvC,CAAC"}
|