0.4.0 • Published 4 years ago

@interrep/api v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

🛠 Install

NPM or Yarn

Install the @interrep/api package with npm:

npm i @interrep/api --save

or yarn:

yarn add @interrep/api

CDN

You can also load it using a script tag using unpkg:

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/@interrep/api/"></script>

or JSDelivr:

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@interrep/api/"></script>

📜 Usage

# new API(environment: Environment): API

import { API } from "@interrep/api"

const api = new API()
const devApi = new API("development")

console.log(api.url) // "https://kovan.interrep.link/api"
console.log(devApi.url) // "http://localhost:3000/api"

# api.getProviders(): Promise<string[]>

const providers = await api.getProviders()

API: api/providers

# api.getGroups(): Promise<any[]>

const groups = await api.getGroups()

API: api/groups

# api.getGroup(parameters: GetGroupRequest): Promise<any>

const group = await api.getGroup({
    provider: "twitter",
    name: "gold"
})

API: /api/groups/:provider/:name

# api.hasIdentityCommitment(parameters: HasIdentityCommitmentRequest): Promise<boolean>

// For any provider group.
const hasIdentityCommitment = await api.hasIdentityCommitment({
    provider: "twitter",
    identityCommitment: "1231231..."
})

API: /api/providers/:provider/:identityCommitment

// For specific group.
const hasIdentityCommitment = await api.hasIdentityCommitment({
    provider: "twitter",
    name: "gold",
    identityCommitment: "1231231..."
})

API (method: get): /api/groups/:provider/:name/:identityCommitment

# api.addIdentityCommitment(parameters: AddIdentityCommitmentRequest): Promise<boolean>

// For Web2 providers.
await api.addIdentityCommitment({
    provider: "twitter",
    name: "gold",
    identityCommitment: "1231231...",
    authenticationHeader: "token <OAuth-token>"
})
// For Web3 providers.
await api.addIdentityCommitment({
    provider: "poap",
    name: "devcon4",
    identityCommitment: "1231231...",
    userAddress: "0xueaoueao",
    userSignature: "aueouaoe"
})

API (method: post): /api/groups/:provider/:name/:identityCommitment

# api.deleteIdentityCommitment(parameters: DeleteIdentityCommitmentRequest): Promise<boolean>

// For Web2 providers.
await api.deleteIdentityCommitment({
    provider: "twitter",
    name: "gold",
    identityCommitment: "1231231...",
    authenticationHeader: "token <OAuth-token>"
})
// For Web3 providers.
await api.deleteIdentityCommitment({
    provider: "poap",
    name: "devcon4",
    identityCommitment: "1231231...",
    userAddress: "0xueaoueao",
    userSignature: "aueouaoe"
})

API (method: delete): /api/groups/:provider/:name/:identityCommitment

# api.getMerkleTreeProof(parameters: GetMerkleTreeProofRequest): Promise<any>

const proof = await api.getMerkleTreeProof({
    provider: "twitter",
    name: "gold",
    identityCommitment: "1231231..."
})

API: /api/groups/:provider/:name/:identityCommitment/proof

# api.getMerkleTreeLeaves(parameters: GetMerkleTreeLeavesRequest, options: RequestOptions): Promise<string[]>

const leaves = await api.getMerkleTreeLeaves(
    {
        rootHash: "1212121..."
    },
    {
        limit: 10
    }
)

API: /api/trees/:rootHash

# api.hasMerkleTreeLeaf(parameters: HasMerkleTreeLeafRequest): Promise<boolean>

const hasMerkleTreeLeaf = await api.hasMerkleTreeLeaf({
    rootHash: "1212121...",
    leafHash: "2122131..."
})

API: /api/trees/:rootHash/:leafHash

# api.getMerkleTreeRootBatches(): Promise<any[]>

const rootBatches = await api.getMerkleTreeRootBatches()

API: /api/trees/batches

# api.getMerkleTreeRootBatch(parameters: GetMerkleTreeRootBatchRequest): Promise<any>

const rootBatch = await api.getMerkleTreeRootBatch({
    rootHash: "1212121..."
})

API: /api/trees/batches/:rootHash

0.3.0

4 years ago

0.4.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago