From a478e8fa4c7becb4de54a9ae855599a4fbc6fa78 Mon Sep 17 00:00:00 2001 From: Ludovit Scholtz Date: Mon, 14 Oct 2024 22:51:07 +0200 Subject: [PATCH] make account online from msig account --- src/pages/Account/Assets.vue | 33 ---- src/pages/Account/Transactions.vue | 33 ---- src/pages/AccountOverview.vue | 247 ++++++++++++++++++++++++- src/pages/Arc14.vue | 1 - src/pages/Connect.vue | 1 - src/pages/Sign.vue | 138 ++++++++++++-- src/pages/Swap.vue | 1 - src/store/arc14.js | 55 +++--- src/store/index.js | 4 +- src/store/{kmd.js => participation.js} | 145 ++++++++++++--- 10 files changed, 523 insertions(+), 135 deletions(-) rename src/store/{kmd.js => participation.js} (50%) diff --git a/src/pages/Account/Assets.vue b/src/pages/Account/Assets.vue index a291ce1e..7dc56ac3 100644 --- a/src/pages/Account/Assets.vue +++ b/src/pages/Account/Assets.vue @@ -258,8 +258,6 @@ export default { setTransaction: "wallet/setTransaction", getAsset: "indexer/getAsset", prolong: "wallet/prolong", - setAccountOnline: "kmd/setAccountOnline", - setAccountOffline: "kmd/setAccountOffline", openSuccess: "toast/openSuccess", getAlgod: "algod/getAlgod", getIndexer: "indexer/getIndexer", @@ -401,37 +399,6 @@ export default { sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }, - async setAccountOnlineAtParticipationNode() { - this.displayOnlineOfflineDialog = false; - this.changeOnline = true; - if ( - await this.setAccountOnline({ - account: this.$route.params.account, - rounds: this.onlineRounds, - }) - ) { - await this.sleep(5000); - this.changeOnline = false; - await this.reloadAccount(); - this.openSuccess("You have set the account to online mode"); - } else { - this.changeOnline = false; - } - }, - async setAccountOfflineAtParticipationNode() { - this.displayOnlineOfflineDialog = false; - this.changeOffline = true; - if ( - await this.setAccountOffline({ account: this.$route.params.account }) - ) { - await this.sleep(5000); - this.changeOffline = false; - await this.reloadAccount(); - this.openSuccess("You have set the account to offline mode"); - } else { - this.changeOffline = false; - } - }, }, }; diff --git a/src/pages/Account/Transactions.vue b/src/pages/Account/Transactions.vue index 30019efc..cf0220cc 100644 --- a/src/pages/Account/Transactions.vue +++ b/src/pages/Account/Transactions.vue @@ -316,8 +316,6 @@ export default { setTransaction: "wallet/setTransaction", getAsset: "indexer/getAsset", prolong: "wallet/prolong", - setAccountOnline: "kmd/setAccountOnline", - setAccountOffline: "kmd/setAccountOffline", openSuccess: "toast/openSuccess", }), async makeAssets() { @@ -433,37 +431,6 @@ export default { sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }, - async setAccountOnlineAtParticipationNode() { - this.displayOnlineOfflineDialog = false; - this.changeOnline = true; - if ( - await this.setAccountOnline({ - account: this.$route.params.account, - rounds: this.onlineRounds, - }) - ) { - await this.sleep(5000); - this.changeOnline = false; - await this.reloadAccount(); - this.openSuccess("You have set the account to online mode"); - } else { - this.changeOnline = false; - } - }, - async setAccountOfflineAtParticipationNode() { - this.displayOnlineOfflineDialog = false; - this.changeOffline = true; - if ( - await this.setAccountOffline({ account: this.$route.params.account }) - ) { - await this.sleep(5000); - this.changeOffline = false; - await this.reloadAccount(); - this.openSuccess("You have set the account to offline mode"); - } else { - this.changeOffline = false; - } - }, }, }; diff --git a/src/pages/AccountOverview.vue b/src/pages/AccountOverview.vue index 8e6b9c7b..6957cbd1 100644 --- a/src/pages/AccountOverview.vue +++ b/src/pages/AccountOverview.vue @@ -83,14 +83,94 @@ {{ $t("onlineofflinedialog.host") }}: {{ $store.state.config.participation }}

+

Realm : {{ participationRealm }}

