Skip to content

Commit 545e3df

Browse files
authoredDec 20, 2024··
mempool#226 Update Project ID Derivation (#18)
* feat(mempool-ui): adds initial component files * fix: interface importing * chore: local dev setup * adds angor ui components and interfaces * feat(ui): adds blockchain view * feature(angor-search): adds angor to search bar * feat(ui): updates angor module structure * feat(ui): adds pagination - part 1 * feat(ui): adds pagination to the list * feat(ui): adds no-data skeleton * fix: updates the project component * fix: return empty array if no investments * chore: restores local dev settings * chore: removes redundant description * fix: adds missed mock (#14) * mempool#144 - Extract NostrEventId instead Npub (#16) * fix: updates signet challenge * feat(eventId): initial commit * feat(event-id): removes npub from query * feat(eventId): updates unit tests * fix: reverse order of projects * feat(derivation): implements new derivation * fix: removes uneeded import * fix: removes unneeded import * fix: restores back from local dev settings
1 parent e5ff277 commit 545e3df

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed
 

‎backend/src/angor/AngorTransactionDecoder.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,9 @@ export class AngorTransactionDecoder {
357357
* @returns an integer that is derived from integer representation of founder key hash.
358358
*/
359359
private getProjectIdDerivation(founderKeyHashInt: number): number {
360-
// The max size of bip32 derivation range is 2,147,483,648 (2^31) the max number of uint is 4,294,967,295 so we must to divide by 2 and round it to the floor.
361-
const retention = Math.floor(founderKeyHashInt / 2);
360+
const intMaxValue = 0x7FFFFFFF;
361+
362+
const retention = founderKeyHashInt & intMaxValue;
362363

363364
if (retention > Math.pow(2, 31)) {
364365
throw new Error(

‎backend/src/angor/tests/AngorTransactionDecoder.test.ts

+2-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import * as bitcoinJS from 'bitcoinjs-lib';
77
import AngorProjectRepository from '../../repositories/AngorProjectRepository';
88
import AngorInvestmentRepository from '../../repositories/AngorInvestmentRepository';
9-
import DB from '../../database';
109

1110
describe('AngorTransactionDecoder', () => {
1211
describe('Decoding transaction for Angor project creation', () => {
@@ -18,8 +17,8 @@ describe('AngorTransactionDecoder', () => {
1817
founderKeyHashHex:
1918
'68828edc1c6312c915c8967475be57f42d45764105af8216f2da7170d033240a',
2019
founderKeyHashInt: 3493012490,
21-
projectIdDeriviation: 1746506245,
22-
projectId: 'angor1qzkfpckm2vnhdvfcwr7vdhwt7ns3rd95gr0age0',
20+
projectIdDeriviation: 1345528842,
21+
projectId: 'angor1quc59k4kt0nv62xhj72xtqfmzk55cexxmf6pkz7',
2322
nostrEventId: '0f2d8db8568bd3e12bdab1faa217fffc80459053967eff8bde0a65f14e2b7079',
2423
addressOnFeeOutput: 'tb1quc59k4kt0nv62xhj72xtqfmzk55cexxmae8lyc',
2524
txid: '0d28976a42bf7618ad9470cf0202e2eb06d6072e75e139eab012a160b7b480aa',
@@ -261,23 +260,6 @@ describe('AngorTransactionDecoder', () => {
261260
data.projectIdDeriviation
262261
);
263262
});
264-
265-
it('should throw an error if the retention is greater than 2 in power of 31', () => {
266-
jest
267-
.spyOn(angorDecoder as any, 'hashToInt')
268-
.mockImplementation(() => Math.pow(2, 31) * 2 + 2);
269-
270-
const keyHash = angorDecoder['getKeyHash'](keyHex);
271-
const keyHashInt = angorDecoder['hashToInt'](keyHash);
272-
273-
expect(() =>
274-
angorDecoder['getProjectIdDerivation'](keyHashInt)
275-
).toThrow(
276-
new Error(
277-
`Retention is too large. The max number is 2^31 (2,147,483,648).`
278-
)
279-
);
280-
});
281263
});
282264

283265
describe('getProjectId', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.