fix: ensure that Keypair.secretKey is a Uint8Array (#27700)

This commit is contained in:
Justin Starry 2022-09-09 16:31:18 -04:00 committed by GitHub
parent 37296caee8
commit 080f085cb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -88,6 +88,6 @@ export class Keypair {
* The raw secret key for this keypair
*/
get secretKey(): Uint8Array {
return this._keypair.secretKey;
return new Uint8Array(this._keypair.secretKey);
}
}

View File

@ -24,6 +24,11 @@ describe('Keypair', () => {
expect(keypair.publicKey.toBase58()).to.eq(
'2q7pyhPwAwZ3QMfZrnAbDhnh9mDUqycszcpf86VgQxhF',
);
expect(keypair.secretKey.toString()).to.eq(
'153,218,149,89,225,94,145,62,233,171,46,83,227,223,173,87,93,163,59,73,' +
'190,17,37,187,146,46,51,73,79,73,136,40,27,47,73,9,110,62,93,189,15,207,' +
'169,192,192,205,146,217,171,59,33,84,75,52,213,221,74,101,217,139,135,139,153,34',
);
});
it('creating keypair from invalid secret key throws error', () => {