boho 0.8.2 → 1.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/package.json CHANGED
@@ -1,20 +1,13 @@
1
1
  {
2
2
  "name": "boho",
3
- "version": "0.8.2",
3
+ "version": "1.0.0",
4
4
  "description": "Encryption, authentication, Secure communication",
5
- "cjs": "dist/boho.cjs",
6
- "esm": "dist/boho.mjs",
7
- "browser": "dist/boho.min.js",
8
- "browser_esm": "dist/boho.esm.js",
9
5
  "type": "module",
10
6
  "exports": {
11
- "import": "./src/boho.js",
7
+ "import": "./dist/boho.js",
12
8
  "require": "./dist/boho.cjs"
13
9
  },
14
- "scripts": {
15
- "build": "rollup -c",
16
- "test": "mocha"
17
- },
10
+ "browser": "./dist/boho.js",
18
11
  "keywords": [
19
12
  "SSL",
20
13
  "cipher",
@@ -29,19 +22,23 @@
29
22
  "url": "git+https://github.com/remocons/boho.git"
30
23
  },
31
24
  "author": {
32
- "name": "Lee Dongeun",
33
- "email": "sixgen@gmail.com"
25
+ "name": "Lee Taeo",
26
+ "email": "taeo.mocha@gmail.com"
34
27
  },
35
28
  "license": "MIT",
36
29
  "devDependencies": {
37
- "@rollup/plugin-commonjs": "^17.0.0",
38
- "@rollup/plugin-node-resolve": "^11.1.0",
39
- "@rollup/plugin-replace": "^4.0.0",
40
- "@rollup/plugin-terser": "^0.4.0",
41
- "mocha": "^10.0.0",
42
- "rollup": "^2.74.1"
30
+ "@rollup/plugin-commonjs": "^26.0.1",
31
+ "@rollup/plugin-node-resolve": "^15.2.3",
32
+ "@rollup/plugin-replace": "^5.0.7",
33
+ "@rollup/plugin-terser": "^0.4.4",
34
+ "rollup": "^4.21.2"
43
35
  },
44
36
  "dependencies": {
45
- "meta-buffer-pack": "^1.3.1"
37
+ "buffer": "^6.0.3",
38
+ "meta-buffer-pack": "^2.0.1"
39
+ },
40
+ "scripts": {
41
+ "build": "rollup -c",
42
+ "test": "node --test"
46
43
  }
47
44
  }
package/rollup.config.js CHANGED
@@ -1,62 +1,47 @@
1
- import replace from '@rollup/plugin-replace'
2
1
  import resolve from '@rollup/plugin-node-resolve'
3
2
  import commonjs from '@rollup/plugin-commonjs'
4
3
  import terser from '@rollup/plugin-terser'
5
- import pkg from './package.json'
6
4
 
