dash 3.23.0-dev.1 → 3.23.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 (124) hide show
  1. package/README.md +57 -14
  2. package/build/src/SDK/Client/Client.spec.js +2 -4
  3. package/build/src/SDK/Client/Client.spec.js.map +1 -1
  4. package/build/src/SDK/Client/Platform/Platform.js +12 -0
  5. package/build/src/SDK/Client/Platform/Platform.js.map +1 -1
  6. package/build/src/SDK/Client/Platform/broadcastStateTransition.js +16 -9
  7. package/build/src/SDK/Client/Platform/broadcastStateTransition.js.map +1 -1
  8. package/build/src/SDK/Client/Platform/createAssetLockTransaction.js +8 -4
  9. package/build/src/SDK/Client/Platform/createAssetLockTransaction.js.map +1 -1
  10. package/build/src/SDK/Client/Platform/methods/contracts/publish.js +1 -1
  11. package/build/src/SDK/Client/Platform/methods/contracts/publish.js.map +1 -1
  12. package/build/src/SDK/Client/Platform/methods/contracts/update.js +1 -1
  13. package/build/src/SDK/Client/Platform/methods/contracts/update.js.map +1 -1
  14. package/build/src/SDK/Client/Platform/methods/documents/broadcast.js +1 -1
  15. package/build/src/SDK/Client/Platform/methods/documents/broadcast.js.map +1 -1
  16. package/build/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.js +8 -4
  17. package/build/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.js.map +1 -1
  18. package/build/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.js +42 -17
  19. package/build/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.js.map +1 -1
  20. package/build/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.js +8 -4
  21. package/build/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.js.map +1 -1
  22. package/build/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.js +7 -3
  23. package/build/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.js.map +1 -1
  24. package/build/src/SDK/Client/Platform/methods/identities/register.js +31 -8
  25. package/build/src/SDK/Client/Platform/methods/identities/register.js.map +1 -1
  26. package/build/src/SDK/Client/Platform/methods/identities/topUp.js +5 -7
  27. package/build/src/SDK/Client/Platform/methods/identities/topUp.js.map +1 -1
  28. package/build/src/SDK/Client/Platform/methods/identities/update.js +34 -5
  29. package/build/src/SDK/Client/Platform/methods/identities/update.js.map +1 -1
  30. package/build/src/SDK/SDK.js +10 -0
  31. package/build/src/SDK/SDK.js.map +1 -1
  32. package/build/src/test/fixtures/createIdentityFixtureInAccount.js +13 -3
  33. package/build/src/test/fixtures/createIdentityFixtureInAccount.js.map +1 -1
  34. package/build/src/test/fixtures/createTransactionFixtureInAccount.js +2 -2
  35. package/build/src/test/fixtures/createTransactionFixtureInAccount.js.map +1 -1
  36. package/build/src/test/mocks/createAndAttachTransportMocksToClient.js +2 -2
  37. package/build/src/test/mocks/createAndAttachTransportMocksToClient.js.map +1 -1
  38. package/build/tests/fixtures/contracts.json +1 -1
  39. package/build-utils/ws.js +15 -0
  40. package/dist/dash.min.js +9 -0
  41. package/dist/dash.min.js.LICENSE.txt +80 -0
  42. package/dist/dash.min.js.map +1 -0
  43. package/dist/src/SDK/Client/Platform/Platform.d.ts +7 -0
  44. package/dist/src/SDK/Client/Platform/broadcastStateTransition.d.ts +6 -1
  45. package/dist/src/SDK/Client/Platform/createAssetLockTransaction.d.ts +3 -2
  46. package/dist/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.d.ts +3 -2
  47. package/dist/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.d.ts +3 -2
  48. package/dist/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.d.ts +3 -2
  49. package/dist/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.d.ts +2 -1
  50. package/dist/src/SDK/Client/Platform/methods/identities/update.d.ts +4 -0
  51. package/dist/src/SDK/SDK.d.ts +9 -0
  52. package/docs/README.md +11 -52
  53. package/docs/_sidebar.md +0 -17
  54. package/docs/examples/fetch-an-identity-from-its-name.md +5 -9
  55. package/docs/examples/generate-a-new-mnemonic.md +1 -1
  56. package/docs/examples/pay-to-another-address.md +16 -13
  57. package/docs/examples/receive-money-and-check-balance.md +55 -39
  58. package/docs/examples/sign-and-verify-messages.md +19 -9
  59. package/docs/examples/use-different-account.md +5 -17
  60. package/docs/getting-started/core-concepts.md +6 -5
  61. package/docs/getting-started/dash-platform-applications.md +1 -1
  62. package/docs/getting-started/quickstart.md +7 -24
  63. package/docs/getting-started/with-typescript.md +5 -2
  64. package/docs/index.html +2 -2
  65. package/docs/platform/about-platform.md +5 -5
  66. package/docs/platform/contracts/about-contracts.md +2 -2
  67. package/docs/platform/contracts/create.md +5 -5
  68. package/docs/platform/contracts/get.md +1 -1
  69. package/docs/platform/contracts/publish.md +3 -3
  70. package/docs/platform/contracts/update.md +1 -4
  71. package/docs/platform/documents/broadcast.md +15 -15
  72. package/docs/platform/documents/create.md +5 -5
  73. package/docs/platform/documents/get.md +6 -5
  74. package/docs/platform/identities/about-identity.md +1 -1
  75. package/docs/platform/identities/get.md +1 -1
  76. package/docs/platform/identities/register.md +1 -1
  77. package/docs/platform/identities/topUp.md +2 -2
  78. package/docs/platform/names/about-dpns.md +1 -1
  79. package/docs/platform/names/register.md +9 -9
  80. package/docs/platform/names/resolve.md +1 -1
  81. package/docs/platform/names/resolveByRecord.md +9 -8
  82. package/docs/platform/names/search.md +1 -1
  83. package/docs/usage/dashcorelib-primitives.md +48 -37
  84. package/docs/wallet/about-wallet-lib.md +3 -3
  85. package/docs/wallet/accounts.md +11 -7
  86. package/docs/wallet/signing-encrypt.md +12 -6
  87. package/package.json +19 -15
  88. package/src/SDK/Client/Client.spec.ts +2 -4
  89. package/src/SDK/Client/Platform/Platform.ts +21 -0
  90. package/src/SDK/Client/Platform/broadcastStateTransition.ts +15 -6
  91. package/src/SDK/Client/Platform/createAssetLockTransaction.ts +5 -2
  92. package/src/SDK/Client/Platform/methods/contracts/publish.ts +1 -1
  93. package/src/SDK/Client/Platform/methods/contracts/update.ts +1 -1
  94. package/src/SDK/Client/Platform/methods/documents/broadcast.ts +1 -1
  95. package/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.ts +5 -2
  96. package/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.ts +38 -7
  97. package/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.ts +5 -2
  98. package/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.ts +4 -3
  99. package/src/SDK/Client/Platform/methods/identities/register.ts +33 -9
  100. package/src/SDK/Client/Platform/methods/identities/topUp.ts +5 -8
  101. package/src/SDK/Client/Platform/methods/identities/update.ts +35 -1
  102. package/src/SDK/SDK.ts +34 -21
  103. package/src/test/fixtures/createIdentityFixtureInAccount.ts +14 -3
  104. package/src/test/fixtures/createTransactionFixtureInAccount.ts +2 -2
  105. package/src/test/mocks/createAndAttachTransportMocksToClient.ts +2 -2
  106. package/tests/fixtures/contracts.json +1 -1
  107. package/tests/fixtures/ratePlatform.schema.json +1 -1
  108. package/webpack.base.config.js +14 -0
  109. package/webpack.config.js +6 -2
  110. package/docs/examples/publishing-a-new-contract.md +0 -68
  111. package/docs/examples/updating-a-contract.md +0 -55
  112. package/docs/examples/use-local-evonet.md +0 -19
  113. package/examples/node/create-and-fund-wallet.js +0 -28
  114. package/examples/node/register-contract.js +0 -34
  115. package/examples/node/register-identity.js +0 -23
  116. package/examples/node/register-name.js +0 -19
  117. package/examples/node/retrieve-contract.js +0 -20
  118. package/examples/node/retrieve-documents.js +0 -22
  119. package/examples/node/retrieve-identity.js +0 -20
  120. package/examples/node/retrieve-name.js +0 -14
  121. package/examples/node/sign-and-verify-messages.js +0 -29
  122. package/examples/schema.json +0 -58
  123. package/examples/web/usage.web.html +0 -12
  124. package/examples/web/usage.web.js +0 -28
