WIP: adding contact retreival from IndexedDB and preliminary return structure
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -151,6 +151,7 @@ async function createJWS(payload, signer, header = {}, options = {}) {
|
|||||||
return [signingInput, signature].join('.');
|
return [signingInput, signature].join('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function canonicalizeData (object) {
|
function canonicalizeData (object) {
|
||||||
if (typeof object === 'number' && isNaN(object)) {
|
if (typeof object === 'number' && isNaN(object)) {
|
||||||
throw new Error('NaN is not allowed');
|
throw new Error('NaN is not allowed');
|
||||||
@@ -188,6 +189,7 @@ function canonicalizeData (object) {
|
|||||||
return `{${values}}`;
|
return `{${values}}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function encodeSection(data, shouldCanonicalize = false) {
|
function encodeSection(data, shouldCanonicalize = false) {
|
||||||
if (shouldCanonicalize) {
|
if (shouldCanonicalize) {
|
||||||
return encodeBase64url(canonicalizeData(data));
|
return encodeBase64url(canonicalizeData(data));
|
||||||
@@ -201,10 +203,12 @@ function encodeBase64url(s) {
|
|||||||
return bytesToBase64url(u8a.fromString(s))
|
return bytesToBase64url(u8a.fromString(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function instanceOfEcdsaSignature(object) {
|
function instanceOfEcdsaSignature(object) {
|
||||||
return typeof object === 'object' && 'r' in object && 's' in object;
|
return typeof object === 'object' && 'r' in object && 's' in object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function ES256KSignerAlg(recoverable) {
|
function ES256KSignerAlg(recoverable) {
|
||||||
return async function sign(payload, signer) {
|
return async function sign(payload, signer) {
|
||||||
const signature = await signer(payload);
|
const signature = await signer(payload);
|
||||||
@@ -219,6 +223,7 @@ function ES256KSignerAlg(recoverable) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function leftpad(data, size = 64) {
|
function leftpad(data, size = 64) {
|
||||||
if (data.length === size) return data;
|
if (data.length === size) return data;
|
||||||
return '0'.repeat(size - data.length) + data;
|
return '0'.repeat(size - data.length) + data;
|
||||||
@@ -366,6 +371,7 @@ function getAllAccounts() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Usage with async/await:
|
// Usage with async/await:
|
||||||
async function fetchAllAccounts() {
|
async function fetchAllAccounts() {
|
||||||
try {
|
try {
|
||||||
@@ -379,6 +385,45 @@ async function fetchAllAccounts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getAllContacts() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let openRequest = indexedDB.open('TimeSafari');
|
||||||
|
|
||||||
|
openRequest.onupgradeneeded = (event) => {
|
||||||
|
// Handle database setup if necessary
|
||||||
|
let db = event.target.result;
|
||||||
|
if (!db.objectStoreNames.contains('contacts')) {
|
||||||
|
db.createObjectStore('contacts', { keyPath: 'id' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
openRequest.onsuccess = (event) => {
|
||||||
|
let db = event.target.result;
|
||||||
|
let transaction = db.transaction('contacts', 'readonly');
|
||||||
|
let objectStore = transaction.objectStore('contacts');
|
||||||
|
let getAllRequest = objectStore.getAll();
|
||||||
|
|
||||||
|
getAllRequest.onsuccess = () => resolve(getAllRequest.result);
|
||||||
|
getAllRequest.onerror = () => reject(getAllRequest.error);
|
||||||
|
};
|
||||||
|
|
||||||
|
openRequest.onerror = () => reject(openRequest.error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function fetchAllContacts() {
|
||||||
|
try {
|
||||||
|
const contacts = await getAllContacts();
|
||||||
|
console.log('Contacts:', contacts);
|
||||||
|
return contacts;
|
||||||
|
// Further processing with 'contacts' if necessary
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Could not get contacts:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function makeNotifications() {
|
async function makeNotifications() {
|
||||||
const secret = localStorage.getItem('secret');
|
const secret = localStorage.getItem('secret');
|
||||||
const secretUint8Array = util.decodeBase64(secret);
|
const secretUint8Array = util.decodeBase64(secret);
|
||||||
@@ -407,14 +452,22 @@ async function makeNotifications() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
headers["Authorization"] = "Bearer " + await accessToken(identifier);
|
headers["Authorization"] = "Bearer " + await accessToken(identifier);
|
||||||
|
let response = await fetch("https://test-api.endorser.ch/api/v2/report/claims", {
|
||||||
|
method: 'GET',
|
||||||
|
headers: headers,
|
||||||
|
});
|
||||||
|
|
||||||
results.push({ "headers": headers })
|
if (response.status_code =- 200) {
|
||||||
|
data = response.json()['data']
|
||||||
|
results.push({ [did]: data.length })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { "headers": headers }
|
return { "headers": headers }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
makeNotifications
|
makeNotifications
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user