dash-platform-sdk 1.3.0 → 1.3.2-dev.1
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/bundle.min.js +17 -17
- package/package.json +3 -3
- package/src/stateTransitions/broadcast.js +17 -6
- package/src/utils/deserializeConsensusError.d.ts +1 -0
- package/src/utils/deserializeConsensusError.js +17 -0
- package/src/utils/index.d.ts +7 -0
- package/src/utils/index.js +10 -0
- package/test/unit/SDK.spec.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-platform-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2-dev.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Lightweight SDK for accessing Dash Platform blockchain",
|
|
6
6
|
"ts-standard": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"docs": "typedoc"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"pshenmic-dpp": "1.1.2-dev.
|
|
51
|
+
"pshenmic-dpp": "1.1.2-dev.9"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@bufbuild/protobuf": "^2.6.0",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"@scure/bip39": "^2.0.0",
|
|
60
60
|
"@scure/btc-signer": "^2.0.1",
|
|
61
61
|
"cbor-x": "^1.6.0",
|
|
62
|
-
"pshenmic-dpp": "1.1.2-dev.
|
|
62
|
+
"pshenmic-dpp": "1.1.2-dev.9"
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { BroadcastStateTransitionRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { deserializeConsensusError } from '../utils/deserializeConsensusError.js';
|
|
2
3
|
export default async function broadcast(grpcPool, stateTransition) {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
try {
|
|
5
|
+
if (stateTransition.signature?.length === 0) {
|
|
6
|
+
throw new Error('State Transition is not signed');
|
|
7
|
+
}
|
|
8
|
+
const broadcastStateTransitionRequest = BroadcastStateTransitionRequest.create({
|
|
9
|
+
stateTransition: stateTransition.bytes()
|
|
10
|
+
});
|
|
11
|
+
await grpcPool.getClient().broadcastStateTransition(broadcastStateTransitionRequest);
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
if (err.meta?.['dash-serialized-consensus-error-bin']?.length !== 0) {
|
|
15
|
+
throw new Error(deserializeConsensusError(err.meta['dash-serialized-consensus-error-bin']));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
5
20
|
}
|
|
6
|
-
const broadcastStateTransitionRequest = BroadcastStateTransitionRequest.create({
|
|
7
|
-
stateTransition: stateTransition.bytes()
|
|
8
|
-
});
|
|
9
|
-
await grpcPool.getClient().broadcastStateTransition(broadcastStateTransitionRequest);
|
|
10
21
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function deserializeConsensusError(error: string | Uint8Array): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { base64 } from '@scure/base';
|
|
2
|
+
import { ConsensusErrorWASM } from 'pshenmic-dpp';
|
|
3
|
+
export function deserializeConsensusError(error) {
|
|
4
|
+
let normError;
|
|
5
|
+
if (typeof error === 'string') {
|
|
6
|
+
// @scure/base64 works only with padded base64, but cbor can return unpadded base64
|
|
7
|
+
const padding = error.length % 4;
|
|
8
|
+
if (padding !== 0) {
|
|
9
|
+
error += '='.repeat(4 - padding);
|
|
10
|
+
}
|
|
11
|
+
normError = base64.decode(error);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
normError = error;
|
|
15
|
+
}
|
|
16
|
+
return ConsensusErrorWASM.deserialize(normError).message;
|
|
17
|
+
}
|
package/src/utils/index.d.ts
CHANGED
|
@@ -70,4 +70,11 @@ export declare class UtilsController {
|
|
|
70
70
|
* @return {boolean}
|
|
71
71
|
* */
|
|
72
72
|
validateIdentifier(identifier: IdentifierLike): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Allows to deserialize consensus error
|
|
75
|
+
*
|
|
76
|
+
* @param error {string | Uint8Array} error in base64 or bytes
|
|
77
|
+
* @return {string}
|
|
78
|
+
*/
|
|
79
|
+
deserializeConsensusError(error: string | Uint8Array): string;
|
|
73
80
|
}
|
package/src/utils/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import bytesToHex from './bytesToHex.js';
|
|
|
5
5
|
import { createVoterIdentityId } from './createVoterIdentityId.js';
|
|
6
6
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
7
7
|
import { createMasternodeIdentityId } from './createMasternodeIdentityId.js';
|
|
8
|
+
import { deserializeConsensusError } from './deserializeConsensusError.js';
|
|
8
9
|
/**
|
|
9
10
|
* Collection of conversion functions
|
|
10
11
|
*
|
|
@@ -98,4 +99,13 @@ export class UtilsController {
|
|
|
98
99
|
return false;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Allows to deserialize consensus error
|
|
104
|
+
*
|
|
105
|
+
* @param error {string | Uint8Array} error in base64 or bytes
|
|
106
|
+
* @return {string}
|
|
107
|
+
*/
|
|
108
|
+
deserializeConsensusError(error) {
|
|
109
|
+
return deserializeConsensusError(error);
|
|
110
|
+
}
|
|
101
111
|
}
|
package/test/unit/SDK.spec.js
CHANGED
|
@@ -7,4 +7,8 @@ describe('DashPlatformSDK', () => {
|
|
|
7
7
|
test('should be constructable throw `new`', () => {
|
|
8
8
|
expect(sdk).toEqual(expect.any(DashPlatformSDK));
|
|
9
9
|
});
|
|
10
|
+
test('should be able to deserialize consensus error', () => {
|
|
11
|
+
const err = sdk.utils.deserializeConsensusError('AwIiSW52YWxpZCBTdGF0ZSBUcmFuc2l0aW9uIHNpZ25hdHVyZQ');
|
|
12
|
+
expect(err).toEqual('Invalid State Transition signature');
|
|
13
|
+
});
|
|
10
14
|
});
|