Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Remove ethers in logger #366

Merged
merged 2 commits into from
Feb 19, 2024
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
20 changes: 17 additions & 3 deletions packages/logger/src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { version } from '@lit-protocol/constants';
import { hashMessage } from 'ethers/lib/utils';
import { encode } from 'punycode';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, I think we can remove punycode from the project

import { toString as uint8arrayToString } from 'uint8arrays';

export enum LogLevel {
Expand Down Expand Up @@ -329,7 +327,7 @@ export class Logger {
}

private _checkHash(log: Log): boolean {
const digest = hashMessage(log.message);
const digest = this.hashCode(log.message);
const hash = digest.toString();
let item = this._logHashes.get(hash);
if (item) {
Expand All @@ -350,6 +348,22 @@ export class Logger {
//log.id && this._addToLocalStorage(log);
}

/**
simple non secure 32 bit hashing function.

*/
hashCode(str: string, seed: number = 0) {
var hash = 0;
var i, chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}

private _addToLocalStorage(log: Log) {
if (globalThis.localStorage) {
let bucket: { [index: string]: string[] } | string | null =
Expand Down
Loading