OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / go-wire / data / base58 / README.md
1 # go-base58
2
3 I copied this package from https://github.com/jbenet/go-base58
4 which in turn came from https://github.com/conformal/btcutil
5 to provide a simple base58 package that
6 - defaults to base58-check (btc)
7 - and allows using different alphabets.
8 - and returns an error on decoding problems to be
9   compatible with the `encoding/*` packages in stdlib
10
11 ## Usage
12
13 ```go
14 package main
15
16 import (
17   "fmt"
18   b58 "github.com/tendermint/go-wire/data/base58"
19 )
20
21 func main() {
22   buf := []byte{255, 254, 253, 252}
23   fmt.Printf("buffer: %v\n", buf)
24
25   str := b58.Encode(buf)
26   fmt.Printf("encoded: %s\n", str)
27
28   buf2, err := b58.Decode(str)
29   if err != nil {
30     panic(err)
31   }
32   fmt.Printf("decoded: %v\n", buf2)
33 }
34 ```
35
36 ### Another alphabet
37
38 ```go
39 package main
40
41 import (
42   "fmt"
43   b58 "github.com/tendermint/go-wire/data/base58"
44 )
45
46 const BogusAlphabet = "ZYXWVUTSRQPNMLKJHGFEDCBAzyxwvutsrqponmkjihgfedcba987654321"
47
48
49 func encdec(alphabet string) {
50   fmt.Printf("using: %s\n", alphabet)
51
52   buf := []byte{255, 254, 253, 252}
53   fmt.Printf("buffer: %v\n", buf)
54
55   str := b58.EncodeAlphabet(buf, alphabet)
56   fmt.Printf("encoded: %s\n", str)
57
58   buf2, err := b58.DecodeAlphabet(str, alphabet)
59   if err != nil {
60     panic(err)
61   }
62   fmt.Printf("decoded: %v\n\n", buf2)
63 }
64
65
66 func main() {
67   encdec(b58.BTCAlphabet)
68   encdec(b58.FlickrAlphabet)
69   encdec(BogusAlphabet)
70 }
71 ```
72
73
74 ## License
75
76 Package base58 (and the original btcutil) are licensed under the ISC License.