@tari-project/tarijs 0.4.0 → 0.4.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.
Files changed (167) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +36 -0
  2. package/.github/PULL_REQUEST_TEMPLATE.md +27 -0
  3. package/.github/dependabot.yml +8 -0
  4. package/.github/workflows/ci.yml +26 -0
  5. package/.github/workflows/documentation-deploy.yml +44 -0
  6. package/.github/workflows/documentation-test-deploy.yml +20 -0
  7. package/.github/workflows/npm_publish.yml +26 -0
  8. package/.github/workflows/pr_signed_commits_check.yml +19 -0
  9. package/.github/workflows/pr_title.yml +30 -0
  10. package/.moon/toolchain.yml +6 -0
  11. package/.moon/workspace.yml +33 -0
  12. package/.prettierrc +12 -0
  13. package/.prototools +9 -0
  14. package/CODEOWNERS +3 -0
  15. package/README.md +66 -0
  16. package/TODO.md +12 -0
  17. package/docusaurus/tari-docs/README.md +41 -0
  18. package/docusaurus/tari-docs/docs/index.md +16 -0
  19. package/docusaurus/tari-docs/docs/installation.md +27 -0
  20. package/docusaurus/tari-docs/docs/providers/_category_.json +8 -0
  21. package/docusaurus/tari-docs/docs/providers/tari-universe.md +27 -0
  22. package/docusaurus/tari-docs/docs/providers/wallet-connect.md +52 -0
  23. package/docusaurus/tari-docs/docs/providers/wallet-daemon.md +37 -0
  24. package/docusaurus/tari-docs/docs/wallet/_category_.json +8 -0
  25. package/docusaurus/tari-docs/docs/wallet/default-account.md +51 -0
  26. package/docusaurus/tari-docs/docs/wallet/get-substate.md +110 -0
  27. package/docusaurus/tari-docs/docs/wallet/list-substates.md +69 -0
  28. package/docusaurus/tari-docs/docs/wallet/submit-transaction/_category_.json +8 -0
  29. package/docusaurus/tari-docs/docs/wallet/submit-transaction/build-execute-request.md +38 -0
  30. package/docusaurus/tari-docs/docs/wallet/submit-transaction/index.md +14 -0
  31. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/_category_.json +8 -0
  32. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-function.md +17 -0
  33. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-method.md +17 -0
  34. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/fee.md +28 -0
  35. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/index.md +426 -0
  36. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/inputs.md +24 -0
  37. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/instruction.md +108 -0
  38. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/min-max-epoch.md +19 -0
  39. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/raw-instructions.md +16 -0
  40. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/save-var.md +63 -0
  41. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/transaction-internals.md +20 -0
  42. package/docusaurus/tari-docs/docs/wallet/template-definition.md +101 -0
  43. package/docusaurus/tari-docs/docusaurus.config.ts +108 -0
  44. package/docusaurus/tari-docs/moon.yml +41 -0
  45. package/docusaurus/tari-docs/package.json +49 -0
  46. package/docusaurus/tari-docs/sidebars.ts +7 -0
  47. package/docusaurus/tari-docs/src/components/HomepageFeatures/index.tsx +69 -0
  48. package/docusaurus/tari-docs/src/components/HomepageFeatures/styles.module.css +11 -0
  49. package/docusaurus/tari-docs/src/css/custom.css +30 -0
  50. package/docusaurus/tari-docs/src/pages/index.module.css +23 -0
  51. package/docusaurus/tari-docs/src/pages/index.tsx +44 -0
  52. package/docusaurus/tari-docs/static/.nojekyll +0 -0
  53. package/docusaurus/tari-docs/static/img/favicon.png +0 -0
  54. package/docusaurus/tari-docs/static/img/meta-image.png +0 -0
  55. package/docusaurus/tari-docs/static/img/tari/wallet-connect-1.png +0 -0
  56. package/docusaurus/tari-docs/static/img/tari/wallet-connect-2.png +0 -0
  57. package/docusaurus/tari-docs/static/img/tari/wallet-connect-3.png +0 -0
  58. package/docusaurus/tari-docs/static/img/tari-logo.svg +30 -0
  59. package/docusaurus/tari-docs/tsconfig.json +8 -0
  60. package/package.json +4 -28
  61. package/packages/builders/moon.yml +55 -0
  62. package/packages/builders/package.json +30 -0
  63. package/packages/builders/src/helpers/index.ts +2 -0
  64. package/packages/builders/src/helpers/submitTransaction.ts +97 -0
  65. package/packages/builders/src/helpers/workspace.ts +32 -0
  66. package/packages/builders/src/index.ts +9 -0
  67. package/packages/builders/src/transaction/TransactionBuilder.ts +276 -0
  68. package/packages/builders/src/transaction/TransactionRequest.ts +93 -0
  69. package/packages/builders/src/transaction/index.ts +2 -0
  70. package/packages/builders/tsconfig.json +24 -0
  71. package/packages/metamask_provider/moon.yml +55 -0
  72. package/packages/metamask_provider/package.json +30 -0
  73. package/packages/metamask_provider/src/index.ts +232 -0
  74. package/packages/metamask_provider/src/utils.ts +86 -0
  75. package/packages/metamask_provider/tsconfig.json +21 -0
  76. package/packages/tari_permissions/moon.yml +55 -0
  77. package/packages/tari_permissions/package.json +26 -0
  78. package/packages/tari_permissions/src/index.ts +1 -0
  79. package/packages/tari_permissions/src/tari_permissions.ts +312 -0
  80. package/packages/tari_permissions/tsconfig.json +15 -0
  81. package/packages/tari_provider/moon.yml +55 -0
  82. package/packages/tari_provider/package.json +27 -0
  83. package/packages/tari_provider/src/TariProvider.ts +34 -0
  84. package/packages/tari_provider/src/index.ts +3 -0
  85. package/packages/tari_provider/src/types.ts +84 -0
  86. package/packages/tari_provider/tsconfig.json +11 -0
  87. package/packages/tari_universe/moon.yml +55 -0
  88. package/packages/tari_universe/package.json +31 -0
  89. package/packages/tari_universe/src/index.ts +3 -0
  90. package/packages/tari_universe/src/provider.ts +120 -0
  91. package/packages/tari_universe/src/types.ts +33 -0
  92. package/packages/tari_universe/src/utils.ts +23 -0
  93. package/packages/tari_universe/tsconfig.json +24 -0
  94. package/packages/tarijs/integration-tests/.env +1 -0
  95. package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +191 -0
  96. package/packages/tarijs/moon.yml +71 -0
  97. package/packages/tarijs/package.json +40 -0
  98. package/packages/tarijs/src/cbor.spec.ts +259 -0
  99. package/packages/tarijs/src/cbor.ts +114 -0
  100. package/packages/tarijs/src/index.ts +72 -0
  101. package/packages/tarijs/src/network.ts +8 -0
  102. package/packages/tarijs/src/templates/Account.ts +98 -0
  103. package/packages/tarijs/src/templates/Pool.ts +42 -0
  104. package/packages/tarijs/src/templates/Tariswap.ts +101 -0
  105. package/packages/tarijs/src/templates/TemplateFactory.ts +22 -0
  106. package/packages/tarijs/src/templates/TestFaucet.ts +72 -0
  107. package/{dist/utils.js → packages/tarijs/src/utils.ts} +4 -3
  108. package/packages/tarijs/tsconfig.json +39 -0
  109. package/packages/tarijs/vitest.config.ts +9 -0
  110. package/packages/tarijs_types/moon.yml +55 -0
  111. package/packages/tarijs_types/package.json +27 -0
  112. package/packages/tarijs_types/src/Amount.ts +113 -0
  113. package/packages/tarijs_types/src/Arg.ts +3 -0
  114. package/packages/tarijs_types/src/ComponentAddress.ts +3 -0
  115. package/packages/tarijs_types/src/ConfidentialClaim.ts +9 -0
  116. package/packages/tarijs_types/src/ConfidentialOutput.ts +9 -0
  117. package/packages/tarijs_types/src/ConfidentialOutputStatement.ts +10 -0
  118. package/packages/tarijs_types/src/ConfidentialStatement.ts +9 -0
  119. package/packages/tarijs_types/src/ConfidentialWithdrawProof.ts +8 -0
  120. package/packages/tarijs_types/src/ElgamalVerifiableBalance.ts +4 -0
  121. package/packages/tarijs_types/src/Epoch.ts +3 -0
  122. package/packages/tarijs_types/src/FinalizeResult.ts +17 -0
  123. package/packages/tarijs_types/src/Instruction.ts +29 -0
  124. package/packages/tarijs_types/src/ResourceAddress.ts +3 -0
  125. package/packages/tarijs_types/src/SubstateDiff.ts +9 -0
  126. package/packages/tarijs_types/src/SubstateRequirement.ts +6 -0
  127. package/packages/tarijs_types/src/TemplateAddress.ts +3 -0
  128. package/packages/tarijs_types/src/Transaction.ts +16 -0
  129. package/packages/tarijs_types/src/TransactionId.ts +4 -0
  130. package/packages/tarijs_types/src/TransactionResult.ts +26 -0
  131. package/packages/tarijs_types/src/TransactionSignature.ts +4 -0
  132. package/packages/tarijs_types/src/UnsignedTransaction.ts +15 -0
  133. package/packages/tarijs_types/src/VersionedSubstateId.ts +6 -0
  134. package/packages/tarijs_types/src/ViewableBalanceProof.ts +12 -0
  135. package/packages/tarijs_types/src/Workspace.ts +3 -0
  136. package/packages/tarijs_types/src/index.ts +25 -0
  137. package/packages/tarijs_types/tsconfig.json +15 -0
  138. package/packages/wallet_daemon/moon.yml +55 -0
  139. package/packages/wallet_daemon/package.json +29 -0
  140. package/packages/wallet_daemon/src/index.ts +5 -0
  141. package/packages/wallet_daemon/src/provider.ts +263 -0
  142. package/packages/wallet_daemon/src/webrtc.ts +229 -0
  143. package/packages/wallet_daemon/src/webrtc_transport.ts +27 -0
  144. package/packages/wallet_daemon/tsconfig.json +21 -0
  145. package/packages/walletconnect/moon.yml +55 -0
  146. package/packages/walletconnect/package.json +32 -0
  147. package/packages/walletconnect/src/index.ts +274 -0
  148. package/packages/walletconnect/tsconfig.json +21 -0
  149. package/pnpm-workspace.yaml +15 -0
  150. package/tsconfig.json +45 -0
  151. package/dist/index.d.ts +0 -14
  152. package/dist/index.js +0 -13
  153. package/dist/network.d.ts +0 -8
  154. package/dist/network.js +0 -9
  155. package/dist/templates/Account.d.ts +0 -65
  156. package/dist/templates/Account.js +0 -31
  157. package/dist/templates/Pool.d.ts +0 -29
  158. package/dist/templates/Pool.js +0 -20
  159. package/dist/templates/Tariswap.d.ts +0 -64
  160. package/dist/templates/Tariswap.js +0 -36
  161. package/dist/templates/TemplateFactory.d.ts +0 -9
  162. package/dist/templates/TemplateFactory.js +0 -18
  163. package/dist/templates/TestFaucet.d.ts +0 -49
  164. package/dist/templates/TestFaucet.js +0 -31
  165. package/dist/templates/index.js +0 -5
  166. package/dist/utils.d.ts +0 -2
  167. /package/{dist/templates/index.d.ts → packages/tarijs/src/templates/index.ts} +0 -0
