ethereumjs-tx-keyvault
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"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) | ||
}) | ||
```` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8015
54