diff --git a/packages/cactus-plugin-htlc-eth-besu/package.json b/packages/cactus-plugin-htlc-eth-besu/package.json index f6395e1dd6d..17ce2e990ef 100644 --- a/packages/cactus-plugin-htlc-eth-besu/package.json +++ b/packages/cactus-plugin-htlc-eth-besu/package.json @@ -73,7 +73,7 @@ "@hyperledger/cactus-plugin-ledger-connector-besu": "1.2.0", "@hyperledger/cactus-test-tooling": "1.2.0", "axios": "0.21.4", - "bn.js": "5.1.1", + "bn.js": "5.2.1", "dotenv": "16.0.3", "ethers": "6.3.0", "express": "4.17.1", diff --git a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/private-htlc-helper.ts b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/private-htlc-helper.ts index 08b3428f602..5cedf6f7620 100644 --- a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/private-htlc-helper.ts +++ b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/private-htlc-helper.ts @@ -39,7 +39,7 @@ const main = async () => { const GENERATOR = new BN(11); const MODULUS = new BN(109); const SECRET_ALICE = new BN(3); - const SECRET_BOB = new BN(5); + const BOB_INPUT_TO_Z = new BN(50); const exponentiationAliceHashLock = modExp( GENERATOR, @@ -47,18 +47,22 @@ const main = async () => { SECRET_ALICE, ); const HASH_SECRET_ALICE = toBytes32(exponentiationAliceHashLock); - console.log(`Hashed secret from Alice: ${HASH_SECRET_ALICE}`); - console.log(`Secret from Alice: ${toBytes32(SECRET_ALICE)}`); + console.log(`Ya: ${HASH_SECRET_ALICE}`); + console.log(`sa: ${toBytes32(SECRET_ALICE)}`); - const Z = modExp(GENERATOR, MODULUS, SECRET_ALICE.add(SECRET_BOB)); + const Z = modExp(GENERATOR, MODULUS, SECRET_ALICE.mul(BOB_INPUT_TO_Z)); const BYTES_32_Z = toBytes32(Z); - console.log(`BYTES 32 Z: ${BYTES_32_Z}`); + console.log(`Z: ${BYTES_32_Z}`); - // equivalent to g^(sa + z) - const HASH_SECRET_BOB = toBytes32( - modExp(GENERATOR, MODULUS, Z.add(SECRET_ALICE)), - ); - console.log(`Hashed secret from Bob: ${HASH_SECRET_BOB}`); + const YB = exponentiationAliceHashLock + .mul(modExp(GENERATOR, MODULUS, new BN(Z.toNumber()))) + .mod(MODULUS); + console.log(`Yb: ${YB}`); + console.log(`Yb: ${toBytes32(YB)}`); + + const sb = SECRET_ALICE.add(Z); + console.log(`sb: ${sb}`); + console.log(`sb: ${toBytes32(sb)}`); } catch (error) { console.log("There has been an error ", error); throw new Error();