The best way to control Claude Code, Codex and more from any computer or phone

main
ts 178 lines 4.53 KB
Raw
1 /**
2 * Browser layers for the `effect/crypto` modules.
3 *
4 * Every layer here runs the core WebCrypto layer of its family, so that browser
5 * programs take every crypto layer from `BrowserCrypto`. They use the
6 * `WebCrypto` reference, which defaults to the browser's `globalThis.crypto`. Layers
7 * that need `SecureRandom` get it from {@link layerSecureRandom}, so no layer
8 * here has requirements. {@link layer} provides every family at once; provide
9 * a family's own layer to pick services selectively.
10 *
11 * @stability unstable
12 * @since 1.0.0
13 */
14 import * as Aead from "effect/crypto/Aead"
15 import * as Cipher from "effect/crypto/Cipher"
16 import * as Digest from "effect/crypto/Digest"
17 import * as Kdf from "effect/crypto/Kdf"
18 import * as KeyAgreement from "effect/crypto/KeyAgreement"
19 import * as KeyWrap from "effect/crypto/KeyWrap"
20 import * as Mac from "effect/crypto/Mac"
21 import * as SecureRandom from "effect/crypto/SecureRandom"
22 import * as Signature from "effect/crypto/Signature"
23 import * as Layer from "effect/Layer"
24
25 /**
26 * Layer that provides `SecureRandom` on the `WebCrypto` reference.
27 *
28 * **Details**
29 *
30 * This is `SecureRandom.layerWebCrypto`, re-exported for browser programs.
31 *
32 * @stability unstable
33 * @category layers
34 * @since 4.0.0
35 */
36 export const layerSecureRandom: Layer.Layer<SecureRandom.SecureRandom> = SecureRandom.layerWebCrypto
37
38 /**
39 * Layer that provides `Digest` on the `WebCrypto` reference.
40 *
41 * **Details**
42 *
43 * This is `Digest.layerWebCrypto`, re-exported for browser programs.
44 *
45 * @stability unstable
46 * @category layers
47 * @since 4.0.0
48 */
49 export const layerDigest: Layer.Layer<Digest.Digest> = Digest.layerWebCrypto
50
51 /**
52 * Layer that provides `Mac` on the `WebCrypto` reference.
53 *
54 * **Details**
55 *
56 * This is `Mac.layerWebCrypto` with {@link layerSecureRandom}.
57 *
58 * @stability unstable
59 * @category layers
60 * @since 4.0.0
61 */
62 export const layerMac: Layer.Layer<Mac.Mac> = Mac.layerWebCrypto.pipe(Layer.provide(layerSecureRandom))
63
64 /**
65 * Layer that provides `Kdf` on the `WebCrypto` reference.
66 *
67 * **Details**
68 *
69 * This is `Kdf.layerWebCrypto`, re-exported for browser programs.
70 *
71 * @stability unstable
72 * @category layers
73 * @since 4.0.0
74 */
75 export const layerKdf: Layer.Layer<Kdf.Kdf> = Kdf.layerWebCrypto
76
77 /**
78 * Layer that provides `Aead` on the `WebCrypto` reference.
79 *
80 * **Details**
81 *
82 * This is `Aead.layerWebCrypto` with {@link layerSecureRandom}.
83 *
84 * @stability unstable
85 * @category layers
86 * @since 4.0.0
87 */
88 export const layerAead: Layer.Layer<Aead.Aead> = Aead.layerWebCrypto.pipe(Layer.provide(layerSecureRandom))
89
90 /**
91 * Layer that provides `Cipher` on the `WebCrypto` reference.
92 *
93 * **Details**
94 *
95 * This is `Cipher.layerWebCrypto` with {@link layerSecureRandom}.
96 *
97 * @stability unstable
98 * @category layers
99 * @since 4.0.0
100 */
101 export const layerCipher: Layer.Layer<Cipher.Cipher> = Cipher.layerWebCrypto.pipe(Layer.provide(layerSecureRandom))
102
103 /**
104 * Layer that provides `Signature` on the `WebCrypto` reference.
105 *
106 * **Details**
107 *
108 * This is `Signature.layerWebCrypto` with {@link layerSecureRandom}.
109 *
110 * @stability unstable
111 * @category layers
112 * @since 4.0.0
113 */
114 export const layerSignature: Layer.Layer<Signature.Signature> = Signature.layerWebCrypto.pipe(
115 Layer.provide(layerSecureRandom)
116 )
117
118 /**
119 * Layer that provides `KeyAgreement` on the `WebCrypto` reference.
120 *
121 * **Details**
122 *
123 * This is `KeyAgreement.layerWebCrypto` with {@link layerSecureRandom}.
124 *
125 * @stability unstable
126 * @category layers
127 * @since 4.0.0
128 */
129 export const layerKeyAgreement: Layer.Layer<KeyAgreement.KeyAgreement> = KeyAgreement.layerWebCrypto.pipe(
130 Layer.provide(layerSecureRandom)
131 )
132
133 /**
134 * Layer that provides `KeyWrap` on the `WebCrypto` reference.
135 *
136 * **Details**
137 *
138 * This is `KeyWrap.layerWebCrypto` with {@link layerSecureRandom}.
139 *
140 * @stability unstable
141 * @category layers
142 * @since 4.0.0
143 */
144 export const layerKeyWrap: Layer.Layer<KeyWrap.KeyWrap> = KeyWrap.layerWebCrypto.pipe(Layer.provide(layerSecureRandom))
145
146 /**
147 * Layer that provides every `effect/crypto` service on the `WebCrypto`
148 * reference.
149 *
150 * **Details**
151 *
152 * This merges the family layers of this module, so it requires nothing.
153 *
154 * @stability unstable
155 * @category layers
156 * @since 4.0.0
157 */
158 export const layer: Layer.Layer<
159 | SecureRandom.SecureRandom
160 | Digest.Digest
161 | Mac.Mac
162 | Kdf.Kdf
163 | Aead.Aead
164 | Cipher.Cipher
165 | Signature.Signature
166 | KeyAgreement.KeyAgreement
167 | KeyWrap.KeyWrap
168 > = Layer.mergeAll(
169 layerSecureRandom,
170 layerDigest,
171 layerMac,
172 layerKdf,
173 layerAead,
174 layerCipher,
175 layerSignature,
176 layerKeyAgreement,
177 layerKeyWrap
178 )