
Security News
Critical Security Vulnerability in React Server Components
React disclosed a CVSS 10.0 RCE in React Server Components and is advising users to upgrade affected packages and frameworks to patched versions now.
@lens-protocol/sdk-gated
Advanced tools
This package enables gated encrypting and decrypting publication metadata compatible with the Lens API.
npm install @lens-protocol/sdk-gated
yarn add @lens-protocol/sdk-gated
Pretty straightforward, instantiate the LensGatedSDK client providing the required parameters.
Make sure you are encrypting valid MetadataV2 objects or you will get errors. See more on valid metadata standards here. To validate metadata using the Lens API before encrypting, see here.
import { Web3Provider } from '@ethersproject/providers'
import {AndCondition, OrCondition, FollowCondition, CollectCondition, EncryptedMetadata, EoaOwnership, Erc20TokenOwnership, MetadataV2, NftOwnership, ProfileOwnership, PublicationMainFocus, ContractType, ScalarOperator, LensGatedSDK, LensEnvironment, } from '@lens-protocol/sdk-gated'
let metadata: MetadataV2 = {
version: '2.0.0',
name: 'name',
description: 'description',
attributes: [],
content: 'content',
metadata_id: '1',
appId: 'app_id',
mainContentFocus: PublicationMainFocus.TextOnly,
locale: 'en',
}
const uploadMetadataHandler = async (data: EncryptedMetadata): Promise<string> => {
// Upload the encrypted metadata to your server and return a publicly accessible url
return Promise.resolve('test')
}
const nftAccessCondition: NftOwnership = {
contractAddress: '0x0000000000000000000000000000000000000000', // the address of the NFT collection, make sure it is a valid address depending on the chosen network
chainID: 80001, // the chain ID of the network the NFT collection is deployed on;
contractType: ContractType.Erc721, // the type of the NFT collection, ERC721 and ERC1155 are supported
tokenIds: ['1', '2', '3'], // OPTIONAL - the token IDs of the NFTs that grant access to the metadata, if ommitted, owning any NFT from the collection will grant access
}
const eoaAccessCondition: EoaOwnership = {
address: '0x0000000000000000000000000000000000000000', // the address of the EOA that grants access to the metadata
chainID: 80001, // the chain ID of the network
}
const erc20AccessCondition: Erc20TokenOwnership = {
contractAddress: '0x0000000000000000000000000000000000000000', // the address of the ERC20 token that signers should own
chainID: 80001, // the chain ID of the network
amount: '1000000000000000000', // the amount of the ERC20 token that grants access to the metadata
decimals: 18, // the decimals of the ERC20 token that grants access to the metadata
condition: ScalarOperator.GreaterThanOrEqual // the condition that must be met to grant access to the metadata, supported conditions are: '==', '!=', '>', '<', '>=', '<='
}
const profileAccessCondition: ProfileOwnership = {
profileId: '0x01'
}
const followAccessCondition: FollowCondition = {
profileId: '0x01',
}
const collectAccessCondition: CollectCondition = {
publicationId: '0x01-0x01',
}
const andCondition: AndCondition = {
criteria: [
{
token: erc20AccessCondition
},
{
follow: followAccessCondition
}
]
}
const orCondition: OrCondition = {
criteria: [
{
collect: collectAccessCondition,
},
{
profile: profileAccessCondition
}
]
}
(async () => {
const sdk = await LensGatedSDK.create({
provider: new Web3Provider(window.ethereum), // or any ethers Provider
signer: signer, // a wallet or JsonRpcSigner from wagmi or similar
env: LensEnvironment.Mumbai,
});
// this must be called anytime you change networks, exposed so you can add this to your Web3Provider event handling
// but not necessary to call explicitly
await sdk.connect({
address: '0x1234123412341234123412341234123412341234', // your signer's wallet address
env: LensEnvironment.Polygon
})
const { error, contentURI, encryptedMetadata } = await sdk.gated.encryptMetadata(
metadata,
'0x01', // the signed in user's profile id
{
nft: nftAccessCondition
}, // or any other access condition object
uploadMetadataHandler,
)
console.log(contentURI)
// contentURI is ready to be used in the `contentURI` field of your `createPostTypedMetadata` call
// also exposing the encrypted metadata in case you want to do something with it
// ... create post using the Lens API ...
// decrypt metadata
// in most usecases you will fetch the metadata from the Lens API `getPublications` or similar call that returns
// publication content,then for content with `isGated` = true, you can apply the decryption function to the
// publication's metadata object
const { decrypted } = await sdk.gated.decryptMetadata(encryptedMetadata)
// deinitializes variables and deletes the SIWE-compatible signature from storage
await sdk.disconnect();
})();
The currently supported access control models are:
FAQs
SDK for encrypting and decrypting gated content on Lens Protocol
The npm package @lens-protocol/sdk-gated receives a total of 1 weekly downloads. As such, @lens-protocol/sdk-gated popularity was classified as not popular.
We found that @lens-protocol/sdk-gated demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
React disclosed a CVSS 10.0 RCE in React Server Components and is advising users to upgrade affected packages and frameworks to patched versions now.

Research
/Security News
We spotted a wave of auto-generated “elf-*” npm packages published every two minutes from new accounts, with simple malware variants and early takedowns underway.

Security News
TypeScript 6.0 will be the last JavaScript-based major release, as the project shifts to the TypeScript 7 native toolchain with major build speedups.