7
5
  export default [
8
6
  {
9
- input: 'src/browserDefault.js',
7
+ input: './src/index.js',
10
8
  output: [
11
9
  {
12
- name: 'Boho',
13
- file: pkg.browser,
10
+ file: './dist/boho.iife.js',
14
11
  format: 'iife',
12
+ name: 'Boho',
15
13
  sourcemap: true
16
- }
17
- ],
18
- plugins: [
19
- replace({
20
- crypto: '',
21
- delimiters: ['import { webcrypto } from \'', '\''],
22
- preventAssignment: true
23
- }),
24
- resolve(),
25
- commonjs()
26
- , terser()
27
- ]
28
- },
29
- {
30
- input: 'src/boho.js',
31
- output: [
14
+ },
32
15
  {
33
- file: pkg.browser_esm,
16
+ file: './dist/boho.js',
34
17
  format: 'es',
35
18
  sourcemap: true
36
19
  }
37
20
  ],
38
21
  plugins: [
39
- replace({
40
- crypto: '',
41
- delimiters: ['import { webcrypto } from \'', '\''],
42
- preventAssignment: true
22
+ resolve({
23
+ preferBuiltins: false
43
24
  }),
44
- resolve(),
45
25
  commonjs()
46
26
  , terser()
47
27
  ]
48
28
  },
49
-
50
29
  {
51
- input: 'src/boho.js',
30
+ input: './src/index.js',
52
31
  output: [
53
- { file: pkg.cjs, format: 'cjs' },
54
- { file: pkg.esm, format: 'es' }
32
+ {
33
+ file: './dist/boho.cjs',
34
+ format: 'cjs',
35
+ exports: 'default'
36
+ }
55
37
  ],
56
38
  plugins: [
57
- resolve(),
39
+ resolve({
40
+ preferBuiltins: true
41
+ }),
58
42
  commonjs()
59
43
  , terser()
60
44
  ]
61
45
  }
46
+
62
47
  ]
package/src/boho.js CHANGED
@@ -1,28 +1,17 @@
1
1
  import { sha256 } from './sha256-mbp.js'
2
- import { MBP, Buffer } from 'meta-buffer-pack'
3
- export { sha256, MBP, Buffer }
4
-
5
- import { webcrypto } from 'crypto'
6
- import { BohoMsg, Meta, MetaSize } from "./constants.js"
7
- export { BohoMsg, Meta, MetaSize }
8
-
9
- let isNode = false
10
- try {
11
- isNode = Object.prototype.toString.call(global.process) === '[object process]'
12
- } catch (e) { }
13
-
2
+ import MBP from 'meta-buffer-pack'
3
+ export { MBP }
4
+ import { BohoMsg, Meta, MetaSize } from './constants.js'
5
+ export { BohoMsg, Meta, MetaSize, sha256 }
6
+ import { Buffer } from 'buffer/index.js'
7
+ export { Buffer}
14
8
 
15
9
  export function RAND(size) {
16
- if( isNode ){
17
- return webcrypto.getRandomValues(Buffer.alloc(size))
18
- }else{
19
- return self.crypto.getRandomValues(Buffer.alloc(size))
20
- }
10
+ return globalThis.crypto.getRandomValues(Buffer.alloc(size))
21
11
  }
22
12
 
23
-
24
-
25
13
  export class Boho {
14
+
26
15
  // A. Core
27
16
  constructor() {
28
17
 
@@ -462,3 +451,4 @@ export class Boho {
462
451
  }
463
452
 
464
453
  }
454
+
package/src/constants.js CHANGED
@@ -1,6 +1,5 @@
1
- import{ MBP, Buffer} from "meta-buffer-pack"
2
- const MB = MBP.MB
3
-
1
+ import MBP from "meta-buffer-pack"
2
+ import { Buffer } from 'buffer/index.js'
4
3
 
5
4
  // remocon message pack one byte header.
6
5
  export let BohoMsg = {
@@ -20,45 +19,45 @@ for (let c in BohoMsg) { BohoMsg[BohoMsg[c]] = c }
20
19
  export const Meta = {
21
20
 
22
21
  AUTH_REQ: MBP.meta( // 2
23
- MB('header','8', 0),
24
- MB('reserved','8', 0)
22
+ MBP.MB('header','8', 0),
23
+ MBP.MB('reserved','8', 0)
25
24
  ),
26
25
 
27
26
  AUTH_NONCE: MBP.meta( // 13
28
- MB('header','8', 0),
29
- MB('unixTime','32L', 0),
30
- MB('milTime','32L', 0 ),
31
- MB('nonce', Buffer.alloc(4))
27
+ MBP.MB('header','8', 0),
28
+ MBP.MB('unixTime','32L', 0),
29
+ MBP.MB('milTime','32L', 0 ),
30
+ MBP.MB('nonce', Buffer.alloc(4))
32
31
  ),
33
32
 
34
33
  AUTH_HMAC: MBP.meta( // 45
35
- MB('header','8', 0),
36
- MB('id8',Buffer.alloc(8)),
37
- MB('nonce', Buffer.alloc(4)),
38
- MB('hmac32', Buffer.alloc(32))
34
+ MBP.MB('header','8', 0),
35
+ MBP.MB('id8',Buffer.alloc(8)),
36
+ MBP.MB('nonce', Buffer.alloc(4)),
37
+ MBP.MB('hmac32', Buffer.alloc(32))
39
38
  ),
40
39
 
41
40
  AUTH_ACK: MBP.meta( // 33
42
- MB('header','8', 0),
43
- MB('hmac32', Buffer.alloc(32))
41
+ MBP.MB('header','8', 0),
42
+ MBP.MB('hmac32', Buffer.alloc(32))
44
43
  ),
45
44
 
46
45
 
47
46
  ENC_PACK: MBP.meta( //25 + payload
48
- MB('type','8',0),
49
- MB('len','32L',0), // pure xdata size.
50
- MB('salt12', Buffer.alloc(12)), // sec,mil,rand
51
- MB('hmac',8,0)
52
- // MB( 'xdata', encData )
47
+ MBP.MB('type','8',0),
48
+ MBP.MB('len','32L',0), // pure xdata size.
49
+ MBP.MB('salt12', Buffer.alloc(12)), // sec,mil,rand
50
+ MBP.MB('hmac',8,0)
51
+ // MBP.MB( 'xdata', encData )
53
52
  ),
54
53
 
55
54
 
56
55
  ENC_488: MBP.meta( // 21 + payload
57
- MB('type','8', 0 ),
58
- MB('len','32L', 0 ),
59
- MB('otpSrc8', Buffer.alloc(8) ),
60
- MB('hmac8', Buffer.alloc(8) )
61
- // MB('xdata', encData )
56
+ MBP.MB('type','8', 0 ),
57
+ MBP.MB('len','32L', 0 ),
58
+ MBP.MB('otpSrc8', Buffer.alloc(8) ),
59
+ MBP.MB('hmac8', Buffer.alloc(8) )
60
+ // MBP.MB('xdata', encData )
62
61
  )
63
62
 
64
63
 
@@ -1,4 +1,4 @@
1
- import { Boho, RAND, MBP, BohoMsg, Meta, MetaSize , sha256, Buffer } from './boho.js'
1
+ import { Boho, RAND, BohoMsg, Meta, MetaSize, sha256, MBP, Buffer } from './boho.js'
2
2
 
3
3
  Boho.RAND = RAND;
4
4
  Boho.BohoMsg = BohoMsg;
package/src/sha256-mbp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { hash, hmac } from '../lib/fast-sha256.js'
2
- import { MBP } from 'meta-buffer-pack'
2
+ import MBP from 'meta-buffer-pack'
3
3
 
4
4
  /*
5
5
  Tip.
@@ -1,5 +1,12 @@
1
- import assert from 'assert/strict'
2
- import { Boho, MBP, MetaSize, BohoMsg, Meta } from 'boho'
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import Boho from 'boho'
4
+
5
+ const MBP = Boho.MBP
6
+ const MetaSize = Boho.MetaSize
7
+ const BohoMsg = Boho.BohoMsg
8
+ const Meta = Boho.Meta
9
+
3
10
 
4
11
  describe('AUTH process ESM', function () {
5
12
  const id = 'id'
@@ -26,7 +33,7 @@ describe('AUTH process ESM', function () {
26
33
  s.set_key(key) // if correct.
27
34
  const auth_ack_buffer = s.check_auth_hmac(unpack)
28
35
 
29
- const auth_ack_buffer_with_incorrect_hmac = MBP.Buffer.alloc(9)
36
+ const auth_ack_buffer_with_incorrect_hmac = Boho.Buffer.alloc(9)
30
37
  const isCorrectSeverHMAC = c.check_auth_ack_hmac(auth_ack_buffer)
31
38
 
32
39
  auth_ack_buffer.copy(auth_ack_buffer_with_incorrect_hmac)
@@ -1,8 +1,9 @@
1
- const assert = require('assert')
2
- const Boho = require('boho').Boho
3
- const MBP = require('boho').MBP
1
+ const { describe, it } = require('node:test');
2
+ const assert = require('node:assert');
3
+ const Boho = require('boho')
4
+ const MBP = Boho.MBP
4
5
 
5
- describe('ENC_PACK CJS', function () {
6
+ describe('ENC_PACK cjs', function () {
6
7
  describe('encryption and decryption', function () {
7
8
  const plainData = 'aaaaa'
8
9
  const key = 'key'
@@ -1,5 +1,9 @@
1
- import assert from 'assert/strict'
2
- import { Boho, MBP } from 'boho'
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import Boho from 'boho'
4
+
5
+ const MBP = Boho.MBP
6
+
3
7
 
4
8
  describe('ENC_PACK ESM', function () {
5
9
  describe('encryption and decryption', function () {
package/test/RAND.js ADDED
@@ -0,0 +1,17 @@
1
+ // import assert from 'assert/strict'
2
+ import { describe, it } from 'node:test';
3
+ import assert from 'node:assert';
4
+ import Boho from 'boho'
5
+
6
+ describe('RAND ESM', function () {
7
+ describe('for number', function () {
8
+ const num = 16
9
+ it('should return Uint8Array', function () {
10
+ assert.ok(Boho.RAND(num) instanceof Uint8Array)
11
+ })
12
+
13
+ it('should return number-bytes size of Uint8Array', function () {
14
+ assert.ok(Boho.RAND(num).byteLength === num)
15
+ })
16
+ })
17
+ })