boho 0.0.1 → 0.0.2

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,4 +1,41 @@
1
1
  {
2
2
  "name": "boho",
3
- "version": "0.0.1"
4
- }
3
+ "version": "0.0.2",
4
+ "description": "encryption tool",
5
+ "main": "dist/boho.cjs",
6
+ "cjs": "dist/boho.cjs",
7
+ "esm": "dist/boho.mjs",
8
+ "browser": "dist/boho.min.js",
9
+ "browser_esm": "dist/boho.esm.js",
10
+ "type": "module",
11
+ "exports": {
12
+ "import": "./dist/boho.mjs",
13
+ "require": "./dist/boho.cjs"
14
+ },
15
+ "scripts": {
16
+ "test": "mocha"
17
+ },
18
+ "keywords": [
19
+ "암호",
20
+ "cipher",
21
+ "crypto",
22
+ "encrypt"
23
+ ],
24
+ "homepage": "https://github.com/congtrol/boho#readme",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/congtrol/boho.git"
28
+ },
29
+ "author": {
30
+ "name": "Dongeun Lee",
31
+ "email": "sixgen@gmail.com"
32
+ },
33
+ "license": "MIT",
34
+ "devDependencies": {
35
+ "mocha": "^10.0.0"
36
+ },
37
+
38
+ "dependencies": {
39
+ "meta-buffer-pack": "^1.2.1"
40
+ }
41
+ }
@@ -0,0 +1,116 @@
1
+ import assert from 'assert/strict'
2
+ import { SEA , MBP , MetaSize, MsgType ,Meta } from 'boho'
3
+
4
+ describe('AUTH process', function () {
5
+
6
+ const id = "id"
7
+ const key = "key"
8
+
9
+
10
+ //client side
11
+ let c = new SEA()
12
+ c.setStrID( id )
13
+ c.setStrKey( key )
14
+
15
+ let s = new SEA() //server side
16
+
17
+ let auth_req_buffer = s.auth_req()
18
+ let auth_hmac_buffer = c.auth_hmac( auth_req_buffer )
19
+
20
+ let unpack = MBP.unpack( auth_hmac_buffer, Meta.AUTH_HMAC )
21
+
22
+ // Find hashID8 from DATABASE then set the id and key.
23
+ s.setStrID( id )
24
+
25
+ s.setStrKey('wrong-key') // if key is wrong.
26
+ let check_auth_hmack_fail = s.check_auth_hmac( unpack )
27
+
28
+ s.setStrKey( key ); // if correct.
29
+ let auth_ack_buffer = s.check_auth_hmac( unpack )
30
+ // console.log('auth_ack_buffer', auth_ack_buffer )
31
+
32
+ let auth_ack_buffer_with_incorrect_hmac = MBP.Buffer.alloc(9)
33
+ let isCorrectSeverHMAC = c.check_auth_ack_hmac( auth_ack_buffer )
34
+
35
+ auth_ack_buffer.copy( auth_ack_buffer_with_incorrect_hmac)
36
+ auth_ack_buffer_with_incorrect_hmac[2] ^= 0x55 // change hmac
37
+ let wrongSeverHMACResult = c.check_auth_ack_hmac( auth_ack_buffer_with_incorrect_hmac )
38
+
39
+
40
+ describe('1. sever AUTH_REQ pack', function () {
41
+
42
+ it('should return static size buffer', function () {
43
+ // console.log( 'auth-req', auth_req_buffer )
44
+ assert.equal( auth_req_buffer.byteLength , MetaSize.AUTH_REQ )
45
+ })
46
+
47
+ it('should pack[0] is header type ', function () {
48
+ // console.log( 'auth-req', auth_req_buffer )
49
+ assert.ok( auth_req_buffer[0] , MsgType.AUTH_REQ )
50
+ })
51
+
52
+ })
53
+
54
+
55
+ describe('2. client AUTH_HMAC pack', function () {
56
+
57
+ it('should return static size buffer', function () {
58
+ // console.log( 'auth-hmac', auth_hmac_buffer )
59
+ assert.equal( auth_hmac_buffer.byteLength , MetaSize.AUTH_HMAC )
60
+ })
61
+
62
+ it('should pack[0] is header type ', function () {
63
+ // console.log( 'auth-hmac', auth_hmac_buffer )
64
+ assert.ok( auth_hmac_buffer[0] , MsgType.AUTH_HMAC )
65
+ })
66
+
67
+ })
68
+
69
+ describe('3. sever check AUTH_HMACK pack', function () {
70
+
71
+ it('3.1. should success unpack', function () {
72
+ // console.log( 'unpack object of auth-hmac', unpack )
73
+ assert.ok( typeof unpack === 'object' )
74
+ })
75
+
76
+ describe('3.2. check_auth_hmac(obj) ', function () {
77
+
78
+ // wrong key of id.
79
+ it('3.2.1. should return false when wrong key', function () {
80
+ // console.log( 'auth-fail', check_auth_hmack_fail )
81
+ assert.ok( !check_auth_hmack_fail )
82
+ })
83
+
84
+ // correct id and key
85
+ it('3-2.2. should return AUTH_ACK buffer pack when correct key', function () {
86
+ // console.log( 'auth-ack', auth_ack_buffer )
87
+ assert.equal( auth_ack_buffer[0] , MsgType.AUTH_ACK )
88
+ })
89
+ })
90
+
91
+ })
92
+
93
+
94
+
95
+ describe('4. client process', function () {
96
+
97
+ describe('4.1 check_auth_ack_hmac()', function () {
98
+
99
+ it('should return true when correct AUTH_ACK ', function () {
100
+ // console.log( 'auth-ack', auth_ack_buffer )
101
+ assert.ok( isCorrectSeverHMAC )
102
+ })
103
+
104
+ it('should return false when AUTH_ACK has wrong hmac', function () {
105
+ // console.log( 'auth-ack with wrong hmac', auth_ack_buffer_with_incorrect_hmac )
106
+ assert.ok( !wrongSeverHMACResult )
107
+ })
108
+
109
+ })
110
+
111
+
112
+ })
113
+
114
+
115
+
116
+ })
@@ -0,0 +1,24 @@
1
+ import assert from 'assert/strict'
2
+ import { SEA , MBP } from 'boho'
3
+
4
+ describe('ENC_PACK', function () {
5
+ describe('encryption and decryption', function () {
6
+ const plainData = 'aaaaa'
7
+ const key = 'key'
8
+
9
+ it('should decryptPack.data property has same buffer of origin.', function () {
10
+ let sea = new SEA()
11
+ sea.setStrKey( key )
12
+
13
+ let encData = sea.encryptPack( plainData )
14
+ let decObj = sea.decryptPack( encData )
15
+
16
+ let srcBuffer = MBP.B8( plainData )
17
+ let resultBuffer = MBP.B8( decObj.data )
18
+ // console.log( srcBuffer, resultBuffer )
19
+
20
+ assert.ok( MBP.equal( srcBuffer, resultBuffer) )
21
+ })
22
+
23
+ })
24
+ })
package/test/RAND.js ADDED
@@ -0,0 +1,15 @@
1
+ import assert from 'assert/strict'
2
+ import { RAND } from 'boho'
3
+
4
+ describe('RAND', function () {
5
+ describe('for number', function () {
6
+ const num = 16
7
+ it('should return Uint8Array', function () {
8
+ assert.ok(RAND(num) instanceof Uint8Array)
9
+ })
10
+
11
+ it('should return number-bytes size of Uint8Array', function () {
12
+ assert.ok(RAND(num).byteLength === num)
13
+ })
14
+ })
15
+ })
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Document</title>
8
+ </head>
9
+ <body>
10
+ <h1>loading test1: boho.min.js</h1>
11
+ <p>use global name: boho </p>
12
+ <p>boho has SEA, RAND, MBP , Meta,,, </p>
13
+ <h1>loading test2: boho.esm.js</h1>
14
+ <p>embed esm module loader script. check the console.</p>
15
+ <p>this index.html include module two times. </p>
16
+ <script src="../dist/boho.min.js"></script>
17
+ <script type="module">
18
+ import {SEA, MBP ,sha256 } from "../dist/boho.esm.js"
19
+ console.log('SEA', SEA)
20
+ console.log('sha256.hash("hi")', sha256.hash('hi'))
21
+ console.log('MBP', MBP.Buffer.alloc(33))
22
+ </script>
23
+ </body>
24
+ </html>
package/boho-0.0.1.tgz DELETED
Binary file