@@ -1,22 +1,28 @@
1
- ## Sign a Transaction/Transition a message
1
+ ## Obtain account
2
+ ```js
3
+ const account = await client.wallet.getAccount();
4
+ ```
5
+
6
+ ## Sign a Transaction
7
+
2
8
 
3
9
  ```js
4
- const tx = new Dash.Transaction({
5
- //txOpts
10
+ const tx = new Dash.Core.Transaction({
11
+ // ...txOpts
6
12
  });
7
- const signedTx = client.account.sign(tx);
13
+ const signedTx = account.sign(tx);
8
14
  ```
9
15
 
10
16
  ## Encrypt a message
11
17
 
12
18
  ```js
13
19
  const message = 'Something';
14
- const signedMessage = client.account.encrypt('AES',message,'secret');
20
+ const signedMessage = account.encrypt('AES', message, 'secret');
15
21
  ```
16
22
 
17
23
  ## Decrypt a message
18
24
 
19
25
  ```js
20
26
  const encrypted = 'U2FsdGVkX19JLa+1UpbMcut1/QFWLMlKUS+iqz+7Wl4=';
21
- const message = client.account.decrypt('AES',encrypted,'secret');
27
+ const message = account.decrypt('AES', encrypted, 'secret');
22
28
  ```
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "dash",
3
- "version": "3.23.0-dev.1",
3
+ "version": "3.23.0-dev.10",
4
4
  "description": "Dash library for JavaScript/TypeScript ecosystem (Wallet, DAPI, Primitives, BLS, ...)",
