-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ls
More file actions
47 lines (39 loc) · 1.5 KB
/
api.ls
File metadata and controls
47 lines (39 loc) · 1.5 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
require! {
\superagent : { post }
\./guid.js
\./json-stringify.js
\./json-parse.js
\bitcore-lib : bitcore
\bitcore-message : Message
}
create-signature = (private-key-hex, request, cb)->
private-key = bitcore.PrivateKey.fromWIF private-key-hex
err, str <- json-stringify request
return cb err if err?
signature = Message(str).sign private-key
return cb err if err?
cb null, signature
generic-call = (fields, name)-> (config)-> (request, cb)->
{ api-url, private-key } = config
for item in fields
return cb "`#{item}` is required" if not request[item]?
err, signature <- create-signature private-key, request
return cb err if err?
err, data <- post "#{api-url}/#{name}", request .set \signature, signature .end
return cb err if err?
err, result <- json-parse data.text
return cb err if err?
cb null, result
kyc-builder = generic-call <[ firstname lastname bill photo clientid ]> , \kyc
convert-builder = generic-call <[ to from value address clientid ]> , \exchange
export create-clientid = guid
export get-address = (key)->
private-key = bitcore.PrivateKey.fromWIF key
return private-key.to-address bitcore.Networks.livenet .to-string!
export create-api = ({ api-url, private-key }, cb)->
return cb "apiUrl is required" if not api-url?
return cb "private-key is required" if not private-key?
config = { api-url, private-key }
convert = convert-builder config
kyc = kyc-builder config
cb null, { convert, kyc }