| 14 | ) |
| 15 | |
| 16 | const createKey = (encryptStr, ivHex) => { |
| 17 | const encryptStrBuffer = self.buffer.SlowBuffer(encryptStr) |
| 18 | const ivBuffer = self.buffer.SlowBuffer(ivHex) |
| 19 | |
| 20 | const N = 32768 |
| 21 | const r = 8 |
| 22 | const p = 1 |
| 23 | const dkLen = 32 |
| 24 | |
| 25 | self.scrypt( |
| 26 | encryptStrBuffer, |
| 27 | ivBuffer, |
| 28 | N, |
| 29 | r, |
| 30 | p, |
| 31 | dkLen, |
| 32 | function (error, progress, key) { |
| 33 | if (error) { |
| 34 | throw error |
| 35 | } else if (key) { |
| 36 | key = new self.buffer.SlowBuffer(key) |
| 37 | const keyHex = key.toString('hex') |
| 38 | postMessage({ keyHex, keyBuffer: key }) |
| 39 | } |
| 40 | // no else clause here, the progress triggers the else clause |
| 41 | // but there's no key yet at that point |
| 42 | } |
| 43 | ) |
| 44 | } |
| 45 | |
| 46 | self.onmessage = (e) => { |
| 47 | if (!e) return |