cf-workers-native 0.1.4 → 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 (296) hide show
  1. package/README.md +2 -2
  2. package/dist/browser/documents/page-source.js +1 -1
  3. package/dist/browser/fetch/host-call.js +6 -1
  4. package/dist/browser/fetch/native-network.d.ts +1 -1
  5. package/dist/browser/fetch/relay.js +2 -0
  6. package/dist/browser/headers/index.d.ts +2 -0
  7. package/dist/browser/headers/index.js +5 -0
  8. package/dist/browser/isolated/transport.js +3 -2
  9. package/dist/browser/request/index.js +3 -2
  10. package/dist/browser/response/index.d.ts +2 -0
  11. package/dist/browser/response/index.js +11 -3
  12. package/dist/browser/structured-clone/index.d.ts +3 -0
  13. package/dist/browser/structured-clone/index.js +75 -7
  14. package/dist/browser/websocket/attachment-size.d.ts +3 -0
  15. package/dist/browser/websocket/attachment-size.js +336 -0
  16. package/dist/browser/websocket/brand.d.ts +4 -0
  17. package/dist/browser/websocket/brand.js +16 -0
  18. package/dist/browser/websocket/close-event.d.ts +7 -0
  19. package/dist/browser/websocket/close-event.js +30 -0
  20. package/dist/browser/websocket/compression.d.ts +5 -0
  21. package/dist/browser/websocket/compression.js +124 -0
  22. package/dist/browser/websocket/conversion.d.ts +2 -0
  23. package/dist/browser/websocket/conversion.js +13 -0
  24. package/dist/browser/websocket/endpoint.d.ts +39 -0
  25. package/dist/browser/websocket/endpoint.js +379 -0
  26. package/dist/browser/websocket/frames.d.ts +21 -0
  27. package/dist/browser/websocket/frames.js +121 -0
  28. package/dist/browser/websocket/native.d.ts +14 -0
  29. package/dist/browser/websocket/native.js +226 -0
  30. package/dist/cloudflare/apis/cloudflare-node/index.js +11 -23
  31. package/dist/cloudflare/workers/worker-runtime.js +2 -1
  32. package/dist/compat/console/index.d.ts +35 -0
  33. package/dist/compat/console/index.js +92 -0
  34. package/dist/compat/crypto/LICENSE-3RD-PARTY.md +39 -0
  35. package/dist/compat/crypto/LICENSE-APACHE +177 -0
  36. package/dist/compat/crypto/LICENSE.boringssl +238 -0
  37. package/dist/compat/crypto/LICENSE.emscripten +102 -0
  38. package/dist/compat/crypto/LICENSE.musl +193 -0
  39. package/dist/compat/crypto/LICENSE.ncrypto +21 -0
  40. package/dist/compat/crypto/LICENSE.openssl +177 -0
  41. package/dist/compat/crypto/asymmetric.d.ts +13 -0
  42. package/dist/compat/crypto/asymmetric.js +312 -0
  43. package/dist/compat/crypto/brorand.cjs +74 -0
  44. package/dist/compat/crypto/brorand.d.cts +6 -0
  45. package/dist/compat/crypto/certificate.d.ts +14 -0
  46. package/dist/compat/crypto/certificate.js +66 -0
  47. package/dist/compat/crypto/cipher-handle.d.ts +27 -0
  48. package/dist/compat/crypto/cipher-handle.js +239 -0
  49. package/dist/compat/crypto/cipher-info.d.ts +12 -0
  50. package/dist/compat/crypto/cipher-info.js +324 -0
  51. package/dist/compat/crypto/constants.d.ts +62 -0
  52. package/dist/compat/crypto/constants.js +68 -0
  53. package/dist/compat/crypto/dh-handle.d.ts +17 -0
  54. package/dist/compat/crypto/dh-handle.js +180 -0
  55. package/dist/compat/crypto/dh.d.ts +53 -0
  56. package/dist/compat/crypto/dh.js +138 -0
  57. package/dist/compat/crypto/digest-stream.d.ts +15 -0
  58. package/dist/compat/crypto/digest-stream.js +213 -0
  59. package/dist/compat/crypto/digests.d.ts +3 -0
  60. package/dist/compat/crypto/digests.js +32 -0
  61. package/dist/compat/crypto/ecdh.d.ts +25 -0
  62. package/dist/compat/crypto/ecdh.js +109 -0
  63. package/dist/compat/crypto/hash-handle.d.ts +23 -0
  64. package/dist/compat/crypto/hash-handle.js +70 -0
  65. package/dist/compat/crypto/hash.d.ts +37 -0
  66. package/dist/compat/crypto/hash.js +218 -0
  67. package/dist/compat/crypto/hkdf.d.ts +2 -0
  68. package/dist/compat/crypto/hkdf.js +78 -0
  69. package/dist/compat/crypto/index.cjs +2 -0
  70. package/dist/compat/crypto/index.d.cts +169 -0
  71. package/dist/compat/crypto/index.d.ts +213 -0
  72. package/dist/compat/crypto/index.js +96 -0
  73. package/dist/compat/crypto/key-errors.d.ts +10 -0
  74. package/dist/compat/crypto/key-errors.js +17 -0
  75. package/dist/compat/crypto/key-export.d.ts +8 -0
  76. package/dist/compat/crypto/key-export.js +49 -0
  77. package/dist/compat/crypto/key-formats.d.ts +7 -0
  78. package/dist/compat/crypto/key-formats.js +251 -0
  79. package/dist/compat/crypto/key-options.d.ts +1 -0
  80. package/dist/compat/crypto/key-options.js +74 -0
  81. package/dist/compat/crypto/key-state.d.ts +10 -0
  82. package/dist/compat/crypto/key-state.js +4 -0
  83. package/dist/compat/crypto/keys.d.ts +58 -0
  84. package/dist/compat/crypto/keys.js +278 -0
  85. package/dist/compat/crypto/metadata.d.ts +13 -0
  86. package/dist/compat/crypto/metadata.js +109 -0
  87. package/dist/compat/crypto/native-cipher.d.ts +17 -0
  88. package/dist/compat/crypto/native-cipher.js +192 -0
  89. package/dist/compat/crypto/native-crypto.d.ts +81 -0
  90. package/dist/compat/crypto/native-crypto.js +681 -0
  91. package/dist/compat/crypto/pbkdf2-handle.d.ts +4 -0
  92. package/dist/compat/crypto/pbkdf2-handle.js +26 -0
  93. package/dist/compat/crypto/pbkdf2.d.ts +5 -0
  94. package/dist/compat/crypto/pbkdf2.js +60 -0
  95. package/dist/compat/crypto/prime.d.ts +19 -0
  96. package/dist/compat/crypto/prime.js +146 -0
  97. package/dist/compat/crypto/random.d.ts +18 -0
  98. package/dist/compat/crypto/random.js +203 -0
  99. package/dist/compat/crypto/rsa.d.ts +21 -0
  100. package/dist/compat/crypto/rsa.js +177 -0
  101. package/dist/compat/crypto/scrypt.d.ts +25 -0
  102. package/dist/compat/crypto/scrypt.js +152 -0
  103. package/dist/compat/crypto/sign-errors.d.ts +8 -0
  104. package/dist/compat/crypto/sign-errors.js +13 -0
  105. package/dist/compat/crypto/sign-handle.d.ts +22 -0
  106. package/dist/compat/crypto/sign-handle.js +149 -0
  107. package/dist/compat/crypto/signatures.d.ts +34 -0
  108. package/dist/compat/crypto/signatures.js +252 -0
  109. package/dist/compat/crypto/subtle-digest.d.ts +1 -0
  110. package/dist/compat/crypto/subtle-digest.js +56 -0
  111. package/dist/compat/crypto/symmetric.d.ts +45 -0
  112. package/dist/compat/crypto/symmetric.js +239 -0
  113. package/dist/compat/crypto/validation.d.ts +7 -0
  114. package/dist/compat/crypto/validation.js +46 -0
  115. package/dist/compat/crypto/webcrypto.d.ts +13 -0
  116. package/dist/compat/crypto/webcrypto.js +51 -0
  117. package/dist/compat/crypto/x509.d.ts +30 -0
  118. package/dist/compat/crypto/x509.js +407 -0
  119. package/dist/compat/events/errors.d.ts +8 -0
  120. package/dist/compat/events/errors.js +39 -0
  121. package/dist/compat/events/index.cjs +2 -0
  122. package/dist/compat/events/index.d.cts +2 -0
  123. package/dist/compat/events/index.d.ts +64 -0
  124. package/dist/compat/events/index.js +792 -0
  125. package/dist/compat/events/intrinsics.d.ts +1 -0
  126. package/dist/compat/events/intrinsics.js +2 -0
  127. package/dist/compat/fs/LICENSE-3RD-PARTY.md +11 -0
  128. package/dist/compat/fs/LICENSE-APACHE +177 -0
  129. package/dist/compat/fs/directory-backend.d.ts +6 -0
  130. package/dist/compat/fs/directory-backend.js +51 -0
  131. package/dist/compat/fs/directory.d.ts +37 -0
  132. package/dist/compat/fs/directory.js +137 -0
  133. package/dist/compat/fs/embedded.d.ts +85 -0
  134. package/dist/compat/fs/embedded.js +260 -0
  135. package/dist/compat/fs/file-handle.d.ts +75 -0
  136. package/dist/compat/fs/file-handle.js +226 -0
  137. package/dist/compat/fs/glob-internal.d.ts +15 -0
  138. package/dist/compat/fs/glob-internal.js +417 -0
  139. package/dist/compat/fs/glob.d.ts +10 -0
  140. package/dist/compat/fs/glob.js +71 -0
  141. package/dist/compat/fs/index.d.ts +8 -82
  142. package/dist/compat/fs/index.js +736 -238
  143. package/dist/compat/fs/io-validation.d.ts +14 -0
  144. package/dist/compat/fs/io-validation.js +130 -0
  145. package/dist/compat/fs/io.d.ts +1 -0
  146. package/dist/compat/fs/io.js +282 -0
  147. package/dist/compat/fs/mode.d.ts +1 -0
  148. package/dist/compat/fs/mode.js +13 -0
  149. package/dist/compat/fs/promises/index.d.ts +3 -1
  150. package/dist/compat/fs/promises/index.js +1 -1
  151. package/dist/compat/fs/public-types.d.ts +120 -0
  152. package/dist/compat/fs/public-types.js +1 -0
  153. package/dist/compat/fs/stream-errors.d.ts +6 -0
  154. package/dist/compat/fs/stream-errors.js +8 -0
  155. package/dist/compat/fs/stream-utils.d.ts +16 -0
  156. package/dist/compat/fs/stream-utils.js +29 -0
  157. package/dist/compat/fs/streams.d.ts +104 -0
  158. package/dist/compat/fs/streams.js +794 -0
  159. package/dist/compat/fs/writable.d.ts +14 -0
  160. package/dist/compat/fs/writable.js +532 -0
  161. package/dist/compat/http/index.d.ts +11 -28
  162. package/dist/compat/http/index.js +81 -125
  163. package/dist/compat/http/server-options.d.ts +1 -0
  164. package/dist/compat/http/server-options.js +87 -0
  165. package/dist/compat/http/symbols.d.ts +5 -0
  166. package/dist/compat/http/symbols.js +9 -0
  167. package/dist/compat/http/unique-headers.d.ts +1 -0
  168. package/dist/compat/http/unique-headers.js +21 -0
  169. package/dist/compat/http-common/index.d.ts +37 -0
  170. package/dist/compat/http-common/index.js +43 -0
  171. package/dist/compat/http-outgoing/index.d.ts +14 -0
  172. package/dist/compat/http-outgoing/index.js +17 -0
  173. package/dist/compat/http-server/index.d.ts +18 -0
  174. package/dist/compat/http-server/index.js +26 -0
  175. package/dist/compat/https/index.d.ts +4 -2
  176. package/dist/compat/module/builtins.d.ts +1 -0
  177. package/dist/compat/module/builtins.js +101 -0
  178. package/dist/compat/module/index.d.ts +4 -2
  179. package/dist/compat/module/index.js +22 -17
  180. package/dist/compat/module/metadata.d.ts +44 -0
  181. package/dist/compat/module/metadata.js +127 -0
  182. package/dist/compat/net/internal-net.js +4 -0
  183. package/dist/compat/net/sockets.d.ts +5 -0
  184. package/dist/compat/net/sockets.js +153 -14
  185. package/dist/compat/net/validators.d.ts +1 -0
  186. package/dist/compat/net/validators.js +8 -0
  187. package/dist/compat/process/configuration.d.ts +113 -0
  188. package/dist/compat/process/configuration.js +115 -0
  189. package/dist/compat/process/directory.d.ts +4 -0
  190. package/dist/compat/process/directory.js +28 -0
  191. package/dist/compat/process/files.d.ts +3 -0
  192. package/dist/compat/process/files.js +10 -0
  193. package/dist/compat/process/index.cjs +2 -0
  194. package/dist/compat/process/index.d.cts +4 -0
  195. package/dist/compat/process/index.d.ts +20 -0
  196. package/dist/compat/process/index.js +113 -0
  197. package/dist/compat/process/metadata.d.ts +135 -0
  198. package/dist/compat/process/metadata.js +251 -0
  199. package/dist/compat/process/scheduling.d.ts +2 -0
  200. package/dist/compat/process/scheduling.js +60 -0
  201. package/dist/compat/process/state.d.ts +4 -0
  202. package/dist/compat/process/state.js +5 -0
  203. package/dist/compat/process/stdio.d.ts +18 -0
  204. package/dist/compat/process/stdio.js +66 -0
  205. package/dist/compat/stream/destroy.d.ts +1 -0
  206. package/dist/compat/stream/destroy.js +21 -1
  207. package/dist/compat/stream/readable.js +10 -2
  208. package/dist/compat/stream-web/LICENSE +22 -0
  209. package/dist/compat/stream-web/ponyfill.d.ts +1 -1
  210. package/dist/compat/stream-web/ponyfill.js +2369 -1775
  211. package/dist/compat/stream-web/runtime.d.ts +1 -1
  212. package/dist/compat/stream-web/runtime.js +3 -2
  213. package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
  214. package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
  215. package/dist/compat/stream-wrap/index.d.ts +1 -0
  216. package/dist/compat/stream-wrap/index.js +1 -0
  217. package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
  218. package/dist/compat/tls/LICENSE-APACHE +177 -0
  219. package/dist/compat/tls/constants.d.ts +7 -0
  220. package/dist/compat/tls/constants.js +14 -0
  221. package/dist/compat/tls/errors.d.ts +35 -0
  222. package/dist/compat/tls/errors.js +68 -0
  223. package/dist/compat/tls/helpers.d.ts +9 -0
  224. package/dist/compat/tls/helpers.js +207 -0
  225. package/dist/compat/tls/index.d.ts +26 -0
  226. package/dist/compat/tls/index.js +50 -0
  227. package/dist/compat/tls/jsstream.d.ts +19 -0
  228. package/dist/compat/tls/jsstream.js +196 -0
  229. package/dist/compat/tls/native-session.d.ts +3 -0
  230. package/dist/compat/tls/native-session.js +187 -0
  231. package/dist/compat/tls/wrap.d.ts +65 -0
  232. package/dist/compat/tls/wrap.js +541 -0
  233. package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
  234. package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
  235. package/dist/compat/tls-wrap/index.d.ts +7 -0
  236. package/dist/compat/tls-wrap/index.js +3 -0
  237. package/dist/compat/util/index.js +43 -1
  238. package/dist/compat/util/inspect.js +5 -1
  239. package/dist/compat/util/types/index.d.ts +3 -0
  240. package/dist/compat/util/types/index.js +5 -0
  241. package/dist/compat/zlib/LICENSE-3RD-PARTY.md +11 -0
  242. package/dist/compat/zlib/LICENSE-APACHE +177 -0
  243. package/dist/compat/zlib/LICENSE.brotli +19 -0
  244. package/dist/compat/zlib/LICENSE.emscripten +102 -0
  245. package/dist/compat/zlib/LICENSE.musl +193 -0
  246. package/dist/compat/zlib/LICENSE.zlib +22 -0
  247. package/dist/compat/zlib/LICENSE.zstd +30 -0
  248. package/dist/compat/zlib/classic-base.cjs +600 -0
  249. package/dist/compat/zlib/classic-base.d.cts +39 -0
  250. package/dist/compat/zlib/classic-binding.d.ts +28 -0
  251. package/dist/compat/zlib/classic-binding.js +105 -0
  252. package/dist/compat/zlib/classic.d.ts +44 -0
  253. package/dist/compat/zlib/classic.js +199 -0
  254. package/dist/compat/zlib/codec-binding.d.ts +33 -0
  255. package/dist/compat/zlib/codec-binding.js +141 -0
  256. package/dist/compat/zlib/compression.d.ts +26 -0
  257. package/dist/compat/zlib/compression.js +170 -0
  258. package/dist/compat/zlib/constants.d.ts +172 -0
  259. package/dist/compat/zlib/constants.js +173 -0
  260. package/dist/compat/zlib/errors.d.ts +21 -0
  261. package/dist/compat/zlib/errors.js +32 -0
  262. package/dist/compat/zlib/index.d.ts +544 -0
  263. package/dist/compat/zlib/index.js +194 -0
  264. package/dist/compat/zlib/input.d.ts +16 -0
  265. package/dist/compat/zlib/input.js +132 -0
  266. package/dist/compat/zlib/native-codecs.d.ts +24 -0
  267. package/dist/compat/zlib/native-codecs.js +180 -0
  268. package/dist/compat/zlib/native-zlib.d.ts +5 -0
  269. package/dist/compat/zlib/native-zlib.js +52 -0
  270. package/dist/compat/zlib/public-types.d.ts +48 -0
  271. package/dist/compat/zlib/public-types.js +1 -0
  272. package/dist/compat/zlib/validators.d.ts +3 -0
  273. package/dist/compat/zlib/validators.js +18 -0
  274. package/dist/shared/buffer-source.d.ts +5 -0
  275. package/dist/shared/buffer-source.js +70 -0
  276. package/dist/shared/globals/inject.d.ts +2 -1
  277. package/dist/shared/globals/inject.js +2 -1
  278. package/dist/shared/globals/platform.d.ts +8 -0
  279. package/dist/shared/globals/platform.js +1 -0
  280. package/dist/shared/globals/runtime.d.ts +1 -2
  281. package/dist/shared/globals/runtime.js +1 -2
  282. package/dist/shared/globals/web.js +5 -0
  283. package/dist/shared/request-context.d.ts +2 -0
  284. package/dist/shared/request-context.js +11 -0
  285. package/dist/shared/request-scope.d.ts +4 -0
  286. package/dist/shared/request-scope.js +14 -0
  287. package/dist/tooling/async.js +36 -14
  288. package/dist/tooling/shared.d.ts +1 -0
  289. package/dist/tooling/shared.js +26 -1
  290. package/dist/tooling/vite.js +8 -3
  291. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +92 -13
  292. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
  293. package/native/ios/NetworkBridge.swift +11 -1
  294. package/native/ios/SocketBridge.swift +37 -2
  295. package/native/ios/WorkersCapacitorPlugin.swift +4 -0
  296. package/package.json +4 -2
@@ -0,0 +1,252 @@
1
+ // @ts-nocheck
2
+ import { createPrivateKey, createPublicKey } from "./asymmetric.js";
3
+ // Copyright (c) 2017-2023 Cloudflare, Inc.
4
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
5
+ // https://opensource.org/licenses/Apache-2.0
6
+ //
7
+ // Copyright Joyent, Inc. and other Node contributors.
8
+ //
9
+ // Permission is hereby granted, free of charge, to any person obtaining a
10
+ // copy of this software and associated documentation files (the
11
+ // "Software"), to deal in the Software without restriction, including
12
+ // without limitation the rights to use, copy, modify, merge, publish,
13
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
14
+ // persons to whom the Software is furnished to do so, subject to the
15
+ // following conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be included
18
+ // in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
23
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ /* TODO: the following is adopted code, enabling linting one day */
28
+ /* eslint-disable */
29
+ import { default as cryptoImpl, } from "./sign-handle.js";
30
+ import { validateString } from "../net/validators.js";
31
+ import { Buffer } from "node:buffer";
32
+ import { isKeyObject, getKeyObjectHandle } from "./keys.js";
33
+ import { ERR_CRYPTO_SIGN_KEY_REQUIRED, ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE, ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, } from "./sign-errors.js";
34
+ import { Writable } from "../stream/writable.js";
35
+ import { isArrayBufferView } from "../util/types/index.js";
36
+ const kHandle = Symbol("kHandle");
37
+ // Uses old-style class syntax for Node.js compatibility
38
+ export const Sign = function (algorithm, options) {
39
+ if (!(this instanceof Sign))
40
+ return new Sign(algorithm, options);
41
+ validateString(algorithm, "algorithm");
42
+ this[kHandle] = new cryptoImpl.SignHandle(algorithm);
43
+ Writable.call(this, options);
44
+ return this;
45
+ };
46
+ Object.setPrototypeOf(Sign.prototype, Writable.prototype);
47
+ Object.setPrototypeOf(Sign, Writable);
48
+ Sign.prototype._write = function _write(chunk, encoding, callback) {
49
+ this.update(chunk, encoding);
50
+ callback();
51
+ };
52
+ Sign.prototype.update = function (data, encoding) {
53
+ if (typeof data === "string") {
54
+ data = Buffer.from(data, encoding);
55
+ }
56
+ if (!isArrayBufferView(data)) {
57
+ throw new ERR_INVALID_ARG_TYPE("data", ["string", "Buffer", "TypedArray", "DataView"], data);
58
+ }
59
+ this[kHandle].update(data);
60
+ return this;
61
+ };
62
+ function getIntOption(name, options) {
63
+ const value = options[name];
64
+ if (value !== undefined) {
65
+ if (value === value >> 0) {
66
+ return value;
67
+ }
68
+ throw new ERR_INVALID_ARG_VALUE(`options.${name}`, value);
69
+ }
70
+ return undefined;
71
+ }
72
+ function getDSASignatureEncoding(options) {
73
+ if (typeof options === "object") {
74
+ const { dsaEncoding = "der" } = options;
75
+ if (dsaEncoding === "der")
76
+ return 0; // kSigEncDER;
77
+ else if (dsaEncoding === "ieee-p1363")
78
+ return 1; // kSigEncP1363
79
+ throw new ERR_INVALID_ARG_VALUE("options.dsaEncoding", dsaEncoding);
80
+ }
81
+ return 0;
82
+ }
83
+ function getPrivateKey(options) {
84
+ if (options instanceof CryptoKey) {
85
+ return options;
86
+ }
87
+ else if (isKeyObject(options)) {
88
+ const keyObject = options;
89
+ if (keyObject.type === "secret") {
90
+ throw new ERR_INVALID_ARG_TYPE("options", ["PublicKeyObject", "PrivateKeyObject", "CryptoKey", "object"], keyObject.type);
91
+ }
92
+ if (keyObject.type === "public") {
93
+ throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE("public", "private");
94
+ }
95
+ return getKeyObjectHandle(keyObject);
96
+ }
97
+ else {
98
+ return getKeyObjectHandle(createPrivateKey(options));
99
+ }
100
+ }
101
+ Sign.prototype.sign = function (options, encoding) {
102
+ if (!options) {
103
+ throw new ERR_CRYPTO_SIGN_KEY_REQUIRED();
104
+ }
105
+ const key = getPrivateKey(options);
106
+ // Options specific to RSA
107
+ const rsaPadding = getIntOption("padding", options);
108
+ const pssSaltLength = getIntOption("saltLength", options);
109
+ // Options specific to (EC)DSA
110
+ const dsaSigEnc = getDSASignatureEncoding(options);
111
+ const u8 = this[kHandle].sign(key, rsaPadding, pssSaltLength, dsaSigEnc);
112
+ const res = Buffer.from(u8.buffer, u8.byteOffset, u8.byteLength);
113
+ if (encoding && encoding !== "buffer") {
114
+ return res.toString(encoding);
115
+ }
116
+ return res;
117
+ };
118
+ // Uses old-style class syntax for Node.js compatibility
119
+ export const Verify = function (algorithm, options) {
120
+ if (!(this instanceof Verify))
121
+ return new Verify(algorithm, options);
122
+ validateString(algorithm, "algorithm");
123
+ this[kHandle] = new cryptoImpl.VerifyHandle(algorithm);
124
+ Writable.call(this, options);
125
+ return this;
126
+ };
127
+ Object.setPrototypeOf(Verify.prototype, Writable.prototype);
128
+ Object.setPrototypeOf(Verify, Writable);
129
+ Verify.prototype._write = function _write(chunk, encoding, callback) {
130
+ this.update(chunk, encoding);
131
+ callback();
132
+ };
133
+ Verify.prototype.update = function (data, encoding) {
134
+ if (typeof data === "string") {
135
+ data = Buffer.from(data, encoding);
136
+ }
137
+ if (!isArrayBufferView(data)) {
138
+ throw new ERR_INVALID_ARG_TYPE("data", ["string", "Buffer", "TypedArray", "DataView"], data);
139
+ }
140
+ this[kHandle].update(data);
141
+ return this;
142
+ };
143
+ Verify.prototype.verify = function (options, signature, encoding = "utf8") {
144
+ if (!options) {
145
+ throw new ERR_CRYPTO_SIGN_KEY_REQUIRED();
146
+ }
147
+ let key;
148
+ if (options instanceof CryptoKey) {
149
+ key = options;
150
+ }
151
+ else if (isKeyObject(options)) {
152
+ key = getKeyObjectHandle(options);
153
+ }
154
+ else {
155
+ key = getKeyObjectHandle(createPublicKey(options));
156
+ }
157
+ if (!(key instanceof CryptoKey) && !isKeyObject(key)) {
158
+ throw new ERR_INVALID_ARG_TYPE("options", ["KeyObject", "CryptoKey", "object"], key);
159
+ }
160
+ // Options specific to RSA
161
+ const rsaPadding = getIntOption("padding", options);
162
+ const pssSaltLength = getIntOption("saltLength", options);
163
+ // Options specific to (EC)DSA
164
+ const dsaSigEnc = getDSASignatureEncoding(options);
165
+ if (typeof signature === "string") {
166
+ signature = Buffer.from(signature, encoding);
167
+ }
168
+ return this[kHandle].verify(key, signature, rsaPadding, pssSaltLength, dsaSigEnc);
169
+ };
170
+ export function createSign(algorithm, options) {
171
+ return new Sign(algorithm, options);
172
+ }
173
+ export function createVerify(algorithm, options) {
174
+ return new Verify(algorithm, options);
175
+ }
176
+ export function sign(algorithm, data, options, callback) {
177
+ if (algorithm != null) {
178
+ validateString(algorithm, "algorithm");
179
+ }
180
+ else {
181
+ algorithm = undefined;
182
+ }
183
+ if (!isArrayBufferView(data)) {
184
+ throw new ERR_INVALID_ARG_TYPE("data", ["Buffer", "TypedArray", "DataView"], data);
185
+ }
186
+ if (!options) {
187
+ throw new ERR_CRYPTO_SIGN_KEY_REQUIRED();
188
+ }
189
+ const key = getPrivateKey(options);
190
+ // Options specific to RSA
191
+ const rsaPadding = getIntOption("padding", options);
192
+ const pssSaltLength = getIntOption("saltLength", options);
193
+ // Options specific to (EC)DSA
194
+ const dsaSigEnc = getDSASignatureEncoding(options);
195
+ if (callback === undefined) {
196
+ return Buffer.from(cryptoImpl.signOneShot(key, algorithm, data, rsaPadding, pssSaltLength, dsaSigEnc));
197
+ }
198
+ try {
199
+ const signature = Buffer.from(cryptoImpl.signOneShot(key, algorithm, data, rsaPadding, pssSaltLength, dsaSigEnc));
200
+ queueMicrotask(() => callback(null, signature));
201
+ }
202
+ catch (err) {
203
+ queueMicrotask(() => callback(err));
204
+ }
205
+ }
206
+ export function verify(algorithm, data, options, signature, callback) {
207
+ // Node.js allows the algorithm to be either undefined or null, in which
208
+ // case we just normalize it to undefined.
209
+ if (algorithm != null) {
210
+ validateString(algorithm, "algorithm");
211
+ }
212
+ else {
213
+ algorithm = undefined;
214
+ }
215
+ if (!isArrayBufferView(data)) {
216
+ throw new ERR_INVALID_ARG_TYPE("data", ["Buffer", "TypedArray", "DataView"], data);
217
+ }
218
+ if (!isArrayBufferView(signature)) {
219
+ throw new ERR_INVALID_ARG_TYPE("signature", ["Buffer", "TypedArray", "DataView"], signature);
220
+ }
221
+ if (!options) {
222
+ throw new ERR_CRYPTO_SIGN_KEY_REQUIRED();
223
+ }
224
+ let key;
225
+ if (options instanceof CryptoKey) {
226
+ key = options;
227
+ }
228
+ else if (isKeyObject(options)) {
229
+ key = getKeyObjectHandle(options);
230
+ }
231
+ else {
232
+ key = getKeyObjectHandle(createPublicKey(options));
233
+ }
234
+ if (!(key instanceof CryptoKey) && !isKeyObject(key)) {
235
+ throw new ERR_INVALID_ARG_TYPE("options", ["KeyObject", "CryptoKey", "object"], key);
236
+ }
237
+ // Options specific to RSA
238
+ const rsaPadding = getIntOption("padding", options);
239
+ const pssSaltLength = getIntOption("saltLength", options);
240
+ // Options specific to (EC)DSA
241
+ const dsaSigEnc = getDSASignatureEncoding(options);
242
+ if (callback === undefined) {
243
+ return cryptoImpl.verifyOneShot(key, algorithm, data, signature, rsaPadding, pssSaltLength, dsaSigEnc);
244
+ }
245
+ try {
246
+ callback(null, cryptoImpl.verifyOneShot(key, algorithm, data, signature, rsaPadding, pssSaltLength, dsaSigEnc));
247
+ }
248
+ catch (err) {
249
+ queueMicrotask(() => callback(err));
250
+ }
251
+ return; // explicit return is necessary to squelch typescript warning.
252
+ }
@@ -0,0 +1 @@
1
+ export declare function installDigest(subtle: SubtleCrypto): void;
@@ -0,0 +1,56 @@
1
+ import { NativeDigest } from "./native-crypto.js";
2
+ import { dictionaryString } from "./key-formats.js";
3
+ import { bufferBytes, viewBytes } from "../../shared/buffer-source.js";
4
+ const bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
5
+ function isBuffer(value) {
6
+ try {
7
+ bufferLength.call(value);
8
+ return true;
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
14
+ const names = Object.assign(Object.create(null), {
15
+ "sha-1": "sha1",
16
+ "sha-256": "sha256",
17
+ "sha-384": "sha384",
18
+ "sha-512": "sha512",
19
+ md5: "md5",
20
+ });
21
+ export function installDigest(subtle) {
22
+ const digest = {
23
+ digest(algorithm, data) {
24
+ if (this !== subtle)
25
+ throw new TypeError("Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.");
26
+ return (async () => {
27
+ if (algorithm == null)
28
+ throw new TypeError("Cannot initialize N7workerd3api12SubtleCrypto13HashAlgorithmE with required members from an undefined or null value.");
29
+ const name = dictionaryString(typeof algorithm === "object" || typeof algorithm === "function"
30
+ ? algorithm.name
31
+ : algorithm);
32
+ if (!isBuffer(data) && !ArrayBuffer.isView(data))
33
+ throw new TypeError("Failed to execute 'digest' on 'SubtleCrypto': parameter 2 is not of type 'BufferSource'.");
34
+ const bytes = isBuffer(data) ? bufferBytes(data) : viewBytes(data);
35
+ const normalized = names[name.split("\0")[0].toLowerCase()];
36
+ if (!normalized)
37
+ throw new DOMException("Unrecognized or unimplemented digest algorithm requested.", "NotSupportedError");
38
+ const handle = new NativeDigest(normalized);
39
+ try {
40
+ handle.update(bytes);
41
+ return handle.final().buffer;
42
+ }
43
+ finally {
44
+ handle.dispose();
45
+ }
46
+ })();
47
+ },
48
+ }.digest;
49
+ Object.defineProperty(digest, "length", { value: 0 });
50
+ Object.defineProperty(Object.getPrototypeOf(subtle), "digest", {
51
+ value: digest,
52
+ writable: true,
53
+ enumerable: true,
54
+ configurable: true,
55
+ });
56
+ }
@@ -0,0 +1,45 @@
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
+ }
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;
21
+ }
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;
33
+ }
34
+ export interface CipherOptions extends TransformOptions {
35
+ authLengthTag?: number;
36
+ }
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;
45
+ export {};
@@ -0,0 +1,239 @@
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";
27
+ import { Transform } from "../stream/transform.js";
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);
53
+ }
54
+ function getIv(iv) {
55
+ if (isAnyArrayBuffer(iv) || isArrayBufferView(iv)) {
56
+ return iv;
57
+ }
58
+ else if (typeof iv === "string") {
59
+ return Buffer.from(iv, "utf8");
60
+ }
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");
81
+ }
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");
168
+ }
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 = {}) {
235
+ return new Cipheriv(algorithm, key, iv, options);
236
+ }
237
+ export function createDecipheriv(algorithm, key, iv, options = {}) {
238
+ return new Decipheriv(algorithm, key, iv, options);
239
+ }
@@ -0,0 +1,7 @@
1
+ import { Buffer } from "node:buffer";
2
+ export declare function validateInteger(value: unknown, name: string, min?: number, max?: number): asserts value is number;
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;
@@ -0,0 +1,46 @@
1
+ import { bufferBytes, viewBytes, isAnyBuffer, } from "../../shared/buffer-source.js";
2
+ import { Buffer } from "node:buffer";
3
+ import { ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE } from "../net/errors.js";
4
+ export function validateInteger(value, name, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
5
+ if (typeof value !== "number")
6
+ throw new ERR_INVALID_ARG_TYPE(name, "number", value);
7
+ if (!Number.isInteger(value))
8
+ throw new ERR_OUT_OF_RANGE(name, "an integer", value);
9
+ if (value < min || value > max)
10
+ throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
11
+ }
12
+ export function bytes(value, name) {
13
+ if (typeof value === "string")
14
+ return Buffer.from(value);
15
+ if (isAnyBuffer(value))
16
+ return Buffer.from(value);
17
+ if (ArrayBuffer.isView(value))
18
+ return Buffer.from(viewBytes(value));
19
+ throw new ERR_INVALID_ARG_TYPE(name, ["string", "ArrayBuffer", "Buffer", "TypedArray", "DataView"], value);
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 {};