-
Notifications
You must be signed in to change notification settings - Fork 0
/
arweave.ts
73 lines (67 loc) · 2.23 KB
/
arweave.ts
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
import Arweave from 'arweave';
import config from './config';
import { Visibility } from './pages/write';
export const arweave = Arweave.init({
host: config.ARWEAVE_HOST,
port: config.ARWEAVE_PORT,
protocol: config.ARWEAVE_PROTOCOL
});
// todo: fetch to axios maybe
export const getTransactionsByVisibility = async ({ visibility }: { visibility: Visibility }) => {
const response = await fetch(`${config.ARWEAVE_URL}/graphql`, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
query: `
query {
transactions(tags: [
{
name: "App-Name",
values: ["${config.APP_NAME}"]
}
{
name: "Visibility",
values: ["${visibility}"]
}
]) {
edges {
node {
id
}
}
}
}
`
})
});
return response.json();
}
export const getTransactionsById = async (id: string) => {
const response = await fetch(`${config.ARWEAVE_URL}/graphql`, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
query: `
query {
transactions(ids: ["${id}"]) {
edges {
node {
tags {
name
value
}
}
}
}
}
`
})
});
return response.json();
}
export const arweaveEncrypt = (value: string): Promise<Uint8Array> => window.arweaveWallet.encrypt(value, config.ARCONNECT_ENCRYPT_OPTIONS);
export const arweaveDecrypt = (value: Uint8Array): Promise<string> => window.arweaveWallet.decrypt(value, config.ARCONNECT_ENCRYPT_OPTIONS);