Skip to content

Commit

Permalink
feat: allow empty keystore constructor params
Browse files Browse the repository at this point in the history
  • Loading branch information
ayZagen committed Sep 23, 2021
1 parent 189f122 commit 1cfbf0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 44 deletions.
20 changes: 8 additions & 12 deletions src/keystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ export class KeyStore {

constructor(opts?: KeyStoreOpts) {
opts = opts || {}
if (opts.encryption) {
if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {
throw new Error("keys are required for encryption")
}
}
if (opts.signing) {
if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {
throw new Error("keys are required for signing")
}
}

this.encryption = Object.assign({
algorithm: 'aes-192-ccm',
authTagLength: 16,
encoding: 'hex', keys: []
encoding: 'hex',
keys: []
}, opts.encryption || {} as any)

this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)
this.signing = Object.assign({
encoding: 'base64',
algorithm: 'sha1',
keys: []
}, opts.signing || {} as any)

}

Expand Down
32 changes: 0 additions & 32 deletions tests/keystore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,6 @@ describe('[constructor]', () => {
new KeyStore(null)
})

it('should check encryption keys', () => {
expect(() => {
// @ts-expect-error
new KeyStore({encryption: {}})
}).toThrow(Error)

expect(() => {
new KeyStore({encryption: {keys: []}})
}).toThrow(Error)

expect(() => {
// @ts-expect-error
new KeyStore({encryption: {keys: {}}})
}).toThrow(Error)
})

it('should check signing keys', () => {
expect(() => {
// @ts-expect-error
new KeyStore({signing: {}})
}).toThrow(Error)

expect(() => {
new KeyStore({signing: {keys: []}})
}).toThrow(Error)

expect(() => {
// @ts-expect-error
new KeyStore({signing: {keys: {}}})
}).toThrow(Error)
})

it('should assign encryption defaults', () => {
const ks = new KeyStore({encryption: {keys: [genRandom()]}})

Expand Down

0 comments on commit 1cfbf0a

Please sign in to comment.