@tari-project/tarijs 0.4.1 → 0.5.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.
Files changed (108) hide show
  1. package/.github/workflows/ci.yml +2 -1
  2. package/.github/workflows/documentation-deploy.yml +44 -0
  3. package/.github/workflows/documentation-test-deploy.yml +20 -0
  4. package/.moon/workspace.yml +1 -0
  5. package/README.md +19 -0
  6. package/TODO.md +2 -6
  7. package/docusaurus/tari-docs/README.md +41 -0
  8. package/docusaurus/tari-docs/docs/index.md +21 -0
  9. package/docusaurus/tari-docs/docs/installation.md +27 -0
  10. package/docusaurus/tari-docs/docs/providers/_category_.json +8 -0
  11. package/docusaurus/tari-docs/docs/providers/indexer-provider.md +32 -0
  12. package/docusaurus/tari-docs/docs/signers/_category_.json +8 -0
  13. package/docusaurus/tari-docs/docs/signers/tari-universe.md +27 -0
  14. package/docusaurus/tari-docs/docs/signers/wallet-connect.md +51 -0
  15. package/docusaurus/tari-docs/docs/signers/wallet-daemon.md +37 -0
  16. package/docusaurus/tari-docs/docs/wallet/_category_.json +8 -0
  17. package/docusaurus/tari-docs/docs/wallet/default-account.md +51 -0
  18. package/docusaurus/tari-docs/docs/wallet/get-substate.md +110 -0
  19. package/docusaurus/tari-docs/docs/wallet/list-substates.md +68 -0
  20. package/docusaurus/tari-docs/docs/wallet/submit-transaction/_category_.json +8 -0
  21. package/docusaurus/tari-docs/docs/wallet/submit-transaction/build-execute-request.md +38 -0
  22. package/docusaurus/tari-docs/docs/wallet/submit-transaction/index.md +14 -0
  23. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/_category_.json +8 -0
  24. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-function.md +17 -0
  25. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-method.md +17 -0
  26. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/fee.md +28 -0
  27. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/index.md +426 -0
  28. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/inputs.md +24 -0
  29. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/instruction.md +108 -0
  30. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/min-max-epoch.md +19 -0
  31. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/raw-instructions.md +16 -0
  32. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/save-var.md +63 -0
  33. package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/transaction-internals.md +20 -0
  34. package/docusaurus/tari-docs/docs/wallet/template-definition.md +101 -0
  35. package/docusaurus/tari-docs/docusaurus.config.ts +108 -0
  36. package/docusaurus/tari-docs/moon.yml +41 -0
  37. package/docusaurus/tari-docs/package.json +49 -0
  38. package/docusaurus/tari-docs/sidebars.ts +7 -0
  39. package/docusaurus/tari-docs/src/components/HomepageFeatures/index.tsx +69 -0
  40. package/docusaurus/tari-docs/src/components/HomepageFeatures/styles.module.css +11 -0
  41. package/docusaurus/tari-docs/src/css/custom.css +30 -0
  42. package/docusaurus/tari-docs/src/pages/index.module.css +23 -0
  43. package/docusaurus/tari-docs/src/pages/index.tsx +44 -0
  44. package/docusaurus/tari-docs/static/.nojekyll +0 -0
  45. package/docusaurus/tari-docs/static/img/favicon.png +0 -0
  46. package/docusaurus/tari-docs/static/img/meta-image.png +0 -0
  47. package/docusaurus/tari-docs/static/img/tari/wallet-connect-1.png +0 -0
  48. package/docusaurus/tari-docs/static/img/tari/wallet-connect-2.png +0 -0
  49. package/docusaurus/tari-docs/static/img/tari/wallet-connect-3.png +0 -0
  50. package/docusaurus/tari-docs/static/img/tari-logo.svg +30 -0
  51. package/docusaurus/tari-docs/tsconfig.json +10 -0
  52. package/package.json +1 -1
  53. package/packages/builders/package.json +3 -3
  54. package/packages/builders/src/helpers/submitTransaction.ts +8 -8
  55. package/packages/builders/tsconfig.json +2 -4
  56. package/packages/indexer_provider/package.json +31 -0
  57. package/packages/indexer_provider/src/index.ts +2 -0
  58. package/packages/indexer_provider/src/provider.ts +105 -0
  59. package/packages/indexer_provider/src/transports/IndexerProviderClient.ts +144 -0
  60. package/packages/indexer_provider/src/transports/fetch.ts +46 -0
  61. package/packages/indexer_provider/src/transports/index.ts +3 -0
  62. package/packages/indexer_provider/src/transports/rpc.ts +19 -0
  63. package/packages/indexer_provider/tsconfig.json +22 -0
  64. package/packages/metamask_signer/moon.yml +55 -0
  65. package/packages/{metamask_provider → metamask_signer}/package.json +3 -3
  66. package/packages/{metamask_provider → metamask_signer}/src/index.ts +11 -6
  67. package/packages/metamask_signer/tsconfig.json +19 -0
  68. package/packages/tari_permissions/package.json +2 -3
  69. package/packages/tari_permissions/src/helpers.ts +33 -0
  70. package/packages/tari_permissions/src/index.ts +2 -1
  71. package/packages/tari_permissions/src/tari_permissions.ts +59 -42
  72. package/packages/tari_provider/package.json +1 -1
  73. package/packages/tari_provider/src/TariProvider.ts +7 -23
  74. package/packages/tari_provider/src/index.ts +1 -2
  75. package/packages/tari_provider/src/types.ts +38 -24
  76. package/packages/tari_signer/moon.yml +55 -0
  77. package/packages/tari_signer/package.json +28 -0
  78. package/packages/tari_signer/src/TariSigner.ts +35 -0
  79. package/packages/tari_signer/src/index.ts +2 -0
  80. package/packages/tari_signer/src/types.ts +84 -0
  81. package/packages/{metamask_provider → tari_signer}/tsconfig.json +0 -3
  82. package/packages/tari_universe/package.json +3 -3
  83. package/packages/tari_universe/src/index.ts +1 -1
  84. package/packages/tari_universe/src/{provider.ts → signer.ts} +32 -33
  85. package/packages/tari_universe/src/types.ts +15 -10
  86. package/packages/tari_universe/src/utils.ts +8 -8
  87. package/packages/tari_universe/tsconfig.json +2 -4
  88. package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +44 -44
  89. package/packages/tarijs/moon.yml +8 -0
  90. package/packages/tarijs/package.json +9 -6
  91. package/packages/tarijs/src/cbor.spec.ts +259 -0
  92. package/packages/tarijs/src/cbor.ts +114 -0
  93. package/packages/tarijs/src/index.ts +31 -15
  94. package/packages/tarijs/tsconfig.json +7 -1
  95. package/packages/tarijs_types/package.json +1 -1
  96. package/packages/tarijs_types/src/helpers/index.ts +62 -0
  97. package/packages/tarijs_types/src/index.ts +12 -1
  98. package/packages/wallet_daemon/package.json +4 -3
  99. package/packages/wallet_daemon/src/index.ts +1 -1
  100. package/packages/wallet_daemon/src/{provider.ts → signer.ts} +45 -47
  101. package/packages/wallet_daemon/tsconfig.json +4 -1
  102. package/packages/walletconnect/package.json +4 -3
  103. package/packages/walletconnect/src/index.ts +42 -43
  104. package/packages/walletconnect/tsconfig.json +4 -1
  105. package/pnpm-workspace.yaml +4 -3
  106. package/tsconfig.json +11 -2
  107. /package/packages/{metamask_provider → indexer_provider}/moon.yml +0 -0
  108. /package/packages/{metamask_provider → metamask_signer}/src/utils.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
