-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
39 lines (32 loc) · 771 Bytes
/
update.js
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
33
34
35
36
37
38
39
const { create } = require('./create')
const fs = require('./fs')
const debug = require('debug')('ara:identity:update')
/**
* Updates an ARA identity.
*/
async function update(identifier, opts) {
if (null == opts || 'object' !== typeof opts) {
throw new TypeError('Expecting object.')
}
if (opts.ddo) {
opts.created = opts.ddo.created
opts.updated = new Date()
}
if (!opts.keystore) {
opts.keystore = {}
try {
opts.keystore.ara = JSON.parse(await fs.readFile(identifier, 'keystore/ara'))
} catch (err) {
debug(err)
}
try {
opts.keystore.eth = JSON.parse(await fs.readFile(identifier, 'keystore/eth'))
} catch (err) {
debug(err)
}
}
return create(opts)
}
module.exports = {
update
}