summaryrefslogtreecommitdiff
path: root/77/82527dd4f73cc486693c1cb06f2a72399c2127
blob: 479f0049c289c4f30f3ef67949c55be9c36fdcd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
Return-Path: <mnokhb@gmail.com>
Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137])
 by lists.linuxfoundation.org (Postfix) with ESMTP id 7600DC0893
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue, 22 Dec 2020 14:43:26 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by fraxinus.osuosl.org (Postfix) with ESMTP id 71B3D8615E
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue, 22 Dec 2020 14:43:26 +0000 (UTC)
X-Virus-Scanned: amavisd-new at osuosl.org
Received: from fraxinus.osuosl.org ([127.0.0.1])
 by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id nsXFndSS1V2p
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue, 22 Dec 2020 14:43:24 +0000 (UTC)
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6
Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com
 [209.85.167.174])
 by fraxinus.osuosl.org (Postfix) with ESMTPS id 334EF86135
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue, 22 Dec 2020 14:43:24 +0000 (UTC)
Received: by mail-oi1-f174.google.com with SMTP id x13so14975991oic.5
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue, 22 Dec 2020 06:43:24 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=v7Kkq0U5oQfK0KITJMFICdH/+jd7Wj2SqqAuOFcebMQ=;
 b=ePEovuJBoPTjF3qRTuT3D0gNT5sCj5UejiOxcOT2CSwzyFIqcIpA8J696T9tdPUNse
 V5DcARAgUG8GnH1Z49156FuUX7abP5NWEvp4zNx/t0kXmC/rhyLJ5Fi2BP2diSy/7HMY
 7mY4AgMRDzDkOYJ5+FUn/pVICxLWrbY94Ie1O76y/2fmLZZaW5VVcAHB+PIQ3SZnno2H
 B/LQpWhlelxccrwP9v5hrJC8dL/yADNNVx+2k931FaSpwoPTtygjoMlCmxao2tkbke1d
 Wq3140DDqFBEPNSIaiTedNUgBb0dfAFt/CLpYAPIaOK55gnyTotvwgyWcdTAtm7VBEyW
 si4g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=v7Kkq0U5oQfK0KITJMFICdH/+jd7Wj2SqqAuOFcebMQ=;
 b=WsGPVr5nJ7di0TigrV1rj41CysgxsfRTwZ+ICtxoXz+9C7QYhdq8An7NWaFK0PPg7q
 0KMh0UL/b9WoQO6oLJDylUwCFtdJAcfA0KtiORW+jI0jSUdnW/idwSZlduPxYuIye5RC
 qXs6o+3/H54jF65mnF7hnN+KSZhe1p6wsx3u3tMKJ6cg56nqFBIWIxMhgCOYLZ+W1t0+
 2Eq32Vw0J6j8DAaQhSaQ9ycac0jsGSvlbneumpye1SqrHFHNS2mq2Rn/PCiC6NrB9X0i
 ZuE5LQ8ngNqYLu1NUVTCTaNbVX3gNrV4xstctdsfxSwCv8SEwrn5XBv9HZDGxFs+Tq3T
 01pg==
X-Gm-Message-State: AOAM5336W0f5YMazDJuDg4atoiUi4ybbhCeJK61POI73FZ3K7DI85049
 h9dsFJnRSK6FMmUszrUGuO0AISgkOAU43S0Or4wajOUEh/mA6Y/B
X-Google-Smtp-Source: ABdhPJz84m9aQEHKli162oVLKlQlUSq9jEAqmlHr66f+0JSjQ+Er2fhmaJMuxpjdkQssp2X8qxNhHNXl2ZAYrsWnUBo=
X-Received: by 2002:aca:c4cd:: with SMTP id
 u196mr14888082oif.133.1608648203230; 
 Tue, 22 Dec 2020 06:43:23 -0800 (PST)
MIME-Version: 1.0
From: monokh <mnokhb@gmail.com>
Date: Tue, 22 Dec 2020 14:43:11 +0000
Message-ID: <CAPvWj7H9hg8EMCvDzWiq=f59KojHEGCm_iAP+FBaB+25=CLt0A@mail.gmail.com>
To: bitcoin-dev@lists.linuxfoundation.org
Content-Type: multipart/alternative; boundary="000000000000b8e57005b70e9802"
X-Mailman-Approved-At: Tue, 22 Dec 2020 14:48:18 +0000
Subject: [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 <bitcoin-dev.lists.linuxfoundation.org>
List-Unsubscribe: <https://lists.linuxfoundation.org/mailman/options/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=unsubscribe>
List-Archive: <http://lists.linuxfoundation.org/pipermail/bitcoin-dev/>
List-Post: <mailto:bitcoin-dev@lists.linuxfoundation.org>
List-Help: <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=help>
List-Subscribe: <https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=subscribe>
X-List-Received-Date: Tue, 22 Dec 2020 14:43:26 -0000

--000000000000b8e57005b70e9802
Content-Type: text/plain; charset="UTF-8"

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

--000000000000b8e57005b70e9802
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi<br><br>This is a first draft of a BIP we intend to subm=
it. The main intention is to define a simple interface that wallets and app=
lications can agree on that would cover the vast majority of use cases. Thi=
s can enable writing bitcoin applications (e.g. time lock, multi sig) on th=
e web that can be seamlessly used with any compatible wallets. We have impl=
ementations of such examples but I don&#39;t want to turn this thread into =
a promotion and rather focus on the spec.=C2=A0<br><br>Appreciate input fro=
m the list. Please share if there are existing efforts, relevant specs or u=
se cases.=C2=A0<br><div><br></div><div>------------------------------</div>=
<div><br></div><div>A wallet interface specification for bitcoin applicatio=
ns<br><br>## Abstract<br><br>This BIP describes an API for Bitcoin wallets =
and applications as a standard. =C2=A0<br><br>## Summary<br><br>Bitcoin wal=
lets should expose their address derivation and signing functions to extern=
al applications. The interface would be expressed as follows in javascript:=
<br><br>```<br>{<br>	// Wallet Metadata<br>	wallet: {<br>		name: &#39;Bitco=
in Core&#39;<br>	},<br><br>	// Request access to the wallet for the current=
 host<br>	async enable: (),<br><br>	// Request addresses and signatures fro=
m wallet<br>	async request ({ method, params })<br>}<br>```<br><br>In the w=
eb context the interface could be exposed at the top level of a webpage, fo=
r example under `window.bitcoin`. However this spec does not intend to defi=
ne any standards for how and where the interfaces should be exposed.<br><br=
>## Motivation<br><br>Due to the seldom available APIs exposed by wallets, =
applications (web or otherwise) are limited in how they are able to interac=
t. Generally only simple sends have been available. A more robust API that =
introduces other requests will promote richer Bitcoin applications.<br><br>=
Additionally, wallet APIs have frequently included inconsistencies in their=
 interfaces and behaviour. This has required applications to build and main=
tain a separate client for each wallet, increasing the risk of bugs and uni=
ntended behaviour as well as being a limiting factor for the adoption of us=
able bitcoin applications.<br><br>With a standardised wallet API:<br><br>- =
Wallets have a clear API to implement<br>- Applications have a clear expect=
ation of wallet interface and behaviour<br>- Applications become agnostic t=
o the wallet specifics, increasing choice for users<br><br>If more wallets =
implement the specification, applications will be developed more confidentl=
y by benefiting from the wallet interoperability. This creates a positive f=
eedback loop.<br><br>## Specification<br><br>For simplicity, the interface =
is defined in the context of web applications running in the browser (JS) h=
owever, they are simple enough to be easily implemented in other contexts.<=
br><br>### General Rules<br><br>- For sensitive functions (e.g. signing), w=
allet software should always prompt the user for confirmation<br><br>### Ty=
pes<br><br>**UserDeniedError**<br>An error type indicating that the applica=
tion&#39;s request has been denied by the user<br>Type: Error<br><br>**Hex*=
*<br>Type: String<br>Example: `&quot;0000000000000000000a24677957d1e50d70e6=
7c513d220dbe8868c4c3aefc08&quot;`<br><br>**Address**<br>Address details<br>=
Type: Object<br>Example:<br><br>```<br>{ <br>	&quot;address&quot;: &quot;bc=
1qn0fqlzamcfuahq6xuujrq08ex7e26agt20gexs&quot;,<br>	&quot;publicKey&quot;: =
&quot;02ad58c0dced71a236f4073c3b6f0ee27dde6fe96978e9a9c9500172e3f1886e5a&qu=
ot;,<br>	&quot;derivationPath&quot;: &quot;84&#39;/1&#39;/0&#39;/0/0&quot;<=
br>}<br>```<br><br>### API<br><br>The wallet must implement the following m=
ethods.<br><br>**enable**<br><br>The enable call prompts the user for acces=
s to the wallet.<br><br>If successful, it resolves to an address (`**Addres=
s**` type) of the wallet. Typically the first external address to be used a=
s an identity.<br><br>**`UserDeniedError`** will be thrown if the request i=
s rejected.<br><br>**request**<br><br>The request method must take one para=
meter in the following format:<br><br>```<br>{<br>	&quot;method&quot;: &quo=
t;wallet_methodName&quot;,<br>	&quot;params&quot;: [&quot;foo&quot;, &quot;=
bar&quot;, &quot;baz&quot;]<br>}<br>```<br><br>For a list of mandatory meth=
ods see Table<br><br>The wallet should reject request calls unless `enable`=
 has been resolved.<br><br>Sensitive requests that involve signing should a=
lways prompt the user for confirmation<br><br>On success the request should=
 resolve to the response as defined in the method table.<br><br>**`UserDeni=
edError`** will be thrown if the request is rejected.<br><br>**Mandatory me=
thods**<br><br>method: `wallet_getAddresses` params: [`index =3D 0, numAddr=
esses =3D 1, change =3D false`]<br>return: `[ Address ]`<br>error: UserDeni=
edError<br><br>method: `wallet_signMessage` params: `[ message, address ]`<=
br>return: Signature `Hex`<br>error: UserDeniedError<br><br>method: `wallet=
_signPSBT` params: `[ [psbtBase64, inputIndex, address] ]`<br>return: `psbt=
Base64`<br>error: UserDeniedError<br><br>method: `wallet_getConnectedNetwor=
k` params: `[]`<br>return: Network object `mainnet` | `testnet` | `regetst`=
<br>error: UserDeniedError<br><br>## Rationale<br><br>The purpose of the AP=
I is to expose a set of commonly used wallet operations. In addition, it sh=
ould be flexible enough to serve for other requests such as node RPC calls.=
<br><br>**Why is there a singular request call instead of named methods?** =
<br>The transport layer for the requests cannot be assumed, therefore it is=
 much more flexible to instead define an abstract format.<br><br>**Why are =
the mandatory methods so primitive? Where is getBalance, getUtxos, ... ?**<=
br>A wallet need not worry about providing every possible scenario for usag=
e. The primitives of keys and signing can expose enough to applications to =
do the rest. Applications should have flexibility in how they implement the=
se functions. It is the role of a library rather than the wallet. <br><br>#=
# Security Implications<br><br>Great care should be taken when exposing wal=
let functionality externally as the security and privacy of the user is at =
risk.<br><br>### Signing<br><br>Operations that trigger signing using priva=
te keys should be guarded behind confirmation screens where the user is ful=
ly aware of the nature of the transaction. In the example of a PSBT signatu=
re request, the outputs, the inputs and which key is being used should be c=
learly marked.<br><br>### Privacy<br><br>Some api methods expose metadata a=
bout the user, such as public keys. Depending on how privacy focused the wa=
llet intends to be, the wallet could protect these behind a confirmation. C=
ommonly the wallet just needs to give the origin access to all of its publi=
c keys, however it could also allow the option to expose only selected deri=
vation paths.<br></div><div><br></div><div>-monokh</div><div><br></div></di=
v>

--000000000000b8e57005b70e9802--