Skip to content

Conversation

@Akaryatrh
Copy link
Contributor

@Akaryatrh Akaryatrh commented Aug 25, 2025

Adds OneKey keyring based on OneKey libraries.


Note

Adds a new hardware keyring package and wires it into the monorepo.

  • New package: @metamask/eth-onekey-keyring with OneKeyKeyring and OneKeyWebBridge integrating OneKey’s @onekeyfe/hd-* SDKs
  • Supports signTransaction, signPersonalMessage/signMessage, and signTypedData (EIP-712), plus account paging, unlock, HD path management, and serialization
  • Extensive Jest tests, package configs (TypeScript, Jest, Typedoc), README, CHANGELOG, and LICENSE
  • Monorepo updates: README package list/graph entries, root tsconfig.json/tsconfig.build.json references, and workspace dependencies

Written by Cursor Bugbot for commit e40d1ad. This will update automatically on new commits. Configure here.

@Akaryatrh Akaryatrh requested a review from a team as a code owner August 25, 2025 13:44
@socket-security
Copy link

socket-security bot commented Aug 25, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​onekeyfe/​hd-shared@​1.1.17-patch.1821007298100
Added@​types/​bytebuffer@​5.0.491001007480100
Added@​onekeyfe/​hd-transport@​1.1.17-patch.1841008398100
Added@​onekeyfe/​hd-web-sdk@​1.1.17-patch.1851008698100
Added@​onekeyfe/​hd-core@​1.1.17-patch.1851008598100

View full report

@Akaryatrh Akaryatrh force-pushed the feat/onekey-keyring branch from 2dc83be to a18c779 Compare August 25, 2025 13:46
@Akaryatrh Akaryatrh added the team-hardware-wallets This should be handled by the Hardware Wallets Team label Aug 25, 2025
@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

cursor[bot]

This comment was marked as outdated.

@github-actions
Copy link

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.9.0-a18c779",
  "@metamask-previews/keyring-api": "20.1.0-a18c779",
  "@metamask-previews/eth-hd-keyring": "12.1.0-a18c779",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-a18c779",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-a18c779",
  "@metamask-previews/eth-qr-keyring": "0.0.0-a18c779",
  "@metamask-previews/eth-simple-keyring": "10.0.0-a18c779",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-a18c779",
  "@metamask-previews/keyring-internal-api": "8.1.0-a18c779",
  "@metamask-previews/keyring-internal-snap-client": "6.0.0-a18c779",
  "@metamask-previews/eth-snap-keyring": "16.1.0-a18c779",
  "@metamask-previews/keyring-snap-client": "7.0.0-a18c779",
  "@metamask-previews/keyring-snap-sdk": "6.0.0-a18c779",
  "@metamask-previews/keyring-utils": "3.1.0-a18c779"
}

@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.9.0-a621908",
  "@metamask-previews/keyring-api": "20.1.0-a621908",
  "@metamask-previews/eth-hd-keyring": "12.1.0-a621908",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-a621908",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-a621908",
  "@metamask-previews/eth-qr-keyring": "0.0.0-a621908",
  "@metamask-previews/eth-simple-keyring": "10.0.0-a621908",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-a621908",
  "@metamask-previews/keyring-internal-api": "8.1.0-a621908",
  "@metamask-previews/keyring-internal-snap-client": "6.0.0-a621908",
  "@metamask-previews/eth-snap-keyring": "16.1.0-a621908",
  "@metamask-previews/keyring-snap-client": "7.0.0-a621908",
  "@metamask-previews/keyring-snap-sdk": "6.0.0-a621908",
  "@metamask-previews/keyring-utils": "3.1.0-a621908"
}

cursor[bot]

This comment was marked as outdated.

@Akaryatrh Akaryatrh mentioned this pull request Aug 26, 2025
@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.9.0-3e52ac6",
  "@metamask-previews/keyring-api": "20.1.0-3e52ac6",
  "@metamask-previews/eth-hd-keyring": "12.1.0-3e52ac6",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-3e52ac6",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-3e52ac6",
  "@metamask-previews/eth-qr-keyring": "0.0.0-3e52ac6",
  "@metamask-previews/eth-simple-keyring": "10.0.0-3e52ac6",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-3e52ac6",
  "@metamask-previews/keyring-internal-api": "8.1.0-3e52ac6",
  "@metamask-previews/keyring-internal-snap-client": "6.0.0-3e52ac6",
  "@metamask-previews/eth-snap-keyring": "16.1.0-3e52ac6",
  "@metamask-previews/keyring-snap-client": "7.0.0-3e52ac6",
  "@metamask-previews/keyring-snap-sdk": "6.0.0-3e52ac6",
  "@metamask-previews/keyring-utils": "3.1.0-3e52ac6"
}

@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

2 similar comments
@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

github-actions bot commented Sep 4, 2025

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.9.0-a4bb524",
  "@metamask-previews/keyring-api": "20.1.0-a4bb524",
  "@metamask-previews/eth-hd-keyring": "12.1.0-a4bb524",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-a4bb524",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-a4bb524",
  "@metamask-previews/eth-qr-keyring": "0.0.0-a4bb524",
  "@metamask-previews/eth-simple-keyring": "10.0.0-a4bb524",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-a4bb524",
  "@metamask-previews/keyring-internal-api": "8.1.0-a4bb524",
  "@metamask-previews/keyring-internal-snap-client": "6.0.0-a4bb524",
  "@metamask-previews/eth-snap-keyring": "16.1.0-a4bb524",
  "@metamask-previews/keyring-snap-client": "7.0.0-a4bb524",
  "@metamask-previews/keyring-snap-sdk": "6.0.0-a4bb524",
  "@metamask-previews/keyring-utils": "3.1.0-a4bb524"
}

@Akaryatrh Akaryatrh force-pushed the feat/onekey-keyring branch from a9761e5 to 8508712 Compare December 1, 2025 09:53
@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.12.0-8508712",
  "@metamask-previews/keyring-api": "21.3.0-8508712",
  "@metamask-previews/eth-hd-keyring": "13.0.0-8508712",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-8508712",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-8508712",
  "@metamask-previews/eth-qr-keyring": "1.1.0-8508712",
  "@metamask-previews/eth-simple-keyring": "11.0.0-8508712",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-8508712",
  "@metamask-previews/keyring-internal-api": "9.1.1-8508712",
  "@metamask-previews/keyring-internal-snap-client": "8.0.1-8508712",
  "@metamask-previews/eth-snap-keyring": "18.0.2-8508712",
  "@metamask-previews/keyring-snap-client": "8.1.1-8508712",
  "@metamask-previews/keyring-snap-sdk": "7.1.1-8508712",
  "@metamask-previews/keyring-utils": "3.1.0-8508712"
}

reject(new Error('signature doesnt match the right address'));
}
// eslint-disable-next-line promise/no-multiple-resolved
resolve(signature);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing return after reject causes dual promise settlement

In signPersonalMessage, when the recovered address doesn't match the expected account, reject() is called but execution continues without returning. This causes resolve(signature) on line 427 to also be called. The eslint-disable-next-line promise/no-multiple-resolved comment explicitly suppresses the linter warning about this issue rather than fixing it. While Promise semantics make only the first settlement effective, calling both reject() and resolve() is a control flow error indicating the code doesn't properly stop execution after detecting the address mismatch.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

async dispose(): Promise<void> {
this.sdk?.dispose();
return Promise.resolve();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Dispose leaves bridge in inconsistent reinitialization state

The dispose() method calls this.sdk?.dispose() but doesn't reset isSDKInitialized or sdk. When keyring.destroy() calls bridge.dispose(), the bridge is left in an inconsistent state where isSDKInitialized remains true and sdk still references the disposed SDK. If init() is called afterward, it returns early because isSDKInitialized is true, preventing reinitialization. Subsequent operations will then use the disposed SDK. The destroy() method properly resets state but is never called by the keyring.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor's comment here make sense. We should add this.isSDKInitialized = false;.

Comment on lines 135 to 137
return await this.sdk
.evmGetPublicKey('', '', { ...params, skipPassphraseCheck: true })
.then((result) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid mixing .then().catch() with async/awaits? Can we use async/await only to improve readability?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll make some revisions.

},
};
}
return await this.sdk.getPassphraseState('').then((result) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to my other comment, can we use a more consistent pattern with promises?

...params,
skipPassphraseCheck: true,
})
.then((result) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to other comments, can we use async/await only?

...params,
skipPassphraseCheck: true,
})
.then((result) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use async/await?

...params,
skipPassphraseCheck: true,
})
.then((result) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use async/await?

reject(new Error('signature doesnt match the right address'));
}
// eslint-disable-next-line promise/no-multiple-resolved
resolve(signature);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing return after reject causes promise to resolve erroneously

In signPersonalMessage, when the signature address doesn't match the expected account, reject() is called but execution continues and resolve() is also called on line 427. The eslint-disable comment for promise/no-multiple-resolved acknowledges this issue but doesn't fix it - a return statement is needed after the reject() call. This causes the promise to resolve with the signature even when it should be rejected, allowing invalid signatures to be returned to callers.

Fix in Cursor Fix in Web

{
debug: false,
fetchConfig: false,
connectSrc: 'https://jssdk.onekey.so/1.1.0/',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test expects wrong SDK version in connectSrc assertion

The test asserts that init() is called with connectSrc: 'https://jssdk.onekey.so/1.1.0/', but the actual implementation in onekey-web-bridge.ts uses version 1.1.17 ('https://jssdk.onekey.so/1.1.17/'). This version mismatch will cause the test to fail since the expected connectSrc value doesn't match what the code actually passes.

Fix in Cursor Fix in Web

reject(new Error('signature doesnt match the right address'));
}
// eslint-disable-next-line promise/no-multiple-resolved
resolve(signature);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing return after reject causes promise multiple resolution

In signPersonalMessage, when the signature address verification fails, reject() is called but execution continues to also call resolve(signature) because there's no return statement. This causes both rejection and resolution of the same promise. The eslint-disable comment promise/no-multiple-resolved acknowledges this issue was suppressed rather than fixed. Compare to signTypedData which correctly uses throw for the same scenario. This could cause the potentially invalid signature to be returned despite the verification failure.

Fix in Cursor Fix in Web

reject(new Error('signature doesnt match the right address'));
}
// eslint-disable-next-line promise/no-multiple-resolved
resolve(signature);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing return after reject causes both reject and resolve

In signPersonalMessage, when the signature address verification fails (lines 420-424), reject() is called but execution continues to resolve(signature) on line 427 because there's no return statement after the reject(). The ESLint comment promise/no-multiple-resolved explicitly acknowledges this issue but suppresses the warning rather than fixing it. While the promise will technically reject (since reject is called first), both reject and resolve are invoked in the same code path, which indicates unintended control flow.

Fix in Cursor Fix in Web

@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.12.0-ca02a28",
  "@metamask-previews/keyring-api": "21.3.0-ca02a28",
  "@metamask-previews/eth-hd-keyring": "13.0.0-ca02a28",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-ca02a28",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-ca02a28",
  "@metamask-previews/eth-qr-keyring": "1.1.0-ca02a28",
  "@metamask-previews/eth-simple-keyring": "11.0.0-ca02a28",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-ca02a28",
  "@metamask-previews/keyring-internal-api": "9.1.1-ca02a28",
  "@metamask-previews/keyring-internal-snap-client": "8.0.1-ca02a28",
  "@metamask-previews/eth-snap-keyring": "18.0.2-ca02a28",
  "@metamask-previews/keyring-snap-client": "8.1.1-ca02a28",
  "@metamask-previews/keyring-snap-sdk": "7.1.1-ca02a28",
  "@metamask-previews/keyring-utils": "3.1.0-ca02a28"
}

@Akaryatrh Akaryatrh force-pushed the feat/onekey-keyring branch from ca02a28 to 89518ee Compare January 9, 2026 10:23
@Akaryatrh
Copy link
Contributor Author

@SocketSecurity ignore npm/async-function

@Akaryatrh Akaryatrh force-pushed the feat/onekey-keyring branch from 89518ee to ca5bb42 Compare January 9, 2026 10:28
@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.12.0-ca5bb42",
  "@metamask-previews/keyring-api": "21.3.0-ca5bb42",
  "@metamask-previews/eth-hd-keyring": "13.0.0-ca5bb42",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-ca5bb42",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-ca5bb42",
  "@metamask-previews/eth-qr-keyring": "1.1.0-ca5bb42",
  "@metamask-previews/eth-simple-keyring": "11.0.0-ca5bb42",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-ca5bb42",
  "@metamask-previews/keyring-internal-api": "9.1.1-ca5bb42",
  "@metamask-previews/keyring-internal-snap-client": "8.0.1-ca5bb42",
  "@metamask-previews/eth-snap-keyring": "18.0.2-ca5bb42",
  "@metamask-previews/keyring-snap-client": "8.1.1-ca5bb42",
  "@metamask-previews/keyring-snap-sdk": "7.1.1-ca5bb42",
  "@metamask-previews/keyring-utils": "3.1.0-ca5bb42"
}

