@distilled.cloud/acme 1.0.0-rc.13 → 1.0.0-rc.14

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.
Files changed (43) hide show
  1. package/README.md +8 -6
  2. package/lib/credentials.d.ts.map +1 -1
  3. package/lib/credentials.js.map +1 -1
  4. package/lib/errors.d.ts.map +1 -1
  5. package/lib/errors.js +1 -1
  6. package/lib/errors.js.map +1 -1
  7. package/lib/index.d.ts +4 -4
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.js +4 -4
  10. package/lib/index.js.map +1 -1
  11. package/lib/jose.d.ts.map +1 -1
  12. package/lib/jose.js +4 -11
  13. package/lib/jose.js.map +1 -1
  14. package/lib/protocol.d.ts +4 -4
  15. package/lib/protocol.d.ts.map +1 -1
  16. package/lib/protocol.js +12 -18
  17. package/lib/protocol.js.map +1 -1
  18. package/lib/protocol.test.d.ts +2 -0
  19. package/lib/protocol.test.d.ts.map +1 -0
  20. package/lib/protocol.test.js +533 -0
  21. package/lib/protocol.test.js.map +1 -0
  22. package/lib/retry.d.ts +1 -1
  23. package/lib/retry.d.ts.map +1 -1
  24. package/lib/retry.js +1 -1
  25. package/lib/retry.js.map +1 -1
  26. package/lib/services/acme.d.ts +83 -20
  27. package/lib/services/acme.d.ts.map +1 -1
  28. package/lib/services/acme.js +72 -130
  29. package/lib/services/acme.js.map +1 -1
  30. package/package.json +15 -10
  31. package/src/credentials.ts +13 -19
  32. package/src/errors.ts +15 -25
  33. package/src/index.ts +4 -8
  34. package/src/jose.ts +14 -41
  35. package/src/protocol.test.ts +806 -0
  36. package/src/protocol.ts +32 -81
  37. package/src/retry.ts +2 -8
  38. package/src/services/acme.ts +178 -222
  39. package/lib/response-validation.test.d.ts +0 -4
  40. package/lib/response-validation.test.d.ts.map +0 -1
  41. package/lib/response-validation.test.js +0 -51
  42. package/lib/response-validation.test.js.map +0 -1
  43. package/src/response-validation.test.ts +0 -65
package/src/errors.ts CHANGED
@@ -26,6 +26,7 @@ export {
26
26
  DEFAULT_ERRORS,
27
27
  API_ERRORS,
28
28
  } from "@distilled.cloud/core/errors";
