From aa1d6ba4d46b63db1d4f8af5692b3ced37f57a74 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Sun, 30 Sep 2018 20:07:28 -0700 Subject: [PATCH] fix: zero pad correctly --- web3.js/src/publickey.js | 2 +- web3.js/test/publickey.test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/web3.js/src/publickey.js b/web3.js/src/publickey.js index 9af5f9c499..9003b86ccf 100644 --- a/web3.js/src/publickey.js +++ b/web3.js/src/publickey.js @@ -56,7 +56,7 @@ export class PublicKey { } const zeroPad = new Buffer(32); - b.copy(zeroPad, 32 - b.length); + b.copy(zeroPad); return zeroPad; } diff --git a/web3.js/test/publickey.test.js b/web3.js/test/publickey.test.js index dd1d5f7732..6ec4d2f754 100644 --- a/web3.js/test/publickey.test.js +++ b/web3.js/test/publickey.test.js @@ -37,6 +37,10 @@ test('isPublicKey', () => { test('toBase58', () => { const key = new PublicKey('0x300000000000000000000000000000000000000000000000000000000000000'); expect(key.toBase58()).toBe('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3'); + + const key2 = new PublicKey('123456789'); + expect(key2.toBase58()).toBe('Vj3WURvtMv1mii1vhTqLhcSwVWDRs2E135KtTYUXtTq'); + console.log(key2.toBuffer()); }); test('toBuffer', () => {