Skip to content

Commit

Permalink
improve exported symbols and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ycmjason committed Oct 10, 2024
1 parent 1bcc5fd commit 20fa959
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
5 changes: 3 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@fishballpkg/acme",
"version": "0.3.0",
"version": "0.4.0",
"exports": {
".": "./src/mod.ts",
"./Dns01ChallengeUtils": "./src/Dns01ChallengeUtils.ts"
"./Dns01ChallengeUtils": "./src/Dns01ChallengeUtils.ts",
"./generateCSR": "./src/utils/generateCSR.ts"
},
"compilerOptions": {
"strict": true,
Expand Down
6 changes: 5 additions & 1 deletion src/AcmeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { AcmeAccount } from "./AcmeAccount.ts";
import { generateKeyPair } from "./utils/crypto.ts";
import { jwsFetch } from "./utils/jws.ts";

export const REPLAY_NONCE_HEADER_KEY = "Replay-Nonce";
const REPLAY_NONCE_HEADER_KEY = "Replay-Nonce";

/**
* The directory object.
* @see https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.1
*/
export type AcmeDirectory = {
keyChange: string;
newAccount: string;
Expand Down
14 changes: 6 additions & 8 deletions src/AcmeOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ export type AcmeOrderStatus =
| "valid"
| "invalid";

export type AcmeOrderInit = {
account: AcmeAccount;
url: string;
domains?: string[];
authorizationUrls?: string[];
};

/**
* Represents your request for a certificate.
*/
Expand Down Expand Up @@ -151,7 +144,12 @@ export class AcmeOrder {
domains,
url,
authorizationUrls,
}: AcmeOrderInit,
}: {
account: AcmeAccount;
url: string;
domains?: string[];
authorizationUrls?: string[];
},
): Promise<AcmeOrder> {
const order = new AcmeOrder({
account,
Expand Down
31 changes: 20 additions & 11 deletions src/Dns01ChallengeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
/**
* @module Dns01ChallengeUtils
*
* Some utility functions to help you with dns-01 challenge.
*/

/**
* Lookup the DNS `TXT` record for `domain` every `interval`
* (in ms, default: 5000) until the record matches `pollUntil`.
*
* @example
* ```ts
* import { pollDnsTxtRecord } from "@fishballpkg/acme/Dns01ChallengeUtils"
* ```
*
* The lookups are done with the Authoritative Name Server of the `domain`.
*
* - `onBeforeAttempt` is called before *each* DNS lookup happens.
Expand All @@ -22,6 +11,26 @@
*
* Note: To avoid issues with DNS-01 challenges, consider waiting an additional
* 15-30 seconds after this succeeds before submitting the challenge.
*
* @example
* ```ts
* import { pollDnsTxtRecord } from "@fishballpkg/acme/Dns01ChallengeUtils";
*
* pollDnsTxtRecord({
* domain: "sub.example.com",
* pollUntil: "some-secret-text",
* onBeforeAttempt: () => {
* console.log(`Looking up DNS records...`);
* },
* onAfterFailAttempt: (recordss) => {
* for (const [i, records] of recordss.entries()) {
* console.log(`Record in Authoritative Name Server ${i}`);
* console.log(records);
* }
* console.log("Retrying later...");
* },
* });
* ```
*/
export const pollDnsTxtRecord: (payload: {
domain: string;
Expand Down
4 changes: 2 additions & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export * from "./AcmeAuthorization.ts";
export * from "./AcmeChallenge.ts";
export * from "./AcmeClient.ts";
export * from "./AcmeOrder.ts";

/** Utility functions to help you with `dns-01` challenge */
export * as Dns01ChallengeUtils from "./Dns01ChallengeUtils.ts";

export * from "./ACME_DIRECTORY_URLS.ts";

export * from "./utils/generateCSR.ts";
5 changes: 5 additions & 0 deletions src/utils/generateCSR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const ECDSA_WITH_SHA256_SIGNATURE_ALGOTRITHM_SEQUENCE = encodeSequence(
encodeOID(OIDS.ECDSA_WITH_SHA256),
);

/**
* Generate a Certificate Signing Request (CSR) in DER format.
*
* @see https://datatracker.ietf.org/doc/html/rfc2986
*/
export async function generateCSR(
{ domains, keyPair }: { domains: readonly string[]; keyPair: CryptoKeyPair },
): Promise<Uint8Array> {
Expand Down

0 comments on commit 20fa959

Please sign in to comment.