UNPKG

1.02 kBJavaScriptView Raw
1var fs = require('fs')
2 , path = require('path')
3 , libPubkey = require('../lib/pubkey')
4 , loadPubkey = require('../utils/loadPubkey')
5
6function 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 // add self
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 // base58
27 recipients[pubkey.pubkey] = pubkey
28 // email
29 if (pubkey.email) recipients[pubkey.email] = pubkey
30 })
31 cb(null, recipients)
32 })
33 })
34}
35module.exports = loadRecipients
\No newline at end of file