Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Commit 80d4381

Browse files
committed
fix: allow alias renewal by re-submitting existing pair
Allow the same (address, alias) pair to be submitted again to refresh the expiration. Uses ON DUPLICATE KEY UPDATE to reset created timestamp.
1 parent b52bcb9 commit 80d4381

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

src/writer/alias.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ export async function verify(message): Promise<any> {
1414
return Promise.reject('alias cannot be the same as the address');
1515
}
1616

17-
const existing = await db.queryAsync(
18-
'SELECT 1 FROM aliases WHERE address = ? AND alias = ? LIMIT 1',
19-
[message.address, msg.payload.alias]
20-
);
21-
if (existing.length > 0) {
22-
return Promise.reject('alias already exists');
23-
}
24-
2517
return true;
2618
}
2719

@@ -34,5 +26,8 @@ export async function action(message, ipfs, receipt, id): Promise<void> {
3426
alias: msg.payload.alias,
3527
created: msg.timestamp
3628
};
37-
await db.queryAsync('INSERT INTO aliases SET ?', params);
29+
await db.queryAsync(
30+
'INSERT INTO aliases SET ? ON DUPLICATE KEY UPDATE id = VALUES(id), ipfs = VALUES(ipfs), created = VALUES(created)',
31+
params
32+
);
3833
}

test/integration/helpers/alias.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('alias', () => {
2626
});
2727

2828
describe('verify()', () => {
29-
it('should reject when alias already exists', async () => {
29+
it('should pass when alias pair already exists (allows renewal)', async () => {
3030
const { address, alias } = aliasesSqlFixtures[0];
3131
const msg = {
3232
version: '0.1.4',
@@ -35,9 +35,7 @@ describe('alias', () => {
3535
payload: { alias }
3636
};
3737

38-
await expect(verify({ address, msg: JSON.stringify(msg) })).rejects.toMatch(
39-
'alias already exists'
40-
);
38+
await expect(verify({ address, msg: JSON.stringify(msg) })).resolves.toBeTruthy();
4139
});
4240

4341
it('should pass when alias does not exist', async () => {

0 commit comments

Comments
 (0)