3.10.2 • Published 6 days ago

@provenanceio/walletconnect-js v3.10.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 days ago

WalletConnect-JS

Bridging the gap between dApps and Figure wallets using WalletConnect.

Table of Contents

  1. Installation
  2. WalletConnectContextProvider
  3. useWalletConnect
  4. walletConnectState
  5. walletConnectService
  6. QRCodeModal
  7. Window messages
  8. Examples
  9. Status

Installation

npm install @provenanceio/walletconnect-js --save

Exported items:

import {
  // Constants
  WALLET_LIST,
  WINDOW_MESSAGES,
  CONNECTOR_EVENTS,
  CONNECTION_TYPES,
  // Services/Providers
  useWalletConnect,
  useWalletConnectService,
  WalletConnectContextProvider,
  WalletConnectService,
  // Components
  QRCodeModal
  // Types
  ProvenanceMethod,
  WalletConnectServiceStatus,
  ConnectMethod,
  // -- Broadcast events for methods
  BroadcastEventData,
  SignHexMessageMethodResult,
  SignHexMessageMethodEventData,
  SignJWTMethodResult,
  SignJWTMethodEventData,
  SendMessageMethodResult,
  SendMessageMethodEventData,
  DisconnectMethodResult,
  DisconnectMethodEventData,
  ConnectMethodResult,
  ConnectMethodEventData,
  SwitchToGroupMethodEventData,
  // -- Wallet info
  WalletId,
  WalletType,
} from "@provenanceio/walletconnect-js";

WalletConnectContextProvider

React context provider which provides all children components with state and hooks Optional Params:

  • service: (class) Manual instance of walletConnectService to use/reference
  • logsEnabled: (boolean) Enable/disable console log of various events (default false)
  • connectionRedirect: (string) Auto-redirect to url when status is disconnected
  • React.js example:
    // index.js
    ...
    ReactDOM.render(
      <WalletConnectContextProvider>
        <App />
      </WalletConnectContextProvider>,
      document.getElementById('root')
    );

useWalletConnect

React hook which containing walletConnectService and walletConnectState

walletConnectState

Holds current walletconnect-js state values

initialState: {
  address: '', // Wallet address [string]
  attributes: [{ name: string, value: number, type: string}], // Figure Account Attributes
  bridge: 'wss://figure.tech/service-wallet-connect-bridge/ws/external', // WalletConnect bridge used for connection [string]
  status: 'disconnected', // connection status connected ['connected', 'pending', 'disconnected]
  connectionEST: null, // WalletConnect expires at time [number]
  connectionEXP: null, // WalletConnect initialized at time [number]
  connectionTimeout: 1800, // Default timeout duration (seconds)
  modal: { // QRCodeModal values
    showModal: false, // Should the QR modal be open [bool]
    QRCodeUrl: '', // QRCode url contained within image [string]
    QRCodeImg: '', // QRCode image data to connect to WalletConnect bridge [string]
    isMobile: false, // Is the connected browser a mobile device [bool]
    dynamicUrl: '' // Dynamic link to open the Figure mobile wallet [string]
  },
  peer: {}, // Connected wallet info [object]
  pendingMethod: '', // Are any methods currently pending [string]
  publicKey: '', // Wallet public key (base64url encoded)
  signedJWT: '', // Signed JWT token [string]
  walletAppId: '', // Type of wallet [string]
  walletInfo: { // Information about the currently connected wallet account
    coin: '', // [string]
    id: '', // [string]
    name: '', // [string]
  },
  representedGroupPolicy: null, //Present when the wallet holder is acting on behalf of a group
}

walletConnectService

