Skip to content

Commit 2b28234

Browse files
committed
Add intent ID generation for purchase requests
FEATURE: Unique Order/Intent ID - Generate intent ID format: pi_<buyerPubkey8>_<timestamp> - Example: pi_8f7a9b2c_1761034427234 - Ties order to buyer (first 8 chars of pubkey) - Sortable by timestamp - Included in encrypted purchase intent message Technical Changes: - Add intentId field to PurchaseIntent interface - Update preparePurchaseIntent() to accept buyerPubkey parameter - Get buyer pubkey from signer.getPublicKey() before preparing messages - Intent ID logged for tracking in service logs Benefits: - Both buyer and seller can reference same order ID - Traceable in logs and conversation history - Unique identifier before Nostr event ID exists - Helps with order management and support
1 parent a9e0ee8 commit 2b28234

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/services/business/PurchaseBusinessService.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,19 @@ export class PurchaseBusinessService {
159159
* Prepare purchase intent message content
160160
*
161161
* @param sellerIntent - Purchase intent for a specific seller
162+
* @param buyerPubkey - Buyer's public key for generating intent ID
162163
* @returns JSON string for NIP-17 message content
163164
*/
164-
public preparePurchaseIntent(sellerIntent: PurchaseIntentBySeller): string {
165+
public preparePurchaseIntent(sellerIntent: PurchaseIntentBySeller, buyerPubkey: string): string {
166+
const timestamp = Date.now();
167+
const intentId = `pi_${buyerPubkey.slice(0, 8)}_${timestamp}`;
168+
165169
const intent: PurchaseIntent = {
166170
type: 'purchase-intent',
171+
intentId,
167172
products: sellerIntent.products,
168173
totalSats: sellerIntent.totalSats,
169-
timestamp: Date.now(),
174+
timestamp,
170175
};
171176

172177
const messageContent = JSON.stringify(intent, null, 2);
@@ -177,6 +182,7 @@ export class PurchaseBusinessService {
177182
sellerPubkey: sellerIntent.sellerPubkey,
178183
productCount: sellerIntent.products.length,
179184
totalSats: sellerIntent.totalSats,
185+
intentId,
180186
});
181187

182188
return messageContent;
@@ -220,6 +226,9 @@ export class PurchaseBusinessService {
220226
// Group by seller
221227
const sellerGroups = this.groupBySeller(items);
222228

229+
// Get buyer pubkey for intent ID generation
230+
const buyerPubkey = await signer.getPublicKey();
231+
223232
// Send to each seller
224233
const results: PurchaseIntentResult['details'] = [];
225234
let successCount = 0;
@@ -229,8 +238,8 @@ export class PurchaseBusinessService {
229238
const sellerGroup = sellerGroups[i];
230239

231240
try {
232-
// Prepare message content
233-
const messageContent = this.preparePurchaseIntent(sellerGroup);
241+
// Prepare message content with intent ID
242+
const messageContent = this.preparePurchaseIntent(sellerGroup, buyerPubkey);
234243

235244
// Send encrypted message via NIP-17
236245
const sendResult = await this.messagingService.sendMessage(

src/types/purchase.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export interface PurchaseIntent {
3838
/** Message type identifier */
3939
type: 'purchase-intent';
4040

41+
/** Unique intent ID for tracking (format: pi_<pubkey8>_<timestamp>) */
42+
intentId: string;
43+
4144
/** Array of products being purchased from this seller */
4245
products: PurchaseIntentItem[];
4346

0 commit comments

Comments
 (0)