@trezor/connect 9.0.0-beta.3 → 9.0.0-beta.6

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 (109) hide show
  1. package/README.md +11 -1
  2. package/lib/api/binance/binanceSignTx.d.ts +1 -1
  3. package/lib/api/binanceSignTransaction.d.ts +1 -1
  4. package/lib/api/bitcoin/enhanceSignTx.d.ts +1 -1
  5. package/lib/api/bitcoin/refTx.d.ts +1 -1
  6. package/lib/api/bitcoin/signtx.d.ts +1 -1
  7. package/lib/api/bitcoin/signtxLegacy.d.ts +1 -1
  8. package/lib/api/cardano/cardanoAddressParameters.d.ts +1 -1
  9. package/lib/api/cardano/cardanoAuxiliaryData.d.ts +1 -1
  10. package/lib/api/cardano/cardanoCertificate.d.ts +1 -1
  11. package/lib/api/cardano/cardanoInputs.d.ts +1 -0
  12. package/lib/api/cardano/cardanoInputs.js +12 -1
  13. package/lib/api/cardano/cardanoOutputs.d.ts +6 -3
  14. package/lib/api/cardano/cardanoOutputs.js +37 -1
  15. package/lib/api/cardano/cardanoTokenBundle.d.ts +1 -1
  16. package/lib/api/cardano/cardanoUtils.d.ts +3 -0
  17. package/lib/api/cardano/cardanoUtils.js +17 -0
  18. package/lib/api/cardano/cardanoWitnesses.js +4 -4
  19. package/lib/api/cardanoGetAddress.d.ts +1 -1
  20. package/lib/api/cardanoGetNativeScriptHash.d.ts +1 -1
  21. package/lib/api/cardanoGetPublicKey.d.ts +1 -1
  22. package/lib/api/cardanoSignTransaction.d.ts +8 -4
  23. package/lib/api/cardanoSignTransaction.js +40 -17
  24. package/lib/api/composeTransaction.d.ts +1 -1
  25. package/lib/api/eos/eosSignTx.d.ts +1 -1
  26. package/lib/api/eosGetPublicKey.d.ts +1 -1
  27. package/lib/api/ethereum/ethereumSignTx.d.ts +1 -1
  28. package/lib/api/ethereum/ethereumSignTypedData.d.ts +1 -1
  29. package/lib/api/ethereumSignTransaction.d.ts +1 -1
  30. package/lib/api/ethereumSignTypedData.d.ts +1 -1
  31. package/lib/api/firmware/calculateFirmwareHash.d.ts +6 -0
  32. package/lib/api/firmware/calculateFirmwareHash.js +26 -0
  33. package/lib/api/firmware/getBinary.d.ts +2 -2
  34. package/lib/api/firmware/getBinary.js +2 -3
  35. package/lib/api/firmware/index.d.ts +5 -0
  36. package/lib/api/firmware/index.js +13 -0
  37. package/lib/api/firmware/modifyFirmware.d.ts +3 -5
  38. package/lib/api/firmware/modifyFirmware.js +12 -10
  39. package/lib/api/{management → firmware}/uploadFirmware.d.ts +0 -0
  40. package/lib/api/{management → firmware}/uploadFirmware.js +0 -0
  41. package/lib/api/firmwareUpdate.d.ts +4 -1
  42. package/lib/api/firmwareUpdate.js +8 -13
  43. package/lib/api/getFirmwareHash.d.ts +7 -0
  44. package/lib/api/getFirmwareHash.js +29 -0
  45. package/lib/api/index.d.ts +1 -0
  46. package/lib/api/index.js +4 -2
  47. package/lib/api/nem/nemSignTx.d.ts +1 -1
  48. package/lib/api/signTransaction.d.ts +2 -2
  49. package/lib/api/stellar/stellarSignTx.d.ts +1 -1
  50. package/lib/api/stellarSignTransaction.d.ts +1 -1
  51. package/lib/api/tezos/tezosSignTx.d.ts +1 -1
  52. package/lib/constants/errors.js +1 -1
  53. package/lib/core/index.d.ts +1 -1
  54. package/lib/core/method.d.ts +1 -1
  55. package/lib/data/firmwareInfo.js +0 -9
  56. package/lib/data/version.d.ts +1 -1
  57. package/lib/data/version.js +1 -1
  58. package/lib/device/DeviceList.js +3 -1
  59. package/lib/factory.js +1 -0
  60. package/lib/types/api/binance/index.d.ts +29 -0
  61. package/lib/types/api/binance/index.js +3 -0
  62. package/lib/types/api/binanceSignTransaction.d.ts +1 -27
  63. package/lib/types/api/bitcoin/index.d.ts +82 -0
  64. package/lib/types/api/bitcoin/index.js +3 -0
  65. package/lib/types/api/cardano/index.d.ts +193 -0
  66. package/lib/types/api/cardano/index.js +3 -0
  67. package/lib/types/api/cardanoGetAddress.d.ts +1 -31
  68. package/lib/types/api/cardanoGetNativeScriptHash.d.ts +1 -18
  69. package/lib/types/api/cardanoGetPublicKey.d.ts +1 -12
  70. package/lib/types/api/cardanoSignTransaction.d.ts +1 -127
  71. package/lib/types/api/eos/index.d.ts +119 -0
  72. package/lib/types/api/eos/index.js +3 -0
  73. package/lib/types/api/eosGetPublicKey.d.ts +1 -10
  74. package/lib/types/api/eosSignTransaction.d.ts +1 -107
  75. package/lib/types/api/ethereum/index.d.ts +86 -0
  76. package/lib/types/api/ethereum/index.js +3 -0
  77. package/lib/types/api/ethereumSignMessage.d.ts +1 -5
  78. package/lib/types/api/ethereumSignTransaction.d.ts +1 -37
  79. package/lib/types/api/ethereumSignTypedData.d.ts +1 -37
  80. package/lib/types/api/ethereumVerifyMessage.d.ts +1 -6
  81. package/lib/types/api/firmwareUpdate.d.ts +6 -3
  82. package/lib/types/api/getFirmwareHash.d.ts +4 -0
  83. package/lib/types/api/getFirmwareHash.js +3 -0
  84. package/lib/types/api/index.d.ts +2 -0
  85. package/lib/types/api/nem/index.d.ts +90 -0
  86. package/lib/types/api/nem/index.js +3 -0
  87. package/lib/types/api/nemSignTransaction.d.ts +2 -89
  88. package/lib/types/api/ripple/index.d.ts +21 -0
  89. package/lib/types/api/ripple/index.js +3 -0
  90. package/lib/types/api/rippleSignTransaction.d.ts +1 -20
  91. package/lib/types/api/signMessage.d.ts +1 -7
  92. package/lib/types/api/signTransaction.d.ts +1 -67
  93. package/lib/types/api/stellar/index.d.ts +180 -0
  94. package/lib/types/api/stellar/index.js +3 -0
  95. package/lib/types/api/stellarSignTransaction.d.ts +1 -179
  96. package/lib/types/api/tezos/index.d.ts +58 -0
  97. package/lib/types/api/tezos/index.js +3 -0
  98. package/lib/types/api/tezosSignTransaction.d.ts +1 -57
  99. package/lib/types/api/verifyMessage.d.ts +1 -7
  100. package/lib/types/index.d.ts +8 -4
  101. package/lib/types/index.js +8 -0
  102. package/lib/utils/assetUtils.d.ts +2 -0
  103. package/lib/utils/assetUtils.js +22 -0
  104. package/lib/utils/assets-native.d.ts +2 -0
  105. package/lib/utils/assets-native.js +7 -0
  106. package/lib/utils/assets.js +5 -13
  107. package/lib/utils/deviceFeaturesUtils.js +1 -1
  108. package/package.json +7 -4
  109. package/CHANGELOG.md +0 -26
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @trezor/connect API version 9.0.0-beta.3
1
+ # @trezor/connect API version 9.0.0-beta.6
2
2
 
