-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
390 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ dist-ssr | |
*.sln | ||
*.sw? | ||
.vercel | ||
whitelist-addresses.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { hash } from "starknet"; | ||
import * as fs from "fs/promises"; | ||
import * as path from "path"; | ||
|
||
function generateHash(address: string): string { | ||
// Convert address to decimal if it's in hex format | ||
const addressBN = BigInt(address); | ||
return hash.computeHashOnElements([addressBN.toString()]).toString(); | ||
} | ||
|
||
async function readAddresses(): Promise<string[]> { | ||
const addressFile = path.join(process.cwd(), "script/whitelist-addresses.txt"); | ||
const content = await fs.readFile(addressFile, "utf8"); | ||
|
||
return content | ||
.split("\n") | ||
.map(line => line.trim()) | ||
.filter(line => line && !line.startsWith("#")); // Remove empty lines and comments | ||
} | ||
|
||
async function main() { | ||
const walletAddresses = await readAddresses(); | ||
|
||
if (walletAddresses.length === 0) { | ||
console.log("Please add wallet addresses to script/whitelist-addresses.txt"); | ||
console.log("Each address should be on a new line"); | ||
console.log("Lines starting with # are treated as comments"); | ||
return; | ||
} | ||
|
||
const hashes = walletAddresses.map((address) => ({ | ||
address, | ||
hash: generateHash(address), | ||
})); | ||
|
||
// Create the whitelist file content | ||
const whitelistContent = `// This file is auto-generated by generateWhitelistHashes.ts | ||
// DO NOT EDIT DIRECTLY | ||
export const whitelistedHashes: string[] = [ | ||
${hashes.map((item) => ` "${item.hash}", // ${item.address}`).join("\n")} | ||
]; | ||
`; | ||
|
||
// Save to utils directory | ||
const outputFile = path.join(process.cwd(), "src/utils/whitelist.generated.ts"); | ||
await fs.writeFile(outputFile, whitelistContent, "utf8"); | ||
|
||
// Print summary | ||
console.log("Generated hashes for", hashes.length, "addresses"); | ||
if (hashes.length > 0) { | ||
console.log("\nSample output:"); | ||
console.log("Address:", hashes[0].address); | ||
console.log("Hash:", hashes[0].hash); | ||
} | ||
console.log("\nWhitelist saved to:", outputFile); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AccountInterface } from "starknet"; | ||
import { hash } from "starknet"; | ||
import { whitelistedHashes } from "./whitelist.generated"; | ||
|
||
export function isInWhiteList(account: AccountInterface | undefined): boolean { | ||
if (!account) { | ||
return false; | ||
} | ||
// Convert address to checksum format and hash it | ||
const addressHash = hash.computeHashOnElements([account.address]); | ||
// Check if the hash exists in the whitelist | ||
return whitelistedHashes.includes(addressHash.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This file is auto-generated by generateWhitelistHashes.ts | ||
// DO NOT EDIT DIRECTLY | ||
|
||
export const whitelistedHashes: string[] = [ | ||
"0x2917789a9bdf8816372c5563cc384c57f18283c45ed4839cfa7e65832d705a7", // 0x061aaefa3a5025ff8350642b71328a2eb0c9cdddc6f9aed360ebd39dba481eec | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.