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

Draft
wants to merge 50 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[root]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_size = 4
indent_style = tab
trim_trailing_whitespace = true
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release
on:
push:
tags:
- "v*.*.*"
branches:
- master

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Update changelog
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
tag: ${{ github.ref_name }}

- name: Create release
uses: ncipollo/release-action@v1.12.0
with:
allowUpdates: true
draft: false
makeLatest: true
name: ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changes }}
token: ${{ github.token }}

- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: master
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
file_pattern: CHANGELOG.md
34 changes: 34 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Security

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# Also run this workflow every Monday at 6:00.
schedule:
- cron: '0 6 * * 1'
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
security:
name: 'Security check'
runs-on: ubuntu-latest

# Don't run the cronjob in this workflow on forks.
if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'refactor-ring')

steps:
- name: Checkout code
uses: actions/checkout@v4

# This action checks the `composer.lock` file against known security vulnerabilities in the dependencies.
# https://github.com/marketplace/actions/the-php-security-checker
- name: Run Security Check
uses: symfonycorp/security-checker-action@v5
48 changes: 48 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: "Unit Tests"

on:
pull_request:
push:
branches:
- master

jobs:
tests:
runs-on: ${{ matrix.os }}

env:
PHP_EXTENSIONS: none, bcmath, ctype, curl, dom, json, gmp, mbstring, opcache, simplexml, sockets, tokenizer, xml, xmlwriter
PHP_INI_VALUES: memory_limit=-1, assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.1, 8.2, 8.3]
dependency-version: [prefer-lowest, prefer-stable]

name: Tests PHP${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

steps:
- uses: actions/checkout@v4
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: ${{ matrix.coverage-driver }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_VALUES }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Composer dependencies
run: composer update --${{ matrix.dependency-version }} --no-ansi --no-interaction --no-progress --prefer-dist

- name: Run unit tests with PHPUnit
run: composer run test:unit
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor/
build
build
.phpunit.cache
tests/_reports
23 changes: 23 additions & 0 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Publishing a release

This document describes the process of publishing a new version of the package.

1. Update the version in the `composer.json` file.
2. Commit the changes.
- ```bash
git commit -m "chore: bump version to <version>"
```

Where `<version>` is the new version number (e.g. `1.2.3`).
3. Create a new tag.
- ```bash
git tag v<version>
```

Where `<version>` is the new version number (e.g. `1.2.3`).
4. Push the changes.
- ```bash
git push origin master --tags
```

A release will automatically be created.
150 changes: 126 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,147 @@
[![PHPCS PSR-12](https://img.shields.io/badge/PHPCS-PSR–12-226146.svg)](https://www.php-fig.org/psr/psr-12/) [![PHPStan ](.github/phpstan.svg)](https://phpstan.org/)

# Monero Library
A Monero library written in PHP by the [Monero Integrations](https://monerointegrations.com) [team](https://github.com/monero-integrations/monerophp/graphs/contributors).
# Monero-Crypto

## How It Works
This library has 3 main parts:
A Monero cryptography library written in modern PHP 8 by the [Monero Integrations team](https://monerointegrations.com) and [contributors](
https://github.com/monero-integrations/monerophp/graphs/contributors).

1. A Monero daemon JSON RPC API wrapper, `daemonRPC.php`
2. A Monero wallet (`monero-wallet-rpc`) JSON RPC API wrapper, `walletRPC.php`
3. A Monero/Cryptonote toolbox, `cryptonote.php`, with both lower level functions used in Monero related cryptography and higher level methods for things like generating Monero private/public keys.
## Features

In addition to these features, there are other lower-level libraries included for portability, *eg.* an ed25519 library, a SHA3 library, *etc.*
This library implements/interfaces various cryptographic functions used in Monero, such as:

- Monero's base58 encoding
- Monero's mnemonic seeds
- Keccak hash function
- Cryptonote functions on the Edwards25519 curve
- Variably-sized integers (Varint)

Higher-level abstractions are additionally provided for things like generating Monero private/public keys, subaddresses, etc.

## Preview
![Preview](https://user-images.githubusercontent.com/4107993/38056594-b6cd6e14-3291-11e8-96e2-a771b0e9cee3.png)

## Getting Started

The minimum PHP version required is 8.1.0. Please make sure you also have [Composer](https://getcomposer.org/) installed.

You can check your PHP version by running:

```bash
php -v
```

### Extensions

The `bcmath` extension is required.

It is **strongly recommended** to use the `gmp` extension for about 100x faster calculations (as opposed to BCMath).

To check what extensions are installed, run:

```bash
php -m
```

### Installation

#### From Packagist

```bash
composer require monero-integrations/monero-crypto
```

#### From Source

```bash
git clone https://github.com/monero-integrations/monerophp.git
cd monerophp
composer install
```

### Usage

From here, you can use the library in your PHP project. For example:

```php
require 'vendor/autoload.php';

// To get a list of available mnemonic wordlists
use MoneroIntegrations\MoneroCrypto\Mnemonic;
$wordlists = Mnemonic::getWordsetList();

echo "Available wordlists: " . implode(', ', $wordlists) . PHP_EOL;
```

## Documentation

Documentation can be found in the [`/docs`](https://github.com/sneurlax/monerophp/tree/master/docs) folder.
Documentation is still a work-in-progress, but the library is well-documented with PHPDoc comments.

Current documentation can be found in the [`/docs`](./docs/) folder.

## Development

The project uses several development tools to ensure code quality and consistency:

1. PHP CodeSniffer: Used to check the code style against the PSR-12 standard.
2. PHPStan: Static analysis tool to find bugs and improve code quality.
3. PHPUnit: Testing framework for running unit tests.
4. Laravel Pint: Code style fixer for PSR-12 compliance.

### Running Tests

To ensure everything is working correctly, you can run the tests and code quality checks using Composer scripts:

#### Lint Code

```bash
composer lint
```

#### Test Lint

Run linting on your code and test files:

```bash
composer test:lint
```

## Configuration
### Requirements
- Monero daemon (`monerod`)
- Webserver with PHP, for example XMPP, Apache, or NGINX
- cURL PHP extension for JSON RPC API(s)
- GMP PHP extension for about 100x faster calculations (as opposed to BCMath)
#### Analyze Code with PHPStan

Debian (or Ubuntu) are recommended.

### Getting Started
```bash
composer test:phpstan
```

#### Run Unit Tests

1. Start the Monero daemon (`monerod`) on testnet.
```bash
monerod --testnet --detach
composer test:unit
```

2. Start the Monero wallet RPC interface (`monero-wallet-rpc`) on testnet.
#### Run All Tests and Checks

This will run linting, PHPStan analysis, and unit tests:

```bash
monero-wallet-rpc --testnet --rpc-bind-port 28083 --disable-rpc-login --wallet-dir /path/to/wallet/directory
composer test
```

3. Edit `example.php` with your the IP address of `monerod` and `monero-wallet-rpc` (use `127.0.0.1:28081` and `127.0.0.1:28083`, respectively, for testnet.)
### Standards

We follow the PSR-12 coding standard. Please make sure your code adheres to these guidelines. You can use Laravel Pint to automatically fix code style issues.

### Contributions

We welcome contributions! If you have an idea or fix, please follow these steps:

1. Fork the repository
2. Create a branch with your changes
3. Make your changes
4. Submit a pull request (PR) with a clear description of the changes

Please ensure your code passes all tests and adheres to our coding standards before submitting a pull request.

For any questions or issues, feel free to reach out to the maintainers or open an issue on GitHub.

## License

4. Serve `example.php` with your webserver (*eg.* XMPP, Apache/Apache2, NGINX, *etc.*) and navigate to it. If everything has been set up correctly, information from your Monero daemon and wallet will be displayed.
This library is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more information.
Loading