From 4920fb84871d955a68720d4c87015d79b09126d5 Mon Sep 17 00:00:00 2001 From: Radu-Cristian Popa Date: Thu, 15 Feb 2024 09:49:21 +0200 Subject: [PATCH] Initialize hash verification --- src/background/paymentFlow.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/background/paymentFlow.ts b/src/background/paymentFlow.ts index 17610a11..f5f55030 100644 --- a/src/background/paymentFlow.ts +++ b/src/background/paymentFlow.ts @@ -43,22 +43,17 @@ type Headers = SignatureHeaders & Partial export class PaymentFlowService { client: AuthenticatedClient - + sendingWalletAddress: WalletAddress + receivingWalletAddress: WalletAddress sendingPaymentPointerUrl: string receivingPaymentPointerUrl: string - incomingPaymentUrlId: string quoteUrlId: string - token: string interactRef: string - manageUrl: string - amount: string | number - - sendingWalletAddress: WalletAddress - receivingWalletAddress: WalletAddress + nonce: string | null constructor( sendingPaymentPointerUrl: string, @@ -220,6 +215,7 @@ export class PaymentFlowService { ) this.incomingPaymentUrlId = incomingPayment.id + this.nonce = crypto.randomUUID() // Revoke grant to avoid leaving users with unused, dangling grants. await this.client.grant.cancel({ @@ -257,7 +253,7 @@ export class PaymentFlowService { finish: { method: 'redirect', uri: 'http://localhost:3344', - nonce: new Date().getTime().toString(), + nonce: this.nonce, }, }, }, @@ -271,6 +267,9 @@ export class PaymentFlowService { // https://github.com/interledger/open-payments/issues/385 const interactRef = await this.confirmPayment(quoteAndOPGrant.interact.redirect) + // verify hash + // + const continuation = await this.client.grant.continue( { url: quoteAndOPGrant.continue.uri, @@ -379,6 +378,14 @@ export class PaymentFlowService { return activeTabs[0].id } + // TODO: Finish verify hash + async verifyHash(interactRef: string, interactNonce: string, hash: string): Promise { + const url = this.sendingWalletAddress.authServer + const data = new TextEncoder().encode( + `${this.nonce}\n${interactNonce}\n${interactRef}\n${url}/`, + ) + } + private async confirmPayment(url: string): Promise { const currentTabId = await this.getCurrentActiveTabId() @@ -390,7 +397,7 @@ export class PaymentFlowService { try { const tabUrl = new URL(changeInfo.url || '') const interactRef = tabUrl.searchParams.get('interact_ref') - // TODO: Verify hash + if (tabId === tab.id && interactRef) { tabs.update(currentTabId, { active: true }) tabs.remove(tab.id)