Skip to content

Commit

Permalink
fix: Check if file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Nov 13, 2019
1 parent 8f89979 commit 89f604f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/daf-sodium-fs/src/encryption-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ export class SodiumFsEncryptionKeyManager implements EncryptionKeyManager {

private readFromFile(): void {
try {
const raw = fs.readFileSync(this.fileName)
const parsed = JSON.parse(raw)

Object.keys(parsed).forEach(did => {
const i = parsed[did]
this.didKeyPairMap[did] = {
keyType: i.keyType,
privateKeyHex: i.privateKeyHex,
publicKeyHex: i.publicKeyHex,
privateKey: Uint8Array.from(Buffer.from(i.privateKeyHex, 'hex')),
publicKey: Uint8Array.from(Buffer.from(i.publicKeyHex, 'hex')),
}
})
if (fs.existsSync(this.fileName)) {
const raw = fs.readFileSync(this.fileName)
const parsed = JSON.parse(raw)

Object.keys(parsed).forEach(did => {
const i = parsed[did]
this.didKeyPairMap[did] = {
keyType: i.keyType,
privateKeyHex: i.privateKeyHex,
publicKeyHex: i.publicKeyHex,
privateKey: Uint8Array.from(Buffer.from(i.privateKeyHex, 'hex')),
publicKey: Uint8Array.from(Buffer.from(i.publicKeyHex, 'hex')),
}
})
}
} catch (e) {
debug(e)
}
Expand Down

0 comments on commit 89f604f

Please sign in to comment.