Skip to content

Commit

Permalink
fix: patch askar to return public bytes (#244)
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht authored Nov 26, 2024
1 parent ef7ed4b commit c6387b8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
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/@[email protected]
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,

0 comments on commit c6387b8

Please sign in to comment.