-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema system refactor #10280
Schema system refactor #10280
Conversation
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
ae38a90
to
bdaef0c
Compare
Related PR 782 |
48b209f
to
a2f2497
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- left just few comments to discuss now
- please remove commits for connect explorer, lets make a separate PR from it. no need to split our focus too much here.
also @marekrjpolak is going to read this a bit today.
d75bbaf
to
a9a657e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it in runtime and also haven't checked whether the types and validations are strictly equivalent with the old ones (well, we already know they're not, but you know what I mean), let's ask the QA to test it thoroughly.
But, apart from the mostly nitpicks mentioned, I'm impressed. The typebox
lib looks solid, have no other dependencies, and the Assert approach seems really easy-to-use. Good job!
Cc: @mroz22
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
export function Assert<T extends TSchema>(schema: T, value: unknown): asserts value is Static<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos for first usage of asserts
keyword in this repo, I love it already.
@@ -0,0 +1,2611 @@ | |||
// This file is auto generated from data/messages/message.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's just my pet peeve, but I don't think it's necessary to have 5,3k lines of fixtures for this unit test. Does it make sense to prune it somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this test basically takes the entire messages.ts
and compares it to a snapshot. It was more for development purposes because I was interested in messages.ts
in particular
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type InputWithPathParam = Static<typeof InputWithPath>; | ||
export const InputWithPathParam = Type.Composite([ | ||
PROTO.CardanoTxInput, | ||
Type.Object({ | ||
path: Type.Optional(DerivationPath), | ||
}), | ||
]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is newly added and only used in this file. exporting it doesnt seem needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally done reading. lets jump on a call and discuss few notes. we are almost there.
ea26771
to
e8e0c3e
Compare
d31b80e
to
03ade6b
Compare
chore(protobuf): remove `bytebuffer` dependency fix(connect): use assert, update TS references, lint issue fix(connect-explorer): remove old references in tsconfig fix: update yarn, schema after rebase fix: update yarn lock after rebase
refactor(connect): validation in ethereumSignTypedData refactor(connect): validation in `bitcoin/refTx` refactor(connect): simple API methods refactor(connect): additional device API methods fix(connect): missing validation in `requestLogin` async refactor(connect): additional ethereum API methods refactor(connect): validation in `signMessage/verifyMessage` API refactor(connect): validation in methods with bundled params refactor(connect): validation in altcoin `GetAddress` APIs refactor(connect): validation in `GetPublicKey` APIs refactor(connect): validation in `authenticateDevice`, `eos`, `binance`, `ethereum` APIs refactor(connect): validation in altcoin `signTransaction` APIs refactor(connect): validation in `cardano` APIs refactor(connect): validate with schema in authorizeCoinjoin API fix(connect): fix types, re-enable assert in `typedCall` fix(connect): minor lint and type issues
fix(connect): unit test related to loosened `TxOutputType`, notes about issue trezor#10474
fix(connect): `firmwareUpdate` - version array length must be 3 fix(connect): add comments
03ade6b
to
378ecaf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, lets merge this after connect 9.1.8 is ready.
Effort to refactor the schema system based on my previous proposal
Description
schema-utils
, which is based on the Typebox libraryupdate:schema
command to the protobuf package, which generatesmessage-schema.ts
using the codegen script. This should be 1:1 equivalent with the existing types.connect-explorer
- added a page forauthorizeCoinjoin
, which is mapped from the schemablockchain-link
(see below)Potential breaking changes
The new schema system is more strict than the existing one. It is possible that some of the existing API methods will fail validation. This is a good thing, as it will prevent invalid calls to the device.
However it is not out of the question that the types may need to be adjusted to allow for valid calls.
Affected API methods
Skipped for now, dependens on
blockchain-link
No validation currently used
resolve #5297