Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorand/opa #145

Merged
merged 3 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/main/kotlin/id/walt/nftkit/rest/AlgorandNftController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ object AlgorandNftController{
fun verifyNftOwnerShipBasedOnCreatorDocs()= document().operation {
it.summary("Verifying NFT ownership based on creator ")
.operationId("verifyNftOwnerShipBasedOnCreator")
.addTagsItem("NFT verification")}
.addTagsItem("NFT verification On Algorand")}
.pathParam<String>("chain") {
it.schema<AlgorandChain>{}}
.pathParam<String>("address"){}
Expand All @@ -186,5 +186,27 @@ object AlgorandNftController{
it.description("Algorand NFT Metadata")
}


fun verifyPolicyOnAlgorand(ctx: Context){
val chain =ctx.pathParam("chain")
val tokenid = ctx.pathParam("token id")
val policyName = ctx.pathParam("policyName")

val result = VerificationService.verifyPolicyAlgorand(Common.getChain(chain) ,tokenid , policyName)
ctx.result(Json.encodeToString(result))

}

fun doVerifyPolicyOnAlgorandDocs()= document().operation {
it.summary("Verify an NFT metadata against a dynamic policy")
.operationId("verifyNftagainstPolicy")
.addTagsItem("NFT verification On Algorand")}
.pathParam<String>("chain") {
it.schema<AlgorandChain>{}}
.pathParam<String>("token id"){}
.pathParam<String>("policyName"){}
.json<String>(200.toString()) {
it.description("Algorand NFT Metadata")
}
}

36 changes: 24 additions & 12 deletions src/main/kotlin/id/walt/nftkit/rest/NftKitApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,8 @@ object NftKitApi {
}
}
path("nft/verifier") {
get(
"chain/{chain}/verifyNftOwnership",
documented(VerificationController.verifyAlgorandNftOwnershipDocs(), VerificationController::verifyAlgorandNftOwnership)
)
get(
"chain/{chain}/verifyNftOwnershipWithTraits",
documented(VerificationController.verifyAlgorandNftOwnershipWithTraitsDocs(), VerificationController::verifyAlgorandNftOwnershipWithTraits)
)
get(
"chain/{chain}/{address}/verifyNftOwnershipBasedOnCreator/{creatorAddress}",
documented(AlgorandNftController.verifyNftOwnerShipBasedOnCreatorDocs(), AlgorandNftController::verifyNftOwnerShipBasedOnCreator)
)


get(
"chain/{chain}/contract/{contractAddress}/verifyNftOwnership",
documented(VerificationController.verifyNftOwnershipDocs(), VerificationController::verifyNftOwnership)
Expand Down Expand Up @@ -409,6 +399,28 @@ object NftKitApi {
)


}
path("algorand"){
get(
"chain/{chain}/verifyNftOwnership",
documented(VerificationController.verifyAlgorandNftOwnershipDocs(), VerificationController::verifyAlgorandNftOwnership)
)
get(
"chain/{chain}/verifyNftOwnershipWithTraits",
documented(VerificationController.verifyAlgorandNftOwnershipWithTraitsDocs(), VerificationController::verifyAlgorandNftOwnershipWithTraits)
)

get(
"chain/{chain}/{address}/verifyNftOwnershipBasedOnCreator/{creatorAddress}",
documented(AlgorandNftController.verifyNftOwnerShipBasedOnCreatorDocs(), AlgorandNftController::verifyNftOwnerShipBasedOnCreator)
)

get(
"chain/{chain}/token/{token id}/policy/{policyName}/verification",
documented(AlgorandNftController.doVerifyPolicyOnAlgorandDocs(), AlgorandNftController::verifyPolicyOnAlgorand)

)

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/id/walt/nftkit/rest/VerificationController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object VerificationController {

fun verifyAlgorandNftOwnershipWithTraitsDocs() = document().operation {
it.summary("NFT ownership verification on algorand with traits")
.operationId("verifyAlgorandNftOwnershipWithTraits").addTagsItem("NFT verification")
.operationId("verifyAlgorandNftOwnershipWithTraits").addTagsItem("NFT verification On Algorand")
}.pathParam<String>("chain") {
it.schema<AlgorandChain> { }
}.queryParam<String>("assetId") {
Expand All @@ -52,7 +52,7 @@ object VerificationController {

fun verifyAlgorandNftOwnershipDocs() = document().operation {
it.summary("NFT ownership verification on algorand")
.operationId("verifyAlgorandNftOwnership").addTagsItem("NFT verification")
.operationId("verifyAlgorandNftOwnership").addTagsItem("NFT verification On Algorand")
}.pathParam<String>("chain") {
it.schema<AlgorandChain> { }
}.queryParam<String>("assetId") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ object VerificationService {
}
}

fun verifyPolicyAlgorand(chain: Chain, tokenId: String, policyName: String): Boolean {
val policy = PolicyRegistry.listPolicies().get(policyName)
if(policy == null) throw Exception("The policy doesn't exist")
val algorandNftmetadata= AlgorandNftService.getNftMetadata(tokenId ,AlgorandChain.valueOf(chain.toString()) )
val nftMetadata = NftMetadataWrapper(algorandNftMetadata= algorandNftmetadata)
return DynamicPolicy.doVerify(policy!!.input, policy.policy, policy.policyQuery, nftMetadata)
}

fun verifyPolicyWithCollectionId(chain: UniqueNetwork, collectionId : String, tokenId: String, policyName: String): Boolean {
val policy = PolicyRegistry.listPolicies().get(policyName)
if(policy == null) throw Exception("The policy doesn't exist")
Expand Down
Loading