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%
959 B · 31 lines swift
Raw Blame History
1import Foundation23public protocol BufferLayout: Codable, BorshCodable, Equatable {}45public extension BufferLayout {6    init(from decoder: Decoder) throws {7        let container = try decoder.singleValueContainer()89//        // decode parsedJSON10//        if let parsedData = try? container.decode(Self.self) {11//            self = parsedData12//            return13//        }1415        // Unable to get parsed data, fallback to decoding base6416        let stringData = (try? container.decode([String].self).first) ?? (try? container.decode(String.self))17        guard let string = stringData else {18            throw BinaryReaderError.dataMismatch19        }2021        if string.isEmpty, !(Self.self == EmptyInfo.self) {22            throw BinaryReaderError.dataMismatch23        }2425        let data = Data(base64Encoded: string) ?? Data(Base58.decode(string))2627        var reader = BinaryReader(bytes: data.bytes)28        try self.init(from: &reader)29    }30}31