Enable badge creation using Mint Rule: By Keys

This commit is contained in:
Serkan Reis
2023-02-27 21:43:57 +03:00
parent 68efd8d361
commit cc31179516
3 changed files with 104 additions and 19 deletions
+19
View File
@@ -1,5 +1,6 @@
/* eslint-disable eslint-comments/disable-enable-pair */
import * as crypto from 'crypto'
import { Word32Array } from 'jscrypto'
import { SHA256 } from 'jscrypto/SHA256'
import * as secp256k1 from 'secp256k1'
@@ -23,3 +24,21 @@ export function generateSignature(id: number, owner: string, privateKey: string)
return ''
}
}
export function generateKeyPairs(amount: number) {
const keyPairs: { publicKey: string; privateKey: string }[] = []
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,
privateKey,
})
}
return keyPairs
}