@onekeyfe/hd-core 1.2.7 → 1.2.8-alpha.10
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/README.md +27 -0
- package/__tests__/btc-derive-context-hash.test.ts +200 -0
- package/__tests__/device-lifecycle-events.test.ts +51 -7
- package/__tests__/device-pool-state.test.ts +50 -0
- package/dist/api/btc/BTCDeriveContextHash.d.ts +16 -0
- package/dist/api/btc/BTCDeriveContextHash.d.ts.map +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +15 -3
- package/dist/index.js +137 -3
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/btcDeriveContextHash.d.ts +10 -0
- package/dist/types/api/btcDeriveContextHash.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 -0
- 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 +4 -4
- package/src/api/btc/BTCDeriveContextHash.ts +90 -0
- package/src/api/index.ts +1 -0
- package/src/core/index.ts +1 -1
- package/src/data/messages/messages.json +51 -0
- package/src/device/Device.ts +10 -0
- package/src/device/DevicePool.ts +12 -2
- package/src/events/logBlockEvent.ts +1 -0
- package/src/inject.ts +2 -0
- package/src/types/api/btcDeriveContextHash.ts +15 -0
- package/src/types/api/export.ts +1 -0
- package/src/types/api/index.ts +2 -0
|
@@ -12485,6 +12485,8 @@
|
|
|
12485
12485
|
"(has_bitcoin_only_values)": true
|
|
12486
12486
|
},
|
|
12487
12487
|
"values": {
|
|
12488
|
+
"MessageType_BabylonDeriveContextHash": 10054,
|
|
12489
|
+
"MessageType_BabylonDerivedContextHash": 10055,
|
|
12488
12490
|
"MessageType_Initialize": 0,
|
|
12489
12491
|
"MessageType_Ping": 1,
|
|
12490
12492
|
"MessageType_Success": 2,
|
|
@@ -12949,6 +12951,55 @@
|
|
|
12949
12951
|
"MessageType_UpgradeFileHeader": 10050
|
|
12950
12952
|
}
|
|
12951
12953
|
},
|
|
12954
|
+
"CanonicalBitcoinNetwork": {
|
|
12955
|
+
"values": {
|
|
12956
|
+
"BITCOIN_MAINNET": 0,
|
|
12957
|
+
"BITCOIN_TESTNET": 1,
|
|
12958
|
+
"BITCOIN_SIGNET": 2,
|
|
12959
|
+
"BITCOIN_REGTEST": 3
|
|
12960
|
+
}
|
|
12961
|
+
},
|
|
12962
|
+
"BabylonDeriveContextHash": {
|
|
12963
|
+
"fields": {
|
|
12964
|
+
"address_n": {
|
|
12965
|
+
"rule": "repeated",
|
|
12966
|
+
"type": "uint32",
|
|
12967
|
+
"id": 1,
|
|
12968
|
+
"options": {
|
|
12969
|
+
"packed": false
|
|
12970
|
+
}
|
|
12971
|
+
},
|
|
12972
|
+
"script_type": {
|
|
12973
|
+
"rule": "required",
|
|
12974
|
+
"type": "InputScriptType",
|
|
12975
|
+
"id": 2
|
|
12976
|
+
},
|
|
12977
|
+
"app_name": {
|
|
12978
|
+
"rule": "required",
|
|
12979
|
+
"type": "bytes",
|
|
12980
|
+
"id": 3
|
|
12981
|
+
},
|
|
12982
|
+
"context": {
|
|
12983
|
+
"rule": "required",
|
|
12984
|
+
"type": "bytes",
|
|
12985
|
+
"id": 4
|
|
12986
|
+
},
|
|
12987
|
+
"network": {
|
|
12988
|
+
"rule": "required",
|
|
12989
|
+
"type": "CanonicalBitcoinNetwork",
|
|
12990
|
+
"id": 5
|
|
12991
|
+
}
|
|
12992
|
+
}
|
|
12993
|
+
},
|
|
12994
|
+
"BabylonDerivedContextHash": {
|
|
12995
|
+
"fields": {
|
|
12996
|
+
"secret": {
|
|
12997
|
+
"rule": "required",
|
|
12998
|
+
"type": "bytes",
|
|
12999
|
+
"id": 1
|
|
13000
|
+
}
|
|
13001
|
+
}
|
|
13002
|
+
},
|
|
12952
13003
|
"google": {
|
|
12953
13004
|
"nested": {
|
|
12954
13005
|
"protobuf": {
|
package/src/device/Device.ts
CHANGED
|
@@ -248,6 +248,9 @@ export class Device extends EventEmitter {
|
|
|
248
248
|
/** Canonical device-state cache; legacy Features is a compatibility projection. */
|
|
249
249
|
private stateStore = new DeviceStateStore();
|
|
250
250
|
|
|
251
|
+
/** Retain the old public identity only for disconnect notifications after wipe. */
|
|
252
|
+
private deviceBeforeWipe: DeviceTyped | null = null;
|
|
253
|
+
|
|
251
254
|
/** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
|
|
252
255
|
private protocolV2StateNeedsReload = false;
|
|
253
256
|
|
|
@@ -351,6 +354,8 @@ export class Device extends EventEmitter {
|
|
|
351
354
|
toMessageObject(): DeviceTyped | null {
|
|
352
355
|
if (this.isUnacquired() || !this.features) return null;
|
|
353
356
|
|
|
357
|
+
this.deviceBeforeWipe = null;
|
|
358
|
+
|
|
354
359
|
const env = DataManager.getSettings('env');
|
|
355
360
|
const deviceType = this.getCurrentDeviceType();
|
|
356
361
|
|
|
@@ -395,6 +400,10 @@ export class Device extends EventEmitter {
|
|
|
395
400
|
};
|
|
396
401
|
}
|
|
397
402
|
|
|
403
|
+
toDisconnectMessageObject(): DeviceTyped | null {
|
|
404
|
+
return this.toMessageObject() ?? this.deviceBeforeWipe;
|
|
405
|
+
}
|
|
406
|
+
|
|
398
407
|
/**
|
|
399
408
|
* Device connect
|
|
400
409
|
* @returns {Promise<boolean>}
|
|
@@ -1364,6 +1373,7 @@ export class Device extends EventEmitter {
|
|
|
1364
1373
|
}
|
|
1365
1374
|
|
|
1366
1375
|
invalidateAfterWipe() {
|
|
1376
|
+
this.deviceBeforeWipe = this.toMessageObject() ?? this.deviceBeforeWipe;
|
|
1367
1377
|
const deviceId = this.getCurrentDeviceId();
|
|
1368
1378
|
if (deviceId) {
|
|
1369
1379
|
deviceWalletSessionStore.deleteDevice(deviceId);
|
package/src/device/DevicePool.ts
CHANGED
|
@@ -114,7 +114,11 @@ export class DevicePool extends EventEmitter {
|
|
|
114
114
|
const exist = canPathIdentifyDevice(cachedPath)
|
|
115
115
|
? descriptorList.find(d => d.path === cachedPath)
|
|
116
116
|
: undefined;
|
|
117
|
-
if (
|
|
117
|
+
if (
|
|
118
|
+
exist &&
|
|
119
|
+
!initOptions?.forceProtocolDetection &&
|
|
120
|
+
!(device.needReloadDevice && device.isUnacquired())
|
|
121
|
+
) {
|
|
118
122
|
// Log.debug('find existed Device: ', connectId);
|
|
119
123
|
device.updateDescriptor(exist, true);
|
|
120
124
|
await this._refreshRuntimeState(device, initOptions);
|
|
@@ -170,7 +174,13 @@ export class DevicePool extends EventEmitter {
|
|
|
170
174
|
const forceProtocolDetection = initOptions?.forceProtocolDetection === true;
|
|
171
175
|
const isNewDevice = !cachedDevice;
|
|
172
176
|
const device = cachedDevice ?? Device.fromDescriptor(descriptor);
|
|
173
|
-
if (
|
|
177
|
+
if (
|
|
178
|
+
isNewDevice ||
|
|
179
|
+
forceProtocolDetection ||
|
|
180
|
+
(device.needReloadDevice && device.isUnacquired())
|
|
181
|
+
) {
|
|
182
|
+
// Wipe invalidates state while the same USB path can remain discoverable.
|
|
183
|
+
if (cachedDevice) device.updateDescriptor(descriptor, true);
|
|
174
184
|
device.deviceConnector = this.connector;
|
|
175
185
|
// Search/discovery acquires outside Device.run(). Start a new attempt so
|
|
176
186
|
// a previous user cancel does not hide this device from later searches.
|
|
@@ -11,6 +11,7 @@ export const LogBlockEvent: Set<string> = new Set([
|
|
|
11
11
|
// These resource/file APIs did not exist in 1.1.32. Skip the payload so
|
|
12
12
|
// the log layer does not copy huge Base64 or binary data.
|
|
13
13
|
const LogPayloadBlockMethod: Set<string> = new Set([
|
|
14
|
+
'btcDeriveContextHash',
|
|
14
15
|
'deviceUploadNft',
|
|
15
16
|
'deviceUploadWallpaper',
|
|
16
17
|
'uploadPortfolio',
|
package/src/inject.ts
CHANGED
|
@@ -309,6 +309,8 @@ export const createCoreApi = (
|
|
|
309
309
|
call({ ...params, connectId, deviceId, method: 'btcGetAddress' }),
|
|
310
310
|
btcGetPublicKey: (connectId, deviceId, params) =>
|
|
311
311
|
call({ ...params, connectId, deviceId, method: 'btcGetPublicKey' }),
|
|
312
|
+
btcDeriveContextHash: (connectId, deviceId, params) =>
|
|
313
|
+
call({ ...params, connectId, deviceId, method: 'btcDeriveContextHash' }),
|
|
312
314
|
btcSignMessage: (connectId, deviceId, params) =>
|
|
313
315
|
call({ ...params, connectId, deviceId, method: 'btcSignMessage' }),
|
|
314
316
|
btcSignPsbt: (connectId, deviceId, params) =>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BabylonDerivedContextHash } from '@onekeyfe/hd-transport';
|
|
2
|
+
import type { CommonParams, Response } from '../params';
|
|
3
|
+
|
|
4
|
+
export type BTCDeriveContextHashParams = {
|
|
5
|
+
path: string | number[];
|
|
6
|
+
appName: string;
|
|
7
|
+
context: string;
|
|
8
|
+
network: 'bitcoin-mainnet' | 'bitcoin-testnet' | 'bitcoin-signet' | 'bitcoin-regtest';
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export declare function btcDeriveContextHash(
|
|
12
|
+
connectId: string,
|
|
13
|
+
deviceId: string,
|
|
14
|
+
params: CommonParams & BTCDeriveContextHashParams
|
|
15
|
+
): Response<BabylonDerivedContextHash>;
|
package/src/types/api/export.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { BTCAddress, BTCGetAddressParams } from './btcGetAddress';
|
|
2
2
|
export type { BTCPublicKey, BTCGetPublicKeyParams } from './btcGetPublicKey';
|
|
3
|
+
export type { BTCDeriveContextHashParams } from './btcDeriveContextHash';
|
|
3
4
|
export type { BTCSignMessageParams } from './btcSignMessage';
|
|
4
5
|
export type { BTCVerifyMessageParams } from './btcVerifyMessage';
|
|
5
6
|
export type {
|
package/src/types/api/index.ts
CHANGED
|
@@ -73,6 +73,7 @@ import type { evmSignTypedData } from './evmSignTypedData';
|
|
|
73
73
|
import type { evmVerifyMessage } from './evmVerifyMessage';
|
|
74
74
|
import type { btcGetAddress } from './btcGetAddress';
|
|
75
75
|
import type { btcGetPublicKey } from './btcGetPublicKey';
|
|
76
|
+
import type { btcDeriveContextHash } from './btcDeriveContextHash';
|
|
76
77
|
import type { btcSignMessage } from './btcSignMessage';
|
|
77
78
|
import type { btcSignPsbt } from './btcSignPsbt';
|
|
78
79
|
import type { btcSignTransaction } from './btcSignTransaction';
|
|
@@ -286,6 +287,7 @@ export type CoreApi = {
|
|
|
286
287
|
*/
|
|
287
288
|
btcGetAddress: typeof btcGetAddress;
|
|
288
289
|
btcGetPublicKey: typeof btcGetPublicKey;
|
|
290
|
+
btcDeriveContextHash: typeof btcDeriveContextHash;
|
|
289
291
|
btcSignMessage: typeof btcSignMessage;
|
|
290
292
|
btcSignPsbt: typeof btcSignPsbt;
|
|
291
293
|
btcSignTransaction: typeof btcSignTransaction;
|