feat: update superstruct and future proof type validations (#15491)

* chore: update superstruct

* fix: fix program account notification type coercion
This commit is contained in:
Justin Starry
2021-02-26 15:06:12 +08:00
committed by GitHub
parent d866f742e2
commit bb06817e16
6 changed files with 591 additions and 939 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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);
}
}