Skip to content

Commit b60dd4a

Browse files
authored
feat: v0.23.0-alpha updates (#10)
* feat: add identity update - disable key * chore: update dash sdk to 0.23-dev * feat: add identity update - add keys * style: npm run fmt changes * chore: update dash sdk to latest 0.23-dev * feat!: use explicit network type and set via .env file * chore: update dash sdk to latest 0.23 * chore: update to 0.23.0-alpha.4 dependency
1 parent 4873b4a commit b60dd4a

26 files changed

Lines changed: 843 additions & 451 deletions

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ MNEMONIC='jewel pattern cry forget gown better agent celery nothing glove silk i
33
# IDENTITY_ID comes from the "$id" found in the "identity-register.js" response
44
IDENTITY_ID='6cSbshXPYDA2CmBtD31X4uo7YLwtef4mVDt15zRok8Xg'
55
# CONTRACT_ID comes from the "$id" found in the "contract-register-minimal.js" response
6-
CONTRACT_ID='4BRJbxsDTFY4GJGrCqM6KUjv1wSQDBuUYiGkuzgcrD5d'
6+
CONTRACT_ID='4BRJbxsDTFY4GJGrCqM6KUjv1wSQDBuUYiGkuzgcrD5d'
7+
# NETWORK sets which network to connect to: testnet, devnet, or local
8+
NETWORK='testnet'

1-Identities-and-Names/identity-register.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const dotenv = require('dotenv');
44
dotenv.config();
55

66
const clientOpts = {
7-
network: 'testnet',
7+
network: process.env.NETWORK,
88
wallet: {
99
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
1010
unsafeOptions: {

1-Identities-and-Names/identity-retrieve-account-ids.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const dotenv = require('dotenv');
44
dotenv.config();
55

66
const client = new Dash.Client({
7-
network: 'testnet',
7+
network: process.env.NETWORK,
88
wallet: {
99
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
1010
unsafeOptions: {

1-Identities-and-Names/identity-retrieve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Dash = require('dash');
33
const dotenv = require('dotenv');
44
dotenv.config();
55

6-
const client = new Dash.Client();
6+
const client = new Dash.Client({ network: process.env.NETWORK });
77

88
const retrieveIdentity = async () => {
99
return client.platform.identities.get(process.env.IDENTITY_ID); // Your identity ID

1-Identities-and-Names/identity-topup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const dotenv = require('dotenv');
44
dotenv.config();
55

66
const clientOpts = {
7-
network: 'testnet',
7+
network: process.env.NETWORK,
88
wallet: {
99
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
1010
unsafeOptions: {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// See https://dashplatform.readme.io/docs/tutorial-update-an-identity
2+
const Dash = require('dash');
3+
const IdentityPublicKey = require('@dashevo/dpp/lib/identity/IdentityPublicKey');
4+
const dotenv = require('dotenv');
5+
dotenv.config();
6+
7+
const clientOpts = {
8+
network: process.env.NETWORK,
9+
wallet: {
10+
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
11+
unsafeOptions: {
12+
skipSynchronizationBeforeHeight: 675000, // only sync from early-2022
13+
},
14+
},
15+
};
16+
const client = new Dash.Client(clientOpts);
17+
18+
const updateIdentityAddKey = async () => {
19+
const identityId = process.env.IDENTITY_ID;
20+
const existingIdentity = await client.platform.identities.get(identityId);
21+
const newKeyId = existingIdentity.toJSON().publicKeys.length;
22+
23+
// Get an unused identity index
24+
const account = await client.platform.client.getWalletAccount();
25+
const identityIndex = await account.getUnusedIdentityIndex();
26+
27+
// Get unused private key and construct new identity public key
28+
const { privateKey: identityPrivateKey } =
29+
account.identities.getIdentityHDKeyByIndex(identityIndex, 0);
30+
31+
const identityPublicKey = identityPrivateKey.toPublicKey().toBuffer();
32+
33+
const newPublicKey = new IdentityPublicKey({
34+
id: newKeyId,
35+
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
36+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
37+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.HIGH,
38+
data: identityPublicKey,
39+
readOnly: false,
40+
});
41+
42+
const updateAdd = {
43+
add: [newPublicKey],
44+
};
45+
46+
// Submit the update signed with the new key
47+
await client.platform.identities.update(existingIdentity, updateAdd, {
48+
[newPublicKey.getId()]: identityPrivateKey,
49+
});
50+
51+
return client.platform.identities.get(identityId);
52+
};
53+
54+
updateIdentityAddKey()
55+
.then((d) => console.log('Identity updated:\n', d.toJSON()))
56+
.catch((e) => console.error('Something went wrong:\n', e))
57+
.finally(() => client.disconnect());
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// See https://dashplatform.readme.io/docs/tutorial-update-an-identity
2+
const Dash = require('dash');
3+
const dotenv = require('dotenv');
4+
dotenv.config();
5+
6+
const clientOpts = {
7+
network: process.env.NETWORK,
8+
wallet: {
9+
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
10+
unsafeOptions: {
11+
skipSynchronizationBeforeHeight: 675000, // only sync from early-2022
12+
},
13+
},
14+
};
15+
const client = new Dash.Client(clientOpts);
16+
17+
const updateIdentityDisableKey = async () => {
18+
const identityId = process.env.IDENTITY_ID;
19+
const keyId = 2; // One of the identity's public key IDs
20+
21+
// Retrieve the identity to be updated and the public key to disable
22+
const existingIdentity = await client.platform.identities.get(identityId);
23+
// console.log(existingIdentity.toJSON())
24+
const publicKeyToDisable = existingIdentity.getPublicKeyById(keyId);
25+
// console.log(publicKeyToDisable)
26+
27+
const updateDisable = {
28+
disable: [publicKeyToDisable],
29+
};
30+
31+
await client.platform.identities.update(existingIdentity, updateDisable);
32+
return client.platform.identities.get(identityId);
33+
};
34+
35+
updateIdentityDisableKey()
36+
.then((d) => console.log('Identity updated:\n', d.toJSON()))
37+
.catch((e) => console.error('Something went wrong:\n', e))
38+
.finally(() => client.disconnect());

1-Identities-and-Names/name-register-alias.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dotenv.config();
66
const aliasToRegister = ''; // Enter alias to register
77

88
const clientOpts = {
9+
network: process.env.NETWORK,
910
wallet: {
1011
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
1112
unsafeOptions: {

1-Identities-and-Names/name-register.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dotenv.config();
66
const nameToRegister = ''; // Enter name to register
77

88
const clientOpts = {
9+
network: process.env.NETWORK,
910
wallet: {
1011
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
1112
unsafeOptions: {

1-Identities-and-Names/name-resolve-by-name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// See https://dashplatform.readme.io/docs/tutorial-retrieve-a-name
22
const Dash = require('dash');
33

4-
const client = new Dash.Client();
4+
const client = new Dash.Client({ network: process.env.NETWORK });
55

66
const nameToRetrieve = ''; // Enter name to retrieve
77

0 commit comments

Comments
 (0)