Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: Final touches (closes #147, #135, #133, #132, #124, #111, #100, #92, #82, #81, #57, #54) #154

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2480131
chore: remove deprecated classes
recanman May 2, 2024
2c8311e
chore: remove old example.php
recanman May 2, 2024
5e417b6
style: format files
recanman May 2, 2024
ac1513f
feat: rename library, bump php, add phpunit test support
recanman May 2, 2024
612c909
feat: add new Mnemonic class
recanman May 2, 2024
ea70d6d
ci: add security and test workflows
recanman May 2, 2024
32702a5
feat: partially-refactored varint class and tests
recanman May 2, 2024
dc74c82
chore: delete old base58 class
recanman May 9, 2024
4eead4b
feat: implement base58 encode and tests
recanman May 9, 2024
95d72fc
docs: block comments for Base58
recanman May 9, 2024
1a699c7
feat: implement Monero base58 decode
recanman May 9, 2024
d374296
fix: use base58 static methods in Cryptonote, set namespace
recanman May 9, 2024
0b269e5
feat: add some Cryptonote tests
recanman May 16, 2024
793f73e
feat: BigInt, use it in base58
recanman May 16, 2024
1c89c99
chore: improve composer.json gmp suggestion msg
recanman May 16, 2024
5f5eecc
docs: grammatical error in comment
recanman May 16, 2024
6bbbac1
feat: add tests for BigInteger class
recanman May 16, 2024
69b9a6f
ci: add release action
recanman May 25, 2024
461773f
docs: add documentation on publishing
recanman May 25, 2024
2d5d318
ci: change main to master
recanman May 25, 2024
873fdb0
fix: allow mixed input to various BigInteger functions
recanman May 27, 2024
9b05ea7
chore: remove ext-curl dependency
recanman May 27, 2024
cfb4d06
feat: BigInteger bitshift left and right
recanman May 27, 2024
8b9bf27
feat: add bitshift left/right to BigInteger
recanman Jun 1, 2024
51a0bf9
feat: partially implement new ed25519 class
recanman Jun 1, 2024
c9273b7
chore: delete redundant subaddress class
recanman Jun 1, 2024
5d9a8f4
chore: delete old ed25519 class
recanman Jun 1, 2024
457ab44
feat: MoneroNetwork enum in Cryptonote, declare strict types
recanman Jun 1, 2024
95b081c
fix: declare Cryptonote type in test
recanman Jun 1, 2024
8db754c
chore: comment out failing Cryptonote tests until functions fixed (te…
recanman Jun 1, 2024
4945605
feat: accept MoneroNetwork enum in Cryptonote constructor
recanman Jun 1, 2024
87497ea
feat: implement Ed25519 point encoding
recanman Jun 2, 2024
a7b9059
test: add another point test
recanman Jun 2, 2024
a76b1ab
feat: implement bit and decodepoint
recanman Jun 2, 2024
f0a0e6a
chore: remove unused parameter
recanman Jun 2, 2024
54f8d73
chore: fix wordset docstrings
recanman Jun 2, 2024
b4db214
chore: fix many phpstan errors
recanman Jun 2, 2024
40d5f0a
test: add negative base58 test
recanman Jun 2, 2024
04e86f1
test: edwards and scalarmult test, formatting
recanman Jun 5, 2024
2e1d826
fix: edwards implementation
recanman Jun 5, 2024
b6f49d2
fix: don't convert to int in bit
recanman Jun 5, 2024
f732277
fix: decodepoint
recanman Jun 5, 2024
002394c
test: ed25519 public key
recanman Jun 5, 2024
114fbaa
test: sc_reduce
recanman Jun 5, 2024
43f11ad
fix: duplicate declaration of network_prefixes
recanman Aug 3, 2024
b2831a5
style: add editorconfig and format files
recanman Aug 3, 2024
8611a82
refactor: use new classes and clean up cryptonote code
recanman Aug 3, 2024
b2d91ab
chore: remove unneeded extension
recanman Aug 3, 2024
40031d0
docs: rewrite readme
recanman Aug 3, 2024
d3d8223
docs: add mnemonic.md
recanman Aug 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: allow mixed input to various BigInteger functions
  • Loading branch information
recanman committed May 27, 2024
commit 873fdb0c89bf84caab2fba35320649eb3d511e00
66 changes: 33 additions & 33 deletions src/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,59 +148,59 @@ public function toNumber(): int
return gmp_intval($this->value);
}

public function add(int $x): BigInteger
public function add(mixed $x): BigInteger
{
return new BigInteger(gmp_add($this->value, BigInteger::getGmp($x)), true);
}

public function sub(int $x): BigInteger
public function sub(mixed $x): BigInteger
{
return new BigInteger(gmp_sub($this->value, BigInteger::getGmp($x)), true);
}

public function mul(int $x): BigInteger
public function mul(mixed $x): BigInteger
{
return new BigInteger(gmp_mul($this->value, BigInteger::getGmp($x)), true);
}

public function div(int $x): BigInteger
public function div(mixed $x): BigInteger
{
return new BigInteger(gmp_div_q($this->value, BigInteger::getGmp($x)), true);
}

public function divR(int $x): BigInteger
public function divR(mixed $x): BigInteger
{
return new BigInteger(gmp_div_r($this->value, BigInteger::getGmp($x)), true);
}

public function divQR(int $x): array
public function divQR(mixed $x): array
{
$res = gmp_div_qr($this->value, BigInteger::getGmp($x));
return [new BigInteger($res[0], true), new BigInteger($res[1], true)];
}

public function mod(int $x): BigInteger
public function mod(mixed $x): BigInteger
{
return new BigInteger(gmp_mod($this->value, BigInteger::getGmp($x)), true);
}

public function gcd(int $x): BigInteger
public function gcd(mixed $x): BigInteger
{
return new BigInteger(gmp_gcd($this->value, BigInteger::getGmp($x)), true);
}

public function modInverse(int $x): BigInteger|bool
public function modInverse(mixed $x): BigInteger|bool
{
$res = gmp_invert($this->value, BigInteger::getGmp($x));
return $res === false ? false : new BigInteger($res, true);
}

public function pow(int $x): BigInteger
public function pow(mixed $x): BigInteger
{
return new BigInteger(gmp_pow($this->value, (new BigInteger($x))->toNumber()), true);
}

public function powMod(int $x, int $n): BigInteger
public function powMod(mixed $x, mixed $n): BigInteger
{
return new BigInteger(gmp_powm($this->value, BigInteger::getGmp($x), BigInteger::getGmp($n)), true);
}
Expand All @@ -215,17 +215,17 @@ public function neg(): BigInteger
return new BigInteger(gmp_neg($this->value), true);
}

