@tari-project/tarijs 0.4.0 → 0.4.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 (120) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +36 -0
  2. package/.github/PULL_REQUEST_TEMPLATE.md +27 -0
  3. package/.github/dependabot.yml +8 -0
  4. package/.github/workflows/ci.yml +25 -0
  5. package/.github/workflows/npm_publish.yml +26 -0
  6. package/.github/workflows/pr_signed_commits_check.yml +19 -0
  7. package/.github/workflows/pr_title.yml +30 -0
  8. package/.moon/toolchain.yml +6 -0
  9. package/.moon/workspace.yml +32 -0
  10. package/.prettierrc +12 -0
  11. package/.prototools +9 -0
  12. package/CODEOWNERS +3 -0
  13. package/README.md +47 -0
  14. package/TODO.md +12 -0
  15. package/package.json +4 -28
  16. package/packages/builders/moon.yml +55 -0
  17. package/packages/builders/package.json +30 -0
  18. package/packages/builders/src/helpers/index.ts +2 -0
  19. package/packages/builders/src/helpers/submitTransaction.ts +97 -0
  20. package/packages/builders/src/helpers/workspace.ts +32 -0
  21. package/packages/builders/src/index.ts +9 -0
  22. package/packages/builders/src/transaction/TransactionBuilder.ts +276 -0
  23. package/packages/builders/src/transaction/TransactionRequest.ts +93 -0
  24. package/packages/builders/src/transaction/index.ts +2 -0
  25. package/packages/builders/tsconfig.json +24 -0
  26. package/packages/metamask_provider/moon.yml +55 -0
  27. package/packages/metamask_provider/package.json +30 -0
  28. package/packages/metamask_provider/src/index.ts +232 -0
  29. package/packages/metamask_provider/src/utils.ts +86 -0
  30. package/packages/metamask_provider/tsconfig.json +21 -0
  31. package/packages/tari_permissions/moon.yml +55 -0
  32. package/packages/tari_permissions/package.json +26 -0
  33. package/packages/tari_permissions/src/index.ts +1 -0
  34. package/packages/tari_permissions/src/tari_permissions.ts +312 -0
  35. package/packages/tari_permissions/tsconfig.json +15 -0
  36. package/packages/tari_provider/moon.yml +55 -0
  37. package/packages/tari_provider/package.json +27 -0
  38. package/packages/tari_provider/src/TariProvider.ts +35 -0
  39. package/packages/tari_provider/src/index.ts +3 -0
  40. package/packages/tari_provider/src/types.ts +82 -0
  41. package/packages/tari_provider/tsconfig.json +11 -0
  42. package/packages/tari_universe/moon.yml +55 -0
  43. package/packages/tari_universe/package.json +31 -0
  44. package/packages/tari_universe/src/index.ts +3 -0
  45. package/packages/tari_universe/src/provider.ts +135 -0
  46. package/packages/tari_universe/src/types.ts +33 -0
  47. package/packages/tari_universe/src/utils.ts +23 -0
  48. package/packages/tari_universe/tsconfig.json +24 -0
  49. package/packages/tarijs/integration-tests/.env +1 -0
  50. package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +191 -0
  51. package/packages/tarijs/moon.yml +63 -0
  52. package/packages/tarijs/package.json +39 -0
  53. package/packages/tarijs/src/index.ts +69 -0
  54. package/packages/tarijs/src/network.ts +8 -0
  55. package/packages/tarijs/src/templates/Account.ts +98 -0
  56. package/packages/tarijs/src/templates/Pool.ts +42 -0
  57. package/packages/tarijs/src/templates/Tariswap.ts +101 -0
  58. package/packages/tarijs/src/templates/TemplateFactory.ts +22 -0
  59. package/packages/tarijs/src/templates/TestFaucet.ts +72 -0
  60. package/{dist/utils.js → packages/tarijs/src/utils.ts} +4 -3
  61. package/packages/tarijs/tsconfig.json +39 -0
  62. package/packages/tarijs/vitest.config.ts +9 -0
  63. package/packages/tarijs_types/moon.yml +55 -0
  64. package/packages/tarijs_types/package.json +27 -0
  65. package/packages/tarijs_types/src/Amount.ts +113 -0
  66. package/packages/tarijs_types/src/Arg.ts +3 -0
  67. package/packages/tarijs_types/src/ComponentAddress.ts +3 -0
  68. package/packages/tarijs_types/src/ConfidentialClaim.ts +9 -0
  69. package/packages/tarijs_types/src/ConfidentialOutput.ts +9 -0
  70. package/packages/tarijs_types/src/ConfidentialOutputStatement.ts +10 -0
  71. package/packages/tarijs_types/src/ConfidentialStatement.ts +9 -0
  72. package/packages/tarijs_types/src/ConfidentialWithdrawProof.ts +8 -0
  73. package/packages/tarijs_types/src/ElgamalVerifiableBalance.ts +4 -0
  74. package/packages/tarijs_types/src/Epoch.ts +3 -0
  75. package/packages/tarijs_types/src/FinalizeResult.ts +17 -0
  76. package/packages/tarijs_types/src/Instruction.ts +29 -0
  77. package/packages/tarijs_types/src/ResourceAddress.ts +3 -0
  78. package/packages/tarijs_types/src/SubstateDiff.ts +9 -0
  79. package/packages/tarijs_types/src/SubstateRequirement.ts +6 -0
  80. package/packages/tarijs_types/src/TemplateAddress.ts +3 -0
  81. package/packages/tarijs_types/src/Transaction.ts +16 -0
  82. package/packages/tarijs_types/src/TransactionId.ts +4 -0
  83. package/packages/tarijs_types/src/TransactionResult.ts +26 -0
  84. package/packages/tarijs_types/src/TransactionSignature.ts +4 -0
  85. package/packages/tarijs_types/src/UnsignedTransaction.ts +15 -0
  86. package/packages/tarijs_types/src/VersionedSubstateId.ts +6 -0
  87. package/packages/tarijs_types/src/ViewableBalanceProof.ts +12 -0
  88. package/packages/tarijs_types/src/Workspace.ts +3 -0
  89. package/packages/tarijs_types/src/index.ts +25 -0
  90. package/packages/tarijs_types/tsconfig.json +15 -0
  91. package/packages/wallet_daemon/moon.yml +55 -0
  92. package/packages/wallet_daemon/package.json +29 -0
  93. package/packages/wallet_daemon/src/index.ts +5 -0
  94. package/packages/wallet_daemon/src/provider.ts +263 -0
  95. package/packages/wallet_daemon/src/webrtc.ts +229 -0
  96. package/packages/wallet_daemon/src/webrtc_transport.ts +27 -0
  97. package/packages/wallet_daemon/tsconfig.json +21 -0
  98. package/packages/walletconnect/moon.yml +55 -0
  99. package/packages/walletconnect/package.json +32 -0
  100. package/packages/walletconnect/src/index.ts +274 -0
  101. package/packages/walletconnect/tsconfig.json +21 -0
  102. package/pnpm-workspace.yaml +14 -0
  103. package/tsconfig.json +42 -0
  104. package/dist/index.d.ts +0 -14
  105. package/dist/index.js +0 -13
  106. package/dist/network.d.ts +0 -8
  107. package/dist/network.js +0 -9
  108. package/dist/templates/Account.d.ts +0 -65
  109. package/dist/templates/Account.js +0 -31
  110. package/dist/templates/Pool.d.ts +0 -29
  111. package/dist/templates/Pool.js +0 -20
  112. package/dist/templates/Tariswap.d.ts +0 -64
  113. package/dist/templates/Tariswap.js +0 -36
  114. package/dist/templates/TemplateFactory.d.ts +0 -9
  115. package/dist/templates/TemplateFactory.js +0 -18
  116. package/dist/templates/TestFaucet.d.ts +0 -49
  117. package/dist/templates/TestFaucet.js +0 -31
  118. package/dist/templates/index.js +0 -5
  119. package/dist/utils.d.ts +0 -2
  120. /package/{dist/templates/index.d.ts → packages/tarijs/src/templates/index.ts} +0 -0
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: "[TITLE]"
5
+ labels: 'bug-report'
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS & Version: [e.g. iOS 10.2.1]
28
+ - Browser & Version [e.g. chrome v71.0.12345]
29
+
30
+ **Smartphone (please complete the following information):**
31
+ - Device: [e.g. iPhone6]
32
+ - OS: [e.g. iOS8.1]
33
+ - Browser & Version [e.g. stock browser v0.1.2]
34
+
35
+ **Additional context**
36
+ Add any other context about the problem here.
@@ -0,0 +1,27 @@
1
+ Description
2
+ ---
3
+
4
+ Motivation and Context
5
+ ---
6
+
7
+ How Has This Been Tested?
8
+ ---
9
+
10
+ What process can a PR reviewer use to test or verify this change?
11
+ ---
12
+
13
+ <!-- Checklist -->
14
+ <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit
15
+ tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. -->
16
+
17
+
18
+ Breaking Changes
19
+ ---
20
+
21
+ - [x] None
22
+ - [ ] Requires data directory on base node to be deleted
23
+ - [ ] Requires hard fork
24
+ - [ ] Other - Please specify
25
+
26
+ <!-- Does this include a breaking change? If so, include this line as a footer -->
27
+ <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->
@@ -0,0 +1,8 @@
1
+ ---
2
+ version: 2
3
+ updates:
4
+ # Maintain dependencies for GitHub Actions
5
+ - package-ecosystem: "github-actions"
6
+ directory: "/"
7
+ schedule:
8
+ interval: "weekly"
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: CI
3
+
4
+ 'on':
5
+ pull_request:
6
+ types:
7
+ - opened
8
+ - reopened
9
+ - synchronize
10
+
11
+ concurrency:
12
+ # https://docs.github.com/en/actions/examples/using-concurrency-expressions-and-a-test-matrix
13
+ group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
14
+ cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/v') || github.ref != 'refs/heads/main' }}
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: 'moonrepo/setup-toolchain@v0'
22
+ with:
23
+ auto-install: true
24
+ - run: pnpm install
25
+ - run: moon :build
@@ -0,0 +1,26 @@
1
+ ---
2
+ # Publishing the package to the npm registry when the version number changes
3
+ # See https://github.com/marketplace/actions/npm-publish for more information
4
+ name: Publish Package to npmjs
5
+
6
+ on:
7
+ push:
8
+ branches: main
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: 'moonrepo/setup-toolchain@v0'
16
+ with:
17
+ auto-install: true
18
+ - run: pnpm install --frozen-lockfile
19
+ - run: moon :build
20
+ - name: Publish
21
+ run: |
22
+ pnpm config set git-checks false
23
+ pnpm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
24
+ pnpm publish --access public --no-git-checks -r
25
+ env:
26
+ NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,19 @@
1
+ ---
2
+ # Checks if the comments are signed or not
3
+ name: PR - Signed commits check
4
+
5
+ 'on':
6
+ pull_request_target
7
+
8
+ permissions: {}
9
+
10
+ jobs:
11
+ check-signed-commits:
12
+ name: Check signed commits in PR
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: read
16
+ pull-requests: write
17
+ steps:
18
+ - name: Check signed commits in PR
19
+ uses: 1Password/check-signed-commits-action@v1
@@ -0,0 +1,30 @@
1
+ ---
2
+ # Checks that PR titles conform to Conventional Commits
3
+ # See https://www.conventionalcommits.org/en/v1.0.0/ for more information
4
+ name: PR
5
+
6
+ 'on':
7
+ pull_request:
8
+ types:
9
+ - opened
10
+ - reopened
11
+ - edited
12
+ - synchronize
13
+
14
+ concurrency:
15
+ group: ${{ github.workflow }}-${{ github.ref }}
16
+ cancel-in-progress: true
17
+
18
+ jobs:
19
+ check-title:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - name: install
23
+ run: |
24
+ npm install -g @commitlint/cli @commitlint/config-conventional
25
+ echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
26
+ - name: lint
27
+ run: |
28
+ echo "$PR_TITLE" | commitlint
29
+ env:
30
+ PR_TITLE: ${{github.event.pull_request.title}}
@@ -0,0 +1,6 @@
1
+ # Enable Node.js and override default settings
2
+ language: 'typescript'
3
+ node:
4
+ packageManager: 'pnpm'
5
+ typescript:
6
+ syncProjectReferences: true
@@ -0,0 +1,32 @@
1
+ # https://moonrepo.dev/docs/config/workspace
2
+ $schema: 'https://moonrepo.dev/schemas/workspace.json'
3
+
4
+ # Require a specific version of moon while running commands, otherwise fail.
5
+ # versionConstraint: '>=1.0.0'
6
+
7
+ # Extend and inherit an external configuration file. Must be a valid HTTPS URL or file system path.
8
+ # extends: './shared/workspace.yml'
9
+
10
+ # REQUIRED: A map of all projects found within the workspace, or a list or file system globs.
11
+ # When using a map, each entry requires a unique project ID as the map key, and a file system
12
+ # path to the project folder as the map value. File paths are relative from the workspace root,
13
+ # and cannot reference projects located outside the workspace boundary.
14
+ projects:
15
+ - 'apps/*'
16
+ - 'packages/*'
17
+
18
+
19
+
20
+ # Configures the version control system to utilize within the workspace. A VCS
21
+ # is required for determining touched (added, modified, etc) files, calculating file hashes,
22
+ # computing affected files, and much more.
23
+ vcs:
24
+ # The client to use when managing the repository.
25
+ # Accepts "git". Defaults to "git".
26
+ manager: 'git'
27
+
28
+ # The default branch (master/main/trunk) in the repository for comparing the
29
+ # local branch against. For git, this is is typically "master" or "main",
30
+ # and must include the remote prefix (before /).
31
+ defaultBranch: 'main'
32
+
package/.prettierrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "printWidth": 120,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": false,
7
+ "trailingComma": "all",
8
+ "bracketSpacing": true,
9
+ "bracketSameLine": false,
10
+ "arrowParens": "always",
11
+ "endOfLine": "auto"
12
+ }
package/.prototools ADDED
@@ -0,0 +1,9 @@
1
+ moon = "1.31.0"
2
+ node = "22.13.1"
3
+ pnpm = "9.15.3"
4
+
5
+ [plugins]
6
+ moon = "https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
7
+
8
+ [settings]
9
+ auto-install = true
package/CODEOWNERS ADDED
@@ -0,0 +1,3 @@
1
+ # CI/CD-related files require a review by the devops team
2
+ .github/**/* @tari-project/devops
3
+ CODEOWNERS @tari-project/devops
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # tari.js
2
+
3
+ This project provides a unified TypeScript library to connect and send requests to a Tari wallet. It's intended for web application developers that want to interact with a Tari wallet (connect, get substates, submit transactions, etc.).
4
+
5
+ Tari wallets supported:
6
+ * Tari Wallet Daemon
7
+ * MetaMask through the [tari-snap](https://github.com/tari-project/tari-snap)
8
+
9
+ An example site (under the `example` folder) contains a web project that allows the user to connect to any type of Tari wallet and perform common actions.
10
+
11
+ Please read the [TODO](TODO.md) file for upcoming features.
12
+
13
+ ## Library building
14
+
15
+ You must have the [tari-dan](https://github.com/tari-project/tari-dan) repo cloned at the same folder level as this repo.
16
+
17
+ To build the library:
18
+ First you must install [proto](https://moonrepo.dev/proto) to manage node and pnpm versions
19
+ ```shell
20
+ proto use
21
+ pnpm install
22
+ moon tarijs:build
23
+ ```
24
+
25
+ The bundled files for deployment or publication will be located under the `dist` folder.
26
+
27
+ ## Running the example site
28
+
29
+ To run the example site you will need to:
30
+ * Compile the library following the previous section.
31
+ * Have access to a Tari Wallet Daemon and to the Tari MetaMask Snap.
32
+ * Copy the `example/.env.example` file to `example/.env` and edit the correct environment variable values.
33
+
34
+ To run in development mode, in the packages/tarijs folder:
35
+ ```shell
36
+ cd example
37
+ moon tarijs:build
38
+ pnpm run dev
39
+ ```
40
+
41
+ For building and distribution, in the packages/tarijs folder
42
+ ```shell
43
+ cd example
44
+ moon tarijs:build
45
+ ```
46
+ The distribution files will be under the `example/dist` folder.
47
+
package/TODO.md ADDED
@@ -0,0 +1,12 @@
1
+ # TODO
2
+
3
+ - In the wallet provider interface:
4
+ - Full TypeScript class definitions for transaction requests (instructions, etc.).
5
+ - Common return types for both types of wallets.
6
+ - Implement `getSubstate` method for the Tari Wallet Daemon provider.
7
+ - Add account balance to `getAccountData` method for the Tari Wallet Daemon provider.
8
+ - For the example site:
9
+ - The button should indicate when a connection was established.
10
+ - The `TariConnect` button could be made into a reusable React component, ready to be imported by any web.
11
+ - Typescript-bindings
12
+ - [Types refactor and cleanup](https://github.com/tari-project/tari.js/issues/29)
package/package.json CHANGED
@@ -1,39 +1,15 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "",
5
5
  "type": "module",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
6
  "keywords": [],
10
7
  "author": "",
11
8
  "license": "ISC",
12
- "dependencies": {
13
- "@metamask/providers": "^18.2.0",
14
- "@tari-project/typescript-bindings": "^1.4.0",
15
- "@tari-project/metamask-provider": "^0.4.0",
16
- "@tari-project/tari-permissions": "^0.4.0",
17
- "@tari-project/tari-provider": "^0.4.0",
18
- "@tari-project/tari-universe-provider": "^0.4.0",
19
- "@tari-project/tarijs-types": "^0.4.0",
20
- "@tari-project/tarijs-builders": "^0.4.0",
21
- "@tari-project/wallet-connect-provider": "^0.4.0",
22
- "@tari-project/wallet-daemon-provider": "^0.4.0"
9
+ "engines": {
10
+ "node": "22.13.1"
23
11
  },
24
12
  "devDependencies": {
25
- "@types/node": "^22.13.1",
26
- "typescript": "^5.0.4",
27
- "vite": "^6.1.0",
28
- "vitest": "^3.0.4"
29
- },
30
- "files": [
31
- "/dist"
32
- ],
33
- "main": "dist/index.js",
34
- "types": "dist/index.d.ts",
35
- "scripts": {
36
- "build": "tsc -b",
37
- "integration-tests": "vitest run integration-tests"
13
+ "@moonrepo/cli": "^1.32.1"
38
14
  }
39
15
  }
@@ -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)"
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@tari-project/tarijs-builders",
3
+ "version": "0.4.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc -b"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "@tari-project/tari-provider": "workspace:^",
17
+ "@tari-project/tari-universe-provider": "workspace:^",
18
+ "@tari-project/tarijs-types": "workspace:^",
19
+ "@tari-project/typescript-bindings": "catalog:"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "catalog:",
23
+ "typescript": "catalog:"
24
+ },
25
+ "files": [
26
+ "/dist"
27
+ ],
28
+ "main": "dist/index.js",
29
+ "types": "dist/index.d.ts"
30
+ }
@@ -0,0 +1,2 @@
1
+ export { buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult } from "./submitTransaction";
2
+ export { fromWorkspace, toWorkspace } from "./workspace";
@@ -0,0 +1,97 @@
1
+ import { TariUniverseProvider } from "@tari-project/tari-universe-provider";
2
+ import { TariProvider, SubmitTransactionRequest, SubstateRequirement } from "@tari-project/tari-provider";
3
+ import {
4
+ Transaction,
5
+ TransactionResult,
6
+ TransactionStatus,
7
+ DownSubstates,
8
+ UpSubstates,
9
+ FinalizeResultStatus,
10
+ TxResultAccept,
11
+ SubmitTxResult
12
+ } from "@tari-project/tarijs-types";
13
+
14
+ export function buildTransactionRequest(
15
+ transaction: Transaction,
16
+ accountId: number,
17
+ requiredSubstates: SubstateRequirement[],
18
+ inputRefs = [],
19
+ isDryRun = false,
20
+ network = 0,
21
+ isSealSignerAuthorized = true,
22
+ detectInputsUseUnversioned = true,
23
+ ): SubmitTransactionRequest {
24
+ return {
25
+ //TODO refactor SubTxReq type to not use 'object[]' and types match
26
+ // https://github.com/tari-project/tari.js/issues/25
27
+ network,
28
+ account_id: accountId,
29
+ instructions: transaction.instructions as object[],
30
+ fee_instructions: transaction.feeInstructions as object[],
31
+ inputs: transaction.inputs,
32
+ input_refs: inputRefs as object[],
33
+ required_substates: requiredSubstates,
34
+ is_dry_run: isDryRun,
35
+ min_epoch: transaction.minEpoch ?? null,
36
+ max_epoch: transaction.maxEpoch ?? null,
37
+ is_seal_signer_authorized: isSealSignerAuthorized,
38
+ detect_inputs_use_unversioned: detectInputsUseUnversioned,
39
+ };
40
+ }
41
+
42
+ export async function submitAndWaitForTransaction(
43
+ provider: TariProvider,
44
+ req: SubmitTransactionRequest,
45
+ ): Promise<SubmitTxResult> {
46
+ try {
47
+ const response = await provider.submitTransaction(req);
48
+ const result = await waitForTransactionResult(provider, response.transaction_id);
49
+
50
+ return {
51
+ response,
52
+ result,
53
+ };
54
+ } catch (e) {
55
+ throw new Error(`Transaction failed: ${e}`);
56
+ }
57
+ }
58
+
59
+ export async function waitForTransactionResult(
60
+ provider: TariProvider | TariUniverseProvider,
61
+ transactionId: string,
62
+ ): Promise<TransactionResult> {
63
+ // eslint-disable-next-line no-constant-condition
64
+ while (true) {
65
+ const resp = await provider.getTransactionResult(transactionId);
66
+ const FINALIZED_STATUSES = [
67
+ TransactionStatus.Accepted,
68
+ TransactionStatus.Rejected,
69
+ TransactionStatus.InvalidTransaction,
70
+ TransactionStatus.OnlyFeeAccepted,
71
+ TransactionStatus.DryRun,
72
+ ];
73
+
74
+ if (resp.status == TransactionStatus.Rejected) {
75
+ throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
76
+ }
77
+ if (FINALIZED_STATUSES.includes(resp.status)) {
78
+ return resp as any as TransactionResult; //TODO fix: type mismatch (https://github.com/tari-project/tari.js/issues/29)
79
+ }
80
+ await new Promise((resolve) => setTimeout(resolve, 1000));
81
+ }
82
+ }
83
+
84
+ export function getAcceptResultSubstates(
85
+ txResult: TransactionResult,
86
+ ): { upSubstates: UpSubstates; downSubstates: DownSubstates } | undefined {
87
+ const result = txResult.result?.result;
88
+
89
+ if (result && isAccept(result)) {
90
+ return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
91
+ }
92
+ return undefined;
93
+ }
94
+
95
+ function isAccept(result: FinalizeResultStatus): result is TxResultAccept {
96
+ return "Accept" in result;
97
+ }
@@ -0,0 +1,32 @@
1
+ import { WorkspaceArg } from "@tari-project/tarijs-types";
2
+
3
+ /**
4
+ *
5
+ * @param key workspace name
6
+ * @returns encoded Uint8Array value
7
+ * @example
8
+ * key: "0" -> [ 48 ]
9
+ * key: "0.0" -> [ 48, 46, 48 ]
10
+ * key: "0.1" -> [ 48, 46, 49 ]
11
+ *
12
+ * key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
13
+ * key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
14
+ * key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
15
+ */
16
+ export function toWorkspace(key: string): number[] {
17
+ const encoder = new TextEncoder();
18
+ return Array.from(encoder.encode(key));
19
+ }
20
+
21
+ /**
22
+ *
23
+ * @param key workspace name
24
+ * @returns formatted Workspace data
25
+ * @example
26
+ * key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
27
+ */
28
+ export function fromWorkspace(key: string): WorkspaceArg {
29
+ const encoder = new TextEncoder();
30
+ const encodedKey = encoder.encode(key);
31
+ return { Workspace: Array.from(encodedKey) };
32
+ }
@@ -0,0 +1,9 @@
1
+ export * from "@tari-project/tarijs-types";
2
+ export { TransactionBuilder, TransactionRequest, TariMethodDefinition, TariFunctionDefinition } from "./transaction";
3
+ export {
4
+ buildTransactionRequest,
5
+ submitAndWaitForTransaction,
6
+ waitForTransactionResult,
7
+ fromWorkspace,
8
+ toWorkspace,
9
+ } from "./helpers";