dash-platform-sdk 1.0.0 → 1.0.2
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/.github/workflows/build.yml +4 -0
- package/.github/workflows/publish.yml +5 -2
- package/README.md +169 -18
- package/babel.config.js +2 -1
- package/dist/main.js +1 -1
- package/jest.config.js +5 -0
- package/package.json +6 -4
- package/src/dataContracts/getByIdentifier.js +22 -0
- package/src/documents/create.js +9 -0
- package/src/documents/get.js +26 -0
- package/src/errors/identityNotFoundError.js +3 -0
- package/src/grpcConnectionPool.js +50 -0
- package/src/identities/getByIdentifier.js +22 -0
- package/src/identities/getByPublicKeyHash.js +24 -0
- package/src/identities/getIdentityContractNonce.js +26 -0
- package/src/identities/getIdentityNonce.js +25 -0
- package/src/identities/getIdentityPublicKeys.js +19 -0
- package/src/index.js +63 -0
- package/src/names/search.js +22 -0
- package/src/{dapi/getStatus.js → node/status.js} +11 -10
- package/src/stateTransitions/broadcast.js +12 -0
- package/src/stateTransitions/fromDocument.js +5 -0
- package/src/stateTransitions/waitForStateTransitionResult.js +18 -0
- package/src/utils/convertToHomographSafeChars.js +17 -0
- package/src/utils/getEvonodeList.js +33 -0
- package/src/utils/getRandomArrayItem.js +3 -0
- package/src/utils/hexToUint8Array.js +3 -0
- package/src/utils/parseIdentifier.js +7 -0
- package/test/unit/index.spec.js +83 -5
- package/webpack.config.js +7 -8
- package/dist/main.js.LICENSE.txt +0 -12
- package/index.js +0 -76
- package/src/dapi/getDocuments.js +0 -33
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name: Publish
|
|
1
|
+
name: Publish package to NPM
|
|
2
2
|
on:
|
|
3
3
|
release:
|
|
4
4
|
types: [published]
|
|
@@ -13,6 +13,9 @@ jobs:
|
|
|
13
13
|
node-version: '20.x'
|
|
14
14
|
registry-url: 'https://registry.npmjs.org'
|
|
15
15
|
- run: yarn
|
|
16
|
-
- run: yarn
|
|
16
|
+
- run: yarn build:grpc
|
|
17
|
+
- run: yarn test
|
|
18
|
+
- run: yarn build
|
|
19
|
+
- run: yarn publish
|
|
17
20
|
env:
|
|
18
21
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -1,43 +1,194 @@
|
|
|
1
|
-
# dash-platform-sdk
|
|
1
|
+
# dash-platform-sdk v1.0.2
|
|
2
|
+
[](https://github.com/pshenmic/dash-platform-sdk/blob/master/LICENSE)  
|
|
2
3
|
|
|
3
|
-
This is an experimental alternative SDK for Dash Platform chain to access basic actions.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This is an experimental alternative lightweight SDK for Dash Platform chain that let you make queries, create, and sign state
|
|
6
|
+
transitions locally and broadcast them into network
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
It uses an alternative WASM bindings layer to a Dash Platform Protocol, and other GRPC Client solution, that allowed us to minimize the final build to around 3 megabytes
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
* getDocuments (without deserialization atm)
|
|
10
|
+
SDK uses a pre-defined set of seed nodes (public RPC) at the start, and then tries to switch to the latest list of nodes fetched from the Dash network through https://rpc.digitalcash.dev if possible
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
#### This is development version, breaking changes may be each release
|
|
13
13
|
|
|
14
|
+
Currently, only minimal features are included, such as document querying and creation of the documents, and all necessary related functions to do that
|
|
15
|
+
There is no input validation and error handling implemented yet relying on a happy path, this is going to be fixed in next versions
|
|
16
|
+
|
|
17
|
+
This library is isomorphic and works in both Node.js and Web browsers without polyfilling
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Install
|
|
14
21
|
|
|
15
|
-
1) Install NPM package (by GitHub ATM)
|
|
16
22
|
```bash
|
|
17
|
-
$ npm install
|
|
23
|
+
$ npm install dash-platform-sdk
|
|
18
24
|
```
|
|
19
25
|
|
|
26
|
+
Alternatively, you could simply include the library from the CDN:
|
|
20
27
|
|
|
21
|
-
2
|
|
28
|
+
https://unpkg.com/dash-platform-sdk@1.0.2/dist/main.js
|
|
29
|
+
|
|
30
|
+
## Quickstart
|
|
31
|
+
To use the SDK, simply import the library and instantiate an instance of DashPlatformSDK:
|
|
22
32
|
```javascript
|
|
23
33
|
// ES6 / EcmaScript
|
|
24
34
|
import DashPlatformSDK from 'dash-platform-sdk'
|
|
25
35
|
|
|
26
36
|
// CommonJS
|
|
27
37
|
const { default: DashPlatformSDK } = require('dash-platform-sdk')
|
|
38
|
+
|
|
39
|
+
const sdk = new DashPlatformSDK({network: 'testnet'})
|
|
28
40
|
```
|
|
29
41
|
|
|
30
|
-
|
|
42
|
+
## API Documentation
|
|
43
|
+
|
|
44
|
+
### Data Contracts
|
|
45
|
+
|
|
46
|
+
#### Get Data Contract By Identifier
|
|
47
|
+
|
|
48
|
+
Queries a DAPI for data contract and returns a IdentityWASM instance
|
|
49
|
+
|
|
31
50
|
```javascript
|
|
32
|
-
const
|
|
51
|
+
const dataContractIdentifier = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
|
|
52
|
+
|
|
53
|
+
const dataContract = await sdk.dataContracts.getByIdentifier(dataContractIdentifier)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Documents
|
|
57
|
+
|
|
58
|
+
#### Create Document
|
|
59
|
+
Creates a DocumentWASM instance that can be used for a state transition creation
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
|
|
64
|
+
const identity = '9VSMojGcwpFHeWnAZzYxJipFt1t3mb34BWtHt8csizQS'
|
|
65
|
+
const identityContractNonce = BigInt(1)
|
|
66
|
+
const documentType = 'domain'
|
|
67
|
+
const data = {
|
|
68
|
+
"key": "value"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const document = await sdk.documents.create(dataContract, documentType, data, identityContractNonce, identity)
|
|
72
|
+
|
|
73
|
+
console.log(document)
|
|
74
|
+
```
|
|
33
75
|
|
|
34
|
-
|
|
35
|
-
const status = await sdk.utils.getStatus()
|
|
76
|
+
#### Query Document
|
|
36
77
|
|
|
37
|
-
|
|
78
|
+
Performs a query for a document and returns an instance of DocumentWASM
|
|
79
|
+
```javascript
|
|
80
|
+
const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
|
|
81
|
+
const ownerId = '7xnwhCsZQUAHA5ZTFhCxgwSdut4MoMb5GwnzepVrkiuq'
|
|
82
|
+
const documentType = 'domain'
|
|
83
|
+
const limit = 100
|
|
84
|
+
const where = [['$ownerId', '==', ownerId]]
|
|
85
|
+
const orderBy = [['$createdAt', 'desc']]
|
|
86
|
+
|
|
87
|
+
// optional and one of
|
|
88
|
+
const startAt = base58.decode(ownerId)
|
|
89
|
+
const startAfter = base58.decode(ownerId)
|
|
90
|
+
|
|
91
|
+
const [document] = await sdk.documents.query(dataContract, documentType, where, orderBy, limit, startAt, startAfter)
|
|
92
|
+
|
|
93
|
+
console.log(document)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Identities
|
|
97
|
+
#### Get identity by identifier
|
|
98
|
+
Searches an identity by identifier (base58) and returns an IdentityWASM instance
|
|
99
|
+
```javascript
|
|
100
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
101
|
+
|
|
102
|
+
const identity = await sdk.identities.getByIdentifier(identifier)
|
|
103
|
+
|
|
104
|
+
console.log(identity)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Get identity by public key hash
|
|
108
|
+
```javascript
|
|
109
|
+
const publicKeyHash = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
|
110
|
+
|
|
111
|
+
const identity = await sdk.identities.getByPublicKeyHash(publicKeyHash)
|
|
112
|
+
|
|
113
|
+
console.log(identity)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Get identity nonce
|
|
117
|
+
Returns a current BigInt identity nonce for a given Identity
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
38
121
|
|
|
39
|
-
|
|
40
|
-
const documents = await sdk.documents.get('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', 'domain')
|
|
122
|
+
const idenityNonce = await sdk.identities.getIdentityNonce(identifier)
|
|
41
123
|
|
|
42
|
-
console.log(
|
|
124
|
+
console.log(identityNonce)
|
|
43
125
|
```
|
|
126
|
+
|
|
127
|
+
#### Get identity contract nonce
|
|
128
|
+
Returns a current BigInt identity contract nonce for a given Identity and Data Contract
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
132
|
+
const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
|
|
133
|
+
|
|
134
|
+
const idenityContractNonce = await sdk.identities.idenityContractNonce(identifier, dataContract)
|
|
135
|
+
|
|
136
|
+
console.log(idenityContractNonce)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### Get identity public keys
|
|
140
|
+
Return an array of IdentityPublicKeyWASM for a given identity if found
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
144
|
+
|
|
145
|
+
const identityPublicKeys = await sdk.identities.getIdentityPublicKeys(identifier)
|
|
146
|
+
|
|
147
|
+
console.log(identityPublicKeys)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### State Transition
|
|
151
|
+
#### From Document
|
|
152
|
+
Creates a StateTransitionWASM instance that you can use to sign with your private key and later broadcast
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
const document = await sdk.documents.create(dataContract, documentType, data, identityContractNonce, identity)
|
|
156
|
+
|
|
157
|
+
const stateTransition = await sdk.stateTransitions.fromDocument(document, "CREATE", identityContractNonce)
|
|
158
|
+
|
|
159
|
+
console.log(stateTransition)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Broadcast state transition
|
|
163
|
+
|
|
164
|
+
Broadcasts your state transition in the Dash Platform network
|
|
165
|
+
```javascript
|
|
166
|
+
await sdk.stateTransitions.broadcastStateTransition(stateTransition)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Wait for state transition result
|
|
170
|
+
Waits for an execution of a state transition in the network
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
const stateTransitionHash = hexToUint8Array('4B47EEA3E7621BCEDDD7531A153E01262391A8ECB3C3F93628E5DC3B791EBDFA')
|
|
174
|
+
await sdk.stateTransitions.broadcastStateTransition(stateTransitionHash)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### DPNS Names
|
|
178
|
+
#### Search domain by name (ex. xyz.dash)
|
|
179
|
+
```javascript
|
|
180
|
+
const [document] = await sdk.names.search('xyz.dash')
|
|
181
|
+
|
|
182
|
+
console.log(document)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Node Status
|
|
186
|
+
#### Returns status of the node and protocol info
|
|
187
|
+
```javascript
|
|
188
|
+
const status = await sdk.node.status()
|
|
189
|
+
|
|
190
|
+
console.log(status.chain.latestBlockHash)
|
|
191
|
+
console.log(status.time.epoch)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
|
package/babel.config.js
CHANGED