Giter Site home page Giter Site logo

creit-tech / stellar-wallets-kit Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 5.0 3.46 MB

A kit to handle all Stellar Wallets at once with a simple API

Home Page: https://stellarwalletskit.dev

License: MIT License

TypeScript 100.00%
albedo freighter soroban stellar wallets xbull

stellar-wallets-kit's Introduction

A kit to handle all Stellar Wallets at once with a simple API and without caring about individual configurations for each one of them. This library cares only about the connection and interaction with the wallets, allowing developers handling the UI/UX in the way they want.

Compatible Wallets:

  • xBull Wallet (Both PWA and extension version)
  • Albedo
  • Freighter
  • Rabet (extension version)
  • WalletConnect
  • Lobstr

Installation

npm i @creit.tech/stellar-wallets-kit

The StellarWalletsKit class

The first step will be creating a new instance from the main class, you should only create one instance in order to avoid unexpected results.

import {
  StellarWalletsKit,
  WalletNetwork,
  allowAllModules,
  XBULL_ID
} from '@creit.tech/stellar-wallets-kit';

const kit: StellarWalletsKit = new StellarWalletsKit({
  network: WalletNetwork.TESTNET,
  selectedWalletId: XBULL_ID,
  modules: allowAllModules(),
});

The allowAllModules() function doesn't import those modules where you need to provide a configuration (like WalletConnect), you will need to add them manually so check the folder src/modules to know all the available modules.

If you want to specify only the wallets you want to support, you can start the kit with only those by sending the modules to the constructor like this:

import {
  FreighterModule,
  StellarWalletsKit,
  WalletNetwork,
  XBULL_ID,
  xBullModule
} from '@creit.tech/stellar-wallets-kit';

const kit: StellarWalletsKit = new StellarWalletsKit({
  network: WalletNetwork.TESTNET,
  selectedWalletId: XBULL_ID,
  modules: [
    new xBullModule(),
    new FreighterModule(),
  ]
});

Integrated UI modal

The library integrates a UI modal you can show your users after you have started the kit. Once they pick the wallet they want to use you can then use the other methods available. Here is how you can use it:

await kit.openModal({
  onWalletSelected: async (option: ISupportedWallet) => {
    kit.setWallet(option.id);
    const publicKey = await kit.getPublicKey();
    // Do something else
  }
});

And as simple as that you will give full support to all the Stellar wallets plus you don't even need to handle the modal UI yourself.

The openModal method also lets you update multiple things about the model like the title, the allowed wallets or even the styles of it! Here are the accepted parameters:

function openModal(params: {
    onWalletSelected: (option: ISupportedWallet) => void;
    onClosed?: (err: Error) => void;
    modalDialogStyles?: { [name: string]: string | number | undefined | null; }
    modalTitle?: string;
    notAvailableText?: string;
}) {}

Request the public key and sign transactions

Each wallet has its own way when it comes to both requesting the public key and signing a transaction. Using this kit you can do both actions with a unified API:

const publicKey = await kit.getPublicKey();

// AND

const { result } = await kit.signTx({
  xdr: '....',
  publicKeys: [publicKey], // You could send multiple public keys in case the wallet needs to handle multi signatures
  network: WalletNetwork.PUBLIC
});

Both methods will trigger the action using the wallet you have set before calling those methods.

Extra methods

There will be moments where you would like to change certain parameters from the kit like the selected wallet, the network, etc... or maybe listening when a WalletConnect session was removed. These methods will help you in those situations:

Set the target wallet

await kit.setWallet(XBULL_ID)

Set the target network

await kit.setNetwork(WalletNetwork.TESTNET);

And more methods, check the documentation to see all the methods available.

License

Licensed under the MIT License, Copyright © 2023-present Creit Technologies LLP.

Checkout the LICENSE.md file for more details.

stellar-wallets-kit's People

Contributors

aristidesstaffieri avatar earrietadev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stellar-wallets-kit's Issues

Allow logic for adding "plugins"

Just like the "modules" logic, let's add the possibility for others to extend the functionality of this kit by integrating "plugins".

Let's make an example of what a plugin could be by adding a SEP10 plugin to the repo

npm i error

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Trying to run npm i @creit.tech/stellar-wallets-kit but getting an error.

npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name "node:buffer" of package "node:buffer@npm:buffer@^6.0.3": name can only contain URL-friendly characters.

npm ERR! A complete log of this run can be found in: /Users/tylervanderhoeven/.npm/_logs/2024-02-27T14_06_14_101Z-debug-0.log

