mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
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:
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user