Skip to content
Merged
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
18 changes: 0 additions & 18 deletions src/crypto_utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import forge from 'node-forge'
import {BaseWallet, ethers, getBytes, SigningKey, solidityPackedKeccak256} from "ethers"
import * as fs from "node:fs";

const BLOCK_SIZE = 16 // AES block size in bytes
const HEX_BASE = 16
Expand Down Expand Up @@ -204,23 +203,6 @@ export function generateAesKey(): string {
return forge.random.getBytesSync(BLOCK_SIZE)
}

export function loadAesKey(filePath: string): Buffer {
const hexKey = fs.readFileSync(filePath, 'utf8').trim();
const key = Buffer.from(hexKey, 'hex');
if (key.length !== BLOCK_SIZE) {
throw new Error(`Invalid key length: ${key.length} bytes, must be ${BLOCK_SIZE} bytes`);
}
return key;
}

export function writeAesKey(filePath: string, key: Buffer): void {
if (key.length !== BLOCK_SIZE) {
throw new Error(`Invalid key length: ${key.length} bytes, must be ${BLOCK_SIZE} bytes`);
}
const hexKey = key.toString('hex');
fs.writeFileSync(filePath, hexKey);
}

export function encodeString(str: string): Uint8Array {
return new Uint8Array([...str.split('').map((char) => parseInt(char.codePointAt(0)?.toString(HEX_BASE)!, HEX_BASE))])
}
Expand Down