@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,42 @@
1
+ import { TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
2
+ import { TemplateFactory } from "./TemplateFactory";
3
+
4
+ interface CreatePool extends TariMethodDefinition {
5
+ methodName: "create_pool";
6
+ args?: [string, string];
7
+ }
8
+
9
+ interface AddLiquidityMethod extends TariMethodDefinition {
10
+ methodName: "add_liquidity";
11
+ args?: WorkspaceArg[];
12
+ }
13
+
14
+ interface RemoveLiquidityMethod extends TariMethodDefinition {
15
+ methodName: "remove_liquidity";
16
+ args?: WorkspaceArg[];
17
+ }
18
+
19
+ interface SwapMethod extends TariMethodDefinition {
20
+ methodName: "swap";
21
+ args?: (WorkspaceArg | string)[];
22
+ }
23
+
24
+ export class PoolTemplate extends TemplateFactory {
25
+ public createPool: CreatePool;
26
+ public addLiquidity: AddLiquidityMethod;
27
+ public removeLiquidity: RemoveLiquidityMethod;
28
+ public swap: SwapMethod;
29
+
30
+ constructor(public templateAddress: string) {
31
+ super(templateAddress);
32
+ this._initFunctions();
33
+ this._initMethods();
34
+ }
35
+
36
+ protected _initFunctions(): void {}
37
+ protected _initMethods(): void {
38
+ this.addLiquidity = this._defineMethod<AddLiquidityMethod>("add_liquidity");
39
+ this.removeLiquidity = this._defineMethod<RemoveLiquidityMethod>("remove_liquidity");
40
+ this.swap = this._defineMethod<SwapMethod>("swap");
41
+ }
42
+ }
@@ -0,0 +1,101 @@
1
+ import {
2
+ Amount,
3
+ ConfidentialWithdrawProof,
4
+ ResourceAddress,
5
+ TariFunctionDefinition,
6
+ TariMethodDefinition,
7
+ WorkspaceArg,
8
+ } from "@tari-project/tarijs-builders";
9
+ import { TemplateFactory } from "./TemplateFactory";
10
+
11
+ interface NewPoolFunction extends TariFunctionDefinition {
12
+ functionName: "new";
13
+ args?: [ResourceAddress, ResourceAddress, Amount];
14
+ }
15
+
16
+ interface MintFunction extends TariFunctionDefinition {
17
+ functionName: "mint";
18
+ args?: [Amount];
19
+ }
20
+
21
+ interface MintWithSymbolFunction extends TariFunctionDefinition {
22
+ functionName: "mint_with_symbol";
23
+ args?: [Amount, string];
24
+ }
25
+
26
+ interface PayFeeMethod extends TariMethodDefinition {
27
+ methodName: "pay_fee";
28
+ args?: [string];
29
+ }
30
+
31
+ interface PayFeeConfidentialMethod extends TariMethodDefinition {
32
+ methodName: "pay_fee_confidential";
33
+ args?: [ConfidentialWithdrawProof];
34
+ }
35
+
36
+ interface TotalSupplyMethod extends TariMethodDefinition {
37
+ methodName: "total_supply";
38
+ args?: [];
39
+ }
40
+
41
+ interface WithdrawMethod extends TariMethodDefinition {
42
+ methodName: "withdraw";
43
+ args?: [string, string];
44
+ }
45
+
46
+ interface AddLiquidityMethod extends TariMethodDefinition {
47
+ methodName: "add_liquidity";
48
+ args?: WorkspaceArg[];
49
+ }
50
+
51
+ interface RemoveLiquidityMethod extends TariMethodDefinition {
52
+ methodName: "remove_liquidity";
53
+ args?: WorkspaceArg[];
54
+ }
55
+
56
+ interface DepositMethod extends TariMethodDefinition {
57
+ methodName: "deposit";
58
+ args?: WorkspaceArg[];
59
+ }
60
+
61
+ interface SwapMethod extends TariMethodDefinition {
62
+ methodName: "swap";
63
+ args?: (WorkspaceArg | string)[];
64
+ }
65
+
66
+ export class TariswapTemplate extends TemplateFactory {
67
+ public newPool: NewPoolFunction;
68
+ public mint: MintFunction;
69
+ public mintWithSymbol: MintWithSymbolFunction;
70
+ public totalSupply: TotalSupplyMethod;
71
+ public payFee: PayFeeMethod;
72
+ public payFeeConfidential: PayFeeConfidentialMethod;
73
+ public withdraw: WithdrawMethod;
74
+ public addLiquidity: AddLiquidityMethod;
75
+ public removeLiquidity: RemoveLiquidityMethod;
76
+ public deposit: DepositMethod;
77
+ public swap: SwapMethod;
78
+
79
+ constructor(public templateAddress: string) {
80
+ super(templateAddress);
81
+ this._initFunctions();
82
+ this._initMethods();
83
+ }
84
+
85
+ protected _initFunctions(): void {
86
+ this.newPool = this._defineFunction<NewPoolFunction>("new");
87
+ this.mint = this._defineFunction<MintFunction>("mint");
88
+ this.mintWithSymbol = this._defineFunction<MintWithSymbolFunction>("mint_with_symbol");
89
+ }
90
+
91
+ protected _initMethods(): void {
92
+ this.totalSupply = this._defineMethod<TotalSupplyMethod>("total_supply");
93
+ this.payFee = this._defineMethod<PayFeeMethod>("pay_fee");
94
+ this.payFeeConfidential = this._defineMethod<PayFeeConfidentialMethod>("pay_fee_confidential");
95
+ this.withdraw = this._defineMethod<WithdrawMethod>("withdraw");
96
+ this.addLiquidity = this._defineMethod<AddLiquidityMethod>("add_liquidity");
97
+ this.removeLiquidity = this._defineMethod<RemoveLiquidityMethod>("remove_liquidity");
98
+ this.deposit = this._defineMethod<DepositMethod>("deposit");
99
+ this.swap = this._defineMethod<SwapMethod>("swap");
100
+ }
101
+ }
@@ -0,0 +1,22 @@
1
+ import { TariFunctionDefinition, TariMethodDefinition } from "@tari-project/tarijs-builders";
2
+
3
+ export abstract class TemplateFactory {
4
+ constructor(public templateAddress: string) {}
5
+
6
+ public _defineFunction<T extends TariFunctionDefinition>(name: T["functionName"]): T {
7
+ return {
8
+ templateAddress: this.templateAddress,
9
+ functionName: name,
10
+ } as T;
11
+ }
12
+
13
+ public _defineMethod<T extends TariMethodDefinition>(name: T["methodName"]): T {
14
+ return {
15
+ componentAddress: this.templateAddress,
16
+ methodName: name,
17
+ } as T;
18
+ }
19
+
20
+ protected abstract _initFunctions(): void;
21
+ protected abstract _initMethods(): void;
22
+ }
@@ -0,0 +1,72 @@
1
+ import { Amount, ConfidentialWithdrawProof, TariFunctionDefinition, TariMethodDefinition } from "@tari-project/tarijs-builders";
2
+ import { TemplateFactory } from "./TemplateFactory";
3
+
4
+ interface MintFunction extends TariFunctionDefinition {
5
+ functionName: "mint";
6
+ args?: [string];
7
+ }
8
+
9
+ interface MintWithSymbolFunction extends TariFunctionDefinition {
10
+ functionName: "mint_with_symbol";
11
+ args?: [amount: string, symbol: string];
12
+ }
13
+
14
+ interface PayFeeMethod extends TariMethodDefinition {
15
+ methodName: "pay_fee";
16
+ args?: [Amount];
17
+ }
18
+
19
+ interface PayFeeConfidentialMethod extends TariMethodDefinition {
20
+ methodName: "pay_fee_confidential";
21
+ args?: [ConfidentialWithdrawProof];
22
+ }
23
+
24
+ interface TakeFreeCoinsMethod extends TariMethodDefinition {
25
+ methodName: "take_free_coins";
26
+ args?: [];
27
+ }
28
+
29
+ interface TakeFreeCoinsConfidentialMethod extends TariMethodDefinition {
30
+ methodName: "take_free_coins_confidential";
31
+ args?: [ConfidentialWithdrawProof];
32
+ }
33
+
34
+ interface BurnCoinsMethod extends TariMethodDefinition {
35
+ methodName: "burn_coins";
36
+ args?: [BigInt];
37
+ }
38
+
39
+ interface TotalSupplyMethod extends TariMethodDefinition {
40
+ methodName: "total_supply";
41
+ args?: [];
42
+ }
43
+
44
+ export class TestFaucet extends TemplateFactory {
45
+ public mint: MintFunction;
46
+ public mintWithSymbol: MintWithSymbolFunction;
47
+ public takeFreeCoins: TakeFreeCoinsMethod;
48
+ public takeFreeCoinsConfidential: TakeFreeCoinsConfidentialMethod;
49
+ public burnCoins: BurnCoinsMethod;
50
+ public totalSupply: TotalSupplyMethod;
51
+ public payFee: PayFeeMethod;
52
+ public payFeeConfidential: PayFeeConfidentialMethod;
53
+
54
+ constructor(public templateAddress: string) {
55
+ super(templateAddress);
56
+ this._initFunctions();
57
+ this._initMethods();
58
+ }
59
+ protected _initFunctions(): void {
60
+ this.mint = this._defineFunction<MintFunction>("mint");
61
+ this.mintWithSymbol = this._defineFunction<MintWithSymbolFunction>("mint_with_symbol");
62
+ }
63
+ protected _initMethods(): void {
64
+ this.takeFreeCoins = this._defineMethod<TakeFreeCoinsMethod>("take_free_coins");
65
+ this.takeFreeCoinsConfidential =
66
+ this._defineMethod<TakeFreeCoinsConfidentialMethod>("take_free_coins_confidential");
67
+ this.burnCoins = this._defineMethod<BurnCoinsMethod>("burn_coins");
68
+ this.totalSupply = this._defineMethod<TotalSupplyMethod>("total_supply");
69
+ this.payFee = this._defineMethod<PayFeeMethod>("pay_fee");
70
+ this.payFeeConfidential = this._defineMethod<PayFeeConfidentialMethod>("pay_fee_confidential");
71
+ }
72
+ }
@@ -1,4 +1,4 @@
1
- export function toHexString(byteArray) {
1
+ export function toHexString(byteArray: any): string {
2
2
  if (Array.isArray(byteArray)) {
3
3
  return Array.from(byteArray, function (byte) {
4
4
  return ('0' + (byte & 0xff).toString(16)).slice(-2);
@@ -13,10 +13,11 @@ export function toHexString(byteArray) {
13
13
  }
14
14
  return 'Unsupported type';
15
15
  }
16
- export function fromHexString(hexString) {
16
+
17
+ export function fromHexString(hexString: string) {
17
18
  let res = [];
18
19
  for (let i = 0; i < hexString.length; i += 2) {
19
20
  res.push(Number('0x' + hexString.substring(i, i + 2)));
20
21
  }
21
22
  return res;
22
- }
23
+ }
@@ -0,0 +1,39 @@
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
+ "path": "../builders"
16
+ },
17
+ {
18
+ "path": "../metamask_provider"
19
+ },
20
+ {
21
+ "path": "../tari_permissions"
22
+ },
23
+ {
24
+ "path": "../tari_provider"
25
+ },
26
+ {
27
+ "path": "../tari_universe"
28
+ },
29
+ {
30
+ "path": "../tarijs_types"
31
+ },
32
+ {
33
+ "path": "../wallet_daemon"
34
+ },
35
+ {
36
+ "path": "../walletconnect"
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import { loadEnv } from 'vite';
3
+
4
+ export default defineConfig({
5
+ root: '.',
6
+ test: {
7
+ env: loadEnv("", "./integration-tests/", ""),
8
+ },
9
+ });
@@ -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,27 @@
1
+ {
2
+ "name": "@tari-project/tarijs-types",
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/typescript-bindings": "catalog:"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "catalog:",
20
+ "typescript": "catalog:"
21
+ },
22
+ "files": [
23
+ "/dist"
24
+ ],
25
+ "main": "dist/index.js",
26
+ "types": "dist/index.d.ts"
27
+ }
@@ -0,0 +1,113 @@
1
+ export class Amount {
2
+ private value: number;
3
+
4
+ constructor(value: number) {
5
+ this.value = value;
6
+ }
7
+
8
+ public static readonly MAX: Amount = new Amount(Number.MAX_SAFE_INTEGER);
9
+
10
+ public static newAmount(amount: number): Amount {
11
+ return new Amount(amount);
12
+ }
13
+
14
+ public static zero(): Amount {
15
+ return new Amount(0);
16
+ }
17
+
18
+ public isZero(): boolean {
19
+ return this.value === 0;
20
+ }
21
+
22
+ public isPositive(): boolean {
23
+ return this.value >= 0;
24
+ }
25
+
26
+ public isNegative(): boolean {
27
+ return !this.isPositive();
28
+ }
29
+
30
+ public getValue(): number {
31
+ return this.value;
32
+ }
33
+
34
+ public getStringValue(): string {
35
+ return this.value.toString();
36
+ }
37
+
38
+ public checkedAdd(other: Amount): Amount | null {
39
+ const result = this.value + other.value;
40
+ if (result < Number.MIN_SAFE_INTEGER || result > Number.MAX_SAFE_INTEGER) {
41
+ return null;
42
+ }
43
+ return new Amount(result);
44
+ }
45
+
46
+ public saturatingAdd(other: Amount): Amount {
47
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value + other.value)));
48
+ }
49
+
50
+ public checkedSub(other: Amount): Amount | null {
51
+ const result = this.value - other.value;
52
+ if (result < Number.MIN_SAFE_INTEGER || result > Number.MAX_SAFE_INTEGER) {
53
+ return null;
54
+ }
55
+ return new Amount(result);
56
+ }
57
+
58
+ public saturatingSub(other: Amount): Amount {
59
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value - other.value)));
60
+ }
61
+
62
+ public saturatingSubPositive(other: Amount): Amount {
63
+ const result = this.value - other.value;
64
+ return result < 0 ? new Amount(0) : new Amount(result);
65
+ }
66
+
67
+ public checkedSubPositive(other: Amount): Amount | null {
68
+ if (this.isNegative() || other.isNegative()) {
69
+ return null;
70
+ }
71
+ if (this.value < other.value) {
72
+ return null;
73
+ }
74
+ return new Amount(this.value - other.value);
75
+ }
76
+
77
+ public checkedMul(other: Amount): Amount | null {
78
+ const result = this.value * other.value;
79
+ if (result < Number.MIN_SAFE_INTEGER || result > Number.MAX_SAFE_INTEGER) {
80
+ return null;
81
+ }
82
+ return new Amount(result);
83
+ }
84
+
85
+ public saturatingMul(other: Amount): Amount {
86
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value * other.value)));
87
+ }
88
+
89
+ public checkedDiv(other: Amount): Amount | null {
90
+ if (other.value === 0) {
91
+ throw new Error("Division by zero");
92
+ }
93
+ const result = this.value / other.value;
94
+ if (result < Number.MIN_SAFE_INTEGER || result > Number.MAX_SAFE_INTEGER) {
95
+ return null;
96
+ }
97
+ return new Amount(result);
98
+ }
99
+
100
+ public saturatingDiv(other: Amount): Amount {
101
+ if (other.value === 0) {
102
+ throw new Error("Division by zero");
103
+ }
104
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value / other.value)));
105
+ }
106
+
107
+ public asU64Checked(): number | null {
108
+ if (this.value < 0) {
109
+ return null;
110
+ }
111
+ return this.value as number;
112
+ }
113
+ }
@@ -0,0 +1,3 @@
1
+ //TODO refactor Arg type (https://github.com/tari-project/tari.js/issues/29)
2
+ // take a look at typescript-bindings first
3
+ export type Arg = any;
@@ -0,0 +1,3 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
3
+ export type ComponentAddress = string;
@@ -0,0 +1,9 @@
1
+ import type { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
2
+
3
+ export interface ConfidentialClaim {
4
+ publicKey: string;
5
+ outputAddress: string;
6
+ rangeProof: Array<number>;
7
+ proofOfKnowledge: string;
8
+ withdrawProof?: ConfidentialWithdrawProof;
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { ElgamalVerifiableBalance } from "./ElgamalVerifiableBalance";
2
+
3
+ export interface ConfidentialOutput {
4
+ commitment: string;
5
+ stealthPublicNonce: string;
6
+ encrypted_data: Array<number>;
7
+ minimumValuePromise: number;
8
+ viewableBalance?: ElgamalVerifiableBalance;
9
+ }
@@ -0,0 +1,10 @@
1
+ import type { Amount } from "./Amount";
2
+ import type { ConfidentialStatement } from "./ConfidentialStatement";
3
+
4
+ export interface ConfidentialOutputStatement {
5
+ outputStatement?: ConfidentialStatement;
6
+ changeStatement?: ConfidentialStatement;
7
+ rangeProof: Array<number>;
8
+ outputRevealedAmount: Amount;
9
+ changeRevealedAmount: Amount;
10
+ }
@@ -0,0 +1,9 @@
1
+ import type { ViewableBalanceProof } from "./ViewableBalanceProof";
2
+
3
+ export interface ConfidentialStatement {
4
+ commitment: Array<number>;
5
+ senderPublicNonce: Array<number>;
6
+ encryptedData: Array<number>;
7
+ minimumValuePromise: number;
8
+ viewableBalanceProof?: ViewableBalanceProof;
9
+ }
@@ -0,0 +1,8 @@
1
+ import type { ConfidentialOutputStatement } from "./ConfidentialOutputStatement";
2
+
3
+ export interface ConfidentialWithdrawProof {
4
+ inputs: Array<Uint8Array>;
5
+ inputRevealedAmount: number;
6
+ outputProof: ConfidentialOutputStatement;
7
+ balanceProof: Array<number>;
8
+ }
@@ -0,0 +1,4 @@
1
+ export interface ElgamalVerifiableBalance {
2
+ encrypted: string;
3
+ public_nonce: string;
4
+ }
@@ -0,0 +1,3 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ // TODO https://github.com/tari-project/tari.js/issues/29
3
+ export type Epoch = number;
@@ -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
+ };
@@ -0,0 +1,3 @@
1
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
+
3
+ export type ResourceAddress = string;
@@ -0,0 +1,9 @@
1
+ import { Substate, SubstateId } from "@tari-project/typescript-bindings";
2
+
3
+ export type UpSubstates = Array<[SubstateId, Substate]>;
4
+ export type DownSubstates = Array<[SubstateId, number]>;
5
+
6
+ export interface SubstateDiff {
7
+ up_substates: UpSubstates;
8
+ down_substates: DownSubstates;
9
+ }
@@ -0,0 +1,6 @@
1
+ import { SubstateId } from "@tari-project/typescript-bindings";
2
+
3
+ export interface SubstateRequirement {
4
+ substateId: SubstateId;
5
+ version?: number;
6
+ }
@@ -0,0 +1,3 @@
1
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
+
3
+ export type TemplateAddress = string;
@@ -0,0 +1,16 @@
1
+ import { Instruction } from "./Instruction";
2
+ import { SubstateRequirement } from "./SubstateRequirement";
3
+ import { Epoch } from "./Epoch";
4
+ import { VersionedSubstateId } from "./VersionedSubstateId";
5
+ import { TransactionSignature } from "./TransactionSignature";
6
+
7
+ export interface Transaction {
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>;
16
+ }