Skip to content

Commit 6561913

Browse files
authored
Merge pull request #45 from DimensionDev/fix/lens-token
fix: lens token
2 parents 3fafc15 + 94eb2a0 commit 6561913

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

src/app/api/frames/vote/route.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export const POST = frames(
3434
const maxVoteCount = poll.type === POLL_CHOICE_TYPE.Multiple ? poll.multiple_count : PER_USER_VOTE_LIMIT;
3535

3636
if (!currentChoice.is_select && votedLen < maxVoteCount) {
37+
if (body.untrustedData.idToken) {
38+
body.untrustedData.identityToken = body.untrustedData.idToken;
39+
delete body.untrustedData.idToken;
40+
}
3741
const voteResult = await vote(
3842
{
3943
poll_id: pollId,

src/config/lensFrame.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { getLensFrameMessage, isLensFrameActionPayload } from 'frames.js/lens';
1+
import { isLensFrameActionPayload } from 'frames.js/lens';
22
import { openframes } from 'frames.js/middleware';
33

4+
import { getLensFrameMessage } from '@/helpers/getLensFrameMessage';
5+
46
export const lensFrame = openframes({
57
clientProtocol: {
68
id: 'lens',

src/helpers/getLensFrameMessage.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { development, FrameVerifySignatureResult, LensClient, production } from '@lens-protocol/client';
2+
3+
import { LensFrameOptions, LensFrameRequest, LensFrameResponse } from '@/types/lens';
4+
5+
type FrameRequest = LensFrameRequest & {
6+
untrustedData: {
7+
idToken?: string;
8+
};
9+
};
10+
11+
export async function getLensFrameMessage(
12+
frameActionPayload: FrameRequest,
13+
options?: LensFrameOptions,
14+
): Promise<
15+
LensFrameResponse & {
16+
walletAddress(): Promise<string | undefined>;
17+
}
18+
> {
19+
const lensClientEnvironment = options?.environment === 'development' ? development : production;
20+
21+
const lensClient = new LensClient({
22+
environment: lensClientEnvironment,
23+
});
24+
25+
const {
26+
url,
27+
inputText,
28+
state,
29+
buttonIndex,
30+
actionResponse,
31+
profileId,
32+
pubId,
33+
specVersion,
34+
deadline,
35+
identityToken,
36+
idToken,
37+
} = frameActionPayload.untrustedData;
38+
39+
const typedData = await lensClient.frames.createFrameTypedData({
40+
url,
41+
inputText,
42+
state,
43+
buttonIndex,
44+
actionResponse,
45+
profileId,
46+
pubId,
47+
specVersion,
48+
deadline,
49+
});
50+
51+
const response = await lensClient.frames.verifyFrameSignature({
52+
identityToken: identityToken || idToken || '',
53+
signature: frameActionPayload.trustedData.messageBytes,
54+
signedTypedData: typedData,
55+
});
56+
57+
return {
58+
...typedData.value,
59+
isValid: response === FrameVerifySignatureResult.Verified,
60+
async walletAddress() {
61+
const profile = await lensClient.profile.fetch({
62+
forProfileId: typedData.value.profileId,
63+
});
64+
65+
return profile?.ownedBy.address;
66+
},
67+
};
68+
}

0 commit comments

Comments
 (0)