Skip to content

Commit

Permalink
Refactor proof types
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Jul 18, 2024
1 parent 01e9556 commit 2999c8c
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 81 deletions.
172 changes: 91 additions & 81 deletions src/api/chain/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,91 +341,101 @@ export declare enum TxType {
UNRECOGNIZED = -1,
}

export interface Proof {
payload?:
| {
$case: 'graviton';
graviton: {
siblings: Uint8Array;
};
}
| {
$case: 'iden3';
iden3: {
siblings: Uint8Array;
};
}
| {
$case: 'ethereumStorage';
ethereumStorage: {
export type GravitonType = {
graviton: {
siblings: Uint8Array;
};
};

export type Id3Type = {
iden3: {
siblings: Uint8Array;
};
};

export type EthereumStorageType = {
ethereumStorage: {
key: Uint8Array;
value: Uint8Array;
siblings: Uint8Array[];
};
};

export type EthereumAccountType = {
ethereumAccount: {
nonce: Uint8Array;
/** Big Int encoded as bytes */
balance: Uint8Array;
storageHash: Uint8Array;
codeHash: Uint8Array;
siblings: Uint8Array[];
};
};

export type CAType = {
ca: {
type: ProofCA_Type;
bundle:
| {
processId: Uint8Array;
address: Uint8Array;
}
| undefined;
signature: Uint8Array;
};
};

export type ArboType = {
arbo: {
type: ProofArbo_Type;
siblings: Uint8Array;
value: Uint8Array;
keyType: ProofArbo_KeyType;
};
};

export type ZkSnarkType = {
zkSnark: {
circuitParametersIndex: number;
a: string[];
b: string[];
c: string[];
publicInputs: string[];
};
};

export type MinimeStorageType = {
minimeStorage: {
proofPrevBlock:
| {
key: Uint8Array;
value: Uint8Array;
siblings: Uint8Array[];
};
}
| {
$case: 'ethereumAccount';
ethereumAccount: {
nonce: Uint8Array;
/** Big Int encoded as bytes */
balance: Uint8Array;
storageHash: Uint8Array;
codeHash: Uint8Array;
siblings: Uint8Array[];
};
}
| {
$case: 'ca';
ca: {
type: ProofCA_Type;
bundle:
| {
processId: Uint8Array;
address: Uint8Array;
}
| undefined;
signature: Uint8Array;
};
}
| {
$case: 'arbo';
arbo: {
type: ProofArbo_Type;
siblings: Uint8Array;
}
| undefined;
proofNextBlock?:
| {
key: Uint8Array;
value: Uint8Array;
keyType: ProofArbo_KeyType;
};
}
| {
$case: 'zkSnark';
zkSnark: {
circuitParametersIndex: number;
a: string[];
b: string[];
c: string[];
publicInputs: string[];
};
}
| {
$case: 'minimeStorage';
minimeStorage: {
proofPrevBlock:
| {
key: Uint8Array;
value: Uint8Array;
siblings: Uint8Array[];
}
| undefined;
proofNextBlock?:
| {
key: Uint8Array;
value: Uint8Array;
siblings: Uint8Array[];
}
| undefined;
};
};
}
siblings: Uint8Array[];
}
| undefined;
};
};

export type Proof =
| GravitonType
| Id3Type
| EthereumStorageType
| EthereumAccountType
| CAType
| ArboType
| ZkSnarkType
| MinimeStorageType;

// export interface Proof {
// payload: ProofTypes;
// }

declare enum ProofCA_Type {
UNKNOWN = 0,
Expand Down
34 changes: 34 additions & 0 deletions src/api/chain/typeguards.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import {
AdminTxType,
ArboType,
CAType,
CollectFaucetTxType,
EthereumAccountType,
EthereumStorageType,
GravitonType,
Id3Type,
MinimeStorageType,
MintTokensTxType,
NewProcessTxType,
Proof,
RegisterKeyTxType,
SendTokensTxType,
SetAccountTxType,
SetProcessTxType,
SetTransactionCostsTxType,
TxTypes,
VoteEnvelopeType,
ZkSnarkType,
} from './transactions';
import { TransactionType } from '../chain';

Expand Down Expand Up @@ -52,3 +61,28 @@ export const isSetAccountTx = (tx: TxTypes): tx is SetAccountTxType => {
export const isCollectFaucetTx = (tx: TxTypes): tx is CollectFaucetTxType => {
return TransactionType.COLLECT_FAUCET_TX in tx;
};

export const isGravitonType = (proof: Proof): proof is GravitonType => {
return 'graviton' in proof;
};
export const isId3Type = (proof: Proof): proof is Id3Type => {
return 'iden3' in proof;
};
export const isEthereumStorageType = (proof: Proof): proof is EthereumStorageType => {
return 'ethereumStorage' in proof;
};
export const isEthereumAccountType = (proof: Proof): proof is EthereumAccountType => {
return 'ethereumAccount' in proof;
};
export const isCAType = (proof: Proof): proof is CAType => {
return 'ca' in proof;
};
export const isArboType = (proof: Proof): proof is ArboType => {
return 'arbo' in proof;
};
export const isZkSnarkType = (proof: Proof): proof is ZkSnarkType => {
return 'zkSnark' in proof;
};
export const isMinimeStorageType = (proof: Proof): proof is MinimeStorageType => {
return 'minimeStorage' in proof;
};

0 comments on commit 2999c8c

Please sign in to comment.