-
Notifications
You must be signed in to change notification settings - Fork 300
feat: add xrp coin #8009
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
base: master
Are you sure you want to change the base?
feat: add xrp coin #8009
Conversation
56ba427 to
257da8f
Compare
- Add sdk-coin-xpr module with transaction builders - Add XPR to statics (CoinFamily, networks, coins) - Implement keyPair, transaction, transferBuilder - Add unit tests
257da8f to
1136675
Compare
|
|
||
| import { DefaultKeys, isPrivateKey, isPublicKey, isSeed, KeyPairOptions, AddressFormat } from '@bitgo/sdk-core'; | ||
| import { PrivateKey, PublicKey, KeyType } from '@greymass/eosio'; | ||
| import { randomBytes } from 'crypto'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
In general, unused imports should be removed to improve readability and avoid confusion. Since randomBytes is never used and crypto is accessed via require('crypto') in the function body instead, the best fix is to delete the unused named import.
Concretely, in modules/sdk-coin-xpr/src/lib/keyPair.ts, remove line 7:
import { randomBytes } from 'crypto';No other changes are required: the existing require('crypto') calls will continue to work, and there is no impact on current behavior since randomBytes was never referenced.
| @@ -4,7 +4,6 @@ | ||
|
|
||
| import { DefaultKeys, isPrivateKey, isPublicKey, isSeed, KeyPairOptions, AddressFormat } from '@bitgo/sdk-core'; | ||
| import { PrivateKey, PublicKey, KeyType } from '@greymass/eosio'; | ||
| import { randomBytes } from 'crypto'; | ||
|
|
||
| /** | ||
| * Proton (XPR Network) key pair class |
| import { | ||
| Transaction as EosioTransaction, | ||
| Checksum256, | ||
| Serializer, | ||
| Action, | ||
| Name, | ||
| Asset, | ||
| Struct, | ||
| } from '@greymass/eosio'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
To fix an unused import, remove the specific symbol from the import list while keeping all other used imports intact. This improves readability and avoids confusion without affecting functionality.
Concretely, in modules/sdk-coin-xpr/src/lib/transaction.ts, edit the import from @greymass/eosio (around lines 15–22). Remove Action from the curly-brace import list, keeping Transaction as EosioTransaction, Checksum256, Serializer, Name, Asset, and Struct unchanged. No other code changes or new imports are required.
| @@ -15,7 +15,6 @@ | ||
| Transaction as EosioTransaction, | ||
| Checksum256, | ||
| Serializer, | ||
| Action, | ||
| Name, | ||
| Asset, | ||
| Struct, |
| import BigNumber from 'bignumber.js'; | ||
| import { KeyPair } from './keyPair'; | ||
| import { TxData, TransactionExplanation, BroadcastFormat, TransferActionData } from './iface'; | ||
| import { MAINNET_CHAIN_ID, TESTNET_CHAIN_ID, TOKEN_CONTRACT, XPR_SYMBOL, XPR_PRECISION } from './constants'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
In general, unused imports should be removed to improve readability and avoid confusion. Since only XPR_SYMBOL is reported as unused while the other imports on the same line may be used elsewhere, the best minimal fix is to delete XPR_SYMBOL from the import list and leave the others unchanged.
Concretely, in modules/sdk-coin-xpr/src/lib/transaction.ts, adjust the import statement on line 26 so that it no longer includes XPR_SYMBOL. No additional methods, definitions, or imports are needed; this is purely a cleanup change to the existing import list.
-
Copy modified line R26
| @@ -23,7 +23,7 @@ | ||
| import BigNumber from 'bignumber.js'; | ||
| import { KeyPair } from './keyPair'; | ||
| import { TxData, TransactionExplanation, BroadcastFormat, TransferActionData } from './iface'; | ||
| import { MAINNET_CHAIN_ID, TESTNET_CHAIN_ID, TOKEN_CONTRACT, XPR_SYMBOL, XPR_PRECISION } from './constants'; | ||
| import { MAINNET_CHAIN_ID, TESTNET_CHAIN_ID, TOKEN_CONTRACT, XPR_PRECISION } from './constants'; | ||
|
|
||
| /** | ||
| * Define the transfer struct for eosio.token |
| import { | ||
| Transaction as EosioTransaction, | ||
| Action, | ||
| Name, | ||
| Asset, | ||
| Serializer, | ||
| UInt16, | ||
| UInt32, | ||
| TimePointSec, | ||
| Struct, | ||
| } from '@greymass/eosio'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
In general, unused imports should be removed from the module to reduce clutter and avoid confusion. Since they are not referenced anywhere in transactionBuilder.ts, deleting them will not affect existing functionality.
Specifically, in modules/sdk-coin-xpr/src/lib/transactionBuilder.ts, we should edit the import from @greymass/eosio on lines 13–23. Remove the unused symbols Action, Serializer, TimePointSec, UInt16, and UInt32 from the destructured import list, leaving only the actually used Transaction as EosioTransaction, Name, Asset, and Struct. No further code changes or additional imports are required.
| @@ -12,13 +12,8 @@ | ||
| import { BaseCoin as CoinConfig } from '@bitgo/statics'; | ||
| import { | ||
| Transaction as EosioTransaction, | ||
| Action, | ||
| Name, | ||
| Asset, | ||
| Serializer, | ||
| UInt16, | ||
| UInt32, | ||
| TimePointSec, | ||
| Struct, | ||
| } from '@greymass/eosio'; | ||
| import BigNumber from 'bignumber.js'; |
| import { | ||
| MAINNET_CHAIN_ID, | ||
| TESTNET_CHAIN_ID, | ||
| TOKEN_CONTRACT, | ||
| XPR_SYMBOL, | ||
| XPR_PRECISION, | ||
| DEFAULT_EXPIRATION_SECONDS, | ||
| } from './constants'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
In general, unused imports should be removed to improve readability and avoid confusion. Since these constants are not used anywhere in the shown code, the best fix is to delete them from the import list while keeping the other, used constants.
Concretely, in modules/sdk-coin-xpr/src/lib/transactionBuilder.ts, adjust the import { ... } from './constants'; statement so that it only imports MAINNET_CHAIN_ID, TESTNET_CHAIN_ID, and DEFAULT_EXPIRATION_SECONDS, and no longer mentions TOKEN_CONTRACT, XPR_SYMBOL, or XPR_PRECISION. No additional methods, imports, or definitions are needed; we are only narrowing the import list.
| @@ -28,9 +28,6 @@ | ||
| import { | ||
| MAINNET_CHAIN_ID, | ||
| TESTNET_CHAIN_ID, | ||
| TOKEN_CONTRACT, | ||
| XPR_SYMBOL, | ||
| XPR_PRECISION, | ||
| DEFAULT_EXPIRATION_SECONDS, | ||
| } from './constants'; | ||
|
|
| /** | ||
| * Define the transfer struct for eosio.token | ||
| */ | ||
| class Transfer extends Struct { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
To fix the problem, remove the unused Transfer class definition so that there is no dead code in the module. This does not affect the existing, visible functionality of the TransactionBuilder class, since nothing in the shown code references Transfer.
Concretely, in modules/sdk-coin-xpr/src/lib/transactionBuilder.ts, delete the block that defines Transfer (lines 37–48 in the snippet: the comment and the class body). No additional imports, methods, or definitions are required, and no other lines need to be changed.
-
Copy modified lines R38-R49
| @@ -34,19 +34,19 @@ | ||
| DEFAULT_EXPIRATION_SECONDS, | ||
| } from './constants'; | ||
|
|
||
| /** | ||
| * Define the transfer struct for eosio.token | ||
| */ | ||
| class Transfer extends Struct { | ||
| static abiName = 'transfer'; | ||
| static abiFields = [ | ||
| { name: 'from', type: Name }, | ||
| { name: 'to', type: Name }, | ||
| { name: 'quantity', type: Asset }, | ||
| { name: 'memo', type: 'string' }, | ||
| ]; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| export abstract class TransactionBuilder extends BaseTransactionBuilder { | ||
| protected _transaction: Transaction; | ||
| protected _sender: string; |
| AuditDecryptedKeyParams, | ||
| } from '@bitgo/sdk-core'; | ||
| import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; | ||
| import { KeyPair as XprKeyPair, Transaction, TransferBuilder } from './lib'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
To fix this, remove the unused TransferBuilder named import from the ./lib import statement, leaving only the identifiers that are actually used (KeyPair as XprKeyPair and Transaction). This eliminates dead code, clarifies dependencies, and aligns with the recommendation to remove unused program elements.
Concretely, in modules/sdk-coin-xpr/src/xpr.ts, edit the import on line 19 so that it no longer imports TransferBuilder. No additional methods, imports, or definitions are required; we’re only trimming the unused symbol from an existing import.
-
Copy modified line R19
| @@ -16,7 +16,7 @@ | ||
| AuditDecryptedKeyParams, | ||
| } from '@bitgo/sdk-core'; | ||
| import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; | ||
| import { KeyPair as XprKeyPair, Transaction, TransferBuilder } from './lib'; | ||
| import { KeyPair as XprKeyPair, Transaction } from './lib'; | ||
| import utils from './lib/utils'; | ||
| import { MAINNET_CHAIN_ID, XPR_PRECISION } from './lib/constants'; | ||
|
|
| * @returns {boolean} | ||
| */ | ||
| async verifyTransaction(params: XprVerifyTransactionOptions): Promise<boolean> { | ||
| const { txPrebuild, txParams } = params; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
To fix the problem, remove the unused txParams binding from the destructuring assignment so the function only declares variables it actually uses. This maintains the existing function signature and behavior (it still receives params, still validates only txPrebuild.txHex, and still returns true), while eliminating the unused local variable.
Concretely, in modules/sdk-coin-xpr/src/xpr.ts, inside the verifyTransaction method, change the line:
const { txPrebuild, txParams } = params;to:
const { txPrebuild } = params;No new imports, methods, or additional code are required; this is a minimal, behavior-preserving cleanup.
-
Copy modified line R177
| @@ -174,7 +174,7 @@ | ||
| * @returns {boolean} | ||
| */ | ||
| async verifyTransaction(params: XprVerifyTransactionOptions): Promise<boolean> { | ||
| const { txPrebuild, txParams } = params; | ||
| const { txPrebuild } = params; | ||
|
|
||
| if (!txPrebuild?.txHex) { | ||
| throw new Error('Missing txPrebuild.txHex'); |
Adds the basic implementation for the Proton blockchain (XPR Network) including key pair generation, address validation, and transaction signing structures. Implements support for both mainnet (xpr) and testnet (txpr) networks.
Co-authored-by: llm-git llm-git@ttll.de
Ticket: BG-0