Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ import AppStoreServerLibrary

let bundleId = "com.example"
let appleRootCAs = loadRootCAs() // Specific implementation may vary
let appAppleId: Int64? = nil // appAppleId must be provided for the Production environment
let enableOnlineChecks = true
let environment = Environment.sandbox

// try! used for example purposes only
let verifier = try! SignedDataVerifier(rootCertificates: appleRootCAs, bundleId: bundleId, appAppleId: nil, environment: environment, enableOnlineChecks: enableOnlineChecks)
let verifier = try! SignedDataVerifier(rootCertificates: appleRootCAs, bundleId: bundleId, appAppleId: appAppleId, environment: environment, enableOnlineChecks: enableOnlineChecks)

let notificationPayload = "ey..."
let notificationResult = await verifier.verifyAndDecodeNotification(signedPayload: notificationPayload)
Expand Down
11 changes: 10 additions & 1 deletion Sources/AppStoreServerLibrary/SignedDataVerifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import Foundation

///A verifier and decoder class designed to decode signed data from the App Store.
public struct SignedDataVerifier {


public enum ConfigurationError: Error {
case INVALID_APP_APPLE_ID
}

private var bundleId: String
private var appAppleId: Int64?
private var environment: Environment
Expand All @@ -18,6 +22,11 @@ public struct SignedDataVerifier {
/// - Parameter enableOnlineChecks: Whether to enable revocation checking and check expiration using the current date
/// - Throws: When the root certificates are malformed
public init(rootCertificates: [Foundation.Data], bundleId: String, appAppleId: Int64?, environment: Environment, enableOnlineChecks: Bool) throws {

guard !(environment == .production && appAppleId == nil) else {
throw ConfigurationError.INVALID_APP_APPLE_ID
}

self.bundleId = bundleId
self.appAppleId = appAppleId
self.environment = environment
Expand Down