Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

feat/Logic to accept an Offer #127

Merged
merged 1 commit into from
May 17, 2024
Merged
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
39 changes: 39 additions & 0 deletions TikiClient/Classes/TikiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,44 @@ public class TikiClient {
public static func createOffer(_id: String?, ptr: String?, description: String?, terms: String?, reward: [Reward], use: Use, tags: [Tag], permissions: [Permission?]){
self.offer = Offer(_id: _id, ptr: ptr, description: description, terms: terms, reward: reward, use: use, tags: tags, permissions: permissions)
}
public static func acceptOffer(completion: @escaping (String?) -> Void, onError: @escaping (String) -> Void){
if(offer == nil){
onError("Offer is nil")
return
}
if(TikiClient.config == nil){
onError("Config is nil")
}
if(TikiClient.userId == nil){
onError("UserId is nil")
}
var tags: [String] = []
for tag in offer!.tags {
tags.append(tag.value)
}

guard let privateKey = KeyService.get(providerId: TikiClient.config!.providerId, userId: TikiClient.userId!, isPrivate: true) else {
onError("Private Key not found. Use the TikiClient.initialize method to register the user.")
return
}

guard let publicKeyB64 = KeyService.publicKeyB64(privateKey: privateKey) else{
onError("Error extracting public key")
return
}

guard let address = KeyService.address(b64PubKey: publicKeyB64) else{
onError("Error decoding address")
return
}


guard let signature = KeyService.sign(message: address, privateKey: privateKey) else{
onError("Error sign request")
return
}
let licenseRequest = LicenseRequest(ptr: offer!.ptr!, tags: tags, uses: [offer!.use], terms: offer!.terms!, description: offer!.description!, origin: Bundle.main.bundleIdentifier!, signature: signature)
TikiClient.license.create(token: TikiClient.config?.publicKey ?? "", postLicenseRequest: licenseRequest, completion: completion)
}

}
Loading