Skip to content

Commit

Permalink
feat(sdk-coin-icp): added ICP skeleton code
Browse files Browse the repository at this point in the history
TICKET: WIN-4245
  • Loading branch information
mohd-kashif committed Jan 16, 2025
1 parent 596f6e0 commit 07db88f
Show file tree
Hide file tree
Showing 29 changed files with 604 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
/modules/sdk-coin-eos/ @BitGo/ethalt-team
/modules/sdk-coin-ethlike/ @BitGo/ethalt-team
/modules/sdk-coin-hbar/ @BitGo/ethalt-team
/modules/sdk-coin-icp/ @BitGo/ethalt-team
/modules/sdk-coin-near/ @BitGo/ethalt-team
/modules/sdk-coin-oas/ @BitGo/ethalt-team
/modules/sdk-coin-opeth/ @BitGo/ethalt-team
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-etc /var/modules/sdk-coin-etc/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-eth2 /var/modules/sdk-coin-eth2/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-hash /var/modules/sdk-coin-hash/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-hbar /var/modules/sdk-coin-hbar/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-icp /var/modules/sdk-coin-icp/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-injective /var/modules/sdk-coin-injective/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-islm /var/modules/sdk-coin-islm/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-near /var/modules/sdk-coin-near/
Expand Down
1 change: 1 addition & 0 deletions modules/account-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@bitgo/sdk-coin-eth2": "^3.0.58",
"@bitgo/sdk-coin-hash": "^3.0.28",
"@bitgo/sdk-coin-hbar": "^2.0.59",
"@bitgo/sdk-coin-icp": "^1.0.0",
"@bitgo/sdk-coin-injective": "^3.0.28",
"@bitgo/sdk-coin-islm": "^2.1.9",
"@bitgo/sdk-coin-near": "^2.0.59",
Expand Down
5 changes: 5 additions & 0 deletions modules/account-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ export { Coredao };
import * as Apt from '@bitgo/sdk-coin-apt';
export { Apt };

import * as Icp from '@bitgo/sdk-coin-icp';
export { Icp };

