boho 2.1.3 → 2.2.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 CHANGED
@@ -1,77 +1,235 @@
1
- [ [en](../README.md) | kr ]
2
-
3
1
  # Boho
4
2
 
5
- **Node.js, 브라우저, Arduino를 위한 안전하고 가벼운 암호화 및 인증 라이브러리**
3
+ [English](README.md) | [한국어](README.ko.md)
4
+
5
+ **Lightweight encryption and authentication for Node.js, browsers and Arduino**
6
+
7
+ Boho is a JavaScript library providing shared-key authentication and encrypted
8
+ binary messages. It runs in Node.js and browsers; the Arduino implementation is
9
+ available in a separate repository. The current protocol is a custom SHA-256-based
10
+ construction and must not be treated as providing the same guarantees as standard
11
+ AEAD or TLS.
12
+
13
+ - `boho` means **protection** in Korean.
14
+
15
+ ---
16
+
17
+ ## Why Boho?
18
+
19
+ Boho is designed for environments where **you control the code and key provisioning
20
+ at both endpoints**. With known peers such as an Arduino device, your own web app
21
+ and a personal server, you can provision a secret securely before using it for
22
+ authentication and encryption.
23
+
24
+ Many encryption algorithms already exist, but practical development also needs
25
+ peer authentication, packet formats, key provisioning and compatibility between
26
+ devices and browsers. Boho combines a SHA-256-based keystream, XOR encryption,
27
+ shared-key authentication and binary packets. Its distinction is **a common
28
+ implementation and application model for Arduino, Node.js and browsers**, rather
29
+ than novelty in XOR itself.
30
+
31
+ ### Where pre-shared symmetric keys fit
6
32
 
7
- Boho는 강력한 암호화, 인증 및 보안 통신을 위한 경량 JavaScript 라이브러리입니다. Node.js, 브라우저, 그리고 Arduino와 같은 임베디드 시스템을 위해 설계되었으며, 최소한의 오버헤드로 강력한 보안이 필요한 IoT, 임베디드 및 웹 애플리케이션에 이상적입니다.
33
+ | Environment | Example provisioning path |
34
+ | --- | --- |
35
+ | Embedded devices you build | Provision device-specific keys over USB or serial during manufacture or installation |
36
+ | Your own web app and personal device | Users enter a key obtained separately, or register it through trusted pairing |
37
+ | Servers under common administration | Distribute keys through SSH, an existing TLS channel or a secret management system |
8
38
 
