PHPackages                             amashukov/ton-crypto-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. amashukov/ton-crypto-php

ActiveLibrary[Security](/categories/security)

amashukov/ton-crypto-php
========================

Ed25519 keypairs and TON-style mnemonic seed derivation for The Open Network, in pure PHP on top of ext-sodium.

v0.1.0(2w ago)0225↑79.4%2MITPHPPHP &gt;=8.3CI passing

Since May 24Pushed 2w agoCompare

[ Source](https://github.com/AndreyMashukov/ton-crypto-php)[ Packagist](https://packagist.org/packages/amashukov/ton-crypto-php)[ RSS](/packages/amashukov-ton-crypto-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (2)Used By (2)

amashukov/ton-crypto-php
========================

[](#amashukovton-crypto-php)

Correct TON mnemonic + Ed25519 keypair derivation for The Open Network in pure PHP.

[![CI](https://camo.githubusercontent.com/2b05bc9ac3bb7cfcd25d7057f658c051b94e79cb983f789d83b62225531fa712/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416e647265794d617368756b6f762f746f6e2d63727970746f2d7068702f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349)](https://github.com/AndreyMashukov/ton-crypto-php/actions)[![PHPStan L9](https://camo.githubusercontent.com/8371242c7bb5d2aca3fd6a87189938205494ffbd10090bec13d0111453e92260/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416e647265794d617368756b6f762f746f6e2d63727970746f2d7068702f7374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d5048505374616e2532304c39)](https://github.com/AndreyMashukov/ton-crypto-php/actions)[![Latest Version](https://camo.githubusercontent.com/34c19f9c3cd7a80ee8b7b3dc2005ef4333122cd982694912a1c07490cba51b1f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d617368756b6f762f746f6e2d63727970746f2d706870)](https://packagist.org/packages/amashukov/ton-crypto-php)[![Downloads](https://camo.githubusercontent.com/20185b26aba910c395518a1865fd1f4608537237343d84c7bd5a18a90632a9ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d617368756b6f762f746f6e2d63727970746f2d706870)](https://packagist.org/packages/amashukov/ton-crypto-php)[![PHP](https://camo.githubusercontent.com/7db0ae033a06c24daad512e3d1284512b00bf4e30bfefe4352859e20c19a9d3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f616d617368756b6f762f746f6e2d63727970746f2d7068702f706870)](https://packagist.org/packages/amashukov/ton-crypto-php)[![License](https://camo.githubusercontent.com/f349c677ebed6310c881d6c9b6e6bb70ea6e1a4e05d8780c3615d91355db8c05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d617368756b6f762f746f6e2d63727970746f2d706870)](LICENSE)[![Stars](https://camo.githubusercontent.com/34a3494eb29dae21e5f9d7733872b7a8ae20223f70060c6a243ecec05db04fa5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f416e647265794d617368756b6f762f746f6e2d63727970746f2d7068703f7374796c653d736f6369616c)](https://github.com/AndreyMashukov/ton-crypto-php)

TON cryptography for PHP: Ed25519 keypairs (sign / verify via libsodium) and **TON-flavoured mnemonic seed derivation** for The Open Network. The TON mnemonic format is PBKDF2-HMAC-SHA512 with salt `"TON default seed"` and 100 000 iterations — it is **not** BIP-39. The wordlist and derivation procedure mirror the TON reference implementation, so the same 24-word phrase produces the same Ed25519 keypair (and therefore the same wallet address) across all TON tooling.

Features
--------

[](#features)

- TON-correct mnemonic → seed → Ed25519 keypair derivation (PBKDF2-HMAC-SHA512, salt `"TON default seed"`, 100 000 iterations).
- Ed25519 keypair generation, sign and verify on top of `ext-sodium`.
- Deterministic phrase normalisation (trims, collapses tab/newline/whitespace runs to a single space).
- Optional password passthrough on the HMAC step.
- Zero composer dependencies — only PHP core extensions.
- PHPStan level 9 clean, `final readonly` value objects, `strict_types`.

Why amashukov/ton-crypto-php
----------------------------

[](#why-amashukovton-crypto-php)

BIP-39 mnemonic libraries derive the **wrong** key for TON. TON does not use the BIP-39 PBKDF2 salt (`"mnemonic"`) or iteration scheme — it uses a distinct entropy → seed pipeline (`hash_hmac` pass feeding PBKDF2-HMAC-SHA512 with salt `"TON default seed"`, 100 000 iterations). Feeding a TON phrase to a generic BIP-39 library yields a seed and address that do not match TON wallets. This package implements the TON procedure exactly, so derived addresses match official TON tooling byte-for-byte.

Installation
------------

[](#installation)

```
composer require amashukov/ton-crypto-php
```

Usage
-----

[](#usage)

### Derive a keypair from a mnemonic phrase

[](#derive-a-keypair-from-a-mnemonic-phrase)

```
use Amashukov\TonCrypto\Mnemonic;

$phrase  = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art';
$keypair = Mnemonic::toKeyPair($phrase);

// Or just the raw 32-byte seed:
$seed = Mnemonic::toSeed($phrase);
```

`toSeed()` and `toKeyPair()` normalise the phrase (trims leading/trailing whitespace, collapses any inter-word run of whitespace — including tabs and newlines — to a single space). Both accept an optional `$password` argument that is fed through the HMAC step.

### Generate a fresh keypair

[](#generate-a-fresh-keypair)

```
use Amashukov\TonCrypto\KeyPair;

$kp = KeyPair::generate();           // 32-byte seed from random_bytes()
$kp = KeyPair::fromSeed($seedBytes); // explicit 32-byte seed
```

### Sign + verify

[](#sign--verify)

```
$signature = $kp->sign('payload');           // 64 raw bytes (Ed25519 detached)
$ok        = $kp->verify('payload', $signature);
```

`verify()` returns `false` for any signature whose length is not exactly 64 bytes, in addition to the cryptographic check.

### `KeyPair` layout

[](#keypair-layout)

- `KeyPair::SEED_BYTES` = 32 (libsodium `SODIUM_CRYPTO_SIGN_SEEDBYTES`)
- `KeyPair::PUBLIC_KEY_BYTES` = 32
- `KeyPair::SECRET_KEY_BYTES` = 64 (libsodium layout: `seed ‖ publicKey`)
- `KeyPair::SIGNATURE_BYTES` = 64

### TON mnemonic parameters

[](#ton-mnemonic-parameters)

- Salt: `TON default seed`
- KDF: PBKDF2-HMAC-SHA512
- Iterations: 100 000
- Output: 64 bytes; first 32 bytes are the Ed25519 seed
- HMAC pass: `hash_hmac('sha512', $password, $normalizedPhrase, true)` produces the entropy fed into PBKDF2

These constants are exposed on `Mnemonic::DEFAULT_SALT`, `Mnemonic::PBKDF2_ITERATIONS`, `Mnemonic::PBKDF2_OUTPUT_BYTES`.

Requirements
------------

[](#requirements)

- PHP 8.3+
- `ext-sodium`
- `ext-hash` (bundled with PHP core; used for HMAC-SHA512 + PBKDF2)

No composer dependencies.

Related packages
----------------

[](#related-packages)

PackageTierPurpose[amashukov/ton-cell-php](https://github.com/AndreyMashukov/ton-cell-php)leafTLB Cell / BoC serialization[amashukov/ton-wallet-php](https://github.com/AndreyMashukov/ton-wallet-php)compositeTON wallet contracts + address derivation[amashukov/toncenter-client-php](https://github.com/AndreyMashukov/toncenter-client-php)RPCtoncenter v2/v3 API client[amashukov/ton-php](https://github.com/AndreyMashukov/ton-php)metaTON umbrella package[amashukov/keccak-php](https://github.com/AndreyMashukov/keccak-php)leafkeccak-256 hashingQuality
-------

[](#quality)

- PHPStan level 9.
- php-cs-fixer with the `@PER-CS` ruleset.
- GitHub Actions CI on every push.
- Derived seeds and addresses validated against the TON reference implementation.

License
-------

[](#license)

MIT.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance97

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

17d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b3e86ca79a82515b23e0239b1d3616c747e59b64c40e169d538d5c759c9bbc4?d=identicon)[Andrey Mashukov](/maintainers/Andrey%20Mashukov)

---

Top Contributors

[![AndreyMashukov](https://avatars.githubusercontent.com/u/24682497?v=4)](https://github.com/AndreyMashukov "AndreyMashukov (3 commits)")

---

Tags

blockchaincryptographyed25519keypairmnemonicphpthe-open-networktoncryptoEd25519walletblockchaintonthe open networkmnemonic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/amashukov-ton-crypto-php/health.svg)

```
[![Health](https://phpackages.com/badges/amashukov-ton-crypto-php/health.svg)](https://phpackages.com/packages/amashukov-ton-crypto-php)
```

###  Alternatives

[phpseclib/phpseclib

PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.

5.6k455.2M1.4k](/packages/phpseclib-phpseclib)[defuse/php-encryption

Secure PHP Encryption Library

3.9k170.7M239](/packages/defuse-php-encryption)[spatie/crypto

Encrypting and signing data using private/public keys

482804.9k12](/packages/spatie-crypto)[paragonie/certainty

Up-to-date, verifiable repository for Certificate Authorities

2642.5M22](/packages/paragonie-certainty)[simplito/elliptic-php

Fast elliptic curve cryptography

2302.4M266](/packages/simplito-elliptic-php)[olifanton/ton

PHP library for The Open Network blockchain

9056.6k2](/packages/olifanton-ton)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
