@@ -13,7 +13,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
13
13
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
14
14
import { InvalidCertificateError } from './errors.js'
15
15
import { KeyType , PublicKey } from './pb/index.js'
16
- import type { PeerId , PublicKey as Libp2pPublicKey , Logger , PrivateKey } from '@libp2p/interface'
16
+ import type { PeerId , PublicKey as Libp2pPublicKey , Logger , PrivateKey , AbortOptions } from '@libp2p/interface'
17
17
import type { Pushable } from 'it-queueless-pushable'
18
18
import type { Duplex , Source } from 'it-stream-types'
19
19
import type { Uint8ArrayList } from 'uint8arraylist'
@@ -91,7 +91,7 @@ export async function verifyPeerCertificate (rawCertificate: Uint8Array, expecte
91
91
return remotePeerId
92
92
}
93
93
94
- export async function generateCertificate ( privateKey : PrivateKey ) : Promise < { cert : string , key : string } > {
94
+ export async function generateCertificate ( privateKey : PrivateKey , options ?: AbortOptions ) : Promise < { cert : string , key : string } > {
95
95
const now = Date . now ( )
96
96
97
97
const alg = {
@@ -101,9 +101,13 @@ export async function generateCertificate (privateKey: PrivateKey): Promise<{ ce
101
101
}
102
102
103
103
const keys = await crypto . subtle . generateKey ( alg , true , [ 'sign' ] )
104
+ options ?. signal ?. throwIfAborted ( )
105
+
104
106
const certPublicKeySpki = await crypto . subtle . exportKey ( 'spki' , keys . publicKey )
107
+ options ?. signal ?. throwIfAborted ( )
108
+
105
109
const dataToSign = encodeSignatureData ( certPublicKeySpki )
106
- const sig = await privateKey . sign ( dataToSign )
110
+ const sig = await privateKey . sign ( dataToSign , options )
107
111
const notAfter = new Date ( now + CERT_VALIDITY_PERIOD_TO )
108
112
// workaround for https://github.com/PeculiarVentures/x509/issues/73
109
113
notAfter . setMilliseconds ( 0 )
@@ -133,8 +137,10 @@ export async function generateCertificate (privateKey: PrivateKey): Promise<{ ce
133
137
} ) . toBER ( ) )
134
138
]
135
139
} )
140
+ options ?. signal ?. throwIfAborted ( )
136
141
137
142
const certPrivateKeyPkcs8 = await crypto . subtle . exportKey ( 'pkcs8' , keys . privateKey )
143
+ options ?. signal ?. throwIfAborted ( )
138
144
139
145
return {
140
146
cert : selfCert . toString ( ) ,
0 commit comments