Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solana Keyring controller #22

Merged
merged 25 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c478871
initial devops commit
SDargarh Jul 22, 2024
bef5bb0
Initial Solana Keyring Implementation
SDargarh Jul 22, 2024
c511e05
Added functionality to sign message
SDargarh Jul 22, 2024
70ce226
devops changes and NPM addition
SubhanshuMG Jul 22, 2024
ee860fe
devops changes
SubhanshuMG Jul 22, 2024
f8720e4
removed other branches
SubhanshuMG Jul 22, 2024
aecebed
branch revert
SubhanshuMG Jul 22, 2024
724badd
Added get balance method to fetch SOL balance of an account
SDargarh Jul 22, 2024
f6b8ad0
Merge pull request #10 from getsafle/feature-devops-setup
sshubhamagg Jul 22, 2024
bea20ed
Added functionality to sign transactions
SDargarh Jul 23, 2024
d9a0408
Added functionality to broadcast a signed transaction
SDargarh Jul 23, 2024
3556e39
Added functionality to get estimated fee for a transaction
SDargarh Jul 23, 2024
2e31237
Added functionality to accept priority fee for a transaction
SDargarh Jul 23, 2024
f15c96f
Added test cases
SDargarh Jul 24, 2024
4eedafd
Added readme
SDargarh Jul 25, 2024
2fada7e
Merge pull request #11 from getsafle/feature-sol-account-management
sshubhamagg Jul 25, 2024
f4ee843
Merge pull request #12 from getsafle/feature-sign-message
sshubhamagg Jul 25, 2024
0b01905
Merge pull request #13 from getsafle/feature-get-sol-balance
sshubhamagg Jul 25, 2024
f962b0a
Merge pull request #14 from getsafle/feature-sign-txns
sshubhamagg Jul 25, 2024
265d085
Merge pull request #15 from getsafle/feature-broadcast-transaction
sshubhamagg Jul 25, 2024
f4d31b2
Merge pull request #16 from getsafle/feature-get-fees
sshubhamagg Jul 25, 2024
79636dd
Merge pull request #18 from getsafle/feature-priority-fee
sshubhamagg Jul 25, 2024
6590667
Merge pull request #19 from getsafle/feature-test-suite
sshubhamagg Jul 25, 2024
c0b79b9
Merge pull request #20 from getsafle/feature-add-readme
sshubhamagg Jul 25, 2024
b095fdb
Merge pull request #21 from getsafle/dev
sshubhamagg Jul 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/main.yaml
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}}
40 changes: 40 additions & 0 deletions .github/workflows/other-branches.yml
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
test.js
.vscode/launch.json
16 changes: 16 additions & 0 deletions CHANGELOG.md
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
79 changes: 79 additions & 0 deletions README.MD
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
Loading
Loading