Skip to content
Draft
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
5 changes: 5 additions & 0 deletions modules/sdk-coin-flrp/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.idea
public
dist

7 changes: 7 additions & 0 deletions modules/sdk-coin-flrp/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../.eslintrc.json",
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "error",
"indent": "off"
}
}
3 changes: 3 additions & 0 deletions modules/sdk-coin-flrp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.idea/
dist/
8 changes: 8 additions & 0 deletions modules/sdk-coin-flrp/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require: 'tsx'
timeout: '60000'
reporter: 'min'
reporter-option:
- 'cdn=true'
- 'json=false'
exit: true
spec: ['test/unit/**/*.ts']
12 changes: 12 additions & 0 deletions modules/sdk-coin-flrp/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!dist/
.idea/
.prettierrc.yml
tsconfig.json
src/
test/
scripts/
.nyc_output
CODEOWNERS
node_modules/
.prettierignore
.mocharc.js
2 changes: 2 additions & 0 deletions modules/sdk-coin-flrp/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output/
dist/
3 changes: 3 additions & 0 deletions modules/sdk-coin-flrp/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printWidth: 120
singleQuote: true
trailingComma: 'es5'
Empty file.
64 changes: 64 additions & 0 deletions modules/sdk-coin-flrp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@bitgo/sdk-coin-flrp",
"version": "5.3.0",
"description": "BitGo's SDK coin library for flrp coin",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
"build": "yarn tsc --build --incremental --verbose .",
"fmt": "prettier --write .",
"check-fmt": "prettier --check .",
"clean": "rm -r ./dist",
"lint": "eslint --quiet .",
"prepare": "npm run build",
"test": "npm run coverage",
"coverage": "nyc -- npm run unit-test",
"unit-test": "mocha"
},
"scriptsComment": {
"build": "Need to re-add unit-test: 'nyc -- mocha' and test 'npm run unit-test', removed to green build and will add tests as implemented"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-flrp"
},
"author": "BitGo SDK Team <sdkteam@bitgo.com>",
"license": "MIT",
"engines": {
"node": ">=18 <23"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"devDependencies": {
"@bitgo/sdk-api": "^1.67.0",
"@bitgo/sdk-test": "^9.0.5"
},
"dependencies": {
"@bitgo/sdk-core": "^36.5.0",
"@bitgo/secp256k1": "^1.5.0",
"@bitgo/statics": "^57.5.0",
"@flarenetwork/flarejs": "1.3.2",
"@noble/curves": "1.8.1",
"@types/bn.js": "^5.2.0",
"create-hash": "^1.2.0",
"ecurve": "^1.0.6",
"ethers": "^6.0.0",
"hdkey": "^2.0.1",
"lodash": "^4.17.14",
"safe-buffer": "^5.2.1"
},
"gitHead": "18e460ddf02de2dbf13c2aa243478188fb539f0c"
}
18 changes: 18 additions & 0 deletions modules/sdk-coin-flrp/src/flrp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
import { AbstractEthLikeNewCoins } from '@bitgo/abstract-eth';

export class Flrp extends AbstractEthLikeNewCoins {
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo, staticsCoin);
}

static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
return new Flrp(bitgo, staticsCoin);
}

protected getTransactionBuilder(): any {
// TODO: Implement transaction builder
throw new Error('Method not implemented.');
}
}
52 changes: 52 additions & 0 deletions modules/sdk-coin-flrp/src/iface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
SignTransactionOptions,
TransactionPrebuild as BaseTransactionPrebuild,
TransactionRecipient,
TransactionFee,
VerifyTransactionOptions,
TransactionParams,
} from '@bitgo/sdk-core';

export { TransactionFee };
export interface ExplainTransactionOptions {
txHex?: string;
halfSigned?: {
txHex: string;
};
publicKeys?: string[];
}

export interface TxInfo {
recipients: TransactionRecipient[];
from: string;
txid: string;
}

