fix: createProgramAddress now throws on an invalid seed length

This commit is contained in:
Michael Vines
2020-10-13 13:40:38 -07:00
parent f8d338c9cb
commit e84a91d417
5 changed files with 19 additions and 2 deletions

View File

@@ -10,6 +10,11 @@ let naclLowLevel = nacl.lowlevel;
type PublicKeyNonce = [PublicKey, number]; // This type exists to workaround an esdoc parse error
/**
* Maximum length of derived pubkey seed
*/
export const MAX_SEED_LENGTH = 32;
/**
* A public key
*/
@@ -97,6 +102,9 @@ export class PublicKey {
): Promise<PublicKey> {
let buffer = Buffer.alloc(0);
seeds.forEach(function (seed) {
if (seed.length > MAX_SEED_LENGTH) {
throw new Error(`Max seed length exceeded`);
}
buffer = Buffer.concat([buffer, Buffer.from(seed)]);
});
buffer = Buffer.concat([