Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 fix: dynex issues OK-27498 OK-27511 #4522

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/engine/@types/biginteger.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/src/vaults/impl/dynex/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export default class Vault extends VaultBase {
.shiftedBy(network.decimals)
.toFixed(),
extraInfo: null,
utxoFrom: [],
utxoTo: [],
},
direction:
encodedTx.to === address
Expand Down
19 changes: 9 additions & 10 deletions packages/engine/src/vaults/impl/dynex/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/utils/hardware/OneKeyHardware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions patches/biginteger+1.0.3.patch
Original file line number Diff line number Diff line change
@@ -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 <pow> and <exp10> (0x7FFFFFFF or 2147483647).
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading