iosignal 1.7.1 → 2.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/LICENSE +21 -0
- package/README.md +39 -40
- package/dist/iosignal.cjs +25 -2
- package/dist/iosignal.iife.js +26 -0
- package/dist/iosignal.iife.js.map +1 -0
- package/dist/iosignal.js +26 -0
- package/dist/iosignal.js.map +1 -0
- package/index.js +6 -2
- package/package.json +9 -17
- package/rollup.config.js +13 -37
- package/src/auth/Auth_Env.js +2 -2
- package/src/auth/Auth_File.js +2 -2
- package/src/auth/Auth_Redis.js +2 -2
- package/src/auth/BohoAuth.js +5 -5
- package/src/client/CongPacket.js +1 -1
- package/src/client/IOCore.js +12 -11
- package/src/client/IOWebSocket.js +9 -4
- package/src/common/payload.js +1 -1
- package/src/server/Manager.js +1 -1
- package/src/server/RemoteCore.js +13 -13
- package/test-browser/index.html +10 -10
- package/test-client-nodejs/client.cjs +2 -2
- package/test-client-nodejs/client.mjs +2 -2
- package/test-client-nodejs/client_api_reply.mjs +2 -2
- package/test-client-nodejs/stateChange.mjs +2 -2
- package/test-signal-payloadType/signaling.js +3 -3
- package/dist/iosignal.esm.js +0 -3
- package/dist/iosignal.esm.js.map +0 -1
- package/dist/iosignal.min.js +0 -3
- package/dist/iosignal.min.js.map +0 -1
- package/indexWebBrowser.js +0 -13
package/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export { IOCongSocket } from './src/client/IOCongSocket.js'
|
|
2
|
-
export { IOWS
|
|
2
|
+
export { IOWS } from './src/client/IOWS.js'
|
|
3
3
|
export { pack, CongRx } from './src/client/CongPacket.js'
|
|
4
4
|
export { Server } from './src/server/Server.js'
|
|
5
5
|
export { serverOption } from './src/server/serverOption.js'
|
|
6
6
|
export { FileLogger } from './src/server/FileLogger.js'
|
|
7
|
+
export { getSignalPack, parsePayload, getPayloadFromSignalPack } from './src/common/payload.js'
|
|
7
8
|
export * from './src/common/constants.js'
|
|
8
9
|
|
|
10
|
+
// MBP
|
|
11
|
+
export { default as MBP } from 'meta-buffer-pack'
|
|
12
|
+
|
|
9
13
|
// boho auth
|
|
10
|
-
export
|
|
14
|
+
export { default as Boho} from 'boho'
|
|
11
15
|
export { BohoAuth } from './src/auth/BohoAuth.js'
|
|
12
16
|
export { Auth_File } from './src/auth/Auth_File.js'
|
|
13
17
|
export { Auth_Env } from './src/auth/Auth_Env.js'
|
package/package.json
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iosignal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "iosignal",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/iosignal.cjs",
|
|
7
6
|
"exports": {
|
|
8
7
|
"import": "./index.js",
|
|
9
8
|
"require": "./dist/iosignal.cjs"
|
|
10
9
|
},
|
|
11
|
-
"browser": "./dist/iosignal.
|
|
12
|
-
"browser_esm": "./dist/iosignal.esm.js",
|
|
13
|
-
"esm": "./dist/iosignal.mjs",
|
|
10
|
+
"browser": "./dist/iosignal.js",
|
|
14
11
|
"devDependencies": {
|
|
15
|
-
"@rollup/plugin-commonjs": "^
|
|
16
|
-
"@rollup/plugin-
|
|
17
|
-
"@rollup/plugin-node-resolve": "^11.2.1",
|
|
18
|
-
"@rollup/plugin-replace": "^4.0.0",
|
|
12
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
13
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
19
14
|
"@rollup/plugin-terser": "^0.4.4",
|
|
20
|
-
"
|
|
21
|
-
"redis": "^4.6.12",
|
|
22
|
-
"rollup": "^2.79.1"
|
|
15
|
+
"rollup": "^4.21.2"
|
|
23
16
|
},
|
|
24
17
|
"scripts": {
|
|
25
18
|
"build": "rollup -c",
|
|
@@ -34,15 +27,14 @@
|
|
|
34
27
|
},
|
|
35
28
|
"license": "MIT",
|
|
36
29
|
"dependencies": {
|
|
37
|
-
"boho": "^0.
|
|
38
|
-
"commander": "^12.1.0",
|
|
30
|
+
"boho": "^1.0.1",
|
|
39
31
|
"eventemitter3": "^5.0.1",
|
|
40
|
-
"meta-buffer-pack": "^
|
|
41
|
-
"ws": "^8.
|
|
32
|
+
"meta-buffer-pack": "^2.0.2",
|
|
33
|
+
"ws": "^8.18.0"
|
|
42
34
|
},
|
|
43
35
|
"optionalDependencies": {
|
|
44
36
|
"bufferutil": "^4.0.8",
|
|
45
|
-
"utf-8-validate": "^6.0.
|
|
37
|
+
"utf-8-validate": "^6.0.4"
|
|
46
38
|
},
|
|
47
39
|
"repository": {
|
|
48
40
|
"type": "git",
|
package/rollup.config.js
CHANGED
|
@@ -1,58 +1,35 @@
|
|
|
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 json from '@rollup/plugin-json'
|
|
6
|
-
import pkg from './package.json'
|
|
7
4
|
|
|
8
5
|
export default [
|
|
9
6
|
{
|
|
10
|
-
input: './indexWebBrowser.js',
|
|
11
|
-
output: [
|
|
12
|
-
{
|
|
13
|
-
file: pkg.browser,
|
|
14
|
-
format: 'iife',
|
|
15
|
-
name: 'IO',
|
|
16
|
-
sourcemap: true,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
],
|
|
20
|
-
plugins: [
|
|
21
|
-
replace({
|
|
22
|
-
crypto: '',
|
|
23
|
-
delimiters: ['import { webcrypto } from \'', '\''],
|
|
24
|
-
preventAssignment: true
|
|
25
|
-
}),
|
|
26
|
-
resolve(),
|
|
27
|
-
commonjs()
|
|
28
|
-
,terser()
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
,{
|
|
32
7
|
input: './src/client/IOWebSocket.js',
|
|
33
8
|
output: [
|
|
34
9
|
{
|
|
35
|
-
file:
|
|
10
|
+
file: './dist/iosignal.js',
|
|
36
11
|
format: 'es', //
|
|
37
12
|
sourcemap: true,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
file: './dist/iosignal.iife.js',
|
|
16
|
+
format: 'iife',
|
|
17
|
+
name: 'IO',
|
|
18
|
+
sourcemap: true,
|
|
38
19
|
}
|
|
39
20
|
],
|
|
40
21
|
plugins: [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
delimiters: ['import { webcrypto } from \'', '\''],
|
|
44
|
-
preventAssignment: true
|
|
22
|
+
resolve({
|
|
23
|
+
preferBuiltins: false
|
|
45
24
|
}),
|
|
46
|
-
|
|
47
|
-
commonjs()
|
|
25
|
+
commonjs()
|
|
48
26
|
,terser()
|
|
49
27
|
]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
,{
|
|
28
|
+
},
|
|
29
|
+
{
|
|
53
30
|
input: './index.js',
|
|
54
31
|
output: [
|
|
55
|
-
{ file:
|
|
32
|
+
{ file: './dist/iosignal.cjs',
|
|
56
33
|
format: 'cjs'
|
|
57
34
|
}
|
|
58
35
|
],
|
|
@@ -60,7 +37,6 @@ export default [
|
|
|
60
37
|
resolve({
|
|
61
38
|
preferBuiltins: true
|
|
62
39
|
}),
|
|
63
|
-
json(),
|
|
64
40
|
commonjs()
|
|
65
41
|
,terser()
|
|
66
42
|
]
|
package/src/auth/Auth_Env.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { BohoAuth } from './BohoAuth.js';
|
|
21
|
-
import
|
|
21
|
+
import Boho from 'boho'
|
|
22
22
|
|
|
23
23
|
export class Auth_Env extends BohoAuth {
|
|
24
24
|
constructor(authInfo) {
|
|
@@ -68,7 +68,7 @@ export class Auth_Env extends BohoAuth {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
addAuth(id, keyStr, cid, level = 0) {
|
|
71
|
-
let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
|
|
71
|
+
let Base64hashKey = Buffer.from(Boho.sha256.hash(keyStr)).toString('base64')
|
|
72
72
|
this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
|
|
73
73
|
}
|
|
74
74
|
|
package/src/auth/Auth_File.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BohoAuth } from './BohoAuth.js';
|
|
2
2
|
import { readFileSync } from 'fs'
|
|
3
|
-
import
|
|
3
|
+
import Boho from 'boho'
|
|
4
4
|
import path from 'path'
|
|
5
5
|
|
|
6
6
|
export class Auth_File extends BohoAuth {
|
|
@@ -61,7 +61,7 @@ export class Auth_File extends BohoAuth {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
addAuth(id, keyStr, cid, level = 0) {
|
|
64
|
-
let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
|
|
64
|
+
let Base64hashKey = Buffer.from(Boho.sha256.hash(keyStr)).toString('base64')
|
|
65
65
|
this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
|
|
66
66
|
}
|
|
67
67
|
|
package/src/auth/Auth_Redis.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BohoAuth } from './BohoAuth.js';
|
|
2
|
-
import
|
|
2
|
+
import Boho from 'boho'
|
|
3
3
|
const DEVICE_PREFIX = "device:"
|
|
4
4
|
|
|
5
5
|
export class Auth_Redis extends BohoAuth {
|
|
@@ -28,7 +28,7 @@ export class Auth_Redis extends BohoAuth {
|
|
|
28
28
|
|
|
29
29
|
// add device auth info
|
|
30
30
|
async addAuth(id, keyStr, cid = '', level = 0) {
|
|
31
|
-
let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
|
|
31
|
+
let Base64hashKey = Buffer.from(Boho.sha256.hash(keyStr)).toString('base64')
|
|
32
32
|
return this.redis.hSet(DEVICE_PREFIX + id, { 'key': Base64hashKey, 'cid': cid, 'level': level })
|
|
33
33
|
}
|
|
34
34
|
|
package/src/auth/BohoAuth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import MBP from 'meta-buffer-pack'
|
|
2
|
+
import Boho from 'boho'
|
|
3
3
|
import { quotaTable } from '../common/quotaTable.js'
|
|
4
4
|
import { serverOption } from '../server/serverOption.js'
|
|
5
5
|
import { IOMsg, CLIENT_STATE } from '../common/constants.js'
|
|
@@ -22,17 +22,17 @@ export class BohoAuth {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
console.log('## AUTH_FAIL reason:', reason)
|
|
25
|
-
// peer.send( Buffer.from( [BohoMsg.AUTH_FAIL] ))
|
|
25
|
+
// peer.send( Buffer.from( [Boho.BohoMsg.AUTH_FAIL] ))
|
|
26
26
|
peer.setState(CLIENT_STATE.AUTH_FAIL)
|
|
27
27
|
setTimeout(e => {
|
|
28
|
-
peer.send(Buffer.from([BohoMsg.AUTH_FAIL]))
|
|
28
|
+
peer.send(Buffer.from([Boho.BohoMsg.AUTH_FAIL]))
|
|
29
29
|
}, serverOption.auth.delay_auth_fail)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
async verify_auth_hmac(auth_hmac, peer) {
|
|
33
33
|
try {
|
|
34
34
|
//1. unpack
|
|
35
|
-
let infoPack = MBP.unpack(auth_hmac, Meta.AUTH_HMAC)
|
|
35
|
+
let infoPack = MBP.unpack(auth_hmac, Boho.Meta.AUTH_HMAC)
|
|
36
36
|
if (!infoPack) {
|
|
37
37
|
this.send_auth_fail(peer, 'unpack auth_pack fail');
|
|
38
38
|
return
|
package/src/client/CongPacket.js
CHANGED
package/src/client/IOCore.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import MBP from 'meta-buffer-pack'
|
|
2
2
|
import EventEmitter from "eventemitter3";
|
|
3
|
-
import { Boho, BohoMsg, MetaSize } from "boho";
|
|
4
3
|
import { IOMsg, PAYLOAD_TYPE, SIZE_LIMIT, ENC_MODE, STATES } from '../common/constants.js'
|
|
5
4
|
import { quotaTable } from '../common/quotaTable.js'
|
|
6
5
|
import { getSignalPack } from '../common/payload.js';
|
|
6
|
+
import Boho from "boho";
|
|
7
7
|
|
|
8
|
+
const Buffer = MBP.Buffer;
|
|
8
9
|
const encoder = new TextEncoder()
|
|
9
10
|
const decoder = new TextDecoder()
|
|
10
11
|
|
|
@@ -146,7 +147,7 @@ export class IOCore extends EventEmitter {
|
|
|
146
147
|
let msgType = buffer[0];
|
|
147
148
|
let decoded;
|
|
148
149
|
|
|
149
|
-
if (msgType === BohoMsg.ENC_488) {
|
|
150
|
+
if (msgType === Boho.BohoMsg.ENC_488) {
|
|
150
151
|
decoded = this.boho.decrypt_488(buffer)
|
|
151
152
|
if (decoded) {
|
|
152
153
|
msgType = decoded[0]
|
|
@@ -154,7 +155,7 @@ export class IOCore extends EventEmitter {
|
|
|
154
155
|
} else {
|
|
155
156
|
// console.log('DEC_FAIL', buffer.byteLength)
|
|
156
157
|
}
|
|
157
|
-
} else if (msgType === BohoMsg.ENC_E2E) {
|
|
158
|
+
} else if (msgType === Boho.BohoMsg.ENC_E2E) {
|
|
158
159
|
|
|
159
160
|
try {
|
|
160
161
|
decoded = this.boho.decrypt_488(buffer)
|
|
@@ -162,8 +163,8 @@ export class IOCore extends EventEmitter {
|
|
|
162
163
|
// console.log( 'ENC_E2E decoded ', decoded )
|
|
163
164
|
msgType = decoded[0]
|
|
164
165
|
// decoded has msg_header only.
|
|
165
|
-
buffer.set(decoded, MetaSize.ENC_488) // set decoded signal_e2e headaer.
|
|
166
|
-
buffer = buffer.subarray(MetaSize.ENC_488) // reset offset.
|
|
166
|
+
buffer.set(decoded, Boho.MetaSize.ENC_488) // set decoded signal_e2e headaer.
|
|
167
|
+
buffer = buffer.subarray(Boho.MetaSize.ENC_488) // reset offset.
|
|
167
168
|
// console.log('DECODED MsgType:', IOMsg[ msgType ] )
|
|
168
169
|
} else {
|
|
169
170
|
// console.log('488 DEC_FAIL', buffer)
|
|
@@ -178,7 +179,7 @@ export class IOCore extends EventEmitter {
|
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
let type = IOMsg[msgType]
|
|
181
|
-
if (!type) type = BohoMsg[msgType]
|
|
182
|
+
if (!type) type = Boho.BohoMsg[msgType]
|
|
182
183
|
|
|
183
184
|
// console.log( "MsgType: ", type , " LEN ", buffer.byteLength)
|
|
184
185
|
|
|
@@ -355,7 +356,7 @@ export class IOCore extends EventEmitter {
|
|
|
355
356
|
this.testPromise(buffer)
|
|
356
357
|
break;
|
|
357
358
|
|
|
358
|
-
case BohoMsg.AUTH_NONCE:
|
|
359
|
+
case Boho.BohoMsg.AUTH_NONCE:
|
|
359
360
|
let auth_hmac = this.boho.auth_hmac(buffer)
|
|
360
361
|
if (auth_hmac) {
|
|
361
362
|
this.send(auth_hmac)
|
|
@@ -364,11 +365,11 @@ export class IOCore extends EventEmitter {
|
|
|
364
365
|
}
|
|
365
366
|
break;
|
|
366
367
|
|
|
367
|
-
case BohoMsg.AUTH_FAIL:
|
|
368
|
+
case Boho.BohoMsg.AUTH_FAIL:
|
|
368
369
|
this.stateChange('auth_fail', 'server reject auth.')
|
|
369
370
|
break;
|
|
370
371
|
|
|
371
|
-
case BohoMsg.AUTH_ACK:
|
|
372
|
+
case Boho.BohoMsg.AUTH_ACK:
|
|
372
373
|
if (this.boho.check_auth_ack_hmac(buffer)) {
|
|
373
374
|
this.stateChange('auth_ready', 'server sent auth_ack')
|
|
374
375
|
this.send(Buffer.from([IOMsg.CID_REQ]))
|
|
@@ -484,7 +485,7 @@ export class IOCore extends EventEmitter {
|
|
|
484
485
|
// encrypt signal_header area only. payload is encrypted with e2e key already.
|
|
485
486
|
let tagLen = data[1]
|
|
486
487
|
let encHeader = this.boho.encrypt_488(data.subarray(0, 3 + tagLen))
|
|
487
|
-
encHeader[0] = BohoMsg.ENC_E2E
|
|
488
|
+
encHeader[0] = Boho.BohoMsg.ENC_E2E
|
|
488
489
|
this.send(Buffer.concat([encHeader, data.subarray(3 + tagLen)]))
|
|
489
490
|
// console.log('<< send_enc_mode [ ENC_E2E ]')
|
|
490
491
|
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { IOCore } from "./IOCore.js";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import Boho from 'boho'
|
|
3
|
+
import * as constants from '../common/constants.js'
|
|
4
|
+
|
|
5
|
+
const Buffer = Boho.Buffer
|
|
5
6
|
|
|
6
7
|
// Browser WebSocket
|
|
7
|
-
export class IO extends IOCore {
|
|
8
|
+
export default class IO extends IOCore {
|
|
8
9
|
static binaryType = "arraybuffer"
|
|
10
|
+
static Boho = Boho;
|
|
11
|
+
static MBP = Boho.MBP;
|
|
12
|
+
static Buffer = Boho.Buffer;
|
|
13
|
+
static constants = constants
|
|
9
14
|
|
|
10
15
|
constructor(url) {
|
|
11
16
|
super(url);
|
package/src/common/payload.js
CHANGED
package/src/server/Manager.js
CHANGED
package/src/server/RemoteCore.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { webcrypto } from 'crypto';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
// import { webcrypto } from 'crypto';
|
|
2
|
+
import MBP from 'meta-buffer-pack'
|
|
3
|
+
import Boho from 'boho'
|
|
4
4
|
import { serverOption } from './serverOption.js';
|
|
5
5
|
import { IOMsg, ENC_MODE, CLIENT_STATE } from '../common/constants.js'
|
|
6
6
|
import { quotaTable } from '../common/quotaTable.js'
|
|
@@ -70,7 +70,7 @@ export class RemoteCore {
|
|
|
70
70
|
let from = this.boho.isAuthorized ? `did: ${this.did} ${this.cid}@` : `${this.cid}@`
|
|
71
71
|
if (isBinary) {
|
|
72
72
|
let msgTypeName = IOMsg[message[0]]
|
|
73
|
-
if (!msgTypeName) msgTypeName = BohoMsg[message[0]]
|
|
73
|
+
if (!msgTypeName) msgTypeName = Boho.BohoMsg[message[0]]
|
|
74
74
|
msgTypeName = ' [' + msgTypeName + ']';
|
|
75
75
|
if (message.byteLength > 40) {
|
|
76
76
|
console.log(from + msgTypeName + ' LEN:', message.length);
|
|
@@ -119,7 +119,7 @@ export class RemoteCore {
|
|
|
119
119
|
if (isBinary) {
|
|
120
120
|
msgType = message[0]
|
|
121
121
|
|
|
122
|
-
if (msgType === BohoMsg.ENC_488) {
|
|
122
|
+
if (msgType === Boho.BohoMsg.ENC_488) {
|
|
123
123
|
|
|
124
124
|
try {
|
|
125
125
|
decoded = this.boho.decrypt_488(message)
|
|
@@ -135,7 +135,7 @@ export class RemoteCore {
|
|
|
135
135
|
return
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
} else if (msgType === BohoMsg.ENC_E2E) { // symetric E2EE Signal
|
|
138
|
+
} else if (msgType === Boho.BohoMsg.ENC_E2E) { // symetric E2EE Signal
|
|
139
139
|
try {
|
|
140
140
|
decoded = this.boho.decrypt_488(message)
|
|
141
141
|
} catch (err) {
|
|
@@ -145,14 +145,14 @@ export class RemoteCore {
|
|
|
145
145
|
// console.log('e2e unpack:', decoded )
|
|
146
146
|
if (decoded) {
|
|
147
147
|
msgType = decoded[0]
|
|
148
|
-
message.set(decoded, MetaSize.ENC_488) // set decoded signal_e2e headaer.
|
|
149
|
-
message = message.subarray(MetaSize.ENC_488) // reset offset.
|
|
148
|
+
message.set(decoded, Boho.MetaSize.ENC_488) // set decoded signal_e2e headaer.
|
|
149
|
+
message = message.subarray(Boho.MetaSize.ENC_488) // reset offset.
|
|
150
150
|
} else {
|
|
151
151
|
return
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
} else {
|
|
155
|
-
// console.log( `[P] ${ IOMsg[ msgType] || BohoMsg[cmd]} LEN: ${message.byteLength}` )
|
|
155
|
+
// console.log( `[P] ${ IOMsg[ msgType] || Boho.BohoMsg[cmd]} LEN: ${message.byteLength}` )
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
switch (msgType) {
|
|
@@ -170,7 +170,7 @@ export class RemoteCore {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
if (!this.cid) {
|
|
173
|
-
this.cid = '?' +
|
|
173
|
+
this.cid = '?' + globalThis.crypto.getRandomValues(Buffer.alloc(3)).toString('base64url')
|
|
174
174
|
this.manager.cid2remote.set(this.cid, this)
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -290,7 +290,7 @@ export class RemoteCore {
|
|
|
290
290
|
|
|
291
291
|
|
|
292
292
|
// Auth
|
|
293
|
-
case BohoMsg.AUTH_REQ:
|
|
293
|
+
case Boho.BohoMsg.AUTH_REQ:
|
|
294
294
|
if (!this.manager.authManager) return
|
|
295
295
|
if (this.state < CLIENT_STATE.SENT_SERVER_READY) {
|
|
296
296
|
// console.log('protocol error. auth_req before server_ready')
|
|
@@ -303,7 +303,7 @@ export class RemoteCore {
|
|
|
303
303
|
this.setState(CLIENT_STATE.SENT_SERVER_NONCE)
|
|
304
304
|
break;
|
|
305
305
|
|
|
306
|
-
case BohoMsg.AUTH_HMAC:
|
|
306
|
+
case Boho.BohoMsg.AUTH_HMAC:
|
|
307
307
|
if (!this.manager.authManager) return
|
|
308
308
|
if (this.state < CLIENT_STATE.SENT_SERVER_NONCE) {
|
|
309
309
|
// console.log('protocol error. auth_hmac before server_nonce')
|
|
@@ -387,7 +387,7 @@ export class RemoteCore {
|
|
|
387
387
|
// console.log('server bypass E2E signal taginfo:', tagInfo )
|
|
388
388
|
|
|
389
389
|
let encHeader = this.boho.encrypt_488(data.subarray(0, 3 + tagLen))
|
|
390
|
-
encHeader[0] = BohoMsg.ENC_E2E
|
|
390
|
+
encHeader[0] = Boho.BohoMsg.ENC_E2E
|
|
391
391
|
let newEncBuffer = Buffer.concat([encHeader, data.subarray(3 + tagLen)])
|
|
392
392
|
this.send(newEncBuffer)
|
|
393
393
|
|
package/test-browser/index.html
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
<h2>Simple pub sub example.</h2>
|
|
19
19
|
<p>you should start server first.</p>
|
|
20
20
|
<p>this index.html load two types of modules. </p>
|
|
21
|
-
<h5>1. IIFE: iosignal.
|
|
21
|
+
<h5>1. IIFE: iosignal-iife.js</h5>
|
|
22
22
|
<p>use global name: IO </p>
|
|
23
23
|
<p>IO has props: Boho, MBP, Buffer,, </p>
|
|
24
|
-
<h5>2. ESM: iosignal.
|
|
24
|
+
<h5>2. ESM: iosignal.js</h5>
|
|
25
25
|
<p> check the console.</p>
|
|
26
26
|
<h2>message log</h2>
|
|
27
27
|
<div id="messageView">...</div>
|
|
28
|
-
<script src="../dist/iosignal.
|
|
28
|
+
<script src="../dist/iosignal.iife.js"></script>
|
|
29
29
|
<script>
|
|
30
30
|
console.log('IIFE:')
|
|
31
31
|
console.log('IO', IO)
|
|
@@ -82,16 +82,16 @@
|
|
|
82
82
|
addMessage('ws.error')
|
|
83
83
|
}
|
|
84
84
|
</script>
|
|
85
|
-
|
|
86
|
-
import
|
|
85
|
+
<script type="module">
|
|
86
|
+
import IO from "../dist/iosignal.js"
|
|
87
87
|
ESM_IO = IO
|
|
88
88
|
console.log('ESM:')
|
|
89
89
|
console.log('IO', IO)
|
|
90
|
-
console.log('Boho', Boho )
|
|
91
|
-
console.log('MBP', MBP )
|
|
92
|
-
console.log('Buffer', Buffer)
|
|
93
|
-
console.log('sha256.hash("hi")', sha256.hash('hi'))
|
|
94
|
-
</script>
|
|
90
|
+
console.log('Boho', IO.Boho )
|
|
91
|
+
console.log('MBP', IO.MBP )
|
|
92
|
+
console.log('Buffer', IO.Buffer)
|
|
93
|
+
console.log('sha256.hash("hi")', IO.Boho.sha256.hash('hi'))
|
|
94
|
+
</script>
|
|
95
95
|
</body>
|
|
96
96
|
|
|
97
97
|
</html>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IOWS, Server } from 'iosignal'
|
|
2
2
|
|
|
3
3
|
let url = 'ws://localhost:5555'
|
|
4
4
|
let server = new Server({
|
|
@@ -7,13 +7,13 @@ let server = new Server({
|
|
|
7
7
|
})
|
|
8
8
|
let done = false;
|
|
9
9
|
|
|
10
|
-
let tx = new
|
|
10
|
+
let tx = new IOWS(url)
|
|
11
11
|
tx.on('ready', () => {
|
|
12
12
|
console.log('tx ready', tx.cid)
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
let rx = new
|
|
16
|
+
let rx = new IOWS(url)
|
|
17
17
|
rx.on('ready', () => {
|
|
18
18
|
console.log('rx ready', rx.cid)
|
|
19
19
|
})
|