Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update the SDK documentation to reflect its finalized organization #320

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 58 additions & 66 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

The Verax SDK facilitates the interactions with the contracts and the subgraph, both from a frontend and a backend.

[DRAFT]

## Installation

VeraxSDK is a [npm package](https://www.npmjs.com/package/@verax-attestation-registry/verax-sdk/).
VeraxSDK is an [npm package](https://www.npmjs.com/package/@verax-attestation-registry/verax-sdk/).

```bash
# npm
Expand All @@ -27,33 +25,47 @@ pnpm add @verax-attestation-registry/verax-sdk

### 1. Import VeraxSdk

```js
// CommonJS
```javascript
// JavaScript
var VeraxSdk = require("@verax-attestation-registry/verax-sdk");
```

```js
// ES6
```typescript
// TypeScript
import VeraxSdk from "@verax-attestation-registry/verax-sdk";
```

### 2. Instantiate VeraxSdk

```js
// Default configuration for Linea Testnet
```javascript
// Default configuration for Linea Testnet on a backend
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);
```

or,

```js
// Default configuration for Linea Mainnet
```javascript
// Default configuration for Linea Mainnet on a backend
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_MAINNET);
```

or,

```js
```javascript
// Default configuration for Linea Testnet on a frontend
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET_FRONTEND);
```

or,

```javascript
// Default configuration for Linea Mainnet on a frontend
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_MAINNET_FRONTEND);
```

or,

```javascript
// Custom configuration
const myVeraxConfiguration = {
chain: lineaTestnet,
Expand All @@ -71,20 +83,20 @@ const veraxSdk = new VeraxSdk(myVeraxConfiguration);

### 1. Get DataMappers

```js
// Each Verax classes has its DataMapper
```javascript
// Each Verax object has its DataMapper
// Get them from the SDK instance
const attestationDataMapper = veraxSdk.attestation; // RW Attestations
const moduleDataMapper = veraxSdk.module; // RW Modules
const portalDataMapper = veraxSdk.portal; // RW Portals
const schemaDataMapper = veraxSdk.schema; // RW Schemas
const moduleDataMapper = veraxSdk.module; // RW Modules
const attestationDataMapper = veraxSdk.attestation; // RW Attestations
```

### 2. Read content (one object)

Each DataMapper comes with the method `findOneById` to get one object by ID.

```js
```typescript
const myAttestation = await attestationDataMapper.findOneById("12345");
console.log(myAttestation);

Expand All @@ -100,28 +112,26 @@ console.log(myAttestation);

Each DataMapper comes with the method `findBy` to get objects by criteria.

```js
```typescript
//
// args:
// - criteria: object {property1: value1, property2: value2, ...}
// - page: integer (optional, default 0)
// - offset: integer (optional, default 50, max= 500)
// - orderBy: string (optional, default createdAt)
// - order(property?): enum string "ASC", "DESC" (optional, default "DESC")
// - first: number (optional, default 100)
// - skip: number (optional, default 0)
// - where: object (optional, default `null`)
// - orderBy: string (optional, default `null`)
// - orderDirection: enum string "ASC", "DESC" (optional, default `null`)
//
const myAttestations = await attestationDataMapper.findBy(
{ portalId: "37773", subject: "John" },
4,
30,
{ portalId: "37773", subject: "John" },
"schemaId",
"ASC",
"asc",
);

console.log(myAttestations);
//
// totalNumber: 147,
// page: 0,
// objects: [
// [
// {id: "12345", schemaId: "99AE34", portalId: "37773", subject: "Florian", ...},
// {id: "2221E", schemaId: "AAF77E", portalId: "37773", subject: "Florian", ...},
// ...
Expand All @@ -131,50 +141,40 @@ console.log(myAttestations);

### 4. Write content

[WORK IN PROGRESS] Each dataMapper comes with write methods, that may vary depending on the class. See the detail of
write method per class dataMapper.
Each DataMapper comes with write methods, that may vary depending on the class. See the detail of write method per
DataMapper.

```js
const result = await attestationDataMapper.attest(
```typescript
const transactionHash = await attestationDataMapper.attest(
"0x123ABC...", // portalAddress
{
// attestationPayload
schemaId: "muhpoih",
portalId: "OJOJ43432",
expirationDate: null,
subject: "florian.demiramon@...",
data: {
subject: "0xdeadbeef...",
attestationData: {
foo: "bar",
zee: "plop",
},
},
signer,
["..."], // validationPayloads
);

console.log(result);
console.log(transactionHash);
//
// txReceipt: ....
// object: {
// {
// id: "0XAZFZF"
// schemaId: "muhpoih"
// portalId: "OJOJ43432"
// expirationDate: null
// subject: "florian.demiramon@..."
// attestationData: {
// foo: "bar",
// zee: "plop"
// }
// attestationRawData: "1234234124124FAAZC"
// replacedBy: null
// attester: "0x1111"
// attestedDate: "today"
// revocationDate: null
// version: 1
// revoked: false
// }
// 0x...
//
```

## CLI examples
## 5. Other operations

The class `veraxSdk.utils` extends the capabilities:

- precompute the ID of an Attestation
- precompute the ID of a Schema
- encode/decode an attestation payload

## 6. CLI examples

You can use command lines to test all the implemented SDK methods. Here are some examples.

Expand Down Expand Up @@ -298,11 +298,3 @@ pnpm schema isRegistered "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de

pnpm schema getSchemaIds 0
```

## Other operations

[Work in progress] The class `veraxSdk.utils` extends the capabilities:

- precompute the ID of an Attestation
- precompute the ID of a Schema
- encode decode payload