@tari-project/tarijs 0.4.2 → 0.5.1

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 (91) hide show
  1. package/Dockerfile +52 -0
  2. package/README.md +37 -2
  3. package/TODO.md +0 -8
  4. package/docusaurus/tari-docs/docs/index.md +10 -5
  5. package/docusaurus/tari-docs/docs/installation.md +1 -1
  6. package/docusaurus/tari-docs/docs/providers/_category_.json +2 -2
  7. package/docusaurus/tari-docs/docs/providers/indexer-provider.md +32 -0
  8. package/docusaurus/tari-docs/docs/signers/_category_.json +8 -0
  9. package/docusaurus/tari-docs/docs/{providers → signers}/tari-universe.md +5 -5
  10. package/docusaurus/tari-docs/docs/{providers → signers}/wallet-connect.md +6 -7
  11. package/docusaurus/tari-docs/docs/{providers → signers}/wallet-daemon.md +7 -7
  12. package/docusaurus/tari-docs/docs/wallet/_category_.json +1 -1
  13. package/docusaurus/tari-docs/docs/wallet/list-substates.md +2 -3
  14. package/docusaurus/tari-docs/package.json +1 -1
  15. package/docusaurus/tari-docs/tsconfig.json +3 -1
  16. package/package.json +1 -1
  17. package/packages/builders/package.json +4 -5
  18. package/packages/builders/src/helpers/submitTransaction.ts +12 -12
  19. package/packages/builders/src/transaction/TransactionBuilder.ts +6 -7
  20. package/packages/builders/src/transaction/TransactionRequest.ts +10 -20
  21. package/packages/builders/tsconfig.json +2 -4
  22. package/packages/indexer_provider/package.json +31 -0
  23. package/packages/indexer_provider/src/index.ts +2 -0
  24. package/packages/indexer_provider/src/provider.ts +105 -0
  25. package/packages/indexer_provider/src/transports/IndexerProviderClient.ts +144 -0
  26. package/packages/indexer_provider/src/transports/fetch.ts +46 -0
  27. package/packages/indexer_provider/src/transports/index.ts +3 -0
  28. package/packages/indexer_provider/src/transports/rpc.ts +19 -0
  29. package/packages/indexer_provider/tsconfig.json +22 -0
  30. package/packages/metamask_signer/moon.yml +55 -0
  31. package/packages/{metamask_provider → metamask_signer}/package.json +3 -3
  32. package/packages/{metamask_provider → metamask_signer}/src/index.ts +42 -30
  33. package/packages/metamask_signer/tsconfig.json +19 -0
  34. package/packages/tari_permissions/package.json +2 -3
  35. package/packages/tari_permissions/src/helpers.ts +33 -0
  36. package/packages/tari_permissions/src/index.ts +2 -1
  37. package/packages/tari_permissions/src/tari_permissions.ts +59 -42
  38. package/packages/tari_provider/package.json +3 -2
  39. package/packages/tari_provider/src/TariProvider.ts +10 -25
  40. package/packages/tari_provider/src/index.ts +1 -3
  41. package/packages/tari_provider/tsconfig.json +9 -2
  42. package/packages/tari_signer/moon.yml +55 -0
  43. package/packages/tari_signer/package.json +28 -0
  44. package/packages/tari_signer/src/TariSigner.ts +30 -0
  45. package/packages/tari_signer/src/index.ts +1 -0
  46. package/packages/{metamask_provider → tari_signer}/tsconfig.json +0 -3
  47. package/packages/tari_universe/package.json +3 -3
  48. package/packages/tari_universe/src/index.ts +1 -1
  49. package/packages/tari_universe/src/{provider.ts → signer.ts} +45 -36
  50. package/packages/tari_universe/src/types.ts +10 -10
  51. package/packages/tari_universe/src/utils.ts +8 -8
  52. package/packages/tari_universe/tsconfig.json +2 -4
  53. package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +44 -44
  54. package/packages/tarijs/package.json +8 -6
  55. package/packages/tarijs/src/index.ts +39 -28
  56. package/packages/tarijs/tsconfig.json +7 -1
  57. package/packages/tarijs_types/package.json +1 -1
  58. package/packages/tarijs_types/src/ConfidentialOutput.ts +1 -1
  59. package/packages/tarijs_types/src/ConfidentialWithdrawProof.ts +1 -1
  60. package/packages/tarijs_types/src/GetTransactionResultResponse.ts +8 -0
  61. package/packages/tarijs_types/src/Instruction.ts +8 -5
  62. package/packages/tarijs_types/src/ListAccountNftFromBalancesRequest.ts +5 -0
  63. package/packages/tarijs_types/src/Transaction.ts +1 -1
  64. package/packages/tarijs_types/src/TransactionArg.ts +2 -0
  65. package/packages/tarijs_types/src/TransactionResult.ts +1 -10
  66. package/packages/tarijs_types/src/TransactionStatus.ts +9 -0
  67. package/packages/tarijs_types/src/UnsignedTransaction.ts +1 -2
  68. package/packages/tarijs_types/src/helpers/index.ts +69 -0
  69. package/packages/tarijs_types/src/index.ts +40 -11
  70. package/packages/{tari_provider/src/types.ts → tarijs_types/src/signer.ts} +17 -28
  71. package/packages/wallet_daemon/package.json +4 -3
  72. package/packages/wallet_daemon/src/index.ts +1 -1
  73. package/packages/wallet_daemon/src/{provider.ts → signer.ts} +59 -60
  74. package/packages/wallet_daemon/tsconfig.json +4 -1
  75. package/packages/walletconnect/package.json +4 -3
  76. package/packages/walletconnect/src/index.ts +56 -57
  77. package/packages/walletconnect/tsconfig.json +4 -1
  78. package/pnpm-workspace.yaml +3 -3
  79. package/tsconfig.json +8 -2
  80. package/packages/tarijs_types/src/Arg.ts +0 -3
  81. package/packages/tarijs_types/src/ComponentAddress.ts +0 -3
  82. package/packages/tarijs_types/src/ConfidentialOutputStatement.ts +0 -10
  83. package/packages/tarijs_types/src/ConfidentialStatement.ts +0 -9
  84. package/packages/tarijs_types/src/ElgamalVerifiableBalance.ts +0 -4
  85. package/packages/tarijs_types/src/Epoch.ts +0 -3
  86. package/packages/tarijs_types/src/ResourceAddress.ts +0 -3
  87. package/packages/tarijs_types/src/TemplateAddress.ts +0 -3
  88. package/packages/tarijs_types/src/TransactionId.ts +0 -4
  89. package/packages/tarijs_types/src/ViewableBalanceProof.ts +0 -12
  90. /package/packages/{metamask_provider → indexer_provider}/moon.yml +0 -0
  91. /package/packages/{metamask_provider → metamask_signer}/src/utils.ts +0 -0
