feat: allow PublicKey.isOnCurve to accept PublicKeyInitData (#24602)
This commit is contained in:
parent
70d57245b4
commit
758fcd383d
|
@ -222,8 +222,9 @@ export class PublicKey extends Struct {
|
||||||
/**
|
/**
|
||||||
* Check that a pubkey is on the ed25519 curve.
|
* Check that a pubkey is on the ed25519 curve.
|
||||||
*/
|
*/
|
||||||
static isOnCurve(pubkey: Uint8Array): boolean {
|
static isOnCurve(pubkeyData: PublicKeyInitData): boolean {
|
||||||
return is_on_curve(pubkey) == 1;
|
const pubkey = new PublicKey(pubkeyData);
|
||||||
|
return is_on_curve(pubkey.toBytes()) == 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,8 @@ describe('PublicKey', function () {
|
||||||
it('isOnCurve', () => {
|
it('isOnCurve', () => {
|
||||||
let onCurve = Keypair.generate().publicKey;
|
let onCurve = Keypair.generate().publicKey;
|
||||||
expect(PublicKey.isOnCurve(onCurve.toBuffer())).to.be.true;
|
expect(PublicKey.isOnCurve(onCurve.toBuffer())).to.be.true;
|
||||||
|
expect(PublicKey.isOnCurve(onCurve.toBase58())).to.be.true;
|
||||||
|
expect(PublicKey.isOnCurve(onCurve)).to.be.true;
|
||||||
// A program address, yanked from one of the above tests. This is a pretty
|
// A program address, yanked from one of the above tests. This is a pretty
|
||||||
// poor test vector since it was created by the same code it is testing.
|
// poor test vector since it was created by the same code it is testing.
|
||||||
// Unfortunately, I've been unable to find a golden negative example input
|
// Unfortunately, I've been unable to find a golden negative example input
|
||||||
|
@ -240,6 +242,8 @@ describe('PublicKey', function () {
|
||||||
'12rqwuEgBYiGhBrDJStCiqEtzQpTTiZbh7teNVLuYcFA',
|
'12rqwuEgBYiGhBrDJStCiqEtzQpTTiZbh7teNVLuYcFA',
|
||||||
);
|
);
|
||||||
expect(PublicKey.isOnCurve(offCurve.toBuffer())).to.be.false;
|
expect(PublicKey.isOnCurve(offCurve.toBuffer())).to.be.false;
|
||||||
|
expect(PublicKey.isOnCurve(offCurve.toBase58())).to.be.false;
|
||||||
|
expect(PublicKey.isOnCurve(offCurve)).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('canBeSerializedWithBorsh', () => {
|
it('canBeSerializedWithBorsh', () => {
|
||||||
|
|
Loading…
Reference in New Issue