-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
961 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FramesEip721TypedDataSpec, LensClient, development, staging } from '@lens-protocol/client'; | ||
|
||
async function main() { | ||
const client = new LensClient({ | ||
environment: staging, | ||
}); | ||
|
||
const deadline = new Date(); | ||
deadline.setMinutes(deadline.getMinutes() + 5); | ||
|
||
const result = await client.frames.createFrameTypedData({ | ||
actionResponse: '0x0000000000000000000000000000000000000000', | ||
buttonIndex: 2, | ||
deadline: deadline.getTime(), | ||
inputText: 'Hello, World!', | ||
profileId: '0x01', | ||
pubId: '0x01-0x01', | ||
specVersion: FramesEip721TypedDataSpec.OnePointOnePointOne, | ||
state: '{"counter":1,"idempotency_key":"431b8b38-eb4d-455b"}', | ||
url: 'https://mylensframe.xyz', | ||
}); | ||
|
||
console.log(`Result: `, result); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { FramesEip721TypedDataSpec } from '@lens-protocol/client'; | ||
|
||
import { getAuthenticatedClient } from '../shared/getAuthenticatedClient'; | ||
import { setupWallet } from '../shared/setupWallet'; | ||
|
||
async function main() { | ||
const wallet = setupWallet(); | ||
const client = await getAuthenticatedClient(wallet, '0x58'); | ||
|
||
const result = await client.frames.signFrameAction({ | ||
actionResponse: '0x0000000000000000000000000000000000000000', | ||
buttonIndex: 2, | ||
inputText: 'Hello, World!', | ||
profileId: '0x01', | ||
pubId: '0x01-0x01', | ||
specVersion: FramesEip721TypedDataSpec.OnePointOnePointOne, | ||
state: '{"counter":1,"idempotency_key":"431b8b38-eb4d-455b"}', | ||
url: 'https://mylensframe.xyz', | ||
}); | ||
|
||
if (result.isFailure()) { | ||
console.error(result.error); // CredentialsExpiredError or NotAuthenticatedError | ||
process.exit(1); | ||
} | ||
|
||
const data = result.value; | ||
|
||
console.log(`Result: `, data); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { PromiseResult } from '@lens-protocol/shared-kernel'; | ||
|
||
import type { Authentication } from '../../authentication'; | ||
import { LensContext } from '../../context'; | ||
import { CredentialsExpiredError, NotAuthenticatedError } from '../../errors'; | ||
import { FetchGraphQLClient } from '../../graphql/FetchGraphQLClient'; | ||
import { | ||
FrameEip712Request, | ||
FrameLensManagerEip712Request, | ||
FrameVerifySignature, | ||
} from '../../graphql/types.generated'; | ||
import { requireAuthHeaders, sdkAuthHeaderWrapper } from '../../helpers'; | ||
import { | ||
CreateFrameEip712TypedDataFragment, | ||
FrameLensManagerSignatureResultFragment, | ||
Sdk, | ||
getSdk, | ||
} from './graphql/frames.generated'; | ||
|
||
/** | ||
* Lens Frames | ||
* | ||
* @group LensClient Modules | ||
*/ | ||
export class Frames { | ||
private readonly sdk: Sdk; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
constructor( | ||
context: LensContext, | ||
private readonly authentication: Authentication, | ||
) { | ||
const client = new FetchGraphQLClient(context); | ||
|
||
this.sdk = getSdk(client, sdkAuthHeaderWrapper(authentication)); | ||
} | ||
|
||
/** | ||
* Create a Lens Frame Typed Data to sign by the user wallet | ||
* | ||
* @param request - The request object | ||
* @returns Typed data for Lens Frame request | ||
* | ||
* @example | ||
* ```ts | ||
* const result = await client.frames.createFrameTypedData({ | ||
* actionResponse: '0x0000000000000000000000000000000000000000', | ||
* buttonIndex: 2, | ||
* deadline: 1711038973, | ||
* inputText: 'Hello, World!', | ||
* profileId: '0x01', | ||
* pubId: '0x01-0x01', | ||
* specVersion: FramesEip721TypedDataSpec.OnePointOnePointOne, | ||
* state: '{"counter":1,"idempotency_key":"431b8b38-eb4d-455b"}', | ||
* url: 'https://mylensframe.xyz', | ||
* }); | ||
* ``` | ||
*/ | ||
async createFrameTypedData( | ||
request: FrameEip712Request, | ||
): Promise<CreateFrameEip712TypedDataFragment> { | ||
const response = await this.sdk.CreateFrameTypedData({ request }); | ||
return response.data.result; | ||
} | ||
|
||
async verifyFrameSignature(request: FrameVerifySignature): Promise<boolean> { | ||
const response = await this.sdk.VerifyFrameSignature({ request }); | ||
return response.data.result; | ||
} | ||
|
||
/** | ||
* Sign a Lens Frame Action Data | ||
* | ||
* ⚠️ Requires authenticated LensClient. | ||
* | ||
* @param request - The request object | ||
* @returns Signature result | ||
* | ||
* @example | ||
* ```ts | ||
* const result = await client.frames.signFrameAction({ | ||
* actionResponse: '0x0000000000000000000000000000000000000000', | ||
* buttonIndex: 2, | ||
* inputText: 'Hello, World!', | ||
* profileId: '0x01', | ||
* pubId: '0x01-0x01', | ||
* specVersion: FramesEip721TypedDataSpec.OnePointOnePointOne, | ||
* state: '{"counter":1,"idempotency_key":"431b8b38-eb4d-455b"}', | ||
* url: 'https://mylensframe.xyz', | ||
* }); | ||
* ``` | ||
*/ | ||
async signFrameAction( | ||
request: FrameLensManagerEip712Request, | ||
): PromiseResult< | ||
FrameLensManagerSignatureResultFragment, | ||
CredentialsExpiredError | NotAuthenticatedError | ||
> { | ||
return requireAuthHeaders(this.authentication, async (headers) => { | ||
const result = await this.sdk.SignFrameAction( | ||
{ | ||
request, | ||
}, | ||
headers, | ||
); | ||
|
||
return result.data.result; | ||
}); | ||
} | ||
} |
Oops, something went wrong.