Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
rename verifyingkey to publickey
Browse files Browse the repository at this point in the history
  • Loading branch information
Synesso committed Mar 7, 2018
1 parent 1e2d605 commit e2781e2
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 71 deletions.
8 changes: 4 additions & 4 deletions src/it/scala/stellar/sdk/DomainMatchersIT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package stellar.sdk

import org.apache.commons.codec.binary.Hex
import org.specs2.matcher.{AnyMatchers, Matcher, MustExpectations, OptionMatchers, SequenceMatchersCreation}
import org.stellar.sdk.xdr.{DecoratedSignature, Hash, PublicKey, SignerKey, Uint64, Memo => XDRMemo, Operation => XDROperation}
import org.stellar.sdk.xdr.{DecoratedSignature, Hash, PublicKey => XDRPublicKey, SignerKey, Uint64, Memo => XDRMemo, Operation => XDROperation}
import stellar.sdk.op._

trait DomainMatchersIT extends AnyMatchers with MustExpectations with SequenceMatchersCreation with OptionMatchers {
Expand Down Expand Up @@ -41,8 +41,8 @@ trait DomainMatchersIT extends AnyMatchers with MustExpectations with SequenceMa
signer.getEd25519.getUint256.toSeq mustEqual other.getEd25519.getUint256.toSeq
}

def beEquivalentTo(other: VerifyingKey): Matcher[VerifyingKey] = beLike[VerifyingKey] {
case VerifyingKey(pk) =>
def beEquivalentTo(other: PublicKey): Matcher[PublicKey] = beLike[PublicKey] {
case PublicKey(pk) =>
Hex.encodeHex(pk.getAbyte) mustEqual Hex.encodeHex(other.pk.getAbyte)
}

Expand All @@ -67,7 +67,7 @@ trait DomainMatchersIT extends AnyMatchers with MustExpectations with SequenceMa
memo.getText mustEqual other.getText
}

def beEquivalentTo(other: PublicKey): Matcher[PublicKey] = beLike[PublicKey] {
def beEquivalentTo(other: XDRPublicKey): Matcher[XDRPublicKey] = beLike[XDRPublicKey] {
case pk =>
pk.getDiscriminant mustEqual other.getDiscriminant
pk.getEd25519.getUint256.toSeq mustEqual other.getEd25519.getUint256.toSeq
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/stellar/sdk/Asset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ case object NativeAsset extends Asset {

trait NonNativeAsset extends Asset {
val code: String
val issuer: VerifyingKey
val issuer: PublicKey
val typeString: String
}

Expand All @@ -48,7 +48,7 @@ trait NonNativeAsset extends Asset {
*
* @see <a href="https://www.stellar.org/developers/learn/concepts/assets.html" target="_blank">Assets</a>
*/
case class AssetTypeCreditAlphaNum4(code: String, issuer: VerifyingKey) extends NonNativeAsset {
case class AssetTypeCreditAlphaNum4(code: String, issuer: PublicKey) extends NonNativeAsset {
assert(code.nonEmpty, s"Asset's code '$code' cannot be empty")
assert(code.length <= 4, s"Asset's code '$code' should have length no greater than 4")

Expand All @@ -69,7 +69,7 @@ case class AssetTypeCreditAlphaNum4(code: String, issuer: VerifyingKey) extends

object AssetTypeCreditAlphaNum4 {
def apply(code: String, keyPair: PublicKeyOps): AssetTypeCreditAlphaNum4 =
AssetTypeCreditAlphaNum4(code, keyPair.asVerifyingKey)
AssetTypeCreditAlphaNum4(code, keyPair.asPublicKey)
}


Expand All @@ -78,7 +78,7 @@ object AssetTypeCreditAlphaNum4 {
*
* @see <a href="https://www.stellar.org/developers/learn/concepts/assets.html" target="_blank">Assets</a>
*/
case class AssetTypeCreditAlphaNum12(code: String, issuer: VerifyingKey) extends NonNativeAsset {
case class AssetTypeCreditAlphaNum12(code: String, issuer: PublicKey) extends NonNativeAsset {
assert(code.length >= 5 && code.length <= 12, s"Asset's code '$code' should have length between 5 & 12 inclusive")

override def toXDR: XDRAsset = {
Expand All @@ -98,5 +98,5 @@ case class AssetTypeCreditAlphaNum12(code: String, issuer: VerifyingKey) extends

object AssetTypeCreditAlphaNum12 {
def apply(code: String, keyPair: PublicKeyOps): AssetTypeCreditAlphaNum12 =
AssetTypeCreditAlphaNum12(code, keyPair.asVerifyingKey)
AssetTypeCreditAlphaNum12(code, keyPair.asPublicKey)
}
28 changes: 14 additions & 14 deletions src/main/scala/stellar/sdk/KeyPair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util

import net.i2p.crypto.eddsa._
import net.i2p.crypto.eddsa.spec._
import org.stellar.sdk.xdr._
import org.stellar.sdk.xdr.{PublicKey => XDRPublicKey, _}

import scala.util.Try

Expand Down Expand Up @@ -54,7 +54,7 @@ case class KeyPair(pk: EdDSAPublicKey, sk: EdDSAPrivateKey) extends PublicKeyOps
}
}

case class VerifyingKey(pk: EdDSAPublicKey) extends PublicKeyOps {
case class PublicKey(pk: EdDSAPublicKey) extends PublicKeyOps {

override def hashCode(): Int = accountId.hashCode()

Expand All @@ -63,7 +63,7 @@ case class VerifyingKey(pk: EdDSAPublicKey) extends PublicKeyOps {
case _ => false
}

override def toString: String = s"VerifyingKey($accountId)"
override def toString: String = s"PublicKey($accountId)"

}

Expand Down Expand Up @@ -93,8 +93,8 @@ trait PublicKeyOps {
case _: SignatureException => false
}.get

def getXDRPublicKey: PublicKey = {
val publicKey = new PublicKey
def getXDRPublicKey: XDRPublicKey = {
val publicKey = new XDRPublicKey
publicKey.setDiscriminant(PublicKeyType.PUBLIC_KEY_TYPE_ED25519)
val uint256 = new Uint256
uint256.setUint256(pk.getAbyte)
Expand All @@ -114,7 +114,7 @@ trait PublicKeyOps {
/**
* This key pair or verifying key without the private key.
*/
def asVerifyingKey = VerifyingKey(pk)
def asPublicKey = PublicKey(pk)


/**
Expand All @@ -123,7 +123,7 @@ trait PublicKeyOps {
val signatureHint: Try[SignatureHint] = Try {
val pkStream = new ByteArrayOutputStream
val os = new XdrDataOutputStream(pkStream)
PublicKey.encode(os, getXDRPublicKey)
XDRPublicKey.encode(os, getXDRPublicKey)
val pkBytes = pkStream.toByteArray
val hintBytes = util.Arrays.copyOfRange(pkBytes, pkBytes.length - 4, pkBytes.length)
val hint = new SignatureHint
Expand Down Expand Up @@ -181,21 +181,21 @@ object KeyPair {
* Creates a new Stellar verifying key from a 32 byte address.
*
* @param publicKey The 32 byte public key.
* @return { @link VerifyingKey}
* @return { @link PublicKey }
*/
def fromPublicKey(publicKey: Array[Byte]): VerifyingKey = {
VerifyingKey(new EdDSAPublicKey(new EdDSAPublicKeySpec(publicKey, ed25519)))
def fromPublicKey(publicKey: Array[Byte]): PublicKey = {
PublicKey(new EdDSAPublicKey(new EdDSAPublicKeySpec(publicKey, ed25519)))
}

/**
* Creates a new Stellar VerifyingKey from a strkey encoded Stellar account ID.
* Creates a new Stellar PublicKey from a strkey encoded Stellar account ID.
*
* @param accountId The strkey encoded Stellar account ID.
* @return { @link VerifyingKey}
* @return { @link PublicKey}
*/
def fromAccountId(accountId: String): VerifyingKey = fromPublicKey(StrKey.decodeStellarAccountId(accountId))
def fromAccountId(accountId: String): PublicKey = fromPublicKey(StrKey.decodeStellarAccountId(accountId))

def fromXDRPublicKey(key: PublicKey) = fromPublicKey(key.getEd25519.getUint256)
def fromXDRPublicKey(key: XDRPublicKey) = fromPublicKey(key.getEd25519.getUint256)

/**
* Generates a random Stellar keypair.
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/stellar/sdk/op/AllowTrustOperation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import org.stellar.sdk.xdr.Operation.OperationBody
import org.stellar.sdk.xdr.OperationType._
import org.stellar.sdk.xdr.{AccountID, AllowTrustOp}
import stellar.sdk._
import stellar.sdk.{ByteArrays, KeyPair, VerifyingKey}
import stellar.sdk.{ByteArrays, KeyPair, PublicKey}

import scala.util.Try

case class AllowTrustOperation(trustor: VerifyingKey,
case class AllowTrustOperation(trustor: PublicKey,
assetCode: String,
authorize: Boolean,
sourceAccount: Option[PublicKeyOps] = None) extends Operation with ByteArrays {
Expand Down
46 changes: 23 additions & 23 deletions src/test/scala/stellar/sdk/ArbitraryInput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait ArbitraryInput extends ScalaCheck {

implicit def arbKeyPair: Arbitrary[KeyPair] = Arbitrary(genKeyPair)

implicit def arbVerifyingKey: Arbitrary[VerifyingKey] = Arbitrary(genVerifyingKey)
implicit def arbPublicKey: Arbitrary[PublicKey] = Arbitrary(genPublicKey)

implicit def arbAccount: Arbitrary[Account] = Arbitrary(genAccount)

Expand All @@ -34,25 +34,25 @@ trait ArbitraryInput extends ScalaCheck {
implicit def arbNonNativeAsset: Arbitrary[NonNativeAsset] = Arbitrary(genNonNativeAsset)

implicit def arbAccountMergeOperation: Arbitrary[AccountMergeOperation] = Arbitrary(genAccountMergeOperation)

implicit def arbAllowTrustOperation: Arbitrary[AllowTrustOperation] = Arbitrary(genAllowTrustOperation)

implicit def arbChangeTrustOperation: Arbitrary[ChangeTrustOperation] = Arbitrary(genChangeTrustOperation)

implicit def arbCreateAccountOperation: Arbitrary[CreateAccountOperation] = Arbitrary(genCreateAccountOperation)

implicit def arbCreatePassiveOfferOperation: Arbitrary[CreatePassiveOfferOperation] = Arbitrary(genCreatePassiveOfferOperation)

implicit def arbWriteDataOperation: Arbitrary[WriteDataOperation] = Arbitrary(genWriteDataOperation)

implicit def arbDeleteDataOperation: Arbitrary[DeleteDataOperation] = Arbitrary(genDeleteDataOperation)

implicit def arbCreateOfferOperation: Arbitrary[CreateOfferOperation] = Arbitrary(genCreateOfferOperation)

implicit def arbDeleteOfferOperation: Arbitrary[DeleteOfferOperation] = Arbitrary(genDeleteOfferOperation)

implicit def arbUpdateOfferOperation: Arbitrary[UpdateOfferOperation] = Arbitrary(genUpdateOfferOperation)

implicit def arbPathPaymentOperation: Arbitrary[PathPaymentOperation] = Arbitrary(genPathPaymentOperation)

implicit def arbPaymentOperation: Arbitrary[PaymentOperation] = Arbitrary(genPaymentOperation)
Expand Down Expand Up @@ -87,7 +87,7 @@ trait ArbitraryInput extends ScalaCheck {

def genSignerKey: Gen[SignerKey] = genKeyPair.map(_.getXDRSignerKey)

def genVerifyingKey: Gen[VerifyingKey] = genKeyPair.map(kp => VerifyingKey(kp.pk))
def genPublicKey: Gen[PublicKey] = genKeyPair.map(kp => PublicKey(kp.pk))

def genAccount: Gen[Account] = for {
kp <- genKeyPair
Expand Down Expand Up @@ -145,11 +145,11 @@ trait ArbitraryInput extends ScalaCheck {
Gen.oneOf(AuthorizationRequiredFlag, AuthorizationRevocableFlag, AuthorizationImmutableFlag)

def genAccountMergeOperation: Gen[AccountMergeOperation] = for {
destination <- genVerifyingKey
destination <- genPublicKey
} yield AccountMergeOperation(destination)

def genAllowTrustOperation = for {
trustor <- genVerifyingKey
trustor <- genPublicKey
assetCode <- Gen.identifier.map(_.take(12))
authorise <- Gen.oneOf(true, false)
} yield AllowTrustOperation(trustor, assetCode, authorise)
Expand All @@ -159,7 +159,7 @@ trait ArbitraryInput extends ScalaCheck {
} yield ChangeTrustOperation(limit)

def genCreateAccountOperation = for {
destination <- genVerifyingKey
destination <- genPublicKey
startingBalance <- genNativeAmount
} yield CreateAccountOperation(destination, startingBalance)

Expand Down Expand Up @@ -206,18 +206,18 @@ trait ArbitraryInput extends ScalaCheck {

def genPathPaymentOperation = for {
sendMax <- genAmount
destAccount <- genVerifyingKey
destAccount <- genPublicKey
destAmount <- genAmount
path <- Gen.listOf(genAsset)
} yield PathPaymentOperation(sendMax, destAccount, destAmount, path)

def genPaymentOperation = for {
destAccount <- genVerifyingKey
destAccount <- genPublicKey
amount <- genAmount
} yield PaymentOperation(destAccount, amount)

def genSetOptionsOperation: Gen[SetOptionsOperation] = for {
inflationDestination <- Gen.option(genVerifyingKey)
inflationDestination <- Gen.option(genPublicKey)
clearFlags <- Gen.option(Gen.nonEmptyContainerOf[Set, IssuerFlag](genIssuerFlag))
setFlags <- Gen.option(Gen.nonEmptyContainerOf[Set, IssuerFlag](genIssuerFlag))
masterKeyWeight <- Gen.option(Gen.choose(0, 255))
Expand All @@ -226,7 +226,7 @@ trait ArbitraryInput extends ScalaCheck {
highThreshold <- Gen.option(Gen.choose(0, 255))
homeDomain <- Gen.option(Gen.identifier)
signer <- Gen.option{ for {
accn <- genVerifyingKey
accn <- genPublicKey
weight <- Gen.choose(0, 255)
} yield AccountSigner(accn, weight)}
} yield SetOptionsOperation(inflationDestination, clearFlags, setFlags, masterKeyWeight, lowThreshold, medThreshold,
Expand Down Expand Up @@ -309,7 +309,7 @@ trait ArbitraryInput extends ScalaCheck {

def genOfferResp: Gen[OfferResp] = for {
id <- Gen.posNum[Long]
seller <- genVerifyingKey
seller <- genPublicKey
selling <- genAmount
buying <- genAsset
price <- genPrice
Expand All @@ -318,7 +318,7 @@ trait ArbitraryInput extends ScalaCheck {
def genTransacted[O <: Operation](genOp: Gen[O]): Gen[Transacted[O]] = for {
id <- Gen.posNum[Long]
hash <- genHash
source <- genVerifyingKey
source <- genPublicKey
createdAt <- genZonedDateTime
op <- genOp
} yield Transacted(id, hash, source, createdAt, op)
Expand All @@ -341,9 +341,9 @@ trait ArbitraryInput extends ScalaCheck {
id <- Gen.identifier
ledgerCloseTime <- genZonedDateTime
offerId <- Gen.posNum[Long]
baseAccount <- genVerifyingKey
baseAccount <- genPublicKey
baseAmount <- genAmount
counterAccount <- genVerifyingKey
counterAccount <- genPublicKey
counterAmount <- genAmount
baseIsSeller <- Gen.oneOf(true, false)
} yield Trade(id, ledgerCloseTime, offerId, baseAccount, baseAmount, counterAccount, counterAmount, baseIsSeller)
Expand Down
8 changes: 4 additions & 4 deletions src/test/scala/stellar/sdk/DomainMatchers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.time.format.DateTimeFormatter

import org.apache.commons.codec.binary.Hex
import org.specs2.matcher.{AnyMatchers, Matcher, MustExpectations, OptionMatchers, SequenceMatchersCreation}
import org.stellar.sdk.xdr.{DecoratedSignature, Hash, PublicKey, SignerKey, Uint64, Memo => XDRMemo, Operation => XDROperation}
import org.stellar.sdk.xdr.{DecoratedSignature, Hash, PublicKey => XDRPublicKey, SignerKey, Uint64, Memo => XDRMemo, Operation => XDROperation}
import stellar.sdk._
import stellar.sdk.op._

Expand Down Expand Up @@ -45,8 +45,8 @@ trait DomainMatchers extends AnyMatchers with MustExpectations with SequenceMatc
signer.getEd25519.getUint256.toSeq mustEqual other.getEd25519.getUint256.toSeq
}

def beEquivalentTo(other: VerifyingKey): Matcher[VerifyingKey] = beLike[VerifyingKey] {
case VerifyingKey(pk) =>
def beEquivalentTo(other: PublicKey): Matcher[PublicKey] = beLike[PublicKey] {
case PublicKey(pk) =>
Hex.encodeHex(pk.getAbyte) mustEqual Hex.encodeHex(other.pk.getAbyte)
}

Expand All @@ -71,7 +71,7 @@ trait DomainMatchers extends AnyMatchers with MustExpectations with SequenceMatc
memo.getText mustEqual other.getText
}

def beEquivalentTo(other: PublicKey): Matcher[PublicKey] = beLike[PublicKey] {
def beEquivalentTo(other: XDRPublicKey): Matcher[XDRPublicKey] = beLike[XDRPublicKey] {
case pk =>
pk.getDiscriminant mustEqual other.getDiscriminant
pk.getEd25519.getUint256.toSeq mustEqual other.getEd25519.getUint256.toSeq
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/stellar/sdk/KeyPairSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class KeyPairSpec extends Specification with ArbitraryInput with DomainMatchers
"report its account id and secret seed and be reconstituted from these" >> prop { kp: KeyPair =>
kp.accountId.toCharArray must haveLength(56)
kp.accountId must startWith("G")
KeyPair.fromPublicKey(kp.publicKey) must beEquivalentTo(kp.asVerifyingKey)
KeyPair.fromPublicKey(kp.publicKey) must beEquivalentTo(kp.asPublicKey)
KeyPair.fromSecretSeed(kp.secretSeed) must beEquivalentTo(kp)
KeyPair.fromSecretSeed(kp.secretSeed.mkString) must beEquivalentTo(kp)
KeyPair.fromAccountId(kp.accountId) must beEquivalentTo(kp.asVerifyingKey)
KeyPair.fromAccountId(kp.accountId) must beEquivalentTo(kp.asPublicKey)
}
}
}
Loading

0 comments on commit e2781e2

Please sign in to comment.