@ocap/client 1.6.5 → 1.6.10

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.
Files changed (60) hide show
  1. package/README.md +1 -1
  2. package/dist/base.js +36 -22
  3. package/dist/base.js.map +1 -1
  4. package/dist/browser.d.ts +974 -567
  5. package/dist/browser.js +1 -8
  6. package/dist/browser.js.map +1 -1
  7. package/dist/bundle.js +3 -3
  8. package/dist/client.js +11 -7
  9. package/dist/client.js.map +1 -1
  10. package/dist/extension.js +502 -462
  11. package/dist/extension.js.map +1 -1
  12. package/dist/methods.js +0 -142
  13. package/dist/methods.js.map +1 -1
  14. package/dist/report.html +2 -2
  15. package/dist/schema/graphql.json +9447 -4831
  16. package/dist/schema/graphql.txt +2 -2
  17. package/dist/types.js +2137 -1918
  18. package/dist/types.js.map +1 -1
  19. package/docs/QUERIES.md +1547 -1494
  20. package/docs/README.md +4386 -4937
  21. package/examples/asset.js +7 -7
  22. package/examples/create-secondary-token.js +44 -0
  23. package/examples/declare.js +9 -9
  24. package/examples/{delegate_exchange_both.js → delegate-exchange-both.js} +12 -8
  25. package/examples/{delegate_exchange.js → delegate-exchange.js} +11 -7
  26. package/examples/{delegate_transfer.js → delegate-transfer.js} +12 -6
  27. package/examples/exchange-secondary-token.js +100 -0
  28. package/examples/exchange.js +9 -9
  29. package/examples/{migrate_account.js → migrate-account.js} +5 -5
  30. package/examples/run-no-debug.sh +8 -8
  31. package/examples/run.sh +8 -8
  32. package/examples/subscribe.js +16 -0
  33. package/examples/{transfer_asset.js → transfer-asset.js} +11 -11
  34. package/examples/{transfer_token.js → transfer-primary-token.js} +10 -10
  35. package/examples/transfer-secondary-token.js +62 -0
  36. package/lib/base.js +36 -22
  37. package/lib/base.js.map +1 -1
  38. package/lib/client.js +11 -7
  39. package/lib/client.js.map +1 -1
  40. package/lib/extension.js +502 -462
  41. package/lib/extension.js.map +1 -1
  42. package/lib/methods.js +0 -142
  43. package/lib/methods.js.map +1 -1
  44. package/lib/node.d.ts +974 -567
  45. package/lib/node.js +0 -6
  46. package/lib/node.js.map +1 -1
  47. package/lib/schema/graphql.json +9447 -4831
  48. package/lib/schema/graphql.txt +2 -2
  49. package/lib/types.js +2137 -1918
  50. package/lib/types.js.map +1 -1
  51. package/package.json +30 -32
  52. package/examples/atomic_swap.js +0 -145
  53. package/examples/consume_asset_gatekeeper.js +0 -105
  54. package/examples/consume_asset_simple.js +0 -91
  55. package/examples/declare_forgeweb.js +0 -60
  56. package/examples/declare_restricted.js +0 -47
  57. package/examples/delegate_atomic_swap.js +0 -177
  58. package/examples/get_free_token.js +0 -33
  59. package/examples/subscribe_new_block.js +0 -36
  60. package/examples/subscribe_transfer.js +0 -80
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@ocap/client",
3
- "version": "1.6.5",
3
+ "version": "1.6.10",
4
4
  "description": "graphql client to read/write data on forge powered blockchain",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "client",
8
- "forge",
9
8
  "blockchain",
10
9
  "arcblock"
11
10
  ],
@@ -17,7 +16,10 @@
17
16
  "email": "shijun@arcblock.io",
18
17
  "url": "https://github.com/wangshijun"
19
18
  },
20
- "homepage": "https://github.com/arcblock/ocap-js/forge/graphql-client",
19
+ "contributors": [
20
+ "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
21
+ ],
22
+ "homepage": "https://github.com/arcblock/asset-chain/forge/graphql-client",
21
23
  "license": "Apache-2.0",
22
24
  "main": "./lib/node.js",
23
25
  "browser": "./dist/browser.js",
@@ -28,40 +30,37 @@
28
30
  "lib"
29
31
  ],
30
32
  "dependencies": {
31
- "@arcblock/did": "^1.6.5",
32
- "@arcblock/did-util": "^1.6.5",
33
- "@arcblock/sdk-util": "^0.29.1",
34
- "@ocap/mcrypto": "^1.6.5",
35
- "@ocap/message": "^1.6.5",
36
- "@ocap/proto": "^1.6.5",
37
- "@ocap/util": "^1.6.5",
38
- "@ocap/wallet": "^1.6.5",
33
+ "@arcblock/did": "1.6.10",
34
+ "@arcblock/did-util": "1.6.10",
35
+ "@arcblock/sdk-util": "^0.30.0",
36
+ "@arcblock/ws": "1.6.10",
37
+ "@ocap/asset": "1.6.10",
38
+ "@ocap/mcrypto": "1.6.10",
39
+ "@ocap/message": "1.6.10",
40
+ "@ocap/proto": "1.6.10",
41
+ "@ocap/util": "1.6.10",
42
+ "@ocap/wallet": "1.6.10",
39
43
  "blueimp-md5": "^2.10.0",
40
- "debug": "^4.3.1",
44
+ "debug": "^4.3.3",
45
+ "is-absolute-url": "^3.0.3",
41
46
  "jsonpack": "^1.1.5",
42
47
  "lodash": "^4.17.21",
43
- "phoenix-channels": "^1.0.0",
44
48
  "react-app-polyfill": "^1.0.1",
45
49
  "wolfy87-eventemitter": "^5.2.5"
46
50
  },
47
51
  "devDependencies": {
48
- "@arcblock/did-util": "^1.6.0",
49
- "@ocap/util": "^1.6.0",
50
- "@ocap/wallet": "^1.6.0",
51
- "axios": "^0.21.1",
52
- "axios-mock-adapter": "^1.19.0",
53
52
  "babel-cli": "^6.26.0",
54
53
  "babel-plugin-inline-import": "^3.0.0",
55
54
  "babel-preset-env": "^1.7.0",
56
- "eslint": "6.8.0",
55
+ "eslint": "^7.31.0",
57
56
  "graphql": "14.6.0",
58
- "graphql-request": "^1.8.2",
57
+ "graphql-request": "^4.2.0",
59
58
  "inspectpack": "^4.2.1",
60
- "jest": "^26.6.3",
61
- "jsdoc-to-markdown": "^5.0.0",
62
- "prettier": "^2.2.1",
63
- "remark-cli": "^5.0.0",
64
- "remark-preset-github": "^0.0.9",
59
+ "jest": "^27.3.1",
60
+ "jsdoc-to-markdown": "^7.1.1",
61
+ "prettier": "^2.3.2",
62
+ "remark-cli": "^10.0.1",
63
+ "remark-preset-github": "^4.0.1",
65
64
  "rimraf": "^2.6.2",
66
65
  "shelljs": "^0.8.3",
67
66
  "webpack": "^4.29.6",
@@ -72,9 +71,8 @@
72
71
  "plugins": [
73
72
  "preset-github",
74
73
  [
75
- "validate-links",
76
74
  {
77
- "repository": "ArcBlock/ocap-js"
75
+ "repository": "ArcBlock/asset-chain"
78
76
  }
79
77
  ]
80
78
  ]
@@ -96,16 +94,16 @@
96
94
  "update-schema": "rm -f src/schema/graphql.json && node tools/update-graphql-schema.js",
97
95
  "upgrade": "npm run update-schema && npm run build && npm run gen-queries && npm run gen-types && npm run docs && npm run build && npm run lint:fix",
98
96
  "docs": "npm run gen-dts && npm run gen-docs && npm run cleanup-docs && npm run format-docs",
99
- "cleanup-docs": "node ../../tools/cleanup-docs.js docs/README.md $npm_package_name",
100
- "test": "node tools/jest.js",
97
+ "cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
98
+ "test": "jest --forceExit --detectOpenHandles",
101
99
  "coverage": "npm run test -- --coverage"
102
100
  },
103
101
  "repository": {
104
102
  "type": "git",
105
- "url": "git+https://github.com/ArcBlock/ocap-js.git"
103
+ "url": "git+https://github.com/ArcBlock/asset-chain.git"
106
104
  },
107
105
  "bugs": {
108
- "url": "https://github.com/ArcBlock/ocap-js/issues"
106
+ "url": "https://github.com/ArcBlock/asset-chain/issues"
109
107
  },
110
- "gitHead": "5779448f13824de38978df3c84c9da0c1e1ad989"
108
+ "gitHead": "ab272e8db3a15c6571cc7fae7cc3d3e0fdd4bdb1"
111
109
  }
@@ -1,145 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- /* eslint no-console:"off" */
3
-
4
- /**
5
- * This script demonstrates how to do atomic swap between two chains
6
- * This script requires 2 running chain
7
- *
8
- * Run script with: `DEBUG=@ocap/client node examples/atomic_swap.js`
9
- */
10
-
11
- const GraphQLClient = require('@ocap/client');
12
- const { getRandomBytes, Hasher } = require('@ocap/mcrypto');
13
- const { fromRandom } = require('@ocap/wallet');
14
-
15
- const appChain = new GraphQLClient({ endpoint: 'http://localhost:8210/api' });
16
- const assetChain = new GraphQLClient({ endpoint: 'http://localhost:8211/api' });
17
-
18
- const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
19
-
20
- (async () => {
21
- try {
22
- const buyer = fromRandom();
23
- const seller = fromRandom();
24
- console.log({
25
- buyer: buyer.toJSON(),
26
- seller: seller.toJSON(),
27
- });
28
-
29
- const declare = async (wallet, moniker) => {
30
- let hash = await appChain.declare({ moniker, wallet });
31
- console.log(`declare.appChain.${moniker}`, hash);
32
-
33
- hash = await assetChain.declare({ moniker, wallet });
34
- console.log(`declare.assetChain.${moniker}`, hash);
35
- };
36
-
37
- // declare
38
- await declare(buyer, 'buyer');
39
- await declare(seller, 'seller');
40
-
41
- // 3. ensure asset for seller on app chain
42
- const ensureSellerAsset = async () => {
43
- const [hash, address] = await appChain.createAsset({
44
- moniker: 'asset',
45
- data: {
46
- typeUrl: 'json',
47
- value: {
48
- key: 'value2',
49
- sn: Math.random(),
50
- },
51
- },
52
- wallet: seller,
53
- });
54
- console.log('ensureSellerAsset', hash, address);
55
- return address;
56
- };
57
-
58
- // ensure token for buyer on asset chain
59
- const ensureBuyerToken = async () => {
60
- const hash = await assetChain.checkin({ wallet: buyer });
61
- console.log('ensureSellerAsset', hash);
62
- };
63
-
64
- // setup swap on asset chain
65
- const doBuyerSetup = async (asset, hashlock) => {
66
- const hash = await assetChain.setupSwap({
67
- token: 10,
68
- assets: [],
69
- receiver: seller.toAddress(),
70
- hashlock,
71
- wallet: buyer,
72
- });
73
- console.log('doBuyerSetup', hash);
74
- return hash;
75
- };
76
-
77
- // setup swap on app chain
78
- const doSellerSetup = async (asset, hashlock) => {
79
- const hash = await appChain.setupSwap({
80
- token: 0,
81
- assets: [asset],
82
- receiver: buyer.toAddress(),
83
- hashlock,
84
- wallet: seller,
85
- });
86
- console.log('doSellerSetup', hash);
87
- return hash;
88
- };
89
-
90
- // retrieve swap on app chain
91
- const doBuyerRetrieve = async (address, hashkey) => {
92
- const hash = await appChain.retrieveSwap({
93
- address,
94
- hashkey,
95
- wallet: buyer,
96
- });
97
- console.log('doBuyerRetrieve', hash);
98
- };
99
-
100
- // retrieve swap on asset chain
101
- const doSellerRetrieve = async (address, hashkey) => {
102
- const hash = await assetChain.retrieveSwap({
103
- address,
104
- hashkey,
105
- wallet: seller,
106
- });
107
- console.log('doSellerRetrieve', hash);
108
- };
109
-
110
- // token and asset
111
- const asset = await ensureSellerAsset();
112
- console.log('asset', asset);
113
- await ensureBuyerToken();
114
- await sleep(3000);
115
-
116
- // Setup swap by buyer
117
- const hashkey = getRandomBytes(32);
118
- const hashlock = Hasher.SHA3.hash256(hashkey);
119
- const [buyerSetupHash, buyerSwapAddress] = await doBuyerSetup(asset, hashlock);
120
- const [sellerSetupHash, sellerSwapAddress] = await doSellerSetup(asset, hashlock);
121
- console.log('setup', {
122
- hashkey,
123
- hashlock,
124
- buyerSetupHash,
125
- buyerSwapAddress,
126
- sellerSetupHash,
127
- sellerSwapAddress,
128
- });
129
- await sleep(3000);
130
-
131
- // Inspect swap
132
- const buyerSwapState = await assetChain.getSwapState({ address: buyerSwapAddress });
133
- const sellerSwapState = await appChain.getSwapState({ address: sellerSwapAddress });
134
- console.log('buyerSwapState', buyerSwapState);
135
- console.log('sellerSwapState', sellerSwapState);
136
-
137
- await doBuyerRetrieve(sellerSwapAddress, hashkey);
138
- await doSellerRetrieve(buyerSwapAddress, hashkey);
139
-
140
- // TODO: validate swap
141
- } catch (err) {
142
- console.error(err);
143
- console.log(JSON.stringify(err.errors));
144
- }
145
- })();
@@ -1,105 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- /* eslint no-console:"off" */
3
-
4
- /**
5
- * This script demonstrates the whole workflow of consume assets with graphql-client
6
- *
7
- * Run script with: `DEBUG=@ocap/client node examples/consume_asset_gatekeeper.js`
8
- */
9
-
10
- const GraphQLClient = require('@ocap/client');
11
- const { fromRandom } = require('@ocap/wallet');
12
-
13
- const endpoint = process.env.FORGE_API_HOST || 'http://127.0.0.1:8210'; // testnet
14
-
15
- const client = new GraphQLClient(`${endpoint}/api`);
16
- const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
17
-
18
- (async () => {
19
- try {
20
- const issuer = fromRandom(); // the one create asset and responsible for consuming asset
21
- const consumer = fromRandom(); // the one bought the asset and want to use it
22
- const gateKeeper = fromRandom(); // the gateKeeper that is responsible to consume the asset
23
- console.log({
24
- issuer: issuer.toAddress(),
25
- consumer: consumer.toAddress(),
26
- gateKeeper: gateKeeper.toAddress(),
27
- });
28
-
29
- // 1. declare issuer
30
- let hash = await client.declare({ moniker: 'issuer', wallet: issuer });
31
- console.log('issuer account', `${endpoint}/node/explorer/accounts/${issuer.toAddress()}`);
32
- console.log('issuer tx', `${endpoint}/node/explorer/txs/${hash}`);
33
-
34
- // 2. declare consumer
35
- hash = await client.declare({ moniker: 'consumer', wallet: consumer });
36
- console.log('consumer account', `${endpoint}/node/explorer/accounts/${consumer.toAddress()}`);
37
- console.log('consumer tx', `${endpoint}/node/explorer/txs/${hash}`);
38
-
39
- // 3. declare gate keeper
40
- hash = await client.declare({
41
- moniker: 'gateKeeper',
42
- issuer: issuer.toAddress(),
43
- wallet: gateKeeper,
44
- });
45
- console.log('gate keeper account', `${endpoint}/node/explorer/accounts/${gateKeeper.toAddress()}`);
46
- console.log('gate keeper tx', `${endpoint}/node/explorer/txs/${hash}`);
47
-
48
- // 4. create asset for issuer
49
- let assetAddress;
50
- // eslint-disable-next-line prefer-const
51
- [hash, assetAddress] = await client.createAsset({
52
- moniker: 'asset_to_be_consumed',
53
- data: {
54
- typeUrl: 'json',
55
- value: {
56
- sn: Math.random(), // To make this asset uniq every time this script runs
57
- key: 'value2',
58
- },
59
- },
60
- wallet: issuer,
61
- });
62
- console.log('view asset state', `${endpoint}/node/explorer/assets/${assetAddress}`);
63
- console.log('view asset tx', `${endpoint}/node/explorer/txs/${hash}`);
64
- await sleep(3000);
65
-
66
- // 4. transfer asset from issuer to consumer
67
- hash = await client.transfer({
68
- to: consumer.toAddress(),
69
- assets: [assetAddress],
70
- wallet: issuer,
71
- });
72
- console.log('view transfer tx', `${endpoint}/node/explorer/txs/${hash}`);
73
- await sleep(3000);
74
- const { state } = await client.getAssetState({ address: assetAddress });
75
- console.log('asset state', state);
76
-
77
- // 5.1 issuer: encode and sign the transaction
78
- const tx = await client.prepareConsumeAsset({
79
- issuer: issuer.toAddress(),
80
- wallet: gateKeeper,
81
- // wallet: issuer,
82
- });
83
- // console.log('gateKeeper.signed', inspect(tx));
84
- // console.log('issuer.signed', inspect(tx));
85
-
86
- // 5.2 consumer: populate signatures field
87
- const tx2 = await client.finalizeConsumeAsset({
88
- tx,
89
- wallet: consumer,
90
- address: assetAddress,
91
- });
92
- // console.log('consumer.signed', inspect(tx2));
93
-
94
- // 5.3 Send the consume tx
95
- await sleep(3000);
96
- hash = await client.consumeAsset({
97
- tx: tx2,
98
- wallet: consumer,
99
- });
100
- console.log('view consume tx', `${endpoint}/node/explorer/txs/${hash}`);
101
- } catch (err) {
102
- console.error(err);
103
- console.log(JSON.stringify(err.errors));
104
- }
105
- })();
@@ -1,91 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- /* eslint no-console:"off" */
3
-
4
- /**
5
- * This script demonstrates the whole workflow of consume assets with graphql-client
6
- *
7
- * Run script with: `DEBUG=@ocap/client node examples/consume_asset_simple.js`
8
- */
9
-
10
- const GraphQLClient = require('@ocap/client');
11
- const { fromRandom } = require('@ocap/wallet');
12
-
13
- const endpoint = process.env.FORGE_API_HOST || 'http://127.0.0.1:8210'; // testnet
14
-
15
- const client = new GraphQLClient(`${endpoint}/api`);
16
- const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
17
-
18
- (async () => {
19
- try {
20
- const issuer = fromRandom(); // the one create asset and responsible for consuming asset
21
- const consumer = fromRandom(); // the one bought the asset and want to use it
22
- console.log({
23
- issuer: issuer.toAddress(),
24
- consumer: consumer.toAddress(),
25
- });
26
-
27
- // 1. declare issuer
28
- let hash = await client.declare({ moniker: 'issuer', wallet: issuer });
29
- console.log('issuer account', `${endpoint}/node/explorer/accounts/${issuer.toAddress()}`);
30
- console.log('issuer tx', `${endpoint}/node/explorer/txs/${hash}`);
31
-
32
- // 2. declare consumer
33
- hash = await client.declare({ moniker: 'consumer', wallet: consumer });
34
- console.log('consumer account', `${endpoint}/node/explorer/accounts/${consumer.toAddress()}`);
35
- console.log('consumer tx', `${endpoint}/node/explorer/txs/${hash}`);
36
-
37
- // 3. create asset for issuer
38
- let assetAddress;
39
- // eslint-disable-next-line prefer-const
40
- [hash, assetAddress] = await client.createAsset({
41
- moniker: 'asset_to_be_consumed',
42
- data: {
43
- typeUrl: 'json',
44
- value: {
45
- sn: Math.random(), // To make this asset uniq every time this script runs
46
- key: 'value2',
47
- },
48
- },
49
- wallet: issuer,
50
- });
51
- console.log('view asset state', `${endpoint}/node/explorer/assets/${assetAddress}`);
52
- console.log('view asset tx', `${endpoint}/node/explorer/txs/${hash}`);
53
- await sleep(3000);
54
-
55
- // 4. transfer asset from issuer to consumer
56
- hash = await client.transfer({
57
- to: consumer.toAddress(),
58
- assets: [assetAddress],
59
- wallet: issuer,
60
- });
61
- console.log('view transfer tx', `${endpoint}/node/explorer/txs/${hash}`);
62
- await sleep(3000);
63
- const { state } = await client.getAssetState({ address: assetAddress });
64
- console.log('asset state', state);
65
-
66
- // 5.1 issuer: encode and sign the transaction
67
- const tx = await client.prepareConsumeAsset({
68
- issuer: issuer.toAddress(),
69
- wallet: issuer,
70
- });
71
-
72
- // 5.2 consumer: populate signatures field
73
- const tx2 = await client.finalizeConsumeAsset({
74
- tx,
75
- wallet: consumer,
76
- address: assetAddress,
77
- });
78
- // console.log('consumer.signed', inspect(tx2));
79
-
80
- // 5.3 Send the consume tx
81
- await sleep(3000);
82
- hash = await client.consumeAsset({
83
- tx: tx2,
84
- wallet: consumer,
85
- });
86
- console.log('view consume tx', `${endpoint}/node/explorer/txs/${hash}`);
87
- } catch (err) {
88
- console.error(err);
89
- console.log(JSON.stringify(err.errors));
90
- }
91
- })();
@@ -1,60 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- /* eslint no-console:"off" */
3
-
4
- /**
5
- * This script demonstrates how to declare an identity on the blockchain
6
- *
7
- * In real world, identities may belong to different entities: application, user, node, device
8
- *
9
- * Run script with: `DEBUG=@ocap/client node examples/declare_forgeweb.js`
10
- */
11
- const axios = require('axios');
12
- const { JWT } = require('@arcblock/did-auth');
13
- const { fromRandom } = require('@ocap/wallet');
14
- const { toBase58 } = require('@ocap/util');
15
-
16
- // const endpoint = process.env.FORGE_API_HOST || 'http://127.0.0.1:8210';
17
- const endpoint = process.env.FORGE_API_HOST || 'https://xenon.abtnetwork.io';
18
-
19
- axios.defaults.baseURL = endpoint;
20
-
21
- (async () => {
22
- try {
23
- const user = fromRandom();
24
- console.log('user', user.toJSON());
25
-
26
- const { data } = await axios.get('/didauth/declare');
27
- let info = JWT.decode(data.authInfo);
28
- console.log('Step1', info);
29
-
30
- let token = JWT.sign(user.toAddress(), user.secretKey, { requestedClaims: [] });
31
- let payload = {
32
- userPk: toBase58(user.publicKey),
33
- userInfo: token,
34
- };
35
-
36
- let result = await axios.post(info.url, payload);
37
- info = JWT.decode(result.data.authInfo);
38
- console.log('Step2', info);
39
-
40
- const { requestedClaims } = info;
41
- const { origin, digest } = requestedClaims[0];
42
- if (toBase58(user.hash(origin)) !== digest) {
43
- throw new Error('Origin and digest do not match');
44
- }
45
- requestedClaims[0].sig = toBase58(user.sign(origin));
46
-
47
- token = JWT.sign(user.toAddress(), user.secretKey, { requestedClaims });
48
- payload = {
49
- userPk: toBase58(user.publicKey),
50
- userInfo: token,
51
- };
52
-
53
- result = await axios.post(info.url, payload);
54
- info = JWT.decode(result.data.authInfo);
55
- console.log('Step3', info);
56
- } catch (err) {
57
- console.error(err);
58
- console.log(JSON.stringify(err.errors));
59
- }
60
- })();
@@ -1,47 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- /* eslint no-console:"off" */
3
-
4
- /**
5
- * This script demonstrates how to declare an identity on the blockchain
6
- *
7
- * In real world, identities may belong to different entities: application, user, node, device
8
- *
9
- * Run script with: `DEBUG=@ocap/client node examples/declare.js`
10
- */
11
- const GraphqlClient = require('@ocap/client');
12
- const Mcrypto = require('@ocap/mcrypto');
13
- const { fromRandom, fromSecretKey, WalletType } = require('@ocap/wallet');
14
-
15
- const endpoint = process.env.FORGE_API_HOST || 'http://127.0.0.1:8210'; // testnet
16
-
17
- const client = new GraphqlClient(`${endpoint}/api`);
18
- // change this to your chain moderator sk before run the script
19
- const sk = '<YOUR MODERATOR SK HERE>';
20
-
21
- (async () => {
22
- try {
23
- const issuer = fromSecretKey(sk, WalletType({ role: Mcrypto.types.RoleType.ROLE_ACCOUNT }));
24
- console.log(issuer.toJSON());
25
-
26
- console.log('issuer', `${endpoint}/node/explorer/accounts/${issuer.toAddress()}`);
27
-
28
- // Sign and then send: sendDeclareTx
29
- const user = fromRandom();
30
- const tx1 = await client.prepareDeclare({
31
- issuer: issuer.toAddress(),
32
- moniker: 'user',
33
- wallet: user,
34
- });
35
- const tx2 = await client.finalizeDeclare({
36
- tx: tx1,
37
- wallet: issuer,
38
- });
39
-
40
- const hash = await client.sendDeclareTx({ tx: tx2, wallet: issuer });
41
- console.log('user', `${endpoint}/node/explorer/accounts/${user.toAddress()}`);
42
- console.log('tx', `${endpoint}/node/explorer/txs/${hash}`);
43
- } catch (err) {
44
- console.error(err);
45
- console.log(JSON.stringify(err.errors));
46
- }
47
- })();