-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
51 lines (45 loc) · 1.48 KB
/
Copy pathutils.ts
File metadata and controls
51 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { Wallet } from './src/models/models';
import { appendFile } from "node:fs/promises";
export const wrapCall = <Args extends Array<unknown>>(f: (...args: Args) => Promise<void>): (...args: Args) => Promise<void> => {
return async (...args) => {
try {
await f(...args);
} catch (err) {
console.error(err);
}
};
};
export function seedToIdentity(seed: string): Wallet {
const seedBuf = new Uint8Array(new ArrayBuffer(32));
if (seed.length && seed.length > 0 && seed.length <= 32) {
seedBuf.set(new TextEncoder().encode(seed));
return Ed25519KeyIdentity.generate(seedBuf);
}
return null;
};
// Append request's logs to the log's file
export function log(requestLog: any[]) {
const LOG_PATH = `logs/${getDate()}.log`;
try {
// Write (file's content + request's log)
appendFile(LOG_PATH, `\n ${(new Date()).toISOString() +" "+ requestLog.join(' ')}`);
} catch (e) {
// If log's file doesn't exist, write new content
console.log("Log file doesn't exist",e);
}
}
function getDate(){
let objectDate = new Date();
let day = objectDate.getDate();
let month = objectDate.getMonth();
let year = objectDate.getFullYear();
let format1 = month + "-" + day + "-" + year;
return format1;
}
export function randomId(length = 6) {
return Math.random().toString(36).substring(2, length+2);
};
export function randomNumber() {
return Math.random();
};