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

fix: patch askar to return public bytes #244

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions apps/easypid/src/crypto/WalletServiceProviderClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,34 @@ import { deriveKeypairFromPin } from './pin'

// TODO: should auto reset after X seconds
let __pin: Array<number> | undefined
export const setWalletServiceProviderPin = async (pin: Array<number>) => {
export const setWalletServiceProviderPin = async (pin: Array<number>, validatePin = true) => {
const pinString = pin.join('')
const walletKeyVersion = secureWalletKey.getWalletKeyVersion()
const walletKey = await secureWalletKey.getWalletKeyUsingPin(pinString, walletKeyVersion)
const walletId = `easypid-wallet-${walletKeyVersion}`
const agent = new Agent({
config: {
label: 'pin_test_agent',
walletConfig: { id: walletId, key: walletKey, keyDerivationMethod: KeyDerivationMethod.Raw },
},
modules: {
askar: new AskarModule({ ariesAskar }),
},
dependencies: agentDependencies,
})
if (validatePin) {
const walletKeyVersion = secureWalletKey.getWalletKeyVersion()
const walletKey = await secureWalletKey.getWalletKeyUsingPin(pinString, walletKeyVersion)
const walletId = `easypid-wallet-${walletKeyVersion}`
const agent = new Agent({
config: {
label: 'pin_test_agent',
walletConfig: { id: walletId, key: walletKey, keyDerivationMethod: KeyDerivationMethod.Raw },
},
modules: {
askar: new AskarModule({ ariesAskar }),
},
dependencies: agentDependencies,
})

try {
await agent.initialize()
} catch (e) {
if (e instanceof WalletInvalidKeyError) {
throw new InvalidPinError()
try {
await agent.initialize()
} catch (e) {
if (e instanceof WalletInvalidKeyError) {
throw new InvalidPinError()
}
throw e
}
throw e
}

await agent.shutdown()
await agent.shutdown()
}
__pin = pin
}

Expand Down
4 changes: 2 additions & 2 deletions apps/easypid/src/features/onboarding/onboardingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ export function OnboardingContextProvider({

return secureUnlock
.setup(walletPin as string)
.then(({ walletKey }) => {
setWalletServiceProviderPin((walletPin as string).split('').map(Number))
.then(async ({ walletKey }) => {
await setWalletServiceProviderPin((walletPin as string).split('').map(Number), false)
return initializeAgent(walletKey)
})
.then(goToNextStep)
Expand Down
3 changes: 1 addition & 2 deletions patches/@credo-ts__askar@0.6.0-pr-2102-20241122194225.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ index f4352d639a511347d9a087f4ba5c5afddec477ce..b67794d922ba8112dcca27b8166c2877
// Generate a hardware-backed P-256 keypair
- secureEnvironment.generateKeypair(kid);
- const publicKeyBytes = secureEnvironment.getPublicBytesForKeyId(kid);
+ await secureEnvironment.generateKeypair(kid);
+ const publicKeyBytes = await secureEnvironment.getPublicBytesForKeyId(kid);
+ const publicKeyBytes = await secureEnvironment.generateKeypair(kid);
const publicKeyBase58 = core_1.TypedArrayEncoder.toBase58(publicKeyBytes);
await this.storeSecureEnvironmentKeyById({
keyType,