node-opcua-crypto-web 5.4.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.
@@ -0,0 +1,632 @@
1
+ import __crypto, { KeyLike } from 'node:crypto';
2
+ import * as x509 from '@peculiar/x509';
3
+
4
+ declare const createPrivateKeyFromNodeJSCrypto: typeof __crypto.createPrivateKey;
5
+ type KeyFormat = "pem" | "der" | "jwk";
6
+ type KeyObjectType = "secret" | "public" | "private";
7
+ interface KeyExportOptions<T extends KeyFormat> {
8
+ type: "pkcs1" | "spki" | "pkcs8" | "sec1";
9
+ format: T;
10
+ cipher?: string | undefined;
11
+ passphrase?: string | Buffer | undefined;
12
+ }
13
+ interface JwkKeyExportOptions {
14
+ format: "jwk";
15
+ }
16
+ interface KeyObject {
17
+ export(options: KeyExportOptions<"pem">): string | Buffer;
18
+ export(options: KeyExportOptions<"der">): Buffer;
19
+ export(options: JwkKeyExportOptions): JsonWebKey;
20
+ type: KeyObjectType;
21
+ }
22
+ declare function isKeyObject(mayBeKeyObject: unknown): boolean;
23
+ type PrivateKey = {
24
+ hidden: string;
25
+ } | {
26
+ hidden: KeyObject;
27
+ };
28
+ type PublicKey = KeyObject;
29
+ type Nonce = Buffer;
30
+ type PEM = string;
31
+ type DER = Buffer;
32
+ type Certificate = DER;
33
+ type CertificatePEM = PEM;
34
+ type PrivateKeyPEM = PEM;
35
+ type PublicKeyPEM = PEM;
36
+ type Signature = Buffer;
37
+ type CertificateRevocationList = Buffer;
38
+ declare enum CertificatePurpose {
39
+ NotSpecified = 0,
40
+ ForCertificateAuthority = 1,
41
+ ForApplication = 2,
42
+ ForUserAuthentication = 3
43
+ }
44
+
45
+ /**
46
+ * Determine if a Certificate Revocation List (CRL) was issued by
47
+ * the given certificate, by comparing the CRL's issuer name
48
+ * fingerprint with the certificate's subject name fingerprint.
49
+ *
50
+ * This is a lightweight check (no cryptographic signature
51
+ * verification). Use {@link verifyCrlIssuedByCertificate} for
52
+ * full verification.
53
+ *
54
+ * @param crl - the CRL to check (DER-encoded)
55
+ * @param certificate - the candidate issuer certificate (DER-encoded)
56
+ * @returns `true` if the CRL's issuer fingerprint matches the
57
+ * certificate's subject fingerprint
58
+ */
59
+ declare function isCrlIssuedByCertificate(crl: CertificateRevocationList, certificate: Certificate): boolean;
60
+ /**
61
+ * Verify that a Certificate Revocation List (CRL) was issued by
62
+ * the given certificate. This performs both a fingerprint match
63
+ * **and** a cryptographic signature verification.
64
+ *
65
+ * @param crl - the CRL to verify (DER-encoded)
66
+ * @param certificate - the candidate issuer certificate (DER-encoded)
67
+ * @returns `true` if the CRL's issuer matches the certificate
68
+ * **and** the CRL's signature is valid against the
69
+ * certificate's public key
70
+ */
71
+ declare function verifyCrlIssuedByCertificate(crl: CertificateRevocationList, certificate: Certificate): boolean;
72
+
73
+ interface DirectoryName {
74
+ stateOrProvinceName?: string;
75
+ localityName?: string;
76
+ organizationName?: string;
77
+ organizationUnitName?: string;
78
+ commonName?: string;
79
+ countryName?: string;
80
+ }
81
+ declare function readDirectoryName(buffer: Buffer, block: BlockInfo): DirectoryName;
82
+
83
+ declare enum TagType {
84
+ BOOLEAN = 1,
85
+ INTEGER = 2,
86
+ BIT_STRING = 3,
87
+ OCTET_STRING = 4,
88
+ NULL = 5,
89
+ OBJECT_IDENTIFIER = 6,
90
+ UTF8String = 12,
91
+ NumericString = 18,
92
+ PrintableString = 19,
93
+ TeletexString = 20,
94
+ IA5String = 22,
95
+ UTCTime = 23,
96
+ GeneralizedTime = 24,
97
+ GraphicString = 25,
98
+ VisibleString = 26,
99
+ GeneralString = 27,
100
+ UniversalString = 28,
101
+ BMPString = 30,
102
+ SEQUENCE = 48,
103
+ SET = 49,
104
+ CONTEXT_SPECIFIC0 = 160,
105
+ CONTEXT_SPECIFIC1 = 161,
106
+ CONTEXT_SPECIFIC2 = 162,
107
+ CONTEXT_SPECIFIC3 = 163,
108
+ A4 = 164
109
+ }
110
+ interface BlockInfo {
111
+ tag: TagType | number;
112
+ position: number;
113
+ length: number;
114
+ start: number;
115
+ }
116
+ declare function readTag(buf: Buffer, pos: number): BlockInfo;
117
+ declare function readStruct(buf: Buffer, blockInfo: BlockInfo): BlockInfo[];
118
+ interface AlgorithmIdentifier {
119
+ identifier: string;
120
+ }
121
+ declare function readAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier;
122
+ type SignatureValue = string;
123
+ declare function readSignatureValueBin(buffer: Buffer, block: BlockInfo): Buffer;
124
+
125
+ type PublicKeyLength = 64 | 96 | 128 | 256 | 384 | 512;
126
+ /**
127
+ * A structure exposing useful information about a certificate
128
+ */
129
+ interface CertificateInfo {
130
+ /** the public key length in bits */
131
+ publicKeyLength: PublicKeyLength;
132
+ /** the date at which the certificate starts to be valid */
133
+ notBefore: Date;
134
+ /** the date after which the certificate is not valid any more */
135
+ notAfter: Date;
136
+ /** info about certificate owner */
137
+ subject: DirectoryName;
138
+ /** public key */
139
+ publicKey: SubjectPublicKey;
140
+ }
141
+ declare function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate;
142
+ /**
143
+ * @method exploreCertificateInfo
144
+ * returns useful information about the certificate such as public key length, start date and end of validity date,
145
+ * and CN
146
+ * @param certificate the certificate to explore
147
+ */
148
+ declare function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo;
149
+
150
+ /**
151
+ * @module node_opcua_crypto
152
+ */
153
+
154
+ interface AttributeTypeAndValue {
155
+ [key: string]: unknown;
156
+ }
157
+ interface Validity {
158
+ notBefore: Date;
159
+ notAfter: Date;
160
+ }
161
+ interface X509KeyUsage {
162
+ digitalSignature: boolean;
163
+ nonRepudiation: boolean;
164
+ keyEncipherment: boolean;
165
+ dataEncipherment: boolean;
166
+ keyAgreement: boolean;
167
+ keyCertSign: boolean;
168
+ cRLSign: boolean;
169
+ encipherOnly: boolean;
170
+ decipherOnly: boolean;
171
+ }
172
+ interface X509ExtKeyUsage {
173
+ clientAuth: boolean;
174
+ serverAuth: boolean;
175
+ codeSigning: boolean;
176
+ emailProtection: boolean;
177
+ timeStamping: boolean;
178
+ ocspSigning: boolean;
179
+ ipsecEndSystem: boolean;
180
+ ipsecTunnel: boolean;
181
+ ipsecUser: boolean;
182
+ }
183
+ interface SubjectPublicKey {
184
+ modulus: Buffer;
185
+ }
186
+ declare function readExtension(buffer: Buffer, block: BlockInfo): {
187
+ identifier: {
188
+ oid: string;
189
+ name: string;
190
+ };
191
+ value: string | X509KeyUsage | X509ExtKeyUsage | AuthorityKeyIdentifier | BasicConstraints | {
192
+ [key: string]: string[];
193
+ };
194
+ };
195
+ interface SubjectPublicKeyInfo {
196
+ algorithm: string;
197
+ keyLength: PublicKeyLength;
198
+ subjectPublicKey: SubjectPublicKey;
199
+ }
200
+ interface BasicConstraints {
201
+ critical: boolean;
202
+ cA: boolean;
203
+ pathLengthConstraint?: number;
204
+ }
205
+ interface AuthorityKeyIdentifier {
206
+ keyIdentifier: string | null;
207
+ authorityCertIssuer: DirectoryName | null;
208
+ authorityCertIssuerFingerPrint: string;
209
+ serial: string | null;
210
+ }
211
+ interface CertificateExtension {
212
+ basicConstraints: BasicConstraints;
213
+ subjectKeyIdentifier?: string;
214
+ authorityKeyIdentifier?: AuthorityKeyIdentifier;
215
+ keyUsage?: X509KeyUsage;
216
+ extKeyUsage?: X509ExtKeyUsage;
217
+ subjectAltName?: {
218
+ [key: string]: string[];
219
+ };
220
+ }
221
+ interface TbsCertificate {
222
+ version: number;
223
+ serialNumber: string;
224
+ issuer: DirectoryName;
225
+ signature: AlgorithmIdentifier;
226
+ validity: Validity;
227
+ subject: DirectoryName;
228
+ subjectFingerPrint: string;
229
+ subjectPublicKeyInfo: SubjectPublicKeyInfo;
230
+ extensions: CertificateExtension | null;
231
+ }
232
+ declare function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertificate;
233
+ interface CertificateInternals {
234
+ tbsCertificate: TbsCertificate;
235
+ signatureAlgorithm: AlgorithmIdentifier;
236
+ signatureValue: SignatureValue;
237
+ }
238
+ declare function clearExploreCertificateCache(): void;
239
+ /**
240
+ * explore a certificate structure
241
+ * @param certificate
242
+ * @returns a json object that exhibits the internal data of the certificate
243
+ */
244
+ declare function exploreCertificate(certificate: Certificate): CertificateInternals;
245
+ /**
246
+ * @method split_der
247
+ * split a multi chain certificates
248
+ * @param certificateChain the certificate chain in der (binary) format}
249
+ * @returns an array of Der , each element of the array is one certificate of the chain
250
+ */
251
+ declare function split_der(certificateChain: Certificate): Certificate[];
252
+ /**
253
+ * @method verify_certificate_der_structure
254
+ * Verify that a certificate or certificate chain is structurally well-formed DER.
255
+ * Ensures the blocks parse correctly and the length exactly matches the buffer length.
256
+ * @param cert the DER certificate or chain to verify
257
+ * @throws {Error} if the structure is invalid or truncated
258
+ */
259
+ declare function verify_certificate_der_structure(cert: Certificate): void;
260
+ /**
261
+ * @method combine_der
262
+ * combine an array of certificates into a single blob
263
+ * @param certificates a array with the individual DER certificates of the chain
264
+ * @return a concatenated buffer containing the certificates
265
+ */
266
+ declare function combine_der(certificates: Certificate[]): Certificate;
267
+
268
+ declare function exploreAsn1(buffer: Buffer): void;
269
+
270
+ type Version = string;
271
+ type Name = string;
272
+ type CertificateSerialNumber = string;
273
+ type Extensions = Record<string, unknown>;
274
+ interface RevokedCertificate {
275
+ userCertificate: CertificateSerialNumber;
276
+ revocationDate: Date;
277
+ crlEntryExtensions?: Extensions;
278
+ }
279
+ interface TBSCertList {
280
+ version?: Version;
281
+ signature: AlgorithmIdentifier;
282
+ issuer: Name;
283
+ issuerFingerprint: string;
284
+ thisUpdate: Date;
285
+ nextUpdate?: Date;
286
+ revokedCertificates: RevokedCertificate[];
287
+ }
288
+ interface CertificateRevocationListInfo {
289
+ tbsCertList: TBSCertList;
290
+ signatureAlgorithm: AlgorithmIdentifier;
291
+ signatureValue: Buffer;
292
+ }
293
+ declare function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName;
294
+ declare function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo;
295
+
296
+ interface SubjectAltName {
297
+ uniformResourceIdentifier: string[];
298
+ dNSName: string[];
299
+ iPAddress: string[];
300
+ [key: string]: unknown;
301
+ }
302
+ interface ExtensionRequest {
303
+ basicConstraints: BasicConstraints;
304
+ keyUsage: X509KeyUsage;
305
+ subjectAltName: SubjectAltName;
306
+ }
307
+ interface CertificateSigningRequestInfo {
308
+ extensionRequest: ExtensionRequest;
309
+ }
310
+ declare function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo;
311
+ declare function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo;
312
+
313
+ interface PrivateKeyInternals {
314
+ /***/
315
+ version: Buffer;
316
+ modulus: Buffer;
317
+ publicExponent: Buffer;
318
+ privateExponent: Buffer;
319
+ prime1: Buffer;
320
+ prime2: Buffer;
321
+ exponent1: Buffer;
322
+ exponent2: Buffer;
323
+ }
324
+ /**
325
+ *
326
+ * @param privateKey RSAPrivateKey ::= SEQUENCE {
327
+ * version Version,
328
+ * modulus INTEGER, -- n
329
+ * publicExponent INTEGER, -- e
330
+ * privateExponent INTEGER, -- d
331
+ * prime1 INTEGER, -- p
332
+ * prime2 INTEGER, -- q
333
+ * exponent1 INTEGER, -- d mod (p-1)
334
+ * exponent2 INTEGER, -- d mod (q-1)
335
+ * coefficient INTEGER, -- (inverse of q) mod p
336
+ * otherPrimeInfos OtherPrimeInfos OPTIONAL
337
+ }
338
+ */
339
+ declare function explorePrivateKey(privateKey2: PrivateKey): PrivateKeyInternals;
340
+
341
+ /**
342
+ * The type of content found in a DER-encoded buffer.
343
+ */
344
+ type DERContentType = "X509Certificate" | "X509CertificateChain" | "CertificateRevocationList" | "CertificateSigningRequest" | "PKCS12" | "PrivateKey" | "Unknown";
345
+ /**
346
+ * Identify the content type of a DER-encoded buffer by inspecting
347
+ * its ASN.1 structure.
348
+ *
349
+ * This function does NOT fully parse the buffer — it only inspects
350
+ * the outermost tags to determine the type. It can distinguish:
351
+ *
352
+ * - **X509Certificate** — a single X.509 certificate (v1 or v3)
353
+ * - **X509CertificateChain** — multiple concatenated X.509 DER
354
+ * certificates
355
+ * - **CertificateRevocationList** — an X.509 CRL (v1 or v2)
356
+ * - **CertificateSigningRequest** — a PKCS#10 CSR
357
+ * - **PKCS12** — a PKCS#12 / PFX container (version 3)
358
+ * - **PrivateKey** — a PKCS#8 or raw RSA private key
359
+ * - **Unknown** — could not identify the content
360
+ *
361
+ * @param buffer A DER-encoded buffer to identify.
362
+ * @returns The detected {@link DERContentType}.
363
+ */
364
+ declare function identifyDERContent(buffer: Buffer): DERContentType;
365
+
366
+ interface SubjectOptions {
367
+ commonName?: string;
368
+ organization?: string;
369
+ organizationalUnit?: string;
370
+ locality?: string;
371
+ state?: string;
372
+ country?: string;
373
+ domainComponent?: string;
374
+ }
375
+ /**
376
+ * subjectName The subject name to use for the Certificate.
377
+ * If not specified the ApplicationName and/or domainNames are used to create a suitable default value.
378
+ */
379
+ declare class Subject implements SubjectOptions {
380
+ readonly commonName?: string;
381
+ readonly organization?: string;
382
+ readonly organizationalUnit?: string;
383
+ readonly locality?: string;
384
+ readonly state?: string;
385
+ readonly country?: string;
386
+ readonly domainComponent?: string;
387
+ constructor(options: SubjectOptions | string);
388
+ static parse(str: string): SubjectOptions;
389
+ toStringInternal(sep: string): string;
390
+ toStringForOPCUA(): string;
391
+ toString(): string;
392
+ }
393
+
394
+ declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
395
+ declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
396
+ declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
397
+ type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
398
+ declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
399
+ status: _VerifyStatus;
400
+ reason: string;
401
+ }>;
402
+
403
+ declare function coercePEMorDerToPrivateKey(privateKeyInDerOrPem: string | Buffer): PrivateKey;
404
+ /**
405
+ *
406
+ * @private
407
+ */
408
+ declare function _coercePrivateKey(privateKey: unknown): Promise<KeyObject>;
409
+
410
+ interface CreateCertificateSigningRequestOptions {
411
+ privateKey: CryptoKey;
412
+ notBefore?: Date;
413
+ notAfter?: Date;
414
+ validity?: number;
415
+ subject?: string;
416
+ dns?: string[];
417
+ ip?: string[];
418
+ applicationUri?: string;
419
+ purpose: CertificatePurpose;
420
+ }
421
+ declare function createCertificateSigningRequest({ privateKey, subject, dns, ip, applicationUri, purpose, }: CreateCertificateSigningRequestOptions): Promise<{
422
+ csr: string;
423
+ der: x509.Pkcs10CertificateRequest;
424
+ }>;
425
+
426
+ declare function generateKeyPair(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKeyPair>;
427
+ /**
428
+ * generate a pair of private/public keys of length 1024,2048, 3072, or 4096 bits
429
+ */
430
+ declare function generatePrivateKey(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKey>;
431
+ /**
432
+ * convert a CryptoKey to a PEM string
433
+ */
434
+ declare function privateKeyToPEM(privateKey: CryptoKey): Promise<{
435
+ privPem: string;
436
+ privDer: ArrayBuffer;
437
+ }>;
438
+ declare function derToPrivateKey(privDer: ArrayBuffer): Promise<CryptoKey>;
439
+ declare function pemToPrivateKey(pem: string): Promise<CryptoKey>;
440
+
441
+ interface CreateSelfSignCertificateOptions {
442
+ privateKey: CryptoKey;
443
+ notBefore?: Date;
444
+ notAfter?: Date;
445
+ validity?: number;
446
+ subject?: string;
447
+ dns?: string[];
448
+ ip?: string[];
449
+ applicationUri?: string;
450
+ purpose: CertificatePurpose;
451
+ }
452
+ /**
453
+ *
454
+ * construct a self-signed certificate
455
+ */
456
+ declare function createSelfSignedCertificate({ privateKey, notAfter, notBefore, validity, subject, dns, ip, applicationUri, purpose, }: CreateSelfSignCertificateOptions): Promise<{
457
+ cert: string;
458
+ der: x509.X509Certificate;
459
+ }>;
460
+
461
+ declare function identifyPemType(rawKey: Certificate | Certificate[] | string): undefined | string;
462
+ declare function removeTrailingLF(str: string): string;
463
+ declare function toPem(raw_key: Certificate | Certificate[] | string, pem: string): string;
464
+ /**
465
+ * Convert a PEM string to DER format.
466
+ * If the PEM string contains multiple certificates, they will be concatenated in DER format.
467
+ *
468
+ * @param raw_key The PEM string to convert.
469
+ * @returns The DER buffer.
470
+ */
471
+ declare function convertPEMtoDER(raw_key: PEM): DER;
472
+ declare function hexDump(buffer: Buffer, width?: number): string;
473
+ interface MakeMessageChunkSignatureOptions {
474
+ signatureLength: number;
475
+ algorithm: string;
476
+ privateKey: PrivateKey;
477
+ }
478
+ declare function makeMessageChunkSignature(chunk: Buffer, options: MakeMessageChunkSignatureOptions): Buffer;
479
+ interface VerifyMessageChunkSignatureOptions {
480
+ signatureLength?: number;
481
+ algorithm: string;
482
+ publicKey: PublicKeyPEM;
483
+ }
484
+ /**
485
+ * @method verifyMessageChunkSignature
486
+ *
487
+ * const signer = {
488
+ * signatureLength : 128,
489
+ * algorithm : "RSA-SHA256",
490
+ * publicKey: "qsdqsdqsd"
491
+ * };
492
+ * @param blockToVerify
493
+ * @param signature
494
+ * @param options
495
+ * @param options.signatureLength
496
+ * @param options.algorithm for example "RSA-SHA256"
497
+ * @param options.publicKey
498
+ * @return true if the signature is valid
499
+ */
500
+ declare function verifyMessageChunkSignature(blockToVerify: Buffer, signature: Signature, options: VerifyMessageChunkSignatureOptions): boolean;
501
+ declare function makeSHA1Thumbprint(buffer: Buffer): Signature;
502
+ declare const RSA_PKCS1_OAEP_PADDING: number;
503
+ declare const RSA_PKCS1_PADDING: number;
504
+ declare enum PaddingAlgorithm {
505
+ RSA_PKCS1_OAEP_PADDING = 4,
506
+ RSA_PKCS1_PADDING = 1
507
+ }
508
+ declare function publicEncrypt_native(buffer: Buffer, publicKey: KeyLike, algorithm?: PaddingAlgorithm): Buffer;
509
+ declare function privateDecrypt_native(buffer: Buffer, privateKey: PrivateKey, algorithm?: PaddingAlgorithm): Buffer;
510
+ declare const publicEncrypt: typeof publicEncrypt_native;
511
+ declare const privateDecrypt: typeof privateDecrypt_native;
512
+ declare function publicEncrypt_long(buffer: Buffer, publicKey: KeyLike, blockSize: number, padding?: number, paddingAlgorithm?: PaddingAlgorithm): Buffer;
513
+ declare function privateDecrypt_long(buffer: Buffer, privateKey: PrivateKey, blockSize: number, paddingAlgorithm?: number): Buffer;
514
+ declare function coerceCertificatePem(certificate: Certificate | CertificatePEM): CertificatePEM;
515
+ declare function extractPublicKeyFromCertificateSync(certificate: Certificate | CertificatePEM): PublicKeyPEM;
516
+ /**
517
+ * extract the publickey from a certificate
518
+ * @async
519
+ */
520
+ declare function extractPublicKeyFromCertificate(certificate: CertificatePEM | Certificate, callback: (err: Error | null, publicKeyPEM?: PublicKeyPEM) => void): void;
521
+
522
+ /***
523
+ * @method rsaLengthPrivateKey
524
+ * A method to determine the rsa key length ( i.e 2048bits or 1024bits)
525
+ * @param key a PEM public key or a PEM rsa private key
526
+ * @return the key length in bytes.
527
+ */
528
+ declare function rsaLengthPrivateKey(key: PrivateKey): number;
529
+ /**
530
+ * @method toPem2
531
+ * @param raw_key
532
+ * @param pem
533
+ *
534
+ *
535
+ * @return a PEM string containing the Private Key
536
+ *
537
+ * Note: a Pem key can be converted back to a private key object using coercePrivateKey
538
+ *
539
+ */
540
+ declare function toPem2(raw_key: Buffer | string | KeyObject | PrivateKey, pem: string): string;
541
+ declare function coercePrivateKeyPem(privateKey: PrivateKey): PrivateKeyPEM;
542
+ declare function coercePublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicKeyPEM;
543
+ declare function coerceRsaPublicKeyPem(publicKey: PublicKey | KeyObject | PublicKeyPEM): PublicKeyPEM;
544
+ declare function rsaLengthPublicKey(key: PublicKeyPEM | PublicKey): number;
545
+ declare function rsaLengthRsaPublicKey(key: PublicKeyPEM | PublicKey): number;
546
+
547
+ declare function makePseudoRandomBuffer(secret: Nonce, seed: Nonce, minLength: number, sha1or256: "SHA1" | "SHA256"): Buffer;
548
+ interface ComputeDerivedKeysOptions {
549
+ signatureLength: number;
550
+ signingKeyLength: number;
551
+ encryptingKeyLength: number;
552
+ encryptingBlockSize: number;
553
+ algorithm: string;
554
+ sha1or256?: "SHA1" | "SHA256";
555
+ }
556
+ interface DerivedKeys extends ComputeDerivedKeysOptions {
557
+ signatureLength: number;
558
+ signingKeyLength: number;
559
+ encryptingKeyLength: number;
560
+ encryptingBlockSize: number;
561
+ algorithm: string;
562
+ sha1or256: "SHA1" | "SHA256";
563
+ signingKey: Buffer;
564
+ encryptingKey: Buffer;
565
+ initializationVector: Buffer;
566
+ }
567
+ declare function computeDerivedKeys(secret: Nonce, seed: Nonce, options: ComputeDerivedKeysOptions): DerivedKeys;
568
+ /**
569
+ * @method reduceLength
570
+ * @param buffer
571
+ * @param byteToRemove
572
+ * @return buffer
573
+ */
574
+ declare function reduceLength(buffer: Buffer, byteToRemove: number): Buffer;
575
+ /**
576
+ * @method removePadding
577
+ * @param buffer
578
+ * @return buffer with padding removed
579
+ */
580
+ declare function removePadding(buffer: Buffer): Buffer;
581
+ type VerifyChunkSignatureOptions = VerifyMessageChunkSignatureOptions;
582
+ /**
583
+ * @method verifyChunkSignature
584
+ *
585
+ * const signer = {
586
+ * signatureLength : 128,
587
+ * algorithm : "RSA-SHA256",
588
+ * public_key: "qsdqsdqsd"
589
+ * };
590
+ *
591
+ * @param chunk The message chunk to verify.
592
+ * @param options
593
+ * @param options.signatureLength
594
+ * @param options.algorithm the algorithm.
595
+ * @param options.publicKey
596
+ * @return {*}
597
+ */
598
+ declare function verifyChunkSignature(chunk: Buffer, options: VerifyChunkSignatureOptions): boolean;
599
+ declare function computePaddingFooter(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
600
+ declare function encryptBufferWithDerivedKeys(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
601
+ declare function decryptBufferWithDerivedKeys(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
602
+ /**
603
+ * @method makeMessageChunkSignatureWithDerivedKeys
604
+ * @param message
605
+ * @param derivedKeys
606
+ * @return
607
+ */
608
+ declare function makeMessageChunkSignatureWithDerivedKeys(message: Buffer, derivedKeys: DerivedKeys): Buffer;
609
+ /**
610
+ * @method verifyChunkSignatureWithDerivedKeys
611
+ * @param chunk
612
+ * @param derivedKeys
613
+ * @return
614
+ */
615
+ declare function verifyChunkSignatureWithDerivedKeys(chunk: Buffer, derivedKeys: DerivedKeys): boolean;
616
+
617
+ declare function makePrivateKeyFromPem(privateKeyInPem: string): PrivateKey;
618
+
619
+ declare function makePrivateKeyThumbPrint(_privateKey: PrivateKey): Buffer;
620
+
621
+ declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
622
+ declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
623
+
624
+ declare const asn1: {
625
+ readDirectoryName: typeof readDirectoryName;
626
+ readTag: typeof readTag;
627
+ readStruct: typeof readStruct;
628
+ readAlgorithmIdentifier: typeof readAlgorithmIdentifier;
629
+ readSignatureValueBin: typeof readSignatureValueBin;
630
+ };
631
+
632
+ export { type AttributeTypeAndValue, type AuthorityKeyIdentifier, type BasicConstraints, type Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, type CertificatePEM, CertificatePurpose, type CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateSelfSignCertificateOptions, type DER, type DERContentType, type DerivedKeys, type DirectoryName, type ExtensionRequest, type Extensions, type KeyObject, type Name, type Nonce, type PEM, PaddingAlgorithm, type PrivateKey, type PrivateKeyInternals, type PrivateKeyPEM, type PublicKey, type PublicKeyLength, type PublicKeyPEM, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type RevokedCertificate, type Signature, Subject, type SubjectAltName, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, asn1, certificateMatchesPrivateKey, clearExploreCertificateCache, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateSigningRequest, createPrivateKeyFromNodeJSCrypto, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, hexDump, identifyDERContent, identifyPemType, isCrlIssuedByCertificate, isKeyObject, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePrivateKeyThumbPrint, makePseudoRandomBuffer, makeSHA1Thumbprint, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readExtension, readNameForCrl, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyCrlIssuedByCertificate, verifyMessageChunkSignature, verify_certificate_der_structure };