Skip to content

Commit

Permalink
chore: resolved feedback and formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <sliedrecht@berend.io>
  • Loading branch information
berendsliedrecht committed Jul 29, 2024
1 parent 8af84ef commit 49cfbf9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions packages/askar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@
"peerDependencies": {
"@hyperledger/aries-askar-shared": "^0.2.3",
"@animo-id/expo-secure-environment": "^0.0.1-alpha.0"
},
"peerDependenciesMeta": {
"@animo-id/expo-secure-environment": {
"optional": true
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import type { getPublicBytesForKeyId, generateKeypair, sign } from '@animo-id/expo-secure-environment'

export function importSecureEnvironment() {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const secureEnvironment = require('@animo-id/expo-secure-environment') as {
sign: typeof sign
generateKeypair: typeof generateKeypair
getPublicBytesForKeyId: typeof getPublicBytesForKeyId
}
const secureEnvironment = require('@animo-id/expo-secure-environment')
return secureEnvironment
} catch (error) {
throw new Error('@animo-id/expo-secure-environment must be installed as a peer dependency')
Expand Down
2 changes: 1 addition & 1 deletion packages/askar/src/secureEnvironment/secureEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export function importSecureEnvironment(): {
generateKeypair: (id: string) => void
} {
throw new Error(
'expo-secure-environment cannot be imported in Node.js. Currently, there is no hardware key support for node.js'
'@animo-id/expo-secure-environment cannot be imported in Node.js. Currently, there is no hardware key support for node.js'
)
}
12 changes: 6 additions & 6 deletions packages/askar/src/wallet/AskarBaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { CryptoBox, Store, Key as AskarKey, keyAlgFromString } from '@hyperledger/aries-askar-shared'
import BigNumber from 'bn.js'

import { importSecureEnvironment } from '../secureEnvironment'
import {
AskarErrorCode,
AskarKeyTypePurpose,
Expand All @@ -40,7 +41,6 @@ import {
} from '../utils'

import { didcommV1Pack, didcommV1Unpack } from './didcommV1'
import { importSecureEnvironment } from '../secureEnvironment'

const isError = (error: unknown): error is Error => error instanceof Error

Expand Down Expand Up @@ -200,13 +200,13 @@ export abstract class AskarBaseWallet implements Wallet {
const publicKeyBytes = secureEnvironment.getPublicBytesForKeyId(kid)
const publicKeyBase58 = TypedArrayEncoder.toBase58(publicKeyBytes)

await this.storeHardwareKeyById({
await this.storeSecureEnvironmentKeyById({
keyType,
publicKeyBase58,
keyId: kid,
})

return new Key(publicKeyBytes, keyType, keyId)
return new Key(publicKeyBytes, keyType, kid)
} else {
// Check if there is a signing key provider for the specified key type.
if (this.signingKeyProviderRegistry.hasProviderForKeyType(keyType)) {
Expand Down Expand Up @@ -521,7 +521,7 @@ export abstract class AskarBaseWallet implements Wallet {
private async doesSecureEnvironmentKeyExist(keyId: string): Promise<boolean> {
try {
const entryObject = await this.withSession((session) =>
session.fetch({ category: 'SecureEnvironmentRecord', name: keyId })
session.fetch({ category: 'SecureEnvironmentKeyRecord', name: keyId })
)

return !!entryObject
Expand Down Expand Up @@ -558,15 +558,15 @@ export abstract class AskarBaseWallet implements Wallet {
}
}

private async storeHardwareKeyById(options: {
private async storeSecureEnvironmentKeyById(options: {
keyId: string
publicKeyBase58: string
keyType: KeyType
}): Promise<void> {
try {
await this.withSession((session) =>
session.insert({
category: 'SecureEnvironmentRecord',
category: 'SecureEnvironmentKeyRecord',
name: options.keyId,
value: JSON.stringify(options),
tags: {
Expand Down
2 changes: 1 addition & 1 deletion packages/askar/src/wallet/__tests__/AskarWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('AskarWallet basic operations', () => {
await expect(askarWallet.createKey({ seed, keyType: KeyType.P384 })).rejects.toThrow(WalletError)
})

test('Fail to create a P256 keypair in hardware', async () => {
test('Fail to create a P256 keypair in the secure environment', async () => {
await expect(
askarWallet.createKey({ keyType: KeyType.P256, keyBackend: KeyBackend.SecureElement })
).rejects.toThrow(WalletError)
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/crypto/Key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { getKeyTypeByMultiCodecPrefix, getMultiCodecPrefixByKeyType } from './mu
export class Key {
public readonly publicKey: Buffer
public readonly keyType: KeyType

/**
*
* the identifier of the key. If not provided in the constructor the base58 encoded public key will be used as the key identifier by default
*
*/
public keyId: string

public constructor(publicKey: Uint8Array, keyType: KeyType, keyId?: string) {
Expand Down

0 comments on commit 49cfbf9

Please sign in to comment.