{"id":13772718,"url":"https://github.com/wavesplatform/go-lib-crypto","last_synced_at":"2025-08-20T18:35:13.253Z","repository":{"id":144200305,"uuid":"189381631","full_name":"wavesplatform/go-lib-crypto","owner":"wavesplatform","description":"GoLang implementation of the unified crypto primitives for Waves Platform","archived":false,"fork":false,"pushed_at":"2020-08-31T10:36:11.000Z","size":1148,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-15T00:16:49.377Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wavesplatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-05-30T09:06:11.000Z","updated_at":"2023-08-04T21:14:25.000Z","dependencies_parsed_at":"2023-07-15T01:45:48.608Z","dependency_job_id":null,"html_url":"https://github.com/wavesplatform/go-lib-crypto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fgo-lib-crypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fgo-lib-crypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fgo-lib-crypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fgo-lib-crypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wavesplatform","download_url":"https://codeload.github.com/wavesplatform/go-lib-crypto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230445917,"owners_count":18227060,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:07.196Z","updated_at":"2024-12-19T14:15:33.566Z","avatar_url":"https://github.com/wavesplatform.png","language":"Go","readme":"# go-lib-crypto\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/wavesplatform/go-lib-crypto)](https://goreportcard.com/report/github.com/wavesplatform/go-lib-crypto)\n[![GoDoc](https://godoc.org/github.com/wavesplatform/go-lib-crypto?status.svg)](https://godoc.org/github.com/wavesplatform/go-lib-crypto)\n\n`go-lib-crypto` is a unified crypto library for [Waves Platform](https://wavesplatform.com). It has a unified set of functions corresponding with [`unified-declarations`](https://github.com/wavesplatform/unified-declarations).\n\nThis library meant to be used in client applications. That's why its API is relatively simple. \n\nThe following could be done using the library:\n\n* Calculation of a hash digest of various hash functions used by Waves\n* Encoding and decoding of byte slices in BASE58 and BASE64 string representation\n* Key pair generation from seed phrase\n* Waves address generation and verification\n* Random seed phrase generation and verification\n* Signing of bytes message\n* Verification of signed message\n\n## Installation and import\n\n```bash\ngo get -u github.com/wavesplatform/go-lib-crypto\n```\n```go\nimport \"github.com/wavesplatform/go-lib-crypto\"\n```\n\n## Short API reference with examples\n\n### Instantiation\n\nFor the purpose of unification the API of the library made in form of the interface.\nTo instantiate the un-exported structure that implements the interface call the `NewWavesCrypto` function.\n\n```go\ncrypto := wavesplatform.NewWavesCrypto()\n```\n\n### Working with hashes\n\nThe three hash functions used by Waves are supported:\n\n* SHA-256\n* BLAKE2b-256\n* Keccak-256 (legacy version)\n\nEvery hash functions accepts one parameter of type `Bytes`. The `Bytes` type wraps a slice of bytes.\n\n```go\npackage main\n\nimport (\n\t\"encoding/hex\"\n\t\"fmt\"\n\t\"github.com/wavesplatform/go-lib-crypto\"\n)\n\nfunc main() {\n\tbytes, _ := hex.DecodeString(\"fd08be957bda07dc529ad8100df732f9ce12ae3e42bcda6acabe12c02dfd6989\")\n\tc := wavesplatform.NewWavesCrypto()\n\tblake := c.Blake2b(bytes)\n\tkeccak := c.Keccak(bytes)\n\tsha := c.Sha256(bytes)\n\tfmt.Println(\"BLAKE2b-256:\", hex.EncodeToString(blake))\n\tfmt.Println(\"Keccak-256:\", hex.EncodeToString(keccak))\n\tfmt.Println(\"SHA-256:\", hex.EncodeToString(sha))\n}\n```\n\nThe output should be like this:\n\n```\nBLAKE2b-256: c425f69e3be14c929d18b2808831cbaeb2733c9e6b9c5ed37c3601086f202396\nKeccak-256: 14a0d0ee74865d8d721c4218768b7c39fd365b53f0359d6d28d82dc97450f583\nSHA-256: 7ed1b5b6867c0d6c98097676adc00b6049882e473441ac5ff3613df48b69f9f3\n```\n\nSee the [example on play.golang.org](https://play.golang.org/p/d5Eo4yY6lIC).\n\n### Seed and keys generation\n\nOne can create a new key pair from the seed phrase. Library defines types for `Seed`, `PrivateKey`, `PublicKey` (wrappers over `string`) and structure for `KeyPair` that combines the private and public keys.\n\nThe function `RandomSeed` creates a new random seed phrase of 15 words. The seed generation follows the [BIP39 standard](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki). \n\nThe keys generation functions `KeyPair`, `PublicKey` and `PrivateKey` accept the seed phrase as its parameters and produces a `KeyPair`, `PublicKey` or `PrivateKey` relatively. In latter two cases the whole key pair is produced, but only a part of it returned to the user.\n\nHere is the [example](https://play.golang.org/p/MCGUtsvPXbZ).\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/wavesplatform/go-lib-crypto\"\n)\n\nfunc main() {\n\tc := wavesplatform.NewWavesCrypto()\n\tseed := c.RandomSeed()\n\tfmt.Println(\"SEED:\", seed)\n\n\tpair := c.KeyPair(seed)\n\tfmt.Println(\"PAIR:\", \"PRIVATE KEY:\", pair.PrivateKey, \"PUBLIC KEY:\", pair.PublicKey)\n\n\tsk := c.PrivateKey(seed)\n\tfmt.Println(\"PRIVATE KEY:\", sk)\n\n\tpk := c.PublicKey(seed)\n\tfmt.Println(\"PUBLIC KEY:\", pk)\n}\n```\n\n### Waves address generation\n\nThere is an `Address` type which wraps the string. An address could be created from `PublicKey` or `Seed` using functions `Address` or `AddressFromSeed`. In both cases the `WavesChainID` byte should be provided as second parameter. \nIt is possible to verify the correctness of an Address string using functions `VerifyAddressChecksum` or `VerifyAddress`. The first function checks that the address has correct length and version and the built-in checksum is correct. The second one additionally checks that the address contains the correct `WavesChainID`.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/wavesplatform/go-lib-crypto\"\n)\n\nfunc main() {\n\tc := wavesplatform.NewWavesCrypto()\n\tseed := c.RandomSeed()\n\tfmt.Println(\"SEED:\", seed)\n\n\tpair := c.KeyPair(seed)\n\tfmt.Println(\"PAIR:\", \"PRIVATE KEY:\", pair.PrivateKey, \"PUBLIC KEY:\", pair.PublicKey)\n\t\n\taddress := c.Address(pair.PublicKey, wavesplatform.TestNet)\n\tfmt.Println(\"ADDRESS 1:\", address)\n\t\n\taddress2 := c.AddressFromSeed(seed, wavesplatform.TestNet)\n\tfmt.Println(\"ADDRESS 2:\", address2)\n\t\n\tfmt.Println(\"CHECKSUM OK:\", c.VerifyAddressChecksum(address))\n\tfmt.Println(\"ADDRESS ON TESTNET OK:\", c.VerifyAddress(address, wavesplatform.TestNet))\n\tfmt.Println(\"ADDRESS ON MAINNET OK:\", c.VerifyAddress(address, wavesplatform.MainNet))\n}\n```\n\nTry the [example](https://play.golang.org/p/YXHpdWAItC7).\n\n### Signing and verifying \n\nThe library offers two functions to sign bytes (`SignBytes` and `SignBytesBySeed`) and one to verify a signature (`VerifySignature`). \n\nHere is the [example](https://play.golang.org/p/7r8Ivd5XgNE) of using those functions.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"encoding/hex\"\n\t\"github.com/wavesplatform/go-lib-crypto\"\n)\n\nfunc main() {\n\tbytes, _ := hex.DecodeString(\"fd08be957bda07dc529ad8100df732f9ce12ae3e42bcda6acabe12c02dfd6989\")\n\tother, _ := hex.DecodeString(\"54686520696e636f7272656374206d657373616765\")\n\n\tc := wavesplatform.NewWavesCrypto()\n\tseed := c.RandomSeed()\n\tfmt.Println(\"SEED:\", seed)\n\n\tpair := c.KeyPair(seed)\n\tfmt.Println(\"PAIR:\", \"PRIVATE KEY:\", pair.PrivateKey, \"PUBLIC KEY:\", pair.PublicKey)\n\t\n\tsig1 := c.SignBytes(bytes, pair.PrivateKey)\n\tfmt.Println(\"SIGNATURE 1:\", hex.EncodeToString(sig1))\n\tsig2 := c.SignBytesBySeed(bytes, seed)\n\tfmt.Println(\"SIGNATURE 2:\", hex.EncodeToString(sig2))\n\t\n\tfmt.Println(\"SIGNATURE 1 OK:\", c.VerifySignature(pair.PublicKey, bytes, sig1))\n\tfmt.Println(\"SIGNATURE 2 OK:\", c.VerifySignature(pair.PublicKey, bytes, sig2))\n\n\tfmt.Println(\"SIGNATURE 1 ON OTHER OK:\", c.VerifySignature(pair.PublicKey, other, sig1))\n\tfmt.Println(\"SIGNATURE 2 ON OTHER OK:\", c.VerifySignature(pair.PublicKey, other, sig2))\n}\n```\n\n## Documentation\n\n[`go-lib-crypto` on GoDoc](http://godoc.org/github.com/wavesplatform/go-lib-crypto).\n","funding_links":[],"categories":["Frameworks and tools"],"sub_categories":["Client libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesplatform%2Fgo-lib-crypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwavesplatform%2Fgo-lib-crypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesplatform%2Fgo-lib-crypto/lists"}