2021-08-24 15:27:45 -07:00
|
|
|
//
|
|
|
|
// MnemonicSeedPhraseHandling.swift
|
|
|
|
// wallet
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 2/28/20.
|
|
|
|
// Copyright © 2020 Francisco Gindre. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2021-09-14 04:15:29 -07:00
|
|
|
|
2021-08-24 15:27:45 -07:00
|
|
|
enum MnemonicError: Error {
|
|
|
|
case invalidSeed
|
|
|
|
case checksumFailed
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol MnemonicSeedPhraseHandling {
|
|
|
|
/**
|
2021-09-14 04:15:29 -07:00
|
|
|
Random 24 words mnemonic phrase
|
|
|
|
*/
|
2021-08-24 15:27:45 -07:00
|
|
|
func randomMnemonic() throws -> String
|
2021-09-14 04:15:29 -07:00
|
|
|
|
2021-08-24 15:27:45 -07:00
|
|
|
/**
|
2021-09-14 04:15:29 -07:00
|
|
|
Random 24 words mnemonic phrase as array of words
|
2021-08-24 15:27:45 -07:00
|
|
|
*/
|
|
|
|
func randomMnemonicWords() throws -> [String]
|
2021-09-14 04:15:29 -07:00
|
|
|
|
2021-08-24 15:27:45 -07:00
|
|
|
/**
|
2021-09-14 04:15:29 -07:00
|
|
|
Generate deterministic seed from mnemonic phrase
|
|
|
|
*/
|
2021-08-24 15:27:45 -07:00
|
|
|
func toSeed(mnemonic: String) throws -> [UInt8]
|
2021-09-14 04:15:29 -07:00
|
|
|
|
2021-08-24 15:27:45 -07:00
|
|
|
/**
|
2021-09-14 04:15:29 -07:00
|
|
|
Get this mnemonic
|
2021-08-24 15:27:45 -07:00
|
|
|
*/
|
|
|
|
func asWords(mnemonic: String) throws -> [String]
|
2021-09-14 04:15:29 -07:00
|
|
|
|
2021-08-24 15:27:45 -07:00
|
|
|
/**
|
2021-09-14 04:15:29 -07:00
|
|
|
Validates whether the given mnemonic is correct
|
|
|
|
*/
|
2021-08-24 15:27:45 -07:00
|
|
|
func isValid(mnemonic: String) throws
|
|
|
|
}
|