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.3 to 1.0.4

2

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

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

@@ -9,24 +9,46 @@ # Extensions to ethereumjs-tx adding transaction signing support using Azure Key Vault

````javascript
const TxExtensions = require("ethereumjs-tx-keyvault")
const txExt = require("ethereumjs-tx-keyvault")
const KeyVault = require("azure-keyvault")
const EthereumTx = require("ethereumjs-tx")
const AuthenticationContext = require("adal-node").AuthenticationContext;
const client = KeyVault.createKeyVaultClient(/* client credentials */)
const clientId = "<to-be-filled>";
const clientSecret = "<to-be-filled>";
const vaultUri = "<to-be-filled>";
// Setup key vault client and credentials
const authenticator = function (challenge, callback) {
const context = new AuthenticationContext(challenge.authorization);
return context.acquireTokenWithClientCredentials(challenge.resource, clientId, clientSecret, function (err, tokenResponse) {
if (err) throw err
const authorizationValue = tokenResponse.tokenType + ' ' + tokenResponse.accessToken
return callback(null, authorizationValue)
})
}
const credentials = new KeyVault.KeyVaultCredentials(authenticator)
const client = new KeyVault.KeyVaultClient(credentials);
// Create a sample transaction
const txParams = {
nonce: '0x34f', // Replace by nonce for your account on geth node
nonce: '0x00',
gasPrice: '0x09184e72a000',
gasLimit: '0x27100',
to: '0x0d8e50b8849f59f25078bb9e2d9014b9a540dcab',
value: '0xde0b6b3a7640000'
gasLimit: '0x2710',
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
// EIP 155 chainId - mainnet: 1, ropsten: 3
chainId: 3
}
var transaction = new EthereumTx(txParams)
const tx = new EthereumTx(txParams)
TxExtensions.sign(transaction, client, "your_vault_uri", "your_key_name", "your_key_version")
// Sign the transaction and log verification results
txExt.sign(tx, client, vaultUri, "alice", "")
.then(signature => {
Object.assign(transaction, signature)
Object.assign(tx, signature)
console.log("Signature verification: " + tx.verifySignature())
console.log("Transaction verified: " + transaction.verifySignature())
})
// Print transaction hash. Can be sent directly to geth using 'sendRawTransaction'
const txHash = "0x" + Buffer.from(tx.serialize()).toString("hex")
console.log("Transaction hash: " + txHash)
})
````
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