5
5
  "main": "build/src/index.js",
6
6
  "unpkg": "dist/dash.min.js",
7
+ "browser": "dist/dash.min.js",
7
8
  "types": "dist/src/index.d.ts",
8
9
  "scripts": {
9
10
  "start:dev": "nodemon --exec 'yarn run build && yarn run test:unit'",
10
- "build": "yarn run build:ts",
11
- "build:web": "yarn run build:ts && webpack --stats-error-details",
11
+ "start:ts": "tsc --watch",
12
+ "build": "yarn run build:ts && webpack --stats-error-details",
12
13
  "build:ts": "tsc",
13
14
  "lint": "",
14
15
  "test": "yarn run test:unit && yarn run test:functional && yarn run test:browsers",
15
16
  "test:browsers": "karma start ./karma.conf.js --single-run",
16
17
  "test:unit": "TS_NODE_COMPILER_OPTIONS={\"target\":\"es6\"} ts-mocha \"src/**/*.spec.ts\"",
17
18
  "test:functional": "yarn run build && mocha --recursive tests/functional/**/*.js",
18
- "prepublishOnly": "yarn run build:web",
19
+ "prepublishOnly": "yarn run build",
19
20
  "prepare": "yarn run build"
20
21
  },
21
22
  "ultra": {
@@ -34,14 +35,14 @@
34
35
  },
35
36
  "homepage": "https://github.com/dashevo/DashJS#readme",
36
37
  "dependencies": {
37
- "@dashevo/dapi-client": "~0.23.0-dev.1",
38
- "@dashevo/dashcore-lib": "~0.19.30",
39
- "@dashevo/dashpay-contract": "~0.23.0-dev.1",
40
- "@dashevo/dpns-contract": "~0.23.0-dev.1",
41
- "@dashevo/dpp": "~0.23.0-dev.1",
42
- "@dashevo/grpc-common": "~0.23.0-dev.1",
43
- "@dashevo/masternode-reward-shares-contract": "~0.23.0-dev.1",
44
- "@dashevo/wallet-lib": "~7.23.0-dev.1",
38
+ "@dashevo/dapi-client": "~0.23.0-dev.10",
39
+ "@dashevo/dashcore-lib": "~0.19.44",
40
+ "@dashevo/dashpay-contract": "~0.23.0-dev.10",
41
+ "@dashevo/dpns-contract": "~0.23.0-dev.10",
42
+ "@dashevo/dpp": "~0.23.0-dev.10",
43
+ "@dashevo/grpc-common": "~0.23.0-dev.10",
44
+ "@dashevo/masternode-reward-shares-contract": "~0.23.0-dev.10",
45
+ "@dashevo/wallet-lib": "~7.23.0-dev.10",
45
46
  "bs58": "^4.0.1",
46
47
  "node-inspect-extracted": "^1.0.8"
47
48
  },
@@ -63,7 +64,7 @@
63
64
  "dotenv-safe": "^8.2.0",
64
65
  "events": "^3.3.0",
65
66
  "https-browserify": "^1.0.0",
66
- "karma": "^6.3.4",
67
+ "karma": "^6.4.1",
67
68
  "karma-chai": "^0.1.0",
68
69
  "karma-chrome-launcher": "^3.1.0",
69
70
  "karma-firefox-launcher": "^2.1.1",
@@ -71,7 +72,8 @@
71
72
  "karma-mocha-reporter": "^2.2.5",
72
73
  "karma-webpack": "^5.0.0",
73
74
  "mocha": "^9.1.2",
74
- "nodemon": "^2.0.4",
75
+ "net": "^1.0.2",
76
+ "nodemon": "^2.0.20",
75
77
  "os-browserify": "^0.3.0",
76
78
  "path-browserify": "^1.0.1",
77
79
  "process": "^0.11.10",
@@ -81,8 +83,10 @@
81
83
  "stream-browserify": "^3.0.0",
82
84
  "stream-http": "^3.2.0",
83
85
  "string_decoder": "^1.3.0",
86
+ "terser-webpack-plugin": "^5.3.1",
87
+ "tls": "^0.0.1",
84
88
  "ts-loader": "^8.0.2",
85
- "ts-mocha": "^8.0.0",
89
+ "ts-mocha": "^9.0.2",
86
90
  "ts-mock-imports": "^1.3.0",
87
91
  "ts-node": "^10.4.0",
88
92
  "typescript": "^3.9.5",
@@ -11,7 +11,6 @@ import { StateTransitionBroadcastError } from '../../errors/StateTransitionBroad
11
11
  const getDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentsFixture');
12
12
  // @ts-ignore
13
13
  const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