reject(new Error('signature doesnt match the right address'));
}
// eslint-disable-next-line promise/no-multiple-resolved
resolve(signature);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return after reject causes double promise resolution

Medium Severity

In signPersonalMessage, when the recovered signature address doesn't match the expected account, reject() is called but execution continues and resolve(signature) is also invoked. The eslint-disable-next-line promise/no-multiple-resolved comment confirms this was caught by the linter but suppressed rather than fixed. While Promise semantics mean the rejection wins, calling both reject and resolve on the same promise is incorrect behavior and could lead to confusion or bugs if the code is modified later. A return statement is needed after the reject() call.

Fix in Cursor Fix in Web

#onUIEvent?: ((event: Unsuccessful['payload']) => void) | undefined;

#handleBlockErrorEvent(payload: Unsuccessful): void {
const { code } = payload.payload;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check causes crash in error handler

Medium Severity

The #handleBlockErrorEvent method immediately destructures payload.payload without a null check, but callers pass result after checking result?.success with optional chaining. This inconsistency means if an SDK method returns null or undefined, the optional chaining check passes (since undefined?.success is falsy), but then #handleBlockErrorEvent(result) crashes with a TypeError when accessing undefined.payload. The pattern repeats in getPublicKey, getPassphraseState, ethereumSignTransaction, ethereumSignMessage, and ethereumSignTypedData.

Additional Locations (2)

Fix in Cursor Fix in Web

@Akaryatrh
Copy link
Contributor Author

@SocketSecurity ignore npm/async-function@1.0.0

reject(new Error('signature doesnt match the right address'));
}
// eslint-disable-next-line promise/no-multiple-resolved
resolve(signature);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return after reject causes multiple promise settlements

Medium Severity

In signPersonalMessage, when the recovered address doesn't match the expected address, reject() is called but execution continues and resolve(signature) is also called. The eslint-disable comment for promise/no-multiple-resolved acknowledges this issue but masks it rather than fixing it. A return statement is needed after the reject() call to prevent the promise from being settled twice and to avoid returning an invalid signature path.

Fix in Cursor Fix in Web

},
});
}
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI_EVENT subscription never removed causes memory leak

Medium Severity

The UI_EVENT event listener added via this.sdk?.on('UI_EVENT', ...) in init() is never unsubscribed. Neither destroy() nor dispose() removes this listener before clearing the SDK reference. The callback closure holds references to this (the bridge instance), causing memory to accumulate if the bridge is initialized and destroyed multiple times during the application lifecycle.

Additional Locations (1)

Fix in Cursor Fix in Web

async dispose(): Promise<void> {
this.sdk?.dispose();
return Promise.resolve();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dispose() doesn't reset state preventing SDK re-initialization

Medium Severity

The dispose() method calls sdk.dispose() but doesn't reset isSDKInitialized or sdk. Since OneKeyKeyring.destroy() calls bridge.dispose() (not bridge.destroy()), the bridge is left in an inconsistent state where isSDKInitialized remains true but the SDK is disposed. Subsequent calls to init() return early without re-initializing, and SDK method calls will fail on the disposed SDK.

Additional Locations (1)

Fix in Cursor Fix in Web

@Akaryatrh
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "0.12.0-e40d1ad",
  "@metamask-previews/keyring-api": "21.3.0-e40d1ad",
  "@metamask-previews/eth-hd-keyring": "13.0.0-e40d1ad",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.1.2-e40d1ad",
  "@metamask-previews/eth-onekey-keyring": "0.1.0-e40d1ad",
  "@metamask-previews/eth-qr-keyring": "1.1.0-e40d1ad",
  "@metamask-previews/eth-simple-keyring": "11.0.0-e40d1ad",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-e40d1ad",
  "@metamask-previews/keyring-internal-api": "9.1.1-e40d1ad",
  "@metamask-previews/keyring-internal-snap-client": "8.0.1-e40d1ad",
  "@metamask-previews/eth-snap-keyring": "18.0.2-e40d1ad",
  "@metamask-previews/keyring-snap-client": "8.1.1-e40d1ad",
  "@metamask-previews/keyring-snap-sdk": "7.1.1-e40d1ad",
  "@metamask-previews/keyring-utils": "3.1.0-e40d1ad"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-hardware-wallets This should be handled by the Hardware Wallets Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants