Skip to content

Instantly share code, notes, and snippets.

Goal

The main goal of this refactor is to define a proper separation between the frontend and the backend of the application. Although Copay is a 100% client side application, a clean separation of the core functionalities is needed to later offer different endpoints, eg. web interface, npm command line interface or just a library that runs both on server and browser.

Layers of application

Three layers are proposed for the application:

  1. UI Interface: AngularJS | CLI
  2. Wallet Models and Services
  3. Backing Services: P2P Networking | Blockchain | Storage
var auth = require('./auth.js')
function testAuthentication(username, password) {
auth.authenticateUser(username, password, function onResult(isAuthenticated){
console.log(username + ' can authenticate with '+ password
+ ' --> ' + isAuthenticated);
});
}
function runTest(){
@yemel
yemel / auth.js
Last active August 29, 2015 13:58
"use strict";
var pg = require('pg');
var crypto = require('crypto');
var DATABASE_URL = process.env.DATABASE_URL;
// -------- Cryptographic functions --------
// Passwords are represented as SALT:SHA1_HASH in base64.
@yemel
yemel / gist:9993627
Created April 5, 2014 15:52
Trustless Prepaid Service
Integrantes: C) Cliente, T) ThirdParty, P) Proveedor
C genera 3 claves privadas y una bitcoin address que para la que se le pueden retirar fondos con 2 de 3 de esas claves (todo esto client-side)
A carga fondos a esa address, entrega una clave privada a T y otra clave privada a P. Los fondos cargados corresponderían al prepago, por ejemplo dinero suficiente para un año de servicio de X.
Cuando C le pasa la clave privada a T también informa las condiciones de pago que exigirá P, como pueden ser: gasto máximo en un periodo y la frecuencia de cobro.
Finalmente el proceso de pago sería el siguiente: