Skip to content

Commit

Permalink
No longer uses deprecated data from mint auth response
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-on-git committed Jan 18, 2023
1 parent 209f211 commit 21db32c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
6 changes: 3 additions & 3 deletions KycDao.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'KycDao'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'iOS SDK for kycDAO'

# This description is used to generate tags and improve search results.
Expand All @@ -23,12 +23,12 @@ kycDAO is the first interoperable web3 native compliance framework.
kycDAO links existing CeFi accounts to self hosted wallets with a soulbound kycNFT. dApps, smart-contracts, and web3 services use these compliant proofs to create trusted ecosystems.
DESC

s.homepage = 'https://github.com/kycdao/kycdao-ios-sdk'
s.homepage = 'https://kycdao.xyz/'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
# s.license = { :type => 'UNLICENSED' }
s.author = { 'kycDAO' => '[email protected]' }
s.source = { :git => 'https://github.com/kycdao/kycdao-ios-sdk.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.social_media_url = 'https://twitter.com/kycdao'

s.ios.deployment_target = '13.0'

Expand Down
17 changes: 6 additions & 11 deletions Sources/kycDAO-SDK/Core/VerificationSession+Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,16 @@ extension VerificationSession {
return try await ethereumClient.eth_getTransactionReceipt(txHash: txHash)
}

func getRawRequiredMintCostForCode(authCode: String) async throws -> BigUInt {

guard let authCodeNumber = UInt32(authCode)
else {
throw KycDaoError.internal(.unknown)
}
func getRawRequiredMintCostForCode(authCode: UInt32) async throws -> BigUInt {

let ethWalletAddress = EthereumAddress(walletAddress)
let mintCost = try await kycContract.getRequiredMintCostForCode(authorizationCode: authCodeNumber,
let mintCost = try await kycContract.getRequiredMintCostForCode(authorizationCode: authCode,
destination: ethWalletAddress)

return mintCost
}

func getRequiredMintCostForCode(authCode: String) async throws -> BigUInt {
func getRequiredMintCostForCode(authCode: UInt32) async throws -> BigUInt {
let mintingCost = try await getRawRequiredMintCostForCode(authCode: authCode)

//Adding 10% slippage (no floating point operation for multiplying BigUInt with 1.1)
Expand Down Expand Up @@ -131,10 +126,10 @@ extension VerificationSession {
return estimation
}

func tokenMinted(authCode: String, tokenId: String, txHash: String) async throws -> TokenDetailsDTO {
func tokenMinted(authCode: UInt32, tokenId: BigUInt, txHash: String) async throws -> TokenDetailsDTO {

let mintResultInput = MintResultUploadDTO(authCode: authCode,
tokenId: tokenId,
let mintResultInput = MintResultUploadDTO(authCode: "\(authCode)",
tokenId: "\(tokenId)",
txHash: txHash)

let result = try await ApiConnection.call(endPoint: .token,
Expand Down
23 changes: 13 additions & 10 deletions Sources/kycDAO-SDK/Core/VerificationSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class VerificationSession: Identifiable {

//Internal state
internal var personaSessionData: PersonaSessionData?
private var authCode: String?
private var authCode: UInt32?

//Derived internal data
private var loginProof: String { "kycDAO-login-\(sessionData.nonce)" }
Expand Down Expand Up @@ -401,11 +401,14 @@ public class VerificationSession: Identifiable {
output: MintAuthorizationDTO.self)
let mintAuth = result.data

guard let code = mintAuth.code, let txHash = mintAuth.tx_hash else {
guard let txHash = mintAuth.token?.authorization_tx_id,
let code = mintAuth.token?.authorization_code,
let authCodeNumber = UInt32(code)
else {
throw KycDaoError.internal(.unknown)
}

authCode = code
authCode = authCodeNumber

try await resumeWhenTransactionFinished(txHash: txHash)

Expand All @@ -424,12 +427,11 @@ public class VerificationSession: Identifiable {
try precondition(requiredInformationProvided, throws: KycDaoError.requiredInformationNotProvided)
try precondition(verificationStatus == .verified, throws: KycDaoError.identityNotVerified)

guard let authCode = authCode,
let authCodeNum = UInt32(authCode)
guard let authCode = authCode
else { throw KycDaoError.unauthorizedMinting }

let requiredMintCost = try await getRequiredMintCostForCode(authCode: authCode)
let mintingTransaction = try kycContract.mintWithCode(authorizationCode: authCodeNum,
let mintingTransaction = try kycContract.mintWithCode(authorizationCode: authCode,
walletAddress: EthereumAddress(walletAddress),
cost: requiredMintCost)
let props = try await transactionProperties(forTransaction: mintingTransaction)
Expand All @@ -439,7 +441,9 @@ public class VerificationSession: Identifiable {
guard let event = receipt.lookForEvent(event: ERC721Events.Transfer.self)
else { throw KycDaoError.internal(.unknown) }

let tokenDetails = try await tokenMinted(authCode: authCode, tokenId: "\(event.tokenId)", txHash: txRes.txHash)
let tokenDetails = try await tokenMinted(authCode: authCode,
tokenId: event.tokenId,
txHash: txRes.txHash)

self.authCode = nil

Expand Down Expand Up @@ -468,12 +472,11 @@ public class VerificationSession: Identifiable {
try precondition(requiredInformationProvided, throws: KycDaoError.requiredInformationNotProvided)
try precondition(verificationStatus == .verified, throws: KycDaoError.identityNotVerified)

guard let authCode = authCode,
let authCodeNum = UInt32(authCode)
guard let authCode = authCode
else { throw KycDaoError.unauthorizedMinting }

let requiredMintCost = try await getRequiredMintCostForCode(authCode: authCode)
let mintingTransaction = try kycContract.mintWithCode(authorizationCode: authCodeNum,
let mintingTransaction = try kycContract.mintWithCode(authorizationCode: authCode,
walletAddress: EthereumAddress(walletAddress),
cost: requiredMintCost)
let gasEstimation = try await estimateGas(forTransaction: mintingTransaction)
Expand Down
5 changes: 3 additions & 2 deletions Sources/kycDAO-SDK/Models/ResponseBodies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import Foundation

struct MintAuthorizationDTO: Decodable {
let code: String?
let tx_hash: String?
let token: TokenDetailsDTO?
}

struct TokenDetailsDTO: Decodable {
let image_url: String?
let authorization_code: String?
let authorization_tx_id: String?
}

struct TokenImageDTO: Decodable {
Expand Down

0 comments on commit 21db32c

Please sign in to comment.