blob: 84466bf25068b04b0f592229e72ff04a708eabbb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
const CryptographyKey = require('./cryptography-key');
/* istanbul ignore if */
if (typeof (Buffer) === 'undefined') {
let Buffer = require('buffer/').Buffer;
}
module.exports = class Backend {
constructor() {
// NOP
this.backendName = 'UndefinedBackend';
}
/**
* @param {CryptographyKey} sKey
* @param {CryptographyKey} pKey
* @return {Promise<CryptographyKey>}
*/
async crypto_box_keypair_from_secretkey_and_publickey(sKey, pKey) {
/* istanbul ignore if */
if (sKey.getLength() !== 32) {
throw new Error('Secret key must be 32 bytes');
}
/* istanbul ignore if */
if (pKey.getLength() !== 32) {
throw new Error('Public key must be 32 bytes');
}
const keypair = Buffer.alloc(64);
sKey.getBuffer().copy(keypair, 0, 0, 32);
pKey.getBuffer().copy(keypair, 32, 0, 32);
return new CryptographyKey(Buffer.from(keypair));
}
};
|