Itheum Docs
  • 👋Getting Started
  • Infrastructure
    • 🚆AI Data Workforce
      • Token Utility for the AI Data Workforce
      • Join the Workforce
      • Liveliness Staking Rewards
    • 🖼️Data NFT
      • Data NFT Types
        • Data NFT-FT
        • Data NFT-LEASE
        • Data NFT-PH (Plug-In Hybrid)
      • Data NFT Generative Image Tool
    • 🤖NFMe ID Vaults
    • 🔋Liveliness - On-Chain Reputation
      • Data Creator Liveliness Bonding
        • Liveliness Score States
      • Liveliness Staking
      • FAQ - Liveliness staking
    • 🔓Data Marshal Network
  • Apps
    • 🔥<BiTz> XP System
      • Bonus BiTz for protocol usage
    • 💹Data NFT Marketplace
      • Listing a Data NFT
      • Procuring a Data NFT
      • FAQ - Data NFT Marketplace
    • 📡Data DEX
      • Minting a Data NFT
        • Store Data and Mint a Data NFT - Step-by-Step Tutorial
        • Creator Donations For Community Airdrops
      • Using the claims Portal
      • CanaryNet Guardrails
        • Guardrail : Trading Data NFTs on 3rd Party NFT Marketplaces
    • 🔍Itheum Explorer
  • Integrators
    • 🔋Liveliness Staking Guides
      • Liveliness Staking Guide : Solana
      • Liveliness Staking Guide : MultiversX
    • 📙Data Streams Guides
      • Data Asset Storage Options
      • Data Stream URL Rules
      • Zedge Storage
        • Static File on IPFS
        • Dymamic File on IPFS + DNS Link
        • Dymamic File on IPFS + IPNS
        • Music Data NFT Compatible Dynamic Data Stream on IPFS + IPNS
        • Trailblazer Data NFT Compatible Dynamic Data Stream on IPFS + IPNS
      • Amazon Web Services (AWS)
        • Storage : AWS S3
          • Data NFT Streaming Automation - Multiple files
          • Manual upload of file to AWS for Data NFT Streaming
          • Data NFT Streaming Automation - Trailblazer
        • Hosting : AWS S3 + Cloudflare
          • Task 1: Use a domain name to "sit in front" of your AWS S3 Bucket Public URL
          • Task 2: Convert your AWS S3 Bucket into a "website"
          • Task 3: Use Cloudflare to connect your Domain Name to your S3 Bucket securely
          • Troubleshooting
      • Akord - Arweave blockchain
      • MultiversX Native Auth Protected API
    • 📗Data DEX Guides
      • MultiversX Blockchain
        • Guide 1 : Get Started with the Data DEX on MultiversX
          • Section 1: Setting up wallets on the MultiversX Blockchain - Devnet
          • Section 2: Getting xEGLD Gas tokens to pay for transactions - MultiversX Devnet
          • Section 3: Getting ITHEUM devnet tokens via the Data DEX - MultiversX Devnet
        • Guide 2: Get Started with Itheum Enterprise
        • Itheum Ecosystem Actions Catalogue
      • Astar Network
        • Guide 1 : Get Started with the Data DEX on Astar Network
          • Section 1: Setting up wallets on Astar Network - Shibuya Testnet
          • Section 2: Getting ITHEUM devnet tokens via the Data DEX - Shibuya Testnet
        • Guide 2 : Procure Data NFTs from the peer-to-peer Data NFT Marketplace on Astar Network
        • Guide 3: Use the “Web3 Gamer Passport” App on the Astar Network to trade your PlayStation Data
    • 💳Supported Wallets
      • MultiversX DeFi Wallet
      • Ledger Wallet
      • xPortal Wallet
      • xAlias (Login with Google)
    • 📕Trailblazer Guides
      • How to Acquire a Trailblazer
      • How to view a Trailblazer
      • How to List a Trailblazer
    • 📘Data Coalition DAOs (DC DAOs) Guides
      • Appointer > Delegator Pattern for Data NFT "Deputizing"
  • Developers
    • 👨‍💻Software Development Kits (SDKs)
      • Data NFT SDK
        • Guide 1 : Minting a Custom Data NFT Collection with Authenticated Data Streams (via SDK)
        • Guide 2 : Unlocking Data NFTs via MultiversX Native Auth
        • Guide 3 : Using Nested Streams to Access Nested Data Assets from a Primary Data Stream
        • Guide 4: Use the Data NFT "Deputy" Feature to delegate access of your Data NFTs to a Smart Contract
        • Guide 5: Preparing a Data Stream containing a password to protect a URL
      • Enterprise SDK
        • Guide 1 : Using Itheum Enterprise to Mint a Data NFT Collection (e.g. NFT Loyalty Card Solution)
      • Data Marshal Network SDK
        • Guide 1 : Make your Regular NFT Collection to be Data NFT-PH Compatible
    • 🥋Data Marshal Network
      • Data Marshal Node Gateway Endpoints
      • Data Marshal Transit Flags and Headers
    • 🛂Tech Support - Discord
      • Portal Bridge Support
    • 🛒Release Notes
      • Data DEX
      • Itheum Explorer
      • Data NFT SDK
      • Enterprise SDK
      • Data Marshal Network
    • 🔐Security
      • 🐞Bug Bounty
      • ℹ️Security Audit
  • Protocol
    • $ITHEUM Token
    • 🌉Token Bridge
      • FAQ - Omni-Chain Portal Bridge
      • $ITHEUM Token Multi-Chain Max Supply Rebalancing Transactions Audit
    • 🏆Token Rewards
      • Badges
    • 🧨Token Burning
      • Phase 1 : Token Burn Program
    • 🏛️Governance
      • Itheum Ecosystem DAO
        • Version 1: How it Works
      • Itheum xPand DAO
        • Itheum xPand Grants Program
          • Code Of Conduct
          • Announcement Guidelines
          • Cohorts vs Alpha Builders
        • Program 1: MultiversX Post-Hackathon Accelerator
        • Program 2: xPand DAO Music Data NFT Growth
    • 💪Hackathons and Dev Challenges
      • MultiversX xDay Hackathon
        • Project Ideas > MultiversX Dev Tooling and Infra
        • Project Ideas > Itheum
        • Test Data NFT Catalog
      • Community Test Events
        • Portal Traveler 🌀 : Test the Itheum Omni-Chain Portal (Bridge)
        • APR for Liveliness 🎖️: Test the Bonding + Staking Rewards Module
        • Minting and Bonding on Solana
  • R&D
    • 🏢Itheum Enterprise
    • 🗳️Data Coalition DAOs (DC DAOs)
    • 🎏Trailblazer
      • FAQ - Trailblazer
  • Legal
    • ⚖️Ecosystem Tools Terms
      • Datadex
        • Terms Of Use
        • Privacy Policy
      • Liveliness Bonding: Penalties and Slashing Terms
      • BiTz XP
        • Give BiTz
      • Omni-Chain Portal Bridge
      • Gamer Passport
        • Data Collection and Storage
    • 👮Content Guidelines
    • Itheum Data License
    • Terminology Disclaimer
    • Protocol Docs, Token Disclaimer
