Skip to content

Commit

Permalink
Add signed tx data to log (#105)
Browse files Browse the repository at this point in the history
* console.log() for signEthKMSTransaction added

* DEBUG_MODE added to config.ts

* DEBUG_MODE to checkConfig()

* minor

* minor

* TATUM_KMS_DEBUG_MODE set default = 0

* minor

* check if debug mode

* readme update

* package.json ver bump
  • Loading branch information
alexey-gorlitsky authored May 20, 2024
1 parent f549e9d commit 9e2d286
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ TATUM_KMS_AWS_SECRET_NAME=YOUR_KMS_SECRET_NAME
TATUM_KMS_AWS_ACCESS_KEY_ID=AKIAYWGKDBVRGMCASWIE
TATUM_KMS_AWS_SECRET_ACCESS_KEY=ZxDq62BZGyGe2CzwnVjL/IH8NnJG5Fu0isN7wev9
TATUM_KMS_AWS_SECRET_KEY=pwd
# Debug mode. if true/1, it will expose data from signEthKMSTransaction() method to the console
TATUM_KMS_DEBUG_MODE=true/false/1/0
```

### Install KMS from npm
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum-kms",
"version": "7.0.3",
"version": "7.0.4",
"description": "Tatum KMS - Key Management System for Tatum-powered apps.",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum ConfigOption {
AWS_SECRET_KEY,
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
TATUM_KMS_DEBUG_MODE,
}

export class Config {
Expand Down Expand Up @@ -75,13 +76,20 @@ export class Config {
question:
'Enter AWS Secret key from you stored secret to obtain password from AWS Secrets Manager (or set env var TATUM_KMS_AWS_SECRET_KEYa):',
},
[ConfigOption.TATUM_KMS_DEBUG_MODE]: {
environmentKey: 'TATUM_KMS_DEBUG_MODE',
question: 'Enter debug mode (true/false) (or set env var TATUM_KMS_DEBUG_MODE):',
},
}

public static getValue(what: ConfigOption): string {
const config = this._configOptions[what]
if (process.env[config.environmentKey]) {
return process.env[config.environmentKey] as string
}
if (what === ConfigOption.TATUM_KMS_DEBUG_MODE && !process.env[config.environmentKey]) {
return 'false'
}
if (what === ConfigOption.TATUM_API_KEY) {
throw new Error('Required TATUM_API_KEY is not set. Please set it as env variable or pass it as argument.')
}
Expand Down
1 change: 1 addition & 0 deletions src/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ export const checkConfig = (pwdType: PasswordType, envFile?: string, path?: stri
console.log(`TATUM_KMS_AWS_SECRET_ACCESS_KEY : ${secretValue(process.env.TATUM_KMS_AWS_SECRET_ACCESS_KEY)}`)
console.log(`TATUM_KMS_AWS_SECRET_NAME : ${secretValue(process.env.TATUM_KMS_AWS_SECRET_NAME)}`)
console.log(`TATUM_KMS_AWS_SECRET_KEY : ${secretValue(process.env.TATUM_KMS_AWS_SECRET_KEY)}`)
console.log(`TATUM_KMS_DEBUG_MODE : ${process.env.TATUM_KMS_DEBUG_MODE ?? 'N/A'}`)
}

export const setTatumKey = (apiKey: string) => {
Expand Down
7 changes: 6 additions & 1 deletion src/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ const processTransaction = async (
if (blockchainSignature.withdrawalId) {
txData = await signEthOffchainKMSTransaction(blockchainSignature, privateKey, testnet)
} else {
await ethBroadcast(await signEthKMSTransaction(blockchainSignature, privateKey), blockchainSignature.id)
const signKMSTransaction = await signEthKMSTransaction(blockchainSignature, privateKey);
const debugMode = Config.getValue(ConfigOption.TATUM_KMS_DEBUG_MODE) || 0;
if (debugMode === 'true' || debugMode === '1') {
console.log('signEthKMSTransaction data', signKMSTransaction, blockchainSignature.id)
}
await ethBroadcast(signKMSTransaction, blockchainSignature.id)
return
}
break
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"skipLibCheck": true,
"baseUrl": "./",
"lib": [
"ES2020"
"ES2020",
"dom"
],
"typeRoots": [
"node_modules/@types"
Expand Down

0 comments on commit 9e2d286

Please sign in to comment.