@tari-project/tarijs 0.3.1 → 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 (199) 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 +9 -8
  14. package/TODO.md +12 -0
  15. package/package.json +6 -24
  16. package/packages/builders/moon.yml +55 -0
  17. package/packages/builders/package.json +30 -0
  18. package/packages/builders/src/helpers/submitTransaction.ts +97 -0
  19. package/{dist/builders/helpers/workspace.js → packages/builders/src/helpers/workspace.ts} +10 -7
  20. package/packages/builders/src/index.ts +9 -0
  21. package/packages/builders/src/transaction/TransactionBuilder.ts +276 -0
  22. package/packages/builders/src/transaction/TransactionRequest.ts +93 -0
  23. package/packages/builders/src/transaction/index.ts +2 -0
  24. package/packages/builders/tsconfig.json +24 -0
  25. package/packages/metamask_provider/moon.yml +55 -0
  26. package/packages/metamask_provider/package.json +30 -0
  27. package/packages/metamask_provider/src/index.ts +232 -0
  28. package/packages/metamask_provider/src/utils.ts +86 -0
  29. package/packages/metamask_provider/tsconfig.json +21 -0
  30. package/packages/tari_permissions/moon.yml +55 -0
  31. package/packages/tari_permissions/package.json +26 -0
  32. package/packages/tari_permissions/src/index.ts +1 -0
  33. package/packages/tari_permissions/src/tari_permissions.ts +312 -0
  34. package/packages/tari_permissions/tsconfig.json +15 -0
  35. package/packages/tari_provider/moon.yml +55 -0
  36. package/packages/tari_provider/package.json +27 -0
  37. package/packages/tari_provider/src/TariProvider.ts +35 -0
  38. package/packages/tari_provider/src/index.ts +3 -0
  39. package/packages/tari_provider/src/types.ts +82 -0
  40. package/packages/tari_provider/tsconfig.json +11 -0
  41. package/packages/tari_universe/moon.yml +55 -0
  42. package/packages/tari_universe/package.json +31 -0
  43. package/{dist/providers/tari_universe/index.d.ts → packages/tari_universe/src/index.ts} +1 -1
  44. package/packages/tari_universe/src/provider.ts +135 -0
  45. package/{dist/providers/tari_universe/types.d.ts → packages/tari_universe/src/types.ts} +20 -17
  46. package/packages/tari_universe/src/utils.ts +23 -0
  47. package/packages/tari_universe/tsconfig.json +24 -0
  48. package/packages/tarijs/integration-tests/.env +1 -0
  49. package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +191 -0
  50. package/packages/tarijs/moon.yml +63 -0
  51. package/packages/tarijs/package.json +39 -0
  52. package/packages/tarijs/src/index.ts +69 -0
  53. package/packages/tarijs/src/network.ts +8 -0
  54. package/packages/tarijs/src/templates/Account.ts +98 -0
  55. package/packages/tarijs/src/templates/Pool.ts +42 -0
  56. package/packages/tarijs/src/templates/Tariswap.ts +101 -0
  57. package/packages/tarijs/src/templates/TemplateFactory.ts +22 -0
  58. package/packages/tarijs/src/templates/TestFaucet.ts +72 -0
  59. package/{dist/utils.js → packages/tarijs/src/utils.ts} +4 -3
  60. package/packages/tarijs/tsconfig.json +39 -0
  61. package/packages/tarijs/vitest.config.ts +9 -0
  62. package/packages/tarijs_types/moon.yml +55 -0
  63. package/packages/tarijs_types/package.json +27 -0
  64. package/packages/tarijs_types/src/Amount.ts +113 -0
  65. package/packages/tarijs_types/src/Arg.ts +3 -0
  66. package/packages/tarijs_types/src/ComponentAddress.ts +3 -0
  67. package/packages/tarijs_types/src/ConfidentialClaim.ts +9 -0
  68. package/packages/tarijs_types/src/ConfidentialOutput.ts +9 -0
  69. package/packages/tarijs_types/src/ConfidentialOutputStatement.ts +10 -0
  70. package/packages/tarijs_types/src/ConfidentialStatement.ts +9 -0
  71. package/packages/tarijs_types/src/ConfidentialWithdrawProof.ts +8 -0
  72. package/packages/tarijs_types/src/ElgamalVerifiableBalance.ts +4 -0
  73. package/packages/tarijs_types/src/Epoch.ts +3 -0
  74. package/packages/tarijs_types/src/FinalizeResult.ts +17 -0
  75. package/packages/tarijs_types/src/Instruction.ts +29 -0
  76. package/{dist/builders/types/ResourceAddress.js → packages/tarijs_types/src/ResourceAddress.ts} +2 -1
  77. package/{dist/builders/types/SubstateDiff.d.ts → packages/tarijs_types/src/SubstateDiff.ts} +4 -2
  78. package/{dist/builders/types/SubstateRequirement.d.ts → packages/tarijs_types/src/SubstateRequirement.ts} +3 -2
  79. package/{dist/builders/types/TemplateAddress.js → packages/tarijs_types/src/TemplateAddress.ts} +2 -1
  80. package/{dist/builders/types/Transaction.d.ts → packages/tarijs_types/src/Transaction.ts} +9 -8
  81. package/packages/tarijs_types/src/TransactionId.ts +4 -0
  82. package/packages/tarijs_types/src/TransactionResult.ts +26 -0
  83. package/packages/tarijs_types/src/TransactionSignature.ts +4 -0
  84. package/packages/tarijs_types/src/UnsignedTransaction.ts +15 -0
  85. package/{dist/builders/types/VersionedSubstateId.d.ts → packages/tarijs_types/src/VersionedSubstateId.ts} +3 -2
  86. package/packages/tarijs_types/src/ViewableBalanceProof.ts +12 -0
  87. package/{dist/builders/types/Workspace.d.ts → packages/tarijs_types/src/Workspace.ts} +1 -1
  88. package/{dist/builders/types/index.d.ts → packages/tarijs_types/src/index.ts} +4 -3
  89. package/packages/tarijs_types/tsconfig.json +15 -0
  90. package/packages/wallet_daemon/moon.yml +55 -0
  91. package/packages/wallet_daemon/package.json +29 -0
  92. package/{dist/providers/wallet_daemon/index.d.ts → packages/wallet_daemon/src/index.ts} +3 -1
  93. package/packages/wallet_daemon/src/provider.ts +263 -0
  94. package/packages/wallet_daemon/src/webrtc.ts +229 -0
  95. package/packages/wallet_daemon/src/webrtc_transport.ts +27 -0
  96. package/packages/wallet_daemon/tsconfig.json +21 -0
  97. package/packages/walletconnect/moon.yml +55 -0
  98. package/packages/walletconnect/package.json +32 -0
  99. package/packages/walletconnect/src/index.ts +274 -0
  100. package/packages/walletconnect/tsconfig.json +21 -0
  101. package/pnpm-workspace.yaml +14 -0
  102. package/tsconfig.json +42 -0
  103. package/dist/builders/helpers/index.js +0 -2
  104. package/dist/builders/helpers/submitTransaction.d.ts +0 -13
  105. package/dist/builders/helpers/submitTransaction.js +0 -62
  106. package/dist/builders/helpers/workspace.d.ts +0 -23
  107. package/dist/builders/index.d.ts +0 -3
  108. package/dist/builders/index.js +0 -3
  109. package/dist/builders/transaction/TransactionBuilder.d.ts +0 -44
  110. package/dist/builders/transaction/TransactionBuilder.js +0 -164
  111. package/dist/builders/transaction/TransactionRequest.d.ts +0 -27
  112. package/dist/builders/transaction/TransactionRequest.js +0 -67
  113. package/dist/builders/transaction/index.d.ts +0 -2
  114. package/dist/builders/transaction/index.js +0 -2
  115. package/dist/builders/types/Amount.d.ts +0 -23
  116. package/dist/builders/types/Amount.js +0 -93
  117. package/dist/builders/types/Arg.d.ts +0 -1
  118. package/dist/builders/types/Arg.js +0 -1
  119. package/dist/builders/types/Builder.d.ts +0 -47
  120. package/dist/builders/types/Builder.js +0 -1
  121. package/dist/builders/types/ComponentAddress.d.ts +0 -1
  122. package/dist/builders/types/ComponentAddress.js +0 -1
  123. package/dist/builders/types/ConfidentialClaim.d.ts +0 -8
  124. package/dist/builders/types/ConfidentialClaim.js +0 -1
  125. package/dist/builders/types/ConfidentialOutput.d.ts +0 -8
  126. package/dist/builders/types/ConfidentialOutput.js +0 -1
  127. package/dist/builders/types/ConfidentialOutputStatement.d.ts +0 -9
  128. package/dist/builders/types/ConfidentialOutputStatement.js +0 -1
  129. package/dist/builders/types/ConfidentialStatement.d.ts +0 -8
  130. package/dist/builders/types/ConfidentialStatement.js +0 -1
  131. package/dist/builders/types/ConfidentialWithdrawProof.d.ts +0 -7
  132. package/dist/builders/types/ConfidentialWithdrawProof.js +0 -1
  133. package/dist/builders/types/ElgamalVerifiableBalance.d.ts +0 -4
  134. package/dist/builders/types/ElgamalVerifiableBalance.js +0 -1
  135. package/dist/builders/types/Epoch.d.ts +0 -1
  136. package/dist/builders/types/Epoch.js +0 -1
  137. package/dist/builders/types/FinalizeResult.d.ts +0 -20
  138. package/dist/builders/types/FinalizeResult.js +0 -1
  139. package/dist/builders/types/Instruction.d.ts +0 -56
  140. package/dist/builders/types/Instruction.js +0 -1
  141. package/dist/builders/types/ResourceAddress.d.ts +0 -1
  142. package/dist/builders/types/SubstateDiff.js +0 -1
  143. package/dist/builders/types/SubstateRequirement.js +0 -1
  144. package/dist/builders/types/TemplateAddress.d.ts +0 -1
  145. package/dist/builders/types/Transaction.js +0 -1
  146. package/dist/builders/types/TransactionId.d.ts +0 -1
  147. package/dist/builders/types/TransactionId.js +0 -1
  148. package/dist/builders/types/TransactionResult.d.ts +0 -22
  149. package/dist/builders/types/TransactionResult.js +0 -10
  150. package/dist/builders/types/TransactionSignature.d.ts +0 -4
  151. package/dist/builders/types/TransactionSignature.js +0 -1
  152. package/dist/builders/types/UnsignedTransaction.d.ts +0 -12
  153. package/dist/builders/types/UnsignedTransaction.js +0 -1
  154. package/dist/builders/types/VersionedSubstateId.js +0 -1
  155. package/dist/builders/types/ViewableBalanceProof.d.ts +0 -10
  156. package/dist/builders/types/ViewableBalanceProof.js +0 -2
  157. package/dist/builders/types/Workspace.js +0 -1
  158. package/dist/builders/types/index.js +0 -2
  159. package/dist/index.d.ts +0 -13
  160. package/dist/index.js +0 -12
  161. package/dist/providers/index.d.ts +0 -16
  162. package/dist/providers/index.js +0 -1
  163. package/dist/providers/metamask/index.d.ts +0 -30
  164. package/dist/providers/metamask/index.js +0 -168
  165. package/dist/providers/metamask/utils.d.ts +0 -38
  166. package/dist/providers/metamask/utils.js +0 -55
  167. package/dist/providers/tari_universe/index.js +0 -3
  168. package/dist/providers/tari_universe/provider.d.ts +0 -23
  169. package/dist/providers/tari_universe/provider.js +0 -89
  170. package/dist/providers/tari_universe/types.js +0 -1
  171. package/dist/providers/tari_universe/utils.d.ts +0 -2
  172. package/dist/providers/tari_universe/utils.js +0 -16
  173. package/dist/providers/types.d.ts +0 -69
  174. package/dist/providers/types.js +0 -10
  175. package/dist/providers/wallet_daemon/index.js +0 -3
  176. package/dist/providers/wallet_daemon/provider.d.ts +0 -43
  177. package/dist/providers/wallet_daemon/provider.js +0 -198
  178. package/dist/providers/wallet_daemon/tari_permissions.d.ts +0 -216
  179. package/dist/providers/wallet_daemon/tari_permissions.js +0 -282
  180. package/dist/providers/wallet_daemon/webrtc.d.ts +0 -20
  181. package/dist/providers/wallet_daemon/webrtc.js +0 -201
  182. package/dist/providers/wallet_daemon/webrtc_transport.d.ts +0 -10
  183. package/dist/providers/wallet_daemon/webrtc_transport.js +0 -18
  184. package/dist/providers/walletconnect/index.d.ts +0 -23
  185. package/dist/providers/walletconnect/index.js +0 -221
  186. package/dist/templates/Account.d.ts +0 -65
  187. package/dist/templates/Account.js +0 -31
  188. package/dist/templates/Pool.d.ts +0 -30
  189. package/dist/templates/Pool.js +0 -20
  190. package/dist/templates/Tariswap.d.ts +0 -65
  191. package/dist/templates/Tariswap.js +0 -36
  192. package/dist/templates/TemplateFactory.d.ts +0 -9
  193. package/dist/templates/TemplateFactory.js +0 -18
  194. package/dist/templates/TestFaucet.d.ts +0 -49
  195. package/dist/templates/TestFaucet.js +0 -31
  196. package/dist/templates/index.js +0 -5
  197. package/dist/utils.d.ts +0 -2
  198. /package/{dist/builders/helpers/index.d.ts → packages/builders/src/helpers/index.ts} +0 -0
  199. /package/{dist/templates/index.d.ts → packages/tarijs/src/templates/index.ts} +0 -0
@@ -0,0 +1,17 @@
1
+ import { FeeReceipt, InstructionResult, LogEntry, RejectReason } from "@tari-project/typescript-bindings";
2
+ import { SubstateDiff } from "./SubstateDiff";
3
+
4
+ export type TxResultAccept = { Accept: SubstateDiff };
5
+ export type TxResultAcceptFeeRejectRest = { AcceptFeeRejectRest: [SubstateDiff, RejectReason] };
6
+ export type TxResultReject = { Reject: RejectReason };
7
+
8
+ export type FinalizeResultStatus = TxResultAccept | TxResultAcceptFeeRejectRest | TxResultReject;
9
+
10
+ export interface FinalizeResult {
11
+ transaction_hash: Uint8Array;
12
+ events: Array<Event>;
13
+ logs: Array<LogEntry>;
14
+ execution_results: Array<InstructionResult>;
15
+ result: FinalizeResultStatus;
16
+ fee_receipt: FeeReceipt;
17
+ }
@@ -0,0 +1,29 @@
1
+ import { ComponentAddress, LogLevel } from "@tari-project/typescript-bindings";
2
+ import { Arg } from "./Arg";
3
+ import { ConfidentialClaim } from "./ConfidentialClaim";
4
+ import { Amount } from "./Amount";
5
+ import { ConfidentialOutput } from "./ConfidentialOutput";
6
+ import { TemplateAddress } from "./TemplateAddress";
7
+
8
+ export type Instruction =
9
+ | CreateAccount
10
+ | CallFunction
11
+ | CallMethod
12
+ | PutLastInstructionOutputOnWorkspace
13
+ | EmitLog
14
+ | ClaimBurn
15
+ | ClaimValidatorFees
16
+ | DropAllProofsInWorkspace
17
+ | CreateFreeTestCoins;
18
+
19
+ export type CreateAccount = { CreateAccount: { owner_public_key: string; workspace_bucket: string | null } };
20
+ export type CallFunction = { CallFunction: { template_address: TemplateAddress; function: string; args: Array<Arg> } };
21
+ export type CallMethod = { CallMethod: { component_address: ComponentAddress; method: string; args: Array<Arg> } };
22
+ export type PutLastInstructionOutputOnWorkspace = { PutLastInstructionOutputOnWorkspace: { key: number[] } };
23
+ export type EmitLog = { EmitLog: { level: LogLevel; message: string } };
24
+ export type ClaimBurn = { ClaimBurn: { claim: ConfidentialClaim } };
25
+ export type ClaimValidatorFees = { ClaimValidatorFees: { epoch: number; validator_public_key: string } };
26
+ export type DropAllProofsInWorkspace = "DropAllProofsInWorkspace";
27
+ export type CreateFreeTestCoins = {
28
+ CreateFreeTestCoins: { revealed_amount: Amount; output: ConfidentialOutput | null };
29
+ };
@@ -1,2 +1,3 @@
1
1
  //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
- export {};
2
+
3
+ export type ResourceAddress = string;
@@ -1,7 +1,9 @@
1
1
  import { Substate, SubstateId } from "@tari-project/typescript-bindings";
2
+
2
3
  export type UpSubstates = Array<[SubstateId, Substate]>;
3
4
  export type DownSubstates = Array<[SubstateId, number]>;
5
+
4
6
  export interface SubstateDiff {
5
- up_substates: UpSubstates;
6
- down_substates: DownSubstates;
7
+ up_substates: UpSubstates;
8
+ down_substates: DownSubstates;
7
9
  }
@@ -1,5 +1,6 @@
1
1
  import { SubstateId } from "@tari-project/typescript-bindings";
2
+
2
3
  export interface SubstateRequirement {
3
- substateId: SubstateId;
4
- version?: number;
4
+ substateId: SubstateId;
5
+ version?: number;
5
6
  }
@@ -1,2 +1,3 @@
1
1
  //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
- export {};
2
+
3
+ export type TemplateAddress = string;
@@ -3,13 +3,14 @@ import { SubstateRequirement } from "./SubstateRequirement";
3
3
  import { Epoch } from "./Epoch";
4
4
  import { VersionedSubstateId } from "./VersionedSubstateId";
5
5
  import { TransactionSignature } from "./TransactionSignature";
