Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/connect-examples/electron-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hardware-example",
"productName": "HardwareExample",
"executableName": "onekey-hardware-example",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"author": "OneKey",
"description": "OneKey Hardware SDK Electron BLE example",
"main": "dist/index.js",
Expand All @@ -21,7 +21,7 @@
"ts:check": "yarn tsc --noEmit"
},
"dependencies": {
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.148",
"@stoprocent/noble": "2.3.16",
"debug": "4.3.4",
"electron-is-dev": "^3.0.1",
Expand Down
12 changes: 6 additions & 6 deletions packages/connect-examples/expo-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-example",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"scripts": {
"start": "yarn expo start --dev-client",
"android": "yarn expo run:android",
Expand All @@ -19,11 +19,11 @@
"@noble/ed25519": "^2.1.0",
"@noble/hashes": "^1.3.3",
"@noble/secp256k1": "^1.7.1",
"@onekeyfe/hd-ble-sdk": "1.2.0-alpha.142",
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.142",
"@onekeyfe/hd-core": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142",
"@onekeyfe/hd-ble-sdk": "1.2.0-alpha.148",
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.148",
"@onekeyfe/hd-core": "1.2.0-alpha.148",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
"@onekeyfe/react-native-ble-utils": "^0.1.3",
"@polkadot/util-crypto": "13.1.1",
"@react-native-async-storage/async-storage": "1.21.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/connect-examples/expo-playground/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onekey-hardware-playground",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"private": true,
"sideEffects": [
"app/utils/shim.js",
Expand All @@ -19,10 +19,10 @@
},
"dependencies": {
"@noble/hashes": "^1.8.0",
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.142",
"@onekeyfe/hd-core": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142",
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.148",
"@onekeyfe/hd-core": "1.2.0-alpha.148",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
"@radix-ui/react-checkbox": "^1.3.2",
"@radix-ui/react-dialog": "^1.1.14",
"@radix-ui/react-dropdown-menu": "^2.1.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-examples/hwk-demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hwk-demo",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"private": true,
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-core",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -25,8 +25,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
"axios": "1.15.2",
"bignumber.js": "^9.0.2",
"buffer": "^6.0.3",
Expand Down
93 changes: 87 additions & 6 deletions packages/core/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ const onCallDevice = async (
if (method.payload?.onlyConnectBleDevice) {
preWarmCallbackTask?.resolve();
Log.debug('Call API - only connect ble device: ', device?.mainId);
// This early return bypasses the normal-path releaseTask at the end of the
// call; without it the task leaks and haunts every later queue snapshot
// and cancel sweep (field log: a completed task lingered for 6 minutes).
requestQueue.releaseTask(method.responseID);
return createResponseMessage(method.responseID, true, null);
}

Expand Down Expand Up @@ -938,7 +942,60 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
* If the Bluetooth connection times out, retry up to 6 times
* @param retryCount - Current retry count (default 0)
*/
async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
// device.acquire awaits a transport reply with no deadline of its own; a
// transport that never settles (field case: Electron main lost an IPC reply,
// "reply was never sent" after 5 minutes) hangs the call forever and cancel()
// only takes effect at poll checkpoints. Race acquire against a deadline and
// the caller's abort signal so the hang is bounded and cancel is immediate.
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;

function raceBleAcquire<T>(acquirePromise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {
return new Promise<T>((resolve, reject) => {
let settled = false;
const settle = (fn: () => void) => {
if (settled) return;
settled = true;
clearTimeout(deadline);
abortSignal?.removeEventListener('abort', onAbort);
fn();
};
const onAbort = () =>
settle(() => reject(ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)));
const deadline = setTimeout(
() =>
settle(() =>
reject(
ERRORS.TypedError(
HardwareErrorCode.BleTimeoutError,
`BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`
)
)
),
BLE_ACQUIRE_DEADLINE_MS
);
// Attach before any early return so a late settlement of acquirePromise
// is always consumed — an abort or deadline must never leave the acquire
// rejection unhandled.
acquirePromise.then(
value => settle(() => resolve(value)),
error => settle(() => reject(error))
);
if (abortSignal) {
if (abortSignal.aborted) {
onAbort();
return;
}
abortSignal.addEventListener('abort', onAbort);
}
});
}

async function connectDeviceForBle(
method: BaseMethod,
device: Device,
abortSignal?: AbortSignal,
retryCount = 0
) {
try {
if (method.payload.forceProtocolDetection && device.hasDeviceAcquire()) {
await device.release();
Expand All @@ -949,9 +1006,31 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
!device.commands ||
device.commands.disposed;
if (shouldAcquire) {
await device.acquire(method.payload.connectProtocol, {
forceProtocolDetection: method.payload.forceProtocolDetection,
});
// A cancel landing during the retry backoff must not start a new acquire.
if (abortSignal?.aborted) {
throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
}
try {
await raceBleAcquire(
device.acquire(method.payload.connectProtocol, {
forceProtocolDetection: method.payload.forceProtocolDetection,
}),
abortSignal
);
} catch (err) {
// A deadline hit means the transport is wedged mid-acquire; drop the
// link before the retry so it cold-connects instead of stacking a
// second connect onto the half-open one.
if (
err.errorCode === HardwareErrorCode.BleTimeoutError &&
device.mainId &&
device.deviceConnector
) {
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
device.markTransportDisconnected();
}
throw err;
}
}
if (method.payload?.onlyConnectBleDevice) {
if (shouldAcquire) {
Expand Down Expand Up @@ -997,7 +1076,7 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
const nextRetry = retryCount + 1;
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
await wait(3000);
await connectDeviceForBle(method, device, nextRetry);
await connectDeviceForBle(method, device, abortSignal, nextRetry);
} else {
throw err;
}
Expand Down Expand Up @@ -1102,7 +1181,7 @@ const ensureConnected = async (
if (abort()) {
return;
}
await connectDeviceForBle(method, device);
await connectDeviceForBle(method, device, abortSignal);
}
resolve(device);
return;
Expand Down Expand Up @@ -1144,6 +1223,8 @@ const ensureConnected = async (
HardwareErrorCode.DeviceDetectInBootloaderMode,
HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
HardwareErrorCode.BridgeNeedsPermission,
// Cancel must fail the call now, not after another poll round.
HardwareErrorCode.CallQueueActionCancelled,
].includes(error.errorCode)
) {
reject(error);
Expand Down
8 changes: 4 additions & 4 deletions packages/hd-ble-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-ble-sdk",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,8 +20,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-react-native": "1.2.0-alpha.142"
"@onekeyfe/hd-core": "1.2.0-alpha.148",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport-react-native": "1.2.0-alpha.148"
}
}
10 changes: 5 additions & 5 deletions packages/hd-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hardware-cli",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"description": "OneKey hardware wallet CLI for testing device communication",
"author": "OneKey",
"license": "Apache-2.0",
Expand Down Expand Up @@ -31,10 +31,10 @@
"test": "jest"
},
"dependencies": {
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.142",
"@onekeyfe/hd-core": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-usb": "1.2.0-alpha.142",
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.148",
"@onekeyfe/hd-core": "1.2.0-alpha.148",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport-usb": "1.2.0-alpha.148",
"@stoprocent/noble": "2.3.16",
"commander": "^12.0.0"
}
Expand Down
16 changes: 8 additions & 8 deletions packages/hd-common-connect-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-common-connect-sdk",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,12 +20,12 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-emulator": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-http": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-lowlevel": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-usb": "1.2.0-alpha.142",
"@onekeyfe/hd-transport-web-device": "1.2.0-alpha.142"
"@onekeyfe/hd-core": "1.2.0-alpha.148",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport-emulator": "1.2.0-alpha.148",
"@onekeyfe/hd-transport-http": "1.2.0-alpha.148",
"@onekeyfe/hd-transport-lowlevel": "1.2.0-alpha.148",
"@onekeyfe/hd-transport-usb": "1.2.0-alpha.148",
"@onekeyfe/hd-transport-web-device": "1.2.0-alpha.148"
}
}
8 changes: 4 additions & 4 deletions packages/hd-transport-electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-electron",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
Expand All @@ -25,9 +25,9 @@
"electron-log": ">=4.0.0"
},
"dependencies": {
"@onekeyfe/hd-core": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142",
"@onekeyfe/hd-core": "1.2.0-alpha.148",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
"@stoprocent/noble": "2.3.16",
"p-retry": "^4.6.2"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/hd-transport-emulator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-emulator",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"description": "hardware emulator transport",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -24,8 +24,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
"axios": "1.15.2",
"secure-json-parse": "^4.0.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hd-transport-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-http",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"description": "hardware http transport",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -24,8 +24,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
"axios": "1.15.2",
"secure-json-parse": "^4.0.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hd-transport-lowlevel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-lowlevel",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -20,7 +20,7 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142"
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148"
}
}
8 changes: 4 additions & 4 deletions packages/hd-transport-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-react-native",
"version": "1.2.0-alpha.142",
"version": "1.2.0-alpha.148",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -20,9 +20,9 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "1.2.0-alpha.142",
"@onekeyfe/hd-shared": "1.2.0-alpha.142",
"@onekeyfe/hd-transport": "1.2.0-alpha.142",
"@onekeyfe/hd-core": "1.2.0-alpha.148",
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
"@onekeyfe/react-native-ble-utils": "^0.1.6",
"react-native-ble-plx": "3.5.1"
}
Expand Down
Loading
Loading