@tari-project/tarijs 0.12.0 → 0.12.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.
- package/.github/workflows/lint.yml +19 -0
- package/README.md +4 -1
- package/docusaurus/tari-docs/package.json +1 -1
- package/eslint.config.mjs +23 -6
- package/examples/vite-typescript-react/eslint.config.js +13 -10
- package/examples/vite-typescript-react/index.html +1 -1
- package/examples/vite-typescript-react/package.json +5 -6
- package/examples/vite-typescript-react/public/tari-logo.svg +18 -0
- package/examples/vite-typescript-react/tsconfig.json +2 -4
- package/knip.ts +18 -0
- package/package.json +7 -5
- package/packages/builders/package.json +3 -2
- package/packages/builders/src/helpers/submitTransaction.ts +11 -10
- package/packages/builders/src/helpers/workspace.ts +2 -2
- package/packages/builders/src/transaction/TransactionBuilder.ts +12 -13
- package/packages/indexer_provider/package.json +3 -2
- package/packages/indexer_provider/src/provider.ts +6 -7
- package/packages/indexer_provider/src/transports/IndexerProviderClient.ts +1 -0
- package/packages/indexer_provider/src/transports/fetch.ts +2 -2
- package/packages/indexer_provider/src/transports/rpc.ts +1 -0
- package/packages/metamask_signer/package.json +3 -2
- package/packages/metamask_signer/src/index.ts +7 -7
- package/packages/metamask_signer/src/utils.ts +36 -45
- package/packages/permissions/package.json +3 -2
- package/packages/permissions/src/helpers.ts +0 -1
- package/packages/permissions/src/permissions.ts +6 -13
- package/packages/react-mui-connect-button/package.json +3 -4
- package/packages/react-mui-connect-button/src/Logos.tsx +77 -48
- package/packages/react-mui-connect-button/src/TariConnectButton.tsx +1 -2
- package/packages/react-mui-connect-button/src/TariWalletSelectionDialog.tsx +64 -28
- package/packages/react-mui-connect-button/src/index.ts +6 -3
- package/packages/tari_provider/package.json +3 -2
- package/packages/tari_signer/package.json +3 -2
- package/packages/tari_universe/package.json +3 -2
- package/packages/tari_universe/src/types.ts +1 -0
- package/packages/tarijs/package.json +3 -2
- package/packages/tarijs/src/index.ts +2 -20
- package/packages/tarijs/src/templates/TestFaucet.ts +7 -2
- package/packages/tarijs/test/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +9 -12
- package/packages/tarijs_types/package.json +3 -2
- package/packages/tarijs_types/src/Amount.ts +1 -1
- package/packages/tarijs_types/src/SubmitTransactionResponse.ts +3 -0
- package/packages/tarijs_types/src/TransactionArg.ts +1 -0
- package/packages/tarijs_types/src/consts.ts +1 -1
- package/packages/tarijs_types/src/helpers/hexString.ts +20 -19
- package/packages/tarijs_types/src/helpers/simpleResult.ts +23 -20
- package/packages/tarijs_types/src/helpers/txResult.ts +3 -4
- package/packages/tarijs_types/src/index.ts +9 -4
- package/packages/tarijs_types/src/signer.ts +3 -6
- package/packages/wallet_daemon/package.json +3 -2
- package/packages/wallet_daemon/src/provider.ts +14 -16
- package/packages/wallet_daemon/src/signer.ts +15 -17
- package/packages/wallet_daemon/src/webrtc.ts +18 -13
- package/packages/walletconnect/package.json +6 -6
- package/packages/walletconnect/src/index.ts +36 -22
- package/pnpm-workspace.yaml +8 -8
- package/tsconfig.json +1 -1
- package/typedoc.json +3 -2
- package/packages/react-mui-connect-button/src/defaultPermissions.ts +0 -0
- package/packages/tarijs_types/src/TransactionResult.ts +0 -16
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
run-linters:
|
|
9
|
+
name: Run linters
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0
|
|
15
|
+
- uses: "moonrepo/setup-toolchain@v0"
|
|
16
|
+
with:
|
|
17
|
+
auto-install: true
|
|
18
|
+
- run: pnpm install
|
|
19
|
+
- run: pnpm run lint
|
package/README.md
CHANGED
package/eslint.config.mjs
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import eslint from
|
|
4
|
-
import tseslint from
|
|
3
|
+
import eslint from "@eslint/js";
|
|
4
|
+
import tseslint from "typescript-eslint";
|
|
5
5
|
|
|
6
|
-
export default tseslint.config(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export default tseslint.config(eslint.configs.recommended, tseslint.configs.recommended, {
|
|
7
|
+
rules: {
|
|
8
|
+
// "no-console": ["warn", { allow: ["info", "warn", "debug", "error"] }],
|
|
9
|
+
"no-unused-vars": "off", // base rule must be disabled
|
|
10
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
11
|
+
"@typescript-eslint/ban-ts-comment": "warn",
|
|
12
|
+
"@typescript-eslint/no-unused-vars": [
|
|
13
|
+
"warn",
|
|
14
|
+
{
|
|
15
|
+
argsIgnorePattern: "^_",
|
|
16
|
+
varsIgnorePattern: "^_",
|
|
17
|
+
caughtErrorsIgnorePattern: "^_",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
languageOptions: {
|
|
22
|
+
parserOptions: {
|
|
23
|
+
tsconfigRootDir: "./",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import js from
|
|
2
|
-
import globals from
|
|
3
|
-
import reactHooks from
|
|
4
|
-
import reactRefresh from
|
|
5
|
-
import tseslint from
|
|
6
|
-
import { globalIgnores } from
|
|
1
|
+
import js from "@eslint/js";
|
|
2
|
+
import globals from "globals";
|
|
3
|
+
import reactHooks from "eslint-plugin-react-hooks";
|
|
4
|
+
import reactRefresh from "eslint-plugin-react-refresh";
|
|
5
|
+
import tseslint from "typescript-eslint";
|
|
6
|
+
import { globalIgnores } from "eslint/config";
|
|
7
7
|
|
|
8
8
|
export default tseslint.config([
|
|
9
|
-
globalIgnores([
|
|
9
|
+
globalIgnores(["dist"]),
|
|
10
10
|
{
|
|
11
|
-
files: [
|
|
11
|
+
files: ["**/*.{ts,tsx}"],
|
|
12
12
|
extends: [
|
|
13
13
|
js.configs.recommended,
|
|
14
14
|
tseslint.configs.recommended,
|
|
15
|
-
reactHooks.configs[
|
|
15
|
+
reactHooks.configs["recommended-latest"],
|
|
16
16
|
reactRefresh.configs.vite,
|
|
17
17
|
],
|
|
18
18
|
languageOptions: {
|
|
19
19
|
ecmaVersion: 2020,
|
|
20
20
|
globals: globals.browser,
|
|
21
|
+
parserOptions: {
|
|
22
|
+
tsconfigRootDir: "./",
|
|
23
|
+
},
|
|
21
24
|
},
|
|
22
25
|
},
|
|
23
|
-
])
|
|
26
|
+
]);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="/
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/tari-logo.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Tari.js Connect Button Example</title>
|
|
8
8
|
</head>
|
|
@@ -10,14 +10,13 @@
|
|
|
10
10
|
"preview": "vite preview"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@
|
|
14
|
-
"@tari-project/react-mui-connect-button": "workspace:^",
|
|
15
|
-
"react": "^19.1.0",
|
|
16
|
-
"react-dom": "^19.1.0",
|
|
13
|
+
"@emotion/styled": "^11.14.1",
|
|
17
14
|
"@mui/icons-material": "^7",
|
|
18
15
|
"@mui/material": "^7",
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
16
|
+
"@tari-project/react-mui-connect-button": "workspace:^",
|
|
17
|
+
"@tari-project/tarijs-all": "workspace:^",
|
|
18
|
+
"react": "^19.1.0",
|
|
19
|
+
"react-dom": "^19.1.0"
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
23
22
|
"@eslint/js": "^9.29.0",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="25px" height="25px" viewBox="0 0 25 25" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<title>node-icon</title>
|
|
4
|
+
<defs>
|
|
5
|
+
<linearGradient x1="18.2919102%" y1="10.0218476%" x2="75.2362057%" y2="77.3326874%" id="linearGradient-1">
|
|
6
|
+
<stop stop-color="#6239FF" offset="0%"></stop>
|
|
7
|
+
<stop stop-color="#C326D6" offset="100%"></stop>
|
|
8
|
+
</linearGradient>
|
|
9
|
+
</defs>
|
|
10
|
+
<g id="Final-Designs" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
11
|
+
<g id="Icons">
|
|
12
|
+
<g id="node-icon">
|
|
13
|
+
<polygon id="Path" points="0 0 25 0 25 25 0 25"></polygon>
|
|
14
|
+
<path d="M20.1635307,8.81670631 L20.1635307,11.1649473 L6.39264373,7.6223935 L11.0366915,4.59938041 L20.1635307,8.81670631 Z M11.8116251,18.6587023 L11.8116251,10.9999256 L19.1635161,12.8911326 L11.8116251,18.6587023 Z M9.89076494,17.9185993 L4.8364693,12.2747253 L4.8364693,9.20558518 L9.89076494,10.5058018 L9.89076494,17.9185993 Z M2.91551501,7.5936818 L2.91551501,13.0091801 L10.8424874,21.8606694 L22.084485,13.0410925 L22.084485,7.58822187 L10.8784476,2.41013641 L2.91551501,7.5936818 Z" fill="url(#linearGradient-1)"></path>
|
|
15
|
+
</g>
|
|
16
|
+
</g>
|
|
17
|
+
</g>
|
|
18
|
+
</svg>
|
package/knip.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { KnipConfig } from "knip";
|
|
2
|
+
|
|
3
|
+
const config: KnipConfig = {
|
|
4
|
+
rules: {
|
|
5
|
+
files: "error",
|
|
6
|
+
dependencies: "warn",
|
|
7
|
+
unlisted: "warn",
|
|
8
|
+
exports: "warn",
|
|
9
|
+
types: "warn",
|
|
10
|
+
duplicates: "warn",
|
|
11
|
+
},
|
|
12
|
+
ignoreBinaries: ["commitlint"],
|
|
13
|
+
ignoreExportsUsedInFile: true,
|
|
14
|
+
ignore: ["docusaurus/**/*.ts"],
|
|
15
|
+
ignoreDependencies: ["@moonrepo/cli"],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -13,16 +13,18 @@
|
|
|
13
13
|
"@eslint/js": "^9.30.0",
|
|
14
14
|
"@moonrepo/cli": "^1.32.1",
|
|
15
15
|
"eslint": "^9.30.0",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"knip": "^5.61.3",
|
|
17
|
+
"typedoc": "^0.28.7",
|
|
18
18
|
"typedoc-plugin-markdown": "^4.7.0",
|
|
19
19
|
"typescript": "^5.8.3",
|
|
20
20
|
"typescript-eslint": "^8.35.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tari-project/tarijs-types": "^0.12.
|
|
23
|
+
"@tari-project/tarijs-types": "^0.12.2"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"docs": "typedoc"
|
|
26
|
+
"docs": "typedoc",
|
|
27
|
+
"lint": "pnpm -r lint",
|
|
28
|
+
"knip": "knip"
|
|
27
29
|
}
|
|
28
30
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-builders",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
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",
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { TariUniverseSigner } from "@tari-project/tari-universe-signer";
|
|
2
2
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
3
|
-
import {
|
|
4
|
-
TransactionResult,
|
|
5
|
-
UnsignedTransactionV1,
|
|
6
|
-
} from "@tari-project/typescript-bindings";
|
|
3
|
+
import { TransactionResult, UnsignedTransactionV1 } from "@tari-project/typescript-bindings";
|
|
7
4
|
import {
|
|
8
5
|
DownSubstates,
|
|
9
6
|
UpSubstates,
|
|
10
7
|
SubmitTransactionRequest,
|
|
11
|
-
TransactionStatus,
|
|
8
|
+
TransactionStatus,
|
|
9
|
+
SimpleTransactionResult,
|
|
12
10
|
} from "@tari-project/tarijs-types";
|
|
13
11
|
|
|
14
12
|
export function buildTransactionRequest(
|
|
@@ -39,7 +37,6 @@ export async function waitForTransactionResult(
|
|
|
39
37
|
signer: TariSigner | TariUniverseSigner,
|
|
40
38
|
transactionId: string,
|
|
41
39
|
): Promise<SimpleTransactionResult> {
|
|
42
|
-
// eslint-disable-next-line no-constant-condition
|
|
43
40
|
while (true) {
|
|
44
41
|
const resp = await signer.getTransactionResult(transactionId);
|
|
45
42
|
const FINALIZED_STATUSES = [
|
|
@@ -53,6 +50,9 @@ export async function waitForTransactionResult(
|
|
|
53
50
|
if (resp.status == TransactionStatus.Rejected) {
|
|
54
51
|
throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
|
|
55
52
|
}
|
|
53
|
+
if (!resp.result?.result) {
|
|
54
|
+
throw new Error(`Transaction finalized but the result is undefined`);
|
|
55
|
+
}
|
|
56
56
|
if (FINALIZED_STATUSES.includes(resp.status)) {
|
|
57
57
|
if (!resp.result) {
|
|
58
58
|
throw new Error(`BUG: Transaction result is empty for transaction ID: ${transactionId}`);
|
|
@@ -64,10 +64,15 @@ export async function waitForTransactionResult(
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** @public */
|
|
67
68
|
export function getAcceptResultSubstates(txResult: TransactionResult): {
|
|
68
69
|
upSubstates: UpSubstates;
|
|
69
70
|
downSubstates: DownSubstates;
|
|
70
71
|
} {
|
|
72
|
+
if ("Reject" in txResult) {
|
|
73
|
+
throw new Error(`Transaction rejected: ${txResult.Reject}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
71
76
|
if ("Accept" in txResult) {
|
|
72
77
|
return {
|
|
73
78
|
upSubstates: txResult.Accept.up_substates,
|
|
@@ -75,10 +80,6 @@ export function getAcceptResultSubstates(txResult: TransactionResult): {
|
|
|
75
80
|
};
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
if ("Reject" in txResult) {
|
|
79
|
-
throw new Error(`Transaction rejected: ${txResult.Reject}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
83
|
if ("AcceptFeeRejectRest" in txResult) {
|
|
83
84
|
return {
|
|
84
85
|
upSubstates: txResult.AcceptFeeRejectRest[0].up_substates,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransactionArg
|
|
1
|
+
import { TransactionArg } from "@tari-project/tarijs-types";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A parsed workspace key string into an object with name and optional offset.
|
|
@@ -39,4 +39,4 @@ export function parseWorkspaceStringKey(key: string): ParsedBuildersWorkspaceKey
|
|
|
39
39
|
* Named workspace arguments are used to refer to a workspace by name,
|
|
40
40
|
* and are converted to numeric IDs by the TransactionBuilder.
|
|
41
41
|
*/
|
|
42
|
-
export type NamedArg = { Workspace: string } | TransactionArg;
|
|
42
|
+
export type NamedArg = { Workspace: string } | TransactionArg;
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
UnsignedTransaction,
|
|
16
16
|
PublishedTemplateAddress,
|
|
17
17
|
WorkspaceOffsetId,
|
|
18
|
-
UnsignedTransactionV1,
|
|
18
|
+
UnsignedTransactionV1,
|
|
19
|
+
AllocatableAddressType,
|
|
19
20
|
} from "@tari-project/typescript-bindings";
|
|
20
21
|
import { parseWorkspaceStringKey, NamedArg } from "../helpers";
|
|
21
22
|
|
|
@@ -23,7 +24,9 @@ import { parseWorkspaceStringKey, NamedArg } from "../helpers";
|
|
|
23
24
|
* This interface defines the constructor for a Transaction object.
|
|
24
25
|
* It is used to create a new signed Transaction instance from an UnsignedTransaction and an array of TransactionSignatures.
|
|
25
26
|
* The constructor takes an UnsignedTransaction and an array of TransactionSignatures as parameters.
|
|
27
|
+
* @public
|
|
26
28
|
*/
|
|
29
|
+
|
|
27
30
|
export interface TransactionConstructor {
|
|
28
31
|
/**
|
|
29
32
|
* Creates a new {@link Transaction} instance.
|
|
@@ -42,7 +45,7 @@ export interface TransactionConstructor {
|
|
|
42
45
|
*
|
|
43
46
|
* @returns A new Transaction instance.
|
|
44
47
|
*/
|
|
45
|
-
new(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
|
|
48
|
+
new (unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
/**
|
|
@@ -105,7 +108,7 @@ export interface TariMethodDefinition {
|
|
|
105
108
|
* @example
|
|
106
109
|
* "my_workspace"
|
|
107
110
|
*/
|
|
108
|
-
fromWorkspace?: string
|
|
111
|
+
fromWorkspace?: string;
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
/**
|
|
@@ -186,7 +189,6 @@ export interface Builder {
|
|
|
186
189
|
*/
|
|
187
190
|
claimBurn(claim: ConfidentialClaim): this;
|
|
188
191
|
|
|
189
|
-
|
|
190
192
|
addInput(inputObject: SubstateRequirement): this;
|
|
191
193
|
|
|
192
194
|
/** Adds a raw instruction to the transaction.
|
|
@@ -325,10 +327,10 @@ export class TransactionBuilder implements Builder {
|
|
|
325
327
|
}
|
|
326
328
|
|
|
327
329
|
public callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this {
|
|
328
|
-
const call = method.componentAddress
|
|
329
|
-
{ Address: method.componentAddress }
|
|
330
|
-
// NOTE: offset IDs are not supported for method calls
|
|
331
|
-
|
|
330
|
+
const call = method.componentAddress
|
|
331
|
+
? { Address: method.componentAddress }
|
|
332
|
+
: // NOTE: offset IDs are not supported for method calls
|
|
333
|
+
{ Workspace: this.getNamedId(method.fromWorkspace!)! };
|
|
332
334
|
const resolvedArgs = this.resolveArgs(args);
|
|
333
335
|
return this.addInstruction({
|
|
334
336
|
CallMethod: {
|
|
@@ -340,9 +342,7 @@ export class TransactionBuilder implements Builder {
|
|
|
340
342
|
}
|
|
341
343
|
|
|
342
344
|
public createAccount(ownerPublicKey: string, workspaceBucket?: string): this {
|
|
343
|
-
const workspace_id = workspaceBucket ?
|
|
344
|
-
this.getOffsetIdFromWorkspaceName(workspaceBucket) :
|
|
345
|
-
null;
|
|
345
|
+
const workspace_id = workspaceBucket ? this.getOffsetIdFromWorkspaceName(workspaceBucket) : null;
|
|
346
346
|
|
|
347
347
|
return this.addInstruction({
|
|
348
348
|
CreateAccount: {
|
|
@@ -399,7 +399,7 @@ export class TransactionBuilder implements Builder {
|
|
|
399
399
|
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
400
400
|
*/
|
|
401
401
|
public saveVar(name: string): this {
|
|
402
|
-
|
|
402
|
+
const key = this.addNamedId(name);
|
|
403
403
|
return this.addInstruction({
|
|
404
404
|
PutLastInstructionOutputOnWorkspace: {
|
|
405
405
|
key,
|
|
@@ -546,5 +546,4 @@ export class TransactionBuilder implements Builder {
|
|
|
546
546
|
return arg;
|
|
547
547
|
});
|
|
548
548
|
}
|
|
549
|
-
|
|
550
549
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/indexer-provider",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
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",
|
|
@@ -4,7 +4,6 @@ import { IndexerProviderClient } from "./transports";
|
|
|
4
4
|
import {
|
|
5
5
|
GetTemplateDefinitionResponse,
|
|
6
6
|
ListTemplatesResponse,
|
|
7
|
-
stringToSubstateId,
|
|
8
7
|
substateIdToString,
|
|
9
8
|
SubstatesListRequest,
|
|
10
9
|
} from "@tari-project/typescript-bindings";
|
|
@@ -46,11 +45,11 @@ export class IndexerProvider implements TariProvider {
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
public async listSubstates({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
filter_by_template,
|
|
49
|
+
filter_by_type,
|
|
50
|
+
limit,
|
|
51
|
+
offset,
|
|
52
|
+
}: ListSubstatesRequest): Promise<ListSubstatesResponse> {
|
|
54
53
|
const resp = await this.client.listSubstates({
|
|
55
54
|
filter_by_template,
|
|
56
55
|
filter_by_type,
|
|
@@ -99,7 +98,7 @@ export class IndexerProvider implements TariProvider {
|
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
public async getTemplateDefinition(template_address: string): Promise<GetTemplateDefinitionResponse> {
|
|
102
|
-
|
|
101
|
+
const resp = await this.client.getTemplateDefinition({ template_address });
|
|
103
102
|
return resp;
|
|
104
103
|
}
|
|
105
104
|
}
|
|
@@ -129,6 +129,7 @@ export class IndexerProviderClient {
|
|
|
129
129
|
|
|
130
130
|
async __invokeRpc(method: string, params: object | null = null) {
|
|
131
131
|
const id = this.id++;
|
|
132
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
132
133
|
const response = await this.transport.sendRequest<any>(
|
|
133
134
|
{
|
|
134
135
|
method,
|
|
@@ -19,8 +19,8 @@ export default class FetchRpcTransport implements RpcTransport {
|
|
|
19
19
|
headers["Authorization"] = `Bearer ${options.token}`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const signal = controller.signal;
|
|
24
24
|
|
|
25
25
|
const timeoutId = options.timeout_millis
|
|
26
26
|
? setTimeout(() => {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/metamask-signer",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
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",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
2
3
|
import {
|
|
3
4
|
SubmitTransactionRequest,
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
ConfidentialViewVaultBalanceRequest,
|
|
18
19
|
ListAccountNftRequest,
|
|
19
20
|
ListAccountNftResponse,
|
|
20
|
-
SubstateType,
|
|
21
21
|
} from "@tari-project/typescript-bindings";
|
|
22
22
|
|
|
23
23
|
export const MetamaskNotInstalled = "METAMASK_NOT_INSTALLED";
|
|
@@ -154,11 +154,11 @@ export class MetamaskTariSigner implements TariSigner {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
public async getConfidentialVaultBalances({
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
vault_id,
|
|
158
|
+
maximum_expected_value,
|
|
159
|
+
minimum_expected_value,
|
|
160
|
+
view_key_id,
|
|
161
|
+
}: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances> {
|
|
162
162
|
const resp = await this.metamaskRequest("getConfidentialVaultBalances", {
|
|
163
163
|
view_key_id,
|
|
164
164
|
vault_id,
|
|
@@ -179,7 +179,7 @@ export class MetamaskTariSigner implements TariSigner {
|
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
private async metamaskRequest<T>(method: string, params:
|
|
182
|
+
private async metamaskRequest<T>(method: string, params: object): Promise<T> {
|
|
183
183
|
console.log("Metamask request:", method, params);
|
|
184
184
|
const resp = await this.metamask.request({
|
|
185
185
|
method: "wallet_invokeSnap",
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { MetaMaskInpageProvider } from
|
|
2
|
-
|
|
1
|
+
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
3
2
|
|
|
4
3
|
export type GetSnapsResponse = Record<string, Snap>;
|
|
5
4
|
|
|
6
5
|
export type Snap = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
permissionName: string;
|
|
7
|
+
id: string;
|
|
8
|
+
version: string;
|
|
9
|
+
initialPermissions: Record<string, unknown>;
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -16,13 +15,10 @@ export type Snap = {
|
|
|
16
15
|
* @param provider - The MetaMask inpage provider.
|
|
17
16
|
* @returns The snaps installed in MetaMask.
|
|
18
17
|
*/
|
|
19
|
-
export const getSnaps = async (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
method: 'wallet_getSnaps',
|
|
24
|
-
})) as unknown as GetSnapsResponse;
|
|
25
|
-
|
|
18
|
+
export const getSnaps = async (provider: MetaMaskInpageProvider): Promise<GetSnapsResponse> =>
|
|
19
|
+
(await provider.request({
|
|
20
|
+
method: "wallet_getSnaps",
|
|
21
|
+
})) as unknown as GetSnapsResponse;
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
24
|
* Connect a snap to MetaMask.
|
|
@@ -30,14 +26,11 @@ export const getSnaps = async (
|
|
|
30
26
|
* @param snapId - The ID of the snap.
|
|
31
27
|
* @param params - The params to pass with the snap to connect.
|
|
32
28
|
*/
|
|
33
|
-
export const connectSnap = async (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
method: 'wallet_requestSnaps',
|
|
39
|
-
params: snaps,
|
|
40
|
-
});
|
|
29
|
+
export const connectSnap = async (provider: MetaMaskInpageProvider, snaps: Record<string, { version?: string }>) => {
|
|
30
|
+
await provider.request({
|
|
31
|
+
method: "wallet_requestSnaps",
|
|
32
|
+
params: snaps,
|
|
33
|
+
});
|
|
41
34
|
};
|
|
42
35
|
|
|
43
36
|
/**
|
|
@@ -47,24 +40,22 @@ export const connectSnap = async (
|
|
|
47
40
|
* @returns The snap object returned by the extension.
|
|
48
41
|
*/
|
|
49
42
|
export const getSnap = async (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
provider: MetaMaskInpageProvider,
|
|
44
|
+
snapId: string,
|
|
45
|
+
version?: string,
|
|
53
46
|
): Promise<Snap | undefined> => {
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
try {
|
|
48
|
+
const snaps = await getSnaps(provider);
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
console.log('Failed to obtain installed snap', e);
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
50
|
+
return Object.values(snaps).find((snap) => snap.id === snapId && (!version || snap.version === version));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.log("Failed to obtain installed snap", e);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
65
55
|
};
|
|
66
56
|
|
|
67
|
-
|
|
57
|
+
/** @public */
|
|
58
|
+
export const isLocalSnap = (snapId: string) => snapId.startsWith("local:");
|
|
68
59
|
|
|
69
60
|
/**
|
|
70
61
|
* Detect if the wallet injecting the ethereum object is MetaMask Flask.
|
|
@@ -72,15 +63,15 @@ export const isLocalSnap = (snapId: string) => snapId.startsWith('local:');
|
|
|
72
63
|
* @returns True if the MetaMask version is Flask, false otherwise.
|
|
73
64
|
*/
|
|
74
65
|
export const isFlask = async (provider: MetaMaskInpageProvider) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
try {
|
|
67
|
+
const clientVersion = await provider.request({
|
|
68
|
+
method: "web3_clientVersion",
|
|
69
|
+
});
|
|
79
70
|
|
|
80
|
-
|
|
71
|
+
const isFlaskDetected = (clientVersion as string[])?.includes("flask");
|
|
81
72
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
73
|
+
return Boolean(provider && isFlaskDetected);
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
};
|