@onekeyfe/hd-core 0.1.54 → 0.1.56
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/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts +7 -1
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetPublicKey.d.ts +18 -0
- package/dist/api/aptos/AptosGetPublicKey.d.ts.map +1 -0
- package/dist/api/device/DeviceUpdateReboot.d.ts +2 -2
- package/dist/api/device/DeviceUpdateReboot.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +3 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/index.d.ts +19 -14
- package/dist/index.js +209 -68
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/aptosGetPublicKey.d.ts +14 -0
- package/dist/types/api/aptosGetPublicKey.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +1 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/api/GetPassphraseState.ts +3 -0
- package/src/api/aptos/AptosGetAddress.ts +13 -6
- package/src/api/aptos/AptosGetPublicKey.ts +60 -0
- package/src/api/aptos/AptosSignTransaction.ts +1 -1
- package/src/api/device/DeviceUpdateReboot.ts +3 -3
- package/src/api/helpers/hexUtils.ts +1 -1
- package/src/api/index.ts +1 -1
- package/src/data/coins/bitcoin.json +1 -0
- package/src/data/messages/messages.json +115 -13
- package/src/device/Device.ts +30 -14
- package/src/device/DeviceCommands.ts +5 -2
- package/src/inject.ts +2 -6
- package/src/types/api/aptosGetPublicKey.ts +23 -0
- package/src/types/api/export.ts +1 -0
- package/src/types/api/index.ts +2 -2
- package/dist/api/BatchGetPublicKey.d.ts +0 -11
- package/dist/api/BatchGetPublicKey.d.ts.map +0 -1
- package/dist/types/api/batchGetPublicKey.d.ts +0 -11
- package/dist/types/api/batchGetPublicKey.d.ts.map +0 -1
- package/src/api/BatchGetPublicKey.ts +0 -40
- package/src/types/api/batchGetPublicKey.ts +0 -18
package/src/device/Device.ts
CHANGED
|
@@ -251,6 +251,13 @@ export class Device extends EventEmitter {
|
|
|
251
251
|
return this.commands;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
private generateStateKey(deviceId: string, passphraseState?: string) {
|
|
255
|
+
if (passphraseState) {
|
|
256
|
+
return `${deviceId}@${passphraseState}`;
|
|
257
|
+
}
|
|
258
|
+
return deviceId;
|
|
259
|
+
}
|
|
260
|
+
|
|
254
261
|
getInternalState(_deviceId?: string) {
|
|
255
262
|
Log.debug(
|
|
256
263
|
'getInternalState session param: ',
|
|
@@ -264,19 +271,27 @@ export class Device extends EventEmitter {
|
|
|
264
271
|
if (!deviceId) return undefined;
|
|
265
272
|
if (!this.passphraseState) return undefined;
|
|
266
273
|
|
|
267
|
-
const usePassKey =
|
|
274
|
+
const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
|
|
275
|
+
return deviceSessionCache[usePassKey];
|
|
276
|
+
}
|
|
268
277
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
278
|
+
tryFixInternalState(state: string, deviceId: string) {
|
|
279
|
+
Log.debug(
|
|
280
|
+
'tryFixInternalState session param: ',
|
|
281
|
+
`device_id: ${deviceId}`,
|
|
282
|
+
`passphraseState: ${state}`
|
|
283
|
+
);
|
|
275
284
|
|
|
276
|
-
|
|
285
|
+
const key = `${deviceId}`;
|
|
286
|
+
const session = deviceSessionCache[key];
|
|
287
|
+
if (session) {
|
|
288
|
+
deviceSessionCache[this.generateStateKey(deviceId, state)] = session;
|
|
289
|
+
delete deviceSessionCache[key];
|
|
290
|
+
}
|
|
291
|
+
Log.debug('tryFixInternalState session cache: ', deviceSessionCache);
|
|
277
292
|
}
|
|
278
293
|
|
|
279
|
-
setInternalState(state: string, initSession?: boolean) {
|
|
294
|
+
private setInternalState(state: string, initSession?: boolean) {
|
|
280
295
|
Log.debug(
|
|
281
296
|
'setInternalState session param: ',
|
|
282
297
|
`state: ${state}`,
|
|
@@ -288,10 +303,11 @@ export class Device extends EventEmitter {
|
|
|
288
303
|
if (!this.features) return;
|
|
289
304
|
if (!this.passphraseState && !initSession) return;
|
|
290
305
|
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
306
|
+
const deviceId = this.features?.device_id;
|
|
307
|
+
if (!deviceId) return;
|
|
308
|
+
|
|
309
|
+
const key = this.generateStateKey(deviceId, this.passphraseState);
|
|
310
|
+
|
|
295
311
|
if (state) {
|
|
296
312
|
deviceSessionCache[key] = state;
|
|
297
313
|
}
|
|
@@ -307,7 +323,7 @@ export class Device extends EventEmitter {
|
|
|
307
323
|
delete deviceSessionCache[key];
|
|
308
324
|
|
|
309
325
|
if (this.passphraseState) {
|
|
310
|
-
const usePassKey =
|
|
326
|
+
const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
|
|
311
327
|
delete deviceSessionCache[usePassKey];
|
|
312
328
|
}
|
|
313
329
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Transport, Messages } from '@onekeyfe/hd-transport';
|
|
1
|
+
import type { Transport, Messages, FailureType } from '@onekeyfe/hd-transport';
|
|
2
2
|
import { ERRORS, HardwareError, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
3
|
import TransportManager from '../data-manager/TransportManager';
|
|
4
4
|
import DataManager from '../data-manager/DataManager';
|
|
@@ -146,7 +146,10 @@ export class DeviceCommands {
|
|
|
146
146
|
): Promise<DefaultMessageResponse> {
|
|
147
147
|
Log.debug('_filterCommonTypes: ', res);
|
|
148
148
|
if (res.type === 'Failure') {
|
|
149
|
-
const { code, message } = res.message
|
|
149
|
+
const { code, message } = res.message as {
|
|
150
|
+
code?: string | FailureType;
|
|
151
|
+
message?: string;
|
|
152
|
+
};
|
|
150
153
|
let error: HardwareError | null = null;
|
|
151
154
|
// Model One does not send any message in firmware update
|
|
152
155
|
if (code === 'Failure_FirmwareError' && !message) {
|
package/src/inject.ts
CHANGED
|
@@ -53,12 +53,6 @@ export const inject = ({
|
|
|
53
53
|
*/
|
|
54
54
|
getFeatures: connectId => call({ connectId, method: 'getFeatures' }),
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* 批量获取公钥
|
|
58
|
-
*/
|
|
59
|
-
batchGetPublicKey: (connectId, deviceId, params) =>
|
|
60
|
-
call({ ...params, connectId, deviceId, method: 'batchGetPublicKey' }),
|
|
61
|
-
|
|
62
56
|
/**
|
|
63
57
|
* 检查固件版本
|
|
64
58
|
*/
|
|
@@ -177,6 +171,8 @@ export const inject = ({
|
|
|
177
171
|
|
|
178
172
|
aptosGetAddress: (connectId, deviceId, params) =>
|
|
179
173
|
call({ ...params, connectId, deviceId, method: 'aptosGetAddress' }),
|
|
174
|
+
aptosGetPublicKey: (connectId, deviceId, params) =>
|
|
175
|
+
call({ ...params, connectId, deviceId, method: 'aptosGetPublicKey' }),
|
|
180
176
|
aptosSignTransaction: (connectId, deviceId, params) =>
|
|
181
177
|
call({ ...params, connectId, deviceId, method: 'aptosSignTransaction' }),
|
|
182
178
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CommonParams, Response } from '../params';
|
|
2
|
+
|
|
3
|
+
export type AptosPublicKey = {
|
|
4
|
+
path: string;
|
|
5
|
+
publicKey: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type AptosGetPublicKeyParams = {
|
|
9
|
+
path: string | number[];
|
|
10
|
+
showOnOneKey?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export declare function aptosGetPublicKey(
|
|
14
|
+
connectId: string,
|
|
15
|
+
deviceId: string,
|
|
16
|
+
params: CommonParams & AptosGetPublicKeyParams
|
|
17
|
+
): Response<AptosPublicKey>;
|
|
18
|
+
|
|
19
|
+
export declare function aptosGetPublicKey(
|
|
20
|
+
connectId: string,
|
|
21
|
+
deviceId: string,
|
|
22
|
+
params: CommonParams & { bundle?: AptosGetPublicKeyParams[] }
|
|
23
|
+
): Response<Array<AptosPublicKey>>;
|
package/src/types/api/export.ts
CHANGED
|
@@ -94,4 +94,5 @@ export type { NearAddress, NearGetAddressParams } from './nearGetAddress';
|
|
|
94
94
|
export type { NearSignTransactionParams } from './nearSignTransaction';
|
|
95
95
|
|
|
96
96
|
export type { AptosAddress, AptosGetAddressParams } from './aptosGetAddress';
|
|
97
|
+
export type { AptosPublicKey, AptosGetPublicKeyParams } from './aptosGetPublicKey';
|
|
97
98
|
export type { AptosSignedTx, AptosSignTransactionParams } from './aptosSignTransaction';
|
package/src/types/api/index.ts
CHANGED
|
@@ -26,7 +26,6 @@ import { deviceFlags } from './deviceFlags';
|
|
|
26
26
|
import { deviceUpdateReboot } from './deviceUpdateReboot';
|
|
27
27
|
import { deviceSupportFeatures } from './deviceSupportFeatures';
|
|
28
28
|
|
|
29
|
-
import { batchGetPublicKey } from './batchGetPublicKey';
|
|
30
29
|
import { cipherKeyValue } from './cipherKeyValue';
|
|
31
30
|
|
|
32
31
|
import { evmGetAddress } from './evmGetAddress';
|
|
@@ -71,6 +70,7 @@ import { nearGetAddress } from './nearGetAddress';
|
|
|
71
70
|
import { nearSignTransaction } from './nearSignTransaction';
|
|
72
71
|
|
|
73
72
|
import { aptosGetAddress } from './aptosGetAddress';
|
|
73
|
+
import { aptosGetPublicKey } from './aptosGetPublicKey';
|
|
74
74
|
import { aptosSignTransaction } from './aptosSignTransaction';
|
|
75
75
|
|
|
76
76
|
export * from './export';
|
|
@@ -118,7 +118,6 @@ export type CoreApi = {
|
|
|
118
118
|
firmwareUpdate: typeof firmwareUpdate;
|
|
119
119
|
firmwareUpdateV2: typeof firmwareUpdate;
|
|
120
120
|
|
|
121
|
-
batchGetPublicKey: typeof batchGetPublicKey;
|
|
122
121
|
cipherKeyValue: typeof cipherKeyValue;
|
|
123
122
|
|
|
124
123
|
/**
|
|
@@ -193,5 +192,6 @@ export type CoreApi = {
|
|
|
193
192
|
* Aptos function
|
|
194
193
|
*/
|
|
195
194
|
aptosGetAddress: typeof aptosGetAddress;
|
|
195
|
+
aptosGetPublicKey: typeof aptosGetPublicKey;
|
|
196
196
|
aptosSignTransaction: typeof aptosSignTransaction;
|
|
197
197
|
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from './BaseMethod';
|
|
2
|
-
export default class BatchGetPublicKey extends BaseMethod {
|
|
3
|
-
init(): void;
|
|
4
|
-
getVersionRange(): {
|
|
5
|
-
model_mini: {
|
|
6
|
-
min: string;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
run(): Promise<any>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=BatchGetPublicKey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BatchGetPublicKey.d.ts","sourceRoot":"","sources":["../../src/api/BatchGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU;IACvD,IAAI;IAaJ,eAAe;;;;;IAQT,GAAG;CAaV"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { CommonParams, Response } from '../params';
|
|
2
|
-
export declare type BatchGetPublicKeyParams = {
|
|
3
|
-
paths: string[];
|
|
4
|
-
ecdsaCurveName: 'secp256k1' | 'ed25519';
|
|
5
|
-
};
|
|
6
|
-
export declare type BatchGetPublicKeyResponse = {
|
|
7
|
-
path: string;
|
|
8
|
-
publicKey: string;
|
|
9
|
-
}[];
|
|
10
|
-
export declare function batchGetPublicKey(connectId: string, deviceId: string, params: CommonParams & BatchGetPublicKeyParams): Response<BatchGetPublicKeyResponse>;
|
|
11
|
-
//# sourceMappingURL=batchGetPublicKey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batchGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/types/api/batchGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,oBAAY,uBAAuB,GAAG;IACpC,KAAK,EAAE,MAAM,EAAE,CAAC;IAKhB,cAAc,EAAE,WAAW,GAAG,SAAS,CAAC;CACzC,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC;AAE9E,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,uBAAuB,GAC7C,QAAQ,CAAC,yBAAyB,CAAC,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from './BaseMethod';
|
|
2
|
-
import { validateParams } from './helpers/paramsValidator';
|
|
3
|
-
import { validatePath, serializedPath } from './helpers/pathUtils';
|
|
4
|
-
|
|
5
|
-
export default class BatchGetPublicKey extends BaseMethod {
|
|
6
|
-
init() {
|
|
7
|
-
this.checkDeviceId = true;
|
|
8
|
-
validateParams(this.payload, [
|
|
9
|
-
{ name: 'paths', type: 'array' },
|
|
10
|
-
{ name: 'ecdsaCurveName', type: 'string' },
|
|
11
|
-
]);
|
|
12
|
-
|
|
13
|
-
this.params = this.payload.paths.map((path: string) => {
|
|
14
|
-
const addressN = validatePath(path, 1);
|
|
15
|
-
return { address_n: addressN };
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getVersionRange() {
|
|
20
|
-
return {
|
|
21
|
-
model_mini: {
|
|
22
|
-
min: '2.6.0',
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async run() {
|
|
28
|
-
// @ts-expect-error
|
|
29
|
-
const res = await this.device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
|
|
30
|
-
paths: this.params,
|
|
31
|
-
ecdsa_curve_name: this.payload.ecdsaCurveName ?? 'secp256k1',
|
|
32
|
-
});
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
const result = res.message.public_keys.map((publicKey: string, index: number) => ({
|
|
35
|
-
path: serializedPath((this.params as unknown as any[])[index].address_n),
|
|
36
|
-
publicKey,
|
|
37
|
-
}));
|
|
38
|
-
return Promise.resolve(result);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CommonParams, Response } from '../params';
|
|
2
|
-
|
|
3
|
-
export type BatchGetPublicKeyParams = {
|
|
4
|
-
paths: string[];
|
|
5
|
-
/**
|
|
6
|
-
* secp256k1 for eth and btc
|
|
7
|
-
* ed25519 for sol, stc, aptos
|
|
8
|
-
*/
|
|
9
|
-
ecdsaCurveName: 'secp256k1' | 'ed25519';
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type BatchGetPublicKeyResponse = { path: string; publicKey: string }[];
|
|
13
|
-
|
|
14
|
-
export declare function batchGetPublicKey(
|
|
15
|
-
connectId: string,
|
|
16
|
-
deviceId: string,
|
|
17
|
-
params: CommonParams & BatchGetPublicKeyParams
|
|
18
|
-
): Response<BatchGetPublicKeyResponse>;
|