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
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
69b71ef
Fix `TransactionVersion` test cases
DelevoXDG Feb 29, 2024
7e09e80
Use `Transaction.VX_QUERY` in estimate fee tests instead of checking …
DelevoXDG Mar 1, 2024
598a0cb
Add `TypedDataRevision` enum
DelevoXDG Mar 1, 2024
e016d68
Add docstring for `TypedDataRevision`
DelevoXDG Mar 1, 2024
0744947
Add `EnumType`
DelevoXDG Mar 1, 2024
c4061c6
Update serializer to support `EnumType`
DelevoXDG Mar 1, 2024
1963133
Fix `TypedDataRevision` serialization
DelevoXDG Mar 2, 2024
105fbca
Reference SNIP-12 as a standard in TypedData docstring
DelevoXDG Mar 2, 2024
814e549
Add `Domain` helper class
DelevoXDG Mar 2, 2024
76d76b4
Update type verification logic in `TypedData`
DelevoXDG Mar 2, 2024
57bc7fc
Merge branch 'main' into feat/snip-12
DelevoXDG Mar 2, 2024
0bfb4ab
Remove redundand typing
DelevoXDG Mar 3, 2024
336073e
Fix Domain serialization
DelevoXDG Mar 3, 2024
3a4c9e0
Fix dangling types check
DelevoXDG Mar 3, 2024
60ccd6c
Update `MerkleTree` to allow `Poseidon` hashing
DelevoXDG Mar 3, 2024
1bfe287
Minor refactor of `TypedData`
DelevoXDG Mar 4, 2024
61c3331
Fix TypedDataTest
DelevoXDG Mar 4, 2024
51f10dd
Don't support `chainn_id` in `TypedData.Domain`
DelevoXDG Mar 4, 2024
dd59869
Format
DelevoXDG Mar 6, 2024
5b84b6d
Rename `MerkleHashFunction` -> `HashMethod`
DelevoXDG Mar 6, 2024
8ce47e9
Change `domain` from `JsonObject` to `TypedData.Domain`
DelevoXDG Mar 6, 2024
0a4d59e
Add `hash(List<Felt>)` method to `HashMethod`
DelevoXDG Mar 6, 2024
b65ed36
Introduce revision-based hashing in `TypedData`
DelevoXDG Mar 6, 2024
a26bb60
Move `TypedData.domainSeparatorName` to `Domain.separatorName`
DelevoXDG Mar 6, 2024
f800d3a
Replace `contains` and `containKeys` calls with `in`
DelevoXDG Mar 6, 2024
9db210e
Add helper `String.isArray()` and `String.isEnum()` extensions
DelevoXDG Mar 6, 2024
9cb3121
Fix `HashMethod.PEDERSEN.hash`
DelevoXDG Mar 6, 2024
51abbd9
Update `TypedData.getDependencies`
DelevoXDG Mar 6, 2024
9111651
Fix serialization process for `enum` type
DelevoXDG Mar 6, 2024
5d020e3
Revert "Update `TypedData.getDependencies`"
DelevoXDG Mar 6, 2024
34282db
Update `TypedData.getDependencies`
DelevoXDG Mar 6, 2024
c7090a2
Move secondary `TypedData` constructor to the top
DelevoXDG Mar 6, 2024
ab7257e
Use isArray() instead of raw check
DelevoXDG Mar 6, 2024
73b53e4
Support preset types in `TypedData`
DelevoXDG Mar 6, 2024
4cdcd54
[BREAKING] Rename Type-related classes in `TypedData`
DelevoXDG Mar 6, 2024
e80a57a
Commit random uncommited changes
DelevoXDG Mar 6, 2024
0a889a3
Make `TypedData.verifyTypes` argument-less again
DelevoXDG Mar 6, 2024
a62f860
Update `encodeDependency` to escape when encoding and support enums
DelevoXDG Mar 6, 2024
e229118
Move `TypedData.escape` to `TypedData.encodeDependency.escape`
DelevoXDG Mar 6, 2024
869e7e3
Update array handling in `TypedData.encodeValue`
DelevoXDG Mar 7, 2024
13c3cf3
Support handling 'enum' basic type in `TypedData.encodeValue`
DelevoXDG Mar 7, 2024
0445bde
Move `merkletree` handling higher in `TypedData.encodeValue`
DelevoXDG Mar 7, 2024
2caa85c
Update `string` handling in `TypedData.encodeValue`
DelevoXDG Mar 7, 2024
b2888b0
Add support for rev 1 basic types in `TypedData.encodeValue`
DelevoXDG Mar 7, 2024
f83c5df
Update `TypedData.getMessageHash` to support rev 1
DelevoXDG Mar 7, 2024
bdb7bec
Add `Felt.fromSigned` helper factory constructors
DelevoXDG Mar 7, 2024
aaa1c0a
Properly handle `bool` and `i128` basic types in `TypedData.encodeValue`
DelevoXDG Mar 7, 2024
2f386a8
Refactor `reservedTypesV0` and `reservedTypesV1` to be sets
DelevoXDG Mar 7, 2024
a2b3c26
Reorder checks in `TypedData.verifyTypes()`
DelevoXDG Mar 7, 2024
36ce4df
Change `TypedDataRevision` `value` type from `Felt` to `Hex`
DelevoXDG Mar 7, 2024
03f9d23
Update reserved types tests
DelevoXDG Mar 7, 2024
9e57392
Lazily load TD from files in TypedDataTest
DelevoXDG Mar 8, 2024
49bfbf4
Refactor reserved types in `TypedData`
DelevoXDG Mar 8, 2024
f01a93c
Make `Felt.fromSigned` methods public, add docstring, slightly refact…
DelevoXDG Mar 8, 2024
d044e7e
Format
DelevoXDG Mar 8, 2024
f88d442
Move `TypedDataRevision` to `TypedData.Revision`
DelevoXDG Mar 8, 2024
b32bfd8
Add remaining `InvalidTypeTest` tests; Fix `TypedData.verifyTypes()`
DelevoXDG Mar 8, 2024
a57e53e
Make `TypedData.Domain.separatorName` internal
DelevoXDG Mar 8, 2024
78b3e66
Add missing `escape()`` call in `TypedData.encodeDependency()`
DelevoXDG Mar 8, 2024
5bfeffc
Refactor tests to prepare for rev 1 tests
DelevoXDG Mar 8, 2024
a734cc9
Add rev 0 `encode type` tests
DelevoXDG Mar 8, 2024
3e105f4
Move typed data test files
DelevoXDG Mar 8, 2024
8b9d522
Add remaining `encodeType` tests
DelevoXDG Mar 9, 2024
f608f9e
Fix encoding of name in `TypedData.encodeDependency()`
DelevoXDG Mar 9, 2024
de13a20
Fix `enum` handling in `TypedData.encodeDependency()`
DelevoXDG Mar 9, 2024
c0b07cb
Adjust `enum` handling `TypedData.verifyTypes()`
DelevoXDG Mar 9, 2024
3d88acc
Change `TypedData.stripPointer()` signature
DelevoXDG Mar 9, 2024
1724efc
Parametrize `encode type` test
DelevoXDG Mar 9, 2024
65565cc
Fix missing dependency test
DelevoXDG Mar 9, 2024
760adb7
Format
DelevoXDG Mar 9, 2024
31219cd
Add rev 1 `TypedData.getTypeHash()` tests
DelevoXDG Mar 9, 2024
1cc57c5
Fix `TypedData.getMessageHash()`
DelevoXDG Mar 11, 2024
27c9127
Introduce `StarknetByteArray`; fix logic
DelevoXDG Mar 11, 2024
e0b57e5
Fix and refactor `TypedData.feltFromPrimitive()`
DelevoXDG Mar 11, 2024
5a1e7be
Change `typed_data_basic_types_example.json`
DelevoXDG Mar 11, 2024
942c1ad
Better handle `enum` in `TypedData.encodeValue()`
DelevoXDG Mar 11, 2024
03363b3
Use non-docs `StarknetByteArray.fromString()` logic
DelevoXDG Mar 11, 2024
d24fdc3
Add remaining `getStructHash` and `getMessageHashArguments` tests
DelevoXDG Mar 12, 2024
890e304
Simplify `enum` handling in `TypedData.encodeValue()`
DelevoXDG Mar 12, 2024
67c370c
Move `enum` `encodeValue()` logic to a helper function
DelevoXDG Mar 12, 2024
4e37267
Move `merkletree` `encodeValue()` logic to a helper method
DelevoXDG Mar 12, 2024
908687c
Refactor `encodeValue()`
DelevoXDG Mar 12, 2024
13bc182
Drop `raw` type from `encodeValue()`; Unify and improve `merkletree` …
DelevoXDG Mar 13, 2024
7e109e8
Fix `TD_FELT_MERKLETREE` tests `typed_data_felt_merkletree_example.json`
DelevoXDG Mar 13, 2024
879f995
Add simple rev 1 test with no extra types and structs
DelevoXDG Mar 13, 2024
0b6ae22
Revert "Use non-docs `StarknetByteArray.fromString()` logic"
DelevoXDG Mar 13, 2024
09e400b
Merge branch 'main' into feat/snip-12
DelevoXDG Mar 13, 2024
a4a5ef9
Fix `StandardAccountTest` typed data tests; Add rev 1 test; Group to …
DelevoXDG Mar 13, 2024
9d9fad3
Add `encodeType` `merkletree` tests
DelevoXDG Mar 13, 2024
772688d
Format
DelevoXDG Mar 13, 2024
c26e2dd
Fix `merkletree with invalid contains` test
DelevoXDG Mar 13, 2024
89428cb
Don't nest test cases
DelevoXDG Mar 13, 2024
03abdae
Format
DelevoXDG Mar 13, 2024
eb9908f
Require `enum` to be used only in revision 1
DelevoXDG Mar 13, 2024
3cf768f
Don't nest merkletree tests
DelevoXDG Mar 13, 2024
c9d1394
Don't trim type in `extractEnumTypes()`
DelevoXDG Mar 13, 2024
ef9fad7
Merge branch 'main' into feat/snip-12
DelevoXDG Mar 14, 2024
7c847b4
Merge branch 'main' into feat/snip-12
DelevoXDG Mar 14, 2024
6cb5e5e
Simplify `types` logic; Make it private
DelevoXDG Mar 14, 2024
6b7844a
Mark `revision` as `@Transient`
DelevoXDG Mar 14, 2024
ee89660
Improve wording in `verifyTypes()` checks
DelevoXDG Mar 15, 2024
a695a26
Remove "raw" from `basicTypesV0`
DelevoXDG Mar 15, 2024
f0d8a8a
Fix tests
DelevoXDG Mar 15, 2024
7695f27
Don't discard type names with parenthesis unless they're enclosed in …
DelevoXDG Mar 15, 2024
471b2d6
Rename `types`->`allTypes`, `customTypes`->`types`
DelevoXDG Mar 15, 2024
2897787
Improve error messages; Fix `merkletree with invalid context` test
DelevoXDG Mar 17, 2024
04dd026
Format
DelevoXDG Mar 17, 2024
565c272
Minor `feltFromPrimitive()` refactor
DelevoXDG Mar 18, 2024
510c1f1
Use sealed classes for basic and preset types (#440)
DelevoXDG Mar 18, 2024
fae15d0
Add separate methods for primitives (#442)
DelevoXDG Mar 18, 2024
605700a
Nest TypedData-related test cases (#434)
DelevoXDG Mar 18, 2024
d2980b9
Merge branch 'main' into feat/snip-12
DelevoXDG Mar 18, 2024
a7453dd
Cover extra `verifyTypes()` errors
DelevoXDG Mar 18, 2024
55b9361
Use `BasicType` instead of raw string
DelevoXDG Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/src/main/kotlin/com/swmansion/starknet/crypto/HashMethod.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.swmansion.starknet.crypto

import com.swmansion.starknet.data.types.Felt

enum class HashMethod {
PEDERSEN {
override fun hash(first: Felt, second: Felt): Felt {
return StarknetCurve.pedersen(first, second)
}
override fun hash(values: List<Felt>): Felt {
return StarknetCurve.pedersenOnElements(values)
}
},
POSEIDON {
override fun hash(first: Felt, second: Felt): Felt {
return Poseidon.poseidonHash(first, second)
}
override fun hash(values: List<Felt>): Felt {
return Poseidon.poseidonHash(values)
}
}, ;

abstract fun hash(first: Felt, second: Felt): Felt
abstract fun hash(values: List<Felt>): Felt
}
Loading
Loading