@onekeyfe/hd-transport-emulator 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 -12
- package/package.json +4 -4
- package/src/http.ts +0 -1
- 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 EmulatorTransport {
|
|
|
13
13
|
configured: boolean;
|
|
14
14
|
stopped: boolean;
|
|
15
15
|
isOutdated: boolean;
|
|
16
|
+
getProtocolType(_path: string): ProtocolType;
|
|
16
17
|
url: string;
|
|
17
18
|
Log?: any;
|
|
18
19
|
constructor(url?: 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,CAAC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|
|
103
103
|
if ((_a = config.url) === null || _a === void 0 ? void 0 : _a.startsWith('http://localhost:21333')) {
|
|
104
104
|
if (!config.headers.get('Origin')) {
|
|
105
|
-
console.log('set node request origin');
|
|
106
105
|
config.headers.set('Origin', 'https://jssdk.onekey.so');
|
|
107
106
|
}
|
|
108
107
|
}
|
|
@@ -111,8 +110,11 @@ axios__default["default"].interceptors.request.use((config) => {
|
|
|
111
110
|
|
|
112
111
|
const DEFAULT_URL = 'http://localhost:21333';
|
|
113
112
|
|
|
114
|
-
const { check,
|
|
113
|
+
const { check, ProtocolV1, parseConfigure } = transport__default["default"];
|
|
115
114
|
class EmulatorTransport {
|
|
115
|
+
getProtocolType(_path) {
|
|
116
|
+
return 'V1';
|
|
117
|
+
}
|
|
116
118
|
constructor(url) {
|
|
117
119
|
this.name = 'EmulatorTransport';
|
|
118
120
|
this.version = '1.0.0';
|
|
@@ -199,13 +201,8 @@ class EmulatorTransport {
|
|
|
199
201
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
200
202
|
}
|
|
201
203
|
const messages = this._messages;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
this.Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
207
|
-
}
|
|
208
|
-
const o = buildOne(messages, name, data);
|
|
204
|
+
this.Log.debug('transport call', { name, protocol: 'V1' });
|
|
205
|
+
const o = ProtocolV1.encodeEnvelope(messages, name, data);
|
|
209
206
|
const outData = o.toString('hex');
|
|
210
207
|
const resData = yield this._post({
|
|
211
208
|
url: `/call/${session}`,
|
|
@@ -215,7 +212,7 @@ class EmulatorTransport {
|
|
|
215
212
|
if (typeof resData !== 'string') {
|
|
216
213
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
217
214
|
}
|
|
218
|
-
const jsonData =
|
|
215
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
219
216
|
return check.call(jsonData);
|
|
220
217
|
});
|
|
221
218
|
}
|
|
@@ -225,7 +222,7 @@ class EmulatorTransport {
|
|
|
225
222
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
226
223
|
}
|
|
227
224
|
const messages = this._messages;
|
|
228
|
-
const outData =
|
|
225
|
+
const outData = ProtocolV1.encodeEnvelope(messages, name, data).toString('hex');
|
|
229
226
|
yield this._post({
|
|
230
227
|
url: `/post/${session}`,
|
|
231
228
|
body: outData,
|
|
@@ -244,7 +241,7 @@ class EmulatorTransport {
|
|
|
244
241
|
if (typeof resData !== 'string') {
|
|
245
242
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
246
243
|
}
|
|
247
|
-
const jsonData =
|
|
244
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
248
245
|
return check.call(jsonData);
|
|
249
246
|
});
|
|
250
247
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-emulator",
|
|
3
|
-
"version": "1.1.34-alpha.
|
|
3
|
+
"version": "1.1.34-alpha.3",
|
|
4
4
|
"description": "hardware emulator 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/http.ts
CHANGED
|
@@ -75,7 +75,6 @@ axios.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
|
|
75
75
|
// node environment
|
|
76
76
|
if (config.url?.startsWith('http://localhost:21333')) {
|
|
77
77
|
if (!config.headers.get('Origin')) {
|
|
78
|
-
console.log('set node request origin');
|
|
79
78
|
// add Origin field for request headers
|
|
80
79
|
config.headers.set('Origin', 'https://jssdk.onekey.so');
|
|
81
80
|
}
|
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 EmulatorTransport {
|
|
|
27
31
|
|
|
28
32
|
isOutdated = false;
|
|
29
33
|
|
|
34
|
+
// EmulatorTransport speaks Protocol V1 only.
|
|
35
|
+
getProtocolType(_path: string): ProtocolType {
|
|
36
|
+
return 'V1';
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
url: string;
|
|
31
40
|
|
|
32
41
|
Log?: any;
|
|
@@ -115,13 +124,9 @@ export default class EmulatorTransport {
|
|
|
115
124
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
116
125
|
}
|
|
117
126
|
const messages = this._messages;
|
|
118
|
-
|
|
119
|
-
this.Log.debug('call-', ' name: ', name);
|
|
120
|
-
} else {
|
|
121
|
-
this.Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
122
|
-
}
|
|
127
|
+
this.Log.debug('transport call', { name, protocol: 'V1' });
|
|
123
128
|
|
|
124
|
-
const o =
|
|
129
|
+
const o = ProtocolV1.encodeEnvelope(messages, name, data);
|
|
125
130
|
const outData = o.toString('hex');
|
|
126
131
|
const resData = await this._post({
|
|
127
132
|
url: `/call/${session}`,
|
|
@@ -131,7 +136,7 @@ export default class EmulatorTransport {
|
|
|
131
136
|
if (typeof resData !== 'string') {
|
|
132
137
|
throw ERRORS.TypedError(HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
133
138
|
}
|
|
134
|
-
const jsonData =
|
|
139
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
135
140
|
return check.call(jsonData);
|
|
136
141
|
}
|
|
137
142
|
|
|
@@ -140,7 +145,7 @@ export default class EmulatorTransport {
|
|
|
140
145
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
141
146
|
}
|
|
142
147
|
const messages = this._messages;
|
|
143
|
-
const outData =
|
|
148
|
+
const outData = ProtocolV1.encodeEnvelope(messages, name, data).toString('hex');
|
|
144
149
|
await this._post({
|
|
145
150
|
url: `/post/${session}`,
|
|
146
151
|
body: outData,
|
|
@@ -158,7 +163,7 @@ export default class EmulatorTransport {
|
|
|
158
163
|
if (typeof resData !== 'string') {
|
|
159
164
|
throw ERRORS.TypedError(HardwareErrorCode.NetworkError, 'Returning data is not string.');
|
|
160
165
|
}
|
|
161
|
-
const jsonData =
|
|
166
|
+
const jsonData = ProtocolV1.decodeMessage(messages, resData);
|
|
162
167
|
return check.call(jsonData);
|
|
163
168
|
}
|
|
164
169
|
|