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
2 changes: 2 additions & 0 deletions modules/sdk-coin-xpr/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions modules/sdk-coin-xpr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dist
/node_modules
/.nyc_output
8 changes: 8 additions & 0 deletions modules/sdk-coin-xpr/.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']
10 changes: 10 additions & 0 deletions modules/sdk-coin-xpr/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/*.ts
!**/*.d.ts
src
test
tsconfig.json
tslint.json
.gitignore
.eslintignore
.mocharc.yml
.prettierignore
2 changes: 2 additions & 0 deletions modules/sdk-coin-xpr/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions modules/sdk-coin-xpr/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printWidth: 120
singleQuote: true
trailingComma: es5
30 changes: 30 additions & 0 deletions modules/sdk-coin-xpr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-xpr

SDK coins provide a modular approach to a monolithic architecture. This and all BitGoJS SDK coins allow developers to use only the coins needed for a given project.

## Installation

All coins are loaded traditionally through the `bitgo` package. If you are using coins individually, you will be accessing the coin via the `@bitgo/sdk-api` package.

In your project install both `@bitgo/sdk-api` and `@bitgo/sdk-coin-xpr`.

```shell
npm i @bitgo/sdk-api @bitgo/sdk-coin-xpr
```

Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`.

```javascript
import { BitGoAPI } from '@bitgo/sdk-api';
import { Xpr } from '@bitgo/sdk-coin-xpr';

const sdk = new BitGoAPI();

sdk.register('xpr', Xpr.createInstance);
```

## Development

Most of the coin implementations are derived from `@bitgo/sdk-core`, `@bitgo/statics`, and coin specific packages. These implementations are used to interact with the BitGo API and BitGo platform services.

You will notice that the basic version of common class extensions have been provided to you and must be resolved before the package build will succeed. Upon initiation of a given SDK coin, you will need to verify that your coin has been included in the root `tsconfig.packages.json` and that the linting, formatting, and testing succeeds when run both within the coin and from the root of BitGoJS.
57 changes: 57 additions & 0 deletions modules/sdk-coin-xpr/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@bitgo/sdk-coin-xpr",
"version": "1.0.0",
"description": "BitGo SDK coin library for Proton (XPR Network)",
"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 '**/*.{ts,js,json}'",
"clean": "rm -r ./dist",
"lint": "eslint --quiet .",
"prepare": "npm run build",
"test": "npm run coverage",
"coverage": "nyc -- npm run unit-test",
"unit-test": "mocha"
},
"author": "BitGo SDK Team <sdkteam@bitgo.com>",
"license": "MIT",
"engines": {
"node": ">=20 <25"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-xpr"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/sdk-core": "^36.29.0",
"@bitgo/statics": "^58.23.0",
"@greymass/eosio": "^0.7.0",
"bignumber.js": "^9.1.1",
"@bitgo/sdk-lib-mpc": "^10.8.1",
"bs58": "^5.0.0"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.73.3",
"@bitgo/sdk-test": "^9.1.24"
},
"files": [
"dist"
]
}
4 changes: 4 additions & 0 deletions modules/sdk-coin-xpr/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib';
export * from './xpr';
export * from './txpr';
export * from './register';
37 changes: 37 additions & 0 deletions modules/sdk-coin-xpr/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Constants for Proton (XPR Network)
*/

// Proton mainnet chain ID
export const MAINNET_CHAIN_ID = '384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0';

// Proton testnet chain ID
export const TESTNET_CHAIN_ID = '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd';

// Coin names
export const MAINNET_COIN = 'xpr';
export const TESTNET_COIN = 'txpr';

// XPR token symbol and precision
export const XPR_SYMBOL = 'XPR';
export const XPR_PRECISION = 4;

// Token contract
export const TOKEN_CONTRACT = 'eosio.token';

// Account name constraints
export const MAX_ACCOUNT_NAME_LENGTH = 12;

// Valid characters for EOSIO account names: a-z, 1-5, and dot
// Note: Account names must be lowercase and cannot start or end with a dot
export const VALID_ACCOUNT_NAME_REGEX = /^[a-z1-5.]{1,12}$/;

// Public key formats (PUB_K1_, EOS legacy format)
export const VALID_PUBLIC_KEY_REGEX = /^(PUB_K1_[A-Za-z0-9]{50}|EOS[A-Za-z0-9]{50,52})$/;

// Private key format (PVT_K1_ or WIF)
export const VALID_PRIVATE_KEY_REGEX = /^(PVT_K1_[A-Za-z0-9]{47,52}|5[HJK][A-Za-z0-9]{49,50})$/;

// Transaction constants
export const DEFAULT_EXPIRATION_SECONDS = 120; // 2 minutes
export const MAX_EXPIRATION_SECONDS = 3600; // 1 hour
107 changes: 107 additions & 0 deletions modules/sdk-coin-xpr/src/lib/iface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Interfaces for Proton (XPR Network)
*/

import { TransactionExplanation as BaseTransactionExplanation, TransactionType } from '@bitgo/sdk-core';

/**
* Authorization for an EOSIO action
*/
export interface Authorization {
actor: string;
permission: string;
}

/**
* Transfer action data
*/
export interface TransferActionData {
from: string;
to: string;
quantity: string;
memo: string;
}

/**
* EOSIO action
*/
export interface Action {
account: string;
name: string;
authorization: Authorization[];
data: TransferActionData | Record<string, unknown>;
}

/**
* Transaction headers from the blockchain
*/
export interface TransactionHeaders {
expiration: string;
refBlockNum: number;
refBlockPrefix: number;
}

/**
* Transaction data structure
*/
export interface TxData {
id?: string;
type?: TransactionType;
sender: string;
expiration: string;
refBlockNum: number;
refBlockPrefix: number;
actions: Action[];
signatures: string[];
}

/**
* Transaction JSON representation for serialization
*/
export interface TransactionJson {
expiration: string;
ref_block_num: number;
ref_block_prefix: number;
max_net_usage_words: number;
max_cpu_usage_ms: number;
delay_sec: number;
context_free_actions: Action[];
actions: Action[];
transaction_extensions: unknown[];
}

/**
* Broadcast format for Proton transactions
*/
export interface BroadcastFormat {
signatures: string[];
compression: string;
packed_context_free_data: string;
packed_trx: string;
}

/**
* Transaction output (recipient)
*/
export interface TransactionOutput {
address: string;
amount: string;
memo?: string;
}

/**
* Transaction input (sender)
*/
export interface TransactionInput {
address: string;
amount: string;
}

/**
* Extended transaction explanation for Proton
*/
export interface TransactionExplanation extends BaseTransactionExplanation {
type: string;
sender?: string;
memo?: string;
}
7 changes: 7 additions & 0 deletions modules/sdk-coin-xpr/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './keyPair';
export * from './utils';
export * from './constants';
export * from './iface';
export * from './transaction';
export * from './transactionBuilder';
export * from './transferBuilder';
Loading
Loading