@onekeyfe/hd-transport-emulator 1.0.33-alpha.10 → 1.0.37-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/README.md +68 -23
- package/dist/constants.d.ts +1 -1
- package/dist/index.js +4 -4
- package/package.json +4 -4
- package/src/constants.ts +1 -1
- package/src/http.ts +2 -2
- package/src/index.ts +1 -1
- package/tsconfig.json +2 -2
package/README.md
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OneKey Hardware Emulator Transport
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Description
|
|
6
|
-
|
|
7
|
-
This package provides a transport layer for communicating with OneKey hardware emulators running on localhost:21321.
|
|
3
|
+
This package provides HTTP-based transport for connecting to OneKey hardware emulator.
|
|
8
4
|
|
|
9
5
|
## Features
|
|
10
6
|
|
|
11
|
-
-
|
|
12
|
-
- Compatible with OneKey
|
|
13
|
-
-
|
|
14
|
-
-
|
|
7
|
+
- HTTP-based communication with emulator server
|
|
8
|
+
- Compatible with OneKey Connect SDK
|
|
9
|
+
- Support for switchTransport functionality
|
|
10
|
+
- Default emulator server URL: `http://localhost:21333`
|
|
15
11
|
|
|
16
12
|
## Installation
|
|
17
13
|
|
|
@@ -21,28 +17,77 @@ npm install @onekeyfe/hd-transport-emulator
|
|
|
21
17
|
|
|
22
18
|
## Usage
|
|
23
19
|
|
|
20
|
+
### Basic Usage
|
|
21
|
+
|
|
24
22
|
```javascript
|
|
25
23
|
import EmulatorTransport from '@onekeyfe/hd-transport-emulator';
|
|
26
24
|
|
|
27
|
-
// Create transport instance
|
|
25
|
+
// Create transport instance
|
|
28
26
|
const transport = new EmulatorTransport();
|
|
27
|
+
// or with custom URL
|
|
28
|
+
const transport = new EmulatorTransport('http://localhost:21333');
|
|
29
|
+
|
|
30
|
+
// Initialize transport
|
|
31
|
+
await transport.init(logger);
|
|
32
|
+
|
|
33
|
+
// Configure with protobuf messages
|
|
34
|
+
await transport.configure(signedData);
|
|
35
|
+
```
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
### With OneKey Connect SDK
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
import HardwareSDK from '@onekeyfe/hd-web-sdk';
|
|
41
|
+
|
|
42
|
+
// Initialize with emulator environment
|
|
43
|
+
await HardwareSDK.init({
|
|
44
|
+
env: 'emulator',
|
|
45
|
+
debug: true
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Switch to emulator transport
|
|
49
|
+
await HardwareSDK.switchTransport('emulator');
|
|
32
50
|
```
|
|
33
51
|
|
|
34
|
-
|
|
52
|
+
### In Connect Examples
|
|
35
53
|
|
|
36
|
-
The transport
|
|
37
|
-
- Port: 21321
|
|
38
|
-
- Protocol: HTTP
|
|
39
|
-
- Host: localhost
|
|
54
|
+
The emulator transport is integrated into the connect examples:
|
|
40
55
|
|
|
41
|
-
|
|
56
|
+
1. **Expo Example**: Select "Emulator" from the transport picker
|
|
57
|
+
2. **Electron Example**: Use switchTransport API to switch to emulator
|
|
42
58
|
|
|
43
|
-
|
|
44
|
-
- Node.js environment or modern browser with CORS support
|
|
59
|
+
## API
|
|
45
60
|
|
|
46
|
-
|
|
61
|
+
### Constructor
|
|
47
62
|
|
|
48
|
-
|
|
63
|
+
```javascript
|
|
64
|
+
new EmulatorTransport(url?: string)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- `url` (optional): Emulator server URL, defaults to `http://localhost:21333`
|
|
68
|
+
|
|
69
|
+
### Methods
|
|
70
|
+
|
|
71
|
+
All methods implement the standard OneKey Transport interface:
|
|
72
|
+
|
|
73
|
+
- `init(logger)`: Initialize transport
|
|
74
|
+
- `configure(signedData)`: Configure protobuf messages
|
|
75
|
+
- `enumerate()`: List available devices
|
|
76
|
+
- `acquire(input)`: Acquire device session
|
|
77
|
+
- `release(session, onclose)`: Release device session
|
|
78
|
+
- `call(session, name, data)`: Call device method
|
|
79
|
+
- `stop()`: Stop transport
|
|
80
|
+
|
|
81
|
+
## Emulator Server
|
|
82
|
+
|
|
83
|
+
Make sure your OneKey emulator server is running on the configured URL (default: `http://localhost:21333`) before using this transport.
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Build
|
|
89
|
+
npm run build
|
|
90
|
+
|
|
91
|
+
# Development mode
|
|
92
|
+
npm run dev
|
|
93
|
+
```
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DEFAULT_URL = "http://localhost:
|
|
1
|
+
export declare const DEFAULT_URL = "http://localhost:21333";
|
|
2
2
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -100,16 +100,16 @@ axios__default["default"].interceptors.request.use(config => {
|
|
|
100
100
|
if (typeof window !== 'undefined') {
|
|
101
101
|
return config;
|
|
102
102
|
}
|
|
103
|
-
if ((_a = config.url) === null || _a === void 0 ? void 0 : _a.startsWith('http://localhost:
|
|
103
|
+
if ((_a = config.url) === null || _a === void 0 ? void 0 : _a.startsWith('http://localhost:21333')) {
|
|
104
104
|
if (!((_b = config === null || config === void 0 ? void 0 : config.headers) === null || _b === void 0 ? void 0 : _b.Origin)) {
|
|
105
|
-
console.log('set node request origin
|
|
105
|
+
console.log('set node request origin');
|
|
106
106
|
config.headers = Object.assign(Object.assign({}, config.headers), { Origin: 'https://jssdk.onekey.so' });
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
return config;
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
const DEFAULT_URL = 'http://localhost:
|
|
112
|
+
const DEFAULT_URL = 'http://localhost:21333';
|
|
113
113
|
|
|
114
114
|
const { check, buildOne, receiveOne, parseConfigure } = transport__default["default"];
|
|
115
115
|
class EmulatorTransport {
|
|
@@ -153,7 +153,7 @@ class EmulatorTransport {
|
|
|
153
153
|
listen(old) {
|
|
154
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
155
|
if (old === null) {
|
|
156
|
-
throw hdShared.ERRORS.TypedError('
|
|
156
|
+
throw hdShared.ERRORS.TypedError('Http-Transport does not support listen without previous.');
|
|
157
157
|
}
|
|
158
158
|
const devicesS = yield this._post({
|
|
159
159
|
url: '/listen',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-emulator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37-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.0.
|
|
28
|
-
"@onekeyfe/hd-transport": "^1.0.
|
|
27
|
+
"@onekeyfe/hd-shared": "^1.0.37-alpha.3",
|
|
28
|
+
"@onekeyfe/hd-transport": "^1.0.37-alpha.3",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"secure-json-parse": "^4.0.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "350e6072e38266ae3896a87187294a1302123ff7"
|
|
33
33
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DEFAULT_URL = 'http://localhost:
|
|
1
|
+
export const DEFAULT_URL = 'http://localhost:21333';
|
package/src/http.ts
CHANGED
|
@@ -71,9 +71,9 @@ axios.interceptors.request.use(config => {
|
|
|
71
71
|
return config;
|
|
72
72
|
}
|
|
73
73
|
// node environment
|
|
74
|
-
if (config.url?.startsWith('http://localhost:
|
|
74
|
+
if (config.url?.startsWith('http://localhost:21333')) {
|
|
75
75
|
if (!config?.headers?.Origin) {
|
|
76
|
-
console.log('set node request origin
|
|
76
|
+
console.log('set node request origin');
|
|
77
77
|
// add Origin field for request headers
|
|
78
78
|
config.headers = {
|
|
79
79
|
...config.headers,
|
package/src/index.ts
CHANGED
|
@@ -68,7 +68,7 @@ export default class EmulatorTransport {
|
|
|
68
68
|
|
|
69
69
|
async listen(old?: Array<OneKeyDeviceInfoWithSession>) {
|
|
70
70
|
if (old === null) {
|
|
71
|
-
throw ERRORS.TypedError('
|
|
71
|
+
throw ERRORS.TypedError('Http-Transport does not support listen without previous.');
|
|
72
72
|
}
|
|
73
73
|
const devicesS = await this._post({
|
|
74
74
|
url: '/listen',
|