fix: improve findProgramAddress error when MAX_SEED_LENGTH is exceeded (#17151)

This commit is contained in:
Christian Machacek 2021-05-11 00:55:51 +02:00 committed by GitHub
parent 82fb6712e7
commit e511c442e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,7 +113,7 @@ export class PublicKey {
let buffer = Buffer.alloc(0);
seeds.forEach(function (seed) {
if (seed.length > MAX_SEED_LENGTH) {
throw new Error(`Max seed length exceeded`);
throw new TypeError(`Max seed length exceeded`);
}
buffer = Buffer.concat([buffer, toBuffer(seed)]);
});
@ -148,6 +148,9 @@ export class PublicKey {
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
address = await this.createProgramAddress(seedsWithNonce, programId);
} catch (err) {
if (err instanceof TypeError) {
throw err;
}
nonce--;
continue;
}