3
3
  [![Build Status](https://github.com/trezor/trezor-suite/actions/workflows/connect-test.yml/badge.svg)](https://github.com/trezor/trezor-suite/actions/workflows/connect-test.yml)
4
4
  [![NPM](https://img.shields.io/npm/v/@trezor/connect.svg)](https://www.npmjs.org/package/@trezor/connect)
@@ -44,6 +44,16 @@ With regards to this repo - All updates should go to current version branch, the
44
44
 
45
45
  For deployment process of trezor-connect v8 refer to [trezor/connect repository](https://github.com/trezor/connect/blob/develop/docs/deployment/index.md)
46
46
 
47
+ ## Docs
48
+
49
+ Interactive API explorer is available on https://connect.trezor.io/9/#/
50
+
51
+ Documentation is available [docs/packages/connect](../../docs/packages/connect/index.md)
52
+
53
+ ## Examples
54
+
55
+ A collection of examples on how to implement @trezor/connect in various environments is available in [packages/connect-examples](../connect-examples/README.md)
56
+
47
57
  ## Tests
48
58
 
49
59
  For integration testing against trezord and emulator refer to [this document](https://github.com/trezor/trezor-suite/blob/develop/packages/integration-tests/projects/connect/README.md).
@@ -1,5 +1,5 @@
1
1
  import { PROTO } from '../../constants';
2
- import type { BinanceSDKTransaction, BinancePreparedTransaction } from '../../types/api/binanceSignTransaction';
2
+ import type { BinanceSDKTransaction, BinancePreparedTransaction } from '../../types/api/binance';
3
3
  import type { TypedCall } from '../../device/DeviceCommands';
4
4
  export declare const validate: (tx: BinanceSDKTransaction) => BinancePreparedTransaction;
5
5
  export declare const signTx: (typedCall: TypedCall, address_n: number[], tx: BinancePreparedTransaction) => Promise<PROTO.BinanceSignedTx>;
@@ -1,5 +1,5 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
- import type { BinancePreparedTransaction } from '../types/api/binanceSignTransaction';
2
+ import type { BinancePreparedTransaction } from '../types/api/binance';
3
3
  declare type Params = {
4
4
  path: number[];
5
5
  transaction: BinancePreparedTransaction;
@@ -1,4 +1,4 @@
1
1
  import type { BitcoinNetworkInfo } from '../../types';
2
- import type { TransactionOptions } from '../../types/api/signTransaction';
2
+ import type { TransactionOptions } from '../../types/api/bitcoin';
3
3
  export declare const enhanceSignTx: (options: TransactionOptions, coinInfo: BitcoinNetworkInfo) => TransactionOptions;
4
4
  //# sourceMappingURL=enhanceSignTx.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import type { TypedRawTransaction } from '@trezor/blockchain-link';
2
2
  import type { CoinInfo, AccountAddresses } from '../../types';
3
- import type { RefTransaction, TransactionOptions } from '../../types/api/signTransaction';
3
+ import type { RefTransaction, TransactionOptions } from '../../types/api/bitcoin';
4
4
  import type { PROTO } from '../../constants';
5
5
  export declare const requireReferencedTransactions: (inputs: PROTO.TxInputType[], options?: TransactionOptions, coinInfo?: CoinInfo | undefined) => boolean;
6
6
  export declare const getReferencedTransactions: (inputs: PROTO.TxInputType[]) => string[];
@@ -1,7 +1,7 @@
1
1
  import { PROTO } from '../../constants';
2
2
  import type { BitcoinNetworkInfo } from '../../types';
3
3
  import type { TypedCall } from '../../device/DeviceCommands';
4
- import type { RefTransaction, TransactionOptions, SignedTransaction } from '../../types/api/signTransaction';
4
+ import type { RefTransaction, TransactionOptions, SignedTransaction } from '../../types/api/bitcoin';
5
5
  export interface SignTxHelperProps {
6
6
  typedCall: TypedCall;
7
7
  txRequest: PROTO.TxRequest;
@@ -1,4 +1,4 @@
1
- import type { SignedTransaction } from '../../types/api/signTransaction';
1
+ import type { SignedTransaction } from '../../types/api/bitcoin';
2
2
  import type { SignTxHelperParams } from './signtx';
3
3
  export declare const signTxLegacy: ({ typedCall, inputs, outputs, refTxs, options, coinInfo, }: SignTxHelperParams) => Promise<SignedTransaction>;
4
4
  //# sourceMappingURL=signtxLegacy.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { PROTO } from '../../constants';
2
2
  import type { Device } from '../../device/Device';
3
- import type { CardanoAddressParameters } from '../../types/api/cardanoGetAddress';
3
+ import type { CardanoAddressParameters } from '../../types/api/cardano';
4
4
  export declare const validateAddressParameters: (addressParameters: CardanoAddressParameters) => void;
5
5
  export declare const modifyAddressParametersForBackwardsCompatibility: (device: Device, address_parameters: PROTO.CardanoAddressParametersType) => PROTO.CardanoAddressParametersType;
6
6
  export declare const addressParametersToProto: (addressParameters: CardanoAddressParameters) => PROTO.CardanoAddressParametersType;
@@ -1,6 +1,6 @@
1
1
  import type { Device } from '../../device/Device';
2
2
  import type { PROTO } from '../../constants';
3
- import type { CardanoAuxiliaryData } from '../../types/api/cardanoSignTransaction';
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;
6
6
  //# sourceMappingURL=cardanoAuxiliaryData.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { PROTO } from '../../constants';
2
- import type { CardanoCertificate } from '../../types/api/cardanoSignTransaction';
2
+ import type { CardanoCertificate } from '../../types/api/cardano';
3
3
  export declare type CertificateWithPoolOwnersAndRelays = {
4
4
  certificate: PROTO.CardanoTxCertificate;
5
5
  poolOwners: PROTO.CardanoPoolOwner[];
@@ -10,4 +10,5 @@ export declare type CollateralInputWithPath = {
10
10
  };
11
11
  export declare const transformInput: (input: any) => InputWithPath;
12
12
  export declare const transformCollateralInput: (collateralInput: any) => CollateralInputWithPath;
13
+ export declare const transformReferenceInput: (referenceInput: any) => PROTO.CardanoTxReferenceInput;
13
14
  //# sourceMappingURL=cardanoInputs.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformCollateralInput = exports.transformInput = void 0;
3
+ exports.transformReferenceInput = exports.transformCollateralInput = exports.transformInput = void 0;
4
4
  const paramsValidator_1 = require("../common/paramsValidator");
5
5
  const pathUtils_1 = require("../../utils/pathUtils");
6
6
  const transformInput = (input) => {
@@ -31,4 +31,15 @@ const transformCollateralInput = (collateralInput) => {
31
31
  };
32
32
  };
33
33
  exports.transformCollateralInput = transformCollateralInput;
34
+ const transformReferenceInput = (referenceInput) => {
35
+ (0, paramsValidator_1.validateParams)(referenceInput, [
36
+ { name: 'prev_hash', type: 'string', required: true },
37
+ { name: 'prev_index', type: 'number', required: true },
38
+ ]);
39
+ return {
40
+ prev_hash: referenceInput.prev_hash,
41
+ prev_index: referenceInput.prev_index,
42
+ };
43
+ };
44
+ exports.transformReferenceInput = transformReferenceInput;
34
45
  //# sourceMappingURL=cardanoInputs.js.map
@@ -1,8 +1,11 @@
1
1
  import type { AssetGroupWithTokens } from './cardanoTokenBundle';
2
- import type { PROTO } from '../../constants';
3
- export declare type OutputWithTokens = {
2
+ import { PROTO } from '../../constants';
3
+ export declare type OutputWithData = {
4
4
  output: PROTO.CardanoTxOutput;
5
5
  tokenBundle?: AssetGroupWithTokens[];
6
+ inlineDatum?: string;
7
+ referenceScript?: string;
6
8
  };
7
- export declare const transformOutput: (output: any) => OutputWithTokens;
9
+ export declare const transformOutput: (output: any) => OutputWithData;
10
+ export declare const sendOutput: (typedCall: any, outputWithData: OutputWithData) => Promise<void>;
8
11
  //# sourceMappingURL=cardanoOutputs.d.ts.map
@@ -1,22 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformOutput = void 0;
3
+ exports.sendOutput = exports.transformOutput = void 0;
4
4
  const paramsValidator_1 = require("../common/paramsValidator");
5
5
  const cardanoAddressParameters_1 = require("./cardanoAddressParameters");
6
6
  const cardanoTokenBundle_1 = require("./cardanoTokenBundle");
7
+ const cardanoUtils_1 = require("./cardanoUtils");
7
8
  const transformOutput = (output) => {
8
9
  (0, paramsValidator_1.validateParams)(output, [
9
10
  { name: 'address', type: 'string' },
10
11
  { name: 'amount', type: 'uint', required: true },
11
12
  { name: 'tokenBundle', type: 'array', allowEmpty: true },
12
13
  { name: 'datumHash', type: 'string' },
14
+ { name: 'format', type: 'number' },
15
+ { name: 'inlineDatum', type: 'string' },
16
+ { name: 'referenceScript', type: 'string' },
13
17
  ]);
14
18
  const result = {
15
19
  output: {
16
20
  amount: output.amount,
17
21
  asset_groups_count: 0,
18
22
  datum_hash: output.datumHash,
23
+ format: output.format,
24
+ inline_datum_size: output.inlineDatum
25
+ ? (0, cardanoUtils_1.hexStringByteLength)(output.inlineDatum)
26
+ : undefined,
27
+ reference_script_size: output.referenceScript
28
+ ? (0, cardanoUtils_1.hexStringByteLength)(output.referenceScript)
29
+ : undefined,
19
30
  },
31
+ inlineDatum: output.inlineDatum,
32
+ referenceScript: output.referenceScript,
20
33
  };
21
34
  if (output.addressParameters) {
22
35
  (0, cardanoAddressParameters_1.validateAddressParameters)(output.addressParameters);
@@ -35,4 +48,27 @@ const transformOutput = (output) => {
35
48
  return result;
36
49
  };
37
50
  exports.transformOutput = transformOutput;
51
+ const sendOutput = async (typedCall, outputWithData) => {
52
+ const MAX_CHUNK_SIZE = 1024 * 2;
53
+ const { output, tokenBundle, inlineDatum, referenceScript } = outputWithData;
54
+ await typedCall('CardanoTxOutput', 'CardanoTxItemAck', output);
55
+ if (tokenBundle) {
56
+ for (const assetGroup of tokenBundle) {
57
+ await typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
58
+ policy_id: assetGroup.policyId,
59
+ tokens_count: assetGroup.tokens.length,
60
+ });
61
+ for (const token of assetGroup.tokens) {
62
+ await typedCall('CardanoToken', 'CardanoTxItemAck', token);
63
+ }
64
+ }
65
+ }
66
+ if (inlineDatum) {
67
+ await (0, cardanoUtils_1.sendChunkedHexString)(typedCall, inlineDatum, MAX_CHUNK_SIZE, 'CardanoTxInlineDatumChunk');
68
+ }
69
+ if (referenceScript) {
70
+ await (0, cardanoUtils_1.sendChunkedHexString)(typedCall, referenceScript, MAX_CHUNK_SIZE, 'CardanoTxReferenceScriptChunk');
71
+ }
72
+ };
73
+ exports.sendOutput = sendOutput;
38
74
  //# sourceMappingURL=cardanoOutputs.js.map
@@ -1,5 +1,5 @@
1
1
  import type { PROTO } from '../../constants';
2
- import type { CardanoAssetGroup } from '../../types/api/cardanoSignTransaction';
2
+ import type { CardanoAssetGroup } from '../../types/api/cardano';
3
3
  export declare type AssetGroupWithTokens = {
4
4
  policyId: string;
5
5
  tokens: PROTO.CardanoToken[];
@@ -0,0 +1,3 @@
1
+ export declare const hexStringByteLength: (s: string) => number;
2
+ export declare const sendChunkedHexString: (typedCall: any, data: string, chunkSize: number, messageType: string) => Promise<void>;
3
+ //# sourceMappingURL=cardanoUtils.d.ts.map
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendChunkedHexString = exports.hexStringByteLength = void 0;
4
+ const hexStringByteLength = (s) => s.length / 2;
5
+ exports.hexStringByteLength = hexStringByteLength;
6
+ const sendChunkedHexString = async (typedCall, data, chunkSize, messageType) => {
7
+ let processedSize = 0;
8
+ while (processedSize < data.length) {
9
+ const chunk = data.slice(processedSize, processedSize + chunkSize);
10
+ await typedCall(messageType, 'CardanoTxItemAck', {
11
+ data: chunk,
12
+ });
13
+ processedSize += chunkSize;
14
+ }
15
+ };
16
+ exports.sendChunkedHexString = sendChunkedHexString;
17
+ //# sourceMappingURL=cardanoUtils.js.map
@@ -34,11 +34,11 @@ const gatherWitnessPaths = (inputsWithPath, certificatesWithPoolOwnersAndRelays,
34
34
  if (path)
35
35
  _insert(path);
36
36
  });
37
- requiredSigners.forEach(({ key_path }) => {
38
- if (key_path)
39
- _insert(key_path);
40
- });
41
37
  }
38
+ requiredSigners.forEach(({ key_path }) => {
39
+ if (key_path)
40
+ _insert(key_path);
41
+ });
42
42
  additionalWitnessRequests.forEach(path => {
43
43
  _insert(path);
44
44
  });
@@ -17,7 +17,7 @@ export default class CardanoGetAddress extends AbstractMethod<'cardanoGetAddress
17
17
  noBackupConfirmation(): Promise<boolean>;
18
18
  _call({ address_parameters, protocol_magic, network_id, derivation_type, show_display, }: Params): Promise<PROTO.CardanoAddress>;
19
19
  _ensureFirmwareSupportsBatch(batch: Params): void;
20
- run(): Promise<import("../types/api/cardanoGetAddress").CardanoAddress | import("../types/api/cardanoGetAddress").CardanoAddress[]>;
20
+ run(): Promise<import("..").CardanoAddress | import("..").CardanoAddress[]>;
21
21
  }
22
22
  export {};
23
23
  //# sourceMappingURL=cardanoGetAddress.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { PROTO } from '../constants';
2
2
  import { AbstractMethod } from '../core/AbstractMethod';
3
- import type { CardanoNativeScript } from '../types/api/cardanoGetNativeScriptHash';
3
+ import type { CardanoNativeScript } from '../types/api/cardano';
4
4
  export default class CardanoGetNativeScriptHash extends AbstractMethod<'cardanoGetNativeScriptHash', PROTO.CardanoGetNativeScriptHash> {
5
5
  init(): void;
6
6
  validateScript(script: CardanoNativeScript): void;
@@ -5,6 +5,6 @@ export default class CardanoGetPublicKey extends AbstractMethod<'cardanoGetPubli
5
5
  confirmed?: boolean;
6
6
  init(): void;
7
7
  confirmation(): Promise<boolean>;
8
- run(): Promise<import("../types/api/cardanoGetPublicKey").CardanoPublicKey | import("../types/api/cardanoGetPublicKey").CardanoPublicKey[]>;
8
+ run(): Promise<import("..").CardanoPublicKey | import("..").CardanoPublicKey[]>;
9
9
  }
10
10
  //# sourceMappingURL=cardanoGetPublicKey.d.ts.map
@@ -1,9 +1,9 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
2
  import type { CertificateWithPoolOwnersAndRelays } from './cardano/cardanoCertificate';
3
- import type { Path, InputWithPath, CollateralInputWithPath } from './cardano/cardanoInputs';
4
- import type { OutputWithTokens } from './cardano/cardanoOutputs';
3
+ import { Path, InputWithPath, CollateralInputWithPath } from './cardano/cardanoInputs';
4
+ import type { OutputWithData } from './cardano/cardanoOutputs';
5
5
  import { PROTO } from '../constants';
6
- import type { CardanoSignedTxData } from '../types/api/cardanoSignTransaction';
6
+ import type { CardanoSignedTxData } from '../types/api/cardano';
7
7
  import type { AssetGroupWithTokens } from './cardano/cardanoTokenBundle';
8
8
  declare const CardanoSignTransactionFeatures: Readonly<{
9
9
  TransactionStreaming: string[];
@@ -14,11 +14,12 @@ declare const CardanoSignTransactionFeatures: Readonly<{
14
14
  ScriptDataHash: string[];
15
15
  Plutus: string[];
16
16
  KeyHashStakeCredential: string[];
17
+ Babbage: string[];
17
18
  }>;
18
19
  export declare type CardanoSignTransactionParams = {
19
20
  signingMode: PROTO.CardanoTxSigningMode;
20
21
  inputsWithPath: InputWithPath[];
21
- outputsWithTokens: OutputWithTokens[];
22
+ outputsWithData: OutputWithData[];
22
23
  fee: PROTO.UintType;
23
24
  ttl?: PROTO.UintType;
24
25
  certificatesWithPoolOwnersAndRelays: CertificateWithPoolOwnersAndRelays[];
@@ -29,6 +30,9 @@ export declare type CardanoSignTransactionParams = {
29
30
  scriptDataHash?: string;
30
31
  collateralInputsWithPath: CollateralInputWithPath[];
31
32
  requiredSigners: PROTO.CardanoTxRequiredSigner[];
33
+ collateralReturnWithData?: OutputWithData;
34
+ totalCollateral?: PROTO.UintType;
35
+ referenceInputs: PROTO.CardanoTxReferenceInput[];
32
36
  protocolMagic: number;
33
37
  networkId: number;
34
38
  witnessPaths: Path[];
@@ -20,6 +20,7 @@ const CardanoSignTransactionFeatures = Object.freeze({
20
20
  ScriptDataHash: ['0', '2.4.4'],
21
21
  Plutus: ['0', '2.4.4'],
22
22
  KeyHashStakeCredential: ['0', '2.4.4'],
23
+ Babbage: ['0', '2.5.2'],
23
24
  });
24
25
  class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
25
26
  init() {
@@ -46,6 +47,8 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
46
47
  { name: 'scriptDataHash', type: 'string' },
47
48
  { name: 'collateralInputs', type: 'array', allowEmpty: true },
48
49
  { name: 'requiredSigners', type: 'array', allowEmpty: true },
50
+ { name: 'totalCollateral', type: 'uint' },
51
+ { name: 'referenceInputs', type: 'array', allowEmpty: true },
49
52
  { name: 'protocolMagic', type: 'number', required: true },
50
53
  { name: 'networkId', type: 'number', required: true },
51
54
  { name: 'additionalWitnessRequests', type: 'array', allowEmpty: true },
@@ -53,7 +56,7 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
53
56
  { name: 'includeNetworkId', type: 'boolean' },
54
57
  ]);
55
58
  const inputsWithPath = payload.inputs.map(cardanoInputs_1.transformInput);
56
- const outputsWithTokens = payload.outputs.map(cardanoOutputs_1.transformOutput);
59
+ const outputsWithData = payload.outputs.map(cardanoOutputs_1.transformOutput);
57
60
  let certificatesWithPoolOwnersAndRelays = [];
58
61
  if (payload.certificates) {
59
62
  certificatesWithPoolOwnersAndRelays = payload.certificates.map(cardanoCertificate_1.transformCertificate);
@@ -102,10 +105,17 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
102
105
  };
103
106
  });
104
107
  }
108
+ const collateralReturnWithData = payload.collateralReturn
109
+ ? (0, cardanoOutputs_1.transformOutput)(payload.collateralReturn)
110
+ : undefined;
111
+ let referenceInputs = [];
112
+ if (payload.referenceInputs) {
113
+ referenceInputs = payload.referenceInputs.map(cardanoInputs_1.transformReferenceInput);
114
+ }
105
115
  this.params = {
106
116
  signingMode: payload.signingMode,
107
117
  inputsWithPath,
108
- outputsWithTokens,
118
+ outputsWithData,
109
119
  fee: payload.fee,
110
120
  ttl: payload.ttl,
111
121
  certificatesWithPoolOwnersAndRelays,
@@ -116,6 +126,9 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
116
126
  scriptDataHash: payload.scriptDataHash,
117
127
  collateralInputsWithPath,
118
128
  requiredSigners,
129
+ collateralReturnWithData,
130
+ totalCollateral: payload.totalCollateral,
131
+ referenceInputs,
119
132
  protocolMagic: payload.protocolMagic,
120
133
  networkId: payload.networkId,
121
134
  witnessPaths: (0, cardanoWitnesses_1.gatherWitnessPaths)(inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, payload.signingMode),
@@ -142,7 +155,7 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
142
155
  this._ensureFeatureIsSupported('KeyHashStakeCredential');
143
156
  }
144
157
  });
145
- params.outputsWithTokens.forEach(({ output }) => {
158
+ params.outputsWithData.forEach(({ output }) => {
146
159
  if (output.datum_hash) {
147
160
  this._ensureFeatureIsSupported('OutputDatumHash');
148
161
  }
@@ -168,6 +181,18 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
168
181
  if (params.signingMode === constants_1.PROTO.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
169
182
  this._ensureFeatureIsSupported('Plutus');
170
183
  }
184
+ params.outputsWithData.forEach(({ output, inlineDatum, referenceScript }) => {
185
+ if (output.format === constants_1.PROTO.CardanoTxOutputSerializationFormat.MAP_BABBAGE ||
186
+ inlineDatum ||
187
+ referenceScript) {
188
+ this._ensureFeatureIsSupported('Babbage');
189
+ }
190
+ });
191
+ if (params.collateralReturnWithData ||
192
+ params.totalCollateral != null ||
193
+ params.referenceInputs.length > 0) {
194
+ this._ensureFeatureIsSupported('Babbage');
195
+ }
171
196
  }
172
197
  async _sign_tx() {
173
198
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
@@ -177,7 +202,7 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
177
202
  protocol_magic: this.params.protocolMagic,
178
203
  network_id: this.params.networkId,
179
204
  inputs_count: this.params.inputsWithPath.length,
180
- outputs_count: this.params.outputsWithTokens.length,
205
+ outputs_count: this.params.outputsWithData.length,
181
206
  fee: this.params.fee,
182
207
  ttl: this.params.ttl,
183
208
  certificates_count: this.params.certificatesWithPoolOwnersAndRelays.length,
@@ -189,6 +214,9 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
189
214
  script_data_hash: this.params.scriptDataHash,
190
215
  collateral_inputs_count: this.params.collateralInputsWithPath.length,
191
216
  required_signers_count: this.params.requiredSigners.length,
217
+ has_collateral_return: this.params.collateralReturnWithData != null,
218
+ total_collateral: this.params.totalCollateral,
219
+ reference_inputs_count: this.params.referenceInputs.length,
192
220
  derivation_type: this.params.derivationType,
193
221
  include_network_id: this.params.includeNetworkId,
194
222
  };
@@ -196,19 +224,8 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
196
224
  for (const { input } of this.params.inputsWithPath) {
197
225
  await typedCall('CardanoTxInput', 'CardanoTxItemAck', input);
198
226
  }
199
- for (const { output, tokenBundle } of this.params.outputsWithTokens) {
200
- await typedCall('CardanoTxOutput', 'CardanoTxItemAck', output);
201
- if (tokenBundle) {
202
- for (const assetGroup of tokenBundle) {
203
- await typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
204
- policy_id: assetGroup.policyId,
205
- tokens_count: assetGroup.tokens.length,
206
- });
207
- for (const token of assetGroup.tokens) {
208
- await typedCall('CardanoToken', 'CardanoTxItemAck', token);
209
- }
210
- }
211
- }
227
+ for (const outputWithData of this.params.outputsWithData) {
228
+ await (0, cardanoOutputs_1.sendOutput)(typedCall, outputWithData);
212
229
  }
213
230
  for (const { certificate, poolOwners, poolRelays } of this.params
214
231
  .certificatesWithPoolOwnersAndRelays) {
@@ -260,6 +277,12 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
260
277
  for (const requiredSigner of this.params.requiredSigners) {
261
278
  await typedCall('CardanoTxRequiredSigner', 'CardanoTxItemAck', requiredSigner);
262
279
  }
280
+ if (this.params.collateralReturnWithData) {
281
+ await (0, cardanoOutputs_1.sendOutput)(typedCall, this.params.collateralReturnWithData);
282
+ }
283
+ for (const referenceInput of this.params.referenceInputs) {
284
+ await typedCall('CardanoTxReferenceInput', 'CardanoTxItemAck', referenceInput);
285
+ }
263
286
  const witnesses = [];
264
287
  for (const path of this.params.witnessPaths) {
265
288
  const { message } = await typedCall('CardanoTxWitnessRequest', 'CardanoTxWitnessResponse', { path });
@@ -26,7 +26,7 @@ export default class ComposeTransaction extends AbstractMethod<'composeTransacti
26
26
  }>;
27
27
  selectFee(account: DiscoveryAccount, utxo: AccountUtxo[]): Promise<SignedTransaction | "change-account">;
28
28
  _selectFeeUiResponse(composer: TransactionComposer): Promise<SignedTransaction | 'change-account'>;
29
- _sign(tx: ComposeResult): Promise<import("../types/api/signTransaction").SignedTransaction>;
29
+ _sign(tx: ComposeResult): Promise<import("../types").SignedTransaction>;
30
30
  dispose(): void;
31
31
  }
32
32
  export {};
@@ -1,5 +1,5 @@
1
1
  import { PROTO } from '../../constants';
2
- import type { EosSDKTransaction } from '../../types/api/eosSignTransaction';
2
+ import type { EosSDKTransaction } from '../../types/api/eos';
3
3
  import type { TypedCall } from '../../device/DeviceCommands';
4
4
  export declare const validate: (tx: EosSDKTransaction) => {
5
5
  chain_id: string;
@@ -5,6 +5,6 @@ export default class EosGetPublicKey extends AbstractMethod<'eosGetPublicKey', P
5
5
  confirmed?: boolean;
6
6
  init(): void;
7
7
  confirmation(): Promise<boolean>;
8
- run(): Promise<import("../types/api/eosGetPublicKey").EosPublicKey | import("../types/api/eosGetPublicKey").EosPublicKey[]>;
8
+ run(): Promise<import("..").EosPublicKey | import("..").EosPublicKey[]>;
9
9
  }
10
10
  //# sourceMappingURL=eosGetPublicKey.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import type { TypedCall } from '../../device/DeviceCommands';
2
- import type { EthereumAccessList } from '../../types/api/ethereumSignTransaction';
2
+ import type { EthereumAccessList } from '../../types/api/ethereum';
3
3
  export declare const ethereumSignTx: (typedCall: TypedCall, address_n: number[], to: string, value: string, gas_limit: string, gas_price: string, nonce: string, chain_id: number, data?: string | undefined, tx_type?: number | undefined) => Promise<{
4
4
  v: string;
5
5
  r: string;
@@ -1,5 +1,5 @@
1
1
  import { PROTO } from '../../constants';
2
- import type { EthereumSignTypedDataTypes } from '../../types/api/ethereumSignTypedData';
2
+ import type { EthereumSignTypedDataTypes } from '../../types/api/ethereum';
3
3
  export declare function parseArrayType(arrayTypeName: string): {
4
4
  entryTypeName: string;
5
5
  arraySize: number | null;
@@ -1,5 +1,5 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
- import type { EthereumTransaction, EthereumTransactionEIP1559 } from '../types/api/ethereumSignTransaction';
2
+ import type { EthereumTransaction, EthereumTransactionEIP1559 } from '../types/api/ethereum';
3
3
  declare type Params = {
4
4
  path: number[];
5
5
  tx: ({
@@ -1,5 +1,5 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
- import type { EthereumSignTypedDataTypes, EthereumSignTypedData as EthereumSignTypedDataParams, EthereumSignTypedHash as EthereumSignTypedHashParams } from '../types/api/ethereumSignTypedData';
2
+ import type { EthereumSignTypedDataTypes, EthereumSignTypedData as EthereumSignTypedDataParams, EthereumSignTypedHash as EthereumSignTypedHashParams } from '../types/api/ethereum';
3
3
  declare type Params = (Omit<EthereumSignTypedDataParams<EthereumSignTypedDataTypes>, 'path'> | Omit<EthereumSignTypedHashParams<EthereumSignTypedDataTypes>, 'path'>) & {
4
4
  address_n: number[];
5
5
  };
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ export declare const calculateFirmwareHash: (major_version: number, fw: ArrayBuffer, key?: Buffer | undefined) => {
3
+ hash: string;
4
+ challenge: string;
5
+ };
6
+ //# sourceMappingURL=calculateFirmwareHash.d.ts.map
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateFirmwareHash = void 0;
4
+ const blakejs_1 = require("blakejs");
5
+ const SIZE_T1 = (7 * 128 + 64) * 1024;
6
+ const SIZE_TT = 13 * 128 * 1024;
7
+ const calculateFirmwareHash = (major_version, fw, key) => {
8
+ const size = major_version === 1 ? SIZE_T1 : SIZE_TT;
9
+ const padding = size - fw.byteLength;
10
+ if (padding < 0) {
11
+ throw new Error('Firmware too big');
12
+ }
13
+ const data = new Uint8Array(new ArrayBuffer(size));
14
+ data.set(new Uint8Array(fw));
15
+ if (padding > 0) {
16
+ const zeroBytes = Buffer.alloc(padding);
17
+ zeroBytes.fill(Buffer.from('ff', 'hex'));
18
+ data.set(zeroBytes, fw.byteLength);
19
+ }
20
+ return {
21
+ hash: key && key.length > 0 ? (0, blakejs_1.blake2sHex)(data, key) : (0, blakejs_1.blake2sHex)(data),
22
+ challenge: key ? key.toString('hex') : '',
23
+ };
24
+ };
25
+ exports.calculateFirmwareHash = calculateFirmwareHash;
26
+ //# sourceMappingURL=calculateFirmwareHash.js.map
@@ -6,9 +6,9 @@ interface GetBinaryProps extends GetInfoProps {
6
6
  intermediary?: boolean;
7
7
  }
8
8
  export declare const getBinary: ({ features, releases, baseUrl, version, btcOnly, intermediary, }: GetBinaryProps) => Promise<{
9
- binary: ArrayBuffer;
9
+ binary: any;
10
10
  } | {
11
- binary: ArrayBuffer;
11
+ binary: any;
12
12
  changelog: import("../..").FirmwareRelease[] | null;
13
13
  release: import("../..").FirmwareRelease;
14
14
  isLatest: boolean;
@@ -5,14 +5,13 @@ const utils_1 = require("@trezor/utils");
5
5
  const assets_1 = require("../../utils/assets");
6
6
  const firmwareUtils_1 = require("../../utils/firmwareUtils");
7
7
  const firmwareInfo_1 = require("../../data/firmwareInfo");
8
- const modifyFirmware_1 = require("./modifyFirmware");
9
8
  const getBinary = async ({ features, releases, baseUrl, version, btcOnly, intermediary = false, }) => {
10
9
  if (!(0, firmwareUtils_1.isStrictFeatures)(features)) {
11
10
  throw new Error('Features of unexpected shape provided');
12
11
  }
13
12
  if (intermediary && features.major_version !== 2) {
14
13
  const fw = await (0, assets_1.httpRequest)(`${baseUrl}/firmware/1/trezor-inter-1.10.0.bin`, 'binary');
15
- return { binary: (0, modifyFirmware_1.modifyFirmware)({ fw, features }) };
14
+ return { binary: fw };
16
15
  }
17
16
  const infoByBootloader = (0, firmwareInfo_1.getInfo)({ features, releases });
18
17
  const releaseByFirmware = releases.find(r => version &&
@@ -30,7 +29,7 @@ const getBinary = async ({ features, releases, baseUrl, version, btcOnly, interm
30
29
  const fw = await (0, assets_1.httpRequest)(`${baseUrl}/${btcOnly ? releaseByFirmware.url_bitcoinonly : releaseByFirmware.url}`, 'binary');
31
30
  return {
32
31
  ...infoByBootloader,
33
- binary: (0, modifyFirmware_1.modifyFirmware)({ fw, features }),
32
+ binary: fw,
34
33
  };
35
34
  };
36
35
  exports.getBinary = getBinary;
@@ -0,0 +1,5 @@
1
+ export { getBinary } from './getBinary';
2
+ export { shouldStripFwHeaders, stripFwHeaders } from './modifyFirmware';
3
+ export { uploadFirmware } from './uploadFirmware';
4
+ export { calculateFirmwareHash } from './calculateFirmwareHash';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateFirmwareHash = exports.uploadFirmware = exports.stripFwHeaders = exports.shouldStripFwHeaders = exports.getBinary = void 0;
4
+ var getBinary_1 = require("./getBinary");
5
+ Object.defineProperty(exports, "getBinary", { enumerable: true, get: function () { return getBinary_1.getBinary; } });
6
+ var modifyFirmware_1 = require("./modifyFirmware");
7
+ Object.defineProperty(exports, "shouldStripFwHeaders", { enumerable: true, get: function () { return modifyFirmware_1.shouldStripFwHeaders; } });
8
+ Object.defineProperty(exports, "stripFwHeaders", { enumerable: true, get: function () { return modifyFirmware_1.stripFwHeaders; } });
9
+ var uploadFirmware_1 = require("./uploadFirmware");
10
+ Object.defineProperty(exports, "uploadFirmware", { enumerable: true, get: function () { return uploadFirmware_1.uploadFirmware; } });
11
+ var calculateFirmwareHash_1 = require("./calculateFirmwareHash");
12
+ Object.defineProperty(exports, "calculateFirmwareHash", { enumerable: true, get: function () { return calculateFirmwareHash_1.calculateFirmwareHash; } });
13
+ //# sourceMappingURL=index.js.map