Skip to content

Commit

Permalink
chore: polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
eigmax committed Jul 13, 2023
1 parent 4b19637 commit c789c5e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions core/lib/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const createBlakeHash = require("blake-hash");
const { Buffer } = require("buffer");
import { Aes256gcm } from "./aes_gcm";
import { Note } from "./note";
import { __DEFAULT_ALIAS__ } from "./utils";
import { __DEFAULT_ALIAS__, getAddressPrefix } from "./utils";
const consola = require("consola");

type UnpackFunc = (babyJub: any) => [any, any];
Expand All @@ -15,10 +15,11 @@ interface Address {
unpack: UnpackFunc;
}
export class EigenAddress implements Address {
protocol: string = "eig:";
protocol: string;
pubKey: string;
constructor(pubKey: string) {
this.pubKey = pubKey;
this.protocol = getAddressPrefix();
}
unpack: UnpackFunc = (babyJub: any) => {
let pubKey = this.pubKey;
Expand Down Expand Up @@ -59,7 +60,7 @@ export class SigningKey implements IKey {
}
let pubKey = eddsa.prv2pub(rawpvk);
let pPubKey = eddsa.babyJub.packPoint(pubKey);
let hexPubKey = "eig:" + Buffer.from(pPubKey).toString("hex");
let hexPubKey = getAddressPrefix() + Buffer.from(pPubKey).toString("hex");
this.prvKey = rawpvk;
this.pubKey = new EigenAddress(hexPubKey);
return this;
Expand Down
7 changes: 6 additions & 1 deletion core/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,9 @@ const normalizeAlias = (alias: string) => {
return /^[A-Za-z][A-Za-z0-9_.]{2,32}$/.test(alias)
}

export { hasValue, requireEnvVariables, prepareJson, pathJoin, __DEFAULT_ALIAS__, SESSION_DURATION, normalizeAlias, ETH };
const getAddressPrefix = () => {
let prefix = process.env.ADDRESS_PREFIX || "eig";
return `${prefix}:`;
}

export { hasValue, requireEnvVariables, prepareJson, pathJoin, __DEFAULT_ALIAS__, SESSION_DURATION, normalizeAlias, ETH, getAddressPrefix };
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eigen-secret/core",
"version": "1.1.12",
"version": "1.1.13",
"description": "> TODO: description",
"author": "Eigen Labs",
"homepage": "https://github.com/0xEigenLabs/eigen-secret#readme",
Expand Down
1 change: 1 addition & 0 deletions server/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
NODE_ENV="development"
PRIVATE_KEY=""
DUNE_API_KEY=
ADDRESS_PREFIX=
2 changes: 1 addition & 1 deletion test/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Test Account Compressor", function() {
let prvKey = ethers.utils.randomBytes(31);
let pubKey = eddsa.prv2pub(prvKey);
let pPubKey = eddsa.babyJub.packPoint(pubKey);
let hexPubKey = "eig:" + Buffer.from(pPubKey).toString("hex");
let hexPubKey = utils.getAddressPrefix() + Buffer.from(pPubKey).toString("hex");

let pubKey2 = eddsa.babyJub.unpackPoint(pPubKey);
expect(Buffer.from(pubKey[0]).toString("hex")).to.eq(
Expand Down

0 comments on commit c789c5e

Please sign in to comment.