boho 1.1.0 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boho",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Secure Lightweight Encryption & Authentication Library for Node.js, Browsers and Arduino.",
5
5
  "type": "module",
6
6
  "exports": {
package/src/boho.js CHANGED
@@ -1,3 +1,10 @@
1
+ // Copyright (c) 2024 Taeo Lee (sixgen@gmail.com)
2
+ // MIT License
3
+ //
4
+ // https://github.com/remocons/boho
5
+ //
6
+ //
7
+ //
1
8
  import { sha256 } from './sha256-mbp.js'
2
9
  import MBP from 'meta-buffer-pack'
3
10
  export { MBP }
@@ -7,8 +14,8 @@ import { Buffer } from 'buffer/index.js'
7
14
  export { Buffer}
8
15
 
9
16
  /**
10
- * 랜덤 바이트 버퍼를 생성합니다.
11
- * @param {number} size - 생성할 바이트 수
17
+ * Generates a random byte buffer.
18
+ * @param {number} size - Number of bytes to generate
12
19
  * @returns {Buffer}
13
20
  */
14
21
  export function RAND(size) {
@@ -16,7 +23,7 @@ export function RAND(size) {
16
23
  }
17
24
 
18
25
  /**
19
- * Boho 보안 프로토콜 클래스
26
+ * Boho security protocol class
20
27
  */
21
28
  export class Boho {
22
29
  /**
@@ -37,7 +44,7 @@ export class Boho {
37
44
  }
38
45
 
39
46
  /**
40
- * 인증 상태를 초기화합니다.
47
+ * Initializes authentication state.
41
48
  */
42
49
  clearAuth(){
43
50
  this._id8.fill(0)
@@ -51,7 +58,7 @@ export class Boho {
51
58
  }
52
59
 
53
60
  /**
54
- * 입력 데이터를 해시하여 id8에 설정합니다.
61
+ * Sets id8 by hashing the input data.
55
62
  * @param {any} data
56
63
  */
57
64
  set_hash_id8(data) {
@@ -60,7 +67,7 @@ export class Boho {
60
67
  }
61
68
 
62
69
  /**
63
- * id8 값을 설정합니다.
70
+ * Sets the id8 value.
64
71
  * @param {any} data
65
72
  */
66
73
  set_id8(data) {
@@ -70,7 +77,7 @@ export class Boho {
70
77
  }
71
78
 
72
79
  /**
73
- * 키 값을 해시하여 otpSrc44에 설정합니다.
80
+ * Sets the key value by hashing and storing in otpSrc44.
74
81
  * @param {any} data
75
82
  */
76
83
  set_key(data) {
@@ -79,7 +86,7 @@ export class Boho {
79
86
  }
80
87
 
81
88
  /**
82
- * 'id.key' 문자열을 분리하여 id8과 key를 설정합니다.
89
+ * Splits 'id.key' string and sets id8 and key.
83
90
  * @param {string} id_key
84
91
  */
85
92
  set_id_key(id_key) {
@@ -92,7 +99,7 @@ export class Boho {
92
99
  }
93
100
 
94
101
  /**
95
- * 외부에서 id8 값을 복사합니다.
102
+ * Copies id8 value from external buffer.
96
103
  * @param {Buffer} data
97
104
  */
98
105
  copy_id8(data) {
@@ -100,7 +107,7 @@ export class Boho {
100
107
  }
101
108
 
102
109
  /**
103
- * 외부에서 key 값을 복사합니다.
110
+ * Copies key value from external buffer.
104
111
  * @param {Buffer} data
105
112
  */
106
113
  copy_key(data) {
@@ -108,7 +115,7 @@ export class Boho {
108
115
  }
109
116
 
110
117
  /**
111
- * sha256 해시를 n번 반복 적용합니다.
118
+ * Applies sha256 hash n times.
112
119
  * @param {any} srcData
113
120
  * @param {number} n
114
121
  * @returns {Uint8Array}
@@ -120,7 +127,7 @@ export class Boho {
120
127
  }
121
128
 
122
129
  /**
123
- * 랜덤 시계값(salt12)을 otpSrc44에 설정합니다.
130
+ * Sets random clock value (salt12) in otpSrc44.
124
131
  */
125
132
  set_clock_rand() {
126
133
 
@@ -137,7 +144,7 @@ export class Boho {
137
144
  }
138
145
 
139
146
  /**
140
- * 주어진 nonce와 시계값을 otpSrc44에 설정합니다.
147
+ * Sets otpSrc44 with given nonce and clock value.
141
148
  * @param {Buffer} nonce
142
149
  */
143
150
  set_clock_nonce(nonce) {
@@ -154,7 +161,7 @@ export class Boho {
154
161
  }
155
162
 
156
163
  /**
157
- * salt12 값을 otpSrc44에 설정합니다.
164
+ * Sets salt12 value in otpSrc44.
158
165
  * @param {Buffer} salt12
159
166
  */
160
167
  set_salt12(salt12) {
@@ -162,7 +169,7 @@ export class Boho {
162
169
  }
163
170
 
164
171
  /**
165
- * otp 값을 초기화합니다.
172
+ * Initializes OTP value.
166
173
  */
167
174
  resetOTP() {
168
175
  let otp32 = MBP.B8(sha256.hash(this._otpSrc44))
@@ -170,7 +177,7 @@ export class Boho {
170
177
  }
171
178
 
172
179
  /**
173
- * 인덱스에 해당하는 OTP 값을 반환합니다.
180
+ * Returns OTP value for the given index.
174
181
  * @param {number} otpIndex
175
182
  * @returns {Uint8Array}
176
183
  */
@@ -180,7 +187,7 @@ export class Boho {
180
187
  }
181
188
 
182
189
  /**
183
- * HMAC 값을 생성합니다.
190
+ * Generates HMAC value.
184
191
  * @param {Buffer} data
185
192
  */
186
193
  generateHMAC(data) {
@@ -189,7 +196,7 @@ export class Boho {
189
196
  }
190
197
 
191
198
  /**
192
- * 8바이트 HMAC 값을 반환합니다.
199
+ * Returns 8-byte HMAC value.
193
200
  * @param {Buffer} data
194
201
  * @returns {Buffer}
195
202
  */
@@ -200,7 +207,7 @@ export class Boho {
200
207
  }
201
208
 
202
209
  /**
203
- * OTP 기반 XOR 암호화/복호화
210
+ * OTP-based XOR encryption/decryption
204
211
  * @param {Buffer} data
205
212
  * @param {number} [otpStartIndex=0]
206
213
  * @param {boolean} [shareDataBuffer=false]
@@ -229,7 +236,7 @@ export class Boho {
229
236
  // B. AUTH process
230
237
 
231
238
  /**
232
- * AUTH_REQ 메시지 생성
239
+ * Generates AUTH_REQ message
233
240
  * @returns {Buffer}
234
241
  */
235
242
  auth_req() {
@@ -240,7 +247,7 @@ export class Boho {
240
247
  }
241
248
 
242
249
  /**
243
- * AUTH_NONCE 메시지 생성
250
+ * Generates AUTH_NONCE message
244
251
  * @returns {Buffer}
245
252
  */
246
253
  auth_nonce() {
@@ -262,7 +269,7 @@ export class Boho {
262
269
  }
263
270
 
264
271
  /**
265
- * AUTH_HMAC 메시지 생성
272
+ * Generates AUTH_HMAC message
266
273
  * @param {Buffer} buffer
267
274
  * @returns {Buffer|boolean}
268
275
  */
@@ -304,7 +311,7 @@ export class Boho {
304
311
  */
305
312
 
306
313
  /**
307
- * 클라이언트의 AUTH_HMAC을 검증합니다.
314
+ * Verifies client's AUTH_HMAC.
308
315
  * @param {Buffer|object} data
309
316
  * @returns {boolean}
310
317
  */
@@ -348,7 +355,7 @@ export class Boho {
348
355
  }
349
356
 
350
357
  /**
351
- * 서버의 AUTH_ACK HMAC을 검증합니다.
358
+ * Verifies server's AUTH_ACK HMAC.
352
359
  * @param {Buffer} buffer
353
360
  * @returns {boolean}
354
361
  */
@@ -375,7 +382,7 @@ export class Boho {
375
382
 
376
383
  // Must AUTH first.
377
384
  /**
378
- * 인증 후 488 암호화 패킷 생성
385
+ * Generates encrypted 488 packet after authentication
379
386
  * @param {Buffer} data
380
387
  * @returns {Buffer|undefined}
381
388
  */
@@ -401,7 +408,7 @@ export class Boho {
401
408
  }
402
409
 
403
410
  /**
404
- * 인증 후 488 암호화 패킷 복호화
411
+ * Decrypts 488 packet after authentication
405
412
  * @param {Buffer} data
406
413
  * @returns {Buffer|undefined}
407
414
  */
@@ -431,7 +438,7 @@ export class Boho {
431
438
  }
432
439
 
433
440
  /**
434
- * 최대 2^32-1 바이트 데이터 암호화 패킷 생성
441
+ * Generates encrypted packet for up to 2^32-1 bytes
435
442
  * @param {Buffer} data
436
443
  * @returns {Buffer}
437
444
  */
@@ -455,7 +462,7 @@ export class Boho {
455
462
  }
456
463
 
457
464
  /**
458
- * 암호화 패킷 복호화
465
+ * Decrypts encrypted packet
459
466
  * @param {Buffer} data
460
467
  * @returns {Buffer}
461
468
  */
@@ -492,7 +499,7 @@ export class Boho {
492
499
  }
493
500
 
494
501
  /**
495
- * E2E 암호화
502
+ * End-to-end encryption
496
503
  * @param {Buffer} data
497
504
  * @param {Buffer} key
498
505
  * @returns {Buffer}
@@ -507,7 +514,7 @@ export class Boho {
507
514
  }
508
515
 
509
516
  /**
510
- * E2E 복호화
517
+ * End-to-end decryption
511
518
  * @param {Buffer} data
512
519
  * @param {Buffer} key
513
520
  * @returns {Buffer}
package/src/constants.js CHANGED
@@ -1,8 +1,15 @@
1
+ // Copyright (c) 2024 Taeo Lee (sixgen@gmail.com)
2
+ // MIT License
3
+ //
4
+ // https://github.com/remocons/boho
5
+ //
6
+ //
7
+ //
1
8
  import MBP from "meta-buffer-pack"
2
9
  import { Buffer } from 'buffer/index.js'
3
10
 
4
11
  /**
5
- * Boho 메시지 타입 상수
12
+ * Boho message type constants
6
13
  * @typedef {Object} BohoMsg
7
14
  * @property {number} AUTH_REQ
8
15
  * @property {number} AUTH_NONCE
@@ -15,23 +22,23 @@ import { Buffer } from 'buffer/index.js'
15
22
  * @property {number} ENC_488
16
23
  */
17
24
 
18
- // remocon message pack one byte header.
25
+ // One-byte header for remote control message pack.
19
26
  export let BohoMsg = {
20
- AUTH_REQ : 0xB0,
27
+ AUTH_REQ : 0xB0,
21
28
  AUTH_NONCE: 0xB1,
22
29
  AUTH_HMAC: 0xB2,
23
30
  AUTH_ACK: 0xB3,
24
31
  AUTH_FAIL: 0xB4,
25
32
  AUTH_EXT: 0xB5,
26
- ENC_PACK : 0xB6,
27
- ENC_E2E : 0xB7,
33
+ ENC_PACK : 0xB6,
34
+ ENC_E2E : 0xB7,
28
35
  ENC_488 : 0xB8
29
36
  }
30
37
 
31
38
  for (let c in BohoMsg) { BohoMsg[BohoMsg[c]] = c }
32
39
 
33
40
  /**
34
- * Boho 메시지 메타 정보
41
+ * Boho message meta information
35
42
  * @typedef {Object} Meta
36
43
  * @property {any} AUTH_REQ
37
44
  * @property {any} AUTH_NONCE
@@ -61,16 +68,16 @@ export const Meta = {
61
68
  MBP.MB('nonce', Buffer.alloc(4)),
62
69
  MBP.MB('hmac32', Buffer.alloc(32))
63
70
  ),
64
-
71
+
65
72
  AUTH_ACK: MBP.meta( // 33
66
73
  MBP.MB('header','8', 0),
67
74
  MBP.MB('hmac32', Buffer.alloc(32))
68
75
  ),
69
-
76
+
70
77
 
71
78
  ENC_PACK: MBP.meta( //25 + payload
72
79
  MBP.MB('type','8',0),
73
- MBP.MB('len','32L',0), // pure xdata size.
80
+ MBP.MB('len','32L',0), // pure xdata size.
74
81
  MBP.MB('salt12', Buffer.alloc(12)), // sec,mil,rand
75
82
  MBP.MB('hmac',8,0)
76
83
  // MBP.MB( 'xdata', encData )
@@ -82,7 +89,7 @@ export const Meta = {
82
89
  MBP.MB('len','32L', 0 ),
83
90
  MBP.MB('otpSrc8', Buffer.alloc(8) ),
84
91
  MBP.MB('hmac8', Buffer.alloc(8) )
85
- // MBP.MB('xdata', encData )
92
+ // MBP.MB('xdata', encData )
86
93
  )
87
94
 
88
95
 
@@ -95,7 +102,7 @@ export const Meta = {
95
102
  }
96
103
 
97
104
  /**
98
- * 각 메타의 바이트 크기 정보
105
+ * Byte size information for each meta
99
106
  * @typedef {Object} MetaSize
100
107
  * @property {number} AUTH_REQ
101
108
  * @property {number} AUTH_NONCE
@@ -106,7 +113,7 @@ export const Meta = {
106
113
  */
107
114
 
108
115
  /**
109
- * 각 메타의 바이트 크기 정보
116
+ * Byte size information for each meta
110
117
  * @type {MetaSize}
111
118
  */
112
119
  export const MetaSize = {
package/src/index.js CHANGED
@@ -1,3 +1,10 @@
1
+ // Copyright (c) 2024 Taeo Lee (sixgen@gmail.com)
2
+ // MIT License
3
+ //
4
+ // https://github.com/remocons/boho
5
+ //
6
+ //
7
+ //
1
8
  import { Boho, RAND, BohoMsg, Meta, MetaSize, sha256, MBP, Buffer } from './boho.js'
2
9
 
3
10
  Boho.RAND = RAND;
@@ -9,7 +16,7 @@ Boho.MBP = MBP;
9
16
  Boho.Buffer = Buffer;
10
17
 
11
18
  /**
12
- * boho 라이브러리의 메인 엔트리포인트
19
+ * Main entry point of the boho library
13
20
  * @module boho
14
21
  */
15
22
 
@@ -25,7 +32,7 @@ Boho.Buffer = Buffer;
25
32
  */
26
33
 
27
34
  /**
28
- * boho의 기본 export 객체
35
+ * Default export object of boho
29
36
  * @type {Boho & { RAND: typeof RAND, BohoMsg: typeof BohoMsg, Meta: typeof Meta, MetaSize: typeof MetaSize, sha256: typeof sha256, MBP: typeof MBP, Buffer: typeof Buffer }}
30
37
  */
31
38
  export default Boho;
package/src/sha256-mbp.js CHANGED
@@ -1,3 +1,10 @@
1
+ // Copyright (c) 2024 Taeo Lee (sixgen@gmail.com)
2
+ // MIT License
3
+ //
4
+ // https://github.com/remocons/boho
5
+ //
6
+ //
7
+ //
1
8
  import { hash, hmac } from '../lib/fast-sha256.js'
2
9
  import MBP from 'meta-buffer-pack'
3
10