|
|
@ -424,50 +424,52 @@ async function fetchAllContacts() { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function makeNotifications() { |
|
|
|
async function getNotificationCount() { |
|
|
|
const secret = localStorage.getItem('secret'); |
|
|
|
const secretUint8Array = util.decodeBase64(secret); |
|
|
|
|
|
|
|
const setting = await getSettingById(1); |
|
|
|
const settings = await getSettingById(1); |
|
|
|
const activeDid = settings['activeDid']; |
|
|
|
const accounts = await fetchAllAccounts(); |
|
|
|
|
|
|
|
let results = []; |
|
|
|
let result = null; |
|
|
|
for (var i = 0; i < accounts.length; i++) { |
|
|
|
let account = accounts[i]; |
|
|
|
let did = account['did']; |
|
|
|
let publicKeyHex = account['publicKeyHex']; |
|
|
|
let identity = account['identity']; |
|
|
|
|
|
|
|
const messageWithNonceAsUint8Array = util.decodeBase64(identity); |
|
|
|
const nonce = messageWithNonceAsUint8Array.slice(0, 24); |
|
|
|
const message = messageWithNonceAsUint8Array.slice(24, identity.length); |
|
|
|
const decrypted = nacl.secretbox.open(message, nonce, secretUint8Array); |
|
|
|
|
|
|
|
const decoder = new TextDecoder('utf-8'); |
|
|
|
const msg = decoder.decode(decrypted); |
|
|
|
const identifier = JSON.parse(JSON.parse(msg)); |
|
|
|
|
|
|
|
const headers = { |
|
|
|
"Content-Type": "application/json", |
|
|
|
}; |
|
|
|
|
|
|
|
headers["Authorization"] = "Bearer " + await accessToken(identifier); |
|
|
|
let response = await fetch("https://test-api.endorser.ch/api/v2/report/claims", { |
|
|
|
method: 'GET', |
|
|
|
headers: headers, |
|
|
|
}); |
|
|
|
|
|
|
|
if (response.status_code =- 200) { |
|
|
|
data = response.json()['data'] |
|
|
|
results.push({ [did]: data.length }) |
|
|
|
if (did == activeDid) { |
|
|
|
let publicKeyHex = account['publicKeyHex']; |
|
|
|
let identity = account['identity']; |
|
|
|
|
|
|
|
const messageWithNonceAsUint8Array = util.decodeBase64(identity); |
|
|
|
const nonce = messageWithNonceAsUint8Array.slice(0, 24); |
|
|
|
const message = messageWithNonceAsUint8Array.slice(24, identity.length); |
|
|
|
const decrypted = nacl.secretbox.open(message, nonce, secretUint8Array); |
|
|
|
|
|
|
|
const decoder = new TextDecoder('utf-8'); |
|
|
|
const msg = decoder.decode(decrypted); |
|
|
|
const identifier = JSON.parse(JSON.parse(msg)); |
|
|
|
|
|
|
|
const headers = { |
|
|
|
"Content-Type": "application/json", |
|
|
|
}; |
|
|
|
|
|
|
|
headers["Authorization"] = "Bearer " + await accessToken(identifier); |
|
|
|
let response = await fetch("https://test-api.endorser.ch/api/v2/report/claims", { |
|
|
|
method: 'GET', |
|
|
|
headers: headers, |
|
|
|
}); |
|
|
|
|
|
|
|
if (response.status_code =- 200) { |
|
|
|
data = response.json()['data'] |
|
|
|
result = { [did]: data.length }; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return { "headers": headers } |
|
|
|
|
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
makeNotifications |
|
|
|
getNotificationCount |
|
|
|
}; |