Sauron API
Introduction
Sauron is the GraphQL API your application’s server will call to request the data you seek.
eye-of-sauron Node.js SDK
We provide a Node.js SDK that makes it super easy to interact with the Sauron API. eyeofsauron
completely abstracts away the complexity of authentication and interacting with the GraphQL APIs.
Install eye-of-sauron
npm i -g @gandalf-network/eyeofsauron
eyeofsauron generate
This will generate an eyeofsauron
folder in your project root directory.
Usage
Import the library
// Typescript
import Eye, { Source } from './eyeofsauron';
// ESModules
import Eye, { Source } from './eyeofsauron/index.js';
// CommonJS
const Connect = require("@gandalf-network/connect");
const { Source } = require('./eyeofsauron');
Get Activity
const eye = new Eye({privateKey: process.env.PRIVATE_KEY})
const { data } = await eye.getActivity({dataKey: dataKey, source: Source.Amazon, limit: 100, page: 2})
Authentication
eyeofsauron
SDK handles all of this authentication stuff automagically! You might want to consider using it
instead.Every request to the Sauron API needs to be authenticated using your privateKey
. This is required to validate that the data request is truly coming from your application.
Prepare the signature
Start by creating a digital signature of your request’s body. You’ll need to hash the body of your request using
SHA-256 and then sign the hash with ECDSA using your privateKey
.
Encode the signature
After signing, encode the digital signature using Base64.
Add signature header
Add the Base64-encoded signature to the request’s headers with the key X-Gandalf-Signature
.
privateKey
is extremely important. All requests to Sauron should be made server-side.See example code snippets:
Requesting Data
Calling the getActivity()
query is how you pull data on your users.
eye-of-sauron
as a function. You can read about all
Queries, Mutations & Types in the Schema Reference.