Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ethereumjs-tx-keyvault

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereumjs-tx-keyvault - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

60

index.js

@@ -5,5 +5,32 @@ "use strict"

const KeyVault = require("azure-keyvault")
const BN = require("bn.js")
const assert = require("assert")
const secp256k1 = require("secp256k1")
const _ = require("underscore")
const CURVE_ORDER = new BN(Buffer.from('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 'hex'))
const HALF_CURVE_ORDER = CURVE_ORDER.clone().ishrn(1)
var isHigh = function (num) {
return num.ucmp(HALF_CURVE_ORDER) === 1
}
var makeCanonical = function(buffer) {
var r = new BN(buffer.slice(0, 32))
var s = new BN(buffer.slice(32, 64))
if (isHigh(s)) {
s = CURVE_ORDER.sub(s)
}
return Buffer.concat([ r.toBuffer(), s.toBuffer() ])
}
const txParams = {
nonce: '0x34f', // Replace by nonce for your account on geth node
gasPrice: '0x09184e72a000',
gasLimit: '0x27100',
to: '0x0d8e50b8849f59f25078bb9e2d9014b9a540dcab',
value: '0xde0b6b3a7640000'
};
var Extensions = function () {

@@ -17,11 +44,13 @@ function Extensions() {

* @param {KeyVault.KeyVaultClient} client the key vault client object
* @param {String} kid the key identifier in key vault URI format
* @param {String} vaultUri the vault URI
* @param {String} keyName the name of the EC key
* @param {String} keyVersion the version of the key
* @return {Buffer} the signed transaction object
*/
Extensions.prototype.sign = function (tx, client, kid) {
Extensions.prototype.sign = function (tx, client, vaultUri, keyName, keyVersion) {
assert.equal(true, tx instanceof EthereumTx, "Transaction must be of type 'require(\"ethereumjs-tx\")'")
assert.equal(true, tx instanceof KeyVault.KeyVaultClient, "Client must be of type 'require(\"azure-keyvault\").KeyVaultClient'")
assert.equal(true, client instanceof KeyVault.KeyVaultClient, "Client must be of type 'require(\"azure-keyvault\").KeyVaultClient'")
return new Promise((resolve, reject) => {
client.getKey(kid, function (getErr, getKeyBundle) {
client.getKey(vaultUri, keyName, keyVersion, null, function (getErr, getKeyBundle) {
if (getErr) {

@@ -33,3 +62,3 @@ reject(getErr)

client.sign(kid, "ECDSA256", msgHash, function (signErr, signature) {
client.sign(vaultUri, keyName, keyVersion, "ECDSA256", msgHash, null, function (signErr, signature) {
if (signErr) {

@@ -39,5 +68,20 @@ reject(signErr)

}
const pubKey = Buffer.concat([ Uint8Array.from([4]), getKeyBundle.key.x, getKeyBundle.key.y])
const sig = makeCanonical(Buffer.from(signature.result))
console.log(signature)
resolve(signature)
var sigObj = {
r: sig.slice(0, 32),
s: sig.slice(32, 64)
}
for (var i = 0; i < 4; i++) {
const recoveredPubKey = secp256k1.recover(msgHash, sig, i, false)
if (_.isEqual(pubKey, recoveredPubKey)) {
sigObj.v = Buffer.from([i + 27])
break
}
}
console.debug("secp256k1 verify: " + secp256k1.verify(msgHash, sig, pubKey))
resolve(sigObj)
})

@@ -44,0 +88,0 @@ })

7

package.json
{
"name": "ethereumjs-tx-keyvault",
"version": "1.0.0",
"version": "1.0.1",
"description": "Azure Key Vault extensions for ethereumjs-tx",

@@ -25,4 +25,7 @@ "main": "index.js",

"azure-keyvault": "^3.0.0-preview",
"ethereumjs-tx": "^1.3.3"
"bn.js": "^4.11.8",
"ethereumjs-tx": "^1.3.3",
"secp256k1": "^3.5.0",
"underscore": "^1.8.3"
}
}
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