Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
fix(allowlist): allowlist parsing updated sdk 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers committed May 20, 2024
1 parent 7671d06 commit 2686005
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hypercerts-org/sdk",
"version": "1.5.0",
"version": "1.5.1",
"description": "SDK for hypercerts protocol",
"repository": "git@github.com:hypercerts-org/hypercerts.git",
"author": "Hypercerts team",
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class HypercertsStorage implements HypercertStorageInterface {
logger.debug("Storing allowlist: ", "storage", [data]);

const tree = parseAllowListEntriesToMerkleTree(allowList);
if (!tree) {
throw new MalformedDataError(`Invalid allowList.`, { errors: { tree: "Parsing to tree returned undefined" } });
}

logger.debug("Allowlist tree: ", "storage", [tree]);

Expand Down
5 changes: 4 additions & 1 deletion sdk/src/utils/allowlist.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { getFromIPFS } from "./fetchers";
import { logger } from "./logger";
import { AllowlistEntry } from "src/types";
import { AllowlistEntry, MalformedDataError } from "src/types";

const parseAllowListEntriesToMerkleTree = (allowList: AllowlistEntry[]) => {
if (!allowList || allowList.length == 0) {
throw new MalformedDataError(`Invalid allowList.`, { errors: { allowlist: "Length is 0" } });
}
const tuples = allowList.map((p) => [p.address, p.units.toString()]);
const tree = StandardMerkleTree.of(tuples, ["address", "uint256"]);

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const validateAllowlist = (data: AllowlistEntry[], units: bigint): ValidationRes
errors["units"] = "Total units in allowlist must be greater than 0";
}

const filteredAddresses = data.filter((entry) => !isAddress(entry.address.toLowerCase()));
const filteredAddresses = data.filter((entry) => !isAddress(entry.address, { strict: false }));
if (filteredAddresses.length > 0) {
errors["address"] = filteredAddresses.map((entry) => entry.address);
}
Expand Down

0 comments on commit 2686005

Please sign in to comment.