Coder Social home page Coder Social logo

Comments (11)

luckyyang avatar luckyyang commented on August 10, 2024 2
const Address  = require('@nervosnetwork/ckb-sdk-address')

should be:

const Address  = require('@nervosnetwork/ckb-sdk-address').default

The runnable code will be:

const EC = require('elliptic').ec
const Address  = require('@nervosnetwork/ckb-sdk-address').default

const ec = new EC('secp256k1')

const privateKey = ec.genKeyPair()

const address = new Address(privateKey, { prefix: 'ckt' }) // the ckt is the signal for testnet

from ckb-sdk-js.

Keith-CY avatar Keith-CY commented on August 10, 2024

For now, the ckb-sdk-js doesn't expose such API to generate a private key. If it is really necessary, we'd like to add one.

Here is a trick way to get a random private key:

In the project which has installed ckb-sdk-js, an package named elliptic is also installed, you can just run the following script to get one.

const EC = require('elliptic').ec;
const ec = new EC('secp256k1')
const key = ec.genKeyPair()

from ckb-sdk-js.

Keith-CY avatar Keith-CY commented on August 10, 2024

The @nervosnetwork/[email protected] generates addresses for the mainnet by default, it's not handy for the testnet so an improvement has been committed to accept address configuration.

If you are using the @nervosnetwork/[email protected], the @nervosnetwork/[email protected] is already installed, you can use the following script to get the address object

const Address  = require('@nervosnetwork/ckb-sdk-address')
const privateKey = '0x...'
const address = new Address(privateKey, { prefix: 'ckt' }) // the ckt is the signal for testnet

from ckb-sdk-js.

luckyyang avatar luckyyang commented on August 10, 2024

Will try, thanks.

from ckb-sdk-js.

luckyyang avatar luckyyang commented on August 10, 2024

I make it into a repo https://github.com/rebase-network/ckb-wallet-generator
Maybe later we convert it to a web service.

from ckb-sdk-js.

ashchan avatar ashchan commented on August 10, 2024

As an alternative, just use openssl to generate one.

openssl rand 32 -hex

from ckb-sdk-js.

ashchan avatar ashchan commented on August 10, 2024

The @nervosnetwork/[email protected] generates addresses for the mainnet by default, it's not handy for the testnet so an improvement has been committed to accept address configuration.

If you are using the @nervosnetwork/[email protected], the @nervosnetwork/[email protected] is already installed, you can use the following script to get the address object

const Address  = require('@nervosnetwork/ckb-sdk-address')
const privateKey = '0x...'
const address = new Address(privateKey, { prefix: 'ckt' }) // the ckt is the signal for testnet

Please update so it generate testnet address by default.

from ckb-sdk-js.

luckyyang avatar luckyyang commented on August 10, 2024
openssl rand 32 -hex

Yes that's the easiest way

from ckb-sdk-js.

liushooter avatar liushooter commented on August 10, 2024

openssl rand 32 -hex only get private key

from ckb-sdk-js.

ashchan avatar ashchan commented on August 10, 2024

openssl rand 32 -hex only get private key

Yes but public key and address derivation is already supported by the SDK ;-)

from ckb-sdk-js.

Keith-CY avatar Keith-CY commented on August 10, 2024

The @nervosnetwork/[email protected] generates addresses for the mainnet by default, it's not handy for the testnet so an improvement has been committed to accept address configuration.
If you are using the @nervosnetwork/[email protected], the @nervosnetwork/[email protected] is already installed, you can use the following script to get the address object

const Address  = require('@nervosnetwork/ckb-sdk-address')
const privateKey = '0x...'
const address = new Address(privateKey, { prefix: 'ckt' }) // the ckt is the signal for testnet

Please update so it generate testnet address by default.

set ckt as the default prefix of address in #211

from ckb-sdk-js.

Related Issues (20)

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.