Skip to content

Commit

Permalink
fix: renaming
Browse files Browse the repository at this point in the history
Signed-off-by: Artemkaaas <artem.ivanov@dsr-corporation.com>
  • Loading branch information
Artemkaaas committed Aug 4, 2023
1 parent 0c875da commit 20b125b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ export const SigningProviderToken = Symbol('SigningProviderToken')

@injectable()
export class SigningProviderRegistry {
public keyProviders: SigningProvider[]
public signingProviders: SigningProvider[]

public constructor(@injectAll(SigningProviderToken) keyProviders: Array<'default' | SigningProvider>) {
public constructor(@injectAll(SigningProviderToken) signingProviders: Array<'default' | SigningProvider>) {
// This is a really ugly hack to make tsyringe work without any SigningProviders registered
// It is currently impossible to use @injectAll if there are no instances registered for the
// token. We register a value of `default` by default and will filter that out in the registry.
// Once we have a signing provider that should always be registered we can remove this. We can make an ed25519
// signer using the @stablelib/ed25519 library.
this.keyProviders = keyProviders.filter((provider) => provider !== 'default') as SigningProvider[]
this.signingProviders = signingProviders.filter((provider) => provider !== 'default') as SigningProvider[]
}

public hasProviderForKeyType(keyType: KeyType): boolean {
const signingKeyProvider = this.keyProviders.find((x) => x.keyType === keyType)
const signingKeyProvider = this.signingProviders.find((x) => x.keyType === keyType)

return signingKeyProvider !== undefined
}

public getProviderForKeyType(keyType: KeyType): SigningProvider {
const signingKeyProvider = this.keyProviders.find((x) => x.keyType === keyType)
const signingKeyProvider = this.signingProviders.find((x) => x.keyType === keyType)

if (!signingKeyProvider) {
throw new AriesFrameworkError(`No key provider for key type: ${keyType}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { SigningProvider, KeyPair } from '../SigningProvider'
import { KeyType } from '../../KeyType'
import { SigningProviderRegistry } from '../SigningProviderRegistry'

class KeyProviderMock implements SigningProvider {
class SigningProviderMock implements SigningProvider {
public readonly keyType = KeyType.Bls12381g2

public async createKeyPair(): Promise<KeyPair> {
Expand All @@ -18,8 +18,8 @@ class KeyProviderMock implements SigningProvider {
}
}

const keyProvider = new KeyProviderMock()
const signingProviderRegistry = new SigningProviderRegistry([keyProvider])
const signingProvider = new SigningProviderMock()
const signingProviderRegistry = new SigningProviderRegistry([signingProvider])

describe('SigningProviderRegistry', () => {
describe('hasProviderForKeyType', () => {
Expand All @@ -34,7 +34,7 @@ describe('SigningProviderRegistry', () => {

describe('getProviderForKeyType', () => {
test('returns the correct provider true if the key type is registered', () => {
expect(signingProviderRegistry.getProviderForKeyType(KeyType.Bls12381g2)).toBe(keyProvider)
expect(signingProviderRegistry.getProviderForKeyType(KeyType.Bls12381g2)).toBe(signingProvider)
})

test('throws error if the key type is not registered', () => {
Expand Down
4 changes: 0 additions & 4 deletions txn.txt

This file was deleted.

0 comments on commit 20b125b

Please sign in to comment.