Skip to content

Commit

Permalink
fix: make keystore method lookup typesafe
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Sep 3, 2023
1 parent fc72dee commit b48be59
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/snap/src/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable jsdoc/require-jsdoc */
import {
InMemoryKeystore,
Keystore,
PrivateKeyBundleV1,
keystoreApiDefs,
} from '@xmtp/xmtp-js';
Expand Down Expand Up @@ -161,13 +162,16 @@ export function KeystoreHandler(backingKeystore: InMemoryKeystore) {
throw new Error('no method found in keystore');
}

// eslint-disable-next-line no-loop-func
out[method] = async (req: SnapRequest): Promise<SnapResponse> => {
const backingMethod = backingKeystore[method as keyof Keystore];
if (typeof backingMethod !== 'function') {
throw new Error('not a function');
}
return processProtoRequest(
apiDef,
req,
backingKeystore[method as keyof InMemoryKeystore].bind(
backingKeystore,
) as any,
backingMethod.bind(backingKeystore) as any,
);
};
}
Expand Down

0 comments on commit b48be59

Please sign in to comment.