Skip to content

Commit 0bff95b

Browse files
committed
fix: handle locked auths with no privatekey
1 parent c7c0407 commit 0bff95b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "krist",
3-
"version": "3.5.1",
3+
"version": "3.5.2",
44
"description": "The new Krist node written in TypeScript.",
55
"type": "module",
66
"scripts": {

src/krist/addresses/verify.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export async function verifyAddress(
6969
return { authed: true, address: newAddress };
7070
}
7171

72-
if (address.privatekey) { // Address exists, auth if the privatekey is equal
72+
// Address exists, auth if the privatekey is equal, or handle the locked flow if it's locked (even if there's no
73+
// privatekey set)
74+
if (address.privatekey || address.locked) {
7375
const authed = !address.locked && address.privatekey === hash;
7476

7577
if (authed) {

test/routes/login.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
import { expect } from "chai";
23+
import { Address } from "../../src/database/index.js";
2324
import { api } from "../api.js";
2425
import { seed } from "../seed.js";
2526

@@ -56,5 +57,21 @@ describe("v2 routes: login", function() {
5657
expect(res).to.be.json;
5758
expect(res.body).to.deep.include({ ok: true, authed: true, address: "k8juvewcui" });
5859
});
60+
61+
it("should error for locked addresses even without a privatekey", async function() {
62+
const address = await Address.findOne({ where: { address: "kwsgj3x184" } });
63+
if (!address) throw new Error("Address not found");
64+
65+
const oldPrivatekey = address.privatekey;
66+
address.privatekey = null;
67+
await address.save();
68+
69+
const res = await api().post("/login").send({ privatekey: "c" });
70+
expect(res).to.be.json;
71+
expect(res.body).to.deep.include({ ok: true, authed: false });
72+
73+
address.privatekey = oldPrivatekey;
74+
await address.save();
75+
});
5976
});
6077
});

0 commit comments

Comments
 (0)