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

Update display-key methods #594

Merged
merged 2 commits into from
Aug 28, 2023
Merged
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
11 changes: 0 additions & 11 deletions src/algorand/AlgorandEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,17 +708,6 @@ export class AlgorandEngine extends CurrencyEngine<
return edgeTransaction
}

getDisplayPrivateSeed(privateKeys: JsonObject): string {
const algorandPrivateKeys = asAlgorandPrivateKeys(
this.currencyInfo.pluginId
)(privateKeys)
return algorandPrivateKeys.mnemonic
}

getDisplayPublicSeed(): string {
return this.walletInfo.keys.publicKey ?? ''
}

engineGetActivationAssets = async (
options: EdgeEngineGetActivationAssetsOptions
): Promise<EdgeGetActivationAssetsResults> => {
Expand Down
16 changes: 15 additions & 1 deletion src/algorand/AlgorandTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { getDenomInfo } from '../common/utils'
import {
AlgorandNetworkInfo,
asAlgorandPrivateKeys,
asMaybeContractAddressLocation
asMaybeContractAddressLocation,
asSafeAlgorandWalletInfo
} from './algorandTypes'

const { isValidAddress, mnemonicFromSeed } = algosdk
Expand All @@ -37,6 +38,19 @@ export class AlgorandTools implements EdgeCurrencyTools {
this.builtinTokens = builtinTokens
}

async getDisplayPrivateKey(
privateWalletInfo: EdgeWalletInfo
): Promise<string> {
const { pluginId } = this.currencyInfo
const keys = asAlgorandPrivateKeys(pluginId)(privateWalletInfo.keys)
return keys.mnemonic
}

async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise<string> {
const { keys } = asSafeAlgorandWalletInfo(publicWalletInfo)
return keys.publicKey
}

async importPrivateKey(input: string): Promise<JsonObject> {
const { pluginId } = this.currencyInfo

Expand Down
10 changes: 0 additions & 10 deletions src/binance/BinanceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,6 @@ export class BinanceEngine extends CurrencyEngine<
throw new Error(`Broadcast failed: ${e.message}`)
}
}

getDisplayPrivateSeed(privateKeys: JsonObject): string {
const bnbPrivateKey = asBnbPrivateKey(privateKeys)
return bnbPrivateKey.binanceMnemonic
}

getDisplayPublicSeed(): string {
const { keys } = this.walletInfo
return keys.publicKey
}
}

