-
Notifications
You must be signed in to change notification settings - Fork 316
refactor: pending requests on popup page #6381
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c68130
refactor: pending requests on popup page
guanbinrui 158969e
refactor: add back maskwall sdk
guanbinrui 2afdc80
fix: mask wallet
guanbinrui 47297f1
fix: bugfix for popup
nuanyang233 3ef784f
chore: remove unused code
nuanyang233 12188ab
chore: set popup window be default value
nuanyang233 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 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
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
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
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
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
88 changes: 88 additions & 0 deletions
88
packages/mask/src/plugins/Wallet/services/maskwallet/index.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,88 @@ | ||
| import type { MaskBaseAPI } from '@masknet/web3-providers' | ||
| import { api } from '@dimensiondev/mask-wallet-core/proto' | ||
| import { OnDemandWorker } from '@masknet/shared-base' | ||
|
|
||
| type Request = InstanceType<typeof api.MWRequest> | ||
| type Response = InstanceType<typeof api.MWResponse> | ||
|
|
||
| const Worker = new OnDemandWorker(new URL('../../../../../web-workers/wallet.ts', import.meta.url), { | ||
| name: 'MaskWallet', | ||
| }) | ||
|
|
||
| enum ErrorCode { | ||
| KdfParamsInvalid = '-3001', | ||
| PasswordIncorrect = '-3002', | ||
| InvalidKeyIvLength = '-3003', | ||
| InvalidCiphertext = '-3004', | ||
| InvalidPrivateKey = '-3005', | ||
| InvalidPublicKey = '-3006', | ||
| InvalidMnemonic = '-3007', | ||
| InvalidSeed = '-3008', | ||
| InvalidDerivationPath = '-3009', | ||
| InvalidKeyStoreJSON = '-3010', | ||
| NotSupportedPublicKeyType = '-3011', | ||
| NotSupportedCurve = '-3012', | ||
| NotSupportedCipher = '-3013', | ||
| } | ||
|
|
||
| const ErrorMessage = { | ||
| [ErrorCode.KdfParamsInvalid]: 'Invalid kdf parameters.', | ||
| [ErrorCode.PasswordIncorrect]: 'Incorrect payment password.', | ||
| [ErrorCode.InvalidKeyIvLength]: 'Invalid key IV length.', | ||
| [ErrorCode.InvalidCiphertext]: 'Invalid cipher text.', | ||
| [ErrorCode.InvalidPrivateKey]: 'Invalid private key.', | ||
| [ErrorCode.InvalidPublicKey]: 'Invalid public key.', | ||
| [ErrorCode.InvalidMnemonic]: 'Invalid mnemonic words.', | ||
| [ErrorCode.InvalidSeed]: 'Invalid seed.', | ||
| [ErrorCode.InvalidDerivationPath]: 'Invalid derivation path.', | ||
| [ErrorCode.InvalidKeyStoreJSON]: 'Invalid keystore JSON.', | ||
| [ErrorCode.NotSupportedPublicKeyType]: 'Not supported public key type.', | ||
| [ErrorCode.NotSupportedCurve]: 'Not supported curve.', | ||
| [ErrorCode.NotSupportedCipher]: 'Not supported cipher.', | ||
| } | ||
|
|
||
| function send<I extends keyof Request, O extends keyof Response>(input: I, output: O) { | ||
| return (value: Request[I]) => { | ||
| return new Promise<Response[O]>((resolve, reject) => { | ||
| const req: MaskBaseAPI.Input = { id: Math.random(), data: { [input]: value } } | ||
| Worker.postMessage(req) | ||
| Worker.addEventListener('message', function f(message) { | ||
| if (message.data.id !== req.id) return | ||
|
|
||
| Worker.removeEventListener('message', f) | ||
| const data: MaskBaseAPI.Output = message.data | ||
| if (data.response.error) | ||
| return reject( | ||
| new Error(ErrorMessage[data.response.error.errorCode as ErrorCode] || 'Unknown Error'), | ||
| ) | ||
| resolve(data.response[output]) | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| export const Coin = api.Coin | ||
| export const StoredKeyType = api.StoredKeyType | ||
| export const StoredKeyImportType = api.StoredKeyImportType | ||
| export const StoredKeyExportType = api.StoredKeyExportType | ||
|
|
||
| export const loadStoredKey = send('param_load_stored_key', 'resp_load_stored_key') | ||
| export const createStoredKey = send('param_create_stored_key', 'resp_create_stored_key') | ||
| export const importPrivateKey = send('param_import_private_key', 'resp_import_private_key') | ||
| export const importMnemonic = send('param_import_mnemonic', 'resp_import_mnemonic') | ||
| export const importJSON = send('param_import_json', 'resp_import_json') | ||
| export const createAccountOfCoinAtPath = send( | ||
| 'param_create_account_of_coin_at_path', | ||
| 'resp_create_account_of_coin_at_path', | ||
| ) | ||
| export const exportPrivateKey = send('param_export_private_key', 'resp_export_private_key') | ||
| export const exportPrivateKeyOfPath = send('param_export_private_key_of_path', 'resp_export_private_key') | ||
| export const exportMnemonic = send('param_export_mnemonic', 'resp_export_mnemonic') | ||
| export const exportKeyStoreJSONOfAddress = send('param_export_key_store_json_of_address', 'resp_export_key_store_json') | ||
| export const exportKeyStoreJSONOfPath = send('param_export_key_store_json_of_path', 'resp_export_key_store_json') | ||
| export const exportUpdateKeyStorePassword = send('param_update_key_store_password', 'resp_update_key_store_password') | ||
| export const signTransaction = send('param_sign_transaction', 'resp_sign_transaction') | ||
| export const getLibVersion = send('param_get_version', 'resp_get_version') | ||
| export const validate = send('param_validation', 'resp_validate') | ||
| export const getSupportImportTypes = send('param_get_stored_key_import_type', 'resp_get_stored_key_import_type') | ||
| export const getSupportExportTypes = send('param_get_stored_key_export_type', 'resp_get_stored_key_export_type') |
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.
@nuanyang233 do not add
createScript! This allowseval