Skip to content

Commit 22c507e

Browse files
authored
Merge pull request #471 from NEMStudios/task/g740_add_s_part_in_tx_hash
Added s-part in transaction hash
2 parents fa035d8 + ece8fa9 commit 22c507e

File tree

3 files changed

+6
-127
lines changed

3 files changed

+6
-127
lines changed

src/core/crypto/nacl_catapult.ts

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -669,28 +669,6 @@ const unpack25519 = (o, n) => {
669669
o[15] &= 0x7fff;
670670
};
671671

672-
export const cleanup = (arr) => {
673-
for (let i = 0; i < arr.length; i++) {
674-
arr[i] = 0;
675-
}
676-
};
677-
678-
export const crypto_shared_key_hash = (shared, pk, sk, hashfunc) => {
679-
const d = new Uint8Array(64);
680-
const p = [gf(), gf(), gf(), gf()];
681-
682-
hashfunc(d, sk, 32);
683-
d[0] &= 248;
684-
d[31] &= 127;
685-
d[31] |= 64;
686-
687-
const q = [gf(), gf(), gf(), gf()];
688-
// tslint:disable: no-use-before-declare
689-
unpackneg(q, pk);
690-
scalarmult(p, q, d);
691-
pack(shared, p);
692-
};
693-
694672
export const crypto_verify_32 = (x, xi, y, yi) => {
695673
return vn(x, xi, y, yi, 32);
696674
};
@@ -728,47 +706,6 @@ export const add = (p, q) => {
728706
M(p[3], e, h);
729707
};
730708

731-
export const modL = (r, x) => {
732-
// tslint:disable-next-line:one-variable-per-declaration
733-
let carry, i, j, k;
734-
for (i = 63; i >= 32; --i) {
735-
carry = 0;
736-
for (j = i - 32, k = i - 12; j < k; ++j) {
737-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
738-
carry = (x[j] + 128) >> 8;
739-
x[j] -= carry * 256;
740-
}
741-
x[j] += carry;
742-
x[i] = 0;
743-
}
744-
carry = 0;
745-
for (j = 0; j < 32; j++) {
746-
x[j] += carry - (x[31] >> 4) * L[j];
747-
carry = x[j] >> 8;
748-
x[j] &= 255;
749-
}
750-
for (j = 0; j < 32; j++) {
751-
x[j] -= carry * L[j];
752-
}
753-
for (i = 0; i < 32; i++) {
754-
x[i + 1] += x[i] >> 8;
755-
r[i] = x[i] & 255;
756-
}
757-
};
758-
759-
export const reduce = (r) => {
760-
// tslint:disable-next-line:one-variable-per-declaration
761-
let x = new Float64Array(64),
762-
i;
763-
for (i = 0; i < 64; i++) {
764-
x[i] = r[i];
765-
}
766-
for (i = 0; i < 64; i++) {
767-
r[i] = 0;
768-
}
769-
modL(r, x);
770-
};
771-
772709
export const pack = (r, p) => {
773710
// tslint:disable-next-line:one-variable-per-declaration
774711
const tx = gf(),
@@ -797,64 +734,6 @@ export const scalarmult = (p, q, s) => {
797734
}
798735
};
799736

800-
export const scalarbase = (p, s) => {
801-
const q = [gf(), gf(), gf(), gf()];
802-
set25519(q[0], X);
803-
set25519(q[1], Y);
804-
set25519(q[2], gf1);
805-
M(q[3], X, Y);
806-
scalarmult(p, q, s);
807-
};
808-
809-
export const unpackneg = (r, p) => {
810-
// tslint:disable-next-line:one-variable-per-declaration
811-
const t = gf(),
812-
chk = gf(),
813-
num = gf(),
814-
den = gf(),
815-
den2 = gf(),
816-
den4 = gf(),
817-
den6 = gf();
818-
819-
set25519(r[2], gf1);
820-
unpack25519(r[1], p);
821-
S(num, r[1]);
822-
M(den, num, D);
823-
Z(num, num, r[2]);
824-
A(den, r[2], den);
825-
826-
S(den2, den);
827-
S(den4, den2);
828-
M(den6, den4, den2);
829-
M(t, den6, num);
830-
M(t, t, den);
831-
832-
pow2523(t, t);
833-
M(t, t, num);
834-
M(t, t, den);
835-
M(t, t, den);
836-
M(r[0], t, den);
837-
838-
S(chk, r[0]);
839-
M(chk, chk, den);
840-
if (neq25519(chk, num)) {
841-
M(r[0], r[0], I);
842-
}
843-
844-
S(chk, r[0]);
845-
M(chk, chk, den);
846-
if (neq25519(chk, num)) {
847-
return -1;
848-
}
849-
850-
if (par25519(r[0]) === (p[31] >> 7)) {
851-
Z(r[0], gf0, r[0]);
852-
}
853-
854-
M(r[3], r[0], r[1]);
855-
return 0;
856-
};
857-
858737
export const unpack = (r, p) => {
859738
// tslint:disable-next-line:one-variable-per-declaration
860739
const t = gf(),

src/model/transaction/Transaction.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ export abstract class Transaction {
138138
TransactionType.AGGREGATE_COMPLETE,
139139
].find((type: TransactionType) => entityType === type) !== undefined;
140140

141-
// 1) take "R" part of a signature (first 32 bytes)
142-
const signatureR: Uint8Array = transactionBytes.slice(8, 8 + 32);
141+
// 1) add full signature
142+
const signature: Uint8Array = transactionBytes.slice(8, 8 + 64);
143143

144144
// 2) add public key to match sign/verify behavior (32 bytes)
145-
const pubKeyIdx: number = signatureR.length;
145+
const pubKeyIdx: number = signature.length;
146146
const publicKey: Uint8Array = transactionBytes.slice(8 + 64, 8 + 64 + 32);
147147

148148
// 3) add generationHash (32 bytes)
@@ -162,12 +162,12 @@ export abstract class Transaction {
162162
// 5) concatenate binary hash parts
163163
// layout: `signature_R || signerPublicKey || generationHash || EntityDataBuffer`
164164
const entityHashBytes: Uint8Array = new Uint8Array(
165-
signatureR.length
165+
signature.length
166166
+ publicKey.length
167167
+ generationHash.length
168168
+ transactionBody.length,
169169
);
170-
entityHashBytes.set(signatureR, 0);
170+
entityHashBytes.set(signature, 0);
171171
entityHashBytes.set(publicKey, pubKeyIdx);
172172
entityHashBytes.set(generationHash, generationHashIdx);
173173
entityHashBytes.set(transactionBody, transactionBodyIdx);

test/model/transaction/Transaction.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ describe('Transaction', () => {
255255
);
256256

257257
// expected values
258-
const knownHash_sha3 = '709373248659274C5933BEA2920942D6C7B48B9C2DA4BAEE233510E71495931F';
258+
const knownHash_sha3 = 'F0F5A62A0863D45E832B50EFF4E2F68157268A5D1674EC1068D82EC5F88D950B';
259259
const generationHashBytes = Array.from(Convert.hexToUint8('988C4CDCE4D188013C13DE7914C7FD4D626169EF256722F61C52EFBE06BD5A2C'));
260260
const generationHashBytes_mt = Array.from(Convert.hexToUint8('17FA4747F5014B50413CCF968749604D728D7065DC504291EEE556899A534CBB'));
261261

0 commit comments

Comments
 (0)