-
Notifications
You must be signed in to change notification settings - Fork 81
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
24 changed files
with
1,160 additions
and
28 deletions.
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,5 @@ | ||
--- | ||
"@lens-protocol/client": minor | ||
--- | ||
|
||
**feat:** added Frames module |
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
35 changes: 35 additions & 0 deletions
35
examples/node/scripts/authentication/validateIdentityToken.ts
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,35 @@ | ||
import { LensClient, development } from '@lens-protocol/client'; | ||
|
||
import { setupWallet } from '../shared/setupWallet'; | ||
|
||
async function main() { | ||
const client = new LensClient({ | ||
environment: development, | ||
}); | ||
|
||
const wallet = setupWallet(); | ||
const address = await wallet.getAddress(); | ||
|
||
const managedProfiles = await client.wallet.profilesManaged({ for: wallet.address }); | ||
|
||
if (managedProfiles.items.length === 0) { | ||
throw new Error(`You don't manage any profiles, create one first`); | ||
} | ||
|
||
const { id, text } = await client.authentication.generateChallenge({ | ||
signedBy: address, | ||
for: managedProfiles.items[0].id, | ||
}); | ||
|
||
const signature = await wallet.signMessage(text); | ||
|
||
await client.authentication.authenticate({ id, signature }); | ||
|
||
const identityTokenResult = await client.authentication.getIdentityToken(); | ||
const identityToken = identityTokenResult.unwrap(); | ||
|
||
console.log(`Identity token: `, identityToken); | ||
console.log(`Is identity token valid? `, await client.authentication.verify({ identityToken })); | ||
} | ||
|
||
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,26 @@ | ||
import { FramesEip721TypedDataSpec, LensClient, development } from '@lens-protocol/client'; | ||
|
||
async function main() { | ||
const client = new LensClient({ | ||
environment: development, | ||
}); | ||
|
||
const deadline = new Date(); | ||
deadline.setMinutes(deadline.getMinutes() + 30); | ||
|
||
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); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { FrameVerifySignatureResult, 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); | ||
const profileId = await client.authentication.getProfileId(); | ||
|
||
if (!profileId) { | ||
throw new Error('Profile not authenticated'); | ||
} | ||
|
||
const identityTokenResult = await client.authentication.getIdentityToken(); | ||
const identityToken = identityTokenResult.unwrap(); | ||
|
||
// get signature | ||
const result = await client.frames.signFrameAction({ | ||
actionResponse: '0x0000000000000000000000000000000000000000', | ||
buttonIndex: 2, | ||
inputText: 'Hello, World!', | ||
profileId: profileId, | ||
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; | ||
|
||
// verify | ||
const verifyResult = await client.frames.verifyFrameSignature({ | ||
identityToken, | ||
signature: data.signature, | ||
signedTypedData: data.signedTypedData, | ||
}); | ||
|
||
console.log(`Is signature valid? `, verifyResult === FrameVerifySignatureResult.Verified); | ||
} | ||
|
||
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
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
Oops, something went wrong.