Futureverse Asset Register Core SDK
Installation
NPM:
npm install @futureverse/asset-register --save
Yarn:
yarn add @futureverse/asset-register
Usage
Create Schema
import { Wallet } from 'ethers'
import { AssetRegister } from '@futureverse/asset-register'
import { Namespace } from '@futureverse/asset-register/types'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const assetRegisterSdk = new AssetRegister({
url: 'https://ar.futureverse.app/graphql',
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress,
},
})
assetRegisterSdk.createSchema({
namespace: 'fv.test' as Namespace,
schema: '',
version: 0.1,
})
Asset Linking
import {
AssetRegister,
AssetTransactionMessage,
ChainAddress,
Signature,
TransactionHash,
} from '@futureverse/asset-register'
import { ARTM, STATEMENTS } from '@futureverse/artm'
import { Wallet } from 'ethers'
const GQL_API_URL = 'http://localhost:8080/graphql'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const boxerDid =
'did:fv-asset:5:evm:0x5085cc0236ae108812571eadf24beee4fe8e0c50:4132'
const asmGenTwoBrainDid =
'did:fv-asset:5:evm:0x51cea47135c93eee33a6c15c22ea3532aec0540a:375'
let nonce = 0
const assetRegisterSdk = new AssetRegister({
url: GQL_API_URL,
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress: walletAddress,
},
})
nonce = await assetRegisterSdk.nonceForChainAddress(
walletAddress as ChainAddress,
)
const artmMessage = new ARTM({
address: walletAddress,
statement: STATEMENTS.OWNERSHIP,
nonce: nonce,
})
const operation = 'create'
artmMessage.operations = [
{
type: 'asset-link',
action: operation,
args: ['equipWith_asmBrain', boxerDid, asmGenTwoBrainDid],
},
]
const signature = await wallet.signMessage(artmMessage.getMessageToSign())
const input = {
signature: signature as Signature,
transaction: artmMessage.message as AssetTransactionMessage,
}
const response = await assetRegisterSdk.submitTransaction(input)
const transactionStatus = await assetRegisterSdk.transaction({
transactionHash: response.transactionHash as TransactionHash,
})
Create off-chain Asset
import { AssetRegister } from '@futureverse/asset-register'
import { Wallet } from 'ethers'
import { v4 as uuidv4 } from 'uuid'
const GQL_API_URL = 'http://localhost:8080/graphql'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const CREATOR_ID = '72fe2ff1-5f69-40e3-90b3-5335c7126552'
const assetRegisterSdk = new AssetRegister({
url: GQL_API_URL,
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress: walletAddress,
},
})
const creatorCollectionId = uuidv4()
const sftInput = {
creatorCollectionId: creatorCollectionId,
creatorId: CREATOR_ID,
}
const response = await assetRegisterSdk.registerOffChainAsset(sftInput)
const tokenId = uuidv4()
const creatorCollectionId2 = uuidv4()
const nftInput = {
creatorCollectionId: creatorCollectionId2,
creatorId: CREATOR_ID,
tokenId: tokenId,
}
const response2 = await assetRegisterSdk.registerOffChainAsset(nftInput)
Get Asset Tree
import { AssetRegister } from '@futureverse/asset-register'
import {
CollectionId,
} from '@futureverse/asset-register/types'
import { Wallet } from 'ethers'
const GQL_API_URL = 'http://localhost:8080/graphql'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const boxerDid =
'did:fv-asset:5:evm:0x5085cc0236ae108812571eadf24beee4fe8e0c50:4132'
const [_did, _fvAsset, chainId, chainType, contractAddress, tokenId] = boxerDid.split(':')
const assetRegisterSdk = new AssetRegister({
url: GQL_API_URL,
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress: walletAddress,
}
})
const collectionId = `${chainId}:${chainType}:${contractAddress}` as CollectionId
const assetTree = await ar.getAssetTree({
tokenId
collectionId
})
const paths = assetTree?.paths
const clothingAssetTreePath = await assetTree.getPath('http://schema.futureverse.com#equippedWith_accessoryClothing')
const clothingAssetTree = await clothingAssetTreePath.getAssetTree()
Migration guide from @futureverse/asset-registry
package
The new package name for this library is now @futureverse/asset-register
. Hence, there are some files
and codes that have been renamed in the new version. Here are the migration guides:
./src/lib/AssetRegistry.ts
file is now ./src/lib/AssetRegister.ts
AssetRegistry
class is now AssetRegister
- For types:
AssetRegistryError
is now AssetRegisterError
AssetRegistryErrorExtensions
is now AssetRegisterErrorExtensions
New Core SDK APIs
The original Core SDK API had limitations:
- Cumbersome Pagination: It lacked user-friendly features for navigating through large datasets.
- Limited Batching: It couldn't process multiple data requests (queries or mutations) in a single call.
- Inefficient Relationship Handling: It wasn't optimized for retrieving related data elements effectively.
To address these shortcomings, we've introduced a redesigned Core SDK API.
All the new APIs are located under the @futureverse/asset-register/v2
path of the npm package.
Initialize the client
const auth: AuthorizationParameters = {
...
}
const client = new new AssetRegister({
url: 'http://localhost:8080/graphql',
auth
}
Authentication
interface AuthorizationParameters {
sign: SignFunction
storage: Storage
domain: string
origin: string
chainId: number
walletAddress: string
}
client.setAuthorizationParameters(auth: AuthorizationParameters)
Query
const [namespaces] = await client.namespaces().execute()
const [domains] = await client.domains().execute()
Multiple queries in one request
const [namespace, assets1, assets2] = await client
.namespaces()
.asset({
tokenId: '<tokenId 1>',
collectionId: '<collectionId 1>' as CollectionId,
})
.asset({
tokenId: '<tokenId 2>',
collectionId: '<collectionId 2>' as CollectionId,
})
.execute()
if (namespaces.hasNextPage()) {
const namespaces_on_next_page = await namespaces.nextPage()
}
Access the items in the list by map method
const [namespaces] = await client.namespaces().execute()
namespaces.map((namespace) => {
})
Access sub-items directly
const [asset] = client.asset({
tokenID: 'token id',
collectionID: 'collection id'
}).execute()
const schema = asset.schema;
const assetTree = asset.assetTree;