dash-platform-sdk 1.3.0-dev.4 → 1.3.0-dev.6

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.
Files changed (138) hide show
  1. package/bundle.min.js +21 -2
  2. package/index.js +2 -5
  3. package/package.json +30 -31
  4. package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
  5. package/proto/generated/google/protobuf/wrappers.js +562 -345
  6. package/proto/generated/platform.client.d.ts +251 -0
  7. package/proto/generated/platform.client.js +175 -0
  8. package/proto/generated/platform.d.ts +3682 -1939
  9. package/proto/generated/platform.js +8119 -18366
  10. package/src/DashPlatformSDK.d.ts +5 -4
  11. package/src/DashPlatformSDK.js +56 -46
  12. package/src/constants.js +7 -10
  13. package/src/contestedResources/createStateTransition.d.ts +1 -2
  14. package/src/contestedResources/createStateTransition.js +4 -7
  15. package/src/contestedResources/getContestedResourceVoteState.js +67 -118
  16. package/src/contestedResources/index.js +9 -55
  17. package/src/dataContracts/create.js +5 -8
  18. package/src/dataContracts/createStateTransition.js +10 -14
  19. package/src/dataContracts/getDataContractByIdentifier.js +40 -83
  20. package/src/dataContracts/index.js +17 -63
  21. package/src/documents/create.js +3 -6
  22. package/src/documents/createStateTransition.js +19 -31
  23. package/src/documents/index.js +25 -72
  24. package/src/documents/query.js +58 -90
  25. package/src/grpcConnectionPool.d.ts +30 -8
  26. package/src/grpcConnectionPool.js +63 -121
  27. package/src/identities/createStateTransition.js +14 -26
  28. package/src/identities/getIdentityBalance.js +37 -80
  29. package/src/identities/getIdentityByIdentifier.js +37 -80
  30. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
  31. package/src/identities/getIdentityByPublicKeyHash.js +37 -80
  32. package/src/identities/getIdentityContractNonce.js +40 -83
  33. package/src/identities/getIdentityNonce.js +38 -81
  34. package/src/identities/getIdentityPublicKeys.js +43 -81
  35. package/src/identities/index.js +57 -153
  36. package/src/keyPair/deriveChild.d.ts +2 -2
  37. package/src/keyPair/deriveChild.js +2 -49
  38. package/src/keyPair/derivePath.d.ts +2 -2
  39. package/src/keyPair/derivePath.js +2 -49
  40. package/src/keyPair/index.d.ts +39 -114
  41. package/src/keyPair/index.js +62 -296
  42. package/src/keyPair/mnemonicToSeed.d.ts +1 -1
  43. package/src/keyPair/mnemonicToSeed.js +3 -46
  44. package/src/names/index.js +43 -111
  45. package/src/names/registerName.js +60 -127
  46. package/src/names/searchByIdentity.d.ts +1 -1
  47. package/src/names/searchByIdentity.js +4 -50
  48. package/src/names/searchByName.js +15 -63
  49. package/src/names/testNameContested.js +1 -4
  50. package/src/names/validateName.js +3 -6
  51. package/src/node/epochs.js +43 -85
  52. package/src/node/index.d.ts +3 -3
  53. package/src/node/index.js +18 -77
  54. package/src/node/status.js +37 -81
  55. package/src/node/totalCredits.d.ts +2 -1
  56. package/src/node/totalCredits.js +32 -73
  57. package/src/signer/AbstractSigner.js +1 -2
  58. package/src/signer/setSigner.js +1 -4
  59. package/src/stateTransitions/broadcast.js +7 -57
  60. package/src/stateTransitions/index.js +13 -66
  61. package/src/stateTransitions/waitForStateTransitionResult.js +6 -58
  62. package/src/tokens/createStateTransition.js +23 -35
  63. package/src/tokens/getIdentitiesTokenBalances.js +40 -83
  64. package/src/tokens/getIdentityTokensBalances.js +40 -83
  65. package/src/tokens/getTokenContractInfo.js +40 -83
  66. package/src/tokens/getTokenDirectPurchasePrices.js +37 -80
  67. package/src/tokens/getTokenTotalSupply.js +38 -81
  68. package/src/tokens/index.js +39 -124
  69. package/src/types.d.ts +6 -12
  70. package/src/types.js +6 -16
  71. package/src/utils/base58ToBytes.js +3 -6
  72. package/src/utils/bytesToHex.js +2 -5
  73. package/src/utils/bytesToTypedArray.d.ts +1 -0
  74. package/src/utils/bytesToTypedArray.js +3 -0
  75. package/src/utils/calculateMsgHash.d.ts +1 -1
  76. package/src/utils/calculateMsgHash.js +10 -13
  77. package/src/utils/calculateSignHash.d.ts +1 -1
  78. package/src/utils/calculateSignHash.js +7 -10
  79. package/src/utils/calculateStateIdHash.d.ts +1 -1
  80. package/src/utils/calculateStateIdHash.js +8 -10
  81. package/src/utils/convertToHomographSafeChars.js +2 -5
  82. package/src/utils/createVoterIdentityId.d.ts +1 -1
  83. package/src/utils/createVoterIdentityId.js +12 -11
  84. package/src/utils/getEvonodeList.d.ts +2 -2
  85. package/src/utils/getEvonodeList.js +10 -61
  86. package/src/utils/getQuorumPublicKey.js +15 -66
  87. package/src/utils/getRandomArrayItem.js +1 -4
  88. package/src/utils/getRandomBytes.js +2 -5
  89. package/src/utils/hexToBytes.js +2 -6
  90. package/src/utils/index.js +21 -28
  91. package/src/utils/indexBytesToString.js +2 -5
  92. package/src/utils/sha256.d.ts +1 -1
  93. package/src/utils/sha256.js +10 -8
  94. package/src/utils/signHash.d.ts +1 -1
  95. package/src/utils/signHash.js +9 -12
  96. package/src/utils/signRequestId.d.ts +1 -1
  97. package/src/utils/signRequestId.js +9 -12
  98. package/src/utils/sleep.js +2 -50
  99. package/src/utils/stringToIndexValueBytes.js +4 -7
  100. package/src/utils/verifyTenderdashProof.d.ts +1 -1
  101. package/src/utils/verifyTenderdashProof.js +13 -17
  102. package/src/voting/createStateTransition.d.ts +1 -2
  103. package/src/voting/createStateTransition.js +4 -7
  104. package/src/voting/createVote.js +4 -7
  105. package/src/voting/index.d.ts +3 -4
  106. package/src/voting/index.js +19 -26
  107. package/test/unit/ContestedResources.spec.js +92 -177
  108. package/test/unit/DataContract.spec.js +44 -111
  109. package/test/unit/Document.spec.js +93 -183
  110. package/test/unit/Identity.spec.js +221 -346
  111. package/test/unit/KeyPair.spec.js +30 -145
  112. package/test/unit/Names.spec.js +27 -90
  113. package/test/unit/Node.spec.js +55 -126
  114. package/test/unit/SDK.spec.js +7 -9
  115. package/test/unit/Tokens.spec.js +111 -278
  116. package/bundle.min.js.LICENSE.txt +0 -1
  117. package/src/keyPair/keyToPublicKey.d.ts +0 -2
  118. package/src/keyPair/keyToPublicKey.js +0 -47
  119. package/src/keyPair/keyToWalletId.d.ts +0 -2
  120. package/src/keyPair/keyToWalletId.js +0 -50
  121. package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
  122. package/src/keyPair/keyToXPrivateKey.js +0 -50
  123. package/src/keyPair/keyToXPublicKey.d.ts +0 -3
  124. package/src/keyPair/keyToXPublicKey.js +0 -50
  125. package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
  126. package/src/keyPair/mnemonicToIdentityKey.js +0 -57
  127. package/src/keyPair/mnemonicToWallet.d.ts +0 -2
  128. package/src/keyPair/mnemonicToWallet.js +0 -55
  129. package/src/keyPair/privateKeyToWif.d.ts +0 -2
  130. package/src/keyPair/privateKeyToWif.js +0 -50
  131. package/src/keyPair/publicKeyToAddress.d.ts +0 -2
  132. package/src/keyPair/publicKeyToAddress.js +0 -50
  133. package/src/keyPair/seedToWallet.d.ts +0 -2
  134. package/src/keyPair/seedToWallet.js +0 -50
  135. package/src/keyPair/walletToIdentityKey.d.ts +0 -3
  136. package/src/keyPair/walletToIdentityKey.js +0 -56
  137. package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
  138. package/src/keyPair/xkeyToHDXKey.js +0 -50
