Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
use hex strings for private keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Sep 28, 2020
1 parent cfe8a9a commit 6c89111
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions test/account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,22 @@ describe('privateToPublic', function() {
it('should produce a public key given a private key', function() {
const pubKey =
'3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d'
// prettier-ignore
const privateKey = Buffer.from([234, 84, 189, 197, 45, 22, 63, 136, 201, 58, 176, 97, 87, 130, 207, 113, 138, 46, 251, 158, 81, 167, 152, 154, 171, 27, 8, 6, 126, 156, 28, 95,])
const privateKey = Buffer.from(
'ea54bdc52d163f88c93ab0615782cf718a2efb9e51a7989aab1b08067e9c1c5f',
'hex',
)
const r: any = privateToPublic(privateKey).toString('hex')
assert.equal(r.toString('hex'), pubKey)
})
it("shouldn't produce a public key given an invalid private key", function() {
// prettier-ignore
const privateKey1 = Buffer.from([234, 84, 189, 197, 45, 22, 63, 136, 201, 58, 176, 97, 87, 130, 207, 113, 138, 46, 251, 158, 81, 167, 152, 154, 171, 27, 8, 6, 126, 156, 28, 95, 42,])
// prettier-ignore
const privateKey2 = Buffer.from([234, 84, 189, 197, 45, 22, 63, 136, 201, 58, 176, 97, 87, 130, 207, 113, 138, 46, 251, 158, 81, 167, 152, 154, 171, 27, 8, 6, 126, 156, 28,])
const privateKey1 = Buffer.from(
'ea54bdc52d163f88c93ab0615782cf718a2efb9e51a7989aab1b08067e9c1c5f2a',
'hex',
)
const privateKey2 = Buffer.from(
'ea54bdc52d163f88c93ab0615782cf718a2efb9e51a7989aab1b08067e9c1c',
'hex',
)
assert.throws(function() {
privateToPublic(privateKey1)
})
Expand All @@ -412,8 +418,10 @@ describe('privateToAddress', function() {
it('should produce an address given a private key', function() {
const address = '2f015c60e0be116b1f0cd534704db9c92118fb6a'
// Our private key
// prettier-ignore
const privateKey = Buffer.from([234, 84, 189, 197, 45, 22, 63, 136, 201, 58, 176, 97, 87, 130, 207, 113, 138, 46, 251, 158, 81, 167, 152, 154, 171, 27, 8, 6, 126, 156, 28, 95,])
const privateKey = Buffer.from(
'ea54bdc52d163f88c93ab0615782cf718a2efb9e51a7989aab1b08067e9c1c5f',
'hex',
)
const r: any = privateToAddress(privateKey).toString('hex')
assert.equal(r.toString('hex'), address)
})
Expand Down

0 comments on commit 6c89111

Please sign in to comment.