-
Notifications
You must be signed in to change notification settings - Fork 33
/
example_test.go
53 lines (46 loc) · 1.16 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package core
import (
"encoding/hex"
"fmt"
"time"
"github.com/iden3/go-iden3-crypto/poseidon"
)
func ExampleNewClaim() {
var schemaHash SchemaHash
expDate := time.Date(2021, 1, 10, 20, 30, 0, 0, time.UTC)
claim, err := NewClaim(schemaHash,
WithExpirationDate(expDate),
WithVersion(42))
if err != nil {
panic(err)
}
expDateRes, ok := claim.GetExpirationDate()
fmt.Println(ok)
fmt.Println(expDateRes.In(time.UTC).Format(time.RFC3339))
fmt.Println(claim.GetVersion())
indexEntry, valueEntry := claim.RawSlots()
indexHash, err := poseidon.Hash(ElemBytesToInts(indexEntry[:]))
if err != nil {
panic(err)
}
valueHash, err := poseidon.Hash(ElemBytesToInts(valueEntry[:]))
if err != nil {
panic(err)
}
indexSlot, err := NewElemBytesFromInt(indexHash)
if err != nil {
panic(err)
}
valueSlot, err := NewElemBytesFromInt(valueHash)
if err != nil {
panic(err)
}
fmt.Println(hex.EncodeToString(indexSlot[:]))
fmt.Println(hex.EncodeToString(valueSlot[:]))
// Output:
// true
// 2021-01-10T20:30:00Z
// 42
// a07b32a81b631544f9199f4bf429ad2026baec31ba5e5e707a49cc2c9d243f18
// 8e6bca4b559d758eca7b6125faea23ed0765cdcb6f85b3fe9477ca4293a6fd05
}