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%
3.0 KB · 94 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 Foundation1112/// Represents a BIP 0173 address.13public final class SegwitAddress: Address {1415    /// Compares two addresses for equality.16    ///17    /// - Parameter lhs: left non-null pointer to a Bech32 Address18    /// - Parameter rhs: right non-null pointer to a Bech32 Address19    /// - Returns: true if both address are equal, false otherwise20    public static func == (lhs: SegwitAddress, rhs: SegwitAddress) -> Bool {21        return TWSegwitAddressEqual(lhs.rawValue, rhs.rawValue)22    }2324    /// Determines if the string is a valid Bech32 address.25    ///26    /// - Parameter string: Non-null pointer to a Bech32 address as a string27    /// - Returns: true if the string is a valid Bech32 address, false otherwise.28    public static func isValidString(string: String) -> Bool {29        let stringString = TWStringCreateWithNSString(string)30        defer {31            TWStringDelete(stringString)32        }33        return TWSegwitAddressIsValidString(stringString)34    }3536    /// Returns the address string representation.37    ///38    /// - Parameter address: Non-null pointer to a Segwit Address39    /// - Returns: Non-null pointer to the segwit address string representation40    public var description: String {41        return TWStringNSString(TWSegwitAddressDescription(rawValue))42    }4344    /// Returns the human-readable part.45    ///46    /// - Parameter address: Non-null pointer to a Segwit Address47    /// - Returns: the HRP part of the given address48    public var hrp: HRP {49        return HRP(rawValue: TWSegwitAddressHRP(rawValue).rawValue)!50    }5152    /// Returns the human-readable part.53    ///54    /// - Parameter address: Non-null pointer to a Segwit Address55    /// - Returns: returns the witness version of the given segwit address56    public var witnessVersion: Int32 {57        return TWSegwitAddressWitnessVersion(rawValue)58    }5960    /// Returns the witness program61    ///62    /// - Parameter address: Non-null pointer to a Segwit Address63    /// - Returns: returns the witness data of the given segwit address as a non-null pointer block of data64    public var witnessProgram: Data {65        return TWDataNSData(TWSegwitAddressWitnessProgram(rawValue))66    }6768    let rawValue: OpaquePointer6970    init(rawValue: OpaquePointer) {71        self.rawValue = rawValue72    }7374    public init?(string: String) {75        let stringString = TWStringCreateWithNSString(string)76        defer {77            TWStringDelete(stringString)78        }79        guard let rawValue = TWSegwitAddressCreateWithString(stringString) else {80            return nil81        }82        self.rawValue = rawValue83    }8485    public init(hrp: HRP, publicKey: PublicKey) {86        rawValue = TWSegwitAddressCreateWithPublicKey(TWHRP(rawValue: hrp.rawValue), publicKey.rawValue)87    }8889    deinit {90        TWSegwitAddressDelete(rawValue)91    }9293}94