Options
All
  • Public
  • Public/Protected
  • All
Menu

Module wallet-link

@helium/wallet-link

Utilities for linking a 3rd party app to the helium wallet. The link token is used for hotspot onboarding, location assertion, and ownership transfer transaction signing with the Helium Wallet and Hotspot apps.

Installation

React Native

$ yarn add @helium/wallet-link @helium/crypto-react-native
$ yarn add --dev patch-package postinstall-postinstall
# or
$ npm install @helium/wallet-link @helium/crypto-react-native
$ npm install --save-dev patch-package

When using this library in React Native you must patch the @helium/crypto calls with @helium/crypto-react-native. You can do this using patch-package by adding the following file to your React Native root at /patches/@helium+wallet-link+4.6.1.patch.

diff --git a/node_modules/@helium/wallet-link/build/walletLink.js b/node_modules/@helium/wallet-link/build/walletLink.js
index 5378554..de9d701 100644
--- a/node_modules/@helium/wallet-link/build/walletLink.js
+++ b/node_modules/@helium/wallet-link/build/walletLink.js
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.createUpdateHotspotUrl = exports.createSignHotspotCallbackUrl = exports.createLinkWalletCallbackUrl = exports.createWalletLinkUrl = exports.parseWalletLinkToken = exports.verifyWalletLinkToken = exports.makeAppLinkAuthToken = void 0;
/* eslint-disable object-curly-newline */
const address_1 = __importDefault(require("@helium/address"));
-const crypto_1 = require("@helium/crypto");
+const crypto_1 = require("@helium/crypto-react-native");
const query_string_1 = __importDefault(require("query-string"));
const date_fns_1 = require("date-fns");
const types_1 = require("./types");

In your package.json add the following script to run the patch on postinstall:

 "scripts": {
+ "postinstall": "patch-package"
}

Lastly run yarn or npm install and the patch will be installed.

Browser or other JS environments

$ yarn add @helium/wallet-link @helium/crypto
# or
$ npm install @helium/wallet-link @helium/crypto

Usage

// Create link to Helium app
const url = createWalletLinkUrl({
universalLink: 'https://wallet.helium.com/',
requestAppId: 'com.maker.app',
callbackUrl: 'makerappscheme://',
appName: 'Maker App',
})

Linking.openURL(url)

// parse received token
const parsed = parseWalletLinkToken(token)

// verify token
const verified = verifyWalletLinkToken(parsed)

// verify token with max age
const verified = verifyWalletLinkToken(parsed, { maxAgeInSeconds: 60 })

// Create link to update a hotspot
const updateParams = {
token,
platform: Platform.OS,
addGatewayTxn: 'your_optional_unsigned_txn',
assertLocationTxn: 'your_optional_unsigned_txn',
transferHotspotTxn: 'your_optional_unsigned_txn',
} as SignHotspotRequest

const url = createUpdateHotspotUrl(updateParams)
Linking.openURL(url)

// submit signed txn

Index

Type Aliases

DelegateApp: { androidPackage: string; appStoreId: number; iosBundleId: string; name: string; universalLink: string }

Type declaration

  • androidPackage: string
  • appStoreId: number
  • iosBundleId: string
  • name: string
  • universalLink: string
LinkWalletRequest: { appName: string; callbackUrl: string; requestAppId: string }

Type declaration

  • appName: string
  • callbackUrl: string
  • requestAppId: string
LinkWalletResponse: { status: "success" | "user_cancelled"; token?: string }

Type declaration

  • status: "success" | "user_cancelled"
  • Optional token?: string
MakerApp: { androidPackage: string; iosBundleId: string; name: string; universalLink: string }

Type declaration

  • androidPackage: string
  • iosBundleId: string
  • name: string
  • universalLink: string
SignHotspotRequest: { addGatewayTxn?: string; assertLocationTxn?: string; solanaTransactions?: string; token: string; transferHotspotTxn?: string }

Type declaration

  • Optional addGatewayTxn?: string
  • Optional assertLocationTxn?: string
  • Optional solanaTransactions?: string
  • token: string
  • Optional transferHotspotTxn?: string
SignHotspotResponse: { assertTxn?: string; gatewayAddress?: string; gatewayTxn?: string; solanaTransactions?: string; status: "success" | "token_not_found" | "user_cancelled" | "gateway_not_found" | "invalid_link"; transferTxn?: string }

Type declaration

  • Optional assertTxn?: string
  • Optional gatewayAddress?: string
  • Optional gatewayTxn?: string
  • Optional solanaTransactions?: string
  • status: "success" | "token_not_found" | "user_cancelled" | "gateway_not_found" | "invalid_link"
  • Optional transferTxn?: string
Token: LinkWalletRequest & { address: string; signingAppId: string; time: number }
TokenWithSig: Token & { signature: string }

Variables

HELIUM_HOTSPOT_APP: DelegateApp = ...
HELIUM_WALLET_APP: DelegateApp = ...

Functions

  • createLinkWalletCallbackUrl(protocol: string, address: string, responseParams: LinkWalletResponse): string
  • createWalletLinkUrl(opts: { appName: string; callbackUrl: string; path?: string; requestAppId: string }): string
  • Parameters

    • opts: { appName: string; callbackUrl: string; path?: string; requestAppId: string }
      • appName: string
      • callbackUrl: string
      • Optional path?: string
      • requestAppId: string

    Returns string

  • makeAppLinkAuthToken(tokenOpts: Token, keypair: SignableKeypair): Promise<string>
  • verifyWalletLinkToken(linkToken: TokenWithSig, opts?: { maxAgeInSeconds: number }): Promise<boolean>

Generated using TypeDoc