parent
f2ed39850f
commit
874c9cccaa
@ -1,46 +1,15 @@ |
||||
{ |
||||
"plugins": [ |
||||
["transform-es2015-template-literals", { |
||||
"loose": true |
||||
}], |
||||
"transform-es2015-literals", |
||||
"transform-es2015-function-name", |
||||
"transform-es2015-arrow-functions", |
||||
"transform-es2015-block-scoped-functions", ["transform-es2015-classes", { |
||||
"loose": true |
||||
}], |
||||
"transform-es2015-object-super", |
||||
"transform-es2015-shorthand-properties", ["transform-es2015-computed-properties", { |
||||
"loose": true |
||||
}], |
||||
["transform-es2015-for-of", { |
||||
"loose": true |
||||
}], |
||||
"transform-es2015-sticky-regex", |
||||
"transform-es2015-unicode-regex", |
||||
"check-es2015-constants", ["transform-es2015-spread", { |
||||
"loose": true |
||||
}], |
||||
"transform-es2015-parameters", ["transform-es2015-destructuring", { |
||||
"loose": true |
||||
}], |
||||
"transform-es2015-block-scoping", |
||||
"transform-object-rest-spread", |
||||
"transform-es3-member-expression-literals", |
||||
"transform-es3-property-literals", |
||||
"transform-async-to-generator", |
||||
"transform-regenerator", |
||||
["transform-runtime", { |
||||
"polyfill": true, |
||||
"regenerator": true |
||||
}] |
||||
], |
||||
"presets": ["@babel/preset-env"], |
||||
"env": { |
||||
"es5": { |
||||
"presets": ["es2015"] |
||||
}, |
||||
"es6": { |
||||
"presets": ["es2017"] |
||||
"presets": [ |
||||
[ |
||||
"@babel/preset-env", |
||||
{ |
||||
"modules": false |
||||
} |
||||
] |
||||
] |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,34 +1,25 @@ |
||||
import { compress, decompress } from './public-key'; |
||||
|
||||
export function stringify(cipher) { |
||||
if (typeof cipher === 'string') return cipher; |
||||
if (typeof cipher === 'string') return cipher; // use compressed key because it's smaller
|
||||
|
||||
// use compressed key because it's smaller
|
||||
var compressedKey = compress(cipher.ephemPublicKey); |
||||
|
||||
var ret = Buffer.concat([Buffer.from(cipher.iv, 'hex'), // 16bit
|
||||
Buffer.from(compressedKey, 'hex'), // 33bit
|
||||
Buffer.from(cipher.mac, 'hex'), // 32bit
|
||||
Buffer.from(cipher.ciphertext, 'hex') // var bit
|
||||
]); |
||||
|
||||
return ret.toString('hex'); |
||||
} |
||||
|
||||
export function parse(str) { |
||||
if (typeof str !== 'string') return str; |
||||
|
||||
var buf = Buffer.from(str, 'hex'); |
||||
|
||||
var ret = { |
||||
iv: buf.toString('hex', 0, 16), |
||||
ephemPublicKey: buf.toString('hex', 16, 49), |
||||
mac: buf.toString('hex', 49, 81), |
||||
ciphertext: buf.toString('hex', 81, buf.length) |
||||
}; |
||||
}; // decompress publicKey
|
||||
|
||||
// decompress publicKey
|
||||
ret.ephemPublicKey = '04' + decompress(ret.ephemPublicKey); |
||||
|
||||
return ret; |
||||
} |
@ -1,21 +1,16 @@ |
||||
import { decrypt } from 'eccrypto'; |
||||
import { parse } from './cipher'; |
||||
import { removeLeading0x } from './util'; |
||||
|
||||
export default function decryptWithPrivateKey(privateKey, encrypted) { |
||||
encrypted = parse(encrypted); // remove trailing '0x' from privateKey
|
||||
|
||||
encrypted = parse(encrypted); |
||||
|
||||
// remove trailing '0x' from privateKey
|
||||
var twoStripped = removeLeading0x(privateKey); |
||||
|
||||
var encryptedBuffer = { |
||||
iv: Buffer.from(encrypted.iv, 'hex'), |
||||
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'), |
||||
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'), |
||||
mac: Buffer.from(encrypted.mac, 'hex') |
||||
}; |
||||
|
||||
return decrypt(Buffer.from(twoStripped, 'hex'), encryptedBuffer).then(function (decryptedBuffer) { |
||||
return decryptedBuffer.toString(); |
||||
}); |
||||
|
@ -1,39 +1,30 @@ |
||||
import { publicKeyConvert } from 'secp256k1'; |
||||
import { pubToAddress, toChecksumAddress, toBuffer } from 'ethereumjs-util'; |
||||
import { hexToUnit8Array, uint8ArrayToHex, addLeading0x } from './util'; |
||||
|
||||
export function compress(startsWith04) { |
||||
|
||||
// add trailing 04 if not done before
|
||||
var testBuffer = Buffer.from(startsWith04, 'hex'); |
||||
if (testBuffer.length === 64) startsWith04 = '04' + startsWith04; |
||||
|
||||
return uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith04), true)); |
||||
} |
||||
|
||||
export function decompress(startsWith02Or03) { |
||||
|
||||
// if already decompressed an not has trailing 04
|
||||
var testBuffer = Buffer.from(startsWith02Or03, 'hex'); |
||||
if (testBuffer.length === 64) startsWith02Or03 = '04' + startsWith02Or03; |
||||
var decompressed = uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith02Or03), false)); // remove trailing 04
|
||||
|
||||
var decompressed = uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith02Or03), false)); |
||||
|
||||
// remove trailing 04
|
||||
decompressed = decompressed.substring(2); |
||||
return decompressed; |
||||
} |
||||
|
||||
/** |
||||
* generates the ethereum-adress of the publicKey |
||||
* We create the checksum-adress which is case-sensitive |
||||
* @returns {string} address |
||||
*/ |
||||
export function toAddress(publicKey) { |
||||
|
||||
export function toAddress(publicKey) { |
||||
// normalize key
|
||||
publicKey = decompress(publicKey); |
||||
|
||||
var addressBuffer = pubToAddress(toBuffer(addLeading0x(publicKey))); |
||||
var checkSumAdress = toChecksumAddress(addLeading0x(addressBuffer.toString('hex'))); |
||||
return checkSumAdress; |
||||
|
@ -1,25 +1,22 @@ |
||||
import { ecdsaRecover } from 'secp256k1'; |
||||
import { removeLeading0x, hexToUnit8Array, uint8ArrayToHex } from './util'; |
||||
|
||||
/** |
||||
* returns the publicKey for the privateKey with which the messageHash was signed |
||||
* @param {string} signature |
||||
* @param {string} hash |
||||
* @return {string} publicKey |
||||
*/ |
||||
|
||||
export default function recoverPublicKey(signature, hash) { |
||||
signature = removeLeading0x(signature); |
||||
signature = removeLeading0x(signature); // split into v-value and sig
|
||||
|
||||
// split into v-value and sig
|
||||
var sigOnly = signature.substring(0, signature.length - 2); // all but last 2 chars
|
||||
|
||||
var vValue = signature.slice(-2); // last 2 chars
|
||||
|
||||
var recoveryNumber = vValue === '1c' ? 1 : 0; |
||||
var pubKey = uint8ArrayToHex(ecdsaRecover(hexToUnit8Array(sigOnly), recoveryNumber, hexToUnit8Array(removeLeading0x(hash)), false)); // remove trailing '04'
|
||||
|
||||
var pubKey = uint8ArrayToHex(ecdsaRecover(hexToUnit8Array(sigOnly), recoveryNumber, hexToUnit8Array(removeLeading0x(hash)), false)); |
||||
|
||||
// remove trailing '04'
|
||||
pubKey = pubKey.slice(2); |
||||
|
||||
return pubKey; |
||||
} |
@ -1,13 +1,21 @@ |
||||
import { ContractFactory } from 'ethers'; |
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } |
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } |
||||
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } |
||||
|
||||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } |
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } |
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } |
||||
|
||||
import { ContractFactory } from 'ethers'; |
||||
export default function txDataByCompiled(abi, bytecode, args) { |
||||
// solc returns a string which is often passed instead of the json
|
||||
if (typeof abi === 'string') abi = JSON.parse(abi); |
||||
if (typeof abi === 'string') abi = JSON.parse(abi); // Construct a Contract Factory
|
||||
|
||||
// Construct a Contract Factory
|
||||
var factory = new ContractFactory(abi, '0x' + bytecode); |
||||
|
||||
var deployTransaction = factory.getDeployTransaction.apply(factory, args); |
||||
|
||||
var deployTransaction = factory.getDeployTransaction.apply(factory, _toConsumableArray(args)); |
||||
return deployTransaction.data; |
||||
} |
@ -1,15 +1,12 @@ |
||||
export function removeLeading0x(str) { |
||||
if (str.startsWith('0x')) return str.substring(2);else return str; |
||||
} |
||||
|
||||
export function addLeading0x(str) { |
||||
if (!str.startsWith('0x')) return '0x' + str;else return str; |
||||
} |
||||
|
||||
export function uint8ArrayToHex(arr) { |
||||
return Buffer.from(arr).toString('hex'); |
||||
} |
||||
|
||||
export function hexToUnit8Array(str) { |
||||
return new Uint8Array(Buffer.from(str, 'hex')); |
||||
} |
@ -1,4 +1,4 @@ |
||||
'use strict'; |
||||
"use strict"; |
||||
|
||||
var EthCrypto = require('./index.js'); |
||||
|
||||
|
@ -1,56 +1,55 @@ |
||||
'use strict'; |
||||
"use strict"; |
||||
|
||||
Object.defineProperty(exports, "__esModule", { |
||||
value: true |
||||
}); |
||||
exports.createPrivateKey = createPrivateKey; |
||||
exports['default'] = createIdentity; |
||||
exports["default"] = createIdentity; |
||||
|
||||
var _publicKeyByPrivateKey = require('./public-key-by-private-key'); |
||||
var _publicKeyByPrivateKey = _interopRequireDefault(require("./public-key-by-private-key")); |
||||
|
||||
var _publicKeyByPrivateKey2 = _interopRequireDefault(_publicKeyByPrivateKey); |
||||
var _account = require("eth-lib/lib/account"); |
||||
|
||||
var _account = require('eth-lib/lib/account'); |
||||
var _hash = require("eth-lib/lib/hash"); |
||||
|
||||
var _hash = require('eth-lib/lib/hash'); |
||||
var _bytes = _interopRequireDefault(require("eth-lib/lib/bytes")); |
||||
|
||||
var _bytes = require('eth-lib/lib/bytes'); |
||||
|
||||
var _bytes2 = _interopRequireDefault(_bytes); |
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } |
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
||||
|
||||
var MIN_ENTROPY_SIZE = 128; |
||||
|
||||
/** |
||||
* create a privateKey from the given entropy or a new one |
||||
* @param {Buffer} entropy |
||||
* @return {string} |
||||
*/ |
||||
|
||||
function createPrivateKey(entropy) { |
||||
if (entropy) { |
||||
if (!Buffer.isBuffer(entropy)) throw new Error('EthCrypto.createPrivateKey(): given entropy is no Buffer'); |
||||
if (Buffer.byteLength(entropy, 'utf8') < MIN_ENTROPY_SIZE) throw new Error('EthCrypto.createPrivateKey(): Entropy-size must be at least ' + MIN_ENTROPY_SIZE); |
||||
|
||||
var outerHex = (0, _hash.keccak256)(entropy); |
||||
return outerHex; |
||||
} else { |
||||
// @link https://github.com/MaiaVictor/eth-lib/blob/master/lib/account.js#L8
|
||||
var innerHex = (0, _hash.keccak256)(_bytes2['default'].concat(_bytes2['default'].random(32), _bytes2['default'].random(32))); |
||||
var middleHex = _bytes2['default'].concat(_bytes2['default'].concat(_bytes2['default'].random(32), innerHex), _bytes2['default'].random(32)); |
||||
var innerHex = (0, _hash.keccak256)(_bytes["default"].concat(_bytes["default"].random(32), _bytes["default"].random(32))); |
||||
|
||||
var middleHex = _bytes["default"].concat(_bytes["default"].concat(_bytes["default"].random(32), innerHex), _bytes["default"].random(32)); |
||||
|
||||
var _outerHex = (0, _hash.keccak256)(middleHex); |
||||
|
||||
return _outerHex; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* creates a new object with |
||||
* private-, public-Key and address |
||||
* @param {Buffer?} entropy if provided, will use that as single random-source |
||||
*/ |
||||
|
||||
|
||||
function createIdentity(entropy) { |
||||
var privateKey = createPrivateKey(entropy); |
||||
var identity = (0, _account.fromPrivate)(privateKey); |
||||
identity.publicKey = (0, _publicKeyByPrivateKey2['default'])(identity.privateKey); |
||||
identity.publicKey = (0, _publicKeyByPrivateKey["default"])(identity.privateKey); |
||||
return identity; |
||||
} |
@ -1,30 +1,26 @@ |
||||
'use strict'; |
||||
"use strict"; |
||||
|
||||
Object.defineProperty(exports, "__esModule", { |
||||
value: true |
||||
}); |
||||
exports['default'] = decryptWithPrivateKey; |
||||
exports["default"] = decryptWithPrivateKey; |
||||
|
||||
var _eccrypto = require('eccrypto'); |
||||
var _eccrypto = require("eccrypto"); |
||||
|
||||
var _cipher = require('./cipher'); |
||||
var _cipher = require("./cipher"); |
||||
|
||||
var _util = require('./util'); |
||||
var _util = require("./util"); |
||||
|
||||
function decryptWithPrivateKey(privateKey, encrypted) { |
||||
encrypted = (0, _cipher.parse)(encrypted); // remove trailing '0x' from privateKey
|
||||
|
||||
encrypted = (0, _cipher.parse)(encrypted); |
||||
|
||||
// remove trailing '0x' from privateKey
|
||||
var twoStripped = (0, _util.removeLeading0x)(privateKey); |
||||
|
||||
var encryptedBuffer = { |
||||
iv: Buffer.from(encrypted.iv, 'hex'), |
||||
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'), |
||||
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'), |
||||
mac: Buffer.from(encrypted.mac, 'hex') |
||||
}; |
||||
|
||||
return (0, _eccrypto.decrypt)(Buffer.from(twoStripped, 'hex'), encryptedBuffer).then(function (decryptedBuffer) { |
||||
return decryptedBuffer.toString(); |
||||
}); |
||||
|
@ -1,109 +1,138 @@ |
||||
'use strict'; |
||||
"use strict"; |
||||
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
||||
|
||||
Object.defineProperty(exports, "__esModule", { |
||||
value: true |
||||
}); |
||||
exports.util = exports.vrs = exports.hex = exports.hash = exports.calculateContractAddress = exports.txDataByCompiled = exports.signTransaction = exports.sign = exports.recoverPublicKey = exports.recover = exports.publicKeyByPrivateKey = exports.cipher = exports.encryptWithPublicKey = exports.decryptWithPrivateKey = exports.publicKey = exports.createIdentity = undefined; |
||||
|
||||
var _createIdentity = require('./create-identity'); |
||||
|
||||
var _createIdentity2 = _interopRequireDefault(_createIdentity); |
||||
|
||||
var _publicKey = require('./public-key'); |
||||
|
||||
var publicKey = _interopRequireWildcard(_publicKey); |
||||
|
||||
var _decryptWithPrivateKey = require('./decrypt-with-private-key'); |
||||
|
||||
var _decryptWithPrivateKey2 = _interopRequireDefault(_decryptWithPrivateKey); |
||||
|
||||
var _encryptWithPublicKey = require('./encrypt-with-public-key'); |
||||
|
||||
var _encryptWithPublicKey2 = _interopRequireDefault(_encryptWithPublicKey); |
||||
|
||||
var _cipher = require('./cipher'); |
||||
Object.defineProperty(exports, "createIdentity", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _createIdentity["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "decryptWithPrivateKey", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _decryptWithPrivateKey["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "encryptWithPublicKey", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _encryptWithPublicKey["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "publicKeyByPrivateKey", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _publicKeyByPrivateKey["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "recover", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _recover["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "recoverPublicKey", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _recoverPublicKey["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "sign", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _sign["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "signTransaction", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _signTransaction["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "txDataByCompiled", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _txDataByCompiled["default"]; |
||||
} |
||||
}); |
||||
Object.defineProperty(exports, "calculateContractAddress", { |
||||
enumerable: true, |
||||
get: function get() { |
||||
return _calculateContractAddress["default"]; |
||||
} |
||||
}); |
||||
exports.util = exports.vrs = exports.hex = exports.hash = exports.cipher = exports.publicKey = exports["default"] = void 0; |
||||
|
||||
var cipher = _interopRequireWildcard(_cipher); |
||||
var _createIdentity = _interopRequireDefault(require("./create-identity")); |
||||
|
||||
var _publicKeyByPrivateKey = require('./public-key-by-private-key'); |
||||
var publicKey = _interopRequireWildcard(require("./public-key")); |
||||
|
||||
var _publicKeyByPrivateKey2 = _interopRequireDefault(_publicKeyByPrivateKey); |
||||
exports.publicKey = publicKey; |
||||
|
||||
var _recover = require('./recover'); |
||||
var _decryptWithPrivateKey = _interopRequireDefault(require("./decrypt-with-private-key")); |
||||
|
||||
var _recover2 = _interopRequireDefault(_recover); |
||||
var _encryptWithPublicKey = _interopRequireDefault(require("./encrypt-with-public-key")); |
||||
|
||||
var _recoverPublicKey = require('./recover-public-key'); |
||||
var cipher = _interopRequireWildcard(require("./cipher")); |
||||
|
||||
var _recoverPublicKey2 = _interopRequireDefault(_recoverPublicKey); |
||||
exports.cipher = cipher; |
||||
|
||||
var _sign = require('./sign'); |
||||
var _publicKeyByPrivateKey = _interopRequireDefault(require("./public-key-by-private-key")); |
||||
|
||||
var _sign2 = _interopRequireDefault(_sign); |
||||
var _recover = _interopRequireDefault(require("./recover")); |
||||
|
||||
var _signTransaction = require('./sign-transaction'); |
||||
var _recoverPublicKey = _interopRequireDefault(require("./recover-public-key")); |
||||
|
||||
var _signTransaction2 = _interopRequireDefault(_signTransaction); |
||||
var _sign = _interopRequireDefault(require("./sign")); |
||||
|
||||
var _txDataByCompiled = require('./tx-data-by-compiled'); |
||||
var _signTransaction = _interopRequireDefault(require("./sign-transaction")); |
||||
|
||||
var _txDataByCompiled2 = _interopRequireDefault(_txDataByCompiled); |
||||
var _txDataByCompiled = _interopRequireDefault(require("./tx-data-by-compiled")); |
||||
|
||||
var _calculateContractAddress = require('./calculate-contract-address'); |
||||
var _calculateContractAddress = _interopRequireDefault(require("./calculate-contract-address")); |
||||
|
||||
var _calculateContractAddress2 = _interopRequireDefault(_calculateContractAddress); |
||||
var hash = _interopRequireWildcard(require("./hash")); |
||||
|
||||
var _hash = require('./hash'); |
||||
exports.hash = hash; |
||||
|
||||
var hash = _interopRequireWildcard(_hash); |
||||
var hex = _interopRequireWildcard(require("./hex")); |
||||
|
||||
var _hex = require('./hex'); |
||||
exports.hex = hex; |
||||
|
||||
var hex = _interopRequireWildcard(_hex); |
||||
var vrs = _interopRequireWildcard(require("./vrs")); |
||||
|
||||
var _vrs = require('./vrs'); |
||||
exports.vrs = vrs; |
||||
|
||||
var vrs = _interopRequireWildcard(_vrs); |
||||
var util = _interopRequireWildcard(require("./util")); |
||||
|
||||
var _util = require('./util'); |
||||
exports.util = util; |
||||
|
||||
var util = _interopRequireWildcard(_util); |
||||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } |
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } |
||||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } |
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
||||
|
||||
exports.createIdentity = _createIdentity2['default']; |
||||
exports.publicKey = publicKey; |
||||
exports.decryptWithPrivateKey = _decryptWithPrivateKey2['default']; |
||||
exports.encryptWithPublicKey = _encryptWithPublicKey2['default']; |
||||
exports.cipher = cipher; |
||||
exports.publicKeyByPrivateKey = _publicKeyByPrivateKey2['default']; |
||||
exports.recover = _recover2['default']; |
||||
exports.recoverPublicKey = _recoverPublicKey2['default']; |
||||
exports.sign = _sign2['default']; |
||||
exports.signTransaction = _signTransaction2['default']; |
||||
exports.txDataByCompiled = _txDataByCompiled2['default']; |
||||
exports.calculateContractAddress = _calculateContractAddress2['default']; |
||||
exports.hash = hash; |
||||
exports.hex = hex; |
||||
exports.vrs = vrs; |
||||
exports.util = util; |
||||
exports['default'] = { |
||||
createIdentity: _createIdentity2['default'], |
||||
var _default = { |
||||
createIdentity: _createIdentity["default"], |
||||
publicKey: publicKey, |
||||
decryptWithPrivateKey: _decryptWithPrivateKey2['default'], |
||||
encryptWithPublicKey: _encryptWithPublicKey2['default'], |
||||
decryptWithPrivateKey: _decryptWithPrivateKey["default"], |
||||
encryptWithPublicKey: _encryptWithPublicKey["default"], |
||||
cipher: cipher, |
||||
publicKeyByPrivateKey: _publicKeyByPrivateKey2['default'], |
||||
recover: _recover2['default'], |
||||
recoverPublicKey: _recoverPublicKey2['default'], |
||||
sign: _sign2['default'], |
||||
signTransaction: _signTransaction2['default'], |
||||
txDataByCompiled: _txDataByCompiled2['default'], |
||||
calculateContractAddress: _calculateContractAddress2['default'], |
||||
publicKeyByPrivateKey: _publicKeyByPrivateKey["default"], |
||||
recover: _recover["default"], |
||||
recoverPublicKey: _recoverPublicKey["default"], |
||||
sign: _sign["default"], |
||||
signTransaction: _signTransaction["default"], |
||||
txDataByCompiled: _txDataByCompiled["default"], |
||||
calculateContractAddress: _calculateContractAddress["default"], |
||||
hash: hash, |
||||
hex: hex, |
||||
vrs: vrs, |
||||
util: util |
||||
}; |
||||
exports["default"] = _default; |
@ -1,32 +1,28 @@ |
||||
'use strict'; |
||||
"use strict"; |
||||
|
||||
Object.defineProperty(exports, "__esModule", { |
||||
value: true |
||||
}); |
||||
exports['default'] = signTransaction; |
||||
exports["default"] = signTransaction; |
||||
|
||||
var _tx = require('@ethereumjs/tx'); |
||||
var _tx = require("@ethereumjs/tx"); |
||||
|
||||
var _publicKeyByPrivateKey = require('./public-key-by-private-key'); |
||||
var _publicKeyByPrivateKey = _interopRequireDefault(require("./public-key-by-private-key")); |
||||
|
||||
var _publicKeyByPrivateKey2 = _interopRequireDefault(_publicKeyByPrivateKey); |
||||
var _publicKey = require("./public-key"); |
||||
|
||||
var _publicKey = require('./public-key'); |
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } |
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
||||
|
||||
function signTransaction(rawTx, privateKey) { |
||||
var txOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
||||
|
||||
|
||||
// check if privateKey->address matches rawTx.from
|
||||
var publicKey = (0, _publicKeyByPrivateKey2['default'])(privateKey); |
||||
var publicKey = (0, _publicKeyByPrivateKey["default"])(privateKey); |
||||
var address = (0, _publicKey.toAddress)(publicKey); |
||||
if (address != rawTx.from) throw new Error('EthCrypto.signTransaction(): rawTx.from does not match the address of the privateKey'); |
||||
|
||||
var privateKeyBuffer = Buffer.from(privateKey.replace(/^.{2}/g, ''), 'hex'); |
||||
|
||||
var tx = _tx.Transaction.fromTxData(rawTx, txOptions); |
||||
|
||||
var signedTx = tx.sign(privateKeyBuffer); |
||||
var serializedTx = signedTx.serialize().toString('hex'); |
||||
return serializedTx; |
||||
|
@ -1,27 +1,29 @@ |
||||
'use strict'; |
||||
"use strict"; |
||||
|
||||
Object.defineProperty(exports, "__esModule", { |
||||
value: true |
||||
}); |
||||
exports["default"] = txDataByCompiled; |
||||
|
||||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); |
||||
var _ethers = require("ethers"); |
||||
|
||||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); |
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } |
||||
|
||||
exports['default'] = txDataByCompiled; |
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } |
||||
|
||||
var _ethers = require('ethers'); |
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } |
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } |
||||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } |
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } |
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } |
||||
|
||||
function txDataByCompiled(abi, bytecode, args) { |
||||
// solc returns a string which is often passed instead of the json
|
||||
if (typeof abi === 'string') abi = JSON.parse(abi); |
||||
if (typeof abi === 'string') abi = JSON.parse(abi); // Construct a Contract Factory
|
||||
|
||||
// Construct a Contract Factory
|
||||
var factory = new _ethers.ContractFactory(abi, '0x' + bytecode); |
||||
|
||||
var deployTransaction = factory.getDeployTransaction.apply(factory, (0, _toConsumableArray3['default'])(args)); |
||||
|
||||
var deployTransaction = factory.getDeployTransaction.apply(factory, _toConsumableArray(args)); |
||||
return deployTransaction.data; |
||||
} |
Loading…
Reference in new issue