From 6c89111e4b60b4fd3a1d98205199d6d274b61959 Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Sun, 27 Sep 2020 20:15:42 -0700 Subject: [PATCH] use hex strings for private keys --- test/account.spec.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/account.spec.ts b/test/account.spec.ts index 241768ad..2548fbfa 100644 --- a/test/account.spec.ts +++ b/test/account.spec.ts @@ -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) }) @@ -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) })