diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..033a7b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc +pex.xcworkspace \ No newline at end of file diff --git a/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/PresentationExchangeSdkiOS.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/PresentationExchangeSdkiOS.xcscheme new file mode 100644 index 0000000..65c5733 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/PresentationExchangeSdkiOS.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..e84bf24 --- /dev/null +++ b/Package.swift @@ -0,0 +1,25 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "PresentationExchangeSdkiOS", + products: [ + // Products define the executables and libraries a package produces, making them visible to other packages. + .library( + name: "PresentationExchangeSdkiOS", + targets: ["PresentationExchangeSdkiOS", "Pexioswrapper"]), + ], + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .target( + name: "PresentationExchangeSdkiOS"), + .binaryTarget( + name: "Pexioswrapper", + path: "Sources/Artifacts/Pexioswrapper.xcframework"), + .testTarget( + name: "PresentationExchangeSdkiOSTests", + dependencies: ["PresentationExchangeSdkiOS"]), + ]) diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/Info.plist b/Sources/Artifacts/Pexioswrapper.xcframework/Info.plist new file mode 100644 index 0000000..6e6bab5 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/Info.plist @@ -0,0 +1,44 @@ + + + + + AvailableLibraries + + + BinaryPath + Pexioswrapper.framework/Versions/A/Pexioswrapper + LibraryIdentifier + ios-arm64 + LibraryPath + Pexioswrapper.framework + SupportedArchitectures + + arm64 + + SupportedPlatform + ios + + + BinaryPath + Pexioswrapper.framework/Versions/A/Pexioswrapper + LibraryIdentifier + ios-arm64_x86_64-simulator + LibraryPath + Pexioswrapper.framework + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + ios + SupportedPlatformVariant + simulator + + + CFBundlePackageType + XFWK + XCFrameworkFormatVersion + 1.0 + + diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Headers b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Modules b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Modules new file mode 120000 index 0000000..5736f31 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Modules @@ -0,0 +1 @@ +Versions/Current/Modules \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Pexioswrapper b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Pexioswrapper new file mode 120000 index 0000000..5d36a87 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Pexioswrapper @@ -0,0 +1 @@ +Versions/Current/Pexioswrapper \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Resources b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h new file mode 100644 index 0000000..ff24cf1 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h @@ -0,0 +1,13 @@ + +// Objective-C API for talking to the following Go packages +// +// github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pexioswrapper +// +// File is generated by gomobile bind. Do not edit. +#ifndef __Pexioswrapper_FRAMEWORK_H__ +#define __Pexioswrapper_FRAMEWORK_H__ + +#include "Pexioswrapper.objc.h" +#include "Universe.objc.h" + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h new file mode 100644 index 0000000..87fda02 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h @@ -0,0 +1,16 @@ +// Objective-C API for talking to github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pexioswrapper Go package. +// gobind -lang=objc github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pexioswrapper +// +// File is generated by gobind. Do not edit. + +#ifndef __Pexioswrapper_H__ +#define __Pexioswrapper_H__ + +@import Foundation; +#include "ref.h" +#include "Universe.objc.h" + + +FOUNDATION_EXPORT NSString* _Nonnull PexioswrapperMatchCredentials(NSString* _Nullable inputDescriptorJson, NSString* _Nullable credentials); + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h new file mode 100644 index 0000000..019e750 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h @@ -0,0 +1,29 @@ +// Objective-C API for talking to Go package. +// gobind -lang=objc +// +// File is generated by gobind. Do not edit. + +#ifndef __Universe_H__ +#define __Universe_H__ + +@import Foundation; +#include "ref.h" + +@protocol Universeerror; +@class Universeerror; + +@protocol Universeerror +- (NSString* _Nonnull)error; +@end + +@class Universeerror; + +@interface Universeerror : NSError { +} +@property(strong, readonly) _Nonnull id _ref; + +- (nonnull instancetype)initWithRef:(_Nonnull id)ref; +- (NSString* _Nonnull)error; +@end + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/ref.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/ref.h new file mode 100644 index 0000000..b8036a4 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/ref.h @@ -0,0 +1,35 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef __GO_REF_HDR__ +#define __GO_REF_HDR__ + +#include + +// GoSeqRef is an object tagged with an integer for passing back and +// forth across the language boundary. A GoSeqRef may represent either +// an instance of a Go object, or an Objective-C object passed to Go. +// The explicit allocation of a GoSeqRef is used to pin a Go object +// when it is passed to Objective-C. The Go seq package maintains a +// reference to the Go object in a map keyed by the refnum along with +// a reference count. When the reference count reaches zero, the Go +// seq package will clear the corresponding entry in the map. +@interface GoSeqRef : NSObject { +} +@property(readonly) int32_t refnum; +@property(strong) id obj; // NULL when representing a Go object. + +// new GoSeqRef object to proxy a Go object. The refnum must be +// provided from Go side. +- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj; + +- (int32_t)incNum; + +@end + +@protocol goSeqRefInterface +-(GoSeqRef*) _ref; +@end + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Modules/module.modulemap b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Modules/module.modulemap new file mode 100644 index 0000000..ee01a39 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Modules/module.modulemap @@ -0,0 +1,8 @@ +framework module "Pexioswrapper" { + header "ref.h" + header "Pexioswrapper.objc.h" + header "Universe.objc.h" + header "Pexioswrapper.h" + + export * +} \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Pexioswrapper b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Pexioswrapper new file mode 100644 index 0000000..7fc03b5 Binary files /dev/null and b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Pexioswrapper differ diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Resources/Info.plist b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..0d1a4b8 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/Current b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Headers b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Modules b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Modules new file mode 120000 index 0000000..5736f31 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Modules @@ -0,0 +1 @@ +Versions/Current/Modules \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Pexioswrapper b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Pexioswrapper new file mode 120000 index 0000000..5d36a87 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Pexioswrapper @@ -0,0 +1 @@ +Versions/Current/Pexioswrapper \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Resources b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h new file mode 100644 index 0000000..ff24cf1 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h @@ -0,0 +1,13 @@ + +// Objective-C API for talking to the following Go packages +// +// github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pexioswrapper +// +// File is generated by gomobile bind. Do not edit. +#ifndef __Pexioswrapper_FRAMEWORK_H__ +#define __Pexioswrapper_FRAMEWORK_H__ + +#include "Pexioswrapper.objc.h" +#include "Universe.objc.h" + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h new file mode 100644 index 0000000..87fda02 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h @@ -0,0 +1,16 @@ +// Objective-C API for talking to github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pexioswrapper Go package. +// gobind -lang=objc github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pexioswrapper +// +// File is generated by gobind. Do not edit. + +#ifndef __Pexioswrapper_H__ +#define __Pexioswrapper_H__ + +@import Foundation; +#include "ref.h" +#include "Universe.objc.h" + + +FOUNDATION_EXPORT NSString* _Nonnull PexioswrapperMatchCredentials(NSString* _Nullable inputDescriptorJson, NSString* _Nullable credentials); + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h new file mode 100644 index 0000000..019e750 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h @@ -0,0 +1,29 @@ +// Objective-C API for talking to Go package. +// gobind -lang=objc +// +// File is generated by gobind. Do not edit. + +#ifndef __Universe_H__ +#define __Universe_H__ + +@import Foundation; +#include "ref.h" + +@protocol Universeerror; +@class Universeerror; + +@protocol Universeerror +- (NSString* _Nonnull)error; +@end + +@class Universeerror; + +@interface Universeerror : NSError { +} +@property(strong, readonly) _Nonnull id _ref; + +- (nonnull instancetype)initWithRef:(_Nonnull id)ref; +- (NSString* _Nonnull)error; +@end + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/ref.h b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/ref.h new file mode 100644 index 0000000..b8036a4 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/ref.h @@ -0,0 +1,35 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef __GO_REF_HDR__ +#define __GO_REF_HDR__ + +#include + +// GoSeqRef is an object tagged with an integer for passing back and +// forth across the language boundary. A GoSeqRef may represent either +// an instance of a Go object, or an Objective-C object passed to Go. +// The explicit allocation of a GoSeqRef is used to pin a Go object +// when it is passed to Objective-C. The Go seq package maintains a +// reference to the Go object in a map keyed by the refnum along with +// a reference count. When the reference count reaches zero, the Go +// seq package will clear the corresponding entry in the map. +@interface GoSeqRef : NSObject { +} +@property(readonly) int32_t refnum; +@property(strong) id obj; // NULL when representing a Go object. + +// new GoSeqRef object to proxy a Go object. The refnum must be +// provided from Go side. +- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj; + +- (int32_t)incNum; + +@end + +@protocol goSeqRefInterface +-(GoSeqRef*) _ref; +@end + +#endif diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Modules/module.modulemap b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Modules/module.modulemap new file mode 100644 index 0000000..ee01a39 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Modules/module.modulemap @@ -0,0 +1,8 @@ +framework module "Pexioswrapper" { + header "ref.h" + header "Pexioswrapper.objc.h" + header "Universe.objc.h" + header "Pexioswrapper.h" + + export * +} \ No newline at end of file diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Pexioswrapper b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Pexioswrapper new file mode 100644 index 0000000..7164f8a Binary files /dev/null and b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Pexioswrapper differ diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Resources/Info.plist b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..0d1a4b8 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/Current b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/Sources/PresentationExchangeSdkiOS/PresentationExchangeSdkiOS.swift b/Sources/PresentationExchangeSdkiOS/PresentationExchangeSdkiOS.swift new file mode 100644 index 0000000..7df6a10 --- /dev/null +++ b/Sources/PresentationExchangeSdkiOS/PresentationExchangeSdkiOS.swift @@ -0,0 +1,27 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book + +import Pexioswrapper + +/// Match list of credentials against input descriptor and return matched credentials +/// - Parameters: +/// - inputDescriptorJson: Json string that conforms to presentation exchange specification +/// - credentials: Json string that is an array of verifiable credentials +/// - Returns: Json string that contains following fields MatchedCredentials, Err +public func matchCredentials(inputDescriptorJson: String, credentials: [String]) -> String { + // Convert array of credentials to JSON array + let jsonData: Data + do { + jsonData = try JSONSerialization.data(withJSONObject: credentials) + } catch { + return "Error: Unable to convert array to JSON data - \(error.localizedDescription)" + } + + // Convert JSON array to string + guard let credentialsJsonString = String(data: jsonData, encoding: .utf8) else { + return "Error: Unable to convert JSON data to string" + } + + let res = PexioswrapperMatchCredentials(inputDescriptorJson, credentialsJsonString) + return res +} diff --git a/Tests/PresentationExchangeSdkiOSTests/PresentationExchangeSdkiOSTests.swift b/Tests/PresentationExchangeSdkiOSTests/PresentationExchangeSdkiOSTests.swift new file mode 100644 index 0000000..6655750 --- /dev/null +++ b/Tests/PresentationExchangeSdkiOSTests/PresentationExchangeSdkiOSTests.swift @@ -0,0 +1,12 @@ +import XCTest +@testable import PresentationExchangeSdkiOS + +final class PresentationExchangeSdkiOSTests: XCTestCase { + func testExample() throws { + // XCTest Documentation + // https://developer.apple.com/documentation/xctest + + // Defining Test Cases and Test Methods + // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods + } +} diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..83c4c29 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,18 @@ +module github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go + +go 1.21.6 + +require github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/ohler55/ojg v1.21.4 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect + github.com/stretchr/testify v1.9.0 // indirect + golang.org/x/mobile v0.0.0-20240213143359-d1f7d3436075 // indirect + golang.org/x/mod v0.15.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/tools v0.18.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go/go.sum b/go/go.sum new file mode 100644 index 0000000..76b20c0 --- /dev/null +++ b/go/go.sum @@ -0,0 +1,29 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/ohler55/ojg v1.21.4 h1:2iWyz/xExx0XySVIxR9kWFxIdsLNrpWLrKuAcs5aOZU= +github.com/ohler55/ojg v1.21.4/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= +github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY= +github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0= +golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/mobile v0.0.0-20240213143359-d1f7d3436075 h1:iZzqyDd8gFkJZpsJNzveyScRBcQlsveheh6Q77LzhPY= +golang.org/x/mobile v0.0.0-20240213143359-d1f7d3436075/go.mod h1:Y8Bnziw2dX69ZhYuqQB8Ihyjks1Q6fMmbg17j9+ISNA= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go/main.go b/go/main.go new file mode 100644 index 0000000..dd1585b --- /dev/null +++ b/go/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "encoding/json" + "fmt" + + "github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pexioswrapper" +) + +func main() { + inputDescriptor := `{"id":"9a18d1b5-13ac-4fbc-8c12-d5916740ce1d","constraints":{"fields":[{"path":["$.type"],"filter":{"type":"array","contains":{"const":"Passport"}}},{"path":["$.name"],"filter":{"type":"string","const":"John"}},{"path":["$.dob"],"filter":{"type":"string","const":"14-Mar-70"}},{"path":["$.address.city"],"filter":{"type":"string","const":"EKM"}}]}}` + credentials := []string{`{"type":["Passport"],"name":"John","dob":"14-Mar-70","address":{"city":"EKM","state":"Kerala"}}`} + + credentialsBytes, _ := json.Marshal(credentials) + + res := pexioswrapper.MatchCredentials(inputDescriptor, string(credentialsBytes)) + fmt.Printf("Response: %v\n", res) +} diff --git a/go/pex/inputdescriptor.go b/go/pex/inputdescriptor.go new file mode 100644 index 0000000..0cdd503 --- /dev/null +++ b/go/pex/inputdescriptor.go @@ -0,0 +1,17 @@ +package pex + +type inputDescriptor struct { + ID string `json:"id"` + Constraints constraints `json:"constraints"` +} + +type constraints struct { + Fields []field `json:"fields"` + LimitedDisclosure string `json:"limited_disclosure"` +} + +type field struct { + Path []string `json:"path"` + Filter interface{} `json:"filter"` + Optional bool `json:"optional"` +} diff --git a/go/pex/matchedcredential.go b/go/pex/matchedcredential.go new file mode 100644 index 0000000..2184651 --- /dev/null +++ b/go/pex/matchedcredential.go @@ -0,0 +1,17 @@ +package pex + +type MatchedPath struct { + Path string `json:"path"` + Index int `json:"index"` + Value interface{} `json:"value"` +} + +type MatchedField struct { + Index int `json:"index"` + Path MatchedPath `json:"path"` +} + +type MatchedCredential struct { + Index int `json:"index"` + Fields []MatchedField `json:"fields"` +} diff --git a/go/pex/pexsdk.go b/go/pex/pexsdk.go new file mode 100644 index 0000000..f0cd4ad --- /dev/null +++ b/go/pex/pexsdk.go @@ -0,0 +1,117 @@ +package pex + +import ( + "encoding/json" + + "github.com/ohler55/ojg/jp" + "github.com/ohler55/ojg/oj" + "github.com/santhosh-tekuri/jsonschema/v5" +) + +func applyJsonPath(inputJsonString string, path string) (results []any, err error) { + // Parse input JSON string + parsedInput, err := oj.ParseString(inputJsonString) + if err != nil { + return nil, err + } + // Parse JSON path string + parsedJsonPath, err := jp.ParseString(path) + if err != nil { + return nil, err + } + // Apply JSON path on input and get the matches + matches := parsedJsonPath.Get(parsedInput) + return matches, nil +} + +func validateJsonSchema(inputJsonString interface{}, schema string) error { + // Compile and parse JSON schema + sch, err := jsonschema.CompileString("schema.json", schema) + if err != nil { + return err + } + // Validate JSON schema against the input JSON string + if err = sch.Validate(inputJsonString); err != nil { + return err + } + return nil +} + +func MatchCredentials(inputDescriptorJson string, credentials []string) ([]MatchedCredential, error) { + // Deserialise input descriptor json string + var descriptor inputDescriptor + err := json.Unmarshal([]byte(inputDescriptorJson), &descriptor) + if err != nil { + return []MatchedCredential{}, err + } + + // To store the matched credentials + matches := make([]MatchedCredential, 0) + + // Iterate through each credential + for credentialIndex, credential := range credentials { + + // Assume credential matches until proven otherwise + credentialMatched := true + var matchedFields []MatchedField + + // Iterate through fields specified in the constraints + for fieldIndex, field := range descriptor.Constraints.Fields { + + // Assume field matches until proven otherwise + fieldMatched := false + + // Iterate through JSON paths for the current field + for pathIndex, path := range field.Path { + + // Apply JSON path on the credential + pathMatches, err := applyJsonPath(credential, path) + + // FIXME: Handle multiple path matches + if len(pathMatches) > 0 && err == nil { + if field.Filter != nil { + filterBytes, err := json.Marshal(field.Filter) + if err != nil { + // Continue to next path, since filter has failed to serialise + continue + } + + // Validate the matched JSON against the field's filter + if err := validateJsonSchema(pathMatches[0], string(filterBytes)); err != nil { + // Field doesn't match since validation failed + fieldMatched = false + break + } + } + + // Add the matched field to the list + fieldMatched = true + matchedFields = append(matchedFields, MatchedField{ + Index: fieldIndex, + Path: MatchedPath{ + Path: path, + Index: pathIndex, + Value: pathMatches[0], + }, + }) + } + } + + if !fieldMatched { + // If any one field didn't match then move to next credential + credentialMatched = false + break + } + } + if credentialMatched { + // All fields matched, then credential is matched + matches = append(matches, MatchedCredential{ + Index: credentialIndex, + Fields: matchedFields, + }) + } + } + + // Return the list of matched credentials + return matches, err +} diff --git a/go/pex/pexsdk_test.go b/go/pex/pexsdk_test.go new file mode 100644 index 0000000..44903ae --- /dev/null +++ b/go/pex/pexsdk_test.go @@ -0,0 +1,65 @@ +package pex + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// Test function for MatchCredentials() function +func TestMatchCredentials(tt *testing.T) { + // Test cases + cases := []struct { + name string + inputDescriptorJson string + credentials []string + }{ + { + "valid input descriptor with 4 fields, 1 path each, 1 filter each and 1 matching credential", + `{"id":"9a18d1b5-13ac-4fbc-8c12-d5916740ce1d","constraints":{"fields":[{"path":["$.type"],"filter":{"type":"array","contains":{"const":"Passport"}}},{"path":["$.name"],"filter":{"type":"string","const":"John"}},{"path":["$.dob"],"filter":{"type":"string","const":"14-Mar-70"}},{"path":["$.address.city"],"filter":{"type":"string","const":"EKM"}}]}}`, + []string{`{"type":["Passport"],"name":"John","dob":"14-Mar-70","address":{"city":"EKM","state":"Kerala"}}`}, + }, + { + "valid input descriptor with 1 field, 1 path each, 0 filter and and 1 matching credential", + `{"id":"9a18d1b5-13ac-4fbc-8c12-d5916740ce1d","constraints":{"fields":[{"path":["$.address.city"]}]}}`, + []string{`{"type":["Passport"],"name":"John","dob":"14-Mar-70","address":{"city":"EKM","state":"Kerala"}}`}, + }, + { + "valid input descriptor with 1 field, 1 path each, 1 filter and and 2 matching credential", + `{"id":"9a18d1b5-13ac-4fbc-8c12-d5916740ce1d","constraints":{"fields":[{"path":["$.address.city"]}]}}`, + []string{ + `{"type":["Passport"],"name":"John","dob":"14-Mar-70","address":{"city":"EKM","state":"Kerala"}}`, + `{"type":["Passport"],"name":"Alice","dob":"14-Mar-80","address":{"city":"Stockholm","state":"Stockholm"}}`, + }, + }, + } + + tt.Run(cases[0].name, func(t *testing.T) { + o, err := MatchCredentials(cases[0].inputDescriptorJson, cases[0].credentials) + assert.Nil(t, err) + assert.Equal(t, 1, len(o)) + assert.Equal(t, 4, len(o[0].Fields)) + }) + + tt.Run(cases[1].name, func(t *testing.T) { + o, err := MatchCredentials(cases[1].inputDescriptorJson, cases[1].credentials) + assert.Nil(t, err) + assert.Equal(t, 1, len(o)) + assert.Equal(t, 1, len(o[0].Fields)) + assert.Equal(t, "$.address.city", o[0].Fields[0].Path.Path) + assert.Equal(t, "EKM", o[0].Fields[0].Path.Value) + }) + + tt.Run(cases[2].name, func(t *testing.T) { + o, err := MatchCredentials(cases[2].inputDescriptorJson, cases[2].credentials) + assert.Nil(t, err) + assert.Equal(t, 2, len(o)) + assert.Equal(t, 1, len(o[0].Fields)) + assert.Equal(t, "$.address.city", o[0].Fields[0].Path.Path) + assert.Equal(t, "EKM", o[0].Fields[0].Path.Value) + + assert.Equal(t, 1, len(o[1].Fields)) + assert.Equal(t, "$.address.city", o[1].Fields[0].Path.Path) + assert.Equal(t, "Stockholm", o[1].Fields[0].Path.Value) + }) +} diff --git a/go/pexioswrapper/pexioswrapper.go b/go/pexioswrapper/pexioswrapper.go new file mode 100644 index 0000000..a366aed --- /dev/null +++ b/go/pexioswrapper/pexioswrapper.go @@ -0,0 +1,32 @@ +package pexioswrapper + +import ( + "encoding/json" + + "github.com/decentralised-dataexchange/presentation-exchange-sdk-ios/go/pex" +) + +type response struct { + MatchedCredentials interface{} + Err string +} + +func MatchCredentials(inputDescriptorJson string, credentials string) string { + // Deserialise string to []string + var credentialsArray []string + err := json.Unmarshal([]byte(credentials), &credentialsArray) + if err != nil { + res, _ := json.Marshal(response{Err: err.Error()}) + return string(res) + } + + // Match credentials against the input descriptor + matchedCredentials, err := pex.MatchCredentials(inputDescriptorJson, credentialsArray) + if err != nil { + res, _ := json.Marshal(response{Err: err.Error()}) + return string(res) + } + + resBytes, _ := json.Marshal(response{MatchedCredentials: matchedCredentials}) + return string(resBytes) +}