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

start cashu lib with bun tests #215

Merged
merged 7 commits into from
Dec 23, 2024
Merged

start cashu lib with bun tests #215

merged 7 commits into from
Dec 23, 2024

Conversation

gudnuf
Copy link
Contributor

@gudnuf gudnuf commented Dec 11, 2024

I started to create the cashu library we will need. This is in lib/cashu.

In types.ts I added types for proof secrets which I would appreciate feedback on. For now we are only using the P2PK secret but as we want to add advanced functionality like DLCs, we will be using these secrets a lot.

A secret can be a string (NUT00) or of the well-known secret format described in NUT10. For NUT10 secrets I created two types. There is the tuple type ParsedNUT10Secret that is what we get when we call JSON.parse(secret), and then I convert that to NUT10Secret which is easier to work with.

I also setup testing using bun. All that was needed was to add bun's types to the project

@gudnuf gudnuf requested a review from jbojcic1 December 11, 2024 19:32
Copy link

vercel bot commented Dec 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
boardwalk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 23, 2024 10:51pm

Copy link

github-actions bot commented Dec 11, 2024

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 81add7c.

♻️ This comment has been updated with latest results.

package.json Show resolved Hide resolved
lib/cashu/types.ts Outdated Show resolved Hide resolved
lib/cashu/proof.ts Outdated Show resolved Hide resolved
lib/cashu/proof.ts Outdated Show resolved Hide resolved
lib/cashu/secret.ts Outdated Show resolved Hide resolved
lib/cashu/secret.ts Outdated Show resolved Hide resolved
lib/cashu/secret.ts Outdated Show resolved Hide resolved
test/cashu/secret.test.ts Outdated Show resolved Hide resolved
test/cashu/secret.test.ts Show resolved Hide resolved
lib/cashu/proof.ts Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
app/lib/cashu/types.ts Show resolved Hide resolved
app/lib/cashu/types.ts Outdated Show resolved Hide resolved
app/lib/cashu/types.ts Show resolved Hide resolved
app/lib/cashu/types.ts Outdated Show resolved Hide resolved
app/lib/cashu/types.ts Show resolved Hide resolved
@gudnuf
Copy link
Contributor Author

gudnuf commented Dec 22, 2024

I'm getting this type error and I think it's because I added the bun types. Should we try to change the types in app/lib/timeout or figure out why adding bun types causes this error. Makes sense to me to use Bun's types for Timer instead of node types.

error TS2322: Type 'Timer' is not assignable to type 'number | Timeout | null'.
  Property '[Symbol.dispose]' is missing in type 'Timer' but required in type 'Timeout'.

30       longTimeout.id = setTimeout(
         ~~~~~~~~~~~~~~

  node_modules/@types/node/timers.d.ts:130:17
    130                 [Symbol.dispose](): void;
                        ~~~~~~~~~~~~~~~~
    '[Symbol.dispose]' is declared here.


Found 1 error in app/lib/timeout.ts:30

@jbojcic1
Copy link
Collaborator

jbojcic1 commented Dec 22, 2024

I'm getting this type error and I think it's because I added the bun types. Should we try to change the types in app/lib/timeout or figure out why adding bun types causes this error. Makes sense to me to use Bun's types for Timer instead of node types.

error TS2322: Type 'Timer' is not assignable to type 'number | Timeout | null'.
  Property '[Symbol.dispose]' is missing in type 'Timer' but required in type 'Timeout'.

30       longTimeout.id = setTimeout(
         ~~~~~~~~~~~~~~

  node_modules/@types/node/timers.d.ts:130:17
    130                 [Symbol.dispose](): void;
                        ~~~~~~~~~~~~~~~~
    '[Symbol.dispose]' is declared here.


Found 1 error in app/lib/timeout.ts:30

I am not sure why it happens. Let's fix it by defining type like this:

type LongTimeout = {
  id: ReturnType<typeof setTimeout> | null; // Tracks the latest timeout ID
};

this way we are safe no matter the runtime

app/lib/cashu/secret.ts Outdated Show resolved Hide resolved
@gudnuf
Copy link
Contributor Author

gudnuf commented Dec 23, 2024

I am not sure why it happens. Let's fix it by defining type like this:

Nice! fixed

* remove ParsedNUT10Secret and NUT10SecretData types

* use safe json parsing

* return success in safeJsonParse and use zod in guest-account-storage

* move schemas to types and infer from zod

* redefined types using the schemas
@gudnuf gudnuf merged commit 0ee8428 into master Dec 23, 2024
3 checks passed
@gudnuf gudnuf deleted the cashu-lib branch December 23, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants