@onekeyfe/hd-core 0.0.8 → 0.1.0
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 +4 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CipherKeyValue.d.ts +9 -0
- package/dist/api/CipherKeyValue.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts +14 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -0
- package/dist/api/device/DeviceRebootToBootloader.d.ts +8 -0
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts +5 -0
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTransaction.d.ts +5 -0
- package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts +7 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +33 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -0
- package/dist/api/firmware/uploadFirmware.d.ts +8 -0
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -0
- package/dist/api/helpers/hexUtils.d.ts.map +1 -1
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/nem/NEMGetAddress.d.ts +9 -0
- package/dist/api/nem/NEMGetAddress.d.ts.map +1 -0
- package/dist/api/nem/NEMSignTransaction.d.ts +20 -0
- package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -0
- package/dist/api/solana/SolGetAddress.d.ts +9 -0
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -0
- package/dist/api/solana/SolSignTransaction.d.ts +17 -0
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -0
- package/dist/api/stellar/StellarGetAddress.d.ts +9 -0
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -0
- package/dist/api/stellar/StellarSignTransaction.d.ts +335 -0
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -0
- package/dist/constants/errors.d.ts +1 -0
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data/version.d.ts +1 -1
- package/dist/data/version.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +1 -0
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +9 -1
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +364 -5
- package/dist/index.js +845 -21
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/cipherKeyValue.d.ts +19 -0
- package/dist/types/api/cipherKeyValue.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +7 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +13 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/nemGetAddress.d.ts +15 -0
- package/dist/types/api/nemGetAddress.d.ts.map +1 -0
- package/dist/types/api/nemSignTransaction.d.ts +93 -0
- package/dist/types/api/nemSignTransaction.d.ts.map +1 -0
- package/dist/types/api/solGetAddress.d.ts +14 -0
- package/dist/types/api/solGetAddress.d.ts.map +1 -0
- package/dist/types/api/solSignTransaction.d.ts +14 -0
- package/dist/types/api/solSignTransaction.d.ts.map +1 -0
- package/dist/types/api/stellarGetAddress.d.ts +14 -0
- package/dist/types/api/stellarGetAddress.d.ts.map +1 -0
- package/dist/types/api/stellarSignTransaction.d.ts +130 -0
- package/dist/types/api/stellarSignTransaction.d.ts.map +1 -0
- package/dist/types/device.d.ts +45 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/firmware.d.ts +2 -1
- package/dist/types/firmware.d.ts.map +1 -1
- package/dist/types/params.d.ts +3 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/utils/assets.d.ts +1 -1
- package/dist/utils/assets.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +49 -2
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/networkUtils.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api/BaseMethod.ts +9 -0
- package/src/api/CipherKeyValue.ts +66 -0
- package/src/api/FirmwareUpdate.ts +78 -0
- package/src/api/device/DeviceRebootToBootloader.ts +11 -0
- package/src/api/evm/EVMSignMessageEIP712.ts +8 -0
- package/src/api/evm/EVMSignTransaction.ts +15 -0
- package/src/api/evm/EVMSignTypedData.ts +55 -15
- package/src/api/firmware/getBinary.ts +46 -0
- package/src/api/firmware/uploadFirmware.ts +72 -0
- package/src/api/helpers/hexUtils.ts +0 -1
- package/src/api/index.ts +12 -0
- package/src/api/nem/NEMGetAddress.ts +61 -0
- package/src/api/nem/NEMSignTransaction.ts +246 -0
- package/src/api/solana/SolGetAddress.ts +59 -0
- package/src/api/solana/SolSignTransaction.ts +69 -0
- package/src/api/stellar/StellarGetAddress.ts +59 -0
- package/src/api/stellar/StellarSignTransaction.ts +213 -0
- package/src/constants/errors.ts +1 -0
- package/src/core/index.ts +40 -5
- package/src/data/version.ts +1 -1
- package/src/device/Device.ts +4 -0
- package/src/device/DeviceCommands.ts +2 -0
- package/src/events/ui-request.ts +15 -1
- package/src/inject.ts +17 -0
- package/src/types/api/cipherKeyValue.ts +26 -0
- package/src/types/api/export.ts +27 -0
- package/src/types/api/firmwareUpdate.ts +21 -0
- package/src/types/api/index.ts +21 -0
- package/src/types/api/nemGetAddress.ts +22 -0
- package/src/types/api/nemSignTransaction.ts +117 -0
- package/src/types/api/solGetAddress.ts +21 -0
- package/src/types/api/solSignTransaction.ts +21 -0
- package/src/types/api/stellarGetAddress.ts +21 -0
- package/src/types/api/stellarSignTransaction.ts +153 -0
- package/src/types/device.ts +52 -0
- package/src/types/firmware.ts +2 -1
- package/src/types/params.ts +2 -0
- package/src/utils/assets.ts +1 -1
- package/src/utils/deviceFeaturesUtils.ts +16 -2
- package/src/utils/networkUtils.ts +3 -1
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NEMAggregateModification,
|
|
3
|
+
NEMImportanceTransfer,
|
|
4
|
+
NEMMosaicCreation,
|
|
5
|
+
NEMMosaicDefinition,
|
|
6
|
+
NEMMosaicSupplyChange,
|
|
7
|
+
NEMProvisionNamespace,
|
|
8
|
+
NEMSignTx,
|
|
9
|
+
NEMTransactionCommon,
|
|
10
|
+
NEMTransfer,
|
|
11
|
+
} from '@onekeyfe/hd-transport/src/types/messages';
|
|
12
|
+
|
|
13
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
14
|
+
import { validatePath } from '../helpers/pathUtils';
|
|
15
|
+
import { BaseMethod } from '../BaseMethod';
|
|
16
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
17
|
+
import {
|
|
18
|
+
NEMAggregateModificationTransaction,
|
|
19
|
+
NEMImportanceTransaction,
|
|
20
|
+
NEMMosaicCreationTransaction,
|
|
21
|
+
NEMProvisionNamespaceTransaction,
|
|
22
|
+
NEMSupplyChangeTransaction,
|
|
23
|
+
NEMTransaction,
|
|
24
|
+
NEMTransferTransaction,
|
|
25
|
+
} from '../../types';
|
|
26
|
+
import { ERRORS } from '../../constants';
|
|
27
|
+
|
|
28
|
+
const NEM_TRANSFER = 0x0101;
|
|
29
|
+
const NEM_COSIGNING = 0x0102;
|
|
30
|
+
const NEM_IMPORTANCE_TRANSFER = 0x0801;
|
|
31
|
+
const NEM_AGGREGATE_MODIFICATION = 0x1001;
|
|
32
|
+
const NEM_MULTISIG_SIGNATURE = 0x1002;
|
|
33
|
+
const NEM_MULTISIG = 0x1004;
|
|
34
|
+
const NEM_PROVISION_NAMESPACE = 0x2001;
|
|
35
|
+
const NEM_MOSAIC_CREATION = 0x4001;
|
|
36
|
+
const NEM_SUPPLY_CHANGE = 0x4002;
|
|
37
|
+
|
|
38
|
+
export default class NEMSignTransaction extends BaseMethod<NEMSignTx> {
|
|
39
|
+
NEM_MOSAIC_LEVY_TYPES: Record<number, string> = {
|
|
40
|
+
1: 'MosaicLevy_Absolute',
|
|
41
|
+
2: 'MosaicLevy_Percentile',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
NEM_SUPPLY_CHANGE_TYPES: Record<number, string> = {
|
|
45
|
+
1: 'SupplyChange_Increase',
|
|
46
|
+
2: 'SupplyChange_Decrease',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
NEM_AGGREGATE_MODIFICATION_TYPES: Record<number, string> = {
|
|
50
|
+
1: 'CosignatoryModification_Add',
|
|
51
|
+
2: 'CosignatoryModification_Delete',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
NEM_IMPORTANCE_TRANSFER_MODES: Record<number, string> = {
|
|
55
|
+
1: 'ImportanceTransfer_Activate',
|
|
56
|
+
2: 'ImportanceTransfer_Deactivate',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
getCommon = (tx: NEMTransaction, address_n?: number[]): NEMTransactionCommon => ({
|
|
60
|
+
address_n,
|
|
61
|
+
// eslint-disable-next-line no-bitwise
|
|
62
|
+
network: (tx.version >> 24) & 0xff,
|
|
63
|
+
timestamp: tx.timeStamp,
|
|
64
|
+
fee: tx.fee,
|
|
65
|
+
deadline: tx.deadline ?? 0,
|
|
66
|
+
signer: address_n ? undefined : tx.signer,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
transferMessage = (tx: NEMTransferTransaction): NEMTransfer => {
|
|
70
|
+
const mosaics = tx.mosaics
|
|
71
|
+
? tx.mosaics.map(mosaic => ({
|
|
72
|
+
namespace: mosaic.mosaicId.namespaceId,
|
|
73
|
+
mosaic: mosaic.mosaicId.name,
|
|
74
|
+
quantity: mosaic.quantity,
|
|
75
|
+
}))
|
|
76
|
+
: undefined;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
recipient: tx.recipient,
|
|
80
|
+
amount: tx.amount,
|
|
81
|
+
payload: tx.message ? tx.message.payload : undefined,
|
|
82
|
+
public_key: tx.message && tx.message.type === 0x02 ? tx.message.publicKey : undefined,
|
|
83
|
+
mosaics,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
importanceTransferMessage = (tx: NEMImportanceTransaction): NEMImportanceTransfer => ({
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
mode: this.NEM_IMPORTANCE_TRANSFER_MODES[tx.importanceTransfer.mode],
|
|
90
|
+
public_key: tx.importanceTransfer.publicKey,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
aggregateModificationMessage = (
|
|
94
|
+
tx: NEMAggregateModificationTransaction
|
|
95
|
+
): NEMAggregateModification => {
|
|
96
|
+
const modifications = tx.modifications
|
|
97
|
+
? tx.modifications.map(modification => ({
|
|
98
|
+
type: this.NEM_AGGREGATE_MODIFICATION_TYPES[modification.modificationType],
|
|
99
|
+
public_key: modification.cosignatoryAccount,
|
|
100
|
+
}))
|
|
101
|
+
: undefined;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
// @ts-expect-error
|
|
105
|
+
modifications,
|
|
106
|
+
relative_change: tx.minCosignatories.relativeChange,
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
provisionNamespaceMessage = (tx: NEMProvisionNamespaceTransaction): NEMProvisionNamespace => ({
|
|
111
|
+
namespace: tx.newPart ?? '',
|
|
112
|
+
parent: tx.parent || undefined,
|
|
113
|
+
sink: tx.rentalFeeSink ?? '',
|
|
114
|
+
fee: tx.rentalFee ?? 0,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
mosaicCreationMessage = (tx: NEMMosaicCreationTransaction): NEMMosaicCreation => {
|
|
118
|
+
const { levy } = tx.mosaicDefinition;
|
|
119
|
+
|
|
120
|
+
const definition: NEMMosaicDefinition = {
|
|
121
|
+
namespace: tx.mosaicDefinition.id.namespaceId,
|
|
122
|
+
mosaic: tx.mosaicDefinition.id.name,
|
|
123
|
+
// @ts-expect-error
|
|
124
|
+
levy: levy && levy.type ? this.NEM_MOSAIC_LEVY_TYPES[levy.type] : undefined,
|
|
125
|
+
fee: levy && levy.fee,
|
|
126
|
+
levy_address: levy && levy.recipient,
|
|
127
|
+
levy_namespace: levy && levy.mosaicId && levy.mosaicId.namespaceId,
|
|
128
|
+
levy_mosaic: levy && levy.mosaicId && levy.mosaicId.name,
|
|
129
|
+
description: tx.mosaicDefinition.description,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const { properties } = tx.mosaicDefinition;
|
|
133
|
+
if (Array.isArray(properties)) {
|
|
134
|
+
properties.forEach(property => {
|
|
135
|
+
const { name, value } = property;
|
|
136
|
+
switch (name) {
|
|
137
|
+
case 'divisibility':
|
|
138
|
+
definition.divisibility = parseInt(value);
|
|
139
|
+
break;
|
|
140
|
+
|
|
141
|
+
case 'initialSupply':
|
|
142
|
+
definition.supply = parseInt(value);
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
case 'supplyMutable':
|
|
146
|
+
definition.mutable_supply = value === 'true';
|
|
147
|
+
break;
|
|
148
|
+
|
|
149
|
+
case 'transferable':
|
|
150
|
+
definition.transferable = value === 'true';
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
definition,
|
|
159
|
+
sink: tx.creationFeeSink ?? '',
|
|
160
|
+
fee: tx.creationFee ?? 0,
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
supplyChangeMessage = (tx: NEMSupplyChangeTransaction): NEMMosaicSupplyChange => ({
|
|
165
|
+
namespace: tx.mosaicId.namespaceId,
|
|
166
|
+
mosaic: tx.mosaicId.name,
|
|
167
|
+
// @ts-expect-error
|
|
168
|
+
type: this.NEM_SUPPLY_CHANGE_TYPES[tx.supplyType],
|
|
169
|
+
delta: tx.delta ?? 0,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
parseTx = (tx: NEMTransaction, address_n: number[]) => {
|
|
173
|
+
let transaction = tx;
|
|
174
|
+
const message: NEMSignTx = {
|
|
175
|
+
transaction: this.getCommon(tx, address_n),
|
|
176
|
+
transfer: undefined,
|
|
177
|
+
importance_transfer: undefined,
|
|
178
|
+
aggregate_modification: undefined,
|
|
179
|
+
provision_namespace: undefined,
|
|
180
|
+
mosaic_creation: undefined,
|
|
181
|
+
supply_change: undefined,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
if (
|
|
185
|
+
tx.type === NEM_COSIGNING ||
|
|
186
|
+
tx.type === NEM_MULTISIG ||
|
|
187
|
+
tx.type === NEM_MULTISIG_SIGNATURE
|
|
188
|
+
) {
|
|
189
|
+
message.cosigning = tx.type === NEM_COSIGNING || tx.type === NEM_MULTISIG_SIGNATURE;
|
|
190
|
+
transaction = tx.otherTrans;
|
|
191
|
+
message.multisig = this.getCommon(transaction);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
switch (transaction.type) {
|
|
195
|
+
case NEM_TRANSFER:
|
|
196
|
+
message.transfer = this.transferMessage(transaction);
|
|
197
|
+
break;
|
|
198
|
+
|
|
199
|
+
case NEM_IMPORTANCE_TRANSFER:
|
|
200
|
+
message.importance_transfer = this.importanceTransferMessage(transaction);
|
|
201
|
+
break;
|
|
202
|
+
|
|
203
|
+
case NEM_AGGREGATE_MODIFICATION:
|
|
204
|
+
message.aggregate_modification = this.aggregateModificationMessage(transaction);
|
|
205
|
+
break;
|
|
206
|
+
|
|
207
|
+
case NEM_PROVISION_NAMESPACE:
|
|
208
|
+
message.provision_namespace = this.provisionNamespaceMessage(transaction);
|
|
209
|
+
break;
|
|
210
|
+
|
|
211
|
+
case NEM_MOSAIC_CREATION:
|
|
212
|
+
message.mosaic_creation = this.mosaicCreationMessage(transaction);
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
case NEM_SUPPLY_CHANGE:
|
|
216
|
+
message.supply_change = this.supplyChangeMessage(transaction);
|
|
217
|
+
break;
|
|
218
|
+
|
|
219
|
+
default:
|
|
220
|
+
throw ERRORS.TypedError('Method_InvalidParameter', 'Unknown transaction type');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return message;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
init() {
|
|
227
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
228
|
+
|
|
229
|
+
validateParams(this.payload, [
|
|
230
|
+
{ name: 'path', required: true },
|
|
231
|
+
{ name: 'transaction', type: 'object', required: true },
|
|
232
|
+
]);
|
|
233
|
+
const { path, transaction } = this.payload;
|
|
234
|
+
const addressN = validatePath(path, 3);
|
|
235
|
+
|
|
236
|
+
this.params = this.parseTx(transaction, addressN);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async run() {
|
|
240
|
+
const res = await this.device.commands.typedCall('NEMSignTx', 'NEMSignedTx', {
|
|
241
|
+
...this.params,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return Promise.resolve(res);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SolanaGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
3
|
+
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
4
|
+
import { BaseMethod } from '../BaseMethod';
|
|
5
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
6
|
+
import { SolanaAddress, SolanaGetAddressParams } from '../../types';
|
|
7
|
+
|
|
8
|
+
export default class SolGetAddress extends BaseMethod<SolanaGetAddress[]> {
|
|
9
|
+
hasBundle = false;
|
|
10
|
+
|
|
11
|
+
init() {
|
|
12
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
13
|
+
|
|
14
|
+
this.hasBundle = !!this.payload?.bundle;
|
|
15
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
16
|
+
|
|
17
|
+
// check payload
|
|
18
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
19
|
+
|
|
20
|
+
// init params
|
|
21
|
+
this.params = [];
|
|
22
|
+
payload.bundle.forEach((batch: SolanaGetAddressParams) => {
|
|
23
|
+
const addressN = validatePath(batch.path, 3);
|
|
24
|
+
|
|
25
|
+
validateParams(batch, [
|
|
26
|
+
{ name: 'path', required: true },
|
|
27
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const showOnOneKey = batch.showOnOneKey ?? true;
|
|
31
|
+
|
|
32
|
+
this.params.push({
|
|
33
|
+
address_n: addressN,
|
|
34
|
+
show_display: showOnOneKey,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async run() {
|
|
40
|
+
const responses: SolanaAddress[] = [];
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
43
|
+
const param = this.params[i];
|
|
44
|
+
|
|
45
|
+
const res = await this.device.commands.typedCall('SolanaGetAddress', 'SolanaAddress', {
|
|
46
|
+
...param,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const { address } = res.message;
|
|
50
|
+
|
|
51
|
+
responses.push({
|
|
52
|
+
path: serializedPath(param.address_n),
|
|
53
|
+
address,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SolanaSignTx as HardwareSolanaSignTx } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
3
|
+
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
4
|
+
import { BaseMethod } from '../BaseMethod';
|
|
5
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
6
|
+
import { SolanaSignedTx, SolanaSignTransactionParams } from '../../types';
|
|
7
|
+
import { formatAnyHex } from '../helpers/hexUtils';
|
|
8
|
+
|
|
9
|
+
export default class SolSignTransaction extends BaseMethod<HardwareSolanaSignTx[]> {
|
|
10
|
+
hasBundle = false;
|
|
11
|
+
|
|
12
|
+
init() {
|
|
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: SolanaSignTransactionParams) => {
|
|
24
|
+
const addressN = validatePath(batch.path, 3);
|
|
25
|
+
|
|
26
|
+
validateParams(batch, [
|
|
27
|
+
{ name: 'path', required: true },
|
|
28
|
+
{ name: 'rawTx', type: 'hexString', required: true },
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
this.params.push({
|
|
32
|
+
address_n: addressN,
|
|
33
|
+
raw_tx: formatAnyHex(batch.rawTx),
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getVersionRange() {
|
|
39
|
+
return {
|
|
40
|
+
classic: {
|
|
41
|
+
min: '2.1.9',
|
|
42
|
+
},
|
|
43
|
+
mini: {
|
|
44
|
+
min: '2.1.9',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async run() {
|
|
50
|
+
const responses: SolanaSignedTx[] = [];
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
53
|
+
const param = this.params[i];
|
|
54
|
+
|
|
55
|
+
const res = await this.device.commands.typedCall('SolanaSignTx', 'SolanaSignedTx', {
|
|
56
|
+
...param,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const { signature } = res.message;
|
|
60
|
+
|
|
61
|
+
responses.push({
|
|
62
|
+
path: serializedPath(param.address_n),
|
|
63
|
+
signature,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { StellarGetAddress as HardwareStellarGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
3
|
+
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
4
|
+
import { BaseMethod } from '../BaseMethod';
|
|
5
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
6
|
+
import { StellarGetAddressParams, StellarAddress } from '../../types';
|
|
7
|
+
|
|
8
|
+
export default class StellarGetAddress extends BaseMethod<HardwareStellarGetAddress[]> {
|
|
9
|
+
hasBundle = false;
|
|
10
|
+
|
|
11
|
+
init() {
|
|
12
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
13
|
+
|
|
14
|
+
this.hasBundle = !!this.payload?.bundle;
|
|
15
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
16
|
+
|
|
17
|
+
// check payload
|
|
18
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
19
|
+
|
|
20
|
+
// init params
|
|
21
|
+
this.params = [];
|
|
22
|
+
payload.bundle.forEach((batch: StellarGetAddressParams) => {
|
|
23
|
+
const addressN = validatePath(batch.path, 3);
|
|
24
|
+
|
|
25
|
+
validateParams(batch, [
|
|
26
|
+
{ name: 'path', required: true },
|
|
27
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const showOnOneKey = batch.showOnOneKey ?? true;
|
|
31
|
+
|
|
32
|
+
this.params.push({
|
|
33
|
+
address_n: addressN,
|
|
34
|
+
show_display: showOnOneKey,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async run() {
|
|
40
|
+
const responses: StellarAddress[] = [];
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
43
|
+
const param = this.params[i];
|
|
44
|
+
|
|
45
|
+
const res = await this.device.commands.typedCall('StellarGetAddress', 'StellarAddress', {
|
|
46
|
+
...param,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const { address } = res.message;
|
|
50
|
+
|
|
51
|
+
responses.push({
|
|
52
|
+
path: serializedPath(param.address_n),
|
|
53
|
+
address,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StellarSignedTx,
|
|
3
|
+
StellarSignTx as HardwareStellarSignTx,
|
|
4
|
+
} from '@onekeyfe/hd-transport/src/types/messages';
|
|
5
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
6
|
+
import { validatePath } from '../helpers/pathUtils';
|
|
7
|
+
import { BaseMethod } from '../BaseMethod';
|
|
8
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
9
|
+
import { StellarOperation, StellarSignTransactionParams } from '../../types';
|
|
10
|
+
|
|
11
|
+
export default class StellarSignTransaction extends BaseMethod<HardwareStellarSignTx> {
|
|
12
|
+
operations: any[] = [];
|
|
13
|
+
|
|
14
|
+
parseOperation = (op: StellarOperation) => {
|
|
15
|
+
switch (op.type) {
|
|
16
|
+
case 'createAccount':
|
|
17
|
+
validateParams(op, [
|
|
18
|
+
{ name: 'destination', type: 'string', required: true },
|
|
19
|
+
{ name: 'startingBalance', type: 'bigNumber', required: true },
|
|
20
|
+
]);
|
|
21
|
+
return {
|
|
22
|
+
type: 'StellarCreateAccountOp',
|
|
23
|
+
source_account: op.source,
|
|
24
|
+
new_account: op.destination,
|
|
25
|
+
starting_balance: op.startingBalance,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
case 'payment':
|
|
29
|
+
validateParams(op, [
|
|
30
|
+
{ name: 'destination', type: 'string', required: true },
|
|
31
|
+
{ name: 'amount', type: 'bigNumber', required: true },
|
|
32
|
+
{ name: 'asset', required: true },
|
|
33
|
+
]);
|
|
34
|
+
return {
|
|
35
|
+
type: 'StellarPaymentOp',
|
|
36
|
+
source_account: op.source,
|
|
37
|
+
destination_account: op.destination,
|
|
38
|
+
asset: op.asset,
|
|
39
|
+
amount: op.amount,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
case 'pathPayment':
|
|
43
|
+
validateParams(op, [{ name: 'destAmount', type: 'bigNumber', required: true }]);
|
|
44
|
+
return {
|
|
45
|
+
type: 'StellarPathPaymentOp',
|
|
46
|
+
source_account: op.source,
|
|
47
|
+
send_asset: op.sendAsset,
|
|
48
|
+
send_max: op.sendMax,
|
|
49
|
+
destination_account: op.destination,
|
|
50
|
+
destination_asset: op.destAsset,
|
|
51
|
+
destination_amount: op.destAmount,
|
|
52
|
+
paths: op.path,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
case 'createPassiveOffer':
|
|
56
|
+
validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
|
|
57
|
+
return {
|
|
58
|
+
type: 'StellarCreatePassiveOfferOp',
|
|
59
|
+
source_account: op.source,
|
|
60
|
+
buying_asset: op.buying,
|
|
61
|
+
selling_asset: op.selling,
|
|
62
|
+
amount: op.amount,
|
|
63
|
+
price_n: op.price.n,
|
|
64
|
+
price_d: op.price.d,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
case 'manageOffer':
|
|
68
|
+
validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
|
|
69
|
+
return {
|
|
70
|
+
type: 'StellarManageOfferOp',
|
|
71
|
+
source_account: op.source,
|
|
72
|
+
buying_asset: op.buying,
|
|
73
|
+
selling_asset: op.selling,
|
|
74
|
+
amount: op.amount,
|
|
75
|
+
offer_id: op.offerId,
|
|
76
|
+
price_n: op.price.n,
|
|
77
|
+
price_d: op.price.d,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
case 'setOptions': {
|
|
81
|
+
const signer = op.signer
|
|
82
|
+
? {
|
|
83
|
+
signer_type: op.signer.type,
|
|
84
|
+
signer_key: op.signer.key,
|
|
85
|
+
signer_weight: op.signer.weight,
|
|
86
|
+
}
|
|
87
|
+
: undefined;
|
|
88
|
+
return {
|
|
89
|
+
type: 'StellarSetOptionsOp',
|
|
90
|
+
source_account: op.source,
|
|
91
|
+
clear_flags: op.clearFlags,
|
|
92
|
+
set_flags: op.setFlags,
|
|
93
|
+
master_weight: op.masterWeight,
|
|
94
|
+
low_threshold: op.lowThreshold,
|
|
95
|
+
medium_threshold: op.medThreshold,
|
|
96
|
+
high_threshold: op.highThreshold,
|
|
97
|
+
home_domain: op.homeDomain,
|
|
98
|
+
inflation_destination_account: op.inflationDest,
|
|
99
|
+
...signer,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
case 'changeTrust':
|
|
104
|
+
validateParams(op, [{ name: 'limit', type: 'bigNumber' }]);
|
|
105
|
+
return {
|
|
106
|
+
type: 'StellarChangeTrustOp',
|
|
107
|
+
source_account: op.source,
|
|
108
|
+
asset: op.line,
|
|
109
|
+
limit: op.limit,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
case 'allowTrust':
|
|
113
|
+
return {
|
|
114
|
+
type: 'StellarAllowTrustOp',
|
|
115
|
+
source_account: op.source,
|
|
116
|
+
trusted_account: op.trustor,
|
|
117
|
+
asset_type: op.assetType,
|
|
118
|
+
asset_code: op.assetCode,
|
|
119
|
+
is_authorized: op.authorize ? 1 : 0,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
case 'accountMerge':
|
|
123
|
+
return {
|
|
124
|
+
type: 'StellarAccountMergeOp',
|
|
125
|
+
source_account: op.source,
|
|
126
|
+
destination_account: op.destination,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
case 'manageData':
|
|
130
|
+
return {
|
|
131
|
+
type: 'StellarManageDataOp',
|
|
132
|
+
source_account: op.source,
|
|
133
|
+
key: op.name,
|
|
134
|
+
value: op.value,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
case 'bumpSequence':
|
|
138
|
+
return {
|
|
139
|
+
type: 'StellarBumpSequenceOp',
|
|
140
|
+
source_account: op.source,
|
|
141
|
+
bump_to: op.bumpTo,
|
|
142
|
+
};
|
|
143
|
+
default:
|
|
144
|
+
return {};
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
init() {
|
|
149
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
150
|
+
|
|
151
|
+
// check payload
|
|
152
|
+
validateParams(this.payload, [
|
|
153
|
+
{ name: 'path', required: true },
|
|
154
|
+
{ name: 'networkPassphrase', type: 'string', required: true },
|
|
155
|
+
{ name: 'transaction', type: 'object', required: true },
|
|
156
|
+
]);
|
|
157
|
+
|
|
158
|
+
// init params
|
|
159
|
+
const addressN = validatePath(this.payload.path, 3);
|
|
160
|
+
const { transaction, networkPassphrase } = this.payload as StellarSignTransactionParams;
|
|
161
|
+
|
|
162
|
+
this.params = {
|
|
163
|
+
address_n: addressN,
|
|
164
|
+
network_passphrase: networkPassphrase,
|
|
165
|
+
source_account: transaction.source,
|
|
166
|
+
fee: transaction.fee,
|
|
167
|
+
sequence_number: transaction.sequence,
|
|
168
|
+
num_operations: transaction.operations.length,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
if (transaction.timebounds) {
|
|
172
|
+
this.params.timebounds_start = transaction.timebounds.minTime;
|
|
173
|
+
this.params.timebounds_end = transaction.timebounds.maxTime;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (transaction.memo) {
|
|
177
|
+
this.params.memo_type = transaction.memo.type;
|
|
178
|
+
this.params.memo_text = transaction.memo.text;
|
|
179
|
+
this.params.memo_id = transaction.memo.id;
|
|
180
|
+
this.params.memo_hash = transaction.memo.hash;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
transaction.operations.forEach(op => {
|
|
184
|
+
const transformed = this.parseOperation(op);
|
|
185
|
+
if (transformed) {
|
|
186
|
+
this.operations.push(transformed);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
console.log('StellarSignTransactionParams', this.params);
|
|
191
|
+
console.log('StellarSignTransactionOperations', this.operations);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
processTxRequest = async (operations: any, index: number): Promise<StellarSignedTx> => {
|
|
195
|
+
const isLastOp = index + 1 >= operations.length;
|
|
196
|
+
const { type, ...op } = operations[index];
|
|
197
|
+
|
|
198
|
+
if (isLastOp) {
|
|
199
|
+
const response = await this.device.commands.typedCall(type, 'StellarSignedTx', op);
|
|
200
|
+
return response.message;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
await this.device.commands.typedCall(type, 'StellarTxOpRequest', op);
|
|
204
|
+
|
|
205
|
+
return this.processTxRequest(operations, index + 1);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
async run() {
|
|
209
|
+
await this.device.commands.typedCall('StellarSignTx', 'StellarTxOpRequest', { ...this.params });
|
|
210
|
+
|
|
211
|
+
return this.processTxRequest(this.operations, 0);
|
|
212
|
+
}
|
|
213
|
+
}
|