Git Product home page Git Product logo

dashcore-lib's Introduction

Dashcore Library

NPM Version Build Status Release Date standard-readme compliant

A pure and powerful JavaScript Dash library.

Dash is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Dash network allows for highly resilient Dash infrastructure, and the developer community needs reliable, open-source tools to implement Dash apps and services.

Table of Contents

Install

NodeJS

npm install @dashevo/dashcore-lib

Browser

CDN Standalone

<script src="https://unpkg.com/@dashevo/dashcore-lib"></script>
<script>
  const { PrivateKey } = dashcore;
  const privateKey = new PrivateKey();
  const address = privateKey.toAddress().toString();
  ...
</script>

Building the Browser Bundle

To build a dashcore-lib full bundle for the browser:

npm run build

This will generate a file named dashcore-lib.min.js in the dist/ folder.

Usage

Browser

<script src='./dist/dashcore-lib.min.js' type="text/javascript"></script>
<script>
  const PrivateKey = dashcore.PrivateKey;
  const privateKey = new PrivateKey();
  const address = privateKey.toAddress().toString();
</script>

Modules

Some functionality is implemented as a module that can be installed separately:

Development & Tests

git clone https://github.com/dashevo/dashcore-lib
cd dashcore-lib
npm install

Run all the tests:

npm test

You can also run just the Node.js tests with npm run test:node, just the browser tests with npm run test:browser or run a test coverage report with npm run coverage.

Documentation

Concepts

How To Use

Use Case Examples

Some examples can be found here, below is a list of direct links for some of them.

Contributing

Please send pull requests for bug fixes, code optimization, and ideas for improvement. For more information on how to contribute, please refer to our CONTRIBUTING file.

License

Code released under the MIT license.

Copyright 2013-2017 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.
Copyright 2016-2017 The Dash Foundation, Inc.
Copyright 2017-2020 Dash Core Group, Inc.

dashcore-lib's People

Contributors

alex-werner avatar antouhou avatar bitjson avatar braydonf avatar chjj avatar cofresi avatar dskloet avatar eordano avatar fanatid avatar gabegattis avatar gasteve avatar jawid-h avatar kamuelafranco avatar maraoz avatar markin-io avatar martindale avatar matiu avatar nmarley avatar olalonde avatar pnagurny avatar rubensayshi avatar ryanxcharles avatar schinzelh avatar shumkov avatar snogcel avatar thephez avatar throughnothing avatar trevinhofmann avatar udjinm6 avatar yemel 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  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  avatar  avatar  avatar  avatar  avatar

dashcore-lib's Issues

Can not import dashevo/dashcore-lib library in react native

Steps to Reproduce (for bugs)

  1. Create react native project and run it.
  2. Now, Intsall the dashevo/dashcore-lib and import them.
  3. The error will be displayed in terminal.

Please find the attached screenshot and logs

image

Your Environment

  • Node Version used: 17

Logs:

Error: Unable to resolve module path from /node_modules/bls-signatures/blsjs.js: path could not be found within the project or in these directories:
node_modules

If you are sure the module exists, try these steps:

  1. Clear watchman watches: watchman watch-del-all
  2. Delete node_modules and run yarn install
  3. Reset Metro's cache: yarn start --reset-cache
  4. Remove the cache: rm -rf /tmp/metro-*
    15 |
    16 | var f;f||(f=typeof Module !== 'undefined' ? Module : {});var aa;f.ready=new Promise(function(a){aa=a});var ba={},m;for(m in f)f.hasOwnProperty(m)&&(ba[m]=f[m]);var ca=!1,u=!1,da=!1,ea=!1;ca="object"===typeof window;u="function"===typeof importScripts;da="object"===typeof process&&"object"===typeof process.versions&&"string"===typeof process.versions.node;ea=!ca&&!da&&!u;var w="",fa,ha,ia,ja;

