Browse Source

WIP: adding contact retreival from IndexedDB and preliminary return structure

master
Matthew Raymer 1 year ago
parent
commit
7a6d5307f4
  1. 2
      dist/custom-module-bundle.js
  2. 57
      src/custom-module-entry.js

2
dist/custom-module-bundle.js

File diff suppressed because one or more lines are too long

57
src/custom-module-entry.js

@ -151,6 +151,7 @@ async function createJWS(payload, signer, header = {}, options = {}) {
return [signingInput, signature].join('.');
}
function canonicalizeData (object) {
if (typeof object === 'number' && isNaN(object)) {
throw new Error('NaN is not allowed');
@ -188,6 +189,7 @@ function canonicalizeData (object) {
return `{${values}}`;
};
function encodeSection(data, shouldCanonicalize = false) {
if (shouldCanonicalize) {
return encodeBase64url(canonicalizeData(data));
@ -201,10 +203,12 @@ function encodeBase64url(s) {
return bytesToBase64url(u8a.fromString(s))
}
function instanceOfEcdsaSignature(object) {
return typeof object === 'object' && 'r' in object && 's' in object;
}
function ES256KSignerAlg(recoverable) {
return async function sign(payload, signer) {
const signature = await signer(payload);
@ -219,6 +223,7 @@ function ES256KSignerAlg(recoverable) {
};
}
function leftpad(data, size = 64) {
if (data.length === size) return data;
return '0'.repeat(size - data.length) + data;
@ -366,6 +371,7 @@ function getAllAccounts() {
});
}
// Usage with async/await:
async function fetchAllAccounts() {
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() {
const secret = localStorage.getItem('secret');
const secretUint8Array = util.decodeBase64(secret);
@ -407,14 +452,22 @@ async function makeNotifications() {
};
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 }
}
module.exports = {
makeNotifications
};

Loading…
Cancel
Save