@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,259 @@
1
+ import { assert, describe, expect, it, vi } from "vitest";
2
+ import { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
3
+
4
+ describe("convertTaggedValue", () => {
5
+ it.each([
6
+ {
7
+ tag: BinaryTag.VaultId,
8
+ value: { Bytes: [1, 2, 3, 4, 255] },
9
+ expected: "vault_01020304ff",
10
+ },
11
+ {
12
+ tag: BinaryTag.ComponentAddress,
13
+ value: { Bytes: [1, 2, 3, 4, 255] },
14
+ expected: "component_01020304ff",
15
+ },
16
+ {
17
+ tag: BinaryTag.ResourceAddress,
18
+ value: { Bytes: [1, 2, 3, 4, 255] },
19
+ expected: "resource_01020304ff",
20
+ },
21
+ ])("converts tags with bytes into a string representation", ({ tag, value, expected }) => {
22
+ expect(convertTaggedValue(tag, value)).toEqual(expected);
23
+ });
24
+
25
+ it.each([
26
+ {
27
+ tag: BinaryTag.Metadata,
28
+ value: { Array: [{ Text: "One" }, { Text: "Two" }] },
29
+ expected: ["metadata", ["One", "Two"]],
30
+ },
31
+ {
32
+ tag: BinaryTag.Metadata,
33
+ value: {
34
+ Map: [
35
+ [{ Text: "key1" }, { Integer: 5 }],
36
+ [{ Text: "key2" }, { Integer: 3 }],
37
+ ],
38
+ },
39
+ expected: ["metadata", { key1: 5, key2: 3 }],
40
+ },
41
+ ])(
42
+ "converts other values into a tuple",
43
+ ({ tag, value, expected }: { tag: BinaryTag; value: unknown; expected: unknown }) => {
44
+ expect(convertTaggedValue(tag, value as CborValue)).toEqual(expected);
45
+ },
46
+ );
47
+
48
+ it("falls back to 'unknown' for unknown tags", () => {
49
+ expect(convertTaggedValue(55, { Bool: true })).toEqual(["unknown", true]);
50
+ });
51
+ });
52
+
53
+ describe("parseCbor", () => {
54
+ describe("Null", () => {
55
+ it("returns null", () => {
56
+ expect(parseCbor("Null")).toBeNull();
57
+ });
58
+ });
59
+
60
+ describe("Integer", () => {
61
+ it.each([
62
+ {
63
+ value: { Integer: 5 },
64
+ expected: 5,
65
+ },
66
+ {
67
+ value: { Integer: 3 },
68
+ expected: 3,
69
+ },
70
+ ])("returns an integer", ({ value, expected }) => {
71
+ expect(parseCbor(value)).toEqual(expected);
72
+ });
73
+ });
74
+
75
+ describe("Float", () => {
76
+ it.each([
77
+ {
78
+ value: { Float: 3.9 },
79
+ expected: 3.9,
80
+ },
81
+ {
82
+ value: { Float: 3 },
83
+ expected: 3,
84
+ },
85
+ ])("returns a number", ({ value, expected }) => {
86
+ expect(parseCbor(value)).toEqual(expected);
87
+ });
88
+ });
89
+
90
+ describe("Text", () => {
91
+ it.each([
92
+ {
93
+ value: { Text: "Some text" },
94
+ expected: "Some text",
95
+ },
96
+ {
97
+ value: { Text: "DEF" },
98
+ expected: "DEF",
99
+ },
100
+ ])("returns a string", ({ value, expected }) => {
101
+ expect(parseCbor(value)).toEqual(expected);
102
+ });
103
+ });
104
+
105
+ describe("Bytes", () => {
106
+ it.each([
107
+ {
108
+ value: { Bytes: [1, 2, 0xff] },
109
+ expected: Uint8Array.from([1, 2, 0xff]),
110
+ },
111
+ {
112
+ value: { Bytes: [] },
113
+ expected: new Uint8Array(),
114
+ },
115
+ ])("returns Uint8Array", ({ value, expected }) => {
116
+ expect(parseCbor(value)).toEqual(expected);
117
+ });
118
+ });
119
+
120
+ describe("Bool", () => {
121
+ it.each([
122
+ {
123
+ value: { Bool: true },
124
+ expected: true,
125
+ },
126
+ {
127
+ value: { Bool: false },
128
+ expected: false,
129
+ },
130
+ ])("returns a boolean", ({ value, expected }) => {
131
+ expect(parseCbor(value)).toEqual(expected);
132
+ });
133
+ });
134
+
135
+ describe("Tag", () => {
136
+ it.each([
137
+ {
138
+ value: {
139
+ Tag: [BinaryTag.VaultId, { Bytes: [1, 2, 3, 4, 255] }],
140
+ },
141
+ expected: "vault_01020304ff",
142
+ },
143
+ {
144
+ value: { Tag: [BinaryTag.Metadata, { Array: [{ Text: "One" }, { Text: "Two" }] }] },
145
+ expected: ["metadata", ["One", "Two"]],
146
+ },
147
+ ])("returns a tag representation", ({ value, expected }: { value: unknown; expected: unknown }) => {
148
+ expect(parseCbor(value as CborValue)).toEqual(expected);
149
+ });
150
+ });
151
+
152
+ describe("Array", () => {
153
+ it.each([
154
+ {
155
+ value: {
156
+ Array: [{ Integer: 5 }, { Float: 3.9 }, { Text: "Some text" }, { Bytes: [1, 2, 0xff] }, { Bool: true }],
157
+ },
158
+ expected: [5, 3.9, "Some text", Uint8Array.from([1, 2, 0xff]), true],
159
+ },
160
+ ])("returns an array", ({ value, expected }) => {
161
+ expect(parseCbor(value)).toEqual(expected);
162
+ });
163
+ });
164
+
165
+ describe("Map", () => {
166
+ it.each([
167
+ {
168
+ value: {
169
+ Map: [
170
+ [{ Text: "key1" }, { Integer: 5 }],
171
+ [{ Text: "key2" }, { Float: 3.9 }],
172
+ [{ Text: "key3" }, { Text: "Some text" }],
173
+ [{ Text: "key4" }, { Bytes: [1, 2, 0xff] }],
174
+ [{ Text: "key5" }, { Bool: true }],
175
+ [{ Text: "key6" }, { Array: [{ Integer: 1 }, { Integer: 2 }] }],
176
+ [
177
+ { Text: "key_nested" },
178
+ {
179
+ Map: [
180
+ [{ Text: "nested1" }, { Text: "Nested text" }],
181
+ [{ Text: "nested2" }, { Integer: 2 }],
182
+ ],
183
+ },
184
+ ],
185
+ ],
186
+ },
187
+ expected: {
188
+ key1: 5,
189
+ key2: 3.9,
190
+ key3: "Some text",
191
+ key4: Uint8Array.from([1, 2, 0xff]),
192
+ key5: true,
193
+ key6: [1, 2],
194
+ key_nested: {
195
+ nested1: "Nested text",
196
+ nested2: 2,
197
+ },
198
+ },
199
+ },
200
+ ])("returns an object", ({ value, expected }: { value: unknown; expected: unknown }) => {
201
+ expect(parseCbor(value as CborValue)).toEqual(expected);
202
+ });
203
+ });
204
+
205
+ it.each([{}, { Unknown: 2 }])("throws, when data in unknown format is found", (value: unknown) => {
206
+ expect(() => parseCbor(value as CborValue)).toThrow();
207
+ });
208
+ });
209
+
210
+ describe("getCborValueByPath", () => {
211
+ it.each([
212
+ {
213
+ path: "$.key1",
214
+ expected: 5,
215
+ },
216
+ {
217
+ path: "$.key3",
218
+ expected: "Some text",
219
+ },
220
+ {
221
+ path: "$.key6.1",
222
+ expected: 2,
223
+ },
224
+ {
225
+ path: "$.key_nested.nested1",
226
+ expected: "Nested text",
227
+ },
228
+ {
229
+ path: "$.missing.path",
230
+ expected: null,
231
+ },
232
+ {
233
+ path: "$.key6.999",
234
+ expected: null,
235
+ },
236
+ ])("gets value by path", ({ path, expected }) => {
237
+ const cbor: CborValue = {
238
+ Map: [
239
+ [{ Text: "key1" }, { Integer: 5 }],
240
+ [{ Text: "key2" }, { Float: 3.9 }],
241
+ [{ Text: "key3" }, { Text: "Some text" }],
242
+ [{ Text: "key4" }, { Bytes: [1, 2, 0xff] }],
243
+ [{ Text: "key5" }, { Bool: true }],
244
+ [{ Text: "key6" }, { Array: [{ Integer: 1 }, { Integer: 2 }] }],
245
+ [
246
+ { Text: "key_nested" },
247
+ {
248
+ Map: [
249
+ [{ Text: "nested1" }, { Text: "Nested text" }],
250
+ [{ Text: "nested2" }, { Integer: 2 }],
251
+ ],
252
+ },
253
+ ],
254
+ ],
255
+ };
256
+
257
+ expect(getCborValueByPath(cbor, path)).toEqual(expected);
258
+ });
259
+ });
@@ -0,0 +1,114 @@
1
+ export type CborValue =
2
+ | { Map: Array<[CborValue, CborValue]> }
3
+ | { Array: CborValue[] }
4
+ | { Tag: [BinaryTag, CborValue] }
5
+ | { Bool: boolean }
6
+ | { Bytes: number[] }
7
+ | { Text: string }
8
+ | { Float: number }
9
+ | { Integer: number }
10
+ | "Null";
11
+
12
+ export function parseCbor(value: CborValue): unknown {
13
+ if (typeof value === "string") {
14
+ if (value === "Null") {
15
+ return null;
16
+ }
17
+ throw new Error("Unknown CBOR value type");
18
+ }
19
+ if ("Map" in value) {
20
+ return Object.fromEntries(value.Map.map(([k, v]) => [parseCbor(k), parseCbor(v)]));
21
+ } else if ("Array" in value) {
22
+ return value.Array.map(parseCbor);
23
+ } else if ("Tag" in value) {
24
+ const [type, data] = value.Tag;
25
+ return convertTaggedValue(type, data);
26
+ } else if ("Bool" in value) {
27
+ return value.Bool;
28
+ } else if ("Bytes" in value) {
29
+ return new Uint8Array(value.Bytes);
30
+ } else if ("Text" in value) {
31
+ return value.Text;
32
+ } else if ("Float" in value) {
33
+ return value.Float;
34
+ } else if ("Integer" in value) {
35
+ return value.Integer;
36
+ }
37
+ throw new Error("Unknown CBOR value type");
38
+ }
39
+
40
+ export function getCborValueByPath(cborRepr: CborValue | null, path: string): unknown {
41
+ if (!cborRepr) {
42
+ return null;
43
+ }
44
+ let value = cborRepr;
45
+ for (const part of path.split(".")) {
46
+ if (part == "$") {
47
+ continue;
48
+ }
49
+ if (typeof value !== "object") {
50
+ return null;
51
+ }
52
+ if ("Map" in value) {
53
+ const mapEntry = value.Map.find((v) => parseCbor(v[0]) === part)?.[1];
54
+ if (mapEntry) {
55
+ value = mapEntry;
56
+ continue;
57
+ } else {
58
+ return null;
59
+ }
60
+ }
61
+
62
+ if ("Array" in value) {
63
+ const arr = value.Array;
64
+ const index = parseInt(part);
65
+ if (!Number.isNaN(index) && Array.isArray(arr) && arr.length > index) {
66
+ value = arr[index];
67
+ continue;
68
+ }
69
+ }
70
+
71
+ return null;
72
+ }
73
+ return parseCbor(value);
74
+ }
75
+
76
+ function uint8ArrayToHex(bytes: Uint8Array): string {
77
+ return Array.from(bytes)
78
+ .map((byte) => byte.toString(16).padStart(2, "0"))
79
+ .join("");
80
+ }
81
+
82
+ export enum BinaryTag {
83
+ ComponentAddress = 128,
84
+ Metadata = 129,
85
+ NonFungibleAddress = 130,
86
+ ResourceAddress = 131,
87
+ VaultId = 132,
88
+ BucketId = 133,
89
+ TransactionReceipt = 134,
90
+ ProofId = 135,
91
+ UnclaimedConfidentialOutputAddress = 136,
92
+ TemplateAddress = 137,
93
+ ValidatorNodeFeePool = 138,
94
+ }
95
+
96
+ const BINARY_TAG_KEYS = new Map<BinaryTag, string>([
97
+ [BinaryTag.ComponentAddress, "component"],
98
+ [BinaryTag.Metadata, "metadata"],
99
+ [BinaryTag.NonFungibleAddress, "nft"],
100
+ [BinaryTag.ResourceAddress, "resource"],
101
+ [BinaryTag.VaultId, "vault"],
102
+ [BinaryTag.BucketId, "bucket"],
103
+ [BinaryTag.TransactionReceipt, "transaction-receipt"],
104
+ [BinaryTag.ProofId, "proof"],
105
+ [BinaryTag.UnclaimedConfidentialOutputAddress, "unclaimed-confidential-output-address"],
106
+ [BinaryTag.TemplateAddress, "template-address"],
107
+ [BinaryTag.ValidatorNodeFeePool, "validator-node-fee-pool"],
108
+ ]);
109
+
110
+ export function convertTaggedValue(type: number, value: CborValue): string | unknown {
111
+ const tag = BINARY_TAG_KEYS.get(type) ?? "unknown";
112
+ const decoded = parseCbor(value);
113
+ return decoded instanceof Uint8Array ? `${tag}_${uint8ArrayToHex(decoded)}` : [tag, decoded];
114
+ }
@@ -0,0 +1,72 @@
1
+ import { TariProvider } from "@tari-project/tari-provider";
2
+ import * as utils from "./utils";
3
+ import { Network } from "./network";
4
+ import {
5
+ Account,
6
+ TransactionStatus,
7
+ TransactionResult,
8
+ SubmitTransactionResponse,
9
+ SubmitTransactionRequest,
10
+ VaultBalances,
11
+ VaultData,
12
+ TemplateDefinition,
13
+ SubstateRequirement,
14
+ Substate,
15
+ } from "@tari-project/tari-provider";
16
+ import { MetamaskTariProvider } from "@tari-project/metamask-provider";
17
+ import { MetaMaskInpageProvider } from "@metamask/providers";
18
+ import {
19
+ WalletDaemonTariProvider,
20
+ WalletDaemonParameters,
21
+ TariPermissions,
22
+ } from "@tari-project/wallet-daemon-provider";
23
+ import { TariUniverseProvider, TariUniverseProviderParameters } from "@tari-project/tari-universe-provider";
24
+ import * as permissions from "@tari-project/tari-permissions";
25
+ import { WalletConnectTariProvider } from "@tari-project/wallet-connect-provider";
26
+ import {
27
+ TransactionBuilder,
28
+ TransactionRequest,
29
+ buildTransactionRequest,
30
+ submitAndWaitForTransaction,
31
+ waitForTransactionResult,
32
+ fromWorkspace,
33
+ toWorkspace,
34
+ } from "@tari-project/tarijs-builders";
35
+ import * as templates from "./templates";
36
+ import { parseCbor, getCborValueByPath } from "./cbor";
37
+
38
+ export * from "@tari-project/tarijs-types";
39
+ export {
40
+ utils,
41
+ Network,
42
+ TariProvider,
43
+ Account,
44
+ TransactionStatus,
45
+ TransactionResult,
46
+ SubmitTransactionResponse,
47
+ SubmitTransactionRequest,
48
+ VaultBalances,
49
+ VaultData,
50
+ TemplateDefinition,
51
+ SubstateRequirement,
52
+ MetamaskTariProvider,
53
+ WalletDaemonTariProvider,
54
+ WalletDaemonParameters,
55
+ TariUniverseProvider,
56
+ TariUniverseProviderParameters,
57
+ TariPermissions,
58
+ MetaMaskInpageProvider,
59
+ Substate,
60
+ permissions,
61
+ WalletConnectTariProvider,
62
+ TransactionBuilder,
63
+ TransactionRequest,
64
+ buildTransactionRequest,
65
+ submitAndWaitForTransaction,
66
+ waitForTransactionResult,
67
+ fromWorkspace,
68
+ toWorkspace,
69
+ templates,
70
+ parseCbor,
71
+ getCborValueByPath,
72
+ };
@@ -0,0 +1,8 @@
1
+ export enum Network {
2
+ MainNet = 0x00,
3
+ StageNet = 0x01,
4
+ NextNet = 0x02,
5
+ LocalNet = 0x10,
6
+ Igor = 0x24,
7
+ Esmeralda = 0x26,
8
+ }
@@ -0,0 +1,98 @@
1
+ import { ConfidentialWithdrawProof, NonFungibleId, ResourceAddress } from "@tari-project/typescript-bindings";
2
+ import { Amount } from "@tari-project/tarijs-types";
3
+ import { TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
4
+ import { TemplateFactory } from "./TemplateFactory";
5
+
6
+ /**
7
+ * Adds a fee instruction that calls the "take_fee" method on a component.
8
+ * This method must exist and return a Bucket with containing revealed confidential XTR resource.
9
+ * This allows the fee to originate from sources other than the transaction sender's account.
10
+ * The fee instruction will lock up the "max_fee" amount for the duration of the transaction.
11
+ * @param componentAddress
12
+ * @param maxFee
13
+ * @returns
14
+ */
15
+ interface PayFeeMethod extends TariMethodDefinition {
16
+ methodName: "pay_fee";
17
+ args?: [Amount];
18
+ }
19
+ // /**
20
+ // * Adds a fee instruction that calls the "take_fee_confidential" method on a component.
21
+ // * This method must exist and return a Bucket with containing revealed confidential XTR resource.
22
+ // * This allows the fee to originate from sources other than the transaction sender's account.
23
+ // * @param componentAddress
24
+ // * @param proof
25
+ // * @returns
26
+ // */
27
+ interface PayFeeConfidentialMethod extends TariMethodDefinition {
28
+ methodName: "pay_fee_confidential";
29
+ args?: [ConfidentialWithdrawProof];
30
+ }
31
+
32
+ interface WithdrawMethod extends TariMethodDefinition {
33
+ methodName: "withdraw";
34
+ args?: [string, Amount];
35
+ }
36
+
37
+ interface DepositMethod extends TariMethodDefinition {
38
+ methodName: "deposit";
39
+ args?: WorkspaceArg[];
40
+ }
41
+
42
+ interface CreateProofForResourceMethod extends TariMethodDefinition {
43
+ methodName: "create_proof_for_resource";
44
+ args?: [ResourceAddress];
45
+ }
46
+
47
+ interface CreateProofByAmountMethod extends TariMethodDefinition {
48
+ methodName: "create_proof_by_amount";
49
+ args?: [ResourceAddress, Amount];
50
+ }
51
+
52
+ interface CreateProofByNonFungibleIdsMethod extends TariMethodDefinition {
53
+ methodName: "create_proof_by_non_fungible_ids";
54
+ args?: [ResourceAddress, NonFungibleId[]];
55
+ }
56
+
57
+ interface BalanceMethod extends TariMethodDefinition {
58
+ methodName: "balance";
59
+ args?: [ResourceAddress];
60
+ }
61
+
62
+ interface GetBalancesMethod extends TariMethodDefinition {
63
+ methodName: "get_balances";
64
+ args?: [];
65
+ }
66
+
67
+ export class AccountTemplate extends TemplateFactory {
68
+ public deposit: DepositMethod;
69
+ public withdraw: WithdrawMethod;
70
+ public createProofByAmount: CreateProofByAmountMethod;
71
+ public createProofByNonFungibleIds: CreateProofByNonFungibleIdsMethod;
72
+ public createProofForResource: CreateProofForResourceMethod;
73
+ public balance: BalanceMethod;
74
+ public getBalances: GetBalancesMethod;
75
+ public payFee: PayFeeMethod;
76
+ public payFeeConfidential: PayFeeConfidentialMethod;
77
+
78
+ constructor(public templateAddress: string) {
79
+ super(templateAddress);
80
+ this._initFunctions();
81
+ this._initMethods();
82
+ }
83
+
84
+ protected _initFunctions(): void {}
85
+ protected _initMethods(): void {
86
+ this.deposit = this._defineMethod<DepositMethod>("deposit");
87
+ this.withdraw = this._defineMethod<WithdrawMethod>("withdraw");
88
+ this.createProofByAmount = this._defineMethod<CreateProofByAmountMethod>("create_proof_by_amount");
89
+ this.createProofByNonFungibleIds = this._defineMethod<CreateProofByNonFungibleIdsMethod>(
90
+ "create_proof_by_non_fungible_ids",
91
+ );
92
+ this.createProofForResource = this._defineMethod<CreateProofForResourceMethod>("create_proof_for_resource");
93
+ this.balance = this._defineMethod<BalanceMethod>("balance");
94
+ this.getBalances = this._defineMethod<GetBalancesMethod>("get_balances");
95
+ this.payFee = this._defineMethod<PayFeeMethod>("pay_fee");
96
+ this.payFeeConfidential = this._defineMethod<PayFeeConfidentialMethod>("pay_fee_confidential");
97
+ }
98
+ }
@@ -0,0 +1,42 @@
1
+ import { TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
2
+ import { TemplateFactory } from "./TemplateFactory";
3
+
4
+ interface CreatePool extends TariMethodDefinition {
5
+ methodName: "create_pool";
6
+ args?: [string, string];
7
+ }
8
+
9
+ interface AddLiquidityMethod extends TariMethodDefinition {
10
+ methodName: "add_liquidity";
11
+ args?: WorkspaceArg[];
12
+ }
13
+
14
+ interface RemoveLiquidityMethod extends TariMethodDefinition {
15
+ methodName: "remove_liquidity";
16
+ args?: WorkspaceArg[];
17
+ }
18
+
19
+ interface SwapMethod extends TariMethodDefinition {
20
+ methodName: "swap";
21
+ args?: (WorkspaceArg | string)[];
22
+ }
23
+
24
+ export class PoolTemplate extends TemplateFactory {
25
+ public createPool: CreatePool;
26
+ public addLiquidity: AddLiquidityMethod;
27
+ public removeLiquidity: RemoveLiquidityMethod;
28
+ public swap: SwapMethod;
29
+
30
+ constructor(public templateAddress: string) {
31
+ super(templateAddress);
32
+ this._initFunctions();
33
+ this._initMethods();
34
+ }
35
+
36
+ protected _initFunctions(): void {}
37
+ protected _initMethods(): void {
38
+ this.addLiquidity = this._defineMethod<AddLiquidityMethod>("add_liquidity");
39
+ this.removeLiquidity = this._defineMethod<RemoveLiquidityMethod>("remove_liquidity");
40
+ this.swap = this._defineMethod<SwapMethod>("swap");
41
+ }
42
+ }
@@ -0,0 +1,101 @@
1
+ import {
2
+ Amount,
3
+ ConfidentialWithdrawProof,
4
+ ResourceAddress,
5
+ TariFunctionDefinition,
6
+ TariMethodDefinition,
7
+ WorkspaceArg,
8
+ } from "@tari-project/tarijs-builders";
9
+ import { TemplateFactory } from "./TemplateFactory";
10
+
11
+ interface NewPoolFunction extends TariFunctionDefinition {
12
+ functionName: "new";
13
+ args?: [ResourceAddress, ResourceAddress, Amount];
14
+ }
15
+
16
+ interface MintFunction extends TariFunctionDefinition {
17
+ functionName: "mint";
18
+ args?: [Amount];
19
+ }
20
+
21
+ interface MintWithSymbolFunction extends TariFunctionDefinition {
22
+ functionName: "mint_with_symbol";
23
+ args?: [Amount, string];
24
+ }
25
+
26
+ interface PayFeeMethod extends TariMethodDefinition {
27
+ methodName: "pay_fee";
28
+ args?: [string];
29
+ }
30
+
31
+ interface PayFeeConfidentialMethod extends TariMethodDefinition {
32
+ methodName: "pay_fee_confidential";
33
+ args?: [ConfidentialWithdrawProof];
34
+ }
35
+
36
+ interface TotalSupplyMethod extends TariMethodDefinition {
37
+ methodName: "total_supply";
38
+ args?: [];
39
+ }
40
+
41
+ interface WithdrawMethod extends TariMethodDefinition {
42
+ methodName: "withdraw";
43
+ args?: [string, string];
44
+ }
45
+
46
+ interface AddLiquidityMethod extends TariMethodDefinition {
47
+ methodName: "add_liquidity";
48
+ args?: WorkspaceArg[];
49
+ }
50
+
51
+ interface RemoveLiquidityMethod extends TariMethodDefinition {
52
+ methodName: "remove_liquidity";
53
+ args?: WorkspaceArg[];
54
+ }
55
+
56
+ interface DepositMethod extends TariMethodDefinition {
57
+ methodName: "deposit";
58
+ args?: WorkspaceArg[];
59
+ }
60
+
61
+ interface SwapMethod extends TariMethodDefinition {
62
+ methodName: "swap";
63
+ args?: (WorkspaceArg | string)[];
64
+ }
65
+
66
+ export class TariswapTemplate extends TemplateFactory {
67
+ public newPool: NewPoolFunction;
68
+ public mint: MintFunction;
69
+ public mintWithSymbol: MintWithSymbolFunction;
70
+ public totalSupply: TotalSupplyMethod;
71
+ public payFee: PayFeeMethod;
72
+ public payFeeConfidential: PayFeeConfidentialMethod;
73
+ public withdraw: WithdrawMethod;
74
+ public addLiquidity: AddLiquidityMethod;
75
+ public removeLiquidity: RemoveLiquidityMethod;
76
+ public deposit: DepositMethod;
77
+ public swap: SwapMethod;
78
+
79
+ constructor(public templateAddress: string) {
80
+ super(templateAddress);
81
+ this._initFunctions();
82
+ this._initMethods();
83
+ }
84
+
85
+ protected _initFunctions(): void {
86
+ this.newPool = this._defineFunction<NewPoolFunction>("new");
87
+ this.mint = this._defineFunction<MintFunction>("mint");
88
+ this.mintWithSymbol = this._defineFunction<MintWithSymbolFunction>("mint_with_symbol");
89
+ }
90
+
91
+ protected _initMethods(): void {
92
+ this.totalSupply = this._defineMethod<TotalSupplyMethod>("total_supply");
93
+ this.payFee = this._defineMethod<PayFeeMethod>("pay_fee");
94
+ this.payFeeConfidential = this._defineMethod<PayFeeConfidentialMethod>("pay_fee_confidential");
95
+ this.withdraw = this._defineMethod<WithdrawMethod>("withdraw");
96
+ this.addLiquidity = this._defineMethod<AddLiquidityMethod>("add_liquidity");
97
+ this.removeLiquidity = this._defineMethod<RemoveLiquidityMethod>("remove_liquidity");
98
+ this.deposit = this._defineMethod<DepositMethod>("deposit");
99
+ this.swap = this._defineMethod<SwapMethod>("swap");
100
+ }
101
+ }