chore: export is_on_curve()
This commit is contained in:
committed by
mergify[bot]
parent
b17d5eeaee
commit
aee30e304d
@ -150,6 +150,13 @@ export class PublicKey {
|
|||||||
}
|
}
|
||||||
throw new Error(`Unable to find a viable program address nonce`);
|
throw new Error(`Unable to find a viable program address nonce`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that a pubkey is on the ed25519 curve.
|
||||||
|
*/
|
||||||
|
static isOnCurve(pubkey: Uint8Array): boolean {
|
||||||
|
return is_on_curve(pubkey) == 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -3,6 +3,7 @@ import {Buffer} from 'buffer';
|
|||||||
import {expect, use} from 'chai';
|
import {expect, use} from 'chai';
|
||||||
import chaiAsPromised from 'chai-as-promised';
|
import chaiAsPromised from 'chai-as-promised';
|
||||||
|
|
||||||
|
import {Account} from '../src/account';
|
||||||
import {PublicKey, MAX_SEED_LENGTH} from '../src/publickey';
|
import {PublicKey, MAX_SEED_LENGTH} from '../src/publickey';
|
||||||
|
|
||||||
use(chaiAsPromised);
|
use(chaiAsPromised);
|
||||||
@ -328,4 +329,17 @@ describe('PublicKey', function () {
|
|||||||
),
|
),
|
||||||
).to.be.true;
|
).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('isOnCurve', () => {
|
||||||
|
let onCurve = new Account().publicKey;
|
||||||
|
expect(PublicKey.isOnCurve(onCurve.toBuffer())).to.be.true;
|
||||||
|
// 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.
|
||||||
|
// Unfortunately, I've been unable to find a golden negative example input
|
||||||
|
// for curve25519 point decompression :/
|
||||||
|
let offCurve = new PublicKey(
|
||||||
|
'12rqwuEgBYiGhBrDJStCiqEtzQpTTiZbh7teNVLuYcFA',
|
||||||
|
);
|
||||||
|
expect(PublicKey.isOnCurve(offCurve.toBuffer())).to.be.false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user