ECKeyPair.smali

.class public Lorg/web3j/crypto/ECKeyPair;
.super Ljava/lang/Object;
.source "ECKeyPair.java"


# instance fields
.field private final privateKey:Ljava/math/BigInteger;

.field private final publicKey:Ljava/math/BigInteger;


# direct methods
.method public constructor <init>(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
    .registers 3

    .prologue
    .line 23
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 24
    iput-object p1, p0, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

    .line 25
    iput-object p2, p0, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

    .line 26
    return-void
.end method

.method public static create(Ljava/math/BigInteger;)Lorg/web3j/crypto/ECKeyPair;
    .registers 3

    .prologue
    .line 68
    new-instance v0, Lorg/web3j/crypto/ECKeyPair;

    invoke-static {p0}, Lorg/web3j/crypto/Sign;->publicKeyFromPrivate(Ljava/math/BigInteger;)Ljava/math/BigInteger;

    move-result-object v1

    invoke-direct {v0, p0, v1}, Lorg/web3j/crypto/ECKeyPair;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    return-object v0
.end method

.method public static create(Ljava/security/KeyPair;)Lorg/web3j/crypto/ECKeyPair;
    .registers 6

    .prologue
    const/4 v4, 0x1

    .line 52
    invoke-virtual {p0}, Ljava/security/KeyPair;->getPrivate()Ljava/security/PrivateKey;

    move-result-object v0

    check-cast v0, Lorg/spongycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey;

    .line 53
    invoke-virtual {p0}, Ljava/security/KeyPair;->getPublic()Ljava/security/PublicKey;

    move-result-object v1

    check-cast v1, Lorg/spongycastle/jcajce/provider/asymmetric/ec/BCECPublicKey;

    .line 55
    invoke-virtual {v0}, Lorg/spongycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey;->getD()Ljava/math/BigInteger;

    move-result-object v0

    .line 60
    invoke-virtual {v1}, Lorg/spongycastle/jcajce/provider/asymmetric/ec/BCECPublicKey;->getQ()Lorg/spongycastle/math/ec/ECPoint;

    move-result-object v1

    const/4 v2, 0x0

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

    move-result-object v1

    .line 61
    new-instance v2, Ljava/math/BigInteger;

    array-length v3, v1

    invoke-static {v1, v4, v3}, Ljava/util/Arrays;->copyOfRange([BII)[B

    move-result-object v1

    invoke-direct {v2, v4, v1}, Ljava/math/BigInteger;-><init>(I[B)V

    .line 64
    new-instance v1, Lorg/web3j/crypto/ECKeyPair;

    invoke-direct {v1, v0, v2}, Lorg/web3j/crypto/ECKeyPair;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    return-object v1
.end method

.method public static create([B)Lorg/web3j/crypto/ECKeyPair;
    .registers 2

    .prologue
    .line 72
    invoke-static {p0}, Lorg/web3j/utils/Numeric;->toBigInt([B)Ljava/math/BigInteger;

    move-result-object v0

    invoke-static {v0}, Lorg/web3j/crypto/ECKeyPair;->create(Ljava/math/BigInteger;)Lorg/web3j/crypto/ECKeyPair;

    move-result-object v0

    return-object v0
.end method


# virtual methods
.method public equals(Ljava/lang/Object;)Z
    .registers 6

    .prologue
    const/4 v0, 0x1

    const/4 v1, 0x0

    .line 77
    if-ne p0, p1, :cond_5

    .line 91
    :cond_4
    :goto_4
    return v0

    .line 80
    :cond_5
    if-eqz p1, :cond_11

    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v2

    invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v3

    if-eq v2, v3, :cond_13

    :cond_11
    move v0, v1

    .line 81
    goto :goto_4

    .line 84
    :cond_13
    check-cast p1, Lorg/web3j/crypto/ECKeyPair;

    .line 86
    iget-object v2, p0, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

    if-eqz v2, :cond_25

    iget-object v2, p0, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

    iget-object v3, p1, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

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

    move-result v2

    if-nez v2, :cond_29

    :cond_23
    move v0, v1

    .line 88
    goto :goto_4

    .line 86
    :cond_25
    iget-object v2, p1, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

    if-nez v2, :cond_23

    .line 91
    :cond_29
    iget-object v2, p0, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

    if-eqz v2, :cond_36

    iget-object v0, p0, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

    iget-object v1, p1, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

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

    move-result v0

    goto :goto_4

    :cond_36
    iget-object v2, p1, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

    if-eqz v2, :cond_4

    move v0, v1

    goto :goto_4
.end method

.method public getPrivateKey()Ljava/math/BigInteger;
    .registers 2

    .prologue
    .line 29
    iget-object v0, p0, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

    return-object v0
.end method

.method public getPublicKey()Ljava/math/BigInteger;
    .registers 2

    .prologue
    .line 33
    iget-object v0, p0, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

    return-object v0
.end method

.method public hashCode()I
    .registers 4

    .prologue
    const/4 v1, 0x0

    .line 97
    iget-object v0, p0, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

    if-eqz v0, :cond_19

    iget-object v0, p0, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

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

    move-result v0

    .line 98
    :goto_b
    mul-int/lit8 v0, v0, 0x1f

    iget-object v2, p0, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

    if-eqz v2, :cond_17

    iget-object v1, p0, Lorg/web3j/crypto/ECKeyPair;->publicKey:Ljava/math/BigInteger;

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

    move-result v1

    :cond_17
    add-int/2addr v0, v1

    .line 99
    return v0

    :cond_19
    move v0, v1

    .line 97
    goto :goto_b
.end method

.method public sign([B)Lorg/web3j/crypto/ECDSASignature;
    .registers 7

    .prologue
    const/4 v4, 0x1

    .line 42
    new-instance v0, Lorg/spongycastle/crypto/signers/ECDSASigner;

    new-instance v1, Lorg/spongycastle/crypto/signers/HMacDSAKCalculator;

    new-instance v2, Lorg/spongycastle/crypto/digests/SHA256Digest;

    invoke-direct {v2}, Lorg/spongycastle/crypto/digests/SHA256Digest;-><init>()V

    invoke-direct {v1, v2}, Lorg/spongycastle/crypto/signers/HMacDSAKCalculator;-><init>(Lorg/spongycastle/crypto/Digest;)V

    invoke-direct {v0, v1}, Lorg/spongycastle/crypto/signers/ECDSASigner;-><init>(Lorg/spongycastle/crypto/signers/DSAKCalculator;)V

    .line 44
    new-instance v1, Lorg/spongycastle/crypto/params/ECPrivateKeyParameters;

    iget-object v2, p0, Lorg/web3j/crypto/ECKeyPair;->privateKey:Ljava/math/BigInteger;

    sget-object v3, Lorg/web3j/crypto/Sign;->CURVE:Lorg/spongycastle/crypto/params/ECDomainParameters;

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

    .line 45
    invoke-virtual {v0, v4, v1}, Lorg/spongycastle/crypto/signers/ECDSASigner;->init(ZLorg/spongycastle/crypto/CipherParameters;)V

    .line 46
    invoke-virtual {v0, p1}, Lorg/spongycastle/crypto/signers/ECDSASigner;->generateSignature([B)[Ljava/math/BigInteger;

    move-result-object v0

    .line 48
    new-instance v1, Lorg/web3j/crypto/ECDSASignature;

    const/4 v2, 0x0

    aget-object v2, v0, v2

    aget-object v0, v0, v4

    invoke-direct {v1, v2, v0}, Lorg/web3j/crypto/ECDSASignature;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    invoke-virtual {v1}, Lorg/web3j/crypto/ECDSASignature;->toCanonicalised()Lorg/web3j/crypto/ECDSASignature;

    move-result-object v0

    return-object v0
.end method