@tephranet/tephra-sdk
v2.2.2
Published
This is the official SDK for [Tephra](https://tephra.co). A platform for tracking and preserving the authenticity of assets as they're transferred between users.
Downloads
43
Readme
Tephra SDK
This is the official SDK for Tephra. A platform for tracking and preserving the authenticity of assets as they're transferred between users.
Getting Started
You can install the SDK with npm
or yarn
:
npm install @tephranet/tephra-sdk
# or ...
yarn add @tephranet/tephra-sdk
Once the SDK is installed, you can create a new instance with your Tephra key and secret.
// Import our SDK
import { TephraSDK } from '@tephranet/tephra-sdk'
// Authenticate
const tephra = new TephraSDK(KEY, SECRET)
Create an Asset
An asset is a representation of whatever is being preserved. Each asset can be owned by just one individual at a time.
const address = await tephra.create()
console.log(`Now there's an asset at "${address}"`)
// e.g., Now there's an asset at "3a134374-b266-411f-882b-022422d05989"
When you create an asset in Tephra, it will be given an address. This unique address represents the asset. It can be used to retrieve information about the asset like the current owner, date of creation, chain of custody, etc.
Note: All transactions on the Tephra production server are stored in the global changeset. The changeset is regularly chunked and preserved on IPFS and timestamped on an Ethereum NFT. Because of this, the changeset is public and immutable.
Asset Contents
Assets can have contents like a name, description, image, and a list of attributes. These contents will be preserved as part of the changeset so they can be used to prove authenticity. They will also be displayed when the asset is validated and provide context for users.
// Create an asset
const assetAddress = await tephra.create({
name: 'My First Asset',
description: 'This asset will exist forever.',
image: {
type: 'ipfs',
address: someIpfsAddress,
},
// Attributes can be used to store any structured
// information about the asset.
attributes: [
{
label: 'Created By',
value: 'Me.',
},
],
})
Custom Addresses
In some cases you might already have universally unique IDs for your products. You can also provide a custom address when creating an asset. Keep in mind that this call will fail if the address already exists.
tephra.create(myProduct, '10fbc842-b481-4556-93c8-b2a7373997ab')
Grants & Transfers
Once the asset has been created you can easily grant it to a user and transfer it between users. The string representation of the user (often a user ID or an email) must be unique for each user but it doesn't have to be unique accross the Tephra network.
// Grant the asset
await tephra.grant(address, USER_ONE)
// Transfer the asset
await tephra.transfer(address, USER_ONE, USER_TWO)
Privacy
Privacy is important to us. We don't store any user information beyond these address
<> userId
relationships. In cases where more detail is required (e.g., displaying user avatars in a chain of custody log) we request the information from your server using the userId
you provide and we won't save it.
Security
We provide assurances that an asset can only be granted to a user ID once, and that tranfers always originate from the user ID that currently owns them. This makes it easier for developers to safely build patterns around trading and secondary sales.
Ejecting
When an asset is consumed, or ported to another marketplace, it can no longer be acted on in Tephra. When this happens, we say the asset has been "ejected". The address can still be validated but it will contain information about the last owner and the date it left the Tephra platform.
await tephra.eject(address, FROM_USER)