Skip to content

Commit 54a68fd

Browse files
committed
[FEAT] creation de la route pour retourner le registry
1 parent 1e376ad commit 54a68fd

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/crypto.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export async function createRandomSymmetricKey(): Promise<webcrypto.CryptoKey> {
132132
// keys are extractable.
133133
const key = await crypto.subtle.generateKey(
134134
{
135-
name: "AES-GCM",
135+
name: "AES-CBC",
136136
length: 256
137137
},
138138
true,
@@ -158,7 +158,7 @@ export async function importSymKey(
158158
// TODO implement this function to go back from the result of the exportSymKey function to it's native crypto key object
159159
const jwkString = Buffer.from(strKey, "base64").toString("utf-8");
160160
const jwk = JSON.parse(jwkString);
161-
const key = await crypto.subtle.importKey("jwk", jwk, { name: "AES-GCM" }, true, ["encrypt", "decrypt"]);
161+
const key = await crypto.subtle.importKey("jwk", jwk, { name: "AES-CBC" }, true, ["encrypt", "decrypt"]);
162162
return key;
163163
}
164164

@@ -167,7 +167,7 @@ export async function symEncrypt(key: webcrypto.CryptoKey,data: string): Promise
167167
// TODO implement this function to encrypt a base64 encoded message with a public key
168168
// tip: encode the data to a uin8array with TextEncoder
169169
const dataArray = new TextEncoder().encode(data);
170-
const encryptedData = await crypto.subtle.encrypt({ name: "AES-GCM" }, key, dataArray);
170+
const encryptedData = await crypto.subtle.encrypt({ name: "AES-CBC" }, key, dataArray);
171171
const encryptedBase64 = Buffer.from(encryptedData).toString("base64");
172172
return encryptedBase64;
173173
}
@@ -178,7 +178,7 @@ export async function symDecrypt(strKey: string,encryptedData: string): Promise<
178178
// tip: use the provided base64ToArrayBuffer function and use TextDecode to go back to a string format
179179
const key = await importSymKey(strKey);
180180
const encryptedArray = base64ToArrayBuffer(encryptedData);
181-
const decryptedData = await crypto.subtle.decrypt({ name: "AES-GCM" }, key, encryptedArray);
181+
const decryptedData = await crypto.subtle.decrypt({ name: "AES-CBC" }, key, encryptedArray);
182182
const decryptedString = new TextDecoder().decode(decryptedData);
183183
return decryptedString;
184184
}

src/registry/registry.ts

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ export async function launchRegistry() {
1313
_registry.use(express.json());
1414

1515
let registeredNodes: Node[] = [];
16+
17+
function getNodeRegistry(req: Request, res: Response<GetNodeRegistryBody>) {
18+
return res.json({
19+
nodes: Array.from(registeredNodes),
20+
});
21+
}
1622

1723
_registry.post("/registerNode", (req: Request<any, any, Node>, res: Response) => {
1824
const { nodeId, pubKey } = req.body;
@@ -33,9 +39,12 @@ export async function launchRegistry() {
3339
res.send("live");
3440
});
3541

42+
_registry.get("/getNodeRegistry", getNodeRegistry);
43+
3644
const server = _registry.listen(REGISTRY_PORT, () => {
3745
console.log(`registry is listening on port ${REGISTRY_PORT}`);
3846
});
3947

4048
return server;
4149
}
50+

0 commit comments

Comments
 (0)