29
+ import * as Category from "@distilled.cloud/core/category";
29
30
  import type {
30
31
  BadRequest as CoreBadRequest,
31
32
  Conflict as CoreConflict,
@@ -34,34 +35,27 @@ import type {
34
35
  NotFound as CoreNotFound,
35
36
  } from "@distilled.cloud/core/errors";
36
37
  import * as Schema from "effect/Schema";
37
- import * as Category from "@distilled.cloud/core/category";
38
38
 
39
39
  /**
40
40
  * Unknown ACME error — a problem document whose `type` matches no typed
41
41
  * class on the operation. Carries structured problem fields and a redacted
42
42
  * body. Add newly observed URNs to the authored model.
43
43
  */
44
- export class UnknownAcmeError extends Schema.TaggedError<UnknownAcmeError>()(
45
- "UnknownAcmeError",
46
- {
47
- /** The problem `type` URN, when the body was a problem document. */
48
- type: Schema.optional(Schema.String),
49
- message: Schema.optional(Schema.String),
50
- status: Schema.optional(Schema.Number),
51
- detail: Schema.optional(Schema.String),
52
- subproblems: Schema.optional(Schema.Array(Schema.Unknown)),
53
- body: Schema.Unknown,
54
- },
55
- ) {}
44
+ export class UnknownAcmeError extends Schema.TaggedError<UnknownAcmeError>()("UnknownAcmeError", {
45
+ /** The problem `type` URN, when the body was a problem document. */
46
+ type: Schema.optional(Schema.String),
47
+ message: Schema.optional(Schema.String),
48
+ status: Schema.optional(Schema.Number),
49
+ detail: Schema.optional(Schema.String),
50
+ subproblems: Schema.optional(Schema.Array(Schema.Unknown)),
51
+ body: Schema.Unknown,
52
+ }) {}
56
53
 
57
54
  /** Schema parse error wrapper. */
58
- export class AcmeParseError extends Schema.TaggedError<AcmeParseError>()(
59
- "AcmeParseError",
60
- {
61
- body: Schema.Unknown,
62
- cause: Schema.Unknown,
63
- },
64
- ).pipe(Category.withParseError) {}
55
+ export class AcmeParseError extends Schema.TaggedError<AcmeParseError>()("AcmeParseError", {
56
+ body: Schema.Unknown,
57
+ cause: Schema.Unknown,
58
+ }).pipe(Category.withParseError) {}
65
59
 
66
60
  /** The account key could not be parsed or used to sign (client-side). */
67
61
  export class JoseError extends Schema.TaggedError<JoseError>()("JoseError", {
@@ -82,11 +76,7 @@ export class DirectoryMissingResource extends Schema.TaggedError<DirectoryMissin
82
76
  ).pipe(Category.withBadRequestError) {}
83
77
 
84
78
  /** Errors any ACME operation may surface beyond the core HTTP defaults. */
85
- export type ClientErrors =
86
- | UnknownAcmeError
87
- | AcmeParseError
88
- | JoseError
89
- | DirectoryMissingResource;
79
+ export type ClientErrors = UnknownAcmeError | AcmeParseError | JoseError | DirectoryMissingResource;
90
80
 
91
81
  /**
92
82
  * Default ACME operation errors: the shared HTTP status errors from core plus
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @distilled.cloud/acme — ACME (RFC 8555) SDK for Effect.
3
3
  *
4
- * `./services` is generated by `scripts/generate.ts` from the hand-authored
5
- * Smithy model in `manual-specs/acme.json` (RFC 8555 — there is no vendor spec for
6
- * a protocol). Everything else in this folder is hand-written: the
4
+ * `./services` is generated by `scripts/generate.ts` from the Smithy model
5
+ * `scripts/convert.ts` builds from RFC 8555 (there is no vendor spec for a
6
+ * protocol). Everything else in this folder is hand-written: the
7
7
  * JWS-signing protocol, credentials (account key + directory + EAB), JOSE
8
8
  * helpers, retry and errors.
9
9
  *
@@ -25,9 +25,5 @@ export * from "./errors.ts";
25
25
  export * as Jose from "./jose.ts";
26
26
  export * as T from "./traits.ts";
27
27
  export * as Retry from "./retry.ts";
28
- export {
29
- AcmeProtocol,
30
- type AcmeOpError,
31
- type AcmeOpContext,
32
- } from "./protocol.ts";
28
+ export { AcmeProtocol, type AcmeOpError, type AcmeOpContext } from "./protocol.ts";
33
29
  export * from "./services/index.ts";
package/src/jose.ts CHANGED
@@ -29,10 +29,7 @@ export const base64url = (bytes: Uint8Array | ArrayBuffer): string => {
29
29
  const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
30
30
  let binary = "";
31
31
  for (const byte of view) binary += String.fromCharCode(byte);
32
- return btoa(binary)
33
- .replaceAll("+", "-")
34
- .replaceAll("/", "_")
35
- .replace(/=+$/, "");
32
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
36
33
  };
37
34
 
38
35
  export const base64urlDecode = (text: string): Uint8Array => {
@@ -43,20 +40,16 @@ export const base64urlDecode = (text: string): Uint8Array => {
43
40
  return out;
44
41
  };
45
42
 
46
- const base64urlJson = (value: unknown): string =>
47
- base64url(encoder.encode(JSON.stringify(value)));
43
+ const base64urlJson = (value: unknown): string => base64url(encoder.encode(JSON.stringify(value)));
48
44
 
49
45
  const sha256 = (data: Uint8Array | string): Effect.Effect<Uint8Array> =>
50
46
  Effect.promise(async () => {
51
47
  const bytes = typeof data === "string" ? encoder.encode(data) : data;
52
- return new Uint8Array(
53
- await crypto.subtle.digest("SHA-256", bytes as Uint8Array<ArrayBuffer>),
54
- );
48
+ return new Uint8Array(await crypto.subtle.digest("SHA-256", bytes as Uint8Array<ArrayBuffer>));
55
49
  });
56
50
 
57
51
  /** Detect the JWS algorithm for a JWK. */
58
- export const algorithmOf = (jwk: Jwk): Algorithm =>
59
- jwk.kty === "RSA" ? "RS256" : "ES256";
52
+ export const algorithmOf = (jwk: Jwk): Algorithm => (jwk.kty === "RSA" ? "RS256" : "ES256");
60
53
 
61
54
  const importAlgorithm = (alg: Algorithm) =>
62
55
  alg === "RS256"
@@ -64,9 +57,7 @@ const importAlgorithm = (alg: Algorithm) =>
64
57
  : { name: "ECDSA", namedCurve: "P-256" };
65
58
 
66
59
  const signAlgorithm = (alg: Algorithm) =>
67
- alg === "RS256"
68
- ? { name: "RSASSA-PKCS1-v1_5" }
69
- : { name: "ECDSA", hash: "SHA-256" };
60
+ alg === "RS256" ? { name: "RSASSA-PKCS1-v1_5" } : { name: "ECDSA", hash: "SHA-256" };
70
61
 
71
62
  /** Generate a fresh account key as a private JWK (JSON text, Redacted). */
72
63
  export const generateAccountKey = (
@@ -90,12 +81,9 @@ export const generateAccountKey = (
90
81
  });
91
82
 
92
83
  /** Parse a private JWK from its JSON text. */
93
- export const parseJwk = (
94
- key: Redacted.Redacted<string> | string,
95
- ): Effect.Effect<Jwk, JoseError> =>
84
+ export const parseJwk = (key: Redacted.Redacted<string> | string): Effect.Effect<Jwk, JoseError> =>
96
85
  Effect.try({
97
- try: () =>
98
- JSON.parse(Redacted.isRedacted(key) ? Redacted.value(key) : key) as Jwk,
86
+ try: () => JSON.parse(Redacted.isRedacted(key) ? Redacted.value(key) : key) as Jwk,
99
87
  catch: (cause) =>
100
88
  new JoseError({
101
89
  message: "The account key is not a JSON Web Key.",
@@ -114,21 +102,12 @@ export const thumbprint = (jwk: Jwk): Effect.Effect<string> =>
114
102
  sha256(JSON.stringify(publicJwk(jwk))).pipe(Effect.map(base64url));
115
103
 
116
104
  /** `<token>.<thumbprint>` — what a challenge proves the client holds. */
117
- export const keyAuthorization = (
118
- token: string,
119
- jwk: Jwk,
120
- ): Effect.Effect<string> =>
105
+ export const keyAuthorization = (token: string, jwk: Jwk): Effect.Effect<string> =>
121
106
  thumbprint(jwk).pipe(Effect.map((print) => `${token}.${print}`));
122
107
 
123
108
  /** The TXT record value for a DNS-01 challenge: base64url(SHA-256(keyAuthorization)). */
124
- export const dnsChallengeValue = (
125
- token: string,
126
- jwk: Jwk,
127
- ): Effect.Effect<string> =>
128
- keyAuthorization(token, jwk).pipe(
129
- Effect.flatMap(sha256),
130
- Effect.map(base64url),
131
- );
109
+ export const dnsChallengeValue = (token: string, jwk: Jwk): Effect.Effect<string> =>
110
+ keyAuthorization(token, jwk).pipe(Effect.flatMap(sha256), Effect.map(base64url));
132
111
 
133
112
  export interface FlattenedJws {
134
113
  readonly protected: string;
@@ -147,9 +126,7 @@ export interface SignOptions {
147
126
  }
148
127
 
149
128
  /** Sign an ACME request body (RFC 8555 §6.2) with the account key. */
150
- export const signRequest = (
151
- options: SignOptions,
152
- ): Effect.Effect<FlattenedJws, JoseError> =>
129
+ export const signRequest = (options: SignOptions): Effect.Effect<FlattenedJws, JoseError> =>
153
130
  Effect.tryPromise({
154
131
  try: async () => {
155
132
  const alg = algorithmOf(options.jwk);
@@ -157,13 +134,10 @@ export const signRequest = (
157
134
  alg,
158
135
  nonce: options.nonce,
159
136
  url: options.url,
160
- ...(options.kid !== undefined
161
- ? { kid: options.kid }
162
- : { jwk: publicJwk(options.jwk) }),
137
+ ...(options.kid !== undefined ? { kid: options.kid } : { jwk: publicJwk(options.jwk) }),
163
138
  };
164
139
  const protectedB64 = base64urlJson(header);
165
- const payloadB64 =
166
- options.payload === undefined ? "" : base64urlJson(options.payload);
140
+ const payloadB64 = options.payload === undefined ? "" : base64urlJson(options.payload);
167
141
  const key = await crypto.subtle.importKey(
168
142
  "jwk",
169
143
  options.jwk as JsonWebKey,
@@ -182,8 +156,7 @@ export const signRequest = (
182
156
  signature: base64url(signature),
183
157
  };
184
158
  },
185
- catch: (cause) =>
186
- new JoseError({ message: "Signing the ACME request failed.", cause }),
159
+ catch: (cause) => new JoseError({ message: "Signing the ACME request failed.", cause }),
187
160
  });
188
161
 
189
162
  /**