@trezor/connect 9.0.2 → 9.0.4

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 (84) hide show
  1. package/README.md +5 -5
  2. package/lib/api/authorizeCoinJoin.js +6 -2
  3. package/lib/api/bitcoin/TransactionComposer.js +2 -1
  4. package/lib/api/bitcoin/enhanceSignTx.js +1 -1
  5. package/lib/api/bitcoin/inputs.js +3 -2
  6. package/lib/api/bitcoin/outputs.js +2 -4
  7. package/lib/api/bitcoin/refTx.js +3 -3
  8. package/lib/api/bitcoin/signtxVerify.d.ts +3 -3
  9. package/lib/api/bitcoin/signtxVerify.js +16 -15
  10. package/lib/api/blockchainDisconnect.js +1 -1
  11. package/lib/api/blockchainSetCustomBackend.js +1 -1
  12. package/lib/api/cardano/cardanoAuxiliaryData.d.ts +1 -1
  13. package/lib/api/cardano/cardanoAuxiliaryData.js +38 -16
  14. package/lib/api/cardanoSignTransaction.d.ts +1 -0
  15. package/lib/api/cardanoSignTransaction.js +23 -3
  16. package/lib/api/getAddress.d.ts +2 -1
  17. package/lib/api/getAddress.js +12 -1
  18. package/lib/api/getOwnershipProof.d.ts +1 -5
  19. package/lib/api/getOwnershipProof.js +5 -3
  20. package/lib/api/getPublicKey.d.ts +1 -0
  21. package/lib/api/getPublicKey.js +22 -7
  22. package/lib/api/index.d.ts +2 -0
  23. package/lib/api/index.js +5 -1
  24. package/lib/api/setBusy.d.ts +7 -0
  25. package/lib/api/setBusy.js +27 -0
  26. package/lib/api/signTransaction.d.ts +2 -1
  27. package/lib/api/signTransaction.js +24 -5
  28. package/lib/api/unlockPath.d.ts +10 -0
  29. package/lib/api/unlockPath.js +35 -0
  30. package/lib/backend/BackendManager.d.ts +21 -0
  31. package/lib/backend/BackendManager.js +91 -0
  32. package/lib/backend/Blockchain.d.ts +72 -0
  33. package/lib/backend/Blockchain.js +204 -0
  34. package/lib/backend/BlockchainLink.d.ts +6 -71
  35. package/lib/backend/BlockchainLink.js +12 -288
  36. package/lib/constants/cardano.d.ts +3 -1
  37. package/lib/constants/cardano.js +3 -1
  38. package/lib/core/AbstractMethod.d.ts +1 -0
  39. package/lib/core/index.d.ts +1 -1
  40. package/lib/core/index.js +1 -1
  41. package/lib/core/method.d.ts +1 -1
  42. package/lib/data/config.js +2 -2
  43. package/lib/data/version.d.ts +1 -1
  44. package/lib/data/version.js +1 -1
  45. package/lib/device/Device.d.ts +1 -1
  46. package/lib/device/Device.js +8 -2
  47. package/lib/device/DeviceCommands.d.ts +8 -2
  48. package/lib/device/DeviceCommands.js +48 -25
  49. package/lib/factory.js +2 -0
  50. package/lib/types/api/authorizeCoinJoin.d.ts +1 -0
  51. package/lib/types/api/bitcoin/index.d.ts +5 -0
  52. package/lib/types/api/cardano/index.d.ts +13 -10
  53. package/lib/types/api/eos/index.d.ts +0 -4
  54. package/lib/types/api/eosGetPublicKey.d.ts +4 -4
  55. package/lib/types/api/getAddress.d.ts +1 -0
  56. package/lib/types/api/getPublicKey.d.ts +5 -0
  57. package/lib/types/api/index.d.ts +4 -0
  58. package/lib/types/api/setBusy.d.ts +4 -0
  59. package/lib/types/api/setBusy.js +3 -0
  60. package/lib/types/api/unlockPath.d.ts +8 -0
  61. package/lib/types/api/unlockPath.js +3 -0
  62. package/lib/utils/pathUtils.d.ts +2 -3
  63. package/lib/utils/pathUtils.js +42 -15
  64. package/package.json +19 -7
  65. package/lib/api/bitcoin/__fixtures__/inputs.d.ts +0 -112
  66. package/lib/api/bitcoin/__fixtures__/inputs.js +0 -102
  67. package/lib/api/bitcoin/__fixtures__/signtxVerify.d.ts +0 -147
  68. package/lib/api/bitcoin/__fixtures__/signtxVerify.js +0 -216
  69. package/lib/api/common/__fixtures__/paramsValidator.d.ts +0 -596
  70. package/lib/api/common/__fixtures__/paramsValidator.js +0 -355
  71. package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.d.ts +0 -225
  72. package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.js +0 -341
  73. package/lib/utils/__fixtures__/accountUtils.d.ts +0 -4
  74. package/lib/utils/__fixtures__/accountUtils.js +0 -32
  75. package/lib/utils/__fixtures__/addressUtils.d.ts +0 -10
  76. package/lib/utils/__fixtures__/addressUtils.js +0 -214
  77. package/lib/utils/__fixtures__/ethereumUtils.d.ts +0 -3
  78. package/lib/utils/__fixtures__/ethereumUtils.js +0 -20
  79. package/lib/utils/__fixtures__/formatUtils.d.ts +0 -3
  80. package/lib/utils/__fixtures__/formatUtils.js +0 -15
  81. package/lib/utils/__fixtures__/hdnodeUtils.d.ts +0 -186
  82. package/lib/utils/__fixtures__/hdnodeUtils.js +0 -206
  83. package/lib/utils/bufferUtils.d.ts +0 -3
  84. package/lib/utils/bufferUtils.js +0 -11
