Class: TepuiRegistry

The main object used to interact with the Tepui Registry

Remarks

You can use a library like openid-client to authenticate to Tepui before making any calls. An initial refresh token can be obtained from the profile page in the Tepui application. The refresh token expires every 30 days. You can use the refresh_token grant to renew the token. The access token expires after 60 minutes. If your application runs for longer than that, you can pass a function to the TepuiRegistry constructor to refresh the token as needed.

const { Issuer } = require("openid-client");
const issuer = await Issuer.discover(TepuiRegistry.issuerUrl);
const client = new issuer.Client(TepuiRegistry.metadata);
const refreshToken = process.env["REFRESH_TOKEN"];
const tokenSet = await client.refresh(refreshToken);
const tepuiRegistry = new TepuiRegistry.default(() => tokenSet.access_token);

Hierarchy

  • TepuiRegistry

Index

Constructors

Methods

Constructors

constructor

+ new TepuiRegistry(authToken: function): TepuiRegistry

Parameters:

authToken: function

a function that returns a valid, unexpired open-id access token. The function is invoked prior to any request.

▸ (): Promise‹string | undefined›

Returns: TepuiRegistry

Methods

createPlan

createPlan(plan: IPlan): Promise‹IPlan

Creates a new plan

Parameters:

Name

Type

Description

plan

The plan to be created. The id should not be populated (if it is, it gets ignored)

Returns: Promise‹IPlan

The plan created including the id that can be used to refer to this plan

createSubscription

createSubscription(planId: string, subscriberAddress: string): Promise‹ISubscription

Registers a subscription with Tepui. This should be invoked after the subscription is submitted to the blockchain. It should be invoked by the user that subscribed.

Remarks

This method allows Tepui to associate a subscription with a Tepui user. The information is needed to notify the user about payment processing, low-balance notifications, etc.

Parameters:

Name

Type

Description

planId

string

the id of the plan that was subscribed

subscriberAddress

string

the blockchain address of the subscriber

Returns: Promise‹ISubscription

the subscription created

getPlanTransactionMap

getPlanTransactionMap(planIds: string[]): Promise‹object›

Parameters:

Name

Type

Description

planIds

string[]

the list of plan ids to query

Returns: Promise‹object›

an object map where the keys are the plan ids and the values contain the list of transactions for each plan The result can be passed to Tepui blockchain sdks to resolve the contract address for each plan

retrieveOwnedPlans

retrieveOwnedPlans(): Promise‹IPlan[]›

Returns: Promise‹IPlan[]›

all plans owned by the invoking user

retrievePlan

retrievePlan(planId: string): Promise‹IPlan | undefined›

Parameters:

Name

Type

Description

planId

string

The id of the plan to be retrieved

Returns: Promise‹IPlan | undefined›

the plan if found, undefined otherwise

retrievePlans

retrievePlans(): Promise‹IPlan[]›

Returns: Promise‹IPlan[]›

all public plans for all owners

retrieveProfile

retrieveProfile(sub: string): Promise‹IProfile | undefined›

Parameters:

Name

Type

Description

sub

string

the id of the user

Returns: Promise‹IProfile | undefined›

the profile for the user if found, undefined otherwise

retrieveSubscribedPlans

retrieveSubscribedPlans(subscriberAddress: string): Promise‹string[]›

throws if invoking user has not verified the address

Parameters:

Name

Type

Description

subscriberAddress

string

the address of the subscriber

Returns: Promise‹string[]›

the ids for all the subscribed plans

Remarks

this can only be invoked by a user that has verified posession of the private key associated with the address

retrieveSubscription

retrieveSubscription(planId: string, subscriberAddress: string): Promise‹ISubscription | undefined›

Parameters:

Name

Type

Description

planId

string

the id of the plan

subscriberAddress

string

the blockchain address of the subscriber

Returns: Promise‹ISubscription | undefined›

a subscription for a given plan and subscriber address, or undefined if the plan does not exist, the caller is not the owner, or the subscriber address does not have a subscription for that plan

Remarks

Only the plan owner can invoke this method

retrieveTokens

retrieveTokens(): Promise‹string[]›

Returns: Promise‹string[]›

the list of ERC-20 tokens supported

Remarks

Tepui will only deploy contracts for supported ERC-20 tokens

retrieveUserAddresses

retrieveUserAddresses(): Promise‹string[]›

Returns: Promise‹string[]›

the addresses registered to the invoking user

updatePlan

updatePlan(plan: IPlan): Promise‹IPlan

Updates an existing plan. The plan id needs to be populated.

Remarks

Only the owner of the plan can make changes to it

throws if a plan with the provided id is not found

Parameters:

Name

Type

Description

plan

the plan object used to update the plan

Returns: Promise‹IPlan

the plan updated

verifyUserAddress

verifyUserAddress(address: string, payload: string, signature: string): Promise‹void›

Adds a registered address to the user making the call

Remarks

Invoke this method to add a blockchain address for the user. It gives the user the ability to view subscriptions for that address. The server verifies that the user owns the private key by checking signature that should be signed with the provided address. The payload is expected to be the current timestamp in ISO format. Payloads older than 5 minutes will result in an error. The signature can be obtained by invoking the Tepui signPayload method in the appropriate blockchain sdk.

Parameters:

Name

Type

Description

address

string

the address to be registered to the user

payload

string

a data payload that was signed in the provided signature

signature

string

the signature of the payload with the provided address

Returns: Promise‹void›

Last updated

Was this helpful?