Skip to content

Commit 82d6d49

Browse files
committed
Transaction opponent key
1 parent 93506de commit 82d6d49

File tree

9 files changed

+35
-34
lines changed

9 files changed

+35
-34
lines changed

library/src/main/kotlin/one/mixin/bot/HttpClient.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package one.mixin.bot
22

33
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
4+
import java.security.Security
5+
import java.util.Locale
6+
import java.util.concurrent.TimeUnit
47
import net.i2p.crypto.eddsa.EdDSAPrivateKey
58
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable
69
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec
@@ -22,9 +25,6 @@ import one.mixin.bot.util.getRSAPrivateKeyFromString
2225
import org.bouncycastle.jce.provider.BouncyCastleProvider
2326
import retrofit2.Retrofit
2427
import retrofit2.converter.gson.GsonConverterFactory
25-
import java.security.Security
26-
import java.util.Locale
27-
import java.util.concurrent.TimeUnit
2828

2929
class HttpClient private constructor(
3030
private val clientToken: SessionToken,

library/src/main/kotlin/one/mixin/bot/Session.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package one.mixin.bot
22

33
import io.jsonwebtoken.Claims
44
import io.jsonwebtoken.Jwts
5+
import java.security.Key
6+
import java.util.UUID
7+
import java.util.concurrent.ConcurrentHashMap
58
import okhttp3.Request
69
import okio.ByteString.Companion.encode
710
import one.mixin.bot.extension.base64Decode
@@ -10,9 +13,6 @@ import one.mixin.bot.extension.bodyToString
1013
import one.mixin.bot.extension.path
1114
import one.mixin.bot.extension.toLeByteArray
1215
import one.mixin.bot.util.aesEncrypt
13-
import java.security.Key
14-
import java.util.UUID
15-
import java.util.concurrent.ConcurrentHashMap
1616

1717
fun signToken(userId: String, sessionId: String, method: String, path: String, body: String?, key: Key): String {
1818
val expire = System.currentTimeMillis() / 1000 + 1800

library/src/main/kotlin/one/mixin/bot/util/CryptoUtil.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package one.mixin.bot.util
22

3-
import net.i2p.crypto.eddsa.EdDSAPrivateKey
4-
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable
5-
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec
6-
import one.mixin.bot.extension.base64Decode
7-
import one.mixin.bot.extension.base64Encode
8-
import org.bouncycastle.jce.provider.BouncyCastleProvider
9-
import org.whispersystems.curve25519.Curve25519
103
import java.security.KeyFactory
114
import java.security.KeyPair
125
import java.security.KeyPairGenerator
@@ -25,6 +18,13 @@ import javax.crypto.spec.PSource
2518
import javax.crypto.spec.SecretKeySpec
2619
import kotlin.experimental.and
2720
import kotlin.experimental.or
21+
import net.i2p.crypto.eddsa.EdDSAPrivateKey
22+
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable
23+
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec
24+
import one.mixin.bot.extension.base64Decode
25+
import one.mixin.bot.extension.base64Encode
26+
import org.bouncycastle.jce.provider.BouncyCastleProvider
27+
import org.whispersystems.curve25519.Curve25519
2828

2929
fun generateRSAKeyPair(keyLength: Int = 2048): KeyPair {
3030
val kpg = KeyPairGenerator.getInstance("RSA")

library/src/main/kotlin/one/mixin/bot/vo/TransactionRequest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ data class TransactionRequest(
66
@SerializedName("asset_id")
77
val assetId: String,
88
@SerializedName("opponent_multisig")
9-
val opponentMultisig: OpponentMultisig,
9+
val opponentMultisig: OpponentMultisig? = null,
10+
@SerializedName("opponent_key")
11+
val opponentKey: String? = null,
1012
val amount: String,
1113
val pin: String,
1214
@SerializedName("trace_id")

library/src/test/kotlin/one/mixin/bot/CryptoTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package one.mixin.bot
22

3+
import kotlin.test.Test
4+
import kotlin.test.assertEquals
35
import one.mixin.bot.util.aesGcmDecrypt
46
import one.mixin.bot.util.aesGcmEncrypt
57
import one.mixin.bot.util.generateAesKey
6-
import kotlin.test.Test
7-
import kotlin.test.assertEquals
88

99
class CryptoTest {
1010
@Test fun testAesGcm() {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package jvmMain.java;
22

33
final class Config {
4-
final static String pin = "538128";
4+
final static String pin = "967784";
55
final static String userId = "24888245-d200-4907-aff0-1303d94217d5";
6-
final static String sessionId = "7a511421-65ed-4475-825e-550eaea847f8";
7-
final static String privateKey = "bQ4fXlU-AFwhb5tbr3n3sJTd_5GJJylYQybQOXArf1CwsXUYms9S2stQAiQb_4oStPsZvkokX6drZiiBk4TmGA";
8-
final static String pinTokenPem = "kCIUWq-UX6QNXVOaeS7KpZoZSN61HlC2PLr5-c8FcEs";
9-
}
6+
final static String sessionId = "0d89aa10-f559-400e-9323-9d103f9fd49e";
7+
final static String privateKey = "ZywWUtZxMUxdS6LHSEqVsxFr9Y3pM5OJDx648Hm54Tgn9IoGhUOLbNoQ2nKewVNnCsBF3qOcb4nuiowuxQax4w";
8+
final static String pinTokenPem = "kMu0ihumvCC0t1sgbD1n1sv8TQLFVje4qWv-Wpy_Ihg";
9+
}

samples/src/main/java/jvmMain/java/Sample.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Sample {
2424
final static String userPin = "131416";
2525
final static String CNB_assetId = "965e5c6e-434c-3fa9-b780-c50f43cd955c";
2626
final static String BTC_assetId = "c6d0c728-2624-429b-8e0d-d9d19b6592fa";
27-
final static String amount = "2";
27+
final static String amount = "0.001";
2828

2929
public static void main(String[] args) {
3030
EdDSAPrivateKey key = getEdDSAPrivateKeyFromString(privateKey);
@@ -245,10 +245,7 @@ private static SessionToken getUserToken(User user, KeyPair sessionKey, boolean
245245

246246
private static void transactions(HttpClient client, List<String> receivers, String aseKey, String pin) throws IOException {
247247
MixinResponse<TransactionResponse> transactionResponse = client.getAssetService().transactionsCall(
248-
new TransactionRequest(Sample.CNB_assetId, new OpponentMultisig(
249-
receivers,
250-
2
251-
), Sample.amount, encryptPin(aseKey, pin, System.nanoTime())
248+
new TransactionRequest(Sample.CNB_assetId, null,"XINQTmRReDuPEUAVEyDyE2mBgxa1ojVRAvpYcKs5nSA7FDBBfAEeVRn8s9vAm3Cn1qzQ7JtjG62go4jSJU6yWyRUKHpamWAM", Sample.amount, encryptPin(aseKey, pin, System.nanoTime())
252249
, null, null)).execute().body();
253250
assert transactionResponse != null;
254251
if (transactionResponse.isSuccess()) {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package jvmMain.kotlin
22

33
object Config {
4-
const val pin = "538128"
4+
const val pin = "967784"
55
const val userId = "24888245-d200-4907-aff0-1303d94217d5"
6-
const val sessionId = "7a511421-65ed-4475-825e-550eaea847f8"
6+
const val sessionId = "0d89aa10-f559-400e-9323-9d103f9fd49e"
77
const val privateKey =
8-
"bQ4fXlU-AFwhb5tbr3n3sJTd_5GJJylYQybQOXArf1CwsXUYms9S2stQAiQb_4oStPsZvkokX6drZiiBk4TmGA"
9-
const val pinTokenPem = "kCIUWq-UX6QNXVOaeS7KpZoZSN61HlC2PLr5-c8FcEs"
10-
}
8+
"ZywWUtZxMUxdS6LHSEqVsxFr9Y3pM5OJDx648Hm54Tgn9IoGhUOLbNoQ2nKewVNnCsBF3qOcb4nuiowuxQax4w"
9+
const val pinTokenPem = "kMu0ihumvCC0t1sgbD1n1sv8TQLFVje4qWv-Wpy_Ihg"
10+
}

samples/src/main/java/jvmMain/kotlin/Sample.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import java.util.UUID
2929
const val CNB_ID = "965e5c6e-434c-3fa9-b780-c50f43cd955c"
3030
const val BTC_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
3131
const val DEFAULT_PIN = "131416"
32-
const val DEFAULT_AMOUNT = "1"
32+
const val DEFAULT_AMOUNT = "0.01"
3333

3434
fun main() = runBlocking {
3535
val key = getEdDSAPrivateKeyFromString(Config.privateKey)
@@ -251,11 +251,13 @@ private suspend fun transactions(
251251
val transactionsResponse = client.assetService.transactions(
252252
TransactionRequest(
253253
CNB_ID,
254-
OpponentMultisig(listOf("00c5a4ae-dcdc-48db-ab8e-a7eef69b441d", "087e91ff-7169-451a-aaaa-5b3297411a4b", "4e0e6e6b-6c9d-4e99-b7f1-1356322abec3"), 2),
254+
// OpponentMultisig(listOf("00c5a4ae-dcdc-48db-ab8e-a7eef69b441d", "087e91ff-7169-451a-aaaa-5b3297411a4b", "4e0e6e6b-6c9d-4e99-b7f1-1356322abec3"), 2),
255+
opponentMultisig = null,
256+
opponentKey = "XINQTmRReDuPEUAVEyDyE2mBgxa1ojVRAvpYcKs5nSA7FDBBfAEeVRn8s9vAm3Cn1qzQ7JtjG62go4jSJU6yWyRUKHpamWAM", // test address
255257
DEFAULT_AMOUNT,
256258
encryptPin(
257259
userAesKey,
258-
DEFAULT_PIN,
260+
pin,
259261
System.nanoTime()
260262
),
261263
UUID.randomUUID().toString(),

0 commit comments

Comments
 (0)