Skip to content

Commit

Permalink
chore(wallet-mobile): dropped legacy assert things
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Oct 31, 2024
1 parent 94f6bfe commit eaf3237
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 68 deletions.
1 change: 0 additions & 1 deletion apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
"@yoroi/theme": "^2.0.0",
"@yoroi/transfer": "^1.0.1",
"add": "2.0.6",
"assert": "^2.0.0",
"axios": "^1.5.0",
"base-64": "^1.0.0",
"bignumber.js": "^9.0.1",
Expand Down
10 changes: 0 additions & 10 deletions apps/wallet-mobile/src/features/Dev/DeveloperScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage'
import {useNavigation} from '@react-navigation/native'
import {useTheme} from '@yoroi/theme'
import {Api} from '@yoroi/types'
import assert from 'assert'
import _ from 'lodash'
import React from 'react'
import {useIntl} from 'react-intl'
Expand Down Expand Up @@ -284,8 +283,6 @@ const read = async (path: string) => {
}

const readMany = async (paths: Array<string>) => {
assert(_.every(paths, checkPathFormat), 'Wrong storage key path')

try {
const items = await AsyncStorage.multiGet(paths)

Expand All @@ -297,10 +294,6 @@ const readMany = async (paths: Array<string>) => {
}

const write = async (path: string, data: any) => {
assert(path.startsWith('/'), 'Wrong storage key path')
assert(!path.endsWith('/'), 'Wrong storage key path')
assert(data !== undefined, 'Cannot store undefined')

try {
await AsyncStorage.setItem(path, JSON.stringify(data))
} catch (error) {
Expand All @@ -309,9 +302,6 @@ const write = async (path: string, data: any) => {
}

const remove = async (path: string) => {
assert(path.startsWith('/'), 'Wrong storage key path')
assert(!path.endsWith('/'), 'Wrong storage key path')

try {
await AsyncStorage.removeItem(path)
} catch (error) {
Expand Down
3 changes: 0 additions & 3 deletions apps/wallet-mobile/src/kernel/encryption/encryption.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {App} from '@yoroi/types'
import assert from 'assert'
import cryptoRandomString from 'crypto-random-string'

import {Cardano} from '../../yoroi-wallets/wallets'

export const encryptData = async (plaintextHex: string, secretKey: string): Promise<string> => {
assert(!!plaintextHex, 'encrypt:: !!plaintextHex')
assert(!!secretKey, 'encrypt:: !!secretKey')
const secretKeyHex = Buffer.from(secretKey, 'utf8').toString('hex')
const saltHex = cryptoRandomString({
length: 2 * 32,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {parseSafe} from '@yoroi/common'
import {App, Wallet} from '@yoroi/types'
import assert from 'assert'
import _ from 'lodash'
import {defaultMemoize} from 'reselect'

Expand Down Expand Up @@ -132,8 +131,6 @@ export class AddressChain {
lastUsedIndex = 0,
lastUsedIndexVisual = lastUsedIndex,
) {
assert(blockSize > gapLimit, 'Block size needs to be > gap limit')

this._addressGenerator = addressGenerator
this._blockSize = blockSize
this._gapLimit = gapLimit
Expand Down Expand Up @@ -194,7 +191,6 @@ export class AddressChain {
}

_extendAddresses(newAddresses: Array<string>) {
assert(_.intersection(this._addresses, newAddresses).length === 0, 'extendAddresses received an existing address')
this._addresses = [...this._addresses, ...newAddresses]
this._subscriptions.forEach((handler) => handler(newAddresses))
}
Expand All @@ -214,9 +210,7 @@ export class AddressChain {
}

_getLastBlock() {
this._selfCheck()
const block = _.takeRight(this.addresses, this._blockSize)
assert(block.length === this._blockSize, 'AddressChain::_getLastBlock(): block length')
return block
}

Expand All @@ -226,11 +220,6 @@ export class AddressChain {
this._isInitialized = true
}

_selfCheck() {
assert(this._isInitialized, 'AddressChain::_selfCheck(): isInitialized')
assert(this._addresses.length % this._blockSize === 0, 'AddressChain::_selfCheck(): lengths')
}

async sync(filterFn: AsyncAddressFilter) {
let keepSyncing = true
while (keepSyncing) {
Expand All @@ -239,7 +228,6 @@ export class AddressChain {
}

async _syncStep(filterFn: AsyncAddressFilter) {
this._selfCheck()
const block = this._getLastBlock()
const used = await filterFn(block)

Expand Down
4 changes: 0 additions & 4 deletions apps/wallet-mobile/src/yoroi-wallets/cardano/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert'
import _ from 'lodash'

import type {
Expand Down Expand Up @@ -30,7 +29,6 @@ export const fetchNewTxHistory = async (
request: TxHistoryRequest,
baseApiUrl: string,
): Promise<{isLast: boolean; transactions: Array<RawTransaction>}> => {
assert(request.addresses.length <= limitApiRecords, 'fetchNewTxHistory: too many addresses')
const transactions = await fetchDefault<Array<RawTransaction>>('v2/txs/history', request, baseApiUrl)

return {
Expand All @@ -40,7 +38,6 @@ export const fetchNewTxHistory = async (
}

export const filterUsedAddresses = async (addresses: Addresses, baseApiUrl: string): Promise<Addresses> => {
assert(addresses.length <= limitApiRecords, 'filterUsedAddresses: too many addresses')
// Take a copy in case underlying data mutates during await
const copy = [...addresses]
const used = await fetchDefault<Addresses>('v2/addresses/filterUsed', {addresses: copy}, baseApiUrl)
Expand All @@ -57,7 +54,6 @@ export const submitTransaction = async (signedTx: string, baseApiUrl: string): P
}

export const getAccountState = (request: AccountStateRequest, baseApiUrl: string): Promise<AccountStateResponse> => {
assert(request.addresses.length <= limitApiRecords, 'getAccountState: too many addresses')
return fetchDefault('account/state', request, baseApiUrl)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from 'assert'

import {cardanoConfig} from '../../../features/WalletManager/common/adapters/cardano/cardano-config'
import {CardanoMobile} from '../../wallets'

Expand All @@ -20,7 +18,6 @@ export const isValidPath = (path: unknown): boolean => {
}

export const isCIP1852AccountPath = (path: Array<number>): boolean => {
assert(isValidPath(path), 'invalid bip44 path')
// note: allows non-zero accounts
return (
path.length === 3 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {Datum} from '@emurgo/yoroi-lib/dist/internals/models'
import {AppApi} from '@yoroi/api'
import {isNonNullable} from '@yoroi/common'
import {Api, App, Balance, HW, Network, Portfolio, Wallet} from '@yoroi/types'
import assert from 'assert'
import {BigNumber} from 'bignumber.js'
import {Buffer} from 'buffer'
import {freeze} from 'immer'
Expand Down Expand Up @@ -252,7 +251,6 @@ export const makeCardanoWallet = (networkManager: Network.Manager, implementatio

const candidateAddresses = this.internalChain.addresses
const unseen = candidateAddresses.filter((addr) => !this.isUsedAddress(addr))
assert(unseen.length > 0, 'Cannot find change address')
const changeAddress = _.first(unseen)
if (!changeAddress) throwLoggedError('CardanoWallet: getChangeAddress unable to resolve change address')
return changeAddress
Expand Down Expand Up @@ -1086,7 +1084,6 @@ export const makeCardanoWallet = (networkManager: Network.Manager, implementatio

private _isUsedAddressIndexSelector = defaultMemoize((perAddressTxs) =>
_.mapValues(perAddressTxs, (txs) => {
assert(!!txs, 'perAddressTxs cointains false-ish value')
return txs.length > 0
}),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {normalizeToAddress} from '@emurgo/yoroi-lib/dist/internals/utils/addresses'
import assert from 'assert'
import {Buffer} from 'buffer'

import {harden} from '../common/signatureUtils'
Expand All @@ -20,7 +19,6 @@ describe('CIP8', () => {

const payloadInBytes = Buffer.from(payload, 'hex')
const normalisedAddress = await normalizeToAddress(csl, bech32)
assert(normalisedAddress != null)
const coseSign1 = await cip8.sign(Buffer.from(await normalisedAddress.toHex(), 'hex'), signingKey, payloadInBytes)
const signature = Buffer.from(await coseSign1.toBytes()).toString('hex')
expect(signature).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import {CardanoAddressedUtxo} from '@emurgo/yoroi-lib'
import {normalizeToAddress} from '@emurgo/yoroi-lib/dist/internals/utils/addresses'
import assert from 'assert'
import {sortBy} from 'lodash'

import {StakingStatus} from '../types/staking'
Expand Down Expand Up @@ -65,7 +64,6 @@ export const getDelegationStatus = (
if (cert.rewardAddress !== rewardAddress) continue

if (cert.kind === 'StakeDelegation') {
assert(cert.poolKeyHash != null, 'getDelegationStatus:: StakeDelegation certificate without poolKeyHash')
status = {
poolKeyHash: cert.poolKeyHash,
isRegistered: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {isArray, isString} from '@yoroi/common'
import {Portfolio} from '@yoroi/types'
import assert from 'assert'
import {BigNumber} from 'bignumber.js'

import {
Expand Down Expand Up @@ -235,7 +234,6 @@ export const processTxHistoryData = (
amount = brutto.joinSubtractMutable(totalFee)
fee = remoteFee ?? totalFee
} else {
assert(ownInputs.length === 0, 'This cannot be receiving transaction')
direction = TRANSACTION_DIRECTION.RECEIVED
amount = brutto
fee = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {isArray, parseSafe, PromiseAllLimited} from '@yoroi/common'
import {App} from '@yoroi/types'
import assert from 'assert'
import {fromPairs, mapValues, max} from 'lodash'
import DeviceInfo from 'react-native-device-info'
import {defaultMemoize} from 'reselect'
Expand Down Expand Up @@ -478,7 +477,6 @@ const confirmationCountsSelector = (state: TransactionManagerState) => {
...tx.inputs.map(getBlockNum),
...tx.outputs.map(getBlockNum),
])
assert(tx.blockNum, 'Successfull tx should have blockNum')

return bestBlockNum - (tx as any).blockNum
})
Expand Down
25 changes: 1 addition & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7054,16 +7054,6 @@ assert@^1.1.1:
object-assign "^4.1.1"
util "0.10.3"

assert@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/assert/-/assert-2.0.0.tgz#95fc1c616d48713510680f2eaf2d10dd22e02d32"
integrity sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==
dependencies:
es6-object-assign "^1.1.0"
is-nan "^1.2.1"
object-is "^1.0.1"
util "^0.12.0"

assertion-error@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
Expand Down Expand Up @@ -10746,11 +10736,6 @@ es5-shim@^4.5.13:
resolved "https://registry.yarnpkg.com/es5-shim/-/es5-shim-4.6.7.tgz#bc67ae0fc3dd520636e0a1601cc73b450ad3e955"
integrity sha512-jg21/dmlrNQI7JyyA2w7n+yifSxBng0ZralnSfVZjoCawgNTCnS+yBCyVM9DL5itm7SUnDGgv7hcq2XCZX4iRQ==

es6-object-assign@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/es6-object-assign/-/es6-object-assign-1.1.0.tgz#c2c3582656247c39ea107cb1e6652b6f9f24523c"
integrity sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==

es6-shim@^0.35.5:
version "0.35.8"
resolved "https://registry.yarnpkg.com/es6-shim/-/es6-shim-0.35.8.tgz#89216f6fbf8bacba3f897c8c0e814d2a41c05fb7"
Expand Down Expand Up @@ -13728,14 +13713,6 @@ is-map@^2.0.1, is-map@^2.0.2:
resolved "https://registry.yarnpkg.com/is-map/-/is-map-2.0.2.tgz#00922db8c9bf73e81b7a335827bc2a43f2b91127"
integrity sha512-cOZFQQozTha1f4MxLFzlgKYPTyj26picdZTx82hbc/Xf4K/tZOOXSCkMvU4pKioRXGDLJRn0GM7Upe7kR721yg==

is-nan@^1.2.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/is-nan/-/is-nan-1.3.2.tgz#043a54adea31748b55b6cd4e09aadafa69bd9e1d"
integrity sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==
dependencies:
call-bind "^1.0.0"
define-properties "^1.1.3"

is-negative-zero@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.2.tgz#7bf6f03a28003b8b3965de3ac26f664d765f3150"
Expand Down Expand Up @@ -22716,7 +22693,7 @@ util@^0.11.0:
dependencies:
inherits "2.0.3"

util@^0.12.0, util@^0.12.4:
util@^0.12.4:
version "0.12.5"
resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc"
integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==
Expand Down

0 comments on commit eaf3237

Please sign in to comment.