6
+
6
7
  export interface Transaction {
7
- id: string;
8
- feeInstructions: Array<Instruction>;
9
- instructions: Array<Instruction>;
10
- inputs: Array<SubstateRequirement>;
11
- minEpoch?: Epoch;
12
- maxEpoch?: Epoch;
13
- signatures: Array<TransactionSignature>;
14
- filledInputs: Array<VersionedSubstateId>;
8
+ id: string;
9
+ feeInstructions: Array<Instruction>;
10
+ instructions: Array<Instruction>;
11
+ inputs: Array<SubstateRequirement>;
12
+ minEpoch?: Epoch;
13
+ maxEpoch?: Epoch;
14
+ signatures: Array<TransactionSignature>;
15
+ filledInputs: Array<VersionedSubstateId>;
15
16
  }
@@ -0,0 +1,4 @@
1
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
+ // for now ts type is string, but rust is different
3
+ // dan_layer/transaction/src/transaction.rs
4
+ export type TransactionId = string;
@@ -0,0 +1,26 @@
1
+ import { FinalizeResult } from "./FinalizeResult";
2
+
3
+ export type SubmitTransactionResponse = {
4
+ transaction_id: string;
5
+ };
6
+
7
+ export interface SubmitTxResult {
8
+ response: SubmitTransactionResponse;
9
+ result: TransactionResult;
10
+ }
11
+
12
+ export enum TransactionStatus {
13
+ New,
14
+ DryRun,
15
+ Pending,
16
+ Accepted,
17
+ Rejected,
18
+ InvalidTransaction,
19
+ OnlyFeeAccepted,
20
+ }
21
+
22
+ export type TransactionResult = {
23
+ transaction_id: string;
24
+ status: TransactionStatus;
25
+ result: FinalizeResult | null;
26
+ };
@@ -0,0 +1,4 @@
1
+ export interface TransactionSignature {
2
+ public_key: string;
3
+ signature: string;
4
+ }
@@ -0,0 +1,15 @@
1
+ import { Instruction } from "./Instruction";
2
+ import { Epoch } from "./Epoch";
3
+ import { SubstateRequirement } from "./SubstateRequirement";
4
+ import { VersionedSubstateId } from "./VersionedSubstateId";
5
+
6
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
7
+ // differs from bindings implementation because of 'Instruction'
8
+ export interface UnsignedTransaction {
9
+ feeInstructions: Instruction[];
10
+ instructions: Instruction[];
11
+ inputs: SubstateRequirement[];
12
+ filledInputs: VersionedSubstateId[];
13
+ minEpoch?: Epoch;
14
+ maxEpoch?: Epoch;
15
+ }
@@ -1,5 +1,6 @@
1
1
  import { SubstateId } from "@tari-project/typescript-bindings";
