Skip to content

Commit

Permalink
feat: support sui signMessage (#280)
Browse files Browse the repository at this point in the history
* feat: support sui signMessage

* chore: release version 0.3.30
  • Loading branch information
ByteZhang1024 authored Sep 7, 2023
1 parent eae21a4 commit 269ee36
Show file tree
Hide file tree
Showing 23 changed files with 174 additions and 43 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.29",
"version": "0.3.30",
"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.29",
"@onekeyfe/hd-common-connect-sdk": "^0.3.29",
"@onekeyfe/hd-core": "^0.3.29",
"@onekeyfe/hd-web-sdk": "^0.3.29",
"@onekeyfe/hd-ble-sdk": "^0.3.30",
"@onekeyfe/hd-common-connect-sdk": "^0.3.30",
"@onekeyfe/hd-core": "^0.3.30",
"@onekeyfe/hd-web-sdk": "^0.3.30",
"@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
@@ -1,5 +1,5 @@
import { CommonParams, CoreApi } from '@onekeyfe/hd-core';
import React, { View, StyleSheet, Text } from 'react-native';
import React, { StyleSheet, Text, View } from 'react-native';
import type { Device } from './DeviceList';
import MethodInvoke from './MethodInvoke';

Expand All @@ -18,7 +18,7 @@ export function CallKaspaMethods({
const deviceId = currentDevice?.features?.deviceId ?? '';
return (
<View>
<Text style={{ textAlign: 'center', fontSize: 24 }}>Sui Method Test</Text>
<Text style={{ textAlign: 'center', fontSize: 24 }}>Kaspa Method Test</Text>
<View style={styles.buttonContainer}>
<MethodInvoke
title="kaspaGetAddress"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonParams, CoreApi } from '@onekeyfe/hd-core';
import React, { View, StyleSheet, Text } from 'react-native';
import React, { StyleSheet, Text, View } from 'react-native';
import type { Device } from './DeviceList';
import MethodInvoke from './MethodInvoke';

Expand Down Expand Up @@ -60,6 +60,24 @@ export function CallSuiMethods({
onCall={data => SDK.suiGetPublicKey(connectId, deviceId, { ...commonParams, ...data })}
/>

<MethodInvoke
title="suiSignMessage"
options={[
{ name: 'path', value: "m/44'/784'/0'/0'/0'", type: 'string' },
{
name: 'messageHex',
value: '010203',
type: 'string',
},
]}
onCall={data =>
SDK.suiSignMessage(connectId, deviceId, {
...commonParams,
...data,
} as unknown as any)
}
/>

<MethodInvoke
title="suiSignTransaction"
options={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getHardwareSDKInstance = memoizee(
console.log(HardwareSDK);

if (Platform.OS === 'web') {
settings.connectSrc = 'https://jssdk.onekey.so/0.3.29/';
settings.connectSrc = 'https://jssdk.onekey.so/0.3.30/';
// 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.29",
"version": "0.3.30",
"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.29",
"@onekeyfe/hd-transport": "^0.3.29",
"@onekeyfe/hd-shared": "^0.3.30",
"@onekeyfe/hd-transport": "^0.3.30",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2",
"bytebuffer": "^5.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export { default as xrpSignTransaction } from './xrp/XrpSignTransaction';

export { default as suiGetAddress } from './sui/SuiGetAddress';
export { default as suiGetPublicKey } from './sui/SuiGetPublicKey';
export { default as suiSignMessage } from './sui/SuiSignMessage';
export { default as suiSignTransaction } from './sui/SuiSignTransaction';

export { default as cardanoGetAddress } from './cardano/CardanoGetAddress';
Expand Down
47 changes: 47 additions & 0 deletions packages/core/src/api/sui/SuiSignMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { SuiSignMessage as HardwareSuiSignMessage } from '@onekeyfe/hd-transport';
import { UI_REQUEST } from '../../constants/ui-request';
import { validatePath } from '../helpers/pathUtils';
import { BaseMethod } from '../BaseMethod';
import { validateParams } from '../helpers/paramsValidator';
import { stripHexPrefix } from '../helpers/hexUtils';

export default class SuiSignMessage extends BaseMethod<HardwareSuiSignMessage> {
init() {
this.checkDeviceId = true;
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE];

// check payload
validateParams(this.payload, [
{ name: 'path', required: true },
{ name: 'messageHex', type: 'hexString', required: true },
]);

const { path, messageHex } = this.payload;
const addressN = validatePath(path, 3);

// init params
this.params = {
address_n: addressN,
message: stripHexPrefix(messageHex),
};
}

getVersionRange() {
return {
model_mini: {
min: '3.4.0',
},
model_touch: {
min: '4.6.0',
},
};
}

async run() {
const response = await this.device.commands.typedCall('SuiSignMessage', 'SuiMessageSignature', {
...this.params,
});

return Promise.resolve(response.message);
}
}
33 changes: 33 additions & 0 deletions packages/core/src/data/messages/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -8919,6 +8919,37 @@
}
}
},
"SuiSignMessage": {
"fields": {
"address_n": {
"rule": "repeated",
"type": "uint32",
"id": 1,
"options": {
"packed": false
}
},
"message": {
"rule": "required",
"type": "bytes",
"id": 2
}
}
},
"SuiMessageSignature": {
"fields": {
"signature": {
"rule": "required",
"type": "bytes",
"id": 1
},
"address": {
"rule": "required",
"type": "string",
"id": 2
}
}
},
"TezosGetAddress": {
"fields": {
"address_n": {
Expand Down Expand Up @@ -10099,6 +10130,8 @@
"MessageType_SuiAddress": 11101,
"MessageType_SuiSignTx": 11102,
"MessageType_SuiSignedTx": 11103,
"MessageType_SuiSignMessage": 11104,
"MessageType_SuiMessageSignature": 11105,
"MessageType_FilecoinGetAddress": 11200,
"MessageType_FilecoinAddress": 11201,
"MessageType_FilecoinSignTx": 11202,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ export const createCoreApi = (
call({ ...params, connectId, deviceId, method: 'suiGetAddress' }),
suiGetPublicKey: (connectId, deviceId, params) =>
call({ ...params, connectId, deviceId, method: 'suiGetPublicKey' }),
suiSignMessage: (connectId, deviceId, params) =>
call({ ...params, connectId, deviceId, method: 'suiSignMessage' }),
suiSignTransaction: (connectId, deviceId, params) =>
call({ ...params, connectId, deviceId, method: 'suiSignTransaction' }),

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/api/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export type { CosmosSignedTx, CosmosSignTransactionParams } from './cosmosSignTr

export type { SuiAddress, SuiGetAddressParams } from './suiGetAddress';
export type { SuiPublicKey, SuiGetPublicKeyParams } from './suiGetPublicKey';
export type { SuiSignMessageParams } from './suiSignMessage';
export type { SuiSignedTx, SuiSignTransactionParams } from './suiSignTransaction';

export type {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/types/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { on, off, removeAllListeners } from './event';
import { off, on, removeAllListeners } from './event';
import { uiResponse } from './uiResponse';
import { init, updateSettings } from './init';

Expand Down Expand Up @@ -92,6 +92,7 @@ import { xrpSignTransaction } from './xrpSignTransaction';

import { suiGetAddress } from './suiGetAddress';
import { suiGetPublicKey } from './suiGetPublicKey';
import { suiSignMessage } from './suiSignMessage';
import { suiSignTransaction } from './suiSignTransaction';

import { cardanoGetAddress } from './cardanoGetAddress';
Expand Down Expand Up @@ -266,6 +267,7 @@ export type CoreApi = {
*/
suiGetAddress: typeof suiGetAddress;
suiGetPublicKey: typeof suiGetPublicKey;
suiSignMessage: typeof suiSignMessage;
suiSignTransaction: typeof suiSignTransaction;

/**
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/types/api/suiSignMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SuiMessageSignature } from '@onekeyfe/hd-transport';
import type { CommonParams, Response } from '../params';

export type SuiSignMessageParams = {
path: string | number[];
messageHex: string;
};

export declare function suiSignMessage(
connectId: string,
deviceId: string,
params: CommonParams & SuiSignMessageParams
): Response<SuiMessageSignature>;
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.29",
"version": "0.3.30",
"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.29",
"@onekeyfe/hd-shared": "^0.3.29",
"@onekeyfe/hd-transport-react-native": "^0.3.29"
"@onekeyfe/hd-core": "^0.3.30",
"@onekeyfe/hd-shared": "^0.3.30",
"@onekeyfe/hd-transport-react-native": "^0.3.30"
}
}
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": "0.3.29",
"version": "0.3.30",
"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": "^0.3.29",
"@onekeyfe/hd-shared": "^0.3.29",
"@onekeyfe/hd-transport-http": "^0.3.29",
"@onekeyfe/hd-transport-lowlevel": "^0.3.29",
"@onekeyfe/hd-transport-webusb": "^0.3.29"
"@onekeyfe/hd-core": "^0.3.30",
"@onekeyfe/hd-shared": "^0.3.30",
"@onekeyfe/hd-transport-http": "^0.3.30",
"@onekeyfe/hd-transport-lowlevel": "^0.3.30",
"@onekeyfe/hd-transport-webusb": "^0.3.30"
}
}
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.29",
"version": "0.3.30",
"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.29",
"@onekeyfe/hd-transport": "^0.3.29",
"@onekeyfe/hd-shared": "^0.3.30",
"@onekeyfe/hd-transport": "^0.3.30",
"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": "0.3.29",
"version": "0.3.30",
"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": "^0.3.29",
"@onekeyfe/hd-transport": "^0.3.29"
"@onekeyfe/hd-shared": "^0.3.30",
"@onekeyfe/hd-transport": "^0.3.30"
}
}
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.29",
"version": "0.3.30",
"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.29",
"@onekeyfe/hd-transport": "^0.3.29",
"@onekeyfe/hd-shared": "^0.3.30",
"@onekeyfe/hd-transport": "^0.3.30",
"@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.29",
"version": "0.3.30",
"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.29",
"@onekeyfe/hd-transport": "^0.3.29"
"@onekeyfe/hd-shared": "^0.3.30",
"@onekeyfe/hd-transport": "^0.3.30"
},
"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.29",
"version": "0.3.30",
"description": "> TODO: description",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand Down
Loading

0 comments on commit 269ee36

Please sign in to comment.