LogoLogo
ProductsCommunityGitHubShare Feedback
NFT Kit
NFT Kit
  • What is the NFT KIT?
    • Introduction
    • Non-Fungible Tokens (NFTs)
      • NFT | Basics
      • Technologies & Concepts
    • NFT Kit
      • NFT Kit | Basics
        • Overview
        • Functionality
      • NFT Flavors & Ecosystems
      • Architecture
        • Low-Level Service Abstraction
        • Ecosystem Abstraction
        • High-Level Interfaces / APIs
      • Use Cases
  • Getting started
    • Quick Start
  • Ecosystems
    • Ethereum | Polygon | Shimmer
      • Setup
      • NFT | Creation & Management
        • Smart Contract Deployment
        • Minting NFTs
        • Get NFT Metadata
        • Get Account Balance
        • Get Token Owner
        • Get Collection Info
        • Get NFTs by Account
      • NFT | Ownership Verification
        • Ownership Verification
        • Ownership Verification With Traits
      • Smart Contract | Extensions
        • Pausable
        • Burnable
      • Smart Contract | Access Control
        • Ownership
        • Role-Based Access Control
    • Ocean Protocol
      • Setup
      • NFT | Verification
      • NFT | Wallet
      • Architecture
    • Tezos
      • Architecture
      • NFT | Creation & Management
        • Smart Contract
        • Add Minter
        • NFT Minting
        • Fetch NFT metadata
        • Get account NFTs
        • Get contract metadata
      • NFT | Ownership Verification
        • NFT Ownership Verification
        • NFT Ownership Verification Within A Collection
        • NFT Ownership Verification With Traits
      • NFT | Wallet
      • Tutorials
        • Minting NFTs on Tezos
          • Setup
          • New Collection
          • First NFT
          • Verification
          • Wallet
    • Near Protocol
      • Architecture
        • Smart Contract
        • Blockchain NFTs operations
        • NFTs Queries
      • NFT | Creation & Management
        • NEAR Sub-Account
        • Deploy NFT Contract
        • NFT | Minting
      • Querying NFT information controller
        • Get NFTs for account
        • Get NFT By Token Id
        • Get NFT contract metadata
      • NFT | Wallet
      • Tutorials
        • Minting NFT on Near Protocol
          • Near Wallet Creation
          • Setup NFT-Kit
          • Create Sub-account
          • Smart Contract ( Collection )
          • Minting your first NFT
        • NFT Ownership Verification
        • Wallet
    • Polkadot
      • Architecture
      • Query NFTs
        • Unique network
          • Fetching Token id & Collection id
          • Fetching NFT metadata
        • Parachain Networks
          • Fetching Tokens by subscan
          • Fetching EVM ERC721 Collectibles by subscan
      • NFT | Ownership Verification
        • NFT ownership verification
        • NFT ownership verification within a collection
        • NFT ownership verification with traits
      • NFT | Wallet
        • Polkadot parachains
        • Polkadot EVM compatible parachains
    • Flow
      • Architecture
        • Cadence Scripts
        • NFT Operations (FCL)
      • Querying NFT information Controller
        • Get NFTs for an account
        • Get NFTs in Collection
        • Get NFT by Token Id
      • NFT | Ownership Verification
        • NFT ownership verification on Flow
        • NFT ownership verification in collection on Flow
      • NFT | Wallet
        • Flow Blockchain
    • Algorand
      • Architecture
        • Algorand Standard Assets (ASAs)
      • NFT | Creation & Management
        • Account Creation
        • NFT Creation (ARC3)
      • Querying Asset information
        • Get Assets for account
        • Get Asset Details
        • Get NFT Metadata by asset id
        • Get NFT by Asset id
      • NFT | Ownership Verification
        • NFT ownership verification
        • NFT ownership verification with traits
        • NFT ownership verification Based on Creator
        • NFT Metadata verification against a dynamic policy
      • NFT | Wallet
        • Algorand Blockchain
    • IPFS
  • Concepts
    • Soulbound Tokens (SBTs)
    • NFT verification with OPA
  • Configurations
    • Configuration Files
    • Gas Provider
  • Community
    • Discord
    • Twitter
    • Newsletter
    • GitHub Discussions
  • DEVELOPER RELATIONS
    • Roadmap
    • Contribute
    • Share Feedback
    • Contact
  • Product Editions
    • Open Source | Always Free
    • Enterprise | Self-Managed
    • Cloud Platform | Managed
Powered by GitBook
On this page
  • 1. Via REST API
  • Add new policy
  • Get policy list
  • Apply a policy to a NFT
  • 2. Via code
  • Setup
  • Code examples
  • Rego Code Example:

Was this helpful?

Export as PDF
  1. Concepts

NFT verification with OPA

PreviousSoulbound Tokens (SBTs)NextConfiguration Files

Last updated 1 month ago

Was this helpful?

1. Via REST API

Add new policy

After the development of a policy using Rego, we need to add it to the NFT Kit.

API Doc

|

Curl call example

curl -X POST "https://nftkit.walt-test.cloud/v2/nftkit/nft/verifier/policies/create"  
 -H  "Content-Type: application/json" 
 -d "{\"name\":\"string\",\"description\":\"string\",\"input\":{\"additionalProp1\":{},\"additionalProp2\":{},\"additionalProp3\":{}},\"policy\":\"string\",\"policyQuery\":\"string\",\"policyEngine\":\"OPA\"}"

Body parameters:

{
  "name": "string",
  "description": "string",
  "input": {
    "additionalProp1": {},
    "additionalProp2": {},
    "additionalProp3": {}
  },
  "policy": "string",
  "policyQuery": "string",
  "policyEngine": "OPA"
}
  • name: [string] policy name.

  • description: [string] policy description.

  • input: [string] the input parameter of the open policy engine(OPA).

  • policy: [string] the policy Rego code that will be executed by OPA.

  • policyQuery: [string] the query parameter of the open policy engine(OPA).

  • policyEngine: [string] the engine who will run the policy.

Example:

curl -X POST "http://0.0.0.0:7000/v2/nftkit/nft/verifier/policies/create" 
 -H  "Content-Type: application/json" 
 -d "{  \"name\": \"policy 1\",  \"description\": \"policy 1\",  \"input\": {    \"Background\": \"Purple\",    \"Body\": \"Body 11\"  },  \"policy\": \"package app.nftimport future.keywords.ifdefault allow := falseallow if {\tvalid_nft_Background\tvalid_nft_Body}valid_nft_Background if input.Background= data.Backgroundvalid_nft_Body if input.Body= data.Body\",  \"policyQuery\": \"data.app.nft.allow\",  \"policyEngine\": \"OPA\"}"

Rego policy example:

package app.nft

import future.keywords.if

default allow := false


allow if {
	valid_nft_Background
	valid_nft_Body
}


valid_nft_Background if input.Background= data.Background

valid_nft_Body if input.Body= data.Body

Get policy list

Get the list of added policies.

API Doc

Curl call example

curl -X GET "http://0.0.0.0:7000/v2/nftkit/nft/verifier/policies"

Apply a policy to a NFT

Execute a policy against a NFT metadata.

API Doc

Curl call example

curl -X GET "http://0.0.0.0:7000/v2/nftkit/nft/verifier/chain/{{chain}}/contract/{{contract}}/token/{{tokenId}}/policy/{{policyName}}/verification"

Path parameters:

  • chain: [string] chain to work with. Either TEZOS, GHOSTNET, ETHEREUM, POLYGON, GOERLI, MUMBAI , TESTNET or MAINNET .

  • contract: [string] smart contract address

  • tokenId: [string] token id of the NFT

  • policyName: [string] the name of an already-added policy.

Example:

curl -X GET "http://0.0.0.0:7000/v2/nftkit/nft/verifier/chain/TEZOS/contract/KT1U6EHmNxJTkvaWJ4ThczG4FSDaHC21ssvi/token/1462880/policy/policy1/verification" 

2. Via code

Setup

  1. You need to add a path of OPA in the environment variable. When using IntelliJ IDEA:

Code examples

You can run an OPA policy against an NFT metadata from an EVM compatible or Tezos chains.

  • EVM compatible:

val inputs = mutableMapOf("type" to "T1", "model" to "M1",
"reference" to "R1")//in the IDP Kit, inputs parameterexist in idp-Config.json
val policy = "/home/walid/Desktop/walt.id/opa/nft.rego"
/*in the IDP Kit, policy parameter exist in
idp-Config.json.
Path file that contains rego code*/
val query= "data.app.nft.allow" //in the IDP Kit, query parameter exist in idp-Config.json
val nftMetadata = NftService.getNftMetadata(Chain.MUMBAI,
        "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517", BigInteger.valueOf(0))
val nftMetadataWrapper= NftMetadataWrapper(evmNftMetadata = nftMetadata)
val result= DynamicPolicy.doVerify(inputs, policy, query,
        nftMetadataWrapper) //true or false
  • Tezos

val inputs = mutableMapOf("type" to "T1", "model" to "M1",
"reference" to "R1")//in the IDP Kit, inputs parameterexist in idp-Config.json
val policy = "/home/walid/Desktop/walt.id/opa/nft.rego"
/*in the IDP Kit, policy parameter exist in
idp-Config.json.
Path file that contains rego code*/
val query= "data.app.nft.allow" //in the IDP Kit, query parameter exist in idp-Config.json
val nftMetadata = TezosNftService.getNftTezosMetadata(Chain.TEZOS,
    "KT1RCzrLhBpdKXkyasKGpDTCcdbBTipUk77x", "1")
val nftMetadataWrapper= NftMetadataWrapper(tezosNftMetadata = nftMetadata)
val result= DynamicPolicy.doVerify(inputs, policy, query,
        nftMetadataWrapper) //true or false

Rego Code Example:

package app.nft
import future.keywords.if
default allow := false
allow if {
valid_datanft_type
valid_datanft_model
valid_datanft_reference
}
valid_datanft_type if input.type= data.type
valid_datanft_model if input.model= data.model
valid_datanft_reference if input.reference= data.reference

|

|

You need have OPA in your local machine. .

Swagger Doc
ReDoc
Swagger Doc
ReDoc
Swagger Doc
ReDoc
Running OPA instructions