-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
@@ -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") |
There was a problem hiding this comment.
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 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was copied from https://github.com/paulmillr/nip44/blob/b60eef26fe336e7e086b98a1bad27f0b8f09bca2/nip44.vectors.json
There was a problem hiding this 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.
Co-authored-by: Bryan Montz <bryanmontz@me.com>
… instead of raw strings
…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
…Encrypting public extension
|
||
/// 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This change broke the |
// | ||
|
||
import Foundation | ||
import Clibsodium |
There was a problem hiding this comment.
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
NIP-44 v2: https://github.com/nostr-protocol/nips/blob/4b79bc67c471f77061d62704538e5fdd6ac28ae8/44.md
Heavily inspired by this Kotlin implementation from @vitorpamplona
https://github.com/paulmillr/nip44/tree/b60eef26fe336e7e086b98a1bad27f0b8f09bca2/kotlin