+ }
@@ -1,3 +1,4 @@
1
+ import { TariSigner } from "@tari-project/tari-signer";
1
2
  import { TariProvider } from "@tari-project/tari-provider";
2
3
  import * as utils from "./utils";
3
4
  import { Network } from "./network";
@@ -12,17 +13,13 @@ import {
12
13
  TemplateDefinition,
13
14
  SubstateRequirement,
14
15
  Substate,
15
- } from "@tari-project/tari-provider";
16
- import { MetamaskTariProvider } from "@tari-project/metamask-provider";
16
+ } from "@tari-project/tari-signer";
17
+ import { MetamaskTariSigner } from "@tari-project/metamask-signer";
17
18
  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";
19
+ import { WalletDaemonTariSigner, WalletDaemonParameters, TariPermissions } from "@tari-project/wallet-daemon-signer";
20
+ import { TariUniverseSigner, TariUniverseSignerParameters } from "@tari-project/tari-universe-signer";
24
21
  import * as permissions from "@tari-project/tari-permissions";
25
- import { WalletConnectTariProvider } from "@tari-project/wallet-connect-provider";
22
+ import { WalletConnectTariSigner } from "@tari-project/wallet-connect-signer";
26
23
  import {
27
24
  TransactionBuilder,
28
25
  TransactionRequest,
@@ -33,11 +30,21 @@ import {
33
30
  toWorkspace,
34
31
  } from "@tari-project/tarijs-builders";
35
32
  import * as templates from "./templates";
33
+ import { parseCbor, getCborValueByPath } from "./cbor";
34
+ import { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
35
+ import {
36
+ convertStringToTransactionStatus,
37
+ convertHexStringToU256Array,
38
+ convertU256ToHexString,
39
+ createNftAddressFromResource,
40
+ createNftAddressFromToken,
41
+ } from "@tari-project/tarijs-types";
36
42
 
37
43
  export * from "@tari-project/tarijs-types";
38
44
  export {
39
45
  utils,
40
46
  Network,
47
+ TariSigner,
41
48
  TariProvider,
42
49
  Account,
43
50
  TransactionStatus,
@@ -48,22 +55,31 @@ export {
48
55
  VaultData,
49
56
  TemplateDefinition,
50
57
  SubstateRequirement,
51
- MetamaskTariProvider,
52
- WalletDaemonTariProvider,
58
+ MetamaskTariSigner,
59
+ WalletDaemonTariSigner,
53
60
  WalletDaemonParameters,
54
- TariUniverseProvider,
55
- TariUniverseProviderParameters,
61
+ TariUniverseSigner,
62
+ TariUniverseSignerParameters,
56
63
  TariPermissions,
57
64
  MetaMaskInpageProvider,
58
65
  Substate,
59
- permissions,
60
- WalletConnectTariProvider,
66
+ WalletConnectTariSigner,
61
67
  TransactionBuilder,
62
68
  TransactionRequest,
69
+ IndexerProvider,
70
+ IndexerProviderParameters,
71
+ convertStringToTransactionStatus,
63
72
  buildTransactionRequest,
64
73
  submitAndWaitForTransaction,
65
74
  waitForTransactionResult,
66
75
  fromWorkspace,
67
76
  toWorkspace,
77
+ convertHexStringToU256Array,
78
+ convertU256ToHexString,
79
+ createNftAddressFromResource,
80
+ createNftAddressFromToken,
81
+ permissions,
68
82
  templates,
83
+ parseCbor,
84
+ getCborValueByPath,
69
85
  };
@@ -15,7 +15,10 @@
15
15
  "path": "../builders"
16
16
  },
17
17
  {
18
- "path": "../metamask_provider"
18
+ "path": "../indexer_provider"
19
+ },
20
+ {
21
+ "path": "../metamask_signer"
19
22
  },
20
23
  {
21
24
  "path": "../tari_permissions"
@@ -23,6 +26,9 @@
23
26
  {
24
27
  "path": "../tari_provider"
25
28
  },
29
+ {
30
+ "path": "../tari_signer"
31
+ },
26
32
  {
27
33
  "path": "../tari_universe"
28
34
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs-types",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -0,0 +1,62 @@
1
+ import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
2
+ import { TransactionStatus } from "../TransactionResult";
3
+
4
+ export function convertStringToTransactionStatus(status: string): TransactionStatus {
5
+ switch (status) {
6
+ case "New":
7
+ return TransactionStatus.New;
8
+ case "DryRun":
9
+ return TransactionStatus.DryRun;
10
+ case "Pending":
11
+ return TransactionStatus.Pending;
12
+ case "Accepted":
13
+ return TransactionStatus.Accepted;
14
+ case "Rejected":
15
+ return TransactionStatus.Rejected;
16
+ case "InvalidTransaction":
17
+ return TransactionStatus.InvalidTransaction;
18
+ case "OnlyFeeAccepted":
19
+ return TransactionStatus.OnlyFeeAccepted;
20
+ default:
21
+ throw new Error(`Unknown status: ${status}`);
22
+ }
23
+ }
24
+
25
+ // Function to create the Nft address
26
+ // address format: nft_RESOURCEADDR_uuid_TOKENID
27
+ export function createNftAddressFromToken(token: NonFungibleToken): string {
28
+ return createNftAddressFromResource(token.resource_address, token.nft_id);
29
+ }
30
+
31
+ export function convertU256ToHexString(id: NonFungibleId): string {
32
+ if ("U256" in id && Array.isArray(id.U256)) {
33
+ return id.U256.map((num) => num.toString(16).padStart(2, "0")).join("");
34
+ }
35
+ return "";
36
+ }
37
+
38
+ export function convertHexStringToU256Array(hexString: string): number[] {
39
+ const cleanHexString = hexString.replace(/[^0-9a-fA-F]/g, "");
40
+ const u256Array: number[] = [];
41
+
42
+ for (let i = 0; i < cleanHexString.length; i += 2) {
43
+ const hexPair = cleanHexString.slice(i, i + 2);
44
+ u256Array.push(parseInt(hexPair, 16));
45
+ }
46
+
47
+ return u256Array;
48
+ }
49
+
50
+ export function createNftAddressFromResource(address: ResourceAddress, tokenId: NonFungibleId): string {
51
+ let nftAddress = "nft_";
52
+
53
+ const resourceAddress = address.replace(/^resource_/, "");
54
+ nftAddress += resourceAddress;
55
+
56
+ nftAddress += "_uuid_";
57
+
58
+ const nftIdHexString = convertU256ToHexString(tokenId);
59
+ nftAddress += nftIdHexString;
60
+
61
+ return nftAddress;
62
+ }
@@ -9,7 +9,11 @@ export { ConfidentialStatement } from "./ConfidentialStatement";
9
9
  export { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
10
10
  export { Epoch } from "./Epoch";
11
11
  export {
12
- FinalizeResult, FinalizeResultStatus, TxResultAccept, TxResultAcceptFeeRejectRest, TxResultReject,
12
+ FinalizeResult,
13
+ FinalizeResultStatus,
14
+ TxResultAccept,
15
+ TxResultAcceptFeeRejectRest,
16
+ TxResultReject,
13
17
  } from "./FinalizeResult";
14
18
  export { ResourceAddress } from "./ResourceAddress";
15
19
  export { Instruction } from "./Instruction";
@@ -23,3 +27,10 @@ export { UnsignedTransaction } from "./UnsignedTransaction";
23
27
  export { VersionedSubstateId } from "./VersionedSubstateId";
24
28
  export { ViewableBalanceProof } from "./ViewableBalanceProof";
25
29
  export { WorkspaceArg } from "./Workspace";
30
+ export {
31
+ convertHexStringToU256Array,
32
+ convertStringToTransactionStatus,
33
+ convertU256ToHexString,
34
+ createNftAddressFromResource,
35
+ createNftAddressFromToken,
36
+ } from "./helpers";
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "@tari-project/wallet-daemon-provider",
3
- "version": "0.4.0",
2
+ "name": "@tari-project/wallet-daemon-signer",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -14,7 +14,8 @@
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
16
  "@tari-project/tari-permissions": "workspace:^",
17
- "@tari-project/tari-provider": "workspace:^",
17
+ "@tari-project/tari-signer": "workspace:^",
18
+ "@tari-project/tarijs-types": "workspace:^",
18
19
  "@tari-project/wallet_jrpc_client": "catalog:"
19
20
  },
20
21
  "devDependencies": {
@@ -2,4 +2,4 @@ export { TariConnection } from "./webrtc";
2
2
 
3
3
 
4
4
  export * from "@tari-project/tari-permissions";
5
- export * from "./provider";
5
+ export * from "./signer";