diff --git a/core/lib/account.ts b/core/lib/account.ts index 0cd3bd9f..966233a8 100644 --- a/core/lib/account.ts +++ b/core/lib/account.ts @@ -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]; @@ -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; @@ -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; diff --git a/core/lib/utils.ts b/core/lib/utils.ts index 5ffcfd01..8b46a076 100644 --- a/core/lib/utils.ts +++ b/core/lib/utils.ts @@ -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 }; diff --git a/core/package.json b/core/package.json index e93fe3b7..627373ae 100644 --- a/core/package.json +++ b/core/package.json @@ -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", diff --git a/server/.env.sample b/server/.env.sample index 3019030f..e8a37f1c 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -2,3 +2,4 @@ NODE_ENV="development" PRIVATE_KEY="" DUNE_API_KEY= +ADDRESS_PREFIX= diff --git a/test/account.test.ts b/test/account.test.ts index 7e9be05d..aa05e051 100644 --- a/test/account.test.ts +++ b/test/account.test.ts @@ -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(