From 002394c1237d958a6aab7dd31228afc466b42012 Mon Sep 17 00:00:00 2001 From: recanman <29310982+recanman@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:59:09 -0700 Subject: [PATCH] test: ed25519 public key --- src/Ed25519.php | 9 +++++++++ tests/unit/Ed25519Test.php | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Ed25519.php b/src/Ed25519.php index d324f11..a1fc68a 100644 --- a/src/Ed25519.php +++ b/src/Ed25519.php @@ -259,6 +259,15 @@ public function Hint(mixed $m, bool $asBigInt = false): BigInteger|string return $asBigInt ? $res : $res->toDec(); } + /** + * Determines the public key from a secret key. + */ + public function publickey(BigInteger $sk): string + { + return $this->encodePoint($this->scalarmult($this->B, $sk)); + } + + /** * Determines if a point is on the Edwards25519 curve. */ diff --git a/tests/unit/Ed25519Test.php b/tests/unit/Ed25519Test.php index d0a285c..ce48870 100644 --- a/tests/unit/Ed25519Test.php +++ b/tests/unit/Ed25519Test.php @@ -25,6 +25,9 @@ class Ed25519Test extends TestCase private $testEncodedB = "5866666666666666666666666666666666666666666666666666666666666666"; private $testBitInput = "fffffffffffffffffffffffffffffffX"; + private $testPublicKeyInput = "92109952688507622152061303160978719049325098095664035905533631729165308545803"; + private $testPublicKeyOutput = "22b93c70919f3bb0023e2dd172db4b0d1ed9980fa1edf8cfdd39181047f66639"; + private $testEdwardsOutput = "c9a3f86aae465f0e56513864510f3997561fa2c9e85ea21dc2292309f3cd6022"; protected function setUp(): void @@ -97,6 +100,14 @@ public function testScalarMult(): void $this->assertEquals($this->ed25519->edwards($this->ed25519->B, $this->ed25519->B), $result); } + public function testPublicKey(): void + { + $sk = new BigInteger($this->testPublicKeyInput); + $pk = $this->ed25519->publickey($sk); + + $this->assertEquals($this->testPublicKeyOutput, $pk); + } + public function testEncodeInt(): void { $result = $this->ed25519->encodeint(new BigInteger(100));