@evanp/activitypub-bot 0.13.9 → 0.13.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/keystorage.js +11 -4
- package/package.json +1 -1
package/lib/keystorage.js
CHANGED
|
@@ -50,7 +50,8 @@ export class KeyStorage {
|
|
|
50
50
|
'found key for bot in database')
|
|
51
51
|
publicKey = result[0].public_key
|
|
52
52
|
privateKey = result[0].private_key
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
|
+
if (!publicKey || !privateKey) {
|
|
54
55
|
this.#logger.debug(
|
|
55
56
|
{ username, method: 'KeyStorage.#getKeys' },
|
|
56
57
|
'no key for bot, generating new key'
|
|
@@ -62,11 +63,13 @@ export class KeyStorage {
|
|
|
62
63
|
)
|
|
63
64
|
await this.#saveKeyPair(username, publicKey, privateKey)
|
|
64
65
|
}
|
|
66
|
+
const publicKeyHash = publicKey ? this.#hasher.humanize(publicKey) : null
|
|
67
|
+
const privateKeyHash = privateKey ? this.#hasher.humanize(privateKey) : null
|
|
65
68
|
this.#logger.debug({
|
|
66
69
|
username,
|
|
67
70
|
method: 'KeyStorage.#getKeys',
|
|
68
|
-
publicKeyHash
|
|
69
|
-
privateKeyHash
|
|
71
|
+
publicKeyHash,
|
|
72
|
+
privateKeyHash
|
|
70
73
|
})
|
|
71
74
|
return [publicKey, privateKey]
|
|
72
75
|
}
|
|
@@ -91,7 +94,11 @@ export class KeyStorage {
|
|
|
91
94
|
|
|
92
95
|
async #saveKeyPair (username, publicKey, privateKey) {
|
|
93
96
|
await this.#connection.query(`
|
|
94
|
-
INSERT INTO new_keys (username, public_key, private_key)
|
|
97
|
+
INSERT INTO new_keys (username, public_key, private_key)
|
|
98
|
+
VALUES (?, ?, ?)
|
|
99
|
+
ON CONFLICT(username) DO UPDATE SET
|
|
100
|
+
public_key = excluded.public_key,
|
|
101
|
+
private_key = excluded.private_key
|
|
95
102
|
`, { replacements: [username, publicKey, privateKey] })
|
|
96
103
|
}
|
|
97
104
|
}
|