Skip to content

Commit

Permalink
feat: As a user, I want to be able to call any method on the `Attesta…
Browse files Browse the repository at this point in the history
…tionRegistry` via the SDK (#304)

Co-authored-by: Satyajeet Kolhapure <[email protected]>
Co-authored-by: Alain Nicolas <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2023
1 parent 484c24d commit 6e593ef
Show file tree
Hide file tree
Showing 9 changed files with 542 additions and 100 deletions.
40 changes: 36 additions & 4 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,14 @@ Note: if your don't pass any parameter (e.g. `pnpm portal findBy`)`, some defaul
```shell
pnpm portal findonebyid '0x34798a866f52949208e67fb57ad36244024c50c0'

pnpm portal findby '{\"ownerName\": \"Satya\"}'

pnpm portal findby '{\"ownerName\": \"Tester\"}'
pnpm portal simulateattest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}, \"validationPayloads\": []}'

pnpm portal attest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}, \"validationPayloads\": []}'

pnpm portal simulateBulkAttest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayloads\" : [{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]},{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}], \"validationPayloads\": [[],[]]}'

pnpm portal bulkAttest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayloads\" : [{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]},{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}], \"validationPayloads\": [[],[]]}'
pnpm portal bulkAttest '{\"portalAddress\": \"0xBA5bBAe01509311f61Bac8A15dCB4B41bEd8Ecb5\", \"attestationPayloads\" : [{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]},{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}], \"validationPayloads\": [[],[]]}'

pnpm portal simulaterevoke '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationId\" : \"0x00000000000000000000000000000000000000000000000000000000000010a8\" }'

Expand All @@ -203,6 +202,14 @@ pnpm portal simulateBulkRevoke '{\"portalAddress\": \"0x34798a866f52949208e67fb5

pnpm portal bulkRevoke '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationIds\" : [\"0x00000000000000000000000000000000000000000000000000000000000010a7\", \"0x00000000000000000000000000000000000000000000000000000000000010a6\"] }'

pnpm portal simulateReplace '{\"portalAddress\": \"0xBA5bBAe01509311f61Bac8A15dCB4B41bEd8Ecb5\", \"attestationId\": \"0x0000000000000000000000000000000000000000000000000000000000000006\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}, \"validationPayloads\": []}'

pnpm portal replace '{\"portalAddress\": \"0xBA5bBAe01509311f61Bac8A15dCB4B41bEd8Ecb5\", \"attestationId\": \"0x0000000000000000000000000000000000000000000000000000000000000006\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}, \"validationPayloads\": []}'

pnpm portal simulateBulkReplace '{\"portalAddress\": \"0xBA5bBAe01509311f61Bac8A15dCB4B41bEd8Ecb5\", \"attestationIds\" : [\"0x0000000000000000000000000000000000000000000000000000000000000007\", \"0x0000000000000000000000000000000000000000000000000000000000000008\"], \"attestationPayloads\" : [{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]},{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}], \"validationPayloads\": [[],[]]}'

pnpm portal bulkReplace '{\"portalAddress\": \"0xBA5bBAe01509311f61Bac8A15dCB4B41bEd8Ecb5\", \"attestationIds\" : [\"0x0000000000000000000000000000000000000000000000000000000000000007\", \"0x0000000000000000000000000000000000000000000000000000000000000008\"], \"attestationPayloads\" : [{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]},{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}], \"validationPayloads\": [[],[]]}'

pnpm portal simulateRegister '{\"id\":\"0xD39c439cD3Ae5E1F3c7d13985aDAC90846284904\",\"name\":\"test\",\"description\":\"example\",\"isRevocable\":true,\"ownerName\":\"test\"}'

pnpm portal register '{\"id\":\"0xD39c439cD3Ae5E1F3c7d13985aDAC90846284904\",\"name\":\"test\",\"description\":\"example\",\"isRevocable\":true,\"ownerName\":\"test\"}'
Expand All @@ -216,7 +223,6 @@ pnpm portal getPortalByAddress '{\"portalAddress\":\"0x8b833796869b5debb9b06370d
pnpm portal isPortalRegistered '{\"portalAddress\":\"0x8b833796869b5debb9b06370d6d47016f0d7973b\"}'

pnpm portal getPortalsCount

```

### Attestation examples
Expand All @@ -227,6 +233,32 @@ pnpm attestation findonebyid "0x000000000000000000000000000000000000000000000000
pnpm attestation findby '{\"portal\": \"0x34798a866f52949208e67fb57ad36244024c50c0\"}'

pnpm attestation getRelatedAttestations "0x0000000000000000000000000000000000000000000000000000000000000001"

pnpm attestation simulateUpdateRouter "0xC825ACA6621597bcb86438346A2538fba85380d9"

pnpm attestation updateRouter "0xC825ACA6621597bcb86438346A2538fba85380d9"

pnpm attestation simulateMassImport '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayloads\" : [{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]},{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}]}'

pnpm attestation massImport '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayloads\" : [{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]},{ \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}]}'

pnpm attestation simulateIncrementVersionNumber

pnpm attestation incrementVersionNumber

pnpm attestation isRegistered "0x0000000000000000000000000000000000000000000000000000000000000001"

pnpm attestation isRevocable "0xBA5bBAe01509311f61Bac8A15dCB4B41bEd8Ecb5"

pnpm attestation getAttestation "0x0000000000000000000000000000000000000000000000000000000000000001"

pnpm attestation getVersionNumber

pnpm attestation getAttestationIdCounter

pnpm attestation balanceof '{\"account\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"id\": 1}'

pnpm attestation balanceOfBatch '{\"accounts\": [\"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\"], \"ids\": [0, 1]}'
```

### Module examples
Expand Down
112 changes: 112 additions & 0 deletions sdk/examples/attestation/attestationExamples.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from "viem";
import VeraxSdk from "../../src/VeraxSdk";

export default class AttestationExamples {
Expand Down Expand Up @@ -31,5 +32,116 @@ export default class AttestationExamples {
argv === "" ? "0x0000000000000000000000000000000000000000000000000000000000000001" : argv;
console.log(await this.veraxSdk.attestation.getRelatedAttestations(attestationId));
}

if (methodName.toLowerCase() == "simulateUpdateRouter".toLowerCase() || methodName == "") {
const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address);
console.log(await this.veraxSdk.attestation.simulateUpdateRouter(routerAddress));
}

if (methodName.toLowerCase() == "updateRouter".toLowerCase() || methodName == "") {
const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address);
console.log(await this.veraxSdk.attestation.updateRouter(routerAddress));
}

if (methodName.toLowerCase() == "simulateMassImport".toLowerCase() || methodName == "") {
let params;
if (argv !== "") params = JSON.parse(argv);
const portalAddress = params?.portalAddress
? (params.portalAddress as Address)
: "0xeea25bc2ec56cae601df33b8fc676673285e12cc";

const attestationPayloads = params?.attestationPayloads ?? [
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
];
console.log(await this.veraxSdk.attestation.simulateMassImport(portalAddress, attestationPayloads));
}

if (methodName.toLowerCase() == "massImport".toLowerCase() || methodName == "") {
let params;
if (argv !== "") params = JSON.parse(argv);
const portalAddress = params?.portalAddress
? (params.portalAddress as Address)
: "0xeea25bc2ec56cae601df33b8fc676673285e12cc";

const attestationPayloads = params?.attestationPayloads ?? [
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
];
console.log(await this.veraxSdk.attestation.massImport(portalAddress, attestationPayloads));
}

if (methodName.toLowerCase() == "simulateIncrementVersionNumber".toLowerCase() || methodName == "") {
console.log(await this.veraxSdk.attestation.simulateIncrementVersionNumber());
}

if (methodName.toLowerCase() == "incrementVersionNumber".toLowerCase() || methodName == "") {
console.log(await this.veraxSdk.attestation.incrementVersionNumber());
}

if (methodName.toLowerCase() == "isRegistered".toLowerCase() || methodName == "") {
const attestationId: string =
argv === "" ? "0x00000000000000000000000000000000000000000000000000000000000007b5" : argv;
console.log(await this.veraxSdk.attestation.isRegistered(attestationId));
}

if (methodName.toLowerCase() == "isRevocable".toLowerCase() || methodName == "") {
const portalId: string = argv === "" ? "0xeea25bc2ec56cae601df33b8fc676673285e12cc" : argv;
console.log(await this.veraxSdk.attestation.isRevocable(portalId));
}

if (methodName.toLowerCase() == "getAttestation".toLowerCase() || methodName == "") {
const attestationId: string =
argv === "" ? "0x00000000000000000000000000000000000000000000000000000000000007b5" : argv;
console.log(await this.veraxSdk.attestation.getAttestation(attestationId));
}

if (methodName.toLowerCase() == "getVersionNumber".toLowerCase() || methodName == "") {
console.log(await this.veraxSdk.attestation.getVersionNumber());
}

if (methodName.toLowerCase() == "getAttestationIdCounter".toLowerCase() || methodName == "") {
console.log(await this.veraxSdk.attestation.getAttestationIdCounter());
}

if (methodName.toLowerCase() == "balanceOf".toLowerCase() || methodName == "") {
let params;
if (argv !== "") params = JSON.parse(argv);
const account = params?.account ? (params.account as Address) : "0x809e815596abeb3764abf81be2dc39fbbacc9949";
const id = params?.id ? (params.id as unknown as number) : 1;

console.log(await this.veraxSdk.attestation.balanceOf(account, id));
}

if (methodName.toLowerCase() == "balanceOfBatch".toLowerCase() || methodName == "") {
let params;
if (argv !== "") params = JSON.parse(argv);
const accounts = params?.accounts
? (params.accounts as Address[])
: ["0x809e815596abeb3764abf81be2dc39fbbacc9949", "0x809e815596abeb3764abf81be2dc39fbbacc9949"];
const ids = params?.ids ? (params.ids as number[]) : [1, 2];

console.log(await this.veraxSdk.attestation.balanceOfBatch(accounts as Address[], ids));
}
}
}
Loading

0 comments on commit 6e593ef

Please sign in to comment.