dash-platform-sdk 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -1,43 +1,204 @@
1
- # dash-platform-sdk
1
+ # dash-platform-sdk v1.0.3
2
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/pshenmic/dash-platform-sdk/blob/master/LICENSE) ![npm version](https://img.shields.io/npm/v/react.svg?style=flat) ![a](https://github.com/pshenmic/platform-explorer/actions/workflows/build.yml/badge.svg)
2
3
 
3
- This is an experimental alternative SDK for Dash Platform chain to access basic actions.
4
4
 
5
- #### Development is ongoing, breaking changes may be each release
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
- Features implemented:
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
- * getStatus (retrieve node status)
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
- # How to use
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 pshenmic/dash-platform-sdk
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) Import:
28
+ https://unpkg.com/dash-platform-sdk@1.0.3/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
- const { default: DashPlatformSDK } = require('dash-platform-sdk')
37
+ const DashPlatformSDK = require('dash-platform-sdk')
38
+
39
+ const sdk = new DashPlatformSDK({network: 'testnet'})
28
40
  ```
29
41
 
30
- 3) Run:
42
+ Or load it straight from the web page:
43
+
44
+ ```html
45
+ <script src="https://unpkg.com/dash-platform-sdk@1.0.3/dist/main.js"></script>
46
+ <script>
47
+ const sdk = new DashPlatformSDK({network: 'testnet'})
48
+ </script>
49
+ ```
50
+
51
+
52
+ ## API Documentation
53
+
54
+ ### Data Contracts
55
+
56
+ #### Get Data Contract By Identifier
57
+
58
+ Queries a DAPI for data contract and returns a IdentityWASM instance
59
+
31
60
  ```javascript
32
- const sdk = new DashPlatformSDK() // new DashPlatformSDK({ network: 'testnet', dapiUrls: ['https://52.33.28.47:1443']})
61
+ const dataContractIdentifier = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
62
+
63
+ const dataContract = await sdk.dataContracts.getByIdentifier(dataContractIdentifier)
64
+ ```
33
65
 
34
- // Retrieve node status
35
- const status = await sdk.utils.getStatus()
66
+ ### Documents
36
67
 
37
- console.log(status)
68
+ #### Create Document
69
+ Creates a DocumentWASM instance that can be used for a state transition creation
38
70
 
39
- // Get Documents
40
- const documents = await sdk.documents.get('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', 'domain')
41
71
 
42
- console.log(documents)
72
+ ```javascript
73
+ const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
74
+ const identity = '9VSMojGcwpFHeWnAZzYxJipFt1t3mb34BWtHt8csizQS'
75
+ const identityContractNonce = BigInt(1)
76
+ const documentType = 'domain'
77
+ const data = {
78
+ "key": "value"
79
+ }
80
+
81
+ const document = await sdk.documents.create(dataContract, documentType, data, identityContractNonce, identity)
82
+
83
+ console.log(document)
43
84
  ```
85
+
86
+ #### Query Document
87
+
88
+ Performs a query for a document and returns an instance of DocumentWASM
89
+ ```javascript
90
+ const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
91
+ const ownerId = '7xnwhCsZQUAHA5ZTFhCxgwSdut4MoMb5GwnzepVrkiuq'
92
+ const documentType = 'domain'
93
+ const limit = 100
94
+ const where = [['$ownerId', '==', ownerId]]
95
+ const orderBy = [['$createdAt', 'desc']]
96
+
97
+ // optional and one of
98
+ const startAt = base58.decode(ownerId)
99
+ const startAfter = base58.decode(ownerId)
100
+
101
+ const [document] = await sdk.documents.query(dataContract, documentType, where, orderBy, limit, startAt, startAfter)
102
+
103
+ console.log(document)
104
+ ```
105
+
106
+ ### Identities
107
+ #### Get identity by identifier
108
+ Searches an identity by identifier (base58) and returns an IdentityWASM instance
109
+ ```javascript
110
+ const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
111
+
112
+ const identity = await sdk.identities.getByIdentifier(identifier)
113
+
114
+ console.log(identity)
115
+ ```
116
+
117
+ #### Get identity by public key hash
118
+ ```javascript
119
+ const publicKeyHash = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
120
+
121
+ const identity = await sdk.identities.getByPublicKeyHash(publicKeyHash)
122
+
123
+ console.log(identity)
124
+ ```
125
+
126
+ #### Get identity nonce
127
+ Returns a current BigInt identity nonce for a given Identity
128
+
129
+ ```javascript
130
+ const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
131
+
132
+ const idenityNonce = await sdk.identities.getIdentityNonce(identifier)
133
+
134
+ console.log(identityNonce)
135
+ ```
136
+
137
+ #### Get identity contract nonce
138
+ Returns a current BigInt identity contract nonce for a given Identity and Data Contract
139
+
140
+ ```javascript
141
+ const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
142
+ const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
143
+
144
+ const idenityContractNonce = await sdk.identities.idenityContractNonce(identifier, dataContract)
145
+
146
+ console.log(idenityContractNonce)
147
+ ```
148
+
149
+ #### Get identity public keys
150
+ Return an array of IdentityPublicKeyWASM for a given identity if found
151
+
152
+ ```javascript
153
+ const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
154
+
155
+ const identityPublicKeys = await sdk.identities.getIdentityPublicKeys(identifier)
156
+
157
+ console.log(identityPublicKeys)
158
+ ```
159
+
160
+ ### State Transition
161
+ #### From Document
162
+ Creates a StateTransitionWASM instance that you can use to sign with your private key and later broadcast
163
+
164
+ ```javascript
165
+ const document = await sdk.documents.create(dataContract, documentType, data, identityContractNonce, identity)
166
+
167
+ const stateTransition = await sdk.stateTransitions.fromDocument(document, "CREATE", identityContractNonce)
168
+
169
+ console.log(stateTransition)
170
+ ```
171
+
172
+ #### Broadcast state transition
173
+
174
+ Broadcasts your state transition in the Dash Platform network
175
+ ```javascript
176
+ await sdk.stateTransitions.broadcastStateTransition(stateTransition)
177
+ ```
178
+
179
+ #### Wait for state transition result
180
+ Waits for an execution of a state transition in the network
181
+
182
+ ```javascript
183
+ const stateTransitionHash = hexToUint8Array('4B47EEA3E7621BCEDDD7531A153E01262391A8ECB3C3F93628E5DC3B791EBDFA')
184
+ await sdk.stateTransitions.broadcastStateTransition(stateTransitionHash)
185
+ ```
186
+
187
+ ### DPNS Names
188
+ #### Search domain by name (ex. xyz.dash)
189
+ ```javascript
190
+ const [document] = await sdk.names.search('xyz.dash')
191
+
192
+ console.log(document)
193
+ ```
194
+
195
+ ### Node Status
196
+ #### Returns status of the node and protocol info
197
+ ```javascript
198
+ const status = await sdk.node.status()
199
+
200
+ console.log(status.chain.latestBlockHash)
201
+ console.log(status.time.epoch)
202
+ ```
203
+
204
+