@onekeyfe/hd-transport-http 1.1.34-alpha.2 → 1.1.34-alpha.3
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/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -11
- package/package.json +4 -4
- package/src/index.ts +17 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _onekeyfe_hd_transport from '@onekeyfe/hd-transport';
|
|
2
|
-
import _onekeyfe_hd_transport__default, { OneKeyDeviceInfoWithSession, AcquireInput } from '@onekeyfe/hd-transport';
|
|
2
|
+
import _onekeyfe_hd_transport__default, { ProtocolType, OneKeyDeviceInfoWithSession, AcquireInput } from '@onekeyfe/hd-transport';
|
|
3
3
|
|
|
4
4
|
type IncompleteRequestOptions = {
|
|
5
5
|
body?: Array<any> | Record<string, unknown> | string;
|
|
@@ -13,6 +13,7 @@ declare class HttpTransport {
|
|
|
13
13
|
stopped: boolean;
|
|
14
14
|
url: string;
|
|
15
15
|
Log?: any;
|
|
16
|
+
getProtocolType(_path: string): ProtocolType;
|
|
16
17
|
constructor(url?: string);
|
|
17
18
|
_post(options: IncompleteRequestOptions): Promise<any>;
|
|
18
19
|
init(logger: any): Promise<string>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAM/C,OAAO,KAAK,EACV,YAAY,EACZ,2BAA2B,EAC3B,YAAY,EACb,MAAM,wBAAwB,CAAC;AAIhC,KAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CA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|
|
129
129
|
|
|
130
|
-
const { check,
|
|
130
|
+
const { check, ProtocolV1, parseConfigure } = transport__default["default"];
|
|
131
131
|
class HttpTransport {
|
|
132
|
+
getProtocolType(_path) {
|
|
133
|
+
return 'V1';
|
|
134
|
+
}
|
|
132
135
|
constructor(url) {
|
|
133
136
|
this.name = 'HttpTransport';
|
|
134
137
|
this.configured = false;
|
|
@@ -213,13 +216,8 @@ class HttpTransport {
|
|
|
213
216
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
214
217
|
}
|
|
215
218
|
const messages = this._messages;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
this.Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
221
|
-
}
|
|
222
|
-
const o = buildOne(messages, name, data);
|
|
219
|
+
this.Log.debug('transport call', { name, protocol: 'V1' });
|
|
220
|
+
const o = ProtocolV1.encodeEnvelope(messages, name, data);
|
|
223
221
|
const outData = o.toString('hex');
|
|
224
222
|
const resData = yield this._post({
|
|
225
223
|
url: `/call/${session}`,
|
|
@@ -229,7 +227,7 @@ class HttpTransport {
|
|
|
229
227
|
if (typeof resData !== 'string') {
|
|
230
228
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
231
229
|
}
|
|
232
|
-
const jsonData =
|
|
230
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
233
231
|
return check.call(jsonData);
|
|
234
232
|
});
|
|
235
233
|
}
|
|
@@ -239,7 +237,7 @@ class HttpTransport {
|
|
|
239
237
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
240
238
|
}
|
|
241
239
|
const messages = this._messages;
|
|
242
|
-
const outData =
|
|
240
|
+
const outData = ProtocolV1.encodeEnvelope(messages, name, data).toString('hex');
|
|
243
241
|
yield this._post({
|
|
244
242
|
url: `/post/${session}`,
|
|
245
243
|
body: outData,
|
|
@@ -258,7 +256,7 @@ class HttpTransport {
|
|
|
258
256
|
if (typeof resData !== 'string') {
|
|
259
257
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
260
258
|
}
|
|
261
|
-
const jsonData =
|
|
259
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
262
260
|
return check.call(jsonData);
|
|
263
261
|
});
|
|
264
262
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-http",
|
|
3
|
-
"version": "1.1.34-alpha.
|
|
3
|
+
"version": "1.1.34-alpha.3",
|
|
4
4
|
"description": "hardware http transport",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@onekeyfe/hd-shared": "1.1.34-alpha.
|
|
28
|
-
"@onekeyfe/hd-transport": "1.1.34-alpha.
|
|
27
|
+
"@onekeyfe/hd-shared": "1.1.34-alpha.3",
|
|
28
|
+
"@onekeyfe/hd-transport": "1.1.34-alpha.3",
|
|
29
29
|
"axios": "1.15.2",
|
|
30
30
|
"secure-json-parse": "^4.0.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "3688bc8495eeb2ffd5616270d13fa29e8967623a"
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import transport
|
|
1
|
+
import transport from '@onekeyfe/hd-transport';
|
|
2
2
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
3
|
|
|
4
4
|
import { request as http } from './http';
|
|
5
5
|
import { DEFAULT_URL } from './constants';
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
AcquireInput,
|
|
9
|
+
OneKeyDeviceInfoWithSession,
|
|
10
|
+
ProtocolType,
|
|
11
|
+
} from '@onekeyfe/hd-transport';
|
|
8
12
|
|
|
9
|
-
const { check,
|
|
13
|
+
const { check, ProtocolV1, parseConfigure } = transport;
|
|
10
14
|
|
|
11
15
|
type IncompleteRequestOptions = {
|
|
12
16
|
body?: Array<any> | Record<string, unknown> | string;
|
|
@@ -27,6 +31,11 @@ export default class HttpTransport {
|
|
|
27
31
|
|
|
28
32
|
Log?: any;
|
|
29
33
|
|
|
34
|
+
// HttpTransport (Bridge) speaks Protocol V1 only.
|
|
35
|
+
getProtocolType(_path: string): ProtocolType {
|
|
36
|
+
return 'V1';
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
constructor(url?: string) {
|
|
31
40
|
this.url = url == null ? DEFAULT_URL : url;
|
|
32
41
|
}
|
|
@@ -111,13 +120,9 @@ export default class HttpTransport {
|
|
|
111
120
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
112
121
|
}
|
|
113
122
|
const messages = this._messages;
|
|
114
|
-
|
|
115
|
-
this.Log.debug('call-', ' name: ', name);
|
|
116
|
-
} else {
|
|
117
|
-
this.Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
118
|
-
}
|
|
123
|
+
this.Log.debug('transport call', { name, protocol: 'V1' });
|
|
119
124
|
|
|
120
|
-
const o =
|
|
125
|
+
const o = ProtocolV1.encodeEnvelope(messages, name, data);
|
|
121
126
|
const outData = o.toString('hex');
|
|
122
127
|
const resData = await this._post({
|
|
123
128
|
url: `/call/${session}`,
|
|
@@ -127,7 +132,7 @@ export default class HttpTransport {
|
|
|
127
132
|
if (typeof resData !== 'string') {
|
|
128
133
|
throw ERRORS.TypedError(HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
129
134
|
}
|
|
130
|
-
const jsonData =
|
|
135
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
131
136
|
return check.call(jsonData);
|
|
132
137
|
}
|
|
133
138
|
|
|
@@ -136,7 +141,7 @@ export default class HttpTransport {
|
|
|
136
141
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
137
142
|
}
|
|
138
143
|
const messages = this._messages;
|
|
139
|
-
const outData =
|
|
144
|
+
const outData = ProtocolV1.encodeEnvelope(messages, name, data).toString('hex');
|
|
140
145
|
await this._post({
|
|
141
146
|
url: `/post/${session}`,
|
|
142
147
|
body: outData,
|
|
@@ -154,7 +159,7 @@ export default class HttpTransport {
|
|
|
154
159
|
if (typeof resData !== 'string') {
|
|
155
160
|
throw ERRORS.TypedError(HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
156
161
|
}
|
|
157
|
-
const jsonData =
|
|
162
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
158
163
|
return check.call(jsonData);
|
|
159
164
|
}
|
|
160
165
|
|