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: benfen return address #390

Merged
merged 2 commits into from
Dec 4, 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.15",
"version": "1.0.16-alpha.0",
"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.15",
"version": "1.0.16-alpha.0",
"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.15",
"@onekeyfe/hd-common-connect-sdk": "^1.0.15",
"@onekeyfe/hd-core": "^1.0.15",
"@onekeyfe/hd-web-sdk": "^1.0.15",
"@onekeyfe/hd-ble-sdk": "^1.0.16-alpha.0",
"@onekeyfe/hd-common-connect-sdk": "^1.0.16-alpha.0",
"@onekeyfe/hd-core": "^1.0.16-alpha.0",
"@onekeyfe/hd-web-sdk": "^1.0.16-alpha.0",
"@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
16 changes: 16 additions & 0 deletions packages/core/__tests__/benfen.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { publicKeyToAddress, hex2BfcAddress } from '../src/api/benfen/normalize';

describe('Benfen Address Normalization', () => {
it('publicKeyToBFCAddress', () => {
// Test case with a known public key and its expected address
const publicKey = '6e9c9ef745cc3a250168db15526d18075dc52849d49f8a6ea5477c1c264b4848';
const expectedHexAddress = '0xb4ced58018b75d7ba72a10fa97c09b7bf66533ff104bf9db1bfdb004b17d8eaa';
const expectedAddress =
'BFCb4ced58018b75d7ba72a10fa97c09b7bf66533ff104bf9db1bfdb004b17d8eaa2e35';

const hexAddress = publicKeyToAddress(publicKey);
const bfcAddress = hex2BfcAddress(hexAddress);
expect(hexAddress).toBe(expectedHexAddress);
expect(bfcAddress).toBe(expectedAddress);
Comment on lines +5 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数据集太少,不要用常用钱包地址去做

准备一个 fixtures 数据集

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 本来是想管理一个通用的数据集,将助记词也记在里面,后续维护同一个数据集。但是有两个问题

    • 安全性。虽然可以使用空的,全新的钱包。
    • 一个一个导入钱包去生成地址/用例, 没有直接创建一个效率高。(因为导入需要输入助记词)
  • 目前维护 12 / 18 / 24 位助记词,每种类型 3 个数据。共 3 *3 = 9 个数据。这样应该是可以的?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 个数据为 "m/44'/728'/0'/0'","m/44'/728'/0'/0'/0'", "m/44'/728'/0'/0'/1'"

(另,第一次种情况,不传递最后一位address_index。在实际中应该不会出现,需要这样测试么?)

});
wabicai marked this conversation as resolved.
Show resolved Hide resolved
});
8 changes: 7 additions & 1 deletion packages/core/__tests__/checkBootloaderReleast.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* eslint-disable @typescript-eslint/no-var-requires */
wabicai marked this conversation as resolved.
Show resolved Hide resolved
const { shouldUpdateBootloaderForClassicAndMini } = require('../src/api/firmware/bootloaderHelper');
import { shouldUpdateBootloaderForClassicAndMini } from '../src/api/firmware/bootloaderHelper';

// Add mock for config module
jest.mock('../src/data/config', () => ({
getSDKVersion: () => '1.0.0',
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
}));
wabicai marked this conversation as resolved.
Show resolved Hide resolved

const fixtures = [
{
Expand Down
1 change: 1 addition & 0 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
preset: '../../jest.config.js',
testEnvironment: 'node',
modulePathIgnorePatterns: ['node_modules', '<rootDir>/lib', '<rootDir>/libDev'],
collectCoverage: true,
};
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.15",
"version": "1.0.16-alpha.0",
"description": "> TODO: description",
wabicai marked this conversation as resolved.
Show resolved Hide resolved
"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.15",
"@onekeyfe/hd-transport": "^1.0.15",
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport": "^1.0.16-alpha.0",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2",
"bytebuffer": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/api/benfen/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function hex2BfcAddress(hexAddress: string): string {
const hex = hexAddress.replace(/^0x/, '').padStart(64, '0').toLowerCase();

// 使用SHA-256计算校验和
const hash = sha256(hexToBytes(hex));
const hash = sha256(new TextEncoder().encode(hex));
wabicai marked this conversation as resolved.
Show resolved Hide resolved
wabicai marked this conversation as resolved.
Show resolved Hide resolved
const checksumHex = bytesToHex(hash).slice(0, 4);

// 返回BFC格式地址
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.15",
"version": "1.0.16-alpha.0",
"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.15",
"@onekeyfe/hd-shared": "^1.0.15",
"@onekeyfe/hd-transport-react-native": "^1.0.15"
"@onekeyfe/hd-core": "^1.0.16-alpha.0",
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport-react-native": "^1.0.16-alpha.0"
}
}
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.15",
"version": "1.0.16-alpha.0",
"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.15",
"@onekeyfe/hd-shared": "^1.0.15",
"@onekeyfe/hd-transport-http": "^1.0.15",
"@onekeyfe/hd-transport-lowlevel": "^1.0.15",
"@onekeyfe/hd-transport-webusb": "^1.0.15"
"@onekeyfe/hd-core": "^1.0.16-alpha.0",
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport-http": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport-lowlevel": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport-webusb": "^1.0.16-alpha.0"
}
}
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.15",
"version": "1.0.16-alpha.0",
"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.15",
"@onekeyfe/hd-transport": "^1.0.15",
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport": "^1.0.16-alpha.0",
"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.15",
"version": "1.0.16-alpha.0",
"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.15",
"@onekeyfe/hd-transport": "^1.0.15"
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport": "^1.0.16-alpha.0"
}
}
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.15",
"version": "1.0.16-alpha.0",
"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.15",
"@onekeyfe/hd-transport": "^1.0.15",
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport": "^1.0.16-alpha.0",
"@onekeyfe/react-native-ble-plx": "3.0.1",
"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": "1.0.15",
"version": "1.0.16-alpha.0",
"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": "^1.0.15",
"@onekeyfe/hd-transport": "^1.0.15"
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport": "^1.0.16-alpha.0"
},
"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": "1.0.15",
"version": "1.0.16-alpha.0",
"description": "> TODO: description",
wabicai marked this conversation as resolved.
Show resolved Hide resolved
"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": "1.0.15",
"version": "1.0.16-alpha.0",
"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": "^1.0.15",
"@onekeyfe/hd-shared": "^1.0.15",
"@onekeyfe/hd-transport-http": "^1.0.15",
"@onekeyfe/hd-transport-webusb": "^1.0.15"
"@onekeyfe/hd-core": "^1.0.16-alpha.0",
"@onekeyfe/hd-shared": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport-http": "^1.0.16-alpha.0",
"@onekeyfe/hd-transport-webusb": "^1.0.16-alpha.0"
},
"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": "1.0.15",
"version": "1.0.16-alpha.0",
wabicai marked this conversation as resolved.
Show resolved Hide resolved
"description": "Hardware SDK's shared tool library",
"keywords": [
"Hardware-SDK",
Expand Down
Loading