2
+
2
3
  export interface VersionedSubstateId {
3
- substateId: SubstateId;
4
- version: number;
4
+ substateId: SubstateId;
5
+ version: number;
5
6
  }
@@ -0,0 +1,12 @@
1
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
+
3
+ export interface ViewableBalanceProof {
4
+ elgamal_encrypted: Uint8Array;
5
+ elgamal_public_nonce: Uint8Array;
6
+ c_prime: Uint8Array;
7
+ e_prime: Uint8Array;
8
+ r_prime: Uint8Array;
9
+ s_v: Uint8Array;
10
+ s_m: Uint8Array;
11
+ s_r: Uint8Array;
12
+ }
@@ -1,3 +1,3 @@
1
1
  export interface WorkspaceArg {
2
- Workspace: number[];
2
+ Workspace: number[];
3
3
  }
@@ -1,4 +1,3 @@
1
- export { Builder, TariCreateAccountDefinition, TariFunctionDefinition, TariMethodDefinition, TransactionConstructor, } from "./Builder";
2
1
  export { TemplateAddress } from "./TemplateAddress";
3
2
  export { Amount } from "./Amount";
4
3
  export { Arg } from "./Arg";
@@ -9,14 +8,16 @@ export { ConfidentialOutputStatement } from "./ConfidentialOutputStatement";
9
8
  export { ConfidentialStatement } from "./ConfidentialStatement";
