-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#351
- WalletProvider
refactor to move init logic into `contexts/…
…*.tsx` (#380) * quick save * completed create pin page completed verify pin (pending some text and styling) * quick save * complete pin creations UI implementation * update OceanInterface queue api * update unit test * fix outdated jellyfish mnemonic usage * derive account from wallet context when only needed * add wallet context mock for oceaninterface unit test * fix test, redux store auto append broadcast status on queue * install rn scrypt, implement native ScryptProvider * quick save * add custom max-w tailwind * add delay for pin input callback, allow render before complete (if any) promise * delete accident swp * fix merge, migrate to new custom button * done deferred prompt promise (UI thread resolve context init promise) * make standalone passcode prompt "page" rendered side by side with main AppNavigator * remove pininput in oceaninterface * quick save * completed encrypted wallet implementation (refactored) - ui implementation (page, pin input) - tx queue (in store), split from broadcast queue - retry mech + state management - clear wallet after consecutive failure (persistent failure counter, reset upon valid pin) * syntax and comment fixes * rename scrypt native module file, to build correctly * rename * added loading after collect pin, before signing complete * fix test snapshot * try manual select module (by platform.os) for bundling * require at runtime * temp disable web scryptsy * implement scryptsy for web locally, dep removed from jellyfish * move pin creation screens under wallet/ * fix pin input not auto focused (race condition) * bump dep jellyfish-wallet-encrypted 0.31 * fix outdated redux action usage, move files * test mobile build without sestate at onpinchange * manual select scryptsy (do not rely on extension) * mock scrypt * fix translate, replaceAll not working in RN * fix auth UI not get dismissed correctly when wipe wallet * minor syntax update, prevent less than 6 digit pin fire callback * rollback changes that I don't need for this refactoring * revert root navigator * rename passcode_attempt.ts * refactor WalletManagementContext.tsx to WalletPersistenceContext.tsx * added deprecated notice for wallet state * moved wallet init logic to WalletContext.tsx * fixed playground with new wallet context setup * updated package-lock.json * update to support scrypt Co-authored-by: ivan <[email protected]>
- Loading branch information
Showing
24 changed files
with
347 additions
and
184 deletions.
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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './wallet/persistence' | ||
export * from './storage' | ||
export * from './logging' |
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,21 @@ | ||
import { JellyfishWallet, WalletHdNode, WalletHdNodeProvider } from '@defichain/jellyfish-wallet' | ||
import { WhaleApiClient } from '@defichain/whale-api-client' | ||
import { WhaleWalletAccount, WhaleWalletAccountProvider } from '@defichain/whale-api-wallet' | ||
import { EnvironmentNetwork } from '../../environment' | ||
import { getJellyfishNetwork } from './network' | ||
|
||
/** | ||
* Whale JellyfishWallet connected to Whale APIs via the Ocean Infrastructure | ||
*/ | ||
export type WhaleWallet = JellyfishWallet<WhaleWalletAccount, WalletHdNode> | ||
|
||
export function initWhaleWallet (provider: WalletHdNodeProvider<WalletHdNode>, network: EnvironmentNetwork, client: WhaleApiClient): WhaleWallet { | ||
const accountProvider = new WhaleWalletAccountProvider(client, getJellyfishNetwork(network)) | ||
return new JellyfishWallet(provider, accountProvider) | ||
} | ||
|
||
export * from './provider/mnemonic_encrypted' | ||
export * from './provider/mnemonic_unprotected' | ||
export * from './network' | ||
export * from './passcode_attempt' | ||
export * from './persistence' |
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,20 @@ | ||
import { StorageAPI } from '../storage' | ||
|
||
const KEY = 'PASSCODE_ATTEMPT.count' | ||
|
||
async function get (): Promise<number> { | ||
const str = await StorageAPI.getItem(KEY) | ||
return str === undefined ? 0 : Number(str) | ||
} | ||
|
||
async function set (count: number): Promise<void> { | ||
await StorageAPI.setItem(KEY, `${count}`) | ||
} | ||
|
||
/** | ||
* Failed passcode input counter persistence layer | ||
*/ | ||
export const PasscodeAttemptCounter = { | ||
set, | ||
get | ||
} |
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 was deleted.
Oops, something went wrong.
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,51 @@ | ||
import { | ||
EncryptedHdNodeProvider, | ||
EncryptedProviderData, | ||
PrivateKeyEncryption, | ||
PromptPassphrase, | ||
Scrypt | ||
} from '@defichain/jellyfish-wallet-encrypted' | ||
import * as Random from 'expo-random' | ||
import { EnvironmentNetwork } from '../../../environment' | ||
import { getBip32Option } from '../network' | ||
import { WalletPersistenceData, WalletType } from '../persistence' | ||
|
||
const encryption = new PrivateKeyEncryption(new Scrypt(), numOfBytes => { | ||
const bytes = Random.getRandomBytes(numOfBytes) | ||
return Buffer.from(bytes) | ||
}) | ||
|
||
function initProvider ( | ||
data: WalletPersistenceData<EncryptedProviderData>, | ||
network: EnvironmentNetwork, | ||
promptPassphrase: PromptPassphrase | ||
): EncryptedHdNodeProvider { | ||
if (data.type !== WalletType.MNEMONIC_ENCRYPTED || data.version !== 'v1') { | ||
throw new Error('Unexpected WalletPersistenceData') | ||
} | ||
|
||
const bip32Options = getBip32Option(network) | ||
return EncryptedHdNodeProvider.init(data.raw, bip32Options, encryption, promptPassphrase) | ||
} | ||
|
||
async function toData (mnemonic: string[], network: EnvironmentNetwork, passphrase: string): Promise<WalletPersistenceData<EncryptedProviderData>> { | ||
const options = getBip32Option(network) | ||
const data = await EncryptedHdNodeProvider.wordsToEncryptedData(mnemonic, options, encryption, passphrase) | ||
|
||
return { | ||
version: 'v1', | ||
type: WalletType.MNEMONIC_ENCRYPTED, | ||
raw: data | ||
} | ||
} | ||
|
||
export const MnemonicEncrypted = { | ||
initProvider, | ||
toData, | ||
/** | ||
* Convenience Abandon23 Art on Playground Network Data | ||
*/ | ||
Abandon23Playground: toData([ | ||
'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'abandon', 'art' | ||
], EnvironmentNetwork.LocalPlayground, '123456') | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.