-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from getsafle/test
Solana Keyring controller
- Loading branch information
Showing
18 changed files
with
4,067 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages | ||
|
||
name: Main Branch | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- package.json | ||
- CHANGELOG | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 18.x | ||
- run: npm ci | ||
- run: npm run test | ||
|
||
publish-npm: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 18.x | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm ci | ||
- run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages | ||
|
||
name: Feature/Bugfix/dev/test branch | ||
|
||
on: | ||
push: | ||
branches: | ||
- feature-* | ||
- bugfix-* | ||
- dev | ||
- test | ||
pull_request: | ||
branches: | ||
- feature-* | ||
- bugfix-* | ||
- dev | ||
- test | ||
paths: | ||
- package.json | ||
- CHANGELOG | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Code checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setting up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18.x' | ||
|
||
- name: Installing dependencies | ||
run: npm ci | ||
|
||
- name: Run tests | ||
run: | | ||
npm run test:coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
test.js | ||
.vscode/launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
### 1.0.0 (2024-7-22) | ||
|
||
##### Solana Keyring Implementation | ||
|
||
- Implemented Keyring functionality to enable account generation and export keys | ||
- Added getAccounts() method to fetch list of generated accounts | ||
- Added importWallet() to import account using privateKey | ||
- Added initial test | ||
- Added functionality to sign message | ||
- Added get balance method to fetch SOL balance of an account | ||
- Added functionality to sign SOL and fungible tokens transfer transaction | ||
- Added functionality to broadcast a signed transaction | ||
- Added functionality to get estimated fee for a transaction | ||
- Added functionality to accept priority fee for a transaction | ||
- Added test cases | ||
- Added readme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# vault-SOL-controller<code><a href="https://www.docker.com/" target="_blank"><img height="50" src="https://assets.coingecko.com/coins/images/4128/standard/solana.png?1718769756"></a></code> | ||
|
||
[![npm version](https://badge.fury.io/js/@getsafle%2Fvault-sol-controller.svg)](https://badge.fury.io/js/@getsafle%2Fvault-sol-controller) <img alt="Static Badge" src="https://img.shields.io/badge/License-MIT-green"> [![Discussions][discussions-badge]][discussions-link] | ||
<img alt="Static Badge" src="https://img.shields.io/badge/sol_controller-documentation-purple"> | ||
|
||
|
||
|
||
## Install | ||
|
||
`npm install --save @getsafle/vault-sol-controller` | ||
|
||
## Initialize the solana Controller class | ||
|
||
``` | ||
const { KeyringController, getBalance } = require('@getsafle/vault-sol-controller'); | ||
const solController = new KeyringController({ | ||
// 12 words mnemonic to create wallet | ||
mnemonic: string, | ||
// network - type of network [TESTNET|MAINNET] | ||
// default is MAINNET even if no network is passed | ||
network: string (TESTNET | MAINNET) | ||
}); | ||
``` | ||
|
||
## Methods | ||
|
||
### add new account | ||
|
||
``` | ||
const keyringState = await solController.addAccount(); | ||
``` | ||
|
||
### Export the private key of an address present in the keyring | ||
|
||
``` | ||
const privateKey = await solController.exportPrivateKey(address); | ||
``` | ||
|
||
### Get all accounts in the keyring | ||
|
||
``` | ||
const privateKey = await solController.getAccounts(); | ||
``` | ||
|
||
### Sign a transaction | ||
|
||
``` | ||
const signedTx = await solController.signTransaction(solTx); | ||
STX transfer transaction: | ||
solTx: {from, to, amount, txnType} | ||
Token transfer transaction: | ||
solTx: {from, to, amount, txnType, token} | ||
transactionType = 'NATIVE_TRANSFER' || 'TOKEN_TRANSFER' | ||
``` | ||
|
||
### Sign a message | ||
|
||
``` | ||
const signedMsg = await solController.signMessage(msgString, address); | ||
``` | ||
|
||
### Get fees | ||
|
||
``` | ||
const fees = await solController.getFees(rawTransaction); | ||
``` | ||
|
||
### Get balance | ||
|
||
``` | ||
const balance = await getBalance(address, network); // if network !== TESTNET then it will fetch mainnet balance | ||
``` | ||
|
||
[discussions-badge]: https://img.shields.io/badge/Code_Quality-passing-rgba | ||
[discussions-link]: https://github.com/getsafle/vault-sol-controller/actions |
Oops, something went wrong.