fix: add publickey toJSON (#22004)

This commit is contained in:
Victor Pontis 2021-12-20 16:16:32 -05:00 committed by GitHub
parent e810400716
commit c0c3d7c1f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -87,6 +87,10 @@ export class PublicKey extends Struct {
return bs58.encode(this.toBytes());
}
toJSON(): string {
return this.toBase58();
}
/**
* Return the byte array representation of the public key
*/

View File

@ -71,6 +71,17 @@ describe('PublicKey', function () {
expect(key4.toBase58()).to.eq('11111111111111111111111111111111');
});
it('toJSON', () => {
const key = new PublicKey('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
expect(key.toJSON()).to.eq('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
expect(JSON.stringify(key)).to.eq(
'"CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3"',
);
expect(JSON.stringify({key})).to.eq(
'{"key":"CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3"}',
);
});
it('toBuffer', () => {
const key = new PublicKey('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
expect(key.toBuffer()).to.have.length(32);