From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3A193C0893 for ; Wed, 23 Dec 2020 02:15:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 1FB53228AE for ; Wed, 23 Dec 2020 02:15:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nEHW+Dzbq1MT for ; Wed, 23 Dec 2020 02:15:51 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zinan.dashjr.org (zinan.dashjr.org [192.3.11.21]) by silver.osuosl.org (Postfix) with ESMTP id CF303203D0 for ; Wed, 23 Dec 2020 02:15:50 +0000 (UTC) Received: from ishibashi.lan (unknown [12.190.236.208]) (Authenticated sender: luke-jr) by zinan.dashjr.org (Postfix) with ESMTPSA id 1D30438A09CA; Wed, 23 Dec 2020 02:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dashjr.org; s=zinan; t=1608689748; bh=FgfgqIik1ZJV3TaZDep/92V1KbMQ8BXG0O1KCip7C/0=; h=From:To:Subject:Date:References:In-Reply-To; b=UEoh04jaZZ6oHI60re4wHKwd10MpEpZXLMErU8cMuBBuzw4LKzIrN6vdoy9E/wI6S BZ8QiY0HkN3q9B0tKd4AIXWemgLW8a+6mkL49ryCqrc21qMDz98M+/pTpeWKXei7cR RfOad3/6WZ7gw9GlWPI/1llrX4jd4sGfhdREc2+M= From: Luke Dashjr To: monokh , Bitcoin Protocol Discussion Date: Wed, 23 Dec 2020 02:15:45 +0000 User-Agent: KMail/1.9.10 References: In-Reply-To: X-KMail-QuotePrefix: > MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <202012230215.46394.luke@dashjr.org> Subject: Re: [bitcoin-dev] BIP Proposal: Wallet Interface X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Dec 2020 02:15:52 -0000 1) People should not be encouraged to write or use web browsers for their wallet. 2) You may want to look over earlier work in this area. On Tuesday 22 December 2020 14:43:11 monokh via bitcoin-dev wrote: > Hi > > This is a first draft of a BIP we intend to submit. The main intention is > to define a simple interface that wallets and applications can agree on > that would cover the vast majority of use cases. This can enable writing > bitcoin applications (e.g. time lock, multi sig) on the web that can be > seamlessly used with any compatible wallets. We have implementations of > such examples but I don't want to turn this thread into a promotion and > rather focus on the spec. > > Appreciate input from the list. Please share if there are existing efforts, > relevant specs or use cases. > > ------------------------------ > > A wallet interface specification for bitcoin applications > > ## Abstract > > This BIP describes an API for Bitcoin wallets and applications as a > standard. > > ## Summary > > Bitcoin wallets should expose their address derivation and signing > functions to external applications. The interface would be expressed as > follows in javascript: > > ``` > { > // Wallet Metadata > wallet: { > name: 'Bitcoin Core' > }, > > // Request access to the wallet for the current host > async enable: (), > > // Request addresses and signatures from wallet > async request ({ method, params }) > } > ``` > > In the web context the interface could be exposed at the top level of a > webpage, for example under `window.bitcoin`. However this spec does not > intend to define any standards for how and where the interfaces should be > exposed. > > ## Motivation > > Due to the seldom available APIs exposed by wallets, applications (web or > otherwise) are limited in how they are able to interact. Generally only > simple sends have been available. A more robust API that introduces other > requests will promote richer Bitcoin applications. > > Additionally, wallet APIs have frequently included inconsistencies in their > interfaces and behaviour. This has required applications to build and > maintain a separate client for each wallet, increasing the risk of bugs and > unintended behaviour as well as being a limiting factor for the adoption of > usable bitcoin applications. > > With a standardised wallet API: > > - Wallets have a clear API to implement > - Applications have a clear expectation of wallet interface and behaviour > - Applications become agnostic to the wallet specifics, increasing choice > for users > > If more wallets implement the specification, applications will be developed > more confidently by benefiting from the wallet interoperability. This > creates a positive feedback loop. > > ## Specification > > For simplicity, the interface is defined in the context of web applications > running in the browser (JS) however, they are simple enough to be easily > implemented in other contexts. > > ### General Rules > > - For sensitive functions (e.g. signing), wallet software should always > prompt the user for confirmation > > ### Types > > **UserDeniedError** > An error type indicating that the application's request has been denied by > the user > Type: Error > > **Hex** > Type: String > Example: > `"0000000000000000000a24677957d1e50d70e67c513d220dbe8868c4c3aefc08"` > > **Address** > Address details > Type: Object > Example: > > ``` > { > "address": "bc1qn0fqlzamcfuahq6xuujrq08ex7e26agt20gexs", > "publicKey": > "02ad58c0dced71a236f4073c3b6f0ee27dde6fe96978e9a9c9500172e3f1886e5a", > "derivationPath": "84'/1'/0'/0/0" > } > ``` > > ### API > > The wallet must implement the following methods. > > **enable** > > The enable call prompts the user for access to the wallet. > > If successful, it resolves to an address (`**Address**` type) of the > wallet. Typically the first external address to be used as an identity. > > **`UserDeniedError`** will be thrown if the request is rejected. > > **request** > > The request method must take one parameter in the following format: > > ``` > { > "method": "wallet_methodName", > "params": ["foo", "bar", "baz"] > } > ``` > > For a list of mandatory methods see Table > > The wallet should reject request calls unless `enable` has been resolved. > > Sensitive requests that involve signing should always prompt the user for > confirmation > > On success the request should resolve to the response as defined in the > method table. > > **`UserDeniedError`** will be thrown if the request is rejected. > > **Mandatory methods** > > method: `wallet_getAddresses` params: [`index = 0, numAddresses = 1, change > = false`] > return: `[ Address ]` > error: UserDeniedError > > method: `wallet_signMessage` params: `[ message, address ]` > return: Signature `Hex` > error: UserDeniedError > > method: `wallet_signPSBT` params: `[ [psbtBase64, inputIndex, address] ]` > return: `psbtBase64` > error: UserDeniedError > > method: `wallet_getConnectedNetwork` params: `[]` > return: Network object `mainnet` | `testnet` | `regetst` > error: UserDeniedError > > ## Rationale > > The purpose of the API is to expose a set of commonly used wallet > operations. In addition, it should be flexible enough to serve for other > requests such as node RPC calls. > > **Why is there a singular request call instead of named methods?** > The transport layer for the requests cannot be assumed, therefore it is > much more flexible to instead define an abstract format. > > **Why are the mandatory methods so primitive? Where is getBalance, > getUtxos, ... ?** > A wallet need not worry about providing every possible scenario for usage. > The primitives of keys and signing can expose enough to applications to do > the rest. Applications should have flexibility in how they implement these > functions. It is the role of a library rather than the wallet. > > ## Security Implications > > Great care should be taken when exposing wallet functionality externally as > the security and privacy of the user is at risk. > > ### Signing > > Operations that trigger signing using private keys should be guarded behind > confirmation screens where the user is fully aware of the nature of the > transaction. In the example of a PSBT signature request, the outputs, the > inputs and which key is being used should be clearly marked. > > ### Privacy > > Some api methods expose metadata about the user, such as public keys. > Depending on how privacy focused the wallet intends to be, the wallet could > protect these behind a confirmation. Commonly the wallet just needs to give > the origin access to all of its public keys, however it could also allow > the option to expose only selected derivation paths. > > -monokh