Implement Mint by Keys for Badge Actions > Actions
This commit is contained in:
parent
1396445f19
commit
0696e83bfa
@ -22,7 +22,6 @@ import { TransactionHash } from 'components/TransactionHash'
|
|||||||
import { WhitelistUpload } from 'components/WhitelistUpload'
|
import { WhitelistUpload } from 'components/WhitelistUpload'
|
||||||
import { useWallet } from 'contexts/wallet'
|
import { useWallet } from 'contexts/wallet'
|
||||||
import type { Badge, BadgeHubInstance } from 'contracts/badgeHub'
|
import type { Badge, BadgeHubInstance } from 'contracts/badgeHub'
|
||||||
import * as crypto from 'crypto'
|
|
||||||
import sizeof from 'object-sizeof'
|
import sizeof from 'object-sizeof'
|
||||||
import type { FormEvent } from 'react'
|
import type { FormEvent } from 'react'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
@ -156,18 +155,24 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
|||||||
|
|
||||||
const ownerListState = useAddressListState()
|
const ownerListState = useAddressListState()
|
||||||
|
|
||||||
const pubkeyState = useInputState({
|
const pubKeyState = useInputState({
|
||||||
id: 'pubkey',
|
id: 'pubKey',
|
||||||
name: 'pubkey',
|
name: 'pubKey',
|
||||||
title: 'Pubkey',
|
title: 'Public Key',
|
||||||
subtitle: 'The public key to check whether it can be used to mint a badge',
|
subtitle:
|
||||||
|
type === 'mint_by_keys'
|
||||||
|
? 'The whitelisted public key authorized to mint a badge'
|
||||||
|
: 'The public key to check whether it can be used to mint a badge',
|
||||||
})
|
})
|
||||||
|
|
||||||
const privateKeyState = useInputState({
|
const privateKeyState = useInputState({
|
||||||
id: 'privateKey',
|
id: 'privateKey',
|
||||||
name: 'privateKey',
|
name: 'privateKey',
|
||||||
title: 'Private Key',
|
title: 'Private Key',
|
||||||
subtitle: 'The private key that was generated during badge creation',
|
subtitle:
|
||||||
|
type === 'mint_by_keys'
|
||||||
|
? 'The corresponding private key for the whitelisted public key'
|
||||||
|
: 'The private key that was generated during badge creation',
|
||||||
})
|
})
|
||||||
|
|
||||||
const nftState = useInputState({
|
const nftState = useInputState({
|
||||||
@ -185,10 +190,11 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
|||||||
})
|
})
|
||||||
|
|
||||||
const showMetadataField = isEitherType(type, ['edit_badge'])
|
const showMetadataField = isEitherType(type, ['edit_badge'])
|
||||||
const showOwnerField = isEitherType(type, ['mint_by_key', 'mint_by_keys'])
|
const showOwnerField = isEitherType(type, ['mint_by_key', 'mint_by_keys', 'mint_by_minter'])
|
||||||
const showPrivateKeyField = isEitherType(type, ['mint_by_key', 'mint_by_keys', 'airdrop_by_key'])
|
const showPrivateKeyField = isEitherType(type, ['mint_by_key', 'mint_by_keys', 'airdrop_by_key'])
|
||||||
const showAirdropFileField = isEitherType(type, ['airdrop_by_key'])
|
const showAirdropFileField = isEitherType(type, ['airdrop_by_key'])
|
||||||
const showOwnerList = isEitherType(type, ['mint_by_minter'])
|
const showOwnerList = isEitherType(type, ['mint_by_minter'])
|
||||||
|
const showPubKeyField = isEitherType(type, ['mint_by_keys'])
|
||||||
|
|
||||||
const payload: DispatchExecuteArgs = {
|
const payload: DispatchExecuteArgs = {
|
||||||
badge: {
|
badge: {
|
||||||
@ -241,7 +247,7 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
|||||||
id: badgeId,
|
id: badgeId,
|
||||||
editFee,
|
editFee,
|
||||||
owner: resolvedOwnerAddress,
|
owner: resolvedOwnerAddress,
|
||||||
pubkey: pubkeyState.value,
|
pubkey: pubKeyState.value,
|
||||||
signature,
|
signature,
|
||||||
keys: [],
|
keys: [],
|
||||||
limit: limitState.value,
|
limit: limitState.value,
|
||||||
@ -484,19 +490,6 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleGenerateKeys = (amount: number) => {
|
|
||||||
for (let i = 0; i < amount; i++) {
|
|
||||||
let privKey: Buffer
|
|
||||||
do {
|
|
||||||
privKey = crypto.randomBytes(32)
|
|
||||||
} while (!secp256k1.privateKeyVerify(privKey))
|
|
||||||
|
|
||||||
const privateKey = privKey.toString('hex')
|
|
||||||
const publicKey = Buffer.from(secp256k1.publicKeyCreate(privKey)).toString('hex')
|
|
||||||
keyPairs.push(publicKey.concat(',', privateKey))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form>
|
<form>
|
||||||
<div className="grid grid-cols-2 mt-4">
|
<div className="grid grid-cols-2 mt-4">
|
||||||
@ -532,6 +525,7 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
|||||||
title="Owner"
|
title="Owner"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{showPubKeyField && <TextInput className="mt-2" {...pubKeyState} />}
|
||||||
{showPrivateKeyField && <TextInput className="mt-2" {...privateKeyState} />}
|
{showPrivateKeyField && <TextInput className="mt-2" {...privateKeyState} />}
|
||||||
|
|
||||||
<Conditional test={showOwnerList}>
|
<Conditional test={showOwnerList}>
|
||||||
|
Loading…
Reference in New Issue
Block a user