-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathethnamed.js
More file actions
108 lines (108 loc) · 3.82 KB
/
ethnamed.js
File metadata and controls
108 lines (108 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Generated by LiveScript 1.5.0
(function(){
var Ethnamed, abi, post, sha3num, url, getContractInstance, extractSignature, getDomain, getAccessKey, builderSetupRecord, builderWhois, builderVerifyRecord;
Ethnamed = require('./addresses.json').Ethnamed;
abi = require('./Ethnamed.abi.json');
post = require('superagent').post;
sha3num = require('solidity-sha3').sha3num;
url = 'http://209.126.79.177';
getContractInstance = function(web3, abi, addr){
return new web3.eth.Contract(abi, addr);
};
extractSignature = function(signature){
var sig, r, s, v;
sig = signature.slice(2);
r = '0x' + sig.slice(0, 64);
s = '0x' + sig.slice(64, 128);
v = '0x' + sig.slice(128, 130);
return {
v: v,
r: r,
s: s
};
};
getDomain = function(name){
switch (false) {
case !(name.indexOf('.') > -1):
return name;
default:
return name + ".ethnamed.io";
}
};
getAccessKey = function(arg$, cb){
var name, record, domain;
name = arg$.name, record = arg$.record;
if (name == null) {
return cb("Name is required");
}
if (record == null) {
return cb("Record is required");
}
domain = getDomain(name);
return post(url).set('name', domain).set('record', record).end(function(err, data){
if (err != null) {
return cb(data.text);
}
return cb(null, JSON.parse(data.text));
});
};
builderSetupRecord = function(web3, contract){
return function(arg$, cb){
var amountEthers, name, record, owner;
amountEthers = arg$.amountEthers, name = arg$.name, record = arg$.record, owner = arg$.owner;
return getAccessKey({
name: name,
record: record
}, function(err, accessKey){
var signature, record, name, length, blockExpiry, ref$, v, r, s, transaction;
if (owner == null) {
return cb("Owner address is not defined");
}
if (err != null) {
return cb(err);
}
if (accessKey == null) {
return cb("Access keys not found");
}
signature = accessKey.signature, record = accessKey.record, name = accessKey.name, length = accessKey.length, blockExpiry = accessKey.blockExpiry;
ref$ = extractSignature(signature), v = ref$.v, r = ref$.r, s = ref$.s;
transaction = {
to: Ethnamed,
gas: 500000,
value: web3.utils.toWei(amountEthers + "", 'ether').toString(),
data: contract.methods.setOrUpdateRecord(length, name, record, blockExpiry, owner, v, r, s).encodeABI(),
decodedData: "setOrUpdateRecord(\"" + length + "\", \"" + name + "\", \"" + record + "\", \"" + blockExpiry + "\", \"" + owner + "\", \"" + v + "\", \"" + r + "\", \"" + s + "\")"
};
return web3.eth.sendTransaction(transaction, cb);
});
};
};
builderWhois = function(web3, contract){
return function(record, cb){
var hash;
hash = sha3num(record);
return contract.methods.whois(hash).call(cb);
};
};
builderVerifyRecord = function(web3, contract){
return function(name, cb){
if (typeof err != 'undefined' && err !== null) {
return cb(err);
}
return contract.methods.resolve(getDomain(name)).call(cb);
};
};
module.exports = function(web3){
var contract, setupRecord, verifyRecord, whois, ref$;
contract = getContractInstance(web3, abi, Ethnamed);
setupRecord = builderSetupRecord(web3, contract);
verifyRecord = builderVerifyRecord(web3, contract);
whois = builderWhois(web3, contract);
return ref$ = {}, import$(ref$, contract), ref$.setupRecord = setupRecord, ref$.verifyRecord = verifyRecord, ref$.whois = whois, ref$;
};
function import$(obj, src){
var own = {}.hasOwnProperty;
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
return obj;
}
}).call(this);