17 | if(da)w=u?require("path").dirname(w)+"/":__dirname+"/",fa=function(a,b){ia||(ia=require("fs"));ja||(ja=require("path"));a=ja.normalize(a);return ia.readFileSync(a,b?null:"utf8")},ha=function(a){a=fa(a,!0);a.buffer||(a=new Uint8Array(a));assert(a.buffer);return a},1<process.argv.length&&process.argv[1].replace(/\/g,"/"),process.argv.slice(2),f.inspect=function(){return"[Emscripten Module object]"};else if(ea)"undefined"!=
| ^
18 | typeof read&&(fa=function(a){return read(a)}),ha=function(a){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(a));a=read(a,"binary");assert("object"===typeof a);return a},"undefined"!==typeof print&&("undefined"===typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!==typeof printErr?printErr:print);else if(ca||u)u?w=self.location.href:document.currentScript&&(w=document.currentScript.src),_scriptDir&&(w=_scriptDir),0!==w.indexOf("blob:")?w=w.substr(0,
19 | w.lastIndexOf("/")+1):w="",fa=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},u&&(ha=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)});var ma=f.print||console.log.bind(console),z=f.printErr||console.warn.bind(console);for(m in ba)ba.hasOwnProperty(m)&&(f[m]=ba[m]);ba=null;var na={"f64-rem":function(a,b){return a%b},"debugger":function(){}},oa;f.wasmBinary&&(oa=f.wasmBinary);
20 | var noExitRuntime;f.noExitRuntime&&(noExitRuntime=f.noExitRuntime);"object"!==typeof WebAssembly&&z("no native wasm support detected");var pa,qa=new WebAssembly.Table({initial:744,maximum:744,element:"anyfunc"}),ra=!1;function assert(a,b){a||x("Assertion failed: "+b)}var sa="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;
at ModuleResolver.resolveDependency (/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:129:15)
at DependencyGraph.resolveDependency (/node_modules/metro/src/node-haste/DependencyGraph.js:288:43)
at Object.resolve (/node_modules/metro/src/lib/transformHelpers.js:129:24)
at resolve (/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
at /node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
at Array.reduce ()
at resolveDependencies (/node_modules/metro/src/DeltaBundler/traverseDependencies.js:411:33)
at processModule (/node_modules/metro/src/DeltaBundler/traverseDependencies.js:140:31)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)
BUNDLE ./index.js

identities.register() throws TypeError: Invalid argument type: script

Current Behavior

When trying to register an identity in the browser, I get the error:

TypeError: Invalid argument type: script
    at h.setScript (output.js:168)
    at new h (output.js:39)
    at d.m._fromObject (input.js:77)
    at d.m (input.js:33)
    at new d (publickeyhash.js:24)
    at transaction.js:448
    at wr (lodash.js:516)
    at Function.cu (lodash.js:9342)
    at O.fromObject (transaction.js:440)
    at new O (transaction.js:60)

What seems to throw is:

/**
 * Set a script from a Script, a buffer or it's String representation.
 * Replace any previously set script
 *
 * @param {Script|Buffer|String} script
 * @return {Output}
 */
Output.prototype.setScript = function(script) {
  if (script instanceof Script) {
    this._scriptBuffer = script.toBuffer();
    this._script = script;
    this._script._isOutput = true;
  } else if (_.isString(script)) {
    this._script = Script.fromString(script);
    this._scriptBuffer = this._script.toBuffer();
    this._script._isOutput = true;
  } else if (bufferUtil.isBuffer(script)) {
    this.setScriptFromBuffer(script);
  } else {
    throw new TypeError('Invalid argument type: script');
  }
  return this;
};

Possible Solution

update dash to pull in the latest dashcore-lib version?

Steps to Reproduce (for bugs)

see console.dashevo.io

Your Environment

[email protected]
├── @dashevo/[email protected] 
├─┬ @dashevo/[email protected]
│ └── @dashevo/[email protected]  deduped
└─┬ [email protected]
  ├─┬ @dashevo/[email protected]
  │ ├─┬ @dashevo/[email protected]
  │ │ └── @dashevo/[email protected] 
  │ ├── @dashevo/[email protected]  deduped
  │ └─┬ @dashevo/[email protected]
  │   └── @dashevo/[email protected]  deduped
  ├── @dashevo/[email protected] 
  ├─┬ @dashevo/[email protected]
  │ └── @dashevo/[email protected]  deduped
  └─┬ @dashevo/[email protected]
    └── @dashevo/[email protected] 

Typescript issues with Transaction.id and new Transaction()

Unfortunately the typescript definitions don't allow transaction.id to work as the test https://github.com/dashevo/dashcore-lib/blob/master/test/transaction/transaction.js#L177 indicates it should.

If you could fix the typescript definition file it would be super useful. =)

If anyone needs a workaround, this works for me:

export async function txHash({
  signed_tx
}: TxHashInput): Promise<TxHashOutput> {
  const tx = new dashcore.Transaction(signed_tx)

  // All this madness because tx.id doesn't work in typescript.
  const littleEndianHashBuffer = tx._getHash()

  var hashBuffer = Buffer.allocUnsafe(littleEndianHashBuffer.length)

  for (var i = 0, j = littleEndianHashBuffer.length - 1; i <= j; ++i, --j) {
    hashBuffer[i] = littleEndianHashBuffer[j]
    hashBuffer[j] = littleEndianHashBuffer[i]
  }

  return {
    tx_hash: hashBuffer.toString("hex")
  };
}

