@human-protocol/sdk 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -14
- package/dist/escrow.d.ts +0 -6
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +0 -6
- package/dist/graphql/queries/escrow.d.ts.map +1 -1
- package/dist/graphql/queries/escrow.js +0 -3
- package/dist/graphql/queries/kvstore.d.ts +1 -0
- package/dist/graphql/queries/kvstore.d.ts.map +1 -1
- package/dist/graphql/queries/kvstore.js +12 -1
- package/dist/graphql/queries/operator.js +1 -1
- package/dist/graphql/queries/statistics.d.ts +2 -2
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +11 -7
- package/dist/graphql/types.d.ts +0 -5
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/interfaces.d.ts +3 -5
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +69 -106
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +123 -159
- package/dist/statistics.d.ts +72 -66
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +121 -89
- package/package.json +1 -1
- package/src/constants.ts +15 -14
- package/src/escrow.ts +0 -6
- package/src/graphql/queries/escrow.ts +0 -3
- package/src/graphql/queries/kvstore.ts +11 -0
- package/src/graphql/queries/operator.ts +1 -1
- package/src/graphql/queries/statistics.ts +13 -9
- package/src/graphql/types.ts +0 -5
- package/src/index.ts +2 -1
- package/src/interfaces.ts +3 -5
- package/src/kvstore.ts +145 -158
- package/src/statistics.ts +138 -100
package/src/constants.ts
CHANGED
|
@@ -63,7 +63,7 @@ export const NETWORKS: {
|
|
|
63
63
|
subgraphUrl:
|
|
64
64
|
'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
|
|
65
65
|
subgraphUrlApiKey:
|
|
66
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
66
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmWGUDcQG1e8bjp9LRcyWCo4xfWcVCdgApi59sY6rgdRkS',
|
|
67
67
|
oldSubgraphUrl: '',
|
|
68
68
|
oldFactoryAddress: '',
|
|
69
69
|
},
|
|
@@ -109,7 +109,7 @@ export const NETWORKS: {
|
|
|
109
109
|
subgraphUrl:
|
|
110
110
|
'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
|
|
111
111
|
subgraphUrlApiKey:
|
|
112
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
112
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmfCCRC1cGKWuoRtaj2ZJKyaw97Ry15TbGiC4u3veTq8iX',
|
|
113
113
|
oldSubgraphUrl: '',
|
|
114
114
|
oldFactoryAddress: '',
|
|
115
115
|
},
|
|
@@ -125,7 +125,7 @@ export const NETWORKS: {
|
|
|
125
125
|
subgraphUrl:
|
|
126
126
|
'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
|
|
127
127
|
subgraphUrlApiKey:
|
|
128
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
128
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmWNVgcdzBkDyCNBYd7jBp1vChj9B3ah7nKMSXoDkzzXYm',
|
|
129
129
|
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
|
|
130
130
|
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
|
|
131
131
|
},
|
|
@@ -141,7 +141,7 @@ export const NETWORKS: {
|
|
|
141
141
|
subgraphUrl:
|
|
142
142
|
'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
|
|
143
143
|
subgraphUrlApiKey:
|
|
144
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
144
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmaEPv3KDMJJJ8EWfcKWX7FJGDBudHhuHDCMR2LkbYhdNR',
|
|
145
145
|
oldSubgraphUrl:
|
|
146
146
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
|
|
147
147
|
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
|
|
@@ -158,7 +158,7 @@ export const NETWORKS: {
|
|
|
158
158
|
subgraphUrl:
|
|
159
159
|
'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
|
|
160
160
|
subgraphUrlApiKey:
|
|
161
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
161
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmS2jKUstRaGWyAhytjA2b84grhXFKouZ3fzP9fPp2etum',
|
|
162
162
|
oldSubgraphUrl:
|
|
163
163
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
|
|
164
164
|
oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
|
|
@@ -191,7 +191,7 @@ export const NETWORKS: {
|
|
|
191
191
|
subgraphUrl:
|
|
192
192
|
'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
|
|
193
193
|
subgraphUrlApiKey:
|
|
194
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
194
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmVfssyiU81KwrTVL1QRjj4LPpTkA1ZmexHTRVg51J5YxP',
|
|
195
195
|
oldSubgraphUrl: '',
|
|
196
196
|
oldFactoryAddress: '',
|
|
197
197
|
},
|
|
@@ -207,7 +207,7 @@ export const NETWORKS: {
|
|
|
207
207
|
subgraphUrl:
|
|
208
208
|
'https://api.studio.thegraph.com/query/74256/moonbeam/version/latest',
|
|
209
209
|
subgraphUrlApiKey:
|
|
210
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
210
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmU5hSFUvu2fp8EWU3uqxcz477gWjXjRq3jnpMT3KG14Sg',
|
|
211
211
|
oldSubgraphUrl:
|
|
212
212
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam',
|
|
213
213
|
oldFactoryAddress: '0x98108c28B7767a52BE38B4860832dd4e11A7ecad',
|
|
@@ -224,7 +224,7 @@ export const NETWORKS: {
|
|
|
224
224
|
subgraphUrl:
|
|
225
225
|
'https://api.studio.thegraph.com/query/74256/moonbase-alpha/version/latest',
|
|
226
226
|
subgraphUrlApiKey:
|
|
227
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
227
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/Qmf9qH6CCxBzxkruDLLJzJTm4ig8LkSZYErGCNfJC5vsgQ',
|
|
228
228
|
oldSubgraphUrl: '',
|
|
229
229
|
oldFactoryAddress: '',
|
|
230
230
|
},
|
|
@@ -240,7 +240,7 @@ export const NETWORKS: {
|
|
|
240
240
|
subgraphUrl:
|
|
241
241
|
'https://api.studio.thegraph.com/query/74256/fuji/version/latest',
|
|
242
242
|
subgraphUrlApiKey:
|
|
243
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
243
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmXcSyzYPk4AFyWq4wubxrgVNYuse8zHiQYUZR7WFinRSj',
|
|
244
244
|
oldSubgraphUrl:
|
|
245
245
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
|
|
246
246
|
oldFactoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
|
|
@@ -257,7 +257,7 @@ export const NETWORKS: {
|
|
|
257
257
|
subgraphUrl:
|
|
258
258
|
'https://api.studio.thegraph.com/query/74256/avalanche/version/latest',
|
|
259
259
|
subgraphUrlApiKey:
|
|
260
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
260
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmbKoD9diMdiLoVgAzJmjM4Qj6jeUQAD8ztquPMMcaZVFA',
|
|
261
261
|
oldSubgraphUrl:
|
|
262
262
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
|
|
263
263
|
oldFactoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
|
|
@@ -274,7 +274,7 @@ export const NETWORKS: {
|
|
|
274
274
|
subgraphUrl:
|
|
275
275
|
'https://api.studio.thegraph.com/query/74256/celo-alfajores/version/latest',
|
|
276
276
|
subgraphUrlApiKey:
|
|
277
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
277
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmWSLvacfR6xiJ8dYJbABtMg3r2TuoKBSjMGSofJVh2uoR',
|
|
278
278
|
oldSubgraphUrl: '',
|
|
279
279
|
oldFactoryAddress: '',
|
|
280
280
|
},
|
|
@@ -290,7 +290,7 @@ export const NETWORKS: {
|
|
|
290
290
|
subgraphUrl:
|
|
291
291
|
'https://api.studio.thegraph.com/query/74256/celo/version/latest',
|
|
292
292
|
subgraphUrlApiKey:
|
|
293
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
293
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmXCUVfazFdQ9s1gWHyr7eNGTUY1zLVhmVGoVYhLbkT4ib',
|
|
294
294
|
oldSubgraphUrl: '',
|
|
295
295
|
oldFactoryAddress: '',
|
|
296
296
|
},
|
|
@@ -306,7 +306,7 @@ export const NETWORKS: {
|
|
|
306
306
|
subgraphUrl:
|
|
307
307
|
'https://api.studio.thegraph.com/query/74256/xlayer/version/latest',
|
|
308
308
|
subgraphUrlApiKey:
|
|
309
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
309
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmY7z7abXHxFBSqzeM67q5AYxF4uRLFvpVrQQQpwVJqMkQ',
|
|
310
310
|
oldSubgraphUrl: '',
|
|
311
311
|
oldFactoryAddress: '',
|
|
312
312
|
},
|
|
@@ -322,7 +322,7 @@ export const NETWORKS: {
|
|
|
322
322
|
subgraphUrl:
|
|
323
323
|
'https://api.studio.thegraph.com/query/74256/xlayer-testnet/version/latest',
|
|
324
324
|
subgraphUrlApiKey:
|
|
325
|
-
'https://gateway-testnet-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/
|
|
325
|
+
'https://gateway-testnet-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmVw3K8cdbommhhH6jhmkLGQAbPjgWuYYeUfBCQv6rmJTr',
|
|
326
326
|
oldSubgraphUrl: '',
|
|
327
327
|
oldFactoryAddress: '',
|
|
328
328
|
},
|
|
@@ -349,6 +349,7 @@ export const KVStoreKeys = {
|
|
|
349
349
|
webhookUrl: 'webhook_url',
|
|
350
350
|
url: 'url',
|
|
351
351
|
jobTypes: 'job_types',
|
|
352
|
+
registrationNeeded: 'registration_needed',
|
|
352
353
|
};
|
|
353
354
|
|
|
354
355
|
export const Role = {
|
package/src/escrow.ts
CHANGED
|
@@ -1484,11 +1484,8 @@ export class EscrowUtils {
|
|
|
1484
1484
|
* manifestHash?: string;
|
|
1485
1485
|
* manifestUrl?: string;
|
|
1486
1486
|
* recordingOracle?: string;
|
|
1487
|
-
* recordingOracleFee?: string;
|
|
1488
1487
|
* reputationOracle?: string;
|
|
1489
|
-
* reputationOracleFee?: string;
|
|
1490
1488
|
* exchangeOracle?: string;
|
|
1491
|
-
* exchangeOracleFee?: string;
|
|
1492
1489
|
* status: EscrowStatus;
|
|
1493
1490
|
* token: string;
|
|
1494
1491
|
* totalFundedAmount: string;
|
|
@@ -1618,11 +1615,8 @@ export class EscrowUtils {
|
|
|
1618
1615
|
* manifestHash?: string;
|
|
1619
1616
|
* manifestUrl?: string;
|
|
1620
1617
|
* recordingOracle?: string;
|
|
1621
|
-
* recordingOracleFee?: string;
|
|
1622
1618
|
* reputationOracle?: string;
|
|
1623
|
-
* reputationOracleFee?: string;
|
|
1624
1619
|
* exchangeOracle?: string;
|
|
1625
|
-
* exchangeOracleFee?: string;
|
|
1626
1620
|
* status: EscrowStatus;
|
|
1627
1621
|
* token: string;
|
|
1628
1622
|
* totalFundedAmount: string;
|
|
@@ -21,3 +21,14 @@ export const GET_KVSTORE_BY_ADDRESS_QUERY = () => {
|
|
|
21
21
|
${KVSTORE_FRAGMENT}
|
|
22
22
|
`;
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
export const GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY = () => {
|
|
26
|
+
return gql`
|
|
27
|
+
query getKVStoreDataByKey($address: String!, $key: String!) {
|
|
28
|
+
kvstores(where: { address: $address, key: $key }) {
|
|
29
|
+
...KVStoreFields
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
${KVSTORE_FRAGMENT}
|
|
33
|
+
`;
|
|
34
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import gql from 'graphql-tag';
|
|
2
|
-
import {
|
|
2
|
+
import { IStatisticsFilter } from '../../interfaces';
|
|
3
3
|
|
|
4
4
|
const HMTOKEN_STATISTICS_FRAGMENT = gql`
|
|
5
5
|
fragment HMTokenStatisticsFields on HMTokenStatistics {
|
|
@@ -70,25 +70,29 @@ export const GET_ESCROW_STATISTICS_QUERY = gql`
|
|
|
70
70
|
${ESCROW_STATISTICS_FRAGMENT}
|
|
71
71
|
`;
|
|
72
72
|
|
|
73
|
-
export const GET_EVENT_DAY_DATA_QUERY = (params:
|
|
74
|
-
const { from, to
|
|
73
|
+
export const GET_EVENT_DAY_DATA_QUERY = (params: IStatisticsFilter) => {
|
|
74
|
+
const { from, to } = params;
|
|
75
75
|
const WHERE_CLAUSE = `
|
|
76
76
|
where: {
|
|
77
77
|
${from !== undefined ? `timestamp_gte: $from` : ''}
|
|
78
78
|
${to !== undefined ? `timestamp_lte: $to` : ''}
|
|
79
79
|
}
|
|
80
80
|
`;
|
|
81
|
-
const LIMIT_CLAUSE = `
|
|
82
|
-
first: ${limit ? `$limit` : `1000`}
|
|
83
|
-
`;
|
|
84
81
|
|
|
85
82
|
return gql`
|
|
86
|
-
query GetEscrowDayData(
|
|
83
|
+
query GetEscrowDayData(
|
|
84
|
+
$from: Int,
|
|
85
|
+
$to: Int,
|
|
86
|
+
$orderDirection: String
|
|
87
|
+
$first: Int
|
|
88
|
+
$skip: Int
|
|
89
|
+
) {
|
|
87
90
|
eventDayDatas(
|
|
88
91
|
${WHERE_CLAUSE},
|
|
89
92
|
orderBy: timestamp,
|
|
90
|
-
orderDirection:
|
|
91
|
-
$
|
|
93
|
+
orderDirection: $orderDirection,
|
|
94
|
+
first: $first,
|
|
95
|
+
skip: $skip
|
|
92
96
|
) {
|
|
93
97
|
...EventDayDataFields
|
|
94
98
|
}
|
package/src/graphql/types.ts
CHANGED
|
@@ -13,11 +13,8 @@ export type EscrowData = {
|
|
|
13
13
|
manifestHash?: string;
|
|
14
14
|
manifestUrl?: string;
|
|
15
15
|
recordingOracle?: string;
|
|
16
|
-
recordingOracleFee?: string;
|
|
17
16
|
reputationOracle?: string;
|
|
18
|
-
reputationOracleFee?: string;
|
|
19
17
|
exchangeOracle?: string;
|
|
20
|
-
exchangeOracleFee?: string;
|
|
21
18
|
status: string;
|
|
22
19
|
token: string;
|
|
23
20
|
totalFundedAmount: string;
|
|
@@ -141,8 +138,6 @@ export type HMTStatistics = {
|
|
|
141
138
|
totalTransferAmount: bigint;
|
|
142
139
|
totalTransferCount: number;
|
|
143
140
|
totalHolders: number;
|
|
144
|
-
holders: HMTHolder[];
|
|
145
|
-
dailyHMTData: DailyHMTData[];
|
|
146
141
|
};
|
|
147
142
|
|
|
148
143
|
export type IMDataEntity = {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StakingClient } from './staking';
|
|
2
2
|
import { StorageClient } from './storage';
|
|
3
|
-
import { KVStoreClient } from './kvstore';
|
|
3
|
+
import { KVStoreClient, KVStoreUtils } from './kvstore';
|
|
4
4
|
import { EscrowClient, EscrowUtils } from './escrow';
|
|
5
5
|
import { StatisticsClient } from './statistics';
|
|
6
6
|
import { Encryption, EncryptionUtils } from './encryption';
|
|
@@ -16,6 +16,7 @@ export {
|
|
|
16
16
|
StakingClient,
|
|
17
17
|
StorageClient,
|
|
18
18
|
KVStoreClient,
|
|
19
|
+
KVStoreUtils,
|
|
19
20
|
EscrowClient,
|
|
20
21
|
EscrowUtils,
|
|
21
22
|
StatisticsClient,
|
package/src/interfaces.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface ILeader {
|
|
|
26
26
|
amountSlashed: bigint;
|
|
27
27
|
reputation: bigint;
|
|
28
28
|
reward: bigint;
|
|
29
|
-
|
|
29
|
+
amountJobsProcessed: bigint;
|
|
30
30
|
role?: string;
|
|
31
31
|
fee?: bigint;
|
|
32
32
|
publicKey?: string;
|
|
@@ -96,15 +96,13 @@ export interface IKeyPair {
|
|
|
96
96
|
revocationCertificate?: string;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export interface
|
|
99
|
+
export interface IStatisticsFilter extends IPagination {
|
|
100
100
|
from?: Date;
|
|
101
101
|
to?: Date;
|
|
102
|
-
limit?: number;
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
export interface IHMTHoldersParams {
|
|
104
|
+
export interface IHMTHoldersParams extends IPagination {
|
|
106
105
|
address?: string;
|
|
107
|
-
orderDirection?: 'asc' | 'desc';
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
export interface IPayoutFilter {
|
package/src/kvstore.ts
CHANGED
|
@@ -19,7 +19,10 @@ import {
|
|
|
19
19
|
import gqlFetch from 'graphql-request';
|
|
20
20
|
import { NetworkData } from './types';
|
|
21
21
|
import { getSubgraphUrl, isValidUrl } from './utils';
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY,
|
|
24
|
+
GET_KVSTORE_BY_ADDRESS_QUERY,
|
|
25
|
+
} from './graphql/queries/kvstore';
|
|
23
26
|
import { KVStoreData } from './graphql';
|
|
24
27
|
import { IKVStore } from './interfaces';
|
|
25
28
|
/**
|
|
@@ -277,71 +280,162 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
277
280
|
throw Error(`Failed to set URL and hash: ${e.message}`);
|
|
278
281
|
}
|
|
279
282
|
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* ## Introduction
|
|
287
|
+
*
|
|
288
|
+
* Utility class for KVStore-related operations.
|
|
289
|
+
*
|
|
290
|
+
* ## Installation
|
|
291
|
+
*
|
|
292
|
+
* ### npm
|
|
293
|
+
* ```bash
|
|
294
|
+
* npm install @human-protocol/sdk
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* ### yarn
|
|
298
|
+
* ```bash
|
|
299
|
+
* yarn install @human-protocol/sdk
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* ## Code example
|
|
303
|
+
*
|
|
304
|
+
* ### Signer
|
|
305
|
+
*
|
|
306
|
+
* **Using private key (backend)**
|
|
307
|
+
*
|
|
308
|
+
* ```ts
|
|
309
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
310
|
+
*
|
|
311
|
+
* const KVStoreAddresses = new KVStoreUtils.getKVStoreData({
|
|
312
|
+
* ChainId.POLYGON_AMOY,
|
|
313
|
+
* "0x1234567890123456789012345678901234567890",
|
|
314
|
+
* );
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
export class KVStoreUtils {
|
|
318
|
+
/**
|
|
319
|
+
* This function returns the KVStore data for a given address.
|
|
320
|
+
*
|
|
321
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
322
|
+
* @param {string} address Address of the KVStore
|
|
323
|
+
* @returns {Promise<IKVStore[]>} KVStore data
|
|
324
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
325
|
+
* @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
|
|
326
|
+
*
|
|
327
|
+
* **Code example**
|
|
328
|
+
*
|
|
329
|
+
* ```ts
|
|
330
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
331
|
+
*
|
|
332
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
|
|
333
|
+
* console.log(kvStoreData);
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
public static async getKVStoreData(
|
|
337
|
+
chainId: ChainId,
|
|
338
|
+
address: string
|
|
339
|
+
): Promise<IKVStore[]> {
|
|
340
|
+
const networkData = NETWORKS[chainId];
|
|
341
|
+
|
|
342
|
+
if (!networkData) {
|
|
343
|
+
throw ErrorUnsupportedChainID;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (address && !ethers.isAddress(address)) {
|
|
347
|
+
throw ErrorInvalidAddress;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
|
|
351
|
+
getSubgraphUrl(networkData),
|
|
352
|
+
GET_KVSTORE_BY_ADDRESS_QUERY(),
|
|
353
|
+
{ address: address.toLowerCase() }
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const kvStoreData = kvstores.map((item) => ({
|
|
357
|
+
key: item.key,
|
|
358
|
+
value: item.value,
|
|
359
|
+
}));
|
|
360
|
+
|
|
361
|
+
return kvStoreData || [];
|
|
362
|
+
}
|
|
280
363
|
|
|
281
364
|
/**
|
|
282
|
-
* Gets the value of a key-value pair in the
|
|
365
|
+
* Gets the value of a key-value pair in the KVStore using the subgraph.
|
|
283
366
|
*
|
|
367
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
284
368
|
* @param {string} address Address from which to get the key value.
|
|
285
369
|
* @param {string} key Key to obtain the value.
|
|
286
|
-
* @returns {string} Value of the key.
|
|
287
|
-
*
|
|
370
|
+
* @returns {Promise<string>} Value of the key.
|
|
371
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
372
|
+
* @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
|
|
373
|
+
* @throws {ErrorKVStoreEmptyKey} - Thrown if the key is empty
|
|
288
374
|
*
|
|
289
375
|
* **Code example**
|
|
290
376
|
*
|
|
291
|
-
* > Need to have available stake.
|
|
292
|
-
*
|
|
293
377
|
* ```ts
|
|
294
|
-
* import {
|
|
295
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
296
|
-
*
|
|
297
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
378
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
298
379
|
*
|
|
299
|
-
* const
|
|
300
|
-
* const
|
|
380
|
+
* const chainId = ChainId.POLYGON_AMOY;
|
|
381
|
+
* const address = '0x1234567890123456789012345678901234567890';
|
|
382
|
+
* const key = 'role';
|
|
301
383
|
*
|
|
302
|
-
* const value = await
|
|
384
|
+
* const value = await KVStoreUtils.get(chainId, address, key);
|
|
385
|
+
* console.log(value);
|
|
303
386
|
* ```
|
|
304
387
|
*/
|
|
305
|
-
public async get(
|
|
388
|
+
public static async get(
|
|
389
|
+
chainId: ChainId,
|
|
390
|
+
address: string,
|
|
391
|
+
key: string
|
|
392
|
+
): Promise<string> {
|
|
306
393
|
if (key === '') throw ErrorKVStoreEmptyKey;
|
|
307
394
|
if (!ethers.isAddress(address)) throw ErrorInvalidAddress;
|
|
308
395
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
396
|
+
const networkData = NETWORKS[chainId];
|
|
397
|
+
|
|
398
|
+
if (!networkData) {
|
|
399
|
+
throw ErrorUnsupportedChainID;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
|
|
403
|
+
getSubgraphUrl(networkData),
|
|
404
|
+
GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY(),
|
|
405
|
+
{ address: address.toLowerCase(), key }
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
if (!kvstores || kvstores.length === 0) {
|
|
409
|
+
throw new Error(`Key "${key}" not found for address ${address}`);
|
|
315
410
|
}
|
|
411
|
+
|
|
412
|
+
const value = kvstores[0].value;
|
|
413
|
+
|
|
414
|
+
return value;
|
|
316
415
|
}
|
|
317
416
|
|
|
318
417
|
/**
|
|
319
|
-
* Gets the URL value of the given entity, and
|
|
418
|
+
* Gets the URL value of the given entity, and verifies its hash.
|
|
320
419
|
*
|
|
420
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
321
421
|
* @param {string} address Address from which to get the URL value.
|
|
322
|
-
* @param {string} urlKey
|
|
323
|
-
* @returns {string} URL value for the given address if exists, and the content is valid
|
|
324
|
-
*
|
|
422
|
+
* @param {string} urlKey Configurable URL key. `url` by default.
|
|
423
|
+
* @returns {Promise<string>} URL value for the given address if it exists, and the content is valid
|
|
325
424
|
*
|
|
326
425
|
* **Code example**
|
|
327
426
|
*
|
|
328
427
|
* ```ts
|
|
329
|
-
* import {
|
|
330
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
428
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
331
429
|
*
|
|
332
|
-
* const
|
|
430
|
+
* const chainId = ChainId.POLYGON_AMOY;
|
|
431
|
+
* const address = '0x1234567890123456789012345678901234567890';
|
|
333
432
|
*
|
|
334
|
-
* const
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
* const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
338
|
-
* const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
|
|
339
|
-
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
340
|
-
* 'linkedin_url'
|
|
341
|
-
* );
|
|
433
|
+
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
|
|
434
|
+
* console.log(url);
|
|
342
435
|
* ```
|
|
343
436
|
*/
|
|
344
|
-
public async getFileUrlAndVerifyHash(
|
|
437
|
+
public static async getFileUrlAndVerifyHash(
|
|
438
|
+
chainId: ChainId,
|
|
345
439
|
address: string,
|
|
346
440
|
urlKey = 'url'
|
|
347
441
|
): Promise<string> {
|
|
@@ -352,7 +446,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
352
446
|
hash = '';
|
|
353
447
|
|
|
354
448
|
try {
|
|
355
|
-
url = await this.
|
|
449
|
+
url = await this.get(chainId, address, urlKey);
|
|
356
450
|
} catch (e) {
|
|
357
451
|
if (e instanceof Error) throw Error(`Failed to get URL: ${e.message}`);
|
|
358
452
|
}
|
|
@@ -363,7 +457,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
363
457
|
}
|
|
364
458
|
|
|
365
459
|
try {
|
|
366
|
-
hash = await this.
|
|
460
|
+
hash = await this.get(chainId, address, hashKey);
|
|
367
461
|
} catch (e) {
|
|
368
462
|
if (e instanceof Error) throw Error(`Failed to get Hash: ${e.message}`);
|
|
369
463
|
}
|
|
@@ -379,28 +473,30 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
379
473
|
}
|
|
380
474
|
|
|
381
475
|
/**
|
|
382
|
-
* Gets the public key of the given entity, and
|
|
476
|
+
* Gets the public key of the given entity, and verifies its hash.
|
|
383
477
|
*
|
|
478
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
384
479
|
* @param {string} address Address from which to get the public key.
|
|
385
|
-
* @returns {string} Public key for the given address if exists, and the content is valid
|
|
386
|
-
*
|
|
480
|
+
* @returns {Promise<string>} Public key for the given address if it exists, and the content is valid
|
|
387
481
|
*
|
|
388
482
|
* **Code example**
|
|
389
483
|
*
|
|
390
484
|
* ```ts
|
|
391
|
-
* import {
|
|
392
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
393
|
-
*
|
|
394
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
485
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
395
486
|
*
|
|
396
|
-
* const
|
|
397
|
-
* const
|
|
487
|
+
* const chainId = ChainId.POLYGON_AMOY;
|
|
488
|
+
* const address = '0x1234567890123456789012345678901234567890';
|
|
398
489
|
*
|
|
399
|
-
* const publicKey = await
|
|
490
|
+
* const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
|
|
491
|
+
* console.log(publicKey);
|
|
400
492
|
* ```
|
|
401
493
|
*/
|
|
402
|
-
public async getPublicKey(
|
|
494
|
+
public static async getPublicKey(
|
|
495
|
+
chainId: ChainId,
|
|
496
|
+
address: string
|
|
497
|
+
): Promise<string> {
|
|
403
498
|
const publicKeyUrl = await this.getFileUrlAndVerifyHash(
|
|
499
|
+
chainId,
|
|
404
500
|
address,
|
|
405
501
|
KVStoreKeys.publicKey
|
|
406
502
|
);
|
|
@@ -414,112 +510,3 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
414
510
|
return publicKey;
|
|
415
511
|
}
|
|
416
512
|
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* ## Introduction
|
|
420
|
-
*
|
|
421
|
-
* Utility class for KVStore-related operations.
|
|
422
|
-
*
|
|
423
|
-
* ## Installation
|
|
424
|
-
*
|
|
425
|
-
* ### npm
|
|
426
|
-
* ```bash
|
|
427
|
-
* npm install @human-protocol/sdk
|
|
428
|
-
* ```
|
|
429
|
-
*
|
|
430
|
-
* ### yarn
|
|
431
|
-
* ```bash
|
|
432
|
-
* yarn install @human-protocol/sdk
|
|
433
|
-
* ```
|
|
434
|
-
*
|
|
435
|
-
* ## Code example
|
|
436
|
-
*
|
|
437
|
-
* ### Signer
|
|
438
|
-
*
|
|
439
|
-
* **Using private key (backend)**
|
|
440
|
-
*
|
|
441
|
-
* ```ts
|
|
442
|
-
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
443
|
-
*
|
|
444
|
-
* const KVStoreAddresses = new KVStoreUtils.getData({
|
|
445
|
-
* network: ChainId.POLYGON_AMOY
|
|
446
|
-
* });
|
|
447
|
-
* ```
|
|
448
|
-
*/
|
|
449
|
-
export class KVStoreUtils {
|
|
450
|
-
/**
|
|
451
|
-
* This function returns the KVStore data for a given address.
|
|
452
|
-
*
|
|
453
|
-
* > This uses Subgraph
|
|
454
|
-
*
|
|
455
|
-
* **Input parameters**
|
|
456
|
-
*
|
|
457
|
-
* ```ts
|
|
458
|
-
* enum ChainId {
|
|
459
|
-
* ALL = -1,
|
|
460
|
-
* MAINNET = 1,
|
|
461
|
-
* RINKEBY = 4,
|
|
462
|
-
* GOERLI = 5,
|
|
463
|
-
* BSC_MAINNET = 56,
|
|
464
|
-
* BSC_TESTNET = 97,
|
|
465
|
-
* POLYGON = 137,
|
|
466
|
-
* POLYGON_MUMBAI = 80001,
|
|
467
|
-
* POLYGON_AMOY = 80002,
|
|
468
|
-
* MOONBEAM = 1284,
|
|
469
|
-
* MOONBASE_ALPHA = 1287,
|
|
470
|
-
* AVALANCHE = 43114,
|
|
471
|
-
* AVALANCHE_TESTNET = 43113,
|
|
472
|
-
* CELO = 42220,
|
|
473
|
-
* CELO_ALFAJORES = 44787,
|
|
474
|
-
* LOCALHOST = 1338,
|
|
475
|
-
* }
|
|
476
|
-
* ```
|
|
477
|
-
*
|
|
478
|
-
* ```ts
|
|
479
|
-
* interface IKVStore {
|
|
480
|
-
* key: string;
|
|
481
|
-
* value: string;
|
|
482
|
-
* }
|
|
483
|
-
* ```
|
|
484
|
-
*
|
|
485
|
-
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
486
|
-
* @param {string} address Address of the KVStore
|
|
487
|
-
* @returns {Promise<IKVStore[]>} KVStore data
|
|
488
|
-
*
|
|
489
|
-
* **Code example**
|
|
490
|
-
*
|
|
491
|
-
* ```ts
|
|
492
|
-
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
493
|
-
*
|
|
494
|
-
* const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
|
|
495
|
-
* console.log(kvStoreData);
|
|
496
|
-
* ```
|
|
497
|
-
*/
|
|
498
|
-
public static async getKVStoreData(
|
|
499
|
-
chainId: ChainId,
|
|
500
|
-
address: string
|
|
501
|
-
): Promise<IKVStore[]> {
|
|
502
|
-
const networkData = NETWORKS[chainId];
|
|
503
|
-
|
|
504
|
-
if (!networkData) {
|
|
505
|
-
throw ErrorUnsupportedChainID;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if (address && !ethers.isAddress(address)) {
|
|
509
|
-
throw ErrorInvalidAddress;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
|
|
513
|
-
getSubgraphUrl(networkData),
|
|
514
|
-
GET_KVSTORE_BY_ADDRESS_QUERY(),
|
|
515
|
-
{ address: address.toLowerCase() }
|
|
516
|
-
);
|
|
517
|
-
|
|
518
|
-
const kvStoreData = kvstores.map((item) => ({
|
|
519
|
-
key: item.key,
|
|
520
|
-
value: item.value,
|
|
521
|
-
}));
|
|
522
|
-
|
|
523
|
-
return kvStoreData || [];
|
|
524
|
-
}
|
|
525
|
-
}
|