cf-workers-native 0.1.5 → 0.1.6
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/README.md +2 -2
- package/dist/browser/documents/page-source.js +1 -1
- package/dist/browser/headers/index.d.ts +2 -0
- package/dist/browser/headers/index.js +5 -0
- package/dist/browser/response/index.d.ts +2 -0
- package/dist/browser/response/index.js +11 -3
- package/dist/browser/structured-clone/index.d.ts +3 -0
- package/dist/browser/structured-clone/index.js +75 -7
- package/dist/browser/websocket/attachment-size.d.ts +3 -0
- package/dist/browser/websocket/attachment-size.js +336 -0
- package/dist/browser/websocket/brand.d.ts +4 -0
- package/dist/browser/websocket/brand.js +16 -0
- package/dist/browser/websocket/close-event.d.ts +7 -0
- package/dist/browser/websocket/close-event.js +30 -0
- package/dist/browser/websocket/compression.d.ts +5 -0
- package/dist/browser/websocket/compression.js +124 -0
- package/dist/browser/websocket/conversion.d.ts +2 -0
- package/dist/browser/websocket/conversion.js +13 -0
- package/dist/browser/websocket/endpoint.d.ts +39 -0
- package/dist/browser/websocket/endpoint.js +379 -0
- package/dist/browser/websocket/frames.d.ts +21 -0
- package/dist/browser/websocket/frames.js +121 -0
- package/dist/browser/websocket/native.d.ts +14 -0
- package/dist/browser/websocket/native.js +226 -0
- package/dist/cloudflare/apis/cloudflare-node/index.js +11 -23
- package/dist/compat/crypto/LICENSE-3RD-PARTY.md +20 -0
- package/dist/compat/crypto/LICENSE.boringssl +238 -0
- package/dist/compat/crypto/LICENSE.ncrypto +21 -0
- package/dist/compat/crypto/asymmetric.js +141 -68
- package/dist/compat/crypto/cipher-handle.d.ts +27 -0
- package/dist/compat/crypto/cipher-handle.js +239 -0
- package/dist/compat/crypto/cipher-info.d.ts +12 -0
- package/dist/compat/crypto/cipher-info.js +324 -0
- package/dist/compat/crypto/constants.d.ts +62 -0
- package/dist/compat/crypto/constants.js +68 -0
- package/dist/compat/crypto/dh-handle.d.ts +17 -0
- package/dist/compat/crypto/dh-handle.js +180 -0
- package/dist/compat/crypto/dh.d.ts +53 -0
- package/dist/compat/crypto/dh.js +138 -0
- package/dist/compat/crypto/digest-stream.d.ts +15 -0
- package/dist/compat/crypto/digest-stream.js +213 -0
- package/dist/compat/crypto/digests.d.ts +3 -0
- package/dist/compat/crypto/digests.js +32 -0
- package/dist/compat/crypto/ecdh.d.ts +16 -6
- package/dist/compat/crypto/hash-handle.d.ts +23 -0
- package/dist/compat/crypto/hash-handle.js +70 -0
- package/dist/compat/crypto/hash.d.ts +37 -0
- package/dist/compat/crypto/hash.js +218 -0
- package/dist/compat/crypto/hkdf.js +40 -14
- package/dist/compat/crypto/index.d.cts +168 -1
- package/dist/compat/crypto/index.d.ts +191 -8
- package/dist/compat/crypto/index.js +36 -23
- package/dist/compat/crypto/key-errors.d.ts +10 -0
- package/dist/compat/crypto/key-errors.js +17 -0
- package/dist/compat/crypto/key-export.d.ts +8 -0
- package/dist/compat/crypto/key-export.js +49 -0
- package/dist/compat/crypto/key-formats.d.ts +2 -1
- package/dist/compat/crypto/key-formats.js +162 -31
- package/dist/compat/crypto/key-options.d.ts +1 -0
- package/dist/compat/crypto/key-options.js +74 -0
- package/dist/compat/crypto/key-state.d.ts +1 -0
- package/dist/compat/crypto/keys.d.ts +20 -12
- package/dist/compat/crypto/keys.js +125 -56
- package/dist/compat/crypto/metadata.d.ts +9 -0
- package/dist/compat/crypto/metadata.js +89 -2
- package/dist/compat/crypto/native-cipher.d.ts +17 -0
- package/dist/compat/crypto/native-cipher.js +192 -0
- package/dist/compat/crypto/native-crypto.d.ts +14 -1
- package/dist/compat/crypto/native-crypto.js +118 -6
- package/dist/compat/crypto/pbkdf2-handle.d.ts +4 -0
- package/dist/compat/crypto/pbkdf2-handle.js +26 -0
- package/dist/compat/crypto/pbkdf2.d.ts +5 -0
- package/dist/compat/crypto/pbkdf2.js +60 -0
- package/dist/compat/crypto/prime.js +4 -4
- package/dist/compat/crypto/random.d.ts +11 -0
- package/dist/compat/crypto/random.js +86 -6
- package/dist/compat/crypto/rsa.d.ts +17 -1
- package/dist/compat/crypto/rsa.js +8 -4
- package/dist/compat/crypto/scrypt.d.ts +3 -3
- package/dist/compat/crypto/scrypt.js +25 -23
- package/dist/compat/crypto/sign-handle.d.ts +3 -3
- package/dist/compat/crypto/sign-handle.js +55 -11
- package/dist/compat/crypto/signatures.d.ts +17 -11
- package/dist/compat/crypto/subtle-digest.d.ts +1 -0
- package/dist/compat/crypto/subtle-digest.js +56 -0
- package/dist/compat/crypto/symmetric.d.ts +40 -24
- package/dist/compat/crypto/symmetric.js +229 -94
- package/dist/compat/crypto/validation.d.ts +4 -0
- package/dist/compat/crypto/validation.js +29 -2
- package/dist/compat/crypto/webcrypto.d.ts +13 -0
- package/dist/compat/crypto/webcrypto.js +51 -0
- package/dist/compat/crypto/x509.js +2 -1
- package/dist/compat/events/index.js +1 -1
- package/dist/compat/fs/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/fs/LICENSE-APACHE +177 -0
- package/dist/compat/fs/directory-backend.d.ts +6 -0
- package/dist/compat/fs/directory-backend.js +51 -0
- package/dist/compat/fs/directory.d.ts +37 -0
- package/dist/compat/fs/directory.js +137 -0
- package/dist/compat/fs/embedded.d.ts +1 -1
- package/dist/compat/fs/embedded.js +7 -2
- package/dist/compat/fs/file-handle.d.ts +75 -0
- package/dist/compat/fs/file-handle.js +226 -0
- package/dist/compat/fs/glob-internal.d.ts +15 -0
- package/dist/compat/fs/glob-internal.js +417 -0
- package/dist/compat/fs/glob.d.ts +10 -0
- package/dist/compat/fs/glob.js +71 -0
- package/dist/compat/fs/index.d.ts +6 -3
- package/dist/compat/fs/index.js +582 -50
- package/dist/compat/fs/io-validation.d.ts +14 -0
- package/dist/compat/fs/io-validation.js +130 -0
- package/dist/compat/fs/io.d.ts +1 -0
- package/dist/compat/fs/io.js +282 -0
- package/dist/compat/fs/promises/index.d.ts +3 -1
- package/dist/compat/fs/public-types.d.ts +120 -0
- package/dist/compat/fs/public-types.js +1 -0
- package/dist/compat/fs/stream-errors.d.ts +6 -0
- package/dist/compat/fs/stream-errors.js +8 -0
- package/dist/compat/fs/stream-utils.d.ts +16 -0
- package/dist/compat/fs/stream-utils.js +29 -0
- package/dist/compat/fs/streams.d.ts +104 -0
- package/dist/compat/fs/streams.js +794 -0
- package/dist/compat/fs/writable.d.ts +8 -0
- package/dist/compat/fs/writable.js +412 -22
- package/dist/compat/http/index.d.ts +11 -28
- package/dist/compat/http/index.js +81 -125
- package/dist/compat/http/server-options.d.ts +1 -0
- package/dist/compat/http/server-options.js +87 -0
- package/dist/compat/http/unique-headers.d.ts +1 -0
- package/dist/compat/http/unique-headers.js +21 -0
- package/dist/compat/http-outgoing/index.d.ts +2 -1
- package/dist/compat/http-outgoing/index.js +2 -17
- package/dist/compat/http-server/index.d.ts +2 -2
- package/dist/compat/http-server/index.js +4 -85
- package/dist/compat/https/index.d.ts +4 -2
- package/dist/compat/net/sockets.js +98 -20
- package/dist/compat/net/validators.d.ts +1 -0
- package/dist/compat/net/validators.js +8 -0
- package/dist/compat/process/configuration.d.ts +113 -0
- package/dist/compat/process/configuration.js +115 -0
- package/dist/compat/process/directory.d.ts +4 -0
- package/dist/compat/process/directory.js +28 -0
- package/dist/compat/process/files.d.ts +3 -0
- package/dist/compat/process/files.js +10 -0
- package/dist/compat/process/index.d.ts +15 -13
- package/dist/compat/process/index.js +47 -74
- package/dist/compat/process/scheduling.d.ts +2 -0
- package/dist/compat/process/scheduling.js +60 -0
- package/dist/compat/process/state.js +1 -0
- package/dist/compat/process/stdio.d.ts +18 -0
- package/dist/compat/process/stdio.js +66 -0
- package/dist/compat/stream/destroy.d.ts +1 -0
- package/dist/compat/stream/destroy.js +21 -1
- package/dist/compat/stream/readable.js +10 -2
- package/dist/compat/tls/jsstream.js +16 -6
- package/dist/compat/tls/wrap.d.ts +1 -1
- package/dist/compat/tls/wrap.js +0 -3
- package/dist/compat/util/inspect.js +5 -1
- package/dist/compat/zlib/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/zlib/LICENSE-APACHE +177 -0
- package/dist/compat/zlib/LICENSE.zlib +22 -0
- package/dist/compat/zlib/classic-base.cjs +600 -0
- package/dist/compat/zlib/classic-base.d.cts +39 -0
- package/dist/compat/zlib/classic-binding.d.ts +28 -0
- package/dist/compat/zlib/classic-binding.js +105 -0
- package/dist/compat/zlib/classic.d.ts +44 -0
- package/dist/compat/zlib/classic.js +199 -0
- package/dist/compat/zlib/codec-binding.d.ts +33 -0
- package/dist/compat/zlib/codec-binding.js +141 -0
- package/dist/compat/zlib/compression.d.ts +22 -51
- package/dist/compat/zlib/compression.js +129 -218
- package/dist/compat/zlib/errors.d.ts +21 -0
- package/dist/compat/zlib/errors.js +32 -0
- package/dist/compat/zlib/index.d.ts +367 -3
- package/dist/compat/zlib/index.js +28 -11
- package/dist/compat/zlib/input.d.ts +16 -0
- package/dist/compat/zlib/input.js +132 -0
- package/dist/compat/zlib/native-codecs.d.ts +7 -0
- package/dist/compat/zlib/native-codecs.js +22 -10
- package/dist/compat/zlib/native-zlib.d.ts +5 -0
- package/dist/compat/zlib/native-zlib.js +52 -0
- package/dist/compat/zlib/public-types.d.ts +48 -0
- package/dist/compat/zlib/public-types.js +1 -0
- package/dist/compat/zlib/validators.d.ts +3 -0
- package/dist/compat/zlib/validators.js +18 -0
- package/dist/shared/buffer-source.d.ts +5 -0
- package/dist/shared/buffer-source.js +70 -0
- package/dist/shared/globals/platform.d.ts +8 -0
- package/dist/shared/globals/platform.js +1 -0
- package/dist/shared/globals/web.js +5 -0
- package/dist/shared/request-context.d.ts +2 -0
- package/dist/shared/request-context.js +11 -0
- package/dist/shared/request-scope.js +4 -1
- package/dist/tooling/shared.js +6 -0
- package/dist/tooling/vite.js +4 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +38 -7
- package/package.json +2 -2
|
@@ -1,30 +1,213 @@
|
|
|
1
|
+
import * as dh from "./dh.js";
|
|
2
|
+
export * from "./dh.js";
|
|
3
|
+
import { pbkdf2, pbkdf2Sync } from "./pbkdf2.js";
|
|
4
|
+
export { pbkdf2, pbkdf2Sync };
|
|
5
|
+
import { Hash, Hmac, createHmac, createHash, hash } from "./hash.js";
|
|
6
|
+
export { Hash, Hmac, createHmac, createHash, hash };
|
|
7
|
+
export type { HashOptions } from "./hash.js";
|
|
1
8
|
import { X509Certificate } from "./x509.js";
|
|
2
9
|
export { X509Certificate };
|
|
3
10
|
import { Certificate } from "./certificate.js";
|
|
4
11
|
export { Certificate };
|
|
5
12
|
import { ECDH, createECDH } from "./ecdh.js";
|
|
6
13
|
export { ECDH, createECDH };
|
|
14
|
+
import * as signatures from "./signatures.js";
|
|
7
15
|
export * from "./signatures.js";
|
|
16
|
+
import * as prime from "./prime.js";
|
|
8
17
|
export * from "./prime.js";
|
|
18
|
+
export type { PrimeNum as primeNum, GeneratePrimeOptions as generatePrimeOptions, CheckPrimeOptions as checkPrimeOptions, } from "./prime.js";
|
|
19
|
+
import * as asymmetric from "./asymmetric.js";
|
|
9
20
|
export { createPrivateKey, createPublicKey, generateKeyPair, generateKeyPairSync, diffieHellman, timingSafeEqual, } from "./asymmetric.js";
|
|
21
|
+
import * as keys from "./keys.js";
|
|
10
22
|
export { KeyObject, SecretKeyObject, PublicKeyObject, PrivateKeyObject, createSecretKey, generateKey, generateKeySync, } from "./keys.js";
|
|
23
|
+
import * as metadata from "./metadata.js";
|
|
11
24
|
export * from "./metadata.js";
|
|
12
25
|
import { hkdf, hkdfSync } from "./hkdf.js";
|
|
13
|
-
import { randomInt, randomUUID } from "./random.js";
|
|
26
|
+
import { randomInt, randomUUID, randomBytes, randomFill, randomFillSync } from "./random.js";
|
|
27
|
+
export { randomBytes, randomFill, randomFillSync };
|
|
28
|
+
export declare const pseudoRandomBytes: typeof randomBytes;
|
|
14
29
|
import { scrypt, scryptSync } from "./scrypt.js";
|
|
15
30
|
export { hkdf, hkdfSync, randomInt, randomUUID, scrypt, scryptSync };
|
|
16
|
-
export
|
|
17
|
-
import {
|
|
18
|
-
export {
|
|
31
|
+
export type { ArrayLike as arrayLike } from "./scrypt.js";
|
|
32
|
+
import { constants } from "./constants.js";
|
|
33
|
+
export { constants };
|
|
34
|
+
import { Cipheriv, Decipheriv, createCipheriv, createDecipheriv } from "./symmetric.js";
|
|
35
|
+
export { Cipheriv, Decipheriv, createCipheriv, createDecipheriv };
|
|
19
36
|
import { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt } from "./rsa.js";
|
|
20
37
|
export { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt };
|
|
21
|
-
|
|
22
|
-
export
|
|
38
|
+
import { webcrypto, subtle } from "./webcrypto.js";
|
|
39
|
+
export { webcrypto, subtle };
|
|
23
40
|
export declare const getRandomValues: <T extends Exclude<BufferSource, ArrayBuffer>>(array: T) => T;
|
|
24
41
|
export declare const CryptoKey: {
|
|
25
42
|
new (): CryptoKey;
|
|
26
43
|
prototype: CryptoKey;
|
|
27
44
|
};
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
declare const _default: {
|
|
46
|
+
DiffieHellman: {
|
|
47
|
+
(sizeOrKey: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer), keyEncoding?: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer) | undefined, generator?: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer) | undefined, genEncoding?: ("buffer" | BufferEncoding) | undefined): dh.DiffieHellman;
|
|
48
|
+
new (sizeOrKey: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer), keyEncoding?: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer) | undefined, generator?: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer) | undefined, genEncoding?: ("buffer" | BufferEncoding) | undefined): dh.DiffieHellman;
|
|
49
|
+
prototype: dh.DiffieHellman;
|
|
50
|
+
};
|
|
51
|
+
DiffieHellmanGroup: {
|
|
52
|
+
(name: string): dh.DiffieHellmanGroup;
|
|
53
|
+
new (name: string): dh.DiffieHellmanGroup;
|
|
54
|
+
prototype: dh.DiffieHellmanGroup;
|
|
55
|
+
};
|
|
56
|
+
createDiffieHellman(sizeOrKey: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer), keyEncoding?: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer), generator?: number | (string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | SharedArrayBuffer), genEncoding?: "buffer" | BufferEncoding): dh.DiffieHellman;
|
|
57
|
+
createDiffieHellmanGroup(name: string): dh.DiffieHellmanGroup;
|
|
58
|
+
getDiffieHellman(name: string): dh.DiffieHellmanGroup;
|
|
59
|
+
Sign: {
|
|
60
|
+
(algorithm: string, options?: signatures.SignOptions): signatures.Sign;
|
|
61
|
+
new (algorithm: string, options?: signatures.SignOptions): signatures.Sign;
|
|
62
|
+
};
|
|
63
|
+
Verify: {
|
|
64
|
+
(algorithm: string, options?: signatures.SignOptions): signatures.Verify;
|
|
65
|
+
new (algorithm: string, options?: signatures.SignOptions): signatures.Verify;
|
|
66
|
+
};
|
|
67
|
+
createSign(algorithm: string, options?: signatures.SignOptions): signatures.Sign;
|
|
68
|
+
createVerify(algorithm: string, options?: signatures.SignOptions): signatures.Verify;
|
|
69
|
+
sign(algorithm: string | null | undefined, data: ArrayBufferView, options: any): Buffer;
|
|
70
|
+
sign(algorithm: string | null | undefined, data: ArrayBufferView, options: any, callback: (err: any, signature?: Buffer) => void): void;
|
|
71
|
+
verify(algorithm: string | null | undefined, data: ArrayBufferView, options: any, signature: ArrayBufferView): boolean;
|
|
72
|
+
verify(algorithm: string | null | undefined, data: ArrayBufferView, options: any, signature: ArrayBufferView, callback: (err: any, valid?: boolean) => void): void;
|
|
73
|
+
generatePrimeSync(size: number, options?: prime.GeneratePrimeOptions): bigint | ArrayBuffer;
|
|
74
|
+
generatePrime(size: number, options: prime.GeneratePrimeOptions, callback: prime.GeneratePrimeCallback): void;
|
|
75
|
+
generatePrime(size: number, callback: prime.GeneratePrimeCallback): void;
|
|
76
|
+
checkPrimeSync(candidate: prime.PrimeNum, options?: prime.CheckPrimeOptions): boolean;
|
|
77
|
+
checkPrime(candidate: prime.PrimeNum, options: prime.CheckPrimeOptions, callback: prime.CheckPrimeCallback): void;
|
|
78
|
+
checkPrime(candidate: prime.PrimeNum, callback: prime.CheckPrimeCallback): void;
|
|
79
|
+
getHashes(): string[];
|
|
80
|
+
getCurves(): string[];
|
|
81
|
+
secureHeapUsed(): Record<string, number>;
|
|
82
|
+
setEngine(_engine: string, _flags?: number): never;
|
|
83
|
+
setFips(_enabled: boolean): never;
|
|
84
|
+
getFips(): boolean;
|
|
85
|
+
getCipherInfo: typeof metadata.getCipherInfo;
|
|
86
|
+
getCiphers(): string[];
|
|
87
|
+
Cipher(): never;
|
|
88
|
+
Decipher(): never;
|
|
89
|
+
createCipher(): never;
|
|
90
|
+
createDecipher(): never;
|
|
91
|
+
X509Certificate: typeof X509Certificate;
|
|
92
|
+
Certificate: typeof Certificate;
|
|
93
|
+
constants: Omit<{
|
|
94
|
+
readonly DH_CHECK_P_NOT_SAFE_PRIME: number;
|
|
95
|
+
readonly DH_CHECK_P_NOT_PRIME: number;
|
|
96
|
+
readonly DH_UNABLE_TO_CHECK_GENERATOR: number;
|
|
97
|
+
readonly DH_NOT_SUITABLE_GENERATOR: number;
|
|
98
|
+
readonly RSA_PKCS1_PADDING: number;
|
|
99
|
+
readonly RSA_NO_PADDING: number;
|
|
100
|
+
readonly RSA_PKCS1_OAEP_PADDING: number;
|
|
101
|
+
readonly RSA_X931_PADDING: number;
|
|
102
|
+
readonly RSA_PKCS1_PSS_PADDING: number;
|
|
103
|
+
readonly RSA_PSS_SALTLEN_DIGEST: number;
|
|
104
|
+
readonly RSA_PSS_SALTLEN_MAX_SIGN: number;
|
|
105
|
+
readonly RSA_PSS_SALTLEN_AUTO: number;
|
|
106
|
+
readonly POINT_CONVERSION_COMPRESSED: number;
|
|
107
|
+
readonly POINT_CONVERSION_UNCOMPRESSED: number;
|
|
108
|
+
readonly POINT_CONVERSION_HYBRID: number;
|
|
109
|
+
readonly OPENSSL_VERSION_NUMBER: number;
|
|
110
|
+
readonly SSL_OP_ALL: number;
|
|
111
|
+
readonly SSL_OP_ALLOW_NO_DHE_KEX: number;
|
|
112
|
+
readonly SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number;
|
|
113
|
+
readonly SSL_OP_CIPHER_SERVER_PREFERENCE: number;
|
|
114
|
+
readonly SSL_OP_CISCO_ANYCONNECT: number;
|
|
115
|
+
readonly SSL_OP_COOKIE_EXCHANGE: number;
|
|
116
|
+
readonly SSL_OP_CRYPTOPRO_TLSEXT_BUG: number;
|
|
117
|
+
readonly SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number;
|
|
118
|
+
readonly SSL_OP_LEGACY_SERVER_CONNECT: number;
|
|
119
|
+
readonly SSL_OP_NO_COMPRESSION: number;
|
|
120
|
+
readonly SSL_OP_NO_ENCRYPT_THEN_MAC: number;
|
|
121
|
+
readonly SSL_OP_NO_QUERY_MTU: number;
|
|
122
|
+
readonly SSL_OP_NO_RENEGOTIATION: number;
|
|
123
|
+
readonly SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number;
|
|
124
|
+
readonly SSL_OP_NO_SSLv2: number;
|
|
125
|
+
readonly SSL_OP_NO_SSLv3: number;
|
|
126
|
+
readonly SSL_OP_NO_TICKET: number;
|
|
127
|
+
readonly SSL_OP_NO_TLSv1: number;
|
|
128
|
+
readonly SSL_OP_NO_TLSv1_1: number;
|
|
129
|
+
readonly SSL_OP_NO_TLSv1_2: number;
|
|
130
|
+
readonly SSL_OP_NO_TLSv1_3: number;
|
|
131
|
+
readonly SSL_OP_PRIORITIZE_CHACHA: number;
|
|
132
|
+
readonly SSL_OP_TLS_ROLLBACK_BUG: number;
|
|
133
|
+
readonly ENGINE_METHOD_RSA: number;
|
|
134
|
+
readonly ENGINE_METHOD_DSA: number;
|
|
135
|
+
readonly ENGINE_METHOD_DH: number;
|
|
136
|
+
readonly ENGINE_METHOD_RAND: number;
|
|
137
|
+
readonly ENGINE_METHOD_EC: number;
|
|
138
|
+
readonly ENGINE_METHOD_CIPHERS: number;
|
|
139
|
+
readonly ENGINE_METHOD_DIGESTS: number;
|
|
140
|
+
readonly ENGINE_METHOD_PKEY_METHS: number;
|
|
141
|
+
readonly ENGINE_METHOD_PKEY_ASN1_METHS: number;
|
|
142
|
+
readonly ENGINE_METHOD_ALL: number;
|
|
143
|
+
readonly ENGINE_METHOD_NONE: number;
|
|
144
|
+
readonly defaultCoreCipherList: string;
|
|
145
|
+
readonly TLS1_VERSION: number;
|
|
146
|
+
readonly TLS1_1_VERSION: number;
|
|
147
|
+
readonly TLS1_2_VERSION: number;
|
|
148
|
+
readonly TLS1_3_VERSION: number;
|
|
149
|
+
readonly defaultCipherList: string;
|
|
150
|
+
}, "defaultCipherList"> & {
|
|
151
|
+
defaultCipherList: string;
|
|
152
|
+
};
|
|
153
|
+
pbkdf2: typeof pbkdf2;
|
|
154
|
+
pbkdf2Sync: typeof pbkdf2Sync;
|
|
155
|
+
Hash: typeof Hash;
|
|
156
|
+
createHash: typeof createHash;
|
|
157
|
+
fips: boolean;
|
|
158
|
+
createPrivateKey: typeof asymmetric.createPrivateKey;
|
|
159
|
+
createPublicKey: typeof asymmetric.createPublicKey;
|
|
160
|
+
generateKeyPair: typeof asymmetric.generateKeyPair;
|
|
161
|
+
generateKeyPairSync: typeof asymmetric.generateKeyPairSync;
|
|
162
|
+
timingSafeEqual: typeof asymmetric.timingSafeEqual;
|
|
163
|
+
publicEncrypt: typeof publicEncrypt;
|
|
164
|
+
privateEncrypt: typeof privateEncrypt;
|
|
165
|
+
publicDecrypt: typeof publicDecrypt;
|
|
166
|
+
privateDecrypt: typeof privateDecrypt;
|
|
167
|
+
ECDH: {
|
|
168
|
+
(curveName: string): ECDH;
|
|
169
|
+
new (curveName: string): ECDH;
|
|
170
|
+
convertKey(key: string | ArrayBufferView<ArrayBufferLike>, curve: string, inputEncoding?: BufferEncoding, outputEncoding?: undefined, format?: import("./ecdh.js").ECDHFormat): Buffer;
|
|
171
|
+
convertKey(key: string | ArrayBufferView<ArrayBufferLike>, curve: string, inputEncoding: BufferEncoding | undefined, outputEncoding: BufferEncoding, format?: import("./ecdh.js").ECDHFormat): string;
|
|
172
|
+
};
|
|
173
|
+
createECDH: typeof createECDH;
|
|
174
|
+
KeyObject: typeof keys.KeyObject;
|
|
175
|
+
SecretKeyObject: typeof keys.SecretKeyObject;
|
|
176
|
+
PublicKeyObject: typeof keys.PublicKeyObject;
|
|
177
|
+
PrivateKeyObject: typeof keys.PrivateKeyObject;
|
|
178
|
+
createSecretKey: typeof keys.createSecretKey;
|
|
179
|
+
generateKey: typeof keys.generateKey;
|
|
180
|
+
generateKeySync: typeof keys.generateKeySync;
|
|
181
|
+
Hmac: typeof Hmac;
|
|
182
|
+
createHmac: typeof createHmac;
|
|
183
|
+
Cipheriv: new (algorithm: string, key: string | ArrayBuffer | ArrayBufferView | keys.KeyObject | CryptoKey, iv: string | ArrayBuffer | ArrayBufferView | null, options?: import("./symmetric.js").CipherOptions) => Cipheriv;
|
|
184
|
+
createCipheriv: typeof createCipheriv;
|
|
185
|
+
Decipheriv: new (algorithm: string, key: string | ArrayBuffer | ArrayBufferView | keys.KeyObject | CryptoKey, iv: string | ArrayBuffer | ArrayBufferView | null, options?: import("./symmetric.js").CipherOptions) => Decipheriv;
|
|
186
|
+
createDecipheriv: typeof createDecipheriv;
|
|
187
|
+
hkdf: typeof hkdf;
|
|
188
|
+
hkdfSync: typeof hkdfSync;
|
|
189
|
+
webcrypto: Crypto & {
|
|
190
|
+
DigestStream: typeof import("./digest-stream.js").DigestStream;
|
|
191
|
+
subtle: SubtleCrypto & {
|
|
192
|
+
timingSafeEqual(left: ArrayBuffer | ArrayBufferView, right: ArrayBuffer | ArrayBufferView): boolean;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
subtle: SubtleCrypto & {
|
|
196
|
+
timingSafeEqual(left: ArrayBuffer | ArrayBufferView, right: ArrayBuffer | ArrayBufferView): boolean;
|
|
197
|
+
};
|
|
198
|
+
getRandomValues: <T extends Exclude<BufferSource, ArrayBuffer>>(array: T) => T;
|
|
199
|
+
CryptoKey: {
|
|
200
|
+
new (): CryptoKey;
|
|
201
|
+
prototype: CryptoKey;
|
|
202
|
+
};
|
|
203
|
+
randomInt: typeof randomInt;
|
|
204
|
+
randomUUID: typeof randomUUID;
|
|
205
|
+
pseudoRandomBytes: typeof randomBytes;
|
|
206
|
+
randomBytes: typeof randomBytes;
|
|
207
|
+
randomFill: typeof randomFill;
|
|
208
|
+
randomFillSync: typeof randomFillSync;
|
|
209
|
+
hash: typeof hash;
|
|
210
|
+
scrypt: typeof scrypt;
|
|
211
|
+
scryptSync: typeof scryptSync;
|
|
212
|
+
};
|
|
30
213
|
export default _default;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import * as dh from "./dh.js";
|
|
2
|
+
export * from "./dh.js";
|
|
3
|
+
import { pbkdf2, pbkdf2Sync } from "./pbkdf2.js";
|
|
4
|
+
export { pbkdf2, pbkdf2Sync };
|
|
5
|
+
import { Hash, Hmac, createHmac, createHash, hash } from "./hash.js";
|
|
6
|
+
export { Hash, Hmac, createHmac, createHash, hash };
|
|
1
7
|
import { X509Certificate } from "./x509.js";
|
|
2
8
|
export { X509Certificate };
|
|
3
9
|
import { Certificate } from "./certificate.js";
|
|
@@ -14,40 +20,43 @@ import * as keys from "./keys.js";
|
|
|
14
20
|
export { KeyObject, SecretKeyObject, PublicKeyObject, PrivateKeyObject, createSecretKey, generateKey, generateKeySync, } from "./keys.js";
|
|
15
21
|
import * as metadata from "./metadata.js";
|
|
16
22
|
export * from "./metadata.js";
|
|
17
|
-
// Existing algorithms retain the dependency implementation. Additional APIs
|
|
18
|
-
// below are separately verified against the pinned Workers profile.
|
|
19
|
-
// @ts-expect-error crypto-browserify has no declarations
|
|
20
|
-
import original from "crypto-browserify/index.js";
|
|
21
23
|
import { hkdf, hkdfSync } from "./hkdf.js";
|
|
22
|
-
import { randomInt, randomUUID } from "./random.js";
|
|
24
|
+
import { randomInt, randomUUID, randomBytes, randomFill, randomFillSync, } from "./random.js";
|
|
25
|
+
export { randomBytes, randomFill, randomFillSync };
|
|
26
|
+
export const pseudoRandomBytes = randomBytes;
|
|
23
27
|
import { scrypt, scryptSync } from "./scrypt.js";
|
|
24
|
-
import { validateString } from "../net/validators.js";
|
|
25
|
-
import { bytes } from "./validation.js";
|
|
26
28
|
export { hkdf, hkdfSync, randomInt, randomUUID, scrypt, scryptSync };
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
import { constants } from "./constants.js";
|
|
30
|
+
export { constants };
|
|
31
|
+
import { Cipheriv, Decipheriv, createCipheriv, createDecipheriv, } from "./symmetric.js";
|
|
32
|
+
export { Cipheriv, Decipheriv, createCipheriv, createDecipheriv };
|
|
30
33
|
import { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt, } from "./rsa.js";
|
|
31
34
|
export { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt };
|
|
32
|
-
|
|
33
|
-
export
|
|
35
|
+
import { webcrypto, subtle } from "./webcrypto.js";
|
|
36
|
+
export { webcrypto, subtle };
|
|
34
37
|
export const getRandomValues = webcrypto.getRandomValues.bind(webcrypto);
|
|
35
38
|
export const CryptoKey = globalThis.CryptoKey;
|
|
36
|
-
export function hash(algorithm, data, outputEncoding = "hex") {
|
|
37
|
-
validateString(algorithm, "algorithm");
|
|
38
|
-
validateString(outputEncoding, "outputEncoding");
|
|
39
|
-
const result = original
|
|
40
|
-
.createHash(algorithm)
|
|
41
|
-
.update(bytes(data, "data"))
|
|
42
|
-
.digest();
|
|
43
|
-
return outputEncoding === "buffer" ? result : result.toString(outputEncoding);
|
|
44
|
-
}
|
|
45
39
|
export default {
|
|
46
40
|
X509Certificate,
|
|
47
41
|
Certificate,
|
|
48
|
-
...
|
|
42
|
+
...dh,
|
|
43
|
+
constants,
|
|
44
|
+
pbkdf2,
|
|
45
|
+
pbkdf2Sync,
|
|
46
|
+
Hash,
|
|
47
|
+
createHash,
|
|
49
48
|
...metadata,
|
|
50
|
-
|
|
49
|
+
get fips() {
|
|
50
|
+
return metadata.getFips();
|
|
51
|
+
},
|
|
52
|
+
set fips(value) {
|
|
53
|
+
metadata.setFips(value);
|
|
54
|
+
},
|
|
55
|
+
createPrivateKey: asymmetric.createPrivateKey,
|
|
56
|
+
createPublicKey: asymmetric.createPublicKey,
|
|
57
|
+
generateKeyPair: asymmetric.generateKeyPair,
|
|
58
|
+
generateKeyPairSync: asymmetric.generateKeyPairSync,
|
|
59
|
+
timingSafeEqual: asymmetric.timingSafeEqual,
|
|
51
60
|
...signatures,
|
|
52
61
|
...prime,
|
|
53
62
|
publicEncrypt,
|
|
@@ -77,6 +86,10 @@ export default {
|
|
|
77
86
|
CryptoKey,
|
|
78
87
|
randomInt,
|
|
79
88
|
randomUUID,
|
|
89
|
+
pseudoRandomBytes,
|
|
90
|
+
randomBytes,
|
|
91
|
+
randomFill,
|
|
92
|
+
randomFillSync,
|
|
80
93
|
hash,
|
|
81
94
|
scrypt,
|
|
82
95
|
scryptSync,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NodeError } from "../net/error-base.js";
|
|
2
|
+
export declare class ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS extends NodeError {
|
|
3
|
+
constructor(type: string, reason: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class ERR_INCOMPATIBLE_OPTION_PAIR extends NodeError {
|
|
6
|
+
constructor(a: string, b: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class ERR_MISSING_OPTION extends NodeError {
|
|
9
|
+
constructor(name: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// From pinned workerd internal_errors.ts (Apache-2.0 / Node MIT).
|
|
2
|
+
import { NodeError } from "../net/error-base.js";
|
|
3
|
+
export class ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS extends NodeError {
|
|
4
|
+
constructor(type, reason) {
|
|
5
|
+
super("ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS", `The selected key encoding ${type} ${reason}.`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class ERR_INCOMPATIBLE_OPTION_PAIR extends NodeError {
|
|
9
|
+
constructor(a, b) {
|
|
10
|
+
super("ERR_INCOMPATIBLE_OPTION_PAIR", `The options "${a}" and "${b}" are mutually exclusive.`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class ERR_MISSING_OPTION extends NodeError {
|
|
14
|
+
constructor(name) {
|
|
15
|
+
super("ERR_MISSING_OPTION", name);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NativeKey } from "./native-crypto.js";
|
|
2
|
+
export declare function exportOptions(value: any): {
|
|
3
|
+
type?: string;
|
|
4
|
+
format?: string;
|
|
5
|
+
cipher?: string;
|
|
6
|
+
passphrase?: Uint8Array;
|
|
7
|
+
};
|
|
8
|
+
export declare function exportAsymmetric(key: NativeKey, privateKey: boolean, options: ReturnType<typeof exportOptions>): Uint8Array<ArrayBufferLike>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { dictionaryString } from "./key-formats.js";
|
|
2
|
+
import { encodeKey } from "./native-cipher.js";
|
|
3
|
+
import { bufferBytes, isAnyBuffer, viewBytes, } from "../../shared/buffer-source.js";
|
|
4
|
+
// JSG KeyExportOptions is converted after the JavaScript frontend validation.
|
|
5
|
+
export function exportOptions(value) {
|
|
6
|
+
const result = {};
|
|
7
|
+
for (const name of ["type", "format", "cipher"]) {
|
|
8
|
+
const field = value[name];
|
|
9
|
+
if (field !== undefined)
|
|
10
|
+
result[name] = dictionaryString(field);
|
|
11
|
+
}
|
|
12
|
+
const passphrase = value.passphrase;
|
|
13
|
+
if (passphrase !== undefined) {
|
|
14
|
+
if (!isAnyBuffer(passphrase) && !ArrayBuffer.isView(passphrase))
|
|
15
|
+
throw new TypeError("Incorrect type for the 'passphrase' field on 'KeyExportOptions': the provided value is not of type 'BufferSource'.");
|
|
16
|
+
result.passphrase = isAnyBuffer(passphrase)
|
|
17
|
+
? bufferBytes(passphrase)
|
|
18
|
+
: viewBytes(passphrase);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
export function exportAsymmetric(key, privateKey, options) {
|
|
23
|
+
const { format, type, cipher, passphrase } = options;
|
|
24
|
+
if (type === undefined)
|
|
25
|
+
throw new TypeError("Missing type option");
|
|
26
|
+
if (format !== "pem" && format !== "der")
|
|
27
|
+
throw new Error("Invalid key format");
|
|
28
|
+
if (!["pkcs1", "pkcs8", "sec1", "spki"].includes(type))
|
|
29
|
+
throw new Error("Invalid key encoding");
|
|
30
|
+
if (type === "pkcs1" && key.type !== "rsa" && key.type !== "rsa-pss")
|
|
31
|
+
throw new Error("PKCS1 can only be used for RSA keys");
|
|
32
|
+
if (type === "sec1" && key.type !== "ec")
|
|
33
|
+
throw new Error("SEC1 can only be used for EC keys");
|
|
34
|
+
if (key.type === "dh")
|
|
35
|
+
throw new Error("Failed to export key");
|
|
36
|
+
let canonical;
|
|
37
|
+
try {
|
|
38
|
+
canonical = key.export(privateKey, false, privateKey ? "pkcs8" : "spki");
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw new Error("Failed to export key");
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return encodeKey(canonical, privateKey, format === "pem", type, cipher, passphrase, key.ecEncoding);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
canonical.fill(0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -2,5 +2,6 @@ import { Buffer } from "node:buffer";
|
|
|
2
2
|
import { NativeKey } from "./native-crypto.js";
|
|
3
3
|
export declare function der(tag: number, ...parts: Uint8Array[]): Buffer;
|
|
4
4
|
export declare function integer(bytes: Uint8Array): Buffer;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function dictionaryString(value: any): string;
|
|
6
|
+
export declare function importJwk(value: any, privateKey: boolean): NativeKey;
|
|
6
7
|
export declare function exportJwk(key: NativeKey, privateKey: boolean): any;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import { NativeKey } from "./native-crypto.js";
|
|
3
|
+
import { curveName, validateEcPrivate } from "./native-cipher.js";
|
|
3
4
|
// DER encodings follow RFC 5208/5915/8410; JWK members follow RFC 7518/8037.
|
|
4
5
|
const curves = {
|
|
5
6
|
"P-256": { oid: "2a8648ce3d030107", size: 32, native: "prime256v1" },
|
|
6
7
|
"P-384": { oid: "2b81040022", size: 48, native: "secp384r1" },
|
|
7
8
|
"P-521": { oid: "2b81040023", size: 66, native: "secp521r1" },
|
|
8
|
-
|
|
9
|
+
"": { oid: "2b81040021", size: 28, native: "secp224r1" },
|
|
9
10
|
};
|
|
10
11
|
export function der(tag, ...parts) {
|
|
11
12
|
const data = Buffer.concat(parts);
|
|
@@ -26,50 +27,180 @@ export function integer(bytes) {
|
|
|
26
27
|
let offset = 0;
|
|
27
28
|
while (offset < bytes.length - 1 && bytes[offset] === 0)
|
|
28
29
|
offset++;
|
|
29
|
-
const data = bytes.subarray(offset);
|
|
30
|
+
const data = bytes.length ? bytes.subarray(offset) : Buffer.from([0]);
|
|
30
31
|
return der(2, ...(data[0] & 128 ? [Buffer.from([0]), data] : [data]));
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
-
if (
|
|
34
|
-
throw new
|
|
35
|
-
|
|
36
|
-
if (size !== undefined && bytes.length !== size)
|
|
37
|
-
throw new TypeError(`Invalid JWK member length: ${name}`);
|
|
38
|
-
if (!bytes.length)
|
|
39
|
-
throw new TypeError(`Empty JWK member: ${name}`);
|
|
40
|
-
return bytes;
|
|
33
|
+
function required(jwk, name) {
|
|
34
|
+
if (jwk[name] === undefined)
|
|
35
|
+
throw new Error(`${jwk.kty} JWK missing ${name} parameter`);
|
|
36
|
+
return `${jwk[name]}`;
|
|
41
37
|
}
|
|
42
|
-
|
|
38
|
+
function field(jwk, name) {
|
|
39
|
+
const value = required(jwk, name).replace(/[\t\n\f\r ]/g, "");
|
|
40
|
+
if (!/^[A-Za-z0-9_-]*={0,2}$/.test(value) ||
|
|
41
|
+
value.replace(/=+$/, "").length % 4 === 1 ||
|
|
42
|
+
(value.includes("=") && value.length % 4 !== 0))
|
|
43
|
+
throw new Error(`${jwk.kty} JWK invalid ${name} parameter`);
|
|
44
|
+
return Buffer.from(value, "base64url");
|
|
45
|
+
}
|
|
46
|
+
function fixed(bytes, length) {
|
|
47
|
+
let start = 0;
|
|
48
|
+
while (start < bytes.length && bytes[start] === 0)
|
|
49
|
+
start++;
|
|
50
|
+
bytes = bytes.subarray(start);
|
|
51
|
+
if (bytes.length > length)
|
|
52
|
+
throw new Error("EC JWK invalid public key");
|
|
53
|
+
return Buffer.concat([Buffer.alloc(length - bytes.length), bytes]);
|
|
54
|
+
}
|
|
55
|
+
export function dictionaryString(value) {
|
|
56
|
+
const object = (item) => item !== null && (typeof item === "object" || typeof item === "function");
|
|
57
|
+
if (object(value)) {
|
|
58
|
+
const primitive = value[Symbol.toPrimitive];
|
|
59
|
+
if (primitive != null) {
|
|
60
|
+
value = Reflect.apply(primitive, value, ["string"]);
|
|
61
|
+
if (object(value))
|
|
62
|
+
throw new TypeError("Cannot convert object to primitive value");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const original = value;
|
|
66
|
+
for (const name of ["toString", "valueOf"]) {
|
|
67
|
+
const method = original[name];
|
|
68
|
+
if (typeof method !== "function")
|
|
69
|
+
continue;
|
|
70
|
+
value = Reflect.apply(method, original, []);
|
|
71
|
+
if (!object(value))
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (object(value))
|
|
75
|
+
throw new TypeError("Cannot convert object to primitive value");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (typeof value === "symbol")
|
|
79
|
+
throw new TypeError("Cannot convert a Symbol value to a string");
|
|
80
|
+
return String(value).replace(/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g, "\ufffd");
|
|
81
|
+
}
|
|
82
|
+
function dictionary(value) {
|
|
83
|
+
const result = {};
|
|
84
|
+
for (const name of [
|
|
85
|
+
"kty",
|
|
86
|
+
"use",
|
|
87
|
+
"key_ops",
|
|
88
|
+
"alg",
|
|
89
|
+
"ext",
|
|
90
|
+
"crv",
|
|
91
|
+
"x",
|
|
92
|
+
"y",
|
|
93
|
+
"d",
|
|
94
|
+
"n",
|
|
95
|
+
"e",
|
|
96
|
+
"p",
|
|
97
|
+
"q",
|
|
98
|
+
"dp",
|
|
99
|
+
"dq",
|
|
100
|
+
"qi",
|
|
101
|
+
"oth",
|
|
102
|
+
"k",
|
|
103
|
+
"pub",
|
|
104
|
+
"priv",
|
|
105
|
+
]) {
|
|
106
|
+
const field = value[name];
|
|
107
|
+
if (field === undefined && name !== "kty")
|
|
108
|
+
continue;
|
|
109
|
+
if (name === "key_ops" || name === "oth") {
|
|
110
|
+
if (!Array.isArray(field))
|
|
111
|
+
throw new TypeError(`Incorrect type for the '${name}' field on 'JsonWebKey': the provided value is not of type 'Array'.`);
|
|
112
|
+
result[name] = [];
|
|
113
|
+
const length = field.length;
|
|
114
|
+
for (let i = 0; i < length; i++) {
|
|
115
|
+
const item = field[i];
|
|
116
|
+
if (name === "key_ops")
|
|
117
|
+
result[name].push(dictionaryString(item));
|
|
118
|
+
else {
|
|
119
|
+
if (item != null &&
|
|
120
|
+
typeof item !== "object" &&
|
|
121
|
+
typeof item !== "function")
|
|
122
|
+
throw new TypeError(`Incorrect type for array element ${i}: the provided value is not of type 'RsaOtherPrimesInfo'.`);
|
|
123
|
+
const prime = {};
|
|
124
|
+
for (const member of ["r", "d", "t"]) {
|
|
125
|
+
const part = item?.[member];
|
|
126
|
+
if (part !== undefined)
|
|
127
|
+
prime[member] = dictionaryString(part);
|
|
128
|
+
}
|
|
129
|
+
result[name].push(prime);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
result[name] = name === "ext" ? Boolean(field) : dictionaryString(field);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
export function importJwk(value, privateKey) {
|
|
139
|
+
const jwk = dictionary(value);
|
|
140
|
+
const unsupported = () => new Error(`JWK ${privateKey ? "private" : "public"} key import is not implemented for this key type`);
|
|
43
141
|
if (jwk?.kty === "RSA") {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
142
|
+
required(jwk, "n");
|
|
143
|
+
required(jwk, "e");
|
|
144
|
+
const values = [field(jwk, "n"), field(jwk, "e")];
|
|
145
|
+
if (privateKey) {
|
|
146
|
+
const names = ["d", "p", "q", "dp", "dq", "qi"];
|
|
147
|
+
for (const name of names)
|
|
148
|
+
required(jwk, name);
|
|
149
|
+
values.push(...names.map((name) => field(jwk, name)));
|
|
150
|
+
}
|
|
151
|
+
return NativeKey.parse(der(48, ...(privateKey ? [integer(Buffer.from([0]))] : []), ...values.map(integer)), false, privateKey);
|
|
48
152
|
}
|
|
49
153
|
if (jwk?.kty === "EC") {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
154
|
+
const crv = required(jwk, "crv");
|
|
155
|
+
let native;
|
|
156
|
+
try {
|
|
157
|
+
native = curveName(crv);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
throw new Error(error.message === "Failed to initialize key"
|
|
161
|
+
? "EC JWK unsupported curve"
|
|
162
|
+
: "EC JWK unsupported crv parameter");
|
|
163
|
+
}
|
|
164
|
+
const curve = Object.values(curves).find((value) => value.native === native);
|
|
165
|
+
required(jwk, "x");
|
|
166
|
+
required(jwk, "y");
|
|
167
|
+
const x = field(jwk, "x"), y = field(jwk, "y");
|
|
53
168
|
const oid = der(6, Buffer.from(curve.oid, "hex"));
|
|
54
169
|
const point = Buffer.concat([
|
|
55
170
|
Buffer.from([4]),
|
|
56
|
-
|
|
57
|
-
|
|
171
|
+
fixed(x, curve.size),
|
|
172
|
+
fixed(y, curve.size),
|
|
58
173
|
]);
|
|
59
174
|
const bits = der(3, Buffer.from([0]), point);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
175
|
+
const publicData = der(48, der(48, der(6, Buffer.from("2a8648ce3d0201", "hex")), oid), bits);
|
|
176
|
+
let publicKey;
|
|
177
|
+
try {
|
|
178
|
+
publicKey = NativeKey.parse(publicData, false, false);
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
throw new Error("EC JWK invalid public key");
|
|
182
|
+
}
|
|
183
|
+
if (!privateKey)
|
|
184
|
+
return publicKey;
|
|
185
|
+
publicKey.dispose();
|
|
186
|
+
const d = field(jwk, "d");
|
|
187
|
+
validateEcPrivate(native, d);
|
|
188
|
+
return NativeKey.parse(der(48, integer(Buffer.from([1])), der(4, d), der(160, oid), der(161, bits)), false, true);
|
|
64
189
|
}
|
|
65
|
-
if (jwk?.kty === "OKP"
|
|
66
|
-
const
|
|
190
|
+
if (jwk?.kty === "OKP") {
|
|
191
|
+
const crv = required(jwk, "crv");
|
|
192
|
+
if (!["Ed25519", "X25519"].includes(crv))
|
|
193
|
+
throw new Error("OKP JWK unsupported crv parameter");
|
|
194
|
+
const value = field(jwk, privateKey ? "d" : "x");
|
|
195
|
+
if (value.length !== 32)
|
|
196
|
+
throw unsupported();
|
|
197
|
+
const algorithm = der(48, der(6, Buffer.from([43, 101, crv === "Ed25519" ? 112 : 110])));
|
|
67
198
|
const data = privateKey
|
|
68
|
-
? der(48, integer(Buffer.from([0])), algorithm, der(4, der(4,
|
|
69
|
-
: der(48, algorithm, der(3, Buffer.from([0]),
|
|
199
|
+
? der(48, integer(Buffer.from([0])), algorithm, der(4, der(4, value)))
|
|
200
|
+
: der(48, algorithm, der(3, Buffer.from([0]), value));
|
|
70
201
|
return NativeKey.parse(data, false, privateKey);
|
|
71
202
|
}
|
|
72
|
-
throw
|
|
203
|
+
throw unsupported();
|
|
73
204
|
}
|
|
74
205
|
function encode(bytes, size) {
|
|
75
206
|
if (size !== undefined && bytes.length < size)
|
|
@@ -116,5 +247,5 @@ export function exportJwk(key, privateKey) {
|
|
|
116
247
|
x: encode(key.raw(false)),
|
|
117
248
|
...(privateKey ? { d: encode(key.raw(true)) } : {}),
|
|
118
249
|
};
|
|
119
|
-
throw new
|
|
250
|
+
throw new Error("Key type is invalid for JWK export");
|
|
120
251
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateExportOptions(options: any, type: string, name?: string, asymmetricKeyType?: string): void;
|