Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove ipfs and second signature types #117

Merged
Merged
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
22 changes: 9 additions & 13 deletions packages/mainsail/source/client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ export class ClientService extends Services.AbstractClientService {
};

const mappings: Record<string, string> = {
address: "address",
cursor: "page",
limit: "limit",
memo: "vendorField",
orderBy: "orderBy",
address: "address",
recipientId: "recipientId",
senderId: "senderId",
senderPublicKey: "senderPublicKey",
Expand Down Expand Up @@ -219,14 +219,6 @@ export class ClientService extends Services.AbstractClientService {
type: Enums.TransactionType.DelegateResignation,
typeGroup: Enums.TransactionTypeGroup.Core,
},
usernameRegistration: {
type: Enums.TransactionType.UsernameRegistration,
typeGroup: Enums.TransactionTypeGroup.Core,
},
usernameResignation: {
type: Enums.TransactionType.UsernameResignation,
typeGroup: Enums.TransactionTypeGroup.Core,
},
multiPayment: {
type: Enums.TransactionType.MultiPayment,
typeGroup: Enums.TransactionTypeGroup.Core,
Expand All @@ -235,14 +227,18 @@ export class ClientService extends Services.AbstractClientService {
type: Enums.TransactionType.MultiSignature,
typeGroup: Enums.TransactionTypeGroup.Core,
},
secondSignature: {
type: Enums.TransactionType.SecondSignature,
typeGroup: Enums.TransactionTypeGroup.Core,
},
transfer: {
type: Enums.TransactionType.Transfer,
typeGroup: Enums.TransactionTypeGroup.Core,
},
usernameRegistration: {
type: Enums.TransactionType.UsernameRegistration,
typeGroup: Enums.TransactionTypeGroup.Core,
},
usernameResignation: {
type: Enums.TransactionType.UsernameResignation,
typeGroup: Enums.TransactionTypeGroup.Core,
},
vote: {
type: Enums.TransactionType.Vote,
typeGroup: Enums.TransactionTypeGroup.Core,
Expand Down
2 changes: 1 addition & 1 deletion packages/mainsail/source/confirmed-transaction.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ConfirmedTransactionData extends DTO.AbstractConfirmedTransactionDa
}

public override isSecondSignature(): boolean {
return TransactionTypeService.isSecondSignature(this.data);
throw new Exceptions.NotImplemented(this.constructor.name, this.isSecondSignature.name);
}

public override isUsernameRegistration(): boolean {
Expand Down
1 change: 0 additions & 1 deletion packages/mainsail/source/crypto/enums.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export enum TransactionType {
Transfer = 0,
SecondSignature = 1,
DelegateRegistration = 2,
Vote = 3,
MultiSignature = 4,
Expand Down
6 changes: 0 additions & 6 deletions packages/mainsail/source/crypto/interfaces/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export interface ITransactionAsset {
votes?: string[];
multiSignatureLegacy?: IMultiSignatureLegacyAsset;
multiSignature?: IMultiSignatureAsset;
ipfs?: string;
payments?: IMultiPaymentItem[];
}

Expand All @@ -63,7 +62,6 @@ export interface ITransactionData {

id?: string;
signature?: string;
secondSignature?: string;
signSignature?: string;
signatures?: string[];

Expand Down Expand Up @@ -94,14 +92,11 @@ export interface ITransactionJson {

id?: string;
signature?: string;
secondSignature?: string;
signSignature?: string;
signatures?: string[];

blockId?: string;
sequence?: number;

ipfsHash?: string;
}

export interface ISchemaValidationResult<T = any> {
Expand Down Expand Up @@ -139,6 +134,5 @@ export interface ISerializeOptions {
acceptLegacyVersion?: boolean;
disableVersionCheck?: boolean;
excludeSignature?: boolean;
excludeSecondSignature?: boolean;
excludeMultiSignature?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export const milestones = [
staticFees: {
delegateRegistration: 2_500_000_000,
delegateResignation: 2_500_000_000,
usernameRegistration: 2_500_000_000,
usernameResignation: 2_500_000_000,
htlcClaim: 0,
htlcLock: 10_000_000,
htlcRefund: 0,
Expand All @@ -23,6 +21,8 @@ export const milestones = [
multiSignature: 500_000_000,
secondSignature: 500_000_000,
transfer: 10_000_000,
usernameRegistration: 2_500_000_000,
usernameResignation: 2_500_000_000,
vote: 100_000_000,
},
},
Expand Down
12 changes: 1 addition & 11 deletions packages/mainsail/source/crypto/transactions/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ export class Deserializer {
return marker === 255;
};

// Second Signature
if (buf.getRemainderLength() && !beginningMultiSignature()) {
const secondSignatureLength: number = currentSignatureLength();
transaction.secondSignature = buf.readBuffer(secondSignatureLength).toString("hex");
}

// Multi Signatures
if (buf.getRemainderLength() && beginningMultiSignature()) {
buf.jump(1);
Expand All @@ -106,17 +100,13 @@ export class Deserializer {
transaction.signature = buf.readBuffer(64).toString("hex");
}

if (canReadNonMultiSignature()) {
transaction.secondSignature = buf.readBuffer(64).toString("hex");
}

if (buf.getRemainderLength()) {
if (buf.getRemainderLength() % 65 === 0) {
transaction.signatures = [];

const count: number = buf.getRemainderLength() / 65;
const publicKeyIndexes: { [index: number]: boolean } = {};
for (let i = 0; i < count; i++) {
for (let index = 0; index < count; index++) {
const multiSignaturePart: string = buf.readBuffer(65).toString("hex");
const publicKeyIndex: number = Number.parseInt(multiSignaturePart.slice(0, 2), 16);

Expand Down
6 changes: 0 additions & 6 deletions packages/mainsail/source/crypto/transactions/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export class Serializer {
buf.writeBuffer(Buffer.from(transaction.signature, "hex"));
}

const secondSignature: string | undefined = transaction.secondSignature || transaction.signSignature;

if (secondSignature && !options.excludeSecondSignature) {
buf.writeBuffer(Buffer.from(secondSignature, "hex"));
}

if (transaction.signatures && !options.excludeMultiSignature) {
buf.writeBuffer(Buffer.from(transaction.signatures.join(""), "hex"));
}
Expand Down
15 changes: 2 additions & 13 deletions packages/mainsail/source/crypto/transactions/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Utils } from "./utils.js";

export class Signer {
public static sign(transaction: ITransactionData, keys: IKeyPair, options?: ISerializeOptions): string {
if (!options || (options.excludeSignature === undefined && options.excludeSecondSignature === undefined)) {
options = { excludeSecondSignature: true, excludeSignature: true, ...options };
if (!options || options.excludeSignature === undefined) {
options = { excludeSignature: true, ...options };
}

const hash: Buffer = Utils.toHash(transaction, options);
Expand All @@ -20,17 +20,6 @@ export class Signer {
return signature;
}

public static secondSign(transaction: ITransactionData, keys: IKeyPair): string {
const hash: Buffer = Utils.toHash(transaction, { excludeSecondSignature: true });
const signature: string = Hash.signSchnorr(hash, keys);

if (!transaction.secondSignature) {
transaction.secondSignature = signature;
}

return signature;
}

public static async multiSign(
transaction: MainsailContracts.Crypto.TransactionData,
keys: IKeyPair,
Expand Down
64 changes: 19 additions & 45 deletions packages/mainsail/source/crypto/transactions/types/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TransactionType } from "../../enums.js";
import deepmerge from "deepmerge";

import { TransactionType } from "../../enums.js";

const signedTransaction = {
anyOf: [
{ required: ["id", "signature"] },
Expand All @@ -23,11 +24,9 @@ export const transactionBaseSchema: Record<string, any> = {
id: { anyOf: [{ $ref: "transactionId" }, { type: "null" }] },
network: { $ref: "networkByte" },
nonce: { bignumber: { minimum: 0 } },
secondSignature: { $ref: "alphanumeric" },
senderPublicKey: { $ref: "publicKey" },
signSignature: { $ref: "alphanumeric" },
signature: { $ref: "alphanumeric" },
version: { enum: [1, 2] },
signatures: {
additionalItems: false,
items: { allOf: [{ maxLength: 130, minLength: 130 }, { $ref: "alphanumeric" }] },
Expand All @@ -36,8 +35,9 @@ export const transactionBaseSchema: Record<string, any> = {
type: "array",
uniqueItems: true,
},
timestamp: { type: "integer", minimum: 0 },
timestamp: { minimum: 0, type: "integer" },
typeGroup: { minimum: 0, type: "integer" },
version: { enum: [1, 2] },
},
then: { required: ["type", "senderPublicKey", "fee", "amount", "timestamp"] },
type: "object",
Expand Down Expand Up @@ -70,32 +70,6 @@ export const transfer = extend(transactionBaseSchema, {
required: ["recipientId"],
});

export const secondSignature = extend(transactionBaseSchema, {
$id: "secondSignature",
properties: {
amount: { bignumber: { maximum: 0, minimum: 0 } },
asset: {
properties: {
signature: {
properties: {
publicKey: {
$ref: "publicKey",
},
},
required: ["publicKey"],
type: "object",
},
},
required: ["signature"],
type: "object",
},
fee: { bignumber: { minimum: 1 } },
secondSignature: { type: "null" },
type: { transactionType: TransactionType.SecondSignature },
},
required: ["asset"],
});

export const delegateRegistration = extend(transactionBaseSchema, {
$id: "delegateRegistration",
properties: {
Expand Down Expand Up @@ -150,8 +124,8 @@ export const vote = extend(transactionBaseSchema, {
votes: {
additionalItems: false,
items: { $ref: "walletVote" },
minItems: 1,
maxItems: 2,
minItems: 1,
type: "array",
},
},
Expand Down Expand Up @@ -180,10 +154,10 @@ export const multiSignature = extend(transactionBaseSchema, {
},
publicKeys: {
additionalItems: false,
minItems: 1,
items: { $ref: "publicKey" },
type: "array",
maxItems: 16,
minItems: 1,
type: "array",
uniqueItems: true,
},
},
Expand Down Expand Up @@ -220,24 +194,24 @@ export const multiSignatureLegacy = extend(transactionBaseSchemaNoSignatures, {
properties: {
multiSignatureLegacy: {
properties: {
lifetime: {
minimum: 1,
type: "integer",
maximum: 72,
},
keysgroup: {
minItems: 1,
type: "array",
additionalItems: false,
maxItems: 16,
items: {
allOf: [{ minimum: 67, type: "string", maximum: 67, transform: ["toLowerCase"] }],
allOf: [{ maximum: 67, minimum: 67, transform: ["toLowerCase"], type: "string" }],
},
maxItems: 16,
minItems: 1,
type: "array",
},
min: {
type: "integer",
lifetime: {
maximum: 72,
minimum: 1,
type: "integer",
},
min: {
maximum: { $data: "1/keysgroup/length" },
minimum: 1,
type: "integer",
},
},
required: ["keysgroup", "min", "lifetime"],
Expand Down Expand Up @@ -270,11 +244,11 @@ export const multiPayment = extend(transactionBaseSchema, {
payments: {
additionalItems: false,
items: {
required: ["amount", "recipientId"],
properties: {
amount: { bignumber: { minimum: 1 } },
recipientId: { $ref: "address" },
},
required: ["amount", "recipientId"],
type: "object",
},
minItems: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ export abstract class Transaction implements ITransaction {
return Verifier.verify(this.data, options);
}

public verifySecondSignature(publicKey: string): boolean {
return Verifier.verifySecondSignature(this.data, publicKey);
}

public verifySchema(): ISchemaValidationResult {
return Verifier.verifySchema(this.data);
}
Expand Down
Loading
Loading