Skip to content

Commit

Permalink
fix: evm sign (#272)
Browse files Browse the repository at this point in the history
* fix: evm sign

* chore: bump versions
  • Loading branch information
ByteZhang1024 authored Aug 9, 2023
1 parent a82d6e7 commit c6a9dda
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 123 deletions.
10 changes: 5 additions & 5 deletions packages/connect-examples/expo-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-example",
"version": "0.3.21",
"version": "0.3.22",
"scripts": {
"start": "expo start --dev-client",
"android": "expo run:android",
Expand All @@ -10,10 +10,10 @@
},
"dependencies": {
"@noble/hashes": "^1.1.3",
"@onekeyfe/hd-ble-sdk": "^0.3.21",
"@onekeyfe/hd-common-connect-sdk": "^0.3.21",
"@onekeyfe/hd-core": "^0.3.21",
"@onekeyfe/hd-web-sdk": "^0.3.21",
"@onekeyfe/hd-ble-sdk": "^0.3.22",
"@onekeyfe/hd-common-connect-sdk": "^0.3.22",
"@onekeyfe/hd-core": "^0.3.22",
"@onekeyfe/hd-web-sdk": "^0.3.22",
"@onekeyfe/react-native-ble-plx": "3.0.0",
"@react-native-async-storage/async-storage": "^1.17.6",
"@react-native-picker/picker": "2.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function CallEVMMethods({
},
{
name: 'transaction.data',
value: '0x01',
value: `0x${'01'.repeat(3072)}`,
type: 'string',
},
{
Expand Down Expand Up @@ -182,7 +182,7 @@ export function CallEVMMethods({
},
{
name: 'transaction.data',
value: '0x01',
value: `0x${'01'.repeat(3072)}`,
type: 'string',
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getHardwareSDKInstance = memoizee(
console.log(HardwareSDK);

if (Platform.OS === 'web') {
settings.connectSrc = 'https://jssdk.onekey.so/0.3.21/';
settings.connectSrc = 'https://jssdk.onekey.so/0.3.22/';
// settings.connectSrc = 'https://localhost:8087/';
settings.env = 'web';
settings.preRelease = false;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-core",
"version": "0.3.21",
"version": "0.3.22",
"description": "> TODO: description",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -25,8 +25,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.21",
"@onekeyfe/hd-transport": "^0.3.21",
"@onekeyfe/hd-shared": "^0.3.22",
"@onekeyfe/hd-transport": "^0.3.22",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2",
"bytebuffer": "^5.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/api/evm/latest/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const processTxRequest = async ({
});
};

const evmSignTx = async ({
export const evmSignTx = async ({
typedCall,
addressN,
tx,
Expand Down Expand Up @@ -127,7 +127,7 @@ const evmSignTx = async ({
});
};

const evmSignTxEip1559 = async ({
export const evmSignTxEip1559 = async ({
typedCall,
addressN,
tx,
Expand Down
94 changes: 9 additions & 85 deletions packages/core/src/api/evm/legacyV1/signTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,7 @@
import { EthereumSignTx, EthereumSignTxEIP1559, TypedCall } from '@onekeyfe/hd-transport';
import { TypedCall } from '@onekeyfe/hd-transport';
import { EVMTransaction, EVMTransactionEIP1559 } from '../../../types';
import { cutString } from '../../helpers/stringUtils';
import { stripHexStartZeroes } from '../../helpers/hexUtils';
import { processTxRequest } from '../latest/signTransaction';
import { evmSignTx, evmSignTxEip1559 } from '../latest/signTransaction';

const evmSignTx = async (typedCall: TypedCall, addressN: number[], tx: EVMTransaction) => {
const { to, value, gasPrice, gasLimit, nonce, data, chainId, txType } = tx;

const length = data == null ? 0 : data.length / 2;

const [first, rest] = cutString(data, 1024 * 2);

let message: EthereumSignTx = {
address_n: addressN,
nonce: stripHexStartZeroes(nonce),
gas_price: stripHexStartZeroes(gasPrice),
gas_limit: stripHexStartZeroes(gasLimit),
to,
value: stripHexStartZeroes(value),
chain_id: chainId,
};

if (length !== 0) {
message = {
...message,
data_length: length,
data_initial_chunk: first,
};
}

if (txType !== null) {
message = {
...message,
tx_type: txType,
};
}

const response = await typedCall('EthereumSignTx', 'EthereumTxRequest', message);

return processTxRequest({ typedCall, request: response.message, data: rest, chainId });
};

const evmSignTxEip1559 = async (
typedCall: TypedCall,
addressN: number[],
tx: EVMTransactionEIP1559
) => {
const {
to,
value,
gasLimit,
nonce,
data,
chainId,
maxFeePerGas,
maxPriorityFeePerGas,
accessList,
} = tx;

const length = data == null ? 0 : data.length / 2;

const [first, rest] = cutString(data, 1024 * 2);

const message: EthereumSignTxEIP1559 = {
address_n: addressN,
nonce: stripHexStartZeroes(nonce),
max_gas_fee: stripHexStartZeroes(maxFeePerGas),
max_priority_fee: stripHexStartZeroes(maxPriorityFeePerGas),
gas_limit: stripHexStartZeroes(gasLimit),
to,
value: stripHexStartZeroes(value),
data_length: length,
data_initial_chunk: first,
chain_id: chainId,
access_list: (accessList || []).map(a => ({
address: a.address,
storage_keys: a.storageKeys,
})),
};

const response = await typedCall('EthereumSignTxEIP1559', 'EthereumTxRequest', message);

return processTxRequest({ typedCall, request: response.message, data: rest });
};
export const signTransaction = async ({
typedCall,
isEIP1559,
Expand All @@ -95,5 +14,10 @@ export const signTransaction = async ({
typedCall: TypedCall;
}) =>
isEIP1559
? evmSignTxEip1559(typedCall, addressN, tx as EVMTransactionEIP1559)
: evmSignTx(typedCall, addressN, tx as EVMTransaction);
? evmSignTxEip1559({
typedCall,
addressN,
tx: tx as EVMTransactionEIP1559,
supportTrezor: true,
})
: evmSignTx({ typedCall, addressN, tx: tx as EVMTransaction, supportTrezor: true });
8 changes: 4 additions & 4 deletions packages/hd-ble-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-ble-sdk",
"version": "0.3.21",
"version": "0.3.22",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,8 +20,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "^0.3.21",
"@onekeyfe/hd-shared": "^0.3.21",
"@onekeyfe/hd-transport-react-native": "^0.3.21"
"@onekeyfe/hd-core": "^0.3.22",
"@onekeyfe/hd-shared": "^0.3.22",
"@onekeyfe/hd-transport-react-native": "^0.3.22"
}
}
10 changes: 5 additions & 5 deletions packages/hd-common-connect-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-common-connect-sdk",
"version": "0.3.21",
"version": "0.3.22",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,9 +20,9 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "^0.3.21",
"@onekeyfe/hd-shared": "^0.3.21",
"@onekeyfe/hd-transport-http": "^0.3.21",
"@onekeyfe/hd-transport-webusb": "^0.3.21"
"@onekeyfe/hd-core": "^0.3.22",
"@onekeyfe/hd-shared": "^0.3.22",
"@onekeyfe/hd-transport-http": "^0.3.22",
"@onekeyfe/hd-transport-webusb": "^0.3.22"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-http",
"version": "0.3.21",
"version": "0.3.22",
"description": "hardware http transport",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -24,8 +24,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.21",
"@onekeyfe/hd-transport": "^0.3.21",
"@onekeyfe/hd-shared": "^0.3.22",
"@onekeyfe/hd-transport": "^0.3.22",
"axios": "^0.27.2"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-react-native",
"version": "0.3.21",
"version": "0.3.22",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -19,8 +19,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.21",
"@onekeyfe/hd-transport": "^0.3.21",
"@onekeyfe/hd-shared": "^0.3.22",
"@onekeyfe/hd-transport": "^0.3.22",
"@onekeyfe/react-native-ble-plx": "3.0.0",
"react-native-ble-manager": "^8.1.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hd-transport-webusb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-webusb",
"version": "0.3.21",
"version": "0.3.22",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
Expand All @@ -20,8 +20,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.21",
"@onekeyfe/hd-transport": "^0.3.21"
"@onekeyfe/hd-shared": "^0.3.22",
"@onekeyfe/hd-transport": "^0.3.22"
},
"devDependencies": {
"@types/w3c-web-usb": "^1.0.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/hd-transport/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport",
"version": "0.3.21",
"version": "0.3.22",
"description": "> TODO: description",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand Down
10 changes: 5 additions & 5 deletions packages/hd-web-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-web-sdk",
"version": "0.3.21",
"version": "0.3.22",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -21,10 +21,10 @@
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "^0.0.17",
"@onekeyfe/hd-core": "^0.3.21",
"@onekeyfe/hd-shared": "^0.3.21",
"@onekeyfe/hd-transport-http": "^0.3.21",
"@onekeyfe/hd-transport-webusb": "^0.3.21"
"@onekeyfe/hd-core": "^0.3.22",
"@onekeyfe/hd-shared": "^0.3.22",
"@onekeyfe/hd-transport-http": "^0.3.22",
"@onekeyfe/hd-transport-webusb": "^0.3.22"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.17.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-shared",
"version": "0.3.21",
"version": "0.3.22",
"description": "Hardware SDK's shared tool library",
"keywords": [
"Hardware-SDK",
Expand Down

0 comments on commit c6a9dda

Please sign in to comment.