@@ -0,0 +1,105 @@
1
+ import { TariProvider } from "@tari-project/tari-provider";
2
+ import { TariPermissions } from "@tari-project/tari-permissions";
3
+ import { IndexerProviderClient } from "./transports";
4
+ import {
5
+ GetTemplateDefinitionResponse,
6
+ ListTemplatesResponse,
7
+ stringToSubstateId,
8
+ substateIdToString,
9
+ SubstatesListRequest,
10
+ } from "@tari-project/typescript-bindings";
11
+ import {
12
+ convertStringToTransactionStatus,
13
+ GetSubstateRequest,
14
+ GetTransactionResultResponse,
15
+ ListSubstatesRequest,
16
+ ListSubstatesResponse,
17
+ Substate,
18
+ } from "@tari-project/tarijs-types";
19
+
20
+ export interface IndexerProviderParameters {
21
+ indexerJrpcUrl: string;
22
+ permissions: TariPermissions;
23
+ optionalPermissions?: TariPermissions;
24
+ onConnection?: () => void;
25
+ }
26
+
27
+ export class IndexerProvider implements TariProvider {
28
+ public providerName = "IndexerProvider";
29
+ client: IndexerProviderClient;
30
+ params: IndexerProviderParameters;
31
+
32
+ private constructor(params: IndexerProviderParameters, connection: IndexerProviderClient) {
33
+ this.params = params;
34
+ this.client = connection;
35
+ }
36
+
37
+ static async build(params: IndexerProviderParameters) {
38
+ const client = IndexerProviderClient.usingFetchTransport(params.indexerJrpcUrl);
39
+ await client.getIdentity();
40
+ params.onConnection?.();
41
+ return new IndexerProvider(params, client);
42
+ }
43
+
44
+ public isConnected(): boolean {
45
+ return this.client.isConnected();
46
+ }
47
+
48
+ public async listSubstates({
49
+ filter_by_template,
50
+ filter_by_type,
51
+ limit,
52
+ offset,
53
+ }: ListSubstatesRequest): Promise<ListSubstatesResponse> {
54
+ const resp = await this.client.listSubstates({
55
+ filter_by_template,
56
+ filter_by_type,
57
+ limit,
58
+ offset,
59
+ } as SubstatesListRequest);
60
+
61
+ const substates = resp.substates.map((s) => ({
62
+ substate_id: typeof s.substate_id === "string" ? s.substate_id : substateIdToString(s.substate_id),
63
+ module_name: s.module_name,
64
+ version: s.version,
65
+ template_address: s.template_address,
66
+ }));
67
+
68
+ return { substates };
69
+ }
70
+
71
+ public async getSubstate({ substate_address, version }: GetSubstateRequest): Promise<Substate> {
72
+ const resp = await this.client.getSubstate({
73
+ address: stringToSubstateId(substate_address),
74
+ version: version ?? null,
75
+ local_search_only: false,
76
+ });
77
+ return {
78
+ address: {
79
+ substate_id: substateIdToString(resp.address),
80
+ version: resp.version,
81
+ },
82
+ value: resp.substate,
83
+ };
84
+ }
85
+
86
+ public async listTemplates(limit: number = 0): Promise<ListTemplatesResponse> {
87
+ const resp = await this.client.listTemplates({ limit });
88
+ return resp;
89
+ }
90
+
91
+ public async getTransactionResult(transactionId: string): Promise<GetTransactionResultResponse> {
92
+ const resp = await this.client.getTransactionResult({ transaction_id: transactionId });
93
+
94
+ return {
95
+ transaction_id: transactionId,
96
+ status: convertStringToTransactionStatus(resp.status),
97
+ result: resp.result,
98
+ };
99
+ }
100
+
101
+ public async getTemplateDefinition(template_address: string): Promise<GetTemplateDefinitionResponse> {
102
+ let resp = await this.client.getTemplateDefinition({ template_address });
103
+ return resp;
104
+ }
105
+ }
@@ -0,0 +1,144 @@
1
+ import {
2
+ GetEpochManagerStatsResponse,
3
+ GetNonFungibleCollectionsResponse,
4
+ GetNonFungibleCountRequest,
5
+ GetNonFungibleCountResponse,
6
+ GetNonFungiblesRequest,
7
+ GetNonFungiblesResponse,
8
+ GetRelatedTransactionsRequest,
9
+ GetRelatedTransactionsResponse,
10
+ GetTemplateDefinitionRequest,
11
+ GetTemplateDefinitionResponse,
12
+ IndexerGetIdentityResponse,
13
+ IndexerGetSubstateRequest,
14
+ IndexerGetSubstateResponse,
15
+ IndexerSubmitTransactionRequest,
16
+ IndexerSubmitTransactionResponse,
17
+ InspectSubstateRequest,
18
+ InspectSubstateResponse,
19
+ ListTemplatesRequest,
20
+ ListTemplatesResponse,
21
+ SubstatesListRequest,
22
+ SubstatesListResponse,
23
+ TransactionGetResultRequest,
24
+ TransactionGetResultResponse,
25
+ TransactionWaitResultRequest,
26
+ TransactionWaitResultResponse,
27
+ } from "@tari-project/typescript-bindings";
28
+ import { FetchRpcTransport, RpcTransport } from "./rpc";
29
+
30
+ export class IndexerProviderClient {
31
+ private token: string | null;
32
+ private transport: RpcTransport;
33
+ private id: number;
34
+ private connected: boolean;
35
+
36
+ constructor(transport: RpcTransport) {
37
+ this.token = null;
38
+ this.transport = transport;
39
+ this.id = 0;
40
+ this.connected = false;
41
+ }
42
+
43
+ public static new(transport: RpcTransport): IndexerProviderClient {
44
+ return new IndexerProviderClient(transport);
45
+ }
46
+
47
+ public static usingFetchTransport(url: string): IndexerProviderClient {
48
+ return IndexerProviderClient.new(FetchRpcTransport.new(url));
49
+ }
50
+
51
+ getTransport() {
52
+ return this.transport;
53
+ }
54
+
55
+ public isAuthenticated() {
56
+ return this.token !== null;
57
+ }
58
+
59
+ public isConnected() {
60
+ return this.connected;
61
+ }
62
+
63
+ public setToken(token: string) {
64
+ this.token = token;
65
+ }
66
+
67
+ public submitTransaction(params: IndexerSubmitTransactionRequest): Promise<IndexerSubmitTransactionResponse> {
68
+ return this.__invokeRpc("submit_transaction", params);
69
+ }
70
+
71
+ public inspectSubstate(params: InspectSubstateRequest): Promise<InspectSubstateResponse> {
72
+ return this.__invokeRpc("inspect_substate", params);
73
+ }
74
+
75
+ public getSubstate(params: IndexerGetSubstateRequest): Promise<IndexerGetSubstateResponse> {
76
+ return this.__invokeRpc("get_substate", params);
77
+ }
78
+
79
+ public listSubstates(params: SubstatesListRequest): Promise<SubstatesListResponse> {
80
+ return this.__invokeRpc("list_substates", params);
81
+ }
82
+
83
+ public listTemplates(params: ListTemplatesRequest): Promise<ListTemplatesResponse> {
84
+ return this.__invokeRpc("list_templates", params);
85
+ }
86
+
87
+ public getTemplateDefinition(params: GetTemplateDefinitionRequest): Promise<GetTemplateDefinitionResponse> {
88
+ return this.__invokeRpc("get_template_definition", params);
89
+ }
90
+
91
+ public getTransactionResult(params: TransactionGetResultRequest): Promise<TransactionGetResultResponse> {
92
+ return this.__invokeRpc("get_transaction_result", params);
93
+ }
94
+
95
+ public getSubstateTransactions(params: GetRelatedTransactionsRequest): Promise<GetRelatedTransactionsResponse> {
96
+ return this.__invokeRpc("get_substate_transactions", params);
97
+ }
98
+
99
+ public getNonFungibles(params: GetNonFungiblesRequest): Promise<GetNonFungiblesResponse> {
100
+ return this.__invokeRpc("get_non_fungibles", params);
101
+ }
102
+
103
+ public getNonFungibleCollections(): Promise<GetNonFungibleCollectionsResponse> {
104
+ return this.__invokeRpc("get_non_fungible_collections");
105
+ }
106
+
107
+ public getNonFungibleCount(params: GetNonFungibleCountRequest): Promise<GetNonFungibleCountResponse> {
108
+ return this.__invokeRpc("get_non_fungible_count", params);
109
+ }
110
+
111
+ public getEpochManagerStats(): Promise<GetEpochManagerStatsResponse> {
112
+ return this.__invokeRpc("get_epoch_manager_stats");
113
+ }
114
+
115
+ public waitForTransactionResult(params: TransactionWaitResultRequest): Promise<TransactionWaitResultResponse> {
116
+ return this.__invokeRpc("transactions.wait_result", params);
117
+ }
118
+
119
+ public async getIdentity(): Promise<IndexerGetIdentityResponse | undefined> {
120
+ try {
121
+ const res: IndexerGetIdentityResponse = await this.__invokeRpc("get_identity");
122
+ this.connected = !!res.public_key;
123
+ return res;
124
+ } catch (e) {
125
+ console.error("Failed to get Indexer identity:", e);
126
+ this.connected = false;
127
+ }
128
+ }
129
+
130
+ async __invokeRpc(method: string, params: object | null = null) {
131
+ const id = this.id++;
132
+ const response = await this.transport.sendRequest<any>(
133
+ {
134
+ method,
135
+ jsonrpc: "2.0",
136
+ id: id,
137
+ params: params || {},
138
+ },
139
+ { token: this.token ?? undefined, timeout_millis: undefined },
140
+ );
141
+
142
+ return response;
143
+ }
144
+ }
@@ -0,0 +1,46 @@
1
+ import { RpcRequest, RpcTransport, RpcTransportOptions } from "./rpc";
2
+
3
+ export default class FetchRpcTransport implements RpcTransport {
4
+ private url: string;
5
+
6
+ constructor(url: string) {
7
+ this.url = url;
8
+ }
9
+
10
+ static new(url: string) {
11
+ return new FetchRpcTransport(url);
12
+ }
13
+
14
+ async sendRequest<T>(data: RpcRequest, options: RpcTransportOptions): Promise<T> {
15
+ const headers: { [key: string]: string } = {
16
+ "Content-Type": "application/json",
17
+ };
18
+ if (options?.token) {
19
+ headers["Authorization"] = `Bearer ${options.token}`;
20
+ }
21
+
22
+ let controller = new AbortController();
23
+ let signal = controller.signal;
24
+
25
+ const timeoutId = options.timeout_millis
26
+ ? setTimeout(() => {
27
+ controller.abort("Timeout");
28
+ }, options.timeout_millis)
29
+ : null;
30
+
31
+ const response = await fetch(this.url, {
32
+ method: "POST",
33
+ body: JSON.stringify(data),
34
+ headers,
35
+ signal,
36
+ });
37
+ if (timeoutId) {
38
+ clearTimeout(timeoutId);
39
+ }
40
+ const json = await response.json();
41
+ if (json.error) {
42
+ throw new Error(`${json.error.code}: ${json.error.message}`);
43
+ }
44
+ return json.result;
45
+ }
46
+ }
@@ -0,0 +1,3 @@
1
+ export { IndexerProviderClient } from "./IndexerProviderClient";
2
+ export * from "./fetch";
3
+ export * from "./rpc";
@@ -0,0 +1,19 @@
1
+ import FetchRpcTransport from "./fetch";
2
+
3
+ export { FetchRpcTransport };
4
+
5
+ export interface RpcTransport {
6
+ sendRequest<T>(request: RpcRequest, options: RpcTransportOptions): Promise<T>;
7
+ }
8
+
9
+ export interface RpcTransportOptions {
10
+ token?: string;
11
+ timeout_millis?: number;
12
+ }
13
+
14
+ export interface RpcRequest {
15
+ id: number;
16
+ jsonrpc: string;
17
+ method: string;
18
+ params: any;
19
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ES2020",
5
+ "target": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "outDir": "./dist",
8
+ "rootDir": "./src"
9
+ },
10
+ "include": ["src/**/*"],
11
+ "references": [
12
+ {
13
+ "path": "../tari_permissions"
14
+ },
15
+ {
16
+ "path": "../tari_provider"
17
+ },
18
+ {
19
+ "path": "../tarijs_types"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,55 @@
1
+ language: "typescript"
2
+ platform: "node"
3
+ type: "library"
4
+
5
+ fileGroups:
6
+ configs:
7
+ - "tsconfig.json"
8
+ - "package.json"
9
+ - "eslint.config.ts"
10
+ sources:
11
+ - "src/**/*"
12
+ tests:
13
+ - "integration-tests/**/*"
14
+
15
+ tasks:
16
+ build:
17
+ command: "pnpm run build"
18
+ inputs:
19
+ - "@files(sources)"
20
+ - "@files(configs)"
21
+ outputs:
22
+ - "dist"
23
+ format:
24
+ command: "pnpm run format"
25
+ inputs:
26
+ - "@files(sources)"
27
+ - "@files(configs)"
28
+ - "@files(tests)"
29
+ options:
30
+ runInCI: false
31
+ lint:
32
+ command: "pnpm run lint:fix"
33
+ inputs:
34
+ - "@files(sources)"
35
+ - "@files(configs)"
36
+ - "@files(tests)"
37
+ options:
38
+ runInCI: false
39
+ deps:
40
+ - "build"
41
+
42
+ lintCheck:
43
+ command: "pnpm run lint"
44
+ inputs:
45
+ - "@files(sources)"
46
+ - "@files(configs)"
47
+ - "@files(tests)"
48
+ deps:
49
+ - "build"
50
+ formatCheck:
51
+ command: "pnpm run format:check"
52
+ inputs:
53
+ - "@files(sources)"
54
+ - "@files(configs)"
55
+ - "@files(tests)"
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "@tari-project/metamask-provider",
3
- "version": "0.4.0",
2
+ "name": "@tari-project/metamask-signer",
3
+ "version": "0.5.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -14,7 +14,7 @@
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
16
  "@metamask/providers": "catalog:",
17
- "@tari-project/tari-provider": "workspace:^",
17
+ "@tari-project/tari-signer": "workspace:^",
18
18
  "@tari-project/tarijs-types": "workspace:^",
19
19
  "@tari-project/typescript-bindings": "catalog:"
20
20
  },
@@ -1,4 +1,4 @@
1
- import { TariProvider } from "@tari-project/tari-provider";
1
+ import { TariSigner } from "@tari-project/tari-signer";
2
2
  import {
3
3
  SubmitTransactionRequest,
4
4
  TransactionResult,
@@ -8,11 +8,18 @@ import {
8
8
  TemplateDefinition,
9
9
  Substate,
10
10
  ListSubstatesResponse,
11
- Account
12
- } from "@tari-project/tari-provider";
11
+ AccountData,
12
+ ListSubstatesRequest,
13
+ GetTransactionResultResponse,
14
+ } from "@tari-project/tarijs-types";
13
15
  import { MetaMaskInpageProvider } from "@metamask/providers";
14
16
  import { connectSnap, getSnap, isFlask, Snap } from "./utils";
15
- import { SubstateType } from "@tari-project/typescript-bindings";
17
+ import {
18
+ ConfidentialViewVaultBalanceRequest,
19
+ ListAccountNftRequest,
20
+ ListAccountNftResponse,
21
+ SubstateType,
22
+ } from "@tari-project/typescript-bindings";
16
23
 
17
24
  export const MetamaskNotInstalled = "METAMASK_NOT_INSTALLED";
18
25
  export const MetamaskIsNotFlask = "METAMASK_IS_NOT_FLASK";
@@ -20,8 +27,8 @@ export const TariSnapNotInstalled = "TARI_SNAP_NOT_INSTALLED";
20
27
 
21
28
  type Maybe<T> = T | null | undefined;
22
29
 
23
- export class MetamaskTariProvider implements TariProvider {
24
- public providerName = "Metamask";
30
+ export class MetamaskTariSigner implements TariSigner {
31
+ public signerName = "Metamask";
25
32
  snapId: string;
26
33
  snapVersion: string | undefined;
27
34
  metamask: MetaMaskInpageProvider;
@@ -64,7 +71,7 @@ export class MetamaskTariProvider implements TariProvider {
64
71
  return this.metamaskConnected;
65
72
  }
66
73
 
67
- public async createFreeTestCoins(account_id: number): Promise<Account> {
74
+ public async createFreeTestCoins(account_id: number): Promise<AccountData> {
68
75
  const res = (await this.metamaskRequest("getFreeTestCoins", {
69
76
  amount: 1000000,
70
77
  account_id,
@@ -78,7 +85,7 @@ export class MetamaskTariProvider implements TariProvider {
78
85
  };
79
86
  }
80
87
 
81
- async getAccount(): Promise<Account> {
88
+ async getAccount(): Promise<AccountData> {
82
89
  return (await this.metamaskRequest("getAccountData", { account_id: 0 })) as any;
83
90
  }
84
91
 
@@ -91,12 +98,12 @@ export class MetamaskTariProvider implements TariProvider {
91
98
  return { value: substate, address: { substate_id, version } };
92
99
  }
93
100
 
94
- async listSubstates(
95
- filter_by_template: string | null,
96
- filter_by_type: SubstateType | null,
97
- limit: number | null,
98
- offset: number | null,
99
- ): Promise<ListSubstatesResponse> {
101
+ async listSubstates({
102
+ filter_by_template,
103
+ filter_by_type,
104
+ limit,
105
+ offset,
106
+ }: ListSubstatesRequest): Promise<ListSubstatesResponse> {
100
107
  const res = (await this.metamaskRequest("listSubstates", {
101
108
  filter_by_template,
102
109
  filter_by_type,
@@ -126,7 +133,7 @@ export class MetamaskTariProvider implements TariProvider {
126
133
  return { transaction_id: resp.transaction_id };
127
134
  }
128
135
 
129
- public async getTransactionResult(transactionId: string): Promise<TransactionResult> {
136
+ public async getTransactionResult(transactionId: string): Promise<GetTransactionResultResponse> {
130
137
  // This request returns the response from the indexer get_transaction_result request
131
138
  const resp: Maybe<any> = await this.metamaskRequest("getTransactionResult", { transaction_id: transactionId });
132
139
 
@@ -139,7 +146,7 @@ export class MetamaskTariProvider implements TariProvider {
139
146
  transaction_id: transactionId,
140
147
  status: TransactionStatus.Pending,
141
148
  result: null,
142
- } as TransactionResult;
149
+ } as GetTransactionResultResponse;
143
150
  }
144
151
 
145
152
  if (!resp?.result?.Finalized) {
@@ -152,7 +159,7 @@ export class MetamaskTariProvider implements TariProvider {
152
159
  transaction_id: transactionId,
153
160
  status: newStatus,
154
161
  result: resp.result.Finalized.execution_result.finalize,
155
- } as TransactionResult;
162
+ } as GetTransactionResultResponse;
156
163
  }
157
164
 
158
165
  public async getPublicKey(_branch: string, index: number): Promise<string> {
@@ -165,20 +172,20 @@ export class MetamaskTariProvider implements TariProvider {
165
172
  return resp.public_key;
166
173
  }
167
174
 
168
- public async getConfidentialVaultBalances(
169
- viewKeyId: number,
170
- vaultId: string,
171
- min: number | null = null,
172
- max: number | null = null,
173
- ): Promise<VaultBalances> {
174
- const res = (await this.metamaskRequest("getConfidentialVaultBalances", {
175
- view_key_id: viewKeyId,
176
- vault_id: vaultId,
177
- minimum_expected_value: min,
178
- maximum_expected_value: max,
179
- })) as any;
175
+ public async getConfidentialVaultBalances({
176
+ vault_id,
177
+ maximum_expected_value,
178
+ minimum_expected_value,
179
+ view_key_id,
180
+ }: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances> {
181
+ const resp = await this.metamaskRequest("getConfidentialVaultBalances", {
182
+ view_key_id,
183
+ vault_id,
184
+ minimum_expected_value,
185
+ maximum_expected_value,
186
+ });
180
187
 
181
- return { balances: res as unknown as Map<string, number | null> };
188
+ return { balances: resp as Map<string, number | null> };
182
189
  }
183
190
 
184
191
  getTemplateDefinition(template_address: string): Promise<TemplateDefinition> {
@@ -212,6 +219,11 @@ export class MetamaskTariProvider implements TariProvider {
212
219
 
213
220
  return resp as T;
214
221
  }
222
+
223
+ public async getNftsList(req: ListAccountNftRequest): Promise<ListAccountNftResponse> {
224
+ const resp = (await this.metamaskRequest("getNftsList", req)) as ListAccountNftResponse;
225
+ return resp;
226
+ }
215
227
  }
216
228
 
217
229
  function convertToStatus(result: any): TransactionStatus {
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ES2020",
5
+ "target": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "outDir": "./dist",
8
+ "rootDir": "./src"
9
+ },
10
+ "include": ["src/**/*"],
11
+ "references": [
12
+ {
13
+ "path": "../tari_signer"
14
+ },
15
+ {
16
+ "path": "../tarijs_types"
17
+ }
18
+ ]
19
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tari-permissions",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -12,8 +12,7 @@
12
12
  "keywords": [],
13
13
  "author": "",
14
14
  "license": "ISC",
15
- "dependencies": {
16
- },
15
+ "dependencies": {},
17
16
  "devDependencies": {
18
17
  "@types/node": "catalog:",
19
18
  "typescript": "catalog:"
@@ -0,0 +1,33 @@
1
+ import {
2
+ TariPermission,
3
+ TariPermissionAccountBalance,
4
+ TariPermissionAccountInfo,
5
+ TariPermissionAccountList,
6
+ TariPermissionGetNft,
7
+ TariPermissionKeyList,
8
+ TariPermissionNftGetOwnershipProof,
9
+ TariPermissionTransactionGet,
10
+ TariPermissionTransactionSend,
11
+ } from "./tari_permissions";
12
+
13
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14
+ export function createPermissionFromType(permission: any): TariPermission {
15
+ if (Object.prototype.hasOwnProperty.call(permission, "AccountBalance")) {
16
+ return new TariPermissionAccountBalance(permission.AccountBalance);
17
+ } else if (permission === "AccountInfo") {
18
+ return new TariPermissionAccountInfo();
19
+ } else if (Object.prototype.hasOwnProperty.call(permission, "AccountList")) {
20
+ return new TariPermissionAccountList(permission.AccountList);
21
+ } else if (permission == "KeyList") {
22
+ return new TariPermissionKeyList();
23
+ } else if (Object.prototype.hasOwnProperty.call(permission, "TransactionSend")) {
24
+ return new TariPermissionTransactionSend(permission.TransactionSend);
25
+ } else if (permission === "TransactionGet") {
26
+ return new TariPermissionTransactionGet();
27
+ } else if (Object.prototype.hasOwnProperty.call(permission, "GetNft")) {
28
+ return new TariPermissionGetNft(permission.GetNft);
29
+ } else if (Object.prototype.hasOwnProperty.call(permission, "NftGetOwnershipProof")) {
30
+ return new TariPermissionNftGetOwnershipProof(permission.NftGetOwnershipProof);
31
+ }
32
+ return permission;
33
+ }
@@ -1 +1,2 @@
1
- export * from './tari_permissions';
1
+ export * from "./tari_permissions";
2
+ export * from "./helpers";