LibertyDSNP / eth-sdk-ts

TypeScript SDK for DSNP on Ethereum
Apache License 2.0
9 stars 1 forks source link

Helpful Code Snippets? #60

Open wilwade opened 3 years ago

wilwade commented 3 years ago

Do we have a place to put helpful code snippets like these?

// Config is a one time thing at app initialization:
import sdk from "@dsnp/sdk";
import { providers } from "ethers";

const provider = new providers.JsonRpcProvider(chainUrl);
const signer = new Wallet("[Private Key of the server]");

sdk.setConfig({ provider, signer });
// Want to filter a list of handles for the ones that are available?
import sdk from "@dsnp/sdk";

// Docs: https://libertydsnp.github.io/sdk-ts/modules/index.html#availabilityfilter-1

const handes = ["bob", "ali", "coolguy13"];
const availableHandles = await sdk.availabilityFilter(handles);
// Want create a new DSNP Registration?
import sdk from "@dsnp/sdk";

// Docs: https://libertydsnp.github.io/sdk-ts/modules/index.html#createregistration-1

const newDsnpId = await sdk.createRegistration(userPublicEthereumAddress, handle);
// Want to check that a user signed a message?
import { isMessageSignatureAuthorizedTo } from "@dsnp/sdk/core/contracts/registry";

// Docs: https://libertydsnp.github.io/sdk-ts/modules/core_contracts_registry.html#ismessagesignatureauthorizedto
await isMessageSignatureAuthorizedTo(signature, serializedMessage, dsnpId, 1);
kfogel commented 3 years ago

@wilwade A snippets file in the examples/ directory, maybe?