Skip to content

Commit 637f455

Browse files
authored
Merge pull request #9 from ffmcgee725/joaoc/browser-wallet-messaging-interface-update
Update caip-294 to fit extension id as valid target type (caip-341)
2 parents bd15294 + c115a2e commit 637f455

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

CAIPs/caip-282.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ interface WalletAnnounceRequestParams {
6060
name: string;
6161
icon: string;
6262
rdns: string;
63+
targets?: { type: string, value: any }[],
6364
scopes?: AuthorizationScopes;
6465
}
6566
```
@@ -68,7 +69,7 @@ Whenever a new Wallet Provider is discovered the Blockchain Library would index
6869

6970
The parameters `name` and `icon` are used to display to the user to be easily recognizable while the `rdns` and `uuid` are only used internally for de-duping while they must always be unique, the `rdns` will always be the same but `uuid` is ephemeral per browser session.
7071

71-
The only optional parameter is `scopes` which is defined by CAIP-217 authorization specs that enables early discoverability and filtering of wallets based on RPC methods, notifications, documents and endpoints but also optional discovery of supported chains and even accounts.
72+
The optional parameters are `scopes`, which is defined by [CAIP-217] authorization specs that enables early discoverability and filtering of wallets based on RPC methods, notifications, documents and endpoints but also optional discovery of supported chains and even accounts, and `targets`, which accepts [CAIP-341] Extension ID as a valid target type for establishing connections with browser extension wallets via the [CAIP-294] `wallet_announce` wallet discovery event.
7273

7374
```typescript
7475
// Defined by CAIP-217

CAIPs/caip-294.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ The `walletData` object MUST include the following properties:
138138

139139
Additionally, the `walletData` object MAY include the following optional properties:
140140

141-
- `extensionId`: The canonical extension ID of the wallet provider for the active browser.
141+
- `targets`: An array of objects, with an object containing `type: "caip341"` and `value: <extension_id>` used to connect to wallets using `externally_connectable`. Important to note here that other CAIPs can extend this, and [CAIP-341][caip-341] is an example of a valid target type for this use case.
142142
- `scopes`: An object defining the authorization scopes supported by the wallet, as specified in CAIP-217.
143143

144144
```typescript
@@ -148,12 +148,8 @@ interface WalletData {
148148
name: string;
149149
icon: string;
150150
rdns: string;
151-
152151
// Optional properties
153-
target?: {
154-
origin?: string;
155-
extensionId?: string;
156-
}
152+
targets?: { type: string, value: any }[],
157153
scopes?: Caip217AuthorizationScopes;
158154
}
159155
```
@@ -166,7 +162,22 @@ const walletData = {
166162
name: "Example Wallet",
167163
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
168164
rdns: "com.example.wallet",
169-
extensionId: "abcdefghijklmnopqrstuvwxyz",
165+
targets: [
166+
{
167+
type: "caip341",
168+
value: "abcdefghijklmnopqrstuvwxyz"
169+
},
170+
{
171+
type: "caip315",
172+
value: true
173+
},
174+
{
175+
type: "caip316",
176+
value: {
177+
somethingElse: "hello"
178+
}
179+
},
180+
]
170181
scopes: {
171182
"eip155:1": {
172183
methods: ["eth_signTransaction", "eth_sendTransaction"],
@@ -176,20 +187,20 @@ const walletData = {
176187
}
177188
```
178189

179-
This `walletData` type is is a superset of `WalletAnnounceRequestParams` type described in the [CAIP-282][caip-282] standard, adding the optional `extensionId` property as it is only relevant for browser extension based wallets.
190+
This `walletData` type is a superset of `WalletAnnounceRequestParams` type described in the [CAIP-282][caip-282] standard, adding the optional `targets` property with the object defining `extensionId`, as it is only relevant for browser extension based wallets.
180191

181-
### ExtensionId
192+
### Targets
182193

183-
When the `extensionId` is included in the `walletData` object, it indicates that the wallet supports communication via the browser's `externally_connectable` API. In this case:
194+
When a `targets` property with the array containing an object with [`type: 'caip341'`][caip-341] is included in the `walletData` object, it indicates that the wallet expects communication via the browser's [`externally_connectable` API][externally_connectable]. In this case:
184195

185-
1. The dapp MUST use the `extensionId` to establish a connection with the wallet using the `externally_connectable` browser API.
196+
1. The dapp MUST use the `targets.find(({ type }) => type === "caip314").value` (an [`extensionId`][externally_connectable]) to establish a connection with the wallet using the `externally_connectable` browser API.
186197
2. All subsequent communication with the wallet (the "session") SHOULD be conducted over the `externally_connectable` API using `runtime.connect()` and `runtime.sendMessage()`.
187-
3. The dapp MUST NOT use the injected provider for communication when `extensionId` is present.
198+
3. The dapp MUST NOT use the injected provider for communication when `targets` with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is present.
188199

189200
Example of establishing a connection and sending a message:
190201

191202
```javascript
192-
const port = chrome.runtime.connect(walletData.extensionId);
203+
const port = chrome.runtime.connect(walletData.targets.value);
193204

194205
port.onMessage.addListener((message) => {
195206
// Handle incoming messages
@@ -205,7 +216,7 @@ port.postMessage({
205216
});
206217
```
207218

208-
If the `extensionId` is not present in the `walletData` object, the dapp SHOULD assume that communication will occur through the traditional injected provider method.
219+
If the `targets` object with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is not present in the `walletData` object, the dapp SHOULD assume that communication will occur through the traditional injected provider method.
209220

210221
#### Handshake
211222

@@ -500,11 +511,15 @@ TODO
500511
- [CAIP-27][caip-27] - Blockchain ID Specification
501512
- [CAIP-25][caip-25] - Blockchain ID Specification
502513
- [CAIP-282][caip-282] - Browser Wallet Discovery Interface
514+
- [CAIP-341][caip-341] - Extension ID Target Type Specification
515+
- [externally_connectable][externally_connectable] - Chrome's `externally_connectable` browser API documentation
503516

504517
[eip-6963]: https://eips.ethereum.org/EIPS/eip-6963
505518
[caip-27]: https://chainagnostic.org/CAIPs/caip-27
506519
[caip-25]: https://chainagnostic.org/CAIPs/caip-25
507520
[caip-282]: https://chainagnostic.org/CAIPs/caip-282
521+
[caip-341]: https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md
522+
[externally_connectable]: https://developer.chrome.com/docs/extensions/reference/manifest/externally-connectable
508523

509524
## Copyright
510525

CAIPs/caip-295.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ This provides the foundation for any Wallet Provider to interface with a Decentr
4747

4848
Different loading times can be affected by multiple factors, which makes it non-deterministic to publish and listen to messages from different sources within the browser.
4949

50+
#### Target Origin
51+
52+
TODO Make Proposal For Target Origin As Valid Target Type For Wallet Data.
53+
5054
#### Discovery
5155

5256
Both Wallet Providers and blockchain libraries must listen to incoming messages that might be published after their initialization. Additionally both Wallet Providers and blockchain libraries must publish a message to both announce themselves and their intent to connect, respectively.
@@ -56,7 +60,10 @@ Here is the expected logic from the Blockchain Library:
5660
```typescript
5761
interface WalletMapEntry {
5862
data: WalletAnnounceRequestParams;
59-
targetOrigin: string;
63+
targets: {
64+
type: <caip-id-for-target-origin>;
65+
value: <target-origin>
66+
}[]
6067
}
6168

6269
const wallets: Record<string, WalletMapEntry> = {}
@@ -67,7 +74,7 @@ window.addEventListener("message", (event) => {
6774
// when an announce message was received then the library can index it by uuid
6875
wallets[event.data.params.uuid] = {
6976
params: event.data.params,
70-
targetOrigin: event.targetOrigin
77+
targetOrigin: event.target.value
7178
}
7279
}
7380
});
@@ -158,7 +165,10 @@ Logic from the Blockchain Library:
158165
// also by posting a prompt message
159166
interface WalletMapEntry {
160167
data: WalletAnnounceRequestParams;
161-
targetOrigin: string;
168+
targets: {
169+
type: <caip-id-for-target-origin>;
170+
value: <target-origin>
171+
}[]
162172
}
163173

164174
const wallets: Record<string, WalletMapEntry> = {}
@@ -168,7 +178,7 @@ window.addEventListener("message", (event) => {
168178
// when an announce message was received then the library can index it by uuid
169179
wallets[event.data.params.uuid] = {
170180
params: event.data.params,
171-
targetOrigin: event.targetOrigin
181+
targetOrigin: event.targets.find(({ type }) => type === "caip295")?.value
172182
}
173183
}
174184
});
@@ -208,7 +218,7 @@ const sessionRequest = {
208218
let sessionResult = {}
209219

210220
window.addEventListener("message", (event) => {
211-
if (event.targetOrigin !== wallets[selected_uuid].targetOrigin) return;
221+
if (event.targets.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return;
212222
if (event.data.id === sessionRequest.id) {
213223
// Get JSON-RPC response
214224
if (event.data.error) {
@@ -247,7 +257,7 @@ const signingRequest = {
247257
let signingResult = {}
248258

249259
window.addEventListener("message", (event) => {
250-
if (event.targetOrigin !== wallets[selected_uuid].targetOrigin) return;
260+
if (event.targets.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return;
251261
if (event.data.id === signingRequest.id) {
252262
// Get JSON-RPC response
253263
if (event.data.error) {
@@ -309,7 +319,7 @@ window.addEventListener("message", (event) => {
309319
if (checkSupportedScopes(event.data.params)) {
310320
// prompt user to approve session
311321
// persist the targetOrigin for sessionRequest
312-
sessionOrigin = event.targetOrigin
322+
sessionOrigin = event.targets.find(({ type }) => type === "caip295")?.value
313323
}
314324
}
315325
});
@@ -344,7 +354,7 @@ window.postMessage(sessionResponse, sessionOrigin);
344354
let signingRequest = {}
345355

346356
window.addEventListener("message", (event) => {
347-
if (event.targetOrigin !== sessionOrigin) return;
357+
if (event.targets.find(({ type }) => type === "caip295")?.value !== sessionOrigin) return;
348358
if (event.data.method === "wallet_createSession" && event.data.params.sessionId === walletData.uuid) {
349359
signingRequest = event.data.params
350360
}

0 commit comments

Comments
 (0)