Skip to content

Commit

Permalink
mempool#226 Update Project ID Derivation (#18)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nostrdev-com authored Dec 20, 2024
1 parent e5ff277 commit 545e3df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
5 changes: 3 additions & 2 deletions backend/src/angor/AngorTransactionDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 2 additions & 20 deletions backend/src/angor/tests/AngorTransactionDecoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -18,8 +17,8 @@ describe('AngorTransactionDecoder', () => {
founderKeyHashHex:
'68828edc1c6312c915c8967475be57f42d45764105af8216f2da7170d033240a',
founderKeyHashInt: 3493012490,
projectIdDeriviation: 1746506245,
projectId: 'angor1qzkfpckm2vnhdvfcwr7vdhwt7ns3rd95gr0age0',
projectIdDeriviation: 1345528842,
projectId: 'angor1quc59k4kt0nv62xhj72xtqfmzk55cexxmf6pkz7',
nostrEventId: '0f2d8db8568bd3e12bdab1faa217fffc80459053967eff8bde0a65f14e2b7079',
addressOnFeeOutput: 'tb1quc59k4kt0nv62xhj72xtqfmzk55cexxmae8lyc',
txid: '0d28976a42bf7618ad9470cf0202e2eb06d6072e75e139eab012a160b7b480aa',
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 545e3df

Please sign in to comment.