From 14eb853f276a63f8c0ec17d300865577599769bc Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 18 Sep 2012 15:44:25 -0700 Subject: [PATCH] Checking sketch of JS libs. --- js/ledger.js | 34 ++++++++++++++++++++++++++++++++++ js/serializer.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ js/transaction.js | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 js/ledger.js create mode 100644 js/serializer.js create mode 100644 js/transaction.js diff --git a/js/ledger.js b/js/ledger.js new file mode 100644 index 00000000..42c04fc1 --- /dev/null +++ b/js/ledger.js @@ -0,0 +1,34 @@ +// +// Tools for working with ledger entries. +// +// Fundamentally, we work in the more strict case of not trusting the ledger as presented. If we have a server we trust, then the +// burden of verify the ledger entries is left to the server. But, we work in the same fundamental units of information, ledger +// entries, to keep the code orthagonal. +// + +var serializer = require("./serializer"); + +exports.getLedgerEntry = function(key, done) { + var id = (ws.id += 1); + + ws.response[id] = done; + + ws.send({ + 'command': 'getLedgerEntry', + 'id': id, + 'ledger': ledger, + 'account': accountId, + 'proof': false // Eventually, we will want proof if the server is untrusted. + }); +}; + +exports.getAccountRootNode = function(ledger, accountId, done) { + var s = new Serializer(); + + s.addUInt16('a'); + s.addUInt160(accountId); + + getLedgerEntry(s.getSHA512Half(), done); +}; + +// vim:ts=4 diff --git a/js/serializer.js b/js/serializer.js new file mode 100644 index 00000000..00f9e070 --- /dev/null +++ b/js/serializer.js @@ -0,0 +1,44 @@ +// + +var serializer = {}; + +serializer.addUInt16 = function(value) { + switch (typeof value) { + case 'string': + addUInt16(value.charCodeAt(0)); + break; + + case 'integer': + for (i = 16/8; i; i -=1) { + raw.push(value & 255); + value >>= 8; + } + break; + + default: + throw 'UNEXPECTED_TYPE'; + } +}; + +serializer.addUInt160 = function(value) { + switch (typeof value) { + case 'array': + raw.concat(value); + break; + + case 'integer': + for (i = 160/8; i; i -=1) { + raw.push(value & 255); + value >>= 8; + } + break; + + default: + throw 'UNEXPECTED_TYPE'; + } +}; + +serializer.getSHA512Half = function() { +}; + +// vim:ts=4 diff --git a/js/transaction.js b/js/transaction.js new file mode 100644 index 00000000..3706a24a --- /dev/null +++ b/js/transaction.js @@ -0,0 +1,38 @@ +// Work with transactions. +// +// This works for both trusted and untrusted servers. +// +// For untrusted servers: +// - We never send a secret to an untrusted server. +// - Convert transactions to and from JSON. +// - Sign and verify signatures. +// - Encrypt and decrypt. +// +// For trusted servers: +// - We need a websocket way of working with transactions as JSON. +// - This allows us to not need to port the transaction tools to so many +// languages. +// + +var commands = {}; + +commands.buildSend = function(params) { + var srcAccountID = params.srcAccountID; + var fee = params.fee; + var dstAccountID = params.dstAccountID; + var amount = params.amount; + var sendMax = params.sendMax; + var partial = params.partial; + var limit = params.limit; +}; + + +exports.trustedCreate = function() { + +}; + +exports.untrustedCreate = function() { + +}; + +// vim:ts=4