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.
Files changed (197) hide show
  1. package/README.md +2 -2
  2. package/dist/browser/documents/page-source.js +1 -1
  3. package/dist/browser/headers/index.d.ts +2 -0
  4. package/dist/browser/headers/index.js +5 -0
  5. package/dist/browser/response/index.d.ts +2 -0
  6. package/dist/browser/response/index.js +11 -3
  7. package/dist/browser/structured-clone/index.d.ts +3 -0
  8. package/dist/browser/structured-clone/index.js +75 -7
  9. package/dist/browser/websocket/attachment-size.d.ts +3 -0
  10. package/dist/browser/websocket/attachment-size.js +336 -0
  11. package/dist/browser/websocket/brand.d.ts +4 -0
  12. package/dist/browser/websocket/brand.js +16 -0
  13. package/dist/browser/websocket/close-event.d.ts +7 -0
  14. package/dist/browser/websocket/close-event.js +30 -0
  15. package/dist/browser/websocket/compression.d.ts +5 -0
  16. package/dist/browser/websocket/compression.js +124 -0
  17. package/dist/browser/websocket/conversion.d.ts +2 -0
  18. package/dist/browser/websocket/conversion.js +13 -0
  19. package/dist/browser/websocket/endpoint.d.ts +39 -0
  20. package/dist/browser/websocket/endpoint.js +379 -0
  21. package/dist/browser/websocket/frames.d.ts +21 -0
  22. package/dist/browser/websocket/frames.js +121 -0
  23. package/dist/browser/websocket/native.d.ts +14 -0
  24. package/dist/browser/websocket/native.js +226 -0
  25. package/dist/cloudflare/apis/cloudflare-node/index.js +11 -23
  26. package/dist/compat/crypto/LICENSE-3RD-PARTY.md +20 -0
  27. package/dist/compat/crypto/LICENSE.boringssl +238 -0
  28. package/dist/compat/crypto/LICENSE.ncrypto +21 -0
  29. package/dist/compat/crypto/asymmetric.js +141 -68
  30. package/dist/compat/crypto/cipher-handle.d.ts +27 -0
  31. package/dist/compat/crypto/cipher-handle.js +239 -0
  32. package/dist/compat/crypto/cipher-info.d.ts +12 -0
  33. package/dist/compat/crypto/cipher-info.js +324 -0
  34. package/dist/compat/crypto/constants.d.ts +62 -0
  35. package/dist/compat/crypto/constants.js +68 -0
  36. package/dist/compat/crypto/dh-handle.d.ts +17 -0
  37. package/dist/compat/crypto/dh-handle.js +180 -0
  38. package/dist/compat/crypto/dh.d.ts +53 -0
  39. package/dist/compat/crypto/dh.js +138 -0
  40. package/dist/compat/crypto/digest-stream.d.ts +15 -0
  41. package/dist/compat/crypto/digest-stream.js +213 -0
  42. package/dist/compat/crypto/digests.d.ts +3 -0
  43. package/dist/compat/crypto/digests.js +32 -0
  44. package/dist/compat/crypto/ecdh.d.ts +16 -6
  45. package/dist/compat/crypto/hash-handle.d.ts +23 -0
  46. package/dist/compat/crypto/hash-handle.js +70 -0
  47. package/dist/compat/crypto/hash.d.ts +37 -0
  48. package/dist/compat/crypto/hash.js +218 -0
  49. package/dist/compat/crypto/hkdf.js +40 -14
  50. package/dist/compat/crypto/index.d.cts +168 -1
  51. package/dist/compat/crypto/index.d.ts +191 -8
  52. package/dist/compat/crypto/index.js +36 -23
  53. package/dist/compat/crypto/key-errors.d.ts +10 -0
  54. package/dist/compat/crypto/key-errors.js +17 -0
  55. package/dist/compat/crypto/key-export.d.ts +8 -0
  56. package/dist/compat/crypto/key-export.js +49 -0
  57. package/dist/compat/crypto/key-formats.d.ts +2 -1
  58. package/dist/compat/crypto/key-formats.js +162 -31
  59. package/dist/compat/crypto/key-options.d.ts +1 -0
  60. package/dist/compat/crypto/key-options.js +74 -0
  61. package/dist/compat/crypto/key-state.d.ts +1 -0
  62. package/dist/compat/crypto/keys.d.ts +20 -12
  63. package/dist/compat/crypto/keys.js +125 -56
  64. package/dist/compat/crypto/metadata.d.ts +9 -0
  65. package/dist/compat/crypto/metadata.js +89 -2
  66. package/dist/compat/crypto/native-cipher.d.ts +17 -0
  67. package/dist/compat/crypto/native-cipher.js +192 -0
  68. package/dist/compat/crypto/native-crypto.d.ts +14 -1
  69. package/dist/compat/crypto/native-crypto.js +118 -6
  70. package/dist/compat/crypto/pbkdf2-handle.d.ts +4 -0
  71. package/dist/compat/crypto/pbkdf2-handle.js +26 -0
  72. package/dist/compat/crypto/pbkdf2.d.ts +5 -0
  73. package/dist/compat/crypto/pbkdf2.js +60 -0
  74. package/dist/compat/crypto/prime.js +4 -4
  75. package/dist/compat/crypto/random.d.ts +11 -0
  76. package/dist/compat/crypto/random.js +86 -6
  77. package/dist/compat/crypto/rsa.d.ts +17 -1
  78. package/dist/compat/crypto/rsa.js +8 -4
  79. package/dist/compat/crypto/scrypt.d.ts +3 -3
  80. package/dist/compat/crypto/scrypt.js +25 -23
  81. package/dist/compat/crypto/sign-handle.d.ts +3 -3
  82. package/dist/compat/crypto/sign-handle.js +55 -11
  83. package/dist/compat/crypto/signatures.d.ts +17 -11
  84. package/dist/compat/crypto/subtle-digest.d.ts +1 -0
  85. package/dist/compat/crypto/subtle-digest.js +56 -0
  86. package/dist/compat/crypto/symmetric.d.ts +40 -24
  87. package/dist/compat/crypto/symmetric.js +229 -94
  88. package/dist/compat/crypto/validation.d.ts +4 -0
  89. package/dist/compat/crypto/validation.js +29 -2
  90. package/dist/compat/crypto/webcrypto.d.ts +13 -0
  91. package/dist/compat/crypto/webcrypto.js +51 -0
  92. package/dist/compat/crypto/x509.js +2 -1
  93. package/dist/compat/events/index.js +1 -1
  94. package/dist/compat/fs/LICENSE-3RD-PARTY.md +11 -0
  95. package/dist/compat/fs/LICENSE-APACHE +177 -0
  96. package/dist/compat/fs/directory-backend.d.ts +6 -0
  97. package/dist/compat/fs/directory-backend.js +51 -0
  98. package/dist/compat/fs/directory.d.ts +37 -0
  99. package/dist/compat/fs/directory.js +137 -0
  100. package/dist/compat/fs/embedded.d.ts +1 -1
  101. package/dist/compat/fs/embedded.js +7 -2
  102. package/dist/compat/fs/file-handle.d.ts +75 -0
  103. package/dist/compat/fs/file-handle.js +226 -0
  104. package/dist/compat/fs/glob-internal.d.ts +15 -0
  105. package/dist/compat/fs/glob-internal.js +417 -0
  106. package/dist/compat/fs/glob.d.ts +10 -0
  107. package/dist/compat/fs/glob.js +71 -0
  108. package/dist/compat/fs/index.d.ts +6 -3
  109. package/dist/compat/fs/index.js +582 -50
  110. package/dist/compat/fs/io-validation.d.ts +14 -0
  111. package/dist/compat/fs/io-validation.js +130 -0
  112. package/dist/compat/fs/io.d.ts +1 -0
  113. package/dist/compat/fs/io.js +282 -0
  114. package/dist/compat/fs/promises/index.d.ts +3 -1
  115. package/dist/compat/fs/public-types.d.ts +120 -0
  116. package/dist/compat/fs/public-types.js +1 -0
  117. package/dist/compat/fs/stream-errors.d.ts +6 -0
  118. package/dist/compat/fs/stream-errors.js +8 -0
  119. package/dist/compat/fs/stream-utils.d.ts +16 -0
  120. package/dist/compat/fs/stream-utils.js +29 -0
  121. package/dist/compat/fs/streams.d.ts +104 -0
  122. package/dist/compat/fs/streams.js +794 -0
  123. package/dist/compat/fs/writable.d.ts +8 -0
  124. package/dist/compat/fs/writable.js +412 -22
  125. package/dist/compat/http/index.d.ts +11 -28
  126. package/dist/compat/http/index.js +81 -125
  127. package/dist/compat/http/server-options.d.ts +1 -0
  128. package/dist/compat/http/server-options.js +87 -0
  129. package/dist/compat/http/unique-headers.d.ts +1 -0
  130. package/dist/compat/http/unique-headers.js +21 -0
  131. package/dist/compat/http-outgoing/index.d.ts +2 -1
  132. package/dist/compat/http-outgoing/index.js +2 -17
  133. package/dist/compat/http-server/index.d.ts +2 -2
  134. package/dist/compat/http-server/index.js +4 -85
  135. package/dist/compat/https/index.d.ts +4 -2
  136. package/dist/compat/net/sockets.js +98 -20
  137. package/dist/compat/net/validators.d.ts +1 -0
  138. package/dist/compat/net/validators.js +8 -0
  139. package/dist/compat/process/configuration.d.ts +113 -0
  140. package/dist/compat/process/configuration.js +115 -0
  141. package/dist/compat/process/directory.d.ts +4 -0
  142. package/dist/compat/process/directory.js +28 -0
  143. package/dist/compat/process/files.d.ts +3 -0
  144. package/dist/compat/process/files.js +10 -0
  145. package/dist/compat/process/index.d.ts +15 -13
  146. package/dist/compat/process/index.js +47 -74
  147. package/dist/compat/process/scheduling.d.ts +2 -0
  148. package/dist/compat/process/scheduling.js +60 -0
  149. package/dist/compat/process/state.js +1 -0
  150. package/dist/compat/process/stdio.d.ts +18 -0
  151. package/dist/compat/process/stdio.js +66 -0
  152. package/dist/compat/stream/destroy.d.ts +1 -0
  153. package/dist/compat/stream/destroy.js +21 -1
  154. package/dist/compat/stream/readable.js +10 -2
  155. package/dist/compat/tls/jsstream.js +16 -6
  156. package/dist/compat/tls/wrap.d.ts +1 -1
  157. package/dist/compat/tls/wrap.js +0 -3
  158. package/dist/compat/util/inspect.js +5 -1
  159. package/dist/compat/zlib/LICENSE-3RD-PARTY.md +11 -0
  160. package/dist/compat/zlib/LICENSE-APACHE +177 -0
  161. package/dist/compat/zlib/LICENSE.zlib +22 -0
  162. package/dist/compat/zlib/classic-base.cjs +600 -0
  163. package/dist/compat/zlib/classic-base.d.cts +39 -0
  164. package/dist/compat/zlib/classic-binding.d.ts +28 -0
  165. package/dist/compat/zlib/classic-binding.js +105 -0
  166. package/dist/compat/zlib/classic.d.ts +44 -0
  167. package/dist/compat/zlib/classic.js +199 -0
  168. package/dist/compat/zlib/codec-binding.d.ts +33 -0
  169. package/dist/compat/zlib/codec-binding.js +141 -0
  170. package/dist/compat/zlib/compression.d.ts +22 -51
  171. package/dist/compat/zlib/compression.js +129 -218
  172. package/dist/compat/zlib/errors.d.ts +21 -0
  173. package/dist/compat/zlib/errors.js +32 -0
  174. package/dist/compat/zlib/index.d.ts +367 -3
  175. package/dist/compat/zlib/index.js +28 -11
  176. package/dist/compat/zlib/input.d.ts +16 -0
  177. package/dist/compat/zlib/input.js +132 -0
  178. package/dist/compat/zlib/native-codecs.d.ts +7 -0
  179. package/dist/compat/zlib/native-codecs.js +22 -10
  180. package/dist/compat/zlib/native-zlib.d.ts +5 -0
  181. package/dist/compat/zlib/native-zlib.js +52 -0
  182. package/dist/compat/zlib/public-types.d.ts +48 -0
  183. package/dist/compat/zlib/public-types.js +1 -0
  184. package/dist/compat/zlib/validators.d.ts +3 -0
  185. package/dist/compat/zlib/validators.js +18 -0
  186. package/dist/shared/buffer-source.d.ts +5 -0
  187. package/dist/shared/buffer-source.js +70 -0
  188. package/dist/shared/globals/platform.d.ts +8 -0
  189. package/dist/shared/globals/platform.js +1 -0
  190. package/dist/shared/globals/web.js +5 -0
  191. package/dist/shared/request-context.d.ts +2 -0
  192. package/dist/shared/request-context.js +11 -0
  193. package/dist/shared/request-scope.js +4 -1
  194. package/dist/tooling/shared.js +6 -0
  195. package/dist/tooling/vite.js +4 -0
  196. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +38 -7
  197. package/package.json +2 -2
