Skip to content

Commit

Permalink
Docs (#19)
Browse files Browse the repository at this point in the history
* chore(release): publish

- project: @justaname.id/react 0.3.40

- project: @justaname.id/sdk 0.2.37

- project: create-justaname-app 0.3.34

* chore(release): publish

- project: @justaname.id/react 0.3.41

- project: @justaname.id/sdk 0.2.38

- project: create-justaname-app 0.3.35

* chore(release): publish

- project: @justaname.id/react 0.3.42

- project: @justaname.id/sdk 0.2.39

- project: create-justaname-app 0.3.36

* feat: address decoder upgrade

* feat: get communities

* chore(release): publish

- project: @justaname.id/react 0.3.43

- project: @justaname.id/sdk 0.2.40

- project: create-justaname-app 0.3.37

* chore(release): publish

- project: @justaname.id/react 0.3.44

- project: @justaname.id/sdk 0.2.41

- project: create-justaname-app 0.3.38

* chore(release): publish

- project: @justaname.id/react 0.3.45

- project: @justaname.id/sdk 0.2.42

- project: create-justaname-app 0.3.39

* chore(release): publish

- project: @justaname.id/react 0.3.46

- project: @justaname.id/sdk 0.2.43

- project: create-justaname-app 0.3.40

* chore(release): publish

- project: @justaname.id/react 0.3.47

- project: @justaname.id/sdk 0.2.44

- project: create-justaname-app 0.3.41

* chore(release): publish

- project: @justaname.id/react 0.3.48

- project: @justaname.id/sdk 0.2.45

- project: create-justaname-app 0.3.42

* feat: how to docs (#18)

* feat: community paginated and use address subname

---------

Co-authored-by: Ghadi Mhawej <[email protected]>
  • Loading branch information
HadiKhai and Ghadi8 authored May 31, 2024
1 parent bf502a0 commit 33a9936
Show file tree
Hide file tree
Showing 77 changed files with 1,194 additions and 1,562 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion apps/express-trial/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
JUSTANAME_API_KEY=your_api_key
JUSTANAME_CHAIN_ID=your_chain_id
JUSTANAME_DOMAIN=yourwebsite
JUSTANAME_ORIGIN=yourwebsite.com
JUSTANAME_ORIGIN=yourwebsite.com
JUSTANAME_ENS_DOMAIN=yourens.eth
75 changes: 7 additions & 68 deletions apps/express-trial/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express, { Request } from 'express';
import cors from 'cors';
import { JustaName, SubnameUpdateRequest } from '@justaname.id/sdk';
import { JustaName } from '@justaname.id/sdk';
import dotenv from 'dotenv'

dotenv.config();
Expand All @@ -25,6 +25,7 @@ const chainId = parseInt(process.env.JUSTANAME_CHAIN_ID as string);
const domain = process.env.JUSTANAME_DOMAIN as string;
const origin = process.env.JUSTANAME_ORIGIN as string;
const apiKey = process.env.JUSTANAME_API_KEY as string;
const ensDomain = process.env.JUSTANAME_ENS_DOMAIN as string;

if(!origin) {
throw new Error('Origin is required');
Expand All @@ -46,6 +47,10 @@ if (!apiKey) {
throw new Error('API Key is required');
}

if (!ensDomain) {
throw new Error('ENS Domain is required');
}

let justaname: JustaName;

app.get('/api/request-challenge', async (req: Request<NonNullable<unknown>, NonNullable<unknown>, NonNullable<unknown>,RequestChallenge>, res) => {
Expand Down Expand Up @@ -93,7 +98,7 @@ app.post('/api/subnames/add', async (req: Request<SubnameAdd>, res) => {
try {
const add = await justaname.subnames.addSubname({
username: username,
ensDomain: domain,
ensDomain: ensDomain,
chainId: chainId
},
{
Expand All @@ -111,71 +116,6 @@ app.post('/api/subnames/add', async (req: Request<SubnameAdd>, res) => {
}
});

export interface SubnameUpdate extends Omit<SubnameUpdateRequest, 'ensDomain' | 'chainId'> {
address: string;
signature: string;
message: string;
}

app.post('/api/subnames/update', async (req: Request<SubnameUpdate>, res) => {

const username = req.body.username;
const addresses = req.body.addresses;
const text = req.body.text;
const contentHash = req.body.contentHash;
const signature = req.body.signature;
const address = req.body.address;
const message = req.body.message;

if(!username) {
res.status(400).send({ message: 'Username is required' });
return;
}

if(!addresses) {
res.status(400).send({ message: 'Addresses are required' });
return;
}

if(!text) {
res.status(400).send({ message: 'Text records are required' });
return;
}

if(!contentHash && contentHash !== '') {
res.status(400).send({ message: 'Content hash is required' });
return;
}

if(!req.body.address || !req.body.signature || !req.body.message) {
res.status(400).send({ message: 'Address, signature and message are required' });
return;
}


try {
const add = await justaname.subnames.updateSubname({
username: username,
ensDomain: domain,
chainId: chainId,
addresses,
text,
contentHash
},
{
xSignature: signature,
xAddress: address,
xMessage: message
});

res.status(201).send(add);
return;
}
catch (error) {
if(error instanceof Error)
res.status(500).send({ error: error.message });
}
})

app.get('/api', (req, res) => {
res.send({ message: 'Welcome to JustaName Express!' });
Expand All @@ -187,7 +127,6 @@ const server = app.listen(port, async () => {
apiKey: process.env.JUSTANAME_API_KEY as string
});


console.log(`Listening at http://localhost:${port}/api`);
});

Expand Down
5 changes: 3 additions & 2 deletions apps/react-trial/src/app/components/Subname.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const Subname: React.FC<SubnameProps> = ({ currentSubname }) => {

return (
<div>
<p>{subname?.subname}</p>
<h2>{subname?.subname}</h2>

<h2>Data</h2>
<p>Data</p>
<table>
<thead>
<tr>
Expand Down Expand Up @@ -50,6 +50,7 @@ export const Subname: React.FC<SubnameProps> = ({ currentSubname }) => {
updateSubname({
username: subname.username,
subname: subname.subname,
ensDomain: import.meta.env.VITE_APP_ENS_DOMAIN as string,
...subname.data,
text: [
...subname.data.textRecords.filter(record => record.key !== key ).map((record)=>{
Expand Down
5 changes: 4 additions & 1 deletion apps/react-trial/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
cacheDir: '../../node_modules/.vite/apps/react-trial',

server: {
port: 4200,
port: 3000,
host: 'localhost',
},

Expand All @@ -19,6 +19,9 @@ export default defineConfig({

plugins: [react(), nxViteTsPaths()],

define: {
'process.env': process.env,
},
// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
Expand Down
102 changes: 102 additions & 0 deletions docs/docs/home/how-to/01-resolving-a-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
id: resolving-a-name
title: Resolving a Name
sidebar_label: Resolving a Name
slug: /how-to/resolving-a-name
---

# Resolving Names

## Overview
This guide demonstrates how to resolve names to their attached addresses in a chain-agnostic manner. This means any address from any blockchain can be associated with a name, and the name can consequently be resolved to any of these attached addresses.

We'll cover two methods for achieving this:
1. Using the `@ensdomains/ensjs` package.
2. Using the `@justaname.id/sdk` package.

## Method 1: Using `@ensdomains/ensjs`
The `@ensdomains/ensjs` package is a powerful tool that enables domain name resolution, particularly for the Ethereum Name Service (ENS). Below, you'll find an example of how to use this package to resolve multiple blockchain addresses associated with a single domain name.

### Installation
First, ensure you have the necessary packages:
```sh
npm install @ensdomains/ensjs viem
```

### Code Example
Below is an example code snippet using `@ensdomains/ensjs`:
```javascript
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
import { addEnsContracts } from "@ensdomains/ensjs";
import { getRecords } from "@ensdomains/ensjs/public";

const client = createPublicClient({
chain: addEnsContracts(mainnet),
transport: http(),
});

const main = async () => {
const result = await getRecords(client, {
name: "justghadi.justan.id",
texts: [
"com.twitter",
"avatar",
"email"
],
coins: ["60", "0", "2147483658", "2147483785", "2147492101", "2147542792"],
contentHash: true,
});
console.log({result});
};

main();
```

### Explanation
- **Texts**: These are the traditional DNS records like `twitter handle`, `avatar`, `email`, etc.
- **Coins**: These represent different blockchain addresses:
- `"60"`: Ethereum
- `"0"`: Bitcoin
- `"2147483658"`: Optimism
- `"2147483785"`: Polygon
- `"2147492101"`: Base
- `"2147542792"`: Linea
- The `main()` function fetches and prints the records associated with the specified name.

## Method 2: Using `@justaname.id/sdk`
The `@justaname.id/sdk` package is another versatile tool for name resolution, which supports the resolution of names across different chains.

### Installation
Ensure you have the required package:
```sh
npm install @justaname.id/sdk
```

### Code Example
Below is an example code snippet using `@justaname.id/sdk`:
```javascript
import { JustaName } from "@justaname.id/sdk";

const main = async () => {
const justaName = await JustaName.init({});

const records = await justaName.subnames.getRecordsByFullName({
fullName: "justghadi.justan.id",
chainId: 1,
providerUrl: "https://ethereum-rpc.publicnode.com",
});

console.log({ records });
};

main();
```

### Explanation
- **fullName**: The full name to resolve.
- **chainId**: The blockchain ID. `1` stands for Ethereum mainnet.
- **providerUrl**: URL of the ethereum RPC provider.
- The `main()` function initializes the `JustaName` SDK and fetches all records associated with the specified name.

**Note**: The `@justaname.id/sdk` package will return all records attached to the name, making it a comprehensive solution to retrieve all necessary information linked to a name.
90 changes: 90 additions & 0 deletions docs/docs/home/how-to/02-coin-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
id: coin-types
title: Coin Types
sidebar_label: Coin Types
slug: /how-to/coin-types
---

# Understanding Coin Types in EVM and Multi-Chain Ecosystems

This markdown page provides a comprehensive explanation on how to understand and use coin types, particularly within EVM (Ethereum Virtual Machine) compatible chains. We will reference formal specifications such as **[SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md)** for non-EVM coins and **ENSIP-11** for EVM compatible chains.

## Introduction to Coin Types

Coin types are identifiers used to uniquely specify the address encoding types of various cryptocurrencies, particularly in the context of deterministic wallets. These identifiers ensure that addresses for different types of coins are distinct and non-colliding.

## Coin Types for Non-EVM Chains

For non-EVM compatible chains, coin types are assigned according to the [SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) standard. This document lists various coin types and their respective cryptocurrencies.

## Coin Types for EVM-Compatible Chains

For EVM compatible chains, the **ENSIP-11** specification extends the basic multi-coin resolution principles introduced in **ENSIP-9**. ENSIP-11 provides a systematic way to derive and manage coin types for EVM chains.

### Abstract

ENSIP-11 dedicates a designated range for coin types for EVM chains, ensuring they do not collide with non-EVM coin types.

### Motivations

The primary motivation of ENSIP-11 is to avoid redundant requests for adding EVM compatible chains into SLIP 44 because most of these chains inherit Ethereum's address encoding type.

### Specifications

- **MSB Reserved:** The most-significant bit (MSB) is reserved for EVM chain IDs.
- **Coin Type Derivation:** Compute the coin type for EVM chains by bitwise-ORing the chain ID with `0x80000000`:
```javascript
export const evmChainIdToCoinType = (chainId: number) => {
return (0x80000000 | chainId) >>> 0;
}
```

- **Reverse Operation:** To infer the chain ID from a coin type, bitwise-AND the coin type with `0x7fffffff`:
```javascript
export const coinTypeToEvmChainId = (coinType: number) => {
return (0x7fffffff & coinType) >> 0;
}
```

### Implementation

An implementation is provided in the [ensdomains/address-encoder repository](https://github.com/ensdomains/address-encoder).

### Example

To compute the new coin type for an EVM chain (e.g., chain ID 61):

```javascript
import { coinTypeToEvmChainId, evmChainIdToCoinType } from "@ensdomains/address-encoder/utils";

console.log(evmChainIdToCoinType(61)); // Outputs: 2147483709
console.log(coinTypeToEvmChainId(2147483709)); // Outputs: 61
```

### Exceptions

Some EVM chains have specific considerations:

- **AVAX:** AVAX has multiple chain address formats, only `c` chain is EVM compatible.
- **RSK:** RSK requires additional validation.

These chains will continue using coin types as defined in SLIP44.

### Backward Compatibility

The following EVM compatible coin types were defined before this new standard and should be appended with `_LEGACY` for backward compatibility:

- NRG
- POA
- TT
- CELO
- CLO
- TOMO
- EWT
- THETA
- GO
- FTM
- XDAI
- ETC

When these are displayed, append `_LEGACY` to the coin type and mark them as read-only.
9 changes: 9 additions & 0 deletions docs/docs/home/how-to/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: how-to
title: How To
sidebar_label: How To
slug: /how-to
---
import DocCardList from '@theme/DocCardList';

<DocCardList/>
5 changes: 3 additions & 2 deletions examples/backend/express/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
JUSTANAME_API_KEY=your_api_key
JUSTANAME_CHAIN_ID=your_chain_id
JUSTANAME_DOMAIN=your-ens-domain.eth
JUSTANAME_ORIGIN=yoursite.com
JUSTANAME_DOMAIN=yourwebsite
JUSTANAME_ORIGIN=yourwebsite.com
JUSTANAME_ENS_DOMAIN=yourens.eth
2 changes: 1 addition & 1 deletion examples/backend/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint . --ext .ts"
},
"dependencies": {
"@justaname.id/sdk": "0.2.36",
"@justaname.id/sdk": "0.2.45",
"express": "^4.18.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 33a9936

Please sign in to comment.