-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8babe7e
commit 12e2fbf
Showing
16 changed files
with
269 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/one/mixin/android/api/request/AnonymousMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package one.mixin.android.api.request | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import one.mixin.android.extension.sha256 | ||
import one.mixin.android.extension.toHex | ||
import one.mixin.android.util.GsonHelper | ||
import timber.log.Timber | ||
import kotlin.random.Random | ||
|
||
class AnonymousMessage( | ||
@SerializedName("random") | ||
var random: String = "", | ||
@SerializedName("created_at") | ||
val createdAt: String | ||
) | ||
|
||
fun AnonymousMessage.doAnonymousPOW(): AnonymousMessage { | ||
val anonymousNumberDifficulty = 1 | ||
val prefix = "0".repeat(anonymousNumberDifficulty) | ||
val data = ByteArray(32) | ||
|
||
while (true) { | ||
Random.nextBytes(data) | ||
this.random = data.toHex() | ||
val messageBuf = GsonHelper.customGson.toJson(this).toByteArray() | ||
val hash = messageBuf.sha256() | ||
val hashHex = hash.toHex() | ||
Timber.e("json ${GsonHelper.customGson.toJson(this)} hex:$hashHex") | ||
if (hashHex.startsWith(prefix)) { | ||
return this | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.