2022-09-07 15:15:43 -04:00
|
|
|
package rln
|
|
|
|
|
|
|
|
import "encoding/hex"
|
|
|
|
|
2023-03-30 18:13:52 -04:00
|
|
|
func toMembershipKeyPairs(groupKeys [][]string) ([]IdentityCredential, error) {
|
2022-09-07 15:15:43 -04:00
|
|
|
// 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
|
|
|
|
|
2023-03-30 18:13:52 -04:00
|
|
|
groupKeyPairs := []IdentityCredential{}
|
2022-09-07 15:15:43 -04:00
|
|
|
for _, pair := range groupKeys {
|
2023-03-30 18:13:52 -04:00
|
|
|
idSecretHash, err := hex.DecodeString(pair[0])
|
2022-09-07 15:15:43 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
idCommitment, err := hex.DecodeString(pair[1])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-03-30 18:13:52 -04:00
|
|
|
groupKeyPairs = append(groupKeyPairs, IdentityCredential{IDSecretHash: IDSecretHash(Bytes32(idSecretHash)), IDCommitment: IDCommitment(Bytes32(idCommitment))})
|
2022-09-07 15:15:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return groupKeyPairs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Bytes32(b []byte) [32]byte {
|
|
|
|
var result [32]byte
|
2022-10-05 17:29:38 -04:00
|
|
|
copy(result[32-len(b):], b)
|
2022-09-07 15:15:43 -04:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2022-10-05 17:29:38 -04:00
|
|
|
func Bytes128(b []byte) [128]byte {
|
|
|
|
var result [128]byte
|
|
|
|
copy(result[128-len(b):], b)
|
2022-09-07 15:15:43 -04:00
|
|
|
return result
|
|
|
|
}
|