-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for 4.0.0 #508
Comments
Naturally, keeping that list of related modules is super helpful ( |
I think these decisions are becoming more and more important as more complicated structures and algorithms are becoming the norm (see opt-in RBF, CLTV, payment channels, etc). |
Yes, you know I'd be in favor of breaking up the library into smaller modules =) I'd be willing to contribute any of my existing modules / names if you think they'd be of use. We can start fresh too.
Yes, definitely. |
To add to the discussion, here's what I'd like:
|
Agreed, how do you want to go about that discussion?
Mixed thoughts on this. Its not much of a benefit to change existing code, but, new code sure.
Agreed, just need to figure out what is the most suitable without giving up the powerful [albeit, Java-like] parts of the existing API.
Already have, I'm thinking that is the next step. @fanatid what is the status there OOI?
Absolutely. I'll check out GitBook :)
Tape. Targeting |
secp256k1-node v3.0.0-alpha.0 is ready, @wanderer checks PR and I hope he finish at the weekend. |
I also favor tape over mocha. After using mocha for a long time I found tape much easier to use and more consistent. |
👍 for using secp256k1-node, I've been running (an older version) in production for months now tbh I'd prefer to keep the transactionbuilder in the same package, too much hassle to extract it and keep it in sync with the version of bitcoinjs-lib. |
@rubensayshi I think the current roadmap is encompassing the extraction of:
Not much else. |
@dcousens do you want move bip32 to another module itself? or any volunteers are welcome? |
@fanatid see https://github.com/bitcoinjs/bip32, that is the planned destination. |
@dcousens check my bip32 repository https://github.com/fanatid/bip32 if it's ok, push to bitcoinjs-lib/bip32 (I haven't permission to push there) |
My concerns (some of these are pedantic):
Love that it uses try {
var secp256k1 = require('secp256k1')
} catch () {
var secp256k1 = require('secp256k1/js')
} for Of course, these are just opinions. I don't feel strongly about any of them other than the (Sorry, this probably isn't the right place to comment on this. I'm fine with this becoming |
|
@jprichardson I'm totally on board with properties, but, without compilation warnings it can be very confusing as to what the behaviour should be if those properties are
Where is
What random feature?
Multi-parameter constructors are just plain confusing.
They're not even in the same ball park? |
Do you mean |
No, I'm referring to removing
While this accurate for Flow, you can do runtime checking with Babel, that's why I included it. See: https://github.com/codemix/babel-plugin-typecheck |
Right. I thought this was a discussion RE |
Yes, you're right. My fault for commenting in that regard. When we get consensus (really just your decision in this case on fanatid/bip32 -> bitcoinjs/bip32... hehe). I'll ping back here and we can delete these bip32 related comments to keep the discussion on topic. |
@jprichardson do you have an example for a relative example of how we might use babel run time types for bitcoinjs-lib? Also, would this mean non-babel users would essentially be left in the dust? (assuming they aren't already haha) |
I think this example (https://github.com/codemix/babel-plugin-typecheck#what) is pretty solid: function sendMessage (to: User, message: string): boolean {
return socket.send(to, message);
} to function sendMessage(to, message) {
var _socket$send;
if (!(to instanceof User)) throw new TypeError("Value of argument 'to' violates contract.");
if (typeof message !== "string") throw new TypeError("Value of argument 'message' violates contract.");
_socket$send = socket.send(to, message);
if (typeof _socket$send !== "boolean") throw new TypeError("Function 'sendMessage' return value violates contract.");
return _socket$send;
} Gives us both static compile-time checking and run-time checking. If we were to use Babel, we'd precompile as most do (unless they used Rollup and |
@jprichardson complete with crap error messages though? :/ |
Also can I enforce more complicated types like a map of |
Have we made consensus on switching to https://github.com/cryptocoinjs/secp256k1-node? Also, everyone cool with starting a |
Also, @dcousens which modules are you alright with breaking out for 3.0.0 if any at all? |
@jprichardson pretty much all of them I thought. If we do move on it now though, it means anyone wanting to use SegWit [which will probably be merged after] will likely have to upgrade... do we want to force that? |
Why would this be necessary? Couldn't we keep 2.x as the mainline for a bit? |
@jprichardson sorry, I mistook what you said above as a "lets make master 3.0.0 and start merging" |
@jprichardson @fanatid it is your opinion that moving to Related to #623 |
@ryanxcharles comment from February 2015 comes to mind as a good "goal" to continue to strive for... |
Bumping this to |
In the spirit of #407, for the purposes of #513, #737 and #787 (and indirectly #866, even #899), I think the following point should be kept in mind for
Think of this.__Q = secp256k1.G.multiply(this.d) is computationally expensive... without caching The secondary reason, is That leaves If the If a |
To capture the motivation for the ideas being thrown around in https://github.com/bitcoinjs/playground, this is the ideal scenario for let { maybe witness, maybe input, output } = p2sh(p2wsh(p2pkh(pubkey, maybe signature)))
let { maybe witness, maybe input, output } = p2sh(p2wsh(p2ms(pubkeys, maybe signatures)))
let { output } = p2sh(p2wsh(p2ms(pubkeys)))
let { witness, input } = p2sh(p2wsh(p2ms(pubkeys, signatures))) // fails without pubkeys, missing redeemscript
let { witness, input } = p2ms([], signatures)
let { witness, output, pubKeys, signatures } = p2ms({ witness, scriptPubKey })
// ... or
let { output } = p2sh({ redeem: p2wsh(p2ms(pubkeys)) })
I want to capture I don't this API is the cleanest when applied with I think |
I want to try and have a first-pass at a release candidate for this by 20th December 👍 |
Oh wow, that's a mission :) lets get it done I'll start getting up to speed on it, only had time to glance at stuff recently :/ One thing I'd like to make sure is in there, basically don't construct any inputs the person hasn't provided the txOut for. Be nice to have it as it lets us expose some interesting stuff. It does reenforce however that assumptions can be made about a tx (fee wise, fully signed-ness, whatever) unless we have all inputs.. TransactionBuilder.prototype.input = function (nIn, txOut, {rs, ws}) {
if (!(nIn in this.inputs)) {
this.inputs[nIn] = this.buildInput(this.tx, nIn, txOut, {rs, ws})
}
return this.inputs[nIn]
}
TransactionBuilder.prototype.sign = function (txOut, {rs, ws}, key, hashtype) {
this.input(nIn, txOut, {rs, ws}).sign(key, hashType)
} so you get all sorts of nice stuff from inputs: var input = txb.input(nIn, txOut, opts);
input.isFullySigned()
input.getSigHashUnsafe(hashType)
input.verify()
// and other goodies.. Am about to grab a flight, might try make a start.. awful tho, we have to many tests to keep happy ;) |
Throw around any crazy ideas in the "playground" (maybe I should rename it "bitcoinjs-lab" - haha). |
I think Private keys are 32-byte The existing
Any thoughts on an API around that? |
From issue 999: ECPair and HDNode should have a scriptType attribute to make transaction building easier for users. |
@dabura667 alternatively, if we simplify the keys down (as we said, remove The key structures should probably only support the minimal ECDSA functionality, and a public key getter... |
From #927 (comment) const bitcoin = require('bitcoinjs-lib')
const pubKey = bitcoin.HDNode.fromBase58('ypub6XMTwf6NSvfzYYgVgdNWRNfMTiQt4rSjZbEk8qoCnBGhUD2rsgZ2A8pexgzaGLKgySZxqxrctDpAVU8QtfxqfX8QUAhtFmGFUFx9B51TVg8')
.derive(0)
.derive(27)
.getPublicKeyBuffer()
const { address } = bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpk({
pubkey: pubKey
})
}) And for signing, let txb = new Transaction()
txb.addInput(..., ...)
txb.addOutput(..., ...)
txb.signForWitnessV0(0, unspent.value, SIGHASH_ALL, function (hash) {
let signature = keyPair.sign(hash, SIGHASH_ALL)
// expects { input, witness } at the least
return bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpk({
pubkey: pubKey,
signature: signature
})
})
}) Thoughts? ping @afk11 |
For multisig let signatures = [OPS.OP_0, OPS.OP_0]
let pubkeys = [alice, bob, keyPair.getPublicKeyBuffer()]
txb.sign(0, SIGHASH_ALL, function signFn (hash) {
let signature = keyPair.sign(hash, SIGHASH_ALL)
signatures[1] = signature
// expects { input } at the least
return bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2ms({
m: 2,
pubkeys,
signatures,
allowIncomplete: true
})
})
}) The callback isn't async, so it may be an odd pattern, but I think it keeps the data flow clear and encapsulated. (not tied to the idea though) |
If we replace
Admittedly, the last point being what we actually want to get rid of because of how much complexity it entails and in the end, the above is insanely easy. That said, we could have the payments result being stored as state and given as a second parameter |
For standard P2PKH (assuming we don't add any conveniences) txb.sign(0, SIGHASH_ALL, function (hash) {
return bitcoin.payments.p2pkh({
pubkey: keyPair.getPublicKeyBuffer(),
signature: keyPair.sign(hash, SIGHASH_ALL)
})
}) |
Just a bike shed for
3.0.0
4.0.0
, if its necessary, and the currently open PRs:#459 - Extraction of DER encoding
#456 - Remove message module (
bitcoinjs-message
)#440 - Var naming conventions
#350 - secp256k1
#428 - Altcoin support
@jprichardson I was also thinking about
TransactionBuilder
, and what it represents.It is basically a convenience wrapper around
Transaction
(the primitive) that makes everyone's life easier when building complex transactions, but, to be honest, it could easily be extracted from the core library.Thoughts?
In general, I'm thinking we work on making this library primarily all the primitives for bitcoin operations such that other libraries can easily compose using them.
I'd like to see other crypto primitives like merkle trees, bloom filters and rolling bloom filters in the ecosystem too.
The text was updated successfully, but these errors were encountered: