@dashevo/dapi-client 1.0.0-dev.6 → 1.0.0-dev.7
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.
|
@@ -11,6 +11,7 @@ const getProtocolVersionUpgradeVoteStatusFactory = require('./getProtocolVersion
|
|
|
11
11
|
const getProtocolVersionUpgradeStateFactory = require('./getProtocolVersionUpgradeState/getProtocolVersionUpgradeStateFactory');
|
|
12
12
|
const getIdentityContractNonceFactory = require('./getIdentityContractNonce/getIdentityContractNonceFactory');
|
|
13
13
|
const getIdentityNonceFactory = require('./getIdentityNonce/getIdentityNonceFactory');
|
|
14
|
+
const getIdentityKeysFactory = require('./getIdentityKeys/getIdentityKeysFactory');
|
|
14
15
|
|
|
15
16
|
class PlatformMethodsFacade {
|
|
16
17
|
/**
|
|
@@ -32,6 +33,7 @@ class PlatformMethodsFacade {
|
|
|
32
33
|
this.getProtocolVersionUpgradeState = getProtocolVersionUpgradeStateFactory(grpcTransport);
|
|
33
34
|
this.getIdentityContractNonce = getIdentityContractNonceFactory(grpcTransport);
|
|
34
35
|
this.getIdentityNonce = getIdentityNonceFactory(grpcTransport);
|
|
36
|
+
this.getIdentityKeys = getIdentityKeysFactory(grpcTransport);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
3
|
+
|
|
4
|
+
class GetIdentityKeysResponse extends AbstractResponse {
|
|
5
|
+
/**
|
|
6
|
+
* @param {number} identityKeys
|
|
7
|
+
* @param {Metadata} metadata
|
|
8
|
+
* @param {Proof} [proof]
|
|
9
|
+
*/
|
|
10
|
+
constructor(identityKeys, metadata, proof = undefined) {
|
|
11
|
+
super(metadata, proof);
|
|
12
|
+
|
|
13
|
+
this.identityKeys = identityKeys;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns {number}
|
|
18
|
+
*/
|
|
19
|
+
getIdentityKeys() {
|
|
20
|
+
return this.identityKeys;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param proto
|
|
25
|
+
* @returns {GetIdentityKeysResponse}
|
|
26
|
+
*/
|
|
27
|
+
static createFromProto(proto) {
|
|
28
|
+
// eslint-disable-next-line
|
|
29
|
+
const keys = proto.getV0().getKeys();
|
|
30
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
|
|
31
|
+
proto,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
let identityKeys = [];
|
|
35
|
+
if ((typeof keys === 'undefined' || keys === null) && !proof) {
|
|
36
|
+
throw new InvalidResponseError('Identity keys are not defined');
|
|
37
|
+
} else if (!proof) {
|
|
38
|
+
identityKeys = keys.getKeysBytesList();
|
|
39
|
+
if ((typeof identityKeys === 'undefined' || identityKeys === null) && !proof) {
|
|
40
|
+
throw new InvalidResponseError('Identity keys are not defined');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return new GetIdentityKeysResponse(
|
|
45
|
+
identityKeys,
|
|
46
|
+
metadata,
|
|
47
|
+
proof,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = GetIdentityKeysResponse;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetIdentityKeysRequest,
|
|
5
|
+
KeyRequestType,
|
|
6
|
+
SpecificKeys,
|
|
7
|
+
},
|
|
8
|
+
} = require('@dashevo/dapi-grpc');
|
|
9
|
+
const { UInt32Value } = require('google-protobuf/google/protobuf/wrappers_pb');
|
|
10
|
+
|
|
11
|
+
const GetIdentityKeysResponse = require('./GetIdentityKeysResponse');
|
|
12
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {GrpcTransport} grpcTransport
|
|
16
|
+
* @returns {getIdentityKeys}
|
|
17
|
+
*/
|
|
18
|
+
function getIdentityKeysFactory(grpcTransport) {
|
|
19
|
+
/**
|
|
20
|
+
* Fetch the version upgrade vote status
|
|
21
|
+
* @typedef {getIdentityKeys}
|
|
22
|
+
* @param {Buffer} identityId
|
|
23
|
+
* @param {number[]} keyIds
|
|
24
|
+
* @param {number} limit
|
|
25
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
26
|
+
* @returns {Promise<GetIdentityKeysResponse>}
|
|
27
|
+
*/
|
|
28
|
+
async function getIdentityKeys(identityId, keyIds, limit = 100, options = {}) {
|
|
29
|
+
const { GetIdentityKeysRequestV0 } = GetIdentityKeysRequest;
|
|
30
|
+
const getIdentityKeysRequest = new GetIdentityKeysRequest();
|
|
31
|
+
|
|
32
|
+
if (Buffer.isBuffer(identityId)) {
|
|
33
|
+
// eslint-disable-next-line no-param-reassign
|
|
34
|
+
identityId = Buffer.from(identityId);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getIdentityKeysRequest.setV0(
|
|
38
|
+
new GetIdentityKeysRequestV0()
|
|
39
|
+
.setIdentityId(identityId)
|
|
40
|
+
.setRequestType(new KeyRequestType()
|
|
41
|
+
.setSpecificKeys(new SpecificKeys().setKeyIdsList(keyIds)))
|
|
42
|
+
.setLimit(new UInt32Value([limit]))
|
|
43
|
+
.setProve(!!options.prove),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
let lastError;
|
|
47
|
+
|
|
48
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
49
|
+
for (let i = 0; i < 3; i += 1) {
|
|
50
|
+
try {
|
|
51
|
+
// eslint-disable-next-line no-await-in-loop
|
|
52
|
+
const getIdentityKeysResponse = await grpcTransport.request(
|
|
53
|
+
PlatformPromiseClient,
|
|
54
|
+
'getIdentityKeys',
|
|
55
|
+
getIdentityKeysRequest,
|
|
56
|
+
options,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return GetIdentityKeysResponse
|
|
60
|
+
.createFromProto(getIdentityKeysResponse);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (e instanceof InvalidResponseError) {
|
|
63
|
+
lastError = e;
|
|
64
|
+
} else {
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
71
|
+
// and we're throwing the last error encountered
|
|
72
|
+
throw lastError;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return getIdentityKeys;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = getIdentityKeysFactory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.7",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "1.0.0-dev.
|
|
30
|
-
"@dashevo/dash-spv": "1.0.0-dev.
|
|
29
|
+
"@dashevo/dapi-grpc": "1.0.0-dev.7",
|
|
30
|
+
"@dashevo/dash-spv": "1.0.0-dev.7",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.21.1",
|
|
32
|
-
"@dashevo/grpc-common": "1.0.0-dev.
|
|
33
|
-
"@dashevo/wasm-dpp": "1.0.0-dev.
|
|
32
|
+
"@dashevo/grpc-common": "1.0.0-dev.7",
|
|
33
|
+
"@dashevo/wasm-dpp": "1.0.0-dev.7",
|
|
34
34
|
"bs58": "^4.0.1",
|
|
35
35
|
"cbor": "^8.0.0",
|
|
36
36
|
"google-protobuf": "^3.12.2",
|