• Stars
    star
    283
  • Rank 146,066 (Top 3 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elliptic curve cryptography functions: Private Key, Public Key, Signature, AES, Encryption, Decryption

NPM Build Status

Elliptic curve cryptography functions (ECC)

Private Key, Public Key, Signature, AES, Encryption / Decryption

Import

import ecc from 'eosjs-ecc'
// or
const ecc = require('eosjs-ecc')

Include

  • Install with: yarn add eosjs-ecc
  • Html script tag, see releases for the correct version and its matching script integrity hash.
<html>
<head>
  <meta charset="utf-8">
  <!--
  sha512-cL+IQQaQ586s9DrXfGtDheRpj5iDKh2M+xlpfwbhNjRIp4BGQ1fkM/vB4Ta8mc+f51YBW9sJiPcyMDIreJe6gQ== lib/eosjs-ecc.js
  sha512-dYFDmK/d9r3/NCp6toLtfkwOjSMRBaEzaGAx1tfRItC0nsI0hVLERk05iNBQR7uDNI7ludYhcBI4vUiFHdjsTQ== lib/eosjs-ecc.min.js
  sha512-eq1SCoSe38uR1UVuQMwR73VgY8qKTBDc87n2nIiC5WLhn1o2y1U6c5wY8lrigVX7INM8fM0PxDlMX5WvpghKig== lib/eosjs-ecc.min.js.map
  -->
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/eosjs-ecc.min.js"
    integrity="sha512-dYFDmK/d9r3/NCp6toLtfkwOjSMRBaEzaGAx1tfRItC0nsI0hVLERk05iNBQR7uDNI7ludYhcBI4vUiFHdjsTQ=="
    crossorigin="anonymous"></script>

</head>
<body>
  See console object: eosjs_ecc
</body>
</html>

Common API

Table of Contents

wif

Wallet Import Format

Type: string

ecc

initialize

Initialize by running some self-checking code. This should take a second to gather additional CPU entropy used during private key generation.

Initialization happens once even if called multiple times.

Returns Promise

unsafeRandomKey

Does not pause to gather CPU entropy.

Returns Promise<PrivateKey> test key

randomKey

Parameters

  • cpuEntropyBits number gather additional entropy from a CPU mining algorithm. This will already happen once by default. (optional, default 0)

Examples

ecc.randomKey().then(privateKey => {
console.log('Private Key:\t', privateKey) // wif
console.log('Public Key:\t', ecc.privateToPublic(privateKey)) // EOSkey...
})

Returns Promise<wif>

seedPrivate

Parameters

  • seed string any length string. This is private. The same seed produces the same private key every time. At least 128 random bits should be used to produce a good private key.

Examples

ecc.seedPrivate('secret') === wif

Returns wif

privateToPublic

Parameters

  • wif wif
  • pubkey_prefix string public key prefix (optional, default 'EOS')

Examples

ecc.privateToPublic(wif) === pubkey

Returns pubkey

isValidPublic

Parameters

  • pubkey pubkey like EOSKey..
  • pubkey_prefix string (optional, default 'EOS')

Examples

ecc.isValidPublic(pubkey) === true

Returns boolean valid

isValidPrivate

Parameters

Examples

ecc.isValidPrivate(wif) === true

Returns boolean valid

sign

Create a signature using data or a hash.

Parameters

  • data (string | Buffer)
  • privateKey (wif | PrivateKey)
  • encoding String data encoding (if string) (optional, default 'utf8')

Examples

ecc.sign('I am alive', wif)

Returns string string signature

signHash

Parameters

  • dataSha256 (String | Buffer) sha256 hash 32 byte buffer or string
  • privateKey (wif | PrivateKey)
  • encoding String dataSha256 encoding (if string) (optional, default 'hex')

Returns string string signature

verify

Verify signed data.

Parameters

  • signature (string | Buffer) buffer or hex string
  • data (string | Buffer)
  • pubkey (pubkey | PublicKey)
  • encoding (optional, default 'utf8')
  • hashData boolean sha256 hash data before verify (optional, default true)

Examples

ecc.verify(signature, 'I am alive', pubkey) === true

Returns boolean

recover

Recover the public key used to create the signature.

Parameters

  • signature (String | Buffer) (EOSbase58sig.., Hex, Buffer)
  • data (String | Buffer) full data
  • encoding String data encoding (if data is a string) (optional, default 'utf8')

Examples

ecc.recover(signature, 'I am alive') === pubkey

Returns pubkey

recoverHash

Parameters

  • signature (String | Buffer) (EOSbase58sig.., Hex, Buffer)
  • dataSha256 (String | Buffer) sha256 hash 32 byte buffer or hex string
  • encoding String dataSha256 encoding (if dataSha256 is a string) (optional, default 'hex')

Returns PublicKey

sha256

Parameters

  • data (string | Buffer) always binary, you may need Buffer.from(data, 'hex')
  • resultEncoding (optional, default 'hex')
  • encoding string result encoding 'hex', 'binary' or 'base64' (optional, default 'hex')

Examples

ecc.sha256('hashme') === '02208b..'
ecc.sha256(Buffer.from('02208b', 'hex')) === '29a23..'

Returns (string | Buffer) Buffer when encoding is null, or string

pubkey

EOSKey..

Type: string

Usage (Object API)

let {PrivateKey, PublicKey, Signature, Aes, key_utils, config} = require('eosjs-ecc')

// Create a new random private key
let privateWif
PrivateKey.randomKey().then(privateKey => privateWif = privateKey.toWif())

// Convert to a public key
pubkey = PrivateKey.fromString(privateWif).toPublic().toString()

Browser

git clone https://github.com/EOSIO/eosjs-ecc.git
cd eosjs-ecc
yarn
yarn build_browser
# builds: ./dist/eosjs-ecc.js
# Verify release hash
<script src=eosjs-ecc.js></script>
var ecc = eosjs_ecc

ecc.randomKey().then(privateWif =>  {
  var pubkey = ecc.privateToPublic(privateWif)
  console.log(pubkey)
})

More Repositories

1

eos

An open source smart contract platform
C++
11,274
star
2

Documentation

EOSIO Documents
2,084
star
3

eosjs

General purpose library for the EOSIO blockchain.
TypeScript
1,436
star
4

eosio.cdt

EOSIO.CDT (Contract Development Toolkit) is a suite of tools used to build EOSIO contracts
C++
511
star
5

eosio.contracts

Smart contracts that provide some of the basic functions of the EOSIO blockchain
C++
323
star
6

demux-js

💫 Deterministic event-sourced state and side effect handling for blockchain applications
TypeScript
306
star
7

eos-token-distribution

Shell
196
star
8

eos-vm

A Low-Latency, High Performance and Extensible WebAssembly Backend Library
C++
193
star
9

eosjs-api

Application programming interface to EOS blockchain nodes.
JavaScript
178
star
10

eosio-card-game-repo

The Elemental Battles Tutorial is divided into easy to follow lessons that take you through the process of creating your own fully-functional blockchain-based dApp.
158
star
11

eosio-web-ide

eosio-web-ide
TypeScript
151
star
12

eosio-project-boilerplate-simple

This repository demonstrates the eosio platform running a blockchain as a local single node test net with a simple DApp, NoteChain.
Shell
141
star
13

universal-authenticator-library

A library for allowing apps to easily use different auth providers.
TypeScript
127
star
14

eosio-java

EOSIO SDK for Java - API for integrating with EOSIO-based blockchains
Java
125
star
15

eosio-explorer

An application providing Web GUI to communicate with EOSIO blockchain in a local development environment.
JavaScript
115
star
16

eosio-project-demux-example

Simple Blog DApp built with Demux and React for the EOSIO Blockchain
JavaScript
89
star
17

eosjs-keygen

Javascript keys generator for EOS
JavaScript
72
star
18

history-tools

EOSIO History Tools
C++
65
star
19

eosio-reference-ios-authenticator-app

iOS reference app demonstrating inter-application transaction signing for EOSIO blockchain apps
Swift
65
star
20

eosio-swift

EOSIO SDK for Swift - API for integrating with EOSIO-based blockchains
C
61
star
21

patroneos

RPC Checkpoint for EOS nodes
Go
47
star
22

ricardian-template-toolkit

Renderer for the Ricardian Contract specification
TypeScript
41
star
23

spec-repo

EOSIO Specifications Repository
40
star
24

demux-js-eos

Demux-js Action Reader implementations for EOSIO blockchains
TypeScript
38
star
25

fc

C++
38
star
26

eosio-webauthn-example-app

Example web app demonstrating EOSIO signing via WebAuthn
TypeScript
38
star
27

welcome

Documentation that covers EOSIO Overview, Getting Started and Protocol documents
C++
38
star
28

abieos

Binary <> JSON conversion using ABIs. Compatible with languages which can interface to C
C++
34
star
29

eosio-java-android-example-app

Application demonstrating integration with EOSIO-based blockchains using EOSIO SDK for Java
Java
32
star
30

eosio-swift-ios-example-app

Application demonstrating integration with EOSIO-based blockchains using EOSIO SDK for Swift
Swift
30
star
31

eosjs-json

Information about the EOS blockchain in the JSON file format.
JavaScript
28
star
32

eosio-reference-chrome-extension-authenticator-app

Chrome extension reference app demonstrating how users could sign transactions using various EOSIO Labs tools
TypeScript
25
star
33

ual-token-pocket

authenticator meant to be used with Token Pocket and the Universal Authenticator Library
TypeScript
24
star
34

ricardian-spec

Specification defining valid Ricardian contracts
23
star
35

ual-reactjs-renderer

This library provides a React renderer around the Universal Authenticator Library
JavaScript
23
star
36

tropical-example-web-app

An example for developers showing an application built on EOSIO combining UAL, Manifest Spec, and Ricardian Contracts
JavaScript
22
star
37

eosio.exchange

C++
21
star
38

eosjs-secp256k1

Compiles c++ secp256k1 pedersen commitments, borromean ring signatures, and ZK range proofs into JavaScript.
JavaScript
17
star
39

hackathon-howto-guide

Getting started guide for EOS Global Hackathon series
16
star
40

musl

Mirror of git://git.musl-libc.org/musl
C
14
star
41

eosio-toppings

A monorepo with tools working on top of nodeos
TSQL
14
star
42

ual-scatter

authenticator meant to be used with Scatter and Universal Authenticator Library
TypeScript
14
star
43

ual-authenticator-walkthrough

tutorial walking through the steps required to create a new authenticator for the Universal Authenticator Library
JavaScript
13
star
44

EEPs

EOSIO Enhancement Proposals
13
star
45

eosio-swift-vault

Utility library for managing keys and signing with Apple's Keychain and Secure Enclave
Swift
12
star
46

eosio.assert

A security feature to reduce the need for users to trust blockchain apps when a user signs a transaction for a trusted blockchain network with a trusted wallet application
C++
12
star
47

eosio-java-softkey-signature-provider

Example pluggable signature provider for EOSIO SDK for Java for signing transactions using in-memory keys
Java
12
star
48

eosio.forum

C++
12
star
49

eosio-swift-ecc

Swift utilities for working with keys, cryptographic signatures, encryption/decryption, etc.
Swift
11
star
50

key-value-example-app

An example app for using the key value database feature new to 2.1 of EOSIO.
TypeScript
11
star
51

eosio-java-android-abieos-serialization-provider

Pluggable serialization provider for EOSIO SDK for Java using ABIEOS
Java
11
star
52

eosio-authentication-transport-protocol-spec

EOSIO authentication transport protocol specification for consistent request-response lifecycle
10
star
53

ual-plainjs-renderer

library providers a Plain JS renderer around the Universal Authenticator Library
TypeScript
10
star
54

eosio-wasm-spec-tests

Repo for holding the generated wasm spec tests, as well as the generator
C++
10
star
55

demux-js-postgres

Demux-js Action Handler implementation for Postgres databases
TypeScript
10
star
56

eosjs-ledger-signature-provider

EOSJS Ledger Signature Provider Interface
TypeScript
10
star
57

demux-cli

CLI tool for starting, developing, and interacting with demux-js projects.
JavaScript
10
star
58

mojey

Swift
9
star
59

tutorials

Tutorials, examples and how-tos for EOS.IO
9
star
60

eosio.system

Reference system contract for an EOSIO based chain
C++
9
star
61

eosio-java-android-rpc-provider

Pluggable RPC provider for EOSIO SDK for Java
Java
9
star
62

manifest-spec

A specification detailing how EOSIO-enabled applications comply with the application manifest requirements of EOSIO-compatible user agents
9
star
63

eosio-android-keystore-signature-provider

Pluggable signature provider for EOSIO SDK for Java using Android's Keystore
Kotlin
9
star
64

vt-blockchain-bootcamp-starter

JavaScript
8
star
65

homebrew-eosio

homebrew tap for EOSIO
Shell
8
star
66

ual-eosio-reference-authenticator

Authenticator meant for use with EOSIO Reference Authenticator Apps and the Universal Authenticator Library
TypeScript
7
star
67

eosio.helm

Helm charts for EOSIO.
Shell
6
star
68

return-values-example-app

An example app for using the action return value feature new to 2.1 of EOSIO.
Shell
6
star
69

training-EED101

C++
6
star
70

eosio-swift-reference-ios-authenticator-signature-provider

A pluggable signature provider for EOSIO SDK for Swift for signing transactions with EOSIO Reference iOS Authenticator App
Swift
6
star
71

test-state-history

JavaScript
5
star
72

eosio-java-rpc-provider

Pluggable RPC provider for EOSIO SDK for Java
Java
5
star
73

eosio-java-abieos-serialization-provider

Java version of the ABIEOS Serialization Provider
Java
5
star
74

ual-ledger

authenticator meant to be used with Ledger and the Universal Authenticator Library
TypeScript
5
star
75

ual-lynx

authenticator meant to be used with Lynx and Universal Authenticator Library
TypeScript
5
star
76

taurus-node

EOSIO-Taurus - The Most Powerful Infrastructure for Decentralized Applications
C++
4
star
77

eosio-swift-abieos-serialization-provider

Pluggable serialization provider for EOSIO SDK for Swift using ABIEOS
C++
4
star
78

eosio.token

Reference contract for an EOSIO based token
C++
4
star
79

eosio-swift-vault-signature-provider

Pluggable signature provider for EOSIO SDK for Swift using Apple's Keychain or Secure Enclave
Swift
4
star
80

history-tools-docs

history-tools migrated docs for dev portal consumption
3
star
81

eosjs-ios-browser-signature-provider-interface

a Signature Provider Interface for communicating with an authenticator from iOS Safari using the EOSIO Authentication Transport Protocol Specification
TypeScript
3
star
82

chain-kv

key-value storage for blockchains
C++
3
star
83

eosio-swift-softkey-signature-provider

Example pluggable signature provider for EOSIO SDK for Swift for signing transactions using in-memory keys
Swift
3
star
84

eosjs-window-message-signature-provider-interface

A Signature Provider Interface for communicating with an authenticator over the Window Messaging API using the EOSIO Authentication Transport Protocol Spec.
TypeScript
3
star
85

eosjs-signature-provider-interface

An abstract class that implements the EOSJS SignatureProvider interface, and provides helper methods for interacting with an authenticator using the EOSIO Authentication Transport Protocol Specification.
TypeScript
3
star
86

homebrew-eosio.cdt

homebrew tap for eosio.cdt
Ruby
2
star
87

training-tictactoe

Bootstrap for certain training courses
C++
2
star
88

auto-request-generator

Python
2
star
89

eos-vm-test-wasms

Binary wasms for testing eos-vm.
1
star
90

taurus-zpp-bits

C++
1
star