Skip to content

Commit

Permalink
1.18.2:support private key
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjia404 committed Jun 30, 2023
1 parent 65ea141 commit 52a65e6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ dependencies {
testImplementation 'org.robolectric:shadows-multidex:4.4'
}

def canonicalVersionCode = 352
def canonicalVersionName = "1.18.1"
def canonicalVersionCode = 353
def canonicalVersionName = "1.18.2"

def postFixSize = 10
def abiPostFix = ['armeabi-v7a' : 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
val loadFileContents: (String) -> String = { fileName ->
MnemonicUtilities.loadFileContents(this, fileName)
}
MnemonicCodec(loadFileContents).encode(
hexEncodedSeed!!, MnemonicCodec.Language.Configuration.english
)
if (hexEncodedSeed.length == 64){
hexEncodedSeed
} else{
MnemonicCodec(loadFileContents).encode(
hexEncodedSeed!!, MnemonicCodec.Language.Configuration.english
)
}

}

private var displayNameEditActionMode: ActionMode? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
languageConfiguration: Language.Configuration = Language.Configuration.english
): String {
val words = mnemonic.split(" ").toMutableList()
// support private key
if (words.size == 1 && mnemonic.length == 64) {
return mnemonic
}

// support private key
if (words.size == 1 && mnemonic.length == 66 && mnemonic.startsWith("0x")) {
return mnemonic.substring(2)
}
// support session style
if (words.size == 13) {
return decodeOld(mnemonic, languageConfiguration)
Expand Down Expand Up @@ -188,11 +197,19 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
0,
0
)
val seed = MnemonicUtils.generateSeed(mnemonic, "")
val masterKeyPair = Bip32ECKeyPair.generateKeyPair(seed)
val bip44Keypair = Bip32ECKeyPair.deriveKeyPair(masterKeyPair, path)
val credentials = Credentials.create(bip44Keypair)
return credentials.address
val words = mnemonic.split(" ").toMutableList()
// support private key
if (words.size == 1 && mnemonic.length == 64) {
val credentials = Credentials.create(mnemonic)
return credentials.address
} else {
val seed = MnemonicUtils.generateSeed(mnemonic, "")
val masterKeyPair = Bip32ECKeyPair.generateKeyPair(seed)
val bip44Keypair = Bip32ECKeyPair.deriveKeyPair(masterKeyPair, path)
val credentials = Credentials.create(bip44Keypair)
return credentials.address
}

}
}
}

0 comments on commit 52a65e6

Please sign in to comment.