Powered by GitBook
On this page
  • What is Native Auth?
  • How Native Auth Improves the Data NFT User Experience
  • Target User Story:
  • Step 1: Installation of Itheum Data NFT SDK
  • Step 2: Using SDK Core to enable MultiversX Wallet Login with Native Auth Enabled
  • Step 3: Grab a Native Auth "Session Token"
  • Step 4: Open a Data NFT and "View Data" via a Native Auth session
  • Bonus Step 5: How can I parse non-JSON Data Streams?
  1. Developers
  2. Software Development Kits (SDKs)
  3. Data NFT SDK

Guide 2 : Unlocking Data NFTs via MultiversX Native Auth

PreviousGuide 1 : Minting a Custom Data NFT Collection with Authenticated Data Streams (via SDK)NextGuide 3 : Using Nested Streams to Access Nested Data Assets from a Primary Data Stream

Last updated 1 year ago

This guide walks you through how to use MultiversX Native Auth to access Data Stream that are served by the Itheum protocol. Native Auth significantly improves the user experience of accessing data available within Data NFT protected Data Streams.

What is Native Auth?

Before we begin, we need to understand what Native Auth is. Native Auth can be thought of as the traditional "Single Sign On" experience you see with many web2 apps, where you log into a single app and remain logged into other apps that are part of the same login service (e.g., Google Login). Similarly, with MultiversX Native Auth, you can log into a single DApp using your Crypto Wallet and have this "login session" persist across all other MultiversX ecosystem DApps that can access that Native Auth "login session."

How Native Auth Improves the Data NFT User Experience

