Skip to content
Merged
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-tempo/.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-tempo/.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-tempo/.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-tempo/.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-tempo/.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-tempo/.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-tempo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-tempo

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

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

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

const sdk = new BitGoAPI();

sdk.register('tempo', Tempo.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.
53 changes: 53 additions & 0 deletions modules/sdk-coin-tempo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@bitgo/sdk-coin-tempo",
"version": "1.0.0",
"description": "BitGo SDK coin library for Tempo",
"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 <23"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-tempo"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/sdk-core": "^36.23.1",
"@bitgo/statics": "^58.16.1"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.71.9",
"@bitgo/sdk-test": "^9.1.17"
},
"files": [
"dist"
]
}
4 changes: 4 additions & 0 deletions modules/sdk-coin-tempo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib';
export * from './tempo';
export * from './ttempo';
export * from './register';
9 changes: 9 additions & 0 deletions modules/sdk-coin-tempo/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Constants for Tempo
*/

export const MAINNET_COIN = 'tempo';
export const TESTNET_COIN = 'ttempo';

export const VALID_ADDRESS_REGEX = /^[A-Za-z0-9]+$/; // Update with actual address format
export const VALID_PUBLIC_KEY_REGEX = /^[A-Fa-f0-9]{64}$/; // Update with actual public key format
18 changes: 18 additions & 0 deletions modules/sdk-coin-tempo/src/lib/iface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Interfaces for Tempo
*/

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface TransactionData {
// TODO: Define transaction data structure
}

export interface TransactionOutput {
address: string;
amount: string;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface TransactionInput {
// TODO: Define transaction input structure
}
4 changes: 4 additions & 0 deletions modules/sdk-coin-tempo/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './keyPair';
export * from './utils';
export * from './constants';
export * from './iface';
67 changes: 67 additions & 0 deletions modules/sdk-coin-tempo/src/lib/keyPair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { DefaultKeys, isPrivateKey, isPublicKey, isSeed, KeyPairOptions } from '@bitgo/sdk-core';
import * as crypto from 'crypto';

/**
* Tempo keys and address management
*/
export class KeyPair {
private keyPair: DefaultKeys;

/**
* Public constructor. By default, creates a key pair with a random master seed.
*
* @param { KeyPairOptions } source Either a master seed, a private key, or a public key
*/
constructor(source?: KeyPairOptions) {
let seed: Buffer;

if (!source) {
seed = crypto.randomBytes(32);
} else if (isSeed(source)) {
seed = source.seed;
} else if (isPrivateKey(source)) {
// TODO: Implement private key to keypair conversion
throw new Error('Private key import not yet implemented');
} else if (isPublicKey(source)) {
// TODO: Implement public key import
throw new Error('Public key import not yet implemented');
} else {
throw new Error('Invalid key pair options');
}

// TODO: Generate actual keypair from seed based on the coin's key derivation
this.keyPair = this.generateKeyPairFromSeed(seed);
}

/**
* Generate a keypair from a seed
* @param seed
* @private
*/
private generateKeyPairFromSeed(seed: Buffer): DefaultKeys {
// TODO: Implement actual key generation for Tempo
// This is a placeholder implementation
const prv = seed.toString('hex');
const pub = crypto.createHash('sha256').update(seed).digest('hex');

return {
prv,
pub,
};
}

/**
* Get the public key
*/
getKeys(): DefaultKeys {
return this.keyPair;
}

/**
* Get the address
*/
getAddress(): string {
// TODO: Implement address derivation from public key
return this.keyPair.pub;
}
}
40 changes: 40 additions & 0 deletions modules/sdk-coin-tempo/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { VALID_ADDRESS_REGEX, VALID_PUBLIC_KEY_REGEX } from './constants';

/**
* Utility functions for Tempo
*/

/**
* Check if the address is valid
* @param address
*/
export function isValidAddress(address: string): boolean {
// TODO: Implement proper address validation for Tempo
return VALID_ADDRESS_REGEX.test(address);
}

/**
* Check if the public key is valid
* @param publicKey
*/
export function isValidPublicKey(publicKey: string): boolean {
// TODO: Implement proper public key validation for Tempo
return VALID_PUBLIC_KEY_REGEX.test(publicKey);
}

/**
* Check if the private key is valid
* @param privateKey
*/
export function isValidPrivateKey(privateKey: string): boolean {
// TODO: Implement proper private key validation for Tempo
return privateKey.length === 64;
}

const utils = {
isValidAddress,
isValidPublicKey,
isValidPrivateKey,
};

export default utils;
8 changes: 8 additions & 0 deletions modules/sdk-coin-tempo/src/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BitGoBase } from '@bitgo/sdk-core';
import { Tempo } from './tempo';
import { Ttempo } from './ttempo';

export const register = (sdk: BitGoBase): void => {
sdk.register('tempo', Tempo.createInstance);
sdk.register('ttempo', Ttempo.createInstance);
};
Loading