@dashevo/dashpay-contract 1.0.0 → 1.0.1
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/.eslintrc +2 -1
- package/.mocharc.yml +1 -2
- package/CHANGELOG.md +18 -0
- package/Cargo.toml +13 -0
- package/README.md +6 -6
- package/lib/systemIds.js +4 -0
- package/lib/test/.eslintrc +12 -0
- package/lib/test/bootstrap.js +29 -0
- package/package.json +12 -16
- package/schema/{dashpay.schema.json → v1/dashpay.schema.json} +73 -12
- package/src/error.rs +17 -0
- package/src/lib.rs +38 -0
- package/src/v1/mod.rs +17 -0
- package/test/.eslintrc +12 -0
- package/test/unit/schema.spec.js +795 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -26
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -32
- package/.travis.yml +0 -40
- package/REAMDE.md +0 -68
- package/bin/travis-deploy.sh +0 -31
- package/bootstrap.test.js +0 -22
- package/schema/dashpay.schema.spec.js +0 -428
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Bug report
|
|
3
|
-
about: Create a report to help us improve
|
|
4
|
-
title: ''
|
|
5
|
-
labels: 'bug'
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
<!--- Provide a general summary of the issue in the Title above -->
|
|
11
|
-
|
|
12
|
-
## Expected Behavior
|
|
13
|
-
<!--- Tell us what should happen -->
|
|
14
|
-
|
|
15
|
-
## Current Behavior
|
|
16
|
-
<!--- Tell us what happens instead of the expected behavior -->
|
|
17
|
-
|
|
18
|
-
## Possible Solution
|
|
19
|
-
<!--- Not obligatory, but suggest a fix/reason for the bug -->
|
|
20
|
-
|
|
21
|
-
## Steps to Reproduce (for bugs)
|
|
22
|
-
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
|
23
|
-
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
|
24
|
-
1.
|
|
25
|
-
2.
|
|
26
|
-
3.
|
|
27
|
-
4.
|
|
28
|
-
|
|
29
|
-
## Context
|
|
30
|
-
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
|
31
|
-
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
|
32
|
-
|
|
33
|
-
## Your Environment
|
|
34
|
-
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
|
35
|
-
* Version used:
|
|
36
|
-
* Environment name and version (e.g. Chrome 39, node.js 5.4):
|
|
37
|
-
* Operating System and version (desktop, server, or mobile):
|
|
38
|
-
* Link to your project:
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Feature request
|
|
3
|
-
about: Suggest an idea for this project
|
|
4
|
-
title: ''
|
|
5
|
-
labels: 'enhancement'
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
<!--- Provide a general summary of the feature request in the Title above -->
|
|
11
|
-
|
|
12
|
-
## Expected Behavior
|
|
13
|
-
<!--- A clear and concise description of what you want to happen -->
|
|
14
|
-
|
|
15
|
-
## Current Behavior
|
|
16
|
-
<!--- Explain the difference from current behavior -->
|
|
17
|
-
|
|
18
|
-
## Possible Solution
|
|
19
|
-
<!--- Suggest ideas of how to implement the addition or change -->
|
|
20
|
-
|
|
21
|
-
## Alternatives Considered
|
|
22
|
-
<!--- A clear and concise description of any alternative solutions or features you've considered -->
|
|
23
|
-
|
|
24
|
-
## Additional Context
|
|
25
|
-
<!--- Add any other context or screenshots about the feature request here. -->
|
|
26
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<!--- Provide a general summary of your changes in the Title above -->
|
|
2
|
-
<!--- Pull request titles must use the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) format -->
|
|
3
|
-
|
|
4
|
-
## Issue being fixed or feature implemented
|
|
5
|
-
<!--- Why is this change required? What problem does it solve? -->
|
|
6
|
-
<!--- If it fixes an open issue, please link to the issue here. -->
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## What was done?
|
|
10
|
-
<!--- Describe your changes in detail -->
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## How Has This Been Tested?
|
|
14
|
-
<!--- Please describe in detail how you tested your changes. -->
|
|
15
|
-
<!--- Include details of your testing environment, and the tests you ran to -->
|
|
16
|
-
<!--- see how your change affects other areas of the code, etc. -->
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## Breaking Changes
|
|
20
|
-
<!--- Please describe any breaking changes your code introduces and verify that -->
|
|
21
|
-
<!--- the title includes "!" following the conventional commit type (e.g. "feat!: ..."-->
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
## Checklist:
|
|
25
|
-
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
|
26
|
-
- [ ] I have performed a self-review of my own code
|
|
27
|
-
- [ ] I have commented my code, particularly in hard-to-understand areas
|
|
28
|
-
- [ ] I have added or updated relevant unit/integration/functional/e2e tests
|
|
29
|
-
- [ ] I have made corresponding changes to the documentation
|
|
30
|
-
|
|
31
|
-
**For repository code-owners and collaborators only**
|
|
32
|
-
- [ ] I have assigned this pull request to a milestone
|
package/.travis.yml
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
sudo: false
|
|
2
|
-
dist: trusty
|
|
3
|
-
language: node_js
|
|
4
|
-
|
|
5
|
-
node_js:
|
|
6
|
-
- '14'
|
|
7
|
-
|
|
8
|
-
branches:
|
|
9
|
-
only:
|
|
10
|
-
- master
|
|
11
|
-
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)-dev$/
|
|
12
|
-
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
|
|
13
|
-
|
|
14
|
-
services:
|
|
15
|
-
- docker
|
|
16
|
-
|
|
17
|
-
addons:
|
|
18
|
-
apt:
|
|
19
|
-
packages:
|
|
20
|
-
- docker-ce
|
|
21
|
-
|
|
22
|
-
install:
|
|
23
|
-
- npm ci
|
|
24
|
-
|
|
25
|
-
script:
|
|
26
|
-
- npm run check-package
|
|
27
|
-
- npm run lint
|
|
28
|
-
- npm run test
|
|
29
|
-
|
|
30
|
-
before_deploy:
|
|
31
|
-
# Login to NPM registry
|
|
32
|
-
- echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
|
|
33
|
-
|
|
34
|
-
deploy:
|
|
35
|
-
provider: script
|
|
36
|
-
skip_cleanup: true
|
|
37
|
-
script: bash bin/travis-deploy.sh
|
|
38
|
-
on:
|
|
39
|
-
tags: true
|
|
40
|
-
repo: dashevo/dashpay-contract
|
package/REAMDE.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# DashPay Contract
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@dashevo/dashpay-contract)
|
|
4
|
-
[](https://travis-ci.com/dashevo/dashpay-contract)
|
|
5
|
-
[](https://github.com/dashevo/dashpay-contract/releases/latest)
|
|
6
|
-
[](LICENSE)
|
|
7
|
-
[](https://github.com/RichardLitt/standard-readme)
|
|
8
|
-
|
|
9
|
-
> Reference contract of the DashPay Application Contract
|
|
10
|
-
|
|
11
|
-
DashPay allows Dash user to create a DashPay profile on the Platform chain.
|
|
12
|
-
This profile can be used to interact with other DashPay profiles, may it be for the purpose of sending/receiving transactions without having to go around the process of querying the public address of the recipient.
|
|
13
|
-
|
|
14
|
-
## Table of Contents
|
|
15
|
-
- [Install](#install)
|
|
16
|
-
- [Usage](#usage)
|
|
17
|
-
- [API](#api)
|
|
18
|
-
- [Contributing](#contributing)
|
|
19
|
-
- [License](#license)
|
|
20
|
-
|
|
21
|
-
## Install
|
|
22
|
-
|
|
23
|
-
Ensure you have the latest [NodeJS](https://nodejs.org/en/download/) installed.
|
|
24
|
-
|
|
25
|
-
#### From repository
|
|
26
|
-
|
|
27
|
-
Clone the repo:
|
|
28
|
-
|
|
29
|
-
```shell
|
|
30
|
-
git clone https://github.com/dashevo/dashpay-contract
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Install npm packages:
|
|
34
|
-
|
|
35
|
-
```shell
|
|
36
|
-
npm install
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
#### From NPM
|
|
40
|
-
|
|
41
|
-
```sh
|
|
42
|
-
npm install @dashevo/dashpay-contract
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Usage
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
#### Publish the contract
|
|
49
|
-
|
|
50
|
-
```shell
|
|
51
|
-
npm run publish-contract
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
#### Running the tests
|
|
55
|
-
|
|
56
|
-
To run tests, simply run
|
|
57
|
-
|
|
58
|
-
```shell
|
|
59
|
-
npm test
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Contributing
|
|
63
|
-
|
|
64
|
-
Feel free to dive in! [Open an issue](https://github.com/dashevo/dashpay-contract/issues/new/choose) or submit PRs.
|
|
65
|
-
|
|
66
|
-
## Licence
|
|
67
|
-
|
|
68
|
-
[MIT](LICENCE) © Dash Core Group, Inc.
|
package/bin/travis-deploy.sh
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#! /bin/sh
|
|
2
|
-
|
|
3
|
-
set -xe
|
|
4
|
-
|
|
5
|
-
# Update this whenever the latest Node.js LTS version changes (~ every year).
|
|
6
|
-
# Do not forget to add this version to .travis.yml config also.
|
|
7
|
-
LATEST_LTS_VERSION="14"
|
|
8
|
-
|
|
9
|
-
# We want this command to succeed whether or not the Node.js version is the
|
|
10
|
-
# latest (so that the build does not show as failed), but _only_ the latest
|
|
11
|
-
# should be used to publish the module.
|
|
12
|
-
if [ "$TRAVIS_NODE_VERSION" != "$LATEST_LTS_VERSION" ]; then
|
|
13
|
-
echo "Node.js v$TRAVIS_NODE_VERSION is not latest LTS version -- will not deploy with this version."
|
|
14
|
-
exit 0
|
|
15
|
-
fi
|
|
16
|
-
|
|
17
|
-
# Ensure the tag matches the one in package.json, otherwise abort.
|
|
18
|
-
PACKAGE_TAG=v"$(jq -r .version package.json)"
|
|
19
|
-
if [ "$PACKAGE_TAG" != "$TRAVIS_TAG" ]; then
|
|
20
|
-
echo "Travis tag (\"$TRAVIS_TAG\") is not equal to package.json tag (\"$PACKAGE_TAG\"). Please push a correct tag and try again."
|
|
21
|
-
exit 1
|
|
22
|
-
fi
|
|
23
|
-
|
|
24
|
-
# Use regex pattern matching to check if "dev" exists in tag
|
|
25
|
-
NPM_TAG="latest"
|
|
26
|
-
if [[ $PACKAGE_TAG =~ dev ]]; then
|
|
27
|
-
NPM_TAG="dev"
|
|
28
|
-
fi
|
|
29
|
-
|
|
30
|
-
# Now that checks have been passed, publish the module
|
|
31
|
-
npm publish --tag $NPM_TAG
|
package/bootstrap.test.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const sinon = require('sinon');
|
|
2
|
-
const sinonChai = require('sinon-chai');
|
|
3
|
-
|
|
4
|
-
const { expect, use } = require('chai');
|
|
5
|
-
const dirtyChai = require('dirty-chai');
|
|
6
|
-
|
|
7
|
-
use(dirtyChai);
|
|
8
|
-
use(sinonChai);
|
|
9
|
-
|
|
10
|
-
beforeEach(function beforeEach() {
|
|
11
|
-
if (!this.sinon) {
|
|
12
|
-
this.sinon = sinon.createSandbox();
|
|
13
|
-
} else {
|
|
14
|
-
this.sinon.restore();
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(function afterEach() {
|
|
19
|
-
this.sinon.restore();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
global.expect = expect;
|
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
const { expect } = require('chai');
|
|
2
|
-
const DashPlatformProtocol = require('@dashevo/dpp');
|
|
3
|
-
const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
4
|
-
const schema = require('./dashpay.schema');
|
|
5
|
-
|
|
6
|
-
const whitepaperMasternodeText = 'Full nodes are servers running on a P2P network that allow peers to use them to receive updates about the events on the network. These nodes utilize significant amounts of traffic and other resources that incur a substantial cost. As a result, a steady decrease in the amount of these nodes has been observed for some time on the Bitcoin network and as a result, block propagation times have been upwards of 40 seconds. Many solutions have been proposed such as a new reward scheme by Microsoft Research and the Bitnodes incentive program';
|
|
7
|
-
const encoded32Chars = '4fafc98bbfe597f7ba2c9f767d52036d';
|
|
8
|
-
const encoded64Chars = '4fafc98bbfe597f7ba2c9f767d52036d2226175960a908e355e5c575711eb166';
|
|
9
|
-
|
|
10
|
-
const filteredObject = (inputObj) => {
|
|
11
|
-
const filteredEntries = Object
|
|
12
|
-
.entries(inputObj)
|
|
13
|
-
.filter((el) => el[0][0] !== '$');
|
|
14
|
-
|
|
15
|
-
return Object
|
|
16
|
-
.fromEntries(filteredEntries);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe('Dashpay Contract', () => {
|
|
20
|
-
let dpp;
|
|
21
|
-
let contract;
|
|
22
|
-
let identityId;
|
|
23
|
-
|
|
24
|
-
beforeEach(function beforeEach() {
|
|
25
|
-
const fetchContractStub = this.sinon.stub();
|
|
26
|
-
|
|
27
|
-
dpp = new DashPlatformProtocol({
|
|
28
|
-
stateRepository: {
|
|
29
|
-
fetchDataContract: fetchContractStub,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
identityId = generateRandomIdentifier();
|
|
34
|
-
|
|
35
|
-
contract = dpp.dataContract.create(identityId, schema);
|
|
36
|
-
|
|
37
|
-
fetchContractStub.resolves(contract);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should have a valid contract definition', async () => {
|
|
41
|
-
const validationResult = await dpp.dataContract.validate(contract);
|
|
42
|
-
expect(validationResult.isValid()).to.be.true();
|
|
43
|
-
});
|
|
44
|
-
describe('Documents', () => {
|
|
45
|
-
describe('Profile', () => {
|
|
46
|
-
let profileData;
|
|
47
|
-
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
profileData = {
|
|
50
|
-
displayName: 'Bob',
|
|
51
|
-
publicMessage: 'Hello Dashpay!',
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
describe('displayName', () => {
|
|
55
|
-
it('can be avoided', async () => {
|
|
56
|
-
delete profileData.displayName;
|
|
57
|
-
const profile = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
58
|
-
expect(filteredObject(profile.toObject())).to.deep.equal(profileData);
|
|
59
|
-
});
|
|
60
|
-
it('can be empty', async () => {
|
|
61
|
-
profileData.displayName = '';
|
|
62
|
-
const profile = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
63
|
-
expect(filteredObject(profile.toObject())).to.deep.equal(profileData);
|
|
64
|
-
});
|
|
65
|
-
it('should have less than 25 chars length', async () => {
|
|
66
|
-
profileData.displayName = 'AliceAndBobAndCarolAndDanAndEveAndFrankAndIvanAndMikeAndWalterAndWendy';
|
|
67
|
-
try {
|
|
68
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
69
|
-
throw new Error('Expected error');
|
|
70
|
-
} catch (e) {
|
|
71
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
72
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
73
|
-
const [error] = e.errors;
|
|
74
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
75
|
-
expect(error.keyword).to.equal('maxLength');
|
|
76
|
-
expect(error.dataPath).to.equal('.displayName');
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('publicMessage', () => {
|
|
81
|
-
it('can be avoided', async () => {
|
|
82
|
-
delete profileData.publicMessage;
|
|
83
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
84
|
-
});
|
|
85
|
-
it('can be empty', async () => {
|
|
86
|
-
profileData.publicMessage = '';
|
|
87
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
88
|
-
});
|
|
89
|
-
it('should have less than 256 chars length', async () => {
|
|
90
|
-
profileData.publicMessage = whitepaperMasternodeText;
|
|
91
|
-
try {
|
|
92
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
93
|
-
throw new Error('Expected error');
|
|
94
|
-
} catch (e) {
|
|
95
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
96
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
97
|
-
const [error] = e.errors;
|
|
98
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
99
|
-
expect(error.keyword).to.equal('maxLength');
|
|
100
|
-
expect(error.dataPath).to.equal('.publicMessage');
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
describe('avatarUrl', () => {
|
|
105
|
-
it('should not be empty', async () => {
|
|
106
|
-
profileData.avatarUrl = '';
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
110
|
-
throw new Error('Expected error');
|
|
111
|
-
} catch (e) {
|
|
112
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
113
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
114
|
-
const [error] = e.errors;
|
|
115
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
116
|
-
expect(error.keyword).to.equal('format');
|
|
117
|
-
expect(error.dataPath).to.equal('.avatarUrl');
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
it('should have less than 2048 chars length', async () => {
|
|
121
|
-
profileData.avatarUrl = `https://github.com/dashpay/dash/wiki/Whitepaper?text=${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}`;
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
125
|
-
throw new Error('Expected error');
|
|
126
|
-
} catch (e) {
|
|
127
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
128
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
129
|
-
const [error] = e.errors;
|
|
130
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
131
|
-
expect(error.keyword).to.equal('maxLength');
|
|
132
|
-
expect(error.dataPath).to.equal('.avatarUrl');
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
it('should be of type URL', async () => {
|
|
136
|
-
profileData.avatarUrl = 'notAUrl';
|
|
137
|
-
try {
|
|
138
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
139
|
-
throw new Error('Expected error');
|
|
140
|
-
} catch (e) {
|
|
141
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
142
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
143
|
-
const [error] = e.errors;
|
|
144
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
145
|
-
expect(error.keyword).to.equal('format');
|
|
146
|
-
expect(error.dataPath).to.equal('.avatarUrl');
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
it('should not have additional properties', async () => {
|
|
151
|
-
profileData.someOtherProperty = 42;
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
dpp.document.create(contract, identityId, 'profile', profileData);
|
|
155
|
-
throw new Error('Expected error');
|
|
156
|
-
} catch (e) {
|
|
157
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
158
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
159
|
-
const [error] = e.errors;
|
|
160
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
161
|
-
expect(error.keyword).to.equal('additionalProperties');
|
|
162
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
it('should be valid', async () => {
|
|
166
|
-
const profile = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
167
|
-
|
|
168
|
-
const result = await dpp.document.validate(profile);
|
|
169
|
-
|
|
170
|
-
expect(result.isValid()).to.be.true();
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('Contact info', () => {
|
|
175
|
-
let contactInfoData;
|
|
176
|
-
|
|
177
|
-
beforeEach(() => {
|
|
178
|
-
contactInfoData = {
|
|
179
|
-
encToUserId: Buffer.alloc(32),
|
|
180
|
-
privateData: Buffer.alloc(48),
|
|
181
|
-
rootEncryptionKeyIndex: 0,
|
|
182
|
-
derivationEncryptionKeyIndex: 0,
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
describe('encToUserId', () => {
|
|
186
|
-
it('should be defined', async () => {
|
|
187
|
-
delete contactInfoData.encToUserId;
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
191
|
-
throw new Error('Expected error');
|
|
192
|
-
} catch (e) {
|
|
193
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
194
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
195
|
-
const [error] = e.errors;
|
|
196
|
-
|
|
197
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
198
|
-
expect(error.keyword).to.equal('required');
|
|
199
|
-
expect(error.params.missingProperty).to.equal('encToUserId');
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
it('should have exactly 32 chars length', async () => {
|
|
203
|
-
contactInfoData.encToUserId = Buffer.from(`${encoded64Chars}11`, 'hex');
|
|
204
|
-
|
|
205
|
-
try {
|
|
206
|
-
dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
207
|
-
throw new Error('Expected error');
|
|
208
|
-
} catch (e) {
|
|
209
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
210
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
211
|
-
const [error] = e.errors;
|
|
212
|
-
|
|
213
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
214
|
-
expect(error.keyword).to.equal('maxItems');
|
|
215
|
-
expect(error.dataPath).to.equal('.encToUserId');
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
it('should have more or 32 chars length', async () => {
|
|
219
|
-
contactInfoData.encToUserId = Buffer.from(encoded32Chars, 'hex');
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
223
|
-
throw new Error('Expected error');
|
|
224
|
-
} catch (e) {
|
|
225
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
226
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
227
|
-
const [error] = e.errors;
|
|
228
|
-
|
|
229
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
230
|
-
expect(error.keyword).to.equal('minItems');
|
|
231
|
-
expect(error.dataPath).to.equal('.encToUserId');
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
describe('rootEncryptionKeyIndex', () => {
|
|
236
|
-
it('should be defined', async () => {
|
|
237
|
-
delete contactInfoData.rootEncryptionKeyIndex;
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
241
|
-
throw new Error('Expected error');
|
|
242
|
-
} catch (e) {
|
|
243
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
244
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
245
|
-
const [error] = e.errors;
|
|
246
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
247
|
-
expect(error.keyword).to.equal('required');
|
|
248
|
-
expect(error.params.missingProperty).to.equal('rootEncryptionKeyIndex');
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
it('should not be less than 0', async () => {
|
|
252
|
-
contactInfoData.rootEncryptionKeyIndex = -1;
|
|
253
|
-
|
|
254
|
-
try {
|
|
255
|
-
dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
256
|
-
throw new Error('Expected error');
|
|
257
|
-
} catch (e) {
|
|
258
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
259
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
260
|
-
const [error] = e.errors;
|
|
261
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
262
|
-
expect(error.keyword).to.equal('minimum');
|
|
263
|
-
expect(error.dataPath).to.equal('.rootEncryptionKeyIndex');
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
describe('privateData', () => {
|
|
268
|
-
it('should be defined', async () => {
|
|
269
|
-
delete contactInfoData.privateData;
|
|
270
|
-
|
|
271
|
-
try {
|
|
272
|
-
dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
273
|
-
throw new Error('Expected error');
|
|
274
|
-
} catch (e) {
|
|
275
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
276
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
277
|
-
const [error] = e.errors;
|
|
278
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
279
|
-
expect(error.keyword).to.equal('required');
|
|
280
|
-
expect(error.params.missingProperty).to.equal('privateData');
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
it('should not have additional properties', async () => {
|
|
285
|
-
contactInfoData.someOtherProperty = 42;
|
|
286
|
-
|
|
287
|
-
try {
|
|
288
|
-
dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
289
|
-
throw new Error('Expected error');
|
|
290
|
-
} catch (e) {
|
|
291
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
292
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
293
|
-
const [error] = e.errors;
|
|
294
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
295
|
-
expect(error.keyword).to.equal('additionalProperties');
|
|
296
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
describe('Contact Request', () => {
|
|
301
|
-
let contactRequestData;
|
|
302
|
-
|
|
303
|
-
beforeEach(() => {
|
|
304
|
-
contactRequestData = {
|
|
305
|
-
toUserId: Buffer.alloc(32),
|
|
306
|
-
encryptedPublicKey: Buffer.alloc(96),
|
|
307
|
-
senderKeyIndex: 0,
|
|
308
|
-
recipientKeyIndex: 0,
|
|
309
|
-
accountReference: 0,
|
|
310
|
-
};
|
|
311
|
-
});
|
|
312
|
-
describe('toUserId', () => {
|
|
313
|
-
it('should be defined', async () => {
|
|
314
|
-
delete contactRequestData.toUserId;
|
|
315
|
-
|
|
316
|
-
try {
|
|
317
|
-
dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
318
|
-
throw new Error('Expected error');
|
|
319
|
-
} catch (e) {
|
|
320
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
321
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
322
|
-
const [error] = e.errors;
|
|
323
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
324
|
-
expect(error.keyword).to.equal('required');
|
|
325
|
-
expect(error.params.missingProperty).to.equal('toUserId');
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
describe('encryptedPublicKey', () => {
|
|
330
|
-
it('should be defined', async () => {
|
|
331
|
-
delete contactRequestData.encryptedPublicKey;
|
|
332
|
-
|
|
333
|
-
try {
|
|
334
|
-
dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
335
|
-
throw new Error('Expected error');
|
|
336
|
-
} catch (e) {
|
|
337
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
338
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
339
|
-
const [error] = e.errors;
|
|
340
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
341
|
-
expect(error.keyword).to.equal('required');
|
|
342
|
-
expect(error.params.missingProperty).to.equal('encryptedPublicKey');
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
describe('senderKeyIndex', () => {
|
|
347
|
-
it('should be defined', async () => {
|
|
348
|
-
delete contactRequestData.senderKeyIndex;
|
|
349
|
-
|
|
350
|
-
try {
|
|
351
|
-
dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
352
|
-
throw new Error('Expected error');
|
|
353
|
-
} catch (e) {
|
|
354
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
355
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
356
|
-
const [error] = e.errors;
|
|
357
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
358
|
-
expect(error.keyword).to.equal('required');
|
|
359
|
-
expect(error.params.missingProperty).to.equal('senderKeyIndex');
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
it('should not be less than 0', async () => {
|
|
363
|
-
contactRequestData.senderKeyIndex = -1;
|
|
364
|
-
|
|
365
|
-
try {
|
|
366
|
-
dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
367
|
-
throw new Error('Expected error');
|
|
368
|
-
} catch (e) {
|
|
369
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
370
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
371
|
-
const [error] = e.errors;
|
|
372
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
373
|
-
expect(error.keyword).to.equal('minimum');
|
|
374
|
-
expect(error.dataPath).to.equal('.senderKeyIndex');
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
describe('recipientKeyIndex', () => {
|
|
379
|
-
it('should be defined', async () => {
|
|
380
|
-
delete contactRequestData.recipientKeyIndex;
|
|
381
|
-
|
|
382
|
-
try {
|
|
383
|
-
dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
384
|
-
throw new Error('Expected error');
|
|
385
|
-
} catch (e) {
|
|
386
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
387
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
388
|
-
const [error] = e.errors;
|
|
389
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
390
|
-
expect(error.keyword).to.equal('required');
|
|
391
|
-
expect(error.params.missingProperty).to.equal('recipientKeyIndex');
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
it('should not be less than 0', async () => {
|
|
395
|
-
contactRequestData.recipientKeyIndex = -1;
|
|
396
|
-
|
|
397
|
-
try {
|
|
398
|
-
dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
399
|
-
throw new Error('Expected error');
|
|
400
|
-
} catch (e) {
|
|
401
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
402
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
403
|
-
const [error] = e.errors;
|
|
404
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
405
|
-
expect(error.keyword).to.equal('minimum');
|
|
406
|
-
expect(error.dataPath).to.equal('.recipientKeyIndex');
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
it('should not have additional properties', async () => {
|
|
411
|
-
contactRequestData.someOtherProperty = 42;
|
|
412
|
-
|
|
413
|
-
try {
|
|
414
|
-
dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
415
|
-
throw new Error('Expected error');
|
|
416
|
-
} catch (e) {
|
|
417
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
418
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
419
|
-
const [error] = e.errors;
|
|
420
|
-
|
|
421
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
422
|
-
expect(error.keyword).to.equal('additionalProperties');
|
|
423
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
});
|
|
428
|
-
});
|