dash 3.23.0-dev.2 → 3.23.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -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/createAssetLockTransaction.js +8 -4
- package/build/src/SDK/Client/Platform/createAssetLockTransaction.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 +8 -4
- 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 +5 -6
- 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 +22 -22
- 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/mocks/createAndAttachTransportMocksToClient.js +1 -1
- 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/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/SDK.d.ts +9 -0
- package/package.json +16 -12
- package/src/SDK/Client/Platform/Platform.ts +21 -0
- package/src/SDK/Client/Platform/createAssetLockTransaction.ts +5 -2
- package/src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.ts +5 -2
- package/src/SDK/Client/Platform/methods/identities/internal/createIdentityCreateTransition.ts +5 -2
- 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 +6 -8
- package/src/SDK/Client/Platform/methods/identities/topUp.ts +5 -8
- package/src/SDK/Client/Platform/methods/identities/update.ts +18 -12
- package/src/SDK/SDK.ts +34 -21
- package/src/test/mocks/createAndAttachTransportMocksToClient.ts +1 -1
- 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,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;
|
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/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.5",
|
|
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": "
|
|
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.5",
|
|
39
|
+
"@dashevo/dashcore-lib": "~0.19.39",
|
|
40
|
+
"@dashevo/dashpay-contract": "~0.23.0-dev.5",
|
|
41
|
+
"@dashevo/dpns-contract": "~0.23.0-dev.5",
|
|
42
|
+
"@dashevo/dpp": "~0.23.0-dev.5",
|
|
43
|
+
"@dashevo/grpc-common": "~0.23.0-dev.5",
|
|
44
|
+
"@dashevo/masternode-reward-shares-contract": "~0.23.0-dev.5",
|
|
45
|
+
"@dashevo/wallet-lib": "~7.23.0-dev.5",
|
|
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",
|
|
@@ -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
|
+
|
|
@@ -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;
|
|
@@ -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();
|
|
@@ -73,3 +74,5 @@ export default async function createIdentityCreateTransition(platform : Platform
|
|
|
73
74
|
|
|
74
75
|
return { identity, identityCreateTransition, identityIndex };
|
|
75
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
|
/**
|
|
@@ -24,15 +21,16 @@ 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);
|
|
36
34
|
|
|
37
35
|
await broadcastStateTransition(this, identityCreateTransition);
|
|
38
36
|
|
|
@@ -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(
|
|
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
|
|
32
|
+
const assetLockProof = await this.identities.utils
|
|
33
|
+
.createAssetLockProof(assetLockTransaction, assetLockOutputIndex);
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const identityTopUpTransition = await this.identities.utils
|
|
36
|
+
.createIdentityTopUpTransition(assetLockProof, assetLockPrivateKey, identityId);
|
|
40
37
|
|
|
41
38
|
// Broadcast ST
|
|
42
39
|
await broadcastStateTransition(this, identityTopUpTransition);
|
|
@@ -36,24 +36,30 @@ export async function update(
|
|
|
36
36
|
if (identityUpdateTransition.getPublicKeysToAdd()) {
|
|
37
37
|
const signerKey = identity.getPublicKeys()[signerKeyIndex];
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
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
41
|
|
|
42
|
-
|
|
43
|
-
throw new Error(`Private key for key ${publicKey.getId()} not found`);
|
|
44
|
-
}
|
|
42
|
+
const starterPromise = Promise.resolve(null);
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
await identityUpdateTransition.getPublicKeysToAdd().reduce(
|
|
45
|
+
(previousPromise, publicKey) => previousPromise.then(async () => {
|
|
46
|
+
const privateKey = privateKeys[publicKey.getId()];
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
if (!privateKey) {
|
|
49
|
+
throw new Error(`Private key for key ${publicKey.getId()} not found`);
|
|
50
|
+
}
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
identityUpdateTransition.setSignaturePublicKeyId(signerKey.getId());
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
identityUpdateTransition.setSignaturePublicKeyId(undefined);
|
|
54
|
-
})
|
|
54
|
+
await identityUpdateTransition.signByPrivateKey(privateKey, publicKey.getType());
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
publicKey.setSignature(identityUpdateTransition.getSignature());
|
|
57
|
+
|
|
58
|
+
identityUpdateTransition.setSignature(undefined);
|
|
59
|
+
identityUpdateTransition.setSignaturePublicKeyId(undefined);
|
|
60
|
+
}),
|
|
61
|
+
starterPromise,
|
|
62
|
+
);
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
await signStateTransition(this, identityUpdateTransition, identity, signerKeyIndex);
|
package/src/SDK/SDK.ts
CHANGED
|
@@ -3,34 +3,47 @@ import { Core as _Core } from './Core';
|
|
|
3
3
|
import { Platform as _Platform } from './Platform';
|
|
4
4
|
import { default as _DAPIClient } from '@dashevo/dapi-client';
|
|
5
5
|
|
|
6
|
+
import { StateTransitionBroadcastError } from '../errors/StateTransitionBroadcastError'
|
|
7
|
+
|
|
6
8
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
Wallet as _Wallet,
|
|
10
|
+
Account as _Account,
|
|
11
|
+
DerivableKeyChain as _KeyChain,
|
|
12
|
+
CONSTANTS as _WalletLibCONSTANTS,
|
|
13
|
+
EVENTS as _WalletLibEVENTS,
|
|
14
|
+
utils as _WalletLibUtils,
|
|
15
|
+
plugins as _WalletLibPlugins
|
|
14
16
|
} from '@dashevo/wallet-lib';
|
|
15
17
|
|
|
16
18
|
export namespace SDK {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
export let DAPIClient = _DAPIClient;
|
|
20
|
+
export let Client = _Client;
|
|
21
|
+
|
|
22
|
+
export let Core = _Core;
|
|
23
|
+
// TODO: consider marking as DEPRECATED and use PlatformProtocol below instead
|
|
24
|
+
export let Platform = _Platform;
|
|
25
|
+
|
|
26
|
+
// Wallet-lib primitives
|
|
27
|
+
export let Wallet = _Wallet;
|
|
28
|
+
export let Account = _Account;
|
|
29
|
+
export let KeyChain = _KeyChain;
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
// TODO: consider merging into Wallet above and mark as DEPRECATED
|
|
32
|
+
export let WalletLib = {
|
|
33
|
+
CONSTANTS: _WalletLibCONSTANTS,
|
|
34
|
+
EVENTS: _WalletLibEVENTS,
|
|
35
|
+
plugins: _WalletLibPlugins,
|
|
36
|
+
utils: _WalletLibUtils,
|
|
37
|
+
}
|
|
22
38
|
|
|
23
|
-
|
|
24
|
-
export let Wallet = _Wallet;
|
|
25
|
-
export let Account = _Account;
|
|
26
|
-
export let KeyChain = _KeyChain;
|
|
39
|
+
export let PlatformProtocol = Platform.DashPlatformProtocol;
|
|
27
40
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
plugins: _WalletLibPlugins,
|
|
32
|
-
utils: _WalletLibUtils,
|
|
33
|
-
}
|
|
41
|
+
export let Essentials = {
|
|
42
|
+
Buffer,
|
|
43
|
+
}
|
|
34
44
|
|
|
45
|
+
export let Errors = {
|
|
46
|
+
StateTransitionBroadcastError
|
|
47
|
+
}
|
|
35
48
|
}
|
|
36
49
|
export { SDK as default };
|
|
@@ -87,7 +87,7 @@ export async function createAndAttachTransportMocksToClient(client, sinon) {
|
|
|
87
87
|
await accountPromise;
|
|
88
88
|
|
|
89
89
|
// Putting data in transport stubs
|
|
90
|
-
transportMock.
|
|
90
|
+
transportMock.getIdentitiesByPublicKeyHashes.resolves([]);
|
|
91
91
|
makeTxStreamEmitISLocksForTransactions(transportMock, txStreamMock);
|
|
92
92
|
makeGetIdentityRespondWithIdentity(client, dapiClientMock);
|
|
93
93
|
|
package/webpack.base.config.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const webpack = require('webpack');
|
|
3
|
+
const TerserPlugin = require("terser-webpack-plugin");
|
|
3
4
|
|
|
4
5
|
const baseConfig = {
|
|
5
6
|
entry: './src/index.ts',
|
|
7
|
+
devtool: 'eval',
|
|
6
8
|
module: {
|
|
7
9
|
rules: [
|
|
8
10
|
{
|
|
@@ -12,6 +14,14 @@ const baseConfig = {
|
|
|
12
14
|
},
|
|
13
15
|
],
|
|
14
16
|
},
|
|
17
|
+
optimization: {
|
|
18
|
+
minimize: true,
|
|
19
|
+
minimizer: [new TerserPlugin({
|
|
20
|
+
terserOptions: {
|
|
21
|
+
keep_classnames: true // fixes empty string in `object.constructor.name`
|
|
22
|
+
}
|
|
23
|
+
})],
|
|
24
|
+
},
|
|
15
25
|
resolve: {
|
|
16
26
|
extensions: ['.ts', '.js', '.json'],
|
|
17
27
|
fallback: {
|
|
@@ -29,6 +39,10 @@ const baseConfig = {
|
|
|
29
39
|
zlib: require.resolve('browserify-zlib'),
|
|
30
40
|
events: require.resolve('events/'),
|
|
31
41
|
string_decoder: require.resolve('string_decoder/'),
|
|
42
|
+
tls: require.resolve('tls/'),
|
|
43
|
+
net: require.resolve('net/'),
|
|
44
|
+
// Browser build have to use native WebSocket
|
|
45
|
+
ws: require.resolve('./build-utils/ws'),
|
|
32
46
|
},
|
|
33
47
|
},
|
|
34
48
|
plugins: [
|
package/webpack.config.js
CHANGED
|
@@ -4,11 +4,15 @@ const webpackBaseConfig = require("./webpack.base.config");
|
|
|
4
4
|
const webConfig = {
|
|
5
5
|
...webpackBaseConfig,
|
|
6
6
|
entry: './build/src/index.js',
|
|
7
|
+
devtool: 'source-map',
|
|
7
8
|
mode: 'production',
|
|
9
|
+
target: 'web',
|
|
8
10
|
output: {
|
|
9
11
|
path: path.resolve(__dirname, 'dist'),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
library: {
|
|
13
|
+
name: 'Dash',
|
|
14
|
+
type: 'umd'
|
|
15
|
+
},
|
|
12
16
|
filename: 'dash.min.js',
|
|
13
17
|
// fixes ReferenceError: window is not defined
|
|
14
18
|
globalObject: "(typeof self !== 'undefined' ? self : this)"
|