Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
pablof7z committed Sep 30, 2024
1 parent 543067b commit 8852717
Show file tree
Hide file tree
Showing 80 changed files with 25,383 additions and 19,563 deletions.
5 changes: 0 additions & 5 deletions .changeset/brave-ties-listen.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/calm-hornets-care.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/hungry-pans-draw.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/moody-worms-tie.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/rude-owls-punch.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/wise-dolls-provide.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/witty-starfishes-move.md

This file was deleted.

52 changes: 26 additions & 26 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
{
"name": "NDK devcontainer",
"build": {
// Path is relative to the devcontainer.json file.
"dockerfile": "Dockerfile",
"context": "../"
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
}
}
},
// Add pnpm bin to path, so we have turbo available
"postStartCommand": "echo 'export PATH=$(pnpm bin):$PATH' >> ~/.bashrc && . ~/.bashrc"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
"name": "NDK devcontainer",
"build": {
// Path is relative to the devcontainer.json file.
"dockerfile": "Dockerfile",
"context": "../"
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
}
}
},
// Add pnpm bin to path, so we have turbo available
"postStartCommand": "echo 'export PATH=$(pnpm bin):$PATH' >> ~/.bashrc && . ~/.bashrc"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
102 changes: 51 additions & 51 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@
name: Deploy VitePress site to Pages

on:
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
# using the `master` branch as the default branch.
push:
branches: [master]
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
# using the `master` branch as the default branch.
push:
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: pages
cancel-in-progress: false
group: pages
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Not needed if lastUpdated is not enabled
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
- name: Setup Node
uses: pnpm/action-setup@v3 # Uncomment this if you're using pnpm
with:
node-version: 21
cache: pnpm # or pnpm / yarn
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: pnpm install # or pnpm install / yarn install / bun install
- name: Build dexie typedoc
run: cd ndk-cache-dexie && pnpm typedoc && cat docs/interfaces/NDKCacheAdapterDexieOptions.md >> ../docs/cache/dexie.md
- name: Build with VitePress
run: pnpm docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
- name: Build typedoc
run: cd ndk && pnpm typedoc --out ../docs/.vitepress/dist/api
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Not needed if lastUpdated is not enabled
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
- name: Setup Node
uses: pnpm/action-setup@v3 # Uncomment this if you're using pnpm
with:
node-version: 21
cache: pnpm # or pnpm / yarn
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: pnpm install # or pnpm install / yarn install / bun install
- name: Build dexie typedoc
run: cd ndk-cache-dexie && pnpm typedoc && cat docs/interfaces/NDKCacheAdapterDexieOptions.md >> ../docs/cache/dexie.md
- name: Build with VitePress
run: pnpm docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
- name: Build typedoc
run: cd ndk && pnpm typedoc --out ../docs/.vitepress/dist/api
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 0 additions & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ pnpm install
cd ndk
pnpm build
```

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ NDK is a [nostr](<[url](https://github.com/nostr-protocol/nostr)>) development k
npm add @nostr-dev-kit/ndk
```


## Debugging

