1 | var fs = require('fs')
|
2 | , path = require('path')
|
3 | , libPubkey = require('../lib/pubkey')
|
4 | , loadPubkey = require('../utils/loadPubkey')
|
5 |
|
6 | function loadRecipients (walletDir, cb) {
|
7 | var inFile = path.join(walletDir, 'imported_keys')
|
8 | fs.readFile(inFile, {encoding: 'utf8'}, function (err, str) {
|
9 | if (err && err.code !== 'ENOENT') return cb(err)
|
10 | var lines = (str || '').trim().split('\n')
|
11 |
|
12 | loadPubkey(walletDir, function (err, pubkey) {
|
13 | if (err) return cb(err)
|
14 | var recipients = Object.create(null)
|
15 | if (pubkey) {
|
16 | recipients['self'] = pubkey
|
17 | lines.push(pubkey.toString())
|
18 | }
|
19 | lines.forEach(function (line) {
|
20 | try {
|
21 | var pubkey = libPubkey.parse(line.trim())
|
22 | }
|
23 | catch (e) {
|
24 | return
|
25 | }
|
26 |
|
27 | recipients[pubkey.pubkey] = pubkey
|
28 |
|
29 | if (pubkey.email) recipients[pubkey.email] = pubkey
|
30 | })
|
31 | cb(null, recipients)
|
32 | })
|
33 | })
|
34 | }
|
35 | module.exports = loadRecipients |
\ | No newline at end of file |