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
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-platform-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@babel/core": "^7.26.10",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"isomorphic-ws": "^5.0.0",
|
|
13
13
|
"jest": "^29.7.0",
|
|
14
14
|
"nice-grpc-web": "^3.3.6",
|
|
15
|
+
"standard": "^17.1.2",
|
|
15
16
|
"stream-browserify": "^3.0.0",
|
|
16
17
|
"ts-node": "^10.9.2",
|
|
17
18
|
"ts-proto": "^2.6.1",
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
"scripts": {
|
|
25
26
|
"build": "webpack",
|
|
26
27
|
"build:grpc": "yarn proto:generate && yarn proto:transpile",
|
|
28
|
+
"lint": "standard",
|
|
27
29
|
"test": "jest",
|
|
28
30
|
"test:debug": "node --inspect-brk ./node_modules/.bin/jest",
|
|
29
31
|
"proto:generate": "grpc_tools_node_protoc --plugin=protoc-gen-ts_proto=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./proto/generated --ts_proto_opt=forceLong=string,env=browser,outputServices=nice-grpc,outputServices=generic-definitions,outputJsonMethods=false,useExactTypes=false --proto_path=./proto ./proto/platform.proto",
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
35
|
"@scure/base": "^1.2.4",
|
|
34
|
-
"cbor": "^10.0.3"
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
"cbor": "^10.0.3",
|
|
37
|
+
"pshenmic-dpp": "^1.0.3"
|
|
38
|
+
}
|
|
37
39
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PlatformVersionWASM } from 'pshenmic-dpp'
|
|
2
|
+
import { GetDataContractRequest } from '../../proto/generated/platform'
|
|
3
|
+
import parseIdentifier from '../utils/parseIdentifier'
|
|
4
|
+
|
|
5
|
+
export default async function GetByIdentifier (identifier) {
|
|
6
|
+
// eslint-disable-next-line new-cap
|
|
7
|
+
const getDataContractRequest = new GetDataContractRequest.fromPartial({
|
|
8
|
+
v0: {
|
|
9
|
+
id: parseIdentifier(identifier)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const { v0 } = await this.grpcPool.getClient().getDataContract(getDataContractRequest)
|
|
14
|
+
|
|
15
|
+
const { dataContract } = v0
|
|
16
|
+
|
|
17
|
+
if (!dataContract) {
|
|
18
|
+
throw new Error(`Data Contract with identifier ${identifier} not found`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return this.wasm.DataContractWASM.fromBytes(dataContract, true, PlatformVersionWASM.PLATFORM_V1)
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default async function createDocument (dataContract, documentType, data, identityContractNonce, identity, identityPublicKey, privateKey) {
|
|
2
|
+
return new this.wasm.DocumentWASM(
|
|
3
|
+
data,
|
|
4
|
+
documentType,
|
|
5
|
+
identityContractNonce,
|
|
6
|
+
dataContract,
|
|
7
|
+
identity
|
|
8
|
+
)
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GetDocumentsRequest } from '../../proto/generated/platform.js'
|
|
2
|
+
import { base58 } from '@scure/base'
|
|
3
|
+
import cbor from 'cbor'
|
|
4
|
+
import { DocumentWASM, PlatformVersionWASM } from 'pshenmic-dpp'
|
|
5
|
+
import getByIdentifier from '../dataContracts/getByIdentifier'
|
|
6
|
+
|
|
7
|
+
export default async function get (dataContractId, documentType, where, orderBy, limit = 100, startAt, startAfter) {
|
|
8
|
+
// eslint-disable-next-line new-cap
|
|
9
|
+
const getDocumentsRequest = new GetDocumentsRequest.fromPartial({
|
|
10
|
+
v0: {
|
|
11
|
+
dataContractId: base58.decode(dataContractId),
|
|
12
|
+
documentType,
|
|
13
|
+
where: where ? cbor.encode(where) : undefined,
|
|
14
|
+
orderBy: orderBy ? cbor.encode(orderBy) : undefined,
|
|
15
|
+
limit,
|
|
16
|
+
startAt: startAt || undefined,
|
|
17
|
+
startAfter: startAfter || undefined
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const dataContract = await getByIdentifier.bind(this)(dataContractId)
|
|
22
|
+
|
|
23
|
+
const { v0 } = await this.grpcPool.getClient().getDocuments(getDocumentsRequest)
|
|
24
|
+
|
|
25
|
+
return v0.documents.documents.map(document => DocumentWASM.fromBytes(document, dataContract, documentType, PlatformVersionWASM.PLATFORM_V1))
|
|
26
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import getRandomArrayItem from './utils/getRandomArrayItem'
|
|
2
|
+
import { createChannel, createClient } from 'nice-grpc-web'
|
|
3
|
+
import { PlatformDefinition } from '../proto/generated/platform'
|
|
4
|
+
import getEvonodeList from './utils/getEvonodeList'
|
|
5
|
+
|
|
6
|
+
const seedNodes = {
|
|
7
|
+
testnet: [
|
|
8
|
+
'https://54.201.32.131:1443',
|
|
9
|
+
'https://52.42.202.128:1443',
|
|
10
|
+
'https://52.40.219.41:1443',
|
|
11
|
+
'https://52.89.154.48:1443',
|
|
12
|
+
'https://52.34.144.50:1443'
|
|
13
|
+
],
|
|
14
|
+
mainnet: [
|
|
15
|
+
'https://149.202.78.214',
|
|
16
|
+
'https://52.10.213.198',
|
|
17
|
+
'https://194.163.166.185',
|
|
18
|
+
'https://66.70.170.22',
|
|
19
|
+
'https://31.220.85.180'
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default class GRPCConnectionPool {
|
|
24
|
+
channels
|
|
25
|
+
|
|
26
|
+
constructor (network) {
|
|
27
|
+
this.channels = seedNodes[network].map(dapiUrl => createChannel(dapiUrl))
|
|
28
|
+
|
|
29
|
+
getEvonodeList(network)
|
|
30
|
+
.then((evonodeList) => {
|
|
31
|
+
const evonodeListDapiURLs = Object
|
|
32
|
+
.entries(evonodeList)
|
|
33
|
+
.map(([, info]) => info)
|
|
34
|
+
.filter(info => info.status === 'ENABLED')
|
|
35
|
+
.map(info => {
|
|
36
|
+
const [host] = info.address.split(':')
|
|
37
|
+
|
|
38
|
+
return `https://${host}:${info.platformHTTPPort}`
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
this.channels = evonodeListDapiURLs.map(dapiUrl => createChannel(dapiUrl))
|
|
42
|
+
})
|
|
43
|
+
.catch(console.error)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getClient () {
|
|
47
|
+
const channel = getRandomArrayItem(this.channels)
|
|
48
|
+
return createClient(PlatformDefinition, channel)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GetIdentityRequest } from '../../proto/generated/platform'
|
|
2
|
+
import parseIdentifier from '../utils/parseIdentifier'
|
|
3
|
+
import { IdentityWASM } from 'pshenmic-dpp'
|
|
4
|
+
|
|
5
|
+
export default async function getByIdentifier (identifier) {
|
|
6
|
+
// eslint-disable-next-line new-cap
|
|
7
|
+
const getIdentityRequest = new GetIdentityRequest.fromPartial({
|
|
8
|
+
v0: {
|
|
9
|
+
id: parseIdentifier(identifier)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const { v0 } = await this.grpcPool.getClient().getIdentity(getIdentityRequest)
|
|
14
|
+
|
|
15
|
+
const { identity } = v0
|
|
16
|
+
|
|
17
|
+
if (!identity) {
|
|
18
|
+
throw new Error(`Identity with identifier ${identifier} not found`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return IdentityWASM.fromBytes(identity)
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetIdentityByPublicKeyHashRequest
|
|
3
|
+
} from '../../proto/generated/platform'
|
|
4
|
+
import { IdentityWASM } from 'pshenmic-dpp'
|
|
5
|
+
import hexToUint8Array from '../utils/hexToUint8Array'
|
|
6
|
+
|
|
7
|
+
export default async function getByPublicKeyHash (hex) {
|
|
8
|
+
// eslint-disable-next-line new-cap
|
|
9
|
+
const getIdentityByPublicKeyHashRequest = new GetIdentityByPublicKeyHashRequest.fromPartial({
|
|
10
|
+
v0: {
|
|
11
|
+
publicKeyHash: hexToUint8Array(hex)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const { v0 } = await this.grpcPool.getClient().getIdentityByPublicKeyHash(getIdentityByPublicKeyHashRequest)
|
|
16
|
+
|
|
17
|
+
const { identity } = v0
|
|
18
|
+
|
|
19
|
+
if (!identity) {
|
|
20
|
+
throw new Error(`Identity with public key hash ${hex} not found`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return IdentityWASM.fromBytes(identity)
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetIdentityContractNonceRequest
|
|
3
|
+
} from '../../proto/generated/platform'
|
|
4
|
+
import parseIdentifier from '../utils/parseIdentifier'
|
|
5
|
+
|
|
6
|
+
const IDENTITY_CONTRACT_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF)
|
|
7
|
+
|
|
8
|
+
export default async function getIdentityContractNonce (identity, dataContract) {
|
|
9
|
+
// eslint-disable-next-line new-cap
|
|
10
|
+
const getIdentityContractNonceRequest = new GetIdentityContractNonceRequest.fromPartial({
|
|
11
|
+
v0: {
|
|
12
|
+
identityId: parseIdentifier(identity),
|
|
13
|
+
contractId: parseIdentifier(dataContract)
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const { v0 } = await this.grpcPool.getClient().getIdentityContractNonce(getIdentityContractNonceRequest)
|
|
18
|
+
|
|
19
|
+
const { identityContractNonce } = v0
|
|
20
|
+
|
|
21
|
+
if (!identityContractNonce) {
|
|
22
|
+
throw new Error(`Could not get identityContractNonce for Identity with identifier ${identity}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return BigInt(identityContractNonce) & IDENTITY_CONTRACT_NONCE_VALUE_FILTER
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetIdentityNonceRequest
|
|
3
|
+
} from '../../proto/generated/platform'
|
|
4
|
+
import parseIdentifier from '../utils/parseIdentifier'
|
|
5
|
+
|
|
6
|
+
const IDENTITY_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF)
|
|
7
|
+
|
|
8
|
+
export default async function getIdentityNonce (identifier) {
|
|
9
|
+
// eslint-disable-next-line new-cap
|
|
10
|
+
const getIdentityNonceRequest = new GetIdentityNonceRequest.fromPartial({
|
|
11
|
+
v0: {
|
|
12
|
+
identityId: parseIdentifier(identifier)
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const { v0 } = await this.grpcPool.getClient().getIdentityNonce(getIdentityNonceRequest)
|
|
17
|
+
|
|
18
|
+
const { identityNonce } = v0
|
|
19
|
+
|
|
20
|
+
if (!identityNonce) {
|
|
21
|
+
throw new Error(`Could not get identityNonce for Identity with identifier ${identifier}`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return BigInt(identityNonce) & IDENTITY_NONCE_VALUE_FILTER
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GetIdentityKeysRequest, KeyRequestType } from '../../proto/generated/platform'
|
|
2
|
+
import parseIdentifier from '../utils/parseIdentifier'
|
|
3
|
+
|
|
4
|
+
export default async function getIdentityPublicKeys (identifier) {
|
|
5
|
+
// eslint-disable-next-line new-cap
|
|
6
|
+
const getIdentityKeysRequest = new GetIdentityKeysRequest.fromPartial({
|
|
7
|
+
v0: {
|
|
8
|
+
identityId: parseIdentifier(identifier),
|
|
9
|
+
requestType: KeyRequestType.fromPartial({ allKeys: {} })
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const { v0 } = await this.grpcPool.getClient().getIdentityKeys(getIdentityKeysRequest)
|
|
14
|
+
|
|
15
|
+
const { keys } = v0
|
|
16
|
+
const { keysBytes } = keys
|
|
17
|
+
|
|
18
|
+
return keysBytes.map((bytes) => this.wasm.IdentityPublicKeyWASM.fromBytes(bytes))
|
|
19
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import status from './node/status'
|
|
2
|
+
import getDocuments from './documents/get'
|
|
3
|
+
import createDocument from './documents/create'
|
|
4
|
+
import getDataContractByIdentifier from './dataContracts/getByIdentifier'
|
|
5
|
+
import getIdentityByIdentifier from './identities/getByIdentifier'
|
|
6
|
+
import getByPublicKeyHash from './identities/getByPublicKeyHash'
|
|
7
|
+
import * as wasm from 'pshenmic-dpp'
|
|
8
|
+
import wasmBytes from 'pshenmic-dpp/dist/wasm/pshenmic_dpp_bg'
|
|
9
|
+
import getIdentityContractNonce from './identities/getIdentityContractNonce'
|
|
10
|
+
import getIdentityNonce from './identities/getIdentityNonce'
|
|
11
|
+
import getIdentityPublicKeys from './identities/getIdentityPublicKeys'
|
|
12
|
+
import search from './names/search'
|
|
13
|
+
import GRPCConnectionPool from './grpcConnectionPool'
|
|
14
|
+
import fromDocument from './stateTransitions/fromDocument'
|
|
15
|
+
import broadcastStateTransition from './stateTransitions/broadcast'
|
|
16
|
+
import waitForStateTransitionResult from './stateTransitions/waitForStateTransitionResult'
|
|
17
|
+
|
|
18
|
+
const DEFAULT_OPTIONS = {
|
|
19
|
+
network: 'testnet'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class DashPlatformSDK {
|
|
23
|
+
constructor (options = DEFAULT_OPTIONS) {
|
|
24
|
+
wasm.initSync({ module: Buffer.from(wasmBytes, 'base64') })
|
|
25
|
+
|
|
26
|
+
this.network = options.network
|
|
27
|
+
|
|
28
|
+
this.grpcPool = new GRPCConnectionPool(this.network)
|
|
29
|
+
|
|
30
|
+
this.wasm = wasm
|
|
31
|
+
|
|
32
|
+
this.dataContracts = {
|
|
33
|
+
getByIdentifier: getDataContractByIdentifier.bind(this)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.documents = {
|
|
37
|
+
query: getDocuments.bind(this),
|
|
38
|
+
create: createDocument.bind(this)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.names = {
|
|
42
|
+
search: search.bind(this)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.stateTransitions = {
|
|
46
|
+
fromDocument: fromDocument.bind(this),
|
|
47
|
+
broadcast: broadcastStateTransition.bind(this),
|
|
48
|
+
waitForStateTransitionResult: waitForStateTransitionResult.bind(this),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.identities = {
|
|
52
|
+
getByIdentifier: getIdentityByIdentifier.bind(this),
|
|
53
|
+
getByPublicKeyHash: getByPublicKeyHash.bind(this),
|
|
54
|
+
getIdentityContractNonce: getIdentityContractNonce.bind(this),
|
|
55
|
+
getIdentityNonce: getIdentityNonce.bind(this),
|
|
56
|
+
getIdentityPublicKeys: getIdentityPublicKeys.bind(this)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.node = {
|
|
60
|
+
status: status.bind(this)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import convertToHomographSafeChars from '../utils/convertToHomographSafeChars'
|
|
2
|
+
import query from '../documents/get'
|
|
3
|
+
|
|
4
|
+
const DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
|
|
5
|
+
|
|
6
|
+
export default async function search (name) {
|
|
7
|
+
const [label, parentDomainName] = name.split('.')
|
|
8
|
+
|
|
9
|
+
const normalizedParentDomainName = convertToHomographSafeChars(parentDomainName)
|
|
10
|
+
const normalizedLabelPrefix = convertToHomographSafeChars(label)
|
|
11
|
+
|
|
12
|
+
const where = [
|
|
13
|
+
['normalizedParentDomainName', '==', normalizedParentDomainName],
|
|
14
|
+
['normalizedLabel', 'startsWith', normalizedLabelPrefix]
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const orderBy = [
|
|
18
|
+
['normalizedLabel', 'asc']
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
return query.bind(this)(DPNS_DATA_CONTRACT_ID, 'domain', where, orderBy)
|
|
22
|
+
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { GetStatusRequest } from '../../proto/generated/platform.js'
|
|
2
2
|
|
|
3
|
-
export default async function
|
|
4
|
-
|
|
3
|
+
export default async function status () {
|
|
4
|
+
// eslint-disable-next-line new-cap
|
|
5
|
+
const getStatusRequest = new GetStatusRequest.fromPartial({ v0: {} })
|
|
5
6
|
|
|
6
|
-
const response
|
|
7
|
+
const response = await this.grpcPool.getClient().getStatus(getStatusRequest)
|
|
7
8
|
|
|
8
|
-
const {v0} = response
|
|
9
|
+
const { v0 } = response
|
|
9
10
|
|
|
10
11
|
// map buffers to hex string
|
|
11
|
-
v0.node.id = v0.node.id.reduce((code, acc) => acc + code.toString(16),
|
|
12
|
-
v0.node.proTxHash = v0.node.proTxHash.reduce((code, acc) => acc + code.toString(16),
|
|
13
|
-
v0.chain.latestBlockHash = v0.chain.latestBlockHash.reduce((code, acc) => acc + code.toString(16),
|
|
14
|
-
v0.chain.latestAppHash = v0.chain.latestAppHash.reduce((code, acc) => acc + code.toString(16),
|
|
15
|
-
v0.chain.earliestAppHash = v0.chain.earliestAppHash.reduce((code, acc) => acc + code.toString(16),
|
|
16
|
-
v0.chain.earliestBlockHash = v0.chain.earliestBlockHash.reduce((code, acc) => acc + code.toString(16),
|
|
12
|
+
v0.node.id = v0.node.id.reduce((code, acc) => acc + code.toString(16), '')
|
|
13
|
+
v0.node.proTxHash = v0.node.proTxHash.reduce((code, acc) => acc + code.toString(16), '')
|
|
14
|
+
v0.chain.latestBlockHash = v0.chain.latestBlockHash.reduce((code, acc) => acc + code.toString(16), '')
|
|
15
|
+
v0.chain.latestAppHash = v0.chain.latestAppHash.reduce((code, acc) => acc + code.toString(16), '')
|
|
16
|
+
v0.chain.earliestAppHash = v0.chain.earliestAppHash.reduce((code, acc) => acc + code.toString(16), '')
|
|
17
|
+
v0.chain.earliestBlockHash = v0.chain.earliestBlockHash.reduce((code, acc) => acc + code.toString(16), '')
|
|
17
18
|
|
|
18
19
|
return v0
|
|
19
20
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BroadcastStateTransitionRequest } from '../../proto/generated/platform'
|
|
2
|
+
|
|
3
|
+
export default async function broadcast (stateTransition) {
|
|
4
|
+
// eslint-disable-next-line new-cap
|
|
5
|
+
const broadcastStateTransitionRequest = new BroadcastStateTransitionRequest.fromPartial({
|
|
6
|
+
v0: {
|
|
7
|
+
stateTransition: stateTransition.toBuffer()
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
await this.grpcPool.getClient().broadcastStateTransition(broadcastStateTransitionRequest)
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WaitForStateTransitionResultRequest } from '../../proto/generated/platform'
|
|
2
|
+
|
|
3
|
+
export default async function waitForStateTransitionResult (stateTransitionHash) {
|
|
4
|
+
// eslint-disable-next-line new-cap
|
|
5
|
+
const waitForStateTransitionResultRequest = new WaitForStateTransitionResultRequest.fromPartial({
|
|
6
|
+
v0: {
|
|
7
|
+
stateTransitionHash
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const { v0 } = await this.grpcPool.getClient().waitForStateTransitionResult(waitForStateTransitionResultRequest)
|
|
12
|
+
|
|
13
|
+
const { error } = v0
|
|
14
|
+
|
|
15
|
+
if (error) {
|
|
16
|
+
throw new Error(error)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} input
|
|
3
|
+
* @return {string}
|
|
4
|
+
*/
|
|
5
|
+
export default function convertToHomographSafeChars (input) {
|
|
6
|
+
return input.toLowerCase().replace(/[oli]/g, (match) => {
|
|
7
|
+
if (match === 'o') {
|
|
8
|
+
return '0'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (match === 'l' || match === 'i') {
|
|
12
|
+
return '1'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return match
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export default async function getEvonodeList (network) {
|
|
2
|
+
const baseUrl = {
|
|
3
|
+
testnet: 'https://trpc.digitalcash.dev',
|
|
4
|
+
mainnet: 'https://rpc.digitalcash.dev'
|
|
5
|
+
}[network]
|
|
6
|
+
|
|
7
|
+
// let basicAuth = btoa(`user:pass`);
|
|
8
|
+
const payload = JSON.stringify({
|
|
9
|
+
method: 'masternodelist',
|
|
10
|
+
params: [
|
|
11
|
+
'evo'
|
|
12
|
+
]
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const resp = await fetch(baseUrl, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
// "Authorization": `Basic ${basicAuth}`,
|
|
19
|
+
'Content-Type': 'application/json'
|
|
20
|
+
},
|
|
21
|
+
body: payload
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const data = await resp.json()
|
|
25
|
+
|
|
26
|
+
if (data.error) {
|
|
27
|
+
const err = new Error(data.error.message)
|
|
28
|
+
Object.assign(err, data.error)
|
|
29
|
+
throw err
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return data.result
|
|
33
|
+
}
|
package/test/unit/index.spec.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/* global describe, test, beforeAll, expect */
|
|
2
|
+
|
|
3
|
+
import DashPlatformSDK from '../../src/index'
|
|
4
|
+
import { DataContractWASM, DocumentWASM, IdentityPublicKeyWASM, IdentityWASM } from 'pshenmic-dpp'
|
|
2
5
|
|
|
3
6
|
let sdk
|
|
4
7
|
|
|
@@ -12,7 +15,7 @@ describe('DashPlatformSDK', () => {
|
|
|
12
15
|
})
|
|
13
16
|
|
|
14
17
|
test('should be able to call getStatus', async () => {
|
|
15
|
-
const status = await sdk.
|
|
18
|
+
const status = await sdk.node.status()
|
|
16
19
|
|
|
17
20
|
expect(status.version.software.dapi).toEqual(expect.any(String))
|
|
18
21
|
expect(status.version.software.drive).toEqual(expect.any(String))
|
|
@@ -56,9 +59,84 @@ describe('DashPlatformSDK', () => {
|
|
|
56
59
|
expect(status.time.epoch).toEqual(expect.any(Number))
|
|
57
60
|
})
|
|
58
61
|
|
|
59
|
-
test('should be able to
|
|
60
|
-
const
|
|
62
|
+
test('should be able to create document', async () => {
|
|
63
|
+
const dataContract = '6QMfQTdKpC3Y9uWBcTwXeY3KdzRLDqASUsDnQ4MEc9XC'
|
|
64
|
+
const identity = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
65
|
+
const identityContractNonce = BigInt(1)
|
|
66
|
+
const documentType = 'pool'
|
|
67
|
+
const data = {
|
|
68
|
+
name: 'MyPool',
|
|
69
|
+
type: 'EVONODE',
|
|
70
|
+
status: 'INACTIVE',
|
|
71
|
+
description: 'test pool'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const document = await sdk.documents.create(dataContract, documentType, data, identityContractNonce, identity)
|
|
75
|
+
|
|
76
|
+
expect(document).toEqual(expect.any(DocumentWASM))
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('should be able to get data contract', async () => {
|
|
80
|
+
const dataContractIdentifier = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
|
|
81
|
+
|
|
82
|
+
const dataContract = await sdk.dataContracts.getByIdentifier(dataContractIdentifier)
|
|
83
|
+
|
|
84
|
+
expect(dataContract).toEqual(expect.any(DataContractWASM))
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('should be able to get documents', async () => {
|
|
88
|
+
const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
|
|
89
|
+
const documentType = 'domain'
|
|
90
|
+
|
|
91
|
+
const [document] = await sdk.documents.query(dataContract, documentType)
|
|
92
|
+
|
|
93
|
+
expect(document).toEqual(expect.any(DocumentWASM))
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('should be able to search names by DPNS name', async () => {
|
|
97
|
+
const [document] = await sdk.names.search('xyz.dash')
|
|
98
|
+
|
|
99
|
+
expect(document).toEqual(expect.any(DocumentWASM))
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('should be able to get identity by identifier', async () => {
|
|
103
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
104
|
+
|
|
105
|
+
const identity = await sdk.identities.getByIdentifier(identifier)
|
|
106
|
+
|
|
107
|
+
expect(identity).toEqual(expect.any(IdentityWASM))
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('should be able to get identity by public key hash', async () => {
|
|
111
|
+
const publicKeyHash = 'c5b7fdfa5731e1b31b1b42c13959756e8db22b3b'
|
|
112
|
+
|
|
113
|
+
const identity = await sdk.identities.getByPublicKeyHash(publicKeyHash)
|
|
114
|
+
|
|
115
|
+
expect(identity).toEqual(expect.any(IdentityWASM))
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('should be able to get identity contract nonce', async () => {
|
|
119
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
120
|
+
const dataContract = '6QMfQTdKpC3Y9uWBcTwXeY3KdzRLDqASUsDnQ4MEc9XC'
|
|
121
|
+
|
|
122
|
+
const identityContractNonce = await sdk.identities.getIdentityContractNonce(identifier, dataContract)
|
|
123
|
+
|
|
124
|
+
expect(identityContractNonce).toEqual(expect.any(BigInt))
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('should be able to get identity nonce', async () => {
|
|
128
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
129
|
+
|
|
130
|
+
const identityNonce = await sdk.identities.getIdentityNonce(identifier)
|
|
131
|
+
|
|
132
|
+
expect(identityNonce).toEqual(expect.any(BigInt))
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('should be able to get identity public keys', async () => {
|
|
136
|
+
const identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'
|
|
137
|
+
|
|
138
|
+
const identityPublicKeys = await sdk.identities.getIdentityPublicKeys(identifier)
|
|
61
139
|
|
|
62
|
-
expect(
|
|
140
|
+
expect(identityPublicKeys.every(identityPublicKey => identityPublicKey instanceof IdentityPublicKeyWASM)).toBeTruthy()
|
|
63
141
|
})
|
|
64
142
|
})
|
package/webpack.config.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
const path = require('path')
|
|
1
|
+
const path = require('path')
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
mode: 'production',
|
|
5
|
-
entry: './index.js',
|
|
5
|
+
entry: './src/index.js',
|
|
6
6
|
resolve: {
|
|
7
7
|
fallback: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
8
|
+
stream: require.resolve('stream-browserify'),
|
|
9
|
+
buffer: require.resolve('buffer/')
|
|
10
|
+
}
|
|
11
11
|
},
|
|
12
12
|
output: {
|
|
13
13
|
globalObject: 'this',
|
|
14
14
|
path: path.resolve(__dirname, 'dist'),
|
|
15
15
|
libraryTarget: 'umd'
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
16
|
+
}
|
|
17
|
+
}
|
package/dist/main.js.LICENSE.txt
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* The buffer module from node.js, for the browser.
|
|
3
|
-
*
|
|
4
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
9
|
-
|
|
10
|
-
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
11
|
-
|
|
12
|
-
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|