10
9
  export { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
11
10
  export { Epoch } from "./Epoch";
12
- export { FinalizeResult, FinalizeResultStatus } from "./FinalizeResult";
11
+ export {
12
+ FinalizeResult, FinalizeResultStatus, TxResultAccept, TxResultAcceptFeeRejectRest, TxResultReject,
13
+ } from "./FinalizeResult";
13
14
  export { ResourceAddress } from "./ResourceAddress";
14
15
  export { Instruction } from "./Instruction";
15
16
  export { Transaction } from "./Transaction";
16
17
  export { SubstateDiff, DownSubstates, UpSubstates } from "./SubstateDiff";
17
18
  export { SubstateRequirement } from "./SubstateRequirement";
18
19
  export { TransactionId } from "./TransactionId";
19
- export { TransactionResult, TransactionStatus } from "./TransactionResult";
20
+ export { TransactionResult, TransactionStatus, SubmitTxResult, SubmitTransactionResponse } from "./TransactionResult";
20
21
  export { TransactionSignature } from "./TransactionSignature";
21
22
  export { UnsignedTransaction } from "./UnsignedTransaction";
22
23
  export { VersionedSubstateId } from "./VersionedSubstateId";
@@ -0,0 +1,15 @@
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": [
11
+ "src/**/*"
12
+ ],
13
+ "references": [
14
+ ]
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,29 @@
1
+ {
2
+ "name": "@tari-project/wallet-daemon-provider",
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-permissions": "workspace:^",
17
+ "@tari-project/tari-provider": "workspace:^",
18
+ "@tari-project/wallet_jrpc_client": "catalog:"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "catalog:",
22
+ "typescript": "catalog:"
23
+ },
24
+ "files": [
25
+ "/dist"
26
+ ],
27
+ "main": "dist/index.js",
28
+ "types": "dist/index.d.ts"
29
+ }
@@ -1,3 +1,5 @@
1
1
  export { TariConnection } from "./webrtc";
2
- export * from "./tari_permissions";
2
+
3
+
4
+ export * from "@tari-project/tari-permissions";
3
5
  export * from "./provider";
