moneybutton / bsv Goto Github PK
View Code? Open in Web Editor NEWBitcoin SV javascript library
License: Other
Bitcoin SV javascript library
License: Other
or add a legacy address where the bsv come from .add this data to webhook call back
Hi have an Angular 7 app and have imported the bsv library.
The app displays the following error:
TypeError: Buffer.alloc is not a function
at Object../node_modules/bsv/lib/util/buffer.js (.../node_modules/bsv/lib/util/buffer.js:176:1)
Tried a whole bunch of things and failed miserably.
Any pointers greatly appreciated.
It seems that the version guard error is quite annoying when requiring multiple modules that depend on bsv.
More than one instance of bsv found. Please make sure to require bsv and check that submodules do not also include their own bsv dependency.
Maybe we should change version guard in index.js, by using a global bsv instance in somewhere like global._bsvInstance ?
I clicked the link on this page: https://docs.moneybutton.com/docs/mb-html.html
The anchor text is "api-client" in the paragraph under the simple paywall example.
(Btw, you can search with Google and observe the number of results returned to see that it's much more commonly spelled "paywall," not "pay wall," to the extent that I think it's fair to call the compound word version the correct spelling.)
The broken link is to this page: https://docs.moneybutton.com/docs/api-client.md
I guess it might technically be a resource not loading on that page, rather than a broken link. The error I see is "Cannot GET /docs/api-client.md" with the result being that the expected content is not displayed.
https://github.com/moneybutton/bsv/blob/master/lib/block.js#L130
It's set to 1MB right now. Can this be increased to 10MB or higher without issue?
How to know if a TxBuilder
is fully signed using the lastest version of this library?
In the legacy version we had tx.isFullySigned(): bool
Is there an equivalent in the latest version?
Raw transactions contain several compactsize unsigned integers. These are a variable width datatype, however the transaction size function "estimates" the maximum width for these fields. Instead we should calculate the exact size, as we have all the necessary information to do so.
https://github.com/moneybutton/bsv/blob/master/lib/transaction/transaction.js#L909
https://github.com/moneybutton/bsv/blob/master/lib/transaction/transaction.js#L85
Hello, today is my first day using the bsv package.
I'm trying to generate a 'testnet' address following the code in the documentation.
const bsv = require("bsv");
let privateKey = bsv.PrivKey.fromRandom('testnet')
let publicKey = bsv.PubKey.fromPrivKey(privateKey)
let address = bsv.Address.fromPubKey(publicKey, 'testnet')
let address2 = bsv.Address.fromPrivKey(privateKey, 'testnet')
console.log(address.toString());
console.log(address2.toString());
No matter how many times I try, they all start with a 1.
example: 1B9ymVLbAMkwY87rNugSxqfx7V1hGw71xX
Am I making a mistake or is there something wrong with the documentation?
I want to use this bsv library, but I found sign transaction with bip0143 does not support, can you add me as a directly contributor?
This script is present in testnet:
6a304502204b13f000b2f046a17fe77976ad4bc6c6055194745b434757eef9faf8bc5de9a8022100b1c2fdce9df149cc8de3dda5ea680dab46888d28abca9b8abac7a8d6d37e4e6a
bsv 2.x is able to parse it with no issues. bsv 1.x is not able to parse it.
I'll keep adding info.
The inputs need to be signed by separate keys. This page is a good example of what I am trying to achieve with this library.
When parsing this transaction's (https://whatsonchain.com/tx/ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767) output scripts bsv throws this error:
Error
at new NodeError (/project/node_modules/bsv/lib/errors/index.js:20:41)
at Function.Script.fromBuffer (/project/node_modules/bsv/lib/script/script.js:101:15)
{
message: "Invalid script buffer: can't parse valid script from given buffer 4e",
Looks like this was fixed for bitcoinjs-lib:
bitcoinjs/bitcoinjs-lib#375
The bsv 2.0 branch is here: https://github.com/moneybutton/bsv/tree/bsv2
import
syntax on 'bsv' directly, and for each part of the library to accessible in a tree-shakable way that way, e.g. import Address from 'bsv'
.It tell me Mnemonic undefined
, When I use this lib in ts. the code is
import {PrivateKey, Mnemonic, HDPrivateKey, Transaction} from "bsv";
let mnemonic = Mnemonic.fromRandom();
read the source code, the Mnemonic
class is export in bsv.d.ts
, but it not export in index.js
ใ
This is my change
index.js
bsv.Transaction = require('./lib/transaction') // line 56
bsv.Mnemonic = require('./lib/mnemonic') // add line
menmonic.js
// var _ = bsv.deps._ // line 6
var _ = require('../util/_') // new line
message: 'Dust amount detected in one output - For more information please see: https://bsv.io/api/lib/transaction#serialization-checks',
Please check the code at
/node_modules/bsv/lib/transaction/transaction.js:167
I think the link is not correct.
For now, there's no standard or BIP about ECIES, and there are different implements which are incompatible with each other.
So we need to choose one, but I think bitcore's implement is not as good as electrum's implement.
There are reasons:
Thus, I suggest we use electrum-ecies instead of bitcore-ecies.
At this page: https://github.com/moneybutton/bsv/blob/master/docs/index.md
I'm getting 404 / Page not found errors when I click the majority of the links under "Documentation Index".
I'm especially looking for the mnemonics docs if anyone can provide a working link, thank you!
do you need to run bitcore to use bsv as a javascript library?
Hi there,
The sentence in README,
Bitcoin sv uses a different sighash for transaction signatures.
What does this exactly mean...
I've read code lib/crypto/signature.js
Signature.SIGHASH_ALL = 0x01;
Signature.SIGHASH_NONE = 0x02;
Signature.SIGHASH_SINGLE = 0x03;
Signature.SIGHASH_FORKID = 0x40;
Signature.SIGHASH_ANYONECANPAY = 0x80;
code lib/transaction/sighash.js
function sighash(transaction, sighashType, inputNumber, subscript, satoshisBN, flags)
...
compare with code in bitcoin-sv/bitcoin-sv repo
const std::map<uint8_t, std::string> mapSigHashTypes = {
{SIGHASH_ALL, "ALL"},
{SIGHASH_ALL | SIGHASH_ANYONECANPAY, "ALL|ANYONECANPAY"},
{SIGHASH_ALL | SIGHASH_FORKID, "ALL|FORKID"},
{SIGHASH_ALL | SIGHASH_FORKID | SIGHASH_ANYONECANPAY,
"ALL|FORKID|ANYONECANPAY"},
{SIGHASH_NONE, "NONE"},
{SIGHASH_NONE | SIGHASH_ANYONECANPAY, "NONE|ANYONECANPAY"},
{SIGHASH_NONE | SIGHASH_FORKID, "NONE|FORKID"},
{SIGHASH_NONE | SIGHASH_FORKID | SIGHASH_ANYONECANPAY,
"NONE|FORKID|ANYONECANPAY"},
{SIGHASH_SINGLE, "SINGLE"},
{SIGHASH_SINGLE | SIGHASH_ANYONECANPAY, "SINGLE|ANYONECANPAY"},
{SIGHASH_SINGLE | SIGHASH_FORKID, "SINGLE|FORKID"},
{SIGHASH_SINGLE | SIGHASH_FORKID | SIGHASH_ANYONECANPAY,
"SINGLE|FORKID|ANYONECANPAY"},
};
and code src/script/sighashtype.h
/** Signature hash types/flags */
enum {
SIGHASH_ALL = 1,
SIGHASH_NONE = 2,
SIGHASH_SINGLE = 3,
SIGHASH_FORKID = 0x40,
SIGHASH_ANYONECANPAY = 0x80,
};
I didn't quite understand, what's the difference that BSV SigHash has, compared with BitcoinCash(BCH)
Would you please kindly help and teach me about this?
For my understandings, SigHash logic that BCH and BSV used, are the same, currently
Is there a plan of removing the SIGHASH_FORKID
or changing the value?
Thanks very much for you helping and teaching ๐
hereby request repo and file name change to bsv.js to comply with common naming conventions of such a package.
I was trying to access the deps.buffer in the browser. It seems like it is not exposed.
Maybe I am doing it wrong. Any suggestions would be welcome.
Cheers.
In Transaction.prototype.from
there is a check to see if the new UTXO is in fact one of the old ones. This Check however expects certain fields in the object, that might not be there:
This is the check:
var exists = _.some(this.inputs, function (input) {
// TODO: Maybe prevTxId should be a string? Or defined as read only property?
return input.prevTxId.toString('hex') === utxo.txId && input.outputIndex === utxo.outputIndex
})
if (exists) {
return this
}
This check expects the fields txId
and outputIndex
to be present.
The problem is that the later code doesn't only work with these fields. It can also work with txid
and vout
.
If the passed inputs are like:
tx.from({ txid: "same txid", vout: 0, amount:100000, scriptPubKey: "same script" });
tx.from({ txid: "same txid", vout: 0, amount:100000, scriptPubKey: "same script" });
tx.from({ txid: "same txid", vout: 0, amount:100000, scriptPubKey: "same script" });
tx.from({ txid: "same txid", vout: 0, amount:100000, scriptPubKey: "same script" });
...then the check will pass. and all of these will be added as separate inputs, even though they are the same.
The way to fix this bug is either to move the check Down (to a moment After it is transformed to an input), or to move the transformation Up ( move utxo = new UnspentOutput(utxo)
to the moment before any checks are made. )
Hi,
I found this issue and I can't seem to mitigate it in any way. I have tried different things that I will explain below.
The stack trace for the error looks like:
Uncaught (in promise) Error: Assertion failed
at n (bn.js:5)
at o.toBuffer (bn.js:485)
at e.s.toBuffer.s.toDER (signature.js:158)
at h.addSignature (publickeyhash.js:71)
at x.applySignature (transaction.js:1233)
at transaction.js:1198
at Array.forEach (<anonymous>)
at Object.each (_.js:62)
at x.sign (transaction.js:1197)
at Fe (transaction.js:152)
Where transaction.js:152
looks something like:
tx.addOutput(BSV.Transaction.Output({ script, satoshis: 0 }))
.change(change)
.feePerKb(feePerKb);
.sign(pvKey)
The problem does not occur when I test it on my local machine, but when I build the react app and deploy it on production, I keep getting this error which seems to be related to the Buffer
type's presence. I have tried adding these lines to my react app's entry script (index.js
):
import { Buffer } from 'buffer';
global.Buffer = Buffer;
window.Buffer = Buffer;
But it didn't solve the problem. I don't know if I am doing something wrong or it's the bsv
library, but I tried to upgrade the bsv
package version to the latest version and it didn't solve the problem either.
So, any insights or helps are appreciated. Thanks.
In the Money Button Docs there's an example of .toASM https://docs.moneybutton.com/docs/ex-op-return.html
but that is in the context of Money Button, not purely BSV.js.
I don't see anything about .toASM or .buildSafeDataOut or really much at all about transactions in the bsv docs, though they are great for keys / mnemonics / addresses and other features.
I attached a screen shot from bitcore-lib docs showing .from, .sign, and .addData methods on the Transaction object
but when I run bsv.Transaction in the terminal I don't see .addData or .from or .change anywhere, and I'm at a loss for how to use ASM string formats other than using Money Button.
For example, is there some way to just put ASM data directly into a transaction in BSV?
Looking for properties I'm getting
> Object.getOwnPropertyNames(bsv.Transaction) [ 'length', 'name', 'prototype', 'DUST_AMOUNT', 'FEE_SECURITY_MARGIN', 'MAX_MONEY', 'NLOCKTIME_BLOCKHEIGHT_LIMIT', 'NLOCKTIME_MAX_VALUE', 'FEE_PER_KB', 'CHANGE_OUTPUT_MAX_SIZE', 'shallowCopy', 'Input', 'Output', 'UnspentOutput', 'Signature', 'Sighash', 'sighash' ]
and don't see .addData anywhere when I fish around in the properties.
Is there some place within the BSV documentation where you get into bsv.Script.buildSafeDataOut, .addData, or any transaction kung fu? It seems glossed over in the Examples section of the Money Button Docs and not included in the BSV docs.
I don't blame you for the fragmented nature of the docs, it looks like bitcore-lib's docs were also spotty, but it would be good to have more thorough explanations of the different transaction methods, especially not being able to find .addData documented in the BSV docs is kinda bothersome for me.
Specifically, if you know how to add a script to a transaction output, in ASM format, without Money Button, that would be a helpful example to include. Would that be bsv.Script.fromASM?
I could experiment to brute force some of this info, but I can't seem to find addData or .from or .change by scanning the classes.
Unless I'm missing it, it seems like you only mention ASM once in passing in that Examples section which is not even part of the main BSV docs so it would be good to add a Transactions section and get into ASM more, especially, kinda like how they have here, but even this doesn't really explain all the possible methods: https://github.com/bitpay/bitcore-lib/blob/master/docs/transaction.md
Especially strange to me that I can't find .change .addData .from etc properties... I would think that would be under Transaction.Output but maybe I'm suffering from a newbie blind spot.
I have used one of the public key from test cases here. Converted it to an address for regtest
. Tried validating using bsv.Address.isValid()
but it failed.
When I inspected the issue, this line is interpreting the network of the above address(using bsv.Address.fromPublicKey
) as testnet, when it is actually for regtest.
const bsv = require("bsv");
// Public Key from one of BSV test cases
var pubkey = new bsv.PublicKey(
"0485e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b00" +
"4833fef26c8be4c4823754869ff4e46755b85d851077771c220e2610496a29d98"
);
// Get address for `regtest` using the Public Key
var address = bsv.Address.fromPublicKey(pubkey, "regtest");
// Try validating the address - This logs false to console
console.log(
bsv.Address.isValid(address.toString(), "regtest", "pubkeyhash")
);
For the purpose of running the above script, I've used v1.2.0 (as shown in package-lock.json
).
"bsv": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/bsv/-/bsv-1.2.0.tgz",
"integrity": "sha512-Hccrppea561dus7v/5OZsSWClsPYLFd+kQjdRRkR5Ky+fuwlJYtMdJWGR7nuLUKqWyZwkBI5lLocXERvZ/zSkg=="
}
I suggest next release is named 1.0.0 and starting to use semantic versioning to indicate breaking changes, added features and fixes/patches in the version number.
I know keeping 0.x.y might seem more "be carefull what you do with this update" but i much rather raise the version number to 56.x.y over the years than not really know the meaning between a 0.44.2 and 0.45.0
When deriving keys from a Testnet Bip32, derived keys are generated for Mainnet
bip32 = Bip32.Testnet.fromRandom();
bip32.privKey.toString();
-- 'cSPSuY71HyHRm8wqFd71Cp7L6TfuorPoTS3XogrYoX7iRdYpRPh1'
bip32.derive('m/0/0').privKey.toString();
-- 'L2ouEGaEEGvctTMxyVAApxxPKoQS3GEEhQowPGZRZBDx4ZnBzRBp'
Notice how the first WIF starts with a c
while the derived starts with L
This issue serves to track adding the now re-enabled opcodes to the interpreter in the interp.js
file. Feel free to take some on, if you want.
OP_MUL
OP_DIV
OP_CAT
OP_SPLIT
OP_INVERT
OP_AND
OP_OR
OP_XOR
OP_MOD
OP_LSHIFT
OP_RSHIFT
var rawtx = "0200000002e0615d2f66f2da21f41b63e71856deb3be61bfc38661de249fdb624b61765aae01000000fdf20947304402203bf41b56d2b2903b8f3873e9ef25e8309b097076ff950a26c56060f97577aa7002203dcfee2e21f89dd09da02df0bdef06afc89bd689995693ec71c314e28bb4bf52c32103734f39f61a6941945d661b441786b2f875e69c4a09511f6f1e99a310fa53e7814d2b0902000000adcea30469fc3b26bacb8f9d759bf151b70c4b885bbefdc7bc7b90b5e958dcd0752adad0a7b9ceca853768aebb6965eca126a62965f698a0c1bc43d83db632ade0615d2f66f2da21f41b63e71856deb3be61bfc38661de249fdb624b61765aae01000000fd8c085101400176018801a901ac615e7961007901687f7700005279517f75007f77007901fd8763615379537f75517f77007901007e81517a7561537a75527a527a5379535479937f75537f77527a75517a67007901fe8763615379557f75517f77007901007e81517a7561537a75527a527a5379555479937f75557f77527a75517a67007901ff8763615379597f75517f77007901007e81517a7561537a75527a527a5379595479937f75597f77527a75517a67615379517f75007f77007901007e81517a7561537a75527a527a5379515479937f75517f77527a75517a6868685179517a75517a75517a75517a7561517a7561007982770079011494527951797f77537952797f750001127900a063610113795a7959797e01147e51797e5a797e58797e517a7561610079011479007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a527975757568607900a06351790112797e610079011279007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575685e7900a063615f795a7959797e01147e51797e5a797e58797e517a75616100796079007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575685c7900a063615d795a7959797e01147e51797e5a797e58797e517a75616100795e79007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575680079aa007961011679007982775179517958947f7551790128947f77517a75517a75618769011679a954798769011779011779ac69610115796100792097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce0810201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c011379011379855679aa616100790079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a756157795679567956795679537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff0061517951795179517997527a75517a5179009f635179517993527a75517a685179517a75517a7561527a75517a517951795296a0630079527994527a75517a68537982775279827754527993517993013051797e527e53797e57797e527e52797e5579517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7e56797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75617777777777777777777777777777777777777777777777776a92c27eb5ea37eb38cf15661eac1d994df76f8176b822000000000000ffffffff8655941fcad982efe66467c97c8afc79ef1231ed394431f0cb13b254d7d7ca2e000000004100000014000000000000000000000000000000000000000000140d36c8ec4212fe58d2010f9551a0cbfc8c67f94d027c2c1400000000000000000000000000000000000000000014000000000000000000000000000000000000000000ffffffffaeea98a87a19f586f40d7cda7e88750dbed03b2654f081b5178ae2c8c68c37030000000000ffffffff017c2c000000000000fd8c085101400176018801a901ac615e7961007901687f7700005279517f75007f77007901fd8763615379537f75517f77007901007e81517a7561537a75527a527a5379535479937f75537f77527a75517a67007901fe8763615379557f75517f77007901007e81517a7561537a75527a527a5379555479937f75557f77527a75517a67007901ff8763615379597f75517f77007901007e81517a7561537a75527a527a5379595479937f75597f77527a75517a67615379517f75007f77007901007e81517a7561537a75527a527a5379515479937f75517f77527a75517a6868685179517a75517a75517a75517a7561517a7561007982770079011494527951797f77537952797f750001127900a063610113795a7959797e01147e51797e5a797e58797e517a7561610079011479007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a527975757568607900a06351790112797e610079011279007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575685e7900a063615f795a7959797e01147e51797e5a797e58797e517a75616100796079007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575685c7900a063615d795a7959797e01147e51797e5a797e58797e517a75616100795e79007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575680079aa007961011679007982775179517958947f7551790128947f77517a75517a75618769011679a954798769011779011779ac69610115796100792097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce0810201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c011379011379855679aa616100790079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a756157795679567956795679537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff0061517951795179517997527a75517a5179009f635179517993527a75517a685179517a75517a7561527a75517a517951795296a0630079527994527a75517a68537982775279827754527993517993013051797e527e53797e57797e527e52797e5579517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7e56797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75617777777777777777777777777777777777777777777777776a0d36c8ec4212fe58d2010f9551a0cbfc8c67f94d00000000"
Tx.fromHex(rawtx).toHex() == rawtx
It turns false
, toHex
added four zeros at the tail.
I believe somewhere along the line OP_SPLIT
was introduced to replace OP_SUBSTR
.
The following should be true:
OpCode.OP_SPLIT === 0x7f
Currently it is undefined
@Soundpisey
Duplicate of #
Basically I need a function as the following:
export function getBSVAddress(mnemonic: string): { address: string; privateKey: string } {
return { address: 'xxx', privateKey: 'yyy' };
}
I've done similar things with other coins such as BTC, BCH, EOS, ETH quite smoothly, but I'm having a hard time with this library, any suggestions?
var bsv = require('bsv')
var script = bsv.Script.buildDataOut('something before')
console.log(script.toASM())
// 'OP_RETURN 736f6d657468696e67206265666f7265'
console.log(script.toHex())
// 6a10736f6d657468696e67206265666f7265
script.add(new Buffer(0))
console.log(script.toASM())
// 'OP_RETURN 736f6d657468696e67206265666f7265'
console.log(script.toHex())
// 6a10736f6d657468696e67206265666f726500
It shall be 'OP_RETURN 736f6d657468696e67206265666f7265 OP_0'
or something.
The toASM is not correct.
test code:
it('check_tx_id', async function () {
// test 147056 / 00000000000007a678f2e1316e0f7f7acf2b967d998558aed8dadcd4430fd5f1
const height = 147056
const blockhash = await chain.getblockhash(height)
const chain_block_hex = await chain.getblock(blockhash, 0)
const chain_block = await chain.getblock(blockhash, 1)
const chain_tx0_id = chain_block.tx[0]
const block = bsv.Block.fromBuffer(Buffer.from(chain_block_hex, 'hex'))
const block_tx0_id = block.txs[0].id()
console.log(chain_tx0_id)
console.log(block_tx0_id)
expect(chain_tx0_id).to.equal(block_tx0_id);
});
The two tx ids should be equal. Obviously block_tx0_id is not correct.
2) bsv
check_tx_id:
AssertionError: expected '9fa47592276963ff2b8d44d0f547b03a41ac1e4e18e2a02b5445ade9b021071d' to equal '121f0f093c0e98bb499643bbe781a9746deaf4b9b123f958b2a962b3bb57d873'
+ expected - actual
-9fa47592276963ff2b8d44d0f547b03a41ac1e4e18e2a02b5445ade9b021071d
+121f0f093c0e98bb499643bbe781a9746deaf4b9b123f958b2a962b3bb57d873
at Context.<anonymous> (test/chain.spec.js:59:29)
at process._tickCallback (internal/process/next_tick.js:68:7)
Example:
bsv.Script.buildDataOut(["149xadSKJcKdhgE4sMmcvx421nsGYwgkWo", "", "", "test"]).toASM()
Expected result:
out.s1 = "149xadSKJcKdhgE4sMmcvx421nsGYwgkWo"
out.s2 = ""
out.s3 = ""
out.s4 = "test"
Actual Result:
out.s1 = "149xadSKJcKdhgE4sMmcvx421nsGYwgkWo"
out.s2 = "test"
Since v2.0.10 tests in txforge are failing - re libitx/txforge#15
It seems the global export of bsv
no longer exists if using es module syntax in node environments. eg:
import bsv from 'bsv'
console.log(typeof bsv) // => undefined
Possibly related to 42334f5 but unsure
The following transaction is sent from moneybutton react module.
When parsing this tx with bsv module, the output script fails to recognize the op_return output as data output.
you can reproduce with the following nodejs code.
`const bsvjs = require('bsv');
const txId = 'd5ea08bccca2f7e778335bc2d3cf49497f984d856493d7036a08fa5f979ba845';
const txHex = '01000000014aec653971ae61f6eb3734764779290ed61dcd48db3d894f6c6963276188e54f010000006a47304402203db4e1801cd9770cffc53f92df1a891c777aa6d58df46d1f9a253c26e35fee34022031bca787ef52dc99f6929e6857e14a9b48450982289c342e9ddef45b218960d94121031805031f354bb560cb7eda9807b09429bbee0ebb6e70d12176d3f1984747e26bffffffff03000000000000000042006a0f6d6f6e6579627574746f6e2e636f6d04757466382a6d6f6e6579627574746f6e2e636f6d2053454e44494e472057495448206f7052657475726e2050524f5010270000000000001976a9143ef1ad96462dd01b611c701a5df60399d708395188ac76460000000000001976a9143c5754dae948944119770fcaa06599025f2ea8b488ac00000000';
const tx = new bsvjs.Transaction();
tx.fromString(txHex);
console.log(tx: ${JSON.stringify(tx)} isCoinbase:${tx.isCoinbase()}\n
);
for (const idx in tx.inputs) {
const input = tx.inputs[idx];
console.log( in[${idx}]: ${input.script.toAddress().toString()}\n
);
}
for (const idx in tx.outputs) {
const output = tx.outputs[idx];
if (output.script.isDataOut()) {
console.log(` ou[${idx}]: isData:${output.script.isDataOut()}, data: ${output.script.getData().toString('utf-8')}`);
}
else {
console.log(` ou[${idx}]: isData:${output.script.isDataOut()}, ${output.script.toAddress().toString()}, ${output.satoshis}`);
}
}`
The expected result of ou[0] is 'isData: true',
but the actual result of ou[0] is 'isData: false'.
Hi there, I'm quite new to JS and BSV programming. I tried to create a raw transaction, but I wasn't very successful.
I installed the bsv library "npm install --save --save-exact bsv" and ran the following code:
`let bsv = require('bsv');
let str_privateKey = 'L5aw273pEhyQBJQCZXjg42QqkaLnTGSdpDNmRD6eCTNXFqu5EsJ9';
let privateKey2 = bsv.PrivateKey.fromWIF(str_privateKey)
var tx = bsv.Transaction();
tx.from('0200000001c3203f4bbe59399b343103f1368f9e27e248f75a8e0ac166deadca1a41cf7506000000006a47304402200c146b37ac8a1ff971db6992c0190e24caad2080d6e1dcd120457c61b27d20e802205dd28518744cfe0b7791024efaa3ef2d870b29a66a6a0737a191a4772b7518a9412102394c63c0ee8c2efc9cbb771c6d704323b62e6014ce19a18caee4ad9858903e5affffffff02e8060100000000001976a914f51cc15ce74136ed6371af8d03f1c9ecfabd219e88ace387a80d000000001976a914318ea8397710273b3255353723cfe036f56542a688ac00000000'); // I used the transaction hex (not sure if this is right
tx.to('1718koF1VRrNg5ADLQLRMLHomTwYekEGTE', '65304'); // Added an address and an output in satoshis (basically, the full amount minus 2000 satoshis)
tx.change('1718koF1VRrNg5ADLQLRMLHomTwYekEGTE'); // Sets up a change address where the rest of the funds will go
tx.sign(privateKey2); // Signs all the inputs it can
const serializedTx = tx.serialize();
console.log(serializedTx);`
However, it's not working. Any input is welcome! thank you for the support.
test code:
it('check_block_hex', async function () {
// test 147056 / 00000000000007a678f2e1316e0f7f7acf2b967d998558aed8dadcd4430fd5f1
const height = 147056
const blockhash = await chain.getblockhash(height)
const chain_block_hex = await chain.getblock(blockhash, 0)
const block = bsv.Block.fromBuffer(Buffer.from(chain_block_hex, 'hex'))
const lib_block_hex = block.toBuffer().toString('hex')
console.log(chain_block_hex)
console.log(lib_block_hex)
expect(chain_block_hex).to.equal(lib_block_hex);
});
After hex compared, hex from bsv lib has extra '00000000', the result hex should be equal to rpc result.
Hello, I am new to bsv and want to develop node app that transfers BSV between accounts.
But I could not find any hints how to do that in this repo.
Hope to get some instructions how to do that.
Thank you
Hi there.
I'm trying to implement bsv
support into my bitcore-node
. But I'm getting this error below when I try to start it. Is there anyone who tried to implement bsv into the bitcore-node? I need help with this ๐ต.
Thank you.
Unhandled Rejection at: Error: More than one instance of bitcore-lib-cash found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency.
bitcore-node_1 | at Object.bitcore.versionGuard (/usr/src/app/packages/bitcore-node/node_modules/bsv/index.js:12:11)
bitcore-node_1 | at Object.<anonymous> (/usr/src/app/packages/bitcore-node/node_modules/bsv/index.js:15:9)
bitcore-node_1 | at Module._compile (internal/modules/cjs/loader.js:701:30)
bitcore-node_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
bitcore-node_1 | at Module.load (internal/modules/cjs/loader.js:600:32)
bitcore-node_1 | at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
bitcore-node_1 | at Function.Module._load (internal/modules/cjs/loader.js:531:3)
bitcore-node_1 | at Module.require (internal/modules/cjs/loader.js:637:17)
bitcore-node_1 | at require (internal/modules/cjs/helpers.js:22:18)
bitcore-node_1 | at LibProvider.register (/usr/src/app/packages/bitcore-node/src/providers/libs/index.ts:10:31)
bitcore-node_1 | at new BSVModule (/usr/src/app/packages/bitcore-node/src/modules/bitcoin-sv/index.ts:9:19)
bitcore-node_1 | at ModuleManager.loadConfigured (/usr/src/app/packages/bitcore-node/src/modules/index.ts:49:34)
bitcore-node_1 | at Object.exports.FullClusteredWorker (/usr/src/app/packages/bitcore-node/src/workers/all.ts:35:11)
bitcore-node_1 | at Object.<anonymous> (/usr/src/app/packages/bitcore-node/src/server.ts:4:1)
bitcore-node_1 | at Module._compile (internal/modules/cjs/loader.js:701:30)
bitcore-node_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
bitcore-node_1 | Shutting down 62
(...)
"bsv": "0.24.1",
"bsv-p2p": "git+https://github.com/deanmlittle/bsv-p2p.git",
(...)
import { BaseModule } from '..';
import { BSVStateProvider } from '../../providers/chain-state/bsv/bsv';
import { BitcoinP2PWorker } from '../bitcoin/p2p';
import { VerificationPeer } from '../bitcoin/VerificationPeer';
export default class BSVModule extends BaseModule {
constructor(services) {
super(services);
services.Libs.register('BSV', 'bsv', 'bsv-p2p');
services.P2P.register('BSV', BitcoinP2PWorker);
services.CSP.registerService('BSV', new BSVStateProvider());
services.Verification.register('BSV', VerificationPeer);
}
}
import { CacheStorage } from '../../../models/cache';
import { GetEstimateSmartFeeParams } from '../../../types/namespaces/ChainStateProvider';
import { BTCStateProvider } from '../btc/btc';
export class BSVStateProvider extends BTCStateProvider {
constructor(chain: string = 'BSV') {
super(chain);
}
async getFee(params: GetEstimateSmartFeeParams) {
const { chain, network } = params;
const cacheKey = `getFee-${chain}-${network}`;
return CacheStorage.getGlobalOrRefresh(
cacheKey,
async () => {
return { feerate: await this.getRPC(chain, network).getEstimateFee() };
},
30 * CacheStorage.Times.Minute
);
}
}
module.exports = {
BTC: {
lib: require('bitcore-lib'),
p2p: require('bitcore-p2p')
},
BCH: {
lib: require('bitcore-lib-cash'),
p2p: require('bitcore-p2p-cash')
},
LTC: {
lib: require('litecore-lib'),
p2p: require('litecore-p2p')
},
BSV: {
lib: require('bsv'),
p2p: require('bsv-p2p')
},
DOGE: {
lib: require('@csio.company/dogecore-lib'),
p2p: require('@csio.company/dogecore-p2p')
},
DSH: {
lib: require('@dashevo/dashcore-lib'),
p2p: require('@dashevo/dashcore-p2p')
}
};
function buildTransaction(inputs, outputs, change) {
let txb = new Transaction();
inputs.forEach(utxo => {
txb.from({'txId':utxo.txId, 'outputIndex':utxo.outputIndex,'script':Script.buildPublicKeyHashOut(utxo.address).toString(),'satoshis':toSatoshis(utxo.amount)});
});
outputs.forEach(to => {
txb.to(to.address, toSatoshis(to.amount));
});
if (change) {
txb.to(change.address, toSatoshis(change.amount));
}
for (let i=0; i<inputs.length; i++) {
txb.sign(inputs[i].ecPair.d.toHex(32));
}
return txb;
}
error code: -26
error message:
16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)
Multiple calls to HDPrivateKey()
generate the same key.
OS: macOS Mojave 10.14.6
Browsers: Safari and Brave
Debugging through the browser, the issue appears to be with the Base58 encoding on this line as it always returns the same xpriv:
https://github.com/moneybutton/bsv/blob/master/lib/hdprivatekey.js#L482
Reproduce with this code:
<html>
<script type="text/javascript" src="https://unpkg.com/[email protected]/bsv.min.js"></script>
<script type="text/javascript">
console.log(window.crypto.getRandomValues(new Uint8Array(12)));
console.log(window.crypto.getRandomValues(new Uint8Array(12)));
console.log(window.crypto.getRandomValues(new Uint8Array(12)));
console.log(window.crypto.getRandomValues(new Uint8Array(12)));
var a = bsv.HDPrivateKey()
var b = bsv.HDPrivateKey()
console.log(a.toString())
console.log(b.toString())
</script>
<h1>Random test</h1>
</html>
As a developer
I want Message.sign to sign a Buffer or a String
So that I can choose the best representation of data for my purposes
Currently Message constructor only accepts a string. This change is to allow Message constructor to accept a Buffer as well as String
Additional Info
We want to sign any kind of data and not just a string. Underneath the signing is done on a Buffer object anyways.
This change is to convert the internal representation from this.message
to this.messageBuffer
and accept a Buffer
in the constructor.
This enables this library to be able to sign binary data in the most direct way, in addition to supporting string and existing use-cases.
why the new version not compatible with the old one, such as 1.5.4;
the new version is hard to use...very disgusting update
Hello, testing out the BSV library and I noticed an issue with a function within the documentation
The function to display the WIF key is stated as toWIF(), however it should be toWif()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.