@onekeyfe/hd-core 1.2.2-alpha.1 → 1.2.2-alpha.100
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 +4 -20
- package/__tests__/DeviceCommands.test.ts +0 -13
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/check-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/device-lifecycle-events.test.ts +0 -19
- package/__tests__/deviceUploadNft.test.ts +0 -68
- package/__tests__/evmSignTypedData.test.ts +0 -42
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -825
- package/__tests__/open-wallet-session.test.ts +1 -127
- package/__tests__/protocol-v2-resources.test.ts +4 -7
- package/__tests__/protocol-v2-unlock-policy.test.ts +1 -35
- package/__tests__/protocol-v2.test.ts +27 -710
- package/dist/api/FirmwareUpdateV4.d.ts +0 -4
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.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/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/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +0 -3
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +5 -21
- package/dist/index.js +402 -1136
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -2
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +0 -3
- package/dist/protocols/protocol-v2/walletSession.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 +0 -3
- 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/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +75 -434
- package/src/api/OpenWalletSession.ts +9 -39
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +1 -2
- package/src/api/evm/EVMSignTypedData.ts +0 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -9
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +1 -7
- package/src/api/protocol-v2/DeviceUploadNft.ts +8 -31
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -27
- package/src/api/protocol-v2/helpers.ts +0 -8
- package/src/core/index.ts +10 -121
- package/src/data/messages/messages-protocol-v2.json +1 -111
- package/src/device/Device.ts +1 -3
- package/src/device/DeviceConnector.ts +3 -7
- package/src/events/ui-request.ts +0 -3
- package/src/protocols/protocol-v2/resources.ts +1 -9
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -8
- package/src/protocols/protocol-v2/walletSession.ts +22 -65
- package/src/types/settings.ts +2 -4
- package/src/utils/deviceFeaturesUtils.ts +0 -4
- package/__tests__/pro2HostAssetPackage.test.ts +0 -58
- package/dist/utils/pro2HostAssetPackage.d.ts +0 -8
- package/dist/utils/pro2HostAssetPackage.d.ts.map +0 -1
- package/src/utils/pro2HostAssetPackage.ts +0 -354
|
@@ -446,9 +446,6 @@
|
|
|
446
446
|
"MessageType_DeviceCertificateSignature": 60423,
|
|
447
447
|
"MessageType_DeviceCertificateSign": 60424,
|
|
448
448
|
"MessageType_DeviceMiscUsbMscControl": 60440,
|
|
449
|
-
"MessageType_DeviceFindMyTokenState": 60450,
|
|
450
|
-
"MessageType_DeviceFindMyTokenUpdate": 60451,
|
|
451
|
-
"MessageType_DeviceFindMyTokenStateGet": 60452,
|
|
452
449
|
"MessageType_DeviceInfoGet": 60600,
|
|
453
450
|
"MessageType_DeviceInfo": 60601,
|
|
454
451
|
"MessageType_DeviceStatusGet": 60602,
|
|
@@ -5407,10 +5404,6 @@
|
|
|
5407
5404
|
"request_id": {
|
|
5408
5405
|
"type": "bytes",
|
|
5409
5406
|
"id": 5
|
|
5410
|
-
},
|
|
5411
|
-
"source_fingerprint": {
|
|
5412
|
-
"type": "uint32",
|
|
5413
|
-
"id": 6
|
|
5414
5407
|
}
|
|
5415
5408
|
}
|
|
5416
5409
|
},
|
|
@@ -5546,14 +5539,6 @@
|
|
|
5546
5539
|
"tx_type": {
|
|
5547
5540
|
"type": "uint32",
|
|
5548
5541
|
"id": 10
|
|
5549
|
-
},
|
|
5550
|
-
"expected_address": {
|
|
5551
|
-
"type": "bytes",
|
|
5552
|
-
"id": 12
|
|
5553
|
-
},
|
|
5554
|
-
"source_fingerprint": {
|
|
5555
|
-
"type": "uint32",
|
|
5556
|
-
"id": 13
|
|
5557
5542
|
}
|
|
5558
5543
|
}
|
|
5559
5544
|
},
|
|
@@ -5634,14 +5619,6 @@
|
|
|
5634
5619
|
"rule": "repeated",
|
|
5635
5620
|
"type": "EthereumAccessListOneKey",
|
|
5636
5621
|
"id": 11
|
|
5637
|
-
},
|
|
5638
|
-
"expected_address": {
|
|
5639
|
-
"type": "bytes",
|
|
5640
|
-
"id": 12
|
|
5641
|
-
},
|
|
5642
|
-
"source_fingerprint": {
|
|
5643
|
-
"type": "uint32",
|
|
5644
|
-
"id": 13
|
|
5645
5622
|
}
|
|
5646
5623
|
}
|
|
5647
5624
|
},
|
|
@@ -5818,10 +5795,6 @@
|
|
|
5818
5795
|
"chain_id": {
|
|
5819
5796
|
"type": "uint64",
|
|
5820
5797
|
"id": 3
|
|
5821
|
-
},
|
|
5822
|
-
"source_fingerprint": {
|
|
5823
|
-
"type": "uint32",
|
|
5824
|
-
"id": 4
|
|
5825
5798
|
}
|
|
5826
5799
|
}
|
|
5827
5800
|
},
|
|
@@ -9501,10 +9474,6 @@
|
|
|
9501
9474
|
"rule": "required",
|
|
9502
9475
|
"type": "bytes",
|
|
9503
9476
|
"id": 2
|
|
9504
|
-
},
|
|
9505
|
-
"source_fingerprint": {
|
|
9506
|
-
"type": "uint32",
|
|
9507
|
-
"id": 3
|
|
9508
9477
|
}
|
|
9509
9478
|
}
|
|
9510
9479
|
},
|
|
@@ -9549,10 +9518,6 @@
|
|
|
9549
9518
|
"application_domain": {
|
|
9550
9519
|
"type": "bytes",
|
|
9551
9520
|
"id": 5
|
|
9552
|
-
},
|
|
9553
|
-
"source_fingerprint": {
|
|
9554
|
-
"type": "uint32",
|
|
9555
|
-
"id": 6
|
|
9556
9521
|
}
|
|
9557
9522
|
}
|
|
9558
9523
|
},
|
|
@@ -9570,10 +9535,6 @@
|
|
|
9570
9535
|
"rule": "required",
|
|
9571
9536
|
"type": "bytes",
|
|
9572
9537
|
"id": 2
|
|
9573
|
-
},
|
|
9574
|
-
"source_fingerprint": {
|
|
9575
|
-
"type": "uint32",
|
|
9576
|
-
"id": 3
|
|
9577
9538
|
}
|
|
9578
9539
|
}
|
|
9579
9540
|
},
|
|
@@ -11803,27 +11764,6 @@
|
|
|
11803
11764
|
}
|
|
11804
11765
|
}
|
|
11805
11766
|
},
|
|
11806
|
-
"DeviceFindMyTokenUpdate": {
|
|
11807
|
-
"fields": {
|
|
11808
|
-
"token": {
|
|
11809
|
-
"rule": "required",
|
|
11810
|
-
"type": "bytes",
|
|
11811
|
-
"id": 1
|
|
11812
|
-
}
|
|
11813
|
-
}
|
|
11814
|
-
},
|
|
11815
|
-
"DeviceFindMyTokenStateGet": {
|
|
11816
|
-
"fields": {}
|
|
11817
|
-
},
|
|
11818
|
-
"DeviceFindMyTokenState": {
|
|
11819
|
-
"fields": {
|
|
11820
|
-
"burned": {
|
|
11821
|
-
"rule": "required",
|
|
11822
|
-
"type": "bool",
|
|
11823
|
-
"id": 1
|
|
11824
|
-
}
|
|
11825
|
-
}
|
|
11826
|
-
},
|
|
11827
11767
|
"DeviceFactoryAck": {
|
|
11828
11768
|
"values": {
|
|
11829
11769
|
"FACTORY_ACK_SUCCESS": 0,
|
|
@@ -11953,13 +11893,6 @@
|
|
|
11953
11893
|
"FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS": 10
|
|
11954
11894
|
}
|
|
11955
11895
|
},
|
|
11956
|
-
"DeviceFirmwareUpdatePhase": {
|
|
11957
|
-
"values": {
|
|
11958
|
-
"FW_MGMT_UPDATER_PHASE_PREPARE": 0,
|
|
11959
|
-
"FW_MGMT_UPDATER_PHASE_INSTALL": 1,
|
|
11960
|
-
"FW_MGMT_UPDATER_PHASE_VERIFY": 2
|
|
11961
|
-
}
|
|
11962
|
-
},
|
|
11963
11896
|
"DeviceFirmwareTarget": {
|
|
11964
11897
|
"fields": {
|
|
11965
11898
|
"target_id": {
|
|
@@ -11984,26 +11917,7 @@
|
|
|
11984
11917
|
}
|
|
11985
11918
|
},
|
|
11986
11919
|
"DeviceFirmwareUpdateRequest": {
|
|
11987
|
-
"fields": {
|
|
11988
|
-
"reboot_after_update": {
|
|
11989
|
-
"type": "bool",
|
|
11990
|
-
"id": 1
|
|
11991
|
-
}
|
|
11992
|
-
}
|
|
11993
|
-
},
|
|
11994
|
-
"DeviceFirmwareUpdatePhaseInfo": {
|
|
11995
|
-
"fields": {
|
|
11996
|
-
"phase": {
|
|
11997
|
-
"rule": "required",
|
|
11998
|
-
"type": "DeviceFirmwareUpdatePhase",
|
|
11999
|
-
"id": 1
|
|
12000
|
-
},
|
|
12001
|
-
"progress_percent": {
|
|
12002
|
-
"rule": "required",
|
|
12003
|
-
"type": "uint32",
|
|
12004
|
-
"id": 2
|
|
12005
|
-
}
|
|
12006
|
-
}
|
|
11920
|
+
"fields": {}
|
|
12007
11921
|
},
|
|
12008
11922
|
"DeviceFirmwareUpdateRecord": {
|
|
12009
11923
|
"fields": {
|
|
@@ -12016,14 +11930,6 @@
|
|
|
12016
11930
|
"type": "DeviceFirmwareUpdateTaskStatus",
|
|
12017
11931
|
"id": 10
|
|
12018
11932
|
},
|
|
12019
|
-
"progress_percent": {
|
|
12020
|
-
"type": "uint32",
|
|
12021
|
-
"id": 11
|
|
12022
|
-
},
|
|
12023
|
-
"phase_info": {
|
|
12024
|
-
"type": "DeviceFirmwareUpdatePhaseInfo",
|
|
12025
|
-
"id": 12
|
|
12026
|
-
},
|
|
12027
11933
|
"payload_version": {
|
|
12028
11934
|
"type": "uint32",
|
|
12029
11935
|
"id": 20
|
|
@@ -12040,14 +11946,6 @@
|
|
|
12040
11946
|
"type": "bool",
|
|
12041
11947
|
"id": 10
|
|
12042
11948
|
},
|
|
12043
|
-
"progress_percent": {
|
|
12044
|
-
"type": "bool",
|
|
12045
|
-
"id": 11
|
|
12046
|
-
},
|
|
12047
|
-
"phase_info": {
|
|
12048
|
-
"type": "bool",
|
|
12049
|
-
"id": 12
|
|
12050
|
-
},
|
|
12051
11949
|
"payload_version": {
|
|
12052
11950
|
"type": "bool",
|
|
12053
11951
|
"id": 20
|
|
@@ -12815,10 +12713,6 @@
|
|
|
12815
12713
|
"text_id": {
|
|
12816
12714
|
"type": "uint32",
|
|
12817
12715
|
"id": 3
|
|
12818
|
-
},
|
|
12819
|
-
"text_arg": {
|
|
12820
|
-
"type": "string",
|
|
12821
|
-
"id": 4
|
|
12822
12716
|
}
|
|
12823
12717
|
}
|
|
12824
12718
|
},
|
|
@@ -12886,10 +12780,6 @@
|
|
|
12886
12780
|
"title_id": {
|
|
12887
12781
|
"type": "uint32",
|
|
12888
12782
|
"id": 8
|
|
12889
|
-
},
|
|
12890
|
-
"title_arg": {
|
|
12891
|
-
"type": "string",
|
|
12892
|
-
"id": 9
|
|
12893
12783
|
}
|
|
12894
12784
|
}
|
|
12895
12785
|
},
|
package/src/device/Device.ts
CHANGED
|
@@ -2005,8 +2005,7 @@ export class Device extends EventEmitter {
|
|
|
2005
2005
|
passphraseState?: string,
|
|
2006
2006
|
useEmptyPassphrase?: boolean,
|
|
2007
2007
|
skipPassphraseCheck?: boolean,
|
|
2008
|
-
deriveCardano?: boolean
|
|
2009
|
-
mainPinSelected?: boolean
|
|
2008
|
+
deriveCardano?: boolean
|
|
2010
2009
|
) {
|
|
2011
2010
|
if (this.isUnacquired()) return false;
|
|
2012
2011
|
|
|
@@ -2017,7 +2016,6 @@ export class Device extends EventEmitter {
|
|
|
2017
2016
|
onlyMainPin: useEmptyPassphrase,
|
|
2018
2017
|
deriveCardano,
|
|
2019
2018
|
rejectAttachPinForMainWallet: useEmptyPassphrase === true,
|
|
2020
|
-
mainPinSelected,
|
|
2021
2019
|
});
|
|
2022
2020
|
|
|
2023
2021
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
@@ -96,8 +96,7 @@ export default class DeviceConnector {
|
|
|
96
96
|
forceCleanRunPromise?: boolean,
|
|
97
97
|
expectedProtocol?: HardwareConnectProtocol,
|
|
98
98
|
protocolHint?: HardwareConnectProtocol,
|
|
99
|
-
forceProtocolDetection?: boolean
|
|
100
|
-
skipProtocolProbe?: boolean
|
|
99
|
+
forceProtocolDetection?: boolean
|
|
101
100
|
) {
|
|
102
101
|
Log.debug('acquire', path, session, expectedProtocol, protocolHint);
|
|
103
102
|
const env = DataManager.getSettings('env');
|
|
@@ -105,15 +104,13 @@ export default class DeviceConnector {
|
|
|
105
104
|
const transport = this.getActiveTransport();
|
|
106
105
|
let res;
|
|
107
106
|
if (DataManager.isBleConnect(env)) {
|
|
108
|
-
|
|
107
|
+
res = await transport.acquire({
|
|
109
108
|
uuid: path,
|
|
110
109
|
forceCleanRunPromise,
|
|
111
110
|
expectedProtocol,
|
|
112
111
|
protocolHint,
|
|
113
112
|
forceProtocolDetection,
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
res = await transport.acquire(acquireInput);
|
|
113
|
+
});
|
|
117
114
|
} else {
|
|
118
115
|
res = await transport.acquire({
|
|
119
116
|
path,
|
|
@@ -121,7 +118,6 @@ export default class DeviceConnector {
|
|
|
121
118
|
expectedProtocol,
|
|
122
119
|
protocolHint,
|
|
123
120
|
forceProtocolDetection,
|
|
124
|
-
skipProtocolProbe,
|
|
125
121
|
});
|
|
126
122
|
}
|
|
127
123
|
if (expectedProtocol) {
|
package/src/events/ui-request.ts
CHANGED
|
@@ -189,9 +189,6 @@ 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;
|
|
195
192
|
};
|
|
196
193
|
}
|
|
197
194
|
|
|
@@ -59,15 +59,7 @@ export function isProtocolV2ResourceArchiveEntryName(entryName: string): boolean
|
|
|
59
59
|
return (
|
|
60
60
|
fileName.length > 0 &&
|
|
61
61
|
!fileName.startsWith('.') &&
|
|
62
|
-
!parts.some(
|
|
63
|
-
part =>
|
|
64
|
-
!part ||
|
|
65
|
-
part === '.' ||
|
|
66
|
-
part === '..' ||
|
|
67
|
-
part === '.DS_Store' ||
|
|
68
|
-
part.startsWith('._') ||
|
|
69
|
-
part.toUpperCase() === '__MACOSX'
|
|
70
|
-
)
|
|
62
|
+
!parts.some(part => part === '__MACOSX' || part === '.' || part === '..' || part === '')
|
|
71
63
|
);
|
|
72
64
|
}
|
|
73
65
|
|
|
@@ -14,14 +14,10 @@ const Log = getLogger(LoggerNames.Core);
|
|
|
14
14
|
|
|
15
15
|
export type ProtocolV2UnlockContext = {
|
|
16
16
|
preflightCompleted: boolean;
|
|
17
|
-
preflightStatusRefreshed?: boolean;
|
|
18
|
-
preflightMainPinSelected?: boolean;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
export const createProtocolV2UnlockContext = (): ProtocolV2UnlockContext => ({
|
|
22
20
|
preflightCompleted: false,
|
|
23
|
-
preflightStatusRefreshed: false,
|
|
24
|
-
preflightMainPinSelected: false,
|
|
25
21
|
});
|
|
26
22
|
|
|
27
23
|
type RunnableMethod = Pick<
|
|
@@ -104,12 +100,11 @@ export async function runMethodWithUnlockPolicy<T = unknown>(
|
|
|
104
100
|
await afterStatusBeforeUnlock?.();
|
|
105
101
|
|
|
106
102
|
if (!status.unlocked) {
|
|
107
|
-
const preUnlockPinType = resolvePreUnlockPinType(method);
|
|
108
103
|
const unlockInteraction: HardwareUiInteractionMeta | undefined = shouldCoordinateUi
|
|
109
104
|
? uiCoordinator.enterUnlockInteraction(method.name)
|
|
110
105
|
: undefined;
|
|
111
106
|
const unlockedStatus = await device.unlockDevice(
|
|
112
|
-
|
|
107
|
+
resolvePreUnlockPinType(method),
|
|
113
108
|
shouldCoordinateUi
|
|
114
109
|
? { emitUiEvent: false, interaction: unlockInteraction }
|
|
115
110
|
: {
|
|
@@ -125,11 +120,9 @@ export async function runMethodWithUnlockPolicy<T = unknown>(
|
|
|
125
120
|
'Protocol V2 device remained locked after the unlock flow.'
|
|
126
121
|
);
|
|
127
122
|
}
|
|
128
|
-
context.preflightMainPinSelected = preUnlockPinType === DeviceSessionPinType.Main;
|
|
129
123
|
Log.debug('Protocol V2 pre-unlock completed', { method: method.name });
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
context.preflightStatusRefreshed = true;
|
|
133
126
|
context.preflightCompleted = true;
|
|
134
127
|
}
|
|
135
128
|
|
|
@@ -83,21 +83,15 @@ const buildDeviceSessionGetRequest = ({
|
|
|
83
83
|
],
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
const askDevicePassphrase = async (
|
|
87
|
-
device: Device,
|
|
88
|
-
requestPayload: DeviceSessionAskPassphrase,
|
|
89
|
-
onStatusRefreshed?: () => void
|
|
90
|
-
) => {
|
|
86
|
+
const askDevicePassphrase = async (device: Device, requestPayload: DeviceSessionAskPassphrase) => {
|
|
91
87
|
await device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', requestPayload);
|
|
92
88
|
await refreshProtocolV2DeviceStatus(device);
|
|
93
|
-
onStatusRefreshed?.();
|
|
94
89
|
};
|
|
95
90
|
|
|
96
91
|
const selectDeviceSession = async (
|
|
97
92
|
device: Device,
|
|
98
93
|
expectedPassphraseState?: string,
|
|
99
|
-
deriveCardano?: boolean
|
|
100
|
-
onStatusRefreshed?: () => void
|
|
94
|
+
deriveCardano?: boolean
|
|
101
95
|
) => {
|
|
102
96
|
const existsAttachPinUser = device.features?.attachToPinEnabled === true;
|
|
103
97
|
const metadata = {
|
|
@@ -159,19 +153,14 @@ const selectDeviceSession = async (
|
|
|
159
153
|
emitUiEvent: false,
|
|
160
154
|
interaction: attachPinInteraction,
|
|
161
155
|
});
|
|
162
|
-
onStatusRefreshed?.();
|
|
163
156
|
return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
|
|
164
157
|
}
|
|
165
158
|
|
|
166
159
|
if (hasHostPassphrase) {
|
|
167
|
-
await askDevicePassphrase(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
on_device: false,
|
|
172
|
-
},
|
|
173
|
-
onStatusRefreshed
|
|
174
|
-
);
|
|
160
|
+
await askDevicePassphrase(device, {
|
|
161
|
+
passphrase: hostPassphrase,
|
|
162
|
+
on_device: false,
|
|
163
|
+
});
|
|
175
164
|
return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
|
|
176
165
|
}
|
|
177
166
|
|
|
@@ -183,7 +172,7 @@ const selectDeviceSession = async (
|
|
|
183
172
|
...metadata,
|
|
184
173
|
...(passphraseOnDeviceInteraction ? { interaction: passphraseOnDeviceInteraction } : {}),
|
|
185
174
|
});
|
|
186
|
-
await askDevicePassphrase(device, { on_device: true }
|
|
175
|
+
await askDevicePassphrase(device, { on_device: true });
|
|
187
176
|
return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
|
|
188
177
|
};
|
|
189
178
|
|
|
@@ -202,8 +191,6 @@ export async function getProtocolV2WalletSession(
|
|
|
202
191
|
deriveCardano?: boolean;
|
|
203
192
|
/** Read the wallet already selected by Attach PIN without reopening wallet selection. */
|
|
204
193
|
readCurrentAttachPinSession?: boolean;
|
|
205
|
-
/** The current call already selected the Main PIN during its unlock preflight. */
|
|
206
|
-
mainPinSelected?: boolean;
|
|
207
194
|
}
|
|
208
195
|
) {
|
|
209
196
|
const forceWalletSelection =
|
|
@@ -240,16 +227,10 @@ export async function getProtocolV2WalletSession(
|
|
|
240
227
|
: undefined;
|
|
241
228
|
let response;
|
|
242
229
|
let resumed = false;
|
|
243
|
-
let
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
let mainPinAuthenticated =
|
|
248
|
-
options?.mainPinSelected === true ||
|
|
249
|
-
(options?.onlyMainPin === true &&
|
|
250
|
-
device.features?.unlocked === true &&
|
|
251
|
-
device.features?.unlockedAttachPin === false);
|
|
252
|
-
let standardWalletSelected = options?.mainPinSelected === true;
|
|
230
|
+
let mainPinSelected =
|
|
231
|
+
options?.onlyMainPin === true &&
|
|
232
|
+
device.features?.unlocked === true &&
|
|
233
|
+
device.features?.unlockedAttachPin === false;
|
|
253
234
|
|
|
254
235
|
const clearCurrentWalletSession = () => {
|
|
255
236
|
if (options?.onlyMainPin) {
|
|
@@ -261,7 +242,6 @@ export async function getProtocolV2WalletSession(
|
|
|
261
242
|
|
|
262
243
|
const rejectMismatchedAttachPinWallet = async () => {
|
|
263
244
|
const features = await refreshProtocolV2DeviceStatus(device);
|
|
264
|
-
markWalletStatusRefreshed();
|
|
265
245
|
if (features.unlockedAttachPin !== true) {
|
|
266
246
|
return;
|
|
267
247
|
}
|
|
@@ -285,42 +265,30 @@ export async function getProtocolV2WalletSession(
|
|
|
285
265
|
}
|
|
286
266
|
|
|
287
267
|
const selectMainPin = async (force = false) => {
|
|
288
|
-
if (force || !
|
|
268
|
+
if (force || !mainPinSelected) {
|
|
289
269
|
await device.unlockDevice(DeviceSessionPinType.Main, {
|
|
290
270
|
source: 'wallet-session-coordinator',
|
|
291
271
|
reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet',
|
|
292
272
|
deviceOnly: true,
|
|
293
273
|
});
|
|
294
|
-
|
|
295
|
-
mainPinAuthenticated = true;
|
|
296
|
-
standardWalletSelected = true;
|
|
274
|
+
mainPinSelected = true;
|
|
297
275
|
}
|
|
298
276
|
};
|
|
299
277
|
|
|
300
278
|
const selectStandardWallet = async () => {
|
|
279
|
+
// Main PIN authenticates the device; an empty host passphrase selects the standard derivation.
|
|
280
|
+
await selectMainPin();
|
|
301
281
|
if (device.features?.passphraseProtection === true) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
{
|
|
307
|
-
passphrase: '',
|
|
308
|
-
on_device: false,
|
|
309
|
-
},
|
|
310
|
-
markWalletStatusRefreshed
|
|
311
|
-
);
|
|
312
|
-
standardWalletSelected = true;
|
|
313
|
-
} else if (!standardWalletSelected) {
|
|
314
|
-
// Without passphrase protection there is no empty-passphrase selector.
|
|
315
|
-
// Main PIN selection is the only authoritative switch back to the standard wallet.
|
|
316
|
-
await selectMainPin(true);
|
|
282
|
+
await askDevicePassphrase(device, {
|
|
283
|
+
passphrase: '',
|
|
284
|
+
on_device: false,
|
|
285
|
+
});
|
|
317
286
|
}
|
|
318
287
|
};
|
|
319
288
|
|
|
320
289
|
if (readCurrentAttachPinSession) {
|
|
321
290
|
const status = await requestProtocolV2DeviceStatus(device);
|
|
322
291
|
device.updateProtocolV2Status(status);
|
|
323
|
-
markWalletStatusRefreshed();
|
|
324
292
|
if (
|
|
325
293
|
status.unlocked !== true ||
|
|
326
294
|
status.passphrase_enabled !== true ||
|
|
@@ -404,12 +372,7 @@ export async function getProtocolV2WalletSession(
|
|
|
404
372
|
device.clearInternalState();
|
|
405
373
|
throw ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid);
|
|
406
374
|
}
|
|
407
|
-
response = await selectDeviceSession(
|
|
408
|
-
device,
|
|
409
|
-
expectedPassphraseState,
|
|
410
|
-
options?.deriveCardano,
|
|
411
|
-
markWalletStatusRefreshed
|
|
412
|
-
);
|
|
375
|
+
response = await selectDeviceSession(device, expectedPassphraseState, options?.deriveCardano);
|
|
413
376
|
}
|
|
414
377
|
|
|
415
378
|
let { message } = response;
|
|
@@ -439,12 +402,7 @@ export async function getProtocolV2WalletSession(
|
|
|
439
402
|
);
|
|
440
403
|
} else {
|
|
441
404
|
device.clearInternalState();
|
|
442
|
-
response = await selectDeviceSession(
|
|
443
|
-
device,
|
|
444
|
-
expectedPassphraseState,
|
|
445
|
-
options?.deriveCardano,
|
|
446
|
-
markWalletStatusRefreshed
|
|
447
|
-
);
|
|
405
|
+
response = await selectDeviceSession(device, expectedPassphraseState, options?.deriveCardano);
|
|
448
406
|
}
|
|
449
407
|
message = response.message;
|
|
450
408
|
try {
|
|
@@ -480,7 +438,7 @@ export async function getProtocolV2WalletSession(
|
|
|
480
438
|
let unlockedAttachPin: boolean | undefined;
|
|
481
439
|
if (readCurrentAttachPinSession) {
|
|
482
440
|
unlockedAttachPin = true;
|
|
483
|
-
} else if (
|
|
441
|
+
} else if (mainPinSelected) {
|
|
484
442
|
unlockedAttachPin = false;
|
|
485
443
|
}
|
|
486
444
|
|
|
@@ -489,7 +447,6 @@ export async function getProtocolV2WalletSession(
|
|
|
489
447
|
newSession: message.session_id,
|
|
490
448
|
unlockedAttachPin,
|
|
491
449
|
resumed,
|
|
492
|
-
walletStatusRefreshed,
|
|
493
450
|
};
|
|
494
451
|
}
|
|
495
452
|
|
package/src/types/settings.ts
CHANGED
|
@@ -77,8 +77,7 @@ export type IProtocolV2Resources = {
|
|
|
77
77
|
/** STM32 firmware config */
|
|
78
78
|
export type IFirmwareReleaseInfo = {
|
|
79
79
|
required: boolean;
|
|
80
|
-
|
|
81
|
-
url?: string;
|
|
80
|
+
url: string;
|
|
82
81
|
/**
|
|
83
82
|
* Firmware type (bitcoinonly or universal)
|
|
84
83
|
* This field is not present in the remote config, but will be inferred from the firmware field name
|
|
@@ -107,8 +106,7 @@ export type IFirmwareReleaseInfo = {
|
|
|
107
106
|
bootloaderChangelog?: {
|
|
108
107
|
[k in ILocale]: string;
|
|
109
108
|
};
|
|
110
|
-
|
|
111
|
-
fingerprint?: string;
|
|
109
|
+
fingerprint: string;
|
|
112
110
|
expectedSize?: number;
|
|
113
111
|
version: IVersionArray;
|
|
114
112
|
changelog: {
|
|
@@ -110,7 +110,6 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
110
110
|
initSession?: boolean;
|
|
111
111
|
deriveCardano?: boolean;
|
|
112
112
|
rejectAttachPinForMainWallet?: boolean;
|
|
113
|
-
mainPinSelected?: boolean;
|
|
114
113
|
}
|
|
115
114
|
) => {
|
|
116
115
|
if (device.isProtocolV2()) {
|
|
@@ -128,7 +127,6 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
128
127
|
onlyMainPin: options?.onlyMainPin,
|
|
129
128
|
deriveCardano: options?.deriveCardano,
|
|
130
129
|
rejectAttachPinForMainWallet: options?.rejectAttachPinForMainWallet,
|
|
131
|
-
mainPinSelected: options?.mainPinSelected,
|
|
132
130
|
});
|
|
133
131
|
}
|
|
134
132
|
|
|
@@ -196,7 +194,6 @@ export const getPassphraseState = async (
|
|
|
196
194
|
initSession?: boolean;
|
|
197
195
|
deriveCardano?: boolean;
|
|
198
196
|
rejectAttachPinForMainWallet?: boolean;
|
|
199
|
-
mainPinSelected?: boolean;
|
|
200
197
|
}
|
|
201
198
|
): Promise<{
|
|
202
199
|
passphraseState: string | undefined;
|
|
@@ -219,7 +216,6 @@ export const getPassphraseState = async (
|
|
|
219
216
|
onlyMainPin: options?.onlyMainPin,
|
|
220
217
|
deriveCardano: options?.deriveCardano,
|
|
221
218
|
rejectAttachPinForMainWallet: options?.rejectAttachPinForMainWallet,
|
|
222
|
-
mainPinSelected: options?.mainPinSelected,
|
|
223
219
|
});
|
|
224
220
|
}
|
|
225
221
|
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { sha3_512 } from '@noble/hashes/sha3';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
buildPro2HostAssetPackage,
|
|
5
|
-
supportsPro2HostAssetPackage,
|
|
6
|
-
} from '../src/utils/pro2HostAssetPackage';
|
|
7
|
-
|
|
8
|
-
describe('Pro2 host asset package', () => {
|
|
9
|
-
test('builds the unsigned RESOURCE container and LZ4-blocked archive expected by firmware', () => {
|
|
10
|
-
const raw = new TextEncoder().encode('123456789');
|
|
11
|
-
const packageData = buildPro2HostAssetPackage([{ name: 'wallpaper.bin', data: raw }]);
|
|
12
|
-
const headerSize = 0x5f90;
|
|
13
|
-
const payload = packageData.subarray(headerSize);
|
|
14
|
-
const packageView = new DataView(
|
|
15
|
-
packageData.buffer,
|
|
16
|
-
packageData.byteOffset,
|
|
17
|
-
packageData.byteLength
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
expect(packageView.getUint32(0, true)).toBe(0x50504b4f);
|
|
21
|
-
expect(packageView.getUint32(4, true)).toBe(1);
|
|
22
|
-
expect(packageView.getUint32(8, true)).toBe(0x43534552);
|
|
23
|
-
expect(packageView.getUint32(0x0c, true)).toBe(headerSize);
|
|
24
|
-
expect(packageView.getUint32(0x10, true)).toBe(1);
|
|
25
|
-
expect(packageView.getUint32(0x14, true)).toBe(payload.byteLength);
|
|
26
|
-
expect(packageData.subarray(0x200, 0x240)).toEqual(sha3_512(payload));
|
|
27
|
-
expect(packageData.subarray(0x240, 0x280)).toEqual(sha3_512(packageData.subarray(0, 0x240)));
|
|
28
|
-
expect(packageData[0x400]).toBe(0);
|
|
29
|
-
expect(packageView.getUint32(0x408, true)).toBe(0x71717171);
|
|
30
|
-
|
|
31
|
-
const archiveView = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
32
|
-
expect(archiveView.getUint32(0, true)).toBe(0x52414b4f);
|
|
33
|
-
expect(archiveView.getUint32(4, true)).toBe(1);
|
|
34
|
-
expect(archiveView.getUint16(8, true)).toBe(1);
|
|
35
|
-
expect(new TextDecoder().decode(payload.subarray(43, 56))).toBe('wallpaper.bin');
|
|
36
|
-
expect(archiveView.getUint32(42 + 0x100, true)).toBe(340);
|
|
37
|
-
expect(archiveView.getUint32(42 + 0x104, true)).toBe(raw.byteLength);
|
|
38
|
-
expect(archiveView.getUint32(42 + 0x10c, true)).toBe(0xcbf43926);
|
|
39
|
-
expect(payload[42 + 0x114]).toBe(1);
|
|
40
|
-
|
|
41
|
-
const compressedOffset = archiveView.getUint32(42 + 0x100, true);
|
|
42
|
-
expect(archiveView.getUint16(compressedOffset, true)).toBe(1);
|
|
43
|
-
expect(archiveView.getUint16(compressedOffset + 2, true)).toBe(12);
|
|
44
|
-
expect(archiveView.getUint32(compressedOffset + 4, true)).toBe(0);
|
|
45
|
-
expect(archiveView.getUint32(compressedOffset + 8, true)).toBe(10);
|
|
46
|
-
expect(payload.subarray(compressedOffset + 12)).toEqual(new Uint8Array([0x90, ...raw]));
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test.each([
|
|
50
|
-
['1.0.0', false],
|
|
51
|
-
['1.0.1-beta.1', false],
|
|
52
|
-
['1.0.1', true],
|
|
53
|
-
['1.1.0', true],
|
|
54
|
-
[undefined, false],
|
|
55
|
-
])('selects package uploads for firmware %s', (firmwareVersion, expected) => {
|
|
56
|
-
expect(supportsPro2HostAssetPackage(firmwareVersion)).toBe(expected);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare const PRO2_HOST_ASSET_PACKAGE_MIN_VERSION = "1.0.1";
|
|
2
|
-
export type Pro2HostAssetPackageEntry = {
|
|
3
|
-
name: string;
|
|
4
|
-
data: Uint8Array;
|
|
5
|
-
};
|
|
6
|
-
export declare function supportsPro2HostAssetPackage(firmwareVersion: string | undefined): boolean;
|
|
7
|
-
export declare function buildPro2HostAssetPackage(entries: Pro2HostAssetPackageEntry[]): Uint8Array;
|
|
8
|
-
//# sourceMappingURL=pro2HostAssetPackage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pro2HostAssetPackage.d.ts","sourceRoot":"","sources":["../../src/utils/pro2HostAssetPackage.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,mCAAmC,UAAU,CAAC;AAwB3D,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAQF,wBAAgB,4BAA4B,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAMzF;AA2QD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,yBAAyB,EAAE,GAAG,UAAU,CA4B1F"}
|