@@ -1,357 +1,232 @@
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());
1
+ import { IdentityPublicKeyWASM, IdentityWASM, KeyType, PrivateKeyWASM, Purpose, SecurityLevel } from 'pshenmic-dpp';
2
+ import { DashPlatformSDK } from '../../src/types';
3
+ let sdk;
4
+ describe('Identity', () => {
5
+ beforeAll(() => {
6
+ sdk = new DashPlatformSDK({ network: 'testnet' });
9
7
  });
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 DashPlatformSDK_1 = require("../../src/DashPlatformSDK");
41
- var sdk;
42
- describe('Identity', function () {
43
- beforeAll(function () {
44
- sdk = new DashPlatformSDK_1.DashPlatformSDK();
8
+ test('should be able to get identity by identifier', async () => {
9
+ const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
10
+ const identity = await sdk.identities.getIdentityByIdentifier(identifier);
11
+ expect(identity).toEqual(expect.any(IdentityWASM));
45
12
  });
46
- test('should be able to get identity by identifier', function () { return __awaiter(void 0, void 0, void 0, function () {
47
- var identifier, identity;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0:
51
- identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
52
- return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(identifier)];
53
- case 1:
54
- identity = _a.sent();
55
- expect(identity).toEqual(expect.any(pshenmic_dpp_1.IdentityWASM));
56
- return [2 /*return*/];
57
- }
58
- });
59
- }); });
60
- test('should be able to get identity by public key hash', function () { return __awaiter(void 0, void 0, void 0, function () {
61
- var publicKeyHash, identity;
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
64
- case 0:
65
- publicKeyHash = 'c1b95d254c405a3d9d82ef88a47f9f792ac8efd7';
66
- return [4 /*yield*/, sdk.identities.getIdentityByPublicKeyHash(publicKeyHash)];
67
- case 1:
68
- identity = _a.sent();
69
- expect(identity).toEqual(expect.any(pshenmic_dpp_1.IdentityWASM));
70
- return [2 /*return*/];
71
- }
72
- });
73
- }); });
74
- test('should be able to get identity by non unique public key hash', function () { return __awaiter(void 0, void 0, void 0, function () {
75
- var identity;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0: return [4 /*yield*/, sdk.identities.getIdentityByNonUniquePublicKeyHash('8b30a2cda275d1110874c0380b8447db3a9b04ee')];
79
- case 1:
80
- identity = _a.sent();
81
- expect(identity).toEqual(expect.any(pshenmic_dpp_1.IdentityWASM));
82
- return [2 /*return*/];
83
- }
84
- });
85
- }); });
86
- test('should be able to get identity contract nonce', function () { return __awaiter(void 0, void 0, void 0, function () {
87
- var identifier, dataContract, identityContractNonce;
88
- return __generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0:
91
- identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
92
- dataContract = 'DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV';
93
- return [4 /*yield*/, sdk.identities.getIdentityContractNonce(identifier, dataContract)];
94
- case 1:
95
- identityContractNonce = _a.sent();
96
- expect(identityContractNonce).toEqual(expect.any(BigInt));
97
- return [2 /*return*/];
98
- }
99
- });
100
- }); });
101
- test('should be able to get identity nonce', function () { return __awaiter(void 0, void 0, void 0, function () {
102
- var identifier, identityNonce;
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0:
106
- identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
107
- return [4 /*yield*/, sdk.identities.getIdentityNonce(identifier)];
108
- case 1:
109
- identityNonce = _a.sent();
110
- expect(identityNonce).toEqual(expect.any(BigInt));
111
- return [2 /*return*/];
112
- }
113
- });
114
- }); });
115
- test('should be able to get identity public keys', function () { return __awaiter(void 0, void 0, void 0, function () {
116
- var identifier, identityPublicKeys;
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0:
120
- identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
121
- return [4 /*yield*/, sdk.identities.getIdentityPublicKeys(identifier)];
122
- case 1:
123
- identityPublicKeys = _a.sent();
124
- expect(identityPublicKeys.every(function (identityPublicKey) { return identityPublicKey instanceof pshenmic_dpp_1.IdentityPublicKeyWASM; })).toBeTruthy();
125
- return [2 /*return*/];
126
- }
127
- });
128
- }); });
129
- test('should be able to get balance', function () { return __awaiter(void 0, void 0, void 0, function () {
130
- var identifier, balance;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0:
134
- identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
135
- return [4 /*yield*/, sdk.identities.getIdentityBalance(identifier)];
136
- case 1:
137
- balance = _a.sent();
138
- expect(balance).toEqual(expect.any(BigInt));
139
- return [2 /*return*/];
140
- }
13
+ test('should be able to get identity by public key hash', async () => {
14
+ const publicKeyHash = 'c1b95d254c405a3d9d82ef88a47f9f792ac8efd7';
15
+ const identity = await sdk.identities.getIdentityByPublicKeyHash(publicKeyHash);
16
+ expect(identity).toEqual(expect.any(IdentityWASM));
17
+ });
18
+ test('should be able to get identity by non unique public key hash', async () => {
19
+ const identity = await sdk.identities.getIdentityByNonUniquePublicKeyHash('8b30a2cda275d1110874c0380b8447db3a9b04ee');
20
+ expect(identity).toEqual(expect.any(IdentityWASM));
21
+ });
22
+ test('should be able to get identity contract nonce', async () => {
23
+ const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
24
+ const dataContract = 'DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV';
25
+ const identityContractNonce = await sdk.identities.getIdentityContractNonce(identifier, dataContract);
26
+ expect(identityContractNonce).toEqual(expect.any(BigInt));
27
+ });
28
+ test('should be able to get identity nonce', async () => {
29
+ const identifier = '34vkjdeUTP2z798SiXqoB6EAuobh51kXYURqVa9xkujf';
30
+ const identityNonce = await sdk.identities.getIdentityNonce(identifier);
31
+ expect(identityNonce).toEqual(expect.any(BigInt));
32
+ });
33
+ test('should be able to get identity public keys', async () => {
34
+ const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
35
+ const identityPublicKeys = await sdk.identities.getIdentityPublicKeys(identifier);
36
+ expect(identityPublicKeys.every(identityPublicKey => identityPublicKey instanceof IdentityPublicKeyWASM)).toBeTruthy();
37
+ });
38
+ test('should be able to get balance', async () => {
39
+ const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
40
+ const balance = await sdk.identities.getIdentityBalance(identifier);
41
+ expect(balance).toEqual(expect.any(BigInt));
42
+ });
43
+ describe('createStateTransition', () => {
44
+ test('should be able to create IdentityCreateTransition via ChainLock', async () => {
45
+ const assetLockPrivateKey = PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
46
+ const txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
47
+ const outputIndex = 0;
48
+ const coreChainLockedHeight = 1337;
49
+ const privateKey1 = PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
50
+ const identityPublicKeyInCreation1 = {
51
+ id: 0,
52
+ purpose: Purpose.AUTHENTICATION,
53
+ securityLevel: SecurityLevel.MASTER,
54
+ keyType: KeyType.ECDSA_SECP256K1,
55
+ readOnly: false,
56
+ data: privateKey1.getPublicKey().bytes()
57
+ };
58
+ const privateKey2 = PrivateKeyWASM.fromHex('44a8195e242364b935e9d7ff2106ed109e9baf3800907f5e58a259fdfd1ca5e5', 'testnet');
59
+ const identityPublicKeyInCreation2 = {
60
+ id: 1,
61
+ purpose: Purpose.AUTHENTICATION,
62
+ securityLevel: SecurityLevel.HIGH,
63
+ keyType: KeyType.ECDSA_SECP256K1,
64
+ readOnly: false,
65
+ data: privateKey2.getPublicKey().bytes()
66
+ };
67
+ let identityCreateStateTransition;
68
+ // Set identity public key signature for public key 0
69
+ identityCreateStateTransition = sdk.identities.createStateTransition('create', {
70
+ publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
71
+ assetLockProof: {
72
+ txid,
73
+ outputIndex,
74
+ coreChainLockedHeight,
75
+ type: 'chainLock'
76
+ }
77
+ });
78
+ identityCreateStateTransition.signByPrivateKey(privateKey1, KeyType.ECDSA_SECP256K1);
79
+ identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
80
+ // Set identity public key signature for public key 1
81
+ identityCreateStateTransition = sdk.identities.createStateTransition('create', {
82
+ publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
83
+ assetLockProof: {
84
+ txid,
85
+ outputIndex,
86
+ coreChainLockedHeight,
87
+ type: 'chainLock'
88
+ }
89
+ });
90
+ identityCreateStateTransition.signByPrivateKey(privateKey2, KeyType.ECDSA_SECP256K1);
91
+ identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
92
+ // Finalize
93
+ identityCreateStateTransition = sdk.identities.createStateTransition('create', {
94
+ publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
95
+ assetLockProof: {
96
+ txid,
97
+ outputIndex,
98
+ coreChainLockedHeight,
99
+ type: 'chainLock'
100
+ }
101
+ });
102
+ identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, KeyType.ECDSA_SECP256K1);
141
103
  });
142
- }); });
143
- describe('createStateTransition', function () {
144
- test('should be able to create IdentityCreateTransition via ChainLock', function () { return __awaiter(void 0, void 0, void 0, function () {
145
- var assetLockPrivateKey, txid, outputIndex, coreChainLockedHeight, privateKey1, identityPublicKeyInCreation1, privateKey2, identityPublicKeyInCreation2, identityCreateStateTransition;
146
- return __generator(this, function (_a) {
147
- assetLockPrivateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
148
- txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
149
- outputIndex = 0;
150
- coreChainLockedHeight = 1337;
151
- privateKey1 = pshenmic_dpp_1.PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
152
- identityPublicKeyInCreation1 = {
153
- id: 0,
154
- purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
155
- securityLevel: pshenmic_dpp_1.SecurityLevel.MASTER,
156
- keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
157
- readOnly: false,
158
- data: privateKey1.getPublicKey().bytes()
159
- };
160
- privateKey2 = pshenmic_dpp_1.PrivateKeyWASM.fromHex('44a8195e242364b935e9d7ff2106ed109e9baf3800907f5e58a259fdfd1ca5e5', 'testnet');
161
- identityPublicKeyInCreation2 = {
162
- id: 1,
163
- purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
164
- securityLevel: pshenmic_dpp_1.SecurityLevel.HIGH,
165
- keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
166
- readOnly: false,
167
- data: privateKey2.getPublicKey().bytes()
168
- };
169
- // Set identity public key signature for public key 0
170
- identityCreateStateTransition = sdk.identities.createStateTransition('create', {
171
- publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
172
- assetLockProof: {
173
- txid: txid,
174
- outputIndex: outputIndex,
175
- coreChainLockedHeight: coreChainLockedHeight,
176
- type: 'chainLock'
177
- }
178
- });
179
- identityCreateStateTransition.signByPrivateKey(privateKey1, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
180
- identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
181
- // Set identity public key signature for public key 1
182
- identityCreateStateTransition = sdk.identities.createStateTransition('create', {
183
- publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
184
- assetLockProof: {
185
- txid: txid,
186
- outputIndex: outputIndex,
187
- coreChainLockedHeight: coreChainLockedHeight,
188
- type: 'chainLock'
189
- }
190
- });
191
- identityCreateStateTransition.signByPrivateKey(privateKey2, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
192
- identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
193
- // Finalize
194
- identityCreateStateTransition = sdk.identities.createStateTransition('create', {
195
- publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
196
- assetLockProof: {
197
- txid: txid,
198
- outputIndex: outputIndex,
199
- coreChainLockedHeight: coreChainLockedHeight,
200
- type: 'chainLock'
201
- }
202
- });
203
- identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
204
- return [2 /*return*/];
104
+ test('should be able to create IdentityCreateTransition via InstantSend', async () => {
105
+ const assetLockPrivateKey = PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
106
+ const transaction = '03000800017dada5379e34ae1b59df35ba7acb879f3afaa12fa522f4b289a34d9fa2a68825010000006b48304502210093d609f65219e0d7ee694d271c4b7460ce89d298ef3e3670d5aef957e5551ead0220085d252e16cb3aae0d4e5d371e359e844fe82db93d8e4e26b5c61dc94676b7df0121037b86a1f7a11b4cc69fc7052e5cabdc625f3db47ee283ed4b87108f2cd879521effffffff0200e1f50500000000026a004054fa02000000001976a91416bbe230f46eea86fc4bf4dd550be45dc9adfcb488ac0000000024010100e1f505000000001976a914883bccdb8bfa44e55a19a1120ff2427537f7e92488ac';
107
+ const instantLock = '01017dada5379e34ae1b59df35ba7acb879f3afaa12fa522f4b289a34d9fa2a688250100000060afc1323120f0a3b835dd113b3221e92dea56814369925f10dd3e8f6bcfaa6aa89ed4282521863d8eb72e7e0e7d80c86ca64cce9986ae8bb63657f43f0000009179b5d130fe69bd0f2ea7bc90e9ea904a7eeea515a2612045a70925a7c678b0b09499ea307575751e22f804c443d2e1105e1fd4e30aa894324a41cd983ffe58d5312ff8db11676bd530c6ab8af1f7d2980d356dd3c86d0386da7df70aa3a66b';
108
+ const outputIndex = 0;
109
+ const privateKey1 = PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
110
+ const identityPublicKeyInCreation1 = {
111
+ id: 0,
112
+ purpose: Purpose.AUTHENTICATION,
113
+ securityLevel: SecurityLevel.MASTER,
114
+ keyType: KeyType.ECDSA_SECP256K1,
115
+ readOnly: false,
116
+ data: privateKey1.getPublicKey().bytes()
117
+ };
118
+ const privateKey2 = PrivateKeyWASM.fromHex('44a8195e242364b935e9d7ff2106ed109e9baf3800907f5e58a259fdfd1ca5e5', 'testnet');
119
+ const identityPublicKeyInCreation2 = {
120
+ id: 1,
121
+ purpose: Purpose.AUTHENTICATION,
122
+ securityLevel: SecurityLevel.HIGH,
123
+ keyType: KeyType.ECDSA_SECP256K1,
124
+ readOnly: false,
125
+ data: privateKey2.getPublicKey().bytes()
126
+ };
127
+ let identityCreateStateTransition;
128
+ // Set identity public key signature for public key 0
129
+ identityCreateStateTransition = sdk.identities.createStateTransition('create', {
130
+ publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
131
+ assetLockProof: {
132
+ transaction,
133
+ instantLock,
134
+ outputIndex,
135
+ type: 'instantLock'
136
+ }
205
137
  });
206
- }); });
207
- test('should be able to create IdentityCreateTransition via InstantSend', function () { return __awaiter(void 0, void 0, void 0, function () {
208
- var assetLockPrivateKey, transaction, instantLock, outputIndex, privateKey1, identityPublicKeyInCreation1, privateKey2, identityPublicKeyInCreation2, identityCreateStateTransition;
209
- return __generator(this, function (_a) {
210
- assetLockPrivateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
211
- transaction = '03000800017dada5379e34ae1b59df35ba7acb879f3afaa12fa522f4b289a34d9fa2a68825010000006b48304502210093d609f65219e0d7ee694d271c4b7460ce89d298ef3e3670d5aef957e5551ead0220085d252e16cb3aae0d4e5d371e359e844fe82db93d8e4e26b5c61dc94676b7df0121037b86a1f7a11b4cc69fc7052e5cabdc625f3db47ee283ed4b87108f2cd879521effffffff0200e1f50500000000026a004054fa02000000001976a91416bbe230f46eea86fc4bf4dd550be45dc9adfcb488ac0000000024010100e1f505000000001976a914883bccdb8bfa44e55a19a1120ff2427537f7e92488ac';
212
- instantLock = '01017dada5379e34ae1b59df35ba7acb879f3afaa12fa522f4b289a34d9fa2a688250100000060afc1323120f0a3b835dd113b3221e92dea56814369925f10dd3e8f6bcfaa6aa89ed4282521863d8eb72e7e0e7d80c86ca64cce9986ae8bb63657f43f0000009179b5d130fe69bd0f2ea7bc90e9ea904a7eeea515a2612045a70925a7c678b0b09499ea307575751e22f804c443d2e1105e1fd4e30aa894324a41cd983ffe58d5312ff8db11676bd530c6ab8af1f7d2980d356dd3c86d0386da7df70aa3a66b';
213
- outputIndex = 0;
214
- privateKey1 = pshenmic_dpp_1.PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
215
- identityPublicKeyInCreation1 = {
216
- id: 0,
217
- purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
218
- securityLevel: pshenmic_dpp_1.SecurityLevel.MASTER,
219
- keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
220
- readOnly: false,
221
- data: privateKey1.getPublicKey().bytes()
222
- };
223
- privateKey2 = pshenmic_dpp_1.PrivateKeyWASM.fromHex('44a8195e242364b935e9d7ff2106ed109e9baf3800907f5e58a259fdfd1ca5e5', 'testnet');
224
- identityPublicKeyInCreation2 = {
225
- id: 1,
226
- purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
227
- securityLevel: pshenmic_dpp_1.SecurityLevel.HIGH,
228
- keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
229
- readOnly: false,
230
- data: privateKey2.getPublicKey().bytes()
231
- };
232
- // Set identity public key signature for public key 0
233
- identityCreateStateTransition = sdk.identities.createStateTransition('create', {
234
- publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
235
- assetLockProof: {
236
- transaction: transaction,
237
- instantLock: instantLock,
238
- outputIndex: outputIndex,
239
- type: 'instantLock'
240
- }
241
- });
242
- identityCreateStateTransition.signByPrivateKey(privateKey1, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
243
- identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
244
- // Set identity public key signature for public key 1
245
- identityCreateStateTransition = sdk.identities.createStateTransition('create', {
246
- publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
247
- assetLockProof: {
248
- transaction: transaction,
249
- instantLock: instantLock,
250
- outputIndex: outputIndex,
251
- type: 'instantLock'
252
- }
253
- });
254
- identityCreateStateTransition.signByPrivateKey(privateKey2, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
255
- identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
256
- // Finalize
257
- identityCreateStateTransition = sdk.identities.createStateTransition('create', {
258
- publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
259
- assetLockProof: {
260
- transaction: transaction,
261
- instantLock: instantLock,
262
- outputIndex: outputIndex,
263
- type: 'instantLock'
264
- }
265
- });
266
- identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
267
- return [2 /*return*/];
138
+ identityCreateStateTransition.signByPrivateKey(privateKey1, KeyType.ECDSA_SECP256K1);
139
+ identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
140
+ // Set identity public key signature for public key 1
141
+ identityCreateStateTransition = sdk.identities.createStateTransition('create', {
142
+ publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
143
+ assetLockProof: {
144
+ transaction,
145
+ instantLock,
146
+ outputIndex,
147
+ type: 'instantLock'
148
+ }
268
149
  });
269
- }); });
270
- test('should be able to create IdentityTopUpTransition via InstantSend', function () { return __awaiter(void 0, void 0, void 0, function () {
271
- var transaction, instantLock, outputIndex, assetLockPrivateKey, identityId, identityTopUpTransaction;
272
- return __generator(this, function (_a) {
273
- transaction = '03000800011a468e6a7cf1c5111b09b7bca6743f2571a9bf13d2ff6d21d3d230fd1dea1e97000000006b483045022100fceb25c45e77e1a273660e4f4c9a09042fb858a57704806e14bf80a734af232a02201929893dd720cf5855e31dda577cda16df29520a9774b4f3e813a4cc468fe086012103e16ede6dc5c99f28e3a5733f47a7494992bc6ce4f98551c092645910b9888b8fffffffff0200e1f50500000000026a004054fa02000000001976a91416bbe230f46eea86fc4bf4dd550be45dc9adfcb488ac0000000024010100e1f505000000001976a9147f78813975a3282e09e284d97d93c083b202e34188ac';
274
- instantLock = '01011a468e6a7cf1c5111b09b7bca6743f2571a9bf13d2ff6d21d3d230fd1dea1e9700000000892304531821bcddfe960388f93e6e91bbae170987a5c6db33f0a4cf2d88ef148968a159512600791f94053e30f688aac43bf6e698fd78339a9ab5fd3b00000091ee77cadbf9683ca3d1fb1abcb2f561f0c745b26099fe5294885852a03a4f26770a3d437265f5f00ae21d0f681d0e1610a7ac47b6d463c3efdc5f7f922e310e6f3cd66c319e63e4f1c2cc70e97886e15485dba4f29b836bf55f0619837437e8';
275
- outputIndex = 0;
276
- assetLockPrivateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('3ca33236ab14f6df6cf87fcbb0551544fee7dcf4f251557af02c175725764a5a', 'testnet');
277
- identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
278
- identityTopUpTransaction = sdk.identities.createStateTransition('topUp', {
279
- identityId: identityId,
280
- assetLockProof: {
281
- transaction: transaction,
282
- instantLock: instantLock,
283
- outputIndex: outputIndex,
284
- type: 'instantLock'
285
- }
286
- });
287
- identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
288
- return [2 /*return*/];
150
+ identityCreateStateTransition.signByPrivateKey(privateKey2, KeyType.ECDSA_SECP256K1);
151
+ identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
152
+ // Finalize
153
+ identityCreateStateTransition = sdk.identities.createStateTransition('create', {
154
+ publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
155
+ assetLockProof: {
156
+ transaction,
157
+ instantLock,
158
+ outputIndex,
159
+ type: 'instantLock'
160
+ }
289
161
  });
290
- }); });
291
- test('should be able to create IdentityTopUpTransition via ChainLock', function () { return __awaiter(void 0, void 0, void 0, function () {
292
- var txid, outputIndex, coreChainLockedHeight, assetLockPrivateKey, identityId, identityTopUpTransaction;
293
- return __generator(this, function (_a) {
294
- txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
295
- outputIndex = 0;
296
- coreChainLockedHeight = 1337;
297
- assetLockPrivateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('3ca33236ab14f6df6cf87fcbb0551544fee7dcf4f251557af02c175725764a5a', 'testnet');
298
- identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
299
- identityTopUpTransaction = sdk.identities.createStateTransition('topUp', {
300
- identityId: identityId,
301
- assetLockProof: {
302
- txid: txid,
303
- outputIndex: outputIndex,
304
- coreChainLockedHeight: coreChainLockedHeight,
305
- type: 'chainLock'
306
- }
307
- });
308
- identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
309
- return [2 /*return*/];
162
+ identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, KeyType.ECDSA_SECP256K1);
163
+ });
164
+ test('should be able to create IdentityTopUpTransition via InstantSend', async () => {
165
+ const transaction = '03000800011a468e6a7cf1c5111b09b7bca6743f2571a9bf13d2ff6d21d3d230fd1dea1e97000000006b483045022100fceb25c45e77e1a273660e4f4c9a09042fb858a57704806e14bf80a734af232a02201929893dd720cf5855e31dda577cda16df29520a9774b4f3e813a4cc468fe086012103e16ede6dc5c99f28e3a5733f47a7494992bc6ce4f98551c092645910b9888b8fffffffff0200e1f50500000000026a004054fa02000000001976a91416bbe230f46eea86fc4bf4dd550be45dc9adfcb488ac0000000024010100e1f505000000001976a9147f78813975a3282e09e284d97d93c083b202e34188ac';
166
+ const instantLock = '01011a468e6a7cf1c5111b09b7bca6743f2571a9bf13d2ff6d21d3d230fd1dea1e9700000000892304531821bcddfe960388f93e6e91bbae170987a5c6db33f0a4cf2d88ef148968a159512600791f94053e30f688aac43bf6e698fd78339a9ab5fd3b00000091ee77cadbf9683ca3d1fb1abcb2f561f0c745b26099fe5294885852a03a4f26770a3d437265f5f00ae21d0f681d0e1610a7ac47b6d463c3efdc5f7f922e310e6f3cd66c319e63e4f1c2cc70e97886e15485dba4f29b836bf55f0619837437e8';
167
+ const outputIndex = 0;
168
+ const assetLockPrivateKey = PrivateKeyWASM.fromHex('3ca33236ab14f6df6cf87fcbb0551544fee7dcf4f251557af02c175725764a5a', 'testnet');
169
+ const identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
170
+ const identityTopUpTransaction = sdk.identities.createStateTransition('topUp', {
171
+ identityId,
172
+ assetLockProof: {
173
+ transaction,
174
+ instantLock,
175
+ outputIndex,
176
+ type: 'instantLock'
177
+ }
310
178
  });
311
- }); });
312
- test('should be able to create IdentityUpdateTransition', function () { return __awaiter(void 0, void 0, void 0, function () {
313
- var identityId, masterPrivateKey, masterKeyId, identity, revision, identityNonce, keyId, identityPrivateKey, identityPublicKeyInCreation, identityUpdateTransition;
314
- return __generator(this, function (_a) {
315
- switch (_a.label) {
316
- case 0:
317
- identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
318
- masterPrivateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('16f614c6242580628d849e3616491dda1eccce99642a85667eb9a364dc85324a', 'testnet');
319
- masterKeyId = 0;
320
- return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(identityId)];
321
- case 1:
322
- identity = _a.sent();
323
- revision = identity.revision + BigInt(1);
324
- return [4 /*yield*/, sdk.identities.getIdentityNonce(identityId)];
325
- case 2:
326
- identityNonce = (_a.sent()) + BigInt(1);
327
- keyId = identity.getPublicKeys()[identity.getPublicKeys().length - 1].keyId + 1;
328
- identityPrivateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('16f614c6242580628d849e3616491dda1eccce99642a85667eb9a364dc85324a', 'testnet');
329
- identityPublicKeyInCreation = {
330
- id: keyId,
331
- purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
332
- securityLevel: pshenmic_dpp_1.SecurityLevel.HIGH,
333
- keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
334
- readOnly: false,
335
- data: identityPrivateKey.getPublicKey().bytes()
336
- };
337
- identityUpdateTransition = sdk.identities.createStateTransition('update', {
338
- identityId: identityId,
339
- revision: revision,
340
- identityNonce: identityNonce,
341
- addPublicKeys: [identityPublicKeyInCreation]
342
- });
343
- identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
344
- identityPublicKeyInCreation.signature = identityUpdateTransition.signature;
345
- identityUpdateTransition = sdk.identities.createStateTransition('update', {
346
- identityId: identityId,
347
- revision: revision,
348
- identityNonce: identityNonce,
349
- addPublicKeys: [identityPublicKeyInCreation]
350
- });
351
- identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
352
- return [2 /*return*/];
179
+ identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, KeyType.ECDSA_SECP256K1);
180
+ });
181
+ test('should be able to create IdentityTopUpTransition via ChainLock', async () => {
182
+ const txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
183
+ const outputIndex = 0;
184
+ const coreChainLockedHeight = 1337;
185
+ const assetLockPrivateKey = PrivateKeyWASM.fromHex('3ca33236ab14f6df6cf87fcbb0551544fee7dcf4f251557af02c175725764a5a', 'testnet');
186
+ const identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
187
+ const identityTopUpTransaction = sdk.identities.createStateTransition('topUp', {
188
+ identityId,
189
+ assetLockProof: {
190
+ txid,
191
+ outputIndex,
192
+ coreChainLockedHeight,
193
+ type: 'chainLock'
353
194
  }
354
195
  });
355
- }); });
196
+ identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, KeyType.ECDSA_SECP256K1);
197
+ });
198
+ test('should be able to create IdentityUpdateTransition', async () => {
199
+ const identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
200
+ const masterPrivateKey = PrivateKeyWASM.fromHex('16f614c6242580628d849e3616491dda1eccce99642a85667eb9a364dc85324a', 'testnet');
201
+ const masterKeyId = 0;
202
+ const identity = await sdk.identities.getIdentityByIdentifier(identityId);
203
+ const revision = identity.revision + BigInt(1);
204
+ const identityNonce = await sdk.identities.getIdentityNonce(identityId) + BigInt(1);
205
+ const keyId = identity.getPublicKeys()[identity.getPublicKeys().length - 1].keyId + 1;
206
+ const identityPrivateKey = PrivateKeyWASM.fromHex('16f614c6242580628d849e3616491dda1eccce99642a85667eb9a364dc85324a', 'testnet');
207
+ const identityPublicKeyInCreation = {
208
+ id: keyId,
209
+ purpose: Purpose.AUTHENTICATION,
210
+ securityLevel: SecurityLevel.HIGH,
211
+ keyType: KeyType.ECDSA_SECP256K1,
212
+ readOnly: false,
213
+ data: identityPrivateKey.getPublicKey().bytes()
214
+ };
215
+ let identityUpdateTransition = sdk.identities.createStateTransition('update', {
216
+ identityId,
217
+ revision,
218
+ identityNonce,
219
+ addPublicKeys: [identityPublicKeyInCreation]
220
+ });
221
+ identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, KeyType.ECDSA_SECP256K1);
222
+ identityPublicKeyInCreation.signature = identityUpdateTransition.signature;
223
+ identityUpdateTransition = sdk.identities.createStateTransition('update', {
224
+ identityId,
225
+ revision,
226
+ identityNonce,
227
+ addPublicKeys: [identityPublicKeyInCreation]
228
+ });
229
+ identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, KeyType.ECDSA_SECP256K1);
230
+ });
356
231
  });
357
232
  });