@tari-project/tarijs 0.1.21 → 0.1.22

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 (109) hide show
  1. package/dist/builders/helpers/index.d.ts +2 -0
  2. package/dist/builders/helpers/index.js +2 -0
  3. package/dist/builders/helpers/submitTransaction.d.ts +13 -0
  4. package/dist/builders/helpers/submitTransaction.js +59 -0
  5. package/dist/builders/helpers/workspace.d.ts +23 -0
  6. package/dist/builders/helpers/workspace.js +29 -0
  7. package/dist/builders/index.d.ts +3 -0
  8. package/dist/builders/index.js +3 -0
  9. package/dist/builders/transaction/TransactionBuilder.d.ts +44 -0
  10. package/dist/builders/transaction/TransactionBuilder.js +164 -0
  11. package/dist/builders/transaction/TransactionRequest.d.ts +27 -0
  12. package/dist/builders/transaction/TransactionRequest.js +67 -0
  13. package/dist/builders/transaction/index.d.ts +2 -0
  14. package/dist/builders/transaction/index.js +2 -0
  15. package/dist/builders/types/Amount.d.ts +23 -0
  16. package/dist/builders/types/Amount.js +93 -0
  17. package/dist/builders/types/Arg.d.ts +1 -0
  18. package/dist/builders/types/Arg.js +1 -0
  19. package/dist/builders/types/Builder.d.ts +47 -0
  20. package/dist/builders/types/Builder.js +1 -0
  21. package/dist/builders/types/ComponentAddress.d.ts +1 -0
  22. package/dist/builders/types/ComponentAddress.js +1 -0
  23. package/dist/builders/types/ConfidentialClaim.d.ts +8 -0
  24. package/dist/builders/types/ConfidentialClaim.js +1 -0
  25. package/dist/builders/types/ConfidentialOutput.d.ts +8 -0
  26. package/dist/builders/types/ConfidentialOutput.js +1 -0
  27. package/dist/builders/types/ConfidentialOutputStatement.d.ts +9 -0
  28. package/dist/builders/types/ConfidentialOutputStatement.js +1 -0
  29. package/dist/builders/types/ConfidentialStatement.d.ts +8 -0
  30. package/dist/builders/types/ConfidentialStatement.js +1 -0
  31. package/dist/builders/types/ConfidentialWithdrawProof.d.ts +7 -0
  32. package/dist/builders/types/ConfidentialWithdrawProof.js +1 -0
  33. package/dist/builders/types/ElgamalVerifiableBalance.d.ts +4 -0
  34. package/dist/builders/types/ElgamalVerifiableBalance.js +1 -0
  35. package/dist/builders/types/Epoch.d.ts +1 -0
  36. package/dist/builders/types/Epoch.js +1 -0
  37. package/dist/builders/types/FinalizeResult.d.ts +20 -0
  38. package/dist/builders/types/FinalizeResult.js +1 -0
  39. package/dist/builders/types/Instruction.d.ts +56 -0
  40. package/dist/builders/types/Instruction.js +1 -0
  41. package/dist/builders/types/ResourceAddress.d.ts +1 -0
  42. package/dist/builders/types/ResourceAddress.js +2 -0
  43. package/dist/builders/types/SubstateDiff.d.ts +7 -0
  44. package/dist/builders/types/SubstateDiff.js +1 -0
  45. package/dist/builders/types/SubstateRequirement.d.ts +5 -0
  46. package/dist/builders/types/SubstateRequirement.js +1 -0
  47. package/dist/builders/types/TemplateAddress.d.ts +1 -0
  48. package/dist/builders/types/TemplateAddress.js +2 -0
  49. package/dist/builders/types/Transaction.d.ts +15 -0
  50. package/dist/builders/types/Transaction.js +1 -0
  51. package/dist/builders/types/TransactionId.d.ts +1 -0
  52. package/dist/builders/types/TransactionId.js +1 -0
  53. package/dist/builders/types/TransactionResult.d.ts +22 -0
  54. package/dist/builders/types/TransactionResult.js +10 -0
  55. package/dist/builders/types/TransactionSignature.d.ts +4 -0
  56. package/dist/builders/types/TransactionSignature.js +1 -0
  57. package/dist/builders/types/UnsignedTransaction.d.ts +12 -0
  58. package/dist/builders/types/UnsignedTransaction.js +1 -0
  59. package/dist/builders/types/VersionedSubstateId.d.ts +5 -0
  60. package/dist/builders/types/VersionedSubstateId.js +1 -0
  61. package/dist/builders/types/ViewableBalanceProof.d.ts +10 -0
  62. package/dist/builders/types/ViewableBalanceProof.js +2 -0
  63. package/dist/builders/types/Workspace.d.ts +3 -0
  64. package/dist/builders/types/Workspace.js +1 -0
  65. package/dist/builders/types/index.d.ts +24 -0
  66. package/dist/builders/types/index.js +2 -0
  67. package/dist/index.d.ts +13 -0
  68. package/dist/index.js +12 -0
  69. package/dist/providers/index.d.ts +16 -0
  70. package/dist/providers/index.js +1 -0
  71. package/dist/providers/metamask/index.d.ts +30 -0
  72. package/dist/providers/metamask/index.js +169 -0
  73. package/dist/providers/metamask/utils.d.ts +38 -0
  74. package/dist/providers/metamask/utils.js +55 -0
  75. package/dist/providers/tari_universe/index.d.ts +3 -0
  76. package/dist/providers/tari_universe/index.js +3 -0
  77. package/dist/providers/tari_universe/provider.d.ts +23 -0
  78. package/dist/providers/tari_universe/provider.js +88 -0
  79. package/dist/providers/tari_universe/types.d.ts +30 -0
  80. package/dist/providers/tari_universe/types.js +1 -0
  81. package/dist/providers/types.d.ts +66 -0
  82. package/dist/providers/types.js +10 -0
  83. package/dist/providers/wallet_daemon/index.d.ts +3 -0
  84. package/dist/providers/wallet_daemon/index.js +3 -0
  85. package/dist/providers/wallet_daemon/provider.d.ts +35 -0
  86. package/dist/providers/wallet_daemon/provider.js +173 -0
  87. package/dist/providers/wallet_daemon/tari_permissions.d.ts +216 -0
  88. package/dist/providers/wallet_daemon/tari_permissions.js +282 -0
  89. package/dist/providers/wallet_daemon/webrtc.d.ts +20 -0
  90. package/dist/providers/wallet_daemon/webrtc.js +201 -0
  91. package/dist/providers/wallet_daemon/webrtc_transport.d.ts +10 -0
  92. package/dist/providers/wallet_daemon/webrtc_transport.js +18 -0
  93. package/dist/providers/walletconnect/index.d.ts +23 -0
  94. package/dist/providers/walletconnect/index.js +217 -0
  95. package/dist/templates/Account.d.ts +65 -0
  96. package/dist/templates/Account.js +31 -0
  97. package/dist/templates/Pool.d.ts +30 -0
  98. package/dist/templates/Pool.js +20 -0
  99. package/dist/templates/Tariswap.d.ts +65 -0
  100. package/dist/templates/Tariswap.js +36 -0
  101. package/dist/templates/TemplateFactory.d.ts +9 -0
  102. package/dist/templates/TemplateFactory.js +18 -0
  103. package/dist/templates/TestFaucet.d.ts +49 -0
  104. package/dist/templates/TestFaucet.js +31 -0
  105. package/dist/templates/index.d.ts +4 -0
  106. package/dist/templates/index.js +4 -0
  107. package/dist/utils.d.ts +2 -0
  108. package/dist/utils.js +22 -0
  109. package/package.json +8 -4
