@onekeyfe/hd-core 1.2.2-alpha.100 → 1.2.2-alpha.102
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/__tests__/AllNetworkGetAddressBase.tracing.test.ts +20 -4
- package/__tests__/DeviceCommands.test.ts +13 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +0 -2
- package/__tests__/check-firmware-release-protocol-v2.test.ts +0 -2
- package/__tests__/device-lifecycle-events.test.ts +102 -0
- package/__tests__/deviceUploadNft.test.ts +68 -0
- package/__tests__/evmSignTypedData.test.ts +42 -0
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +825 -12
- package/__tests__/logBlockEvent.test.ts +45 -122
- package/__tests__/open-wallet-session.test.ts +781 -69
- package/__tests__/pro2HostAssetPackage.test.ts +165 -0
- package/__tests__/protocol-v2-resources.test.ts +7 -4
- package/__tests__/protocol-v2-unlock-policy.test.ts +35 -1
- package/__tests__/protocol-v2.test.ts +937 -74
- package/__tests__/protocolV2FileWrite.test.ts +40 -0
- package/__tests__/sol-sign-offchain-message.test.ts +64 -0
- package/dist/api/FirmwareUpdateV4.d.ts +5 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +1 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +2 -2
- package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +2 -0
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +1 -1
- package/dist/device/Device.d.ts +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceConnector.d.ts +1 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +3 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +38 -16
- package/dist/index.js +2569 -1555
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +2 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +3 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -4
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/solSignOffchainMessage.d.ts +1 -0
- package/dist/types/api/solSignOffchainMessage.d.ts.map +1 -1
- package/dist/types/settings.d.ts +2 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +3 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2HostAssetPackage.d.ts +8 -0
- package/dist/utils/pro2HostAssetPackage.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +474 -83
- package/src/api/OpenWalletSession.ts +39 -12
- package/src/api/UploadPortfolio.ts +5 -4
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +5 -2
- package/src/api/evm/EVMSignTypedData.ts +1 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +9 -3
- package/src/api/helpers/protocolV2FileWrite.ts +11 -5
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +7 -1
- package/src/api/protocol-v2/DeviceUploadNft.ts +31 -8
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +33 -8
- package/src/api/protocol-v2/helpers.ts +8 -0
- package/src/api/solana/SolSignOffchainMessage.ts +44 -4
- package/src/core/RequestQueue.ts +16 -1
- package/src/core/index.ts +179 -27
- package/src/data/messages/messages-protocol-v2.json +1591 -1382
- package/src/data/messages/messages.json +8 -5
- package/src/device/Device.ts +3 -1
- package/src/device/DeviceConnector.ts +7 -3
- package/src/events/logBlockEvent.ts +6 -75
- package/src/events/ui-request.ts +3 -0
- package/src/protocols/protocol-v2/resources.ts +9 -1
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +8 -1
- package/src/protocols/protocol-v2/walletSession.ts +223 -56
- package/src/types/api/protocolV2.ts +3 -4
- package/src/types/api/solSignOffchainMessage.ts +2 -0
- package/src/types/settings.ts +4 -2
- package/src/utils/deviceFeaturesUtils.ts +4 -0
- package/src/utils/pro2HostAssetPackage.ts +400 -0
|
@@ -10243,7 +10243,8 @@
|
|
|
10243
10243
|
},
|
|
10244
10244
|
"SolanaOffChainMessageVersion": {
|
|
10245
10245
|
"values": {
|
|
10246
|
-
"MESSAGE_VERSION_0": 0
|
|
10246
|
+
"MESSAGE_VERSION_0": 0,
|
|
10247
|
+
"MESSAGE_VERSION_1": 1
|
|
10247
10248
|
}
|
|
10248
10249
|
},
|
|
10249
10250
|
"SolanaOffChainMessageFormat": {
|
|
@@ -10276,14 +10277,16 @@
|
|
|
10276
10277
|
},
|
|
10277
10278
|
"message_format": {
|
|
10278
10279
|
"type": "SolanaOffChainMessageFormat",
|
|
10279
|
-
"id": 4
|
|
10280
|
-
"options": {
|
|
10281
|
-
"default": "V0_RESTRICTED_ASCII"
|
|
10282
|
-
}
|
|
10280
|
+
"id": 4
|
|
10283
10281
|
},
|
|
10284
10282
|
"application_domain": {
|
|
10285
10283
|
"type": "bytes",
|
|
10286
10284
|
"id": 5
|
|
10285
|
+
},
|
|
10286
|
+
"required_signers": {
|
|
10287
|
+
"rule": "repeated",
|
|
10288
|
+
"type": "bytes",
|
|
10289
|
+
"id": 7
|
|
10287
10290
|
}
|
|
10288
10291
|
}
|
|
10289
10292
|
},
|
package/src/device/Device.ts
CHANGED
|
@@ -2005,7 +2005,8 @@ export class Device extends EventEmitter {
|
|
|
2005
2005
|
passphraseState?: string,
|
|
2006
2006
|
useEmptyPassphrase?: boolean,
|
|
2007
2007
|
skipPassphraseCheck?: boolean,
|
|
2008
|
-
deriveCardano?: boolean
|
|
2008
|
+
deriveCardano?: boolean,
|
|
2009
|
+
mainPinSelected?: boolean
|
|
2009
2010
|
) {
|
|
2010
2011
|
if (this.isUnacquired()) return false;
|
|
2011
2012
|
|
|
@@ -2016,6 +2017,7 @@ export class Device extends EventEmitter {
|
|
|
2016
2017
|
onlyMainPin: useEmptyPassphrase,
|
|
2017
2018
|
deriveCardano,
|
|
2018
2019
|
rejectAttachPinForMainWallet: useEmptyPassphrase === true,
|
|
2020
|
+
mainPinSelected,
|
|
2019
2021
|
});
|
|
2020
2022
|
|
|
2021
2023
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
@@ -96,7 +96,8 @@ export default class DeviceConnector {
|
|
|
96
96
|
forceCleanRunPromise?: boolean,
|
|
97
97
|
expectedProtocol?: HardwareConnectProtocol,
|
|
98
98
|
protocolHint?: HardwareConnectProtocol,
|
|
99
|
-
forceProtocolDetection?: boolean
|
|
99
|
+
forceProtocolDetection?: boolean,
|
|
100
|
+
skipProtocolProbe?: boolean
|
|
100
101
|
) {
|
|
101
102
|
Log.debug('acquire', path, session, expectedProtocol, protocolHint);
|
|
102
103
|
const env = DataManager.getSettings('env');
|
|
@@ -104,13 +105,15 @@ export default class DeviceConnector {
|
|
|
104
105
|
const transport = this.getActiveTransport();
|
|
105
106
|
let res;
|
|
106
107
|
if (DataManager.isBleConnect(env)) {
|
|
107
|
-
|
|
108
|
+
const acquireInput: Parameters<Transport['acquire']>[0] = {
|
|
108
109
|
uuid: path,
|
|
109
110
|
forceCleanRunPromise,
|
|
110
111
|
expectedProtocol,
|
|
111
112
|
protocolHint,
|
|
112
113
|
forceProtocolDetection,
|
|
113
|
-
|
|
114
|
+
skipProtocolProbe,
|
|
115
|
+
};
|
|
116
|
+
res = await transport.acquire(acquireInput);
|
|
114
117
|
} else {
|
|
115
118
|
res = await transport.acquire({
|
|
116
119
|
path,
|
|
@@ -118,6 +121,7 @@ export default class DeviceConnector {
|
|
|
118
121
|
expectedProtocol,
|
|
119
122
|
protocolHint,
|
|
120
123
|
forceProtocolDetection,
|
|
124
|
+
skipProtocolProbe,
|
|
121
125
|
});
|
|
122
126
|
}
|
|
123
127
|
if (expectedProtocol) {
|
|
@@ -8,8 +8,9 @@ export const LogBlockEvent: Set<string> = new Set([
|
|
|
8
8
|
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
9
9
|
]);
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// These resource/file APIs did not exist in 1.1.32. Skip the payload so
|
|
12
|
+
// the log layer does not copy huge Base64 or binary data.
|
|
13
|
+
const LogPayloadBlockMethod: Set<string> = new Set([
|
|
13
14
|
'deviceUploadNft',
|
|
14
15
|
'deviceUploadWallpaper',
|
|
15
16
|
'uploadPortfolio',
|
|
@@ -17,61 +18,6 @@ const LogLabelMethod: Set<string> = new Set([
|
|
|
17
18
|
'fileRead',
|
|
18
19
|
]);
|
|
19
20
|
|
|
20
|
-
// 资源上传参数可能包含很大的 Base64 字符串。这里按方法整段跳过,避免日志层
|
|
21
|
-
// 递归复制和序列化这些数据;资源 API 与传输内容本身保持不变。
|
|
22
|
-
const LogPayloadBlockMethod: Set<string> = new Set([
|
|
23
|
-
'deviceUploadNft',
|
|
24
|
-
'deviceUploadWallpaper',
|
|
25
|
-
'uploadPortfolio',
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
const SensitiveLogKeys: Set<string> = new Set([
|
|
29
|
-
'devicestate',
|
|
30
|
-
'entropy',
|
|
31
|
-
'expectedpassphrasestate',
|
|
32
|
-
'mnemonic',
|
|
33
|
-
'passphrase',
|
|
34
|
-
'passphrasestate',
|
|
35
|
-
'password',
|
|
36
|
-
'pin',
|
|
37
|
-
'privatekey',
|
|
38
|
-
'seed',
|
|
39
|
-
'session',
|
|
40
|
-
'sessionid',
|
|
41
|
-
'walletsessionid',
|
|
42
|
-
'xprv',
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
const normalizeLogKey = (key: string) => key.replace(/[_-]/g, '').toLowerCase();
|
|
46
|
-
|
|
47
|
-
const isSigningMethod = (methodName: string) => /sign/i.test(methodName);
|
|
48
|
-
|
|
49
|
-
const redactLogValue = (value: unknown, seen: WeakSet<object>): unknown => {
|
|
50
|
-
if (ArrayBuffer.isView(value)) {
|
|
51
|
-
return `[BINARY:${value.byteLength}]`;
|
|
52
|
-
}
|
|
53
|
-
if (value instanceof ArrayBuffer) {
|
|
54
|
-
return `[BINARY:${value.byteLength}]`;
|
|
55
|
-
}
|
|
56
|
-
if (Array.isArray(value)) {
|
|
57
|
-
return value.map(item => redactLogValue(item, seen));
|
|
58
|
-
}
|
|
59
|
-
if (!value || typeof value !== 'object') return value;
|
|
60
|
-
if (seen.has(value)) return '[CIRCULAR]';
|
|
61
|
-
|
|
62
|
-
seen.add(value);
|
|
63
|
-
const redacted = Object.fromEntries(
|
|
64
|
-
Object.entries(value as Record<string, unknown>).map(([key, item]) => [
|
|
65
|
-
key,
|
|
66
|
-
SensitiveLogKeys.has(normalizeLogKey(key)) && item !== null && item !== undefined
|
|
67
|
-
? '[REDACTED]'
|
|
68
|
-
: redactLogValue(item, seen),
|
|
69
|
-
])
|
|
70
|
-
);
|
|
71
|
-
seen.delete(value);
|
|
72
|
-
return redacted;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
21
|
export function getLogBlockLabel(message: unknown): string | undefined {
|
|
76
22
|
if (!message || typeof message !== 'object') return undefined;
|
|
77
23
|
|
|
@@ -86,7 +32,7 @@ export function getLogBlockLabel(message: unknown): string | undefined {
|
|
|
86
32
|
}
|
|
87
33
|
|
|
88
34
|
const methodName = method ?? payload?.method;
|
|
89
|
-
if (methodName &&
|
|
35
|
+
if (methodName && LogPayloadBlockMethod.has(methodName)) {
|
|
90
36
|
return methodName;
|
|
91
37
|
}
|
|
92
38
|
|
|
@@ -94,25 +40,10 @@ export function getLogBlockLabel(message: unknown): string | undefined {
|
|
|
94
40
|
}
|
|
95
41
|
|
|
96
42
|
export function getSafeLogPayload(value: unknown, blockLabel?: string): unknown {
|
|
97
|
-
if (
|
|
98
|
-
blockLabel &&
|
|
99
|
-
(LogBlockEvent.has(blockLabel) ||
|
|
100
|
-
LogPayloadBlockMethod.has(blockLabel) ||
|
|
101
|
-
isSigningMethod(blockLabel))
|
|
102
|
-
) {
|
|
43
|
+
if (blockLabel) {
|
|
103
44
|
return { method: blockLabel, payload: '[REDACTED]' };
|
|
104
45
|
}
|
|
105
|
-
|
|
106
|
-
const redactedValue = redactLogValue(value, new WeakSet());
|
|
107
|
-
if (
|
|
108
|
-
blockLabel &&
|
|
109
|
-
redactedValue &&
|
|
110
|
-
typeof redactedValue === 'object' &&
|
|
111
|
-
!Array.isArray(redactedValue)
|
|
112
|
-
) {
|
|
113
|
-
return { ...redactedValue, method: blockLabel };
|
|
114
|
-
}
|
|
115
|
-
return redactedValue;
|
|
46
|
+
return value;
|
|
116
47
|
}
|
|
117
48
|
|
|
118
49
|
export function formatLogMethodLabel(label: string, methodName?: string): string {
|
package/src/events/ui-request.ts
CHANGED
|
@@ -189,6 +189,9 @@ export interface FirmwareProgress {
|
|
|
189
189
|
totalBytes?: number;
|
|
190
190
|
rateBytesPerSecond?: number;
|
|
191
191
|
elapsedMs?: number;
|
|
192
|
+
installTargetId?: number;
|
|
193
|
+
installPhase?: 'prepare' | 'install' | 'verify';
|
|
194
|
+
installPhaseProgress?: number;
|
|
192
195
|
};
|
|
193
196
|
}
|
|
194
197
|
|
|
@@ -59,7 +59,15 @@ export function isProtocolV2ResourceArchiveEntryName(entryName: string): boolean
|
|
|
59
59
|
return (
|
|
60
60
|
fileName.length > 0 &&
|
|
61
61
|
!fileName.startsWith('.') &&
|
|
62
|
-
!parts.some(
|
|
62
|
+
!parts.some(
|
|
63
|
+
part =>
|
|
64
|
+
!part ||
|
|
65
|
+
part === '.' ||
|
|
66
|
+
part === '..' ||
|
|
67
|
+
part === '.DS_Store' ||
|
|
68
|
+
part.startsWith('._') ||
|
|
69
|
+
part.toUpperCase() === '__MACOSX'
|
|
70
|
+
)
|
|
63
71
|
);
|
|
64
72
|
}
|
|
65
73
|
|
|
@@ -14,10 +14,14 @@ const Log = getLogger(LoggerNames.Core);
|
|
|
14
14
|
|
|
15
15
|
export type ProtocolV2UnlockContext = {
|
|
16
16
|
preflightCompleted: boolean;
|
|
17
|
+
preflightStatusRefreshed?: boolean;
|
|
18
|
+
preflightMainPinSelected?: boolean;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export const createProtocolV2UnlockContext = (): ProtocolV2UnlockContext => ({
|
|
20
22
|
preflightCompleted: false,
|
|
23
|
+
preflightStatusRefreshed: false,
|
|
24
|
+
preflightMainPinSelected: false,
|
|
21
25
|
});
|
|
22
26
|
|
|
23
27
|
type RunnableMethod = Pick<
|
|
@@ -100,11 +104,12 @@ export async function runMethodWithUnlockPolicy<T = unknown>(
|
|
|
100
104
|
await afterStatusBeforeUnlock?.();
|
|
101
105
|
|
|
102
106
|
if (!status.unlocked) {
|
|
107
|
+
const preUnlockPinType = resolvePreUnlockPinType(method);
|
|
103
108
|
const unlockInteraction: HardwareUiInteractionMeta | undefined = shouldCoordinateUi
|
|
104
109
|
? uiCoordinator.enterUnlockInteraction(method.name)
|
|
105
110
|
: undefined;
|
|
106
111
|
const unlockedStatus = await device.unlockDevice(
|
|
107
|
-
|
|
112
|
+
preUnlockPinType,
|
|
108
113
|
shouldCoordinateUi
|
|
109
114
|
? { emitUiEvent: false, interaction: unlockInteraction }
|
|
110
115
|
: {
|
|
@@ -120,9 +125,11 @@ export async function runMethodWithUnlockPolicy<T = unknown>(
|
|
|
120
125
|
'Protocol V2 device remained locked after the unlock flow.'
|
|
121
126
|
);
|
|
122
127
|
}
|
|
128
|
+
context.preflightMainPinSelected = preUnlockPinType === DeviceSessionPinType.Main;
|
|
123
129
|
Log.debug('Protocol V2 pre-unlock completed', { method: method.name });
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
context.preflightStatusRefreshed = true;
|
|
126
133
|
context.preflightCompleted = true;
|
|
127
134
|
}
|
|
128
135
|
|