NDK uses the `debug` package to assist in understanding what's happening behind the hood. If you are building a package
Expand Down
2 changes: 1 addition & 1 deletion REFERENCES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ to this list.
- Stateful wrapper library of React hooks around NDK.
- [magicCity h=n](https://github.com/tezosmiami/hicetnunc) - By [@hicetnunc2000](https://github.com/hicetnunc2000/), [@tezosmiami](https://njump.me/npub190rqwj0nud4uhvmaeg7cgn0gypu0s09j87vqjluhfhju0req2khsskh9w7)
- [notepress](https://github.com/utxo-one/notepress) - By [@utxo](httsp://njump.me/[email protected])
- No frameworks! A very simple long-form (NIP-23) reader
- No frameworks! A very simple long-form (NIP-23) reader
11 changes: 6 additions & 5 deletions demos/get-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "websocket-polyfill";
import NDK, { NDKRelay } from "@nostr-dev-kit/ndk";
import { relaysFromArgs } from "./utils/relays-from-args";

import chalk from 'chalk';
import chalk from "chalk";
import { verifySignature } from "nostr-tools";
const log = console.log;
const time = console.time;
Expand All @@ -18,10 +18,12 @@ infoLog(`Starting perftest`);
const relays = relaysFromArgs();

const ndk = new NDK();
ndk.pool.on("relay:connect", (r: NDKRelay) => { infoLog(`Connected to relay ${r.url}`); });
ndk.pool.on("relay:connect", (r: NDKRelay) => {
infoLog(`Connected to relay ${r.url}`);
});
for (const relay of relays) {
ndk.addExplicitRelay(relay, undefined, false);
log(relay.url)
log(relay.url);
}
await ndk.connect(2000);

Expand All @@ -35,8 +37,7 @@ async function fetchAndVerifyEvents(label: string, skipVerification: boolean) {
timeEnd(info("fetchEvents"));
infoLog(`Fetched ${events.size} events`);

const eventObjects = Array.from(events.values())
.map((e) => e.rawEvent());
const eventObjects = Array.from(events.values()).map((e) => e.rawEvent());

time(info("verifySignature"));
for (const event of eventObjects) {
Expand Down
4 changes: 2 additions & 2 deletions demos/utils/relays-from-args.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NDKRelay } from "@nostr-dev-kit/ndk";

const defaultRelays = [ "wss://nos.lol" ];
const defaultRelays = ["wss://nos.lol"];

export function relaysFromArgs(): NDKRelay[] {
const explicitRelayUrls: string[] = [];
Expand Down Expand Up @@ -42,4 +42,4 @@ export function relaysFromArgs(): NDKRelay[] {
}

return relays;
}
}
44 changes: 44 additions & 0 deletions docs/wallet/discover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Discover wallets

A user might have configured your application to use a specific wallet (e.g. via WebLN), or they could be
interfacing with your application with a NIP-60 wallet created somewhere else.

Additionally, a user might have NIP-61 nutzaps enabled.

The `NDKWalletService` provides a simple interface to handle these cases:
* Configure + Discover configured wallets
* See NIP-61 nutzaps

## Discovering configured wallets
```typescript
const walletService = new NDKWalletService(ndk);

walletService.start();
walletService.on("wallet", (wallet: NDKWallet, isDefault: boolean) => {
console.log("Found a wallet of type " + wallet.type, isDefault ? "(default)" : "");
});
```

`walletService.start()` will do the following:
* If you have established a client name via `ndk.clientName`, it will look for a NIP-78 configuration

## Configuring a wallet for your application
```typescript
ndk.clientName = 'my-application';
const walletService = new NDKWalletService(ndk);
const wallet = new NDKWebLNWallet();
await walletService.setDefaultWallet(wallet);
```

`walletService.setDefaultWallet(wallet)` will add to your applications's NIP-78, the configuration to be able to use this wallet next time your application starts, next time your application is initialized, `walletService.start()` will emit a `wallet` event for this wallet.

## Seeing NIP-61 nutzaps
```typescript
const walletService = new NDKWalletService(ndk);
walletService.start();
walletService.on("nutzap", (nutzap: NDKNutzap) => {
console.log("Received a nutzap from " + nutzap.pubkey + " for " + nutzap.amount + " " + nutzap.unit + " on mint " + nutzap.mint);
// -> "Received a nutzap from fa98..... for 1 usd on mint https://..."
});
```

17 changes: 5 additions & 12 deletions examples/hello-world/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
],
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"lib": [
"ESNext"
],
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"strict": true,
Expand All @@ -21,5 +14,5 @@
"skipLibCheck": true,
"sourceMap": true,
"moduleResolution": "node"
},
}
}
}
20 changes: 14 additions & 6 deletions examples/outbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import NDK, { NDKEvent, NDKKind, NDKPrivateKeySigner, NostrEvent } from "@nostr-
// const signer = new NDKPrivateKeySigner("...");

const ndk = new NDK({
outboxRelayUrls: [ "wss://purplepag.es" ],
outboxRelayUrls: ["wss://purplepag.es"],
enableOutboxModel: true,
});

const pablo = ndk.getUser({npub: "npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft"});
const pablo = ndk.getUser({
npub: "npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft",
});
// const user = pablo;
// const fiatjaf = ndk.getUser({npub: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6"});

Expand Down Expand Up @@ -48,10 +50,16 @@ setTimeout(async () => {

console.log("Follows", follows.size);



setTimeout(async () => {
const feed = await ndk.fetchEvents({ kinds: [1], authors: Array.from(follows).slice(0, 20000).map(u => u.pubkey) }, { subId: "feed"});
const feed = await ndk.fetchEvents(
{
kinds: [1],
authors: Array.from(follows)
.slice(0, 20000)
.map((u) => u.pubkey),
},
{ subId: "feed" }
);
console.log("Feed", feed.size);
}, 4000);
}, 2000)
}, 2000);
Loading

0 comments on commit 8852717

Please sign in to comment.