0.1.8 • Published 4 months ago

@verified-network/verified-custody v0.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Verified Custody

This react module allows users to create a vault using Mobile/ E-mail as their vault id and gives you a private Key which the users can use to sign all transactions further.

Build:

  • All the components of the module is compiled and available under the dist/ directory.

Install:

npm install @verified-network/verified-custody

The react module exports some constants and helper functions which will be useful when changing UI based on a user's state or any business logic

IS_CUSTODY_SET - (bool) - Returns true when the user's pk is stored in the device and is validated by the users pin.

useCustody() - (hook) - contains vaultInfo and IS_CUSTODY_SET.

initializeMessaging() - (void) - Should be called to initialise the fcm which will get the device token. Should be called at the earliest.

getPermissionStatus - (bool - Returns the status whether the user has allowed Push notification permissions.

getFcmToken - ( string) - Returns the FCM token of the device.

**< StartCustody />** component is the entry component, which starts from asking the user to enter their phone/email and follows.

This < StartCustody /> component, can be used for multiple use case like to Sign Transactions and Retrieve Private Key by passing props.

  • Create a new vault
  • To Accept and Decline Cosigner Request
  • To Sign Transactions

creator, txId, transactionType, user(id), etc., will be obtained from the notification params and as the query params.

Usage:

Creating a vault:

return (
    <>
      { IS_CUSTODY_SET ? (
        <div>Welcome to dashboard</div>
      ) : permissionStatus === "granted" ? (
        <>
          { fcmToken ? (
            <StartCustody creatorInfo={{ fcmToken }} />
          ) : (
            <div>Retrieving fcm token...</div>
          ) }
        </>
      ) :  permissionStatus === 'denied' ? (
          <p>
            Notifications are blocked. Please enable them from your browser
            settings.
          </p>
      ) : (
        <div>Requesting notification permissions...</div>
      )}
    </>
  )

Handling cosigner requests:

    <StartCustody
        startPoint={{
            component: "StartCosigner",  // currently supports all forms of signing
            args: { creator, txId, transactionType, id },
        }}
    />

transactionType determines the type of signing request.

Recovering a private key:

This < GetPrivateKey /> component, will let you to retreive the private key once all your cosigners signoff your recovery code request.

return (
<GetPrivateKey
  setupProps={{
    chainId: 84532,
  }}
  signingInfo={{ creator, txId, transactionType, user }}
 />
)