@open-e2ee/signal-protocol-sdk 2.0.0 → 2.0.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 +19 -0
- package/README.md +38 -34
- package/dist/internal/crypto/pq/kyber.d.ts.map +1 -1
- package/dist/internal/crypto/pq/kyber.js +5 -7
- package/dist/internal/crypto/pq/kyber.js.map +1 -1
- package/dist/internal/crypto/random-host.d.ts +2 -0
- package/dist/internal/crypto/random-host.d.ts.map +1 -0
- package/dist/internal/crypto/random-host.js +12 -0
- package/dist/internal/crypto/random-host.js.map +1 -0
- package/dist/internal/crypto/random-host.native.d.ts +2 -0
- package/dist/internal/crypto/random-host.native.d.ts.map +1 -0
- package/dist/internal/crypto/random-host.native.js +16 -0
- package/dist/internal/crypto/random-host.native.js.map +1 -0
- package/dist/internal/crypto/random-host.node.d.ts +2 -0
- package/dist/internal/crypto/random-host.node.d.ts.map +1 -0
- package/dist/internal/crypto/random-host.node.js +9 -0
- package/dist/internal/crypto/random-host.node.js.map +1 -0
- package/dist/internal/crypto/random.d.ts +1 -20
- package/dist/internal/crypto/random.d.ts.map +1 -1
- package/dist/internal/crypto/random.js +5 -41
- package/dist/internal/crypto/random.js.map +1 -1
- package/dist/internal/crypto/symmetric/aes-provider.d.ts +5 -0
- package/dist/internal/crypto/symmetric/aes-provider.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/aes-provider.js +26 -0
- package/dist/internal/crypto/symmetric/aes-provider.js.map +1 -0
- package/dist/internal/crypto/symmetric/aes.d.ts +0 -8
- package/dist/internal/crypto/symmetric/aes.d.ts.map +1 -1
- package/dist/internal/crypto/symmetric/aes.js +12 -81
- package/dist/internal/crypto/symmetric/aes.js.map +1 -1
- package/dist/layers.d.ts +5 -1
- package/dist/layers.d.ts.map +1 -1
- package/dist/layers.js +5 -1
- package/dist/layers.js.map +1 -1
- package/dist/local/store/expo/models/recipient-identity.js +2 -2
- package/dist/local/store/expo/models/recipient-identity.js.map +1 -1
- package/dist/local/store/expo/schema.d.ts +62 -0
- package/dist/local/store/expo/schema.d.ts.map +1 -1
- package/dist/local/store/expo/schema.js +5 -0
- package/dist/local/store/expo/schema.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +0 -7
- package/dist/logger.js.map +1 -1
- package/dist/remote/relay/memory/adapter.d.ts +0 -1
- package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
- package/dist/remote/relay/memory/adapter.js +2 -3
- package/dist/remote/relay/memory/adapter.js.map +1 -1
- package/docs/ASSURANCE.md +80 -140
- package/examples/browser/README.md +35 -0
- package/examples/browser/index.html +27 -0
- package/examples/browser/src/exchange.ts +69 -0
- package/examples/browser/src/main.ts +63 -0
- package/examples/browser/src/style.css +9 -0
- package/examples/browser/src/worker.ts +10 -0
- package/examples/browser/vite.config.ts +9 -0
- package/package.json +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
- Correct the browser and Expo example package integrity for the release environment.
|
|
6
|
+
- Check example pins before publication and publish the checked tarball.
|
|
7
|
+
This release changes package metadata and publication checks.
|
|
8
|
+
|
|
9
|
+
## 2.0.1
|
|
10
|
+
|
|
11
|
+
- Select secure randomness for browsers, Node, and Expo through package imports.
|
|
12
|
+
ML-KEM receives explicit random input on Hermes.
|
|
13
|
+
React Native uses the application's Web Crypto provider before loading Expo crypto.
|
|
14
|
+
- Use Noble AES when the runtime has no Web Crypto implementation.
|
|
15
|
+
- Export the metadata table required by Expo storage. Read recipient identities
|
|
16
|
+
with the column names returned by SQLite.
|
|
17
|
+
- Keep in-memory relay message identifiers unique across resets and restarts.
|
|
18
|
+
Persistent clients no longer discard new replies as duplicate deliveries.
|
|
19
|
+
- Add runnable browser and Expo examples, including encrypted replies and
|
|
20
|
+
SQLCipher persistence. Explain private testing and public verification.
|
|
21
|
+
|
|
3
22
|
## 2.0.0
|
|
4
23
|
|
|
5
24
|
- Six Jazzer.js targets run for 150 seconds each on Ubuntu 24.04.
|
package/README.md
CHANGED
|
@@ -1,50 +1,58 @@
|
|
|
1
|
-
<
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/open-e2ee/design/v0.21.2/brand/generated/hosted/open-e2ee-logo-dark.svg">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/open-e2ee/design/v0.21.2/brand/generated/hosted/open-e2ee-logo-light.svg" alt="OpenE2EE" width="340">
|
|
4
|
+
</picture>
|
|
2
5
|
|
|
3
6
|
# OpenE2EE Signal Protocol SDK
|
|
4
7
|
|
|
5
|
-
**
|
|
8
|
+
**Pure TypeScript for end-to-end encrypted chat.**
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
Add encrypted messaging to Expo, React Native, browser, and Node applications. The SDK manages device identities, session establishment, and message encryption. Your application supplies storage, user authentication, and a relay for delivery.
|
|
11
|
+
|
|
12
|
+
The default policy requires post-quantum session establishment and ratcheting. The protocol implementation is open source under AGPLv3, with a [commercial license](./COMMERCIAL.md) available.
|
|
13
|
+
|
|
14
|
+
[**Run an encrypted exchange in your browser**](https://open-e2ee.dev/playground) · [Edit on StackBlitz](https://stackblitz.com/fork/github/open-e2ee/signal-protocol-js/tree/v2.0.2/examples/browser) · [Run on Expo / Hermes](./examples/expo/README.md)
|
|
15
|
+
|
|
16
|
+
[](./LICENSE)
|
|
8
17
|
[](https://www.npmjs.com/package/@open-e2ee/signal-protocol-sdk)
|
|
9
|
-
[](./ARCHITECTURE.md)
|
|
10
18
|
[](https://www.npmjs.com/package/@open-e2ee/signal-protocol-sdk#provenance)
|
|
11
19
|
[](https://github.com/open-e2ee/signal-protocol-js/actions/workflows/ci.yml)
|
|
12
20
|
|
|
13
|
-
[
|
|
14
|
-
[Documentation](https://docs.open-e2ee.dev) ·
|
|
15
|
-
[Live demo](https://open-e2ee.dev/#demo) ·
|
|
16
|
-
[OpenE2EE Relay](https://open-e2ee.dev/relay) ·
|
|
17
|
-
[API reference](https://docs.open-e2ee.dev/reference/api) ·
|
|
18
|
-
[Security](./SECURITY.md)
|
|
21
|
+
[Documentation](https://docs.open-e2ee.dev) · [API reference](https://docs.open-e2ee.dev/reference/api) · [OpenE2EE Relay](https://open-e2ee.dev/relay) · [Security](./SECURITY.md)
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
- **Post-quantum by default.** The default policy requires PQXDH session establishment and the ML-KEM Braid post-quantum ratchet. Required post-quantum operations fail closed.
|
|
22
|
-
- **Messaging primitives included.** Build multi-device messaging, groups, sealed sender, encrypted attachments, and safety-number verification.
|
|
23
|
-
- **Explicit infrastructure boundaries.** Your application owns device-local storage. Supply your own relay adapter or use [OpenE2EE Relay](https://open-e2ee.dev/relay) for managed encrypted delivery. The relay never needs message plaintext or device private keys.
|
|
24
|
-
- **AGPLv3, or a commercial license.** Proprietary applications that cannot meet AGPLv3 obligations can use a [commercial license](./COMMERCIAL.md).
|
|
23
|
+
## See an encrypted round trip
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
Press play for device setup, session establishment, encrypted delivery, and decryption on each device.
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
https://github.com/user-attachments/assets/d8002bc3-c037-41b6-8f48-4008f2d49e6c
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
The [visual demo](https://open-e2ee.dev/#demo) shows the envelope, ratchets, relay mailbox, and decrypted result. On desktop, type a message and inspect each step. On mobile, a recorded protocol run replays at reading pace. Displayed timings exclude network time.
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
The [console example](https://open-e2ee.dev/playground) executes in your browser on desktop or mobile. It creates Alice and Bob, sends your message, and decrypts a reply. The page and developer console show the actual output. [Read the complete source](./examples/browser/src/exchange.ts) or [run it locally](./examples/browser/README.md).
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
Both examples use real protocol code and cryptography. An in-memory relay holds their envelopes. They need no account or backend project.
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
## What the SDK handles
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
- **Session establishment and ratcheting.** PQXDH establishes sessions. The ML-KEM Braid ratchet adds post-quantum key updates. Required post-quantum operations fail closed.
|
|
38
|
+
- **Chat features.** Multi-device messaging, groups, sealed sender, encrypted attachments, and safety-number verification use the same package.
|
|
39
|
+
- **Device-local state.** Storage adapters keep identities, sessions, and message state on the device.
|
|
40
|
+
- **Delivery through an adapter.** Operate your own relay or use [OpenE2EE Relay](https://open-e2ee.dev/relay).
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
The relay never needs message plaintext or device private keys.
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
OpenE2EE implements a versioned profile of the published Signal Protocol specifications. It is not affiliated with Signal Messenger and is **not wire-compatible with Signal Messenger or libsignal**. Messages, identities, and safety numbers do not interoperate. See the [notice](./NOTICE) and [documented deviations](./docs/DEVIATIONS.md).
|
|
45
|
+
|
|
46
|
+
Version `2.0.x`. Public APIs and persisted formats follow semantic versioning.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
43
49
|
|
|
44
50
|
```bash
|
|
45
51
|
npm install @open-e2ee/signal-protocol-sdk
|
|
46
52
|
```
|
|
47
53
|
|
|
54
|
+
Use a current Node LTS release for local development. Each runtime example lists its build requirements.
|
|
55
|
+
|
|
48
56
|
## Run a local encrypted round trip
|
|
49
57
|
|
|
50
58
|
Save this as `quickstart.mjs`, then run `node quickstart.mjs`. It uses development-only in-memory adapters so that you can prove the message flow without a backend project.
|
|
@@ -92,14 +100,14 @@ The client factory creates or loads each device identity. When given a relay, it
|
|
|
92
100
|
|
|
93
101
|
The in-memory store loses identities, sessions, and ratchet state on restart. The in-memory relay has no authentication, authorization, or durable storage. Do not ship either adapter. Continue with the [documentation quickstart](https://docs.open-e2ee.dev/start/quickstart), which explains key custody, relay metadata, prekey replenishment, additional devices, and recovery policy.
|
|
94
102
|
|
|
95
|
-
##
|
|
103
|
+
## Use your app’s storage and relay
|
|
96
104
|
|
|
97
105
|
Choose the device-local store for your runtime. Then supply a relay that authenticates each device and implements your product's access policy, or use [OpenE2EE Relay](https://open-e2ee.dev/relay) as the managed delivery path. The SDK does not require the managed service. [Review Relay plans and exact meter definitions.](https://open-e2ee.dev/relay/pricing)
|
|
98
106
|
|
|
99
107
|
| Runtime | Storage path | Deployment boundary |
|
|
100
108
|
|---|---|---|
|
|
101
|
-
| Expo | [`expoStore`](./local/store/expo/README.md) | Configure SQLCipher before schema access. Requires a development build;
|
|
102
|
-
| Browser | [`indexedDbStore`](./local/store/web/README.md) |
|
|
109
|
+
| Expo | [`expoStore`](./local/store/expo/README.md) | Configure SQLCipher before schema access. Requires a native development or release build. [Run the Hermes example](./examples/expo/README.md); Expo Go does not include SQLCipher. |
|
|
110
|
+
| Browser | [`indexedDbStore`](./local/store/web/README.md) | Use a secure context and a restrictive CSP. Same-origin JavaScript can access stored records and their key. [Browser setup](https://docs.open-e2ee.dev/start/browser). |
|
|
103
111
|
| Bare React Native | [`reactNativeStore`](./local/store/react-native/README.md) | Provide an atomic, durable key-value backend and run the exported backend conformance kit. |
|
|
104
112
|
| Node | [`nodeStore`](./local/store/node/README.md) | Set an explicit private data directory on a trusted local filesystem. |
|
|
105
113
|
|
|
@@ -107,18 +115,14 @@ The [adapter guide](./ADAPTERS.md) defines every storage, relay, vault, and obje
|
|
|
107
115
|
|
|
108
116
|
## Security and assurance
|
|
109
117
|
|
|
110
|
-
The [
|
|
118
|
+
The SDK is open source. Our engineering tests remain private. We publish the [testing methodology and dated results](./docs/ASSURANCE.md), including what readers can and cannot verify from this repository. Public CI rebuilds the package, checks types and dependencies, and runs the documented examples.
|
|
119
|
+
|
|
120
|
+
> Reviewed continuously by adversarial AI agents; not audited by any independent firm.
|
|
111
121
|
|
|
112
122
|
JavaScript engines do not provide a machine-level constant-time contract or guaranteed zeroization. The [security model](./docs/SECURITY.md) defines the timing, same-process, storage, and metadata boundaries. The [protocol policy](./docs/PROTOCOL_POLICY.md) defines supported modes and fail-closed behavior.
|
|
113
123
|
|
|
114
124
|
Report a suspected vulnerability privately through the process in [SECURITY](./SECURITY.md). Do not open a public issue for it.
|
|
115
125
|
|
|
116
|
-
## Why developers choose this SDK
|
|
117
|
-
|
|
118
|
-
The SDK gives TypeScript applications one maintained package for required post-quantum session establishment and ratcheting, multi-device messaging, groups, sealed sender, attachments, and safety numbers. It keeps protocol state on the device. Applications can operate a relay adapter or use OpenE2EE Relay for managed delivery.
|
|
119
|
-
|
|
120
|
-
[Compare maintained alternatives and their limits.](https://open-e2ee.dev/product/#how-it-compares)
|
|
121
|
-
|
|
122
126
|
## Documentation
|
|
123
127
|
|
|
124
128
|
- [Getting started](./docs/GETTING_STARTED.md): the integration sequence and mental model.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kyber.d.ts","sourceRoot":"","sources":["../../../../internal/crypto/pq/kyber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;
|
|
1
|
+
{"version":3,"file":"kyber.d.ts","sourceRoot":"","sources":["../../../../internal/crypto/pq/kyber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,OAAO,EAAE,CAAC;AACV,OAAO,CAAC,MAAM,oBAAoB,EAAE,OAAO,MAAM,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG;IAC3C,QAAQ,CAAC,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC;CACvC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,iBAAiB,CAKxE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAE7D;AAMD;;;GAGG;AACH,eAAO,MAAM,gCAAgC,OAAO,CAAC;AACrD,eAAO,MAAM,yBA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AuB,IAAI,OAAO,CAAC;IACvD,SAAS,EAAE,UAAU,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC,CAOD;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,mBAAmB,CAAC,cAAc,EAAE,UAAU,GAAG,OAAO,CAAC;IAC7E,YAAY,EAAE,iBAAiB,CAAC;IAChC,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC,CAeD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,UAAU,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAmB5B;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,UAAU,GAAG,UAAU,CAMjG"}
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* @see https://csrc.nist.gov/pubs/fips/203/final - NIST FIPS 203
|
|
22
22
|
*/
|
|
23
23
|
import { ml_kem768, ml_kem1024 } from '@noble/post-quantum/ml-kem.js';
|
|
24
|
+
import { generateRandomBytes } from '../random.js';
|
|
24
25
|
/**
|
|
25
26
|
* Assert raw bytes as Kyber shared secret.
|
|
26
27
|
*
|
|
@@ -140,9 +141,7 @@ export function parseMlKem1024Ciphertext(serialized) {
|
|
|
140
141
|
return serialized.slice(1);
|
|
141
142
|
}
|
|
142
143
|
export async function generateMlKem1024KeyPair() {
|
|
143
|
-
|
|
144
|
-
// Note: ml_kem1024.keygen() accepts optional 64-byte seed for deterministic generation
|
|
145
|
-
const keyPair = ml_kem1024.keygen();
|
|
144
|
+
const keyPair = ml_kem1024.keygen(await generateRandomBytes(64));
|
|
146
145
|
return {
|
|
147
146
|
publicKey: serializeMlKem1024PublicKey(keyPair.publicKey),
|
|
148
147
|
privateKey: keyPair.secretKey,
|
|
@@ -168,7 +167,7 @@ export async function generateMlKem1024KeyPair() {
|
|
|
168
167
|
*/
|
|
169
168
|
export async function mlKem1024Encapsulate(serializedPublicKey) {
|
|
170
169
|
const rawPublicKey = parseMlKem1024PublicKey(serializedPublicKey);
|
|
171
|
-
const result = ml_kem1024.encapsulate(rawPublicKey);
|
|
170
|
+
const result = ml_kem1024.encapsulate(rawPublicKey, await generateRandomBytes(32));
|
|
172
171
|
return {
|
|
173
172
|
sharedSecret: asKyberSharedSecret(result.sharedSecret), // 32 bytes
|
|
174
173
|
ciphertext: serializeMlKem1024Ciphertext(result.cipherText),
|
|
@@ -218,8 +217,7 @@ export async function mlKem1024Decapsulate(serializedCiphertext, privateKey) {
|
|
|
218
217
|
* @see https://csrc.nist.gov/pubs/fips/203/final - NIST FIPS 203
|
|
219
218
|
*/
|
|
220
219
|
export async function generateKyber768KeyPair() {
|
|
221
|
-
|
|
222
|
-
const keyPair = ml_kem768.keygen();
|
|
220
|
+
const keyPair = ml_kem768.keygen(await generateRandomBytes(64));
|
|
223
221
|
return {
|
|
224
222
|
publicKey: keyPair.publicKey, // KYBER_768_PUBLIC_KEY_BYTES (1184)
|
|
225
223
|
privateKey: keyPair.secretKey, // KYBER_768_SECRET_KEY_BYTES (2400)
|
|
@@ -250,7 +248,7 @@ export async function kyber768Encapsulate(kyberPublicKey) {
|
|
|
250
248
|
throw new Error(`Invalid Kyber-768 public key: expected ${KYBER_768_PUBLIC_KEY_BYTES} bytes, got ${kyberPublicKey.length}`);
|
|
251
249
|
}
|
|
252
250
|
// ML-KEM-768 encapsulation
|
|
253
|
-
const result = ml_kem768.encapsulate(kyberPublicKey);
|
|
251
|
+
const result = ml_kem768.encapsulate(kyberPublicKey, await generateRandomBytes(32));
|
|
254
252
|
return {
|
|
255
253
|
sharedSecret: asKyberSharedSecret(result.sharedSecret), // 32 bytes
|
|
256
254
|
ciphertext: result.cipherText, // 1088 bytes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kyber.js","sourceRoot":"","sources":["../../../../internal/crypto/pq/kyber.ts"],"names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Ae,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAUvE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export async function hostRandomBytes(size) {
|
|
2
|
+
const crypto = globalThis.crypto;
|
|
3
|
+
if (!crypto?.getRandomValues) {
|
|
4
|
+
throw new Error('No cryptographically secure random source is available in this runtime.');
|
|
5
|
+
}
|
|
6
|
+
const bytes = new Uint8Array(size);
|
|
7
|
+
for (let offset = 0; offset < size; offset += 65_536) {
|
|
8
|
+
crypto.getRandomValues(bytes.subarray(offset, Math.min(size, offset + 65_536)));
|
|
9
|
+
}
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=random-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-host.js","sourceRoot":"","sources":["../../../internal/crypto/random-host.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IACjC,IAAI,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,MAAM,EAAE,CAAC;QACrD,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-host.native.d.ts","sourceRoot":"","sources":["../../../internal/crypto/random-host.native.ts"],"names":[],"mappings":"AAAA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAevE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export async function hostRandomBytes(size) {
|
|
2
|
+
const crypto = globalThis.crypto;
|
|
3
|
+
const bytes = new Uint8Array(size);
|
|
4
|
+
if (crypto?.getRandomValues) {
|
|
5
|
+
for (let offset = 0; offset < size; offset += 65_536) {
|
|
6
|
+
crypto.getRandomValues(bytes.subarray(offset, Math.min(size, offset + 65_536)));
|
|
7
|
+
}
|
|
8
|
+
return bytes;
|
|
9
|
+
}
|
|
10
|
+
const { getRandomBytesAsync } = await import('expo-crypto');
|
|
11
|
+
for (let offset = 0; offset < size; offset += 1024) {
|
|
12
|
+
bytes.set(await getRandomBytesAsync(Math.min(1024, size - offset)), offset);
|
|
13
|
+
}
|
|
14
|
+
return bytes;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=random-host.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-host.native.js","sourceRoot":"","sources":["../../../internal/crypto/random-host.native.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,MAAM,EAAE,eAAe,EAAE,CAAC;QAC5B,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,MAAM,EAAE,CAAC;YACrD,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAC5D,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC;QACnD,KAAK,CAAC,GAAG,CAAC,MAAM,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-host.node.d.ts","sourceRoot":"","sources":["../../../internal/crypto/random-host.node.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMvE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { webcrypto } from 'node:crypto';
|
|
2
|
+
export async function hostRandomBytes(size) {
|
|
3
|
+
const bytes = new Uint8Array(size);
|
|
4
|
+
for (let offset = 0; offset < size; offset += 65_536) {
|
|
5
|
+
webcrypto.getRandomValues(bytes.subarray(offset, Math.min(size, offset + 65_536)));
|
|
6
|
+
}
|
|
7
|
+
return bytes;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=random-host.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-host.node.js","sourceRoot":"","sources":["../../../internal/crypto/random-host.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,MAAM,EAAE,CAAC;QACrD,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Secure Random Number Generation
|
|
3
|
-
*
|
|
4
|
-
* Provides cryptographically secure random bytes using Web Crypto when
|
|
5
|
-
* available, with Node and Expo fallbacks for non-browser runtimes.
|
|
6
|
-
*
|
|
7
|
-
* @see https://signal.org/docs/specifications/doubleratchet/#external-functions
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Generate cryptographically secure random bytes
|
|
11
|
-
*
|
|
12
|
-
* Resolution order:
|
|
13
|
-
* - `globalThis.crypto.getRandomValues` (browser / modern Node / many RN runtimes)
|
|
14
|
-
* - `node:crypto.webcrypto` (Node fallback)
|
|
15
|
-
* - `expo-crypto.getRandomBytesAsync` (Expo fallback)
|
|
16
|
-
*
|
|
17
|
-
* @param size Number of random bytes to generate
|
|
18
|
-
* @returns Promise resolving to random bytes
|
|
19
|
-
*/
|
|
20
|
-
export {};
|
|
1
|
+
/** Generate secure random bytes from the runtime host. */
|
|
21
2
|
export declare function generateRandomBytes(size: number): Promise<Uint8Array>;
|
|
22
3
|
/**
|
|
23
4
|
* Generate a random RFC 4122 version 4 UUID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../internal/crypto/random.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../internal/crypto/random.ts"],"names":[],"mappings":"AAEA,0DAA0D;AAC1D,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAK3E;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAStD"}
|
|
@@ -1,46 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Provides cryptographically secure random bytes using Web Crypto when
|
|
5
|
-
* available, with Node and Expo fallbacks for non-browser runtimes.
|
|
6
|
-
*
|
|
7
|
-
* @see https://signal.org/docs/specifications/doubleratchet/#external-functions
|
|
8
|
-
*/
|
|
9
|
-
const MAX_GET_RANDOM_VALUES_BYTES = 65_536;
|
|
10
|
-
function fillRandomBytes(fillChunk, size) {
|
|
11
|
-
const bytes = new Uint8Array(size);
|
|
12
|
-
for (let offset = 0; offset < size; offset += MAX_GET_RANDOM_VALUES_BYTES) {
|
|
13
|
-
const chunkSize = Math.min(size - offset, MAX_GET_RANDOM_VALUES_BYTES);
|
|
14
|
-
const chunk = new Uint8Array(new ArrayBuffer(chunkSize));
|
|
15
|
-
fillChunk(chunk);
|
|
16
|
-
bytes.set(chunk, offset);
|
|
17
|
-
}
|
|
18
|
-
return bytes;
|
|
19
|
-
}
|
|
1
|
+
import { hostRandomBytes } from '#secure-random-host';
|
|
2
|
+
/** Generate secure random bytes from the runtime host. */
|
|
20
3
|
export async function generateRandomBytes(size) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return fillRandomBytes((buffer) => {
|
|
24
|
-
webCrypto.getRandomValues(buffer);
|
|
25
|
-
}, size);
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
const { webcrypto } = await import('node:crypto');
|
|
29
|
-
return fillRandomBytes((buffer) => {
|
|
30
|
-
webcrypto.getRandomValues(buffer);
|
|
31
|
-
}, size);
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
// Ignore and fall through to Expo fallback.
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const expoCrypto = await import('expo-crypto');
|
|
38
|
-
return await expoCrypto.getRandomBytesAsync(size);
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
throw new Error('No cryptographically secure random source available. ' +
|
|
42
|
-
'Provide Web Crypto, Node crypto, or Expo Crypto in this runtime.');
|
|
4
|
+
if (!Number.isSafeInteger(size) || size < 0) {
|
|
5
|
+
throw new RangeError('Random byte length must be a nonnegative safe integer.');
|
|
43
6
|
}
|
|
7
|
+
return hostRandomBytes(size);
|
|
44
8
|
}
|
|
45
9
|
/**
|
|
46
10
|
* Generate a random RFC 4122 version 4 UUID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../internal/crypto/random.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../internal/crypto/random.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,0DAA0D;AAC1D,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAY;IACpD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,UAAU,CAAC,wDAAwD,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAC5C,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,YAAY;IAClD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,eAAe;IACrD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrF,OAAO,CACL,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG;QAC9D,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type AesMode = 'AES-CBC' | 'AES-GCM';
|
|
2
|
+
export declare function encryptAes(mode: AesMode, key: Uint8Array, iv: Uint8Array, plaintext: Uint8Array, additionalData?: Uint8Array): Promise<Uint8Array>;
|
|
3
|
+
export declare function decryptAes(mode: AesMode, key: Uint8Array, iv: Uint8Array, ciphertext: Uint8Array, additionalData?: Uint8Array): Promise<Uint8Array>;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=aes-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes-provider.d.ts","sourceRoot":"","sources":["../../../../internal/crypto/symmetric/aes-provider.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AA6BrC,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAElJ;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAEnJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { cbc, gcm } from '@noble/ciphers/aes.js';
|
|
2
|
+
/** Use Web Crypto when available. Hermes uses the existing Noble AES implementation. */
|
|
3
|
+
async function transform(operation, mode, key, iv, data, additionalData) {
|
|
4
|
+
const subtle = globalThis.crypto?.subtle;
|
|
5
|
+
if (subtle) {
|
|
6
|
+
const cryptoKey = await subtle.importKey('raw', key, { name: mode }, false, [operation]);
|
|
7
|
+
const params = {
|
|
8
|
+
name: mode,
|
|
9
|
+
iv: iv,
|
|
10
|
+
...(mode === 'AES-GCM' ? {
|
|
11
|
+
tagLength: 128,
|
|
12
|
+
...(additionalData === undefined ? {} : { additionalData: additionalData }),
|
|
13
|
+
} : {}),
|
|
14
|
+
};
|
|
15
|
+
return new Uint8Array(await subtle[operation](params, cryptoKey, data));
|
|
16
|
+
}
|
|
17
|
+
const cipher = mode === 'AES-GCM' ? gcm(key, iv, additionalData) : cbc(key, iv);
|
|
18
|
+
return cipher[operation](data);
|
|
19
|
+
}
|
|
20
|
+
export function encryptAes(mode, key, iv, plaintext, additionalData) {
|
|
21
|
+
return transform('encrypt', mode, key, iv, plaintext, additionalData);
|
|
22
|
+
}
|
|
23
|
+
export function decryptAes(mode, key, iv, ciphertext, additionalData) {
|
|
24
|
+
return transform('decrypt', mode, key, iv, ciphertext, additionalData);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=aes-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes-provider.js","sourceRoot":"","sources":["../../../../internal/crypto/symmetric/aes-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAIjD,wFAAwF;AACxF,KAAK,UAAU,SAAS,CACtB,SAAgC,EAChC,IAAa,EACb,GAAe,EACf,EAAc,EACd,IAAgB,EAChB,cA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AAS,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -11,14 +11,6 @@
|
|
|
11
11
|
* @see https://signal.org/docs/specifications/doubleratchet/#recommended-cryptographic-algorithms - AES-256-CBC + HMAC-SHA256
|
|
12
12
|
*/
|
|
13
13
|
import type { Base64 } from '../../../types/index.js';
|
|
14
|
-
/**
|
|
15
|
-
* Narrow Uint8Array<ArrayBufferLike> to Uint8Array<ArrayBuffer> for Web Crypto API.
|
|
16
|
-
*
|
|
17
|
-
* TypeScript 5.x widens Uint8Array to Uint8Array<ArrayBufferLike> which includes
|
|
18
|
-
* SharedArrayBuffer. Web Crypto expects BufferSource backed by ArrayBuffer only.
|
|
19
|
-
* At runtime, our code never creates SharedArrayBuffer, so this cast is safe.
|
|
20
|
-
*/
|
|
21
|
-
export {};
|
|
22
14
|
/**
|
|
23
15
|
* AES-256 key size in bytes
|
|
24
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes.d.ts","sourceRoot":"","sources":["../../../../internal/crypto/symmetric/aes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"aes.d.ts","sourceRoot":"","sources":["../../../../internal/crypto/symmetric/aes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAU7C;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAMnC;;;;;;;GAOG;AACH,wBAAsB,a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