@trezor/connect 9.0.11 → 9.1.1

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +19 -2
  3. package/lib/api/bitcoin/createPendingTx.d.ts +1 -0
  4. package/lib/api/bitcoin/createPendingTx.js +1 -0
  5. package/lib/api/cancelCoinjoinAuthorization.d.ts +7 -0
  6. package/lib/api/cancelCoinjoinAuthorization.js +25 -0
  7. package/lib/api/cardanoGetPublicKey.d.ts +1 -0
  8. package/lib/api/cardanoGetPublicKey.js +9 -0
  9. package/lib/api/cipherKeyValue.js +3 -2
  10. package/lib/api/getAccountInfo.d.ts +2 -0
  11. package/lib/api/getPublicKey.d.ts +1 -0
  12. package/lib/api/getPublicKey.js +9 -0
  13. package/lib/api/index.d.ts +2 -0
  14. package/lib/api/index.js +6 -2
  15. package/lib/api/rebootToBootloader.js +1 -1
  16. package/lib/api/showDeviceTutorial.d.ts +7 -0
  17. package/lib/api/showDeviceTutorial.js +21 -0
  18. package/lib/constants/errors.d.ts +0 -3
  19. package/lib/constants/errors.js +1 -4
  20. package/lib/core/index.d.ts +5 -6
  21. package/lib/core/index.js +44 -50
  22. package/lib/core/method.d.ts +1 -1
  23. package/lib/data/coinInfo.d.ts +0 -1
  24. package/lib/data/coinInfo.js +7 -14
  25. package/lib/data/config.js +7 -1
  26. package/lib/data/version.d.ts +1 -1
  27. package/lib/data/version.js +1 -1
  28. package/lib/device/Device.d.ts +8 -10
  29. package/lib/device/Device.js +60 -95
  30. package/lib/device/DeviceCommands.d.ts +4 -3
  31. package/lib/device/DeviceCommands.js +40 -18
  32. package/lib/device/DeviceList.d.ts +15 -25
  33. package/lib/device/DeviceList.js +224 -258
  34. package/lib/events/transport.d.ts +2 -9
  35. package/lib/events/transport.js +3 -10
  36. package/lib/factory.js +2 -0
  37. package/lib/index.js +7 -7
  38. package/lib/types/api/cancelCoinjoinAuthorization.d.ts +8 -0
  39. package/lib/types/api/cancelCoinjoinAuthorization.js +3 -0
  40. package/lib/types/api/index.d.ts +4 -0
  41. package/lib/types/api/showDeviceTutorial.d.ts +4 -0
  42. package/lib/types/api/showDeviceTutorial.js +3 -0
  43. package/lib/types/device.d.ts +1 -1
  44. package/lib/types/device.js +3 -0
  45. package/lib/types/settings.d.ts +1 -1
  46. package/lib/utils/debug.js +2 -1
  47. package/lib/utils/deviceFeaturesUtils.d.ts +2 -1
  48. package/lib/utils/deviceFeaturesUtils.js +12 -1
  49. package/lib/workers/workers-browser.d.ts +1 -3
  50. package/lib/workers/workers-browser.js +1 -7
  51. package/lib/workers/workers-react-native.d.ts +1 -3
  52. package/lib/workers/workers-react-native.js +1 -7
  53. package/lib/workers/workers.d.ts +1 -5
  54. package/lib/workers/workers.js +1 -5
  55. package/package.json +15 -12
  56. package/lib/device/DescriptorStream.d.ts +0 -28
  57. package/lib/device/DescriptorStream.js +0 -139
  58. package/lib/utils/objectUtils.d.ts +0 -10
  59. package/lib/utils/objectUtils.js +0 -37
  60. package/lib/workers/RNUsbPlugin.d.ts +0 -31
  61. package/lib/workers/RNUsbPlugin.js +0 -65
