dash-platform-sdk 1.3.0-dev.1 → 1.3.0-dev.10

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