-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9f7c0a9
Showing
30 changed files
with
1,169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "ethereumjs-tx-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "webpack.config.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"ethereumjs-tx": "^1.1.1", | ||
"ethereumjs-util": "^4.3.0", | ||
"express": "^4.13.4", | ||
"hooked-web3-provider": "^1.0.0", | ||
"html-loader": "^0.4.3", | ||
"http-proxy-middleware": "^0.13.0", | ||
"js-base64": "^2.1.9", | ||
"json-loader": "^0.5.4", | ||
"jsonwebtoken": "^5.7.0", | ||
"secp256k1": "^3.0.1", | ||
"web3": "^0.15.3", | ||
"webpack": "^1.12.14", | ||
"webpack-dev-middleware": "^1.5.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Ethereum authentication | ||
======================= | ||
|
||
This project contains a first draft version of a authentication and authorizaion service in blockchain technolgy. The sevice provides a library which helps setting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var fs = require('fs'); | ||
|
||
require.extensions['.sol'] = function (module, filename) { | ||
module.exports = fs.readFileSync(filename, 'utf8'); | ||
}; | ||
|
||
|
||
var contracts = { | ||
//app: require('./contracts/App.sol'), | ||
user: require('./contracts/User.sol'), | ||
userFactory: require('./contracts/UserFactory.sol'), | ||
token: require('./contracts/Token.sol'), | ||
getterSetter: require('./contracts/GetterSetter.sol'), | ||
//resource: require('./contracts/Resource.sol') | ||
}; | ||
|
||
var all = "" | ||
Object.keys(contracts).forEach(function(key) { | ||
all += contracts[key] | ||
}); | ||
|
||
module.exports = all; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
contract App { | ||
|
||
string name; | ||
|
||
function User(string n) { | ||
name[0] = n; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
contract GetterSetter { | ||
|
||
bytes32 name; | ||
|
||
function setName(bytes32 n) { | ||
name = n; | ||
} | ||
|
||
function getName() constant returns(bytes32) { | ||
return name; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
contract grant { | ||
|
||
address app; | ||
address user; | ||
|
||
function grant() { | ||
app = msg.sender | ||
} | ||
|
||
function authorize(address u) { | ||
user = u | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
contract App { | ||
|
||
string name; | ||
|
||
function User(string n) { | ||
name[0] = n; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
contract OwnedToken { | ||
// TokenCreator is a contract type that is defined below. | ||
// It is fine to reference it as long as it is not used | ||
// to create a new contract. | ||
address creator; | ||
address owner; | ||
bytes32 name; | ||
// This is the constructor which registers the | ||
// creator and the assigned name. | ||
function OwnedToken(bytes32 _name) { | ||
owner = msg.sender; | ||
// We do an explicit type conversion from `address` | ||
// to `TokenCreator` and assume that the type of | ||
// the calling contract is TokenCreator, there is | ||
// no real way to check that. | ||
creator = TokenCreator(msg.sender); | ||
name = _name; | ||
} | ||
function changeName(bytes32 newName) { | ||
// Only the creator can alter the name -- | ||
// the comparison is possible since contracts | ||
// are implicitly convertible to addresses. | ||
if (msg.sender == creator) name = newName; | ||
} | ||
|
||
function getName() constant returns(bytes32){ | ||
return name; | ||
} | ||
|
||
} | ||
|
||
contract TokenCreator { | ||
function createToken(bytes32 name) | ||
returns (OwnedToken tokenAddress) | ||
{ | ||
// Create a new Token contract and return its address. | ||
// From the JavaScript side, the return type is simply | ||
// "address", as this is the closest type available in | ||
// the ABI. | ||
return new OwnedToken(name); | ||
} | ||
function changeName(OwnedToken tokenAddress, bytes32 name) { | ||
// Again, the external type of "tokenAddress" is | ||
// simply "address". | ||
tokenAddress.changeName(name); | ||
} | ||
|
||
function getName(OwnedToken tokenAddress) constant returns(bytes32){ | ||
return tokenAddress.getName(); | ||
} | ||
|
||
function isTokenTransferOK( | ||
address currentOwner, | ||
address newOwner | ||
) returns (bool ok) { | ||
// Check some arbitrary condition. | ||
address tokenAddress = msg.sender; | ||
return (sha3(newOwner) & 0xff) == (bytes20(tokenAddress) & 0xff); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
contract User { | ||
|
||
mapping (address => bool) delegates; | ||
|
||
function User() { | ||
delegates[msg.sender] = true; | ||
} | ||
|
||
function authorize(address delegate) { | ||
if(!delegates[msg.sender]) throw; | ||
address.authorize(); | ||
} | ||
|
||
function createDelegate(address delegate) { | ||
if(!delegates[msg.sender]) throw; | ||
delegates[delegate] = true; | ||
} | ||
|
||
function deleteDelegate(address delegate) { | ||
if(!delegates[msg.sender]) throw; | ||
if(!delegates[delegate]) throw; | ||
delete delegates[delegate]; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
contract UserFactory { | ||
|
||
User user; | ||
|
||
function createUser(bytes32 name) { | ||
user = new User(); | ||
} | ||
|
||
function getUser() constant returns (User){ | ||
return user; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var Web3 = require('web3'); | ||
var web3 = new Web3(); | ||
|
||
var defaultProvider = new web3.providers.HttpProvider("http://128.199.53.68:8545") | ||
|
||
web3.setProvider(defaultProvider); | ||
web3.eth.defaultAccount = web3.eth.coinbase; | ||
|
||
var source = "contract test { function multiply(uint a) constant returns(uint d) {return a * 7;}}"; | ||
|
||
var compiled = web3.eth.compile.solidity(source); | ||
var abi = compiled.test.info.abiDefinition; | ||
var code = compiled.test.code; | ||
|
||
function createContract(callback){ | ||
web3.eth.contract(abi).new({ | ||
from: web3.eth.coinbase, | ||
gas: 500000, | ||
data: code | ||
}, callback); | ||
} | ||
|
||
module.exports = createContract; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var Web3 = require('web3'); | ||
var secp256k1 = require('secp256k1'); | ||
var base64 = { | ||
encode: function(string){ | ||
return new Buffer(string, 'utf8').toString('base64') | ||
}, | ||
decode: function(string){ | ||
return new Buffer(string, 'base64').toString('utf8') | ||
}, | ||
} | ||
|
||
module.exports = { | ||
sign: function (payload, privateKey) { | ||
var web3 = new Web3(); | ||
var header = { | ||
"alg": "ES256", | ||
"typ": "JWT" | ||
}; | ||
var msg = base64.encode(JSON.stringify(header)) + "." + base64.encode(JSON.stringify(payload)); | ||
|
||
var hash = web3.sha3(msg); | ||
var sign = secp256k1.sign(new Buffer(hash, 'hex'), privateKey); | ||
|
||
sign.signature = sign.signature.toString('hex'); | ||
var token = msg + "." + base64.encode(JSON.stringify(sign)); | ||
|
||
return token; | ||
}, | ||
|
||
verify: function (token, publicKey) { | ||
var web3 = new Web3(); | ||
var split = token.split("."); | ||
var msg = split[0] + "." + split[1]; | ||
|
||
var hash = web3.sha3(msg); | ||
var sign = JSON.parse(base64.decode(split[2])); | ||
|
||
var recover = secp256k1.recover(new Buffer(hash, 'hex'), new Buffer(sign.signature, 'hex'), sign.recovery); | ||
|
||
return Buffer.compare(publicKey, recover) === 0; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var ethereumjsTx = require('ethereumjs-tx'); | ||
var ethereumjsUtil = require('ethereumjs-util'); | ||
|
||
module.exports = function (privateKey) { | ||
|
||
return { | ||
|
||
hasAddress: function (address, callback) { | ||
callback(null, true) | ||
}, | ||
|
||
signTransaction: function (tx_params, callback) { | ||
|
||
tx_params.gasPrice = '0xBA43B7400'; | ||
tx_params.gasLimit = '0x500000'; | ||
|
||
console.log(tx_params); | ||
|
||
var tx = new ethereumjsTx(tx_params); | ||
tx.sign(privateKey); | ||
|
||
var senderAddress = ethereumjsUtil.bufferToHex(tx.getSenderAddress()); | ||
|
||
var buffer = new Buffer(tx.serialize()); | ||
console.log(buffer.toString('hex')); | ||
var signedTx = ethereumjsUtil.bufferToHex(buffer); | ||
|
||
callback(null, ethereumjsUtil.stripHexPrefix(signedTx)); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
|
||
var assert = require('assert'); | ||
var Web3 = require('web3'); | ||
|
||
var contracts = require('../src/contracts'); | ||
|
||
describe('TokenCreator', function () { | ||
|
||
|
||
var hex = "0x57696c6c656d0000000000000000000000000000000000000000000000000000" | ||
var hex = "0x681f3e6d00000000000000000000000000000000000000000000000000000000" | ||
|
||
it('should create GetterSetterContract', function () { | ||
|
||
var buffer = new Buffer(hex.slice(2), 'hex'); | ||
console.log(buffer); | ||
console.log(buffer.toString('ascii')); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var assert = require('assert'); | ||
|
||
var Web3 = require('web3'); | ||
|
||
var ethereumjsUtil = require('ethereumjs-util'); | ||
|
||
var secp256k1 = require('secp256k1') | ||
|
||
var jwt = require('../src/jwt'); | ||
|
||
describe('Jwt', function () { | ||
|
||
var web3 = new Web3(); | ||
|
||
var username = 'willem'; | ||
var password = '123456'; | ||
var hash = web3.sha3(username + ":" + password); | ||
|
||
var privateKey = new Buffer(hash, 'hex'); | ||
var publicKey= secp256k1.publicKeyCreate(privateKey); | ||
|
||
|
||
it('should create jwt token', function (done) { | ||
var token = jwt.sign("Hello World", privateKey); | ||
|
||
console.log('token', token); | ||
|
||
var verify = jwt.verify(token, publicKey) | ||
assert.equal(true, verify); | ||
|
||
done() | ||
}); | ||
|
||
}); |
Oops, something went wrong.