chore: update static keys

This commit is contained in:
Richard Ramos 2023-04-03 17:38:39 -04:00 committed by RichΛrd
parent f3f2c16093
commit deaab0718c
3 changed files with 49 additions and 114 deletions

View File

@ -158,7 +158,7 @@ func (s *RLNSuite) TestCheckCorrectness() {
groupKeys := STATIC_GROUP_KEYS
// create a set of MembershipKeyPair objects from groupKeys
groupKeyPairs, err := toMembershipKeyPairs(groupKeys)
groupKeyPairs, err := ToIdentityCredentials(groupKeys)
s.NoError(err)
// extract the id commitments

File diff suppressed because one or more lines are too long

View File

@ -1,26 +1,46 @@
package rln
import "encoding/hex"
import (
"encoding/hex"
)
func toMembershipKeyPairs(groupKeys [][]string) ([]IdentityCredential, error) {
func ToIdentityCredentials(groupKeys [][]string) ([]IdentityCredential, error) {
// groupKeys is sequence of membership key tuples in the form of (identity key, identity commitment) all in the hexadecimal format
// the toMembershipKeyPairs proc populates a sequence of MembershipKeyPairs using the supplied groupKeys
// the toIdentityCredentials proc populates a sequence of IdentityCredentials using the supplied groupKeys
// Returns an error if the conversion fails
groupKeyPairs := []IdentityCredential{}
for _, pair := range groupKeys {
idSecretHash, err := hex.DecodeString(pair[0])
if err != nil {
return nil, err
}
idCommitment, err := hex.DecodeString(pair[1])
var groupIdCredentials []IdentityCredential
for _, gk := range groupKeys {
idTrapdoor, err := ToBytes32LE(gk[0])
if err != nil {
return nil, err
}
groupKeyPairs = append(groupKeyPairs, IdentityCredential{IDSecretHash: IDSecretHash(Bytes32(idSecretHash)), IDCommitment: IDCommitment(Bytes32(idCommitment))})
idNullifier, err := ToBytes32LE(gk[1])
if err != nil {
return nil, err
}
idSecretHash, err := ToBytes32LE(gk[2])
if err != nil {
return nil, err
}
idCommitment, err := ToBytes32LE(gk[3])
if err != nil {
return nil, err
}
groupIdCredentials = append(groupIdCredentials, IdentityCredential{
IDTrapdoor: idTrapdoor,
IDNullifier: idNullifier,
IDSecretHash: idSecretHash,
IDCommitment: idCommitment,
})
}
return groupKeyPairs, nil
return groupIdCredentials, nil
}
func Bytes32(b []byte) [32]byte {
@ -34,3 +54,17 @@ func Bytes128(b []byte) [128]byte {
copy(result[128-len(b):], b)
return result
}
func ToBytes32LE(hexStr string) ([32]byte, error) {
b, err := hex.DecodeString(hexStr)
if err != nil {
return [32]byte{}, err
}
for i := 0; i < len(b)/2; i++ {
b[i], b[len(b)-i-1] = b[len(b)-i-1], b[i]
}
return Bytes32(b), nil
}