Skip to content

Commit

Permalink
chore: add initial test case
Browse files Browse the repository at this point in the history
  • Loading branch information
billyjacoby committed Nov 7, 2024
1 parent c723b31 commit 3709a9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toUtf8 } from '../..'
import { generateArbitrarySignDoc } from '../tx'
import { PrivateKey } from './PrivateKey'

Expand Down Expand Up @@ -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', () => {
//
})
Expand Down
3 changes: 1 addition & 2 deletions packages/wallets/wallet-private-key/src/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3709a9f

Please sign in to comment.