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/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
]
},
"dependencies": {
"@bitgo/abstract-eth": "^24.19.4",
"@bitgo/sdk-core": "^36.25.0",
"@bitgo/secp256k1": "^1.8.0",
"@bitgo/statics": "^58.19.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-tempo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './lib';
export * from './tempo';
export * from './ttempo';
export * from './tip20Token';
export * from './register';
2 changes: 1 addition & 1 deletion modules/sdk-coin-tempo/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Constants for Tempo
* Constants for Tempo blockchain (EVM-compatible)
*/

export const MAINNET_COIN = 'tempo';
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-tempo/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './keyPair';
export * from './utils';
export * from './constants';
export * from './iface';
export * from './tip20Abi';
68 changes: 19 additions & 49 deletions modules/sdk-coin-tempo/src/lib/keyPair.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,37 @@
import { DefaultKeys, isPrivateKey, isPublicKey, isSeed, KeyPairOptions } from '@bitgo/sdk-core';
import * as crypto from 'crypto';
/**
* Tempo KeyPair - Reuses Ethereum KeyPair Implementation
*
* Since Tempo is EVM-compatible and uses the same cryptography (ECDSA/secp256k1)
* as Ethereum, we can directly reuse the Ethereum KeyPair implementation.
*/

import { bip32 } from '@bitgo/secp256k1';
import { DefaultKeys, KeyPairOptions } from '@bitgo/sdk-core';

/**
* Tempo keys and address management
* Tempo KeyPair class
* Uses same key derivation as Ethereum (BIP32 + secp256k1)
*/
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');
// TODO: Implement proper key generation when needed
const seed = Buffer.alloc(64);
const hdNode = bip32.fromSeed(seed);

return {
prv,
pub,
this.keyPair = {
prv: hdNode.toBase58(),
pub: hdNode.neutered().toBase58(),
};
}

/**
* 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;
// TODO: Implement Ethereum-style address derivation
return '0x0000000000000000000000000000000000000000';
}
}
32 changes: 32 additions & 0 deletions modules/sdk-coin-tempo/src/lib/tip20Abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* TIP20 Token Standard ABI (Skeleton)
*
* TODO: Update this file when TIP20 ABI becomes available
*/

/**
* Placeholder TIP20 ABI
* This is an empty array that should be replaced with the actual ABI
*/
export const TIP20_ABI = [] as const;

/**
* Placeholder for TIP20 Factory ABI
*/
export const TIP20_FACTORY_ABI = [] as const;

/**
* Get the method signature for TIP20 transfer
* TODO: Update with actual method name if different from ERC20
*/
export function getTip20TransferSignature(): string {
return 'transfer(address,uint256)';
}

/**
* Get the method signature for TIP20 transferFrom
* TODO: Update with actual method name if different from ERC20
*/
export function getTip20TransferFromSignature(): string {
return 'transferFrom(address,address,uint256)';
}
48 changes: 34 additions & 14 deletions modules/sdk-coin-tempo/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
import { VALID_ADDRESS_REGEX, VALID_PUBLIC_KEY_REGEX } from './constants';

/**
* Utility functions for Tempo
* Tempo Utility Functions
*
* Since Tempo is EVM-compatible, we can reuse Ethereum utilities
*/

import { bip32 } from '@bitgo/secp256k1';
import { VALID_ADDRESS_REGEX } from './constants';

/**
* Check if the address is valid
* @param address
* Check if address is valid Ethereum-style address
* TODO: Replace with ETH utils when implementing
*/
export function isValidAddress(address: string): boolean {
// TODO: Implement proper address validation for Tempo
if (typeof address !== 'string') {
return false;
}
return VALID_ADDRESS_REGEX.test(address);
}

/**
* Check if the public key is valid
* @param publicKey
* Check if public key is valid (BIP32 xpub format)
* TODO: Replace with ETH utils when implementing
*/
export function isValidPublicKey(publicKey: string): boolean {
// TODO: Implement proper public key validation for Tempo
return VALID_PUBLIC_KEY_REGEX.test(publicKey);
if (typeof publicKey !== 'string') {
return false;
}
try {
const hdNode = bip32.fromBase58(publicKey);
return hdNode.isNeutered();
} catch (e) {
return false;
}
}

/**
* Check if the private key is valid
* @param privateKey
* Check if private key is valid (BIP32 xprv format)
* TODO: Replace with ETH utils when implementing
*/
export function isValidPrivateKey(privateKey: string): boolean {
// TODO: Implement proper private key validation for Tempo
return privateKey.length === 64;
if (typeof privateKey !== 'string') {
return false;
}
try {
const hdNode = bip32.fromBase58(privateKey);
return !hdNode.isNeutered();
} catch (e) {
return false;
}
}

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

/**
* Register Tempo and TIP20 tokens with the SDK
* @param sdk - BitGo SDK instance
*/
export const register = (sdk: BitGoBase): void => {
// Register base Tempo coins
sdk.register('tempo', Tempo.createInstance);
sdk.register('ttempo', Ttempo.createInstance);

// Register TIP20 tokens (skeleton)
// TODO: Add actual token configurations from @bitgo/statics
// For now, this creates an empty array which can be populated progressively
const tip20Tokens = Tip20Token.createTokenConstructors([
// TODO: Add TIP20 token configurations here
// Example:
// {
// type: 'tempo:usdc',
// coin: 'tempo',
// network: 'Mainnet',
// name: 'USD Coin on Tempo',
// tokenContractAddress: '0x...',
// decimalPlaces: 6,
// },
]);

// Register each TIP20 token with the SDK
tip20Tokens.forEach(({ name, coinConstructor }) => {
sdk.register(name, coinConstructor);
});
};
Loading