Skip to content

Commit

Permalink
feat(web): integrate cert management from akashjs
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed May 13, 2024
1 parent c4c9318 commit 5d8187b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 136 deletions.
43 changes: 22 additions & 21 deletions deploy-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions deploy-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@akashnetwork/akash-api": "^1.3.0",
"@akashnetwork/akashjs": "^0.8.1",
"@akashnetwork/akashjs": "^0.9.0",
"@auth0/nextjs-auth0": "^3.1.0",
"@cosmjs/encoding": "^0.29.5",
"@cosmjs/stargate": "^0.29.5",
Expand Down Expand Up @@ -53,7 +53,6 @@
"js-yaml": "^4.1.0",
"json-stable-stringify": "^1.0.2",
"json2csv": "^5.0.7",
"jsrsasign": "^10.6.1",
"lodash": "^4.17.21",
"long": "^5.2.3",
"material-ui-popup-state": "^4.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useSettings } from "../../context/SettingsProvider";
import { makeStyles } from "tss-react/mui";
import { useWallet } from "@src/context/WalletProvider";
import { useRouter } from "next/router";
import { certificateManager } from "@akashnetwork/akashjs/build/certificates/certificate-manager";

import { Timer } from "@src/utils/timer";
import { defaultInitialDeposit, RouteStepKeys } from "@src/utils/constants";
import { deploymentData } from "@src/utils/deploymentData";
Expand All @@ -22,7 +24,6 @@ import { AnalyticsEvents } from "@src/utils/analytics";
import { PrerequisiteList } from "./PrerequisiteList";
import { TemplateCreation } from "@src/types";
import { useCertificate } from "@src/context/CertificateProvider";
import { generateCertificate } from "@src/utils/certificateUtils";
import { updateWallet } from "@src/utils/walletUtils";
import sdlStore from "@src/store/sdlStore";
import { useAtom } from "jotai";
Expand Down Expand Up @@ -160,7 +161,7 @@ export const ManifestEdit: React.FunctionComponent<Props> = ({ editedManifest, s

// Create a cert if the user doesn't have one
if (!hasValidCert) {
const { crtpem, pubpem, encryptedKey } = generateCertificate(address);
const { cert: crtpem, publicKey: pubpem, privateKey: encryptedKey } = certificateManager.generatePEM(address);
_crtpem = crtpem;
_encryptedKey = encryptedKey;
messages.push(TransactionMessageData.getCreateCertificateMsg(address, crtpem, pubpem));
Expand Down
5 changes: 3 additions & 2 deletions deploy-web/src/components/sdl/RentGpusForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useEffect, useRef, useState } from "react";
import { ApiTemplate, ProfileGpuModel, RentGpusFormValues, Service } from "@src/types";
import { defaultAnyRegion, defaultRentGpuService } from "@src/utils/sdl/data";
import { useRouter } from "next/router";
import { certificateManager } from "@akashnetwork/akashjs/build/certificates/certificate-manager";

import sdlStore from "@src/store/sdlStore";
import { useAtom } from "jotai";
import { RegionSelect } from "./RegionSelect";
Expand All @@ -21,7 +23,6 @@ import { useCertificate } from "@src/context/CertificateProvider";
import { useSettings } from "@src/context/SettingsProvider";
import { useWallet } from "@src/context/WalletProvider";
import { validateDeploymentData } from "@src/utils/deploymentUtils";
import { generateCertificate } from "@src/utils/certificateUtils";
import { TransactionMessageData } from "@src/utils/TransactionMessageData";
import { updateWallet } from "@src/utils/walletUtils";
import { saveDeploymentManifestAndName } from "@src/utils/deploymentLocalDataUtils";
Expand Down Expand Up @@ -203,7 +204,7 @@ export const RentGpusForm: React.FunctionComponent<Props> = ({}) => {

// Create a cert if the user doesn't have one
if (!hasValidCert) {
const { crtpem, pubpem, encryptedKey } = generateCertificate(address);
const { cert: crtpem, publicKey: pubpem, privateKey: encryptedKey } = certificateManager.generatePEM(address);
_crtpem = crtpem;
_encryptedKey = encryptedKey;
messages.push(TransactionMessageData.getCreateCertificateMsg(address, crtpem, pubpem));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useState, useCallback, useEffect } from "react";
import axios from "axios";
import { useSnackbar } from "notistack";
import { certificateManager } from "@akashnetwork/akashjs/build/certificates/certificate-manager";

import { useSettings } from "../SettingsProvider";
import { networkVersion } from "@src/utils/constants";
import { generateCertificate, getCertPem, openCert } from "@src/utils/certificateUtils";
import { Snackbar } from "@src/components/shared/Snackbar";
import { getSelectedStorageWallet, getStorageWallets, updateWallet } from "@src/utils/walletUtils";
import { useWallet } from "../WalletProvider";
Expand Down Expand Up @@ -82,7 +83,7 @@ export const CertificateProvider = ({ children }) => {
);
const certs = (response.data.certificates || []).map(cert => {
const parsed = atob(cert.certificate.cert);
const pem = getCertPem(parsed);
const pem = certificateManager.parsePem(parsed);

return {
...cert,
Expand Down Expand Up @@ -158,8 +159,7 @@ export const CertificateProvider = ({ children }) => {
for (let i = 0; i < wallets.length; i++) {
const _wallet = wallets[i];

const cert = await openCert(_wallet.cert, _wallet.certKey);
const _cert = { ...cert, address: _wallet.address };
const _cert = { certPem: _wallet.cert, keyPem: _wallet.certKey, address: _wallet.address };

certs.push(_cert);

Expand All @@ -177,7 +177,7 @@ export const CertificateProvider = ({ children }) => {
async function createCertificate() {
setIsCreatingCert(true);

const { crtpem, pubpem, encryptedKey } = generateCertificate(address);
const { cert: crtpem, publicKey: pubpem, privateKey: encryptedKey } = certificateManager.generatePEM(address);

try {
const message = TransactionMessageData.getCreateCertificateMsg(address, crtpem, pubpem);
Expand Down Expand Up @@ -214,7 +214,7 @@ export const CertificateProvider = ({ children }) => {
*/
async function regenerateCertificate() {
setIsCreatingCert(true);
const { crtpem, pubpem, encryptedKey } = generateCertificate(address);
const { cert: crtpem, publicKey: pubpem, privateKey: encryptedKey } = certificateManager.generatePEM(address);

try {
const revokeCertMsg = TransactionMessageData.getRevokeCertificateMsg(address, selectedCertificate.serial);
Expand Down
103 changes: 0 additions & 103 deletions deploy-web/src/utils/certificateUtils.ts

This file was deleted.

0 comments on commit 5d8187b

Please sign in to comment.