Scalable Multi-Signature Web Wallets With Copay

As we saw in Web Wallets Using Copay the main drawback to using BitPay’s Copay as an online web wallet like Coinbase is its lack of scalability. Every Copay wallet establishes two connections to the Insight server. Our previous article includes code which eliminates one of the connections used to send and receive single-signature wallet updates to and from the blockchain. Here we offer code which consolidates all multi-signature wallet copayer updates.

First, a quick explanation of how Copay works. Let’s refer to an instance of Copay running in a web browser as a client, and to the instance of Insight the various clients connect to as server. When a wallet connects to a server it is assigned a channel according to the wallet’s public key. A channel in this context functions similarly to a chatroom; when a message is sent to a channel, it is received by all clients subscribed to that channel. All the users of a specific multi-signature wallet will be assigned the same channel and so receive each other’s messages. Because of the way clients are coded in Copay each socket is subscribed to only one channel but the number of channels a socket may be subscribed to is actually unlimited. Additionally, Copay takes advantage of an Insight plugin called “mailbox” that allows messages between clients to be distributed asynchronously. A client may broadcast a message regardless of whether the other clients are connected at that time. This is used for transaction confirmations and other types of notifications.

What our modification does is separate a wallet from its socket, so several wallets may share the same socket. This single socket will subscribe to the corresponding channel of each wallet. Messages are sent normally, but receiving messages requires a simple bit of routing so the message gets to the right wallet. Note that, because of the way socket channels work, if a socket receives a message, there is a wallet using that socket that should receive that message. Our modification doesn’t increase network traffic.

Bitcoin lacks specifications for joining wallets and receiving new addresses generated by other copayers. Fortunately, Copay has addressed these issues for their users, but the solution should ideally be a standard part of Bitcoin.

(Sebastian Wain contributed with the writing of this article)