Socket
Socket
Sign inDemoInstall

bytes32

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bytes32 - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

4

bin.js

@@ -7,7 +7,9 @@ #!/usr/bin/env node

const [, , input] = process.argv;
console.log(
bytes32({
input: process.argv[2],
input,
ignoreLength: process.argv[3] === '--ignore-length',
}),
);

@@ -17,4 +17,21 @@ 'use strict';

// (ibid)
const hexToAscii = function (hex) {
let str = '';
let i = 0;
if (hex.substring(0, 2) === '0x') {
i = 2;
}
for (; i < hex.length; i += 2) {
const code = parseInt(hex.substr(i, 2), 16);
str += String.fromCharCode(code);
}
return str;
};
module.exports = ({ input = '', ignoreLength = false }) => {
if (!ignoreLength && input.length > 32) {
if (/^(0x)?[0-9a-zA-Z]{64}$/.test(input)) {
// then it's bytes to str
return hexToAscii(input);
} else if (!ignoreLength && input.length > 32) {
throw Error(

@@ -21,0 +38,0 @@ `Input string is too long, must be maximum of 32. It is currently ${input.length}`,

{
"name": "bytes32",
"version": "0.0.1",
"version": "0.0.2",
"description": "Simply utility to convert string to bytes32",

@@ -5,0 +5,0 @@ "main": "index.js",

# Bytes32
Simple CLI tool to convert a string to `bytes32` for Ethereum.
Simple CLI tool to convert a string to `bytes32` for Ethereum. Always works in reverse if given a valid bytes32 input

@@ -22,14 +22,30 @@ ## Usage:

0x537570657263616c6966726167696c697374696365787069616c69646f63696f7573
$ npx bytes32 0x7345544800000000000000000000000000000000000000000000000000000000
sETH
$ npx bytes32 7345544800000000000000000000000000000000000000000000000000000000
sETH
```
or in code
> To copy to clipboard on a mac, you can pipe to `pbcopy`.
>
> ```bash
> $ npx bytes32 sETH | pbcopy
> ```
or in code:
```javascript
const bytes32 = require('bytes32');
console.log(bytes32({ input: 'sETH' });
console.log(bytes32({ input: 'sETH' }));
// 0x7345544800000000000000000000000000000000000000000000000000000000
console.log(bytes32({ input: 'Supercalifragilisticexpialidocious', ignoreLength: true });
console.log(bytes32({ input: 'Supercalifragilisticexpialidocious', ignoreLength: true }));
// 0x537570657263616c6966726167696c697374696365787069616c69646f63696f7573
console.log(bytes32({ input: '0x7345544800000000000000000000000000000000000000000000000000000000' }));
// sETH
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc