Skip to content

Commit f6b86e9

Browse files
authored
Merge pull request #31 from Ryun1/feat/add-auth-cc-cert
Feat: add Constitutional Committee Authorization Cert to CIP95 Tools
2 parents ffa0494 + 86327c9 commit f6b86e9

File tree

4 files changed

+125
-4
lines changed

4 files changed

+125
-4
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, {useState} from 'react'
2+
import InputWithLabel from '../../inputWithLabel'
3+
import {
4+
getCommitteeHotAuth,
5+
getCertOfNewCommitteeHotAuth,
6+
} from '../../../utils/cslTools'
7+
import GovToolsPanel from '../govToolsPanel'
8+
9+
const AuthCCPanel = (props) => {
10+
const {onWaiting, onError, getters, setters, handleInputCreds} = props
11+
const {getCertBuilder} = getters
12+
const {handleAddingCertInTx} = setters
13+
14+
const [ccColdInputValue, setCCColdCredInputValue] = useState('')
15+
const [ccHotInputValue, setCCHotCredInputValue] = useState('')
16+
17+
const buildCCAuthCert = () => {
18+
onWaiting(true)
19+
20+
// build CC auth cert
21+
const certBuilder = getCertBuilder()
22+
try {
23+
24+
// cold credential
25+
const coldCred = handleInputCreds(ccColdInputValue)
26+
if (coldCred == null) {
27+
return null
28+
}
29+
30+
// hot credential
31+
const hotCred = handleInputCreds(ccHotInputValue)
32+
if (hotCred == null) {
33+
return null
34+
}
35+
36+
// Create cert object
37+
const committeeHotAuthCert = getCommitteeHotAuth(coldCred, hotCred)
38+
// add cert to certBuilder
39+
certBuilder.add(getCertOfNewCommitteeHotAuth(committeeHotAuthCert))
40+
// adding the cert to the certStorage
41+
handleAddingCertInTx(certBuilder)
42+
onWaiting(false)
43+
} catch (error) {
44+
console.error(error)
45+
onWaiting(false)
46+
onError()
47+
}
48+
}
49+
50+
const panelProps = {
51+
buttonName: 'Build Cert',
52+
certLabel: 'ccAuth',
53+
clickFunction: buildCCAuthCert,
54+
}
55+
56+
return (
57+
<GovToolsPanel {...panelProps}>
58+
<InputWithLabel
59+
inputName="CC Cold Credential"
60+
helpText="Bech32 or Hex encoded"
61+
inputValue={ccColdInputValue}
62+
onChangeFunction={(event) => {
63+
setCCColdCredInputValue(event.target.value)
64+
}}
65+
/>
66+
<InputWithLabel
67+
inputName="CC Hot Credential"
68+
helpText="Bech32 or Hex encoded"
69+
inputValue={ccHotInputValue}
70+
onChangeFunction={(event) => {
71+
setCCHotCredInputValue(event.target.value)
72+
}}
73+
/>
74+
</GovToolsPanel>
75+
)
76+
}
77+
78+
export default AuthCCPanel

src/components/tabs/subtabs/cip95AdditionalPart.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ const Cip95AdditionalPart = ({api, onWaiting, onError, getters, setters}) => {
7979
children: <GovActionsTab />,
8080
},
8181
{
82-
label: 'Constitutional Commitee Certs',
82+
label: 'Constitutional Committee Certs',
8383
value: 'ccCerts',
84-
children: <ConstitCommCertsTab />,
84+
children: (
85+
<ConstitCommCertsTab
86+
api={api}
87+
onWaiting={onWaiting}
88+
onError={onError}
89+
getters={newGetters}
90+
setters={newSetters}
91+
/>
92+
),
8593
},
8694
]
8795
return (

src/components/tabs/subtabs/constitCommCertsTab.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
import React from 'react'
22
import TabsComponent from '../tabsComponent'
3+
import AuthCCPanel from '../../cards/govActions/authCCPanel'
4+
import {getCslCredentialFromBech32, getCslCredentialFromHex} from '../../../utils/cslTools'
5+
6+
const ConstitCommCertsTab = ({api, onWaiting, onError, getters, setters}) => {
7+
const handleInputCreds = (input) => {
8+
try {
9+
return getCslCredentialFromHex(input)
10+
} catch (err1) {
11+
try {
12+
return getCslCredentialFromBech32(input)
13+
} catch (err2) {
14+
onWaiting(false)
15+
console.error(
16+
`Error in parsing credential, not Hex or Bech32: ${JSON.stringify(err1)}, ${JSON.stringify(err2)}`,
17+
)
18+
onError()
19+
return null
20+
}
21+
}
22+
}
23+
24+
const panelsProps = {
25+
api,
26+
onWaiting,
27+
onError,
28+
getters,
29+
setters,
30+
handleInputCreds,
31+
}
332

4-
const ConstitCommCertsTab = () => {
533
const data = [
634
{
735
label: 'Authorize CC Hot Credential',
836
value: 'authHotCred',
9-
children: <></>,
37+
children: <AuthCCPanel {...panelsProps} />,
1038
},
1139
{
1240
label: 'Resign CC Cold Credential',

src/utils/cslTools.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,10 @@ export const getStakeKeyDeregCert = (stakeCred) => wasm.StakeDeregistration.new(
205205

206206
export const getCertOfNewStakeDereg = (stakeKeyDeregCert) =>
207207
wasm.Certificate.new_stake_deregistration(stakeKeyDeregCert)
208+
209+
// Committee Hot Authorization Certificate
210+
export const getCommitteeHotAuth = (coldCred, hotCred) =>
211+
wasm.CommitteeHotAuth.new(coldCred, hotCred)
212+
213+
export const getCertOfNewCommitteeHotAuth = (committeeHotAuthCert) =>
214+
wasm.Certificate.new_committee_hot_auth(committeeHotAuthCert)

0 commit comments

Comments
 (0)