Skip to content

Commit d80a8d0

Browse files
Chore/optimize boot update & solSignMessage (#406)
* chore: optimize boot update * chore: release 1.0.20-alpha.1 * feat: support solSignMessage
1 parent d23d32f commit d80a8d0

File tree

29 files changed

+245
-72
lines changed

29 files changed

+245
-72
lines changed

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"bracketSpacing": true,
55
"singleQuote": true,
66
"semi": true,
7-
"trailingComma": "all",
7+
"trailingComma": "es5",
88
"tabWidth": 2,
99
"useTabs": false,
1010
"jsxBracketSameLine": false

packages/connect-examples/electron-example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "hardware-example",
33
"productName": "HardwareExample",
44
"executableName": "onekey-hardware-example",
5-
"version": "1.0.20-alpha.0",
5+
"version": "1.0.20-alpha.1",
66
"author": "OneKey",
77
"description": "End-to-end encrypted workspaces for teams",
88
"main": "dist/index.js",

packages/connect-examples/expo-example/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "expo-example",
3-
"version": "1.0.20-alpha.0",
3+
"version": "1.0.20-alpha.1",
44
"scripts": {
55
"start": "CONNECT_SRC=https://localhost:8087/ yarn expo start --dev-client",
66
"android": "yarn expo run:android",
@@ -19,10 +19,10 @@
1919
"@noble/ed25519": "^2.1.0",
2020
"@noble/hashes": "^1.3.3",
2121
"@noble/secp256k1": "^1.7.1",
22-
"@onekeyfe/hd-ble-sdk": "^1.0.20-alpha.0",
23-
"@onekeyfe/hd-common-connect-sdk": "^1.0.20-alpha.0",
24-
"@onekeyfe/hd-core": "^1.0.20-alpha.0",
25-
"@onekeyfe/hd-web-sdk": "^1.0.20-alpha.0",
22+
"@onekeyfe/hd-ble-sdk": "^1.0.20-alpha.1",
23+
"@onekeyfe/hd-common-connect-sdk": "^1.0.20-alpha.1",
24+
"@onekeyfe/hd-core": "^1.0.20-alpha.1",
25+
"@onekeyfe/hd-web-sdk": "^1.0.20-alpha.1",
2626
"@onekeyfe/react-native-ble-plx": "3.0.0",
2727
"@polkadot/util-crypto": "13.1.1",
2828
"@react-native-async-storage/async-storage": "1.21.0",

packages/connect-examples/expo-example/src/data/solana.ts

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ const api: PlaygroundProps[] = [
6060
},
6161
],
6262
},
63+
{
64+
method: 'solSignMessage',
65+
description: 'Sign Message',
66+
presupposes: [
67+
{
68+
title: 'Sign Message',
69+
value: {
70+
path: "m/44'/501'/0'/0'",
71+
messageHex: '48656c6c6f',
72+
},
73+
},
74+
],
75+
},
6376
];
6477

6578
export default api;

packages/connect-examples/expo-example/src/testTools/securityCheckTest/blindSignature/baseParams.ts

