-
Notifications
You must be signed in to change notification settings - Fork 2
/
coinbase-transfer.html
69 lines (66 loc) · 2.39 KB
/
coinbase-transfer.html
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
<html>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js"></script>
<script>
var coinbase = {
key: `${key}`,
secret: `${secret}`,
passphrase: `${passphrase}`,
timestamp: (Date.now() / 1000)
};
function sign(secret, method, uri, body) {
var message = coinbase.timestamp + method + uri + (body ?? '');
var secretDecoded = CryptoJS.enc.Base64.parse(coinbase.secret);
var hash = CryptoJS.HmacSHA256(message, secretDecoded);
return CryptoJS.enc.Base64.stringify(hash);
}
$.ajax({
type: 'GET',
url: 'https://api.pro.coinbase.com/payment-methods/',
contentType: 'application/json',
dataType: 'json',
headers: {
'Access-Control-Allow-Origin': '*',
'CB-ACCESS-KEY': coinbase.key,
'CB-ACCESS-TIMESTAMP': coinbase.timestamp,
'CB-ACCESS-PASSPHRASE': coinbase.passphrase,
'CB-ACCESS-SIGN': sign(coinbase.secret, 'GET', '/payment-methods/'),
},
success: (data) => {
var paymentId = data.find(item => item.name.includes('Evansville'))?.id;
if(paymentId) {
$.ajax({
type: 'POST',
url: 'https://api.pro.coinbase.com/deposits/payment-method/',
contentType: 'application/json',
dataType: 'json',
headers: {
'Access-Control-Allow-Origin': '*',
'CB-ACCESS-KEY': coinbase.key,
'CB-ACCESS-TIMESTAMP': coinbase.timestamp,
'CB-ACCESS-PASSPHRASE': coinbase.passphrase,
'CB-ACCESS-SIGN': sign(coinbase.secret, 'POST', '/deposits/payment-method/'),
},
data: {
"amount": 0, //10.00,
"currency": "USD",
"payment_method_id": paymentId
},
success: (data) => {
document.write(data);
console.log(data);
},
error: (error) => {
console.log(error);
}
});
}
},
error: (error) => {
console.log(error);
}
});
</script>
</html>