@seedprotocol/encryption 0.0.0-stage → 0.8.3
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 +12 -0
- package/README.md +148 -2
- package/SPEC.md +243 -0
- package/dist/base64.d.ts +5 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/deviceStore.d.ts +17 -0
- package/dist/deviceStore.d.ts.map +1 -0
- package/dist/entitlement.d.ts +29 -0
- package/dist/entitlement.d.ts.map +1 -0
- package/dist/envelope.d.ts +87 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelopeDecryptor.d.ts +13 -0
- package/dist/envelopeDecryptor.d.ts.map +1 -0
- package/dist/hpke.d.ts +22 -0
- package/dist/hpke.d.ts.map +1 -0
- package/dist/identity.d.ts +65 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +862 -0
- package/dist/index.js.map +1 -0
- package/dist/keystore.d.ts +88 -0
- package/dist/keystore.d.ts.map +1 -0
- package/dist/passkey.d.ts +22 -0
- package/dist/passkey.d.ts.map +1 -0
- package/dist/recipient.d.ts +32 -0
- package/dist/recipient.d.ts.map +1 -0
- package/dist/uploadEncryptor.d.ts +34 -0
- package/dist/uploadEncryptor.d.ts.map +1 -0
- package/package.json +67 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this package are documented in this file.
|
|
4
|
+
|
|
5
|
+
## 0.8.3 (2026-11-23)
|
|
6
|
+
|
|
7
|
+
- `createEnvelopeDecryptor(identities)` returns the decryptor for the SDK's `setEnvelopeDecryptor`: it opens an envelope wrapped to any of the identities' recipient keys and returns null when none is a recipient.
|
|
8
|
+
- `createPrivateUploadEncryptor({ recipients, bind, padding })` returns the `encryptPrivateUpload` for `@seedprotocol/publish`: each upload becomes its own envelope with a fresh file key and envelope id, wrapped to every recipient, its real content type inside and a `Seed-Encryption: seed-private/v1` tag outside. It needs only public keys.
|
|
9
|
+
- New package. `encryptEnvelope` and `decryptEnvelope` implement the `seed-private/v1` envelope described in `SPEC.md`: a header of recipient stanzas and a `bind` line, authenticated by an HMAC under the file key, and a payload of 64 KiB AES-256-GCM chunks whose first bytes hold the content type and body length. The plaintext is zero-padded to its PADMÉ length by default (at most 12% extra), so the envelope size shows a size class rather than the exact length; `padding: 'none'` turns that off. Decryption fails with an `EnvelopeError` whose `code` names the problem (`HEADER_MAC`, `TRUNCATED`, `BAD_CHUNK`, `TRAILING_DATA`, `BIND_MISMATCH`, ...).
|
|
10
|
+
- The `mlkem768x25519` recipient stanza: `generateRecipientKeyPair`, `wrapFileKey`, `unwrapFileKey` and `unwrapWithSecretKeys` seal the file key to an X-Wing public key with HPKE (KEM `0x647a`, HKDF-SHA256, AES-256-GCM), following age's construction. Adds `@noble/post-quantum` as a dependency.
|
|
11
|
+
- Encryption identity and keystore manifest. `createEncryptionIdentity` makes a 32-byte identity secret from which the recipient key, an X25519 tag key, an Ed25519 binding key and a key id are derived. `signKeyBinding(identity, { account, chainId })` signs that the identity belongs to an account on a chain, and `verifyKeyBinding` checks such a signature; an account's encryption key registration carries it. `encryptionKeyId` and `keyBindingMessage` give the key id and the signed bytes SPEC.md defines. `generateRecoveryPhrase` and `recoveryKeyFromPhrase` handle a 24-word BIP39 recovery phrase. `buildKeystoreManifest` writes the public manifest (a `seed-private/v1` envelope holding the identity secret) with one stanza per authenticator: the recovery key, a passkey's PRF output (`passkey-prf`, with `enrollPasskey` and `passkeyPrf` for WebAuthn) or a deterministic EOA signature (`eoa-signature`). `eoaSignatureStanza` needs `acceptWalletKeyRisk: true` and throws `BAD_KEYSTORE` without it, because anyone with the wallet's key can then open the identity and read every private Version wrapped to it. `openKeystoreManifest` unlocks it and checks the contents against the key id. `saveIdentityOnDevice` and `loadIdentityFromDevice` keep an unlocked identity in IndexedDB under a non-extractable key. Adds `@noble/curves` and `@scure/bip39` as dependencies.
|
|
12
|
+
- `registerEntitlementAdapter(kind, adapter)` and `isEntitled(policy, address, blockTag)`: one adapter per access-policy kind decides who may receive keys.
|
package/README.md
CHANGED
|
@@ -1,3 +1,149 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @seedprotocol/encryption
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Encryption for Seed Protocol private Versions (ADR 0033): an author publishes a Version only their
|
|
4
|
+
own identity, and its recovery phrase, can read.
|
|
5
|
+
|
|
6
|
+
- `encryptEnvelope` / `decryptEnvelope`: the `seed-private/v1` envelope, specified in
|
|
7
|
+
[SPEC.md](SPEC.md). No SDK dependency, so a reader can decrypt without the SDK.
|
|
8
|
+
- `parseEnvelopeHeader`: the bind values and recipient stanzas, readable without a key.
|
|
9
|
+
- `generateRecipientKeyPair`, `wrapFileKey`, `unwrapFileKey`, `unwrapWithSecretKeys`: the
|
|
10
|
+
`mlkem768x25519` recipient stanza, which seals the file key to an X-Wing (post-quantum hybrid)
|
|
11
|
+
public key with HPKE. X-Wing comes from `@noble/post-quantum`.
|
|
12
|
+
- `createEncryptionIdentity`, `encryptionIdentityFromSecret`: a user's identity, one 32-byte secret
|
|
13
|
+
from which the recipient key, an X25519 tag key, an Ed25519 binding key and the key id are
|
|
14
|
+
derived.
|
|
15
|
+
- `signKeyBinding`, `verifyKeyBinding`: the binding key's signature that the identity belongs to an
|
|
16
|
+
account on a chain, which the account's registration carries.
|
|
17
|
+
- `generateRecoveryPhrase`, `recoveryKeyFromPhrase`: a 24-word BIP39 phrase and the recovery key
|
|
18
|
+
derived from it.
|
|
19
|
+
- `buildKeystoreManifest`, `openKeystoreManifest`, `describeKeystoreManifest`: the public keystore
|
|
20
|
+
manifest that recovers the identity, with a stanza per authenticator (`recoveryStanza`,
|
|
21
|
+
`passkeyStanza`, `eoaSignatureStanza`). `enrollPasskey` and `passkeyPrf` make the WebAuthn calls.
|
|
22
|
+
Use a passkey and the recovery phrase. `eoaSignatureStanza` lets a wallet signature unlock the
|
|
23
|
+
identity instead, which means anyone with the wallet's key can read every private Version; it
|
|
24
|
+
needs `acceptWalletKeyRisk: true`, so offer it only as an option the user picks.
|
|
25
|
+
- `createPrivateUploadEncryptor`: the `encryptPrivateUpload` for `@seedprotocol/publish`, one envelope
|
|
26
|
+
per private upload.
|
|
27
|
+
- `createEnvelopeDecryptor`: opens downloaded envelopes for the SDK's `setEnvelopeDecryptor`.
|
|
28
|
+
- `saveIdentityOnDevice`, `loadIdentityFromDevice`, `listIdentitiesOnDevice`,
|
|
29
|
+
`forgetIdentityOnDevice`: an unlocked identity kept in IndexedDB under a non-extractable key.
|
|
30
|
+
Any script on the origin can still decrypt it, so don't save one on a shared device.
|
|
31
|
+
- `registerEntitlementAdapter` / `isEntitled`: which addresses may receive keys for an access
|
|
32
|
+
policy, answered by an adapter per policy kind.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import {
|
|
36
|
+
decryptEnvelope,
|
|
37
|
+
encryptEnvelope,
|
|
38
|
+
generateEnvelopeId,
|
|
39
|
+
generateFileKey,
|
|
40
|
+
unwrapWithSecretKeys,
|
|
41
|
+
wrapFileKey,
|
|
42
|
+
} from '@seedprotocol/encryption'
|
|
43
|
+
|
|
44
|
+
const fileKey = generateFileKey()
|
|
45
|
+
const envelope = await encryptEnvelope({
|
|
46
|
+
fileKey,
|
|
47
|
+
bind: { envelopeId: generateEnvelopeId() },
|
|
48
|
+
stanzas: [await wrapFileKey(fileKey, publisher.publicKey), await wrapFileKey(fileKey, recovery.publicKey)],
|
|
49
|
+
contentType: 'text/html',
|
|
50
|
+
body,
|
|
51
|
+
})
|
|
52
|
+
const { contentType, body: plain } = await decryptEnvelope(envelope, {
|
|
53
|
+
unwrap: unwrapWithSecretKeys([publisher.secretKey]),
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Setting up an identity, and unlocking it on another device:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import {
|
|
61
|
+
buildKeystoreManifest,
|
|
62
|
+
createEncryptionIdentity,
|
|
63
|
+
enrollPasskey,
|
|
64
|
+
generateRecoveryPhrase,
|
|
65
|
+
openKeystoreManifest,
|
|
66
|
+
passkeyPrf,
|
|
67
|
+
recoveryKeyFromPhrase,
|
|
68
|
+
recoveryStanza,
|
|
69
|
+
saveIdentityOnDevice,
|
|
70
|
+
} from '@seedprotocol/encryption'
|
|
71
|
+
|
|
72
|
+
const identity = await createEncryptionIdentity()
|
|
73
|
+
const phrase = generateRecoveryPhrase() // show once
|
|
74
|
+
const manifest = await buildKeystoreManifest(identity, [
|
|
75
|
+
await recoveryStanza(identity, (await recoveryKeyFromPhrase(phrase)).publicKey),
|
|
76
|
+
await enrollPasskey(identity, { rpName: 'PermaPress', userName: 'reader@example.com' }),
|
|
77
|
+
])
|
|
78
|
+
await saveIdentityOnDevice(identity)
|
|
79
|
+
|
|
80
|
+
// Elsewhere: the registration from getVerifiedEncryptionKey (@seedprotocol/publish) names the
|
|
81
|
+
// manifest's Arweave transaction and the key id.
|
|
82
|
+
const unlocked = await openKeystoreManifest(manifest, { passkey: passkeyPrf() }, { expectKeyId: registration.keyId })
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`registerEncryptionKey` in `@seedprotocol/publish` uploads the manifest and attests the key id,
|
|
86
|
+
public keys and binding signature from the user's account, then revokes the account's earlier
|
|
87
|
+
registrations.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { signKeyBinding } from '@seedprotocol/encryption'
|
|
91
|
+
import { registerEncryptionKey } from '@seedprotocol/publish'
|
|
92
|
+
|
|
93
|
+
await registerEncryptionKey(
|
|
94
|
+
{
|
|
95
|
+
keyId: identity.keyId,
|
|
96
|
+
recipientKey: identity.recipient.publicKey,
|
|
97
|
+
tagKey: identity.tagKey.publicKey,
|
|
98
|
+
bindingKey: identity.bindingKey.publicKey,
|
|
99
|
+
bindingSignature: signKeyBinding(identity, { account, chainId: 11155420 }),
|
|
100
|
+
keystoreManifest: manifest,
|
|
101
|
+
},
|
|
102
|
+
{ account },
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Publishing private properties: pass an encryptor wrapping to the account's registered key.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { createPrivateUploadEncryptor } from '@seedprotocol/encryption'
|
|
110
|
+
import { getVerifiedEncryptionKey, initPublish } from '@seedprotocol/publish'
|
|
111
|
+
|
|
112
|
+
// The newest registration the indexer lists that EAS on chain confirms. Undefined when none is.
|
|
113
|
+
const registration = await getVerifiedEncryptionKey({ account })
|
|
114
|
+
initPublish({
|
|
115
|
+
// ...
|
|
116
|
+
encryptPrivateUpload: createPrivateUploadEncryptor({
|
|
117
|
+
recipients: [registration.recipientKey],
|
|
118
|
+
bind: { chainId: '11155420', publisher: account },
|
|
119
|
+
}),
|
|
120
|
+
})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Only Html, Json, File, Image and ItemStorage Text properties can be `private: true`; their uploads
|
|
124
|
+
are encrypted, and titles, relations and other scalars stay public.
|
|
125
|
+
|
|
126
|
+
Reading private Versions on a device where the identity is unlocked: register a decryptor in every
|
|
127
|
+
tab, then open what earlier downloads kept.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { createEnvelopeDecryptor } from '@seedprotocol/encryption'
|
|
131
|
+
import { openAllEncryptedDownloads, setEnvelopeDecryptor } from '@seedprotocol/sdk'
|
|
132
|
+
|
|
133
|
+
setEnvelopeDecryptor(createEnvelopeDecryptor([unlocked]))
|
|
134
|
+
await openAllEncryptedDownloads()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Until then, a private Image, File or Html value reads as `valueStatus: 'encrypted'`. Don't register a
|
|
138
|
+
decrypting Arweave read transform in a process that builds public feeds.
|
|
139
|
+
|
|
140
|
+
## Not supported yet
|
|
141
|
+
|
|
142
|
+
- Sharing a private Version with other readers or collaborators, and subscriptions. Every upload is
|
|
143
|
+
wrapped only to the recipient keys you pass to `createPrivateUploadEncryptor`.
|
|
144
|
+
- Linking a second device from one that is already unlocked. On a new device, open the keystore
|
|
145
|
+
manifest with the recovery phrase.
|
|
146
|
+
- Reading private Versions in Node: the SDK downloads files only in the browser.
|
|
147
|
+
- Without a key, a private ItemStorage value reads as `valueStatus: 'missing'`, not `'encrypted'`;
|
|
148
|
+
only Image, File and Html values report `'encrypted'`.
|
|
149
|
+
- Loading one property on its own downloads its kept envelope again.
|
package/SPEC.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# seed-private/v1
|
|
2
|
+
|
|
3
|
+
The byte format of an encrypted upload for a Seed Protocol private Version. A reader that has the
|
|
4
|
+
32-byte file key can decrypt an envelope with this document alone, without the SDK. The design
|
|
5
|
+
follows [age](https://github.com/C2SP/C2SP/blob/main/age.md): a text header of recipient stanzas
|
|
6
|
+
authenticated by an HMAC, then a STREAM payload of independently authenticated chunks. It differs
|
|
7
|
+
from age in the key size, the cipher, the `bind` line and the content frame. ADR 0033 records why.
|
|
8
|
+
|
|
9
|
+
Status: draft. Defined so far: the `mlkem768x25519` recipient stanza, the encryption identity and
|
|
10
|
+
its key binding, and the keystore manifest with its `passkey-prf` and `eoa-signature` stanzas. Stanza types for readers'
|
|
11
|
+
key grants and subscription epochs come with those features.
|
|
12
|
+
|
|
13
|
+
## Notation
|
|
14
|
+
|
|
15
|
+
`||` is concatenation. `HKDF(ikm, salt, info, L)` is HKDF-SHA-256 (RFC 5869) with output length `L`
|
|
16
|
+
bytes. `HMAC(key, msg)` is HMAC-SHA-256. Strings are ASCII unless stated. `base64` is the standard
|
|
17
|
+
alphabet (RFC 4648 section 4) without padding, and a decoder must reject padding, characters outside
|
|
18
|
+
the alphabet, and non-zero trailing bits.
|
|
19
|
+
|
|
20
|
+
## Keys
|
|
21
|
+
|
|
22
|
+
- **File key:** 32 random bytes, generated per private Version. Each stanza wraps it for one
|
|
23
|
+
recipient. The publisher's own wrap is always present.
|
|
24
|
+
- **Header MAC key:** `HKDF(file key, empty, "seed-private/v1/header", 32)`.
|
|
25
|
+
- **Payload key:** `HKDF(file key, payload nonce, "seed-private/v1/payload" || 0x00 || bind, 32)`,
|
|
26
|
+
where `bind` is the canonical bind JSON's UTF-8 bytes and the payload nonce is 16 random bytes
|
|
27
|
+
written at the start of the payload.
|
|
28
|
+
|
|
29
|
+
## Header
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
seed-private/v1
|
|
33
|
+
bind <base64(bind)>
|
|
34
|
+
-> <type> [<arg> ...]
|
|
35
|
+
<base64 body, 64 characters per line; the last line is shorter, possibly empty>
|
|
36
|
+
...more stanzas...
|
|
37
|
+
--- <base64(MAC)>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Every line ends with a single LF. Header lines are printable ASCII (0x20 to 0x7E).
|
|
41
|
+
|
|
42
|
+
**Version line.** Exactly `seed-private/v1`. Readers detect an envelope by this line and its LF.
|
|
43
|
+
|
|
44
|
+
**Bind line.** The canonical bind JSON: an object whose keys match `[A-Za-z][A-Za-z0-9]*`, whose
|
|
45
|
+
values are strings, with keys sorted by UTF-16 code unit and no whitespace, serialized as
|
|
46
|
+
`JSON.stringify` does. The key `envelopeId` is required: `0x` followed by 64 lowercase hex digits,
|
|
47
|
+
chosen before encryption and recorded in the Version's envelope attestation. Other keys (for
|
|
48
|
+
example `chainId`, `publisher`, `seed`, `version`) are values known before upload. A reader must
|
|
49
|
+
reject a bind that does not re-serialize to the same bytes, and should compare the values it expects
|
|
50
|
+
from the attestation before using the content.
|
|
51
|
+
|
|
52
|
+
**Stanzas.** At least one. The stanza line is `-> `, a type, and zero or more arguments, separated
|
|
53
|
+
by single spaces; the type and each argument are one or more characters from 0x21 to 0x7E. The body
|
|
54
|
+
is base64 wrapped at 64 characters; the body ends at the first line shorter than 64 characters, so
|
|
55
|
+
a body whose encoding is a multiple of 64 characters is followed by an empty line. A reader ignores
|
|
56
|
+
stanza types it doesn't know. The type `x-test` appears only in test vectors.
|
|
57
|
+
|
|
58
|
+
**MAC line.** `--- ` and the base64 of `HMAC(header MAC key, header bytes from the start through
|
|
59
|
+
"---")`. The MAC covers the version line, the bind line, every stanza and the three dashes, not the
|
|
60
|
+
space or the MAC itself. A reader must verify it, in constant time, before decrypting the payload.
|
|
61
|
+
|
|
62
|
+
## Recipient stanzas
|
|
63
|
+
|
|
64
|
+
### mlkem768x25519
|
|
65
|
+
|
|
66
|
+
The file key sealed with HPKE (RFC 9180) to an X-Wing public key. The publisher's own wrap and the
|
|
67
|
+
recovery wrap are both this type, each to its own key. The construction follows age's
|
|
68
|
+
`mlkem768x25519` recipient ([c2sp.org/age](https://c2sp.org/age)) with a different `info`
|
|
69
|
+
string, a 32-byte file key and AES-256-GCM.
|
|
70
|
+
|
|
71
|
+
**Keys.** The secret key is 32 random bytes. The public key is the 1216-byte X-Wing encapsulation
|
|
72
|
+
key derived from it (draft-connolly-cfrg-xwing-kem, the KEM that draft-ietf-hpke-pq calls
|
|
73
|
+
MLKEM768-X25519): the ML-KEM-768 encapsulation key followed by the X25519 public key.
|
|
74
|
+
|
|
75
|
+
**Wrapping.** `enc, ct = SealBase(pkR = public key, info = "seed-private/v1/mlkem768x25519",
|
|
76
|
+
aad = "", pt = file key)` with this suite:
|
|
77
|
+
|
|
78
|
+
| | Algorithm | Id |
|
|
79
|
+
|---|---|---|
|
|
80
|
+
| KEM | MLKEM768-X25519 (X-Wing) | `0x647a` |
|
|
81
|
+
| KDF | HKDF-SHA256 | `0x0001` |
|
|
82
|
+
| AEAD | AES-256-GCM | `0x0002` |
|
|
83
|
+
|
|
84
|
+
The stanza is `-> mlkem768x25519 <base64(enc)>` with `ct` as its body. `enc` is 1120 bytes (the
|
|
85
|
+
ML-KEM-768 ciphertext, then the X25519 ephemeral key) and `ct` is 48 bytes. Every wrap uses fresh
|
|
86
|
+
encapsulation randomness.
|
|
87
|
+
|
|
88
|
+
**Unwrapping.** A reader with a secret key computes `OpenBase(enc, skR, info, "", ct)`. A stanza
|
|
89
|
+
of this type with other than one argument, an argument that isn't canonical base64 of 1120 bytes,
|
|
90
|
+
or a body that isn't 48 bytes is malformed, and decryption fails. A body that doesn't authenticate
|
|
91
|
+
means the stanza was wrapped to another key; the reader tries the next stanza. Readers try every
|
|
92
|
+
`mlkem768x25519` stanza, since the header doesn't say which key each one is for.
|
|
93
|
+
|
|
94
|
+
## Identity
|
|
95
|
+
|
|
96
|
+
A user's encryption identity is one **identity secret** of 32 random bytes. Everything else is
|
|
97
|
+
derived from it:
|
|
98
|
+
|
|
99
|
+
- **Recipient key:** the `mlkem768x25519` key pair whose secret key is
|
|
100
|
+
`HKDF(identity secret, empty, "seed-private/v1/identity/mlkem768x25519", 32)`. Version file keys
|
|
101
|
+
are wrapped to its public key.
|
|
102
|
+
- **Tag key:** the X25519 key pair whose private key is
|
|
103
|
+
`HKDF(identity secret, empty, "seed-private/v1/identity/x25519", 32)` (RFC 7748 clamping applies
|
|
104
|
+
when it is used). It is reserved for blinded tags.
|
|
105
|
+
- **Binding key:** the Ed25519 key pair (RFC 8032) whose 32-byte private key is
|
|
106
|
+
`HKDF(identity secret, empty, "seed-private/v1/identity/ed25519", 32)`. It signs key bindings
|
|
107
|
+
and nothing else.
|
|
108
|
+
- **Key id:** `0x` and the lowercase hex of `SHA-256("seed-private/v1/key-id" || 0x00 || recipient
|
|
109
|
+
public key || tag public key || binding public key)`.
|
|
110
|
+
|
|
111
|
+
**Key binding.** An account that registers an identity also publishes the binding key's Ed25519
|
|
112
|
+
signature over
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
"seed-private/v1/key-binding" || 0x00 || key id (32 bytes) || chain id (32 bytes, big-endian) || account (20 bytes)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
where the account is the registering account's address and the chain id is the chain the
|
|
119
|
+
registration is on. A reader accepts a registration only when the key id matches the three public
|
|
120
|
+
keys and the signature verifies for the registration's attester and chain. Without it, an account
|
|
121
|
+
could register another identity's public keys as its own, and content shared with that account
|
|
122
|
+
would be readable by the other identity instead. The X-Wing and X25519 keys can't sign, so the
|
|
123
|
+
binding key signs for them; the key id commits to all three.
|
|
124
|
+
|
|
125
|
+
**Recovery key.** A recovery phrase is 24 words from the BIP39 English list encoding 32 bytes of
|
|
126
|
+
entropy with BIP39's checksum. Readers compare words after NFKD normalization, lowercasing and
|
|
127
|
+
collapsing whitespace, and reject unknown words, a bad checksum and any other length. The recovery
|
|
128
|
+
key is the `mlkem768x25519` key pair whose secret key is
|
|
129
|
+
`HKDF(entropy, empty, "seed-private/v1/recovery/mlkem768x25519", 32)`. BIP39's PBKDF2 seed is not
|
|
130
|
+
used, so a wallet's phrase entered by mistake gives an unrelated key.
|
|
131
|
+
|
|
132
|
+
## Keystore manifest
|
|
133
|
+
|
|
134
|
+
The keystore manifest lets any authenticator the user enrolled recover the identity secret. It is a
|
|
135
|
+
`seed-private/v1` envelope with:
|
|
136
|
+
|
|
137
|
+
- **file key** `HKDF(identity secret, empty, "seed-private/v1/keystore", 32)`. It depends only on
|
|
138
|
+
the identity, so a device that holds the identity can write a revised manifest that copies the
|
|
139
|
+
existing stanzas unchanged and adds one;
|
|
140
|
+
- **bind** `{"envelopeId": <random per revision>, "keyId": <the key id>, "purpose": "keystore"}`;
|
|
141
|
+
- **content type** `application/vnd.seedprotocol.identity-secret` and the 32-byte identity secret
|
|
142
|
+
as the body;
|
|
143
|
+
- **one or more stanzas**, each of a type below.
|
|
144
|
+
|
|
145
|
+
The manifest is public, so a stanza may hold nothing that identifies the user beyond their account.
|
|
146
|
+
A reader that opens a manifest must check that the identity derived from the body has the bind's
|
|
147
|
+
key id, and that its keystore file key equals the one the stanza unwrapped; when it knows the key id
|
|
148
|
+
from the registration attestation it must also check the bind against it.
|
|
149
|
+
|
|
150
|
+
**Recovery stanza.** An `mlkem768x25519` stanza wrapping the keystore file key to the recovery
|
|
151
|
+
public key. Writing it needs only the public key, not the phrase.
|
|
152
|
+
|
|
153
|
+
**`passkey-prf`.** `-> passkey-prf <base64(credential id)> <base64(salt)>`, where the salt is 32
|
|
154
|
+
random bytes, with a 48-byte body `AES-256-GCM(KEK, nonce = 12 zero bytes, aad = "", file key)` and
|
|
155
|
+
`KEK = HKDF(PRF output, salt, "seed-private/v1/passkey-prf", 32)`. The PRF output is the WebAuthn
|
|
156
|
+
`prf` extension's `results.first` for the credential with `eval.first = salt`. A reader with
|
|
157
|
+
several `passkey-prf` stanzas asks for any of their credentials in one request, using
|
|
158
|
+
`evalByCredential`.
|
|
159
|
+
|
|
160
|
+
**`eoa-signature`.** Writers should offer this stanza only when the user chooses it over a passkey,
|
|
161
|
+
because it makes the identity no stronger than the EOA's secp256k1 key: anyone who has that key can
|
|
162
|
+
produce the signature below and open the public manifest, which reveals every private Version
|
|
163
|
+
wrapped to the identity. That includes a future attacker who recovers the key from the public key
|
|
164
|
+
any of the account's transactions expose. `-> eoa-signature <base64(salt)>`, with a 32-byte random salt and the same
|
|
165
|
+
body construction, with `KEK = HKDF(r || s, salt, "seed-private/v1/eoa-signature", 32)`. `r || s`
|
|
166
|
+
are the 64 bytes of the account's EIP-191 `personal_sign` signature over the message below, with
|
|
167
|
+
`s` replaced by `n - s` when it is above `n / 2` (`n` the secp256k1 order), and with the parity bit
|
|
168
|
+
cleared when the signature is in EIP-2098 compact form. `v` is not used. Only EOAs whose wallets
|
|
169
|
+
sign deterministically (RFC 6979) can use this stanza. The message, with LF line endings and the
|
|
170
|
+
salt as `0x` and lowercase hex:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Unlock your Seed Protocol encryption key
|
|
174
|
+
|
|
175
|
+
Signing this message lets this app read your private Versions. Anyone who gets this signature can read them too, so sign it only in apps you trust.
|
|
176
|
+
|
|
177
|
+
Key: 0x<salt>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
A zero nonce is safe in both stanzas because each KEK is used for one encryption: it depends on a
|
|
181
|
+
fresh random salt.
|
|
182
|
+
|
|
183
|
+
## Payload
|
|
184
|
+
|
|
185
|
+
The payload follows the MAC line's LF: the 16-byte payload nonce, then the chunks.
|
|
186
|
+
|
|
187
|
+
The plaintext is the content frame: a 4-byte big-endian length `n`, then `n` bytes of UTF-8 JSON
|
|
188
|
+
`{"bodyLength":<integer>,"contentType":"<MIME type>"}`, then `bodyLength` bytes of content, then
|
|
189
|
+
zero bytes of padding. The real content type is only here, never in the header or in upload tags.
|
|
190
|
+
`n` must not exceed 65536. A reader must reject a frame whose `bodyLength` is not a non-negative
|
|
191
|
+
integer, runs past the end of the plaintext, or is followed by a non-zero byte.
|
|
192
|
+
|
|
193
|
+
**Padding.** Writers should pad by default, so the ciphertext size shows a size class rather than
|
|
194
|
+
the exact length. Seed writers pad the frame's total length `L` (the 4 length bytes, the JSON and
|
|
195
|
+
the content) to PADMÉ(`L`): with `E = floor(log2 L)` and `S = floor(log2 E) + 1`, round `L` up to a
|
|
196
|
+
multiple of `2^(E - S)`. That adds at most 12%. `L` below 2 is left as is. A writer may skip
|
|
197
|
+
padding; readers handle both the same way.
|
|
198
|
+
|
|
199
|
+
The plaintext is split into 64 KiB (65536-byte) chunks. Every chunk but the last is full-size. The
|
|
200
|
+
last chunk is non-empty, unless it is the only chunk. Chunk `i` (from 0) is encrypted with
|
|
201
|
+
AES-256-GCM under the payload key, no associated data, and the 12-byte nonce `i` as an 11-byte
|
|
202
|
+
big-endian integer followed by `0x01` for the last chunk and `0x00` otherwise. Each sealed chunk is
|
|
203
|
+
the ciphertext followed by its 16-byte tag, so a non-final sealed chunk is 65552 bytes.
|
|
204
|
+
|
|
205
|
+
A reader decrypting chunk by chunk treats a chunk as the last when 65552 or fewer bytes remain. It
|
|
206
|
+
must fail when:
|
|
207
|
+
|
|
208
|
+
- a chunk does not authenticate;
|
|
209
|
+
- the payload ends after a full-size non-final chunk (truncated);
|
|
210
|
+
- bytes follow a full-size chunk that authenticates as final (trailing data);
|
|
211
|
+
- the last chunk is empty and is not the only chunk.
|
|
212
|
+
|
|
213
|
+
Bytes appended after a short final chunk make that chunk fail to authenticate, so they are reported
|
|
214
|
+
as a bad chunk. A reader must not release plaintext from a payload that later fails, unless it
|
|
215
|
+
tells its caller the content is incomplete.
|
|
216
|
+
|
|
217
|
+
## Uploads
|
|
218
|
+
|
|
219
|
+
An envelope is uploaded with `Content-Type: application/octet-stream` and the tag
|
|
220
|
+
`Seed-Encryption: seed-private/v1`. `Content-SHA-256` is the SHA-256 of the envelope bytes.
|
|
221
|
+
|
|
222
|
+
## Test vectors
|
|
223
|
+
|
|
224
|
+
`__tests__/vectors.json` lists inputs and the resulting envelopes: the hex for envelopes up to
|
|
225
|
+
4096 bytes, and the length and SHA-256 for all. All vectors use file key `00 01 ... 1f` and payload
|
|
226
|
+
nonce `a0 a1 ... af`, and each names its `padding` (`padme` or `none`). They were produced by
|
|
227
|
+
`__tests__/reference.ts`, a node:crypto implementation that shares no code with `src/`. The cases
|
|
228
|
+
cover a short text, an empty body with two stanzas and a stanza body that fills a whole line, an
|
|
229
|
+
unpadded plaintext of exactly one chunk and of one chunk plus one byte, and a 200000-byte body
|
|
230
|
+
padded to four chunks. `__tests__/envelope.test.ts` lists the failure cases above as tests.
|
|
231
|
+
|
|
232
|
+
`recipientVectors` gives two `mlkem768x25519` stanzas, wrapping the same file key, each with its
|
|
233
|
+
recipient seed, the SHA-256 of the public key and the 64 bytes of encapsulation randomness (the
|
|
234
|
+
first 32 for ML-KEM, the last 32 for the X25519 ephemeral key). `recipientEnvelope` is an
|
|
235
|
+
envelope carrying both. These stanzas were produced with hpke-js (`@hpke/core`,
|
|
236
|
+
`@hpke/hybridkem-x-wing`), which shares no code with `src/`; `__tests__/recipient.test.ts` also
|
|
237
|
+
checks the X-Wing KEM against the draft's first test vector.
|
|
238
|
+
|
|
239
|
+
`keystoreVector` is a keystore manifest built by the reference with its derived file key and the
|
|
240
|
+
same payload nonce. It lists the identity secret, its derived public keys and key id, the keystore
|
|
241
|
+
file key, one stanza of each type with its inputs, and `keyBinding`: the binding signature for an
|
|
242
|
+
account and chain id. The recovery entropy is BIP39's test vector `7f7f...7f` ("legal winner thank year ..."), and the
|
|
243
|
+
signature is from secp256k1 private key `77 77 ... 77`.
|
package/dist/base64.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Standard base64 alphabet without padding, as age uses in headers. Strict: rejects padding and non-canonical trailing bits. */
|
|
2
|
+
export declare function encodeBase64NoPad(bytes: Uint8Array): string;
|
|
3
|
+
/** Returns null when `text` is not canonical unpadded base64. */
|
|
4
|
+
export declare function decodeBase64NoPad(text: string): Uint8Array<ArrayBuffer> | null;
|
|
5
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,iIAAiI;AAMjI,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAgB3D;AAED,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAoB9E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps unlocked identities on this device in IndexedDB, each encrypted with its own
|
|
3
|
+
* non-extractable AES-GCM key stored beside it. That keeps the secret from being read out of the
|
|
4
|
+
* database by copying its files or calling `exportKey`, but any script on the origin can still
|
|
5
|
+
* decrypt it. Don't save an identity on a shared device; unlock it from the keystore manifest
|
|
6
|
+
* each session instead.
|
|
7
|
+
*/
|
|
8
|
+
import { type EncryptionIdentity } from './identity.js';
|
|
9
|
+
/** Saves `identity` on this device, replacing an earlier save of the same key id. */
|
|
10
|
+
export declare function saveIdentityOnDevice(identity: EncryptionIdentity): Promise<void>;
|
|
11
|
+
/** The identity saved under `keyId`, or null when this device has none. */
|
|
12
|
+
export declare function loadIdentityFromDevice(keyId: string): Promise<EncryptionIdentity | null>;
|
|
13
|
+
/** Key ids of the identities saved on this device. */
|
|
14
|
+
export declare function listIdentitiesOnDevice(): Promise<string[]>;
|
|
15
|
+
/** Deletes the identity saved under `keyId` from this device. Its keystore manifest is unaffected. */
|
|
16
|
+
export declare function forgetIdentityOnDevice(keyId: string): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=deviceStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceStore.d.ts","sourceRoot":"","sources":["../src/deviceStore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAgC,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAA;AA2ClF,qFAAqF;AACrF,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAStF;AAED,2EAA2E;AAC3E,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAkB9F;AAED,sDAAsD;AACtD,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAEhE;AAED,sGAAsG;AACtG,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may receive keys for an access policy. Adapters answer one question for one policy kind:
|
|
3
|
+
* was `address` entitled at `blockTag`? Licensing, subscriptions and token gates each register
|
|
4
|
+
* their own kind; key grants are issued only to addresses an adapter says yes to.
|
|
5
|
+
*/
|
|
6
|
+
/** The parts of an access policy an adapter reads. `kind` selects the adapter. */
|
|
7
|
+
export interface AccessPolicyRef {
|
|
8
|
+
policyId: string;
|
|
9
|
+
kind: string;
|
|
10
|
+
/** Adapter-specific configuration fixed when the policy was created (contract address, schema uid...). */
|
|
11
|
+
gateConfig?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** A block number, or a tag such as 'latest'. Entitlement decisions pin a block so they can be re-run. */
|
|
14
|
+
export type EntitlementBlockTag = bigint | 'latest';
|
|
15
|
+
export interface EntitlementAdapter {
|
|
16
|
+
isEntitled(policy: AccessPolicyRef, address: string, blockTag: EntitlementBlockTag): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
export declare class UnknownEntitlementKindError extends Error {
|
|
19
|
+
readonly kind: string;
|
|
20
|
+
constructor(kind: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Registers the adapter for a policy kind and returns a function that removes it. Registering a
|
|
24
|
+
* kind that already has an adapter throws, so two packages can't silently replace each other.
|
|
25
|
+
*/
|
|
26
|
+
export declare function registerEntitlementAdapter(kind: string, adapter: EntitlementAdapter): () => void;
|
|
27
|
+
/** Asks the adapter registered for `policy.kind`. Throws UnknownEntitlementKindError when there is none. */
|
|
28
|
+
export declare function isEntitled(policy: AccessPolicyRef, address: string, blockTag?: EntitlementBlockTag): Promise<boolean>;
|
|
29
|
+
//# sourceMappingURL=entitlement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement.d.ts","sourceRoot":"","sources":["../src/entitlement.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kFAAkF;AAClF,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,0GAA0G;IAC1G,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,0GAA0G;AAC1G,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEnD,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACtG;AAED,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBACT,IAAI,EAAE,MAAM;CAKzB;AAID;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAOhG;AAED,4GAA4G;AAC5G,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,mBAA8B,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/H"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `seed-private/v1` envelope: an age-style header of recipient stanzas, authenticated with an
|
|
3
|
+
* HMAC under the file key, followed by a chunked AES-256-GCM payload. SPEC.md is the normative
|
|
4
|
+
* description; this file implements it with WebCrypto only.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ENVELOPE_FORMAT = "seed-private/v1";
|
|
7
|
+
/** Content-Type for an uploaded envelope. The real type is inside the encrypted payload. */
|
|
8
|
+
export declare const ENVELOPE_CONTENT_TYPE = "application/octet-stream";
|
|
9
|
+
/** Upload tag that marks an envelope, so readers know to decrypt before sniffing. */
|
|
10
|
+
export declare const ENVELOPE_FORMAT_TAG: {
|
|
11
|
+
readonly name: "Seed-Encryption";
|
|
12
|
+
readonly value: "seed-private/v1";
|
|
13
|
+
};
|
|
14
|
+
export declare const FILE_KEY_LENGTH = 32;
|
|
15
|
+
export declare const CHUNK_SIZE: number;
|
|
16
|
+
export type EnvelopeErrorCode = 'NOT_ENVELOPE' | 'BAD_HEADER' | 'BAD_BIND' | 'BIND_MISMATCH' | 'NO_KEY' | 'BAD_FILE_KEY' | 'BAD_RECIPIENT_KEY' | 'HEADER_MAC' | 'TRUNCATED' | 'BAD_CHUNK' | 'TRAILING_DATA' | 'BAD_CONTENT_FRAME' | 'BAD_RECOVERY_PHRASE' | 'BAD_KEYSTORE' | 'PASSKEY_PRF_UNSUPPORTED';
|
|
17
|
+
export declare class EnvelopeError extends Error {
|
|
18
|
+
readonly code: EnvelopeErrorCode;
|
|
19
|
+
constructor(code: EnvelopeErrorCode, message: string);
|
|
20
|
+
}
|
|
21
|
+
/** One recipient's wrap of the file key. Types are defined in SPEC.md; this layer treats them as opaque. */
|
|
22
|
+
export interface Stanza {
|
|
23
|
+
type: string;
|
|
24
|
+
args: string[];
|
|
25
|
+
body: Uint8Array;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Values the envelope is bound to, known before upload. `envelopeId` is required and is recorded
|
|
29
|
+
* in the envelope attestation, so a ciphertext can't be presented as another Version's.
|
|
30
|
+
*/
|
|
31
|
+
export type EnvelopeBind = {
|
|
32
|
+
envelopeId: string;
|
|
33
|
+
} & Record<string, string>;
|
|
34
|
+
export interface EnvelopeHeader {
|
|
35
|
+
bind: EnvelopeBind;
|
|
36
|
+
stanzas: Stanza[];
|
|
37
|
+
}
|
|
38
|
+
export interface EncryptEnvelopeInput {
|
|
39
|
+
/** 32 random bytes, from `generateFileKey()`. One per private Version. */
|
|
40
|
+
fileKey: Uint8Array;
|
|
41
|
+
bind: EnvelopeBind;
|
|
42
|
+
/** At least one. Always include the publisher's own wrap. */
|
|
43
|
+
stanzas: Stanza[];
|
|
44
|
+
/** The plaintext's real MIME type; stored inside the encrypted payload. */
|
|
45
|
+
contentType: string;
|
|
46
|
+
body: Uint8Array;
|
|
47
|
+
/**
|
|
48
|
+
* `'padme'` (default) zero-pads the plaintext to its PADMÉ length, so the ciphertext size
|
|
49
|
+
* reveals only a size class (at most 12% extra bytes). `'none'` leaves the exact length visible.
|
|
50
|
+
*/
|
|
51
|
+
padding?: EnvelopePadding;
|
|
52
|
+
}
|
|
53
|
+
export type EnvelopePadding = 'padme' | 'none';
|
|
54
|
+
export interface DecryptEnvelopeOptions {
|
|
55
|
+
/** The file key, when the caller already unwrapped it. */
|
|
56
|
+
fileKey?: Uint8Array;
|
|
57
|
+
/** Called with the parsed header when `fileKey` is not given; returns the unwrapped file key or null. */
|
|
58
|
+
unwrap?: (header: EnvelopeHeader) => Promise<Uint8Array | null> | Uint8Array | null;
|
|
59
|
+
/** Every key given must equal the envelope's bind value, or decryption fails with BIND_MISMATCH. */
|
|
60
|
+
expectBind?: Partial<EnvelopeBind>;
|
|
61
|
+
}
|
|
62
|
+
export interface DecryptedEnvelope {
|
|
63
|
+
bind: EnvelopeBind;
|
|
64
|
+
contentType: string;
|
|
65
|
+
body: Uint8Array;
|
|
66
|
+
}
|
|
67
|
+
export declare function generateFileKey(): Uint8Array;
|
|
68
|
+
/** A random `0x`-prefixed 32-byte hex id, chosen before encryption and attested with the Version. */
|
|
69
|
+
export declare function generateEnvelopeId(): string;
|
|
70
|
+
/** True when `bytes` start with the envelope's version line. Doesn't validate the rest. */
|
|
71
|
+
export declare function isEnvelope(bytes: Uint8Array): boolean;
|
|
72
|
+
/** Sorted keys, string values, no whitespace. The bytes feed the payload key derivation. */
|
|
73
|
+
export declare function canonicalBind(bind: EnvelopeBind): string;
|
|
74
|
+
export declare function hkdf(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Promise<Uint8Array<ArrayBuffer>>;
|
|
75
|
+
/**
|
|
76
|
+
* PADMÉ (Nikitin et al., "Reducing Metadata Leakage from Encrypted Files and Communication with
|
|
77
|
+
* PURBs", 2019): round `length` up so only the top `floor(log2(E)) + 1` bits of its exponent `E`
|
|
78
|
+
* vary. Overhead is at most 12%.
|
|
79
|
+
*/
|
|
80
|
+
export declare function padmeLength(length: number): number;
|
|
81
|
+
/** Encrypt with a caller-chosen payload nonce. Exported for test vectors only; use `encryptEnvelope`. */
|
|
82
|
+
export declare function encryptEnvelopeWithNonce(input: EncryptEnvelopeInput, payloadNonce: Uint8Array): Promise<Uint8Array>;
|
|
83
|
+
export declare function encryptEnvelope(input: EncryptEnvelopeInput): Promise<Uint8Array>;
|
|
84
|
+
/** Reads the bind values and stanzas without a key, so a reader can pick the stanza to unwrap. */
|
|
85
|
+
export declare function parseEnvelopeHeader(bytes: Uint8Array): EnvelopeHeader;
|
|
86
|
+
export declare function decryptEnvelope(bytes: Uint8Array, options: DecryptEnvelopeOptions): Promise<DecryptedEnvelope>;
|
|
87
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens downloaded envelopes for the SDK (`setEnvelopeDecryptor` in `@seedprotocol/sdk`): tries
|
|
3
|
+
* each unlocked identity's recipient key and returns the plaintext with the content type recorded
|
|
4
|
+
* inside, or null when none of them is a recipient.
|
|
5
|
+
*/
|
|
6
|
+
import type { EncryptionIdentity } from './identity.js';
|
|
7
|
+
/** What `setEnvelopeDecryptor` takes. Structural, so no SDK import. */
|
|
8
|
+
export type EnvelopeOpener = (envelope: Uint8Array) => Promise<{
|
|
9
|
+
contentType: string;
|
|
10
|
+
body: Uint8Array;
|
|
11
|
+
} | null>;
|
|
12
|
+
export declare function createEnvelopeDecryptor(identities: EncryptionIdentity[]): EnvelopeOpener;
|
|
13
|
+
//# sourceMappingURL=envelopeDecryptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelopeDecryptor.d.ts","sourceRoot":"","sources":["../src/envelopeDecryptor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGpD,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,UAAU,KAAK,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG,IAAI,CAAC,CAAA;AAEhH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,EAAE,GAAG,cAAc,CAWxF"}
|
package/dist/hpke.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-shot HPKE (RFC 9180) in base mode, for one suite: KEM MLKEM768-X25519 (X-Wing, `0x647a`),
|
|
3
|
+
* KDF HKDF-SHA256 (`0x0001`), AEAD AES-256-GCM (`0x0002`). Only the first message of a context is
|
|
4
|
+
* sealed or opened, so the nonce is the base nonce. The KEM comes from `@noble/post-quantum`; the
|
|
5
|
+
* key schedule and AEAD use WebCrypto.
|
|
6
|
+
*/
|
|
7
|
+
export declare const XWING_KEM_ID = 25722;
|
|
8
|
+
export declare const XWING_PUBLIC_KEY_LENGTH = 1216;
|
|
9
|
+
export declare const XWING_SECRET_KEY_LENGTH = 32;
|
|
10
|
+
export declare const XWING_ENC_LENGTH = 1120;
|
|
11
|
+
export declare function xwingKeyPair(seed: Uint8Array): {
|
|
12
|
+
secretKey: Uint8Array;
|
|
13
|
+
publicKey: Uint8Array;
|
|
14
|
+
};
|
|
15
|
+
/** RFC 9180 SealBase. `randomness` is for test vectors only; leave it out to use the CSPRNG. */
|
|
16
|
+
export declare function sealBase(publicKey: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array, randomness?: Uint8Array): Promise<{
|
|
17
|
+
enc: Uint8Array;
|
|
18
|
+
ciphertext: Uint8Array;
|
|
19
|
+
}>;
|
|
20
|
+
/** RFC 9180 OpenBase. Returns null when the ciphertext doesn't authenticate under this key. */
|
|
21
|
+
export declare function openBase(enc: Uint8Array, secretKey: Uint8Array, info: Uint8Array, aad: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array | null>;
|
|
22
|
+
//# sourceMappingURL=hpke.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke.d.ts","sourceRoot":"","sources":["../src/hpke.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,eAAO,MAAM,YAAY,QAAS,CAAA;AAOlC,eAAO,MAAM,uBAAuB,OAAO,CAAA;AAC3C,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC,eAAO,MAAM,gBAAgB,OAAO,CAAA;AAkDpC,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG;IAAE,SAAS,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,UAAU,CAAA;CAAE,CAG/F;AAED,gGAAgG;AAChG,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,UAAU,EACrB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,UAAU,EACrB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAKtD;AAED,+FAA+F;AAC/F,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,UAAU,EACrB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,EACf,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAU5B"}
|