+

+ Please sign ARC14 authentication transaction and return back to + this form. +

+

ARC14 auth has been loaded.

+

+ Generating participation keys.. Please be patient, the + participation node is performing CPU sensitive task. +

@@ -488,6 +580,7 @@ import AccountType from "@/components/AccountType.vue"; import ProgressSpinner from "primevue/progressspinner"; import { VERIFY_FALLBACK_SERVER } from "@walletconnect/core"; import { JsonViewer } from "vue3-json-viewer"; +import algosdk from "algosdk"; export default { components: { @@ -510,6 +603,10 @@ export default { changeOnline: false, changeOffline: false, onlineRounds: 500000, + participationRealm: "", + participationAuth: "", + participationData: {}, + participationWizzard: false, }; }, computed: { @@ -560,6 +657,14 @@ export default { if (!rekeyedInfo) return null; return rekeyedInfo.params; }, + multisigParams() { + if (this.rekeyedToInfo) return this.rekeyedMultisigParams; + if (!this.account) return {}; + return this.account.params; + }, + isMultisig() { + return !!this.multisigParams; + }, }, watch: { async selection() { @@ -576,6 +681,10 @@ export default { await this.reloadAccount(); await this.makeAssets(); this.prolong(); + if (this.isMultisig) { + this.participationWizzard = true; + } + console.log("account", this.account); }, methods: { ...mapActions({ @@ -587,9 +696,15 @@ export default { setTransaction: "wallet/setTransaction", getAsset: "indexer/getAsset", prolong: "wallet/prolong", - setAccountOnline: "kmd/setAccountOnline", - setAccountOffline: "kmd/setAccountOffline", + setAccountOnline: "participation/setAccountOnline", + getParticipationData: "participation/getParticipationData", + setAccountOffline: "participation/setAccountOffline", + getAccountOfflineTx: "participation/getAccountOfflineTx", + getARC14ParticipationRealm: "participation/getARC14ParticipationRealm", openSuccess: "toast/openSuccess", + signAuthTx: "arc14/signAuthTx", + getAuthTx: "arc14/getAuthTx", + returnTo: "signer/returnTo", }), async makeAssets() { this.assets = []; @@ -689,13 +804,122 @@ export default { sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }, + _arrayBufferToBase64(buffer) { + var binary = ""; + var bytes = new Uint8Array(buffer); + var len = bytes.byteLength; + for (var i = 0; i < len; i++) { + binary += String.fromCharCode(bytes[i]); + } + return btoa(binary); + }, + base642base64url(input) { + return input + .replaceAll("+", "-") + .replaceAll("/", "_") + .replaceAll("=", ""); + }, + async clickFetchArc14Realm() { + await this.prolong(); + this.participationRealm = await this.getARC14ParticipationRealm(); + console.log("this.participationRealm", this.participationRealm); + + // check if we did go through step 2 + + if ( + this.$store.state.arc14.address2chain2realm2token[ + this.$store.state.config.env + ] && + this.$store.state.arc14.address2chain2realm2token[ + this.$store.state.config.env + ][this.$route.params.account] && + this.$store.state.arc14.address2chain2realm2token[ + this.$store.state.config.env + ][this.$route.params.account][this.participationRealm] + ) { + this.participationAuth = + this.$store.state.arc14.address2chain2realm2token[ + this.$store.state.config.env + ][this.$route.params.account][this.participationRealm]; + } + console.log( + "this.participationAuth", + this.participationAuth, + this.$store.state.arc14.address2chain2realm2token + ); + }, + async clickSignArc14AuthTx() { + await this.prolong(); + this.participationAuth = await this.signAuthTx({ + account: this.$route.params.account, + realm: this.participationRealm, + }); + console.log("this.participationAuth", this.participationAuth); + }, + async clickSignArc14MsigAuthTx() { + await this.prolong(); + const txn = await this.getAuthTx({ + account: this.$route.params.account, + realm: this.participationRealm, + }); + console.log("this.participationAuth", this.participationAuth); + const encodedtxn = algosdk.encodeUnsignedTransaction(txn); + const urldataB64 = this._arrayBufferToBase64(encodedtxn); + const urldataB64url = this.base642base64url(urldataB64); + const pushTo = `/multisig/${this.$route.params.account}/${urldataB64url}`; + await this.returnTo("Arc14Participation"); + + this.$router.push(pushTo); + }, + async clickLoadParticipationData() { + await this.prolong(); + this.changeOnline = true; + this.participationData = await this.getParticipationData({ + account: this.$route.params.account, + rounds: this.onlineRounds, + participationAuth: this.participationAuth, + }); + this.changeOnline = false; + console.log("this.participationData", this.participationData); + }, + async clickSignParticipationTx() { + await this.prolong(); + if (this.isMultisig) { + const txn = algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject( + this.participationData + ); + + const encodedtxn = algosdk.encodeUnsignedTransaction(txn); + const urldataB64 = this._arrayBufferToBase64(encodedtxn); + const urldataB64url = this.base642base64url(urldataB64); + const pushTo = `/multisig/${this.$route.params.account}/${urldataB64url}`; + this.$router.push(pushTo); + } else { + const txn = algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject( + this.participationData + ); + + const encodedtxn = algosdk.encodeUnsignedTransaction(txn); + const urldataB64 = this._arrayBufferToBase64(encodedtxn); + const urldataB64url = this.base642base64url(urldataB64); + const pushTo = `/sign/${this.$route.params.account}/${urldataB64url}`; + this.$router.push(pushTo); + } + }, async setAccountOnlineAtParticipationNode() { + await this.prolong(); this.displayOnlineOfflineDialog = false; this.changeOnline = true; + this.participationRealm = await this.getARC14ParticipationRealm(); + this.participationAuth = await this.signAuthTx({ + account: this.$route.params.account, + realm: this.participationRealm, + }); if ( await this.setAccountOnline({ account: this.$route.params.account, rounds: this.onlineRounds, + participationAuth: this.participationAuth, }) ) { await this.sleep(5000); @@ -707,6 +931,7 @@ export default { } }, async setAccountOfflineAtParticipationNode() { + await this.prolong(); this.displayOnlineOfflineDialog = false; this.changeOffline = true; if ( @@ -720,6 +945,18 @@ export default { this.changeOffline = false; } }, + async setAccountOfflineMsigAtParticipationNode() { + await this.prolong(); + this.displayOnlineOfflineDialog = false; + const txn = await this.getAccountOfflineTx({ + account: this.$route.params.account, + }); + const encodedtxn = algosdk.encodeUnsignedTransaction(txn); + const urldataB64 = this._arrayBufferToBase64(encodedtxn); + const urldataB64url = this.base642base64url(urldataB64); + const pushTo = `/multisig/${this.$route.params.account}/${urldataB64url}`; + this.$router.push(pushTo); + }, }, }; diff --git a/src/pages/Arc14.vue b/src/pages/Arc14.vue index 484aad2b..73d8bac7 100644 --- a/src/pages/Arc14.vue +++ b/src/pages/Arc14.vue @@ -69,7 +69,6 @@ export default { setTransaction: "wallet/setTransaction", getAsset: "indexer/getAsset", prolong: "wallet/prolong", - setAccountOnline: "kmd/setAccountOnline", openSuccess: "toast/openSuccess", axiosGet: "axios/get", getSK: "wallet/getSK", diff --git a/src/pages/Connect.vue b/src/pages/Connect.vue index 077158cb..bf9f20fe 100644 --- a/src/pages/Connect.vue +++ b/src/pages/Connect.vue @@ -598,7 +598,6 @@ export default { setTransaction: "wallet/setTransaction", getAsset: "indexer/getAsset", prolong: "wallet/prolong", - setAccountOnline: "kmd/setAccountOnline", openSuccess: "toast/openSuccess", openError: "toast/openError", axiosGet: "axios/get", diff --git a/src/pages/Sign.vue b/src/pages/Sign.vue index 0bb322ee..7569d6e3 100644 --- a/src/pages/Sign.vue +++ b/src/pages/Sign.vue @@ -50,6 +50,38 @@ {{ payTo }} +
+ +
+ Tx to unregister from the participation +
+
+
+ +
+ {{ txn.voteFirst }} +
+
+
+ +
+ {{ txn.voteLast }} +
+
-
+
@@ -207,6 +246,20 @@ {{ multisigDecoded.txn.tag }}
+
+ +
+ {{ encodeAddress(multisigDecoded.txn.from.publicKey) }} +
+
Return to scheduled payment management +