@tari-project/tarijs 0.12.1 → 0.13.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 (61) hide show
  1. package/.github/workflows/lint.yml +19 -0
  2. package/README.md +4 -1
  3. package/docusaurus/tari-docs/package.json +1 -1
  4. package/eslint.config.mjs +23 -6
  5. package/examples/vite-typescript-react/eslint.config.js +13 -10
  6. package/examples/vite-typescript-react/index.html +1 -1
  7. package/examples/vite-typescript-react/package.json +5 -6
  8. package/examples/vite-typescript-react/public/tari-logo.svg +18 -0
  9. package/examples/vite-typescript-react/tsconfig.json +2 -4
  10. package/knip.ts +18 -0
  11. package/package.json +7 -5
  12. package/packages/builders/package.json +3 -2
  13. package/packages/builders/src/helpers/submitTransaction.ts +11 -10
  14. package/packages/builders/src/helpers/workspace.ts +2 -2
  15. package/packages/builders/src/transaction/TransactionBuilder.ts +12 -13
  16. package/packages/indexer_provider/package.json +3 -2
  17. package/packages/indexer_provider/src/provider.ts +6 -7
  18. package/packages/indexer_provider/src/transports/IndexerProviderClient.ts +1 -0
  19. package/packages/indexer_provider/src/transports/fetch.ts +2 -2
  20. package/packages/indexer_provider/src/transports/rpc.ts +1 -0
  21. package/packages/metamask_signer/package.json +3 -2
  22. package/packages/metamask_signer/src/index.ts +24 -7
  23. package/packages/metamask_signer/src/utils.ts +36 -45
  24. package/packages/permissions/package.json +3 -2
  25. package/packages/permissions/src/helpers.ts +0 -1
  26. package/packages/permissions/src/permissions.ts +6 -13
  27. package/packages/react-mui-connect-button/package.json +3 -4
  28. package/packages/react-mui-connect-button/src/Logos.tsx +77 -48
  29. package/packages/react-mui-connect-button/src/TariConnectButton.tsx +1 -2
  30. package/packages/react-mui-connect-button/src/TariWalletSelectionDialog.tsx +64 -28
  31. package/packages/react-mui-connect-button/src/index.ts +6 -3
  32. package/packages/tari_provider/package.json +3 -2
  33. package/packages/tari_signer/package.json +3 -2
  34. package/packages/tari_signer/src/TariSigner.ts +7 -0
  35. package/packages/tari_universe/package.json +3 -2
  36. package/packages/tari_universe/src/signer.ts +16 -0
  37. package/packages/tari_universe/src/types.ts +1 -0
  38. package/packages/tarijs/package.json +3 -2
  39. package/packages/tarijs/src/index.ts +2 -20
  40. package/packages/tarijs/src/templates/TestFaucet.ts +7 -2
  41. package/packages/tarijs/test/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +6 -9
  42. package/packages/tarijs_types/package.json +3 -2
  43. package/packages/tarijs_types/src/SubmitTransactionResponse.ts +3 -0
  44. package/packages/tarijs_types/src/TransactionArg.ts +1 -0
  45. package/packages/tarijs_types/src/consts.ts +1 -1
  46. package/packages/tarijs_types/src/helpers/hexString.ts +20 -19
  47. package/packages/tarijs_types/src/helpers/simpleResult.ts +23 -20
  48. package/packages/tarijs_types/src/helpers/txResult.ts +3 -4
  49. package/packages/tarijs_types/src/index.ts +9 -4
  50. package/packages/tarijs_types/src/signer.ts +3 -6
  51. package/packages/wallet_daemon/package.json +3 -2
  52. package/packages/wallet_daemon/src/provider.ts +14 -16
  53. package/packages/wallet_daemon/src/signer.ts +38 -17
  54. package/packages/wallet_daemon/src/webrtc.ts +18 -13
  55. package/packages/walletconnect/package.json +6 -6
  56. package/packages/walletconnect/src/index.ts +60 -22
  57. package/pnpm-workspace.yaml +8 -8
  58. package/tsconfig.json +1 -1
  59. package/typedoc.json +3 -2
  60. package/packages/react-mui-connect-button/src/defaultPermissions.ts +0 -0
  61. package/packages/tarijs_types/src/TransactionResult.ts +0 -16
