Skip to content
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
4 changes: 0 additions & 4 deletions packages/contracts/source/contracts/crypto/identities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { ByteBuffer } from "@mainsail/utils";

import type { MultiSignatureAsset } from "./legacy.js";

export interface KeyPair {
publicKey: string;
privateKey: string;
Expand All @@ -12,7 +10,6 @@ export interface AddressFactory {
fromMnemonic(mnemonic: string): Promise<string>;
fromPublicKey(publicKey: string): Promise<string>;
fromWIF(wif: string): Promise<string>;
fromMultiSignatureAsset(asset: MultiSignatureAsset): Promise<string>;
fromBuffer(buffer: Buffer): Promise<string>;
toBuffer(address: string): Promise<Buffer>;
validate(address: string): Promise<boolean>;
Expand All @@ -21,7 +18,6 @@ export interface AddressFactory {
export interface PublicKeyFactory {
fromMnemonic(mnemonic: string): Promise<string>;
fromWIF(wif: string): Promise<string>;
fromMultiSignatureAsset(asset: MultiSignatureAsset): Promise<string>;
verify(publicKey: string): Promise<boolean>;
aggregate(publicKeys: Buffer[]): Promise<string>;
}
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/source/contracts/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export * from "./config.js";
export * from "./crypto.js";
export * from "./hash.js";
export * from "./identities.js";
export * from "./legacy.js";
export * from "./messages.js";
export * from "./networks.js";
export * from "./proposal.js";
Expand Down
10 changes: 0 additions & 10 deletions packages/contracts/source/contracts/crypto/legacy.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/crypto-address-base58/source/address.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ describe<{ app: Application; factory: AddressFactory }>("AddressFactory", ({ ass
assert.is(await factory.fromMnemonic(mnemonic), "DLsMhiUzAVEXBXDTY1NGNZteWz8SDvphfa");
});

it("#fromMultiSignatureAsset - should derive an address from multi signature address", async ({ factory }) => {
assert.is(
await factory.fromMultiSignatureAsset({
min: 3,
publicKeys: [
"0235d486fea0193cbe77e955ab175b8f6eb9eaf784de689beffbd649989f5d6be3",
"03a46f2547d20b47003c1c376788db5a54d67264df2ae914f70bf453b6a1fa1b3a",
"03d7dfe44e771039334f4712fb95ad355254f674c8f5d286503199157b7bf7c357",
],
}),
"D8UtPGvjKzjn1fN5GfESoTrTrkQv6XjALS",
);
});

it("#fromPublicKey - should derive an address from a public key", async ({ factory }) => {
assert.is(
await factory.fromPublicKey("034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192"),
Expand Down
4 changes: 0 additions & 4 deletions packages/crypto-address-base58/source/address.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ export class AddressFactory implements Contracts.Crypto.AddressFactory {
return this.fromPublicKey(await this.publicKeyFactory.fromWIF(wif));
}

public async fromMultiSignatureAsset(asset: Contracts.Crypto.MultiSignatureAsset): Promise<string> {
return this.fromPublicKey(await this.publicKeyFactory.fromMultiSignatureAsset(asset));
}

public async fromBuffer(buffer: Buffer): Promise<string> {
return this.#encodeCheck(buffer);
}
Expand Down
14 changes: 0 additions & 14 deletions packages/crypto-address-keccak256/source/address.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ describe<{ app: Application; factory: AddressFactory }>("AddressFactory", ({ ass
wallets,
);

it("#fromMultiSignatureAsset - should derive an address from multi signature address", async ({ factory }) => {
assert.is(
await factory.fromMultiSignatureAsset({
min: 3,
publicKeys: [
"0235d486fea0193cbe77e955ab175b8f6eb9eaf784de689beffbd649989f5d6be3",
"03a46f2547d20b47003c1c376788db5a54d67264df2ae914f70bf453b6a1fa1b3a",
"03d7dfe44e771039334f4712fb95ad355254f674c8f5d286503199157b7bf7c357",
],
}),
"0x970996B998f3C854D9a4D2C327Cc049ae6241C40",
);
});

each(
"#validate - should be valid",
async ({ context: { factory }, dataset: address }) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/crypto-address-keccak256/source/address.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export class AddressFactory implements Contracts.Crypto.AddressFactory {
return this.fromPublicKey(await this.publicKeyFactory.fromWIF(wif));
}

public async fromMultiSignatureAsset(asset: Contracts.Crypto.MultiSignatureAsset): Promise<string> {
return this.fromPublicKey(await this.publicKeyFactory.fromMultiSignatureAsset(asset));
}

public async fromBuffer(buffer: Buffer): Promise<string> {
return getAddress(toHex(buffer));
}
Expand Down
4 changes: 0 additions & 4 deletions packages/crypto-key-pair-bls12-381/source/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ describe<{ app: Application; factory: PublicKeyFactory }>("PublicKeyFactory", ({
await assert.rejects(() => factory.fromWIF(""), NotImplemented);
});

it("#fromMultiSignatureAsset - should throw NotImplemented", async ({ factory }) => {
await assert.rejects(async () => factory.fromMultiSignatureAsset({} as any), NotImplemented);
});

each(
"#verify - should pass with valid public keys",
async ({ context, dataset }) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/crypto-key-pair-bls12-381/source/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export class PublicKeyFactory implements Contracts.Crypto.PublicKeyFactory {
throw new NotImplemented(this.constructor.name, "fromWIF");
}

public async fromMultiSignatureAsset(asset: Contracts.Crypto.MultiSignatureAsset): Promise<string> {
throw new NotImplemented(this.constructor.name, "fromMultiSignatureAsset");
}

public async verify(publicKey: string): Promise<boolean> {
const bls = await getBls();

Expand Down
59 changes: 0 additions & 59 deletions packages/crypto-key-pair-ecdsa/source/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,65 +42,6 @@ describe<{ app: Application; factory: PublicKeyFactory }>("PrivateKeyFactory", (
wallets,
);

it("should derive from a musig", async ({ factory }) => {
assert.is(
await factory.fromMultiSignatureAsset({
min: 3,
publicKeys: [
"0235d486fea0193cbe77e955ab175b8f6eb9eaf784de689beffbd649989f5d6be3",
"03a46f2547d20b47003c1c376788db5a54d67264df2ae914f70bf453b6a1fa1b3a",
"03d7dfe44e771039334f4712fb95ad355254f674c8f5d286503199157b7bf7c357",
],
}),
"0321d8b4df000280dd7f3ac8dae0558e214bd6fe736d97cf68ea8a083c024c249c",
);
});

it("should throw if min < 1", async ({ factory }) => {
await assert.rejects(
() =>
factory.fromMultiSignatureAsset({
min: 0,
publicKeys: [
"0235d486fea0193cbe77e955ab175b8f6eb9eaf784de689beffbd649989f5d6be3",
"03a46f2547d20b47003c1c376788db5a54d67264df2ae914f70bf453b6a1fa1b3a",
"03d7dfe44e771039334f4712fb95ad355254f674c8f5d286503199157b7bf7c357",
],
}),
"The multi signature asset is invalid.",
);
});

it("should throw if min > publicKeys.length", async ({ factory }) => {
await assert.rejects(
() =>
factory.fromMultiSignatureAsset({
min: 4,
publicKeys: [
"0235d486fea0193cbe77e955ab175b8f6eb9eaf784de689beffbd649989f5d6be3",
"03a46f2547d20b47003c1c376788db5a54d67264df2ae914f70bf453b6a1fa1b3a",
"03d7dfe44e771039334f4712fb95ad355254f674c8f5d286503199157b7bf7c357",
],
}),
"The multi signature asset is invalid.",
);
});

it("should throw if publicKey is invalid", async ({ factory }) => {
await assert.rejects(
() =>
factory.fromMultiSignatureAsset({
min: 1,
publicKeys: [
"0",
"03a46f2547d20b47003c1c376788db5a54d67264df2ae914f70bf453b6a1fa1b3a",
"03d7dfe44e771039334f4712fb95ad355254f674c8f5d286503199157b7bf7c357",
],
}),
"Expected 0 to be a valid public key",
);
});

each(
"should pass with valid public keys",
async ({ context, dataset }) => {
Expand Down
24 changes: 1 addition & 23 deletions packages/crypto-key-pair-ecdsa/source/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type { Contracts } from "@mainsail/contracts";

import { Identifiers } from "@mainsail/constants";
import { inject, injectable } from "@mainsail/container";
import { InvalidMultiSignatureAssetError, NotImplemented, PublicKeyError } from "@mainsail/exceptions";
import { numberToHex } from "@mainsail/utils";
import { NotImplemented } from "@mainsail/exceptions";
import { secp256k1 } from "bcrypto";

@injectable()
Expand All @@ -21,27 +20,6 @@ export class PublicKeyFactory implements Contracts.Crypto.PublicKeyFactory {
return publicKey;
}

public async fromMultiSignatureAsset(asset: Contracts.Crypto.MultiSignatureAsset): Promise<string> {
const { min, publicKeys }: Contracts.Crypto.MultiSignatureAsset = asset;

for (const publicKey of publicKeys) {
if (!(await this.verify(publicKey))) {
throw new PublicKeyError(publicKey);
}
}

if (min < 1 || min > publicKeys.length) {
throw new InvalidMultiSignatureAssetError();
}

const minKey: string = await this.fromMnemonic(numberToHex(min));
const keys: string[] = [minKey, ...publicKeys];

return secp256k1
.publicKeyCombine(keys.map((publicKey: string) => Buffer.from(publicKey, "hex")))
.toString("hex");
}

public async verify(publicKey: string): Promise<boolean> {
return secp256k1.publicKeyVerify(Buffer.from(publicKey, "hex"));
}
Expand Down
8 changes: 2 additions & 6 deletions packages/crypto-transaction/source/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import type { Contracts } from "@mainsail/contracts";

import { Identifiers } from "@mainsail/constants";
import { inject, injectable, tagged, optional } from "@mainsail/container";
import {
DuplicateParticipantInMultiSignatureError,
InvalidTransactionBytesError,
TransactionSchemaError,
} from "@mainsail/exceptions";
import { InvalidTransactionBytesError, TransactionSchemaError } from "@mainsail/exceptions";
import { assert } from "@mainsail/utils";

import { BlockTransaction } from "./block-transaction.js";
Expand Down Expand Up @@ -140,7 +136,7 @@ export class TransactionFactory implements Contracts.Crypto.TransactionFactory {

return new Transaction(tx, serialized);
} catch (error) {
if (error instanceof TransactionSchemaError || error instanceof DuplicateParticipantInMultiSignatureError) {
if (error instanceof TransactionSchemaError) {
throw error;
}

Expand Down
74 changes: 0 additions & 74 deletions packages/exceptions/source/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,6 @@ export class InvalidNumberOfRoundValidatorsError extends Exception {
}
}

export class InvalidMultiSignatureAssetError extends Exception {
public constructor() {
super(`The multi signature asset is invalid.`);
}
}

export class DuplicateParticipantInMultiSignatureError extends Exception {
public constructor() {
super(`Invalid multi signature, because duplicate participant found.`);
}
}

export class DeactivatedTransactionHandlerError extends Exception {
public constructor(type: number) {
super(`Transaction type ${type.toString()} is deactivated.`);
Expand Down Expand Up @@ -255,30 +243,6 @@ export class MissingLegacySecondSignatureError extends Exception {
}
}

export class MissingMultiSignatureOnSenderError extends Exception {
public constructor() {
super(`Failed to apply transaction, because sender does not have a multi signature.`);
}
}

export class InvalidMultiSignaturesError extends Exception {
public constructor() {
super(`Failed to apply transaction, because the multi signatures are invalid.`);
}
}

export class UnsupportedMultiSignatureRegistrationTransactionError extends Exception {
public constructor() {
super(`Failed to apply transaction, because the transaction does not support multi signatures.`);
}
}

export class UnsupportedMultiSignatureRegistrationException extends Exception {
public constructor() {
super(`Failed to apply transaction, because the transaction does not support multi signatures.`);
}
}

export class WalletAlreadyResignedError extends Exception {
public constructor() {
super(`Failed to apply transaction, because the wallet already resigned as validator.`);
Expand Down Expand Up @@ -376,44 +340,6 @@ export class InvalidSignatureError extends Exception {
}
}

export class MultiSignatureAlreadyRegisteredError extends Exception {
public constructor() {
super(`Failed to apply transaction, because multi signature is already enabled.`);
}
}

export class InvalidMultiSignatureError extends Exception {
public constructor() {
super(`Failed to apply transaction, because the multi signature could not be verified.`);
}
}

export class LegacyMultiSignatureError extends Exception {
public constructor() {
super(`Failed to apply transaction, because legacy multi signature is no longer supported.`);
}
}

export class LegacyMultiSignatureRegistrationError extends Exception {
public constructor() {
super(`Failed to apply transaction, because legacy multi signature registrations are no longer supported.`);
}
}

export class MultiSignatureMinimumKeysError extends Exception {
public constructor() {
super(`Failed to apply transaction, because too few keys were provided.`);
}
}

export class MultiSignatureKeyCountMismatchError extends Exception {
public constructor() {
super(
`Failed to apply transaction, because the number of provided keys does not match the number of signatures.`,
);
}
}

export class MultiPaymentAmountMismatchError extends Exception {
public constructor() {
super(`Payment amounts mismatch.`);
Expand Down
Loading
Loading