Skip to content

Commit

Permalink
feat: As a user, I want to create an attestation using the SDK (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
alainncls authored Oct 12, 2023
1 parent c9283aa commit d0b3281
Show file tree
Hide file tree
Showing 12 changed files with 584 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Run the unit tests
run: pnpm run test
run: pnpm run test:ci

- name: Add test summary
run: |
Expand Down
8 changes: 5 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdk/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRIVATE_KEY=0x0000000000000000000000000000000000000000000000000000000000000001
32 changes: 31 additions & 1 deletion sdk/examples/portal/portalExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,47 @@ import VeraxSdk from "../../src/VeraxSdk";

export default class PortalExamples {
private veraxSdk: VeraxSdk;

constructor(_veraxSdk: VeraxSdk) {
this.veraxSdk = _veraxSdk;
}

async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.findOneById("0x1495341ab1019798dd08976f4a3e5ab0e095510b"));

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.findBy({ ownerName: "Clique" }));

if (methodName.toLowerCase() == "attest" || methodName == "") console.log(await this.veraxSdk.portal.attest());
if (methodName.toLowerCase() == "simulateAttest".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.portal.simulateAttest(
"0xeea25bc2ec56cae601df33b8fc676673285e12cc",
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
[],
),
);
}

if (methodName.toLowerCase() == "attest" || methodName == "") {
console.log(
await this.veraxSdk.portal.attest(
"0xeea25bc2ec56cae601df33b8fc676673285e12cc",
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
[],
),
);
}

if (methodName.toLowerCase() == "bulkAttest".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.bulkAttest());
Expand Down
17 changes: 2 additions & 15 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,12 @@
"module": "ts-node examples/module/index.ts",
"portal": "ts-node examples/portal/index.ts",
"schema": "ts-node examples/schema/index.ts",
"attestation:all": "ts-node examples/attestation/findBy.ts",
"attestation:one": "ts-node examples/attestation/findOneById.ts",
"module:all": "ts-node examples/module/findBy.ts",
"module:one": "ts-node examples/module/findOneById.ts",
"portal:all": "ts-node examples/portal/findBy.ts",
"portal:one": "ts-node examples/portal/findOneById.ts",
"schema:all": "ts-node examples/schema/findBy.ts",
"schema:one": "ts-node examples/schema/findOneById.ts",
"test": "jest",
"utils:attestation:counter": "ts-node examples/utils/getAttestationIdCounter.ts",
"utils:attestation:version": "ts-node examples/utils/getVersionNumber.ts",
"utils:decode": "ts-node examples/utils/decode.ts",
"utils:encode": "ts-node examples/utils/encode.ts",
"utils:module:counter": "ts-node examples/utils/getModulesNumber.ts",
"utils:portal:counter": "ts-node examples/utils/getPortalsCount.ts",
"utils:schema:counter": "ts-node examples/utils/getSchemasNumber.ts"
"test:ci": "cp .env.example .env && jest"
},
"dependencies": {
"@apollo/client": "^3.8.4",
"dotenv": "^16.3.1",
"graphql": "^16.8.1",
"viem": "^1.14.0"
},
Expand Down
44 changes: 37 additions & 7 deletions sdk/src/VeraxSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,49 @@ import AttestationDataMapper from "./dataMapper/AttestationDataMapper";
import SchemaDataMapper from "./dataMapper/SchemaDataMapper";
import ModuleDataMapper from "./dataMapper/ModuleDataMapper";
import PortalDataMapper from "./dataMapper/PortalDataMapper";
import { createPublicClient, http, PublicClient } from "viem";
import { createPublicClient, createWalletClient, custom, Hex, http, PublicClient, WalletClient } from "viem";
import { ApolloClient, InMemoryCache } from "@apollo/client/core";
import { Conf } from "./types";
import UtilsDataMapper from "./dataMapper/UtilsDataMapper";
import { privateKeyToAccount } from "viem/accounts";
import dotenv from "dotenv";
import { Conf } from "./types";
import { SDKMode } from "./utils/constants";

dotenv.config({ path: "./.env" });

export default class VeraxSdk {
static DEFAULT_LINEA_MAINNET: Conf = {
chain: linea,
mode: SDKMode.BACKEND,
subgraphUrl: "https://graph-query.linea.build/subgraphs/name/Consensys/linea-attestation-registry",
portalRegistryAddress: "0xd5d61e4ECDf6d46A63BfdC262af92544DFc19083",
moduleRegistryAddress: "0xf851513A732996F22542226341748f3C9978438f",
schemaRegistryAddress: "0x0f95dCec4c7a93F2637eb13b655F2223ea036B59",
attestationRegistryAddress: "0x3de3893aa4Cdea029e84e75223a152FD08315138",
};

static DEFAULT_LINEA_MAINNET_FRONTEND: Conf = {
...VeraxSdk.DEFAULT_LINEA_MAINNET,
mode: SDKMode.BACKEND,
};

static DEFAULT_LINEA_TESTNET: Conf = {
chain: lineaTestnet,
mode: SDKMode.BACKEND,
subgraphUrl: "https://graph-query.goerli.linea.build/subgraphs/name/Consensys/linea-attestation-registry",
portalRegistryAddress: "0x506f88a5Ca8D5F001f2909b029738A40042e42a6",
moduleRegistryAddress: "0x1a20b2CFA134686306436D2c9f778D7eC6c43A43",
schemaRegistryAddress: "0xB2c4Da1f8F08A0CA25862509E5431289BE2b598B",
attestationRegistryAddress: "0xC765F28096F6121C2F2b82D35A4346280164428b",
};

static DEFAULT_LINEA_TESTNET_FRONTEND: Conf = {
...VeraxSdk.DEFAULT_LINEA_TESTNET,
mode: SDKMode.BACKEND,
};

private readonly web3Client: PublicClient;
private readonly walletClient: WalletClient;
private readonly apolloClient: ApolloClient<object>;

public attestation: AttestationDataMapper;
Expand All @@ -42,15 +60,27 @@ export default class VeraxSdk {
transport: http(),
});

this.walletClient =
conf.mode === SDKMode.BACKEND
? createWalletClient({
chain: conf.chain,
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
transport: http(),
})
: createWalletClient({
chain: conf.chain,
transport: custom(window.ethereum),
});

this.apolloClient = new ApolloClient({
uri: conf.subgraphUrl,
cache: new InMemoryCache(),
});

this.attestation = new AttestationDataMapper(conf, this.web3Client, this.apolloClient);
this.schema = new SchemaDataMapper(conf, this.web3Client, this.apolloClient);
this.module = new ModuleDataMapper(conf, this.web3Client, this.apolloClient);
this.portal = new PortalDataMapper(conf, this.web3Client, this.apolloClient);
this.utils = new UtilsDataMapper(conf, this.web3Client, this.apolloClient);
this.attestation = new AttestationDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient, this);
this.schema = new SchemaDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient, this);
this.module = new ModuleDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient, this);
this.portal = new PortalDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient, this);
this.utils = new UtilsDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient, this);
}
}
Loading

0 comments on commit d0b3281

Please sign in to comment.