-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'COIN-2914-apt-transfer-function-change' into COIN-2920-…
…apt-nft-transfer TICKET: COIN-2920
- Loading branch information
Showing
25 changed files
with
492 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.idea | ||
public | ||
dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
.idea/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require: 'ts-node/register' | ||
timeout: '120000' | ||
reporter: 'min' | ||
reporter-option: | ||
- 'cdn=true' | ||
- 'json=false' | ||
exit: true | ||
spec: ['test/unit/**/*.ts'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
!dist/ | ||
dist/test/ | ||
dist/tsconfig.tsbuildinfo | ||
.idea/ | ||
.prettierrc.yml | ||
tsconfig.json | ||
src/ | ||
test/ | ||
scripts/ | ||
.nyc_output | ||
CODEOWNERS | ||
node_modules/ | ||
.prettierignore | ||
.mocharc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.nyc_output/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
printWidth: 120 | ||
singleQuote: true | ||
trailingComma: 'es5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
**Note:** Version bump only for package @bitgo/sdk-coin-wemix | ||
|
||
### Features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# BitGo sdk-coin-wemix | ||
|
||
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-wemix`. | ||
|
||
```shell | ||
npm i @bitgo/sdk-api @bitgo/sdk-coin-wemix | ||
``` | ||
|
||
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 { wemix } from '@bitgo/sdk-coin-wemix'; | ||
|
||
const sdk = new BitGoAPI(); | ||
|
||
sdk.register('wemix', wemix.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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@bitgo/sdk-coin-wemix", | ||
"version": "1.0.0", | ||
"description": "BitGo SDK coin library for Wemix", | ||
"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" | ||
}, | ||
"author": "BitGo SDK Team <[email protected]>", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=18 <21" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BitGo/BitGoJS.git", | ||
"directory": "modules/sdk-coin-wemix" | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts}": [ | ||
"yarn prettier --write", | ||
"yarn eslint --fix" | ||
] | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
] | ||
}, | ||
"dependencies": { | ||
"@bitgo/abstract-eth": "^22.4.12", | ||
"@bitgo/sdk-core": "^28.21.1", | ||
"@bitgo/statics": "^50.21.1", | ||
"@ethereumjs/common": "^2.6.5" | ||
}, | ||
"devDependencies": { | ||
"@bitgo/sdk-api": "^1.58.4", | ||
"@bitgo/sdk-test": "^8.0.67" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './lib'; | ||
export * from './wemix'; | ||
export * from './twemix'; | ||
export * from './register'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as Utils from './utils'; | ||
|
||
export { TransactionBuilder } from './transactionBuilder'; | ||
export { TransferBuilder } from './transferBuilder'; | ||
export { Transaction, KeyPair } from '@bitgo/abstract-eth'; | ||
export { Utils }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import EthereumCommon from '@ethereumjs/common'; | ||
import { coins, EthereumNetwork } from '@bitgo/statics'; | ||
|
||
export const testnetCommon = EthereumCommon.custom( | ||
{ | ||
name: 'wemix testnet', | ||
networkId: (coins.get('twemix').network as EthereumNetwork).chainId, | ||
chainId: (coins.get('twemix').network as EthereumNetwork).chainId, | ||
}, | ||
{ | ||
baseChain: 'sepolia', | ||
hardfork: 'london', | ||
eips: [1559], | ||
} | ||
); | ||
|
||
export const mainnetCommon = EthereumCommon.custom( | ||
{ | ||
name: 'wemix mainnet', | ||
networkId: (coins.get('wemix').network as EthereumNetwork).chainId, | ||
chainId: (coins.get('wemix').network as EthereumNetwork).chainId, | ||
}, | ||
{ | ||
baseChain: 'mainnet', | ||
hardfork: 'london', | ||
eips: [1559], | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { BaseCoin as CoinConfig } from '@bitgo/statics'; | ||
import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core'; | ||
import { TransactionBuilder as AbstractTransactionBuilder, Transaction } from '@bitgo/abstract-eth'; | ||
import { getCommon } from './utils'; | ||
import { TransferBuilder } from './transferBuilder'; | ||
|
||
export class TransactionBuilder extends AbstractTransactionBuilder { | ||
protected _transfer: TransferBuilder; | ||
|
||
constructor(_coinConfig: Readonly<CoinConfig>) { | ||
super(_coinConfig); | ||
this._common = getCommon(this._coinConfig.network.type); | ||
this.transaction = new Transaction(this._coinConfig, this._common); | ||
} | ||
|
||
/** @inheritdoc */ | ||
transfer(data?: string): TransferBuilder { | ||
if (this._type !== TransactionType.Send) { | ||
throw new BuildTransactionError('Transfers can only be set for send transactions'); | ||
} | ||
if (!this._transfer) { | ||
this._transfer = new TransferBuilder(data); | ||
} | ||
return this._transfer; | ||
} | ||
|
||
protected getContractData(addresses: string[]): string { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { TransferBuilder } from '@bitgo/abstract-eth'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NetworkType } from '@bitgo/statics'; | ||
import EthereumCommon from '@ethereumjs/common'; | ||
import { InvalidTransactionError } from '@bitgo/sdk-core'; | ||
import { testnetCommon, mainnetCommon } from './resources'; | ||
|
||
const commons: Map<NetworkType, EthereumCommon> = new Map<NetworkType, EthereumCommon>([ | ||
[NetworkType.MAINNET, mainnetCommon], | ||
[NetworkType.TESTNET, testnetCommon], | ||
]); | ||
|
||
/** | ||
* @param {NetworkType} network either mainnet or testnet | ||
* @returns {EthereumCommon} Ethereum common configuration object | ||
*/ | ||
export function getCommon(network: NetworkType): EthereumCommon { | ||
const common = commons.get(network); | ||
if (!common) { | ||
throw new InvalidTransactionError('Missing network common configuration'); | ||
} | ||
return common; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { BitGoBase } from '@bitgo/sdk-core'; | ||
import { Wemix } from './wemix'; | ||
import { Twemix } from './twemix'; | ||
|
||
export const register = (sdk: BitGoBase): void => { | ||
sdk.register('wemix', Wemix.createInstance); | ||
sdk.register('twemix', Twemix.createInstance); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Testnet Wemix | ||
* | ||
* @format | ||
*/ | ||
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core'; | ||
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; | ||
import { Wemix } from './wemix'; | ||
|
||
export class Twemix extends Wemix { | ||
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) { | ||
super(bitgo, staticsCoin); | ||
} | ||
|
||
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin { | ||
return new Twemix(bitgo, staticsCoin); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*** | ||
* @developerReferences | ||
* - Developer Hub: https://docs.wemix.com/en/dapp-developer/api-reference | ||
* @coinFullName Wemix | ||
* @coinWebsite https://explorer.wemix.com | ||
*/ | ||
|
||
import { BaseCoin, BitGoBase, common, MPCAlgorithm } from '@bitgo/sdk-core'; | ||
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics'; | ||
import { AbstractEthLikeNewCoins, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth'; | ||
import { TransactionBuilder } from './lib'; | ||
|
||
export class Wemix extends AbstractEthLikeNewCoins { | ||
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) { | ||
super(bitgo, staticsCoin); | ||
} | ||
|
||
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin { | ||
return new Wemix(bitgo, staticsCoin); | ||
} | ||
|
||
protected getTransactionBuilder(): TransactionBuilder { | ||
return new TransactionBuilder(coins.get(this.getBaseChain())); | ||
} | ||
|
||
/** @inheritDoc */ | ||
supportsTss(): boolean { | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
getMPCAlgorithm(): MPCAlgorithm { | ||
return 'ecdsa'; | ||
} | ||
|
||
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> { | ||
const apiToken = common.Environments[this.bitgo.getEnv()].wemixExplorerApiToken; | ||
const explorerUrl = common.Environments[this.bitgo.getEnv()].wemixExplorerBaseUrl; | ||
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { KeyPair } from '@bitgo/abstract-eth'; | ||
|
||
export const PRIVATE_KEY_1 = '950d23766c0d0adad45a7dcf0db7a93b2c91fe411a5154c9a4ac23758c2ae4d5'; | ||
|
||
export const KEYPAIR_PRV = new KeyPair({ prv: PRIVATE_KEY_1 }); | ||
|
||
export const SEND_TX_BROADCAST_LEGACY = | ||
'0xf901cc02843b9aca0083b8a1a0948f977e912ef500548a0c3be6ddde9899f1199b8180b901643912521500000000000000000000000019645032c7f1533395d44a629462e751084d3e4c000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000005ec67da8000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004100dd3c4df19cf8156e9ad14db46d8ffd07c943ebbbab691ebaee58535fb1b0890e70a6cd300f2c4088d2cebec99ba24ae9495468c3091ac6a884efd780d353361c000000000000000000000000000000000000000000000000000000000000008208d4a0fa51ffcbc4d852a5f2f7870f5706b8798d81939fe77aead4052335bcd497f145a045493236056765d1cd847aca650bbe97f7148c1ea41143154ed1a5973184ba15'; | ||
|
||
export const SEND_TX_AMOUNT_ZERO_BROADCAST = | ||
'0xf901cc02843b9aca0083b8a1a0948f977e912ef500548a0c3be6ddde9899f1199b8180b901643912521500000000000000000000000019645032c7f1533395d44a629462e751084d3e4c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000005ec67da8000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000411badc5af505b10ebf6bc80322567ac71af7970a9ac1ebdf33f656bbfa2b40f652239e4ecd9b7b391db68fb84467e11dacb5d54f38770d79f4c95c9c1d4eba0a21c000000000000000000000000000000000000000000000000000000000000008208d3a01c830bee5c43a339f4f6bec2e705045986482d72cf0c504183c121a4c246a57ba068b7460d6e0b0e5b354053c78cd412286adc79e21ec3bb9169930b47e455b071'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { TransactionBuilder } from '../../src'; | ||
import { coins } from '@bitgo/statics'; | ||
|
||
export const getBuilder = (coin: string): TransactionBuilder => { | ||
return new TransactionBuilder(coins.get(coin)); | ||
}; |
Oops, something went wrong.