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
package/src/node/index.js
DELETED
|
@@ -1,102 +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
|
-
exports.NodeController = void 0;
|
|
40
|
-
var status_1 = require("./status");
|
|
41
|
-
var epochs_1 = require("./epochs");
|
|
42
|
-
var totalCredits_1 = require("./totalCredits");
|
|
43
|
-
/**
|
|
44
|
-
* Node controller for requesting information about DAPI node
|
|
45
|
-
*
|
|
46
|
-
* @hideconstructor
|
|
47
|
-
*/
|
|
48
|
-
var NodeController = /** @class */ (function () {
|
|
49
|
-
function NodeController(grpcPool, network) {
|
|
50
|
-
this.grpcPool = grpcPool;
|
|
51
|
-
this.network = network;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves an info about node
|
|
55
|
-
* Includes information about genesis, chain, software versions
|
|
56
|
-
*
|
|
57
|
-
* @return {Promise<NodeStatus>}
|
|
58
|
-
*/
|
|
59
|
-
NodeController.prototype.status = function () {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0: return [4 /*yield*/, (0, status_1.default)(this.grpcPool)];
|
|
64
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Returns total credits amount in platform
|
|
71
|
-
*
|
|
72
|
-
* @return {Promise<bigint>}
|
|
73
|
-
*/
|
|
74
|
-
NodeController.prototype.totalCredits = function () {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
return __generator(this, function (_a) {
|
|
77
|
-
switch (_a.label) {
|
|
78
|
-
case 0: return [4 /*yield*/, (0, totalCredits_1.default)(this.grpcPool, this.network)];
|
|
79
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Retrieves an info about epochs
|
|
86
|
-
* Includes information about first block height, time, fee multiplier, number
|
|
87
|
-
*
|
|
88
|
-
* @return {Promise<EpochInfo[]>}
|
|
89
|
-
*/
|
|
90
|
-
NodeController.prototype.getEpochsInfo = function (count, ascending, start) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
-
return __generator(this, function (_a) {
|
|
93
|
-
switch (_a.label) {
|
|
94
|
-
case 0: return [4 /*yield*/, (0, epochs_1.default)(this.grpcPool, count, ascending, start)];
|
|
95
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
return NodeController;
|
|
101
|
-
}());
|
|
102
|
-
exports.NodeController = NodeController;
|
package/src/node/status.js
DELETED
|
@@ -1,85 +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
|
-
exports.default = status;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
42
|
-
function status(grpcPool) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var getStatusRequest, response, v0;
|
|
45
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
46
|
-
return __generator(this, function (_j) {
|
|
47
|
-
switch (_j.label) {
|
|
48
|
-
case 0:
|
|
49
|
-
getStatusRequest = platform_1.GetStatusRequest.fromPartial({ v0: {} });
|
|
50
|
-
return [4 /*yield*/, grpcPool.getClient().getStatus(getStatusRequest)];
|
|
51
|
-
case 1:
|
|
52
|
-
response = _j.sent();
|
|
53
|
-
v0 = response.v0;
|
|
54
|
-
if (v0 == null) {
|
|
55
|
-
throw new Error('Unable to get node status');
|
|
56
|
-
}
|
|
57
|
-
return [2 /*return*/, {
|
|
58
|
-
node: (v0.node != null)
|
|
59
|
-
? {
|
|
60
|
-
id: (0, bytesToHex_1.default)(v0.node.id),
|
|
61
|
-
proTxHash: v0.node.proTxHash != null ? (0, bytesToHex_1.default)(v0.node.proTxHash) : undefined
|
|
62
|
-
}
|
|
63
|
-
: undefined,
|
|
64
|
-
chain: (v0.chain != null)
|
|
65
|
-
? {
|
|
66
|
-
catchingUp: v0.chain.catchingUp,
|
|
67
|
-
latestBlockHeight: v0.chain.latestBlockHeight,
|
|
68
|
-
earliestBlockHeight: v0.chain.earliestBlockHeight,
|
|
69
|
-
maxPeerBlockHeight: v0.chain.maxPeerBlockHeight,
|
|
70
|
-
coreChainLockedHeight: v0.chain.coreChainLockedHeight,
|
|
71
|
-
latestBlockHash: ((_a = v0.chain) === null || _a === void 0 ? void 0 : _a.latestBlockHash) != null ? (0, bytesToHex_1.default)((_b = v0.chain) === null || _b === void 0 ? void 0 : _b.latestBlockHash) : '',
|
|
72
|
-
latestAppHash: ((_c = v0.chain) === null || _c === void 0 ? void 0 : _c.latestAppHash) != null ? (0, bytesToHex_1.default)((_d = v0.chain) === null || _d === void 0 ? void 0 : _d.latestAppHash) : '',
|
|
73
|
-
earliestBlockHash: ((_e = v0.chain) === null || _e === void 0 ? void 0 : _e.earliestBlockHash) != null ? (0, bytesToHex_1.default)((_f = v0.chain) === null || _f === void 0 ? void 0 : _f.earliestBlockHash) : '',
|
|
74
|
-
earliestAppHash: ((_g = v0.chain) === null || _g === void 0 ? void 0 : _g.earliestAppHash) != null ? (0, bytesToHex_1.default)((_h = v0.chain) === null || _h === void 0 ? void 0 : _h.earliestAppHash) : ''
|
|
75
|
-
}
|
|
76
|
-
: undefined,
|
|
77
|
-
version: v0.version,
|
|
78
|
-
network: v0.network,
|
|
79
|
-
stateSync: v0.stateSync,
|
|
80
|
-
time: v0.time
|
|
81
|
-
}];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
}
|
package/src/node/totalCredits.js
DELETED
|
@@ -1,76 +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
|
-
exports.default = totalCredits;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var constants_1 = require("../constants");
|
|
42
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
43
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
46
|
-
function totalCredits(grpcPool, network) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var request, v0, _a, proof, metadata, activationHeight, _b, rootHash, totalCredits, quorumPublicKey, verify;
|
|
49
|
-
return __generator(this, function (_c) {
|
|
50
|
-
switch (_c.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
request = platform_1.GetTotalCreditsInPlatformRequest.fromPartial({ v0: { prove: true } });
|
|
53
|
-
return [4 /*yield*/, grpcPool.getClient().getTotalCreditsInPlatform(request)];
|
|
54
|
-
case 1:
|
|
55
|
-
v0 = (_c.sent()).v0;
|
|
56
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
57
|
-
if (proof == null) {
|
|
58
|
-
throw new Error('Proof not found');
|
|
59
|
-
}
|
|
60
|
-
if (metadata == null) {
|
|
61
|
-
throw new Error('Metadata not found');
|
|
62
|
-
}
|
|
63
|
-
activationHeight = network === 'testnet' ? constants_1.TESTNET_ACTIVATION_HEIGHT : constants_1.MAINNET_ACTIVATION_HEIGHT;
|
|
64
|
-
_b = (0, pshenmic_dpp_1.verifyTotalCreditsProof)(proof.grovedbProof, constants_1.HALVING_INTERVAL, activationHeight, Number(metadata.height), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, totalCredits = _b.totalCredits;
|
|
65
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
66
|
-
case 2:
|
|
67
|
-
quorumPublicKey = _c.sent();
|
|
68
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
69
|
-
if (!verify) {
|
|
70
|
-
throw new Error('Failed to verify query');
|
|
71
|
-
}
|
|
72
|
-
return [2 /*return*/, totalCredits];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
File without changes
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// import { IdentityWASM, NetworkWASM, PrivateKeyWASM, StateTransitionWASM } from 'pshenmic-dpp'
|
|
2
|
-
// import { base64 } from '@scure/base'
|
|
3
|
-
// import { IdentitiesController } from '../identities'
|
|
4
|
-
// import {AbstractSigner} from "./AbstractSigner";
|
|
5
|
-
//
|
|
6
|
-
// export class PrivateKeySigner implements AbstractSigner {
|
|
7
|
-
// privateKey: PrivateKeyWASM
|
|
8
|
-
// identity: IdentityWASM
|
|
9
|
-
// identities: IdentitiesController
|
|
10
|
-
//
|
|
11
|
-
// constructor (identitiesController: IdentitiesController, privateKey: string | PrivateKeyWASM, network?: NetworkWASM | string) {
|
|
12
|
-
// this.identities = identitiesController
|
|
13
|
-
//
|
|
14
|
-
// if (typeof privateKey === 'string') {
|
|
15
|
-
// let privateKeyWASM
|
|
16
|
-
//
|
|
17
|
-
// try {
|
|
18
|
-
// privateKeyWASM = PrivateKeyWASM.fromWIF(privateKey)
|
|
19
|
-
// } catch (e) {
|
|
20
|
-
// }
|
|
21
|
-
//
|
|
22
|
-
// if (privateKey.length === 64 && !network) {
|
|
23
|
-
// throw new Error('Network must be specified if hex or base64 private key being used')
|
|
24
|
-
// }
|
|
25
|
-
//
|
|
26
|
-
// try {
|
|
27
|
-
// privateKeyWASM = PrivateKeyWASM.fromHex(privateKey, network)
|
|
28
|
-
// } catch (e) {
|
|
29
|
-
// }
|
|
30
|
-
//
|
|
31
|
-
// try {
|
|
32
|
-
// privateKeyWASM = PrivateKeyWASM.fromBytes(base64.decode(privateKey), network)
|
|
33
|
-
// } catch (e) {
|
|
34
|
-
// }
|
|
35
|
-
//
|
|
36
|
-
// if (privateKeyWASM == null) {
|
|
37
|
-
// throw new Error('Could not decode private key')
|
|
38
|
-
// }
|
|
39
|
-
// } else if (privateKey?.__type === 'PrivateKeyWASM') {
|
|
40
|
-
// this.privateKey = privateKey
|
|
41
|
-
// } else {
|
|
42
|
-
// throw new Error('Unrecognized private key type')
|
|
43
|
-
// }
|
|
44
|
-
// }
|
|
45
|
-
//
|
|
46
|
-
// async connect (): Promise<void> {
|
|
47
|
-
// this.identity = await this.identities.getIdentityByPublicKeyHash(this.privateKey.getPublicKeyHash())
|
|
48
|
-
// }
|
|
49
|
-
//
|
|
50
|
-
// getCurrentIdentity (): IdentityWASM {
|
|
51
|
-
// return this.identity
|
|
52
|
-
// }
|
|
53
|
-
//
|
|
54
|
-
// signStateTransition (stateTransition: StateTransitionWASM): void {
|
|
55
|
-
// const [identityPublicKey] = this.identity.getPublicKeys()
|
|
56
|
-
// .filter(identityPublicKey => identityPublicKey.getPublicKeyHash() === this.privateKey.getPublicKeyHash())
|
|
57
|
-
//
|
|
58
|
-
// if (identityPublicKey == null) {
|
|
59
|
-
// throw new Error('Could not find an identity public key of identity matching this private key')
|
|
60
|
-
// }
|
|
61
|
-
//
|
|
62
|
-
// stateTransition.sign(this.privateKey, identityPublicKey)
|
|
63
|
-
// }
|
|
64
|
-
// }
|
package/src/signer/setSigner.js
DELETED
|
@@ -1,60 +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
|
-
exports.default = broadcast;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
function broadcast(grpcPool, stateTransition) {
|
|
42
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var broadcastStateTransitionRequest;
|
|
44
|
-
return __generator(this, function (_a) {
|
|
45
|
-
switch (_a.label) {
|
|
46
|
-
case 0:
|
|
47
|
-
if (stateTransition.signature.length === 0) {
|
|
48
|
-
throw new Error('State Transition is not signed');
|
|
49
|
-
}
|
|
50
|
-
broadcastStateTransitionRequest = platform_1.BroadcastStateTransitionRequest.fromPartial({
|
|
51
|
-
stateTransition: stateTransition.bytes()
|
|
52
|
-
});
|
|
53
|
-
return [4 /*yield*/, grpcPool.getClient().broadcastStateTransition(broadcastStateTransitionRequest)];
|
|
54
|
-
case 1:
|
|
55
|
-
_a.sent();
|
|
56
|
-
return [2 /*return*/];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
@@ -1,87 +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
|
-
exports.StateTransitionsController = void 0;
|
|
40
|
-
var waitForStateTransitionResult_1 = require("./waitForStateTransitionResult");
|
|
41
|
-
var broadcast_1 = require("./broadcast");
|
|
42
|
-
/**
|
|
43
|
-
* Collection of methods to perform state transitions (transactions) such like broadcast, wait for state transition result
|
|
44
|
-
*
|
|
45
|
-
* @hideconstructor
|
|
46
|
-
*/
|
|
47
|
-
var StateTransitionsController = /** @class */ (function () {
|
|
48
|
-
function StateTransitionsController(grpcPool) {
|
|
49
|
-
this.grpcPool = grpcPool;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Broadcasts a state transition to a network
|
|
53
|
-
*
|
|
54
|
-
* @param stateTransition {StateTransitionWASM}
|
|
55
|
-
*
|
|
56
|
-
* @return {Promise<void>}
|
|
57
|
-
*/
|
|
58
|
-
StateTransitionsController.prototype.broadcast = function (stateTransition) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
return __generator(this, function (_a) {
|
|
61
|
-
switch (_a.label) {
|
|
62
|
-
case 0: return [4 /*yield*/, (0, broadcast_1.default)(this.grpcPool, stateTransition)];
|
|
63
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Waits for a given state transition to finalize in the network (usually 1-3 sec)
|
|
70
|
-
*
|
|
71
|
-
* @param stateTransition {StateTransitionWASM}
|
|
72
|
-
*
|
|
73
|
-
* @return {Promise<void>}
|
|
74
|
-
*/
|
|
75
|
-
StateTransitionsController.prototype.waitForStateTransitionResult = function (stateTransition) {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
-
return __generator(this, function (_a) {
|
|
78
|
-
switch (_a.label) {
|
|
79
|
-
case 0: return [4 /*yield*/, (0, waitForStateTransitionResult_1.default)(this.grpcPool, stateTransition)];
|
|
80
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
return StateTransitionsController;
|
|
86
|
-
}());
|
|
87
|
-
exports.StateTransitionsController = StateTransitionsController;
|
|
@@ -1,60 +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
|
-
exports.default = waitForStateTransitionResult;
|
|
40
|
-
function waitForStateTransitionResult(grpcPool, stateTransition) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
-
var url, resp, _a, _b;
|
|
43
|
-
return __generator(this, function (_c) {
|
|
44
|
-
switch (_c.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
url = "https://".concat(grpcPool.network === 'mainnet' ? '' : 'testnet.', "platform-explorer.pshenmic.dev/waitForStateTransitionResult/").concat(stateTransition.hash(false));
|
|
47
|
-
return [4 /*yield*/, fetch(url)];
|
|
48
|
-
case 1:
|
|
49
|
-
resp = _c.sent();
|
|
50
|
-
if (!(resp.status !== 200)) return [3 /*break*/, 3];
|
|
51
|
-
_b = (_a = console).log;
|
|
52
|
-
return [4 /*yield*/, resp.json()];
|
|
53
|
-
case 2:
|
|
54
|
-
_b.apply(_a, [_c.sent()]);
|
|
55
|
-
throw new Error('Internal server error while waiting for state transition result');
|
|
56
|
-
case 3: return [2 /*return*/];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.default = createStateTransition;
|
|
13
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
14
|
-
var tokenTransitionsMap = {
|
|
15
|
-
burn: {
|
|
16
|
-
class: pshenmic_dpp_1.TokenBurnTransitionWASM,
|
|
17
|
-
arguments: ['amount', 'publicNote'],
|
|
18
|
-
optionalArguments: ['publicNote']
|
|
19
|
-
},
|
|
20
|
-
mint: {
|
|
21
|
-
class: pshenmic_dpp_1.TokenMintTransitionWASM,
|
|
22
|
-
arguments: ['identityId', 'amount', 'publicNote'],
|
|
23
|
-
optionalArguments: ['publicNote']
|
|
24
|
-
},
|
|
25
|
-
transfer: {
|
|
26
|
-
class: pshenmic_dpp_1.TokenTransferTransitionWASM,
|
|
27
|
-
arguments: ['identityId', 'amount', 'publicNote', 'sharedEncryptedNote', 'privateEncryptedNote'],
|
|
28
|
-
optionalArguments: ['publicNote', 'sharedEncryptedNote', 'privateEncryptedNote']
|
|
29
|
-
},
|
|
30
|
-
freeze: {
|
|
31
|
-
class: pshenmic_dpp_1.TokenFreezeTransitionWASM,
|
|
32
|
-
arguments: ['identityId', 'publicNote'],
|
|
33
|
-
optionalArguments: ['publicNote']
|
|
34
|
-
},
|
|
35
|
-
unfreeze: {
|
|
36
|
-
class: pshenmic_dpp_1.TokenUnFreezeTransitionWASM,
|
|
37
|
-
arguments: ['identityId', 'publicNote'],
|
|
38
|
-
optionalArguments: ['publicNote']
|
|
39
|
-
},
|
|
40
|
-
destroyFrozenFunds: {
|
|
41
|
-
class: pshenmic_dpp_1.TokenDestroyFrozenFundsTransitionWASM,
|
|
42
|
-
arguments: ['identityId', 'publicNote'],
|
|
43
|
-
optionalArguments: ['publicNote']
|
|
44
|
-
},
|
|
45
|
-
emergencyAction: {
|
|
46
|
-
class: pshenmic_dpp_1.TokenEmergencyActionTransitionWASM,
|
|
47
|
-
arguments: ['emergencyAction', 'publicNote'],
|
|
48
|
-
optionalArguments: ['publicNote']
|
|
49
|
-
},
|
|
50
|
-
directPurchase: {
|
|
51
|
-
class: pshenmic_dpp_1.TokenDirectPurchaseTransitionWASM,
|
|
52
|
-
arguments: ['amount', 'totalAgreedPrice'],
|
|
53
|
-
optionalArguments: []
|
|
54
|
-
},
|
|
55
|
-
setPriceForDirectPurchase: {
|
|
56
|
-
class: pshenmic_dpp_1.TokenSetPriceForDirectPurchaseTransitionWASM,
|
|
57
|
-
arguments: ['price', 'publicNote'],
|
|
58
|
-
optionalArguments: ['publicNote']
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
function createStateTransition(base, ownerId, type, params) {
|
|
62
|
-
var _a = tokenTransitionsMap[type], TransitionClass = _a.class, classArguments = _a.arguments, optionalArguments = _a.optionalArguments;
|
|
63
|
-
if (TransitionClass == null) {
|
|
64
|
-
throw new Error("Unimplemented transition type: ".concat(type));
|
|
65
|
-
}
|
|
66
|
-
// check if all required params for token transition exists
|
|
67
|
-
var missingArgument = classArguments
|
|
68
|
-
.filter(function (classArgument) { return params[classArgument] == null &&
|
|
69
|
-
!optionalArguments.includes(classArgument); })[0];
|
|
70
|
-
if (missingArgument != null) {
|
|
71
|
-
throw new Error("Token transition param \"".concat(missingArgument, "\" is missing"));
|
|
72
|
-
}
|
|
73
|
-
var transitionParams = classArguments.map(function (classArgument) { return params[classArgument]; });
|
|
74
|
-
// @ts-expect-error
|
|
75
|
-
var tokenTransition = new (TransitionClass.bind.apply(TransitionClass, __spreadArray([void 0, base], transitionParams, false)))();
|
|
76
|
-
var tokenTransitionWASM = new pshenmic_dpp_1.TokenTransitionWASM(tokenTransition);
|
|
77
|
-
var batchedTransition = new pshenmic_dpp_1.BatchedTransitionWASM(tokenTransitionWASM);
|
|
78
|
-
return pshenmic_dpp_1.BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition], ownerId, 1).toStateTransition();
|
|
79
|
-
}
|