-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add OneKey keyring #353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
ec02eda
be93f69
7bd08e8
8648ef2
cbc7a7d
f8dc1e0
04710f6
deea5da
a18c779
a621908
f7e6591
3e52ac6
a4bb524
8dab699
cc191ea
532ba69
e4453a3
7cd0f44
2c8529e
2d94f20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,12 @@ import type { TypedTransaction, TypedTxData } from '@ethereumjs/tx'; | |
| import { TransactionFactory } from '@ethereumjs/tx'; | ||
| import * as ethUtil from '@ethereumjs/util'; | ||
| import type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util'; | ||
| import { SignTypedDataVersion, TypedDataUtils } from '@metamask/eth-sig-util'; | ||
| import { | ||
| SignTypedDataVersion, | ||
| TypedDataUtils, | ||
| recoverPersonalSignature, | ||
| recoverTypedSignature, | ||
| } from '@metamask/eth-sig-util'; | ||
| import type { Keyring } from '@metamask/keyring-utils'; | ||
| import type { Hex } from '@metamask/utils'; | ||
| import type { | ||
|
|
@@ -407,13 +412,17 @@ export class OneKeyKeyring implements Keyring { | |
| }) | ||
| .then((response) => { | ||
| if (response.success) { | ||
| const signature = addHexPrefix(response.payload.signature); | ||
| const addressSignedWith = recoverPersonalSignature({ | ||
| data: message, | ||
| signature, | ||
| }); | ||
| if ( | ||
| response.payload.address !== | ||
| ethUtil.toChecksumAddress(addressSignedWith) !== | ||
| ethUtil.toChecksumAddress(withAccount) | ||
| ) { | ||
| reject(new Error('signature doesnt match the right address')); | ||
| } | ||
| const signature = addHexPrefix(response.payload.signature); | ||
| // eslint-disable-next-line promise/no-multiple-resolved | ||
| resolve(signature); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing return after reject causes dual promise settlementIn
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing return after reject causes promise to resolve erroneouslyIn |
||
| } else { | ||
|
|
@@ -463,10 +472,19 @@ export class OneKeyKeyring implements Keyring { | |
| }); | ||
|
|
||
| if (response.success) { | ||
| if (ethUtil.toChecksumAddress(address) !== response.payload.address) { | ||
| const signature = addHexPrefix(response.payload.signature); | ||
| const addressSignedWith = recoverTypedSignature({ | ||
| data: typedData, | ||
| signature, | ||
| version: dataVersion, | ||
| }); | ||
| if ( | ||
| ethUtil.toChecksumAddress(addressSignedWith) !== | ||
| ethUtil.toChecksumAddress(address) | ||
| ) { | ||
| throw new Error('signature doesnt match the right address'); | ||
| } | ||
| return addHexPrefix(response.payload.signature); | ||
| return signature; | ||
| } | ||
|
|
||
| throw new Error(response.payload?.error || 'Unknown error'); | ||
|
|
||
There was a problem hiding this comment.
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 double promise resolution
In
signPersonalMessage, when the address verification fails (lines 410-414),reject()is called but execution continues without areturnstatement. This causesresolve(signature)to also be called on line 418. The// eslint-disable-next-line promise/no-multiple-resolvedcomment explicitly acknowledges this issue. While Promise semantics cause the first call (reject) to take effect, the control flow is broken—the code afterreject()still runs unnecessarily. The similarsignTypedDatamethod correctly handles this case by usingthrowinstead, which properly exits the function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor is right here, you should remove the
// eslint-disable-next-lineand put theresolvein aelse {}block.