feat: update superstruct and future proof type validations (#15491)
* chore: update superstruct * fix: fix program account notification type coercion
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,12 @@
|
||||
// @flow
|
||||
|
||||
import {Buffer} from 'buffer';
|
||||
import {struct} from 'superstruct';
|
||||
import {
|
||||
assert as assertType,
|
||||
optional,
|
||||
string,
|
||||
type as pick,
|
||||
} from 'superstruct';
|
||||
|
||||
import * as Layout from './layout';
|
||||
import * as shortvec from './util/shortvec-encoding';
|
||||
@@ -35,11 +40,11 @@ export type Info = {|
|
||||
keybaseUsername?: string,
|
||||
|};
|
||||
|
||||
const InfoString = struct({
|
||||
name: 'string',
|
||||
website: 'string?',
|
||||
details: 'string?',
|
||||
keybaseUsername: 'string?',
|
||||
const InfoString = pick({
|
||||
name: string(),
|
||||
website: optional(string()),
|
||||
details: optional(string()),
|
||||
keybaseUsername: optional(string()),
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -94,7 +99,8 @@ export class ValidatorInfo {
|
||||
if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
|
||||
if (configKeys[1].isSigner) {
|
||||
const rawInfo = Layout.rustString().decode(Buffer.from(byteArray));
|
||||
const info = InfoString(JSON.parse(rawInfo));
|
||||
const info = JSON.parse(rawInfo);
|
||||
assertType(info, InfoString);
|
||||
return new ValidatorInfo(configKeys[1].publicKey, info);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user