diff --git a/Package.swift b/Package.swift
index b2d489b..2575752 100644
--- a/Package.swift
+++ b/Package.swift
@@ -9,17 +9,42 @@ let package = Package(
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "PresentationExchangeSdkiOS",
- targets: ["PresentationExchangeSdkiOS", "Pexioswrapper"]),
+ targets: ["PresentationExchangeSdkiOS"]),
+ ],
+ dependencies: [
+ .package(
+ url: "https://github.com/KittyMac/Sextant.git",
+ .upToNextMinor(from: "0.4.0")
+ ),
+ .package(
+ url: "https://github.com/kylef/JSONSchema.swift",
+ from: "0.6.0"
+ )
],
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"),
+ name: "PresentationExchangeSdkiOS",
+ dependencies: [
+ .product(
+ name: "Sextant",
+ package: "Sextant"
+ ),
+ .product(
+ name: "JSONSchema",
+ package: "JSONSchema.swift"
+ ),
+ ]),
.testTarget(
name: "PresentationExchangeSdkiOSTests",
- dependencies: ["PresentationExchangeSdkiOS"]),
+ dependencies: ["PresentationExchangeSdkiOS",
+ .product(
+ name: "Sextant",
+ package: "Sextant"
+ ),
+ .product(
+ name: "JSONSchema",
+ package: "JSONSchema.swift"
+ )]),
])
diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/Info.plist b/Sources/Artifacts/Pexioswrapper.xcframework/Info.plist
deleted file mode 100644
index 6e6bab5..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/Info.plist
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
- 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
deleted file mode 120000
index a177d2a..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Headers
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 120000
index 5736f31..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Modules
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 120000
index 5d36a87..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Pexioswrapper
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 120000
index 953ee36..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Resources
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 100644
index ff24cf1..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h
+++ /dev/null
@@ -1,13 +0,0 @@
-
-// 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
deleted file mode 100644
index 87fda02..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// 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
deleted file mode 100644
index 019e750..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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
deleted file mode 100644
index b8036a4..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Headers/ref.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// 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
deleted file mode 100644
index ee01a39..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Modules/module.modulemap
+++ /dev/null
@@ -1,8 +0,0 @@
-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
deleted file mode 100644
index 7fc03b5..0000000
Binary files a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Pexioswrapper and /dev/null 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
deleted file mode 100644
index 0d1a4b8..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/A/Resources/Info.plist
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/Current b/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/Current
deleted file mode 120000
index 8c7e5a6..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64/Pexioswrapper.framework/Versions/Current
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 120000
index a177d2a..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Headers
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 120000
index 5736f31..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Modules
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 120000
index 5d36a87..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Pexioswrapper
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 120000
index 953ee36..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Resources
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 100644
index ff24cf1..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.h
+++ /dev/null
@@ -1,13 +0,0 @@
-
-// 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
deleted file mode 100644
index 87fda02..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Pexioswrapper.objc.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// 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
deleted file mode 100644
index 019e750..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/Universe.objc.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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
deleted file mode 100644
index b8036a4..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Headers/ref.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// 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
deleted file mode 100644
index ee01a39..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Modules/module.modulemap
+++ /dev/null
@@ -1,8 +0,0 @@
-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
deleted file mode 100644
index 7164f8a..0000000
Binary files a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Pexioswrapper and /dev/null 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
deleted file mode 100644
index 0d1a4b8..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/A/Resources/Info.plist
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
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
deleted file mode 120000
index 8c7e5a6..0000000
--- a/Sources/Artifacts/Pexioswrapper.xcframework/ios-arm64_x86_64-simulator/Pexioswrapper.framework/Versions/Current
+++ /dev/null
@@ -1 +0,0 @@
-A
\ No newline at end of file
diff --git a/Sources/PresentationExchangeSdkiOS/Models/InputDescriptor.swift b/Sources/PresentationExchangeSdkiOS/Models/InputDescriptor.swift
new file mode 100644
index 0000000..4ff8977
--- /dev/null
+++ b/Sources/PresentationExchangeSdkiOS/Models/InputDescriptor.swift
@@ -0,0 +1,128 @@
+//
+// PresentationDefinitionModel.swift
+//
+//
+// Created by milan on 7/8/24.
+//
+import Foundation
+// MARK: - InputDescriptor
+public struct InputDescriptor: Codable {
+ public var id: String?
+ public let name: String?
+ public let purpose: String?
+ public var constraints: Constraints?
+}
+// MARK: - Constraints
+public struct Constraints: Codable {
+ public let limitDisclosure: String?
+ public var fields: [Field]?
+ enum CodingKeys: String, CodingKey {
+ case fields
+ case limitDisclosure = "limit_disclosure"
+ }
+}
+// MARK: - Field
+public struct Field: Codable, Hashable {
+ public let paths: [String]
+ public let filter: [String: Any]?
+
+ enum CodingKeys: String, CodingKey {
+ case paths = "path"
+ case filter
+ }
+
+ public init(paths: [String], filter: [String: Any]?) {
+ self.paths = paths
+ self.filter = filter
+ }
+
+ public init(from decoder: Decoder) throws {
+ let container = try decoder.container(keyedBy: CodingKeys.self)
+ paths = try container.decode([String].self, forKey: .paths)
+ let jsonAnyDictionary = try container.decodeIfPresent([String: JSONAny].self, forKey: .filter)
+ filter = jsonAnyDictionary?.mapValues { $0.value }
+ }
+
+ public func encode(to encoder: Encoder) throws {
+ var container = encoder.container(keyedBy: CodingKeys.self)
+ try container.encode(paths, forKey: .paths)
+ if let filter = filter {
+ let jsonAnyDictionary = filter.mapValues { JSONAny($0) }
+ try container.encode(jsonAnyDictionary, forKey: .filter)
+ }
+ }
+
+ public func hash(into hasher: inout Hasher) {
+ hasher.combine(paths)
+ if let filter = filter {
+ for (key, value) in filter {
+ hasher.combine(key)
+ if let value = value as? String {
+ hasher.combine(value)
+ }
+ }
+ }
+ }
+
+ public static func == (lhs: Field, rhs: Field) -> Bool {
+ return lhs.paths == rhs.paths &&
+ NSDictionary(dictionary: lhs.filter ?? [:]).isEqual(to: rhs.filter ?? [:])
+ }
+}
+
+public struct JSONAny: Codable {
+ public let value: Any
+
+ public init(_ value: Any) {
+ self.value = value
+ }
+
+ public init(from decoder: Decoder) throws {
+ let container = try decoder.singleValueContainer()
+
+ if let intValue = try? container.decode(Int.self) {
+ value = intValue
+ } else if let doubleValue = try? container.decode(Double.self) {
+ value = doubleValue
+ } else if let stringValue = try? container.decode(String.self) {
+ value = stringValue
+ } else if let boolValue = try? container.decode(Bool.self) {
+ value = boolValue
+ } else if let nestedDictionary = try? container.decode([String: JSONAny].self) {
+ value = nestedDictionary.mapValues { $0.value }
+ } else if let nestedArray = try? container.decode([JSONAny].self) {
+ value = nestedArray.map { $0.value }
+ } else {
+ throw DecodingError.typeMismatch(
+ JSONAny.self,
+ DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Unable to decode JSONAny")
+ )
+ }
+ }
+
+ public func encode(to encoder: Encoder) throws {
+ var container = encoder.singleValueContainer()
+
+ switch value {
+ case let intValue as Int:
+ try container.encode(intValue)
+ case let doubleValue as Double:
+ try container.encode(doubleValue)
+ case let stringValue as String:
+ try container.encode(stringValue)
+ case let boolValue as Bool:
+ try container.encode(boolValue)
+ case let dictionaryValue as [String: Any]:
+ let wrappedDictionary = dictionaryValue.mapValues { JSONAny($0) }
+ try container.encode(wrappedDictionary)
+ case let arrayValue as [Any]:
+ let wrappedArray = arrayValue.map { JSONAny($0) }
+ try container.encode(wrappedArray)
+ default:
+ throw EncodingError.invalidValue(
+ value,
+ EncodingError.Context(codingPath: encoder.codingPath, debugDescription: "Unable to encode JSONAny")
+ )
+ }
+ }
+}
diff --git a/Sources/PresentationExchangeSdkiOS/Models/MatchedCredential.swift b/Sources/PresentationExchangeSdkiOS/Models/MatchedCredential.swift
new file mode 100644
index 0000000..8952a33
--- /dev/null
+++ b/Sources/PresentationExchangeSdkiOS/Models/MatchedCredential.swift
@@ -0,0 +1,88 @@
+//
+// File.swift
+//
+//
+// Created by oem on 09/08/24.
+//
+
+import Foundation
+
+public class MatchedCredential: Encodable {
+ public var index: Int
+ public var fields: [MatchedField]
+
+ public init(index: Int, fields: [MatchedField]) {
+ self.index = index
+ self.fields = fields
+ }
+
+ enum CodingKeys: String, CodingKey {
+ case index, fields
+ }
+}
+
+public class MatchedField: Encodable {
+ public var index: Int
+ public var path: MatchedPath
+
+ public init(index: Int, path: MatchedPath) {
+ self.index = index
+ self.path = path
+ }
+
+ enum CodingKeys: String, CodingKey {
+ case index, path
+ }
+}
+
+public class MatchedPath: Encodable {
+ public var path: String?
+ public var index: Int
+ public var value: Any?
+
+ public init(path: String?, index: Int, value: Any?) {
+ self.path = path
+ self.index = index
+ self.value = value
+ }
+
+ enum CodingKeys: String, CodingKey {
+ case path, index, value
+ }
+
+ public func encode(to encoder: Encoder) throws {
+ var container = encoder.container(keyedBy: CodingKeys.self)
+ try container.encode(path, forKey: .path)
+ try container.encode(index, forKey: .index)
+
+ if let value = value {
+ switch value {
+ case let stringValue as String:
+ try container.encode(stringValue, forKey: .value)
+ case let intValue as Int:
+ try container.encode(intValue, forKey: .value)
+ case let doubleValue as Double:
+ try container.encode(doubleValue, forKey: .value)
+ case let boolValue as Bool:
+ try container.encode(boolValue, forKey: .value)
+ case let arrayValue as [Any]:
+ var nestedContainer = container.nestedUnkeyedContainer(forKey: .value)
+ for element in arrayValue {
+ if let encodableElement = element as? Encodable {
+ try encodableElement.encode(to: nestedContainer.superEncoder())
+ }
+ }
+ case let dictValue as [String: Any]:
+ var nestedContainer = container.nestedContainer(keyedBy: CodingKeys.self, forKey: .value)
+ for (key, element) in dictValue {
+ if let encodableElement = element as? Encodable {
+ try encodableElement.encode(to: nestedContainer.superEncoder(forKey: CodingKeys(stringValue: key)!))
+ }
+ }
+ default:
+ throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: encoder.codingPath, debugDescription: "Invalid value type for encoding"))
+ }
+ }
+ }
+}
+
diff --git a/Sources/PresentationExchangeSdkiOS/PresentationExchangeSdkiOS.swift b/Sources/PresentationExchangeSdkiOS/PresentationExchangeSdkiOS.swift
index 7df6a10..fa60243 100644
--- a/Sources/PresentationExchangeSdkiOS/PresentationExchangeSdkiOS.swift
+++ b/Sources/PresentationExchangeSdkiOS/PresentationExchangeSdkiOS.swift
@@ -1,27 +1,111 @@
-// The Swift Programming Language
-// https://docs.swift.org/swift-book
-
+import Foundation
+import Sextant
+import JSONSchema
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)"
+/// - inputDescriptorJson: JSON string that conforms to presentation exchange specification
+/// - credentials: JSON string that is an array of verifiable credentials
+/// - Returns: JSON string that contains the matched credentials or an error message
+public func matchCredentials(inputDescriptorJson: String, credentials: [String]) throws -> [MatchedCredential] {
+ let decoder = JSONDecoder()
+ let descriptor = try decoder.decode(InputDescriptor.self, from: Data(inputDescriptorJson.utf8))
+
+ var matches = [MatchedCredential]()
+
+ for (credentialIndex, credential) in credentials.enumerated() {
+ var credentialMatched = true
+ var matchedFields = [MatchedField]()
+
+ if let fields = descriptor.constraints?.fields {
+ for (fieldIndex, field) in fields.enumerated() {
+ var fieldMatched = false
+
+ for (pathIndex, path) in field.paths.enumerated() {
+ do {
+ let pathMatches = try applyJsonPath(inputJsonString: credential, path: path)
+ if let firstMatch = pathMatches.first {
+ if let filter = field.filter {
+ let filterData = try JSONSerialization.data(withJSONObject: filter)
+ if let filterString = String(data: filterData, encoding: .utf8) {
+ try validateJsonSchema(inputJsonString: firstMatch, schema: filter)
+ }
+ }
+ fieldMatched = true
+ matchedFields.append(MatchedField(index: fieldIndex, path: MatchedPath(path: path, index: pathIndex, value: firstMatch)))
+ }
+ } catch {
+ continue
+ }
+ }
+
+ if !fieldMatched {
+ credentialMatched = false
+ break
+ }
+ }
+ }
+
+ if credentialMatched {
+ matches.append(MatchedCredential(index: credentialIndex, fields: matchedFields))
+ }
}
+ return matches
+}
- // Convert JSON array to string
- guard let credentialsJsonString = String(data: jsonData, encoding: .utf8) else {
- return "Error: Unable to convert JSON data to string"
+// Function to apply JSON path
+func applyJsonPath(inputJsonString: String, path: String) throws -> [Any] {
+ guard let jsonData = inputJsonString.data(using: .utf8) else {
+ throw NSError(domain: "Invalid JSON string", code: 0, userInfo: nil)
}
+ let parsedInput = try JSONSerialization.jsonObject(with: jsonData)
+ let parsedJsonPath = try parseJsonPath(path)
+ return parsedJsonPath.get(inputJsonString)
+}
+
+// Function to validate JSON schema
+func validateJsonSchema(inputJsonString: Any, schema: [String: Any]) throws {
+ let schemaValidator = try compileJsonSchema(schema: schema)
+ try schemaValidator.validate(inputJsonString)
+}
+
+// Placeholder functions to simulate JSON path parsing and JSON schema validation.
+func parseJsonPath(_ path: String) throws -> SomeJsonPathParser {
+ return SomeJsonPathParser(path: path)
+}
+
+func compileJsonSchema(schema: [String: Any]) throws -> SomeJsonSchemaValidator {
+ return SomeJsonSchemaValidator(schema: schema)
+}
+
+// Implementation for JSON path parser
+struct SomeJsonPathParser {
+ let path: String
+
+ func get(_ json: String) -> [Any] {
+ do {
+ return try json.query(values: path)?.compactMap({ $0 }) ?? []
+ } catch {
+ print("JSONPath error: \(error)")
+ return []
+ }
+ }
+}
+
+// Implementation for JSON schema validator
+struct SomeJsonSchemaValidator {
+ let schema: [String: Any]
+
+ func validate(_ json: Any) throws {
+ let validationResult = try JSONSchema.validate(json, schema: schema)
+ if !validationResult.valid {
+ throw ValidationError.validationFailed("Validation failed")
+ }
+ }
+}
- let res = PexioswrapperMatchCredentials(inputDescriptorJson, credentialsJsonString)
- return res
+enum ValidationError: Error {
+ case invalidJson
+ case validationFailed(String) // You can include more details if needed
}
diff --git a/Tests/PresentationExchangeSdkiOSTests/PresentationExchangeSdkiOSTests.swift b/Tests/PresentationExchangeSdkiOSTests/PresentationExchangeSdkiOSTests.swift
index 6655750..2bca55a 100644
--- a/Tests/PresentationExchangeSdkiOSTests/PresentationExchangeSdkiOSTests.swift
+++ b/Tests/PresentationExchangeSdkiOSTests/PresentationExchangeSdkiOSTests.swift
@@ -1,12 +1,123 @@
import XCTest
@testable import PresentationExchangeSdkiOS
-final class PresentationExchangeSdkiOSTests: XCTestCase {
- func testExample() throws {
- // XCTest Documentation
- // https://developer.apple.com/documentation/xctest
+class MatchCredentialsTests: XCTestCase {
- // Defining Test Cases and Test Methods
- // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
+ func testMatchCredentialsSuccess() {
+ let inputDescriptorJson = """
+ {
+ "id": "test",
+ "constraints": {
+ "fields": [
+ {
+ "path": ["$.address.city"],
+ "filter": {
+ "type": "string",
+ "enum": ["New York"]
+ }
+ }
+ ]
+ }
+ }
+ """
+
+ let credentials = [
+ """
+ {
+ "type": ["Passport"],
+ "name": "John Doe",
+ "dob": "14-Mar-70",
+ "address": {
+ "city": "New York",
+ "state": "NY"
+ }
+ }
+ """
+ ]
+
+ do {
+ let matchedCredentials = try matchCredentials(inputDescriptorJson: inputDescriptorJson, credentials: credentials)
+ XCTAssertEqual(matchedCredentials.count, 1, "Expected one matched credential")
+ XCTAssertEqual(matchedCredentials.first?.fields.count, 1, "Expected one matched field")
+ } catch {
+ XCTFail("Unexpected error: \(error)")
+ }
+ }
+
+ func testMatchCredentialsNoMatch() {
+ let inputDescriptorJson = """
+ {
+ "id": "test",
+ "constraints": {
+ "fields": [
+ {
+ "path": ["$.address.city"],
+ "filter": {
+ "type": "string",
+ "enum": ["Los Angeles"]
+ }
+ }
+ ]
+ }
+ }
+ """
+
+ let credentials = [
+ """
+ {
+ "type": ["Passport"],
+ "name": "John Doe",
+ "dob": "14-Mar-70",
+ "address": {
+ "city": "New York",
+ "state": "NY"
+ }
+ }
+ """
+ ]
+
+ do {
+ let matchedCredentials = try matchCredentials(inputDescriptorJson: inputDescriptorJson, credentials: credentials)
+ XCTAssertEqual(matchedCredentials.count, 0, "Expected no matched credentials")
+ } catch {
+ XCTFail("Unexpected error: \(error)")
+ }
+ }
+
+ func testMatchCredentialsInvalidJson() {
+ let inputDescriptorJson = """
+ {
+ "id": "test",
+ "constraints": {
+ "fields": [
+ {
+ "path": ["$.address.city"]
+ }
+ ]
+ }
+ }
+ """
+
+ let credentials = [
+ """
+ {
+ "type": ["Passport"],
+ "name": "John Doe",
+ "dob": "14-Mar-70",
+ "address": {
+ "city": "New York",
+ "state": "NY"
+ }
+ }
+ """,
+ "Invalid JSON String"
+ ]
+
+ do {
+ _ = try matchCredentials(inputDescriptorJson: inputDescriptorJson, credentials: credentials)
+ XCTFail("Expected function to throw an error for invalid JSON")
+ } catch {
+ // Expected an error, pass the test
+ }
}
}
diff --git a/go/go.mod b/go/go.mod
deleted file mode 100644
index 83c4c29..0000000
--- a/go/go.mod
+++ /dev/null
@@ -1,18 +0,0 @@
-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
deleted file mode 100644
index 76b20c0..0000000
--- a/go/go.sum
+++ /dev/null
@@ -1,29 +0,0 @@
-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
deleted file mode 100644
index dd1585b..0000000
--- a/go/main.go
+++ /dev/null
@@ -1,18 +0,0 @@
-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
deleted file mode 100644
index 0cdd503..0000000
--- a/go/pex/inputdescriptor.go
+++ /dev/null
@@ -1,17 +0,0 @@
-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
deleted file mode 100644
index 2184651..0000000
--- a/go/pex/matchedcredential.go
+++ /dev/null
@@ -1,17 +0,0 @@
-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
deleted file mode 100644
index f0cd4ad..0000000
--- a/go/pex/pexsdk.go
+++ /dev/null
@@ -1,117 +0,0 @@
-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
deleted file mode 100644
index 44903ae..0000000
--- a/go/pex/pexsdk_test.go
+++ /dev/null
@@ -1,65 +0,0 @@
-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
deleted file mode 100644
index a366aed..0000000
--- a/go/pexioswrapper/pexioswrapper.go
+++ /dev/null
@@ -1,32 +0,0 @@
-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)
-}