From 545e3dfb1ad15f723b0cf55f1bdf188cf7dc45ab Mon Sep 17 00:00:00 2001 From: NostrDev Date: Fri, 20 Dec 2024 15:32:52 +0100 Subject: [PATCH] #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) * #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 --- backend/src/angor/AngorTransactionDecoder.ts | 5 +++-- .../tests/AngorTransactionDecoder.test.ts | 22 ++----------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/backend/src/angor/AngorTransactionDecoder.ts b/backend/src/angor/AngorTransactionDecoder.ts index 377f7905fe..2770b2bd84 100644 --- a/backend/src/angor/AngorTransactionDecoder.ts +++ b/backend/src/angor/AngorTransactionDecoder.ts @@ -357,8 +357,9 @@ export class AngorTransactionDecoder { * @returns an integer that is derived from integer representation of founder key hash. */ private getProjectIdDerivation(founderKeyHashInt: number): number { - // 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. - const retention = Math.floor(founderKeyHashInt / 2); + const intMaxValue = 0x7FFFFFFF; + + const retention = founderKeyHashInt & intMaxValue; if (retention > Math.pow(2, 31)) { throw new Error( diff --git a/backend/src/angor/tests/AngorTransactionDecoder.test.ts b/backend/src/angor/tests/AngorTransactionDecoder.test.ts index 29c6361874..92f5c96c9e 100644 --- a/backend/src/angor/tests/AngorTransactionDecoder.test.ts +++ b/backend/src/angor/tests/AngorTransactionDecoder.test.ts @@ -6,7 +6,6 @@ import { import * as bitcoinJS from 'bitcoinjs-lib'; import AngorProjectRepository from '../../repositories/AngorProjectRepository'; import AngorInvestmentRepository from '../../repositories/AngorInvestmentRepository'; -import DB from '../../database'; describe('AngorTransactionDecoder', () => { describe('Decoding transaction for Angor project creation', () => { @@ -18,8 +17,8 @@ describe('AngorTransactionDecoder', () => { founderKeyHashHex: '68828edc1c6312c915c8967475be57f42d45764105af8216f2da7170d033240a', founderKeyHashInt: 3493012490, - projectIdDeriviation: 1746506245, - projectId: 'angor1qzkfpckm2vnhdvfcwr7vdhwt7ns3rd95gr0age0', + projectIdDeriviation: 1345528842, + projectId: 'angor1quc59k4kt0nv62xhj72xtqfmzk55cexxmf6pkz7', nostrEventId: '0f2d8db8568bd3e12bdab1faa217fffc80459053967eff8bde0a65f14e2b7079', addressOnFeeOutput: 'tb1quc59k4kt0nv62xhj72xtqfmzk55cexxmae8lyc', txid: '0d28976a42bf7618ad9470cf0202e2eb06d6072e75e139eab012a160b7b480aa', @@ -261,23 +260,6 @@ describe('AngorTransactionDecoder', () => { data.projectIdDeriviation ); }); - - it('should throw an error if the retention is greater than 2 in power of 31', () => { - jest - .spyOn(angorDecoder as any, 'hashToInt') - .mockImplementation(() => Math.pow(2, 31) * 2 + 2); - - const keyHash = angorDecoder['getKeyHash'](keyHex); - const keyHashInt = angorDecoder['hashToInt'](keyHash); - - expect(() => - angorDecoder['getProjectIdDerivation'](keyHashInt) - ).toThrow( - new Error( - `Retention is too large. The max number is 2^31 (2,147,483,648).` - ) - ); - }); }); describe('getProjectId', () => {