Skip to content

Commit

Permalink
test: ed25519 public key
Browse files Browse the repository at this point in the history
  • Loading branch information
recanman committed Jun 5, 2024
1 parent f732277 commit 002394c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Ed25519.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/Ed25519Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 002394c

Please sign in to comment.