🥯Bagel

Domain Resolution API

Integrate .bagel domains into your wallet or application

bagel Domain Resolution API

The bagel Domain Resolution API provides a simple way for wallets and applications to resolve .bagel domains to retrieve the corresponding viewing and spending public keys needed for stealth transactions.

API Endpoint

https://bagel-resolve.fly.dev/resolve/:domain

This API allows any wallet or application to easily integrate support for bagel's privacy features without implementing the full SDK.

Usage

HTTP Request

GET https://bagel-resolve.fly.dev/resolve/:domain

Where :domain is the bagel domain to resolve (e.g., alice.bagel).

Response Format

A successful response will return JSON with the following structure:

{"stealthAddress":"F93hFRnikRs3MjM7SaEkrKoydEojSu57BYh2JRkjM5Hd",
"domain":"alice"}

The response includes:

  • stealthAddress: The resolved bagel domain's stealthAddress
  • domain: domain name

Error Response

If the domain cannot be resolved, the API will return an error:

{
  "error": "Domain not found",
  "status": "error"
}

Integration Example

Here's how to integrate the bagel Domain Resolution API into your wallet or application:

async function resolvebagelDomain(domain) {
  try {
    const response = await fetch(`https://bagel-resolve.fly.dev/resolve/${encodeURIComponent(domain)}`);
    
    if (!response.ok) {
      throw new Error(`Failed to resolve domain: ${response.statusText}`);
    }
    
    const data = await response.json();
    
    if (data.status === 'error') {
      throw new Error(data.error);
    }
    
    return {
      domain: data.domain,
      viewingPublicKey: data.viewingPublicKey,
      spendingPublicKey: data.spendingPublicKey
    };
  } catch (error) {
    console.error('Error resolving bagel domain:', error);
    throw error;
  }
}
 
// Example usage
async function sendTobagelDomain(domain, amount) {
  try {
    // 1. Resolve the domain to get public keys
    const recipient = await resolvebagelDomain(domain);
    
    // 2. Generate ephemeral keypair (you can use your preferred crypto library)
    const ephemeralKeypair = generateEphemeralKeypair();
    
    // 3. Compute shared secret using recipient's viewing public key
    const sharedSecret = computeSharedSecret(
      ephemeralKeypair.privateKey,
      recipient.viewingPublicKey
    );
    
    // 4. Create stealth address using shared secret and recipient's spending public key
    const stealthAddress = createStealthAddress(
      sharedSecret,
      recipient.spendingPublicKey
    );
    
    // 5. Send funds to the stealth address using your wallet's send function
    const txId = await sendFunds(stealthAddress, amount);
    
    // 6. Register the ephemeral public key (so recipient can find the payment)
    await registerEphemeralKey(domain, ephemeralKeypair.publicKey);
    
    return txId;
  } catch (error) {
    console.error('Error sending to bagel domain:', error);
    throw error;
  }
}

Best Practices

  1. Error Handling: Always implement proper error handling for failed domain resolution
  2. Caching: Consider caching resolved domains for a short period to reduce API calls
  3. User Feedback: Provide clear feedback to users during the resolution process
  4. Validation: Validate bagel domains before sending them to the API
  5. Rate Limiting: Implement reasonable rate limiting for API calls

CORS Support

The bagel Domain Resolution API supports Cross-Origin Resource Sharing (CORS), allowing it to be used directly from browser-based applications.

API Status

You can check the API status by making a simple request:

GET https://bagel-resolve.fly.dev/status

A successful response will return:

{
  "status": "operational",
  "version": "1.0.0"
}

By integrating this simple API, your wallet or application can offer bagel's privacy features to users with minimal development effort.

On this page