Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ describe('validate evm send', () => {
logoSmall: 'logoSmall',
logoUri: 'logoUri',
collectionName: 'collectionName',
description: 'description'
description: 'description',
chainId: 1
}

beforeEach(() => {
Expand Down Expand Up @@ -145,7 +146,8 @@ describe('validate evm send', () => {
logoSmall: 'logoSmall',
logoUri: 'logoUri',
collectionName: 'collectionName',
description: 'description'
description: 'description',
chainId: 1
}

beforeEach(() => {
Expand Down
3 changes: 0 additions & 3 deletions packages/core-mobile/app/new/features/ledger/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export const SOLANA_DERIVATION_PATH = "44'/501'/0'/0'/0"
// Solana derivation path prefix for generating indexed paths
export const SOLANA_DERIVATION_PATH_PREFIX = "44'/501'/0'/0'"

// Deprecated Avalanche public key path prefix
export const DEPRECATED_AVALANCHE_DERIVATION_PATH_PREFIX = "m/44'/9000'/0'"

/**
* Generate a Solana derivation path for a specific account index
* @param accountIndex - The account index to generate the path for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ export function useLedgerWallet(): UseLedgerWalletReturn {
addressAVM: addresses.AVM,
addressPVM: addresses.PVM,
addressSVM: addresses.SVM,
addressCoreEth: addresses.CoreEth
addressCoreEth: addresses.CoreEth,
xpAddresses: [] // TODO: add xp addresses
}

dispatch(setAccount(newAccount))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const CollectibleFetchAndRender = memo(
const tokenId = token?.collectableTokenId?.toString() || ''

const initialCollectible = useMemo(() => {
const chainId = Number(tx.chainId)

return {
localId,
type: token?.type as TokenType.ERC721 | TokenType.ERC1155,
Expand All @@ -36,14 +38,15 @@ export const CollectibleFetchAndRender = memo(
status: NftLocalStatus.Unprocessed,
balance: BigInt(0),
balanceDisplayValue: '',
networkChainId: Number(tx.chainId),
networkChainId: chainId,
description: '',
logoUri: '',
logoSmall: '',
name: '',
symbol: '',
tokenUri: '',
collectionName: ''
collectionName: '',
chainId
}
}, [localId, token?.type, tx.to, tx.chainId, tokenId])

Expand All @@ -69,6 +72,7 @@ export const CollectibleFetchAndRender = memo(
processedMetadata.animation_url ||
processedMetadata.external_url
)
const chainId = Number(tx.chainId)

setCollectible({
...result,
Expand All @@ -86,7 +90,8 @@ export const CollectibleFetchAndRender = memo(
logoUri: '',
logoSmall: '',
collectionName: '',
networkChainId: Number(tx.chainId),
networkChainId: chainId,
chainId,
symbol: ''
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as cs from '@cubist-labs/cubesigner-sdk'
import { strip0x } from '@avalabs/core-utils-sdk'
import { AddressPublicKey, Curve } from 'utils/publicKeys'
import { DEPRECATED_AVALANCHE_DERIVATION_PATH_PREFIX } from 'features/ledger/consts'
import {
AddressPublicKey,
Curve,
DEPRECATED_AVALANCHE_DERIVATION_PATH_PREFIX
} from 'utils/publicKeys'

export const transformKeyInfosToPubKeys = (
keyInfos: cs.KeyInfo[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class AccountsService {
addressAVM: addresses[NetworkVMType.AVM],
addressPVM: addresses[NetworkVMType.PVM],
addressCoreEth: addresses[NetworkVMType.CoreEth],
addressSVM: addresses[NetworkVMType.SVM]
addressSVM: addresses[NetworkVMType.SVM],
xpAddresses: [] // TODO: add xp addresses
}
}

Expand Down
76 changes: 45 additions & 31 deletions packages/core-mobile/app/services/earn/EarnService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, AccountCollection } from 'store/account/types'
import { Account } from 'store/account/types'
import { importPWithBalanceCheck } from 'services/earn/importP'
import Big from 'big.js'
import { FujiParams, MainnetParams } from 'utils/NetworkParams'
Expand Down Expand Up @@ -29,7 +29,6 @@ import AnalyticsService from 'services/analytics/AnalyticsService'
import { TokenUnit } from '@avalabs/core-utils-sdk'
import { Avalanche } from '@avalabs/core-wallets-sdk'
import { AvaxXP } from 'types/AvaxXP'
import AccountsService from 'services/account/AccountsService'
import {
getTransformedTransactions,
maxGetAtomicUTXOsRetries,
Expand Down Expand Up @@ -352,7 +351,7 @@ class EarnService {
}: {
walletId: string
walletType: WalletType
accounts: AccountCollection
accounts: Account[]
isTestnet: boolean
startTimestamp?: number
}): Promise<
Expand All @@ -365,44 +364,59 @@ class EarnService {
}[]
| undefined
> => {
const accountsArray = Object.values(accounts)

try {
const currentNetworkAddresses = accountsArray
.map(account => account.addressPVM)
.filter((address): address is string => address !== undefined)
const currentNetworkTransactions = await getTransformedTransactions(
currentNetworkAddresses,
isTestnet,
startTimestamp
const currentNetworkAddressesPromises = accounts.map(account =>
WalletService.getXPExternalAddresses({
account,
walletId,
walletType,
isTestnet
})
)
const currentNetworkAddresses = await Promise.all(
currentNetworkAddressesPromises
)
const currentNetworkAddressesArray = currentNetworkAddresses
.flat()
.map(address => address.address)
const currentNetworkTransactions =
currentNetworkAddressesArray.length > 0
? await getTransformedTransactions(
currentNetworkAddressesArray,
isTestnet,
startTimestamp
)
: []

const oppositeNetworkAddresses = (
await Promise.all(
accountsArray.map(account =>
AccountsService.getAddresses({
walletId,
walletType,
accountIndex: account.index,
isTestnet
})
)
)
).map(address => address.PVM)
const oppositeNetworkTransactions = await getTransformedTransactions(
oppositeNetworkAddresses,
!isTestnet,
startTimestamp
const oppositeNetworkAddressesPromises = accounts.map(account =>
WalletService.getXPExternalAddresses({
account,
walletId,
walletType,
isTestnet: !isTestnet
})
)
const oppositeNetworkAddresses = await Promise.all(
oppositeNetworkAddressesPromises
)
const oppositeNetworkAddressesArray = oppositeNetworkAddresses
.flat()
.map(address => address.address)
const oppositeNetworkTransactions =
oppositeNetworkAddressesArray.length > 0
? await getTransformedTransactions(
oppositeNetworkAddressesArray,
!isTestnet,
startTimestamp
)
: []

const now = new Date()
return currentNetworkTransactions
.concat(oppositeNetworkTransactions)
.flatMap(transaction => {
// find account that matches the transaction's index
const account = accountsArray.find(
acc => acc.index === transaction.index
)
const account = accounts.find(acc => acc.index === transaction.index)

// flat map will remove this
if (!account) return []
Expand Down
48 changes: 48 additions & 0 deletions packages/core-mobile/app/services/profile/ProfileService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { NetworkVMType } from '@avalabs/vm-module-types'
import Config from 'react-native-config'
import { NetworkAddresses } from 'services/wallet/types'
import fetchWithAppCheck from 'utils/httpClient'
import Logger from 'utils/Logger'

if (!Config.CORE_PROFILE_URL) {
Logger.warn(
'CORE_PROFILE_URL is missing. Profile service may not work properly.'
)
}

class ProfileService {
public async fetchXPAddresses({
xpubXP,
networkType,
isTestnet = false,
onlyWithActivity
}: {
xpubXP: string
networkType: NetworkVMType.AVM | NetworkVMType.PVM
isTestnet: boolean
onlyWithActivity: boolean
}): Promise<NetworkAddresses> {
try {
const res = await fetchWithAppCheck(
`${Config.CORE_PROFILE_URL}/v1/get-addresses`,
JSON.stringify({
networkType: networkType,
extendedPublicKey: xpubXP,
isTestnet,
onlyWithActivity
})
)

if (!res.ok) {
throw new Error(`${res.status}:${res.statusText}`)
}

return res.json()
} catch (err) {
Logger.error(`[ProfileService][fetchXPAddresses]${err}`)
throw err
}
}
}

export default new ProfileService()
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default class KeystoneWallet implements Wallet {
s: string
v: number
}> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const signature: any = ETHSignature.fromCBOR(cbor).getSignature()
const r = hexlify(new Uint8Array(signature.slice(0, 32)))
const s = hexlify(new Uint8Array(signature.slice(32, 64)))
Expand Down Expand Up @@ -192,11 +193,9 @@ export default class KeystoneWallet implements Wallet {
{
masterFingerprint: Buffer.from(this.mfp, 'hex'),
pubkey: getAddressPublicKeyFromXPub(this.xpub, accountIndex),
path: getAddressDerivationPath(
accountIndex,
DerivationPath.BIP44,
'EVM'
)
path: getAddressDerivationPath(accountIndex, 'EVM', {
pathSpec: DerivationPath.BIP44
})
}
]
})
Expand Down Expand Up @@ -238,6 +237,7 @@ export default class KeystoneWallet implements Wallet {
return await signer(requestUR, ['avax-signature'], cbor => {
const response = AvalancheSignature.fromCBOR(cbor)
const sig = response.getSignature()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tx.addSignature(sig as any)
return Promise.resolve(JSON.stringify(tx.toJSON()))
})
Expand Down Expand Up @@ -332,6 +332,7 @@ export default class KeystoneWallet implements Wallet {
// This here is BIP44 for the first account (index 0). 2nd account should be M/44'/60'/0'/0/1, etc..
const keyPath = `${EVM_DERIVATION_PATH}/0/${activeAccountIndex}`
const ethSignRequest = EthSignRequest.constructETHRequest(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Buffer.from(message as any),
dataType,
keyPath,
Expand Down
2 changes: 1 addition & 1 deletion packages/core-mobile/app/services/wallet/LedgerWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ export class LedgerWallet implements Wallet {
}
}

public async getRawXpubXP(): Promise<string> {
public async getRawXpubXP(_accountIndex: number): Promise<string> {
// TODO: implement this
throw new Error('getRawXpubXP not implemented yet for LedgerWallet')
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core-mobile/app/services/wallet/MnemonicWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export class MnemonicWallet implements Wallet {
this.#mnemonic = mnemonic
}

public getRawXpubXP(): string {
return Avalanche.getXpubFromMnemonic(this.mnemonic)
public getRawXpubXP(accountIndex: number): string {
return Avalanche.getXpubFromMnemonic(this.mnemonic, accountIndex)
}

/** WALLET INTERFACE IMPLEMENTATION **/
Expand Down
Loading
Loading