New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@covalenthq/js-sign

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@covalenthq/js-sign - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

.babelrc

12

package.json
{
"name": "@covalenthq/js-sign",
"version": "1.0.4",
"version": "1.0.5",
"description": "Covalent browser compatible library for typed data signature creation and verification",
"main": "dist/lib.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},

@@ -27,10 +27,12 @@ "repository": {

"assert": "^2.0.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"stream-browserify": "^3.0.0",
"buffer": "^6.0.3",
"eth-crypto": "^2.0.0",
"eth-lib": "^0.2.8",
"eth-typed-data": "^0.1.0-beta.0"
"eth-typed-data": "^0.1.0-beta.0",
"stream-browserify": "^3.0.0"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.15.0",
"jest": "^27.0.6",
"webpack": "^5.50.0",

@@ -37,0 +39,0 @@ "webpack-cli": "^4.8.0"

@@ -1,4 +0,4 @@

# js-sign
# [js-sign](https://covalenthq.com/) · [![GitHub license](https://img.shields.io/npm/v/@covalenthq/js-sign)]()
This library help create Covalent signature which is intended to authenticate the data communicate with Covalent API endpoints. Generally, only one function call is required to create the necessary signature.
js-sign library allows browsers and Node.js clients to create signature payload in order to interact with Covalent API. Generally, only one function call is required to create the necessary signature.

@@ -11,4 +11,6 @@ Currently, when using some Covalent API endpoints, the only data that required signing is the wallet address.

Embed the javascript source in html
```html
<script src="https://cdn.jsdelivr.net/npm/covalent-js-sign/dist/lib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@covalenthq/js-sign/dist/lib.min.js"></script>
```

@@ -18,8 +20,10 @@

Installing module
```bash
npm i --save covalent-js-sign
npm i --save @covalenthq/js-sign
```
### Private library inclusion
### Download from github gist

@@ -31,2 +35,21 @@ * Please download the single library, covalent-js-sign.js, directly from the github gist,

## Testing
All new code changes should be covered with unit tests. You can run the tests with the following command,
```bash
npm run test
```
## Configuration and Setup
### Private key
Provide private key to process.env.PRIVATE_KEY variable. You can use dotenv or any other way.
```bash
process.env.PRIVATE_KEY = ${YOUR_PRIVATE_KEY}
```
## Usage

@@ -36,16 +59,13 @@

// Node.JS
import { createSignaturePayloadB64 } from 'covalent-js-sign';
import * as covalent from '@covalenthq/js-sign';
// To create the payload that include the typed data challenge and the signature in base64 encoding format,
const privateKey = "59e96b740f0af54f2d4335ddd033816fa24348b4097d3fddad4f6edc939f52e9";
const privateKey = process.env.PRIVATE_KEY;
const walletAddress = "0x71d094E5382CA33B25B92d3A75d5C6f269A78fAe";
const chainId = 1; // default is 1
// Node.JS
const payload = createSignaturePayloadB64(privateKey, walletAddress, chainId);
const payload = covalent.createSignaturePayloadB64(privateKey, walletAddress, chainId);
// browser
const payload = covalent.createSignaturePayloadB64(privateKey, walletAddress, chainId);
```

@@ -22,4 +22,4 @@ 'use strict';

// @return EIP-712 commpliance schema object
export function createChallenge(walletAddress, chainId="1") {
const typeData = createTypedDataSchema(walletAddress, chainId);
export function createChallenge(walletAddress, chainId=1, createSchema=createTypedDataSchema) {
const typeData = createSchema(walletAddress, chainId);
const myDomain = new EIP712Domain(typeData.domain);

@@ -41,3 +41,3 @@

const hash_ = challenge.signHash();
const hash = EthCrypto.util.uint8ArrayToHe(hash_);
const hash = EthCrypto.util.uint8ArrayToHex(hash_);

@@ -53,3 +53,7 @@ const signature = EthCrypto.sign(privateKey, hash);

// @return base64 payload: return base64 string that include both signature and typed data challenge
export function createSignaturePayloadB64(privateKey, walletAddress, chainId="1") {
export function createSignaturePayloadB64(privateKey,
walletAddress,
chainId=1,
createChallenge=createChallenge,
createSignature=createSignature) {
const challenge = createChallenge(walletAddress, chainId);

@@ -56,0 +60,0 @@

@@ -9,30 +9,32 @@ 'use strict';

export function createTypedDataSchema(address, chainId=1) {
export function createTypedDataSchema(address,
chainId = 1,
make_salt = (() => { return _bytes2['default'].random(32); }),
make_timestamp = (() => { return Math.floor(Date.now() / 1000); })) {
return {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: "salt", type: "bytes32" },
],
},
Challenge: [
{ name: "address", type: "address" },
// { name: "nonce", type: "string" },
{ name: "timestamp", type: "uint64" },
],
primaryType: 'Challenge',
domain: {
name: 'ETHChallenger',
version: '1',
chainId: '' + chainId,
salt: _bytes2['default'].random(32),
},
message: {
"address": address,
"timestamp": Math.floor(Date.now() / 1000),
},
};
return {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: "salt", type: "bytes32" },
],
},
Challenge: [
{ name: "address", type: "address" },
{ name: "timestamp", type: "uint64" },
],
primaryType: 'Challenge',
domain: {
name: 'ETHChallenger',
version: '1',
chainId: '' + chainId,
salt: make_salt(),
},
message: {
"address": address,
"timestamp": make_timestamp(),
},
};
}

@@ -8,3 +8,3 @@ const path = require('path');

filename: 'lib.js',
library: 'covalent',
library: 'covalenthq',
path: path.resolve(__dirname, 'dist'),

@@ -11,0 +11,0 @@ libraryTarget: 'umd',

Sorry, the diff of this file is too big to display

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