Skip to content

Commit a1e7abf

Browse files
authored
fix: check auditor public key (#10)
* feat: implements auditor public key check for encrypted operations * delete publish script
1 parent 17ec46c commit a1e7abf

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@avalabs/eerc-sdk",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",
@@ -39,8 +39,7 @@
3939
"lint": "biome check .",
4040
"format": "biome format --write .",
4141
"test": "jest",
42-
"test:watch": "jest --watch",
43-
"publish": "npm run build && npm publish"
42+
"test:watch": "jest --watch"
4443
},
4544
"dependencies": {
4645
"blake-hash": "^2.0.0",

src/EERC.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ export class EERC {
812812

813813
let totalBalance = 0n;
814814

815-
if (balancePCT.some((e) => e !== 0n)) {
815+
if (balancePCT?.some((e) => e !== 0n)) {
816816
const decryptedBalancePCT = this.decryptPCT(balancePCT);
817817
totalBalance += decryptedBalancePCT;
818818
}

src/hooks/useEncryptedBalance.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ export function useEncryptedBalance(
136136
const privateMint = useCallback(
137137
(recipient: `0x${string}`, amount: bigint) => {
138138
if (!eerc || !auditorPublicKey) throw new Error("EERC not initialized");
139+
if (
140+
!auditorPublicKey.length ||
141+
auditorPublicKey.some((key) => key === 0n)
142+
)
143+
throw new Error("Auditor public key is not set");
144+
139145
return eerc.privateMint(recipient, amount, auditorPublicKey as Point);
140146
},
141147
[eerc, auditorPublicKey],
@@ -149,8 +155,13 @@ export function useEncryptedBalance(
149155
const privateBurn = useCallback(
150156
(amount: bigint) => {
151157
try {
152-
if (!eerc || !auditorPublicKey || !balanceState.encrypted.length)
158+
if (!eerc || !balanceState.encrypted.length)
153159
throw new Error("EERC not initialized");
160+
if (
161+
!auditorPublicKey.length ||
162+
auditorPublicKey.some((key) => key === 0n)
163+
)
164+
throw new Error("Auditor public key is not set");
154165
if (balanceState.decrypted < amount || amount <= 0n)
155166
throw new Error("Invalid amount");
156167

@@ -177,8 +188,13 @@ export function useEncryptedBalance(
177188
const privateTransfer = useCallback(
178189
(to: string, amount: bigint) => {
179190
try {
180-
if (!eerc || !auditorPublicKey || !balanceState.encrypted.length)
191+
if (!eerc || !balanceState.encrypted.length)
181192
throw new Error("EERC not initialized");
193+
if (
194+
!auditorPublicKey.length ||
195+
auditorPublicKey.some((key) => key === 0n)
196+
)
197+
throw new Error("Auditor public key is not set");
182198
if (balanceState.decrypted < amount || amount <= 0n)
183199
throw new Error("Invalid amount");
184200

@@ -209,14 +225,19 @@ export function useEncryptedBalance(
209225
if (!eerc) throw new Error("EERC not initialized");
210226
if (!tokenAddress) throw new Error("Token address is not set");
211227
if (!decimals) throw new Error("Decimals not set");
228+
if (
229+
!auditorPublicKey.length ||
230+
auditorPublicKey.some((key) => key === 0n)
231+
)
232+
throw new Error("Auditor public key is not set");
212233

213234
return eerc.deposit(amount, tokenAddress, decimals);
214235
} catch (error) {
215236
console.error("Deposit failed", error);
216237
throw error;
217238
}
218239
},
219-
[eerc, tokenAddress, decimals],
240+
[eerc, tokenAddress, decimals, auditorPublicKey],
220241
);
221242

222243
/**
@@ -229,6 +250,11 @@ export function useEncryptedBalance(
229250
try {
230251
if (!eerc) throw new Error("EERC not initialized");
231252
if (!tokenAddress) throw new Error("Token address is not set");
253+
if (
254+
!auditorPublicKey.length ||
255+
auditorPublicKey.some((key) => key === 0n)
256+
)
257+
throw new Error("Auditor public key is not set");
232258

233259
return eerc.withdraw(
234260
amount,

0 commit comments

Comments
 (0)