@distilled.cloud/acme 0.0.0-placeholder → 1.0.0-rc.13

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 (53) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +73 -0
  3. package/lib/credentials.d.ts +50 -0
  4. package/lib/credentials.d.ts.map +1 -0
  5. package/lib/credentials.js +57 -0
  6. package/lib/credentials.js.map +1 -0
  7. package/lib/errors.d.ts +73 -0
  8. package/lib/errors.d.ts.map +1 -0
  9. package/lib/errors.js +50 -0
  10. package/lib/errors.js.map +1 -0
  11. package/lib/index.d.ts +30 -0
  12. package/lib/index.d.ts.map +1 -0
  13. package/lib/index.js +30 -0
  14. package/lib/index.js.map +1 -0
  15. package/lib/jose.d.ts +66 -0
  16. package/lib/jose.d.ts.map +1 -0
  17. package/lib/jose.js +128 -0
  18. package/lib/jose.js.map +1 -0
  19. package/lib/protocol.d.ts +27 -0
  20. package/lib/protocol.d.ts.map +1 -0
  21. package/lib/protocol.js +410 -0
  22. package/lib/protocol.js.map +1 -0
  23. package/lib/response-validation.test.d.ts +4 -0
  24. package/lib/response-validation.test.d.ts.map +1 -0
  25. package/lib/response-validation.test.js +51 -0
  26. package/lib/response-validation.test.js.map +1 -0
  27. package/lib/retry.d.ts +33 -0
  28. package/lib/retry.d.ts.map +1 -0
  29. package/lib/retry.js +33 -0
  30. package/lib/retry.js.map +1 -0
  31. package/lib/services/acme.d.ts +446 -0
  32. package/lib/services/acme.d.ts.map +1 -0
  33. package/lib/services/acme.js +597 -0
  34. package/lib/services/acme.js.map +1 -0
  35. package/lib/services/index.d.ts +2 -0
  36. package/lib/services/index.d.ts.map +1 -0
  37. package/lib/services/index.js +3 -0
  38. package/lib/services/index.js.map +1 -0
  39. package/lib/traits.d.ts +13 -0
  40. package/lib/traits.d.ts.map +1 -0
  41. package/lib/traits.js +13 -0
  42. package/lib/traits.js.map +1 -0
  43. package/package.json +75 -7
  44. package/src/credentials.ts +106 -0
  45. package/src/errors.ts +101 -0
  46. package/src/index.ts +33 -0
  47. package/src/jose.ts +234 -0
  48. package/src/protocol.ts +582 -0
  49. package/src/response-validation.test.ts +65 -0
  50. package/src/retry.ts +55 -0
  51. package/src/services/acme.ts +1140 -0
  52. package/src/services/index.ts +2 -0
  53. package/src/traits.ts +46 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # ACME for Effect
