@vex-chat/libvex 5.4.0 → 5.5.1
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/README.md +25 -23
- package/dist/Client.d.ts +113 -77
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +311 -234
- package/dist/Client.js.map +1 -1
- package/dist/__tests__/harness/memory-storage.d.ts +1 -1
- package/dist/__tests__/harness/memory-storage.d.ts.map +1 -1
- package/dist/__tests__/harness/memory-storage.js +1 -1
- package/dist/__tests__/harness/memory-storage.js.map +1 -1
- package/dist/codecs.d.ts +118 -0
- package/dist/codecs.d.ts.map +1 -1
- package/dist/codecs.js +41 -0
- package/dist/codecs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/storage/node/http-agents.d.ts +1 -1
- package/dist/storage/node/http-agents.d.ts.map +1 -1
- package/dist/storage/node/http-agents.js +4 -4
- package/dist/storage/node/http-agents.js.map +1 -1
- package/dist/storage/sqlite.d.ts +8 -8
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +16 -16
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/utils/fipsMailExtra.d.ts +9 -9
- package/dist/utils/fipsMailExtra.d.ts.map +1 -1
- package/dist/utils/fipsMailExtra.js +47 -47
- package/dist/utils/fipsMailExtra.js.map +1 -1
- package/dist/utils/resolveAtRestAesKey.js +1 -1
- package/dist/utils/resolveAtRestAesKey.js.map +1 -1
- package/package.json +134 -152
- package/src/Client.ts +452 -306
- package/src/__tests__/harness/memory-storage.ts +1 -1
- package/src/__tests__/harness/shared-suite.ts +177 -177
- package/src/codecs.ts +52 -0
- package/src/index.ts +4 -0
- package/src/storage/node/http-agents.ts +7 -7
- package/src/storage/sqlite.ts +23 -23
- package/src/utils/fipsMailExtra.ts +80 -80
- package/src/utils/resolveAtRestAesKey.ts +1 -1
|
@@ -14,58 +14,6 @@ const FIPS_SUBSEQUENT_V1: readonly [number, number, number] = [
|
|
|
14
14
|
0xf1, 0x03, 0x01,
|
|
15
15
|
] as const;
|
|
16
16
|
|
|
17
|
-
function u16be(n: number): [number, number] {
|
|
18
|
-
if (!Number.isInteger(n) || n < 0 || n > 65535) {
|
|
19
|
-
throw new Error(`FIPS: invalid u16 length: ${String(n)}`);
|
|
20
|
-
}
|
|
21
|
-
return [n >> 8, n & 0xff];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function u16read(buf: Uint8Array, offset: number): number {
|
|
25
|
-
if (offset + 2 > buf.length) {
|
|
26
|
-
return -1;
|
|
27
|
-
}
|
|
28
|
-
return ((buf[offset] ?? 0) * 256 + (buf[offset + 1] ?? 0)) >>> 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function isFipsInitialExtraV1(buf: Uint8Array): boolean {
|
|
32
|
-
return (
|
|
33
|
-
buf.length >= 3 &&
|
|
34
|
-
buf[0] === FIPS_INITIAL_EXTRA_V1[0] &&
|
|
35
|
-
buf[1] === FIPS_INITIAL_EXTRA_V1[1] &&
|
|
36
|
-
buf[2] === FIPS_INITIAL_EXTRA_V1[2]
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* P-256 fips (Web Crypto) initial mail `extra` bytes (version 1). Length-prefixed segments
|
|
42
|
-
* (variable lengths) plus a 6-byte OTK index, AD length includes both identity raw publics.
|
|
43
|
-
*/
|
|
44
|
-
export function encodeFipsInitialExtraV1(
|
|
45
|
-
signPub: Uint8Array,
|
|
46
|
-
ephPub: Uint8Array,
|
|
47
|
-
pk: Uint8Array,
|
|
48
|
-
ad: Uint8Array,
|
|
49
|
-
index6: Uint8Array,
|
|
50
|
-
): Uint8Array {
|
|
51
|
-
if (index6.length !== 6) {
|
|
52
|
-
throw new Error("FIPS: OTK index must be 6 bytes.");
|
|
53
|
-
}
|
|
54
|
-
const a = (len: number) => new Uint8Array([...u16be(len)]);
|
|
55
|
-
return xConcat(
|
|
56
|
-
Uint8Array.from([...FIPS_INITIAL_EXTRA_V1]),
|
|
57
|
-
a(signPub.length),
|
|
58
|
-
signPub,
|
|
59
|
-
a(ephPub.length),
|
|
60
|
-
ephPub,
|
|
61
|
-
a(pk.length),
|
|
62
|
-
pk,
|
|
63
|
-
a(ad.length),
|
|
64
|
-
ad,
|
|
65
|
-
index6,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
17
|
/**
|
|
70
18
|
* @returns [signKey, ephKey, ad, index6] (Uint8Array slices, index is always length 6)
|
|
71
19
|
*/
|
|
@@ -105,12 +53,47 @@ export function decodeFipsInitialExtraV1(
|
|
|
105
53
|
return [signKey, ephKey, ad, index6];
|
|
106
54
|
}
|
|
107
55
|
|
|
108
|
-
export function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
56
|
+
export function decodeFipsSubsequentExtraV1(extra: Uint8Array): Uint8Array {
|
|
57
|
+
if (!isFipsSubsequentExtraV1(extra)) {
|
|
58
|
+
throw new Error("FIPS: not a v1 subsequent extra.");
|
|
59
|
+
}
|
|
60
|
+
const len = u16read(extra, 3);
|
|
61
|
+
if (len < 0) {
|
|
62
|
+
throw new Error("FIPS: bad subsequent extra length field.");
|
|
63
|
+
}
|
|
64
|
+
const p = 5;
|
|
65
|
+
if (p + len > extra.length) {
|
|
66
|
+
throw new Error("FIPS: subsequent extra truncated.");
|
|
67
|
+
}
|
|
68
|
+
return extra.subarray(p, p + len);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* P-256 fips (Web Crypto) initial mail `extra` bytes (version 1). Length-prefixed segments
|
|
73
|
+
* (variable lengths) plus a 6-byte OTK index, AD length includes both identity raw publics.
|
|
74
|
+
*/
|
|
75
|
+
export function encodeFipsInitialExtraV1(
|
|
76
|
+
signPub: Uint8Array,
|
|
77
|
+
ephPub: Uint8Array,
|
|
78
|
+
pk: Uint8Array,
|
|
79
|
+
ad: Uint8Array,
|
|
80
|
+
index6: Uint8Array,
|
|
81
|
+
): Uint8Array {
|
|
82
|
+
if (index6.length !== 6) {
|
|
83
|
+
throw new Error("FIPS: OTK index must be 6 bytes.");
|
|
84
|
+
}
|
|
85
|
+
const a = (len: number) => new Uint8Array([...u16be(len)]);
|
|
86
|
+
return xConcat(
|
|
87
|
+
Uint8Array.from([...FIPS_INITIAL_EXTRA_V1]),
|
|
88
|
+
a(signPub.length),
|
|
89
|
+
signPub,
|
|
90
|
+
a(ephPub.length),
|
|
91
|
+
ephPub,
|
|
92
|
+
a(pk.length),
|
|
93
|
+
pk,
|
|
94
|
+
a(ad.length),
|
|
95
|
+
ad,
|
|
96
|
+
index6,
|
|
114
97
|
);
|
|
115
98
|
}
|
|
116
99
|
|
|
@@ -130,28 +113,6 @@ export function encodeFipsSubsequentExtraV1(
|
|
|
130
113
|
);
|
|
131
114
|
}
|
|
132
115
|
|
|
133
|
-
export function decodeFipsSubsequentExtraV1(extra: Uint8Array): Uint8Array {
|
|
134
|
-
if (!isFipsSubsequentExtraV1(extra)) {
|
|
135
|
-
throw new Error("FIPS: not a v1 subsequent extra.");
|
|
136
|
-
}
|
|
137
|
-
const len = u16read(extra, 3);
|
|
138
|
-
if (len < 0) {
|
|
139
|
-
throw new Error("FIPS: bad subsequent extra length field.");
|
|
140
|
-
}
|
|
141
|
-
const p = 5;
|
|
142
|
-
if (p + len > extra.length) {
|
|
143
|
-
throw new Error("FIPS: subsequent extra truncated.");
|
|
144
|
-
}
|
|
145
|
-
return extra.subarray(p, p + len);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** P-256: message bytes signed to bind a prekey (FIPS) — 1-byte tag + uncompressed public. */
|
|
149
|
-
export function fipsP256PreKeySignPayload(
|
|
150
|
-
preKeyRawPublic: Uint8Array,
|
|
151
|
-
): Uint8Array {
|
|
152
|
-
return xConcat(new Uint8Array([0xa1]), preKeyRawPublic);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
116
|
/**
|
|
156
117
|
* P-256 identity AD: concatenation of our and their P-256 ECDH identity publics (uncompressed, 65B each if standard).
|
|
157
118
|
* Used instead of `xEncode` + X25519 for FIPS.
|
|
@@ -162,3 +123,42 @@ export function fipsP256AdFromIdentityPubs(
|
|
|
162
123
|
): Uint8Array {
|
|
163
124
|
return xConcat(ourIdentityRaw, theirIdentityFromBundle);
|
|
164
125
|
}
|
|
126
|
+
|
|
127
|
+
/** P-256: message bytes signed to bind a prekey (FIPS) — 1-byte tag + uncompressed public. */
|
|
128
|
+
export function fipsP256PreKeySignPayload(
|
|
129
|
+
preKeyRawPublic: Uint8Array,
|
|
130
|
+
): Uint8Array {
|
|
131
|
+
return xConcat(new Uint8Array([0xa1]), preKeyRawPublic);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function isFipsInitialExtraV1(buf: Uint8Array): boolean {
|
|
135
|
+
return (
|
|
136
|
+
buf.length >= 3 &&
|
|
137
|
+
buf[0] === FIPS_INITIAL_EXTRA_V1[0] &&
|
|
138
|
+
buf[1] === FIPS_INITIAL_EXTRA_V1[1] &&
|
|
139
|
+
buf[2] === FIPS_INITIAL_EXTRA_V1[2]
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function isFipsSubsequentExtraV1(buf: Uint8Array): boolean {
|
|
144
|
+
return (
|
|
145
|
+
buf.length >= 3 &&
|
|
146
|
+
buf[0] === FIPS_SUBSEQUENT_V1[0] &&
|
|
147
|
+
buf[1] === FIPS_SUBSEQUENT_V1[1] &&
|
|
148
|
+
buf[2] === FIPS_SUBSEQUENT_V1[2]
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function u16be(n: number): [number, number] {
|
|
153
|
+
if (!Number.isInteger(n) || n < 0 || n > 65535) {
|
|
154
|
+
throw new Error(`FIPS: invalid u16 length: ${String(n)}`);
|
|
155
|
+
}
|
|
156
|
+
return [n >> 8, n & 0xff];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function u16read(buf: Uint8Array, offset: number): number {
|
|
160
|
+
if (offset + 2 > buf.length) {
|
|
161
|
+
return -1;
|
|
162
|
+
}
|
|
163
|
+
return ((buf[offset] ?? 0) * 256 + (buf[offset + 1] ?? 0)) >>> 0;
|
|
164
|
+
}
|