
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
@trezor/schema-utils
Advanced tools
A schema definition and validation library for TypeScript, based on TypeBox.
Let's say we have a TypeScript type that we want to convert to a schema.
export interface Example {
coordinator: string;
coin?: string;
maxRounds: number;
maxFeePerKvbyte: Uint;
data: ArrayBuffer;
path: DerivationPath;
}
The schema for this type can be defined as follows:
import { Type, Static } from '@trezor/schema-utils';
// ...
export const Example = Type.Object({
coordinator: Type.String(),
coin: Type.Optional(Type.String()),
maxRounds: Type.Number(),
maxFeePerKvbyte: Type.Uint(),
data: Type.ArrayBuffer(),
path: DerivationPath, // Reference to another schema
});
// Inferred TS type
export type Example = Static<typeof schema>;
We can see that primitive and common types are defined using the Type object. This is also used for constructs such as unions, intersects, etc. The full list of available types can be found in the TypeBox documentation
If done correctly, the new schema should be equivalent to the old TypeScript type. Since the inferred TypeScript type is exported with the same name, it can be used both as a type and for runtime validation.
We have two main functions for validation: Assert and Validate.
Assert throws an error if the payload does not match the schema, also functioning as a type assertion.
import { Assert } from '@trezor/schema-utils';
Assert(Example, payload);
// payload now must be of type Example
Validate does not throw, but simply returns a boolean. It can also be used as a type guard.
import { Validate } from '@trezor/schema-utils';
if (Validate(Example, payload)) {
// payload now must be of type Example
}
To generate schemas from TypeScript types automatically, you can use the code generation tool.
yarn workspace @trezor/schema-utils codegen <file>
This tool is also used in Protobuf code generation to generate schemas for the messages.
There are a few behavior changes and custom types that are used in the schemas.
enum MyExample {
Foo = 'foo',
Bar = 'bar',
}
const EnumMyExample = Type.Enum(MyExample);
To use an enum as a schema, you need to use the Type.Enum function.
The convention is to prefix the name of the schema with Enum.
That way, the original enum can be used as a TypeScript type, and the schema can be used for validation.
To get the schema for the keys of the enum, you can use the KeyOfEnum type. The parameter it takes is directly the original Enum, not the schema. Don't use Typebox's Type.KeyOf function for this, as it will not work correctly.
const MyExampleKey: Type.KeyOfEnum(MyExample);
Type.Uint();
// Can also be used for Sint
Type.Uint({ allowNegative: true });
The Uint type is a custom type that is used in the Protobuf messages.
It is a unsigned integer that can be represented as a string or a number.
By using the allowNegative option, it can also be used for signed integers.
Type.ArrayBuffer();
Type.Buffer();
Instances of the ArrayBuffer JS built-in object and Buffer in Node.js.
FAQs
Unknown package
We found that @trezor/schema-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.