SAS-SDK (Starknet Attestation System SDK) is a JavaScript/TypeScript library for interacting with Starknet-based smart contracts. This SDK provides functions to manage schemas, create attestations, and validate attestations efficiently.
- Schema Management: Create and fetch schemas.
- Attestation: Register and validate attestations on Starknet.
- Simplified Integration: Easily connect and interact with Starknet smart contracts.
Install the SDK using npm or yarn:
npm install sas-sdk
or
yarn add sas-sdk
- Clone the repository for the example or start a new project.
git clone https://github.com/rajeebkm/sas-sdk
cd sas-sdk
- Install dependencies:
npm install
Here’s an example of how to use the SAS-SDK in your project:
require("dotenv").config();
const { SAS } = require("sas-sdk");
(async () => {
try {
const sas = new SAS({
network: "testnet",
srContractAddress: process.env.SR_CONTRACT_ADDRESS,
saContractAddress: process.env.SA_CONTRACT_ADDRESS,
privateKey: process.env.PRIVATE_KEY,
accountAddress: process.env.ACCOUNT_ADDRESS,
});
// Create a schema
const schema = await sas.createSchema("schema_hash_example");
console.log("Schema created:", schema);
// Fetch all schemas
const schemas = await sas.getSchemas();
console.log("Schemas:", schemas);
// Register an attestation
const attestation = await sas.attest("schema_id_example", "claim_hash_example");
console.log("Attestation registered:", attestation);
// Validate an attestation
const validation = await sas.validate("schema_id_example", "claim_hash_example");
console.log("Validation result:", validation);
} catch (error) {
console.error("Error:", error);
}
})();
Run the example script:
node example/usage.js
new SAS({ network, srContractAddress, saContractAddress, privateKey, accountAddress });
network
(string): Network to use (e.g.,mainnet
,testnet
).srContractAddress
(string): Schema Registry contract address.saContractAddress
(string): Schema Attestation contract address.privateKey
(string): Private key for the account.accountAddress
(string): Starknet account address.
-
createSchema(schemaHash)
- Creates a schema.
- Parameters:
schemaHash
(string): The hash of the schema to be created.
- Returns: Schema details.
-
getSchemas()
- Fetches all schemas.
- Returns: Array of schema details.
-
attest(schemaId, claimHash)
- Registers an attestation.
- Parameters:
schemaId
(string): ID of the schema.claimHash
(string): Hash of the claim to be attested.
- Returns: Attestation details.
-
validate(schemaId, claimHash)
- Validates an attestation.
- Parameters:
schemaId
(string): ID of the schema.claimHash
(string): Hash of the claim to validate.
- Returns: Validation result (boolean).
Contributions are welcome! Please fork the repository and submit a pull request. Ensure you adhere to the coding standards and add tests for any new functionality.