Skip to content

Commit

Permalink
upgrade bitcoinjs-lib, rename params
Browse files Browse the repository at this point in the history
  • Loading branch information
jpochyla authored and prusnak committed May 12, 2016
1 parent 3c0176a commit 07200a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion emscripten/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "1.0.0",
"description": "",
"dependencies": {
"bitcoinjs-lib": "^1.5.7"
"bitcoinjs-lib": "^2.1.1"
}
}
32 changes: 18 additions & 14 deletions emscripten/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _address = _malloc(ADDRESS_SIZE);
*/

/**
* @param {HDNode} node HDNode struct, see the definition above
* @param {HDNode} node HDNode struct, see the definition above
* @return {Uint8Array}
*/
function serializeNode(node) {
Expand All @@ -47,9 +47,9 @@ function serializeNode(node) {
}

/**
* @param {Uint8Array} sn serialized node, see `serializeNode`
* @param {Number} index BIP32 index of the address
* @param {Number} version address version byte
* @param {Uint8Array} sn serialized node, see `serializeNode`
* @param {Number} index BIP32 index of the address
* @param {Number} version address version byte
* @return {String}
*/
function deriveAddress(sn, index, version) {
Expand All @@ -60,17 +60,17 @@ function deriveAddress(sn, index, version) {
}

/**
* @param {HDNode} node HDNode struct, see the definition above
* @param {Number} from index of the first address
* @param {Number} to index of the last address
* @param {Number} version address version byte
* @param {HDNode} node HDNode struct, see the definition above
* @param {Number} firstIndex index of the first address
* @param {Number} lastIndex index of the last address
* @param {Number} version address version byte
* @return {Array<String>}
*/
function deriveAddressRange(node, from, to, version) {
function deriveAddressRange(node, firstIndex, lastIndex, version) {
var addresses = [];
var sn = serializeNode(node);
var i;
for (i = from; i <= to; i++) {
for (i = firstIndex; i <= lastIndex; i++) {
addresses.push(deriveAddress(sn, i, version));
}
return addresses;
Expand All @@ -94,13 +94,17 @@ function processMessage(event) {

switch (type) {
case 'deriveAddressRange':
var response = deriveAddressRange(
var addresses = deriveAddressRange(
data['node'],
data['from'],
data['to'],
data['firstIndex'],
data['lastIndex'],
data['version']
);
postMessage(response);
postMessage({
'addresses': addresses,
'firstIndex': data['firstIndex'],
'lastIndex': data['lastIndex']
});
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion emscripten/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var nodeStruct = {
child_num: node.index,
fingerprint: node.parentFingerprint,
chain_code: node.chainCode,
public_key: node.pubKey.toBuffer()
public_key: node.keyPair.getPublicKeyBuffer().toString('hex')
};
var nodeSerialized = crypto.serializeNode(nodeStruct);

Expand Down

0 comments on commit 07200a3

Please sign in to comment.