@@ -1,29 +1,45 @@
1
- declare const BaseTransform: typeof import("node:stream").Transform;
2
- export declare class Hmac extends BaseTransform {
3
- constructor(algorithm: string, key: unknown, options?: any);
4
- update(data: unknown, encoding?: string): this;
5
- digest(encoding?: string): any;
6
- _transform(chunk: any, encoding: any, callback: any): void;
7
- _flush(callback: any): void;
1
+ import { type CipherHandle } from "./cipher-handle.js";
2
+ import type { Transform as NodeTransform, TransformOptions } from "node:stream";
3
+ import { KeyObject } from "./keys.js";
4
+ import { Buffer } from "node:buffer";
5
+ export interface AADOptions {
6
+ plaintextLength?: number;
7
+ encoding?: string;
8
8
  }
9
- declare class CipherTransform extends BaseTransform {
10
- constructor(decrypt: boolean, algorithm: string, key: unknown, iv: unknown, options?: any);
11
- update(data: unknown, inputEncoding?: string, outputEncoding?: string): any;
12
- final(encoding?: string): any;
13
- setAutoPadding(value?: boolean): this;
14
- setAAD(data: unknown, options?: any): this;
15
- getAuthTag(): any;
16
- setAuthTag(data: unknown): this;
17
- _transform(chunk: any, encoding: any, callback: any): void;
18
- _flush(callback: any): void;
9
+ declare const kHandle: unique symbol;
10
+ export interface Cipheriv extends NodeTransform {
11
+ [kHandle]: CipherHandle;
12
+ update(data: string | ArrayBuffer | ArrayBufferView, inputEncoding?: string): Buffer;
13
+ update(data: string | ArrayBuffer | ArrayBufferView, inputEncoding: string | undefined, outputEncoding: string): string;
14
+ update(data: string | ArrayBuffer | ArrayBufferView, inputEncoding?: string, outputEncoding?: string): string | Buffer;
15
+ final(): Buffer;
16
+ final(outputEncoding: string): string;
17
+ final(outputEncoding?: string): string | Buffer;
18
+ setAAD(buffer: string | ArrayBuffer | ArrayBufferView, options?: AADOptions): this;
19
+ setAutoPadding(autoPadding?: boolean): this;
20
+ getAuthTag(): Buffer;
19
21
  }
20
- export declare class Cipheriv extends CipherTransform {
21
- constructor(algorithm: string, key: unknown, iv: unknown, options?: any);
22
+ export interface Decipheriv extends NodeTransform {
23
+ [kHandle]: CipherHandle;
24
+ update(data: string | ArrayBuffer | ArrayBufferView, inputEncoding?: string): Buffer;
25
+ update(data: string | ArrayBuffer | ArrayBufferView, inputEncoding: string | undefined, outputEncoding: string): string;
26
+ update(data: string | ArrayBuffer | ArrayBufferView, inputEncoding?: string, outputEncoding?: string): string | Buffer;
27
+ final(): Buffer;
28
+ final(outputEncoding: string): string;
29
+ final(outputEncoding?: string): string | Buffer;
30
+ setAAD(buffer: string | ArrayBuffer | ArrayBufferView, options?: AADOptions): this;
31
+ setAutoPadding(autoPadding?: boolean): this;
32
+ setAuthTag(buffer: ArrayBuffer | ArrayBufferView): this;
22
33
  }
23
- export declare class Decipheriv extends CipherTransform {
24
- constructor(algorithm: string, key: unknown, iv: unknown, options?: any);
34
+ export interface CipherOptions extends TransformOptions {
35
+ authLengthTag?: number;
25
36
  }
26
- export declare function createHmac(algorithm: string, key: unknown, options?: any): Hmac;
27
- export declare function createCipheriv(algorithm: string, key: unknown, iv: unknown, options?: any): Cipheriv;
28
- export declare function createDecipheriv(algorithm: string, key: unknown, iv: unknown, options?: any): Decipheriv;
37
+ export declare const Cipheriv: {
38
+ new (algorithm: string, key: string | ArrayBuffer | ArrayBufferView | KeyObject | CryptoKey, iv: string | ArrayBuffer | ArrayBufferView | null, options?: CipherOptions): Cipheriv;
39
+ };
40
+ export declare const Decipheriv: {
41
+ new (algorithm: string, key: string | ArrayBuffer | ArrayBufferView | KeyObject | CryptoKey, iv: string | ArrayBuffer | ArrayBufferView | null, options?: CipherOptions): Decipheriv;
42
+ };
43
+ export declare function createCipheriv(algorithm: string, key: string | ArrayBuffer | ArrayBufferView | KeyObject | CryptoKey, iv: string | ArrayBuffer | ArrayBufferView | null, options?: CipherOptions): Cipheriv;
44
+ export declare function createDecipheriv(algorithm: string, key: string | ArrayBuffer | ArrayBufferView | KeyObject | CryptoKey, iv: string | ArrayBuffer | ArrayBufferView | null, options?: CipherOptions): Decipheriv;
29
45
  export {};
@@ -1,104 +1,239 @@
1
- import { Buffer } from "node:buffer";
1
+ // @ts-nocheck
2
+ // Copyright (c) 2017-2023 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 cryptoImpl from "./cipher-handle.js";
2
27
  import { Transform } from "../stream/transform.js";
3
- // @ts-expect-error dependency has no declarations
4
- import original from "crypto-browserify/index.js";
5
- import { secretMaterial } from "./keys.js";
6
- const BaseTransform = Transform;
7
- const handles = new WeakMap();
8
- export class Hmac extends BaseTransform {
9
- constructor(algorithm, key, options) {
10
- super(options);
11
- handles.set(this, original.createHmac(algorithm, typeof key === "string"
12
- ? Buffer.from(key, options?.encoding)
13
- : secretMaterial(key)));
14
- }
15
- update(data, encoding) {
16
- handles.get(this).update(data, encoding);
17
- return this;
18
- }
19
- digest(encoding) {
20
- return handles.get(this).digest(encoding);
21
- }
22
- _transform(chunk, encoding, callback) {
23
- try {
24
- this.update(chunk, encoding);
25
- callback();
26
- }
27
- catch (error) {
28
- callback(error);
29
- }
30
- }
31
- _flush(callback) {
32
- try {
33
- this.push(this.digest());
34
- callback();
35
- }
36
- catch (error) {
37
- callback(error);
38
- }
39
- }
28
+ import { KeyObject, createSecretKey } from "./keys.js";
29
+ import { validateObject, validateString, validateUint32, } from "../net/validators.js";
30
+ import { ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE } from "../net/errors.js";
31
+ import { ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE } from "./sign-errors.js";
32
+ import { isAnyBuffer as isAnyArrayBuffer } from "./validation.js";
33
+ import { Buffer } from "node:buffer";
34
+ const isArrayBufferView = ArrayBuffer.isView;
35
+ const kHandle = Symbol("kHandle");
36
+ const CipherMode = {
37
+ CIPHER: 0,
38
+ DECIPHER: 1,
39
+ };
40
+ function getSecretKey(key) {
41
+ if (typeof CryptoKey !== "undefined" && key instanceof CryptoKey)
42
+ key = KeyObject.from(key);
43
+ if (key instanceof KeyObject) {
44
+ if (key.type !== "secret")
45
+ throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(key.type, "secret");
46
+ return key;
47
+ }
48
+ if (isAnyArrayBuffer(key) || isArrayBufferView(key))
49
+ return createSecretKey(key);
50
+ if (typeof key === "string")
51
+ return createSecretKey(key, "utf8");
52
+ throw new ERR_INVALID_ARG_TYPE("key", ["string", "Buffer", "TypedArray", "DataView", "KeyObject", "CryptoKey"], key);
40
53
  }
41
- class CipherTransform extends BaseTransform {
42
- constructor(decrypt, algorithm, key, iv, options) {
43
- super(options);
44
- handles.set(this, (decrypt ? original.createDecipheriv : original.createCipheriv)(algorithm, secretMaterial(key), iv, options));
45
- }
46
- update(data, inputEncoding, outputEncoding) {
47
- return handles.get(this).update(data, inputEncoding, outputEncoding);
48
- }
49
- final(encoding) {
50
- return handles.get(this).final(encoding);
51
- }
52
- setAutoPadding(value) {
53
- handles.get(this).setAutoPadding(value);
54
- return this;
55
- }
56
- setAAD(data, options) {
57
- handles.get(this).setAAD(data, options);
58
- return this;
54
+ function getIv(iv) {
55
+ if (isAnyArrayBuffer(iv) || isArrayBufferView(iv)) {
56
+ return iv;
59
57
  }
60
- getAuthTag() {
61
- return handles.get(this).getAuthTag();
58
+ else if (typeof iv === "string") {
59
+ return Buffer.from(iv, "utf8");
62
60
  }
63
- setAuthTag(data) {
64
- handles.get(this).setAuthTag(data);
65
- return this;
66
- }
67
- _transform(chunk, encoding, callback) {
68
- try {
69
- this.push(this.update(chunk, encoding));
70
- callback();
71
- }
72
- catch (error) {
73
- callback(error);
74
- }
75
- }
76
- _flush(callback) {
77
- try {
78
- this.push(this.final());
79
- callback();
61
+ throw new ERR_INVALID_ARG_TYPE("iv", ["string", "Buffer", "TypedArray", "DataView", "null"], iv);
62
+ }
63
+ export const Cipheriv = function (algorithm, key, iv, options = {}) {
64
+ validateString(algorithm, "algorithm");
65
+ const secretKey = getSecretKey(key);
66
+ const ivBuf = getIv(iv);
67
+ if (options.authLengthTag !== undefined) {
68
+ validateUint32(options.authLengthTag, "options.authLengthTag");
69
+ }
70
+ this[kHandle] = cryptoImpl.newHandle(CipherMode.CIPHER, algorithm, secretKey, ivBuf, options.authLengthTag);
71
+ Transform.call(this, options);
72
+ };
73
+ Object.setPrototypeOf(Cipheriv.prototype, Transform.prototype);
74
+ Object.setPrototypeOf(Cipheriv, Transform);
75
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
76
+ Cipheriv.prototype.update = function (data, inputEncoding, outputEncoding) {
77
+ let ret;
78
+ if (typeof data === "string") {
79
+ if (inputEncoding === undefined) {
80
+ throw new ERR_INVALID_ARG_VALUE("inputEncoding", inputEncoding, "If inputEncoding is not provided then the data must be a Buffer");
80
81
  }
81
- catch (error) {
82
- callback(error);
82
+ ret = this[kHandle].update(Buffer.from(data, inputEncoding));
83
+ }
84
+ else if (isAnyArrayBuffer(data)) {
85
+ ret = this[kHandle].update(data);
86
+ }
87
+ else if (isArrayBufferView(data)) {
88
+ ret = this[kHandle].update(data);
89
+ }
90
+ else {
91
+ throw new ERR_INVALID_ARG_TYPE("data", ["string", "Buffer", "TypedArray", "DataView"], data);
92
+ }
93
+ if (outputEncoding === undefined) {
94
+ return Buffer.from(ret);
95
+ }
96
+ return Buffer.from(ret).toString(outputEncoding);
97
+ };
98
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
99
+ Cipheriv.prototype.final = function (outputEncoding) {
100
+ const ret = this[kHandle].final();
101
+ if (outputEncoding === undefined) {
102
+ return Buffer.from(ret);
103
+ }
104
+ return Buffer.from(ret).toString(outputEncoding);
105
+ };
106
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
107
+ Cipheriv.prototype.setAAD = function (buffer, options = {}) {
108
+ validateObject(options, "options");
109
+ const { plaintextLength, encoding } = options;
110
+ if (plaintextLength !== undefined) {
111
+ validateUint32(plaintextLength, "options.plaintextLength");
112
+ }
113
+ if (encoding !== undefined) {
114
+ validateString(encoding, "options.encoding");
115
+ }
116
+ if (typeof buffer === "string") {
117
+ this[kHandle].setAAD(Buffer.from(buffer, encoding), plaintextLength);
118
+ }
119
+ else if (isAnyArrayBuffer(buffer) || isArrayBufferView(buffer)) {
120
+ this[kHandle].setAAD(buffer, plaintextLength);
121
+ }
122
+ return this;
123
+ };
124
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
125
+ Cipheriv.prototype.setAutoPadding = function (autoPadding) {
126
+ this[kHandle].setAutoPadding(autoPadding ? true : false);
127
+ return this;
128
+ };
129
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
130
+ Cipheriv.prototype.getAuthTag = function () {
131
+ const ret = this[kHandle].getAuthTag();
132
+ if (ret === undefined)
133
+ return undefined;
134
+ return Buffer.from(ret);
135
+ };
136
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
137
+ Cipheriv.prototype._transform = function (chunk, encoding, callback) {
138
+ if (typeof chunk === "string") {
139
+ chunk = Buffer.from(chunk, encoding);
140
+ }
141
+ this.push(Buffer.from(this[kHandle].update(chunk)));
142
+ callback();
143
+ };
144
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
145
+ Cipheriv.prototype._flush = function (callback) {
146
+ this.push(Buffer.from(this[kHandle].final()));
147
+ callback();
148
+ };
149
+ export const Decipheriv = function (algorithm, key, iv, options = {}) {
150
+ validateString(algorithm, "algorithm");
151
+ const secretKey = getSecretKey(key);
152
+ const ivBuf = getIv(iv);
153
+ if (options.authLengthTag !== undefined) {
154
+ validateUint32(options.authLengthTag, "options.authLengthTag");
155
+ }
156
+ this[kHandle] = cryptoImpl.newHandle(CipherMode.DECIPHER, algorithm, secretKey, ivBuf, options.authLengthTag);
157
+ Transform.call(this, options);
158
+ return this;
159
+ };
160
+ Object.setPrototypeOf(Decipheriv.prototype, Transform.prototype);
161
+ Object.setPrototypeOf(Decipheriv, Transform);
162
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
163
+ Decipheriv.prototype.update = function (data, inputEncoding, outputEncoding) {
164
+ let ret;
165
+ if (typeof data === "string") {
166
+ if (inputEncoding === undefined) {
167
+ throw new ERR_INVALID_ARG_VALUE("inputEncoding", inputEncoding, "If inputEncoding is not provided then the data must be a Buffer");
83
168
  }
84
- }
85
- }
86
- export class Cipheriv extends CipherTransform {
87
- constructor(algorithm, key, iv, options) {
88
- super(false, algorithm, key, iv, options);
89
- }
90
- }
91
- export class Decipheriv extends CipherTransform {
92
- constructor(algorithm, key, iv, options) {
93
- super(true, algorithm, key, iv, options);
94
- }
95
- }
96
- export function createHmac(algorithm, key, options) {
97
- return new Hmac(algorithm, key, options);
98
- }
99
- export function createCipheriv(algorithm, key, iv, options) {
169
+ ret = this[kHandle].update(Buffer.from(data, inputEncoding));
170
+ }
171
+ else if (isAnyArrayBuffer(data)) {
172
+ ret = this[kHandle].update(data);
173
+ }
174
+ else if (isArrayBufferView(data)) {
175
+ ret = this[kHandle].update(data);
176
+ }
177
+ else {
178
+ throw new ERR_INVALID_ARG_TYPE("data", ["string", "Buffer", "TypedArray", "DataView"], data);
179
+ }
180
+ if (outputEncoding === undefined) {
181
+ return Buffer.from(ret);
182
+ }
183
+ return Buffer.from(ret).toString(outputEncoding);
184
+ };
185
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
186
+ Decipheriv.prototype.final = function (outputEncoding) {
187
+ const ret = this[kHandle].final();
188
+ if (outputEncoding === undefined) {
189
+ return Buffer.from(ret);
190
+ }
191
+ return Buffer.from(ret).toString(outputEncoding);
192
+ };
193
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
194
+ Decipheriv.prototype.setAAD = function (buffer, options = {}) {
195
+ validateObject(options, "options");
196
+ const { plaintextLength, encoding } = options;
197
+ if (plaintextLength !== undefined) {
198
+ validateUint32(plaintextLength, "options.plaintextLength");
199
+ }
200
+ if (encoding !== undefined) {
201
+ validateString(encoding, "options.encoding");
202
+ }
203
+ if (typeof buffer === "string") {
204
+ this[kHandle].setAAD(Buffer.from(buffer, encoding), plaintextLength);
205
+ }
206
+ else if (isAnyArrayBuffer(buffer) || isArrayBufferView(buffer)) {
207
+ this[kHandle].setAAD(buffer, plaintextLength);
208
+ }
209
+ return this;
210
+ };
211
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
212
+ Decipheriv.prototype.setAutoPadding = function (autoPadding) {
213
+ this[kHandle].setAutoPadding(autoPadding ? true : false);
214
+ return this;
215
+ };
216
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
217
+ Decipheriv.prototype.setAuthTag = function (buffer) {
218
+ this[kHandle].setAuthTag(buffer);
219
+ return this;
220
+ };
221
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
222
+ Decipheriv.prototype._transform = function (chunk, encoding, callback) {
223
+ if (typeof chunk === "string") {
224
+ chunk = Buffer.from(chunk, encoding);
225
+ }
226
+ this.push(Buffer.from(this[kHandle].update(chunk)));
227
+ callback();
228
+ };
229
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
230
+ Decipheriv.prototype._flush = function (callback) {
231
+ this.push(Buffer.from(this[kHandle].final()));
232
+ callback();
233
+ };
234
+ export function createCipheriv(algorithm, key, iv, options = {}) {
100
235
  return new Cipheriv(algorithm, key, iv, options);
101
236
  }
102
- export function createDecipheriv(algorithm, key, iv, options) {
237
+ export function createDecipheriv(algorithm, key, iv, options = {}) {
103
238
  return new Decipheriv(algorithm, key, iv, options);
104
239
  }
@@ -1,3 +1,7 @@
1
1
  import { Buffer } from "node:buffer";
2
2
  export declare function validateInteger(value: unknown, name: string, min?: number, max?: number): asserts value is number;
3
3
  export declare function bytes(value: unknown, name: string): Buffer;
4
+ export declare function validateCryptoLength(length: number, message: string): void;
5
+ export { viewBytes, isAnyBuffer } from "../../shared/buffer-source.js";
6
+ export declare function arrayBufferOrView(value: unknown, name: string, expected?: string[]): ArrayBuffer | ArrayBufferView;
7
+ export declare function inputBytes(value: ArrayBuffer | ArrayBufferView, method: string, parameter: number): Uint8Array;
@@ -1,3 +1,4 @@
1
+ import { bufferBytes, viewBytes, isAnyBuffer, } from "../../shared/buffer-source.js";
1
2
  import { Buffer } from "node:buffer";
2
3
  import { ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE } from "../net/errors.js";
3
4
  export function validateInteger(value, name, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
@@ -11,9 +12,35 @@ export function validateInteger(value, name, min = Number.MIN_SAFE_INTEGER, max
11
12
  export function bytes(value, name) {
12
13
  if (typeof value === "string")
13
14
  return Buffer.from(value);
14
- if (value instanceof ArrayBuffer)
15
+ if (isAnyBuffer(value))
15
16
  return Buffer.from(value);
16
17
  if (ArrayBuffer.isView(value))
17
- return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
18
+ return Buffer.from(viewBytes(value));
18
19
  throw new ERR_INVALID_ARG_TYPE(name, ["string", "ArrayBuffer", "Buffer", "TypedArray", "DataView"], value);
19
20
  }
21
+ // Native Workers crypto entry points use signed 32-bit buffer lengths.
22
+ export function validateCryptoLength(length, message) {
23
+ if (length > 0x7fffffff)
24
+ throw new RangeError(message);
25
+ }
26
+ export { viewBytes, isAnyBuffer } from "../../shared/buffer-source.js";
27
+ // Preserve observable frontend properties until the native boundary.
28
+ export function arrayBufferOrView(value, name, expected = ["string", "ArrayBuffer", "Buffer", "TypedArray", "DataView"]) {
29
+ if (typeof value === "string")
30
+ return Buffer.from(value);
31
+ if (isAnyBuffer(value) || ArrayBuffer.isView(value))
32
+ return value;
33
+ throw new ERR_INVALID_ARG_TYPE(name, expected, value);
34
+ }
35
+ const arrayBufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
36
+ export function inputBytes(value, method, parameter) {
37
+ if (ArrayBuffer.isView(value))
38
+ return viewBytes(value);
39
+ try {
40
+ arrayBufferLength.call(value);
41
+ }
42
+ catch {
43
+ throw new TypeError(`Failed to execute '${method}' on 'CryptoImpl': parameter ${parameter} is not of type 'BufferSource'.`);
44
+ }
45
+ return bufferBytes(value);
46
+ }
@@ -0,0 +1,13 @@
1
+ import { DigestStream } from "./digest-stream.js";
2
+ type WorkersSubtleCrypto = SubtleCrypto & {
3
+ timingSafeEqual(left: ArrayBuffer | ArrayBufferView, right: ArrayBuffer | ArrayBufferView): boolean;
4
+ };
5
+ type WorkersCrypto = Crypto & {
6
+ DigestStream: typeof DigestStream;
7
+ subtle: WorkersSubtleCrypto;
8
+ };
9
+ export declare const webcrypto: WorkersCrypto;
10
+ export declare const subtle: SubtleCrypto & {
11
+ timingSafeEqual(left: ArrayBuffer | ArrayBufferView, right: ArrayBuffer | ArrayBufferView): boolean;
12
+ };
13
+ export {};
@@ -0,0 +1,51 @@
1
+ import { installDigest } from "./subtle-digest.js";
2
+ import { installResourceSymbols } from "../../shared/globals/symbols.js";
3
+ import { viewBytes } from "./validation.js";
4
+ import { DigestStream } from "./digest-stream.js";
5
+ import { nativeTimingEqual } from "./native-crypto.js";
6
+ import { Buffer } from "node:buffer";
7
+ installResourceSymbols(globalThis.Symbol);
8
+ export const webcrypto = globalThis.crypto;
9
+ export const subtle = webcrypto.subtle;
10
+ installDigest(subtle);
11
+ function source(value, parameter) {
12
+ if (ArrayBuffer.isView(value))
13
+ return viewBytes(value);
14
+ try {
15
+ Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get.call(value);
16
+ try {
17
+ return Buffer.from(value);
18
+ }
19
+ catch {
20
+ return new Uint8Array(0);
21
+ }
22
+ }
23
+ catch {
24
+ throw new TypeError(`Failed to execute 'timingSafeEqual' on 'SubtleCrypto': parameter ${parameter} is not of type 'BufferSource'.`);
25
+ }
26
+ }
27
+ function timingSafeEqual(left, right) {
28
+ if (this !== subtle)
29
+ throw new TypeError("Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.");
30
+ const a = source(left, 1), b = source(right, 2);
31
+ if (a.byteLength !== b.byteLength)
32
+ throw new TypeError("Input buffers must have the same byte length.");
33
+ return nativeTimingEqual(a, b);
34
+ }
35
+ // Preserve host Crypto/SubtleCrypto identity. Digest uses the Workers registry;
36
+ // other standard operations retain their host implementation.
37
+ // These Workers extensions use the owned digest and comparison backend.
38
+ if (!("DigestStream" in webcrypto))
39
+ Object.defineProperty(Object.getPrototypeOf(webcrypto), "DigestStream", {
40
+ value: DigestStream,
41
+ writable: true,
42
+ enumerable: true,
43
+ configurable: true,
44
+ });
45
+ if (!("timingSafeEqual" in subtle))
46
+ Object.defineProperty(Object.getPrototypeOf(subtle), "timingSafeEqual", {
47
+ value: timingSafeEqual,
48
+ writable: true,
49
+ enumerable: true,
50
+ configurable: true,
51
+ });
@@ -24,6 +24,7 @@
24
24
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
  /* TODO: the following is adopted code, enabling linting one day */
26
26
  /* eslint-disable */
27
+ import { viewBytes } from "../../shared/buffer-source.js";
27
28
  import { NativeX509 } from "./native-crypto.js";
28
29
  import { validateString, validateObject, validateBoolean, } from "../net/validators.js";
29
30
  import { Buffer } from "buffer";
@@ -106,7 +107,7 @@ export class X509Certificate {
106
107
  if (!isArrayBufferView(buffer)) {
107
108
  throw new ERR_INVALID_ARG_TYPE("buffer", ["string", "Buffer", "TypedArray", "DataView"], buffer);
108
109
  }
109
- const handle = NativeX509.parse(new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength));
110
+ const handle = NativeX509.parse(viewBytes(buffer));
110
111
  if (handle == null) {
111
112
  throw new ERR_INVALID_ARG_VALUE("buffer", buffer, "is not a valid certificate");
112
113
  }
@@ -38,7 +38,7 @@ function spliceOne(list, index) {
38
38
  list[index] = list[index + 1];
39
39
  list.pop();
40
40
  }
41
- import { nextTick, emitWarning } from "../process/index.js";
41
+ import { nextTick, emitWarning } from "../process/scheduling.js";
42
42
  import { default as async_hooks } from "node:async_hooks";
43
43
  const { AsyncResource } = async_hooks;
44
44
  import { inspect } from "node:util";
@@ -0,0 +1,11 @@
1
+ # Upstream notices
2
+
3
+ This module ports Cloudflare workerd tag `v1.20261012.1`, revision
4
+ `5358e3d337336eaf696a48bc1563d808b10feba5`:
5
+
6
+ - `src/node/_tls_common.ts`
7
+ - `src/node/internal/internal_tls_common.ts`
8
+
9
+ Copyright Cloudflare, Inc.; Apache License 2.0. Node.js/Joyent MIT notices
10
+ are preserved in the source files. Imports, resource-management symbols and
11
+ host constructor references are adapted for the Capacitor runtime.