Skip to content

Commit 2edb13a

Browse files
authored
Fix for endianness of contract hash (#119)
* Fixed endianness of contract hash. * Changed 'describe.only' to 'describe' in script.spec.ts to allow all tests to run
1 parent d84836e commit 2edb13a

File tree

4 files changed

+4
-10
lines changed

4 files changed

+4
-10
lines changed

src/issuance.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ function hashContract(contract) {
8989
(obj, key) => ({ ...obj, [key]: contract[key] }),
9090
{},
9191
);
92-
return bcrypto
93-
.sha256(Buffer.from(JSON.stringify(sortedContract)))
94-
.slice()
95-
.reverse();
92+
return bcrypto.sha256(Buffer.from(JSON.stringify(sortedContract)));
9693
}
9794
exports.hashContract = hashContract;
9895
/**

test/issuance.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('Issuance', () => {
312312
it(`should calculate the correct contract hash for ${contractFixture.contractJSON.name}`, () => {
313313
const computed = issuance.hashContract(contractFixture.contractJSON);
314314
assert.strictEqual(
315-
computed.toString('hex'),
315+
computed.reverse().toString('hex'),
316316
contractFixture.contractHash,
317317
);
318318
});

test/script.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as assert from 'assert';
22
import { describe, it } from 'mocha';
33
import { script } from '../ts_src';
44

5-
describe.only('script', () => {
5+
describe('script', () => {
66
describe('toASM', () => {
77
it('converts OP_CHECKLOCKTIMEVERIFY correctly', () => {
88
const asm = 'OP_CHECKLOCKTIMEVERIFY';

ts_src/issuance.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ export function hashContract(contract: IssuanceContract): Buffer {
7272
{},
7373
);
7474

75-
return bcrypto
76-
.sha256(Buffer.from(JSON.stringify(sortedContract)))
77-
.slice()
78-
.reverse();
75+
return bcrypto.sha256(Buffer.from(JSON.stringify(sortedContract)));
7976
}
8077

8178
/**

0 commit comments

Comments
 (0)