@trezor/connect 9.0.3 → 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.
- package/README.md +1 -1
- package/lib/api/authorizeCoinJoin.js +6 -2
- package/lib/api/bitcoin/enhanceSignTx.js +1 -1
- package/lib/api/bitcoin/inputs.js +3 -2
- package/lib/api/bitcoin/refTx.js +3 -3
- package/lib/api/blockchainDisconnect.js +1 -1
- package/lib/api/blockchainSetCustomBackend.js +1 -1
- package/lib/api/cardano/cardanoAuxiliaryData.d.ts +1 -1
- package/lib/api/cardano/cardanoAuxiliaryData.js +38 -16
- package/lib/api/cardanoSignTransaction.d.ts +1 -0
- package/lib/api/cardanoSignTransaction.js +23 -3
- package/lib/api/getOwnershipProof.d.ts +1 -5
- package/lib/api/getOwnershipProof.js +5 -3
- package/lib/api/index.d.ts +1 -0
- package/lib/api/index.js +3 -1
- package/lib/api/setBusy.d.ts +7 -0
- package/lib/api/setBusy.js +27 -0
- package/lib/api/signTransaction.d.ts +1 -1
- package/lib/api/signTransaction.js +10 -3
- package/lib/backend/BackendManager.d.ts +21 -0
- package/lib/backend/BackendManager.js +91 -0
- package/lib/backend/Blockchain.d.ts +72 -0
- package/lib/backend/Blockchain.js +204 -0
- package/lib/backend/BlockchainLink.d.ts +6 -71
- package/lib/backend/BlockchainLink.js +12 -288
- package/lib/constants/cardano.d.ts +3 -1
- package/lib/constants/cardano.js +3 -1
- package/lib/core/AbstractMethod.d.ts +1 -0
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/method.d.ts +1 -1
- package/lib/data/config.js +1 -1
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +1 -1
- package/lib/device/Device.js +8 -2
- package/lib/device/DeviceCommands.d.ts +1 -0
- package/lib/device/DeviceCommands.js +11 -0
- package/lib/factory.js +1 -0
- package/lib/types/api/authorizeCoinJoin.d.ts +1 -0
- package/lib/types/api/bitcoin/index.d.ts +4 -0
- package/lib/types/api/cardano/index.d.ts +10 -3
- package/lib/types/api/index.d.ts +2 -0
- package/lib/types/api/setBusy.d.ts +4 -0
- package/lib/types/api/setBusy.js +3 -0
- package/package.json +10 -8
- package/lib/utils/bufferUtils.d.ts +0 -3
- package/lib/utils/bufferUtils.js +0 -11
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @trezor/connect
|
|
2
2
|
|
|
3
|
-
API version 9.0.
|
|
3
|
+
API version 9.0.4
|
|
4
4
|
|
|
5
5
|
[](https://github.com/trezor/trezor-suite/actions/workflows/connect-test.yml)
|
|
6
6
|
[](https://www.npmjs.org/package/@trezor/connect)
|
|
@@ -16,11 +16,13 @@ class AuthorizeCoinJoin extends AbstractMethod_1.AbstractMethod {
|
|
|
16
16
|
{ name: 'coin', type: 'string' },
|
|
17
17
|
{ name: 'scriptType', type: 'string' },
|
|
18
18
|
{ name: 'amountUnit', type: 'uint' },
|
|
19
|
+
{ name: 'preauthorized', type: 'boolean' },
|
|
19
20
|
]);
|
|
20
21
|
const address_n = (0, pathUtils_1.validatePath)(payload.path, 3);
|
|
21
22
|
const script_type = payload.scriptType || (0, pathUtils_1.getScriptType)(address_n);
|
|
22
23
|
const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(payload.coin || address_n);
|
|
23
24
|
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, coinInfo, this.firmwareRange);
|
|
25
|
+
this.preauthorized = payload.preauthorized;
|
|
24
26
|
this.params = {
|
|
25
27
|
coordinator: payload.coordinator,
|
|
26
28
|
max_rounds: payload.maxRounds,
|
|
@@ -34,8 +36,10 @@ class AuthorizeCoinJoin extends AbstractMethod_1.AbstractMethod {
|
|
|
34
36
|
}
|
|
35
37
|
async run() {
|
|
36
38
|
const cmd = this.device.getCommands();
|
|
37
|
-
if (
|
|
38
|
-
await cmd.
|
|
39
|
+
if (this.preauthorized) {
|
|
40
|
+
if (await cmd.preauthorize(false)) {
|
|
41
|
+
return { message: 'Success' };
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
44
|
const response = await cmd.typedCall('AuthorizeCoinJoin', 'Success', this.params);
|
|
41
45
|
return response.message;
|
|
@@ -15,7 +15,7 @@ const enhanceSignTx = (options, coinInfo) => {
|
|
|
15
15
|
options.version_group_id = 0x26a7270a;
|
|
16
16
|
}
|
|
17
17
|
if (typeof options.branch_id !== 'number') {
|
|
18
|
-
const backend = (0, BlockchainLink_1.findBackend)(coinInfo.
|
|
18
|
+
const backend = (0, BlockchainLink_1.findBackend)(coinInfo.shortcut);
|
|
19
19
|
if (backend && ((_a = backend.serverInfo) === null || _a === void 0 ? void 0 : _a.consensusBranchId)) {
|
|
20
20
|
options.branch_id = backend.serverInfo.consensusBranchId;
|
|
21
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inputToTrezor = exports.enhanceTrezorInputs = exports.validateTrezorInputs = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("@trezor/utils");
|
|
5
5
|
const pathUtils_1 = require("../../utils/pathUtils");
|
|
6
6
|
const hdnodeUtils_1 = require("../../utils/hdnodeUtils");
|
|
7
7
|
const paramsValidator_1 = require("../common/paramsValidator");
|
|
@@ -17,6 +17,7 @@ const validateTrezorInputs = (inputs, coinInfo) => inputs
|
|
|
17
17
|
{ name: 'script_type', type: 'string' },
|
|
18
18
|
{ name: 'sequence', type: 'number' },
|
|
19
19
|
{ name: 'multisig', type: 'object' },
|
|
20
|
+
{ name: 'coinjoin_flags', type: 'number' },
|
|
20
21
|
]);
|
|
21
22
|
if (input.script_type === 'EXTERNAL') {
|
|
22
23
|
(0, paramsValidator_1.validateParams)(input, [
|
|
@@ -50,7 +51,7 @@ const inputToTrezor = (input, sequence) => {
|
|
|
50
51
|
return {
|
|
51
52
|
address_n,
|
|
52
53
|
prev_index: input.index,
|
|
53
|
-
prev_hash:
|
|
54
|
+
prev_hash: utils_1.bufferUtils.reverseBuffer(input.hash).toString('hex'),
|
|
54
55
|
script_type: (0, pathUtils_1.getScriptType)(address_n),
|
|
55
56
|
amount: input.amount,
|
|
56
57
|
sequence,
|
package/lib/api/bitcoin/refTx.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateReferencedTransactions = exports.transformReferencedTransactions = exports.transformOrigTransactions = exports.getOrigTransactions = exports.getReferencedTransactions = exports.requireReferencedTransactions = void 0;
|
|
4
4
|
const utxo_lib_1 = require("@trezor/utxo-lib");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("@trezor/utils");
|
|
6
6
|
const pathUtils_1 = require("../../utils/pathUtils");
|
|
7
7
|
const paramsValidator_1 = require("../common/paramsValidator");
|
|
8
8
|
const errors_1 = require("../../constants/errors");
|
|
@@ -72,7 +72,7 @@ const transformOrigTransactions = (txs, coinInfo, addresses) => txs.flatMap(raw
|
|
|
72
72
|
const address_n = (0, pathUtils_1.getHDPath)((inputAddress === null || inputAddress === void 0 ? void 0 : inputAddress.path) || '');
|
|
73
73
|
return {
|
|
74
74
|
address_n,
|
|
75
|
-
prev_hash:
|
|
75
|
+
prev_hash: utils_1.bufferUtils.reverseBuffer(input.hash).toString('hex'),
|
|
76
76
|
prev_index: input.index,
|
|
77
77
|
script_sig: input.script.toString('hex'),
|
|
78
78
|
sequence: input.sequence,
|
|
@@ -139,7 +139,7 @@ const transformReferencedTransactions = (txs, coinInfo) => txs.flatMap(raw => {
|
|
|
139
139
|
const inputsMap = (input) => ({
|
|
140
140
|
prev_index: input.index,
|
|
141
141
|
sequence: input.sequence,
|
|
142
|
-
prev_hash:
|
|
142
|
+
prev_hash: utils_1.bufferUtils.reverseBuffer(input.hash).toString('hex'),
|
|
143
143
|
script_sig: input.script.toString('hex'),
|
|
144
144
|
});
|
|
145
145
|
const binOutputsMap = (output) => ({
|
|
@@ -23,7 +23,7 @@ class BlockchainDisconnect extends AbstractMethod_1.AbstractMethod {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
run() {
|
|
26
|
-
const backend = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.
|
|
26
|
+
const backend = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.shortcut);
|
|
27
27
|
if (backend) {
|
|
28
28
|
backend.disconnect();
|
|
29
29
|
}
|
|
@@ -26,7 +26,7 @@ class BlockchainSetCustomBackend extends AbstractMethod_1.AbstractMethod {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
async run() {
|
|
29
|
-
const current = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.
|
|
29
|
+
const current = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.shortcut);
|
|
30
30
|
if (current) {
|
|
31
31
|
current.disconnect();
|
|
32
32
|
await (0, BlockchainLink_1.initBlockchain)(this.params.coinInfo, this.postMessage);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Device } from '../../device/Device';
|
|
2
|
-
import
|
|
2
|
+
import { PROTO } from '../../constants';
|
|
3
3
|
import type { CardanoAuxiliaryData } from '../../types/api/cardano';
|
|
4
4
|
export declare const transformAuxiliaryData: (auxiliaryData: CardanoAuxiliaryData) => PROTO.CardanoTxAuxiliaryData;
|
|
5
5
|
export declare const modifyAuxiliaryDataForBackwardsCompatibility: (device: Device, auxiliary_data: PROTO.CardanoTxAuxiliaryData) => PROTO.CardanoTxAuxiliaryData;
|
|
@@ -4,18 +4,40 @@ exports.modifyAuxiliaryDataForBackwardsCompatibility = exports.transformAuxiliar
|
|
|
4
4
|
const cardanoAddressParameters_1 = require("./cardanoAddressParameters");
|
|
5
5
|
const paramsValidator_1 = require("../common/paramsValidator");
|
|
6
6
|
const pathUtils_1 = require("../../utils/pathUtils");
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const constants_1 = require("../../constants");
|
|
8
|
+
const MAX_DELEGATION_COUNT = 32;
|
|
9
|
+
const transformDelegation = (delegation) => {
|
|
10
|
+
(0, paramsValidator_1.validateParams)(delegation, [
|
|
9
11
|
{ name: 'votingPublicKey', type: 'string', required: true },
|
|
12
|
+
{ name: 'weight', type: 'uint', required: true },
|
|
13
|
+
]);
|
|
14
|
+
return {
|
|
15
|
+
voting_public_key: delegation.votingPublicKey,
|
|
16
|
+
weight: delegation.weight,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const transformGovernanceRegistrationParameters = (governanceRegistrationParameters) => {
|
|
20
|
+
(0, paramsValidator_1.validateParams)(governanceRegistrationParameters, [
|
|
21
|
+
{ name: 'votingPublicKey', type: 'string' },
|
|
10
22
|
{ name: 'stakingPath', required: true },
|
|
11
23
|
{ name: 'nonce', type: 'uint', required: true },
|
|
24
|
+
{ name: 'format', type: 'number' },
|
|
25
|
+
{ name: 'delegations', type: 'array', allowEmpty: true },
|
|
26
|
+
{ name: 'votingPurpose', type: 'uint' },
|
|
12
27
|
]);
|
|
13
|
-
(0, cardanoAddressParameters_1.validateAddressParameters)(
|
|
28
|
+
(0, cardanoAddressParameters_1.validateAddressParameters)(governanceRegistrationParameters.rewardAddressParameters);
|
|
29
|
+
const { delegations } = governanceRegistrationParameters;
|
|
30
|
+
if (delegations && delegations.length > MAX_DELEGATION_COUNT) {
|
|
31
|
+
throw constants_1.ERRORS.TypedError('Method_InvalidParameter', `At most ${MAX_DELEGATION_COUNT} delegations are allowed in a governance registration`);
|
|
32
|
+
}
|
|
14
33
|
return {
|
|
15
|
-
voting_public_key:
|
|
16
|
-
staking_path: (0, pathUtils_1.validatePath)(
|
|
17
|
-
reward_address_parameters: (0, cardanoAddressParameters_1.addressParametersToProto)(
|
|
18
|
-
nonce:
|
|
34
|
+
voting_public_key: governanceRegistrationParameters.votingPublicKey,
|
|
35
|
+
staking_path: (0, pathUtils_1.validatePath)(governanceRegistrationParameters.stakingPath, 3),
|
|
36
|
+
reward_address_parameters: (0, cardanoAddressParameters_1.addressParametersToProto)(governanceRegistrationParameters.rewardAddressParameters),
|
|
37
|
+
nonce: governanceRegistrationParameters.nonce,
|
|
38
|
+
format: governanceRegistrationParameters.format,
|
|
39
|
+
delegations: delegations === null || delegations === void 0 ? void 0 : delegations.map(transformDelegation),
|
|
40
|
+
voting_purpose: governanceRegistrationParameters.votingPurpose,
|
|
19
41
|
};
|
|
20
42
|
};
|
|
21
43
|
const transformAuxiliaryData = (auxiliaryData) => {
|
|
@@ -25,24 +47,24 @@ const transformAuxiliaryData = (auxiliaryData) => {
|
|
|
25
47
|
type: 'string',
|
|
26
48
|
},
|
|
27
49
|
]);
|
|
28
|
-
let
|
|
29
|
-
if (auxiliaryData.
|
|
30
|
-
|
|
50
|
+
let governanceRegistrationParameters;
|
|
51
|
+
if (auxiliaryData.governanceRegistrationParameters) {
|
|
52
|
+
governanceRegistrationParameters = transformGovernanceRegistrationParameters(auxiliaryData.governanceRegistrationParameters);
|
|
31
53
|
}
|
|
32
54
|
return {
|
|
33
55
|
hash: auxiliaryData.hash,
|
|
34
|
-
|
|
56
|
+
governance_registration_parameters: governanceRegistrationParameters,
|
|
35
57
|
};
|
|
36
58
|
};
|
|
37
59
|
exports.transformAuxiliaryData = transformAuxiliaryData;
|
|
38
60
|
const modifyAuxiliaryDataForBackwardsCompatibility = (device, auxiliary_data) => {
|
|
39
|
-
const {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
(0, cardanoAddressParameters_1.modifyAddressParametersForBackwardsCompatibility)(device,
|
|
61
|
+
const { governance_registration_parameters } = auxiliary_data;
|
|
62
|
+
if (governance_registration_parameters) {
|
|
63
|
+
governance_registration_parameters.reward_address_parameters =
|
|
64
|
+
(0, cardanoAddressParameters_1.modifyAddressParametersForBackwardsCompatibility)(device, governance_registration_parameters.reward_address_parameters);
|
|
43
65
|
return {
|
|
44
66
|
...auxiliary_data,
|
|
45
|
-
|
|
67
|
+
governance_registration_parameters,
|
|
46
68
|
};
|
|
47
69
|
}
|
|
48
70
|
return auxiliary_data;
|
|
@@ -15,6 +15,7 @@ declare const CardanoSignTransactionFeatures: Readonly<{
|
|
|
15
15
|
Plutus: string[];
|
|
16
16
|
KeyHashStakeCredential: string[];
|
|
17
17
|
Babbage: string[];
|
|
18
|
+
GovernanceRegistrationCIP36: string[];
|
|
18
19
|
}>;
|
|
19
20
|
export declare type CardanoSignTransactionParams = {
|
|
20
21
|
signingMode: PROTO.CardanoTxSigningMode;
|
|
@@ -21,6 +21,7 @@ const CardanoSignTransactionFeatures = Object.freeze({
|
|
|
21
21
|
Plutus: ['0', '2.4.4'],
|
|
22
22
|
KeyHashStakeCredential: ['0', '2.4.4'],
|
|
23
23
|
Babbage: ['0', '2.5.2'],
|
|
24
|
+
GovernanceRegistrationCIP36: ['0', '2.5.3'],
|
|
24
25
|
});
|
|
25
26
|
class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
26
27
|
init() {
|
|
@@ -34,6 +35,11 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
34
35
|
if (payload.auxiliaryData && payload.auxiliaryData.blob) {
|
|
35
36
|
throw constants_1.ERRORS.TypedError('Method_InvalidParameter', 'Auxiliary data can now only be sent as a hash.');
|
|
36
37
|
}
|
|
38
|
+
if (payload.auxiliaryData && payload.auxiliaryData.catalystRegistrationParameters) {
|
|
39
|
+
console.warn('Please use governanceRegistrationParameters instead of catalystRegistrationParameters.');
|
|
40
|
+
payload.auxiliaryData.governanceRegistrationParameters =
|
|
41
|
+
payload.auxiliaryData.catalystRegistrationParameters;
|
|
42
|
+
}
|
|
37
43
|
(0, paramsValidator_1.validateParams)(payload, [
|
|
38
44
|
{ name: 'signingMode', type: 'number', required: true },
|
|
39
45
|
{ name: 'inputs', type: 'array', required: true },
|
|
@@ -148,6 +154,7 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
_ensureFirmwareSupportsParams() {
|
|
157
|
+
var _a;
|
|
151
158
|
const { params } = this;
|
|
152
159
|
this._ensureFeatureIsSupported('TransactionStreaming');
|
|
153
160
|
params.certificatesWithPoolOwnersAndRelays.forEach(({ certificate }) => {
|
|
@@ -193,6 +200,18 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
193
200
|
params.referenceInputs.length > 0) {
|
|
194
201
|
this._ensureFeatureIsSupported('Babbage');
|
|
195
202
|
}
|
|
203
|
+
if (params.requiredSigners.length > 0 &&
|
|
204
|
+
params.signingMode !== constants_1.PROTO.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
|
|
205
|
+
this._ensureFeatureIsSupported('Babbage');
|
|
206
|
+
}
|
|
207
|
+
if ((_a = params.auxiliaryData) === null || _a === void 0 ? void 0 : _a.governance_registration_parameters) {
|
|
208
|
+
const { format, delegations, voting_purpose } = params.auxiliaryData.governance_registration_parameters;
|
|
209
|
+
if (format === constants_1.PROTO.CardanoGovernanceRegistrationFormat.CIP36 ||
|
|
210
|
+
(delegations === null || delegations === void 0 ? void 0 : delegations.length) ||
|
|
211
|
+
voting_purpose != null) {
|
|
212
|
+
this._ensureFeatureIsSupported('GovernanceRegistrationCIP36');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
196
215
|
}
|
|
197
216
|
async _sign_tx() {
|
|
198
217
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
@@ -242,8 +261,8 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
242
261
|
}
|
|
243
262
|
let auxiliaryDataSupplement;
|
|
244
263
|
if (this.params.auxiliaryData) {
|
|
245
|
-
const {
|
|
246
|
-
if (
|
|
264
|
+
const { governance_registration_parameters } = this.params.auxiliaryData;
|
|
265
|
+
if (governance_registration_parameters) {
|
|
247
266
|
this.params.auxiliaryData = (0, cardanoAuxiliaryData_1.modifyAuxiliaryDataForBackwardsCompatibility)(this.device, this.params.auxiliaryData);
|
|
248
267
|
}
|
|
249
268
|
const { message } = await typedCall('CardanoTxAuxiliaryData', 'CardanoTxAuxiliaryDataSupplement', this.params.auxiliaryData);
|
|
@@ -252,7 +271,8 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
252
271
|
auxiliaryDataSupplement = {
|
|
253
272
|
type: auxiliaryDataType,
|
|
254
273
|
auxiliaryDataHash: message.auxiliary_data_hash,
|
|
255
|
-
|
|
274
|
+
governanceSignature: message.governance_signature,
|
|
275
|
+
catalystSignature: message.governance_signature,
|
|
256
276
|
};
|
|
257
277
|
}
|
|
258
278
|
await typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { AbstractMethod } from '../core/AbstractMethod';
|
|
2
2
|
import { PROTO } from '../constants';
|
|
3
|
-
|
|
4
|
-
preauthorized?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export default class GetOwnershipProof extends AbstractMethod<'getOwnershipProof', Params[]> {
|
|
3
|
+
export default class GetOwnershipProof extends AbstractMethod<'getOwnershipProof', PROTO.GetOwnershipProof[]> {
|
|
7
4
|
hasBundle?: boolean;
|
|
8
5
|
confirmed?: boolean;
|
|
9
6
|
init(): void;
|
|
10
7
|
confirmation(): Promise<boolean>;
|
|
11
8
|
run(): Promise<import("../types/api/getOwnershipProof").OwnershipProof | import("../types/api/getOwnershipProof").OwnershipProof[]>;
|
|
12
9
|
}
|
|
13
|
-
export {};
|
|
14
10
|
//# sourceMappingURL=getOwnershipProof.d.ts.map
|
|
@@ -29,6 +29,9 @@ class GetOwnershipProof extends AbstractMethod_1.AbstractMethod {
|
|
|
29
29
|
const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(batch.coin || address_n);
|
|
30
30
|
const script_type = batch.scriptType || (0, pathUtils_1.getScriptType)(address_n);
|
|
31
31
|
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, coinInfo, this.firmwareRange);
|
|
32
|
+
if (batch.preauthorized) {
|
|
33
|
+
this.preauthorized = batch.preauthorized;
|
|
34
|
+
}
|
|
32
35
|
return {
|
|
33
36
|
address_n,
|
|
34
37
|
coin_name: coinInfo ? coinInfo.name : undefined,
|
|
@@ -37,7 +40,6 @@ class GetOwnershipProof extends AbstractMethod_1.AbstractMethod {
|
|
|
37
40
|
user_confirmation: batch.userConfirmation,
|
|
38
41
|
ownership_ids: batch.ownershipIds,
|
|
39
42
|
commitment_data: batch.commitmentData,
|
|
40
|
-
preauthorized: batch.preauthorized,
|
|
41
43
|
};
|
|
42
44
|
});
|
|
43
45
|
}
|
|
@@ -63,8 +65,8 @@ class GetOwnershipProof extends AbstractMethod_1.AbstractMethod {
|
|
|
63
65
|
const cmd = this.device.getCommands();
|
|
64
66
|
for (let i = 0; i < this.params.length; i++) {
|
|
65
67
|
const batch = this.params[i];
|
|
66
|
-
if (
|
|
67
|
-
await cmd.
|
|
68
|
+
if (this.preauthorized) {
|
|
69
|
+
await cmd.preauthorize(true);
|
|
68
70
|
}
|
|
69
71
|
const { message } = await cmd.typedCall('GetOwnershipProof', 'OwnershipProof', batch);
|
|
70
72
|
responses.push({
|
package/lib/api/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export { default as requestLogin } from './requestLogin';
|
|
|
51
51
|
export { default as resetDevice } from './resetDevice';
|
|
52
52
|
export { default as rippleGetAddress } from './rippleGetAddress';
|
|
53
53
|
export { default as rippleSignTransaction } from './rippleSignTransaction';
|
|
54
|
+
export { default as setBusy } from './setBusy';
|
|
54
55
|
export { default as setProxy } from './setProxy';
|
|
55
56
|
export { default as signMessage } from './signMessage';
|
|
56
57
|
export { default as signTransaction } from './signTransaction';
|
package/lib/api/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.requestLogin = exports.recoveryDevice = exports.rebootToBootloader = exports.pushTransaction = exports.nemSignTransaction = exports.nemGetAddress = exports.getSettings = exports.getPublicKey = exports.getOwnershipProof = exports.getOwnershipId = exports.getFirmwareHash = exports.getFeatures = exports.getDeviceState = exports.getCoinInfo = exports.getAddress = exports.getAccountInfo = exports.firmwareUpdate = exports.ethereumVerifyMessage = exports.ethereumSignTypedData = exports.ethereumSignTransaction = exports.ethereumSignMessage = exports.ethereumGetPublicKey = exports.ethereumGetAddress = exports.eosSignTransaction = exports.eosGetPublicKey = exports.composeTransaction = exports.cipherKeyValue = exports.changePin = exports.cardanoSignTransaction = exports.cardanoGetPublicKey = exports.cardanoGetNativeScriptHash = exports.cardanoGetAddress = exports.blockchainUnsubscribeFiatRates = exports.blockchainUnsubscribe = exports.blockchainSubscribeFiatRates = exports.blockchainSubscribe = exports.blockchainSetCustomBackend = exports.blockchainGetTransactions = exports.blockchainGetFiatRatesForTimestamps = exports.blockchainGetCurrentFiatRates = exports.blockchainGetAccountBalanceHistory = exports.blockchainEstimateFee = exports.blockchainDisconnect = exports.binanceSignTransaction = exports.binanceGetPublicKey = exports.binanceGetAddress = exports.backupDevice = exports.authorizeCoinJoin = exports.applySettings = exports.applyFlags = void 0;
|
|
7
|
-
exports.checkFirmwareAuthenticity = exports.wipeDevice = exports.verifyMessage = exports.unlockPath = exports.tezosSignTransaction = exports.tezosGetPublicKey = exports.tezosGetAddress = exports.stellarSignTransaction = exports.stellarGetAddress = exports.signTransaction = exports.signMessage = exports.setProxy = exports.rippleSignTransaction = exports.rippleGetAddress = exports.resetDevice = void 0;
|
|
7
|
+
exports.checkFirmwareAuthenticity = exports.wipeDevice = exports.verifyMessage = exports.unlockPath = exports.tezosSignTransaction = exports.tezosGetPublicKey = exports.tezosGetAddress = exports.stellarSignTransaction = exports.stellarGetAddress = exports.signTransaction = exports.signMessage = exports.setProxy = exports.setBusy = exports.rippleSignTransaction = exports.rippleGetAddress = exports.resetDevice = void 0;
|
|
8
8
|
var applyFlags_1 = require("./applyFlags");
|
|
9
9
|
Object.defineProperty(exports, "applyFlags", { enumerable: true, get: function () { return __importDefault(applyFlags_1).default; } });
|
|
10
10
|
var applySettings_1 = require("./applySettings");
|
|
@@ -111,6 +111,8 @@ var rippleGetAddress_1 = require("./rippleGetAddress");
|
|
|
111
111
|
Object.defineProperty(exports, "rippleGetAddress", { enumerable: true, get: function () { return __importDefault(rippleGetAddress_1).default; } });
|
|
112
112
|
var rippleSignTransaction_1 = require("./rippleSignTransaction");
|
|
113
113
|
Object.defineProperty(exports, "rippleSignTransaction", { enumerable: true, get: function () { return __importDefault(rippleSignTransaction_1).default; } });
|
|
114
|
+
var setBusy_1 = require("./setBusy");
|
|
115
|
+
Object.defineProperty(exports, "setBusy", { enumerable: true, get: function () { return __importDefault(setBusy_1).default; } });
|
|
114
116
|
var setProxy_1 = require("./setProxy");
|
|
115
117
|
Object.defineProperty(exports, "setProxy", { enumerable: true, get: function () { return __importDefault(setProxy_1).default; } });
|
|
116
118
|
var signMessage_1 = require("./signMessage");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AbstractMethod } from '../core/AbstractMethod';
|
|
2
|
+
import { PROTO } from '../constants';
|
|
3
|
+
export default class SetBusy extends AbstractMethod<'setBusy', PROTO.SetBusy> {
|
|
4
|
+
init(): void;
|
|
5
|
+
run(): Promise<PROTO.Success>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=setBusy.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const AbstractMethod_1 = require("../core/AbstractMethod");
|
|
4
|
+
const paramsValidator_1 = require("./common/paramsValidator");
|
|
5
|
+
class SetBusy extends AbstractMethod_1.AbstractMethod {
|
|
6
|
+
init() {
|
|
7
|
+
this.useDeviceState = false;
|
|
8
|
+
this.requiredPermissions = ['management'];
|
|
9
|
+
this.keepSession = true;
|
|
10
|
+
const { payload } = this;
|
|
11
|
+
(0, paramsValidator_1.validateParams)(payload, [{ name: 'expiry_ms', type: 'number' }]);
|
|
12
|
+
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, {
|
|
13
|
+
1: { min: '0', max: '0' },
|
|
14
|
+
2: { min: '2.5.3', max: '0' },
|
|
15
|
+
});
|
|
16
|
+
this.params = {
|
|
17
|
+
expiry_ms: payload.expiry_ms,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async run() {
|
|
21
|
+
const cmd = this.device.getCommands();
|
|
22
|
+
const { message } = await cmd.typedCall('SetBusy', 'Success', this.params);
|
|
23
|
+
return message;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = SetBusy;
|
|
27
|
+
//# sourceMappingURL=setBusy.js.map
|
|
@@ -6,12 +6,12 @@ declare type Params = {
|
|
|
6
6
|
inputs: PROTO.TxInputType[];
|
|
7
7
|
outputs: PROTO.TxOutputType[];
|
|
8
8
|
paymentRequests: PROTO.TxAckPaymentRequest[];
|
|
9
|
+
coinjoinRequest?: PROTO.CoinJoinRequest;
|
|
9
10
|
refTxs?: RefTransaction[];
|
|
10
11
|
addresses?: AccountAddresses;
|
|
11
12
|
options: TransactionOptions;
|
|
12
13
|
coinInfo: BitcoinNetworkInfo;
|
|
13
14
|
push: boolean;
|
|
14
|
-
preauthorized?: boolean;
|
|
15
15
|
unlockPath?: PROTO.UnlockPath;
|
|
16
16
|
};
|
|
17
17
|
export default class SignTransaction extends AbstractMethod<'signTransaction', Params> {
|
|
@@ -19,6 +19,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
19
19
|
{ name: 'inputs', type: 'array', required: true },
|
|
20
20
|
{ name: 'outputs', type: 'array', required: true },
|
|
21
21
|
{ name: 'paymentRequests', type: 'array', allowEmpty: true },
|
|
22
|
+
{ name: 'coinjoinRequest', type: 'object' },
|
|
22
23
|
{ name: 'refTxs', type: 'array', allowEmpty: true },
|
|
23
24
|
{ name: 'account', type: 'object' },
|
|
24
25
|
{ name: 'locktime', type: 'number' },
|
|
@@ -33,6 +34,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
33
34
|
{ name: 'preauthorized', type: 'boolean' },
|
|
34
35
|
{ name: 'amountUnit', type: ['number', 'string'] },
|
|
35
36
|
{ name: 'unlockPath', type: 'object' },
|
|
37
|
+
{ name: 'serialize', type: 'boolean' },
|
|
36
38
|
]);
|
|
37
39
|
if (payload.unlockPath) {
|
|
38
40
|
(0, paramsValidator_1.validateParams)(payload.unlockPath, [
|
|
@@ -45,6 +47,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
45
47
|
throw constants_1.ERRORS.TypedError('Method_UnknownCoin');
|
|
46
48
|
}
|
|
47
49
|
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, coinInfo, this.firmwareRange);
|
|
50
|
+
this.preauthorized = payload.preauthorized;
|
|
48
51
|
this.info = (0, pathUtils_1.getLabel)('Sign #NETWORK transaction', coinInfo);
|
|
49
52
|
const inputs = (0, bitcoin_1.validateTrezorInputs)(payload.inputs, coinInfo);
|
|
50
53
|
const outputs = (0, bitcoin_1.validateTrezorOutputs)(payload.outputs, coinInfo);
|
|
@@ -73,10 +76,11 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
73
76
|
branch_id: payload.branchId,
|
|
74
77
|
decred_staking_ticket: payload.decredStakingTicket,
|
|
75
78
|
amount_unit: payload.amountUnit,
|
|
79
|
+
serialize: payload.serialize,
|
|
80
|
+
coinjoin_request: payload.coinjoinRequest,
|
|
76
81
|
},
|
|
77
82
|
coinInfo,
|
|
78
83
|
push: typeof payload.push === 'boolean' ? payload.push : false,
|
|
79
|
-
preauthorized: payload.preauthorized,
|
|
80
84
|
unlockPath: payload.unlockPath,
|
|
81
85
|
};
|
|
82
86
|
this.params.options = (0, bitcoin_1.enhanceSignTx)(this.params.options, coinInfo);
|
|
@@ -121,8 +125,8 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
121
125
|
else {
|
|
122
126
|
refTxs = params.refTxs;
|
|
123
127
|
}
|
|
124
|
-
if (
|
|
125
|
-
await device.getCommands().
|
|
128
|
+
if (this.preauthorized) {
|
|
129
|
+
await device.getCommands().preauthorize(true);
|
|
126
130
|
}
|
|
127
131
|
else if (params.unlockPath) {
|
|
128
132
|
await device.getCommands().unlockPath(params.unlockPath);
|
|
@@ -133,6 +137,9 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
133
137
|
refTxs,
|
|
134
138
|
typedCall: device.getCommands().typedCall.bind(device.getCommands()),
|
|
135
139
|
});
|
|
140
|
+
if (!response.serializedTx) {
|
|
141
|
+
return response;
|
|
142
|
+
}
|
|
136
143
|
if (params.options.decred_staking_ticket) {
|
|
137
144
|
await (0, bitcoin_1.verifyTicketTx)(device.getCommands().getHDNode.bind(device.getCommands()), params.inputs, params.outputs, response.serializedTx, params.coinInfo);
|
|
138
145
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Blockchain, BlockchainOptions } from './Blockchain';
|
|
2
|
+
import type { CoinInfo, BlockchainLink } from '../types';
|
|
3
|
+
declare type CoinShortcut = CoinInfo['shortcut'];
|
|
4
|
+
export declare class BackendManager {
|
|
5
|
+
private readonly instances;
|
|
6
|
+
private readonly custom;
|
|
7
|
+
private readonly preferred;
|
|
8
|
+
get(shortcut: CoinShortcut): Blockchain | null;
|
|
9
|
+
remove(shortcut: CoinShortcut): void;
|
|
10
|
+
getOrConnect(coinInfo: CoinInfo, postMessage: BlockchainOptions['postMessage']): Promise<Blockchain>;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
reconnectAll(): Promise<Blockchain[]>;
|
|
13
|
+
isSupported(coinInfo: CoinInfo): void;
|
|
14
|
+
setCustom(shortcut: CoinShortcut, blockchainLink: BlockchainLink): void;
|
|
15
|
+
removeCustom(shortcut: CoinShortcut): void;
|
|
16
|
+
private setPreferred;
|
|
17
|
+
private removePreferred;
|
|
18
|
+
private patchCoinInfo;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=BackendManager.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BackendManager = void 0;
|
|
4
|
+
const config_1 = require("../data/config");
|
|
5
|
+
const DataManager_1 = require("../data/DataManager");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const Blockchain_1 = require("./Blockchain");
|
|
8
|
+
class BackendManager {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.instances = {};
|
|
11
|
+
this.custom = {};
|
|
12
|
+
this.preferred = {};
|
|
13
|
+
}
|
|
14
|
+
get(shortcut) {
|
|
15
|
+
var _a;
|
|
16
|
+
return (_a = this.instances[shortcut]) !== null && _a !== void 0 ? _a : null;
|
|
17
|
+
}
|
|
18
|
+
remove(shortcut) {
|
|
19
|
+
delete this.instances[shortcut];
|
|
20
|
+
}
|
|
21
|
+
async getOrConnect(coinInfo, postMessage) {
|
|
22
|
+
let backend = this.get(coinInfo.shortcut);
|
|
23
|
+
if (!backend) {
|
|
24
|
+
backend = new Blockchain_1.Blockchain({
|
|
25
|
+
coinInfo: this.patchCoinInfo(coinInfo),
|
|
26
|
+
postMessage,
|
|
27
|
+
debug: DataManager_1.DataManager.getSettings('debug'),
|
|
28
|
+
proxy: DataManager_1.DataManager.getSettings('proxy'),
|
|
29
|
+
onionDomains: DataManager_1.DataManager.getSettings('useOnionLinks') && !this.custom[coinInfo.shortcut]
|
|
30
|
+
? config_1.config.onionDomains
|
|
31
|
+
: undefined,
|
|
32
|
+
onConnected: url => this.setPreferred(coinInfo.shortcut, url),
|
|
33
|
+
onDisconnected: () => this.remove(coinInfo.shortcut),
|
|
34
|
+
});
|
|
35
|
+
this.instances[coinInfo.shortcut] = backend;
|
|
36
|
+
try {
|
|
37
|
+
await backend.init();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
this.remove(coinInfo.shortcut);
|
|
41
|
+
this.removePreferred(coinInfo.shortcut);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return backend;
|
|
46
|
+
}
|
|
47
|
+
dispose() {
|
|
48
|
+
Object.values(this.instances).forEach(i => i.disconnect());
|
|
49
|
+
}
|
|
50
|
+
reconnectAll() {
|
|
51
|
+
const params = Object.values(this.instances).map(i => [i.coinInfo, i.postMessage]);
|
|
52
|
+
Object.values(this.instances).forEach(i => i.disconnect());
|
|
53
|
+
return Promise.all(params.map(p => this.getOrConnect(...p)));
|
|
54
|
+
}
|
|
55
|
+
isSupported(coinInfo) {
|
|
56
|
+
const info = this.custom[coinInfo.shortcut] || coinInfo.blockchainLink;
|
|
57
|
+
if (!info) {
|
|
58
|
+
throw constants_1.ERRORS.TypedError('Backend_NotSupported');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
setCustom(shortcut, blockchainLink) {
|
|
62
|
+
this.removePreferred(shortcut);
|
|
63
|
+
this.custom[shortcut] = blockchainLink;
|
|
64
|
+
}
|
|
65
|
+
removeCustom(shortcut) {
|
|
66
|
+
this.removePreferred(shortcut);
|
|
67
|
+
delete this.custom[shortcut];
|
|
68
|
+
}
|
|
69
|
+
setPreferred(shortcut, url) {
|
|
70
|
+
this.preferred[shortcut] = url;
|
|
71
|
+
}
|
|
72
|
+
removePreferred(shortcut) {
|
|
73
|
+
delete this.preferred[shortcut];
|
|
74
|
+
}
|
|
75
|
+
patchCoinInfo(coinInfo) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const custom = this.custom[coinInfo.shortcut];
|
|
78
|
+
const preferred = this.preferred[coinInfo.shortcut];
|
|
79
|
+
const url = preferred ? [preferred] : (_a = custom === null || custom === void 0 ? void 0 : custom.url) !== null && _a !== void 0 ? _a : (_b = coinInfo.blockchainLink) === null || _b === void 0 ? void 0 : _b.url;
|
|
80
|
+
return {
|
|
81
|
+
...coinInfo,
|
|
82
|
+
blockchainLink: {
|
|
83
|
+
...coinInfo.blockchainLink,
|
|
84
|
+
...custom,
|
|
85
|
+
url,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.BackendManager = BackendManager;
|
|
91
|
+
//# sourceMappingURL=BackendManager.js.map
|