@signature-kit/a1 0.2.0 → 0.4.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/CHANGELOG.md +21 -0
- package/README.md +29 -9
- package/dist/config.d.ts +2 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -8
- package/dist/signer.d.ts +5 -27
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +60 -93
- package/package.json +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
|
+
## @signature-kit/a1@0.4.0
|
|
2
|
+
|
|
3
|
+
### Publish A1 with Node-resolvable imports
|
|
4
|
+
|
|
5
|
+
Release the fully specified relative imports already in source, so `@signature-kit/a1/signer` loads under native Node ESM instead of failing with `ERR_MODULE_NOT_FOUND`.
|
|
6
|
+
|
|
7
|
+
This release also removes the unused `A1Signer` service and `a1SignerLayer`; use `a1SignaturesLayer` or `loadA1SignerAdapter`.
|
|
8
|
+
|
|
1
9
|
# Changelog
|
|
2
10
|
|
|
11
|
+
## Unreleased
|
|
12
|
+
|
|
13
|
+
- Remove the unused `A1Signer` service and `a1SignerLayer`; use `a1SignaturesLayer` or `loadA1SignerAdapter`.
|
|
14
|
+
- Share one validated remote-certificate loader between URL-backed signing and profile APIs.
|
|
15
|
+
|
|
16
|
+
## 0.3.0
|
|
17
|
+
|
|
18
|
+
- Emit distinct `SignatureKitError` codes for expired, not-yet-valid, and
|
|
19
|
+
missing Brazilian CPF/CNPJ certificate profile failures.
|
|
20
|
+
|
|
21
|
+
- Report A1 schema decode names as local strings after the core schema-name
|
|
22
|
+
catalog removal; public A1 signing behavior is unchanged.
|
|
23
|
+
|
|
3
24
|
## 0.2.0
|
|
4
25
|
|
|
5
26
|
- Redact presigned-URL credentials from error messages when fetching remote PKCS#12 material.
|
package/README.md
CHANGED
|
@@ -1,25 +1,45 @@
|
|
|
1
1
|
# @signature-kit/a1
|
|
2
2
|
|
|
3
|
-
Local A1 / PKCS#12 signer adapter that exposes signing power through the core SignerAdapter
|
|
3
|
+
Local A1 / PKCS#12 signer adapter that exposes signing power through the core `SignerAdapter` and `Signatures` service contracts.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
bun add @signature-kit/a1 effect
|
|
8
|
+
bun add @signature-kit/a1 @signature-kit/signatures effect
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
`effect` is a direct runtime dependency. PKCS#12 passwords stay `Redacted` until the explicit parse/import boundary.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- `@signature-kit/a1/signer`
|
|
13
|
+
## Public surface
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
- `@signature-kit/a1/config` — `A1SignerOptionsSchema`, remote-source schemas, and `A1CertificateProfileSchema`.
|
|
16
|
+
- `@signature-kit/a1/signer` — `createA1SignerAdapter`, `loadA1SignerAdapter`, `a1SignaturesLayer`, `parseA1CertificateProfile`, `fetchA1Pkcs12`, `a1SignaturesLayerFromUrl`, and `parseA1CertificateProfileFromUrl`.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
`a1SignaturesLayer(options)` is the usual application-boundary layer for local PDF/XML signing. URL helpers fetch a remote `.pfx`/`.p12` through `SignatureHttpClient`; presigned URLs are redacted in error messages through the diagnostic URL path.
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Example
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
```ts
|
|
23
|
+
import { a1SignaturesLayer } from "@signature-kit/a1/signer";
|
|
24
|
+
import { signatures } from "@signature-kit/signatures";
|
|
25
|
+
import { Effect, Redacted } from "effect";
|
|
26
|
+
|
|
27
|
+
declare const content: Uint8Array;
|
|
28
|
+
declare const pfx: Uint8Array;
|
|
29
|
+
|
|
30
|
+
const program = signatures
|
|
31
|
+
.sign({
|
|
32
|
+
content,
|
|
33
|
+
algorithm: "rsa-sha256",
|
|
34
|
+
})
|
|
35
|
+
.pipe(Effect.provide(a1SignaturesLayer({ pfx, password: Redacted.make("secret") })));
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Errors and i18n
|
|
39
|
+
|
|
40
|
+
A1 parse, import, sign, and certificate-profile failures surface as `SignatureKitError` from `@signature-kit/signatures`. Applications can render localized copy through `errorMessage` from `@signature-kit/i18n` with the `signatureKitErrorMessages` catalog from `@signature-kit/signatures`.
|
|
41
|
+
|
|
42
|
+
Docs: <https://signaturekit.dev/en-US/docs/a1-signing/browser-pdf-flow>.
|
|
23
43
|
|
|
24
44
|
## License
|
|
25
45
|
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A1 signer adapter options.
|
|
3
|
-
*/
|
|
4
1
|
import { Schema } from "effect";
|
|
5
2
|
export declare const A1SignerOptionsSchema: Schema.Struct<{
|
|
6
3
|
readonly pfx: Schema.Uint8Array;
|
|
@@ -8,16 +5,14 @@ export declare const A1SignerOptionsSchema: Schema.Struct<{
|
|
|
8
5
|
}>;
|
|
9
6
|
export type A1SignerOptions = (typeof A1SignerOptionsSchema)["Type"];
|
|
10
7
|
export declare const A1RemoteFetchSchema: Schema.Struct<{
|
|
11
|
-
/** The (presigned) URL the PKCS#12 bytes are fetched from with a GET. */
|
|
12
8
|
url: Schema.NonEmptyString;
|
|
13
|
-
/** Extra request headers (for auth not already baked into the URL). */
|
|
14
9
|
headers: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
15
10
|
}>;
|
|
16
11
|
export type A1RemoteFetch = (typeof A1RemoteFetchSchema)["Type"];
|
|
17
12
|
export declare const A1RemoteSourceSchema: Schema.Struct<{
|
|
18
|
-
readonly password: Schema.ConstraintDecoder<import("effect/Redacted").Redacted<string>, never>;
|
|
19
13
|
readonly url: Schema.NonEmptyString;
|
|
20
14
|
readonly headers: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
15
|
+
readonly password: Schema.ConstraintDecoder<import("effect/Redacted").Redacted<string>, never>;
|
|
21
16
|
}>;
|
|
22
17
|
export type A1RemoteSource = (typeof A1RemoteSourceSchema)["Type"];
|
|
23
18
|
export declare const A1CertificateProfileSchema: Schema.Struct<{
|
|
@@ -29,7 +24,7 @@ export declare const A1CertificateProfileSchema: Schema.Struct<{
|
|
|
29
24
|
readonly fingerprint: Schema.NonEmptyString;
|
|
30
25
|
readonly validFrom: Schema.Date;
|
|
31
26
|
readonly validTo: Schema.Date;
|
|
32
|
-
readonly daysUntilExpiry: Schema.
|
|
27
|
+
readonly daysUntilExpiry: Schema.Finite;
|
|
33
28
|
}>;
|
|
34
29
|
export type A1CertificateProfile = (typeof A1CertificateProfileSchema)["Type"];
|
|
35
30
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,qBAAqB;;;EAGhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAOrE,eAAO,MAAM,mBAAmB;;;EAAwC,CAAC;AACzE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,eAAO,MAAM,oBAAoB;;;;EAG/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,eAAO,MAAM,0BAA0B;;;;;;;;;;EAUrC,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { redactedStringSchema } from "@signature-kit/core/config";
|
|
5
|
-
import { SignatureHttpHeadersSchema } from "@signature-kit/core/http";
|
|
1
|
+
import { redactedStringSchema } from "@signature-kit/signatures";
|
|
2
|
+
import { SignatureHttpHeadersSchema } from "@signature-kit/http";
|
|
6
3
|
import { Schema } from "effect";
|
|
7
4
|
export const A1SignerOptionsSchema = Schema.Struct({
|
|
8
5
|
pfx: Schema.Uint8Array,
|
|
9
6
|
password: redactedStringSchema,
|
|
10
7
|
});
|
|
11
8
|
const A1RemoteLocationFields = {
|
|
12
|
-
/** The (presigned) URL the PKCS#12 bytes are fetched from with a GET. */
|
|
13
9
|
url: Schema.NonEmptyString,
|
|
14
|
-
/** Extra request headers (for auth not already baked into the URL). */
|
|
15
10
|
headers: Schema.optional(SignatureHttpHeadersSchema),
|
|
16
11
|
};
|
|
17
12
|
export const A1RemoteFetchSchema = Schema.Struct(A1RemoteLocationFields);
|
|
@@ -28,5 +23,5 @@ export const A1CertificateProfileSchema = Schema.Struct({
|
|
|
28
23
|
fingerprint: Schema.NonEmptyString,
|
|
29
24
|
validFrom: Schema.Date,
|
|
30
25
|
validTo: Schema.Date,
|
|
31
|
-
daysUntilExpiry: Schema.
|
|
26
|
+
daysUntilExpiry: Schema.Finite,
|
|
32
27
|
});
|
package/dist/signer.d.ts
CHANGED
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type { Certificate, SignerAdapter } from "@signature-kit/core/config";
|
|
7
|
-
import { SignatureKitError } from "@signature-kit/core/config";
|
|
8
|
-
import { Context, Effect, Layer } from "effect";
|
|
9
|
-
import { type A1CertificateProfile, type A1RemoteFetch, type A1RemoteSource, type A1SignerOptions } from "./config";
|
|
10
|
-
export type A1SignerMaterial = {
|
|
11
|
-
readonly certificate: Certificate;
|
|
12
|
-
readonly profile: A1CertificateProfile;
|
|
13
|
-
readonly signer: SignerAdapter;
|
|
14
|
-
};
|
|
15
|
-
declare const A1Signer_base: Context.ServiceClass<A1Signer, "@signature-kit/a1/Signer", A1SignerMaterial>;
|
|
16
|
-
export declare class A1Signer extends A1Signer_base {
|
|
17
|
-
}
|
|
18
|
-
/** Build an A1 signer adapter from an already-parsed core {@link Certificate}. */
|
|
1
|
+
import { Signatures, SignatureKitError } from "@signature-kit/signatures";
|
|
2
|
+
import { SignatureHttpClient } from "@signature-kit/http";
|
|
3
|
+
import type { Certificate, SignerAdapter } from "@signature-kit/signatures";
|
|
4
|
+
import { Effect, Layer } from "effect";
|
|
5
|
+
import type { A1CertificateProfile, A1RemoteFetch, A1RemoteSource, A1SignerOptions } from "./config.js";
|
|
19
6
|
export declare const createA1SignerAdapter: (certificate: Certificate) => SignerAdapter;
|
|
20
|
-
/** Load an A1 container and expose its parsed certificate, profile, and signer. */
|
|
21
|
-
export declare const a1SignerLayer: (options: A1SignerOptions) => Layer.Layer<A1Signer, SignatureKitError>;
|
|
22
|
-
/** Load an A1 container and build the adapter in one Effect. */
|
|
23
7
|
export declare const loadA1SignerAdapter: (options: A1SignerOptions) => Effect.Effect<SignerAdapter, SignatureKitError>;
|
|
24
|
-
/** Parse and validate the certificate metadata most app integrations store. */
|
|
25
8
|
export declare const parseA1CertificateProfile: (options: A1SignerOptions) => Effect.Effect<A1CertificateProfile, SignatureKitError>;
|
|
26
|
-
/** Load an A1 container and provide the agnostic core Signatures service. */
|
|
27
9
|
export declare const a1SignaturesLayer: (options: A1SignerOptions) => Layer.Layer<Signatures, SignatureKitError>;
|
|
28
|
-
/** Fetch the A1 PKCS#12 (.pfx) bytes from a (presigned) URL via a GET. */
|
|
29
10
|
export declare const fetchA1Pkcs12: (source: A1RemoteFetch) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
|
|
30
|
-
/** Provide the agnostic core Signatures service from a remote (URL) A1 container. */
|
|
31
11
|
export declare const a1SignaturesLayerFromUrl: (source: A1RemoteSource) => Layer.Layer<Signatures, SignatureKitError, SignatureHttpClient>;
|
|
32
|
-
/** Parse and validate the A1 certificate metadata from a remote (URL) container. */
|
|
33
12
|
export declare const parseA1CertificateProfileFromUrl: (source: A1RemoteSource) => Effect.Effect<A1CertificateProfile, SignatureKitError, SignatureHttpClient>;
|
|
34
|
-
export {};
|
|
35
13
|
//# sourceMappingURL=signer.d.ts.map
|
package/dist/signer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EAKlB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAsB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGhG,OAAO,EAAS,MAAM,EAAE,KAAK,EAA2B,MAAM,QAAQ,CAAC;AAEvE,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,eAAe,EAChB,MAAM,aAAa,CAAC;AAyLrB,eAAO,MAAM,qBAAqB,gBAAiB,WAAW,KAAG,aA8DhE,CAAC;AAEF,eAAO,MAAM,mBAAmB,YACrB,eAAe,KACvB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,iBAAiB,CACmB,CAAC;AAErE,eAAO,MAAM,yBAAyB,YAC3B,eAAe,KACvB,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,CACa,CAAC;AAEtE,eAAO,MAAM,iBAAiB,YACnB,eAAe,KACvB,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,iBAAiB,CACkD,CAAC;AAc/F,eAAO,MAAM,aAAa,WAChB,aAAa,KACpB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAkChE,CAAC;AAuBJ,eAAO,MAAM,wBAAwB,WAC3B,cAAc,KACrB,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAI9D,CAAC;AAEJ,eAAO,MAAM,gCAAgC,WACnC,cAAc,KACrB,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,EAAE,mBAAmB,CACO,CAAC"}
|
package/dist/signer.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { Signatures } from "@signature-kit/core/signatures";
|
|
5
|
-
import { SignatureHttpClient } from "@signature-kit/core/http";
|
|
6
|
-
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, SignatureKitSchemaNameValue, SignInputSchema, VerifyInputSchema, } from "@signature-kit/core/config";
|
|
1
|
+
import { Signatures, SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, SignInputSchema, VerifyInputSchema, } from "@signature-kit/signatures";
|
|
2
|
+
import { SignatureHttpClient } from "@signature-kit/http";
|
|
7
3
|
import { daysUntilExpiry, parseCertificate, toSignerIdentity } from "@signature-kit/certificates";
|
|
8
4
|
import { pemToDer } from "@signature-kit/crypto/pem";
|
|
9
|
-
import {
|
|
10
|
-
import { A1RemoteFetchSchema, A1RemoteSourceSchema, A1SignerOptionsSchema
|
|
5
|
+
import { Clock, Effect, Layer, Match, Redacted, Schema } from "effect";
|
|
6
|
+
import { A1RemoteFetchSchema, A1RemoteSourceSchema, A1SignerOptionsSchema } from "./config.js";
|
|
11
7
|
const RSA_ALGORITHM_NAME = "RSASSA-PKCS1-v1_5";
|
|
8
|
+
const RsaAlgorithmHashSchema = Schema.Literals(["SHA-1", "SHA-256", "SHA-512"]);
|
|
9
|
+
const rsaAlgorithmHash = (algorithm) => Match.value(algorithm).pipe(Match.when("rsa-sha1", () => "SHA-1"), Match.when("rsa-sha256", () => "SHA-256"), Match.when("rsa-sha512", () => "SHA-512"), Match.exhaustive);
|
|
12
10
|
const rsaAlgorithm = (algorithm) => ({
|
|
13
11
|
name: RSA_ALGORITHM_NAME,
|
|
14
|
-
hash: algorithm
|
|
12
|
+
hash: rsaAlgorithmHash(algorithm),
|
|
15
13
|
});
|
|
16
|
-
/** Copy into a fresh ArrayBuffer-backed view so it satisfies `BufferSource`. */
|
|
17
14
|
const toBufferSource = (data) => {
|
|
18
15
|
const copy = new Uint8Array(data.byteLength);
|
|
19
16
|
copy.set(data);
|
|
@@ -56,40 +53,43 @@ const verifyWithKey = (key, algorithm, signature, content) => Effect.tryPromise(
|
|
|
56
53
|
operation: SignatureKitOperationValue.cryptoVerify,
|
|
57
54
|
}),
|
|
58
55
|
});
|
|
59
|
-
export class A1Signer extends Context.Service()("@signature-kit/a1/Signer") {
|
|
60
|
-
}
|
|
61
|
-
/** Cache WebCrypto imports per adapter and algorithm. */
|
|
62
56
|
const cachedKey = (cache, algorithm, load) => {
|
|
63
57
|
const cached = cache.get(algorithm);
|
|
64
58
|
if (cached !== undefined)
|
|
65
59
|
return Effect.succeed(cached);
|
|
66
60
|
return load(algorithm).pipe(Effect.tap((key) => Effect.sync(() => cache.set(algorithm, key))));
|
|
67
61
|
};
|
|
68
|
-
const loadA1Certificate = (options) => Schema.decodeUnknownEffect(A1SignerOptionsSchema)(options).pipe(Effect.mapError((issue) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
}), Effect.flatMap((valid) => parseCertificate(valid.pfx, valid.password)));
|
|
62
|
+
const loadA1Certificate = (options) => Schema.decodeUnknownEffect(A1SignerOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
63
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
64
|
+
retryable: false,
|
|
65
|
+
reason: "Invalid A1 signer options.",
|
|
66
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
67
|
+
schemaName: "A1SignerOptions",
|
|
68
|
+
issueMessage: String(issue),
|
|
69
|
+
})), Effect.flatMap((valid) => parseCertificate(valid.pfx, valid.password)));
|
|
78
70
|
const certificateProfile = (certificate) => Effect.gen(function* () {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
const currentTime = yield* Clock.currentTimeMillis;
|
|
72
|
+
if (currentTime > certificate.validity.notAfter.getTime()) {
|
|
73
|
+
return yield* new SignatureKitError({
|
|
74
|
+
code: SignatureKitErrorCodeValue.certificateExpired,
|
|
75
|
+
retryable: false,
|
|
76
|
+
reason: `A1 certificate expired at ${certificate.validity.notAfter.toISOString()}.`,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (currentTime < certificate.validity.notBefore.getTime()) {
|
|
80
|
+
return yield* new SignatureKitError({
|
|
81
|
+
code: SignatureKitErrorCodeValue.certificateNotYetValid,
|
|
82
82
|
retryable: false,
|
|
83
|
-
reason: `A1 certificate is not valid
|
|
84
|
-
})
|
|
83
|
+
reason: `A1 certificate is not valid before ${certificate.validity.notBefore.toISOString()}.`,
|
|
84
|
+
});
|
|
85
85
|
}
|
|
86
86
|
const document = certificate.brazilian.cnpj ?? certificate.brazilian.cpf;
|
|
87
87
|
if (document === null) {
|
|
88
|
-
return yield*
|
|
89
|
-
code: SignatureKitErrorCodeValue.
|
|
88
|
+
return yield* new SignatureKitError({
|
|
89
|
+
code: SignatureKitErrorCodeValue.missingBrIdentifier,
|
|
90
90
|
retryable: false,
|
|
91
91
|
reason: "A1 certificate does not contain a Brazilian CPF or CNPJ.",
|
|
92
|
-
})
|
|
92
|
+
});
|
|
93
93
|
}
|
|
94
94
|
return {
|
|
95
95
|
document,
|
|
@@ -103,7 +103,6 @@ const certificateProfile = (certificate) => Effect.gen(function* () {
|
|
|
103
103
|
daysUntilExpiry: daysUntilExpiry(certificate),
|
|
104
104
|
};
|
|
105
105
|
});
|
|
106
|
-
/** Build an A1 signer adapter from an already-parsed core {@link Certificate}. */
|
|
107
106
|
export const createA1SignerAdapter = (certificate) => {
|
|
108
107
|
const privateKeys = new Map();
|
|
109
108
|
const publicKeys = new Map();
|
|
@@ -114,67 +113,44 @@ export const createA1SignerAdapter = (certificate) => {
|
|
|
114
113
|
inspect: () => Effect.succeed(toSignerIdentity(certificate)),
|
|
115
114
|
certificate: () => Effect.succeed(certificate),
|
|
116
115
|
importSigningKey: signingKey,
|
|
117
|
-
sign: (input) => Schema.decodeUnknownEffect(SignInputSchema)(input).pipe(Effect.mapError((issue) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
schemaName: SignatureKitSchemaNameValue.verifyInput,
|
|
134
|
-
issueMessage: String(issue),
|
|
135
|
-
});
|
|
136
|
-
}), Effect.flatMap((valid) => verificationKey(valid.algorithm).pipe(Effect.flatMap((key) => verifyWithKey(key, valid.algorithm, valid.signature, valid.content)), Effect.map((val32) => ({ valid: val32, algorithm: valid.algorithm }))))),
|
|
116
|
+
sign: (input) => Schema.decodeUnknownEffect(SignInputSchema)(input).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
117
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
118
|
+
retryable: false,
|
|
119
|
+
reason: "Invalid sign input.",
|
|
120
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
121
|
+
schemaName: "SignInput",
|
|
122
|
+
issueMessage: String(issue),
|
|
123
|
+
})), Effect.flatMap((valid) => signingKey(valid.algorithm).pipe(Effect.flatMap((key) => signWithKey(key, valid.algorithm, valid.content)), Effect.map((signature) => ({ algorithm: valid.algorithm, signature }))))),
|
|
124
|
+
verify: (input) => Schema.decodeUnknownEffect(VerifyInputSchema)(input).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
125
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
126
|
+
retryable: false,
|
|
127
|
+
reason: "Invalid verify input.",
|
|
128
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
129
|
+
schemaName: "VerifyInput",
|
|
130
|
+
issueMessage: String(issue),
|
|
131
|
+
})), Effect.flatMap((valid) => verificationKey(valid.algorithm).pipe(Effect.flatMap((key) => verifyWithKey(key, valid.algorithm, valid.signature, valid.content)), Effect.map((val32) => ({ valid: val32, algorithm: valid.algorithm }))))),
|
|
137
132
|
};
|
|
138
133
|
};
|
|
139
|
-
const loadA1SignerMaterial = (options) => loadA1Certificate(options).pipe(Effect.flatMap((certificate) => certificateProfile(certificate).pipe(Effect.map((profile) => ({
|
|
140
|
-
certificate,
|
|
141
|
-
profile,
|
|
142
|
-
signer: createA1SignerAdapter(certificate),
|
|
143
|
-
})))));
|
|
144
|
-
/** Load an A1 container and expose its parsed certificate, profile, and signer. */
|
|
145
|
-
export const a1SignerLayer = (options) => Layer.effect(A1Signer, loadA1SignerMaterial(options));
|
|
146
|
-
/** Load an A1 container and build the adapter in one Effect. */
|
|
147
134
|
export const loadA1SignerAdapter = (options) => loadA1Certificate(options).pipe(Effect.map(createA1SignerAdapter));
|
|
148
|
-
/** Parse and validate the certificate metadata most app integrations store. */
|
|
149
135
|
export const parseA1CertificateProfile = (options) => loadA1Certificate(options).pipe(Effect.flatMap(certificateProfile));
|
|
150
|
-
/** Load an A1 container and provide the agnostic core Signatures service. */
|
|
151
136
|
export const a1SignaturesLayer = (options) => Layer.effect(Signatures, loadA1Certificate(options).pipe(Effect.map(createA1SignerAdapter)));
|
|
152
|
-
// ---------------------------------------------------------------------------
|
|
153
|
-
// Remote A1 material — fetch the PKCS#12 (.pfx) from a (presigned) URL.
|
|
154
|
-
//
|
|
155
|
-
// The A1 container usually lives in object storage (e.g. S3) and is handed to
|
|
156
|
-
// the signer as a short-lived presigned URL. Fetching is the ONLY thing that
|
|
157
|
-
// changes versus the local-bytes path: the fetched bytes flow into exactly the
|
|
158
|
-
// same loadA1Certificate -> createA1SignerAdapter pipeline, so the signer, the
|
|
159
|
-
// profile, and the Signatures layer behave identically. The private key never
|
|
160
|
-
// leaves this process — only the encrypted PKCS#12 is fetched, then decrypted
|
|
161
|
-
// locally with the Redacted password.
|
|
162
|
-
// ---------------------------------------------------------------------------
|
|
163
137
|
const redactPresignedUrl = (url) => {
|
|
164
138
|
if (!URL.canParse(url))
|
|
165
139
|
return "<redacted>";
|
|
166
140
|
const sanitized = new URL(url);
|
|
141
|
+
sanitized.username = "";
|
|
142
|
+
sanitized.password = "";
|
|
143
|
+
sanitized.hash = "";
|
|
167
144
|
for (const key of sanitized.searchParams.keys()) {
|
|
168
145
|
sanitized.searchParams.set(key, "<redacted>");
|
|
169
146
|
}
|
|
170
147
|
return sanitized.toString();
|
|
171
148
|
};
|
|
172
|
-
/** Fetch the A1 PKCS#12 (.pfx) bytes from a (presigned) URL via a GET. */
|
|
173
149
|
export const fetchA1Pkcs12 = (source) => Schema.decodeUnknownEffect(A1RemoteFetchSchema)(source).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
174
150
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
175
151
|
retryable: false,
|
|
176
152
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
177
|
-
schemaName:
|
|
153
|
+
schemaName: "A1RemoteFetch",
|
|
178
154
|
issueMessage: String(issue),
|
|
179
155
|
})), Effect.flatMap((valid) => SignatureHttpClient.use((http) => http
|
|
180
156
|
.requestBytes({
|
|
@@ -183,26 +159,17 @@ export const fetchA1Pkcs12 = (source) => Schema.decodeUnknownEffect(A1RemoteFetc
|
|
|
183
159
|
diagnosticUrl: redactPresignedUrl(valid.url),
|
|
184
160
|
...(valid.headers === undefined ? {} : { headers: valid.headers }),
|
|
185
161
|
})
|
|
186
|
-
.pipe(Effect.
|
|
187
|
-
|
|
188
|
-
code: SignatureKitErrorCodeValue.emptyFile,
|
|
189
|
-
retryable: false,
|
|
190
|
-
reason: "The fetched A1 certificate is empty.",
|
|
191
|
-
}))
|
|
192
|
-
: Effect.succeed(bytes))))));
|
|
193
|
-
/** Provide the agnostic core Signatures service from a remote (URL) A1 container. */
|
|
194
|
-
export const a1SignaturesLayerFromUrl = (source) => Layer.effect(Signatures, Schema.decodeUnknownEffect(A1RemoteSourceSchema)(source).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
195
|
-
code: SignatureKitErrorCodeValue.invalidInput,
|
|
162
|
+
.pipe(Effect.filterOrFail((bytes) => bytes.byteLength !== 0, () => new SignatureKitError({
|
|
163
|
+
code: SignatureKitErrorCodeValue.emptyFile,
|
|
196
164
|
retryable: false,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
})), Effect.flatMap((valid) => fetchA1Pkcs12(valid).pipe(Effect.flatMap((pfx) => loadA1Certificate({ pfx, password: valid.password })), Effect.map(createA1SignerAdapter)))));
|
|
201
|
-
/** Parse and validate the A1 certificate metadata from a remote (URL) container. */
|
|
202
|
-
export const parseA1CertificateProfileFromUrl = (source) => Schema.decodeUnknownEffect(A1RemoteSourceSchema)(source).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
165
|
+
reason: "The fetched A1 certificate is empty.",
|
|
166
|
+
}))))));
|
|
167
|
+
const loadA1CertificateFromRemoteSource = (source) => Schema.decodeUnknownEffect(A1RemoteSourceSchema)(source).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
203
168
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
204
169
|
retryable: false,
|
|
205
170
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
206
|
-
schemaName:
|
|
171
|
+
schemaName: "A1RemoteSource",
|
|
207
172
|
issueMessage: String(issue),
|
|
208
|
-
})), Effect.flatMap((valid) => fetchA1Pkcs12(valid).pipe(Effect.flatMap((pfx) =>
|
|
173
|
+
})), Effect.flatMap((valid) => fetchA1Pkcs12(valid).pipe(Effect.flatMap((pfx) => loadA1Certificate({ pfx, password: valid.password })))));
|
|
174
|
+
export const a1SignaturesLayerFromUrl = (source) => Layer.effect(Signatures, loadA1CertificateFromRemoteSource(source).pipe(Effect.map(createA1SignerAdapter)));
|
|
175
|
+
export const parseA1CertificateProfileFromUrl = (source) => loadA1CertificateFromRemoteSource(source).pipe(Effect.flatMap(certificateProfile));
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signature-kit/a1",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Licitei/signature-kit.git"
|
|
8
|
+
},
|
|
5
9
|
"files": [
|
|
6
10
|
"dist",
|
|
7
11
|
"README.md",
|
|
@@ -24,22 +28,21 @@
|
|
|
24
28
|
"access": "public"
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|
|
27
|
-
"build": "tsc -b tsconfig.json",
|
|
28
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
29
31
|
"test": "vitest run"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
|
-
"@signature-kit/certificates": "^0.
|
|
33
|
-
"@signature-kit/
|
|
34
|
-
"@signature-kit/
|
|
35
|
-
"
|
|
34
|
+
"@signature-kit/certificates": "^0.3.0",
|
|
35
|
+
"@signature-kit/crypto": "^0.2.1",
|
|
36
|
+
"@signature-kit/http": "^0.1.0",
|
|
37
|
+
"@signature-kit/signatures": "^0.2.0",
|
|
38
|
+
"effect": "4.0.5"
|
|
36
39
|
},
|
|
37
40
|
"nx": {
|
|
38
41
|
"targets": {
|
|
39
42
|
"npm-pack": {
|
|
40
43
|
"executor": "nx:run-commands",
|
|
41
44
|
"options": {
|
|
42
|
-
"command": "
|
|
45
|
+
"command": "bun pm pack --dry-run",
|
|
43
46
|
"cwd": "{projectRoot}"
|
|
44
47
|
}
|
|
45
48
|
},
|