dash-platform-sdk 1.3.0-dev.4 → 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 +21 -2
- package/index.js +2 -5
- package/package.json +30 -31
- package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
- package/proto/generated/google/protobuf/wrappers.js +562 -345
- package/proto/generated/platform.client.d.ts +251 -0
- package/proto/generated/platform.client.js +175 -0
- package/proto/generated/platform.d.ts +3682 -1939
- package/proto/generated/platform.js +8119 -18366
- package/src/DashPlatformSDK.d.ts +5 -4
- package/src/DashPlatformSDK.js +56 -46
- package/src/constants.js +7 -10
- package/src/contestedResources/createStateTransition.d.ts +1 -2
- package/src/contestedResources/createStateTransition.js +4 -7
- package/src/contestedResources/getContestedResourceVoteState.js +67 -118
- package/src/contestedResources/index.js +9 -55
- package/src/dataContracts/create.js +5 -8
- package/src/dataContracts/createStateTransition.js +10 -14
- package/src/dataContracts/getDataContractByIdentifier.js +40 -83
- package/src/dataContracts/index.js +17 -63
- package/src/documents/create.js +3 -6
- package/src/documents/createStateTransition.js +19 -31
- package/src/documents/index.js +25 -72
- package/src/documents/query.js +58 -90
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/grpcConnectionPool.js +63 -121
- package/src/identities/createStateTransition.js +14 -26
- package/src/identities/getIdentityBalance.js +37 -80
- package/src/identities/getIdentityByIdentifier.js +37 -80
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
- package/src/identities/getIdentityByPublicKeyHash.js +37 -80
- package/src/identities/getIdentityContractNonce.js +40 -83
- package/src/identities/getIdentityNonce.js +38 -81
- package/src/identities/getIdentityPublicKeys.js +43 -81
- package/src/identities/index.js +57 -153
- package/src/keyPair/deriveChild.d.ts +2 -2
- package/src/keyPair/deriveChild.js +2 -49
- package/src/keyPair/derivePath.d.ts +2 -2
- package/src/keyPair/derivePath.js +2 -49
- package/src/keyPair/index.d.ts +39 -114
- package/src/keyPair/index.js +62 -296
- package/src/keyPair/mnemonicToSeed.d.ts +1 -1
- package/src/keyPair/mnemonicToSeed.js +3 -46
- package/src/names/index.js +43 -111
- package/src/names/registerName.js +60 -127
- package/src/names/searchByIdentity.d.ts +1 -1
- package/src/names/searchByIdentity.js +4 -50
- package/src/names/searchByName.js +15 -63
- package/src/names/testNameContested.js +1 -4
- package/src/names/validateName.js +3 -6
- package/src/node/epochs.js +43 -85
- package/src/node/index.d.ts +3 -3
- package/src/node/index.js +18 -77
- package/src/node/status.js +37 -81
- package/src/node/totalCredits.d.ts +2 -1
- package/src/node/totalCredits.js +32 -73
- package/src/signer/AbstractSigner.js +1 -2
- package/src/signer/setSigner.js +1 -4
- package/src/stateTransitions/broadcast.js +7 -57
- package/src/stateTransitions/index.js +13 -66
- package/src/stateTransitions/waitForStateTransitionResult.js +6 -58
- package/src/tokens/createStateTransition.js +23 -35
- package/src/tokens/getIdentitiesTokenBalances.js +40 -83
- package/src/tokens/getIdentityTokensBalances.js +40 -83
- package/src/tokens/getTokenContractInfo.js +40 -83
- package/src/tokens/getTokenDirectPurchasePrices.js +37 -80
- package/src/tokens/getTokenTotalSupply.js +38 -81
- package/src/tokens/index.js +39 -124
- package/src/types.d.ts +6 -12
- package/src/types.js +6 -16
- package/src/utils/base58ToBytes.js +3 -6
- package/src/utils/bytesToHex.js +2 -5
- package/src/utils/bytesToTypedArray.d.ts +1 -0
- package/src/utils/bytesToTypedArray.js +3 -0
- package/src/utils/calculateMsgHash.d.ts +1 -1
- package/src/utils/calculateMsgHash.js +10 -13
- package/src/utils/calculateSignHash.d.ts +1 -1
- package/src/utils/calculateSignHash.js +7 -10
- package/src/utils/calculateStateIdHash.d.ts +1 -1
- package/src/utils/calculateStateIdHash.js +8 -10
- package/src/utils/convertToHomographSafeChars.js +2 -5
- package/src/utils/createVoterIdentityId.d.ts +1 -1
- package/src/utils/createVoterIdentityId.js +12 -11
- package/src/utils/getEvonodeList.d.ts +2 -2
- package/src/utils/getEvonodeList.js +10 -61
- package/src/utils/getQuorumPublicKey.js +15 -66
- package/src/utils/getRandomArrayItem.js +1 -4
- package/src/utils/getRandomBytes.js +2 -5
- package/src/utils/hexToBytes.js +2 -6
- package/src/utils/index.js +21 -28
- package/src/utils/indexBytesToString.js +2 -5
- package/src/utils/sha256.d.ts +1 -1
- package/src/utils/sha256.js +10 -8
- package/src/utils/signHash.d.ts +1 -1
- package/src/utils/signHash.js +9 -12
- package/src/utils/signRequestId.d.ts +1 -1
- package/src/utils/signRequestId.js +9 -12
- package/src/utils/sleep.js +2 -50
- package/src/utils/stringToIndexValueBytes.js +4 -7
- package/src/utils/verifyTenderdashProof.d.ts +1 -1
- package/src/utils/verifyTenderdashProof.js +13 -17
- package/src/voting/createStateTransition.d.ts +1 -2
- package/src/voting/createStateTransition.js +4 -7
- package/src/voting/createVote.js +4 -7
- package/src/voting/index.d.ts +3 -4
- package/src/voting/index.js +19 -26
- package/test/unit/ContestedResources.spec.js +92 -177
- package/test/unit/DataContract.spec.js +44 -111
- package/test/unit/Document.spec.js +93 -183
- package/test/unit/Identity.spec.js +221 -346
- package/test/unit/KeyPair.spec.js +30 -145
- package/test/unit/Names.spec.js +27 -90
- package/test/unit/Node.spec.js +55 -126
- package/test/unit/SDK.spec.js +7 -9
- package/test/unit/Tokens.spec.js +111 -278
- package/bundle.min.js.LICENSE.txt +0 -1
- package/src/keyPair/keyToPublicKey.d.ts +0 -2
- package/src/keyPair/keyToPublicKey.js +0 -47
- package/src/keyPair/keyToWalletId.d.ts +0 -2
- package/src/keyPair/keyToWalletId.js +0 -50
- package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
- package/src/keyPair/keyToXPrivateKey.js +0 -50
- package/src/keyPair/keyToXPublicKey.d.ts +0 -3
- package/src/keyPair/keyToXPublicKey.js +0 -50
- package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
- package/src/keyPair/mnemonicToIdentityKey.js +0 -57
- package/src/keyPair/mnemonicToWallet.d.ts +0 -2
- package/src/keyPair/mnemonicToWallet.js +0 -55
- package/src/keyPair/privateKeyToWif.d.ts +0 -2
- package/src/keyPair/privateKeyToWif.js +0 -50
- package/src/keyPair/publicKeyToAddress.d.ts +0 -2
- package/src/keyPair/publicKeyToAddress.js +0 -50
- package/src/keyPair/seedToWallet.d.ts +0 -2
- package/src/keyPair/seedToWallet.js +0 -50
- package/src/keyPair/walletToIdentityKey.d.ts +0 -3
- package/src/keyPair/walletToIdentityKey.js +0 -56
- package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
- package/src/keyPair/xkeyToHDXKey.js +0 -50
|
@@ -1,357 +1,232 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1
|
+
import { 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' });
|
|
9
7
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
40
|
-
var DashPlatformSDK_1 = require("../../src/DashPlatformSDK");
|
|
41
|
-
var sdk;
|
|
42
|
-
describe('Identity', function () {
|
|
43
|
-
beforeAll(function () {
|
|
44
|
-
sdk = new DashPlatformSDK_1.DashPlatformSDK();
|
|
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));
|
|
45
12
|
});
|
|
46
|
-
test('should be able to get identity by
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
case 1:
|
|
137
|
-
balance = _a.sent();
|
|
138
|
-
expect(balance).toEqual(expect.any(BigInt));
|
|
139
|
-
return [2 /*return*/];
|
|
140
|
-
}
|
|
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);
|
|
141
103
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
coreChainLockedHeight: coreChainLockedHeight,
|
|
176
|
-
type: 'chainLock'
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
identityCreateStateTransition.signByPrivateKey(privateKey1, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
180
|
-
identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
|
|
181
|
-
// Set identity public key signature for public key 1
|
|
182
|
-
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
183
|
-
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
184
|
-
assetLockProof: {
|
|
185
|
-
txid: txid,
|
|
186
|
-
outputIndex: outputIndex,
|
|
187
|
-
coreChainLockedHeight: coreChainLockedHeight,
|
|
188
|
-
type: 'chainLock'
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
identityCreateStateTransition.signByPrivateKey(privateKey2, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
192
|
-
identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
|
|
193
|
-
// Finalize
|
|
194
|
-
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
195
|
-
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
196
|
-
assetLockProof: {
|
|
197
|
-
txid: txid,
|
|
198
|
-
outputIndex: outputIndex,
|
|
199
|
-
coreChainLockedHeight: coreChainLockedHeight,
|
|
200
|
-
type: 'chainLock'
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
204
|
-
return [2 /*return*/];
|
|
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
|
+
}
|
|
205
137
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
|
|
218
|
-
securityLevel: pshenmic_dpp_1.SecurityLevel.MASTER,
|
|
219
|
-
keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
|
|
220
|
-
readOnly: false,
|
|
221
|
-
data: privateKey1.getPublicKey().bytes()
|
|
222
|
-
};
|
|
223
|
-
privateKey2 = pshenmic_dpp_1.PrivateKeyWASM.fromHex('44a8195e242364b935e9d7ff2106ed109e9baf3800907f5e58a259fdfd1ca5e5', 'testnet');
|
|
224
|
-
identityPublicKeyInCreation2 = {
|
|
225
|
-
id: 1,
|
|
226
|
-
purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
|
|
227
|
-
securityLevel: pshenmic_dpp_1.SecurityLevel.HIGH,
|
|
228
|
-
keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
|
|
229
|
-
readOnly: false,
|
|
230
|
-
data: privateKey2.getPublicKey().bytes()
|
|
231
|
-
};
|
|
232
|
-
// Set identity public key signature for public key 0
|
|
233
|
-
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
234
|
-
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
235
|
-
assetLockProof: {
|
|
236
|
-
transaction: transaction,
|
|
237
|
-
instantLock: instantLock,
|
|
238
|
-
outputIndex: outputIndex,
|
|
239
|
-
type: 'instantLock'
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
identityCreateStateTransition.signByPrivateKey(privateKey1, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
243
|
-
identityPublicKeyInCreation1.signature = identityCreateStateTransition.signature;
|
|
244
|
-
// Set identity public key signature for public key 1
|
|
245
|
-
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
246
|
-
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
247
|
-
assetLockProof: {
|
|
248
|
-
transaction: transaction,
|
|
249
|
-
instantLock: instantLock,
|
|
250
|
-
outputIndex: outputIndex,
|
|
251
|
-
type: 'instantLock'
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
identityCreateStateTransition.signByPrivateKey(privateKey2, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
255
|
-
identityPublicKeyInCreation2.signature = identityCreateStateTransition.signature;
|
|
256
|
-
// Finalize
|
|
257
|
-
identityCreateStateTransition = sdk.identities.createStateTransition('create', {
|
|
258
|
-
publicKeys: [identityPublicKeyInCreation1, identityPublicKeyInCreation2],
|
|
259
|
-
assetLockProof: {
|
|
260
|
-
transaction: transaction,
|
|
261
|
-
instantLock: instantLock,
|
|
262
|
-
outputIndex: outputIndex,
|
|
263
|
-
type: 'instantLock'
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
identityCreateStateTransition.signByPrivateKey(assetLockPrivateKey, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
267
|
-
return [2 /*return*/];
|
|
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
|
+
}
|
|
268
149
|
});
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
assetLockProof: {
|
|
281
|
-
transaction: transaction,
|
|
282
|
-
instantLock: instantLock,
|
|
283
|
-
outputIndex: outputIndex,
|
|
284
|
-
type: 'instantLock'
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
288
|
-
return [2 /*return*/];
|
|
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
|
+
}
|
|
289
161
|
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
identityTopUpTransaction.signByPrivateKey(assetLockPrivateKey, undefined, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
309
|
-
return [2 /*return*/];
|
|
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
|
+
}
|
|
310
178
|
});
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
identityNonce = (_a.sent()) + BigInt(1);
|
|
327
|
-
keyId = identity.getPublicKeys()[identity.getPublicKeys().length - 1].keyId + 1;
|
|
328
|
-
identityPrivateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('16f614c6242580628d849e3616491dda1eccce99642a85667eb9a364dc85324a', 'testnet');
|
|
329
|
-
identityPublicKeyInCreation = {
|
|
330
|
-
id: keyId,
|
|
331
|
-
purpose: pshenmic_dpp_1.Purpose.AUTHENTICATION,
|
|
332
|
-
securityLevel: pshenmic_dpp_1.SecurityLevel.HIGH,
|
|
333
|
-
keyType: pshenmic_dpp_1.KeyType.ECDSA_SECP256K1,
|
|
334
|
-
readOnly: false,
|
|
335
|
-
data: identityPrivateKey.getPublicKey().bytes()
|
|
336
|
-
};
|
|
337
|
-
identityUpdateTransition = sdk.identities.createStateTransition('update', {
|
|
338
|
-
identityId: identityId,
|
|
339
|
-
revision: revision,
|
|
340
|
-
identityNonce: identityNonce,
|
|
341
|
-
addPublicKeys: [identityPublicKeyInCreation]
|
|
342
|
-
});
|
|
343
|
-
identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
344
|
-
identityPublicKeyInCreation.signature = identityUpdateTransition.signature;
|
|
345
|
-
identityUpdateTransition = sdk.identities.createStateTransition('update', {
|
|
346
|
-
identityId: identityId,
|
|
347
|
-
revision: revision,
|
|
348
|
-
identityNonce: identityNonce,
|
|
349
|
-
addPublicKeys: [identityPublicKeyInCreation]
|
|
350
|
-
});
|
|
351
|
-
identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, pshenmic_dpp_1.KeyType.ECDSA_SECP256K1);
|
|
352
|
-
return [2 /*return*/];
|
|
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'
|
|
353
194
|
}
|
|
354
195
|
});
|
|
355
|
-
|
|
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
|
+
});
|
|
356
231
|
});
|
|
357
232
|
});
|