@@ -0,0 +1,2 @@
1
+ export { buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult } from "./submitTransaction";
2
+ export { fromWorkspace, toWorkspace } from "./workspace";
@@ -0,0 +1,2 @@
1
+ export { buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult } from "./submitTransaction";
2
+ export { fromWorkspace, toWorkspace } from "./workspace";
@@ -0,0 +1,13 @@
1
+ import { TariProvider } from "../../providers";
2
+ import { TariUniverseProvider } from "../../providers/tari_universe";
3
+ import { SubmitTransactionRequest, SubstateRequirement } from "../../providers/types";
4
+ import { Transaction, TransactionResult } from "../types";
5
+ import { DownSubstates, UpSubstates } from "../types/SubstateDiff";
6
+ import { SubmitTxResult } from "../types/TransactionResult";
7
+ export declare function buildTransactionRequest(transaction: Transaction, accountId: number, requiredSubstates: SubstateRequirement[], inputRefs?: never[], isDryRun?: boolean): SubmitTransactionRequest;
8
+ export declare function submitAndWaitForTransaction(provider: TariProvider, req: SubmitTransactionRequest): Promise<SubmitTxResult>;
9
+ export declare function waitForTransactionResult(provider: TariProvider | TariUniverseProvider, transactionId: string): Promise<TransactionResult>;
10
+ export declare function getAcceptResultSubstates(txResult: TransactionResult): {
11
+ upSubstates: UpSubstates;
12
+ downSubstates: DownSubstates;
13
+ } | undefined;
@@ -0,0 +1,59 @@
1
+ import { TransactionStatus } from "../types";
2
+ export function buildTransactionRequest(transaction, accountId, requiredSubstates, inputRefs = [], isDryRun = false) {
3
+ return {
4
+ //TODO refactor SubTxReq type to not use 'object[]' and types match
5
+ // https://github.com/tari-project/tari.js/issues/25
6
+ account_id: accountId,
7
+ instructions: transaction.instructions,
8
+ fee_instructions: transaction.feeInstructions,
9
+ inputs: transaction.inputs,
10
+ input_refs: inputRefs,
11
+ required_substates: requiredSubstates,
12
+ is_dry_run: isDryRun,
13
+ min_epoch: transaction.minEpoch ?? null,
14
+ max_epoch: transaction.maxEpoch ?? null,
15
+ };
16
+ }
17
+ export async function submitAndWaitForTransaction(provider, req) {
18
+ try {
19
+ const response = await provider.submitTransaction(req);
20
+ const result = await waitForTransactionResult(provider, response.transaction_id);
21
+ return {
22
+ response,
23
+ result,
24
+ };
25
+ }
26
+ catch (e) {
27
+ throw new Error(`Transaction failed: ${e}`);
28
+ }
29
+ }
30
+ export async function waitForTransactionResult(provider, transactionId) {
31
+ // eslint-disable-next-line no-constant-condition
32
+ while (true) {
33
+ const resp = await provider.getTransactionResult(transactionId);
34
+ const FINALIZED_STATUSES = [
35
+ TransactionStatus.Accepted,
36
+ TransactionStatus.Rejected,
37
+ TransactionStatus.InvalidTransaction,
38
+ TransactionStatus.OnlyFeeAccepted,
39
+ TransactionStatus.DryRun,
40
+ ];
41
+ if (resp.status == TransactionStatus.Rejected) {
42
+ throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
43
+ }
44
+ if (FINALIZED_STATUSES.includes(resp.status)) {
45
+ return resp; //TODO fix: type mismatch (https://github.com/tari-project/tari.js/issues/29)
46
+ }
47
+ await new Promise((resolve) => setTimeout(resolve, 1000));
48
+ }
49
+ }
50
+ export function getAcceptResultSubstates(txResult) {
51
+ const result = txResult.result?.result;
52
+ if (result && isAccept(result)) {
53
+ return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
54
+ }
55
+ return undefined;
56
+ }
57
+ function isAccept(result) {
58
+ return "Accept" in result;
59
+ }
@@ -0,0 +1,23 @@
1
+ import { WorkspaceArg } from "../types";
2
+ /**
3
+ *
4
+ * @param key workspace name
5
+ * @returns encoded Uint8Array value
6
+ * @example
7
+ * key: "0" -> [ 48 ]
8
+ * key: "0.0" -> [ 48, 46, 48 ]
9
+ * key: "0.1" -> [ 48, 46, 49 ]
10
+ *
11
+ * key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
12
+ * key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
13
+ * key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
14
+ */
15
+ export declare function toWorkspace(key: string): number[];
16
+ /**
17
+ *
18
+ * @param key workspace name
19
+ * @returns formatted Workspace data
20
+ * @example
21
+ * key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
22
+ */
23
+ export declare function fromWorkspace(key: string): WorkspaceArg;
@@ -0,0 +1,29 @@
1
+ /**
2
+ *
3
+ * @param key workspace name
4
+ * @returns encoded Uint8Array value
5
+ * @example
6
+ * key: "0" -> [ 48 ]
7
+ * key: "0.0" -> [ 48, 46, 48 ]
8
+ * key: "0.1" -> [ 48, 46, 49 ]
9
+ *
10
+ * key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
11
+ * key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
12
+ * key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
13
+ */
14
+ export function toWorkspace(key) {
15
+ const encoder = new TextEncoder();
16
+ return Array.from(encoder.encode(key));
17
+ }
18
+ /**
19
+ *
20
+ * @param key workspace name
21
+ * @returns formatted Workspace data
22
+ * @example
23
+ * key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
24
+ */
25
+ export function fromWorkspace(key) {
26
+ const encoder = new TextEncoder();
27
+ const encodedKey = encoder.encode(key);
28
+ return { Workspace: Array.from(encodedKey) };
29
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export { TransactionBuilder, TransactionRequest } from "./transaction";
3
+ export { buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, } from "./helpers";
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export { TransactionBuilder, TransactionRequest } from "./transaction";
3
+ export { buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, } from "./helpers";
@@ -0,0 +1,44 @@
1
+ import { Builder, TariFunctionDefinition, TariMethodDefinition } from "../types/Builder";
2
+ import { ComponentAddress, ConfidentialClaim, ConfidentialWithdrawProof, Instruction, ResourceAddress, SubstateRequirement, Transaction, UnsignedTransaction } from "../types";
3
+ export declare class TransactionBuilder implements Builder {
4
+ private unsignedTransaction;
5
+ private signatures;
6
+ constructor();
7
+ callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
8
+ callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
9
+ createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
10
+ createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
11
+ claimBurn(claim: ConfidentialClaim): this;
12
+ /**
13
+ * The `SaveVar` method replaces
14
+ * `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
15
+ * to make saving variables easier.
16
+ */
17
+ saveVar(key: string): this;
18
+ /**
19
+ * Adds a fee instruction that calls the `take_fee` method on a component.
20
+ * This method must exist and return a Bucket with containing revealed confidential XTR resource.
21
+ * This allows the fee to originate from sources other than the transaction sender's account.
22
+ * The fee instruction will lock up the `max_fee` amount for the duration of the transaction.
23
+ */
24
+ feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this;
25
+ /**
26
+ * Adds a fee instruction that calls the `take_fee_confidential` method on a component.
27
+ * This method must exist and return a Bucket with containing revealed confidential XTR resource.
28
+ * This allows the fee to originate from sources other than the transaction sender's account.
29
+ */
30
+ feeTransactionPayFromComponentConfidential(componentAddress: ComponentAddress, proof: ConfidentialWithdrawProof): this;
31
+ dropAllProofsInWorkspace(): this;
32
+ withUnsignedTransaction(unsignedTransaction: UnsignedTransaction): this;
33
+ withFeeInstructions(instructions: Instruction[]): this;
34
+ withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => TransactionBuilder): this;
35
+ addInstruction(instruction: Instruction): this;
36
+ addFeeInstruction(instruction: Instruction): this;
37
+ withInstructions(instructions: Instruction[]): this;
38
+ addInput(inputObject: SubstateRequirement): this;
39
+ withInputs(inputs: SubstateRequirement[]): this;
40
+ withMinEpoch(minEpoch: number): this;
41
+ withMaxEpoch(maxEpoch: number): this;
42
+ buildUnsignedTransaction(): UnsignedTransaction;
43
+ build(): Transaction;
44
+ }
@@ -0,0 +1,164 @@
1
+ // Copyright 2024 The Tari Project
2
+ // SPDX-License-Identifier: BSD-3-Clause
3
+ import { toWorkspace } from "../helpers";
4
+ import { TransactionRequest } from "./TransactionRequest";
5
+ export class TransactionBuilder {
6
+ unsignedTransaction;
7
+ signatures;
8
+ constructor() {
9
+ this.unsignedTransaction = {
10
+ feeInstructions: [],
11
+ instructions: [],
12
+ inputs: [],
13
+ filledInputs: [],
14
+ minEpoch: undefined,
15
+ maxEpoch: undefined,
16
+ };
17
+ this.signatures = [];
18
+ }
19
+ callFunction(func, args) {
20
+ return this.addInstruction({
21
+ CallFunction: {
22
+ template_address: func.templateAddress,
23
+ function: func.functionName,
24
+ args,
25
+ },
26
+ });
27
+ }
28
+ callMethod(method, args) {
29
+ return this.addInstruction({
30
+ CallMethod: {
31
+ component_address: method.componentAddress,
32
+ method: method.methodName,
33
+ args,
34
+ },
35
+ });
36
+ }
37
+ createAccount(ownerPublicKey, workspaceBucket) {
38
+ return this.addInstruction({
39
+ CreateAccount: {
40
+ owner_public_key: ownerPublicKey,
41
+ workspace_bucket: workspaceBucket ?? null,
42
+ },
43
+ });
44
+ }
45
+ createProof(account, resourceAddress) {
46
+ return this.addInstruction({
47
+ CallMethod: {
48
+ component_address: account,
49
+ method: "create_proof_for_resource",
50
+ args: [resourceAddress],
51
+ },
52
+ });
53
+ }
54
+ claimBurn(claim) {
55
+ return this.addInstruction({
56
+ ClaimBurn: {
57
+ claim,
58
+ },
59
+ });
60
+ }
61
+ /**
62
+ * The `SaveVar` method replaces
63
+ * `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
64
+ * to make saving variables easier.
65
+ */
66
+ saveVar(key) {
67
+ return this.addInstruction({
68
+ PutLastInstructionOutputOnWorkspace: {
69
+ key: toWorkspace(key),
70
+ },
71
+ });
72
+ }
73
+ /**
74
+ * Adds a fee instruction that calls the `take_fee` method on a component.
75
+ * This method must exist and return a Bucket with containing revealed confidential XTR resource.
76
+ * This allows the fee to originate from sources other than the transaction sender's account.
77
+ * The fee instruction will lock up the `max_fee` amount for the duration of the transaction.
78
+ */
79
+ feeTransactionPayFromComponent(componentAddress, maxFee) {
80
+ return this.addFeeInstruction({
81
+ CallMethod: {
82
+ component_address: componentAddress,
83
+ method: "pay_fee",
84
+ args: [maxFee],
85
+ },
86
+ });
87
+ }
88
+ /**
89
+ * Adds a fee instruction that calls the `take_fee_confidential` method on a component.
90
+ * This method must exist and return a Bucket with containing revealed confidential XTR resource.
91
+ * This allows the fee to originate from sources other than the transaction sender's account.
92
+ */
93
+ feeTransactionPayFromComponentConfidential(componentAddress, proof) {
94
+ return this.addFeeInstruction({
95
+ CallMethod: {
96
+ component_address: componentAddress,
97
+ method: "pay_fee_confidential",
98
+ args: [proof],
99
+ },
100
+ });
101
+ }
102
+ dropAllProofsInWorkspace() {
103
+ return this.addInstruction("DropAllProofsInWorkspace");
104
+ }
105
+ withUnsignedTransaction(unsignedTransaction) {
106
+ this.unsignedTransaction = unsignedTransaction;
107
+ this.signatures = [];
108
+ return this;
109
+ }
110
+ withFeeInstructions(instructions) {
111
+ this.unsignedTransaction.feeInstructions = instructions;
112
+ this.signatures = [];
113
+ return this;
114
+ }
115
+ withFeeInstructionsBuilder(builder) {
116
+ const newBuilder = builder(new TransactionBuilder());
117
+ this.unsignedTransaction.feeInstructions = newBuilder.unsignedTransaction.instructions;
118
+ this.signatures = [];
119
+ return this;
120
+ }
121
+ addInstruction(instruction) {
122
+ this.unsignedTransaction.instructions.push(instruction);
123
+ this.signatures = [];
124
+ return this;
125
+ }
126
+ addFeeInstruction(instruction) {
127
+ this.unsignedTransaction.feeInstructions.push(instruction);
128
+ this.signatures = [];
129
+ return this;
130
+ }
131
+ withInstructions(instructions) {
132
+ this.unsignedTransaction.instructions.push(...instructions);
133
+ this.signatures = [];
134
+ return this;
135
+ }
136
+ addInput(inputObject) {
137
+ this.unsignedTransaction.inputs.push(inputObject);
138
+ this.signatures = [];
139
+ return this;
140
+ }
141
+ withInputs(inputs) {
142
+ this.unsignedTransaction.inputs.push(...inputs);
143
+ this.signatures = [];
144
+ return this;
145
+ }
146
+ withMinEpoch(minEpoch) {
147
+ this.unsignedTransaction.minEpoch = minEpoch;
148
+ // Reset the signatures as they are no longer valid
149
+ this.signatures = [];
150
+ return this;
151
+ }
152
+ withMaxEpoch(maxEpoch) {
153
+ this.unsignedTransaction.maxEpoch = maxEpoch;
154
+ // Reset the signatures as they are no longer valid
155
+ this.signatures = [];
156
+ return this;
157
+ }
158
+ buildUnsignedTransaction() {
159
+ return this.unsignedTransaction;
160
+ }
161
+ build() {
162
+ return new TransactionRequest(this.unsignedTransaction, this.signatures);
163
+ }
164
+ }
@@ -0,0 +1,27 @@
1
+ import { Epoch, Instruction, SubstateRequirement, Transaction, TransactionId, TransactionSignature, UnsignedTransaction, VersionedSubstateId } from "../types";
2
+ export declare class TransactionRequest implements Transaction {
3
+ id: TransactionId;
4
+ feeInstructions: Array<Instruction>;
5
+ instructions: Array<Instruction>;
6
+ inputs: Array<SubstateRequirement>;
7
+ signatures: Array<TransactionSignature>;
8
+ unsignedTransaction: UnsignedTransaction;
9
+ minEpoch?: Epoch;
10
+ maxEpoch?: Epoch;
11
+ filledInputs: VersionedSubstateId[];
12
+ constructor(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]);
13
+ private calculateHash;
14
+ withFilledInputs(filled_inputs: Array<VersionedSubstateId>): this;
15
+ getId(): TransactionId;
16
+ checkId(): boolean;
17
+ getUnsignedTransaction(): UnsignedTransaction;
18
+ getFeeInstructions(): Instruction[];
19
+ getInstructions(): Instruction[];
20
+ getSignatures(): TransactionSignature[];
21
+ getHash(): string;
22
+ getInputs(): SubstateRequirement[];
23
+ getFilledInputs(): VersionedSubstateId[];
24
+ getFilledInputsMut(): VersionedSubstateId[];
25
+ getMinEpoch(): Epoch | undefined;
26
+ getMaxEpoch(): Epoch | undefined;
27
+ }
@@ -0,0 +1,67 @@
1
+ ///TODO this implementation is not fully done, see:
2
+ /// https://github.com/tari-project/tari-dan/blob/development/dan_layer/transaction/src/transaction.rs
3
+ export class TransactionRequest {
4
+ id;
5
+ feeInstructions;
6
+ instructions;
7
+ inputs;
8
+ signatures;
9
+ unsignedTransaction;
10
+ minEpoch;
11
+ maxEpoch;
12
+ filledInputs;
13
+ constructor(unsignedTransaction, signatures) {
14
+ this.id = this.calculateHash();
15
+ this.feeInstructions = unsignedTransaction.feeInstructions;
16
+ this.instructions = unsignedTransaction.instructions;
17
+ this.inputs = unsignedTransaction.inputs;
18
+ this.signatures = signatures;
19
+ this.minEpoch = unsignedTransaction.minEpoch;
20
+ this.maxEpoch = unsignedTransaction.maxEpoch;
21
+ // Inputs filled by some authority. These are not part of the transaction hash nor the signature
22
+ this.filledInputs = [];
23
+ }
24
+ calculateHash() {
25
+ return "";
26
+ }
27
+ withFilledInputs(filled_inputs) {
28
+ return { ...this, filled_inputs };
29
+ }
30
+ getId() {
31
+ return this.id;
32
+ }
33
+ checkId() {
34
+ const id = this.calculateHash();
35
+ return id === this.id;
36
+ }
37
+ getUnsignedTransaction() {
38
+ return this.unsignedTransaction;
39
+ }
40
+ getFeeInstructions() {
41
+ return this.feeInstructions;
42
+ }
43
+ getInstructions() {
44
+ return this.instructions;
45
+ }
46
+ getSignatures() {
47
+ return this.signatures;
48
+ }
49
+ getHash() {
50
+ return this.id;
51
+ }
52
+ getInputs() {
53
+ return this.inputs;
54
+ }
55
+ getFilledInputs() {
56
+ return this.filledInputs;
57
+ }
58
+ getFilledInputsMut() {
59
+ return this.filledInputs;
60
+ }
61
+ getMinEpoch() {
62
+ return this.minEpoch;
63
+ }
64
+ getMaxEpoch() {
65
+ return this.maxEpoch;
66
+ }
67
+ }
@@ -0,0 +1,2 @@
1
+ export { TransactionBuilder } from "./TransactionBuilder";
2
+ export { TransactionRequest } from "./TransactionRequest";
@@ -0,0 +1,2 @@
1
+ export { TransactionBuilder } from "./TransactionBuilder";
2
+ export { TransactionRequest } from "./TransactionRequest";
@@ -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
+ }
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export type Arg = any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { TemplateAddress } from "./TemplateAddress";
2
+ import { Arg } from "./Arg";
3
+ import { ComponentAddress, ConfidentialClaim, ConfidentialWithdrawProof, Instruction, ResourceAddress, SubstateRequirement, Transaction, TransactionSignature, UnsignedTransaction } from ".";
4
+ import { TransactionBuilder } from "../transaction";
5
+ export interface TransactionConstructor {
6
+ new (unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
7
+ }
8
+ export interface TariFunctionDefinition {
9
+ functionName: string;
10
+ args?: Arg[];
11
+ templateAddress: TemplateAddress;
12
+ }
13
+ export interface TariMethodDefinition {
14
+ methodName: string;
15
+ args?: Arg[];
16
+ componentAddress: ComponentAddress;
17
+ }
18
+ export interface TariCreateAccountDefinition {
19
+ methodName: string;
20
+ args?: {
21
+ ownerPublicKey: string;
22
+ workspaceBucket?: string;
23
+ };
24
+ }
25
+ export interface Builder {
26
+ callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
27
+ callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
28
+ createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
29
+ createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
30
+ saveVar(key: string): this;
31
+ dropAllProofsInWorkspace(): this;
32
+ claimBurn(claim: ConfidentialClaim): this;
33
+ addInput(inputObject: SubstateRequirement): this;
34
+ addInstruction(instruction: Instruction): this;
35
+ addFeeInstruction(instruction: Instruction): this;
36
+ withMinEpoch(minEpoch: number): this;
37
+ withMaxEpoch(maxEpoch: number): this;
38
+ withInputs(inputs: SubstateRequirement[]): this;
39
+ withInstructions(instructions: Instruction[]): this;
40
+ withFeeInstructions(instructions: Instruction[]): this;
41
+ withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => this): this;
42
+ withUnsignedTransaction(unsignedTransaction: UnsignedTransaction): this;
43
+ feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this;
44
+ feeTransactionPayFromComponentConfidential(componentAddress: ComponentAddress, proof: ConfidentialWithdrawProof): this;
45
+ buildUnsignedTransaction(): UnsignedTransaction;
46
+ build(): Transaction;
47
+ }
@@ -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 {};