From 9f75d7325ceea7bf61114625f4edb00471f256bc Mon Sep 17 00:00:00 2001 From: eum602 Date: Mon, 4 Sep 2023 23:39:31 -0500 Subject: [PATCH] refactor: update signing method --- package.json | 2 +- src/services/lacchain.generic.signer.service.ts | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 29b299a..ddba0a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lacchain-key-manager", - "version": "0.0.1", + "version": "0.0.2", "description": "Rest api for lacchain key manager", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/services/lacchain.generic.signer.service.ts b/src/services/lacchain.generic.signer.service.ts index 127a97f..19e8b92 100644 --- a/src/services/lacchain.generic.signer.service.ts +++ b/src/services/lacchain.generic.signer.service.ts @@ -7,7 +7,7 @@ import { ISecp256k1SignatureMessageResponse, ISignPlainMessageByAddress } from 'src/interfaces/signer/signer.interface'; -import { Wallet, isAddress } from 'ethers'; +import { SigningKey, isAddress } from 'ethers'; import { Secp256k1GenericSignerService } from './interfaces/secp256k1.generic.signer'; import { arrayify } from '@ethersproject/bytes'; @@ -16,10 +16,14 @@ import { arrayify } from '@ethersproject/bytes'; export class Secp256k1GenericSignerServiceDb implements Secp256k1GenericSignerService { protected readonly secp256k1DbService = new Secp256k1DbService(); log = log4TSProvider.getLogger('secp256k1-plain-message-signer'); + /** + * @param {string} digest - message digest (32 bytes) to sign. + * @return {Promise} + */ async signPlainMessage( - message: ISignPlainMessageByAddress + digest: ISignPlainMessageByAddress ): Promise { - const signerAddress = message.address; + const signerAddress = digest.address; if (!signerAddress || !isAddress(signerAddress)) { const message = ErrorsMessages.MISSING_PARAMS; this.log.info(message); @@ -28,11 +32,12 @@ export class Secp256k1GenericSignerServiceDb implements Secp256k1GenericSignerSe const privateKey = await this.secp256k1DbService.getKeyByAddress( signerAddress ); - const wallet = new Wallet(privateKey.key); - const messageHash = message.messageHash; + const messageHash = digest.messageHash; const messageHashBytes = arrayify(messageHash); + const signingKeyInstance = new SigningKey(privateKey.key); + const s = signingKeyInstance.sign(messageHashBytes).serialized; const signature = { - signature: await wallet.signMessage(messageHashBytes) + signature: s }; return signature; }