9
- - `boho`는 **보호**를 의미합니다.
39
+ If initial key sharing is handled, appropriate symmetric encryption and
40
+ authentication can provide secure communication. Peers can authenticate through
41
+ their shared key without a certificate authority. Trust rests on the provisioning
42
+ path and endpoint software. Sharing one key across many devices expands both its
43
+ authentication scope and the impact of a leak; plan device-specific keys,
44
+ rotation and revocation.
45
+
46
+ Writing a web app yourself does not automatically keep its key secret. A common
47
+ secret included in a public JavaScript bundle is readable by visitors.
48
+
49
+ ### XOR and one-time pads
50
+
51
+ XOR is a simple operation: applying it twice with the same value restores the
52
+ original value.
53
+
54
+ ```text
55
+ Encryption: C = P XOR S
56
+ Decryption: P = C XOR S
57
+
58
+ P: plaintext, C: ciphertext, S: keystream
59
+ ```
60
+
61
+ A uniformly random keystream that is independent of the plaintext, as long as the
62
+ data, kept secret and used only once provides the perfect secrecy of a one-time
63
+ pad (OTP). Under these conditions even simple XOR forms the basis of strong
64
+ encryption. The practical difficulty is supplying a new 1 MB secret pad to both
65
+ endpoints for every 1 MB of data. Repeating a short fixed key does not meet these
66
+ conditions.
67
+
68
+ Reusing a keystream exposes `C1 XOR C2 = P1 XOR P2`, revealing a relationship
69
+ between the plaintexts. Security depends on keystream generation and avoiding
70
+ reuse, not on the complexity of XOR.
71
+
72
+ ### A “virtual OTP” generated with SHA-256
73
+
74
+ Hashing sufficiently unpredictable secret input together with message-specific
75
+ values, while varying a block index, can form a construction that generates a
76
+ keystream of the required length. Both peers can reproduce the same output from
77
+ the same input, without storing or transmitting the entire pad. Boho's usual
78
+ `set_key` path is:
79
+
80
+ ```text
81
+ K = SHA256(input key)
82
+ B = SHA256(K || salt12)
83
+ S1 = SHA256(B || LE32(1))
84
+ S2 = SHA256(B || LE32(2))
85
+ …
86
+ S = S1 || S2 || … // use only the plaintext length
87
+ C = P XOR S
88
+ ```
89
+
90
+ `||` means byte concatenation; `LE32` is a four-byte little-endian integer.
91
+ SHA-256 produces 32 bytes, so a 70-byte plaintext uses two full blocks and the
92
+ first six bytes of the third. Decryption XORs with the same keystream rather than
93
+ reversing the hash.
94
+
95
+ `salt12` contains seconds (4 bytes), milliseconds (2), a counter (2) and a nonce
96
+ (4). These values are not secret and are available to the receiver. **Anyone can
97
+ compute a hash of public random values alone.** The shared secret key is the
98
+ essential secret input; avoiding reuse of `salt12` under the same key is also
99
+ important.
100
+
101
+ “Virtual OTP” here describes a hash-based pseudorandom keystream. Expanding a short
102
+ key into a long output does not provide the information-theoretic security of a
103
+ true OTP. Using standard SHA-256 does not establish the security of the whole
104
+ construction. Keystream generation followed by XOR also appears in
105
+ [ChaCha20](https://www.rfc-editor.org/rfc/rfc8439.html#section-2.4), but Boho is a
106
+ separate custom construction.
107
+
108
+ XOR alone does not detect tampering. Boho data packets also contain a verification
109
+ tag: the first eight bytes of `SHA256(K || salt12 || plaintext)`. Despite the
110
+ legacy `HMAC` names in the code, this tag is not standard HMAC. Receivers must use
111
+ data only after decryption and tag verification succeed.
112
+
113
+ ### Comparing with TLS
114
+
115
+ Typical certificate-based TLS authenticates peers and establishes keys without
116
+ requiring a previously shared secret, then protects application data with
117
+ symmetric encryption. Web services therefore do not need to distribute a secret
118
+ to each visitor in advance. Even users who have not logged in can authenticate a
119
+ server and establish an encrypted connection; this does not imply network
120
+ anonymity.
121
+
122
+ For small embedded projects, certificate chains, trust roots, validity and clock
123
+ management, renewal, handshake work and buffers can be burdensome. Costs include
124
+ code size, memory, power and operating time, not just certificate purchases.
125
+ Systems that can already provision keys securely may be able to omit some of
126
+ this machinery.
127
+
128
+ However, **TLS also supports PSK-only and PSK with (EC)DHE**, so it should not be
129
+ described as always requiring public-key exchange and third-party certificates.
130
+ [TLS 1.3 pre-shared keys](https://www.rfc-editor.org/rfc/rfc8446.html#section-2.2)
131
+
132
+ Boho's lightweight goal is to provide application-packet protection and shared-key
133
+ authentication without public-key operations or certificate handling in its
134
+ construction. This does not mean it is faster or uses less memory than every TLS
135
+ or standard symmetric implementation; actual comparisons require measurement.
136
+
137
+ ### Arduino, web apps and IOSignal
138
+
139
+ Boho's Arduino and JavaScript implementations exchange encrypted packets between
140
+ DIY devices, Node.js servers and browser apps. Boho handles encryption and
141
+ authentication, while [IOSignal](https://github.com/remocons/iosignal) and
142
+ [IOSignal for Arduino](https://github.com/remocons/iosignal-arduino) handle
143
+ connections and message delivery.
144
+
145
+ Connection credentials and end-to-end (E2E) data keys serve different purposes.
146
+ To keep the body confidential from a relay, only the final endpoints should hold
147
+ its separate data key. Ordinary connection encryption is not automatically E2E,
148
+ and E2E does not hide all routing information or traffic sizes.
149
+
150
+ Modified web app code can expose keys and plaintext, so normal web deployments
151
+ can use HTTPS/WSS alongside Boho. Boho does not bypass browser mixed content
152
+ rules, and E2E still requires trust in the provider of the web app code.
153
+
154
+ ### Conditions to check when applying Boho
155
+
156
+ - Use strong random keys. A single SHA-256 in `set_key` is not a slow password KDF.
157
+ - JavaScript uses `crypto.getRandomValues()`, but Arduino currently uses `micros()` for standalone-packet nonces and the authentication client nonce. This is not a cryptographic random source; consider repeated key/`salt12` combinations across restarts, devices and communication directions.
158
+ - A valid tag alone does not prove that a message is new. The caller manages challenge expiry, replay rejection, ordering and permission to execute commands.
159
+ - Boho is a custom protocol. Do not assume standard AEAD/TLS guarantees or forward secrecy protecting past traffic after a long-term key leak.
10
160
 
11
161
  ---
12
162
 
13
- ## 주요 기능
14
- - 범용 암호화 및 복호화
15
- - 상호 인증 프로토콜 (아래 참조)
16
- - 인증 후 보안 통신
17
- - 종단간(End-to-End) 대칭 암호화
18
- - TypeScript 타입 정의 포함
19
- - JavaScript (Node.js, 브라우저) 및 C/C++ (Arduino) 지원
163
+ ## Features
164
+
165
+ - General-purpose encryption and decryption
166
+ - Mutual authentication protocol (see below)
167
+ - Encrypted communication after authentication
168
+ - End-to-end symmetric encryption
169
+ - TypeScript declarations
170
+ - JavaScript (Node.js, browsers) and C/C++ (Arduino) implementations
20
171
 
21
172
  ---
22
173
 
23
- ## 라이브러리
24
- - **JavaScript:** Node.js, 웹 브라우저 ([GitHub](https://github.com/remocons/boho))
174
+ ## Libraries
175
+
176
+ - **JavaScript:** Node.js and browsers ([GitHub](https://github.com/remocons/boho))
25
177
  - **C/C++:** Arduino ([GitHub](https://github.com/remocons/boho-arduino))
26
178
 
27
179
  ---
28
180
 
29
- ## 대표적인 사용 사례
30
- - WebSocket 인증 및 보안 메시징
31
- - 보안 TCP/직렬/스트림 통신
32
- - 보안 MQTT 페이로드
33
- - 로컬 파일 암호화
181
+ ## Typical use cases
182
+
183
+ - WebSocket authentication and encrypted messaging
184
+ - Encrypted TCP, serial and stream communication
185
+ - Encrypted MQTT payloads
186
+ - Local file encryption
34
187
 
35
188
  ---
36
189
 
37
- ## 주요 API
38
- - `encryptPack`, `decryptPack`: 범용 암호화/복호화
39
- - `encrypt_488`, `decrypt_488`: 인증 후 보안 통신
40
- - `encrypt_e2e`, `decrypt_e2e`: 종단간 암호화
41
- - `RAND(size)`: 안전한 랜덤 버퍼 생성
42
- - `sha256.hash`, `sha256.hex`, `sha256.base64`, `sha256.hmac`: 해싱 유틸리티
190
+ ## Main APIs
191
+
192
+ - `encryptPack`, `decryptPack`: general-purpose encryption and decryption
193
+ - `encrypt_488`, `decrypt_488`: encrypted communication after authentication
194
+ - `encrypt_e2e`, `decrypt_e2e`: end-to-end encryption
195
+ - `RAND(size)`: cryptographically secure random buffer generation
196
+ - `sha256.hash`, `sha256.hex`, `sha256.base64`, `sha256.hmac`: hashing utilities
43
197
 
44
198
  ---
45
199
 
46
- ## 인증 프로토콜 (요약)
200
+ ## Authentication protocol overview
47
201
 
48
- boho 라이브러리의 서버-클라이언트 인증(AUTH) 프로세스는 다음과 같은 단계로 이루어집니다.
202
+ The Boho client–server authentication (AUTH) exchange follows these steps.
49
203
 
50
204
  ---
51
205
 
52
- ### 1. 서버 → 클라이언트: SERVER_TIME_NONCE
53
- - 서버는 현재 시각(초/밀리초)과 랜덤 nonce를 포함한 `SERVER_TIME_NONCE` 메시지를 클라이언트에 보냅니다.
54
- - 메시지 타입: `BohoMsg.SERVER_TIME_NONCE`
55
- - 내용: unixTime, milTime, nonce
206
+ ### 1. Server → client: SERVER_TIME_NONCE
207
+
208
+ - The server sends `SERVER_TIME_NONCE` containing the current time (seconds/milliseconds) and a random nonce.
209
+ - Message type: `BohoMsg.SERVER_TIME_NONCE`
210
+ - Contents: unixTime, milTime, nonce
211
+
212
+ ### 2. Client → server: AUTH_REQ
56
213
 
57
- ### 2. 클라이언트 → 서버: AUTH_REQ
58
- - 클라이언트는 서버로부터 받은 nonce와 시각 정보를 바탕으로 salt12를 생성하고, 자신의 랜덤 nonce를 새로 만듭니다.
59
- - salt12와 자신의 nonce를 합쳐 HMAC을 생성한 뒤, `AUTH_REQ` 메시지로 서버에 전송합니다.
60
- - 메시지 타입: `BohoMsg.AUTH_REQ`
61
- - 내용: id8, clientNonce, hmac32
214
+ - The client constructs salt12 from the server's nonce and time, and creates its own nonce. JavaScript uses a random nonce; Arduino currently uses `micros()`.
215
+ - It computes an authentication tag using salt12 and its nonce, then sends `AUTH_REQ`.
216
+ - Message type: `BohoMsg.AUTH_REQ`
217
+ - Contents: id8, clientNonce, hmac32
62
218
 
63
- ### 3. 서버: AUTH_REQ 검증 및 응답
64
- - 서버는 클라이언트의 HMAC이 올바른지 검증합니다.
65
- - 검증 성공 시, 서버는 자신의 HMAC을 생성하여 `AUTH_RES` 메시지로 클라이언트에 응답합니다.
66
- - 실패 시, `AUTH_FAIL` 메시지를 보낼 수 있습니다.
219
+ ### 3. Server: verify AUTH_REQ and respond
67
220
 
68
- ### 4. 클라이언트: AUTH_RES 검증
69
- - 클라이언트는 서버의 `AUTH_RES` 메시지에 포함된 HMAC이 올바른지 검증합니다.
70
- - 검증이 성공하면, 양쪽 모두 `isAuthorized = true` 상태가 되어 이후 암호화 통신이 가능합니다.
221
+ - The server verifies the client's authentication tag.
222
+ - On success, it generates its own tag and returns `AUTH_RES`.
223
+ - On failure, it may send `AUTH_FAIL`.
224
+
225
+ ### 4. Client: verify AUTH_RES
226
+
227
+ - The client verifies the authentication tag in `AUTH_RES`.
228
+ - Once verification succeeds, both peers have `isAuthorized = true` and can exchange encrypted messages.
71
229
 
72
230
  ---
73
231
 
74
- ### 메시지 플로우 요약
232
+ ### Message flow
75
233
 
76
234
  ```mermaid
77
235
  sequenceDiagram
@@ -81,49 +239,53 @@ sequenceDiagram
81
239
  Server->>Client: SERVER_TIME_NONCE (unixTime, milTime, nonce)
82
240
  Client->>Server: AUTH_REQ (id8, clientNonce, hmac32)
83
241
  Server->>Client: AUTH_RES (hmac32) / AUTH_FAIL
84
- Client->>Client: AUTH_RES verification
242
+ Client->>Client: AUTH_RES verification
85
243
  ```
86
244
 
87
245
  ---
88
246
 
89
- ### 각 단계의 목적
247
+ ### Purpose of each step
90
248
 
91
- - **SERVER_TIME_NONCE**: 서버가 시간/nonce를 제공하여 리플레이 공격 방지
92
- - **AUTH_REQ**: 클라이언트가 서버의 정보를 바탕으로 HMAC 생성(서버가 검증)
93
- - **AUTH_RES**: 서버가 클라이언트의 인증 성공을 알리고, 클라이언트는 서버의 HMAC 검증 상호 인증
94
- - **AUTH_FAIL**: 인증 실패 시 서버가 전송
249
+ - **SERVER_TIME_NONCE**: provides a per-connection server challenge; the caller manages its lifetime and reuse policy.
250
+ - **AUTH_REQ**: the client generates an authentication tag from the server's information for server verification.
251
+ - **AUTH_RES**: the server responds after verifying the client; the client verifies the server's tag for mutual authentication.
252
+ - **AUTH_FAIL**: the server sends this on authentication failure.
95
253
 
96
254
  ---
97
255
 
98
- ### 특징 및 보안성
256
+ ### Properties and security scope
99
257
 
100
- - 서버와 클라이언트 모두 랜덤 nonce와 시각 정보를 사용하여, 리플레이 공격에 강함
101
- - HMAC 기반 상호 인증으로, 키를 노출하지 않고 인증 가능
102
- - 인증이 완료되어야만 이후 암호화 통신(ENC_488, ENC_PACK, E2E )이 가능
258
+ - Authentication verifies against the challenge stored by the server. Challenge expiry and reuse restrictions, attempt limits and final connection approval belong to the caller, such as IOSignal.
259
+ - Tag-based mutual authentication avoids transmitting the key itself.
260
+ - `ENC_488` is used after mutual authentication. `ENC_PACK` and E2E operate with an explicitly configured key without requiring a prior authentication exchange.
103
261
 
104
262
  ---
105
263
 
106
- boho의 인증 프로토콜은 서버와 클라이언트가 nonce와 시각 정보를 교환하고, HMAC을 통해 상호 인증하는 구조입니다. 이 과정을 통해 안전하게 세션을 설정하고, 이후 암호화된 데이터 통신이 가능합니다.
264
+ Boho exchanges nonces and time information between the server and client, then
265
+ uses authentication tags for mutual authentication. The authenticated session can
266
+ subsequently exchange encrypted messages.
107
267
 
108
268
  ---
109
269
 
110
- ## 사용 예제
270
+ ## Usage example
271
+
272
+ ### General-purpose encryption and decryption
111
273
 
112
- ### 일반 데이터 암호화 및 복호화
113
274
  ```js
114
275
  import Boho from 'boho'
115
276
 
116
277
  let boho = new Boho()
117
278
 
118
- boho.set_key('abc' )
279
+ // In real communication, use a random key securely shared with the peer.
280
+ boho.set_key(Boho.RAND(32))
119
281
 
120
282
  let data = 'aaaaaaaa'
121
283
 
122
284
  let encData = boho.encryptPack( data )
123
285
  console.log('encData buffer:', encData )
124
286
  let result = boho.decryptPack( encData )
125
-
126
- if(result){
287
+
288
+ if(result){
127
289
  console.log('result object:', result )
128
290
  printMessage(result.data) // decode to string.
129
291
  }else{
@@ -132,22 +294,61 @@ import Boho from 'boho'
132
294
 
133
295
  function printMessage(data){
134
296
  let dataStr = new TextDecoder().decode( data )
135
- console.log('
136
- result string:',dataStr)
297
+ console.log('\n result string:',dataStr)
137
298
  }
138
299
 
139
300
  ```
140
301
 
141
- ### Boho를 사용한 인증 및 보안 통신 예제는 `IOSignal`을 참고하세요.
302
+ ### Authentication and encrypted communication examples
303
+
304
+ See `IOSignal` and the authentication example:
305
+
142
306
  - `iosignal` ([GitHub](https://github.com/remocons/iosignal))
143
307
  - test/AUTH_process.js
144
308
 
145
309
  ---
146
310
 
147
- ## TypeScript 지원
148
- Boho는 완전한 TypeScript 타입 정의를 제공합니다. 간단히 설치하고 가져오기만 하면 TypeScript 프로젝트에서 자동 완성 및 타입 검사를 받을 수 있습니다.
311
+ ## TypeScript support
312
+
313
+ Declarations cover the default-exported `Boho` class and static properties such
314
+ as `Boho.RAND`, `Boho.Buffer` and `Boho.MBP`. Use `import Boho from 'boho'`.
315
+ Named value exports such as `import { Boho, RAND } from 'boho'` are not provided.
316
+
317
+ ## Receive policy and security scope
318
+
319
+ - Internal `HMAC` names and packet `hmac` fields are retained for compatibility. Protocol tags actually use `SHA256(internal key || salt || data)`, not standard HMAC. The utility `Boho.sha256.hmac(key, data)` is standard HMAC.
320
+ - `set_key` requires a nonempty key. `encryptPack` throws if no key is configured, and `clearAuth` also clears the key. `copy_key` accepts exactly 32 bytes.
321
+ - Boho does not enforce a duplicate-receive cache or authentication-stage restrictions. Duplicate, ordering and freshness checks for `ENC_488`, challenge expiry and connection state belong to the caller, such as IOSignal. A valid tag alone does not prove freshness.
322
+ - `set_key`/`copy_key` do not automatically change `isAuthorized`. The caller must explicitly manage state during reauthentication, key changes and shutdown.
323
+ - JS sending maintains increasing clock/counter values even if the clock moves backward or the counter wraps within the same millisecond. Receiving permits existing Arduino clock adjustments and counter wrapping, without enforcing receive-history policy.
324
+ - `ENC_PACK` and E2E support independent messages and stored data, permitting repeated decryption. Replay detection for these APIs belongs to the caller.
325
+ - Decryption rejects truncated packets, invalid types/lengths and tag mismatches with `undefined`. `ENC_PACK`/`ENC_488` also reject extra bytes. IOSignal's `ENC_E2E` is an exception: only the routing header of the declared length is decrypted, and the delivery layer preserves the trailing E2E body. The final recipient verifies that body with `decrypt_e2e`.
326
+ - A slow KDF for short passwords, forward secrecy and E2E key distribution are not provided. Cryptographic design changes, including nonce and tag sizes, require a new protocol version.
327
+
328
+ ## Development checks
329
+
330
+ `npm test` first rebuilds distribution files, then runs regression tests for the
331
+ source, ESM and browser UMD (in a Node VM), plus TypeScript checks. Actual browser
332
+ and physical Arduino tests are separate.
333
+
334
+ `npm run test:arduino` compiles the adjacent `../boho-arduino/src/Boho.cpp`
335
+ unchanged with a host C++ compiler and checks bidirectional JS communication.
336
+ Set `BOHO_ARDUINO_PATH` for a different location. macOS uses CommonCrypto; other
337
+ hosts need OpenSSL development libraries. Test clock, Serial and SHA-256 adapters
338
+ mean this does not replace physical device tests.
339
+
340
+ `npm run test:iosignal` uses the actual sources in adjacent `../iosignal` and
341
+ `../iosignal-arduino`. A loader injects the modified Boho into the JS server and
342
+ client, and tests authentication plus ordinary/E2EE traffic in both directions
343
+ using Arduino IOSignal's 80-byte RX buffer and an in-memory transport.
344
+ `IOSIGNAL_PATH` and `IOSIGNAL_ARDUINO_PATH` override those locations. This does not
345
+ test actual AVR SRAM usage or physical networking.
346
+
347
+ See [security fixes](docs/SECURITY_FIXES.md) for the issue list and compatibility
348
+ impact.
149
349
 
150
350
  ---
151
351
 
152
- ## 라이선스
352
+ ## License
353
+
153
354
  MIT
package/dist/boho.d.ts CHANGED
@@ -5,13 +5,15 @@
5
5
  import { Buffer } from 'buffer';
6
6
  import MBP from 'meta-buffer-pack';
7
7
 
8
- export function RAND(size: number): Buffer;
8
+ declare function RAND(size: number): Buffer;
9
9
 
10
10
  // Interfaces based on src/constants.js and usage in boho.js
11
11
  export interface BohoMsgType {
12
12
  SERVER_TIME_NONCE: number;
13
13
  AUTH_REQ: number;
14
14
  AUTH_RES: number;
15
+ AUTH_FAIL: number;
16
+ ENC_E2E: number;
15
17
  ENC_PACK: number;
16
18
  ENC_488: number;
17
19
  [key: string]: number | string;
@@ -26,7 +28,11 @@ export interface MetaType {
26
28
  }
27
29
 
28
30
  export interface MetaSizeType {
31
+ SERVER_TIME_NONCE: number;
32
+ AUTH_REQ: number;
33
+ AUTH_RES: number;
29
34
  ENC_PACK: number;
35
+ ENC_488: number;
30
36
  }
31
37
 
32
38
  export interface Sha256 {
@@ -36,7 +42,14 @@ export interface Sha256 {
36
42
  hmac(key: any, data: any): Uint8Array;
37
43
  }
38
44
 
39
- export class Boho {
45
+ declare class Boho {
46
+ static RAND: typeof RAND;
47
+ static BohoMsg: BohoMsgType;
48
+ static Meta: MetaType;
49
+ static MetaSize: MetaSizeType;
50
+ static sha256: Sha256;
51
+ static MBP: typeof MBP;
52
+ static Buffer: typeof Buffer;
40
53
  protected _id8: Buffer;
41
54
  protected _otpSrc44: Buffer;
42
55
  protected _otp36: Buffer;
@@ -89,7 +102,7 @@ export class Boho {
89
102
  * Copies key value from external buffer.
90
103
  * @param data
91
104
  */
92
- copy_key(data: Buffer): void;
105
+ copy_key(data: Uint8Array): void;
93
106
 
94
107
  /**
95
108
  * Applies sha256 hash n times.
@@ -128,13 +141,13 @@ export class Boho {
128
141
  getIndexOTP(otpIndex: number): Uint8Array;
129
142
 
130
143
  /**
131
- * Generates HMAC value.
144
+ * Generates the legacy SHA-256 prefix tag, not standard HMAC.
132
145
  * @param data
133
146
  */
134
147
  generateHMAC(data: Buffer): void;
135
148
 
136
149
  /**
137
- * Returns 8-byte HMAC value.
150
+ * Returns the 8-byte legacy tag, not standard HMAC.
138
151
  * @param data
139
152
  */
140
153
  getHMAC8(data: Buffer): Buffer;
@@ -158,20 +171,20 @@ export class Boho {
158
171
  * Generates AUTH_REQ message
159
172
  * @param buffer server's time nonce
160
173
  */
161
- auth_req(buffer: Buffer): Buffer | boolean;
174
+ auth_req(buffer: Uint8Array): Buffer | false;
162
175
 
163
176
  /**
164
177
  * Verify client's AUTH_REQ.
165
178
  * @param data
166
179
  * @returns auth_res packet or false
167
180
  */
168
- verify_auth_req(data: Buffer | object): Buffer | false;
181
+ verify_auth_req(data: Uint8Array | object): Buffer | false;
169
182
 
170
183
  /**
171
184
  * Verifies server's AUTH_RES HMAC.
172
185
  * @param buffer
173
186
  */
174
- verify_auth_res(buffer: Buffer): boolean | undefined;
187
+ verify_auth_res(buffer: Uint8Array): boolean | undefined;
175
188
 
176
189
  // C. Secure Communication
177
190
 
@@ -179,45 +192,41 @@ export class Boho {
179
192
  * Generates encrypted 488 packet after authentication
180
193
  * @param data
181
194
  */
182
- encrypt_488(data: Buffer): Buffer | undefined;
195
+ encrypt_488(data: string | Uint8Array): Buffer | undefined;
183
196
 
184
197
  /**
185
198
  * Decrypts 488 packet after authentication
186
199
  * @param data
187
200
  */
188
- decrypt_488(data: Buffer): Buffer | undefined;
201
+ decrypt_488(data: Uint8Array): Buffer | undefined;
189
202
 
190
203
  /**
191
204
  * Generates encrypted packet for up to 2^32-1 bytes
192
205
  * @param data
193
206
  */
194
- encryptPack(data: Buffer): Buffer;
207
+ encryptPack(data: string | Uint8Array): Buffer;
195
208
 
196
209
  /**
197
210
  * Decrypts encrypted packet
198
211
  * @param data
199
212
  * @returns The decrypted data buffer inside a pack object, or undefined.
200
213
  */
201
- decryptPack(data: Buffer): { data: Buffer, [key: string]: any } | undefined;
214
+ decryptPack(data: Uint8Array): { data: Buffer, [key: string]: any } | undefined;
202
215
 
203
216
  /**
204
217
  * End-to-end encryption
205
218
  * @param data
206
219
  * @param key
207
220
  */
208
- encrypt_e2e(data: Buffer, key: any): Buffer;
221
+ encrypt_e2e(data: string | Uint8Array, key: any): Buffer;
209
222
 
210
223
  /**
211
224
  * End-to-end decryption
212
225
  * @param data
213
226
  * @param key
214
227
  */
215
- decrypt_e2e(data: Buffer, key: any): { data: Buffer, [key: string]: any } | undefined;
228
+ decrypt_e2e(data: Uint8Array, key: any): { data: Buffer, [key: string]: any } | undefined;
216
229
  }
217
230
 
218
- export const BohoMsg: BohoMsgType;
219
- export const Meta: MetaType;
220
- export const MetaSize: MetaSizeType;
221
- export const sha256: Sha256;
222
-
223
- export { MBP, Buffer };
231
+ export type { Boho, Buffer };
232
+ export default Boho;