Hyperledger Fabric SDK Nodejs

SDK能做什么

  • 创建通道
  • 邀请peer节点加入通道
  • 在peer节点上安装智能合约
  • 在通道上实例化合约
  • 调用合约执行交易
  • 交易查询,区块查询

fabric上的安全性是用数字证书来保证的的。所有fabric中的操作要求必须由CA证书。

Node.js SDK的功能

Hyperledger Fabric SDK是以面向对象的编程风格进行设计。其模块化结构使应用程序开发人员能够对关键功能实现可插拔的替代实现,例如加密模块,状态存储模块和日志模块。
SDK的功能列表包括:

  • fabric-client

    • 创建一个新的通道(channel)
     //加载配置 可以传json对象或者json文件的路径
     loadFromConfig(config) 
    
     addTlsClientCertAndKey(opts)
    
     //创建channel 返回一个promise
     //参数类型 ChannelRequest
     ![image.png](https://upload-images.jianshu.io/upload_images/5659111-b8fb4a5a46e7842c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
     createChannel(request)
      
    //创建User 参数类型UserOpts  返回promise
    ![image.png](https://upload-images.jianshu.io/upload_images/5659111-02aa7111abac01ca.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
     createUser(opts) 
    
     extractChannelConfig(config_envelope)
    
     getCertificateAuthority(name)
      
     getChannel(name, throwError)
     ![image.png](https://upload-images.jianshu.io/upload_images/5659111-b81d7f0755cb7d5f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    
     getClientConfig()
    
     getCryptoSuite()
    
     getEventHub(peer_name)
    
     getEventHubsForOrg(org_name)
    
     getMspid()
    
     getOrderer(name)
    
     getPeer(name)
    
     getPeersForOrg(org_name)
    
     getStateStore()
    
     getUserContext(name, checkPersistence)
    
     initCredentialStores()
    
     installChaincode(request, timeout)
     ![image.png](https://upload-images.jianshu.io/upload_images/5659111-dafc384213581ff6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
      
     isDevMode()
    
     loadFromConfig(config)
     
     loadUserFromStateStore(name)
    
     newChannel(name)
    
     newEventHub()
      
     newOrderer(url, opts)
    
     newPeer(url, opts)
    
     newTransactionID(admin)
    
     queryChannels(peer, useAdmin)
    
     queryInstalledChaincodes(peer, useAdmin)
    
     saveUserToStateStore()
      
     setAdminSigningIdentity(private_key, certificate, mspid)
    
     setCryptoSuite(cryptoSuite)
    
     setDevMode(devMode)
    
     setStateStore(keyValueStore)
    
     setTlsClientCertAndKey(clientCert, clientKey)
    
     setUserContext(user, skipPersistence)
    
     signChannelConfig(config)
    
     updateChannel(request)
    
    • 在channel加入节点
    addOrderer(orderer)
    
    addPeer(peer, roles)
    
    close()
    
    compareProposalResponseResults(The)
    
    executeTransaction(request)
    
    getChannelConfig(target)
    
    getChannelConfigFromOrderer()
    
    getChannelEventHub(name)
    
    getChannelEventHubsForOrg(org_name)
    
    getChannelPeer(name)
    
    getGenesisBlock(request)
    
    getMSPManager()
    
    getName()
    
    getOrderer(name)
    
    getOrderers()
    
    getOrganizations()
    
    getPeer(name)
    
    getPeers()
    
    getPeersForOrg(org_name)
    
    initialize(config)
    
    joinChannel(request, timeout)
    
    newChannelEventHub(peer)
    
    queryBlock(blockNumber, target, useAdmin)
    
    queryBlockByHash(block, target, useAdmin)
    
    queryBlockByTxID(tx_id, target, useAdmin)
    
    queryByChaincode(request)
    
    queryInfo(target, useAdmin)
    
    queryInstantiatedChaincodes(target, useAdmin)
    
    queryTransaction(tx_id, target, useAdmin)
    
    removeOrderer(orderer)
    
    removePeer(peer)
    
    sendInstantiateProposal(request, timeout)
    
    sendTransaction(request)
    
    sendTransactionProposal(request, timeout)
    
    sendUpgradeProposal(request, timeout)
    
    setMSPManager(msp_manager)
    
    toString()
    
    verifyProposalResponse(proposal_response)
    
    • 安装智能合约
    installChaincode(request, timeout)
    
    • 初始化智能合约
    sendInstantiateProposal(request, timeout)//
    
    sendTransaction(request) //https://fabric-sdk-node.github.io/Channel.html#sendInstantiateProposal
    
    • 提交交易
     sendTransactionProposal(request, timeout)//https://fabric-sdk-node.github.io/Channel.html#sendTransactionProposal
    
     sendTransaction(request)//https://fabric-sdk-node.github.io/Channel.html#sendTransaction
    
    • 查询合约
     queryByChaincode(request)
    
    • 各种查询功能:
      • 区块高度
       queryInfo(target, useAdmin)
      
      • 通过区块I区块D和区块哈希查询
      queryBlock(blockNumber, target, useAdmin)//https://fabric-sdk-node.github.io/Channel.html#queryBlock
      queryBlockByTxID(tx_id, target, useAdmin)//https://fabric-sdk-node.github.io/Channel.html#queryBlockByHash
      
      • 查询一个peer节点隶属的所有通道
      queryChannels(peer, useAdmin)
      
      • 查询一个peer节点上安装的所有智能合约
      queryInstalledChaincodes(peer, useAdmin)
      
      • 查询一个通道中的所有智能合约
      queryInstantiatedChaincodes(target, useAdmin)
      
      • 通过ID来查询交易
      queryTransaction(tx_id, target, useAdmin)
      
      • 查询通道的配置
      getChannelConfig(target)
      
    • 事件:
      • 连接一个peer节点的事件流
      connect()
      
      • 监听区块事件
      registerBlockEvent(onEvent, onError)
      
      • 监听交易事件(并查明交易是否成功提交给账本或标记为无效)
      registerTxEvent(txid, onEvent, onError)
      
      • 监听合约上自定义事件
      registerChaincodeEvent(ccid, eventname, onEvent, onError)
      
    • User对象序列化 签名
      fromString()
      getAffiliation()
      getCryptoSuite()
      getIdentity()
      getName()
      getRoles()
      getSigningIdentity()
      isEnrolled()
      setAffiliation(affiliation)
      setEnrollment(privateKey, certificate, mspId)
      setRoles(roles)
      toString()
      
    • 多种配置引入方式:文件、环境变量、程序参数、内存设置
    • 内置日志模块(winston),可以使用log4js和bunyan等其他日志模块替换
    • 可插拔的CryptoSuite接口描述与Fabric成功交互所需的加密操作。提供两种实现方式:
      • Software-based ECDSA
      • PKCS#11-compliant ECDSA
    • 可插拔的状态存储接口,用于保存诸如用户的状态缓存
      • 文件存储
      • CouchDB
    • 可自定义的加密
    • 同时支持TLS(grpcs://)或非TLS(grpc://)连接到peer和orderer,请参阅Remote,它是同级和订购者的超类
    //https://fabric-sdk-node.github.io/Remote.html
    
    //https://fabric-sdk-node.github.io/Orderer.html
    
    //https://fabric-sdk-node.github.io/Peer.html
    
    //https://fabric-sdk-node.github.io/Orderer.html
    
    
  • fabric-ca-client

    • 注册用户
    • 获取CA证书
    • 吊销证书
    • 证书持久化存储

你可能感兴趣的:(Hyperledger Fabric SDK Nodejs)