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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ composer.json
```

```bash
composer require decentfoundation/dcorephp-sdk
composer require decentfoundation/dcorephp-sdk:^2.6
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "decentfoundation/dcorephp-sdk",
"version": "2.5.0",
"version": "2.6.0",
"description": "DCore PHP SDK library",
"type": "library",
"license": "GPL-3.0-only",
Expand Down
12 changes: 9 additions & 3 deletions src/Crypto/ECKeyPair.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
use kornrunner\Secp256k1;
use kornrunner\Serializer\HexSignatureSerializer;
use Mdanter\Ecc\Crypto\Signature\SignatureInterface;
use Mdanter\Ecc\Crypto\Signature\Signer;
use Mdanter\Ecc\Crypto\Signature\SignHasher;
use Mdanter\Ecc\EccFactory;
use Mdanter\Ecc\Primitives\PointInterface;
use Mdanter\Ecc\Serializer\PrivateKey\DerPrivateKeySerializer;
use Mdanter\Ecc\Serializer\PrivateKey\PemPrivateKeySerializer;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Validation;
Expand Down Expand Up @@ -128,14 +133,15 @@ public function getPublic(): PublicKey
* @param string $chainId
* @return string|null canonical signature on success, null if signature is not canonical
* @throws ValidationException
* @throws \Exception
*/
public function signature(string $hexData, string $chainId): ?string
{
$hash = hash('sha256', pack('H*', $chainId . $hexData)); // 1cb9ecc48ea039dda1c4626965db67c241486ce886a007903c8d5446465d7c0c
$hash = hash('sha256', pack('H*', $chainId . $hexData));
$derPrivateKey = $this->getPrivate()->toHex();
$derPublicKey = $this->getPublic()->toCompressedPublicKey(); // compressed public key
$signaturePoint = (new Secp256k1())->sign($hash, $derPrivateKey); // [98168512353566611467237581092075278762442757234040552549754768745652925038257, 44848356081555762428592265712819773562446994169847499152120711725219453447745]
$signatureHex = (new HexSignatureSerializer())->serialize($signaturePoint); // d90968b241bfdce430bc1dfd15039b08429783d3f1380364294311ca86e0feb16327451e425f07be71768a7fe25d60f232cd12eafe036b9f24b600104415ae41
$signaturePoint = (new Secp256k1())->sign($hash, $derPrivateKey);
$signatureHex = (new HexSignatureSerializer())->serialize($signaturePoint);

$finalRecId = -1;
$recId = 31;
Expand Down
27 changes: 6 additions & 21 deletions src/DCoreApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
use DCorePHP\Sdk\MessagingApi;
use DCorePHP\Sdk\MiningApi;
use DCorePHP\Sdk\NftApi;
use DCorePHP\Sdk\ProposalApi;
use DCorePHP\Sdk\PurchaseApi;
use DCorePHP\Sdk\SeederApi;
use DCorePHP\Sdk\SubscriptionApi;
use DCorePHP\Sdk\TransactionApi;
use DCorePHP\Sdk\ValidationApi;
use Exception;
use WebSocket\BadOpcodeException;

class DCoreApi extends DCoreSdk
Expand Down Expand Up @@ -57,8 +57,6 @@ class DCoreApi extends DCoreSdk
private $assetApi;
/** @var SubscriptionApi */
private $subscriptionApi;
/** @var ProposalApi */
private $proposalApi;
/** @var ContentApi */
private $contentApi;
/** @var GeneralApi */
Expand Down Expand Up @@ -93,7 +91,6 @@ public function __construct(string $dcoreApiUrl, string $dcoreWebsocketUrl, bool
$this->seederApi = new SeederApi($this);
$this->assetApi = new AssetApi($this);
$this->subscriptionApi = new SubscriptionApi($this);
$this->proposalApi = new ProposalApi($this);
$this->contentApi = new ContentApi($this);
$this->generalApi = new GeneralApi($this);
$this->historyApi = new HistoryApi($this);
Expand Down Expand Up @@ -242,22 +239,6 @@ public function setSubscriptionApi(SubscriptionApi $subscriptionApi): void
$this->subscriptionApi = $subscriptionApi;
}

/**
* @return ProposalApi
*/
public function getProposalApi(): ProposalApi
{
return $this->proposalApi;
}

/**
* @param ProposalApi $proposalApi
*/
public function setProposalApi(ProposalApi $proposalApi): void
{
$this->proposalApi = $proposalApi;
}

/**
* @return ContentApi
*/
Expand Down Expand Up @@ -464,8 +445,12 @@ public function setNftApi(NftApi $nftApi): DCoreApi
/**
* @param BaseOperation[] $operations
* @param int $expiration
*
* @return Transaction
* @throws \Exception
*
* @throws BadOpcodeException
* @throws InvalidApiCallException
* @throws Exception
*/
public function prepareTransaction(array $operations, int $expiration): Transaction
{
Expand Down
78 changes: 74 additions & 4 deletions src/Model/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace DCorePHP\Model;

use DCorePHP\Exception\ValidationException;

class Account
{
/** @var ChainObject */
private $id;
/** @var string */
/** @var ChainObject */
private $registrar;
/** @var string */
private $name;
Expand Down Expand Up @@ -39,7 +41,7 @@ public function getId(): ChainObject
/**
* @param ChainObject|string $id
* @return Account
* @throws \DCorePHP\Exception\ValidationException
* @throws ValidationException
*/
public function setId($id): Account
{
Expand All @@ -51,95 +53,163 @@ public function setId($id): Account
return $this;
}

public function getRegistrar(): string
/**
* @return ChainObject
*/
public function getRegistrar(): ChainObject
{
return $this->registrar;
}

public function setRegistrar(string $registrar): Account
/**
* @param ChainObject|string $registrar
*
* @return Account
* @throws ValidationException
*/
public function setRegistrar($registrar): Account
{
if (is_string($registrar)) {
$registrar = new ChainObject($registrar);
}
$this->registrar = $registrar;

return $this;
}

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* @param string $name
*
* @return Account
*/
public function setName(string $name): Account
{
$this->name = $name;

return $this;
}

/**
* @return Authority
*/
public function getOwner(): Authority
{
return $this->owner;
}

/**
* @param Authority $owner
*
* @return Account
*/
public function setOwner(Authority $owner): Account
{
$this->owner = $owner;

return $this;
}

/**
* @return Authority
*/
public function getActive(): Authority
{
return $this->active;
}

/**
* @param Authority $active
*
* @return Account
*/
public function setActive(Authority $active): Account
{
$this->active = $active;

return $this;
}

/**
* @return Options
*/
public function getOptions(): Options
{
return $this->options;
}

/**
* @param Options $options
*
* @return Account
*/
public function setOptions(Options $options): Account
{
$this->options = $options;

return $this;
}

/**
* @return Publishing
*/
public function getRightsToPublish(): Publishing
{
return $this->rightsToPublish;
}

/**
* @param Publishing $rightsToPublish
*
* @return Account
*/
public function setRightsToPublish(Publishing $rightsToPublish): Account
{
$this->rightsToPublish = $rightsToPublish;

return $this;
}

/**
* @return string
*/
public function getStatistics(): string
{
return $this->statistics;
}

/**
* @param string $statistics
*
* @return Account
*/
public function setStatistics(string $statistics): Account
{
$this->statistics = $statistics;

return $this;
}

/**
* @return int
*/
public function getTopControlFlags(): int
{
return $this->topControlFlags;
}

/**
* @param int $topControlFlags
*
* @return Account
*/
public function setTopControlFlags(int $topControlFlags): Account
{
$this->topControlFlags = $topControlFlags;
Expand Down
61 changes: 61 additions & 0 deletions src/Model/CoAuthors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace DCorePHP\Model;

use DCorePHP\Utils\Math;
use DCorePHP\Utils\VarInt;

class CoAuthors
{
/**
* @var array
* [[ChainObject, Int], ...]
*/
private $authors = [];

/**
* @return array
*/
public function getAuthors(): array
{
return $this->authors;
}

/**
* @param array $authors
*
* @return CoAuthors
*/
public function setAuthors(array $authors): CoAuthors
{
$this->authors = $authors;

return $this;
}

public function toArray(): array
{
$result = [];
/**
* @var ChainObject $id
* @var int $weight
*/
foreach ($this->getAuthors() as [$id, $weight]) {
$result[] = [$id->getId(), $weight];
}
return $result;
}

public function toBytes(): string
{
$result = VarInt::encodeDecToHex(sizeof($this->getAuthors()));
/**
* @var ChainObject $id
* @var int $weight
*/
foreach ($this->getAuthors() as [$id, $weight]) {
$result .= $id->toBytes() . Math::getInt32Reversed($weight);
}
return $result;
}
}
Loading