Skip to content

Commit

Permalink
feat: update offchain relayer
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>
  • Loading branch information
RafaelAPB committed May 9, 2023
1 parent d681809 commit efd3fbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/cactus-plugin-htlc-eth-besu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,30 @@ 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,
MODULUS,
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();
Expand Down

0 comments on commit efd3fbb

Please sign in to comment.