Skip to content

Commit

Permalink
chore: resolve feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <berend@animo.id>
  • Loading branch information
berendsliedrecht committed Feb 6, 2025
1 parent d037fbc commit 4758e8b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
15 changes: 9 additions & 6 deletions packages/askar/src/wallet/AskarBaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
KeyBackend,
KeyType,
utils,
expandIfPossible,
expandPublicKeyIfPossible,
} from '@credo-ts/core'
import {
CryptoBox,
Expand Down Expand Up @@ -181,7 +181,7 @@ export abstract class AskarBaseWallet implements Wallet {
// This will be fixed once we use the new 'using' syntax
key = _key

const keyPublicBytes = expandIfPossible(key.publicBytes, keyType)
const keyPublicBytes = expandPublicKeyIfPossible(key.publicBytes, keyType)

// Store key
await this.withSession((session) =>
Expand All @@ -208,7 +208,7 @@ export abstract class AskarBaseWallet implements Wallet {
await secureEnvironment.generateKeypair(kid)
const compressedPublicKeyBytes = await secureEnvironment.getPublicBytesForKeyId(kid)

const publicKeyBytes = expandIfPossible(compressedPublicKeyBytes, keyType)
const publicKeyBytes = expandPublicKeyIfPossible(compressedPublicKeyBytes, keyType)
const publicKeyBase58 = TypedArrayEncoder.toBase58(publicKeyBytes)

await this.storeSecureEnvironmentKeyById({
Expand Down Expand Up @@ -351,9 +351,12 @@ export abstract class AskarBaseWallet implements Wallet {
if (!isError(error)) {
throw new CredoError('Attempted to throw error, but it was not of type Error', { cause: error })
}
throw new WalletError(`Error signing data with key associated with ${key.publicKeyBase58}. ${error.message}`, {
cause: error,
})
throw new WalletError(
`Error signing data with key associated with publicKeyBase58 ${key.publicKeyBase58}. ${error.message}`,
{
cause: error,
}
)
} finally {
askarKey?.handle.free()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bbs-signatures/tests/bbs-signing-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describeSkipNode18('BBS Signing Provider', () => {
key,
})
).rejects.toThrow(
'Error signing data with key associated with AeAihfn5UFf7y9oesemKE1oLmTwKMRv7fafTepespr3qceF4RUMggAbogkoC8n6rXgtJytq4oGy59DsVHxmNj9WGWwkiRnP3Sz2r924RLVbc2NdP4T7yEPsSFZPsWmLjgnP1vXHpj4bVXNcTmkUmF6mSXinF3HehnQVip14vRFuMzYVxMUh28ofTJzbtUqxMWZQRu. Unsupported keyType: bls12381g1g2'
'Error signing data with key associated with publicKeyBase58 AeAihfn5UFf7y9oesemKE1oLmTwKMRv7fafTepespr3qceF4RUMggAbogkoC8n6rXgtJytq4oGy59DsVHxmNj9WGWwkiRnP3Sz2r924RLVbc2NdP4T7yEPsSFZPsWmLjgnP1vXHpj4bVXNcTmkUmF6mSXinF3HehnQVip14vRFuMzYVxMUh28ofTJzbtUqxMWZQRu. Unsupported keyType: bls12381g1g2'
)
})

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/crypto/Key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { KeyType } from './KeyType'

import { MultiBaseEncoder, TypedArrayEncoder, VarintEncoder } from '../utils'

import { compressIfPossible, expandIfPossible } from './jose/jwk/ecCompression'
import { compressIfPossible, expandPublicKeyIfPossible } from './jose/jwk/ecCompression'
import { isEncryptionSupportedForKeyType, isSigningSupportedForKeyType } from './keyUtils'
import { getKeyTypeByMultiCodecPrefix, getMultiCodecPrefixByKeyType } from './multiCodecKey'

Expand All @@ -11,7 +11,7 @@ export class Key {
public readonly keyType: KeyType

public constructor(publicKey: Uint8Array, keyType: KeyType) {
this.publicKey = expandIfPossible(publicKey, keyType)
this.publicKey = expandPublicKeyIfPossible(publicKey, keyType)
this.keyType = keyType
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/crypto/jose/jwk/ecCompression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function compressIfPossible(publicKey: Uint8Array, keyType: KeyType): Uin
return isValidUncompressedPublicKey(publicKey, keyType) ? compress(publicKey) : publicKey
}

export function expandIfPossible(publicKey: Uint8Array, keyType: KeyType): Uint8Array {
export function expandPublicKeyIfPossible(publicKey: Uint8Array, keyType: KeyType): Uint8Array {
return isValidCompressedPublicKey(publicKey, keyType) ? expand(publicKey, keyType as CompressableKey) : publicKey
}

Expand Down
4 changes: 2 additions & 2 deletions tests/InMemoryWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CryptoBox, Store, Key as AskarKey, keyAlgFromString } from '@hyperledge

import { convertToAskarKeyBackend } from '../packages/askar/src/utils/askarKeyBackend'
import { didcommV1Pack, didcommV1Unpack } from '../packages/askar/src/wallet/didcommV1'
import { expandIfPossible } from '../packages/core/src/crypto/jose/jwk/ecCompression'
import { expandPublicKeyIfPossible } from '../packages/core'

Check warning on line 15 in tests/InMemoryWallet.ts

View workflow job for this annotation

GitHub Actions / Validate

'/home/runner/work/credo-ts/credo-ts/packages/core/src/index.ts' imported multiple times

import {
JsonEncoder,
Expand Down Expand Up @@ -185,7 +185,7 @@ export class InMemoryWallet implements Wallet {
const keyPublicBytes = key.publicBytes

// Store key
this.getInMemoryKeys()[TypedArrayEncoder.toBase58(expandIfPossible(keyPublicBytes, keyType))] = {
this.getInMemoryKeys()[TypedArrayEncoder.toBase58(expandPublicKeyIfPossible(keyPublicBytes, keyType))] = {
publicKeyBytes: keyPublicBytes,
secretKeyBytes: key.secretBytes,
keyType,
Expand Down

0 comments on commit 4758e8b

Please sign in to comment.