GithubHelp home page GithubHelp logo

zsw-crypto-gm's Introduction

NPM Build Status

中数文加密代码库

使用方式:

import ecc from 'zsw-crypto-gm'
// or
const ecc = require('zsw-crypto-gm')

Include

  • Install with: yarn add zsw-crypto-gm
  • Html script tag, see releases for the correct version and its matching script integrity hash.

Common API

Table of Contents

wif

Wallet Import Format

Type: string

pubkey

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)) 
})

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 'ZSW')

Examples

ecc.privateToPublic(wif) === pubkey

Returns pubkey

isValidPublic

Parameters

  • pubkey pubkey
  • pubkey_prefix string (optional, default 'ZSW')

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) (ZSWbase58sig.., 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) (ZSWbase58sig.., 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

Usage (Object API)

let {PrivateKey, PublicKey, Signature, Aes, key_utils, config} = require('zsw-crypto-gm')

// 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/zhongshuwen/zsw-crypto-gm.git
cd zsw-crypto-gm
yarn
yarn build_browser
# builds: ./dist/zsw-crypto-gm.js
# Verify release hash
<script src=zsw-crypto-gm.js></script>
var ecc = zsw_crypto

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

zsw-crypto-gm's People

Contributors

cf avatar

Stargazers

 avatar

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.