Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ It is recommended to add this repository main branch to your project as a submod

After adding, you need to run 'npm install' in the root directory of this module in order to install all prerequisites.

## Note
if you get any error about node-gyp or sodium-native. try deleting this two files

C:\Users\{YourUserName}\AppData\Local\node-gyp

C:\Users\{YourUserName}\.node-gyp

## Supported Coins
- Bitcoin based coins Like Bitcoin, Litecoin, Bitcoincash, Doge, Bitcoin Gold
- Ethereum
Expand Down
34 changes: 34 additions & 0 deletions data/ProkeyCoinsInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -35789,5 +35789,39 @@
"https://wallet.prokey.io"
]
}
],
"stellar": [
{
"name": "Stellar",
"shortcut": "XLM",
"slip44": 148,
"decimals": 0,
"priority": 9,
"on_device": "Stellar",
"test": false,
"support": {
"optimum": "1.8.0"
},
"tx_url": "https://stellarchain.io/tx/{hash}",
"wallets": [
"https://wallet.prokey.io"
]
},
{
"name": "Stellar Testnet",
"shortcut": "tXLM",
"slip44": 1,
"decimals": 0,
"priority": 100,
"on_device": "Stellar Testnet",
"test": true,
"support": {
"optimum": "1.8.0"
},
"tx_url": "http://testnet.stellarchain.io/transactions/{hash}",
"wallets": [
"https://wallet.prokey.io"
]
}
]
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"rxjs": "~6.2.0",
"typescript-http-client": "^0.10.1",
"websocket": "^1.0.34",
"crypto-js": "3.1.9-1"
"crypto-js": "3.1.9-1",
"websocket": "^1.0.34",
"sodium-native": "^3.2.1",
"stellar-base": "^6.0.1"
},
"scripts": {
"build": "tsc",
Expand Down
38 changes: 19 additions & 19 deletions src/blockchain/servers/prokey/src/ProkeyBaseBlockChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,51 @@ import { Request,
import {RequestAddressInfo} from "../../../../models/GenericWalletModel";

export abstract class ProkeyBaseBlockChain {
_url = 'https://blocks.prokey.org/';
_baseUrl = 'https://blocks.prokey.org/';

constructor(url?: string) {
if (url) {
this._url = url;
}
}

// These functions must be implemented in child classes
// These functions must be implemented in child classes
public abstract GetAddressInfo(reqAddresses: Array<RequestAddressInfo> | RequestAddressInfo);
public abstract GetTransactions(hash: string);
public abstract GetLatestTransactions(trs: Array<any>, count : number, offset: number);
public abstract BroadCastTransaction(data: any);

constructor(baseUrl: string = 'https://blocks.prokey.org/') {
this._baseUrl = baseUrl;
}
/**
* This is a private helper function to GET data from server
* @param toServer URL + data
* @param changeJson a callback for adjust json before casting
*/
protected async GetFromServer<T>(toServer: string, changeJson?: (json: string) => string) {

const client = newHttpClient();

const request = new Request(this._url + toServer, { method: 'GET' });
const request = new Request(this._baseUrl + toServer, {method: 'GET'});

let json = await client.execute<string>(request);

if (changeJson) {
json = changeJson(json);
}

return JSON.parse(json) as T;
}
return this.handleJsonResponse<T>(changeJson, json);
}

/**
* This is a private helper function to POST data to server
* @param toServer URL
* @param body Request Body
* @returns Response data from server
*/
protected async PostToServer<T>(toServer: string, body: any): Promise<T> {
protected async PostToServer<T>(toServer: string, body: any, changeJson?: (json: string) => string): Promise<T> {
const client = newHttpClient();

const request = new Request(this._url + toServer, {body: body, method: 'POST'});
const request = new Request(this._baseUrl + toServer, {body: body, method: 'POST'});

let json = await client.execute<string>(request);
return this.handleJsonResponse<T>(changeJson, json);
}

return JSON.parse(await client.execute<string>(request));
private handleJsonResponse<T>(changeJson: ((json: string) => string) | undefined, json: string) {
if (changeJson) {
json = changeJson(json);
}
return JSON.parse(json) as T;
}
}
87 changes: 87 additions & 0 deletions src/blockchain/servers/prokey/src/stellar/Stellar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {ProkeyBaseBlockChain} from "../ProkeyBaseBlockChain";
import {RequestAddressInfo} from "../../../../../models/GenericWalletModel";
import {
StellarAccountInfo,
StellarFee,
StellarTransactionOperationResponse,
StellarTransactionResponse
} from "./StellarModels";
import {MyConsole} from "../../../../../utils/console";

export class StellarBlockchain extends ProkeyBaseBlockChain {
_coinName: string;

constructor(coinName: string = "Xlm")
{
super();
this._coinName = coinName;
MyConsole.Info(this._coinName);
}

/**
* broadcast transaction over network
* @param data stellar signed transaction (base64 format)
* @returns object response of transaction
*/
public async BroadCastTransaction(data: string): Promise<any> {
return await this.PostToServer<any>(`Transaction/advanced-send/${this._coinName}/`, {"SignedTransactionBlob": data});
}

/**
* get account information from network
* @param reqAddress address
* @returns StellarAccountInfo account info
*/
public async GetAddressInfo(reqAddress: RequestAddressInfo) : Promise<StellarAccountInfo | null> {
try {
return await this.GetFromServer<StellarAccountInfo>(`address/${this._coinName}/${reqAddress.address}`);
} catch (error) {
return null;
}
}

/**
* get account transaction list from network
* @param accountAddress address of account
* @param limit number of transactions
* @param cursor used for pagination when you want next page
* @returns StellarAccountInfo list of transactions
*/
public async GetAccountTransactions(accountAddress: string, limit: number = 10, cursor?: string): Promise<StellarTransactionResponse | null> {
let serverResponse = await this.GetFromServer<any>(`address/transactions/${this._coinName}/${accountAddress}/${limit}`);
if (serverResponse != null && serverResponse.transactions != null)
{
return serverResponse;
}
return null;
}

/**
* get operations of a specific transaction
* @param transactionId transaction id
* @returns StellarTransactionOperationResponse list of operations
*/
public async GetTransactionOperations(transactionId: string): Promise<StellarTransactionOperationResponse | null> {
let queryUrl = `transaction/${this._coinName}/${transactionId}`;
let serverResponse = await this.GetFromServer<any>(queryUrl);
if (serverResponse != null && serverResponse.operations != null)
{
return serverResponse;
}
return null;
}

/**
* get network fee detail
* @returns StellarFee
*/
public async GetCurrentFee(): Promise<StellarFee> {
return await this.GetFromServer<StellarFee>(`transaction/fee/${this._coinName}`);
}

GetLatestTransactions(trs: Array<number>, count: number, offset: number) {
}

GetTransactions(hash: string) {
}
}
164 changes: 164 additions & 0 deletions src/blockchain/servers/prokey/src/stellar/StellarModels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* This is part of PROKEY HARDWARE WALLET project
* Copyright (C) Prokey.io
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export interface StellarFee {
last_ledger: string,
last_ledger_base_fee: string,
ledger_capacity_usage: string,
min_accepted_fee: string,
mode_accepted_fee: string,
p10_accepted_fee: string,
p20_accepted_fee: string,
p30_accepted_fee: string,
p40_accepted_fee: string,
p50_accepted_fee: string,
p60_accepted_fee: string,
p70_accepted_fee: string,
p80_accepted_fee: string,
p90_accepted_fee: string,
p95_accepted_fee: string,
p99_accepted_fee: string,
fee_charged: FeeState,
max_fee: FeeState
}

export interface StellarAccountInfo {
account_id: string,
sequence: number,
subentry_count: number,
inflation_destination: string,
home_domain: string,
thresholds: Thresholds,
flags: Flags,
balances: Balance[],
signers: Signer[],
num_sponsoring: number,
num_sponsored: number,
Data: object
}

export interface StellarTransactionResponse {
transactions: StellarTransaction[],
nextPageCursor: string,
prevPageCursor: string
}

export interface StellarTransaction {
hash: string,
ledger: number,
created_at: string,
source_account: string,
fee_account: string,
successful: boolean,
paging_token: string,
source_account_sequence: number,
fee_charged: number,
max_fee: number,
operation_count: number,
envelope_xdr: string,
result_xdr: string,
result_meta_xdr: string,
signatures: string[],
fee_bump_transaction: FeeBumpTransaction,
inner_transaction: InnerTransaction,
memo_type: string,
memo: string,
memo_bytes: string
}

export interface StellarTransactionOperationResponse {
operations: StellarTransactionOperation[],
nextPageCursor: string,
prevPageCursor: string
}

export interface StellarTransactionOperation {
id: number,
source_account: string,
paging_token: string,
type: string,
type_i: number,
created_at: string,
transaction_hash: string,
transaction_successful: boolean
asset_type: string,
from: string,
to: string,
amount: string,
name: string,
value: string,
funder: string,
account: string,
starting_balance: string
}

interface FeeState {
max: string;
min: string;
mode: string;
p10: string;
p20: string;
p30: string;
p40: string;
p50: string;
p60: string;
p70: string;
p80: string;
p90: string;
p95: string;
p99: string;
}

export interface FeeBumpTransaction {
hash: string,
signatures: string[]
}

export interface InnerTransaction {
hash: string,
signatures: string,
max_fee: number
}

export interface Thresholds {
low_threshold: number,
med_threshold: number,
high_threshold: number
}

export interface Flags {
auth_required: boolean,
auth_revocable: boolean,
auth_immutable: boolean
}

export interface Balance {
asset_type: string,
asset_code: string,
asset_issuer: string,
limit: string,
balance: string,
buying_liabilities: string,
selling_liabilities: string,
is_authorized: boolean,
is_authorized_to_maintain_liabilities: boolean
}

export interface Signer {
key: string,
type: string,
weight: number
}
Loading