mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
4.2 KiB
Swift
115 lines
4.2 KiB
Swift
2 years ago
|
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
import SessionUtil
|
||
|
import SessionUtilitiesKit
|
||
|
|
||
2 years ago
|
public extension Crypto.Generator {
|
||
|
static func tokenSubaccount(
|
||
10 months ago
|
config: LibSession.Config?,
|
||
2 years ago
|
groupSessionId: SessionId,
|
||
|
memberId: String
|
||
2 years ago
|
) -> Crypto.Generator<[UInt8]> {
|
||
|
return Crypto.Generator(
|
||
|
id: "tokenSubaccount",
|
||
2 years ago
|
args: [config, groupSessionId, memberId]
|
||
|
) {
|
||
10 months ago
|
guard case .groupKeys(let conf, _, _) = config else { throw LibSessionError.invalidConfigObject }
|
||
2 years ago
|
|
||
10 months ago
|
var cMemberId: [CChar] = try memberId.cString(using: .utf8) ?? { throw LibSessionError.invalidCConversion }()
|
||
|
var tokenData: [UInt8] = [UInt8](repeating: 0, count: LibSession.sizeSubaccountBytes)
|
||
2 years ago
|
|
||
|
guard groups_keys_swarm_subaccount_token(
|
||
|
conf,
|
||
|
&cMemberId,
|
||
|
&tokenData
|
||
10 months ago
|
) else { throw LibSessionError.failedToMakeSubAccountInGroup }
|
||
2 years ago
|
|
||
|
return tokenData
|
||
|
}
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
static func memberAuthData(
|
||
10 months ago
|
config: LibSession.Config?,
|
||
2 years ago
|
groupSessionId: SessionId,
|
||
|
memberId: String
|
||
2 years ago
|
) -> Crypto.Generator<Authentication.Info> {
|
||
|
return Crypto.Generator(
|
||
2 years ago
|
id: "memberAuthData",
|
||
|
args: [config, groupSessionId, memberId]
|
||
|
) {
|
||
10 months ago
|
guard case .groupKeys(let conf, _, _) = config else { throw LibSessionError.invalidConfigObject }
|
||
2 years ago
|
|
||
10 months ago
|
var cMemberId: [CChar] = try memberId.cString(using: .utf8) ?? { throw LibSessionError.invalidCConversion }()
|
||
|
var authData: [UInt8] = [UInt8](repeating: 0, count: LibSession.sizeAuthDataBytes)
|
||
2 years ago
|
|
||
|
guard groups_keys_swarm_make_subaccount(
|
||
|
conf,
|
||
|
&cMemberId,
|
||
|
&authData
|
||
10 months ago
|
) else { throw LibSessionError.failedToMakeSubAccountInGroup }
|
||
2 years ago
|
|
||
|
return .groupMember(groupSessionId: groupSessionId, authData: Data(authData))
|
||
|
}
|
||
|
}
|
||
2 years ago
|
|
||
|
static func signatureSubaccount(
|
||
10 months ago
|
config: LibSession.Config?,
|
||
2 years ago
|
verificationBytes: [UInt8],
|
||
|
memberAuthData: Data
|
||
2 years ago
|
) -> Crypto.Generator<Authentication.Signature> {
|
||
|
return Crypto.Generator(
|
||
|
id: "signatureSubaccount",
|
||
2 years ago
|
args: [config, verificationBytes, memberAuthData]
|
||
|
) {
|
||
10 months ago
|
guard case .groupKeys(let conf, _, _) = config else { throw LibSessionError.invalidConfigObject }
|
||
2 years ago
|
|
||
|
var verificationBytes: [UInt8] = verificationBytes
|
||
|
var memberAuthData: [UInt8] = Array(memberAuthData)
|
||
10 months ago
|
var subaccount: [UInt8] = [UInt8](repeating: 0, count: LibSession.sizeSubaccountBytes)
|
||
|
var subaccountSig: [UInt8] = [UInt8](repeating: 0, count: LibSession.sizeSubaccountSigBytes)
|
||
|
var signature: [UInt8] = [UInt8](repeating: 0, count: LibSession.sizeSubaccountSignatureBytes)
|
||
2 years ago
|
|
||
|
guard groups_keys_swarm_subaccount_sign_binary(
|
||
|
conf,
|
||
|
&verificationBytes,
|
||
|
verificationBytes.count,
|
||
|
&memberAuthData,
|
||
|
&subaccount,
|
||
|
&subaccountSig,
|
||
|
&signature
|
||
|
) else { throw MessageSenderError.signingFailed }
|
||
|
|
||
|
return Authentication.Signature.subaccount(
|
||
|
subaccount: subaccount,
|
||
|
subaccountSig: subaccountSig,
|
||
|
signature: signature
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
1 year ago
|
|
||
|
public extension Crypto.Verification {
|
||
|
static func memberAuthData(
|
||
|
groupSessionId: SessionId,
|
||
|
ed25519SecretKey: [UInt8],
|
||
|
memberAuthData: Data
|
||
|
) -> Crypto.Verification {
|
||
|
return Crypto.Verification(
|
||
|
id: "memberAuthData",
|
||
|
args: [groupSessionId, ed25519SecretKey, memberAuthData]
|
||
|
) {
|
||
10 months ago
|
guard var cGroupId: [CChar] = groupSessionId.hexString.cString(using: .utf8) else { return false }
|
||
|
|
||
1 year ago
|
var cEd25519SecretKey: [UInt8] = ed25519SecretKey
|
||
|
var cAuthData: [UInt8] = Array(memberAuthData)
|
||
|
|
||
|
return groups_keys_swarm_verify_subaccount(
|
||
|
&cGroupId,
|
||
|
&cEd25519SecretKey,
|
||
|
&cAuthData
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|