@tari-project/tarijs-types 0.4.0

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 (52) hide show
  1. package/LICENSE +29 -0
  2. package/dist/Amount.d.ts +23 -0
  3. package/dist/Amount.js +93 -0
  4. package/dist/Arg.d.ts +1 -0
  5. package/dist/Arg.js +1 -0
  6. package/dist/ComponentAddress.d.ts +1 -0
  7. package/dist/ComponentAddress.js +1 -0
  8. package/dist/ConfidentialClaim.d.ts +8 -0
  9. package/dist/ConfidentialClaim.js +1 -0
  10. package/dist/ConfidentialOutput.d.ts +8 -0
  11. package/dist/ConfidentialOutput.js +1 -0
  12. package/dist/ConfidentialOutputStatement.d.ts +9 -0
  13. package/dist/ConfidentialOutputStatement.js +1 -0
  14. package/dist/ConfidentialStatement.d.ts +8 -0
  15. package/dist/ConfidentialStatement.js +1 -0
  16. package/dist/ConfidentialWithdrawProof.d.ts +7 -0
  17. package/dist/ConfidentialWithdrawProof.js +1 -0
  18. package/dist/ElgamalVerifiableBalance.d.ts +4 -0
  19. package/dist/ElgamalVerifiableBalance.js +1 -0
  20. package/dist/Epoch.d.ts +1 -0
  21. package/dist/Epoch.js +1 -0
  22. package/dist/FinalizeResult.d.ts +20 -0
  23. package/dist/FinalizeResult.js +1 -0
  24. package/dist/Instruction.d.ts +56 -0
  25. package/dist/Instruction.js +1 -0
  26. package/dist/ResourceAddress.d.ts +1 -0
  27. package/dist/ResourceAddress.js +2 -0
  28. package/dist/SubstateDiff.d.ts +7 -0
  29. package/dist/SubstateDiff.js +1 -0
  30. package/dist/SubstateRequirement.d.ts +5 -0
  31. package/dist/SubstateRequirement.js +1 -0
  32. package/dist/TemplateAddress.d.ts +1 -0
  33. package/dist/TemplateAddress.js +2 -0
  34. package/dist/Transaction.d.ts +15 -0
  35. package/dist/Transaction.js +1 -0
  36. package/dist/TransactionId.d.ts +1 -0
  37. package/dist/TransactionId.js +1 -0
  38. package/dist/TransactionResult.d.ts +22 -0
  39. package/dist/TransactionResult.js +10 -0
  40. package/dist/TransactionSignature.d.ts +4 -0
  41. package/dist/TransactionSignature.js +1 -0
  42. package/dist/UnsignedTransaction.d.ts +12 -0
  43. package/dist/UnsignedTransaction.js +1 -0
  44. package/dist/VersionedSubstateId.d.ts +5 -0
  45. package/dist/VersionedSubstateId.js +1 -0
  46. package/dist/ViewableBalanceProof.d.ts +10 -0
  47. package/dist/ViewableBalanceProof.js +2 -0
  48. package/dist/Workspace.d.ts +3 -0
  49. package/dist/Workspace.js +1 -0
  50. package/dist/index.d.ts +23 -0
  51. package/dist/index.js +2 -0
  52. package/package.json +27 -0
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, The Tari Developer Community
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,23 @@
1
+ export declare class Amount {
2
+ private value;
3
+ constructor(value: number);
4
+ static readonly MAX: Amount;
5
+ static newAmount(amount: number): Amount;
6
+ static zero(): Amount;
7
+ isZero(): boolean;
8
+ isPositive(): boolean;
9
+ isNegative(): boolean;
10
+ getValue(): number;
11
+ getStringValue(): string;
12
+ checkedAdd(other: Amount): Amount | null;
13
+ saturatingAdd(other: Amount): Amount;
14
+ checkedSub(other: Amount): Amount | null;
15
+ saturatingSub(other: Amount): Amount;
16
+ saturatingSubPositive(other: Amount): Amount;
17
+ checkedSubPositive(other: Amount): Amount | null;
18
+ checkedMul(other: Amount): Amount | null;
19
+ saturatingMul(other: Amount): Amount;
20
+ checkedDiv(other: Amount): Amount | null;
21
+ saturatingDiv(other: Amount): Amount;
22
+ asU64Checked(): number | null;
23
+ }
package/dist/Amount.js ADDED
@@ -0,0 +1,93 @@
1
+ export class Amount {
2
+ value;
3
+ constructor(value) {
4
+ this.value = value;
5
+ }
6
+ static MAX = new Amount(Number.MAX_SAFE_INTEGER);
7
+ static newAmount(amount) {
8
+ return new Amount(amount);
9
+ }
10
+ static zero() {
11
+ return new Amount(0);
12
+ }
13
+ isZero() {
14
+ return this.value === 0;
15
+ }
16
+ isPositive() {
17
+ return this.value >= 0;
18
+ }
19
+ isNegative() {
20
+ return !this.isPositive();
21
+ }
22
+ getValue() {
23
+ return this.value;
24
+ }
25
+ getStringValue() {
26
+ return this.value.toString();
27
+ }
28
+ checkedAdd(other) {
29
+ const result = this.value + other.value;
30
+ if (result < Number.MIN_SAFE_INTEGER || result > Number.MAX_SAFE_INTEGER) {
31
+ return null;
32
+ }
33
+ return new Amount(result);
34
+ }
35
+ saturatingAdd(other) {
36
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value + other.value)));
37
+ }
38
+ checkedSub(other) {
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
+ saturatingSub(other) {
46
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value - other.value)));
47
+ }
48
+ saturatingSubPositive(other) {
49
+ const result = this.value - other.value;
50
+ return result < 0 ? new Amount(0) : new Amount(result);
51
+ }
52
+ checkedSubPositive(other) {
53
+ if (this.isNegative() || other.isNegative()) {
54
+ return null;
55
+ }
56
+ if (this.value < other.value) {
57
+ return null;
58
+ }
59
+ return new Amount(this.value - other.value);
60
+ }
61
+ checkedMul(other) {
62
+ const result = this.value * other.value;
63
+ if (result < Number.MIN_SAFE_INTEGER || result > Number.MAX_SAFE_INTEGER) {
64
+ return null;
65
+ }
66
+ return new Amount(result);
67
+ }
68
+ saturatingMul(other) {
69
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value * other.value)));
70
+ }
71
+ checkedDiv(other) {
72
+ if (other.value === 0) {
73
+ throw new Error("Division by zero");
74
+ }
75
+ const result = this.value / other.value;
76
+ if (result < Number.MIN_SAFE_INTEGER || result > Number.MAX_SAFE_INTEGER) {
77
+ return null;
78
+ }
79
+ return new Amount(result);
80
+ }
81
+ saturatingDiv(other) {
82
+ if (other.value === 0) {
83
+ throw new Error("Division by zero");
84
+ }
85
+ return new Amount(Math.min(Number.MAX_SAFE_INTEGER, Math.max(Number.MIN_SAFE_INTEGER, this.value / other.value)));
86
+ }
87
+ asU64Checked() {
88
+ if (this.value < 0) {
89
+ return null;
90
+ }
91
+ return this.value;
92
+ }
93
+ }
package/dist/Arg.d.ts ADDED
@@ -0,0 +1 @@
1
+ export type Arg = any;
package/dist/Arg.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type ComponentAddress = string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
2
+ export interface ConfidentialClaim {
3
+ publicKey: string;
4
+ outputAddress: string;
5
+ rangeProof: Array<number>;
6
+ proofOfKnowledge: string;
7
+ withdrawProof?: ConfidentialWithdrawProof;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ElgamalVerifiableBalance } from "./ElgamalVerifiableBalance";
2
+ export interface ConfidentialOutput {
3
+ commitment: string;
4
+ stealthPublicNonce: string;
5
+ encrypted_data: Array<number>;
6
+ minimumValuePromise: number;
7
+ viewableBalance?: ElgamalVerifiableBalance;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { Amount } from "./Amount";
2
+ import type { ConfidentialStatement } from "./ConfidentialStatement";
3
+ export interface ConfidentialOutputStatement {
4
+ outputStatement?: ConfidentialStatement;
5
+ changeStatement?: ConfidentialStatement;
6
+ rangeProof: Array<number>;
7
+ outputRevealedAmount: Amount;
8
+ changeRevealedAmount: Amount;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ViewableBalanceProof } from "./ViewableBalanceProof";
2
+ export interface ConfidentialStatement {
3
+ commitment: Array<number>;
4
+ senderPublicNonce: Array<number>;
5
+ encryptedData: Array<number>;
6
+ minimumValuePromise: number;
7
+ viewableBalanceProof?: ViewableBalanceProof;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ConfidentialOutputStatement } from "./ConfidentialOutputStatement";
2
+ export interface ConfidentialWithdrawProof {
3
+ inputs: Array<Uint8Array>;
4
+ inputRevealedAmount: number;
5
+ outputProof: ConfidentialOutputStatement;
6
+ balanceProof: Array<number>;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export interface ElgamalVerifiableBalance {
2
+ encrypted: string;
3
+ public_nonce: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type Epoch = number;
package/dist/Epoch.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import { FeeReceipt, InstructionResult, LogEntry, RejectReason } from "@tari-project/typescript-bindings";
2
+ import { SubstateDiff } from "./SubstateDiff";
3
+ export type TxResultAccept = {
4
+ Accept: SubstateDiff;
5
+ };
6
+ export type TxResultAcceptFeeRejectRest = {
7
+ AcceptFeeRejectRest: [SubstateDiff, RejectReason];
8
+ };
9
+ export type TxResultReject = {
10
+ Reject: RejectReason;
11
+ };
12
+ export type FinalizeResultStatus = TxResultAccept | TxResultAcceptFeeRejectRest | TxResultReject;
13
+ export interface FinalizeResult {
14
+ transaction_hash: Uint8Array;
15
+ events: Array<Event>;
16
+ logs: Array<LogEntry>;
17
+ execution_results: Array<InstructionResult>;
18
+ result: FinalizeResultStatus;
19
+ fee_receipt: FeeReceipt;
20
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,56 @@
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
+ export type Instruction = CreateAccount | CallFunction | CallMethod | PutLastInstructionOutputOnWorkspace | EmitLog | ClaimBurn | ClaimValidatorFees | DropAllProofsInWorkspace | CreateFreeTestCoins;
8
+ export type CreateAccount = {
9
+ CreateAccount: {
10
+ owner_public_key: string;
11
+ workspace_bucket: string | null;
12
+ };
13
+ };
14
+ export type CallFunction = {
15
+ CallFunction: {
16
+ template_address: TemplateAddress;
17
+ function: string;
18
+ args: Array<Arg>;
19
+ };
20
+ };
21
+ export type CallMethod = {
22
+ CallMethod: {
23
+ component_address: ComponentAddress;
24
+ method: string;
25
+ args: Array<Arg>;
26
+ };
27
+ };
28
+ export type PutLastInstructionOutputOnWorkspace = {
29
+ PutLastInstructionOutputOnWorkspace: {
30
+ key: number[];
31
+ };
32
+ };
33
+ export type EmitLog = {
34
+ EmitLog: {
35
+ level: LogLevel;
36
+ message: string;
37
+ };
38
+ };
39
+ export type ClaimBurn = {
40
+ ClaimBurn: {
41
+ claim: ConfidentialClaim;
42
+ };
43
+ };
44
+ export type ClaimValidatorFees = {
45
+ ClaimValidatorFees: {
46
+ epoch: number;
47
+ validator_public_key: string;
48
+ };
49
+ };
50
+ export type DropAllProofsInWorkspace = "DropAllProofsInWorkspace";
51
+ export type CreateFreeTestCoins = {
52
+ CreateFreeTestCoins: {
53
+ revealed_amount: Amount;
54
+ output: ConfidentialOutput | null;
55
+ };
56
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type ResourceAddress = string;
@@ -0,0 +1,2 @@
1
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
+ export {};
@@ -0,0 +1,7 @@
1
+ import { Substate, SubstateId } from "@tari-project/typescript-bindings";
2
+ export type UpSubstates = Array<[SubstateId, Substate]>;
3
+ export type DownSubstates = Array<[SubstateId, number]>;
4
+ export interface SubstateDiff {
5
+ up_substates: UpSubstates;
6
+ down_substates: DownSubstates;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SubstateId } from "@tari-project/typescript-bindings";
2
+ export interface SubstateRequirement {
3
+ substateId: SubstateId;
4
+ version?: number;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type TemplateAddress = string;
@@ -0,0 +1,2 @@
1
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
+ export {};
@@ -0,0 +1,15 @@
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
+ 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>;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type TransactionId = string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { FinalizeResult } from "./FinalizeResult";
2
+ export type SubmitTransactionResponse = {
3
+ transaction_id: string;
4
+ };
5
+ export interface SubmitTxResult {
6
+ response: SubmitTransactionResponse;
7
+ result: TransactionResult;
8
+ }
9
+ export declare enum TransactionStatus {
10
+ New = 0,
11
+ DryRun = 1,
12
+ Pending = 2,
13
+ Accepted = 3,
14
+ Rejected = 4,
15
+ InvalidTransaction = 5,
16
+ OnlyFeeAccepted = 6
17
+ }
18
+ export type TransactionResult = {
19
+ transaction_id: string;
20
+ status: TransactionStatus;
21
+ result: FinalizeResult | null;
22
+ };
@@ -0,0 +1,10 @@
1
+ export var TransactionStatus;
2
+ (function (TransactionStatus) {
3
+ TransactionStatus[TransactionStatus["New"] = 0] = "New";
4
+ TransactionStatus[TransactionStatus["DryRun"] = 1] = "DryRun";
5
+ TransactionStatus[TransactionStatus["Pending"] = 2] = "Pending";
6
+ TransactionStatus[TransactionStatus["Accepted"] = 3] = "Accepted";
7
+ TransactionStatus[TransactionStatus["Rejected"] = 4] = "Rejected";
8
+ TransactionStatus[TransactionStatus["InvalidTransaction"] = 5] = "InvalidTransaction";
9
+ TransactionStatus[TransactionStatus["OnlyFeeAccepted"] = 6] = "OnlyFeeAccepted";
10
+ })(TransactionStatus || (TransactionStatus = {}));
@@ -0,0 +1,4 @@
1
+ export interface TransactionSignature {
2
+ public_key: string;
3
+ signature: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Instruction } from "./Instruction";
2
+ import { Epoch } from "./Epoch";
3
+ import { SubstateRequirement } from "./SubstateRequirement";
4
+ import { VersionedSubstateId } from "./VersionedSubstateId";
5
+ export interface UnsignedTransaction {
6
+ feeInstructions: Instruction[];
7
+ instructions: Instruction[];
8
+ inputs: SubstateRequirement[];
9
+ filledInputs: VersionedSubstateId[];
10
+ minEpoch?: Epoch;
11
+ maxEpoch?: Epoch;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SubstateId } from "@tari-project/typescript-bindings";
2
+ export interface VersionedSubstateId {
3
+ substateId: SubstateId;
4
+ version: number;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface ViewableBalanceProof {
2
+ elgamal_encrypted: Uint8Array;
3
+ elgamal_public_nonce: Uint8Array;
4
+ c_prime: Uint8Array;
5
+ e_prime: Uint8Array;
6
+ r_prime: Uint8Array;
7
+ s_v: Uint8Array;
8
+ s_m: Uint8Array;
9
+ s_r: Uint8Array;
10
+ }
@@ -0,0 +1,2 @@
1
+ //TODO refactor type (https://github.com/tari-project/tari.js/issues/29)
2
+ export {};
@@ -0,0 +1,3 @@
1
+ export interface WorkspaceArg {
2
+ Workspace: number[];
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
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 { FinalizeResult, FinalizeResultStatus, TxResultAccept, TxResultAcceptFeeRejectRest, TxResultReject, } from "./FinalizeResult";
12
+ export { ResourceAddress } from "./ResourceAddress";
13
+ export { Instruction } from "./Instruction";
14
+ export { Transaction } from "./Transaction";
15
+ export { SubstateDiff, DownSubstates, UpSubstates } from "./SubstateDiff";
16
+ export { SubstateRequirement } from "./SubstateRequirement";
17
+ export { TransactionId } from "./TransactionId";
18
+ export { TransactionResult, TransactionStatus, SubmitTxResult, SubmitTransactionResponse } from "./TransactionResult";
19
+ export { TransactionSignature } from "./TransactionSignature";
20
+ export { UnsignedTransaction } from "./UnsignedTransaction";
21
+ export { VersionedSubstateId } from "./VersionedSubstateId";
22
+ export { ViewableBalanceProof } from "./ViewableBalanceProof";
23
+ export { WorkspaceArg } from "./Workspace";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Amount } from "./Amount";
2
+ export { TransactionStatus } from "./TransactionResult";
package/package.json ADDED
@@ -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
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "@tari-project/typescript-bindings": "^1.4.0"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^22.13.1",
17
+ "typescript": "^5.0.4"
18
+ },
19
+ "files": [
20
+ "/dist"
21
+ ],
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "scripts": {
25
+ "build": "tsc -b"
26
+ }
27
+ }