@onekeyfe/hd-core 0.1.41 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts +9 -0
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -0
- package/dist/api/aptos/AptosSignTransaction.d.ts +12 -0
- package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -0
- package/dist/api/conflux/ConfluxGetAddress.d.ts +14 -0
- package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -0
- package/dist/api/conflux/ConfluxSignMessage.d.ts +12 -0
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -0
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +12 -0
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -0
- package/dist/api/conflux/ConfluxSignTransaction.d.ts +17 -0
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -0
- package/dist/api/helpers/stringUtils.d.ts +1 -0
- package/dist/api/helpers/stringUtils.d.ts.map +1 -1
- package/dist/api/index.d.ts +21 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/near/NearGetAddress.d.ts +14 -0
- package/dist/api/near/NearGetAddress.d.ts.map +1 -0
- package/dist/api/near/NearSignTransaction.d.ts +12 -0
- package/dist/api/near/NearSignTransaction.d.ts.map +1 -0
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/tron/TronGetAddress.d.ts +14 -0
- package/dist/api/tron/TronGetAddress.d.ts.map +1 -0
- package/dist/api/tron/TronSignMessage.d.ts +12 -0
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -0
- package/dist/api/tron/TronSignTransaction.d.ts +14 -0
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/index.d.ts +347 -199
- package/dist/index.js +1579 -594
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/aptosGetAddress.d.ts +14 -0
- package/dist/types/api/aptosGetAddress.d.ts.map +1 -0
- package/dist/types/api/aptosSignTransaction.d.ts +11 -0
- package/dist/types/api/aptosSignTransaction.d.ts.map +1 -0
- package/dist/types/api/confluxGetAddress.d.ts +15 -0
- package/dist/types/api/confluxGetAddress.d.ts.map +1 -0
- package/dist/types/api/confluxSignMessage.d.ts +8 -0
- package/dist/types/api/confluxSignMessage.d.ts.map +1 -0
- package/dist/types/api/confluxSignMessageCIP23.d.ts +9 -0
- package/dist/types/api/confluxSignMessageCIP23.d.ts.map +1 -0
- package/dist/types/api/confluxSignTransaction.d.ts +25 -0
- package/dist/types/api/confluxSignTransaction.d.ts.map +1 -0
- package/dist/types/api/deviceVerify.d.ts +2 -3
- package/dist/types/api/deviceVerify.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +11 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +49 -27
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/nearGetAddress.d.ts +14 -0
- package/dist/types/api/nearGetAddress.d.ts.map +1 -0
- package/dist/types/api/nearSignTransaction.d.ts +8 -0
- package/dist/types/api/nearSignTransaction.d.ts.map +1 -0
- package/dist/types/api/tronGetAddress.d.ts +14 -0
- package/dist/types/api/tronGetAddress.d.ts.map +1 -0
- package/dist/types/api/tronSignMessage.d.ts +8 -0
- package/dist/types/api/tronSignMessage.d.ts.map +1 -0
- package/dist/types/api/tronSignTransaction.d.ts +32 -0
- package/dist/types/api/tronSignTransaction.d.ts.map +1 -0
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +5 -2
- package/src/api/aptos/AptosGetAddress.ts +60 -0
- package/src/api/aptos/AptosSignTransaction.ts +45 -0
- package/src/api/conflux/ConfluxGetAddress.ts +67 -0
- package/src/api/conflux/ConfluxSignMessage.ts +48 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +48 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +134 -0
- package/src/api/helpers/stringUtils.ts +3 -0
- package/src/api/index.ts +26 -10
- package/src/api/near/NearGetAddress.ts +68 -0
- package/src/api/near/NearSignTransaction.ts +45 -0
- package/src/api/solana/SolGetAddress.ts +0 -2
- package/src/api/solana/SolSignTransaction.ts +0 -2
- package/src/api/stellar/StellarSignTransaction.ts +14 -7
- package/src/api/tron/TronGetAddress.ts +68 -0
- package/src/api/tron/TronSignMessage.ts +48 -0
- package/src/api/tron/TronSignTransaction.ts +87 -0
- package/src/core/index.ts +15 -2
- package/src/data/messages/messages.json +8887 -8433
- package/src/device/DeviceCommands.ts +6 -7
- package/src/inject.ts +26 -0
- package/src/types/api/aptosGetAddress.ts +23 -0
- package/src/types/api/aptosSignTransaction.ts +17 -0
- package/src/types/api/confluxGetAddress.ts +24 -0
- package/src/types/api/confluxSignMessage.ts +13 -0
- package/src/types/api/confluxSignMessageCIP23.ts +14 -0
- package/src/types/api/confluxSignTransaction.ts +32 -0
- package/src/types/api/deviceVerify.ts +2 -2
- package/src/types/api/export.ts +25 -0
- package/src/types/api/index.ts +101 -35
- package/src/types/api/nearGetAddress.ts +23 -0
- package/src/types/api/nearSignTransaction.ts +13 -0
- package/src/types/api/tronGetAddress.ts +23 -0
- package/src/types/api/tronSignMessage.ts +13 -0
- package/src/types/api/tronSignTransaction.ts +41 -0
- package/src/utils/deviceFeaturesUtils.ts +2 -2
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
StellarMemoType,
|
|
3
|
+
StellarSignedTx,
|
|
4
|
+
StellarSignTx as HardwareStellarSignTx,
|
|
5
|
+
} from '@onekeyfe/hd-transport';
|
|
2
6
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
3
7
|
import { validatePath } from '../helpers/pathUtils';
|
|
4
8
|
import { BaseMethod } from '../BaseMethod';
|
|
5
9
|
import { validateParams } from '../helpers/paramsValidator';
|
|
6
10
|
import { StellarOperation, StellarSignTransactionParams } from '../../types';
|
|
11
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
7
12
|
|
|
8
13
|
export default class StellarSignTransaction extends BaseMethod<HardwareStellarSignTx> {
|
|
9
14
|
operations: any[] = [];
|
|
@@ -153,9 +158,13 @@ export default class StellarSignTransaction extends BaseMethod<HardwareStellarSi
|
|
|
153
158
|
{ name: 'transaction', type: 'object', required: true },
|
|
154
159
|
]);
|
|
155
160
|
|
|
161
|
+
const { transaction, networkPassphrase } = this.payload as StellarSignTransactionParams;
|
|
162
|
+
if (!transaction.timebounds) {
|
|
163
|
+
throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'timebounds is required');
|
|
164
|
+
}
|
|
165
|
+
|
|
156
166
|
// init params
|
|
157
167
|
const addressN = validatePath(this.payload.path, 3);
|
|
158
|
-
const { transaction, networkPassphrase } = this.payload as StellarSignTransactionParams;
|
|
159
168
|
|
|
160
169
|
this.params = {
|
|
161
170
|
address_n: addressN,
|
|
@@ -164,13 +173,11 @@ export default class StellarSignTransaction extends BaseMethod<HardwareStellarSi
|
|
|
164
173
|
fee: transaction.fee,
|
|
165
174
|
sequence_number: transaction.sequence,
|
|
166
175
|
num_operations: transaction.operations.length,
|
|
176
|
+
memo_type: StellarMemoType.NONE,
|
|
177
|
+
timebounds_start: transaction.timebounds.minTime,
|
|
178
|
+
timebounds_end: transaction.timebounds.maxTime,
|
|
167
179
|
};
|
|
168
180
|
|
|
169
|
-
if (transaction.timebounds) {
|
|
170
|
-
this.params.timebounds_start = transaction.timebounds.minTime;
|
|
171
|
-
this.params.timebounds_end = transaction.timebounds.maxTime;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
181
|
if (transaction.memo) {
|
|
175
182
|
this.params.memo_type = transaction.memo.type;
|
|
176
183
|
this.params.memo_text = transaction.memo.text;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
2
|
+
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
3
|
+
import { BaseMethod } from '../BaseMethod';
|
|
4
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
5
|
+
import { TronGetAddressParams, TronAddress } from '../../types';
|
|
6
|
+
import { TronGetAddress as HardwareTronGetAddress } from '@onekeyfe/hd-transport';
|
|
7
|
+
|
|
8
|
+
export default class TronGetAddress extends BaseMethod<HardwareTronGetAddress[]> {
|
|
9
|
+
hasBundle = false;
|
|
10
|
+
|
|
11
|
+
init() {
|
|
12
|
+
this.checkDeviceId = true;
|
|
13
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
14
|
+
|
|
15
|
+
this.hasBundle = !!this.payload?.bundle;
|
|
16
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
17
|
+
|
|
18
|
+
// check payload
|
|
19
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
20
|
+
|
|
21
|
+
// init params
|
|
22
|
+
this.params = [];
|
|
23
|
+
payload.bundle.forEach((batch: TronGetAddressParams) => {
|
|
24
|
+
const addressN = validatePath(batch.path, 3);
|
|
25
|
+
|
|
26
|
+
validateParams(batch, [
|
|
27
|
+
{ name: 'path', required: true },
|
|
28
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const showOnOneKey = batch.showOnOneKey ?? true;
|
|
32
|
+
|
|
33
|
+
this.params.push({
|
|
34
|
+
address_n: addressN,
|
|
35
|
+
show_display: showOnOneKey,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getVersionRange() {
|
|
41
|
+
return {
|
|
42
|
+
model_mini: {
|
|
43
|
+
min: '2.4.0',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async run() {
|
|
49
|
+
const responses: TronAddress[] = [];
|
|
50
|
+
|
|
51
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
52
|
+
const param = this.params[i];
|
|
53
|
+
|
|
54
|
+
const res = await this.device.commands.typedCall('TronGetAddress', 'TronAddress', {
|
|
55
|
+
...param,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const { address } = res.message;
|
|
59
|
+
|
|
60
|
+
responses.push({
|
|
61
|
+
path: serializedPath(param.address_n),
|
|
62
|
+
address,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
2
|
+
import { validatePath } from '../helpers/pathUtils';
|
|
3
|
+
import { BaseMethod } from '../BaseMethod';
|
|
4
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
5
|
+
import { stripHexPrefix } from '../helpers/hexUtils';
|
|
6
|
+
import { TronSignMessage as HardwareTronSignMessage } from '@onekeyfe/hd-transport';
|
|
7
|
+
|
|
8
|
+
export default class TronSignMessage extends BaseMethod<HardwareTronSignMessage> {
|
|
9
|
+
init() {
|
|
10
|
+
this.checkDeviceId = true;
|
|
11
|
+
this.allowDeviceMode = [...this.allowDeviceMode, 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
|
+
model_mini: {
|
|
32
|
+
min: '2.4.0',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async run() {
|
|
38
|
+
const response = await this.device.commands.typedCall(
|
|
39
|
+
'TronSignMessage',
|
|
40
|
+
'TronMessageSignature',
|
|
41
|
+
{
|
|
42
|
+
...this.params,
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return Promise.resolve(response.message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
2
|
+
import { validatePath } from '../helpers/pathUtils';
|
|
3
|
+
import { BaseMethod } from '../BaseMethod';
|
|
4
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
5
|
+
import { TronTransaction } from '../../types/api/tronSignTransaction';
|
|
6
|
+
import { TronSignTx } from '@onekeyfe/hd-transport';
|
|
7
|
+
import { formatAnyHex } from '../helpers/hexUtils';
|
|
8
|
+
|
|
9
|
+
export default class TronSignTransaction extends BaseMethod<TronSignTx> {
|
|
10
|
+
parseTx(tx: TronTransaction, address_n: number[]): TronSignTx {
|
|
11
|
+
const unSignTx = {
|
|
12
|
+
address_n,
|
|
13
|
+
data: tx.data,
|
|
14
|
+
timestamp: tx.timestamp,
|
|
15
|
+
fee_limit: tx.feeLimit,
|
|
16
|
+
ref_block_bytes: tx.refBlockBytes,
|
|
17
|
+
ref_block_hash: tx.refBlockHash,
|
|
18
|
+
expiration: tx.expiration,
|
|
19
|
+
contract: {},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
if (tx.contract) {
|
|
23
|
+
if (tx.contract.transferContract) {
|
|
24
|
+
unSignTx.contract = {
|
|
25
|
+
transfer_contract: {
|
|
26
|
+
to_address: tx.contract.transferContract.toAddress,
|
|
27
|
+
amount: tx.contract.transferContract.amount,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (tx.contract.triggerSmartContract) {
|
|
32
|
+
unSignTx.contract = {
|
|
33
|
+
trigger_smart_contract: {
|
|
34
|
+
contract_address: tx.contract.triggerSmartContract.contractAddress,
|
|
35
|
+
call_value: tx.contract.triggerSmartContract.callValue,
|
|
36
|
+
data: tx.contract.triggerSmartContract.data,
|
|
37
|
+
call_token_value: tx.contract.triggerSmartContract.callTokenValue,
|
|
38
|
+
asset_id: tx.contract.triggerSmartContract.assetId,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return unSignTx;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
init() {
|
|
48
|
+
this.checkDeviceId = true;
|
|
49
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
50
|
+
|
|
51
|
+
// check payload
|
|
52
|
+
validateParams(this.payload, [
|
|
53
|
+
{ name: 'path', required: true },
|
|
54
|
+
{ name: 'transaction', type: 'object', required: true },
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
const { path, transaction } = this.payload;
|
|
58
|
+
const addressN = validatePath(path, 3);
|
|
59
|
+
|
|
60
|
+
validateParams(transaction, [
|
|
61
|
+
{ name: 'refBlockBytes', type: 'hexString', required: true },
|
|
62
|
+
{ name: 'refBlockHash', type: 'hexString', required: true },
|
|
63
|
+
{ name: 'expiration', type: 'number', required: true },
|
|
64
|
+
{ name: 'timestamp', type: 'number', required: true },
|
|
65
|
+
{ name: 'contract', type: 'object', required: true },
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
// init params
|
|
69
|
+
this.params = this.parseTx(formatAnyHex(transaction), addressN);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getVersionRange() {
|
|
73
|
+
return {
|
|
74
|
+
model_mini: {
|
|
75
|
+
min: '2.4.0',
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async run() {
|
|
81
|
+
const response = await this.device.commands.typedCall('TronSignTx', 'TronSignedTx', {
|
|
82
|
+
...this.params,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return Promise.resolve(response.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -242,7 +242,7 @@ export const callAPI = async (message: CoreMessage) => {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
//
|
|
245
|
+
// Automatic check safety_check level for Kovan, Ropsten, Rinkeby, Goerli test networks.
|
|
246
246
|
try {
|
|
247
247
|
await method.checkSafetyLevelOnTestNet();
|
|
248
248
|
} catch (e) {
|
|
@@ -640,7 +640,20 @@ export default class Core extends EventEmitter {
|
|
|
640
640
|
|
|
641
641
|
case IFRAME.CALL: {
|
|
642
642
|
const response = await callAPI(message);
|
|
643
|
-
|
|
643
|
+
const { success, payload } = response;
|
|
644
|
+
|
|
645
|
+
if (success) {
|
|
646
|
+
return response;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
return {
|
|
650
|
+
...response,
|
|
651
|
+
payload: {
|
|
652
|
+
...payload,
|
|
653
|
+
connectId: message.payload?.connectId ?? '',
|
|
654
|
+
deviceId: message.payload?.deviceId ?? '',
|
|
655
|
+
},
|
|
656
|
+
};
|
|
644
657
|
}
|
|
645
658
|
case IFRAME.CANCEL: {
|
|
646
659
|
cancel(message.payload.connectId);
|