Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions 1-Identities-and-Names/identity-update-add-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ const updateIdentityAddKey = async () => {

const identityPublicKey = identityPrivateKey.toPublicKey().toBuffer();

const newPublicKey = new IdentityPublicKeyWithWitness({
id: newKeyId,
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
data: identityPublicKey,
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
securityLevel: IdentityPublicKey.SECURITY_LEVELS.HIGH,
readOnly: false,
signature: Buffer.alloc(0),
});
const newPublicKey = new IdentityPublicKeyWithWitness(1);
newPublicKey.setId(newKeyId);
newPublicKey.setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.HIGH);
newPublicKey.setData(identityPublicKey);

const updateAdd = {
add: [newPublicKey],
Expand Down
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/name-resolve-by-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ const retrieveName = async () => {
};

retrieveName()
.then((d) => console.log('Name retrieved:\n', d.toJSON()))
.then((d) => console.log('Name retrieved:\n', d.getData()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/name-resolve-by-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ const retrieveNameByRecord = async () => {
};

retrieveNameByRecord()
.then((d) => console.log('Name retrieved:\n', d[0].toJSON()))
.then((d) => console.log('Name retrieved:\n', d[0].getData()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/name-search-by-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const retrieveNameBySearch = async () => {
retrieveNameBySearch()
.then((d) => {
for (const name of d) {
console.log('Name retrieved:\n', name.toJSON());
console.log('Name retrieved:\n', name.getData());
}
})
.catch((e) => console.error('Something went wrong:\n', e))
Expand Down
13 changes: 3 additions & 10 deletions 2-Contracts-and-Documents/contract-register-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,9 @@ const registerContract = async () => {
const contract = await platform.contracts.create(contractDocuments, identity);
console.dir({ contract: contract.toJSON() });

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(contract);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.publish(contract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
// Sign and submit the data contract
await platform.contracts.publish(contract, identity);
return contract;
};

registerContract()
Expand Down
21 changes: 6 additions & 15 deletions 2-Contracts-and-Documents/contract-update-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,17 @@ const updateContract = async () => {
const existingDataContract = await platform.contracts.get(
process.env.CONTRACT_ID,
);
const documents = existingDataContract.getDocuments();
const documentSchema = existingDataContract.getDocumentSchema('note');

documents.note.properties.author = {
documentSchema.properties.author = {
type: 'string',
};

existingDataContract.setDocuments(documents);
existingDataContract.setDocumentSchema('note', documentSchema);

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(
existingDataContract,
);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.update(existingDataContract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
// Sign and submit the data contract
await platform.contracts.update(existingDataContract, identity);
return existingDataContract;
};

updateContract()
Expand Down
3 changes: 2 additions & 1 deletion 2-Contracts-and-Documents/document-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const deleteNoteDocument = async () => {
);

// Sign and submit the document delete transition
return platform.documents.broadcast({ delete: [document] }, identity);
await platform.documents.broadcast({ delete: [document] }, identity);
return document;
};

deleteNoteDocument()
Expand Down
3 changes: 2 additions & 1 deletion 2-Contracts-and-Documents/document-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const submitNoteDocument = async () => {
delete: [], // Document(s) to delete
};
// Sign and submit the document(s)
return platform.documents.broadcast(documentBatch, identity);
await platform.documents.broadcast(documentBatch, identity);
return noteDocument;
};

submitNoteDocument()
Expand Down
3 changes: 2 additions & 1 deletion 2-Contracts-and-Documents/document-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const updateNoteDocument = async () => {
document.set('message', `Updated document @ ${new Date().toUTCString()}`);

// Sign and submit the document replace transition
return platform.documents.broadcast({ replace: [document] }, identity);
await platform.documents.broadcast({ replace: [document] }, identity);
return document;
};

updateNoteDocument()
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Code for the tutorials found on the

## Install

Note: [NodeJS](https://nodejs.org/en/download/) (v12+) must be installed to run
Note: [NodeJS](https://nodejs.org/en/download/) (v18+) must be installed to run
the tutorial code.

### Clone this repository
Expand Down Expand Up @@ -41,6 +41,11 @@ Proceed with the tutorials
align with the tutorials section found on the
[documentation site](https://dashplatform.readme.io/docs/tutorials-introduction).

After [creating an identity](./1-Identities-and-Names/identity-register.js), set
the `IDENTITY_ID` value in your `.env` file to your new identity ID. After
[registering a data contract](./2-Contracts-and-Documents/contract-register-minimal.js),
set the `CONTRACT_ID` value in your `.env` file to your new contract ID.

## Contributing

PRs accepted.
Expand Down
Loading