package/lib/index.js CHANGED
@@ -36,7 +36,7 @@ const handleMessage = (message) => {
36
36
  if (!_core)
37
37
  return;
38
38
  if (type === events_2.UI.REQUEST_UI_WINDOW) {
39
- _core.handleMessage({ event: events_2.UI_EVENT, type: events_2.POPUP.HANDSHAKE }, true);
39
+ _core.handleMessage({ event: events_2.UI_EVENT, type: events_2.POPUP.HANDSHAKE });
40
40
  return;
41
41
  }
42
42
  if (type === events_2.POPUP.CANCEL_POPUP_REQUEST)
@@ -84,10 +84,10 @@ function postMessage(message, usePromise = true) {
84
84
  _messageID++;
85
85
  exports.messagePromises[_messageID] = (0, utils_1.createDeferred)();
86
86
  const { promise } = exports.messagePromises[_messageID];
87
- _core.handleMessage({ ...message, id: _messageID }, true);
87
+ _core.handleMessage({ ...message, id: _messageID });
88
88
  return promise;
89
89
  }
90
- _core.handleMessage(message, true);
90
+ _core.handleMessage(message);
91
91
  }
92
92
  const init = async (settings = {}) => {
93
93
  var _a;
@@ -105,7 +105,7 @@ const init = async (settings = {}) => {
105
105
  _settings.lazyLoad = false;
106
106
  return;
107
107
  }
108
- _core = await (0, core_1.init)(_settings);
108
+ _core = await (0, core_1.initCore)(_settings);
109
109
  _core.on(events_2.CORE_EVENT, handleMessage);
110
110
  await (0, core_1.initTransport)(_settings);
111
111
  };
@@ -138,7 +138,7 @@ const uiResponse = (response) => {
138
138
  throw constants_1.ERRORS.TypedError('Init_NotInitialized');
139
139
  }
140
140
  const { type, payload } = response;
141
- _core.handleMessage({ event: events_2.UI_EVENT, type, payload }, true);
141
+ _core.handleMessage({ event: events_2.UI_EVENT, type, payload });
142
142
  };
143
143
  const requestLogin = async (params) => {
144
144
  if (typeof params.callback === 'function') {
@@ -152,14 +152,14 @@ const requestLogin = async (params) => {
152
152
  event: events_2.UI_EVENT,
153
153
  type: events_2.UI.LOGIN_CHALLENGE_RESPONSE,
154
154
  payload,
155
- }, true);
155
+ });
156
156
  }
157
157
  catch (error) {
158
158
  _core === null || _core === void 0 ? void 0 : _core.handleMessage({
159
159
  event: events_2.UI_EVENT,
160
160
  type: events_2.UI.LOGIN_CHALLENGE_RESPONSE,
161
161
  payload: error.message,
162
- }, true);
162
+ });
163
163
  }
164
164
  }
165
165
  };
@@ -0,0 +1,8 @@
1
+ import type { PROTO } from '../../constants';
2
+ import type { Params, Response } from '../params';
3
+ interface CancelCoinjoinAuthorization {
4
+ preauthorized?: boolean;
5
+ }
6
+ export declare function cancelCoinjoinAuthorization(params: Params<CancelCoinjoinAuthorization>): Response<PROTO.Success>;
7
+ export {};
8
+ //# sourceMappingURL=cancelCoinjoinAuthorization.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=cancelCoinjoinAuthorization.js.map
@@ -75,10 +75,14 @@ import { unlockPath } from './unlockPath';
75
75
  import { verifyMessage } from './verifyMessage';
76
76
  import { wipeDevice } from './wipeDevice';
77
77
  import { checkFirmwareAuthenticity } from './checkFirmwareAuthenticity';
