From 3c1ab3543594ccd5f7de9e44ee8ae8393abf0dd7 Mon Sep 17 00:00:00 2001 From: N V Rakesh Reddy Date: Thu, 9 Jan 2025 18:01:20 +0530 Subject: [PATCH] chore(abstract-substrate): add abstract-substrate skeleton TICKET: WIN-4291 --- CODEOWNERS | 1 + Dockerfile | 3 + modules/abstract-substrate/.eslintignore | 5 + modules/abstract-substrate/.gitignore | 3 + modules/abstract-substrate/.mocharc.yml | 8 ++ modules/abstract-substrate/.npmignore | 12 +++ modules/abstract-substrate/.prettierignore | 2 + modules/abstract-substrate/.prettierrc.yml | 3 + modules/abstract-substrate/CHANGELOG.md | 0 modules/abstract-substrate/README.md | 1 + modules/abstract-substrate/package.json | 44 ++++++++ .../src/abstractSubstrateCoin.ts | 102 ++++++++++++++++++ modules/abstract-substrate/src/index.ts | 1 + modules/abstract-substrate/tsconfig.json | 23 ++++ tsconfig.packages.json | 3 + 15 files changed, 211 insertions(+) create mode 100644 modules/abstract-substrate/.eslintignore create mode 100644 modules/abstract-substrate/.gitignore create mode 100644 modules/abstract-substrate/.mocharc.yml create mode 100644 modules/abstract-substrate/.npmignore create mode 100644 modules/abstract-substrate/.prettierignore create mode 100644 modules/abstract-substrate/.prettierrc.yml create mode 100644 modules/abstract-substrate/CHANGELOG.md create mode 100644 modules/abstract-substrate/README.md create mode 100644 modules/abstract-substrate/package.json create mode 100644 modules/abstract-substrate/src/abstractSubstrateCoin.ts create mode 100644 modules/abstract-substrate/src/index.ts create mode 100644 modules/abstract-substrate/tsconfig.json diff --git a/CODEOWNERS b/CODEOWNERS index 61c0edb3d2..5f46ff10c3 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -45,6 +45,7 @@ # All other coins /modules/abstract-cosmos/ @BitGo/ethalt-team +/modules/abstract-substrate/ @BitGo/ethalt-team /modules/sdk-coin-ada/ @BitGo/ethalt-team /modules/sdk-coin-algo/ @BitGo/ethalt-team /modules/sdk-coin-apt/ @Bitgo/ethalt-team diff --git a/Dockerfile b/Dockerfile index 7d7bb89f87..e54a64b794 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,6 +61,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-arbeth /var/modules/sdk-coin-arb COPY --from=builder /tmp/bitgo/modules/abstract-eth /var/modules/abstract-eth/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-atom /var/modules/sdk-coin-atom/ COPY --from=builder /tmp/bitgo/modules/abstract-cosmos /var/modules/abstract-cosmos/ +COPY --from=builder /tmp/bitgo/modules/abstract-substrate /var/modules/abstract-substrate/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-avaxc /var/modules/sdk-coin-avaxc/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-avaxp /var/modules/sdk-coin-avaxp/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-eth /var/modules/sdk-coin-eth/ @@ -136,6 +137,7 @@ cd /var/modules/sdk-coin-arbeth && yarn link && \ cd /var/modules/abstract-eth && yarn link && \ cd /var/modules/sdk-coin-atom && yarn link && \ cd /var/modules/abstract-cosmos && yarn link && \ +cd /var/modules/abstract-substrate && yarn link && \ cd /var/modules/sdk-coin-avaxc && yarn link && \ cd /var/modules/sdk-coin-avaxp && yarn link && \ cd /var/modules/sdk-coin-eth && yarn link && \ @@ -214,6 +216,7 @@ RUN cd /var/bitgo-express && \ yarn link @bitgo/abstract-eth && \ yarn link @bitgo/sdk-coin-atom && \ yarn link @bitgo/abstract-cosmos && \ + yarn link @bitgo/abstract-substrate && \ yarn link @bitgo/sdk-coin-avaxc && \ yarn link @bitgo/sdk-coin-avaxp && \ yarn link @bitgo/sdk-coin-eth && \ diff --git a/modules/abstract-substrate/.eslintignore b/modules/abstract-substrate/.eslintignore new file mode 100644 index 0000000000..c4c8af8b66 --- /dev/null +++ b/modules/abstract-substrate/.eslintignore @@ -0,0 +1,5 @@ +node_modules +.idea +public +dist +resources diff --git a/modules/abstract-substrate/.gitignore b/modules/abstract-substrate/.gitignore new file mode 100644 index 0000000000..67ccce4c64 --- /dev/null +++ b/modules/abstract-substrate/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +.idea/ +dist/ diff --git a/modules/abstract-substrate/.mocharc.yml b/modules/abstract-substrate/.mocharc.yml new file mode 100644 index 0000000000..95814796d1 --- /dev/null +++ b/modules/abstract-substrate/.mocharc.yml @@ -0,0 +1,8 @@ +require: 'ts-node/register' +timeout: '60000' +reporter: 'min' +reporter-option: + - 'cdn=true' + - 'json=false' +exit: true +spec: ['test/unit/**/*.ts'] diff --git a/modules/abstract-substrate/.npmignore b/modules/abstract-substrate/.npmignore new file mode 100644 index 0000000000..7df125fca2 --- /dev/null +++ b/modules/abstract-substrate/.npmignore @@ -0,0 +1,12 @@ +!dist/ +.idea/ +.prettierrc.yml +tsconfig.json +src/ +test/ +scripts/ +.nyc_output +CODEOWNERS +node_modules/ +.prettierignore +.mocharc.js diff --git a/modules/abstract-substrate/.prettierignore b/modules/abstract-substrate/.prettierignore new file mode 100644 index 0000000000..3a11d6af29 --- /dev/null +++ b/modules/abstract-substrate/.prettierignore @@ -0,0 +1,2 @@ +.nyc_output/ +dist/ diff --git a/modules/abstract-substrate/.prettierrc.yml b/modules/abstract-substrate/.prettierrc.yml new file mode 100644 index 0000000000..7c3d8dd32a --- /dev/null +++ b/modules/abstract-substrate/.prettierrc.yml @@ -0,0 +1,3 @@ +printWidth: 120 +singleQuote: true +trailingComma: 'es5' diff --git a/modules/abstract-substrate/CHANGELOG.md b/modules/abstract-substrate/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/modules/abstract-substrate/README.md b/modules/abstract-substrate/README.md new file mode 100644 index 0000000000..31e432b9e9 --- /dev/null +++ b/modules/abstract-substrate/README.md @@ -0,0 +1 @@ +# BitGo abstract-substrate diff --git a/modules/abstract-substrate/package.json b/modules/abstract-substrate/package.json new file mode 100644 index 0000000000..b0205193df --- /dev/null +++ b/modules/abstract-substrate/package.json @@ -0,0 +1,44 @@ +{ + "name": "@bitgo/abstract-substrate", + "version": "1.0.0", + "description": "BitGo SDK coin library for Substrate base implementation", + "main": "./dist/src/index.js", + "types": "./dist/src/index.d.ts", + "scripts": { + "build": "npm run prepare", + "build-ts": "yarn tsc --build --incremental --verbose .", + "fmt": "prettier --write .", + "check-fmt": "prettier --check .", + "clean": "rm -r ./dist", + "lint": "eslint --quiet .", + "prepare": "npm run build-ts" + }, + "author": "BitGo SDK Team ", + "license": "MIT", + "engines": { + "node": ">=18 <21" + }, + "repository": { + "type": "git", + "url": "https://github.com/BitGo/BitGoJS.git", + "directory": "modules/abstract-substrate" + }, + "lint-staged": { + "*.{js,ts}": [ + "yarn prettier --write", + "yarn eslint --fix" + ] + }, + "publishConfig": { + "access": "public" + }, + "nyc": { + "extension": [ + ".ts" + ] + }, + "dependencies": { + "@bitgo/sdk-core": "^28.18.0", + "@bitgo/statics": "^50.17.0" + } +} diff --git a/modules/abstract-substrate/src/abstractSubstrateCoin.ts b/modules/abstract-substrate/src/abstractSubstrateCoin.ts new file mode 100644 index 0000000000..6d9c86fc37 --- /dev/null +++ b/modules/abstract-substrate/src/abstractSubstrateCoin.ts @@ -0,0 +1,102 @@ +import { + BaseCoin, + BitGoBase, + KeyPair, + MPCAlgorithm, + ParsedTransaction, + ParseTransactionOptions, + SignedTransaction, + SignTransactionOptions, + VerifyAddressOptions, + VerifyTransactionOptions, +} from '@bitgo/sdk-core'; +import { BaseCoin as StaticsBaseCoin, CoinFamily } from '@bitgo/statics'; + +export class SubstrateCoin extends BaseCoin { + protected readonly _staticsCoin: Readonly; + protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly) { + super(bitgo); + + if (!staticsCoin) { + throw new Error('missing required constructor parameter staticsCoin'); + } + + this._staticsCoin = staticsCoin; + } + + static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly): BaseCoin { + return new SubstrateCoin(bitgo, staticsCoin); + } + + /** + * Creates an instance of TransactionBuilderFactory for the coin specific sdk + */ + getBuilder(): any { + throw new Error('Method not implemented.'); + } + + /** @inheritDoc **/ + getBaseFactor(): string | number { + throw new Error('Method not implemented'); + } + + /** @inheritDoc **/ + getChain(): string { + return this._staticsCoin.name; + } + + /** @inheritDoc **/ + getFamily(): CoinFamily { + return this._staticsCoin.family; + } + + /** @inheritDoc **/ + getFullName(): string { + return this._staticsCoin.fullName; + } + + /** @inheritDoc */ + supportsTss(): boolean { + return true; + } + + /** @inheritDoc **/ + getMPCAlgorithm(): MPCAlgorithm { + return 'eddsa'; + } + + /** @inheritDoc **/ + generateKeyPair(seed?: Buffer): KeyPair { + throw new Error('Method not implemented'); + } + + /** @inheritDoc **/ + isValidPub(pub: string): boolean { + throw new Error('Method not implemented'); + } + + /** @inheritDoc **/ + isWalletAddress(params: VerifyAddressOptions): Promise { + throw new Error('Method not implemented'); + } + + /** @inheritDoc **/ + parseTransaction(params: ParseTransactionOptions): Promise { + throw new Error('Method not implemented'); + } + + /** @inheritDoc **/ + verifyTransaction(params: VerifyTransactionOptions): Promise { + throw new Error('Method not implemented'); + } + + /** @inheritDoc **/ + isValidAddress(address: string): boolean { + throw new Error('Method not implemented.'); + } + + /** @inheritDoc **/ + signTransaction(params: SignTransactionOptions): Promise { + throw new Error('Method not implemented.'); + } +} diff --git a/modules/abstract-substrate/src/index.ts b/modules/abstract-substrate/src/index.ts new file mode 100644 index 0000000000..6c0f84a8dc --- /dev/null +++ b/modules/abstract-substrate/src/index.ts @@ -0,0 +1 @@ +export { SubstrateCoin } from './abstractSubstrateCoin'; diff --git a/modules/abstract-substrate/tsconfig.json b/modules/abstract-substrate/tsconfig.json new file mode 100644 index 0000000000..cb6a620eb2 --- /dev/null +++ b/modules/abstract-substrate/tsconfig.json @@ -0,0 +1,23 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./", + "strictPropertyInitialization": false, + "esModuleInterop": true, + "typeRoots": ["../../types", "./node_modules/@types", "../../node_modules/@types"] + }, + "include": ["src/**/*", "resources/**/*"], + "exclude": ["node_modules"], + "references": [ + { + "path": "../sdk-core" + }, + { + "path": "../statics" + }, + { + "path": "../utxo-lib" + } + ] +} diff --git a/tsconfig.packages.json b/tsconfig.packages.json index 46b591d78e..a4b9249737 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -4,6 +4,9 @@ { "path": "./modules/abstract-cosmos" }, + { + "path": "./modules/abstract-substrate" + }, { "path": "./modules/abstract-eth" },