Skip to content

Commit

Permalink
split API to resolve and verify, and init register page
Browse files Browse the repository at this point in the history
  • Loading branch information
wizicer committed Mar 19, 2024
1 parent cf90526 commit 3db0207
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 51 deletions.
97 changes: 97 additions & 0 deletions src/API/Register.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Register

## Price

Get the price for domain registering.

**GET** https://cns.api.pawket.app/api/price

**Request:**

```
?name=123458.xch&year=1&renew=false
```

| Key | Required? | Description |
| ----- | --------- | -------------------------------------------------- |
| name | Yes | the name to register, typically suffix with `.xch` |
| year | Yes | how many year to register or renew, max 99 |
| renew | No | whether to get price for register or renew |

**Response:**

```json
{
"name": "123458.xch",
"price": 400000000000,
"annualFee": 250000000000,
"registrationFee": 150000000000,
"royaltyPercentage": 500,
"success": true
}
```

| Key | Type | Description |
| ----------------- | -------- | ---------------------------------------------- |
| name | String | the name to register or renew |
| price | Number | the total price for register or renew, in mojo |
| annualFee | Number | the annual fee for this name, in mojo |
| registrationFee | Number | the registration fee for this name, in mojo |
| royaltyPercentage | Number | the royalty percentage in 1/10000, e.g. 500=5% |
| success | Boolean | whether success to get price information |
| code | String | if failed, this is the error code |
| reason | String | if failed, this is the reason |
| arguments | String[] | if failed, this is the arguments for reason |

## Register

Get the offer for registering or renewing.

**POST** https://cns.api.pawket.app/api/register

**Request:**

```json
{
"name": "123458.xch",
"royaltyAddress": "",
"address": "",
"publicKey": "",
"did": "",
"text": "",
"renew": false,
"year": 1
}
```

| Key | Required? | Description |
| -------------- | --------- | -------------------------------------------------------------------- |
| name | Yes | the name to register, typically suffix with `.xch` |
| year | Yes | how many year to register or renew, max 99 |
| royaltyAddress | No | the default royalty address of this CNS NFT, format like xch1... |
| address | No | the default binding address, format like xch1 |
| publicKey | No | the default binding publick key, format usually like 0x... |
| did | No | the default binding DID, format like did:chia:... |
| text | No | the default binding text, can be arbitrary text except double quotes |
| renew | No | whether to get price for register or renew |

**Response:**

```json
{
"name": "123458.xch",
"offer": "offer1qqr83....",
"image": "/9j/4AAQSkZJRg....",
"success": true
}
```

| Key | Type | Description |
| --------- | -------- | ------------------------------------------- |
| name | String | the name to register or renew |
| image | String | the NFT image in base64 |
| offer | String | the offer string |
| success | Boolean | whether success to get register offer |
| code | String | if failed, this is the error code |
| reason | String | if failed, this is the reason |
| arguments | String[] | if failed, this is the arguments for reason |
54 changes: 4 additions & 50 deletions src/API.md → src/API/Resolve.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# API

## Resolve
# Resolve

**NOTE:**

1. You can access the hosting service of CNS, or resolve it by yourself with or without this [reference code](https://github.com/SutuLabs/pawket-api)
2. We are still working towards a more decentralized solution like the mechanism in the inscription chain.

### API to resolve
## Single resolve

Here you can resolve the address through our API for demonstration purpose.

Expand Down Expand Up @@ -59,7 +57,7 @@ Here you can resolve the address through our API for demonstration purpose.
- the `data` is in Hex format, and in this case, it should be: `xch1975vey77eqh4pfmcrnkj0dkzaedguhhar4cxq6u803vthp29ayrqp0ydw2`
- You can either get accurate block time from block chain or just roughly calculated like I did in Pawket here: [Code](https://github.com/SutuLabs/Pawket/blob/master/packages/pawket/src/components/Common/AddressField.vue#L223-L236)

### Reverse resolving
## Reverse resolving

Sometime, we need to reverse resolving, from address to name, here is the example.

Expand Down Expand Up @@ -98,55 +96,11 @@ Sometime, we need to reverse resolving, from address to name, here is the exampl

If the address is resolving to multiple names, the earliest change would be responsed.

## Verify Proof

The quick and dirty way is just resolve without verify, but to resist the malicious resolver, the client are persuade to verify the proof in the client side.

Here is the steps:

1. download coin data from blockchain for the proof coin
2. parse(uncurry) the coin and check the correctness of name and binding address
3. check the next coin of this proof coin is not spent (that the proof coin is the latest changes)

### API to check coin

Different client may have different way to get the coin details, here is one way to demonstrate this function.

**POST** https://walletapi.chiabee.net/Wallet/get-coin-solution

**Request:**

```json
{
"coinIds": ["0x59cffe9b0d863c74e04bd41aad96f39ca74bf8494d09e74aa387ad2dbc81086d"]
}
```

**Response:**

```json
[
{
"coin": {
"amount": 1,
"parent_coin_info": "0x804037b1362351a6e9b29f0dc3a821a81143dc499fd953a1b9573ed95fc4836e",
"puzzle_hash": "0x10d14864451e4c2e6e94d58512b29f7de603e77713ed62e4b23f1b8af44f3b0d"
},
"puzzle_reveal": "0xff02ffff01ff02ffff0...",
"solution": "0xffffa0793d3984ad2321...",
"confirmed_index": 4946819,
"spent_index": 4952003,
"timestamp": 1707986063
}
]
```

## Retrieve All

For some application, it's better to get all domain names at once, and resolve them locally with periodical update.

### API to resolve all

Here you can resolve the address through our API for demonstration purpose.

**GET** https://walletapi.chiabee.net/Name/all
Expand Down Expand Up @@ -196,4 +150,4 @@ After verifying, it could tell user it's verified.

If the address is not found in the resolver, then the error may tell user.

![](cns-not-found.png)
![](cns-not-found.png)
44 changes: 44 additions & 0 deletions src/API/Verify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Verify

The security of CNS resolving can be greatly upgraded by doing verification, which require access to synchronized full node.

The quick and dirty way is just resolve without verify, but to resist the malicious resolver, the client are persuade to verify the proof in the client side.

Here is the steps:

1. download coin data from blockchain for the proof coin
2. parse(uncurry) the coin and check the correctness of name and binding address
3. check the next coin of this proof coin is not spent (that the proof coin is the latest changes)

## API to check coin

Different client may have different way to get the coin details, here is one way to demonstrate this function.

**POST** https://walletapi.chiabee.net/Wallet/get-coin-solution

**Request:**

```json
{
"coinIds": ["0x59cffe9b0d863c74e04bd41aad96f39ca74bf8494d09e74aa387ad2dbc81086d"]
}
```

**Response:**

```json
[
{
"coin": {
"amount": 1,
"parent_coin_info": "0x804037b1362351a6e9b29f0dc3a821a81143dc499fd953a1b9573ed95fc4836e",
"puzzle_hash": "0x10d14864451e4c2e6e94d58512b29f7de603e77713ed62e4b23f1b8af44f3b0d"
},
"puzzle_reveal": "0xff02ffff01ff02ffff0...",
"solution": "0xffffa0793d3984ad2321...",
"confirmed_index": 4946819,
"spent_index": 4952003,
"timestamp": 1707986063
}
]
```
File renamed without changes
File renamed without changes
File renamed without changes
17 changes: 17 additions & 0 deletions src/API/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# API

| API | Path | Type | Summary |
| ---------- | ------------------------------------------------------ | ---- | ------------------------------------------ |
| [Resolve] | https://walletapi.chiabee.net/Name/resolve | POST | resolve address or name |
| [Resolve] | https://walletapi.chiabee.net/Name/all | GET | get all names and corresponding address |
| [Verify] | https://walletapi.chiabee.net/Wallet/get-coin-solution | POST | get the information for verification |
| [Register] | https://cns.api.pawket.app/api/price | GET | get price for the CNS to register or renew |
| [Register] | https://cns.api.pawket.app/api/register | POST | request to register or renew certain CNS |

- for testnet, prefix `testnet.`
- Resolving/Verify: https://testnet.walletapi.chiabee.net/
- Register: https://testnet.cns.api.pawket.app/

[resolve]: Resolve.md
[verify]: Verify.md
[register]: Register.md
5 changes: 4 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
- [Pricing](./Pricing.md)
- [Airdrop](./Airdrop.md)
- [Beyond](./Beyond.md)
- [API](./API.md)
- [API](./API/index.md)
- [Resolve](./API/Resolve.md)
- [Verify](./API/Verify.md)
- [Register](./API/Register.md)

--------------

Expand Down

0 comments on commit 3db0207

Please sign in to comment.