Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
198 changes: 198 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,204 @@ MODULE_zcash-main_NODES[]=http://login:password@127.0.0.2:1234/
MODULE_zcash-main_REQUESTER_TIMEOUT=60
MODULE_zcash-main_REQUESTER_THREADS=12

######################
## Main Centrifuge Module
######################

MODULES[]=centrifuge-main
MODULE_centrifuge-main_CLASS=CentrifugeMainModule
MODULE_centrifuge-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-main_REQUESTER_TIMEOUT=60
MODULE_centrifuge-main_REQUESTER_THREADS=12

######################
## EVM Main Centrifuge Module
######################

MODULES[]=centrifuge-evm-main
MODULE_centrifuge-evm-main_CLASS=CentrifugeEVMMainModule
MODULE_centrifuge-evm-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-main_REQUESTER_TIMEOUT=60
MODULE_centrifuge-evm-main_REQUESTER_THREADS=12

######################
## EVM ERC20 Centrifuge Module
######################

MODULES[]=centrifuge-evm-erc-20
MODULE_centrifuge-evm-erc-20_CLASS=CentrifugeEVMERC20Module
MODULE_centrifuge-evm-erc-20_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-erc-20_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-erc-20_REQUESTER_TIMEOUT=60
MODULE_centrifuge-evm-erc-20_REQUESTER_THREADS=12

######################
## EVM ERC721 Centrifuge Module
######################

MODULES[]=centrifuge-evm-erc-721
MODULE_centrifuge-evm-erc-721_CLASS=CentrifugeEVMERC721Module
MODULE_centrifuge-evm-erc-721_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-erc-721_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-erc-721_REQUESTER_TIMEOUT=60
MODULE_centrifuge-evm-erc-721_REQUESTER_THREADS=12

######################
## EVM ERC1155 Centrifuge Module
######################

MODULES[]=centrifuge-evm-erc-1155
MODULE_centrifuge-evm-erc-1155_CLASS=CentrifugeEVMERC1155Module
MODULE_centrifuge-evm-erc-1155_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-erc-1155_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_centrifuge-evm-erc-1155_REQUESTER_TIMEOUT=60
MODULE_centrifuge-evm-erc-1155_REQUESTER_THREADS=12

######################
## Main Astar Module
######################

MODULES[]=astar-main
MODULE_astar-main_CLASS=AstarMainModule
MODULE_astar-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-main_REQUESTER_TIMEOUT=60
MODULE_astar-main_REQUESTER_THREADS=12

######################
## EVM Main Astar Module
######################

MODULES[]=astar-evm-main
MODULE_astar-evm-main_CLASS=AstarEVMMainModule
MODULE_astar-evm-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-main_REQUESTER_TIMEOUT=60
MODULE_astar-evm-main_REQUESTER_THREADS=12

######################
## EVM Trace Astar Module
######################

MODULES[]=astar-evm-trace
MODULE_astar-evm-trace_CLASS=AstarEVMTraceModule
MODULE_astar-evm-trace_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-trace_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-trace_REQUESTER_TIMEOUT=60
MODULE_astar-evm-trace_REQUESTER_THREADS=12

######################
## EVM ERC20 Astar Module
######################

MODULES[]=astar-evm-erc-20
MODULE_astar-evm-erc-20_CLASS=AstarEVMERC20Module
MODULE_astar-evm-erc-20_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-erc-20_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-erc-20_REQUESTER_TIMEOUT=60
MODULE_astar-evm-erc-20_REQUESTER_THREADS=12

######################
## EVM ERC721 Astar Module
######################

MODULES[]=astar-evm-erc-721
MODULE_astar-evm-erc-721_CLASS=AstarEVMERC721Module
MODULE_astar-evm-erc-721_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-erc-721_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-erc-721_REQUESTER_TIMEOUT=60
MODULE_astar-evm-erc-721_REQUESTER_THREADS=12

######################
## EVM ERC1155 Astar Module
######################

MODULES[]=astar-evm-erc-1155
MODULE_astar-evm-erc-1155_CLASS=AstarEVMERC1155Module
MODULE_astar-evm-erc-1155_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-erc-1155_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_astar-evm-erc-1155_REQUESTER_TIMEOUT=60
MODULE_astar-evm-erc-1155_REQUESTER_THREADS=12

######################
## Main Acala Module
######################

MODULES[]=acala-main
MODULE_acala-main_CLASS=AcalaMainModule
MODULE_acala-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_acala-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_acala-main_REQUESTER_TIMEOUT=60
MODULE_acala-main_REQUESTER_THREADS=12

######################
## XCM Acala Module
######################

MODULES[]=acala-xcm
MODULE_acala-xcm_CLASS=AcalaXCMModule
MODULE_acala-xcm_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_acala-xcm_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_acala-xcm_REQUESTER_TIMEOUT=60
MODULE_acala-xcm_REQUESTER_THREADS=12

######################
## Tokens Acala Module
######################

MODULES[]=acala-tokens
MODULE_acala-tokens_CLASS=AcalaTokensModule
MODULE_acala-tokens_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_acala-tokens_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_acala-tokens_REQUESTER_TIMEOUT=60
MODULE_acala-tokens_REQUESTER_THREADS=12

######################
## Main Kusama Module
######################

MODULES[]=kusama-main
MODULE_kusama-main_CLASS=KusamaMainModule
MODULE_kusama-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_kusama-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_kusama-main_REQUESTER_TIMEOUT=60
MODULE_kusama-main_REQUESTER_THREADS=12

######################
## XCM Kusama Module
######################

MODULES[]=kusama-xcm
MODULE_kusama-xcm_CLASS=KusamaXCMModule
MODULE_kusama-xcm_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_kusama-xcm_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_kusama-xcm_REQUESTER_TIMEOUT=60
MODULE_kusama-xcm_REQUESTER_THREADS=12

######################
## Main Polkadot Module
######################

MODULES[]=polkadot-main
MODULE_polkadot-main_CLASS=PolkadotMainModule
MODULE_polkadot-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_polkadot-main_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_polkadot-main_REQUESTER_TIMEOUT=60
MODULE_polkadot-main_REQUESTER_THREADS=12

######################
## XCM Polkadot Module
######################

MODULES[]=polkadot-xcm
MODULE_polkadot-xcm_CLASS=PolkadotXCMModule
MODULE_polkadot-xcm_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_polkadot-xcm_NODES[]=http://login:password@127.0.0.1:1234/
MODULE_polkadot-xcm_REQUESTER_TIMEOUT=60
MODULE_polkadot-xcm_REQUESTER_THREADS=12

############################
# Titles, descriptions, etc.
############################
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
- Beacon Chain modules
* [alexqrid](https://github.com/alexqrid)
- TVM modules
* [Kirill Kuzminykh](https://github.com/Oskal174)
- Substrate modules
* [Oleg Makaussov](https://github.com/Lorgansar)
- Cardano Tokens modules
4 changes: 2 additions & 2 deletions Engine/Crypto/Base58.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class Base58
{
private const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';

private static function base58_encode($string)
public static function base58_encode($string)
{
if (!$string)
return '';
Expand Down Expand Up @@ -51,7 +51,7 @@ private static function base58_encode($string)
return $output;
}

private static function base58_decode($base58)
public static function base58_decode($base58)
{
if (!$base58)
return '';
Expand Down
76 changes: 76 additions & 0 deletions Engine/Crypto/SS58.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

require_once __DIR__ . '/Base58.php';
final class SS58
{
private const ALLOWED_DECODED_LENGTHS = [1, 2, 4, 8, 32, 33];
private const ALLOWED_ENCODED_LENGTHS = [3, 4, 6, 10, 35, 36, 37, 38];

/**
* @throws SodiumException
*/
public static function ss58_encode($accountId, $ss58_format = 42): ?string
{
$key = SS58::ss58_decode($accountId);
if (strlen($key) == 64)
$key = hex2bin($key);
//there should be also this condition along
// || in_array($ss58_format,[46, 47])
// but we don't care, we just have to decode everything
// even reserved one
if (($ss58_format < 0) || ($ss58_format > 16383)) {
return null;
}
elseif (!in_array(strlen($key),self::ALLOWED_DECODED_LENGTHS)) {
return null;
}
$prefix = $ss58_format < 64 ? [$ss58_format] : [
(($ss58_format & 252) >> 2) | 64,
($ss58_format >> 8) | (($ss58_format & 3) << 6)
];
$data_with_prefix = join(array_map("chr", $prefix)) . $key;
$checksum_length = in_array(strlen($key),[32,33]) ? 2 : 1;
$checksum = substr(sodium_crypto_generichash("SS58PRE" . $data_with_prefix, '', 64), 0, $checksum_length);

$data_with_checksum = $data_with_prefix . $checksum;

return Base58::base58_encode($data_with_checksum);
}

/**
* @throws SodiumException
*/
public static function ss58_decode(string $ss58_address, $ignore_checksum=true): string
{
if (strlen($ss58_address) == 64)
{
// dirty hack for encode function
return hex2bin($ss58_address);
}
$decoded_data = Base58::base58_decode($ss58_address);
if (!in_array(strlen($decoded_data), self::ALLOWED_ENCODED_LENGTHS)) {
return "";
}
// dirty hack for \x00 prefix
if (str_starts_with(bin2hex($decoded_data), '5c783030')) {
$decoded_data = unpack("C*",hex2bin(str_replace("5c783030","00",bin2hex($decoded_data))));
$decoded_data = join(array_map("chr",$decoded_data));
}
// Calculate address checksum
$ss58_length = (ord($decoded_data[0]) & 64) ? 2 : 1;
// prefix of the parachain decoded in $ss58_decoded
// $ss58_decoded = $ss58_length === 1 ? ord($decoded_data[0]) : ((ord($decoded_data[0]) & 63) << 2) | (ord($decoded_data[1]) >> 6) | ((ord($decoded_data[1]) & 63) << 8);
$is_public_key = in_array(strlen($decoded_data), [34 + $ss58_length, 35 + $ss58_length]);
$length = strlen($decoded_data) - ($is_public_key ? 2 : 1);
$data = "SS58PRE" . substr($decoded_data, 0, $length);
$hash = substr(sodium_crypto_generichash($data, '', 64), 0, 2);

$is_valid = (ord($decoded_data[0]) & 128) === 0 && !in_array(ord($decoded_data[0]), [46, 47]) && ($is_public_key
? str_ends_with($decoded_data, $hash)
: substr($decoded_data, -1) === $hash[0]);
if (!$is_valid && !$ignore_checksum) {
return "";
}
return bin2hex(substr($decoded_data, $ss58_length, $length - $ss58_length));
}
}
24 changes: 24 additions & 0 deletions Modules/AcalaMainModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This is the main Acala module. */

final class AcalaMainModule extends SubstrateMainModule implements Module
{
function initialize()
{
// CoreModule
$this->blockchain = 'acala';
$this->module = 'acala-main';
$this->is_main = true;
$this->first_block_date = '2021-12-18';
$this->currency = 'acala';
$this->currency_details = ['name' => 'Acala', 'symbol' => 'ACA', 'decimals' => 12, 'description' => null];

// Substrate-specific
$this->chain_type = SubstrateChainType::Para;
}
}
22 changes: 22 additions & 0 deletions Modules/AcalaTokensModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This is the Tokens Acala module. */

final class AcalaTokensModule extends SubstrateTokensModule implements Module
{
function initialize()
{
// CoreModule
$this->blockchain = 'acala';
$this->module = 'acala-tokens';
$this->is_main = false;
$this->first_block_date = '2021-12-18';

// Tokens-specific
$this->native_token_id = 'native-ACA';
}
}
22 changes: 22 additions & 0 deletions Modules/AcalaXCMModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This is the XCM Acala module. */

final class AcalaXCMModule extends SubstrateXCMModule implements Module
{
function initialize()
{
// CoreModule
$this->blockchain = 'acala';
$this->module = 'acala-xcm';
$this->is_main = false;
$this->first_block_date = '2021-12-18';

// Substrait XCM specific
$this->native_asset_id = 'native-ACA';
}
}
Loading