@tari-project/tarijs 0.4.0 → 0.4.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/ISSUE_TEMPLATE/bug_report.md +36 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +27 -0
- package/.github/dependabot.yml +8 -0
- package/.github/workflows/ci.yml +26 -0
- package/.github/workflows/documentation-deploy.yml +44 -0
- package/.github/workflows/documentation-test-deploy.yml +20 -0
- package/.github/workflows/npm_publish.yml +26 -0
- package/.github/workflows/pr_signed_commits_check.yml +19 -0
- package/.github/workflows/pr_title.yml +30 -0
- package/.moon/toolchain.yml +6 -0
- package/.moon/workspace.yml +33 -0
- package/.prettierrc +12 -0
- package/.prototools +9 -0
- package/CODEOWNERS +3 -0
- package/README.md +66 -0
- package/TODO.md +12 -0
- package/docusaurus/tari-docs/README.md +41 -0
- package/docusaurus/tari-docs/docs/index.md +16 -0
- package/docusaurus/tari-docs/docs/installation.md +27 -0
- package/docusaurus/tari-docs/docs/providers/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/providers/tari-universe.md +27 -0
- package/docusaurus/tari-docs/docs/providers/wallet-connect.md +52 -0
- package/docusaurus/tari-docs/docs/providers/wallet-daemon.md +37 -0
- package/docusaurus/tari-docs/docs/wallet/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/wallet/default-account.md +51 -0
- package/docusaurus/tari-docs/docs/wallet/get-substate.md +110 -0
- package/docusaurus/tari-docs/docs/wallet/list-substates.md +69 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/build-execute-request.md +38 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/index.md +14 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-function.md +17 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-method.md +17 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/fee.md +28 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/index.md +426 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/inputs.md +24 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/instruction.md +108 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/min-max-epoch.md +19 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/raw-instructions.md +16 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/save-var.md +63 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/transaction-internals.md +20 -0
- package/docusaurus/tari-docs/docs/wallet/template-definition.md +101 -0
- package/docusaurus/tari-docs/docusaurus.config.ts +108 -0
- package/docusaurus/tari-docs/moon.yml +41 -0
- package/docusaurus/tari-docs/package.json +49 -0
- package/docusaurus/tari-docs/sidebars.ts +7 -0
- package/docusaurus/tari-docs/src/components/HomepageFeatures/index.tsx +69 -0
- package/docusaurus/tari-docs/src/components/HomepageFeatures/styles.module.css +11 -0
- package/docusaurus/tari-docs/src/css/custom.css +30 -0
- package/docusaurus/tari-docs/src/pages/index.module.css +23 -0
- package/docusaurus/tari-docs/src/pages/index.tsx +44 -0
- package/docusaurus/tari-docs/static/.nojekyll +0 -0
- package/docusaurus/tari-docs/static/img/favicon.png +0 -0
- package/docusaurus/tari-docs/static/img/meta-image.png +0 -0
- package/docusaurus/tari-docs/static/img/tari/wallet-connect-1.png +0 -0
- package/docusaurus/tari-docs/static/img/tari/wallet-connect-2.png +0 -0
- package/docusaurus/tari-docs/static/img/tari/wallet-connect-3.png +0 -0
- package/docusaurus/tari-docs/static/img/tari-logo.svg +30 -0
- package/docusaurus/tari-docs/tsconfig.json +8 -0
- package/package.json +4 -28
- package/packages/builders/moon.yml +55 -0
- package/packages/builders/package.json +30 -0
- package/packages/builders/src/helpers/index.ts +2 -0
- package/packages/builders/src/helpers/submitTransaction.ts +97 -0
- package/packages/builders/src/helpers/workspace.ts +32 -0
- package/packages/builders/src/index.ts +9 -0
- package/packages/builders/src/transaction/TransactionBuilder.ts +276 -0
- package/packages/builders/src/transaction/TransactionRequest.ts +93 -0
- package/packages/builders/src/transaction/index.ts +2 -0
- package/packages/builders/tsconfig.json +24 -0
- package/packages/metamask_provider/moon.yml +55 -0
- package/packages/metamask_provider/package.json +30 -0
- package/packages/metamask_provider/src/index.ts +232 -0
- package/packages/metamask_provider/src/utils.ts +86 -0
- package/packages/metamask_provider/tsconfig.json +21 -0
- package/packages/tari_permissions/moon.yml +55 -0
- package/packages/tari_permissions/package.json +26 -0
- package/packages/tari_permissions/src/index.ts +1 -0
- package/packages/tari_permissions/src/tari_permissions.ts +312 -0
- package/packages/tari_permissions/tsconfig.json +15 -0
- package/packages/tari_provider/moon.yml +55 -0
- package/packages/tari_provider/package.json +27 -0
- package/packages/tari_provider/src/TariProvider.ts +34 -0
- package/packages/tari_provider/src/index.ts +3 -0
- package/packages/tari_provider/src/types.ts +84 -0
- package/packages/tari_provider/tsconfig.json +11 -0
- package/packages/tari_universe/moon.yml +55 -0
- package/packages/tari_universe/package.json +31 -0
- package/packages/tari_universe/src/index.ts +3 -0
- package/packages/tari_universe/src/provider.ts +120 -0
- package/packages/tari_universe/src/types.ts +33 -0
- package/packages/tari_universe/src/utils.ts +23 -0
- package/packages/tari_universe/tsconfig.json +24 -0
- package/packages/tarijs/integration-tests/.env +1 -0
- package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +191 -0
- package/packages/tarijs/moon.yml +71 -0
- package/packages/tarijs/package.json +40 -0
- package/packages/tarijs/src/cbor.spec.ts +259 -0
- package/packages/tarijs/src/cbor.ts +114 -0
- package/packages/tarijs/src/index.ts +72 -0
- package/packages/tarijs/src/network.ts +8 -0
- package/packages/tarijs/src/templates/Account.ts +98 -0
- package/packages/tarijs/src/templates/Pool.ts +42 -0
- package/packages/tarijs/src/templates/Tariswap.ts +101 -0
- package/packages/tarijs/src/templates/TemplateFactory.ts +22 -0
- package/packages/tarijs/src/templates/TestFaucet.ts +72 -0
- package/{dist/utils.js → packages/tarijs/src/utils.ts} +4 -3
- package/packages/tarijs/tsconfig.json +39 -0
- package/packages/tarijs/vitest.config.ts +9 -0
- package/packages/tarijs_types/moon.yml +55 -0
- package/packages/tarijs_types/package.json +27 -0
- package/packages/tarijs_types/src/Amount.ts +113 -0
- package/packages/tarijs_types/src/Arg.ts +3 -0
- package/packages/tarijs_types/src/ComponentAddress.ts +3 -0
- package/packages/tarijs_types/src/ConfidentialClaim.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialOutput.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialOutputStatement.ts +10 -0
- package/packages/tarijs_types/src/ConfidentialStatement.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialWithdrawProof.ts +8 -0
- package/packages/tarijs_types/src/ElgamalVerifiableBalance.ts +4 -0
- package/packages/tarijs_types/src/Epoch.ts +3 -0
- package/packages/tarijs_types/src/FinalizeResult.ts +17 -0
- package/packages/tarijs_types/src/Instruction.ts +29 -0
- package/packages/tarijs_types/src/ResourceAddress.ts +3 -0
- package/packages/tarijs_types/src/SubstateDiff.ts +9 -0
- package/packages/tarijs_types/src/SubstateRequirement.ts +6 -0
- package/packages/tarijs_types/src/TemplateAddress.ts +3 -0
- package/packages/tarijs_types/src/Transaction.ts +16 -0
- package/packages/tarijs_types/src/TransactionId.ts +4 -0
- package/packages/tarijs_types/src/TransactionResult.ts +26 -0
- package/packages/tarijs_types/src/TransactionSignature.ts +4 -0
- package/packages/tarijs_types/src/UnsignedTransaction.ts +15 -0
- package/packages/tarijs_types/src/VersionedSubstateId.ts +6 -0
- package/packages/tarijs_types/src/ViewableBalanceProof.ts +12 -0
- package/packages/tarijs_types/src/Workspace.ts +3 -0
- package/packages/tarijs_types/src/index.ts +25 -0
- package/packages/tarijs_types/tsconfig.json +15 -0
- package/packages/wallet_daemon/moon.yml +55 -0
- package/packages/wallet_daemon/package.json +29 -0
- package/packages/wallet_daemon/src/index.ts +5 -0
- package/packages/wallet_daemon/src/provider.ts +263 -0
- package/packages/wallet_daemon/src/webrtc.ts +229 -0
- package/packages/wallet_daemon/src/webrtc_transport.ts +27 -0
- package/packages/wallet_daemon/tsconfig.json +21 -0
- package/packages/walletconnect/moon.yml +55 -0
- package/packages/walletconnect/package.json +32 -0
- package/packages/walletconnect/src/index.ts +274 -0
- package/packages/walletconnect/tsconfig.json +21 -0
- package/pnpm-workspace.yaml +15 -0
- package/tsconfig.json +45 -0
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -13
- package/dist/network.d.ts +0 -8
- package/dist/network.js +0 -9
- package/dist/templates/Account.d.ts +0 -65
- package/dist/templates/Account.js +0 -31
- package/dist/templates/Pool.d.ts +0 -29
- package/dist/templates/Pool.js +0 -20
- package/dist/templates/Tariswap.d.ts +0 -64
- package/dist/templates/Tariswap.js +0 -36
- package/dist/templates/TemplateFactory.d.ts +0 -9
- package/dist/templates/TemplateFactory.js +0 -18
- package/dist/templates/TestFaucet.d.ts +0 -49
- package/dist/templates/TestFaucet.js +0 -31
- package/dist/templates/index.js +0 -5
- package/dist/utils.d.ts +0 -2
- /package/{dist/templates/index.d.ts → packages/tarijs/src/templates/index.ts} +0 -0
|
@@ -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
|
-
|
|
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,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,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,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,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,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
|
+
}
|
|
@@ -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,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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { TemplateAddress } from "./TemplateAddress";
|
|
2
|
+
export { Amount } from "./Amount";
|
|
3
|
+
export { Arg } from "./Arg";
|
|
4
|
+
export { ComponentAddress } from "./ComponentAddress";
|
|
5
|
+
export { ConfidentialClaim } from "./ConfidentialClaim";
|
|
6
|
+
export { ConfidentialOutput } from "./ConfidentialOutput";
|
|
7
|
+
export { ConfidentialOutputStatement } from "./ConfidentialOutputStatement";
|
|
8
|
+
export { ConfidentialStatement } from "./ConfidentialStatement";
|
|
9
|
+
export { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
|
|
10
|
+
export { Epoch } from "./Epoch";
|
|
11
|
+
export {
|
|
12
|
+
FinalizeResult, FinalizeResultStatus, TxResultAccept, TxResultAcceptFeeRejectRest, TxResultReject,
|
|
13
|
+
} from "./FinalizeResult";
|
|
14
|
+
export { ResourceAddress } from "./ResourceAddress";
|
|
15
|
+
export { Instruction } from "./Instruction";
|
|
16
|
+
export { Transaction } from "./Transaction";
|
|
17
|
+
export { SubstateDiff, DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
18
|
+
export { SubstateRequirement } from "./SubstateRequirement";
|
|
19
|
+
export { TransactionId } from "./TransactionId";
|
|
20
|
+
export { TransactionResult, TransactionStatus, SubmitTxResult, SubmitTransactionResponse } from "./TransactionResult";
|
|
21
|
+
export { TransactionSignature } from "./TransactionSignature";
|
|
22
|
+
export { UnsignedTransaction } from "./UnsignedTransaction";
|
|
23
|
+
export { VersionedSubstateId } from "./VersionedSubstateId";
|
|
24
|
+
export { ViewableBalanceProof } from "./ViewableBalanceProof";
|
|
25
|
+
export { WorkspaceArg } from "./Workspace";
|