Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ curl --location 'https://keycard.snapshot.org/' \

### whitelist

This method is used by laser to whitelist new address
This method whitelists a new address and returns a generated API key. It does
not require the apps secret, so it can be called directly from the Snapshot UI.

```sh
curl --location 'https://keycard.snapshot.org/' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'secret: <APP_SECRET>' \
--data '{
"jsonrpc": "2.0",
"method": "whitelist",
"params": {
"owner": "<OWNER_ADDRESS>",
"address": "<OWNER_ADDRESS>",
"name": "<NAME>"
},
"id": "123456789"
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const authChecker = async (req, res, next) => {
const { id = null, method } = req.body;
const { secret = '' } = req.headers;

if (method !== 'generate_key' && secret !== APPS_SECRET) {
const publicMethods = ['generate_key', 'whitelist'];

if (!publicMethods.includes(method) && secret !== APPS_SECRET) {
console.log('[Received] method:', method, id);
return rpcError(res, 401, 'Wrong secret', id);
}
Expand Down
19 changes: 16 additions & 3 deletions test/e2e/whitelist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ const ADDRESS = '0x0000000000000000000000000000000000000001';

describe('POST / { method: whitelist }', () => {
beforeEach(async () => {
await cleanupDb();
await cleanupDb(NAME);
});

afterAll(async () => {
await cleanupDb();
await cleanupDb(NAME);
return db.endAsync();
});

describe('on a valid payload', () => {
it('whitelists the given address', async () => {
it('whitelists the given address and returns a key', async () => {
const response = await request(HOST)
.post('/')
.set({ secret: process.env.SECRET })
Expand All @@ -27,6 +27,19 @@ describe('POST / { method: whitelist }', () => {

expect(response.status).toBe(200);
expect(response.body.result.success).toBe(true);
expect(response.body.result.key).toHaveLength(64);
});

it('whitelists without the apps secret', async () => {
const response = await request(HOST)
.post('/')
.send({
method: 'whitelist',
params: { name: NAME, address: ADDRESS }
});

expect(response.status).toBe(200);
expect(response.body.result.success).toBe(true);
});
});

Expand Down