Skip to content

Commit

Permalink
Initialize hash verification
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Feb 15, 2024
1 parent bd81ba0 commit 4920fb8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/background/paymentFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,17 @@ type Headers = SignatureHeaders & Partial<ContentHeaders>

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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -257,7 +253,7 @@ export class PaymentFlowService {
finish: {
method: 'redirect',
uri: 'http://localhost:3344',
nonce: new Date().getTime().toString(),
nonce: this.nonce,
},
},
},
Expand All @@ -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,
Expand Down Expand Up @@ -379,6 +378,14 @@ export class PaymentFlowService {
return activeTabs[0].id
}

// TODO: Finish verify hash
async verifyHash(interactRef: string, interactNonce: string, hash: string): Promise<void> {
const url = this.sendingWalletAddress.authServer
const data = new TextEncoder().encode(
`${this.nonce}\n${interactNonce}\n${interactRef}\n${url}/`,
)
}

private async confirmPayment(url: string): Promise<string> {
const currentTabId = await this.getCurrentActiveTabId()

Expand All @@ -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)
Expand Down

0 comments on commit 4920fb8

Please sign in to comment.