Skip to content

Commit

Permalink
Add payment hash verification to web client
Browse files Browse the repository at this point in the history
  • Loading branch information
ssantos21 committed Aug 12, 2024
1 parent 7fa1b95 commit 6ff4790
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
21 changes: 20 additions & 1 deletion clients/libs/web/lightning-latch.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,23 @@ const retrievePreImage = async (clientConfig, walletName, statechainId, batchId)
return { preimage: response?.data?.preimage };
}

export default { createPreImage, confirmPendingInvoice, retrievePreImage };
const getPaymentHash = async (clientConfig, batchId) => {

const url = `${clientConfig.statechainEntity}/transfer/paymenthash/${batchId}`;

try {
let response = await axios.get(url);

return response?.data?.hash;

} catch (error) {
if (error.response.status == 401) {
return null;
} else {
throw new Error(`Failed to retrieve payment hash: ${JSON.stringify(error.response.data)}`);
}
}

}

export default { createPreImage, confirmPendingInvoice, retrievePreImage, getPaymentHash };
8 changes: 7 additions & 1 deletion clients/libs/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ const retrievePreImage = async (clientConfig, walletName, statechainId, batchId)
return await lightningLatch.retrievePreImage(clientConfig, walletName, statechainId, batchId);
}

const getPaymentHash = async (clientConfig, batchId) => {

return await lightningLatch.getPaymentHash(clientConfig, batchId);
}

export default {
greet,
createWallet,
Expand All @@ -135,5 +140,6 @@ export default {
transferReceive,
paymentHash,
confirmPendingInvoice,
retrievePreImage
retrievePreImage,
getPaymentHash
}
3 changes: 2 additions & 1 deletion clients/tests/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "vite build",
"preview": "vite preview",
"test": "vitest",
"test:browser": "vitest --workspace=vitest.workspace.js"
"test:browser": "vitest --workspace=vitest.workspace.js",
"test:headless": "vitest --browser.name=chromium --browser.headless --exclude '**/data_bitcoin_regtest/**'"
},
"dependencies": {
"axios": "^1.7.2",
Expand Down
4 changes: 4 additions & 0 deletions clients/tests/web/test/tb04-simple-lightning-latch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ describe('TB04 - Simple Lightning Latch', () => {

await mercuryweblib.transferSend(clientConfig, wallet1.name, statechainId, transferAddress.transfer_receive, false, paymentHash.batchId );

const hashFromServer = await mercuryweblib.getPaymentHash(clientConfig, paymentHash.batchId);

expect(hashFromServer).to.equal(paymentHash.hash);

let transferReceive = await mercuryweblib.transferReceive(clientConfig, wallet2.name);

expect(transferReceive.isThereBatchLocked).toBe(true);
Expand Down
9 changes: 5 additions & 4 deletions clients/tests/web/vitest.workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export default defineWorkspace([
// https://playwright.dev
providerOptions: {},
},
exclude:[
...configDefaults.exclude,
'**/data_bitcoin_regtest/**'
],
},
exclude:[
...configDefaults.exclude,
'./data_bitcoin_regtest/*'
],

},
])
2 changes: 1 addition & 1 deletion token-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
config = "0.13.1"
reqwest = { version = "0.11.16", features = ["blocking", "json", "socks"] }
rocket = { version = "0.5.0-rc", features = ["json"] }
sqlx = { version = "0.8.0", features = [ "runtime-tokio", "postgres", "time", "uuid", "tls-rustls" ] }
sqlx = { version = "0.7", features = [ "runtime-tokio", "postgres", "time", "uuid", "tls-rustls" ] }
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
schemars = { version = "0.8.12", features = ["chrono", "uuid"] }
Expand Down

0 comments on commit 6ff4790

Please sign in to comment.