Common javascript cryptographic utilities. Based on sjcl.

Usage no npm install needed!

<script type="module">
  import nrlDemoLibcrypto from 'https://cdn.skypack.dev/@nrl-demo/libcrypto';



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


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


> crypto = require('@nrl-demo/libcrypto');


Hashes the content of an ArrayBuffer using SHA-256.

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


Hashes the content of an ArrayBuffer using RIPEMD-160.

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


Provides operations over Knowledgr secp256k1-based ECC private keys.

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


Provides operations over Knowledgr secp256k1-based ECC public keys.

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


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

> crypto.generateKeys()
  private: "5JCDRqLdyX4W7tscyzyxav8EaqABSVAWLvfi7rdqMKJneqqwQGt",
  public: "KWR5pZ15FDVAvNKW3saTJchWmSSmYtEvA6aKiXwDtCq2JRZV9KtR9"

crypto.keysFromPassword(accountName, accountPassword)

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

> crypto.keysFromPassword('username', 'password')
{ owner:
   { private: '5JCDRqLdyX4W7tscyzyxav8EaqABSVAWLvfi7rdqMKJneqqwQGt',
     public: 'KWR5pZ15FDVAvNKW3saTJchWmSSmYtEvA6aKiXwDtCq2JRZV9KtR9' },
   { private: '5JSmQQJXH5ZrSW3KJSTUPFJy7SuLeDiY3bW6vB1McamxzJQFhwD',
     public: 'KWR5nwJgD9jmkAdTXuiz3jqrkw3om95gCapZo4e4Bcp3qzyiedwCn' },
   { private: '5HsoxWiHRRyx6oSxKj32HDqDMzSGhs79zLZopDc7nMcjMbcPp5E',
     public: 'KWR6gZmazY23TEMkxmPpnmvbAgWFAzwtaSDbhSUdmpTXzoJJLPFH4' },
   { private: '5JamTPvZyQsHf8c2pbN92F1gUY3sJkpW3ZJFzdmfbAJPAXT5aw3',
     public: 'KWR5SKxjN1YdrFLgoPcp9KteUmNVdgE8DpTPC9sF6jbjVqP9d2Utq' } }


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


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.