Skip to content

Commit

Permalink
refactor: update signing method
Browse files Browse the repository at this point in the history
  • Loading branch information
eum602 committed Sep 5, 2023
1 parent e6d934c commit 9f75d73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 11 additions & 6 deletions src/services/lacchain.generic.signer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<ISecp256k1SignatureMessageResponse>}
*/
async signPlainMessage(
message: ISignPlainMessageByAddress
digest: ISignPlainMessageByAddress
): Promise<ISecp256k1SignatureMessageResponse> {
const signerAddress = message.address;
const signerAddress = digest.address;
if (!signerAddress || !isAddress(signerAddress)) {
const message = ErrorsMessages.MISSING_PARAMS;
this.log.info(message);
Expand All @@ -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;
}
Expand Down

0 comments on commit 9f75d73

Please sign in to comment.