mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
remove protobuf, preparing for adding as submodule
This commit is contained in:
parent
c40c6b87a0
commit
c268af5962
@ -1 +1 @@
|
||||
Subproject commit 680e56876d6e7f2778bff4eb49c880063716b391
|
||||
Subproject commit f0b1d113cee2a76e9dbb098b315f4acaf38410d0
|
||||
@ -1,66 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
namespace Model\Transactions;
|
||||
|
||||
//use Model\Messages\Gradido\Transaction;
|
||||
//use Model\Messages\Gradido\TransactionBody;
|
||||
|
||||
class Transaction extends TransactionBase {
|
||||
|
||||
private $mProtoTransaction = null;
|
||||
private $mProtoTransactionBody = null;
|
||||
private $errors = [];
|
||||
|
||||
public function __construct($base64Data) {
|
||||
$transactionBin = base64_decode($base64Data);
|
||||
if($transactionBin == FALSE) {
|
||||
//$this->addError('base64 decode failed');
|
||||
$this->addError(['data' => $base64Data, 'bin' => $transactionBin, 'msg' => 'base64 decode error']);
|
||||
} else {
|
||||
$this->mProtoTransaction = new \Model\Messages\Gradido\Transaction();
|
||||
$this->mProtoTransaction->mergeFromString($transactionBin);
|
||||
|
||||
$this->mProtoTransactionBody = new \Model\Messages\Gradido\TransactionBody();
|
||||
$this->mProtoTransactionBody->mergeFromString($this->mProtoTransaction->getBodyBytes());
|
||||
|
||||
$data = $this->mProtoTransactionBody->getData();
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function validate() {
|
||||
$sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair();
|
||||
$bodyBytes = $this->mProtoTransaction->getBodyBytes();
|
||||
|
||||
// check signature(s)
|
||||
foreach($sigPairs as $sigPair) {
|
||||
$pubkey = $sigPair->getPubKey();
|
||||
$signature = $sigPair->getEd25519();
|
||||
if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) {
|
||||
$this->addError('signature for key ' . bin2hex($pubkey) . ' isn\'t valid ' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getErrors() {
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
public function hasErrors() {
|
||||
return count($this->errors) > 0;
|
||||
}
|
||||
|
||||
|
||||
private function addError($message) {
|
||||
array_push($this->errors, $message);
|
||||
}
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
namespace Model\Transactions;
|
||||
|
||||
//use Model\Messages\Gradido\Transaction;
|
||||
//use Model\Messages\Gradido\TransactionBody;
|
||||
|
||||
class Transaction extends TransactionBase {
|
||||
|
||||
private $mProtoTransaction = null;
|
||||
private $mProtoTransactionBody = null;
|
||||
private $errors = [];
|
||||
|
||||
public function __construct($base64Data) {
|
||||
$transactionBin = base64_decode($base64Data);
|
||||
if($transactionBin == FALSE) {
|
||||
//$this->addError('base64 decode failed');
|
||||
$this->addError(['data' => $base64Data, 'bin' => $transactionBin, 'msg' => 'base64 decode error']);
|
||||
} else {
|
||||
$this->mProtoTransaction = new \Model\Messages\Gradido\Transaction();
|
||||
$this->mProtoTransaction->mergeFromString($transactionBin);
|
||||
|
||||
$this->mProtoTransactionBody = new \Model\Messages\Gradido\TransactionBody();
|
||||
$this->mProtoTransactionBody->mergeFromString($this->mProtoTransaction->getBodyBytes());
|
||||
|
||||
$data = $this->mProtoTransactionBody->getData();
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function validate() {
|
||||
$sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair();
|
||||
$bodyBytes = $this->mProtoTransaction->getBodyBytes();
|
||||
|
||||
// check signature(s)
|
||||
foreach($sigPairs as $sigPair) {
|
||||
$pubkey = $sigPair->getPubKey();
|
||||
$signature = $sigPair->getEd25519();
|
||||
if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) {
|
||||
$this->addError('signature for key ' . bin2hex($pubkey) . ' isn\'t valid ' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getErrors() {
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
public function hasErrors() {
|
||||
return count($this->errors) > 0;
|
||||
}
|
||||
|
||||
|
||||
private function addError($message) {
|
||||
array_push($this->errors, $message);
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Model\Transactions;
|
||||
|
||||
class TransactionBase {
|
||||
|
||||
<?php
|
||||
|
||||
namespace Model\Transactions;
|
||||
|
||||
class TransactionBase {
|
||||
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package model.messages.gradido;
|
||||
|
||||
message Key {
|
||||
oneof key {
|
||||
bytes ed25519 = 2; // ed25519 signature (libsodium default)
|
||||
bytes ed25519_ref10 = 3; // ed25519 ref10 signature
|
||||
}
|
||||
}
|
||||
|
||||
message SignaturePair {
|
||||
bytes pubKey = 1;
|
||||
oneof signature {
|
||||
bytes ed25519 = 2; // ed25519 signature (libsodium default)
|
||||
bytes ed25519_ref10 = 3; // ed25519 ref10 signature
|
||||
}
|
||||
}
|
||||
|
||||
message SignatureMap {
|
||||
repeated SignaturePair sigPair = 1; // Each signature pair corresponds to a unique Key required to sign the transaction.
|
||||
}
|
||||
|
||||
/* An exact date and time. This is the same data structure as the protobuf Timestamp.proto (see the comments in https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto) */
|
||||
message Timestamp {
|
||||
int64 seconds = 1; // Number of complete seconds since the start of the epoch
|
||||
int32 nanos = 2; // Number of nanoseconds since the start of the last second
|
||||
}
|
||||
|
||||
/* An exact date and time, with a resolution of one second (no nanoseconds). */
|
||||
message TimestampSeconds {
|
||||
int64 seconds = 1; // Number of complete seconds since the start of the epoch
|
||||
}
|
||||
|
||||
message SenderAmount {
|
||||
bytes ed25519_sender_pubkey = 1;
|
||||
sint64 amount = 2;
|
||||
sint64 senderFinalBalance = 3; // sender balance after transaction, including perishability
|
||||
}
|
||||
|
||||
message ReceiverAmount {
|
||||
bytes ed25519_receiver_pubkey = 1;
|
||||
sint64 amount = 2;
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package model.messages.gradido;
|
||||
|
||||
import "BasicTypes.proto";
|
||||
|
||||
// need signature from this group and from parent (if it isn't zero)
|
||||
message StateCreateGroup {
|
||||
string name = 1;
|
||||
Key groupPublicKey = 2;
|
||||
Key parentGroupPublicKey = 3;
|
||||
reserved "hederaConsensusId";
|
||||
reserved 4;
|
||||
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package model.messages.gradido;
|
||||
|
||||
import "BasicTypes.proto";
|
||||
|
||||
// need signature from this group and from both parents (if it isn't zero)
|
||||
message StateGroupChangeParent {
|
||||
Key groupPublicKey = 1;
|
||||
Key newParentGroupPublicKey = 2;
|
||||
Key oldParentGroupPublicKey = 3;
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package model.messages.gradido;
|
||||
|
||||
import "BasicTypes.proto";
|
||||
|
||||
/*
|
||||
id will be set by Node server
|
||||
txHash will be also set by Node server,
|
||||
calculated from previous transaction txHash and this id, sigMap and received;
|
||||
*/
|
||||
|
||||
message Transaction {
|
||||
uint64 id = 1;
|
||||
TimestampSeconds received = 2;
|
||||
SignatureMap sigMap = 3;
|
||||
bytes txHash = 4;
|
||||
bytes bodyBytes = 5;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package model.messages.gradido;
|
||||
|
||||
import "Transfer.proto";
|
||||
import "StateCreateGroup.proto";
|
||||
import "StateGroupChangeParent.proto";
|
||||
import "TransactionCreation.proto";
|
||||
|
||||
message TransactionBody {
|
||||
string memo = 1; // max 150 chars
|
||||
oneof data {
|
||||
StateCreateGroup createGroup = 2;
|
||||
StateGroupChangeParent groupChangeParent = 3;
|
||||
Transfer transfer = 4;
|
||||
TransactionCreation creation = 5;
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package model.messages.gradido;
|
||||
|
||||
import "BasicTypes.proto";
|
||||
|
||||
// need signature from group admin or
|
||||
// percent of group users another than the receiver
|
||||
message TransactionCreation {
|
||||
ReceiverAmount receiverAmount = 1;
|
||||
sint32 ident_hash = 2;
|
||||
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package model.messages.gradido;
|
||||
|
||||
import "BasicTypes.proto";
|
||||
|
||||
message Transfer {
|
||||
repeated SenderAmount senderAmounts = 1;
|
||||
repeated ReceiverAmount receiverAmounts = 2;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user