Package com.swmansion.starknet.data
Class TypedData
-
- All Implemented Interfaces:
@Serializable() public final class TypedData
Sign message for off-chain usage. Follows standard proposed here.
String typedDataString = """ { "types": { "StarkNetDomain": [ {"name": "name", "type": "string"}, {"name": "version", "type": "felt"}, {"name": "chainId", "type": "felt"} ], "Airdrop": [ {"name": "address", "type": "felt"}, {"name": "amount", "type": "felt"} ], "Validate": [ {"name": "id", "type": "felt"}, {"name": "from", "type": "felt"}, {"name": "amount", "type": "felt"}, {"name": "nameGamer", "type": "string"}, {"name": "endDate", "type": "felt"}, {"name": "itemsAuthorized", "type": "felt*"}, {"name": "chkFunction", "type": "selector"}, {"name": "rootList", "type": "merkletree", "contains": "Airdrop"} ] }, "primaryType": "Validate", "domain": { "name": "myDapp", "version": "1", "chainId": "SN_SEPOLIA" }, "message": { "id": "0x0000004f000f", "from": "0x2c94f628d125cd0e86eaefea735ba24c262b9a441728f63e5776661829a4066", "amount": "400", "nameGamer": "Hector26", "endDate": "0x27d32a3033df4277caa9e9396100b7ca8c66a4ef8ea5f6765b91a7c17f0109c", "itemsAuthorized": ["0x01", "0x03", "0x0a", "0x0e"], "chkFunction": "check_authorization", "rootList": [ { "address": "0x69b49c2cc8b16e80e86bfc5b0614a59aa8c9b601569c7b80dde04d3f3151b79", "amount": "1554785" }, { "address": "0x7447084f620ba316a42c72ca5b8eefb3fe9a05ca5fe6430c65a69ecc4349b3b", "amount": "2578248" }, { "address": "0x3cad9a072d3cf29729ab2fad2e08972b8cfde01d4979083fb6d15e8e66f8ab1", "amount": "4732581" }, { "address": "0x7f14339f5d364946ae5e27eccbf60757a5c496bf45baf35ddf2ad30b583541a", "amount": "913548" } ] } } """; // Create a TypedData instance from string TypedData typedData = TypedData.fromJsonString(typedDataString); // Create a string from TypedData instance TypedData typedData = new TypedData(...); String typedDataString = typedData.toJsonString(); // Get a message hash Felt messageHash = typedData.getMessageHash(accountAddress);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enum
TypedData.Revision
TypedData revision.
The revision of the specification to be used.
V0 - Legacy revision, represents the de facto spec before SNIP-12 was published. V1 - Initial and current revision, represents the spec after SNIP-12 was published.
public final class
TypedData.Domain
public class
TypedData.Type
public final class
TypedData.StandardType
public final class
TypedData.MerkleTreeType
public final class
TypedData.EnumType
public final class
TypedData.Context
-
Field Summary
Fields Modifier and Type Field Description private final Map<String, List<TypedData.Type>>
types
private final String
primaryType
private final TypedData.Domain
domain
private final JsonObject
message
-
Method Summary
Modifier and Type Method Description final Map<String, List<TypedData.Type>>
getTypes()
final String
getPrimaryType()
final TypedData.Domain
getDomain()
final JsonObject
getMessage()
final Felt
getTypeHash(String typeName)
final Felt
getStructHash(String typeName, String data)
final Felt
getMessageHash(Felt accountAddress)
final String
toJsonString()
Create a JSON string from TypedData. final static TypedData
fromJsonString(String typedData)
Create TypedData from JSON string. -
-
Method Detail
-
getTypes
final Map<String, List<TypedData.Type>> getTypes()
-
getPrimaryType
final String getPrimaryType()
-
getDomain
final TypedData.Domain getDomain()
-
getMessage
final JsonObject getMessage()
-
getTypeHash
final Felt getTypeHash(String typeName)
-
getStructHash
final Felt getStructHash(String typeName, String data)
-
getMessageHash
final Felt getMessageHash(Felt accountAddress)
-
toJsonString
final String toJsonString()
Create a JSON string from TypedData.
-
fromJsonString
final static TypedData fromJsonString(String typedData)
Create TypedData from JSON string.
- Parameters:
typedData
- json string of typed data
-
-
-
-