Skip to content
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

chore: minor cleanup and doc typos (corrected) #49

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Server and browser compatible. Vanilla JS. 0 Dependencies.

```sh
npm install --save @dashincubator/secp256k1
npm install --save dashkeys
npm install --save dashtx
```

Expand Down Expand Up @@ -478,7 +479,7 @@ Tx.create({ sign, getPrivateKey });
* These may or may not be the default options, depending
* on the library used.
*
* We recommend @dashincubator/secp246k1 and @noble/secp246k1.
* We recommend @dashincubator/secp256k1 and @noble/secp256k1.
*
* @param {Uint8Array} privateKey - an input's corresponding key
* @param {Uint8Array} txHashBytes - the (not reversed) 2x-sha256-hash
Expand Down
26 changes: 14 additions & 12 deletions dashtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

/**
* @callback TxCreate
* @param {TxDeps} myUtils
* @param {TxDeps} keyUtils
* @returns {tx}
*/

Expand Down Expand Up @@ -230,10 +230,10 @@ var DashTx = ("object" === typeof module && exports) || {};
return sats;
};

Tx.create = function (myUtils) {
Tx.create = function (_keyUtils) {
let txInst = {};

txInst._utils = Object.assign({}, Tx.utils, myUtils);
txInst._utils = Object.assign({}, Tx.utils, _keyUtils);

/** @type {TxHashAndSignAll} */
txInst.hashAndSignAll = async function (txInfo, keys) {
Expand Down Expand Up @@ -392,7 +392,7 @@ var DashTx = ("object" === typeof module && exports) || {};
}
if (!hasEntropy) {
let err = new Error(
"secp265k1 implementation does not use signature entropy",
"secp256k1 implementation does not use signature entropy",
);
Object.assign(err, { code: "E_NO_ENTROPY" });
throw err;
Expand Down Expand Up @@ -746,11 +746,11 @@ var DashTx = ("object" === typeof module && exports) || {};
};

/**
* @param {TxDeps} myUtils
* @param {TxDeps} keyUtils
* @param {Array<TxPrivateKey>} keys
*/
Tx._createKeyUtils = function (myUtils, keys) {
let _getPublicKey = myUtils.getPublicKey || getPublicKey;
Tx._createKeyUtils = function (keyUtils, keys) {
let _getPublicKey = keyUtils.getPublicKey || getPublicKey;
let _utils = {
/** @type {TxGetPrivateKey} */
getPrivateKey: async function (_, i) {
Expand All @@ -759,16 +759,16 @@ var DashTx = ("object" === typeof module && exports) || {};
},
/** @type {TxGetPublicKey} */
getPublicKey: _getPublicKey,
sign: myUtils.sign,
sign: keyUtils.sign,
};

/** @type {TxGetPublicKey} */
async function getPublicKey(txInput, i, txInputs) {
let privKey = keys[i];
if (!myUtils.toPublicKey) {
if (!keyUtils.toPublicKey) {
throw new Error("type assert: missing 'toPublicKey'");
}
let pubKey = myUtils.toPublicKey(privKey);
let pubKey = keyUtils.toPublicKey(privKey);
if ("string" === typeof pubKey) {
console.warn(
"oops, you gave a publicKey as hex (deprecated) rather than a buffer",
Expand All @@ -778,7 +778,7 @@ var DashTx = ("object" === typeof module && exports) || {};
return pubKey;
}

return Object.assign(_utils, myUtils);
return Object.assign(_utils, keyUtils);
};

/**
Expand Down Expand Up @@ -903,7 +903,7 @@ var DashTx = ("object" === typeof module && exports) || {};
* TODO _param {Array<TxOutput>} txInfo.outputs
* TODO _param {Uint32} [txInfo.version]
* TODO _param {Boolean} [txInfo._debug] - bespoke debug output
* @param {TxDeps} myUtils
* @param {TxDeps} keyUtils
* @returns {Promise<TxInfoSigned>}
*/
Tx._hashAndSignAll = async function (txInfo, keyUtils) {
Expand Down Expand Up @@ -937,6 +937,8 @@ var DashTx = ("object" === typeof module && exports) || {};
inputs: [],
outputs: txInfo.outputs,
version: txInfo.version || CURRENT_VERSION,
locktime: txInfo.locktime || 0x00,
transaction: "",
};

// temp shim
Expand Down
27 changes: 15 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"homepage": "https://github.com/dashhive/dashtx.js#readme",
"devDependencies": {
"@dashincubator/secp256k1": "^1.7.1-5",
"@types/node": "^20.11.30",
"dashkeys": "^1.0.1",
"@types/node": "^20.12.7",
"dashkeys": "^1.1.0",
"zora": "^5.2.0"
}
}
Loading