forked from LiskArchive/app-registry
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request LiskArchive#51 from LiskHQ/50-Update-validation-sc…
…ripts-to-validate-for-at-least-one-base-demon-with-zero-decimals-in-native-Tokens Update validation scripts to validate for at least one base demon with zero decimals in native Tokens
- Loading branch information
Showing
15 changed files
with
444 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
utility/extractPublicKeyFromCertificate.js → ...ficate/extractPublicKeyFromCertificate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Extract public key from PEM Certificate using Node.js | ||
|
||
This Node.js script lets you extract the public key from a URL and save it locally to your filesystem. Follow the steps below to use the script: | ||
|
||
## Prerequisites | ||
|
||
Before using the script, kindly ensure that you have Node.js installed on your system. You can download Node.js from the [official website](https://nodejs.org). | ||
|
||
## Getting Started | ||
|
||
1. **Download the script:** | ||
|
||
Download the [`extractPublicKeyFromURL.js`](./extractPublicKeyFromURL.js) file from this repository and save it to a location on your computer. | ||
|
||
2. **Open a Terminal or Command Prompt:** | ||
|
||
Navigate to the directory where you saved the `extractPublicKeyFromURL.js` file using the terminal or command prompt. | ||
|
||
4. **Generate Public Key:** | ||
|
||
To run the script and generate the public key, use the following command: | ||
|
||
```bash | ||
node extractPublicKeyFromURL.js <URL> <path/to/public_key.pem> | ||
``` | ||
|
||
Replace `<URL>` with the desiered URL without port number, and `<path/to/public_key.pem>` with the desired output file path for the public key to be extracted. |
67 changes: 67 additions & 0 deletions
67
utility/extractPublicKeyFromURL/extractPublicKeyFromURL.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
|
||
const fs = require('fs') | ||
const { exec } = require('child_process'); | ||
const crypto = require('crypto'); | ||
|
||
const url = process.argv[2]; | ||
const publicKeyFilePath = process.argv[3]; | ||
|
||
const getCertificateFromURL = async (url) => new Promise((resolve, reject) => { | ||
const { host } = new URL(url); | ||
|
||
// Use OpenSSL to retrieve the PEM certificate | ||
const command = `openssl s_client -connect ${host}:443 -showcerts </dev/null 2>/dev/null | openssl x509 -outform PEM`; | ||
|
||
exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
|
||
if (stderr) { | ||
reject(new Error(`Error: ${stderr}`)); | ||
return; | ||
} | ||
|
||
const pemCertificate = stdout; | ||
resolve(pemCertificate); | ||
}); | ||
}); | ||
|
||
const convertCertificateToPemPublicKey = (pemCertificate) => new Promise((resolve, reject) => { | ||
try { | ||
// Create a certificate object from the PEM data | ||
const certificate = crypto.createPublicKey({ | ||
key: pemCertificate, | ||
format: 'pem', | ||
}); | ||
|
||
// Convert the certificate to PEM format for public key | ||
const publicKeyPem = certificate.export({ | ||
format: 'pem', | ||
type: 'spki', | ||
}); | ||
|
||
// Write the public key to the output file | ||
fs.writeFileSync(publicKeyFilePath, publicKeyPem); | ||
} catch (error) { | ||
reject(new Error(`Error occurred while extracting the public key: ${error.message}.`)); | ||
} | ||
}); | ||
|
||
getCertificateFromURL(url).then((cert) => { | ||
convertCertificateToPemPublicKey(cert); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
const config = require('../config'); | ||
const { readJsonFile } = require('./utils/fs'); | ||
|
||
const validateTokens = async (changedAppFiles) => { | ||
const validationErrors = []; | ||
|
||
const nativetokenFiles = changedAppFiles.filter((filename) => filename.endsWith(config.filename.NATIVE_TOKENS)); | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
for (const nativetokenFile of nativetokenFiles) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const nativeTokensdata = await readJsonFile(nativetokenFile); | ||
const { tokens } = nativeTokensdata; | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
for (const token of tokens) { | ||
const isBaseDenomInDenomUnits = token.denomUnits.some(unit => unit.denom === token.baseDenom); | ||
if (!isBaseDenomInDenomUnits) { | ||
validationErrors.push(`baseDenom "${token.baseDenom}" is not defined in denomUnits.`); | ||
} | ||
|
||
const isBaseDenomDefinitionValid = token.denomUnits.some(unit => unit.denom === token.baseDenom && unit.decimals === 0); | ||
if (isBaseDenomInDenomUnits && !isBaseDenomDefinitionValid) { | ||
validationErrors.push(`baseDenom "${token.baseDenom}" defined in denomUnits does not have "decimals" set to 0.`); | ||
} | ||
} | ||
} | ||
|
||
return validationErrors; | ||
}; | ||
|
||
module.exports = { | ||
validateTokens, | ||
}; |
Oops, something went wrong.