SPB Git

spb/os-vault Public

Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.

Swift 96% Shell 3.4% Makefile 0.6%
4.5 KB · 126 lines swift
Raw Blame History
1import WalletCoreC2import Foundation3// SPDX-License-Identifier: Apache-2.04//5// Copyright © 2017 Trust Wallet.6//7// This is a GENERATED FILE, changes made here WILL BE LOST.8//910import Foundation111213public final class Barz {1415    /// Calculate a counterfactual address for the smart contract wallet16    /// 17    /// - Parameter input: The serialized data of ContractAddressInput.18    /// - Returns: The address.19    public static func getCounterfactualAddress(input: Data) -> String? {20        let inputData = TWDataCreateWithNSData(input)21        defer {22            TWDataDelete(inputData)23        }24        guard let result = TWBarzGetCounterfactualAddress(inputData) else {25            return nil26        }27        return TWStringNSString(result)28    }2930    /// Returns the init code parameter of ERC-4337 User Operation31    /// 32    /// - Parameter factory: The address of the factory contract33    /// - Parameter public_key: Public key for the verification facet34    /// - Parameter verification_facet: The address of the verification facet35    /// - Parameter salt: The salt of the init code; Must be non-negative36    /// - Returns: The init code.37    public static func getInitCode(factory: String, publicKey: PublicKey, verificationFacet: String, salt: Int32) -> Data? {38        let factoryString = TWStringCreateWithNSString(factory)39        defer {40            TWStringDelete(factoryString)41        }42        let verificationFacetString = TWStringCreateWithNSString(verificationFacet)43        defer {44            TWStringDelete(verificationFacetString)45        }46        guard let result = TWBarzGetInitCode(factoryString, publicKey.rawValue, verificationFacetString, salt) else {47            return nil48        }49        return TWDataNSData(result)50    }5152    /// Converts the original ASN-encoded signature from webauthn to the format accepted by Barz53    /// 54    /// - Parameter signature: Original signature55    /// - Parameter challenge: The original challenge that was signed56    /// - Parameter authenticator_data: Returned from Webauthn API57    /// - Parameter client_data_json: Returned from Webauthn API58    /// - Returns: Bytes of the formatted signature59    public static func getFormattedSignature(signature: Data, challenge: Data, authenticatorData: Data, clientDataJson: String) -> Data? {60        let signatureData = TWDataCreateWithNSData(signature)61        defer {62            TWDataDelete(signatureData)63        }64        let challengeData = TWDataCreateWithNSData(challenge)65        defer {66            TWDataDelete(challengeData)67        }68        let authenticatorDataData = TWDataCreateWithNSData(authenticatorData)69        defer {70            TWDataDelete(authenticatorDataData)71        }72        let clientDataJsonString = TWStringCreateWithNSString(clientDataJson)73        defer {74            TWStringDelete(clientDataJsonString)75        }76        guard let result = TWBarzGetFormattedSignature(signatureData, challengeData, authenticatorDataData, clientDataJsonString) else {77            return nil78        }79        return TWDataNSData(result)80    }8182    /// Returns the final hash to be signed by Barz for signing messages & typed data83    /// 84    /// - Parameter msg_hash: Original msgHash85    /// - Parameter barzAddress: The address of Barz wallet signing the message86    /// - Parameter chainId: The chainId of the network the verification will happen; Must be non-negative87    /// - Returns: The final hash to be signed.88    public static func getPrefixedMsgHash(msgHash: Data, barzAddress: String, chainId: Int32) -> Data? {89        let msgHashData = TWDataCreateWithNSData(msgHash)90        defer {91            TWDataDelete(msgHashData)92        }93        let barzAddressString = TWStringCreateWithNSString(barzAddress)94        defer {95            TWStringDelete(barzAddressString)96        }97        guard let result = TWBarzGetPrefixedMsgHash(msgHashData, barzAddressString, chainId) else {98            return nil99        }100        return TWDataNSData(result)101    }102103    /// Returns the encoded diamondCut function call for Barz contract upgrades104    /// 105    /// - Parameter input: The serialized data of DiamondCutInput.106    /// - Returns: The diamond cut code.107    public static func getDiamondCutCode(input: Data) -> Data? {108        let inputData = TWDataCreateWithNSData(input)109        defer {110            TWDataDelete(inputData)111        }112        guard let result = TWBarzGetDiamondCutCode(inputData) else {113            return nil114        }115        return TWDataNSData(result)116    }117118    let rawValue: OpaquePointer119120    init(rawValue: OpaquePointer) {121        self.rawValue = rawValue122    }123124125}126