Skip to content

Commit

Permalink
Fixed endianness of contract hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
Randy808 committed Mar 11, 2024
1 parent d84836e commit 8e265b9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
5 changes: 1 addition & 4 deletions src/issuance.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ function hashContract(contract) {
(obj, key) => ({ ...obj, [key]: contract[key] }),
{},
);
return bcrypto
.sha256(Buffer.from(JSON.stringify(sortedContract)))
.slice()
.reverse();
return bcrypto.sha256(Buffer.from(JSON.stringify(sortedContract))).slice();
}
exports.hashContract = hashContract;
/**
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/contract_hash.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ticker": "ACE",
"version": 0
},
"contractHash": "2d9d310ab7885463357382856ec91c7f586b4d2dabfac23849c66aef3d378310"
"contractHash": "1083373def6ac64938c2faab2d4d6b587f1cc96e85827335635488b70a319d2d"
},
{
"contractJSON": {
Expand All @@ -23,7 +23,7 @@
"ticker": "DMp",
"version": 0
},
"contractHash": "459f2f4eb63d5cf6a4d1f8e54d3d5edb2245df63bd97e774864505c17ee188d8"
"contractHash": "d888e17ec105458674e797bd63df4522db5e3d4de5f8d1a4f65c3db64e2f9f45"
},
{
"contractJSON": {
Expand All @@ -36,7 +36,7 @@
"ticker": "EXO",
"version": 0
},
"contractHash": "86ddc3aeda751fb86e2c074c05e4a7ef9253f030ee2c55de0ee35e1b2afec49c"
"contractHash": "9cc4fe2a1b5ee30ede552cee30f05392efa7e4054c072c6eb81f75daaec3dd86"
},
{
"contractJSON": {
Expand All @@ -55,6 +55,6 @@
"version": 0,
"file": "QmSBt7nJMbHN6ndYGBbXj8FLCqdffnNRPbSu4oXLqV2p9E"
},
"contractHash": "6c797254d3974813ed556220bfab10cb3a70ee3a5bd827b8f9525920ec6b3d6b"
"contractHash": "6b3d6bec205952f9b827d85b3aee703acb10abbf206255ed134897d35472796c"
}
]
5 changes: 1 addition & 4 deletions ts_src/issuance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ export function hashContract(contract: IssuanceContract): Buffer {
{},
);

return bcrypto
.sha256(Buffer.from(JSON.stringify(sortedContract)))
.slice()
.reverse();
return bcrypto.sha256(Buffer.from(JSON.stringify(sortedContract))).slice();
}

/**
Expand Down

0 comments on commit 8e265b9

Please sign in to comment.