boho 2.2.2 → 3.0.0

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/dist/boho.d.ts CHANGED
@@ -1,38 +1,37 @@
1
- // TypeScript type definitions for boho
1
+ // TypeScript type definitions for boho 3
2
2
  // Project: https://github.com/remocons/boho
3
3
  // Definitions by: Taeo Lee (sixgen@gmail.com)
4
+ //
5
+ // Boho 3: shared-key authentication and encrypted messages on Ascon (NIST SP 800-232).
6
+ // Boho 2.x (SHA-256 based) is not supported.
4
7
 
5
8
  import { Buffer } from 'buffer';
6
9
  import MBP from 'meta-buffer-pack';
7
10
 
8
11
  declare function RAND(size: number): Buffer;
9
12
 
10
- // Interfaces based on src/constants.js and usage in boho.js
13
+ /** Key string → the 16-byte key a server stores for an ID. */
14
+ declare function deriveKey(key: string | Uint8Array): Buffer;
15
+
11
16
  export interface BohoMsgType {
12
17
  SERVER_TIME_NONCE: number;
18
+ AUTH_FAIL: number;
13
19
  AUTH_REQ: number;
14
20
  AUTH_RES: number;
15
- AUTH_FAIL: number;
16
- ENC_E2E: number;
17
21
  ENC_PACK: number;
18
- ENC_488: number;
22
+ ENC_E2E: number;
23
+ ENC: number;
19
24
  [key: string]: number | string;
20
25
  }
21
26
 
22
- export interface MetaType {
23
- SERVER_TIME_NONCE: any;
24
- AUTH_REQ: any;
25
- AUTH_RES: any;
26
- ENC_PACK: any;
27
- ENC_488: any;
28
- }
29
-
30
27
  export interface MetaSizeType {
31
28
  SERVER_TIME_NONCE: number;
32
29
  AUTH_REQ: number;
33
30
  AUTH_RES: number;
31
+ /** Header size of ENC and ENC_E2E. */
32
+ ENC: number;
33
+ /** Header size of ENC_PACK. */
34
34
  ENC_PACK: number;
35
- ENC_488: number;
36
35
  }
37
36
 
