@onekeyfe/hd-core 1.2.2-alpha.7 → 1.2.2-alpha.8
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.
|
@@ -154,7 +154,7 @@ describe('openWalletSession', () => {
|
|
|
154
154
|
expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', standardSessionGet);
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
test('
|
|
157
|
+
test('opens the already-unlocked standard wallet without repeating Main PIN when passphrase is disabled', async () => {
|
|
158
158
|
const typedCall = jest.fn((request: string) => {
|
|
159
159
|
if (request === 'ProtocolInfoRequest') {
|
|
160
160
|
return { message: { version: 2 } };
|
|
@@ -173,11 +173,7 @@ describe('openWalletSession', () => {
|
|
|
173
173
|
|
|
174
174
|
await getProtocolV2WalletSession(device as any, { onlyMainPin: true });
|
|
175
175
|
|
|
176
|
-
expect(device.unlockDevice).
|
|
177
|
-
source: 'wallet-session-coordinator',
|
|
178
|
-
reason: 'open-wallet',
|
|
179
|
-
deviceOnly: true,
|
|
180
|
-
});
|
|
176
|
+
expect(device.unlockDevice).not.toHaveBeenCalled();
|
|
181
177
|
expect(typedCall).not.toHaveBeenCalledWith(
|
|
182
178
|
'DeviceSessionAskPassphrase',
|
|
183
179
|
'Success',
|
|
@@ -186,6 +182,47 @@ describe('openWalletSession', () => {
|
|
|
186
182
|
expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', standardSessionGet);
|
|
187
183
|
});
|
|
188
184
|
|
|
185
|
+
test('still requires Main PIN when a cached standard session resolves to another wallet', async () => {
|
|
186
|
+
let sessionGetCount = 0;
|
|
187
|
+
const typedCall = jest.fn((request: string) => {
|
|
188
|
+
if (request === 'ProtocolInfoRequest') {
|
|
189
|
+
return { message: { version: 2 } };
|
|
190
|
+
}
|
|
191
|
+
if (request === 'DeviceSessionGet') {
|
|
192
|
+
sessionGetCount += 1;
|
|
193
|
+
return {
|
|
194
|
+
message: {
|
|
195
|
+
btc_test_address:
|
|
196
|
+
sessionGetCount === 1 ? 'unexpected-wallet-state' : 'cached-standard-state',
|
|
197
|
+
session_id:
|
|
198
|
+
sessionGetCount === 1 ? 'unexpected-wallet-session' : 'cached-standard-session',
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
throw new Error(`Unexpected request: ${request}`);
|
|
203
|
+
});
|
|
204
|
+
const device = createDevice({ passphraseProtection: false, typedCall });
|
|
205
|
+
device.getStandardInternalState = jest.fn(() => ({
|
|
206
|
+
passphraseState: 'cached-standard-state',
|
|
207
|
+
sessionId: 'cached-standard-session',
|
|
208
|
+
}));
|
|
209
|
+
device.clearStandardInternalState = jest.fn();
|
|
210
|
+
|
|
211
|
+
await expect(
|
|
212
|
+
getProtocolV2WalletSession(device as any, { onlyMainPin: true })
|
|
213
|
+
).resolves.toMatchObject({
|
|
214
|
+
passphraseState: 'cached-standard-state',
|
|
215
|
+
newSession: 'cached-standard-session',
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, {
|
|
219
|
+
source: 'wallet-session-coordinator',
|
|
220
|
+
reason: 'session-recovery',
|
|
221
|
+
deviceOnly: true,
|
|
222
|
+
});
|
|
223
|
+
expect(sessionGetCount).toBe(2);
|
|
224
|
+
});
|
|
225
|
+
|
|
189
226
|
test('reuses a Main PIN selected by the current preflight when passphrase is disabled', async () => {
|
|
190
227
|
const typedCall = jest.fn((request: string) => {
|
|
191
228
|
if (request === 'ProtocolInfoRequest') {
|
package/dist/index.js
CHANGED
|
@@ -41981,7 +41981,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41981
41981
|
standardWalletSelected = true;
|
|
41982
41982
|
}
|
|
41983
41983
|
});
|
|
41984
|
-
const selectStandardWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41984
|
+
const selectStandardWallet = (forceMainPin = false) => __awaiter(this, void 0, void 0, function* () {
|
|
41985
41985
|
var _q;
|
|
41986
41986
|
if (((_q = device.features) === null || _q === void 0 ? void 0 : _q.passphraseProtection) === true) {
|
|
41987
41987
|
yield selectMainPin();
|
|
@@ -41992,7 +41992,8 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41992
41992
|
standardWalletSelected = true;
|
|
41993
41993
|
}
|
|
41994
41994
|
else if (!standardWalletSelected) {
|
|
41995
|
-
yield selectMainPin(
|
|
41995
|
+
yield selectMainPin(forceMainPin);
|
|
41996
|
+
standardWalletSelected = true;
|
|
41996
41997
|
}
|
|
41997
41998
|
});
|
|
41998
41999
|
if (readCurrentAttachPinSession) {
|
|
@@ -42091,7 +42092,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42091
42092
|
}
|
|
42092
42093
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42093
42094
|
(_h = device.clearStandardInternalState) === null || _h === void 0 ? void 0 : _h.call(device);
|
|
42094
|
-
yield selectStandardWallet();
|
|
42095
|
+
yield selectStandardWallet(true);
|
|
42095
42096
|
response = yield getDeviceSession(device, sessionGetRequest());
|
|
42096
42097
|
}
|
|
42097
42098
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AA8JD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;;;;;;
|
|
1
|
+
{"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AA8JD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;;;;;;GAyXF;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,uBAAuB,EAAE,MAAM,EAC/B,aAAa,CAAC,EAAE,OAAO;;;;;;GAOxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
3
|
+
"version": "1.2.2-alpha.8",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.2-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.2-alpha.8",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.2-alpha.8",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "7a5d129ea1db0b3eb230e309ab29ed3e9e7f141e"
|
|
50
50
|
}
|
|
@@ -371,7 +371,7 @@ export async function getProtocolV2WalletSession(
|
|
|
371
371
|
}
|
|
372
372
|
};
|
|
373
373
|
|
|
374
|
-
const selectStandardWallet = async () => {
|
|
374
|
+
const selectStandardWallet = async (forceMainPin = false) => {
|
|
375
375
|
if (device.features?.passphraseProtection === true) {
|
|
376
376
|
// Main PIN authenticates the device; an empty host passphrase selects the standard derivation.
|
|
377
377
|
await selectMainPin();
|
|
@@ -387,8 +387,10 @@ export async function getProtocolV2WalletSession(
|
|
|
387
387
|
standardWalletSelected = true;
|
|
388
388
|
} else if (!standardWalletSelected) {
|
|
389
389
|
// Without passphrase protection there is no empty-passphrase selector.
|
|
390
|
-
//
|
|
391
|
-
|
|
390
|
+
// An unlocked non-Attach-PIN device is already in the only available wallet context.
|
|
391
|
+
// Force Main PIN only when recovering from a mismatched cached standard session.
|
|
392
|
+
await selectMainPin(forceMainPin);
|
|
393
|
+
standardWalletSelected = true;
|
|
392
394
|
}
|
|
393
395
|
};
|
|
394
396
|
|
|
@@ -499,7 +501,7 @@ export async function getProtocolV2WalletSession(
|
|
|
499
501
|
}
|
|
500
502
|
if (options?.onlyMainPin) {
|
|
501
503
|
device.clearStandardInternalState?.();
|
|
502
|
-
await selectStandardWallet();
|
|
504
|
+
await selectStandardWallet(true);
|
|
503
505
|
response = await getDeviceSession(device, sessionGetRequest());
|
|
504
506
|
} else {
|
|
505
507
|
device.clearInternalState();
|