From c06811beb1faca27c936c7232220625fc004ffdb Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Thu, 12 Dec 2024 15:48:26 +0100 Subject: [PATCH 1/8] feat: update caip-294 to fit extension id as valid target type --- CAIPs/caip-294.md | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/CAIPs/caip-294.md b/CAIPs/caip-294.md index 41f48eef..7746fc05 100644 --- a/CAIPs/caip-294.md +++ b/CAIPs/caip-294.md @@ -138,7 +138,7 @@ The `walletData` object MUST include the following properties: Additionally, the `walletData` object MAY include the following optional properties: -- `extensionId`: The canonical extension ID of the wallet provider for the active browser. +- `target`: The object containing `extensionId` type used to connect to wallets using `externally_connectable` . For reference on this specification, see [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md). - `scopes`: An object defining the authorization scopes supported by the wallet, as specified in CAIP-217. ```typescript @@ -148,9 +148,11 @@ interface WalletData { name: string; icon: string; rdns: string; - // Optional properties - extensionId?: string; + target?: { + type: "caip341", + value: + } scopes?: Caip217AuthorizationScopes; } ``` @@ -163,7 +165,10 @@ const walletData = { name: "Example Wallet", icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", rdns: "com.example.wallet", - extensionId: "abcdefghijklmnopqrstuvwxyz", + target: { + type: "caip341", + value: "abcdefghijklmnopqrstuvwxyz" + } scopes: { "eip155:1": { methods: ["eth_signTransaction", "eth_sendTransaction"], @@ -173,20 +178,20 @@ const walletData = { } ``` -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. +This `walletData` type is is a superset of `WalletAnnounceRequestParams` type described in the [CAIP-282][caip-282] standard, adding the optional `target` property with the `extensionId` as it is only relevant for browser extension based wallets. -### ExtensionId +### Target -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: +When the `target` with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is included in the `walletData` object, it indicates that the wallet supports communication via the browser's `externally_connectable` API. In this case: -1. The dapp MUST use the `extensionId` to establish a connection with the wallet using the `externally_connectable` browser API. +1. The dapp MUST use the `target.value` (represents `extensionId`) to establish a connection with the wallet using the `externally_connectable` browser API. 2. All subsequent communication with the wallet (the "session") SHOULD be conducted over the `externally_connectable` API using `runtime.connect()` and `runtime.sendMessage()`. -3. The dapp MUST NOT use the injected provider for communication when `extensionId` is present. +3. The dapp MUST NOT use the injected provider for communication when `target` with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is present. Example of establishing a connection and sending a message: ```javascript -const port = chrome.runtime.connect(walletData.extensionId); +const port = chrome.runtime.connect(walletData.target.value); port.onMessage.addListener((message) => { // Handle incoming messages @@ -202,7 +207,7 @@ port.postMessage({ }); ``` -If the `extensionId` is not present in the `walletData` object, the dapp SHOULD assume that communication will occur through the traditional injected provider method. +If the `target` 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. #### Handshake @@ -497,11 +502,13 @@ TODO - [CAIP-27][caip-27] - Blockchain ID Specification - [CAIP-25][caip-25] - Blockchain ID Specification - [CAIP-282][caip-282] - Browser Wallet Discovery Interface +- [CAIP-341][caip-341] - Extension ID Target Type Specification [eip-6963]: https://eips.ethereum.org/EIPS/eip-6963 [caip-27]: https://chainagnostic.org/CAIPs/caip-27 [caip-25]: https://chainagnostic.org/CAIPs/caip-25 [caip-282]: https://chainagnostic.org/CAIPs/caip-282 +[caip-341]: https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md ## Copyright From 41fc1c6fe957a158ac03ac5417ba7db0bd4a8cd6 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Thu, 12 Dec 2024 18:18:37 +0100 Subject: [PATCH 2/8] refactor: proposed changes by adonesky1 --- CAIPs/caip-282.md | 6 +++++- CAIPs/caip-294.md | 8 +++++--- CAIPs/caip-295.md | 26 ++++++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CAIPs/caip-282.md b/CAIPs/caip-282.md index c3091372..09cba454 100644 --- a/CAIPs/caip-282.md +++ b/CAIPs/caip-282.md @@ -60,6 +60,10 @@ interface WalletAnnounceRequestParams { name: string; icon: string; rdns: string; + target?: { + type: "caip341", + value: + } scopes?: AuthorizationScopes; } ``` @@ -68,7 +72,7 @@ Whenever a new Wallet Provider is discovered the Blockchain Library would index 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. -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. +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 `target`, which is defined by [CAIP-341] which defines the `extensionId` type as a valid target type for establishing connections with browser extension wallets via the [CAIP-294] `wallet_announce` wallet discovery event. ```typescript // Defined by CAIP-217 diff --git a/CAIPs/caip-294.md b/CAIPs/caip-294.md index 7746fc05..9c0d8c04 100644 --- a/CAIPs/caip-294.md +++ b/CAIPs/caip-294.md @@ -138,7 +138,7 @@ The `walletData` object MUST include the following properties: Additionally, the `walletData` object MAY include the following optional properties: -- `target`: The object containing `extensionId` type used to connect to wallets using `externally_connectable` . For reference on this specification, see [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md). +- `target`: An object containing `type: caip341` and `value: ` used to connect to wallets using `externally_connectable` . For reference on this specification, see [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md). - `scopes`: An object defining the authorization scopes supported by the wallet, as specified in CAIP-217. ```typescript @@ -182,9 +182,9 @@ This `walletData` type is is a superset of `WalletAnnounceRequestParams` type de ### Target -When the `target` with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is included in the `walletData` object, it indicates that the wallet supports communication via the browser's `externally_connectable` API. In this case: +When a `target` property with the [`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: -1. The dapp MUST use the `target.value` (represents `extensionId`) to establish a connection with the wallet using the `externally_connectable` browser API. +1. The dapp MUST use the `target.value` (an [`extensionId`][externally_connectable]) to establish a connection with the wallet using the `externally_connectable` browser API. 2. All subsequent communication with the wallet (the "session") SHOULD be conducted over the `externally_connectable` API using `runtime.connect()` and `runtime.sendMessage()`. 3. The dapp MUST NOT use the injected provider for communication when `target` with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is present. @@ -503,12 +503,14 @@ TODO - [CAIP-25][caip-25] - Blockchain ID Specification - [CAIP-282][caip-282] - Browser Wallet Discovery Interface - [CAIP-341][caip-341] - Extension ID Target Type Specification +- [externally_connectable][externally_connectable] - Chrome's `externally_connectable` browser API documentation [eip-6963]: https://eips.ethereum.org/EIPS/eip-6963 [caip-27]: https://chainagnostic.org/CAIPs/caip-27 [caip-25]: https://chainagnostic.org/CAIPs/caip-25 [caip-282]: https://chainagnostic.org/CAIPs/caip-282 [caip-341]: https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md +[externally_connectable]: https://developer.chrome.com/docs/extensions/reference/manifest/externally-connectable ## Copyright diff --git a/CAIPs/caip-295.md b/CAIPs/caip-295.md index 05c30dcb..dd09b9c2 100644 --- a/CAIPs/caip-295.md +++ b/CAIPs/caip-295.md @@ -47,6 +47,10 @@ This provides the foundation for any Wallet Provider to interface with a Decentr 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. +#### Target Origin + +TODO Make Proposal For Target Origin As Valid Target Type For Wallet Data. + #### Discovery 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: ```typescript interface WalletMapEntry { data: WalletAnnounceRequestParams; - targetOrigin: string; + target: { + type: ; + value: + } } const wallets: Record = {} @@ -67,7 +74,7 @@ window.addEventListener("message", (event) => { // when an announce message was received then the library can index it by uuid wallets[event.data.params.uuid] = { params: event.data.params, - targetOrigin: event.targetOrigin + targetOrigin: event.target.value } } }); @@ -158,7 +165,10 @@ Logic from the Blockchain Library: // also by posting a prompt message interface WalletMapEntry { data: WalletAnnounceRequestParams; - targetOrigin: string; + target: { + type: ; + value: + } } const wallets: Record = {} @@ -168,7 +178,7 @@ window.addEventListener("message", (event) => { // when an announce message was received then the library can index it by uuid wallets[event.data.params.uuid] = { params: event.data.params, - targetOrigin: event.targetOrigin + targetOrigin: event.target.value } } }); @@ -208,7 +218,7 @@ const sessionRequest = { let sessionResult = {} window.addEventListener("message", (event) => { - if (event.targetOrigin !== wallets[selected_uuid].targetOrigin) return; + if (event.target.value !== wallets[selected_uuid].targetOrigin) return; if (event.data.id === sessionRequest.id) { // Get JSON-RPC response if (event.data.error) { @@ -247,7 +257,7 @@ const signingRequest = { let signingResult = {} window.addEventListener("message", (event) => { - if (event.targetOrigin !== wallets[selected_uuid].targetOrigin) return; + if (event.target.value !== wallets[selected_uuid].targetOrigin) return; if (event.data.id === signingRequest.id) { // Get JSON-RPC response if (event.data.error) { @@ -309,7 +319,7 @@ window.addEventListener("message", (event) => { if (checkSupportedScopes(event.data.params)) { // prompt user to approve session // persist the targetOrigin for sessionRequest - sessionOrigin = event.targetOrigin + sessionOrigin = event.target.value } } }); @@ -344,7 +354,7 @@ window.postMessage(sessionResponse, sessionOrigin); let signingRequest = {} window.addEventListener("message", (event) => { - if (event.targetOrigin !== sessionOrigin) return; + if (event.target.value !== sessionOrigin) return; if (event.data.method === "wallet_createSession" && event.data.params.sessionId === walletData.uuid) { signingRequest = event.data.params } From 9623140975cb97d9b80b074da7cad4b1e2eb9b71 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Thu, 12 Dec 2024 19:43:14 +0100 Subject: [PATCH 3/8] refactor: improvement suggestions by jiexi --- CAIPs/caip-282.md | 2 +- CAIPs/caip-294.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CAIPs/caip-282.md b/CAIPs/caip-282.md index 09cba454..800aab41 100644 --- a/CAIPs/caip-282.md +++ b/CAIPs/caip-282.md @@ -72,7 +72,7 @@ Whenever a new Wallet Provider is discovered the Blockchain Library would index 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. -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 `target`, which is defined by [CAIP-341] which defines the `extensionId` type as a valid target type for establishing connections with browser extension wallets via the [CAIP-294] `wallet_announce` wallet discovery event. +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 `target`, 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. ```typescript // Defined by CAIP-217 diff --git a/CAIPs/caip-294.md b/CAIPs/caip-294.md index 9c0d8c04..1bd1e475 100644 --- a/CAIPs/caip-294.md +++ b/CAIPs/caip-294.md @@ -138,7 +138,7 @@ The `walletData` object MUST include the following properties: Additionally, the `walletData` object MAY include the following optional properties: -- `target`: An object containing `type: caip341` and `value: ` used to connect to wallets using `externally_connectable` . For reference on this specification, see [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md). +- `target`: An object containing `type: "caip341"` and `value: ` 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. - `scopes`: An object defining the authorization scopes supported by the wallet, as specified in CAIP-217. ```typescript From 678db0733bc599455f75c470587fe2f1b3faf584 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Tue, 28 Jan 2025 21:01:12 +0100 Subject: [PATCH 4/8] feat: update specifications as per consensus --- CAIPs/caip-282.md | 5 +---- CAIPs/caip-294.md | 35 ++++++++++++++++++++++------------- CAIPs/caip-295.md | 14 +++++++------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/CAIPs/caip-282.md b/CAIPs/caip-282.md index 800aab41..d270b3a7 100644 --- a/CAIPs/caip-282.md +++ b/CAIPs/caip-282.md @@ -60,10 +60,7 @@ interface WalletAnnounceRequestParams { name: string; icon: string; rdns: string; - target?: { - type: "caip341", - value: - } + target?: { type: string, value: any }[], scopes?: AuthorizationScopes; } ``` diff --git a/CAIPs/caip-294.md b/CAIPs/caip-294.md index 1bd1e475..666410b1 100644 --- a/CAIPs/caip-294.md +++ b/CAIPs/caip-294.md @@ -138,7 +138,7 @@ The `walletData` object MUST include the following properties: Additionally, the `walletData` object MAY include the following optional properties: -- `target`: An object containing `type: "caip341"` and `value: ` 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. +- `target`: An array of objects, with an object containing `type: "caip341"` and `value: ` 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. - `scopes`: An object defining the authorization scopes supported by the wallet, as specified in CAIP-217. ```typescript @@ -149,10 +149,7 @@ interface WalletData { icon: string; rdns: string; // Optional properties - target?: { - type: "caip341", - value: - } + target?: { type: string, value: any }[], scopes?: Caip217AuthorizationScopes; } ``` @@ -165,10 +162,22 @@ const walletData = { name: "Example Wallet", icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", rdns: "com.example.wallet", - target: { - type: "caip341", - value: "abcdefghijklmnopqrstuvwxyz" - } + target: [ + { + type: "caip341", + value: "abcdefghijklmnopqrstuvwxyz" + }, + { + type: "caip315", + value: true + }, + { + type: "caip316", + value: { + somethingElse: "hello" + } + }, + ] scopes: { "eip155:1": { methods: ["eth_signTransaction", "eth_sendTransaction"], @@ -178,13 +187,13 @@ const walletData = { } ``` -This `walletData` type is is a superset of `WalletAnnounceRequestParams` type described in the [CAIP-282][caip-282] standard, adding the optional `target` property with the `extensionId` as it is only relevant for browser extension based wallets. +This `walletData` type is a superset of `WalletAnnounceRequestParams` type described in the [CAIP-282][caip-282] standard, adding the optional `target` property with the object defining `extensionId`, as it is only relevant for browser extension based wallets. ### Target -When a `target` property with the [`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: +When a `target` 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: -1. The dapp MUST use the `target.value` (an [`extensionId`][externally_connectable]) to establish a connection with the wallet using the `externally_connectable` browser API. +1. The dapp MUST use the `target.find(({ type }) => type === "caip314").value` (an [`extensionId`][externally_connectable]) to establish a connection with the wallet using the `externally_connectable` browser API. 2. All subsequent communication with the wallet (the "session") SHOULD be conducted over the `externally_connectable` API using `runtime.connect()` and `runtime.sendMessage()`. 3. The dapp MUST NOT use the injected provider for communication when `target` with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is present. @@ -207,7 +216,7 @@ port.postMessage({ }); ``` -If the `target` 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. +If the `target` 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. #### Handshake diff --git a/CAIPs/caip-295.md b/CAIPs/caip-295.md index dd09b9c2..0ff59f04 100644 --- a/CAIPs/caip-295.md +++ b/CAIPs/caip-295.md @@ -63,7 +63,7 @@ interface WalletMapEntry { target: { type: ; value: - } + }[] } const wallets: Record = {} @@ -168,7 +168,7 @@ interface WalletMapEntry { target: { type: ; value: - } + }[] } const wallets: Record = {} @@ -178,7 +178,7 @@ window.addEventListener("message", (event) => { // when an announce message was received then the library can index it by uuid wallets[event.data.params.uuid] = { params: event.data.params, - targetOrigin: event.target.value + targetOrigin: event.target.find(({ type }) => type === "caip295")?.value } } }); @@ -218,7 +218,7 @@ const sessionRequest = { let sessionResult = {} window.addEventListener("message", (event) => { - if (event.target.value !== wallets[selected_uuid].targetOrigin) return; + if (event.target.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return; if (event.data.id === sessionRequest.id) { // Get JSON-RPC response if (event.data.error) { @@ -257,7 +257,7 @@ const signingRequest = { let signingResult = {} window.addEventListener("message", (event) => { - if (event.target.value !== wallets[selected_uuid].targetOrigin) return; + if (event.target.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return; if (event.data.id === signingRequest.id) { // Get JSON-RPC response if (event.data.error) { @@ -319,7 +319,7 @@ window.addEventListener("message", (event) => { if (checkSupportedScopes(event.data.params)) { // prompt user to approve session // persist the targetOrigin for sessionRequest - sessionOrigin = event.target.value + sessionOrigin = event.target.find(({ type }) => type === "caip295")?.value } } }); @@ -354,7 +354,7 @@ window.postMessage(sessionResponse, sessionOrigin); let signingRequest = {} window.addEventListener("message", (event) => { - if (event.target.value !== sessionOrigin) return; + if (event.target.find(({ type }) => type === "caip295")?.value !== sessionOrigin) return; if (event.data.method === "wallet_createSession" && event.data.params.sessionId === walletData.uuid) { signingRequest = event.data.params } From 9469cba8eb85ab573d6fad9dfd39d52c41ea9afb Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Mon, 12 May 2025 12:18:36 +0200 Subject: [PATCH 5/8] Update CAIPs/caip-282.md Co-authored-by: jiexi --- CAIPs/caip-282.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CAIPs/caip-282.md b/CAIPs/caip-282.md index b3466c9d..6b62f6d3 100644 --- a/CAIPs/caip-282.md +++ b/CAIPs/caip-282.md @@ -60,7 +60,7 @@ interface WalletAnnounceRequestParams { name: string; icon: string; rdns: string; - target?: { type: string, value: any }[], + targets?: { type: string, value: any }[], scopes?: AuthorizationScopes; } ``` From 2a5de02df93ea27d247f15bbddc7524611f2d48b Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Mon, 12 May 2025 12:18:45 +0200 Subject: [PATCH 6/8] Update CAIPs/caip-294.md Co-authored-by: jiexi --- CAIPs/caip-294.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CAIPs/caip-294.md b/CAIPs/caip-294.md index 666410b1..c2f14631 100644 --- a/CAIPs/caip-294.md +++ b/CAIPs/caip-294.md @@ -138,7 +138,7 @@ The `walletData` object MUST include the following properties: Additionally, the `walletData` object MAY include the following optional properties: -- `target`: An array of objects, with an object containing `type: "caip341"` and `value: ` 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. +- `targets`: An array of objects, with an object containing `type: "caip341"` and `value: ` 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. - `scopes`: An object defining the authorization scopes supported by the wallet, as specified in CAIP-217. ```typescript From 3bda6bf805605bd035ccd5dcfdfb1ba13c09cfb1 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Mon, 12 May 2025 12:22:43 +0200 Subject: [PATCH 7/8] Apply suggestions from code review --- CAIPs/caip-282.md | 2 +- CAIPs/caip-294.md | 16 ++++++++-------- CAIPs/caip-295.md | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CAIPs/caip-282.md b/CAIPs/caip-282.md index 6b62f6d3..804b0020 100644 --- a/CAIPs/caip-282.md +++ b/CAIPs/caip-282.md @@ -69,7 +69,7 @@ Whenever a new Wallet Provider is discovered the Blockchain Library would index 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. -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 `target`, 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. +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. ```typescript // Defined by CAIP-217 diff --git a/CAIPs/caip-294.md b/CAIPs/caip-294.md index c2f14631..c4a2de08 100644 --- a/CAIPs/caip-294.md +++ b/CAIPs/caip-294.md @@ -149,7 +149,7 @@ interface WalletData { icon: string; rdns: string; // Optional properties - target?: { type: string, value: any }[], + targets?: { type: string, value: any }[], scopes?: Caip217AuthorizationScopes; } ``` @@ -162,7 +162,7 @@ const walletData = { name: "Example Wallet", icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", rdns: "com.example.wallet", - target: [ + targets: [ { type: "caip341", value: "abcdefghijklmnopqrstuvwxyz" @@ -189,18 +189,18 @@ const walletData = { This `walletData` type is a superset of `WalletAnnounceRequestParams` type described in the [CAIP-282][caip-282] standard, adding the optional `target` property with the object defining `extensionId`, as it is only relevant for browser extension based wallets. -### Target +### Targets -When a `target` 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: +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: -1. The dapp MUST use the `target.find(({ type }) => type === "caip314").value` (an [`extensionId`][externally_connectable]) to establish a connection with the wallet using the `externally_connectable` browser API. +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. 2. All subsequent communication with the wallet (the "session") SHOULD be conducted over the `externally_connectable` API using `runtime.connect()` and `runtime.sendMessage()`. -3. The dapp MUST NOT use the injected provider for communication when `target` with [CAIP-341](https://github.com/ChainAgnostic/CAIPs/blob/656551f800843b92243fb08ca6c24e805ad149a3/CAIPs/caip-341.md) type is present. +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. Example of establishing a connection and sending a message: ```javascript -const port = chrome.runtime.connect(walletData.target.value); +const port = chrome.runtime.connect(walletData.targets.value); port.onMessage.addListener((message) => { // Handle incoming messages @@ -216,7 +216,7 @@ port.postMessage({ }); ``` -If the `target` 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. +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. #### Handshake diff --git a/CAIPs/caip-295.md b/CAIPs/caip-295.md index 0ff59f04..0fd6f3e4 100644 --- a/CAIPs/caip-295.md +++ b/CAIPs/caip-295.md @@ -60,7 +60,7 @@ Here is the expected logic from the Blockchain Library: ```typescript interface WalletMapEntry { data: WalletAnnounceRequestParams; - target: { + targets: { type: ; value: }[] @@ -165,7 +165,7 @@ Logic from the Blockchain Library: // also by posting a prompt message interface WalletMapEntry { data: WalletAnnounceRequestParams; - target: { + targets: { type: ; value: }[] @@ -178,7 +178,7 @@ window.addEventListener("message", (event) => { // when an announce message was received then the library can index it by uuid wallets[event.data.params.uuid] = { params: event.data.params, - targetOrigin: event.target.find(({ type }) => type === "caip295")?.value + targetOrigin: event.targets.find(({ type }) => type === "caip295")?.value } } }); @@ -218,7 +218,7 @@ const sessionRequest = { let sessionResult = {} window.addEventListener("message", (event) => { - if (event.target.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return; + if (event.targets.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return; if (event.data.id === sessionRequest.id) { // Get JSON-RPC response if (event.data.error) { @@ -257,7 +257,7 @@ const signingRequest = { let signingResult = {} window.addEventListener("message", (event) => { - if (event.target.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return; + if (event.targets.find(({ type }) => type === "caip295")?.value !== wallets[selected_uuid].targetOrigin) return; if (event.data.id === signingRequest.id) { // Get JSON-RPC response if (event.data.error) { @@ -319,7 +319,7 @@ window.addEventListener("message", (event) => { if (checkSupportedScopes(event.data.params)) { // prompt user to approve session // persist the targetOrigin for sessionRequest - sessionOrigin = event.target.find(({ type }) => type === "caip295")?.value + sessionOrigin = event.targets.find(({ type }) => type === "caip295")?.value } } }); @@ -354,7 +354,7 @@ window.postMessage(sessionResponse, sessionOrigin); let signingRequest = {} window.addEventListener("message", (event) => { - if (event.target.find(({ type }) => type === "caip295")?.value !== sessionOrigin) return; + if (event.targets.find(({ type }) => type === "caip295")?.value !== sessionOrigin) return; if (event.data.method === "wallet_createSession" && event.data.params.sessionId === walletData.uuid) { signingRequest = event.data.params } From c115a2e285aa253c78b57dc11282451e22ffc9f4 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Mon, 12 May 2025 12:24:02 +0200 Subject: [PATCH 8/8] Apply suggestions from code review --- CAIPs/caip-294.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CAIPs/caip-294.md b/CAIPs/caip-294.md index c4a2de08..ba1f5748 100644 --- a/CAIPs/caip-294.md +++ b/CAIPs/caip-294.md @@ -187,7 +187,7 @@ const walletData = { } ``` -This `walletData` type is a superset of `WalletAnnounceRequestParams` type described in the [CAIP-282][caip-282] standard, adding the optional `target` property with the object defining `extensionId`, as it is only relevant for browser extension based wallets. +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. ### Targets