-
Notifications
You must be signed in to change notification settings - Fork 7
Keystone<>Core Mobile integration #3021
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
Open
Charon-Fan
wants to merge
19
commits into
ava-labs:main
Choose a base branch
from
KeystoneHQ:feat/keystone-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
54ac7d5
feat: Keystone integration
Charon-Fan 0b01a84
fix: update modal options to use formSheetScreensOptions for Keystone…
Charon-Fan df9bd4d
fix: simplify QRCode rendering in QRRenderer component
Charon-Fan a816362
feat: add light and dark QR code icons for Keystone troubleshooting s…
Charon-Fan 3440e90
fix: update Keystone onboarding navigation and SVG icon dimensions
Charon-Fan 2fd4a32
feat: implement KeystoneWallet and related components for wallet func…
Charon-Fan 83a1acf
Merge branch 'main' into feat/keystone-v2
Charon-Fan e718afc
refactor: update getPublicKeyFor method to accept an object and remov…
Charon-Fan 2420a73
chore: remove unused deps
Charon-Fan d250eeb
fix: update CreatePin to use active wallet ID when creating a new wallet
Charon-Fan 2d4363b
feat: enhance Ethereum signature handling in KeystoneWallet
Charon-Fan 2556db8
Merge branch 'main' into feat/keystone-v2
Charon-Fan 4c1701f
Merge branch 'main' into feat/keystone-v2
Charon-Fan 5695bea
feat: refactor Keystone integration and improve wallet data handling
Charon-Fan 1b2a38a
feat: enhance Keystone troubleshooting screen with step-by-step instr…
Charon-Fan f6b404f
feat: implement Keystone blocking logic and update access wallet navi…
Charon-Fan b2c32c2
Merge branch 'main' into feat/keystone-v2
Charon-Fan 2b2c3b6
feat: add KeystoneWallet implementation and related tests
Charon-Fan 82b9049
Merge branch 'main' into feat/keystone-v2
Charon-Fan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
packages/core-mobile/app/assets/icons/keystone_logo_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions
39
packages/core-mobile/app/hardware/services/KeystoneService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { UR } from '@ngraveio/bc-ur' | ||
import KeystoneSDK from '@keystonehq/keystone-sdk' | ||
import { fromPublicKey } from 'bip32' | ||
import { KeystoneDataStorage } from 'features/keystone/storage/KeystoneDataStorage' | ||
|
||
class KeystoneService { | ||
private walletInfo = { | ||
evm: '', | ||
xp: '', | ||
mfp: '' | ||
} | ||
|
||
init(ur: UR): void { | ||
const sdk = new KeystoneSDK() | ||
const accounts = sdk.parseMultiAccounts(ur) | ||
const mfp = accounts.masterFingerprint | ||
const ethAccount = accounts.keys.find(key => key.chain === 'ETH') | ||
const avaxAccount = accounts.keys.find(key => key.chain === 'AVAX') | ||
if (!ethAccount || !avaxAccount) { | ||
throw new Error('No ETH or AVAX account found') | ||
} | ||
|
||
this.walletInfo.evm = fromPublicKey( | ||
Buffer.from(ethAccount.publicKey, 'hex'), | ||
Buffer.from(ethAccount.chainCode, 'hex') | ||
).toBase58() | ||
this.walletInfo.xp = fromPublicKey( | ||
Buffer.from(avaxAccount.publicKey, 'hex'), | ||
Buffer.from(avaxAccount.chainCode, 'hex') | ||
).toBase58() | ||
this.walletInfo.mfp = mfp | ||
} | ||
|
||
async save(): Promise<void> { | ||
await KeystoneDataStorage.save(this.walletInfo) | ||
} | ||
} | ||
|
||
export default new KeystoneService() |
21 changes: 21 additions & 0 deletions
21
packages/core-mobile/app/hardware/wallet/keystoneSigner.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { UR } from '@ngraveio/bc-ur' | ||
import { requestKeystoneSigner } from 'features/keystone/utils' | ||
|
||
export const signer = async ( | ||
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. could you move this signer file to |
||
request: UR, | ||
responseURTypes: string[], | ||
handleResult: (cbor: Buffer) => Promise<string> | ||
): Promise<string> => { | ||
return new Promise<string>((resolve, reject) => { | ||
requestKeystoneSigner({ | ||
request, | ||
responseURTypes, | ||
onReject: (message?: string) => { | ||
reject(message ?? 'User rejected') | ||
}, | ||
onApprove: (cbor: Buffer) => { | ||
return handleResult(cbor).then(resolve).catch(reject) | ||
} | ||
}) | ||
}) | ||
} |
131 changes: 131 additions & 0 deletions
131
packages/core-mobile/app/new/common/components/KeystoneQrScanner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import React, { useState, useCallback, useEffect } from 'react' | ||
import { UR, URDecoder } from '@ngraveio/bc-ur' | ||
import * as Progress from 'react-native-progress' | ||
import { View, Text, SCREEN_WIDTH, useTheme } from '@avalabs/k2-alpine' | ||
import { showKeystoneTroubleshooting } from 'features/keystone/utils' | ||
import { QrCodeScanner } from './QrCodeScanner' | ||
import { Space } from './Space' | ||
|
||
const SCANNER_WIDTH = SCREEN_WIDTH - 64 | ||
|
||
interface Props { | ||
urTypes: string[] | ||
onSuccess: (ur: UR) => void | ||
onError?: () => void | ||
info?: string | ||
} | ||
|
||
export const KeystoneQrScanner: (props: Props) => JSX.Element = ({ | ||
info, | ||
urTypes, | ||
onSuccess, | ||
onError | ||
}) => { | ||
const [urDecoder, setUrDecoder] = useState(new URDecoder()) | ||
const [progress, setProgress] = useState<number>(0) | ||
const [showTroubleshooting, setShowTroubleshooting] = useState(false) | ||
const { theme } = useTheme() | ||
|
||
const progressColor = theme.isDark ? theme.colors.$white : theme.colors.$black | ||
const handleError = useCallback(() => { | ||
setUrDecoder(new URDecoder()) | ||
setShowTroubleshooting(true) | ||
if (onError) { | ||
onError() | ||
} | ||
}, [onError]) | ||
|
||
const showErrorSheet = useCallback(() => { | ||
showKeystoneTroubleshooting({ | ||
errorCode: -1, | ||
retry: () => { | ||
setShowTroubleshooting(false) | ||
setProgress(0) | ||
} | ||
}) | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (showTroubleshooting && !onError) { | ||
showErrorSheet() | ||
} | ||
}, [showTroubleshooting, showErrorSheet, onError]) | ||
|
||
const handleScan = useCallback( | ||
(code: string) => { | ||
if (showTroubleshooting) { | ||
return | ||
} | ||
try { | ||
urDecoder.receivePart(code) | ||
if (!urDecoder.isComplete()) { | ||
setProgress(urDecoder.estimatedPercentComplete()) | ||
return | ||
} | ||
|
||
if (urDecoder.isError()) { | ||
handleError() | ||
} | ||
|
||
if (urDecoder.isSuccess()) { | ||
const ur = urDecoder.resultUR() | ||
|
||
if (urTypes.includes(ur.type)) { | ||
setProgress(1) | ||
|
||
onSuccess(ur) | ||
} else { | ||
throw new Error('Invalid qr code') | ||
} | ||
} | ||
} catch (error) { | ||
handleError() | ||
} | ||
}, | ||
[ | ||
setProgress, | ||
onSuccess, | ||
urDecoder, | ||
urTypes, | ||
handleError, | ||
showTroubleshooting | ||
] | ||
) | ||
|
||
return ( | ||
<View sx={{ alignItems: 'center', height: '100%' }}> | ||
<QrCodeScanner | ||
paused={showTroubleshooting} | ||
onSuccess={handleScan} | ||
vibrate={progress !== 1} | ||
sx={{ | ||
width: SCANNER_WIDTH, | ||
height: SCANNER_WIDTH | ||
}} | ||
/> | ||
<View | ||
sx={{ | ||
alignItems: 'center', | ||
flexDirection: 'column' | ||
}}> | ||
<Space y={70} /> | ||
<Progress.Bar | ||
borderRadius={8} | ||
color={progressColor} | ||
width={290} | ||
height={16} | ||
progress={progress} | ||
style={{ | ||
opacity: [0, 1].includes(progress) ? 0 : 1 | ||
}} | ||
/> | ||
{info && ( | ||
<> | ||
<Space y={32} /> | ||
<Text>{info}</Text> | ||
</> | ||
)} | ||
</View> | ||
</View> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
could you move this service into
app/new/features/keystone/services
?