-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHARD-1166: Archiver whitelisting (#123)
* Added allowed archiver signed list and endpoint to fetch it * Move the allowed archiver list verification to archiver * Add script to sign the archiver config file * Add allowed-archivers endpoint unit test * Add more unit tests * Moved the verification and config loading to AllowedArchiversManager class * Use archiverWhitelistMinSigRequired config * Get and apply latest changes from global account * Code refactor and bug fixes * Fix: reload config on global account updates * Remove counter * Remove allowed signers and minSigRequired from the config * Update unit test
- Loading branch information
1 parent
175ddd8
commit 55df324
Showing
11 changed files
with
426 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"allowedArchivers": [ | ||
{ | ||
"ip": "127.0.0.1", | ||
"port": 4000, | ||
"publicKey": "758b1c119412298802cd28dbfa394cdfeecc4074492d60844cc192d632d84de3" | ||
}, | ||
{ | ||
"ip": "127.0.0.1", | ||
"port": 4001, | ||
"publicKey": "e8a5c26b9e2c3c31eb7c7d73eaed9484374c16d983ce95f3ab18a62521964a94" | ||
} | ||
], | ||
"signatures": [ | ||
{ | ||
"owner": "0x002D3a2BfE09E3E29b6d38d58CaaD16EEe4C9BC5", | ||
"sig": "0x53535921e57d0796b0dbf1451ff6a9ff535bbf2f51cdcc1a5ddd618aa62ca0f36a98c5e2fcecaa7217626735fc3bb5f47acc5e7e60284bb20fb157b50390d45f1b" | ||
} | ||
] | ||
} |
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,52 @@ | ||
import { ethers } from 'ethers'; | ||
import * as fs from 'fs'; | ||
import { Utils as StringUtils } from '@shardeum-foundation/lib-types'; | ||
|
||
interface ConfigData { | ||
allowedArchivers: string[]; | ||
} | ||
|
||
interface SignaturePayload { | ||
allowedArchivers: string[]; | ||
} | ||
|
||
async function generateSignature(): Promise<void> { | ||
try { | ||
|
||
// Get private key from env or command line | ||
const privateKey = process.env.PRIVATE_KEY || process.argv[2]; | ||
if (!privateKey) { | ||
throw new Error('Private key not provided. Set PRIVATE_KEY in .env or provide as command line argument'); | ||
} | ||
|
||
// Read and parse config file | ||
const configData: ConfigData = StringUtils.safeJsonParse( | ||
fs.readFileSync('./allowed-archivers.json', 'utf8') | ||
); | ||
|
||
// Create payload | ||
const rawPayload: SignaturePayload = { | ||
allowedArchivers: configData.allowedArchivers | ||
}; | ||
|
||
// Generate hash of payload | ||
const payloadHash = ethers.keccak256( | ||
ethers.toUtf8Bytes(StringUtils.safeStringify(rawPayload)) | ||
); | ||
|
||
console.log('Payload hash:', payloadHash); | ||
|
||
// Initialize wallet and sign | ||
const wallet = new ethers.Wallet(privateKey); | ||
const signature = await wallet.signMessage(payloadHash); | ||
console.log('Signature:', signature); | ||
} catch (error) { | ||
console.error('Error generating signature:', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
// Execute if running directly | ||
if (require.main === module) { | ||
generateSignature(); | ||
} |
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
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
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.