Skip to content

Commit 096a79f

Browse files
encrpyted rooms work
1 parent 3c3b18e commit 096a79f

29 files changed

+408
-245
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"date-fns": "^2.30.0",
7373
"discreetly-interfaces": "^0.1.42",
7474
"dompurify": "^3.0.5",
75-
"idc-nullifier": "^0.0.6",
75+
"idc-nullifier": "^0.0.8",
7676
"libsodium-wrappers": "^0.7.11",
7777
"marked": "^7.0.5",
7878
"minidenticons": "^4.2.0",
@@ -86,4 +86,4 @@
8686
"wagmi": "^1.4.3",
8787
"zuauth": "^0.3.0"
8888
}
89-
}
89+
}

src/lib/components/Gateways/EthereumGroup.svelte

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
loadingRooms = true;
6464
getEthAddressRoomNames($selectedServer, address)
6565
.then((groupNames) => {
66-
console.log(groupNames);
6766
loadingRooms = false;
6867
groups = groupNames;
6968
})
@@ -84,8 +83,7 @@
8483
<h3 class="h4 mb-2"><span class="text-success-500">Step 1:</span> Connect your wallet</h3>
8584
<button
8685
bind:this={btnEl}
87-
class="btn variant-outline-tertiary">Connect</button
88-
>
86+
class="btn variant-outline-tertiary">Connect</button>
8987
</div>
9088
{#if isConnected}
9189
<div>
@@ -106,8 +104,7 @@
106104
<button
107105
on:click={proveOwnership}
108106
id="btn"
109-
class="btn variant-outline-success">Sign</button
110-
>
107+
class="btn variant-outline-success">Sign</button>
111108
</div>
112109
{:else if loadingRooms}
113110
<p>Loading rooms...</p>

src/lib/components/Gateways/InviteCode.svelte

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
})
2222
.catch((err) => {
23-
console.log(err);
23+
console.warn(err);
2424
alertQueue.enqueue(`Unexpected error: ${err.message}`, 'error');
2525
})
2626
.finally(() => {
@@ -90,26 +90,23 @@
9090
{#if !hideInput}
9191
<label
9292
class="label"
93-
for="inviteCode"
94-
>
93+
for="inviteCode">
9594
<span class="h5">Enter Invite Code:</span>
9695
<input
9796
class="input"
9897
type="text"
9998
placeholder="Invite Code"
10099
id="inviteCode"
101100
bind:value={code}
102-
on:keydown={(event) => inviteCodeKeyPress(event)}
103-
/>
101+
on:keydown={(event) => inviteCodeKeyPress(event)} />
104102
</label>
105103
{/if}
106104
{#if !loading}
107105
<button
108106
class="btn variant-ghost-success mt-3"
109107
type="button"
110108
disabled={!code}
111-
on:click={() => addCode(code)}>{buttonText}</button
112-
>
109+
on:click={() => addCode(code)}>{buttonText}</button>
113110
{:else}
114111
<div class="text-primary">Going Anon, please wait...</div>
115112
<Loading />
@@ -120,8 +117,7 @@
120117
<div>
121118
If you are having trouble and would like help, please message us on <a
122119
href="https://discord.gg/brJQ36KVxk"
123-
class="underline link">Discord</a
124-
>
120+
class="underline link">Discord</a>
125121
</div>
126122
</aside>
127123
{/if}

src/lib/components/Gateways/TheWord.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
})
1818
.catch((err) => {
19-
console.log(err);
19+
console.warn(err);
2020
alertQueue.enqueue(`Unexpected error: ${err.message}`, 'error');
2121
})
2222
.finally(() => {
@@ -55,9 +55,7 @@
5555
class="px-2"
5656
name="the-word-proof.json"
5757
bind:files
58-
on:change={onChangeHandler}
59-
/></label
60-
>
58+
on:change={onChangeHandler} /></label>
6159
</section>
6260
{#if loading}
6361
<Loading />

src/lib/crypto/rlnProver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async function genProof(
132132
);
133133

134134
const proof = prover.generateProof(proofInputs).then((proof: RLNFullProof) => {
135-
console.log('Proof generated!');
135+
console.info('Proof generated!');
136136
const msg: MessageI = {
137137
messageId: proof.snarkProof.publicSignals.nullifier.toString(),
138138
message: message,

src/lib/services/api.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,23 @@ export async function getAuth(
128128
throw new Error(`Failed to post to ${url}`);
129129
}
130130
}
131+
132+
/**
133+
* @description - makes a get request to the api
134+
* @param {string[] | string} urlParts - the url parts to be joined to form the url
135+
* @param {object} data - the data to be sent to the api
136+
* @returns {object} - the response from the api
137+
* @throws {Error} - if the request fails
138+
*/
139+
export async function postRaw(urlParts: string[] | string, data: object): Promise<Response> {
140+
const url = cleanURL(urlParts);
141+
const res = await fetch(url, {
142+
method: 'POST',
143+
headers: {
144+
'Access-Control-Allow-Origin': '*',
145+
'Content-Type': 'application/json'
146+
},
147+
body: JSON.stringify(data)
148+
});
149+
return res;
150+
}

src/lib/services/server.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { MessageI, ServerI } from 'discreetly-interfaces';
22
import type { IdentityStoreI, Invites, JoinResponseI, JubmojiProofI, RoomI } from '$lib/types';
33
import { Prover } from 'idc-nullifier';
44
import type { Identity } from '@semaphore-protocol/identity';
5-
import { get, getAuth, post, postAuth } from './api';
5+
import { get, getAuth, post, postAuth, postRaw } from './api';
66
import { getIdentity } from '$lib/utils';
77
import { alertQueue } from '$lib/stores';
88

@@ -193,6 +193,22 @@ export async function postCheckRoomPassword(
193193
return Boolean(response.success);
194194
}
195195

196+
export async function postDoesRoomPasswordExist(
197+
serverUrl: string,
198+
roomId: string
199+
): Promise<boolean> {
200+
const response = await postRaw([serverUrl, `room/checkpasswordhash/${roomId}`], {
201+
passwordHash: 'passwordHash'
202+
});
203+
if (response.status == 200 && (response.json() as unknown as CheckResponse).success == false) {
204+
return false;
205+
} else if (response.status == 400) {
206+
return true;
207+
} else {
208+
return false;
209+
}
210+
}
211+
196212
export async function postSetRoomPassword(
197213
serverUrl: string,
198214
roomId: string,
@@ -207,7 +223,6 @@ export async function postSetRoomPassword(
207223
idForProof.nullifier = id._nullifier;
208224
idForProof.secret = id._secret;
209225
idForProof.commitment = id._commitment;
210-
211226
// Proves you know the identity secret with a timestamp so this proof can't be replayed
212227
prover
213228
.generateProof({

src/lib/stores/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const pixelStore = sessionable({} as pixelStoreI, 'pixelmaps');
6565
/**
6666
* @description Stores the encrypted key for each room keyed by the roomId
6767
*/
68-
export const roomPassStore = encryptable({} as roomPassStoreI, 'roomKey');
68+
export const roomPassStore = encryptable({} as roomPassStoreI, 'roomPasses');
6969

7070
/**
7171
* @description Derived Store: The messages of the currently selected room

src/lib/utils/identity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function createIdentity(
3232
alertQueue.enqueue('Identity Created! Congrats on your new journey', 'success');
3333
return 'created';
3434
} else {
35-
console.log(get(identityExists));
35+
console.warn(get(identityExists));
3636
alertQueue.enqueue('Error creating identity!!!', 'error');
3737
return 'error';
3838
}

src/lib/utils/password.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
identityExists,
99
alertQueue,
1010
roomPassStore,
11-
selectedServer
11+
selectedServer,
12+
roomKeyStore
1213
} from '$lib/stores';
1314
import { encryptIdentity } from './identity';
1415
import type { IdentityStoreI } from '$lib/types';
@@ -75,6 +76,17 @@ export async function unlockPadlock(password: string) {
7576
identityKeyStore.read();
7677
roomPassStore.read();
7778
updateRooms();
79+
console.debug('Unlocking rooms');
80+
setTimeout(() => {
81+
const roomPasses = get(roomPassStore);
82+
Object.keys(roomPasses).forEach(async (roomId) => {
83+
const roomKey = await deriveKey(roomPasses[roomId].password);
84+
roomKeyStore.update((roomKeys) => {
85+
roomKeys[roomId] = roomKey;
86+
return roomKeys;
87+
});
88+
});
89+
}, 50);
7890
});
7991
} else {
8092
alertQueue.enqueue('Incorrect Password', 'warning');
@@ -85,12 +97,17 @@ export async function unlockPadlock(password: string) {
8597
export async function enterRoomPassword(password: string, roomId: string): Promise<boolean> {
8698
const hashedSaltedPassword = await hashPassword(password + roomId);
8799
if (hashedSaltedPassword) {
88-
postCheckRoomPassword(get(selectedServer), roomId, hashedSaltedPassword).then((res) => {
100+
postCheckRoomPassword(get(selectedServer), roomId, hashedSaltedPassword).then(async (res) => {
89101
if (res) {
90102
roomPassStore.update((roomPass) => {
91103
roomPass[roomId] = { password, hashedSaltedPassword };
92104
return roomPass;
93105
});
106+
const key = await deriveKey(password);
107+
roomKeyStore.update((roomKeys) => {
108+
roomKeys[roomId] = key;
109+
return roomKeys;
110+
});
94111
return true;
95112
} else {
96113
return false;
@@ -103,12 +120,17 @@ export async function enterRoomPassword(password: string, roomId: string): Promi
103120
export async function setRoomPassword(password: string, roomId: string): Promise<boolean> {
104121
const hashedSaltedPassword = await hashPassword(password + roomId);
105122
if (hashedSaltedPassword) {
106-
postSetRoomPassword(get(selectedServer), roomId, hashedSaltedPassword).then((res) => {
123+
postSetRoomPassword(get(selectedServer), roomId, hashedSaltedPassword).then(async (res) => {
107124
if (res) {
108125
roomPassStore.update((roomPass) => {
109126
roomPass[roomId] = { password, hashedSaltedPassword };
110127
return roomPass;
111128
});
129+
const key = await deriveKey(password);
130+
roomKeyStore.update((roomKeys) => {
131+
roomKeys[roomId] = key;
132+
return roomKeys;
133+
});
112134
return true;
113135
} else {
114136
return false;

src/routes/+layout.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
3131
3232
onMount(async () => {
33-
console.log('Starting Up Application');
33+
console.info('Starting Up Application');
3434
if (getServerList().length === 0) {
3535
setDefaultServers();
3636
}
@@ -45,7 +45,7 @@
4545
drawerStore.close();
4646
}
4747
} else {
48-
console.log('Input field focused, not opening console');
48+
console.debug('Input field focused, not opening console');
4949
}
5050
}
5151
});

src/routes/admin/+page.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<a
3535
class="btn variant-filled-primary"
3636
href="/admin/addAdmin">Add Room Admin</a>
37+
<a
38+
class="btn variant-filled-warning"
39+
href="/settings/debug">Debug</a>
3740
</div>
3841

3942
<style>

0 commit comments

Comments
 (0)