@@ -0,0 +1,263 @@
1
+ import { TariPermissions } from "@tari-project/tari-permissions";
2
+ import { TariConnection } from "./webrtc";
3
+ import { TariProvider } from "@tari-project/tari-provider";
4
+ import {
5
+ SubmitTransactionRequest,
6
+ TransactionResult,
7
+ TransactionStatus,
8
+ SubmitTransactionResponse,
9
+ VaultBalances, TemplateDefinition, Substate,
10
+ ListSubstatesResponse,
11
+ } from "@tari-project/tari-provider";
12
+ import { Account } from "@tari-project/tari-provider";
13
+ import {
14
+ WalletDaemonClient,
15
+ substateIdToString,
16
+ Instruction,
17
+ SubstateType,
18
+ SubstatesListRequest,
19
+ KeyBranch,
20
+ SubstateId,
21
+ } from "@tari-project/wallet_jrpc_client";
22
+ import { WebRtcRpcTransport } from "./webrtc_transport";
23
+
24
+ export const WalletDaemonNotConnected = "WALLET_DAEMON_NOT_CONNECTED";
25
+ export const Unsupported = "UNSUPPORTED";
26
+
27
+ export interface WalletDaemonBaseParameters {
28
+ permissions: TariPermissions,
29
+ optionalPermissions?: TariPermissions,
30
+ onConnection?: () => void
31
+ }
32
+
33
+ export interface WalletDaemonParameters extends WalletDaemonBaseParameters {
34
+ signalingServerUrl?: string,
35
+ webRtcConfig?: RTCConfiguration,
36
+ name?: string,
37
+ };
38
+
39
+ export interface WalletDaemonFetchParameters extends WalletDaemonBaseParameters {
40
+ serverUrl: string,
41
+ }
42
+
43
+ export class WalletDaemonTariProvider implements TariProvider {
44
+ public providerName = "WalletDaemon";
45
+ params: WalletDaemonParameters;
46
+ client: WalletDaemonClient;
47
+
48
+ private constructor(params: WalletDaemonParameters, connection: WalletDaemonClient) {
49
+ this.params = params;
50
+ this.client = connection;
51
+ }
52
+
53
+ static async build(params: WalletDaemonParameters): Promise<WalletDaemonTariProvider> {
54
+ const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
55
+ let connection = new TariConnection(params.signalingServerUrl, params.webRtcConfig);
56
+ const client = WalletDaemonClient.new(WebRtcRpcTransport.new(connection));
57
+ await connection.init(allPermissions, (conn) => {
58
+ params.onConnection?.();
59
+ if (conn.token) {
60
+ client.setToken(conn.token);
61
+ }
62
+ });
63
+ return new WalletDaemonTariProvider(params, client);
64
+ }
65
+
66
+ static async buildFetchProvider(params: WalletDaemonFetchParameters) {
67
+ const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
68
+ const client = WalletDaemonClient.usingFetchTransport(params.serverUrl);
69
+
70
+ const plainPermissions = allPermissions.toJSON().flatMap((p) => typeof (p) === "string" ? [p] : []);
71
+ const authResponse = await client.authRequest(plainPermissions);
72
+ await client.authAccept(authResponse, "WalletDaemon");
73
+
74
+ params.onConnection?.();
75
+ return new WalletDaemonTariProvider(params, client);
76
+ }
77
+
78
+ private static buildPermissions(params: WalletDaemonBaseParameters): TariPermissions {
79
+ const allPermissions = new TariPermissions();
80
+ allPermissions.addPermissions(params.permissions);
81
+ if (params.optionalPermissions) {
82
+ allPermissions.addPermissions(params.optionalPermissions);
83
+ }
84
+ return allPermissions;
85
+ }
86
+
87
+ private getWebRtcTransport(): WebRtcRpcTransport | undefined {
88
+ const transport = this.client.getTransport();
89
+ return transport instanceof WebRtcRpcTransport ? transport : undefined;
90
+ }
91
+
92
+ public get token(): string | undefined {
93
+ return this.getWebRtcTransport()?.token();
94
+ }
95
+
96
+ public get tokenUrl(): string | undefined {
97
+ if (!this.token) {
98
+ return undefined;
99
+ }
100
+
101
+ const name = this.params.name && encodeURIComponent(this.params.name) || "";
102
+ const token = this.token;
103
+ const permissions = JSON.stringify(this.params.permissions);
104
+ const optionalPermissions = JSON.stringify(this.params.optionalPermissions);
105
+
106
+ return `tari://${name}/${token}/${permissions}/${optionalPermissions}`;
107
+ }
108
+
109
+ public isConnected(): boolean {
110
+ return this.getWebRtcTransport()?.isConnected() || true;
111
+ }
112
+
113
+ public async createFreeTestCoins(): Promise<Account> {
114
+ const res = await this.client.createFreeTestCoins({
115
+ account: { Name: "template_web" },
116
+ amount: 1000000,
117
+ max_fee: null,
118
+ key_id: 0,
119
+ });
120
+ return {
121
+ account_id: res.account.key_index,
122
+ address: (res.account.address as { Component: string }).Component,
123
+ public_key: res.public_key,
124
+ resources: [],
125
+ };
126
+ }
127
+
128
+ public async getAccount(): Promise<Account> {
129
+ const { account, public_key } = await this.client.accountsGetDefault({}) as any;
130
+ const address = typeof account.address === "object" ? account.address.Component : account.address;
131
+ const { balances } = await this.client.accountsGetBalances({
132
+ account: { ComponentAddress: address },
133
+ refresh: false,
134
+ });
135
+
136
+ return {
137
+ account_id: account.key_index,
138
+ address,
139
+ public_key,
140
+ // TODO: should be vaults not resources
141
+ resources: balances.map((b: any) => ({
142
+ type: b.resource_type,
143
+ resource_address: b.resource_address,
144
+ balance: b.balance + b.confidential_balance,
145
+ vault_id: (typeof (b.vault_address) === "object" && "Vault" in b.vault_address) ? b.vault_address.Vault : b.vault_address,
146
+ token_symbol: b.token_symbol,
147
+ })),
148
+ };
149
+ }
150
+
151
+ public async getAccountBalances(componentAddress: string): Promise<unknown> {
152
+ return await this.client.accountsGetBalances({ account: { ComponentAddress: componentAddress }, refresh: true });
153
+ }
154
+
155
+ public async getSubstate(substateId: string): Promise<Substate> {
156
+ // Wallet daemon expects a SubstateId as a string
157
+ const { value, record } = await this.client.substatesGet({ substate_id: substateId as unknown as SubstateId });
158
+ return {
159
+ value,
160
+ address: {
161
+ substate_id: substateIdToString(record.substate_id),
162
+ version: record.version,
163
+ },
164
+ };
165
+ }
166
+
167
+ public async submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse> {
168
+ const params = {
169
+ transaction: {
170
+ V1: {
171
+ network: req.network,
172
+ instructions: req.instructions as Instruction[],
173
+ fee_instructions: req.fee_instructions as Instruction[],
174
+ inputs: req.required_substates.map((s) => ({
175
+ // TODO: Hmm The bindings want a SubstateId object, but the wallet only wants a string. Any is used to skip type checking here
176
+ substate_id: s.substate_id as any,
177
+ version: s.version ?? null,
178
+ })),
179
+ min_epoch: null,
180
+ max_epoch: null,
181
+ is_seal_signer_authorized: req.is_seal_signer_authorized,
182
+ },
183
+ },
184
+ signing_key_index: req.account_id,
185
+ autofill_inputs: [],
186
+ detect_inputs: true,
187
+ proof_ids: [],
188
+ detect_inputs_use_unversioned: req.detect_inputs_use_unversioned,
189
+ };
190
+
191
+ const res = await this.client.submitTransaction(params);
192
+ return { transaction_id: res.transaction_id };
193
+ }
194
+
195
+ public async getTransactionResult(transactionId: string): Promise<TransactionResult> {
196
+ const res = await this.client.getTransactionResult({ transaction_id: transactionId });
197
+
198
+ return {
199
+ transaction_id: transactionId,
200
+ status: convertStringToTransactionStatus(res.status),
201
+ result: res.result,
202
+ };
203
+ }
204
+
205
+ public async getPublicKey(branch: string, index: number): Promise<string> {
206
+ const res = await this.client.createKey({ branch: branch as KeyBranch, specific_index: index });
207
+ return res.public_key;
208
+ }
209
+
210
+ public async getTemplateDefinition(template_address: string): Promise<TemplateDefinition> {
211
+ let resp = await this.client.templatesGet({ template_address });
212
+ return resp.template_definition as TemplateDefinition;
213
+ }
214
+
215
+ public async getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min: number | null = null, max: number | null = null): Promise<VaultBalances> {
216
+ const res = await this.client.viewVaultBalance({
217
+ view_key_id: viewKeyId,
218
+ vault_id: vaultId,
219
+ minimum_expected_value: min,
220
+ maximum_expected_value: max,
221
+ });
222
+ return { balances: res.balances as unknown as Map<string, number | null> };
223
+ }
224
+
225
+ public async listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse> {
226
+ const resp = await this.client.substatesList({
227
+ filter_by_template,
228
+ filter_by_type,
229
+ limit,
230
+ offset,
231
+ } as SubstatesListRequest);
232
+
233
+ const substates = resp.substates.map((s) => ({
234
+ substate_id: typeof s.substate_id === "string" ? s.substate_id : substateIdToString(s.substate_id),
235
+ module_name: s.module_name,
236
+ version: s.version,
237
+ template_address: s.template_address,
238
+ }));
239
+
240
+ return { substates };
241
+ }
242
+ }
243
+
244
+ function convertStringToTransactionStatus(status: string): TransactionStatus {
245
+ switch (status) {
246
+ case "New":
247
+ return TransactionStatus.New;
248
+ case "DryRun":
249
+ return TransactionStatus.DryRun;
250
+ case "Pending":
251
+ return TransactionStatus.Pending;
252
+ case "Accepted":
253
+ return TransactionStatus.Accepted;
254
+ case "Rejected":
255
+ return TransactionStatus.Rejected;
256
+ case "InvalidTransaction":
257
+ return TransactionStatus.InvalidTransaction;
258
+ case "OnlyFeeAccepted":
259
+ return TransactionStatus.OnlyFeeAccepted;
260
+ default:
261
+ throw new Error(`Unknown status: ${status}`);
262
+ }
263
+ }