Skip to content

Commit

Permalink
Merge pull request #22 from getsafle/test
Browse files Browse the repository at this point in the history
Solana Keyring controller
  • Loading branch information
sshubhamagg authored Jul 25, 2024
2 parents 732a1f3 + b095fdb commit 12dc285
Show file tree
Hide file tree
Showing 18 changed files with 4,067 additions and 0 deletions.
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

0 comments on commit 12dc285

Please sign in to comment.