Feat: Encrypt and include seed words in account export

Encrypts the seed words using NIP-44 and adds them to the account export data. This ensures that mnemonic phrases are securely backed up along with other account details during the export process.
This commit is contained in:
greenart7c3
2025-10-20 14:26:41 -03:00
parent 5e58744f7f
commit 9b57a0ea09
2 changed files with 14 additions and 10 deletions
@@ -10,17 +10,19 @@ import com.fasterxml.jackson.module.kotlin.readValue
*/
@Immutable
data class AccountExportData(
@JsonProperty("npub")
@param:JsonProperty("npub")
val npub: String,
@JsonProperty("name")
@param:JsonProperty("name")
val name: String,
@JsonProperty("nsec")
@param:JsonProperty("nsec")
val nsec: String?,
@JsonProperty("signPolicy")
@param:JsonProperty("seedWords")
val seedWords: String,
@param:JsonProperty("signPolicy")
val signPolicy: Int,
@JsonProperty("picture")
@param:JsonProperty("picture")
val picture: String?,
@JsonProperty("didBackup")
@param:JsonProperty("didBackup")
val didBackup: Boolean,
)
@@ -29,13 +31,13 @@ data class AccountExportData(
*/
@Immutable
data class BulkAccountExport(
@JsonProperty("version")
@param:JsonProperty("version")
val version: String = "1.0",
@JsonProperty("exportDate")
@param:JsonProperty("exportDate")
val exportDate: Long = System.currentTimeMillis() / 1000,
@JsonProperty("accountCount")
@param:JsonProperty("accountCount")
val accountCount: Int,
@JsonProperty("accounts")
@param:JsonProperty("accounts")
val accounts: List<AccountExportData>,
) {
companion object {
@@ -64,6 +64,7 @@ object AccountExportService {
*/
private fun accountToExportData(account: Account, password: String): AccountExportData {
val privKey = account.signer.keyPair.privKey
val encrypedSeedWords = if (account.seedWords.isNotEmpty()) account.signer.signerSync.nip44Encrypt(account.seedWords.joinToString(" "), account.hexKey) else ""
// Encrypt private key with password (NIP-49) or use nsec if no password
val encryptedNsec = if (privKey != null) {
@@ -83,6 +84,7 @@ object AccountExportService {
signPolicy = account.signPolicy,
picture = account.picture.value,
didBackup = account.didBackup,
seedWords = encrypedSeedWords,
)
}
}