{"id":13772706,"url":"https://github.com/wavesplatform/ts-lib-crypto","last_synced_at":"2025-06-19T14:34:11.826Z","repository":{"id":34024074,"uuid":"158679359","full_name":"wavesplatform/ts-lib-crypto","owner":"wavesplatform","description":"All algorithm implementations like signature verification and protocol entries like address used in Waves protocol.","archived":false,"fork":false,"pushed_at":"2023-01-04T18:27:14.000Z","size":1932,"stargazers_count":9,"open_issues_count":22,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-21T07:29:49.617Z","etag":null,"topics":["crypto","cryptography","signature"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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}},"created_at":"2018-11-22T10:06:34.000Z","updated_at":"2023-08-06T16:57:20.000Z","dependencies_parsed_at":"2023-01-15T04:01:49.623Z","dependency_job_id":null,"html_url":"https://github.com/wavesplatform/ts-lib-crypto","commit_stats":null,"previous_names":["wavesplatform/waves-crypto"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fts-lib-crypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fts-lib-crypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fts-lib-crypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesplatform%2Fts-lib-crypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wavesplatform","download_url":"https://codeload.github.com/wavesplatform/ts-lib-crypto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230171534,"owners_count":18184416,"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":["crypto","cryptography","signature"],"created_at":"2024-08-03T17:01:07.066Z","updated_at":"2024-12-19T14:15:14.489Z","avatar_url":"https://github.com/wavesplatform.png","language":"TypeScript","readme":"﻿# ts-lib-crypto [![npm version](https://badge.fury.io/js/%40waves%2Fts-lib-crypto.svg)](https://www.npmjs.com/package/@waves/ts-lib-crypto)\n\nThe waves protocol is a set of rules named consensus by which nodes reach an agreement on the network, and format which nodes use to communicate with each other. It based on several well described hash and crypto algorithms and has predefined set of entries to operate on network. This library contains all algorithm implementations like signature verification and protocol entries like address used in waves protocol. Also it contains utility methods and format converters to help 3rd party developers.\n\n## Agenda\n- **[Installation](#installation)**\n- **[Import styles](#import-styles)**\n- **[Inputs](#inputs)**\n- **[Outputs](#outputs)**\n - **[Seed generation](#seed-generation)**\n\t - [randomSeed](#randomseed)\n\t - [seedWordsList](#seedwordslist)\n - **[Keys and address](#keys-and-address)**\n\t - [publicKey](#publickey)\n\t - [privateKey](#privatekey)\n\t - [keyPair](#keypair)\n\t - [address](#address)\n - **[Signatures](#signatures)**\n\t - [signBytes](#signbytes)\n\t - [verifySignature](#verifySignature)\n- **[Hashing](#hashing)**\n\t - [blake2b](#blake2b)\n\t - [keccak](#keccak)\n\t - [sha256](#sha256)\n - **[Random](#random)**\n\t - [randomBytes](#randomBytes)\n\t - [random](#random)\n - **[Base encoding\\decoding](#base-encodingdecoding)**\n\t - [base16](#base-encodingdecoding)\n\t - [base58](#base-encodingdecoding)\n\t - [base64](#base-encodingdecoding)\n - **[Messaging](#messaging)**\n\t - [sharedKey](#sharedKey)\n\t - [messageEncrypt](#messageEncrypt)\n\t - [messageDecrypt](#messageDecrypt)\n - **[Encryption](#encryption)**\n\t - [aesEncrypt](#aesEncrypt)\n\t - [aesDecrypt](#aesDecrypt)\n- **[Seed encryption](#Seed-encryption)**\n - **[Utils](#utils)**\n\t - [split](#split)\n\t - [concat](#concat)\n\t - [stringToBytes](#stringtobytes)\n\t - [bytesToString](#bytestostring)\n- **[Constants](#constants)**\n- **[Interface](#interface)**\n- **[More examples](#more-examples)**\n## Installation\n```\nnpm install @waves/ts-lib-crypto\n```\n## Import styles\nThe is several ways of doing things when using **ts-lib-crypto**.\nYou can import functions strait-forward:\n```ts\nimport { address } from  '@waves/ts-lib-crypto'\naddress('my secret seed') // 3PAP3wkgbGjdd1FuBLn9ajXvo6edBMCa115\n```\nOr you can use a crypto constructor function:\n```ts\nimport { crypto } from  '@waves/ts-lib-crypto'\nconst { address } = crypto()\naddress('my secret seed') // 3PAP3wkgbGjdd1FuBLn9ajXvo6edBMCa115\n```\nThe second approach gives you more flexibility, using this approach you are able to embed the **seed** and use all seed-dependant functions without **seed** parameter:\n```ts\nimport { crypto } from  '@waves/ts-lib-crypto'\nconst { address } = crypto({seed: 'my secret seed'})\naddress() // 3PAP3wkgbGjdd1FuBLn9ajXvo6edBMCa115\n```\n\n## Inputs \n**ts-lib-crypto** is even more flexible. Any function argument that represents binary data or seed could be passed in several ways. Let's take a look on the following example:\n```ts\nimport { address } from  '@waves/ts-lib-crypto'\nconst  seedString  =  'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nconst  seedBytesAsArray  = [117, 110, 99, 108, 101, 32, 112, 117, 115, 104, 32, 104, 117, 109, 97, 110, 32, 98, 117, 115, 32, 101, 99, 104, 111, 32, 100, 114, 97, 115, 116, 105, 99, 32, 103, 97, 114, 100, 101, 110, 32, 106, 111, 107, 101, 32, 115, 97, 110, 100, 32, 119, 97, 114, 102, 97, 114, 101, 32, 115, 101, 110, 116, 101, 110, 99, 101, 32, 102, 111, 115, 115, 105, 108, 32, 116, 105, 116, 108, 101, 32, 99, 111, 108, 111, 114, 32, 99, 111, 109, 98, 105, 110, 101]\nconst  seedBytesAsUintArray  =  Uint8Array.from(seedBytesAsArray)\naddress(seedString) // 3P9KR33QyXwfTXv8kKtNGZYtgKk3RXSUk36\naddress(seedBytesAsArray) // 3P9KR33QyXwfTXv8kKtNGZYtgKk3RXSUk36\naddress(seedBytesAsUintArray) // 3P9KR33QyXwfTXv8kKtNGZYtgKk3RXSUk36\n```\nAs you can see **seed** parameter is treated the same way for **number[]** or **Uint8Array**.\nWhen you pass binary data is could be represented as  **number[]** or **Uint8Array** or even **base58**:\n```ts\nimport { address, randomSeed, sha256 } from '@waves/ts-lib-crypto'\nconst seed = randomSeed() // uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine\nconst addressBase58 = address(seed) // 3P9KR33QyXwfTXv8kKtNGZYtgKk3RXSUk36\nsha256(addressBase58) // DMPenguwWdLdZ7tesiZY6grw7mjKU2Dob1cn9Uq9TKfp\n```\nHere we got **sha256** hash from address bytes represented as **base58** *(3P9KR33QyXwfTXv8kKtNGZYtgKk3RXSUk36)*. \nBe aware that **sha256** value is not based on \"*3P9KR33QyXwfTXv8kKtNGZYtgKk3RXSUk36*\" string itself, this value was treated as a **binary data** and **base58Decode** was applied.\n\n## Outputs\nAs you've noticed from the previous section *address()* output is **base58** string like:\n```ts\n// 3PAP3wkgbGjdd1FuBLn9ajXvo6edBMCa115\n```\n By default functions from the following list output **base58** string as a result,\n no matter what import-style you choose:\n```\nkeyPair\npublicKey\nprivateKey\naddress\nsharedKey\nsignBytes\n```\n\nIf you prefer **binary** output, you can alter this behaviour and make those functions to return **UInt8Array** instead.\n\nWhen using inline import style:\n```ts\n// You can use [/bytes] module when importing functions to set output to UInt8Array\nimport { address } from  '@waves/ts-lib-crypto/bytes'\naddress('uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine')\n// =\u003e Uint8Array [1,87,55,118,79,89,6,115,207,200,130,220,32,33,101,69,108,108,53,48,167,127,203,18,143,121]\n```\nWhen using crypto constructor function:\n```ts\nimport { crypto } from  '@waves/ts-lib-crypto'\nconst { address } = crypto({ output: 'Bytes' })\naddress('uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine')\n// =\u003e Uint8Array [1,87,55,118,79,89,6,115,207,200,130,220,32,33,101,69,108,108,53,48,167,127,203,18,143,121]\n```\n\n## Seed generation\n\nThe seed is a set of words or bytes that private and public keys are generated from. The usual Waves seed looks like:\n```\nuncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine\n```\nThere are couple ways to generate seed: \n```ts\nconst handWrittenSeedString = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nconst handWrittenSeedBytes = [117, 110, 99, 108, 101, 32, 112, 117, 115, 104, 32, 104, 117, 109, 97, 110, 32, 98, 117, 115, 32, 101, 99, 104, 111, 32, 100, 114, 97, 115, 116, 105, 99, 32, 103, 97, 114, 100, 101, 110, 32, 106, 111, 107, 101, 32, 115, 97, 110, 100, 32, 119, 97, 114, 102, 97, 114, 101, 32, 115, 101, 110, 116, 101, 110, 99, 101, 32, 102, 111, 115, 115, 105, 108, 32, 116, 105, 116, 108, 101, 32, 99, 111, 108, 111, 114, 32, 99, 111, 109, 98, 105, 110, 101]\n```\nOr if you need seed with nonce:\n```ts\nimport { seedWithNonce, randomSeed, address } from '@waves/ts-lib-crypto'\n\nconst nonce = 1\nconst seedphrase = randomSeed() // uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine\nconst seed = seedWithNonce(seedphrase, nonce)\n\n//Now you can use seed as usual\naddress(seed)\n```\nSeed could be any **string** or **number[]** or **Uint8Array** or **ISeedWithNonce**.\n\nThere is also a way to generate seed-phrase using **ts-lib-crypto** described in the next section.\n\n### randomSeed\n```ts\nimport { randomSeed } from '@waves/ts-lib-crypto'\n\nrandomSeed() //uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine\n```\nYou can also specify seed-phrase size:\n```ts\nrandomSeed(3) //uncle push human\n```\nThe default seed size is 15 words.\n\n### seedWordsList\nIf you want to get all the valid seed words that official waves-client generates seed-phrase from, use **seedWordsList** the 2048 word array.\n```ts\nimport { seedWordsList } from '@waves/ts-lib-crypto'\nconsole.log(seedWordsList) // [ 'abandon','ability','able', ... 2045 more items ]\n```\n## Keys and address\n\n### publicKey\nYou could get public key either from raw seed-phrase or seed with nonce:\n```ts\nimport { publicKey, seedWithNonce } from '@waves/ts-lib-crypto'\nconst seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\npublicKey(seed) // 4KxUVD9NtyRJjU3BCvPgJSttoJX7cb3DMdDTNucLN121\npublicKey(seedWithNonce(seed, 0)) // 4KxUVD9NtyRJjU3BCvPgJSttoJX7cb3DMdDTNucLN121\n```\nOr even from private key, it's usefull in some cases:\n```ts\nimport { publicKey, privateKey, seedWithNonce } from '@waves/ts-lib-crypto'\nconst seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nconst pk = privateKey(seed)\npublicKey({ privateKey: pk }) // 4KxUVD9NtyRJjU3BCvPgJSttoJX7cb3DMdDTNucLN121\n```\n\n### privateKey\nSame with private key:\n```ts\nimport { privateKey, seedWithNonce } from '@waves/ts-lib-crypto'\nconst  seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nprivateKey(seed)\nprivateKey(seedWithNonce(seed, 99))\n```\n### keyPair\nYou could also obtain a keyPair:\n```ts\nimport { keyPair } from '@waves/ts-lib-crypto'\nconst  seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nkeyPair(seed)\n// =\u003e { \n//      publicKey:  '4KxUVD9NtyRJjU3BCvPgJSttoJX7cb3DMdDTNucLN121',\n//      privateKey: '6zFSymZAoaua3gtJPbAUwM584tRETdKYdEG9BeEnZaGW'\n//    }\n```\n### address\nYou can create an address for *Mainnet*:\n```ts\nimport { address } from '@waves/ts-lib-crypto'\nconst  seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\naddress(seed) // 3P9KR33QyXwfTXv8kKtNGZYtgKk3RXSUk36\n```\nor *Testnet*:\n```ts\naddress(seed, 'T') // 3MwJc5iX7QQGq5ciVFdNK7B5KSEGbUCVxDw\n```\nalternatively You could use **TEST_NET_CHAIN_ID** constant instead of **T** literal like this:\n```ts\nimport { address, TEST_NET_CHAIN_ID } from '@waves/ts-lib-crypto'\nconst  seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\naddress(seed, TEST_NET_CHAIN_ID) // 3MwJc5iX7QQGq5ciVFdNK7B5KSEGbUCVxDw\n```\nThere are several more useful constants, you can check them in [\\[constants\\]](/#constants) section.\n## Signatures\n#### signBytes\nTo sign arbitrary bytes or usually transaction bytes you should use the **signBytes** function.\nHere is sign with seed example:\n```ts\nimport { signBytes } from '@waves/ts-lib-crypto'\nconst bytes = [117, 110, 99, 108, 101]\nconst seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nsignBytes(seed, bytes) // 5ZpULwrnUYoxQZcw26km6tgGbj1y23ywYB4A9bLCpax6PUdrhkCmmoLBP6C1G5yiMJ7drqN9jNxPym6f8vrPsWnm\n```\nAlso you can use private key to sign bytes:\n```ts\nimport { signBytes, privateKey } from '@waves/ts-lib-crypto'\nconst bytes = [117, 110, 99, 108, 101]\nconst seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nconst key = privateKey(seed)\nsignBytes({ privateKey: key }, bytes)\n```\nRemember that you can use **base58** strings when it's about binary data, so you can represent bytes as **base58** too:\n```ts\nsignBytes({ privateKey:  key }, 'Fk1sjwdPSwZ4bPwvpCGPH6')\n```\nYou can learn more about it in the [outputs](#outputs) section.\n#### verifySignature\nVerifying signature is a way to proof what particular bytes was signed with a particular private key or seed which correspond to public key that we are checking against:\n```ts\nimport { signBytes, verifySignature, keyPair } from '@waves/ts-lib-crypto'\n//Signature roundtrip\nconst bytes = [117, 110, 99, 108, 101]\nconst seed = 'uncle push human bus echo drastic garden joke sand warfare sentence fossil title color combine'\nconst keys = keyPair(seed)\nconst signature = signBytes(keys, bytes)\nverifySignature(keys.publicKey, bytes, signature) // true\n```\n## Hashing\nThere are three hashing algorithms available in **ts-lib-crypto**.\n#### blake2b\n```ts\nimport { blake2b } from '@waves/ts-lib-crypto'\nconst bytesArray = [117, 110, 99, 108, 101]\nconst bytesUint = Uint8Array.from([117, 110, 99, 108, 101])\nconst bytesBase58 = 'EFRr9cp'\nblake2b(bytesArray)  // 9DqBU9wZAR85PyrUSJpwaU9DggM8veyMxRMvFe1q6atu\nblake2b(bytesUint)   // 9DqBU9wZAR85PyrUSJpwaU9DggM8veyMxRMvFe1q6atu\nblake2b(bytesBase58) // 9DqBU9wZAR85PyrUSJpwaU9DggM8veyMxRMvFe1q6atu\n\n```\n#### keccak\n```ts\nimport { keccak } from '@waves/ts-lib-crypto'\nconst bytesArray = [117, 110, 99, 108, 101]\nconst bytesUint = Uint8Array.from([117, 110, 99, 108, 101])\nconst bytesBase58 = 'EFRr9cp'\nkeccak(bytesArray)  // 5cqz9N2PPjDkSBSwga8AttKzQEHfn8aQ95rcZZmabLA7\nkeccak(bytesUint)   // 5cqz9N2PPjDkSBSwga8AttKzQEHfn8aQ95rcZZmabLA7\nkeccak(bytesBase58) // 5cqz9N2PPjDkSBSwga8AttKzQEHfn8aQ95rcZZmabLA7\n```\n#### sha256\n```ts\nimport { sha256 } from '@waves/ts-lib-crypto'\nconst bytesArray = [117, 110, 99, 108, 101]\nconst bytesUint = Uint8Array.from([117, 110, 99, 108, 101])\nconst bytesBase58 = 'EFRr9cp'\nsha256(bytesArray)  // 4JPydqbhxhZF7kpuGA2tJWkXDmevJYfig45gqdV1UF9E\nsha256(bytesUint)   // 4JPydqbhxhZF7kpuGA2tJWkXDmevJYfig45gqdV1UF9E\nsha256(bytesBase58) // 4JPydqbhxhZF7kpuGA2tJWkXDmevJYfig45gqdV1UF9E\n```\n## Random\nThere is several ways to get random values in **ts-lib-crypto**.\nTo get an **Uint8Array** of random values simply use:\n#### randomBytes\n```ts\nimport { randomBytes } from '@waves/ts-lib-crypto'\nrandomBytes(3) // Uint8Array [ 120, 46, 179 ]             \n```\nIf you want more control over the values format you could use:\n#### random\n```ts\nimport { random } from '@waves/ts-lib-crypto'\n\nconst length = 3     \nrandom(length, 'Array8')       // [ 19, 172, 130 ]   \nrandom(length, 'Array16')      // [ 61736, 48261, 38395 ] \nrandom(length, 'Array32')      // [ 406628961, 307686833, 2604847943 ]       \nrandom(length, 'Buffer')       // \u003cBuffer db ff fb\u003e       \nrandom(length, 'Uint8Array')   // Uint8Array [ 137, 85, 212 ]   \nrandom(length, 'Uint16Array')  // Uint16Array [ 35881, 51653, 55967 ]  \nrandom(length, 'Uint32Array')  // Uint32Array [ 698646076, 2957331816, 2073997581 ]    \n```\n## Base encoding\\decoding\n\n\n```ts\nimport { base16Encode, base16Decode, base58Encode, base58Decode, base64Encode, base64Decode, randomBytes } from '@waves/ts-lib-crypto'\n\nconst bytes = randomBytes(32)\n\n// Base16 same as Hex\nconst base16String = base16Encode(bytes) // 2059ec5d9ed640b75722ec6a2ff76890e523ea4624887549db761d678ba8f899\nconst bytesFromBase16 = base16Decode(base16String)\n\n// Base58\nconst base58String = base58Encode(bytes) // 3BHaM9Q5HhUobQ5oZAqjdkE9HRpmqMx4XLq3GXTMD5tU\nconst bytesFromBase58 = base58Decode(base58String)\n\n// Base64\nconst base64String = base64Encode(bytes) // IFnsXZ7WQLdXIuxqL/dokOUj6kYkiHVJ23YdZ4uo+Jk=\nconst bytesFromBase64 = base64Decode(base64String)\n```\n## Messaging\nThese methods implement waves messaging protocol \n- sharedKey \n- messageDecrypt\n- messageEncrypt\n```typescript\nimport { sharedKey, messageEncrypt, messageDecrypt, keyPair } from '@waves/ts-lib-crypto'\n\nconst bobKeyPair = keyPair('Bob')\nconst aliceKeyPair = keyPair('Alice')\nconst msg = 'hello world'\n\n// Alice derives shared key and encrypts message\nconst sharedKeyA = sharedKey(aliceKeyPair.privateKey, bobKeyPair.publicKey, 'waves') \nconst encrypted = messageEncrypt(sharedKeyA, msg)\n\n// Bob decrypts message derives shared key and decrypts message\nconst sharedKeyB = sharedKey(aliceKeyPair.privateKey, bobKeyPair.publicKey, 'waves') \nconst decrypted = messageDecrypt(sharedKeyB, encrypted)\n```\n## Encryption\nThis is low level functionality where you have to generate key and iv yourself \n#### aesEncrypt\nEncrypt bytes using AES algorithm. \n```typescript\nimport { aesEncrypt, randomBytes } from '@waves/ts-lib-crypto'\n\nconst data = Uint8Arraty.from([1,2,3])\nconst mode =  'CBC' // Possible modes are 'CBC' | 'CFB' | 'CTR' | 'OFB' | 'ECB' | 'GCM'\n\nconst key = randomBytes(32)\nconst iv = randomBytes(32)\n\nconst encrypted = aesEncrypt(data, key, mode, iv)\n\n```\n#### aesDecrypt\nDecrypt bytes using AES algorithm\n```typescript\nconst decrypted = aesDecrypt(encrypted, key, mode, iv)\n```\n\n## Seed encryption\nThese functions implements seed encryption protocol used in DexClient and WavesKeeper\n```typescript\nimport { encryptSeed, decryptSeed } from '@waves/ts-lib-crypto'\n\nconst seed = 'some secret seed phrase i use'\nconst encrypted = encryptSeed(seed, 'secure password')\nconst decrypted = decryptSeed(encryptSeed, 'secure password')\n\n```\n## Utils\nUtility functions designed to help 3rd party developers working with js binary types like Uint8Array and Buffer.\n#### split\nYou can use split for splitting bytes to sub arrays.\n```ts\nimport { split, randomBytes } from '@waves/ts-lib-crypto'\nconst bytes = randomBytes(2 + 3 + 4 + 10)\nsplit(bytes, 2, 3, 4)\n// [ \n//   Uint8Array [195, 206],\n//   Uint8Array [ 10, 208, 171 ],\n//   Uint8Array [ 36, 18, 254, 205 ],\n//   Uint8Array [ 244, 232, 55, 11, 113, 47, 80, 194, 170, 216 ]\n// ]\n```\nAlternatively, you can use array deconstruction syntax:\n```ts\nconst [a, b, c, rest] = split(bytes, 2, 3, 4)\n// a = Uint8Array [195, 206],\n// b = Uint8Array [ 10, 208, 171 ],\n// c = Uint8Array [ 36, 18, 254, 205 ],\n// rest = Uint8Array [ 244, 232, 55, 11, 113, 47, 80, 194, 170, 216 ]\n```\n#### concat\nConcat is the opposite and pretty self-explanatory:\n```ts\nimport { concat, randomBytes } from '@waves/ts-lib-crypto'\nconst bytesA = randomBytes(2)\nconst bytesB = randomBytes(2)\nconcat(bytesA, bytesB) // Uint8Array [ 36, 18, 254, 205 ]\n```\n#### stringToBytes\n```ts\nimport { stringToBytes } from '@waves/ts-lib-crypto'\nstringToBytes('Waves!') // Uint8Array [ 87, 97, 118, 101, 115, 33 ]\n```\n#### bytesToString\n```ts\nimport { bytesToString } from '@waves/ts-lib-crypto'\nbytesToString([ 87, 97, 118, 101, 115, 33 ]) // Waves!\n```\n## Constants\nThere is several useful constants declared at **ts-lib-crypto**:\n```ts\nconst PUBLIC_KEY_LENGTH = 32\nconst PRIVATE_KEY_LENGTH = 32\nconst SIGNATURE_LENGTH = 64\nconst ADDRESS_LENGTH = 26\n\nconst MAIN_NET_CHAIN_ID = 87 // W\nconst TEST_NET_CHAIN_ID = 84 // T\n```\n## Interface \nThe full **IWavesCrypto** interface can be found on the [project`s github](https://github.com/wavesplatform/ts-lib-crypto) in [interface.ts](https://github.com/wavesplatform/ts-lib-crypto/blob/master/src/crypto/interface.ts).\n```ts\n  //Seeds, keys and addresses\n  seedWithNonce: (seed: TSeed, nonce: number) =\u003e INonceSeed\n  keyPair: (seed: TSeed) =\u003e TKeyPair\u003cTBytesOrBase58\u003e\n  publicKey: (seed: TSeed) =\u003e TBytesOrBase58\n  privateKey: (seed: TSeed) =\u003e TBytesOrBase58\n  address: (seedOrPublicKey: TSeed | TPublicKey\u003cTBinaryIn\u003e, chainId?: TChainId) =\u003e TBytesOrBase58\n\n  //Signature\n  signBytes: (seedOrPrivateKey: TSeed | TPrivateKey\u003cTBinaryIn\u003e, bytes: TBinaryIn, random?: TBinaryIn) =\u003e TDesiredOut\n  //Hashing \n  blake2b: (input: TBinaryIn) =\u003e TBytes\n  keccak: (input: TBinaryIn) =\u003e TBytes\n  sha256: (input: TBinaryIn) =\u003e TBytes\n\n  //Base encoding\\decoding\n  base64Encode: (input: TBinaryIn) =\u003e TBase64\n  base64Decode: (input: TBase64) =\u003e TBytes //throws (invalid input)\n  base58Encode: (input: TBinaryIn) =\u003e TBase58\n  base58Decode: (input: TBase58) =\u003e TBytes //throws (invalid input)\n  base16Encode: (input: TBinaryIn) =\u003e TBase16\n  base16Decode: (input: TBase16) =\u003e TBytes //throws (invalid input)\n\n  //Utils\n  stringToBytes: (input: string) =\u003e TBytes\n  bytesToString: (input: TBinaryIn) =\u003e string\n  split: (binary: TBinaryIn, ...sizes: number[]) =\u003e TBytes[]\n  concat: (...binaries: TBinaryIn[]) =\u003e TBytes\n\n  //Random\n  random\u003cT extends keyof TRandomTypesMap\u003e(count: number, type: T): TRandomTypesMap[T]\n  randomBytes: (size: number) =\u003e TBytes\n  randomSeed: (wordsCount?: number) =\u003e string\n\n  //Verification\n  verifySignature: (publicKey: TBinaryIn, bytes: TBinaryIn, signature: TBinaryIn) =\u003e boolean\n  verifyPublicKey: (publicKey: TBinaryIn) =\u003e boolean\n  verifyAddress: (address: TBinaryIn, optional?: { chainId?: TChainId, publicKey?: TBinaryIn }) =\u003e boolean\n\n  //Messaging\n  sharedKey: (privateKeyFrom: TBinaryIn, publicKeyTo: TBinaryIn, prefix: TRawStringIn) =\u003e TBytesOrBase58\n  messageDecrypt: (sharedKey: TBinaryIn, encryptedMessage: TBinaryIn) =\u003e string\n  messageEncrypt: (sharedKey: TBinaryIn, message: TRawStringIn) =\u003e TBytes\n\n  //Encryption\n  aesEncrypt: (data: TRawStringIn, secret: TBinaryIn, mode?: AESMode, iv?: TBinaryIn) =\u003e TBytes\n  aesDecrypt: (encryptedData: TBinaryIn, secret: TBinaryIn, mode?: AESMode, iv?: TBinaryIn) =\u003e TBytes\n```\n## More examples\nEvery example used in this document and many more can be found on the [project`s github](https://github.com/wavesplatform/ts-lib-crypto) inside [examples](https://github.com/wavesplatform/ts-lib-crypto/tree/master/examples) folder.\n\n\n","funding_links":[],"categories":["Frameworks and tools"],"sub_categories":["Client libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesplatform%2Fts-lib-crypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwavesplatform%2Fts-lib-crypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesplatform%2Fts-lib-crypto/lists"}