@certd/acme-client 0.1.6 → 0.2.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/types/index.d.ts CHANGED
@@ -1,141 +1,141 @@
1
- /**
2
- * acme-client type definitions
3
- */
4
-
5
- import { AxiosInstance } from 'axios';
6
- import * as rfc8555 from './rfc8555';
7
-
8
- export type PrivateKeyBuffer = Buffer;
9
- export type PublicKeyBuffer = Buffer;
10
- export type CertificateBuffer = Buffer;
11
- export type CsrBuffer = Buffer;
12
-
13
- export type PrivateKeyString = string;
14
- export type PublicKeyString = string;
15
- export type CertificateString = string;
16
- export type CsrString = string;
17
-
18
-
19
- /**
20
- * Augmented ACME interfaces
21
- */
22
-
23
- export interface Order extends rfc8555.Order {
24
- url: string;
25
- }
26
-
27
- export interface Authorization extends rfc8555.Authorization {
28
- url: string;
29
- }
30
-
31
-
32
- /**
33
- * Client
34
- */
35
-
36
- export interface ClientOptions {
37
- directoryUrl: string;
38
- accountKey: PrivateKeyBuffer | PrivateKeyString;
39
- accountUrl?: string;
40
- backoffAttempts?: number;
41
- backoffMin?: number;
42
- backoffMax?: number;
43
- }
44
-
45
- export interface ClientAutoOptions {
46
- csr: CsrBuffer | CsrString;
47
- challengeCreateFn: (authz: Authorization, challenge: rfc8555.Challenge, keyAuthorization: string) => Promise<any>;
48
- challengeRemoveFn: (authz: Authorization, challenge: rfc8555.Challenge, keyAuthorization: string) => Promise<any>;
49
- email?: string;
50
- termsOfServiceAgreed?: boolean;
51
- skipChallengeVerification?: boolean;
52
- challengePriority?: string[];
53
- preferredChain?: string;
54
- }
55
-
56
- export class Client {
57
- constructor(opts: ClientOptions);
58
- getTermsOfServiceUrl(): Promise<string>;
59
- getAccountUrl(): string;
60
- createAccount(data?: rfc8555.AccountCreateRequest): Promise<rfc8555.Account>;
61
- updateAccount(data?: rfc8555.AccountUpdateRequest): Promise<rfc8555.Account>;
62
- updateAccountKey(newAccountKey: PrivateKeyBuffer | PrivateKeyString, data?: object): Promise<rfc8555.Account>;
63
- createOrder(data: rfc8555.OrderCreateRequest): Promise<Order>;
64
- getOrder(order: Order): Promise<Order>;
65
- finalizeOrder(order: Order, csr: CsrBuffer | CsrString): Promise<Order>;
66
- getAuthorizations(order: Order): Promise<Authorization[]>;
67
- deactivateAuthorization(authz: Authorization): Promise<Authorization>;
68
- getChallengeKeyAuthorization(challenge: rfc8555.Challenge): Promise<string>;
69
- verifyChallenge(authz: Authorization, challenge: rfc8555.Challenge): Promise<boolean>;
70
- completeChallenge(challenge: rfc8555.Challenge): Promise<rfc8555.Challenge>;
71
- waitForValidStatus<T = Order | Authorization | rfc8555.Challenge>(item: T): Promise<T>;
72
- getCertificate(order: Order, preferredChain?: string | null): Promise<string>;
73
- revokeCertificate(cert: CertificateBuffer | CertificateString, data?: rfc8555.CertificateRevocationRequest): Promise<void>;
74
- auto(opts: ClientAutoOptions): Promise<string>;
75
- }
76
-
77
-
78
- /**
79
- * Directory URLs
80
- */
81
-
82
- export const directory: {
83
- letsencrypt: {
84
- staging: string,
85
- production: string
86
- }
87
- };
88
-
89
-
90
- /**
91
- * Crypto
92
- */
93
-
94
- export interface CertificateDomains {
95
- commonName: string;
96
- altNames: string[];
97
- }
98
-
99
- export interface CertificateIssuer {
100
- commonName: string;
101
- }
102
-
103
- export interface CertificateInfo {
104
- issuer: CertificateIssuer;
105
- domains: CertificateDomains;
106
- notAfter: Date;
107
- notBefore: Date;
108
- }
109
-
110
- export interface CsrOptions {
111
- keySize?: number;
112
- commonName?: string;
113
- altNames?: string[];
114
- country?: string;
115
- state?: string;
116
- locality?: string;
117
- organization?: string;
118
- organizationUnit?: string;
119
- emailAddress?: string;
120
- }
121
-
122
- export interface CryptoInterface {
123
- createPrivateKey(size?: number): Promise<PrivateKeyBuffer>;
124
- createPublicKey(key: PrivateKeyBuffer | PrivateKeyString): Promise<PublicKeyBuffer>;
125
- getPemBody(str: string): string;
126
- splitPemChain(str: string): string[];
127
- getModulus(input: PrivateKeyBuffer | PrivateKeyString | PublicKeyBuffer | PublicKeyString | CertificateBuffer | CertificateString | CsrBuffer | CsrString): Promise<Buffer>;
128
- getPublicExponent(input: PrivateKeyBuffer | PrivateKeyString | PublicKeyBuffer | PublicKeyString | CertificateBuffer | CertificateString | CsrBuffer | CsrString): Promise<Buffer>;
129
- readCsrDomains(csr: CsrBuffer | CsrString): Promise<CertificateDomains>;
130
- readCertificateInfo(cert: CertificateBuffer | CertificateString): Promise<CertificateInfo>;
131
- createCsr(data: CsrOptions, key?: PrivateKeyBuffer | PrivateKeyString): Promise<[PrivateKeyBuffer, CsrBuffer]>;
132
- }
133
-
134
- export const forge: CryptoInterface;
135
-
136
-
137
- /**
138
- * Axios
139
- */
140
-
141
- export const axios: AxiosInstance;
1
+ /**
2
+ * acme-client type definitions
3
+ */
4
+
5
+ import { AxiosInstance } from 'axios';
6
+ import * as rfc8555 from './rfc8555';
7
+
8
+ export type PrivateKeyBuffer = Buffer;
9
+ export type PublicKeyBuffer = Buffer;
10
+ export type CertificateBuffer = Buffer;
11
+ export type CsrBuffer = Buffer;
12
+
13
+ export type PrivateKeyString = string;
14
+ export type PublicKeyString = string;
15
+ export type CertificateString = string;
16
+ export type CsrString = string;
17
+
18
+
19
+ /**
20
+ * Augmented ACME interfaces
21
+ */
22
+
23
+ export interface Order extends rfc8555.Order {
24
+ url: string;
25
+ }
26
+
27
+ export interface Authorization extends rfc8555.Authorization {
28
+ url: string;
29
+ }
30
+
31
+
32
+ /**
33
+ * Client
34
+ */
35
+
36
+ export interface ClientOptions {
37
+ directoryUrl: string;
38
+ accountKey: PrivateKeyBuffer | PrivateKeyString;
39
+ accountUrl?: string;
40
+ backoffAttempts?: number;
41
+ backoffMin?: number;
42
+ backoffMax?: number;
43
+ }
44
+
45
+ export interface ClientAutoOptions {
46
+ csr: CsrBuffer | CsrString;
47
+ challengeCreateFn: (authz: Authorization, challenge: rfc8555.Challenge, keyAuthorization: string) => Promise<any>;
48
+ challengeRemoveFn: (authz: Authorization, challenge: rfc8555.Challenge, keyAuthorization: string) => Promise<any>;
49
+ email?: string;
50
+ termsOfServiceAgreed?: boolean;
51
+ skipChallengeVerification?: boolean;
52
+ challengePriority?: string[];
53
+ preferredChain?: string;
54
+ }
55
+
56
+ export class Client {
57
+ constructor(opts: ClientOptions);
58
+ getTermsOfServiceUrl(): Promise<string>;
59
+ getAccountUrl(): string;
60
+ createAccount(data?: rfc8555.AccountCreateRequest): Promise<rfc8555.Account>;
61
+ updateAccount(data?: rfc8555.AccountUpdateRequest): Promise<rfc8555.Account>;
62
+ updateAccountKey(newAccountKey: PrivateKeyBuffer | PrivateKeyString, data?: object): Promise<rfc8555.Account>;
63
+ createOrder(data: rfc8555.OrderCreateRequest): Promise<Order>;
64
+ getOrder(order: Order): Promise<Order>;
65
+ finalizeOrder(order: Order, csr: CsrBuffer | CsrString): Promise<Order>;
66
+ getAuthorizations(order: Order): Promise<Authorization[]>;
67
+ deactivateAuthorization(authz: Authorization): Promise<Authorization>;
68
+ getChallengeKeyAuthorization(challenge: rfc8555.Challenge): Promise<string>;
69
+ verifyChallenge(authz: Authorization, challenge: rfc8555.Challenge): Promise<boolean>;
70
+ completeChallenge(challenge: rfc8555.Challenge): Promise<rfc8555.Challenge>;
71
+ waitForValidStatus<T = Order | Authorization | rfc8555.Challenge>(item: T): Promise<T>;
72
+ getCertificate(order: Order, preferredChain?: string | null): Promise<string>;
73
+ revokeCertificate(cert: CertificateBuffer | CertificateString, data?: rfc8555.CertificateRevocationRequest): Promise<void>;
74
+ auto(opts: ClientAutoOptions): Promise<string>;
75
+ }
76
+
77
+
78
+ /**
79
+ * Directory URLs
80
+ */
81
+
82
+ export const directory: {
83
+ letsencrypt: {
84
+ staging: string,
85
+ production: string
86
+ }
87
+ };
88
+
89
+
90
+ /**
91
+ * Crypto
92
+ */
93
+
94
+ export interface CertificateDomains {
95
+ commonName: string;
96
+ altNames: string[];
97
+ }
98
+
99
+ export interface CertificateIssuer {
100
+ commonName: string;
101
+ }
102
+
103
+ export interface CertificateInfo {
104
+ issuer: CertificateIssuer;
105
+ domains: CertificateDomains;
106
+ notAfter: Date;
107
+ notBefore: Date;
108
+ }
109
+
110
+ export interface CsrOptions {
111
+ keySize?: number;
112
+ commonName?: string;
113
+ altNames?: string[];
114
+ country?: string;
115
+ state?: string;
116
+ locality?: string;
117
+ organization?: string;
118
+ organizationUnit?: string;
119
+ emailAddress?: string;
120
+ }
121
+
122
+ export interface CryptoInterface {
123
+ createPrivateKey(size?: number): Promise<PrivateKeyBuffer>;
124
+ createPublicKey(key: PrivateKeyBuffer | PrivateKeyString): Promise<PublicKeyBuffer>;
125
+ getPemBody(str: string): string;
126
+ splitPemChain(str: string): string[];
127
+ getModulus(input: PrivateKeyBuffer | PrivateKeyString | PublicKeyBuffer | PublicKeyString | CertificateBuffer | CertificateString | CsrBuffer | CsrString): Promise<Buffer>;
128
+ getPublicExponent(input: PrivateKeyBuffer | PrivateKeyString | PublicKeyBuffer | PublicKeyString | CertificateBuffer | CertificateString | CsrBuffer | CsrString): Promise<Buffer>;
129
+ readCsrDomains(csr: CsrBuffer | CsrString): Promise<CertificateDomains>;
130
+ readCertificateInfo(cert: CertificateBuffer | CertificateString): Promise<CertificateInfo>;
131
+ createCsr(data: CsrOptions, key?: PrivateKeyBuffer | PrivateKeyString): Promise<[PrivateKeyBuffer, CsrBuffer]>;
132
+ }
133
+
134
+ export const forge: CryptoInterface;
135
+
136
+
137
+ /**
138
+ * Axios
139
+ */
140
+
141
+ export const axios: AxiosInstance;
@@ -1,127 +1,127 @@
1
- /**
2
- * Account
3
- *
4
- * https://tools.ietf.org/html/rfc8555#section-7.1.2
5
- * https://tools.ietf.org/html/rfc8555#section-7.3
6
- * https://tools.ietf.org/html/rfc8555#section-7.3.2
7
- */
8
-
9
- export interface Account {
10
- status: 'valid' | 'deactivated' | 'revoked';
11
- orders: string;
12
- contact?: string[];
13
- termsOfServiceAgreed?: boolean;
14
- externalAccountBinding?: object;
15
- }
16
-
17
- export interface AccountCreateRequest {
18
- contact?: string[];
19
- termsOfServiceAgreed?: boolean;
20
- onlyReturnExisting?: boolean;
21
- externalAccountBinding?: object;
22
- }
23
-
24
- export interface AccountUpdateRequest {
25
- status?: string;
26
- contact?: string[];
27
- termsOfServiceAgreed?: boolean;
28
- }
29
-
30
-
31
- /**
32
- * Order
33
- *
34
- * https://tools.ietf.org/html/rfc8555#section-7.1.3
35
- * https://tools.ietf.org/html/rfc8555#section-7.4
36
- */
37
-
38
- export interface Order {
39
- status: 'pending' | 'ready' | 'processing' | 'valid' | 'invalid';
40
- identifiers: Identifier[];
41
- authorizations: string[];
42
- finalize: string;
43
- expires?: string;
44
- notBefore?: string;
45
- notAfter?: string;
46
- error?: object;
47
- certificate?: string;
48
- }
49
-
50
- export interface OrderCreateRequest {
51
- identifiers: Identifier[];
52
- notBefore?: string;
53
- notAfter?: string;
54
- }
55
-
56
-
57
- /**
58
- * Authorization
59
- *
60
- * https://tools.ietf.org/html/rfc8555#section-7.1.4
61
- */
62
-
63
- export interface Authorization {
64
- identifier: Identifier;
65
- status: 'pending' | 'valid' | 'invalid' | 'deactivated' | 'expired' | 'revoked';
66
- challenges: Challenge[];
67
- expires?: string;
68
- wildcard?: boolean;
69
- }
70
-
71
- export interface Identifier {
72
- type: string;
73
- value: string;
74
- }
75
-
76
-
77
- /**
78
- * Challenge
79
- *
80
- * https://tools.ietf.org/html/rfc8555#section-8
81
- * https://tools.ietf.org/html/rfc8555#section-8.3
82
- * https://tools.ietf.org/html/rfc8555#section-8.4
83
- */
84
-
85
- export interface ChallengeAbstract {
86
- type: string;
87
- url: string;
88
- status: 'pending' | 'processing' | 'valid' | 'invalid';
89
- validated?: string;
90
- error?: object;
91
- }
92
-
93
- export interface HttpChallenge extends ChallengeAbstract {
94
- type: 'http-01';
95
- token: string;
96
- }
97
-
98
- export interface DnsChallenge extends ChallengeAbstract {
99
- type: 'dns-01';
100
- token: string;
101
- }
102
-
103
- export type Challenge = HttpChallenge | DnsChallenge;
104
-
105
-
106
- /**
107
- * Certificate
108
- *
109
- * https://tools.ietf.org/html/rfc8555#section-7.6
110
- */
111
-
112
- export enum CertificateRevocationReason {
113
- Unspecified = 0,
114
- KeyCompromise = 1,
115
- CACompromise = 2,
116
- AffiliationChanged = 3,
117
- Superseded = 4,
118
- CessationOfOperation = 5,
119
- CertificateHold = 6,
120
- RemoveFromCRL = 8,
121
- PrivilegeWithdrawn = 9,
122
- AACompromise = 10,
123
- }
124
-
125
- export interface CertificateRevocationRequest {
126
- reason?: CertificateRevocationReason;
127
- }
1
+ /**
2
+ * Account
3
+ *
4
+ * https://tools.ietf.org/html/rfc8555#section-7.1.2
5
+ * https://tools.ietf.org/html/rfc8555#section-7.3
6
+ * https://tools.ietf.org/html/rfc8555#section-7.3.2
7
+ */
8
+
9
+ export interface Account {
10
+ status: 'valid' | 'deactivated' | 'revoked';
11
+ orders: string;
12
+ contact?: string[];
13
+ termsOfServiceAgreed?: boolean;
14
+ externalAccountBinding?: object;
15
+ }
16
+
17
+ export interface AccountCreateRequest {
18
+ contact?: string[];
19
+ termsOfServiceAgreed?: boolean;
20
+ onlyReturnExisting?: boolean;
21
+ externalAccountBinding?: object;
22
+ }
23
+
24
+ export interface AccountUpdateRequest {
25
+ status?: string;
26
+ contact?: string[];
27
+ termsOfServiceAgreed?: boolean;
28
+ }
29
+
30
+
31
+ /**
32
+ * Order
33
+ *
34
+ * https://tools.ietf.org/html/rfc8555#section-7.1.3
35
+ * https://tools.ietf.org/html/rfc8555#section-7.4
36
+ */
37
+
38
+ export interface Order {
39
+ status: 'pending' | 'ready' | 'processing' | 'valid' | 'invalid';
40
+ identifiers: Identifier[];
41
+ authorizations: string[];
42
+ finalize: string;
43
+ expires?: string;
44
+ notBefore?: string;
45
+ notAfter?: string;
46
+ error?: object;
47
+ certificate?: string;
48
+ }
49
+
50
+ export interface OrderCreateRequest {
51
+ identifiers: Identifier[];
52
+ notBefore?: string;
53
+ notAfter?: string;
54
+ }
55
+
56
+
57
+ /**
58
+ * Authorization
59
+ *
60
+ * https://tools.ietf.org/html/rfc8555#section-7.1.4
61
+ */
62
+
63
+ export interface Authorization {
64
+ identifier: Identifier;
65
+ status: 'pending' | 'valid' | 'invalid' | 'deactivated' | 'expired' | 'revoked';
66
+ challenges: Challenge[];
67
+ expires?: string;
68
+ wildcard?: boolean;
69
+ }
70
+
71
+ export interface Identifier {
72
+ type: string;
73
+ value: string;
74
+ }
75
+
76
+
77
+ /**
78
+ * Challenge
79
+ *
80
+ * https://tools.ietf.org/html/rfc8555#section-8
81
+ * https://tools.ietf.org/html/rfc8555#section-8.3
82
+ * https://tools.ietf.org/html/rfc8555#section-8.4
83
+ */
84
+
85
+ export interface ChallengeAbstract {
86
+ type: string;
87
+ url: string;
88
+ status: 'pending' | 'processing' | 'valid' | 'invalid';
89
+ validated?: string;
90
+ error?: object;
91
+ }
92
+
93
+ export interface HttpChallenge extends ChallengeAbstract {
94
+ type: 'http-01';
95
+ token: string;
96
+ }
97
+
98
+ export interface DnsChallenge extends ChallengeAbstract {
99
+ type: 'dns-01';
100
+ token: string;
101
+ }
102
+
103
+ export type Challenge = HttpChallenge | DnsChallenge;
104
+
105
+
106
+ /**
107
+ * Certificate
108
+ *
109
+ * https://tools.ietf.org/html/rfc8555#section-7.6
110
+ */
111
+
112
+ export enum CertificateRevocationReason {
113
+ Unspecified = 0,
114
+ KeyCompromise = 1,
115
+ CACompromise = 2,
116
+ AffiliationChanged = 3,
117
+ Superseded = 4,
118
+ CessationOfOperation = 5,
119
+ CertificateHold = 6,
120
+ RemoveFromCRL = 8,
121
+ PrivilegeWithdrawn = 9,
122
+ AACompromise = 10,
123
+ }
124
+
125
+ export interface CertificateRevocationRequest {
126
+ reason?: CertificateRevocationReason;
127
+ }
package/types/test.ts CHANGED
@@ -1,70 +1,70 @@
1
- /**
2
- * acme-client type definition tests
3
- */
4
-
5
- import * as acme from 'acme-client';
6
-
7
-
8
- (async () => {
9
- /* Client */
10
- const accountKey = await acme.forge.createPrivateKey();
11
-
12
- const client = new acme.Client({
13
- accountKey,
14
- directoryUrl: acme.directory.letsencrypt.staging
15
- });
16
-
17
- /* Account */
18
- await client.createAccount({
19
- termsOfServiceAgreed: true,
20
- contact: ['mailto:test@example.com']
21
- });
22
-
23
- /* Order */
24
- const order = await client.createOrder({
25
- identifiers: [
26
- { type: 'dns', value: 'example.com' },
27
- { type: 'dns', value: '*.example.com' },
28
- ]
29
- });
30
-
31
- await client.getOrder(order);
32
-
33
- /* Authorizations / Challenges */
34
- const authorizations = await client.getAuthorizations(order);
35
- const authorization = authorizations[0];
36
- const challenge = authorization.challenges[0];
37
-
38
- await client.getChallengeKeyAuthorization(challenge);
39
- await client.verifyChallenge(authorization, challenge);
40
- await client.completeChallenge(challenge);
41
- await client.waitForValidStatus(challenge);
42
-
43
- /* Finalize */
44
- const [certKey, certCsr] = await acme.forge.createCsr({
45
- commonName: 'example.com',
46
- altNames: ['example.com', '*.example.com']
47
- });
48
-
49
- await client.finalizeOrder(order, certCsr);
50
- await client.getCertificate(order);
51
- await client.getCertificate(order, 'DST Root CA X3');
52
-
53
- /* Auto */
54
- await client.auto({
55
- csr: certCsr,
56
- challengeCreateFn: async (authz, challenge, keyAuthorization) => {},
57
- challengeRemoveFn: async (authz, challenge, keyAuthorization) => {}
58
- });
59
-
60
- await client.auto({
61
- csr: certCsr,
62
- email: 'test@example.com',
63
- termsOfServiceAgreed: false,
64
- skipChallengeVerification: false,
65
- challengePriority: ['http-01', 'dns-01'],
66
- preferredChain: 'DST Root CA X3',
67
- challengeCreateFn: async (authz, challenge, keyAuthorization) => {},
68
- challengeRemoveFn: async (authz, challenge, keyAuthorization) => {}
69
- });
70
- })();
1
+ /**
2
+ * acme-client type definition tests
3
+ */
4
+
5
+ import * as acme from 'acme-client';
6
+
7
+
8
+ (async () => {
9
+ /* Client */
10
+ const accountKey = await acme.forge.createPrivateKey();
11
+
12
+ const client = new acme.Client({
13
+ accountKey,
14
+ directoryUrl: acme.directory.letsencrypt.staging
15
+ });
16
+
17
+ /* Account */
18
+ await client.createAccount({
19
+ termsOfServiceAgreed: true,
20
+ contact: ['mailto:test@example.com']
21
+ });
22
+
23
+ /* Order */
24
+ const order = await client.createOrder({
25
+ identifiers: [
26
+ { type: 'dns', value: 'example.com' },
27
+ { type: 'dns', value: '*.example.com' },
28
+ ]
29
+ });
30
+
31
+ await client.getOrder(order);
32
+
33
+ /* Authorizations / Challenges */
34
+ const authorizations = await client.getAuthorizations(order);
35
+ const authorization = authorizations[0];
36
+ const challenge = authorization.challenges[0];
37
+
38
+ await client.getChallengeKeyAuthorization(challenge);
39
+ await client.verifyChallenge(authorization, challenge);
40
+ await client.completeChallenge(challenge);
41
+ await client.waitForValidStatus(challenge);
42
+
43
+ /* Finalize */
44
+ const [certKey, certCsr] = await acme.forge.createCsr({
45
+ commonName: 'example.com',
46
+ altNames: ['example.com', '*.example.com']
47
+ });
48
+
49
+ await client.finalizeOrder(order, certCsr);
50
+ await client.getCertificate(order);
51
+ await client.getCertificate(order, 'DST Root CA X3');
52
+
53
+ /* Auto */
54
+ await client.auto({
55
+ csr: certCsr,
56
+ challengeCreateFn: async (authz, challenge, keyAuthorization) => {},
57
+ challengeRemoveFn: async (authz, challenge, keyAuthorization) => {}
58
+ });
59
+
60
+ await client.auto({
61
+ csr: certCsr,
62
+ email: 'test@example.com',
63
+ termsOfServiceAgreed: false,
64
+ skipChallengeVerification: false,
65
+ challengePriority: ['http-01', 'dns-01'],
66
+ preferredChain: 'DST Root CA X3',
67
+ challengeCreateFn: async (authz, challenge, keyAuthorization) => {},
68
+ challengeRemoveFn: async (authz, challenge, keyAuthorization) => {}
69
+ });
70
+ })();