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%
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/// `crypto_box` encryption algorithms.13public struct CryptoBox {1415 /// Encrypts message using `my_secret` and `other_pubkey`.16 /// The output will have a randomly generated nonce prepended to it.17 /// The output will be Overhead + 24 bytes longer than the original.18 ///19 /// - Parameter mySecret: *non-null* pointer to my secret key.20 /// - Parameter otherPubkey: *non-null* pointer to other's public key.21 /// - Parameter message: *non-null* pointer to the message to be encrypted.22 /// - Returns: *nullable* pointer to the encrypted message with randomly generated nonce prepended to it.23 public static func encryptEasy(mySecret: CryptoBoxSecretKey, otherPubkey: CryptoBoxPublicKey, message: Data) -> Data {24 let messageData = TWDataCreateWithNSData(message)25 defer {26 TWDataDelete(messageData)27 }28 return TWDataNSData(TWCryptoBoxEncryptEasy(mySecret.rawValue, otherPubkey.rawValue, messageData))29 }3031 /// Decrypts box produced by `TWCryptoBoxEncryptEasy`.32 /// We assume a 24-byte nonce is prepended to the encrypted text in box.33 ///34 /// - Parameter mySecret: *non-null* pointer to my secret key.35 /// - Parameter otherPubkey: *non-null* pointer to other's public key.36 /// - Parameter encrypted: *non-null* pointer to the encrypted message with nonce prepended to it.37 /// - Returns: *nullable* pointer to the decrypted message.38 public static func decryptEasy(mySecret: CryptoBoxSecretKey, otherPubkey: CryptoBoxPublicKey, encrypted: Data) -> Data? {39 let encryptedData = TWDataCreateWithNSData(encrypted)40 defer {41 TWDataDelete(encryptedData)42 }43 guard let result = TWCryptoBoxDecryptEasy(mySecret.rawValue, otherPubkey.rawValue, encryptedData) else {44 return nil45 }46 return TWDataNSData(result)47 }484950 init() {51 }525354}55