Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 9bd0bae

Browse files
committed
refactor(encryption): Remove static validateGroupKey from Encryption class, just use GroupKey.validate().
1 parent cb576fd commit 9bd0bae

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/stream/Encryption.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ class EncryptionUtilBase {
224224
}
225225
}
226226

227-
static validateGroupKey(groupKey: any) {
228-
return GroupKey.validate(groupKey)
229-
}
230-
231227
/*
232228
* Returns a Buffer or a hex String
233229
*/

test/unit/Encryption.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,24 @@ function TestEncryptionUtil({ isBrowser = false } = {}) {
163163
})
164164
})
165165

166-
it('validateGroupKey() throws if key is the wrong size', () => {
167-
expect(() => {
168-
EncryptionUtil.validateGroupKey(crypto.randomBytes(16))
169-
}).toThrow()
170-
})
166+
describe('GroupKey.validate', () => {
167+
it('throws if key is the wrong size', () => {
168+
expect(() => {
169+
GroupKey.validate(GroupKey.from(['test', crypto.randomBytes(16)]))
170+
}).toThrow('size')
171+
})
171172

172-
it('validateGroupKey() throws if key is not a buffer', () => {
173-
expect(() => {
174-
EncryptionUtil.validateGroupKey(ethers.utils.hexlify(GroupKey.generate() as any))
175-
}).toThrow()
176-
})
173+
it('throws if key is not a buffer', () => {
174+
expect(() => {
175+
// expected error below is desirable, show typecheks working as intended
176+
// @ts-expect-error
177+
GroupKey.validate(GroupKey.from(['test', Array.from(crypto.randomBytes(32))]))
178+
}).toThrow('Buffer')
179+
})
177180

178-
it('validateGroupKey() does not throw', () => {
179-
EncryptionUtil.validateGroupKey(GroupKey.generate())
181+
it('does not throw with valid values', () => {
182+
GroupKey.validate(GroupKey.generate())
183+
})
180184
})
181185
})
182186
}

0 commit comments

Comments
 (0)