diff --git a/Package.swift b/Package.swift index 952844b..93fb4f8 100644 --- a/Package.swift +++ b/Package.swift @@ -14,7 +14,7 @@ let package = Package( ], dependencies: [], targets: [ - .binaryTarget(name: "nostr_sdkFFI", url: "https://github.com/rust-nostr/nostr-sdk-swift/releases/download/0.34.0/nostr_sdkFFI.xcframework.zip", checksum: "b86c22250f04f09edc7a1939835b75886a95d2a20cbf1b4e2dce7ac0f720cf1f"), + .binaryTarget(name: "nostr_sdkFFI", url: "https://github.com/rust-nostr/nostr-sdk-swift/releases/download/0.35.0/nostr_sdkFFI.xcframework.zip", checksum: "2bc9bb31d6fe0688d9433fbab30fdfac11331892acf96f0245664be89b229f50"), .target(name: "NostrSDK", dependencies: ["nostr_sdkFFI"]), ] ) diff --git a/Sources/NostrSDK/Nostr.swift b/Sources/NostrSDK/Nostr.swift index 496edb1..2895869 100644 --- a/Sources/NostrSDK/Nostr.swift +++ b/Sources/NostrSDK/Nostr.swift @@ -950,6 +950,7 @@ public protocol CoordinateProtocol : AnyObject { */ open class Coordinate: CustomDebugStringConvertible, + CustomStringConvertible, Equatable, Hashable, CoordinateProtocol { @@ -1074,6 +1075,14 @@ open func toNostrUri()throws -> String { try! rustCall() { uniffi_nostr_ffi_fn_method_coordinate_uniffi_trait_debug(self.uniffiClonePointer(),$0 ) +} + ) + } + open var description: String { + return try! FfiConverterString.lift( + try! rustCall() { + uniffi_nostr_ffi_fn_method_coordinate_uniffi_trait_display(self.uniffiClonePointer(),$0 + ) } ) } @@ -1352,6 +1361,8 @@ public protocol EventProtocol : AnyObject { func asJson() throws -> String + func asPrettyJson() throws -> String + /** * Get event author (`pubkey` field) */ @@ -1404,13 +1415,6 @@ public protocol EventProtocol : AnyObject { */ func identifier() -> String? - /** - * Check if event `Kind` is `Ephemeral` - * - * - */ - func isEphemeral() -> Bool - /** * Returns `true` if the event has an expiration tag that is expired. * If an event has no `Expiration` tag, then it will return `false`. @@ -1419,27 +1423,6 @@ public protocol EventProtocol : AnyObject { */ func isExpired() -> Bool - /** - * Check if `Kind` is a NIP90 job request - * - * - */ - func isJobRequest() -> Bool - - /** - * Check if `Kind` is a NIP90 job result - * - * - */ - func isJobResult() -> Bool - - /** - * Check if event `Kind` is `Parameterized replaceable` - * - * - */ - func isParameterizedReplaceable() -> Bool - /** * Check if it's a protected event * @@ -1447,20 +1430,6 @@ public protocol EventProtocol : AnyObject { */ func isProtected() -> Bool - /** - * Check if event `Kind` is `Regular` - * - * - */ - func isRegular() -> Bool - - /** - * Check if event `Kind` is `Replaceable` - * - * - */ - func isReplaceable() -> Bool - func kind() -> Kind /** @@ -1482,12 +1451,12 @@ public protocol EventProtocol : AnyObject { /** * Verify if the `EventId` it's composed correctly */ - func verifyId() throws + func verifyId() -> Bool /** * Verify only event `Signature` */ - func verifySignature() throws + func verifySignature() -> Bool } @@ -1548,6 +1517,13 @@ open func asJson()throws -> String { uniffi_nostr_ffi_fn_method_event_as_json(self.uniffiClonePointer(),$0 ) }) +} + +open func asPrettyJson()throws -> String { + return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { + uniffi_nostr_ffi_fn_method_event_as_pretty_json(self.uniffiClonePointer(),$0 + ) +}) } /** @@ -1657,18 +1633,6 @@ open func identifier() -> String? { uniffi_nostr_ffi_fn_method_event_identifier(self.uniffiClonePointer(),$0 ) }) -} - - /** - * Check if event `Kind` is `Ephemeral` - * - * - */ -open func isEphemeral() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_event_is_ephemeral(self.uniffiClonePointer(),$0 - ) -}) } /** @@ -1682,42 +1646,6 @@ open func isExpired() -> Bool { uniffi_nostr_ffi_fn_method_event_is_expired(self.uniffiClonePointer(),$0 ) }) -} - - /** - * Check if `Kind` is a NIP90 job request - * - * - */ -open func isJobRequest() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_event_is_job_request(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Check if `Kind` is a NIP90 job result - * - * - */ -open func isJobResult() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_event_is_job_result(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Check if event `Kind` is `Parameterized replaceable` - * - * - */ -open func isParameterizedReplaceable() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_event_is_parameterized_replaceable(self.uniffiClonePointer(),$0 - ) -}) } /** @@ -1730,30 +1658,6 @@ open func isProtected() -> Bool { uniffi_nostr_ffi_fn_method_event_is_protected(self.uniffiClonePointer(),$0 ) }) -} - - /** - * Check if event `Kind` is `Regular` - * - * - */ -open func isRegular() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_event_is_regular(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Check if event `Kind` is `Replaceable` - * - * - */ -open func isReplaceable() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_event_is_replaceable(self.uniffiClonePointer(),$0 - ) -}) } open func kind() -> Kind { @@ -1802,19 +1706,21 @@ open func verify() -> Bool { /** * Verify if the `EventId` it's composed correctly */ -open func verifyId()throws {try rustCallWithError(FfiConverterTypeNostrError.lift) { +open func verifyId() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { uniffi_nostr_ffi_fn_method_event_verify_id(self.uniffiClonePointer(),$0 ) -} +}) } /** * Verify only event `Signature` */ -open func verifySignature()throws {try rustCallWithError(FfiConverterTypeNostrError.lift) { +open func verifySignature() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { uniffi_nostr_ffi_fn_method_event_verify_signature(self.uniffiClonePointer(),$0 ) -} +}) } open var debugDescription: String { @@ -1903,14 +1809,17 @@ public protocol EventBuilderProtocol : AnyObject { */ func customCreatedAt(createdAt: Timestamp) -> EventBuilder - func toEvent(keys: Keys) throws -> Event + /** + * Set POW difficulty + * + * Only values `> 0` are accepted! + */ + func pow(difficulty: UInt8) -> EventBuilder - func toPowEvent(keys: Keys, difficulty: UInt8) throws -> Event + func toEvent(keys: Keys) throws -> Event func toUnsignedEvent(publicKey: PublicKey) -> UnsignedEvent - func toUnsignedPowEvent(publicKey: PublicKey, difficulty: UInt8) -> UnsignedEvent - } open class EventBuilder: @@ -2262,15 +2171,10 @@ public static func interests(list: Interests) -> EventBuilder { * * */ -public static func jobFeedback(jobRequest: Event, status: DataVendingMachineStatus, extraInfo: String?, amountMillisats: UInt64, bolt11: String? = nil, payload: String? = nil) -> EventBuilder { +public static func jobFeedback(data: JobFeedbackData) -> EventBuilder { return try! FfiConverterTypeEventBuilder.lift(try! rustCall() { uniffi_nostr_ffi_fn_constructor_eventbuilder_job_feedback( - FfiConverterTypeEvent.lower(jobRequest), - FfiConverterTypeDataVendingMachineStatus.lower(status), - FfiConverterOptionString.lower(extraInfo), - FfiConverterUInt64.lower(amountMillisats), - FfiConverterOptionString.lower(bolt11), - FfiConverterOptionString.lower(payload),$0 + FfiConverterTypeJobFeedbackData.lower(data),$0 ) }) } @@ -2719,19 +2623,23 @@ open func customCreatedAt(createdAt: Timestamp) -> EventBuilder { }) } -open func toEvent(keys: Keys)throws -> Event { - return try FfiConverterTypeEvent.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { - uniffi_nostr_ffi_fn_method_eventbuilder_to_event(self.uniffiClonePointer(), - FfiConverterTypeKeys.lower(keys),$0 + /** + * Set POW difficulty + * + * Only values `> 0` are accepted! + */ +open func pow(difficulty: UInt8) -> EventBuilder { + return try! FfiConverterTypeEventBuilder.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_eventbuilder_pow(self.uniffiClonePointer(), + FfiConverterUInt8.lower(difficulty),$0 ) }) } -open func toPowEvent(keys: Keys, difficulty: UInt8)throws -> Event { +open func toEvent(keys: Keys)throws -> Event { return try FfiConverterTypeEvent.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { - uniffi_nostr_ffi_fn_method_eventbuilder_to_pow_event(self.uniffiClonePointer(), - FfiConverterTypeKeys.lower(keys), - FfiConverterUInt8.lower(difficulty),$0 + uniffi_nostr_ffi_fn_method_eventbuilder_to_event(self.uniffiClonePointer(), + FfiConverterTypeKeys.lower(keys),$0 ) }) } @@ -2742,15 +2650,6 @@ open func toUnsignedEvent(publicKey: PublicKey) -> UnsignedEvent { FfiConverterTypePublicKey.lower(publicKey),$0 ) }) -} - -open func toUnsignedPowEvent(publicKey: PublicKey, difficulty: UInt8) -> UnsignedEvent { - return try! FfiConverterTypeUnsignedEvent.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_eventbuilder_to_unsigned_pow_event(self.uniffiClonePointer(), - FfiConverterTypePublicKey.lower(publicKey), - FfiConverterUInt8.lower(difficulty),$0 - ) -}) } open var debugDescription: String { @@ -4005,16 +3904,197 @@ public func FfiConverterTypeImageDimensions_lower(_ value: ImageDimensions) -> U +/** + * Data Vending Machine (DVM) - Job Feedback data + * + * + */ +public protocol JobFeedbackDataProtocol : AnyObject { + + /** + * Add payment amount + */ + func amount(millisats: UInt64, bolt11: String?) -> JobFeedbackData + + /** + * Add extra info + */ + func extraInfo(info: String) -> JobFeedbackData + + /** + * Add payload + */ + func payload(payload: String) -> JobFeedbackData + +} + +/** + * Data Vending Machine (DVM) - Job Feedback data + * + * + */ +open class JobFeedbackData: + JobFeedbackDataProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_nostr_ffi_fn_clone_jobfeedbackdata(self.pointer, $0) } + } + /** + * Construct new Job Feedback + */ +public convenience init(jobRequest: Event, status: DataVendingMachineStatus) { + let pointer = + try! rustCall() { + uniffi_nostr_ffi_fn_constructor_jobfeedbackdata_new( + FfiConverterTypeEvent.lower(jobRequest), + FfiConverterTypeDataVendingMachineStatus.lower(status),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_nostr_ffi_fn_free_jobfeedbackdata(pointer, $0) } + } + + + + + /** + * Add payment amount + */ +open func amount(millisats: UInt64, bolt11: String?) -> JobFeedbackData { + return try! FfiConverterTypeJobFeedbackData.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_jobfeedbackdata_amount(self.uniffiClonePointer(), + FfiConverterUInt64.lower(millisats), + FfiConverterOptionString.lower(bolt11),$0 + ) +}) +} + + /** + * Add extra info + */ +open func extraInfo(info: String) -> JobFeedbackData { + return try! FfiConverterTypeJobFeedbackData.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_jobfeedbackdata_extra_info(self.uniffiClonePointer(), + FfiConverterString.lower(info),$0 + ) +}) +} + + /** + * Add payload + */ +open func payload(payload: String) -> JobFeedbackData { + return try! FfiConverterTypeJobFeedbackData.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_jobfeedbackdata_payload(self.uniffiClonePointer(), + FfiConverterString.lower(payload),$0 + ) +}) +} + + +} + +public struct FfiConverterTypeJobFeedbackData: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = JobFeedbackData + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> JobFeedbackData { + return JobFeedbackData(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: JobFeedbackData) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> JobFeedbackData { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: JobFeedbackData, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeJobFeedbackData_lift(_ pointer: UnsafeMutableRawPointer) throws -> JobFeedbackData { + return try FfiConverterTypeJobFeedbackData.lift(pointer) +} + +public func FfiConverterTypeJobFeedbackData_lower(_ value: JobFeedbackData) -> UnsafeMutableRawPointer { + return FfiConverterTypeJobFeedbackData.lower(value) +} + + + + +/** + * Nostr keys + */ public protocol KeysProtocol : AnyObject { + /** + * Get public key + */ func publicKey() -> PublicKey - func secretKey() throws -> SecretKey + /** + * Get secret key + */ + func secretKey() -> SecretKey + /** + * Creates a schnorr signature of a message. + * + * This method use a random number generator that retrieves randomness from the operating system. + */ func signSchnorr(message: Data) throws -> String } +/** + * Nostr keys + */ open class Keys: CustomDebugStringConvertible, Equatable, @@ -4045,6 +4125,9 @@ open class Keys: public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_nostr_ffi_fn_clone_keys(self.pointer, $0) } } + /** + * Initialize nostr keys from secret key. + */ public convenience init(secretKey: SecretKey) { let pointer = try! rustCall() { @@ -4065,7 +4148,7 @@ public convenience init(secretKey: SecretKey) { /** - * Derive `Keys` from BIP-39 mnemonics (ENGLISH wordlist). + * Derive keys from BIP-39 mnemonics (ENGLISH wordlist). * * */ @@ -4079,18 +4162,16 @@ public static func fromMnemonic(mnemonic: String, passphrase: String? = nil, acc FfiConverterOptionUInt32.lower(index),$0 ) }) -} - -public static func fromPublicKey(publicKey: PublicKey) -> Keys { - return try! FfiConverterTypeKeys.lift(try! rustCall() { - uniffi_nostr_ffi_fn_constructor_keys_from_public_key( - FfiConverterTypePublicKey.lower(publicKey),$0 - ) -}) } /** - * Generate random `Keys` + * Generate random keys + * + * This constructor use a random number generator that retrieves randomness from the operating system. + * + * Generate random keys **without** construct the `Keypair`. + * This allows faster keys generation (i.e. for vanity pubkey mining). + * The `Keypair` will be automatically created when needed and stored in a cell. */ public static func generate() -> Keys { return try! FfiConverterTypeKeys.lift(try! rustCall() { @@ -4100,7 +4181,7 @@ public static func generate() -> Keys { } /** - * Try to parse keys from **secret key** `hex` or `bech32` + * Parse secret key from `hex` or `bech32` and compose keys */ public static func parse(secretKey: String)throws -> Keys { return try FfiConverterTypeKeys.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { @@ -4122,6 +4203,9 @@ public static func vanity(prefixes: [String], bech32: Bool, numCores: UInt8)thro + /** + * Get public key + */ open func publicKey() -> PublicKey { return try! FfiConverterTypePublicKey.lift(try! rustCall() { uniffi_nostr_ffi_fn_method_keys_public_key(self.uniffiClonePointer(),$0 @@ -4129,13 +4213,21 @@ open func publicKey() -> PublicKey { }) } -open func secretKey()throws -> SecretKey { - return try FfiConverterTypeSecretKey.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { + /** + * Get secret key + */ +open func secretKey() -> SecretKey { + return try! FfiConverterTypeSecretKey.lift(try! rustCall() { uniffi_nostr_ffi_fn_method_keys_secret_key(self.uniffiClonePointer(),$0 ) }) } + /** + * Creates a schnorr signature of a message. + * + * This method use a random number generator that retrieves randomness from the operating system. + */ open func signSchnorr(message: Data)throws -> String { return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { uniffi_nostr_ffi_fn_method_keys_sign_schnorr(self.uniffiClonePointer(), @@ -4217,14 +4309,61 @@ public protocol KindProtocol : AnyObject { func asEnum() -> KindEnum /** - * Get kind as 16-bit unsigned number + * Get as 16-bit unsigned integer */ func asU16() -> UInt16 /** - * Get kind as 64-bit unsigned number + * Check if it's ephemeral + * + * Ephemeral means that event is not expected to be stored by relays. + * + * */ - func asU64() -> UInt64 + func isEphemeral() -> Bool + + /** + * Check if it's a NIP-90 job request + * + * + */ + func isJobRequest() -> Bool + + /** + * Check if it's a NIP-90 job result + * + * + */ + func isJobResult() -> Bool + + /** + * Check if it's parameterized replaceable + * + * Parametrized replaceable means that, for each combination of `pubkey`, `kind` and the `d` tag's first value, + * only the latest event MUST be stored by relays, older versions MAY be discarded. + * + * + */ + func isParameterizedReplaceable() -> Bool + + /** + * Check if it's regular + * + * Regular means that event is expected to be stored by relays. + * + * + */ + func isRegular() -> Bool + + /** + * Check if it's replaceable + * + * Replaceable means that, for each combination of `pubkey` and `kind`, + * only the latest event MUST be stored by relays, older versions MAY be discarded. + * + * + */ + func isReplaceable() -> Bool } @@ -4299,7 +4438,7 @@ open func asEnum() -> KindEnum { } /** - * Get kind as 16-bit unsigned number + * Get as 16-bit unsigned integer */ open func asU16() -> UInt16 { return try! FfiConverterUInt16.lift(try! rustCall() { @@ -4309,11 +4448,83 @@ open func asU16() -> UInt16 { } /** - * Get kind as 64-bit unsigned number + * Check if it's ephemeral + * + * Ephemeral means that event is not expected to be stored by relays. + * + * */ -open func asU64() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_nostr_ffi_fn_method_kind_as_u64(self.uniffiClonePointer(),$0 +open func isEphemeral() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_kind_is_ephemeral(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Check if it's a NIP-90 job request + * + * + */ +open func isJobRequest() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_kind_is_job_request(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Check if it's a NIP-90 job result + * + * + */ +open func isJobResult() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_kind_is_job_result(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Check if it's parameterized replaceable + * + * Parametrized replaceable means that, for each combination of `pubkey`, `kind` and the `d` tag's first value, + * only the latest event MUST be stored by relays, older versions MAY be discarded. + * + * + */ +open func isParameterizedReplaceable() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_kind_is_parameterized_replaceable(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Check if it's regular + * + * Regular means that event is expected to be stored by relays. + * + * + */ +open func isRegular() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_kind_is_regular(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Check if it's replaceable + * + * Replaceable means that, for each combination of `pubkey` and `kind`, + * only the latest event MUST be stored by relays, older versions MAY be discarded. + * + * + */ +open func isReplaceable() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_nostr_ffi_fn_method_kind_is_replaceable(self.uniffiClonePointer(),$0 ) }) } @@ -4396,6 +4607,8 @@ public protocol MetadataProtocol : AnyObject { func asJson() throws -> String + func asPrettyJson() throws -> String + func asRecord() -> MetadataRecord func getAbout() -> String? @@ -4513,6 +4726,13 @@ open func asJson()throws -> String { }) } +open func asPrettyJson()throws -> String { + return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { + uniffi_nostr_ffi_fn_method_metadata_as_pretty_json(self.uniffiClonePointer(),$0 + ) +}) +} + open func asRecord() -> MetadataRecord { return try! FfiConverterTypeMetadataRecord.lift(try! rustCall() { uniffi_nostr_ffi_fn_method_metadata_as_record(self.uniffiClonePointer(),$0 @@ -8690,6 +8910,8 @@ public protocol UnsignedEventProtocol : AnyObject { func asJson() throws -> String + func asPrettyJson() throws -> String + func author() -> PublicKey func content() -> String @@ -8783,6 +9005,13 @@ open func asJson()throws -> String { }) } +open func asPrettyJson()throws -> String { + return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNostrError.lift) { + uniffi_nostr_ffi_fn_method_unsignedevent_as_pretty_json(self.uniffiClonePointer(),$0 + ) +}) +} + open func author() -> PublicKey { return try! FfiConverterTypePublicKey.lift(try! rustCall() { uniffi_nostr_ffi_fn_method_unsignedevent_author(self.uniffiClonePointer(),$0 @@ -12814,8 +13043,8 @@ public enum ClientMessageEnum { */ case negOpen(subscriptionId: String, filter: Filter, /** - * ID size (MUST be between 8 and 32, inclusive) - */idSize: UInt8, initialMessage: String + * ID size (deprecated) + */idSize: UInt8?, initialMessage: String ) /** * Negentropy Message @@ -12852,7 +13081,7 @@ public struct FfiConverterTypeClientMessageEnum: FfiConverterRustBuffer { case 5: return .auth(event: try FfiConverterTypeEvent.read(from: &buf) ) - case 6: return .negOpen(subscriptionId: try FfiConverterString.read(from: &buf), filter: try FfiConverterTypeFilter.read(from: &buf), idSize: try FfiConverterUInt8.read(from: &buf), initialMessage: try FfiConverterString.read(from: &buf) + case 6: return .negOpen(subscriptionId: try FfiConverterString.read(from: &buf), filter: try FfiConverterTypeFilter.read(from: &buf), idSize: try FfiConverterOptionUInt8.read(from: &buf), initialMessage: try FfiConverterString.read(from: &buf) ) case 7: return .negMsg(subscriptionId: try FfiConverterString.read(from: &buf), message: try FfiConverterString.read(from: &buf) @@ -12900,7 +13129,7 @@ public struct FfiConverterTypeClientMessageEnum: FfiConverterRustBuffer { writeInt(&buf, Int32(6)) FfiConverterString.write(subscriptionId, into: &buf) FfiConverterTypeFilter.write(filter, into: &buf) - FfiConverterUInt8.write(idSize, into: &buf) + FfiConverterOptionUInt8.write(idSize, into: &buf) FfiConverterString.write(initialMessage, into: &buf) @@ -17471,6 +17700,27 @@ extension ZapType: Equatable, Hashable {} +fileprivate struct FfiConverterOptionUInt8: FfiConverterRustBuffer { + typealias SwiftType = UInt8? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt8.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt8.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer { typealias SwiftType = UInt32? @@ -19121,6 +19371,9 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_method_event_as_json() != 6443) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_ffi_checksum_method_event_as_pretty_json() != 12604) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_ffi_checksum_method_event_author() != 55205) { return InitializationResult.apiChecksumMismatch } @@ -19154,30 +19407,12 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_method_event_identifier() != 23430) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_event_is_ephemeral() != 21349) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_ffi_checksum_method_event_is_expired() != 57175) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_event_is_job_request() != 26053) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_ffi_checksum_method_event_is_job_result() != 54684) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_ffi_checksum_method_event_is_parameterized_replaceable() != 17253) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_ffi_checksum_method_event_is_protected() != 548) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_event_is_regular() != 8941) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_ffi_checksum_method_event_is_replaceable() != 57468) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_ffi_checksum_method_event_kind() != 15262) { return InitializationResult.apiChecksumMismatch } @@ -19193,10 +19428,10 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_method_event_verify() != 11448) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_event_verify_id() != 58200) { + if (uniffi_nostr_ffi_checksum_method_event_verify_id() != 57588) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_event_verify_signature() != 63925) { + if (uniffi_nostr_ffi_checksum_method_event_verify_signature() != 50020) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_ffi_checksum_method_eventbuilder_add_tags() != 37368) { @@ -19205,18 +19440,15 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_method_eventbuilder_custom_created_at() != 25828) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_eventbuilder_to_event() != 27477) { + if (uniffi_nostr_ffi_checksum_method_eventbuilder_pow() != 35800) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_eventbuilder_to_pow_event() != 361) { + if (uniffi_nostr_ffi_checksum_method_eventbuilder_to_event() != 27477) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_ffi_checksum_method_eventbuilder_to_unsigned_event() != 12334) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_eventbuilder_to_unsigned_pow_event() != 38142) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_ffi_checksum_method_eventid_as_bytes() != 42102) { return InitializationResult.apiChecksumMismatch } @@ -19373,27 +19605,54 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_method_imagedimensions_width() != 1901) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_keys_public_key() != 8351) { + if (uniffi_nostr_ffi_checksum_method_jobfeedbackdata_amount() != 59731) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_jobfeedbackdata_extra_info() != 5908) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_jobfeedbackdata_payload() != 3168) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_keys_public_key() != 55373) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_keys_secret_key() != 10917) { + if (uniffi_nostr_ffi_checksum_method_keys_secret_key() != 40486) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_keys_sign_schnorr() != 38932) { + if (uniffi_nostr_ffi_checksum_method_keys_sign_schnorr() != 22725) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_ffi_checksum_method_kind_as_enum() != 37013) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_kind_as_u16() != 42491) { + if (uniffi_nostr_ffi_checksum_method_kind_as_u16() != 18194) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_method_kind_as_u64() != 51642) { + if (uniffi_nostr_ffi_checksum_method_kind_is_ephemeral() != 50434) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_kind_is_job_request() != 28580) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_kind_is_job_result() != 57920) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_kind_is_parameterized_replaceable() != 993) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_kind_is_regular() != 65478) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_ffi_checksum_method_kind_is_replaceable() != 4249) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_ffi_checksum_method_metadata_as_json() != 49741) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_ffi_checksum_method_metadata_as_pretty_json() != 31827) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_ffi_checksum_method_metadata_as_record() != 14817) { return InitializationResult.apiChecksumMismatch } @@ -19691,6 +19950,9 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_method_unsignedevent_as_json() != 44697) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_ffi_checksum_method_unsignedevent_as_pretty_json() != 44034) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_ffi_checksum_method_unsignedevent_author() != 15518) { return InitializationResult.apiChecksumMismatch } @@ -19838,7 +20100,7 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_constructor_eventbuilder_interests() != 25709) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_constructor_eventbuilder_job_feedback() != 21708) { + if (uniffi_nostr_ffi_checksum_constructor_eventbuilder_job_feedback() != 61541) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_ffi_checksum_constructor_eventbuilder_job_request() != 45432) { @@ -19964,19 +20226,19 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_ffi_checksum_constructor_imagedimensions_new() != 24393) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_constructor_keys_from_mnemonic() != 36491) { + if (uniffi_nostr_ffi_checksum_constructor_jobfeedbackdata_new() != 10031) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_constructor_keys_from_public_key() != 57552) { + if (uniffi_nostr_ffi_checksum_constructor_keys_from_mnemonic() != 10786) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_constructor_keys_generate() != 34326) { + if (uniffi_nostr_ffi_checksum_constructor_keys_generate() != 3743) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_constructor_keys_new() != 32326) { + if (uniffi_nostr_ffi_checksum_constructor_keys_new() != 19077) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_ffi_checksum_constructor_keys_parse() != 16239) { + if (uniffi_nostr_ffi_checksum_constructor_keys_parse() != 28082) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_ffi_checksum_constructor_keys_vanity() != 20910) { diff --git a/Sources/NostrSDK/NostrSDK.swift b/Sources/NostrSDK/NostrSDK.swift index 269426c..54c24ef 100644 --- a/Sources/NostrSDK/NostrSDK.swift +++ b/Sources/NostrSDK/NostrSDK.swift @@ -537,41 +537,47 @@ fileprivate struct FfiConverterDuration: FfiConverterRustBuffer { public protocol ClientProtocol : AnyObject { /** - * Add new relay + * Add discovery relay * - * Return `false` if the relay already exists. + * If relay already exists, this method automatically add the `DISCOVERY` flag to it and return `false`. * - * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, - * to avoid to set pool subscriptions. + * + */ + func addDiscoveryRelay(url: String) async throws -> Bool + + /** + * Add read relay * - * This method use previously set or default `Options` to configure the `Relay` (ex. set proxy, set min POW, set relay limits, ...). - * To use custom `RelayOptions`, check `add_relay_with_opts` method. + * If relay already exists, this method add the `READ` flag to it and return `false`. * - * Connection is **NOT** automatically started with relay, remember to call `connect` method! + * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, + * to avoid to set pool subscriptions. */ - func addRelay(url: String) async throws -> Bool + func addReadRelay(url: String) async throws -> Bool /** - * Add new relay with custom `RelayOptions` + * Add new relay * - * Return `false` if the relay already exists. + * Relays added with this method will have both `READ` and `WRITE` flags enabled + * + * If the relay already exists, the flags will be updated and `false` returned. * * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, * to avoid to set pool subscriptions. * + * This method use previously set or default `Options` to configure the `Relay` (ex. set proxy, set min POW, set relay limits, ...). + * To use custom `RelayOptions` use `add_relay` method on `RelayPool`. + * * Connection is **NOT** automatically started with relay, remember to call `connect` method! */ - func addRelayWithOpts(url: String, opts: RelayOptions) async throws -> Bool + func addRelay(url: String) async throws -> Bool /** - * Add multiple relays + * Add write relay * - * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, - * to avoid to set pool subscriptions. - * - * Connection is **NOT** automatically started with relays, remember to call `connect` method! + * If relay already exists, this method add the `WRITE` flag to it and return `false`. */ - func addRelays(relays: [String]) async throws + func addWriteRelay(url: String) async throws -> Bool /** * Auto authenticate to relays (default: true) @@ -580,11 +586,6 @@ public protocol ClientProtocol : AnyObject { */ func automaticAuthentication(enable: Bool) - /** - * Get blacklist - */ - func blacklist() -> RelayBlacklist - /** * Connect to all added relays */ @@ -616,13 +617,36 @@ public protocol ClientProtocol : AnyObject { */ func dislike(event: Event) async throws -> SendEventOutput + /** + * Fetch the newest public key metadata from database and connected relays. + * + * If you only want to consult cached data, + * consider `client.database().profile(PUBKEY)`. + * + * + */ + func fetchMetadata(publicKey: PublicKey, timeout: TimeInterval?) async throws -> Metadata + func fileMetadata(description: String, metadata: FileMetadata) async throws -> SendEventOutput + /** + * Get filtering + */ + func filtering() -> RelayFiltering + /** * Get events of filters from specific relays */ func getEventsFrom(urls: [String], filters: [Filter], timeout: TimeInterval?) async throws -> [Event] + /** + * Get events of filters + * + * The returned events are sorted by newest first, if there is a limit only the newest are returned. + * + * If `gossip` is enabled (see `Options]) the events will be requested also to + * NIP-65 relays (automatically discovered) of public keys included in filters (if any). + */ func getEventsOf(filters: [Filter], source: EventSource) async throws -> [Event] /** @@ -652,22 +676,9 @@ public protocol ClientProtocol : AnyObject { func like(event: Event) async throws -> SendEventOutput /** - * Mute event IDs - * - * Add event IDs to blacklist - * - *
Mute list event is not currently created/updated!
- */ - func muteIds(ids: [EventId]) async - - /** - * Mute public keys - * - * Add public keys to blacklist - * - *
Mute list event is not currently created/updated!
+ * Get relay pool */ - func mutePublicKeys(publicKeys: [PublicKey]) async + func pool() -> RelayPool /** * React to an [`Event`] @@ -680,6 +691,9 @@ public protocol ClientProtocol : AnyObject { func relay(url: String) async throws -> Relay + /** + * Get relays with `READ` or `WRITE` flags + */ func relays() async -> [String: Relay] func removeRelay(url: String) async throws @@ -689,26 +703,33 @@ public protocol ClientProtocol : AnyObject { */ func repost(event: Event, relayUrl: String?) async throws -> SendEventOutput + /** + * Send event + * + * Send event to all relays with `WRITE` flag. + * If `gossip` is enabled (see `Options`) the event will be sent also to NIP-65 relays (automatically discovered). + */ func sendEvent(event: Event) async throws -> SendEventOutput /** - * Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to all relays. + * Take an `EventBuilder`, sign it by using the `NostrSigner` and broadcast to relays (check `send_event` method for more details) * - * Rise an error if the [`NostrSigner`] is not set. + * Rise an error if the `NostrSigner` is not set. */ func sendEventBuilder(builder: EventBuilder) async throws -> SendEventOutput /** - * Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to specific relays. + * Take an `EventBuilder`, sign it by using the `NostrSigner` and broadcast to specific relays. * - * Rise an error if the [`NostrSigner`] is not set. + * Rise an error if the `NostrSigner` is not set. */ func sendEventBuilderTo(urls: [String], builder: EventBuilder) async throws -> SendEventOutput + /** + * Send event to specific relays. + */ func sendEventTo(urls: [String], event: Event) async throws -> SendEventOutput - func sendMsg(msg: ClientMessage) async throws -> Output - func sendMsgTo(urls: [String], msg: ClientMessage) async throws -> Output /** @@ -737,7 +758,10 @@ public protocol ClientProtocol : AnyObject { func signer() async throws -> NostrSigner /** - * Subscribe to filters to all connected relays + * Subscribe to filters + * + * If `gossip` is enabled (see `Options]) the events will be requested also to + * NIP-65 relays (automatically discovered) of public keys included in filters (if any). * * ### Auto-closing subscription * @@ -755,7 +779,10 @@ public protocol ClientProtocol : AnyObject { func subscribeTo(urls: [String], filters: [Filter], opts: SubscribeAutoCloseOptions?) async throws -> SubscribeOutput /** - * Subscribe to filters with custom subscription ID to all connected relays + * Subscribe to filters with custom subscription ID + * + * If `gossip` is enabled (see `Options]) the events will be requested also to + * NIP-65 relays (automatically discovered) of public keys included in filters (if any). * * ### Auto-closing subscription * @@ -776,24 +803,6 @@ public protocol ClientProtocol : AnyObject { func subscriptions() async -> [String: [Filter]] - /** - * Unmute event IDs - * - * Remove event IDs from blacklist - * - *
Mute list event is not currently created/updated!
- */ - func unmuteIds(ids: [EventId]) async - - /** - * Unmute public keys - * - * Remove public keys from blacklist - * - *
Mute list event is not currently created/updated!
- */ - func unmutePublicKeys(publicKeys: [PublicKey]) async - func unsubscribe(subscriptionId: String) async func unsubscribeAll() async @@ -885,23 +894,42 @@ public static func withOpts(signer: NostrSigner?, opts: Options) -> Client { /** - * Add new relay + * Add discovery relay * - * Return `false` if the relay already exists. + * If relay already exists, this method automatically add the `DISCOVERY` flag to it and return `false`. * - * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, - * to avoid to set pool subscriptions. + * + */ +open func addDiscoveryRelay(url: String)async throws -> Bool { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_nostr_sdk_ffi_fn_method_client_add_discovery_relay( + self.uniffiClonePointer(), + FfiConverterString.lower(url) + ) + }, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_i8, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_i8, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_i8, + liftFunc: FfiConverterBool.lift, + errorHandler: FfiConverterTypeNostrSdkError.lift + ) +} + + /** + * Add read relay * - * This method use previously set or default `Options` to configure the `Relay` (ex. set proxy, set min POW, set relay limits, ...). - * To use custom `RelayOptions`, check `add_relay_with_opts` method. + * If relay already exists, this method add the `READ` flag to it and return `false`. * - * Connection is **NOT** automatically started with relay, remember to call `connect` method! + * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, + * to avoid to set pool subscriptions. */ -open func addRelay(url: String)async throws -> Bool { +open func addReadRelay(url: String)async throws -> Bool { return try await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_add_relay( + uniffi_nostr_sdk_ffi_fn_method_client_add_read_relay( self.uniffiClonePointer(), FfiConverterString.lower(url) ) @@ -915,22 +943,27 @@ open func addRelay(url: String)async throws -> Bool { } /** - * Add new relay with custom `RelayOptions` + * Add new relay * - * Return `false` if the relay already exists. + * Relays added with this method will have both `READ` and `WRITE` flags enabled + * + * If the relay already exists, the flags will be updated and `false` returned. * * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, * to avoid to set pool subscriptions. * + * This method use previously set or default `Options` to configure the `Relay` (ex. set proxy, set min POW, set relay limits, ...). + * To use custom `RelayOptions` use `add_relay` method on `RelayPool`. + * * Connection is **NOT** automatically started with relay, remember to call `connect` method! */ -open func addRelayWithOpts(url: String, opts: RelayOptions)async throws -> Bool { +open func addRelay(url: String)async throws -> Bool { return try await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_add_relay_with_opts( + uniffi_nostr_sdk_ffi_fn_method_client_add_relay( self.uniffiClonePointer(), - FfiConverterString.lower(url),FfiConverterTypeRelayOptions.lower(opts) + FfiConverterString.lower(url) ) }, pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_i8, @@ -942,26 +975,23 @@ open func addRelayWithOpts(url: String, opts: RelayOptions)async throws -> Bool } /** - * Add multiple relays - * - * If are set pool subscriptions, the new added relay will inherit them. Use `subscribe_to` method instead of `subscribe`, - * to avoid to set pool subscriptions. + * Add write relay * - * Connection is **NOT** automatically started with relays, remember to call `connect` method! + * If relay already exists, this method add the `WRITE` flag to it and return `false`. */ -open func addRelays(relays: [String])async throws { +open func addWriteRelay(url: String)async throws -> Bool { return try await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_add_relays( + uniffi_nostr_sdk_ffi_fn_method_client_add_write_relay( self.uniffiClonePointer(), - FfiConverterSequenceString.lower(relays) + FfiConverterString.lower(url) ) }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_void, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_void, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_void, - liftFunc: { $0 }, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_i8, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_i8, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_i8, + liftFunc: FfiConverterBool.lift, errorHandler: FfiConverterTypeNostrSdkError.lift ) } @@ -976,16 +1006,6 @@ open func automaticAuthentication(enable: Bool) {try! rustCall() { FfiConverterBool.lower(enable),$0 ) } -} - - /** - * Get blacklist - */ -open func blacklist() -> RelayBlacklist { - return try! FfiConverterTypeRelayBlacklist.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_client_blacklist(self.uniffiClonePointer(),$0 - ) -}) } /** @@ -1116,6 +1136,31 @@ open func dislike(event: Event)async throws -> SendEventOutput { ) } + /** + * Fetch the newest public key metadata from database and connected relays. + * + * If you only want to consult cached data, + * consider `client.database().profile(PUBKEY)`. + * + * + */ +open func fetchMetadata(publicKey: PublicKey, timeout: TimeInterval? = nil)async throws -> Metadata { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_nostr_sdk_ffi_fn_method_client_fetch_metadata( + self.uniffiClonePointer(), + FfiConverterTypePublicKey_lower(publicKey),FfiConverterOptionDuration.lower(timeout) + ) + }, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_pointer, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_pointer, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_pointer, + liftFunc: FfiConverterTypeMetadata_lift, + errorHandler: FfiConverterTypeNostrSdkError.lift + ) +} + open func fileMetadata(description: String, metadata: FileMetadata)async throws -> SendEventOutput { return try await uniffiRustCallAsync( @@ -1133,6 +1178,16 @@ open func fileMetadata(description: String, metadata: FileMetadata)async throws ) } + /** + * Get filtering + */ +open func filtering() -> RelayFiltering { + return try! FfiConverterTypeRelayFiltering.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_client_filtering(self.uniffiClonePointer(),$0 + ) +}) +} + /** * Get events of filters from specific relays */ @@ -1153,6 +1208,14 @@ open func getEventsFrom(urls: [String], filters: [Filter], timeout: TimeInterval ) } + /** + * Get events of filters + * + * The returned events are sorted by newest first, if there is a limit only the newest are returned. + * + * If `gossip` is enabled (see `Options]) the events will be requested also to + * NIP-65 relays (automatically discovered) of public keys included in filters (if any). + */ open func getEventsOf(filters: [Filter], source: EventSource)async throws -> [Event] { return try await uniffiRustCallAsync( @@ -1257,53 +1320,13 @@ open func like(event: Event)async throws -> SendEventOutput { } /** - * Mute event IDs - * - * Add event IDs to blacklist - * - *
Mute list event is not currently created/updated!
- */ -open func muteIds(ids: [EventId])async { - return - try! await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_mute_ids( - self.uniffiClonePointer(), - FfiConverterSequenceTypeEventId.lower(ids) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_void, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_void, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: nil - - ) -} - - /** - * Mute public keys - * - * Add public keys to blacklist - * - *
Mute list event is not currently created/updated!
+ * Get relay pool */ -open func mutePublicKeys(publicKeys: [PublicKey])async { - return - try! await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_mute_public_keys( - self.uniffiClonePointer(), - FfiConverterSequenceTypePublicKey.lower(publicKeys) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_void, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_void, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: nil - - ) +open func pool() -> RelayPool { + return try! FfiConverterTypeRelayPool.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_client_pool(self.uniffiClonePointer(),$0 + ) +}) } /** @@ -1362,6 +1385,9 @@ open func relay(url: String)async throws -> Relay { ) } + /** + * Get relays with `READ` or `WRITE` flags + */ open func relays()async -> [String: Relay] { return try! await uniffiRustCallAsync( @@ -1417,6 +1443,12 @@ open func repost(event: Event, relayUrl: String?)async throws -> SendEventOutpu ) } + /** + * Send event + * + * Send event to all relays with `WRITE` flag. + * If `gossip` is enabled (see `Options`) the event will be sent also to NIP-65 relays (automatically discovered). + */ open func sendEvent(event: Event)async throws -> SendEventOutput { return try await uniffiRustCallAsync( @@ -1435,9 +1467,9 @@ open func sendEvent(event: Event)async throws -> SendEventOutput { } /** - * Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to all relays. + * Take an `EventBuilder`, sign it by using the `NostrSigner` and broadcast to relays (check `send_event` method for more details) * - * Rise an error if the [`NostrSigner`] is not set. + * Rise an error if the `NostrSigner` is not set. */ open func sendEventBuilder(builder: EventBuilder)async throws -> SendEventOutput { return @@ -1457,9 +1489,9 @@ open func sendEventBuilder(builder: EventBuilder)async throws -> SendEventOutpu } /** - * Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to specific relays. + * Take an `EventBuilder`, sign it by using the `NostrSigner` and broadcast to specific relays. * - * Rise an error if the [`NostrSigner`] is not set. + * Rise an error if the `NostrSigner` is not set. */ open func sendEventBuilderTo(urls: [String], builder: EventBuilder)async throws -> SendEventOutput { return @@ -1478,6 +1510,9 @@ open func sendEventBuilderTo(urls: [String], builder: EventBuilder)async throws ) } + /** + * Send event to specific relays. + */ open func sendEventTo(urls: [String], event: Event)async throws -> SendEventOutput { return try await uniffiRustCallAsync( @@ -1495,23 +1530,6 @@ open func sendEventTo(urls: [String], event: Event)async throws -> SendEventOut ) } -open func sendMsg(msg: ClientMessage)async throws -> Output { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_send_msg( - self.uniffiClonePointer(), - FfiConverterTypeClientMessage_lower(msg) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, - liftFunc: FfiConverterTypeOutput.lift, - errorHandler: FfiConverterTypeNostrSdkError.lift - ) -} - open func sendMsgTo(urls: [String], msg: ClientMessage)async throws -> Output { return try await uniffiRustCallAsync( @@ -1645,7 +1663,10 @@ open func signer()async throws -> NostrSigner { } /** - * Subscribe to filters to all connected relays + * Subscribe to filters + * + * If `gossip` is enabled (see `Options]) the events will be requested also to + * NIP-65 relays (automatically discovered) of public keys included in filters (if any). * * ### Auto-closing subscription * @@ -1693,7 +1714,10 @@ open func subscribeTo(urls: [String], filters: [Filter], opts: SubscribeAutoClos } /** - * Subscribe to filters with custom subscription ID to all connected relays + * Subscribe to filters with custom subscription ID + * + * If `gossip` is enabled (see `Options]) the events will be requested also to + * NIP-65 relays (automatically discovered) of public keys included in filters (if any). * * ### Auto-closing subscription * @@ -1776,56 +1800,6 @@ open func subscriptions()async -> [String: [Filter]] { ) } - /** - * Unmute event IDs - * - * Remove event IDs from blacklist - * - *
Mute list event is not currently created/updated!
- */ -open func unmuteIds(ids: [EventId])async { - return - try! await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_unmute_ids( - self.uniffiClonePointer(), - FfiConverterSequenceTypeEventId.lower(ids) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_void, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_void, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: nil - - ) -} - - /** - * Unmute public keys - * - * Remove public keys from blacklist - * - *
Mute list event is not currently created/updated!
- */ -open func unmutePublicKeys(publicKeys: [PublicKey])async { - return - try! await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_client_unmute_public_keys( - self.uniffiClonePointer(), - FfiConverterSequenceTypePublicKey.lower(publicKeys) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_void, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_void, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: nil - - ) -} - open func unsubscribe(subscriptionId: String)async { return try! await uniffiRustCallAsync( @@ -2153,7 +2127,7 @@ public protocol ConnectionProtocol : AnyObject { /** * Use embedded tor client */ - func embeddedTor() -> Connection + func embeddedTor(dataPath: String) -> Connection /** * Set connection mode (default: direct) @@ -2235,9 +2209,10 @@ open func addr(addr: String)throws -> Connection { /** * Use embedded tor client */ -open func embeddedTor() -> Connection { +open func embeddedTor(dataPath: String) -> Connection { return try! FfiConverterTypeConnection.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_connection_embedded_tor(self.uniffiClonePointer(),$0 + uniffi_nostr_sdk_ffi_fn_method_connection_embedded_tor(self.uniffiClonePointer(), + FfiConverterString.lower(dataPath),$0 ) }) } @@ -2355,19 +2330,11 @@ public protocol CustomNostrDatabase : AnyObject { func saveEvent(event: Event) async throws -> Bool /** - * Check if [`Event`] has already been saved - */ - func hasEventAlreadyBeenSaved(eventId: EventId) async throws -> Bool - - /** - * Check if [`EventId`] has already been seen - */ - func hasEventAlreadyBeenSeen(eventId: EventId) async throws -> Bool - - /** - * Check if [`EventId`] has been deleted + * Check event status by ID + * + * Check if the event is saved, deleted or not existent. */ - func hasEventIdBeenDeleted(eventId: EventId) async throws -> Bool + func checkId(eventId: EventId) async throws -> DatabaseEventStatus /** * Check if event with [`Coordinate`] has been deleted before [`Timestamp`] @@ -2386,6 +2353,11 @@ public protocol CustomNostrDatabase : AnyObject { */ func eventSeenOnRelays(eventId: EventId) async throws -> [String]? + /** + * Get event by ID + */ + func eventById(eventId: EventId) async throws -> Event? + /** * Count number of [`Event`] found by filters * @@ -2486,61 +2458,23 @@ open func saveEvent(event: Event)async throws -> Bool { } /** - * Check if [`Event`] has already been saved - */ -open func hasEventAlreadyBeenSaved(eventId: EventId)async throws -> Bool { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_customnostrdatabase_has_event_already_been_saved( - self.uniffiClonePointer(), - FfiConverterTypeEventId_lower(eventId) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_i8, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_i8, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_i8, - liftFunc: FfiConverterBool.lift, - errorHandler: FfiConverterTypeNostrSdkError.lift - ) -} - - /** - * Check if [`EventId`] has already been seen - */ -open func hasEventAlreadyBeenSeen(eventId: EventId)async throws -> Bool { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_customnostrdatabase_has_event_already_been_seen( - self.uniffiClonePointer(), - FfiConverterTypeEventId_lower(eventId) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_i8, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_i8, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_i8, - liftFunc: FfiConverterBool.lift, - errorHandler: FfiConverterTypeNostrSdkError.lift - ) -} - - /** - * Check if [`EventId`] has been deleted + * Check event status by ID + * + * Check if the event is saved, deleted or not existent. */ -open func hasEventIdBeenDeleted(eventId: EventId)async throws -> Bool { +open func checkId(eventId: EventId)async throws -> DatabaseEventStatus { return try await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_customnostrdatabase_has_event_id_been_deleted( + uniffi_nostr_sdk_ffi_fn_method_customnostrdatabase_check_id( self.uniffiClonePointer(), FfiConverterTypeEventId_lower(eventId) ) }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_i8, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_i8, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_i8, - liftFunc: FfiConverterBool.lift, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeDatabaseEventStatus.lift, errorHandler: FfiConverterTypeNostrSdkError.lift ) } @@ -2607,6 +2541,26 @@ open func eventSeenOnRelays(eventId: EventId)async throws -> [String]? { ) } + /** + * Get event by ID + */ +open func eventById(eventId: EventId)async throws -> Event? { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_nostr_sdk_ffi_fn_method_customnostrdatabase_event_by_id( + self.uniffiClonePointer(), + FfiConverterTypeEventId_lower(eventId) + ) + }, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, + liftFunc: FfiConverterOptionTypeEvent.lift, + errorHandler: FfiConverterTypeNostrSdkError.lift + ) +} + /** * Count number of [`Event`] found by filters * @@ -2770,28 +2724,28 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { ) uniffiOutReturn.pointee = uniffiForeignFuture }, - hasEventAlreadyBeenSaved: { ( + checkId: { ( uniffiHandle: UInt64, eventId: UnsafeMutableRawPointer, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteI8, + uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, uniffiCallbackData: UInt64, uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () async throws -> Bool in + () async throws -> DatabaseEventStatus in guard let uniffiObj = try? FfiConverterTypeCustomNostrDatabase.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.hasEventAlreadyBeenSaved( + return try await uniffiObj.checkId( eventId: try FfiConverterTypeEventId_lift(eventId) ) } - let uniffiHandleSuccess = { (returnValue: Bool) in + let uniffiHandleSuccess = { (returnValue: DatabaseEventStatus) in uniffiFutureCallback( uniffiCallbackData, - UniffiForeignFutureStructI8( - returnValue: FfiConverterBool.lower(returnValue), + UniffiForeignFutureStructRustBuffer( + returnValue: FfiConverterTypeDatabaseEventStatus.lower(returnValue), callStatus: RustCallStatus() ) ) @@ -2799,8 +2753,8 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { let uniffiHandleError = { (statusCode, errorBuf) in uniffiFutureCallback( uniffiCallbackData, - UniffiForeignFutureStructI8( - returnValue: 0, + UniffiForeignFutureStructRustBuffer( + returnValue: RustBuffer.empty(), callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) ) ) @@ -2813,9 +2767,10 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { ) uniffiOutReturn.pointee = uniffiForeignFuture }, - hasEventAlreadyBeenSeen: { ( + hasCoordinateBeenDeleted: { ( uniffiHandle: UInt64, - eventId: UnsafeMutableRawPointer, + coordinate: UnsafeMutableRawPointer, + timestamp: UnsafeMutableRawPointer, uniffiFutureCallback: @escaping UniffiForeignFutureCompleteI8, uniffiCallbackData: UInt64, uniffiOutReturn: UnsafeMutablePointer @@ -2825,8 +2780,9 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { guard let uniffiObj = try? FfiConverterTypeCustomNostrDatabase.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.hasEventAlreadyBeenSeen( - eventId: try FfiConverterTypeEventId_lift(eventId) + return try await uniffiObj.hasCoordinateBeenDeleted( + coordinate: try FfiConverterTypeCoordinate_lift(coordinate), + timestamp: try FfiConverterTypeTimestamp_lift(timestamp) ) } @@ -2856,73 +2812,29 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { ) uniffiOutReturn.pointee = uniffiForeignFuture }, - hasEventIdBeenDeleted: { ( + eventIdSeen: { ( uniffiHandle: UInt64, eventId: UnsafeMutableRawPointer, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteI8, - uniffiCallbackData: UInt64, - uniffiOutReturn: UnsafeMutablePointer - ) in - let makeCall = { - () async throws -> Bool in - guard let uniffiObj = try? FfiConverterTypeCustomNostrDatabase.handleMap.get(handle: uniffiHandle) else { - throw UniffiInternalError.unexpectedStaleHandle - } - return try await uniffiObj.hasEventIdBeenDeleted( - eventId: try FfiConverterTypeEventId_lift(eventId) - ) - } - - let uniffiHandleSuccess = { (returnValue: Bool) in - uniffiFutureCallback( - uniffiCallbackData, - UniffiForeignFutureStructI8( - returnValue: FfiConverterBool.lower(returnValue), - callStatus: RustCallStatus() - ) - ) - } - let uniffiHandleError = { (statusCode, errorBuf) in - uniffiFutureCallback( - uniffiCallbackData, - UniffiForeignFutureStructI8( - returnValue: 0, - callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) - ) - ) - } - let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError( - makeCall: makeCall, - handleSuccess: uniffiHandleSuccess, - handleError: uniffiHandleError, - lowerError: FfiConverterTypeNostrSdkError.lower - ) - uniffiOutReturn.pointee = uniffiForeignFuture - }, - hasCoordinateBeenDeleted: { ( - uniffiHandle: UInt64, - coordinate: UnsafeMutableRawPointer, - timestamp: UnsafeMutableRawPointer, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteI8, + relayUrl: RustBuffer, + uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid, uniffiCallbackData: UInt64, uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () async throws -> Bool in + () async throws -> () in guard let uniffiObj = try? FfiConverterTypeCustomNostrDatabase.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.hasCoordinateBeenDeleted( - coordinate: try FfiConverterTypeCoordinate_lift(coordinate), - timestamp: try FfiConverterTypeTimestamp_lift(timestamp) + return try await uniffiObj.eventIdSeen( + eventId: try FfiConverterTypeEventId_lift(eventId), + relayUrl: try FfiConverterString.lift(relayUrl) ) } - let uniffiHandleSuccess = { (returnValue: Bool) in + let uniffiHandleSuccess = { (returnValue: ()) in uniffiFutureCallback( uniffiCallbackData, - UniffiForeignFutureStructI8( - returnValue: FfiConverterBool.lower(returnValue), + UniffiForeignFutureStructVoid( callStatus: RustCallStatus() ) ) @@ -2930,8 +2842,7 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { let uniffiHandleError = { (statusCode, errorBuf) in uniffiFutureCallback( uniffiCallbackData, - UniffiForeignFutureStructI8( - returnValue: 0, + UniffiForeignFutureStructVoid( callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) ) ) @@ -2944,29 +2855,28 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { ) uniffiOutReturn.pointee = uniffiForeignFuture }, - eventIdSeen: { ( + eventSeenOnRelays: { ( uniffiHandle: UInt64, eventId: UnsafeMutableRawPointer, - relayUrl: RustBuffer, - uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid, + uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, uniffiCallbackData: UInt64, uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () async throws -> () in + () async throws -> [String]? in guard let uniffiObj = try? FfiConverterTypeCustomNostrDatabase.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.eventIdSeen( - eventId: try FfiConverterTypeEventId_lift(eventId), - relayUrl: try FfiConverterString.lift(relayUrl) + return try await uniffiObj.eventSeenOnRelays( + eventId: try FfiConverterTypeEventId_lift(eventId) ) } - let uniffiHandleSuccess = { (returnValue: ()) in + let uniffiHandleSuccess = { (returnValue: [String]?) in uniffiFutureCallback( uniffiCallbackData, - UniffiForeignFutureStructVoid( + UniffiForeignFutureStructRustBuffer( + returnValue: FfiConverterOptionSequenceString.lower(returnValue), callStatus: RustCallStatus() ) ) @@ -2974,7 +2884,8 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { let uniffiHandleError = { (statusCode, errorBuf) in uniffiFutureCallback( uniffiCallbackData, - UniffiForeignFutureStructVoid( + UniffiForeignFutureStructRustBuffer( + returnValue: RustBuffer.empty(), callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) ) ) @@ -2987,7 +2898,7 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { ) uniffiOutReturn.pointee = uniffiForeignFuture }, - eventSeenOnRelays: { ( + eventById: { ( uniffiHandle: UInt64, eventId: UnsafeMutableRawPointer, uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, @@ -2995,20 +2906,20 @@ fileprivate struct UniffiCallbackInterfaceCustomNostrDatabase { uniffiOutReturn: UnsafeMutablePointer ) in let makeCall = { - () async throws -> [String]? in + () async throws -> Event? in guard let uniffiObj = try? FfiConverterTypeCustomNostrDatabase.handleMap.get(handle: uniffiHandle) else { throw UniffiInternalError.unexpectedStaleHandle } - return try await uniffiObj.eventSeenOnRelays( + return try await uniffiObj.eventById( eventId: try FfiConverterTypeEventId_lift(eventId) ) } - let uniffiHandleSuccess = { (returnValue: [String]?) in + let uniffiHandleSuccess = { (returnValue: Event?) in uniffiFutureCallback( uniffiCallbackData, UniffiForeignFutureStructRustBuffer( - returnValue: FfiConverterOptionSequenceString.lower(returnValue), + returnValue: FfiConverterOptionTypeEvent.lower(returnValue), callStatus: RustCallStatus() ) ) @@ -3651,52 +3562,29 @@ public func FfiConverterTypeHandleNotification_lower(_ value: HandleNotification /** - * Nostr Wallet Connect client + * A mock relay for (unit) tests. */ -public protocol NwcProtocol : AnyObject { - - /** - * Get balance - */ - func getBalance() async throws -> UInt64 - - /** - * Get info - */ - func getInfo() async throws -> GetInfoResponseResult - - /** - * List transactions - */ - func listTransactions(params: ListTransactionsRequestParams) async throws -> [LookupInvoiceResponseResult] - - /** - * Lookup invoice - */ - func lookupInvoice(params: LookupInvoiceRequestParams) async throws -> LookupInvoiceResponseResult +public protocol MockRelayProtocol : AnyObject { - /** - * Create invoice - */ - func makeInvoice(params: MakeInvoiceRequestParams) async throws -> MakeInvoiceResponseResult + func none() async /** - * Pay invoice + * Shutdown relay */ - func payInvoice(invoice: String) async throws -> String + func shutdown() /** - * Pay keysend + * Get url */ - func payKeysend(params: PayKeysendRequestParams) async throws -> PayKeysendResponseResult + func url() -> String } /** - * Nostr Wallet Connect client + * A mock relay for (unit) tests. */ -open class Nwc: - NwcProtocol { +open class MockRelay: + MockRelayProtocol { fileprivate let pointer: UnsafeMutableRawPointer! /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. @@ -3721,79 +3609,265 @@ open class Nwc: } public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_nostr_sdk_ffi_fn_clone_nwc(self.pointer, $0) } + return try! rustCall { uniffi_nostr_sdk_ffi_fn_clone_mockrelay(self.pointer, $0) } } - /** - * Compose new `NWC` client - */ -public convenience init(uri: NostrWalletConnectUri) { - let pointer = - try! rustCall() { - uniffi_nostr_sdk_ffi_fn_constructor_nwc_new( - FfiConverterTypeNostrWalletConnectURI_lower(uri),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} + // No primary constructor declared for this class. deinit { guard let pointer = pointer else { return } - try! rustCall { uniffi_nostr_sdk_ffi_fn_free_nwc(pointer, $0) } + try! rustCall { uniffi_nostr_sdk_ffi_fn_free_mockrelay(pointer, $0) } } - /** - * Compose new `NWC` client with `NostrWalletConnectOptions` - */ -public static func withOpts(uri: NostrWalletConnectUri, opts: NostrWalletConnectOptions) -> Nwc { - return try! FfiConverterTypeNWC.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_constructor_nwc_with_opts( - FfiConverterTypeNostrWalletConnectURI_lower(uri), - FfiConverterTypeNostrWalletConnectOptions.lower(opts),$0 - ) -}) -} - - - - /** - * Get balance - */ -open func getBalance()async throws -> UInt64 { +public static func run()async throws -> MockRelay { return try await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_nwc_get_balance( - self.uniffiClonePointer() - + uniffi_nostr_sdk_ffi_fn_constructor_mockrelay_run( ) }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_u64, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_u64, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_u64, - liftFunc: FfiConverterUInt64.lift, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_pointer, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_pointer, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_pointer, + liftFunc: FfiConverterTypeMockRelay.lift, errorHandler: FfiConverterTypeNostrSdkError.lift ) } - /** - * Get info - */ -open func getInfo()async throws -> GetInfoResponseResult { + + +open func none()async { return - try await uniffiRustCallAsync( + try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_nwc_get_info( + uniffi_nostr_sdk_ffi_fn_method_mockrelay__none( self.uniffiClonePointer() ) }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_void, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_void, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: nil + + ) +} + + /** + * Shutdown relay + */ +open func shutdown() {try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_mockrelay_shutdown(self.uniffiClonePointer(),$0 + ) +} +} + + /** + * Get url + */ +open func url() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_mockrelay_url(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + +public struct FfiConverterTypeMockRelay: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = MockRelay + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MockRelay { + return MockRelay(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: MockRelay) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MockRelay { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: MockRelay, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeMockRelay_lift(_ pointer: UnsafeMutableRawPointer) throws -> MockRelay { + return try FfiConverterTypeMockRelay.lift(pointer) +} + +public func FfiConverterTypeMockRelay_lower(_ value: MockRelay) -> UnsafeMutableRawPointer { + return FfiConverterTypeMockRelay.lower(value) +} + + + + +/** + * Nostr Wallet Connect client + */ +public protocol NwcProtocol : AnyObject { + + /** + * Get balance + */ + func getBalance() async throws -> UInt64 + + /** + * Get info + */ + func getInfo() async throws -> GetInfoResponseResult + + /** + * List transactions + */ + func listTransactions(params: ListTransactionsRequestParams) async throws -> [LookupInvoiceResponseResult] + + /** + * Lookup invoice + */ + func lookupInvoice(params: LookupInvoiceRequestParams) async throws -> LookupInvoiceResponseResult + + /** + * Create invoice + */ + func makeInvoice(params: MakeInvoiceRequestParams) async throws -> MakeInvoiceResponseResult + + /** + * Pay invoice + */ + func payInvoice(invoice: String) async throws -> String + + /** + * Pay keysend + */ + func payKeysend(params: PayKeysendRequestParams) async throws -> PayKeysendResponseResult + +} + +/** + * Nostr Wallet Connect client + */ +open class Nwc: + NwcProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_nostr_sdk_ffi_fn_clone_nwc(self.pointer, $0) } + } + /** + * Compose new `NWC` client + */ +public convenience init(uri: NostrWalletConnectUri) { + let pointer = + try! rustCall() { + uniffi_nostr_sdk_ffi_fn_constructor_nwc_new( + FfiConverterTypeNostrWalletConnectURI_lower(uri),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_nostr_sdk_ffi_fn_free_nwc(pointer, $0) } + } + + + /** + * Compose new `NWC` client with `NostrWalletConnectOptions` + */ +public static func withOpts(uri: NostrWalletConnectUri, opts: NostrWalletConnectOptions) -> Nwc { + return try! FfiConverterTypeNWC.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_constructor_nwc_with_opts( + FfiConverterTypeNostrWalletConnectURI_lower(uri), + FfiConverterTypeNostrWalletConnectOptions.lower(opts),$0 + ) +}) +} + + + + /** + * Get balance + */ +open func getBalance()async throws -> UInt64 { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_nostr_sdk_ffi_fn_method_nwc_get_balance( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_u64, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_u64, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_u64, + liftFunc: FfiConverterUInt64.lift, + errorHandler: FfiConverterTypeNostrSdkError.lift + ) +} + + /** + * Get info + */ +open func getInfo()async throws -> GetInfoResponseResult { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_nostr_sdk_ffi_fn_method_nwc_get_info( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, liftFunc: FfiConverterTypeGetInfoResponseResult_lift, errorHandler: FfiConverterTypeNostrSdkError.lift ) @@ -4657,8 +4731,6 @@ public func FfiConverterTypeNostrConnectSignerActions_lower(_ value: NostrConnec public protocol NostrDatabaseProtocol : AnyObject { - func none() async - func count(filters: [Filter]) async throws -> UInt64 /** @@ -4669,7 +4741,7 @@ public protocol NostrDatabaseProtocol : AnyObject { /** * Get [`Event`] by [`EventId`] */ - func eventById(eventId: EventId) async throws -> Event + func eventById(eventId: EventId) async throws -> Event? /** * Get list of relays that have seen the [`EventId`] @@ -4742,72 +4814,18 @@ public static func custom(database: CustomNostrDatabase) -> NostrDatabase { } /** - * [`nostrdb`](https://github.com/damus-io/nostrdb) backend + * LMDB backend */ -public static func ndb(path: String)throws -> NostrDatabase { +public static func lmdb(path: String)throws -> NostrDatabase { return try FfiConverterTypeNostrDatabase.lift(try rustCallWithError(FfiConverterTypeNostrSdkError.lift) { - uniffi_nostr_sdk_ffi_fn_constructor_nostrdatabase_ndb( + uniffi_nostr_sdk_ffi_fn_constructor_nostrdatabase_lmdb( FfiConverterString.lower(path),$0 ) }) } - /** - * Open database with **unlimited** capacity - */ -public static func sqlite(path: String)async throws -> NostrDatabase { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_constructor_nostrdatabase_sqlite(FfiConverterString.lower(path) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_pointer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_pointer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_pointer, - liftFunc: FfiConverterTypeNostrDatabase.lift, - errorHandler: FfiConverterTypeNostrSdkError.lift - ) -} - - /** - * Open database with **limited** capacity - */ -public static func sqliteBounded(path: String, maxCapacity: UInt64)async throws -> NostrDatabase { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_constructor_nostrdatabase_sqlite_bounded(FfiConverterString.lower(path),FfiConverterUInt64.lower(maxCapacity) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_pointer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_pointer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_pointer, - liftFunc: FfiConverterTypeNostrDatabase.lift, - errorHandler: FfiConverterTypeNostrSdkError.lift - ) -} - -open func none()async { - return - try! await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_nostrdatabase__none( - self.uniffiClonePointer() - - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_void, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_void, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: nil - - ) -} - open func count(filters: [Filter])async throws -> UInt64 { return try await uniffiRustCallAsync( @@ -4848,7 +4866,7 @@ open func delete(filter: Filter)async throws { /** * Get [`Event`] by [`EventId`] */ -open func eventById(eventId: EventId)async throws -> Event { +open func eventById(eventId: EventId)async throws -> Event? { return try await uniffiRustCallAsync( rustFutureFunc: { @@ -4857,11 +4875,11 @@ open func eventById(eventId: EventId)async throws -> Event { FfiConverterTypeEventId_lower(eventId) ) }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_pointer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_pointer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_pointer, - liftFunc: FfiConverterTypeEvent_lift, - errorHandler: FfiConverterTypeNostrSdkError.lift + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, + liftFunc: FfiConverterOptionTypeEvent.lift, + errorHandler: FfiConverterTypeNostrSdkError.lift ) } @@ -5568,6 +5586,16 @@ public protocol OptionsProtocol : AnyObject { func difficulty(difficulty: UInt8) -> Options + /** + * Set filtering mode (default: blacklist) + */ + func filteringMode(mode: RelayFilteringMode) -> Options + + /** + * Enable gossip model (default: false) + */ + func gossip(enabled: Bool) -> Options + /** * Set max latency (default: None) * @@ -5703,6 +5731,28 @@ open func difficulty(difficulty: UInt8) -> Options { FfiConverterUInt8.lower(difficulty),$0 ) }) +} + + /** + * Set filtering mode (default: blacklist) + */ +open func filteringMode(mode: RelayFilteringMode) -> Options { + return try! FfiConverterTypeOptions.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_options_filtering_mode(self.uniffiClonePointer(), + FfiConverterTypeRelayFilteringMode.lower(mode),$0 + ) +}) +} + + /** + * Enable gossip model (default: false) + */ +open func gossip(enabled: Bool) -> Options { + return try! FfiConverterTypeOptions.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_options_gossip(self.uniffiClonePointer(), + FfiConverterBool.lower(enabled),$0 + ) +}) } /** @@ -6037,11 +6087,6 @@ public protocol RelayProtocol : AnyObject { */ func batchMsg(msgs: [ClientMessage], opts: RelaySendOptions) async throws - /** - * Get blacklist - */ - func blacklist() -> RelayBlacklist - /** * Connect to relay and keep alive connection */ @@ -6064,6 +6109,11 @@ public protocol RelayProtocol : AnyObject { func document() async -> RelayInformationDocument + /** + * Get relay filtering + */ + func filtering() -> RelayFiltering + /** * Get events of filters */ @@ -6214,14 +6264,13 @@ public convenience init(url: String)throws { /** - * Create new `Relay` with **custom** `options` and/or `database` + * Create new `Relay` with **custom** `database` and/or `options` */ -public static func custom(url: String, database: NostrDatabase, blacklist: RelayBlacklist, opts: RelayOptions)throws -> Relay { +public static func custom(url: String, database: NostrDatabase, opts: RelayOptions)throws -> Relay { return try FfiConverterTypeRelay.lift(try rustCallWithError(FfiConverterTypeNostrSdkError.lift) { uniffi_nostr_sdk_ffi_fn_constructor_relay_custom( FfiConverterString.lower(url), FfiConverterTypeNostrDatabase.lower(database), - FfiConverterTypeRelayBlacklist.lower(blacklist), FfiConverterTypeRelayOptions.lower(opts),$0 ) }) @@ -6281,16 +6330,6 @@ open func batchMsg(msgs: [ClientMessage], opts: RelaySendOptions)async throws { ) } - /** - * Get blacklist - */ -open func blacklist() -> RelayBlacklist { - return try! FfiConverterTypeRelayBlacklist.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relay_blacklist(self.uniffiClonePointer(),$0 - ) -}) -} - /** * Connect to relay and keep alive connection */ @@ -6380,6 +6419,16 @@ open func document()async -> RelayInformationDocument { ) } + /** + * Get relay filtering + */ +open func filtering() -> RelayFiltering { + return try! FfiConverterTypeRelayFiltering.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relay_filtering(self.uniffiClonePointer(),$0 + ) +}) +} + /** * Get events of filters */ @@ -6759,15 +6808,235 @@ public func FfiConverterTypeRelay_lower(_ value: Relay) -> UnsafeMutableRawPoint -public protocol RelayBlacklistProtocol : AnyObject { +public protocol RelayConnectionStatsProtocol : AnyObject { + + /** + * The number of times a connection has been attempted + */ + func attempts() -> UInt64 + + /** + * Bytes received + */ + func bytesReceived() -> UInt64 + + /** + * Bytes sent + */ + func bytesSent() -> UInt64 + + /** + * Get UNIX timestamp of the last connection + */ + func connectedAt() -> Timestamp + + /** + * Get UNIX timestamp of the first connection + */ + func firstConnectionTimestamp() -> Timestamp + + func latency() async -> TimeInterval? + + /** + * The number of times a connection has been successfully established + */ + func success() -> UInt64 /** - * Add event IDs to blacklist + * Uptime + */ + func uptime() -> Double + +} + +open class RelayConnectionStats: + RelayConnectionStatsProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_nostr_sdk_ffi_fn_clone_relayconnectionstats(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_nostr_sdk_ffi_fn_free_relayconnectionstats(pointer, $0) } + } + + + + + /** + * The number of times a connection has been attempted + */ +open func attempts() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_attempts(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Bytes received + */ +open func bytesReceived() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_bytes_received(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Bytes sent + */ +open func bytesSent() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_bytes_sent(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get UNIX timestamp of the last connection + */ +open func connectedAt() -> Timestamp { + return try! FfiConverterTypeTimestamp_lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_connected_at(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get UNIX timestamp of the first connection + */ +open func firstConnectionTimestamp() -> Timestamp { + return try! FfiConverterTypeTimestamp_lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_first_connection_timestamp(self.uniffiClonePointer(),$0 + ) +}) +} + +open func latency()async -> TimeInterval? { + return + try! await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_latency( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, + completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, + freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, + liftFunc: FfiConverterOptionDuration.lift, + errorHandler: nil + + ) +} + + /** + * The number of times a connection has been successfully established + */ +open func success() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_success(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Uptime + */ +open func uptime() -> Double { + return try! FfiConverterDouble.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_uptime(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + +public struct FfiConverterTypeRelayConnectionStats: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = RelayConnectionStats + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayConnectionStats { + return RelayConnectionStats(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: RelayConnectionStats) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RelayConnectionStats { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: RelayConnectionStats, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeRelayConnectionStats_lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayConnectionStats { + return try FfiConverterTypeRelayConnectionStats.lift(pointer) +} + +public func FfiConverterTypeRelayConnectionStats_lower(_ value: RelayConnectionStats) -> UnsafeMutableRawPointer { + return FfiConverterTypeRelayConnectionStats.lower(value) +} + + + + +public protocol RelayFilteringProtocol : AnyObject { + + /** + * Add event IDs + * + * Note: IDs are ignored in whitelist mode! */ func addIds(ids: [EventId]) async /** - * Add public keys to blacklist + * Add public keys */ func addPublicKeys(publicKeys: [PublicKey]) async @@ -6777,39 +7046,53 @@ public protocol RelayBlacklistProtocol : AnyObject { func clear() async /** - * Check if blacklist contains event ID + * Check if has event ID */ func hasId(id: EventId) async -> Bool /** - * Check if blacklist contains public key + * Check if has public key */ func hasPublicKey(publicKey: PublicKey) async -> Bool /** - * Remove event ID from blacklist + * Get filtering mode + */ + func mode() -> RelayFilteringMode + + /** + * Remove event ID + * + * Note: IDs are ignored in whitelist mode! */ func removeId(id: EventId) async /** - * Remove event IDs from blacklist + * Remove event IDs + * + * Note: IDs are ignored in whitelist mode! */ func removeIds(ids: [EventId]) async /** - * Remove public key from blacklist + * Remove public key */ func removePublicKey(publicKey: PublicKey) async /** - * Remove event IDs from blacklist + * Remove public keys */ func removePublicKeys(ids: [PublicKey]) async + /** + * Update filtering mode + */ + func updateMode(mode: RelayFilteringMode) + } -open class RelayBlacklist: - RelayBlacklistProtocol { +open class RelayFiltering: + RelayFilteringProtocol { fileprivate let pointer: UnsafeMutableRawPointer! /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. @@ -6834,34 +7117,35 @@ open class RelayBlacklist: } public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_nostr_sdk_ffi_fn_clone_relayblacklist(self.pointer, $0) } + return try! rustCall { uniffi_nostr_sdk_ffi_fn_clone_relayfiltering(self.pointer, $0) } } -public convenience init(ids: [EventId] = [], publicKeys: [PublicKey] = []) { - let pointer = - try! rustCall() { - uniffi_nostr_sdk_ffi_fn_constructor_relayblacklist_new( - FfiConverterSequenceTypeEventId.lower(ids), - FfiConverterSequenceTypePublicKey.lower(publicKeys),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} + // No primary constructor declared for this class. deinit { guard let pointer = pointer else { return } - try! rustCall { uniffi_nostr_sdk_ffi_fn_free_relayblacklist(pointer, $0) } + try! rustCall { uniffi_nostr_sdk_ffi_fn_free_relayfiltering(pointer, $0) } } /** - * construct new empty blacklist + * Construct new filtering in blacklist mode + */ +public static func blacklist() -> RelayFiltering { + return try! FfiConverterTypeRelayFiltering.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_constructor_relayfiltering_blacklist($0 + ) +}) +} + + /** + * Construct new filtering in whitelist mode */ -public static func empty() -> RelayBlacklist { - return try! FfiConverterTypeRelayBlacklist.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_constructor_relayblacklist_empty($0 +public static func whitelist() -> RelayFiltering { + return try! FfiConverterTypeRelayFiltering.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_constructor_relayfiltering_whitelist($0 ) }) } @@ -6869,13 +7153,15 @@ public static func empty() -> RelayBlacklist { /** - * Add event IDs to blacklist + * Add event IDs + * + * Note: IDs are ignored in whitelist mode! */ open func addIds(ids: [EventId])async { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_add_ids( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_add_ids( self.uniffiClonePointer(), FfiConverterSequenceTypeEventId.lower(ids) ) @@ -6890,13 +7176,13 @@ open func addIds(ids: [EventId])async { } /** - * Add public keys to blacklist + * Add public keys */ open func addPublicKeys(publicKeys: [PublicKey])async { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_add_public_keys( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_add_public_keys( self.uniffiClonePointer(), FfiConverterSequenceTypePublicKey.lower(publicKeys) ) @@ -6917,7 +7203,7 @@ open func clear()async { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_clear( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_clear( self.uniffiClonePointer() ) @@ -6932,13 +7218,13 @@ open func clear()async { } /** - * Check if blacklist contains event ID + * Check if has event ID */ open func hasId(id: EventId)async -> Bool { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_has_id( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_has_id( self.uniffiClonePointer(), FfiConverterTypeEventId_lower(id) ) @@ -6953,13 +7239,13 @@ open func hasId(id: EventId)async -> Bool { } /** - * Check if blacklist contains public key + * Check if has public key */ open func hasPublicKey(publicKey: PublicKey)async -> Bool { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_has_public_key( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_has_public_key( self.uniffiClonePointer(), FfiConverterTypePublicKey_lower(publicKey) ) @@ -6974,13 +7260,25 @@ open func hasPublicKey(publicKey: PublicKey)async -> Bool { } /** - * Remove event ID from blacklist + * Get filtering mode + */ +open func mode() -> RelayFilteringMode { + return try! FfiConverterTypeRelayFilteringMode.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_mode(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Remove event ID + * + * Note: IDs are ignored in whitelist mode! */ open func removeId(id: EventId)async { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_remove_id( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_remove_id( self.uniffiClonePointer(), FfiConverterTypeEventId_lower(id) ) @@ -6995,13 +7293,15 @@ open func removeId(id: EventId)async { } /** - * Remove event IDs from blacklist + * Remove event IDs + * + * Note: IDs are ignored in whitelist mode! */ open func removeIds(ids: [EventId])async { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_remove_ids( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_remove_ids( self.uniffiClonePointer(), FfiConverterSequenceTypeEventId.lower(ids) ) @@ -7016,13 +7316,13 @@ open func removeIds(ids: [EventId])async { } /** - * Remove public key from blacklist + * Remove public key */ open func removePublicKey(publicKey: PublicKey)async { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_remove_public_key( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_remove_public_key( self.uniffiClonePointer(), FfiConverterTypePublicKey_lower(publicKey) ) @@ -7037,13 +7337,13 @@ open func removePublicKey(publicKey: PublicKey)async { } /** - * Remove event IDs from blacklist + * Remove public keys */ open func removePublicKeys(ids: [PublicKey])async { return try! await uniffiRustCallAsync( rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayblacklist_remove_public_keys( + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_remove_public_keys( self.uniffiClonePointer(), FfiConverterSequenceTypePublicKey.lower(ids) ) @@ -7057,241 +7357,33 @@ open func removePublicKeys(ids: [PublicKey])async { ) } - -} - -public struct FfiConverterTypeRelayBlacklist: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = RelayBlacklist - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayBlacklist { - return RelayBlacklist(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: RelayBlacklist) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RelayBlacklist { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: RelayBlacklist, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeRelayBlacklist_lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayBlacklist { - return try FfiConverterTypeRelayBlacklist.lift(pointer) -} - -public func FfiConverterTypeRelayBlacklist_lower(_ value: RelayBlacklist) -> UnsafeMutableRawPointer { - return FfiConverterTypeRelayBlacklist.lower(value) -} - - - - -public protocol RelayConnectionStatsProtocol : AnyObject { - - /** - * The number of times a connection has been attempted - */ - func attempts() -> UInt64 - - /** - * Bytes received - */ - func bytesReceived() -> UInt64 - - /** - * Bytes sent - */ - func bytesSent() -> UInt64 - - /** - * Get UNIX timestamp of the last connection - */ - func connectedAt() -> Timestamp - - /** - * Get UNIX timestamp of the first connection - */ - func firstConnectionTimestamp() -> Timestamp - - func latency() async -> TimeInterval? - - /** - * The number of times a connection has been successfully established - */ - func success() -> UInt64 - - /** - * Uptime - */ - func uptime() -> Double - -} - -open class RelayConnectionStats: - RelayConnectionStatsProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_nostr_sdk_ffi_fn_clone_relayconnectionstats(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_nostr_sdk_ffi_fn_free_relayconnectionstats(pointer, $0) } - } - - - - - /** - * The number of times a connection has been attempted - */ -open func attempts() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_attempts(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Bytes received - */ -open func bytesReceived() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_bytes_received(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Bytes sent - */ -open func bytesSent() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_bytes_sent(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Get UNIX timestamp of the last connection - */ -open func connectedAt() -> Timestamp { - return try! FfiConverterTypeTimestamp_lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_connected_at(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Get UNIX timestamp of the first connection - */ -open func firstConnectionTimestamp() -> Timestamp { - return try! FfiConverterTypeTimestamp_lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_first_connection_timestamp(self.uniffiClonePointer(),$0 - ) -}) -} - -open func latency()async -> TimeInterval? { - return - try! await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_latency( - self.uniffiClonePointer() - - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, - liftFunc: FfiConverterOptionDuration.lift, - errorHandler: nil - - ) -} - /** - * The number of times a connection has been successfully established + * Update filtering mode */ -open func success() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_success(self.uniffiClonePointer(),$0 - ) -}) -} - - /** - * Uptime - */ -open func uptime() -> Double { - return try! FfiConverterDouble.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relayconnectionstats_uptime(self.uniffiClonePointer(),$0 +open func updateMode(mode: RelayFilteringMode) {try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayfiltering_update_mode(self.uniffiClonePointer(), + FfiConverterTypeRelayFilteringMode.lower(mode),$0 ) -}) +} } } -public struct FfiConverterTypeRelayConnectionStats: FfiConverter { +public struct FfiConverterTypeRelayFiltering: FfiConverter { typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = RelayConnectionStats + typealias SwiftType = RelayFiltering - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayConnectionStats { - return RelayConnectionStats(unsafeFromRawPointer: pointer) + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayFiltering { + return RelayFiltering(unsafeFromRawPointer: pointer) } - public static func lower(_ value: RelayConnectionStats) -> UnsafeMutableRawPointer { + public static func lower(_ value: RelayFiltering) -> UnsafeMutableRawPointer { return value.uniffiClonePointer() } - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RelayConnectionStats { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RelayFiltering { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -7302,7 +7394,7 @@ public struct FfiConverterTypeRelayConnectionStats: FfiConverter { return try lift(ptr!) } - public static func write(_ value: RelayConnectionStats, into buf: inout [UInt8]) { + public static func write(_ value: RelayFiltering, into buf: inout [UInt8]) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) @@ -7312,12 +7404,12 @@ public struct FfiConverterTypeRelayConnectionStats: FfiConverter { -public func FfiConverterTypeRelayConnectionStats_lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayConnectionStats { - return try FfiConverterTypeRelayConnectionStats.lift(pointer) +public func FfiConverterTypeRelayFiltering_lift(_ pointer: UnsafeMutableRawPointer) throws -> RelayFiltering { + return try FfiConverterTypeRelayFiltering.lift(pointer) } -public func FfiConverterTypeRelayConnectionStats_lower(_ value: RelayConnectionStats) -> UnsafeMutableRawPointer { - return FfiConverterTypeRelayConnectionStats.lower(value) +public func FfiConverterTypeRelayFiltering_lower(_ value: RelayFiltering) -> UnsafeMutableRawPointer { + return FfiConverterTypeRelayFiltering.lower(value) } @@ -7558,6 +7650,11 @@ public protocol RelayOptionsProtocol : AnyObject { */ func connectionMode(mode: ConnectionMode) throws -> RelayOptions + /** + * Set filtering mode (default: blacklist) + */ + func filteringMode(mode: RelayFilteringMode) -> RelayOptions + /** * Set custom limits */ @@ -7698,6 +7795,17 @@ open func connectionMode(mode: ConnectionMode)throws -> RelayOptions { FfiConverterTypeConnectionMode.lower(mode),$0 ) }) +} + + /** + * Set filtering mode (default: blacklist) + */ +open func filteringMode(mode: RelayFilteringMode) -> RelayOptions { + return try! FfiConverterTypeRelayOptions.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relayoptions_filtering_mode(self.uniffiClonePointer(), + FfiConverterTypeRelayFilteringMode.lower(mode),$0 + ) +}) } /** @@ -7885,20 +7993,15 @@ public protocol RelayPoolProtocol : AnyObject { func addRelay(url: String, opts: RelayOptions) async throws -> Bool /** - * Send multiple `Event` at once to **all connected relays** and wait for `OK` message + * Send multiple events at once to all relays with `WRITE` flag */ func batchEvent(events: [Event], opts: RelaySendOptions) async throws -> Output /** - * Send multiple events at once to **specific relays** and wait for `OK` message + * Send multiple events at once to specific relays */ func batchEventTo(urls: [String], events: [Event], opts: RelaySendOptions) async throws -> Output - /** - * Send multiple client messages at once to all connected relays - */ - func batchMsg(msgs: [ClientMessage], opts: RelaySendOptions) async throws -> Output - /** * Send multiple client messages at once to specific relays * @@ -7906,11 +8009,6 @@ public protocol RelayPoolProtocol : AnyObject { */ func batchMsgTo(urls: [String], msgs: [ClientMessage], opts: RelaySendOptions) async throws -> Output - /** - * Get blacklist - */ - func blacklist() -> RelayBlacklist - /** * Connect to all added relays and keep connection alive */ @@ -7931,6 +8029,11 @@ public protocol RelayPoolProtocol : AnyObject { */ func disconnect() async throws + /** + * Get relay filtering + */ + func filtering() -> RelayFiltering + /** * Get events of filters from **specific relays** */ @@ -7964,7 +8067,7 @@ public protocol RelayPoolProtocol : AnyObject { func relay(url: String) async throws -> Relay /** - * Get relays + * Get relays with `READ` or `WRITE` flags */ func relays() async -> [String: Relay] @@ -7973,20 +8076,15 @@ public protocol RelayPoolProtocol : AnyObject { func removeRelay(url: String) async throws /** - * Send event to **all connected relays** and wait for `OK` message + * Send event to all relays with `WRITE` flag */ func sendEvent(event: Event, opts: RelaySendOptions) async throws -> SendEventOutput /** - * Send event to **specific relays** and wait for `OK` message + * Send event to specific relays */ func sendEventTo(urls: [String], event: Event, opts: RelaySendOptions) async throws -> SendEventOutput - /** - * Send client message to all connected relays - */ - func sendMsg(msg: ClientMessage, opts: RelaySendOptions) async throws -> Output - /** * Send client message to specific relays * @@ -8000,7 +8098,7 @@ public protocol RelayPoolProtocol : AnyObject { func shutdown() async throws /** - * Subscribe to filters to all connected relays + * Subscribe to filters to relays with `READ` flag. * * ### Auto-closing subscription * @@ -8020,7 +8118,7 @@ public protocol RelayPoolProtocol : AnyObject { func subscribeTo(urls: [String], filters: [Filter], opts: SubscribeOptions) async throws -> SubscribeOutput /** - * Subscribe with custom subscription ID to all connected relays + * Subscribe with custom subscription ID to relays with `READ` flag. * * ### Auto-closing subscription * @@ -8141,7 +8239,7 @@ open func addRelay(url: String, opts: RelayOptions)async throws -> Bool { } /** - * Send multiple `Event` at once to **all connected relays** and wait for `OK` message + * Send multiple events at once to all relays with `WRITE` flag */ open func batchEvent(events: [Event], opts: RelaySendOptions)async throws -> Output { return @@ -8161,7 +8259,7 @@ open func batchEvent(events: [Event], opts: RelaySendOptions)async throws -> Ou } /** - * Send multiple events at once to **specific relays** and wait for `OK` message + * Send multiple events at once to specific relays */ open func batchEventTo(urls: [String], events: [Event], opts: RelaySendOptions)async throws -> Output { return @@ -8180,26 +8278,6 @@ open func batchEventTo(urls: [String], events: [Event], opts: RelaySendOptions)a ) } - /** - * Send multiple client messages at once to all connected relays - */ -open func batchMsg(msgs: [ClientMessage], opts: RelaySendOptions)async throws -> Output { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relaypool_batch_msg( - self.uniffiClonePointer(), - FfiConverterSequenceTypeClientMessage.lower(msgs),FfiConverterTypeRelaySendOptions.lower(opts) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, - liftFunc: FfiConverterTypeOutput.lift, - errorHandler: FfiConverterTypeNostrSdkError.lift - ) -} - /** * Send multiple client messages at once to specific relays * @@ -8222,16 +8300,6 @@ open func batchMsgTo(urls: [String], msgs: [ClientMessage], opts: RelaySendOptio ) } - /** - * Get blacklist - */ -open func blacklist() -> RelayBlacklist { - return try! FfiConverterTypeRelayBlacklist.lift(try! rustCall() { - uniffi_nostr_sdk_ffi_fn_method_relaypool_blacklist(self.uniffiClonePointer(),$0 - ) -}) -} - /** * Connect to all added relays and keep connection alive */ @@ -8303,6 +8371,16 @@ open func disconnect()async throws { ) } + /** + * Get relay filtering + */ +open func filtering() -> RelayFiltering { + return try! FfiConverterTypeRelayFiltering.lift(try! rustCall() { + uniffi_nostr_sdk_ffi_fn_method_relaypool_filtering(self.uniffiClonePointer(),$0 + ) +}) +} + /** * Get events of filters from **specific relays** */ @@ -8426,7 +8504,7 @@ open func relay(url: String)async throws -> Relay { } /** - * Get relays + * Get relays with `READ` or `WRITE` flags */ open func relays()async -> [String: Relay] { return @@ -8481,7 +8559,7 @@ open func removeRelay(url: String)async throws { } /** - * Send event to **all connected relays** and wait for `OK` message + * Send event to all relays with `WRITE` flag */ open func sendEvent(event: Event, opts: RelaySendOptions)async throws -> SendEventOutput { return @@ -8501,7 +8579,7 @@ open func sendEvent(event: Event, opts: RelaySendOptions)async throws -> SendEv } /** - * Send event to **specific relays** and wait for `OK` message + * Send event to specific relays */ open func sendEventTo(urls: [String], event: Event, opts: RelaySendOptions)async throws -> SendEventOutput { return @@ -8520,26 +8598,6 @@ open func sendEventTo(urls: [String], event: Event, opts: RelaySendOptions)async ) } - /** - * Send client message to all connected relays - */ -open func sendMsg(msg: ClientMessage, opts: RelaySendOptions)async throws -> Output { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_nostr_sdk_ffi_fn_method_relaypool_send_msg( - self.uniffiClonePointer(), - FfiConverterTypeClientMessage_lower(msg),FfiConverterTypeRelaySendOptions.lower(opts) - ) - }, - pollFunc: ffi_nostr_sdk_ffi_rust_future_poll_rust_buffer, - completeFunc: ffi_nostr_sdk_ffi_rust_future_complete_rust_buffer, - freeFunc: ffi_nostr_sdk_ffi_rust_future_free_rust_buffer, - liftFunc: FfiConverterTypeOutput.lift, - errorHandler: FfiConverterTypeNostrSdkError.lift - ) -} - /** * Send client message to specific relays * @@ -8583,7 +8641,7 @@ open func shutdown()async throws { } /** - * Subscribe to filters to all connected relays + * Subscribe to filters to relays with `READ` flag. * * ### Auto-closing subscription * @@ -8633,7 +8691,7 @@ open func subscribeTo(urls: [String], filters: [Filter], opts: SubscribeOptions) } /** - * Subscribe with custom subscription ID to all connected relays + * Subscribe with custom subscription ID to relays with `READ` flag. * * ### Auto-closing subscription * @@ -9949,7 +10007,8 @@ public enum ConnectionMode { case direct case proxy(addr: String ) - case tor + case tor(customPath: String? + ) } @@ -9965,7 +10024,8 @@ public struct FfiConverterTypeConnectionMode: FfiConverterRustBuffer { case 2: return .proxy(addr: try FfiConverterString.read(from: &buf) ) - case 3: return .tor + case 3: return .tor(customPath: try FfiConverterOptionString.read(from: &buf) + ) default: throw UniffiInternalError.unexpectedEnumCase } @@ -9984,9 +10044,10 @@ public struct FfiConverterTypeConnectionMode: FfiConverterRustBuffer { FfiConverterString.write(addr, into: &buf) - case .tor: + case let .tor(customPath): writeInt(&buf, Int32(3)) - + FfiConverterOptionString.write(customPath, into: &buf) + } } } @@ -10070,6 +10131,68 @@ extension ConnectionTarget: Equatable, Hashable {} +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum DatabaseEventStatus { + + case saved + case deleted + case notExistent +} + + +public struct FfiConverterTypeDatabaseEventStatus: FfiConverterRustBuffer { + typealias SwiftType = DatabaseEventStatus + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DatabaseEventStatus { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .saved + + case 2: return .deleted + + case 3: return .notExistent + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: DatabaseEventStatus, into buf: inout [UInt8]) { + switch value { + + + case .saved: + writeInt(&buf, Int32(1)) + + + case .deleted: + writeInt(&buf, Int32(2)) + + + case .notExistent: + writeInt(&buf, Int32(3)) + + } + } +} + + +public func FfiConverterTypeDatabaseEventStatus_lift(_ buf: RustBuffer) throws -> DatabaseEventStatus { + return try FfiConverterTypeDatabaseEventStatus.lift(buf) +} + +public func FfiConverterTypeDatabaseEventStatus_lower(_ value: DatabaseEventStatus) -> RustBuffer { + return FfiConverterTypeDatabaseEventStatus.lower(value) +} + + + +extension DatabaseEventStatus: Equatable, Hashable {} + + + // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. /** @@ -10340,6 +10463,67 @@ extension NostrSdkError: Foundation.LocalizedError { } } +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum RelayFilteringMode { + + /** + * Only the matching values will be allowed + */ + case whitelist + /** + * All matching values will be discarded + */ + case blacklist +} + + +public struct FfiConverterTypeRelayFilteringMode: FfiConverterRustBuffer { + typealias SwiftType = RelayFilteringMode + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RelayFilteringMode { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .whitelist + + case 2: return .blacklist + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: RelayFilteringMode, into buf: inout [UInt8]) { + switch value { + + + case .whitelist: + writeInt(&buf, Int32(1)) + + + case .blacklist: + writeInt(&buf, Int32(2)) + + } + } +} + + +public func FfiConverterTypeRelayFilteringMode_lift(_ buf: RustBuffer) throws -> RelayFilteringMode { + return try FfiConverterTypeRelayFilteringMode.lift(buf) +} + +public func FfiConverterTypeRelayFilteringMode_lower(_ value: RelayFilteringMode) -> RustBuffer { + return FfiConverterTypeRelayFilteringMode.lower(value) +} + + + +extension RelayFilteringMode: Equatable, Hashable {} + + + // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. @@ -10651,6 +10835,27 @@ fileprivate struct FfiConverterOptionSequenceTypeFilter: FfiConverterRustBuffer } } +fileprivate struct FfiConverterOptionTypeEvent: FfiConverterRustBuffer { + typealias SwiftType = Event? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeEvent.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeEvent.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + fileprivate struct FfiConverterOptionTypeEventId: FfiConverterRustBuffer { typealias SwiftType = EventId? @@ -11177,19 +11382,19 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_func_init_logger() != 38847) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_add_relay() != 58887) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_add_discovery_relay() != 57691) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_add_relay_with_opts() != 36241) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_add_read_relay() != 52565) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_add_relays() != 46859) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_add_relay() != 33779) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_automatic_authentication() != 51347) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_add_write_relay() != 6818) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_blacklist() != 3155) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_automatic_authentication() != 51347) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_client_connect() != 30312) { @@ -11213,13 +11418,19 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_client_dislike() != 15515) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_method_client_fetch_metadata() != 24983) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_method_client_file_metadata() != 65496) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_method_client_filtering() != 62979) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_method_client_get_events_from() != 34355) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_get_events_of() != 28254) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_get_events_of() != 44667) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_client_gift_wrap() != 52974) { @@ -11234,10 +11445,7 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_client_like() != 17749) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_mute_ids() != 26708) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_method_client_mute_public_keys() != 39159) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_pool() != 3145) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_client_reaction() != 13847) { @@ -11249,7 +11457,7 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_client_relay() != 53414) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_relays() != 25563) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_relays() != 53935) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_client_remove_relay() != 5421) { @@ -11258,19 +11466,16 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_client_repost() != 15487) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event() != 56846) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event() != 36678) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event_builder() != 57135) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event_builder() != 28604) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event_builder_to() != 63065) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event_builder_to() != 34972) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event_to() != 29322) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_method_client_send_msg() != 26109) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_send_event_to() != 40531) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_client_send_msg_to() != 7643) { @@ -11294,13 +11499,13 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_client_signer() != 31951) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_subscribe() != 27244) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_subscribe() != 20608) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_client_subscribe_to() != 26336) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_subscribe_with_id() != 53663) { + if (uniffi_nostr_sdk_ffi_checksum_method_client_subscribe_with_id() != 13157) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_client_subscribe_with_id_to() != 27069) { @@ -11312,12 +11517,6 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_client_subscriptions() != 20072) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_client_unmute_ids() != 55190) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_method_client_unmute_public_keys() != 32497) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_sdk_ffi_checksum_method_client_unsubscribe() != 16499) { return InitializationResult.apiChecksumMismatch } @@ -11354,7 +11553,7 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_connection_addr() != 43068) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_connection_embedded_tor() != 63012) { + if (uniffi_nostr_sdk_ffi_checksum_method_connection_embedded_tor() != 51580) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_connection_mode() != 217) { @@ -11369,34 +11568,31 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_save_event() != 44808) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_has_event_already_been_saved() != 31021) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_has_event_already_been_seen() != 60236) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_check_id() != 33847) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_has_event_id_been_deleted() != 63072) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_has_coordinate_been_deleted() != 8731) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_has_coordinate_been_deleted() != 45636) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_event_id_seen() != 48961) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_event_id_seen() != 22968) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_event_seen_on_relays() != 64294) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_event_seen_on_relays() != 3595) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_event_by_id() != 63015) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_count() != 49398) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_count() != 29484) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_query() != 32414) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_query() != 33233) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_delete() != 48524) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_delete() != 56179) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_wipe() != 13488) { + if (uniffi_nostr_sdk_ffi_checksum_method_customnostrdatabase_wipe() != 62100) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_handlenotification_handle_msg() != 15446) { @@ -11405,6 +11601,15 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_handlenotification_handle() != 58660) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_method_mockrelay__none() != 40990) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_sdk_ffi_checksum_method_mockrelay_shutdown() != 1736) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_sdk_ffi_checksum_method_mockrelay_url() != 63169) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_method_nwc_get_balance() != 30742) { return InitializationResult.apiChecksumMismatch } @@ -11456,16 +11661,13 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_nostrconnectsigneractions_approve() != 33577) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_nostrdatabase__none() != 38126) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_sdk_ffi_checksum_method_nostrdatabase_count() != 63911) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_nostrdatabase_delete() != 19224) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_nostrdatabase_event_by_id() != 15873) { + if (uniffi_nostr_sdk_ffi_checksum_method_nostrdatabase_event_by_id() != 13180) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_nostrdatabase_event_seen_on_relays() != 47905) { @@ -11528,6 +11730,12 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_options_difficulty() != 20804) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_method_options_filtering_mode() != 33603) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_sdk_ffi_checksum_method_options_gossip() != 22162) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_method_options_max_avg_latency() != 34264) { return InitializationResult.apiChecksumMismatch } @@ -11570,9 +11778,6 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relay_batch_msg() != 15403) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relay_blacklist() != 35021) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_sdk_ffi_checksum_method_relay_connect() != 15421) { return InitializationResult.apiChecksumMismatch } @@ -11588,6 +11793,9 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relay_document() != 55628) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_method_relay_filtering() != 16293) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_method_relay_get_events_of() != 8379) { return InitializationResult.apiChecksumMismatch } @@ -11642,55 +11850,61 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relay_url() != 1351) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_add_ids() != 56523) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_attempts() != 52060) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_bytes_received() != 157) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_bytes_sent() != 64970) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_add_public_keys() != 28791) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_connected_at() != 17598) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_clear() != 40843) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_first_connection_timestamp() != 30824) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_has_id() != 25951) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_latency() != 43153) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_has_public_key() != 23755) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_success() != 52759) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_remove_id() != 32469) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_uptime() != 29449) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_remove_ids() != 19470) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_add_ids() != 37238) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_remove_public_key() != 59175) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_add_public_keys() != 16552) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayblacklist_remove_public_keys() != 53857) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_clear() != 53904) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_attempts() != 52060) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_has_id() != 884) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_bytes_received() != 157) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_has_public_key() != 9857) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_bytes_sent() != 64970) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_mode() != 29749) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_connected_at() != 17598) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_remove_id() != 62305) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_first_connection_timestamp() != 30824) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_remove_ids() != 35650) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_latency() != 43153) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_remove_public_key() != 61695) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_success() != 52759) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_remove_public_keys() != 54891) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relayconnectionstats_uptime() != 29449) { + if (uniffi_nostr_sdk_ffi_checksum_method_relayfiltering_update_mode() != 20763) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_relaylimits_event_max_num_tags() != 29781) { @@ -11714,6 +11928,9 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relayoptions_connection_mode() != 24699) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_method_relayoptions_filtering_mode() != 53101) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_method_relayoptions_limits() != 10405) { return InitializationResult.apiChecksumMismatch } @@ -11753,21 +11970,15 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_add_relay() != 60070) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_batch_event() != 37555) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_batch_event_to() != 15226) { + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_batch_event() != 30015) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_batch_msg() != 33910) { + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_batch_event_to() != 65135) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_batch_msg_to() != 33822) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_blacklist() != 51161) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_connect() != 31806) { return InitializationResult.apiChecksumMismatch } @@ -11780,6 +11991,9 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_disconnect() != 51163) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_filtering() != 46575) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_get_events_from() != 53633) { return InitializationResult.apiChecksumMismatch } @@ -11798,7 +12012,7 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_relay() != 11676) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_relays() != 54295) { + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_relays() != 16476) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_remove_all_relay() != 16039) { @@ -11807,13 +12021,10 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_remove_relay() != 40859) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_send_event() != 60050) { + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_send_event() != 16615) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_send_event_to() != 59933) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_send_msg() != 65023) { + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_send_event_to() != 14653) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_send_msg_to() != 65436) { @@ -11822,13 +12033,13 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_shutdown() != 24603) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_subscribe() != 60735) { + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_subscribe() != 63089) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_subscribe_to() != 20032) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_subscribe_with_id() != 28475) { + if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_subscribe_with_id() != 5916) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_method_relaypool_subscribe_with_id_to() != 46946) { @@ -11897,6 +12108,9 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_constructor_eventsource_specific_relays() != 35301) { return InitializationResult.apiChecksumMismatch } + if (uniffi_nostr_sdk_ffi_checksum_constructor_mockrelay_run() != 52562) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_nostr_sdk_ffi_checksum_constructor_nwc_new() != 26100) { return InitializationResult.apiChecksumMismatch } @@ -11918,13 +12132,7 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_constructor_nostrdatabase_custom() != 63992) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_constructor_nostrdatabase_ndb() != 25092) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_constructor_nostrdatabase_sqlite() != 20589) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_nostr_sdk_ffi_checksum_constructor_nostrdatabase_sqlite_bounded() != 1908) { + if (uniffi_nostr_sdk_ffi_checksum_constructor_nostrdatabase_lmdb() != 21752) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_constructor_nostrsigner_keys() != 51910) { @@ -11945,7 +12153,7 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_constructor_profile_new() != 65224) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_constructor_relay_custom() != 17945) { + if (uniffi_nostr_sdk_ffi_checksum_constructor_relay_custom() != 38370) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_constructor_relay_new() != 3279) { @@ -11954,10 +12162,10 @@ private var initializationResult: InitializationResult = { if (uniffi_nostr_sdk_ffi_checksum_constructor_relay_with_opts() != 9335) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_constructor_relayblacklist_empty() != 38614) { + if (uniffi_nostr_sdk_ffi_checksum_constructor_relayfiltering_blacklist() != 16765) { return InitializationResult.apiChecksumMismatch } - if (uniffi_nostr_sdk_ffi_checksum_constructor_relayblacklist_new() != 62518) { + if (uniffi_nostr_sdk_ffi_checksum_constructor_relayfiltering_whitelist() != 49922) { return InitializationResult.apiChecksumMismatch } if (uniffi_nostr_sdk_ffi_checksum_constructor_relaylimits_disable() != 39641) {