Skip to content

Commit

Permalink
refactor(crypto-transaction): use RLP for serialization (#800)
Browse files Browse the repository at this point in the history
* Remove getBytes

* Remove serialize from tx

* Move assetSize to serializer

* Remove deserialize

* Recoverable signature works with EcdsaSignature

* Use v r s values in transaction

* Use RLp serialization

* Regenerate crypto

* Fix tests

* Update e2e tests

* Fix serializer

* Fix tests

* Fix test-framework tests

* Enable tests

* style: resolve style guide violations

* Fix deps

* Enable all tests

* Remove console logs

* Regenerate crypto

---------

Co-authored-by: sebastijankuzner <[email protected]>
  • Loading branch information
sebastijankuzner and sebastijankuzner authored Jan 7, 2025
1 parent 16b8aef commit 0d51fd9
Show file tree
Hide file tree
Showing 43 changed files with 2,383 additions and 2,063 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ jobs:
run: cd packages/cli && pnpm run test
- name: Test configuration-generator
run: cd packages/configuration-generator && pnpm run test
# - name: Test consensus
# run: cd packages/consensus && pnpm run test
- name: Test consensus
run: cd packages/consensus && pnpm run test
- name: Test consensus-storage
run: cd packages/consensus-storage && pnpm run test
- name: Test container
Expand Down Expand Up @@ -204,8 +204,8 @@ jobs:
run: cd packages/processor && pnpm run test
- name: Test serializer
run: cd packages/serializer && pnpm run test
# - name: Test state
# run: cd packages/state && pnpm run test
- name: Test state
run: cd packages/state && pnpm run test
- name: Test test-framework
run: cd packages/test-framework && pnpm run test
- name: Test test-runner
Expand All @@ -224,8 +224,8 @@ jobs:
run: cd packages/utils && pnpm run test
- name: Test validation
run: cd packages/validation && pnpm run test
# - name: Test validator
# run: cd packages/validator && pnpm run test
- name: Test validator
run: cd packages/validator && pnpm run test
- name: Test webhooks
run: cd packages/webhooks && pnpm run test

Expand Down
3 changes: 2 additions & 1 deletion packages/api-sync/source/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ export class Restore {
senderAddress: data.senderAddress,
senderPublicKey: data.senderPublicKey,
sequence: data.sequence as unknown as number,
signature: data.signature,
// signature: data.signature,
signature: "",
signatures: undefined, //data.signatures,
timestamp: block.header.timestamp.toFixed(),
});
Expand Down
3 changes: 2 additions & 1 deletion packages/api-sync/source/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ export class Sync implements Contracts.ApiSync.Service {
senderAddress: data.senderAddress,
senderPublicKey: data.senderPublicKey,
sequence: data.sequence as unknown as number,
signature: data.signature,
// signature: data.signature,
signature: "",
signatures: undefined, //data.signatures,
timestamp: header.timestamp.toFixed(),
})),
Expand Down
8 changes: 4 additions & 4 deletions packages/configuration-generator/bin/create-genesis-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ async function run() {
symbol: "TѦ",
token: "ARK",
distribute: true,
premine: "0",
snapshot: {
path: "../../snapshot-19a87c96dbe8ad1be06d33e97cd17f5662eb952c29efd3d8bb00c9c75e7582bc.json",
},
premine: "12499999999999969",
// snapshot: {
// path: "../../snapshot-19a87c96dbe8ad1be06d33e97cd17f5662eb952c29efd3d8bb00c9c75e7582bc.json",
// },
});
}

Expand Down
12 changes: 9 additions & 3 deletions packages/contracts/source/contracts/crypto/identities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export interface PublicKeySerializer {
deserialize(buffer: ByteBuffer): Buffer;
}

export interface EcdsaSignature {
r: string;
s: string;
v: number;
}

export interface Signature {
sign(message: Buffer, privateKey: Buffer): Promise<string>;

Expand All @@ -81,9 +87,9 @@ export interface Signature {

aggregate(signatures: Buffer[]): Promise<string>;

signRecoverable(message: Buffer, privateKey: Buffer): Promise<string>;
signRecoverable(message: Buffer, privateKey: Buffer): Promise<EcdsaSignature>;

verifyRecoverable(signature: Buffer, message: Buffer, publicKey: Buffer): Promise<boolean>;
verifyRecoverable(signature: EcdsaSignature, message: Buffer, publicKey: Buffer): Promise<boolean>;

recoverPublicKey(message: Buffer, signature: Buffer): string;
recoverPublicKey(message: Buffer, signature: EcdsaSignature): string;
}
28 changes: 9 additions & 19 deletions packages/contracts/source/contracts/crypto/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber, ByteBuffer } from "@mainsail/utils";
import { BigNumber } from "@mainsail/utils";

import type { KeyPair } from "./identities.js";
import type { EcdsaSignature, KeyPair } from "./identities.js";
import type { SchemaValidationResult } from "./validator.js";

export interface Transaction {
Expand All @@ -9,20 +9,10 @@ export interface Transaction {

data: TransactionData;
serialized: Buffer;

assetSize(): number;
serialize(options?: SerializeOptions): Promise<ByteBuffer>;
deserialize(buf: ByteBuffer): Promise<void>;
}

export type TransactionSchema = Record<string, any>;

export interface EcdsaSignature {
r: string;
s: string;
v: number;
}

export interface TransactionData {
network: number;

Expand All @@ -41,7 +31,9 @@ export interface TransactionData {
id: string;
timestamp: number;

signature?: string;
v?: number;
r?: string;
s?: string;
legacySecondSignature?: string;

sequence?: number;
Expand All @@ -68,7 +60,9 @@ export interface TransactionJson {
id?: string;
timestamp?: number;

signature?: string;
v?: number;
r?: string;
s?: string;

sequence?: number;
gasUsed?: number;
Expand Down Expand Up @@ -108,20 +102,16 @@ export interface TransactionVerifier {
}

export interface TransactionSigner {
sign(transaction: TransactionData, keys: KeyPair, options?: SerializeOptions): Promise<string>;
sign(transaction: TransactionData, keys: KeyPair, options?: SerializeOptions): Promise<EcdsaSignature>;
multiSign(transaction: TransactionData, keys: KeyPair, index?: number): Promise<string>;
}

export interface TransactionSerializer {
getBytes(transaction: TransactionData, options?: SerializeOptions): Promise<Buffer>;

serialize(transaction: Transaction, options?: SerializeOptions): Promise<Buffer>;
}

export interface TransactionDeserializer {
deserialize(serialized: string | Buffer): Promise<Transaction>;

deserializeCommon(transaction: TransactionData, buf: ByteBuffer): void;
}

export interface TransactionFactory {
Expand Down
Loading

0 comments on commit 0d51fd9

Please sign in to comment.