Giter Club home page Giter Club logo

libcrypto-js's Introduction

libcrypto

A small vendoring wrapper for sjcl with support for hashes and encodings required by the Steem platform.

Usage

If you are using Webpack or Browserify, you must ensure that Node's built-in crypto package is excluded from your builds.

Otherwise, just

$ yarn install steem-crypto

API

> crypto = require('@steemit/libcrypto');

crypto.sha256(data)

Hashes the content of an ArrayBuffer using SHA-256.

> shaHash = crypto.sha256(new Uint8Array().buffer)
ArrayBuffer { byteLength: 32 }
> crypto.hexify(shaHash)
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'

crypto.ripemd160(data)

Hashes the content of an ArrayBuffer using RIPEMD-160.

> ripemdHash = crypto.ripemd160(new Uint8Array().buffer)
ArrayBuffer { byteLength: 20 }
> crypto.hexify(ripemdHash)
'9c1185a5c5e9fc54612808977ee8f548b2258d31'

crypto.PrivateKey

Provides operations over Steemit secp256k1-based ECC private keys.

> secretKey = crypto.PrivateKey.from('5JCDRqLdyX4W7tscyzyxav8EaqABSVAWLvfi7rdqMKJneqqwQGt')
PrivateKey { getPublicKey: [Function], sign: [Function] }
> secretKey.getPublicKey().toString()
'STM5pZ15FDVAvNKW3saTJchWmSSmYtEvA6aKiXwDtCq2JRZV9KtR9'
> secretSig = secretKey.sign(new Uint8Array(32).buffer)
ArrayBuffer { byteLength: 65 }
> crypto.hexify(secretSig)
'20387d5f9ae215a64065fde2a9d4f7be83d3480b7cc89f7c01488042da348845408909e9d4f1d66466c53f0007c771a73bf2883d8d5ab4735b5b4316091361442c'

crypto.PublicKey

Provides operations over Steemit secp256k1-based ECC public keys.

> publicKey = crypto.PublicKey.from('STM5SKxjN1YdrFLgoPcp9KteUmNVdgE8DpTPC9sF6jbjVqP9d2Utq')
... 
> publicKey.verify(new Uint8Array(32).buffer, secretSig)
true
> PublicKey.recover(someHash, someSig)
...

crypto.generateKeys()

Generates a new pair of keys in Steem WIF format using cryptographically secure random number generation.

> crypto.generateKeys()
{
  private: "5JCDRqLdyX4W7tscyzyxav8EaqABSVAWLvfi7rdqMKJneqqwQGt",
  public: "STM5pZ15FDVAvNKW3saTJchWmSSmYtEvA6aKiXwDtCq2JRZV9KtR9"
}

crypto.keysFromPassword(accountName, accountPassword)

Given a Steemit account name and password, regenerates the derived owner, posting, active, and memo keys.

> crypto.keysFromPassword('username', 'password')
{ owner:
   { private: '5JCDRqLdyX4W7tscyzyxav8EaqABSVAWLvfi7rdqMKJneqqwQGt',
     public: 'STM5pZ15FDVAvNKW3saTJchWmSSmYtEvA6aKiXwDtCq2JRZV9KtR9' },
  memo:
   { private: '5JSmQQJXH5ZrSW3KJSTUPFJy7SuLeDiY3bW6vB1McamxzJQFhwD',
     public: 'STM5nwJgD9jmkAdTXuiz3jqrkw3om95gCapZo4e4Bcp3qzyiedwCn' },
  posting:
   { private: '5HsoxWiHRRyx6oSxKj32HDqDMzSGhs79zLZopDc7nMcjMbcPp5E',
     public: 'STM6gZmazY23TEMkxmPpnmvbAgWFAzwtaSDbhSUdmpTXzoJJLPFH4' },
  active:
   { private: '5JamTPvZyQsHf8c2pbN92F1gUY3sJkpW3ZJFzdmfbAJPAXT5aw3',
     public: 'STM5SKxjN1YdrFLgoPcp9KteUmNVdgE8DpTPC9sF6jbjVqP9d2Utq' } }

Requirements

steem-crypto is written in Javascript as specified by ECMA-262, version 5.1. Other than its vendored copy of sjcl, it has no dependencies and never will.

steem-crypto explicitly supports the following environments without polyfills:

  • Node.js versions 4 and up
  • Microsoft Edge (all versions)
  • Safari for macOS versions 7.1+
  • Safari for iOS versions 8+
  • Firefox, Chrome, and Opera versions 30+

steem-crypto explicitly does not support the following environments:

  • Opera Mini
  • Android Browser (i.e., the non-Chromium versions)
  • Microsoft Internet Explorer versions <10

Contributing

Contributions must conform to the following rules:

  • They must pass formatting and linting and the existing automated test suite must pass.
  • They must add test coverage for new code.
  • They must not introduce any new dependencies.
  • They must support the environments listed above without the use of polyfills.

libcrypto-js's People

Contributors

goldibex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libcrypto-js's Issues

crypto.randomBytes is not a function

I'm having an issue in a vue.js application using steem-js and steemit/libcrypto.js.

require('steem.js')

throws the following exception:
TypeError: crypto.randomBytes is not a function

raised in the "nodeRandom" function of secure-random.js
It looks like nodeRandom invokes:
require('crypto')
then "randomBytes" on the result.

However require('crypto') is returning an empty object in my environment.
I'm wondering if steemit/libcrypto-js is clashing with node.js crypto.

Thanks for your assistance!

Build script error

Error: Cannot find module './lib/file'

yarn install v1.2.1
[1/4] ๐Ÿ”  Resolving packages...
success Already up-to-date.
$ ./scripts/build.js
module.js:538
    throw err;
    ^

Error: Cannot find module './lib/file'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/jnordberg/Development/steemit/steem-crypto-js/scripts/build.js:8:12)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
error Command failed with exit code 1.

Code coverage

Add some code coverage tool to make sure our tests cover all usecases

Publish prep

  • Add to watt
  • Rename repo to match package name
  • Make repo public

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.