Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@eslint/compat": "^1.2.9",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.26.0",
"@types/crypto-js": "^4.2.2",
"@types/jest": "^29.5.14",
"@types/latlon-geohash": "^2.0.4",
"@types/leaflet": "^1.9.17",
Expand Down Expand Up @@ -71,6 +72,7 @@
"@nivo/line": "^0.96.0",
"base-ex": "^0.8.1",
"country-flag-icons": "^1.5.19",
"crypto-js": "^4.2.0",
"date-fns": "^4.1.0",
"file-replace-loader": "^1.4.2",
"i18next": "^25.1.2",
Expand Down
96 changes: 96 additions & 0 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,97 @@
import * as CryptoJS from 'crypto-js';
import App from './App';

// Create a polyfill for the WebCrypto API
const getWebCrypto = () => {
return {
subtle: {
digest: (algorithm, data) => {
return new Promise((resolve, reject) => {
if (algorithm === 'SHA-256') {
let message;

if (data instanceof Uint8Array) {
message = new TextDecoder().decode(data);
} else if (data instanceof ArrayBuffer) {
message = new TextDecoder().decode(new Uint8Array(data));
} else {
message = data; // Assume it's a string
}

const hash = CryptoJS.SHA256(message).toString();
const match = hash.match(/.{1,2}/g);
if (!match) {
return reject(new Error('Hash computation failed'));
}

const hashArray = new Uint8Array(match.map((byte) => parseInt(byte, 16)));
resolve(hashArray);
} else {
reject(new Error('Algorithm not supported'));
}
});
},

encrypt: (algorithm, key, data) => {
return new Promise((resolve, reject) => {
if (algorithm === 'AES-CBC') {
const iv = CryptoJS.lib.WordArray.random(128 / 8); // Generate a random IV
const encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(data), key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});

resolve({
ciphertext: encrypted.toString(),
iv: iv.toString(),
});
} else {
reject(new Error('Algorithm not supported'));
}
});
},

decrypt: (algorithm, key, data) => {
return new Promise((resolve, reject) => {
if (algorithm === 'AES-CBC') {
const { ciphertext, iv } = data;
const decrypted = CryptoJS.AES.decrypt(ciphertext, key, {
iv: CryptoJS.enc.Hex.parse(iv),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});

resolve(decrypted.toString(CryptoJS.enc.Utf8));
} else {
reject(new Error('Algorithm not supported'));
}
});
},

generateKey: (algorithm, extractable, keyUsages) => {
return new Promise((resolve, reject) => {
if (algorithm.name === 'AES-CBC') {
const key = CryptoJS.lib.WordArray.random(256 / 8); // Generate a random AES key
resolve(key);
} else {
reject(new Error('Algorithm not supported'));
}
});
},
},
};
};

// Override the global crypto object
if (typeof window !== 'undefined' && !window.crypto.subtle) {
window.crypto = {
getRandomValues: (arr) => {
for (let i = 0; i < arr.length; i++) {
arr[i] = Math.floor(Math.random() * 256);
}
return arr;
},
subtle: getWebCrypto().subtle,
};
}
4 changes: 2 additions & 2 deletions frontend/src/models/Coordinator.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ export class Coordinator {
getRelayUrl = (network: 'mainnet' | 'testnet', hostUrl: string, selfHosted: boolean): string => {
const protocol = hostUrl.includes('https') ? 'wss' : 'ws';
if (selfHosted && this.shortAlias !== 'local') {
return `${protocol}://${hostUrl.replace(/^https?:\/\//, '')}/${network}/${this.shortAlias}/relay/`;
return `${protocol}://${hostUrl.replace(/^https?:\/\//, '')}/${network}/${this.shortAlias}/nostr/`;
} else {
return `${protocol}://${this.url.replace(/^https?:\/\//, '')}/relay/`;
return `${protocol}://${this.url.replace(/^https?:\/\//, '')}/nostr/`;
}
};
}
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/pgp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ export interface generatedKeyPair {
}

export async function genKey(highEntropyToken: string): Promise<generatedKeyPair> {
const d = new Date();
const date = new Date();
date.setDate(date.getDate() - 1); // One day of offset. Helps reducing errors due to client's system time being in the future.

const keyPair = await generateKey({
type: 'ecc', // Type of the key, defaults to ECC
curve: 'curve25519', // ECC curve name, defaults to curve25519
curve: 'curve25519Legacy', // ECC curve name, defaults to curve25519
userIDs: [{ name: 'RoboSats ID ' + sha256(sha256(highEntropyToken)) }], // Ideally it would be the avatar nickname, but the nickname is generated only after submission. The second SHA256 can be converted into the Nickname using nick_generator package.
passphrase: highEntropyToken,
format: 'armored',
date: d.setDate(d.getDate() - 1), // One day of offset. Helps reducing errors due to client's system time being in the future.
date,
});

return {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/RoboPool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RoboPool {

if (settings.host) {
const protocol = hostUrl.includes('https') ? 'wss' : 'ws';
const hostNostr = `${protocol}://${settings.host.replace(/^https?:\/\//, '')}/relay/`;
const hostNostr = `${protocol}://${settings.host.replace(/^https?:\/\//, '')}/nostr/`;
if (federationRelays.includes(hostNostr)) {
this.relays.push(hostNostr);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/System/SystemWebClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SystemWebClient implements SystemClient {
};

public setCookie: (key: string, value: string) => void = (key, value) => {
document.cookie = `${key}=${value};path=/;SameSite=None;Secure`;
document.cookie = `${key}=${value};path=/;SameSite=None;`;
};

public deleteCookie: (key: string) => void = (key) => {
Expand Down