const coinBuilderMap = {
trx: Trx.WrappedBuilder,
ttrx: Trx.WrappedBuilder,
Expand Down Expand Up @@ -219,6 +222,8 @@ const coinBuilderMap = {
tcoredao: Coredao.TransactionBuilder,
apt: Apt.TransactionBuilder,
tapt: Apt.TransactionBuilder,
icp: Icp.TransactionBuilder,
ticp: Icp.TransactionBuilder,
};

/**
Expand Down
3 changes: 3 additions & 0 deletions modules/account-lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
{
"path": "../sdk-coin-hbar"
},
{
"path": "../sdk-coin-icp"
},
{
"path": "../sdk-coin-injective"
},
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@bitgo/sdk-coin-ethw": "^20.0.59",
"@bitgo/sdk-coin-hash": "^3.0.28",
"@bitgo/sdk-coin-hbar": "^2.0.59",
"@bitgo/sdk-coin-icp": "^1.0.0",
"@bitgo/sdk-coin-injective": "^3.0.28",
"@bitgo/sdk-coin-islm": "^2.1.9",
"@bitgo/sdk-coin-lnbtc": "^1.1.37",
Expand Down
4 changes: 4 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
Hash,
Hbar,
Hteth,
Icp,
Injective,
Islm,
Lnbtc,
Expand Down Expand Up @@ -109,6 +110,7 @@ import {
Thash,
Thbar,
Tia,
Ticp,
Tinjective,
Tislm,
Tlnbtc,
Expand Down Expand Up @@ -184,6 +186,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('hteth', Hteth.createInstance);
globalCoinFactory.register('lnbtc', Lnbtc.createInstance);
globalCoinFactory.register('ltc', Ltc.createInstance);
globalCoinFactory.register('icp', Icp.createInstance);
globalCoinFactory.register('injective', Injective.createInstance);
globalCoinFactory.register('islm', Islm.createInstance);
globalCoinFactory.register('near', Near.createInstance);
Expand Down Expand Up @@ -235,6 +238,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('tfiatusd', TfiatUsd.createInstance);
globalCoinFactory.register('thash', Thash.createInstance);
globalCoinFactory.register('thbar', Thbar.createInstance);
globalCoinFactory.register('ticp', Ticp.createInstance);
globalCoinFactory.register('tinjective', Tinjective.createInstance);
globalCoinFactory.register('tislm', Tislm.createInstance);
globalCoinFactory.register('tlnbtc', Tlnbtc.createInstance);
Expand Down
2 changes: 2 additions & 0 deletions modules/bitgo/src/v2/coins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { Ethw } from '@bitgo/sdk-coin-ethw';
import { EthLikeCoin, TethLikeCoin } from '@bitgo/sdk-coin-ethlike';
import { Hash, Thash } from '@bitgo/sdk-coin-hash';
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
import { Icp, Ticp } from '@bitgo/sdk-coin-icp';
import { Injective, Tinjective } from '@bitgo/sdk-coin-injective';
import { Islm, Tislm } from '@bitgo/sdk-coin-islm';
import { Lnbtc, Tlnbtc } from '@bitgo/sdk-coin-lnbtc';
Expand Down Expand Up @@ -86,6 +87,7 @@ export { EthLikeCoin, TethLikeCoin };
export { Etc, Tetc };
export { Hash, Thash };
export { Hbar, Thbar };
export { Icp, Ticp };
export { Lnbtc, Tlnbtc };
export { Ltc, Tltc };
export { Oas, Toas };
Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
{
"path": "../sdk-coin-hbar"
},
{
"path": "../sdk-coin-icp"
},
{
"path": "../sdk-coin-injective"
},
Expand Down
4 changes: 4 additions & 0 deletions modules/sdk-coin-icp/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.idea
public
dist
3 changes: 3 additions & 0 deletions modules/sdk-coin-icp/.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-icp/.mocharc.yml
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']
14 changes: 14 additions & 0 deletions modules/sdk-coin-icp/.npmignore
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
2 changes: 2 additions & 0 deletions modules/sdk-coin-icp/.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-icp/.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-icp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-icp

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-icp`.

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

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 { Icp } from '@bitgo/sdk-coin-icp';

const sdk = new BitGoAPI();

sdk.register('icp', Icp.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.
50 changes: 50 additions & 0 deletions modules/sdk-coin-icp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@bitgo/sdk-coin-icp",
"version": "1.0.0",
"description": "BitGo SDK coin library for Internet Computer",
"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 <sdkteam@bitgo.com>",
"license": "MIT",
"engines": {
"node": ">=18 <21"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-icp"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/sdk-core": "^28.19.0",
"@bitgo/statics": "^50.18.0"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.58.0",
"@bitgo/sdk-test": "^8.0.63"
}
}
92 changes: 92 additions & 0 deletions modules/sdk-coin-icp/src/icp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
BaseCoin,
BitGoBase,
MPCAlgorithm,
VerifyTransactionOptions,
TssVerifyAddressOptions,
ParseTransactionOptions,
ParsedTransaction,
KeyPair,
SignTransactionOptions,
SignedTransaction,
} from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';

export class Icp extends BaseCoin {
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo);

if (!staticsCoin) {
throw new Error('missing required constructor parameter staticsCoin');
}

this._staticsCoin = staticsCoin;
}

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

getChain(): string {
return 'icp';
}

getBaseChain(): string {
return 'icp';
}

getFamily(): string {
return 'icp';
}

getFullName(): string {
return 'Internet Computer';
}

getBaseFactor(): number {
return Math.pow(10, this._staticsCoin.decimalPlaces);
}

async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
return true;
}

async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
return true;
}

async parseTransaction(params: ParseTransactionOptions): Promise<ParsedTransaction> {
return {};
}

generateKeyPair(seed?: Buffer): KeyPair {
throw new Error('Method not implemented.');
}

isValidAddress(address: string): boolean {
throw new Error('Method not implemented.');
}

signTransaction(_: SignTransactionOptions): Promise<SignedTransaction> {
throw new Error('Method not implemented.');
}

isValidPub(_: string): boolean {
throw new Error('Method not implemented.');
}

isValidPrv(_: string): boolean {
throw new Error('Method not implemented.');
}

/** @inheritDoc */
supportsTss(): boolean {
return true;
}

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}
}
4 changes: 4 additions & 0 deletions modules/sdk-coin-icp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib';
export * from './icp';
export * from './ticp';
export * from './register';
5 changes: 5 additions & 0 deletions modules/sdk-coin-icp/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as Utils from './utils';

export { TransactionBuilder } from './transactionBuilder';
export { TransferBuilder } from './transferBuilder';
export { Utils };
Loading

0 comments on commit 07db88f

Please sign in to comment.