78
+ import { cancelCoinjoinAuthorization } from './cancelCoinjoinAuthorization';
79
+ import { showDeviceTutorial } from './showDeviceTutorial';
78
80
  export interface TrezorConnect {
79
81
  applyFlags: typeof applyFlags;
80
82
  applySettings: typeof applySettings;
81
83
  authorizeCoinjoin: typeof authorizeCoinjoin;
84
+ cancelCoinjoinAuthorization: typeof cancelCoinjoinAuthorization;
85
+ showDeviceTutorial: typeof showDeviceTutorial;
82
86
  backupDevice: typeof backupDevice;
83
87
  binanceGetAddress: typeof binanceGetAddress;
84
88
  binanceGetPublicKey: typeof binanceGetPublicKey;
@@ -0,0 +1,4 @@
1
+ import type { PROTO } from '../../constants';
2
+ import type { CommonParams, Response } from '../params';
3
+ export declare function showDeviceTutorial(params: CommonParams): Response<PROTO.Success>;
4
+ //# sourceMappingURL=showDeviceTutorial.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=showDeviceTutorial.js.map
@@ -55,6 +55,7 @@ export type UnreadableDevice = {
55
55
  };
56
56
  export type Device = KnownDevice | UnknownDevice | UnreadableDevice;
57
57
  export type Features = PROTO.Features;
58
+ export { DeviceModelInternal } from '@trezor/transport/lib/types/messages';
58
59
  type FeaturesNarrowing = {
59
60
  major_version: 2;
60
61
  fw_major: null;
@@ -92,5 +93,4 @@ type FeaturesNarrowing = {
92
93
  firmware_present: true;
93
94
  };
94
95
  export type StrictFeatures = Features & FeaturesNarrowing;
95
- export {};
96
96
  //# sourceMappingURL=device.d.ts.map
@@ -1,3 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceModelInternal = void 0;
4
+ var messages_1 = require("@trezor/transport/lib/types/messages");
5
+ Object.defineProperty(exports, "DeviceModelInternal", { enumerable: true, get: function () { return messages_1.DeviceModelInternal; } });
3
6
  //# sourceMappingURL=device.js.map
@@ -15,7 +15,7 @@ export interface ConnectSettings {
15
15
  popup?: boolean;
16
16
  transportReconnect?: boolean;
17
17
  webusb?: boolean;
18
- transports?: Transport['name'][];
18
+ transports?: (Transport['name'] | Transport)[];
19
19
  pendingTransportEvent?: boolean;
20
20
  lazyLoad?: boolean;
21
21
  interactionTimeout?: number;
@@ -9,6 +9,7 @@ const colors = {
9
9
  DeviceList: 'color: #77ab59; background: #000;',
10
10
  Device: 'color: #bada55; background: #000;',
11
11
  DeviceCommands: 'color: #bada55; background: #000;',
12
+ '@trezor/transport': 'color: #bada55; background: #000;',
12
13
  };
13
14
  const MAX_ENTRIES = 100;
14
15
  class Log {
@@ -23,7 +24,7 @@ class Log {
23
24
  level,
24
25
  prefix,
25
26
  message: args,
26
- timestamp: new Date().getTime(),
27
+ timestamp: Date.now(),
27
28
  });
28
29
  if (this.messages.length > MAX_ENTRIES) {
29
30
  this.messages.shift();
@@ -1,6 +1,7 @@
1
1
  import { PROTO } from '../constants';
2
- import type { Features, CoinInfo, UnavailableCapabilities } from '../types';
2
+ import { Features, CoinInfo, UnavailableCapabilities, DeviceModelInternal } from '../types';
3
3
  export declare const parseCapabilities: (features?: Features) => PROTO.Capability[];
4
4
  export declare const getUnavailableCapabilities: (features: Features, coins: CoinInfo[]) => UnavailableCapabilities;
5
5
  export declare const parseRevision: (features: Features) => string | null;
6
+ export declare const ensureInternalModelFeature: (model: Features['model']) => DeviceModelInternal;
6
7
  //# sourceMappingURL=deviceFeaturesUtils.d.ts.map
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRevision = exports.getUnavailableCapabilities = exports.parseCapabilities = void 0;
3
+ exports.ensureInternalModelFeature = exports.parseRevision = exports.getUnavailableCapabilities = exports.parseCapabilities = void 0;
4
4
  const versionUtils_1 = require("./versionUtils");
5
5
  const config_1 = require("../data/config");
6
+ const types_1 = require("../types");
6
7
  const DEFAULT_CAPABILITIES_T1 = [
7
8
  'Capability_Bitcoin',
8
9
  'Capability_Bitcoin_like',
@@ -112,4 +113,14 @@ const parseRevision = (features) => {
112
113
  return /^([a-f0-9])*$/gi.test(revisionUtf8) ? revisionUtf8 : revision;
113
114
  };
114
115
  exports.parseRevision = parseRevision;
116
+ const ensureInternalModelFeature = (model) => {
117
+ switch (model.toUpperCase()) {
118
+ case 'T':
119
+ return types_1.DeviceModelInternal.T2T1;
120
+ case '1':
121
+ default:
122
+ return types_1.DeviceModelInternal.T1B1;
123
+ }
124
+ };
125
+ exports.ensureInternalModelFeature = ensureInternalModelFeature;
115
126
  //# sourceMappingURL=deviceFeaturesUtils.js.map
@@ -1,8 +1,6 @@
1
1
  import BlockbookWorker from '@trezor/blockchain-link/lib/workers/blockbook';
2
2
  import RippleWorker from '@trezor/blockchain-link/lib/workers/ripple';
3
3
  import BlockfrostWorker from '@trezor/blockchain-link/lib/workers/blockfrost';
4
- declare const WebUsbPlugin: () => import("packages/transport/lib/lowlevel/withSharedConnections").default;
5
- declare const ReactNativeUsbPlugin: undefined;
6
4
  declare const ElectrumWorker: undefined;
7
- export { WebUsbPlugin, ReactNativeUsbPlugin, BlockbookWorker, RippleWorker, BlockfrostWorker, ElectrumWorker, };
5
+ export { BlockbookWorker, RippleWorker, BlockfrostWorker, ElectrumWorker };
8
6
  //# sourceMappingURL=workers-browser.d.ts.map
@@ -1,19 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElectrumWorker = exports.BlockfrostWorker = exports.RippleWorker = exports.BlockbookWorker = exports.ReactNativeUsbPlugin = exports.WebUsbPlugin = void 0;
3
+ exports.ElectrumWorker = exports.BlockfrostWorker = exports.RippleWorker = exports.BlockbookWorker = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const sharedConnectionWorker_1 = tslib_1.__importDefault(require("@trezor/transport/lib/lowlevel/sharedConnectionWorker"));
6
5
  const blockbook_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/blockbook"));
7
6
  exports.BlockbookWorker = blockbook_1.default;
8
7
  const ripple_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/ripple"));
9
8
  exports.RippleWorker = ripple_1.default;
10
9
  const blockfrost_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/blockfrost"));
11
10
  exports.BlockfrostWorker = blockfrost_1.default;
12
- const transport_1 = tslib_1.__importDefault(require("@trezor/transport"));
13
- const WebUsbPlugin = () => new transport_1.default.Lowlevel(new transport_1.default.WebUsb(), typeof SharedWorker !== 'undefined' ? () => new sharedConnectionWorker_1.default() : null);
14
- exports.WebUsbPlugin = WebUsbPlugin;
15
- const ReactNativeUsbPlugin = undefined;
16
- exports.ReactNativeUsbPlugin = ReactNativeUsbPlugin;
17
11
  const ElectrumWorker = undefined;
18
12
  exports.ElectrumWorker = ElectrumWorker;
19
13
  //# sourceMappingURL=workers-browser.js.map
@@ -1,8 +1,6 @@
1
1
  import BlockbookWorker from '@trezor/blockchain-link/lib/workers/blockbook';
2
2
  import RippleWorker from '@trezor/blockchain-link/lib/workers/ripple';
3
3
  import BlockfrostWorker from '@trezor/blockchain-link/lib/workers/blockfrost';
4
- declare const WebUsbPlugin: undefined;
5
4
  declare const ElectrumWorker: undefined;
6
- declare const ReactNativeUsbPlugin: () => import("packages/transport/lib/lowlevel/withSharedConnections").default;
7
- export { WebUsbPlugin, ReactNativeUsbPlugin, BlockbookWorker, RippleWorker, BlockfrostWorker, ElectrumWorker, };
5
+ export { BlockbookWorker, RippleWorker, BlockfrostWorker, ElectrumWorker };
8
6
  //# sourceMappingURL=workers-react-native.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElectrumWorker = exports.BlockfrostWorker = exports.RippleWorker = exports.BlockbookWorker = exports.ReactNativeUsbPlugin = exports.WebUsbPlugin = void 0;
3
+ exports.ElectrumWorker = exports.BlockfrostWorker = exports.RippleWorker = exports.BlockbookWorker = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const blockbook_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/blockbook"));
6
6
  exports.BlockbookWorker = blockbook_1.default;
@@ -8,12 +8,6 @@ const ripple_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/wo
8
8
  exports.RippleWorker = ripple_1.default;
9
9
  const blockfrost_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/blockfrost"));
10
10
  exports.BlockfrostWorker = blockfrost_1.default;
11
- const transport_1 = tslib_1.__importDefault(require("@trezor/transport"));
12
- const RNUsbPlugin_1 = require("./RNUsbPlugin");
13
- const WebUsbPlugin = undefined;
14
- exports.WebUsbPlugin = WebUsbPlugin;
15
11
  const ElectrumWorker = undefined;
16
12
  exports.ElectrumWorker = ElectrumWorker;
17
- const ReactNativeUsbPlugin = () => new transport_1.default.Lowlevel(new RNUsbPlugin_1.ReactNativePlugin(), undefined);
18
- exports.ReactNativeUsbPlugin = ReactNativeUsbPlugin;
19
13
  //# sourceMappingURL=workers-react-native.js.map
@@ -2,9 +2,5 @@ import BlockbookWorker from '@trezor/blockchain-link/lib/workers/blockbook';
2
2
  import RippleWorker from '@trezor/blockchain-link/lib/workers/ripple';
3
3
  import BlockfrostWorker from '@trezor/blockchain-link/lib/workers/blockfrost';
4
4
  import ElectrumWorker from '@trezor/blockchain-link/lib/workers/electrum';
5
- import type { Transport } from '@trezor/transport';
6
- type TransportWrapper = () => Transport;
7
- declare const WebUsbPlugin: TransportWrapper | typeof undefined;
8
- declare const ReactNativeUsbPlugin: TransportWrapper | typeof undefined;
9
- export { WebUsbPlugin, ReactNativeUsbPlugin, BlockbookWorker, RippleWorker, BlockfrostWorker, ElectrumWorker, };
5
+ export { BlockbookWorker, RippleWorker, BlockfrostWorker, ElectrumWorker };
10
6
  //# sourceMappingURL=workers.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElectrumWorker = exports.BlockfrostWorker = exports.RippleWorker = exports.BlockbookWorker = exports.ReactNativeUsbPlugin = exports.WebUsbPlugin = void 0;
3
+ exports.ElectrumWorker = exports.BlockfrostWorker = exports.RippleWorker = exports.BlockbookWorker = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const blockbook_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/blockbook"));
6
6
  exports.BlockbookWorker = blockbook_1.default;
@@ -10,8 +10,4 @@ const blockfrost_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/li
10
10
  exports.BlockfrostWorker = blockfrost_1.default;
11
11
  const electrum_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/electrum"));
12
12
  exports.ElectrumWorker = electrum_1.default;
13
- const WebUsbPlugin = undefined;
14
- exports.WebUsbPlugin = WebUsbPlugin;
15
- const ReactNativeUsbPlugin = undefined;
16
- exports.ReactNativeUsbPlugin = ReactNativeUsbPlugin;
17
13
  //# sourceMappingURL=workers.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trezor/connect",
3
- "version": "9.0.11",
3
+ "version": "9.1.1",
4
4
  "author": "Trezor <info@trezor.io>",
5
5
  "homepage": "https://github.com/trezor/trezor-suite/tree/develop/packages/connect",
6
6
  "description": "High-level javascript interface for Trezor hardware wallet.",
@@ -49,22 +49,24 @@
49
49
  "prepublish": "yarn tsx ../../scripts/prepublish.js"
50
50
  },
51
51
  "dependencies": {
52
- "@trezor/blockchain-link": "2.1.13",
53
- "@trezor/connect-analytics": "1.0.2",
54
- "@trezor/connect-common": "0.0.16",
55
- "@trezor/transport": "1.1.12",
56
- "@trezor/utils": "9.0.9",
57
- "@trezor/utxo-lib": "1.0.7",
52
+ "@trezor/blockchain-link": "2.1.15",
53
+ "@trezor/blockchain-link-types": "1.0.4",
54
+ "@trezor/connect-analytics": "1.0.4",
55
+ "@trezor/connect-common": "0.0.18",
56
+ "@trezor/transport": "1.1.14",
57
+ "@trezor/utils": "9.0.11",
58
+ "@trezor/utxo-lib": "1.0.9",
58
59
  "bignumber.js": "^9.1.1",
59
60
  "blakejs": "^1.2.1",
61
+ "bs58": "^5.0.0",
62
+ "bs58check": "^3.0.1",
60
63
  "cross-fetch": "^3.1.6",
61
64
  "events": "^3.3.0",
62
- "randombytes": "2.1.0",
63
- "tslib": "2.5.2"
65
+ "randombytes": "2.1.0"
64
66
  },
65
67
  "devDependencies": {
66
68
  "@trezor/trezor-user-env-link": "1.0.2",
67
- "@types/karma": "^6.3.3",
69
+ "@types/karma": "^6.3.4",
68
70
  "@types/parse-uri": "^1.0.0",
69
71
  "@types/randombytes": "^2.0.0",
70
72
  "jest": "^29.5.0",
@@ -77,9 +79,10 @@
77
79
  "karma-sourcemap-loader": "^0.4.0",
78
80
  "karma-webpack": "^5.0.0",
79
81
  "rimraf": "^5.0.1",
80
- "ts-loader": "^9.4.2",
81
82
  "ts-node": "^10.9.1",
82
83
  "tsx": "^3.12.7",
83
- "typescript": "4.9.5"
84
+ "typescript": "4.9.5",
85
+ "webpack": "^5.87.0",
86
+ "ws": "7.5.9"
84
87
  }
85
88
  }
@@ -1,28 +0,0 @@
1
- /// <reference types="node" />
2
- import EventEmitter from 'events';
3
- import type { Transport, TrezorDeviceInfoWithSession as DeviceDescriptor } from '@trezor/transport';
4
- export type DeviceDescriptorDiff = {
5
- didUpdate: boolean;
6
- connected: DeviceDescriptor[];
7
- disconnected: DeviceDescriptor[];
8
- changedSessions: DeviceDescriptor[];
9
- changedDebugSessions: DeviceDescriptor[];
10
- acquired: DeviceDescriptor[];
11
- debugAcquired: DeviceDescriptor[];
12
- released: DeviceDescriptor[];
13
- debugReleased: DeviceDescriptor[];
14
- descriptors: DeviceDescriptor[];
15
- };
16
- export declare class DescriptorStream extends EventEmitter {
17
- transport: Transport;
18
- listening: boolean;
19
- listenTimestamp: number;
20
- current: DeviceDescriptor[] | null;
21
- upcoming: DeviceDescriptor[];
22
- constructor(transport: Transport);
23
- listen(): Promise<void>;
24
- enumerate(): Promise<void>;
25
- stop(): void;
26
- _reportChanges(): void;
27
- }
28
- //# sourceMappingURL=DescriptorStream.d.ts.map
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DescriptorStream = void 0;
4
- const tslib_1 = require("tslib");
5
- const events_1 = tslib_1.__importDefault(require("events"));
6
- const transport_1 = require("../events/transport");
7
- const device_1 = require("../events/device");
8
- const debug_1 = require("../utils/debug");
9
- const DataManager_1 = require("../data/DataManager");
10
- const promiseUtils_1 = require("../utils/promiseUtils");
11
- const logger = (0, debug_1.initLog)('DescriptorStream');
12
- const getDiff = (current, descriptors) => {
13
- const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
14
- const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
15
- const changedSessions = descriptors.filter(d => {
16
- const currentDescriptor = current.find(x => x.path === d.path);
17
- if (currentDescriptor) {
18
- return currentDescriptor.session !== d.session;
19
- }
20
- return false;
21
- });
22
- const acquired = changedSessions.filter(d => typeof d.session === 'string');
23
- const released = changedSessions.filter(d => typeof d.session !== 'string');
24
- const changedDebugSessions = descriptors.filter(d => {
25
- const currentDescriptor = current.find(x => x.path === d.path);
26
- if (currentDescriptor) {
27
- return currentDescriptor.debugSession !== d.debugSession;
28
- }
29
- return false;
30
- });
31
- const debugAcquired = changedSessions.filter(d => typeof d.debugSession === 'string');
32
- const debugReleased = changedSessions.filter(d => typeof d.debugSession !== 'string');
33
- const didUpdate = connected.length +
34
- disconnected.length +
35
- changedSessions.length +
36
- changedDebugSessions.length >
37
- 0;
38
- return {
39
- connected,
40
- disconnected,
41
- changedSessions,
42
- acquired,
43
- released,
44
- changedDebugSessions,
45
- debugAcquired,
46
- debugReleased,
47
- didUpdate,
48
- descriptors,
49
- };
50
- };
51
- class DescriptorStream extends events_1.default {
52
- constructor(transport) {
53
- super();
54
- this.listening = false;
55
- this.listenTimestamp = 0;
56
- this.current = null;
57
- this.upcoming = [];
58
- this.transport = transport;
59
- }
60
- async listen() {
61
- const waitForEvent = this.current !== null;
62
- const current = this.current || [];
63
- this.listening = true;
64
- let descriptors;
65
- try {
66
- logger.debug('Start listening', current);
67
- this.listenTimestamp = new Date().getTime();
68
- descriptors = waitForEvent
69
- ? await this.transport.listen(current)
70
- : await this.transport.enumerate();
71
- if (this.listening && !waitForEvent) {
72
- if (descriptors.length > 0 && DataManager_1.DataManager.getSettings('pendingTransportEvent')) {
73
- this.emit(transport_1.TRANSPORT.START_PENDING, descriptors.length);
74
- }
75
- else {
76
- this.emit(transport_1.TRANSPORT.START);
77
- }
78
- }
79
- if (!this.listening)
80
- return;
81
- this.upcoming = descriptors;
82
- logger.debug('Listen result', descriptors);
83
- this._reportChanges();
84
- if (this.listening)
85
- this.listen();
86
- }
87
- catch (error) {
88
- const time = new Date().getTime() - this.listenTimestamp;
89
- logger.debug('Listen error', 'timestamp', time, typeof error);
90
- if (time > 1100) {
91
- await (0, promiseUtils_1.resolveAfter)(1000, null).promise;
92
- if (this.listening)
93
- this.listen();
94
- }
95
- else {
96
- logger.warn('Transport error');
97
- this.emit(transport_1.TRANSPORT.ERROR, error);
98
- }
99
- }
100
- }
101
- async enumerate() {
102
- if (!this.listening)
103
- return;
104
- try {
105
- this.upcoming = await this.transport.enumerate();
106
- this._reportChanges();
107
- }
108
- catch (error) {
109
- }
110
- }
111
- stop() {
112
- this.listening = false;
113
- this.removeAllListeners();
114
- }
115
- _reportChanges() {
116
- const diff = getDiff(this.current || [], this.upcoming);
117
- this.current = this.upcoming;
118
- if (diff.didUpdate && this.listening) {
119
- diff.connected.forEach(d => {
120
- this.emit(device_1.DEVICE.CONNECT, d);
121
- });
122
- diff.disconnected.forEach(d => {
123
- this.emit(device_1.DEVICE.DISCONNECT, d);
124
- });
125
- diff.acquired.forEach(d => {
126
- this.emit(device_1.DEVICE.ACQUIRED, d);
127
- });
128
- diff.released.forEach(d => {
129
- this.emit(device_1.DEVICE.RELEASED, d);
130
- });
131
- diff.changedSessions.forEach(d => {
132
- this.emit(device_1.DEVICE.CHANGED, d);
133
- });
134
- this.emit(transport_1.TRANSPORT.UPDATE, diff);
135
- }
136
- }
137
- }
138
- exports.DescriptorStream = DescriptorStream;
139
- //# sourceMappingURL=DescriptorStream.js.map
@@ -1,10 +0,0 @@
1
- export declare function clone<T>(obj: T): T;
2
- export declare function entries<T>(obj: {
3
- [key: string]: T;
4
- }): Array<[string, T]>;
5
- export declare function deepClone(_obj: any, _hash?: any): void;
6
- export declare function snapshot(obj: any): any;
7
- export declare function objectValues<X>(object: {
8
- [key: string]: X;
9
- }): X[];
10
- //# sourceMappingURL=objectUtils.d.ts.map
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.objectValues = exports.snapshot = exports.deepClone = exports.entries = exports.clone = void 0;
4
- function clone(obj) {
5
- const jsonString = JSON.stringify(obj);
6
- if (jsonString === undefined) {
7
- return obj;
8
- }
9
- return JSON.parse(jsonString);
10
- }
11
- exports.clone = clone;
12
- function entries(obj) {
13
- const keys = Object.keys(obj);
14
- return keys.map(key => [key, obj[key]]);
15
- }
16
- exports.entries = entries;
17
- function deepClone(_obj, _hash = new WeakMap()) {
18
- }
19
- exports.deepClone = deepClone;
20
- function snapshot(obj) {
21
- if (obj == null || typeof obj !== 'object') {
22
- return obj;
23
- }
24
- const temp = new obj.constructor();
25
- Object.keys(temp).forEach(key => {
26
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
27
- temp[key] = snapshot(obj[key]);
28
- }
29
- });
30
- return temp;
31
- }
32
- exports.snapshot = snapshot;
33
- function objectValues(object) {
34
- return Object.keys(object).map(key => object[key]);
35
- }
36
- exports.objectValues = objectValues;
37
- //# sourceMappingURL=objectUtils.js.map
@@ -1,31 +0,0 @@
1
- type TrezorDeviceInfoDebug = {
2
- path: string;
3
- debug: boolean;
4
- };
5
- interface TrezorTransport {
6
- enumerate(): Promise<TrezorDeviceInfoDebug[]>;
7
- acquire(path: string, debugLink: boolean): Promise<void>;
8
- release(path: string, debugLink: boolean, closePort: boolean): Promise<void>;
9
- write(path: string, debugLink: boolean, data: string): Promise<void>;
10
- read(path: string, debugLink: boolean): Promise<{
11
- data: string;
12
- }>;
13
- }
14
- export declare class ReactNativePlugin {
15
- name: string;
16
- version: string;
17
- debug: boolean;
18
- allowsWriteAndEnumerate: boolean;
19
- requestNeeded: boolean;
20
- usb: TrezorTransport;
21
- constructor();
22
- init(debug?: boolean): Promise<void>;
23
- enumerate(): Promise<TrezorDeviceInfoDebug[]>;
24
- send(path: string, data: ArrayBuffer, debugLink: boolean): Promise<void>;
25
- receive(path: string, debugLink: boolean): Promise<ArrayBuffer>;
26
- connect(path: string, debugLink: boolean): Promise<void>;
27
- disconnect(path: string, debugLink: boolean, last: boolean): Promise<void>;
28
- requestDevice(): any;
29
- }
30
- export {};
31
- //# sourceMappingURL=RNUsbPlugin.d.ts.map
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReactNativePlugin = void 0;
4
- const react_native_1 = require("react-native");
5
- const bufferToHex = (buffer) => Array.prototype.map.call(new Uint8Array(buffer), x => `00${x.toString(16)}`.slice(-2)).join('');
6
- const toArrayBuffer = (buffer) => {
7
- const ab = new ArrayBuffer(buffer.length);
8
- const view = new Uint8Array(ab);
9
- const len = buffer.length;
10
- for (let i = 0; i < len; ++i) {
11
- view[i] = buffer[i];
12
- }
13
- return ab;
14
- };
15
- class ReactNativePlugin {
16
- constructor() {
17
- this.name = 'ReactNativePlugin';
18
- this.version = '1.0.0';
19
- this.debug = false;
20
- this.allowsWriteAndEnumerate = true;
21
- this.requestNeeded = false;
22
- this.usb = react_native_1.NativeModules.TrezorTransport;
23
- }
24
- init(debug) {
25
- this.debug = !!debug;
26
- if (!this.usb) {
27
- throw new Error('ReactNative plugin is not available');
28
- }
29
- return Promise.resolve();
30
- }
31
- enumerate() {
32
- return this.usb.enumerate();
33
- }
34
- send(path, data, debugLink) {
35
- const dataHex = bufferToHex(data);
36
- return this.usb.write(path, debugLink, dataHex);
37
- }
38
- async receive(path, debugLink) {
39
- const { data } = await this.usb.read(path, debugLink);
40
- return toArrayBuffer(Buffer.from(data, 'hex'));
41
- }
42
- async connect(path, debugLink) {
43
- for (let i = 0; i < 5; i++) {
44
- if (i > 0) {
45
- await new Promise(resolve => setTimeout(resolve, i * 200));
46
- }
47
- try {
48
- await this.usb.acquire(path, debugLink);
49
- return;
50
- }
51
- catch (e) {
52
- if (i === 4) {
53
- throw e;
54
- }
55
- }
56
- }
57
- }
58
- disconnect(path, debugLink, last) {
59
- return this.usb.release(path, debugLink, last);
60
- }
61
- requestDevice() {
62
- }
63
- }
64
- exports.ReactNativePlugin = ReactNativePlugin;
65
- //# sourceMappingURL=RNUsbPlugin.js.map