fix: add publickey toJSON (#22004)
This commit is contained in:
@ -87,6 +87,10 @@ export class PublicKey extends Struct {
|
|||||||
return bs58.encode(this.toBytes());
|
return bs58.encode(this.toBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toJSON(): string {
|
||||||
|
return this.toBase58();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the byte array representation of the public key
|
* Return the byte array representation of the public key
|
||||||
*/
|
*/
|
||||||
|
@ -71,6 +71,17 @@ describe('PublicKey', function () {
|
|||||||
expect(key4.toBase58()).to.eq('11111111111111111111111111111111');
|
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', () => {
|
it('toBuffer', () => {
|
||||||
const key = new PublicKey('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
|
const key = new PublicKey('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
|
||||||
expect(key.toBuffer()).to.have.length(32);
|
expect(key.toBuffer()).to.have.length(32);
|
||||||
|
Reference in New Issue
Block a user