Skip to content

Commit

Permalink
Generate Go Bindings
Browse files Browse the repository at this point in the history
This chances `ParticipantIdentifier` to be represented as a hex
string instead of bytes, because GoLang can use Bytes as a key
for maps [see](NordSecurity/uniffi-bindgen-go#52)
  • Loading branch information
pacu committed Jun 10, 2024
1 parent 058dfb3 commit 3c1d2fb
Show file tree
Hide file tree
Showing 8 changed files with 2,845 additions and 10 deletions.
8 changes: 4 additions & 4 deletions FrostSwift/Sources/FrostSwiftFFI/frost_uniffi_sdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -946,11 +946,11 @@ public func FfiConverterTypeMessage_lower(_ value: Message) -> RustBuffer {


public struct ParticipantIdentifier {
public var data: Data
public var data: String

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(data: Data) {
public init(data: String) {
self.data = data
}
}
Expand All @@ -973,12 +973,12 @@ extension ParticipantIdentifier: Equatable, Hashable {
public struct FfiConverterTypeParticipantIdentifier: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ParticipantIdentifier {
return try ParticipantIdentifier(
data: FfiConverterData.read(from: &buf)
data: FfiConverterString.read(from: &buf)
)
}

public static func write(_ value: ParticipantIdentifier, into buf: inout [UInt8]) {
FfiConverterData.write(value.data, into: &buf)
FfiConverterString.write(value.data, into: &buf)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let package = Package(
.target(name: "FrostSwiftFFI")
], path: "FrostSwift/Sources/FrostSwift"
),
.binaryTarget(name: "RustFramework", url: "https://github.com/pacu/frost-uniffi-sdk/releases/download/0.0.1/RustFramework.xcframework.zip", checksum: "c273d33439e052316bb6f78390d124c3dabf6a8f9b99e26525b92057d38bc2f7"),
.binaryTarget(name: "RustFramework", path: "FrostSwift/RustFramework.xcframework.zip"),
.target(
name: "FrostSwiftFFI",
dependencies: [
Expand Down
11 changes: 7 additions & 4 deletions frost-uniffi-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct ParticipantList {

#[derive(uniffi::Record, Hash, Eq, PartialEq, Clone)]
pub struct ParticipantIdentifier {
pub data: Vec<u8>,
pub data: String,
}

#[derive(uniffi::Record)]
Expand Down Expand Up @@ -203,16 +203,19 @@ impl FrostKeyPackage {
impl ParticipantIdentifier {
pub fn from_identifier(identifier: Identifier) -> Result<ParticipantIdentifier, Error> {
Ok(ParticipantIdentifier {
data: identifier.clone().serialize().to_vec(),
data: hex::encode(identifier.clone().serialize()),
})
}

pub fn into_identifier(&self) -> Result<Identifier, Error> {
let raw_bytes = self.data[0..32]
let raw_bytes = hex::decode(self.data.clone())
.map_err(|_| Error::DeserializationError)?;

let raw_identifier = raw_bytes[0..32]
.try_into()
.map_err(|_| Error::DeserializationError)?;

Identifier::deserialize(&raw_bytes)
Identifier::deserialize(&raw_identifier)
}
}

Expand Down
6 changes: 5 additions & 1 deletion frost-uniffi-sdk/uniffi.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## Custom UniFFI binding generation settings
## See https://mozilla.github.io/uniffi-rs/swift/configuration.html.
#[bindings.kotlin]
[bindings.swift]
[bindings.swift]

[bindings.go]
package_name = "frost_go_ffi"
module_name = "frost_go_ffi"
8 changes: 8 additions & 0 deletions frost_go_ffi/frost_go_ffi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <frost_go_ffi.h>

// This file exists beacause of
// https://github.com/golang/go/issues/11263

void cgo_rust_task_callback_bridge_frost_go_ffi(RustTaskCallback cb, const void * taskData, int8_t status) {
cb(taskData, status);
}
Loading

0 comments on commit 3c1d2fb

Please sign in to comment.