Skip to content

Commit

Permalink
fix: lens token
Browse files Browse the repository at this point in the history
  • Loading branch information
dudu0506 committed Nov 28, 2024
1 parent 3fafc15 commit 94eb2a0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/app/api/frames/vote/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const POST = frames(
const maxVoteCount = poll.type === POLL_CHOICE_TYPE.Multiple ? poll.multiple_count : PER_USER_VOTE_LIMIT;

if (!currentChoice.is_select && votedLen < maxVoteCount) {
if (body.untrustedData.idToken) {
body.untrustedData.identityToken = body.untrustedData.idToken;
delete body.untrustedData.idToken;
}
const voteResult = await vote(
{
poll_id: pollId,
Expand Down
4 changes: 3 additions & 1 deletion src/config/lensFrame.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getLensFrameMessage, isLensFrameActionPayload } from 'frames.js/lens';
import { isLensFrameActionPayload } from 'frames.js/lens';
import { openframes } from 'frames.js/middleware';

import { getLensFrameMessage } from '@/helpers/getLensFrameMessage';

export const lensFrame = openframes({
clientProtocol: {
id: 'lens',
Expand Down
68 changes: 68 additions & 0 deletions src/helpers/getLensFrameMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { development, FrameVerifySignatureResult, LensClient, production } from '@lens-protocol/client';

import { LensFrameOptions, LensFrameRequest, LensFrameResponse } from '@/types/lens';

type FrameRequest = LensFrameRequest & {
untrustedData: {
idToken?: string;
};
};

export async function getLensFrameMessage(
frameActionPayload: FrameRequest,
options?: LensFrameOptions,
): Promise<
LensFrameResponse & {
walletAddress(): Promise<string | undefined>;
}
> {
const lensClientEnvironment = options?.environment === 'development' ? development : production;

const lensClient = new LensClient({
environment: lensClientEnvironment,
});

const {
url,
inputText,
state,
buttonIndex,
actionResponse,
profileId,
pubId,
specVersion,
deadline,
identityToken,
idToken,
} = frameActionPayload.untrustedData;

const typedData = await lensClient.frames.createFrameTypedData({
url,
inputText,
state,
buttonIndex,
actionResponse,
profileId,
pubId,
specVersion,
deadline,
});

const response = await lensClient.frames.verifyFrameSignature({
identityToken: identityToken || idToken || '',
signature: frameActionPayload.trustedData.messageBytes,
signedTypedData: typedData,
});

return {
...typedData.value,
isValid: response === FrameVerifySignatureResult.Verified,
async walletAddress() {
const profile = await lensClient.profile.fetch({
forProfileId: typedData.value.profileId,
});

return profile?.ownedBy.address;
},
};
}

0 comments on commit 94eb2a0

Please sign in to comment.