a.smali

.class public final Lcom/cmcm/safewallet/data/dapp/a/a;
.super Ljava/lang/Object;
.source "Sign.java"


# static fields
.field private static CURVE:Lorg/spongycastle/crypto/params/ECDomainParameters;

.field private static final CURVE_PARAMS:Lorg/spongycastle/asn1/x9/X9ECParameters;


# direct methods
.method static constructor <clinit>()V
    .registers 5

    .prologue
    .line 29
    const-string v0, "secp256k1"

    invoke-static {v0}, Lorg/spongycastle/crypto/ec/CustomNamedCurves;->getByName(Ljava/lang/String;)Lorg/spongycastle/asn1/x9/X9ECParameters;

    move-result-object v0

    sput-object v0, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE_PARAMS:Lorg/spongycastle/asn1/x9/X9ECParameters;

    .line 30
    new-instance v0, Lorg/spongycastle/crypto/params/ECDomainParameters;

    sget-object v1, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE_PARAMS:Lorg/spongycastle/asn1/x9/X9ECParameters;

    .line 31
    invoke-virtual {v1}, Lorg/spongycastle/asn1/x9/X9ECParameters;->getCurve()Lorg/spongycastle/math/ec/ECCurve;

    move-result-object v1

    sget-object v2, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE_PARAMS:Lorg/spongycastle/asn1/x9/X9ECParameters;

    invoke-virtual {v2}, Lorg/spongycastle/asn1/x9/X9ECParameters;->getG()Lorg/spongycastle/math/ec/ECPoint;

    move-result-object v2

    sget-object v3, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE_PARAMS:Lorg/spongycastle/asn1/x9/X9ECParameters;

    invoke-virtual {v3}, Lorg/spongycastle/asn1/x9/X9ECParameters;->getN()Ljava/math/BigInteger;

    move-result-object v3

    sget-object v4, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE_PARAMS:Lorg/spongycastle/asn1/x9/X9ECParameters;

    invoke-virtual {v4}, Lorg/spongycastle/asn1/x9/X9ECParameters;->getH()Ljava/math/BigInteger;

    move-result-object v4

    invoke-direct {v0, v1, v2, v3, v4}, Lorg/spongycastle/crypto/params/ECDomainParameters;-><init>(Lorg/spongycastle/math/ec/ECCurve;Lorg/spongycastle/math/ec/ECPoint;Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    sput-object v0, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE:Lorg/spongycastle/crypto/params/ECDomainParameters;

    .line 32
    sget-object v0, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE_PARAMS:Lorg/spongycastle/asn1/x9/X9ECParameters;

    invoke-virtual {v0}, Lorg/spongycastle/asn1/x9/X9ECParameters;->getN()Ljava/math/BigInteger;

    move-result-object v0

    const/4 v1, 0x1

    invoke-virtual {v0, v1}, Ljava/math/BigInteger;->shiftRight(I)Ljava/math/BigInteger;

    return-void
.end method

.method public static a([BLorg/web3j/crypto/ECKeyPair;Z)Lorg/web3j/crypto/Sign$SignatureData;
    .registers 13

    .prologue
    .line 35
    invoke-virtual {p1}, Lorg/web3j/crypto/ECKeyPair;->getPublicKey()Ljava/math/BigInteger;

    move-result-object v3

    .line 38
    if-eqz p2, :cond_a

    .line 39
    invoke-static {p0}, Lorg/web3j/crypto/Hash;->sha3([B)[B

    move-result-object p0

    .line 42
    :cond_a
    invoke-virtual {p1, p0}, Lorg/web3j/crypto/ECKeyPair;->sign([B)Lorg/web3j/crypto/ECDSASignature;

    move-result-object v4

    .line 44
    const/4 v2, -0x1

    .line 45
    const/4 v1, 0x0

    :goto_10
    const/4 v0, 0x4

    if-ge v1, v0, :cond_11a

    .line 1090
    if-ltz v1, :cond_74

    const/4 v0, 0x1

    :goto_16
    const-string v5, "recId must be positive"

    invoke-static {v0, v5}, Lorg/web3j/utils/Assertions;->verifyPrecondition(ZLjava/lang/String;)V

    .line 1091
    iget-object v0, v4, Lorg/web3j/crypto/ECDSASignature;->r:Ljava/math/BigInteger;

    invoke-virtual {v0}, Ljava/math/BigInteger;->signum()I

    move-result v0

    if-ltz v0, :cond_76

    const/4 v0, 0x1

    :goto_24
    const-string v5, "r must be positive"

    invoke-static {v0, v5}, Lorg/web3j/utils/Assertions;->verifyPrecondition(ZLjava/lang/String;)V

    .line 1092
    iget-object v0, v4, Lorg/web3j/crypto/ECDSASignature;->s:Ljava/math/BigInteger;

    invoke-virtual {v0}, Ljava/math/BigInteger;->signum()I

    move-result v0

    if-ltz v0, :cond_78

    const/4 v0, 0x1

    :goto_32
    const-string v5, "s must be positive"

    invoke-static {v0, v5}, Lorg/web3j/utils/Assertions;->verifyPrecondition(ZLjava/lang/String;)V

    .line 1093
    if-eqz p0, :cond_7a

    const/4 v0, 0x1

    :goto_3a
    const-string v5, "message cannot be null"

    invoke-static {v0, v5}, Lorg/web3j/utils/Assertions;->verifyPrecondition(ZLjava/lang/String;)V

    .line 1097
    sget-object v0, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE:Lorg/spongycastle/crypto/params/ECDomainParameters;

    invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getN()Ljava/math/BigInteger;

    move-result-object v5

    .line 1098
    int-to-long v6, v1

    const-wide/16 v8, 0x2

    div-long/2addr v6, v8

    invoke-static {v6, v7}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;

    move-result-object v0

    .line 1099
    iget-object v6, v4, Lorg/web3j/crypto/ECDSASignature;->r:Ljava/math/BigInteger;

    invoke-virtual {v0, v5}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v0

    invoke-virtual {v6, v0}, Ljava/math/BigInteger;->add(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v6

    .line 1107
    sget-object v0, Lorg/spongycastle/math/ec/custom/sec/SecP256K1Curve;->q:Ljava/math/BigInteger;

    .line 1108
    invoke-virtual {v6, v0}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I

    move-result v0

    if-ltz v0, :cond_7c

    .line 1110
    const/4 v0, 0x0

    .line 47
    :goto_60
    if-eqz v0, :cond_fd

    invoke-virtual {v0, v3}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_fd

    move v0, v1

    .line 52
    :goto_69
    const/4 v1, -0x1

    if-ne v0, v1, :cond_101

    .line 53
    new-instance v0, Ljava/lang/RuntimeException;

    const-string v1, "Could not construct a recoverable key. This should never happen."

    invoke-direct {v0, v1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 1090
    :cond_74
    const/4 v0, 0x0

    goto :goto_16

    .line 1091
    :cond_76
    const/4 v0, 0x0

    goto :goto_24

    .line 1092
    :cond_78
    const/4 v0, 0x0

    goto :goto_32

    .line 1093
    :cond_7a
    const/4 v0, 0x0

    goto :goto_3a

    .line 1114
    :cond_7c
    and-int/lit8 v0, v1, 0x1

    const/4 v7, 0x1

    if-ne v0, v7, :cond_b4

    const/4 v0, 0x1

    .line 1149
    :goto_82
    new-instance v7, Lorg/spongycastle/asn1/x9/X9IntegerConverter;

    invoke-direct {v7}, Lorg/spongycastle/asn1/x9/X9IntegerConverter;-><init>()V

    .line 1150
    sget-object v8, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE:Lorg/spongycastle/crypto/params/ECDomainParameters;

    invoke-virtual {v8}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getCurve()Lorg/spongycastle/math/ec/ECCurve;

    move-result-object v8

    invoke-virtual {v7, v8}, Lorg/spongycastle/asn1/x9/X9IntegerConverter;->getByteLength(Lorg/spongycastle/math/ec/ECCurve;)I

    move-result v8

    add-int/lit8 v8, v8, 0x1

    invoke-virtual {v7, v6, v8}, Lorg/spongycastle/asn1/x9/X9IntegerConverter;->integerToBytes(Ljava/math/BigInteger;I)[B

    move-result-object v6

    .line 1151
    const/4 v7, 0x0

    if-eqz v0, :cond_b6

    const/4 v0, 0x3

    :goto_9b
    int-to-byte v0, v0

    aput-byte v0, v6, v7

    .line 1152
    sget-object v0, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE:Lorg/spongycastle/crypto/params/ECDomainParameters;

    invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getCurve()Lorg/spongycastle/math/ec/ECCurve;

    move-result-object v0

    invoke-virtual {v0, v6}, Lorg/spongycastle/math/ec/ECCurve;->decodePoint([B)Lorg/spongycastle/math/ec/ECPoint;

    move-result-object v0

    .line 1117
    invoke-virtual {v0, v5}, Lorg/spongycastle/math/ec/ECPoint;->multiply(Ljava/math/BigInteger;)Lorg/spongycastle/math/ec/ECPoint;

    move-result-object v6

    invoke-virtual {v6}, Lorg/spongycastle/math/ec/ECPoint;->isInfinity()Z

    move-result v6

    if-nez v6, :cond_b8

    .line 1118
    const/4 v0, 0x0

    goto :goto_60

    .line 1114
    :cond_b4
    const/4 v0, 0x0

    goto :goto_82

    .line 1151
    :cond_b6
    const/4 v0, 0x2

    goto :goto_9b

    .line 1121
    :cond_b8
    new-instance v6, Ljava/math/BigInteger;

    const/4 v7, 0x1

    invoke-direct {v6, v7, p0}, Ljava/math/BigInteger;-><init>(I[B)V

    .line 1136
    sget-object v7, Ljava/math/BigInteger;->ZERO:Ljava/math/BigInteger;

    invoke-virtual {v7, v6}, Ljava/math/BigInteger;->subtract(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v6

    invoke-virtual {v6, v5}, Ljava/math/BigInteger;->mod(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v6

    .line 1137
    iget-object v7, v4, Lorg/web3j/crypto/ECDSASignature;->r:Ljava/math/BigInteger;

    invoke-virtual {v7, v5}, Ljava/math/BigInteger;->modInverse(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v7

    .line 1138
    iget-object v8, v4, Lorg/web3j/crypto/ECDSASignature;->s:Ljava/math/BigInteger;

    invoke-virtual {v7, v8}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v8

    invoke-virtual {v8, v5}, Ljava/math/BigInteger;->mod(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v8

    .line 1139
    invoke-virtual {v7, v6}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v6

    invoke-virtual {v6, v5}, Ljava/math/BigInteger;->mod(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v5

    .line 1140
    sget-object v6, Lcom/cmcm/safewallet/data/dapp/a/a;->CURVE:Lorg/spongycastle/crypto/params/ECDomainParameters;

    invoke-virtual {v6}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getG()Lorg/spongycastle/math/ec/ECPoint;

    move-result-object v6

    invoke-static {v6, v5, v0, v8}, Lorg/spongycastle/math/ec/ECAlgorithms;->sumOfTwoMultiplies(Lorg/spongycastle/math/ec/ECPoint;Ljava/math/BigInteger;Lorg/spongycastle/math/ec/ECPoint;Ljava/math/BigInteger;)Lorg/spongycastle/math/ec/ECPoint;

    move-result-object v0

    .line 1142
    const/4 v5, 0x0

    invoke-virtual {v0, v5}, Lorg/spongycastle/math/ec/ECPoint;->getEncoded(Z)[B

    move-result-object v5

    .line 1144
    new-instance v0, Ljava/math/BigInteger;

    const/4 v6, 0x1

    const/4 v7, 0x1

    array-length v8, v5

    invoke-static {v5, v7, v8}, Ljava/util/Arrays;->copyOfRange([BII)[B

    move-result-object v5

    invoke-direct {v0, v6, v5}, Ljava/math/BigInteger;-><init>(I[B)V

    goto/16 :goto_60

    .line 45
    :cond_fd
    add-int/lit8 v1, v1, 0x1

    goto/16 :goto_10

    .line 57
    :cond_101
    add-int/lit8 v0, v0, 0x1b

    .line 60
    int-to-byte v0, v0

    .line 61
    iget-object v1, v4, Lorg/web3j/crypto/ECDSASignature;->r:Ljava/math/BigInteger;

    const/16 v2, 0x20

    invoke-static {v1, v2}, Lorg/web3j/utils/Numeric;->toBytesPadded(Ljava/math/BigInteger;I)[B

    move-result-object v1

    .line 62
    iget-object v2, v4, Lorg/web3j/crypto/ECDSASignature;->s:Ljava/math/BigInteger;

    const/16 v3, 0x20

    invoke-static {v2, v3}, Lorg/web3j/utils/Numeric;->toBytesPadded(Ljava/math/BigInteger;I)[B

    move-result-object v2

    .line 64
    new-instance v3, Lorg/web3j/crypto/Sign$SignatureData;

    invoke-direct {v3, v0, v1, v2}, Lorg/web3j/crypto/Sign$SignatureData;-><init>(B[B[B)V

    return-object v3

    :cond_11a
    move v0, v2

    goto/16 :goto_69
.end method