@@ -47,45 +47,55 @@ class DeviceCommands {
47
47
  isDisposed() {
48
48
  return this.disposed;
49
49
  }
50
- async getPublicKey(address_n, coin_name = 'Bitcoin', script_type, show_display) {
50
+ unlockPath(params) {
51
+ return this.typedCall('UnlockPath', 'UnlockedPathRequest', params);
52
+ }
53
+ async getPublicKey(params, unlockPath) {
54
+ if (unlockPath) {
55
+ await this.unlockPath(unlockPath);
56
+ }
51
57
  const response = await this.typedCall('GetPublicKey', 'PublicKey', {
52
- address_n,
53
- coin_name,
54
- script_type,
55
- show_display,
58
+ address_n: params.address_n,
59
+ coin_name: params.coin_name || 'Bitcoin',
60
+ script_type: params.script_type,
61
+ show_display: params.show_display,
62
+ ignore_xpub_magic: params.ignore_xpub_magic,
63
+ ecdsa_curve_name: params.ecdsa_curve_name,
56
64
  });
57
65
  return response.message;
58
66
  }
59
- async getHDNode(path, coinInfo, validation = true, showOnTrezor = false) {
67
+ async getHDNode(params, options = {}) {
68
+ const path = params.address_n;
69
+ const { coinInfo, unlockPath } = options;
70
+ const validation = typeof options.validation === 'boolean' ? options.validation : true;
60
71
  if (!this.device.atLeast(['1.7.2', '2.0.10']) || !coinInfo) {
61
72
  return this.getBitcoinHDNode(path, coinInfo);
62
73
  }
63
- let network;
64
- if ((0, pathUtils_1.isMultisigPath)(path)) {
65
- network = coinInfo.network;
74
+ let network = null;
75
+ if (!params.script_type) {
76
+ params.script_type = (0, pathUtils_1.getScriptType)(path);
66
77
  }
67
- else if ((0, pathUtils_1.isSegwitPath)(path)) {
78
+ if (params.script_type === 'SPENDP2SHWITNESS') {
68
79
  network = (0, coinInfo_1.getSegwitNetwork)(coinInfo);
69
80
  }
70
- else if ((0, pathUtils_1.isBech32Path)(path)) {
81
+ else if (params.script_type === 'SPENDWITNESS') {
71
82
  network = (0, coinInfo_1.getBech32Network)(coinInfo);
72
83
  }
73
- let scriptType = (0, pathUtils_1.getScriptType)(path);
74
84
  if (!network) {
75
85
  network = coinInfo.network;
76
- if (scriptType !== 'SPENDADDRESS') {
77
- scriptType = undefined;
78
- }
86
+ }
87
+ if (!params.coin_name) {
88
+ params.coin_name = coinInfo.name;
79
89
  }
80
90
  let publicKey;
81
- if (showOnTrezor || !validation) {
82
- publicKey = await this.getPublicKey(path, coinInfo.name, scriptType, showOnTrezor);
91
+ if (params.show_display || !validation) {
92
+ publicKey = await this.getPublicKey(params, unlockPath);
83
93
  }
84
94
  else {
85
95
  const suffix = 0;
86
96
  const childPath = path.concat([suffix]);
87
- const resKey = await this.getPublicKey(path, coinInfo.name, scriptType);
88
- const childKey = await this.getPublicKey(childPath, coinInfo.name, scriptType);
97
+ const resKey = await this.getPublicKey(params, unlockPath);
98
+ const childKey = await this.getPublicKey({ ...params, address_n: childPath }, unlockPath);
89
99
  publicKey = hdnodeUtils.xpubDerive(resKey, childKey, suffix, network, coinInfo.network);
90
100
  }
91
101
  const response = {
@@ -103,20 +113,22 @@ class DeviceCommands {
103
113
  response.xpub = hdnodeUtils.convertXpub(publicKey.xpub, network, coinInfo.network);
104
114
  }
105
115
  if ((0, pathUtils_1.isTaprootPath)(path)) {
106
- response.xpubSegwit = `tr([5c9e228d/86'/${(0, pathUtils_1.fromHardened)(path[1])}'/${(0, pathUtils_1.fromHardened)(path[2])}']${response.xpub}/<0;1>/*)`;
116
+ const fingerprint = Number(publicKey.root_fingerprint || 0).toString(16);
117
+ const descriptorPath = `${fingerprint}${response.serializedPath.substring(1)}`;
118
+ response.xpubSegwit = `tr([${descriptorPath}]${response.xpub}/<0;1>/*)`;
107
119
  }
108
120
  return response;
109
121
  }
110
122
  async getBitcoinHDNode(path, coinInfo, validation = true) {
111
123
  let publicKey;
112
124
  if (!validation) {
113
- publicKey = await this.getPublicKey(path);
125
+ publicKey = await this.getPublicKey({ address_n: path });
114
126
  }
115
127
  else {
116
128
  const suffix = 0;
117
129
  const childPath = path.concat([suffix]);
118
- const resKey = await this.getPublicKey(path);
119
- const childKey = await this.getPublicKey(childPath);
130
+ const resKey = await this.getPublicKey({ address_n: path });
131
+ const childKey = await this.getPublicKey({ address_n: childPath });
120
132
  publicKey = hdnodeUtils.xpubDerive(resKey, childKey, suffix);
121
133
  }
122
134
  const response = {
@@ -183,7 +195,7 @@ class DeviceCommands {
183
195
  }
184
196
  async ethereumGetPublicKey({ address_n, show_display, }) {
185
197
  if (!this.device.atLeast(['1.8.1', '2.1.0'])) {
186
- return this.getHDNode(address_n);
198
+ return this.getHDNode({ address_n });
187
199
  }
188
200
  const suffix = 0;
189
201
  const childPath = address_n.concat([suffix]);
@@ -207,6 +219,17 @@ class DeviceCommands {
207
219
  depth: publicKey.node.depth,
208
220
  };
209
221
  }
222
+ async preauthorize(throwError) {
223
+ try {
224
+ await this.typedCall('DoPreauthorized', 'PreauthorizedRequest', {});
225
+ return true;
226
+ }
227
+ catch (error) {
228
+ if (throwError)
229
+ throw error;
230
+ return false;
231
+ }
232
+ }
210
233
  getDeviceState(networkType) {
211
234
  if (!this.device.atLeast('2.4.3')) {
212
235
  return this._getAddressForNetworkType(networkType);
@@ -403,7 +426,7 @@ class DeviceCommands {
403
426
  ? indexOrPath
404
427
  : (0, accountUtils_1.getAccountAddressN)(coinInfo, indexOrPath);
405
428
  if (coinInfo.type === 'bitcoin') {
406
- const resp = await this.getHDNode(address_n, coinInfo, false);
429
+ const resp = await this.getHDNode({ address_n }, { coinInfo, validation: false });
407
430
  return {
408
431
  descriptor: resp.xpubSegwit || resp.xpub,
409
432
  legacyXpub: resp.xpub,
package/lib/factory.js CHANGED
@@ -94,6 +94,7 @@ const factory = ({ eventEmitter, manifest, init, call, requestLogin, uiResponse,
94
94
  }),
95
95
  tezosGetPublicKey: params => call({ ...params, method: 'tezosGetPublicKey' }),
96
96
  tezosSignTransaction: params => call({ ...params, method: 'tezosSignTransaction' }),
97
+ unlockPath: params => call({ ...params, method: 'unlockPath' }),
97
98
  eosGetPublicKey: params => call({ ...params, method: 'eosGetPublicKey' }),
98
99
  eosSignTransaction: params => call({ ...params, method: 'eosSignTransaction' }),
99
100
  binanceGetAddress: params => call({
@@ -116,6 +117,7 @@ const factory = ({ eventEmitter, manifest, init, call, requestLogin, uiResponse,
116
117
  recoveryDevice: params => call({ ...params, method: 'recoveryDevice' }),
117
118
  getCoinInfo: params => call({ ...params, method: 'getCoinInfo' }),
118
119
  rebootToBootloader: params => call({ ...params, method: 'rebootToBootloader' }),
120
+ setBusy: params => call({ ...params, method: 'setBusy' }),
119
121
  setProxy: params => call({ ...params, method: 'setProxy' }),
120
122
  dispose,
121
123
  cancel,
@@ -9,6 +9,7 @@ export interface AuthorizeCoinJoin {
9
9
  coin?: string;
10
10
  scriptType?: PROTO.InternalInputScriptType;
11
11
  amountUnit?: PROTO.AmountUnit;
12
+ preauthorized?: boolean;
12
13
  }
13
14
  export declare function authorizeCoinJoin(params: Params<AuthorizeCoinJoin>): Response<PROTO.Success>;
14
15
  //# sourceMappingURL=authorizeCoinJoin.d.ts.map
@@ -44,6 +44,8 @@ export interface TransactionOptions {
44
44
  branch_id?: number;
45
45
  decred_staking_ticket?: boolean;
46
46
  amount_unit?: PROTO.AmountUnit;
47
+ serialize?: boolean;
48
+ coinjoin_request?: PROTO.CoinJoinRequest;
47
49
  }
48
50
  export interface SignTransaction {
49
51
  inputs: PROTO.TxInputType[];
@@ -65,6 +67,9 @@ export interface SignTransaction {
65
67
  push?: boolean;
66
68
  preauthorized?: boolean;
67
69
  amountUnit?: PROTO.AmountUnit;
70
+ unlockPath?: PROTO.UnlockPath;
71
+ serialize?: boolean;
72
+ coinjoinRequest?: PROTO.CoinJoinRequest;
68
73
  }
69
74
  export declare type SignedTransaction = {
70
75
  signatures: string[];
@@ -1,4 +1,5 @@
1
1
  import type { PROTO } from '../../../constants';
2
+ import type { GetPublicKey, PublicKey } from '../../params';
2
3
  export interface CardanoCertificatePointer {
3
4
  blockIndex: number;
4
5
  txIndex: number;
@@ -46,15 +47,10 @@ export interface CardanoGetNativeScriptHash {
46
47
  export interface CardanoNativeScriptHash {
47
48
  scriptHash: string;
48
49
  }
49
- export interface CardanoGetPublicKey {
50
- path: string | number[];
51
- showOnTrezor?: boolean;
50
+ export interface CardanoGetPublicKey extends GetPublicKey {
52
51
  derivationType?: PROTO.CardanoDerivationType;
53
52
  }
54
- export interface CardanoPublicKey {
55
- path: number[];
56
- serializedPath: string;
57
- publicKey: string;
53
+ export interface CardanoPublicKey extends PublicKey {
58
54
  node: PROTO.HDNodeType;
59
55
  }
60
56
  export interface CardanoInput {
@@ -141,15 +137,22 @@ export interface CardanoReferenceInput {
141
137
  prev_hash: string;
142
138
  prev_index: number;
143
139
  }
144
- export interface CardanoCatalystRegistrationParameters {
140
+ export interface CardanoGovernanceRegistrationDelegation {
145
141
  votingPublicKey: string;
142
+ weight: number;
143
+ }
144
+ export interface CardanoGovernanceRegistrationParameters {
145
+ votingPublicKey?: string;
146
146
  stakingPath: string | number[];
147
147
  rewardAddressParameters: CardanoAddressParameters;
148
148
  nonce: string;
149
+ format?: PROTO.CardanoGovernanceRegistrationFormat;
150
+ delegations?: CardanoGovernanceRegistrationDelegation[];
151
+ votingPurpose?: number;
149
152
  }
150
153
  export interface CardanoAuxiliaryData {
151
154
  hash?: string;
152
- catalystRegistrationParameters?: CardanoCatalystRegistrationParameters;
155
+ governanceRegistrationParameters?: CardanoGovernanceRegistrationParameters;
153
156
  }
154
157
  export interface CardanoSignTransaction {
155
158
  inputs: CardanoInput[];
@@ -183,7 +186,7 @@ export interface CardanoSignedTxWitness {
183
186
  export interface CardanoAuxiliaryDataSupplement {
184
187
  type: PROTO.CardanoTxAuxiliaryDataSupplementType;
185
188
  auxiliaryDataHash: string;
186
- catalystSignature?: string;
189
+ governanceSignature?: string;
187
190
  }
188
191
  export interface CardanoSignedTxData {
189
192
  hash: string;
@@ -1,8 +1,4 @@
1
1
  import { PROTO } from '../../../constants';
2
- export interface EosGetPublicKey {
3
- path: string | number[];
4
- showOnTrezor?: boolean;
5
- }
6
2
  export interface EosPublicKey {
7
3
  wifPublicKey: string;
8
4
  rawPublicKey: string;
@@ -1,5 +1,5 @@
1
- import type { Params, BundledParams, Response } from '../params';
2
- import { EosGetPublicKey, EosPublicKey } from './eos';
3
- export declare function eosGetPublicKey(params: Params<EosGetPublicKey>): Response<EosPublicKey>;
4
- export declare function eosGetPublicKey(params: BundledParams<EosGetPublicKey>): Response<EosPublicKey[]>;
1
+ import type { Params, GetPublicKey, BundledParams, Response } from '../params';
2
+ import { EosPublicKey } from './eos';
3
+ export declare function eosGetPublicKey(params: Params<GetPublicKey>): Response<EosPublicKey>;
4
+ export declare function eosGetPublicKey(params: BundledParams<GetPublicKey>): Response<EosPublicKey[]>;
5
5
  //# sourceMappingURL=eosGetPublicKey.d.ts.map
@@ -5,6 +5,7 @@ interface GetAddress extends GetAddressShared {
5
5
  crossChain?: boolean;
6
6
  multisig?: PROTO.MultisigRedeemScriptType;
7
7
  scriptType?: PROTO.InternalInputScriptType;
8
+ unlockPath?: PROTO.UnlockPath;
8
9
  }
9
10
  declare type Address = AddressShared & PROTO.Address;
10
11
  export declare function getAddress(params: Params<GetAddress>): Response<Address>;
@@ -1,7 +1,12 @@
1
+ import type { PROTO } from '../../constants';
1
2
  import type { GetPublicKey as GetPublicKeyShared, Params, BundledParams, Response } from '../params';
2
3
  export interface GetPublicKey extends GetPublicKeyShared {
3
4
  coin?: string;
4
5
  crossChain?: boolean;
6
+ scriptType?: PROTO.InternalInputScriptType;
7
+ ignoreXpubMagic?: boolean;
8
+ ecdsaCurveName?: string;
9
+ unlockPath?: PROTO.UnlockPath;
5
10
  }
6
11
  export interface HDNodeResponse {
7
12
  path: number[];
@@ -60,6 +60,7 @@ import { requestLogin } from './requestLogin';
60
60
  import { resetDevice } from './resetDevice';
61
61
  import { rippleGetAddress } from './rippleGetAddress';
62
62
  import { rippleSignTransaction } from './rippleSignTransaction';
63
+ import { setBusy } from './setBusy';
63
64
  import { setProxy } from './setProxy';
64
65
  import { signMessage } from './signMessage';
65
66
  import { signTransaction } from './signTransaction';
@@ -69,6 +70,7 @@ import { tezosGetAddress } from './tezosGetAddress';
69
70
  import { tezosGetPublicKey } from './tezosGetPublicKey';
70
71
  import { tezosSignTransaction } from './tezosSignTransaction';
71
72
  import { uiResponse } from './uiResponse';
73
+ import { unlockPath } from './unlockPath';
72
74
  import { verifyMessage } from './verifyMessage';
73
75
  import { wipeDevice } from './wipeDevice';
74
76
  import { checkFirmwareAuthenticity } from './checkFirmwareAuthenticity';
@@ -135,6 +137,7 @@ export interface TrezorConnect {
135
137
  resetDevice: typeof resetDevice;
136
138
  rippleGetAddress: typeof rippleGetAddress;
137
139
  rippleSignTransaction: typeof rippleSignTransaction;
140
+ setBusy: typeof setBusy;
138
141
  setProxy: typeof setProxy;
139
142
  signMessage: typeof signMessage;
140
143
  signTransaction: typeof signTransaction;
@@ -144,6 +147,7 @@ export interface TrezorConnect {
144
147
  tezosGetPublicKey: typeof tezosGetPublicKey;
145
148
  tezosSignTransaction: typeof tezosSignTransaction;
146
149
  uiResponse: typeof uiResponse;
150
+ unlockPath: typeof unlockPath;
147
151
  verifyMessage: typeof verifyMessage;
148
152
  wipeDevice: typeof wipeDevice;
149
153
  checkFirmwareAuthenticity: typeof checkFirmwareAuthenticity;
@@ -0,0 +1,4 @@
1
+ import type { PROTO } from '../../constants';
2
+ import type { CommonParams, Response } from '../params';
3
+ export declare function setBusy(params: CommonParams & PROTO.SetBusy): Response<PROTO.Success>;
4
+ //# sourceMappingURL=setBusy.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=setBusy.js.map
@@ -0,0 +1,8 @@
1
+ import type { PROTO } from '../../constants';
2
+ import type { Params, Response } from '../params';
3
+ export interface UnlockPathParams {
4
+ path: string | number[];
5
+ mac?: string;
6
+ }
7
+ export declare function unlockPath(params: Params<UnlockPathParams>): Response<PROTO.UnlockPath>;
8
+ //# sourceMappingURL=unlockPath.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=unlockPath.js.map
@@ -4,13 +4,12 @@ export declare const HD_HARDENED = 2147483648;
4
4
  export declare const toHardened: (n: number) => number;
5
5
  export declare const fromHardened: (n: number) => number;
6
6
  export declare const getHDPath: (path: string) => number[];
7
- export declare const isMultisigPath: (path: number[] | undefined) => boolean;
8
7
  export declare const isSegwitPath: (path: number[] | undefined) => boolean;
9
8
  export declare const isBech32Path: (path: number[] | undefined) => boolean;
10
9
  export declare const isTaprootPath: (path: number[] | undefined) => boolean;
11
10
  export declare const getAccountType: (path: number[] | undefined) => "p2pkh" | "p2sh" | "p2tr" | "p2wpkh";
12
- export declare const getScriptType: (path: number[] | undefined) => PROTO.InternalInputScriptType;
13
- export declare const getOutputScriptType: (path?: number[]) => PROTO.ChangeOutputScriptType;
11
+ export declare const getScriptType: (path: number[] | undefined) => PROTO.InternalInputScriptType | undefined;
12
+ export declare const getOutputScriptType: (path?: number[]) => PROTO.ChangeOutputScriptType | undefined;
14
13
  export declare const validatePath: (path: string | number[], length?: number, base?: boolean) => number[];
15
14
  export declare const getSerializedPath: (path: number[]) => string;
16
15
  export declare const getPathFromIndex: (bip44purpose: number, bip44cointype: number, index: number) => number[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLabel = exports.fixPath = exports.getIndexFromPath = exports.getPathFromIndex = exports.getSerializedPath = exports.validatePath = exports.getOutputScriptType = exports.getScriptType = exports.getAccountType = exports.isTaprootPath = exports.isBech32Path = exports.isSegwitPath = exports.isMultisigPath = exports.getHDPath = exports.fromHardened = exports.toHardened = exports.HD_HARDENED = void 0;
3
+ exports.getLabel = exports.fixPath = exports.getIndexFromPath = exports.getPathFromIndex = exports.getSerializedPath = exports.validatePath = exports.getOutputScriptType = exports.getScriptType = exports.getAccountType = exports.isTaprootPath = exports.isBech32Path = exports.isSegwitPath = exports.getHDPath = exports.fromHardened = exports.toHardened = exports.HD_HARDENED = void 0;
4
4
  const constants_1 = require("../constants");
5
5
  exports.HD_HARDENED = 0x80000000;
6
6
  const toHardened = (n) => (n | exports.HD_HARDENED) >>> 0;
@@ -35,13 +35,11 @@ const getHDPath = (path) => {
35
35
  });
36
36
  };
37
37
  exports.getHDPath = getHDPath;
38
- const isMultisigPath = (path) => Array.isArray(path) && path[0] === (0, exports.toHardened)(48);
39
- exports.isMultisigPath = isMultisigPath;
40
38
  const isSegwitPath = (path) => Array.isArray(path) && path[0] === (0, exports.toHardened)(49);
41
39
  exports.isSegwitPath = isSegwitPath;
42
40
  const isBech32Path = (path) => Array.isArray(path) && path[0] === (0, exports.toHardened)(84);
43
41
  exports.isBech32Path = isBech32Path;
44
- const isTaprootPath = (path) => Array.isArray(path) && path[0] === (0, exports.toHardened)(86);
42
+ const isTaprootPath = (path) => Array.isArray(path) && (path[0] === (0, exports.toHardened)(86) || path[0] === (0, exports.toHardened)(10025));
45
43
  exports.isTaprootPath = isTaprootPath;
46
44
  const getAccountType = (path) => {
47
45
  if ((0, exports.isTaprootPath)(path))
@@ -55,40 +53,69 @@ const getAccountType = (path) => {
55
53
  exports.getAccountType = getAccountType;
56
54
  const getScriptType = (path) => {
57
55
  if (!Array.isArray(path) || path.length < 1)
58
- return 'SPENDADDRESS';
56
+ return undefined;
59
57
  const p1 = (0, exports.fromHardened)(path[0]);
60
58
  switch (p1) {
61
- case 48:
62
- return 'SPENDMULTISIG';
59
+ case 44:
60
+ return 'SPENDADDRESS';
61
+ case 48: {
62
+ if (path.length < 4)
63
+ return undefined;
64
+ const p3 = (0, exports.fromHardened)(path[3]);
65
+ switch (p3) {
66
+ case 0:
67
+ return 'SPENDMULTISIG';
68
+ case 1:
69
+ return 'SPENDP2SHWITNESS';
70
+ case 2:
71
+ return 'SPENDWITNESS';
72
+ default:
73
+ return undefined;
74
+ }
75
+ }
63
76
  case 49:
64
77
  return 'SPENDP2SHWITNESS';
65
78
  case 84:
66
79
  return 'SPENDWITNESS';
67
80
  case 86:
81
+ case 10025:
68
82
  return 'SPENDTAPROOT';
69
83
  default:
70
- return 'SPENDADDRESS';
84
+ return undefined;
71
85
  }
72
86
  };
73
87
  exports.getScriptType = getScriptType;
74
88
  const getOutputScriptType = (path) => {
75
89
  if (!Array.isArray(path) || path.length < 1)
76
- return 'PAYTOADDRESS';
77
- if (path[0] === 49) {
78
- return 'PAYTOP2SHWITNESS';
79
- }
90
+ return undefined;
80
91
  const p = (0, exports.fromHardened)(path[0]);
81
92
  switch (p) {
82
- case 48:
83
- return 'PAYTOMULTISIG';
93
+ case 44:
94
+ return 'PAYTOADDRESS';
95
+ case 48: {
96
+ if (path.length < 4)
97
+ return undefined;
98
+ const p3 = (0, exports.fromHardened)(path[3]);
99
+ switch (p3) {
100
+ case 0:
101
+ return 'PAYTOMULTISIG';
102
+ case 1:
103
+ return 'PAYTOP2SHWITNESS';
104
+ case 2:
105
+ return 'PAYTOWITNESS';
106
+ default:
107
+ return undefined;
108
+ }
109
+ }
84
110
  case 49:
85
111
  return 'PAYTOP2SHWITNESS';
86
112
  case 84:
87
113
  return 'PAYTOWITNESS';
88
114
  case 86:
115
+ case 10025:
89
116
  return 'PAYTOTAPROOT';
90
117
  default:
91
- return 'PAYTOADDRESS';
118
+ return undefined;
92
119
  }
93
120
  };
94
121
  exports.getOutputScriptType = getOutputScriptType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trezor/connect",
3
- "version": "9.0.2",
3
+ "version": "9.0.4",
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.",
@@ -41,14 +41,16 @@
41
41
  "version:beta": "tsx scripts/bump-version.ts prerelease",
42
42
  "version:patch": "tsx scripts/bump-version.ts patch",
43
43
  "version:minor": "tsx scripts/bump-version.ts minor",
44
- "version:major": "tsx scripts/bump-version.ts major"
44
+ "version:major": "tsx scripts/bump-version.ts major",
45
+ "test:e2e:web": "ts-node -O '{\"module\": \"commonjs\"}' ./e2e/run.ts web",
46
+ "test:e2e:node": "ts-node -O '{\"module\": \"commonjs\"}' ./e2e/run.ts node"
45
47
  },
46
48
  "dependencies": {
47
- "@trezor/blockchain-link": "^2.1.4",
48
- "@trezor/connect-common": "0.0.9",
49
- "@trezor/transport": "^1.1.4",
50
- "@trezor/utils": "^9.0.2",
51
- "@trezor/utxo-lib": "^1.0.0",
49
+ "@trezor/blockchain-link": "^2.1.5",
50
+ "@trezor/connect-common": "0.0.10",
51
+ "@trezor/transport": "^1.1.5",
52
+ "@trezor/utils": "^9.0.3",
53
+ "@trezor/utxo-lib": "^1.0.1",
52
54
  "bignumber.js": "^9.1.0",
53
55
  "blakejs": "^1.2.1",
54
56
  "bowser": "^2.11.0",
@@ -59,10 +61,20 @@
59
61
  "tslib": "^2.3.1"
60
62
  },
61
63
  "devDependencies": {
64
+ "@trezor/trezor-user-env-link": "*",
65
+ "@types/karma": "^6.3.3",
62
66
  "@types/parse-uri": "^1.0.0",
63
67
  "@types/randombytes": "^2.0.0",
64
68
  "jest": "^26.6.3",
69
+ "karma": "^6.3.16",
70
+ "karma-babel-preprocessor": "^8.0.2",
71
+ "karma-chrome-launcher": "^3.1.0",
72
+ "karma-jasmine": "4.0.1",
73
+ "karma-jasmine-async": "^0.0.1",
74
+ "karma-sourcemap-loader": "^0.3.8",
75
+ "karma-webpack": "^5.0.0",
65
76
  "rimraf": "^3.0.2",
77
+ "ts-node": "^10.9.1",
66
78
  "tsx": "^3.8.2",
67
79
  "typescript": "4.7.4"
68
80
  }
@@ -1,112 +0,0 @@
1
- export declare const validateTrezorInputs: ({
2
- description: string;
3
- params: {
4
- address_n: number[];
5
- amount: string;
6
- prev_index: number;
7
- prev_hash: string;
8
- }[];
9
- result: {
10
- amount: string;
11
- }[];
12
- } | {
13
- description: string;
14
- params: {
15
- address_n: number[];
16
- amount: string;
17
- prev_index: number;
18
- prev_hash: string;
19
- }[];
20
- result: {
21
- address_n: number[];
22
- }[];
23
- } | {
24
- description: string;
25
- params: {
26
- address_n: number[];
27
- amount: string;
28
- prev_index: number;
29
- prev_hash: string;
30
- multisig: {
31
- pubkeys: {
32
- node: string;
33
- }[];
34
- };
35
- }[];
36
- result: {
37
- multisig: {
38
- pubkeys: {
39
- node: {
40
- public_key: string;
41
- chain_code: string;
42
- depth: number;
43
- };
44
- }[];
45
- };
46
- }[];
47
- } | {
48
- description: string;
49
- params: {
50
- amount: string;
51
- prev_index: number;
52
- prev_hash: string;
53
- script_type: string;
54
- script_pubkey: string;
55
- witness: string;
56
- }[];
57
- result: {
58
- amount: string;
59
- }[];
60
- } | {
61
- description: string;
62
- params: {
63
- amount: string;
64
- prev_index: number;
65
- prev_hash: string;
66
- }[];
67
- result?: undefined;
68
- } | {
69
- description: string;
70
- params: {
71
- address_n: number[];
72
- amount: string;
73
- prev_hash: string;
74
- }[];
75
- result?: undefined;
76
- } | {
77
- description: string;
78
- params: {
79
- address_n: number[];
80
- amount: string;
81
- prev_index: number;
82
- }[];
83
- result?: undefined;
84
- } | {
85
- description: string;
86
- params: {
87
- address_n: number[];
88
- prev_index: number;
89
- prev_hash: string;
90
- }[];
91
- result: {
92
- prev_index: number;
93
- }[];
94
- } | {
95
- description: string;
96
- params: {
97
- address_n: number[];
98
- prev_index: number;
99
- prev_hash: string;
100
- }[];
101
- result?: undefined;
102
- } | {
103
- description: string;
104
- params: {
105
- amount: string;
106
- prev_index: number;
107
- prev_hash: string;
108
- script_type: string;
109
- }[];
110
- result?: undefined;
111
- })[];
112
- //# sourceMappingURL=inputs.d.ts.map