To run the example project, clone the repo, and run pod install
from the Example directory first.
KeepinCRUD is available through CocoaPods. To install it, simply add the following line to your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/METADIUM/Web3Swift-iOS'
target 'project' do
pod 'KeepinCRUD', :git => 'https://github.com/METADIUM/Keepin_iOS_SDK.git'
end
//delegate url, node url, resolver url, didPrefix를 직접 설정할 때 초기화 부분에 셋팅합니다.
/**
* 개발서버 delegateUrl: https://testdelegator.metadium.com, nodeUrl: https://api.metadium.com/dev, resolverUrl: https://testnetresolver.metadium.com/1.0/identifiers/, didPrefix: did:meta:testnet:
* 운영서버 delegateUrl: https://delegator.metadium.com, nodeUrl: https://api.metadium.com/prod, resolverUrl: https://resolver.metadium.com/1.0/identifiers/, didPrefix: did:meta:
*/
let delegator = MetaDelegator.init(delegatorUrl: "https://testdelegator.metadium.com",
nodeUrl: "https://api.metadium.com/dev",
resolverUrl: "https://testnetresolver.metadium.com/1.0/identifiers/",
didPrefix: "did:meta:testnet:",
api_key: "testKey")
let key = wallet.createKey()
//key.privateKey, key.publicKey, key.address
let delegator = MetaDelegator.init(delegatorUrl: "https://testdelegator.metadium.com",
nodeUrl: "https://api.metadium.com/dev",
resolverUrl: "https://testnetresolver.metadium.com/1.0/identifiers/",
didPrefix: "did:meta:testnet:",
api_key: "testKey")
let wallet = MetaWallet.init(delegator: delegator, privateKey: "0xb7fddf3e1645b2f2ef8e1f427ec2ae76cc6989fd33999f065bc48cb39d6c2336", did: "did:meta:testnet:0000000000000000000000000000000000000000000000000000000000002f4c")
let data = "test data".data(using: .utf8)
let (signature, r, s, v) = wallet.getSignature(data: data!)
let wallet = wallet.assignPrivateKey(privateKey: privateKey)
let (signatureData, r, s, v) = wallt.getWalletSignature()
let (signData, r, s, v) = wallet.getCreateKeySignature()
delegator.createIdentityDelegated(signData: signData!, r: r, s: s, v: v) { (type, txId, error) in
if error != nil {
return
}
DispatchQueue.global().asyncAfter(deadline: .now() + 0.3) {
self.wallet.transactionReceipt(type: type!, txId: txId!) { (error, receipt) in
if error != nil {
return
}
if receipt == nil {
self.wallet.transactionReceipt(type: type!, txId: txId!, complection: nil)
return
}
if receipt!.status == .success {
//Todo...
}
}
}
}
}
let serviceKey = wallet.createServiceKey()
let (signData, r, s, v) = self.wallet.getPublicKeySignature()
self.delegator.addPublicKeyDelegated(signData: signData!, r: r, s: s, v: v) { (type, txId, error) in
if error != nil {
return
}
DispatchQueue.global().asyncAfter(deadline: .now() + 0.3) {
self.wallet.transactionReceipt(type: type!, txId: txId!) { (error, receipt) in
if error != nil {
return
}
if receipt == nil {
self.wallet.transactionReceipt(type: type!, txId: txId!, complection: nil)
return
}
print("status: \(receipt!.status), hash : \(receipt!.transactionHash)")
if receipt!.status == .success {
//Todo...
}
}
}
}
}
let (addr, signData, servieId, r, s, v) = self.wallet.getSignServiceId(serviceID: "5933e64b-cb34-11ea-9e0f-020c6496fbdc", serviceAddress: address!)
self.delegator.addKeyDelegated(address: addr, signData: signData!, serviceId: servieId, r: r, s: s, v: v) { (type, txId, error) in
if error != nil {
return
}
DispatchQueue.global().asyncAfter(deadline: .now() + 0.3) {
self.wallet.transactionReceipt(type: type!, txId: txId!) { (error, receipt) in
if error != nil {
return
}
if receipt == nil {
self.wallet.transactionReceipt(type: type!, txId: txId!, complection: nil)
return
}
print("status: \(receipt!.status), hash : \(receipt!.transactionHash)")
if receipt!.status == .success {
//Todo...
}
else {
//Todo...
}
}
}
}
}
let (_, r, s, v) = self.wallet!.getRemoveKeySign()
self.delegator?.removeKeyDelegated(r: r, s: s, v: v, complection: { (type, txId, error) in
if error != nil {
return
}
DispatchQueue.global().asyncAfter(deadline: .now() + 0.3) {
self.wallet?.transactionReceipt(type: type!, txId: txId!, complection: { (error, receipt) in
if receipt!.status == .success {
//Todo..
}
})
}
})
let (_, r, s, v) = self.wallet!.getRemovePublicKeySign()
self.delegator?.removePublicKeyDelegated(r: r, s: s, v: v, complection: { (type, txId, error) in
if error != nil {
return
}
DispatchQueue.global().asyncAfter(deadline: .now() + 0.3) {
self.wallet?.transactionReceipt(type: type!, txId: txId!, complection: { (error, receipt) in
if receipt!.status == .success {
//Todo...
}
})
}
})
let (_, r, s, v) = self.wallet!.getRemoveAssociatedAddressSign()
self.delegator?.removeAssociatedAddressDelegated(r: r, s: s, v: v, complection: { (type, txId, error) in
if error != nil {
return
}
DispatchQueue.global().asyncAfter(deadline: .now() + 0.3) {
self.wallet?.transactionReceipt(type: type!, txId: txId!, complection: { (error, receipt) in
if receipt!.status == .success {
//Todo...
}
})
}
})
let did = self.wallet?.getDid()
self.wallet?.reqDiDDocument(did: did!, complection: { (document, error) in
if error != nil {
return
}
let didDocument = document
})
let issuanceDate = Date()
let expirationDate = Date()
let nonce = Data.randomBytes(length: 32)?.base64EncodedString()
let vc = try? self.wallet?.issueCredential(types: ["NameCredential"],
id: "http://aa.metadium.com/credential/name/343",
nonce: nonce,
issuanceDate: issuanceDate,
expirationDate: expirationDate,
ownerDid: "did:meta:00000...00003159",
subjects: ["name": "Keepin"]) as! JWSObject
let serializedVC = try? vc?.serialize()
let issuanceDate = Date()
let expirationDate = Date()
let nonce = Data.randomBytes(length: 32)?.base64EncodedString()
let vp = try? self.wallet?.issuePresentation(types: ["TestPresentation"],
id: "http://aa.metadium.com/presentation/343",
nonce: nonce,
issuanceDate: issuanceDate,
expirationDate: expirationDate,
vcList: [serializedVC]) as! JWSObject
let serializedVP = try? vp?.serialize()
let jws = try? JWSObject.init(string: serializedVC)
let jwt = try? JWT.init(jsonData: jws!.payload)
let expireDate = jwt!.expirationTime
let isVerify = try? self.wallet?.verify(jwt: jws!)
if isVerify == false {
//검증실패
}
else if (expireDate != nil && expireDate! > Date()) {
// 유효기간 초과
}
jinsikhan, [email protected]
KeepinCRUD is available under the MIT license. See the LICENSE file for more info.