export async function makeCurrencyEngine(
Expand Down
18 changes: 17 additions & 1 deletion src/binance/BinanceTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
import { PluginEnvironment } from '../common/innerPlugin'
import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers'
import { getDenomInfo } from '../common/utils'
import { BinanceNetworkInfo } from './binanceTypes'
import {
asBnbPrivateKey,
asSafeBnbWalletInfo,
BinanceNetworkInfo
} from './binanceTypes'

const {
checkAddress,
Expand All @@ -39,6 +43,18 @@ export class BinanceTools implements EdgeCurrencyTools {
this.networkInfo = networkInfo
}

async getDisplayPrivateKey(
privateWalletInfo: EdgeWalletInfo
): Promise<string> {
const keys = asBnbPrivateKey(privateWalletInfo.keys)
return keys.binanceMnemonic
}

async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise<string> {
const { keys } = asSafeBnbWalletInfo(publicWalletInfo)
return keys.publicKey
}

// will actually use MNEMONIC version of private key
async importPrivateKey(mnemonic: string): Promise<Object> {
const isValid = validateMnemonic(mnemonic)
Expand Down
8 changes: 0 additions & 8 deletions src/common/CurrencyEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,14 +1076,6 @@ export class CurrencyEngine<
// Virtual functions to be override by extension:
//

getDisplayPrivateSeed(privateKeys: JsonObject): string | null {
throw new Error('not implemented')
}

getDisplayPublicSeed(): string | null {
throw new Error('not implemented')
}

async resyncBlockchain(): Promise<void> {
throw new Error('not implemented')
}
Expand Down
25 changes: 0 additions & 25 deletions src/eos/EosEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,31 +1150,6 @@ export class EosEngine extends CurrencyEngine<EosTools, SafeEosWalletInfo> {
throw err
}
}

getDisplayPrivateSeed(privateKeys: JsonObject): string {
const eosPrivateKeys = asEosPrivateKeys(privateKeys)
let out = ''
// usage of eosOwnerKey must be protected by conditional
// checking for its existence
out += 'owner key\n' + String(eosPrivateKeys.eosOwnerKey) + '\n\n'
out += 'active key\n' + String(eosPrivateKeys.eosKey) + '\n\n'
return out
}

getDisplayPublicSeed(): string {
let out = ''
if (this.walletInfo.keys?.ownerPublicKey != null) {
out +=
'owner publicKey\n' +
String(this.walletInfo.keys.ownerPublicKey) +
'\n\n'
}
if (this.walletInfo.keys?.publicKey != null) {
out +=
'active publicKey\n' + String(this.walletInfo.keys.publicKey) + '\n\n'
}
return out
}
}

export async function makeCurrencyEngine(
Expand Down
31 changes: 30 additions & 1 deletion src/eos/EosTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import {
asGetActivationCost,
asGetActivationSupportedCurrencies
} from './eosSchema'
import { EosNetworkInfo } from './eosTypes'
import {
asEosPrivateKeys,
asSafeEosWalletInfo,
EosNetworkInfo
} from './eosTypes'

export function checkAddress(address: string): boolean {
return Name.pattern.test(address)
Expand Down Expand Up @@ -63,6 +67,31 @@ export class EosTools implements EdgeCurrencyTools {
this.networkInfo = networkInfo
}

async getDisplayPrivateKey(
privateWalletInfo: EdgeWalletInfo
): Promise<string> {
const keys = asEosPrivateKeys(privateWalletInfo.keys)
let out = ''
// usage of eosOwnerKey must be protected by conditional
// checking for its existence
out += 'owner key\n' + String(keys.eosOwnerKey) + '\n\n'
out += 'active key\n' + String(keys.eosKey) + '\n\n'
return out
}

async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise<string> {
const { keys } = asSafeEosWalletInfo(publicWalletInfo)

let out = ''
if (keys?.ownerPublicKey != null) {
out += 'owner publicKey\n' + String(keys.ownerPublicKey) + '\n\n'
}
if (keys?.publicKey != null) {
out += 'active publicKey\n' + String(keys.publicKey) + '\n\n'
}
return out
}

async importPrivateKey(privateKey: string): Promise<Object> {
const strippedPrivateKey = privateKey.replace(/ /g, '') // should be in WIF format
if (strippedPrivateKey.length !== 51) {
Expand Down
11 changes: 0 additions & 11 deletions src/ethereum/EthereumEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,17 +1325,6 @@ export class EthereumEngine extends CurrencyEngine<
}
}

getDisplayPrivateSeed(privateKeys: JsonObject): string {
const ethereumPrivateKeys = asEthereumPrivateKeys(
this.currencyInfo.pluginId
)(privateKeys)
return ethereumPrivateKeys.privateKey
}

getDisplayPublicSeed(): string | null {
return this.walletInfo.keys.publicKey
}

// Overload saveTx to mutate replaced transactions by RBF
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async saveTx(edgeTransaction: EdgeTransaction) {
Expand Down
19 changes: 18 additions & 1 deletion src/ethereum/EthereumTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { asMaybeContractLocation, validateToken } from '../common/tokenHelpers'
import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers'
import { biggyScience, getDenomInfo } from '../common/utils'
import { ethereumPlugins } from './ethereumInfos'
import { EthereumNetworkInfo } from './ethereumTypes'
import {
asEthereumPrivateKeys,
asSafeEthWalletInfo,
EthereumNetworkInfo
} from './ethereumTypes'

export class EthereumTools implements EdgeCurrencyTools {
builtinTokens: EdgeTokenMap
Expand All @@ -36,6 +40,19 @@ export class EthereumTools implements EdgeCurrencyTools {
this.networkInfo = networkInfo
}

async getDisplayPrivateKey(
privateWalletInfo: EdgeWalletInfo
): Promise<string> {
const { pluginId } = this.currencyInfo
const keys = asEthereumPrivateKeys(pluginId)(privateWalletInfo.keys)
return keys.privateKey
}

async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise<string> {
const { keys } = asSafeEthWalletInfo(publicWalletInfo)
return keys.publicKey
}

async importPrivateKey(userInput: string): Promise<Object> {
const { pluginId } = this.currencyInfo
const { pluginMnemonicKeyName, pluginRegularKeyName } = this.networkInfo
Expand Down
9 changes: 0 additions & 9 deletions src/fio/FioEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1991,15 +1991,6 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
async getFreshAddress(options: any): Promise<EdgeFreshAddress> {
return { publicAddress: this.walletInfo.keys.publicKey }
}

getDisplayPrivateSeed(privateKeys: JsonObject): string {
const fioPrivateKeys = asFioPrivateKeys(privateKeys)
return fioPrivateKeys.fioKey
}

getDisplayPublicSeed(): string {
return this.walletInfo.keys.publicKey
}
}

export async function makeCurrencyEngine(
Expand Down
18 changes: 17 additions & 1 deletion src/fio/FioTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import {
import { DEFAULT_APR, FIO_REG_API_ENDPOINTS } from './fioConst'
import { fioApiErrorCodes, FioError } from './fioError'
import { currencyInfo } from './fioInfo'
import { FioNetworkInfo } from './fioTypes'
import {
asFioPrivateKeys,
asSafeFioWalletInfo,
FioNetworkInfo
} from './fioTypes'

const FIO_CURRENCY_CODE = 'FIO'
const FIO_TYPE = 'fio'
Expand Down Expand Up @@ -74,6 +78,18 @@ export class FioTools implements EdgeCurrencyTools {
}
}

async getDisplayPrivateKey(
privateWalletInfo: EdgeWalletInfo
): Promise<string> {
const keys = asFioPrivateKeys(privateWalletInfo.keys)
return keys.fioKey
}

async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise<string> {
const { keys } = asSafeFioWalletInfo(publicWalletInfo)
return keys.publicKey
}

async importPrivateKey(userInput: string): Promise<Object> {
const { pluginId } = this.currencyInfo
const keys = {}
Expand Down
19 changes: 0 additions & 19 deletions src/hedera/HederaEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,25 +544,6 @@ export class HederaEngine extends CurrencyEngine<
getBlockHeight(): number {
return Math.floor(Date.now() / 1000)
}

getDisplayPrivateSeed(privateKeys: JsonObject): string {
const hederaPrivateKeys = asHederaPrivateKeys(this.currencyInfo.pluginId)(
privateKeys
)
return hederaPrivateKeys.mnemonic ?? hederaPrivateKeys.privateKey
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
getDisplayPublicSeed() {
if (
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
this.walletInfo.keys != null &&
this.walletInfo.keys.publicKey != null
) {
return this.walletInfo.keys.publicKey
}
return ''
}
}

function hashToTxid(hash: Uint8Array): string {
Expand Down
20 changes: 19 additions & 1 deletion src/hedera/HederaTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {
import { PluginEnvironment } from '../common/innerPlugin'
import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers'
import { getDenomInfo, getFetchCors } from '../common/utils'
import { asGetActivationCost, HederaNetworkInfo } from './hederaTypes'
import {
asGetActivationCost,
asHederaPrivateKeys,
asSafeHederaWalletInfo,
HederaNetworkInfo
} from './hederaTypes'
import { createChecksum, validAddress } from './hederaUtils'

// if users want to import their mnemonic phrase in e.g. MyHbarWallet.com
Expand All @@ -42,6 +47,19 @@ export class HederaTools implements EdgeCurrencyTools {
this.networkInfo = networkInfo
}

async getDisplayPrivateKey(
privateWalletInfo: EdgeWalletInfo
): Promise<string> {
const { pluginId } = this.currencyInfo
const keys = asHederaPrivateKeys(pluginId)(privateWalletInfo.keys)
return keys.mnemonic ?? keys.privateKey
}

async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise<string> {
const { keys } = asSafeHederaWalletInfo(publicWalletInfo)
return keys.publicKey
}

async createPrivateKey(walletType: string): Promise<Object> {
if (walletType !== this.currencyInfo.walletType) {
throw new Error('InvalidWalletType')
Expand Down
11 changes: 0 additions & 11 deletions src/polkadot/PolkadotEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,17 +476,6 @@ export class PolkadotEngine extends CurrencyEngine<

return edgeTransaction
}

getDisplayPrivateSeed(privateKeys: JsonObject): string {
const polkadotPrivateKeys = asPolkapolkadotPrivateKeys(
this.currencyInfo.pluginId
)(privateKeys)
return polkadotPrivateKeys.mnemonic ?? polkadotPrivateKeys.privateKey
}

getDisplayPublicSeed(): string {
return this.walletInfo.keys.publicKey ?? ''
}
}

export async function makeCurrencyEngine(
Expand Down
19 changes: 18 additions & 1 deletion src/polkadot/PolkadotTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
import { PluginEnvironment } from '../common/innerPlugin'
import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers'
import { getDenomInfo, isHex } from '../common/utils'
import { PolkadotNetworkInfo } from './polkadotTypes'
import {
asPolkapolkadotPrivateKeys,
asSafePolkadotWalletInfo,
PolkadotNetworkInfo
} from './polkadotTypes'

const { ed25519PairFromSeed, isAddress, mnemonicToMiniSecret } = utilCrypto

Expand All @@ -42,6 +46,19 @@ export class PolkadotTools implements EdgeCurrencyTools {
this.polkadotApiSubscribers = new Set()
}

async getDisplayPrivateKey(
privateWalletInfo: EdgeWalletInfo
): Promise<string> {
const { pluginId } = this.currencyInfo
const keys = asPolkapolkadotPrivateKeys(pluginId)(privateWalletInfo.keys)
return keys.mnemonic ?? keys.privateKey
}

async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise<string> {
const { keys } = asSafePolkadotWalletInfo(publicWalletInfo)
return keys.publicKey
}

async importPrivateKey(userInput: string): Promise<JsonObject> {
const { pluginId } = this.currencyInfo
if (validateMnemonic(userInput)) {
Expand Down
Loading
Loading