-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
63 lines (57 loc) · 2.05 KB
/
index.js
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
const Everpay = require('everpay')
const crypto = require("crypto");
module.exports = {
id: "everpay",
setup:async()=>{
const everpay = Everpay.default?new Everpay.default():new Everpay()
return {
async verifySignature(signerPublickey, message, signature) {
const dataToVerify = new TextEncoder().encode(message);
const binarySignature = b64UrlToBuffer(signature);
const hash = await crypto.subtle.digest("SHA-256", dataToVerify);
const publicJWK = {
e: "AQAB",
ext: true,
kty: "RSA",
n: signerPublickey,
};
const cryptoKey = await crypto.subtle.importKey(
"jwk",
publicJWK,
{
name: "RSA-PSS",
hash: "SHA-256",
},
false,
["verify"]
);
const result = await crypto.subtle.verify(
{ name: "RSA-PSS", saltLength: 32 },
cryptoKey,
binarySignature,
hash
);
return result;
},
async readTxById(id){
let dataFromEverpay = await everpay.txByHash(id)
if (!dataFromEverpay || dataFromEverpay.action != "transfer" || dataFromEverpay.internalStatus != '{"status":"success"}') {
return null
}
return {
coin: dataFromEverpay.tokenSymbol,
timestamp: dataFromEverpay.timestamp,
amount:dataFromEverpay.amount,
from: dataFromEverpay.from,
to:dataFromEverpay.to,
}
}
}
}
}
const b64UrlToBuffer = (b64Url) =>
new Uint8Array(
atob(b64Url.replace(/-/g, "+").replace(/_/g, "/"))
.split("")
.map((c) => c.charCodeAt(0))
).buffer;