First fully working version.
This commit is contained in:
@@ -362,49 +362,6 @@
|
||||
return window.NostrTools.getPublicKey(randomKey);
|
||||
}
|
||||
|
||||
// Generate actual padding string based on requested bytes
|
||||
function generatePaddingString(paddingInput) {
|
||||
console.log('DEBUG: generatePaddingString called with:', paddingInput);
|
||||
|
||||
if (!paddingInput || paddingInput.trim() === '') {
|
||||
console.log('DEBUG: No padding input, returning null');
|
||||
return null;
|
||||
}
|
||||
|
||||
let cleanInput = paddingInput.trim();
|
||||
|
||||
// If no +/- prefix, assume it's addition
|
||||
if (!/^[+-]/.test(cleanInput)) {
|
||||
cleanInput = '+' + cleanInput;
|
||||
console.log('DEBUG: Added + prefix, now:', cleanInput);
|
||||
}
|
||||
|
||||
const match = cleanInput.match(/^([+-])(\d+)$/);
|
||||
if (!match) {
|
||||
console.log('DEBUG: Padding format invalid, returning null');
|
||||
return null;
|
||||
}
|
||||
|
||||
const operation = match[1]; // "+" or "-"
|
||||
const bytes = parseInt(match[2]);
|
||||
|
||||
console.log('DEBUG: Padding operation:', operation, 'bytes:', bytes);
|
||||
|
||||
if (operation === '-') {
|
||||
// For removal, we'll return the operation and count
|
||||
console.log('DEBUG: Returning removal padding:', cleanInput);
|
||||
return cleanInput; // Keep as "-50" format
|
||||
} else {
|
||||
// For addition, generate actual padding string
|
||||
// Use repeating digits: "0123456789012345..."
|
||||
let paddingStr = '';
|
||||
for (let i = 0; i < bytes; i++) {
|
||||
paddingStr += (i % 10).toString();
|
||||
}
|
||||
console.log('DEBUG: Generated padding string:', paddingStr);
|
||||
return paddingStr;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate random pubkey for testing (since we don't have real superballs yet)
|
||||
function generateRandomPubkey(bounceId) {
|
||||
@@ -495,8 +452,13 @@
|
||||
<input type="number" id="delay-${bounceId}" class="small-input" value="30" min="1">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label for="padding-${bounceId}">Padding (+N or -N bytes):</label>
|
||||
<input type="text" id="padding-${bounceId}" class="small-input" placeholder="+150 or -50">
|
||||
<label for="padding-${bounceId}">Add Padding Bytes to This Event:</label>
|
||||
<input type="number" id="padding-${bounceId}" class="small-input" placeholder="150" min="0" step="1">
|
||||
</div>
|
||||
<div class="input-group" id="daemon-padding-${bounceId}">
|
||||
<label for="add-padding-bytes-${bounceId}">Instruct Next Daemon to Add Padding (bytes):</label>
|
||||
<input type="number" id="add-padding-bytes-${bounceId}" class="small-input" placeholder="256" min="0" step="1">
|
||||
<small style="color: #666; font-size: 12px;">Only used when forwarding to another Superball</small>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label for="payment-${bounceId}">Payment (optional):</label>
|
||||
@@ -525,6 +487,15 @@
|
||||
const auditTag = generateAuditTag();
|
||||
document.getElementById(`audit-tag-${bounceId}`).value = auditTag;
|
||||
|
||||
// Hide daemon padding field for final bounce (first one created)
|
||||
if (bounces.length === 0) {
|
||||
// This is the final bounce - hide daemon padding field since it makes no sense
|
||||
const daemonPaddingDiv = document.getElementById(`daemon-padding-${bounceId}`);
|
||||
if (daemonPaddingDiv) {
|
||||
daemonPaddingDiv.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Update bounce labels to reflect execution order
|
||||
updateBounceLabels();
|
||||
}
|
||||
@@ -588,7 +559,8 @@
|
||||
const superballPubkey = document.getElementById(`superball-pubkey-${bounceId}`).value.trim();
|
||||
const bounceRelays = document.getElementById(`bounce-relays-${bounceId}`).value.split(',').map(r => r.trim()).filter(r => r);
|
||||
const delay = parseInt(document.getElementById(`delay-${bounceId}`).value);
|
||||
const padding = document.getElementById(`padding-${bounceId}`).value.trim();
|
||||
const builderPadding = parseInt(document.getElementById(`padding-${bounceId}`).value) || 0;
|
||||
const addPaddingBytes = parseInt(document.getElementById(`add-padding-bytes-${bounceId}`).value) || 0;
|
||||
const payment = document.getElementById(`payment-${bounceId}`).value.trim();
|
||||
|
||||
// Debug the input values
|
||||
@@ -596,7 +568,8 @@
|
||||
console.log(' - superballPubkey:', superballPubkey);
|
||||
console.log(' - bounceRelays:', bounceRelays);
|
||||
console.log(' - delay:', delay);
|
||||
console.log(' - padding:', `"${padding}"`);
|
||||
console.log(' - builderPadding:', builderPadding);
|
||||
console.log(' - addPaddingBytes:', addPaddingBytes);
|
||||
console.log(' - payment:', `"${payment}"`);
|
||||
|
||||
if (!superballPubkey || superballPubkey.length !== 64) {
|
||||
@@ -640,19 +613,10 @@
|
||||
audit: auditTag
|
||||
};
|
||||
|
||||
// Add optional fields
|
||||
console.log('DEBUG: Processing padding field:', padding);
|
||||
if (padding) {
|
||||
const paddingStr = generatePaddingString(padding);
|
||||
console.log('DEBUG: Generated padding result:', paddingStr);
|
||||
if (paddingStr !== null) {
|
||||
routingInstructions.padding = paddingStr;
|
||||
console.log('DEBUG: Added padding to routing instructions:', paddingStr);
|
||||
} else {
|
||||
console.log('DEBUG: Padding string was null, not adding to routing');
|
||||
}
|
||||
} else {
|
||||
console.log('DEBUG: No padding field provided');
|
||||
// Add daemon instruction to add padding when forwarding (if specified and not final bounce)
|
||||
if (!isLastBounce && addPaddingBytes > 0) {
|
||||
routingInstructions.add_padding_bytes = addPaddingBytes;
|
||||
console.log('DEBUG: Added add_padding_bytes instruction:', addPaddingBytes);
|
||||
}
|
||||
|
||||
if (payment) {
|
||||
@@ -669,6 +633,18 @@
|
||||
}
|
||||
// Note: If this IS the last bounce (first one created), no 'p' field means final posting
|
||||
|
||||
// Add builder padding to routing instructions (if specified)
|
||||
if (builderPadding > 0) {
|
||||
// Generate counting padding string (0123456789012...)
|
||||
let paddingString = '';
|
||||
for (let i = 0; i < builderPadding; i++) {
|
||||
paddingString += (i % 10).toString();
|
||||
}
|
||||
routingInstructions.padding = paddingString;
|
||||
|
||||
console.log('DEBUG: Added', builderPadding, 'bytes of builder padding to routing instructions');
|
||||
}
|
||||
|
||||
// Create the payload to encrypt
|
||||
const payload = {
|
||||
event: eventToWrap,
|
||||
|
||||
Reference in New Issue
Block a user