Skip to content

Update NDK to v2.12.2 #2041

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

Merged
merged 3 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions lib/nostr.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const RELAYS_BLACKLIST = []
/**
* @import {NDKSigner} from '@nostr-dev-kit/ndk'
* @import { NDK } from '@nostr-dev-kit/ndk'
* @import {NDKNwc} from '@nostr-dev-kit/ndk'
* @import {NDKNWCWallet} from '@nostr-dev-kit/ndk-wallet'
* @typedef {Object} Nostr
* @property {NDK} ndk
* @property {function(string, {logger: Object}): Promise<NDKNwc>} nwc
* @property {function(string, {logger: Object}): Promise<NDKNWCWallet>} nwc
* @property {function(Object, {privKey: string, signer: NDKSigner}): Promise<NDKEvent>} sign
* @property {function(Object, {relays: Array<string>, privKey: string, signer: NDKSigner}): Promise<NDKEvent>} publish
*/
Expand Down
231 changes: 220 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"@apollo/server": "^4.11.0",
"@as-integrations/next": "^3.1.0",
"@auth/prisma-adapter": "^2.7.0",
"@cashu/cashu-ts": "^2.4.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunately required even though it's supposed to be a peer dependency of ndk-wallet (which is itself a peer dependency).

If I don't install this, the app fails to start:

app  | 2025-03-30T21:06:26.954347000Z  ⨯ ./node_modules/@nostr-dev-kit/ndk-wallet/dist/index.mjs:344:1
app  | 2025-03-30T21:06:26.954485000Z Module not found: Can't resolve '@cashu/cashu-ts'
app  | 2025-03-30T21:06:26.954523000Z
app  | 2025-03-30T21:06:26.954556000Z https://nextjs.org/docs/messages/module-not-found
app  | 2025-03-30T21:06:26.954595000Z
app  | 2025-03-30T21:06:26.954632000Z Import trace for requested module:
app  | 2025-03-30T21:06:26.954660000Z ./wallets/nwc/index.js
app  | 2025-03-30T21:06:26.954684000Z ./wallets/nwc/client.js
app  | 2025-03-30T21:06:26.954706000Z ./wallets/client.js
app  | 2025-03-30T21:06:26.954740000Z ./wallets/index.js
app  | 2025-03-30T21:06:26.954769000Z ./components/pay-bounty.js
app  | 2025-03-30T21:06:26.954795000Z ./components/comment.js
app  | 2025-03-30T21:06:26.954822000Z ./components/items.js
app  | 2025-03-30T21:06:26.954850000Z ./pages/~/index.js
app  | 2025-03-30T21:06:26.982840000Z    automatically enabled Fast Refresh for 1 custom loader
app  | 2025-03-30T21:06:29.830712000Z  ⨯ ./node_modules/@nostr-dev-kit/ndk-wallet/dist/index.mjs:344:1
app  | 2025-03-30T21:06:29.830824000Z Module not found: Can't resolve '@cashu/cashu-ts'
app  | 2025-03-30T21:06:29.830861000Z
app  | 2025-03-30T21:06:29.830892000Z https://nextjs.org/docs/messages/module-not-found
app  | 2025-03-30T21:06:29.830928000Z
app  | 2025-03-30T21:06:29.830959000Z Import trace for requested module:
app  | 2025-03-30T21:06:29.831002000Z ./wallets/nwc/index.js
app  | 2025-03-30T21:06:29.831036000Z ./wallets/nwc/client.js
app  | 2025-03-30T21:06:29.831068000Z ./wallets/client.js
app  | 2025-03-30T21:06:29.831098000Z ./wallets/index.js
app  | 2025-03-30T21:06:29.831141000Z ./pages/_app.js

"@graphql-tools/schema": "^10.0.6",
"@lightninglabs/lnc-web": "^0.3.2-alpha",
"@noble/curves": "^1.6.0",
"@nostr-dev-kit/ndk": "^2.10.5",
"@nostr-dev-kit/ndk": "^2.12.2",
"@nostr-dev-kit/ndk-wallet": "^0.5.0",
"@opensearch-project/opensearch": "^2.12.0",
"@prisma/client": "^5.20.0",
"@slack/web-api": "^7.6.0",
Expand Down
62 changes: 62 additions & 0 deletions scripts/test-nip57.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

# https://github.com/nostr-protocol/nips/blob/master/57.md
set -e

# test user with attached wallet
# TODO: attach wallet to test01 via psql if not already attached?
USERNAME=test01

# XXX this should match NOSTR_PRIVATE_KEY in .env.development
NOSTR_PRIVATE_KEY=5f30b7e7714360f51f2be2e30c1d93b7fdf67366e730658e85777dfcc4e4245f
NOSTR_PUBLIC_KEY=$(nak key public $NOSTR_PRIVATE_KEY)

SINCE=$(date +%s)

function create_event() {
nak event -k 9734 \
--tag p=$NOSTR_PUBLIC_KEY \
--tag 'relays=wss://relay.primal.net' \
--tag amount=100000
}

function url_encode() {
cat - | jq -sRr @uri
}

function test_exit() {
if [ $1 -eq 0 ]; then
echo "worker publishes nip-57 zap receipts: PASSED"
else
echo "worker publishes nip-57 zap receipts: FAILED"
fi
exit $1
}

create_event | nak verify

# create a zap request event (kind 9734)
EVENT="$(create_event)"

echo "generated zap request event:"
echo "$EVENT" | jq

echo $EVENT | nak verify

# XXX make sure amount is higher than dust limit of receiver's wallet
echo -n "sending zap request event LNURL endpoint ... "
PR=$(curl -s "http://localhost:3000/api/lnurlp/$USERNAME/pay?amount=100000&nostr=$(echo $EVENT | url_encode)" | jq -r .pr)
echo "OK"

[ "$PR" == "null" ] && echo "error: LNURL endpoint did not return bolt11" && test_exit 1
echo $PR

sndev fund --cln $PR

# subscribe to zap receipt event (kind 9735)
echo -n "waiting for zap receipt event ... "
sleep 3
PR2=$(nak -q req -k 9735 -p $NOSTR_PUBLIC_KEY --limit 1 wss://relay.primal.net | jq -r '.tags[] | select(.[0] == "bolt11") | .[1]')
echo "OK"

[ "$PR" == "$PR2" ] && test_exit 0 || test_exit 1
2 changes: 1 addition & 1 deletion wallets/nwc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export async function testSendPayment ({ nwcUrl }, { signal }) {
}

export async function sendPayment (bolt11, { nwcUrl }, { signal }) {
const result = await nwcTryRun(nwc => nwc.payInvoice(bolt11), { nwcUrl }, { signal })
const result = await nwcTryRun(nwc => nwc.lnPay({ pr: bolt11 }), { nwcUrl }, { signal })
return result.preimage
}
Loading