@yielded/crypto 0.0.0-stage → 0.1.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/THIRD_PARTY_NOTICES.md +378 -0
- package/dist/Aead.d.mts +34 -0
- package/dist/Aead.mjs +28 -0
- package/dist/Aead.mjs.map +1 -0
- package/dist/Errors.d.mts +20 -0
- package/dist/Errors.mjs +19 -0
- package/dist/Errors.mjs.map +1 -0
- package/dist/Hmac.d.mts +39 -0
- package/dist/Hmac.mjs +26 -0
- package/dist/Hmac.mjs.map +1 -0
- package/dist/Kdf.d.mts +54 -0
- package/dist/Kdf.mjs +78 -0
- package/dist/Kdf.mjs.map +1 -0
- package/dist/KdfAdmission.d.mts +24 -0
- package/dist/KdfAdmission.mjs +48 -0
- package/dist/KdfAdmission.mjs.map +1 -0
- package/dist/Portable.d.mts +11 -0
- package/dist/Portable.mjs +13 -0
- package/dist/Portable.mjs.map +1 -0
- package/dist/Signature.d.mts +70 -0
- package/dist/Signature.mjs +73 -0
- package/dist/Signature.mjs.map +1 -0
- package/dist/WebCrypto.d.mts +20 -0
- package/dist/WebCrypto.mjs +33 -0
- package/dist/WebCrypto.mjs.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +7 -0
- package/dist/internal/aead.mjs +81 -0
- package/dist/internal/aead.mjs.map +1 -0
- package/dist/internal/argon2-core.mjs +293 -0
- package/dist/internal/argon2-core.mjs.map +1 -0
- package/dist/internal/argon2.mjs +16 -0
- package/dist/internal/argon2.mjs.map +1 -0
- package/dist/internal/blake2b.mjs +359 -0
- package/dist/internal/blake2b.mjs.map +1 -0
- package/dist/internal/common.mjs +20 -0
- package/dist/internal/common.mjs.map +1 -0
- package/dist/internal/hmac.mjs +68 -0
- package/dist/internal/hmac.mjs.map +1 -0
- package/dist/internal/kdf.mjs +99 -0
- package/dist/internal/kdf.mjs.map +1 -0
- package/dist/internal/layer.mjs +26 -0
- package/dist/internal/layer.mjs.map +1 -0
- package/dist/internal/node.d.mts +11 -0
- package/dist/internal/node.mjs +34 -0
- package/dist/internal/node.mjs.map +1 -0
- package/dist/internal/poly1305.mjs +247 -0
- package/dist/internal/poly1305.mjs.map +1 -0
- package/dist/internal/signature.mjs +140 -0
- package/dist/internal/signature.mjs.map +1 -0
- package/dist/internal/word64.mjs +25 -0
- package/dist/internal/word64.mjs.map +1 -0
- package/dist/internal/xchacha-core.mjs +285 -0
- package/dist/internal/xchacha-core.mjs.map +1 -0
- package/dist/internal/xchacha.mjs +21 -0
- package/dist/internal/xchacha.mjs.map +1 -0
- package/dist/platform-bun.d.mts +2 -0
- package/dist/platform-bun.mjs +2 -0
- package/dist/platform-node.d.mts +2 -0
- package/dist/platform-node.mjs +2 -0
- package/package.json +1 -6
- package/src/Aead.ts +39 -0
- package/src/Errors.ts +27 -0
- package/src/Hmac.ts +41 -0
- package/src/Kdf.ts +87 -0
- package/src/KdfAdmission.ts +87 -0
- package/src/Portable.ts +8 -0
- package/src/Signature.ts +87 -0
- package/src/WebCrypto.ts +46 -0
- package/src/index.ts +6 -0
- package/src/internal/aead.ts +119 -0
- package/src/internal/argon2-core.ts +470 -0
- package/src/internal/argon2.ts +23 -0
- package/src/internal/blake2b.ts +230 -0
- package/src/internal/common.ts +44 -0
- package/src/internal/hmac.ts +111 -0
- package/src/internal/kdf.ts +150 -0
- package/src/internal/layer.ts +32 -0
- package/src/internal/node.ts +46 -0
- package/src/internal/poly1305.ts +289 -0
- package/src/internal/signature.ts +188 -0
- package/src/internal/word64.ts +48 -0
- package/src/internal/xchacha-core.ts +397 -0
- package/src/internal/xchacha.ts +26 -0
- package/src/platform-bun.ts +2 -0
- package/src/platform-node.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel van der Merwe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yielded/crypto
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Effect services for authenticated encryption, HMAC, key derivation and signatures.
|
|
4
|
+
Effect is its only runtime package dependency; it is independent of Auth.
|
|
5
|
+
Applications own keys, nonces, password
|
|
6
|
+
policy, envelopes and protocol formats. Use Effect `Crypto` for secure randomness
|
|
7
|
+
and SHA digests.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add @yielded/crypto@beta effect
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Import `Aead`, `Hmac`, `Kdf`, `KdfAdmission` and `Signature` from the root. Select
|
|
14
|
+
an implementation through a direct backend import:
|
|
15
|
+
|
|
16
|
+
- `/WebCrypto`: native operations from a supplied `SubtleCrypto`, plus named global
|
|
17
|
+
web adapters for Effect entropy/digests and HMAC.
|
|
18
|
+
- `/Portable`: WebCrypto plus owned Argon2id and XChaCha20-Poly1305 implementations.
|
|
19
|
+
- `/platform-node`, `/platform-bun`: shared Node-compatible WebCrypto and native
|
|
20
|
+
Argon2id, plus the owned XChaCha20-Poly1305 implementation.
|
|
21
|
+
|
|
22
|
+
Full backend Layers require one shared `KdfAdmission` Layer. The focused
|
|
23
|
+
`WebCrypto.layerHmac(subtle)` and global `layerWebCrypto` adapters need no KDF
|
|
24
|
+
admission. Waiting for derivation is bounded;
|
|
25
|
+
once admitted, derivation retains its permit until actual work and cleanup finish,
|
|
26
|
+
including interruption. Portable Argon2id yields through Effect between batches,
|
|
27
|
+
accepts interruption, and clears its work buffers before releasing admission. It
|
|
28
|
+
still runs on the calling thread. JavaScript cannot guarantee zeroization or
|
|
29
|
+
constant-time execution.
|
|
30
|
+
|
|
31
|
+
Secret inputs, derived bytes and decrypted plaintext use `Redacted`. Backend
|
|
32
|
+
errors contain classifications without native causes or secret payloads. Keep
|
|
33
|
+
each AEAD nonce unique for its key. `Hmac.importKey` snapshots a reusable,
|
|
34
|
+
nonextractable key in the caller's Scope; closure joins native work and prevents
|
|
35
|
+
further use. Signature operations use PKCS8/SPKI DER keys;
|
|
36
|
+
raw key components can be encoded through the native key parser.
|
|
37
|
+
[JOSE](../jose/README.md) and password-hash serialization belong to other layers.
|
|
38
|
+
|
|
39
|
+
See the [usage and supported profiles](../../docs/src/content/docs/reference/crypto.md)
|
|
40
|
+
and [third-party notices](THIRD_PARTY_NOTICES.md). The notices ship in this package.
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
`@yielded/crypto` uses native runtime capabilities and owned portable implementations
|
|
4
|
+
adapted from the sources below. Effect is its only runtime package dependency.
|
|
5
|
+
The Effect services, validation, admission, scheduling and backend integration are
|
|
6
|
+
Yielded code; the portable arithmetic retains its upstream attribution.
|
|
7
|
+
|
|
8
|
+
## Noble hashes and ciphers — MIT
|
|
9
|
+
|
|
10
|
+
Paul Miller and contributors, [noble-hashes](https://github.com/paulmillr/noble-hashes)
|
|
11
|
+
and [noble-ciphers](https://github.com/paulmillr/noble-ciphers).
|
|
12
|
+
|
|
13
|
+
- noble-hashes 2.3.0, revision `8060cc83bbab6681d23c9eed071db3f3a6b442da`:
|
|
14
|
+
`test/hmac.test.ts`, `test/kdf.test.ts`, `test/argon2.test.ts` influenced and
|
|
15
|
+
supplied selected known-answer/validation tests in `test/primitives.test.ts`,
|
|
16
|
+
`test/boundaries.test.ts`, and `test/vectors.ts`. All nine Argon2id v19 known
|
|
17
|
+
answers from `test/argon2.test.ts` are adapted in `test/argon2.test.ts` and
|
|
18
|
+
`test/fixtures/argon2-vectors.ts`; Argon2d, Argon2i and version 16 are excluded
|
|
19
|
+
because they are outside the supported API.
|
|
20
|
+
`src/argon2.ts`, `src/blake2.ts`, `src/_blake.ts`, and `src/_u64.ts` are adapted
|
|
21
|
+
into `src/internal/argon2-core.ts`, `blake2b.ts`, and `word64.ts`. The port retains
|
|
22
|
+
Argon2id v19 and its unkeyed BLAKE2b machinery, with per-derivation work buffers,
|
|
23
|
+
explicit little-endian encoding, and an Effect driver in `src/internal/argon2.ts`.
|
|
24
|
+
- noble-ciphers 2.1.1, revision `785181b0772ba84afbe812025714163e4e48262f`:
|
|
25
|
+
AEAD test behavior and independent vectors informed `test/primitives.test.ts`
|
|
26
|
+
and `test/vectors.ts`. `src/chacha.ts`, `src/_poly1305.ts`, and the stream/nonce
|
|
27
|
+
construction in `src/_arx.ts` are adapted into `src/internal/xchacha-core.ts`
|
|
28
|
+
and `poly1305.ts`. Only XChaCha20-Poly1305 is retained. The port uses owned work
|
|
29
|
+
buffers, authenticates before producing plaintext, and returns typed Effect
|
|
30
|
+
failures through `src/internal/xchacha.ts`.
|
|
31
|
+
|
|
32
|
+
The MIT notices below preserve both libraries' copyright holders. Noble's
|
|
33
|
+
cipher license also credits Thomas Pornin.
|
|
34
|
+
Noble's Poly1305 arithmetic derives from Andrew Moon's public-domain
|
|
35
|
+
[poly1305-donna](https://github.com/floodyberry/poly1305-donna/blob/e6ad6e091d30d7f4ec2d4f978be1fcfcbce72781/poly1305-donna-16.h).
|
|
36
|
+
|
|
37
|
+
## Project Wycheproof — Apache-2.0
|
|
38
|
+
|
|
39
|
+
Copyright 2016–2026 The Wycheproof Authors.
|
|
40
|
+
[Source revision](https://github.com/C2SP/wycheproof/tree/3fa63dd0344abb611f1fb1d77e119938603ea230).
|
|
41
|
+
|
|
42
|
+
`test/vectors.ts` contains selected, reformatted test data, with unused metadata
|
|
43
|
+
removed, from `testvectors_v1/aes_gcm_test.json` (tcId 91),
|
|
44
|
+
`ecdsa_secp256r1_sha256_p1363_test.json` (tcIds 64 and 11),
|
|
45
|
+
`rsa_pss_2048_sha256_mgf1_32_test.json` (tcId 1),
|
|
46
|
+
`rsa_pss_2048_sha256_mgf1_0_test.json` (tcId 1, valid generally but rejected by our
|
|
47
|
+
32-byte-salt profile), and `rsa_signature_2048_sha256_test.json` (tcIds 1 and 240).
|
|
48
|
+
These are test-data adaptations, not copied implementation. The Apache license
|
|
49
|
+
is reproduced below.
|
|
50
|
+
|
|
51
|
+
`test/fixtures/xchacha-vectors.ts` reformats all 315 cases from
|
|
52
|
+
`testvectors_v1/xchacha20_poly1305_test.json` at the same revision, retaining test
|
|
53
|
+
IDs, comments, flags and results. `test/xchacha.test.ts` adapts encryption,
|
|
54
|
+
decryption and rejection behavior through the public Effect service.
|
|
55
|
+
|
|
56
|
+
## Standards and independent results
|
|
57
|
+
|
|
58
|
+
Selected numerical vectors are reproduced in `test/vectors.ts` and exercised
|
|
59
|
+
through Effect services in `test/primitives.test.ts` and `test/signatures.test.ts`:
|
|
60
|
+
|
|
61
|
+
- RFC 2202 §3 (P. Cheng, R. Glenn), HMAC-SHA-1.
|
|
62
|
+
- RFC 4231 §4.2 (M. Nystrom), HMAC-SHA-256/384/512.
|
|
63
|
+
- RFC 5869 Appendix A.1 (H. Krawczyk, P. Eronen), HKDF-SHA-256.
|
|
64
|
+
- RFC 7914 §11 (C. Percival, S. Josefsson), PBKDF2-HMAC-SHA-256.
|
|
65
|
+
- RFC 9106 §5.3 (A. Biryukov, D. Dinu, D. Khovratovich, S. Josefsson),
|
|
66
|
+
Argon2id v19. Also cross-referenced by Noble to the Argon2 reference vector at
|
|
67
|
+
`P-H-C/phc-winner-argon2` revision `f57e61e19229e23c4445b85494dbf7c07de721cb`.
|
|
68
|
+
No reference implementation code is copied. The reference project credits
|
|
69
|
+
Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson and Samuel Neves (2015),
|
|
70
|
+
and offers CC0-1.0 or Apache-2.0; the selected vector is used under Apache-2.0.
|
|
71
|
+
- RFC 8032 §7.1, test 1 (S. Josefsson, I. Liusvaara), Ed25519.
|
|
72
|
+
- `draft-irtf-cfrg-xchacha-03`, Appendix A.3.1 (S. Arciszewski),
|
|
73
|
+
XChaCha20-Poly1305. This is an Internet-Draft vector, not a claim of RFC status.
|
|
74
|
+
|
|
75
|
+
RFC 2202: Copyright (C) The Internet Society (1997). All Rights Reserved.
|
|
76
|
+
RFC 4231: Copyright (C) The Internet Society (2005).
|
|
77
|
+
RFC 5869/7914/8032/9106 and the XChaCha draft: Copyright (c) 2010/2016/2017/2021/2020
|
|
78
|
+
IETF Trust and the persons identified as the document authors. All rights reserved.
|
|
79
|
+
The extracted numerical vectors are reformatted as TypeScript data; no RFC prose
|
|
80
|
+
or implementation pseudocode is copied. IETF Code Component terms are retained below.
|
|
81
|
+
|
|
82
|
+
A binary-password PBKDF2 fixture is independently calculated using Python's
|
|
83
|
+
`hashlib.pbkdf2_hmac`; no Python source is copied. Source URLs are retained beside
|
|
84
|
+
each vector. Additional binary-input, rounded-memory and variable-output Argon2id
|
|
85
|
+
fixtures in `test/fixtures/argon2-vectors.ts` were independently calculated with
|
|
86
|
+
Node's native `crypto.argon2Sync` before the portable implementation was adapted.
|
|
87
|
+
These attributions do not imply an upstream endorsement or transfer an upstream
|
|
88
|
+
security audit to the adapted implementation.
|
|
89
|
+
|
|
90
|
+
## License texts
|
|
91
|
+
|
|
92
|
+
### noble-hashes
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
The MIT License (MIT)
|
|
96
|
+
|
|
97
|
+
Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
98
|
+
|
|
99
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
100
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
101
|
+
in the Software without restriction, including without limitation the rights
|
|
102
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
103
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
104
|
+
furnished to do so, subject to the following conditions:
|
|
105
|
+
|
|
106
|
+
The above copyright notice and this permission notice shall be included in
|
|
107
|
+
all copies or substantial portions of the Software.
|
|
108
|
+
|
|
109
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
110
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
111
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
112
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
113
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
114
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
115
|
+
THE SOFTWARE.
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### noble-ciphers
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
The MIT License (MIT)
|
|
122
|
+
|
|
123
|
+
Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
124
|
+
Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
|
|
125
|
+
|
|
126
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
127
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
128
|
+
in the Software without restriction, including without limitation the rights
|
|
129
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
130
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
131
|
+
furnished to do so, subject to the following conditions:
|
|
132
|
+
|
|
133
|
+
The above copyright notice and this permission notice shall be included in
|
|
134
|
+
all copies or substantial portions of the Software.
|
|
135
|
+
|
|
136
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
137
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
138
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
139
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
140
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
141
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
142
|
+
THE SOFTWARE.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Apache License 2.0
|
|
146
|
+
|
|
147
|
+
```text
|
|
148
|
+
|
|
149
|
+
Apache License
|
|
150
|
+
Version 2.0, January 2004
|
|
151
|
+
http://www.apache.org/licenses/
|
|
152
|
+
|
|
153
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
154
|
+
|
|
155
|
+
1. Definitions.
|
|
156
|
+
|
|
157
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
158
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
159
|
+
|
|
160
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
161
|
+
the copyright owner that is granting the License.
|
|
162
|
+
|
|
163
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
164
|
+
other entities that control, are controlled by, or are under common
|
|
165
|
+
control with that entity. For the purposes of this definition,
|
|
166
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
167
|
+
direction or management of such entity, whether by contract or
|
|
168
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
169
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
170
|
+
|
|
171
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
172
|
+
exercising permissions granted by this License.
|
|
173
|
+
|
|
174
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
175
|
+
including but not limited to software source code, documentation
|
|
176
|
+
source, and configuration files.
|
|
177
|
+
|
|
178
|
+
"Object" form shall mean any form resulting from mechanical
|
|
179
|
+
transformation or translation of a Source form, including but
|
|
180
|
+
not limited to compiled object code, generated documentation,
|
|
181
|
+
and conversions to other media types.
|
|
182
|
+
|
|
183
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
184
|
+
Object form, made available under the License, as indicated by a
|
|
185
|
+
copyright notice that is included in or attached to the work
|
|
186
|
+
(an example is provided in the Appendix below).
|
|
187
|
+
|
|
188
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
189
|
+
form, that is based on (or derived from) the Work and for which the
|
|
190
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
191
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
192
|
+
of this License, Derivative Works shall not include works that remain
|
|
193
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
194
|
+
the Work and Derivative Works thereof.
|
|
195
|
+
|
|
196
|
+
"Contribution" shall mean any work of authorship, including
|
|
197
|
+
the original version of the Work and any modifications or additions
|
|
198
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
199
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
200
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
201
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
202
|
+
means any form of electronic, verbal, or written communication sent
|
|
203
|
+
to the Licensor or its representatives, including but not limited to
|
|
204
|
+
communication on electronic mailing lists, source code control systems,
|
|
205
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
206
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
207
|
+
excluding communication that is conspicuously marked or otherwise
|
|
208
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
209
|
+
|
|
210
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
211
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
212
|
+
subsequently incorporated within the Work.
|
|
213
|
+
|
|
214
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
215
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
216
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
217
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
218
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
219
|
+
Work and such Derivative Works in Source or Object form.
|
|
220
|
+
|
|
221
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
222
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
223
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
224
|
+
(except as stated in this section) patent license to make, have made,
|
|
225
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
226
|
+
where such license applies only to those patent claims licensable
|
|
227
|
+
by such Contributor that are necessarily infringed by their
|
|
228
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
229
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
230
|
+
institute patent litigation against any entity (including a
|
|
231
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
232
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
233
|
+
or contributory patent infringement, then any patent licenses
|
|
234
|
+
granted to You under this License for that Work shall terminate
|
|
235
|
+
as of the date such litigation is filed.
|
|
236
|
+
|
|
237
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
238
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
239
|
+
modifications, and in Source or Object form, provided that You
|
|
240
|
+
meet the following conditions:
|
|
241
|
+
|
|
242
|
+
(a) You must give any other recipients of the Work or
|
|
243
|
+
Derivative Works a copy of this License; and
|
|
244
|
+
|
|
245
|
+
(b) You must cause any modified files to carry prominent notices
|
|
246
|
+
stating that You changed the files; and
|
|
247
|
+
|
|
248
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
249
|
+
that You distribute, all copyright, patent, trademark, and
|
|
250
|
+
attribution notices from the Source form of the Work,
|
|
251
|
+
excluding those notices that do not pertain to any part of
|
|
252
|
+
the Derivative Works; and
|
|
253
|
+
|
|
254
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
255
|
+
distribution, then any Derivative Works that You distribute must
|
|
256
|
+
include a readable copy of the attribution notices contained
|
|
257
|
+
within such NOTICE file, excluding those notices that do not
|
|
258
|
+
pertain to any part of the Derivative Works, in at least one
|
|
259
|
+
of the following places: within a NOTICE text file distributed
|
|
260
|
+
as part of the Derivative Works; within the Source form or
|
|
261
|
+
documentation, if provided along with the Derivative Works; or,
|
|
262
|
+
within a display generated by the Derivative Works, if and
|
|
263
|
+
wherever such third-party notices normally appear. The contents
|
|
264
|
+
of the NOTICE file are for informational purposes only and
|
|
265
|
+
do not modify the License. You may add Your own attribution
|
|
266
|
+
notices within Derivative Works that You distribute, alongside
|
|
267
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
268
|
+
that such additional attribution notices cannot be construed
|
|
269
|
+
as modifying the License.
|
|
270
|
+
|
|
271
|
+
You may add Your own copyright statement to Your modifications and
|
|
272
|
+
may provide additional or different license terms and conditions
|
|
273
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
274
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
275
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
276
|
+
the conditions stated in this License.
|
|
277
|
+
|
|
278
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
279
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
280
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
281
|
+
this License, without any additional terms or conditions.
|
|
282
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
283
|
+
the terms of any separate license agreement you may have executed
|
|
284
|
+
with Licensor regarding such Contributions.
|
|
285
|
+
|
|
286
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
287
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
288
|
+
except as required for reasonable and customary use in describing the
|
|
289
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
290
|
+
|
|
291
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
292
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
293
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
294
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
295
|
+
implied, including, without limitation, any warranties or conditions
|
|
296
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
297
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
298
|
+
appropriateness of using or redistributing the Work and assume any
|
|
299
|
+
risks associated with Your exercise of permissions under this License.
|
|
300
|
+
|
|
301
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
302
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
303
|
+
unless required by applicable law (such as deliberate and grossly
|
|
304
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
305
|
+
liable to You for damages, including any direct, indirect, special,
|
|
306
|
+
incidental, or consequential damages of any character arising as a
|
|
307
|
+
result of this License or out of the use or inability to use the
|
|
308
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
309
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
310
|
+
other commercial damages or losses), even if such Contributor
|
|
311
|
+
has been advised of the possibility of such damages.
|
|
312
|
+
|
|
313
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
314
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
315
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
316
|
+
or other liability obligations and/or rights consistent with this
|
|
317
|
+
License. However, in accepting such obligations, You may act only
|
|
318
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
319
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
320
|
+
defend, and hold each Contributor harmless for any liability
|
|
321
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
322
|
+
of your accepting any such warranty or additional liability.
|
|
323
|
+
|
|
324
|
+
END OF TERMS AND CONDITIONS
|
|
325
|
+
|
|
326
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
327
|
+
|
|
328
|
+
To apply the Apache License to your work, attach the following
|
|
329
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
330
|
+
replaced with your own identifying information. (Don't include
|
|
331
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
332
|
+
comment syntax for the file format. We also recommend that a
|
|
333
|
+
file or class name and description of purpose be included on the
|
|
334
|
+
same "printed page" as the copyright notice for easier
|
|
335
|
+
identification within third-party archives.
|
|
336
|
+
|
|
337
|
+
Copyright [yyyy] [name of copyright owner]
|
|
338
|
+
|
|
339
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
340
|
+
you may not use this file except in compliance with the License.
|
|
341
|
+
You may obtain a copy of the License at
|
|
342
|
+
|
|
343
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
344
|
+
|
|
345
|
+
Unless required by applicable law or agreed to in writing, software
|
|
346
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
347
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
348
|
+
See the License for the specific language governing permissions and
|
|
349
|
+
limitations under the License.
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### IETF Code Components — Simplified BSD
|
|
353
|
+
|
|
354
|
+
```text
|
|
355
|
+
Copyright (c) IETF Trust and the persons identified as authors of the
|
|
356
|
+
referenced documents. All rights reserved.
|
|
357
|
+
|
|
358
|
+
Redistribution and use in source and binary forms, with or without
|
|
359
|
+
modification, are permitted provided that the following conditions are met:
|
|
360
|
+
|
|
361
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
362
|
+
this list of conditions and the following disclaimer.
|
|
363
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
364
|
+
this list of conditions and the following disclaimer in the documentation
|
|
365
|
+
and/or other materials provided with the distribution.
|
|
366
|
+
|
|
367
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
368
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
369
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
370
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
371
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
372
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
373
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
374
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
375
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
376
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
377
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
378
|
+
```
|
package/dist/Aead.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuthenticationFailed, OperationError } from "./Errors.mjs";
|
|
2
|
+
import { Context, Effect, Redacted, Schema } from "effect";
|
|
3
|
+
//#region src/Aead.d.ts
|
|
4
|
+
export declare const Algorithm: Schema.Literals<readonly ["AES-256-GCM", "XChaCha20-Poly1305"]>;
|
|
5
|
+
export type Algorithm = typeof Algorithm.Type;
|
|
6
|
+
export declare const EncryptInput: Schema.Struct<{
|
|
7
|
+
readonly algorithm: Schema.Literals<readonly ["AES-256-GCM", "XChaCha20-Poly1305"]>;
|
|
8
|
+
readonly key: Schema.Redacted<Schema.Uint8Array>;
|
|
9
|
+
readonly nonce: Schema.Uint8Array;
|
|
10
|
+
readonly additionalData: Schema.optionalKey<Schema.Uint8Array>;
|
|
11
|
+
readonly plaintext: Schema.Redacted<Schema.Uint8Array>;
|
|
12
|
+
}>;
|
|
13
|
+
export type EncryptInput = typeof EncryptInput.Type;
|
|
14
|
+
export declare const DecryptInput: Schema.Struct<{
|
|
15
|
+
readonly algorithm: Schema.Literals<readonly ["AES-256-GCM", "XChaCha20-Poly1305"]>;
|
|
16
|
+
readonly key: Schema.Redacted<Schema.Uint8Array>;
|
|
17
|
+
readonly nonce: Schema.Uint8Array;
|
|
18
|
+
readonly additionalData: Schema.optionalKey<Schema.Uint8Array>;
|
|
19
|
+
readonly ciphertext: Schema.Uint8Array;
|
|
20
|
+
}>;
|
|
21
|
+
export type DecryptInput = typeof DecryptInput.Type;
|
|
22
|
+
declare const Aead_base: Context.ServiceClass<Aead, "@yielded/crypto/Aead", {
|
|
23
|
+
readonly encrypt: (input: EncryptInput) => Effect.Effect<Uint8Array, OperationError>;
|
|
24
|
+
readonly decrypt: (input: DecryptInput) => Effect.Effect<Redacted.Redacted<Uint8Array>, OperationError | AuthenticationFailed>;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Both algorithms use a 32-byte key and append a 16-byte tag to ciphertext.
|
|
28
|
+
* AES-GCM uses a 12-byte nonce; XChaCha uses 24. The caller MUST supply a unique
|
|
29
|
+
* nonce for each encryption with a key. Obtain entropy from Effect Crypto.
|
|
30
|
+
* Envelope serialization and key selection belong to the caller.
|
|
31
|
+
*/
|
|
32
|
+
export declare class Aead extends Aead_base {}
|
|
33
|
+
//#endregion
|
|
34
|
+
//# sourceMappingURL=Aead.d.mts.map
|
package/dist/Aead.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Context, Schema } from "effect";
|
|
2
|
+
//#region src/Aead.ts
|
|
3
|
+
const Algorithm = Schema.Literals(["AES-256-GCM", "XChaCha20-Poly1305"]);
|
|
4
|
+
const context = {
|
|
5
|
+
algorithm: Algorithm,
|
|
6
|
+
key: Schema.Redacted(Schema.Uint8Array, { disallowJsonEncode: true }),
|
|
7
|
+
nonce: Schema.Uint8Array,
|
|
8
|
+
additionalData: Schema.optionalKey(Schema.Uint8Array)
|
|
9
|
+
};
|
|
10
|
+
const EncryptInput = Schema.Struct({
|
|
11
|
+
...context,
|
|
12
|
+
plaintext: Schema.Redacted(Schema.Uint8Array, { disallowJsonEncode: true })
|
|
13
|
+
});
|
|
14
|
+
const DecryptInput = Schema.Struct({
|
|
15
|
+
...context,
|
|
16
|
+
ciphertext: Schema.Uint8Array
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Both algorithms use a 32-byte key and append a 16-byte tag to ciphertext.
|
|
20
|
+
* AES-GCM uses a 12-byte nonce; XChaCha uses 24. The caller MUST supply a unique
|
|
21
|
+
* nonce for each encryption with a key. Obtain entropy from Effect Crypto.
|
|
22
|
+
* Envelope serialization and key selection belong to the caller.
|
|
23
|
+
*/
|
|
24
|
+
var Aead = class extends Context.Service()("@yielded/crypto/Aead") {};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Aead, Algorithm, DecryptInput, EncryptInput };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=Aead.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Aead.mjs","names":[],"sources":["../src/Aead.ts"],"sourcesContent":["import { Context, type Effect, type Redacted, Schema } from \"effect\";\n\nimport type { AuthenticationFailed, OperationError } from \"./Errors\";\n\nexport const Algorithm = Schema.Literals([\"AES-256-GCM\", \"XChaCha20-Poly1305\"]);\nexport type Algorithm = typeof Algorithm.Type;\n\nconst context = {\n algorithm: Algorithm,\n key: Schema.Redacted(Schema.Uint8Array, { disallowJsonEncode: true }),\n nonce: Schema.Uint8Array,\n additionalData: Schema.optionalKey(Schema.Uint8Array),\n};\n\nexport const EncryptInput = Schema.Struct({\n ...context,\n plaintext: Schema.Redacted(Schema.Uint8Array, { disallowJsonEncode: true }),\n});\n\nexport type EncryptInput = typeof EncryptInput.Type;\n\nexport const DecryptInput = Schema.Struct({ ...context, ciphertext: Schema.Uint8Array });\nexport type DecryptInput = typeof DecryptInput.Type;\n\n/**\n * Both algorithms use a 32-byte key and append a 16-byte tag to ciphertext.\n * AES-GCM uses a 12-byte nonce; XChaCha uses 24. The caller MUST supply a unique\n * nonce for each encryption with a key. Obtain entropy from Effect Crypto.\n * Envelope serialization and key selection belong to the caller.\n */\nexport class Aead extends Context.Service<\n Aead,\n {\n readonly encrypt: (input: EncryptInput) => Effect.Effect<Uint8Array, OperationError>;\n readonly decrypt: (\n input: DecryptInput,\n ) => Effect.Effect<Redacted.Redacted<Uint8Array>, OperationError | AuthenticationFailed>;\n }\n>()(\"@yielded/crypto/Aead\") {}\n"],"mappings":";;AAIA,MAAa,YAAY,OAAO,SAAS,CAAC,eAAe,oBAAoB,CAAC;AAG9E,MAAM,UAAU;CACd,WAAW;CACX,KAAK,OAAO,SAAS,OAAO,YAAY,EAAE,oBAAoB,KAAK,CAAC;CACpE,OAAO,OAAO;CACd,gBAAgB,OAAO,YAAY,OAAO,UAAU;AACtD;AAEA,MAAa,eAAe,OAAO,OAAO;CACxC,GAAG;CACH,WAAW,OAAO,SAAS,OAAO,YAAY,EAAE,oBAAoB,KAAK,CAAC;AAC5E,CAAC;AAID,MAAa,eAAe,OAAO,OAAO;CAAE,GAAG;CAAS,YAAY,OAAO;AAAW,CAAC;;;;;;;AASvF,IAAa,OAAb,cAA0B,QAAQ,QAQhC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/Errors.d.ts
|
|
3
|
+
declare const InvalidInput_base: Schema.Class<InvalidInput, Schema.TaggedStruct<"CryptoInvalidInput", {
|
|
4
|
+
readonly reason: Schema.Literals<readonly ["key", "nonce", "parameters", "data"]>;
|
|
5
|
+
}>, import("effect/Cause").YieldableError>;
|
|
6
|
+
/** Diagnostics contain only fixed classifications, never native causes or input. */
|
|
7
|
+
export declare class InvalidInput extends InvalidInput_base {}
|
|
8
|
+
declare const UnsupportedAlgorithm_base: Schema.Class<UnsupportedAlgorithm, Schema.TaggedStruct<"CryptoUnsupportedAlgorithm", {}>, import("effect/Cause").YieldableError>;
|
|
9
|
+
export declare class UnsupportedAlgorithm extends UnsupportedAlgorithm_base {}
|
|
10
|
+
declare const CryptoUnavailable_base: Schema.Class<CryptoUnavailable, Schema.TaggedStruct<"CryptoUnavailable", {}>, import("effect/Cause").YieldableError>;
|
|
11
|
+
/** A native backend failed without a more specific classification. */
|
|
12
|
+
export declare class CryptoUnavailable extends CryptoUnavailable_base {}
|
|
13
|
+
declare const AuthenticationFailed_base: Schema.Class<AuthenticationFailed, Schema.TaggedStruct<"CryptoAuthenticationFailed", {}>, import("effect/Cause").YieldableError>;
|
|
14
|
+
/** An authenticated decryption rejected the supplied ciphertext or context. */
|
|
15
|
+
export declare class AuthenticationFailed extends AuthenticationFailed_base {}
|
|
16
|
+
declare const KdfBusy_base: Schema.Class<KdfBusy, Schema.TaggedStruct<"CryptoKdfBusy", {}>, import("effect/Cause").YieldableError>;
|
|
17
|
+
export declare class KdfBusy extends KdfBusy_base {}
|
|
18
|
+
export type OperationError = InvalidInput | UnsupportedAlgorithm | CryptoUnavailable;
|
|
19
|
+
//#endregion
|
|
20
|
+
//# sourceMappingURL=Errors.d.mts.map
|
package/dist/Errors.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/Errors.ts
|
|
3
|
+
/** Diagnostics contain only fixed classifications, never native causes or input. */
|
|
4
|
+
var InvalidInput = class extends Schema.TaggedError()("CryptoInvalidInput", { reason: Schema.Literals([
|
|
5
|
+
"key",
|
|
6
|
+
"nonce",
|
|
7
|
+
"parameters",
|
|
8
|
+
"data"
|
|
9
|
+
]) }) {};
|
|
10
|
+
var UnsupportedAlgorithm = class extends Schema.TaggedError()("CryptoUnsupportedAlgorithm", {}) {};
|
|
11
|
+
/** A native backend failed without a more specific classification. */
|
|
12
|
+
var CryptoUnavailable = class extends Schema.TaggedError()("CryptoUnavailable", {}) {};
|
|
13
|
+
/** An authenticated decryption rejected the supplied ciphertext or context. */
|
|
14
|
+
var AuthenticationFailed = class extends Schema.TaggedError()("CryptoAuthenticationFailed", {}) {};
|
|
15
|
+
var KdfBusy = class extends Schema.TaggedError()("CryptoKdfBusy", {}) {};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AuthenticationFailed, CryptoUnavailable, InvalidInput, KdfBusy, UnsupportedAlgorithm };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=Errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.mjs","names":[],"sources":["../src/Errors.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n/** Diagnostics contain only fixed classifications, never native causes or input. */\nexport class InvalidInput extends Schema.TaggedError<InvalidInput>()(\"CryptoInvalidInput\", {\n reason: Schema.Literals([\"key\", \"nonce\", \"parameters\", \"data\"]),\n}) {}\n\nexport class UnsupportedAlgorithm extends Schema.TaggedError<UnsupportedAlgorithm>()(\n \"CryptoUnsupportedAlgorithm\",\n {},\n) {}\n\n/** A native backend failed without a more specific classification. */\nexport class CryptoUnavailable extends Schema.TaggedError<CryptoUnavailable>()(\n \"CryptoUnavailable\",\n {},\n) {}\n\n/** An authenticated decryption rejected the supplied ciphertext or context. */\nexport class AuthenticationFailed extends Schema.TaggedError<AuthenticationFailed>()(\n \"CryptoAuthenticationFailed\",\n {},\n) {}\n\nexport class KdfBusy extends Schema.TaggedError<KdfBusy>()(\"CryptoKdfBusy\", {}) {}\n\nexport type OperationError = InvalidInput | UnsupportedAlgorithm | CryptoUnavailable;\n"],"mappings":";;;AAGA,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CAAC,sBAAsB,EACzF,QAAQ,OAAO,SAAS;CAAC;CAAO;CAAS;CAAc;AAAM,CAAC,EAChE,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAClF,8BACA,CAAC,CACH,CAAC,CAAC,CAAC;;AAGH,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA,CAAC,CACH,CAAC,CAAC,CAAC;;AAGH,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAClF,8BACA,CAAC,CACH,CAAC,CAAC,CAAC;AAEH,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/Hmac.d.mts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OperationError } from "./Errors.mjs";
|
|
2
|
+
import { Context, Effect, Schema, Scope } from "effect";
|
|
3
|
+
//#region src/Hmac.d.ts
|
|
4
|
+
/** SHA-1 exists for interoperability with TOTP, not new signature designs. */
|
|
5
|
+
export declare const Algorithm: Schema.Literals<readonly ["SHA-1", "SHA-256", "SHA-384", "SHA-512"]>;
|
|
6
|
+
export type Algorithm = typeof Algorithm.Type;
|
|
7
|
+
export declare const KeyInput: Schema.Struct<{
|
|
8
|
+
readonly algorithm: Schema.Literals<readonly ["SHA-1", "SHA-256", "SHA-384", "SHA-512"]>;
|
|
9
|
+
readonly key: Schema.Redacted<Schema.Uint8Array>;
|
|
10
|
+
}>;
|
|
11
|
+
export type KeyInput = typeof KeyInput.Type;
|
|
12
|
+
export declare const Input: Schema.Struct<{
|
|
13
|
+
readonly algorithm: Schema.Literals<readonly ["SHA-1", "SHA-256", "SHA-384", "SHA-512"]>;
|
|
14
|
+
readonly key: Schema.Redacted<Schema.Uint8Array>;
|
|
15
|
+
readonly data: Schema.Uint8Array;
|
|
16
|
+
}>;
|
|
17
|
+
export type Input = typeof Input.Type;
|
|
18
|
+
export declare const VerifyInput: Schema.Struct<{
|
|
19
|
+
readonly algorithm: Schema.Literals<readonly ["SHA-1", "SHA-256", "SHA-384", "SHA-512"]>;
|
|
20
|
+
readonly key: Schema.Redacted<Schema.Uint8Array>;
|
|
21
|
+
readonly data: Schema.Uint8Array;
|
|
22
|
+
readonly tag: Schema.Uint8Array;
|
|
23
|
+
}>;
|
|
24
|
+
export type VerifyInput = typeof VerifyInput.Type;
|
|
25
|
+
/** An imported, nonextractable key, usable only while its owning Scope is open. */
|
|
26
|
+
export interface Key {
|
|
27
|
+
readonly sign: (data: Uint8Array) => Effect.Effect<Uint8Array, OperationError>;
|
|
28
|
+
readonly verify: (data: Uint8Array, tag: Uint8Array) => Effect.Effect<boolean, OperationError>;
|
|
29
|
+
}
|
|
30
|
+
declare const Hmac_base: Context.ServiceClass<Hmac, "@yielded/crypto/Hmac", {
|
|
31
|
+
/** Snapshot and validate once. Closing the Scope joins native work and releases the key. */
|
|
32
|
+
readonly importKey: (input: KeyInput) => Effect.Effect<Key, OperationError, Scope.Scope>;
|
|
33
|
+
readonly sign: (input: Input) => Effect.Effect<Uint8Array, OperationError>;
|
|
34
|
+
/** A wrong tag is false; a key or backend failure stays in the error channel. */
|
|
35
|
+
readonly verify: (input: VerifyInput) => Effect.Effect<boolean, OperationError>;
|
|
36
|
+
}>;
|
|
37
|
+
export declare class Hmac extends Hmac_base {}
|
|
38
|
+
//#endregion
|
|
39
|
+
//# sourceMappingURL=Hmac.d.mts.map
|
package/dist/Hmac.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context, Schema } from "effect";
|
|
2
|
+
//#region src/Hmac.ts
|
|
3
|
+
/** SHA-1 exists for interoperability with TOTP, not new signature designs. */
|
|
4
|
+
const Algorithm = Schema.Literals([
|
|
5
|
+
"SHA-1",
|
|
6
|
+
"SHA-256",
|
|
7
|
+
"SHA-384",
|
|
8
|
+
"SHA-512"
|
|
9
|
+
]);
|
|
10
|
+
const KeyInput = Schema.Struct({
|
|
11
|
+
algorithm: Algorithm,
|
|
12
|
+
key: Schema.Redacted(Schema.Uint8Array, { disallowJsonEncode: true })
|
|
13
|
+
});
|
|
14
|
+
const Input = Schema.Struct({
|
|
15
|
+
...KeyInput.fields,
|
|
16
|
+
data: Schema.Uint8Array
|
|
17
|
+
});
|
|
18
|
+
const VerifyInput = Schema.Struct({
|
|
19
|
+
...Input.fields,
|
|
20
|
+
tag: Schema.Uint8Array
|
|
21
|
+
});
|
|
22
|
+
var Hmac = class extends Context.Service()("@yielded/crypto/Hmac") {};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Algorithm, Hmac, Input, KeyInput, VerifyInput };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=Hmac.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hmac.mjs","names":[],"sources":["../src/Hmac.ts"],"sourcesContent":["import { Context, type Effect, Schema, type Scope } from \"effect\";\n\nimport type { OperationError } from \"./Errors\";\n\n/** SHA-1 exists for interoperability with TOTP, not new signature designs. */\nexport const Algorithm = Schema.Literals([\"SHA-1\", \"SHA-256\", \"SHA-384\", \"SHA-512\"]);\nexport type Algorithm = typeof Algorithm.Type;\n\nexport const KeyInput = Schema.Struct({\n algorithm: Algorithm,\n key: Schema.Redacted(Schema.Uint8Array, { disallowJsonEncode: true }),\n});\n\nexport type KeyInput = typeof KeyInput.Type;\n\nexport const Input = Schema.Struct({\n ...KeyInput.fields,\n data: Schema.Uint8Array,\n});\n\nexport type Input = typeof Input.Type;\n\nexport const VerifyInput = Schema.Struct({ ...Input.fields, tag: Schema.Uint8Array });\nexport type VerifyInput = typeof VerifyInput.Type;\n\n/** An imported, nonextractable key, usable only while its owning Scope is open. */\nexport interface Key {\n readonly sign: (data: Uint8Array) => Effect.Effect<Uint8Array, OperationError>;\n readonly verify: (data: Uint8Array, tag: Uint8Array) => Effect.Effect<boolean, OperationError>;\n}\n\nexport class Hmac extends Context.Service<\n Hmac,\n {\n /** Snapshot and validate once. Closing the Scope joins native work and releases the key. */\n readonly importKey: (input: KeyInput) => Effect.Effect<Key, OperationError, Scope.Scope>;\n readonly sign: (input: Input) => Effect.Effect<Uint8Array, OperationError>;\n /** A wrong tag is false; a key or backend failure stays in the error channel. */\n readonly verify: (input: VerifyInput) => Effect.Effect<boolean, OperationError>;\n }\n>()(\"@yielded/crypto/Hmac\") {}\n"],"mappings":";;;AAKA,MAAa,YAAY,OAAO,SAAS;CAAC;CAAS;CAAW;CAAW;AAAS,CAAC;AAGnF,MAAa,WAAW,OAAO,OAAO;CACpC,WAAW;CACX,KAAK,OAAO,SAAS,OAAO,YAAY,EAAE,oBAAoB,KAAK,CAAC;AACtE,CAAC;AAID,MAAa,QAAQ,OAAO,OAAO;CACjC,GAAG,SAAS;CACZ,MAAM,OAAO;AACf,CAAC;AAID,MAAa,cAAc,OAAO,OAAO;CAAE,GAAG,MAAM;CAAQ,KAAK,OAAO;AAAW,CAAC;AASpF,IAAa,OAAb,cAA0B,QAAQ,QAShC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC"}
|