diff --git a/packages/engine/@types/biginteger.d.ts b/packages/engine/@types/biginteger.d.ts new file mode 100644 index 00000000000..267a0e954ce --- /dev/null +++ b/packages/engine/@types/biginteger.d.ts @@ -0,0 +1,15 @@ +declare module 'biginteger' { + export class BigInteger { + constructor(n: number | string | BigInteger, base?: number): BigInteger; + + compare(n: number | string | BigInteger): number; + + divide(n: number | string | BigInteger): BigInteger; + + pow(n: number | string | BigInteger): BigInteger; + + toJSValue(): number; + + lowVal(): number; + } +} diff --git a/packages/engine/package.json b/packages/engine/package.json index 713fd054fe4..0d830baf2ff 100644 --- a/packages/engine/package.json +++ b/packages/engine/package.json @@ -56,6 +56,7 @@ "axios-retry": "^3.4.0", "bchaddrjs": "^0.5.2", "bech32": "^2.0.0", + "biginteger": "^1.0.3", "bignumber.js": "^9.0.1", "bip32": "^4.0.0", "bip39": "^3.1.0", diff --git a/packages/engine/src/vaults/impl/dynex/Vault.ts b/packages/engine/src/vaults/impl/dynex/Vault.ts index 52f54591e0b..d180317592b 100644 --- a/packages/engine/src/vaults/impl/dynex/Vault.ts +++ b/packages/engine/src/vaults/impl/dynex/Vault.ts @@ -165,6 +165,8 @@ export default class Vault extends VaultBase { .shiftedBy(network.decimals) .toFixed(), extraInfo: null, + utxoFrom: [], + utxoTo: [], }, direction: encodedTx.to === address diff --git a/packages/engine/src/vaults/impl/dynex/utils.ts b/packages/engine/src/vaults/impl/dynex/utils.ts index f05ff50f586..db511b2b746 100644 --- a/packages/engine/src/vaults/impl/dynex/utils.ts +++ b/packages/engine/src/vaults/impl/dynex/utils.ts @@ -1,6 +1,7 @@ /* eslint-disable no-param-reassign */ /* eslint-disable no-bitwise */ import { keccak256 } from '@ethersproject/keccak256'; +import { BigInteger } from 'biginteger'; import BigNumber from 'bignumber.js'; import type { IEncodedTxDynex, ISignTxParams } from './types'; @@ -11,16 +12,14 @@ const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX = 29; const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX = 52; export function encodeVarInt(number: number) { - const result = []; - do { - let byte = number & 0x7f; - number >>>= 7; - if (number !== 0) { - byte |= 0x80; - } - result.push(byte); - } while (number !== 0); - return result.map((byte) => byte.toString(16).padStart(2, '0')).join(''); + let numberBI = new BigInteger(number); + let out = ''; + while (numberBI.compare(0x80) >= 0) { + out += `0${((numberBI.lowVal() & 0x7f) | 0x80).toString(16)}`.slice(-2); + numberBI = numberBI.divide(new BigInteger(2).pow(7)); + } + out += `0${numberBI.toJSValue().toString(16)}`.slice(-2); + return out; } export function integerToLittleEndianHex({ diff --git a/packages/kit/src/utils/hardware/OneKeyHardware.ts b/packages/kit/src/utils/hardware/OneKeyHardware.ts index 55b4fac74c9..c21aae3ca52 100644 --- a/packages/kit/src/utils/hardware/OneKeyHardware.ts +++ b/packages/kit/src/utils/hardware/OneKeyHardware.ts @@ -8,7 +8,7 @@ export const getDeviceTypeByDeviceId = (deviceId?: string): IDeviceType => getDeviceTypeByDeviceIdUtil(deviceId); export const isHwClassic = (deviceType: string | undefined): boolean => - deviceType === 'classic' || deviceType === 'classic1s'; + deviceType === 'classic'; export const getDeviceFirmwareVersion = ( features: IOneKeyDeviceFeatures | undefined, diff --git a/patches/biginteger+1.0.3.patch b/patches/biginteger+1.0.3.patch new file mode 100644 index 00000000000..c817cf7682f --- /dev/null +++ b/patches/biginteger+1.0.3.patch @@ -0,0 +1,15 @@ +diff --git a/node_modules/biginteger/biginteger.js b/node_modules/biginteger/biginteger.js +index b881105..41967f5 100644 +--- a/node_modules/biginteger/biginteger.js ++++ b/node_modules/biginteger/biginteger.js +@@ -1564,6 +1564,10 @@ BigInteger.prototype.toJSValue = function() { + return parseInt(this.toString(), 10); + }; + ++BigInteger.prototype.lowVal = function () { ++ return this._d[0] || 0; ++}; ++ + var MAX_EXP = BigInteger(0x7FFFFFFF); + // Constant: MAX_EXP + // The largest exponent allowed in and (0x7FFFFFFF or 2147483647). diff --git a/yarn.lock b/yarn.lock index fdb6b875358..72feb3c6db7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7039,6 +7039,7 @@ __metadata: axios-retry: ^3.4.0 bchaddrjs: ^0.5.2 bech32: ^2.0.0 + biginteger: ^1.0.3 bignumber.js: ^9.0.1 bip32: ^4.0.0 bip39: ^3.1.0 @@ -13986,6 +13987,13 @@ __metadata: languageName: node linkType: hard +"biginteger@npm:^1.0.3": + version: 1.0.3 + resolution: "biginteger@npm:1.0.3" + checksum: 325458d3801885eef4468ddb1d9b24fd4773d958fdd85bf75a7e71e856cea0009f7b319aec718ed5a64ce9e7f0aa4010b23b702e9576a840b8710e04e9550080 + languageName: node + linkType: hard + "bignumber.js@npm:^9.0.0, bignumber.js@npm:^9.0.1, bignumber.js@npm:^9.0.2": version: 9.0.2 resolution: "bignumber.js@npm:9.0.2"