-
Notifications
You must be signed in to change notification settings - Fork 8
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
Telos Cloud Migration #720
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b7e9263
Metakeep prototype working
Viterbo 056dee9
now both EVM and Zero login buttons looks the same
Viterbo 0710c04
add loggin with google + metakeep
Viterbo 6f6d22d
MetaKeep working on both Zero and EVM!
Viterbo 90c7e36
minor fix
Viterbo 4d8cd04
fixing api parameter
Viterbo 25a86a4
save WIP
Viterbo 3402699
fixing the url for account creation
Viterbo 3617270
add jwt as part of the API endpoint security
Viterbo 6f8c951
incorporating jwt security param
Viterbo 1040b9d
migration from OreId to Metakeep
Viterbo 09052f3
Merge branch 'develop' of https://github.com/telosnetwork/telos-walle…
Viterbo 38e465c
resolve conflicts and fix broken unit tests
Viterbo 20fdb9c
ading expiration date
Viterbo 171a9a2
addressing Ezra's feedback
Viterbo 418d260
enable the Telos Cloud EVM button
Viterbo 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
This file contains 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 |
---|---|---|
|
@@ -34,5 +34,5 @@ yarn-error.log* | |
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
|
||
.vscode | ||
.env |
This file contains 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 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 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,87 @@ | ||
import { | ||
CURRENT_CONTEXT, | ||
useAccountStore, | ||
useBalancesStore, | ||
useChainStore, | ||
useNftsStore, | ||
} from 'src/antelope'; | ||
import { metakeepCache } from 'src/antelope/wallets/ual/utils/metakeep-cache'; | ||
|
||
const nftsStore = useNftsStore(); | ||
const balanceStore = useBalancesStore(); | ||
|
||
export const isTodayBeforeTelosCloudDown = new Date().getTime() < new Date('2023-12-31').getTime(); | ||
|
||
// ----- EVM ------ | ||
const ethPubKey = () => { | ||
const emails = metakeepCache.getMails(); | ||
if (emails.length > 0) { | ||
const ethPubKey = metakeepCache.getEthAddress(emails[0]); | ||
if (ethPubKey) { | ||
return ethPubKey; | ||
} | ||
} | ||
return ''; | ||
}; | ||
|
||
const hasAnyTokenBalance = () => balanceStore.currentBalances.some(balance => !balance.amount.isNegative() && !balance.amount.isZero()); | ||
const authenticator = () => useAccountStore().getAccount(CURRENT_CONTEXT).authenticator; | ||
const currentAuthName = () => authenticator()?.getName() || ''; | ||
const hasNfts = () => nftsStore.loggedInventory?.length > 0; | ||
const hasAssets = () => hasAnyTokenBalance() || hasNfts(); | ||
const isMigrationNeeded = () => currentAuthName() === 'OreId' && ethPubKey() !== '' && hasAssets() && isTodayBeforeTelosCloudDown; | ||
|
||
const evm = { | ||
hasNfts, | ||
hasAssets, | ||
ethPubKey, | ||
isMigrationNeeded, | ||
}; | ||
|
||
|
||
// ----- ZERO ------ | ||
const accountNameZero = () => { | ||
const emails = metakeepCache.getMails(); | ||
if (emails.length > 0) { | ||
const chainId = useChainStore().currentChain.settings.getChainId(); | ||
const names = metakeepCache.getAccountNames(emails[0], chainId); | ||
if (names.length > 0) { | ||
return names[0]; | ||
} | ||
} | ||
return ''; | ||
}; | ||
|
||
const currentAuthNameZero = () => localStorage.getItem('autoLogin'); | ||
const isMigrationNeededZero = () => currentAuthNameZero() === 'ual-oreid' && accountNameZero() !== '' && isTodayBeforeTelosCloudDown; | ||
|
||
const zero = { | ||
accountName: accountNameZero, | ||
isMigrationNeeded: isMigrationNeededZero, | ||
}; | ||
|
||
|
||
const update = () => { | ||
metakeepCache.loadCache(); | ||
}; | ||
|
||
const print = () => { | ||
console.log('-- EVM --'); | ||
console.log('ethPubKey', ethPubKey()); | ||
console.log('hasNfts', hasNfts()); | ||
console.log('hasAssets', hasAssets()); | ||
console.log('currentAuthName', currentAuthName()); | ||
console.log('hasAnyTokenBalance', hasAnyTokenBalance()); | ||
console.log('isMigrationNeeded ->', isMigrationNeeded()); | ||
console.log('-- ZERO --'); | ||
console.log('accountName ->', accountNameZero()); | ||
console.log('isMigrationNeeded ->', isMigrationNeededZero); | ||
console.log('currentAuthNameZero ->', currentAuthNameZero()); | ||
}; | ||
|
||
export const migration = { | ||
update, | ||
print, | ||
evm, | ||
zero, | ||
}; |
This file contains 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 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,172 @@ | ||
|
||
import { EthereumProvider } from 'src/antelope/types/Providers'; | ||
import { EVMAuthenticator } from 'src/antelope/wallets/authenticators/EVMAuthenticator'; | ||
import { InjectedProviderAuth } from 'src/antelope/wallets/authenticators/InjectedProviderAuth'; | ||
import { MetaKeep } from 'metakeep'; | ||
import { AntelopeError, addressString } from 'src/antelope/types'; | ||
|
||
import { ethers } from 'ethers'; | ||
import { useFeedbackStore } from 'src/antelope/stores/feedback'; | ||
import { metakeepCache } from 'src/antelope/wallets/ual/utils/metakeep-cache'; | ||
import { useChainStore } from 'src/antelope/stores/chain'; | ||
import { CURRENT_CONTEXT } from 'src/antelope'; | ||
import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; | ||
|
||
|
||
export interface MetakeepOptions { | ||
appId: string; | ||
appName: string; | ||
reasonCallback?: (transaction: never) => string; | ||
} | ||
|
||
let metakeep: MetaKeep | null = null; | ||
let web3Provider: ethers.providers.Web3Provider | null = null; | ||
|
||
const name = 'MetaKeep'; | ||
export const MetaKeepAuthName = name; | ||
export class MetaKeepAuth extends InjectedProviderAuth { | ||
|
||
accountAddress = ''; | ||
accountEmail = ''; | ||
appId = ''; | ||
appName = ''; | ||
reasonCallback?: (transaction: never) => string; | ||
|
||
// this is just a dummy label to identify the authenticator base class | ||
constructor(options: MetakeepOptions, label = name) { | ||
super(label); | ||
if (!options?.appId) { | ||
throw new AntelopeError('antelope.evm.error_metakeep_app_id'); | ||
} | ||
this.appId = options.appId; | ||
this.appName = options.appName; | ||
this.reasonCallback = options.reasonCallback; | ||
this.accountEmail = metakeepCache.getLogged() ?? ''; | ||
} | ||
|
||
// InjectedProviderAuth API ------------------------------------------------------ | ||
|
||
getProvider(): EthereumProvider | null { | ||
return window.ethereum as unknown as EthereumProvider ?? null; | ||
} | ||
|
||
// EVMAuthenticator API ---------------------------------------------------------- | ||
|
||
getName(): string { | ||
return name; | ||
} | ||
|
||
setEmail(email: string): void { | ||
this.accountEmail = email; | ||
metakeepCache.setLogged(email); | ||
} | ||
|
||
// this is the important instance creation where we define a label to assign to this instance of the authenticator | ||
newInstance(label: string): EVMAuthenticator { | ||
this.trace('newInstance', label); | ||
const auth = new MetaKeepAuth({ | ||
appId: this.appId, | ||
appName: this.appName, | ||
reasonCallback: this.reasonCallback, | ||
}, label); | ||
auth.setEmail(this.accountEmail); | ||
return auth; | ||
} | ||
|
||
async assertMetakeepSDKReady(): Promise<void> { | ||
if (!metakeep) { | ||
const chainSettings = (useChainStore().getChain(CURRENT_CONTEXT).settings as EVMChainSettings); | ||
const endpoint = chainSettings.getRPCEndpoint(); | ||
const url = `${endpoint.protocol}://${endpoint.host}:${endpoint.port}${endpoint.path ?? ''}`; | ||
|
||
const chainId: number = parseInt(chainSettings.getChainId()); | ||
|
||
|
||
const rpcNodeUrls = { | ||
[chainId]: url, | ||
} as unknown as Map<number, string>; | ||
|
||
metakeep = new MetaKeep({ | ||
// App id to configure UI | ||
appId: this.appId, | ||
// Default chain to use | ||
chainId, | ||
// RPC node urls map | ||
rpcNodeUrls, | ||
// Signed in user's email address | ||
user: { | ||
email: this.accountEmail, | ||
}, | ||
}); | ||
|
||
const provider = await metakeep.ethereum; | ||
await provider.enable(); | ||
web3Provider = new ethers.providers.Web3Provider(provider); | ||
} | ||
} | ||
|
||
async login(network: string): Promise<addressString | null> { | ||
this.trace('login', network); | ||
useFeedbackStore().setLoading(`${this.getName()}.login`); | ||
|
||
await this.assertMetakeepSDKReady(); | ||
|
||
// metakeepCache | ||
const accountAddress = metakeepCache.getEthAddress(this.accountEmail); | ||
if (accountAddress) { | ||
this.accountAddress = accountAddress; | ||
useFeedbackStore().unsetLoading(`${this.getName()}.login`); | ||
return this.accountAddress as addressString; | ||
} | ||
|
||
|
||
const provider = await this.web3Provider(); | ||
this.accountAddress = await provider.getSigner().getAddress(); | ||
|
||
useFeedbackStore().unsetLoading(`${this.getName()}.login`); | ||
|
||
|
||
const credentials = await metakeep?.getWallet(); | ||
metakeepCache.addCredentials(this.accountEmail, credentials.wallet); | ||
|
||
return this.accountAddress as addressString; | ||
} | ||
|
||
async logout(): Promise<void> { | ||
this.trace('logout'); | ||
metakeepCache.setLogged(''); | ||
return Promise.resolve(); | ||
} | ||
|
||
async isConnectedTo(chainId: string): Promise<boolean> { | ||
this.trace('isConnectedTo', chainId); | ||
return true; | ||
} | ||
|
||
async web3Provider(): Promise<ethers.providers.Web3Provider> { | ||
this.trace('web3Provider'); | ||
await this.assertMetakeepSDKReady(); | ||
if (web3Provider) { | ||
return web3Provider; | ||
} else { | ||
console.error('web3Provider not ready'); | ||
throw new AntelopeError('antelope.evm.error_metakeep_web3_provider'); | ||
} | ||
} | ||
|
||
// returns the associated account address according to the label | ||
getAccountAddress(): addressString { | ||
return this.accountAddress as addressString; | ||
} | ||
|
||
handleCatchError(error: Error): AntelopeError { | ||
this.trace('handleCatchError', error.message); | ||
if ( | ||
(error as unknown as {status:string}).status === 'USER_REQUEST_DENIED' | ||
) { | ||
return new AntelopeError('antelope.evm.error_transaction_canceled'); | ||
} else { | ||
return new AntelopeError('antelope.evm.error_send_transaction', { error }); | ||
} | ||
} | ||
} |
This file contains 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.
is it not possible to check chainID with metakeep?
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.
by default, they support any EOS, ETH, or SOL-compatible blockchains.
This is a good topic for a KT I think.