example_test.go raw

   1  // Copyright (c) 2014 The btcsuite developers
   2  // Use of this source code is governed by an ISC
   3  // license that can be found in the LICENSE file.
   4  
   5  package base58_test
   6  
   7  import (
   8  	"fmt"
   9  
  10  	"next.orly.dev/pkg/nostr/crypto/ec/base58"
  11  )
  12  
  13  // This example demonstrates how to decode modified base58 encoded data.
  14  func ExampleDecode() {
  15  	// Decode example modified base58 encoded data.
  16  	encoded := "25JnwSn7XKfNQ"
  17  	decoded := base58.Decode(encoded)
  18  
  19  	// Show the decoded data.
  20  	fmt.Println("Decoded Data:", string(decoded))
  21  
  22  	// Output:
  23  	// Decoded Data: Test data
  24  }
  25  
  26  // This example demonstrates how to encode data using the modified base58
  27  // encoding scheme.
  28  func ExampleEncode() {
  29  	// Encode example data with the modified base58 encoding scheme.
  30  	data := []byte("Test data")
  31  	encoded := base58.Encode(data)
  32  
  33  	// Show the encoded data.
  34  	fmt.Println("Encoded Data:", encoded)
  35  
  36  	// Output:
  37  	// Encoded Data: 25JnwSn7XKfNQ
  38  }
  39  
  40  // This example demonstrates how to decode Base58Check encoded data.
  41  func ExampleCheckDecode() {
  42  	// Decode an example Base58Check encoded data.
  43  	encoded := "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
  44  	decoded, version, err := base58.CheckDecode(encoded)
  45  	if err != nil {
  46  		fmt.Println(err)
  47  		return
  48  	}
  49  
  50  	// Show the decoded data.
  51  	fmt.Printf("Decoded data: %x\n", decoded)
  52  	fmt.Println("Version Byte:", version)
  53  
  54  	// Output:
  55  	// Decoded data: 62e907b15cbf27d5425399ebf6f0fb50ebb88f18
  56  	// Version Byte: 0
  57  }
  58  
  59  // This example demonstrates how to encode data using the Base58Check encoding
  60  // scheme.
  61  func ExampleCheckEncode() {
  62  	// Encode example data with the Base58Check encoding scheme.
  63  	data := []byte("Test data")
  64  	encoded := base58.CheckEncode(data, 0)
  65  
  66  	// Show the encoded data.
  67  	fmt.Println("Encoded Data:", encoded)
  68  
  69  	// Output:
  70  	// Encoded Data: 182iP79GRURMp7oMHDU
  71  }
  72