Skip to content

Commit

Permalink
Merge pull request #201 from RunOnFlux/development
Browse files Browse the repository at this point in the history
v1.5.0
  • Loading branch information
TheTrunk authored Jun 14, 2024
2 parents 2baf38e + e28a023 commit 0283ed3
Show file tree
Hide file tree
Showing 14 changed files with 688 additions and 433 deletions.
52 changes: 27 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ssp-wallet",
"description": "Secure. Simple. Powerful.",
"private": true,
"version": "1.4.0",
"version": "1.5.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -14,53 +14,55 @@
"dependencies": {
"@metamask/browser-passworder": "~5.0.0",
"@noble/hashes": "~1.4.0",
"@reduxjs/toolkit": "~2.2.3",
"@reduxjs/toolkit": "~2.2.5",
"@runonflux/flux-sdk": "~1.0.2",
"@runonflux/utxo-lib": "~1.0.0",
"@scure/bip32": "~1.4.0",
"@scure/bip39": "~1.3.0",
"antd": "~5.16.1",
"antd": "~5.18.0",
"assert": "~2.1.0",
"axios": "~1.6.8",
"axios": "~1.7.2",
"bchaddrjs": "~0.5.2",
"bignumber.js": "~9.1.2",
"buffer": "~6.0.3",
"currency-symbol-map": "~5.1.0",
"crypto-browserify": "~3.12.0",
"currency-symbol-map": "~5.1.0",
"events": "~3.3.0",
"i18next": "~23.11.1",
"i18next": "~23.11.5",
"localforage": "~1.10.0",
"lru-cache": "~10.2.0",
"lru-cache": "~10.2.2",
"patch-package": "~8.0.0",
"postinstall-postinstall": "~2.1.0",
"process": "~0.11.10",
"react": "~18.2.0",
"react": "~18.3.1",
"react-countdown-circle-timer": "~3.2.1",
"react-dom": "~18.2.0",
"react-i18next": "~14.1.0",
"react-redux": "~9.1.0",
"react-router-dom": "~6.22.3",
"react-dom": "~18.3.1",
"react-i18next": "~14.1.2",
"react-redux": "~9.1.2",
"react-router-dom": "~6.23.1",
"react-secure-storage": "~1.3.2",
"socket.io-client": "~4.7.5",
"stream-browserify": "~3.0.0",
"util": "~0.12.5"
},
"devDependencies": {
"@types/chrome": "~0.0.266",
"@types/node": "~20.12.7",
"@types/react": "~18.2.77",
"@types/react-dom": "~18.2.25",
"@types/bchaddrjs": "~0.4.3",
"@types/chrome": "~0.0.268",
"@types/node": "~20.14.1",
"@types/react": "~18.3.3",
"@types/react-dom": "~18.3.0",
"@types/react-redux": "~7.1.33",
"@types/react-router-dom": "~5.3.3",
"@typescript-eslint/eslint-plugin": "~7.6.0",
"@typescript-eslint/parser": "~7.6.0",
"@vitejs/plugin-react-swc": "~3.6.0",
"eslint": "~8.56.0",
"eslint-plugin-react": "~7.34.1",
"eslint-plugin-react-hooks": "~4.6.0",
"eslint-plugin-react-refresh": "~0.4.6",
"prettier": "~3.2.5",
"@typescript-eslint/eslint-plugin": "~7.12.0",
"@typescript-eslint/parser": "~7.12.0",
"@vitejs/plugin-react-swc": "~3.7.0",
"eslint": "~8.57.0",
"eslint-plugin-react": "~7.34.2",
"eslint-plugin-react-hooks": "~4.6.2",
"eslint-plugin-react-refresh": "~0.4.7",
"prettier": "~3.3.0",
"typescript": "~5.4.5",
"vite": "~5.2.8"
"vite": "~5.2.12"
},
"engines": {
"node": ">=20"
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.4.0",
"version": "1.5.0",
"manifest_version": 3,
"name": "SSP Wallet",
"short_name": "SSP",
Expand Down
15 changes: 15 additions & 0 deletions src/assets/bch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/assets/zec.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/blockchains.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ declare module '@storage/blockchains' {
maxMessage: number;
maxTxSize: number;
rbf: boolean;
cashaddr: string;
txExpiryHeight: number;
hashType: number;
}
type blockchains = Record<string, Blockchain>;
let blockchains: blockchains;
Expand Down
39 changes: 38 additions & 1 deletion src/lib/constructTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import utxolib from '@runonflux/utxo-lib';
import { Buffer } from 'buffer';
import axios from 'axios';
import BigNumber from 'bignumber.js';
import { toLegacyAddress } from 'bchaddrjs';
import {
blockbookUtxo,
utxo,
Expand All @@ -16,6 +17,8 @@ import { blockchains } from '@storage/blockchains';

import { LRUCache } from 'lru-cache';

import { getBlockheight } from './blockheight.ts';

const utxoCache = new LRUCache({
max: 1000,
ttl: 1 * 60 * 60 * 1000, // 1 hour, just as precaution here, not really needed
Expand Down Expand Up @@ -211,7 +214,14 @@ export function signTransaction(
const libID = getLibId(chain);
const network = utxolib.networks[libID];
const txhex = rawTx;
const hashType = utxolib.Transaction.SIGHASH_ALL;
let hashType = utxolib.Transaction.SIGHASH_ALL;
if (blockchains[chain].hashType) {
// only for BCH
hashType =
// eslint-disable-next-line no-bitwise
utxolib.Transaction.SIGHASH_ALL |
utxolib.Transaction.SIGHASH_BITCOINCASHBIP143;
}
const keyPair = utxolib.ECPair.fromWIF(privateKey, network);
const txb = utxolib.TransactionBuilder.fromTransaction(
utxolib.Transaction.fromHex(txhex, network),
Expand Down Expand Up @@ -262,23 +272,32 @@ export function buildUnsignedRawTx(
message: string,
maxFee: string,
isRBF = true,
expiryHeight?: number,
): string {
try {
const libID = getLibId(chain);
const network = utxolib.networks[libID];
const cashAddrPrefix = blockchains[chain].cashaddr;
const txb = new utxolib.TransactionBuilder(network, fee);
if (blockchains[chain].txVersion) {
txb.setVersion(blockchains[chain].txVersion);
}
if (blockchains[chain].txGroupID) {
txb.setVersionGroupId(blockchains[chain].txGroupID);
}
if (expiryHeight && blockchains[chain].txExpiryHeight) {
txb.setExpiryHeight(expiryHeight);
}
if (isRBF) {
const RBFsequence = 0xffffffff - 2;
utxos.forEach((x) => txb.addInput(x.txid, x.vout, RBFsequence));
} else {
utxos.forEach((x) => txb.addInput(x.txid, x.vout));
}
if (cashAddrPrefix) {
receiver = toLegacyAddress(receiver);
change = toLegacyAddress(change);
}
const recipients = [
{
address: receiver,
Expand Down Expand Up @@ -589,6 +608,13 @@ export async function getTransactionSize(
if (mandatoryUtxos?.length) {
console.log('RBF TX');
}
const rbf = blockchains[chain].rbf ?? false;
let expiryHeight;
if (blockchains[chain].txExpiryHeight) {
// fetch current blockheight
const currentBlockheight = await getBlockheight(chain);
expiryHeight = currentBlockheight + blockchains[chain].txExpiryHeight;
}
const rawTx = buildUnsignedRawTx(
chain,
pickedUtxos,
Expand All @@ -598,6 +624,8 @@ export async function getTransactionSize(
change,
message,
maxFee,
rbf,
expiryHeight,
);
if (!rawTx) {
throw new Error('Could not construct raw tx');
Expand Down Expand Up @@ -700,6 +728,13 @@ export async function constructAndSignTransaction(
if (mandatoryUtxos?.length) {
console.log('RBF TX');
}
const rbf = blockchains[chain].rbf ?? false;
let expiryHeight;
if (blockchains[chain].txExpiryHeight) {
// fetch current blockheight
const currentBlockheight = await getBlockheight(chain);
expiryHeight = currentBlockheight + blockchains[chain].txExpiryHeight;
}
const rawTx = buildUnsignedRawTx(
chain,
pickedUtxos,
Expand All @@ -709,6 +744,8 @@ export async function constructAndSignTransaction(
change,
message,
maxFee,
rbf,
expiryHeight,
);
if (!rawTx) {
throw new Error('Could not construct raw tx');
Expand Down
6 changes: 6 additions & 0 deletions src/lib/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import BigNumber from 'bignumber.js';
import utxolib from '@runonflux/utxo-lib';
import { toCashAddress } from 'bchaddrjs';
import {
transacitonsInsight,
transactionInsight,
Expand Down Expand Up @@ -249,6 +250,7 @@ export function decodeTransactionForApproval(
try {
const libID = getLibId(chain);
const decimals = blockchains[chain].decimals;
const cashAddrPrefix = blockchains[chain].cashaddr;
const network = utxolib.networks[libID];
const txhex = rawTx;
const txb = utxolib.TransactionBuilder.fromTransaction(
Expand Down Expand Up @@ -304,6 +306,10 @@ export function decodeTransactionForApproval(
.toFixed();
}
}
if (cashAddrPrefix) {
senderAddress = toCashAddress(senderAddress);
txReceiver = toCashAddress(txReceiver);
}
const txInfo = {
sender: senderAddress,
receiver: txReceiver,
Expand Down
18 changes: 15 additions & 3 deletions src/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Buffer } from 'buffer';
import { HDKey } from '@scure/bip32';
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
import { toCashAddress } from 'bchaddrjs';
import {
keyPair,
minHDKey,
Expand Down Expand Up @@ -111,6 +112,7 @@ export function generateMultisigAddress(
const bipParams = blockchains[chain].bip32;
const type = blockchains[chain].scriptType;
const networkBipParams = utxolib.networks[libID].bip32;
const cashAddrPrefix = blockchains[chain].cashaddr;
let externalChain1, externalChain2;
try {
externalChain1 = HDKey.fromExtendedKey(xpub1, bipParams);
Expand Down Expand Up @@ -148,7 +150,10 @@ export function generateMultisigAddress(
const scriptPubKey = utxolib.script.witnessScriptHash.output.encode(
utxolib.crypto.sha256(witnessScript),
);
const address = utxolib.address.fromOutputScript(scriptPubKey, network);
let address = utxolib.address.fromOutputScript(scriptPubKey, network);
if (cashAddrPrefix) {
address = toCashAddress(address);
}
const witnessScriptHex: string = Buffer.from(witnessScript).toString('hex');
return {
address,
Expand All @@ -165,9 +170,12 @@ export function generateMultisigAddress(
const scriptPubKey = utxolib.script.scriptHash.output.encode(
utxolib.crypto.hash160(redeemScript),
);
const address = utxolib.address.fromOutputScript(scriptPubKey, network);
let address = utxolib.address.fromOutputScript(scriptPubKey, network);
const witnessScriptHex: string = Buffer.from(witnessScript).toString('hex');
const redeemScriptHex: string = Buffer.from(redeemScript).toString('hex');
if (cashAddrPrefix) {
address = toCashAddress(address);
}
return {
address,
redeemScript: redeemScriptHex,
Expand All @@ -183,11 +191,15 @@ export function generateMultisigAddress(
utxolib.crypto.hash160(redeemScript),
);

const address: string = utxolib.address.fromOutputScript(
let address: string = utxolib.address.fromOutputScript(
scriptPubKey,
network,
);

if (cashAddrPrefix) {
address = toCashAddress(address);
}

const redeemScriptHex: string = Buffer.from(redeemScript).toString('hex');
return {
address,
Expand Down
10 changes: 10 additions & 0 deletions src/storage/backends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ const btc = {
const doge = {
node: 'blockbookdogecoin.app.runonflux.io',
};
const zec = {
node: 'blockbookzcash.app.runonflux.io',
};
const bch = {
node: 'blockbookbitcoincash.app.runonflux.io',
};
const btcTestnet = {
node: 'blockbookbitcointestnet.app.runonflux.io',
};
Expand All @@ -55,6 +61,8 @@ export function backends() {
ltc: localForgeBackends?.ltc || ltc,
btc: localForgeBackends?.btc || btc,
doge: localForgeBackends?.doge || doge,
zec: localForgeBackends?.zec || zec,
bch: localForgeBackends?.bch || bch,
btcTestnet: localForgeBackends?.btcTestnet || btcTestnet,
btcSignet: localForgeBackends?.btcSignet || btcSignet,
};
Expand All @@ -68,6 +76,8 @@ export function backendsOriginal() {
ltc,
btc,
doge,
zec,
bch,
btcTestnet,
btcSignet,
};
Expand Down
Loading

0 comments on commit 0283ed3

Please sign in to comment.