In addition new Transaction() doesn't work either, as it needs the serialized arg passed in. This makes it difficult to build transactions when using typescript. A fix for this would also be fantastic.

TypeError: Address has mismatched network type.

Hello Community!

I forked Dash's code to start a Community project, with learning in mind.

We managed to get all figured out, but this Insight explorer is killing us, and we want to learn basics.

When we start Insight node, it starts ok, we can see explorer website and even blocks with connection.

But if we click on any block or anything else, we get error and all node goes down.

Error that we get on console is

"error: uncaught exception: TypeError: Address has mismatched network type."

error: uncaught exception: TypeError: Address has mismatched network type.
at Function.Address._transformBuffer (/home/rxc/dashcore-node/mynode/node_modules/@dashevo/dashcore-lib/lib/address.js:217:11)
at Function.Address._transformString (/home/rxc/dashcore-node/mynode/node_modules/@dashevo/dashcore-lib/lib/address.js:296:22)
at Address._classifyArguments (/home/rxc/dashcore-node/mynode/node_modules/@dashevo/dashcore-lib/lib/address.js:116:20)
at new Address (/home/rxc/dashcore-node/mynode/node_modules/@dashevo/dashcore-lib/lib/address.js:76:19)
at Object.Address (/home/rxc/dashcore-node/mynode/node_modules/@dashevo/dashcore-lib/lib/address.js:54:12)
at TxController.transformOutput (/home/rxc/dashcore-node/mynode/node_modules/@dashevo/insight-api/lib/transactions.js:183:28)
at Array.map ()
at TxController.transformTransaction (/home/rxc/dashcore-node/mynode/node_modules/@dashevo/insight-api/lib/transactions.js:86:42)
at /home/rxc/dashcore-node/mynode/node_modules/@dashevo/insight-api/lib/transactions.js:280:16
at /home/rxc/dashcore-node/node_modules/async/dist/async.js:4617:26

As i understand that has something with networks.js file, where we define networkMagic to match our network.
File is located at /dashcore-node/mynode/node_modules/@dashevo/dashcore-lib/lib/networks.js

From our source code we have this information

pchMessageStart[0] = 0xd6;
pchMessageStart[1] = 0x93;
pchMessageStart[2] = 0xf3;
pchMessageStart[3] = 0x43;
vAlertPubKey = ParseHex("04e807f1caf222eb75de194e8b83c065c89fbce06b60d0968cdc832bd1ce17ef264362b43df7fd9 7cc7a1a38d69d6b7aab3c16cf7a3a9988fa8816c69a6a3016e1");
nDefaultPort = 23506;
nPruneAfterHeight = 100000;

So we changed networkMagic to 0x4693f343, and p2p port 23506

Should we change anything else from here?

