@dashevo/dapi-client 1.0.0-dev.3 → 1.0.0-dev.5
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 +4 -0
- package/lib/methods/platform/getIdentityContractNonce/GetIdentityContractNonceResponse.js +49 -0
- package/lib/methods/platform/getIdentityContractNonce/getIdentityContractNonceFactory.js +81 -0
- package/lib/methods/platform/getIdentityNonce/GetIdentityNonceResponse.js +49 -0
- package/lib/methods/platform/getIdentityNonce/getIdentityNonceFactory.js +74 -0
- package/package.json +6 -6
|
@@ -9,6 +9,8 @@ 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');
|
|
12
14
|
|
|
13
15
|
class PlatformMethodsFacade {
|
|
14
16
|
/**
|
|
@@ -28,6 +30,8 @@ class PlatformMethodsFacade {
|
|
|
28
30
|
grpcTransport,
|
|
29
31
|
);
|
|
30
32
|
this.getProtocolVersionUpgradeState = getProtocolVersionUpgradeStateFactory(grpcTransport);
|
|
33
|
+
this.getIdentityContractNonce = getIdentityContractNonceFactory(grpcTransport);
|
|
34
|
+
this.getIdentityNonce = getIdentityNonceFactory(grpcTransport);
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
|
|
@@ -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,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;
|
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.5",
|
|
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.
|
|
31
|
-
"@dashevo/dashcore-lib": "~0.21.
|
|
32
|
-
"@dashevo/grpc-common": "1.0.0-dev.
|
|
33
|
-
"@dashevo/wasm-dpp": "1.0.0-dev.
|
|
29
|
+
"@dashevo/dapi-grpc": "1.0.0-dev.5",
|
|
30
|
+
"@dashevo/dash-spv": "1.0.0-dev.5",
|
|
31
|
+
"@dashevo/dashcore-lib": "~0.21.1",
|
|
32
|
+
"@dashevo/grpc-common": "1.0.0-dev.5",
|
|
33
|
+
"@dashevo/wasm-dpp": "1.0.0-dev.5",
|
|
34
34
|
"bs58": "^4.0.1",
|
|
35
35
|
"cbor": "^8.0.0",
|
|
36
36
|
"google-protobuf": "^3.12.2",
|