mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-05-15 22:26:58 +00:00
Format code
This commit is contained in:
parent
035142504b
commit
452c3a0894
@ -1,5 +1,5 @@
|
||||
import { useCallback, useContext, useEffect, useState } from 'react';
|
||||
import Logo2 from '../assets/svgs/Logo2.svg';
|
||||
import Logo2 from '../../assets/svgs/Logo2.svg';
|
||||
import {
|
||||
MyContext,
|
||||
getArbitraryEndpointReact,
|
||||
|
@ -14,15 +14,18 @@ async function initializeKeyAndIV() {
|
||||
async function generateKey(): Promise<CryptoKey> {
|
||||
return await crypto.subtle.generateKey(
|
||||
{
|
||||
name: "AES-GCM",
|
||||
length: 256
|
||||
name: 'AES-GCM',
|
||||
length: 256,
|
||||
},
|
||||
true,
|
||||
["encrypt", "decrypt"]
|
||||
['encrypt', 'decrypt']
|
||||
);
|
||||
}
|
||||
|
||||
async function encryptData(data: string, key: CryptoKey): Promise<{ iv: Uint8Array; encryptedData: ArrayBuffer }> {
|
||||
async function encryptData(
|
||||
data: string,
|
||||
key: CryptoKey
|
||||
): Promise<{ iv: Uint8Array; encryptedData: ArrayBuffer }> {
|
||||
const encoder = new TextEncoder();
|
||||
const encodedData = encoder.encode(data);
|
||||
|
||||
@ -31,8 +34,8 @@ async function encryptData(data: string, key: CryptoKey): Promise<{ iv: Uint8Arr
|
||||
|
||||
const encryptedData = await crypto.subtle.encrypt(
|
||||
{
|
||||
name: "AES-GCM",
|
||||
iv: iv
|
||||
name: 'AES-GCM',
|
||||
iv: iv,
|
||||
},
|
||||
key,
|
||||
encodedData
|
||||
@ -41,11 +44,15 @@ async function encryptData(data: string, key: CryptoKey): Promise<{ iv: Uint8Arr
|
||||
return { iv, encryptedData };
|
||||
}
|
||||
|
||||
async function decryptData(encryptedData: ArrayBuffer, key: CryptoKey, iv: Uint8Array): Promise<string> {
|
||||
async function decryptData(
|
||||
encryptedData: ArrayBuffer,
|
||||
key: CryptoKey,
|
||||
iv: Uint8Array
|
||||
): Promise<string> {
|
||||
const decryptedData = await crypto.subtle.decrypt(
|
||||
{
|
||||
name: "AES-GCM",
|
||||
iv: iv
|
||||
name: 'AES-GCM',
|
||||
iv: iv,
|
||||
},
|
||||
key,
|
||||
encryptedData
|
||||
@ -83,7 +90,10 @@ export const storeData = async (key: string, payload: any): Promise<string> => {
|
||||
const { iv, encryptedData } = await encryptData(base64Data, inMemoryKey);
|
||||
|
||||
// Combine IV and encrypted data into a single Uint8Array
|
||||
const combinedData = new Uint8Array([...iv, ...new Uint8Array(encryptedData)]);
|
||||
const combinedData = new Uint8Array([
|
||||
...iv,
|
||||
...new Uint8Array(encryptedData),
|
||||
]);
|
||||
const encryptedBase64Data = btoa(String.fromCharCode(...combinedData));
|
||||
await SecureStoragePlugin.set({ key, value: encryptedBase64Data });
|
||||
} else {
|
||||
@ -91,10 +101,9 @@ export const storeData = async (key: string, payload: any): Promise<string> => {
|
||||
await SecureStoragePlugin.set({ key, value: base64Data });
|
||||
}
|
||||
|
||||
return "Data saved successfully";
|
||||
return 'Data saved successfully';
|
||||
};
|
||||
|
||||
|
||||
export const getData = async <T = any>(key: string): Promise<T | null> => {
|
||||
await initializeKeyAndIV();
|
||||
|
||||
@ -105,13 +114,17 @@ export const getData = async <T = any>(key: string): Promise<T | null> => {
|
||||
if (keysToEncrypt.includes(key) && inMemoryKey) {
|
||||
// Decode the Base64-encoded encrypted data
|
||||
const combinedData = atob(storedDataBase64.value)
|
||||
.split("")
|
||||
.split('')
|
||||
.map((c) => c.charCodeAt(0));
|
||||
|
||||
const iv = new Uint8Array(combinedData.slice(0, 12)); // First 12 bytes are the IV
|
||||
const encryptedData = new Uint8Array(combinedData.slice(12)).buffer;
|
||||
|
||||
const decryptedBase64Data = await decryptData(encryptedData, inMemoryKey, iv);
|
||||
const decryptedBase64Data = await decryptData(
|
||||
encryptedData,
|
||||
inMemoryKey,
|
||||
iv
|
||||
);
|
||||
return base64ToJson(decryptedBase64Data);
|
||||
} else {
|
||||
// Decode non-encrypted data
|
||||
@ -121,16 +134,16 @@ export const getData = async <T = any>(key: string): Promise<T | null> => {
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Remove keys from storage and log out
|
||||
export async function removeKeysAndLogout(keys: string[], event: MessageEvent, request: any) {
|
||||
export async function removeKeysAndLogout(
|
||||
keys: string[],
|
||||
event: MessageEvent,
|
||||
request: any
|
||||
) {
|
||||
try {
|
||||
for (const key of keys) {
|
||||
try {
|
||||
@ -144,13 +157,13 @@ export async function removeKeysAndLogout(keys: string[], event: MessageEvent, r
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "logout",
|
||||
action: 'logout',
|
||||
payload: true,
|
||||
type: "backgroundMessageResponse",
|
||||
type: 'backgroundMessageResponse',
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error removing keys:", error);
|
||||
console.error('Error removing keys:', error);
|
||||
}
|
||||
}
|
||||
|
@ -8,24 +8,24 @@ export function decodeIfEncoded(input) {
|
||||
}
|
||||
} catch (e) {
|
||||
// decodeURIComponent throws an error if input is not encoded
|
||||
console.error("Error decoding URI:", e);
|
||||
console.error('Error decoding URI:', e);
|
||||
}
|
||||
|
||||
// Return input as-is if not URI-encoded
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
export const isValidBase64 = (str: string): boolean => {
|
||||
if (typeof str !== "string" || str.length % 4 !== 0) return false;
|
||||
export const isValidBase64 = (str: string): boolean => {
|
||||
if (typeof str !== 'string' || str.length % 4 !== 0) return false;
|
||||
|
||||
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
||||
return base64Regex.test(str);
|
||||
};
|
||||
};
|
||||
|
||||
export const isValidBase64WithDecode = (str: string): boolean => {
|
||||
export const isValidBase64WithDecode = (str: string): boolean => {
|
||||
try {
|
||||
return isValidBase64(str) && Boolean(atob(str));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -1,38 +1,59 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import Base58 from '../deps/Base58'
|
||||
import ed2curve from '../deps/ed2curve'
|
||||
import nacl from '../deps/nacl-fast'
|
||||
import {Sha256} from 'asmcrypto.js'
|
||||
import Base58 from '../deps/Base58';
|
||||
import ed2curve from '../deps/ed2curve';
|
||||
import nacl from '../deps/nacl-fast';
|
||||
import { Sha256 } from 'asmcrypto.js';
|
||||
|
||||
|
||||
export const decryptChatMessage = (encryptedMessage, privateKey, recipientPublicKey, lastReference) => {
|
||||
const test = encryptedMessage
|
||||
let _encryptedMessage = atob(encryptedMessage)
|
||||
const binaryLength = _encryptedMessage.length
|
||||
const bytes = new Uint8Array(binaryLength)
|
||||
export const decryptChatMessage = (
|
||||
encryptedMessage,
|
||||
privateKey,
|
||||
recipientPublicKey,
|
||||
lastReference
|
||||
) => {
|
||||
const test = encryptedMessage;
|
||||
let _encryptedMessage = atob(encryptedMessage);
|
||||
const binaryLength = _encryptedMessage.length;
|
||||
const bytes = new Uint8Array(binaryLength);
|
||||
|
||||
for (let i = 0; i < binaryLength; i++) {
|
||||
bytes[i] = _encryptedMessage.charCodeAt(i)
|
||||
bytes[i] = _encryptedMessage.charCodeAt(i);
|
||||
}
|
||||
|
||||
const _base58RecipientPublicKey =
|
||||
recipientPublicKey instanceof Uint8Array
|
||||
? Base58.encode(recipientPublicKey)
|
||||
: recipientPublicKey;
|
||||
const _recipientPublicKey = Base58.decode(_base58RecipientPublicKey);
|
||||
|
||||
const _base58RecipientPublicKey = recipientPublicKey instanceof Uint8Array ? Base58.encode(recipientPublicKey) : recipientPublicKey
|
||||
const _recipientPublicKey = Base58.decode(_base58RecipientPublicKey)
|
||||
const _lastReference =
|
||||
lastReference instanceof Uint8Array
|
||||
? lastReference
|
||||
: Base58.decode(lastReference);
|
||||
|
||||
const _lastReference = lastReference instanceof Uint8Array ? lastReference : Base58.decode(lastReference)
|
||||
|
||||
const convertedPrivateKey = ed2curve.convertSecretKey(privateKey)
|
||||
const convertedPublicKey = ed2curve.convertPublicKey(_recipientPublicKey)
|
||||
const convertedPrivateKey = ed2curve.convertSecretKey(privateKey);
|
||||
const convertedPublicKey = ed2curve.convertPublicKey(_recipientPublicKey);
|
||||
const sharedSecret = new Uint8Array(32);
|
||||
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey)
|
||||
nacl.lowlevel.crypto_scalarmult(
|
||||
sharedSecret,
|
||||
convertedPrivateKey,
|
||||
convertedPublicKey
|
||||
);
|
||||
|
||||
const _chatEncryptionSeed = new Sha256().process(sharedSecret).finish().result
|
||||
const _decryptedMessage = nacl.secretbox.open(bytes, _lastReference.slice(0, 24), _chatEncryptionSeed)
|
||||
const _chatEncryptionSeed = new Sha256()
|
||||
.process(sharedSecret)
|
||||
.finish().result;
|
||||
const _decryptedMessage = nacl.secretbox.open(
|
||||
bytes,
|
||||
_lastReference.slice(0, 24),
|
||||
_chatEncryptionSeed
|
||||
);
|
||||
|
||||
let decryptedMessage = ''
|
||||
let decryptedMessage = '';
|
||||
|
||||
_decryptedMessage === false ? decryptedMessage : decryptedMessage = new TextDecoder('utf-8').decode(_decryptedMessage)
|
||||
_decryptedMessage === false
|
||||
? decryptedMessage
|
||||
: (decryptedMessage = new TextDecoder('utf-8').decode(_decryptedMessage));
|
||||
|
||||
return decryptedMessage
|
||||
}
|
||||
return decryptedMessage;
|
||||
};
|
||||
|
@ -1,33 +1,38 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import { crypto } from '../constants/decryptWallet'
|
||||
import Base58 from '../deps/Base58'
|
||||
import {AES_CBC, HmacSha512} from 'asmcrypto.js'
|
||||
import { doInitWorkers, kdf } from '../deps/kdf'
|
||||
|
||||
import { crypto } from '../constants/decryptWallet';
|
||||
import Base58 from '../deps/Base58';
|
||||
import { AES_CBC, HmacSha512 } from 'asmcrypto.js';
|
||||
import { doInitWorkers, kdf } from '../deps/kdf';
|
||||
|
||||
export const decryptStoredWallet = async (password, wallet) => {
|
||||
const threads = doInitWorkers(crypto.kdfThreads)
|
||||
const encryptedSeedBytes = Base58.decode(wallet.encryptedSeed)
|
||||
const iv = Base58.decode(wallet.iv)
|
||||
const salt = Base58.decode(wallet.salt)
|
||||
const threads = doInitWorkers(crypto.kdfThreads);
|
||||
const encryptedSeedBytes = Base58.decode(wallet.encryptedSeed);
|
||||
const iv = Base58.decode(wallet.iv);
|
||||
const salt = Base58.decode(wallet.salt);
|
||||
|
||||
const key = await kdf(password, salt, threads)
|
||||
const encryptionKey = key.slice(0, 32)
|
||||
const macKey = key.slice(32, 63)
|
||||
const mac = new HmacSha512(macKey).process(encryptedSeedBytes).finish().result
|
||||
const key = await kdf(password, salt, threads);
|
||||
const encryptionKey = key.slice(0, 32);
|
||||
const macKey = key.slice(32, 63);
|
||||
const mac = new HmacSha512(macKey)
|
||||
.process(encryptedSeedBytes)
|
||||
.finish().result;
|
||||
if (Base58.encode(mac) !== wallet.mac) {
|
||||
throw new Error("Incorrect password")
|
||||
throw new Error('Incorrect password');
|
||||
}
|
||||
const decryptedBytes = AES_CBC.decrypt(encryptedSeedBytes, encryptionKey, false, iv)
|
||||
return decryptedBytes
|
||||
}
|
||||
const decryptedBytes = AES_CBC.decrypt(
|
||||
encryptedSeedBytes,
|
||||
encryptionKey,
|
||||
false,
|
||||
iv
|
||||
);
|
||||
return decryptedBytes;
|
||||
};
|
||||
|
||||
export const decryptStoredWalletFromSeedPhrase = async (password) => {
|
||||
const threads = doInitWorkers(crypto.kdfThreads)
|
||||
const salt = new Uint8Array(void 0)
|
||||
const threads = doInitWorkers(crypto.kdfThreads);
|
||||
const salt = new Uint8Array(void 0);
|
||||
|
||||
|
||||
const seed = await kdf(password, salt, threads)
|
||||
return seed
|
||||
}
|
||||
const seed = await kdf(password, salt, threads);
|
||||
return seed;
|
||||
};
|
||||
|
@ -1,11 +1,12 @@
|
||||
export const executeEvent = (eventName: string, data: any)=> {
|
||||
const event = new CustomEvent(eventName, {detail: data})
|
||||
document.dispatchEvent(event)
|
||||
}
|
||||
export const subscribeToEvent = (eventName: string, listener: any)=> {
|
||||
document.addEventListener(eventName, listener)
|
||||
}
|
||||
export const executeEvent = (eventName: string, data: any) => {
|
||||
const event = new CustomEvent(eventName, { detail: data });
|
||||
document.dispatchEvent(event);
|
||||
};
|
||||
|
||||
export const unsubscribeFromEvent = (eventName: string, listener: any)=> {
|
||||
document.removeEventListener(eventName, listener)
|
||||
}
|
||||
export const subscribeToEvent = (eventName: string, listener: any) => {
|
||||
document.addEventListener(eventName, listener);
|
||||
};
|
||||
|
||||
export const unsubscribeFromEvent = (eventName: string, listener: any) => {
|
||||
document.removeEventListener(eventName, listener);
|
||||
};
|
||||
|
@ -1,33 +1,27 @@
|
||||
import moment from "moment";
|
||||
|
||||
export const delay = (time: number) => new Promise((_, reject) =>
|
||||
export const delay = (time: number) =>
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Request timed out')), time)
|
||||
);
|
||||
|
||||
// const originalHtml = `<p>---------- Forwarded message ---------</p><p>From: Alex</p><p>Date: Mon, Jun 9 2014 9:32 PM</p><p>Subject: Batteries </p><p>To: Jessica</p><p><br></p><p><br></p>`;
|
||||
|
||||
|
||||
// export function updateMessageDetails(newFrom: string, newDateMillis: number, newTo: string) {
|
||||
// let htmlString = originalHtml
|
||||
// // Use Moment.js to format the date from milliseconds
|
||||
// const formattedDate = moment(newDateMillis).format('ddd, MMM D YYYY h:mm A');
|
||||
|
||||
// // Replace the From, Date, and To fields in the HTML string
|
||||
// htmlString = htmlString.replace(/<p>From:.*?<\/p>/, `<p>From: ${newFrom}</p>`);
|
||||
// htmlString = htmlString.replace(/<p>Date:.*?<\/p>/, `<p>Date: ${formattedDate}</p>`);
|
||||
// htmlString = htmlString.replace(/<p>To:.*?<\/p>/, `<p>To: ${newTo}</p>`);
|
||||
|
||||
// return htmlString;
|
||||
// }
|
||||
);
|
||||
|
||||
const originalHtml = `<p>---------- Forwarded message ---------</p><p>From: Alex</p><p>Subject: Batteries </p><p>To: Jessica</p><p><br></p><p><br></p>`;
|
||||
|
||||
export function updateMessageDetails(
|
||||
newFrom: string,
|
||||
newSubject: string,
|
||||
newTo: string
|
||||
) {
|
||||
let htmlString = originalHtml;
|
||||
|
||||
export function updateMessageDetails(newFrom: string, newSubject: string, newTo: string) {
|
||||
let htmlString = originalHtml
|
||||
htmlString = htmlString.replace(
|
||||
/<p>From:.*?<\/p>/,
|
||||
`<p>From: ${newFrom}</p>`
|
||||
);
|
||||
|
||||
htmlString = htmlString.replace(
|
||||
/<p>Subject:.*?<\/p>/,
|
||||
`<p>Subject: ${newSubject}</p>`
|
||||
);
|
||||
|
||||
htmlString = htmlString.replace(/<p>From:.*?<\/p>/, `<p>From: ${newFrom}</p>`);
|
||||
htmlString = htmlString.replace(/<p>Subject:.*?<\/p>/, `<p>Subject: ${newSubject}</p>`);
|
||||
htmlString = htmlString.replace(/<p>To:.*?<\/p>/, `<p>To: ${newTo}</p>`);
|
||||
|
||||
return htmlString;
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { openIndexedDB } from "../components/Apps/useQortalMessageListener";
|
||||
import { fileToBase64 } from "./fileReading";
|
||||
import { openIndexedDB } from '../components/Apps/useQortalMessageListener';
|
||||
import { fileToBase64 } from './fileReading';
|
||||
|
||||
export async function handleGetFileFromIndexedDB(event) {
|
||||
try {
|
||||
const { fileId, requestId } = event.data;
|
||||
const db = await openIndexedDB();
|
||||
const transaction = db.transaction(["files"], "readonly");
|
||||
const objectStore = transaction.objectStore("files");
|
||||
const transaction = db.transaction(['files'], 'readonly');
|
||||
const objectStore = transaction.objectStore('files');
|
||||
|
||||
const getRequest = objectStore.get(fileId);
|
||||
|
||||
@ -18,8 +18,8 @@ export async function handleGetFileFromIndexedDB(event) {
|
||||
const base64String = await fileToBase64(file);
|
||||
|
||||
// Create a new transaction to delete the file
|
||||
const deleteTransaction = db.transaction(["files"], "readwrite");
|
||||
const deleteObjectStore = deleteTransaction.objectStore("files");
|
||||
const deleteTransaction = db.transaction(['files'], 'readwrite');
|
||||
const deleteObjectStore = deleteTransaction.objectStore('files');
|
||||
const deleteRequest = deleteObjectStore.delete(fileId);
|
||||
|
||||
deleteRequest.onsuccess = function () {
|
||||
@ -27,29 +27,37 @@ export async function handleGetFileFromIndexedDB(event) {
|
||||
const targetOrigin = window.location.origin;
|
||||
|
||||
window.postMessage(
|
||||
{ action: "getFileFromIndexedDBResponse", requestId, result: base64String },
|
||||
{
|
||||
action: 'getFileFromIndexedDBResponse',
|
||||
requestId,
|
||||
result: base64String,
|
||||
},
|
||||
targetOrigin
|
||||
);
|
||||
} catch (error) {
|
||||
console.log('error', error)
|
||||
console.log('error', error);
|
||||
}
|
||||
};
|
||||
|
||||
deleteRequest.onerror = function () {
|
||||
console.error(`Error deleting file with ID ${fileId} from IndexedDB`);
|
||||
|
||||
console.error(
|
||||
`Error deleting file with ID ${fileId} from IndexedDB`
|
||||
);
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error converting file to Base64:", error);
|
||||
console.error('Error converting file to Base64:', error);
|
||||
event.ports[0].postMessage({
|
||||
result: null,
|
||||
error: "Failed to convert file to Base64",
|
||||
error: 'Failed to convert file to Base64',
|
||||
});
|
||||
const targetOrigin = window.location.origin;
|
||||
|
||||
window.postMessage(
|
||||
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
||||
error: "Failed to convert file to Base64"
|
||||
{
|
||||
action: 'getFileFromIndexedDBResponse',
|
||||
requestId,
|
||||
result: null,
|
||||
error: 'Failed to convert file to Base64',
|
||||
},
|
||||
targetOrigin
|
||||
);
|
||||
@ -59,8 +67,11 @@ export async function handleGetFileFromIndexedDB(event) {
|
||||
const targetOrigin = window.location.origin;
|
||||
|
||||
window.postMessage(
|
||||
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
||||
error: 'File not found in IndexedDB'
|
||||
{
|
||||
action: 'getFileFromIndexedDBResponse',
|
||||
requestId,
|
||||
result: null,
|
||||
error: 'File not found in IndexedDB',
|
||||
},
|
||||
targetOrigin
|
||||
);
|
||||
@ -71,20 +82,26 @@ export async function handleGetFileFromIndexedDB(event) {
|
||||
console.error(`Error retrieving file with ID ${fileId} from IndexedDB`);
|
||||
|
||||
event.source.postMessage(
|
||||
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
||||
error: 'Error retrieving file from IndexedDB'
|
||||
{
|
||||
action: 'getFileFromIndexedDBResponse',
|
||||
requestId,
|
||||
result: null,
|
||||
error: 'Error retrieving file from IndexedDB',
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
};
|
||||
} catch (error) {
|
||||
const { requestId } = event.data;
|
||||
console.error("Error opening IndexedDB:", error);
|
||||
console.error('Error opening IndexedDB:', error);
|
||||
event.source.postMessage(
|
||||
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
||||
error: 'Error opening IndexedDB'
|
||||
{
|
||||
action: 'getFileFromIndexedDBResponse',
|
||||
requestId,
|
||||
result: null,
|
||||
error: 'Error opening IndexedDB',
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,123 +1,125 @@
|
||||
export const mimeToExtensionMap = {
|
||||
// Documents
|
||||
"application/pdf": ".pdf",
|
||||
"application/msword": ".doc",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
|
||||
"application/vnd.ms-excel": ".xls",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx",
|
||||
"application/vnd.ms-powerpoint": ".ppt",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",
|
||||
"application/vnd.oasis.opendocument.text": ".odt",
|
||||
"application/vnd.oasis.opendocument.spreadsheet": ".ods",
|
||||
"application/vnd.oasis.opendocument.presentation": ".odp",
|
||||
"text/plain": ".txt",
|
||||
"text/csv": ".csv",
|
||||
"application/xhtml+xml": ".xhtml",
|
||||
"application/xml": ".xml",
|
||||
"application/rtf": ".rtf",
|
||||
"application/vnd.apple.pages": ".pages",
|
||||
"application/vnd.google-apps.document": ".gdoc",
|
||||
"application/vnd.google-apps.spreadsheet": ".gsheet",
|
||||
"application/vnd.google-apps.presentation": ".gslides",
|
||||
'application/pdf': '.pdf',
|
||||
'application/msword': '.doc',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
||||
'.docx',
|
||||
'application/vnd.ms-excel': '.xls',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx',
|
||||
'application/vnd.ms-powerpoint': '.ppt',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
||||
'.pptx',
|
||||
'application/vnd.oasis.opendocument.text': '.odt',
|
||||
'application/vnd.oasis.opendocument.spreadsheet': '.ods',
|
||||
'application/vnd.oasis.opendocument.presentation': '.odp',
|
||||
'text/plain': '.txt',
|
||||
'text/csv': '.csv',
|
||||
'application/xhtml+xml': '.xhtml',
|
||||
'application/xml': '.xml',
|
||||
'application/rtf': '.rtf',
|
||||
'application/vnd.apple.pages': '.pages',
|
||||
'application/vnd.google-apps.document': '.gdoc',
|
||||
'application/vnd.google-apps.spreadsheet': '.gsheet',
|
||||
'application/vnd.google-apps.presentation': '.gslides',
|
||||
|
||||
// Images
|
||||
"image/jpeg": ".jpg",
|
||||
"image/png": ".png",
|
||||
"image/gif": ".gif",
|
||||
"image/webp": ".webp",
|
||||
"image/svg+xml": ".svg",
|
||||
"image/tiff": ".tif",
|
||||
"image/bmp": ".bmp",
|
||||
"image/x-icon": ".ico",
|
||||
"image/heic": ".heic",
|
||||
"image/heif": ".heif",
|
||||
"image/apng": ".apng",
|
||||
"image/avif": ".avif",
|
||||
'image/jpeg': '.jpg',
|
||||
'image/png': '.png',
|
||||
'image/gif': '.gif',
|
||||
'image/webp': '.webp',
|
||||
'image/svg+xml': '.svg',
|
||||
'image/tiff': '.tif',
|
||||
'image/bmp': '.bmp',
|
||||
'image/x-icon': '.ico',
|
||||
'image/heic': '.heic',
|
||||
'image/heif': '.heif',
|
||||
'image/apng': '.apng',
|
||||
'image/avif': '.avif',
|
||||
|
||||
// Audio
|
||||
"audio/mpeg": ".mp3",
|
||||
"audio/ogg": ".ogg",
|
||||
"audio/wav": ".wav",
|
||||
"audio/webm": ".weba",
|
||||
"audio/aac": ".aac",
|
||||
"audio/flac": ".flac",
|
||||
"audio/x-m4a": ".m4a",
|
||||
"audio/x-ms-wma": ".wma",
|
||||
"audio/midi": ".midi",
|
||||
"audio/x-midi": ".mid",
|
||||
'audio/mpeg': '.mp3',
|
||||
'audio/ogg': '.ogg',
|
||||
'audio/wav': '.wav',
|
||||
'audio/webm': '.weba',
|
||||
'audio/aac': '.aac',
|
||||
'audio/flac': '.flac',
|
||||
'audio/x-m4a': '.m4a',
|
||||
'audio/x-ms-wma': '.wma',
|
||||
'audio/midi': '.midi',
|
||||
'audio/x-midi': '.mid',
|
||||
|
||||
// Video
|
||||
"video/mp4": ".mp4",
|
||||
"video/webm": ".webm",
|
||||
"video/ogg": ".ogv",
|
||||
"video/x-msvideo": ".avi",
|
||||
"video/quicktime": ".mov",
|
||||
"video/x-ms-wmv": ".wmv",
|
||||
"video/mpeg": ".mpeg",
|
||||
"video/3gpp": ".3gp",
|
||||
"video/3gpp2": ".3g2",
|
||||
"video/x-matroska": ".mkv",
|
||||
"video/x-flv": ".flv",
|
||||
"video/x-ms-asf": ".asf",
|
||||
'video/mp4': '.mp4',
|
||||
'video/webm': '.webm',
|
||||
'video/ogg': '.ogv',
|
||||
'video/x-msvideo': '.avi',
|
||||
'video/quicktime': '.mov',
|
||||
'video/x-ms-wmv': '.wmv',
|
||||
'video/mpeg': '.mpeg',
|
||||
'video/3gpp': '.3gp',
|
||||
'video/3gpp2': '.3g2',
|
||||
'video/x-matroska': '.mkv',
|
||||
'video/x-flv': '.flv',
|
||||
'video/x-ms-asf': '.asf',
|
||||
|
||||
// Archives
|
||||
"application/zip": ".zip",
|
||||
"application/x-rar-compressed": ".rar",
|
||||
"application/x-tar": ".tar",
|
||||
"application/x-7z-compressed": ".7z",
|
||||
"application/x-gzip": ".gz",
|
||||
"application/x-bzip2": ".bz2",
|
||||
"application/x-apple-diskimage": ".dmg",
|
||||
"application/vnd.android.package-archive": ".apk",
|
||||
"application/x-iso9660-image": ".iso",
|
||||
'application/zip': '.zip',
|
||||
'application/x-rar-compressed': '.rar',
|
||||
'application/x-tar': '.tar',
|
||||
'application/x-7z-compressed': '.7z',
|
||||
'application/x-gzip': '.gz',
|
||||
'application/x-bzip2': '.bz2',
|
||||
'application/x-apple-diskimage': '.dmg',
|
||||
'application/vnd.android.package-archive': '.apk',
|
||||
'application/x-iso9660-image': '.iso',
|
||||
|
||||
// Code Files
|
||||
"text/javascript": ".js",
|
||||
"text/css": ".css",
|
||||
"text/html": ".html",
|
||||
"application/json": ".json",
|
||||
"text/xml": ".xml",
|
||||
"application/x-sh": ".sh",
|
||||
"application/x-csh": ".csh",
|
||||
"text/x-python": ".py",
|
||||
"text/x-java-source": ".java",
|
||||
"application/java-archive": ".jar",
|
||||
"application/vnd.microsoft.portable-executable": ".exe",
|
||||
"application/x-msdownload": ".msi",
|
||||
"text/x-c": ".c",
|
||||
"text/x-c++": ".cpp",
|
||||
"text/x-go": ".go",
|
||||
"application/x-perl": ".pl",
|
||||
"text/x-php": ".php",
|
||||
"text/x-ruby": ".rb",
|
||||
"text/x-sql": ".sql",
|
||||
"application/x-httpd-php": ".php",
|
||||
"application/x-python-code": ".pyc",
|
||||
'text/javascript': '.js',
|
||||
'text/css': '.css',
|
||||
'text/html': '.html',
|
||||
'application/json': '.json',
|
||||
'text/xml': '.xml',
|
||||
'application/x-sh': '.sh',
|
||||
'application/x-csh': '.csh',
|
||||
'text/x-python': '.py',
|
||||
'text/x-java-source': '.java',
|
||||
'application/java-archive': '.jar',
|
||||
'application/vnd.microsoft.portable-executable': '.exe',
|
||||
'application/x-msdownload': '.msi',
|
||||
'text/x-c': '.c',
|
||||
'text/x-c++': '.cpp',
|
||||
'text/x-go': '.go',
|
||||
'application/x-perl': '.pl',
|
||||
'text/x-php': '.php',
|
||||
'text/x-ruby': '.rb',
|
||||
'text/x-sql': '.sql',
|
||||
'application/x-httpd-php': '.php',
|
||||
'application/x-python-code': '.pyc',
|
||||
|
||||
// ROM Files
|
||||
"application/x-nintendo-nes-rom": ".nes",
|
||||
"application/x-snes-rom": ".smc",
|
||||
"application/x-gameboy-rom": ".gb",
|
||||
"application/x-gameboy-advance-rom": ".gba",
|
||||
"application/x-n64-rom": ".n64",
|
||||
"application/x-sega-genesis-rom": ".gen",
|
||||
"application/x-sega-master-system-rom": ".sms",
|
||||
"application/x-psx-rom": ".iso", // PlayStation ROMs
|
||||
"application/x-bios-rom": ".rom",
|
||||
"application/x-flash-rom": ".bin",
|
||||
"application/x-eeprom": ".eep",
|
||||
"application/x-c64-rom": ".prg",
|
||||
'application/x-nintendo-nes-rom': '.nes',
|
||||
'application/x-snes-rom': '.smc',
|
||||
'application/x-gameboy-rom': '.gb',
|
||||
'application/x-gameboy-advance-rom': '.gba',
|
||||
'application/x-n64-rom': '.n64',
|
||||
'application/x-sega-genesis-rom': '.gen',
|
||||
'application/x-sega-master-system-rom': '.sms',
|
||||
'application/x-psx-rom': '.iso', // PlayStation ROMs
|
||||
'application/x-bios-rom': '.rom',
|
||||
'application/x-flash-rom': '.bin',
|
||||
'application/x-eeprom': '.eep',
|
||||
'application/x-c64-rom': '.prg',
|
||||
|
||||
// Miscellaneous
|
||||
"application/octet-stream": ".bin", // General binary files
|
||||
"application/x-shockwave-flash": ".swf",
|
||||
"application/x-silverlight-app": ".xap",
|
||||
"application/x-ms-shortcut": ".lnk",
|
||||
"application/vnd.ms-fontobject": ".eot",
|
||||
"font/woff": ".woff",
|
||||
"font/woff2": ".woff2",
|
||||
"font/ttf": ".ttf",
|
||||
"font/otf": ".otf",
|
||||
"application/vnd.visio": ".vsd",
|
||||
"application/vnd.ms-project": ".mpp",
|
||||
'application/octet-stream': '.bin', // General binary files
|
||||
'application/x-shockwave-flash': '.swf',
|
||||
'application/x-silverlight-app': '.xap',
|
||||
'application/x-ms-shortcut': '.lnk',
|
||||
'application/vnd.ms-fontobject': '.eot',
|
||||
'font/woff': '.woff',
|
||||
'font/woff2': '.woff2',
|
||||
'font/ttf': '.ttf',
|
||||
'font/otf': '.otf',
|
||||
'application/vnd.visio': '.vsd',
|
||||
'application/vnd.ms-project': '.mpp',
|
||||
};
|
||||
|
@ -1,21 +1,22 @@
|
||||
import moment from "moment"
|
||||
import moment from 'moment';
|
||||
|
||||
export function formatTimestamp(timestamp: number): string {
|
||||
const now = moment()
|
||||
const timestampMoment = moment(timestamp)
|
||||
const elapsedTime = now.diff(timestampMoment, 'minutes')
|
||||
const now = moment();
|
||||
const timestampMoment = moment(timestamp);
|
||||
const elapsedTime = now.diff(timestampMoment, 'minutes');
|
||||
|
||||
if (elapsedTime < 1) {
|
||||
return 'Just now'
|
||||
return 'Just now';
|
||||
} else if (elapsedTime < 60) {
|
||||
return `${elapsedTime}m ago`
|
||||
return `${elapsedTime}m ago`;
|
||||
} else if (elapsedTime < 1440) {
|
||||
return `${Math.floor(elapsedTime / 60)}h ago`
|
||||
return `${Math.floor(elapsedTime / 60)}h ago`;
|
||||
} else {
|
||||
return timestampMoment.format('MMM D, YYYY')
|
||||
return timestampMoment.format('MMM D, YYYY');
|
||||
}
|
||||
}
|
||||
export function formatTimestampForum(timestamp: number): string {
|
||||
}
|
||||
|
||||
export function formatTimestampForum(timestamp: number): string {
|
||||
const now = moment();
|
||||
const timestampMoment = moment(timestamp);
|
||||
const elapsedTime = now.diff(timestampMoment, 'minutes');
|
||||
@ -31,13 +32,13 @@ export function formatTimestamp(timestamp: number): string {
|
||||
}
|
||||
}
|
||||
|
||||
export const formatDate = (unixTimestamp: number): string => {
|
||||
const date = moment(unixTimestamp, 'x').fromNow()
|
||||
export const formatDate = (unixTimestamp: number): string => {
|
||||
const date = moment(unixTimestamp, 'x').fromNow();
|
||||
|
||||
return date
|
||||
}
|
||||
return date;
|
||||
};
|
||||
|
||||
export function sortArrayByTimestampAndGroupName(array) {
|
||||
export function sortArrayByTimestampAndGroupName(array) {
|
||||
return array.sort((a, b) => {
|
||||
if (a.timestamp && b.timestamp) {
|
||||
// Both have timestamp, sort by timestamp descending
|
||||
@ -53,4 +54,4 @@ export function formatTimestamp(timestamp: number): string {
|
||||
return a.groupName.localeCompare(b.groupName);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,55 @@
|
||||
// @ts-nocheck
|
||||
const utils = {
|
||||
int32ToBytes (word) {
|
||||
var byteArray = []
|
||||
int32ToBytes(word) {
|
||||
var byteArray = [];
|
||||
for (var b = 0; b < 32; b += 8) {
|
||||
byteArray.push((word >>> (24 - b % 32)) & 0xFF)
|
||||
byteArray.push((word >>> (24 - (b % 32))) & 0xff);
|
||||
}
|
||||
return byteArray
|
||||
return byteArray;
|
||||
},
|
||||
|
||||
stringtoUTF8Array (message) {
|
||||
stringtoUTF8Array(message) {
|
||||
if (typeof message === 'string') {
|
||||
var s = unescape(encodeURIComponent(message)) // UTF-8
|
||||
message = new Uint8Array(s.length)
|
||||
var s = unescape(encodeURIComponent(message)); // UTF-8
|
||||
message = new Uint8Array(s.length);
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
message[i] = s.charCodeAt(i) & 0xff
|
||||
message[i] = s.charCodeAt(i) & 0xff;
|
||||
}
|
||||
}
|
||||
return message
|
||||
return message;
|
||||
},
|
||||
// ...buffers then buffers.foreach and append to buffer1
|
||||
appendBuffer (buffer1, buffer2) {
|
||||
buffer1 = new Uint8Array(buffer1)
|
||||
buffer2 = new Uint8Array(buffer2)
|
||||
const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)
|
||||
tmp.set(buffer1, 0)
|
||||
tmp.set(buffer2, buffer1.byteLength)
|
||||
return tmp
|
||||
appendBuffer(buffer1, buffer2) {
|
||||
buffer1 = new Uint8Array(buffer1);
|
||||
buffer2 = new Uint8Array(buffer2);
|
||||
const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
|
||||
tmp.set(buffer1, 0);
|
||||
tmp.set(buffer2, buffer1.byteLength);
|
||||
return tmp;
|
||||
},
|
||||
|
||||
int64ToBytes (int64) {
|
||||
int64ToBytes(int64) {
|
||||
// we want to represent the input as a 8-bytes array
|
||||
var byteArray = [0, 0, 0, 0, 0, 0, 0, 0]
|
||||
var byteArray = [0, 0, 0, 0, 0, 0, 0, 0];
|
||||
|
||||
for (var index = 0; index < byteArray.length; index++) {
|
||||
var byte = int64 & 0xff
|
||||
byteArray[byteArray.length - index - 1] = byte
|
||||
int64 = (int64 - byte) / 256
|
||||
var byte = int64 & 0xff;
|
||||
byteArray[byteArray.length - index - 1] = byte;
|
||||
int64 = (int64 - byte) / 256;
|
||||
}
|
||||
|
||||
return byteArray
|
||||
return byteArray;
|
||||
},
|
||||
|
||||
equal (buf1, buf2) {
|
||||
if (buf1.byteLength != buf2.byteLength) return false
|
||||
var dv1 = new Uint8Array(buf1)
|
||||
var dv2 = new Uint8Array(buf2)
|
||||
equal(buf1, buf2) {
|
||||
if (buf1.byteLength != buf2.byteLength) return false;
|
||||
var dv1 = new Uint8Array(buf1);
|
||||
var dv2 = new Uint8Array(buf2);
|
||||
for (var i = 0; i != buf1.byteLength; i++) {
|
||||
if (dv1[i] != dv2[i]) return false
|
||||
if (dv1[i] != dv2[i]) return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
export default utils
|
||||
export default utils;
|
||||
|
@ -1,21 +1,20 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import Base58 from "../deps/Base58"
|
||||
import Base58 from '../deps/Base58';
|
||||
|
||||
export const validateAddress = (address) => {
|
||||
let isAddress = false
|
||||
let isAddress = false;
|
||||
try {
|
||||
const decodePubKey = Base58.decode(address)
|
||||
const decodePubKey = Base58.decode(address);
|
||||
|
||||
if (!(decodePubKey instanceof Uint8Array && decodePubKey.length == 25)) {
|
||||
isAddress = false
|
||||
isAddress = false;
|
||||
} else {
|
||||
isAddress = true
|
||||
isAddress = true;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
return isAddress
|
||||
}
|
||||
return isAddress;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user