p2party 0.14.3 → 0.14.10
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 +234 -31
- package/THIRD_PARTY_NOTICES.md +33 -6
- package/docs/getting-started.md +118 -4
- package/docs/protocol-v4-security.md +96 -6
- package/docs/references.md +28 -8
- package/docs/session-api.md +19 -2
- package/docs/wire-format.md +102 -14
- package/lib/api/signalingServerApi.d.ts +51 -2
- package/lib/api/webrtc/interfaces.d.ts +70 -1
- package/lib/api/webrtc/peerSocketGeneration.d.ts +68 -0
- package/lib/cryptography/coverCell.d.ts +7 -0
- package/lib/cryptography/emscripten.d.ts +101 -0
- package/lib/cryptography/interfaces.d.ts +3 -0
- package/lib/cryptography/libcrypto.d.ts +181 -0
- package/lib/cryptography/mlkem.d.ts +27 -1
- package/lib/cryptography/mnemonic.d.ts +65 -1
- package/lib/db/outboxTypes.d.ts +135 -0
- package/lib/db/types.d.ts +81 -7
- package/lib/db.worker.js +1 -1
- package/lib/handlers/coverRuntime.d.ts +14 -1
- package/lib/handlers/coverScheduler.d.ts +59 -1
- package/lib/handlers/coverTransfer.d.ts +169 -3
- package/lib/handlers/handleSendMessage.d.ts +138 -9
- package/lib/handlers/handshakeCore.d.ts +2 -7
- package/lib/handlers/handshakeFrame.d.ts +25 -0
- package/lib/handlers/outbox.d.ts +47 -0
- package/lib/handlers/ratchetGate.d.ts +9 -0
- package/lib/handlers/reconcile.d.ts +5 -0
- package/lib/index.d.ts +102 -12
- package/lib/index.js +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.mjs +1 -1
- package/lib/libcrypto.provenance.json +5 -5
- package/lib/libcrypto.wasm +0 -0
- package/lib/reducers/commonSlice.d.ts +3 -2
- package/lib/reducers/keyPairSlice.d.ts +3 -6
- package/lib/reducers/roomSlice.d.ts +89 -6
- package/lib/reducers/signalingServerSlice.d.ts +3 -2
- package/lib/session.d.ts +6 -3
- package/lib/session.js +1 -1
- package/lib/session.mjs +1 -1
- package/lib/store.d.ts +4 -2
- package/lib/utils/constants.d.ts +19 -0
- package/lib/utils/identityRestore.d.ts +108 -0
- package/lib/utils/interfaces.d.ts +36 -6
- package/lib/utils/roomLeaveCoordinator.d.ts +38 -0
- package/lib/utils/signalingReconnectController.d.ts +44 -0
- package/lib/utils/terminalSettlement.d.ts +53 -0
- package/package.json +13 -15
- package/lib/api/webrtc/disconnectFromAllRoomsQuery.d.ts +0 -8
- package/lib/api/webrtc/disconnectFromChannelLabelQuery.d.ts +0 -7
- package/lib/api/webrtc/disconnectFromPeerChannelLabelQuery.d.ts +0 -8
- package/lib/api/webrtc/disconnectFromPeerQuery.d.ts +0 -9
- package/lib/api/webrtc/disconnectFromRoomQuery.d.ts +0 -8
- package/lib/api/webrtc/disconnectQuery.d.ts +0 -8
- package/lib/api/webrtc/iceGeneration.d.ts +0 -17
- package/lib/api/webrtc/iceRepair.d.ts +0 -10
- package/lib/api/webrtc/index.d.ts +0 -16
- package/lib/api/webrtc/negotiationLock.d.ts +0 -12
- package/lib/api/webrtc/openChannelQuery.d.ts +0 -8
- package/lib/api/webrtc/pendingIceCandidates.d.ts +0 -14
- package/lib/api/webrtc/roomPeer.d.ts +0 -11
- package/lib/api/webrtc/sendMessageQuery.d.ts +0 -14
- package/lib/api/webrtc/setCandidateQuery.d.ts +0 -8
- package/lib/api/webrtc/setDescriptionQuery.d.ts +0 -9
- package/lib/cryptography/cpace.d.ts +0 -41
- package/lib/cryptography/ed25519.d.ts +0 -11
- package/lib/cryptography/hashStream.d.ts +0 -15
- package/lib/cryptography/hkdf.d.ts +0 -3
- package/lib/cryptography/identityCrossSig.d.ts +0 -7
- package/lib/cryptography/memory.d.ts +0 -14
- package/lib/cryptography/merkle.d.ts +0 -42
- package/lib/cryptography/pqHealingFrame.d.ts +0 -39
- package/lib/cryptography/random.d.ts +0 -22
- package/lib/cryptography/testModule.d.ts +0 -7
- package/lib/cryptography/utils.d.ts +0 -13
- package/lib/cryptography/x25519.d.ts +0 -15
- package/lib/cryptography/x3dh.d.ts +0 -9
- package/lib/db/api.d.ts +0 -67
- package/lib/db/db.worker.d.ts +0 -1
- package/lib/db/ratchetWrap.d.ts +0 -36
- package/lib/db/src/getDB.d.ts +0 -81
- package/lib/handlers/chunkFrame.d.ts +0 -13
- package/lib/handlers/connectionSignal.d.ts +0 -26
- package/lib/handlers/coverEdge.d.ts +0 -42
- package/lib/handlers/frameType.d.ts +0 -10
- package/lib/handlers/handleChallenge.d.ts +0 -3
- package/lib/handlers/handleConnectToPeer.d.ts +0 -6
- package/lib/handlers/handleHandshake.d.ts +0 -74
- package/lib/handlers/handleMessageQueueing.d.ts +0 -54
- package/lib/handlers/handleOpenChannel.d.ts +0 -12
- package/lib/handlers/handleQueuedIceCandidates.d.ts +0 -2
- package/lib/handlers/handleReadReceipt.d.ts +0 -17
- package/lib/handlers/handleReceiveMessage.d.ts +0 -32
- package/lib/handlers/handleWebSocketMessage.d.ts +0 -3
- package/lib/handlers/messageChunkCrypto.d.ts +0 -70
- package/lib/handlers/peerRosterDelta.d.ts +0 -12
- package/lib/handlers/pqHealingOrchestrator.d.ts +0 -46
- package/lib/handlers/ratchetPersist.d.ts +0 -53
- package/lib/handlers/receiptFrame.d.ts +0 -18
- package/lib/handlers/receiveMessageKeyLifetime.d.ts +0 -24
- package/lib/handlers/transferAbort.d.ts +0 -42
- package/lib/middleware/keyPairListenerMiddleware.d.ts +0 -2
- package/lib/middleware/roomListenerMiddleware.d.ts +0 -2
- package/lib/roomInvite.d.ts +0 -18
- package/lib/roomPinAttempts.d.ts +0 -12
- package/lib/roomPinVault.d.ts +0 -26
- package/lib/utils/channelLabel.d.ts +0 -9
- package/lib/utils/chunkBounds.d.ts +0 -9
- package/lib/utils/drainAndClose.d.ts +0 -5
- package/lib/utils/identityRole.d.ts +0 -19
- package/lib/utils/leafHash.d.ts +0 -13
- package/lib/utils/metadata.d.ts +0 -22
- package/lib/utils/mutex.d.ts +0 -24
- package/lib/utils/protocolVersion.d.ts +0 -5
- package/lib/utils/receiptToken.d.ts +0 -7
- package/lib/utils/sendQueueKey.d.ts +0 -2
- package/lib/utils/signalingAuth.d.ts +0 -8
- package/lib/utils/signalingBounds.d.ts +0 -9
- package/lib/utils/splitToChunks.d.ts +0 -30
- package/lib/utils/uint8array.d.ts +0 -16
- package/lib/utils/waitForOpen.d.ts +0 -3
- package/lib/utils/zeroFree.d.ts +0 -10
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-scoped EmscriptenModule and factory types from @types/emscripten
|
|
3
|
+
* 1.41.5 (DefinitelyTyped). All inherited LibCrypto members are retained.
|
|
4
|
+
* Keeping these types local avoids a required ambient development dependency
|
|
5
|
+
* and does not merge with a consumer's global Emscripten declarations.
|
|
6
|
+
* MIT license, Copyright (c) Microsoft Corporation.
|
|
7
|
+
* See THIRD_PARTY_NOTICES.md for the full upstream license.
|
|
8
|
+
*/
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- Preserve upstream API compatibility. */
|
|
10
|
+
|
|
11
|
+
// Infers the type only in TypeScript environments where GPU types are available
|
|
12
|
+
type MaybeGPUDevice = Navigator extends {
|
|
13
|
+
gpu: {
|
|
14
|
+
requestAdapter(...args: any[]): Promise<null | {
|
|
15
|
+
requestDevice(...args: any[]): Promise<null | infer T>;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
? T
|
|
20
|
+
: never;
|
|
21
|
+
|
|
22
|
+
export interface EmscriptenModule {
|
|
23
|
+
print(str: string): void;
|
|
24
|
+
printErr(str: string): void;
|
|
25
|
+
arguments: string[];
|
|
26
|
+
environment: "WEB" | "NODE" | "SHELL" | "WORKER";
|
|
27
|
+
preInit: Array<{ (): void }>;
|
|
28
|
+
preRun: Array<{ (): void }>;
|
|
29
|
+
postRun: Array<{ (): void }>;
|
|
30
|
+
onAbort: { (what: any): void };
|
|
31
|
+
onRuntimeInitialized: { (): void };
|
|
32
|
+
preinitializedWebGLContext: WebGLRenderingContext;
|
|
33
|
+
preinitializedWebGPUDevice: MaybeGPUDevice;
|
|
34
|
+
noInitialRun: boolean;
|
|
35
|
+
noExitRuntime: boolean;
|
|
36
|
+
logReadFiles: boolean;
|
|
37
|
+
filePackagePrefixURL: string;
|
|
38
|
+
wasmBinary: ArrayBuffer;
|
|
39
|
+
|
|
40
|
+
destroy(object: object): void;
|
|
41
|
+
getPreloadedPackage(
|
|
42
|
+
remotePackageName: string,
|
|
43
|
+
remotePackageSize: number,
|
|
44
|
+
): ArrayBuffer;
|
|
45
|
+
instantiateWasm(
|
|
46
|
+
imports: WebAssembly.Imports,
|
|
47
|
+
successCallback: (module: WebAssembly.Instance) => void,
|
|
48
|
+
): WebAssembly.Exports | undefined;
|
|
49
|
+
locateFile(url: string, scriptDirectory: string): string;
|
|
50
|
+
onCustomMessage(event: MessageEvent): void;
|
|
51
|
+
|
|
52
|
+
// USE_TYPED_ARRAYS == 1
|
|
53
|
+
HEAP: Int32Array;
|
|
54
|
+
IHEAP: Int32Array;
|
|
55
|
+
FHEAP: Float64Array;
|
|
56
|
+
|
|
57
|
+
// USE_TYPED_ARRAYS == 2
|
|
58
|
+
HEAP8: Int8Array;
|
|
59
|
+
HEAP16: Int16Array;
|
|
60
|
+
HEAP32: Int32Array;
|
|
61
|
+
HEAPU8: Uint8Array;
|
|
62
|
+
HEAPU16: Uint16Array;
|
|
63
|
+
HEAPU32: Uint32Array;
|
|
64
|
+
HEAPF32: Float32Array;
|
|
65
|
+
HEAPF64: Float64Array;
|
|
66
|
+
HEAP64: BigInt64Array;
|
|
67
|
+
HEAPU64: BigUint64Array;
|
|
68
|
+
|
|
69
|
+
TOTAL_STACK: number;
|
|
70
|
+
TOTAL_MEMORY: number;
|
|
71
|
+
FAST_MEMORY: number;
|
|
72
|
+
|
|
73
|
+
addOnPreRun(cb: () => any): void;
|
|
74
|
+
addOnInit(cb: () => any): void;
|
|
75
|
+
addOnPreMain(cb: () => any): void;
|
|
76
|
+
addOnExit(cb: () => any): void;
|
|
77
|
+
addOnPostRun(cb: () => any): void;
|
|
78
|
+
|
|
79
|
+
preloadedImages: any;
|
|
80
|
+
preloadedAudios: any;
|
|
81
|
+
|
|
82
|
+
_malloc(size: number): number;
|
|
83
|
+
_free(ptr: number): void;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A factory function is generated when setting the `MODULARIZE` build option
|
|
88
|
+
* to `1` in your Emscripten build. It return a Promise that resolves to an
|
|
89
|
+
* initialized, ready-to-call `EmscriptenModule` instance.
|
|
90
|
+
*
|
|
91
|
+
* By default, the factory function will be named `Module`. It's recommended to
|
|
92
|
+
* use the `EXPORT_ES6` option, in which the factory function will be the
|
|
93
|
+
* default export. If used without `EXPORT_ES6`, the factory function will be a
|
|
94
|
+
* global variable. You can rename the variable using the `EXPORT_NAME` build
|
|
95
|
+
* option. It's left to you to declare any global variables as needed in your
|
|
96
|
+
* application's types.
|
|
97
|
+
* @param moduleOverrides Default properties for the initialized module.
|
|
98
|
+
*/
|
|
99
|
+
export type EmscriptenModuleFactory<
|
|
100
|
+
T extends EmscriptenModule = EmscriptenModule,
|
|
101
|
+
> = (moduleOverrides?: Partial<T>) => Promise<T>;
|
|
@@ -11,6 +11,9 @@ export declare const crypto_secretbox_NONCEBYTES: number;
|
|
|
11
11
|
export declare const crypto_aead_chacha20poly1305_ietf_KEYBYTES: number;
|
|
12
12
|
export declare const crypto_aead_chacha20poly1305_ietf_NPUBBYTES: number;
|
|
13
13
|
export declare const crypto_aead_chacha20poly1305_ietf_ABYTES: number;
|
|
14
|
+
export declare const crypto_aead_xchacha20poly1305_ietf_KEYBYTES: number;
|
|
15
|
+
export declare const crypto_aead_xchacha20poly1305_ietf_NPUBBYTES: number;
|
|
16
|
+
export declare const crypto_aead_xchacha20poly1305_ietf_ABYTES: number;
|
|
14
17
|
export declare const crypto_pwhash_argon2id_SALTBYTES: number;
|
|
15
18
|
export declare const crypto_core_ristretto255_BYTES: number;
|
|
16
19
|
export declare const crypto_core_ristretto255_HASHBYTES: number;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { EmscriptenModule, EmscriptenModuleFactory } from "./emscripten";
|
|
2
|
+
|
|
3
|
+
export interface LibCrypto extends EmscriptenModule {
|
|
4
|
+
wasmMemory: WebAssembly.Memory;
|
|
5
|
+
/** Web Crypto backed entropy callback supplied by the JavaScript loader. */
|
|
6
|
+
getRandomValue?(): number;
|
|
7
|
+
|
|
8
|
+
_crypto_init(): number;
|
|
9
|
+
|
|
10
|
+
_keypair(
|
|
11
|
+
public_key: number, // Uint8Array,
|
|
12
|
+
secret_key: number, // Uint8Array
|
|
13
|
+
): number;
|
|
14
|
+
|
|
15
|
+
_keypair_from_seed(
|
|
16
|
+
public_key: number, // Uint8Array,
|
|
17
|
+
secret_key: number, // Uint8Array,
|
|
18
|
+
seed: number, // Uint8Array,
|
|
19
|
+
): number;
|
|
20
|
+
_keypair_from_secret_key(
|
|
21
|
+
public_key: number, // Uint8Array,
|
|
22
|
+
secret_key: number, // Uint8Array,
|
|
23
|
+
): number;
|
|
24
|
+
|
|
25
|
+
_sign(
|
|
26
|
+
DATA_LEN: number,
|
|
27
|
+
data: number, // Uint8Array,
|
|
28
|
+
secret_key: number, // Uint8Array,
|
|
29
|
+
signature: number, // Uint8Array,
|
|
30
|
+
): number;
|
|
31
|
+
_verify(
|
|
32
|
+
DATA_LEN: number,
|
|
33
|
+
data: number, // Uint8Array,
|
|
34
|
+
public_key: number, // Uint8Array,
|
|
35
|
+
signature: number, // Uint8Array,
|
|
36
|
+
): number;
|
|
37
|
+
|
|
38
|
+
_get_merkle_root(
|
|
39
|
+
LEAVES_LEN: number,
|
|
40
|
+
leaves_hashed: number, // Uint8Array.byteOffset
|
|
41
|
+
root: number, // Uint8Array.byteOffset
|
|
42
|
+
): number;
|
|
43
|
+
_get_merkle_proof(
|
|
44
|
+
LEAVES_LEN: number,
|
|
45
|
+
leaves_hashed: number, // Uint8Array.byteOffset
|
|
46
|
+
element_hash: number, // Uint8Array.byteOffset
|
|
47
|
+
proof: number, // Uint8Array.byteOffset
|
|
48
|
+
): number;
|
|
49
|
+
_get_merkle_root_from_proof(
|
|
50
|
+
PROOF_LEN: number,
|
|
51
|
+
element_hash: number, // Uint8Array.byteOffset
|
|
52
|
+
proof: number, // Uint8Array.byteOffset
|
|
53
|
+
root: number, // Uint8Array.byteOffset
|
|
54
|
+
): number;
|
|
55
|
+
_verify_merkle_proof(
|
|
56
|
+
PROOF_LEN: number,
|
|
57
|
+
element_hash: number, // Uint8Array.byteOffset
|
|
58
|
+
root: number, // Uint8Array.byteOffset
|
|
59
|
+
proof: number, // Uint8Array.byteOffset
|
|
60
|
+
): number;
|
|
61
|
+
|
|
62
|
+
_argon2(
|
|
63
|
+
MNEMONIC_LEN: number,
|
|
64
|
+
seed: number,
|
|
65
|
+
mnemonic: number,
|
|
66
|
+
salt: number,
|
|
67
|
+
): number;
|
|
68
|
+
|
|
69
|
+
// Streaming SHA-512 (plain, no domain separation) — state is a heap
|
|
70
|
+
// crypto_hash_sha512_state (208 bytes) allocated by JS.
|
|
71
|
+
_sha512_init(
|
|
72
|
+
state: number, // Uint8Array.byteOffset (208-byte state)
|
|
73
|
+
): number;
|
|
74
|
+
_sha512_update(
|
|
75
|
+
state: number, // Uint8Array.byteOffset
|
|
76
|
+
in_data: number, // Uint8Array.byteOffset
|
|
77
|
+
in_len: number,
|
|
78
|
+
): number;
|
|
79
|
+
_sha512_final(
|
|
80
|
+
state: number, // Uint8Array.byteOffset
|
|
81
|
+
out: number, // Uint8Array.byteOffset (64 bytes)
|
|
82
|
+
): number;
|
|
83
|
+
|
|
84
|
+
// v3 PAKE + ratchet primitives (pake_ratchet.c)
|
|
85
|
+
_cpace_ristretto255_from_hash(out: number, hash: number): void;
|
|
86
|
+
_cpace_ristretto255_scalarmult(
|
|
87
|
+
out: number,
|
|
88
|
+
scalar: number,
|
|
89
|
+
point: number,
|
|
90
|
+
): number;
|
|
91
|
+
_cpace_ristretto255_scalar_random(out: number): void;
|
|
92
|
+
_x25519_keypair(pk: number, sk: number): number;
|
|
93
|
+
_x25519_dh(shared: number, sk: number, pk: number): number;
|
|
94
|
+
_hkdf_sha512_extract(
|
|
95
|
+
prk: number,
|
|
96
|
+
salt: number,
|
|
97
|
+
salt_len: number,
|
|
98
|
+
ikm: number,
|
|
99
|
+
ikm_len: number,
|
|
100
|
+
): number;
|
|
101
|
+
_hkdf_sha512_expand(
|
|
102
|
+
out: number,
|
|
103
|
+
out_len: number,
|
|
104
|
+
prk: number,
|
|
105
|
+
info: number,
|
|
106
|
+
info_len: number,
|
|
107
|
+
): number;
|
|
108
|
+
_encrypt_chachapoly_symmetric(
|
|
109
|
+
out: number,
|
|
110
|
+
data: number,
|
|
111
|
+
data_len: number,
|
|
112
|
+
key: number,
|
|
113
|
+
nonce: number,
|
|
114
|
+
aad: number,
|
|
115
|
+
aad_len: number,
|
|
116
|
+
): number;
|
|
117
|
+
_decrypt_chachapoly_symmetric(
|
|
118
|
+
out: number,
|
|
119
|
+
ciphertext: number,
|
|
120
|
+
ciphertext_len: number,
|
|
121
|
+
key: number,
|
|
122
|
+
nonce: number,
|
|
123
|
+
aad: number,
|
|
124
|
+
aad_len: number,
|
|
125
|
+
): number;
|
|
126
|
+
_carrier_aead_xchacha20poly1305_encrypt(
|
|
127
|
+
out: number,
|
|
128
|
+
data: number,
|
|
129
|
+
data_len: number,
|
|
130
|
+
key: number,
|
|
131
|
+
nonce: number,
|
|
132
|
+
aad: number,
|
|
133
|
+
aad_len: number,
|
|
134
|
+
): number;
|
|
135
|
+
_carrier_aead_xchacha20poly1305_decrypt(
|
|
136
|
+
out: number,
|
|
137
|
+
ciphertext: number,
|
|
138
|
+
ciphertext_len: number,
|
|
139
|
+
key: number,
|
|
140
|
+
nonce: number,
|
|
141
|
+
aad: number,
|
|
142
|
+
aad_len: number,
|
|
143
|
+
): number;
|
|
144
|
+
_receive_message_with_key(
|
|
145
|
+
decrypted: number,
|
|
146
|
+
message: number,
|
|
147
|
+
merkle_root: number,
|
|
148
|
+
message_key: number,
|
|
149
|
+
): number;
|
|
150
|
+
|
|
151
|
+
// ML-KEM (FIPS 203), deterministic entry points for all standardized
|
|
152
|
+
// parameter sets. JavaScript supplies cryptographically secure coins;
|
|
153
|
+
// zero is success and a negative value is failure.
|
|
154
|
+
_mlkem512_keypair(pk: number, sk: number, coins64: number): number;
|
|
155
|
+
_mlkem512_encaps(ct: number, ss: number, pk: number, coins32: number): number;
|
|
156
|
+
_mlkem512_decaps(ss: number, ct: number, sk: number): number;
|
|
157
|
+
_mlkem768_keypair(pk: number, sk: number, coins64: number): number;
|
|
158
|
+
_mlkem768_encaps(ct: number, ss: number, pk: number, coins32: number): number;
|
|
159
|
+
_mlkem768_decaps(ss: number, ct: number, sk: number): number;
|
|
160
|
+
_mlkem1024_keypair(pk: number, sk: number, coins64: number): number;
|
|
161
|
+
_mlkem1024_encaps(
|
|
162
|
+
ct: number,
|
|
163
|
+
ss: number,
|
|
164
|
+
pk: number,
|
|
165
|
+
coins32: number,
|
|
166
|
+
): number;
|
|
167
|
+
_mlkem1024_decaps(ss: number, ct: number, sk: number): number;
|
|
168
|
+
|
|
169
|
+
// P2Party-owned one-shot FIPS 202 boundary backed by the implementation
|
|
170
|
+
// already compiled into the shared ML-KEM-768 unit.
|
|
171
|
+
_fips202_shake256(
|
|
172
|
+
out: number,
|
|
173
|
+
out_len: number,
|
|
174
|
+
input: number,
|
|
175
|
+
input_len: number,
|
|
176
|
+
): number;
|
|
177
|
+
_fips202_sha3_256(out: number, input: number, input_len: number): number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare const libcrypto: EmscriptenModuleFactory<LibCrypto>;
|
|
181
|
+
export default libcrypto;
|
|
@@ -45,6 +45,15 @@ export declare const ML_KEM_SUITES: Readonly<{
|
|
|
45
45
|
1024: Readonly<MlKemSuiteDescriptor<1024>>;
|
|
46
46
|
}>;
|
|
47
47
|
export declare const getMlKemSuite: <P extends MlKemParameterSet>(parameterSet: P) => Readonly<MlKemSuiteDescriptor<P>>;
|
|
48
|
+
/**
|
|
49
|
+
* FIPS 203 Section 7.2 modulus check for one encoded encapsulation key.
|
|
50
|
+
*
|
|
51
|
+
* Each three-byte group in the encoded polynomial vector contains two
|
|
52
|
+
* little-endian 12-bit coefficients, both of which must be below q=3329.
|
|
53
|
+
* The final 32-byte public seed is unrestricted. This pure check is shared by
|
|
54
|
+
* every composed KEM so canonical ML-KEM public-key encoding has one SSOT.
|
|
55
|
+
*/
|
|
56
|
+
export declare const mlKemPublicKeyHasCanonicalEncoding: (publicKey: unknown, parameterSet: MlKemParameterSet) => boolean;
|
|
48
57
|
type MlKemKeyPairFunction = (publicKey: number, secretKey: number, coins64: number) => number;
|
|
49
58
|
type MlKemEncapsFunction = (ciphertext: number, sharedSecret: number, publicKey: number, coins32: number) => number;
|
|
50
59
|
type MlKemDecapsFunction = (sharedSecret: number, ciphertext: number, secretKey: number) => number;
|
|
@@ -104,12 +113,29 @@ export interface MlKemBackend<P extends MlKemParameterSet = MlKemParameterSet> {
|
|
|
104
113
|
encapsulate(publicKey: Uint8Array): Promise<MlKemEncapsulation>;
|
|
105
114
|
decapsulate(ciphertext: Uint8Array, secretKey: Uint8Array): Promise<MlKemDecapsulation>;
|
|
106
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Real-WASM ML-KEM backend with the explicit deterministic inputs required by
|
|
118
|
+
* composed, version-pinned KEMs. The ordinary backend remains the narrower
|
|
119
|
+
* seam used by protocol state machines and test doubles.
|
|
120
|
+
*/
|
|
121
|
+
export interface DeterministicMlKemBackend<P extends MlKemParameterSet = MlKemParameterSet> extends MlKemBackend<P> {
|
|
122
|
+
/**
|
|
123
|
+
* FIPS 203 KeyGen_internal with the caller-supplied 64-byte d || z seed.
|
|
124
|
+
* The seed is borrowed; this method snapshots but never wipes caller bytes.
|
|
125
|
+
*/
|
|
126
|
+
deriveKeyPair(seed: Uint8Array): Promise<MlKemKeyPair>;
|
|
127
|
+
/**
|
|
128
|
+
* FIPS 203 Encaps_internal with caller-supplied 32-byte randomness.
|
|
129
|
+
* Inputs are borrowed; this method snapshots but never wipes caller bytes.
|
|
130
|
+
*/
|
|
131
|
+
encapsulateDeterministically(publicKey: Uint8Array, randomness: Uint8Array): Promise<MlKemEncapsulation>;
|
|
132
|
+
}
|
|
107
133
|
/** Compatibility aliases for the currently shipped ML-KEM-768 handshake. */
|
|
108
134
|
export type MlKem768KeyPair = MlKemKeyPair;
|
|
109
135
|
export type MlKem768Encapsulation = MlKemEncapsulation;
|
|
110
136
|
export type MlKem768Decapsulation = MlKemDecapsulation;
|
|
111
137
|
export type MlKem768Backend = MlKemBackend<768>;
|
|
112
|
-
export declare const createMlKemBackend: <P extends MlKemParameterSet>(module: LibCrypto, suite: Readonly<MlKemSuiteDescriptor<P>>) =>
|
|
138
|
+
export declare const createMlKemBackend: <P extends MlKemParameterSet>(module: LibCrypto, suite: Readonly<MlKemSuiteDescriptor<P>>) => DeterministicMlKemBackend<P>;
|
|
113
139
|
/**
|
|
114
140
|
* Temporary compatibility factory for the protocol-v3 ML-KEM-768 wire suite.
|
|
115
141
|
*/
|
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
import type { LibCrypto } from "./libcrypto";
|
|
2
|
+
/**
|
|
3
|
+
* The result of a mnemonic check, shaped for a form field: `reason` is a
|
|
4
|
+
* displayable sentence naming the first problem found, and is absent when the
|
|
5
|
+
* phrase is usable.
|
|
6
|
+
*/
|
|
7
|
+
export interface MnemonicValidation {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
reason?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The canonical form of a recovery phrase, and part of the derivation
|
|
13
|
+
* contract: NFKD, then any run of whitespace collapsed to a single space,
|
|
14
|
+
* trimmed, lowercased.
|
|
15
|
+
*
|
|
16
|
+
* A phrase is transcribed by a human from paper, a password manager or a
|
|
17
|
+
* screenshot, so it arrives with a trailing newline, a double space, a soft
|
|
18
|
+
* wrap, or a capital first letter from a keyboard's autocapitalisation. All of
|
|
19
|
+
* those used to be rejected outright by the wordlist lookup. Normalising them
|
|
20
|
+
* away here means `" Adapt patrol "` and `"adapt patrol"` are the same
|
|
21
|
+
* phrase everywhere: for validation, and for the argon2id input that produces
|
|
22
|
+
* the seed. Every phrase that derived a key before this normalisation existed
|
|
23
|
+
* was already in canonical form, so no backup changes what it restores.
|
|
24
|
+
*/
|
|
25
|
+
export declare const normalizeMnemonic: (mnemonic: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Derive an argon2id seed from a passphrase.
|
|
28
|
+
*
|
|
29
|
+
* This is the low-level KDF: it applies NFKD only, because an arbitrary
|
|
30
|
+
* passphrase is not a mnemonic and must not be lowercased. Callers that hash a
|
|
31
|
+
* recovery phrase pass it through `normalizeMnemonic` first, as
|
|
32
|
+
* `keyPairFromMnemonic` does.
|
|
33
|
+
*
|
|
34
|
+
* @param mnemonic - Passphrase to stretch
|
|
35
|
+
* @param salt - Optional salt; a random one is generated when omitted
|
|
36
|
+
* @param module - Optional preloaded WASM module, otherwise one is loaded
|
|
37
|
+
* @returns The argon2id seed. The caller owns it and should wipe it.
|
|
38
|
+
*/
|
|
2
39
|
export declare const argon2: (mnemonic: string, salt?: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
|
|
3
40
|
/**
|
|
4
41
|
* Generates a sequence of words chosen from a prespecified wordlist
|
|
@@ -15,6 +52,27 @@ export declare const argon2: (mnemonic: string, salt?: Uint8Array, module?: LibC
|
|
|
15
52
|
export declare const generateMnemonic: (strength?: 128 | 160 | 192 | 224 | 256 | 288 | 320 | 352 | 384 | 416 | 448 | 480 | 512) => Promise<string>;
|
|
16
53
|
export declare const mnemonicToEntropy: (mnemonic: string) => Promise<boolean>;
|
|
17
54
|
export declare const validateMnemonic: (mnemonic: string) => Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Everything about a recovery phrase that can be checked without hashing:
|
|
57
|
+
* word count and membership of the wordlist. Synchronous, so a form can call
|
|
58
|
+
* it on every keystroke and tell the user which word they mistyped.
|
|
59
|
+
*
|
|
60
|
+
* The checksum is deliberately not checked here — SHA-512 is only available
|
|
61
|
+
* asynchronously through Web Crypto. Use `validateMnemonicPhrase` (or
|
|
62
|
+
* `validateMnemonic`) once the phrase is structurally complete.
|
|
63
|
+
*
|
|
64
|
+
* @param words - The phrase as typed; normalisation is applied for you
|
|
65
|
+
* @returns `{ ok }`, plus a displayable `reason` for the first problem found
|
|
66
|
+
*/
|
|
67
|
+
export declare const validateMnemonicWords: (words: string) => MnemonicValidation;
|
|
68
|
+
/**
|
|
69
|
+
* The full check: `validateMnemonicWords` plus the checksum, reported in the
|
|
70
|
+
* same shape so a form can show one message wherever the phrase went wrong.
|
|
71
|
+
*
|
|
72
|
+
* @param words - The phrase as typed; normalisation is applied for you
|
|
73
|
+
* @returns `{ ok }`, plus a displayable `reason` when the phrase is unusable
|
|
74
|
+
*/
|
|
75
|
+
export declare const validateMnemonicPhrase: (words: string) => Promise<MnemonicValidation>;
|
|
18
76
|
/**
|
|
19
77
|
* Generates an Ed25519 key pair from the provided mnemonic.
|
|
20
78
|
* Optionally, you can strenthen the generation with a password.
|
|
@@ -22,8 +80,14 @@ export declare const validateMnemonic: (mnemonic: string) => Promise<boolean>;
|
|
|
22
80
|
* The password is used as a salt for argon2id.
|
|
23
81
|
* From the generated seed we extract the key pair.
|
|
24
82
|
*
|
|
83
|
+
* The phrase is normalised first (see `normalizeMnemonic`), so how it was
|
|
84
|
+
* typed does not change the identity it restores. Nothing here is persisted:
|
|
85
|
+
* the seed, the salt and the encoded password are wiped before returning, and
|
|
86
|
+
* the phrase itself stays the caller's to forget.
|
|
87
|
+
*
|
|
25
88
|
* @param mnemonic - Sequence of words from the predefined wordlist
|
|
26
89
|
* @param password - Optional salt for the seed derivation
|
|
90
|
+
* @param module - Optional preloaded WASM module, otherwise one is loaded
|
|
27
91
|
* @returns An Ed25519 key pair
|
|
28
92
|
*/
|
|
29
|
-
export declare const keyPairFromMnemonic: (mnemonic: string, password?: string) => Promise<import("./interfaces").SignKeyPair>;
|
|
93
|
+
export declare const keyPairFromMnemonic: (mnemonic: string, password?: string, module?: LibCrypto) => Promise<import("./interfaces").SignKeyPair>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { Chunk, MessageData } from "./types";
|
|
2
|
+
/** Durable resend metadata; secrets remain exclusively in the ratchet vault. */
|
|
3
|
+
export interface OutboxLease {
|
|
4
|
+
transferId: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
fence: number;
|
|
7
|
+
}
|
|
8
|
+
export interface OutboxRecipient {
|
|
9
|
+
peerId: string;
|
|
10
|
+
publicKey: string;
|
|
11
|
+
delivered: boolean;
|
|
12
|
+
cancelled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface OutboxManifest {
|
|
15
|
+
transferId: string;
|
|
16
|
+
senderPublicKey: string;
|
|
17
|
+
identityRevision: bigint;
|
|
18
|
+
roomId: string;
|
|
19
|
+
roomUrl: string;
|
|
20
|
+
policyHex: string;
|
|
21
|
+
channelLabel: string;
|
|
22
|
+
filename: string;
|
|
23
|
+
totalSize: number;
|
|
24
|
+
totalChunks: number;
|
|
25
|
+
stagedBytes: number;
|
|
26
|
+
writtenBytes: number;
|
|
27
|
+
localBytes: number;
|
|
28
|
+
createdAt: number;
|
|
29
|
+
updatedAt: number;
|
|
30
|
+
expiresAt: number;
|
|
31
|
+
phase: "staging" | "pending" | "sending";
|
|
32
|
+
merkleRootHex: string;
|
|
33
|
+
hashHex: string;
|
|
34
|
+
recipients: OutboxRecipient[];
|
|
35
|
+
owner: string;
|
|
36
|
+
fence: number;
|
|
37
|
+
leaseUntil: number;
|
|
38
|
+
lastError?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface OutboxCreate {
|
|
41
|
+
transferId: string;
|
|
42
|
+
senderPublicKey: string;
|
|
43
|
+
roomId: string;
|
|
44
|
+
roomUrl: string;
|
|
45
|
+
policyHex: string;
|
|
46
|
+
channelLabel: string;
|
|
47
|
+
filename: string;
|
|
48
|
+
totalSize: number;
|
|
49
|
+
totalChunks: number;
|
|
50
|
+
stagedBytes: number;
|
|
51
|
+
recipients: Array<{
|
|
52
|
+
peerId: string;
|
|
53
|
+
publicKey: string;
|
|
54
|
+
}>;
|
|
55
|
+
owner: string;
|
|
56
|
+
}
|
|
57
|
+
export interface OutboxReceipt {
|
|
58
|
+
roomId: string;
|
|
59
|
+
peerId: string;
|
|
60
|
+
peerPublicKey: string;
|
|
61
|
+
transferId: string;
|
|
62
|
+
merkleRootHex: string;
|
|
63
|
+
chunkIndex?: number;
|
|
64
|
+
cancelled?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface OutboxAckRecord {
|
|
67
|
+
transferId: string;
|
|
68
|
+
publicKey: string;
|
|
69
|
+
bitmap: Uint8Array;
|
|
70
|
+
}
|
|
71
|
+
export type OutboxRequest = {
|
|
72
|
+
kind: "create";
|
|
73
|
+
input: OutboxCreate;
|
|
74
|
+
} | {
|
|
75
|
+
kind: "publish";
|
|
76
|
+
lease: OutboxLease;
|
|
77
|
+
merkleRootHex: string;
|
|
78
|
+
hashHex: string;
|
|
79
|
+
chunkHashes: ArrayBuffer;
|
|
80
|
+
} | {
|
|
81
|
+
kind: "claim";
|
|
82
|
+
transferId: string;
|
|
83
|
+
owner: string;
|
|
84
|
+
senderPublicKey: string;
|
|
85
|
+
roomId: string;
|
|
86
|
+
roomUrl: string;
|
|
87
|
+
policyHex: string;
|
|
88
|
+
} | {
|
|
89
|
+
kind: "selfChunk";
|
|
90
|
+
lease: OutboxLease;
|
|
91
|
+
chunk: Chunk;
|
|
92
|
+
} | {
|
|
93
|
+
kind: "selfMessage";
|
|
94
|
+
lease: OutboxLease;
|
|
95
|
+
message: MessageData;
|
|
96
|
+
} | {
|
|
97
|
+
kind: "renew";
|
|
98
|
+
lease: OutboxLease;
|
|
99
|
+
} | {
|
|
100
|
+
kind: "release";
|
|
101
|
+
lease: OutboxLease;
|
|
102
|
+
lastError?: string;
|
|
103
|
+
} | {
|
|
104
|
+
kind: "receipt";
|
|
105
|
+
receipt: OutboxReceipt;
|
|
106
|
+
} | {
|
|
107
|
+
kind: "list";
|
|
108
|
+
senderPublicKey: string;
|
|
109
|
+
roomId?: string;
|
|
110
|
+
} | {
|
|
111
|
+
kind: "remove";
|
|
112
|
+
transferId?: string;
|
|
113
|
+
roomId?: string;
|
|
114
|
+
lease?: OutboxLease;
|
|
115
|
+
} | {
|
|
116
|
+
kind: "sweep";
|
|
117
|
+
};
|
|
118
|
+
export interface OutboxResponse {
|
|
119
|
+
accepted: boolean;
|
|
120
|
+
manifest?: OutboxManifest;
|
|
121
|
+
manifests?: OutboxManifest[];
|
|
122
|
+
lease?: OutboxLease;
|
|
123
|
+
chunkHashes?: ArrayBuffer;
|
|
124
|
+
acknowledgments?: OutboxAckRecord[];
|
|
125
|
+
}
|
|
126
|
+
export interface ReceiveActivity {
|
|
127
|
+
merkleRoot: string;
|
|
128
|
+
roomId: string;
|
|
129
|
+
fromPeerId: string;
|
|
130
|
+
lastActivityAt: number;
|
|
131
|
+
/** Deletion fences work queued before the terminal operation. */
|
|
132
|
+
deletedAt?: number;
|
|
133
|
+
writeToken?: string;
|
|
134
|
+
leaseUntil?: number;
|
|
135
|
+
}
|