addNetwork({
name: 'livenet',
alias: 'mainnet',
pubkeyhash: 0x4c,
privatekey: 0xcc,
scripthash: 0x10,
xpubkey: 0x488b21e, // 'xpub' (Bitcoin Default)
xprivkey: 0x488ade4, // 'xprv' (Bitcoin Default)
networkMagic: 0xd693f343,
port: 23506,

Our source code chainparams.cpp for reference
https://github.com/Ruxiol/ruxcryptoRXC/blob/master/src/chainparams.cpp

When i read error again, it says TypeError: Address has mismatched network type, could that be problem somewhere else, some other file?

If someone could help us understand we would be grateful

Could this be the problem? if yes, how can i get those values from my source code
pubkeyhash: 0x4c,
privatekey: 0xcc,
scripthash: 0x10,

Rux, Crypto.ba Community

payloadSigSize is incorrect for ProRegTxPayload

At this line if payloadSig is present, payloadSigSize is set to BLS_SIGNATURE_SIZE. However, the payload is signed with the key that corresponds to the collateral outpoint, which can definitely be a non-BLS key. In fact, I am not sure it is possible for this collateral key to be a BLS key at all.

Message.sign is not deterministic?

Implementation showing that sign is not deterministic with the same key/message. Definitely possible I am doing something wrong, but the key and message when I output them are identical, but the signatures change constantly!

export async function signMessage({
  private_blob,
  message,
  network,
  key_id
}: SignMessageInput): Promise<SignMessageOutput> {
  const privateBlob = await kmsDecrypt(private_blob, key_id);
  const privateKey = dashcore.PrivateKey.fromBuffer(Buffer.from(privateBlob, "hex"), dashNetwork({ network }))
  const prefixedMessage = new dashcore.Message(MESSAGE_SIGNING_PREFIX + message);
  const signature = prefixedMessage.sign(privateKey);

  // The private key and prefixedMessage are identical...
  // console.log(privateKey.toString())
  // console.log(prefixedMessage)
  // console.log(signature)  

  return {
    prefixed_message: prefixedMessage.toString(),
    signature: signature
  };
}

Tests that are failing because the signatures are not deterministic.

test("signMessage is deterministic", async () => {
    const message = "The privkey is mightier than the sword";
    const result1 = await dash.signMessage({
      key_id: null,
      message,
      private_blob: privateBlob,
      network: "dash-mainnet"
    });
    const result2 = await dash.signMessage({
      key_id: null,
      message,
      private_blob: privateBlob,
      network: "dash-mainnet"
    });
    expect(result1.signature).toBe(result2.signature);
  });

  test("signMessage is deterministic for testnet", async () => {
    const message = "The privkey is mightier than the sword";
    const result1 = await dash.signMessage({
      key_id: null,
      message,
      private_blob: privateBlob,
      network: "dash-testnet"
    });
    const result2 = await dash.signMessage({
      key_id: null,
      message,
      private_blob: privateBlob,
      network: "dash-testnet"
    });
    expect(result1.signature).toBe(result2.signature);
  });

Second argument must be numeric (maxfeerate) and no longer supports a boolean. To allow a transaction with high fees, set maxfeerate to 0.. Code:-8

"tx": "0100000001256b8b0e9a1bc3c51fbfe3b1ac38566c4aea81ff3226d699f1f426874aaeac9d000000006a473044022072f8d25e3cf3d6e984d38cf75b8732a71039d2a62ee9d60b429a191adbd2a58d0220100d6c7bd0f38b9f764514b63d541416a0e407118a719142334cb4734e9b872b01210229c046f3c4c40c851b330fb9c05a1231e557bcc30bdcb1ee2cbb6be6ae9ab082ffffffff02e1a40800000000001976a9140b43da111c21708bd49cb60ff8fda24358ec1f0b88ac10270000000000001976a91499b1ab02d70e7c6913693e993343749822ed054688ac00000000"

bitcore-lib-dash.min.js does not load in browser

bitcore-lib-dash.js loads in a browser with require('bitcore-lib-dash').

bitcore-lib-dash.min.js seems to have been minified with a bad minifier.

This process seems to result in a working copy, however:

npm install -g bower gulp uglify-js

git clone [email protected]:dashevo/bitcore-lib-dash.git
pushd bitcore-lib-dash
  npm install
  gulp browser
  uglifyjs bitcore-lib-dash.js > bitcore-lib-dash.min.js
popd

I'm able to load that and run code as expected:

// just checking that this library doesn't default to a bad prng:
Math.random = function () { throw new Error("insecure"); };

// loading and testing
var bitcore = require('bitcore-lib-dash')
var privateKey = new bitcore.PrivateKey();
privateKey.toAddress().toString();

Bug in ProUpRegTxPayload, scriptPayout reversed, inputsHash not always reversed

For some reason the scriptPayout in https://github.com/dashevo/dashcore-lib/blob/master/lib/transaction/payload/proupregtxpayload.js gets reversed
ProUpRegTxPayload.fromBuffer = function (rawPayload) { [...] var scriptPayoutSize = payloadBufferReader.readVarintNum(); payload.scriptPayout = payloadBufferReader.read(scriptPayoutSize).reverse().toString('hex');

All other instances of scriptPayout, scriptOutputPayout, etc. are not reversed and ok:
https://github.com/dashevo/dashcore-lib/blob/master/lib/transaction/payload/proregtxpayload.js
https://github.com/dashevo/dashcore-lib/blob/master/lib/transaction/payload/proupservtxpayload.js

The test uses a reversed script hash as well:
https://github.com/dashevo/dashcore-lib/blob/master/test/transaction/payload/proupregtxpayload.js
should be:
scriptPayout: '76a914f25c59be48ee1c4fd3733ecf56f440659f1d6c5088ac',

The inputsHash is also strange, it gets reversed in proupregtxpayload.js and proupservtxpayload.js, but not in proregtxpayload.js and prouprevtxpayload.js (plus the tests are adjusted to make them pass). This makes no sense to me, it should always be reversed to match what uint256 is doing, i.e. little endian encoding. E.g. proTXHash is always reversed and matches how uint256 works.

I also checked https://github.com/dashpay/docs/raw/master/binary/merchants/Integration-Resources-Dash-v0.13.0-Transaction-Types.pdf and the examples provided there won't work with reverse on scripts and non-reverse on inputsHash.

Here are plenty of examples based on the useful tests from here I just wrote for NBitcoin (not pushed upstream yet):
https://github.com/DeltaEngine/NBitcoin/blob/master/NBitcoin.Tests/DashTests.cs
and the basic implementation (not as complete as dashcore-lib or cpp, but works):
https://github.com/DeltaEngine/NBitcoin/blob/master/NBitcoin.Altcoins/Dash.cs

Could provide a fix to dashcore-lib if you don't want to copy+paste my fixes ..
Also quickly checked the dashpay/dash repo and for example inputsHash is always just loaded this way: READWRITE(inputsHash);

Latest commits break browser compatibility

In ab3b46b (Jan 29, 2018) and 1301449 (Feb 8, 2018) bitcore-lib-dash.js works in browsers just fine.

However, commits into master as of d933ac9 (Feb 19, 2018) seem to have broken browser compatibility.

In a browser it complains that the module bitcore-lib-dash cannot be found. I imagine it's due to either a name change of how the module is loaded or a change in the commonjs/requirejs/universal/es6 loader wrapper.

about dash testnet coin

I want some dash testnet coins for testing.But I can't find the faucet.

Can you provide me with a faucet website?

or give me some testnet coins.My testnet addresss: yMJyv7THUv6nYGKmkvo7ZnMowiYfSarn21

thank you very much

docs: confusing error message about storage adapter with no hints to resolution

node_modules/@dashevo/wallet-lib/src/types/Storage/_getDefaultAdapter.js:

11:    logger.warn('Running on a NodeJS env without any specified adapter. Data will not persist.');
  1. This message doesn't mention what this is or where it comes from or how it is to be configured or even that it's a storage adapter that's in question.
  2. There's no link to documentation or description of the name of the argument that was supposed to be passed, so it's quite difficult to figure out what to do.
  3. I don't think there is any documentation whatsoever for this, at least there wasn't when I had to go figure it out a few months ago.

Re: dashpay/platform-tutorials#4 and dashpay/platform-tutorials#7

DIP-20 opcode support

DIP-20 adds/re-enables a number of opcodes as described here. This DIP is implemented in Dash Core 0.17.0 via dashpay/dash#3824 and dashpay/dash#3893.

Expected Behavior

Dashcore-lib will support the opcode changes

Current Behavior

Dashcore-lib does not yet support the opcode changes

Problem with use bitcore-lib-dash in browser

Hello! I have a task create and sign transaction in the browser to spend from a 2-of-2 multisig P2SH address. But, if I install bitcore-lib-dash from npm and use: new bitcore.Transaction().from(utxo, publicKeys, 2) I have error: ripemd160 is not supported.
If I use: bitcore-lib-dash.min.js - bitcore equals empty object.

Maybe I'm doing something wrong?

Bitcore global variable naming conflict

Hello!

Context

I have two libraries in project - dashcore-lib & bitcore-lib.
And bitcore makes version check before it loads.
It looks like it saving version in global variable - global._bitcore = bitcore.version.
Dashcore-lib use this global too.

I think that it should be renamed in dashcore-lib, like it done in litecore-lib

Reproduce code

require('@dashevo/dashcore-lib');
require('bitcore-lib');

Output

node_modules\bitcore-lib\index.js:12
    throw new Error(message);
    ^

Error: More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency.

Endpoints

https://github.com/dashevo/dashcore-lib/blob/d255efb55189dd50ed6b1004a0be7a6c95cb5d13/index.js#L7-L15

https://github.com/dashevo/dashcore-lib/blob/d255efb55189dd50ed6b1004a0be7a6c95cb5d13/test/index.js#L8-L10

Fix genesis bits and possibly other params

Leaving this open as a TODO for now, one thing I've noticed is that the genesis bits value is set for Bitcoin, but not the Dash value: https://github.com/dashevo/dashcore-lib/blob/3a7f3c36ea62e495c137ead9e3013ea5a7aa103f/lib/block/blockheader.js#L12

Other things like our max block size are still legacy: https://github.com/dashevo/dashcore-lib/blob/master/lib/block/block.js#L30

Please keep this open and allow for a full review so that we can get them all at once, instead of just picking off those example values I described ^. I'd like to ensure we have a solid lib which includes all the necessary Dash params, adjusted appropriately from Bitcoin.

Error: Assertion failed on Transaction

Expected Behavior

A Transaction should be created with new Transaction()

Current Behavior

Getting an error due to clash with bitcore-lib, or at least that's our diagnosis so far.

Error: Assertion failed

Mostly wanted to report this as we might not be the only repo facing this issue. Considering bitcore is also a very popular and widely used library

Possible Solution

Updating libraries to see if the clash gets resolved - no luck so far

Steps to Reproduce (for bugs)

  1. Install both dashcore-lib and bitcore-lib
    (https://github.com/bitpay/bitcore/tree/v8.0.0/packages/bitcore-lib)
  2. Generate a transaction using new Transaction() with the required parameters.

Context

Your Environment

React Native 0.63.4
All Android/IOS simulators

  • Versions used:
    "@dashevo/dashcore-lib": "^0.19.19"
    "bitcore-lib": "^8.15.0",
    "bitcore-lib-cash": "^8.21.0",

Dashify example documentation from Bitcoin version

Our examples in the documentation are still copied from Bitcoin, e.g. in doc/examples.md. We need to convert these to Dash values so that they are less confusing and demonstrate that this is a Dash library.

InstantSend failing with ChangeAddressMissing when using FEE_PER_KB = 1000

The defaults in dashcore-lib are 10x too high:
Transaction.FEE_PER_KB = 10000;

Normal Dash transactions work fine with 1 duff per byte, thus we use:
Transaction.FEE_PER_KB = 1000;

However, when using InstantSend the security margins don't work and are not even checked in Transaction.prototype._estimateFee, which is by default:
Transaction.FEE_SECURITY_MARGIN = 15;

Increasing this to 100 works, or simply disabling the whole check in Transaction.prototype._hasFeeError via opts.disableLargeFees is a workaround. Would be better if InstantSend is actually integrated and checked when building transactions FEE_PER_KB is not relevant, it must be 10000 duffs=0.1mDASH per input, FEE_SECURITY_MARGIN of 15 or higher is also not very useful for DASH imo, 2 would be more than enough as all tx fit fine with the minimum fee.

Another simple fix would be to just use the same check for InstantSend as is used isSpecialTransaction to skip the whole utxo checking.

For https://MyDashWallet.org we have decided to disable the whole check as too many users had problems in the past with complex inputs (>5, small amounts each). Example:
7 inputs: 0.00001+0.00009626+0.0001+0.0001+0.0001+0.0001+0.00319286 = 0.00369912 DASH = 369912 duffs
outputs: 170000 + 129912
fee: 70000 (7*0.1mDASH)
sum: 170000 + 129912 + 70000 = 369912 duffs

Fails to parse rawblock

Edit: This seems to be fixed in the latest version (0.17.2). I feel dumb for not trying to upgrade first. Closing.

Hi,

I'm getting raw block data from the Dash Testnet Insight API.

For example:

http://testnet-insight.dashevo.org/insight-api/rawblock/000000000483135e9b2b2aa1d14133dbc521f7c857d0aaabef0b31b8a7561770

{
  "rawblock": "000000208c10b6ce1943281cdf88136f77aeacdf84e3c18f90d4f19013a1fa06000000006394e4a087482603d8becf57e868dca7d864031a14c7dc2f9e96c4e3f5c6dd507022be5cd765091cb01274220103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff4c03704c01047022be5c08fabe6d6dbda15c30000000156d32313a6873616477a8115158d3ed60fb32313a68736164010000000000000027ffffee3f0000000d2f6e6f64655374726174756d2f000000000540230e43000000001976a914b7ce0ea9ce2010f58ba4aaa6caa76671c438e89088ac40230e43000000001976a9145d059eb168dde8bc719fdf1f887893f99bff448788ac15cd5b07000000001976a91464443a03ebbe1bee991ee3c3e3969c511890dcd188ac708cb912000000001976a914b615444431235cdd9731248762b42a8f47621fba88ac00c2eb0b000000001976a914639f244619d05facfa18fb45607ae44e5f9ac61a88ac00000000460200704c0100424a5796212b313116febe0fa55ac7e96c680164c739ce9ed54c27f83d1d6dc8c7959cdd92b7e3c70c3c9d7b23f3338031a60399abba21e997de20191265671d"
}

I then try to parse the raw block data using dashcore-lib version 0.17.1:

const bitcore = require('@dashevo/dashcore-lib');
const block =
bitcore.Block.fromString("000000208c10b6ce1943281cdf88136f77aeacdf84e3c18f90d4f19013a1fa06000000006394e4a087482603d8becf57e868dca7d864031a14c7dc2f9e96c4e3f5c6dd507022be5cd765091cb01274220103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff4c03704c01047022be5c08fabe6d6dbda15c30000000156d32313a6873616477a8115158d3ed60fb32313a68736164010000000000000027ffffee3f0000000d2f6e6f64655374726174756d2f000000000540230e43000000001976a914b7ce0ea9ce2010f58ba4aaa6caa76671c438e89088ac40230e43000000001976a9145d059eb168dde8bc719fdf1f887893f99bff448788ac15cd5b07000000001976a91464443a03ebbe1bee991ee3c3e3969c511890dcd188ac708cb912000000001976a914b615444431235cdd9731248762b42a8f47621fba88ac00c2eb0b000000001976a914639f244619d05facfa18fb45607ae44e5f9ac61a88ac00000000460200704c0100424a5796212b313116febe0fa55ac7e96c680164c739ce9ed54c27f83d1d6dc8c7959cdd92b7e3c70c3c9d7b23f3338031a60399abba21e997de20191265671d");
console.log(block.transactions[0].inputs);
Error: Failed to parse payload: raw payload is bigger than expected.
    at Function.CoinbasePayload.fromBuffer (/home/me/dash/node_modules/@dashevo/dashcore-lib/lib/transaction/payload/coinbasepayload.js:53:11)
    at Object.parsePayloadBuffer [as parseBuffer] (/home/me/dash/node_modules/@dashevo/dashcore-lib/lib/transaction/payload/payload.js:52:18)
    at Transaction.fromBufferReader (/home/me/dash/node_modules/@dashevo/dashcore-lib/lib/transaction/transaction.js:363:36)
    at Function._fromBufferReader (/home/me/dash/node_modules/@dashevo/dashcore-lib/lib/block/block.js:95:42)
    at Function.fromBufferReader (/home/me/dash/node_modules/@dashevo/dashcore-lib/lib/block/block.js:106:20)
    at Function.fromBuffer (/home/me/dash/node_modules/@dashevo/dashcore-lib/lib/block/block.js:115:16)
    at Function.fromString (/home/me/dash/node_modules/@dashevo/dashcore-lib/lib/block/block.js:124:16)
    at Object.<anonymous> (/home/me/dash/misc/dash.js:2:29)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)

Using bitcore-lib instead works:

const bitcore = require('bitcore-lib');
const block = bitcore.Block.fromString("000000208c10b6ce1943281cdf88136f77aeacdf84e3c18f90d4f19013a1fa06000000006394e4a087482603d8becf57e868dca7d864031a14c7dc2f9e96c4e3f5c6dd507022be5cd765091cb01274220103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff4c03704c01047022be5c08fabe6d6dbda15c30000000156d32313a6873616477a8115158d3ed60fb32313a68736164010000000000000027ffffee3f0000000d2f6e6f64655374726174756d2f000000000540230e43000000001976a914b7ce0ea9ce2010f58ba4aaa6caa76671c438e89088ac40230e43000000001976a9145d059eb168dde8bc719fdf1f887893f99bff448788ac15cd5b07000000001976a91464443a03ebbe1bee991ee3c3e3969c511890dcd188ac708cb912000000001976a914b615444431235cdd9731248762b42a8f47621fba88ac00c2eb0b000000001976a914639f244619d05facfa18fb45607ae44e5f9ac61a88ac00000000460200704c0100424a5796212b313116febe0fa55ac7e96c680164c739ce9ed54c27f83d1d6dc8c7959cdd92b7e3c70c3c9d7b23f3338031a60399abba21e997de20191265671d");
console.log(block.transactions[0].inputs);
```

Output: 

```
[ Input {
    prevTxId:
     <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>,
    outputIndex: 4294967295,
    _scriptBuffer:
     <Buffer 03 70 4c 01 04 70 22 be 5c 08 fa be 6d 6d bd a1 5c 30 00 00 00 15 6d 32 31 3a 68 73 61 64 77 a8 11 51 58 d3 ed 60 fb 32 31 3a 68 73 61 64 01 00 00 00 ... 26 more bytes>,
    sequenceNumber: 0 } ]
```

ReferenceError: PrivateKey is not defined

const dashcore = require('@dashevo/dashcore-lib');

var privateKey = new PrivateKey();

I have runned npm install @dashevo/dashcore-lib

But a simple code follow the docs, generated:
ReferenceError: PrivateKey is not defined

Look entire internet to find the soluction, but not found.

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce (for bugs)

Context

Your Environment

  • Version used:
  • Environment name and version (e.g. Chrome 39, node.js 5.4):
  • Operating System and version (desktop, server, or mobile):
  • Link to your project:

Superblock Candidates not supported in govobject types

When attempting to use dashcore-lib to parse a "trigger" object, type: 2, the library spits back an error about unsupported types.

It would be great if the library just supported this type.

I may try to tackle this.

Stop monkey patching bn.js

In the bn.js file within dashcore-lib, the bn.js npm module is brought into scope. Note that bn.js here refers to two different things, the file within this lib and the module published to npm. The file pulls in the module and then overrides some methods from the module (aka monkey patching). This can cause unexpected and hard to find errors when using dashcore-lib. For example, I have a repository that uses ethereumjs-abi, which pulls in the bn.js npm module. Pulling dashcore-lib into that repository started breaking ethereum functionality because the BN.prototype.toBuffer had been dynamically overridden by dashcore-lib. This is a frustrating developer experience as a user of dashcore-lib and I don't see a good reason why the library is built this way.

React-Native : Right-hand side of 'instanceof' is not callable

Hi !

On React-Native, when using dashcore-lib (dependencies of wallet-library) and specifically on using this kind of code :

 const tx = new Dashcore.Transaction();
tx.to(address, satoshis);

Will result on Script to be called, and in this one, to throw an error

TypeError: Right-hand side of 'instanceof' is not callable
    at new Script (script.js:35)
    at new UnspentOutput (unspentoutput.js:46)
    at Transaction._fromNonP2SH (transaction.js:561)
    at Transaction.from (transaction.js:554)
    at transaction.js:540
    at arrayEach (lodash.js:537)
    at Function.forEach (lodash.js:9359)
    at Transaction.from (transaction.js:539)

With debbuger, I can confirm that Address is indeed undefined. (https://github.com/dashevo/dashcore-lib/blob/master/lib/script/script.js#L35).

The fix that is proposed here : bitpay#184 worked well for me in local, I suspect the problem to come from babel, but for now just opening this issue so we can start discussing / debugging / fixing the problem =D

Signing of P2SH transactions is not implemented except for P2SH Multisig

The getSignatures() method on Transaction fails if the transaction being signed is a non-multisig P2SH transaction.

Expected Behavior

The transaction signature should be returned.

Current Behavior

The method throws Abstract Method Invocation: Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input

Possible Solution

Steps to Reproduce (for bugs)

the following code attempts to sign a transaction spending from a trivial P2SH address with a locking script of

OP_5 OP_EQUAL <pubkey> OP_CHECKSIG

$ node
> const dashcore = require('@dashevo/dashcore-lib');
undefined
> tx = dashcore.Transaction('03000000018618449e1b1f090518ff2d2e7ec185af7688aca26b7c3a4a35db0c45117a05e30000000028005525558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacacffffffff0118c69a3b000000001976a914efb38bcb860f3704cadab10947be89b7b24de70a88ac00000000')
<Transaction: 03000000018618449e1b1f090518ff2d2e7ec185af7688aca26b7c3a4a35db0c45117a05e30000000028005525558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacacffffffff0118c69a3b000000001976a914efb38bcb860f3704cadab10947be89b7b24de70a88ac00000000>
> tx.getSignatures('cUstHm2KaHLXsqcVmq3eKkSs4258WCaHByvqMMmNVjrcFWCWWkCb')
Abstract Method Invocation: Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input: {"prevTxId":"e3057a11450cdb354a3a7c6ba2ac8876af85c17e2e2dff1805091f1b9e441886","outputIndex":0,"sequenceNumber":4294967295,"script":"005525558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacac","scriptString":"OP_0 OP_5 37 0x558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacac"}
Error
   at Error.NodeError (dashcore-lib/lib/errors/index.js:23:41)
   at Input.getSignatures (dashcore-lib/lib/transaction/input/input.js:188:9)
   at forEachInput (dashcore-lib/lib/transaction/transaction.js:1168:18)
   at arrayEach (lodash/lodash.js:516:11)
   at Function.forEach (lodash/lodash.js:9368:14)
   at Transaction.getSignatures (dashcore-lib/lib/transaction/transaction.js:1167:5)
  > 

Context

P2SH transactions are needed to implement more sophisticated transactions like atomic swaps

Your Environment

  • Version used: 0.18.15

Missing OpCode Constant

Opcode.js is missing constants for opcode OP_CHECKSEQUENCEVERIFY (178).

Expected Behavior

Constants OP_CHECKSEQUENCEVERIFY should be defined as 178

Current Behavior

Obsolete OP_NOP3 is defined with for opcodes 178

Environment

  • 0.18.15

Please Unfork

GitHub support can do this for you.

  1. Go to this link https://support.github.com/contact?tags=rr-forks
  2. Type in "unfork"
  3. Let the virtual assistant help you

They completed the process for me within 1 minute after that.

from https://stackoverflow.com/a/66470086

This is not a "fork" of bitpay, it's its own project. We don't contribute upstream to bitpay. We aren't bitcoin, we're dash.

There's no sense in us pushing our developers and search engine SEO to bitcoin when we're trying to develop our own thing.

How to broadcast the serialized transaction to Dash Official server

Current version of dashcore-lib explained that we would have to send the Transaction after serialized through our own local service running dashcore-node.
https://github.com/dashevo/dashcore-lib/blob/master/docs/transaction.md

Now, this could just be serialized to hexadecimal ASCII values (transaction.serialize()) and sent over to the dashd reference client.

I found this endpoint
https://insight.dash.org/insight/tx/send

My question is:
Is there any way to send the serialized transaction directly to Dash Official server?

install on existing node

I have a server already running a fully synced version of dashd

how do I install this on the server without having to download, install and sync another version of dashd?

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.