@@ -26,12 +26,12 @@ class SignalingServer {
26
26
  console.log("jsonRpc", method, token, params);
27
27
  let id = 0;
28
28
  id += 1;
29
- let address = this._server_url;
30
- let headers: { [key: string]: string } = { "Content-Type": "application/json" };
29
+ const address = this._server_url;
30
+ const headers: { [key: string]: string } = { "Content-Type": "application/json" };
31
31
  if (token) {
32
32
  headers["Authorization"] = `Bearer ${token}`;
33
33
  }
34
- let response = await fetch(address, {
34
+ const response = await fetch(address, {
35
35
  method: "POST",
36
36
  body: JSON.stringify({
37
37
  method: method,
@@ -41,7 +41,7 @@ class SignalingServer {
41
41
  }),
42
42
  headers: headers,
43
43
  });
44
- let json = await response.json();
44
+ const json = await response.json();
45
45
  if (json.error) {
46
46
  throw json.error;
47
47
  }
@@ -99,7 +99,7 @@ export class TariConnection {
99
99
  await this._signalingServer.initToken(permissions);
100
100
  // Setup our receiving end
101
101
  this._dataChannel.onmessage = (message) => {
102
- let response = JSON.parse(message.data);
102
+ const response = JSON.parse(message.data);
103
103
  console.log("response", response);
104
104
 
105
105
  if (!this._callbacks[response.id]) {
@@ -107,7 +107,7 @@ export class TariConnection {
107
107
  return;
108
108
  }
109
109
  // The response should contain id, to identify the Promise.resolve, that is waiting for this result
110
- let [resolve, reject] = this._callbacks[response.id];
110
+ const [resolve, reject] = this._callbacks[response.id];
111
111
  delete this._callbacks[response.id];
112
112
  if (response.payload?.error) {
113
113
  reject(new Error(response.payload.error));
@@ -119,8 +119,8 @@ export class TariConnection {
119
119
  // This should be removed before the release, but it's good for debugging.
120
120
  console.log("Data channel is open!");
121
121
 
122
- this.sendMessage({ id: 0, jsonrpc: "2.0", method: "get.token", params: {} }, this._signalingServer.token)
123
- .then((walletToken: unknown) => {
122
+ this.sendMessage({ id: 0, jsonrpc: "2.0", method: "get.token", params: {} }, this._signalingServer.token).then(
123
+ (walletToken: unknown) => {
124
124
  if (typeof walletToken !== "string") {
125
125
  throw Error("Received invalid JWT from wallet daemon");
126
126
  }
@@ -131,7 +131,8 @@ export class TariConnection {
131
131
  if (this.onConnection) {
132
132
  this.onConnection(this);
133
133
  }
134
- });
134
+ },
135
+ );
135
136
  };
136
137
  this._peerConnection.onicecandidate = (event) => {
137
138
  console.log("event", event);
@@ -160,13 +161,13 @@ export class TariConnection {
160
161
  private async setAnswer() {
161
162
  // This is called once the other end got the offer and ices and created and store an answer and its ice candidates
162
163
  // We get its answer sdp
163
- let sdp = await this._signalingServer.getAnswer();
164
+ const sdp = await this._signalingServer.getAnswer();
164
165
 
165
166
  // And its ice candidates
166
- let iceCandidates = await this._signalingServer.getIceCandidates();
167
+ const iceCandidates = await this._signalingServer.getIceCandidates();
167
168
 
168
169
  // For us the answer is remote sdp
169
- let answer = new RTCSessionDescription({ sdp, type: "answer" });
170
+ const answer = new RTCSessionDescription({ sdp, type: "answer" });
170
171
  this._peerConnection.setRemoteDescription(answer);
171
172
 
172
173
  // We add all the ice candidates to connect, the other end is doing the same with our ice candidates
@@ -199,7 +200,11 @@ export class TariConnection {
199
200
  }
200
201
 
201
202
  // If the last parameter has timeout property e.g. {timeout:1000}, it set the timeout for this call.
202
- async sendMessage<T>(request: transports.RpcRequest, token: string | undefined, timeout_secs: number | null = null): Promise<T> {
203
+ async sendMessage<T>(
204
+ request: transports.RpcRequest,
205
+ token: string | undefined,
206
+ timeout_secs: number | null = null,
207
+ ): Promise<T> {
203
208
  if (!this.isConnected) {
204
209
  throw new Error("WALLET_DAEMON_NOT_CONNECTED");
205
210
  }
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@tari-project/wallet-connect-signer",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "scripts": {
10
- "build": "tsc -b"
10
+ "build": "tsc -b",
11
+ "lint": "eslint src/"
11
12
  },
12
13
  "keywords": [],
13
14
  "author": "The Tari Community",
14
15
  "license": "ISC",
15
16
  "dependencies": {
17
+ "@reown/appkit": "catalog:",
18
+ "@tari-project/tari-permissions": "workspace:",
16
19
  "@tari-project/tari-signer": "workspace:^",
17
- "@tari-project/tarijs-builders": "workspace:^",
20
+ "@tari-project/tarijs-builders": "workspace:*",
18
21
  "@tari-project/tarijs-types": "workspace:^",
19
22
  "@tari-project/typescript-bindings": "catalog:",
20
- "@tari-project/wallet_jrpc_client": "catalog:",
21
- "@tari-project/tari-permissions": "workspace:",
22
- "@walletconnect/modal": "catalog:",
23
23
  "@walletconnect/universal-provider": "catalog:"
24
24
  },
25
25
  "devDependencies": {
@@ -1,6 +1,7 @@
1
1
  import { TariSigner } from "@tari-project/tari-signer";
2
2
  import UniversalProvider from "@walletconnect/universal-provider";
3
- import { WalletConnectModal } from "@walletconnect/modal";
3
+ import { AppKitNetwork, mainnet, sepolia } from "@reown/appkit/networks";
4
+ import { createAppKit } from "@reown/appkit/core";
4
5
  import {
5
6
  convertStringToTransactionStatus,
6
7
  GetTransactionResultResponse,
@@ -14,12 +15,16 @@ import {
14
15
  SubmitTransactionResponse,
15
16
  } from "@tari-project/tarijs-types";
16
17
  import {
18
+ AccountGetResponse,
19
+ AccountsListRequest,
20
+ AccountsListResponse,
17
21
  ConfidentialViewVaultBalanceRequest,
18
22
  KeyBranch,
19
23
  ListAccountNftRequest,
20
24
  ListAccountNftResponse,
21
25
  substateIdToString,
22
26
  TransactionSubmitRequest,
27
+ WalletGetInfoResponse,
23
28
  } from "@tari-project/typescript-bindings";
24
29
  import { TariPermission } from "@tari-project/tari-permissions";
25
30
 
@@ -38,6 +43,7 @@ const walletConnectParams = {
38
43
  "tari_createFreeTestCoins",
39
44
  "tari_listSubstates",
40
45
  "tari_getNftsList",
46
+ "tari_getWalletInfo",
41
47
  ],
42
48
  chains: ["tari:devnet"],
43
49
  events: [],
@@ -69,41 +75,54 @@ export class WalletConnectTariSigner implements TariSigner {
69
75
  }
70
76
 
71
77
  async connect(): Promise<() => Promise<void>> {
72
- if (this.wcProvider && this.wcSession) return async () => {
73
- // No-op if already connected
78
+ if (this.wcProvider && this.wcSession)
79
+ return async () => {
80
+ // No-op if already connected
81
+ };
82
+
83
+ const metadata = {
84
+ name: "Tari Universe",
85
+ description: "Tari Universe Wallet",
86
+ url: "https://www.tari.com",
87
+ icons: ["https://tari.com/assets/img/node-icon-alt.svg"],
74
88
  };
75
89
 
76
- // initialize WalletConnect
77
90
  const projectId = this.params.projectId;
78
91
  const provider = await UniversalProvider.init({
79
92
  projectId,
80
93
  // TODO: parameterize the relay URL
81
94
  // relayUrl: "wss://relay.walletconnect.com",
95
+ metadata,
82
96
  });
83
97
 
84
98
  const sessionProperties = {
85
- "required_permissions": JSON.stringify(this.params.requiredPermissions) || "[]",
86
- "optional_permissions": JSON.stringify(this.params.optionalPermissions) || "[]",
99
+ required_permissions: JSON.stringify(this.params.requiredPermissions) || "[]",
100
+ optional_permissions: JSON.stringify(this.params.optionalPermissions) || "[]",
87
101
  };
88
102
  const connectParams = {
89
103
  ...walletConnectParams,
90
104
  sessionProperties,
91
105
  };
92
106
 
93
- // open UI modal with the connection URI
107
+ const networks: [AppKitNetwork, ...AppKitNetwork[]] = [mainnet, sepolia];
108
+
94
109
  const { uri, approval } = await provider.client.connect(connectParams);
95
110
  return async () => {
96
- const walletConnectModal = new WalletConnectModal({
97
- projectId,
111
+ const walletConnectModal = createAppKit({
112
+ projectId: projectId,
113
+ networks: networks,
114
+ universalProvider: provider,
115
+ manualWCControl: true,
98
116
  });
117
+
99
118
  if (uri) {
100
- await walletConnectModal.openModal({ uri });
119
+ await walletConnectModal.open({ uri });
101
120
  }
102
121
 
103
122
  // wait for the wallet to approve the connection
104
123
  console.log("waiting for session approval from the wallet app");
105
124
  const session = await approval();
106
- walletConnectModal.closeModal();
125
+ walletConnectModal.close();
107
126
 
108
127
  // at this point session is open
109
128
  console.log("session approved by the wallet");
@@ -140,6 +159,11 @@ export class WalletConnectTariSigner implements TariSigner {
140
159
  return this.wcSession !== null;
141
160
  }
142
161
 
162
+ async accountsList(req: AccountsListRequest): Promise<AccountsListResponse> {
163
+ const res = await this.sendRequest("tari_accountsList", req);
164
+ return res as AccountsListResponse;
165
+ }
166
+
143
167
  async getAccount(): Promise<AccountData> {
144
168
  const { account, public_key } = await this.sendRequest("tari_getDefaultAccount", {});
145
169
  const { balances } = await this.sendRequest("tari_getAccountBalances", {
@@ -163,6 +187,15 @@ export class WalletConnectTariSigner implements TariSigner {
163
187
  };
164
188
  }
165
189
 
190
+ async getAccountByAddress(address: string): Promise<AccountGetResponse> {
191
+ const res = await this.sendRequest("tari_getAccountByAddress", {
192
+ name_or_address: {
193
+ ComponentAddress: address,
194
+ },
195
+ });
196
+ return res as AccountGetResponse;
197
+ }
198
+
166
199
  async getSubstate(substate_address: string): Promise<Substate> {
167
200
  const method = "tari_getSubstate";
168
201
  const params = { substate_id: substate_address };
@@ -177,11 +210,11 @@ export class WalletConnectTariSigner implements TariSigner {
177
210
  }
178
211
 
179
212
  public async listSubstates({
180
- filter_by_template,
181
- filter_by_type,
182
- limit,
183
- offset,
184
- }: ListSubstatesRequest): Promise<ListSubstatesResponse> {
213
+ filter_by_template,
214
+ filter_by_type,
215
+ limit,
216
+ offset,
217
+ }: ListSubstatesRequest): Promise<ListSubstatesResponse> {
185
218
  const method = "tari_listSubstates";
186
219
  const params = {
187
220
  filter_by_template,
@@ -245,7 +278,7 @@ export class WalletConnectTariSigner implements TariSigner {
245
278
  }
246
279
 
247
280
  async getTemplateDefinition(template_address: string): Promise<TemplateDefinition> {
248
- let resp = await this.sendRequest("tari_getTemplate", { template_address });
281
+ const resp = await this.sendRequest("tari_getTemplate", { template_address });
249
282
  return resp.template_definition as TemplateDefinition;
250
283
  }
251
284
 
@@ -255,11 +288,11 @@ export class WalletConnectTariSigner implements TariSigner {
255
288
  }
256
289
 
257
290
  async getConfidentialVaultBalances({
258
- vault_id,
259
- view_key_id,
260
- maximum_expected_value = null,
261
- minimum_expected_value = null,
262
- }: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances> {
291
+ vault_id,
292
+ view_key_id,
293
+ maximum_expected_value = null,
294
+ minimum_expected_value = null,
295
+ }: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances> {
263
296
  const method = "tari_viewConfidentialVaultBalance";
264
297
  const params = {
265
298
  view_key_id,
@@ -282,4 +315,9 @@ export class WalletConnectTariSigner implements TariSigner {
282
315
  const res = await this.sendRequest(method, params);
283
316
  return res as ListAccountNftResponse;
284
317
  }
318
+
319
+ public async getWalletInfo(): Promise<WalletGetInfoResponse> {
320
+ const res = await this.sendRequest("tari_getWalletInfo", {});
321
+ return res as WalletGetInfoResponse;
322
+ }
285
323
  }
@@ -3,21 +3,21 @@ packages:
3
3
  - apps/*
4
4
  - docusaurus/*
5
5
  - examples/*
6
- - '!**/test/**'
6
+ - "!**/test/**"
7
7
 
8
8
  catalog:
9
9
  typescript: ^5.0.4
10
10
  vitest: ^3.0.4
11
11
  vite: ^6.1.0
12
- '@types/node': ^22.13.1
13
- '@tari-project/typescript-bindings': '>=1.14.0'
14
- '@tari-project/wallet_jrpc_client': ^1.7.2
15
- '@metamask/providers': ^18.2.0
16
- '@walletconnect/universal-provider': ^2.13.3
17
- '@walletconnect/modal': ^2.6.2
12
+ "@types/node": ^22.13.1
13
+ "@tari-project/typescript-bindings": ">=1.15.0"
14
+ "@tari-project/wallet_jrpc_client": ^1.7.2
15
+ "@metamask/providers": ^18.2.0
16
+ "@walletconnect/universal-provider": 2.21.3
17
+ "@reown/appkit": "1.7.15"
18
18
 
19
19
  onlyBuiltDependencies:
20
- - '@moonrepo/cli'
20
+ - "@moonrepo/cli"
21
21
  - core-js
22
22
  - core-js-pure
23
23
  - esbuild
package/tsconfig.json CHANGED
@@ -27,7 +27,7 @@
27
27
  "path": "packages/react-mui-connect-button"
28
28
  },
29
29
  {
30
- "path": "packages/tari_permissions"
30
+ "path": "packages/permissions"
31
31
  },
32
32
  {
33
33
  "path": "packages/tari_provider"
package/typedoc.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
- "entryPoints": ["packages/builders/src/index.ts"],
2
+ "entryPointStrategy": "packages",
3
+ "entryPoints": ["packages/*"],
3
4
  "out": "tsdocs/api",
4
5
  "tsconfig": "./tsconfig.json",
5
6
  "excludePrivate": true,
@@ -7,4 +8,4 @@
7
8
  "excludeExternals": true,
8
9
  "plugin": ["typedoc-plugin-markdown"],
9
10
  "includeVersion": true
10
- }
11
+ }
@@ -1,16 +0,0 @@
1
- import { DownSubstates, UpSubstates } from "./SubstateDiff";
2
- import { ComponentAddress, TransactionResult } from "@tari-project/typescript-bindings";
3
-
4
- export type SubmitTransactionResponse = {
5
- transaction_id: string;
6
- };
7
-
8
- export interface SubmitTxResult {
9
- response: SubmitTransactionResponse;
10
- result: TransactionResult;
11
- upSubstates: UpSubstates;
12
- downSubstates: DownSubstates;
13
- newComponents: UpSubstates;
14
-
15
- getComponentForTemplate(templateAddress: string): ComponentAddress | null;
16
- }