@bcts/spqr 1.0.0-alpha.21
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/LICENSE +661 -0
- package/README.md +11 -0
- package/dist/index.cjs +4321 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +115 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +115 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.iife.js +4318 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.mjs +4312 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
- package/src/authenticator.ts +163 -0
- package/src/chain.ts +522 -0
- package/src/constants.ts +90 -0
- package/src/encoding/gf.ts +190 -0
- package/src/encoding/index.ts +15 -0
- package/src/encoding/polynomial.ts +657 -0
- package/src/error.ts +75 -0
- package/src/incremental-mlkem768.ts +546 -0
- package/src/index.ts +415 -0
- package/src/kdf.ts +34 -0
- package/src/proto/index.ts +1376 -0
- package/src/proto/pq-ratchet-types.ts +195 -0
- package/src/types.ts +81 -0
- package/src/util.ts +61 -0
- package/src/v1/chunked/index.ts +60 -0
- package/src/v1/chunked/message.ts +257 -0
- package/src/v1/chunked/send-ct.ts +352 -0
- package/src/v1/chunked/send-ek.ts +285 -0
- package/src/v1/chunked/serialize.ts +278 -0
- package/src/v1/chunked/states.ts +399 -0
- package/src/v1/index.ts +9 -0
- package/src/v1/unchunked/index.ts +20 -0
- package/src/v1/unchunked/send-ct.ts +231 -0
- package/src/v1/unchunked/send-ek.ts +177 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/** Secret key material (32 bytes) */
|
|
3
|
+
type Secret = Uint8Array;
|
|
4
|
+
/** Opaque serialized state (protobuf bytes) */
|
|
5
|
+
type SerializedState = Uint8Array;
|
|
6
|
+
/** Opaque serialized message (protobuf V1Msg bytes) */
|
|
7
|
+
type SerializedMessage = Uint8Array;
|
|
8
|
+
/** Interface for random byte generation */
|
|
9
|
+
type RandomBytes = (length: number) => Uint8Array;
|
|
10
|
+
/** Result of send() */
|
|
11
|
+
interface Send {
|
|
12
|
+
state: SerializedState;
|
|
13
|
+
msg: SerializedMessage;
|
|
14
|
+
key: Secret | null;
|
|
15
|
+
}
|
|
16
|
+
/** Result of recv() */
|
|
17
|
+
interface Recv {
|
|
18
|
+
state: SerializedState;
|
|
19
|
+
key: Secret | null;
|
|
20
|
+
}
|
|
21
|
+
/** Parameters for initializing SPQR */
|
|
22
|
+
interface Params {
|
|
23
|
+
direction: Direction;
|
|
24
|
+
version: Version;
|
|
25
|
+
minVersion: Version;
|
|
26
|
+
authKey: Uint8Array;
|
|
27
|
+
chainParams: ChainParams;
|
|
28
|
+
}
|
|
29
|
+
/** Chain configuration parameters */
|
|
30
|
+
interface ChainParams {
|
|
31
|
+
maxJump: number;
|
|
32
|
+
maxOooKeys: number;
|
|
33
|
+
}
|
|
34
|
+
/** Protocol version */
|
|
35
|
+
declare enum Version {
|
|
36
|
+
V0 = 0,
|
|
37
|
+
V1 = 1
|
|
38
|
+
}
|
|
39
|
+
/** Communication direction */
|
|
40
|
+
declare enum Direction {
|
|
41
|
+
A2B = 0,
|
|
42
|
+
B2A = 1
|
|
43
|
+
}
|
|
44
|
+
/** Current version negotiation status */
|
|
45
|
+
type CurrentVersion = {
|
|
46
|
+
type: "still_negotiating";
|
|
47
|
+
version: Version;
|
|
48
|
+
minVersion: Version;
|
|
49
|
+
} | {
|
|
50
|
+
type: "negotiation_complete";
|
|
51
|
+
version: Version;
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/error.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* Copyright © 2025 Signal Messenger, LLC
|
|
57
|
+
* Copyright © 2026 Parity Technologies
|
|
58
|
+
*
|
|
59
|
+
* Error types for the SPQR protocol.
|
|
60
|
+
*/
|
|
61
|
+
declare class SpqrError extends Error {
|
|
62
|
+
readonly code: SpqrErrorCode;
|
|
63
|
+
readonly detail?: unknown | undefined;
|
|
64
|
+
constructor(message: string, code: SpqrErrorCode, detail?: unknown | undefined);
|
|
65
|
+
}
|
|
66
|
+
declare enum SpqrErrorCode {
|
|
67
|
+
StateDecode = "STATE_DECODE",
|
|
68
|
+
NotImplemented = "NOT_IMPLEMENTED",
|
|
69
|
+
MsgDecode = "MSG_DECODE",
|
|
70
|
+
MacVerifyFailed = "MAC_VERIFY_FAILED",
|
|
71
|
+
EpochOutOfRange = "EPOCH_OUT_OF_RANGE",
|
|
72
|
+
EncodingDecoding = "ENCODING_DECODING",
|
|
73
|
+
Serialization = "SERIALIZATION",
|
|
74
|
+
VersionMismatch = "VERSION_MISMATCH",
|
|
75
|
+
MinimumVersion = "MINIMUM_VERSION",
|
|
76
|
+
KeyJump = "KEY_JUMP",
|
|
77
|
+
KeyTrimmed = "KEY_TRIMMED",
|
|
78
|
+
KeyAlreadyRequested = "KEY_ALREADY_REQUESTED",
|
|
79
|
+
ErroneousDataReceived = "ERRONEOUS_DATA_RECEIVED",
|
|
80
|
+
SendKeyEpochDecreased = "SEND_KEY_EPOCH_DECREASED",
|
|
81
|
+
InvalidParams = "INVALID_PARAMS",
|
|
82
|
+
ChainNotAvailable = "CHAIN_NOT_AVAILABLE"
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/index.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Return an empty (V0) serialized state.
|
|
88
|
+
*/
|
|
89
|
+
declare function emptyState(): SerializedState;
|
|
90
|
+
/**
|
|
91
|
+
* Create an initial serialized state from parameters.
|
|
92
|
+
*
|
|
93
|
+
* For V0, returns an empty state. For V1+, initializes the inner V1
|
|
94
|
+
* state machine and version negotiation.
|
|
95
|
+
*/
|
|
96
|
+
declare function initialState(params: Params): SerializedState;
|
|
97
|
+
/**
|
|
98
|
+
* Produce the next outgoing message from the current state.
|
|
99
|
+
*
|
|
100
|
+
* Returns the updated state, serialized message, and optional message key.
|
|
101
|
+
*/
|
|
102
|
+
declare function send(state: SerializedState, rng: RandomBytes): Send;
|
|
103
|
+
/**
|
|
104
|
+
* Process an incoming message and transition the state.
|
|
105
|
+
*
|
|
106
|
+
* Returns the updated state and optional message key.
|
|
107
|
+
*/
|
|
108
|
+
declare function recv(state: SerializedState, msg: SerializedMessage): Recv;
|
|
109
|
+
/**
|
|
110
|
+
* Inspect the current version negotiation status of a serialized state.
|
|
111
|
+
*/
|
|
112
|
+
declare function currentVersion(state: SerializedState): CurrentVersion;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { type ChainParams, type CurrentVersion, Direction, type Params, type RandomBytes, type Recv, type Secret, type Send, type SerializedMessage, type SerializedState, SpqrError, SpqrErrorCode, Version, currentVersion, emptyState, initialState, recv, send };
|
|
115
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/error.ts","../src/index.ts"],"mappings":";;KAWY,MAAA,GAAS,UAAA;;KAMT,eAAA,GAAkB,UAAA;;KAGlB,iBAAA,GAAoB,UAAA;AAGhC;AAAA,KAAY,WAAA,IAAe,MAAA,aAAmB,UAAA;;UAG7B,IAAA;EACf,KAAA,EAAO,eAAA;EACP,GAAA,EAAK,iBAAA;EACL,GAAA,EAAK,MAAA;AAAA;;UAIU,IAAA;EACf,KAAA,EAAO,eAAA;EACP,GAAA,EAAK,MAAA;AAAA;;UAUU,MAAA;EACf,SAAA,EAAW,SAAA;EACX,OAAA,EAAS,OAAA;EACT,UAAA,EAAY,OAAA;EACZ,OAAA,EAAS,UAAA;EACT,WAAA,EAAa,WAAA;AAAA;;UAIE,WAAA;EACf,OAAA;EACA,UAAA;AAAA;AAXF;AAAA,aAeY,OAAA;EACV,EAAA;EACA,EAAA;AAAA;;aAIU,SAAA;EACV,GAAA;EACA,GAAA;AAAA;;KAIU,cAAA;EACN,IAAA;EAA2B,OAAA,EAAS,OAAA;EAAS,UAAA,EAAY,OAAA;AAAA;EACzD,IAAA;EAA8B,OAAA,EAAS,OAAA;AAAA;;;;AA/D7C;;;;;cCJa,SAAA,SAAkB,KAAA;EAAA,SAGX,IAAA,EAAM,aAAA;EAAA,SACN,MAAA;cAFhB,OAAA,UACgB,IAAA,EAAM,aAAA,EACN,MAAA;AAAA;AAAA,aAOR,aAAA;EACV,WAAA;EACA,cAAA;EACA,SAAA;EACA,eAAA;EACA,eAAA;EACA,gBAAA;EACA,aAAA;EACA,eAAA;EACA,cAAA;EACA,OAAA;EACA,UAAA;EACA,mBAAA;EACA,qBAAA;EACA,qBAAA;EACA,aAAA;EACA,iBAAA;AAAA;;;;ADRF;;iBE0CgB,UAAA,CAAA,GAAc,eAAA;;;;;;;iBAcd,YAAA,CAAa,MAAA,EAAQ,MAAA,GAAS,eAAA;;;;;;iBAqC9B,IAAA,CAAK,KAAA,EAAO,eAAA,EAAiB,GAAA,EAAK,WAAA,GAAc,IAAA;AFtFhE;;;;;AAAA,iBE+KgB,IAAA,CAAK,KAAA,EAAO,eAAA,EAAiB,GAAA,EAAK,iBAAA,GAAoB,IAAA;;;;iBAyGtD,cAAA,CAAe,KAAA,EAAO,eAAA,GAAkB,cAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/** Secret key material (32 bytes) */
|
|
3
|
+
type Secret = Uint8Array;
|
|
4
|
+
/** Opaque serialized state (protobuf bytes) */
|
|
5
|
+
type SerializedState = Uint8Array;
|
|
6
|
+
/** Opaque serialized message (protobuf V1Msg bytes) */
|
|
7
|
+
type SerializedMessage = Uint8Array;
|
|
8
|
+
/** Interface for random byte generation */
|
|
9
|
+
type RandomBytes = (length: number) => Uint8Array;
|
|
10
|
+
/** Result of send() */
|
|
11
|
+
interface Send {
|
|
12
|
+
state: SerializedState;
|
|
13
|
+
msg: SerializedMessage;
|
|
14
|
+
key: Secret | null;
|
|
15
|
+
}
|
|
16
|
+
/** Result of recv() */
|
|
17
|
+
interface Recv {
|
|
18
|
+
state: SerializedState;
|
|
19
|
+
key: Secret | null;
|
|
20
|
+
}
|
|
21
|
+
/** Parameters for initializing SPQR */
|
|
22
|
+
interface Params {
|
|
23
|
+
direction: Direction;
|
|
24
|
+
version: Version;
|
|
25
|
+
minVersion: Version;
|
|
26
|
+
authKey: Uint8Array;
|
|
27
|
+
chainParams: ChainParams;
|
|
28
|
+
}
|
|
29
|
+
/** Chain configuration parameters */
|
|
30
|
+
interface ChainParams {
|
|
31
|
+
maxJump: number;
|
|
32
|
+
maxOooKeys: number;
|
|
33
|
+
}
|
|
34
|
+
/** Protocol version */
|
|
35
|
+
declare enum Version {
|
|
36
|
+
V0 = 0,
|
|
37
|
+
V1 = 1
|
|
38
|
+
}
|
|
39
|
+
/** Communication direction */
|
|
40
|
+
declare enum Direction {
|
|
41
|
+
A2B = 0,
|
|
42
|
+
B2A = 1
|
|
43
|
+
}
|
|
44
|
+
/** Current version negotiation status */
|
|
45
|
+
type CurrentVersion = {
|
|
46
|
+
type: "still_negotiating";
|
|
47
|
+
version: Version;
|
|
48
|
+
minVersion: Version;
|
|
49
|
+
} | {
|
|
50
|
+
type: "negotiation_complete";
|
|
51
|
+
version: Version;
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/error.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* Copyright © 2025 Signal Messenger, LLC
|
|
57
|
+
* Copyright © 2026 Parity Technologies
|
|
58
|
+
*
|
|
59
|
+
* Error types for the SPQR protocol.
|
|
60
|
+
*/
|
|
61
|
+
declare class SpqrError extends Error {
|
|
62
|
+
readonly code: SpqrErrorCode;
|
|
63
|
+
readonly detail?: unknown | undefined;
|
|
64
|
+
constructor(message: string, code: SpqrErrorCode, detail?: unknown | undefined);
|
|
65
|
+
}
|
|
66
|
+
declare enum SpqrErrorCode {
|
|
67
|
+
StateDecode = "STATE_DECODE",
|
|
68
|
+
NotImplemented = "NOT_IMPLEMENTED",
|
|
69
|
+
MsgDecode = "MSG_DECODE",
|
|
70
|
+
MacVerifyFailed = "MAC_VERIFY_FAILED",
|
|
71
|
+
EpochOutOfRange = "EPOCH_OUT_OF_RANGE",
|
|
72
|
+
EncodingDecoding = "ENCODING_DECODING",
|
|
73
|
+
Serialization = "SERIALIZATION",
|
|
74
|
+
VersionMismatch = "VERSION_MISMATCH",
|
|
75
|
+
MinimumVersion = "MINIMUM_VERSION",
|
|
76
|
+
KeyJump = "KEY_JUMP",
|
|
77
|
+
KeyTrimmed = "KEY_TRIMMED",
|
|
78
|
+
KeyAlreadyRequested = "KEY_ALREADY_REQUESTED",
|
|
79
|
+
ErroneousDataReceived = "ERRONEOUS_DATA_RECEIVED",
|
|
80
|
+
SendKeyEpochDecreased = "SEND_KEY_EPOCH_DECREASED",
|
|
81
|
+
InvalidParams = "INVALID_PARAMS",
|
|
82
|
+
ChainNotAvailable = "CHAIN_NOT_AVAILABLE"
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/index.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Return an empty (V0) serialized state.
|
|
88
|
+
*/
|
|
89
|
+
declare function emptyState(): SerializedState;
|
|
90
|
+
/**
|
|
91
|
+
* Create an initial serialized state from parameters.
|
|
92
|
+
*
|
|
93
|
+
* For V0, returns an empty state. For V1+, initializes the inner V1
|
|
94
|
+
* state machine and version negotiation.
|
|
95
|
+
*/
|
|
96
|
+
declare function initialState(params: Params): SerializedState;
|
|
97
|
+
/**
|
|
98
|
+
* Produce the next outgoing message from the current state.
|
|
99
|
+
*
|
|
100
|
+
* Returns the updated state, serialized message, and optional message key.
|
|
101
|
+
*/
|
|
102
|
+
declare function send(state: SerializedState, rng: RandomBytes): Send;
|
|
103
|
+
/**
|
|
104
|
+
* Process an incoming message and transition the state.
|
|
105
|
+
*
|
|
106
|
+
* Returns the updated state and optional message key.
|
|
107
|
+
*/
|
|
108
|
+
declare function recv(state: SerializedState, msg: SerializedMessage): Recv;
|
|
109
|
+
/**
|
|
110
|
+
* Inspect the current version negotiation status of a serialized state.
|
|
111
|
+
*/
|
|
112
|
+
declare function currentVersion(state: SerializedState): CurrentVersion;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { type ChainParams, type CurrentVersion, Direction, type Params, type RandomBytes, type Recv, type Secret, type Send, type SerializedMessage, type SerializedState, SpqrError, SpqrErrorCode, Version, currentVersion, emptyState, initialState, recv, send };
|
|
115
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/error.ts","../src/index.ts"],"mappings":";;KAWY,MAAA,GAAS,UAAA;;KAMT,eAAA,GAAkB,UAAA;;KAGlB,iBAAA,GAAoB,UAAA;AAGhC;AAAA,KAAY,WAAA,IAAe,MAAA,aAAmB,UAAA;;UAG7B,IAAA;EACf,KAAA,EAAO,eAAA;EACP,GAAA,EAAK,iBAAA;EACL,GAAA,EAAK,MAAA;AAAA;;UAIU,IAAA;EACf,KAAA,EAAO,eAAA;EACP,GAAA,EAAK,MAAA;AAAA;;UAUU,MAAA;EACf,SAAA,EAAW,SAAA;EACX,OAAA,EAAS,OAAA;EACT,UAAA,EAAY,OAAA;EACZ,OAAA,EAAS,UAAA;EACT,WAAA,EAAa,WAAA;AAAA;;UAIE,WAAA;EACf,OAAA;EACA,UAAA;AAAA;AAXF;AAAA,aAeY,OAAA;EACV,EAAA;EACA,EAAA;AAAA;;aAIU,SAAA;EACV,GAAA;EACA,GAAA;AAAA;;KAIU,cAAA;EACN,IAAA;EAA2B,OAAA,EAAS,OAAA;EAAS,UAAA,EAAY,OAAA;AAAA;EACzD,IAAA;EAA8B,OAAA,EAAS,OAAA;AAAA;;;;AA/D7C;;;;;cCJa,SAAA,SAAkB,KAAA;EAAA,SAGX,IAAA,EAAM,aAAA;EAAA,SACN,MAAA;cAFhB,OAAA,UACgB,IAAA,EAAM,aAAA,EACN,MAAA;AAAA;AAAA,aAOR,aAAA;EACV,WAAA;EACA,cAAA;EACA,SAAA;EACA,eAAA;EACA,eAAA;EACA,gBAAA;EACA,aAAA;EACA,eAAA;EACA,cAAA;EACA,OAAA;EACA,UAAA;EACA,mBAAA;EACA,qBAAA;EACA,qBAAA;EACA,aAAA;EACA,iBAAA;AAAA;;;;ADRF;;iBE0CgB,UAAA,CAAA,GAAc,eAAA;;;;;;;iBAcd,YAAA,CAAa,MAAA,EAAQ,MAAA,GAAS,eAAA;;;;;;iBAqC9B,IAAA,CAAK,KAAA,EAAO,eAAA,EAAiB,GAAA,EAAK,WAAA,GAAc,IAAA;AFtFhE;;;;;AAAA,iBE+KgB,IAAA,CAAK,KAAA,EAAO,eAAA,EAAiB,GAAA,EAAK,iBAAA,GAAoB,IAAA;;;;iBAyGtD,cAAA,CAAe,KAAA,EAAO,eAAA,GAAkB,cAAA"}
|