Generic Claim
A Claim is a statement made by one identity about another identity or about itself.
In some cases Claims can be stored as leaves in the Identity Sparse Merkle Tree. In particular, they get stored in case if represent an Auth Claim, so should be "linked" to identity via inclusion in identity's SMT. As other example, a claim can be included into the state of an identity, which issues the claim if the SMT root is published on-chain and the issuance timestamping is desired.
-
Update the required dependencies.
go get github.com/iden3/go-iden3-core
-
Define the claim schema.
A claim schema defines how a set of data must be stored inside a claim. In this example, we will use a schema called
ageSchema
. According to this schema the age is stored in the first index slot of the claim data structure.The hash of the schema is generated from the content of the schema document. For our example, the hash of the schema is:
ce38102464833febf36e714922a83050
Note, that the age schema example is provided only for illustrative purposes. In real life, you would store some constant information like the date of birth, but not the age, which changes over time.
-
Create a generic claim.
Here is what the claim would look like:package main import ( "encoding/json" "fmt" "math/big" core "github.com/iden3/go-iden3-core" ) // create basic claim func main() { ageSchema, _ := core.NewSchemaHashFromHex ("ce38102464833febf36e714922a83050") // define age age := big.NewInt(25) // create claim based on the ageSchema storing the age in the first index slot, while the second data slot remains empty claim, _ := core.NewClaim(ageSchema, core.WithIndexDataInts(age, nil)) // transform claim from bytes array to json claimToMarshal, _ := json.Marshal(claim) fmt.Println(string(claimToMarshal)) }
In particular, the first 4 values of the claim represent the["106590880073303418818490710639556704462","0","25","0","0","0","0","0"]
Index
part of the claim while the last 4 represent theValue
.Index: { "106590880073303418818490710639556704462", // Schema hash "0", "25", // first index data slot stores age "0" // second index data slot is blank } Value: { "0", "0", "0", // first value data slot "0" // second value data slot }
The data stored in the first position of the Index contains a reference to the schema of the claim. As defined in the ageSchema
, the value age must be stored in the first index data slot while the second index data slot and the two value data slots are left empty. Other schemas may provide different rules on where to store the data.
The claim is a flexible and modular data primitive that can be used to represent any identity-related information
The executable code can be found here