fix(sdk): validate index on createDepositsSecrets (#73)

This commit is contained in:
nigiri
2025-04-23 16:05:48 -03:00
committed by GitHub
parent 360b97b445
commit a7cf232fae
2 changed files with 11 additions and 0 deletions

View File

@@ -226,6 +226,10 @@ export class AccountService {
secret: Secret;
precommitment: Hash;
} {
if(index && index < 0n) {
throw AccountError.invalidIndex(index);
}
const accounts = this.account.poolAccounts.get(scope);
index = index || BigInt(accounts?.length || 0);

View File

@@ -32,4 +32,11 @@ export class AccountError extends SDKError {
ErrorCode.OPERATION_FAILED,
);
}
public static invalidIndex(index: bigint): AccountError {
return new AccountError(
`Invalid index: ${index.toString()}`,
ErrorCode.INVALID_INPUT,
);
}
}