@trezor/connect 9.4.8-beta.1 → 9.5.0-beta.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.
- package/CHANGELOG.md +33 -6
- package/README.md +1 -1
- package/lib/api/authorizeCoinjoin.js +1 -1
- package/lib/api/binance/api/binanceGetAddress.js +2 -4
- package/lib/api/binance/api/binanceGetPublicKey.js +1 -0
- package/lib/api/binance/api/binanceSignTransaction.js +1 -2
- package/lib/api/bitcoin/Fees.js +4 -1
- package/lib/api/bitcoin/TransactionComposer.js +9 -2
- package/lib/api/bitcoin/enhanceSignTx.js +1 -2
- package/lib/api/bitcoin/refTx.js +4 -6
- package/lib/api/blockchainDisconnect.js +1 -1
- package/lib/api/blockchainSubscribe.js +1 -2
- package/lib/api/blockchainUnsubscribe.js +1 -2
- package/lib/api/cardano/api/cardanoComposeTransaction.js +1 -1
- package/lib/api/cardano/api/cardanoGetAddress.js +2 -4
- package/lib/api/cardano/api/cardanoGetPublicKey.js +1 -0
- package/lib/api/cardano/cardanoAuxiliaryData.js +2 -2
- package/lib/api/cardano/cardanoUtils.js +5 -6
- package/lib/api/cipherKeyValue.js +1 -0
- package/lib/api/common/Discovery.js +16 -1
- package/lib/api/common/paramsValidator.js +2 -2
- package/lib/api/composeTransaction.js +6 -6
- package/lib/api/eos/api/eosGetPublicKey.js +1 -0
- package/lib/api/ethereum/api/ethereumGetAddress.js +2 -4
- package/lib/api/ethereum/api/ethereumGetPublicKey.js +1 -0
- package/lib/api/ethereum/api/ethereumSignMessage.js +1 -2
- package/lib/api/ethereum/api/ethereumSignTransaction.js +1 -1
- package/lib/api/ethereum/api/ethereumSignTypedData.js +1 -1
- package/lib/api/ethereum/ethereumDefinitions.js +2 -2
- package/lib/api/ethereum/ethereumSignTx.d.ts +2 -2
- package/lib/api/ethereum/ethereumSignTx.js +3 -2
- package/lib/api/firmware/verifyAuthenticityProof.js +3 -3
- package/lib/api/getAccountDescriptor.js +2 -4
- package/lib/api/getAccountInfo.js +4 -5
- package/lib/api/getAddress.js +5 -8
- package/lib/api/getDeviceState.js +1 -1
- package/lib/api/getOwnershipId.js +1 -0
- package/lib/api/getOwnershipProof.js +1 -0
- package/lib/api/getPublicKey.js +3 -2
- package/lib/api/nem/api/nemGetAddress.js +2 -4
- package/lib/api/nem/api/nemSignTransaction.js +1 -2
- package/lib/api/requestLogin.js +1 -0
- package/lib/api/ripple/api/rippleGetAddress.js +2 -4
- package/lib/api/signMessage.js +1 -2
- package/lib/api/signTransaction.js +6 -8
- package/lib/api/solana/additionalInfo.js +2 -3
- package/lib/api/solana/api/solanaComposeTransaction.js +2 -3
- package/lib/api/solana/api/solanaGetAddress.js +2 -4
- package/lib/api/solana/api/solanaGetPublicKey.js +1 -0
- package/lib/api/solana/solanaUtils.js +6 -5
- package/lib/api/stellar/api/stellarGetAddress.js +2 -4
- package/lib/api/tezos/api/tezosGetAddress.js +2 -4
- package/lib/api/tezos/api/tezosGetPublicKey.js +1 -0
- package/lib/backend/BackendManager.js +11 -16
- package/lib/backend/Blockchain.js +10 -4
- package/lib/backend/BlockchainLink.js +1 -1
- package/lib/constants/errors.js +2 -0
- package/lib/core/AbstractMethod.js +30 -5
- package/lib/core/index.js +24 -34
- package/lib/core/onCallFirmwareUpdate.d.ts +3 -2
- package/lib/core/onCallFirmwareUpdate.js +12 -59
- package/lib/data/DataManager.js +3 -2
- package/lib/data/analyticsInfo.js +10 -11
- package/lib/data/connectSettings.js +1 -2
- package/lib/data/defaultFeeLevels.js +4 -7
- package/lib/data/deviceAuthenticityConfig.js +16 -1
- package/lib/data/firmwareInfo.js +5 -6
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +10 -2
- package/lib/device/Device.js +73 -56
- package/lib/device/DeviceCommands.d.ts +5 -1
- package/lib/device/DeviceCommands.js +7 -2
- package/lib/device/DeviceList.d.ts +2 -0
- package/lib/device/DeviceList.js +44 -24
- package/lib/device/StateStorage.js +5 -6
- package/lib/device/checkFirmwareRevision.js +11 -6
- package/lib/device/prompts.js +4 -7
- package/lib/events/call.d.ts +1 -0
- package/lib/events/call.js +3 -3
- package/lib/impl/core-in-module.js +25 -23
- package/lib/impl/dynamic.js +7 -1
- package/lib/index.js +9 -12
- package/lib/types/api/ethereum/index.d.ts +4 -4
- package/lib/types/api/ethereum/index.js +2 -2
- package/lib/types/api/firmwareUpdate.d.ts +1 -8
- package/lib/utils/assets.js +1 -1
- package/lib/utils/assets.native.js +1 -1
- package/lib/utils/hdnodeUtils.js +1 -2
- package/lib/utils/interactionTimeout.js +2 -2
- package/lib/utils/popupPromiseManager.js +2 -2
- package/lib/utils/proxy-event-emitter.js +1 -0
- package/lib/utils/uiPromiseManager.js +3 -4
- package/lib/utils/urlUtils.js +5 -8
- package/package.json +12 -12
- package/lib/utils/abortablePromise.d.ts +0 -5
- package/lib/utils/abortablePromise.js +0 -17
|
@@ -11,10 +11,8 @@ const getAccountDescriptor_1 = require("../types/api/getAccountDescriptor");
|
|
|
11
11
|
const accountUtils_1 = require("../utils/accountUtils");
|
|
12
12
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
13
13
|
class GetAccountDescriptor extends AbstractMethod_1.AbstractMethod {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.disposed = false;
|
|
17
|
-
}
|
|
14
|
+
disposed = false;
|
|
15
|
+
hasBundle;
|
|
18
16
|
init() {
|
|
19
17
|
this.requiredPermissions = ['read'];
|
|
20
18
|
this.useDevice = true;
|
|
@@ -11,10 +11,9 @@ const paramsValidator_1 = require("./common/paramsValidator");
|
|
|
11
11
|
const accountUtils_1 = require("../utils/accountUtils");
|
|
12
12
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
13
13
|
class GetAccountInfo extends AbstractMethod_1.AbstractMethod {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
14
|
+
disposed = false;
|
|
15
|
+
hasBundle;
|
|
16
|
+
discovery;
|
|
18
17
|
init() {
|
|
19
18
|
this.requiredPermissions = ['read'];
|
|
20
19
|
this.useDevice = true;
|
|
@@ -283,7 +282,7 @@ class GetAccountInfo extends AbstractMethod_1.AbstractMethod {
|
|
|
283
282
|
discovery.stop();
|
|
284
283
|
const account = discovery.accounts[uiResp.payload];
|
|
285
284
|
if (!discovery.completed) {
|
|
286
|
-
await (0, resolveAfter_1.resolveAfter)(501)
|
|
285
|
+
await (0, resolveAfter_1.resolveAfter)(501);
|
|
287
286
|
}
|
|
288
287
|
const info = await blockchain.getAccountInfo({
|
|
289
288
|
descriptor: account.descriptor,
|
package/lib/api/getAddress.js
CHANGED
|
@@ -10,10 +10,8 @@ const types_1 = require("../types");
|
|
|
10
10
|
const getAddress_1 = require("../types/api/getAddress");
|
|
11
11
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
12
12
|
class GetAddress extends AbstractMethod_1.AbstractMethod {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.progress = 0;
|
|
16
|
-
}
|
|
13
|
+
hasBundle;
|
|
14
|
+
progress = 0;
|
|
17
15
|
init() {
|
|
18
16
|
this.noBackupConfirmationMode = 'always';
|
|
19
17
|
this.requiredPermissions = ['read'];
|
|
@@ -21,10 +19,9 @@ class GetAddress extends AbstractMethod_1.AbstractMethod {
|
|
|
21
19
|
const payload = !this.payload.bundle
|
|
22
20
|
? { ...this.payload, bundle: [this.payload] }
|
|
23
21
|
: this.payload;
|
|
24
|
-
payload
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
bundleElement.multisig.signatures = Array((_b = bundleElement.multisig) === null || _b === void 0 ? void 0 : _b.pubkeys.length).fill('');
|
|
22
|
+
payload?.bundle.forEach(bundleElement => {
|
|
23
|
+
if (bundleElement.multisig && bundleElement.multisig?.signatures === undefined) {
|
|
24
|
+
bundleElement.multisig.signatures = Array(bundleElement.multisig?.pubkeys.length).fill('');
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
27
|
(0, schema_utils_1.Assert)((0, types_1.Bundle)(getAddress_1.GetAddress), payload);
|
|
@@ -8,7 +8,7 @@ class GetDeviceState extends AbstractMethod_1.AbstractMethod {
|
|
|
8
8
|
}
|
|
9
9
|
run() {
|
|
10
10
|
const state = this.device.getState();
|
|
11
|
-
if (!
|
|
11
|
+
if (!state?.staticSessionId) {
|
|
12
12
|
throw constants_1.ERRORS.TypedError('Runtime', 'Device state not set');
|
|
13
13
|
}
|
|
14
14
|
return Promise.resolve({ state: state.staticSessionId, _state: state });
|
|
@@ -9,6 +9,7 @@ const exports_1 = require("../exports");
|
|
|
9
9
|
const getOwnershipId_1 = require("../types/api/getOwnershipId");
|
|
10
10
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
11
11
|
class GetOwnershipId extends AbstractMethod_1.AbstractMethod {
|
|
12
|
+
hasBundle;
|
|
12
13
|
init() {
|
|
13
14
|
this.requiredPermissions = ['read'];
|
|
14
15
|
this.hasBundle = !!this.payload.bundle;
|
|
@@ -9,6 +9,7 @@ const exports_1 = require("../exports");
|
|
|
9
9
|
const getOwnershipProof_1 = require("../types/api/getOwnershipProof");
|
|
10
10
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
11
11
|
class GetOwnershipProof extends AbstractMethod_1.AbstractMethod {
|
|
12
|
+
hasBundle;
|
|
12
13
|
init() {
|
|
13
14
|
this.requiredPermissions = ['read'];
|
|
14
15
|
this.hasBundle = !!this.payload.bundle;
|
package/lib/api/getPublicKey.js
CHANGED
|
@@ -10,6 +10,7 @@ const getPublicKey_1 = require("../types/api/getPublicKey");
|
|
|
10
10
|
const accountUtils_1 = require("../utils/accountUtils");
|
|
11
11
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
12
12
|
class GetPublicKey extends AbstractMethod_1.AbstractMethod {
|
|
13
|
+
hasBundle;
|
|
13
14
|
init() {
|
|
14
15
|
this.requiredPermissions = ['read'];
|
|
15
16
|
this.hasBundle = !!this.payload.bundle;
|
|
@@ -32,7 +33,7 @@ class GetPublicKey extends AbstractMethod_1.AbstractMethod {
|
|
|
32
33
|
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, coinInfo, this.firmwareRange);
|
|
33
34
|
return {
|
|
34
35
|
address_n,
|
|
35
|
-
coin_name: coinInfo
|
|
36
|
+
coin_name: coinInfo?.name,
|
|
36
37
|
show_display: batch.showOnTrezor,
|
|
37
38
|
script_type: batch.scriptType,
|
|
38
39
|
ignore_xpub_magic: batch.ignoreXpubMagic,
|
|
@@ -62,7 +63,7 @@ class GetPublicKey extends AbstractMethod_1.AbstractMethod {
|
|
|
62
63
|
const cmd = this.device.getCommands();
|
|
63
64
|
for (let i = 0; i < this.params.length; i++) {
|
|
64
65
|
const { coinInfo, unlockPath, ...batch } = this.params[i];
|
|
65
|
-
const coinInfoFallback = coinInfo
|
|
66
|
+
const coinInfoFallback = coinInfo ?? (0, coinInfo_1.getBitcoinNetwork)('btc');
|
|
66
67
|
const response = await cmd.getHDNode(batch, { coinInfo: coinInfoFallback, unlockPath });
|
|
67
68
|
responses.push(response);
|
|
68
69
|
if (this.hasBundle) {
|
|
@@ -13,10 +13,8 @@ const MAINNET = 0x68;
|
|
|
13
13
|
const TESTNET = 0x98;
|
|
14
14
|
const MIJIN = 0x60;
|
|
15
15
|
class NEMGetAddress extends AbstractMethod_1.AbstractMethod {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.progress = 0;
|
|
19
|
-
}
|
|
16
|
+
hasBundle;
|
|
17
|
+
progress = 0;
|
|
20
18
|
init() {
|
|
21
19
|
this.noBackupConfirmationMode = 'always';
|
|
22
20
|
this.requiredPermissions = ['read'];
|
|
@@ -10,12 +10,11 @@ const paramsValidator_1 = require("../../common/paramsValidator");
|
|
|
10
10
|
const helper = tslib_1.__importStar(require("../nemSignTx"));
|
|
11
11
|
class NEMSignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
12
12
|
init() {
|
|
13
|
-
var _a;
|
|
14
13
|
this.requiredPermissions = ['read', 'write'];
|
|
15
14
|
this.requiredDeviceCapabilities = ['Capability_NEM'];
|
|
16
15
|
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, (0, coinInfo_1.getMiscNetwork)('NEM'), this.firmwareRange);
|
|
17
16
|
const { payload } = this;
|
|
18
|
-
if (
|
|
17
|
+
if (payload?.transaction?.timestamp) {
|
|
19
18
|
payload.transaction.timeStamp = payload.transaction.timestamp;
|
|
20
19
|
}
|
|
21
20
|
(0, schema_utils_1.AssertWeak)(nem_1.NEMSignTransaction, payload);
|
package/lib/api/requestLogin.js
CHANGED
|
@@ -8,6 +8,7 @@ const paramsValidator_1 = require("./common/paramsValidator");
|
|
|
8
8
|
const DataManager_1 = require("../data/DataManager");
|
|
9
9
|
const requestLogin_1 = require("../types/api/requestLogin");
|
|
10
10
|
class RequestLogin extends AbstractMethod_1.AbstractMethod {
|
|
11
|
+
asyncChallenge;
|
|
11
12
|
init() {
|
|
12
13
|
this.requiredPermissions = ['read', 'write'];
|
|
13
14
|
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, this.firmwareRange);
|
|
@@ -10,10 +10,8 @@ const getAddress_1 = require("../../../types/api/getAddress");
|
|
|
10
10
|
const pathUtils_1 = require("../../../utils/pathUtils");
|
|
11
11
|
const paramsValidator_1 = require("../../common/paramsValidator");
|
|
12
12
|
class RippleGetAddress extends AbstractMethod_1.AbstractMethod {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.progress = 0;
|
|
16
|
-
}
|
|
13
|
+
hasBundle;
|
|
14
|
+
progress = 0;
|
|
17
15
|
init() {
|
|
18
16
|
this.noBackupConfirmationMode = 'always';
|
|
19
17
|
this.requiredPermissions = ['read'];
|
package/lib/api/signMessage.js
CHANGED
|
@@ -35,8 +35,7 @@ class SignMessage extends AbstractMethod_1.AbstractMethod {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
get info() {
|
|
38
|
-
|
|
39
|
-
const coinInfo = (0, coinInfo_1.getBitcoinNetwork)((_a = this.payload.coin) !== null && _a !== void 0 ? _a : this.params.address_n);
|
|
38
|
+
const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(this.payload.coin ?? this.params.address_n);
|
|
40
39
|
return (0, pathUtils_1.getLabel)('Sign #NETWORK message', coinInfo);
|
|
41
40
|
}
|
|
42
41
|
async run() {
|
|
@@ -10,7 +10,6 @@ const coinInfo_1 = require("../data/coinInfo");
|
|
|
10
10
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
11
11
|
class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
12
12
|
init() {
|
|
13
|
-
var _a, _b, _c;
|
|
14
13
|
this.requiredPermissions = ['read', 'write'];
|
|
15
14
|
const { payload } = this;
|
|
16
15
|
(0, paramsValidator_1.validateParams)(payload, [
|
|
@@ -51,15 +50,15 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
51
50
|
this.preauthorized = payload.preauthorized;
|
|
52
51
|
const inputs = (0, bitcoin_1.validateTrezorInputs)(payload.inputs, coinInfo);
|
|
53
52
|
const outputs = (0, bitcoin_1.validateTrezorOutputs)(payload.outputs, coinInfo);
|
|
54
|
-
if (payload.refTxs &&
|
|
53
|
+
if (payload.refTxs && payload.account?.transactions) {
|
|
55
54
|
console.warn('two sources of referential transactions were passed. payload.refTxs have precedence');
|
|
56
55
|
}
|
|
57
56
|
const refTxs = (0, bitcoin_1.validateReferencedTransactions)({
|
|
58
|
-
transactions: payload.refTxs ||
|
|
57
|
+
transactions: payload.refTxs || payload.account?.transactions,
|
|
59
58
|
inputs,
|
|
60
59
|
outputs,
|
|
61
60
|
coinInfo,
|
|
62
|
-
addresses:
|
|
61
|
+
addresses: payload.account?.addresses,
|
|
63
62
|
});
|
|
64
63
|
const outputsWithAmount = outputs.filter(output => typeof output.amount === 'string' &&
|
|
65
64
|
!Object.prototype.hasOwnProperty.call(output, 'op_return_data'));
|
|
@@ -142,7 +141,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
142
141
|
.getTransactionHexes(origTxsIds)
|
|
143
142
|
.then((0, bitcoin_1.parseTransactionHexes)(coinInfo.network))
|
|
144
143
|
.then(async (rawOrigTxs) => {
|
|
145
|
-
const accountAddresses = addresses
|
|
144
|
+
const accountAddresses = addresses ?? (await this.fetchAddresses(blockchain));
|
|
146
145
|
if (!accountAddresses)
|
|
147
146
|
return [];
|
|
148
147
|
return (0, bitcoin_1.transformOrigTransactions)(rawOrigTxs, coinInfo, inputs, accountAddresses);
|
|
@@ -150,10 +149,9 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
150
149
|
return refTxs.concat(origTxs);
|
|
151
150
|
}
|
|
152
151
|
async run() {
|
|
153
|
-
var _a;
|
|
154
152
|
const { device, params } = this;
|
|
155
153
|
const useLegacySignProcess = !!device.unavailableCapabilities.replaceTransaction;
|
|
156
|
-
const refTxs =
|
|
154
|
+
const refTxs = params.refTxs ?? (await this.fetchRefTxs(useLegacySignProcess));
|
|
157
155
|
if (this.preauthorized) {
|
|
158
156
|
await device.getCommands().preauthorize(true);
|
|
159
157
|
}
|
|
@@ -176,7 +174,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
176
174
|
else {
|
|
177
175
|
bitcoinTx = await (0, bitcoin_1.verifyTx)(device.getCommands().getHDNode.bind(device.getCommands()), params.inputs, params.outputs, response.serializedTx, params.coinInfo, params.unlockPath);
|
|
178
176
|
if (bitcoinTx.hasWitnesses()) {
|
|
179
|
-
response.witnesses = bitcoinTx.ins.map((_, i) =>
|
|
177
|
+
response.witnesses = bitcoinTx.ins.map((_, i) => bitcoinTx?.getWitness(i)?.toString('hex'));
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
if (bitcoinTx && params.addresses) {
|
|
@@ -4,18 +4,17 @@ exports.transformAdditionalInfo = void 0;
|
|
|
4
4
|
const schema_utils_1 = require("@trezor/schema-utils");
|
|
5
5
|
const solana_1 = require("../../types/api/solana");
|
|
6
6
|
const transformAdditionalInfo = (additionalInfo) => {
|
|
7
|
-
var _a;
|
|
8
7
|
if (!additionalInfo) {
|
|
9
8
|
return undefined;
|
|
10
9
|
}
|
|
11
10
|
(0, schema_utils_1.Assert)(solana_1.SolanaTxAdditionalInfo, additionalInfo);
|
|
12
11
|
return {
|
|
13
|
-
token_accounts_infos:
|
|
12
|
+
token_accounts_infos: additionalInfo.tokenAccountsInfos?.map(tokenAccountInfo => ({
|
|
14
13
|
base_address: tokenAccountInfo.baseAddress,
|
|
15
14
|
token_program: tokenAccountInfo.tokenProgram,
|
|
16
15
|
token_mint: tokenAccountInfo.tokenMint,
|
|
17
16
|
token_account: tokenAccountInfo.tokenAccount,
|
|
18
|
-
}))
|
|
17
|
+
})) || [],
|
|
19
18
|
};
|
|
20
19
|
};
|
|
21
20
|
exports.transformAdditionalInfo = transformAdditionalInfo;
|
|
@@ -28,7 +28,6 @@ class SolanaComposeTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
28
28
|
return 'Compose Solana transaction';
|
|
29
29
|
}
|
|
30
30
|
async run() {
|
|
31
|
-
var _a;
|
|
32
31
|
const backend = await (0, BlockchainLink_1.initBlockchain)(this.params.coinInfo, this.postMessage, this.params.identity);
|
|
33
32
|
const [recipientAccountOwner, recipientTokenAccounts] = this.params.token
|
|
34
33
|
? await (0, solanaUtils_1.fetchAccountOwnerAndTokenInfoForAddress)(backend, this.params.toAddress, this.params.token.mint, this.params.token.program)
|
|
@@ -45,14 +44,14 @@ class SolanaComposeTransaction extends AbstractMethod_1.AbstractMethod {
|
|
|
45
44
|
recipientTokenAccounts === undefined &&
|
|
46
45
|
(recipientAccountOwner === solana_1.SYSTEM_PROGRAM_PUBLIC_KEY || recipientAccountOwner == null);
|
|
47
46
|
const newTokenAccountProgramName = isCreatingAccount
|
|
48
|
-
?
|
|
47
|
+
? this.params.token?.program
|
|
49
48
|
: undefined;
|
|
50
49
|
return {
|
|
51
50
|
serializedTx: tx.serialize(),
|
|
52
51
|
additionalInfo: {
|
|
53
52
|
isCreatingAccount: !!isCreatingAccount,
|
|
54
53
|
newTokenAccountProgramName,
|
|
55
|
-
tokenAccountInfo: tokenTransferTxAndDestinationAddress
|
|
54
|
+
tokenAccountInfo: tokenTransferTxAndDestinationAddress?.tokenAccountInfo,
|
|
56
55
|
},
|
|
57
56
|
};
|
|
58
57
|
}
|
|
@@ -10,10 +10,8 @@ const getAddress_1 = require("../../../types/api/getAddress");
|
|
|
10
10
|
const pathUtils_1 = require("../../../utils/pathUtils");
|
|
11
11
|
const paramsValidator_1 = require("../../common/paramsValidator");
|
|
12
12
|
class SolanaGetAddress extends AbstractMethod_1.AbstractMethod {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.progress = 0;
|
|
16
|
-
}
|
|
13
|
+
hasBundle;
|
|
14
|
+
progress = 0;
|
|
17
15
|
init() {
|
|
18
16
|
this.noBackupConfirmationMode = 'always';
|
|
19
17
|
this.requiredPermissions = ['read'];
|
|
@@ -8,6 +8,7 @@ const types_1 = require("../../../types");
|
|
|
8
8
|
const pathUtils_1 = require("../../../utils/pathUtils");
|
|
9
9
|
const paramsValidator_1 = require("../../common/paramsValidator");
|
|
10
10
|
class SolanaGetPublicKey extends AbstractMethod_1.AbstractMethod {
|
|
11
|
+
hasBundle;
|
|
11
12
|
init() {
|
|
12
13
|
this.noBackupConfirmationMode = 'always';
|
|
13
14
|
this.requiredPermissions = ['read'];
|
|
@@ -98,7 +98,7 @@ const buildTransferTransaction = async (fromAddress, toAddress, amountInSol, blo
|
|
|
98
98
|
const [{ address, appendTransactionMessageInstruction, createTransactionMessage, lamports, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageFeePayer, createNoopSigner, }, { getTransferSolInstruction },] = await Promise.all([loadSolanaLib(), loadSolanaSystemProgramLib()]);
|
|
99
99
|
const message = await (0, ts_belt_1.pipe)(createTransactionMessage({ version: 'legacy' }), m => setTransactionMessageFeePayer(address(fromAddress), m), m => setTransactionMessageLifetimeUsingBlockhash({
|
|
100
100
|
blockhash: blockhash,
|
|
101
|
-
lastValidBlockHeight: BigInt(lastValidBlockHeight
|
|
101
|
+
lastValidBlockHeight: BigInt(lastValidBlockHeight ?? '0xFFFFFFFFFFFFFFFF'),
|
|
102
102
|
}, m), m => appendTransactionMessageInstruction(getTransferSolInstruction({
|
|
103
103
|
amount: lamports((0, exports.getLamportsFromSol)(amountInSol)),
|
|
104
104
|
destination: address(toAddress),
|
|
@@ -156,7 +156,7 @@ const buildTokenTransferTransaction = async (fromAddress, toAddress, toAddressOw
|
|
|
156
156
|
const { address, appendTransactionMessageInstruction, appendTransactionMessageInstructions, createTransactionMessage, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, } = await loadSolanaLib();
|
|
157
157
|
let message = await (0, ts_belt_1.pipe)(createTransactionMessage({ version: 'legacy' }), m => setTransactionMessageFeePayer(address(fromAddress), m), m => setTransactionMessageLifetimeUsingBlockhash({
|
|
158
158
|
blockhash: blockhash,
|
|
159
|
-
lastValidBlockHeight: BigInt(lastValidBlockHeight
|
|
159
|
+
lastValidBlockHeight: BigInt(lastValidBlockHeight ?? '0xFFFFFFFFFFFFFFFF'),
|
|
160
160
|
}, m), m => addPriorityFees(m, priorityFees));
|
|
161
161
|
const tokenAmount = new bigNumber_1.BigNumber(tokenUiAmount).times(10 ** tokenDecimals);
|
|
162
162
|
const requiredAccounts = (0, exports.getMinimumRequiredTokenAccountsForTransfer)(fromTokenAccounts, tokenAmount.toString());
|
|
@@ -195,7 +195,6 @@ const buildTokenTransferTransaction = async (fromAddress, toAddress, toAddressOw
|
|
|
195
195
|
};
|
|
196
196
|
exports.buildTokenTransferTransaction = buildTokenTransferTransaction;
|
|
197
197
|
const fetchAccountOwnerAndTokenInfoForAddress = async (blockchain, address, mint, tokenProgram) => {
|
|
198
|
-
var _a, _b, _c, _d;
|
|
199
198
|
let accountOwner;
|
|
200
199
|
let tokenInfo;
|
|
201
200
|
const accountInfoResponse = await blockchain.getAccountInfo({
|
|
@@ -204,8 +203,10 @@ const fetchAccountOwnerAndTokenInfoForAddress = async (blockchain, address, mint
|
|
|
204
203
|
});
|
|
205
204
|
if (accountInfoResponse) {
|
|
206
205
|
const associatedTokenAccount = await (0, exports.getAssociatedTokenAccountAddress)(address, mint, tokenProgram);
|
|
207
|
-
accountOwner =
|
|
208
|
-
tokenInfo =
|
|
206
|
+
accountOwner = accountInfoResponse?.misc?.owner;
|
|
207
|
+
tokenInfo = accountInfoResponse?.tokens
|
|
208
|
+
?.find(token => token.contract === mint)
|
|
209
|
+
?.accounts?.find(account => associatedTokenAccount.toString() === account.publicKey);
|
|
209
210
|
}
|
|
210
211
|
return [accountOwner, tokenInfo];
|
|
211
212
|
};
|
|
@@ -10,10 +10,8 @@ const getAddress_1 = require("../../../types/api/getAddress");
|
|
|
10
10
|
const pathUtils_1 = require("../../../utils/pathUtils");
|
|
11
11
|
const paramsValidator_1 = require("../../common/paramsValidator");
|
|
12
12
|
class StellarGetAddress extends AbstractMethod_1.AbstractMethod {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.progress = 0;
|
|
16
|
-
}
|
|
13
|
+
hasBundle;
|
|
14
|
+
progress = 0;
|
|
17
15
|
init() {
|
|
18
16
|
this.noBackupConfirmationMode = 'always';
|
|
19
17
|
this.requiredPermissions = ['read'];
|
|
@@ -10,10 +10,8 @@ const getAddress_1 = require("../../../types/api/getAddress");
|
|
|
10
10
|
const pathUtils_1 = require("../../../utils/pathUtils");
|
|
11
11
|
const paramsValidator_1 = require("../../common/paramsValidator");
|
|
12
12
|
class TezosGetAddress extends AbstractMethod_1.AbstractMethod {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.progress = 0;
|
|
16
|
-
}
|
|
13
|
+
hasBundle;
|
|
14
|
+
progress = 0;
|
|
17
15
|
init() {
|
|
18
16
|
this.noBackupConfirmationMode = 'always';
|
|
19
17
|
this.requiredPermissions = ['read'];
|
|
@@ -8,6 +8,7 @@ const types_1 = require("../../../types");
|
|
|
8
8
|
const pathUtils_1 = require("../../../utils/pathUtils");
|
|
9
9
|
const paramsValidator_1 = require("../../common/paramsValidator");
|
|
10
10
|
class TezosGetPublicKey extends AbstractMethod_1.AbstractMethod {
|
|
11
|
+
hasBundle;
|
|
11
12
|
init() {
|
|
12
13
|
this.requiredPermissions = ['read'];
|
|
13
14
|
this.requiredDeviceCapabilities = ['Capability_Tezos'];
|
|
@@ -7,18 +7,15 @@ const DataManager_1 = require("../data/DataManager");
|
|
|
7
7
|
const events_1 = require("../events");
|
|
8
8
|
const DEFAULT_IDENTITY = 'default';
|
|
9
9
|
class BackendManager {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.preferred = {};
|
|
15
|
-
}
|
|
10
|
+
instances = {};
|
|
11
|
+
reconnect = {};
|
|
12
|
+
custom = {};
|
|
13
|
+
preferred = {};
|
|
16
14
|
get(shortcut, identity = DEFAULT_IDENTITY) {
|
|
17
|
-
|
|
18
|
-
return (_a = this.instances[`${shortcut}/${identity}`]) !== null && _a !== void 0 ? _a : null;
|
|
15
|
+
return this.instances[`${shortcut}/${identity}`] ?? null;
|
|
19
16
|
}
|
|
20
17
|
async getOrConnect({ coinInfo, postMessage, identity }) {
|
|
21
|
-
const coinIdentity = `${coinInfo.shortcut}/${identity
|
|
18
|
+
const coinIdentity = `${coinInfo.shortcut}/${identity ?? DEFAULT_IDENTITY}`;
|
|
22
19
|
let backend = this.instances[coinIdentity];
|
|
23
20
|
if (!backend) {
|
|
24
21
|
backend = new Blockchain_1.Blockchain({
|
|
@@ -41,7 +38,7 @@ class BackendManager {
|
|
|
41
38
|
return backend;
|
|
42
39
|
}
|
|
43
40
|
catch (error) {
|
|
44
|
-
this.onDisconnect({ coinInfo, postMessage, identity }, reconnect
|
|
41
|
+
this.onDisconnect({ coinInfo, postMessage, identity }, reconnect?.attempts);
|
|
45
42
|
throw error;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
@@ -84,8 +81,7 @@ class BackendManager {
|
|
|
84
81
|
this.preferred[shortcut] = url;
|
|
85
82
|
}
|
|
86
83
|
onDisconnect({ coinInfo, postMessage, identity }, reconnectAttempt) {
|
|
87
|
-
|
|
88
|
-
const coinIdentity = `${coinInfo.shortcut}/${identity !== null && identity !== void 0 ? identity : DEFAULT_IDENTITY}`;
|
|
84
|
+
const coinIdentity = `${coinInfo.shortcut}/${identity ?? DEFAULT_IDENTITY}`;
|
|
89
85
|
this.setInstance(coinIdentity, undefined);
|
|
90
86
|
if (reconnectAttempt === undefined || reconnectAttempt === 4) {
|
|
91
87
|
this.setPreferred(coinInfo.shortcut, undefined);
|
|
@@ -98,21 +94,20 @@ class BackendManager {
|
|
|
98
94
|
const handle = setTimeout(() => {
|
|
99
95
|
this.getOrConnect({ coinInfo, postMessage, identity }).catch(() => { });
|
|
100
96
|
}, timeout);
|
|
101
|
-
clearTimeout(
|
|
97
|
+
clearTimeout(this.reconnect[coinIdentity]?.handle);
|
|
102
98
|
this.reconnect[coinIdentity] = { attempts: reconnectAttempt + 1, handle };
|
|
103
99
|
postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.RECONNECTING, { coin: coinInfo, identity, time }));
|
|
104
100
|
}
|
|
105
101
|
clearReconnect(coinIdentity) {
|
|
106
102
|
const reconnect = this.reconnect[coinIdentity];
|
|
107
|
-
clearTimeout(reconnect
|
|
103
|
+
clearTimeout(reconnect?.handle);
|
|
108
104
|
delete this.reconnect[coinIdentity];
|
|
109
105
|
return reconnect;
|
|
110
106
|
}
|
|
111
107
|
patchCoinInfo(coinInfo) {
|
|
112
|
-
var _a, _b;
|
|
113
108
|
const custom = this.custom[coinInfo.shortcut];
|
|
114
109
|
const preferred = this.preferred[coinInfo.shortcut];
|
|
115
|
-
const url = preferred ? [preferred] :
|
|
110
|
+
const url = preferred ? [preferred] : custom?.url ?? coinInfo.blockchainLink?.url;
|
|
116
111
|
return {
|
|
117
112
|
...coinInfo,
|
|
118
113
|
blockchainLink: {
|
|
@@ -29,9 +29,16 @@ const getNormalizedTrezorShortcut = (shortcut) => {
|
|
|
29
29
|
return shortcut;
|
|
30
30
|
};
|
|
31
31
|
class Blockchain {
|
|
32
|
+
link;
|
|
33
|
+
serverInfo;
|
|
34
|
+
identity;
|
|
35
|
+
coinInfo;
|
|
36
|
+
postMessage;
|
|
37
|
+
feeForBlock = [];
|
|
38
|
+
feeTimestamp = 0;
|
|
39
|
+
onDisconnected;
|
|
40
|
+
initPromise;
|
|
32
41
|
constructor(options) {
|
|
33
|
-
this.feeForBlock = [];
|
|
34
|
-
this.feeTimestamp = 0;
|
|
35
42
|
this.identity = options.identity;
|
|
36
43
|
this.coinInfo = options.coinInfo;
|
|
37
44
|
this.postMessage = options.postMessage;
|
|
@@ -55,7 +62,6 @@ class Blockchain {
|
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
64
|
onError(error) {
|
|
58
|
-
var _a;
|
|
59
65
|
const pendingSubscriptions = this.link.listenerCount('block') ||
|
|
60
66
|
this.link.listenerCount('notification') ||
|
|
61
67
|
this.link.listenerCount('fiatRates');
|
|
@@ -66,7 +72,7 @@ class Blockchain {
|
|
|
66
72
|
error: error.message,
|
|
67
73
|
code: error.code,
|
|
68
74
|
}));
|
|
69
|
-
|
|
75
|
+
this.onDisconnected?.(!!pendingSubscriptions);
|
|
70
76
|
}
|
|
71
77
|
async initLink() {
|
|
72
78
|
let info;
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "Blockchain", { enumerable: true, get: function (
|
|
|
7
7
|
const backends = new BackendManager_1.BackendManager();
|
|
8
8
|
const findBackend = (coin, identity) => backends.get(coin, identity);
|
|
9
9
|
exports.findBackend = findBackend;
|
|
10
|
-
const setCustomBackend = (coinInfo, blockchainLink) => backends.setCustom(coinInfo.shortcut,
|
|
10
|
+
const setCustomBackend = (coinInfo, blockchainLink) => backends.setCustom(coinInfo.shortcut, blockchainLink?.url.length ? blockchainLink : coinInfo.blockchainLink);
|
|
11
11
|
exports.setCustomBackend = setCustomBackend;
|
|
12
12
|
const isBackendSupported = (coinInfo) => backends.isSupported(coinInfo);
|
|
13
13
|
exports.isBackendSupported = isBackendSupported;
|
package/lib/constants/errors.js
CHANGED
|
@@ -49,20 +49,46 @@ function validateDeviceState(input) {
|
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
51
|
class AbstractMethod {
|
|
52
|
+
responseID;
|
|
53
|
+
device;
|
|
54
|
+
params;
|
|
55
|
+
deviceState;
|
|
56
|
+
hasExpectedDeviceState;
|
|
57
|
+
keepSession;
|
|
58
|
+
skipFinalReload;
|
|
59
|
+
skipFirmwareCheck;
|
|
60
|
+
overridePreviousCall;
|
|
61
|
+
overridden;
|
|
62
|
+
name;
|
|
63
|
+
payload;
|
|
52
64
|
get info() {
|
|
53
65
|
return '';
|
|
54
66
|
}
|
|
55
67
|
get confirmation() {
|
|
56
68
|
return undefined;
|
|
57
69
|
}
|
|
70
|
+
useUi;
|
|
71
|
+
useDevice;
|
|
72
|
+
useDeviceState;
|
|
73
|
+
preauthorized;
|
|
74
|
+
useEmptyPassphrase;
|
|
75
|
+
allowSeedlessDevice;
|
|
76
|
+
firmwareRange;
|
|
77
|
+
requiredPermissions;
|
|
78
|
+
allowDeviceMode;
|
|
79
|
+
requireDeviceMode;
|
|
80
|
+
requiredDeviceCapabilities = [];
|
|
81
|
+
network;
|
|
82
|
+
useCardanoDerivation;
|
|
83
|
+
noBackupConfirmationMode;
|
|
84
|
+
postMessage;
|
|
85
|
+
createUiPromise;
|
|
58
86
|
constructor(message) {
|
|
59
|
-
var _a;
|
|
60
|
-
this.requiredDeviceCapabilities = [];
|
|
61
87
|
const { payload } = message;
|
|
62
88
|
this.name = payload.method;
|
|
63
89
|
this.payload = payload;
|
|
64
90
|
this.responseID = message.id || 0;
|
|
65
|
-
this.deviceState = validateDeviceState(
|
|
91
|
+
this.deviceState = validateDeviceState(payload.device?.state);
|
|
66
92
|
this.hasExpectedDeviceState = payload.device
|
|
67
93
|
? Object.prototype.hasOwnProperty.call(payload.device, 'state')
|
|
68
94
|
: false;
|
|
@@ -105,11 +131,10 @@ class AbstractMethod {
|
|
|
105
131
|
this.createUiPromise = (t, d) => originalFn(t, d || device);
|
|
106
132
|
}
|
|
107
133
|
getOriginPermissions({ origin }) {
|
|
108
|
-
var _a;
|
|
109
134
|
if (!origin) {
|
|
110
135
|
return [];
|
|
111
136
|
}
|
|
112
|
-
return
|
|
137
|
+
return connect_common_1.storage.loadForOrigin(origin)?.permissions || [];
|
|
113
138
|
}
|
|
114
139
|
checkPermissions({ origin }) {
|
|
115
140
|
const originPermissions = this.getOriginPermissions({ origin });
|