Used to call walletconnect-js methods

  • connect / init

    Note: connect is being deprecated and will be replaced with init

    Start the connection process to join a Figure wallet with the dApp.

    walletConnectService.connect(options);
    // WINDOW_MESSAGE: CONNECTED
    ParamTypeRequiredDefaultExampleInfo
    bridgestringno"wss://figure.tech/service-wallet-connect-bridge/ws/external""wss://custom.bridge"Custom bridge to connect into
    durationnumberno18003600Custom connection timeout in seconds
    individualAddressstringno''tp1knsxfnn0lq48mmnkfnkgtkk8qnxxdu0y2tklkhRequired individual address for dApp connection
    groupAddressstringno''tp1knsxfnn0lq48mmnkfnkgtkk8qnxxdu0y2tklkhRequired group address for dApp connection
    prohibitGroupsbooleannofalsetrueProhibit group accounts from connecting to this dApp
    qrOptionsshapenonull-Customize the QR code (padding, background, foreground, logo, note: must use hex colors)
    jwtExpirationnumberno''3600Time from now in seconds to expire new JWT returned
    walletAppIdstringno'''figure_extension'Open a specific wallet directly (bypassing the QRCode modal)
  • disconnect

    Disconnect current session

    walletConnectService.disconnect();
    // WINDOW_MESSAGE: DISCONNECT
  • resetConnectionTimeout

    Change the amount of connection time remaining for the currenct walletconnect session Note: This feature is currently only available in extension wallets

    walletConnectService.resetConnectionTimeout(connectionTimeout);
    ParamTypeRequiredDefaultExampleInfo
    connectionTimeoutnumberno18003600Seconds to extend current session
  • signJWT

    Prompt user to sign a generated JWT (async)

    walletConnectService.signJWT(expire, options);
    // WINDOW_MESSAGES: SIGN_JWT_COMPLETE, SIGN_JWT_FAILED
    ParamTypeRequiredDefaultExampleInfo
    expirenumberno24 hours (Date.now() + 86400)1647020269Custom expiration date (ms) of JWT
    optionsobjectno-{ customId: 'abc' }Additional Options (customId)
  • sendMessage

    Submit custom base64 encoded message (async)

    walletConnectService.sendMessage(options);
    // WINDOW_MESSAGES: SEND_MESSAGE_COMPLETE, SEND_MESSAGE_FAILED
    ParamTypeRequiredDefaultExampleInfo
    messagestring / arrayyes-'CiwvcHJvdmVuYW5jZS5tZX...'B64 encoded Message(s) to pass to wallet
    descriptionstringno'Send Message''My Special Message'Prompt title on mobile wallet
    methodstringno'provenance_sendTransaction''provenance_sendTransaction'Message method
    gasPriceobjectno{ gasPrice: [Figure Default], gasPriceDenom: [Figure Default] }{ gasPrice: 1337, gasPriceDenom: 'nhash' }Optional gasPrice object, defaults to Figure values
    feeGranterstringno-'tp1knsxfnn0lq48mmnkfnkgtkk8qnxxdu0y2tklkh'Specify a fee granter address
    feePayerstringno-'tp1knsxfnn0lq48mmnkfnkgtkk8qnxxdu0y2tklkh'Specify a fee payer address
    memostringno-'My special memo'Specify a tx memo
    timeoutHeightnumberno-3Specify a tx timeoutHeight
    extensionOptionsany[]no-['CiwvcHJvdmVuYW5jZS5tZX...']Specify tx extensionOptions
    nonCriticalExtensionOptionsany[]no-['CiwvcHJvdmVuYW5jZS5tZX...']Specify tx nonCriticalExtensionOptions
    customIdstringno-sendMsg_tx_01Custom id to track this transaction message
  • signHexMessage

    Sign a custom hex string message (async)

    walletConnectService.signHexMessage(message, options);
    // WINDOW_MESSAGES: SIGN_HEX_MESSAGE_COMPLETE, SIGN_HEX_MESSAGE_FAILED
    ParamTypeRequiredDefaultExampleInfo
    messagestringyes-'My Custom Message'Hex string message to send
    optionsobjectno-{ customId: 'abc' }Additional Options (customId)
  • removePendingMethod

    Remove a pending method from the wallet

    walletConnectService.removePendingMethod(customId);
    // WINDOW_MESSAGES: REMOVE_PENDING_METHOD_COMPLETE, REMOVE_PENDING_METHOD_FAILED
    ParamTypeRequiredDefaultExampleInfo
    customIdstringyes-my-id-01Remove a pending request from the wallet based on its customId

QRCodeModal

Optional React.js component which creates a popup connection interface.

  • Params:

    • walletConnectService: Service pulled out of useWalletConnect() hook (Required)
    • devWallets: Array of allowed dev wallets to connect into. (Optional)
    • hideWallets: Array of prod wallets to hide from user. (Optional)
    • className: CSS class to customize the styling (Optional)
    • title: Title displayed on top of the modal (Optional)
  • Usage: (See example apps for in-code usage)

  • Note:

    • src/consts/walletList.ts contains a list of available walletsAppIDs
    • This modal is built with React.js and will only work within a React project. If you are not using React.js look through the examples folder to see how to initiate the connection without this QRCodeModal.

Window Messages

Each method will return a window message indicating whether it failed or was completed as well as the result.

Note A: You can use await for most walletConnectService methods instead. Note B: All of these are based off Node.js Event Emitters, read more on them here: Node.js Event Emitters

Window Messages:

WalletConnect Connected

CONNECTED

WalletConnect Disconnect

DISCONNECT

WalletConnect Session Update

SESSION_UPDATED

Send Message

SEND_MESSAGE_COMPLETE SEND_MESSAGE_FAILED

Switch to Group Wallet Action

SWITCH_TO_GROUP_COMPLETE SWITCH_TO_GROUP_FAILED

JWT

SIGN_JWT_COMPLETE SIGN_JWT_FAILED

Sign

SIGN_HEX_MESSAGE_COMPLETE SIGN_HEX_MESSAGE_FAILED

Remove Pending Method

REMOVE_PENDING_METHOD_COMPLETE REMOVE_PENDING_METHOD_FAILED

(See example apps for more detailed usage)

Examples, Setup Configurations, and Alternate imports

This package comes bundled with a full demos that you can run locally to test out the various features of walletconnect-js. To see how to initiate and run the different examples, look through the README.md

  • Non React Setup
    • See examples folder for demo apps
  • Using a CDN Import
    • You can find this package on https://unpkg.com/: - Note: Change the version in the url as needed: https://unpkg.com/@provenanceio/walletconnect-js@2.0.0/umd/walletconnect-js.min.js

Status

Latest Release Apache 2.0 License LOC

Current development is being supported by Figure Technologies.

Back to top

3.10.2

6 days ago

3.10.1

7 days ago

3.10.0

9 days ago

3.9.1

14 days ago

3.9.0

22 days ago

3.8.2

3 months ago

3.8.1

3 months ago

3.8.0

3 months ago

3.7.2

3 months ago

3.7.2-develop.1

3 months ago

3.7.1

3 months ago

3.7.0

3 months ago

3.2.1

10 months ago

3.2.0

10 months ago

3.1.0

10 months ago

3.6.0

8 months ago

3.5.0

9 months ago

3.4.0

10 months ago

3.4.1

9 months ago

3.3.0

10 months ago

3.0.9

10 months ago

2.1.9-develop.2

1 year ago

2.1.9-develop.1

1 year ago

3.0.1-develop.1

1 year ago

3.0.1-develop.2

1 year ago

2.1.1-develop.1

1 year ago

2.1.1-develop.2

1 year ago

3.0.8-develop.2

11 months ago

3.0.8-develop.1

11 months ago

3.0.8-develop.4

11 months ago

3.0.8-develop.3

11 months ago

3.0.8-develop.6

11 months ago

3.0.8-develop.5

11 months ago

3.0.8-develop.8

11 months ago

3.0.8-develop.7

11 months ago

3.0.4

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.8

10 months ago

3.0.7

12 months ago

3.0.6

12 months ago

3.0.5

12 months ago

3.0.0

1 year ago

3.0.2-develop.2

1 year ago

3.0.2-develop.1

1 year ago

3.0.0-develop.9

1 year ago

3.0.0-develop.8

1 year ago

3.0.0-develop.7

1 year ago

3.0.0-develop.6

1 year ago

3.0.0-develop.5

1 year ago

3.0.0-develop.4

1 year ago

3.0.0-develop.3

1 year ago

3.0.0-develop.2

1 year ago

3.0.0-develop.1

1 year ago

2.2.0-develop.3

1 year ago

2.2.0-develop.2

1 year ago

2.2.0-develop.1

1 year ago

2.1.2

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

2.1.1

1 year ago

2.1.0

1 year ago

1.2.10

2 years ago

1.2.11

2 years ago

1.2.0

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.9

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.1.52

2 years ago

0.1.53

2 years ago

0.1.54

2 years ago

0.1.55

2 years ago

0.1.56

2 years ago

0.1.57

2 years ago

0.1.58

2 years ago

0.1.33-beta

2 years ago

0.1.50

2 years ago

0.1.51

2 years ago

0.1.33-beta.1

2 years ago

0.1.49

2 years ago

0.1.41

2 years ago

0.1.42

2 years ago

0.1.43

2 years ago

0.1.44

2 years ago

0.1.45

2 years ago

0.1.46

2 years ago

0.1.47

2 years ago

0.1.48

2 years ago

0.1.40

2 years ago

0.1.38

2 years ago

0.1.39

2 years ago

0.1.30

2 years ago

0.1.31

2 years ago

0.1.32

2 years ago

0.1.34

2 years ago

0.1.35

2 years ago

0.1.36

2 years ago

0.1.37

2 years ago

0.1.29

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.6

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.28

2 years ago

0.1.27

2 years ago

0.1.26

2 years ago

0.1.25

2 years ago

0.1.24

2 years ago

0.1.23

2 years ago

0.1.22

2 years ago

0.1.21

2 years ago

0.1.20

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.17

2 years ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago