@dc3-network/dc3js 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2024-Preset DC3 Network
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @dc3-network/dc3js
@@ -0,0 +1,109 @@
1
+ 'use strict';
2
+
3
+ import {merge, isPlainObject} from 'lodash';
4
+
5
+ const defaultEndpoints = Object.freeze({
6
+ rpc: 'http://localhost:26657',
7
+ rest: 'http://localhost:1317'
8
+ });
9
+
10
+ const localConfig = Object.freeze({
11
+ chainId: 'local'
12
+ });
13
+
14
+ const devConfig = Object.freeze({
15
+ chainId: 'devnet'
16
+ });
17
+
18
+ const testConfig = Object.freeze({
19
+ chainId: 'testnet'
20
+ });
21
+
22
+ const prodConfig = Object.freeze({
23
+ chainId: 'mainnet'
24
+ });
25
+
26
+ const baseConfig = Object.freeze({
27
+ chainId: '',
28
+ chainName: 'dc3',
29
+ rpc: '',
30
+ rest: '',
31
+ bip44: Object.freeze({
32
+ coinType: 118
33
+ }),
34
+ bech32Config: Object.freeze({
35
+ bech32PrefixAccAddr: 'dc3',
36
+ bech32PrefixAccPub: 'dc3pub',
37
+ bech32PrefixValAddr: 'dc3valoper',
38
+ bech32PrefixValPub: 'dc3valoperpub',
39
+ bech32PrefixConsAddr: 'dc3valcons',
40
+ bech32PrefixConsPub: 'dc3valconspub',
41
+ }),
42
+ currencies: Object.freeze([
43
+ Object.freeze({
44
+ coinDenom: 'DC3',
45
+ coinMinimalDenom: 'udc3',
46
+ coinDecimals: 6,
47
+ coinGeckoId: "dc3-identity-token"
48
+ })
49
+ ]),
50
+ feeCurrencies: Object.freeze([
51
+ Object.freeze({
52
+ coinDenom: 'DC3',
53
+ coinMinimalDenom: 'udc3',
54
+ coinDecimals: 6,
55
+ coinGeckoId: "dc3-identity-token",
56
+ gasPriceStep: {
57
+ low: 0.001,
58
+ average: 0.0015,
59
+ high: 0.002
60
+ }
61
+ })
62
+ ]),
63
+ stakeCurrency: Object.freeze({
64
+ coinDenom: 'DC3',
65
+ coinMinimalDenom: 'udc3',
66
+ coinDecimals: 6,
67
+ coinGeckoId: "dc3-identity-token"
68
+ }),
69
+ features: Object.freeze([
70
+ "ibc-go"
71
+ ])
72
+ });
73
+
74
+ export const ChainTypeLocal = 'local';
75
+ export const ChainTypeDev = 'dev';
76
+ export const ChainTypeTest = 'test';
77
+ export const ChainTypeProd = 'prod';
78
+
79
+ export const getChainConfig = (type, endpoints = defaultEndpoints) => {
80
+ let conf = null;
81
+
82
+ switch (type) {
83
+ case ChainTypeLocal:
84
+ conf = localConfig;
85
+ break;
86
+ case ChainTypeDev:
87
+ conf = devConfig;
88
+ break;
89
+ case ChainTypeTest:
90
+ conf = testConfig;
91
+ break;
92
+ case ChainTypeProd:
93
+ conf = prodConfig;
94
+ break;
95
+ default:
96
+ return null;
97
+ }
98
+
99
+ if (!isPlainObject(endpoints)) {
100
+ endpoints = {}
101
+ }
102
+
103
+ const ep = merge({}, defaultEndpoints, endpoints);
104
+
105
+ conf.rpc = ep.rpc;
106
+ conf.rest = ep.rest;
107
+
108
+ return merge({}, baseConfig, conf);
109
+ };
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ import {getChainConfig} from './config/chain';
4
+
5
+ export const chainConfig = getChainConfig;
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@dc3-network/dc3js",
3
+ "version": "0.1.0",
4
+ "description": "DC3 blockchain sdk",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/dc3-network/dc3js.git"
13
+ },
14
+ "contributors": [
15
+ "Craig Thayer <cthayer@users.noreply.github.com>"
16
+ ],
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/dc3-network/dc3js/issues"
20
+ },
21
+ "homepage": "https://github.com/dc3-network/dc3js#readme",
22
+ "dependencies": {
23
+ "@dc3-network/x-node-types": "^0.2.0",
24
+ "@dc3-network/x-org-types": "^0.1.0",
25
+ "lodash": "^4.17.23"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "exports": {
31
+ ".": "./index.js",
32
+ "./tx": "./tx/index.js",
33
+ "./config": "./config/chain.js"
34
+ }
35
+ }
package/tx/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ export * from './v1';
package/tx/v1/index.js ADDED
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ import {forEach} from 'lodash';
4
+
5
+ // import all dc3 chain messages
6
+ import * as nodeMsgPkg from '@dc3-network/x-node-types/v1/tx';
7
+ import * as orgMsgPkg from '@dc3-network/x-org-types/v1/tx';
8
+
9
+ const messages = [];
10
+
11
+ const registerMessages = (pkg) => {
12
+ if (!pkg || !pkg.protobufPackage) {
13
+ return;
14
+ }
15
+
16
+ const protoPkg = pkg.protobufPackage;
17
+
18
+ if (!protoPkg) {
19
+ return;
20
+ }
21
+
22
+ forEach(pkg, (v, k) => {
23
+ if (k.substring(0, 3) !== 'Msg' || k.substring(0, 10) === 'MsgService' || k.substring(0, 9) === 'MsgClient') {
24
+ return;
25
+ }
26
+
27
+ if (!v.typeUrl) {
28
+ v.typeUrl = '/' + protoPkg + '.' + k;
29
+ }
30
+
31
+ messages.push(v);
32
+ });
33
+ };
34
+
35
+ forEach([nodeMsgPkg, orgMsgPkg], registerMessages);
36
+
37
+ export const getMessages = () => {
38
+ return messages;
39
+ };