dash 3.23.0-dev.1 → 3.23.0-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -3
- package/build/src/SDK/Client/Client.spec.js +2 -4
- package/build/src/SDK/Client/Client.spec.js.map +1 -1
- package/build/src/SDK/Client/Platform/Platform.js +12 -0
- package/build/src/SDK/Client/Platform/Platform.js.map +1 -1
- package/build/src/SDK/Client/Platform/broadcastStateTransition.js +16 -9
- package/build/src/SDK/Client/Platform/broadcastStateTransition.js.map +1 -1
- package/build/src/SDK/Client/Platform/createAssetLockTransaction.js +8 -4
- package/build/src/SDK/Client/Platform/createAssetLockTransaction.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/contracts/publish.js +1 -1
- package/build/src/SDK/Client/Platform/methods/contracts/publish.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/contracts/update.js +1 -1
- package/build/src/SDK/Client/Platform/methods/contracts/update.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/documents/broadcast.js +1 -1
- package/build/src/SDK/Client/Platform/methods/documents/broadcast.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.js +8 -4
- package/build/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.js +42 -17
- package/build/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.js +8 -4
- package/build/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.js +7 -3
- package/build/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/identities/register.js +15 -8
- package/build/src/SDK/Client/Platform/methods/identities/register.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/identities/topUp.js +5 -7
- package/build/src/SDK/Client/Platform/methods/identities/topUp.js.map +1 -1
- package/build/src/SDK/Client/Platform/methods/identities/update.js +34 -5
- package/build/src/SDK/Client/Platform/methods/identities/update.js.map +1 -1
- package/build/src/SDK/SDK.js +10 -0
- package/build/src/SDK/SDK.js.map +1 -1
- package/build/src/test/fixtures/createIdentityFixtureInAccount.js +13 -3
- package/build/src/test/fixtures/createIdentityFixtureInAccount.js.map +1 -1
- package/build/src/test/fixtures/createTransactionFixtureInAccount.js +2 -2
- package/build/src/test/fixtures/createTransactionFixtureInAccount.js.map +1 -1
- package/build/src/test/mocks/createAndAttachTransportMocksToClient.js +2 -2
- package/build/src/test/mocks/createAndAttachTransportMocksToClient.js.map +1 -1
- package/build/tests/fixtures/contracts.json +1 -1
- package/build-utils/ws.js +15 -0
- package/dist/dash.min.js +9 -0
- package/dist/dash.min.js.LICENSE.txt +80 -0
- package/dist/dash.min.js.map +1 -0
- package/dist/src/SDK/Client/Platform/Platform.d.ts +7 -0
- package/dist/src/SDK/Client/Platform/broadcastStateTransition.d.ts +6 -1
- package/dist/src/SDK/Client/Platform/createAssetLockTransaction.d.ts +3 -2
- package/dist/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.d.ts +3 -2
- package/dist/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.d.ts +3 -2
- package/dist/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.d.ts +3 -2
- package/dist/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.d.ts +2 -1
- package/dist/src/SDK/Client/Platform/methods/identities/update.d.ts +4 -0
- package/dist/src/SDK/SDK.d.ts +9 -0
- package/docs/README.md +2 -2
- package/package.json +16 -12
- package/src/SDK/Client/Client.spec.ts +2 -4
- package/src/SDK/Client/Platform/Platform.ts +21 -0
- package/src/SDK/Client/Platform/broadcastStateTransition.ts +15 -6
- package/src/SDK/Client/Platform/createAssetLockTransaction.ts +5 -2
- package/src/SDK/Client/Platform/methods/contracts/publish.ts +1 -1
- package/src/SDK/Client/Platform/methods/contracts/update.ts +1 -1
- package/src/SDK/Client/Platform/methods/documents/broadcast.ts +1 -1
- package/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.ts +5 -2
- package/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.ts +38 -7
- package/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.ts +5 -2
- package/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.ts +4 -3
- package/src/SDK/Client/Platform/methods/identities/register.ts +17 -9
- package/src/SDK/Client/Platform/methods/identities/topUp.ts +5 -8
- package/src/SDK/Client/Platform/methods/identities/update.ts +35 -1
- package/src/SDK/SDK.ts +34 -21
- package/src/test/fixtures/createIdentityFixtureInAccount.ts +14 -3
- package/src/test/fixtures/createTransactionFixtureInAccount.ts +2 -2
- package/src/test/mocks/createAndAttachTransportMocksToClient.ts +2 -2
- package/tests/fixtures/contracts.json +1 -1
- package/tests/fixtures/ratePlatform.schema.json +1 -1
- package/webpack.base.config.js +14 -0
- package/webpack.config.js +6 -2
|
@@ -39,6 +39,13 @@ interface Identities {
|
|
|
39
39
|
register: Function;
|
|
40
40
|
topUp: Function;
|
|
41
41
|
update: Function;
|
|
42
|
+
utils: {
|
|
43
|
+
createAssetLockTransaction: Function;
|
|
44
|
+
createAssetLockProof: Function;
|
|
45
|
+
createIdentityCreateTransition: Function;
|
|
46
|
+
createIdentityTopUpTransition: Function;
|
|
47
|
+
waitForCoreChainLockedHeight: Function;
|
|
48
|
+
};
|
|
42
49
|
}
|
|
43
50
|
interface DataContracts {
|
|
44
51
|
update: Function;
|
|
@@ -2,6 +2,11 @@ import { Platform } from "./Platform";
|
|
|
2
2
|
import { IStateTransitionResult } from "./IStateTransitionResult";
|
|
3
3
|
/**
|
|
4
4
|
* @param {Platform} platform
|
|
5
|
+
* @param {Object} [options]
|
|
6
|
+
* @param {boolean} [options.skipValidation=false]
|
|
7
|
+
*
|
|
5
8
|
* @param stateTransition
|
|
6
9
|
*/
|
|
7
|
-
export default function broadcastStateTransition(platform: Platform, stateTransition: any
|
|
10
|
+
export default function broadcastStateTransition(platform: Platform, stateTransition: any, options?: {
|
|
11
|
+
skipValidation?: boolean;
|
|
12
|
+
}): Promise<IStateTransitionResult | void>;
|
|
@@ -2,13 +2,14 @@ import { PrivateKey, Transaction } from "@dashevo/dashcore-lib";
|
|
|
2
2
|
import { Platform } from "./Platform";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
|
|
5
|
-
* @param {Platform}
|
|
5
|
+
* @param {Platform} this
|
|
6
6
|
* @param {number} fundingAmount - amount of dash to fund the identity's credits
|
|
7
7
|
* @return {Promise<{transaction: Transaction, privateKey: PrivateKey}>} - transaction and one time private key
|
|
8
8
|
* that can be used to sign registration/top-up state transition
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export declare function createAssetLockTransaction(this: Platform, fundingAmount: any): Promise<{
|
|
11
11
|
transaction: Transaction;
|
|
12
12
|
privateKey: PrivateKey;
|
|
13
13
|
outputIndex: number;
|
|
14
14
|
}>;
|
|
15
|
+
export default createAssetLockTransaction;
|
|
@@ -2,10 +2,11 @@ import { Transaction } from "@dashevo/dashcore-lib";
|
|
|
2
2
|
import { Platform } from "../../../Platform";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
|
|
5
|
-
* @param {Platform}
|
|
5
|
+
* @param {Platform} this
|
|
6
6
|
* @param {Transaction} assetLockTransaction
|
|
7
7
|
* @param {number} outputIndex - index of the funding output in the asset lock transaction
|
|
8
8
|
* @return {AssetLockProof} - asset lock proof to be used in the state transition
|
|
9
9
|
* that can be used to sign registration/top-up state transition
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export declare function createAssetLockProof(this: Platform, assetLockTransaction: Transaction, outputIndex: number): Promise<any>;
|
|
12
|
+
export default createAssetLockProof;
|
package/dist/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.d.ts
CHANGED
|
@@ -2,14 +2,15 @@ import { PrivateKey } from "@dashevo/dashcore-lib";
|
|
|
2
2
|
import { Platform } from "../../../Platform";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
|
|
5
|
-
* @param {Platform}
|
|
5
|
+
* @param {Platform} this
|
|
6
6
|
* @param {AssetLockProof} assetLockProof - asset lock transaction proof for the identity create transition
|
|
7
7
|
* @param {PrivateKey} assetLockPrivateKey - private key used in asset lock
|
|
8
8
|
* @return {{identity: Identity, identityCreateTransition: IdentityCreateTransition}} - identity, state transition and index of the key used to create it
|
|
9
9
|
* that can be used to sign registration/top-up state transition
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export declare function createIdentityCreateTransition(this: Platform, assetLockProof: any, assetLockPrivateKey: PrivateKey): Promise<{
|
|
12
12
|
identity: any;
|
|
13
13
|
identityCreateTransition: any;
|
|
14
14
|
identityIndex: number;
|
|
15
15
|
}>;
|
|
16
|
+
export default createIdentityCreateTransition;
|
package/dist/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { PrivateKey } from "@dashevo/dashcore-lib";
|
|
|
2
2
|
import { Platform } from "../../../Platform";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
|
|
5
|
-
* @param {Platform}
|
|
5
|
+
* @param {Platform} this
|
|
6
6
|
* @param {AssetLockProof} assetLockProof - asset lock transaction proof for the identity create transition
|
|
7
7
|
* @param {PrivateKey} assetLockPrivateKey - private key used in asset lock
|
|
8
8
|
* @param {string|Buffer|Identifier} identityId
|
|
9
9
|
* @return {{identity: Identity, identityCreateTransition: IdentityCreateTransition}} - identity, state transition and index of the key used to create it
|
|
10
10
|
* that can be used to sign registration/top-up state transition
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export declare function createIdentityTopUpTransition(this: Platform, assetLockProof: any, assetLockPrivateKey: PrivateKey, identityId: any): Promise<any>;
|
|
13
|
+
export default createIdentityTopUpTransition;
|
package/dist/src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Platform } from "../../../Platform";
|
|
2
|
-
export
|
|
2
|
+
export declare function waitForCoreChainLockedHeight(this: Platform, expectedCoreHeight: number): Promise<{
|
|
3
3
|
promise: Promise<any>;
|
|
4
4
|
cancel: Function;
|
|
5
5
|
}>;
|
|
6
|
+
export default waitForCoreChainLockedHeight;
|
|
@@ -7,11 +7,15 @@ import IdentityPublicKey from "@dashevo/dpp/lib/identity/IdentityPublicKey";
|
|
|
7
7
|
* @param {Platform} this - bound instance class
|
|
8
8
|
* @param {Identity} identity - identity to update
|
|
9
9
|
* @param {{add: IdentityPublicKey[]; disable: IdentityPublicKey[]}} publicKeys - public keys to add
|
|
10
|
+
* @param {Object<string, any>} privateKeys - public keys to add
|
|
10
11
|
*
|
|
11
12
|
* @returns {boolean}
|
|
12
13
|
*/
|
|
13
14
|
export declare function update(this: Platform, identity: Identity, publicKeys: {
|
|
14
15
|
add?: IdentityPublicKey[];
|
|
15
16
|
disable?: IdentityPublicKey[];
|
|
17
|
+
}, privateKeys: {
|
|
18
|
+
string: any;
|
|
19
|
+
any: any;
|
|
16
20
|
}): Promise<any>;
|
|
17
21
|
export default update;
|
package/dist/src/SDK/SDK.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Client as _Client } from './Client';
|
|
3
3
|
import { Platform as _Platform } from './Platform';
|
|
4
|
+
import { StateTransitionBroadcastError } from '../errors/StateTransitionBroadcastError';
|
|
4
5
|
import { Wallet as _Wallet, Account as _Account, DerivableKeyChain as _KeyChain } from '@dashevo/wallet-lib';
|
|
5
6
|
export declare namespace SDK {
|
|
6
7
|
let DAPIClient: any;
|
|
@@ -62,6 +63,7 @@ export declare namespace SDK {
|
|
|
62
63
|
UNKNOWN: string;
|
|
63
64
|
};
|
|
64
65
|
STORAGE: {
|
|
66
|
+
version: number;
|
|
65
67
|
autosaveIntervalTime: number;
|
|
66
68
|
};
|
|
67
69
|
TXIN_OUTPOINT_TXID_BYTES: number;
|
|
@@ -185,5 +187,12 @@ export declare namespace SDK {
|
|
|
185
187
|
};
|
|
186
188
|
};
|
|
187
189
|
};
|
|
190
|
+
let PlatformProtocol: any;
|
|
191
|
+
let Essentials: {
|
|
192
|
+
Buffer: typeof Buffer;
|
|
193
|
+
};
|
|
194
|
+
let Errors: {
|
|
195
|
+
StateTransitionBroadcastError: typeof StateTransitionBroadcastError;
|
|
196
|
+
};
|
|
188
197
|
}
|
|
189
198
|
export { SDK as default };
|
package/docs/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Dash SDK
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.org/package/dash)
|
|
4
|
-
[](https://github.com/dashevo/platform/actions/workflows/release.yml)
|
|
5
|
+
[](https://github.com/dashevo/platform/releases/latest)
|
|
6
6
|
[](https://github.com/RichardLitt/standard-readme)
|
|
7
7
|
|
|
8
8
|
Dash library for JavaScript/TypeScript ecosystem (Wallet, DAPI, Primitives, BLS, ...)
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash",
|
|
3
|
-
"version": "3.23.0-dev.
|
|
3
|
+
"version": "3.23.0-dev.4",
|
|
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
|
-
"
|
|
11
|
-
"build
|
|
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
|
|
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.
|
|
38
|
-
"@dashevo/dashcore-lib": "~0.19.
|
|
39
|
-
"@dashevo/dashpay-contract": "~0.23.0-dev.
|
|
40
|
-
"@dashevo/dpns-contract": "~0.23.0-dev.
|
|
41
|
-
"@dashevo/dpp": "~0.23.0-dev.
|
|
42
|
-
"@dashevo/grpc-common": "~0.23.0-dev.
|
|
43
|
-
"@dashevo/masternode-reward-shares-contract": "~0.23.0-dev.
|
|
44
|
-
"@dashevo/wallet-lib": "~7.23.0-dev.
|
|
38
|
+
"@dashevo/dapi-client": "~0.23.0-dev.4",
|
|
39
|
+
"@dashevo/dashcore-lib": "~0.19.39",
|
|
40
|
+
"@dashevo/dashpay-contract": "~0.23.0-dev.4",
|
|
41
|
+
"@dashevo/dpns-contract": "~0.23.0-dev.4",
|
|
42
|
+
"@dashevo/dpp": "~0.23.0-dev.4",
|
|
43
|
+
"@dashevo/grpc-common": "~0.23.0-dev.4",
|
|
44
|
+
"@dashevo/masternode-reward-shares-contract": "~0.23.0-dev.4",
|
|
45
|
+
"@dashevo/wallet-lib": "~7.23.0-dev.4",
|
|
45
46
|
"bs58": "^4.0.1",
|
|
46
47
|
"node-inspect-extracted": "^1.0.8"
|
|
47
48
|
},
|
|
@@ -71,6 +72,7 @@
|
|
|
71
72
|
"karma-mocha-reporter": "^2.2.5",
|
|
72
73
|
"karma-webpack": "^5.0.0",
|
|
73
74
|
"mocha": "^9.1.2",
|
|
75
|
+
"net": "^1.0.2",
|
|
74
76
|
"nodemon": "^2.0.4",
|
|
75
77
|
"os-browserify": "^0.3.0",
|
|
76
78
|
"path-browserify": "^1.0.1",
|
|
@@ -81,6 +83,8 @@
|
|
|
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
89
|
"ts-mocha": "^8.0.0",
|
|
86
90
|
"ts-mock-imports": "^1.3.0",
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
27
|
+
if (!options.skipValidation) {
|
|
28
|
+
const result = await dpp.stateTransition.validateBasic(stateTransition);
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
if (!result.isValid()) {
|
|
23
31
|
const consensusError = result.getFirstError();
|
|
24
32
|
|
|
25
33
|
throw new StateTransitionBroadcastError(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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}
|
|
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
|
|
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}
|
|
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
|
|
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;
|
package/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.ts
CHANGED
|
@@ -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}
|
|
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
|
|
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:
|
|
23
|
-
const
|
|
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:
|
|
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
|
-
|
|
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;
|
package/src/SDK/Client/Platform/methods/identities/internal/createIdnetityTopUpTransition.ts
CHANGED
|
@@ -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}
|
|
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
|
|
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
|
|
6
|
-
|
|
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,7 +1,4 @@
|
|
|
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";
|
|
6
3
|
|
|
7
4
|
/**
|
|
@@ -12,7 +9,7 @@ import broadcastStateTransition from "../../broadcastStateTransition";
|
|
|
12
9
|
*/
|
|
13
10
|
export default async function register(
|
|
14
11
|
this: Platform,
|
|
15
|
-
fundingAmount : number =
|
|
12
|
+
fundingAmount : number = 100000
|
|
16
13
|
): Promise<any> {
|
|
17
14
|
await this.initialize();
|
|
18
15
|
|
|
@@ -24,15 +21,17 @@ export default async function register(
|
|
|
24
21
|
transaction: assetLockTransaction,
|
|
25
22
|
privateKey: assetLockPrivateKey,
|
|
26
23
|
outputIndex: assetLockOutputIndex
|
|
27
|
-
} = await createAssetLockTransaction(
|
|
24
|
+
} = await this.identities.utils.createAssetLockTransaction(fundingAmount);
|
|
28
25
|
|
|
29
26
|
// Broadcast Asset Lock transaction
|
|
30
27
|
await account.broadcastTransaction(assetLockTransaction);
|
|
31
|
-
const assetLockProof = await createAssetLockProof(this, assetLockTransaction, assetLockOutputIndex);
|
|
32
28
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const assetLockProof = await this.identities.utils
|
|
30
|
+
.createAssetLockProof(assetLockTransaction, assetLockOutputIndex);
|
|
31
|
+
|
|
32
|
+
const { identity, identityCreateTransition, identityIndex } = await this.identities.utils
|
|
33
|
+
.createIdentityCreateTransition(assetLockProof, assetLockPrivateKey);
|
|
34
|
+
|
|
36
35
|
await broadcastStateTransition(this, identityCreateTransition);
|
|
37
36
|
|
|
38
37
|
// If state transition was broadcast without any errors, import identity to the account
|
|
@@ -43,5 +42,14 @@ export default async function register(
|
|
|
43
42
|
identityIndex,
|
|
44
43
|
);
|
|
45
44
|
|
|
45
|
+
// Current identity object will not have metadata or balance information
|
|
46
|
+
const registeredIdentity = await this.identities.get(identity.getId().toString());
|
|
47
|
+
|
|
48
|
+
// We cannot just return registeredIdentity as we want to
|
|
49
|
+
// keep additional information (assetLockProof and transaction) instance
|
|
50
|
+
identity.setMetadata(registeredIdentity.getMetadata());
|
|
51
|
+
identity.setBalance(registeredIdentity.getBalance());
|
|
52
|
+
identity.setPublicKeys(registeredIdentity.getPublicKeys());
|
|
53
|
+
|
|
46
54
|
return identity;
|
|
47
55
|
}
|