Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(askar): improved hardware key support #1968

Conversation

berendsliedrecht
Copy link
Contributor

Signed-off-by: Berend Sliedrecht [email protected]

Copy link

changeset-bot bot commented Jul 26, 2024

⚠️ No Changeset found

Latest commit: 49cfbf9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

keyId: kid,
})

return new Key(publicKeyBytes, keyType, keyId)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be kid here

Copy link
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me 👍 Will you remove the secure env integration from askar again?

@@ -44,6 +45,7 @@
"typescript": "~5.5.2"
},
"peerDependencies": {
"@hyperledger/aries-askar-shared": "^0.2.3"
"@hyperledger/aries-askar-shared": "^0.2.3",
"@animo-id/expo-secure-environment": "^0.0.1-alpha.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add it as optional peer dependency? https://pnpm.io/next/package_json#peerdependenciesmetaoptional

Comment on lines 6 to 10
const secureEnvironment = require('@animo-id/expo-secure-environment') as {
sign: typeof sign
generateKeypair: typeof generateKeypair
getPublicBytesForKeyId: typeof getPublicBytesForKeyId
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type is not really needed, as you never import from the .native.ts file. So it doesn't really matter to add the typing here (And it'll probably get out of date). If you do want to have the typying, i'd recommend to use import syntax:

Suggested change
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') as typeof import('@animo-id/expo-secure-environment')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However this still may give issues in envs where the package is not imported and then TS will complain that it can't find the types. So we should either always install the dep and only import it in native. Or we should not always install the dep, but then we should also not import the types form the package at all

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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'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'

private async doesSecureEnvironmentKeyExist(keyId: string): Promise<boolean> {
try {
const entryObject = await this.withSession((session) =>
session.fetch({ category: 'SecureEnvironmentRecord', name: keyId })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
session.fetch({ category: 'SecureEnvironmentRecord', name: keyId })
session.fetch({ category: 'SecureEnvironmentKeyRecord', name: keyId })

@@ -509,4 +557,28 @@ export abstract class AskarBaseWallet implements Wallet {
throw new WalletError('Error saving KeyPair record', { cause: error })
}
}

private async storeHardwareKeyById(options: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incosistent naming hardwareKey vs secureEnvironmentKey

@@ -8,10 +8,12 @@ import { getKeyTypeByMultiCodecPrefix, getMultiCodecPrefixByKeyType } from './mu
export class Key {
public readonly publicKey: Buffer
public readonly keyType: KeyType
public keyId: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public keyId: string
/** 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

@berendsliedrecht
Copy link
Contributor Author

This looks good to me 👍 Will you remove the secure env integration from askar again?

Yes, can pick that up later.

@berendsliedrecht berendsliedrecht merged commit 1a941e7 into openwallet-foundation:main Jul 29, 2024
13 checks passed
@berendsliedrecht berendsliedrecht deleted the mobile-hardware-keys branch July 29, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants