Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Rust bindings as library #11

Merged
merged 17 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build+test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
swift-version: "${{ env.swift_version }}"
- name: Check out sources
uses: actions/checkout@v4
- name: Check formatting
run: swift package plugin --allow-writing-to-package-directory swiftformat --lint
#- name: Check formatting
# run: swift package plugin --allow-writing-to-package-directory swiftformat --lint
bisgardo marked this conversation as resolved.
Show resolved Hide resolved
- name: Build project
run: swift build
#- name: Run tests
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "concordium-grpc-api"]
path = concordium-grpc-api
url = https://github.com/Concordium/concordium-grpc-api.git
[submodule "lib/crypto/concordium-base"]
path = lib/crypto/concordium-base
url = https://github.com/Concordium/concordium-base.git
10 changes: 5 additions & 5 deletions ExampleWallet/ExampleWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
A10E85322B56A6110063B079 /* SeedPhraseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10E85312B56A6110063B079 /* SeedPhraseView.swift */; };
A16C9F8F2B5D2CAF0009AD77 /* SeedPhraseValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A16C9F8E2B5D2CAF0009AD77 /* SeedPhraseValidator.swift */; };
A16C9FBC2B5D370C0009AD77 /* SeedPhraseValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A16C9FBB2B5D370C0009AD77 /* SeedPhraseValidatorTests.swift */; };
CD0E4E142B6116CA00E62FF1 /* ConcordiumSwiftSdk in Frameworks */ = {isa = PBXBuildFile; productRef = CD0E4E132B6116CA00E62FF1 /* ConcordiumSwiftSdk */; };
A17E071D2B57E8DE00F7BFFC /* IssueIdentityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17E071C2B57E8DE00F7BFFC /* IssueIdentityView.swift */; };
A17E07202B57EE8E00F7BFFC /* BlueButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17E071F2B57EE8E00F7BFFC /* BlueButton.swift */; };
A17E07222B57F12400F7BFFC /* BlueTextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17E07212B57F12400F7BFFC /* BlueTextStyle.swift */; };
Expand All @@ -20,6 +19,7 @@
A1CD79D82B556FD200F1CAA5 /* ExampleWalletApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1CD79D72B556FD200F1CAA5 /* ExampleWalletApp.swift */; };
A1CD79DC2B556FD300F1CAA5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A1CD79DB2B556FD300F1CAA5 /* Assets.xcassets */; };
A1CD79DF2B556FD300F1CAA5 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A1CD79DE2B556FD300F1CAA5 /* Preview Assets.xcassets */; };
CD0E4E142B6116CA00E62FF1 /* ConcordiumSwiftSdk in Frameworks */ = {isa = PBXBuildFile; productRef = CD0E4E132B6116CA00E62FF1 /* ConcordiumSwiftSdk */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -541,15 +541,15 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
CD0E4E132B6116CA00E62FF1 /* ConcordiumSwiftSdk */ = {
isa = XCSwiftPackageProductDependency;
productName = ConcordiumSwiftSdk;
};
A1A6B3A02B5A893100EC1313 /* MnemonicSwift */ = {
isa = XCSwiftPackageProductDependency;
package = A1A6B39F2B5A893100EC1313 /* XCRemoteSwiftPackageReference "MnemonicSwift" */;
productName = MnemonicSwift;
};
CD0E4E132B6116CA00E62FF1 /* ConcordiumSwiftSdk */ = {
isa = XCSwiftPackageProductDependency;
productName = ConcordiumSwiftSdk;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = A1CD79CC2B556FD200F1CAA5 /* Project object */;
Expand Down
10 changes: 5 additions & 5 deletions ExampleWallet/ExampleWallet/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ struct MainView: View {
NavigationView {
VStack {
getNavigationLinkTo(destination: SeedPhraseView(), withLabel: "Seed phrase view")

BlueButton("Identity recovery view") {}

BlueButton("Identity view") {}

BlueButton("Account view") {}

Spacer()
}
}
}

private func getNavigationLinkTo<Destination: View>(destination: Destination, withLabel label: String) -> some View {
NavigationLink(destination: destination) {
Text(label).modifier(BlueTextStyle())
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ fmt:
.PHONY: generate-grpc
generate-grpc:
protoc --proto_path=./concordium-grpc-api --grpc-swift_opt='Client=true,Server=false' --grpc-swift_out=./Sources/ConcordiumSwiftSdk/Generated/Grpc --swift_out=./Sources/ConcordiumSwiftSdk/Generated/Grpc ./concordium-grpc-api/v2/concordium/*.proto

.PHONY: build-crypto
build-crypto:
cd ./lib/crypto && ./build.sh
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ let package = Package(
.package(url: "https://github.com/anquii/Base58Check.git", from: "1.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.15.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", exact: "0.53.0"),
.package(path: "./lib/crypto/ConcordiumWalletCrypto"),
],
targets: [
.target(
name: "ConcordiumSwiftSdk",
dependencies: [
"Base58Check",
"ConcordiumWalletCrypto",
.product(name: "GRPC", package: "grpc-swift"),
"SwiftFormat",
]
Expand Down
114 changes: 114 additions & 0 deletions Sources/ConcordiumSwiftSdk/ConcordiumHdWallet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import Foundation

import ConcordiumWalletCrypto

enum ConcordiumNetwork: String {
case mainnet = "Mainnet"
case testnet = "Testnet"
}

class ConcordiumHdWallet {
let seedHex: String
let network: ConcordiumNetwork

init(seedHex: String, network: ConcordiumNetwork) {
self.seedHex = seedHex
self.network = network
}

func getAccountSigningKey(identityProviderIndex: UInt32, identityIndex: UInt32, credentialCounter: UInt32) throws -> String {
try ConcordiumWalletCrypto.getAccountSigningKey(
seedHex: seedHex,
network: network.rawValue,
identityProviderIndex: identityProviderIndex,
identityIndex: identityIndex,
credentialCounter: credentialCounter
)
}

func getAccountPublicKey(identityProviderIndex: UInt32, identityIndex: UInt32, credentialCounter: UInt32) throws -> String {
try ConcordiumWalletCrypto.getAccountPublicKey(
seedHex: seedHex,
network: network.rawValue,
identityProviderIndex: identityProviderIndex,
identityIndex: identityIndex,
credentialCounter: credentialCounter
)
}

func getCredentialId(identityProviderIndex: UInt32, identityIndex: UInt32, credentialCounter: UInt8, commitmentKey: String) throws -> String {
try ConcordiumWalletCrypto.getCredentialId(
seedHex: seedHex,
network: network.rawValue,
identityProviderIndex: identityProviderIndex,
identityIndex: identityIndex,
credentialCounter: credentialCounter,
commitmentKey: commitmentKey
)
}

func getPrfKey(identityProviderIndex: UInt32, identityIndex: UInt32) throws -> String {
try ConcordiumWalletCrypto.getPrfKey(
seedHex: seedHex,
network: network.rawValue,
identityProviderIndex: identityProviderIndex,
identityIndex: identityIndex
)
}

func getIdCredSec(identityProviderIndex: UInt32, identityIndex: UInt32) throws -> String {
try ConcordiumWalletCrypto.getIdCredSec(
seedHex: seedHex,
network: network.rawValue,
identityProviderIndex: identityProviderIndex,
identityIndex: identityIndex
)
}

func getSignatureBlindingRandomness(identityProviderIndex: UInt32, identityIndex: UInt32) throws -> String {
try ConcordiumWalletCrypto.getSignatureBlindingRandomness(
seedHex: seedHex,
network: network.rawValue,
identityProviderIndex: identityProviderIndex,
identityIndex: identityIndex
)
}

func getAttributeCommitmentRandomness(identityProviderIndex: UInt32, identityIndex: UInt32, credentialCounter: UInt32, attribute: UInt8) throws -> String {
try ConcordiumWalletCrypto.getAttributeCommitmentRandomness(
seedHex: seedHex,
network: network.rawValue,
identityProviderIndex: identityProviderIndex,
identityIndex: identityIndex,
credentialCounter: credentialCounter,
attribute: attribute
)
}

func getVerifiableCredentialSigningKey(issuerIndex: UInt64, issuerSubindex: UInt64, verifiableCredentialIndex: UInt32) throws -> String {
try ConcordiumWalletCrypto.getVerifiableCredentialSigningKey(
seedHex: seedHex,
network: network.rawValue,
issuerIndex: issuerIndex,
issuerSubindex: issuerSubindex,
verifiableCredentialIndex: verifiableCredentialIndex
)
}

func getVerifiableCredentialPublicKey(issuerIndex: UInt64, issuerSubindex: UInt64, verifiableCredentialIndex: UInt32) throws -> String {
try ConcordiumWalletCrypto.getVerifiableCredentialPublicKey(
seedHex: seedHex,
network: network.rawValue,
issuerIndex: issuerIndex,
issuerSubindex: issuerSubindex,
verifiableCredentialIndex: verifiableCredentialIndex
)
}

func getVerifiableCredentialBackupEncryptionKey() throws -> String {
try ConcordiumWalletCrypto.getVerifiableCredentialBackupEncryptionKey(
seedHex: seedHex,
network: network.rawValue
)
}
}
1 change: 1 addition & 0 deletions Sources/ConcordiumSwiftSdk/ConcordiumNodeClient.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ConcordiumWalletCrypto
import Foundation
import GRPC
import NIOCore
Expand Down
Loading