public function binaryAnd(int $x): BigInteger
public function binaryAnd(mixed $x): BigInteger
{
return new BigInteger(gmp_and($this->value, BigInteger::getGmp($x)), true);
}

public function binaryOr(int $x): BigInteger
public function binaryOr(mixed $x): BigInteger
{
return new BigInteger(gmp_or($this->value, BigInteger::getGmp($x)), true);
}

public function binaryXor(int $x): BigInteger
public function binaryXor(mixed $x): BigInteger
{
return new BigInteger(gmp_xor($this->value, BigInteger::getGmp($x)), true);
}
Expand All @@ -252,12 +252,12 @@ public function scan1(int $start): int
return gmp_scan1($this->value, $start);
}

public function cmp(int $x): int
public function cmp(mixed $x): int
{
return gmp_cmp($this->value, BigInteger::getGmp($x));
}

public function equals(int $x): bool
public function equals(mixed $x): bool
{
return $this->cmp($x) === 0;
}
Expand Down Expand Up @@ -489,40 +489,40 @@ public function toNumber(): int
return intval($this->value);
}

public function add(int $x): BigInteger
public function add(mixed $x): BigInteger
{
return new BigInteger(bcadd($this->value, BigInteger::getBC($x), 0), true);
}

public function sub(int $x): BigInteger
public function sub(mixed $x): BigInteger
{
return new BigInteger(bcsub($this->value, BigInteger::getBC($x), 0), true);
}

public function mul(int $x): BigInteger
public function mul(mixed $x): BigInteger
{
return new BigInteger(bcmul($this->value, BigInteger::getBC($x), 0), true);
}

public function div(int $x): BigInteger
public function div(mixed $x): BigInteger
{
return new BigInteger(bcdiv($this->value, BigInteger::getBC($x), 0), true);
}

public function divR(int $x): BigInteger
public function divR(mixed $x): BigInteger
{
return new BigInteger(bcmod($this->value, BigInteger::getBC($x)), true);
}

public function divQR(int $x): array
public function divQR(mixed $x): array
{
return [
$this->div($x),
$this->divR($x)
];
}

public function mod(int $x): BigInteger
public function mod(mixed $x): BigInteger
{
$xv = BigInteger::getBC($x);
$mod = bcmod($this->value, $xv);
Expand All @@ -532,7 +532,7 @@ public function mod(int $x): BigInteger
return new BigInteger($mod, true);
}

public function extendedGcd(int $n): array
public function extendedGcd(mixed $n): array
{
$u = $this->value;
$v = (new BigInteger($n))->abs()->value;
Expand Down Expand Up @@ -565,12 +565,12 @@ public function extendedGcd(int $n): array
];
}

public function gcd(int $x): BigInteger
public function gcd(mixed $x): BigInteger
{
return $this->extendedGcd($x)["gcd"];
}

public function modInverse(int $n): BigInteger|bool
public function modInverse(mixed $n): BigInteger|bool
{
$original = $n;
$n = (new BigInteger($n))->abs();
Expand All @@ -592,12 +592,12 @@ public function modInverse(int $n): BigInteger|bool
return $this->sign() < 0 ? $n->sub($x) : $x;
}

public function pow(int $x): BigInteger
public function pow(mixed $x): BigInteger
{
return new BigInteger(bcpow($this->value, BigInteger::getBC($x), 0), true);
}

public function powMod(int $x, int $n): BigInteger
public function powMod(mixed $x, mixed $n): BigInteger
{
return new BigInteger(bcpowmod($this->value, BigInteger::getBC($x), BigInteger::getBC($n), 0), true);
}
Expand All @@ -612,7 +612,7 @@ public function neg(): BigInteger
return new BigInteger($this->value[0] == "-" ? substr($this->value, 1) : "-" . $this->value, true);
}

public function binaryAnd(int $x): BigInteger
public function binaryAnd(mixed $x): BigInteger
{
$left = $this->toBytes();
$right = (new BigInteger($x))->toBytes();
Expand All @@ -625,7 +625,7 @@ public function binaryAnd(int $x): BigInteger
return new BigInteger($left & $right, 256);
}

public function binaryOr(int $x): BigInteger
public function binaryOr(mixed $x): BigInteger
{
$left = $this->toBytes();
$right = (new BigInteger($x))->toBytes();
Expand All @@ -638,7 +638,7 @@ public function binaryOr(int $x): BigInteger
return new BigInteger($left | $right, 256);
}

public function binaryXor(int $x): BigInteger
public function binaryXor(mixed $x): BigInteger
{
$left = $this->toBytes();
$right = (new BigInteger($x))->toBytes();
Expand Down Expand Up @@ -690,12 +690,12 @@ public function scan1(int $start): int
return $pos === false ? -1 : $len - $pos - 1;
}

public function cmp(int $x): int
public function cmp(mixed $x): int
{
return bccomp($this->value, BigInteger::getBC($x));
}

public function equals(int $x): bool
public function equals(mixed $x): bool
{
return $this->value === BigInteger::getBC($x);
}
Expand Down