cf-workers-native 0.1.4 → 0.1.5
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/dist/browser/documents/page-source.js +1 -1
- package/dist/browser/fetch/host-call.js +6 -1
- package/dist/browser/fetch/native-network.d.ts +1 -1
- package/dist/browser/fetch/relay.js +2 -0
- package/dist/browser/isolated/transport.js +3 -2
- package/dist/browser/request/index.js +3 -2
- package/dist/cloudflare/workers/worker-runtime.js +2 -1
- package/dist/compat/console/index.d.ts +35 -0
- package/dist/compat/console/index.js +92 -0
- package/dist/compat/crypto/LICENSE-3RD-PARTY.md +19 -0
- package/dist/compat/crypto/LICENSE-APACHE +177 -0
- package/dist/compat/crypto/LICENSE.emscripten +102 -0
- package/dist/compat/crypto/LICENSE.musl +193 -0
- package/dist/compat/crypto/LICENSE.openssl +177 -0
- package/dist/compat/crypto/asymmetric.d.ts +13 -0
- package/dist/compat/crypto/asymmetric.js +239 -0
- package/dist/compat/crypto/brorand.cjs +74 -0
- package/dist/compat/crypto/brorand.d.cts +6 -0
- package/dist/compat/crypto/certificate.d.ts +14 -0
- package/dist/compat/crypto/certificate.js +66 -0
- package/dist/compat/crypto/ecdh.d.ts +15 -0
- package/dist/compat/crypto/ecdh.js +109 -0
- package/dist/compat/crypto/hkdf.d.ts +2 -0
- package/dist/compat/crypto/hkdf.js +52 -0
- package/dist/compat/crypto/index.cjs +2 -0
- package/dist/compat/crypto/index.d.cts +2 -0
- package/dist/compat/crypto/index.d.ts +30 -0
- package/dist/compat/crypto/index.js +83 -0
- package/dist/compat/crypto/key-formats.d.ts +6 -0
- package/dist/compat/crypto/key-formats.js +120 -0
- package/dist/compat/crypto/key-state.d.ts +9 -0
- package/dist/compat/crypto/key-state.js +4 -0
- package/dist/compat/crypto/keys.d.ts +50 -0
- package/dist/compat/crypto/keys.js +209 -0
- package/dist/compat/crypto/metadata.d.ts +4 -0
- package/dist/compat/crypto/metadata.js +22 -0
- package/dist/compat/crypto/native-crypto.d.ts +68 -0
- package/dist/compat/crypto/native-crypto.js +569 -0
- package/dist/compat/crypto/prime.d.ts +19 -0
- package/dist/compat/crypto/prime.js +146 -0
- package/dist/compat/crypto/random.d.ts +7 -0
- package/dist/compat/crypto/random.js +123 -0
- package/dist/compat/crypto/rsa.d.ts +5 -0
- package/dist/compat/crypto/rsa.js +173 -0
- package/dist/compat/crypto/scrypt.d.ts +25 -0
- package/dist/compat/crypto/scrypt.js +150 -0
- package/dist/compat/crypto/sign-errors.d.ts +8 -0
- package/dist/compat/crypto/sign-errors.js +13 -0
- package/dist/compat/crypto/sign-handle.d.ts +22 -0
- package/dist/compat/crypto/sign-handle.js +105 -0
- package/dist/compat/crypto/signatures.d.ts +28 -0
- package/dist/compat/crypto/signatures.js +252 -0
- package/dist/compat/crypto/symmetric.d.ts +29 -0
- package/dist/compat/crypto/symmetric.js +104 -0
- package/dist/compat/crypto/validation.d.ts +3 -0
- package/dist/compat/crypto/validation.js +19 -0
- package/dist/compat/crypto/x509.d.ts +30 -0
- package/dist/compat/crypto/x509.js +406 -0
- package/dist/compat/events/errors.d.ts +8 -0
- package/dist/compat/events/errors.js +39 -0
- package/dist/compat/events/index.cjs +2 -0
- package/dist/compat/events/index.d.cts +2 -0
- package/dist/compat/events/index.d.ts +64 -0
- package/dist/compat/events/index.js +792 -0
- package/dist/compat/events/intrinsics.d.ts +1 -0
- package/dist/compat/events/intrinsics.js +2 -0
- package/dist/compat/fs/embedded.d.ts +85 -0
- package/dist/compat/fs/embedded.js +255 -0
- package/dist/compat/fs/index.d.ts +7 -84
- package/dist/compat/fs/index.js +218 -252
- package/dist/compat/fs/mode.d.ts +1 -0
- package/dist/compat/fs/mode.js +13 -0
- package/dist/compat/fs/promises/index.d.ts +1 -1
- package/dist/compat/fs/promises/index.js +1 -1
- package/dist/compat/fs/writable.d.ts +6 -0
- package/dist/compat/fs/writable.js +142 -0
- package/dist/compat/http/symbols.d.ts +5 -0
- package/dist/compat/http/symbols.js +9 -0
- package/dist/compat/http-common/index.d.ts +37 -0
- package/dist/compat/http-common/index.js +43 -0
- package/dist/compat/http-outgoing/index.d.ts +13 -0
- package/dist/compat/http-outgoing/index.js +32 -0
- package/dist/compat/http-server/index.d.ts +18 -0
- package/dist/compat/http-server/index.js +107 -0
- package/dist/compat/module/builtins.d.ts +1 -0
- package/dist/compat/module/builtins.js +101 -0
- package/dist/compat/module/index.d.ts +4 -2
- package/dist/compat/module/index.js +22 -17
- package/dist/compat/module/metadata.d.ts +44 -0
- package/dist/compat/module/metadata.js +127 -0
- package/dist/compat/net/internal-net.js +4 -0
- package/dist/compat/net/sockets.d.ts +5 -0
- package/dist/compat/net/sockets.js +74 -13
- package/dist/compat/process/index.cjs +2 -0
- package/dist/compat/process/index.d.cts +4 -0
- package/dist/compat/process/index.d.ts +18 -0
- package/dist/compat/process/index.js +140 -0
- package/dist/compat/process/metadata.d.ts +135 -0
- package/dist/compat/process/metadata.js +251 -0
- package/dist/compat/process/state.d.ts +4 -0
- package/dist/compat/process/state.js +4 -0
- package/dist/compat/stream-web/LICENSE +22 -0
- package/dist/compat/stream-web/ponyfill.d.ts +1 -1
- package/dist/compat/stream-web/ponyfill.js +2369 -1775
- package/dist/compat/stream-web/runtime.d.ts +1 -1
- package/dist/compat/stream-web/runtime.js +3 -2
- package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/stream-wrap/index.d.ts +1 -0
- package/dist/compat/stream-wrap/index.js +1 -0
- package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls/LICENSE-APACHE +177 -0
- package/dist/compat/tls/constants.d.ts +7 -0
- package/dist/compat/tls/constants.js +14 -0
- package/dist/compat/tls/errors.d.ts +35 -0
- package/dist/compat/tls/errors.js +68 -0
- package/dist/compat/tls/helpers.d.ts +9 -0
- package/dist/compat/tls/helpers.js +207 -0
- package/dist/compat/tls/index.d.ts +26 -0
- package/dist/compat/tls/index.js +50 -0
- package/dist/compat/tls/jsstream.d.ts +19 -0
- package/dist/compat/tls/jsstream.js +186 -0
- package/dist/compat/tls/native-session.d.ts +3 -0
- package/dist/compat/tls/native-session.js +187 -0
- package/dist/compat/tls/wrap.d.ts +65 -0
- package/dist/compat/tls/wrap.js +544 -0
- package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/tls-wrap/index.d.ts +7 -0
- package/dist/compat/tls-wrap/index.js +3 -0
- package/dist/compat/util/index.js +43 -1
- package/dist/compat/util/types/index.d.ts +3 -0
- package/dist/compat/util/types/index.js +5 -0
- package/dist/compat/zlib/LICENSE.brotli +19 -0
- package/dist/compat/zlib/LICENSE.emscripten +102 -0
- package/dist/compat/zlib/LICENSE.musl +193 -0
- package/dist/compat/zlib/LICENSE.zstd +30 -0
- package/dist/compat/zlib/compression.d.ts +55 -0
- package/dist/compat/zlib/compression.js +259 -0
- package/dist/compat/zlib/constants.d.ts +172 -0
- package/dist/compat/zlib/constants.js +173 -0
- package/dist/compat/zlib/index.d.ts +180 -0
- package/dist/compat/zlib/index.js +177 -0
- package/dist/compat/zlib/native-codecs.d.ts +17 -0
- package/dist/compat/zlib/native-codecs.js +168 -0
- package/dist/shared/globals/inject.d.ts +2 -1
- package/dist/shared/globals/inject.js +2 -1
- package/dist/shared/globals/runtime.d.ts +1 -2
- package/dist/shared/globals/runtime.js +1 -2
- package/dist/shared/request-scope.d.ts +4 -0
- package/dist/shared/request-scope.js +11 -0
- package/dist/tooling/async.js +36 -14
- package/dist/tooling/shared.d.ts +1 -0
- package/dist/tooling/shared.js +20 -1
- package/dist/tooling/vite.js +4 -3
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +56 -8
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
- package/native/ios/NetworkBridge.swift +11 -1
- package/native/ios/SocketBridge.swift +37 -2
- package/native/ios/WorkersCapacitorPlugin.swift +4 -0
- package/package.json +3 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Browser-only adaptation of brorand 1.1.0.
|
|
3
|
+
|
|
4
|
+
This software is licensed under the MIT License.
|
|
5
|
+
|
|
6
|
+
Copyright Fedor Indutny, 2014.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
copy of this software and associated documentation files (the
|
|
10
|
+
"Software"), to deal in the Software without restriction, including
|
|
11
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
12
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
13
|
+
persons to whom the Software is furnished to do so, subject to the
|
|
14
|
+
following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included
|
|
17
|
+
in all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
20
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
21
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
22
|
+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
23
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
24
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
25
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
|
|
27
|
+
*/
|
|
28
|
+
var r;
|
|
29
|
+
module.exports = function rand(len) {
|
|
30
|
+
if (!r)
|
|
31
|
+
r = new Rand(null);
|
|
32
|
+
return r.generate(len);
|
|
33
|
+
};
|
|
34
|
+
function Rand(rand) {
|
|
35
|
+
this.rand = rand;
|
|
36
|
+
}
|
|
37
|
+
module.exports.Rand = Rand;
|
|
38
|
+
Rand.prototype.generate = function generate(len) {
|
|
39
|
+
return this._rand(len);
|
|
40
|
+
};
|
|
41
|
+
// Emulate crypto API using randy
|
|
42
|
+
Rand.prototype._rand = function _rand(n) {
|
|
43
|
+
if (this.rand.getBytes)
|
|
44
|
+
return this.rand.getBytes(n);
|
|
45
|
+
var res = new Uint8Array(n);
|
|
46
|
+
for (var i = 0; i < res.length; i++)
|
|
47
|
+
res[i] = this.rand.getByte();
|
|
48
|
+
return res;
|
|
49
|
+
};
|
|
50
|
+
if (typeof self === "object") {
|
|
51
|
+
if (self.crypto && self.crypto.getRandomValues) {
|
|
52
|
+
// Modern browsers
|
|
53
|
+
Rand.prototype._rand = function _rand(n) {
|
|
54
|
+
var arr = new Uint8Array(n);
|
|
55
|
+
self.crypto.getRandomValues(arr);
|
|
56
|
+
return arr;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else if (self.msCrypto && self.msCrypto.getRandomValues) {
|
|
60
|
+
// IE
|
|
61
|
+
Rand.prototype._rand = function _rand(n) {
|
|
62
|
+
var arr = new Uint8Array(n);
|
|
63
|
+
self.msCrypto.getRandomValues(arr);
|
|
64
|
+
return arr;
|
|
65
|
+
};
|
|
66
|
+
// Safari's WebWorkers do not have `crypto`
|
|
67
|
+
}
|
|
68
|
+
else if (typeof window === "object") {
|
|
69
|
+
// Old junk
|
|
70
|
+
Rand.prototype._rand = function () {
|
|
71
|
+
throw new Error("Not implemented yet");
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
export declare function verifySpkac(spkac: Buffer | ArrayBuffer | ArrayBufferView | string, encoding?: string): boolean;
|
|
3
|
+
export declare function exportPublicKey(spkac: Buffer | ArrayBuffer | ArrayBufferView | string, encoding?: string): Buffer;
|
|
4
|
+
export declare function exportChallenge(spkac: Buffer | ArrayBuffer | ArrayBufferView | string, encoding?: string): Buffer;
|
|
5
|
+
export declare class Certificate {
|
|
6
|
+
constructor();
|
|
7
|
+
verifySpkac: typeof verifySpkac;
|
|
8
|
+
exportPublicKey: typeof exportPublicKey;
|
|
9
|
+
exportChallenge: typeof exportChallenge;
|
|
10
|
+
static verifySpkac: typeof verifySpkac;
|
|
11
|
+
static exportPublicKey: typeof exportPublicKey;
|
|
12
|
+
static exportChallenge: typeof exportChallenge;
|
|
13
|
+
}
|
|
14
|
+
export declare function Certificate(this: unknown): Certificate;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
3
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
4
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
5
|
+
//
|
|
6
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
7
|
+
//
|
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
// copy of this software and associated documentation files (the
|
|
10
|
+
// "Software"), to deal in the Software without restriction, including
|
|
11
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
12
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
13
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
14
|
+
// following conditions:
|
|
15
|
+
//
|
|
16
|
+
// The above copyright notice and this permission notice shall be included
|
|
17
|
+
// in all copies or substantial portions of the Software.
|
|
18
|
+
//
|
|
19
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
20
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
21
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
22
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
23
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
24
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
25
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
import { nativeSpkac } from "./native-crypto.js";
|
|
27
|
+
import { bytes } from "./validation.js";
|
|
28
|
+
import { isAnyArrayBuffer } from "../util/types/index.js";
|
|
29
|
+
const cryptoImpl = {
|
|
30
|
+
verifySpkac: (data) => nativeSpkac(data, 0),
|
|
31
|
+
exportPublicKey: (data) => nativeSpkac(data, 1),
|
|
32
|
+
exportChallenge: (data) => nativeSpkac(data, 2),
|
|
33
|
+
};
|
|
34
|
+
import { Buffer } from "node:buffer";
|
|
35
|
+
function getArrayBufferOrView(value, name, encoding) {
|
|
36
|
+
if (typeof value === "string")
|
|
37
|
+
return Buffer.from(value, encoding === "buffer" ? undefined : encoding);
|
|
38
|
+
if (isAnyArrayBuffer(value))
|
|
39
|
+
return new Uint8Array(value);
|
|
40
|
+
return bytes(value, name);
|
|
41
|
+
}
|
|
42
|
+
export function verifySpkac(spkac, encoding) {
|
|
43
|
+
return cryptoImpl.verifySpkac(getArrayBufferOrView(spkac, "spkac", encoding));
|
|
44
|
+
}
|
|
45
|
+
export function exportPublicKey(spkac, encoding) {
|
|
46
|
+
const ret = cryptoImpl.exportPublicKey(getArrayBufferOrView(spkac, "spkac", encoding));
|
|
47
|
+
return ret ? Buffer.from(ret) : Buffer.alloc(0);
|
|
48
|
+
}
|
|
49
|
+
export function exportChallenge(spkac, encoding) {
|
|
50
|
+
const ret = cryptoImpl.exportChallenge(getArrayBufferOrView(spkac, "spkac", encoding));
|
|
51
|
+
return ret ? Buffer.from(ret) : Buffer.alloc(0);
|
|
52
|
+
}
|
|
53
|
+
// For backwards compatibility reasons, this cannot be converted into a
|
|
54
|
+
// ES6 Class.
|
|
55
|
+
export function Certificate() {
|
|
56
|
+
if (!(this instanceof Certificate)) {
|
|
57
|
+
return new Certificate();
|
|
58
|
+
}
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
Certificate.prototype.verifySpkac = verifySpkac;
|
|
62
|
+
Certificate.prototype.exportPublicKey = exportPublicKey;
|
|
63
|
+
Certificate.prototype.exportChallenge = exportChallenge;
|
|
64
|
+
Certificate.exportChallenge = exportChallenge;
|
|
65
|
+
Certificate.exportPublicKey = exportPublicKey;
|
|
66
|
+
Certificate.verifySpkac = verifySpkac;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
declare const kHandle: unique symbol;
|
|
3
|
+
export interface ECDH {
|
|
4
|
+
[kHandle]: cryptoImpl.ECDHHandle;
|
|
5
|
+
computeSecret(otherPublicKey: string | ArrayBufferView | ArrayBuffer, inputEncoding?: string, outputEncoding?: string): Buffer | string;
|
|
6
|
+
generateKeys(encoding?: string, format?: string): Buffer | string;
|
|
7
|
+
getPrivateKey(encoding?: string): Buffer | string;
|
|
8
|
+
getPublicKey(encoding?: string, format?: string): Buffer | string;
|
|
9
|
+
setPrivateKey(key: string | ArrayBufferView | ArrayBuffer, encoding?: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const ECDH: {
|
|
12
|
+
new (curveName: string): ECDH;
|
|
13
|
+
};
|
|
14
|
+
export declare function createECDH(curveName: string): ECDH;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// Ported from pinned workerd crypto_dh.ts; see LICENSE-APACHE and LICENSE-3RD-PARTY.md.
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
import { NativeECDH } from "./native-crypto.js";
|
|
5
|
+
import { validateString, validateOneOf } from "../net/validators.js";
|
|
6
|
+
import { ERR_INVALID_ARG_TYPE } from "../net/errors.js";
|
|
7
|
+
import { isArrayBufferView } from "../util/types/index.js";
|
|
8
|
+
const cryptoImpl = { ECDHHandle: NativeECDH };
|
|
9
|
+
const kHandle = Symbol("kHandle");
|
|
10
|
+
export const ECDH = function (curveName) {
|
|
11
|
+
if (!(this instanceof ECDH)) {
|
|
12
|
+
return new ECDH(curveName);
|
|
13
|
+
}
|
|
14
|
+
validateString(curveName, "curveName");
|
|
15
|
+
this[kHandle] = new cryptoImpl.ECDHHandle(curveName);
|
|
16
|
+
return this;
|
|
17
|
+
};
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
19
|
+
ECDH.prototype.computeSecret = function (otherPublicKey, inputEncoding, outputEncoding) {
|
|
20
|
+
if (typeof otherPublicKey === "string") {
|
|
21
|
+
otherPublicKey = Buffer.from(otherPublicKey, inputEncoding);
|
|
22
|
+
}
|
|
23
|
+
if (!isArrayBufferView(otherPublicKey)) {
|
|
24
|
+
throw new ERR_INVALID_ARG_TYPE("otherPublicKey", ["string", "Buffer", "TypedArray", "DataView"], otherPublicKey);
|
|
25
|
+
}
|
|
26
|
+
if (inputEncoding != null) {
|
|
27
|
+
validateString(inputEncoding, "inputEncoding");
|
|
28
|
+
}
|
|
29
|
+
if (outputEncoding != null) {
|
|
30
|
+
validateString(outputEncoding, "outputEncoding");
|
|
31
|
+
}
|
|
32
|
+
const ret = this[kHandle].computeSecret(otherPublicKey);
|
|
33
|
+
if (typeof outputEncoding === "string") {
|
|
34
|
+
return Buffer.from(ret).toString(outputEncoding);
|
|
35
|
+
}
|
|
36
|
+
return Buffer.from(ret);
|
|
37
|
+
};
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
39
|
+
ECDH.prototype.generateKeys = function (encoding, format) {
|
|
40
|
+
if (encoding != null) {
|
|
41
|
+
validateString(encoding, "encoding");
|
|
42
|
+
}
|
|
43
|
+
if (format != null) {
|
|
44
|
+
validateOneOf(format, "format", ["compressed", "uncompressed", "hybrid"]);
|
|
45
|
+
}
|
|
46
|
+
this[kHandle].generateKeys();
|
|
47
|
+
return this.getPublicKey(encoding, format);
|
|
48
|
+
};
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
50
|
+
ECDH.prototype.getPrivateKey = function (encoding) {
|
|
51
|
+
if (encoding != null) {
|
|
52
|
+
validateString(encoding, "encoding");
|
|
53
|
+
}
|
|
54
|
+
const pvt = this[kHandle].getPrivateKey();
|
|
55
|
+
if (typeof encoding === "string") {
|
|
56
|
+
return Buffer.from(pvt).toString(encoding);
|
|
57
|
+
}
|
|
58
|
+
return Buffer.from(pvt);
|
|
59
|
+
};
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
61
|
+
ECDH.prototype.getPublicKey = function (encoding, format = "uncompressed") {
|
|
62
|
+
if (encoding != null) {
|
|
63
|
+
validateString(encoding, "encoding");
|
|
64
|
+
}
|
|
65
|
+
validateOneOf(format, "format", ["compressed", "uncompressed", "hybrid"]);
|
|
66
|
+
const pub = this[kHandle].getPublicKey(format);
|
|
67
|
+
if (typeof encoding === "string") {
|
|
68
|
+
return Buffer.from(pub).toString(encoding);
|
|
69
|
+
}
|
|
70
|
+
return Buffer.from(pub);
|
|
71
|
+
};
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
73
|
+
ECDH.prototype.setPrivateKey = function (key, encoding) {
|
|
74
|
+
if (encoding != null) {
|
|
75
|
+
validateString(encoding, "encoding");
|
|
76
|
+
}
|
|
77
|
+
if (typeof key === "string") {
|
|
78
|
+
key = Buffer.from(key, encoding);
|
|
79
|
+
}
|
|
80
|
+
if (!isArrayBufferView(key)) {
|
|
81
|
+
throw new ERR_INVALID_ARG_TYPE("key", ["string", "Buffer", "TypedArray", "DataView"], key);
|
|
82
|
+
}
|
|
83
|
+
this[kHandle].setPrivateKey(key);
|
|
84
|
+
};
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
|
|
86
|
+
ECDH.convertKey = function (key, curve, inputEncoding, outputEncoding, format = "uncompressed") {
|
|
87
|
+
if (typeof key === "string") {
|
|
88
|
+
key = Buffer.from(key, inputEncoding);
|
|
89
|
+
}
|
|
90
|
+
if (!isArrayBufferView(key)) {
|
|
91
|
+
throw new ERR_INVALID_ARG_TYPE("key", ["string", "Buffer", "TypedArray", "DataView"], key);
|
|
92
|
+
}
|
|
93
|
+
validateString(curve, "curve");
|
|
94
|
+
if (inputEncoding != null) {
|
|
95
|
+
validateString(inputEncoding, "inputEncoding");
|
|
96
|
+
}
|
|
97
|
+
if (outputEncoding != null) {
|
|
98
|
+
validateString(outputEncoding, "outputEncoding");
|
|
99
|
+
}
|
|
100
|
+
validateOneOf(format, "format", ["compressed", "uncompressed", "hybrid"]);
|
|
101
|
+
const ret = cryptoImpl.ECDHHandle.convertKey(key, curve, format);
|
|
102
|
+
if (typeof outputEncoding === "string") {
|
|
103
|
+
return Buffer.from(ret).toString(outputEncoding);
|
|
104
|
+
}
|
|
105
|
+
return Buffer.from(ret);
|
|
106
|
+
};
|
|
107
|
+
export function createECDH(curveName) {
|
|
108
|
+
return new ECDH(curveName);
|
|
109
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function hkdfSync(digest: string, key: unknown, salt: unknown, info: unknown, length: number): ArrayBuffer;
|
|
2
|
+
export declare function hkdf(digest: string, key: unknown, salt: unknown, info: unknown, length: number, callback: (error: unknown, value?: ArrayBuffer) => void): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { secretMaterial } from "./keys.js";
|
|
2
|
+
// RFC 5869 extract-and-expand, using the existing HMAC implementation.
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
// @ts-expect-error dependency has no declarations
|
|
5
|
+
import original from "crypto-browserify/index.js";
|
|
6
|
+
import { bytes, validateInteger } from "./validation.js";
|
|
7
|
+
import { validateString, validateFunction } from "../net/validators.js";
|
|
8
|
+
import { ERR_OUT_OF_RANGE } from "../net/errors.js";
|
|
9
|
+
function parameters(digest, key, salt, info, length) {
|
|
10
|
+
validateString(digest, "digest");
|
|
11
|
+
const ikm = bytes(secretMaterial(key), "ikm"), s = bytes(salt, "salt"), i = bytes(info, "info");
|
|
12
|
+
validateInteger(length, "length", 0, 2147483647);
|
|
13
|
+
if (i.byteLength > 1024)
|
|
14
|
+
throw new ERR_OUT_OF_RANGE("info", "must not contain more than 1024 bytes", i.byteLength);
|
|
15
|
+
return { digest, ikm, s, i, length };
|
|
16
|
+
}
|
|
17
|
+
function derive({ digest, ikm, s, i, length, }) {
|
|
18
|
+
const prk = original.createHmac(digest, s).update(ikm).digest();
|
|
19
|
+
if (length > 255 * prk.length)
|
|
20
|
+
throw Object.assign(new RangeError("Invalid key length"), {
|
|
21
|
+
code: "ERR_CRYPTO_INVALID_KEYLEN",
|
|
22
|
+
});
|
|
23
|
+
const output = Buffer.alloc(length);
|
|
24
|
+
let previous = Buffer.alloc(0);
|
|
25
|
+
try {
|
|
26
|
+
for (let offset = 0, counter = 1; offset < length; counter++) {
|
|
27
|
+
previous = original
|
|
28
|
+
.createHmac(digest, prk)
|
|
29
|
+
.update(previous)
|
|
30
|
+
.update(i)
|
|
31
|
+
.update(Buffer.from([counter]))
|
|
32
|
+
.digest();
|
|
33
|
+
const size = Math.min(previous.length, length - offset);
|
|
34
|
+
output.set(previous.subarray(0, size), offset);
|
|
35
|
+
offset += size;
|
|
36
|
+
}
|
|
37
|
+
return new Uint8Array(output).buffer;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
prk.fill(0);
|
|
41
|
+
previous.fill(0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function hkdfSync(digest, key, salt, info, length) {
|
|
45
|
+
return derive(parameters(digest, key, salt, info, length));
|
|
46
|
+
}
|
|
47
|
+
export function hkdf(digest, key, salt, info, length, callback) {
|
|
48
|
+
const args = parameters(digest, key, salt, info, length);
|
|
49
|
+
validateFunction(callback, "callback");
|
|
50
|
+
const result = new Promise((resolve) => resolve(derive(args)));
|
|
51
|
+
result.then((value) => callback(null, value), (error) => callback(error));
|
|
52
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { X509Certificate } from "./x509.js";
|
|
2
|
+
export { X509Certificate };
|
|
3
|
+
import { Certificate } from "./certificate.js";
|
|
4
|
+
export { Certificate };
|
|
5
|
+
import { ECDH, createECDH } from "./ecdh.js";
|
|
6
|
+
export { ECDH, createECDH };
|
|
7
|
+
export * from "./signatures.js";
|
|
8
|
+
export * from "./prime.js";
|
|
9
|
+
export { createPrivateKey, createPublicKey, generateKeyPair, generateKeyPairSync, diffieHellman, timingSafeEqual, } from "./asymmetric.js";
|
|
10
|
+
export { KeyObject, SecretKeyObject, PublicKeyObject, PrivateKeyObject, createSecretKey, generateKey, generateKeySync, } from "./keys.js";
|
|
11
|
+
export * from "./metadata.js";
|
|
12
|
+
import { hkdf, hkdfSync } from "./hkdf.js";
|
|
13
|
+
import { randomInt, randomUUID } from "./random.js";
|
|
14
|
+
import { scrypt, scryptSync } from "./scrypt.js";
|
|
15
|
+
export { hkdf, hkdfSync, randomInt, randomUUID, scrypt, scryptSync };
|
|
16
|
+
export declare const prng: any, pseudoRandomBytes: any, rng: any, randomBytes: any, Hash: any, createHash: any, getHashes: any, pbkdf2: any, pbkdf2Sync: any, Cipher: any, createCipher: any, Decipher: any, createDecipher: any, getCiphers: any, listCiphers: any, DiffieHellmanGroup: any, createDiffieHellmanGroup: any, getDiffieHellman: any, createDiffieHellman: any, DiffieHellman: any, randomFill: any, randomFillSync: any, createCredentials: any, constants: any;
|
|
17
|
+
import { Hmac, Cipheriv, Decipheriv, createHmac, createCipheriv, createDecipheriv } from "./symmetric.js";
|
|
18
|
+
export { Hmac, Cipheriv, Decipheriv, createHmac, createCipheriv, createDecipheriv, };
|
|
19
|
+
import { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt } from "./rsa.js";
|
|
20
|
+
export { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt };
|
|
21
|
+
export declare const webcrypto: Crypto;
|
|
22
|
+
export declare const subtle: SubtleCrypto;
|
|
23
|
+
export declare const getRandomValues: <T extends Exclude<BufferSource, ArrayBuffer>>(array: T) => T;
|
|
24
|
+
export declare const CryptoKey: {
|
|
25
|
+
new (): CryptoKey;
|
|
26
|
+
prototype: CryptoKey;
|
|
27
|
+
};
|
|
28
|
+
export declare function hash(algorithm: string, data: unknown, outputEncoding?: string): any;
|
|
29
|
+
declare const _default: any;
|
|
30
|
+
export default _default;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { X509Certificate } from "./x509.js";
|
|
2
|
+
export { X509Certificate };
|
|
3
|
+
import { Certificate } from "./certificate.js";
|
|
4
|
+
export { Certificate };
|
|
5
|
+
import { ECDH, createECDH } from "./ecdh.js";
|
|
6
|
+
export { ECDH, createECDH };
|
|
7
|
+
import * as signatures from "./signatures.js";
|
|
8
|
+
export * from "./signatures.js";
|
|
9
|
+
import * as prime from "./prime.js";
|
|
10
|
+
export * from "./prime.js";
|
|
11
|
+
import * as asymmetric from "./asymmetric.js";
|
|
12
|
+
export { createPrivateKey, createPublicKey, generateKeyPair, generateKeyPairSync, diffieHellman, timingSafeEqual, } from "./asymmetric.js";
|
|
13
|
+
import * as keys from "./keys.js";
|
|
14
|
+
export { KeyObject, SecretKeyObject, PublicKeyObject, PrivateKeyObject, createSecretKey, generateKey, generateKeySync, } from "./keys.js";
|
|
15
|
+
import * as metadata from "./metadata.js";
|
|
16
|
+
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
|
+
import { hkdf, hkdfSync } from "./hkdf.js";
|
|
22
|
+
import { randomInt, randomUUID } from "./random.js";
|
|
23
|
+
import { scrypt, scryptSync } from "./scrypt.js";
|
|
24
|
+
import { validateString } from "../net/validators.js";
|
|
25
|
+
import { bytes } from "./validation.js";
|
|
26
|
+
export { hkdf, hkdfSync, randomInt, randomUUID, scrypt, scryptSync };
|
|
27
|
+
export const { prng, pseudoRandomBytes, rng, randomBytes, Hash, createHash, getHashes, pbkdf2, pbkdf2Sync, Cipher, createCipher, Decipher, createDecipher, getCiphers, listCiphers, DiffieHellmanGroup, createDiffieHellmanGroup, getDiffieHellman, createDiffieHellman, DiffieHellman, randomFill, randomFillSync, createCredentials, constants, } = original;
|
|
28
|
+
import { Hmac, Cipheriv, Decipheriv, createHmac, createCipheriv, createDecipheriv, } from "./symmetric.js";
|
|
29
|
+
export { Hmac, Cipheriv, Decipheriv, createHmac, createCipheriv, createDecipheriv, };
|
|
30
|
+
import { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt, } from "./rsa.js";
|
|
31
|
+
export { publicEncrypt, privateEncrypt, publicDecrypt, privateDecrypt };
|
|
32
|
+
export const webcrypto = globalThis.crypto;
|
|
33
|
+
export const subtle = webcrypto.subtle;
|
|
34
|
+
export const getRandomValues = webcrypto.getRandomValues.bind(webcrypto);
|
|
35
|
+
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
|
+
export default {
|
|
46
|
+
X509Certificate,
|
|
47
|
+
Certificate,
|
|
48
|
+
...original,
|
|
49
|
+
...metadata,
|
|
50
|
+
...asymmetric,
|
|
51
|
+
...signatures,
|
|
52
|
+
...prime,
|
|
53
|
+
publicEncrypt,
|
|
54
|
+
privateEncrypt,
|
|
55
|
+
publicDecrypt,
|
|
56
|
+
privateDecrypt,
|
|
57
|
+
ECDH,
|
|
58
|
+
createECDH,
|
|
59
|
+
KeyObject: keys.KeyObject,
|
|
60
|
+
SecretKeyObject: keys.SecretKeyObject,
|
|
61
|
+
PublicKeyObject: keys.PublicKeyObject,
|
|
62
|
+
PrivateKeyObject: keys.PrivateKeyObject,
|
|
63
|
+
createSecretKey: keys.createSecretKey,
|
|
64
|
+
generateKey: keys.generateKey,
|
|
65
|
+
generateKeySync: keys.generateKeySync,
|
|
66
|
+
Hmac,
|
|
67
|
+
createHmac,
|
|
68
|
+
Cipheriv,
|
|
69
|
+
createCipheriv,
|
|
70
|
+
Decipheriv,
|
|
71
|
+
createDecipheriv,
|
|
72
|
+
hkdf,
|
|
73
|
+
hkdfSync,
|
|
74
|
+
webcrypto,
|
|
75
|
+
subtle,
|
|
76
|
+
getRandomValues,
|
|
77
|
+
CryptoKey,
|
|
78
|
+
randomInt,
|
|
79
|
+
randomUUID,
|
|
80
|
+
hash,
|
|
81
|
+
scrypt,
|
|
82
|
+
scryptSync,
|
|
83
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { NativeKey } from "./native-crypto.js";
|
|
3
|
+
export declare function der(tag: number, ...parts: Uint8Array[]): Buffer;
|
|
4
|
+
export declare function integer(bytes: Uint8Array): Buffer;
|
|
5
|
+
export declare function importJwk(jwk: any, privateKey: boolean): NativeKey;
|
|
6
|
+
export declare function exportJwk(key: NativeKey, privateKey: boolean): any;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { NativeKey } from "./native-crypto.js";
|
|
3
|
+
// DER encodings follow RFC 5208/5915/8410; JWK members follow RFC 7518/8037.
|
|
4
|
+
const curves = {
|
|
5
|
+
"P-256": { oid: "2a8648ce3d030107", size: 32, native: "prime256v1" },
|
|
6
|
+
"P-384": { oid: "2b81040022", size: 48, native: "secp384r1" },
|
|
7
|
+
"P-521": { oid: "2b81040023", size: 66, native: "secp521r1" },
|
|
8
|
+
secp256k1: { oid: "2b8104000a", size: 32, native: "secp256k1" },
|
|
9
|
+
};
|
|
10
|
+
export function der(tag, ...parts) {
|
|
11
|
+
const data = Buffer.concat(parts);
|
|
12
|
+
let length = [];
|
|
13
|
+
if (data.length < 128)
|
|
14
|
+
length = [data.length];
|
|
15
|
+
else {
|
|
16
|
+
let size = data.length;
|
|
17
|
+
while (size) {
|
|
18
|
+
length.unshift(size & 255);
|
|
19
|
+
size = Math.floor(size / 256);
|
|
20
|
+
}
|
|
21
|
+
length.unshift(128 + length.length);
|
|
22
|
+
}
|
|
23
|
+
return Buffer.concat([Buffer.from([tag, ...length]), data]);
|
|
24
|
+
}
|
|
25
|
+
export function integer(bytes) {
|
|
26
|
+
let offset = 0;
|
|
27
|
+
while (offset < bytes.length - 1 && bytes[offset] === 0)
|
|
28
|
+
offset++;
|
|
29
|
+
const data = bytes.subarray(offset);
|
|
30
|
+
return der(2, ...(data[0] & 128 ? [Buffer.from([0]), data] : [data]));
|
|
31
|
+
}
|
|
32
|
+
function field(jwk, name, size) {
|
|
33
|
+
if (typeof jwk[name] !== "string")
|
|
34
|
+
throw new TypeError(`Missing JWK member: ${name}`);
|
|
35
|
+
const bytes = Buffer.from(jwk[name], "base64url");
|
|
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;
|
|
41
|
+
}
|
|
42
|
+
export function importJwk(jwk, privateKey) {
|
|
43
|
+
if (jwk?.kty === "RSA") {
|
|
44
|
+
const names = privateKey
|
|
45
|
+
? ["n", "e", "d", "p", "q", "dp", "dq", "qi"]
|
|
46
|
+
: ["n", "e"];
|
|
47
|
+
return NativeKey.parse(der(48, ...(privateKey ? [integer(Buffer.from([0]))] : []), ...names.map((name) => integer(field(jwk, name)))), false, privateKey);
|
|
48
|
+
}
|
|
49
|
+
if (jwk?.kty === "EC") {
|
|
50
|
+
const curve = curves[jwk.crv];
|
|
51
|
+
if (!curve)
|
|
52
|
+
throw new TypeError("Unsupported JWK curve");
|
|
53
|
+
const oid = der(6, Buffer.from(curve.oid, "hex"));
|
|
54
|
+
const point = Buffer.concat([
|
|
55
|
+
Buffer.from([4]),
|
|
56
|
+
field(jwk, "x", curve.size),
|
|
57
|
+
field(jwk, "y", curve.size),
|
|
58
|
+
]);
|
|
59
|
+
const bits = der(3, Buffer.from([0]), point);
|
|
60
|
+
const data = privateKey
|
|
61
|
+
? der(48, integer(Buffer.from([1])), der(4, field(jwk, "d", curve.size)), der(160, oid), der(161, bits))
|
|
62
|
+
: der(48, der(48, der(6, Buffer.from("2a8648ce3d0201", "hex")), oid), bits);
|
|
63
|
+
return NativeKey.parse(data, false, privateKey);
|
|
64
|
+
}
|
|
65
|
+
if (jwk?.kty === "OKP" && ["Ed25519", "X25519"].includes(jwk.crv)) {
|
|
66
|
+
const algorithm = der(48, der(6, Buffer.from([43, 101, jwk.crv === "Ed25519" ? 112 : 110])));
|
|
67
|
+
const data = privateKey
|
|
68
|
+
? der(48, integer(Buffer.from([0])), algorithm, der(4, der(4, field(jwk, "d", 32))))
|
|
69
|
+
: der(48, algorithm, der(3, Buffer.from([0]), field(jwk, "x", 32)));
|
|
70
|
+
return NativeKey.parse(data, false, privateKey);
|
|
71
|
+
}
|
|
72
|
+
throw new TypeError("Unsupported JWK key type");
|
|
73
|
+
}
|
|
74
|
+
function encode(bytes, size) {
|
|
75
|
+
if (size !== undefined && bytes.length < size)
|
|
76
|
+
bytes = Buffer.concat([Buffer.alloc(size - bytes.length), bytes]);
|
|
77
|
+
return Buffer.from(bytes).toString("base64url");
|
|
78
|
+
}
|
|
79
|
+
export function exportJwk(key, privateKey) {
|
|
80
|
+
if (key.type === "rsa") {
|
|
81
|
+
const result = {
|
|
82
|
+
kty: "RSA",
|
|
83
|
+
n: encode(key.parameter("n")),
|
|
84
|
+
e: encode(key.parameter("e")),
|
|
85
|
+
};
|
|
86
|
+
if (privateKey)
|
|
87
|
+
for (const [name, param] of [
|
|
88
|
+
["d", "d"],
|
|
89
|
+
["p", "rsa-factor1"],
|
|
90
|
+
["q", "rsa-factor2"],
|
|
91
|
+
["dp", "rsa-exponent1"],
|
|
92
|
+
["dq", "rsa-exponent2"],
|
|
93
|
+
["qi", "rsa-coefficient1"],
|
|
94
|
+
])
|
|
95
|
+
result[name] = encode(key.parameter(param));
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
if (key.type === "ec") {
|
|
99
|
+
const found = Object.entries(curves).find(([, value]) => value.native === key.group);
|
|
100
|
+
if (!found)
|
|
101
|
+
throw new TypeError("Unsupported JWK curve");
|
|
102
|
+
const [crv, curve] = found;
|
|
103
|
+
return {
|
|
104
|
+
kty: "EC",
|
|
105
|
+
crv,
|
|
106
|
+
x: encode(key.parameter("qx"), curve.size),
|
|
107
|
+
y: encode(key.parameter("qy"), curve.size),
|
|
108
|
+
...(privateKey ? { d: encode(key.parameter("priv"), curve.size) } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (["ed25519", "x25519"].includes(key.type))
|
|
112
|
+
return {
|
|
113
|
+
kty: "OKP",
|
|
114
|
+
...(key.type === "ed25519" ? { alg: "EdDSA" } : {}),
|
|
115
|
+
crv: key.type === "ed25519" ? "Ed25519" : "X25519",
|
|
116
|
+
x: encode(key.raw(false)),
|
|
117
|
+
...(privateKey ? { d: encode(key.raw(true)) } : {}),
|
|
118
|
+
};
|
|
119
|
+
throw new TypeError("Unsupported JWK key type");
|
|
120
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NativeKey } from "./native-crypto.js";
|
|
2
|
+
export interface KeyState {
|
|
3
|
+
type: "secret" | "private" | "public";
|
|
4
|
+
bytes?: Uint8Array;
|
|
5
|
+
asymmetric?: NativeKey;
|
|
6
|
+
native?: CryptoKey;
|
|
7
|
+
}
|
|
8
|
+
export declare const keyStates: WeakMap<object, KeyState>;
|
|
9
|
+
export declare function isKeyObject(value: unknown): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type KeyState } from "./key-state.js";
|
|
2
|
+
export declare function create(type: KeyState["type"], value: Omit<KeyState, "type">): KeyObject;
|
|
3
|
+
export declare abstract class KeyObject {
|
|
4
|
+
constructor();
|
|
5
|
+
static from(key: CryptoKey): KeyObject;
|
|
6
|
+
abstract get type(): KeyState["type"];
|
|
7
|
+
get [Symbol.toStringTag](): string;
|
|
8
|
+
export(options?: any): any;
|
|
9
|
+
equals(other: KeyObject): boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class SecretKeyObject extends KeyObject {
|
|
12
|
+
get type(): "secret";
|
|
13
|
+
export(options?: any): any;
|
|
14
|
+
get symmetricKeySize(): number;
|
|
15
|
+
}
|
|
16
|
+
declare abstract class AsymmetricKeyObject extends KeyObject {
|
|
17
|
+
get asymmetricKeyType(): string;
|
|
18
|
+
get asymmetricKeyDetails(): {
|
|
19
|
+
modulusLength: number;
|
|
20
|
+
publicExponent: bigint;
|
|
21
|
+
namedCurve?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
modulusLength?: undefined;
|
|
24
|
+
publicExponent?: undefined;
|
|
25
|
+
namedCurve: string;
|
|
26
|
+
} | {
|
|
27
|
+
modulusLength?: undefined;
|
|
28
|
+
publicExponent?: undefined;
|
|
29
|
+
namedCurve?: undefined;
|
|
30
|
+
};
|
|
31
|
+
toCryptoKey(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare class PublicKeyObject extends AsymmetricKeyObject {
|
|
34
|
+
get type(): "public";
|
|
35
|
+
export(options?: any): any;
|
|
36
|
+
}
|
|
37
|
+
export declare class PrivateKeyObject extends AsymmetricKeyObject {
|
|
38
|
+
get type(): "private";
|
|
39
|
+
export(options?: any): any;
|
|
40
|
+
}
|
|
41
|
+
export declare function createSecretKey(value: unknown, encoding?: BufferEncoding): SecretKeyObject;
|
|
42
|
+
export declare function secretMaterial(value: unknown): any;
|
|
43
|
+
export declare function generateKeySync(type: string, options: {
|
|
44
|
+
length: number;
|
|
45
|
+
}): SecretKeyObject;
|
|
46
|
+
export declare function generateKey(type: string, options: {
|
|
47
|
+
length: number;
|
|
48
|
+
}, callback: (error: unknown, key?: SecretKeyObject) => void): void;
|
|
49
|
+
export { isKeyObject } from "./key-state.js";
|
|
50
|
+
export declare function getKeyObjectHandle(key: KeyObject): KeyObject;
|