-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniqueHuman.utils.js
39 lines (34 loc) · 1.02 KB
/
uniqueHuman.utils.js
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
require('dotenv').config()
const crypto = require('crypto')
const {
PrivateKey,
PublicKey,
Signature,
CircuitString,
} = require('o1js')
const getSecretValueOfIdentity = async (personalData) => {
const salt = process.env.SECRET_VALUE_UNIQUE_HUMAN
const dataArray = [
personalData.data.name,
personalData.data.surname,
// personalData.data.country, // identity is not tied to country, right?
personalData.data.pno,
salt,
]
const dataString = JSON.stringify(dataArray)
return crypto.createHash('sha256').update(dataString).digest('hex')
}
const getSecretValueOracleSignature = (secret) => {
const privateKey = PrivateKey.fromBase58(process.env.PRIVATE_KEY)
const publicKey = privateKey.toPublicKey()
// encode and sign the data
const mergedArrayOfFields = [
...CircuitString.fromString(secret).toFields(),
]
const signature = Signature.create(privateKey, mergedArrayOfFields)
return [signature, publicKey]
}
module.exports = {
getSecretValueOfIdentity,
getSecretValueOracleSignature,
}