From a0dc1ce406313159146c0dbc4440e2fe92ea3135 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 24 Oct 2024 16:10:26 -0700 Subject: [PATCH] Add wallet contract version to keys Necessary for moving seeds between wallets --- src/ton/TonTools.ts | 14 +++++++++++--- src/ton/tonInfo.ts | 1 + src/ton/tonTypes.ts | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ton/TonTools.ts b/src/ton/TonTools.ts index a8dc6859f..477a62c6d 100644 --- a/src/ton/TonTools.ts +++ b/src/ton/TonTools.ts @@ -27,7 +27,12 @@ import { mergeDeeply, shuffleArray } from '../common/utils' -import { asTonPrivateKeys, TonInfoPayload, TonNetworkInfo } from './tonTypes' +import { + asTonPrivateKeys, + TonInfoPayload, + TonNetworkInfo, + wasTonPrivateKeys +} from './tonTypes' export class TonTools implements EdgeCurrencyTools { io: EdgeIo @@ -100,7 +105,7 @@ export class TonTools implements EdgeCurrencyTools { ): Promise { const { pluginId } = this.currencyInfo const keys = asTonPrivateKeys(pluginId)(privateWalletInfo.keys) - return keys.mnemonic + return `${keys.mnemonic}\n\nVersion: ${keys.walletContract}` } async getDisplayPublicKey(publicWalletInfo: EdgeWalletInfo): Promise { @@ -112,7 +117,10 @@ export class TonTools implements EdgeCurrencyTools { const isValid = validateMnemonic(input) if (!isValid) throw new Error('Invalid mnemonic') - return { [this.networkInfo.pluginMnemonicKeyName]: input } + return wasTonPrivateKeys(this.currencyInfo.pluginId)({ + mnemonic: input, + walletContract: this.networkInfo.defaultWalletContract + }) } async createPrivateKey(walletType: string): Promise { diff --git a/src/ton/tonInfo.ts b/src/ton/tonInfo.ts index 42e5d6cb5..cbabc8d9d 100644 --- a/src/ton/tonInfo.ts +++ b/src/ton/tonInfo.ts @@ -5,6 +5,7 @@ import type { TonTools } from './TonTools' import { asTonInfoPayload, TonInfoPayload, TonNetworkInfo } from './tonTypes' const networkInfo: TonNetworkInfo = { + defaultWalletContract: 'v5r1', minimumAddressBalance: '50000000', // 0.5 TON There isn't a hardcoded minimum but the user needs to keep something left pluginMnemonicKeyName: 'tonMnemonic', tonCenterUrl: 'https://toncenter.com/api/v2/jsonRPC', diff --git a/src/ton/tonTypes.ts b/src/ton/tonTypes.ts index 8e3d02c2b..88239b0f4 100644 --- a/src/ton/tonTypes.ts +++ b/src/ton/tonTypes.ts @@ -5,10 +5,12 @@ import { asObject, asOptional, asString, - Cleaner + Cleaner, + uncleaner } from 'cleaners' export interface TonNetworkInfo { + defaultWalletContract: string minimumAddressBalance: string pluginMnemonicKeyName: string tonCenterUrl: string @@ -37,26 +39,32 @@ export type TonWalletOtherData = ReturnType export interface TonPrivateKeys { mnemonic: string + walletContract: string } export const asTonPrivateKeys = (pluginId: string): Cleaner => { const asKeys = asObject({ - [`${pluginId}Mnemonic`]: asString + [`${pluginId}Mnemonic`]: asString, + walletContract: asString }) return asCodec( raw => { const from = asKeys(raw) return { - mnemonic: from[`${pluginId}Mnemonic`] + mnemonic: from[`${pluginId}Mnemonic`], + walletContract: from.walletContract } }, clean => { return { - [`${pluginId}Mnemonic`]: clean.mnemonic + [`${pluginId}Mnemonic`]: clean.mnemonic, + walletContract: clean.walletContract } } ) } +export const wasTonPrivateKeys = (pluginId: string): Cleaner => + uncleaner(asTonPrivateKeys(pluginId)) const asBigInt = (val: any): BigInt => { if (typeof val !== 'bigint') {