Skip to content

Commit

Permalink
Merge pull request #145 from walt-id/Algorand/opa
Browse files Browse the repository at this point in the history
Algorand/opa
  • Loading branch information
SuperBatata authored Sep 3, 2023
2 parents 98fba96 + cd4f764 commit efc2e54
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
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

0 comments on commit efc2e54

Please sign in to comment.