@shieldfive/crypto 1.0.0-alpha.9 → 1.0.0-beta.2
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/CHANGELOG.md +157 -0
- package/README.md +32 -15
- package/SECURITY.md +1 -1
- package/dist/identity/index.d.ts +16 -0
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +84 -22
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/sign.d.ts +92 -0
- package/dist/identity/sign.d.ts.map +1 -0
- package/dist/identity/sign.js +182 -0
- package/dist/identity/sign.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/encoding.d.ts.map +1 -1
- package/dist/internal/encoding.js +0 -1
- package/dist/internal/encoding.js.map +1 -1
- package/dist/internal/types.d.ts +4 -1
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/internal/types.js +8 -0
- package/dist/internal/types.js.map +1 -1
- package/dist/streams/aes-gcm-v1.d.ts +71 -3
- package/dist/streams/aes-gcm-v1.d.ts.map +1 -1
- package/dist/streams/aes-gcm-v1.js +192 -50
- package/dist/streams/aes-gcm-v1.js.map +1 -1
- package/dist/streams/pq-hybrid-v1.d.ts +34 -3
- package/dist/streams/pq-hybrid-v1.d.ts.map +1 -1
- package/dist/streams/pq-hybrid-v1.js +126 -50
- package/dist/streams/pq-hybrid-v1.js.map +1 -1
- package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v1/api.js +1 -1
- package/dist/suites/aes-gcm-v1/api.js.map +1 -1
- package/dist/suites/aes-gcm-v1/index.d.ts +3 -0
- package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v1/index.js +3 -0
- package/dist/suites/aes-gcm-v1/index.js.map +1 -1
- package/dist/suites/aes-gcm-v2/api.d.ts +44 -0
- package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/api.js +162 -0
- package/dist/suites/aes-gcm-v2/api.js.map +1 -0
- package/dist/suites/aes-gcm-v2/index.d.ts +63 -0
- package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/index.js +193 -0
- package/dist/suites/aes-gcm-v2/index.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts +4 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts.map +1 -1
- package/dist/suites/pq-hybrid-v1/index.js +15 -1
- package/dist/suites/pq-hybrid-v1/index.js.map +1 -1
- package/package.json +12 -2
- package/spec/format-v1.md +200 -7
- package/spec/key-derivation.md +18 -2
- package/spec/threat-model.md +36 -21
- package/src/identity/index.ts +107 -28
- package/src/identity/sign.ts +221 -0
- package/src/index.ts +32 -5
- package/src/internal/encoding.ts +0 -1
- package/src/internal/types.ts +9 -0
- package/src/streams/aes-gcm-v1.ts +275 -59
- package/src/streams/pq-hybrid-v1.ts +182 -59
- package/src/suites/aes-gcm-v1/api.ts +0 -1
- package/src/suites/aes-gcm-v1/index.ts +3 -0
- package/src/suites/aes-gcm-v2/api.ts +268 -0
- package/src/suites/aes-gcm-v2/index.ts +289 -0
- package/src/suites/pq-hybrid-v1/index.ts +25 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,163 @@ All notable changes to `@shieldfive/crypto` will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 1.0.0-beta.2 — 2026-07-02
|
|
9
|
+
|
|
10
|
+
> Reader-consistency hardening for the streaming decrypt paths. The two
|
|
11
|
+
> streaming decryptors now enforce the same `suite_payload` structure their
|
|
12
|
+
> whole-blob and KEM counterparts already require, so every reader mode of a
|
|
13
|
+
> suite agrees on what a well-formed file is. No wire-format, key-derivation,
|
|
14
|
+
> or public-API change: files produced by earlier versions decrypt identically
|
|
15
|
+
> in every mode, and all prior test vectors are unchanged.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **`0x03` PQ-hybrid stream, combined-key mode** now rejects a header whose
|
|
20
|
+
24-byte reserved `classical_wrapped` pad is non-zero (M6, `spec/format-v1.md`
|
|
21
|
+
§ `0x03`), matching `parsePqHybridV1SuitePayload`, `decryptBlob`, and the KEM
|
|
22
|
+
stream path. The combined-key reader previously skipped this structural check.
|
|
23
|
+
- **`0x01` AES-GCM stream** now rejects a `suite_payload` whose length is not
|
|
24
|
+
72 bytes, matching `parseAesGcmV1SuitePayload` and `decryptBlob`.
|
|
25
|
+
- Both streaming **encryptors** now reject a malformed caller-supplied
|
|
26
|
+
`suite_payload`, so the library never emits a file its own readers refuse.
|
|
27
|
+
|
|
28
|
+
### Security
|
|
29
|
+
|
|
30
|
+
- These are canonical-parsing / reader-consistency fixes, **not** a
|
|
31
|
+
confidentiality or integrity break. `suite_payload` is covered by the header
|
|
32
|
+
MAC, so an accepted malformed file already required the content/combined key;
|
|
33
|
+
no forgery, key-recovery, or plaintext-recovery vector was present. Reported
|
|
34
|
+
by avaragebughunter@gmail.com.
|
|
35
|
+
|
|
36
|
+
## 1.0.0-beta.1 — 2026-06-19
|
|
37
|
+
|
|
38
|
+
> Promotes the library from alpha to **beta**. There are no functional,
|
|
39
|
+
> cryptographic, or wire-format changes since `1.0.0-alpha.14`; this release
|
|
40
|
+
> records that the v1 on-disk format and the public TypeScript API are now
|
|
41
|
+
> considered stable enough to leave alpha. `1.0.0` stable remains gated on
|
|
42
|
+
> the planned external third-party audit.
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- **Status: alpha → beta.** The `0x03` PQ-hybrid share-bundle hardening
|
|
47
|
+
(audit findings H2/M6, doc M5) shipped in `1.0.0-alpha.14` and is unchanged
|
|
48
|
+
here. The wire format stays frozen; existing `cipher_version-3` files and
|
|
49
|
+
hardened (`SF5S` v2) share bundles remain valid.
|
|
50
|
+
- `SHIELDFIVE_CRYPTO_VERSION`, the status badge, the README/SECURITY status
|
|
51
|
+
notes, and the example decryptor updated to `1.0.0-beta.1`.
|
|
52
|
+
|
|
53
|
+
### Notes
|
|
54
|
+
|
|
55
|
+
- Beta means the v1 wire format is frozen and the public API is stable; minor,
|
|
56
|
+
backward-compatible API additions remain possible before `1.0.0` stable, but
|
|
57
|
+
breaking changes are not planned.
|
|
58
|
+
- This is **not** a security release — no vulnerabilities were fixed between
|
|
59
|
+
`1.0.0-alpha.14` and `1.0.0-beta.1`. The library has still **not** had an
|
|
60
|
+
external cryptographic audit.
|
|
61
|
+
|
|
62
|
+
## 1.0.0-alpha.14 — 2026-06-10
|
|
63
|
+
|
|
64
|
+
> Pre-launch security hardening of the `0x03` PQ-hybrid share bundle. The
|
|
65
|
+
> share-bundle wire format changes; the on-disk file format and the `0x03`
|
|
66
|
+
> file decryption path are unchanged, so existing `cipher_version-3` files
|
|
67
|
+
> remain decryptable.
|
|
68
|
+
|
|
69
|
+
### Changed (BREAKING — share-bundle wire format only)
|
|
70
|
+
|
|
71
|
+
- **Share bundle (`0x03`) re-keyed and versioned (audit H2).** The share
|
|
72
|
+
transport key is now derived from the KEM/envelope secret under a dedicated
|
|
73
|
+
HKDF label `shieldfive/v1/share-transport` instead of reusing the
|
|
74
|
+
file-combiner label `shieldfive/v1/pq-hybrid/combine`, so a share transport
|
|
75
|
+
key can never equal a file's combined key. The combined key is now wrapped
|
|
76
|
+
with XChaCha20-Poly1305 whose AAD authenticates the **whole** bundle
|
|
77
|
+
(`magic || uint32_be(pq_len) || pq_payload || wrap_nonce`) rather than an
|
|
78
|
+
AAD-less secretbox that authenticated only the 32-byte key — PQ material
|
|
79
|
+
can no longer be substituted or stripped undetected. The bundle now carries
|
|
80
|
+
a `"SF5S"` + version-2 magic prefix so the hardened format is
|
|
81
|
+
distinguishable from (and not confusable with) the earlier unversioned one.
|
|
82
|
+
Share bundles produced by earlier alpha builds are rejected and must be
|
|
83
|
+
re-issued; no real shares exist pre-launch, so this is a clean break. See
|
|
84
|
+
`spec/format-v1.md` § "Share bundle".
|
|
85
|
+
|
|
86
|
+
### Security
|
|
87
|
+
|
|
88
|
+
- **Reserved-pad enforcement (`0x03`, audit M6).** The `0x03` suite-payload
|
|
89
|
+
parser now rejects a non-zero reserved pad in `classical_wrapped` (the 24
|
|
90
|
+
bytes after the 48-byte secretbox), closing a malleable unauthenticated
|
|
91
|
+
field. The default suite combine label and file path are unchanged.
|
|
92
|
+
|
|
93
|
+
### Documentation
|
|
94
|
+
|
|
95
|
+
- README/spec: corrected the "cross-file splice prevention (file_id AAD)"
|
|
96
|
+
table cell and prose — `file_id` is NOT in the chunk AAD; splice resistance
|
|
97
|
+
is structural via `file_id` as the HKDF salt in the chunk-key derivation
|
|
98
|
+
(audit INFO). Noted that the "no parallel implementation" scope is the
|
|
99
|
+
file-content cipher suites; the keyring/envelope layer uses WebCrypto
|
|
100
|
+
AES-GCM/HMAC directly.
|
|
101
|
+
- **Planned (not in this release): suite-id binding in `0x03` chunk derivation
|
|
102
|
+
(audit M5).** The `0x03` chunk-key / nonce-prefix derivations reuse the
|
|
103
|
+
`0x02` xchacha HKDF labels and do not bind the suite id. This is **not
|
|
104
|
+
exploitable** (the header MAC authenticates the suite byte) and is left
|
|
105
|
+
**unchanged** — production `cipher_version-3` files depend on it and would
|
|
106
|
+
become undecryptable if altered. A future suite version (a new suite id,
|
|
107
|
+
not `0x03`) will bind the suite id into the chunk derivation. Recorded in
|
|
108
|
+
`spec/format-v1.md` and `spec/key-derivation.md`.
|
|
109
|
+
|
|
110
|
+
### Tests
|
|
111
|
+
|
|
112
|
+
- Added share-bundle PQ-substitution/forgery, dedicated-transport-key,
|
|
113
|
+
non-zero reserved-pad rejection, and share-bundle version-marker tests
|
|
114
|
+
(182 → 188 passing).
|
|
115
|
+
|
|
116
|
+
## 1.0.0-alpha.13 — 2026-06-09
|
|
117
|
+
|
|
118
|
+
### Fixed
|
|
119
|
+
|
|
120
|
+
- `SHIELDFIVE_CRYPTO_VERSION` now reports the actual package version
|
|
121
|
+
(it was pinned at `1.0.0-alpha.11`). The constant is informational
|
|
122
|
+
only — it is never written into file output or any test vector.
|
|
123
|
+
- Corrected a backwards source comment in the `aes-gcm-v2` suite: the
|
|
124
|
+
cross-file nonce-prefix space *widens* from 2^32 to 2^64 (the comment
|
|
125
|
+
previously said "shrinks"). No behavior change — the README and
|
|
126
|
+
CHANGELOG already described it correctly as widening.
|
|
127
|
+
|
|
128
|
+
## 1.0.0-alpha.12 — 2026-06-09
|
|
129
|
+
|
|
130
|
+
### Documentation
|
|
131
|
+
|
|
132
|
+
- README: corrected the test-suite badge and prose from 171 to
|
|
133
|
+
**182** tests. The 11 additional tests are the offline single-file
|
|
134
|
+
decryptor example suite that landed after the badge was last
|
|
135
|
+
refreshed; `npm test` now reports 182/182.
|
|
136
|
+
- README: the cipher-suite table and the "four suites" wording now
|
|
137
|
+
match the package exports. Suite 0x04 `aes-gcm-v2` shipped in
|
|
138
|
+
alpha.11 but the README published with that release still listed
|
|
139
|
+
only three suites.
|
|
140
|
+
- No source changes in this release — documentation only.
|
|
141
|
+
|
|
142
|
+
## 1.0.0-alpha.11 — 2026-05-21
|
|
143
|
+
|
|
144
|
+
### Added
|
|
145
|
+
|
|
146
|
+
- Cipher suite 0x04 `aes-gcm-v2`: 8-byte HKDF-derived nonce prefix
|
|
147
|
+
+ 4-byte BE chunk counter. Widens the cross-file IV-collision
|
|
148
|
+
space from 2^32 to 2^64 while keeping the IV at 12 bytes. v1
|
|
149
|
+
(suite 0x01) stays decrypt-only on the umbrella export.
|
|
150
|
+
- Optional sender-attribution signatures (`src/identity/sign.ts`).
|
|
151
|
+
Detached Ed25519 (alg 0x01) over
|
|
152
|
+
`header_unauthenticated_bytes || concat(chunk_macs)`, appended as
|
|
153
|
+
a trailing signature block. Legacy files without the block keep
|
|
154
|
+
decrypting unchanged; the streaming API returns
|
|
155
|
+
`{signature: null}` in that case. Algorithm 0x02 is reserved for
|
|
156
|
+
ML-DSA-65.
|
|
157
|
+
|
|
158
|
+
### Notes
|
|
159
|
+
|
|
160
|
+
- Default cipher suite is still PQ-hybrid
|
|
161
|
+
(`SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1`). aes-gcm-v2 is opt-in
|
|
162
|
+
via the dedicated subpath import.
|
|
163
|
+
- Wire format updates documented in `spec/format-v1.md`.
|
|
164
|
+
|
|
8
165
|
## [1.0.0-alpha.9] — 2026-05
|
|
9
166
|
|
|
10
167
|
### Documentation
|
package/README.md
CHANGED
|
@@ -5,24 +5,29 @@
|
|
|
5
5
|
> [ShieldFive](https://shieldfive.com), released as a standalone library.
|
|
6
6
|
|
|
7
7
|
[](LICENSE)
|
|
8
|
-
[](tests/)
|
|
9
|
+
[](#status)
|
|
10
10
|
|
|
11
11
|
## Status & honest scope
|
|
12
12
|
|
|
13
|
-
This library is **
|
|
13
|
+
This library is **beta**. The wire format is frozen for the v1 release;
|
|
14
14
|
the public TypeScript API may make minor adjustments before v1.0.0 stable.
|
|
15
15
|
It has **not** undergone external cryptographic audit. Until it does,
|
|
16
16
|
treat this library as a serious work-in-progress rather than a finished
|
|
17
17
|
product.
|
|
18
18
|
|
|
19
19
|
The design choices documented in [`spec/`](spec/) are deliberate and
|
|
20
|
-
reviewable. The implementation is covered by
|
|
20
|
+
reviewable. The implementation is covered by 188 passing tests including
|
|
21
21
|
truncation, reordering, splice, and tampering detection across all four
|
|
22
22
|
suites. That is enough for internal dogfooding. It is **not** enough to
|
|
23
23
|
claim "most secure crypto library" — that claim requires external review
|
|
24
24
|
this library has not yet received.
|
|
25
25
|
|
|
26
|
+
When this library says it avoids a parallel cryptographic implementation,
|
|
27
|
+
that scope is the file-content cipher suites. The keyring/envelope layer
|
|
28
|
+
that wraps content keys is built directly on WebCrypto AES-GCM and HMAC
|
|
29
|
+
(via `crypto.subtle`), not on a second hand-rolled implementation.
|
|
30
|
+
|
|
26
31
|
## Design positions
|
|
27
32
|
|
|
28
33
|
This library makes specific design choices that differ from existing
|
|
@@ -37,7 +42,7 @@ spec section that documents the choice.
|
|
|
37
42
|
| Self-describing on-disk file format | ✅ | ✅ | ⚠️ | ⚠️ |
|
|
38
43
|
| Cipher-suite agile (one byte selects) | ✅ | ⚠️ | ❌ | ❌ |
|
|
39
44
|
| Truncation detection bound to AEAD | ✅ | ✅ | ❌ | ❌ |
|
|
40
|
-
| Cross-file splice prevention (file_id
|
|
45
|
+
| Cross-file splice prevention (file_id via HKDF salt) | ✅ | ✅ | ❌ | ❌ |
|
|
41
46
|
| Streaming AEAD with random-access chunks | ✅ | ⚠️ | ✅ | ✅ |
|
|
42
47
|
| WebCrypto-only path (no WASM required) | ✅ | ❌ | ❌ | ❌ |
|
|
43
48
|
| Apache 2.0 (patent grant) | ✅ | ⚠️ (LGPL) | ⚠️ | ⚠️ |
|
|
@@ -151,9 +156,11 @@ ML-KEM-1024 secret for Suite 0x03 files deterministically from
|
|
|
151
156
|
the root key (per `spec/key-derivation.md`), and feeds each blob
|
|
152
157
|
into `autoDecryptBlob` here.
|
|
153
158
|
|
|
154
|
-
The recipe
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
The recipe lives at [shieldfive.com/export](https://shieldfive.com/export)
|
|
160
|
+
and the script ships in this repository as
|
|
161
|
+
[`examples/decrypt-one.mjs`](examples/decrypt-one.mjs), kept in
|
|
162
|
+
lock-step with the API surface; this library is the decryption
|
|
163
|
+
primitive the script depends on. If
|
|
157
164
|
you want to reproduce the path from first principles (with no
|
|
158
165
|
ShieldFive code in the loop), `spec/format-v1.md` and
|
|
159
166
|
`spec/key-derivation.md` together describe everything needed.
|
|
@@ -165,7 +172,7 @@ The complete v1 wire format is documented in
|
|
|
165
172
|
|
|
166
173
|
```
|
|
167
174
|
header := magic(5) = "SF5\x01\x00"
|
|
168
|
-
|| suite(1) = 0x01 | 0x02 | 0x03
|
|
175
|
+
|| suite(1) = 0x01 | 0x02 | 0x03 | 0x04
|
|
169
176
|
|| flags(1) = 0x00 (reserved)
|
|
170
177
|
|| file_id(16) = random per-file
|
|
171
178
|
|| chunk_size(4) = uint32 BE
|
|
@@ -179,9 +186,11 @@ chunk_i := length_prefix(4) || AEAD-ciphertext-with-tag
|
|
|
179
186
|
```
|
|
180
187
|
|
|
181
188
|
Every chunk's AEAD authenticator binds the chunk index, total chunk count,
|
|
182
|
-
final-chunk flag
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
and final-chunk flag. The `file_id` is NOT part of the AAD; cross-file
|
|
190
|
+
splice resistance is structural, coming from the suite-specific chunk-key
|
|
191
|
+
and nonce-prefix derivations that mix `file_id` in as the HKDF salt/IKM.
|
|
192
|
+
Together these make truncation, reordering, and cross-file splicing
|
|
193
|
+
detectable by the AEAD rather than by application-layer hashes.
|
|
185
194
|
|
|
186
195
|
## Cipher suites
|
|
187
196
|
|
|
@@ -190,6 +199,13 @@ application-layer hashes.
|
|
|
190
199
|
| 0x01 | `aes-256-gcm-v1` | | WebCrypto-only, hardware-accelerated |
|
|
191
200
|
| 0x02 | `xchacha20-poly1305-v1` | | libsodium, 192-bit nonces |
|
|
192
201
|
| 0x03 | `pq-hybrid-xchacha-mlkem1024-v1` | ✅ | XChaCha20-Poly1305 + ML-KEM-1024 hybrid |
|
|
202
|
+
| 0x04 | `aes-256-gcm-v2` | | WebCrypto-only, 8-byte nonce prefix |
|
|
203
|
+
|
|
204
|
+
Suite `0x04` is the current AES-GCM write path: identical to `0x01` except
|
|
205
|
+
the 12-byte GCM IV uses an 8-byte file-derived nonce prefix and a 4-byte
|
|
206
|
+
counter (rather than 4 + 8), widening the cross-file IV-collision margin.
|
|
207
|
+
`0x01` remains defined for reading files written before `0x04` existed.
|
|
208
|
+
See [`spec/format-v1.md`](spec/format-v1.md) for the per-suite derivations.
|
|
193
209
|
|
|
194
210
|
ML-KEM-1024 is FIPS 203 (NIST PQC standard, security level 5). Files
|
|
195
211
|
encrypted with suite 0x03 remain confidential against an adversary who
|
|
@@ -235,9 +251,9 @@ Requires Node 20+.
|
|
|
235
251
|
|
|
236
252
|
## Status
|
|
237
253
|
|
|
238
|
-
**
|
|
254
|
+
**Beta.** The wire format is frozen for the v1 release, but the public
|
|
239
255
|
TypeScript API may make small adjustments before 1.0.0 stable. Test
|
|
240
|
-
coverage is comprehensive (
|
|
256
|
+
coverage is comprehensive (188 tests, all four suites, all architectural
|
|
241
257
|
guarantees verified). A formal third-party security audit is planned for
|
|
242
258
|
the 1.0.0 stable milestone — until that audit lands, treat this library
|
|
243
259
|
as a serious work-in-progress rather than a finished product.
|
|
@@ -250,7 +266,8 @@ crypto library; we chose it over MIT for that reason.
|
|
|
250
266
|
## Reporting vulnerabilities
|
|
251
267
|
|
|
252
268
|
See [`SECURITY.md`](SECURITY.md). Coordinate with us at
|
|
253
|
-
`security@shieldfive.com` (
|
|
269
|
+
`security@shieldfive.com` (see SECURITY.md for the encrypted-channel
|
|
270
|
+
process). 72-hour acknowledgement,
|
|
254
271
|
30-day target patch window for high-severity issues. Researchers acting
|
|
255
272
|
in good faith are protected under the safe-harbor clause.
|
|
256
273
|
|
package/SECURITY.md
CHANGED
package/dist/identity/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* want stronger identity (e.g. SAS verification, gossiped signatures),
|
|
18
18
|
* they wrap this module rather than modify it.
|
|
19
19
|
*/
|
|
20
|
+
export { SIGNATURE_ALGO_ED25519, SIGNATURE_ALGO_ML_DSA_65, ED25519_PUBLIC_KEY_LENGTH, ED25519_SECRET_KEY_LENGTH, ED25519_SIGNATURE_LENGTH, SignatureError, buildSignatureBlock, deriveEd25519PublicKey, parseSignatureBlock, signHeaderAndMacs, verifyHeaderAndMacs, } from './sign.js';
|
|
21
|
+
export type { SignatureBlock } from './sign.js';
|
|
20
22
|
export interface PublicIdentityBundle {
|
|
21
23
|
/** ML-KEM-1024 public key (1568 bytes) */
|
|
22
24
|
mlKemPublicKey: Uint8Array;
|
|
@@ -99,6 +101,20 @@ export interface ShareFileInput {
|
|
|
99
101
|
* key. To make sharing work, we use a different construction: we wrap
|
|
100
102
|
* the existing combined key under (recipient PQ KEM ⊕ recipient
|
|
101
103
|
* envelope) and emit only the wrapped form.
|
|
104
|
+
*
|
|
105
|
+
* Two properties this construction must hold (audit H2/M6):
|
|
106
|
+
* 1. The wrapping key is NOT the raw KEM/envelope combined key (which
|
|
107
|
+
* reuses the file-combiner HKDF label). We run it through one more
|
|
108
|
+
* HKDF under the dedicated `SHARE_TRANSPORT` label so a share key is
|
|
109
|
+
* never equal to a file's combined key.
|
|
110
|
+
* 2. The wrap authenticates the WHOLE bundle, not just the 32-byte
|
|
111
|
+
* combined key: the XChaCha20-Poly1305 AAD covers the version marker,
|
|
112
|
+
* the length prefix, the entire pqPayload (including its reserved pad)
|
|
113
|
+
* and the nonce, so PQ material cannot be substituted or stripped
|
|
114
|
+
* without breaking the tag.
|
|
115
|
+
*
|
|
116
|
+
* The bundle is prefixed with `SHARE_BUNDLE_MAGIC` ("SF5S" + version) so the
|
|
117
|
+
* hardened format is distinguishable from the earlier unversioned one.
|
|
102
118
|
*/
|
|
103
119
|
export declare function buildShareForRecipient(input: ShareFileInput): Promise<{
|
|
104
120
|
shareBundle: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAWH,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,WAA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kD;IAClD,oBAAoB,EAAE,UAAU,CAAA;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC;IAAE,WAAW,EAAE,UAAU,CAAA;CAAE,CAAC,CAwDtC;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE;IAChD,WAAW,EAAE,UAAU,CAAA;IACvB,MAAM,EAAE,UAAU,CAAA;IAClB,kBAAkB,EAAE,UAAU,CAAA;IAC9B,oBAAoB,EAAE,UAAU,CAAA;CACjC,GAAG,OAAO,CAAC,UAAU,CAAC,CAwEtB"}
|
package/dist/identity/index.js
CHANGED
|
@@ -17,12 +17,21 @@
|
|
|
17
17
|
* want stronger identity (e.g. SAS verification, gossiped signatures),
|
|
18
18
|
* they wrap this module rather than modify it.
|
|
19
19
|
*/
|
|
20
|
-
import { ML_KEM_1024_PUBLIC_KEY_BYTES, ML_KEM_1024_SECRET_KEY_BYTES, deriveMlKemKeypair, generateMlKemKeypair, encapsulateForRecipient, decapsulateFromHeader, parsePqHybridV1SuitePayload,
|
|
20
|
+
import { ML_KEM_1024_PUBLIC_KEY_BYTES, ML_KEM_1024_SECRET_KEY_BYTES, deriveMlKemKeypair, generateMlKemKeypair, encapsulateForRecipient, decapsulateFromHeader, parsePqHybridV1SuitePayload, } from '../suites/pq-hybrid-v1/index.js';
|
|
21
|
+
export { SIGNATURE_ALGO_ED25519, SIGNATURE_ALGO_ML_DSA_65, ED25519_PUBLIC_KEY_LENGTH, ED25519_SECRET_KEY_LENGTH, ED25519_SIGNATURE_LENGTH, SignatureError, buildSignatureBlock, deriveEd25519PublicKey, parseSignatureBlock, signHeaderAndMacs, verifyHeaderAndMacs, } from './sign.js';
|
|
21
22
|
import { bytesToBase64, base64ToBytes, concatBytes, uint16BE, uint32BE, readUint16BE, readUint32BE, } from '../internal/encoding.js';
|
|
22
23
|
import { randomBytes } from '../internal/runtime.js';
|
|
23
24
|
import { getSodium } from '../internal/sodium.js';
|
|
25
|
+
import { hkdfSha256 } from '../internal/hkdf.js';
|
|
26
|
+
import { HKDF_INFO } from '../internal/types.js';
|
|
24
27
|
const IDENTITY_BUNDLE_MAGIC = new Uint8Array([0x53, 0x46, 0x35, 0x49, 0x01]); // "SF5I" + version
|
|
25
|
-
|
|
28
|
+
// Share-bundle magic: "SF5S" + version byte. Version 0x02 marks the hardened
|
|
29
|
+
// share construction (audit H2/M6): a domain-separated transport key and an
|
|
30
|
+
// AEAD wrap whose AAD authenticates the whole bundle. Earlier alpha builds
|
|
31
|
+
// emitted an unversioned bundle (an AAD-less secretbox under the raw transport
|
|
32
|
+
// secret); those are NOT readable here and are rejected by the magic check.
|
|
33
|
+
// No real shares exist pre-launch, so this is a deliberate clean break.
|
|
34
|
+
const SHARE_BUNDLE_MAGIC = new Uint8Array([0x53, 0x46, 0x35, 0x53, 0x02]); // "SF5S" + version 2
|
|
26
35
|
/**
|
|
27
36
|
* Wire format for an identity bundle:
|
|
28
37
|
*
|
|
@@ -140,30 +149,60 @@ export async function createIdentity(options) {
|
|
|
140
149
|
* key. To make sharing work, we use a different construction: we wrap
|
|
141
150
|
* the existing combined key under (recipient PQ KEM ⊕ recipient
|
|
142
151
|
* envelope) and emit only the wrapped form.
|
|
152
|
+
*
|
|
153
|
+
* Two properties this construction must hold (audit H2/M6):
|
|
154
|
+
* 1. The wrapping key is NOT the raw KEM/envelope combined key (which
|
|
155
|
+
* reuses the file-combiner HKDF label). We run it through one more
|
|
156
|
+
* HKDF under the dedicated `SHARE_TRANSPORT` label so a share key is
|
|
157
|
+
* never equal to a file's combined key.
|
|
158
|
+
* 2. The wrap authenticates the WHOLE bundle, not just the 32-byte
|
|
159
|
+
* combined key: the XChaCha20-Poly1305 AAD covers the version marker,
|
|
160
|
+
* the length prefix, the entire pqPayload (including its reserved pad)
|
|
161
|
+
* and the nonce, so PQ material cannot be substituted or stripped
|
|
162
|
+
* without breaking the tag.
|
|
163
|
+
*
|
|
164
|
+
* The bundle is prefixed with `SHARE_BUNDLE_MAGIC` ("SF5S" + version) so the
|
|
165
|
+
* hardened format is distinguishable from the earlier unversioned one.
|
|
143
166
|
*/
|
|
144
167
|
export async function buildShareForRecipient(input) {
|
|
145
168
|
const sodium = await getSodium();
|
|
146
|
-
// Generate a fresh transport
|
|
169
|
+
// Generate a fresh transport secret for this share.
|
|
147
170
|
// ML-KEM encapsulation gives us the PQ-half of the transport secret.
|
|
148
|
-
const { suitePayload: pqPayload, combinedKey:
|
|
171
|
+
const { suitePayload: pqPayload, combinedKey: transportSecret } = await encapsulateForRecipient({
|
|
149
172
|
recipientPublicKey: input.recipient.mlKemPublicKey,
|
|
150
173
|
envelopeKey: input.recipientEnvelopeKey,
|
|
151
174
|
fileId: input.fileId,
|
|
152
175
|
});
|
|
153
|
-
|
|
154
|
-
// XSalsa20-Poly1305 secretbox.
|
|
155
|
-
if (transportKey.length !== 32) {
|
|
176
|
+
if (transportSecret.length !== 32) {
|
|
156
177
|
throw new Error('buildShareForRecipient: transport key length wrong');
|
|
157
178
|
}
|
|
179
|
+
// (1) Domain-separate the share transport key from the file-combiner output.
|
|
180
|
+
const shareTransportKey = await hkdfSha256({
|
|
181
|
+
ikm: transportSecret,
|
|
182
|
+
salt: input.fileId,
|
|
183
|
+
info: HKDF_INFO.SHARE_TRANSPORT,
|
|
184
|
+
length: 32,
|
|
185
|
+
});
|
|
186
|
+
// (2) Wrap the original combined key with an AEAD whose AAD authenticates
|
|
187
|
+
// the whole bundle prefix (magic || length || pqPayload || nonce). Binding
|
|
188
|
+
// the magic means the version marker cannot be stripped or downgraded
|
|
189
|
+
// without breaking the tag.
|
|
158
190
|
const wrapNonce = randomBytes(24);
|
|
159
|
-
const
|
|
191
|
+
const aad = concatBytes([
|
|
192
|
+
SHARE_BUNDLE_MAGIC,
|
|
193
|
+
uint32BE(pqPayload.length),
|
|
194
|
+
pqPayload,
|
|
195
|
+
wrapNonce,
|
|
196
|
+
]);
|
|
197
|
+
const wrappedCombinedKey = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(input.combinedKey, aad, null, wrapNonce, shareTransportKey);
|
|
160
198
|
if (wrappedCombinedKey.length !== 32 + 16) {
|
|
161
|
-
throw new Error('buildShareForRecipient:
|
|
199
|
+
throw new Error('buildShareForRecipient: AEAD produced unexpected length');
|
|
162
200
|
}
|
|
163
201
|
// Share record format:
|
|
164
|
-
// [4 bytes BE length of pqPayload][pqPayload][24-byte wrap nonce][48-byte wrapped combined key]
|
|
202
|
+
// [5-byte magic][4 bytes BE length of pqPayload][pqPayload][24-byte wrap nonce][48-byte wrapped combined key]
|
|
165
203
|
return {
|
|
166
204
|
shareBundle: concatBytes([
|
|
205
|
+
SHARE_BUNDLE_MAGIC,
|
|
167
206
|
uint32BE(pqPayload.length),
|
|
168
207
|
pqPayload,
|
|
169
208
|
wrapNonce,
|
|
@@ -178,10 +217,18 @@ export async function buildShareForRecipient(input) {
|
|
|
178
217
|
*/
|
|
179
218
|
export async function openShareAsRecipient(input) {
|
|
180
219
|
const sodium = await getSodium();
|
|
181
|
-
if (input.shareBundle.length < 4) {
|
|
220
|
+
if (input.shareBundle.length < SHARE_BUNDLE_MAGIC.length + 4) {
|
|
182
221
|
throw new Error('openShareAsRecipient: share too short');
|
|
183
222
|
}
|
|
184
|
-
|
|
223
|
+
// Reject anything that isn't a current ("SF5S" + version) share bundle.
|
|
224
|
+
// Earlier-alpha unversioned bundles fail here rather than producing an
|
|
225
|
+
// opaque authentication error later.
|
|
226
|
+
for (let i = 0; i < SHARE_BUNDLE_MAGIC.length; i += 1) {
|
|
227
|
+
if (input.shareBundle[i] !== SHARE_BUNDLE_MAGIC[i]) {
|
|
228
|
+
throw new Error('openShareAsRecipient: bad magic / unsupported share bundle version');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
let offset = SHARE_BUNDLE_MAGIC.length;
|
|
185
232
|
const pqLen = readUint32BE(input.shareBundle, offset);
|
|
186
233
|
offset += 4;
|
|
187
234
|
if (offset + pqLen + 24 + 48 !== input.shareBundle.length) {
|
|
@@ -192,22 +239,37 @@ export async function openShareAsRecipient(input) {
|
|
|
192
239
|
const wrapNonce = input.shareBundle.slice(offset, offset + 24);
|
|
193
240
|
offset += 24;
|
|
194
241
|
const wrappedCombinedKey = input.shareBundle.slice(offset, offset + 48);
|
|
195
|
-
//
|
|
242
|
+
// Structurally validate the suite payload. This rejects a non-zero reserved
|
|
243
|
+
// pad in classical_wrapped (M6) before any decapsulation work.
|
|
196
244
|
parsePqHybridV1SuitePayload(pqPayload);
|
|
197
|
-
|
|
198
|
-
const checkBytes = buildPqHybridV1SuitePayload(parsePqHybridV1SuitePayload(pqPayload));
|
|
199
|
-
if (checkBytes.length !== pqPayload.length) {
|
|
200
|
-
throw new Error('openShareAsRecipient: pq payload self-check failed');
|
|
201
|
-
}
|
|
202
|
-
const { combinedKey: transportKey } = await decapsulateFromHeader({
|
|
245
|
+
const { combinedKey: transportSecret } = await decapsulateFromHeader({
|
|
203
246
|
suitePayload: pqPayload,
|
|
204
247
|
recipientSecretKey: input.recipientSecretKey,
|
|
205
248
|
envelopeKey: input.recipientEnvelopeKey,
|
|
206
249
|
fileId: input.fileId,
|
|
207
250
|
});
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
251
|
+
const shareTransportKey = await hkdfSha256({
|
|
252
|
+
ikm: transportSecret,
|
|
253
|
+
salt: input.fileId,
|
|
254
|
+
info: HKDF_INFO.SHARE_TRANSPORT,
|
|
255
|
+
length: 32,
|
|
256
|
+
});
|
|
257
|
+
// The AAD must reproduce exactly what the builder authenticated: it binds
|
|
258
|
+
// the version marker, the length prefix, the whole pqPayload (incl. reserved
|
|
259
|
+
// pad) and the nonce, so any substitution/stripping of PQ material breaks
|
|
260
|
+
// the tag.
|
|
261
|
+
const aad = concatBytes([
|
|
262
|
+
SHARE_BUNDLE_MAGIC,
|
|
263
|
+
uint32BE(pqPayload.length),
|
|
264
|
+
pqPayload,
|
|
265
|
+
wrapNonce,
|
|
266
|
+
]);
|
|
267
|
+
let unwrapped;
|
|
268
|
+
try {
|
|
269
|
+
unwrapped = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(null, wrappedCombinedKey, aad, wrapNonce, shareTransportKey);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
throw new Error('openShareAsRecipient: share authentication failed — wrong recipient or tampered share');
|
|
211
273
|
}
|
|
212
274
|
if (unwrapped.length !== 32) {
|
|
213
275
|
throw new Error('openShareAsRecipient: bad combined key length');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,GACb,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,uB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WAAW,EAAE,KAAK,CAAC,oBAAoB;QACvC,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,CAAA;IACF,MAAM,iBAAiB,GAAG,MAAM,UAAU,CAAC;QACzC,GAAG,EAAE,eAAe;QACpB,IAAI,EAAE,KAAK,CAAC,MAAM;QAClB,IAAI,EAAE,SAAS,CAAC,eAAe;QAC/B,MAAM,EAAE,EAAE;KACX,CAAC,CAAA;IAEF,0EAA0E;IAC1E,6EAA6E;IAC7E,0EAA0E;IAC1E,WAAW;IACX,MAAM,GAAG,GAAG,WAAW,CAAC;QACtB,kBAAkB;QAClB,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC;QAC1B,SAAS;QACT,SAAS;KACV,CAAC,CAAA;IACF,IAAI,SAAqB,CAAA;IACzB,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,CAAC,0CAA0C,CAC3D,IAAI,EACJ,kBAAkB,EAClB,GAAG,EACH,SAAS,EACT,iBAAiB,CAClB,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,uFAAuF,CACxF,CAAA;IACH,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAClE,CAAC;IACD,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sender-attribution signatures over the v1 wire format.
|
|
3
|
+
*
|
|
4
|
+
* The v1 file format already authenticates with HMAC under the content
|
|
5
|
+
* key (`header_mac`) and per-chunk AEAD tags, so a recipient can be sure
|
|
6
|
+
* the file decrypts to bytes the encryptor produced. What it does NOT
|
|
7
|
+
* tell them is WHO encrypted it — anyone with the content key could have
|
|
8
|
+
* written the file.
|
|
9
|
+
*
|
|
10
|
+
* This module adds an optional detached signature over
|
|
11
|
+
* `header_unauthenticated_bytes || concat(per-chunk MAC tags)` so that a
|
|
12
|
+
* recipient who trusts a sender's public key can verify authorship. The
|
|
13
|
+
* signature lives in an optional trailing structure (see
|
|
14
|
+
* `spec/format-v1.md § "Signature block"`); legacy files without that
|
|
15
|
+
* structure continue to decrypt unchanged, with the receiving side
|
|
16
|
+
* reporting `signature: null`.
|
|
17
|
+
*
|
|
18
|
+
* Algorithm 0x01 (Ed25519) is the only algorithm defined in v1. 0x02 is
|
|
19
|
+
* reserved for ML-DSA-65; the format leaves room for it but does not yet
|
|
20
|
+
* implement it.
|
|
21
|
+
*/
|
|
22
|
+
/** Signature algorithm: Ed25519 (RFC 8032). 32-byte key, 64-byte signature. */
|
|
23
|
+
export declare const SIGNATURE_ALGO_ED25519 = 1;
|
|
24
|
+
/** Signature algorithm reserved for ML-DSA-65 (FIPS 204). Not yet implemented. */
|
|
25
|
+
export declare const SIGNATURE_ALGO_ML_DSA_65 = 2;
|
|
26
|
+
export declare const ED25519_PUBLIC_KEY_LENGTH = 32;
|
|
27
|
+
export declare const ED25519_SECRET_KEY_LENGTH = 32;
|
|
28
|
+
export declare const ED25519_SIGNATURE_LENGTH = 64;
|
|
29
|
+
export interface SignatureBlock {
|
|
30
|
+
/** Algorithm identifier; see `SIGNATURE_ALGO_*`. */
|
|
31
|
+
algorithm: number;
|
|
32
|
+
/** Sender's verifying key. Length depends on the algorithm. */
|
|
33
|
+
publicKey: Uint8Array;
|
|
34
|
+
/** Detached signature over `signed_message`. */
|
|
35
|
+
signature: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
export declare class SignatureError extends Error {
|
|
38
|
+
readonly code: string;
|
|
39
|
+
constructor(code: string);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Produce a detached Ed25519 signature over
|
|
43
|
+
* `header_unauthenticated_bytes || concat(chunk_macs)`.
|
|
44
|
+
*
|
|
45
|
+
* `header` MUST be the exact bytes covered by the file's `header_mac`
|
|
46
|
+
* (i.e. the output of `buildHeaderUnauthenticated` or
|
|
47
|
+
* `parseHeader().unauthenticatedBytes`). `chunkMacs` MUST be the per-chunk
|
|
48
|
+
* AEAD tags in chunk-index order. For suites defined in v1 (AES-GCM-128,
|
|
49
|
+
* ChaCha20-Poly1305) the tag is the trailing 16 bytes of the chunk's
|
|
50
|
+
* ciphertext field.
|
|
51
|
+
*
|
|
52
|
+
* Returns the raw 64-byte signature. Callers wrap it in a signature block
|
|
53
|
+
* via `buildSignatureBlock`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function signHeaderAndMacs(input: {
|
|
56
|
+
ed25519SecretKey: Uint8Array;
|
|
57
|
+
header: Uint8Array;
|
|
58
|
+
chunkMacs: ReadonlyArray<Uint8Array>;
|
|
59
|
+
}): Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Verify a detached Ed25519 signature produced by `signHeaderAndMacs`.
|
|
62
|
+
* Returns `true` on success, `false` on any failure (wrong length,
|
|
63
|
+
* malformed point, bad signature). Never throws on a verification
|
|
64
|
+
* mismatch — failures are not exceptional.
|
|
65
|
+
*/
|
|
66
|
+
export declare function verifyHeaderAndMacs(input: {
|
|
67
|
+
ed25519PublicKey: Uint8Array;
|
|
68
|
+
header: Uint8Array;
|
|
69
|
+
chunkMacs: ReadonlyArray<Uint8Array>;
|
|
70
|
+
signature: Uint8Array;
|
|
71
|
+
}): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Derive the Ed25519 public key from a 32-byte secret seed.
|
|
74
|
+
*/
|
|
75
|
+
export declare function deriveEd25519PublicKey(ed25519SecretKey: Uint8Array): Uint8Array;
|
|
76
|
+
/**
|
|
77
|
+
* Serialize a signature block:
|
|
78
|
+
* 1 byte algorithm || 2 bytes BE pubkey_len || pubkey || 2 bytes BE sig_len || sig
|
|
79
|
+
*/
|
|
80
|
+
export declare function buildSignatureBlock(block: SignatureBlock): Uint8Array;
|
|
81
|
+
/**
|
|
82
|
+
* Parse a signature block starting at `offset` in `bytes`. Returns the
|
|
83
|
+
* parsed block and the number of bytes consumed. Throws on malformed
|
|
84
|
+
* input (truncation, oversize, or — for known algorithms — wrong key /
|
|
85
|
+
* signature length). Unknown algorithms parse successfully; verification
|
|
86
|
+
* against an unknown algorithm is the caller's policy decision.
|
|
87
|
+
*/
|
|
88
|
+
export declare function parseSignatureBlock(bytes: Uint8Array, offset?: number): {
|
|
89
|
+
block: SignatureBlock;
|
|
90
|
+
consumed: number;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/identity/sign.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAUH,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,IAAO,CAAA;AAE1C,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,IAAO,CAAA;AAE5C,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAC3C,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAC3C,eAAO,MAAM,wBAAwB,KAAK,CAAA;AAE1C,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAA;IACjB,+DAA+D;IAC/D,SAAS,EAAE,UAAU,CAAA;IACrB,gDAAgD;IAChD,SAAS,EAAE,UAAU,CAAA;CACtB;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBACT,IAAI,EAAE,MAAM;CAKzB;AAkBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,gBAAgB,EAAE,UAAU,CAAA;IAC5B,MAAM,EAAE,UAAU,CAAA;IAClB,SAAS,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CACrC,GAAG,UAAU,CAMb;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,gBAAgB,EAAE,UAAU,C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