@@ -0,0 +1,110 @@
1
+ ---
2
+ sidebar_position: 4
3
+ ---
4
+
5
+ # Get substate
6
+
7
+ It is possible to get substate details by substate address:
8
+
9
+ ```js
10
+ const substateAddress = "component_9cdad1188895b080885a64abb71a66a4a4cb1d8117679d85c8b35a4ec5d02243";
11
+ const substate = await provider.getSubstate(substateAddress);
12
+ ```
13
+
14
+ ```json
15
+ {
16
+ "value": {
17
+ "substate": {
18
+ "Component": {
19
+ "access_rules": {
20
+ "default": "AllowAll",
21
+ "method_access": {}
22
+ },
23
+ "body": {
24
+ "state": {
25
+ "Map": [
26
+ [
27
+ {
28
+ "Text": "vault"
29
+ },
30
+ {
31
+ "Tag": [
32
+ 132,
33
+ {
34
+ "Bytes": [
35
+ 156,
36
+ 218,
37
+ 209,
38
+ 24,
39
+ 136,
40
+ 149,
41
+ 176,
42
+ 128,
43
+ 136,
44
+ 90,
45
+ 100,
46
+ 171,
47
+ 183,
48
+ 26,
49
+ 102,
50
+ 164,
51
+ 164,
52
+ 203,
53
+ 29,
54
+ 129,
55
+ 22,
56
+ 248,
57
+ 9,
58
+ 1,
59
+ 100,
60
+ 31,
61
+ 71,
62
+ 132,
63
+ 87,
64
+ 88,
65
+ 252,
66
+ 4
67
+ ]
68
+ }
69
+ ]
70
+ }
71
+ ]
72
+ ]
73
+ }
74
+ },
75
+ "entity_id": [
76
+ 156,
77
+ 218,
78
+ 209,
79
+ 24,
80
+ 136,
81
+ 149,
82
+ 176,
83
+ 128,
84
+ 136,
85
+ 90,
86
+ 100,
87
+ 171,
88
+ 183,
89
+ 26,
90
+ 102,
91
+ 164,
92
+ 164,
93
+ 203,
94
+ 29,
95
+ 129
96
+ ],
97
+ "module_name": "TestFaucet",
98
+ "owner_key": "a6534c991a5c034b2f81af809b9577fe6b5425f810de292c0a4d4d43793a8f50",
99
+ "owner_rule": "OwnedBySigner",
100
+ "template_address": "20a814546424dae7496451a170325ddaed52d118e4fcf46c1abd32b3d6ee8163"
101
+ }
102
+ },
103
+ "version": 0
104
+ },
105
+ "address": {
106
+ "substate_id": "component_9cdad1188895b080885a64abb71a66a4a4cb1d8117679d85c8b35a4ec5d02243",
107
+ "version": 0
108
+ }
109
+ }
110
+ ```
@@ -0,0 +1,69 @@
1
+ ---
2
+ sidebar_position: 3
3
+ ---
4
+
5
+ # List substates
6
+
7
+ In the Tari network, substates are discrete units of state within the Tari Digital Assets Network. Each substate encapsulates a specific piece of data—such as ownership records, smart contract states, or asset balances.
8
+ Substates follow a create-spend lifecycle, meaning they are created, referenced, and eventually consumed or modified according to network rules.
9
+
10
+ You can query substates using the `listSubstates` method of a `TariProvider`.
11
+
12
+ ```ts
13
+ listSubstates(
14
+ filter_by_template: string | null,
15
+ filter_by_type: SubstateType | null,
16
+ limit: number | null,
17
+ offset: number | null
18
+ ): Promise<ListSubstatesResponse>;
19
+ ```
20
+
21
+
22
+ ## List by template
23
+
24
+ ```js
25
+ const accountTemplate = "0000000000000000000000000000000000000000000000000000000000000000";
26
+ const accountSubstates = await provider.listSubstates(accountTemplate, null, 1, 0);
27
+ ```
28
+
29
+ The result could be similar to:
30
+
31
+ ```json
32
+ {
33
+ "substates": [
34
+ {
35
+ "substate_id": "component_24b679b98056c7ca7e3d9f9266fec928c7f29d35e7aec546ed69f532aff40710",
36
+ "module_name": "Account",
37
+ "version": 3,
38
+ "template_address": "0000000000000000000000000000000000000000000000000000000000000000"
39
+ }
40
+ ]
41
+ }
42
+ ```
43
+
44
+ ## List by substate type
45
+
46
+ ```js
47
+ const accountSubstatesByType = await provider.listSubstates(null, "Component", 2, 0);
48
+ ```
49
+
50
+ Output:
51
+
52
+ ```json
53
+ {
54
+ "substates": [
55
+ {
56
+ "substate_id": "component_24b679b98056c7ca7e3d9f9266fec928c7f29d35e7aec546ed69f532aff40710",
57
+ "module_name": "Account",
58
+ "version": 3,
59
+ "template_address": "0000000000000000000000000000000000000000000000000000000000000000"
60
+ },
61
+ {
62
+ "substate_id": "component_1120a9ce46a820a955580cd7d07ee6b93a2ce16ee1671e4dcefd72dfbd33a168",
63
+ "module_name": "TariswapIndex",
64
+ "version": 1,
65
+ "template_address": "60041a6b62a9aa5dbbcc99d8be3ac59765f619c522fd387906dd30c9a9a78d3f"
66
+ }
67
+ ]
68
+ }
69
+ ```
@@ -0,0 +1,8 @@
1
+ {
2
+ "label": "Submit transaction",
3
+ "position": 5,
4
+ "link": {
5
+ "type": "doc",
6
+ "id": "transactions-index"
7
+ }
8
+ }
@@ -0,0 +1,38 @@
1
+ ---
2
+ sidebar_position: 2
3
+ ---
4
+
5
+ # Build and execute a request
6
+
7
+ ## Build a transaction
8
+
9
+ After constructing an instance of the *Transaction Builder*, you can build a transaction as follows:
10
+
11
+ ```js
12
+ const transaction = builder.build();
13
+ ```
14
+
15
+ ## Build a transaction request
16
+
17
+ The transaction request has additional parameters. Therefore, you build it using `buildTransactionRequest`:
18
+
19
+ ```js
20
+ const isDryRun = false;
21
+ const inputRefs = undefined; // Obsolete
22
+ const network = Network.LocalNet;
23
+ const requiredSubstates = []; // Soon to be retired. Use `builder.withInputs()` instead.
24
+ const submitTransactionRequest = buildTransactionRequest(
25
+ transaction,
26
+ account.account_id,
27
+ requiredSubstates,
28
+ inputRefs,
29
+ isDryRun,
30
+ network
31
+ );
32
+ ```
33
+
34
+ ## Execute a transaction
35
+
36
+ ```js
37
+ const txResult = await submitAndWaitForTransaction(provider, submitTransactionRequest);
38
+ ```
@@ -0,0 +1,14 @@
1
+ ---
2
+ id: transactions-index
3
+ title: Submit Transaction
4
+ description: A detailed explanation of submitting transactions.
5
+ ---
6
+
7
+ # Submit transaction
8
+
9
+ The provider exposes the `submitTransaction` and `getTransactionResult` methods. The first submits the transaction, while the second polls the current status of the transaction using its ID. These methods are low-level, so it is recommended to use the transaction builder and other helpers instead.
10
+
11
+ ```ts
12
+ submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
13
+ getTransactionResult(transactionId: string): Promise<TransactionResult>;
14
+ ```
@@ -0,0 +1,8 @@
1
+ {
2
+ "label": "Transaction Builder",
3
+ "position": 1,
4
+ "link": {
5
+ "type": "doc",
6
+ "id": "transaction-builder-index"
7
+ }
8
+ }
@@ -0,0 +1,17 @@
1
+ ---
2
+ sidebar_position: 5
3
+ ---
4
+
5
+ # CallFunction
6
+
7
+ `callFunction` can be used to create instances of components or call other *static* methods.
8
+
9
+ ```js
10
+ builder = builder.callFunction(
11
+ {
12
+ templateAddress,
13
+ functionName: "new",
14
+ },
15
+ [1, 2, 3]
16
+ );
17
+ ```
@@ -0,0 +1,17 @@
1
+ ---
2
+ sidebar_position: 5
3
+ ---
4
+
5
+ # CallMethod
6
+
7
+ `callMethod` calls a method on an instance of a template—in other words, on a component.
8
+
9
+ ```js
10
+ const amount = 10;
11
+ const tokenResource = "resource_217d58767480fbaa48693e11de34baf7fd727e33ee7627f0c4e5b78def378e57";
12
+
13
+ builder = builder.callMethod({
14
+ componentAddress: account.address,
15
+ methodName: "withdraw",
16
+ }, [tokenResource, amount.toString()]);
17
+ ```
@@ -0,0 +1,28 @@
1
+ ---
2
+ sidebar_position: 4
3
+ ---
4
+
5
+ # Fee
6
+
7
+ Executing a transaction requires a fee. This fee can originate from sources other than the transaction sender's account.
8
+
9
+ ```js
10
+ const account = await provider.getAccount();
11
+ const fee = new Amount(2000);
12
+ builder = builder
13
+ .feeTransactionPayFromComponent(account.address, fee.getStringValue());
14
+ ```
15
+
16
+ Under the hood, `feeTransactionPayFromComponent` creates an instruction that calls the `pay_fee` method on a component.
17
+
18
+ ```js
19
+ builder.addFeeInstruction({
20
+ CallMethod: {
21
+ component_address: componentAddress,
22
+ method: "pay_fee",
23
+ args: [maxFee],
24
+ },
25
+ });
26
+ ```
27
+
28
+ You might need to take this explicit route if the fee payment method is named something other than `pay_fee`.