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

Add support for NIP-44 v2 encryption #138

Merged
merged 7 commits into from
Mar 24, 2024
Merged

Add support for NIP-44 v2 encryption #138

merged 7 commits into from
Mar 24, 2024

Conversation

tyiu
Copy link
Contributor

@tyiu tyiu commented Mar 23, 2024

@@ -16,15 +16,17 @@ let package = Package(
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
.package(url: "https://github.com/GigaBitcoin/secp256k1.swift", from: "0.12.2")
.package(url: "https://github.com/GigaBitcoin/secp256k1.swift", from: "0.12.2"),
.package(url: "https://github.com/jedisct1/swift-sodium.git", revision: "63240810df971557fe9badc557257bdfbfeb90a3")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

swift-sodium is a wrapper around the sodium C library, which is the one that the referenced Kotlin implementation uses as well.

@@ -0,0 +1,648 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@bryanmontz bryanmontz left a comment

Choose a reason for hiding this comment

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

Great work, @tyiu! This is...pretty intense haha. Test coverage looks great, so that helps.

Sources/NostrSDK/NIP44v2Encrypting.swift Outdated Show resolved Hide resolved
Sources/NostrSDK/NIP44v2Encrypting.swift Show resolved Hide resolved
Sources/NostrSDK/NIP44v2Encrypting.swift Outdated Show resolved Hide resolved
Tests/NostrSDKTests/NIP44v2EncryptingTests.swift Outdated Show resolved Hide resolved
Tests/NostrSDKTests/FixtureLoading.swift Outdated Show resolved Hide resolved
…instead generically as user A and B to match with the NIP-44 spec, and also expose a public decrypt function that takes a private key and public key instead of a raw conversation key

/// Emulate real conversation with only the public encrypt and decrypt functions,
/// where the nonce used for encryption is a cryptographically secure pseudorandom generated series of bytes.
func testValidEncryptDecryptRandomNonce() throws {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this function so that it's a true test of how the API would be used in the wild.

Copy link
Collaborator

@bryanmontz bryanmontz left a comment

Choose a reason for hiding this comment

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

LGTM!

@bryanmontz bryanmontz merged commit f1384b7 into main Mar 24, 2024
4 checks passed
@bryanmontz bryanmontz deleted the tyiu/nip-44-v2 branch March 24, 2024 22:02
@tyiu
Copy link
Contributor Author

tyiu commented Mar 25, 2024

This change broke the Docs build step when it was merged to the main branch but the logs don't indicate why.
https://github.com/nostr-sdk/nostr-sdk-ios/actions/runs/8412402458/job/23033215548

//

import Foundation
import Clibsodium
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import Clibsodium breaks the documentation generation step of the build and I'm not sure why.

error: 'NostrSDK' does not contain any documentable symbols or a DocC catalog and will not produce documentation

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.

None yet

2 participants