implement cryptography for FileTransfer
This commit is contained in:
@@ -2,14 +2,28 @@
|
||||
|
||||
import ConnectionModel from "./connectionModel";
|
||||
import StorageModel from "./storageModel";
|
||||
import { generateRandomToken } from "../Utility/utility";
|
||||
|
||||
export default class FileTransferModel {
|
||||
storageModel: StorageModel;
|
||||
connectionModel: ConnectionModel;
|
||||
storageModel: StorageModel;
|
||||
connectionModel: ConnectionModel;
|
||||
|
||||
// init
|
||||
constructor(storageModel: StorageModel, connectionModel: ConnectionModel) {
|
||||
this.storageModel = storageModel;
|
||||
this.connectionModel = connectionModel;
|
||||
}
|
||||
}
|
||||
// methods
|
||||
generateTransferData = (): TransferData => {
|
||||
return {
|
||||
channel: generateRandomToken(2),
|
||||
key: generateRandomToken(3),
|
||||
};
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(storageModel: StorageModel, connectionModel: ConnectionModel) {
|
||||
this.storageModel = storageModel;
|
||||
this.connectionModel = connectionModel;
|
||||
}
|
||||
}
|
||||
|
||||
export interface TransferData {
|
||||
channel: string;
|
||||
key: string;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ export interface Stringifiable {
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
// crypto
|
||||
export function generateRandomToken(length: number): string {
|
||||
const array = new Uint8Array(length);
|
||||
crypto.getRandomValues(array);
|
||||
return array.join("");
|
||||
}
|
||||
|
||||
// date
|
||||
export function createTimestamp(): string {
|
||||
return new Date().toISOString();
|
||||
|
||||
@@ -31,6 +31,8 @@ const chatListModel = new ChatListModel(
|
||||
);
|
||||
const fileTransferModel = new FileTransferModel(storageModel, connectionModel);
|
||||
|
||||
console.log(fileTransferModel.generateTransferData());
|
||||
|
||||
// upgrade
|
||||
new v1Upgrader(settingsModel, connectionModel, chatListModel);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user