@onekeyfe/hwk-trezor-connector 1.2.0-alpha.13 → 1.2.0-alpha.131
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/dist/index.js +53 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -63,6 +63,12 @@ function readNumber(value, key) {
|
|
|
63
63
|
const candidate = value[key];
|
|
64
64
|
return typeof candidate === "number" ? candidate : void 0;
|
|
65
65
|
}
|
|
66
|
+
var HEX_STRING = /^(0x|0X)?[0-9A-Fa-f]*$/;
|
|
67
|
+
function assertHexString(field, value) {
|
|
68
|
+
if (!HEX_STRING.test(value)) {
|
|
69
|
+
throw createInvalidParamsError(`${field} must be a hex string`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
66
72
|
function formatAnyHex(value) {
|
|
67
73
|
if (typeof value === "string") {
|
|
68
74
|
let stripped = value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
|
|
@@ -425,6 +431,16 @@ function inputToTrezor(input) {
|
|
|
425
431
|
return result;
|
|
426
432
|
}
|
|
427
433
|
function outputToTrezor(output2) {
|
|
434
|
+
const targetCount = [
|
|
435
|
+
output2.opReturnData !== void 0,
|
|
436
|
+
Boolean(output2.address),
|
|
437
|
+
Boolean(output2.path)
|
|
438
|
+
].filter(Boolean).length;
|
|
439
|
+
if (targetCount > 1) {
|
|
440
|
+
throw createInvalidParamsError(
|
|
441
|
+
"btcSignTransaction output must specify exactly one of opReturnData, address, or path"
|
|
442
|
+
);
|
|
443
|
+
}
|
|
428
444
|
const withOutputMetadata = (result) => {
|
|
429
445
|
if (output2.paymentReqIndex !== void 0) {
|
|
430
446
|
result.payment_req_index = output2.paymentReqIndex;
|
|
@@ -2088,15 +2104,30 @@ async function evmGetAddress(ctx, params) {
|
|
|
2088
2104
|
};
|
|
2089
2105
|
}
|
|
2090
2106
|
function normalizeEvmSignTxHexFields(tx) {
|
|
2091
|
-
const hex = (value) =>
|
|
2107
|
+
const hex = (name, value) => {
|
|
2108
|
+
if (value === void 0) return void 0;
|
|
2109
|
+
assertHexString(name, value);
|
|
2110
|
+
return formatAnyHex(value);
|
|
2111
|
+
};
|
|
2112
|
+
tx.accessList?.forEach((entry, i) => {
|
|
2113
|
+
assertHexString(`accessList[${i}].address`, entry.address);
|
|
2114
|
+
entry.storageKeys?.forEach((key, j) => {
|
|
2115
|
+
assertHexString(`accessList[${i}].storageKeys[${j}]`, key);
|
|
2116
|
+
});
|
|
2117
|
+
});
|
|
2092
2118
|
return {
|
|
2093
2119
|
...tx,
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2120
|
+
// data included on purpose: Trezor Suite's EthereumSignTransaction runs its
|
|
2121
|
+
// deepTransform strip/pad over the WHOLE tx, calldata too — special-casing
|
|
2122
|
+
// data out of the padding here is what created truncation + fractional
|
|
2123
|
+
// data_length on odd input. Byte-for-byte parity with upstream.
|
|
2124
|
+
data: hex("data", tx.data),
|
|
2125
|
+
value: hex("value", tx.value),
|
|
2126
|
+
nonce: hex("nonce", tx.nonce),
|
|
2127
|
+
gasLimit: hex("gasLimit", tx.gasLimit),
|
|
2128
|
+
gasPrice: hex("gasPrice", tx.gasPrice),
|
|
2129
|
+
maxFeePerGas: hex("maxFeePerGas", tx.maxFeePerGas),
|
|
2130
|
+
maxPriorityFeePerGas: hex("maxPriorityFeePerGas", tx.maxPriorityFeePerGas),
|
|
2100
2131
|
accessList: tx.accessList ? formatAnyHex(tx.accessList) : tx.accessList
|
|
2101
2132
|
};
|
|
2102
2133
|
}
|
|
@@ -2198,7 +2229,7 @@ async function processTxRequest(ctx, initialResponse, remainingData, chainIdForL
|
|
|
2198
2229
|
let remaining = remainingData;
|
|
2199
2230
|
const maxRounds = Math.ceil(remainingData.length / 2) + 64;
|
|
2200
2231
|
let rounds = 0;
|
|
2201
|
-
|
|
2232
|
+
for (; ; ) {
|
|
2202
2233
|
rounds += 1;
|
|
2203
2234
|
if (rounds > maxRounds) {
|
|
2204
2235
|
throw new Error(
|
|
@@ -2712,6 +2743,7 @@ function readSolSignTxParams(params) {
|
|
|
2712
2743
|
if (typeof serializedTx !== "string" || serializedTx.length === 0) {
|
|
2713
2744
|
throw createInvalidParamsError("solSignTransaction requires serializedTx as a hex string");
|
|
2714
2745
|
}
|
|
2746
|
+
assertHexString("serializedTx", serializedTx);
|
|
2715
2747
|
return params;
|
|
2716
2748
|
}
|
|
2717
2749
|
function stripHexPrefix2(value) {
|
|
@@ -7465,6 +7497,19 @@ async function tronSignMessage(_ctx, _params) {
|
|
|
7465
7497
|
);
|
|
7466
7498
|
}
|
|
7467
7499
|
function buildContractMessage(contract, ownerAddress) {
|
|
7500
|
+
const contractCount = [
|
|
7501
|
+
contract.transferContract,
|
|
7502
|
+
contract.triggerSmartContract,
|
|
7503
|
+
contract.freezeBalanceV2Contract,
|
|
7504
|
+
contract.unfreezeBalanceV2Contract,
|
|
7505
|
+
contract.voteWitnessContract,
|
|
7506
|
+
contract.withdrawExpireUnfreezeContract
|
|
7507
|
+
].filter(Boolean).length;
|
|
7508
|
+
if (contractCount > 1) {
|
|
7509
|
+
throw createInvalidParamsError(
|
|
7510
|
+
"tronSignTransaction: contract must specify exactly one contract type"
|
|
7511
|
+
);
|
|
7512
|
+
}
|
|
7468
7513
|
if (contract.transferContract) {
|
|
7469
7514
|
const c = contract.transferContract;
|
|
7470
7515
|
return {
|