Generate public & private key pair for badge creation
This commit is contained in:
parent
cb30fbf13c
commit
c626864f0b
@ -45,6 +45,7 @@
|
||||
"react-query": "^3",
|
||||
"react-tracked": "^1",
|
||||
"scheduler": "^0",
|
||||
"secp256k1": "^4.0.3",
|
||||
"zustand": "^3"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -52,6 +53,7 @@
|
||||
"@types/node": "^14",
|
||||
"@types/react": "^18",
|
||||
"@types/react-datetime-picker": "^3",
|
||||
"@types/secp256k1": "^4.0.2",
|
||||
"autoprefixer": "^10",
|
||||
"husky": "^7",
|
||||
"lint-staged": "^12",
|
||||
@ -81,4 +83,4 @@
|
||||
},
|
||||
"prettier": "@stargaze-studio/prettier-config",
|
||||
"private": true
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import { useContracts } from 'contexts/contracts'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import type { DispatchExecuteArgs } from 'contracts/badgeHub/messages/execute'
|
||||
import { dispatchExecute, isEitherType, previewExecutePayload } from 'contracts/badgeHub/messages/execute'
|
||||
import * as crypto from 'crypto'
|
||||
import type { NextPage } from 'next'
|
||||
import { useRouter } from 'next/router'
|
||||
import { NextSeo } from 'next-seo'
|
||||
@ -23,6 +24,7 @@ import { useEffect, useMemo, useState } from 'react'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { FaArrowRight } from 'react-icons/fa'
|
||||
import { useMutation } from 'react-query'
|
||||
import * as secp256k1 from 'secp256k1'
|
||||
import { withMetadata } from 'utils/layout'
|
||||
import { links } from 'utils/links'
|
||||
|
||||
@ -211,7 +213,7 @@ const BadgeHubExecutePage: NextPage = () => {
|
||||
by_key: keyState.value,
|
||||
},
|
||||
expiry: timestamp ? timestamp.getTime() * 1000000 : undefined,
|
||||
max_supply: maxSupplyState.value,
|
||||
max_supply: maxSupplyState.value || undefined,
|
||||
},
|
||||
metadata: {
|
||||
name: nameState.value || undefined,
|
||||
@ -274,9 +276,17 @@ const BadgeHubExecutePage: NextPage = () => {
|
||||
)
|
||||
|
||||
const handleGenerateKey = () => {
|
||||
//generate public and private key pair
|
||||
let privKey: Buffer
|
||||
do {
|
||||
privKey = crypto.randomBytes(32)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
} while (!secp256k1.privateKeyVerify(privKey))
|
||||
|
||||
keyState.onChange('test')
|
||||
const privateKey = privKey.toString('hex')
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
const publicKey = Buffer.from(secp256k1.publicKeyCreate(privKey)).toString('hex')
|
||||
|
||||
keyState.onChange(publicKey)
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
|
28
yarn.lock
28
yarn.lock
@ -2829,6 +2829,13 @@
|
||||
resolved "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz"
|
||||
integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==
|
||||
|
||||
"@types/secp256k1@^4.0.2":
|
||||
version "4.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/secp256k1/-/secp256k1-4.0.3.tgz#1b8e55d8e00f08ee7220b4d59a6abe89c37a901c"
|
||||
integrity sha512-Da66lEIFeIz9ltsdMZcpQvmrmmoqrfju8pm1BH8WbYjZSwUgCwXLb9C+9XYogwBITnbsSaMdVPb2ekf7TV+03w==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@typescript-eslint/eslint-plugin@5.17.0":
|
||||
version "5.17.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.17.0.tgz"
|
||||
@ -4112,7 +4119,7 @@ electron-to-chromium@^1.4.118:
|
||||
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.124.tgz"
|
||||
integrity sha512-VhaE9VUYU6d2eIb+4xf83CATD+T+3bTzvxvlADkQE+c2hisiw3sZmvEDtsW704+Zky9WZGhBuQXijDVqSriQLA==
|
||||
|
||||
elliptic@^6.4.0, elliptic@^6.5.3:
|
||||
elliptic@^6.4.0, elliptic@^6.5.3, elliptic@^6.5.4:
|
||||
version "6.5.4"
|
||||
resolved "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz"
|
||||
integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==
|
||||
@ -6253,10 +6260,20 @@ nft.storage@^6.3.0:
|
||||
streaming-iterables "^6.0.0"
|
||||
throttled-queue "^2.1.2"
|
||||
|
||||
node-addon-api@^2.0.0:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32"
|
||||
integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==
|
||||
|
||||
node-fetch@^2.6.1, "node-fetch@https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz":
|
||||
version "2.6.7"
|
||||
resolved "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz"
|
||||
|
||||
node-gyp-build@^4.2.0:
|
||||
version "4.6.0"
|
||||
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.6.0.tgz#0c52e4cbf54bbd28b709820ef7b6a3c2d6209055"
|
||||
integrity sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==
|
||||
|
||||
node-releases@^2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.npmjs.org/node-releases/-/node-releases-2.0.3.tgz"
|
||||
@ -7130,6 +7147,15 @@ scheduler@^0, scheduler@^0.22.0:
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
|
||||
secp256k1@^4.0.3:
|
||||
version "4.0.3"
|
||||
resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.3.tgz#c4559ecd1b8d3c1827ed2d1b94190d69ce267303"
|
||||
integrity sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA==
|
||||
dependencies:
|
||||
elliptic "^6.5.4"
|
||||
node-addon-api "^2.0.0"
|
||||
node-gyp-build "^4.2.0"
|
||||
|
||||
secretjs@^0.17.0:
|
||||
version "0.17.5"
|
||||
resolved "https://registry.npmjs.org/secretjs/-/secretjs-0.17.5.tgz"
|
||||
|
Loading…
Reference in New Issue
Block a user