corestore 6.0.1-alpha.16 → 6.0.1-alpha.17
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/index.js +2 -4
- package/package.json +1 -1
- package/test/all.js +24 -0
package/index.js
CHANGED
|
@@ -211,7 +211,7 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
211
211
|
auth: {
|
|
212
212
|
sign: (msg) => sign(keyPair, msg),
|
|
213
213
|
verify: (signable, signature) => {
|
|
214
|
-
return
|
|
214
|
+
return crypto.verify(signable, signature, keyPair.publicKey)
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
}
|
|
@@ -321,9 +321,7 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
321
321
|
|
|
322
322
|
function sign (keyPair, message) {
|
|
323
323
|
if (!keyPair.secretKey) throw new Error('Invalid key pair')
|
|
324
|
-
|
|
325
|
-
sodium.crypto_sign_detached(signature, message, keyPair.secretKey)
|
|
326
|
-
return signature
|
|
324
|
+
return crypto.sign(message, keyPair.secretKey)
|
|
327
325
|
}
|
|
328
326
|
|
|
329
327
|
function validateGetOptions (opts) {
|
package/package.json
CHANGED
package/test/all.js
CHANGED
|
@@ -287,6 +287,30 @@ test('different primary keys yield different keypairs', async function (t) {
|
|
|
287
287
|
t.unlike(kp1.publicKey, kp2.publicKey)
|
|
288
288
|
})
|
|
289
289
|
|
|
290
|
+
test('keypair auth sign', async function (t) {
|
|
291
|
+
const store = new Corestore(ram)
|
|
292
|
+
const keyPair = await store.createKeyPair('foo')
|
|
293
|
+
const message = b4a.from('hello world')
|
|
294
|
+
|
|
295
|
+
const sig = keyPair.auth.sign(message)
|
|
296
|
+
|
|
297
|
+
t.is(sig.length, 64)
|
|
298
|
+
t.ok(crypto.verify(message, sig, keyPair.publicKey))
|
|
299
|
+
t.absent(crypto.verify(message, b4a.alloc(64), keyPair.publicKey))
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
test('keypair auth verify', async function (t) {
|
|
303
|
+
const store = new Corestore(ram)
|
|
304
|
+
const keyPair = await store.createKeyPair('foo')
|
|
305
|
+
const message = b4a.from('hello world')
|
|
306
|
+
|
|
307
|
+
const sig = crypto.sign(message, keyPair.secretKey)
|
|
308
|
+
|
|
309
|
+
t.is(sig.length, 64)
|
|
310
|
+
t.ok(keyPair.auth.verify(message, sig))
|
|
311
|
+
t.absent(keyPair.auth.verify(message, b4a.alloc(64)))
|
|
312
|
+
})
|
|
313
|
+
|
|
290
314
|
function tmpdir () {
|
|
291
315
|
return path.join(os.tmpdir(), 'corestore-' + Math.random().toString(16).slice(2))
|
|
292
316
|
}
|