Installation
Our Magic subsystem needs to be installed in the AppDelegate.swift.
let config = CustomNodeConfiguration(rpcUrl: "https://rpc.ankr.com/polygon_mumbai", chainId: 80001)
Magic.shared = Magic(apiKey: "pk_live_A2A4XXXXXX029", customNode: config);Library Import
In any files where you plan to use the Passport libraries, you will need to import some core libraries in addition to 'credenzapassport'. These will all be installed as part of the 'credenzapassport' pod.
import NFCReaderWriter
import MagicSDK
import MagicSDK_Web3
import FoundationUsing the Library
Once that is done, there are a set of primary functions that are available to authorize a login using the Magic Link subsystem. This functionality will all be available through an instance of the PassportUtility object, which can be instantiated like this:
pUtility=PassportUtility(delegate: self)The delegate parameter must point to an object that implements the following methods:
pUtility=PassportUtility(delegate: self)The delegate parameter must point to an object that implements the following methods:
public protocol PassportDelegate {
func loginComplete(address: String)
func nfcScanComplete(address: String)
}These are the two primary delegates required of Passport: capturing the blockchain authentication and capturing an NFC scan that is associated with a Passport account. If you do not plan to use NFC, then you can simply implement and empty function.
Once the object is implemented, you must initialize the object with some primary contracts that will be used as the default contracts for lookups. Credenza will provide the addresses for your organization. The definition of the call is below.
public func initializeCredentials(authenticationToken: String, nftContractAddress: String, storedValueContractAddress: String, connectedContractAddress: String) Initializes the credentials needed for API calls and smart contract interaction.
Parameters
authenticationToken: The authentication token to be used for API calls.
nftContractAddress: The address of the NFT smart contract.
storedValueContractAddress: The address of the stored value smart contract.
connectedContractAddress: The address of the connected smart contract.
Once you have instantiated the PassportUtility object and initialized, you are ready to enable user login and access contracts.