Skip to content
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

Bring integration #3720

Open
wants to merge 181 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
944d2e2
fix: EOL bug
kalfada Sep 3, 2024
6bc3d45
feat: add cashback tab and page
kalfada Sep 11, 2024
12a9f9a
Merge branch 'develop' into integration
kalfada Sep 11, 2024
0b9e6f9
Merge pull request #4 from Bring-Web3-LTD/integration
kalfada Sep 11, 2024
5a2feaa
bundle and inject code for bring
yushih Sep 12, 2024
0a29c0f
fix: change cashback page to use function component
kalfada Sep 18, 2024
05488ba
fix: add not added files
kalfada Sep 18, 2024
5812794
Merge branch 'develop' into feat/bundle-and-inject-bring
yushih Sep 23, 2024
0207012
move Bring code into a content script
yushih Sep 23, 2024
754b8fd
add example for calling chrome.runtime.onMessage
yushih Sep 23, 2024
d4493f2
fix webpack
yushih Sep 23, 2024
e988a0e
Bring content script gets addresses
yushih Sep 23, 2024
c29e5c0
get theme
yushih Sep 24, 2024
5cda0cf
bug fix
yushih Sep 24, 2024
6b511a0
Binds a wallet to bring
yushih Sep 24, 2024
370d8cd
Revert "Binds a wallet to bring"
yushih Sep 24, 2024
2c6d422
fix get address for new wallet
yushih Sep 24, 2024
510449c
add events for active wallet
yushih Sep 25, 2024
64012ff
pop up Yoroi extension if no wallet
yushih Sep 25, 2024
b83688c
get address function returns address in Bech32
yushih Sep 30, 2024
c9e910c
fix: iframeUrl source
kalfada Oct 6, 2024
d05d8de
fix: iframeUrl source
kalfada Oct 7, 2024
93baceb
fix: remove unused config
kalfada Oct 7, 2024
4530486
fix: change event names
kalfada Oct 8, 2024
3395dcc
only fire active-wallet-open event when active wallet changes
yushih Oct 8, 2024
5928827
feat: bringweb3 popup
kalfada Oct 10, 2024
d64b181
fix: change env to sandbox
kalfada Oct 10, 2024
b93140f
Merge branch 'portal-and-popup' into cashback-integration
kalfada Oct 16, 2024
60cc393
Merge pull request #5 from Bring-Web3-LTD/cashback-integration
kalfada Oct 16, 2024
6ddab67
fix: configure sandbox and prod for bringweb3
kalfada Oct 16, 2024
b817054
remove .d.ts files
yushih Oct 30, 2024
3c0a4df
Merge branch 'bring/portal-and-popup' into bring-integration
yushih Oct 30, 2024
3305974
mv3 Bring integration support
yushih Oct 30, 2024
fe7fd04
fire active-wallet-open event after the first wallet is created
yushih Oct 14, 2024
64f4e53
flow fix
yushih Oct 30, 2024
9e7ea12
revert translation file changes
yushih Oct 30, 2024
5e80da9
add frame-src and connect-src for Bring
yushih Oct 30, 2024
40bf7c7
fix flow
yushih Oct 30, 2024
ac4581e
hardware wallet cashback support
yushih Oct 30, 2024
cb46cbe
handling cashback submission errors
yushih Oct 31, 2024
f50fa93
indent code
yushih Oct 31, 2024
25265e0
i18n
yushih Oct 31, 2024
f63a452
style: change cashback icon
kalfada Oct 31, 2024
6d0cf10
Merge pull request #3722 from Bring-Web3-LTD/bring-integration
yushih Oct 31, 2024
9a6b807
stylize error text
yushih Oct 31, 2024
3f6f276
use wildcard in frame-src and connect-src to allow both Bring product…
yushih Oct 31, 2024
e538d97
sign message hash
yushih Oct 31, 2024
d0b63da
fix for Ledger wallet
yushih Nov 4, 2024
c3c3864
fix for Ledger wallet
yushih Nov 4, 2024
7297cee
Merge branch 'develop' into bring-integration
yushih Nov 5, 2024
85075e7
fix code format
yushih Nov 5, 2024
40c1f3d
fix: update bringweb3 package
kalfada Nov 5, 2024
8b71046
Merge pull request #3727 from Bring-Web3-LTD/bring-integration
yushih Nov 5, 2024
5030e42
fix Ledger error message handling
yushih Nov 6, 2024
b451b6a
clear error message after closing cashback claiming dialog
yushih Nov 6, 2024
610a19f
get rid of double scroll
yushih Nov 14, 2024
ba0bf51
restructure code
yushih Nov 19, 2024
995fa53
use chrome.storage instead of window.localStorage to record selected …
yushih Nov 20, 2024
173faaa
save cashback wallet
yushih Nov 20, 2024
61b31c4
add APIs to list wallets and set cashback wallet
yushih Nov 20, 2024
68163c5
implement Ledger sign message UI as design
yushih Nov 20, 2024
158a00c
trigger cashback wallet change event when cashback wallet changes
yushih Nov 21, 2024
9c4807e
cashback page warning dialog when current wallet is not cashback wallet
yushih Nov 21, 2024
61c3e21
disable cashback icon on side bar of Trezor wallets
yushih Nov 22, 2024
b30cb54
handle deleting cashback wallet
yushih Nov 22, 2024
54816d6
cashback wallet selection popup dialog
yushih Nov 24, 2024
16c1ee1
bug fix
yushih Nov 25, 2024
2ce1cc4
move some message definitions
yushih Nov 25, 2024
dccc00d
disclaimer for cashback
yushih Nov 25, 2024
775ba10
fix typo
yushih Nov 25, 2024
7fd63d3
add setting option for bring cashback
SorinC6 Nov 27, 2024
d574c22
Merge pull request #3758 from Emurgo/sorin/YOEXT-1534/cashback-settin…
yushih Nov 27, 2024
fab3286
refactor to lift public key derivation
yushih Nov 27, 2024
9de3b74
add clone wallet function
yushih Nov 27, 2024
9447c45
remove unused parameter
yushih Nov 28, 2024
60680ea
support cloning hardware wallet
yushih Nov 28, 2024
480728c
refactor to lift public key derivation
yushih Nov 28, 2024
9b0e95e
feat: support switch wallet
kalfada Nov 28, 2024
a913844
Merge pull request #3766 from Bring-Web3-LTD/bring-integration
yushih Nov 29, 2024
87d6de9
type annotation
yushih Nov 29, 2024
4a537a6
restore format and remove dev-only frame-src
yushih Nov 29, 2024
5088dc4
do not pick default cashback wallet whne there are >1 wallets
yushih Nov 29, 2024
3f2fe8a
finish cashback wallet setting
yushih Nov 29, 2024
9a6102f
Merge remote-tracking branch 'origin/develop' into bring-integration
yushih Nov 29, 2024
f8645a5
lint
yushih Nov 29, 2024
fcf3feb
Merge remote-tracking branch 'origin/develop' into bring-integration
vsubhuman Nov 29, 2024
3e76306
Version bump: 5.4.501 (nightly)
vsubhuman Nov 29, 2024
b7d2b72
lint
yushih Nov 29, 2024
ab7200a
Merge remote-tracking branch 'origin/develop' into bring-integration
vsubhuman Dec 1, 2024
549e0d0
wallet list rendering fix
vsubhuman Dec 2, 2024
abdb397
filter mainnet wallets
vsubhuman Dec 2, 2024
239775d
bring two configs
vsubhuman Dec 3, 2024
f73d4dc
bring two configs
vsubhuman Dec 3, 2024
e5db4be
fix: update bring npm package
kalfada Dec 3, 2024
0c2890c
Merge pull request #3769 from Bring-Web3-LTD/bring-integration
yushih Dec 3, 2024
a2b7643
remove unused
yushih Dec 3, 2024
becf77b
new not current wallet warning dialog
yushih Dec 3, 2024
03a1e15
fix double scroll again
yushih Dec 3, 2024
86c3680
Merge remote-tracking branch 'origin/bring-integration' into ruslan/b…
vsubhuman Dec 5, 2024
9df9ef5
moved bring config from environment
vsubhuman Dec 5, 2024
1509f60
pick config from flag
vsubhuman Dec 5, 2024
a7aa631
bring sandbox selector
vsubhuman Dec 6, 2024
238f7db
Merge remote-tracking branch 'origin/develop' into bring-integration
vsubhuman Dec 6, 2024
32f6353
package-lock update
vsubhuman Dec 6, 2024
1948e29
Merge remote-tracking branch 'origin/bring-integration' into ruslan/b…
vsubhuman Dec 6, 2024
821050a
unset local storage value on reset
vsubhuman Dec 6, 2024
6fae2de
Merge pull request #3776 from Emurgo/ruslan/bring-two-configs
yushih Dec 6, 2024
ffbb251
Version bump: 5.4.511 (nightly)
vsubhuman Dec 6, 2024
9594388
Merge branch 'develop' into wallet-switch
yushih Dec 9, 2024
5f59144
fix: bring pass message after signing
kalfada Dec 10, 2024
db2e506
Merge pull request #3779 from Bring-Web3-LTD/bring-integration
yushih Dec 10, 2024
d9dd2c6
implement wallet switch dialog UI
yushih Dec 10, 2024
e0bdd5e
change not current cashback wallet warning dialog text
yushih Dec 10, 2024
b211d93
fix messages
yushih Dec 10, 2024
5e60e55
fix
yushih Dec 10, 2024
70fbc5d
fix
yushih Dec 10, 2024
a7bde28
fix flow
yushih Dec 10, 2024
fd272af
Merge remote-tracking branch 'origin/fix/connector-foreign-withrawal'…
vsubhuman Dec 11, 2024
9feddcb
Merge remote-tracking branch 'origin/fix/connector-foreign-withrawal'…
vsubhuman Dec 11, 2024
d89b9fd
Version bump: 5.4.512 (nightly)
vsubhuman Dec 11, 2024
b51e9ca
Merge remote-tracking branch 'origin/develop' into bring-integration
vsubhuman Dec 11, 2024
861ad38
bug fix - should return base address to bring
yushih Dec 11, 2024
873e59b
bug fix
yushih Dec 11, 2024
6c961d0
implement network switch
yushih Dec 11, 2024
fcd9898
fix: update bring npm package
kalfada Dec 12, 2024
d938edb
Merge pull request #3783 from Bring-Web3-LTD/bring-integration
yushih Dec 12, 2024
d5c391c
refactor - move some methods
yushih Dec 12, 2024
e593421
remove the network selection step
yushih Dec 12, 2024
d729c05
sync cloned wallets
yushih Dec 12, 2024
3631030
use last sync info to determine the blocking syncing UI
yushih Dec 12, 2024
d329daa
handle remove
yushih Dec 12, 2024
53c6500
revamp wallet list order
yushih Dec 14, 2024
fd9a25e
Merge remote-tracking branch 'origin/develop' into bring-integration
vsubhuman Dec 14, 2024
80642ed
merge fix
vsubhuman Dec 14, 2024
99e8b78
Version bump: 5.4.531 (nightly)
vsubhuman Dec 14, 2024
6b51834
Merge remote-tracking branch 'origin/develop' into bring-integration
vsubhuman Dec 19, 2024
4c66bc2
Version bump: 5.4.532 (nightly)
vsubhuman Dec 19, 2024
f6d717d
store public key of last selected/active wallet instead of id
yushih Dec 18, 2024
210bc5c
migrate old selected wallet and wallet order
yushih Dec 19, 2024
5ecb941
lint
yushih Dec 19, 2024
d632468
Merge remote-tracking branch 'origin/develop' into wallet-switch
yushih Dec 19, 2024
a63dfee
add i18n message
yushih Dec 19, 2024
7f04e80
i18n
yushih Dec 20, 2024
8c2863f
add badge for testnets
yushih Dec 20, 2024
e3eb147
updated transferTypeSelect page
Nebyt Dec 17, 2024
a1894f5
cleaning
Nebyt Dec 17, 2024
aa57bea
updated transfer card
Nebyt Dec 18, 2024
7dffb7c
updated transfer paper wallet workflow to dark theme
Nebyt Dec 19, 2024
6cd7a86
lint fixes
Nebyt Dec 19, 2024
399c4b1
applied dark theme to the complexity cards
Nebyt Dec 20, 2024
f50284f
fixed remarks
Nebyt Dec 20, 2024
0521934
Bump chromedriver from 131.0.3 to 131.0.4 in /packages/e2e-tests
dependabot[bot] Dec 20, 2024
d9a4f5f
fix
yushih Dec 23, 2024
c1c1499
fix set cashback wallet message getting lost
yushih Dec 23, 2024
99e8641
fix: update bring npm package
kalfada Jan 5, 2025
eb3c7a1
Merge pull request #3799 from Bring-Web3-LTD/bring-integration
yushih Jan 6, 2025
33b5a44
Merge branch 'develop' into bring-integration
yushih Jan 8, 2025
a6f63b6
Merge branch 'develop' into wallet-switch
yushih Jan 8, 2025
2b95838
seperate setting active wallet from routing
yushih Jan 8, 2025
d72e004
restructure some code
yushih Jan 8, 2025
8fe0f0e
remove unused stuff
yushih Jan 8, 2025
eaf82ad
fix uri handling
yushih Jan 9, 2025
0700e63
Merge branch 'fix/url-handling' into bring-integration
yushih Jan 9, 2025
0d3891f
remove unused flag
yushih Jan 9, 2025
2f5c0bb
support opening the cashback page from URL
yushih Jan 9, 2025
4014930
Merge branch 'develop' into wallet-switch
Nebyt Jan 9, 2025
d09dbf0
add buttons on cashback wallet select popup
yushih Jan 10, 2025
dcea885
bug fix
yushih Jan 10, 2025
7099741
Merge branch 'wallet-switch' into fix/url-handling
yushih Jan 10, 2025
e4c00f7
fix unmatched route
yushih Jan 14, 2025
842fc8c
fix: should always go to loading page initially
yushih Jan 14, 2025
aa68a18
Merge branch 'fix/url-handling' into bring-integration
yushih Jan 14, 2025
d0e3c16
remove the word Bring from UI
yushih Jan 15, 2025
c9c26fa
fix: update bring npm package
kalfada Jan 15, 2025
17dc81d
Merge pull request #3807 from Bring-Web3-LTD/bring-integration
yushih Jan 15, 2025
f1f8d93
add space
yushih Jan 15, 2025
13af7c8
fix: upgrade bring NPM package
kalfada Jan 23, 2025
20e174c
Merge pull request #3819 from Bring-Web3-LTD/bring-integration
yushih Jan 23, 2025
c99aa5e
Merge remote-tracking branch 'origin/develop' into bring-integration
vsubhuman Jan 24, 2025
eba94b1
post-merge fixes
vsubhuman Jan 24, 2025
4bd2eb9
Version bump: 5.4.601
vsubhuman Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions packages/yoroi-extension/app/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ const WalletSettingsPagePromise = () => import('./containers/settings/categories
const WalletSettingsPage = React.lazy(WalletSettingsPagePromise);
const ExternalStorageSettingsPagePromise = () => import('./containers/settings/categories/ExternalStorageSettingsPage');
const ExternalStorageSettingsPage = React.lazy(ExternalStorageSettingsPagePromise);
const OAuthDropboxPagePromise = () => import('./containers/settings/categories/OAuthDropboxPage');
const OAuthDropboxPage = React.lazy(OAuthDropboxPagePromise);
const TermsOfUseSettingsPagePromise = () => import('./containers/settings/categories/TermsOfUseSettingsPage');
const TermsOfUseSettingsPage = React.lazy(TermsOfUseSettingsPagePromise);
const SupportSettingsPagePromise = () => import('./containers/settings/categories/SupportSettingsPage');
Expand All @@ -87,9 +85,6 @@ const AnalyticsSettingsPage = React.lazy(AnalyticsSettingsPagePromise);
const NightlyPagePromise = () => import('./containers/profile/NightlyPage');
const NightlyPage = React.lazy(NightlyPagePromise);

const MyWalletsPagePromise = () => import('./containers/wallet/MyWalletsPage');
const MyWalletsPage = React.lazy(MyWalletsPagePromise);

const WalletSummaryPagePromise = () => import('./containers/wallet/WalletSummaryPage');
const WalletSummaryPage = React.lazy(WalletSummaryPagePromise);

Expand Down Expand Up @@ -132,6 +127,9 @@ const TokensPageRevamp = React.lazy(TokensPageRevampPromise);
const TokensDetailPageRevampPromise = () => import('./containers/wallet/TokenDetailPageRevamp');
const TokensDetailPageRevamp = React.lazy(TokensDetailPageRevampPromise);

const CashbackPagePromise = () => import('./containers/cashback/CashbackPage');
const CashbackPage = React.lazy(CashbackPagePromise)

const NFTsPageRevampPromise = () => import('./containers/wallet/NFTsPageRevamp');
const NFTsPageRevamp = React.lazy(NFTsPageRevampPromise);

Expand All @@ -157,11 +155,9 @@ export const LazyLoadPromises: Array<() => any> = [
GeneralSettingsPagePromise,
WalletSettingsPagePromise,
ExternalStorageSettingsPagePromise,
OAuthDropboxPagePromise,
TermsOfUseSettingsPagePromise,
SupportSettingsPagePromise,
NightlyPagePromise,
MyWalletsPagePromise,
WalletSummaryPagePromise,
WalletSendPagePromise,
WalletAssetsPagePromise,
Expand Down Expand Up @@ -216,10 +212,13 @@ export const Routes = (stores: StoresMap): Node => {
path={ROUTES.PROFILE.OPT_FOR_ANALYTICS}
component={props => <OptForAnalyticsPage {...props} stores={stores} />}
/>
<Route exact path={ROUTES.MY_WALLETS} component={props => <MyWalletsPage {...props} stores={stores} />} />
<Route exact path={ROUTES.STAKING} component={props => <StakingPage {...props} stores={stores} />} />
<Route path={ROUTES.ASSETS.ROOT} component={props => wrapAssets({ ...props, stores }, AssetsSubpages(stores))} />
<Route path={ROUTES.NFTS.ROOT} component={props => wrapNFTs({ ...props, stores }, NFTsSubPages(stores))} />
<Route
path={ROUTES.CASHBACK.ROOT}
component={props => <CashbackPage {...props} stores={stores} />}
/>
<Route exact path={ROUTES.WALLETS.ADD} component={props => <AddWalletPage {...props} stores={stores} />} />
<Route
exact
Expand All @@ -241,11 +240,6 @@ export const Routes = (stores: StoresMap): Node => {
<Route path={ROUTES.SWAP.ROOT} component={props => wrapSwap({ ...props, stores }, SwapSubpages(stores))} />
<Route path={ROUTES.TRANSFER.ROOT} component={props => <Transfer {...props} stores={stores} />} />
<Route exact path={ROUTES.SEND_FROM_URI.ROOT} component={props => <URILandingPage {...props} stores={stores} />} />
<Route
exact
path={ROUTES.OAUTH_FROM_EXTERNAL.DROPBOX}
component={props => <OAuthDropboxPage {...props} stores={stores} />}
/>
<Route exact path={ROUTES.SWITCH} component={props => <WalletSwitch {...props} stores={stores} />} />
<Route exact path={ROUTES.REVAMP.CATALYST_VOTING} component={props => <VotingPage {...props} stores={stores} />} />
<Route exact path={ROUTES.EXCHANGE_END} component={props => <ExchangeEndPage {...props} stores={stores} />} />
Expand All @@ -259,8 +253,7 @@ export const Routes = (stores: StoresMap): Node => {
path={ROUTES.PORTFOLIO.ROOT}
component={() => PortfolioSubpages(stores)}
/>

<Redirect to={ROUTES.MY_WALLETS} />
<Redirect to={ROUTES.WALLETS.ROOT} />
</Switch>
</Suspense>
</QueryClientProvider>
Expand Down
2 changes: 1 addition & 1 deletion packages/yoroi-extension/app/UI/context/IntlProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const IntlProvider = ({ children, intl }: { children: React.ReactNode; in
};

export const useIntl = () =>
React.useContext(IntlProviderContext) ?? console.warn('IntlProviderontext: needs to be wrapped in a IntlProvider');
React.useContext(IntlProviderContext) ?? console.warn('IntlProviderContext: needs to be wrapped in a IntlProvider');
101 changes: 97 additions & 4 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ import {
asGetSigningKey,
asHasLevels,
asHasUtxoChains,
asGetStakingKey,
} from './lib/storage/models/PublicDeriver/traits';
import { ConceptualWallet } from './lib/storage/models/ConceptualWallet/index';
import type { IHasLevels } from './lib/storage/models/ConceptualWallet/interfaces';
import { WalletTypeOption, type IHasLevels } from './lib/storage/models/ConceptualWallet/interfaces';
import type {
Address,
Addressing,
Expand Down Expand Up @@ -165,6 +166,7 @@ import TimeUtils from './lib/storage/bridge/timeUtils';
import type { IFetcher } from './lib/state-fetch/IFetcher.types';
import { Bip44DerivationLevels, CoinType } from '@emurgo/yoroi-lib';
import type { ProtocolParameters } from '@emurgo/yoroi-lib/dist/protocol-parameters/models';
import { encryptWithPassword } from '../../utils/passwordCipher';

// ADA specific Request / Response params

Expand Down Expand Up @@ -494,7 +496,6 @@ export type CreateHardwareWalletRequest = {|
publicKey: string,
...Addressing,
hwFeatures: HWFeatures,
checkAddressesInUse: FilterFunc,
network: $ReadOnly<NetworkRow>,
|};
export type CreateHardwareWalletResponse = {|
Expand Down Expand Up @@ -1808,6 +1809,86 @@ export default class AdaApi {
}
}

async cloneWallet(
db: lf$Database,
publicDeriver: PublicDeriver<>,
network: $ReadOnly<NetworkRow>,
): Promise<PublicDeriver<>> {
const withPublicKey = asGetPublicKey(publicDeriver);
if (!withPublicKey) {
throw new Error('unable to get public key');
}
const publicKey = await withPublicKey.getPublicKey();
const accountPublicKey = RustModule.WalletV4.Bip32PublicKey.from_hex(publicKey.Hash);

const conceptualWallet = publicDeriver.getParent();
const walletName = (await conceptualWallet.getFullConceptualWalletInfo()).Name;

let wallet;
if (conceptualWallet.getWalletType() === WalletTypeOption.HARDWARE_WALLET) {
const withStakingKey = asGetStakingKey(publicDeriver);
if (!withStakingKey) {
throw new Error('unable to get staking key');
}
const stakingKey = await withStakingKey.getStakingKey();

const hwMeta = conceptualWallet.getHwWalletMeta();
if (!hwMeta) {
throw new Error('unexpectedly missing hardware metadata');
}

wallet = await createHardwareCip1852Wallet({
db,
accountPublicKey,
accountIndex: stakingKey.addressing.path[2],
walletName,
accountName: '',
hwWalletMetaInsert: {
Vendor: hwMeta.Vendor,
Model: hwMeta.Model,
DeviceId: hwMeta.DeviceId,
},
network,
});
} else {
const withSigningKey = asGetSigningKey(publicDeriver);
if (!withSigningKey) {
throw new Error('unable to get signing key');
}
const signingKey = await withSigningKey.getSigningKey();
const encryptedRoot = signingKey.row.Hash;

const accountIndex = signingKey.path[3].Index;
if (accountIndex === null) {
throw new Error('missing account index');
}

wallet = await createStandardCip1852Wallet({
db,
encryptedRoot,
accountPublicKey,
accountIndex,
walletName,
accountName: '', // set account name empty now
network,
});
}

const cip1852Wallet = await Cip1852Wallet.createCip1852Wallet(
db,
wallet.cip1852WrapperRow,
);

if (wallet.publicDeriver.length !== 1) {
throw new Error(`${nameof(AdaApi)}::${nameof(this.cloneWallet)} should only do 1 HW derivation at a time`);
}
const pubDeriverResult = wallet.publicDeriver[0].publicDeriverResult;
return await PublicDeriver.createPublicDeriver(
pubDeriverResult,
cip1852Wallet,
);
}

/**
* Creates wallet and saves result to DB
*/
Expand All @@ -1823,11 +1904,21 @@ export default class AdaApi {
try {
// Note: we only restore for 0th account
const rootPk = generateWalletRootKey(recoveryPhrase);
const encryptedRoot = encryptWithPassword(
walletPassword,
rootPk.as_bytes(),
);
const accountPublicKey = rootPk
.derive(WalletTypePurpose.CIP1852)
.derive(CoinTypes.CARDANO)
.derive(request.accountIndex)
.to_public();

const newPubDerivers = [];
const wallet = await createStandardCip1852Wallet({
db: request.db,
rootPk,
password: walletPassword,
encryptedRoot,
accountPublicKey,
accountIndex: request.accountIndex,
walletName,
accountName: '', // set account name empty now
Expand Down Expand Up @@ -2694,11 +2785,13 @@ export async function encodeHardwareWalletSignResult(
signatureHex: string,
payloadHex: string,
signingPublicKeyHex: string,
payloadHashed: boolean = false,
): Promise<{| signature: string, key: string |}> {
const coseSign1 = await buildCoseSign1FromSignature (
hexToBytes(addressHex),
hexToBytes(signatureHex),
hexToBytes(payloadHex),
payloadHashed,
);

const key = makeCip8Key(hexToBytes(signingPublicKeyHex));
Expand Down
12 changes: 12 additions & 0 deletions packages/yoroi-extension/app/api/ada/lib/cardanoCrypto/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const buildCoseSign1FromSignature = async (
address: Buffer,
signature: Buffer,
payload: Buffer,
payloadHashed: boolean = false,
): Promise<RustModule.MessageSigning.COSESign1> => {
const protectedHeader = RustModule.MessageSigning.HeaderMap.new();
protectedHeader.set_algorithm_id(
Expand All @@ -191,8 +192,19 @@ export const buildCoseSign1FromSignature = async (
);
const protectedSerialized = RustModule.MessageSigning.ProtectedHeaderMap.new(protectedHeader);
const unprotected = RustModule.MessageSigning.HeaderMap.new();
if (payloadHashed) {
unprotected.set_header(
RustModule.MessageSigning.Label.new_text('hashed'),
RustModule.MessageSigning.CBORValue.new_special(
RustModule.MessageSigning.CBORSpecial.new_bool(true)
),
);
}
const headers = RustModule.MessageSigning.Headers.new(protectedSerialized, unprotected);
const builder = RustModule.MessageSigning.COSESign1Builder.new(headers, payload, false);
if (payloadHashed) {
builder.hash_payload();
}
return builder.build(signature);
}

Expand Down
45 changes: 43 additions & 2 deletions packages/yoroi-extension/app/api/ada/lib/storage/adaMigration.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { migrateFromStorageV1 } from './bridge/walletBuilder/byron';
import { RustModule } from '../cardanoCrypto/rustLoader';
import { removeAllTransactions } from './bridge/updateTransactions';
import { removePublicDeriver } from './bridge/walletBuilder/remove';
import { asGetAllUtxos, asHasLevels, } from './models/PublicDeriver/traits';
import { asGetAllUtxos, asHasLevels, asGetPublicKey, } from './models/PublicDeriver/traits';
import { ConceptualWallet, isLedgerNanoWallet, } from './models/ConceptualWallet/index';
import { loadWalletsFromStorage } from './models/load';
import environment from '../../../../environment';
Expand All @@ -32,6 +32,7 @@ import { getAllSchemaTables, raii, } from './database/utils';
import type { BlockRow } from './database/primitives/tables';
import { GetBlock } from './database/primitives/api/read';
import { ModifyUtxoAtSafePoint } from './database/utxo/api/write';
import type { PublicDeriver } from './models/PublicDeriver/index';

export async function migrateToLatest(
localStorageApi: LocalStorageApi,
Expand Down Expand Up @@ -98,6 +99,7 @@ export async function migrateToLatest(
['<3.8.0', () => cardanoTxHistoryReset(persistentDb)],
['<4.18', () => populateNewUtxodata(persistentDb)],
['<5.4', () => unsetLegacyThemeFlags(localStorageApi)],
['<5.5', () => migrateWalletOrderAndSelectedWalletForNetworkSwitch(persistentDb, localStorageApi)],
];

let appliedMigration = false;
Expand Down Expand Up @@ -421,4 +423,43 @@ async function unsetLegacyThemeFlags(localStorageApi: LocalStorageApi): Promise<
}
await localStorageApi.unsetLegacyThemeFlags();
return true;
}
}

async function migrateWalletOrderAndSelectedWalletForNetworkSwitch(
db: lf$Database,
localStorageApi: LocalStorageApi,
): Promise<boolean> {
const wallets = await loadWalletsFromStorage(db);

const oldWalletOrder = (await localStorageApi.getWalletsNavigation())?.cardano || [];
const publicKeyList = [];
for (const id of oldWalletOrder) {
const wallet = wallets.find(w => w.getPublicDeriverId() === id);
if (wallet) {
publicKeyList.push(await getPublicKey(wallet));
}
}
for (const wallet of wallets) {
if (!oldWalletOrder.includes(wallet.getPublicDeriverId())) {
publicKeyList.push(await getPublicKey(wallet));
}
}
await localStorageApi.saveWalletListOrder(publicKeyList);

const selectedWalletId = await localStorageApi.getSelectedWalletId();
const selectedWallet = wallets.find(
wallet => wallet.getPublicDeriverId() === selectedWalletId
);
if (selectedWallet) {
await localStorageApi.setSelectedWalletPublicKey(await getPublicKey(selectedWallet));
}
return true;
}

async function getPublicKey(publicDeriver: PublicDeriver<>): Promise<string> {
const withPubKey = asGetPublicKey(publicDeriver);
if (withPubKey == null) {
throw new Error('unexpected missing asGetPublicKey result');
}
return (await withPubKey.getPublicKey()).Hash;
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export async function createStandardBip44Wallet(request: {|
}
return {
deriverRequest: {
decryptPrivateDeriverPassword: request.password,
decryptPrivateDeriver: { preDerived: false, password: request.password },
publicDeriverMeta: {
name: request.accountName,
},
Expand Down
Loading
Loading