diff --git a/Dockerfile b/Dockerfile index c6cd813a33..c9fde2693e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -123,6 +123,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-bsv /var/modules/sdk-coin-bsv/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-btc /var/modules/sdk-coin-btc/ COPY --from=builder /tmp/bitgo/modules/utxo-ord /var/modules/utxo-ord/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-btg /var/modules/sdk-coin-btg/ +COPY --from=builder /tmp/bitgo/modules/sdk-coin-canton /var/modules/sdk-coin-canton/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-dash /var/modules/sdk-coin-dash/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-doge /var/modules/sdk-coin-doge/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-eos /var/modules/sdk-coin-eos/ @@ -219,6 +220,7 @@ cd /var/modules/sdk-coin-bsv && yarn link && \ cd /var/modules/sdk-coin-btc && yarn link && \ cd /var/modules/utxo-ord && yarn link && \ cd /var/modules/sdk-coin-btg && yarn link && \ +cd /var/modules/sdk-coin-canton && yarn link && \ cd /var/modules/sdk-coin-dash && yarn link && \ cd /var/modules/sdk-coin-doge && yarn link && \ cd /var/modules/sdk-coin-eos && yarn link && \ @@ -318,6 +320,7 @@ RUN cd /var/bitgo-express && \ yarn link @bitgo/sdk-coin-btc && \ yarn link @bitgo/utxo-ord && \ yarn link @bitgo/sdk-coin-btg && \ + yarn link @bitgo/sdk-coin-canton && \ yarn link @bitgo/sdk-coin-dash && \ yarn link @bitgo/sdk-coin-doge && \ yarn link @bitgo/sdk-coin-eos && \ diff --git a/modules/bitgo/package.json b/modules/bitgo/package.json index 0ac7d0485b..2e209c53ae 100644 --- a/modules/bitgo/package.json +++ b/modules/bitgo/package.json @@ -67,6 +67,7 @@ "@bitgo/sdk-coin-bsv": "^2.4.2", "@bitgo/sdk-coin-btc": "^2.9.1", "@bitgo/sdk-coin-btg": "^2.4.2", + "@bitgo/sdk-coin-canton": "^1.0.0", "@bitgo/sdk-coin-celo": "^5.3.2", "@bitgo/sdk-coin-coredao": "^2.6.2", "@bitgo/sdk-coin-coreum": "^21.5.2", diff --git a/modules/bitgo/src/v2/coinFactory.ts b/modules/bitgo/src/v2/coinFactory.ts index 174306bfe4..607d7d9198 100644 --- a/modules/bitgo/src/v2/coinFactory.ts +++ b/modules/bitgo/src/v2/coinFactory.ts @@ -62,6 +62,7 @@ import { Bsv, Btc, Btg, + Canton, Celo, CeloToken, Coredao, @@ -149,6 +150,7 @@ import { Tbtcsig, Tbtc4, Tbtcbgsig, + Tcanton, Tcelo, Tcoredao, Tcoreum, @@ -241,6 +243,7 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin coinFactory.register('bsv', Bsv.createInstance); coinFactory.register('btc', Btc.createInstance); coinFactory.register('btg', Btg.createInstance); + coinFactory.register('canton', Canton.createInstance); coinFactory.register('celo', Celo.createInstance); coinFactory.register('coredao', Coredao.createInstance); coinFactory.register('coreum', Coreum.createInstance); @@ -605,6 +608,8 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine return Btc.createInstance; case 'btg': return Btg.createInstance; + case 'canton': + return Canton.createInstance; case 'celo': return Celo.createInstance; case 'coredao': @@ -747,6 +752,8 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine return Tbtc4.createInstance; case 'tbtcbgsig': return Tbtcbgsig.createInstance; + case 'tcanton': + return Tcanton.createInstance; case 'tcelo': return Tcelo.createInstance; case 'tcoredao': diff --git a/modules/bitgo/src/v2/coins/index.ts b/modules/bitgo/src/v2/coins/index.ts index f7d7525e8f..010a179d9f 100644 --- a/modules/bitgo/src/v2/coins/index.ts +++ b/modules/bitgo/src/v2/coins/index.ts @@ -18,6 +18,7 @@ import { Bsc, BscToken, Tbsc } from '@bitgo/sdk-coin-bsc'; import { Bsv, Tbsv } from '@bitgo/sdk-coin-bsv'; import { Btc, Tbtc, Tbtcsig, Tbtc4, Tbtcbgsig } from '@bitgo/sdk-coin-btc'; import { Btg } from '@bitgo/sdk-coin-btg'; +import { Canton, Tcanton } from '@bitgo/sdk-coin-canton'; import { Celo, CeloToken, Tcelo } from '@bitgo/sdk-coin-celo'; import { Coredao, Tcoredao, CoredaoToken } from '@bitgo/sdk-coin-coredao'; import { Coreum, Tcoreum } from '@bitgo/sdk-coin-coreum'; @@ -91,6 +92,7 @@ export { Bsc, BscToken, Tbsc }; export { Bsv, Tbsv }; export { Btc, Tbtc, Tbtcsig, Tbtc4, Tbtcbgsig }; export { Btg }; +export { Canton, Tcanton }; export { Celo, CeloToken, Tcelo }; export { Coredao, Tcoredao, CoredaoToken }; export { Coreum, Tcoreum }; diff --git a/modules/bitgo/test/browser/browser.spec.ts b/modules/bitgo/test/browser/browser.spec.ts index 68dcc018b2..9ab6f508f8 100644 --- a/modules/bitgo/test/browser/browser.spec.ts +++ b/modules/bitgo/test/browser/browser.spec.ts @@ -58,6 +58,8 @@ describe('Coins', () => { HashToken: 1, FlrToken: 1, JettonToken: 1, + Canton: 1, + Tcanton: 1, }; Object.keys(BitGoJS.Coin) .filter((coinName) => !excludedKeys[coinName]) diff --git a/modules/bitgo/tsconfig.json b/modules/bitgo/tsconfig.json index 3bdc17681c..29f7f5939d 100644 --- a/modules/bitgo/tsconfig.json +++ b/modules/bitgo/tsconfig.json @@ -113,6 +113,9 @@ { "path": "../sdk-coin-btg" }, + { + "path": "../sdk-coin-canton" + }, { "path": "../sdk-coin-celo" }, diff --git a/modules/sdk-coin-canton/.eslintignore b/modules/sdk-coin-canton/.eslintignore new file mode 100644 index 0000000000..190f83e0df --- /dev/null +++ b/modules/sdk-coin-canton/.eslintignore @@ -0,0 +1,5 @@ +node_modules +.idea +public +dist + diff --git a/modules/sdk-coin-canton/.gitignore b/modules/sdk-coin-canton/.gitignore new file mode 100644 index 0000000000..67ccce4c64 --- /dev/null +++ b/modules/sdk-coin-canton/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +.idea/ +dist/ diff --git a/modules/sdk-coin-canton/.mocharc.yml b/modules/sdk-coin-canton/.mocharc.yml new file mode 100644 index 0000000000..f499ec0a83 --- /dev/null +++ b/modules/sdk-coin-canton/.mocharc.yml @@ -0,0 +1,8 @@ +require: 'tsx' +timeout: '60000' +reporter: 'min' +reporter-option: + - 'cdn=true' + - 'json=false' +exit: true +spec: ['test/unit/**/*.ts'] diff --git a/modules/sdk-coin-canton/.npmignore b/modules/sdk-coin-canton/.npmignore new file mode 100644 index 0000000000..d5fb3a098c --- /dev/null +++ b/modules/sdk-coin-canton/.npmignore @@ -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 diff --git a/modules/sdk-coin-canton/.prettierignore b/modules/sdk-coin-canton/.prettierignore new file mode 100644 index 0000000000..3a11d6af29 --- /dev/null +++ b/modules/sdk-coin-canton/.prettierignore @@ -0,0 +1,2 @@ +.nyc_output/ +dist/ diff --git a/modules/sdk-coin-canton/.prettierrc.yml b/modules/sdk-coin-canton/.prettierrc.yml new file mode 100644 index 0000000000..7c3d8dd32a --- /dev/null +++ b/modules/sdk-coin-canton/.prettierrc.yml @@ -0,0 +1,3 @@ +printWidth: 120 +singleQuote: true +trailingComma: 'es5' diff --git a/modules/sdk-coin-canton/README.md b/modules/sdk-coin-canton/README.md new file mode 100644 index 0000000000..97f7d3c6af --- /dev/null +++ b/modules/sdk-coin-canton/README.md @@ -0,0 +1,30 @@ +# BitGo sdk-coin-canton + +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-canton`. + +```shell +npm i @bitgo/sdk-api @bitgo/sdk-coin-canton +``` + +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 { Canton } from '@bitgo/sdk-coin-canton'; + +const sdk = new BitGoAPI(); + +sdk.register('canton', Canton.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. diff --git a/modules/sdk-coin-canton/package.json b/modules/sdk-coin-canton/package.json new file mode 100644 index 0000000000..47bc8d13cf --- /dev/null +++ b/modules/sdk-coin-canton/package.json @@ -0,0 +1,52 @@ +{ + "name": "@bitgo/sdk-coin-canton", + "version": "1.0.0", + "description": "BitGo SDK coin library for Canton", + "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 ", + "license": "MIT", + "engines": { + "node": ">=20 <23" + }, + "repository": { + "type": "git", + "url": "https://github.com/BitGo/BitGoJS.git", + "directory": "modules/sdk-coin-canton" + }, + "lint-staged": { + "*.{js,ts}": [ + "yarn prettier --write", + "yarn eslint --fix" + ] + }, + "publishConfig": { + "access": "public" + }, + "nyc": { + "extension": [ + ".ts" + ] + }, + "dependencies": { + "@bitgo/sdk-core": "^36.10.1", + "@bitgo/statics": "^58.2.0", + "bignumber.js": "^9.1.1" + }, + "devDependencies": { + "@bitgo/sdk-api": "^1.69.2", + "@bitgo/sdk-lib-mpc": "^10.7.0", + "@bitgo/sdk-test": "^9.1.2" + } +} diff --git a/modules/sdk-coin-canton/src/canton.ts b/modules/sdk-coin-canton/src/canton.ts new file mode 100644 index 0000000000..3ddcc16e58 --- /dev/null +++ b/modules/sdk-coin-canton/src/canton.ts @@ -0,0 +1,112 @@ +import { + AuditDecryptedKeyParams, + BaseCoin, + BitGoBase, + KeyPair, + MPCAlgorithm, + MultisigType, + multisigTypes, + ParsedTransaction, + ParseTransactionOptions, + SignedTransaction, + SignTransactionOptions, + VerifyAddressOptions, + VerifyTransactionOptions, +} from '@bitgo/sdk-core'; +import { auditEddsaPrivateKey } from '@bitgo/sdk-lib-mpc'; +import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; + +export class Canton 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 Canton(bitgo, staticsCoin); + } + + /** @inheritDoc */ + public getBaseFactor(): number { + return 1e10; + } + + /** @inheritDoc */ + public getChain(): string { + return 'canton'; + } + + /** @inheritDoc */ + public getFamily(): string { + return 'canton'; + } + + /** @inheritDoc */ + public getFullName(): string { + return 'Canton'; + } + + /** @inheritDoc */ + supportsTss(): boolean { + return true; + } + + /** inherited doc */ + getDefaultMultisigType(): MultisigType { + return multisigTypes.tss; + } + + getMPCAlgorithm(): MPCAlgorithm { + return 'eddsa'; + } + + /** @inheritDoc */ + verifyTransaction(params: VerifyTransactionOptions): Promise { + 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 */ + generateKeyPair(seed?: Buffer): KeyPair { + throw new Error('Method not implemented.'); + } + + /** @inheritDoc */ + isValidPub(pub: string): boolean { + 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.'); + } + + /** @inheritDoc */ + auditDecryptedKey({ multiSigType, prv, publicKey }: AuditDecryptedKeyParams): void { + if (multiSigType !== 'tss') { + throw new Error('Unsupported multiSigType'); + } + auditEddsaPrivateKey(prv, publicKey ?? ''); + } +} diff --git a/modules/sdk-coin-canton/src/index.ts b/modules/sdk-coin-canton/src/index.ts new file mode 100644 index 0000000000..2fca65df0b --- /dev/null +++ b/modules/sdk-coin-canton/src/index.ts @@ -0,0 +1,3 @@ +export * from './lib'; +export * from './canton'; +export * from './tcanton'; diff --git a/modules/sdk-coin-canton/src/lib/iface.ts b/modules/sdk-coin-canton/src/lib/iface.ts new file mode 100644 index 0000000000..546ef821e8 --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/iface.ts @@ -0,0 +1,6 @@ +/** + * The transaction data returned from the toJson() function of a transaction + */ +export interface TxData { + id: string; +} diff --git a/modules/sdk-coin-canton/src/lib/index.ts b/modules/sdk-coin-canton/src/lib/index.ts new file mode 100644 index 0000000000..5bc4433ac6 --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/index.ts @@ -0,0 +1,9 @@ +import * as Utils from './utils'; +import * as Interface from './iface'; + +export { KeyPair } from './keyPair'; +export { Transaction } from './transaction'; +export { TransactionBuilder } from './transactionBuilder'; +export { TransactionBuilderFactory } from './transactionBuilderFactory'; + +export { Utils, Interface }; diff --git a/modules/sdk-coin-canton/src/lib/keyPair.ts b/modules/sdk-coin-canton/src/lib/keyPair.ts new file mode 100644 index 0000000000..bb4449c74a --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/keyPair.ts @@ -0,0 +1,23 @@ +import { DefaultKeys, Ed25519KeyPair } from '@bitgo/sdk-core'; + +export class KeyPair extends Ed25519KeyPair { + /** @inheritdoc */ + getKeys(): DefaultKeys { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + recordKeysFromPrivateKeyInProtocolFormat(prv: string): DefaultKeys { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + recordKeysFromPublicKeyInProtocolFormat(pub: string): DefaultKeys { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + getAddress(): string { + throw new Error('Method not implemented.'); + } +} diff --git a/modules/sdk-coin-canton/src/lib/transaction.ts b/modules/sdk-coin-canton/src/lib/transaction.ts new file mode 100644 index 0000000000..431c397b49 --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/transaction.ts @@ -0,0 +1,16 @@ +import { BaseKey, BaseTransaction } from '@bitgo/sdk-core'; +import { TxData } from './iface'; + +export class Transaction extends BaseTransaction { + canSign(key: BaseKey): boolean { + return false; + } + + toBroadcastFormat(): string { + throw new Error('Method not implemented.'); + } + + toJson(): TxData { + throw new Error('Method not implemented.'); + } +} diff --git a/modules/sdk-coin-canton/src/lib/transactionBuilder.ts b/modules/sdk-coin-canton/src/lib/transactionBuilder.ts new file mode 100644 index 0000000000..f9adeb2eda --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/transactionBuilder.ts @@ -0,0 +1,99 @@ +import { + BaseAddress, + BaseKey, + BaseTransactionBuilder, + BuildTransactionError, + FeeOptions, + PublicKey as BasePublicKey, + Signature, + TransactionType, +} from '@bitgo/sdk-core'; +import BigNumber from 'bignumber.js'; +import { Transaction } from './transaction'; +import utils from './utils'; + +export abstract class TransactionBuilder extends BaseTransactionBuilder { + protected _transaction: Transaction; + private _signatures: Signature[] = []; + + // get and set region + /** + * The transaction type. + */ + protected abstract get transactionType(): TransactionType; + + /** @inheritdoc */ + protected get transaction(): Transaction { + return this._transaction; + } + + /** @inheritdoc */ + protected set transaction(transaction: Transaction) { + this._transaction = transaction; + } + + /** @inheritdoc */ + protected signImplementation(key: BaseKey): Transaction { + throw new Error('Method not implemented.'); + } + + /** @inheritDoc */ + addSignature(publicKey: BasePublicKey, signature: Buffer): void { + this._signatures.push({ publicKey, signature }); + } + + /** + * Sets the sender of this transaction. + * This account will be responsible for paying transaction fees. + * + * @param {string} senderAddress the account that is sending this transaction + * @returns {TransactionBuilder} This transaction builder + */ + sender(senderAddress: string): this { + throw new Error('Method not implemented.'); + } + + fee(feeOptions: FeeOptions): this { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + protected fromImplementation(rawTransaction: string): Transaction { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + protected async buildImplementation(): Promise { + throw new Error('Method not implemented.'); + } + + // region Validators + /** @inheritdoc */ + validateAddress(address: BaseAddress, addressFormat?: string): void { + if (!utils.isValidAddress(address.address)) { + throw new BuildTransactionError('Invalid address ' + address.address); + } + } + + /** @inheritdoc */ + validateKey(key: BaseKey): void { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + validateRawTransaction(rawTransaction: string): void { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + validateTransaction(transaction?: Transaction): void { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + validateValue(value: BigNumber): void { + if (value.isLessThan(0)) { + throw new BuildTransactionError('Value cannot be less than zero'); + } + } +} diff --git a/modules/sdk-coin-canton/src/lib/transactionBuilderFactory.ts b/modules/sdk-coin-canton/src/lib/transactionBuilderFactory.ts new file mode 100644 index 0000000000..b963ec4b4d --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/transactionBuilderFactory.ts @@ -0,0 +1,20 @@ +import { BaseTransactionBuilderFactory } from '@bitgo/sdk-core'; +import { TransactionBuilder } from './transactionBuilder'; +import { TransferBuilder } from './transferBuilder'; + +export class TransactionBuilderFactory extends BaseTransactionBuilderFactory { + /** @inheritdoc */ + from(raw: string): TransactionBuilder { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + getTransferBuilder(): TransferBuilder { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + getWalletInitializationBuilder(): void { + throw new Error('Method not implemented.'); + } +} diff --git a/modules/sdk-coin-canton/src/lib/transferBuilder.ts b/modules/sdk-coin-canton/src/lib/transferBuilder.ts new file mode 100644 index 0000000000..e57cedf7c9 --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/transferBuilder.ts @@ -0,0 +1,13 @@ +import { TransactionType } from '@bitgo/sdk-core'; +import { BaseCoin as CoinConfig } from '@bitgo/statics'; +import { TransactionBuilder } from './transactionBuilder'; + +export class TransferBuilder extends TransactionBuilder { + constructor(_coinConfig: Readonly) { + super(_coinConfig); + } + + protected get transactionType(): TransactionType { + return TransactionType.Send; + } +} diff --git a/modules/sdk-coin-canton/src/lib/utils.ts b/modules/sdk-coin-canton/src/lib/utils.ts new file mode 100644 index 0000000000..b0cdef2405 --- /dev/null +++ b/modules/sdk-coin-canton/src/lib/utils.ts @@ -0,0 +1,37 @@ +import { BaseUtils } from '@bitgo/sdk-core'; + +export class Utils implements BaseUtils { + /** @inheritdoc */ + isValidAddress(address: string): boolean { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + isValidBlockId(hash: string): boolean { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + isValidPrivateKey(key: string): boolean { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + isValidPublicKey(key: string): boolean { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + isValidSignature(signature: string): boolean { + throw new Error('Method not implemented.'); + } + + /** @inheritdoc */ + isValidTransactionId(txId: string): boolean { + throw new Error('Method not implemented.'); + } +} + +const utils = new Utils(); + +export default utils; diff --git a/modules/sdk-coin-canton/src/register.ts b/modules/sdk-coin-canton/src/register.ts new file mode 100644 index 0000000000..f7f0d4753b --- /dev/null +++ b/modules/sdk-coin-canton/src/register.ts @@ -0,0 +1,8 @@ +import { BitGoBase } from '@bitgo/sdk-core'; +import { Canton } from './canton'; +import { Tcanton } from './tcanton'; + +export const register = (sdk: BitGoBase): void => { + sdk.register('canton', Canton.createInstance); + sdk.register('tcanton', Tcanton.createInstance); +}; diff --git a/modules/sdk-coin-canton/src/tcanton.ts b/modules/sdk-coin-canton/src/tcanton.ts new file mode 100644 index 0000000000..a7ec27c712 --- /dev/null +++ b/modules/sdk-coin-canton/src/tcanton.ts @@ -0,0 +1,34 @@ +import { BaseCoin, BitGoBase } from '@bitgo/sdk-core'; +import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; +import { Canton } from './canton'; + +export class Tcanton extends Canton { + protected readonly _staticsCoin: Readonly; + protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly) { + super(bitgo, staticsCoin); + + if (!staticsCoin) { + throw new Error('missing required constructor parameter staticsCoin'); + } + + this._staticsCoin = staticsCoin; + } + + static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly): BaseCoin { + return new Tcanton(bitgo, staticsCoin); + } + + /** + * Identifier for the blockchain which supports this coin + */ + public getChain(): string { + return 'tcanton'; + } + + /** + * Complete human-readable name of this coin + */ + public getFullName(): string { + return 'Testnet Canton'; + } +} diff --git a/modules/sdk-coin-canton/test/integration/index.ts b/modules/sdk-coin-canton/test/integration/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/modules/sdk-coin-canton/test/unit/index.ts b/modules/sdk-coin-canton/test/unit/index.ts new file mode 100644 index 0000000000..b401d09823 --- /dev/null +++ b/modules/sdk-coin-canton/test/unit/index.ts @@ -0,0 +1,15 @@ +import 'should'; +import { BitGoAPI } from '@bitgo/sdk-api'; +import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; +import { Canton, Tcanton } from '../../src'; + +describe('Canton:', function () { + let bitgo: TestBitGoAPI; + + before(function () { + bitgo = TestBitGo.decorate(BitGoAPI, { env: 'mock' }); + bitgo.safeRegister('canton', Canton.createInstance); + bitgo.safeRegister('tcanton', Tcanton.createInstance); + bitgo.initializeTestVars(); + }); +}); diff --git a/modules/sdk-coin-canton/tsconfig.json b/modules/sdk-coin-canton/tsconfig.json new file mode 100644 index 0000000000..64aeea134a --- /dev/null +++ b/modules/sdk-coin-canton/tsconfig.json @@ -0,0 +1,26 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./", + "strictPropertyInitialization": false, + "esModuleInterop": true, + "typeRoots": ["../../types", "./node_modules/@types", "../../node_modules/@types"] + }, + "include": ["src/**/*", "test/**/*"], + "exclude": ["node_modules"], + "references": [ + { + "path": "../sdk-api" + }, + { + "path": "../sdk-core" + }, + { + "path": "../statics" + }, + { + "path": "../sdk-test" + } + ] +} diff --git a/tsconfig.packages.json b/tsconfig.packages.json index ddd9935097..cbfd203ba3 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -91,6 +91,9 @@ { "path": "./modules/sdk-coin-btg" }, + { + "path": "./modules/sdk-coin-canton" + }, { "path": "./modules/sdk-coin-celo" },