From 3be23ad7f90d5806be461106a84d5e6127298397 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Tue, 8 Nov 2022 13:53:49 -0500 Subject: [PATCH] Update API docs to version 0.11.0 --- api-docs/build.gradle.kts | 4 +-- .../src/main/kotlin/org/bitcoindevkit/bdk.kt | 34 +++++++++++++------ .../test/kotlin/org/bitcoindevkit/Samples.kt | 17 +++++++--- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/api-docs/build.gradle.kts b/api-docs/build.gradle.kts index 46a1921..bbd6ed7 100644 --- a/api-docs/build.gradle.kts +++ b/api-docs/build.gradle.kts @@ -27,7 +27,7 @@ tasks.withType().configureEach { dokkaSourceSets { named("main") { moduleName.set("bdk-android") - moduleVersion.set("0.10.0") + moduleVersion.set("0.11.0") includes.from("Module1.md") samples.from("src/test/kotlin/org/bitcoindevkit/Samples.kt") } @@ -38,7 +38,7 @@ tasks.withType().configureEach { // dokkaSourceSets { // named("main") { // moduleName.set("bdk-jvm") -// moduleVersion.set("0.10.0") +// moduleVersion.set("0.11.0") // includes.from("Module2.md") // samples.from("src/test/kotlin/org/bitcoindevkit/Samples.kt") // } diff --git a/api-docs/src/main/kotlin/org/bitcoindevkit/bdk.kt b/api-docs/src/main/kotlin/org/bitcoindevkit/bdk.kt index d3bc6ce..6da4d18 100644 --- a/api-docs/src/main/kotlin/org/bitcoindevkit/bdk.kt +++ b/api-docs/src/main/kotlin/org/bitcoindevkit/bdk.kt @@ -457,16 +457,6 @@ class BumpFeeTxBuilder() { fun finish(wallet: Wallet): TxBuilderResult {} } -/** - * Generates a new mnemonic using the English word list and the given number of words (12, 15, 18, 21, or 24). - * - * @param wordCount The number of words to use for the mnemonic (also determines the amount of entropy that is used). - * @return The mnemonic words separated by a space in a String - * - * @sample org.bitcoindevkit.generateMnemonicSample - */ -fun generateMnemonic(wordCount: WordCount): String - /** * A BIP-32 derivation path. * @@ -485,7 +475,7 @@ class DerivationPath(path: String) {} * @sample org.bitcoindevkit.descriptorSecretKeyDeriveSample * @sample org.bitcoindevkit.descriptorSecretKeyExtendSample */ -class DescriptorSecretKey(network: Network, mnemonic: String, password: String?) { +class DescriptorSecretKey(network: Network, mnemonic: Mnemonic, password: String?) { /** Derive a private descriptor at a given path. */ fun derive(path: DerivationPath): DescriptorSecretKey {} @@ -568,3 +558,25 @@ class Address(address: String) { /* Return the ScriptPubKey. */ fun scriptPubkey(): Script } + +/** + * Mnemonic phrases are a human-readable version of the private keys. Supported number of words are 12, 15, 18, 21 and 24. + * + * @constructor Generates Mnemonic with a random entropy. + * @param mnemonic The mnemonic as a string of space-separated words. + * + * @sample org.bitcoindevkit.mnemonicSample + */ +class Mnemonic(mnemonic: String) { + /* Returns Mnemonic as string */ + fun asString(): String + + /* Parse a Mnemonic from a given string. */ + fun fromString(): Mnemonic + + /* + * Create a new Mnemonic in the specified language from the given entropy. Entropy must be a + * multiple of 32 bits (4 bytes) and 128-256 bits in length. + */ + fun fromEntropy(): Mnemonic +} diff --git a/api-docs/src/test/kotlin/org/bitcoindevkit/Samples.kt b/api-docs/src/test/kotlin/org/bitcoindevkit/Samples.kt index 198e896..34840ec 100644 --- a/api-docs/src/test/kotlin/org/bitcoindevkit/Samples.kt +++ b/api-docs/src/test/kotlin/org/bitcoindevkit/Samples.kt @@ -130,7 +130,7 @@ fun descriptorSecretKeyExtendSample() { // The `DescriptorSecretKey.extend()` method allows you to extend a key to any given path. // val mnemonic: String = generateMnemonic(WordCount.WORDS12) - val mnemonic: String = "scene change clap smart together mind wheel knee clip normal trial unusual" + val mnemonic: Mnemonic = Mnemonic("scene change clap smart together mind wheel knee clip normal trial unusual") // the initial DescriptorSecretKey will always be at the "master" node, // i.e. the derivation path is empty @@ -159,7 +159,7 @@ fun descriptorSecretKeyDeriveSample() { // The DescriptorSecretKey.derive() method allows you to derive an extended key for a given // node in the derivation tree (for example to create an xpub for a particular account) - val mnemonic: String = "scene change clap smart together mind wheel knee clip normal trial unusual" + val mnemonic: Mnemonic = Mnemonic("scene change clap smart together mind wheel knee clip normal trial unusual") val bip32RootKey: DescriptorSecretKey = DescriptorSecretKey( network = Network.TESTNET, mnemonic = mnemonic, @@ -221,6 +221,13 @@ fun walletSample() { ) } -fun generateMnemonicSample() { - val mnemonic: String = generateMnemonic(WordCount.WORDS12) -} \ No newline at end of file +fun mnemonicSample() { + val mnemonic0: Mnemonic = Mnemonic(WordCount.WORDS12) + + val mnemonic1: Mnemonic = Mnemonic.fromString("scene change clap smart together mind wheel knee clip normal trial unusual") + + val entropy: List = listOf(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u) + val mnemonic2: Mnemonic = Mnemonic.fromEntropy(entropy) + + println(mnemonic0.asString(), mnemonic1.asString(), mnemonic2.asString()) +}