diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index 4d568a1cd..b537acb3f 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -24,7 +24,7 @@ concurrency: jobs: check-book: name: Check book - runs-on: ubuntu-latest + runs-on: macos-latest # Use macOS to check also Swift snippets steps: - name: Checkout uses: actions/checkout@v3 @@ -32,6 +32,11 @@ jobs: - name: Install just run: cargo install just + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.12" + # Required for kotlin snippets - name: Set up Java 17 uses: actions/setup-java@v2 @@ -67,4 +72,4 @@ jobs: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v3 \ No newline at end of file + uses: actions/deploy-pages@v3 diff --git a/book/snippets/justfile b/book/snippets/justfile index 603a1c1f6..3341c41a1 100644 --- a/book/snippets/justfile +++ b/book/snippets/justfile @@ -1,4 +1,4 @@ -test: rust python js kotlin +test: rust python js kotlin swift rust: cd rust && cargo build @@ -11,3 +11,6 @@ js: kotlin: cd kotlin && just test + +swift: + cd swift && just test diff --git a/book/snippets/swift/NostrSnippets/Package.swift b/book/snippets/swift/NostrSnippets/Package.swift index b4fb61e7f..426f66d21 100644 --- a/book/snippets/swift/NostrSnippets/Package.swift +++ b/book/snippets/swift/NostrSnippets/Package.swift @@ -1,13 +1,13 @@ -// swift-tools-version: 5.9 +// swift-tools-version: 5.5 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "NostrSnippets", - platforms: [.macOS(.v13)], + platforms: [.macOS(.v12)], dependencies: [ - .package(url: "https://github.com/rust-nostr/nostr-sdk-swift", from:"0.36.0") + .package(url: "https://github.com/rust-nostr/nostr-sdk-swift", from: "0.36.0") ], targets: [ .executableTarget( diff --git a/book/snippets/swift/NostrSnippets/Sources/Keys.swift b/book/snippets/swift/NostrSnippets/Sources/Keys.swift index 0c037248c..7990dd6c6 100644 --- a/book/snippets/swift/NostrSnippets/Sources/Keys.swift +++ b/book/snippets/swift/NostrSnippets/Sources/Keys.swift @@ -2,5 +2,12 @@ import NostrSDK import Foundation func keys() { - // TODO + // ANCHOR: generate + let keys = Keys.generate() + print("Public key (hex): \(keys.publicKey.toHex())") + print("Secret key (hex): \(keys.secretKey.toHex())") + + print("Public key (bech32): \(keys.publicKey.toBech32())") + print("Secret key (bech32): \(keys.secretKey.toBech32())") + // ANCHOR_END: generate } diff --git a/book/snippets/swift/NostrSnippets/justfile b/book/snippets/swift/NostrSnippets/justfile deleted file mode 100755 index a16ffd957..000000000 --- a/book/snippets/swift/NostrSnippets/justfile +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env just --justfile - -test: - swift build diff --git a/book/snippets/swift/justfile b/book/snippets/swift/justfile new file mode 100755 index 000000000..ee0f30a09 --- /dev/null +++ b/book/snippets/swift/justfile @@ -0,0 +1,13 @@ +#!/usr/bin/env just --justfile + +[macos] +test: + cd NostrSnippets && swift build && swift run + +[linux] +test: + @echo "This command is not supported on Linux platforms (require macOS)." + +[windows] +test: + @echo "This command is not supported on Windows platforms (require macOS)." diff --git a/book/src/sdk/signers/keys.md b/book/src/sdk/signers/keys.md index dbd0f512c..c787e0bdd 100644 --- a/book/src/sdk/signers/keys.md +++ b/book/src/sdk/signers/keys.md @@ -46,7 +46,7 @@ To generate a new key pair use the `generate()` method:
```swift,ignore -{{#include ../../../snippets/swift/NostrSnippets/Sources/Keys.swift}} +{{#include ../../../snippets/swift/NostrSnippets/Sources/Keys.swift:generate}} ```