dash-platform-sdk 1.0.1 → 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.
@@ -30,6 +30,10 @@ jobs:
30
30
  run: |
31
31
  yarn build:grpc
32
32
 
33
+ - name: Run tests
34
+ run: |
35
+ yarn test
36
+
33
37
  - name: Build with Webpack
34
38
  run: |
35
39
  yarn build
@@ -3,7 +3,7 @@ on:
3
3
  release:
4
4
  types: [published]
5
5
  jobs:
6
- build:
6
+ publish:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
9
  - uses: actions/checkout@v4
@@ -14,6 +14,7 @@ jobs:
14
14
  registry-url: 'https://registry.npmjs.org'
15
15
  - run: yarn
16
16
  - run: yarn build:grpc
17
+ - run: yarn test
17
18
  - run: yarn build
18
19
  - run: yarn publish
19
20
  env:
package/README.md CHANGED
@@ -1,43 +1,194 @@
1
- # dash-platform-sdk
1
+ # dash-platform-sdk v1.0.2
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.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
- 3) Run:
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 sdk = new DashPlatformSDK() // new DashPlatformSDK({ network: 'testnet', dapiUrls: ['https://52.33.28.47:1443']})
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
- // Retrieve node status
35
- const status = await sdk.utils.getStatus()
76
+ #### Query Document
36
77
 
37
- console.log(status)
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
- // Get Documents
40
- const documents = await sdk.documents.get('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', 'domain')
122
+ const idenityNonce = await sdk.identities.getIdentityNonce(identifier)
41
123
 
42
- console.log(documents)
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
@@ -1,3 +1,4 @@
1
1
  module.exports = {
2
2
  presets: [['@babel/preset-env']],
3
- };
3
+ plugins: ['@babel/plugin-transform-modules-commonjs']
4
+ }