Git Product home page Git Product logo

codechain-sdk-js's People

Contributors

foriequal0 avatar hoongee avatar hyunsikjeong avatar joojis avatar junha1 avatar kakao-jun-e avatar kseo avatar majecty avatar remagpie avatar sgkim126 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codechain-sdk-js's Issues

Change parcel constructor params

constructor(nonce: U256, fee: U256, networkId: number, action: Action)

=> constructor({ nonce: U256, fee: U256, networkId: number, action: Action})

Fix semantic error TS4026 while `yarn build`

$ yarn build

yarn run v1.7.0
$ rollup -c rollup.config.ts

src/index.ts → ./lib/index.js...
[!] (rpt2 plugin) Error: /home/sgkim126/workspace/codechain-sdk-js/src/index.ts(231,5): semantic error TS4026 Public static property 'signEcdsa' of exported class has or is using name 'ECDSASignature' from external module

Introduce StandardAssetAgent

StandardAssetAgent is same as PubkeyAssetAgent(#44) except that StandardAssetAgent understands standard scripts but not pubkey script.

Network methods

  • RPC supported
  • Add connect (...)
  • Add disconnect (...)
  • Add shareSecret (...)

Introduce checksumed address

Code base

  • Rename from Address to AccountId
  • Import Bech32

Platform Account Address

  • PlatformAccountAddress primitive
  • SDK.sendCCC = ({ account id, amount }) => Parcel with payment action
  • ...

Asset Transfer Address

  • AssetTransferAddress primitive
  • Asset.transfer = ({address, amount}[]) => AssetTransferTransaction
  • AssetScheme.mint = ({address, amount}) => AssetMintTransaction
  • ...

Split SDK methods into groups

  • rpc
    • node
      • ping
      • getNodeVersion
    • chain
      • sendSignedParcel
      • getParcel
      • getParcelInvoice
      • getRegularKey
      • getTransactionInvoice
      • getBalance
      • getNonce
      • getBestBlockNumber
      • getBestBlockId
      • getBlockHash
      • getBlock
      • getAssetScheme
      • getAsset
      • getPendingParcels
    • network
      • shareSecret
      • connect
  • core
    • createPaymentParcel
    • createSetRegularKeyParcel
    • createChangeShardStateParcel

      Parcel.sign

    • createCreateShardParcel
    • getAssetAgent

      AssetAgent.createAddress

    • createAssetScheme

      AssetScheme.mint

    • createAssetMintTransaction (not implemented)
    • AssetMintTransaction.getMintedAsset (not implemented)

      Asset.transfer

    • createAssetTransferTransaction (not implemented)
    • createAssetTransferInput (not implemented)
    • createAssetTransferOutput (not implemented)
    • AssetTransferTransaction.getOutputAssets (not implemented)
  • util
    • toHex
    • blake256
    • blake256WithKey
    • ripemd160
    • signEcdsa
    • verifyEcdsa
    • recoverEcdsa <- (기존 recoverPublic)
    • generatePrivateKey
    • getAccountIdFromPrivate <- (기존 privateKeyToAddress)
    • getPublicFromPrivate <- (기존 privateKeyToPublic)

Change all of the SDK functions to arrow function

Currently, the below example doesn't work

let sdk = new SDK(...);
let { getBlock, ... } = sdk.rpc.chain;

getBlock("0x123..").then(...)

Because of the function context.

Changing all the functions to the arrow function is one of the solutions.

Add network id to SDK instance.

Current:

new SDK("http://localhost:8080")

Patch:

new SDK({
  url: "http://localhost:8080",
  networkId: 0xCA
})

Currently, the network id in the Parcel or Address are not validated and not auto-filled because of that SDK doesn't know what is decent.

Add optional block number param to getAsset() RPC method

getAsset() gets the asset from the latest state only.
Since asset is a part of the blockchain state, it should be gettable from the specific state.

See getBalance and getNonce which already have the optional block number param.

Introduce PubkeyAssetAgent

PubkeyAssetAgent

  • manages the map(lockScriptHash -> Public Key)
  • understands "PubKey" script (PUSH <pubkey> CHKSIG)

Modify format of serialized transactions

Current foramt is

    "transactions":[{
      "payment":{
        "nonce":"0x1",
        "receiver":"0xa6594b7196808d161b6fb137e781abbc251385d9",
        "sender":"0xa6594b7196808d161b6fb137e781abbc251385d9",
        "value":"0x0"
      }
    }]

Modify it to

    "transactions":[{
      "type": "payment",
      "data":{
        "nonce":"0x1",
        "receiver":"0xa6594b7196808d161b6fb137e781abbc251385d9",
        "sender":"0xa6594b7196808d161b6fb137e781abbc251385d9",
        "value":"0x0"
      }
    }],

Refactor Asset.transfer() to Asset.createTransferTransaction()

Current:

var myAsset = ...
var transferTransaction = myAsset.transfer([{
    address: addressAlice
    amount: 10
}, {
    address: addressBob
    amount: 20
}])

Proposal:

var myAsset = ...
var transferTransaction = myAsset.createTransferTransaction({
    recipients: [{
        address: addressAlice
        amount: 10
    }, {
        address: addressBob
        amount: 20
    }]
})

Renewal SDK interfaces

Currently, the parcel creation could be done by below:

const SDK = require("codechain-sdk");
const { Parcel } = SDK;

const fee = new U256(10);
...
const parcel = new Parcel(fee, nonce, networkId, ...);
parcel.sign(...)
...

But, the current has some issues:

  • Exposing a bunch of classes and using it directly is not natural nor intuitive.
  • SDK could not have contexts such as network id or default value for a fee, etc.

So it needs to be changed with some principles

  • SDK do not expose classes unless it's necessary.
  • Every parameter which has the type of primitive classes(U256, H160) must be substitutable with JS primitive types.

Renewaled:

const SDK = require("codechain-sdk");
const sdk = new SDK({ networkId: 0xCA, ... });

const parcel = sdk.createParcel({ fee: 10, nonce: 10, ... })
parcel.sign(...)
...
  • Add Parcel-related methods
  • Add Address-related methods
  • Do not expose the classes
  • Keep parameter consistency
  • Update examples
  • Improve typedoc readability

Module Splitting #53

Refactor AssetScheme.mint() to AssetScheme.createMintTransaction()

Current:

...
var myAddress = ...
var myAsset = sdk.core.createAsset({ metadata, registrar, amount })
var mintTransaction = myAsset.mint(myAddress)

Proposal:

...
var myAddress = ...
var myAssetScheme = sdk.core.createAssetScheme({ metadata, registrar, amount })
var mintTransaction = myAssetScheme.createMintTransaction({ recipient: myAddress })

Introduce KeyStore

Method

  • getKeyList()
  • createKey(password?) => H512
  • removeKey(password) => void
  • sign({ key, message, password? }) => H520

Until codechain support it, SDK will implement and use SecretStoreMemory which is not persistent.

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.