+8
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ export const baseParams = {
309309
path: `m/44'/${COINTYPE_MARK}'/0'/0'/0'`,
310310
messageHex: '010203',
311311
},
312+
solSignMessage: {
313+
path: `m/44'/${COINTYPE_MARK}'/0'/0'`,
314+
messageHex: '48656c6c6f',
315+
},
316+
solSignOffchainMessage: {
317+
path: `m/44'/${COINTYPE_MARK}'/0'/0'`,
318+
messageHex: '48656c6c6f',
319+
},
312320
tronSignMessage: {
313321
path: `m/44'/${COINTYPE_MARK}'/0'/0/0`,
314322
messageHex: '0x6578616d706c65206d657373616765',

packages/connect-examples/expo-example/src/testTools/securityCheckTest/blindSignature/data.ts

+14
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ export default [
216216
'60': false,
217217
},
218218
},
219+
{
220+
method: 'solSignMessage',
221+
expected: {
222+
'501': true,
223+
'60': false,
224+
},
225+
},
226+
{
227+
method: 'solSignOffchainMessage',
228+
expected: {
229+
'501': true,
230+
'60': false,
231+
},
232+
},
219233
{
220234
method: 'tronSignMessage',
221235
expected: {

packages/core/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-core",
3-
"version": "1.0.20-alpha.0",
3+
"version": "1.0.20-alpha.1",
44
"description": "> TODO: description",
55
"author": "OneKey",
66
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
2525
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
2626
},
2727
"dependencies": {
28-
"@onekeyfe/hd-shared": "^1.0.20-alpha.0",
29-
"@onekeyfe/hd-transport": "^1.0.20-alpha.0",
28+
"@onekeyfe/hd-shared": "^1.0.20-alpha.1",
29+
"@onekeyfe/hd-transport": "^1.0.20-alpha.1",
3030
"axios": "^0.27.2",
3131
"bignumber.js": "^9.0.2",
3232
"bytebuffer": "^5.0.1",

packages/core/src/api/firmware/uploadFirmware.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ const postProgressMessage = (
4444
);
4545
};
4646

47+
const postProcessingMessage = (
48+
type: 'firmware' | 'ble' | 'bootloader' | 'resource',
49+
postMessage: (message: CoreMessage) => void
50+
) => {
51+
postMessage(
52+
createUiMessage(UI_REQUEST.FIRMWARE_PROCESSING, {
53+
type,
54+
})
55+
);
56+
};
57+
4758
const postProgressTip = (
4859
device: Device,
4960
message: string,
@@ -301,7 +312,12 @@ const processResourceRequest = async (
301312

302313
// Fixed size
303314
const INIT_DATA_CHUNK_SIZE = 16 * 1024;
304-
export const updateResource = async (typedCall: TypedCall, fileName: string, data: ArrayBuffer) => {
315+
export const updateResource = async (
316+
typedCall: TypedCall,
317+
fileName: string,
318+
data: ArrayBuffer,
319+
onConfirmAfter?: () => void
320+
) => {
305321
const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
306322
const digest = blake2s(chunk);
307323

@@ -312,6 +328,7 @@ export const updateResource = async (typedCall: TypedCall, fileName: string, dat
312328
hash: bytesToHex(digest),
313329
});
314330

331+
onConfirmAfter?.();
315332
return processResourceRequest(typedCall, res, data);
316333
};
317334

@@ -353,7 +370,9 @@ export const updateBootloader = async (
353370
) => {
354371
postProgressTip(device, 'UpdateBootloader', postMessage);
355372
postProgressMessage(device, Math.floor(0), postMessage);
356-
await updateResource(typedCall, 'bootloader.bin', source);
373+
await updateResource(typedCall, 'bootloader.bin', source, () => {
374+
postProcessingMessage('resource', postMessage);
375+
});
357376
postProgressMessage(device, Math.floor(100), postMessage);
358377
postProgressTip(device, 'UpdateBootloaderSuccess', postMessage);
359378
return true;

packages/core/src/api/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export { default as nemSignTransaction } from './nem/NEMSignTransaction';
7373
export { default as solGetAddress } from './solana/SolGetAddress';
7474
export { default as solSignTransaction } from './solana/SolSignTransaction';
7575
export { default as solSignOffchainMessage } from './solana/SolSignOffchainMessage';
76+
export { default as solSignMessage } from './solana/SolSignMessage';
7677

7778
export { default as stellarGetAddress } from './stellar/StellarGetAddress';
7879
export { default as stellarSignTransaction } from './stellar/StellarSignTransaction';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { SolanaSignUnsafeMessage as HardwareSolSignUnsafeMessage } from '@onekeyfe/hd-transport';
2+
import { UI_REQUEST } from '../../constants/ui-request';
3+
import { validatePath } from '../helpers/pathUtils';
4+
import { BaseMethod } from '../BaseMethod';
5+
import { validateParams } from '../helpers/paramsValidator';
6+
import { stripHexPrefix } from '../helpers/hexUtils';
7+
8+
export default class SolSignMessage extends BaseMethod<HardwareSolSignUnsafeMessage> {
9+
init() {
10+
this.checkDeviceId = true;
11+
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE];
12+
13+
// check payload
14+
validateParams(this.payload, [
15+
{ name: 'path', required: true },
16+
{ name: 'messageHex', type: 'hexString', required: true },
17+
]);
18+
19+
const { path, messageHex } = this.payload;
20+
const addressN = validatePath(path, 3);
21+
22+
// init params
23+
this.params = {
24+
address_n: addressN,
25+
message: stripHexPrefix(messageHex),
26+
};
27+
}
28+
29+
getVersionRange() {
30+
return {
31+
pro: {
32+
min: '4.12.0',
33+
},
34+
touch: {
35+
min: '4.10.0',
36+
},
37+
classic1s: {
38+
min: '3.11.0',
39+
},
40+
model_mini: {
41+
min: '3.10.0',
42+
},
43+
};
44+
}
45+
46+
async run() {
47+
const response = await this.device.commands.typedCall(
48+
'SolanaSignUnsafeMessage',
49+
'SolanaMessageSignature',
50+
{
51+
...this.params,
52+
}
53+
);
54+
55+
return Promise.resolve({
56+
signature: response.message.signature,
57+
pub: response.message.public_key,
58+
});
59+
}
60+
}

packages/core/src/api/solana/SolSignOffchainMessage.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { SolanaSignMessage as HardwareSolSignMessage } from '@onekeyfe/hd-transport';
1+
import { SolanaSignOffChainMessage as HardwareSolSignOffChainMessage } from '@onekeyfe/hd-transport';
22
import { UI_REQUEST } from '../../constants/ui-request';
33
import { validatePath } from '../helpers/pathUtils';
44
import { BaseMethod } from '../BaseMethod';
55
import { validateParams } from '../helpers/paramsValidator';
66
import { stripHexPrefix } from '../helpers/hexUtils';
77

8-
export default class SolSignOffchainMessage extends BaseMethod<HardwareSolSignMessage> {
8+
export default class SolSignOffchainMessage extends BaseMethod<HardwareSolSignOffChainMessage> {
99
init() {
1010
this.checkDeviceId = true;
1111
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE];
@@ -45,13 +45,16 @@ export default class SolSignOffchainMessage extends BaseMethod<HardwareSolSignMe
4545

4646
async run() {
4747
const response = await this.device.commands.typedCall(
48-
'SolanaSignMessage',
49-
'SolanaSignedMessage',
48+
'SolanaSignOffChainMessage',
49+
'SolanaMessageSignature',
5050
{
5151
...this.params,
5252
}
5353
);
5454

55-
return Promise.resolve(response.message);
55+
return Promise.resolve({
56+
signature: response.message.signature,
57+
pub: response.message.public_key,
58+
});
5659
}
5760
}

packages/core/src/data/messages/messages.json

+26-9
Original file line numberDiff line numberDiff line change
@@ -9468,18 +9468,18 @@
94689468
}
94699469
}
94709470
},
9471-
"SolanaMessageVersion": {
9471+
"SolanaOffChainMessageVersion": {
94729472
"values": {
94739473
"MESSAGE_VERSION_0": 0
94749474
}
94759475
},
9476-
"SolanaMessageFormat": {
9476+
"SolanaOffChainMessageFormat": {
94779477
"values": {
94789478
"V0_RESTRICTED_ASCII": 0,
94799479
"V0_LIMITED_UTF8": 1
94809480
}
94819481
},
9482-
"SolanaSignMessage": {
9482+
"SolanaSignOffChainMessage": {
94839483
"fields": {
94849484
"address_n": {
94859485
"rule": "repeated",
@@ -9495,14 +9495,14 @@
94959495
"id": 2
94969496
},
94979497
"message_version": {
9498-
"type": "SolanaMessageVersion",
9498+
"type": "SolanaOffChainMessageVersion",
94999499
"id": 3,
95009500
"options": {
95019501
"default": "MESSAGE_VERSION_0"
95029502
}
95039503
},
95049504
"message_format": {
9505-
"type": "SolanaMessageFormat",
9505+
"type": "SolanaOffChainMessageFormat",
95069506
"id": 4,
95079507
"options": {
95089508
"default": "V0_RESTRICTED_ASCII"
@@ -9514,15 +9514,31 @@
95149514
}
95159515
}
95169516
},
9517-
"SolanaSignedMessage": {
9517+
"SolanaSignUnsafeMessage": {
9518+
"fields": {
9519+
"address_n": {
9520+
"rule": "repeated",
9521+
"type": "uint32",
9522+
"id": 1,
9523+
"options": {
9524+
"packed": false
9525+
}
9526+
},
9527+
"message": {
9528+
"rule": "required",
9529+
"type": "bytes",
9530+
"id": 2
9531+
}
9532+
}
9533+
},
9534+
"SolanaMessageSignature": {
95189535
"fields": {
95199536
"signature": {
95209537
"rule": "required",
95219538
"type": "bytes",
95229539
"id": 1
95239540
},
95249541
"public_key": {
9525-
"rule": "required",
95269542
"type": "bytes",
95279543
"id": 2
95289544
}
@@ -11685,8 +11701,9 @@
1168511701
"MessageType_SolanaAddress": 10101,
1168611702
"MessageType_SolanaSignTx": 10102,
1168711703
"MessageType_SolanaSignedTx": 10103,
11688-
"MessageType_SolanaSignMessage": 10104,
11689-
"MessageType_SolanaSignedMessage": 10105,
11704+
"MessageType_SolanaSignOffChainMessage": 10104,
11705+
"MessageType_SolanaMessageSignature": 10105,
11706+
"MessageType_SolanaSignUnsafeMessage": 10106,
1169011707
"MessageType_StarcoinGetAddress": 10300,
1169111708
"MessageType_StarcoinAddress": 10301,
1169211709
"MessageType_StarcoinGetPublicKey": 10302,

packages/core/src/events/ui-request.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const UI_REQUEST = {
2121
LOCATION_PERMISSION: 'ui-location_permission',
2222
LOCATION_SERVICE_PERMISSION: 'ui-location_service_permission',
2323

24+
FIRMWARE_PROCESSING: 'ui-firmware-processing',
2425
FIRMWARE_PROGRESS: 'ui-firmware-progress',
2526
FIRMWARE_TIP: 'ui-firmware-tip',
2627

@@ -33,10 +34,18 @@ export interface UiRequestWithoutPayload {
3334
| typeof UI_REQUEST.BLUETOOTH_PERMISSION
3435
| typeof UI_REQUEST.BLUETOOTH_CHARACTERISTIC_NOTIFY_CHANGE_FAILURE
3536
| typeof UI_REQUEST.LOCATION_PERMISSION
36-
| typeof UI_REQUEST.LOCATION_SERVICE_PERMISSION;
37+
| typeof UI_REQUEST.LOCATION_SERVICE_PERMISSION
38+
| typeof UI_REQUEST.FIRMWARE_PROCESSING;
3739
payload?: typeof undefined;
3840
}
3941

42+
export interface UiRequestFirmwareProgressing {
43+
type: typeof UI_REQUEST.FIRMWARE_PROCESSING;
44+
payload: {
45+
type: 'firmware' | 'ble' | 'bootloader' | 'resource';
46+
};
47+
}
48+
4049
export type UiRequestDeviceAction = {
4150
type: typeof UI_REQUEST.REQUEST_PIN;
4251
payload: {

packages/core/src/inject.ts

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ export const createCoreApi = (
196196
call({ ...params, connectId, deviceId, method: 'solSignTransaction' }),
197197
solSignOffchainMessage: (connectId, deviceId, params) =>
198198
call({ ...params, connectId, deviceId, method: 'solSignOffchainMessage' }),
199+
solSignMessage: (connectId, deviceId, params) =>
200+
call({ ...params, connectId, deviceId, method: 'solSignMessage' }),
199201

200202
stellarGetAddress: (connectId, deviceId, params) =>
201203
call({ ...params, connectId, deviceId, method: 'stellarGetAddress' }),

packages/core/src/types/api/export.ts

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export type {
7070
SolSignOffchainMessageResponse,
7171
SolSignOffchainMessageParams,
7272
} from './solSignOffchainMessage';
73+
export type { SolSignMessageResponse, SolSignMessageParams } from './solSignMessage';
7374

7475
export type { StellarAddress, StellarGetAddressParams } from './stellarGetAddress';
7576
export type {

0 commit comments

Comments
 (0)