dash-platform-sdk 1.3.0-dev.3 → 1.3.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/bundle.min.js +21 -2
- package/package.json +30 -31
- package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
- package/proto/generated/platform.client.d.ts +251 -0
- package/proto/generated/platform.d.ts +3682 -1939
- package/src/DashPlatformSDK.d.ts +5 -4
- package/src/contestedResources/createStateTransition.d.ts +1 -2
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/keyPair/deriveChild.d.ts +2 -2
- package/src/keyPair/derivePath.d.ts +2 -2
- package/src/keyPair/index.d.ts +39 -114
- package/src/keyPair/mnemonicToSeed.d.ts +1 -1
- package/src/names/searchByIdentity.d.ts +1 -1
- package/src/node/index.d.ts +3 -3
- package/src/node/totalCredits.d.ts +2 -1
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +3 -0
- package/src/tokens/index.d.ts +9 -1
- package/src/types.d.ts +10 -12
- package/src/utils/bytesToTypedArray.d.ts +1 -0
- package/src/utils/calculateMsgHash.d.ts +1 -1
- package/src/utils/calculateSignHash.d.ts +1 -1
- package/src/utils/calculateStateIdHash.d.ts +1 -1
- package/src/utils/createVoterIdentityId.d.ts +1 -1
- package/src/utils/getEvonodeList.d.ts +2 -2
- package/src/utils/sha256.d.ts +1 -1
- package/src/utils/signHash.d.ts +1 -1
- package/src/utils/signRequestId.d.ts +1 -1
- package/src/utils/verifyTenderdashProof.d.ts +1 -1
- package/src/voting/createStateTransition.d.ts +1 -2
- package/src/voting/index.d.ts +3 -4
- package/bundle.min.js.LICENSE.txt +0 -1
- package/index.js +0 -5
- package/proto/generated/google/protobuf/wrappers.js +0 -398
- package/proto/generated/platform.js +0 -18524
- package/src/DashPlatformSDK.js +0 -91
- package/src/constants.js +0 -13
- package/src/contestedResources/createStateTransition.js +0 -9
- package/src/contestedResources/getContestedResourceVoteState.js +0 -123
- package/src/contestedResources/index.js +0 -76
- package/src/dataContracts/create.js +0 -14
- package/src/dataContracts/createStateTransition.js +0 -23
- package/src/dataContracts/getDataContractByIdentifier.js +0 -87
- package/src/dataContracts/index.js +0 -103
- package/src/documents/create.js +0 -7
- package/src/documents/createStateTransition.js +0 -64
- package/src/documents/index.js +0 -130
- package/src/documents/query.js +0 -94
- package/src/grpcConnectionPool.js +0 -137
- package/src/identities/createStateTransition.js +0 -46
- package/src/identities/getIdentityBalance.js +0 -83
- package/src/identities/getIdentityByIdentifier.js +0 -83
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +0 -85
- package/src/identities/getIdentityByPublicKeyHash.js +0 -83
- package/src/identities/getIdentityContractNonce.js +0 -86
- package/src/identities/getIdentityNonce.js +0 -84
- package/src/identities/getIdentityPublicKeys.js +0 -85
- package/src/identities/index.js +0 -237
- package/src/keyPair/deriveChild.js +0 -50
- package/src/keyPair/derivePath.js +0 -50
- package/src/keyPair/index.js +0 -323
- package/src/keyPair/keyToPublicKey.d.ts +0 -2
- package/src/keyPair/keyToPublicKey.js +0 -47
- package/src/keyPair/keyToWalletId.d.ts +0 -2
- package/src/keyPair/keyToWalletId.js +0 -50
- package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
- package/src/keyPair/keyToXPrivateKey.js +0 -50
- package/src/keyPair/keyToXPublicKey.d.ts +0 -3
- package/src/keyPair/keyToXPublicKey.js +0 -50
- package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
- package/src/keyPair/mnemonicToIdentityKey.js +0 -57
- package/src/keyPair/mnemonicToSeed.js +0 -47
- package/src/keyPair/mnemonicToWallet.d.ts +0 -2
- package/src/keyPair/mnemonicToWallet.js +0 -55
- package/src/keyPair/privateKeyToWif.d.ts +0 -2
- package/src/keyPair/privateKeyToWif.js +0 -50
- package/src/keyPair/publicKeyToAddress.d.ts +0 -2
- package/src/keyPair/publicKeyToAddress.js +0 -50
- package/src/keyPair/seedToWallet.d.ts +0 -2
- package/src/keyPair/seedToWallet.js +0 -50
- package/src/keyPair/walletToIdentityKey.d.ts +0 -3
- package/src/keyPair/walletToIdentityKey.js +0 -56
- package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
- package/src/keyPair/xkeyToHDXKey.js +0 -50
- package/src/names/index.js +0 -170
- package/src/names/registerName.js +0 -131
- package/src/names/searchByIdentity.js +0 -51
- package/src/names/searchByName.js +0 -64
- package/src/names/testNameContested.js +0 -6
- package/src/names/validateName.js +0 -14
- package/src/node/epochs.js +0 -88
- package/src/node/index.js +0 -102
- package/src/node/status.js +0 -85
- package/src/node/totalCredits.js +0 -76
- package/src/signer/AbstractSigner.js +0 -2
- package/src/signer/PrivateKeySigner.d.ts +0 -0
- package/src/signer/PrivateKeySigner.js +0 -64
- package/src/signer/setSigner.js +0 -8
- package/src/stateTransitions/broadcast.js +0 -60
- package/src/stateTransitions/index.js +0 -87
- package/src/stateTransitions/waitForStateTransitionResult.js +0 -60
- package/src/tokens/createStateTransition.js +0 -79
- package/src/tokens/getIdentitiesTokenBalances.js +0 -86
- package/src/tokens/getIdentityTokensBalances.js +0 -86
- package/src/tokens/getTokenContractInfo.js +0 -86
- package/src/tokens/getTokenTotalSupply.js +0 -84
- package/src/tokens/index.js +0 -175
- package/src/types.js +0 -25
- package/src/utils/base58ToBytes.js +0 -7
- package/src/utils/bytesToHex.js +0 -6
- package/src/utils/calculateMsgHash.js +0 -34
- package/src/utils/calculateSignHash.js +0 -11
- package/src/utils/calculateStateIdHash.js +0 -12
- package/src/utils/convertToHomographSafeChars.js +0 -14
- package/src/utils/createVoterIdentityId.js +0 -12
- package/src/utils/getEvonodeList.js +0 -63
- package/src/utils/getQuorumPublicKey.js +0 -69
- package/src/utils/getRandomArrayItem.js +0 -6
- package/src/utils/getRandomBytes.js +0 -7
- package/src/utils/hexToBytes.js +0 -7
- package/src/utils/index.js +0 -68
- package/src/utils/indexBytesToString.js +0 -7
- package/src/utils/sha256.js +0 -13
- package/src/utils/signHash.js +0 -25
- package/src/utils/signRequestId.js +0 -22
- package/src/utils/sleep.js +0 -51
- package/src/utils/stringToIndexValueBytes.js +0 -13
- package/src/utils/verifyTenderdashProof.js +0 -30
- package/src/voting/createStateTransition.js +0 -9
- package/src/voting/createVote.js +0 -8
- package/src/voting/index.js +0 -62
- package/test/unit/ContestedResources.spec.js +0 -338
- package/test/unit/DataContract.spec.js +0 -142
- package/test/unit/Document.spec.js +0 -199
- package/test/unit/Identity.spec.js +0 -357
- package/test/unit/KeyPair.spec.js +0 -149
- package/test/unit/Names.spec.js +0 -96
- package/test/unit/Node.spec.js +0 -129
- package/test/unit/SDK.spec.js +0 -12
- package/test/unit/Tokens.spec.js +0 -271
|
@@ -1,338 +0,0 @@
|
|
|
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
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
40
|
-
var types_1 = require("../../src/types");
|
|
41
|
-
var stringToIndexValueBytes_1 = require("../../src/utils/stringToIndexValueBytes");
|
|
42
|
-
var sdk;
|
|
43
|
-
var contract;
|
|
44
|
-
describe('Contested Resources', function () {
|
|
45
|
-
beforeAll(function () {
|
|
46
|
-
sdk = new types_1.DashPlatformSDK({ network: 'testnet' });
|
|
47
|
-
contract = new pshenmic_dpp_1.DataContractWASM('11111111111111111111111111111111', BigInt(1), {
|
|
48
|
-
domain: {
|
|
49
|
-
type: 'object',
|
|
50
|
-
indices: [
|
|
51
|
-
{
|
|
52
|
-
name: 'parentNameAndLabel',
|
|
53
|
-
unique: true,
|
|
54
|
-
contested: {
|
|
55
|
-
resolution: 0,
|
|
56
|
-
description: 'If the normalized label part of this index is less than 20 characters (all alphabet a-z, A-Z, 0, 1, and -) then a masternode vote contest takes place to give out the name',
|
|
57
|
-
fieldMatches: [
|
|
58
|
-
{
|
|
59
|
-
field: 'normalizedLabel',
|
|
60
|
-
regexPattern: '^[a-zA-Z01-]{3,19}$'
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
properties: [
|
|
65
|
-
{
|
|
66
|
-
normalizedParentDomainName: 'asc'
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
normalizedLabel: 'asc'
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: 'identityId',
|
|
75
|
-
properties: [
|
|
76
|
-
{
|
|
77
|
-
'records.identity': 'asc'
|
|
78
|
-
}
|
|
79
|
-
],
|
|
80
|
-
nullSearchable: false
|
|
81
|
-
}
|
|
82
|
-
],
|
|
83
|
-
$comment: "In order to register a domain you need to create a preorder. The preorder step is needed to prevent man-in-the-middle attacks. normalizedLabel + '.' + normalizedParentDomain must not be longer than 253 chars length as defined by RFC 1035. Domain documents are immutable: modification and deletion are restricted",
|
|
84
|
-
required: [
|
|
85
|
-
'$createdAt',
|
|
86
|
-
'$updatedAt',
|
|
87
|
-
'$transferredAt',
|
|
88
|
-
'label',
|
|
89
|
-
'normalizedLabel',
|
|
90
|
-
'normalizedParentDomainName',
|
|
91
|
-
'preorderSalt',
|
|
92
|
-
'records',
|
|
93
|
-
'subdomainRules'
|
|
94
|
-
],
|
|
95
|
-
tradeMode: 1,
|
|
96
|
-
transient: [
|
|
97
|
-
'preorderSalt'
|
|
98
|
-
],
|
|
99
|
-
properties: {
|
|
100
|
-
label: {
|
|
101
|
-
type: 'string',
|
|
102
|
-
pattern: '^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$',
|
|
103
|
-
position: 0,
|
|
104
|
-
maxLength: 63,
|
|
105
|
-
minLength: 3,
|
|
106
|
-
description: "Domain label. e.g. 'Bob'."
|
|
107
|
-
},
|
|
108
|
-
records: {
|
|
109
|
-
type: 'object',
|
|
110
|
-
position: 5,
|
|
111
|
-
properties: {
|
|
112
|
-
identity: {
|
|
113
|
-
type: 'array',
|
|
114
|
-
maxItems: 32,
|
|
115
|
-
minItems: 32,
|
|
116
|
-
position: 1,
|
|
117
|
-
byteArray: true,
|
|
118
|
-
description: 'Identifier name record that refers to an Identity',
|
|
119
|
-
contentMediaType: 'application/x.dash.dpp.identifier'
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
minProperties: 1,
|
|
123
|
-
additionalProperties: false
|
|
124
|
-
},
|
|
125
|
-
preorderSalt: {
|
|
126
|
-
type: 'array',
|
|
127
|
-
maxItems: 32,
|
|
128
|
-
minItems: 32,
|
|
129
|
-
position: 4,
|
|
130
|
-
byteArray: true,
|
|
131
|
-
description: 'Salt used in the preorder document'
|
|
132
|
-
},
|
|
133
|
-
subdomainRules: {
|
|
134
|
-
type: 'object',
|
|
135
|
-
position: 6,
|
|
136
|
-
required: [
|
|
137
|
-
'allowSubdomains'
|
|
138
|
-
],
|
|
139
|
-
properties: {
|
|
140
|
-
allowSubdomains: {
|
|
141
|
-
type: 'boolean',
|
|
142
|
-
$comment: 'Only the domain owner is allowed to create subdomains for non top-level domains',
|
|
143
|
-
position: 0,
|
|
144
|
-
description: 'This option defines who can create subdomains: true - anyone; false - only the domain owner'
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
description: 'Subdomain rules allow domain owners to define rules for subdomains',
|
|
148
|
-
additionalProperties: false
|
|
149
|
-
},
|
|
150
|
-
normalizedLabel: {
|
|
151
|
-
type: 'string',
|
|
152
|
-
pattern: '^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-]{0,61}[a-hj-km-np-z0-9]$',
|
|
153
|
-
$comment: 'Must be equal to the label in lowercase. "o", "i" and "l" must be replaced with "0" and "1".',
|
|
154
|
-
position: 1,
|
|
155
|
-
maxLength: 63,
|
|
156
|
-
description: "Domain label converted to lowercase for case-insensitive uniqueness validation. \"o\", \"i\" and \"l\" replaced with \"0\" and \"1\" to mitigate homograph attack. e.g. 'b0b'"
|
|
157
|
-
},
|
|
158
|
-
parentDomainName: {
|
|
159
|
-
type: 'string',
|
|
160
|
-
pattern: '^$|^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$',
|
|
161
|
-
position: 2,
|
|
162
|
-
maxLength: 63,
|
|
163
|
-
minLength: 0,
|
|
164
|
-
description: "A full parent domain name. e.g. 'dash'."
|
|
165
|
-
},
|
|
166
|
-
normalizedParentDomainName: {
|
|
167
|
-
type: 'string',
|
|
168
|
-
pattern: '^$|^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-\\.]{0,61}[a-hj-km-np-z0-9]$',
|
|
169
|
-
$comment: 'Must either be equal to an existing domain or empty to create a top level domain. "o", "i" and "l" must be replaced with "0" and "1". Only the data contract owner can create top level domains.',
|
|
170
|
-
position: 3,
|
|
171
|
-
maxLength: 63,
|
|
172
|
-
minLength: 0,
|
|
173
|
-
description: "A parent domain name in lowercase for case-insensitive uniqueness validation. \"o\", \"i\" and \"l\" replaced with \"0\" and \"1\" to mitigate homograph attack. e.g. 'dash'"
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
canBeDeleted: true,
|
|
177
|
-
transferable: 1,
|
|
178
|
-
documentsMutable: false,
|
|
179
|
-
additionalProperties: false
|
|
180
|
-
},
|
|
181
|
-
preorder: {
|
|
182
|
-
type: 'object',
|
|
183
|
-
indices: [
|
|
184
|
-
{
|
|
185
|
-
name: 'saltedHash',
|
|
186
|
-
unique: true,
|
|
187
|
-
properties: [
|
|
188
|
-
{
|
|
189
|
-
saltedDomainHash: 'asc'
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
],
|
|
194
|
-
$comment: 'Preorder documents are immutable: modification and deletion are restricted',
|
|
195
|
-
required: [
|
|
196
|
-
'saltedDomainHash'
|
|
197
|
-
],
|
|
198
|
-
properties: {
|
|
199
|
-
saltedDomainHash: {
|
|
200
|
-
type: 'array',
|
|
201
|
-
maxItems: 32,
|
|
202
|
-
minItems: 32,
|
|
203
|
-
position: 0,
|
|
204
|
-
byteArray: true,
|
|
205
|
-
description: 'Double sha-256 of the concatenation of a 32 byte random salt and a normalized domain name'
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
canBeDeleted: true,
|
|
209
|
-
documentsMutable: false,
|
|
210
|
-
additionalProperties: false
|
|
211
|
-
}
|
|
212
|
-
}, undefined, undefined, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9);
|
|
213
|
-
contract.id = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
214
|
-
});
|
|
215
|
-
test('should be able to get contested resource vote state with finishedVoteInfo', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
216
|
-
var voteState;
|
|
217
|
-
return __generator(this, function (_a) {
|
|
218
|
-
switch (_a.label) {
|
|
219
|
-
case 0: return [4 /*yield*/, sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
|
|
220
|
-
'dash',
|
|
221
|
-
'asdmaye1ght'
|
|
222
|
-
].map(stringToIndexValueBytes_1.default), types_1.ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, true)];
|
|
223
|
-
case 1:
|
|
224
|
-
voteState = _a.sent();
|
|
225
|
-
expect(voteState.finishedVoteInfo).toBeTruthy();
|
|
226
|
-
expect(voteState.contenders).toBeTruthy();
|
|
227
|
-
expect(voteState.contenders.length).toBeGreaterThan(0);
|
|
228
|
-
expect(voteState.abstainVoteTally).toBeDefined();
|
|
229
|
-
expect(voteState.lockVoteTally).toBeDefined();
|
|
230
|
-
return [2 /*return*/];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}); });
|
|
234
|
-
test('should be able to get contested resource vote state for incorrect values', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
235
|
-
var e_1;
|
|
236
|
-
return __generator(this, function (_a) {
|
|
237
|
-
switch (_a.label) {
|
|
238
|
-
case 0:
|
|
239
|
-
_a.trys.push([0, 2, , 3]);
|
|
240
|
-
return [4 /*yield*/, sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
|
|
241
|
-
'dash',
|
|
242
|
-
'agreatma1n'
|
|
243
|
-
].map(stringToIndexValueBytes_1.default), types_1.ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, false)];
|
|
244
|
-
case 1:
|
|
245
|
-
_a.sent();
|
|
246
|
-
return [3 /*break*/, 3];
|
|
247
|
-
case 2:
|
|
248
|
-
e_1 = _a.sent();
|
|
249
|
-
expect(true).toBeTruthy();
|
|
250
|
-
return [2 /*return*/];
|
|
251
|
-
case 3:
|
|
252
|
-
expect(false).toBeTruthy();
|
|
253
|
-
return [2 /*return*/];
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}); });
|
|
257
|
-
test('should be able to create TowardsIdentity vote', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
258
|
-
var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
|
|
259
|
-
return __generator(this, function (_a) {
|
|
260
|
-
switch (_a.label) {
|
|
261
|
-
case 0:
|
|
262
|
-
dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
263
|
-
documentTypeName = 'domain';
|
|
264
|
-
indexName = 'parentNameAndLabel';
|
|
265
|
-
indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
266
|
-
proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
|
|
267
|
-
choice = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
268
|
-
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
|
|
269
|
-
voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
270
|
-
return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
|
|
271
|
-
case 1:
|
|
272
|
-
voterIdentity = _a.sent();
|
|
273
|
-
identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
|
|
274
|
-
return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
|
|
275
|
-
case 2:
|
|
276
|
-
identityNonce = _a.sent();
|
|
277
|
-
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
278
|
-
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
279
|
-
stateTransition.sign(privateKey, identityPublicKey);
|
|
280
|
-
return [2 /*return*/];
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}); });
|
|
284
|
-
test('should be able to create Abstain vote', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
285
|
-
var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
|
|
286
|
-
return __generator(this, function (_a) {
|
|
287
|
-
switch (_a.label) {
|
|
288
|
-
case 0:
|
|
289
|
-
dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
290
|
-
documentTypeName = 'domain';
|
|
291
|
-
indexName = 'parentNameAndLabel';
|
|
292
|
-
indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
293
|
-
proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
|
|
294
|
-
choice = 'abstain';
|
|
295
|
-
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
|
|
296
|
-
voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
297
|
-
return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
|
|
298
|
-
case 1:
|
|
299
|
-
voterIdentity = _a.sent();
|
|
300
|
-
identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
|
|
301
|
-
return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
|
|
302
|
-
case 2:
|
|
303
|
-
identityNonce = _a.sent();
|
|
304
|
-
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
305
|
-
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
306
|
-
stateTransition.sign(privateKey, identityPublicKey);
|
|
307
|
-
return [2 /*return*/];
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}); });
|
|
311
|
-
test('should be able to create Lock vote', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
312
|
-
var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
|
|
313
|
-
return __generator(this, function (_a) {
|
|
314
|
-
switch (_a.label) {
|
|
315
|
-
case 0:
|
|
316
|
-
dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
317
|
-
documentTypeName = 'domain';
|
|
318
|
-
indexName = 'parentNameAndLabel';
|
|
319
|
-
indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
320
|
-
proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
|
|
321
|
-
choice = 'lock';
|
|
322
|
-
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
|
|
323
|
-
voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
324
|
-
return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
|
|
325
|
-
case 1:
|
|
326
|
-
voterIdentity = _a.sent();
|
|
327
|
-
identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
|
|
328
|
-
return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
|
|
329
|
-
case 2:
|
|
330
|
-
identityNonce = _a.sent();
|
|
331
|
-
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
332
|
-
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
333
|
-
stateTransition.sign(privateKey, identityPublicKey);
|
|
334
|
-
return [2 /*return*/];
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
}); });
|
|
338
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
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
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
40
|
-
var types_1 = require("../../src/types");
|
|
41
|
-
var sdk;
|
|
42
|
-
var ownerIdentifier;
|
|
43
|
-
var identityNonce;
|
|
44
|
-
var config;
|
|
45
|
-
var schema;
|
|
46
|
-
describe('DataContract', function () {
|
|
47
|
-
beforeAll(function () {
|
|
48
|
-
sdk = new types_1.DashPlatformSDK();
|
|
49
|
-
ownerIdentifier = 'GARSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
50
|
-
identityNonce = BigInt(11);
|
|
51
|
-
config = {
|
|
52
|
-
$format_version: '0',
|
|
53
|
-
canBeDeleted: true,
|
|
54
|
-
readonly: true,
|
|
55
|
-
keepsHistory: false,
|
|
56
|
-
documentsKeepHistoryContractDefault: false,
|
|
57
|
-
documentsMutableContractDefault: false,
|
|
58
|
-
documentsCanBeDeletedContractDefault: true,
|
|
59
|
-
requiresIdentityEncryptionBoundedKey: null,
|
|
60
|
-
requiresIdentityDecryptionBoundedKey: null
|
|
61
|
-
};
|
|
62
|
-
schema = {
|
|
63
|
-
note: {
|
|
64
|
-
type: 'object',
|
|
65
|
-
properties: {
|
|
66
|
-
author: {
|
|
67
|
-
type: 'string',
|
|
68
|
-
position: 1
|
|
69
|
-
},
|
|
70
|
-
message: {
|
|
71
|
-
type: 'string',
|
|
72
|
-
position: 0
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
additionalProperties: false
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
test('should be able to get data contract', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
-
var dataContract;
|
|
81
|
-
return __generator(this, function (_a) {
|
|
82
|
-
switch (_a.label) {
|
|
83
|
-
case 0: return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec')];
|
|
84
|
-
case 1:
|
|
85
|
-
// System Data Contract
|
|
86
|
-
dataContract = _a.sent();
|
|
87
|
-
expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
|
|
88
|
-
return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('Aukz296s36am6wKStoMbxm4YhC6kTpu3mERVrC7vHokP')];
|
|
89
|
-
case 2:
|
|
90
|
-
// User Data Contract
|
|
91
|
-
dataContract = _a.sent();
|
|
92
|
-
expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
|
|
93
|
-
return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV')];
|
|
94
|
-
case 3:
|
|
95
|
-
// User Data Contract with keep history
|
|
96
|
-
dataContract = _a.sent();
|
|
97
|
-
expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
|
|
98
|
-
return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('3XtMFe9UPf75DAcLmLsX9CLTrLPNysNPMcnWCE1C39vm')];
|
|
99
|
-
case 4:
|
|
100
|
-
// Token Data Contract
|
|
101
|
-
dataContract = _a.sent();
|
|
102
|
-
expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
|
|
103
|
-
return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}); });
|
|
107
|
-
test('should be able to create data contract', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
|
-
var dataContract;
|
|
109
|
-
return __generator(this, function (_a) {
|
|
110
|
-
dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
111
|
-
expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
|
|
112
|
-
return [2 /*return*/];
|
|
113
|
-
});
|
|
114
|
-
}); });
|
|
115
|
-
test('should be able to create data contract with optional params', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
|
-
var dataContract;
|
|
117
|
-
return __generator(this, function (_a) {
|
|
118
|
-
dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema, true, undefined, config);
|
|
119
|
-
expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
|
|
120
|
-
expect(dataContract.getConfig()).toEqual(config);
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
});
|
|
123
|
-
}); });
|
|
124
|
-
test('should be able to create data contract create transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
-
var dataContract, transition;
|
|
126
|
-
return __generator(this, function (_a) {
|
|
127
|
-
dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
128
|
-
transition = sdk.dataContracts.createStateTransition(dataContract, 'create', identityNonce);
|
|
129
|
-
expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
|
|
130
|
-
return [2 /*return*/];
|
|
131
|
-
});
|
|
132
|
-
}); });
|
|
133
|
-
test('should be able to create data contract update transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
134
|
-
var dataContract, transition;
|
|
135
|
-
return __generator(this, function (_a) {
|
|
136
|
-
dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
137
|
-
transition = sdk.dataContracts.createStateTransition(dataContract, 'update', identityNonce);
|
|
138
|
-
expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
|
|
139
|
-
return [2 /*return*/];
|
|
140
|
-
});
|
|
141
|
-
}); });
|
|
142
|
-
});
|