From 3709a9f79a8653e4448921720fdd6aa34ee972ec Mon Sep 17 00:00:00 2001 From: Billy Jacoby Date: Thu, 31 Oct 2024 13:42:13 -0400 Subject: [PATCH] chore: add initial test case --- .../src/core/accounts/PrivateKey.spec.ts | 20 +++++++++++++++++++ .../src/strategy/strategy.ts | 3 +-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts b/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts index 6072a8c79..38e646abc 100644 --- a/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts +++ b/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts @@ -1,3 +1,4 @@ +import { toUtf8 } from '../..' import { generateArbitrarySignDoc } from '../tx' import { PrivateKey } from './PrivateKey' @@ -113,6 +114,25 @@ describe('PrivateKey', () => { ).toBe(true) }) + it('returns the correct signature for signing an arbitrary message', () => { + // const pubKey = '0x697e62225Dd22A5afcAa82901089b2151DAEB706' + const message = 'this is a test message' + + const verifiedSignature = + '0xfd0879e35cec78b87ae7e647ebb743093ea15edcb88eb388806adaaff5f645527dab0cfac030b23d702206d6e0840a7bae5d2239518ba20b73c6636f75f150401b' + + const privateKey = PrivateKey.fromHex(pk) + + const privKeySignature = privateKey.sign( + Buffer.from(toUtf8(message), 'utf-8'), + ) + + expect(Buffer.from(privKeySignature).toString('hex')).toEqual( + verifiedSignature, + ) + // + }) + it('returns true when verifying signature for a public key and a cosmos message', () => { // }) diff --git a/packages/wallets/wallet-private-key/src/strategy/strategy.ts b/packages/wallets/wallet-private-key/src/strategy/strategy.ts index 15b179868..993ce9210 100644 --- a/packages/wallets/wallet-private-key/src/strategy/strategy.ts +++ b/packages/wallets/wallet-private-key/src/strategy/strategy.ts @@ -202,8 +202,7 @@ export class PrivateKeyWallet } try { - const bufferUTF = Buffer.from(toUtf8(data), 'utf-8') - const signature = await pk.signHashed(bufferUTF) + const signature = await pk.signHashed(Buffer.from(toUtf8(data), 'utf-8')) return signature } catch (e: unknown) {