Quick look into DECENT
The new way of publishing
Our intention is to revolutionize digital distribution across the Internet.
DCore Network is a content distribution platform that is decentralized, open-source and uses Blockchain technology. Blockchain technology guarantees trust and security by embedding encryption at the lowest level. Perhaps the greatest benefit of this implementation of blockchain technology is invariant storage for published content which can eliminate manipulation and influence by any sort of middleman (eg. publisher). In short content can now be created and delivered directly with any fees collected solely by the seller at the point of sale. In addition to the technological side, there are the economical and social protocols that will govern real-world interactions across the network. In order to make transactions viable and user friendly a crypto-token, the DCT, has been implemented. The encrypted DCT tokens help mitigate attacks, promote funding and ensure transaction validation. One last thing of note, unlike other content distribution platforms underdevelopment, there are virtually no limitations as to the type of media that can be published on Dcore Network. It could be songs, books, articles, videos, source code, or anything really and in almost any format.
dcorejs
Javascript library for browser and node.js to work with Dcore blockchain network. Supported browsers versions:
- Chrome - > 54
- Firefox - > 58
- Safari - > 11
- Edge - > 41
Quick start
Installation
-
Install
Node.js >6
andnpm >3
globally -
For Windows you need to install node-gyp build tool.
-
Change directory to project root dir
-
Install
npm install dcorejs
### Customization
In case you want to customize library and generate documentation for code use command npm run generate-docs
.
Documentation will be generated in ./dist/docs
folder.
Initialize library
Server
; ; dcorejs.initializeconfig;
NOTE: If running server from localhost add NODE_TLS_REJECT_UNAUTHORIZED=0
before library initialization.
If you want debug logs during development, before running your application set ENVIRONMENT
variable to DEV
. For websocket debug logs
set WS_ENV
variable to DEV
.
Browser
NOTE: Use testConnection = false
if CORS problem appear.
Replace dcoreNetworkWSPaths
with active dcore daemon instance and chainId
with blockchain id which
you are about to work on.
Usage
Once dcore lib is initialized, you can access methods using dcorejs
with any of submodule - account()
, asset()
, content()
, explorer()
, messaging()
, mining()
, proposal()
, seeding()
or subscription()
Connection control
Library dcorejs offer methods to control connection.
; ; // ... connection.closeConnection; // ... connection.openConnection .then
Create account
There is two ways how to create account in DCore network: Account.registerAccount
and Account.createAccountWithBrainkey
.
Recomended way to create account is using Account.registerAccount
method, because there is option to set keys to be different.
Also can use Account.createAccountWithBrainkey
, but keys generated from brainkey for ownerKey, activeKey and memoKey will be the same, which is not recommended for security reasons.
;; ;;// owner key is generated with sequenceNumber = 0;;;; dcorejs.account.registerAccount 'myNewAccountName', publicOwnerKey.stringKey, publicActiveKey.stringKey, publicMemoKey.stringKey, accountId, registrarPrivateKey .then .catch;
NOTE: Make sure, that sequenceNumber
you generating keys with, was not used for generating keys for your accounts in past.
Submit content
; ;dcorejs.content.generateContentKeysseederIds .then .catch
Example shown above is for case when content is already uploaded to seeders using DCore IPFS
node.
It is also possible to submit content uploaded to different storage (e.g. CDN). Then
omit parameters seeders
and keyParts
, and use empty arrays instead.
Note following:
-
Each newly submitted content must have unique
URI
. -
If submitting content with same
URI
, then parametershash
,author
,date
,seeders
andkeyParts
must stay same. All other data are updated. -
Hash needs to be RIPEMD-160, and can be generated using
dcorejs.Utils.ripemdHash()
method -
Synopsis need to contain at least parameters
title
,description
andcontent_type_id
.content_type_id
is composed of'<app_id>.<category>.<sub_category>.<is_adult_content>'
, for example1.1.2.0
.
Search content
; ;;;;;;; dcorejs.content.searchContentsearchParams .then .catch;
Replace all variables with your values to get requested content. Search browser example
Buy content
; ;;;; dcorejs.content .buyContentcontentId, accountId, elGammalPublic, privateKey .then .catch;
Replace variables with keys from your dcore account to buy content. Otherwise you will not be able to buy content. Private key must be in WIF(Wallet Import Format). Buy browser example
Download/Restore content
Method restoreContentKeys
will restore your key generated during content submission, used to encrypt content.
; ;;;;; // Content key restorationdcorejs.content.restoreContentKeyscontentId, accountId, elGamalKeyPair .then .catch;
Blockchain event handling
dcorejs.subscribe.then; dcorejs.subscribePendingTransaction.then; dcorejs.subscribeBlockApplied.then;
Custom transaction
In case you want to create custom transaction, see following example. Replace 'X' values and private key for your own.
; ;;;;if result === '' else
More examples available here.
To run examples, you need to clone repository and build with npm run build
if folders dist
and lib
is not presented. Browser bundle can be found
within dist/dcorejs.umd.js
. Node version in lib/dcorejs.js
.
All available methods
dcorejs
subscribecallback: ChainSubscriptionCallbacksubscribeBlockAppliedcallback: ChainSubscriptionBlockAppliedCallback subscribePendingTransactioncallback: ChainSubscriptionCallback content: ContentModule account: AccountModule explorer: ExplorerModule asset: AssetModule mining: MiningModule subscription: SubscriptionModule seeding: SeedingModule proposal: ProposalModule messaging: MessagingModule transactionBuilder: TransactionBuilder connection: ApiConnector
Content
searchContentsearchParams?: SearchParams, convertAsset: boolean = false: Promise<Content>getContentid: string, convertAsset: boolean = false: Promise<ContentObject>getContentURIURI: string, convertAsset: boolean = false: Promise<ContentObject | null>removeContentcontentId: string, authorId: string, privateKey: string, broadcast: boolean = true: Promise<Operation>restoreContentKeyscontentId: string, accountId: string, ...elGamalKeys: KeyPair: Promise<string>generateContentKeysseeders: string: Promise<ContentKeys>addContentcontent: SubmitObject, privateKey: string, broadcast: boolean = true: Promise<Operation>getOpenBuyingconvertAsset: boolean = false: Promise<BuyingContent>getOpenBuyingByURIURI: string, convertAsset: boolean = false: Promise<BuyingContent>getOpenBuyingByConsumeraccountId: string, convertAsset: boolean = false: Promise<BuyingContent>getBuyingByConsumerURIaccountId: string, URI: string, convertAsset: boolean = false: Promise<BuyingContent | null>getBuyingHistoryObjectsByConsumeraccountId: string, convertAsset: boolean = false: Promise<BuyingContent>buyContentcontentId: string, buyerId: string, elGammalPub: string, privateKey: string, broadcast: boolean = true: Promise<Operation>getSeedersresultSize: number = 100: Promise<Seeder>getPurchasedContentaccountId: string, order: SearchParamsOrder = SearchParamsOrder.createdDesc, startObjectId: string = '0.0.0', term: string = '', resultSize: number = 100: Promise<Content>getRatingcontentId: string, forUser: string, ratingStartId: string = '', count: number = 100: Promise<Array<BuyingContent>>searchFeedbackaccountId: string, contentURI: string, ratingStartId: string, count: number = 100: Promise<Array<BuyingContent>>getAuthorCoAuthorsURI: string: Promise< | null>leaveCommentAndRatingcontentURI: string, consumer: string, comment: string, rating: number, consumerPKey: string, broadcast: boolean = true: Promise<Operation>
Account
getAccountByNamename: string: Promise<Account>getAccountByIdid: string: Promise<Account>getTransactionHistoryaccountId: string, privateKeys: string = , order: SearchAccountHistoryOrder = SearchAccountHistoryOrder.timeDesc, startObjectId: string = '0.0.0', resultLimit: number = 100: Promise<TransactionRecord>searchAccountHistoryaccountId: string, privateKeys: string = , order: SearchAccountHistoryOrder = SearchAccountHistoryOrder.timeDesc, startObjectId: string = '0.0.0', resultLimit: number = 100, convertAssets: boolean = false: Promise<TransactionRecord>transferamount: number, assetId: string, fromAccount: string, toAccount: string, memo: string, privateKey: string, broadcast: boolean = true: Promise<Operation>getBalanceaccountId: string, assetId: string = '1.3.0', convertAsset: boolean = false: Promise<number>isTransactionConfirmedaccountId: string, transactionId: string: Promise<boolean>getAccountHistoryaccountId: string, historyOptions?: HistoryOptions: Promise<HistoryRecord>searchAccountssearchTerm: string = '', order: AccountOrder = AccountOrder.none, id: string = '0.0.0', limit: number = 100: Promise<Account>getAccountCount: Promise<number>registerAccountname: string, ownerKey: string, activeKey: string, memoKey: string, registrar: string, registrarPrivateKey: string, broadcast: boolean = true: Promise<Operation>createAccountWithBrainkeybrainkey: string, accountName: string, registrar: string, registrarPrivateKey: string: Promise<Operation>listAccountslowerBound: string = '', limit: number = 100: Promise<AccountNameIdPair>listAccountBalancesid: string, convertAssets: boolean = false: Promise<Asset>searchMinerVotingaccountName: string, keyword: string, myVotes: boolean = true, sort: MinerOrder = MinerOrder.none, fromMinerId: string = '', limit: number = 1000: Promise<MinerInfo>updateAccountaccountId: string, params: UpdateAccountParameters, privateKey: string, broadcast: boolean = true: Promise<Operation>searchAccountBalanceHistoryaccountId: string, assetList: string = , partnerId: string = null, fromBlockNumber: number = null, toBlockNumber: number = null, offset: number = 0, limit: number = 100: Promise<HistoryBalanceObject>getAccountBalanceForTransactionaccountId: string, historyId: string: Promise<HistoryBalanceObject>getTransactionByIdtransactionId: string: Promise<any>
Asset
listAssetslowerBoundSymbol: string, limit: number = 100, UIAOnly: boolean = false, formatAssets: boolean = false: Promise<AssetObject>createUserIssuedAssetissuer: string, symbol: string, precision: number, description: string, maxSupply: number, baseExchangeAmount: number, quoteExchangeAmount: number, isExchangeable: boolean, isSupplyFixed: boolean, issuerPrivateKey: string, broadcast: boolean = true: Promise<Operation>issueAssetassetSymbol: string, amount: number, issueToAccount: string, memo: string, issuerPKey: string, broadcast: boolean = true: Promise<Operation>updateUserIssuedAssetsymbol: string, newInfo: UserIssuedAssetInfo, issuerPKey: string, broadcast: boolean = true: Promise<Operation>fundAssetPoolsfromAccountId: string, uiaAmount: number, uiaSymbol: string, dctAmount: number, privateKey: string, broadcast: boolean = true: Promise<Operation>assetReservepayer: string, symbol: string, amountToReserve: number, privateKey: string, broadcast: boolean = true: Promise<Operation>assetClaimFeesissuer: string, uiaAmount: number, uiaSymbol: string, dctAmount: number, privateKey: string, broadcast: boolean = true: Promise<Operation>getAssetassetId: string, formatAsset: boolean = false: Promise<DCoreAssetObject>getAssetsassetIds: string, formatAssets: boolean = false: Promise<DCoreAssetObject>priceToDCTsymbol: string, amount: number: Promise<Asset>publishAssetFeedpublishingAccount: string, symbol: string, exchangeBaseAmount: number, exchangeQuoteAmount: number, privateKey: string, broadcast: boolean = true: Promise<Operation>getFeedsByMinerminerAccountId: string, limit: number = 100: Promise<any>getRealSupply: Promise<RealSupply>getMonitoredAssetDataassetId: string: Promise<MonitoredAssetOptions | null>createMonitoredAssetissuer: string, symbol: string, precision: number, description: string, feedLifetimeSec: number, minimumFeeds: number, issuerPrivateKey: string, broadcast: boolean = true: Promise<Operation>updateMonitoredAssetsymbol: string, description: string, feedLifetimeSec: number, minimumFeeds: number, privateKey: string, broadcast: boolean = true: Promise<Operation>
Explorer
getObjectobjectId: string: Promise<any>getAccountid: string: Promise<Account>getAssetid: string: Promise<Block.Asset>getWitnessid: string: Promise<Block.Miner>getOperationHistoryid: string: Promise<Block.Transaction>getVestingBalanceid: string: Promise<Block.VestingBalance>getAssetDynamicDataTypeid: string: Promise<Block.AssetDynamicProperty>getAccountBalanceid: string: Promise<Block.AccountBalance>getAccountStatisticsid: string: Promise<Block.AccountStatistics>getBlockSummaryid: string: Promise<Block.BlockSummary>getAccountTransactionHistoryid: string: Promise<Block.AccountTransactionHistory>getChainPropertyid: string: Promise<Block.ChainProperty>getMinerScheduleid: string: Promise<Block.MinerSchedule>getBudgetRecordid: string: Promise<Block.BudgetReport>getBuyingid: string: Promise<Block.Buying>getContentid: string: Promise<Block.Content>getPublisherid: string: Promise<Block.Publisher>getSubscriptionid: string: Promise<Block.Subscription>getSeedingStatisticsid: string: Promise<Block.SeedingStatistics>getTransactionDetailid: string: Promise<Block.TransactionDetail>getBlockid: number: Promise<Block.Block>getBlocksid: number, count: number: Promise<Array<Block.Block>>getAccountsids: string: Promise<Array<Account>>getTransactionblockNo: number, txNum: number: Promise<Block.Transaction>getMinersids: string: Promise<Array<Miner>>getMinerid: string: Promise<Miner|null>
Mining
setDesiredMinerCountaccountId: string, desiredNumOfMiners: number, privateKey: string, broadcast: boolean = true: Promise<Operation>createMinerminerAccountId: string, URL: string, signingPublicKey: string, privateKey: string, broadcast: boolean = true: Promise<Operation>unvoteMinerminer: string, account: string, privateKeyWif: string, broadcast: boolean = true: Promise<Operation>unvoteMinersminers: string, account: string, privateKeyWif: string, broadcast: boolean = true: Promise<Operation>voteForMinerminer: string, account: string, privateKeyWif: string, broadcast: boolean = true: Promise<Operation>voteForMinersminers: string, account: string, privateKeyWif: string, broadcast: boolean = true: Promise<Operation>voteUnvoteMinersvoteMiners: string, unvoteMiners: string, accountId: string, privateKey: string, broadcast: boolean = true: Promise<Operation>getVestingBalancesaccountId: string: Promise<VestingBalance>updateMinerminerId: string, minerAccountId: string, updateData: MinerUpdateData, privateKey: string, broadcast: boolean = true: Promise<Operation>withdrawVestingvestinBalanceId: string, ownerId: string, amount: number, assetId: string, privateKey: string, broadcast: boolean = true: Promise<Operation>setVotingProxyaccountId: string, votingAccountId: string, privateKey: string, broadcast: boolean = true: Promise<Operation>listMinersfromId: string, limit: number = 100: Promise<MinerNameIdPair>getMinerminerId: string: Promise<Miner>
Proposal
getProposedTransactionsaccountId: string: Promise<ProposalObject>proposeTransferproposerAccountId: string, fromAccountId: string, toAccountId: string, amount: number, assetId: string, memoKey: string, expiration: string, privateKey: string, broadcast: boolean = true: Promise<Operation>proposeParameterChangeproposerAccountId: string, proposalParameters: ProposalParameters, expiration: string, privateKey: string, broadcast: boolean = true: Promise<Operation>proposeFeeChangeproposerAccountId: string, feesParameters: FeesParameters, expiration: string, privateKey: string, broadcast: boolean = true: Promise<Operation>approveProposalpayingAccountId: string, proposalId: string, approvalsDelta: DeltaParameters, privateKey: string, broadcast: boolean = true: Promise<Operation>
Seeding
listSeedersByPricelimit: number = 100: Promise<Seeder>listSeedersByUploadlimit: number = 100: Promise<Seeder>listSeedersByRegionregion: string: Promise<Seeder>listSeedersByRatinglimit: number = 100: Promise<Seeder>
Subscription
listActiveSubscriptionsByConsumerconsumerId: string, count: number = 100: Promise<SubscriptionObject>
Messaging
getSentMessagessender: string, decryptPrivateKey: string = '', count: number = 100: Promise<IDCoreMessagePayload>getMessagesreceiver: string, decryptPrivateKey: string = '', count: number = 100: Promise<IDCoreMessagePayload>getMessageObjectssender: string = '',sendMessagesender: string, receiverId: string, message: string, privateKey: string, broadcast: boolean = true: Promise<Operation>sendUnencryptedMessagesender: string, receiverId: string, message: string, privateKey: string, broadcast: boolean = true: Promise<Operation>
Utils
formatToReadiblePricedctAmount: number: stringformatAmountForDCTAssetamount: number: numberformatAmountForAssetamount: number, asset: DCoreAssetObject: numberformatAmountToAssetamount: number, asset: DCoreAssetObject: numberripemdHashfromBuffer: string: stringgenerateKeysfromBrainKey: string: getPublicKeyprivateKey: string: KeyPublicprivateKeyFromWifpkWif: string: KeyPrivatepublicKeyFromStringpubKeyString: string: KeyPublicsuggestBrainKey: stringgetBrainKeyInfobrainKey: string: BrainKeyInfonormalizebrainKey: string: stringgenerateNonce: stringelGamalPublicelGamalPrivate: string: stringelGamalPrivateprivateKeyWif: string: stringgenerateElGamalKeysprivateKeyWif: string: ElGamalKeysgenerateBrainKeyElGamalKey: derivePrivateKeybrainKey: string, sequence: number: KeyPrivate
Crypto utils
encryptWithChecksummessage: string, privateKey: string, publicKey: string, nonce: string = '': stringdecryptWithChecksummessage: string, privateKey: string, publicKey: string, nonce: string = '': stringripemdHashfromBuffer: string: stringmd5message: string: stringsha512message: string: stringsha256message: string: stringencryptmessage: string, password: string: stringdecryptmessage: string, password: string: string | nullencryptToHexStringmessage: string | Buffer, password: string: stringdecryptHexStringmessage: string, password: string: string
Transaction builder
addOperationoperation: Operation: voidproposeproposalParameters: ProposalCreateParameters: voidbroadcastprivateKey: string, sign: boolean = true: Promise<void>setTransactionFees: Promise<void>signTransactionprivateKey: KeyPrivate: voidreplaceOperationoperationIndex: number, newOperation: Operation: booleanpreviewTransaction: any