diff --git a/packages/mainsail/package.json b/packages/mainsail/package.json index 63560fe4..10143132 100644 --- a/packages/mainsail/package.json +++ b/packages/mainsail/package.json @@ -36,6 +36,7 @@ "@mainsail/crypto-config": "0.0.1-alpha.15", "@mainsail/crypto-consensus-bls12-381": "0.0.1-alpha.15", "@mainsail/crypto-hash-bcrypto": "0.0.1-alpha.15", + "@mainsail/crypto-key-pair-bls12-381": "0.0.1-alpha.15", "@mainsail/crypto-key-pair-ecdsa": "0.0.1-alpha.15", "@mainsail/crypto-signature-schnorr-secp256k1": "0.0.1-alpha.15", "@mainsail/crypto-transaction": "0.0.1-alpha.15", diff --git a/packages/mainsail/source/public-key.service.ts b/packages/mainsail/source/public-key.service.ts index 73554604..489c2f7b 100644 --- a/packages/mainsail/source/public-key.service.ts +++ b/packages/mainsail/source/public-key.service.ts @@ -5,14 +5,37 @@ import { abort_if, abort_unless } from "@ardenthq/sdk-helpers"; import { BindingType } from "./coin.contract.js"; import { PublicKey as BasePublicKey } from "./crypto/identities/public-key.js"; import { Interfaces } from "./crypto/index.js"; +import { Container } from "@mainsail/container"; +import { Application } from "@mainsail/kernel"; +import { Contracts } from "@mainsail/contracts"; +import { ServiceProvider as CoreValidation } from "@mainsail/validation"; +import { ServiceProvider as CoreCryptoConfig } from "@mainsail/crypto-config"; +import { ServiceProvider as CoreCryptoConsensusBls12381 } from "@mainsail/crypto-consensus-bls12-381"; +import { ServiceProvider as CoreCryptoValidation } from "@mainsail/crypto-validation"; +import { Identifiers } from "@mainsail/contracts"; export class PublicKeyService extends Services.AbstractPublicKeyService { readonly #config!: Interfaces.NetworkConfig; + readonly #app: Application; + #isBooted: boolean = false; public constructor(container: IoC.IContainer) { super(container); this.#config = container.get(BindingType.Crypto); + + this.#app = new Application(new Container()); + + this.#boot(); + } + + async #boot(): Promise { + await this.#app.resolve(CoreValidation).register(); + await this.#app.resolve(CoreCryptoConfig).register(); + await this.#app.resolve(CoreCryptoValidation).register(); + await this.#app.resolve(CoreCryptoConsensusBls12381).register(); + + this.#isBooted = true; } public override async fromMnemonic( @@ -48,4 +71,24 @@ export class PublicKeyService extends Services.AbstractPublicKeyService { publicKey: BasePublicKey.fromWIF(wif), }; } + + public override async verifyPublicKeyWithBLS(publicKey: string): Promise { + if (!this.#isBooted) { + await this.#boot(); + } + + const consensusKeyPairFactory: Contracts.Crypto.KeyPairFactory = this.#app.getTagged( + Identifiers.Cryptography.Identity.KeyPair.Factory, + "type", + "consensus", + ); + + const consensusPublicKeyFactory: Contracts.Crypto.PublicKeyFactory = this.#app.getTagged( + Identifiers.Cryptography.Identity.PublicKey.Factory, + "type", + "consensus", + ); + + return await consensusPublicKeyFactory.verify(publicKey); + } } diff --git a/packages/mainsail/webpack.config.cjs b/packages/mainsail/webpack.config.cjs index 4e23274a..6fc38b10 100644 --- a/packages/mainsail/webpack.config.cjs +++ b/packages/mainsail/webpack.config.cjs @@ -38,4 +38,8 @@ module.exports = { module: false, }, }, + output: { + ...baseConfig.output, + chunkFormat: false, + }, }; diff --git a/packages/sdk/source/extended-public-key.contract.ts b/packages/sdk/source/extended-public-key.contract.ts index e5daf324..f98a81c9 100644 --- a/packages/sdk/source/extended-public-key.contract.ts +++ b/packages/sdk/source/extended-public-key.contract.ts @@ -2,4 +2,5 @@ import { IdentityOptions } from "./shared.contract.js"; export interface ExtendedPublicKeyService { fromMnemonic(mnemonic: string, options?: IdentityOptions): Promise; + verifyPublicKeyWithBLS(publicKey: string): Promise; } diff --git a/packages/sdk/source/extended-public-key.service.ts b/packages/sdk/source/extended-public-key.service.ts index 6d17a68c..48a8a484 100644 --- a/packages/sdk/source/extended-public-key.service.ts +++ b/packages/sdk/source/extended-public-key.service.ts @@ -1,11 +1,11 @@ /* istanbul ignore file */ +import { BindingType } from "./service-provider.contract.js"; import { ConfigRepository } from "./coins.js"; -import { IContainer } from "./container.contracts.js"; -import { NotImplemented } from "./exceptions.js"; import { ExtendedPublicKeyService } from "./extended-public-key.contract.js"; -import { BindingType } from "./service-provider.contract.js"; +import { IContainer } from "./container.contracts.js"; import { IdentityOptions } from "./shared.contract.js"; +import { NotImplemented } from "./exceptions.js"; export class AbstractExtendedPublicKeyService implements ExtendedPublicKeyService { protected readonly configRepository: ConfigRepository; @@ -17,4 +17,8 @@ export class AbstractExtendedPublicKeyService implements ExtendedPublicKeyServic public async fromMnemonic(mnemonic: string, options?: IdentityOptions): Promise { throw new NotImplemented(this.constructor.name, this.fromMnemonic.name); } + + public async verifyPublicKeyWithBLS(publicKey: string): Promise { + throw new NotImplemented(this.constructor.name, this.verifyPublicKeyWithBLS.name); + } } diff --git a/packages/sdk/source/public-key.contract.ts b/packages/sdk/source/public-key.contract.ts index 2627e0bc..9b7abee2 100644 --- a/packages/sdk/source/public-key.contract.ts +++ b/packages/sdk/source/public-key.contract.ts @@ -10,4 +10,5 @@ export interface PublicKeyService { fromMultiSignature(min: number, publicKeys: string[]): Promise; fromWIF(wif: string): Promise; fromSecret(secret: string): Promise; + verifyPublicKeyWithBLS(publicKey: string): Promise; } diff --git a/packages/sdk/source/public-key.service.ts b/packages/sdk/source/public-key.service.ts index cd6e115c..1eb326b4 100644 --- a/packages/sdk/source/public-key.service.ts +++ b/packages/sdk/source/public-key.service.ts @@ -1,12 +1,13 @@ /* istanbul ignore file */ -import { ConfigRepository } from "./coins.js"; -import { IContainer } from "./container.contracts.js"; -import { NotImplemented } from "./exceptions.js"; -import { NetworkHostSelector } from "./network.models.js"; import { PublicKeyDataTransferObject, PublicKeyService } from "./public-key.contract.js"; + import { BindingType } from "./service-provider.contract.js"; +import { ConfigRepository } from "./coins.js"; +import { IContainer } from "./container.contracts.js"; import { IdentityOptions } from "./shared.contract.js"; +import { NetworkHostSelector } from "./network.models.js"; +import { NotImplemented } from "./exceptions.js"; export class AbstractPublicKeyService implements PublicKeyService { protected readonly configRepository: ConfigRepository; @@ -32,4 +33,8 @@ export class AbstractPublicKeyService implements PublicKeyService { public async fromSecret(secret: string): Promise { throw new NotImplemented(this.constructor.name, this.fromSecret.name); } + + public async verifyPublicKeyWithBLS(publicKey: string): Promise { + throw new NotImplemented(this.constructor.name, this.verifyPublicKeyWithBLS.name); + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a09978b5..f1e0f63a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -431,6 +431,9 @@ importers: '@mainsail/crypto-hash-bcrypto': specifier: 0.0.1-alpha.15 version: 0.0.1-alpha.15 + '@mainsail/crypto-key-pair-bls12-381': + specifier: 0.0.1-alpha.15 + version: 0.0.1-alpha.15 '@mainsail/crypto-key-pair-ecdsa': specifier: 0.0.1-alpha.15 version: 0.0.1-alpha.15 @@ -3337,7 +3340,7 @@ packages: resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==} engines: {node: '>= 6.0.0'} dependencies: - debug: 4.3.2 + debug: 4.3.4 transitivePeerDependencies: - supports-color dev: false @@ -5704,7 +5707,7 @@ packages: dependencies: '@tootallnate/once': 1.1.2 agent-base: 6.0.2 - debug: 4.3.2 + debug: 4.3.4 transitivePeerDependencies: - supports-color dev: false @@ -5718,7 +5721,7 @@ packages: engines: {node: '>= 6'} dependencies: agent-base: 6.0.2 - debug: 4.3.2 + debug: 4.3.4 transitivePeerDependencies: - supports-color dev: false