dash-platform-sdk 1.3.0-dev.2 → 1.3.0-dev.4
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 +1 -1
- package/package.json +2 -2
- package/src/names/index.d.ts +8 -0
- package/src/names/index.js +10 -0
- package/src/names/validateName.js +2 -2
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +3 -0
- package/src/tokens/getTokenDirectPurchasePrices.js +83 -0
- package/src/tokens/index.d.ts +9 -1
- package/src/tokens/index.js +18 -0
- package/src/types.d.ts +4 -0
- package/test/unit/ContestedResources.spec.js +6 -0
- package/test/unit/Tokens.spec.js +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-platform-sdk",
|
|
3
|
-
"version": "1.3.0-dev.
|
|
3
|
+
"version": "1.3.0-dev.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Lightweight SDK for accessing Dash Platform blockchain",
|
|
6
6
|
"ts-standard": {
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
"grpc-web": "^1.5.0",
|
|
58
58
|
"hash.js": "^1.1.7",
|
|
59
59
|
"nice-grpc-web": "^3.3.6",
|
|
60
|
-
"pshenmic-dpp": "1.0.
|
|
60
|
+
"pshenmic-dpp": "1.1.0-dev.6"
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/names/index.d.ts
CHANGED
|
@@ -57,4 +57,12 @@ export declare class NamesController {
|
|
|
57
57
|
* @return {string}
|
|
58
58
|
*/
|
|
59
59
|
normalizeLabel(label: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Validates a DPNS name that you would like to register
|
|
62
|
+
*
|
|
63
|
+
* @param fullName {string} full DPNS name (ex. pshenmic.dash)
|
|
64
|
+
*
|
|
65
|
+
* @return {string} null if valid or string with a reason
|
|
66
|
+
*/
|
|
67
|
+
validateName(fullName: string): null | string;
|
|
60
68
|
}
|
package/src/names/index.js
CHANGED
|
@@ -155,6 +155,16 @@ var NamesController = /** @class */ (function () {
|
|
|
155
155
|
NamesController.prototype.normalizeLabel = function (label) {
|
|
156
156
|
return (0, convertToHomographSafeChars_1.default)(label);
|
|
157
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* Validates a DPNS name that you would like to register
|
|
160
|
+
*
|
|
161
|
+
* @param fullName {string} full DPNS name (ex. pshenmic.dash)
|
|
162
|
+
*
|
|
163
|
+
* @return {string} null if valid or string with a reason
|
|
164
|
+
*/
|
|
165
|
+
NamesController.prototype.validateName = function (fullName) {
|
|
166
|
+
return (0, validateName_1.default)(fullName);
|
|
167
|
+
};
|
|
158
168
|
return NamesController;
|
|
159
169
|
}());
|
|
160
170
|
exports.NamesController = NamesController;
|
|
@@ -6,9 +6,9 @@ function validateName(fullName) {
|
|
|
6
6
|
if (chunks.length !== 2) {
|
|
7
7
|
return 'Name to search should be a full domain name (ex. pshenmic.dash)';
|
|
8
8
|
}
|
|
9
|
-
var parentDomainName = chunks[1];
|
|
9
|
+
var label = chunks[0], parentDomainName = chunks[1];
|
|
10
10
|
if (parentDomainName !== 'dash') {
|
|
11
11
|
return 'Root domain must be .dash';
|
|
12
12
|
}
|
|
13
|
-
return null;
|
|
13
|
+
return /^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$/.test(label) ? null : 'Unacceptable label name';
|
|
14
14
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
+
import { IdentifierLike, TokenDirectPurchasePrices } from '../types';
|
|
3
|
+
export default function getTokenDirectPurchasePrices(grpcPool: GRPCConnectionPool, tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.default = getTokenDirectPurchasePrices;
|
|
40
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
41
|
+
var platform_1 = require("../../proto/generated/platform");
|
|
42
|
+
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
43
|
+
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
44
|
+
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
|
+
function getTokenDirectPurchasePrices(grpcPool, tokenIdentifiers) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var tokenIds, request, v0, _a, proof, metadata, _b, rootHash, prices, quorumPublicKey, verify;
|
|
48
|
+
return __generator(this, function (_c) {
|
|
49
|
+
switch (_c.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
tokenIds = tokenIdentifiers.map(function (tokenId) { return new pshenmic_dpp_1.IdentifierWASM(tokenId).bytes(); });
|
|
52
|
+
request = platform_1.GetTokenDirectPurchasePricesRequest.fromPartial({
|
|
53
|
+
v0: {
|
|
54
|
+
tokenIds: tokenIds,
|
|
55
|
+
prove: true
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return [4 /*yield*/, grpcPool.getClient().getTokenDirectPurchasePrices(request)];
|
|
59
|
+
case 1:
|
|
60
|
+
v0 = (_c.sent()).v0;
|
|
61
|
+
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
62
|
+
if (proof == null) {
|
|
63
|
+
throw new Error('Proof not found');
|
|
64
|
+
}
|
|
65
|
+
if (metadata == null) {
|
|
66
|
+
throw new Error('Metadata not found');
|
|
67
|
+
}
|
|
68
|
+
_b = (0, pshenmic_dpp_1.verifyTokenDirectPurchasePrices)(proof.grovedbProof, tokenIds, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, prices = _b.prices;
|
|
69
|
+
if (prices == null) {
|
|
70
|
+
throw new Error('Prices not found');
|
|
71
|
+
}
|
|
72
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
+
case 2:
|
|
74
|
+
quorumPublicKey = _c.sent();
|
|
75
|
+
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
76
|
+
if (!verify) {
|
|
77
|
+
throw new Error('Failed to verify query');
|
|
78
|
+
}
|
|
79
|
+
return [2 /*return*/, prices];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../types';
|
|
2
|
+
import { IdentifierLike, TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../types';
|
|
3
3
|
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances';
|
|
4
4
|
import { IdentityTokenBalances } from './getIdentityTokensBalances';
|
|
5
5
|
import { TokenContractInfo } from './getTokenContractInfo';
|
|
@@ -47,6 +47,14 @@ export declare class TokensController {
|
|
|
47
47
|
* @return {Promise<TokenTotalSupply>}
|
|
48
48
|
*/
|
|
49
49
|
getTokenTotalSupply(tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a tokens prices
|
|
52
|
+
*
|
|
53
|
+
* @param tokenIdentifiers {IdentifierLike[]} - token ids which price we need
|
|
54
|
+
*
|
|
55
|
+
* @return {Promise<TokenDirectPurchasePrices[]>}
|
|
56
|
+
*/
|
|
57
|
+
getTokensDirectPurchasePrice(tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
50
58
|
/**
|
|
51
59
|
* Creates a Token Base Transition that contains base information about token transition
|
|
52
60
|
*
|
package/src/tokens/index.js
CHANGED
|
@@ -44,6 +44,7 @@ var getTokenTotalSupply_1 = require("./getTokenTotalSupply");
|
|
|
44
44
|
var createStateTransition_1 = require("./createStateTransition");
|
|
45
45
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
46
46
|
var getIdentityContractNonce_1 = require("../identities/getIdentityContractNonce");
|
|
47
|
+
var getTokenDirectPurchasePrices_1 = require("./getTokenDirectPurchasePrices");
|
|
47
48
|
/**
|
|
48
49
|
* Tokens controller for requesting information about tokens and tokens holders
|
|
49
50
|
*
|
|
@@ -123,6 +124,23 @@ var TokensController = /** @class */ (function () {
|
|
|
123
124
|
});
|
|
124
125
|
});
|
|
125
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Retrieves a tokens prices
|
|
129
|
+
*
|
|
130
|
+
* @param tokenIdentifiers {IdentifierLike[]} - token ids which price we need
|
|
131
|
+
*
|
|
132
|
+
* @return {Promise<TokenDirectPurchasePrices[]>}
|
|
133
|
+
*/
|
|
134
|
+
TokensController.prototype.getTokensDirectPurchasePrice = function (tokenIdentifiers) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0: return [4 /*yield*/, (0, getTokenDirectPurchasePrices_1.default)(this.grpcPool, tokenIdentifiers)];
|
|
139
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
126
144
|
/**
|
|
127
145
|
* Creates a Token Base Transition that contains base information about token transition
|
|
128
146
|
*
|
package/src/types.d.ts
CHANGED
|
@@ -200,4 +200,8 @@ export interface TokenTotalSupply {
|
|
|
200
200
|
totalSystemAmount: bigint;
|
|
201
201
|
totalAggregatedAmountInUserAccounts: bigint;
|
|
202
202
|
}
|
|
203
|
+
export interface TokenDirectPurchasePrices {
|
|
204
|
+
tokenId: IdentifierWASM;
|
|
205
|
+
price: TokenPricingScheduleWASM;
|
|
206
|
+
}
|
|
203
207
|
export type ResourceVoteChoice = IdentifierLike | 'lock' | 'abstain';
|
|
@@ -276,6 +276,8 @@ describe('Contested Resources', function () {
|
|
|
276
276
|
identityNonce = _a.sent();
|
|
277
277
|
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
278
278
|
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
279
|
+
// test key disabled
|
|
280
|
+
identityPublicKey.removeDisabledAt();
|
|
279
281
|
stateTransition.sign(privateKey, identityPublicKey);
|
|
280
282
|
return [2 /*return*/];
|
|
281
283
|
}
|
|
@@ -303,6 +305,8 @@ describe('Contested Resources', function () {
|
|
|
303
305
|
identityNonce = _a.sent();
|
|
304
306
|
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
305
307
|
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
308
|
+
// test key disabled
|
|
309
|
+
identityPublicKey.removeDisabledAt();
|
|
306
310
|
stateTransition.sign(privateKey, identityPublicKey);
|
|
307
311
|
return [2 /*return*/];
|
|
308
312
|
}
|
|
@@ -330,6 +334,8 @@ describe('Contested Resources', function () {
|
|
|
330
334
|
identityNonce = _a.sent();
|
|
331
335
|
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
332
336
|
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
337
|
+
// test key disabled
|
|
338
|
+
identityPublicKey.removeDisabledAt();
|
|
333
339
|
stateTransition.sign(privateKey, identityPublicKey);
|
|
334
340
|
return [2 /*return*/];
|
|
335
341
|
}
|
package/test/unit/Tokens.spec.js
CHANGED
|
@@ -85,6 +85,23 @@ describe('Tokens', function () {
|
|
|
85
85
|
});
|
|
86
86
|
}); });
|
|
87
87
|
test('should be able to get token identities token balances', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
88
|
+
var tokensPrices;
|
|
89
|
+
return __generator(this, function (_a) {
|
|
90
|
+
switch (_a.label) {
|
|
91
|
+
case 0: return [4 /*yield*/, sdk.tokens.getTokensDirectPurchasePrice([
|
|
92
|
+
'3oTHkj8nqn82QkZRHkmUmNBX696nzE1rg1fwPRpemEdz',
|
|
93
|
+
'6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C'
|
|
94
|
+
])];
|
|
95
|
+
case 1:
|
|
96
|
+
tokensPrices = _a.sent();
|
|
97
|
+
expect(tokensPrices.length).toEqual(2);
|
|
98
|
+
expect(tokensPrices[0].tokenId).toBeTruthy();
|
|
99
|
+
expect(tokensPrices[0].price).toBeTruthy();
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}); });
|
|
104
|
+
test('should be able to get tokens direct purchase prices', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
88
105
|
var tokensIdentityBalance;
|
|
89
106
|
return __generator(this, function (_a) {
|
|
90
107
|
switch (_a.label) {
|