Skip to content
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

Update TypedData in line with SNIP-12 #428

Merged
merged 114 commits into from
Mar 18, 2024
Merged

Update TypedData in line with SNIP-12 #428

merged 114 commits into from
Mar 18, 2024

Conversation

DelevoXDG
Copy link
Contributor

@DelevoXDG DelevoXDG commented Mar 2, 2024

Describe your changes

This PR is part of the stack:

-- Update TypedData in line with SNIP-12 (#428)
-- Use sealed classes for basic and preset types (#440)
-- Add separate methods for primitives (#442)
-- Nest TypedData-related test cases (#434)

TypedData Revision 0 and Revision 1

  • Support bool basic type
  • Introduce Domain class; Use it for domain instead of JsonObject
  • Introduce Revision enum
  • Remove raw basic type; Don't allow merkletree with raw leaves type
  • Rename type-related classes
    • TypeBase->Type
    • Type->StandardType

TypedData Revision 1

  • Support new types
    • Basic types: enum, string (long string), u128, i128, ContractAddress, ClassHash, timestamp, shortstring
      • Add EnumType
    • Preset types: TokenAddress, NtfId, u256
  • Rename types->customTypes; Add types to handle customTypes + presetTypes Add allTypes to handle types + presetTypes
  • Update type verification in line with these suggestions
  • Update internal logic in line with revision 1 standards

Other

  • Expand HashMethod enum to hash multiple elements

Linked issues

Closes #423

Breaking changes

  • This issue contains breaking changes
  • TypedData.domain is now of type TypedData.Domain instead of JsonObject
  • Renamed TypedData.Type->TypedData.StandardType, TypedData.TypeBase->TypedData.Type
  • Removed raw basic type

References

(might come in handy for reviews)

- Add `revision`, `domainObjectName` helper fields to `TypedData`
- Add new restrictions on types introduced in SNIP-12
- Move versioned `reservedTypes` to companion object
- All fields handled as JsonPrimitives
- Allow `chainId` and `chain_id` (should be verified if `chain_id` is valid for revision 0)
- Add type specific references, arrays
- Add `extractEnumTypes` helper
- Adjust tests to not have any dangling types
- Add `MerkleHashFunction` enum
- `MerkleTree` now accepts `hashFunction` as an optinal argument
- (breaking) `MerkleTree.hash` now requires `hashFunction` to be specified
- Rename `domainObjectName` to `domainSeparatorName`
- Format `referencedTypes` logic for better readability
- Remove @JsonNames from `TypedData.Domain`
- Fix `TD_SESSION` test case in `TypedDataTest`
  - Use `chainId` instead of `chain_id` in `typed_data_session_example.json`
@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2024

Codecov Report

Attention: Patch coverage is 85.26786% with 33 lines in your changes are missing coverage. Please review.

Project coverage is 71.11%. Comparing base (245d48b) to head (d2980b9).

Files Patch % Lines
...in/kotlin/com/swmansion/starknet/data/TypedData.kt 86.17% 9 Missing and 21 partials ⚠️
...et/data/serializers/TypedDataTypeBaseSerializer.kt 40.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #428      +/-   ##
==========================================
+ Coverage   70.55%   71.11%   +0.55%     
==========================================
  Files          75       75              
  Lines        3186     3337     +151     
  Branches      316      366      +50     
==========================================
+ Hits         2248     2373     +125     
- Misses        789      797       +8     
- Partials      149      167      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

DelevoXDG added 10 commits March 6, 2024 13:05
- Move to package com.swmansion.starknet.crypto
- Implement using abstract function instead of stored lambda
- Add revision-based `hashMethod`, `hashArray()`
- Use `hashArray()` for hasing arrays
- Instantiate `MerkleTree` with `hashMethod`
- Support REV1 enum types
- Support getting dep from contains for merkletree (this should probably be verified)
- Refactor logic
- Support revision 0 type named enum
@DelevoXDG DelevoXDG marked this pull request as ready for review March 14, 2024 13:10
…parentheses from both sidews

- Only `(example_name)` is not allowed, `(example_name` and `example_name)` are now considered valid
Copy link
Member

@THenry14 THenry14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

@DelevoXDG DelevoXDG merged commit 569c64f into main Mar 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update TypedData in line with SNIP-12
3 participants