dash-platform-sdk 1.3.0-dev.5 → 1.3.0-dev.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle.min.js +17 -17
- package/index.js +2 -0
- package/package.json +4 -4
- package/proto/generated/google/protobuf/wrappers.js +615 -0
- package/proto/generated/platform.client.js +175 -0
- package/proto/generated/platform.js +8277 -0
- package/src/DashPlatformSDK.js +101 -0
- package/src/constants.js +10 -0
- package/src/contestedResources/createStateTransition.js +6 -0
- package/src/contestedResources/getContestedResourceVoteState.js +72 -0
- package/src/contestedResources/index.js +30 -0
- package/src/dataContracts/create.js +11 -0
- package/src/dataContracts/createStateTransition.js +19 -0
- package/src/dataContracts/getDataContractByIdentifier.js +44 -0
- package/src/dataContracts/index.js +57 -0
- package/src/documents/create.js +4 -0
- package/src/documents/createStateTransition.js +52 -0
- package/src/documents/index.js +83 -0
- package/src/documents/query.js +62 -0
- package/src/grpcConnectionPool.js +79 -0
- package/src/identities/createStateTransition.js +34 -0
- package/src/identities/getIdentityBalance.js +40 -0
- package/src/identities/getIdentityByIdentifier.js +40 -0
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +44 -0
- package/src/identities/getIdentityByPublicKeyHash.js +40 -0
- package/src/identities/getIdentityContractNonce.js +43 -0
- package/src/identities/getIdentityNonce.js +41 -0
- package/src/identities/getIdentityPublicKeys.js +47 -0
- package/src/identities/index.js +141 -0
- package/src/keyPair/deriveChild.js +3 -0
- package/src/keyPair/derivePath.js +3 -0
- package/src/keyPair/index.js +89 -0
- package/src/keyPair/mnemonicToSeed.js +4 -0
- package/src/names/index.js +102 -0
- package/src/names/registerName.js +64 -0
- package/src/names/searchByIdentity.js +5 -0
- package/src/names/searchByName.js +16 -0
- package/src/names/testNameContested.js +3 -0
- package/src/names/validateName.js +11 -0
- package/src/node/epochs.js +46 -0
- package/src/node/index.js +43 -0
- package/src/node/status.js +41 -0
- package/src/node/totalCredits.js +35 -0
- package/src/signer/AbstractSigner.js +1 -0
- package/src/signer/PrivateKeySigner.d.ts +0 -0
- package/src/signer/PrivateKeySigner.js +64 -0
- package/src/signer/setSigner.js +5 -0
- package/src/stateTransitions/broadcast.js +10 -0
- package/src/stateTransitions/index.js +34 -0
- package/src/stateTransitions/waitForStateTransitionResult.js +8 -0
- package/src/tokens/createStateTransition.js +67 -0
- package/src/tokens/getIdentitiesTokenBalances.js +43 -0
- package/src/tokens/getIdentityTokensBalances.js +43 -0
- package/src/tokens/getTokenContractInfo.js +43 -0
- package/src/tokens/getTokenDirectPurchasePrices.js +40 -0
- package/src/tokens/getTokenTotalSupply.js +41 -0
- package/src/tokens/index.js +108 -0
- package/src/types.js +15 -0
- package/src/utils/base58ToBytes.js +4 -0
- package/src/utils/bytesToHex.js +3 -0
- package/src/utils/bytesToTypedArray.js +3 -0
- package/src/utils/calculateMsgHash.js +31 -0
- package/src/utils/calculateSignHash.js +8 -0
- package/src/utils/calculateStateIdHash.js +10 -0
- package/src/utils/convertToHomographSafeChars.js +11 -0
- package/src/utils/createVoterIdentityId.js +13 -0
- package/src/utils/getEvonodeList.js +12 -0
- package/src/utils/getQuorumPublicKey.js +18 -0
- package/src/utils/getRandomArrayItem.js +3 -0
- package/src/utils/getRandomBytes.js +4 -0
- package/src/utils/hexToBytes.js +3 -0
- package/src/utils/index.js +61 -0
- package/src/utils/indexBytesToString.js +4 -0
- package/src/utils/sha256.js +15 -0
- package/src/utils/signHash.js +22 -0
- package/src/utils/signRequestId.js +19 -0
- package/src/utils/sleep.js +3 -0
- package/src/utils/stringToIndexValueBytes.js +10 -0
- package/src/utils/verifyTenderdashProof.js +26 -0
- package/src/voting/createStateTransition.js +6 -0
- package/src/voting/createVote.js +5 -0
- package/src/voting/index.js +55 -0
- package/test/unit/ContestedResources.spec.js +259 -0
- package/test/unit/DataContract.spec.js +75 -0
- package/test/unit/Document.spec.js +109 -0
- package/test/unit/Identity.spec.js +232 -0
- package/test/unit/KeyPair.spec.js +34 -0
- package/test/unit/Names.spec.js +33 -0
- package/test/unit/Node.spec.js +58 -0
- package/test/unit/SDK.spec.js +10 -0
- package/test/unit/Tokens.spec.js +121 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { IdentityPublicKeyWASM, IdentityWASM, KeyType, PrivateKeyWASM, Purpose, SecurityLevel } from 'pshenmic-dpp';
|
|
2
|
+
import { DashPlatformSDK } from '../../src/types';
|
|
3
|
+
let sdk;
|
|
4
|
+
describe('Identity', () => {
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
7
|
+
});
|
|
8
|
+
test('should be able to get identity by identifier', async () => {
|
|
9
|
+
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
10
|
+
const identity = await sdk.identities.getIdentityByIdentifier(identifier);
|
|
11
|
+
expect(identity).toEqual(expect.any(IdentityWASM));
|
|
12
|
+
});
|
|
13
|
+
test('should be able to get identity by public key hash', async () => {
|
|
14
|
+
const publicKeyHash = 'c1b95d254c405a3d9d82ef88a47f9f792ac8efd7';
|
|
15
|
+
const identity = await sdk.identities.getIdentityByPublicKeyHash(publicKeyHash);
|
|
16
|
+
expect(identity).toEqual(expect.any(IdentityWASM));
|
|
17
|
+
});
|
|
18
|
+
test('should be able to get identity by non unique public key hash', async () => {
|
|
19
|
+
const identity = await sdk.identities.getIdentityByNonUniquePublicKeyHash('8b30a2cda275d1110874c0380b8447db3a9b04ee');
|
|
20
|
+
expect(identity).toEqual(expect.any(IdentityWASM));
|
|
21
|
+
});
|
|
22
|
+
test('should be able to get identity contract nonce', async () => {
|
|
23
|
+
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
24
|
+
const dataContract = 'DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV';
|
|
25
|
+
const identityContractNonce = await sdk.identities.getIdentityContractNonce(identifier, dataContract);
|
|
26
|
+
expect(identityContractNonce).toEqual(expect.any(BigInt));
|
|
27
|
+
});
|
|
28
|
+
test('should be able to get identity nonce', async () => {
|
|
29
|
+
const identifier = '34vkjdeUTP2z798SiXqoB6EAuobh51kXYURqVa9xkujf';
|
|
30
|
+
const identityNonce = await sdk.identities.getIdentityNonce(identifier);
|
|
31
|
+
expect(identityNonce).toEqual(expect.any(BigInt));
|
|
32
|
+
});
|
|
33
|
+
test('should be able to get identity public keys', async () => {
|
|
34
|
+
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
35
|
+
const identityPublicKeys = await sdk.identities.getIdentityPublicKeys(identifier);
|
|
36
|
+
expect(identityPublicKeys.every(identityPublicKey => identityPublicKey instanceof IdentityPublicKeyWASM)).toBeTruthy();
|
|
37
|
+
});
|
|
38
|
+
test('should be able to get balance', async () => {
|
|
39
|
+
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
40
|
+
const balance = await sdk.identities.getIdentityBalance(identifier);
|
|
41
|
+
expect(balance).toEqual(expect.any(BigInt));
|
|
42
|
+
});
|
|
43
|
+
describe('createStateTransition', () => {
|
|
44
|
+
test('should be able to create IdentityCreateTransition via ChainLock', async () => {
|
|
45
|
+
const assetLockPrivateKey = PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
|
|
46
|
+
const txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
|
|
47
|
+
const outputIndex = 0;
|
|
48
|
+
const coreChainLockedHeight = 1337;
|
|
49
|
+
const privateKey1 = PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
|
|
50
|
+
const identityPublicKeyInCreation1 = {
|
|
51
|
+
id: 0,
|
|
52
|
+
purpose: Purpose.AUTHENTICATION,
|
|
53
|
+
securityLevel: SecurityLevel.MASTER,
|
|
54
|
+
keyType: KeyType.ECDSA_SECP256K1,
|
|
55
|
+
readOnly: false,
|
|
56
|
+
data: privateKey1.getPublicKey().bytes()
|
|
57
|
+
};
|
|
58
|
+
const privateKey2 = PrivateKeyWASM.fromHex('44a8195e242364b935e9d7ff2106ed109e9baf3800907f5e58a259fdfd1ca5e5', 'testnet');
|
|
59
|
+
const identityPublicKeyInCreation2 = {
|
|
60
|
+
id: 1,
|
|
61
|
+
purpose: Purpose.AUTHENTICATION,
|
|
62
|
+
securityLevel: SecurityLevel.HIGH,
|
|
63
|
+
keyType: KeyType.ECDSA_SECP256K1,
|
|
64
|
+
readOnly: false,
|
|
65
|
+
data: privateKey2.getPublicKey().bytes()
|
|
66
|
+
};
|
|
67
|
+
let identityCreateStateTransition;
|
|
68
|
+
// Set identity public key signature for public key 0
|
|
69
|
+
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
70
|
+
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
71
|
+
assetLockProof: {
|
|
72
|
+
txid,
|
|
73
|
+
outputIndex,
|
|
74
|
+
coreChainLockedHeight,
|
|
75
|
+
type: 'chainLock'
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
identityCreateStateTransition.signByPrivateKey(privateKey1, KeyType.ECDSA_SECP256K1);
|
|
79
|
+
identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
|
|
80
|
+
// Set identity public key signature for public key 1
|
|
81
|
+
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
82
|
+
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
83
|
+
assetLockProof: {
|
|
84
|
+
txid,
|
|
85
|
+
outputIndex,
|
|
86
|
+
coreChainLockedHeight,
|
|
87
|
+
type: 'chainLock'
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
identityCreateStateTransition.signByPrivateKey(privateKey2, KeyType.ECDSA_SECP256K1);
|
|
91
|
+
identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
|
|
92
|
+
// Finalize
|
|
93
|
+
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
94
|
+
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
95
|
+
assetLockProof: {
|
|
96
|
+
txid,
|
|
97
|
+
outputIndex,
|
|
98
|
+
coreChainLockedHeight,
|
|
99
|
+
type: 'chainLock'
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, KeyType.ECDSA_SECP256K1);
|
|
103
|
+
});
|
|
104
|
+
test('should be able to create IdentityCreateTransition via InstantSend', async () => {
|
|
105
|
+
const assetLockPrivateKey = PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
|
|
106
|
+
const transaction = '03000800017dada5379e34ae1b59df35ba7acb879f3afaa12fa522f4b289a34d9fa2a68825010000006b48304502210093d609f65219e0d7ee694d271c4b7460ce89d298ef3e3670d5aef957e5551ead0220085d252e16cb3aae0d4e5d371e359e844fe82db93d8e4e26b5c61dc94676b7df0121037b86a1f7a11b4cc69fc7052e5cabdc625f3db47ee283ed4b87108f2cd879521effffffff0200e1f50500000000026a004054fa02000000001976a91416bbe230f46eea86fc4bf4dd550be45dc9adfcb488ac0000000024010100e1f505000000001976a914883bccdb8bfa44e55a19a1120ff2427537f7e92488ac';
|
|
107
|
+
const instantLock = '01017dada5379e34ae1b59df35ba7acb879f3afaa12fa522f4b289a34d9fa2a688250100000060afc1323120f0a3b835dd113b3221e92dea56814369925f10dd3e8f6bcfaa6aa89ed4282521863d8eb72e7e0e7d80c86ca64cce9986ae8bb63657f43f0000009179b5d130fe69bd0f2ea7bc90e9ea904a7eeea515a2612045a70925a7c678b0b09499ea307575751e22f804c443d2e1105e1fd4e30aa894324a41cd983ffe58d5312ff8db11676bd530c6ab8af1f7d2980d356dd3c86d0386da7df70aa3a66b';
|
|
108
|
+
const outputIndex = 0;
|
|
109
|
+
const privateKey1 = PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
|
|
110
|
+
const identityPublicKeyInCreation1 = {
|
|
111
|
+
id: 0,
|
|
112
|
+
purpose: Purpose.AUTHENTICATION,
|
|
113
|
+
securityLevel: SecurityLevel.MASTER,
|
|
114
|
+
keyType: KeyType.ECDSA_SECP256K1,
|
|
115
|
+
readOnly: false,
|
|
116
|
+
data: privateKey1.getPublicKey().bytes()
|
|
117
|
+
};
|
|
118
|
+
const privateKey2 = PrivateKeyWASM.fromHex('44a8195e242364b935e9d7ff2106ed109e9baf3800907f5e58a259fdfd1ca5e5', 'testnet');
|
|
119
|
+
const identityPublicKeyInCreation2 = {
|
|
120
|
+
id: 1,
|
|
121
|
+
purpose: Purpose.AUTHENTICATION,
|
|
122
|
+
securityLevel: SecurityLevel.HIGH,
|
|
123
|
+
keyType: KeyType.ECDSA_SECP256K1,
|
|
124
|
+
readOnly: false,
|
|
125
|
+
data: privateKey2.getPublicKey().bytes()
|
|
126
|
+
};
|
|
127
|
+
let identityCreateStateTransition;
|
|
128
|
+
// Set identity public key signature for public key 0
|
|
129
|
+
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
130
|
+
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
131
|
+
assetLockProof: {
|
|
132
|
+
transaction,
|
|
133
|
+
instantLock,
|
|
134
|
+
outputIndex,
|
|
135
|
+
type: 'instantLock'
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
identityCreateStateTransition.signByPrivateKey(privateKey1, KeyType.ECDSA_SECP256K1);
|
|
139
|
+
identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
|
|
140
|
+
// Set identity public key signature for public key 1
|
|
141
|
+
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
142
|
+
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
143
|
+
assetLockProof: {
|
|
144
|
+
transaction,
|
|
145
|
+
instantLock,
|
|
146
|
+
outputIndex,
|
|
147
|
+
type: 'instantLock'
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
identityCreateStateTransition.signByPrivateKey(privateKey2, KeyType.ECDSA_SECP256K1);
|
|
151
|
+
identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
|
|
152
|
+
// Finalize
|
|
153
|
+
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
154
|
+
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
155
|
+
assetLockProof: {
|
|
156
|
+
transaction,
|
|
157
|
+
instantLock,
|
|
158
|
+
outputIndex,
|
|
159
|
+
type: 'instantLock'
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, KeyType.ECDSA_SECP256K1);
|
|
163
|
+
});
|
|
164
|
+
test('should be able to create IdentityTopUpTransition via InstantSend', async () => {
|
|
165
|
+
const transaction = '03000800011a468e6a7cf1c5111b09b7bca6743f2571a9bf13d2ff6d21d3d230fd1dea1e97000000006b483045022100fceb25c45e77e1a273660e4f4c9a09042fb858a57704806e14bf80a734af232a02201929893dd720cf5855e31dda577cda16df29520a9774b4f3e813a4cc468fe086012103e16ede6dc5c99f28e3a5733f47a7494992bc6ce4f98551c092645910b9888b8fffffffff0200e1f50500000000026a004054fa02000000001976a91416bbe230f46eea86fc4bf4dd550be45dc9adfcb488ac0000000024010100e1f505000000001976a9147f78813975a3282e09e284d97d93c083b202e34188ac';
|
|
166
|
+
const instantLock = '01011a468e6a7cf1c5111b09b7bca6743f2571a9bf13d2ff6d21d3d230fd1dea1e9700000000892304531821bcddfe960388f93e6e91bbae170987a5c6db33f0a4cf2d88ef148968a159512600791f94053e30f688aac43bf6e698fd78339a9ab5fd3b00000091ee77cadbf9683ca3d1fb1abcb2f561f0c745b26099fe5294885852a03a4f26770a3d437265f5f00ae21d0f681d0e1610a7ac47b6d463c3efdc5f7f922e310e6f3cd66c319e63e4f1c2cc70e97886e15485dba4f29b836bf55f0619837437e8';
|
|
167
|
+
const outputIndex = 0;
|
|
168
|
+
const assetLockPrivateKey = PrivateKeyWASM.fromHex('3ca33236ab14f6df6cf87fcbb0551544fee7dcf4f251557af02c175725764a5a', 'testnet');
|
|
169
|
+
const identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
170
|
+
const identityTopUpTransaction = sdk.identities.createStateTransition('topUp', {
|
|
171
|
+
identityId,
|
|
172
|
+
assetLockProof: {
|
|
173
|
+
transaction,
|
|
174
|
+
instantLock,
|
|
175
|
+
outputIndex,
|
|
176
|
+
type: 'instantLock'
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, KeyType.ECDSA_SECP256K1);
|
|
180
|
+
});
|
|
181
|
+
test('should be able to create IdentityTopUpTransition via ChainLock', async () => {
|
|
182
|
+
const txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
|
|
183
|
+
const outputIndex = 0;
|
|
184
|
+
const coreChainLockedHeight = 1337;
|
|
185
|
+
const assetLockPrivateKey = PrivateKeyWASM.fromHex('3ca33236ab14f6df6cf87fcbb0551544fee7dcf4f251557af02c175725764a5a', 'testnet');
|
|
186
|
+
const identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
187
|
+
const identityTopUpTransaction = sdk.identities.createStateTransition('topUp', {
|
|
188
|
+
identityId,
|
|
189
|
+
assetLockProof: {
|
|
190
|
+
txid,
|
|
191
|
+
outputIndex,
|
|
192
|
+
coreChainLockedHeight,
|
|
193
|
+
type: 'chainLock'
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, KeyType.ECDSA_SECP256K1);
|
|
197
|
+
});
|
|
198
|
+
test('should be able to create IdentityUpdateTransition', async () => {
|
|
199
|
+
const identityId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
200
|
+
const masterPrivateKey = PrivateKeyWASM.fromHex('16f614c6242580628d849e3616491dda1eccce99642a85667eb9a364dc85324a', 'testnet');
|
|
201
|
+
const masterKeyId = 0;
|
|
202
|
+
const identity = await sdk.identities.getIdentityByIdentifier(identityId);
|
|
203
|
+
const revision = identity.revision + BigInt(1);
|
|
204
|
+
const identityNonce = await sdk.identities.getIdentityNonce(identityId) + BigInt(1);
|
|
205
|
+
const keyId = identity.getPublicKeys()[identity.getPublicKeys().length - 1].keyId + 1;
|
|
206
|
+
const identityPrivateKey = PrivateKeyWASM.fromHex('16f614c6242580628d849e3616491dda1eccce99642a85667eb9a364dc85324a', 'testnet');
|
|
207
|
+
const identityPublicKeyInCreation = {
|
|
208
|
+
id: keyId,
|
|
209
|
+
purpose: Purpose.AUTHENTICATION,
|
|
210
|
+
securityLevel: SecurityLevel.HIGH,
|
|
211
|
+
keyType: KeyType.ECDSA_SECP256K1,
|
|
212
|
+
readOnly: false,
|
|
213
|
+
data: identityPrivateKey.getPublicKey().bytes()
|
|
214
|
+
};
|
|
215
|
+
let identityUpdateTransition = sdk.identities.createStateTransition('update', {
|
|
216
|
+
identityId,
|
|
217
|
+
revision,
|
|
218
|
+
identityNonce,
|
|
219
|
+
addPublicKeys: [identityPublicKeyInCreation]
|
|
220
|
+
});
|
|
221
|
+
identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, KeyType.ECDSA_SECP256K1);
|
|
222
|
+
identityPublicKeyInCreation.signature = identityUpdateTransition.signature;
|
|
223
|
+
identityUpdateTransition = sdk.identities.createStateTransition('update', {
|
|
224
|
+
identityId,
|
|
225
|
+
revision,
|
|
226
|
+
identityNonce,
|
|
227
|
+
addPublicKeys: [identityPublicKeyInCreation]
|
|
228
|
+
});
|
|
229
|
+
identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, KeyType.ECDSA_SECP256K1);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
2
|
+
let sdk;
|
|
3
|
+
let mnemonic;
|
|
4
|
+
describe('KeyPair', () => {
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
7
|
+
mnemonic = 'deliver frame tomato ring tool second dream mutual fade sponsor visa teach';
|
|
8
|
+
});
|
|
9
|
+
describe('mnemonic', () => {
|
|
10
|
+
test('should be able to get seed from mnemonic', async () => {
|
|
11
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
12
|
+
// TODO: Get mock data from sdk
|
|
13
|
+
expect(seed).toEqual(Uint8Array.from([170, 120, 192, 223, 47, 43, 142, 250, 243, 136, 44, 236, 84, 170, 156, 154, 126, 231, 185, 130, 242, 40, 134, 27, 36, 33, 187, 102, 29, 177, 119, 141, 61, 157, 81, 35, 85, 33, 43, 28, 108, 24, 108, 159, 119, 233, 104, 100, 2, 206, 18, 245, 142, 99, 19, 143, 141, 0, 207, 31, 143, 58, 245, 107]));
|
|
14
|
+
});
|
|
15
|
+
test('should be able to derive hd wallet from seed', async () => {
|
|
16
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
17
|
+
const hdKey = sdk.keyPair.seedToHdKey(seed);
|
|
18
|
+
expect(hdKey.privateKey).toEqual(new Uint8Array([105, 213, 35, 36, 214, 9, 104, 32, 148, 57, 157, 10, 134, 251, 79, 152, 252, 58, 194, 48, 145, 102, 7, 252, 191, 69, 164, 97, 195, 136, 182, 93]));
|
|
19
|
+
});
|
|
20
|
+
test('should be able to derive address from wallet via derive path', async () => {
|
|
21
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
22
|
+
const seedHdKey = sdk.keyPair.seedToHdKey(seed, 'testnet');
|
|
23
|
+
const derivedHdKey = await sdk.keyPair.derivePath(seedHdKey, "m/44'/1'/0'/0/0");
|
|
24
|
+
const address = sdk.keyPair.p2pkhAddress(derivedHdKey.publicKey, 'testnet');
|
|
25
|
+
expect(address).toEqual('yRGEqFgmuqJct4jzH48sFrvBCc3WuPKDTp');
|
|
26
|
+
});
|
|
27
|
+
test('should be able to derive identity hd key from wallet', async () => {
|
|
28
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
29
|
+
const seedHdKey = sdk.keyPair.seedToHdKey(seed);
|
|
30
|
+
const key = sdk.keyPair.deriveIdentityPrivateKey(seedHdKey, 0, 0, 'testnet');
|
|
31
|
+
expect(key.privateKey).toEqual(Uint8Array.from([89, 255, 64, 41, 202, 170, 83, 68, 135, 58, 161, 107, 130, 20, 3, 50, 69, 16, 108, 104, 32, 68, 13, 100, 225, 24, 79, 20, 193, 184, 238, 55]));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import broadcast from '../../src/stateTransitions/broadcast';
|
|
2
|
+
import { DocumentWASM, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
4
|
+
import sleep from '../../src/utils/sleep';
|
|
5
|
+
jest.mock('../../src/stateTransitions/broadcast');
|
|
6
|
+
jest.mock('../../src/utils/sleep');
|
|
7
|
+
let sdk;
|
|
8
|
+
describe('DPNS names', () => {
|
|
9
|
+
beforeAll(() => {
|
|
10
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
sleep.mockReturnValue(Promise.resolve());
|
|
13
|
+
sdk.stateTransitions.broadcast = jest.fn();
|
|
14
|
+
});
|
|
15
|
+
test('should be able to search names by DPNS name', async () => {
|
|
16
|
+
const documents = await sdk.names.searchByName('xyz.dash');
|
|
17
|
+
expect(documents?.length).toEqual(1);
|
|
18
|
+
expect(documents[0]).toEqual(expect.any(DocumentWASM));
|
|
19
|
+
});
|
|
20
|
+
test('should be able to search names by identity', async () => {
|
|
21
|
+
const documents = await sdk.names.searchByIdentity('36LGwPSXef8q8wpdnx4EdDeVNuqCYNAE9boDu5bxytsm');
|
|
22
|
+
expect(documents?.length).toEqual(3);
|
|
23
|
+
const [xyzDocument] = documents;
|
|
24
|
+
expect(xyzDocument.ownerId.base58()).toEqual('36LGwPSXef8q8wpdnx4EdDeVNuqCYNAE9boDu5bxytsm');
|
|
25
|
+
});
|
|
26
|
+
test('should be able to register a name', async () => {
|
|
27
|
+
const fullName = 'test-identity-050.dash';
|
|
28
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
29
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
30
|
+
await sdk.names.registerName(fullName, identityId, privateKey);
|
|
31
|
+
expect(broadcast).toHaveBeenCalledTimes(2);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
2
|
+
let sdk;
|
|
3
|
+
describe('Node', () => {
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
6
|
+
});
|
|
7
|
+
test('should be able to call getStatus', async () => {
|
|
8
|
+
const status = await sdk.node.status();
|
|
9
|
+
expect(status.version?.software?.dapi).toEqual(expect.any(String));
|
|
10
|
+
expect(status.version?.software?.drive).toEqual(expect.any(String));
|
|
11
|
+
expect(status.version?.software?.tenderdash).toEqual(expect.any(String));
|
|
12
|
+
expect(status.version?.protocol?.tenderdash?.p2P).toEqual(expect.any(Number));
|
|
13
|
+
expect(status.version?.protocol?.tenderdash?.block).toEqual(expect.any(Number));
|
|
14
|
+
expect(status.version?.protocol?.drive?.latest).toEqual(expect.any(Number));
|
|
15
|
+
expect(status.version?.protocol?.drive?.current).toEqual(expect.any(Number));
|
|
16
|
+
expect(status.node?.id).toEqual(expect.any(String));
|
|
17
|
+
expect(status.chain?.catchingUp).toEqual(expect.any(Boolean));
|
|
18
|
+
expect(status.chain?.latestBlockHash).toEqual(expect.any(String));
|
|
19
|
+
expect(status.chain?.latestAppHash).toEqual(expect.any(String));
|
|
20
|
+
expect(status.chain?.latestBlockHeight).toEqual(expect.any(String));
|
|
21
|
+
expect(status.chain?.earliestBlockHash).toEqual(expect.any(String));
|
|
22
|
+
expect(status.chain?.earliestAppHash).toEqual(expect.any(String));
|
|
23
|
+
expect(status.chain?.earliestBlockHeight).toEqual(expect.any(String));
|
|
24
|
+
expect(status.chain?.maxPeerBlockHeight).toEqual(expect.any(String));
|
|
25
|
+
expect(status.chain?.coreChainLockedHeight).toEqual(expect.any(Number));
|
|
26
|
+
expect(status.network?.chainId).toEqual(expect.any(String));
|
|
27
|
+
expect(status.network?.peersCount).toEqual(expect.any(Number));
|
|
28
|
+
expect(status.network?.listening).toEqual(expect.any(Boolean));
|
|
29
|
+
expect(status.stateSync?.totalSyncedTime).toEqual(expect.any(String));
|
|
30
|
+
expect(status.stateSync?.remainingTime).toEqual(expect.any(String));
|
|
31
|
+
expect(status.stateSync?.totalSnapshots).toEqual(expect.any(Number));
|
|
32
|
+
expect(status.stateSync?.chunkProcessAvgTime).toEqual(expect.any(String));
|
|
33
|
+
expect(status.stateSync?.snapshotHeight).toEqual(expect.any(String));
|
|
34
|
+
expect(status.stateSync?.snapshotChunksCount).toEqual(expect.any(String));
|
|
35
|
+
expect(status.stateSync?.backfilledBlocks).toEqual(expect.any(String));
|
|
36
|
+
expect(status.stateSync?.backfillBlocksTotal).toEqual(expect.any(String));
|
|
37
|
+
expect(status.time?.local).toEqual(expect.any(String));
|
|
38
|
+
expect(status.time?.block).toEqual(expect.any(String));
|
|
39
|
+
expect(status.time?.genesis).toEqual(expect.any(String));
|
|
40
|
+
expect(status.time?.epoch).toEqual(expect.any(Number));
|
|
41
|
+
});
|
|
42
|
+
test('should be able to call getEpochsInfo in desc', async () => {
|
|
43
|
+
const epochsInfo = await sdk.node.getEpochsInfo(10, false, 8607);
|
|
44
|
+
const expectedEpochsNumbers = Array.from({ length: 10 }, (_val, index) => 8598 + index);
|
|
45
|
+
expect(epochsInfo.length).toEqual(10);
|
|
46
|
+
expect(epochsInfo.map(epochInfo => epochInfo.number)).toEqual(expectedEpochsNumbers);
|
|
47
|
+
});
|
|
48
|
+
test('should be able to call getEpochsInfo in asc', async () => {
|
|
49
|
+
const epochsInfo = await sdk.node.getEpochsInfo(10, true, 8596);
|
|
50
|
+
const expectedEpochsNumbers = Array.from({ length: 10 }, (_val, index) => 8596 + index);
|
|
51
|
+
expect(epochsInfo.length).toEqual(10);
|
|
52
|
+
expect(epochsInfo.map(epochInfo => epochInfo.number)).toEqual(expectedEpochsNumbers);
|
|
53
|
+
});
|
|
54
|
+
test('should be able to call getTotalCreditsInPlatform', async () => {
|
|
55
|
+
const totalCredits = await sdk.node.totalCredits();
|
|
56
|
+
expect(Number(totalCredits)).toBeGreaterThan(0);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
2
|
+
let sdk;
|
|
3
|
+
describe('DashPlatformSDK', () => {
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
6
|
+
});
|
|
7
|
+
test('should be constructable throw `new`', () => {
|
|
8
|
+
expect(sdk).toEqual(expect.any(DashPlatformSDK));
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { StateTransitionWASM, TokenBaseTransitionWASM, TokenEmergencyActionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
3
|
+
let sdk;
|
|
4
|
+
describe('Tokens', () => {
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
7
|
+
});
|
|
8
|
+
test('should be able to get token total supply', async () => {
|
|
9
|
+
const tokenTotalSupply = await sdk.tokens.getTokenTotalSupply('9YxdbQUjJmQsmVPen95HjAU3Esj7tVkWSY2EQWT84ZQP');
|
|
10
|
+
expect(tokenTotalSupply.tokenId).toBeTruthy();
|
|
11
|
+
expect(tokenTotalSupply.totalSystemAmount).toBeTruthy();
|
|
12
|
+
expect(tokenTotalSupply.totalAggregatedAmountInUserAccounts).toBeTruthy();
|
|
13
|
+
});
|
|
14
|
+
test('should be able to get token contract info', async () => {
|
|
15
|
+
const tokenContractInfo = await sdk.tokens.getTokenContractInfo('9YxdbQUjJmQsmVPen95HjAU3Esj7tVkWSY2EQWT84ZQP');
|
|
16
|
+
expect(tokenContractInfo.dataContractId.base58()).toEqual('Y189uedQG3CJCuu83P3DqnG7ngQaRKz69x3gY8uDzQe');
|
|
17
|
+
expect(tokenContractInfo.tokenContractPosition).toEqual(0);
|
|
18
|
+
});
|
|
19
|
+
test('should be able to get identity tokens balances', async () => {
|
|
20
|
+
const tokensIdentityBalance = await sdk.tokens.getIdentityTokensBalances('8eTDkBhpQjHeqgbVeriwLeZr1tCa6yBGw76SckvD1cwc', ['9YxdbQUjJmQsmVPen95HjAU3Esj7tVkWSY2EQWT84ZQP']);
|
|
21
|
+
expect(tokensIdentityBalance.length).toEqual(1);
|
|
22
|
+
expect(tokensIdentityBalance[0].tokenId).toBeTruthy();
|
|
23
|
+
expect(tokensIdentityBalance[0].balance).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
test('should be able to get token identities token balances', async () => {
|
|
26
|
+
const tokensPrices = await sdk.tokens.getTokensDirectPurchasePrice([
|
|
27
|
+
'3oTHkj8nqn82QkZRHkmUmNBX696nzE1rg1fwPRpemEdz',
|
|
28
|
+
'6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C'
|
|
29
|
+
]);
|
|
30
|
+
expect(tokensPrices.length).toEqual(2);
|
|
31
|
+
expect(tokensPrices[0].tokenId).toBeTruthy();
|
|
32
|
+
expect(tokensPrices[0].price).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
test('should be able to get tokens direct purchase prices', async () => {
|
|
35
|
+
const tokensIdentityBalance = await sdk.tokens.getIdentitiesTokenBalances(['8eTDkBhpQjHeqgbVeriwLeZr1tCa6yBGw76SckvD1cwc'], '9YxdbQUjJmQsmVPen95HjAU3Esj7tVkWSY2EQWT84ZQP');
|
|
36
|
+
expect(tokensIdentityBalance.length).toEqual(1);
|
|
37
|
+
expect(tokensIdentityBalance[0].identityId).toBeTruthy();
|
|
38
|
+
expect(tokensIdentityBalance[0].balance).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
test('should be able to create base token transition', async () => {
|
|
41
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition('A36eJF2kyYXwxCtJGsgbR3CTAscUFaNxZN19UqUfM1kw', '34vkjdeUTP2z798SiXqoB6EAuobh51kXYURqVa9xkujf');
|
|
42
|
+
expect(tokenBaseTransition).toBeInstanceOf(TokenBaseTransitionWASM);
|
|
43
|
+
});
|
|
44
|
+
describe('create state transitions', () => {
|
|
45
|
+
test('should be able to create burn transition', async () => {
|
|
46
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
47
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
48
|
+
const amount = BigInt(10);
|
|
49
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
50
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'burn', { amount });
|
|
51
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
52
|
+
});
|
|
53
|
+
test('should be able to create mint transition', async () => {
|
|
54
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
55
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
56
|
+
const recipientId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
57
|
+
const amount = BigInt(10);
|
|
58
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
59
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'mint', { identityId: recipientId, amount });
|
|
60
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
61
|
+
});
|
|
62
|
+
test('should be able to create transfer transition', async () => {
|
|
63
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
64
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
65
|
+
const recipient = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
66
|
+
const amount = BigInt(100);
|
|
67
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
68
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'transfer', { identityId: recipient, amount });
|
|
69
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
70
|
+
});
|
|
71
|
+
test('should be able to create freeze transition', async () => {
|
|
72
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
73
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
74
|
+
const identityId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
75
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
76
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'freeze', { identityId });
|
|
77
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
78
|
+
});
|
|
79
|
+
test('should be able to create unfreeze transition', async () => {
|
|
80
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
81
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
82
|
+
const identityId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
83
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
84
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'unfreeze', { identityId });
|
|
85
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
86
|
+
});
|
|
87
|
+
test('should be able to create destroyFrozenFunds transition', async () => {
|
|
88
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
89
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
90
|
+
const identityId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
91
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
92
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'destroyFrozenFunds', { identityId });
|
|
93
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
94
|
+
});
|
|
95
|
+
test('should be able to create emergency action transition', async () => {
|
|
96
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
97
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
98
|
+
const emergencyAction = TokenEmergencyActionWASM.Pause;
|
|
99
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
100
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'emergencyAction', { emergencyAction });
|
|
101
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
102
|
+
});
|
|
103
|
+
test('should be able to create setPriceForDirectPurchase transition', async () => {
|
|
104
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
105
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
106
|
+
const price = BigInt(10);
|
|
107
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
108
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'setPriceForDirectPurchase', { price });
|
|
109
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
110
|
+
});
|
|
111
|
+
test('should be able to create directPurchase transition', async () => {
|
|
112
|
+
const tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
113
|
+
const owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
114
|
+
const amount = BigInt(10);
|
|
115
|
+
const totalAgreedPrice = BigInt(100);
|
|
116
|
+
const tokenBaseTransition = await sdk.tokens.createBaseTransition(tokenId, owner);
|
|
117
|
+
const stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'directPurchase', { amount, totalAgreedPrice });
|
|
118
|
+
expect(stateTransition).toBeInstanceOf(StateTransitionWASM);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|