Skip to content

Commit

Permalink
Merge pull request #19 from starknet-id/ref/pfp_instead_pp
Browse files Browse the repository at this point in the history
fix: replace pp by pfp & update readme
  • Loading branch information
fricoben authored Nov 28, 2023
2 parents c92fa25 + 9e7ed9f commit 72b27ee
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 381 deletions.
200 changes: 7 additions & 193 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Starknetid.js

Starknetid.js is a JavaScript library that facilitates interaction with the
Starknet.id protocol. Whether you're a dApp developer or a blockchain
enthusiast, this library provides utility functions to seamlessly integrate
Starknet.id into your projects.

[🔗 Full documentation of the package](https://docs.starknet.id/devs/starknetidjs)

## Get started

### Installation
Expand All @@ -12,199 +19,6 @@ npm install starknetid.js starknet@next
yarn install starknetid.js starknet@next
```

Version `1.5.2` works with starknet.js `v5`. If you need to use starknet.js
`v4`, please use version `1.5.0` of `starknetid.js`.

### Usage for dApp developers

#### Basic usage

Import `StarknetIdNavigator` from `starknetid.js` package to access functions.
`StarknetIdNavigator` needs to be initialize with a provider and a chainId.

```
import { StarknetIdNavigator } from 'starknetid.js'
import { Provider, constants } from 'starknet'
const provider = new Provider();
const starknetIdNavigator = new StarknetIdNavigator(provider, constants.StarknetChainId.SN_MAIN);
const addr = await starknetIdNavigator.getAddressFromStarkName('test.stark');
```

#### Using custom contracts

It's possible to use starknetid.js with custom naming and identity contracts.

```
import { StarknetIdNavigator } from 'starknetid.js'
const starknetIdNavigator = new StarknetIdNavigator(
provider,
constants.StarknetChainId.SN_MAIN,
{
naming: customNamingContract,
identity: customIdentityContract
}
)
```

#### Using utils functions

You can access utils function outside of the `StarknetIdNavigator` object
through the `utils` namespace

```
import { utils } from 'starknetid.js'
const encodedDomain = utils.encodeDomain('test.stark');
```

## SDK

### Resolving domains

**getAddressFromStarkName()**

_StarknetIdNavigator.**getAddressFromStarkName**(domain: string) => string_

Get address from Starkname.

**getStarkName()**

_StarknetIdNavigator.**getStarkName**(address: string) => string_

Get Starkname from address.

**getStarknetId()**

_StarknetIdNavigator.**getStarknetId**(domain: string) => number_

Get Starknet id from domain.

### Resolving user data

**getUserData()**

_StarknetIdNavigator.**getUserData**(dOrDomain: number | string, field: string)
=> BN_

Get user data from starknet id or domain.

**getExtentedUserData()**

_StarknetIdNavigator.**getExtentedUserData**(dOrDomain: number | string, field:
string, length: number) => BN[]_

Get user data from starknet id or domain. Use this function to retrieve an array
knowing its size. It will return zeros if not written.

**getUnboundedUserData()**

_StarknetIdNavigator.**getUnboundedUserData**(dOrDomain: number | string, field:
string) => BN[]_

Get User unbounded data from starknet id or domain. Use this function to
retrieve an array up to zero (not included).

### Resolving verifier data

**getVerifierData()**

_StarknetIdNavigator.**getVerifierData**(dOrDomain: number | string, field:
string, verifier?: string) => BN_

Get verifier data from starknet id or domain. If no verifier contract is
provided, it will return the starknet.id verifier contract address deployed on
the StarknetIdNavigator provider chain id.

**getExtendedVerifierData()**

_StarknetIdNavigator.**getExtendedVerifierData**(dOrDomain: number | string,
field: string, length: number, verifier?: string) => BN[]_

Get extended verifier data from starknet id or domain. Use this function to
retrieve an array knowing its size. It will return zeros if not written. If no
verifier contract is provided, it will return the starknet.id verifier contract
address deployed on the StarknetIdNavigator provider chain id.

**getUnboundedVerifierData()**

_StarknetIdNavigator.**getUnboundedVerifierData**(dOrDomain: number | string,
field: string, verifier?: string) => BN[]_

Get User unbounded data from starknet id or domain. Use this function to
retrieve an array up to zero (not included). If no verifier contract is
provided, it will return the starknet.id verifier contract address deployed on
the StarknetIdNavigator provider chain id.

### Utils

**isStarkDomain()**

_utils.**isStarkDomain**(domain: string) => boolean_

Check if domain is starknet.id domain

**decodeDomain()**

_utils.**decodeDomain**(encoded: bigint[]) => string_

Decode starknetid domain represented as an array of bigint `[454245]` ->
`test.stark`

**encodeDomain()**

_utils.**encodeDomain**(domain: string | undefined | null) => bigint[]_

Encode starknetid domains and subdomains to an array bigint `test.stark` ->
`[454245]`

**getNamingContract()**

_utils.**getNamingContract**(chainId: StarknetChainId) => string_

Get starknet.id naming contract address from chainId. If contract is not
deployed will throw an error.

**getIdentityContract()**

_utils.**getIdentityContract**(chainId: StarknetChainId) => string_

Get starknet.id identity contract address from chainId. If contract is not
deployed will throw an error.

**getVerifierContract()**

_utils.**getVerifierContract**(chainId: StarknetChainId) => string_

Get starknet.id verifier contract address from chainId. If contract is not
deployed will throw an error. At the moment, starknet.id verifier contract only
support `Discord`, `Twitter` and `Github` fields.

**isSubdomain()**

_utils.**isSubdomain**(domain: string | undefined) => boolean_

Check if domain is a starknet.id subdomain

**isBraavosSubdomain()**

_utils.**isBraavosSubdomain**(domain: string | undefined) => boolean_

Check if domain is a Braavos subdomain

**isStarkRootDomain()**

_utils.**isStarkRootDomain**(domain: string | undefined) => boolean_

Check if domain is a starknet.id root domain

**isXplorerSubdomain()**

_utils.**isXplorerSubdomain**(domain: string | undefined) => boolean_

Check if domain is a Xplorer subdomain

## Development

You need Node and pnpm installed. Make sure to clone this repo and run:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknetid.js",
"version": "1.5.6",
"version": "2.0.0",
"description": "JavaScript library for Starknet ID",
"private": false,
"license": "MIT",
Expand Down
Loading

0 comments on commit 72b27ee

Please sign in to comment.