2
+
3
+ `@distilled.cloud/acme` implements the ACME account and certificate lifecycle
4
+ with Effect and WebCrypto. Install it alongside `effect`, save this as
5
+ `example.ts`, and run `bun example.ts` to read Let's Encrypt's staging directory:
6
+
7
+ ```ts
8
+ import * as Acme from "@distilled.cloud/acme";
9
+ import * as Effect from "effect/Effect";
10
+ import * as FetchHttpClient from "effect/http/FetchHttpClient";
11
+
12
+ const program = Effect.gen(function* () {
13
+ const accountKey = yield* Acme.Jose.generateAccountKey();
14
+ return yield* Acme.acme.getDirectory({}).pipe(
15
+ Effect.provide(Acme.layer({
16
+ directoryUrl: Acme.Directories.LetsEncryptStaging,
17
+ accountKey,
18
+ })),
19
+ );
20
+ });
21
+
22
+ const directory = await Effect.runPromise(
23
+ program.pipe(Effect.provide(FetchHttpClient.layer)),
24
+ );
25
+ console.log(directory.newOrder);
26
+ ```
27
+
28
+ ## Authentication
29
+
30
+ Signed requests use a private JWK (`Redacted<string>`), supporting ES256/P-256
31
+ and RS256. Persist your account key securely; do not generate a new key per
32
+ issuance. After `acme.newAccount`, supply its `location` as `accountUrl` to
33
+ `Acme.layer`. CAs requiring External Account Binding also need
34
+ `externalAccountBinding: { keyId, hmacKey }`; `hmacKey` is redacted.
35
+
36
+ `CredentialsFromEnv` reads `ACME_ACCOUNT_KEY`, `ACME_ACCOUNT_URL`,
37
+ `ACME_DIRECTORY_URL`, and the optional `ACME_EAB_KID` / `ACME_EAB_HMAC_KEY` pair.
38
+ The default directory is Let's Encrypt **production**; explicitly choose staging
39
+ when testing. A staging certificate is not publicly trusted.
40
+
41
+ ## Responses and retries
42
+
43
+ Operations remain under `Acme.acme` (or the `@distilled.cloud/acme/acme`
44
+ subpath). JSON outputs are schema-validated; HEAD nonce, PEM chain, and empty
45
+ revocation responses retain their respective output shapes. Parse errors omit
46
+ raw bodies and parser diagnostics that could contain secrets.
47
+
48
+ The protocol retries `badNonce` at most twice, re-signing with the nonce on that
49
+ request's rejection. These nonces never enter the shared cache; ordinary nonces
50
+ are cached by the full directory URL. Exhausted recovery surfaces
51
+ `AcmeBadNonce`, not an indefinitely retryable server fault. Typed rate-limit
52
+ errors expose `retryAfter` as an optional Effect `Duration`. Other retries use
53
+ the shared SDK policy, configurable through `Acme.Retry`.
54
+
55
+ Unrecognized problem URNs surface as `UnknownAcmeError` with `type`, `status`,
56
+ `detail`, and `subproblems`, plus a redacted body; they are not classified as
57
+ server errors merely because their URN is unknown.
58
+
59
+ ## Source and limitations
60
+
61
+ [`manual-specs/acme.json`](./manual-specs/acme.json) is authored from
62
+ [RFC 8555](https://www.rfc-editor.org/rfc/rfc8555), not downloaded or mirrored.
63
+ Edit that model and the handwritten protocol, never generated service files.
64
+ From this package directory, regenerate with `bun scripts/generate.ts`; format
65
+ changed paths with `pnpm exec oxfmt <paths>` from the workspace root.
66
+
67
+ The SDK covers directory discovery, nonces, accounts, orders, authorizations,
68
+ challenge responses, certificate downloads, and revocation. It does not deploy
69
+ DNS/HTTP challenges, generate CSRs, schedule renewal, implement account-key
70
+ rollover, or implement ACME Renewal Information. Callers own those workflows,
71
+ CA terms acceptance, polling limits, and certificate/key storage. Directory
72
+ metadata is cached in-process; `resetProtocolCaches` from the `Protocol` subpath
73
+ clears directory and nonce caches.
@@ -0,0 +1,50 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Redacted from "effect/Redacted";
5
+ /** Well-known ACME directories. */
6
+ export declare const Directories: {
7
+ readonly LetsEncrypt: "https://acme-v02.api.letsencrypt.org/directory";
8
+ readonly LetsEncryptStaging: "https://acme-staging-v02.api.letsencrypt.org/directory";
9
+ readonly ZeroSSL: "https://acme.zerossl.com/v2/DV90";
10
+ readonly GoogleTrustServices: "https://dv.acme-v02.api.pki.goog/directory";
11
+ readonly GoogleTrustServicesStaging: "https://dv.acme-v02.test-api.pki.goog/directory";
12
+ };
13
+ export interface ExternalAccountBinding {
14
+ /** The CA-issued EAB key id. */
15
+ readonly keyId: string;
16
+ /** The CA-issued base64url HMAC key. */
17
+ readonly hmacKey: Redacted.Redacted<string>;
18
+ }
19
+ export interface Config {
20
+ /** The CA's directory URL. */
21
+ readonly directoryUrl: string;
22
+ /**
23
+ * The account's private key as a JSON Web Key (JSON text). ES256 (`EC`
24
+ * P-256) by default; RS256 (`RSA`) is accepted.
25
+ */
26
+ readonly accountKey: Redacted.Redacted<string>;
27
+ /**
28
+ * The account URL the CA assigned (`Location` of `newAccount`). Sent as
29
+ * `kid` on every request once known; `newAccount` uses the bare JWK.
30
+ */
31
+ readonly accountUrl?: string | undefined;
32
+ /** EAB for CAs that require it (ZeroSSL, Google Trust Services). */
33
+ readonly externalAccountBinding?: ExternalAccountBinding | undefined;
34
+ }
35
+ declare const Credentials_base: Context.ServiceClass<Credentials, "AcmeCredentials", Effect.Effect<Config, never, never>>;
36
+ export declare class Credentials extends Credentials_base {
37
+ }
38
+ /**
39
+ * Credentials from the environment:
40
+ *
41
+ * - `ACME_DIRECTORY_URL` (default: Let's Encrypt production)
42
+ * - `ACME_ACCOUNT_KEY` — the private JWK as JSON
43
+ * - `ACME_ACCOUNT_URL` — optional, once the account exists
44
+ * - `ACME_EAB_KID` / `ACME_EAB_HMAC_KEY` — optional EAB pair
45
+ */
46
+ export declare const CredentialsFromEnv: Layer.Layer<Credentials, never, never>;
47
+ /** A fixed credentials layer (tests, and consumers that manage keys themselves). */
48
+ export declare const layer: (config: Config | Effect.Effect<Config>) => Layer.Layer<Credentials, never, never>;
49
+ export {};
50
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C,mCAAmC;AACnC,eAAO,MAAM,WAAW;aACtB,WAAW,EAAE,gDAAgD;aAC7D,kBAAkB,EAAE,wDAAwD;aAC5E,OAAO,EAAE,kCAAkC;aAC3C,mBAAmB,EAAE,4CAA4C;aACjE,0BAA0B,EAAE,iDAAiD;CACrE,CAAC;AAEX,MAAM,WAAW,sBAAsB;IACrC,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,MAAM;IACrB,8BAA8B;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,oEAAoE;IACpE,QAAQ,CAAC,sBAAsB,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;CACtE;;AAED,qBAAa,WAAY,SAAQ,gBAGX;CAAG;AAEzB;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,wCA+B9B,CAAC;AAEF,oFAAoF;AACpF,eAAO,MAAM,KAAK,WAAY,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,2CAIzD,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * ACME credentials — hand-written.
3
+ *
4
+ * An ACME "credential" is the **account key**: a private JWK that signs
5
+ * every request. The CA is addressed by its **directory URL** (Let's
6
+ * Encrypt, ZeroSSL, Google Trust Services and Pebble differ only there),
7
+ * plus, for CAs that require it, an **External Account Binding** (key id +
8
+ * HMAC key from the CA's dashboard) presented once on `newAccount`.
9
+ *
10
+ * The `Credentials` service holds an *effect* that resolves the current
11
+ * credentials, so the protocol picks up a rotated key or a newly learned
12
+ * account URL per request.
13
+ */
14
+ import { ConfigError } from "@distilled.cloud/core/errors";
15
+ import * as EffectConfig from "effect/Config";
16
+ import * as Context from "effect/Context";
17
+ import * as Effect from "effect/Effect";
18
+ import * as Layer from "effect/Layer";
19
+ import * as Option from "effect/Option";
20
+ import * as Redacted from "effect/Redacted";
21
+ /** Well-known ACME directories. */
22
+ export const Directories = {
23
+ LetsEncrypt: "https://acme-v02.api.letsencrypt.org/directory",
24
+ LetsEncryptStaging: "https://acme-staging-v02.api.letsencrypt.org/directory",
25
+ ZeroSSL: "https://acme.zerossl.com/v2/DV90",
26
+ GoogleTrustServices: "https://dv.acme-v02.api.pki.goog/directory",
27
+ GoogleTrustServicesStaging: "https://dv.acme-v02.test-api.pki.goog/directory",
28
+ };
29
+ export class Credentials extends Context.Service()("AcmeCredentials") {
30
+ }
31
+ /**
32
+ * Credentials from the environment:
33
+ *
34
+ * - `ACME_DIRECTORY_URL` (default: Let's Encrypt production)
35
+ * - `ACME_ACCOUNT_KEY` — the private JWK as JSON
36
+ * - `ACME_ACCOUNT_URL` — optional, once the account exists
37
+ * - `ACME_EAB_KID` / `ACME_EAB_HMAC_KEY` — optional EAB pair
38
+ */
39
+ export const CredentialsFromEnv = Layer.succeed(Credentials, EffectConfig.all({
40
+ directoryUrl: EffectConfig.String("ACME_DIRECTORY_URL").pipe(EffectConfig.withDefault(Directories.LetsEncrypt)),
41
+ accountKey: EffectConfig.Redacted("ACME_ACCOUNT_KEY"),
42
+ accountUrl: EffectConfig.option(EffectConfig.String("ACME_ACCOUNT_URL")),
43
+ eabKid: EffectConfig.option(EffectConfig.String("ACME_EAB_KID")),
44
+ eabHmac: EffectConfig.option(EffectConfig.Redacted("ACME_EAB_HMAC_KEY")),
45
+ }).pipe(Effect.mapError(() => new ConfigError({
46
+ message: "ACME_ACCOUNT_KEY (a private JWK) is required; ACME_DIRECTORY_URL, ACME_ACCOUNT_URL, ACME_EAB_KID and ACME_EAB_HMAC_KEY are optional",
47
+ })), Effect.map(({ directoryUrl, accountKey, accountUrl, eabKid, eabHmac }) => ({
48
+ directoryUrl,
49
+ accountKey,
50
+ accountUrl: Option.getOrUndefined(accountUrl),
51
+ externalAccountBinding: Option.isSome(eabKid) && Option.isSome(eabHmac)
52
+ ? { keyId: eabKid.value, hmacKey: eabHmac.value }
53
+ : undefined,
54
+ })), Effect.orDie));
55
+ /** A fixed credentials layer (tests, and consumers that manage keys themselves). */
56
+ export const layer = (config) => Layer.succeed(Credentials, Effect.isEffect(config) ? config : Effect.succeed(config));
57
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C,mCAAmC;AACnC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,WAAW,EAAE,gDAAgD;IAC7D,kBAAkB,EAAE,wDAAwD;IAC5E,OAAO,EAAE,kCAAkC;IAC3C,mBAAmB,EAAE,4CAA4C;IACjE,0BAA0B,EAAE,iDAAiD;CACrE,CAAC;AA0BX,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAG7C,CAAC,iBAAiB,CAAC;CAAG;AAEzB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAC7C,WAAW,EACX,YAAY,CAAC,GAAG,CAAC;IACf,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAC1D,YAAY,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAClD;IACD,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IACrD,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACxE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAChE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;CACzE,CAAC,CAAC,IAAI,CACL,MAAM,CAAC,QAAQ,CACb,GAAG,EAAE,CACH,IAAI,WAAW,CAAC;IACd,OAAO,EACL,qIAAqI;CACxI,CAAC,CACL,EACD,MAAM,CAAC,GAAG,CACR,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,EAAU,EAAE,CAAC,CAAC;IACtE,YAAY;IACZ,UAAU;IACV,UAAU,EAAE,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC;IAC7C,sBAAsB,EACpB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7C,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE;QACjD,CAAC,CAAC,SAAS;CAChB,CAAC,CACH,EACD,MAAM,CAAC,KAAK,CACb,CACF,CAAC;AAEF,oFAAoF;AACpF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAsC,EAAE,EAAE,CAC9D,KAAK,CAAC,OAAO,CACX,WAAW,EACX,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAC1D,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * ACME-specific error types.
3
+ *
4
+ * ACME reports failures as RFC 7807 problem documents whose `type` is a
5
+ * `urn:ietf:params:acme:error:*` URN (RFC 8555 §6.7). Every URN the SDK
6
+ * knows is a typed class in the generated service (patched onto the
7
+ * operations that raise it, matched on the URN by the protocol). This
8
+ * module holds the shared HTTP defaults and the package's own client
9
+ * errors.
10
+ */
11
+ export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
12
+ import type { BadRequest as CoreBadRequest, Conflict as CoreConflict, DefaultErrors as CoreDefaultErrors, Forbidden as CoreForbidden, NotFound as CoreNotFound } from "@distilled.cloud/core/errors";
13
+ import * as Schema from "effect/Schema";
14
+ declare const UnknownAcmeError_base: Schema.Class<UnknownAcmeError, Schema.TaggedStruct<"UnknownAcmeError", {
15
+ /** The problem `type` URN, when the body was a problem document. */
16
+ readonly type: Schema.optional<Schema.String>;
17
+ readonly message: Schema.optional<Schema.String>;
18
+ readonly status: Schema.optional<Schema.Number>;
19
+ readonly detail: Schema.optional<Schema.String>;
20
+ readonly subproblems: Schema.optional<Schema.$Array<Schema.Unknown>>;
21
+ readonly body: Schema.Unknown;
22
+ }>, import("effect/Cause").YieldableError>;
23
+ /**
24
+ * Unknown ACME error — a problem document whose `type` matches no typed
25
+ * class on the operation. Carries structured problem fields and a redacted
26
+ * body. Add newly observed URNs to the authored model.
27
+ */
28
+ export declare class UnknownAcmeError extends UnknownAcmeError_base {
29
+ }
30
+ declare const AcmeParseError_base: Schema.Class<AcmeParseError, Schema.TaggedStruct<"AcmeParseError", {
31
+ readonly body: Schema.Unknown;
32
+ readonly cause: Schema.Unknown;
33
+ }>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
34
+ "@distilled.cloud/error/categories": {
35
+ ParseError: true;
36
+ };
37
+ });
38
+ /** Schema parse error wrapper. */
39
+ export declare class AcmeParseError extends AcmeParseError_base {
40
+ }
41
+ declare const JoseError_base: Schema.Class<JoseError, Schema.TaggedStruct<"JoseError", {
42
+ readonly message: Schema.String;
43
+ readonly cause: Schema.optional<Schema.Unknown>;
44
+ }>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
45
+ "@distilled.cloud/error/categories": {
46
+ BadRequestError: true;
47
+ };
48
+ });
49
+ /** The account key could not be parsed or used to sign (client-side). */
50
+ export declare class JoseError extends JoseError_base {
51
+ }
52
+ declare const DirectoryMissingResource_base: Schema.Class<DirectoryMissingResource, Schema.TaggedStruct<"DirectoryMissingResource", {
53
+ readonly resource: Schema.String;
54
+ readonly directoryUrl: Schema.String;
55
+ }>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
56
+ "@distilled.cloud/error/categories": {
57
+ BadRequestError: true;
58
+ };
59
+ });
60
+ /**
61
+ * The directory has no URL for the requested resource (a CA without
62
+ * `newAuthz`/`keyChange`, or a stale directory URL).
63
+ */
64
+ export declare class DirectoryMissingResource extends DirectoryMissingResource_base {
65
+ }
66
+ /** Errors any ACME operation may surface beyond the core HTTP defaults. */
67
+ export type ClientErrors = UnknownAcmeError | AcmeParseError | JoseError | DirectoryMissingResource;
68
+ /**
69
+ * Default ACME operation errors: the shared HTTP status errors from core plus
70
+ * the client errors above.
71
+ */
72
+ export type DefaultErrors = CoreDefaultErrors | CoreBadRequest | CoreForbidden | CoreNotFound | CoreConflict | ClientErrors;
73
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,UAAU,IAAI,cAAc,EAC5B,QAAQ,IAAI,YAAY,EACxB,aAAa,IAAI,iBAAiB,EAClC,SAAS,IAAI,aAAa,EAC1B,QAAQ,IAAI,YAAY,EACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;IAWpC,oEAAoE;;;;;;;;AARxE;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,qBAWrC;CAAG;;;;;;;;;AAEJ,kCAAkC;AAClC,qBAAa,cAAe,SAAQ,mBAML;CAAG;;;;;;;;;AAElC,yEAAyE;AACzE,qBAAa,SAAU,SAAQ,cAGM;CAAG;;;;;;;;;AAExC;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,6BAMV;CAAG;AAEvC,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GACpB,gBAAgB,GAChB,cAAc,GACd,SAAS,GACT,wBAAwB,CAAC;AAE7B;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,cAAc,GACd,aAAa,GACb,YAAY,GACZ,YAAY,GACZ,YAAY,CAAC"}
package/lib/errors.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * ACME-specific error types.
3
+ *
4
+ * ACME reports failures as RFC 7807 problem documents whose `type` is a
5
+ * `urn:ietf:params:acme:error:*` URN (RFC 8555 §6.7). Every URN the SDK
6
+ * knows is a typed class in the generated service (patched onto the
7
+ * operations that raise it, matched on the URN by the protocol). This
8
+ * module holds the shared HTTP defaults and the package's own client
9
+ * errors.
10
+ */
11
+ export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
12
+ import * as Schema from "effect/Schema";
13
+ import * as Category from "@distilled.cloud/core/category";
14
+ /**
15
+ * Unknown ACME error — a problem document whose `type` matches no typed
16
+ * class on the operation. Carries structured problem fields and a redacted
17
+ * body. Add newly observed URNs to the authored model.
18
+ */
19
+ export class UnknownAcmeError extends Schema.TaggedError()("UnknownAcmeError", {
20
+ /** The problem `type` URN, when the body was a problem document. */
21
+ type: Schema.optional(Schema.String),
22
+ message: Schema.optional(Schema.String),
23
+ status: Schema.optional(Schema.Number),
24
+ detail: Schema.optional(Schema.String),
25
+ subproblems: Schema.optional(Schema.Array(Schema.Unknown)),
26
+ body: Schema.Unknown,
27
+ }) {
28
+ }
29
+ /** Schema parse error wrapper. */
30
+ export class AcmeParseError extends Schema.TaggedError()("AcmeParseError", {
31
+ body: Schema.Unknown,
32
+ cause: Schema.Unknown,
33
+ }).pipe(Category.withParseError) {
34
+ }
35
+ /** The account key could not be parsed or used to sign (client-side). */
36
+ export class JoseError extends Schema.TaggedError()("JoseError", {
37
+ message: Schema.String,
38
+ cause: Schema.optional(Schema.Unknown),
39
+ }).pipe(Category.withBadRequestError) {
40
+ }
41
+ /**
42
+ * The directory has no URL for the requested resource (a CA without
43
+ * `newAuthz`/`keyChange`, or a stale directory URL).
44
+ */
45
+ export class DirectoryMissingResource extends Schema.TaggedError()("DirectoryMissingResource", {
46
+ resource: Schema.String,
47
+ directoryUrl: Schema.String,
48
+ }).pipe(Category.withBadRequestError) {
49
+ }
50
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAQtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAC;AAE3D;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAC1E,kBAAkB,EAClB;IACE,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1D,IAAI,EAAE,MAAM,CAAC,OAAO;CACrB,CACF;CAAG;AAEJ,kCAAkC;AAClC,MAAM,OAAO,cAAe,SAAQ,MAAM,CAAC,WAAW,EAAkB,CACtE,gBAAgB,EAChB;IACE,IAAI,EAAE,MAAM,CAAC,OAAO;IACpB,KAAK,EAAE,MAAM,CAAC,OAAO;CACtB,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;CAAG;AAElC,yEAAyE;AACzE,MAAM,OAAO,SAAU,SAAQ,MAAM,CAAC,WAAW,EAAa,CAAC,WAAW,EAAE;IAC1E,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;CACvC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;CAAG;AAExC;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,MAAM,CAAC,WAAW,EAA4B,CAC1F,0BAA0B,EAC1B;IACE,QAAQ,EAAE,MAAM,CAAC,MAAM;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM;CAC5B,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;CAAG"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @distilled.cloud/acme — ACME (RFC 8555) SDK for Effect.
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
7
+ * JWS-signing protocol, credentials (account key + directory + EAB), JOSE
8
+ * helpers, retry and errors.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import * as Acme from "@distilled.cloud/acme";
13
+ *
14
+ * const account = yield* Acme.acme.newAccount({
15
+ * contact: ["mailto:ops@example.com"],
16
+ * termsOfServiceAgreed: true,
17
+ * });
18
+ * const order = yield* Acme.acme.newOrder({
19
+ * identifiers: [{ type: "dns", value: "*.example.com" }],
20
+ * });
21
+ * ```
22
+ */
23
+ export * from "./credentials.ts";
24
+ export * from "./errors.ts";
25
+ export * as Jose from "./jose.ts";
26
+ export * as T from "./traits.ts";
27
+ export * as Retry from "./retry.ts";
28
+ export { AcmeProtocol, type AcmeOpError, type AcmeOpContext, } from "./protocol.ts";
29
+ export * from "./services/index.ts";
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,cAAc,qBAAqB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @distilled.cloud/acme — ACME (RFC 8555) SDK for Effect.
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
7
+ * JWS-signing protocol, credentials (account key + directory + EAB), JOSE
8
+ * helpers, retry and errors.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import * as Acme from "@distilled.cloud/acme";
13
+ *
14
+ * const account = yield* Acme.acme.newAccount({
15
+ * contact: ["mailto:ops@example.com"],
16
+ * termsOfServiceAgreed: true,
17
+ * });
18
+ * const order = yield* Acme.acme.newOrder({
19
+ * identifiers: [{ type: "dns", value: "*.example.com" }],
20
+ * });
21
+ * ```
22
+ */
23
+ export * from "./credentials.js";
24
+ export * from "./errors.js";
25
+ export * as Jose from "./jose.js";
26
+ export * as T from "./traits.js";
27
+ export * as Retry from "./retry.js";
28
+ export { AcmeProtocol, } from "./protocol.js";
29
+ export * from "./services/index.js";
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EACL,YAAY,GAGb,MAAM,eAAe,CAAC;AACvB,cAAc,qBAAqB,CAAC"}