export interface FlrpSignTransactionOptions extends SignTransactionOptions {
txPrebuild: TransactionPrebuild;
prv: string | string[];
pubKeys?: string[];
}
export interface TransactionPrebuild extends BaseTransactionPrebuild {
txHex: string;
txInfo: TxInfo;
source: string;
}
export interface FlrpTransactionStakingOptions {
startTime: string;
endTime: string;
nodeID: string;
amount: string;
delegationFeeRate?: number;
}
export interface FlrpTransactionParams extends TransactionParams {
type: string;
stakingOptions: FlrpTransactionStakingOptions;
locktime?: number;
unspents?: string[];
sourceChain?: string;
}

export interface FlrpVerifyTransactionOptions extends VerifyTransactionOptions {
txParams: FlrpTransactionParams;
}
5 changes: 5 additions & 0 deletions modules/sdk-coin-flrp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './flrp';
export * from './tflrp';
export * as FlrPLib from './lib';
export * from './iface';
export * from './register';
15 changes: 15 additions & 0 deletions modules/sdk-coin-flrp/src/lib/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BuildTransactionError } from '@bitgo/sdk-core';

export class AddressValidationError extends BuildTransactionError {
constructor(malformedAddress: string) {
super(`The address '${malformedAddress}' is not a well-formed dot address`);
this.name = AddressValidationError.name;
}
}

export class InvalidFeeError extends BuildTransactionError {
constructor(type?: string, expectedType?: string) {
super(`The specified type: "${type}" is not valid. Please provide the type: "${expectedType}"`);
this.name = InvalidFeeError.name;
}
}
74 changes: 74 additions & 0 deletions modules/sdk-coin-flrp/src/lib/iface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { TransactionExplanation as BaseTransactionExplanation, Entry, TransactionType } from '@bitgo/sdk-core';
import { avm, platformvm } from '@flarenetwork/flarejs';
export interface FlrpEntry extends Entry {
id: string;
}
export interface TransactionExplanation extends BaseTransactionExplanation {
type: TransactionType;
rewardAddresses: string[];
inputs: Entry[];
}

/**
* Method names for the transaction method. Names change based on the type of transaction e.g 'bond' for the staking transaction
*/
export enum MethodNames {
addDelegator,
addValidator,
}

/**
* The transaction data returned from the toJson() function of a transaction
*/
export interface TxData {
id: string;
inputs: Entry[];
type: TransactionType;
fromAddresses: string[];
threshold: number;
locktime: string;
signatures: string[];
outputs: Entry[];
changeOutputs: Entry[];
sourceChain?: string;
destinationChain?: string;
}

/**
* Decoded UTXO object. This is for a single utxo
*
* @param {number} outputID
* @param {string} amount Amount as a Big Number string
* @param {string} txid Transaction ID encoded as cb58
* @param {string} outputidx Output index as a string
*/
export type DecodedUtxoObj = {
outputID: number;
amount: string;
txid: string;
outputidx: string;
threshold: number;
addresses: string[];
addressesIndex?: number[];
};

/**
* FlareJS uses string-based TypeSymbols instead of numeric type IDs
* For SECP256K1 Transfer Output, use TypeSymbols.TransferOutput from @flarenetwork/flarejs
*
* @see https://docs.flare.network/ for Flare network documentation
* @deprecated Use TypeSymbols.TransferOutput from @flarenetwork/flarejs instead
*/
export const SECP256K1_Transfer_Output = 7; // Legacy - FlareJS uses TypeSymbols.TransferOutput

export const ADDRESS_SEPARATOR = '~';
export const INPUT_SEPARATOR = ':';

// FlareJS 1.3.2 type definitions - using avm and platformvm modules
export type DeprecatedTx = unknown; // Placeholder for backward compatibility
export type DeprecatedBaseTx = unknown; // Placeholder for backward compatibility
export type Tx = avm.UnsignedTx | platformvm.UnsignedTx; // FlareJS UnsignedTx from AVM or Platform VM
export type BaseTx = avm.BaseTx | platformvm.BaseTx; // FlareJS BaseTx
export type AvaxTx = avm.Tx | platformvm.Tx; // FlareJS Tx
export type DeprecatedOutput = unknown; // Placeholder for backward compatibility
export type Output = avm.TransferableOutput | platformvm.TransferableOutput; // FlareJS TransferableOutput
4 changes: 4 additions & 0 deletions modules/sdk-coin-flrp/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Utils from './utils';
export * from './iface';
export { KeyPair } from './keyPair';
export { Utils };
Loading
Loading