Skip to content

Commit

Permalink
Merge branch 'eip155-caip10/typo-in-regex' of https://github.com/chai…
Browse files Browse the repository at this point in the history
…nagnostic/namespaces into eip155-caip10/typo-in-regex
  • Loading branch information
bumblefudge committed Sep 12, 2024
2 parents e4c41b5 + d8c6101 commit f58b044
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 1 deletion.
26 changes: 26 additions & 0 deletions conflux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
namespace-identifier: conflux
title: Conflux Network
author: iosh (@iosh)
status: Draft
type: Informational
created: 2024-08-09
---

# Namespace for Conflux Network blockchains

This document defines the applicability of CAIP schemes to the blockchain of the Conflux network (core space) ecosystem.

## Syntax

The namespace "conflux" refers to the Conflux Network(core space), its forks, devnets and testnets.

## References

[Conflux network website]: https://confluxnetwork.org/
[Conflux Docs site]: https://doc.confluxnetwork.org/docs/core/core-space-basics/addresses
[Addresses]: https://doc.confluxnetwork.org/docs/core/core-space-basics/addresses

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
127 changes: 127 additions & 0 deletions conflux/caip10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
namespace-identifier: conflux-caip10
title: Conflux Namespace - Addresses
author: iosh(@iosh)
status: Draft
type: Standard
created: 2024-08-09
requires: ["CAIP-2", "CAIP-10"]
---

# CAIP-10

_For context, see the [CAIP-10][] specification._

## Rationale

The Conflux Network EOA address is a base32-encoded address.

These are derived directly from the hexadecimal-encoded public keys corresponding to the private keys controlling them, but calculated over a network identifier, address type, and checksum value, address including a distinctive network prefix ("cfx" "cfxtest" or "net[networkId]").

The Conflux core space hex address is a concatenation of a 4-bit type indicator and the rightmost 156-bit Keccak digest of the associated public key of the private key.

There are currently three types of indicators:

(0x)1: Represents the address of an EOA account.
(0x)8: Represents the address of a contract.
(0x)0: Represents the address of an internal contract.

Constructing an address:

```js
encode(0x1a2f80341409639ea6a35bbcab8299066109aa55, "cfx") // cfx:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg
```

1. Network Prefix:

- `cfx` for mainnet, i.e. network ID `1029`
- `cfxtest` for testnet, i.e. network ID `1`
- `net{X}` where X is the integer network ID for any other network

Example address from mainnet: `cfx`

2. Payload: concatenate the version-byte (currently `0x00`) with the 20-byte hexadecimal address to produce a byte array 21 bytes in length.

Payload: `[0x00, 0x1a, 0x2f, 0x80, 0x34, 0x14, 0x09, 0x63, 0x9e, 0xa6, 0xa3, 0x5b, 0xbc, 0xab, 0x82, 0x99, 0x06, 0x61, 0x09, 0xaa, 0x55]`

3. Base32 encode: encode the above result left-to-right, mapping each 5-bit sequence to the corresponding ASCII character, then pad to the right with zero bits (2-bit `0x00`-padding) to complete any unfinished chunk at the end.

5-bit base32: `[0x00, 0x00, 0x0d, 0x02, 0x1f, 0x00, 0x01, 0x14, 0x02, 0x10, 0x04, 0x16, 0x07, 0x07, 0x15, 0x06, 0x14, 0x0d, 0x0d, 0x1b, 0x19, 0x0a, 0x1c, 0x02, 0x13, 0x04, 0x03, 0x06, 0x02, 0x02, 0x0d, 0x0a, 0x0a, 0x14]`

base32-encoded: `aarc9abycue0hhzgyrr53m6cxedgccrmmy`

4. Checksum: Compute the checksum input from the preceding data as follows:

4.1 The lower 5 bits of each character of the network-prefix, e.g. "cfx..." becomes 0x03, 0x06, 0x18, ...

network-prefix cfx: `0x03, 0x06, 0x18`

4.2 A zero for the separator (5 zero bits).

`0x00`

4.3 The payload by chunks of 5 bits. If necessary, the payload is padded to the right with zero bits to complete any unfinished chunk at the end.

checksum input data:

```js
//↓ network-prefix //↓separator //↓ 5-bit base32 with zero padding
[0x03, 0x06, 0x18, 0x00, 0x00, 0x00, 0x0d, 0x02, 0x1f, 0x00, 0x01, 0x14, 0x02, 0x10, 0x04, 0x16, 0x07, 0x07, 0x15, 0x06, 0x14, 0x0d, 0x0d, 0x1b, 0x19, 0x0a, 0x1c, 0x02, 0x13, 0x04, 0x03, 0x06, 0x02, 0x02, 0x0d, 0x0a, 0x0a, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
```

5. Calculate checksum: calculate using [Bitcoin Cash checksum algorithm][] over the input data

checksum output: `688543492710`

6. Base32 encode: encode the output

checksum base32 encode: `ybjgh4xg`

concatenated result: `cfx:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg`

## Syntax

The syntax of Conflux addresses:

```
caip10-like address: namespace + ":" chain_id + ":" + address
namespace: conflux
chain_id cfx or cfxtest or net[network ID]
address: base32 address
```

## Test Cases

The list of example address generated form the same hex address, composed use the [Address Format Conversion][] or [conflux-address-js][]

```
# mainnet
conflux:cfx:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg
# testnet
conflux:cfxtest:aarc9abycue0hhzgyrr53m6cxedgccrmmy8m50bu1p
# private net
conflux:net2024:aarc9abycue0hhzgyrr53m6cxedgccrmmy06bvtn67
# private net
conflux:net202408:aarc9abycue0hhzgyrr53m6cxedgccrmmywsh35uak
```

## References

- [Conflux core space docs][]: Conflux core space eveloper documentation
- [Conflux base32 addresses][]: Conflux addresses
- [Address Format Conversion][]: A tool convert hex address to base32

[Conflux core space docs]: https://doc.confluxnetwork.org/docs/core/Overview
[Conflux base32 addresses]: https://doc.confluxnetwork.org/docs/core/core-space-basics/addresses
[conflux-address-js]: https://github.com/conflux-fans/conflux-address-js
[Address Format Conversion]: https://www.confluxscan.io/address-converter
[CAIP-10]: https://chainagnostic.org/CAIPs/caip-10
[Bitcoin Cash checksum algorithm]: https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md#checksum

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
94 changes: 94 additions & 0 deletions conflux/caip2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
namespace-identifier: conflux-caip2
title: Conflux Namespace - Chains
author: iosh (@iosh)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/124
status: Draft
type: Standard
created: 2024-08-09
requires: CAIP-2
---

# CAIP-2

_For context, see the [CAIP-2][] specification._

## Rationale

Conflux network(core space) consists of 2 networks: main network and testing network.
Private networks can also be created.

The main network has a network ID of 1029, represented by `cfx`. The test network has a network ID of 1, represented by `cfxtest`. Private networks are represented by `net[network ID]`.


## Syntax

A network id in the Conflux core space is defined as an unsigned integer ranging from 1 to 4294967295.

### Resolution Mechanics

To resolve the a network reference for a conflux network, POST a JSON-RPC request to the RPC endpoint of the blockchain node with path / for example:

```jsonc
// request
curl -X POST --data \
'{
"method": "cfx_getStatus",
"params": [],
"jsonrpc": "2.0",
"id": 1
}' \
-H "Content-Type: application/json" \
https://main.confluxrpc.com

// response

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"bestHash": "0x4e5607b1c23124fad2c7e431f34ca52bc3e28e90df2e3733d0a50d64d4790693",
"chainId": "0x405",
"ethereumSpaceChainId": "0x406",
"networkId": "0x405",
"epochNumber": "0x6158f8d",
"blockNumber": "0xeb54f08",
"pendingTxNumber": "0xc9",
"latestCheckpoint": "0x614b3a0",
"latestConfirmed": "0x6158f6a",
"latestState": "0x6158f89",
"latestFinalized": "0x6158eb0"
}
}

```

The response will return a JSON object which will include node status and the `networkId`, encoded in hexadecimal, of the current chain.

## Test Cases

```
# conflux mainnet
conflux:cfx
# conflux testnet
conflux:cfxtest
# private network
conflux:net2024
```

## References

- [CAIP-2][]
- [Conflux core space Docs][] The Conflux Core Space Docs
- [Conflux core space RPC endpoint][] Publicly available Conflux Core Space network RPC endpoints

[CAIP-2]: https://chainagnostic.org/CAIPs/caip-2
[Conflux core space Docs]: https://doc.confluxnetwork.org/docs/core/Overview
[Conflux core space RPC endpoint]: https://doc.confluxnetwork.org/docs/core/conflux_rpcs

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
2 changes: 1 addition & 1 deletion eip155/caip10.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The `chain_id` string will be ammended as follows:
chain_id: namespace + ":" + network_id + ":" + reference
namespace: [-a-z0-9]{3,8}
network_id: [0-9]{1,64}
reference: 0x[a-fA-F0-9]{1,40}
reference: 0x[a-fA-F0-9]{40}
```

### Backwards Compatibility
Expand Down

0 comments on commit f58b044

Please sign in to comment.