Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#226 Update Project ID Derivation #18

Merged
merged 22 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2fbf667
feat(mempool-ui): adds initial component files
nostrdev-com Nov 26, 2024
fa11913
fix: interface importing
nostrdev-com Nov 27, 2024
f1c08ea
chore: local dev setup
nostrdev-com Nov 27, 2024
7e02aca
adds angor ui components and interfaces
nostrdev-com Dec 3, 2024
b7113e4
feat(ui): adds blockchain view
nostrdev-com Dec 3, 2024
06d4d62
feature(angor-search): adds angor to search bar
nostrdev-com Dec 6, 2024
23ddcbe
feat(ui): updates angor module structure
nostrdev-com Dec 9, 2024
ec68406
feat(ui): adds pagination - part 1
nostrdev-com Dec 9, 2024
2686861
feat(ui): adds pagination to the list
nostrdev-com Dec 9, 2024
466d088
feat(ui): adds no-data skeleton
nostrdev-com Dec 9, 2024
d330658
fix: updates the project component
nostrdev-com Dec 10, 2024
89bcd75
fix: return empty array if no investments
nostrdev-com Dec 10, 2024
39254fa
chore: restores local dev settings
nostrdev-com Dec 11, 2024
1d85499
chore: removes redundant description
nostrdev-com Dec 11, 2024
ffce32d
fix: adds missed mock (#14)
nostrdev-com Dec 13, 2024
f5fb3a7
#144 - Extract NostrEventId instead Npub (#16)
nostrdev-com Dec 18, 2024
f9f6563
fix: reverse order of projects
nostrdev-com Dec 18, 2024
d696c4a
feat(derivation): implements new derivation
nostrdev-com Dec 19, 2024
61016bb
fix: removes uneeded import
nostrdev-com Dec 19, 2024
6e1a37f
fix: removes unneeded import
nostrdev-com Dec 19, 2024
7ca0c9e
Merge branch 'master' into issue-226-projectIdDerivation
nostrdev-com Dec 20, 2024
94783c1
fix: restores back from local dev settings
nostrdev-com Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading