Improve merchant creation with automatic keypair generation

Enhance the merchant creation process by automatically generating Nostr keypairs
for users who don't have them, and streamline the API interface.

Changes:
- Add CreateMerchantRequest model to simplify merchant creation API
- Auto-generate Nostr keypairs for users without existing keys
- Update merchant creation endpoint to use user account keypairs
- Improve error handling and validation in merchant creation flow
- Clean up frontend JavaScript for merchant creation

This ensures all merchants have proper Nostr keypairs for marketplace
functionality without requiring manual key management from users.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
padreug 2025-09-07 03:25:19 +02:00 committed by Patrick Mulligan
parent 7c7d6c7953
commit 7245123e49
3 changed files with 56 additions and 46 deletions

View file

@ -49,46 +49,19 @@ window.app = Vue.createApp({
}
},
methods: {
generateKeys: function () {
const privateKey = nostr.generatePrivateKey()
const publicKey = nostr.getPublicKey(privateKey)
this.generateKeyDialog.privateKey = privateKey
this.generateKeyDialog.nsec = nostr.nip19.nsecEncode(privateKey)
this.generateKeyDialog.npub = nostr.nip19.npubEncode(publicKey)
this.generateKeyDialog.showNsec = false
this.generateKeyDialog.show = true
},
confirmGenerateKey: async function () {
this.generateKeyDialog.show = false
await this.createMerchant(this.generateKeyDialog.privateKey)
generateKeys: async function () {
// No longer need to generate keys here - the backend will use user's existing keypairs
await this.createMerchant()
},
importKeys: async function () {
this.importKeyDialog.show = false
let privateKey = this.importKeyDialog.data.privateKey
if (!privateKey) {
return
}
try {
if (privateKey.toLowerCase().startsWith('nsec')) {
privateKey = nostr.nip19.decode(privateKey).data
}
// Check if this key is already in use
const publicKey = nostr.getPublicKey(privateKey)
if (this.merchant?.public_key === publicKey) {
this.$q.notify({
type: 'warning',
message: 'This key is already your current profile'
})
return
}
} catch (error) {
this.$q.notify({
type: 'negative',
message: `${error}`
})
return
}
await this.createMerchant(privateKey)
// Import keys functionality removed since we use user's native keypairs
// Show a message that this is no longer needed
this.$q.notify({
type: 'info',
message: 'Merchants now use your account Nostr keys automatically. Key import is no longer needed.',
timeout: 3000
})
},
showImportKeysDialog: async function () {
this.importKeyDialog.show = true
@ -143,12 +116,9 @@ window.app = Vue.createApp({
this.showKeys = false
this.stallCount = 0
},
createMerchant: async function (privateKey) {
createMerchant: async function () {
try {
const pubkey = nostr.getPublicKey(privateKey)
const payload = {
private_key: privateKey,
public_key: pubkey,
config: {}
}
const {data} = await LNbits.api.request(