Skip to content

Commit

Permalink
Silent inject + trezor helper
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenandrews committed Nov 6, 2018
1 parent 78afdfe commit 262b195
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,13 @@ rpc = {
operations : opResponse
};
});
},
silentInject: function(sopbytes){
return node.query('/injection/operation', sopbytes).then(function (f) {
return {
hash : f
};
});
},
transfer: function (from, keys, to, amount, fee, parameter, gasLimit, storageLimit) {
if (typeof gasLimit == 'undefined') gasLimit = '200';
Expand Down Expand Up @@ -718,6 +725,79 @@ contract = {
return setInterval(ct, timeout * 1000);
},
};
trezor = {
source : function(address){
var tag = (address[0] == "t" ? 0 : 1);
var curve = (parseInt(address[2])-1);
var pp = (tag == 1 ? prefix.KT : prefix["tz"+(curve+1)]);
var bytes = utility.b58cdecode(address, pp);
if (tag == 1) {
bytes = utility.mergebuf(bytes, [0])
} else {
bytes = utility.mergebuf([curve], bytes)
}
return {
tag : tag,
hash : bytes
};
},
operation : function(d){
var operations = [];
var revealOp = false;
var op;
for(var i = 0; i < d.opOb.contents.length; i++){
op = d.opOb.contents[i];
if (op.kind == "reveal"){
if (revealOp) throw "Can't have 2 reveals";
revealOp = {
source : trezor.source(op.source),
fee : parseInt(op.fee),
counter : parseInt(op.counter),
gasLimit : parseInt(op.gas_limit),
storageLimit : parseInt(op.storage_limit),
publicKey : utility.mergebuf([0], utility.b58cdecode(op.public_key, prefix.edpk)),
};
} else {
if (['origination', 'transaction', 'delegation'].indexOf(op.kind) < 0) return console.log("err2");
op2 = {
type : op.kind,
source : trezor.source(op.source),
fee : parseInt(op.fee),
counter : parseInt(op.counter),
gasLimit : parseInt(op.gas_limit),
storageLimit : parseInt(op.storage_limit),
};
switch(op.kind){
case "transaction":
op2.amount = parseInt(op.amount);
op2.destination = trezor.source(op.destination);
if (d.opbytes.length > 172) op2.parameters = utility.hex2buf(d.opbytes.substr(172));
break;
case "origination":
op2.managerPubkey = trezor.source(op.managerPubkey).hash;
op2.balance = parseInt(op.balance);
op2.spendable = op.spendable;
op2.delegatable = op.delegatable;
if (typeof op.delegate != 'undefined'){
op2.delegate = trezor.source(op.delegate).hash;
}
//Script not supported yet...
break;
case "delegation":
if (typeof op.delegate != 'undefined'){
op2.delegate = trezor.source(op.delegate).hash;
}
break;
}
operations.push(op2);
}
}
if (operations.length > 1) return console.log("Too many operations");
var operation = operations[0];
var tx = {};
return [operation, revealOp];
}
};

//Legacy
utility.ml2tzjson = utility.sexp2mic;
Expand All @@ -737,6 +817,7 @@ eztz = {
node: node,
rpc: rpc,
contract: contract,
trezor: trezor,
};

module.exports = {
Expand Down

0 comments on commit 262b195

Please sign in to comment.