Skip to content

Commit

Permalink
feat(sample): add demo apps for SDK
Browse files Browse the repository at this point in the history
fixed a bug with base64URL decoding
fixed pluto tests
  • Loading branch information
goncalo-frade-iohk committed Dec 1, 2022
1 parent 67584a6 commit 620c82a
Show file tree
Hide file tree
Showing 54 changed files with 2,119 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
lint:
name: build
runs-on: macos-latest
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -26,5 +30,8 @@ jobs:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: github.com

- name: Adding Known Hosts
run: ssh-keyscan -H github.com >> ~/.ssh/known_hosts

- name: Build
run: xcodebuild build test -scheme "AtalaPRISMSDK-Package" -destination "platform=iOS Simulator,name=IPhone 14"
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ Podfile.lock
*.mode1v3
*.mode2v3
xcuserdata
*.xcworkspace
*.xcodeproj
*.xcodeproj/project.xcworkspace/xcshareddata/
*.xcworkspace/xcshareddata/
*.xcworkspace/xcshareddata/xcschemes
*.orig
.swiftpm
/.project
*.gcno
*.gcda
Expand Down
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ excluded:
- Pluto/Tests
- Pollux/Tests
- PrismAgent/Tests
- Sample
line_length:
ignores_comments: true
ignores_urls: true
Expand Down
12 changes: 0 additions & 12 deletions Castor/Sources/Helpers/Base64+DIDMethodID.swift

This file was deleted.

3 changes: 2 additions & 1 deletion Castor/Sources/Operations/CreatePrismDIDOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ struct CreatePrismDIDOperation {
) throws -> DID {
let encodedState = try atalaOperation.serializedData()
let stateHash = encodedState.sha256()
let base64State = encodedState.base64UrlEncodedString()
let methodSpecificId = try PrismDIDMethodId(
sections: [
stateHash,
Base64Utils().encodeMethodID(data: encodedState)
base64State
]
)
return DID(method: method, methodId: methodSpecificId.description)
Expand Down
5 changes: 3 additions & 2 deletions Castor/Sources/Resolvers/LongFormPrismDIDResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct LongFormPrismDIDResolver: DIDResolverDomain {
func resolve(did: DID) throws -> DIDDocument {
let prismDID = try LongFormPrismDID(did: did)
guard
let data = Base64Utils().decodeMethodID(str: prismDID.encodedState)
let data = Data(fromBase64URL: prismDID.encodedState)
else { throw CastorError.initialStateOfDIDChanged }

let (verificationMethods, services) = try decodeState(
Expand Down Expand Up @@ -42,7 +42,8 @@ struct LongFormPrismDIDResolver: DIDResolverDomain {
stateHash: String,
encodedData: Data
) throws -> ([String: DIDDocument.VerificationMethod], [DIDDocument.Service]) {
guard stateHash == encodedData.sha256() else { throw CastorError.initialStateOfDIDChanged }
let verifyEncodedState = encodedData.sha256()
guard stateHash == verifyEncodedState else { throw CastorError.initialStateOfDIDChanged }
let operation = try Io_Iohk_Atala_Prism_Protos_AtalaOperation(serializedData: encodedData)
let publicKeys = try operation.createDid.didData.publicKeys.map {
try PrismDIDPublicKey(apollo: apollo, proto: $0)
Expand Down
15 changes: 10 additions & 5 deletions Core/Sources/Helpers/Base64Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ public struct Base64Utils {
public init() {}

public func encode(_ data: Data) -> String {
String(data.base64EncodedString()
let base64 = data.base64EncodedString()
return String(base64
.replacingOccurrences(of: "/", with: "_")
.replacingOccurrences(of: "+", with: "-")
.trimingTrailing(while: CharacterSet(charactersIn: "=")))
}

public func decode(_ src: String) -> Data? {
let expectedLength = (src.count + 3) / 4 * 4
let base64Encoded = src
let expectedLength = src.count % 4
let replaced = src
.replacingOccurrences(of: "_", with: "/")
.replacingOccurrences(of: "-", with: "+")
.appending(String(repeating: .init("="), count: expectedLength))
return Data(base64Encoded: base64Encoded)

if expectedLength > 0 {
return Data(base64Encoded: replaced + String(repeating: "=", count: 4 - expectedLength))
} else {
return Data(base64Encoded:replaced)
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions Core/Sources/Helpers/Date+Miliseconds.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation

extension Date {
public var millisecondsSince1970: UInt64 {
UInt64((self.timeIntervalSince1970 * 1000.0).rounded())
public extension Date {
var millisecondsSince1970: UInt64 {
UInt64((self.timeIntervalSince1970 * 1_000.0).rounded())
}

public init(milliseconds: UInt64) {
self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)
init(milliseconds: UInt64) {
self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1_000)
}
}
4 changes: 2 additions & 2 deletions Core/Sources/Helpers/Future+AsynAwait.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Combine

extension Future where Failure == Error {
public convenience init(operation: @escaping () async throws -> Output) {
public extension Future where Failure == Error {
convenience init(operation: @escaping () async throws -> Output) {
self.init { promise in
Task {
do {
Expand Down
2 changes: 1 addition & 1 deletion Core/Sources/Helpers/Map+AsyncAwait.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public extension Sequence {
public func asyncMap<T>(
func asyncMap<T>(
_ transform: (Element) async throws -> T
) async rethrows -> [T] {
var values = [T]()
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let package = Package(
from: "1.4.4"
),
// This doesnt seem to be working properly on command line, removing for now
// .package(url: "https://github.com/realm/SwiftLint.git", branch: "main"),
// .package(url: "https://github.com/realm/SwiftLint.git", branch: "main"),
.package(url: "https://github.com/apple/swift-protobuf", from: "1.7.0"),
.package(url: "https://github.com/antlr/antlr4", branch: "master"),
.package(url: "https://github.com/input-output-hk/atala-prism-didcomm-swift", from: "0.3.4"),
Expand Down
2 changes: 1 addition & 1 deletion Pluto/Tests/CDDIDPairDAOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class CDDIDPairDAOTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
coreDataManager = CoreDataManager(setup: .init(
modelPath: .storeName("PrismPluto", ModelKit.bundle),
modelPath: .storeName("PrismPluto"),
storeType: .memory
))
privateKeyDao = CDDIDPrivateKeyDAO(
Expand Down
2 changes: 1 addition & 1 deletion Pluto/Tests/CDDIDPrivateKeyDAOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class CDDIDPrivateKeyDAOTestsTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
coreDataManager = CoreDataManager(setup: .init(
modelPath: .storeName("PrismPluto", ModelKit.bundle),
modelPath: .storeName("PrismPluto"),
storeType: .memory
))
}
Expand Down
2 changes: 1 addition & 1 deletion Pluto/Tests/CDMessagesDAOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class CDMessagesDAOTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
coreDataManager = CoreDataManager(setup: .init(
modelPath: .storeName("PrismPluto", ModelKit.bundle),
modelPath: .storeName("PrismPluto"),
storeType: .memory
))
privateDAO = CDDIDPrivateKeyDAO(
Expand Down
2 changes: 1 addition & 1 deletion Pluto/Tests/CDRegisteredDIDDaoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class CDRegisteredDIDDaoTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
coreDataManager = CoreDataManager(setup: .init(
modelPath: .storeName("PrismPluto", ModelKit.bundle),
modelPath: .storeName("PrismPluto"),
storeType: .memory
))
}
Expand Down
3 changes: 0 additions & 3 deletions PrismAgent/Sources/Error.swift

This file was deleted.

Loading

0 comments on commit 620c82a

Please sign in to comment.