Skip to content

Commit

Permalink
Merge branch 'master' into import-export-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
tammo committed Sep 25, 2019
2 parents 5ae6fad + 27f8688 commit 8ae67cf
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 31 deletions.
7 changes: 5 additions & 2 deletions etc/sqlite/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ CREATE TABLE IF NOT EXISTS blockchains (

CREATE TABLE IF NOT EXISTS blocks (
id VARCHAR(64) UNIQUE PRIMARY KEY NOT NULL,
chain_id VARCHAR(64) NOT NULL,
chain_id VARCHAR(64) NOT NULL,
type TEXT NOT NULL,
prev TEXT UNIQUE,
signature TEXT UNIQUE NOT NULL,
payload TEXT,
ref_block TEXT,
commitment_amount TEXT,
commitment_balance TEXT,
rangeproof_amount TEXT,
rangeproof_balance TEXT,
receiver_amount TEXT,
receiver_blinding_factor_amount TEXT,
sender_blinding_factor_balance TEXT,
sender_balance TEXT,
sender_amount TEXT,
FOREIGN KEY (chain_id) REFERENCES blockchains(id),
FOREIGN KEY (prev) REFERENCES blocks(signature),
FOREIGN KEY (reference) REFERENCES blocks(signature)
FOREIGN KEY (ref_block) REFERENCES blocks(signature)
);

-- example queries
Expand Down
3 changes: 3 additions & 0 deletions etc/sqlite/sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
| prev | FK -> blocks.signature, unique | **TEXT** signature reference to chain blocks |
| signature | unique, not null | **TEXT** own block signature |
| payload | - | **TEXT** encrypted arbitrary data that is stored on the blockchain |
| ref_block | FK -> blocks.signature | **TEXT** signature reference to a block of another chain |
| commitment_amount | - | **TEXT** pedersen amount commitment |
| commitment_balance | - | **TEXT** pedersen balance commitment |
| receiver_amount | - | **TEXT** encrypted amount for the receiving party |
| receiver_blinding_factor_amount | - | **TEXT** encrypted blinding factor for the receiving party |
| sender_blinding_factor_balance | - | **TEXT** encrypted blinding factor for the sending party |
| sender_balance | - | **TEXT** encrypted balance factor for the sending party |
| sender_amount | - | **TEXT** encrypted amount for the sending party |
| rangeproof_amount | - | **TEXT** rangeproof commitment |
| rangeproof_balance | - | **TEXT** rangeproof commitment |

### transactions

Expand Down
25 changes: 18 additions & 7 deletions src/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ import { StorageId } from './Blockchain';
export type EncryptedNumber = string;
export type EncryptedString = string;
export type Signature = string;
export type SignatureData = {};
export type SignatureData = {
type: string;
prev: string | null;
payload: string;
amountCommitment: string;
balanceCommitment: string;
amountRangeProof: string;
balanceRangeProof: string;
receiverAmount: string;
receiverBlindingFactorAmount: string;
senderBlindingFactorBalance: string;
senderBalance: string;
senderAmount: string;
};

export enum BlockType {
OPENING = 'OPENING',
Expand All @@ -18,19 +31,17 @@ export type Block = {
type: BlockType;
prev: Signature | null;
payload: EncryptedString;
refBlock: Signature | null;
amountCommitment: string;
balanceCommitment: string;
amountRangeProof: string;
balanceRangeProof: string;
receiverAmount: EncryptedNumber;
receiverBlindingFactorAmount: EncryptedString;
senderBlindingFactorBalance: EncryptedString;
senderBalance: EncryptedNumber;
senderAmount: EncryptedNumber;

getDataForSignature(): SignatureData;
isValid(): boolean;
setAmount(publicKey: string, amount: number): Block;
setBalance(publicKey: string, balance: number): Block;
validateCommitment(): boolean;
verifySignature(accountOwnersPublicKey: string): boolean;
clone(): Block;
setAmount(amount: number, balance: number, prev: Block): void;
};
10 changes: 5 additions & 5 deletions src/Blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Block } from './Block';
import { PublicKey } from './Keys';
import { SigPublicKey } from './Keys';

export type StorageId = string;

export type Blockchain = {
id: StorageId;
leafId: StorageId | null;
publicKey: PublicKey;
leafId: StorageId | undefined;
publicKey: SigPublicKey;
blocks: Block[];

addBlock(block: Block): Blockchain;
leaf(): Block | null;
addBlock(block: Block): void;
leaf(): Block | undefined;
};
3 changes: 0 additions & 3 deletions src/GenesisBlock.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/Keys.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export type PrivateKey = string;
export type PublicKey = string;
export type NTRUPrivateKey = string;
export type NTRUPublicKey = string;
export type SigPublicKey = string;
export type SigPrivateKey = string;
8 changes: 4 additions & 4 deletions src/Ledger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Block, Signature } from './Block';
import { Blockchain } from './Blockchain';
import { PublicKey } from './Keys';
import { SigPublicKey } from './Keys';
import { Transaction } from './Transaction';
import { InMemory } from './Storage';

