From 6a284a20a7ad1861a25a15c5c616826e4b589803 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 11:06:54 +0100 Subject: [PATCH 01/25] added polkadot.js dependencies --- web/waltid-idpkit-ui/package.json | 106 ++++++++++++++++-------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/web/waltid-idpkit-ui/package.json b/web/waltid-idpkit-ui/package.json index 867fe03..0555506 100644 --- a/web/waltid-idpkit-ui/package.json +++ b/web/waltid-idpkit-ui/package.json @@ -1,53 +1,57 @@ { - "name": "waltid-idpkit-ui", - "version": "1.0.0", - "private": true, - "scripts": { - "dev": "nuxt", - "build": "nuxt build", - "start": "nuxt start", - "generate": "nuxt generate" - }, - "dependencies": { - "@airgap/beacon-sdk": "^3.3.0", - "@nuxtjs/axios": "^5.13.6", - "@taquito/beacon-wallet": "^15.0.0", - "@taquito/taquito": "^15.0.0", - "@walletconnect/web3-provider": "^1.8.0", - "bootstrap": "^4.6.2", - "bootstrap-vue": "^2.23.1", - "core-js": "^3.26.0", - "ethers": "^5.7.2", - "nuxt": "^2.15.8", - "qrious": "^4.0.2", - "vue": "2.7.14", - "vue-server-renderer": "2.7.14", - "vue-template-compiler": "2.7.14", - "web3modal": "^1.9.9", - "webpack": "^4.46.0", - "@near-wallet-selector/coin98-wallet": "^7.6.0", - "@near-wallet-selector/core": "^7.6.0", - "@near-wallet-selector/default-wallets": "^7.6.0", - "@near-wallet-selector/here-wallet": "^7.6.0", - "@near-wallet-selector/ledger": "^7.6.0", - "@near-wallet-selector/math-wallet": "^7.6.0", - "@near-wallet-selector/meteor-wallet": "^7.6.0", - "@near-wallet-selector/modal-ui": "^7.6.0", - "@near-wallet-selector/my-near-wallet": "^7.6.0", - "@near-wallet-selector/narwallets": "^7.6.0", - "@near-wallet-selector/near-wallet": "^7.6.0", - "@near-wallet-selector/nearfi": "^7.6.0", - "@near-wallet-selector/neth": "^7.6.0", - "@near-wallet-selector/nightly": "^7.6.0", - "@near-wallet-selector/nightly-connect": "^7.6.0", - "@near-wallet-selector/opto-wallet": "^7.6.0", - "@near-wallet-selector/sender": "^7.6.0", - "@near-wallet-selector/wallet-connect": "^7.6.0", - "@near-wallet-selector/welldone-wallet": "^7.6.0", - "@near-wallet-selector/xdefi": "^7.6.0", - "near-api-js": "^1.1.0" - }, - "devDependencies": { - "@nuxt/types": "~2.15.8" - } + "name": "waltid-idpkit-ui", + "version": "1.0.0", + "private": true, + "scripts": { + "dev": "nuxt", + "build": "nuxt build", + "start": "nuxt start", + "generate": "nuxt generate" + }, + "dependencies": { + "@airgap/beacon-sdk": "^3.3.0", + "@near-wallet-selector/coin98-wallet": "^7.6.0", + "@near-wallet-selector/core": "^7.6.0", + "@near-wallet-selector/default-wallets": "^7.6.0", + "@near-wallet-selector/here-wallet": "^7.6.0", + "@near-wallet-selector/ledger": "^7.6.0", + "@near-wallet-selector/math-wallet": "^7.6.0", + "@near-wallet-selector/meteor-wallet": "^7.6.0", + "@near-wallet-selector/modal-ui": "^7.6.0", + "@near-wallet-selector/my-near-wallet": "^7.6.0", + "@near-wallet-selector/narwallets": "^7.6.0", + "@near-wallet-selector/near-wallet": "^7.6.0", + "@near-wallet-selector/nearfi": "^7.6.0", + "@near-wallet-selector/neth": "^7.6.0", + "@near-wallet-selector/nightly": "^7.6.0", + "@near-wallet-selector/nightly-connect": "^7.6.0", + "@near-wallet-selector/opto-wallet": "^7.6.0", + "@near-wallet-selector/sender": "^7.6.0", + "@near-wallet-selector/wallet-connect": "^7.6.0", + "@near-wallet-selector/welldone-wallet": "^7.6.0", + "@near-wallet-selector/xdefi": "^7.6.0", + "@nuxtjs/axios": "^5.13.6", + "@open-wc/webpack-import-meta-loader": "^0.4.7", + "@polkadot/api": "^10.3.2", + "@polkadot/extension-dapp": "^0.45.5", + "@taquito/beacon-wallet": "^15.0.0", + "@taquito/taquito": "^15.0.0", + "@vue/cli-plugin-babel": "^5.0.8", + "@walletconnect/web3-provider": "^1.8.0", + "bootstrap": "^4.6.2", + "bootstrap-vue": "^2.23.1", + "core-js": "^3.26.0", + "ethers": "^5.7.2", + "near-api-js": "^1.1.0", + "nuxt": "^2.15.8", + "qrious": "^4.0.2", + "vue": "2.7.14", + "vue-server-renderer": "2.7.14", + "vue-template-compiler": "2.7.14", + "web3modal": "^1.9.9", + "webpack": "^4.46.0" + }, + "devDependencies": { + "@nuxt/types": "~2.15.8" + } } From 124f266fefd9c3de3391b1e61ecb927cd95f1eb6 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 11:07:30 +0100 Subject: [PATCH 02/25] extending support of webpack to polkadot dependencies --- web/waltid-idpkit-ui/nuxt.config.js | 87 ++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/web/waltid-idpkit-ui/nuxt.config.js b/web/waltid-idpkit-ui/nuxt.config.js index b0df854..17d717a 100644 --- a/web/waltid-idpkit-ui/nuxt.config.js +++ b/web/waltid-idpkit-ui/nuxt.config.js @@ -1,28 +1,28 @@ export default { // Target: https://go.nuxtjs.dev/config-target - target: 'static', + target: "static", ssr: false, // Global page headers: https://go.nuxtjs.dev/config-head head: { - title: 'waltid-idpkit-ui', + title: "waltid-idpkit-ui", htmlAttrs: { - lang: 'en' + lang: "en", }, meta: [ - {charset: 'utf-8'}, - {name: 'viewport', content: 'width=device-width, initial-scale=1'}, - {hid: 'description', name: 'description', content: ''}, - {name: 'format-detection', content: 'telephone=no'} + { charset: "utf-8" }, + { + name: "viewport", + content: "width=device-width, initial-scale=1", + }, + { hid: "description", name: "description", content: "" }, + { name: "format-detection", content: "telephone=no" }, ], - link: [ - {rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'} - ] + link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }], }, // Global CSS: https://go.nuxtjs.dev/config-css - css: [ - "@near-wallet-selector/modal-ui/styles.css" ], + css: ["@near-wallet-selector/modal-ui/styles.css"], // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins plugins: [], @@ -36,28 +36,65 @@ export default { // Modules: https://go.nuxtjs.dev/config-modules modules: [ // https://go.nuxtjs.dev/bootstrap - 'bootstrap-vue/nuxt', - '@nuxtjs/axios' + "bootstrap-vue/nuxt", + "@nuxtjs/axios", ], // Build Configuration: https://go.nuxtjs.dev/config-build - build: {}, + build: { + babel: { + compact: true, + }, + extend(config, { isClient }) { + // Extend only webpack config for client-bundle + if (isClient) { + config.devtool = "source-map"; + } + config.module.rules.push( + { + test: /\.js$/, + loader: require.resolve( + "@open-wc/webpack-import-meta-loader" + ), + exclude: /\.vue$/, + }, + { + test: /\.m?js$/, + include: /node_modules[/\\|]@polkadot/i, + use: { + loader: "babel-loader", + options: { + presets: [ + "@babel/preset-env", + "@vue/cli-plugin-babel/preset", + ], + plugins: [ + "@babel/plugin-proposal-private-methods", + "@babel/plugin-proposal-class-properties", + "@babel/plugin-proposal-object-rest-spread", + ], + }, + }, + } + ); + }, + }, generate: { - dir: 'dist' + dir: "dist", }, axios: { - proxy: true // Can be also an object with default options + proxy: true, // Can be also an object with default options }, -// publicRuntimeConfig: { -// verifierAddress: process.env.VERIFIER_ADDRESS || 'http://localhost:8080/', -// apiAddress: process.env.API_ADDRESS || 'http://localhost:8080/' -// }, + // publicRuntimeConfig: { + // verifierAddress: process.env.VERIFIER_ADDRESS || 'http://localhost:8080/', + // apiAddress: process.env.API_ADDRESS || 'http://localhost:8080/' + // }, proxy: { - '/verifier-api/': "http://localhost:8080/", - '/api/': "http://localhost:8080/" - } -} + "/verifier-api/": "http://localhost:8080/", + "/api/": "http://localhost:8080/", + }, +}; From a477b1332d65ed1dc89f0a9ef14950d37ea69dd7 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 11:08:00 +0100 Subject: [PATCH 03/25] connect polkadot account and sign message --- web/waltid-idpkit-ui/pages/connect-wallet.vue | 458 ++++++++++-------- 1 file changed, 255 insertions(+), 203 deletions(-) diff --git a/web/waltid-idpkit-ui/pages/connect-wallet.vue b/web/waltid-idpkit-ui/pages/connect-wallet.vue index 55d7d37..0f2d709 100644 --- a/web/waltid-idpkit-ui/pages/connect-wallet.vue +++ b/web/waltid-idpkit-ui/pages/connect-wallet.vue @@ -1,239 +1,291 @@ From 990ef8cb170c02493bca2ee6c49d8595bdcfad6e Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 14:11:53 +0100 Subject: [PATCH 04/25] added Polkadot nft metadata --- src/main/kotlin/id/walt/idp/config/ClaimConfig.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/id/walt/idp/config/ClaimConfig.kt b/src/main/kotlin/id/walt/idp/config/ClaimConfig.kt index b5cff44..44bf459 100644 --- a/src/main/kotlin/id/walt/idp/config/ClaimConfig.kt +++ b/src/main/kotlin/id/walt/idp/config/ClaimConfig.kt @@ -57,7 +57,9 @@ class NFTClaimMapping( val claimValue = when(verificationResult.nftresponseVerificationResult.ecosystem) { ChainEcosystem.EVM -> verificationResult.nftresponseVerificationResult.metadata?.evmNftMetadata?.attributes?.firstOrNull { a -> a.trait_type == mappingDefinition.trait }?.value ChainEcosystem.TEZOS -> verificationResult.nftresponseVerificationResult.metadata?.tezosNftMetadata?.attributes?.firstOrNull { a -> a.name == mappingDefinition.trait }?.value - ChainEcosystem.NEAR -> verificationResult.nftresponseVerificationResult.metadata?.nearNftMetadata?.metadata?.let { NFTManager.getNearNftAttributeValue(it, mappingDefinition.trait) } + ChainEcosystem.NEAR -> verificationResult.nftresponseVerificationResult.metadata?.nearNftMetadata?.metadata?.let { NFTManager.getNearNftAttributeValue(it, mappingDefinition.trait) + } + ChainEcosystem.POLKADOT -> verificationResult.nftresponseVerificationResult.metadata?.uniqueNftMetadata?.attributes?.let { a -> a.firstOrNull { a -> a.name == mappingDefinition.trait }?.value } }?: throw BadRequestResponse("Requested nft metadata trait not found in verification response") claimBuilder.claim(mappingDefinition.trait, claimValue) From 4a2ec7cc1b6f6f45a3446a8db7195853e49c1639 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 14:12:24 +0100 Subject: [PATCH 05/25] created sign in with polkadot file --- .../kotlin/id/walt/idp/siwe/siwpManager.kt | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/main/kotlin/id/walt/idp/siwe/siwpManager.kt diff --git a/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt new file mode 100644 index 0000000..82fd18c --- /dev/null +++ b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt @@ -0,0 +1,71 @@ +package id.walt.idp.siwe + +import id.walt.idp.config.IDPConfig +import id.walt.idp.oidc.OIDCSession +import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.engine.cio.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.plugins.logging.* +import io.ktor.client.request.* +import io.ktor.serialization.kotlinx.json.* +import kotlinx.coroutines.runBlocking +import kotlinx.serialization.json.Json +import java.net.URLEncoder +import java.nio.charset.StandardCharsets + +object SiwpManager { + val client = HttpClient(CIO.create { requestTimeout = 0 }) { + install(ContentNegotiation) { + json(Json { + ignoreUnknownKeys = true + }) + } + install(Logging) { + logger = Logger.SIMPLE + level = LogLevel.ALL + } + expectSuccess = false + } + fun verifySignature(session: OIDCSession, message: String, publicKey: String, signature: String): Boolean{ + println("this is the message: $message") + println("this is the public key: $publicKey") + println("this is the signature: $signature") + + val nonce= getNonce(message) + if (session.siweSession?.nonce != nonce) { + return false; + } + if (SiweManager.nonceBlacklists.contains(nonce)) { + return false + } + SiweManager.nonceBlacklists.add(nonce) + + + return runBlocking { + val result = client.get("${IDPConfig.config.jsProjectExternalUrl}/Polkadot/signature/verification?publicKey=${publicKey}&signature=${signature}&message=${URLEncoder.encode(message, StandardCharsets.UTF_8)}") { + }.body() + return@runBlocking result + } + } + + + fun getAddress(message:String): String{ + val address= message.split(" .").get(0).split(":").last().trim() + return address + } + + fun getNonce(message: String): String{ + val nonce= message.split(".").last().split(":").last().trim() + return nonce + } + + fun getPublicKey(message: String): String{ + val publicKeyPrefix = "Public Key: ed25519:" + val startIndex = message.indexOf(publicKeyPrefix) + publicKeyPrefix.length + val endIndex = message.indexOf(".", startIndex) + return message.substring(startIndex, endIndex) + } + + +} From e2e304d6709a326b4579f234262a56ea535bdc3e Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 14:13:19 +0100 Subject: [PATCH 06/25] added polkadot for NFT verification --- src/main/kotlin/id/walt/idp/nfts/NFTManager.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/id/walt/idp/nfts/NFTManager.kt b/src/main/kotlin/id/walt/idp/nfts/NFTManager.kt index 5f28703..acc981a 100644 --- a/src/main/kotlin/id/walt/idp/nfts/NFTManager.kt +++ b/src/main/kotlin/id/walt/idp/nfts/NFTManager.kt @@ -79,7 +79,7 @@ object NFTManager { Common.getEVMChain(tokenConstraint.chain!!.toString()), tokenConstraint.smartContractAddress!!, account.trim() )?.compareTo(BigInteger("0")) == 1 - ChainEcosystem.TEZOS, ChainEcosystem.NEAR -> VerificationService.verifyNftOwnershipWithinCollection( + ChainEcosystem.TEZOS, ChainEcosystem.NEAR , ChainEcosystem.POLKADOT-> VerificationService.verifyNftOwnershipWithinCollection( tokenConstraint.chain!!, tokenConstraint.smartContractAddress!!,account) } @@ -117,7 +117,8 @@ object NFTManager { NearNftService.getNFTforAccount( account, it, NearChain.valueOf( tokenConstraint.chain!!.toString() ))}?.get(0) - else null + else null, + ) } From 986e3e7e28cd3f8f4e80e04e570763523907be9e Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 14:14:45 +0100 Subject: [PATCH 07/25] added polkadot ecosystem --- src/main/kotlin/id/walt/idp/nfts/NFTController.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt index 817c110..d0fd5a4 100644 --- a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt +++ b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt @@ -6,6 +6,7 @@ import id.walt.idp.oidc.OIDCManager import id.walt.idp.oidc.ResponseVerificationResult import id.walt.idp.siwe.SiweManager import id.walt.idp.siwe.SiwnManager +import id.walt.idp.siwe.SiwpManager import id.walt.idp.siwe.SiwtManager import id.walt.siwe.SiweRequest import id.walt.siwe.eip4361.Eip4361Message @@ -77,6 +78,14 @@ object NFTController { print("is address " + address) SiwnManager.verifySignature(session!!, message, publicKey, signature) } + ChainEcosystem.POLKADOT -> { + val publicKey = SiwpManager.getPublicKey(message) + print( "is the public key" + publicKey ) + address = SiwpManager.getAddress(message) + print("is address " + address) + SiwpManager.verifySignature(session!!, message, publicKey, signature) + } + } if(!siwxResult) { From 86b91b245e043263d06d77ed9a05be2cfb673d82 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 14:15:11 +0100 Subject: [PATCH 08/25] added polkadot to ChainEcosystem --- src/main/kotlin/id/walt/idp/nfts/NFTClaims.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/id/walt/idp/nfts/NFTClaims.kt b/src/main/kotlin/id/walt/idp/nfts/NFTClaims.kt index 63fed0c..f01f64c 100644 --- a/src/main/kotlin/id/walt/idp/nfts/NFTClaims.kt +++ b/src/main/kotlin/id/walt/idp/nfts/NFTClaims.kt @@ -17,7 +17,7 @@ data class NftTokenConstraint( ) enum class ChainEcosystem { - EVM, TEZOS, NEAR + EVM, TEZOS, NEAR , POLKADOT } data class NftTokenClaim( From 86ab5843eedef8135e46c6115a122622bb8c5f44 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 14:15:32 +0100 Subject: [PATCH 09/25] extended idp config to support polkadot --- config/idp-config.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/idp-config.json b/config/idp-config.json index d11f55c..11d605f 100644 --- a/config/idp-config.json +++ b/config/idp-config.json @@ -69,7 +69,7 @@ } ], "default_nft_token_claim": { - "ecosystems": [ "EVM", "TEZOS", "NEAR" ], + "ecosystems": [ "EVM", "TEZOS", "NEAR" ,"POLKADOT"], "nftTokenContraints": { "EVM": { "chain": "POLYGON", @@ -85,6 +85,12 @@ "chain": "TESTNET", "factorySmartContractAddress": "", "smartContractAddress": "demo.khaled_lightency1.testnet" + }, + "POLKADOT": { + "chain": "OPAL", + "factorySmartContractAddress": "", + "smartContractAddress": "" + } } }, From bed3e626fb64b2492d55c6746b8456bcd01d006e Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 10 Apr 2023 14:15:55 +0100 Subject: [PATCH 10/25] updated nft kit dependency --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d2ff177..9d21b8f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -62,7 +62,7 @@ dependencies { testImplementation("io.kotest:kotest-assertions-json:5.5.0") // NftKit - implementation("id.walt:waltid-nftkit:1.0.0") + implementation("id.walt:waltid-nftkit:1.2304041249.0") // HTTP / Client: ktor implementation("io.ktor:ktor-client-core:2.0.0") From 3eb671ae1f222c3724731b0cc373699403345af1 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 01:20:10 +0100 Subject: [PATCH 11/25] removed comment --- src/main/kotlin/id/walt/idp/nfts/NFTController.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt index d0fd5a4..9caa04c 100644 --- a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt +++ b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt @@ -80,9 +80,9 @@ object NFTController { } ChainEcosystem.POLKADOT -> { val publicKey = SiwpManager.getPublicKey(message) - print( "is the public key" + publicKey ) + address = SiwpManager.getAddress(message) - print("is address " + address) + SiwpManager.verifySignature(session!!, message, publicKey, signature) } From 6e755ea99205a2ed4783d6eccb4bf5c4e785540a Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 01:20:31 +0100 Subject: [PATCH 12/25] updated get public key function --- .../kotlin/id/walt/idp/siwe/siwpManager.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt index 82fd18c..ce8ee0e 100644 --- a/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt +++ b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt @@ -28,9 +28,9 @@ object SiwpManager { expectSuccess = false } fun verifySignature(session: OIDCSession, message: String, publicKey: String, signature: String): Boolean{ - println("this is the message: $message") - println("this is the public key: $publicKey") - println("this is the signature: $signature") + println("this is the message yarhem bouk: $message\n") + println("this is the public key: $publicKey\n") + println("this is the signature: $signature\n") val nonce= getNonce(message) if (session.siweSession?.nonce != nonce) { @@ -43,7 +43,7 @@ object SiwpManager { return runBlocking { - val result = client.get("${IDPConfig.config.jsProjectExternalUrl}/Polkadot/signature/verification?publicKey=${publicKey}&signature=${signature}&message=${URLEncoder.encode(message, StandardCharsets.UTF_8)}") { + val result = client.get("${IDPConfig.config.jsProjectExternalUrl}/Polkadot/test?publicKey=${publicKey}&signature=${signature}&message=${URLEncoder.encode(message, StandardCharsets.UTF_8)}") { }.body() return@runBlocking result } @@ -52,19 +52,23 @@ object SiwpManager { fun getAddress(message:String): String{ val address= message.split(" .").get(0).split(":").last().trim() + println("this is the address waaaa: $address\n") return address } fun getNonce(message: String): String{ val nonce= message.split(".").last().split(":").last().trim() + println("this is the nonce waaaa: $nonce\n") return nonce } fun getPublicKey(message: String): String{ - val publicKeyPrefix = "Public Key: ed25519:" - val startIndex = message.indexOf(publicKeyPrefix) + publicKeyPrefix.length - val endIndex = message.indexOf(".", startIndex) - return message.substring(startIndex, endIndex) + val startIndex = message.indexOf("Public Key: ") + + + val endIndex = message.indexOf(" ", startIndex + 12) + + return message.substring(startIndex + 12, endIndex) } From 6a195da8e5628984e78448dfac4280569fb119a7 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 03:08:12 +0100 Subject: [PATCH 13/25] removed unnecessary prints --- src/main/kotlin/id/walt/idp/siwe/siwpManager.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt index ce8ee0e..3d36654 100644 --- a/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt +++ b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt @@ -28,9 +28,6 @@ object SiwpManager { expectSuccess = false } fun verifySignature(session: OIDCSession, message: String, publicKey: String, signature: String): Boolean{ - println("this is the message yarhem bouk: $message\n") - println("this is the public key: $publicKey\n") - println("this is the signature: $signature\n") val nonce= getNonce(message) if (session.siweSession?.nonce != nonce) { @@ -52,13 +49,12 @@ object SiwpManager { fun getAddress(message:String): String{ val address= message.split(" .").get(0).split(":").last().trim() - println("this is the address waaaa: $address\n") return address } fun getNonce(message: String): String{ val nonce= message.split(".").last().split(":").last().trim() - println("this is the nonce waaaa: $nonce\n") + return nonce } From ff7fa3485be77c35ddda54fc715ca2826f87b907 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 03:08:31 +0100 Subject: [PATCH 14/25] clean code --- src/main/kotlin/id/walt/idp/siwe/SiwnManager.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/id/walt/idp/siwe/SiwnManager.kt b/src/main/kotlin/id/walt/idp/siwe/SiwnManager.kt index 99ffb18..ed7e97c 100644 --- a/src/main/kotlin/id/walt/idp/siwe/SiwnManager.kt +++ b/src/main/kotlin/id/walt/idp/siwe/SiwnManager.kt @@ -33,9 +33,7 @@ object SiwnManager { expectSuccess = false } fun verifySignature(session: OIDCSession, message: String, publicKey: String, signature: String): Boolean{ - println("this is the message: $message") - println("this is the public key: $publicKey") - println("this is the signature: $signature") + val nonce= getNonce(message) if (session.siweSession?.nonce != nonce) { From e5724b0167d515e7b841b2679d5c779ac62e1fe6 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 03:08:59 +0100 Subject: [PATCH 15/25] added build for polkadot lib --- web/waltid-idpkit-ui/nuxt.config.js | 40 ++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/web/waltid-idpkit-ui/nuxt.config.js b/web/waltid-idpkit-ui/nuxt.config.js index 87b20cf..ec39f8b 100644 --- a/web/waltid-idpkit-ui/nuxt.config.js +++ b/web/waltid-idpkit-ui/nuxt.config.js @@ -42,7 +42,45 @@ export default { ], // Build Configuration: https://go.nuxtjs.dev/config-build - build: {}, + build: { + babel: { + compact: true, + }, + extend(config, { isClient }) { + // Extend only webpack config for client-bundle + if (isClient) { + config.devtool = "source-map"; + } + config.module.rules.push( + { + test: /\.js$/, + loader: require.resolve( + "@open-wc/webpack-import-meta-loader" + ), + exclude: /\.vue$/, + }, + { + test: /\.m?js$/, + include: /node_modules[/\\|]@polkadot/i, + use: { + loader: "babel-loader", + options: { + presets: [ + "@babel/preset-env", + "@vue/cli-plugin-babel/preset", + ], + plugins: [ + "@babel/plugin-proposal-private-methods", + "@babel/plugin-proposal-class-properties", + "@babel/plugin-proposal-object-rest-spread", + ], + }, + }, + } + ); + }, + }, + generate: { dir: 'dist' From 501c95f9f175153a93e9dd85448cc4d73fb7ebc5 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 03:09:18 +0100 Subject: [PATCH 16/25] removed unused variable --- src/main/kotlin/id/walt/idp/nfts/NFTController.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt index 9caa04c..8be878e 100644 --- a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt +++ b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt @@ -40,12 +40,11 @@ object NFTController { } fun nftVerification(ctx: Context) { - val test = "TESTNET"; val sessionId = ctx.queryParam("session") ?: throw BadRequestResponse("Session not specified") val message = ctx.queryParam("message") ?: throw BadRequestResponse("Message not specified") val signature = ctx.queryParam("signature") ?: throw BadRequestResponse("Signature not specified") - val ecosystem = ctx.queryParam("ecosystem")?.let { ChainEcosystem.valueOf(it.toUpperCase()) } ?: throw BadRequestResponse("Ecosystem not specified") + val ecosystem = ctx.queryParam("ecosystem")?.let { ChainEcosystem.valueOf(it.uppercase()) } ?: throw BadRequestResponse("Ecosystem not specified") val session = OIDCManager.getOIDCSession(sessionId) From bb10c1cbb6f8a412a389f0f7e0e311a8b3bee6c3 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 03:09:39 +0100 Subject: [PATCH 17/25] added smart contract to opal network --- config/idp-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/idp-config.json b/config/idp-config.json index 11d605f..3e0be6c 100644 --- a/config/idp-config.json +++ b/config/idp-config.json @@ -89,7 +89,7 @@ "POLKADOT": { "chain": "OPAL", "factorySmartContractAddress": "", - "smartContractAddress": "" + "smartContractAddress": "5GTmz6Vc7tXsbiD6ujxyt8Yf17FnygJLcrBqvduU3c8NwmHP" } } From f20ffaa8c1b41be3e8f2ccd63d349eaec3aafb1e Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 13 Apr 2023 03:10:07 +0100 Subject: [PATCH 18/25] fixed redirect path --- web/waltid-idpkit-ui/pages/connect-wallet.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/waltid-idpkit-ui/pages/connect-wallet.vue b/web/waltid-idpkit-ui/pages/connect-wallet.vue index 0f2d709..4aa59b6 100644 --- a/web/waltid-idpkit-ui/pages/connect-wallet.vue +++ b/web/waltid-idpkit-ui/pages/connect-wallet.vue @@ -277,7 +277,7 @@ Nonce: ${nonce}`; console.log("signature", signature); const urlSignature = encodeURIComponent(signature); console.log("urlSignature", urlSignature); - window.location = `${redirect_uri}?session=${session_id}&ecosystem=NEAR&message=${message}&signature=${urlSignature}`; + window.location = `${redirect_uri}?session=${session_id}&ecosystem=POLKADOT&message=${message}&signature=${urlSignature}`; } }, }, From 418f58e7a8ba3b482e82655cd23d5fbc17e15aa8 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 17 Apr 2023 02:26:35 +0100 Subject: [PATCH 19/25] fixed url --- src/main/kotlin/id/walt/idp/siwe/siwpManager.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt index 3d36654..babd0e7 100644 --- a/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt +++ b/src/main/kotlin/id/walt/idp/siwe/siwpManager.kt @@ -28,7 +28,6 @@ object SiwpManager { expectSuccess = false } fun verifySignature(session: OIDCSession, message: String, publicKey: String, signature: String): Boolean{ - val nonce= getNonce(message) if (session.siweSession?.nonce != nonce) { return false; From 05b71a070d5bd15d13d53f07c69b60a2a50fb924 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 17 Apr 2023 02:28:42 +0100 Subject: [PATCH 20/25] fixed signature encoding in url --- web/waltid-idpkit-ui/pages/connect-wallet.vue | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/web/waltid-idpkit-ui/pages/connect-wallet.vue b/web/waltid-idpkit-ui/pages/connect-wallet.vue index 4aa59b6..2d18e6d 100644 --- a/web/waltid-idpkit-ui/pages/connect-wallet.vue +++ b/web/waltid-idpkit-ui/pages/connect-wallet.vue @@ -269,15 +269,20 @@ Nonce: ${nonce}`; if (!!signRaw) { // after making sure that signRaw is defined // we can use it to sign our message - const { signature } = await signRaw({ + const signature = await signRaw({ address: account.address, data: stringToHex(message), - type: "payload", + type: "bytes", }); - console.log("signature", signature); - const urlSignature = encodeURIComponent(signature); - console.log("urlSignature", urlSignature); - window.location = `${redirect_uri}?session=${session_id}&ecosystem=POLKADOT&message=${message}&signature=${urlSignature}`; + + const urlSignature = encodeURIComponent(signature.signature); + + const urlMessage = encodeURIComponent(message); + + + let url = `${redirect_uri}?session=${session_id}&ecosystem=Polkadot&message=${urlMessage}&signature=${urlSignature}`; + + window.location = url; } }, }, From 047301e069d467403c7bdccf4bc4be80f80dd652 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Mon, 17 Apr 2023 02:28:58 +0100 Subject: [PATCH 21/25] fixed signature encoding in url --- src/main/kotlin/id/walt/idp/nfts/NFTController.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt index 8be878e..e935333 100644 --- a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt +++ b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt @@ -42,9 +42,13 @@ object NFTController { fun nftVerification(ctx: Context) { val sessionId = ctx.queryParam("session") ?: throw BadRequestResponse("Session not specified") + print("Session ID: $sessionId") val message = ctx.queryParam("message") ?: throw BadRequestResponse("Message not specified") - val signature = ctx.queryParam("signature") ?: throw BadRequestResponse("Signature not specified") + print("Message: $message") val ecosystem = ctx.queryParam("ecosystem")?.let { ChainEcosystem.valueOf(it.uppercase()) } ?: throw BadRequestResponse("Ecosystem not specified") + print("Ecosystem: $ecosystem") + val signature = ctx.queryParam("signature") ?: throw BadRequestResponse("Signature not specified") + print("Signature: $signature") val session = OIDCManager.getOIDCSession(sessionId) @@ -72,9 +76,9 @@ object NFTController { } ChainEcosystem.NEAR -> { val publicKey = SiwnManager.getPublicKey(message) - print( "is the public key" + publicKey ) + print("Public Key: $publicKey") address = SiwnManager.getAddress(message) - print("is address " + address) + print("Address: $address") SiwnManager.verifySignature(session!!, message, publicKey, signature) } ChainEcosystem.POLKADOT -> { From 4aec7da9a9149e185336cb2bc01c75a030694f2c Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 20 Apr 2023 13:47:44 +0100 Subject: [PATCH 22/25] added indexers endpoints in config file --- src/main/resources/walt-default.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/walt-default.yaml b/src/main/resources/walt-default.yaml index 305a852..77a8088 100644 --- a/src/main/resources/walt-default.yaml +++ b/src/main/resources/walt-default.yaml @@ -28,6 +28,10 @@ keys: 0xc8ca7c4f2dc014d7e4fc6973052da1517b4c54da: "9b9c46d0873a9982ade718ab3f4cfc57172b2f07c21b9901ddf239e931d2d6dc" +indexersUrl: + uniqueUrl: "https://api-unique.uniquescan.io/v1/graphql" + opalUrl: "https://api-opal.uniquescan.io/v1/graphql" + apiKeys: ethereumBlockExplorer: "JGD5ZUUBHE8CUXPNKZASVQPHRGBMB7A5XV" polygonBlockExplorer: "DZ3PFVWGJE5B8DMDQPRZ5JFBR6U484B82G" From 145d0830be9abe9598697e51ca0eeeae2226e8c0 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 20 Apr 2023 13:48:43 +0100 Subject: [PATCH 23/25] changed address as public key --- src/main/kotlin/id/walt/idp/nfts/NFTController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt index e935333..4405d2d 100644 --- a/src/main/kotlin/id/walt/idp/nfts/NFTController.kt +++ b/src/main/kotlin/id/walt/idp/nfts/NFTController.kt @@ -83,8 +83,8 @@ object NFTController { } ChainEcosystem.POLKADOT -> { val publicKey = SiwpManager.getPublicKey(message) + address = SiwpManager.getPublicKey(message) - address = SiwpManager.getAddress(message) SiwpManager.verifySignature(session!!, message, publicKey, signature) } From 5c267f03dff645f9d058924b219518fbaea9ff43 Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 20 Apr 2023 13:49:13 +0100 Subject: [PATCH 24/25] added polkadot collection in idp-config.json --- config/idp-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/idp-config.json b/config/idp-config.json index cda8a33..cf19f76 100644 --- a/config/idp-config.json +++ b/config/idp-config.json @@ -89,7 +89,7 @@ "POLKADOT": { "chain": "OPAL", "factorySmartContractAddress": "", - "smartContractAddress": "5GTmz6Vc7tXsbiD6ujxyt8Yf17FnygJLcrBqvduU3c8NwmHP" + "smartContractAddress": "1062" } } From af96e589aa953e4e3095e9f138a3a0c06e6b5c1c Mon Sep 17 00:00:00 2001 From: SuperBatata Date: Thu, 20 Apr 2023 13:49:35 +0100 Subject: [PATCH 25/25] updated NFT kit package --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9d21b8f..ae08f0c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -62,7 +62,7 @@ dependencies { testImplementation("io.kotest:kotest-assertions-json:5.5.0") // NftKit - implementation("id.walt:waltid-nftkit:1.2304041249.0") + implementation("id.walt:waltid-nftkit:1.2304191004.0") // HTTP / Client: ktor implementation("io.ktor:ktor-client-core:2.0.0")