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

fix: ton token transfer #379

Merged
merged 2 commits into from
Oct 18, 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
2 changes: 1 addition & 1 deletion packages/connect-examples/electron-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hardware-example",
"productName": "HardwareExample",
"executableName": "onekey-hardware-example",
"version": "1.0.12-alpha.2",
"version": "1.0.12",
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
"author": "OneKey",
"description": "End-to-end encrypted workspaces for teams",
"main": "dist/index.js",
Expand Down
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": "1.0.12-alpha.2",
"version": "1.0.12",
"scripts": {
"start": "CONNECT_SRC=https://localhost:8087/ yarn expo start --dev-client",
"android": "yarn expo run:android",
Expand All @@ -19,10 +19,10 @@
"@noble/ed25519": "^2.1.0",
"@noble/hashes": "^1.3.3",
"@noble/secp256k1": "^1.7.1",
"@onekeyfe/hd-ble-sdk": "^1.0.12-alpha.2",
"@onekeyfe/hd-common-connect-sdk": "^1.0.12-alpha.2",
"@onekeyfe/hd-core": "^1.0.12-alpha.2",
"@onekeyfe/hd-web-sdk": "^1.0.12-alpha.2",
"@onekeyfe/hd-ble-sdk": "^1.0.12",
"@onekeyfe/hd-common-connect-sdk": "^1.0.12",
"@onekeyfe/hd-core": "^1.0.12",
"@onekeyfe/hd-web-sdk": "^1.0.12",
"@onekeyfe/react-native-ble-plx": "3.0.0",
"@polkadot/util-crypto": "13.1.1",
"@react-native-async-storage/async-storage": "1.21.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/connect-examples/expo-example/src/data/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ const api: PlaygroundProps[] = [
isTestnetOnly: false,
},
},
{
title: 'Token (Big Number)',
value: {
path: "m/44'/607'/0'",
destination: 'UQBYkuShkZzRYAWX_HrK3kFpeAixiRKd-K7QBXYxl9OBXM0_',
tonAmount: 100,
seqno: 0,
expireAt: Date.now() + 1000 * 60 * 60 * 24,
jettonMasterAddress: 'UQBYkuShkZzRYAWX_HrK3kFpeAixiRKd-K7QBXYxl9OBXM0_',
jettonAmount: '500000000000000000',
fwdFee: 100,
comment: '48656c6c6f204f6e654b6579',
mode: 1,
walletVersion: 3,
isBounceable: false,
isTestnetOnly: false,
},
},
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
],
},
{
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": "1.0.12-alpha.2",
"version": "1.0.12",
"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": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport": "^1.0.12-alpha.2",
"@onekeyfe/hd-shared": "^1.0.12",
"@onekeyfe/hd-transport": "^1.0.12",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2",
"bytebuffer": "^5.0.1",
Expand Down
99 changes: 91 additions & 8 deletions packages/core/src/api/ton/TonSignMessage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { TonSignMessage as HardwareTonSignMessage } from '@onekeyfe/hd-transport';

import semver from 'semver';
import BigNumber from 'bignumber.js';
import { isEmpty } from 'lodash';
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
import { UI_REQUEST } from '../../constants/ui-request';
import { validatePath } from '../helpers/pathUtils';
import { BaseMethod } from '../BaseMethod';
import { validateParams } from '../helpers/paramsValidator';
import { DeviceModelToTypes, TonSignMessageParams } from '../../types';
import { getDeviceType } from '../../utils';
import { DeviceFirmwareRange, DeviceModelToTypes, TonSignMessageParams } from '../../types';
import { getDeviceFirmwareVersion, getDeviceType, getMethodVersionRange } from '../../utils';
import { formatAnyHex, stripHexStartZeroes } from '../helpers/hexUtils';

export default class TonSignMessage extends BaseMethod<HardwareTonSignMessage> {
init() {
Expand All @@ -18,14 +22,14 @@ export default class TonSignMessage extends BaseMethod<HardwareTonSignMessage> {
{ name: 'destination', type: 'string' },
{ name: 'jettonMasterAddress', type: 'string' },
{ name: 'jettonWalletAddress', type: 'string' },
{ name: 'tonAmount', type: 'number' },
{ name: 'jettonAmount', type: 'number' },
{ name: 'fwdFee', type: 'number' },
{ name: 'tonAmount' },
{ name: 'jettonAmount' },
{ name: 'fwdFee' },
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
{ name: 'comment', type: 'string' },
{ name: 'isRawData', type: 'boolean' },
{ name: 'mode', type: 'number' },
{ name: 'seqno', type: 'number' },
{ name: 'expireAt', type: 'number' },
{ name: 'expireAt' },
{ name: 'walletVersion' },
{ name: 'walletId', type: 'number' },
{ name: 'workchain' },
Expand All @@ -45,7 +49,6 @@ export default class TonSignMessage extends BaseMethod<HardwareTonSignMessage> {
jetton_master_address: this.payload.jettonMasterAddress,
jetton_wallet_address: this.payload.jettonWalletAddress,
ton_amount: this.payload.tonAmount,
jetton_amount: this.payload.jettonAmount,
fwd_fee: this.payload.fwdFee,
comment: this.payload.comment,
mode: this.payload.mode,
Expand All @@ -68,10 +71,90 @@ export default class TonSignMessage extends BaseMethod<HardwareTonSignMessage> {
model_touch: {
min: '4.10.0',
},
classic1s: {
min: '3.10.0',
},
};
}

getSupportJettonAmountBytesVersionRange(): DeviceFirmwareRange {
return {
pro: {
min: '4.10.2',
},
};
}

checkSupportJettonAmountBytes() {
const firmwareVersion = getDeviceFirmwareVersion(this.device.features)?.join('.');
const versionRange = getMethodVersionRange(
this.device.features,
type => this.getSupportJettonAmountBytesVersionRange()[type]
);

if (!versionRange) {
// Equipment that does not need to be repaired
return true;
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
}

if (semver.valid(firmwareVersion) && semver.gte(firmwareVersion, versionRange.min)) {
return true;
}
return false;
}
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved

getFixCommentErrorVersionRange(): DeviceFirmwareRange {
return {
pro: {
min: '4.10.1',
},
};
}

checkFixCommentError() {
// The issue of missing comments when transferring tokens.
const { comment, jettonAmount } = this.payload;

if (isEmpty(comment) || jettonAmount === null || jettonAmount === undefined) {
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const firmwareVersion = getDeviceFirmwareVersion(this.device.features)?.join('.');
const versionRange = getMethodVersionRange(
this.device.features,
type => this.getFixCommentErrorVersionRange()[type]
);

if (!versionRange) {
// Equipment that does not need to be repaired
return;
}
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved

if (semver.valid(firmwareVersion) && semver.lt(firmwareVersion, versionRange.min)) {
throw ERRORS.TypedError(
HardwareErrorCode.CallMethodNeedUpgradeFirmware,
`Device firmware version is too low, please update to ${versionRange.min}`,
{ current: firmwareVersion, require: versionRange.min }
);
}
}
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved

async run() {
// checkFixCommentError
this.checkFixCommentError();

// check jettonAmount
const { jettonAmount } = this.payload;
if (jettonAmount) {
if (this.checkSupportJettonAmountBytes()) {
this.params.jetton_amount_bytes = stripHexStartZeroes(
formatAnyHex(new BigNumber(jettonAmount).toString(16))
);
} else {
this.params.jetton_amount = jettonAmount;
}
}

const deviceType = getDeviceType(this.device.features);
const res = await this.device.commands.typedCall('TonSignMessage', 'TonSignedMessage', {
...this.params,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/api/ton/TonSignProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class TonSignProof extends BaseMethod<HardwareTonSignProof> {
{ name: 'path', required: true },
{ name: 'appdomain', type: 'string' },
{ name: 'comment', type: 'string' },
{ name: 'expireAt', type: 'number' },
{ name: 'expireAt' },
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
{ name: 'walletVersion' },
{ name: 'walletId', type: 'number' },
{ name: 'workchain' },
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/data/messages/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -10628,6 +10628,10 @@
"rule": "repeated",
"type": "string",
"id": 20
},
"jetton_amount_bytes": {
"type": "bytes",
"id": 21
}
}
},
Expand Down
17 changes: 11 additions & 6 deletions packages/core/src/types/api/tonSignMessage.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import { TonSignedMessage, TonWalletVersion, TonWorkChain } from '@onekeyfe/hd-transport';
import type {
TonSignedMessage,
TonWalletVersion,
TonWorkChain,
UintType,
} from '@onekeyfe/hd-transport';
import type { CommonParams, Response } from '../params';

export type TonSignMessageParams = {
path: string | number[];
destination: string;
jettonMasterAddress?: string;
jettonWalletAddress?: string;
tonAmount: number;
jettonAmount?: number;
fwdFee?: number;
tonAmount: UintType;
jettonAmount?: UintType;
fwdFee?: UintType;
comment?: string;
isRawData?: boolean;
mode?: number;
seqno: number;
expireAt: number;
expireAt: UintType;
walletVersion?: TonWalletVersion;
walletId?: number;
workchain?: TonWorkChain;
isBounceable?: boolean;
isTestnetOnly?: boolean;
extDestination?: string[];
extTonAmount?: number[];
extTonAmount?: UintType[];
extPayload?: string[];
};

Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/types/api/tonSignProof.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { TonSignedProof, TonWalletVersion, TonWorkChain } from '@onekeyfe/hd-transport';
import type {
TonSignedProof,
TonWalletVersion,
TonWorkChain,
UintType,
} from '@onekeyfe/hd-transport';
import type { CommonParams, Response } from '../params';

export type TonSignProofParams = {
path: string | number[];
appdomain: string;
comment?: string;
expireAt: number;
expireAt: UintType;
walletVersion?: TonWalletVersion;
walletId?: number;
workchain?: TonWorkChain;
Expand Down
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": "1.0.12-alpha.2",
"version": "1.0.12",
"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": "^1.0.12-alpha.2",
"@onekeyfe/hd-shared": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport-react-native": "^1.0.12-alpha.2"
"@onekeyfe/hd-core": "^1.0.12",
"@onekeyfe/hd-shared": "^1.0.12",
"@onekeyfe/hd-transport-react-native": "^1.0.12"
}
}
12 changes: 6 additions & 6 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": "1.0.12-alpha.2",
"version": "1.0.12",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,10 +20,10 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "^1.0.12-alpha.2",
"@onekeyfe/hd-shared": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport-http": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport-lowlevel": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport-webusb": "^1.0.12-alpha.2"
"@onekeyfe/hd-core": "^1.0.12",
"@onekeyfe/hd-shared": "^1.0.12",
"@onekeyfe/hd-transport-http": "^1.0.12",
"@onekeyfe/hd-transport-lowlevel": "^1.0.12",
"@onekeyfe/hd-transport-webusb": "^1.0.12"
}
}
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": "1.0.12-alpha.2",
"version": "1.0.12",
"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": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport": "^1.0.12-alpha.2",
"@onekeyfe/hd-shared": "^1.0.12",
"@onekeyfe/hd-transport": "^1.0.12",
"axios": "^0.27.2"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-lowlevel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-lowlevel",
"version": "1.0.12-alpha.2",
"version": "1.0.12",
ByteZhang1024 marked this conversation as resolved.
Show resolved Hide resolved
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -19,7 +19,7 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport": "^1.0.12-alpha.2"
"@onekeyfe/hd-shared": "^1.0.12",
"@onekeyfe/hd-transport": "^1.0.12"
}
}
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": "1.0.12-alpha.2",
"version": "1.0.12",
"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": "^1.0.12-alpha.2",
"@onekeyfe/hd-transport": "^1.0.12-alpha.2",
"@onekeyfe/hd-shared": "^1.0.12",
"@onekeyfe/hd-transport": "^1.0.12",
"@onekeyfe/react-native-ble-plx": "3.0.1",
"react-native-ble-manager": "^8.1.0"
}
Expand Down
Loading
Loading