Skip to content

Commit

Permalink
feat: As a user, I want to create an attestation using the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
alainncls committed Oct 10, 2023
1 parent 2a56f53 commit 4ef4a83
Show file tree
Hide file tree
Showing 10 changed files with 552 additions and 38 deletions.
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=XXX
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
18 changes: 2 additions & 16 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,11 @@
"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": "jest"
},
"dependencies": {
"@apollo/client": "^3.8.4",
"dotenv": "^16.3.1",
"graphql": "^16.8.1",
"viem": "^1.14.0"
},
Expand Down
33 changes: 26 additions & 7 deletions sdk/src/VeraxSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ 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, Hex, http, PublicClient, WalletClient } from "viem";
import { ApolloClient, InMemoryCache } from "@apollo/client/core";
import { Conf } from "./types";
import UtilsDataMapper from "./dataMapper/UtilsDataMapper";
import { Conf } from "./types";
import { privateKeyToAccount } from "viem/accounts";
import dotenv from "dotenv";

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

export default class VeraxSdk {
static DEFAULT_LINEA_MAINNET: Conf = {
chain: linea,
mode: 0, // TODO: use SDKMode enum
subgraphUrl: "https://graph-query.linea.build/subgraphs/name/Consensys/linea-attestation-registry",
portalRegistryAddress: "0xd5d61e4ECDf6d46A63BfdC262af92544DFc19083",
moduleRegistryAddress: "0xf851513A732996F22542226341748f3C9978438f",
Expand All @@ -20,6 +25,7 @@ export default class VeraxSdk {

static DEFAULT_LINEA_TESTNET: Conf = {
chain: lineaTestnet,
mode: 0,
subgraphUrl: "https://graph-query.goerli.linea.build/subgraphs/name/Consensys/linea-attestation-registry",
portalRegistryAddress: "0x506f88a5Ca8D5F001f2909b029738A40042e42a6",
moduleRegistryAddress: "0x1a20b2CFA134686306436D2c9f778D7eC6c43A43",
Expand All @@ -28,6 +34,7 @@ export default class VeraxSdk {
};

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

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

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

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.schema = new SchemaDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient);
this.module = new ModuleDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient);
this.portal = new PortalDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient);
this.utils = new UtilsDataMapper(conf, this.web3Client, this.walletClient, this.apolloClient);
}
}
Loading

0 comments on commit 4ef4a83

Please sign in to comment.