@signature-kit/a1 0.3.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 +13 -0
- package/README.md +1 -1
- package/dist/config.d.ts +2 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -6
- package/dist/signer.d.ts +3 -25
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +44 -87
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
3
16
|
## 0.3.0
|
|
4
17
|
|
|
5
18
|
- Emit distinct `SignatureKitError` codes for expired, not-yet-valid, and
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ bun add @signature-kit/a1 @signature-kit/signatures effect
|
|
|
13
13
|
## Public surface
|
|
14
14
|
|
|
15
15
|
- `@signature-kit/a1/config` — `A1SignerOptionsSchema`, remote-source schemas, and `A1CertificateProfileSchema`.
|
|
16
|
-
- `@signature-kit/a1/signer` — `createA1SignerAdapter`, `loadA1SignerAdapter`, `
|
|
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
|
|
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,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A1 signer adapter options.
|
|
3
|
-
*/
|
|
4
1
|
import { redactedStringSchema } from "@signature-kit/signatures";
|
|
5
2
|
import { SignatureHttpHeadersSchema } from "@signature-kit/http";
|
|
6
3
|
import { Schema } from "effect";
|
|
@@ -9,9 +6,7 @@ export const A1SignerOptionsSchema = Schema.Struct({
|
|
|
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
|
-
* The first e-signature adapter: A1 / PKCS#12.
|
|
3
|
-
*/
|
|
4
|
-
import { Signatures } from "@signature-kit/signatures";
|
|
1
|
+
import { Signatures, SignatureKitError } from "@signature-kit/signatures";
|
|
5
2
|
import { SignatureHttpClient } from "@signature-kit/http";
|
|
6
3
|
import type { Certificate, SignerAdapter } from "@signature-kit/signatures";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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}. */
|
|
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,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* The first e-signature adapter: A1 / PKCS#12.
|
|
3
|
-
*/
|
|
4
|
-
import { Signatures } from "@signature-kit/signatures";
|
|
1
|
+
import { Signatures, SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, SignInputSchema, VerifyInputSchema, } from "@signature-kit/signatures";
|
|
5
2
|
import { SignatureHttpClient } from "@signature-kit/http";
|
|
6
|
-
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, SignInputSchema, VerifyInputSchema, } from "@signature-kit/signatures";
|
|
7
3
|
import { daysUntilExpiry, parseCertificate, toSignerIdentity } from "@signature-kit/certificates";
|
|
8
4
|
import { pemToDer } from "@signature-kit/crypto/pem";
|
|
9
|
-
import { Clock,
|
|
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";
|
|
12
8
|
const RsaAlgorithmHashSchema = Schema.Literals(["SHA-1", "SHA-256", "SHA-512"]);
|
|
13
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);
|
|
@@ -15,7 +11,6 @@ const rsaAlgorithm = (algorithm) => ({
|
|
|
15
11
|
name: RSA_ALGORITHM_NAME,
|
|
16
12
|
hash: rsaAlgorithmHash(algorithm),
|
|
17
13
|
});
|
|
18
|
-
/** Copy into a fresh ArrayBuffer-backed view so it satisfies `BufferSource`. */
|
|
19
14
|
const toBufferSource = (data) => {
|
|
20
15
|
const copy = new Uint8Array(data.byteLength);
|
|
21
16
|
copy.set(data);
|
|
@@ -58,48 +53,43 @@ const verifyWithKey = (key, algorithm, signature, content) => Effect.tryPromise(
|
|
|
58
53
|
operation: SignatureKitOperationValue.cryptoVerify,
|
|
59
54
|
}),
|
|
60
55
|
});
|
|
61
|
-
export class A1Signer extends Context.Service()("@signature-kit/a1/Signer") {
|
|
62
|
-
}
|
|
63
|
-
/** Cache WebCrypto imports per adapter and algorithm. */
|
|
64
56
|
const cachedKey = (cache, algorithm, load) => {
|
|
65
57
|
const cached = cache.get(algorithm);
|
|
66
58
|
if (cached !== undefined)
|
|
67
59
|
return Effect.succeed(cached);
|
|
68
60
|
return load(algorithm).pipe(Effect.tap((key) => Effect.sync(() => cache.set(algorithm, key))));
|
|
69
61
|
};
|
|
70
|
-
const loadA1Certificate = (options) => Schema.decodeUnknownEffect(A1SignerOptionsSchema)(options).pipe(Effect.mapError((issue) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
}), 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)));
|
|
80
70
|
const certificateProfile = (certificate) => Effect.gen(function* () {
|
|
81
71
|
const currentTime = yield* Clock.currentTimeMillis;
|
|
82
72
|
if (currentTime > certificate.validity.notAfter.getTime()) {
|
|
83
|
-
return yield*
|
|
73
|
+
return yield* new SignatureKitError({
|
|
84
74
|
code: SignatureKitErrorCodeValue.certificateExpired,
|
|
85
75
|
retryable: false,
|
|
86
76
|
reason: `A1 certificate expired at ${certificate.validity.notAfter.toISOString()}.`,
|
|
87
|
-
})
|
|
77
|
+
});
|
|
88
78
|
}
|
|
89
79
|
if (currentTime < certificate.validity.notBefore.getTime()) {
|
|
90
|
-
return yield*
|
|
80
|
+
return yield* new SignatureKitError({
|
|
91
81
|
code: SignatureKitErrorCodeValue.certificateNotYetValid,
|
|
92
82
|
retryable: false,
|
|
93
83
|
reason: `A1 certificate is not valid before ${certificate.validity.notBefore.toISOString()}.`,
|
|
94
|
-
})
|
|
84
|
+
});
|
|
95
85
|
}
|
|
96
86
|
const document = certificate.brazilian.cnpj ?? certificate.brazilian.cpf;
|
|
97
87
|
if (document === null) {
|
|
98
|
-
return yield*
|
|
88
|
+
return yield* new SignatureKitError({
|
|
99
89
|
code: SignatureKitErrorCodeValue.missingBrIdentifier,
|
|
100
90
|
retryable: false,
|
|
101
91
|
reason: "A1 certificate does not contain a Brazilian CPF or CNPJ.",
|
|
102
|
-
})
|
|
92
|
+
});
|
|
103
93
|
}
|
|
104
94
|
return {
|
|
105
95
|
document,
|
|
@@ -113,7 +103,6 @@ const certificateProfile = (certificate) => Effect.gen(function* () {
|
|
|
113
103
|
daysUntilExpiry: daysUntilExpiry(certificate),
|
|
114
104
|
};
|
|
115
105
|
});
|
|
116
|
-
/** Build an A1 signer adapter from an already-parsed core {@link Certificate}. */
|
|
117
106
|
export const createA1SignerAdapter = (certificate) => {
|
|
118
107
|
const privateKeys = new Map();
|
|
119
108
|
const publicKeys = new Map();
|
|
@@ -124,62 +113,39 @@ export const createA1SignerAdapter = (certificate) => {
|
|
|
124
113
|
inspect: () => Effect.succeed(toSignerIdentity(certificate)),
|
|
125
114
|
certificate: () => Effect.succeed(certificate),
|
|
126
115
|
importSigningKey: signingKey,
|
|
127
|
-
sign: (input) => Schema.decodeUnknownEffect(SignInputSchema)(input).pipe(Effect.mapError((issue) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
schemaName: "VerifyInput",
|
|
144
|
-
issueMessage: String(issue),
|
|
145
|
-
});
|
|
146
|
-
}), 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 }))))),
|
|
147
132
|
};
|
|
148
133
|
};
|
|
149
|
-
const loadA1SignerMaterial = (options) => loadA1Certificate(options).pipe(Effect.flatMap((certificate) => certificateProfile(certificate).pipe(Effect.map((profile) => ({
|
|
150
|
-
certificate,
|
|
151
|
-
profile,
|
|
152
|
-
signer: createA1SignerAdapter(certificate),
|
|
153
|
-
})))));
|
|
154
|
-
/** Load an A1 container and expose its parsed certificate, profile, and signer. */
|
|
155
|
-
export const a1SignerLayer = (options) => Layer.effect(A1Signer, loadA1SignerMaterial(options));
|
|
156
|
-
/** Load an A1 container and build the adapter in one Effect. */
|
|
157
134
|
export const loadA1SignerAdapter = (options) => loadA1Certificate(options).pipe(Effect.map(createA1SignerAdapter));
|
|
158
|
-
/** Parse and validate the certificate metadata most app integrations store. */
|
|
159
135
|
export const parseA1CertificateProfile = (options) => loadA1Certificate(options).pipe(Effect.flatMap(certificateProfile));
|
|
160
|
-
/** Load an A1 container and provide the agnostic core Signatures service. */
|
|
161
136
|
export const a1SignaturesLayer = (options) => Layer.effect(Signatures, loadA1Certificate(options).pipe(Effect.map(createA1SignerAdapter)));
|
|
162
|
-
// ---------------------------------------------------------------------------
|
|
163
|
-
// Remote A1 material — fetch the PKCS#12 (.pfx) from a (presigned) URL.
|
|
164
|
-
//
|
|
165
|
-
// The A1 container usually lives in object storage (e.g. S3) and is handed to
|
|
166
|
-
// the signer as a short-lived presigned URL. Fetching is the ONLY thing that
|
|
167
|
-
// changes versus the local-bytes path: the fetched bytes flow into exactly the
|
|
168
|
-
// same loadA1Certificate -> createA1SignerAdapter pipeline, so the signer, the
|
|
169
|
-
// profile, and the Signatures layer behave identically. The private key never
|
|
170
|
-
// leaves this process — only the encrypted PKCS#12 is fetched, then decrypted
|
|
171
|
-
// locally with the Redacted password.
|
|
172
|
-
// ---------------------------------------------------------------------------
|
|
173
137
|
const redactPresignedUrl = (url) => {
|
|
174
138
|
if (!URL.canParse(url))
|
|
175
139
|
return "<redacted>";
|
|
176
140
|
const sanitized = new URL(url);
|
|
141
|
+
sanitized.username = "";
|
|
142
|
+
sanitized.password = "";
|
|
143
|
+
sanitized.hash = "";
|
|
177
144
|
for (const key of sanitized.searchParams.keys()) {
|
|
178
145
|
sanitized.searchParams.set(key, "<redacted>");
|
|
179
146
|
}
|
|
180
147
|
return sanitized.toString();
|
|
181
148
|
};
|
|
182
|
-
/** Fetch the A1 PKCS#12 (.pfx) bytes from a (presigned) URL via a GET. */
|
|
183
149
|
export const fetchA1Pkcs12 = (source) => Schema.decodeUnknownEffect(A1RemoteFetchSchema)(source).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
184
150
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
185
151
|
retryable: false,
|
|
@@ -193,26 +159,17 @@ export const fetchA1Pkcs12 = (source) => Schema.decodeUnknownEffect(A1RemoteFetc
|
|
|
193
159
|
diagnosticUrl: redactPresignedUrl(valid.url),
|
|
194
160
|
...(valid.headers === undefined ? {} : { headers: valid.headers }),
|
|
195
161
|
})
|
|
196
|
-
.pipe(Effect.
|
|
197
|
-
|
|
198
|
-
code: SignatureKitErrorCodeValue.emptyFile,
|
|
199
|
-
retryable: false,
|
|
200
|
-
reason: "The fetched A1 certificate is empty.",
|
|
201
|
-
}))
|
|
202
|
-
: Effect.succeed(bytes))))));
|
|
203
|
-
/** Provide the agnostic core Signatures service from a remote (URL) A1 container. */
|
|
204
|
-
export const a1SignaturesLayerFromUrl = (source) => Layer.effect(Signatures, Schema.decodeUnknownEffect(A1RemoteSourceSchema)(source).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
205
|
-
code: SignatureKitErrorCodeValue.invalidInput,
|
|
162
|
+
.pipe(Effect.filterOrFail((bytes) => bytes.byteLength !== 0, () => new SignatureKitError({
|
|
163
|
+
code: SignatureKitErrorCodeValue.emptyFile,
|
|
206
164
|
retryable: false,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
})), Effect.flatMap((valid) => fetchA1Pkcs12(valid).pipe(Effect.flatMap((pfx) => loadA1Certificate({ pfx, password: valid.password })), Effect.map(createA1SignerAdapter)))));
|
|
211
|
-
/** Parse and validate the A1 certificate metadata from a remote (URL) container. */
|
|
212
|
-
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({
|
|
213
168
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
214
169
|
retryable: false,
|
|
215
170
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
216
171
|
schemaName: "A1RemoteSource",
|
|
217
172
|
issueMessage: String(issue),
|
|
218
|
-
})), 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,23 +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.
|
|
34
|
+
"@signature-kit/certificates": "^0.3.0",
|
|
33
35
|
"@signature-kit/crypto": "^0.2.1",
|
|
34
36
|
"@signature-kit/http": "^0.1.0",
|
|
35
|
-
"@signature-kit/signatures": "^0.
|
|
36
|
-
"effect": "4.0.
|
|
37
|
+
"@signature-kit/signatures": "^0.2.0",
|
|
38
|
+
"effect": "4.0.5"
|
|
37
39
|
},
|
|
38
40
|
"nx": {
|
|
39
41
|
"targets": {
|
|
40
42
|
"npm-pack": {
|
|
41
43
|
"executor": "nx:run-commands",
|
|
42
44
|
"options": {
|
|
43
|
-
"command": "
|
|
45
|
+
"command": "bun pm pack --dry-run",
|
|
44
46
|
"cwd": "{projectRoot}"
|
|
45
47
|
}
|
|
46
48
|
},
|