Expand All @@ -9,17 +9,17 @@ export type Ledger = {
* Save one transaction to the ledger. If inMemory is used, all transactions are saved in-memory.
* Returns the tx, if it is validated and saved.
*/
process(txs: Transaction, inMemory?: InMemory): Promise<Transaction>;
process(txs: Transaction, inMemory?: InMemory): Promise<Transaction | undefined>;

/**
* Validate a transaction against the existing blockchain data.
*/
validate(tx: Transaction, inMemory?: InMemory): Promise<Transaction>;
validate(tx: Transaction, inMemory?: InMemory): Promise<Transaction | undefined>;

/**
* Returns a blockchain identified by its public key.
*/
getBlockchain(publicKey: PublicKey): Promise<Blockchain>;
getBlockchain(key: SigPublicKey): Promise<Blockchain | undefined>;

/**
* Return blocks identified by the given signatures.
Expand Down
12 changes: 6 additions & 6 deletions src/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Block, Signature } from './Block';
import { Blockchain } from './Blockchain';
import { PublicKey } from './Keys';
import { SigPublicKey } from './Keys';

export type InMemory = {
db: any;
Expand All @@ -19,11 +19,11 @@ export type Storage = {
*/
persistChains(blockchains: Blockchain[], db?: any): Promise<Blockchain[]>;

findBlockchain(publicKey: PublicKey): Promise<Blockchain>;
findLeafBlocks(publicKey?: PublicKey): Promise<Block[]>;
findBlocks(signatures: Signature[]): Promise<Block[]>;
findPk(publicKey: PublicKey, db?: any): Promise<PublicKey>;
findSignatures(signatures: Signature[], db?: any): Promise<Signature[]>;
findBlockchain(publicKey: SigPublicKey, db?: any): Promise<Blockchain | undefined>;
findLeafBlocks(publicKey?: SigPublicKey, db?: any): Promise<Block[]>;
findBlocks(signatures: Signature[], publicKey?: SigPublicKey, db?: any): Promise<Block[]>;
findPk(publicKey: SigPublicKey, db?: any): Promise<SigPublicKey | undefined>;
findSignatures(signatures: Signature[], publicKey?: SigPublicKey, db?: any): Promise<Signature[]>;
findPrevSignatures(signatures: Signature[], db?: any): Promise<Signature[]>;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Block } from './Block';
import { PublicKey } from './Keys';
import { SigPublicKey } from './Keys';

export type Transaction = {
/**
Expand All @@ -10,7 +10,7 @@ export type Transaction = {
/**
* Is always the public key of the related block chain.
*/
publicKey: PublicKey;
publicKey: SigPublicKey;

/**
* Proof that a certain amount of work was burned.
Expand Down

0 comments on commit 8ae67cf

Please sign in to comment.