npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tokenproof/react-native-client-sdk

v0.1.5

Published

tokenproof Client SDK

Downloads

12

Readme

@tokenproof/react-native-client-sdk

tokenproof Client SDK

Installation

npm install @tokenproof/react-native-client-sdk

Introduction

tokenproof wallet QR code SDK provides a short set of functionalities that allow developers to seamlessly integrate the issuance of tokenproof Verifiable Credentials (VCs) into their applications. With this SDK, you can generate VCs that adhere to our standard, ensuring interoperability and compatibility with tokenproof Verifier app.

Flows

Onboarding

To start using the tokenproof wallet SDK, you need to first initialize the device by calling initializeDevice, so it ensures the device is registered and linked by means of its DID (decentralized ID). If the app is uninstalled and reinstalled, a new DID will be tied to the device.

The redeem code should be generated by the partner backend API by calling

method: POST 
headers: {x-api-key: <your_api_key>, ...}
url: api.tokenproof.xyz/v1/partneronboarding/<app_id>/create
body: {address: string; credential_type:string;}

whose response is

{redeem_url: <string>}

Then, with a valid redeem code, you can use the redeem method to exchange it by a verifiable credential (VC) issued by tokenproof. Such VC is linked to the device by its DID. The client app is responsible of storing and managing the credential. Also, a redeem code can be used only once, so an error would be thrown should the client attempts to use it more than once, regardless of the device used to exchange it.

QR code generation

Finally, you can use the qrEncodeCredential method to encode the credential as a tokenproof-compatible QR code. Please note that the content of the QR code is timestamped and expires 60 seconds after its generation, so make sure the client app creates as new QR code if necessary. QR encoding works even if the device is offline, so the number of calls to qrEncodeCredential is unlimited. This method does not allow encoding credentials issued for other DIDs, so that an app reinstall requires to go through the onboarding flow again.

Sequence diagram

The diagram below summarizes the whole onboarding flow and the generation of the corresponding QR code:

Screenshot 2024-01-25 at 22.08.45.png

Getting started

API key

In order to invoke /partneronboarding/create, you will need an API key. If you want to integrate tokenproof Wallet into your app, do not hesitate in contacting us at at [email protected].

React Native

Installation

yarn add @tokenproof/react-native-client-sdk // this could change when v1 is released

SDK methods

/**
* Set up the device DID. 
* If previously initialized, it loads the DID and the key pair used to sign the QR codes
* @returns true if initialization went well, otherwise returns false.
*/
initializeDevice(): Promise<boolean>
/**
* Exchanges a tokenproof redeem code by a VC issued by tokenproof
* @returns the VC as JSON string
* @throws an error if the code is empty, invalid, or already redeemed.
*/
redeem(code: string): Promise<string>
/**
* Signs and encodes a credential as a QR code
* than can be read by tokenproof Verifier.
* @returns the animated QR code as data uri (data:image/gif;base64,...) 
*          that expires in 60 seconds
* Throws an error if the credential is empty, invalid, or issued for another DID
*/
qrEncodeCredential(credential: string)

Example app

Use the following example app as a demonstration the flow described above.

import * as React from 'react';
import {Button, Image, SafeAreaView, StyleSheet, Text, TextInput} from 'react-native';
import {initializeDevice, qrEncodeCredential, redeem} from '@tokenproof/react-native-client-sdk';

export default function App() {
  const [ready, setReady] = React.useState<boolean>(false);
  const [deviceStatus, setDeviceStatus] = React.useState<string>('not initd');
  const [url, setUrl] = React.useState<string>('');
  const [dataUri, setDataUri] = React.useState<string>('');

  React.useEffect(() => {
    initializeDevice().then(
      (r) =>
        Promise.all([setReady(r), setDeviceStatus(r ? 'ready' : 'failed')]),
      (err) => setDeviceStatus(`error: ${err}`)
    );
  });

  const handleRedeem = async () => {
    if (!ready) return;
    try {
      const vc = await redeem(url);
      const dataUri = await qrEncodeCredential(vc);
      setDataUri(dataUri);
    } catch (error) {
      console.error(error);
    }
  };

  return (
    <SafeAreaView style={styles.container}>
      <Text>Initialized?: {deviceStatus}</Text>
      <TextInput onChangeText={setUrl} style={styles.input} />
      <Button title="Redeem" onPress={handleRedeem} />
      {dataUri && <Image source={{ uri: dataUri }} style={styles.image} />}
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'white',
    flex: 1,
  },
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
    padding: 10,
  },
  image: {
    width: 400,
    height: 400,
  },
});

Untitled

Supported devices

Currently, the React Native module only runs on these platforms+architectures:

iOS:

arm64-ios-device

x86_64-ios-simulator

Android:

armv7a-linux-androideabi

aarch64-linux-android

i686-linux-android

x86_64-linux-android

If you need us to support another platform or architecture, please send our support team an email at [email protected] and we will get back with you as soon as possible.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library