Collecting page data ..Error [ERR_MODULE_NOT_FOUND]: Cannot find module

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Using nextjs and getting this error when running yarn run build.

Collecting page data  ..Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/tylervanderhoeven/Desktop/Web/Soroban/RPCiege/rpciege-next/node_modules/@creit.tech/stellar-wallets-kit/build/stellar-wallets-kit' imported from /Users/tylervanderhoeven/Desktop/Web/Soroban/RPCiege/rpciege-next/node_modules/@creit.tech/stellar-wallets-kit/build/index.js
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:327:11)
    at moduleResolve (node:internal/modules/esm/resolve:980:10)
    at defaultResolve (node:internal/modules/esm/resolve:1193:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39)
    at link (node:internal/modules/esm/module_job:75:36) {
  url: 'file:///Users/tylervanderhoeven/Desktop/Web/Soroban/RPCiege/rpciege-next/node_modules/@creit.tech/stellar-wallets-kit/build/stellar-wallets-kit',
  code: 'ERR_MODULE_NOT_FOUND'
}
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/tylervanderhoeven/Desktop/Web/Soroban/RPCiege/rpciege-next/node_modules/@creit.tech/stellar-wallets-kit/build/stellar-wallets-kit' imported from /Users/tylervanderhoeven/Desktop/Web/Soroban/RPCiege/rpciege-next/node_modules/@creit.tech/stellar-wallets-kit/build/index.js
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:327:11)
    at moduleResolve (node:internal/modules/esm/resolve:980:10)
    at defaultResolve (node:internal/modules/esm/resolve:1193:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39)
    at link (node:internal/modules/esm/module_job:75:36) {
  url: 'file:///Users/tylervanderhoeven/Desktop/Web/Soroban/RPCiege/rpciege-next/node_modules/@creit.tech/stellar-wallets-kit/build/stellar-wallets-kit',
  code: 'ERR_MODULE_NOT_FOUND'
}
  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

We recommend you using version tags when installing the library, this way you have control when doing an npm i

How do you do this? This is very unconventional to not use npm so I don't love that. But also it would be nice to include an example of how to use a version tag when installing the library. If I run npm i github:Creit-Tech/[email protected] I get:

 ERROR  Command failed with exit code 128: git ls-remote git+ssh://[email protected]/null/0.1.4.git HEAD
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/tylervanderhoeven/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/tylervanderhoeven/.ssh/known_hosts:2
Host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

NextJS / Webpack compilation error

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

There is a compilation error when using this package with a NextJS 12 version project.

Versions:

    "@creit.tech/stellar-wallets-kit": "^0.5.0",
    "next": "^12.3.4",
    "react": "^18.2.0",
    "stellar-sdk": "^11.2.0",

Error:

> next build

info  - Linting and checking validity of types  
info  - Creating an optimized production build  
Failed to compile.

static/chunks/pages/_app-322ca9d28969cb07.js from Terser
Unexpected token: punc ({) [static/chunks/pages/_app-322ca9d28969cb07.js:17163,11]
    at js_error (/Users/mootz12/dev/blend/blend-ui/node_modules/next/dist/compiled/terser/bundle.min.js:1:32780)
  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

This can be fixed by upgrading to NextJS 14, so it is possible this issue is out of scope for your library.

If so, feel free to comment as such and close.

Make walletconnect optional

The wallet connect dependencies are quite large and I never use them. It would be nice to make walletconnect an optional dependency to help lighten the load of this package.

Rabet wallet signing transaction invalid XDR

  • I'm submitting a ...
    [x] bug report

  • Rabet wallet signing transaction doesn't work

  • All other wallets work good, only Rabet returns the error 'Invalid XDR'
    Code example:
    import { TransactionBuilder } from 'stellar-sdk';

let transaction = new TransactionBuilder(account, { fee, networkPassphrase: Networks.TESTNET, }) .addOperation(contract.call(func_name, ...args)) .setTimeout(30) .build();

const { result } = await stellarWalletsKit.signTx({ xdr: transaction.toXDR(), publicKeys: [user_address], network: Networks.TESTNET, });

image

All other wallets works fine.

Or may be I'm doing it wrong?

Make the list of the wallets dynamic

Currently the list of the wallets is hardcoded and it only allows to select what wallets you want to include or not. Let's make it so its order can be defined by the web developer but it also prioritizes those wallets that are loaded on the browser

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.