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.
Files changed (161) hide show
  1. package/dist/browser/documents/page-source.js +1 -1
  2. package/dist/browser/fetch/host-call.js +6 -1
  3. package/dist/browser/fetch/native-network.d.ts +1 -1
  4. package/dist/browser/fetch/relay.js +2 -0
  5. package/dist/browser/isolated/transport.js +3 -2
  6. package/dist/browser/request/index.js +3 -2
  7. package/dist/cloudflare/workers/worker-runtime.js +2 -1
  8. package/dist/compat/console/index.d.ts +35 -0
  9. package/dist/compat/console/index.js +92 -0
  10. package/dist/compat/crypto/LICENSE-3RD-PARTY.md +19 -0
  11. package/dist/compat/crypto/LICENSE-APACHE +177 -0
  12. package/dist/compat/crypto/LICENSE.emscripten +102 -0
  13. package/dist/compat/crypto/LICENSE.musl +193 -0
  14. package/dist/compat/crypto/LICENSE.openssl +177 -0
  15. package/dist/compat/crypto/asymmetric.d.ts +13 -0
  16. package/dist/compat/crypto/asymmetric.js +239 -0
  17. package/dist/compat/crypto/brorand.cjs +74 -0
  18. package/dist/compat/crypto/brorand.d.cts +6 -0
  19. package/dist/compat/crypto/certificate.d.ts +14 -0
  20. package/dist/compat/crypto/certificate.js +66 -0
  21. package/dist/compat/crypto/ecdh.d.ts +15 -0
  22. package/dist/compat/crypto/ecdh.js +109 -0
  23. package/dist/compat/crypto/hkdf.d.ts +2 -0
  24. package/dist/compat/crypto/hkdf.js +52 -0
  25. package/dist/compat/crypto/index.cjs +2 -0
  26. package/dist/compat/crypto/index.d.cts +2 -0
  27. package/dist/compat/crypto/index.d.ts +30 -0
  28. package/dist/compat/crypto/index.js +83 -0
  29. package/dist/compat/crypto/key-formats.d.ts +6 -0
  30. package/dist/compat/crypto/key-formats.js +120 -0
  31. package/dist/compat/crypto/key-state.d.ts +9 -0
  32. package/dist/compat/crypto/key-state.js +4 -0
  33. package/dist/compat/crypto/keys.d.ts +50 -0
  34. package/dist/compat/crypto/keys.js +209 -0
  35. package/dist/compat/crypto/metadata.d.ts +4 -0
  36. package/dist/compat/crypto/metadata.js +22 -0
  37. package/dist/compat/crypto/native-crypto.d.ts +68 -0
  38. package/dist/compat/crypto/native-crypto.js +569 -0
  39. package/dist/compat/crypto/prime.d.ts +19 -0
  40. package/dist/compat/crypto/prime.js +146 -0
  41. package/dist/compat/crypto/random.d.ts +7 -0
  42. package/dist/compat/crypto/random.js +123 -0
  43. package/dist/compat/crypto/rsa.d.ts +5 -0
  44. package/dist/compat/crypto/rsa.js +173 -0
  45. package/dist/compat/crypto/scrypt.d.ts +25 -0
  46. package/dist/compat/crypto/scrypt.js +150 -0
  47. package/dist/compat/crypto/sign-errors.d.ts +8 -0
  48. package/dist/compat/crypto/sign-errors.js +13 -0
  49. package/dist/compat/crypto/sign-handle.d.ts +22 -0
  50. package/dist/compat/crypto/sign-handle.js +105 -0
  51. package/dist/compat/crypto/signatures.d.ts +28 -0
  52. package/dist/compat/crypto/signatures.js +252 -0
  53. package/dist/compat/crypto/symmetric.d.ts +29 -0
  54. package/dist/compat/crypto/symmetric.js +104 -0
  55. package/dist/compat/crypto/validation.d.ts +3 -0
  56. package/dist/compat/crypto/validation.js +19 -0
  57. package/dist/compat/crypto/x509.d.ts +30 -0
  58. package/dist/compat/crypto/x509.js +406 -0
  59. package/dist/compat/events/errors.d.ts +8 -0
  60. package/dist/compat/events/errors.js +39 -0
  61. package/dist/compat/events/index.cjs +2 -0
  62. package/dist/compat/events/index.d.cts +2 -0
  63. package/dist/compat/events/index.d.ts +64 -0
  64. package/dist/compat/events/index.js +792 -0
  65. package/dist/compat/events/intrinsics.d.ts +1 -0
  66. package/dist/compat/events/intrinsics.js +2 -0
  67. package/dist/compat/fs/embedded.d.ts +85 -0
  68. package/dist/compat/fs/embedded.js +255 -0
  69. package/dist/compat/fs/index.d.ts +7 -84
  70. package/dist/compat/fs/index.js +218 -252
  71. package/dist/compat/fs/mode.d.ts +1 -0
  72. package/dist/compat/fs/mode.js +13 -0
  73. package/dist/compat/fs/promises/index.d.ts +1 -1
  74. package/dist/compat/fs/promises/index.js +1 -1
  75. package/dist/compat/fs/writable.d.ts +6 -0
  76. package/dist/compat/fs/writable.js +142 -0
  77. package/dist/compat/http/symbols.d.ts +5 -0
  78. package/dist/compat/http/symbols.js +9 -0
  79. package/dist/compat/http-common/index.d.ts +37 -0
  80. package/dist/compat/http-common/index.js +43 -0
  81. package/dist/compat/http-outgoing/index.d.ts +13 -0
  82. package/dist/compat/http-outgoing/index.js +32 -0
  83. package/dist/compat/http-server/index.d.ts +18 -0
  84. package/dist/compat/http-server/index.js +107 -0
  85. package/dist/compat/module/builtins.d.ts +1 -0
  86. package/dist/compat/module/builtins.js +101 -0
  87. package/dist/compat/module/index.d.ts +4 -2
  88. package/dist/compat/module/index.js +22 -17
  89. package/dist/compat/module/metadata.d.ts +44 -0
  90. package/dist/compat/module/metadata.js +127 -0
  91. package/dist/compat/net/internal-net.js +4 -0
  92. package/dist/compat/net/sockets.d.ts +5 -0
  93. package/dist/compat/net/sockets.js +74 -13
  94. package/dist/compat/process/index.cjs +2 -0
  95. package/dist/compat/process/index.d.cts +4 -0
  96. package/dist/compat/process/index.d.ts +18 -0
  97. package/dist/compat/process/index.js +140 -0
  98. package/dist/compat/process/metadata.d.ts +135 -0
  99. package/dist/compat/process/metadata.js +251 -0
  100. package/dist/compat/process/state.d.ts +4 -0
  101. package/dist/compat/process/state.js +4 -0
  102. package/dist/compat/stream-web/LICENSE +22 -0
  103. package/dist/compat/stream-web/ponyfill.d.ts +1 -1
  104. package/dist/compat/stream-web/ponyfill.js +2369 -1775
  105. package/dist/compat/stream-web/runtime.d.ts +1 -1
  106. package/dist/compat/stream-web/runtime.js +3 -2
  107. package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
  108. package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
  109. package/dist/compat/stream-wrap/index.d.ts +1 -0
  110. package/dist/compat/stream-wrap/index.js +1 -0
  111. package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
  112. package/dist/compat/tls/LICENSE-APACHE +177 -0
  113. package/dist/compat/tls/constants.d.ts +7 -0
  114. package/dist/compat/tls/constants.js +14 -0
  115. package/dist/compat/tls/errors.d.ts +35 -0
  116. package/dist/compat/tls/errors.js +68 -0
  117. package/dist/compat/tls/helpers.d.ts +9 -0
  118. package/dist/compat/tls/helpers.js +207 -0
  119. package/dist/compat/tls/index.d.ts +26 -0
  120. package/dist/compat/tls/index.js +50 -0
  121. package/dist/compat/tls/jsstream.d.ts +19 -0
  122. package/dist/compat/tls/jsstream.js +186 -0
  123. package/dist/compat/tls/native-session.d.ts +3 -0
  124. package/dist/compat/tls/native-session.js +187 -0
  125. package/dist/compat/tls/wrap.d.ts +65 -0
  126. package/dist/compat/tls/wrap.js +544 -0
  127. package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
  128. package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
  129. package/dist/compat/tls-wrap/index.d.ts +7 -0
  130. package/dist/compat/tls-wrap/index.js +3 -0
  131. package/dist/compat/util/index.js +43 -1
  132. package/dist/compat/util/types/index.d.ts +3 -0
  133. package/dist/compat/util/types/index.js +5 -0
  134. package/dist/compat/zlib/LICENSE.brotli +19 -0
  135. package/dist/compat/zlib/LICENSE.emscripten +102 -0
  136. package/dist/compat/zlib/LICENSE.musl +193 -0
  137. package/dist/compat/zlib/LICENSE.zstd +30 -0
  138. package/dist/compat/zlib/compression.d.ts +55 -0
  139. package/dist/compat/zlib/compression.js +259 -0
  140. package/dist/compat/zlib/constants.d.ts +172 -0
  141. package/dist/compat/zlib/constants.js +173 -0
  142. package/dist/compat/zlib/index.d.ts +180 -0
  143. package/dist/compat/zlib/index.js +177 -0
  144. package/dist/compat/zlib/native-codecs.d.ts +17 -0
  145. package/dist/compat/zlib/native-codecs.js +168 -0
  146. package/dist/shared/globals/inject.d.ts +2 -1
  147. package/dist/shared/globals/inject.js +2 -1
  148. package/dist/shared/globals/runtime.d.ts +1 -2
  149. package/dist/shared/globals/runtime.js +1 -2
  150. package/dist/shared/request-scope.d.ts +4 -0
  151. package/dist/shared/request-scope.js +11 -0
  152. package/dist/tooling/async.js +36 -14
  153. package/dist/tooling/shared.d.ts +1 -0
  154. package/dist/tooling/shared.js +20 -1
  155. package/dist/tooling/vite.js +4 -3
  156. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +56 -8
  157. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
  158. package/native/ios/NetworkBridge.swift +11 -1
  159. package/native/ios/SocketBridge.swift +37 -2
  160. package/native/ios/WorkersCapacitorPlugin.swift +4 -0
  161. package/package.json +3 -1
@@ -0,0 +1,193 @@
1
+ musl as a whole is licensed under the following standard MIT license:
2
+
3
+ ----------------------------------------------------------------------
4
+ Copyright © 2005-2020 Rich Felker, et al.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ ----------------------------------------------------------------------
25
+
26
+ Authors/contributors include:
27
+
28
+ A. Wilcox
29
+ Ada Worcester
30
+ Alex Dowad
31
+ Alex Suykov
32
+ Alexander Monakov
33
+ Andre McCurdy
34
+ Andrew Kelley
35
+ Anthony G. Basile
36
+ Aric Belsito
37
+ Arvid Picciani
38
+ Bartosz Brachaczek
39
+ Benjamin Peterson
40
+ Bobby Bingham
41
+ Boris Brezillon
42
+ Brent Cook
43
+ Chris Spiegel
44
+ Clément Vasseur
45
+ Daniel Micay
46
+ Daniel Sabogal
47
+ Daurnimator
48
+ David Carlier
49
+ David Edelsohn
50
+ Denys Vlasenko
51
+ Dmitry Ivanov
52
+ Dmitry V. Levin
53
+ Drew DeVault
54
+ Emil Renner Berthing
55
+ Fangrui Song
56
+ Felix Fietkau
57
+ Felix Janda
58
+ Gianluca Anzolin
59
+ Hauke Mehrtens
60
+ He X
61
+ Hiltjo Posthuma
62
+ Isaac Dunham
63
+ Jaydeep Patil
64
+ Jens Gustedt
65
+ Jeremy Huntwork
66
+ Jo-Philipp Wich
67
+ Joakim Sindholt
68
+ John Spencer
69
+ Julien Ramseier
70
+ Justin Cormack
71
+ Kaarle Ritvanen
72
+ Khem Raj
73
+ Kylie McClain
74
+ Leah Neukirchen
75
+ Luca Barbato
76
+ Luka Perkov
77
+ M Farkas-Dyck (Strake)
78
+ Mahesh Bodapati
79
+ Markus Wichmann
80
+ Masanori Ogino
81
+ Michael Clark
82
+ Michael Forney
83
+ Mikhail Kremnyov
84
+ Natanael Copa
85
+ Nicholas J. Kain
86
+ orc
87
+ Pascal Cuoq
88
+ Patrick Oppenlander
89
+ Petr Hosek
90
+ Petr Skocik
91
+ Pierre Carrier
92
+ Reini Urban
93
+ Rich Felker
94
+ Richard Pennington
95
+ Ryan Fairfax
96
+ Samuel Holland
97
+ Segev Finer
98
+ Shiz
99
+ sin
100
+ Solar Designer
101
+ Stefan Kristiansson
102
+ Stefan O'Rear
103
+ Szabolcs Nagy
104
+ Timo Teräs
105
+ Trutz Behn
106
+ Valentin Ochs
107
+ Will Dietz
108
+ William Haddon
109
+ William Pitcock
110
+
111
+ Portions of this software are derived from third-party works licensed
112
+ under terms compatible with the above MIT license:
113
+
114
+ The TRE regular expression implementation (src/regex/reg* and
115
+ src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
116
+ under a 2-clause BSD license (license text in the source files). The
117
+ included version has been heavily modified by Rich Felker in 2012, in
118
+ the interests of size, simplicity, and namespace cleanliness.
119
+
120
+ Much of the math library code (src/math/* and src/complex/*) is
121
+ Copyright © 1993,2004 Sun Microsystems or
122
+ Copyright © 2003-2011 David Schultz or
123
+ Copyright © 2003-2009 Steven G. Kargl or
124
+ Copyright © 2003-2009 Bruce D. Evans or
125
+ Copyright © 2008 Stephen L. Moshier or
126
+ Copyright © 2017-2018 Arm Limited
127
+ and labelled as such in comments in the individual source files. All
128
+ have been licensed under extremely permissive terms.
129
+
130
+ The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
131
+ The Android Open Source Project and is licensed under a two-clause BSD
132
+ license. It was taken from Bionic libc, used on Android.
133
+
134
+ The AArch64 memcpy and memset code (src/string/aarch64/*) are
135
+ Copyright © 1999-2019, Arm Limited.
136
+
137
+ The implementation of DES for crypt (src/crypt/crypt_des.c) is
138
+ Copyright © 1994 David Burren. It is licensed under a BSD license.
139
+
140
+ The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
141
+ originally written by Solar Designer and placed into the public
142
+ domain. The code also comes with a fallback permissive license for use
143
+ in jurisdictions that may not recognize the public domain.
144
+
145
+ The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
146
+ Valentin Ochs and is licensed under an MIT-style license.
147
+
148
+ The x86_64 port was written by Nicholas J. Kain and is licensed under
149
+ the standard MIT terms.
150
+
151
+ The mips and microblaze ports were originally written by Richard
152
+ Pennington for use in the ellcc project. The original code was adapted
153
+ by Rich Felker for build system and code conventions during upstream
154
+ integration. It is licensed under the standard MIT terms.
155
+
156
+ The mips64 port was contributed by Imagination Technologies and is
157
+ licensed under the standard MIT terms.
158
+
159
+ The powerpc port was also originally written by Richard Pennington,
160
+ and later supplemented and integrated by John Spencer. It is licensed
161
+ under the standard MIT terms.
162
+
163
+ All other files which have no copyright comments are original works
164
+ produced specifically for use as part of this library, written either
165
+ by Rich Felker, the main author of the library, or by one or more
166
+ contibutors listed above. Details on authorship of individual files
167
+ can be found in the git version control history of the project. The
168
+ omission of copyright and license comments in each file is in the
169
+ interest of source tree size.
170
+
171
+ In addition, permission is hereby granted for all public header files
172
+ (include/* and arch/*/bits/*) and crt files intended to be linked into
173
+ applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
174
+ the copyright notice and permission notice otherwise required by the
175
+ license, and to use these files without any requirement of
176
+ attribution. These files include substantial contributions from:
177
+
178
+ Bobby Bingham
179
+ John Spencer
180
+ Nicholas J. Kain
181
+ Rich Felker
182
+ Richard Pennington
183
+ Stefan Kristiansson
184
+ Szabolcs Nagy
185
+
186
+ all of whom have explicitly granted such permission.
187
+
188
+ This file previously contained text expressing a belief that most of
189
+ the files covered by the above exception were sufficiently trivial not
190
+ to be subject to copyright, resulting in confusion over whether it
191
+ negated the permissions granted in the license. In the spirit of
192
+ permissive licensing, and of not having licensing issues being an
193
+ obstacle to adoption, that text has been removed.
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ https://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,13 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { PrivateKeyObject, PublicKeyObject } from "./keys.js";
3
+ export declare function createPrivateKey(value: unknown): PrivateKeyObject;
4
+ export declare function createPublicKey(value: any): PublicKeyObject;
5
+ export declare function generateKeyPairSync(type: string, options?: any): {
6
+ publicKey: any;
7
+ privateKey: any;
8
+ };
9
+ export declare function generateKeyPair(type: string, options: any, callback: any): void;
10
+ export declare function sign(algorithm: any, data: unknown, key: any, callback?: any): any;
11
+ export declare function verify(algorithm: any, data: unknown, key: any, signature: unknown, callback?: any): any;
12
+ export declare function diffieHellman(options: any): Buffer;
13
+ export declare function timingSafeEqual(a: unknown, b: unknown): boolean;
@@ -0,0 +1,239 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { NativeKey, nativeTimingEqual } from "./native-crypto.js";
3
+ import { importJwk } from "./key-formats.js";
4
+ import { create, KeyObject, } from "./keys.js";
5
+ import { keyStates } from "./key-state.js";
6
+ import { bytes } from "./validation.js";
7
+ import { validateObject, validateString, validateOneOf, validateFunction, validateUint32, } from "../net/validators.js";
8
+ import { ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE } from "../net/errors.js";
9
+ function handle(key) {
10
+ const value = keyStates.get(key)?.asymmetric;
11
+ if (!value)
12
+ throw Object.assign(new Error("Synchronous access to opaque host key material is unavailable"), { code: "ERR_METHOD_NOT_IMPLEMENTED" });
13
+ return value;
14
+ }
15
+ function input(value, privateKey) {
16
+ if (value == null)
17
+ throw new ERR_INVALID_ARG_TYPE("key", ["ArrayBuffer", "Buffer", "TypedArray", "DataView", "string", "object"], value);
18
+ const options = typeof value === "string" ||
19
+ value instanceof ArrayBuffer ||
20
+ ArrayBuffer.isView(value)
21
+ ? { key: value }
22
+ : value;
23
+ const data = options.key;
24
+ if (data == null ||
25
+ data instanceof KeyObject ||
26
+ data instanceof globalThis.CryptoKey)
27
+ throw new ERR_INVALID_ARG_TYPE("options.key", ["ArrayBuffer", "Buffer", "TypedArray", "DataView", "string", "object"], data);
28
+ if (typeof data === "object" &&
29
+ !(data instanceof ArrayBuffer) &&
30
+ !ArrayBuffer.isView(data))
31
+ return importJwk(data, privateKey);
32
+ const format = options.format ?? "pem";
33
+ validateOneOf(format, "format", ["pem", "der"]);
34
+ if (options.type !== undefined)
35
+ validateOneOf(options.type, "type", privateKey ? ["pkcs1", "pkcs8", "sec1"] : ["pkcs1", "spki"]);
36
+ const raw = typeof data === "string"
37
+ ? Buffer.from(data, options.encoding ?? "utf8")
38
+ : bytes(data, "key");
39
+ const password = options.passphrase === undefined
40
+ ? undefined
41
+ : typeof options.passphrase === "string"
42
+ ? Buffer.from(options.passphrase, options.encoding ?? "utf8")
43
+ : bytes(options.passphrase, "passphrase");
44
+ if (privateKey)
45
+ return NativeKey.parse(raw, format === "pem", true, password);
46
+ try {
47
+ return NativeKey.parse(raw, format === "pem", false, password);
48
+ }
49
+ catch (error) {
50
+ // createPublicKey also accepts a serialized private key, deriving public material.
51
+ let key;
52
+ try {
53
+ key = NativeKey.parse(raw, format === "pem", true, password);
54
+ }
55
+ catch {
56
+ throw error;
57
+ }
58
+ try {
59
+ return NativeKey.parse(key.export(false, false, "spki"), false, false);
60
+ }
61
+ finally {
62
+ key.dispose();
63
+ }
64
+ }
65
+ }
66
+ export function createPrivateKey(value) {
67
+ return create("private", {
68
+ asymmetric: input(value, true),
69
+ });
70
+ }
71
+ export function createPublicKey(value) {
72
+ if (keyStates.has(value)) {
73
+ if (value.type !== "private")
74
+ throw new ERR_INVALID_ARG_TYPE("key", "PrivateKeyObject", value);
75
+ return create("public", {
76
+ asymmetric: NativeKey.parse(handle(value).export(false, false, "spki"), false, false),
77
+ });
78
+ }
79
+ return create("public", {
80
+ asymmetric: input(value, false),
81
+ });
82
+ }
83
+ export function generateKeyPairSync(type, options = {}) {
84
+ validateOneOf(type, "type", ["rsa", "ec", "ed25519", "x25519", "dh"]);
85
+ validateObject(options, "options");
86
+ let key;
87
+ if (type === "rsa") {
88
+ validateUint32(options.modulusLength, "options.modulusLength");
89
+ validateUint32(options.publicExponent ?? 65537, "options.publicExponent");
90
+ key = NativeKey.generate("RSA", options.modulusLength, undefined, options.publicExponent ?? 65537);
91
+ }
92
+ else if (type === "ec") {
93
+ validateString(options.namedCurve, "options.namedCurve");
94
+ validateOneOf(options.paramEncoding ?? "named", "options.paramEncoding", [
95
+ "named",
96
+ "explicit",
97
+ ]);
98
+ key = NativeKey.generate("EC", 0, options.namedCurve);
99
+ }
100
+ else if (type === "dh") {
101
+ const groups = {
102
+ modp1: "modp_768",
103
+ modp2: "modp_1024",
104
+ modp5: "modp_1536",
105
+ modp14: "modp_2048",
106
+ modp15: "modp_3072",
107
+ modp16: "modp_4096",
108
+ modp17: "modp_6144",
109
+ modp18: "modp_8192",
110
+ };
111
+ const group = options.group ?? options.groupName;
112
+ validateString(group, "options.group");
113
+ key = NativeKey.generate("DH", 0, groups[group] ?? group);
114
+ }
115
+ else
116
+ key = NativeKey.generate(type.toUpperCase());
117
+ const privateKey = create("private", { asymmetric: key });
118
+ const publicKey = createPublicKey(privateKey);
119
+ return {
120
+ publicKey: options.publicKeyEncoding
121
+ ? publicKey.export(options.publicKeyEncoding)
122
+ : publicKey,
123
+ privateKey: options.privateKeyEncoding
124
+ ? privateKey.export(options.privateKeyEncoding)
125
+ : privateKey,
126
+ };
127
+ }
128
+ export function generateKeyPair(type, options, callback) {
129
+ if (typeof options === "function") {
130
+ callback = options;
131
+ options = {};
132
+ }
133
+ validateFunction(callback, "callback");
134
+ let result, failure;
135
+ try {
136
+ result = generateKeyPairSync(type, options);
137
+ }
138
+ catch (error) {
139
+ failure = error;
140
+ }
141
+ queueMicrotask(() => failure
142
+ ? callback(failure)
143
+ : callback(null, result.publicKey, result.privateKey));
144
+ }
145
+ function optionsOf(value) {
146
+ return value &&
147
+ typeof value === "object" &&
148
+ !keyStates.has(value) &&
149
+ "key" in value
150
+ ? value
151
+ : { key: value };
152
+ }
153
+ function operationKey(value, privateKey) {
154
+ const key = optionsOf(value).key;
155
+ if (keyStates.has(key)) {
156
+ if (key.type === "secret" || (privateKey && key.type !== "private"))
157
+ throw new TypeError("Invalid key type");
158
+ return key;
159
+ }
160
+ return privateKey ? createPrivateKey(value) : createPublicKey(value);
161
+ }
162
+ function digestName(algorithm) {
163
+ if (algorithm == null)
164
+ return null;
165
+ validateString(algorithm, "algorithm");
166
+ return algorithm;
167
+ }
168
+ export function sign(algorithm, data, key, callback) {
169
+ if (callback !== undefined)
170
+ validateFunction(callback, "callback");
171
+ const digest = digestName(algorithm), raw = bytes(data, "data");
172
+ const execute = () => {
173
+ const options = optionsOf(key);
174
+ return Buffer.from(handle(operationKey(key, true)).sign(digest, raw, options.padding ?? 0, options.saltLength ?? -1, options.dsaEncoding === "ieee-p1363"));
175
+ };
176
+ if (callback === undefined)
177
+ return execute();
178
+ let result, failure;
179
+ try {
180
+ result = execute();
181
+ }
182
+ catch (error) {
183
+ failure = error;
184
+ }
185
+ queueMicrotask(() => callback(failure ?? null, result));
186
+ }
187
+ export function verify(algorithm, data, key, signature, callback) {
188
+ if (callback !== undefined)
189
+ validateFunction(callback, "callback");
190
+ const digest = digestName(algorithm), raw = bytes(data, "data"), sig = bytes(signature, "signature");
191
+ const execute = () => {
192
+ const options = optionsOf(key);
193
+ return handle(operationKey(key, false)).verify(digest, raw, sig, options.padding ?? 0, options.saltLength ?? -1, options.dsaEncoding === "ieee-p1363");
194
+ };
195
+ if (callback === undefined)
196
+ return execute();
197
+ let result, failure;
198
+ try {
199
+ result = execute();
200
+ }
201
+ catch (error) {
202
+ failure = error;
203
+ }
204
+ queueMicrotask(() => callback(failure ?? null, result));
205
+ }
206
+ export function diffieHellman(options) {
207
+ validateObject(options, "options");
208
+ const { publicKey, privateKey } = options;
209
+ if (!keyStates.has(publicKey))
210
+ throw new ERR_INVALID_ARG_TYPE("options.publicKey", "KeyObject", publicKey);
211
+ if (!keyStates.has(privateKey))
212
+ throw new ERR_INVALID_ARG_TYPE("options.privateKey", "KeyObject", privateKey);
213
+ if (publicKey.type !== "public")
214
+ throw new ERR_INVALID_ARG_TYPE("options.publicKey", "public key", publicKey);
215
+ if (privateKey.type !== "private")
216
+ throw new ERR_INVALID_ARG_TYPE("options.privateKey", "private key", privateKey);
217
+ if (publicKey.asymmetricKeyType !== privateKey.asymmetricKeyType)
218
+ throw new ERR_INVALID_ARG_VALUE("options.publicKey.asymmetricKeyType", publicKey.asymmetricKeyType, "must equal privateKey.asymmetricKeyType");
219
+ const publicHandle = handle(publicKey), privateHandle = handle(privateKey);
220
+ // The pinned workerd crypto-keys.c++ passes the public key as the first
221
+ // DHPointer::stateless argument. Preserve its observable failure rather than
222
+ // silently substituting standalone Node behavior.
223
+ try {
224
+ return Buffer.from(publicHandle.derive(privateHandle));
225
+ }
226
+ catch {
227
+ throw new Error("Failed to derive shared diffie-hellman secret");
228
+ }
229
+ }
230
+ export function timingSafeEqual(a, b) {
231
+ if (!(a instanceof ArrayBuffer) && !ArrayBuffer.isView(a))
232
+ throw new ERR_INVALID_ARG_TYPE("buf1", ["ArrayBuffer", "Buffer", "TypedArray", "DataView"], a);
233
+ if (!(b instanceof ArrayBuffer) && !ArrayBuffer.isView(b))
234
+ throw new ERR_INVALID_ARG_TYPE("buf2", ["ArrayBuffer", "Buffer", "TypedArray", "DataView"], b);
235
+ const left = bytes(a, "buf1"), right = bytes(b, "buf2");
236
+ if (left.length !== right.length)
237
+ throw Object.assign(new RangeError("Input buffers must have the same byte length"), { code: "ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH" });
238
+ return nativeTimingEqual(left, right);
239
+ }