In Itheum, we have multiple DApps that are connected to the MultiversX blockchain (e.g., Data DEX or Itheum Explorer). With Native Auth, you can log into one of these DApps, interact with the Data Marshal (a data broker node connected to the MultiversX blockchain), seamlessly prove your web3 identity and ownership of Data NFTs, unlock it, and view the data with it. Without Native Auth, you must provide your identity multiple times in a single-user journey by signing numerous messages with your wallet. This makes the user experience feel unnatural. With Native Auth, the user experience becomes closer to the traditional website experience, bringing Itheum closer to mainstream adoption by breaking down complex web3 workflows.


🏎️ Ready to start? Here are a few assumptions and pre-conditions

  • You need @itheum/sdk-mx-data-nft v2.1.0 or above to follow this guide.

  • This guide assumes that you are integrating with Itheum via an application built on the MultiversX blockchain, you use TypeScript/JavaScript as your programming language and that you use that use the @multiversx/sdk-core and @multiversx/sdk-dapp libraries to authenticate and sign and track on-chain transactions. Although, these libraries are optional and you can use any MultiversX tooling to interact with the blockchain.


Target User Story:

As an integrator of Itheum web3 Data Brokerage infrastructure:

  • I'd like build a simple Data NFT viewer, that let's a logged in user select specific Data NFTs and open them to view the underlying data seamlessly without having to sign any extra transactions that force the user to prove ownership of the Data NFTs

  • I'd also like to build some generic handler that can parse various Data Streams like JSON, TXT, SVG, AUDIO etc so I can display the content in my app

Let's begin...


Step 1: Installation of Itheum Data NFT SDK

npm install --save @itheum/sdk-mx-data-nft

Step 2: Using SDK Core to enable MultiversX Wallet Login with Native Auth Enabled

import React from "react";
import { ExtensionLoginButton } from "@multiversx/sdk-dapp/UI";

function MyLoginComponent() {
  const commonProps = {
    callbackRoute: "/foobar",
    nativeAuth: {
      apiAddress: "https://devnet-api.multiversx.com",
      expirySeconds: 3000,
    },
  };

  return (
    <>
      <ExtensionLoginButton loginButtonText="DeFi Wallet" {...commonProps} />
    </>
  );
}

Note that the commonProps.nativeAuth params are important to note as you will need to match these later on when you configure Native Auth on Itheum's SDK in a step below.

Step 3: Grab a Native Auth "Session Token"

import React from "react";
import { useGetLoginInfo } from "@multiversx/sdk-dapp/hooks";

function MyAppComponent() {
  const { tokenLogin } = useGetLoginInfo();
  const nativeAuthToken = tokenLogin?.nativeAuthToken;

  return <>My Native Auth Session is {nativeAuthToken}</>;
}

Step 4: Open a Data NFT and "View Data" via a Native Auth session

Next, select a Data NFT and "View its Data" using the obtained Native Auth session. As detailed in the introduction of this document, as you are using Native Auth to prove your identity and, therefore, ownership of the Data NFT you are interacting with, you no longer need to sign a custom message like in the regular viewData method also available in the SDK.

In the below same React code, we get to the step of using the Itheum Data NFT SDK to grab a target Data NFT, get its data and then trigger a custom View Data method that supports Native Auth. This example builds on the previous step's code example and show how we can open a Data NFT with a JSON Data Stream.

import React, { useState } from "react";
import { useGetLoginInfo } from "@multiversx/sdk-dapp/hooks";
import { DataNft, ViewDataReturnType } from "@itheum/sdk-mx-data-nft";

async function MyAppComponent() {
  const [showData, setShowData] = useState({});
  const { tokenLogin } = useGetLoginInfo();
  const nativeAuthToken = tokenLogin?.nativeAuthToken;

  // Specify some Data NFTs nonces that you want to fetch
  const DATA_NFT_NONCES_I_WANT_TO_OPEN = [407, 423, 453];

  try {
    /*  Here we use the SDK to fetch the Data NFTs we want to try and open for the logged in user
        note how createManyFromApi takes in a array of objects with mandatory parameter "nonce" 
        and optional parameter "tokenIdentifier" which you can use to select a separate Data NFT collection
        that you may have minted as part of Itheum Enterprise. Leaving tokenIdentifier empty will default to
        the public Data NFT-FT collection that is part of the Ithuem Protocol */
    const _nfts: DataNft[] = await DataNft.createManyFromApi(DATA_NFT_NONCES_I_WANT_TO_OPEN.map((nonce) => ({ nonce })));

    const dataNftToOpen = _nfts[0]; // from the returned set, let's open the 1st one for now just to test

    const res: ViewDataReturnType = await dataNftToOpen.viewDataViaMVXNativeAuth({
      mvxNativeAuthOrigins: ["http://localhost:3000"], // this should match the domain you are on as you run the app
      mvxNativeAuthMaxExpirySeconds: 3000, // this should match the expirySeconds value from Step 2
      fwdHeaderKeys: "authorization", // forward the authorization header to the data stream server (so it can validate the sesison and get caller address etc)
      fwdHeaderMapLookup: {
        "authorization": `Bearer ${nativeAuthToken}`,
      },
    });

    if (!res.error) {
      // if the Data Stream is JSON data this is how we grab it
      res.data = await (res.data as Blob).text();

      setShowData(JSON.parse(res.data));
    } else {
      // And Data Stream errors may end up here so you can handle them as needed
      console.error(res.error);
    }
  } catch (err) {
    // ALL Itheum Data NFT SDK errors appear here, so you can handle them as needed
    console.error(err);
  }

  return `<>JSON DATA from the Opened Data NFT is : ${JSON.stringify(showData)}</>`;
}
  • Note that the above code will ONLY work if the logged in user owns the Data NFTs with the nonces in the DATA_NFT_NONCES_I_WANT_TO_OPEN array, or else you will get an error that indicates that they don't own the Data NFT.

  • On ~line 33, we show you how you can open a JSON specific Data Stream that sits behind a Data NFT. But in reality, a Data NFT can contain a Data Stream that is in any format. So you will need some custom code to try and handle various file types. That's given next...

Bonus Step 5: How can I parse non-JSON Data Streams?

Although this is not part of the Native Auth requirements of this guide, here is some sample code that shows you how to parse some common Data Stream types that the Itheum protocol supports. The code below is an extension to the code block shown in Step 4 and is just some sample code.

enum BlobDataType {
  TEXT,
  IMAGE,
  AUDIO,
  SVG,
  PDF,
}

let blobDataType = BlobDataType.TEXT;
let unpackedData = null;

if (!res.error) {
  if (res.contentType.search("image") >= 0) {
    if (res.contentType == "image/svg+xml") {
      blobDataType = BlobDataType.SVG;
      unpackedData = await (res.data as Blob).text(); // parse SVG in raw data we can show inside a SVG tag
    } else {
      blobDataType = BlobDataType.IMAGE;
      unpackedData = window.URL.createObjectURL(new Blob([res.data], { type: res.contentType })); // parse IMG into a URL we can show
      
    }
  } else if (res.contentType.search("audio") >= 0) {
    res.data = 
    blobDataType = BlobDataType.AUDIO;
    unpackedData = window.URL.createObjectURL(new Blob([res.data], { type: res.contentType })); // parse Audio file into a URL we can play
  } else if (res.contentType.search("application/pdf") >= 0) {
    blobDataType = BlobDataType.PDF;
    unpackedData = window.URL.createObjectURL(new Blob([res.data], { type: res.contentType })); // parse PDF file into a URL we can open
  } else if (res.contentType.search("application/json") >= 0) {
    unpackedData = await (res.data as Blob).text(); // parse JSON file that we can use locally
    unpackedData = JSON.stringify(JSON.parse(unpackedData), null, 4);
  } else if (res.contentType.search("text/plain") >= 0) {
    unpackedData = await (res.data as Blob).text(); // parse TXT file that we can use locally
  } else {
    // we don't support that format
    unpackedData = "Sorry, this file type is currently not supported by the Explorer File Viewer. The file type is: " + res.contentType;
  }
} else {
  // And Data Stream errors may end up here so you can handle them as needed
  console.error(res.error);
}

In your NodeJS/JavaScript/TypeScript app, install the SDK @itheum/sdk-mx-data-nft by following the . If you are using NPM then it would be.

The code snippet below is just an example of how you would use the React Based SDK Core to drop some Wallet Login components on your DApp and configure them for Native Auth based session usage. You can choose to natively implement this as well on any other front-end using the . Although we find that SDK Core provides all that is needed to build an app fast. The below React code sample is not a complete working version, but shows the parts needed for a SDK Core based implementation setup for Native Auth via the .

As you have enabled Native Auth via SDK Core, the following code snippet shows you how you can obtain your Native Auth Session Token. Again, this is a SDK Core specific React example code snippet, you can choose to follow this or implement your custom front-end using the .

👨‍💻
🏁
instructions here
Native Auth Client library from MultiversX
DeFi Browser Extension Wallet
Native Auth Client library from MultiversX