@dashevo/dapi-client 1.0.0-pr.1694.9 → 1.0.0-pr.1825.2
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/lib/methods/platform/PlatformMethodsFacade.js +6 -0
- package/lib/methods/platform/getIdentityContractNonce/GetIdentityContractNonceResponse.js +49 -0
- package/lib/methods/platform/getIdentityContractNonce/getIdentityContractNonceFactory.js +81 -0
- package/lib/methods/platform/getIdentityKeys/GetIdentityKeysResponse.js +52 -0
- package/lib/methods/platform/getIdentityKeys/getIdentityKeysFactory.js +78 -0
- package/lib/methods/platform/getIdentityNonce/GetIdentityNonceResponse.js +49 -0
- package/lib/methods/platform/getIdentityNonce/getIdentityNonceFactory.js +74 -0
- package/lib/transport/GrpcTransport/createGrpcTransportError.js +1 -1
- package/package.json +5 -5
|
@@ -9,6 +9,9 @@ const getConsensusParamsFactory = require('./getConsensusParams/getConsensusPara
|
|
|
9
9
|
const getEpochsInfoFactory = require('./getEpochsInfo/getEpochsInfoFactory');
|
|
10
10
|
const getProtocolVersionUpgradeVoteStatusFactory = require('./getProtocolVersionUpgradeVoteStatus/getProtocolVersionUpgradeVoteStatusFactory');
|
|
11
11
|
const getProtocolVersionUpgradeStateFactory = require('./getProtocolVersionUpgradeState/getProtocolVersionUpgradeStateFactory');
|
|
12
|
+
const getIdentityContractNonceFactory = require('./getIdentityContractNonce/getIdentityContractNonceFactory');
|
|
13
|
+
const getIdentityNonceFactory = require('./getIdentityNonce/getIdentityNonceFactory');
|
|
14
|
+
const getIdentityKeysFactory = require('./getIdentityKeys/getIdentityKeysFactory');
|
|
12
15
|
|
|
13
16
|
class PlatformMethodsFacade {
|
|
14
17
|
/**
|
|
@@ -28,6 +31,9 @@ class PlatformMethodsFacade {
|
|
|
28
31
|
grpcTransport,
|
|
29
32
|
);
|
|
30
33
|
this.getProtocolVersionUpgradeState = getProtocolVersionUpgradeStateFactory(grpcTransport);
|
|
34
|
+
this.getIdentityContractNonce = getIdentityContractNonceFactory(grpcTransport);
|
|
35
|
+
this.getIdentityNonce = getIdentityNonceFactory(grpcTransport);
|
|
36
|
+
this.getIdentityKeys = getIdentityKeysFactory(grpcTransport);
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
39
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
3
|
+
|
|
4
|
+
const IDENTITY_CONTRACT_NONCE_VALUE_FILTER = 0xFFFFFFFFFF;
|
|
5
|
+
|
|
6
|
+
class GetIdentityContractNonceResponse extends AbstractResponse {
|
|
7
|
+
/**
|
|
8
|
+
* @param {number} identityContractNonce
|
|
9
|
+
* @param {Metadata} metadata
|
|
10
|
+
* @param {Proof} [proof]
|
|
11
|
+
*/
|
|
12
|
+
constructor(identityContractNonce, metadata, proof = undefined) {
|
|
13
|
+
super(metadata, proof);
|
|
14
|
+
|
|
15
|
+
this.identityContractNonce = identityContractNonce;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
getIdentityContractNonce() {
|
|
22
|
+
return this.identityContractNonce;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param proto
|
|
27
|
+
* @returns {GetIdentityContractNonceResponse}
|
|
28
|
+
*/
|
|
29
|
+
static createFromProto(proto) {
|
|
30
|
+
// eslint-disable-next-line
|
|
31
|
+
const identityContractNonce = proto.getV0()
|
|
32
|
+
.getIdentityContractNonce() & IDENTITY_CONTRACT_NONCE_VALUE_FILTER;
|
|
33
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
|
|
34
|
+
proto,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if ((typeof identityContractNonce === 'undefined' || identityContractNonce === null) && !proof) {
|
|
38
|
+
throw new InvalidResponseError('Contract nonce data is not defined');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new GetIdentityContractNonceResponse(
|
|
42
|
+
identityContractNonce,
|
|
43
|
+
metadata,
|
|
44
|
+
proof,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = GetIdentityContractNonceResponse;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetIdentityContractNonceRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const GetIdentityContractNonceResponse = require('./GetIdentityContractNonceResponse');
|
|
9
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {GrpcTransport} grpcTransport
|
|
13
|
+
* @returns {getIdentityContractNonce}
|
|
14
|
+
*/
|
|
15
|
+
function getIdentityContractNonceFactory(grpcTransport) {
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the version upgrade vote status
|
|
18
|
+
* @typedef {getIdentityContractNonce}
|
|
19
|
+
* @param {Buffer} identityId
|
|
20
|
+
* @param {Buffer} contractId
|
|
21
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
22
|
+
* @returns {Promise<GetIdentityContractNonceResponse>}
|
|
23
|
+
*/
|
|
24
|
+
async function getIdentityContractNonce(identityId, contractId, options = {}) {
|
|
25
|
+
const {
|
|
26
|
+
GetIdentityContractNonceRequestV0,
|
|
27
|
+
} = GetIdentityContractNonceRequest;
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line max-len
|
|
30
|
+
const getIdentityContractNonceRequest = new GetIdentityContractNonceRequest();
|
|
31
|
+
|
|
32
|
+
if (Buffer.isBuffer(identityId)) {
|
|
33
|
+
// eslint-disable-next-line no-param-reassign
|
|
34
|
+
identityId = Buffer.from(identityId);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (Buffer.isBuffer(contractId)) {
|
|
38
|
+
// eslint-disable-next-line no-param-reassign
|
|
39
|
+
contractId = Buffer.from(contractId);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getIdentityContractNonceRequest.setV0(
|
|
43
|
+
new GetIdentityContractNonceRequestV0()
|
|
44
|
+
.setIdentityId(identityId)
|
|
45
|
+
.setContractId(contractId)
|
|
46
|
+
.setProve(!!options.prove),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
let lastError;
|
|
50
|
+
|
|
51
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
52
|
+
for (let i = 0; i < 3; i += 1) {
|
|
53
|
+
try {
|
|
54
|
+
// eslint-disable-next-line no-await-in-loop
|
|
55
|
+
const getIdentityContractNonceResponse = await grpcTransport.request(
|
|
56
|
+
PlatformPromiseClient,
|
|
57
|
+
'getIdentityContractNonce',
|
|
58
|
+
getIdentityContractNonceRequest,
|
|
59
|
+
options,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return GetIdentityContractNonceResponse
|
|
63
|
+
.createFromProto(getIdentityContractNonceResponse);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
if (e instanceof InvalidResponseError) {
|
|
66
|
+
lastError = e;
|
|
67
|
+
} else {
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
74
|
+
// and we're throwing the last error encountered
|
|
75
|
+
throw lastError;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return getIdentityContractNonce;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = getIdentityContractNonceFactory;
|
|
@@ -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;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
3
|
+
|
|
4
|
+
const IDENTITY_NONCE_VALUE_FILTER = 0xFFFFFFFFFF;
|
|
5
|
+
|
|
6
|
+
class GetIdentityNonceResponse extends AbstractResponse {
|
|
7
|
+
/**
|
|
8
|
+
* @param {number} identityNonce
|
|
9
|
+
* @param {Metadata} metadata
|
|
10
|
+
* @param {Proof} [proof]
|
|
11
|
+
*/
|
|
12
|
+
constructor(identityNonce, metadata, proof = undefined) {
|
|
13
|
+
super(metadata, proof);
|
|
14
|
+
|
|
15
|
+
this.identityNonce = identityNonce;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
getIdentityNonce() {
|
|
22
|
+
return this.identityNonce;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param proto
|
|
27
|
+
* @returns {GetIdentityNonceResponse}
|
|
28
|
+
*/
|
|
29
|
+
static createFromProto(proto) {
|
|
30
|
+
// eslint-disable-next-line
|
|
31
|
+
const identityNonce = proto.getV0()
|
|
32
|
+
.getIdentityNonce() & IDENTITY_NONCE_VALUE_FILTER;
|
|
33
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
|
|
34
|
+
proto,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if ((typeof identityNonce === 'undefined' || identityNonce === null) && !proof) {
|
|
38
|
+
throw new InvalidResponseError('Nonce data is not defined');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new GetIdentityNonceResponse(
|
|
42
|
+
identityNonce,
|
|
43
|
+
metadata,
|
|
44
|
+
proof,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = GetIdentityNonceResponse;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetIdentityNonceRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const GetIdentityNonceResponse = require('./GetIdentityNonceResponse');
|
|
9
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {GrpcTransport} grpcTransport
|
|
13
|
+
* @returns {getIdentityNonce}
|
|
14
|
+
*/
|
|
15
|
+
function getIdentityNonceFactory(grpcTransport) {
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the version upgrade vote status
|
|
18
|
+
* @typedef {getIdentityNonce}
|
|
19
|
+
* @param {Buffer} identityId
|
|
20
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
21
|
+
* @returns {Promise<GetIdentityNonceResponse>}
|
|
22
|
+
*/
|
|
23
|
+
async function getIdentityNonce(identityId, options = {}) {
|
|
24
|
+
const {
|
|
25
|
+
GetIdentityNonceRequestV0,
|
|
26
|
+
} = GetIdentityNonceRequest;
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line max-len
|
|
29
|
+
const getIdentityNonceRequest = new GetIdentityNonceRequest();
|
|
30
|
+
|
|
31
|
+
if (Buffer.isBuffer(identityId)) {
|
|
32
|
+
// eslint-disable-next-line no-param-reassign
|
|
33
|
+
identityId = Buffer.from(identityId);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getIdentityNonceRequest.setV0(
|
|
37
|
+
new GetIdentityNonceRequestV0()
|
|
38
|
+
.setIdentityId(identityId)
|
|
39
|
+
.setProve(!!options.prove),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
let lastError;
|
|
43
|
+
|
|
44
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
45
|
+
for (let i = 0; i < 3; i += 1) {
|
|
46
|
+
try {
|
|
47
|
+
// eslint-disable-next-line no-await-in-loop
|
|
48
|
+
const getIdentityNonceResponse = await grpcTransport.request(
|
|
49
|
+
PlatformPromiseClient,
|
|
50
|
+
'getIdentityNonce',
|
|
51
|
+
getIdentityNonceRequest,
|
|
52
|
+
options,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return GetIdentityNonceResponse
|
|
56
|
+
.createFromProto(getIdentityNonceResponse);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
if (e instanceof InvalidResponseError) {
|
|
59
|
+
lastError = e;
|
|
60
|
+
} else {
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
67
|
+
// and we're throwing the last error encountered
|
|
68
|
+
throw lastError;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return getIdentityNonce;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = getIdentityNonceFactory;
|
|
@@ -118,7 +118,7 @@ async function createGrpcTransportError(grpcError, dapiAddress) {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// DPP consensus errors
|
|
121
|
-
if (code >=
|
|
121
|
+
if (code >= 10000 && code < 50000) {
|
|
122
122
|
const consensusError = deserializeConsensusError(data.serializedError || []);
|
|
123
123
|
|
|
124
124
|
delete data.serializedError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "1.0.0-pr.
|
|
3
|
+
"version": "1.0.0-pr.1825.2",
|
|
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-pr.
|
|
30
|
-
"@dashevo/dash-spv": "1.0.0-pr.
|
|
29
|
+
"@dashevo/dapi-grpc": "1.0.0-pr.1825.2",
|
|
30
|
+
"@dashevo/dash-spv": "1.0.0-pr.1825.2",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.21.1",
|
|
32
|
-
"@dashevo/grpc-common": "1.0.0-pr.
|
|
33
|
-
"@dashevo/wasm-dpp": "1.0.0-pr.
|
|
32
|
+
"@dashevo/grpc-common": "1.0.0-pr.1825.2",
|
|
33
|
+
"@dashevo/wasm-dpp": "1.0.0-pr.1825.2",
|
|
34
34
|
"bs58": "^4.0.1",
|
|
35
35
|
"cbor": "^8.0.0",
|
|
36
36
|
"google-protobuf": "^3.12.2",
|