Skip to content

Commit

Permalink
test(cucumber): fix metadata signature hash
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Aug 8, 2022
1 parent c54e0a7 commit c0ba271
Show file tree
Hide file tree
Showing 8 changed files with 4,161 additions and 262 deletions.
3 changes: 2 additions & 1 deletion integration_tests/features/MergeMining.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
When I ask for a block header by hash using last block header from proxy PROXY
Then Proxy response for block header by hash is valid

@critical
# BROKEN: get_block_template returns error 500
@critical @broken
Scenario: Simple Merge Mining
Given I have a seed node NODE
And I have wallet WALLET connected to all seed nodes
Expand Down
1 change: 1 addition & 0 deletions integration_tests/helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function createEnv(opts) {
[`${network}.base_node.p2p.transport.type`]: "tcp",
[`${network}.base_node.p2p.transport.tcp.listener_address`]: `/ip4/127.0.0.1/tcp/${baseNodePort}`,
[`${network}.base_node.p2p.public_address`]: `/ip4/127.0.0.1/tcp/${baseNodePort}`,
["base_node.report_grpc_error"]: true,

[`wallet.grpc_address`]: walletGrpcAddress,
[`${network}.wallet.grpc_address`]: walletGrpcAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,73 @@

const { blake2bInit, blake2bUpdate, blake2bFinal } = require("blakejs");
const { toLittleEndian } = require("./util");
class DomainHasher {
constructor(label, output_len = 32, key = null) {
this.hasher = blake2bInit(output_len, key);
this.chain(Buffer.from(label, "utf-8"));

class Blake256 {
constructor() {
this.hasher = blake2bInit(32);
}

chain(value) {
let buf = Buffer.from(value);
let le = toLittleEndian(buf.length, 64);
blake2bUpdate(this.hasher, le);
blake2bUpdate(this.hasher, buf);
chain(value, encoding = undefined) {
this.update(value, encoding);
return this;
}

chain_fixed_int(number, bits) {
blake2bUpdate(this.hasher, toLittleEndian(number, bits));
return this;
update(value, encoding = undefined) {
let buf = Buffer.isBuffer(value) ? value : Buffer.from(value, encoding);
blake2bUpdate(this.hasher, buf);
}

finalize() {
return blake2bFinal(this.hasher);
}
}

module.exports = DomainHasher;
class DomainHashing {
constructor(label) {
this.hasher = new Blake256();
this.update(Buffer.from(label, "utf-8"));
}
chain(value, encoding = undefined) {
this.update(value, encoding);
return this;
}

update(value, encoding = undefined) {
let buf = Buffer.isBuffer(value) ? value : Buffer.from(value, encoding);
let le = toLittleEndian(buf.length, 64);
this.hasher.update(le);
this.hasher.update(buf);
}

finalize() {
return this.hasher.finalize();
}
}

exports.DomainHashing = DomainHashing;
exports.Blake256 = Blake256;

function hasherWithLabel(label) {
let len = toLittleEndian(label.length, 64);
let hasher = new Blake256();
return hasher.chain(len).chain(label, "utf-8");
}

module.exports = {
// DomainHashing,
Blake256,
domainHashers: {
transactionKdf(label) {
return new DomainHashing(
`com.tari.base_layer.core.transactions.v0.kdf.${label}`
);
},
},
consensusHashers: {
transactionHasher(label) {
return hasherWithLabel(
`com.tari.base_layer.core.transactions.v0.${label}`
);
},
},
};
Loading

0 comments on commit c0ba271

Please sign in to comment.