Skip to content

Commit 9ad1ae0

Browse files
nathanbogalerphair
andauthored
CIP-0142? | Web-Wallet Bridge - Network Determination (cardano-foundation#972)
* feat: CIP-30 extension to capture network magic * Update CIP-XXXX/README.md updated the CIP number in readme Co-authored-by: Robert Phair <[email protected]> * Update CIP-XXXX/README.md added description to the motivation section Co-authored-by: Robert Phair <[email protected]> * Update CIP-XXXX/README.md added description to the rationale section Co-authored-by: Robert Phair <[email protected]> * CIP-0142: changed from CIP-XXXX, readme updated with feedback * CIP-network-magic: removed the assigned CIP number, added discussion link * Revert "CIP-network-magic: removed the assigned CIP number, added discussion link" This reverts commit daae1b8. Added cardano-foundation#971 to the discussion * CIP-0142: added cardano-foundation#972 to discussions * fix: removed temporary from extension identifier * fix: removed zero padding from the extension naming * fix: adjusted the zero padding inconsistency * fix: acceptance criteria modifications * fix: implemented wallet providers update * fix: need confirmation on Lace * Update CIP-0142/README.md updated Co-authored-by: Robert Phair <[email protected]> * fix: handled duplicated lines --------- Co-authored-by: Robert Phair <[email protected]>
1 parent f305b75 commit 9ad1ae0

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

CIP-0142/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
CIP: 142
3+
Title: Web-Wallet Bridge - Network Determination
4+
Status: Proposed
5+
Category: Wallets
6+
Authors:
7+
- Steven Johnson <[email protected]>
8+
- Nathan Bogale <[email protected]>
9+
Implementors:
10+
- Lace <https://www.lace.io/>
11+
Discussions:
12+
- https://github.com/cardano-foundation/CIPs/pull/209
13+
- https://github.com/cardano-foundation/CIPs/pull/323
14+
- https://github.com/cardano-foundation/CIPs/pull/960
15+
- https://github.com/cardano-foundation/CIPs/pull/972
16+
Created: 2024-01-17
17+
License: CC-BY-4.0
18+
---
19+
20+
## Abstract
21+
22+
This CIP extends CIP-0030 to provide functionality for dApps to determine the specific network magic number of the connected Cardano network. While CIP-0030's `getNetworkId()` allows distinguishing between mainnet and testnet, this extension enables dApps to identify specific test networks through their magic numbers.
23+
24+
## Motivation: why is this CIP necessary?
25+
26+
Currently, CIP-0030 only provides a way to distinguish between mainnet (1) and testnet (0) through the `getNetworkId()` function. However, there are multiple test networks in the Cardano ecosystem (preview, preprod, etc.), each with its own magic number. dApps often need to know the specific test network they're connected to for proper configuration and interaction. This extension addresses this limitation by providing access to the network magic number.
27+
28+
## Specification
29+
30+
### Extension Identifier
31+
32+
This extension uses the following identifier:
33+
```ts
34+
{ "cip": 142 }
35+
```
36+
37+
### API Extension
38+
39+
When this extension is enabled, the following function is added to the API under the `cip-142` namespace:
40+
41+
#### `api.cip142.getNetworkMagic(): Promise<number>`
42+
43+
Errors: `APIError`
44+
45+
Returns the magic number of the currently connected network. For example:
46+
- Mainnet: 764824073
47+
- Preview Testnet: 2
48+
- Preprod Testnet: 1
49+
- Custom Testnet: (other values)
50+
51+
This function will return the same value unless the connected account changes networks.
52+
53+
Example usage:
54+
```typescript
55+
const api = await window.cardano.lace.enable({
56+
extensions: [{ cip: 142 }]
57+
});
58+
59+
const magic = await api.cip142.getNetworkMagic();
60+
console.log(`Connected to network with magic number: ${magic}`);
61+
```
62+
63+
### Error Handling
64+
65+
The function uses the existing `APIError` type from CIP-0030 with the following error codes:
66+
- `InvalidRequest` (-1): If the request is malformed
67+
- `InternalError` (-2): If an error occurs while retrieving the magic number
68+
- `Refused` (-3): If access to the magic number is refused
69+
- `AccountChange` (-4): If the account has changed
70+
71+
## Rationale: how does this CIP achieve its goals?
72+
73+
### Why a New Extension?
74+
75+
While CIP-0030's `getNetworkId()` provides basic network identification, the growing Cardano ecosystem requires more specific network identification, especially for development and testing purposes. This extension:
76+
77+
1. Maintains backward compatibility by not modifying existing CIP-0030 functionality
78+
2. Uses explicit namespacing to avoid conflicts
79+
3. Provides a simple, focused solution to a specific need
80+
81+
### Design Decisions
82+
83+
1. **Explicit Namespacing**: The extension uses the `cip-142` namespace to clearly separate its functionality from the base CIP-0030 API.
84+
2. **Promise-based API**: Follows CIP-0030's pattern of returning Promises for consistency.
85+
3. **Reuse of Error Types**: Leverages existing error types from CIP-0030 to maintain consistency.
86+
87+
## Path to Active
88+
89+
### Acceptance Criteria
90+
91+
- [ ] Implementation by at least three wallet providers
92+
- [x] Eternl
93+
- [ ] Lace
94+
- [ ] Implementation by at least three web app providers
95+
- [ ] Implementation by at one serialisation library or SDK
96+
- [ ] No reported conflicts with other CIP-0030 extensions
97+
98+
### Implementation Plan
99+
100+
1. **Reach out to the Lace wallet team/architects**
101+
- Validate technical feasibility of proposed changes
102+
- Identify priorities for this implementation
103+
- Identify potential integration challenges
104+
2. **Involve ops and products team to drive the plan further**
105+
- First implementation on the Catalyst playground
106+
- Create a plan, validate and collect feedback and suggestions
107+
3. **Implement the CIP-0142 extension in the Lace wallet**
108+
- Implement and use the CIP-0142 extension in the Catalyst pla
109+
- Validate against all specified acceptance criteria
110+
4. **Reach out to other Cardano wallet providers**
111+
- Introduce the CIP-0142 extension to other wallet providers (Nami)
112+
- Collect feedback and suggestions
113+
- Validate against acceptance criteria
114+
115+
**Note:** This implementation plan is subject to iterative refinement based on ongoing technical assessments and stakeholder feedback.
116+
117+
## Copyright
118+
119+
This CIP is licensed under [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/legalcode).

0 commit comments

Comments
 (0)