38
37
  export interface Sha256 {
@@ -42,191 +41,77 @@ export interface Sha256 {
42
41
  hmac(key: any, data: any): Uint8Array;
43
42
  }
44
43
 
44
+ export interface Ascon {
45
+ KEY_SIZE: number;
46
+ NONCE_SIZE: number;
47
+ TAG_SIZE: number;
48
+ HASH_SIZE: number;
49
+ CXOF_MAX_CUSTOM: number;
50
+ /** Ascon-AEAD128: ciphertext followed by the tag (tagLength 4..16, default 16). */
51
+ encrypt(key: Uint8Array, nonce: Uint8Array, plaintext?: any, ad?: any, tagLength?: number): Uint8Array;
52
+ /** Plaintext, or null when the tag does not match. */
53
+ decrypt(key: Uint8Array, nonce: Uint8Array, sealed: any, ad?: any, tagLength?: number): Uint8Array | null;
54
+ hash256(data: any): Uint8Array;
55
+ xof128(data: any, outLength: number): Uint8Array;
56
+ cxof128(data: any, outLength: number, custom?: any): Uint8Array;
57
+ }
58
+
59
+ /** Result of decryptPack / decrypt_e2e. */
60
+ export interface OpenedPack {
61
+ type: number;
62
+ len: number;
63
+ sec: number;
64
+ ms: number;
65
+ counter: number;
66
+ sender: Buffer;
67
+ data: Buffer;
68
+ }
69
+
45
70
  declare class Boho {
46
71
  static RAND: typeof RAND;
72
+ static deriveKey: typeof deriveKey;
47
73
  static BohoMsg: BohoMsgType;
48
- static Meta: MetaType;
49
74
  static MetaSize: MetaSizeType;
75
+ static ascon: Ascon;
50
76
  static sha256: Sha256;
51
77
  static MBP: typeof MBP;
52
78
  static Buffer: typeof Buffer;
53
- protected _id8: Buffer;
54
- protected _otpSrc44: Buffer;
55
- protected _otp36: Buffer;
56
- protected _hmac: Buffer;
57
79
 
58
- auth_salt12: Buffer;
59
- localNonce: Buffer;
60
- remoteNonce: Buffer;
80
+ /** True after a verified login (AUTH_RES on a client, AUTH_REQ on a server). */
61
81
  isAuthorized: boolean;
62
- counter: number;
63
82
 
64
83
  constructor();
65
-
66
- /**
67
- * Initializes authentication state.
68
- */
69
84
  clearAuth(): void;
70
-
71
- /**
72
- * Sets id8 by hashing the input data.
73
- * @param data
74
- */
75
- set_hash_id8(data: any): void;
76
-
77
- /**
78
- * Sets the id8 value.
79
- * @param data
80
- */
81
- set_id8(data: any): void;
82
-
83
- /**
84
- * Sets the key value by hashing and storing in otpSrc44.
85
- * @param data
86
- */
87
- set_key(data: any): void;
88
-
89
- /**
90
- * Splits 'id.key' string and sets id8 and key.
91
- * @param id_key
92
- */
93
- set_id_key(id_key: string): void;
94
-
95
- /**
96
- * Copies id8 value from external buffer.
97
- * @param data
98
- */
99
- copy_id8(data: Buffer): void;
100
-
101
- /**
102
- * Copies key value from external buffer.
103
- * @param data
104
- */
105
- copy_key(data: Uint8Array): void;
106
-
107
- /**
108
- * Applies sha256 hash n times.
109
- * @param srcData
110
- * @param n
111
- */
112
- sha256_n(srcData: any, n: number): Uint8Array;
113
-
114
- /**
115
- * Sets random clock value (salt12) in otpSrc44.
116
- */
117
- set_clock_rand(): void;
118
-
119
- /**
120
- * Sets otpSrc44 with given nonce and clock value.
121
- * @param nonce
122
- */
123
- set_clock_nonce(nonce: Buffer): void;
124
-
125
- /**
126
- * Sets salt12 value in otpSrc44.
127
- * @param salt12
128
- * @param caller - for debug
129
- */
130
- set_salt12(salt12: Buffer, caller?: string): void;
131
-
132
- /**
133
- * Initializes OTP value.
134
- */
135
- resetOTP(): void;
136
-
137
- /**
138
- * Returns OTP value for the given index.
139
- * @param otpIndex
140
- */
141
- getIndexOTP(otpIndex: number): Uint8Array;
142
-
143
- /**
144
- * Generates the legacy SHA-256 prefix tag, not standard HMAC.
145
- * @param data
146
- */
147
- generateHMAC(data: Buffer): void;
148
-
149
- /**
150
- * Returns the 8-byte legacy tag, not standard HMAC.
151
- * @param data
152
- */
153
- getHMAC8(data: Buffer): Buffer;
154
-
155
- /**
156
- * OTP-based XOR encryption/decryption
157
- * @param data
158
- * @param otpStartIndex
159
- * @param shareDataBuffer
160
- */
161
- xotp(data: Buffer, otpStartIndex?: number, shareDataBuffer?: boolean): Buffer;
162
-
163
- // B. AUTH process
164
-
165
- /**
166
- * Generates server time and nonce signal
167
- */
85
+ /** The login ID: at most 8 bytes are used. */
86
+ set_id8(id: any): void;
87
+ copy_id8(id8: Uint8Array): void;
88
+ /** Key string → key. A new key ends the session. */
89
+ set_key(key: any): void;
90
+ /** A stored 16-byte key (deriveKey), on a server. */
91
+ copy_key(key16: Uint8Array): void;
92
+ /** 'id.key' */
93
+ set_id_key(idKey: string): void;
94
+
95
+ /** Server: the challenge (SERVER_TIME_NONCE, 13 bytes), kept for verify_auth_req. */
168
96
  server_time_nonce(): Buffer;
169
-
170
- /**
171
- * Generates AUTH_REQ message
172
- * @param buffer server's time nonce
173
- */
174
- auth_req(buffer: Uint8Array): Buffer | false;
175
-
176
- /**
177
- * Verify client's AUTH_REQ.
178
- * @param data
179
- * @returns auth_res packet or false
180
- */
181
- verify_auth_req(data: Uint8Array | object): Buffer | false;
182
-
183
- /**
184
- * Verifies server's AUTH_RES HMAC.
185
- * @param buffer
186
- */
187
- verify_auth_res(buffer: Uint8Array): boolean | undefined;
188
-
189
- // C. Secure Communication
190
-
191
- /**
192
- * Generates encrypted 488 packet after authentication
193
- * @param data
194
- */
195
- encrypt_488(data: string | Uint8Array): Buffer | undefined;
196
-
197
- /**
198
- * Decrypts 488 packet after authentication
199
- * @param data
200
- */
201
- decrypt_488(data: Uint8Array): Buffer | undefined;
202
-
203
- /**
204
- * Generates encrypted packet for up to 2^32-1 bytes
205
- * @param data
206
- */
207
- encryptPack(data: string | Uint8Array): Buffer;
208
-
209
- /**
210
- * Decrypts encrypted packet
211
- * @param data
212
- * @returns The decrypted data buffer inside a pack object, or undefined.
213
- */
214
- decryptPack(data: Uint8Array): { data: Buffer, [key: string]: any } | undefined;
215
-
216
- /**
217
- * End-to-end encryption
218
- * @param data
219
- * @param key
220
- */
221
- encrypt_e2e(data: string | Uint8Array, key: any): Buffer;
222
-
223
- /**
224
- * End-to-end decryption
225
- * @param data
226
- * @param key
227
- */
228
- decrypt_e2e(data: Uint8Array, key: any): { data: Buffer, [key: string]: any } | undefined;
97
+ /** Server: checks AUTH_REQ; returns AUTH_RES, or false. */
98
+ verify_auth_req(packet: Uint8Array, challenge?: Uint8Array): Buffer | false;
99
+ /** Client: AUTH_REQ for the server's SERVER_TIME_NONCE, or false. */
100
+ auth_req(serverTimeNonce: Uint8Array, clientNonce?: Uint8Array): Buffer | false;
101
+ /** Client: checks AUTH_RES. */
102
+ verify_auth_res(packet: Uint8Array): true | undefined;
103
+
104
+ /** ENC (default) or ENC_E2E after a verified login. */
105
+ encrypt_session(data: any, type?: number): Buffer | undefined;
106
+ /** Opens ENC, or the routing header of ENC_E2E. */
107
+ decrypt_session(packet: Uint8Array): Buffer | undefined;
108
+
109
+ /** ENC_PACK with this side's key. */
110
+ encryptPack(data: any): Buffer | undefined;
111
+ decryptPack(packet: Uint8Array): OpenedPack | undefined;
112
+ /** ENC_PACK with an E2E key string. */
113
+ encrypt_e2e(data: any, key: any): Buffer | undefined;
114
+ decrypt_e2e(packet: Uint8Array, key: any): OpenedPack | undefined;
229
115
  }
230
116
 
231
- export type { Boho, Buffer };
232
117
  export default Boho;