14
- const GetIdentityResponse = require("@dashevo/dapi-client/lib/methods/platform/getIdentity/GetIdentityResponse");
15
14
  const GetDataContractResponse = require("@dashevo/dapi-client/lib/methods/platform/getDataContract/GetDataContractResponse");
16
15
 
17
16
  import { createIdentityFixtureInAccount } from '../../test/fixtures/createIdentityFixtureInAccount';
@@ -68,7 +67,6 @@ describe('Dash - Client', function suite() {
68
67
  transportMock.getBlockHeaderByHash
69
68
  .returns(BlockHeader.fromString(blockHeaderFixture));
70
69
 
71
- dapiClientMock.platform.getIdentity.resolves(new GetIdentityResponse(identityFixture.toBuffer(), getResponseMetadataFixture()));
72
70
  dapiClientMock.platform.getDataContract.resolves(new GetDataContractResponse(dataContractFixture.toBuffer(), getResponseMetadataFixture()));
73
71
  });
74
72
 
@@ -269,7 +267,7 @@ describe('Dash - Client', function suite() {
269
267
  const interceptedSt = await client.platform.dpp.stateTransition.createFromBuffer(serializedSt);
270
268
 
271
269
  // .to.be.true() doesn't work after TS compilation in Chrome
272
- expect(await interceptedSt.verifySignature(identityFixture.getPublicKeyById(0))).to.be.equal(true);
270
+ expect(await interceptedSt.verifySignature(identityFixture.getPublicKeyById(1))).to.be.equal(true);
273
271
 
274
272
  const documentTransitions = interceptedSt.getTransitions();
275
273
 
@@ -313,7 +311,7 @@ describe('Dash - Client', function suite() {
313
311
  const interceptedSt = await client.platform.dpp.stateTransition.createFromBuffer(serializedSt);
314
312
 
315
313
  // .to.be.true() doesn't work after TS compilation in Chrome
316
- expect(await interceptedSt.verifySignature(identityFixture.getPublicKeyById(0))).to.be.equal(true);
314
+ expect(await interceptedSt.verifySignature(identityFixture.getPublicKeyById(1))).to.be.equal(true);
317
315
  expect(interceptedSt.getEntropy()).to.be.deep.equal(dataContractFixture.entropy);
318
316
  expect(interceptedSt.getDataContract().toObject()).to.be.deep.equal(dataContractFixture.toObject());
319
317
  });
@@ -4,6 +4,8 @@ import DashPlatformProtocol from "@dashevo/dpp";
4
4
  import Client from "../Client";
5
5
  import { IStateTransitionResult } from './IStateTransitionResult';
6
6
 
7
+ import createAssetLockTransaction from "./createAssetLockTransaction";
8
+
7
9
  import broadcastDocument from "./methods/documents/broadcast";
8
10
  import createDocument from "./methods/documents/create";
9
11
  import getDocument from "./methods/documents/get";
@@ -17,6 +19,10 @@ import getIdentity from "./methods/identities/get";
17
19
  import registerIdentity from "./methods/identities/register";
18
20
  import topUpIdentity from "./methods/identities/topUp";
19
21
  import updateIdentity from "./methods/identities/update";
22
+ import createIdentityCreateTransition from "./methods/identities/internal/createIdentityCreateTransition";
23
+ import createIdentityTopUpTransition from "./methods/identities/internal/createIdnetityTopUpTransition";
24
+ import createAssetLockProof from "./methods/identities/internal/createAssetLockProof";
25
+ import waitForCoreChainLockedHeight from "./methods/identities/internal/waitForCoreChainLockedHeight";
20
26
 
21
27
  import registerName from "./methods/names/register";
22
28
  import resolveName from "./methods/names/resolve";
@@ -67,6 +73,13 @@ interface Identities {
67
73
  register: Function,
68
74
  topUp: Function,
69
75
  update: Function,
76
+ utils: {
77
+ createAssetLockTransaction: Function
78
+ createAssetLockProof: Function
79
+ createIdentityCreateTransition: Function
80
+ createIdentityTopUpTransition: Function
81
+ waitForCoreChainLockedHeight: Function
82
+ }
70
83
  }
71
84
 
72
85
  interface DataContracts {
@@ -147,6 +160,13 @@ export class Platform {
147
160
  get: getIdentity.bind(this),
148
161
  topUp: topUpIdentity.bind(this),
149
162
  update: updateIdentity.bind(this),
163
+ utils: {
164
+ createAssetLockProof: createAssetLockProof.bind(this),
165
+ createAssetLockTransaction: createAssetLockTransaction.bind(this),
166
+ createIdentityCreateTransition: createIdentityCreateTransition.bind(this),
167
+ createIdentityTopUpTransition: createIdentityTopUpTransition.bind(this),
168
+ waitForCoreChainLockedHeight: waitForCoreChainLockedHeight.bind(this),
169
+ }
150
170
  };
151
171
 
152
172
  this.client = options.client;
@@ -175,3 +195,4 @@ export class Platform {
175
195
  await this.dpp.initialize();
176
196
  }
177
197
  }
198
+
@@ -12,21 +12,30 @@ const GrpcError = require('@dashevo/grpc-common/lib/server/error/GrpcError');
12
12
 
13
13
  /**
14
14
  * @param {Platform} platform
15
+ * @param {Object} [options]
16
+ * @param {boolean} [options.skipValidation=false]
17
+ *
15
18
  * @param stateTransition
16
19
  */
17
- export default async function broadcastStateTransition(platform: Platform, stateTransition: any): Promise<IStateTransitionResult|void> {
20
+ export default async function broadcastStateTransition(
21
+ platform: Platform,
22
+ stateTransition: any,
23
+ options: { skipValidation?: boolean; } = {},
24
+ ): Promise<IStateTransitionResult|void> {
18
25
  const { client, dpp } = platform;
19
26
 
20
- const result = await dpp.stateTransition.validateBasic(stateTransition);
27
+ if (!options.skipValidation) {
28
+ const result = await dpp.stateTransition.validateBasic(stateTransition);
21
29
 
22
- if (!result.isValid()) {
30
+ if (!result.isValid()) {
23
31
  const consensusError = result.getFirstError();
24
32
 
25
33
  throw new StateTransitionBroadcastError(
26
- consensusError.getCode(),
27
- consensusError.message,
28
- consensusError,
34
+ consensusError.getCode(),
35
+ consensusError.message,
36
+ consensusError,
29
37
  );
38
+ }
30
39
  }
31
40
 
32
41
  // Subscribing to future result
@@ -7,12 +7,13 @@ const ASSET_LOCK_OUTPUT_INDEX = 0;
7
7
 
8
8
  /**
9
9
  * Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
10
- * @param {Platform} platform
10
+ * @param {Platform} this
11
11
  * @param {number} fundingAmount - amount of dash to fund the identity's credits
12
12
  * @return {Promise<{transaction: Transaction, privateKey: PrivateKey}>} - transaction and one time private key
13
13
  * that can be used to sign registration/top-up state transition
14
14
  */
15
- export default async function createAssetLockTransaction(platform : Platform, fundingAmount): Promise<{ transaction: Transaction, privateKey: PrivateKey, outputIndex: number }> {
15
+ export async function createAssetLockTransaction(this : Platform, fundingAmount): Promise<{ transaction: Transaction, privateKey: PrivateKey, outputIndex: number }> {
16
+ const platform = this;
16
17
  const account = await platform.client.getWalletAccount();
17
18
 
18
19
  // @ts-ignore
@@ -61,3 +62,5 @@ export default async function createAssetLockTransaction(platform : Platform, fu
61
62
  outputIndex: ASSET_LOCK_OUTPUT_INDEX,
62
63
  };
63
64
  }
65
+
66
+ export default createAssetLockTransaction;
@@ -17,7 +17,7 @@ export default async function publish(this: Platform, dataContract: any, identit
17
17
 
18
18
  const dataContractCreateTransition = dpp.dataContract.createDataContractCreateTransition(dataContract);
19
19
 
20
- await signStateTransition(this, dataContractCreateTransition, identity);
20
+ await signStateTransition(this, dataContractCreateTransition, identity, 1);
21
21
  await broadcastStateTransition(this, dataContractCreateTransition);
22
22
 
23
23
  return dataContractCreateTransition;
@@ -24,7 +24,7 @@ export default async function update(this: Platform, dataContract: any, identity
24
24
 
25
25
  const dataContractUpdateTransition = dpp.dataContract.createDataContractUpdateTransition(updatedDataContract);
26
26
 
27
- await signStateTransition(this, dataContractUpdateTransition, identity);
27
+ await signStateTransition(this, dataContractUpdateTransition, identity, 1);
28
28
  await broadcastStateTransition(this, dataContractUpdateTransition);
29
29
 
30
30
  // Update app with updated data contract if available
@@ -20,7 +20,7 @@ export default async function broadcast(this: Platform, documents: { create?: Do
20
20
 
21
21
  const documentsBatchTransition = dpp.document.createStateTransition(documents);
22
22
 
23
- await signStateTransition(this, documentsBatchTransition, identity);
23
+ await signStateTransition(this, documentsBatchTransition, identity, 1);
24
24
 
25
25
  // Broadcast state transition also wait for the result to be obtained
26
26
  await broadcastStateTransition(this, documentsBatchTransition);
@@ -7,13 +7,14 @@ const { InstantLockTimeoutError, TxMetadataTimeoutError } = require('@dashevo/wa
7
7
 
8
8
  /**
9
9
  * Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
10
- * @param {Platform} platform
10
+ * @param {Platform} this
11
11
  * @param {Transaction} assetLockTransaction
12
12
  * @param {number} outputIndex - index of the funding output in the asset lock transaction
13
13
  * @return {AssetLockProof} - asset lock proof to be used in the state transition
14
14
  * that can be used to sign registration/top-up state transition
15
15
  */
16
- export default async function createAssetLockProof(platform : Platform, assetLockTransaction: Transaction, outputIndex: number): Promise<any> {
16
+ export async function createAssetLockProof(this : Platform, assetLockTransaction: Transaction, outputIndex: number): Promise<any> {
17
+ const platform = this;
17
18
  await platform.initialize();
18
19
 
19
20
  const account = await platform.client.getWalletAccount();
@@ -119,3 +120,5 @@ export default async function createAssetLockProof(platform : Platform, assetLoc
119
120
  })
120
121
  ]);
121
122
  }
123
+
124
+ export default createAssetLockProof;
@@ -4,13 +4,14 @@ import IdentityPublicKey from "@dashevo/dpp/lib/identity/IdentityPublicKey"
4
4
 
5
5
  /**
6
6
  * Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
7
- * @param {Platform} platform
7
+ * @param {Platform} this
8
8
  * @param {AssetLockProof} assetLockProof - asset lock transaction proof for the identity create transition
9
9
  * @param {PrivateKey} assetLockPrivateKey - private key used in asset lock
10
10
  * @return {{identity: Identity, identityCreateTransition: IdentityCreateTransition}} - identity, state transition and index of the key used to create it
11
11
  * that can be used to sign registration/top-up state transition
12
12
  */
13
- export default async function createIdentityCreateTransition(platform : Platform, assetLockProof: any, assetLockPrivateKey: PrivateKey): Promise<{ identity: any, identityCreateTransition: any, identityIndex: number }> {
13
+ export async function createIdentityCreateTransition(this : Platform, assetLockProof: any, assetLockPrivateKey: PrivateKey): Promise<{ identity: any, identityCreateTransition: any, identityIndex: number }> {
14
+ const platform = this;
14
15
  await platform.initialize();
15
16
 
16
17
  const account = await platform.client.getWalletAccount();
@@ -19,22 +20,50 @@ export default async function createIdentityCreateTransition(platform : Platform
19
20
  const identityIndex = await account.getUnusedIdentityIndex();
20
21
 
21
22
  // @ts-ignore
22
- const { privateKey: identityPrivateKey } = account.identities.getIdentityHDKeyByIndex(identityIndex, 0);
23
- const identityPublicKey = identityPrivateKey.toPublicKey();
23
+ const { privateKey: identityMasterPrivateKey } = account.identities.getIdentityHDKeyByIndex(identityIndex, 0);
24
+ const identityMasterPublicKey = identityMasterPrivateKey.toPublicKey();
25
+
26
+ const { privateKey: identitySecondPrivateKey } = account.identities.getIdentityHDKeyByIndex(identityIndex, 1);
27
+ const identitySecondPublicKey = identitySecondPrivateKey.toPublicKey();
24
28
 
25
29
  // Create Identity
26
30
  // @ts-ignore
27
31
  const identity = dpp.identity.create(
28
32
  assetLockProof, [{
29
- key: identityPublicKey,
33
+ key: identityMasterPublicKey,
30
34
  purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
31
35
  securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER
32
- }]
36
+ },
37
+ {
38
+ key: identitySecondPublicKey,
39
+ purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
40
+ securityLevel: IdentityPublicKey.SECURITY_LEVELS.HIGH
41
+ }
42
+ ]
33
43
  );
34
44
 
35
- // Create ST
45
+ // Create ST
36
46
  const identityCreateTransition = dpp.identity.createIdentityCreateTransition(identity);
37
47
 
48
+ // Create key proofs
49
+
50
+ const [masterKey, secondKey] = identityCreateTransition.getPublicKeys();
51
+
52
+ await identityCreateTransition.signByPrivateKey(identityMasterPrivateKey, IdentityPublicKey.TYPES.ECDSA_SECP256K1);
53
+
54
+ masterKey.setSignature(identityCreateTransition.getSignature());
55
+
56
+ identityCreateTransition.setSignature(undefined);
57
+
58
+ await identityCreateTransition.signByPrivateKey(identitySecondPrivateKey, IdentityPublicKey.TYPES.ECDSA_SECP256K1);
59
+
60
+ secondKey.setSignature(identityCreateTransition.getSignature());
61
+
62
+ identityCreateTransition.setSignature(undefined);
63
+
64
+
65
+ // Sign and validate state transition
66
+
38
67
  await identityCreateTransition.signByPrivateKey(assetLockPrivateKey, IdentityPublicKey.TYPES.ECDSA_SECP256K1);
39
68
 
40
69
  const result = await dpp.stateTransition.validateBasic(identityCreateTransition);
@@ -45,3 +74,5 @@ export default async function createIdentityCreateTransition(platform : Platform
45
74
 
46
75
  return { identity, identityCreateTransition, identityIndex };
47
76
  }
77
+
78
+ export default createIdentityCreateTransition;
@@ -4,14 +4,15 @@ import IdentityPublicKey from "@dashevo/dpp/lib/identity/IdentityPublicKey"
4
4
 
5
5
  /**
6
6
  * Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
7
- * @param {Platform} platform
7
+ * @param {Platform} this
8
8
  * @param {AssetLockProof} assetLockProof - asset lock transaction proof for the identity create transition
9
9
  * @param {PrivateKey} assetLockPrivateKey - private key used in asset lock
10
10
  * @param {string|Buffer|Identifier} identityId
11
11
  * @return {{identity: Identity, identityCreateTransition: IdentityCreateTransition}} - identity, state transition and index of the key used to create it
12
12
  * that can be used to sign registration/top-up state transition
13
13
  */
14
- export default async function createIdentityTopUpTransition(platform : Platform, assetLockProof: any, assetLockPrivateKey: PrivateKey, identityId: any): Promise<any> {
14
+ export async function createIdentityTopUpTransition(this : Platform, assetLockProof: any, assetLockPrivateKey: PrivateKey, identityId: any): Promise<any> {
15
+ const platform = this;
15
16
  await platform.initialize();
16
17
 
17
18
  const { dpp } = platform;
@@ -31,3 +32,5 @@ export default async function createIdentityTopUpTransition(platform : Platform,
31
32
 
32
33
  return identityTopUpTransition;
33
34
  }
35
+
36
+ export default createIdentityTopUpTransition;
@@ -2,10 +2,11 @@ import { Platform } from "../../../Platform";
2
2
 
3
3
  import { ownerId as dpnsOwnerId } from "@dashevo/dpns-contract/lib/systemIds";
4
4
 
5
- export default async function waitForCoreChainLockedHeight(
6
- platform : Platform,
5
+ export async function waitForCoreChainLockedHeight(
6
+ this : Platform,
7
7
  expectedCoreHeight : number,
8
8
  ): Promise<{ promise: Promise<any>, cancel: Function }> {
9
+ const platform = this;
9
10
  await platform.initialize();
10
11
 
11
12
  const interval = 5000;
@@ -64,6 +65,6 @@ export default async function waitForCoreChainLockedHeight(
64
65
  }
65
66
  }
66
67
 
67
-
68
+ export default waitForCoreChainLockedHeight;
68
69
 
69
70
 
@@ -1,8 +1,6 @@
1
1
  import { Platform } from "../../Platform";
2
- import createAssetLockTransaction from "../../createAssetLockTransaction";
3
- import createIdentityCreateTransition from "./internal/createIdentityCreateTransition";
4
- import createAssetLockProof from "./internal/createAssetLockProof";
5
2
  import broadcastStateTransition from "../../broadcastStateTransition";
3
+ import {wait} from "../../../../../utils/wait";
6
4
 
7
5
  /**
8
6
  * Register identities to the platform
@@ -12,7 +10,7 @@ import broadcastStateTransition from "../../broadcastStateTransition";
12
10
  */
13
11
  export default async function register(
14
12
  this: Platform,
15
- fundingAmount : number = 10000
13
+ fundingAmount : number = 100000
16
14
  ): Promise<any> {
17
15
  await this.initialize();
18
16
 
@@ -24,15 +22,17 @@ export default async function register(
24
22
  transaction: assetLockTransaction,
25
23
  privateKey: assetLockPrivateKey,
26
24
  outputIndex: assetLockOutputIndex
27
- } = await createAssetLockTransaction(this, fundingAmount);
25
+ } = await this.identities.utils.createAssetLockTransaction(fundingAmount);
28
26
 
29
27
  // Broadcast Asset Lock transaction
30
28
  await account.broadcastTransaction(assetLockTransaction);
31
- const assetLockProof = await createAssetLockProof(this, assetLockTransaction, assetLockOutputIndex);
32
29
 
33
- const { identity, identityCreateTransition, identityIndex } = await createIdentityCreateTransition(
34
- this, assetLockProof, assetLockPrivateKey
35
- );
30
+ const assetLockProof = await this.identities.utils
31
+ .createAssetLockProof(assetLockTransaction, assetLockOutputIndex);
32
+
33
+ const { identity, identityCreateTransition, identityIndex } = await this.identities.utils
34
+ .createIdentityCreateTransition(assetLockProof, assetLockPrivateKey);
35
+
36
36
  await broadcastStateTransition(this, identityCreateTransition);
37
37
 
38
38
  // If state transition was broadcast without any errors, import identity to the account
@@ -43,5 +43,29 @@ export default async function register(
43
43
  identityIndex,
44
44
  );
45
45
 
46
+ // Fetch identity from the network because the current identity object
47
+ // doesn't have metadata and balance information. Due to replication lag
48
+ // some nodes couldn't have it yet, so we need to try multiple times
49
+ const maxAttempts = 20;
50
+ let attempt = 0;
51
+ let registeredIdentity: any = null; // We don't have Identity type yet
52
+
53
+ while (registeredIdentity === null && attempt < maxAttempts) {
54
+ await wait(100);
55
+
56
+ registeredIdentity = await this.identities.get(identity.getId());
57
+ attempt++;
58
+ }
59
+
60
+ if (registeredIdentity === null) {
61
+ throw new Error(`Can't fetch created identity with id ${identity.getId()}`);
62
+ }
63
+
64
+ // We cannot just return registeredIdentity as we want to
65
+ // keep additional information (assetLockProof and transaction) instance
66
+ identity.setMetadata(registeredIdentity.getMetadata());
67
+ identity.setBalance(registeredIdentity.getBalance());
68
+ identity.setPublicKeys(registeredIdentity.getPublicKeys());
69
+
46
70
  return identity;
47
71
  }
@@ -1,10 +1,6 @@
1
- // @ts-ignore
2
1
  import Identifier from "@dashevo/dpp/lib/Identifier";
3
2
  import {Platform} from "../../Platform";
4
3
 
5
- import createAssetLockTransaction from "../../createAssetLockTransaction";
6
- import createAssetLockProof from "./internal/createAssetLockProof";
7
- import createIdentityTopUpTransition from "./internal/createIdnetityTopUpTransition";
8
4
  import broadcastStateTransition from "../../broadcastStateTransition";
9
5
 
10
6
  /**
@@ -28,15 +24,16 @@ export async function topUp(this: Platform, identityId: Identifier | string, amo
28
24
  transaction: assetLockTransaction,
29
25
  privateKey: assetLockPrivateKey,
30
26
  outputIndex: assetLockOutputIndex
31
- } = await createAssetLockTransaction(this, amount);
27
+ } = await this.identities.utils.createAssetLockTransaction(amount);
32
28
 
33
29
  // Broadcast Asset Lock transaction
34
30
  await account.broadcastTransaction(assetLockTransaction);
35
31
  // Create a proof for the asset lock transaction
36
- const assetLockProof = await createAssetLockProof(this, assetLockTransaction, assetLockOutputIndex);
32
+ const assetLockProof = await this.identities.utils
33
+ .createAssetLockProof(assetLockTransaction, assetLockOutputIndex);
37
34
 
38
- // @ts-ignore
39
- const identityTopUpTransition = await createIdentityTopUpTransition(this, assetLockProof, assetLockPrivateKey, identityId);
35
+ const identityTopUpTransition = await this.identities.utils
36
+ .createIdentityTopUpTransition(assetLockProof, assetLockPrivateKey, identityId);
40
37
 
41
38
  // Broadcast ST
42
39
  await broadcastStateTransition(this, identityTopUpTransition);
@@ -11,6 +11,7 @@ import broadcastStateTransition from "../../broadcastStateTransition";
11
11
  * @param {Platform} this - bound instance class
12
12
  * @param {Identity} identity - identity to update
13
13
  * @param {{add: IdentityPublicKey[]; disable: IdentityPublicKey[]}} publicKeys - public keys to add
14
+ * @param {Object<string, any>} privateKeys - public keys to add
14
15
  *
15
16
  * @returns {boolean}
16
17
  */
@@ -18,6 +19,7 @@ export async function update(
18
19
  this: Platform,
19
20
  identity: Identity,
20
21
  publicKeys: { add?: IdentityPublicKey[]; disable?: IdentityPublicKey[] },
22
+ privateKeys: { string, any },
21
23
  ): Promise<any> {
22
24
  await this.initialize();
23
25
 
@@ -28,7 +30,39 @@ export async function update(
28
30
  publicKeys,
29
31
  );
30
32
 
31
- await signStateTransition(this, identityUpdateTransition, identity);
33
+ const signerKeyIndex = 0;
34
+
35
+ // Create key proofs
36
+ if (identityUpdateTransition.getPublicKeysToAdd()) {
37
+ const signerKey = identity.getPublicKeys()[signerKeyIndex];
38
+
39
+ // must be run sequentially! will not work with Promise.all!
40
+ // more info at https://jrsinclair.com/articles/2019/how-to-run-async-js-in-parallel-or-sequential/
41
+
42
+ const starterPromise = Promise.resolve(null);
43
+
44
+ await identityUpdateTransition.getPublicKeysToAdd().reduce(
45
+ (previousPromise, publicKey) => previousPromise.then(async () => {
46
+ const privateKey = privateKeys[publicKey.getId()];
47
+
48
+ if (!privateKey) {
49
+ throw new Error(`Private key for key ${publicKey.getId()} not found`);
50
+ }
51
+
52
+ identityUpdateTransition.setSignaturePublicKeyId(signerKey.getId());
53
+
54
+ await identityUpdateTransition.signByPrivateKey(privateKey, publicKey.getType());
55
+
56
+ publicKey.setSignature(identityUpdateTransition.getSignature());
57
+
58
+ identityUpdateTransition.setSignature(undefined);
59
+ identityUpdateTransition.setSignaturePublicKeyId(undefined);
60
+ }),
61
+ starterPromise,
62
+ );
63
+ }
64
+
65
+ await signStateTransition(this, identityUpdateTransition, identity, signerKeyIndex);
32
66
 
33
67
  const result = await dpp.stateTransition.validateBasic(identityUpdateTransition);
34
68