gamerpc 8.0.6 → 8.0.8
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 +12 -0
- package/package.json +1 -1
- package/src/index.js +671 -38
- package/test/game/kow.js +1 -1
- package/src/authConn.js +0 -595
- package/src/gameConn.js +0 -705
package/test/game/kow.js
CHANGED
|
@@ -23,7 +23,7 @@ const NotifyType = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
//引入长连接组件
|
|
26
|
-
let
|
|
26
|
+
let gameconn = require('../../index');
|
|
27
27
|
let connector = new gameconn(config)
|
|
28
28
|
.setFetch(require('node-fetch')); //设置node服务端环境下兼容的fetch函数,**注意只在node服务端环境下需要,浏览器环境中系统自带 fetch 函数**
|
|
29
29
|
|
package/src/authConn.js
DELETED
|
@@ -1,595 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 授权式连接器,完整封装了客户端通过通过授权模式访问远程全节点的方法,仅仅依赖 create-hmac
|
|
3
|
-
* 可以直接用于 node 环境下的服务端程序,来访问远程全节点丰富的API接口
|
|
4
|
-
* 通过合适的打包程序,也可以用于浏览器环境
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const assert = require('./utils/assert')
|
|
8
|
-
const {io, signHMAC, Base64, now, CommStatus, createHmac, ReturnCode, CommMode, NotifyType, encrypt, decrypt, stringify} = require('./utils/util');
|
|
9
|
-
let {sha1, hash160, hash256, verifyData, generateKey, signObj, verifyObj, verifyAddress} = require('./utils/verifyData');
|
|
10
|
-
const Secret = require('./utils/secret')
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 终端配置管理
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class AuthConn
|
|
17
|
-
{
|
|
18
|
-
constructor() {
|
|
19
|
-
this.defaultNetworkType = 'testnet';
|
|
20
|
-
this.AuthConnConfig = {
|
|
21
|
-
'main': {
|
|
22
|
-
type: 'main',
|
|
23
|
-
ip: '127.0.0.1', //远程服务器地址
|
|
24
|
-
port: 2002, //RPC端口
|
|
25
|
-
head: 'http', //远程服务器通讯协议,分为 http 和 https
|
|
26
|
-
id: 'primary', //默认访问的钱包编号
|
|
27
|
-
apiKey: '', //远程服务器基本校验密码
|
|
28
|
-
cid: '', //授权节点编号,用于访问远程钱包时的认证
|
|
29
|
-
token: '', //授权节点令牌固定量,用于访问远程钱包时的认证
|
|
30
|
-
},
|
|
31
|
-
'testnet': {
|
|
32
|
-
type: 'testnet',
|
|
33
|
-
ip: '127.0.0.1', //远程服务器地址
|
|
34
|
-
port: 2102, //RPC端口
|
|
35
|
-
head: 'http', //远程服务器通讯协议,分为 http 和 https
|
|
36
|
-
id: 'primary', //默认访问的钱包编号
|
|
37
|
-
apiKey: '', //远程服务器基本校验密码
|
|
38
|
-
cid: '', //授权节点编号,用于访问远程钱包时的认证
|
|
39
|
-
token: '', //授权节点令牌固定量,用于访问远程钱包时的认证
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.socketEvents = {};
|
|
44
|
-
this.mode = CommMode.post;
|
|
45
|
-
this.socket = null;
|
|
46
|
-
this.$params = {
|
|
47
|
-
random: null,
|
|
48
|
-
randomTime: null,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 设置通讯模式
|
|
54
|
-
* @param {*} mode 通讯模式
|
|
55
|
-
* @param {*} cb 连接建立时的回调
|
|
56
|
-
*/
|
|
57
|
-
setmode(mode, cb) {
|
|
58
|
-
this.mode = mode;
|
|
59
|
-
if(this.mode == CommMode.ws) {
|
|
60
|
-
this.socketEvents['connect'] = async () => {
|
|
61
|
-
await this.login();
|
|
62
|
-
await this.join();
|
|
63
|
-
if(typeof cb == 'function') {
|
|
64
|
-
await cb();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async retoken() {
|
|
72
|
-
let params = this.getTerminalConfig();
|
|
73
|
-
let msg = await this.setmode(CommMode.ws).execute('token.random', [params.cid]);
|
|
74
|
-
if(!!params.structured) {
|
|
75
|
-
msg = msg.result;
|
|
76
|
-
}
|
|
77
|
-
const hmac = this.createHmac('sha256', msg);
|
|
78
|
-
params.calc = hmac.update(params.token).digest('hex'); //计算并附加访问令牌
|
|
79
|
-
|
|
80
|
-
return params;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* WS模式下的登录流程
|
|
85
|
-
* @param {*} params
|
|
86
|
-
* @param {*} callback
|
|
87
|
-
*/
|
|
88
|
-
async login() {
|
|
89
|
-
let params = await this.retoken();
|
|
90
|
-
|
|
91
|
-
return await this.execute('wallet.auth', [
|
|
92
|
-
params.apiKey,
|
|
93
|
-
params.type,
|
|
94
|
-
params.id,
|
|
95
|
-
params.cid,
|
|
96
|
-
params.calc,
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Listen for events on wallet id.
|
|
102
|
-
* @returns {Promise}
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
async join() {
|
|
106
|
-
let conf = this.getTerminalConfig();
|
|
107
|
-
|
|
108
|
-
let method = 'wallet.join';
|
|
109
|
-
let params = await this.retoken();
|
|
110
|
-
params = [params.id, params.cid, params.calc];
|
|
111
|
-
let sig = signObj({
|
|
112
|
-
method: method,
|
|
113
|
-
params: params,
|
|
114
|
-
cid: conf.cid,
|
|
115
|
-
wid: conf.id,
|
|
116
|
-
}, hash256(Buffer.from(conf.token)));
|
|
117
|
-
|
|
118
|
-
return new Promise((resolve, reject) => {
|
|
119
|
-
this.socket.emit('request', method, params, sig, (err) => {
|
|
120
|
-
if (!!err) {
|
|
121
|
-
console.log(err);
|
|
122
|
-
reject(new Error(err.message));
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
resolve();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Unlisten for events on wallet id.
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
async leave() {
|
|
135
|
-
let conf = this.getTerminalConfig();
|
|
136
|
-
|
|
137
|
-
let method = 'wallet.leave';
|
|
138
|
-
let params = [conf.id];
|
|
139
|
-
let sig = signObj({
|
|
140
|
-
method: method,
|
|
141
|
-
params: params,
|
|
142
|
-
cid: conf.cid,
|
|
143
|
-
wid: conf.id,
|
|
144
|
-
}, hash256(Buffer.from(conf.token)));
|
|
145
|
-
|
|
146
|
-
return new Promise((resolve, reject) => {
|
|
147
|
-
this.socket.emit('request', method, params, sig, (err) => {
|
|
148
|
-
if (err) {
|
|
149
|
-
reject(new Error(err.message));
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
resolve();
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 以 GET 方式,访问开放式API
|
|
159
|
-
* @param {*} url
|
|
160
|
-
*/
|
|
161
|
-
async get(url) {
|
|
162
|
-
const newOptions = { json: true };
|
|
163
|
-
|
|
164
|
-
let conf = this.getTerminalConfig();
|
|
165
|
-
let _head = !!conf.head ? conf.head : 'http';
|
|
166
|
-
url = `${_head}://${conf.ip}:${conf.port}/public/${url}`;
|
|
167
|
-
|
|
168
|
-
newOptions.headers = {
|
|
169
|
-
Accept: 'application/json',
|
|
170
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
let ret = null;
|
|
175
|
-
if(this.fetch) {
|
|
176
|
-
ret = await this.fetch(url, newOptions);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
ret = await fetch(url, newOptions);
|
|
180
|
-
}
|
|
181
|
-
let json = await ret.json();
|
|
182
|
-
|
|
183
|
-
if(!conf.structured) {
|
|
184
|
-
if(json.error) {
|
|
185
|
-
return json;
|
|
186
|
-
} else {
|
|
187
|
-
return json.result; //脱去外围数据结构
|
|
188
|
-
}
|
|
189
|
-
} else {
|
|
190
|
-
return json; //保留外围数据结构
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch(e) {
|
|
194
|
-
console.error(e);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async post(url, options) {
|
|
199
|
-
const newOptions = { json: true, method: 'POST', body: JSON.stringify(options) };
|
|
200
|
-
|
|
201
|
-
let conf = this.getTerminalConfig();
|
|
202
|
-
let _head = !!conf.head ? conf.head : 'http';
|
|
203
|
-
url = `${_head}://${conf.ip}:${conf.port}/public/${url}`;
|
|
204
|
-
|
|
205
|
-
newOptions.headers = {
|
|
206
|
-
Accept: 'application/json',
|
|
207
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
let ret = null;
|
|
212
|
-
if(this.fetch) {
|
|
213
|
-
ret = await this.fetch(url, newOptions);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
ret = await fetch(url, newOptions);
|
|
217
|
-
}
|
|
218
|
-
let json = await ret.json();
|
|
219
|
-
|
|
220
|
-
if(!conf.structured) {
|
|
221
|
-
if(json.error) {
|
|
222
|
-
return json;
|
|
223
|
-
} else {
|
|
224
|
-
return json.result; //脱去外围数据结构
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
return json; //保留外围数据结构
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
catch(e) {
|
|
231
|
-
console.error(e);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* 执行RPC调用
|
|
237
|
-
* @param {*} method
|
|
238
|
-
* @param {*} params
|
|
239
|
-
*/
|
|
240
|
-
async execute(method, params) {
|
|
241
|
-
params = params || [];
|
|
242
|
-
|
|
243
|
-
let conf = this.getTerminalConfig();
|
|
244
|
-
switch(this.mode) {
|
|
245
|
-
case CommMode.ws: {
|
|
246
|
-
if(!this.socket) {
|
|
247
|
-
await this.createSocket();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
let key = generateKey(hash256(Buffer.from(conf.token)));
|
|
251
|
-
let obj = {
|
|
252
|
-
method: method,
|
|
253
|
-
params: params,
|
|
254
|
-
cid: conf.cid,
|
|
255
|
-
wid: conf.id,
|
|
256
|
-
};
|
|
257
|
-
let sig = signObj(obj, key.private);
|
|
258
|
-
|
|
259
|
-
return new Promise((resolve, reject) => {
|
|
260
|
-
this.socket.emit('request', method, params, sig, (err, msg) => {
|
|
261
|
-
if(!!err) {
|
|
262
|
-
reject(err);
|
|
263
|
-
}
|
|
264
|
-
if(!conf.structured) {
|
|
265
|
-
if(!!msg) {
|
|
266
|
-
if(msg.error) {
|
|
267
|
-
resolve(msg);
|
|
268
|
-
} else {
|
|
269
|
-
resolve(msg.result);
|
|
270
|
-
}
|
|
271
|
-
} else {
|
|
272
|
-
resolve(null);
|
|
273
|
-
}
|
|
274
|
-
} else {
|
|
275
|
-
resolve(msg);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
default: {
|
|
282
|
-
await this.queryToken();
|
|
283
|
-
|
|
284
|
-
let opt = this.fillOptions({
|
|
285
|
-
method: 'POST',
|
|
286
|
-
body: {
|
|
287
|
-
method: method,
|
|
288
|
-
params: params,
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
let rt = await this.request(
|
|
293
|
-
opt,
|
|
294
|
-
this.getTerminalConfig(),
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
if(!rt) {
|
|
298
|
-
//console.error(`${method}通讯错误`);
|
|
299
|
-
return { error:-1, };
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if(!!rt.error) {
|
|
303
|
-
//console.error(`${method}: ${rt.error.type} / ${rt.error.message}`);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if(!conf.structured) {
|
|
307
|
-
if(rt.error) {
|
|
308
|
-
return rt;
|
|
309
|
-
} else {
|
|
310
|
-
return rt.result;
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
return rt;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* 计算并返回用于对称加密的密钥
|
|
321
|
-
*/
|
|
322
|
-
getAes() {
|
|
323
|
-
let buf = hash256(Buffer.from(this.getTerminalConfig().token));
|
|
324
|
-
let aeskey = buf.toString('base64').slice(0, 32);
|
|
325
|
-
buf = hash256(buf);
|
|
326
|
-
let aesiv = buf.toString('base64').slice(0, 16);
|
|
327
|
-
|
|
328
|
-
return {aeskey, aesiv};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
getRandom() {
|
|
332
|
-
let _t = (now() / 120) | 0;
|
|
333
|
-
this.$params.randomTime = this.$params.randomTime || _t;
|
|
334
|
-
if (_t > this.$params.randomTime) {
|
|
335
|
-
//有效期检测
|
|
336
|
-
this.$params.random = null;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return this.$params.random;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
setRandom(val) {
|
|
343
|
-
this.$params.random = val;
|
|
344
|
-
if (!!val) {
|
|
345
|
-
this.$params.randomTime = (now() / 120) | 0; //设置有效期
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
fillOptions(options) {
|
|
350
|
-
if (!options) {
|
|
351
|
-
options = {};
|
|
352
|
-
}
|
|
353
|
-
if (!options.body) {
|
|
354
|
-
options.body = {};
|
|
355
|
-
}
|
|
356
|
-
if (!options.headers) {
|
|
357
|
-
options.headers = {};
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
let rnd = this.getRandom();
|
|
361
|
-
let _token = this.getTerminalConfig().token;
|
|
362
|
-
if (_token && rnd) {
|
|
363
|
-
options.body.token = signHMAC(_token, rnd);
|
|
364
|
-
}
|
|
365
|
-
options.body.wid = this.getTerminalConfig().id; //附加默认钱包编号
|
|
366
|
-
options.body.cid = this.getTerminalConfig().cid; //附加客户端编号
|
|
367
|
-
|
|
368
|
-
//对上行数据添加签名, 使用原始 token 作为私钥源
|
|
369
|
-
options.body.sig = signObj({
|
|
370
|
-
method: options.body.method,
|
|
371
|
-
params: options.body.params,
|
|
372
|
-
cid: options.body.cid,
|
|
373
|
-
wid: options.body.wid,
|
|
374
|
-
}, hash256(Buffer.from(_token)));
|
|
375
|
-
|
|
376
|
-
options.body = JSON.stringify(options.body);
|
|
377
|
-
|
|
378
|
-
let auth = {
|
|
379
|
-
username: 'gamerpc',
|
|
380
|
-
password: this.getTerminalConfig().apiKey || '',
|
|
381
|
-
};
|
|
382
|
-
var base = new Base64();
|
|
383
|
-
var result = base.encode(`${auth.username}:${auth.password}`);
|
|
384
|
-
options.headers.Authorization = `Basic ${result}`;
|
|
385
|
-
return options;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
async queryToken() {
|
|
389
|
-
let ret = this.getRandom();
|
|
390
|
-
if (!ret) {
|
|
391
|
-
ret = await this.request(
|
|
392
|
-
this.fillOptions({
|
|
393
|
-
method: 'POST',
|
|
394
|
-
body: {
|
|
395
|
-
method: 'token.random',
|
|
396
|
-
params: [this.getTerminalConfig().cid],
|
|
397
|
-
},
|
|
398
|
-
}),
|
|
399
|
-
this.getTerminalConfig()
|
|
400
|
-
);
|
|
401
|
-
if(!ret || !!ret.error) {
|
|
402
|
-
console.error(`HMAC请求错误`);
|
|
403
|
-
} else {
|
|
404
|
-
this.setRandom(ret.result); //获取令牌随机量
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* 创建通讯连接组件
|
|
411
|
-
* @param {*} ip
|
|
412
|
-
* @param {*} port
|
|
413
|
-
*/
|
|
414
|
-
async createSocket(){
|
|
415
|
-
this.close();
|
|
416
|
-
|
|
417
|
-
let uri = ``;
|
|
418
|
-
let conf = this.getTerminalConfig();
|
|
419
|
-
let _head = !!conf.head ? conf.head : 'http';
|
|
420
|
-
uri = `${_head}://${conf.ip}:${conf.port}/`;
|
|
421
|
-
|
|
422
|
-
this.socket = io(uri, {'force new connection': true})
|
|
423
|
-
.on('disconnect', ()=>{//断线重连
|
|
424
|
-
this.socket.needConnect = true;
|
|
425
|
-
setTimeout(()=>{
|
|
426
|
-
if(!!this.socket.needConnect) {
|
|
427
|
-
this.socket.needConnect = false;
|
|
428
|
-
this.socket.connect();
|
|
429
|
-
}
|
|
430
|
-
}, 1500);
|
|
431
|
-
})
|
|
432
|
-
|
|
433
|
-
Object.keys(this.socketEvents).map(key=>{
|
|
434
|
-
this.socket.on(key, this.socketEvents[key]);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
await (async function(time){return new Promise(resolve =>{setTimeout(resolve, time);});})(2000);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* 关闭长连接
|
|
442
|
-
*/
|
|
443
|
-
close() {
|
|
444
|
-
if(!!this.socket) {
|
|
445
|
-
this.socket.removeAllListeners();
|
|
446
|
-
this.socket.disconnect();
|
|
447
|
-
this.socket = null;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Requests a URL, returning a promise.
|
|
453
|
-
*
|
|
454
|
-
* @param {object} [options] The options we want to pass to "fetch"
|
|
455
|
-
* @return {object} An object containing either "data" or "err"
|
|
456
|
-
*/
|
|
457
|
-
async request(options, conf) {
|
|
458
|
-
const defaultOptions = {
|
|
459
|
-
//credentials: 'include',
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
const newOptions = { ...defaultOptions, ...options };
|
|
463
|
-
newOptions.json = true;
|
|
464
|
-
|
|
465
|
-
let _head = !!conf.head ? conf.head : 'http';
|
|
466
|
-
|
|
467
|
-
newOptions.uri = `${_head}://${conf.ip}:${conf.port}/`;
|
|
468
|
-
|
|
469
|
-
if (
|
|
470
|
-
newOptions.method === 'POST' ||
|
|
471
|
-
newOptions.method === 'PUT' ||
|
|
472
|
-
newOptions.method === 'DELETE'
|
|
473
|
-
) {
|
|
474
|
-
newOptions.headers = {
|
|
475
|
-
Accept: 'application/json',
|
|
476
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
477
|
-
...newOptions.headers,
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
try {
|
|
482
|
-
if(this.fetch) {
|
|
483
|
-
let ret = await this.fetch(newOptions.uri, newOptions);
|
|
484
|
-
return await ret.json();
|
|
485
|
-
}
|
|
486
|
-
else {
|
|
487
|
-
let ret = await fetch(newOptions.uri, newOptions);
|
|
488
|
-
return await ret.json();
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
catch(e) {
|
|
492
|
-
console.error(e);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* 设置服务端推送报文的监控句柄,支持链式调用
|
|
499
|
-
* @param cb 回调
|
|
500
|
-
* @param etype 事件类型
|
|
501
|
-
* @returns {Remote}
|
|
502
|
-
*/
|
|
503
|
-
watch(cb, etype) {
|
|
504
|
-
if(this.socket) {
|
|
505
|
-
this.socket.on(etype, cb);
|
|
506
|
-
} else {
|
|
507
|
-
this.socketEvents[etype] = cb;
|
|
508
|
-
}
|
|
509
|
-
return this;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* 获取终端配置
|
|
514
|
-
* @param {*} networkType
|
|
515
|
-
*/
|
|
516
|
-
getTerminalConfig(networkType) {
|
|
517
|
-
networkType = networkType || this.defaultNetworkType;
|
|
518
|
-
|
|
519
|
-
if(!this.AuthConnConfig[networkType]) {
|
|
520
|
-
this.AuthConnConfig[info.type] = {};
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
return this.AuthConnConfig[networkType];
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* 等待指定时长
|
|
528
|
-
* @param {Number} time 等待时长(毫秒)
|
|
529
|
-
*/
|
|
530
|
-
async wait (time) {
|
|
531
|
-
await (async (time) => {return new Promise(resolve => {setTimeout(resolve, time);});})(time);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* 设置终端配置
|
|
536
|
-
* @param {*} networkType
|
|
537
|
-
* @param {*} info
|
|
538
|
-
*/
|
|
539
|
-
setup(info) {
|
|
540
|
-
if(!!info && info.type) {
|
|
541
|
-
if(!this.AuthConnConfig[info.type]) {
|
|
542
|
-
this.AuthConnConfig[info.type] = {};
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
//设置默认网络类型
|
|
546
|
-
this.defaultNetworkType = info.type;
|
|
547
|
-
|
|
548
|
-
for(let k of Object.keys(info)) {
|
|
549
|
-
//设置默认网络类型的参数 - 逐项设置
|
|
550
|
-
this.AuthConnConfig[info.type][k] = info[k];
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
if(this.mode == CommMode.ws) {
|
|
554
|
-
//断开后自动重连,以便刷新接口参数如目标钱包编号等
|
|
555
|
-
this.close();
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
return this;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* 为了提供node下的兼容性而添加的属性设定函数
|
|
564
|
-
* @param {*} fn
|
|
565
|
-
*/
|
|
566
|
-
setFetch(fn) {
|
|
567
|
-
this.fetch = fn;
|
|
568
|
-
return this;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
AuthConn.prototype.CommMode = CommMode;
|
|
573
|
-
AuthConn.prototype.createHmac = createHmac;
|
|
574
|
-
AuthConn.prototype.assert = assert;
|
|
575
|
-
AuthConn.prototype.stringify = stringify;
|
|
576
|
-
AuthConn.prototype.encrypt = encrypt;
|
|
577
|
-
AuthConn.prototype.decrypt = decrypt;
|
|
578
|
-
AuthConn.prototype.verifyData = verifyData;
|
|
579
|
-
AuthConn.prototype.generateKey = generateKey;
|
|
580
|
-
AuthConn.prototype.signObj = signObj;
|
|
581
|
-
AuthConn.prototype.verifyObj = verifyObj;
|
|
582
|
-
AuthConn.prototype.verifyAddress = verifyAddress;
|
|
583
|
-
AuthConn.prototype.CommMode = CommMode;
|
|
584
|
-
AuthConn.prototype.CommStatus = CommStatus;
|
|
585
|
-
AuthConn.prototype.ReturnCode = ReturnCode;
|
|
586
|
-
AuthConn.prototype.NotifyType = NotifyType;
|
|
587
|
-
AuthConn.prototype.Secret = Secret;
|
|
588
|
-
AuthConn.prototype.hash256 = hash256;
|
|
589
|
-
AuthConn.prototype.hash160 = hash160;
|
|
590
|
-
AuthConn.prototype.sha1 = sha1;
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* 访问全节点的远程调用函数
|
|
594
|
-
*/
|
|
595
|
-
module.exports = AuthConn;
|